]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
zebra: reduce rib workqueue retry timeout
[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 "prefix.h"
26 #include "plist.h"
27 #include "buffer.h"
28 #include "linklist.h"
29 #include "stream.h"
30 #include "thread.h"
31 #include "log.h"
32 #include "memory.h"
33 #include "memory_vty.h"
34 #include "hash.h"
35 #include "queue.h"
36 #include "filter.h"
37 #include "frrstr.h"
38
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_advertise.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_community.h"
44 #include "bgpd/bgp_ecommunity.h"
45 #include "bgpd/bgp_lcommunity.h"
46 #include "bgpd/bgp_damp.h"
47 #include "bgpd/bgp_debug.h"
48 #include "bgpd/bgp_errors.h"
49 #include "bgpd/bgp_fsm.h"
50 #include "bgpd/bgp_nexthop.h"
51 #include "bgpd/bgp_open.h"
52 #include "bgpd/bgp_regex.h"
53 #include "bgpd/bgp_route.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_zebra.h"
56 #include "bgpd/bgp_table.h"
57 #include "bgpd/bgp_vty.h"
58 #include "bgpd/bgp_mpath.h"
59 #include "bgpd/bgp_packet.h"
60 #include "bgpd/bgp_updgrp.h"
61 #include "bgpd/bgp_bfd.h"
62 #include "bgpd/bgp_io.h"
63 #include "bgpd/bgp_evpn.h"
64 #include "bgpd/bgp_addpath.h"
65
66 static struct peer_group *listen_range_exists(struct bgp *bgp,
67 struct prefix *range, int exact);
68
69 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
70 {
71 switch (afi) {
72 case AFI_IP:
73 switch (safi) {
74 case SAFI_UNICAST:
75 return BGP_IPV4_NODE;
76 break;
77 case SAFI_MULTICAST:
78 return BGP_IPV4M_NODE;
79 break;
80 case SAFI_LABELED_UNICAST:
81 return BGP_IPV4L_NODE;
82 break;
83 case SAFI_MPLS_VPN:
84 return BGP_VPNV4_NODE;
85 break;
86 case SAFI_FLOWSPEC:
87 return BGP_FLOWSPECV4_NODE;
88 default:
89 /* not expected */
90 return BGP_IPV4_NODE;
91 break;
92 }
93 break;
94 case AFI_IP6:
95 switch (safi) {
96 case SAFI_UNICAST:
97 return BGP_IPV6_NODE;
98 break;
99 case SAFI_MULTICAST:
100 return BGP_IPV6M_NODE;
101 break;
102 case SAFI_LABELED_UNICAST:
103 return BGP_IPV6L_NODE;
104 break;
105 case SAFI_MPLS_VPN:
106 return BGP_VPNV6_NODE;
107 break;
108 case SAFI_FLOWSPEC:
109 return BGP_FLOWSPECV6_NODE;
110 default:
111 /* not expected */
112 return BGP_IPV4_NODE;
113 break;
114 }
115 break;
116 case AFI_L2VPN:
117 return BGP_EVPN_NODE;
118 break;
119 case AFI_MAX:
120 // We should never be here but to clarify the switch statement..
121 return BGP_IPV4_NODE;
122 break;
123 }
124
125 // Impossible to happen
126 return BGP_IPV4_NODE;
127 }
128
129 /* Utility function to get address family from current node. */
130 afi_t bgp_node_afi(struct vty *vty)
131 {
132 afi_t afi;
133 switch (vty->node) {
134 case BGP_IPV6_NODE:
135 case BGP_IPV6M_NODE:
136 case BGP_IPV6L_NODE:
137 case BGP_VPNV6_NODE:
138 case BGP_FLOWSPECV6_NODE:
139 afi = AFI_IP6;
140 break;
141 case BGP_EVPN_NODE:
142 afi = AFI_L2VPN;
143 break;
144 default:
145 afi = AFI_IP;
146 break;
147 }
148 return afi;
149 }
150
151 /* Utility function to get subsequent address family from current
152 node. */
153 safi_t bgp_node_safi(struct vty *vty)
154 {
155 safi_t safi;
156 switch (vty->node) {
157 case BGP_VPNV4_NODE:
158 case BGP_VPNV6_NODE:
159 safi = SAFI_MPLS_VPN;
160 break;
161 case BGP_IPV4M_NODE:
162 case BGP_IPV6M_NODE:
163 safi = SAFI_MULTICAST;
164 break;
165 case BGP_EVPN_NODE:
166 safi = SAFI_EVPN;
167 break;
168 case BGP_IPV4L_NODE:
169 case BGP_IPV6L_NODE:
170 safi = SAFI_LABELED_UNICAST;
171 break;
172 case BGP_FLOWSPECV4_NODE:
173 case BGP_FLOWSPECV6_NODE:
174 safi = SAFI_FLOWSPEC;
175 break;
176 default:
177 safi = SAFI_UNICAST;
178 break;
179 }
180 return safi;
181 }
182
183 /**
184 * Converts an AFI in string form to afi_t
185 *
186 * @param afi string, one of
187 * - "ipv4"
188 * - "ipv6"
189 * - "l2vpn"
190 * @return the corresponding afi_t
191 */
192 afi_t bgp_vty_afi_from_str(const char *afi_str)
193 {
194 afi_t afi = AFI_MAX; /* unknown */
195 if (strmatch(afi_str, "ipv4"))
196 afi = AFI_IP;
197 else if (strmatch(afi_str, "ipv6"))
198 afi = AFI_IP6;
199 else if (strmatch(afi_str, "l2vpn"))
200 afi = AFI_L2VPN;
201 return afi;
202 }
203
204 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
205 afi_t *afi)
206 {
207 int ret = 0;
208 if (argv_find(argv, argc, "ipv4", index)) {
209 ret = 1;
210 if (afi)
211 *afi = AFI_IP;
212 } else if (argv_find(argv, argc, "ipv6", index)) {
213 ret = 1;
214 if (afi)
215 *afi = AFI_IP6;
216 }
217 return ret;
218 }
219
220 /* supports <unicast|multicast|vpn|labeled-unicast> */
221 safi_t bgp_vty_safi_from_str(const char *safi_str)
222 {
223 safi_t safi = SAFI_MAX; /* unknown */
224 if (strmatch(safi_str, "multicast"))
225 safi = SAFI_MULTICAST;
226 else if (strmatch(safi_str, "unicast"))
227 safi = SAFI_UNICAST;
228 else if (strmatch(safi_str, "vpn"))
229 safi = SAFI_MPLS_VPN;
230 else if (strmatch(safi_str, "evpn"))
231 safi = SAFI_EVPN;
232 else if (strmatch(safi_str, "labeled-unicast"))
233 safi = SAFI_LABELED_UNICAST;
234 else if (strmatch(safi_str, "flowspec"))
235 safi = SAFI_FLOWSPEC;
236 return safi;
237 }
238
239 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
240 safi_t *safi)
241 {
242 int ret = 0;
243 if (argv_find(argv, argc, "unicast", index)) {
244 ret = 1;
245 if (safi)
246 *safi = SAFI_UNICAST;
247 } else if (argv_find(argv, argc, "multicast", index)) {
248 ret = 1;
249 if (safi)
250 *safi = SAFI_MULTICAST;
251 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_LABELED_UNICAST;
255 } else if (argv_find(argv, argc, "vpn", index)) {
256 ret = 1;
257 if (safi)
258 *safi = SAFI_MPLS_VPN;
259 } else if (argv_find(argv, argc, "flowspec", index)) {
260 ret = 1;
261 if (safi)
262 *safi = SAFI_FLOWSPEC;
263 }
264 return ret;
265 }
266
267 /*
268 * bgp_vty_find_and_parse_afi_safi_bgp
269 *
270 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
271 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
272 * to appropriate values for the calling function. This is to allow the
273 * calling function to make decisions appropriate for the show command
274 * that is being parsed.
275 *
276 * The show commands are generally of the form:
277 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
278 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
279 *
280 * Since we use argv_find if the show command in particular doesn't have:
281 * [ip]
282 * [<view|vrf> VIEWVRFNAME]
283 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
284 * The command parsing should still be ok.
285 *
286 * vty -> The vty for the command so we can output some useful data in
287 * the event of a parse error in the vrf.
288 * argv -> The command tokens
289 * argc -> How many command tokens we have
290 * idx -> The current place in the command, generally should be 0 for this
291 * function
292 * afi -> The parsed afi if it was included in the show command, returned here
293 * safi -> The parsed safi if it was included in the show command, returned here
294 * bgp -> Pointer to the bgp data structure we need to fill in.
295 *
296 * The function returns the correct location in the parse tree for the
297 * last token found.
298 *
299 * Returns 0 for failure to parse correctly, else the idx position of where
300 * it found the last token.
301 */
302 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
303 struct cmd_token **argv, int argc,
304 int *idx, afi_t *afi, safi_t *safi,
305 struct bgp **bgp, bool use_json)
306 {
307 char *vrf_name = NULL;
308
309 assert(afi);
310 assert(safi);
311 assert(bgp);
312
313 if (argv_find(argv, argc, "ip", idx))
314 *afi = AFI_IP;
315
316 if (argv_find(argv, argc, "view", idx))
317 vrf_name = argv[*idx + 1]->arg;
318 else if (argv_find(argv, argc, "vrf", idx)) {
319 vrf_name = argv[*idx + 1]->arg;
320 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
321 vrf_name = NULL;
322 }
323 if (vrf_name) {
324 if (strmatch(vrf_name, "all"))
325 *bgp = NULL;
326 else {
327 *bgp = bgp_lookup_by_name(vrf_name);
328 if (!*bgp) {
329 if (use_json)
330 vty_out(vty, "{}\n");
331 else
332 vty_out(vty, "View/Vrf %s is unknown\n",
333 vrf_name);
334 *idx = 0;
335 return 0;
336 }
337 }
338 } else {
339 *bgp = bgp_get_default();
340 if (!*bgp) {
341 if (use_json)
342 vty_out(vty, "{}\n");
343 else
344 vty_out(vty,
345 "Default BGP instance not found\n");
346 *idx = 0;
347 return 0;
348 }
349 }
350
351 if (argv_find_and_parse_afi(argv, argc, idx, afi))
352 argv_find_and_parse_safi(argv, argc, idx, safi);
353
354 *idx += 1;
355 return *idx;
356 }
357
358 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
359 {
360 struct interface *ifp = NULL;
361
362 if (su->sa.sa_family == AF_INET)
363 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
364 else if (su->sa.sa_family == AF_INET6)
365 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
366 su->sin6.sin6_scope_id,
367 bgp->vrf_id);
368
369 if (ifp)
370 return 1;
371
372 return 0;
373 }
374
375 /* Utility function for looking up peer from VTY. */
376 /* This is used only for configuration, so disallow if attempted on
377 * a dynamic neighbor.
378 */
379 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
380 {
381 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
382 int ret;
383 union sockunion su;
384 struct peer *peer;
385
386 if (!bgp) {
387 return NULL;
388 }
389
390 ret = str2sockunion(ip_str, &su);
391 if (ret < 0) {
392 peer = peer_lookup_by_conf_if(bgp, ip_str);
393 if (!peer) {
394 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
395 == NULL) {
396 vty_out(vty,
397 "%% Malformed address or name: %s\n",
398 ip_str);
399 return NULL;
400 }
401 }
402 } else {
403 peer = peer_lookup(bgp, &su);
404 if (!peer) {
405 vty_out(vty,
406 "%% Specify remote-as or peer-group commands first\n");
407 return NULL;
408 }
409 if (peer_dynamic_neighbor(peer)) {
410 vty_out(vty,
411 "%% Operation not allowed on a dynamic neighbor\n");
412 return NULL;
413 }
414 }
415 return peer;
416 }
417
418 /* Utility function for looking up peer or peer group. */
419 /* This is used only for configuration, so disallow if attempted on
420 * a dynamic neighbor.
421 */
422 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
423 {
424 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
425 int ret;
426 union sockunion su;
427 struct peer *peer = NULL;
428 struct peer_group *group = NULL;
429
430 if (!bgp) {
431 return NULL;
432 }
433
434 ret = str2sockunion(peer_str, &su);
435 if (ret == 0) {
436 /* IP address, locate peer. */
437 peer = peer_lookup(bgp, &su);
438 } else {
439 /* Not IP, could match either peer configured on interface or a
440 * group. */
441 peer = peer_lookup_by_conf_if(bgp, peer_str);
442 if (!peer)
443 group = peer_group_lookup(bgp, peer_str);
444 }
445
446 if (peer) {
447 if (peer_dynamic_neighbor(peer)) {
448 vty_out(vty,
449 "%% Operation not allowed on a dynamic neighbor\n");
450 return NULL;
451 }
452
453 return peer;
454 }
455
456 if (group)
457 return group->conf;
458
459 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
460
461 return NULL;
462 }
463
464 int bgp_vty_return(struct vty *vty, int ret)
465 {
466 const char *str = NULL;
467
468 switch (ret) {
469 case BGP_ERR_INVALID_VALUE:
470 str = "Invalid value";
471 break;
472 case BGP_ERR_INVALID_FLAG:
473 str = "Invalid flag";
474 break;
475 case BGP_ERR_PEER_GROUP_SHUTDOWN:
476 str = "Peer-group has been shutdown. Activate the peer-group first";
477 break;
478 case BGP_ERR_PEER_FLAG_CONFLICT:
479 str = "Can't set override-capability and strict-capability-match at the same time";
480 break;
481 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
482 str = "Specify remote-as or peer-group remote AS first";
483 break;
484 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
485 str = "Cannot change the peer-group. Deconfigure first";
486 break;
487 case BGP_ERR_PEER_GROUP_MISMATCH:
488 str = "Peer is not a member of this peer-group";
489 break;
490 case BGP_ERR_PEER_FILTER_CONFLICT:
491 str = "Prefix/distribute list can not co-exist";
492 break;
493 case BGP_ERR_NOT_INTERNAL_PEER:
494 str = "Invalid command. Not an internal neighbor";
495 break;
496 case BGP_ERR_REMOVE_PRIVATE_AS:
497 str = "remove-private-AS cannot be configured for IBGP peers";
498 break;
499 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
500 str = "Local-AS allowed only for EBGP peers";
501 break;
502 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
503 str = "Cannot have local-as same as BGP AS number";
504 break;
505 case BGP_ERR_TCPSIG_FAILED:
506 str = "Error while applying TCP-Sig to session(s)";
507 break;
508 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
509 str = "ebgp-multihop and ttl-security cannot be configured together";
510 break;
511 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
512 str = "ttl-security only allowed for EBGP peers";
513 break;
514 case BGP_ERR_AS_OVERRIDE:
515 str = "as-override cannot be configured for IBGP peers";
516 break;
517 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
518 str = "Invalid limit for number of dynamic neighbors";
519 break;
520 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
521 str = "Dynamic neighbor listen range already exists";
522 break;
523 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
524 str = "Operation not allowed on a dynamic neighbor";
525 break;
526 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
527 str = "Operation not allowed on a directly connected neighbor";
528 break;
529 case BGP_ERR_PEER_SAFI_CONFLICT:
530 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
531 break;
532 }
533 if (str) {
534 vty_out(vty, "%% %s\n", str);
535 return CMD_WARNING_CONFIG_FAILED;
536 }
537 return CMD_SUCCESS;
538 }
539
540 /* BGP clear sort. */
541 enum clear_sort {
542 clear_all,
543 clear_peer,
544 clear_group,
545 clear_external,
546 clear_as
547 };
548
549 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
550 safi_t safi, int error)
551 {
552 switch (error) {
553 case BGP_ERR_AF_UNCONFIGURED:
554 vty_out(vty,
555 "%%BGP: Enable %s address family for the neighbor %s\n",
556 afi_safi_print(afi, safi), peer->host);
557 break;
558 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
559 vty_out(vty,
560 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
561 peer->host);
562 break;
563 default:
564 break;
565 }
566 }
567
568 /* `clear ip bgp' functions. */
569 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
570 enum clear_sort sort, enum bgp_clear_type stype,
571 const char *arg)
572 {
573 int ret;
574 bool found = false;
575 struct peer *peer;
576 struct listnode *node, *nnode;
577
578 /* Clear all neighbors. */
579 /*
580 * Pass along pointer to next node to peer_clear() when walking all
581 * nodes on the BGP instance as that may get freed if it is a
582 * doppelganger
583 */
584 if (sort == clear_all) {
585 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
586 if (!peer->afc[afi][safi])
587 continue;
588
589 if (stype == BGP_CLEAR_SOFT_NONE)
590 ret = peer_clear(peer, &nnode);
591 else
592 ret = peer_clear_soft(peer, afi, safi, stype);
593
594 if (ret < 0)
595 bgp_clear_vty_error(vty, peer, afi, safi, ret);
596 else
597 found = true;
598 }
599
600 /* This is to apply read-only mode on this clear. */
601 if (stype == BGP_CLEAR_SOFT_NONE)
602 bgp->update_delay_over = 0;
603
604 if (!found)
605 vty_out(vty, "%%BGP: No %s peer configured\n",
606 afi_safi_print(afi, safi));
607
608 return CMD_SUCCESS;
609 }
610
611 /* Clear specified neighbor. */
612 if (sort == clear_peer) {
613 union sockunion su;
614
615 /* Make sockunion for lookup. */
616 ret = str2sockunion(arg, &su);
617 if (ret < 0) {
618 peer = peer_lookup_by_conf_if(bgp, arg);
619 if (!peer) {
620 peer = peer_lookup_by_hostname(bgp, arg);
621 if (!peer) {
622 vty_out(vty,
623 "Malformed address or name: %s\n",
624 arg);
625 return CMD_WARNING;
626 }
627 }
628 } else {
629 peer = peer_lookup(bgp, &su);
630 if (!peer) {
631 vty_out(vty,
632 "%%BGP: Unknown neighbor - \"%s\"\n",
633 arg);
634 return CMD_WARNING;
635 }
636 }
637
638 if (!peer->afc[afi][safi])
639 ret = BGP_ERR_AF_UNCONFIGURED;
640 else if (stype == BGP_CLEAR_SOFT_NONE)
641 ret = peer_clear(peer, NULL);
642 else
643 ret = peer_clear_soft(peer, afi, safi, stype);
644
645 if (ret < 0)
646 bgp_clear_vty_error(vty, peer, afi, safi, ret);
647
648 return CMD_SUCCESS;
649 }
650
651 /* Clear all neighbors belonging to a specific peer-group. */
652 if (sort == clear_group) {
653 struct peer_group *group;
654
655 group = peer_group_lookup(bgp, arg);
656 if (!group) {
657 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
658 return CMD_WARNING;
659 }
660
661 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
662 if (!peer->afc[afi][safi])
663 continue;
664
665 if (stype == BGP_CLEAR_SOFT_NONE)
666 ret = peer_clear(peer, NULL);
667 else
668 ret = peer_clear_soft(peer, afi, safi, stype);
669
670 if (ret < 0)
671 bgp_clear_vty_error(vty, peer, afi, safi, ret);
672 else
673 found = true;
674 }
675
676 if (!found)
677 vty_out(vty,
678 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
679 afi_safi_print(afi, safi), arg);
680
681 return CMD_SUCCESS;
682 }
683
684 /* Clear all external (eBGP) neighbors. */
685 if (sort == clear_external) {
686 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
687 if (peer->sort == BGP_PEER_IBGP)
688 continue;
689
690 if (!peer->afc[afi][safi])
691 continue;
692
693 if (stype == BGP_CLEAR_SOFT_NONE)
694 ret = peer_clear(peer, &nnode);
695 else
696 ret = peer_clear_soft(peer, afi, safi, stype);
697
698 if (ret < 0)
699 bgp_clear_vty_error(vty, peer, afi, safi, ret);
700 else
701 found = true;
702 }
703
704 if (!found)
705 vty_out(vty,
706 "%%BGP: No external %s peer is configured\n",
707 afi_safi_print(afi, safi));
708
709 return CMD_SUCCESS;
710 }
711
712 /* Clear all neighbors belonging to a specific AS. */
713 if (sort == clear_as) {
714 as_t as = strtoul(arg, NULL, 10);
715
716 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
717 if (peer->as != as)
718 continue;
719
720 if (!peer->afc[afi][safi])
721 ret = BGP_ERR_AF_UNCONFIGURED;
722 else if (stype == BGP_CLEAR_SOFT_NONE)
723 ret = peer_clear(peer, &nnode);
724 else
725 ret = peer_clear_soft(peer, afi, safi, stype);
726
727 if (ret < 0)
728 bgp_clear_vty_error(vty, peer, afi, safi, ret);
729 else
730 found = true;
731 }
732
733 if (!found)
734 vty_out(vty,
735 "%%BGP: No %s peer is configured with AS %s\n",
736 afi_safi_print(afi, safi), arg);
737
738 return CMD_SUCCESS;
739 }
740
741 return CMD_SUCCESS;
742 }
743
744 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
745 safi_t safi, enum clear_sort sort,
746 enum bgp_clear_type stype, const char *arg)
747 {
748 struct bgp *bgp;
749
750 /* BGP structure lookup. */
751 if (name) {
752 bgp = bgp_lookup_by_name(name);
753 if (bgp == NULL) {
754 vty_out(vty, "Can't find BGP instance %s\n", name);
755 return CMD_WARNING;
756 }
757 } else {
758 bgp = bgp_get_default();
759 if (bgp == NULL) {
760 vty_out(vty, "No BGP process is configured\n");
761 return CMD_WARNING;
762 }
763 }
764
765 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
766 }
767
768 /* clear soft inbound */
769 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
770 {
771 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
772 BGP_CLEAR_SOFT_IN, NULL);
773 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
774 BGP_CLEAR_SOFT_IN, NULL);
775 }
776
777 /* clear soft outbound */
778 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
779 {
780 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
781 BGP_CLEAR_SOFT_OUT, NULL);
782 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
783 BGP_CLEAR_SOFT_OUT, NULL);
784 }
785
786
787 #ifndef VTYSH_EXTRACT_PL
788 #include "bgpd/bgp_vty_clippy.c"
789 #endif
790
791 /* BGP global configuration. */
792 #if (CONFDATE > 20190601)
793 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
794 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
795 #endif
796 DEFUN_HIDDEN (bgp_multiple_instance_func,
797 bgp_multiple_instance_cmd,
798 "bgp multiple-instance",
799 BGP_STR
800 "Enable bgp multiple instance\n")
801 {
802 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
803 return CMD_SUCCESS;
804 }
805
806 DEFUN_HIDDEN (no_bgp_multiple_instance,
807 no_bgp_multiple_instance_cmd,
808 "no bgp multiple-instance",
809 NO_STR
810 BGP_STR
811 "BGP multiple instance\n")
812 {
813 int ret;
814
815 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
816 vty_out(vty, "if you are using this please let the developers know\n");
817 zlog_info("Deprecated option: `bgp multiple-instance` being used");
818 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
819 if (ret < 0) {
820 vty_out(vty, "%% There are more than two BGP instances\n");
821 return CMD_WARNING_CONFIG_FAILED;
822 }
823 return CMD_SUCCESS;
824 }
825
826 DEFUN_HIDDEN (bgp_local_mac,
827 bgp_local_mac_cmd,
828 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
829 BGP_STR
830 "Local MAC config\n"
831 "VxLAN Network Identifier\n"
832 "VNI number\n"
833 "local mac\n"
834 "mac address\n"
835 "mac-mobility sequence\n"
836 "seq number\n")
837 {
838 int rv;
839 vni_t vni;
840 struct ethaddr mac;
841 struct ipaddr ip;
842 uint32_t seq;
843 struct bgp *bgp;
844
845 vni = strtoul(argv[3]->arg, NULL, 10);
846 if (!prefix_str2mac(argv[5]->arg, &mac)) {
847 vty_out(vty, "%% Malformed MAC address\n");
848 return CMD_WARNING;
849 }
850 memset(&ip, 0, sizeof(ip));
851 seq = strtoul(argv[7]->arg, NULL, 10);
852
853 bgp = bgp_get_default();
854 if (!bgp) {
855 vty_out(vty, "Default BGP instance is not there\n");
856 return CMD_WARNING;
857 }
858
859 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
860 if (rv < 0) {
861 vty_out(vty, "Internal error\n");
862 return CMD_WARNING;
863 }
864
865 return CMD_SUCCESS;
866 }
867
868 DEFUN_HIDDEN (no_bgp_local_mac,
869 no_bgp_local_mac_cmd,
870 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
871 NO_STR
872 BGP_STR
873 "Local MAC config\n"
874 "VxLAN Network Identifier\n"
875 "VNI number\n"
876 "local mac\n"
877 "mac address\n")
878 {
879 int rv;
880 vni_t vni;
881 struct ethaddr mac;
882 struct ipaddr ip;
883 struct bgp *bgp;
884
885 vni = strtoul(argv[4]->arg, NULL, 10);
886 if (!prefix_str2mac(argv[6]->arg, &mac)) {
887 vty_out(vty, "%% Malformed MAC address\n");
888 return CMD_WARNING;
889 }
890 memset(&ip, 0, sizeof(ip));
891
892 bgp = bgp_get_default();
893 if (!bgp) {
894 vty_out(vty, "Default BGP instance is not there\n");
895 return CMD_WARNING;
896 }
897
898 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip);
899 if (rv < 0) {
900 vty_out(vty, "Internal error\n");
901 return CMD_WARNING;
902 }
903
904 return CMD_SUCCESS;
905 }
906
907 #if (CONFDATE > 20190601)
908 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
909 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
910 #endif
911 DEFUN_HIDDEN (bgp_config_type,
912 bgp_config_type_cmd,
913 "bgp config-type <cisco|zebra>",
914 BGP_STR
915 "Configuration type\n"
916 "cisco\n"
917 "zebra\n")
918 {
919 int idx = 0;
920 if (argv_find(argv, argc, "cisco", &idx)) {
921 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
922 vty_out(vty, "if you are using this please let the developers know!\n");
923 zlog_info("Deprecated option: `bgp config-type cisco` being used");
924 bgp_option_set(BGP_OPT_CONFIG_CISCO);
925 } else
926 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
927
928 return CMD_SUCCESS;
929 }
930
931 DEFUN_HIDDEN (no_bgp_config_type,
932 no_bgp_config_type_cmd,
933 "no bgp config-type [<cisco|zebra>]",
934 NO_STR
935 BGP_STR
936 "Display configuration type\n"
937 "cisco\n"
938 "zebra\n")
939 {
940 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
941 return CMD_SUCCESS;
942 }
943
944
945 DEFUN (no_synchronization,
946 no_synchronization_cmd,
947 "no synchronization",
948 NO_STR
949 "Perform IGP synchronization\n")
950 {
951 return CMD_SUCCESS;
952 }
953
954 DEFUN (no_auto_summary,
955 no_auto_summary_cmd,
956 "no auto-summary",
957 NO_STR
958 "Enable automatic network number summarization\n")
959 {
960 return CMD_SUCCESS;
961 }
962
963 /* "router bgp" commands. */
964 DEFUN_NOSH (router_bgp,
965 router_bgp_cmd,
966 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
967 ROUTER_STR
968 BGP_STR
969 AS_STR
970 BGP_INSTANCE_HELP_STR)
971 {
972 int idx_asn = 2;
973 int idx_view_vrf = 3;
974 int idx_vrf = 4;
975 int is_new_bgp = 0;
976 int ret;
977 as_t as;
978 struct bgp *bgp;
979 const char *name = NULL;
980 enum bgp_instance_type inst_type;
981
982 // "router bgp" without an ASN
983 if (argc == 2) {
984 // Pending: Make VRF option available for ASN less config
985 bgp = bgp_get_default();
986
987 if (bgp == NULL) {
988 vty_out(vty, "%% No BGP process is configured\n");
989 return CMD_WARNING_CONFIG_FAILED;
990 }
991
992 if (listcount(bm->bgp) > 1) {
993 vty_out(vty, "%% Please specify ASN and VRF\n");
994 return CMD_WARNING_CONFIG_FAILED;
995 }
996 }
997
998 // "router bgp X"
999 else {
1000 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1001
1002 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1003 if (argc > 3) {
1004 name = argv[idx_vrf]->arg;
1005
1006 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1007 if (strmatch(name, VRF_DEFAULT_NAME))
1008 name = NULL;
1009 else
1010 inst_type = BGP_INSTANCE_TYPE_VRF;
1011 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1012 inst_type = BGP_INSTANCE_TYPE_VIEW;
1013 }
1014
1015 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1016 is_new_bgp = (bgp_lookup(as, name) == NULL);
1017
1018 ret = bgp_get(&bgp, &as, name, inst_type);
1019 switch (ret) {
1020 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1021 vty_out(vty,
1022 "Please specify 'bgp multiple-instance' first\n");
1023 return CMD_WARNING_CONFIG_FAILED;
1024 case BGP_ERR_AS_MISMATCH:
1025 vty_out(vty, "BGP is already running; AS is %u\n", as);
1026 return CMD_WARNING_CONFIG_FAILED;
1027 case BGP_ERR_INSTANCE_MISMATCH:
1028 vty_out(vty,
1029 "BGP instance name and AS number mismatch\n");
1030 vty_out(vty,
1031 "BGP instance is already running; AS is %u\n",
1032 as);
1033 return CMD_WARNING_CONFIG_FAILED;
1034 }
1035
1036 /*
1037 * If we just instantiated the default instance, complete
1038 * any pending VRF-VPN leaking that was configured via
1039 * earlier "router bgp X vrf FOO" blocks.
1040 */
1041 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1042 vpn_leak_postchange_all();
1043
1044 /* Pending: handle when user tries to change a view to vrf n vv.
1045 */
1046 }
1047
1048 /* unset the auto created flag as the user config is now present */
1049 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1050 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1051
1052 return CMD_SUCCESS;
1053 }
1054
1055 /* "no router bgp" commands. */
1056 DEFUN (no_router_bgp,
1057 no_router_bgp_cmd,
1058 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1059 NO_STR
1060 ROUTER_STR
1061 BGP_STR
1062 AS_STR
1063 BGP_INSTANCE_HELP_STR)
1064 {
1065 int idx_asn = 3;
1066 int idx_vrf = 5;
1067 as_t as;
1068 struct bgp *bgp;
1069 const char *name = NULL;
1070
1071 // "no router bgp" without an ASN
1072 if (argc == 3) {
1073 // Pending: Make VRF option available for ASN less config
1074 bgp = bgp_get_default();
1075
1076 if (bgp == NULL) {
1077 vty_out(vty, "%% No BGP process is configured\n");
1078 return CMD_WARNING_CONFIG_FAILED;
1079 }
1080
1081 if (listcount(bm->bgp) > 1) {
1082 vty_out(vty, "%% Please specify ASN and VRF\n");
1083 return CMD_WARNING_CONFIG_FAILED;
1084 }
1085
1086 if (bgp->l3vni) {
1087 vty_out(vty, "%% Please unconfigure l3vni %u",
1088 bgp->l3vni);
1089 return CMD_WARNING_CONFIG_FAILED;
1090 }
1091 } else {
1092 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1093
1094 if (argc > 4)
1095 name = argv[idx_vrf]->arg;
1096
1097 /* Lookup bgp structure. */
1098 bgp = bgp_lookup(as, name);
1099 if (!bgp) {
1100 vty_out(vty, "%% Can't find BGP instance\n");
1101 return CMD_WARNING_CONFIG_FAILED;
1102 }
1103
1104 if (bgp->l3vni) {
1105 vty_out(vty, "%% Please unconfigure l3vni %u",
1106 bgp->l3vni);
1107 return CMD_WARNING_CONFIG_FAILED;
1108 }
1109 }
1110
1111 bgp_delete(bgp);
1112
1113 return CMD_SUCCESS;
1114 }
1115
1116
1117 /* BGP router-id. */
1118
1119 DEFPY (bgp_router_id,
1120 bgp_router_id_cmd,
1121 "bgp router-id A.B.C.D",
1122 BGP_STR
1123 "Override configured router identifier\n"
1124 "Manually configured router identifier\n")
1125 {
1126 VTY_DECLVAR_CONTEXT(bgp, bgp);
1127 bgp_router_id_static_set(bgp, router_id);
1128 return CMD_SUCCESS;
1129 }
1130
1131 DEFPY (no_bgp_router_id,
1132 no_bgp_router_id_cmd,
1133 "no bgp router-id [A.B.C.D]",
1134 NO_STR
1135 BGP_STR
1136 "Override configured router identifier\n"
1137 "Manually configured router identifier\n")
1138 {
1139 VTY_DECLVAR_CONTEXT(bgp, bgp);
1140
1141 if (router_id_str) {
1142 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1143 vty_out(vty, "%% BGP router-id doesn't match\n");
1144 return CMD_WARNING_CONFIG_FAILED;
1145 }
1146 }
1147
1148 router_id.s_addr = 0;
1149 bgp_router_id_static_set(bgp, router_id);
1150
1151 return CMD_SUCCESS;
1152 }
1153
1154
1155 /* BGP Cluster ID. */
1156 DEFUN (bgp_cluster_id,
1157 bgp_cluster_id_cmd,
1158 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1159 BGP_STR
1160 "Configure Route-Reflector Cluster-id\n"
1161 "Route-Reflector Cluster-id in IP address format\n"
1162 "Route-Reflector Cluster-id as 32 bit quantity\n")
1163 {
1164 VTY_DECLVAR_CONTEXT(bgp, bgp);
1165 int idx_ipv4 = 2;
1166 int ret;
1167 struct in_addr cluster;
1168
1169 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1170 if (!ret) {
1171 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1172 return CMD_WARNING_CONFIG_FAILED;
1173 }
1174
1175 bgp_cluster_id_set(bgp, &cluster);
1176 bgp_clear_star_soft_out(vty, bgp->name);
1177
1178 return CMD_SUCCESS;
1179 }
1180
1181 DEFUN (no_bgp_cluster_id,
1182 no_bgp_cluster_id_cmd,
1183 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1184 NO_STR
1185 BGP_STR
1186 "Configure Route-Reflector Cluster-id\n"
1187 "Route-Reflector Cluster-id in IP address format\n"
1188 "Route-Reflector Cluster-id as 32 bit quantity\n")
1189 {
1190 VTY_DECLVAR_CONTEXT(bgp, bgp);
1191 bgp_cluster_id_unset(bgp);
1192 bgp_clear_star_soft_out(vty, bgp->name);
1193
1194 return CMD_SUCCESS;
1195 }
1196
1197 DEFUN (bgp_confederation_identifier,
1198 bgp_confederation_identifier_cmd,
1199 "bgp confederation identifier (1-4294967295)",
1200 "BGP specific commands\n"
1201 "AS confederation parameters\n"
1202 "AS number\n"
1203 "Set routing domain confederation AS\n")
1204 {
1205 VTY_DECLVAR_CONTEXT(bgp, bgp);
1206 int idx_number = 3;
1207 as_t as;
1208
1209 as = strtoul(argv[idx_number]->arg, NULL, 10);
1210
1211 bgp_confederation_id_set(bgp, as);
1212
1213 return CMD_SUCCESS;
1214 }
1215
1216 DEFUN (no_bgp_confederation_identifier,
1217 no_bgp_confederation_identifier_cmd,
1218 "no bgp confederation identifier [(1-4294967295)]",
1219 NO_STR
1220 "BGP specific commands\n"
1221 "AS confederation parameters\n"
1222 "AS number\n"
1223 "Set routing domain confederation AS\n")
1224 {
1225 VTY_DECLVAR_CONTEXT(bgp, bgp);
1226 bgp_confederation_id_unset(bgp);
1227
1228 return CMD_SUCCESS;
1229 }
1230
1231 DEFUN (bgp_confederation_peers,
1232 bgp_confederation_peers_cmd,
1233 "bgp confederation peers (1-4294967295)...",
1234 "BGP specific commands\n"
1235 "AS confederation parameters\n"
1236 "Peer ASs in BGP confederation\n"
1237 AS_STR)
1238 {
1239 VTY_DECLVAR_CONTEXT(bgp, bgp);
1240 int idx_asn = 3;
1241 as_t as;
1242 int i;
1243
1244 for (i = idx_asn; i < argc; i++) {
1245 as = strtoul(argv[i]->arg, NULL, 10);
1246
1247 if (bgp->as == as) {
1248 vty_out(vty,
1249 "%% Local member-AS not allowed in confed peer list\n");
1250 continue;
1251 }
1252
1253 bgp_confederation_peers_add(bgp, as);
1254 }
1255 return CMD_SUCCESS;
1256 }
1257
1258 DEFUN (no_bgp_confederation_peers,
1259 no_bgp_confederation_peers_cmd,
1260 "no bgp confederation peers (1-4294967295)...",
1261 NO_STR
1262 "BGP specific commands\n"
1263 "AS confederation parameters\n"
1264 "Peer ASs in BGP confederation\n"
1265 AS_STR)
1266 {
1267 VTY_DECLVAR_CONTEXT(bgp, bgp);
1268 int idx_asn = 4;
1269 as_t as;
1270 int i;
1271
1272 for (i = idx_asn; i < argc; i++) {
1273 as = strtoul(argv[i]->arg, NULL, 10);
1274
1275 bgp_confederation_peers_remove(bgp, as);
1276 }
1277 return CMD_SUCCESS;
1278 }
1279
1280 /**
1281 * Central routine for maximum-paths configuration.
1282 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1283 * @set: 1 for setting values, 0 for removing the max-paths config.
1284 */
1285 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1286 const char *mpaths, uint16_t options,
1287 int set)
1288 {
1289 VTY_DECLVAR_CONTEXT(bgp, bgp);
1290 uint16_t maxpaths = 0;
1291 int ret;
1292 afi_t afi;
1293 safi_t safi;
1294
1295 afi = bgp_node_afi(vty);
1296 safi = bgp_node_safi(vty);
1297
1298 if (set) {
1299 maxpaths = strtol(mpaths, NULL, 10);
1300 if (maxpaths > multipath_num) {
1301 vty_out(vty,
1302 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1303 maxpaths, multipath_num);
1304 return CMD_WARNING_CONFIG_FAILED;
1305 }
1306 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1307 options);
1308 } else
1309 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1310
1311 if (ret < 0) {
1312 vty_out(vty,
1313 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1314 (set == 1) ? "" : "un",
1315 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1316 maxpaths, afi, safi);
1317 return CMD_WARNING_CONFIG_FAILED;
1318 }
1319
1320 bgp_recalculate_all_bestpaths(bgp);
1321
1322 return CMD_SUCCESS;
1323 }
1324
1325 DEFUN (bgp_maxmed_admin,
1326 bgp_maxmed_admin_cmd,
1327 "bgp max-med administrative ",
1328 BGP_STR
1329 "Advertise routes with max-med\n"
1330 "Administratively applied, for an indefinite period\n")
1331 {
1332 VTY_DECLVAR_CONTEXT(bgp, bgp);
1333
1334 bgp->v_maxmed_admin = 1;
1335 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1336
1337 bgp_maxmed_update(bgp);
1338
1339 return CMD_SUCCESS;
1340 }
1341
1342 DEFUN (bgp_maxmed_admin_medv,
1343 bgp_maxmed_admin_medv_cmd,
1344 "bgp max-med administrative (0-4294967295)",
1345 BGP_STR
1346 "Advertise routes with max-med\n"
1347 "Administratively applied, for an indefinite period\n"
1348 "Max MED value to be used\n")
1349 {
1350 VTY_DECLVAR_CONTEXT(bgp, bgp);
1351 int idx_number = 3;
1352
1353 bgp->v_maxmed_admin = 1;
1354 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1355
1356 bgp_maxmed_update(bgp);
1357
1358 return CMD_SUCCESS;
1359 }
1360
1361 DEFUN (no_bgp_maxmed_admin,
1362 no_bgp_maxmed_admin_cmd,
1363 "no bgp max-med administrative [(0-4294967295)]",
1364 NO_STR
1365 BGP_STR
1366 "Advertise routes with max-med\n"
1367 "Administratively applied, for an indefinite period\n"
1368 "Max MED value to be used\n")
1369 {
1370 VTY_DECLVAR_CONTEXT(bgp, bgp);
1371 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1372 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1373 bgp_maxmed_update(bgp);
1374
1375 return CMD_SUCCESS;
1376 }
1377
1378 DEFUN (bgp_maxmed_onstartup,
1379 bgp_maxmed_onstartup_cmd,
1380 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1381 BGP_STR
1382 "Advertise routes with max-med\n"
1383 "Effective on a startup\n"
1384 "Time (seconds) period for max-med\n"
1385 "Max MED value to be used\n")
1386 {
1387 VTY_DECLVAR_CONTEXT(bgp, bgp);
1388 int idx = 0;
1389
1390 argv_find(argv, argc, "(5-86400)", &idx);
1391 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1392 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1393 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1394 else
1395 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1396
1397 bgp_maxmed_update(bgp);
1398
1399 return CMD_SUCCESS;
1400 }
1401
1402 DEFUN (no_bgp_maxmed_onstartup,
1403 no_bgp_maxmed_onstartup_cmd,
1404 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1405 NO_STR
1406 BGP_STR
1407 "Advertise routes with max-med\n"
1408 "Effective on a startup\n"
1409 "Time (seconds) period for max-med\n"
1410 "Max MED value to be used\n")
1411 {
1412 VTY_DECLVAR_CONTEXT(bgp, bgp);
1413
1414 /* Cancel max-med onstartup if its on */
1415 if (bgp->t_maxmed_onstartup) {
1416 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1417 bgp->maxmed_onstartup_over = 1;
1418 }
1419
1420 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1421 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1422
1423 bgp_maxmed_update(bgp);
1424
1425 return CMD_SUCCESS;
1426 }
1427
1428 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1429 const char *wait)
1430 {
1431 VTY_DECLVAR_CONTEXT(bgp, bgp);
1432 uint16_t update_delay;
1433 uint16_t establish_wait;
1434
1435 update_delay = strtoul(delay, NULL, 10);
1436
1437 if (!wait) /* update-delay <delay> */
1438 {
1439 bgp->v_update_delay = update_delay;
1440 bgp->v_establish_wait = bgp->v_update_delay;
1441 return CMD_SUCCESS;
1442 }
1443
1444 /* update-delay <delay> <establish-wait> */
1445 establish_wait = atoi(wait);
1446 if (update_delay < establish_wait) {
1447 vty_out(vty,
1448 "%%Failed: update-delay less than the establish-wait!\n");
1449 return CMD_WARNING_CONFIG_FAILED;
1450 }
1451
1452 bgp->v_update_delay = update_delay;
1453 bgp->v_establish_wait = establish_wait;
1454
1455 return CMD_SUCCESS;
1456 }
1457
1458 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1459 {
1460 VTY_DECLVAR_CONTEXT(bgp, bgp);
1461
1462 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1463 bgp->v_establish_wait = bgp->v_update_delay;
1464
1465 return CMD_SUCCESS;
1466 }
1467
1468 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1469 {
1470 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1471 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1472 if (bgp->v_update_delay != bgp->v_establish_wait)
1473 vty_out(vty, " %d", bgp->v_establish_wait);
1474 vty_out(vty, "\n");
1475 }
1476 }
1477
1478
1479 /* Update-delay configuration */
1480 DEFUN (bgp_update_delay,
1481 bgp_update_delay_cmd,
1482 "update-delay (0-3600)",
1483 "Force initial delay for best-path and updates\n"
1484 "Seconds\n")
1485 {
1486 int idx_number = 1;
1487 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1488 }
1489
1490 DEFUN (bgp_update_delay_establish_wait,
1491 bgp_update_delay_establish_wait_cmd,
1492 "update-delay (0-3600) (1-3600)",
1493 "Force initial delay for best-path and updates\n"
1494 "Seconds\n"
1495 "Seconds\n")
1496 {
1497 int idx_number = 1;
1498 int idx_number_2 = 2;
1499 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1500 argv[idx_number_2]->arg);
1501 }
1502
1503 /* Update-delay deconfiguration */
1504 DEFUN (no_bgp_update_delay,
1505 no_bgp_update_delay_cmd,
1506 "no update-delay [(0-3600) [(1-3600)]]",
1507 NO_STR
1508 "Force initial delay for best-path and updates\n"
1509 "Seconds\n"
1510 "Seconds\n")
1511 {
1512 return bgp_update_delay_deconfig_vty(vty);
1513 }
1514
1515
1516 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1517 char set)
1518 {
1519 VTY_DECLVAR_CONTEXT(bgp, bgp);
1520
1521 if (set) {
1522 uint32_t quanta = strtoul(num, NULL, 10);
1523 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1524 memory_order_relaxed);
1525 } else {
1526 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1527 memory_order_relaxed);
1528 }
1529
1530 return CMD_SUCCESS;
1531 }
1532
1533 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1534 char set)
1535 {
1536 VTY_DECLVAR_CONTEXT(bgp, bgp);
1537
1538 if (set) {
1539 uint32_t quanta = strtoul(num, NULL, 10);
1540 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1541 memory_order_relaxed);
1542 } else {
1543 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1544 memory_order_relaxed);
1545 }
1546
1547 return CMD_SUCCESS;
1548 }
1549
1550 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1551 {
1552 uint32_t quanta =
1553 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1554 if (quanta != BGP_WRITE_PACKET_MAX)
1555 vty_out(vty, " write-quanta %d\n", quanta);
1556 }
1557
1558 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1559 {
1560 uint32_t quanta =
1561 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1562 if (quanta != BGP_READ_PACKET_MAX)
1563 vty_out(vty, " read-quanta %d\n", quanta);
1564 }
1565
1566 /* Packet quanta configuration */
1567 DEFUN (bgp_wpkt_quanta,
1568 bgp_wpkt_quanta_cmd,
1569 "write-quanta (1-10)",
1570 "How many packets to write to peer socket per run\n"
1571 "Number of packets\n")
1572 {
1573 int idx_number = 1;
1574 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1575 }
1576
1577 DEFUN (no_bgp_wpkt_quanta,
1578 no_bgp_wpkt_quanta_cmd,
1579 "no write-quanta (1-10)",
1580 NO_STR
1581 "How many packets to write to peer socket per I/O cycle\n"
1582 "Number of packets\n")
1583 {
1584 int idx_number = 2;
1585 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1586 }
1587
1588 DEFUN (bgp_rpkt_quanta,
1589 bgp_rpkt_quanta_cmd,
1590 "read-quanta (1-10)",
1591 "How many packets to read from peer socket per I/O cycle\n"
1592 "Number of packets\n")
1593 {
1594 int idx_number = 1;
1595 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1596 }
1597
1598 DEFUN (no_bgp_rpkt_quanta,
1599 no_bgp_rpkt_quanta_cmd,
1600 "no read-quanta (1-10)",
1601 NO_STR
1602 "How many packets to read from peer socket per I/O cycle\n"
1603 "Number of packets\n")
1604 {
1605 int idx_number = 2;
1606 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1607 }
1608
1609 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1610 {
1611 if (!bgp->heuristic_coalesce)
1612 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1613 }
1614
1615
1616 DEFUN (bgp_coalesce_time,
1617 bgp_coalesce_time_cmd,
1618 "coalesce-time (0-4294967295)",
1619 "Subgroup coalesce timer\n"
1620 "Subgroup coalesce timer value (in ms)\n")
1621 {
1622 VTY_DECLVAR_CONTEXT(bgp, bgp);
1623
1624 int idx = 0;
1625 argv_find(argv, argc, "(0-4294967295)", &idx);
1626 bgp->heuristic_coalesce = false;
1627 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1628 return CMD_SUCCESS;
1629 }
1630
1631 DEFUN (no_bgp_coalesce_time,
1632 no_bgp_coalesce_time_cmd,
1633 "no coalesce-time (0-4294967295)",
1634 NO_STR
1635 "Subgroup coalesce timer\n"
1636 "Subgroup coalesce timer value (in ms)\n")
1637 {
1638 VTY_DECLVAR_CONTEXT(bgp, bgp);
1639
1640 bgp->heuristic_coalesce = true;
1641 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1642 return CMD_SUCCESS;
1643 }
1644
1645 /* Maximum-paths configuration */
1646 DEFUN (bgp_maxpaths,
1647 bgp_maxpaths_cmd,
1648 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1649 "Forward packets over multiple paths\n"
1650 "Number of paths\n")
1651 {
1652 int idx_number = 1;
1653 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1654 argv[idx_number]->arg, 0, 1);
1655 }
1656
1657 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1658 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1659 "Forward packets over multiple paths\n"
1660 "Number of paths\n")
1661
1662 DEFUN (bgp_maxpaths_ibgp,
1663 bgp_maxpaths_ibgp_cmd,
1664 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1665 "Forward packets over multiple paths\n"
1666 "iBGP-multipath\n"
1667 "Number of paths\n")
1668 {
1669 int idx_number = 2;
1670 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1671 argv[idx_number]->arg, 0, 1);
1672 }
1673
1674 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1675 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1676 "Forward packets over multiple paths\n"
1677 "iBGP-multipath\n"
1678 "Number of paths\n")
1679
1680 DEFUN (bgp_maxpaths_ibgp_cluster,
1681 bgp_maxpaths_ibgp_cluster_cmd,
1682 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1683 "Forward packets over multiple paths\n"
1684 "iBGP-multipath\n"
1685 "Number of paths\n"
1686 "Match the cluster length\n")
1687 {
1688 int idx_number = 2;
1689 return bgp_maxpaths_config_vty(
1690 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1691 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1692 }
1693
1694 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1695 "maximum-paths ibgp " CMD_RANGE_STR(
1696 1, MULTIPATH_NUM) " equal-cluster-length",
1697 "Forward packets over multiple paths\n"
1698 "iBGP-multipath\n"
1699 "Number of paths\n"
1700 "Match the cluster length\n")
1701
1702 DEFUN (no_bgp_maxpaths,
1703 no_bgp_maxpaths_cmd,
1704 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1705 NO_STR
1706 "Forward packets over multiple paths\n"
1707 "Number of paths\n")
1708 {
1709 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1710 }
1711
1712 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1713 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1714 "Forward packets over multiple paths\n"
1715 "Number of paths\n")
1716
1717 DEFUN (no_bgp_maxpaths_ibgp,
1718 no_bgp_maxpaths_ibgp_cmd,
1719 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1720 NO_STR
1721 "Forward packets over multiple paths\n"
1722 "iBGP-multipath\n"
1723 "Number of paths\n"
1724 "Match the cluster length\n")
1725 {
1726 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1727 }
1728
1729 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1730 "no maximum-paths ibgp [" CMD_RANGE_STR(
1731 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1732 NO_STR
1733 "Forward packets over multiple paths\n"
1734 "iBGP-multipath\n"
1735 "Number of paths\n"
1736 "Match the cluster length\n")
1737
1738 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1739 safi_t safi)
1740 {
1741 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1742 vty_out(vty, " maximum-paths %d\n",
1743 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1744 }
1745
1746 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1747 vty_out(vty, " maximum-paths ibgp %d",
1748 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1749 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1750 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1751 vty_out(vty, " equal-cluster-length");
1752 vty_out(vty, "\n");
1753 }
1754 }
1755
1756 /* BGP timers. */
1757
1758 DEFUN (bgp_timers,
1759 bgp_timers_cmd,
1760 "timers bgp (0-65535) (0-65535)",
1761 "Adjust routing timers\n"
1762 "BGP timers\n"
1763 "Keepalive interval\n"
1764 "Holdtime\n")
1765 {
1766 VTY_DECLVAR_CONTEXT(bgp, bgp);
1767 int idx_number = 2;
1768 int idx_number_2 = 3;
1769 unsigned long keepalive = 0;
1770 unsigned long holdtime = 0;
1771
1772 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1773 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1774
1775 /* Holdtime value check. */
1776 if (holdtime < 3 && holdtime != 0) {
1777 vty_out(vty,
1778 "%% hold time value must be either 0 or greater than 3\n");
1779 return CMD_WARNING_CONFIG_FAILED;
1780 }
1781
1782 bgp_timers_set(bgp, keepalive, holdtime);
1783
1784 return CMD_SUCCESS;
1785 }
1786
1787 DEFUN (no_bgp_timers,
1788 no_bgp_timers_cmd,
1789 "no timers bgp [(0-65535) (0-65535)]",
1790 NO_STR
1791 "Adjust routing timers\n"
1792 "BGP timers\n"
1793 "Keepalive interval\n"
1794 "Holdtime\n")
1795 {
1796 VTY_DECLVAR_CONTEXT(bgp, bgp);
1797 bgp_timers_unset(bgp);
1798
1799 return CMD_SUCCESS;
1800 }
1801
1802
1803 DEFUN (bgp_client_to_client_reflection,
1804 bgp_client_to_client_reflection_cmd,
1805 "bgp client-to-client reflection",
1806 "BGP specific commands\n"
1807 "Configure client to client route reflection\n"
1808 "reflection of routes allowed\n")
1809 {
1810 VTY_DECLVAR_CONTEXT(bgp, bgp);
1811 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1812 bgp_clear_star_soft_out(vty, bgp->name);
1813
1814 return CMD_SUCCESS;
1815 }
1816
1817 DEFUN (no_bgp_client_to_client_reflection,
1818 no_bgp_client_to_client_reflection_cmd,
1819 "no bgp client-to-client reflection",
1820 NO_STR
1821 "BGP specific commands\n"
1822 "Configure client to client route reflection\n"
1823 "reflection of routes allowed\n")
1824 {
1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1827 bgp_clear_star_soft_out(vty, bgp->name);
1828
1829 return CMD_SUCCESS;
1830 }
1831
1832 /* "bgp always-compare-med" configuration. */
1833 DEFUN (bgp_always_compare_med,
1834 bgp_always_compare_med_cmd,
1835 "bgp always-compare-med",
1836 "BGP specific commands\n"
1837 "Allow comparing MED from different neighbors\n")
1838 {
1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1841 bgp_recalculate_all_bestpaths(bgp);
1842
1843 return CMD_SUCCESS;
1844 }
1845
1846 DEFUN (no_bgp_always_compare_med,
1847 no_bgp_always_compare_med_cmd,
1848 "no bgp always-compare-med",
1849 NO_STR
1850 "BGP specific commands\n"
1851 "Allow comparing MED from different neighbors\n")
1852 {
1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
1854 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1855 bgp_recalculate_all_bestpaths(bgp);
1856
1857 return CMD_SUCCESS;
1858 }
1859
1860 /* "bgp deterministic-med" configuration. */
1861 DEFUN (bgp_deterministic_med,
1862 bgp_deterministic_med_cmd,
1863 "bgp deterministic-med",
1864 "BGP specific commands\n"
1865 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1866 {
1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868
1869 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1870 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1871 bgp_recalculate_all_bestpaths(bgp);
1872 }
1873
1874 return CMD_SUCCESS;
1875 }
1876
1877 DEFUN (no_bgp_deterministic_med,
1878 no_bgp_deterministic_med_cmd,
1879 "no bgp deterministic-med",
1880 NO_STR
1881 "BGP specific commands\n"
1882 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1883 {
1884 VTY_DECLVAR_CONTEXT(bgp, bgp);
1885 int bestpath_per_as_used;
1886 afi_t afi;
1887 safi_t safi;
1888 struct peer *peer;
1889 struct listnode *node, *nnode;
1890
1891 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1892 bestpath_per_as_used = 0;
1893
1894 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1895 FOREACH_AFI_SAFI (afi, safi)
1896 if (bgp_addpath_dmed_required(
1897 peer->addpath_type[afi][safi])) {
1898 bestpath_per_as_used = 1;
1899 break;
1900 }
1901
1902 if (bestpath_per_as_used)
1903 break;
1904 }
1905
1906 if (bestpath_per_as_used) {
1907 vty_out(vty,
1908 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1909 return CMD_WARNING_CONFIG_FAILED;
1910 } else {
1911 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1912 bgp_recalculate_all_bestpaths(bgp);
1913 }
1914 }
1915
1916 return CMD_SUCCESS;
1917 }
1918
1919 /* "bgp graceful-restart" configuration. */
1920 DEFUN (bgp_graceful_restart,
1921 bgp_graceful_restart_cmd,
1922 "bgp graceful-restart",
1923 "BGP specific commands\n"
1924 "Graceful restart capability parameters\n")
1925 {
1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1928 return CMD_SUCCESS;
1929 }
1930
1931 DEFUN (no_bgp_graceful_restart,
1932 no_bgp_graceful_restart_cmd,
1933 "no bgp graceful-restart",
1934 NO_STR
1935 "BGP specific commands\n"
1936 "Graceful restart capability parameters\n")
1937 {
1938 VTY_DECLVAR_CONTEXT(bgp, bgp);
1939 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1940 return CMD_SUCCESS;
1941 }
1942
1943 DEFUN (bgp_graceful_restart_stalepath_time,
1944 bgp_graceful_restart_stalepath_time_cmd,
1945 "bgp graceful-restart stalepath-time (1-3600)",
1946 "BGP specific commands\n"
1947 "Graceful restart capability parameters\n"
1948 "Set the max time to hold onto restarting peer's stale paths\n"
1949 "Delay value (seconds)\n")
1950 {
1951 VTY_DECLVAR_CONTEXT(bgp, bgp);
1952 int idx_number = 3;
1953 uint32_t stalepath;
1954
1955 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1956 bgp->stalepath_time = stalepath;
1957 return CMD_SUCCESS;
1958 }
1959
1960 DEFUN (bgp_graceful_restart_restart_time,
1961 bgp_graceful_restart_restart_time_cmd,
1962 "bgp graceful-restart restart-time (1-3600)",
1963 "BGP specific commands\n"
1964 "Graceful restart capability parameters\n"
1965 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1966 "Delay value (seconds)\n")
1967 {
1968 VTY_DECLVAR_CONTEXT(bgp, bgp);
1969 int idx_number = 3;
1970 uint32_t restart;
1971
1972 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1973 bgp->restart_time = restart;
1974 return CMD_SUCCESS;
1975 }
1976
1977 DEFUN (no_bgp_graceful_restart_stalepath_time,
1978 no_bgp_graceful_restart_stalepath_time_cmd,
1979 "no bgp graceful-restart stalepath-time [(1-3600)]",
1980 NO_STR
1981 "BGP specific commands\n"
1982 "Graceful restart capability parameters\n"
1983 "Set the max time to hold onto restarting peer's stale paths\n"
1984 "Delay value (seconds)\n")
1985 {
1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
1987
1988 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1989 return CMD_SUCCESS;
1990 }
1991
1992 DEFUN (no_bgp_graceful_restart_restart_time,
1993 no_bgp_graceful_restart_restart_time_cmd,
1994 "no bgp graceful-restart restart-time [(1-3600)]",
1995 NO_STR
1996 "BGP specific commands\n"
1997 "Graceful restart capability parameters\n"
1998 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1999 "Delay value (seconds)\n")
2000 {
2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002
2003 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2004 return CMD_SUCCESS;
2005 }
2006
2007 DEFUN (bgp_graceful_restart_preserve_fw,
2008 bgp_graceful_restart_preserve_fw_cmd,
2009 "bgp graceful-restart preserve-fw-state",
2010 "BGP specific commands\n"
2011 "Graceful restart capability parameters\n"
2012 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2013 {
2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2016 return CMD_SUCCESS;
2017 }
2018
2019 DEFUN (no_bgp_graceful_restart_preserve_fw,
2020 no_bgp_graceful_restart_preserve_fw_cmd,
2021 "no bgp graceful-restart preserve-fw-state",
2022 NO_STR
2023 "BGP specific commands\n"
2024 "Graceful restart capability parameters\n"
2025 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2026 {
2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
2028 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2029 return CMD_SUCCESS;
2030 }
2031
2032 static void bgp_redistribute_redo(struct bgp *bgp)
2033 {
2034 afi_t afi;
2035 int i;
2036 struct list *red_list;
2037 struct listnode *node;
2038 struct bgp_redist *red;
2039
2040 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2041 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
2042
2043 red_list = bgp->redist[afi][i];
2044 if (!red_list)
2045 continue;
2046
2047 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
2048 bgp_redistribute_resend(bgp, afi, i,
2049 red->instance);
2050 }
2051 }
2052 }
2053 }
2054
2055 /* "bgp graceful-shutdown" configuration */
2056 DEFUN (bgp_graceful_shutdown,
2057 bgp_graceful_shutdown_cmd,
2058 "bgp graceful-shutdown",
2059 BGP_STR
2060 "Graceful shutdown parameters\n")
2061 {
2062 VTY_DECLVAR_CONTEXT(bgp, bgp);
2063
2064 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2065 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2066 bgp_static_redo_import_check(bgp);
2067 bgp_redistribute_redo(bgp);
2068 bgp_clear_star_soft_out(vty, bgp->name);
2069 bgp_clear_star_soft_in(vty, bgp->name);
2070 }
2071
2072 return CMD_SUCCESS;
2073 }
2074
2075 DEFUN (no_bgp_graceful_shutdown,
2076 no_bgp_graceful_shutdown_cmd,
2077 "no bgp graceful-shutdown",
2078 NO_STR
2079 BGP_STR
2080 "Graceful shutdown parameters\n")
2081 {
2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083
2084 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2085 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2086 bgp_static_redo_import_check(bgp);
2087 bgp_redistribute_redo(bgp);
2088 bgp_clear_star_soft_out(vty, bgp->name);
2089 bgp_clear_star_soft_in(vty, bgp->name);
2090 }
2091
2092 return CMD_SUCCESS;
2093 }
2094
2095 /* "bgp fast-external-failover" configuration. */
2096 DEFUN (bgp_fast_external_failover,
2097 bgp_fast_external_failover_cmd,
2098 "bgp fast-external-failover",
2099 BGP_STR
2100 "Immediately reset session if a link to a directly connected external peer goes down\n")
2101 {
2102 VTY_DECLVAR_CONTEXT(bgp, bgp);
2103 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2104 return CMD_SUCCESS;
2105 }
2106
2107 DEFUN (no_bgp_fast_external_failover,
2108 no_bgp_fast_external_failover_cmd,
2109 "no bgp fast-external-failover",
2110 NO_STR
2111 BGP_STR
2112 "Immediately reset session if a link to a directly connected external peer goes down\n")
2113 {
2114 VTY_DECLVAR_CONTEXT(bgp, bgp);
2115 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2116 return CMD_SUCCESS;
2117 }
2118
2119 /* "bgp enforce-first-as" configuration. */
2120 #if CONFDATE > 20190517
2121 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2122 #endif
2123
2124 DEFUN_HIDDEN (bgp_enforce_first_as,
2125 bgp_enforce_first_as_cmd,
2126 "[no] bgp enforce-first-as",
2127 NO_STR
2128 BGP_STR
2129 "Enforce the first AS for EBGP routes\n")
2130 {
2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
2132
2133 if (strmatch(argv[0]->text, "no"))
2134 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2135 else
2136 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2137
2138 return CMD_SUCCESS;
2139 }
2140
2141 /* "bgp bestpath compare-routerid" configuration. */
2142 DEFUN (bgp_bestpath_compare_router_id,
2143 bgp_bestpath_compare_router_id_cmd,
2144 "bgp bestpath compare-routerid",
2145 "BGP specific commands\n"
2146 "Change the default bestpath selection\n"
2147 "Compare router-id for identical EBGP paths\n")
2148 {
2149 VTY_DECLVAR_CONTEXT(bgp, bgp);
2150 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2151 bgp_recalculate_all_bestpaths(bgp);
2152
2153 return CMD_SUCCESS;
2154 }
2155
2156 DEFUN (no_bgp_bestpath_compare_router_id,
2157 no_bgp_bestpath_compare_router_id_cmd,
2158 "no bgp bestpath compare-routerid",
2159 NO_STR
2160 "BGP specific commands\n"
2161 "Change the default bestpath selection\n"
2162 "Compare router-id for identical EBGP paths\n")
2163 {
2164 VTY_DECLVAR_CONTEXT(bgp, bgp);
2165 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2166 bgp_recalculate_all_bestpaths(bgp);
2167
2168 return CMD_SUCCESS;
2169 }
2170
2171 /* "bgp bestpath as-path ignore" configuration. */
2172 DEFUN (bgp_bestpath_aspath_ignore,
2173 bgp_bestpath_aspath_ignore_cmd,
2174 "bgp bestpath as-path ignore",
2175 "BGP specific commands\n"
2176 "Change the default bestpath selection\n"
2177 "AS-path attribute\n"
2178 "Ignore as-path length in selecting a route\n")
2179 {
2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
2181 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2182 bgp_recalculate_all_bestpaths(bgp);
2183
2184 return CMD_SUCCESS;
2185 }
2186
2187 DEFUN (no_bgp_bestpath_aspath_ignore,
2188 no_bgp_bestpath_aspath_ignore_cmd,
2189 "no bgp bestpath as-path ignore",
2190 NO_STR
2191 "BGP specific commands\n"
2192 "Change the default bestpath selection\n"
2193 "AS-path attribute\n"
2194 "Ignore as-path length in selecting a route\n")
2195 {
2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
2197 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2198 bgp_recalculate_all_bestpaths(bgp);
2199
2200 return CMD_SUCCESS;
2201 }
2202
2203 /* "bgp bestpath as-path confed" configuration. */
2204 DEFUN (bgp_bestpath_aspath_confed,
2205 bgp_bestpath_aspath_confed_cmd,
2206 "bgp bestpath as-path confed",
2207 "BGP specific commands\n"
2208 "Change the default bestpath selection\n"
2209 "AS-path attribute\n"
2210 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2211 {
2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
2213 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2214 bgp_recalculate_all_bestpaths(bgp);
2215
2216 return CMD_SUCCESS;
2217 }
2218
2219 DEFUN (no_bgp_bestpath_aspath_confed,
2220 no_bgp_bestpath_aspath_confed_cmd,
2221 "no bgp bestpath as-path confed",
2222 NO_STR
2223 "BGP specific commands\n"
2224 "Change the default bestpath selection\n"
2225 "AS-path attribute\n"
2226 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2227 {
2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2230 bgp_recalculate_all_bestpaths(bgp);
2231
2232 return CMD_SUCCESS;
2233 }
2234
2235 /* "bgp bestpath as-path multipath-relax" configuration. */
2236 DEFUN (bgp_bestpath_aspath_multipath_relax,
2237 bgp_bestpath_aspath_multipath_relax_cmd,
2238 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2239 "BGP specific commands\n"
2240 "Change the default bestpath selection\n"
2241 "AS-path attribute\n"
2242 "Allow load sharing across routes that have different AS paths (but same length)\n"
2243 "Generate an AS_SET\n"
2244 "Do not generate an AS_SET\n")
2245 {
2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
2247 int idx = 0;
2248 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2249
2250 /* no-as-set is now the default behavior so we can silently
2251 * ignore it */
2252 if (argv_find(argv, argc, "as-set", &idx))
2253 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2254 else
2255 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2256
2257 bgp_recalculate_all_bestpaths(bgp);
2258
2259 return CMD_SUCCESS;
2260 }
2261
2262 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2263 no_bgp_bestpath_aspath_multipath_relax_cmd,
2264 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2265 NO_STR
2266 "BGP specific commands\n"
2267 "Change the default bestpath selection\n"
2268 "AS-path attribute\n"
2269 "Allow load sharing across routes that have different AS paths (but same length)\n"
2270 "Generate an AS_SET\n"
2271 "Do not generate an AS_SET\n")
2272 {
2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2275 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2276 bgp_recalculate_all_bestpaths(bgp);
2277
2278 return CMD_SUCCESS;
2279 }
2280
2281 /* "bgp log-neighbor-changes" configuration. */
2282 DEFUN (bgp_log_neighbor_changes,
2283 bgp_log_neighbor_changes_cmd,
2284 "bgp log-neighbor-changes",
2285 "BGP specific commands\n"
2286 "Log neighbor up/down and reset reason\n")
2287 {
2288 VTY_DECLVAR_CONTEXT(bgp, bgp);
2289 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2290 return CMD_SUCCESS;
2291 }
2292
2293 DEFUN (no_bgp_log_neighbor_changes,
2294 no_bgp_log_neighbor_changes_cmd,
2295 "no bgp log-neighbor-changes",
2296 NO_STR
2297 "BGP specific commands\n"
2298 "Log neighbor up/down and reset reason\n")
2299 {
2300 VTY_DECLVAR_CONTEXT(bgp, bgp);
2301 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2302 return CMD_SUCCESS;
2303 }
2304
2305 /* "bgp bestpath med" configuration. */
2306 DEFUN (bgp_bestpath_med,
2307 bgp_bestpath_med_cmd,
2308 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2309 "BGP specific commands\n"
2310 "Change the default bestpath selection\n"
2311 "MED attribute\n"
2312 "Compare MED among confederation paths\n"
2313 "Treat missing MED as the least preferred one\n"
2314 "Treat missing MED as the least preferred one\n"
2315 "Compare MED among confederation paths\n")
2316 {
2317 VTY_DECLVAR_CONTEXT(bgp, bgp);
2318
2319 int idx = 0;
2320 if (argv_find(argv, argc, "confed", &idx))
2321 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2322 idx = 0;
2323 if (argv_find(argv, argc, "missing-as-worst", &idx))
2324 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2325
2326 bgp_recalculate_all_bestpaths(bgp);
2327
2328 return CMD_SUCCESS;
2329 }
2330
2331 DEFUN (no_bgp_bestpath_med,
2332 no_bgp_bestpath_med_cmd,
2333 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2334 NO_STR
2335 "BGP specific commands\n"
2336 "Change the default bestpath selection\n"
2337 "MED attribute\n"
2338 "Compare MED among confederation paths\n"
2339 "Treat missing MED as the least preferred one\n"
2340 "Treat missing MED as the least preferred one\n"
2341 "Compare MED among confederation paths\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344
2345 int idx = 0;
2346 if (argv_find(argv, argc, "confed", &idx))
2347 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2348 idx = 0;
2349 if (argv_find(argv, argc, "missing-as-worst", &idx))
2350 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2351
2352 bgp_recalculate_all_bestpaths(bgp);
2353
2354 return CMD_SUCCESS;
2355 }
2356
2357 /* "no bgp default ipv4-unicast". */
2358 DEFUN (no_bgp_default_ipv4_unicast,
2359 no_bgp_default_ipv4_unicast_cmd,
2360 "no bgp default ipv4-unicast",
2361 NO_STR
2362 "BGP specific commands\n"
2363 "Configure BGP defaults\n"
2364 "Activate ipv4-unicast for a peer by default\n")
2365 {
2366 VTY_DECLVAR_CONTEXT(bgp, bgp);
2367 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2368 return CMD_SUCCESS;
2369 }
2370
2371 DEFUN (bgp_default_ipv4_unicast,
2372 bgp_default_ipv4_unicast_cmd,
2373 "bgp default ipv4-unicast",
2374 "BGP specific commands\n"
2375 "Configure BGP defaults\n"
2376 "Activate ipv4-unicast for a peer by default\n")
2377 {
2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
2379 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2380 return CMD_SUCCESS;
2381 }
2382
2383 /* Display hostname in certain command outputs */
2384 DEFUN (bgp_default_show_hostname,
2385 bgp_default_show_hostname_cmd,
2386 "bgp default show-hostname",
2387 "BGP specific commands\n"
2388 "Configure BGP defaults\n"
2389 "Show hostname in certain command outputs\n")
2390 {
2391 VTY_DECLVAR_CONTEXT(bgp, bgp);
2392 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2393 return CMD_SUCCESS;
2394 }
2395
2396 DEFUN (no_bgp_default_show_hostname,
2397 no_bgp_default_show_hostname_cmd,
2398 "no bgp default show-hostname",
2399 NO_STR
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
2402 "Show hostname in certain command outputs\n")
2403 {
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2406 return CMD_SUCCESS;
2407 }
2408
2409 /* "bgp network import-check" configuration. */
2410 DEFUN (bgp_network_import_check,
2411 bgp_network_import_check_cmd,
2412 "bgp network import-check",
2413 "BGP specific commands\n"
2414 "BGP network command\n"
2415 "Check BGP network route exists in IGP\n")
2416 {
2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2419 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2420 bgp_static_redo_import_check(bgp);
2421 }
2422
2423 return CMD_SUCCESS;
2424 }
2425
2426 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2427 "bgp network import-check exact",
2428 "BGP specific commands\n"
2429 "BGP network command\n"
2430 "Check BGP network route exists in IGP\n"
2431 "Match route precisely\n")
2432
2433 DEFUN (no_bgp_network_import_check,
2434 no_bgp_network_import_check_cmd,
2435 "no bgp network import-check",
2436 NO_STR
2437 "BGP specific commands\n"
2438 "BGP network command\n"
2439 "Check BGP network route exists in IGP\n")
2440 {
2441 VTY_DECLVAR_CONTEXT(bgp, bgp);
2442 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2443 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2444 bgp_static_redo_import_check(bgp);
2445 }
2446
2447 return CMD_SUCCESS;
2448 }
2449
2450 DEFUN (bgp_default_local_preference,
2451 bgp_default_local_preference_cmd,
2452 "bgp default local-preference (0-4294967295)",
2453 "BGP specific commands\n"
2454 "Configure BGP defaults\n"
2455 "local preference (higher=more preferred)\n"
2456 "Configure default local preference value\n")
2457 {
2458 VTY_DECLVAR_CONTEXT(bgp, bgp);
2459 int idx_number = 3;
2460 uint32_t local_pref;
2461
2462 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2463
2464 bgp_default_local_preference_set(bgp, local_pref);
2465 bgp_clear_star_soft_in(vty, bgp->name);
2466
2467 return CMD_SUCCESS;
2468 }
2469
2470 DEFUN (no_bgp_default_local_preference,
2471 no_bgp_default_local_preference_cmd,
2472 "no bgp default local-preference [(0-4294967295)]",
2473 NO_STR
2474 "BGP specific commands\n"
2475 "Configure BGP defaults\n"
2476 "local preference (higher=more preferred)\n"
2477 "Configure default local preference value\n")
2478 {
2479 VTY_DECLVAR_CONTEXT(bgp, bgp);
2480 bgp_default_local_preference_unset(bgp);
2481 bgp_clear_star_soft_in(vty, bgp->name);
2482
2483 return CMD_SUCCESS;
2484 }
2485
2486
2487 DEFUN (bgp_default_subgroup_pkt_queue_max,
2488 bgp_default_subgroup_pkt_queue_max_cmd,
2489 "bgp default subgroup-pkt-queue-max (20-100)",
2490 "BGP specific commands\n"
2491 "Configure BGP defaults\n"
2492 "subgroup-pkt-queue-max\n"
2493 "Configure subgroup packet queue max\n")
2494 {
2495 VTY_DECLVAR_CONTEXT(bgp, bgp);
2496 int idx_number = 3;
2497 uint32_t max_size;
2498
2499 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2500
2501 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2502
2503 return CMD_SUCCESS;
2504 }
2505
2506 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2507 no_bgp_default_subgroup_pkt_queue_max_cmd,
2508 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2509 NO_STR
2510 "BGP specific commands\n"
2511 "Configure BGP defaults\n"
2512 "subgroup-pkt-queue-max\n"
2513 "Configure subgroup packet queue max\n")
2514 {
2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
2516 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2517 return CMD_SUCCESS;
2518 }
2519
2520
2521 DEFUN (bgp_rr_allow_outbound_policy,
2522 bgp_rr_allow_outbound_policy_cmd,
2523 "bgp route-reflector allow-outbound-policy",
2524 "BGP specific commands\n"
2525 "Allow modifications made by out route-map\n"
2526 "on ibgp neighbors\n")
2527 {
2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529
2530 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2531 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2532 update_group_announce_rrclients(bgp);
2533 bgp_clear_star_soft_out(vty, bgp->name);
2534 }
2535
2536 return CMD_SUCCESS;
2537 }
2538
2539 DEFUN (no_bgp_rr_allow_outbound_policy,
2540 no_bgp_rr_allow_outbound_policy_cmd,
2541 "no bgp route-reflector allow-outbound-policy",
2542 NO_STR
2543 "BGP specific commands\n"
2544 "Allow modifications made by out route-map\n"
2545 "on ibgp neighbors\n")
2546 {
2547 VTY_DECLVAR_CONTEXT(bgp, bgp);
2548
2549 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2550 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2551 update_group_announce_rrclients(bgp);
2552 bgp_clear_star_soft_out(vty, bgp->name);
2553 }
2554
2555 return CMD_SUCCESS;
2556 }
2557
2558 DEFUN (bgp_listen_limit,
2559 bgp_listen_limit_cmd,
2560 "bgp listen limit (1-5000)",
2561 "BGP specific commands\n"
2562 "Configure BGP defaults\n"
2563 "maximum number of BGP Dynamic Neighbors that can be created\n"
2564 "Configure Dynamic Neighbors listen limit value\n")
2565 {
2566 VTY_DECLVAR_CONTEXT(bgp, bgp);
2567 int idx_number = 3;
2568 int listen_limit;
2569
2570 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2571
2572 bgp_listen_limit_set(bgp, listen_limit);
2573
2574 return CMD_SUCCESS;
2575 }
2576
2577 DEFUN (no_bgp_listen_limit,
2578 no_bgp_listen_limit_cmd,
2579 "no bgp listen limit [(1-5000)]",
2580 "BGP specific commands\n"
2581 "Configure BGP defaults\n"
2582 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2583 "Configure Dynamic Neighbors listen limit value to default\n"
2584 "Configure Dynamic Neighbors listen limit value\n")
2585 {
2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 bgp_listen_limit_unset(bgp);
2588 return CMD_SUCCESS;
2589 }
2590
2591
2592 /*
2593 * Check if this listen range is already configured. Check for exact
2594 * match or overlap based on input.
2595 */
2596 static struct peer_group *listen_range_exists(struct bgp *bgp,
2597 struct prefix *range, int exact)
2598 {
2599 struct listnode *node, *nnode;
2600 struct listnode *node1, *nnode1;
2601 struct peer_group *group;
2602 struct prefix *lr;
2603 afi_t afi;
2604 int match;
2605
2606 afi = family2afi(range->family);
2607 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2608 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2609 lr)) {
2610 if (exact)
2611 match = prefix_same(range, lr);
2612 else
2613 match = (prefix_match(range, lr)
2614 || prefix_match(lr, range));
2615 if (match)
2616 return group;
2617 }
2618 }
2619
2620 return NULL;
2621 }
2622
2623 DEFUN (bgp_listen_range,
2624 bgp_listen_range_cmd,
2625 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2626 "BGP specific commands\n"
2627 "Configure BGP dynamic neighbors listen range\n"
2628 "Configure BGP dynamic neighbors listen range\n"
2629 NEIGHBOR_ADDR_STR
2630 "Member of the peer-group\n"
2631 "Peer-group name\n")
2632 {
2633 VTY_DECLVAR_CONTEXT(bgp, bgp);
2634 struct prefix range;
2635 struct peer_group *group, *existing_group;
2636 afi_t afi;
2637 int ret;
2638 int idx = 0;
2639
2640 argv_find(argv, argc, "A.B.C.D/M", &idx);
2641 argv_find(argv, argc, "X:X::X:X/M", &idx);
2642 char *prefix = argv[idx]->arg;
2643 argv_find(argv, argc, "WORD", &idx);
2644 char *peergroup = argv[idx]->arg;
2645
2646 /* Convert IP prefix string to struct prefix. */
2647 ret = str2prefix(prefix, &range);
2648 if (!ret) {
2649 vty_out(vty, "%% Malformed listen range\n");
2650 return CMD_WARNING_CONFIG_FAILED;
2651 }
2652
2653 afi = family2afi(range.family);
2654
2655 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2656 vty_out(vty,
2657 "%% Malformed listen range (link-local address)\n");
2658 return CMD_WARNING_CONFIG_FAILED;
2659 }
2660
2661 apply_mask(&range);
2662
2663 /* Check if same listen range is already configured. */
2664 existing_group = listen_range_exists(bgp, &range, 1);
2665 if (existing_group) {
2666 if (strcmp(existing_group->name, peergroup) == 0)
2667 return CMD_SUCCESS;
2668 else {
2669 vty_out(vty,
2670 "%% Same listen range is attached to peer-group %s\n",
2671 existing_group->name);
2672 return CMD_WARNING_CONFIG_FAILED;
2673 }
2674 }
2675
2676 /* Check if an overlapping listen range exists. */
2677 if (listen_range_exists(bgp, &range, 0)) {
2678 vty_out(vty,
2679 "%% Listen range overlaps with existing listen range\n");
2680 return CMD_WARNING_CONFIG_FAILED;
2681 }
2682
2683 group = peer_group_lookup(bgp, peergroup);
2684 if (!group) {
2685 vty_out(vty, "%% Configure the peer-group first\n");
2686 return CMD_WARNING_CONFIG_FAILED;
2687 }
2688
2689 ret = peer_group_listen_range_add(group, &range);
2690 return bgp_vty_return(vty, ret);
2691 }
2692
2693 DEFUN (no_bgp_listen_range,
2694 no_bgp_listen_range_cmd,
2695 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2696 NO_STR
2697 "BGP specific commands\n"
2698 "Unconfigure BGP dynamic neighbors listen range\n"
2699 "Unconfigure BGP dynamic neighbors listen range\n"
2700 NEIGHBOR_ADDR_STR
2701 "Member of the peer-group\n"
2702 "Peer-group name\n")
2703 {
2704 VTY_DECLVAR_CONTEXT(bgp, bgp);
2705 struct prefix range;
2706 struct peer_group *group;
2707 afi_t afi;
2708 int ret;
2709 int idx = 0;
2710
2711 argv_find(argv, argc, "A.B.C.D/M", &idx);
2712 argv_find(argv, argc, "X:X::X:X/M", &idx);
2713 char *prefix = argv[idx]->arg;
2714 argv_find(argv, argc, "WORD", &idx);
2715 char *peergroup = argv[idx]->arg;
2716
2717 /* Convert IP prefix string to struct prefix. */
2718 ret = str2prefix(prefix, &range);
2719 if (!ret) {
2720 vty_out(vty, "%% Malformed listen range\n");
2721 return CMD_WARNING_CONFIG_FAILED;
2722 }
2723
2724 afi = family2afi(range.family);
2725
2726 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2727 vty_out(vty,
2728 "%% Malformed listen range (link-local address)\n");
2729 return CMD_WARNING_CONFIG_FAILED;
2730 }
2731
2732 apply_mask(&range);
2733
2734 group = peer_group_lookup(bgp, peergroup);
2735 if (!group) {
2736 vty_out(vty, "%% Peer-group does not exist\n");
2737 return CMD_WARNING_CONFIG_FAILED;
2738 }
2739
2740 ret = peer_group_listen_range_del(group, &range);
2741 return bgp_vty_return(vty, ret);
2742 }
2743
2744 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2745 {
2746 struct peer_group *group;
2747 struct listnode *node, *nnode, *rnode, *nrnode;
2748 struct prefix *range;
2749 afi_t afi;
2750 char buf[PREFIX2STR_BUFFER];
2751
2752 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2753 vty_out(vty, " bgp listen limit %d\n",
2754 bgp->dynamic_neighbors_limit);
2755
2756 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2757 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2758 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2759 nrnode, range)) {
2760 prefix2str(range, buf, sizeof(buf));
2761 vty_out(vty,
2762 " bgp listen range %s peer-group %s\n",
2763 buf, group->name);
2764 }
2765 }
2766 }
2767 }
2768
2769
2770 DEFUN (bgp_disable_connected_route_check,
2771 bgp_disable_connected_route_check_cmd,
2772 "bgp disable-ebgp-connected-route-check",
2773 "BGP specific commands\n"
2774 "Disable checking if nexthop is connected on ebgp sessions\n")
2775 {
2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2778 bgp_clear_star_soft_in(vty, bgp->name);
2779
2780 return CMD_SUCCESS;
2781 }
2782
2783 DEFUN (no_bgp_disable_connected_route_check,
2784 no_bgp_disable_connected_route_check_cmd,
2785 "no bgp disable-ebgp-connected-route-check",
2786 NO_STR
2787 "BGP specific commands\n"
2788 "Disable checking if nexthop is connected on ebgp sessions\n")
2789 {
2790 VTY_DECLVAR_CONTEXT(bgp, bgp);
2791 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2792 bgp_clear_star_soft_in(vty, bgp->name);
2793
2794 return CMD_SUCCESS;
2795 }
2796
2797
2798 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2799 const char *as_str, afi_t afi, safi_t safi)
2800 {
2801 VTY_DECLVAR_CONTEXT(bgp, bgp);
2802 int ret;
2803 as_t as;
2804 int as_type = AS_SPECIFIED;
2805 union sockunion su;
2806
2807 if (as_str[0] == 'i') {
2808 as = 0;
2809 as_type = AS_INTERNAL;
2810 } else if (as_str[0] == 'e') {
2811 as = 0;
2812 as_type = AS_EXTERNAL;
2813 } else {
2814 /* Get AS number. */
2815 as = strtoul(as_str, NULL, 10);
2816 }
2817
2818 /* If peer is peer group, call proper function. */
2819 ret = str2sockunion(peer_str, &su);
2820 if (ret < 0) {
2821 /* Check for peer by interface */
2822 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2823 safi);
2824 if (ret < 0) {
2825 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2826 if (ret < 0) {
2827 vty_out(vty,
2828 "%% Create the peer-group or interface first or specify \"interface\" keyword\n");
2829 vty_out(vty, "%% if using an unnumbered interface neighbor\n");
2830 return CMD_WARNING_CONFIG_FAILED;
2831 }
2832 return CMD_SUCCESS;
2833 }
2834 } else {
2835 if (peer_address_self_check(bgp, &su)) {
2836 vty_out(vty,
2837 "%% Can not configure the local system as neighbor\n");
2838 return CMD_WARNING_CONFIG_FAILED;
2839 }
2840 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2841 }
2842
2843 /* This peer belongs to peer group. */
2844 switch (ret) {
2845 case BGP_ERR_PEER_GROUP_MEMBER:
2846 vty_out(vty,
2847 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2848 as);
2849 return CMD_WARNING_CONFIG_FAILED;
2850 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2851 vty_out(vty,
2852 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2853 as, as_str);
2854 return CMD_WARNING_CONFIG_FAILED;
2855 }
2856 return bgp_vty_return(vty, ret);
2857 }
2858
2859 DEFUN (bgp_default_shutdown,
2860 bgp_default_shutdown_cmd,
2861 "[no] bgp default shutdown",
2862 NO_STR
2863 BGP_STR
2864 "Configure BGP defaults\n"
2865 "Apply administrative shutdown to newly configured peers\n")
2866 {
2867 VTY_DECLVAR_CONTEXT(bgp, bgp);
2868 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2869 return CMD_SUCCESS;
2870 }
2871
2872 DEFUN (neighbor_remote_as,
2873 neighbor_remote_as_cmd,
2874 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2875 NEIGHBOR_STR
2876 NEIGHBOR_ADDR_STR2
2877 "Specify a BGP neighbor\n"
2878 AS_STR
2879 "Internal BGP peer\n"
2880 "External BGP peer\n")
2881 {
2882 int idx_peer = 1;
2883 int idx_remote_as = 3;
2884 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2885 argv[idx_remote_as]->arg, AFI_IP,
2886 SAFI_UNICAST);
2887 }
2888
2889 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2890 afi_t afi, safi_t safi, int v6only,
2891 const char *peer_group_name,
2892 const char *as_str)
2893 {
2894 VTY_DECLVAR_CONTEXT(bgp, bgp);
2895 as_t as = 0;
2896 int as_type = AS_UNSPECIFIED;
2897 struct peer *peer;
2898 struct peer_group *group;
2899 int ret = 0;
2900 union sockunion su;
2901
2902 group = peer_group_lookup(bgp, conf_if);
2903
2904 if (group) {
2905 vty_out(vty, "%% Name conflict with peer-group \n");
2906 return CMD_WARNING_CONFIG_FAILED;
2907 }
2908
2909 if (as_str) {
2910 if (as_str[0] == 'i') {
2911 as_type = AS_INTERNAL;
2912 } else if (as_str[0] == 'e') {
2913 as_type = AS_EXTERNAL;
2914 } else {
2915 /* Get AS number. */
2916 as = strtoul(as_str, NULL, 10);
2917 as_type = AS_SPECIFIED;
2918 }
2919 }
2920
2921 peer = peer_lookup_by_conf_if(bgp, conf_if);
2922 if (peer) {
2923 if (as_str)
2924 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2925 afi, safi);
2926 } else {
2927 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2928 && afi == AFI_IP && safi == SAFI_UNICAST)
2929 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2930 as_type, 0, 0, NULL);
2931 else
2932 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2933 as_type, afi, safi, NULL);
2934
2935 if (!peer) {
2936 vty_out(vty, "%% BGP failed to create peer\n");
2937 return CMD_WARNING_CONFIG_FAILED;
2938 }
2939
2940 if (v6only)
2941 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2942
2943 /* Request zebra to initiate IPv6 RAs on this interface. We do
2944 * this
2945 * any unnumbered peer in order to not worry about run-time
2946 * transitions
2947 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2948 * address
2949 * gets deleted later etc.)
2950 */
2951 if (peer->ifp)
2952 bgp_zebra_initiate_radv(bgp, peer);
2953 }
2954
2955 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2956 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2957 if (v6only)
2958 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2959 else
2960 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2961
2962 /* v6only flag changed. Reset bgp seesion */
2963 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2964 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2965 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2966 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2967 } else
2968 bgp_session_reset(peer);
2969 }
2970
2971 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2972 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2973 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2974 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2975 }
2976
2977 if (peer_group_name) {
2978 group = peer_group_lookup(bgp, peer_group_name);
2979 if (!group) {
2980 vty_out(vty, "%% Configure the peer-group first\n");
2981 return CMD_WARNING_CONFIG_FAILED;
2982 }
2983
2984 ret = peer_group_bind(bgp, &su, peer, group, &as);
2985 }
2986
2987 return bgp_vty_return(vty, ret);
2988 }
2989
2990 DEFUN (neighbor_interface_config,
2991 neighbor_interface_config_cmd,
2992 "neighbor WORD interface [peer-group WORD]",
2993 NEIGHBOR_STR
2994 "Interface name or neighbor tag\n"
2995 "Enable BGP on interface\n"
2996 "Member of the peer-group\n"
2997 "Peer-group name\n")
2998 {
2999 int idx_word = 1;
3000 int idx_peer_group_word = 4;
3001
3002 if (argc > idx_peer_group_word)
3003 return peer_conf_interface_get(
3004 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3005 argv[idx_peer_group_word]->arg, NULL);
3006 else
3007 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3008 SAFI_UNICAST, 0, NULL, NULL);
3009 }
3010
3011 DEFUN (neighbor_interface_config_v6only,
3012 neighbor_interface_config_v6only_cmd,
3013 "neighbor WORD interface v6only [peer-group WORD]",
3014 NEIGHBOR_STR
3015 "Interface name or neighbor tag\n"
3016 "Enable BGP on interface\n"
3017 "Enable BGP with v6 link-local only\n"
3018 "Member of the peer-group\n"
3019 "Peer-group name\n")
3020 {
3021 int idx_word = 1;
3022 int idx_peer_group_word = 5;
3023
3024 if (argc > idx_peer_group_word)
3025 return peer_conf_interface_get(
3026 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3027 argv[idx_peer_group_word]->arg, NULL);
3028
3029 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3030 SAFI_UNICAST, 1, NULL, NULL);
3031 }
3032
3033
3034 DEFUN (neighbor_interface_config_remote_as,
3035 neighbor_interface_config_remote_as_cmd,
3036 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3037 NEIGHBOR_STR
3038 "Interface name or neighbor tag\n"
3039 "Enable BGP on interface\n"
3040 "Specify a BGP neighbor\n"
3041 AS_STR
3042 "Internal BGP peer\n"
3043 "External BGP peer\n")
3044 {
3045 int idx_word = 1;
3046 int idx_remote_as = 4;
3047 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3048 SAFI_UNICAST, 0, NULL,
3049 argv[idx_remote_as]->arg);
3050 }
3051
3052 DEFUN (neighbor_interface_v6only_config_remote_as,
3053 neighbor_interface_v6only_config_remote_as_cmd,
3054 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3055 NEIGHBOR_STR
3056 "Interface name or neighbor tag\n"
3057 "Enable BGP with v6 link-local only\n"
3058 "Enable BGP on interface\n"
3059 "Specify a BGP neighbor\n"
3060 AS_STR
3061 "Internal BGP peer\n"
3062 "External BGP peer\n")
3063 {
3064 int idx_word = 1;
3065 int idx_remote_as = 5;
3066 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3067 SAFI_UNICAST, 1, NULL,
3068 argv[idx_remote_as]->arg);
3069 }
3070
3071 DEFUN (neighbor_peer_group,
3072 neighbor_peer_group_cmd,
3073 "neighbor WORD peer-group",
3074 NEIGHBOR_STR
3075 "Interface name or neighbor tag\n"
3076 "Configure peer-group\n")
3077 {
3078 VTY_DECLVAR_CONTEXT(bgp, bgp);
3079 int idx_word = 1;
3080 struct peer *peer;
3081 struct peer_group *group;
3082
3083 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3084 if (peer) {
3085 vty_out(vty, "%% Name conflict with interface: \n");
3086 return CMD_WARNING_CONFIG_FAILED;
3087 }
3088
3089 group = peer_group_get(bgp, argv[idx_word]->arg);
3090 if (!group) {
3091 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3092 return CMD_WARNING_CONFIG_FAILED;
3093 }
3094
3095 return CMD_SUCCESS;
3096 }
3097
3098 DEFUN (no_neighbor,
3099 no_neighbor_cmd,
3100 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3101 NO_STR
3102 NEIGHBOR_STR
3103 NEIGHBOR_ADDR_STR2
3104 "Specify a BGP neighbor\n"
3105 AS_STR
3106 "Internal BGP peer\n"
3107 "External BGP peer\n")
3108 {
3109 VTY_DECLVAR_CONTEXT(bgp, bgp);
3110 int idx_peer = 2;
3111 int ret;
3112 union sockunion su;
3113 struct peer_group *group;
3114 struct peer *peer;
3115 struct peer *other;
3116
3117 ret = str2sockunion(argv[idx_peer]->arg, &su);
3118 if (ret < 0) {
3119 /* look up for neighbor by interface name config. */
3120 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3121 if (peer) {
3122 /* Request zebra to terminate IPv6 RAs on this
3123 * interface. */
3124 if (peer->ifp)
3125 bgp_zebra_terminate_radv(peer->bgp, peer);
3126 peer_delete(peer);
3127 return CMD_SUCCESS;
3128 }
3129
3130 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3131 if (group)
3132 peer_group_delete(group);
3133 else {
3134 vty_out(vty, "%% Create the peer-group first\n");
3135 return CMD_WARNING_CONFIG_FAILED;
3136 }
3137 } else {
3138 peer = peer_lookup(bgp, &su);
3139 if (peer) {
3140 if (peer_dynamic_neighbor(peer)) {
3141 vty_out(vty,
3142 "%% Operation not allowed on a dynamic neighbor\n");
3143 return CMD_WARNING_CONFIG_FAILED;
3144 }
3145
3146 other = peer->doppelganger;
3147 peer_delete(peer);
3148 if (other && other->status != Deleted)
3149 peer_delete(other);
3150 }
3151 }
3152
3153 return CMD_SUCCESS;
3154 }
3155
3156 DEFUN (no_neighbor_interface_config,
3157 no_neighbor_interface_config_cmd,
3158 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3159 NO_STR
3160 NEIGHBOR_STR
3161 "Interface name\n"
3162 "Configure BGP on interface\n"
3163 "Enable BGP with v6 link-local only\n"
3164 "Member of the peer-group\n"
3165 "Peer-group name\n"
3166 "Specify a BGP neighbor\n"
3167 AS_STR
3168 "Internal BGP peer\n"
3169 "External BGP peer\n")
3170 {
3171 VTY_DECLVAR_CONTEXT(bgp, bgp);
3172 int idx_word = 2;
3173 struct peer *peer;
3174
3175 /* look up for neighbor by interface name config. */
3176 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3177 if (peer) {
3178 /* Request zebra to terminate IPv6 RAs on this interface. */
3179 if (peer->ifp)
3180 bgp_zebra_terminate_radv(peer->bgp, peer);
3181 peer_delete(peer);
3182 } else {
3183 vty_out(vty, "%% Create the bgp interface first\n");
3184 return CMD_WARNING_CONFIG_FAILED;
3185 }
3186 return CMD_SUCCESS;
3187 }
3188
3189 DEFUN (no_neighbor_peer_group,
3190 no_neighbor_peer_group_cmd,
3191 "no neighbor WORD peer-group",
3192 NO_STR
3193 NEIGHBOR_STR
3194 "Neighbor tag\n"
3195 "Configure peer-group\n")
3196 {
3197 VTY_DECLVAR_CONTEXT(bgp, bgp);
3198 int idx_word = 2;
3199 struct peer_group *group;
3200
3201 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3202 if (group)
3203 peer_group_delete(group);
3204 else {
3205 vty_out(vty, "%% Create the peer-group first\n");
3206 return CMD_WARNING_CONFIG_FAILED;
3207 }
3208 return CMD_SUCCESS;
3209 }
3210
3211 DEFUN (no_neighbor_interface_peer_group_remote_as,
3212 no_neighbor_interface_peer_group_remote_as_cmd,
3213 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3214 NO_STR
3215 NEIGHBOR_STR
3216 "Interface name or neighbor tag\n"
3217 "Specify a BGP neighbor\n"
3218 AS_STR
3219 "Internal BGP peer\n"
3220 "External BGP peer\n")
3221 {
3222 VTY_DECLVAR_CONTEXT(bgp, bgp);
3223 int idx_word = 2;
3224 struct peer_group *group;
3225 struct peer *peer;
3226
3227 /* look up for neighbor by interface name config. */
3228 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3229 if (peer) {
3230 peer_as_change(peer, 0, AS_SPECIFIED);
3231 return CMD_SUCCESS;
3232 }
3233
3234 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3235 if (group)
3236 peer_group_remote_as_delete(group);
3237 else {
3238 vty_out(vty, "%% Create the peer-group or interface first\n");
3239 return CMD_WARNING_CONFIG_FAILED;
3240 }
3241 return CMD_SUCCESS;
3242 }
3243
3244 DEFUN (neighbor_local_as,
3245 neighbor_local_as_cmd,
3246 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3247 NEIGHBOR_STR
3248 NEIGHBOR_ADDR_STR2
3249 "Specify a local-as number\n"
3250 "AS number used as local AS\n")
3251 {
3252 int idx_peer = 1;
3253 int idx_number = 3;
3254 struct peer *peer;
3255 int ret;
3256 as_t as;
3257
3258 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3259 if (!peer)
3260 return CMD_WARNING_CONFIG_FAILED;
3261
3262 as = strtoul(argv[idx_number]->arg, NULL, 10);
3263 ret = peer_local_as_set(peer, as, 0, 0);
3264 return bgp_vty_return(vty, ret);
3265 }
3266
3267 DEFUN (neighbor_local_as_no_prepend,
3268 neighbor_local_as_no_prepend_cmd,
3269 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3270 NEIGHBOR_STR
3271 NEIGHBOR_ADDR_STR2
3272 "Specify a local-as number\n"
3273 "AS number used as local AS\n"
3274 "Do not prepend local-as to updates from ebgp peers\n")
3275 {
3276 int idx_peer = 1;
3277 int idx_number = 3;
3278 struct peer *peer;
3279 int ret;
3280 as_t as;
3281
3282 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3283 if (!peer)
3284 return CMD_WARNING_CONFIG_FAILED;
3285
3286 as = strtoul(argv[idx_number]->arg, NULL, 10);
3287 ret = peer_local_as_set(peer, as, 1, 0);
3288 return bgp_vty_return(vty, ret);
3289 }
3290
3291 DEFUN (neighbor_local_as_no_prepend_replace_as,
3292 neighbor_local_as_no_prepend_replace_as_cmd,
3293 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3294 NEIGHBOR_STR
3295 NEIGHBOR_ADDR_STR2
3296 "Specify a local-as number\n"
3297 "AS number used as local AS\n"
3298 "Do not prepend local-as to updates from ebgp peers\n"
3299 "Do not prepend local-as to updates from ibgp peers\n")
3300 {
3301 int idx_peer = 1;
3302 int idx_number = 3;
3303 struct peer *peer;
3304 int ret;
3305 as_t as;
3306
3307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3308 if (!peer)
3309 return CMD_WARNING_CONFIG_FAILED;
3310
3311 as = strtoul(argv[idx_number]->arg, NULL, 10);
3312 ret = peer_local_as_set(peer, as, 1, 1);
3313 return bgp_vty_return(vty, ret);
3314 }
3315
3316 DEFUN (no_neighbor_local_as,
3317 no_neighbor_local_as_cmd,
3318 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3319 NO_STR
3320 NEIGHBOR_STR
3321 NEIGHBOR_ADDR_STR2
3322 "Specify a local-as number\n"
3323 "AS number used as local AS\n"
3324 "Do not prepend local-as to updates from ebgp peers\n"
3325 "Do not prepend local-as to updates from ibgp peers\n")
3326 {
3327 int idx_peer = 2;
3328 struct peer *peer;
3329 int ret;
3330
3331 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3332 if (!peer)
3333 return CMD_WARNING_CONFIG_FAILED;
3334
3335 ret = peer_local_as_unset(peer);
3336 return bgp_vty_return(vty, ret);
3337 }
3338
3339
3340 DEFUN (neighbor_solo,
3341 neighbor_solo_cmd,
3342 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3343 NEIGHBOR_STR
3344 NEIGHBOR_ADDR_STR2
3345 "Solo peer - part of its own update group\n")
3346 {
3347 int idx_peer = 1;
3348 struct peer *peer;
3349 int ret;
3350
3351 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3352 if (!peer)
3353 return CMD_WARNING_CONFIG_FAILED;
3354
3355 ret = update_group_adjust_soloness(peer, 1);
3356 return bgp_vty_return(vty, ret);
3357 }
3358
3359 DEFUN (no_neighbor_solo,
3360 no_neighbor_solo_cmd,
3361 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3362 NO_STR
3363 NEIGHBOR_STR
3364 NEIGHBOR_ADDR_STR2
3365 "Solo peer - part of its own update group\n")
3366 {
3367 int idx_peer = 2;
3368 struct peer *peer;
3369 int ret;
3370
3371 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3372 if (!peer)
3373 return CMD_WARNING_CONFIG_FAILED;
3374
3375 ret = update_group_adjust_soloness(peer, 0);
3376 return bgp_vty_return(vty, ret);
3377 }
3378
3379 DEFUN (neighbor_password,
3380 neighbor_password_cmd,
3381 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3382 NEIGHBOR_STR
3383 NEIGHBOR_ADDR_STR2
3384 "Set a password\n"
3385 "The password\n")
3386 {
3387 int idx_peer = 1;
3388 int idx_line = 3;
3389 struct peer *peer;
3390 int ret;
3391
3392 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3393 if (!peer)
3394 return CMD_WARNING_CONFIG_FAILED;
3395
3396 ret = peer_password_set(peer, argv[idx_line]->arg);
3397 return bgp_vty_return(vty, ret);
3398 }
3399
3400 DEFUN (no_neighbor_password,
3401 no_neighbor_password_cmd,
3402 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3403 NO_STR
3404 NEIGHBOR_STR
3405 NEIGHBOR_ADDR_STR2
3406 "Set a password\n"
3407 "The password\n")
3408 {
3409 int idx_peer = 2;
3410 struct peer *peer;
3411 int ret;
3412
3413 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3414 if (!peer)
3415 return CMD_WARNING_CONFIG_FAILED;
3416
3417 ret = peer_password_unset(peer);
3418 return bgp_vty_return(vty, ret);
3419 }
3420
3421 DEFUN (neighbor_activate,
3422 neighbor_activate_cmd,
3423 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3424 NEIGHBOR_STR
3425 NEIGHBOR_ADDR_STR2
3426 "Enable the Address Family for this Neighbor\n")
3427 {
3428 int idx_peer = 1;
3429 int ret;
3430 struct peer *peer;
3431
3432 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3433 if (!peer)
3434 return CMD_WARNING_CONFIG_FAILED;
3435
3436 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3437 return bgp_vty_return(vty, ret);
3438 }
3439
3440 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3441 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3443 "Enable the Address Family for this Neighbor\n")
3444
3445 DEFUN (no_neighbor_activate,
3446 no_neighbor_activate_cmd,
3447 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3448 NO_STR
3449 NEIGHBOR_STR
3450 NEIGHBOR_ADDR_STR2
3451 "Enable the Address Family for this Neighbor\n")
3452 {
3453 int idx_peer = 2;
3454 int ret;
3455 struct peer *peer;
3456
3457 /* Lookup peer. */
3458 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3459 if (!peer)
3460 return CMD_WARNING_CONFIG_FAILED;
3461
3462 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3463 return bgp_vty_return(vty, ret);
3464 }
3465
3466 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3467 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3468 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3469 "Enable the Address Family for this Neighbor\n")
3470
3471 DEFUN (neighbor_set_peer_group,
3472 neighbor_set_peer_group_cmd,
3473 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3474 NEIGHBOR_STR
3475 NEIGHBOR_ADDR_STR2
3476 "Member of the peer-group\n"
3477 "Peer-group name\n")
3478 {
3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
3480 int idx_peer = 1;
3481 int idx_word = 3;
3482 int ret;
3483 as_t as;
3484 union sockunion su;
3485 struct peer *peer;
3486 struct peer_group *group;
3487
3488 ret = str2sockunion(argv[idx_peer]->arg, &su);
3489 if (ret < 0) {
3490 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3491 if (!peer) {
3492 vty_out(vty, "%% Malformed address or name: %s\n",
3493 argv[idx_peer]->arg);
3494 return CMD_WARNING_CONFIG_FAILED;
3495 }
3496 } else {
3497 if (peer_address_self_check(bgp, &su)) {
3498 vty_out(vty,
3499 "%% Can not configure the local system as neighbor\n");
3500 return CMD_WARNING_CONFIG_FAILED;
3501 }
3502
3503 /* Disallow for dynamic neighbor. */
3504 peer = peer_lookup(bgp, &su);
3505 if (peer && peer_dynamic_neighbor(peer)) {
3506 vty_out(vty,
3507 "%% Operation not allowed on a dynamic neighbor\n");
3508 return CMD_WARNING_CONFIG_FAILED;
3509 }
3510 }
3511
3512 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3513 if (!group) {
3514 vty_out(vty, "%% Configure the peer-group first\n");
3515 return CMD_WARNING_CONFIG_FAILED;
3516 }
3517
3518 ret = peer_group_bind(bgp, &su, peer, group, &as);
3519
3520 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3521 vty_out(vty,
3522 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3523 as);
3524 return CMD_WARNING_CONFIG_FAILED;
3525 }
3526
3527 return bgp_vty_return(vty, ret);
3528 }
3529
3530 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3531 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3532 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3533 "Member of the peer-group\n"
3534 "Peer-group name\n")
3535
3536 DEFUN (no_neighbor_set_peer_group,
3537 no_neighbor_set_peer_group_cmd,
3538 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3539 NO_STR
3540 NEIGHBOR_STR
3541 NEIGHBOR_ADDR_STR2
3542 "Member of the peer-group\n"
3543 "Peer-group name\n")
3544 {
3545 VTY_DECLVAR_CONTEXT(bgp, bgp);
3546 int idx_peer = 2;
3547 int idx_word = 4;
3548 int ret;
3549 struct peer *peer;
3550 struct peer_group *group;
3551
3552 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3553 if (!peer)
3554 return CMD_WARNING_CONFIG_FAILED;
3555
3556 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3557 if (!group) {
3558 vty_out(vty, "%% Configure the peer-group first\n");
3559 return CMD_WARNING_CONFIG_FAILED;
3560 }
3561
3562 ret = peer_delete(peer);
3563
3564 return bgp_vty_return(vty, ret);
3565 }
3566
3567 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3568 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3570 "Member of the peer-group\n"
3571 "Peer-group name\n")
3572
3573 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3574 uint32_t flag, int set)
3575 {
3576 int ret;
3577 struct peer *peer;
3578
3579 peer = peer_and_group_lookup_vty(vty, ip_str);
3580 if (!peer)
3581 return CMD_WARNING_CONFIG_FAILED;
3582
3583 /*
3584 * If 'neighbor <interface>', then this is for directly connected peers,
3585 * we should not accept disable-connected-check.
3586 */
3587 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3588 vty_out(vty,
3589 "%s is directly connected peer, cannot accept disable-"
3590 "connected-check\n",
3591 ip_str);
3592 return CMD_WARNING_CONFIG_FAILED;
3593 }
3594
3595 if (!set && flag == PEER_FLAG_SHUTDOWN)
3596 peer_tx_shutdown_message_unset(peer);
3597
3598 if (set)
3599 ret = peer_flag_set(peer, flag);
3600 else
3601 ret = peer_flag_unset(peer, flag);
3602
3603 return bgp_vty_return(vty, ret);
3604 }
3605
3606 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3607 {
3608 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3609 }
3610
3611 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3612 uint32_t flag)
3613 {
3614 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3615 }
3616
3617 /* neighbor passive. */
3618 DEFUN (neighbor_passive,
3619 neighbor_passive_cmd,
3620 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3621 NEIGHBOR_STR
3622 NEIGHBOR_ADDR_STR2
3623 "Don't send open messages to this neighbor\n")
3624 {
3625 int idx_peer = 1;
3626 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3627 }
3628
3629 DEFUN (no_neighbor_passive,
3630 no_neighbor_passive_cmd,
3631 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3632 NO_STR
3633 NEIGHBOR_STR
3634 NEIGHBOR_ADDR_STR2
3635 "Don't send open messages to this neighbor\n")
3636 {
3637 int idx_peer = 2;
3638 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3639 }
3640
3641 /* neighbor shutdown. */
3642 DEFUN (neighbor_shutdown_msg,
3643 neighbor_shutdown_msg_cmd,
3644 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
3647 "Administratively shut down this neighbor\n"
3648 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3649 "Shutdown message\n")
3650 {
3651 int idx_peer = 1;
3652
3653 if (argc >= 5) {
3654 struct peer *peer =
3655 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3656 char *message;
3657
3658 if (!peer)
3659 return CMD_WARNING_CONFIG_FAILED;
3660 message = argv_concat(argv, argc, 4);
3661 peer_tx_shutdown_message_set(peer, message);
3662 XFREE(MTYPE_TMP, message);
3663 }
3664
3665 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3666 }
3667
3668 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3669 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3671 "Administratively shut down this neighbor\n")
3672
3673 DEFUN (no_neighbor_shutdown_msg,
3674 no_neighbor_shutdown_msg_cmd,
3675 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3676 NO_STR
3677 NEIGHBOR_STR
3678 NEIGHBOR_ADDR_STR2
3679 "Administratively shut down this neighbor\n"
3680 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3681 "Shutdown message\n")
3682 {
3683 int idx_peer = 2;
3684
3685 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3686 PEER_FLAG_SHUTDOWN);
3687 }
3688
3689 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3690 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3691 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3692 "Administratively shut down this neighbor\n")
3693
3694 /* neighbor capability dynamic. */
3695 DEFUN (neighbor_capability_dynamic,
3696 neighbor_capability_dynamic_cmd,
3697 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3698 NEIGHBOR_STR
3699 NEIGHBOR_ADDR_STR2
3700 "Advertise capability to the peer\n"
3701 "Advertise dynamic capability to this neighbor\n")
3702 {
3703 int idx_peer = 1;
3704 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3705 PEER_FLAG_DYNAMIC_CAPABILITY);
3706 }
3707
3708 DEFUN (no_neighbor_capability_dynamic,
3709 no_neighbor_capability_dynamic_cmd,
3710 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3711 NO_STR
3712 NEIGHBOR_STR
3713 NEIGHBOR_ADDR_STR2
3714 "Advertise capability to the peer\n"
3715 "Advertise dynamic capability to this neighbor\n")
3716 {
3717 int idx_peer = 2;
3718 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3719 PEER_FLAG_DYNAMIC_CAPABILITY);
3720 }
3721
3722 /* neighbor dont-capability-negotiate */
3723 DEFUN (neighbor_dont_capability_negotiate,
3724 neighbor_dont_capability_negotiate_cmd,
3725 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3726 NEIGHBOR_STR
3727 NEIGHBOR_ADDR_STR2
3728 "Do not perform capability negotiation\n")
3729 {
3730 int idx_peer = 1;
3731 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3732 PEER_FLAG_DONT_CAPABILITY);
3733 }
3734
3735 DEFUN (no_neighbor_dont_capability_negotiate,
3736 no_neighbor_dont_capability_negotiate_cmd,
3737 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3738 NO_STR
3739 NEIGHBOR_STR
3740 NEIGHBOR_ADDR_STR2
3741 "Do not perform capability negotiation\n")
3742 {
3743 int idx_peer = 2;
3744 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3745 PEER_FLAG_DONT_CAPABILITY);
3746 }
3747
3748 /* neighbor capability extended next hop encoding */
3749 DEFUN (neighbor_capability_enhe,
3750 neighbor_capability_enhe_cmd,
3751 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3752 NEIGHBOR_STR
3753 NEIGHBOR_ADDR_STR2
3754 "Advertise capability to the peer\n"
3755 "Advertise extended next-hop capability to the peer\n")
3756 {
3757 int idx_peer = 1;
3758 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3759 PEER_FLAG_CAPABILITY_ENHE);
3760 }
3761
3762 DEFUN (no_neighbor_capability_enhe,
3763 no_neighbor_capability_enhe_cmd,
3764 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3765 NO_STR
3766 NEIGHBOR_STR
3767 NEIGHBOR_ADDR_STR2
3768 "Advertise capability to the peer\n"
3769 "Advertise extended next-hop capability to the peer\n")
3770 {
3771 int idx_peer = 2;
3772 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3773 PEER_FLAG_CAPABILITY_ENHE);
3774 }
3775
3776 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3777 afi_t afi, safi_t safi, uint32_t flag,
3778 int set)
3779 {
3780 int ret;
3781 struct peer *peer;
3782
3783 peer = peer_and_group_lookup_vty(vty, peer_str);
3784 if (!peer)
3785 return CMD_WARNING_CONFIG_FAILED;
3786
3787 if (set)
3788 ret = peer_af_flag_set(peer, afi, safi, flag);
3789 else
3790 ret = peer_af_flag_unset(peer, afi, safi, flag);
3791
3792 return bgp_vty_return(vty, ret);
3793 }
3794
3795 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3796 afi_t afi, safi_t safi, uint32_t flag)
3797 {
3798 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3799 }
3800
3801 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3802 afi_t afi, safi_t safi, uint32_t flag)
3803 {
3804 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3805 }
3806
3807 /* neighbor capability orf prefix-list. */
3808 DEFUN (neighbor_capability_orf_prefix,
3809 neighbor_capability_orf_prefix_cmd,
3810 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3811 NEIGHBOR_STR
3812 NEIGHBOR_ADDR_STR2
3813 "Advertise capability to the peer\n"
3814 "Advertise ORF capability to the peer\n"
3815 "Advertise prefixlist ORF capability to this neighbor\n"
3816 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3817 "Capability to RECEIVE the ORF from this neighbor\n"
3818 "Capability to SEND the ORF to this neighbor\n")
3819 {
3820 int idx_peer = 1;
3821 int idx_send_recv = 5;
3822 uint16_t flag = 0;
3823
3824 if (strmatch(argv[idx_send_recv]->text, "send"))
3825 flag = PEER_FLAG_ORF_PREFIX_SM;
3826 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3827 flag = PEER_FLAG_ORF_PREFIX_RM;
3828 else if (strmatch(argv[idx_send_recv]->text, "both"))
3829 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3830 else {
3831 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3832 return CMD_WARNING_CONFIG_FAILED;
3833 }
3834
3835 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3836 bgp_node_safi(vty), flag);
3837 }
3838
3839 ALIAS_HIDDEN(
3840 neighbor_capability_orf_prefix,
3841 neighbor_capability_orf_prefix_hidden_cmd,
3842 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3843 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3844 "Advertise capability to the peer\n"
3845 "Advertise ORF capability to the peer\n"
3846 "Advertise prefixlist ORF capability to this neighbor\n"
3847 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3848 "Capability to RECEIVE the ORF from this neighbor\n"
3849 "Capability to SEND the ORF to this neighbor\n")
3850
3851 DEFUN (no_neighbor_capability_orf_prefix,
3852 no_neighbor_capability_orf_prefix_cmd,
3853 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3854 NO_STR
3855 NEIGHBOR_STR
3856 NEIGHBOR_ADDR_STR2
3857 "Advertise capability to the peer\n"
3858 "Advertise ORF capability to the peer\n"
3859 "Advertise prefixlist ORF capability to this neighbor\n"
3860 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3861 "Capability to RECEIVE the ORF from this neighbor\n"
3862 "Capability to SEND the ORF to this neighbor\n")
3863 {
3864 int idx_peer = 2;
3865 int idx_send_recv = 6;
3866 uint16_t flag = 0;
3867
3868 if (strmatch(argv[idx_send_recv]->text, "send"))
3869 flag = PEER_FLAG_ORF_PREFIX_SM;
3870 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3871 flag = PEER_FLAG_ORF_PREFIX_RM;
3872 else if (strmatch(argv[idx_send_recv]->text, "both"))
3873 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3874 else {
3875 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3876 return CMD_WARNING_CONFIG_FAILED;
3877 }
3878
3879 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3880 bgp_node_afi(vty), bgp_node_safi(vty),
3881 flag);
3882 }
3883
3884 ALIAS_HIDDEN(
3885 no_neighbor_capability_orf_prefix,
3886 no_neighbor_capability_orf_prefix_hidden_cmd,
3887 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3888 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3889 "Advertise capability to the peer\n"
3890 "Advertise ORF capability to the peer\n"
3891 "Advertise prefixlist ORF capability to this neighbor\n"
3892 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3893 "Capability to RECEIVE the ORF from this neighbor\n"
3894 "Capability to SEND the ORF to this neighbor\n")
3895
3896 /* neighbor next-hop-self. */
3897 DEFUN (neighbor_nexthop_self,
3898 neighbor_nexthop_self_cmd,
3899 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3900 NEIGHBOR_STR
3901 NEIGHBOR_ADDR_STR2
3902 "Disable the next hop calculation for this neighbor\n")
3903 {
3904 int idx_peer = 1;
3905 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3906 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3907 }
3908
3909 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3910 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3912 "Disable the next hop calculation for this neighbor\n")
3913
3914 /* neighbor next-hop-self. */
3915 DEFUN (neighbor_nexthop_self_force,
3916 neighbor_nexthop_self_force_cmd,
3917 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3918 NEIGHBOR_STR
3919 NEIGHBOR_ADDR_STR2
3920 "Disable the next hop calculation for this neighbor\n"
3921 "Set the next hop to self for reflected routes\n")
3922 {
3923 int idx_peer = 1;
3924 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3925 bgp_node_safi(vty),
3926 PEER_FLAG_FORCE_NEXTHOP_SELF);
3927 }
3928
3929 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3930 neighbor_nexthop_self_force_hidden_cmd,
3931 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3932 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3933 "Disable the next hop calculation for this neighbor\n"
3934 "Set the next hop to self for reflected routes\n")
3935
3936 DEFUN (no_neighbor_nexthop_self,
3937 no_neighbor_nexthop_self_cmd,
3938 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3939 NO_STR
3940 NEIGHBOR_STR
3941 NEIGHBOR_ADDR_STR2
3942 "Disable the next hop calculation for this neighbor\n")
3943 {
3944 int idx_peer = 2;
3945 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3946 bgp_node_afi(vty), bgp_node_safi(vty),
3947 PEER_FLAG_NEXTHOP_SELF);
3948 }
3949
3950 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3951 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3952 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3953 "Disable the next hop calculation for this neighbor\n")
3954
3955 DEFUN (no_neighbor_nexthop_self_force,
3956 no_neighbor_nexthop_self_force_cmd,
3957 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3958 NO_STR
3959 NEIGHBOR_STR
3960 NEIGHBOR_ADDR_STR2
3961 "Disable the next hop calculation for this neighbor\n"
3962 "Set the next hop to self for reflected routes\n")
3963 {
3964 int idx_peer = 2;
3965 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3966 bgp_node_afi(vty), bgp_node_safi(vty),
3967 PEER_FLAG_FORCE_NEXTHOP_SELF);
3968 }
3969
3970 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3971 no_neighbor_nexthop_self_force_hidden_cmd,
3972 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3974 "Disable the next hop calculation for this neighbor\n"
3975 "Set the next hop to self for reflected routes\n")
3976
3977 /* neighbor as-override */
3978 DEFUN (neighbor_as_override,
3979 neighbor_as_override_cmd,
3980 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3981 NEIGHBOR_STR
3982 NEIGHBOR_ADDR_STR2
3983 "Override ASNs in outbound updates if aspath equals remote-as\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_AS_OVERRIDE);
3988 }
3989
3990 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3991 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3993 "Override ASNs in outbound updates if aspath equals remote-as\n")
3994
3995 DEFUN (no_neighbor_as_override,
3996 no_neighbor_as_override_cmd,
3997 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3998 NO_STR
3999 NEIGHBOR_STR
4000 NEIGHBOR_ADDR_STR2
4001 "Override ASNs in outbound updates if aspath equals remote-as\n")
4002 {
4003 int idx_peer = 2;
4004 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4005 bgp_node_afi(vty), bgp_node_safi(vty),
4006 PEER_FLAG_AS_OVERRIDE);
4007 }
4008
4009 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4010 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4012 "Override ASNs in outbound updates if aspath equals remote-as\n")
4013
4014 /* neighbor remove-private-AS. */
4015 DEFUN (neighbor_remove_private_as,
4016 neighbor_remove_private_as_cmd,
4017 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4018 NEIGHBOR_STR
4019 NEIGHBOR_ADDR_STR2
4020 "Remove private ASNs in outbound updates\n")
4021 {
4022 int idx_peer = 1;
4023 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4024 bgp_node_safi(vty),
4025 PEER_FLAG_REMOVE_PRIVATE_AS);
4026 }
4027
4028 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4029 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n")
4032
4033 DEFUN (neighbor_remove_private_as_all,
4034 neighbor_remove_private_as_all_cmd,
4035 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4036 NEIGHBOR_STR
4037 NEIGHBOR_ADDR_STR2
4038 "Remove private ASNs in outbound updates\n"
4039 "Apply to all AS numbers\n")
4040 {
4041 int idx_peer = 1;
4042 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4043 bgp_node_safi(vty),
4044 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4045 }
4046
4047 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4048 neighbor_remove_private_as_all_hidden_cmd,
4049 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4050 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4051 "Remove private ASNs in outbound updates\n"
4052 "Apply to all AS numbers")
4053
4054 DEFUN (neighbor_remove_private_as_replace_as,
4055 neighbor_remove_private_as_replace_as_cmd,
4056 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4057 NEIGHBOR_STR
4058 NEIGHBOR_ADDR_STR2
4059 "Remove private ASNs in outbound updates\n"
4060 "Replace private ASNs with our ASN in outbound updates\n")
4061 {
4062 int idx_peer = 1;
4063 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4064 bgp_node_safi(vty),
4065 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4066 }
4067
4068 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4069 neighbor_remove_private_as_replace_as_hidden_cmd,
4070 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4072 "Remove private ASNs in outbound updates\n"
4073 "Replace private ASNs with our ASN in outbound updates\n")
4074
4075 DEFUN (neighbor_remove_private_as_all_replace_as,
4076 neighbor_remove_private_as_all_replace_as_cmd,
4077 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4078 NEIGHBOR_STR
4079 NEIGHBOR_ADDR_STR2
4080 "Remove private ASNs in outbound updates\n"
4081 "Apply to all AS numbers\n"
4082 "Replace private ASNs with our ASN in outbound updates\n")
4083 {
4084 int idx_peer = 1;
4085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4086 bgp_node_safi(vty),
4087 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4088 }
4089
4090 ALIAS_HIDDEN(
4091 neighbor_remove_private_as_all_replace_as,
4092 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4093 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4094 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4095 "Remove private ASNs in outbound updates\n"
4096 "Apply to all AS numbers\n"
4097 "Replace private ASNs with our ASN in outbound updates\n")
4098
4099 DEFUN (no_neighbor_remove_private_as,
4100 no_neighbor_remove_private_as_cmd,
4101 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4102 NO_STR
4103 NEIGHBOR_STR
4104 NEIGHBOR_ADDR_STR2
4105 "Remove private ASNs in outbound updates\n")
4106 {
4107 int idx_peer = 2;
4108 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4109 bgp_node_afi(vty), bgp_node_safi(vty),
4110 PEER_FLAG_REMOVE_PRIVATE_AS);
4111 }
4112
4113 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4114 no_neighbor_remove_private_as_hidden_cmd,
4115 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4116 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4117 "Remove private ASNs in outbound updates\n")
4118
4119 DEFUN (no_neighbor_remove_private_as_all,
4120 no_neighbor_remove_private_as_all_cmd,
4121 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4122 NO_STR
4123 NEIGHBOR_STR
4124 NEIGHBOR_ADDR_STR2
4125 "Remove private ASNs in outbound updates\n"
4126 "Apply to all AS numbers\n")
4127 {
4128 int idx_peer = 2;
4129 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4130 bgp_node_afi(vty), bgp_node_safi(vty),
4131 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4132 }
4133
4134 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4135 no_neighbor_remove_private_as_all_hidden_cmd,
4136 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4137 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4138 "Remove private ASNs in outbound updates\n"
4139 "Apply to all AS numbers\n")
4140
4141 DEFUN (no_neighbor_remove_private_as_replace_as,
4142 no_neighbor_remove_private_as_replace_as_cmd,
4143 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4144 NO_STR
4145 NEIGHBOR_STR
4146 NEIGHBOR_ADDR_STR2
4147 "Remove private ASNs in outbound updates\n"
4148 "Replace private ASNs with our ASN in outbound updates\n")
4149 {
4150 int idx_peer = 2;
4151 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4152 bgp_node_afi(vty), bgp_node_safi(vty),
4153 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4154 }
4155
4156 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4157 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4158 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4160 "Remove private ASNs in outbound updates\n"
4161 "Replace private ASNs with our ASN in outbound updates\n")
4162
4163 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4164 no_neighbor_remove_private_as_all_replace_as_cmd,
4165 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4166 NO_STR
4167 NEIGHBOR_STR
4168 NEIGHBOR_ADDR_STR2
4169 "Remove private ASNs in outbound updates\n"
4170 "Apply to all AS numbers\n"
4171 "Replace private ASNs with our ASN in outbound updates\n")
4172 {
4173 int idx_peer = 2;
4174 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4175 bgp_node_afi(vty), bgp_node_safi(vty),
4176 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4177 }
4178
4179 ALIAS_HIDDEN(
4180 no_neighbor_remove_private_as_all_replace_as,
4181 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4182 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4184 "Remove private ASNs in outbound updates\n"
4185 "Apply to all AS numbers\n"
4186 "Replace private ASNs with our ASN in outbound updates\n")
4187
4188
4189 /* neighbor send-community. */
4190 DEFUN (neighbor_send_community,
4191 neighbor_send_community_cmd,
4192 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4193 NEIGHBOR_STR
4194 NEIGHBOR_ADDR_STR2
4195 "Send Community attribute to this neighbor\n")
4196 {
4197 int idx_peer = 1;
4198
4199 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4200 bgp_node_safi(vty),
4201 PEER_FLAG_SEND_COMMUNITY);
4202 }
4203
4204 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4205 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4206 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4207 "Send Community attribute to this neighbor\n")
4208
4209 DEFUN (no_neighbor_send_community,
4210 no_neighbor_send_community_cmd,
4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4212 NO_STR
4213 NEIGHBOR_STR
4214 NEIGHBOR_ADDR_STR2
4215 "Send Community attribute to this neighbor\n")
4216 {
4217 int idx_peer = 2;
4218
4219 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4220 bgp_node_afi(vty), bgp_node_safi(vty),
4221 PEER_FLAG_SEND_COMMUNITY);
4222 }
4223
4224 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4225 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4227 "Send Community attribute to this neighbor\n")
4228
4229 /* neighbor send-community extended. */
4230 DEFUN (neighbor_send_community_type,
4231 neighbor_send_community_type_cmd,
4232 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4233 NEIGHBOR_STR
4234 NEIGHBOR_ADDR_STR2
4235 "Send Community attribute to this neighbor\n"
4236 "Send Standard and Extended Community attributes\n"
4237 "Send Standard, Large and Extended Community attributes\n"
4238 "Send Extended Community attributes\n"
4239 "Send Standard Community attributes\n"
4240 "Send Large Community attributes\n")
4241 {
4242 int idx_peer = 1;
4243 uint32_t flag = 0;
4244 const char *type = argv[argc - 1]->text;
4245
4246 if (strmatch(type, "standard")) {
4247 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4248 } else if (strmatch(type, "extended")) {
4249 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4250 } else if (strmatch(type, "large")) {
4251 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4252 } else if (strmatch(type, "both")) {
4253 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4254 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4255 } else { /* if (strmatch(type, "all")) */
4256 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4257 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4258 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4259 }
4260
4261 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4262 bgp_node_safi(vty), flag);
4263 }
4264
4265 ALIAS_HIDDEN(
4266 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4267 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4268 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4269 "Send Community attribute to this neighbor\n"
4270 "Send Standard and Extended Community attributes\n"
4271 "Send Standard, Large and Extended Community attributes\n"
4272 "Send Extended Community attributes\n"
4273 "Send Standard Community attributes\n"
4274 "Send Large Community attributes\n")
4275
4276 DEFUN (no_neighbor_send_community_type,
4277 no_neighbor_send_community_type_cmd,
4278 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4279 NO_STR
4280 NEIGHBOR_STR
4281 NEIGHBOR_ADDR_STR2
4282 "Send Community attribute to this neighbor\n"
4283 "Send Standard and Extended Community attributes\n"
4284 "Send Standard, Large and Extended Community attributes\n"
4285 "Send Extended Community attributes\n"
4286 "Send Standard Community attributes\n"
4287 "Send Large Community attributes\n")
4288 {
4289 int idx_peer = 2;
4290 uint32_t flag = 0;
4291 const char *type = argv[argc - 1]->text;
4292
4293 if (strmatch(type, "standard")) {
4294 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4295 } else if (strmatch(type, "extended")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4297 } else if (strmatch(type, "large")) {
4298 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4299 } else if (strmatch(type, "both")) {
4300 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4301 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4302 } else { /* if (strmatch(type, "all")) */
4303 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4304 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4305 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4306 }
4307
4308 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4309 bgp_node_afi(vty), bgp_node_safi(vty),
4310 flag);
4311 }
4312
4313 ALIAS_HIDDEN(
4314 no_neighbor_send_community_type,
4315 no_neighbor_send_community_type_hidden_cmd,
4316 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4317 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4318 "Send Community attribute to this neighbor\n"
4319 "Send Standard and Extended Community attributes\n"
4320 "Send Standard, Large and Extended Community attributes\n"
4321 "Send Extended Community attributes\n"
4322 "Send Standard Community attributes\n"
4323 "Send Large Community attributes\n")
4324
4325 /* neighbor soft-reconfig. */
4326 DEFUN (neighbor_soft_reconfiguration,
4327 neighbor_soft_reconfiguration_cmd,
4328 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4329 NEIGHBOR_STR
4330 NEIGHBOR_ADDR_STR2
4331 "Per neighbor soft reconfiguration\n"
4332 "Allow inbound soft reconfiguration for this neighbor\n")
4333 {
4334 int idx_peer = 1;
4335 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4336 bgp_node_safi(vty),
4337 PEER_FLAG_SOFT_RECONFIG);
4338 }
4339
4340 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4341 neighbor_soft_reconfiguration_hidden_cmd,
4342 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4344 "Per neighbor soft reconfiguration\n"
4345 "Allow inbound soft reconfiguration for this neighbor\n")
4346
4347 DEFUN (no_neighbor_soft_reconfiguration,
4348 no_neighbor_soft_reconfiguration_cmd,
4349 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4350 NO_STR
4351 NEIGHBOR_STR
4352 NEIGHBOR_ADDR_STR2
4353 "Per neighbor soft reconfiguration\n"
4354 "Allow inbound soft reconfiguration for this neighbor\n")
4355 {
4356 int idx_peer = 2;
4357 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4358 bgp_node_afi(vty), bgp_node_safi(vty),
4359 PEER_FLAG_SOFT_RECONFIG);
4360 }
4361
4362 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4363 no_neighbor_soft_reconfiguration_hidden_cmd,
4364 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4366 "Per neighbor soft reconfiguration\n"
4367 "Allow inbound soft reconfiguration for this neighbor\n")
4368
4369 DEFUN (neighbor_route_reflector_client,
4370 neighbor_route_reflector_client_cmd,
4371 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4372 NEIGHBOR_STR
4373 NEIGHBOR_ADDR_STR2
4374 "Configure a neighbor as Route Reflector client\n")
4375 {
4376 int idx_peer = 1;
4377 struct peer *peer;
4378
4379
4380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4381 if (!peer)
4382 return CMD_WARNING_CONFIG_FAILED;
4383
4384 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4385 bgp_node_safi(vty),
4386 PEER_FLAG_REFLECTOR_CLIENT);
4387 }
4388
4389 ALIAS_HIDDEN(neighbor_route_reflector_client,
4390 neighbor_route_reflector_client_hidden_cmd,
4391 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4392 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4393 "Configure a neighbor as Route Reflector client\n")
4394
4395 DEFUN (no_neighbor_route_reflector_client,
4396 no_neighbor_route_reflector_client_cmd,
4397 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4398 NO_STR
4399 NEIGHBOR_STR
4400 NEIGHBOR_ADDR_STR2
4401 "Configure a neighbor as Route Reflector client\n")
4402 {
4403 int idx_peer = 2;
4404 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4405 bgp_node_afi(vty), bgp_node_safi(vty),
4406 PEER_FLAG_REFLECTOR_CLIENT);
4407 }
4408
4409 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4410 no_neighbor_route_reflector_client_hidden_cmd,
4411 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4413 "Configure a neighbor as Route Reflector client\n")
4414
4415 /* neighbor route-server-client. */
4416 DEFUN (neighbor_route_server_client,
4417 neighbor_route_server_client_cmd,
4418 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4419 NEIGHBOR_STR
4420 NEIGHBOR_ADDR_STR2
4421 "Configure a neighbor as Route Server client\n")
4422 {
4423 int idx_peer = 1;
4424 struct peer *peer;
4425
4426 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4427 if (!peer)
4428 return CMD_WARNING_CONFIG_FAILED;
4429 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4430 bgp_node_safi(vty),
4431 PEER_FLAG_RSERVER_CLIENT);
4432 }
4433
4434 ALIAS_HIDDEN(neighbor_route_server_client,
4435 neighbor_route_server_client_hidden_cmd,
4436 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4437 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4438 "Configure a neighbor as Route Server client\n")
4439
4440 DEFUN (no_neighbor_route_server_client,
4441 no_neighbor_route_server_client_cmd,
4442 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4443 NO_STR
4444 NEIGHBOR_STR
4445 NEIGHBOR_ADDR_STR2
4446 "Configure a neighbor as Route Server client\n")
4447 {
4448 int idx_peer = 2;
4449 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4450 bgp_node_afi(vty), bgp_node_safi(vty),
4451 PEER_FLAG_RSERVER_CLIENT);
4452 }
4453
4454 ALIAS_HIDDEN(no_neighbor_route_server_client,
4455 no_neighbor_route_server_client_hidden_cmd,
4456 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4457 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4458 "Configure a neighbor as Route Server client\n")
4459
4460 DEFUN (neighbor_nexthop_local_unchanged,
4461 neighbor_nexthop_local_unchanged_cmd,
4462 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4463 NEIGHBOR_STR
4464 NEIGHBOR_ADDR_STR2
4465 "Configure treatment of outgoing link-local nexthop attribute\n"
4466 "Leave link-local nexthop unchanged for this peer\n")
4467 {
4468 int idx_peer = 1;
4469 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4470 bgp_node_safi(vty),
4471 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4472 }
4473
4474 DEFUN (no_neighbor_nexthop_local_unchanged,
4475 no_neighbor_nexthop_local_unchanged_cmd,
4476 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4477 NO_STR
4478 NEIGHBOR_STR
4479 NEIGHBOR_ADDR_STR2
4480 "Configure treatment of outgoing link-local-nexthop attribute\n"
4481 "Leave link-local nexthop unchanged for this peer\n")
4482 {
4483 int idx_peer = 2;
4484 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4485 bgp_node_afi(vty), bgp_node_safi(vty),
4486 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4487 }
4488
4489 DEFUN (neighbor_attr_unchanged,
4490 neighbor_attr_unchanged_cmd,
4491 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4492 NEIGHBOR_STR
4493 NEIGHBOR_ADDR_STR2
4494 "BGP attribute is propagated unchanged to this neighbor\n"
4495 "As-path attribute\n"
4496 "Nexthop attribute\n"
4497 "Med attribute\n")
4498 {
4499 int idx = 0;
4500 char *peer_str = argv[1]->arg;
4501 struct peer *peer;
4502 uint16_t flags = 0;
4503 afi_t afi = bgp_node_afi(vty);
4504 safi_t safi = bgp_node_safi(vty);
4505
4506 peer = peer_and_group_lookup_vty(vty, peer_str);
4507 if (!peer)
4508 return CMD_WARNING_CONFIG_FAILED;
4509
4510 if (argv_find(argv, argc, "as-path", &idx))
4511 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4512 idx = 0;
4513 if (argv_find(argv, argc, "next-hop", &idx))
4514 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4515 idx = 0;
4516 if (argv_find(argv, argc, "med", &idx))
4517 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4518
4519 /* no flags means all of them! */
4520 if (!flags) {
4521 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4522 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4523 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4524 } else {
4525 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4526 && peer_af_flag_check(peer, afi, safi,
4527 PEER_FLAG_AS_PATH_UNCHANGED)) {
4528 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4529 PEER_FLAG_AS_PATH_UNCHANGED);
4530 }
4531
4532 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4533 && peer_af_flag_check(peer, afi, safi,
4534 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4535 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4536 PEER_FLAG_NEXTHOP_UNCHANGED);
4537 }
4538
4539 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4540 && peer_af_flag_check(peer, afi, safi,
4541 PEER_FLAG_MED_UNCHANGED)) {
4542 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4543 PEER_FLAG_MED_UNCHANGED);
4544 }
4545 }
4546
4547 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4548 }
4549
4550 ALIAS_HIDDEN(
4551 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4552 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4553 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4554 "BGP attribute is propagated unchanged to this neighbor\n"
4555 "As-path attribute\n"
4556 "Nexthop attribute\n"
4557 "Med attribute\n")
4558
4559 DEFUN (no_neighbor_attr_unchanged,
4560 no_neighbor_attr_unchanged_cmd,
4561 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4562 NO_STR
4563 NEIGHBOR_STR
4564 NEIGHBOR_ADDR_STR2
4565 "BGP attribute is propagated unchanged to this neighbor\n"
4566 "As-path attribute\n"
4567 "Nexthop attribute\n"
4568 "Med attribute\n")
4569 {
4570 int idx = 0;
4571 char *peer = argv[2]->arg;
4572 uint16_t flags = 0;
4573
4574 if (argv_find(argv, argc, "as-path", &idx))
4575 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4576 idx = 0;
4577 if (argv_find(argv, argc, "next-hop", &idx))
4578 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4579 idx = 0;
4580 if (argv_find(argv, argc, "med", &idx))
4581 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4582
4583 if (!flags) // no flags means all of them!
4584 {
4585 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4586 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4587 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4588 }
4589
4590 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4591 bgp_node_safi(vty), flags);
4592 }
4593
4594 ALIAS_HIDDEN(
4595 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4596 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4597 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4598 "BGP attribute is propagated unchanged to this neighbor\n"
4599 "As-path attribute\n"
4600 "Nexthop attribute\n"
4601 "Med attribute\n")
4602
4603 /* EBGP multihop configuration. */
4604 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4605 const char *ttl_str)
4606 {
4607 struct peer *peer;
4608 unsigned int ttl;
4609
4610 peer = peer_and_group_lookup_vty(vty, ip_str);
4611 if (!peer)
4612 return CMD_WARNING_CONFIG_FAILED;
4613
4614 if (peer->conf_if)
4615 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4616
4617 if (!ttl_str)
4618 ttl = MAXTTL;
4619 else
4620 ttl = strtoul(ttl_str, NULL, 10);
4621
4622 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4623 }
4624
4625 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4626 {
4627 struct peer *peer;
4628
4629 peer = peer_and_group_lookup_vty(vty, ip_str);
4630 if (!peer)
4631 return CMD_WARNING_CONFIG_FAILED;
4632
4633 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4634 }
4635
4636 /* neighbor ebgp-multihop. */
4637 DEFUN (neighbor_ebgp_multihop,
4638 neighbor_ebgp_multihop_cmd,
4639 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4640 NEIGHBOR_STR
4641 NEIGHBOR_ADDR_STR2
4642 "Allow EBGP neighbors not on directly connected networks\n")
4643 {
4644 int idx_peer = 1;
4645 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4646 }
4647
4648 DEFUN (neighbor_ebgp_multihop_ttl,
4649 neighbor_ebgp_multihop_ttl_cmd,
4650 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4651 NEIGHBOR_STR
4652 NEIGHBOR_ADDR_STR2
4653 "Allow EBGP neighbors not on directly connected networks\n"
4654 "maximum hop count\n")
4655 {
4656 int idx_peer = 1;
4657 int idx_number = 3;
4658 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4659 argv[idx_number]->arg);
4660 }
4661
4662 DEFUN (no_neighbor_ebgp_multihop,
4663 no_neighbor_ebgp_multihop_cmd,
4664 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4665 NO_STR
4666 NEIGHBOR_STR
4667 NEIGHBOR_ADDR_STR2
4668 "Allow EBGP neighbors not on directly connected networks\n"
4669 "maximum hop count\n")
4670 {
4671 int idx_peer = 2;
4672 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4673 }
4674
4675
4676 /* disable-connected-check */
4677 DEFUN (neighbor_disable_connected_check,
4678 neighbor_disable_connected_check_cmd,
4679 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "one-hop away EBGP peer using loopback address\n"
4683 "Enforce EBGP neighbors perform multihop\n")
4684 {
4685 int idx_peer = 1;
4686 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4687 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4688 }
4689
4690 DEFUN (no_neighbor_disable_connected_check,
4691 no_neighbor_disable_connected_check_cmd,
4692 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4693 NO_STR
4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "one-hop away EBGP peer using loopback address\n"
4697 "Enforce EBGP neighbors perform multihop\n")
4698 {
4699 int idx_peer = 2;
4700 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4701 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4702 }
4703
4704
4705 /* enforce-first-as */
4706 DEFUN (neighbor_enforce_first_as,
4707 neighbor_enforce_first_as_cmd,
4708 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "Enforce the first AS for EBGP routes\n")
4712 {
4713 int idx_peer = 1;
4714
4715 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4716 PEER_FLAG_ENFORCE_FIRST_AS);
4717 }
4718
4719 DEFUN (no_neighbor_enforce_first_as,
4720 no_neighbor_enforce_first_as_cmd,
4721 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4722 NO_STR
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "Enforce the first AS for EBGP routes\n")
4726 {
4727 int idx_peer = 2;
4728
4729 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_ENFORCE_FIRST_AS);
4731 }
4732
4733
4734 DEFUN (neighbor_description,
4735 neighbor_description_cmd,
4736 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4737 NEIGHBOR_STR
4738 NEIGHBOR_ADDR_STR2
4739 "Neighbor specific description\n"
4740 "Up to 80 characters describing this neighbor\n")
4741 {
4742 int idx_peer = 1;
4743 int idx_line = 3;
4744 struct peer *peer;
4745 char *str;
4746
4747 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4748 if (!peer)
4749 return CMD_WARNING_CONFIG_FAILED;
4750
4751 str = argv_concat(argv, argc, idx_line);
4752
4753 peer_description_set(peer, str);
4754
4755 XFREE(MTYPE_TMP, str);
4756
4757 return CMD_SUCCESS;
4758 }
4759
4760 DEFUN (no_neighbor_description,
4761 no_neighbor_description_cmd,
4762 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4763 NO_STR
4764 NEIGHBOR_STR
4765 NEIGHBOR_ADDR_STR2
4766 "Neighbor specific description\n")
4767 {
4768 int idx_peer = 2;
4769 struct peer *peer;
4770
4771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4772 if (!peer)
4773 return CMD_WARNING_CONFIG_FAILED;
4774
4775 peer_description_unset(peer);
4776
4777 return CMD_SUCCESS;
4778 }
4779
4780 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4781 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4782 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4783 "Neighbor specific description\n"
4784 "Up to 80 characters describing this neighbor\n")
4785
4786 /* Neighbor update-source. */
4787 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4788 const char *source_str)
4789 {
4790 struct peer *peer;
4791 struct prefix p;
4792 union sockunion su;
4793
4794 peer = peer_and_group_lookup_vty(vty, peer_str);
4795 if (!peer)
4796 return CMD_WARNING_CONFIG_FAILED;
4797
4798 if (peer->conf_if)
4799 return CMD_WARNING;
4800
4801 if (source_str) {
4802 if (str2sockunion(source_str, &su) == 0)
4803 peer_update_source_addr_set(peer, &su);
4804 else {
4805 if (str2prefix(source_str, &p)) {
4806 vty_out(vty,
4807 "%% Invalid update-source, remove prefix length \n");
4808 return CMD_WARNING_CONFIG_FAILED;
4809 } else
4810 peer_update_source_if_set(peer, source_str);
4811 }
4812 } else
4813 peer_update_source_unset(peer);
4814
4815 return CMD_SUCCESS;
4816 }
4817
4818 #define BGP_UPDATE_SOURCE_HELP_STR \
4819 "IPv4 address\n" \
4820 "IPv6 address\n" \
4821 "Interface name (requires zebra to be running)\n"
4822
4823 DEFUN (neighbor_update_source,
4824 neighbor_update_source_cmd,
4825 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4826 NEIGHBOR_STR
4827 NEIGHBOR_ADDR_STR2
4828 "Source of routing updates\n"
4829 BGP_UPDATE_SOURCE_HELP_STR)
4830 {
4831 int idx_peer = 1;
4832 int idx_peer_2 = 3;
4833 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4834 argv[idx_peer_2]->arg);
4835 }
4836
4837 DEFUN (no_neighbor_update_source,
4838 no_neighbor_update_source_cmd,
4839 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4840 NO_STR
4841 NEIGHBOR_STR
4842 NEIGHBOR_ADDR_STR2
4843 "Source of routing updates\n"
4844 BGP_UPDATE_SOURCE_HELP_STR)
4845 {
4846 int idx_peer = 2;
4847 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4848 }
4849
4850 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4851 afi_t afi, safi_t safi,
4852 const char *rmap, int set)
4853 {
4854 int ret;
4855 struct peer *peer;
4856 struct route_map *route_map;
4857
4858 peer = peer_and_group_lookup_vty(vty, peer_str);
4859 if (!peer)
4860 return CMD_WARNING_CONFIG_FAILED;
4861
4862 if (set) {
4863 route_map = route_map_lookup_warn_noexist(vty, rmap);
4864 ret = peer_default_originate_set(peer, afi, safi,
4865 rmap, route_map);
4866 } else
4867 ret = peer_default_originate_unset(peer, afi, safi);
4868
4869 return bgp_vty_return(vty, ret);
4870 }
4871
4872 /* neighbor default-originate. */
4873 DEFUN (neighbor_default_originate,
4874 neighbor_default_originate_cmd,
4875 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4876 NEIGHBOR_STR
4877 NEIGHBOR_ADDR_STR2
4878 "Originate default route to this neighbor\n")
4879 {
4880 int idx_peer = 1;
4881 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4882 bgp_node_afi(vty),
4883 bgp_node_safi(vty), NULL, 1);
4884 }
4885
4886 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4887 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4888 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4889 "Originate default route to this neighbor\n")
4890
4891 DEFUN (neighbor_default_originate_rmap,
4892 neighbor_default_originate_rmap_cmd,
4893 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Originate default route to this neighbor\n"
4897 "Route-map to specify criteria to originate default\n"
4898 "route-map name\n")
4899 {
4900 int idx_peer = 1;
4901 int idx_word = 4;
4902 return peer_default_originate_set_vty(
4903 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4904 argv[idx_word]->arg, 1);
4905 }
4906
4907 ALIAS_HIDDEN(
4908 neighbor_default_originate_rmap,
4909 neighbor_default_originate_rmap_hidden_cmd,
4910 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4912 "Originate default route to this neighbor\n"
4913 "Route-map to specify criteria to originate default\n"
4914 "route-map name\n")
4915
4916 DEFUN (no_neighbor_default_originate,
4917 no_neighbor_default_originate_cmd,
4918 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4919 NO_STR
4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Originate default route to this neighbor\n"
4923 "Route-map to specify criteria to originate default\n"
4924 "route-map name\n")
4925 {
4926 int idx_peer = 2;
4927 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4928 bgp_node_afi(vty),
4929 bgp_node_safi(vty), NULL, 0);
4930 }
4931
4932 ALIAS_HIDDEN(
4933 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4934 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4935 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4936 "Originate default route to this neighbor\n"
4937 "Route-map to specify criteria to originate default\n"
4938 "route-map name\n")
4939
4940
4941 /* Set neighbor's BGP port. */
4942 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4943 const char *port_str)
4944 {
4945 struct peer *peer;
4946 uint16_t port;
4947 struct servent *sp;
4948
4949 peer = peer_lookup_vty(vty, ip_str);
4950 if (!peer)
4951 return CMD_WARNING_CONFIG_FAILED;
4952
4953 if (!port_str) {
4954 sp = getservbyname("bgp", "tcp");
4955 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4956 } else {
4957 port = strtoul(port_str, NULL, 10);
4958 }
4959
4960 peer_port_set(peer, port);
4961
4962 return CMD_SUCCESS;
4963 }
4964
4965 /* Set specified peer's BGP port. */
4966 DEFUN (neighbor_port,
4967 neighbor_port_cmd,
4968 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4969 NEIGHBOR_STR
4970 NEIGHBOR_ADDR_STR
4971 "Neighbor's BGP port\n"
4972 "TCP port number\n")
4973 {
4974 int idx_ip = 1;
4975 int idx_number = 3;
4976 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4977 argv[idx_number]->arg);
4978 }
4979
4980 DEFUN (no_neighbor_port,
4981 no_neighbor_port_cmd,
4982 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4983 NO_STR
4984 NEIGHBOR_STR
4985 NEIGHBOR_ADDR_STR
4986 "Neighbor's BGP port\n"
4987 "TCP port number\n")
4988 {
4989 int idx_ip = 2;
4990 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4991 }
4992
4993
4994 /* neighbor weight. */
4995 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4996 safi_t safi, const char *weight_str)
4997 {
4998 int ret;
4999 struct peer *peer;
5000 unsigned long weight;
5001
5002 peer = peer_and_group_lookup_vty(vty, ip_str);
5003 if (!peer)
5004 return CMD_WARNING_CONFIG_FAILED;
5005
5006 weight = strtoul(weight_str, NULL, 10);
5007
5008 ret = peer_weight_set(peer, afi, safi, weight);
5009 return bgp_vty_return(vty, ret);
5010 }
5011
5012 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5013 safi_t safi)
5014 {
5015 int ret;
5016 struct peer *peer;
5017
5018 peer = peer_and_group_lookup_vty(vty, ip_str);
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
5021
5022 ret = peer_weight_unset(peer, afi, safi);
5023 return bgp_vty_return(vty, ret);
5024 }
5025
5026 DEFUN (neighbor_weight,
5027 neighbor_weight_cmd,
5028 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5029 NEIGHBOR_STR
5030 NEIGHBOR_ADDR_STR2
5031 "Set default weight for routes from this neighbor\n"
5032 "default weight\n")
5033 {
5034 int idx_peer = 1;
5035 int idx_number = 3;
5036 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5037 bgp_node_safi(vty), argv[idx_number]->arg);
5038 }
5039
5040 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5041 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5042 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5043 "Set default weight for routes from this neighbor\n"
5044 "default weight\n")
5045
5046 DEFUN (no_neighbor_weight,
5047 no_neighbor_weight_cmd,
5048 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5049 NO_STR
5050 NEIGHBOR_STR
5051 NEIGHBOR_ADDR_STR2
5052 "Set default weight for routes from this neighbor\n"
5053 "default weight\n")
5054 {
5055 int idx_peer = 2;
5056 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5057 bgp_node_afi(vty), bgp_node_safi(vty));
5058 }
5059
5060 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5061 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5063 "Set default weight for routes from this neighbor\n"
5064 "default weight\n")
5065
5066
5067 /* Override capability negotiation. */
5068 DEFUN (neighbor_override_capability,
5069 neighbor_override_capability_cmd,
5070 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5071 NEIGHBOR_STR
5072 NEIGHBOR_ADDR_STR2
5073 "Override capability negotiation result\n")
5074 {
5075 int idx_peer = 1;
5076 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5077 PEER_FLAG_OVERRIDE_CAPABILITY);
5078 }
5079
5080 DEFUN (no_neighbor_override_capability,
5081 no_neighbor_override_capability_cmd,
5082 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5083 NO_STR
5084 NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Override capability negotiation result\n")
5087 {
5088 int idx_peer = 2;
5089 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5090 PEER_FLAG_OVERRIDE_CAPABILITY);
5091 }
5092
5093 DEFUN (neighbor_strict_capability,
5094 neighbor_strict_capability_cmd,
5095 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5096 NEIGHBOR_STR
5097 NEIGHBOR_ADDR_STR2
5098 "Strict capability negotiation match\n")
5099 {
5100 int idx_peer = 1;
5101
5102 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5103 PEER_FLAG_STRICT_CAP_MATCH);
5104 }
5105
5106 DEFUN (no_neighbor_strict_capability,
5107 no_neighbor_strict_capability_cmd,
5108 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5109 NO_STR
5110 NEIGHBOR_STR
5111 NEIGHBOR_ADDR_STR2
5112 "Strict capability negotiation match\n")
5113 {
5114 int idx_peer = 2;
5115
5116 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5117 PEER_FLAG_STRICT_CAP_MATCH);
5118 }
5119
5120 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5121 const char *keep_str, const char *hold_str)
5122 {
5123 int ret;
5124 struct peer *peer;
5125 uint32_t keepalive;
5126 uint32_t holdtime;
5127
5128 peer = peer_and_group_lookup_vty(vty, ip_str);
5129 if (!peer)
5130 return CMD_WARNING_CONFIG_FAILED;
5131
5132 keepalive = strtoul(keep_str, NULL, 10);
5133 holdtime = strtoul(hold_str, NULL, 10);
5134
5135 ret = peer_timers_set(peer, keepalive, holdtime);
5136
5137 return bgp_vty_return(vty, ret);
5138 }
5139
5140 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5141 {
5142 int ret;
5143 struct peer *peer;
5144
5145 peer = peer_and_group_lookup_vty(vty, ip_str);
5146 if (!peer)
5147 return CMD_WARNING_CONFIG_FAILED;
5148
5149 ret = peer_timers_unset(peer);
5150
5151 return bgp_vty_return(vty, ret);
5152 }
5153
5154 DEFUN (neighbor_timers,
5155 neighbor_timers_cmd,
5156 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5157 NEIGHBOR_STR
5158 NEIGHBOR_ADDR_STR2
5159 "BGP per neighbor timers\n"
5160 "Keepalive interval\n"
5161 "Holdtime\n")
5162 {
5163 int idx_peer = 1;
5164 int idx_number = 3;
5165 int idx_number_2 = 4;
5166 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5167 argv[idx_number]->arg,
5168 argv[idx_number_2]->arg);
5169 }
5170
5171 DEFUN (no_neighbor_timers,
5172 no_neighbor_timers_cmd,
5173 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5174 NO_STR
5175 NEIGHBOR_STR
5176 NEIGHBOR_ADDR_STR2
5177 "BGP per neighbor timers\n"
5178 "Keepalive interval\n"
5179 "Holdtime\n")
5180 {
5181 int idx_peer = 2;
5182 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5183 }
5184
5185
5186 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5187 const char *time_str)
5188 {
5189 int ret;
5190 struct peer *peer;
5191 uint32_t connect;
5192
5193 peer = peer_and_group_lookup_vty(vty, ip_str);
5194 if (!peer)
5195 return CMD_WARNING_CONFIG_FAILED;
5196
5197 connect = strtoul(time_str, NULL, 10);
5198
5199 ret = peer_timers_connect_set(peer, connect);
5200
5201 return bgp_vty_return(vty, ret);
5202 }
5203
5204 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5205 {
5206 int ret;
5207 struct peer *peer;
5208
5209 peer = peer_and_group_lookup_vty(vty, ip_str);
5210 if (!peer)
5211 return CMD_WARNING_CONFIG_FAILED;
5212
5213 ret = peer_timers_connect_unset(peer);
5214
5215 return bgp_vty_return(vty, ret);
5216 }
5217
5218 DEFUN (neighbor_timers_connect,
5219 neighbor_timers_connect_cmd,
5220 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5221 NEIGHBOR_STR
5222 NEIGHBOR_ADDR_STR2
5223 "BGP per neighbor timers\n"
5224 "BGP connect timer\n"
5225 "Connect timer\n")
5226 {
5227 int idx_peer = 1;
5228 int idx_number = 4;
5229 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5230 argv[idx_number]->arg);
5231 }
5232
5233 DEFUN (no_neighbor_timers_connect,
5234 no_neighbor_timers_connect_cmd,
5235 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5236 NO_STR
5237 NEIGHBOR_STR
5238 NEIGHBOR_ADDR_STR2
5239 "BGP per neighbor timers\n"
5240 "BGP connect timer\n"
5241 "Connect timer\n")
5242 {
5243 int idx_peer = 2;
5244 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5245 }
5246
5247
5248 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5249 const char *time_str, int set)
5250 {
5251 int ret;
5252 struct peer *peer;
5253 uint32_t routeadv = 0;
5254
5255 peer = peer_and_group_lookup_vty(vty, ip_str);
5256 if (!peer)
5257 return CMD_WARNING_CONFIG_FAILED;
5258
5259 if (time_str)
5260 routeadv = strtoul(time_str, NULL, 10);
5261
5262 if (set)
5263 ret = peer_advertise_interval_set(peer, routeadv);
5264 else
5265 ret = peer_advertise_interval_unset(peer);
5266
5267 return bgp_vty_return(vty, ret);
5268 }
5269
5270 DEFUN (neighbor_advertise_interval,
5271 neighbor_advertise_interval_cmd,
5272 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5273 NEIGHBOR_STR
5274 NEIGHBOR_ADDR_STR2
5275 "Minimum interval between sending BGP routing updates\n"
5276 "time in seconds\n")
5277 {
5278 int idx_peer = 1;
5279 int idx_number = 3;
5280 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5281 argv[idx_number]->arg, 1);
5282 }
5283
5284 DEFUN (no_neighbor_advertise_interval,
5285 no_neighbor_advertise_interval_cmd,
5286 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5287 NO_STR
5288 NEIGHBOR_STR
5289 NEIGHBOR_ADDR_STR2
5290 "Minimum interval between sending BGP routing updates\n"
5291 "time in seconds\n")
5292 {
5293 int idx_peer = 2;
5294 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5295 }
5296
5297
5298 /* Time to wait before processing route-map updates */
5299 DEFUN (bgp_set_route_map_delay_timer,
5300 bgp_set_route_map_delay_timer_cmd,
5301 "bgp route-map delay-timer (0-600)",
5302 SET_STR
5303 "BGP route-map delay timer\n"
5304 "Time in secs to wait before processing route-map changes\n"
5305 "0 disables the timer, no route updates happen when route-maps change\n")
5306 {
5307 int idx_number = 3;
5308 uint32_t rmap_delay_timer;
5309
5310 if (argv[idx_number]->arg) {
5311 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5312 bm->rmap_update_timer = rmap_delay_timer;
5313
5314 /* if the dynamic update handling is being disabled, and a timer
5315 * is
5316 * running, stop the timer and act as if the timer has already
5317 * fired.
5318 */
5319 if (!rmap_delay_timer && bm->t_rmap_update) {
5320 BGP_TIMER_OFF(bm->t_rmap_update);
5321 thread_execute(bm->master, bgp_route_map_update_timer,
5322 NULL, 0);
5323 }
5324 return CMD_SUCCESS;
5325 } else {
5326 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5327 return CMD_WARNING_CONFIG_FAILED;
5328 }
5329 }
5330
5331 DEFUN (no_bgp_set_route_map_delay_timer,
5332 no_bgp_set_route_map_delay_timer_cmd,
5333 "no bgp route-map delay-timer [(0-600)]",
5334 NO_STR
5335 BGP_STR
5336 "Default BGP route-map delay timer\n"
5337 "Reset to default time to wait for processing route-map changes\n"
5338 "0 disables the timer, no route updates happen when route-maps change\n")
5339 {
5340
5341 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5342
5343 return CMD_SUCCESS;
5344 }
5345
5346
5347 /* neighbor interface */
5348 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5349 const char *str)
5350 {
5351 struct peer *peer;
5352
5353 peer = peer_lookup_vty(vty, ip_str);
5354 if (!peer || peer->conf_if) {
5355 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5356 return CMD_WARNING_CONFIG_FAILED;
5357 }
5358
5359 if (str)
5360 peer_interface_set(peer, str);
5361 else
5362 peer_interface_unset(peer);
5363
5364 return CMD_SUCCESS;
5365 }
5366
5367 DEFUN (neighbor_interface,
5368 neighbor_interface_cmd,
5369 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5370 NEIGHBOR_STR
5371 NEIGHBOR_ADDR_STR
5372 "Interface\n"
5373 "Interface name\n")
5374 {
5375 int idx_ip = 1;
5376 int idx_word = 3;
5377 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5378 }
5379
5380 DEFUN (no_neighbor_interface,
5381 no_neighbor_interface_cmd,
5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5383 NO_STR
5384 NEIGHBOR_STR
5385 NEIGHBOR_ADDR_STR2
5386 "Interface\n"
5387 "Interface name\n")
5388 {
5389 int idx_peer = 2;
5390 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5391 }
5392
5393 DEFUN (neighbor_distribute_list,
5394 neighbor_distribute_list_cmd,
5395 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5396 NEIGHBOR_STR
5397 NEIGHBOR_ADDR_STR2
5398 "Filter updates to/from this neighbor\n"
5399 "IP access-list number\n"
5400 "IP access-list number (expanded range)\n"
5401 "IP Access-list name\n"
5402 "Filter incoming updates\n"
5403 "Filter outgoing updates\n")
5404 {
5405 int idx_peer = 1;
5406 int idx_acl = 3;
5407 int direct, ret;
5408 struct peer *peer;
5409
5410 const char *pstr = argv[idx_peer]->arg;
5411 const char *acl = argv[idx_acl]->arg;
5412 const char *inout = argv[argc - 1]->text;
5413
5414 peer = peer_and_group_lookup_vty(vty, pstr);
5415 if (!peer)
5416 return CMD_WARNING_CONFIG_FAILED;
5417
5418 /* Check filter direction. */
5419 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5420 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5421 direct, acl);
5422
5423 return bgp_vty_return(vty, ret);
5424 }
5425
5426 ALIAS_HIDDEN(
5427 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5428 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5429 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5430 "Filter updates to/from this neighbor\n"
5431 "IP access-list number\n"
5432 "IP access-list number (expanded range)\n"
5433 "IP Access-list name\n"
5434 "Filter incoming updates\n"
5435 "Filter outgoing updates\n")
5436
5437 DEFUN (no_neighbor_distribute_list,
5438 no_neighbor_distribute_list_cmd,
5439 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5440 NO_STR
5441 NEIGHBOR_STR
5442 NEIGHBOR_ADDR_STR2
5443 "Filter updates to/from this neighbor\n"
5444 "IP access-list number\n"
5445 "IP access-list number (expanded range)\n"
5446 "IP Access-list name\n"
5447 "Filter incoming updates\n"
5448 "Filter outgoing updates\n")
5449 {
5450 int idx_peer = 2;
5451 int direct, ret;
5452 struct peer *peer;
5453
5454 const char *pstr = argv[idx_peer]->arg;
5455 const char *inout = argv[argc - 1]->text;
5456
5457 peer = peer_and_group_lookup_vty(vty, pstr);
5458 if (!peer)
5459 return CMD_WARNING_CONFIG_FAILED;
5460
5461 /* Check filter direction. */
5462 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5463 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5464 direct);
5465
5466 return bgp_vty_return(vty, ret);
5467 }
5468
5469 ALIAS_HIDDEN(
5470 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5471 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5472 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5473 "Filter updates to/from this neighbor\n"
5474 "IP access-list number\n"
5475 "IP access-list number (expanded range)\n"
5476 "IP Access-list name\n"
5477 "Filter incoming updates\n"
5478 "Filter outgoing updates\n")
5479
5480 /* Set prefix list to the peer. */
5481 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5482 afi_t afi, safi_t safi,
5483 const char *name_str,
5484 const char *direct_str)
5485 {
5486 int ret;
5487 int direct = FILTER_IN;
5488 struct peer *peer;
5489
5490 peer = peer_and_group_lookup_vty(vty, ip_str);
5491 if (!peer)
5492 return CMD_WARNING_CONFIG_FAILED;
5493
5494 /* Check filter direction. */
5495 if (strncmp(direct_str, "i", 1) == 0)
5496 direct = FILTER_IN;
5497 else if (strncmp(direct_str, "o", 1) == 0)
5498 direct = FILTER_OUT;
5499
5500 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5501
5502 return bgp_vty_return(vty, ret);
5503 }
5504
5505 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5506 afi_t afi, safi_t safi,
5507 const char *direct_str)
5508 {
5509 int ret;
5510 struct peer *peer;
5511 int direct = FILTER_IN;
5512
5513 peer = peer_and_group_lookup_vty(vty, ip_str);
5514 if (!peer)
5515 return CMD_WARNING_CONFIG_FAILED;
5516
5517 /* Check filter direction. */
5518 if (strncmp(direct_str, "i", 1) == 0)
5519 direct = FILTER_IN;
5520 else if (strncmp(direct_str, "o", 1) == 0)
5521 direct = FILTER_OUT;
5522
5523 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5524
5525 return bgp_vty_return(vty, ret);
5526 }
5527
5528 DEFUN (neighbor_prefix_list,
5529 neighbor_prefix_list_cmd,
5530 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Filter updates to/from this neighbor\n"
5534 "Name of a prefix list\n"
5535 "Filter incoming updates\n"
5536 "Filter outgoing updates\n")
5537 {
5538 int idx_peer = 1;
5539 int idx_word = 3;
5540 int idx_in_out = 4;
5541 return peer_prefix_list_set_vty(
5542 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5543 argv[idx_word]->arg, argv[idx_in_out]->arg);
5544 }
5545
5546 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5547 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5549 "Filter updates to/from this neighbor\n"
5550 "Name of a prefix list\n"
5551 "Filter incoming updates\n"
5552 "Filter outgoing updates\n")
5553
5554 DEFUN (no_neighbor_prefix_list,
5555 no_neighbor_prefix_list_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5557 NO_STR
5558 NEIGHBOR_STR
5559 NEIGHBOR_ADDR_STR2
5560 "Filter updates to/from this neighbor\n"
5561 "Name of a prefix list\n"
5562 "Filter incoming updates\n"
5563 "Filter outgoing updates\n")
5564 {
5565 int idx_peer = 2;
5566 int idx_in_out = 5;
5567 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5568 bgp_node_afi(vty), bgp_node_safi(vty),
5569 argv[idx_in_out]->arg);
5570 }
5571
5572 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5573 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5574 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5575 "Filter updates to/from this neighbor\n"
5576 "Name of a prefix list\n"
5577 "Filter incoming updates\n"
5578 "Filter outgoing updates\n")
5579
5580 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5581 safi_t safi, const char *name_str,
5582 const char *direct_str)
5583 {
5584 int ret;
5585 struct peer *peer;
5586 int direct = FILTER_IN;
5587
5588 peer = peer_and_group_lookup_vty(vty, ip_str);
5589 if (!peer)
5590 return CMD_WARNING_CONFIG_FAILED;
5591
5592 /* Check filter direction. */
5593 if (strncmp(direct_str, "i", 1) == 0)
5594 direct = FILTER_IN;
5595 else if (strncmp(direct_str, "o", 1) == 0)
5596 direct = FILTER_OUT;
5597
5598 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5599
5600 return bgp_vty_return(vty, ret);
5601 }
5602
5603 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5604 safi_t safi, const char *direct_str)
5605 {
5606 int ret;
5607 struct peer *peer;
5608 int direct = FILTER_IN;
5609
5610 peer = peer_and_group_lookup_vty(vty, ip_str);
5611 if (!peer)
5612 return CMD_WARNING_CONFIG_FAILED;
5613
5614 /* Check filter direction. */
5615 if (strncmp(direct_str, "i", 1) == 0)
5616 direct = FILTER_IN;
5617 else if (strncmp(direct_str, "o", 1) == 0)
5618 direct = FILTER_OUT;
5619
5620 ret = peer_aslist_unset(peer, afi, safi, direct);
5621
5622 return bgp_vty_return(vty, ret);
5623 }
5624
5625 DEFUN (neighbor_filter_list,
5626 neighbor_filter_list_cmd,
5627 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5628 NEIGHBOR_STR
5629 NEIGHBOR_ADDR_STR2
5630 "Establish BGP filters\n"
5631 "AS path access-list name\n"
5632 "Filter incoming routes\n"
5633 "Filter outgoing routes\n")
5634 {
5635 int idx_peer = 1;
5636 int idx_word = 3;
5637 int idx_in_out = 4;
5638 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5639 bgp_node_safi(vty), argv[idx_word]->arg,
5640 argv[idx_in_out]->arg);
5641 }
5642
5643 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5644 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5646 "Establish BGP filters\n"
5647 "AS path access-list name\n"
5648 "Filter incoming routes\n"
5649 "Filter outgoing routes\n")
5650
5651 DEFUN (no_neighbor_filter_list,
5652 no_neighbor_filter_list_cmd,
5653 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5654 NO_STR
5655 NEIGHBOR_STR
5656 NEIGHBOR_ADDR_STR2
5657 "Establish BGP filters\n"
5658 "AS path access-list name\n"
5659 "Filter incoming routes\n"
5660 "Filter outgoing routes\n")
5661 {
5662 int idx_peer = 2;
5663 int idx_in_out = 5;
5664 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5665 bgp_node_afi(vty), bgp_node_safi(vty),
5666 argv[idx_in_out]->arg);
5667 }
5668
5669 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5670 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5672 "Establish BGP filters\n"
5673 "AS path access-list name\n"
5674 "Filter incoming routes\n"
5675 "Filter outgoing routes\n")
5676
5677 /* Set route-map to the peer. */
5678 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5679 afi_t afi, safi_t safi, const char *name_str,
5680 const char *direct_str)
5681 {
5682 int ret;
5683 struct peer *peer;
5684 int direct = RMAP_IN;
5685 struct route_map *route_map;
5686
5687 peer = peer_and_group_lookup_vty(vty, ip_str);
5688 if (!peer)
5689 return CMD_WARNING_CONFIG_FAILED;
5690
5691 /* Check filter direction. */
5692 if (strncmp(direct_str, "in", 2) == 0)
5693 direct = RMAP_IN;
5694 else if (strncmp(direct_str, "o", 1) == 0)
5695 direct = RMAP_OUT;
5696
5697 route_map = route_map_lookup_warn_noexist(vty, name_str);
5698 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5699
5700 return bgp_vty_return(vty, ret);
5701 }
5702
5703 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5704 afi_t afi, safi_t safi,
5705 const char *direct_str)
5706 {
5707 int ret;
5708 struct peer *peer;
5709 int direct = RMAP_IN;
5710
5711 peer = peer_and_group_lookup_vty(vty, ip_str);
5712 if (!peer)
5713 return CMD_WARNING_CONFIG_FAILED;
5714
5715 /* Check filter direction. */
5716 if (strncmp(direct_str, "in", 2) == 0)
5717 direct = RMAP_IN;
5718 else if (strncmp(direct_str, "o", 1) == 0)
5719 direct = RMAP_OUT;
5720
5721 ret = peer_route_map_unset(peer, afi, safi, direct);
5722
5723 return bgp_vty_return(vty, ret);
5724 }
5725
5726 DEFUN (neighbor_route_map,
5727 neighbor_route_map_cmd,
5728 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5729 NEIGHBOR_STR
5730 NEIGHBOR_ADDR_STR2
5731 "Apply route map to neighbor\n"
5732 "Name of route map\n"
5733 "Apply map to incoming routes\n"
5734 "Apply map to outbound routes\n")
5735 {
5736 int idx_peer = 1;
5737 int idx_word = 3;
5738 int idx_in_out = 4;
5739 return peer_route_map_set_vty(
5740 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5741 argv[idx_word]->arg, argv[idx_in_out]->arg);
5742 }
5743
5744 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5745 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5746 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Apply route map to neighbor\n"
5748 "Name of route map\n"
5749 "Apply map to incoming routes\n"
5750 "Apply map to outbound routes\n")
5751
5752 DEFUN (no_neighbor_route_map,
5753 no_neighbor_route_map_cmd,
5754 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5755 NO_STR
5756 NEIGHBOR_STR
5757 NEIGHBOR_ADDR_STR2
5758 "Apply route map to neighbor\n"
5759 "Name of route map\n"
5760 "Apply map to incoming routes\n"
5761 "Apply map to outbound routes\n")
5762 {
5763 int idx_peer = 2;
5764 int idx_in_out = 5;
5765 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5766 bgp_node_afi(vty), bgp_node_safi(vty),
5767 argv[idx_in_out]->arg);
5768 }
5769
5770 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5771 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5773 "Apply route map to neighbor\n"
5774 "Name of route map\n"
5775 "Apply map to incoming routes\n"
5776 "Apply map to outbound routes\n")
5777
5778 /* Set unsuppress-map to the peer. */
5779 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5780 afi_t afi, safi_t safi,
5781 const char *name_str)
5782 {
5783 int ret;
5784 struct peer *peer;
5785 struct route_map *route_map;
5786
5787 peer = peer_and_group_lookup_vty(vty, ip_str);
5788 if (!peer)
5789 return CMD_WARNING_CONFIG_FAILED;
5790
5791 route_map = route_map_lookup_warn_noexist(vty, name_str);
5792 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5793
5794 return bgp_vty_return(vty, ret);
5795 }
5796
5797 /* Unset route-map from the peer. */
5798 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5799 afi_t afi, safi_t safi)
5800 {
5801 int ret;
5802 struct peer *peer;
5803
5804 peer = peer_and_group_lookup_vty(vty, ip_str);
5805 if (!peer)
5806 return CMD_WARNING_CONFIG_FAILED;
5807
5808 ret = peer_unsuppress_map_unset(peer, afi, safi);
5809
5810 return bgp_vty_return(vty, ret);
5811 }
5812
5813 DEFUN (neighbor_unsuppress_map,
5814 neighbor_unsuppress_map_cmd,
5815 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
5818 "Route-map to selectively unsuppress suppressed routes\n"
5819 "Name of route map\n")
5820 {
5821 int idx_peer = 1;
5822 int idx_word = 3;
5823 return peer_unsuppress_map_set_vty(
5824 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5825 argv[idx_word]->arg);
5826 }
5827
5828 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Route-map to selectively unsuppress suppressed routes\n"
5832 "Name of route map\n")
5833
5834 DEFUN (no_neighbor_unsuppress_map,
5835 no_neighbor_unsuppress_map_cmd,
5836 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5837 NO_STR
5838 NEIGHBOR_STR
5839 NEIGHBOR_ADDR_STR2
5840 "Route-map to selectively unsuppress suppressed routes\n"
5841 "Name of route map\n")
5842 {
5843 int idx_peer = 2;
5844 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5845 bgp_node_afi(vty),
5846 bgp_node_safi(vty));
5847 }
5848
5849 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5850 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5851 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5852 "Route-map to selectively unsuppress suppressed routes\n"
5853 "Name of route map\n")
5854
5855 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5856 afi_t afi, safi_t safi,
5857 const char *num_str,
5858 const char *threshold_str, int warning,
5859 const char *restart_str)
5860 {
5861 int ret;
5862 struct peer *peer;
5863 uint32_t max;
5864 uint8_t threshold;
5865 uint16_t restart;
5866
5867 peer = peer_and_group_lookup_vty(vty, ip_str);
5868 if (!peer)
5869 return CMD_WARNING_CONFIG_FAILED;
5870
5871 max = strtoul(num_str, NULL, 10);
5872 if (threshold_str)
5873 threshold = atoi(threshold_str);
5874 else
5875 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5876
5877 if (restart_str)
5878 restart = atoi(restart_str);
5879 else
5880 restart = 0;
5881
5882 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5883 restart);
5884
5885 return bgp_vty_return(vty, ret);
5886 }
5887
5888 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5889 afi_t afi, safi_t safi)
5890 {
5891 int ret;
5892 struct peer *peer;
5893
5894 peer = peer_and_group_lookup_vty(vty, ip_str);
5895 if (!peer)
5896 return CMD_WARNING_CONFIG_FAILED;
5897
5898 ret = peer_maximum_prefix_unset(peer, afi, safi);
5899
5900 return bgp_vty_return(vty, ret);
5901 }
5902
5903 /* Maximum number of prefix configuration. prefix count is different
5904 for each peer configuration. So this configuration can be set for
5905 each peer configuration. */
5906 DEFUN (neighbor_maximum_prefix,
5907 neighbor_maximum_prefix_cmd,
5908 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5909 NEIGHBOR_STR
5910 NEIGHBOR_ADDR_STR2
5911 "Maximum number of prefix accept from this peer\n"
5912 "maximum no. of prefix limit\n")
5913 {
5914 int idx_peer = 1;
5915 int idx_number = 3;
5916 return peer_maximum_prefix_set_vty(
5917 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5918 argv[idx_number]->arg, NULL, 0, NULL);
5919 }
5920
5921 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5922 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5923 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5924 "Maximum number of prefix accept from this peer\n"
5925 "maximum no. of prefix limit\n")
5926
5927 DEFUN (neighbor_maximum_prefix_threshold,
5928 neighbor_maximum_prefix_threshold_cmd,
5929 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Maximum number of prefix accept from this peer\n"
5933 "maximum no. of prefix limit\n"
5934 "Threshold value (%) at which to generate a warning msg\n")
5935 {
5936 int idx_peer = 1;
5937 int idx_number = 3;
5938 int idx_number_2 = 4;
5939 return peer_maximum_prefix_set_vty(
5940 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5941 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5942 }
5943
5944 ALIAS_HIDDEN(
5945 neighbor_maximum_prefix_threshold,
5946 neighbor_maximum_prefix_threshold_hidden_cmd,
5947 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5949 "Maximum number of prefix accept from this peer\n"
5950 "maximum no. of prefix limit\n"
5951 "Threshold value (%) at which to generate a warning msg\n")
5952
5953 DEFUN (neighbor_maximum_prefix_warning,
5954 neighbor_maximum_prefix_warning_cmd,
5955 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5956 NEIGHBOR_STR
5957 NEIGHBOR_ADDR_STR2
5958 "Maximum number of prefix accept from this peer\n"
5959 "maximum no. of prefix limit\n"
5960 "Only give warning message when limit is exceeded\n")
5961 {
5962 int idx_peer = 1;
5963 int idx_number = 3;
5964 return peer_maximum_prefix_set_vty(
5965 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5966 argv[idx_number]->arg, NULL, 1, NULL);
5967 }
5968
5969 ALIAS_HIDDEN(
5970 neighbor_maximum_prefix_warning,
5971 neighbor_maximum_prefix_warning_hidden_cmd,
5972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5974 "Maximum number of prefix accept from this peer\n"
5975 "maximum no. of prefix limit\n"
5976 "Only give warning message when limit is exceeded\n")
5977
5978 DEFUN (neighbor_maximum_prefix_threshold_warning,
5979 neighbor_maximum_prefix_threshold_warning_cmd,
5980 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5981 NEIGHBOR_STR
5982 NEIGHBOR_ADDR_STR2
5983 "Maximum number of prefix accept from this peer\n"
5984 "maximum no. of prefix limit\n"
5985 "Threshold value (%) at which to generate a warning msg\n"
5986 "Only give warning message when limit is exceeded\n")
5987 {
5988 int idx_peer = 1;
5989 int idx_number = 3;
5990 int idx_number_2 = 4;
5991 return peer_maximum_prefix_set_vty(
5992 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5993 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5994 }
5995
5996 ALIAS_HIDDEN(
5997 neighbor_maximum_prefix_threshold_warning,
5998 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5999 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6000 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6001 "Maximum number of prefix accept from this peer\n"
6002 "maximum no. of prefix limit\n"
6003 "Threshold value (%) at which to generate a warning msg\n"
6004 "Only give warning message when limit is exceeded\n")
6005
6006 DEFUN (neighbor_maximum_prefix_restart,
6007 neighbor_maximum_prefix_restart_cmd,
6008 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6009 NEIGHBOR_STR
6010 NEIGHBOR_ADDR_STR2
6011 "Maximum number of prefix accept from this peer\n"
6012 "maximum no. of prefix limit\n"
6013 "Restart bgp connection after limit is exceeded\n"
6014 "Restart interval in minutes\n")
6015 {
6016 int idx_peer = 1;
6017 int idx_number = 3;
6018 int idx_number_2 = 5;
6019 return peer_maximum_prefix_set_vty(
6020 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6021 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6022 }
6023
6024 ALIAS_HIDDEN(
6025 neighbor_maximum_prefix_restart,
6026 neighbor_maximum_prefix_restart_hidden_cmd,
6027 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6028 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6029 "Maximum number of prefix accept from this peer\n"
6030 "maximum no. of prefix limit\n"
6031 "Restart bgp connection after limit is exceeded\n"
6032 "Restart interval in minutes\n")
6033
6034 DEFUN (neighbor_maximum_prefix_threshold_restart,
6035 neighbor_maximum_prefix_threshold_restart_cmd,
6036 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
6039 "Maximum number of prefixes to accept from this peer\n"
6040 "maximum no. of prefix limit\n"
6041 "Threshold value (%) at which to generate a warning msg\n"
6042 "Restart bgp connection after limit is exceeded\n"
6043 "Restart interval in minutes\n")
6044 {
6045 int idx_peer = 1;
6046 int idx_number = 3;
6047 int idx_number_2 = 4;
6048 int idx_number_3 = 6;
6049 return peer_maximum_prefix_set_vty(
6050 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6051 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6052 argv[idx_number_3]->arg);
6053 }
6054
6055 ALIAS_HIDDEN(
6056 neighbor_maximum_prefix_threshold_restart,
6057 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6058 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6059 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6060 "Maximum number of prefixes to accept from this peer\n"
6061 "maximum no. of prefix limit\n"
6062 "Threshold value (%) at which to generate a warning msg\n"
6063 "Restart bgp connection after limit is exceeded\n"
6064 "Restart interval in minutes\n")
6065
6066 DEFUN (no_neighbor_maximum_prefix,
6067 no_neighbor_maximum_prefix_cmd,
6068 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6069 NO_STR
6070 NEIGHBOR_STR
6071 NEIGHBOR_ADDR_STR2
6072 "Maximum number of prefixes to accept from this peer\n"
6073 "maximum no. of prefix limit\n"
6074 "Threshold value (%) at which to generate a warning msg\n"
6075 "Restart bgp connection after limit is exceeded\n"
6076 "Restart interval in minutes\n"
6077 "Only give warning message when limit is exceeded\n")
6078 {
6079 int idx_peer = 2;
6080 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6081 bgp_node_afi(vty),
6082 bgp_node_safi(vty));
6083 }
6084
6085 ALIAS_HIDDEN(
6086 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6087 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6088 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6089 "Maximum number of prefixes to accept from this peer\n"
6090 "maximum no. of prefix limit\n"
6091 "Threshold value (%) at which to generate a warning msg\n"
6092 "Restart bgp connection after limit is exceeded\n"
6093 "Restart interval in minutes\n"
6094 "Only give warning message when limit is exceeded\n")
6095
6096
6097 /* "neighbor allowas-in" */
6098 DEFUN (neighbor_allowas_in,
6099 neighbor_allowas_in_cmd,
6100 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "Accept as-path with my AS present in it\n"
6104 "Number of occurences of AS number\n"
6105 "Only accept my AS in the as-path if the route was originated in my AS\n")
6106 {
6107 int idx_peer = 1;
6108 int idx_number_origin = 3;
6109 int ret;
6110 int origin = 0;
6111 struct peer *peer;
6112 int allow_num = 0;
6113
6114 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6115 if (!peer)
6116 return CMD_WARNING_CONFIG_FAILED;
6117
6118 if (argc <= idx_number_origin)
6119 allow_num = 3;
6120 else {
6121 if (argv[idx_number_origin]->type == WORD_TKN)
6122 origin = 1;
6123 else
6124 allow_num = atoi(argv[idx_number_origin]->arg);
6125 }
6126
6127 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6128 allow_num, origin);
6129
6130 return bgp_vty_return(vty, ret);
6131 }
6132
6133 ALIAS_HIDDEN(
6134 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6135 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6136 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6137 "Accept as-path with my AS present in it\n"
6138 "Number of occurences of AS number\n"
6139 "Only accept my AS in the as-path if the route was originated in my AS\n")
6140
6141 DEFUN (no_neighbor_allowas_in,
6142 no_neighbor_allowas_in_cmd,
6143 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6144 NO_STR
6145 NEIGHBOR_STR
6146 NEIGHBOR_ADDR_STR2
6147 "allow local ASN appears in aspath attribute\n"
6148 "Number of occurences of AS number\n"
6149 "Only accept my AS in the as-path if the route was originated in my AS\n")
6150 {
6151 int idx_peer = 2;
6152 int ret;
6153 struct peer *peer;
6154
6155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6156 if (!peer)
6157 return CMD_WARNING_CONFIG_FAILED;
6158
6159 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6160 bgp_node_safi(vty));
6161
6162 return bgp_vty_return(vty, ret);
6163 }
6164
6165 ALIAS_HIDDEN(
6166 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6167 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6168 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6169 "allow local ASN appears in aspath attribute\n"
6170 "Number of occurences of AS number\n"
6171 "Only accept my AS in the as-path if the route was originated in my AS\n")
6172
6173 DEFUN (neighbor_ttl_security,
6174 neighbor_ttl_security_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6176 NEIGHBOR_STR
6177 NEIGHBOR_ADDR_STR2
6178 "BGP ttl-security parameters\n"
6179 "Specify the maximum number of hops to the BGP peer\n"
6180 "Number of hops to BGP peer\n")
6181 {
6182 int idx_peer = 1;
6183 int idx_number = 4;
6184 struct peer *peer;
6185 int gtsm_hops;
6186
6187 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6188 if (!peer)
6189 return CMD_WARNING_CONFIG_FAILED;
6190
6191 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6192
6193 /*
6194 * If 'neighbor swpX', then this is for directly connected peers,
6195 * we should not accept a ttl-security hops value greater than 1.
6196 */
6197 if (peer->conf_if && (gtsm_hops > 1)) {
6198 vty_out(vty,
6199 "%s is directly connected peer, hops cannot exceed 1\n",
6200 argv[idx_peer]->arg);
6201 return CMD_WARNING_CONFIG_FAILED;
6202 }
6203
6204 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6205 }
6206
6207 DEFUN (no_neighbor_ttl_security,
6208 no_neighbor_ttl_security_cmd,
6209 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6210 NO_STR
6211 NEIGHBOR_STR
6212 NEIGHBOR_ADDR_STR2
6213 "BGP ttl-security parameters\n"
6214 "Specify the maximum number of hops to the BGP peer\n"
6215 "Number of hops to BGP peer\n")
6216 {
6217 int idx_peer = 2;
6218 struct peer *peer;
6219
6220 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6221 if (!peer)
6222 return CMD_WARNING_CONFIG_FAILED;
6223
6224 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6225 }
6226
6227 DEFUN (neighbor_addpath_tx_all_paths,
6228 neighbor_addpath_tx_all_paths_cmd,
6229 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6230 NEIGHBOR_STR
6231 NEIGHBOR_ADDR_STR2
6232 "Use addpath to advertise all paths to a neighbor\n")
6233 {
6234 int idx_peer = 1;
6235 struct peer *peer;
6236
6237 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6238 if (!peer)
6239 return CMD_WARNING_CONFIG_FAILED;
6240
6241 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6242 BGP_ADDPATH_ALL);
6243 return CMD_SUCCESS;
6244 }
6245
6246 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6247 neighbor_addpath_tx_all_paths_hidden_cmd,
6248 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6250 "Use addpath to advertise all paths to a neighbor\n")
6251
6252 DEFUN (no_neighbor_addpath_tx_all_paths,
6253 no_neighbor_addpath_tx_all_paths_cmd,
6254 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6255 NO_STR
6256 NEIGHBOR_STR
6257 NEIGHBOR_ADDR_STR2
6258 "Use addpath to advertise all paths to a neighbor\n")
6259 {
6260 int idx_peer = 2;
6261 struct peer *peer;
6262
6263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6264 if (!peer)
6265 return CMD_WARNING_CONFIG_FAILED;
6266
6267 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6268 != BGP_ADDPATH_ALL) {
6269 vty_out(vty,
6270 "%% Peer not currently configured to transmit all paths.");
6271 return CMD_WARNING_CONFIG_FAILED;
6272 }
6273
6274 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6275 BGP_ADDPATH_NONE);
6276
6277 return CMD_SUCCESS;
6278 }
6279
6280 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6281 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6282 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6283 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6284 "Use addpath to advertise all paths to a neighbor\n")
6285
6286 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6287 neighbor_addpath_tx_bestpath_per_as_cmd,
6288 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6289 NEIGHBOR_STR
6290 NEIGHBOR_ADDR_STR2
6291 "Use addpath to advertise the bestpath per each neighboring AS\n")
6292 {
6293 int idx_peer = 1;
6294 struct peer *peer;
6295
6296 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6297 if (!peer)
6298 return CMD_WARNING_CONFIG_FAILED;
6299
6300 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6301 BGP_ADDPATH_BEST_PER_AS);
6302
6303 return CMD_SUCCESS;
6304 }
6305
6306 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6307 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6308 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6309 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6310 "Use addpath to advertise the bestpath per each neighboring AS\n")
6311
6312 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6313 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6314 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6315 NO_STR
6316 NEIGHBOR_STR
6317 NEIGHBOR_ADDR_STR2
6318 "Use addpath to advertise the bestpath per each neighboring AS\n")
6319 {
6320 int idx_peer = 2;
6321 struct peer *peer;
6322
6323 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6324 if (!peer)
6325 return CMD_WARNING_CONFIG_FAILED;
6326
6327 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6328 != BGP_ADDPATH_BEST_PER_AS) {
6329 vty_out(vty,
6330 "%% Peer not currently configured to transmit all best path per as.");
6331 return CMD_WARNING_CONFIG_FAILED;
6332 }
6333
6334 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6335 BGP_ADDPATH_NONE);
6336
6337 return CMD_SUCCESS;
6338 }
6339
6340 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6341 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6342 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6343 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6344 "Use addpath to advertise the bestpath per each neighboring AS\n")
6345
6346 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6347 struct ecommunity **list)
6348 {
6349 struct ecommunity *ecom = NULL;
6350 struct ecommunity *ecomadd;
6351
6352 for (; argc; --argc, ++argv) {
6353
6354 ecomadd = ecommunity_str2com(argv[0]->arg,
6355 ECOMMUNITY_ROUTE_TARGET, 0);
6356 if (!ecomadd) {
6357 vty_out(vty, "Malformed community-list value\n");
6358 if (ecom)
6359 ecommunity_free(&ecom);
6360 return CMD_WARNING_CONFIG_FAILED;
6361 }
6362
6363 if (ecom) {
6364 ecommunity_merge(ecom, ecomadd);
6365 ecommunity_free(&ecomadd);
6366 } else {
6367 ecom = ecomadd;
6368 }
6369 }
6370
6371 if (*list) {
6372 ecommunity_free(&*list);
6373 }
6374 *list = ecom;
6375
6376 return CMD_SUCCESS;
6377 }
6378
6379 /*
6380 * v2vimport is true if we are handling a `import vrf ...` command
6381 */
6382 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6383 {
6384 afi_t afi;
6385
6386 switch (vty->node) {
6387 case BGP_IPV4_NODE:
6388 afi = AFI_IP;
6389 break;
6390 case BGP_IPV6_NODE:
6391 afi = AFI_IP6;
6392 break;
6393 default:
6394 vty_out(vty,
6395 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6396 return AFI_MAX;
6397 }
6398
6399 if (!v2vimport) {
6400 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6401 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6402 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6403 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6404 vty_out(vty,
6405 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6406 return AFI_MAX;
6407 }
6408 } else {
6409 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6410 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6411 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6412 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6413 vty_out(vty,
6414 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6415 return AFI_MAX;
6416 }
6417 }
6418 return afi;
6419 }
6420
6421 DEFPY (af_rd_vpn_export,
6422 af_rd_vpn_export_cmd,
6423 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6424 NO_STR
6425 "Specify route distinguisher\n"
6426 "Between current address-family and vpn\n"
6427 "For routes leaked from current address-family to vpn\n"
6428 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6429 {
6430 VTY_DECLVAR_CONTEXT(bgp, bgp);
6431 struct prefix_rd prd;
6432 int ret;
6433 afi_t afi;
6434 int idx = 0;
6435 int yes = 1;
6436
6437 if (argv_find(argv, argc, "no", &idx))
6438 yes = 0;
6439
6440 if (yes) {
6441 ret = str2prefix_rd(rd_str, &prd);
6442 if (!ret) {
6443 vty_out(vty, "%% Malformed rd\n");
6444 return CMD_WARNING_CONFIG_FAILED;
6445 }
6446 }
6447
6448 afi = vpn_policy_getafi(vty, bgp, false);
6449 if (afi == AFI_MAX)
6450 return CMD_WARNING_CONFIG_FAILED;
6451
6452 /*
6453 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6454 */
6455 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6456 bgp_get_default(), bgp);
6457
6458 if (yes) {
6459 bgp->vpn_policy[afi].tovpn_rd = prd;
6460 SET_FLAG(bgp->vpn_policy[afi].flags,
6461 BGP_VPN_POLICY_TOVPN_RD_SET);
6462 } else {
6463 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6464 BGP_VPN_POLICY_TOVPN_RD_SET);
6465 }
6466
6467 /* post-change: re-export vpn routes */
6468 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6469 bgp_get_default(), bgp);
6470
6471 return CMD_SUCCESS;
6472 }
6473
6474 ALIAS (af_rd_vpn_export,
6475 af_no_rd_vpn_export_cmd,
6476 "no rd vpn export",
6477 NO_STR
6478 "Specify route distinguisher\n"
6479 "Between current address-family and vpn\n"
6480 "For routes leaked from current address-family to vpn\n")
6481
6482 DEFPY (af_label_vpn_export,
6483 af_label_vpn_export_cmd,
6484 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6485 NO_STR
6486 "label value for VRF\n"
6487 "Between current address-family and vpn\n"
6488 "For routes leaked from current address-family to vpn\n"
6489 "Label Value <0-1048575>\n"
6490 "Automatically assign a label\n")
6491 {
6492 VTY_DECLVAR_CONTEXT(bgp, bgp);
6493 mpls_label_t label = MPLS_LABEL_NONE;
6494 afi_t afi;
6495 int idx = 0;
6496 int yes = 1;
6497
6498 if (argv_find(argv, argc, "no", &idx))
6499 yes = 0;
6500
6501 /* If "no ...", squash trailing parameter */
6502 if (!yes)
6503 label_auto = NULL;
6504
6505 if (yes) {
6506 if (!label_auto)
6507 label = label_val; /* parser should force unsigned */
6508 }
6509
6510 afi = vpn_policy_getafi(vty, bgp, false);
6511 if (afi == AFI_MAX)
6512 return CMD_WARNING_CONFIG_FAILED;
6513
6514
6515 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6516 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6517 /* no change */
6518 return CMD_SUCCESS;
6519
6520 /*
6521 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6522 */
6523 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6524 bgp_get_default(), bgp);
6525
6526 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6527 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6528
6529 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6530
6531 /*
6532 * label has previously been automatically
6533 * assigned by labelpool: release it
6534 *
6535 * NB if tovpn_label == MPLS_LABEL_NONE it
6536 * means the automatic assignment is in flight
6537 * and therefore the labelpool callback must
6538 * detect that the auto label is not needed.
6539 */
6540
6541 bgp_lp_release(LP_TYPE_VRF,
6542 &bgp->vpn_policy[afi],
6543 bgp->vpn_policy[afi].tovpn_label);
6544 }
6545 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6546 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6547 }
6548
6549 bgp->vpn_policy[afi].tovpn_label = label;
6550 if (label_auto) {
6551 SET_FLAG(bgp->vpn_policy[afi].flags,
6552 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6553 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6554 vpn_leak_label_callback);
6555 }
6556
6557 /* post-change: re-export vpn routes */
6558 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6559 bgp_get_default(), bgp);
6560
6561 return CMD_SUCCESS;
6562 }
6563
6564 ALIAS (af_label_vpn_export,
6565 af_no_label_vpn_export_cmd,
6566 "no label vpn export",
6567 NO_STR
6568 "label value for VRF\n"
6569 "Between current address-family and vpn\n"
6570 "For routes leaked from current address-family to vpn\n")
6571
6572 DEFPY (af_nexthop_vpn_export,
6573 af_nexthop_vpn_export_cmd,
6574 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6575 NO_STR
6576 "Specify next hop to use for VRF advertised prefixes\n"
6577 "Between current address-family and vpn\n"
6578 "For routes leaked from current address-family to vpn\n"
6579 "IPv4 prefix\n"
6580 "IPv6 prefix\n")
6581 {
6582 VTY_DECLVAR_CONTEXT(bgp, bgp);
6583 afi_t afi;
6584 struct prefix p;
6585 int idx = 0;
6586 int yes = 1;
6587
6588 if (argv_find(argv, argc, "no", &idx))
6589 yes = 0;
6590
6591 if (yes) {
6592 if (!sockunion2hostprefix(nexthop_str, &p))
6593 return CMD_WARNING_CONFIG_FAILED;
6594 }
6595
6596 afi = vpn_policy_getafi(vty, bgp, false);
6597 if (afi == AFI_MAX)
6598 return CMD_WARNING_CONFIG_FAILED;
6599
6600 /*
6601 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6602 */
6603 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6604 bgp_get_default(), bgp);
6605
6606 if (yes) {
6607 bgp->vpn_policy[afi].tovpn_nexthop = p;
6608 SET_FLAG(bgp->vpn_policy[afi].flags,
6609 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6610 } else {
6611 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6612 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6613 }
6614
6615 /* post-change: re-export vpn routes */
6616 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6617 bgp_get_default(), bgp);
6618
6619 return CMD_SUCCESS;
6620 }
6621
6622 ALIAS (af_nexthop_vpn_export,
6623 af_no_nexthop_vpn_export_cmd,
6624 "no nexthop vpn export",
6625 NO_STR
6626 "Specify next hop to use for VRF advertised prefixes\n"
6627 "Between current address-family and vpn\n"
6628 "For routes leaked from current address-family to vpn\n")
6629
6630 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6631 {
6632 if (!strcmp(dstr, "import")) {
6633 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6634 } else if (!strcmp(dstr, "export")) {
6635 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6636 } else if (!strcmp(dstr, "both")) {
6637 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6638 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6639 } else {
6640 vty_out(vty, "%% direction parse error\n");
6641 return CMD_WARNING_CONFIG_FAILED;
6642 }
6643 return CMD_SUCCESS;
6644 }
6645
6646 DEFPY (af_rt_vpn_imexport,
6647 af_rt_vpn_imexport_cmd,
6648 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6649 NO_STR
6650 "Specify route target list\n"
6651 "Specify route target list\n"
6652 "Between current address-family and vpn\n"
6653 "For routes leaked from vpn to current address-family: match any\n"
6654 "For routes leaked from current address-family to vpn: set\n"
6655 "both import: match any and export: set\n"
6656 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6657 {
6658 VTY_DECLVAR_CONTEXT(bgp, bgp);
6659 int ret;
6660 struct ecommunity *ecom = NULL;
6661 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6662 vpn_policy_direction_t dir;
6663 afi_t afi;
6664 int idx = 0;
6665 int yes = 1;
6666
6667 if (argv_find(argv, argc, "no", &idx))
6668 yes = 0;
6669
6670 afi = vpn_policy_getafi(vty, bgp, false);
6671 if (afi == AFI_MAX)
6672 return CMD_WARNING_CONFIG_FAILED;
6673
6674 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6675 if (ret != CMD_SUCCESS)
6676 return ret;
6677
6678 if (yes) {
6679 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6680 vty_out(vty, "%% Missing RTLIST\n");
6681 return CMD_WARNING_CONFIG_FAILED;
6682 }
6683 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6684 if (ret != CMD_SUCCESS) {
6685 return ret;
6686 }
6687 }
6688
6689 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6690 if (!dodir[dir])
6691 continue;
6692
6693 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6694
6695 if (yes) {
6696 if (bgp->vpn_policy[afi].rtlist[dir])
6697 ecommunity_free(
6698 &bgp->vpn_policy[afi].rtlist[dir]);
6699 bgp->vpn_policy[afi].rtlist[dir] =
6700 ecommunity_dup(ecom);
6701 } else {
6702 if (bgp->vpn_policy[afi].rtlist[dir])
6703 ecommunity_free(
6704 &bgp->vpn_policy[afi].rtlist[dir]);
6705 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6706 }
6707
6708 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6709 }
6710
6711 if (ecom)
6712 ecommunity_free(&ecom);
6713
6714 return CMD_SUCCESS;
6715 }
6716
6717 ALIAS (af_rt_vpn_imexport,
6718 af_no_rt_vpn_imexport_cmd,
6719 "no <rt|route-target> vpn <import|export|both>$direction_str",
6720 NO_STR
6721 "Specify route target list\n"
6722 "Specify route target list\n"
6723 "Between current address-family and vpn\n"
6724 "For routes leaked from vpn to current address-family\n"
6725 "For routes leaked from current address-family to vpn\n"
6726 "both import and export\n")
6727
6728 DEFPY (af_route_map_vpn_imexport,
6729 af_route_map_vpn_imexport_cmd,
6730 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6731 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6732 NO_STR
6733 "Specify route map\n"
6734 "Between current address-family and vpn\n"
6735 "For routes leaked from vpn to current address-family\n"
6736 "For routes leaked from current address-family to vpn\n"
6737 "name of route-map\n")
6738 {
6739 VTY_DECLVAR_CONTEXT(bgp, bgp);
6740 int ret;
6741 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6742 vpn_policy_direction_t dir;
6743 afi_t afi;
6744 int idx = 0;
6745 int yes = 1;
6746
6747 if (argv_find(argv, argc, "no", &idx))
6748 yes = 0;
6749
6750 afi = vpn_policy_getafi(vty, bgp, false);
6751 if (afi == AFI_MAX)
6752 return CMD_WARNING_CONFIG_FAILED;
6753
6754 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6755 if (ret != CMD_SUCCESS)
6756 return ret;
6757
6758 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6759 if (!dodir[dir])
6760 continue;
6761
6762 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6763
6764 if (yes) {
6765 if (bgp->vpn_policy[afi].rmap_name[dir])
6766 XFREE(MTYPE_ROUTE_MAP_NAME,
6767 bgp->vpn_policy[afi].rmap_name[dir]);
6768 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6769 MTYPE_ROUTE_MAP_NAME, rmap_str);
6770 bgp->vpn_policy[afi].rmap[dir] =
6771 route_map_lookup_warn_noexist(vty, rmap_str);
6772 if (!bgp->vpn_policy[afi].rmap[dir])
6773 return CMD_SUCCESS;
6774 } else {
6775 if (bgp->vpn_policy[afi].rmap_name[dir])
6776 XFREE(MTYPE_ROUTE_MAP_NAME,
6777 bgp->vpn_policy[afi].rmap_name[dir]);
6778 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6779 bgp->vpn_policy[afi].rmap[dir] = NULL;
6780 }
6781
6782 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6783 }
6784
6785 return CMD_SUCCESS;
6786 }
6787
6788 ALIAS (af_route_map_vpn_imexport,
6789 af_no_route_map_vpn_imexport_cmd,
6790 "no route-map vpn <import|export>$direction_str",
6791 NO_STR
6792 "Specify route map\n"
6793 "Between current address-family and vpn\n"
6794 "For routes leaked from vpn to current address-family\n"
6795 "For routes leaked from current address-family to vpn\n")
6796
6797 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6798 "[no] import vrf route-map RMAP$rmap_str",
6799 NO_STR
6800 "Import routes from another VRF\n"
6801 "Vrf routes being filtered\n"
6802 "Specify route map\n"
6803 "name of route-map\n")
6804 {
6805 VTY_DECLVAR_CONTEXT(bgp, bgp);
6806 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6807 afi_t afi;
6808 int idx = 0;
6809 int yes = 1;
6810 struct bgp *bgp_default;
6811
6812 if (argv_find(argv, argc, "no", &idx))
6813 yes = 0;
6814
6815 afi = vpn_policy_getafi(vty, bgp, true);
6816 if (afi == AFI_MAX)
6817 return CMD_WARNING_CONFIG_FAILED;
6818
6819 bgp_default = bgp_get_default();
6820 if (!bgp_default) {
6821 int32_t ret;
6822 as_t as = bgp->as;
6823
6824 /* Auto-create assuming the same AS */
6825 ret = bgp_get(&bgp_default, &as, NULL,
6826 BGP_INSTANCE_TYPE_DEFAULT);
6827
6828 if (ret) {
6829 vty_out(vty,
6830 "VRF default is not configured as a bgp instance\n");
6831 return CMD_WARNING;
6832 }
6833 }
6834
6835 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6836
6837 if (yes) {
6838 if (bgp->vpn_policy[afi].rmap_name[dir])
6839 XFREE(MTYPE_ROUTE_MAP_NAME,
6840 bgp->vpn_policy[afi].rmap_name[dir]);
6841 bgp->vpn_policy[afi].rmap_name[dir] =
6842 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6843 bgp->vpn_policy[afi].rmap[dir] =
6844 route_map_lookup_warn_noexist(vty, rmap_str);
6845 if (!bgp->vpn_policy[afi].rmap[dir])
6846 return CMD_SUCCESS;
6847 } else {
6848 if (bgp->vpn_policy[afi].rmap_name[dir])
6849 XFREE(MTYPE_ROUTE_MAP_NAME,
6850 bgp->vpn_policy[afi].rmap_name[dir]);
6851 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6852 bgp->vpn_policy[afi].rmap[dir] = NULL;
6853 }
6854
6855 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6856
6857 return CMD_SUCCESS;
6858 }
6859
6860 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6861 "no import vrf route-map",
6862 NO_STR
6863 "Import routes from another VRF\n"
6864 "Vrf routes being filtered\n"
6865 "Specify route map\n")
6866
6867 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6868 "[no] import vrf VIEWVRFNAME$import_name",
6869 NO_STR
6870 "Import routes from another VRF\n"
6871 "VRF to import from\n"
6872 "The name of the VRF\n")
6873 {
6874 VTY_DECLVAR_CONTEXT(bgp, bgp);
6875 struct listnode *node;
6876 struct bgp *vrf_bgp, *bgp_default;
6877 int32_t ret = 0;
6878 as_t as = bgp->as;
6879 bool remove = false;
6880 int32_t idx = 0;
6881 char *vname;
6882 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6883 safi_t safi;
6884 afi_t afi;
6885
6886 if (import_name == NULL) {
6887 vty_out(vty, "%% Missing import name\n");
6888 return CMD_WARNING;
6889 }
6890
6891 if (argv_find(argv, argc, "no", &idx))
6892 remove = true;
6893
6894 afi = vpn_policy_getafi(vty, bgp, true);
6895 if (afi == AFI_MAX)
6896 return CMD_WARNING_CONFIG_FAILED;
6897
6898 safi = bgp_node_safi(vty);
6899
6900 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6901 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6902 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6903 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6904 remove ? "unimport" : "import", import_name);
6905 return CMD_WARNING;
6906 }
6907
6908 bgp_default = bgp_get_default();
6909 if (!bgp_default) {
6910 /* Auto-create assuming the same AS */
6911 ret = bgp_get(&bgp_default, &as, NULL,
6912 BGP_INSTANCE_TYPE_DEFAULT);
6913
6914 if (ret) {
6915 vty_out(vty,
6916 "VRF default is not configured as a bgp instance\n");
6917 return CMD_WARNING;
6918 }
6919 }
6920
6921 vrf_bgp = bgp_lookup_by_name(import_name);
6922 if (!vrf_bgp) {
6923 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6924 vrf_bgp = bgp_default;
6925 else
6926 /* Auto-create assuming the same AS */
6927 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6928
6929 if (ret) {
6930 vty_out(vty,
6931 "VRF %s is not configured as a bgp instance\n",
6932 import_name);
6933 return CMD_WARNING;
6934 }
6935 }
6936
6937 if (remove) {
6938 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6939 } else {
6940 /* Already importing from "import_vrf"? */
6941 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6942 vname)) {
6943 if (strcmp(vname, import_name) == 0)
6944 return CMD_WARNING;
6945 }
6946
6947 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6948 }
6949
6950 return CMD_SUCCESS;
6951 }
6952
6953 /* This command is valid only in a bgp vrf instance or the default instance */
6954 DEFPY (bgp_imexport_vpn,
6955 bgp_imexport_vpn_cmd,
6956 "[no] <import|export>$direction_str vpn",
6957 NO_STR
6958 "Import routes to this address-family\n"
6959 "Export routes from this address-family\n"
6960 "to/from default instance VPN RIB\n")
6961 {
6962 VTY_DECLVAR_CONTEXT(bgp, bgp);
6963 int previous_state;
6964 afi_t afi;
6965 safi_t safi;
6966 int idx = 0;
6967 int yes = 1;
6968 int flag;
6969 vpn_policy_direction_t dir;
6970
6971 if (argv_find(argv, argc, "no", &idx))
6972 yes = 0;
6973
6974 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6975 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6976
6977 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6978 return CMD_WARNING_CONFIG_FAILED;
6979 }
6980
6981 afi = bgp_node_afi(vty);
6982 safi = bgp_node_safi(vty);
6983 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6984 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6985 return CMD_WARNING_CONFIG_FAILED;
6986 }
6987
6988 if (!strcmp(direction_str, "import")) {
6989 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6990 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6991 } else if (!strcmp(direction_str, "export")) {
6992 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6993 dir = BGP_VPN_POLICY_DIR_TOVPN;
6994 } else {
6995 vty_out(vty, "%% unknown direction %s\n", direction_str);
6996 return CMD_WARNING_CONFIG_FAILED;
6997 }
6998
6999 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7000
7001 if (yes) {
7002 SET_FLAG(bgp->af_flags[afi][safi], flag);
7003 if (!previous_state) {
7004 /* trigger export current vrf */
7005 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7006 }
7007 } else {
7008 if (previous_state) {
7009 /* trigger un-export current vrf */
7010 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7011 }
7012 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7013 }
7014
7015 return CMD_SUCCESS;
7016 }
7017
7018 DEFPY (af_routetarget_import,
7019 af_routetarget_import_cmd,
7020 "[no] <rt|route-target> redirect import RTLIST...",
7021 NO_STR
7022 "Specify route target list\n"
7023 "Specify route target list\n"
7024 "Flow-spec redirect type route target\n"
7025 "Import routes to this address-family\n"
7026 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7027 {
7028 VTY_DECLVAR_CONTEXT(bgp, bgp);
7029 int ret;
7030 struct ecommunity *ecom = NULL;
7031 afi_t afi;
7032 int idx = 0;
7033 int yes = 1;
7034
7035 if (argv_find(argv, argc, "no", &idx))
7036 yes = 0;
7037
7038 afi = vpn_policy_getafi(vty, bgp, false);
7039 if (afi == AFI_MAX)
7040 return CMD_WARNING_CONFIG_FAILED;
7041
7042 if (yes) {
7043 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7044 vty_out(vty, "%% Missing RTLIST\n");
7045 return CMD_WARNING_CONFIG_FAILED;
7046 }
7047 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7048 if (ret != CMD_SUCCESS)
7049 return ret;
7050 }
7051
7052 if (yes) {
7053 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7054 ecommunity_free(&bgp->vpn_policy[afi]
7055 .import_redirect_rtlist);
7056 bgp->vpn_policy[afi].import_redirect_rtlist =
7057 ecommunity_dup(ecom);
7058 } else {
7059 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7060 ecommunity_free(&bgp->vpn_policy[afi]
7061 .import_redirect_rtlist);
7062 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7063 }
7064
7065 if (ecom)
7066 ecommunity_free(&ecom);
7067
7068 return CMD_SUCCESS;
7069 }
7070
7071 DEFUN_NOSH (address_family_ipv4_safi,
7072 address_family_ipv4_safi_cmd,
7073 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7074 "Enter Address Family command mode\n"
7075 "Address Family\n"
7076 BGP_SAFI_WITH_LABEL_HELP_STR)
7077 {
7078
7079 if (argc == 3) {
7080 VTY_DECLVAR_CONTEXT(bgp, bgp);
7081 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7082 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7083 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7084 && safi != SAFI_EVPN) {
7085 vty_out(vty,
7086 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7087 return CMD_WARNING_CONFIG_FAILED;
7088 }
7089 vty->node = bgp_node_type(AFI_IP, safi);
7090 } else
7091 vty->node = BGP_IPV4_NODE;
7092
7093 return CMD_SUCCESS;
7094 }
7095
7096 DEFUN_NOSH (address_family_ipv6_safi,
7097 address_family_ipv6_safi_cmd,
7098 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7099 "Enter Address Family command mode\n"
7100 "Address Family\n"
7101 BGP_SAFI_WITH_LABEL_HELP_STR)
7102 {
7103 if (argc == 3) {
7104 VTY_DECLVAR_CONTEXT(bgp, bgp);
7105 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7106 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7107 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7108 && safi != SAFI_EVPN) {
7109 vty_out(vty,
7110 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7111 return CMD_WARNING_CONFIG_FAILED;
7112 }
7113 vty->node = bgp_node_type(AFI_IP6, safi);
7114 } else
7115 vty->node = BGP_IPV6_NODE;
7116
7117 return CMD_SUCCESS;
7118 }
7119
7120 #ifdef KEEP_OLD_VPN_COMMANDS
7121 DEFUN_NOSH (address_family_vpnv4,
7122 address_family_vpnv4_cmd,
7123 "address-family vpnv4 [unicast]",
7124 "Enter Address Family command mode\n"
7125 "Address Family\n"
7126 "Address Family modifier\n")
7127 {
7128 vty->node = BGP_VPNV4_NODE;
7129 return CMD_SUCCESS;
7130 }
7131
7132 DEFUN_NOSH (address_family_vpnv6,
7133 address_family_vpnv6_cmd,
7134 "address-family vpnv6 [unicast]",
7135 "Enter Address Family command mode\n"
7136 "Address Family\n"
7137 "Address Family modifier\n")
7138 {
7139 vty->node = BGP_VPNV6_NODE;
7140 return CMD_SUCCESS;
7141 }
7142 #endif
7143
7144 DEFUN_NOSH (address_family_evpn,
7145 address_family_evpn_cmd,
7146 "address-family l2vpn evpn",
7147 "Enter Address Family command mode\n"
7148 "Address Family\n"
7149 "Address Family modifier\n")
7150 {
7151 VTY_DECLVAR_CONTEXT(bgp, bgp);
7152 vty->node = BGP_EVPN_NODE;
7153 return CMD_SUCCESS;
7154 }
7155
7156 DEFUN_NOSH (exit_address_family,
7157 exit_address_family_cmd,
7158 "exit-address-family",
7159 "Exit from Address Family configuration mode\n")
7160 {
7161 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7162 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7163 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7164 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7165 || vty->node == BGP_EVPN_NODE
7166 || vty->node == BGP_FLOWSPECV4_NODE
7167 || vty->node == BGP_FLOWSPECV6_NODE)
7168 vty->node = BGP_NODE;
7169 return CMD_SUCCESS;
7170 }
7171
7172 /* Recalculate bestpath and re-advertise a prefix */
7173 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7174 const char *ip_str, afi_t afi, safi_t safi,
7175 struct prefix_rd *prd)
7176 {
7177 int ret;
7178 struct prefix match;
7179 struct bgp_node *rn;
7180 struct bgp_node *rm;
7181 struct bgp *bgp;
7182 struct bgp_table *table;
7183 struct bgp_table *rib;
7184
7185 /* BGP structure lookup. */
7186 if (view_name) {
7187 bgp = bgp_lookup_by_name(view_name);
7188 if (bgp == NULL) {
7189 vty_out(vty, "%% Can't find BGP instance %s\n",
7190 view_name);
7191 return CMD_WARNING;
7192 }
7193 } else {
7194 bgp = bgp_get_default();
7195 if (bgp == NULL) {
7196 vty_out(vty, "%% No BGP process is configured\n");
7197 return CMD_WARNING;
7198 }
7199 }
7200
7201 /* Check IP address argument. */
7202 ret = str2prefix(ip_str, &match);
7203 if (!ret) {
7204 vty_out(vty, "%% address is malformed\n");
7205 return CMD_WARNING;
7206 }
7207
7208 match.family = afi2family(afi);
7209 rib = bgp->rib[afi][safi];
7210
7211 if (safi == SAFI_MPLS_VPN) {
7212 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7213 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7214 continue;
7215
7216 table = bgp_node_get_bgp_table_info(rn);
7217 if (table != NULL) {
7218
7219 if ((rm = bgp_node_match(table, &match))
7220 != NULL) {
7221 if (rm->p.prefixlen
7222 == match.prefixlen) {
7223 SET_FLAG(rm->flags,
7224 BGP_NODE_USER_CLEAR);
7225 bgp_process(bgp, rm, afi, safi);
7226 }
7227 bgp_unlock_node(rm);
7228 }
7229 }
7230 }
7231 } else {
7232 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7233 if (rn->p.prefixlen == match.prefixlen) {
7234 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7235 bgp_process(bgp, rn, afi, safi);
7236 }
7237 bgp_unlock_node(rn);
7238 }
7239 }
7240
7241 return CMD_SUCCESS;
7242 }
7243
7244 /* one clear bgp command to rule them all */
7245 DEFUN (clear_ip_bgp_all,
7246 clear_ip_bgp_all_cmd,
7247 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
7248 CLEAR_STR
7249 IP_STR
7250 BGP_STR
7251 BGP_INSTANCE_HELP_STR
7252 BGP_AFI_HELP_STR
7253 BGP_SAFI_WITH_LABEL_HELP_STR
7254 "Clear all peers\n"
7255 "BGP neighbor address to clear\n"
7256 "BGP IPv6 neighbor to clear\n"
7257 "BGP neighbor on interface to clear\n"
7258 "Clear peers with the AS number\n"
7259 "Clear all external peers\n"
7260 "Clear all members of peer-group\n"
7261 "BGP peer-group name\n"
7262 BGP_SOFT_STR
7263 BGP_SOFT_IN_STR
7264 BGP_SOFT_OUT_STR
7265 BGP_SOFT_IN_STR
7266 "Push out prefix-list ORF and do inbound soft reconfig\n"
7267 BGP_SOFT_OUT_STR)
7268 {
7269 char *vrf = NULL;
7270
7271 afi_t afi = AFI_IP6;
7272 safi_t safi = SAFI_UNICAST;
7273 enum clear_sort clr_sort = clear_peer;
7274 enum bgp_clear_type clr_type;
7275 char *clr_arg = NULL;
7276
7277 int idx = 0;
7278
7279 /* clear [ip] bgp */
7280 if (argv_find(argv, argc, "ip", &idx))
7281 afi = AFI_IP;
7282
7283 /* [<vrf> VIEWVRFNAME] */
7284 if (argv_find(argv, argc, "vrf", &idx)) {
7285 vrf = argv[idx + 1]->arg;
7286 idx += 2;
7287 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7288 vrf = NULL;
7289 } else if (argv_find(argv, argc, "view", &idx)) {
7290 /* [<view> VIEWVRFNAME] */
7291 vrf = argv[idx + 1]->arg;
7292 idx += 2;
7293 }
7294 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7295 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7296 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7297
7298 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7299 if (argv_find(argv, argc, "*", &idx)) {
7300 clr_sort = clear_all;
7301 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7302 clr_sort = clear_peer;
7303 clr_arg = argv[idx]->arg;
7304 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7305 clr_sort = clear_peer;
7306 clr_arg = argv[idx]->arg;
7307 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7308 clr_sort = clear_group;
7309 idx++;
7310 clr_arg = argv[idx]->arg;
7311 } else if (argv_find(argv, argc, "WORD", &idx)) {
7312 clr_sort = clear_peer;
7313 clr_arg = argv[idx]->arg;
7314 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7315 clr_sort = clear_as;
7316 clr_arg = argv[idx]->arg;
7317 } else if (argv_find(argv, argc, "external", &idx)) {
7318 clr_sort = clear_external;
7319 }
7320
7321 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7322 if (argv_find(argv, argc, "soft", &idx)) {
7323 if (argv_find(argv, argc, "in", &idx)
7324 || argv_find(argv, argc, "out", &idx))
7325 clr_type = strmatch(argv[idx]->text, "in")
7326 ? BGP_CLEAR_SOFT_IN
7327 : BGP_CLEAR_SOFT_OUT;
7328 else
7329 clr_type = BGP_CLEAR_SOFT_BOTH;
7330 } else if (argv_find(argv, argc, "in", &idx)) {
7331 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7332 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7333 : BGP_CLEAR_SOFT_IN;
7334 } else if (argv_find(argv, argc, "out", &idx)) {
7335 clr_type = BGP_CLEAR_SOFT_OUT;
7336 } else
7337 clr_type = BGP_CLEAR_SOFT_NONE;
7338
7339 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7340 }
7341
7342 DEFUN (clear_ip_bgp_prefix,
7343 clear_ip_bgp_prefix_cmd,
7344 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7345 CLEAR_STR
7346 IP_STR
7347 BGP_STR
7348 BGP_INSTANCE_HELP_STR
7349 "Clear bestpath and re-advertise\n"
7350 "IPv4 prefix\n")
7351 {
7352 char *vrf = NULL;
7353 char *prefix = NULL;
7354
7355 int idx = 0;
7356
7357 /* [<view|vrf> VIEWVRFNAME] */
7358 if (argv_find(argv, argc, "vrf", &idx)) {
7359 vrf = argv[idx + 1]->arg;
7360 idx += 2;
7361 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7362 vrf = NULL;
7363 } else if (argv_find(argv, argc, "view", &idx)) {
7364 /* [<view> VIEWVRFNAME] */
7365 vrf = argv[idx + 1]->arg;
7366 idx += 2;
7367 }
7368
7369 prefix = argv[argc - 1]->arg;
7370
7371 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7372 }
7373
7374 DEFUN (clear_bgp_ipv6_safi_prefix,
7375 clear_bgp_ipv6_safi_prefix_cmd,
7376 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7377 CLEAR_STR
7378 IP_STR
7379 BGP_STR
7380 "Address Family\n"
7381 BGP_SAFI_HELP_STR
7382 "Clear bestpath and re-advertise\n"
7383 "IPv6 prefix\n")
7384 {
7385 int idx_safi = 0;
7386 int idx_ipv6_prefix = 0;
7387 safi_t safi = SAFI_UNICAST;
7388 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7389 argv[idx_ipv6_prefix]->arg : NULL;
7390
7391 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7392 return bgp_clear_prefix(
7393 vty, NULL, prefix, AFI_IP6,
7394 safi, NULL);
7395 }
7396
7397 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7398 clear_bgp_instance_ipv6_safi_prefix_cmd,
7399 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7400 CLEAR_STR
7401 IP_STR
7402 BGP_STR
7403 BGP_INSTANCE_HELP_STR
7404 "Address Family\n"
7405 BGP_SAFI_HELP_STR
7406 "Clear bestpath and re-advertise\n"
7407 "IPv6 prefix\n")
7408 {
7409 int idx_safi = 0;
7410 int idx_vrfview = 0;
7411 int idx_ipv6_prefix = 0;
7412 safi_t safi = SAFI_UNICAST;
7413 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7414 argv[idx_ipv6_prefix]->arg : NULL;
7415 char *vrfview = NULL;
7416
7417 /* [<view|vrf> VIEWVRFNAME] */
7418 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7419 vrfview = argv[idx_vrfview + 1]->arg;
7420 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7421 vrfview = NULL;
7422 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7423 /* [<view> VIEWVRFNAME] */
7424 vrfview = argv[idx_vrfview + 1]->arg;
7425 }
7426 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7427
7428 return bgp_clear_prefix(
7429 vty, vrfview, prefix,
7430 AFI_IP6, safi, NULL);
7431 }
7432
7433 DEFUN (show_bgp_views,
7434 show_bgp_views_cmd,
7435 "show [ip] bgp views",
7436 SHOW_STR
7437 IP_STR
7438 BGP_STR
7439 "Show the defined BGP views\n")
7440 {
7441 struct list *inst = bm->bgp;
7442 struct listnode *node;
7443 struct bgp *bgp;
7444
7445 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7446 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7447 return CMD_WARNING;
7448 }
7449
7450 vty_out(vty, "Defined BGP views:\n");
7451 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7452 /* Skip VRFs. */
7453 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7454 continue;
7455 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7456 bgp->as);
7457 }
7458
7459 return CMD_SUCCESS;
7460 }
7461
7462 DEFUN (show_bgp_vrfs,
7463 show_bgp_vrfs_cmd,
7464 "show [ip] bgp vrfs [json]",
7465 SHOW_STR
7466 IP_STR
7467 BGP_STR
7468 "Show BGP VRFs\n"
7469 JSON_STR)
7470 {
7471 char buf[ETHER_ADDR_STRLEN];
7472 struct list *inst = bm->bgp;
7473 struct listnode *node;
7474 struct bgp *bgp;
7475 bool uj = use_json(argc, argv);
7476 json_object *json = NULL;
7477 json_object *json_vrfs = NULL;
7478 int count = 0;
7479
7480 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7481 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7482 return CMD_WARNING;
7483 }
7484
7485 if (uj) {
7486 json = json_object_new_object();
7487 json_vrfs = json_object_new_object();
7488 }
7489
7490 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7491 const char *name, *type;
7492 struct peer *peer;
7493 struct listnode *node2, *nnode2;
7494 int peers_cfg, peers_estb;
7495 json_object *json_vrf = NULL;
7496
7497 /* Skip Views. */
7498 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7499 continue;
7500
7501 count++;
7502 if (!uj && count == 1)
7503 vty_out(vty,
7504 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7505 "Type", "Id", "routerId", "#PeersVfg",
7506 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7507
7508 peers_cfg = peers_estb = 0;
7509 if (uj)
7510 json_vrf = json_object_new_object();
7511
7512
7513 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7514 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7515 continue;
7516 peers_cfg++;
7517 if (peer->status == Established)
7518 peers_estb++;
7519 }
7520
7521 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7522 name = VRF_DEFAULT_NAME;
7523 type = "DFLT";
7524 } else {
7525 name = bgp->name;
7526 type = "VRF";
7527 }
7528
7529
7530 if (uj) {
7531 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7532 ? -1
7533 : (int64_t)bgp->vrf_id;
7534 json_object_string_add(json_vrf, "type", type);
7535 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7536 json_object_string_add(json_vrf, "routerId",
7537 inet_ntoa(bgp->router_id));
7538 json_object_int_add(json_vrf, "numConfiguredPeers",
7539 peers_cfg);
7540 json_object_int_add(json_vrf, "numEstablishedPeers",
7541 peers_estb);
7542
7543 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7544 json_object_string_add(
7545 json_vrf, "rmac",
7546 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7547 json_object_object_add(json_vrfs, name, json_vrf);
7548 } else
7549 vty_out(vty,
7550 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7551 type,
7552 bgp->vrf_id == VRF_UNKNOWN ? -1
7553 : (int)bgp->vrf_id,
7554 inet_ntoa(bgp->router_id), peers_cfg,
7555 peers_estb, name, bgp->l3vni,
7556 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7557 }
7558
7559 if (uj) {
7560 json_object_object_add(json, "vrfs", json_vrfs);
7561
7562 json_object_int_add(json, "totalVrfs", count);
7563
7564 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7565 json, JSON_C_TO_STRING_PRETTY));
7566 json_object_free(json);
7567 } else {
7568 if (count)
7569 vty_out(vty,
7570 "\nTotal number of VRFs (including default): %d\n",
7571 count);
7572 }
7573
7574 return CMD_SUCCESS;
7575 }
7576
7577
7578 static void show_tip_entry(struct hash_backet *backet, void *args)
7579 {
7580 struct vty *vty = (struct vty *)args;
7581 struct tip_addr *tip = (struct tip_addr *)backet->data;
7582
7583 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7584 tip->refcnt);
7585 }
7586
7587 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7588 {
7589 vty_out(vty, "self nexthop database:\n");
7590 bgp_nexthop_show_address_hash(vty, bgp);
7591
7592 vty_out(vty, "Tunnel-ip database:\n");
7593 hash_iterate(bgp->tip_hash,
7594 (void (*)(struct hash_backet *, void *))show_tip_entry,
7595 vty);
7596 }
7597
7598 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7599 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7600 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7601 "martian next-hops\n"
7602 "martian next-hop database\n")
7603 {
7604 struct bgp *bgp = NULL;
7605 int idx = 0;
7606 char *name = NULL;
7607
7608 /* [<vrf> VIEWVRFNAME] */
7609 if (argv_find(argv, argc, "vrf", &idx)) {
7610 name = argv[idx + 1]->arg;
7611 if (name && strmatch(name, VRF_DEFAULT_NAME))
7612 name = NULL;
7613 } else if (argv_find(argv, argc, "view", &idx))
7614 /* [<view> VIEWVRFNAME] */
7615 name = argv[idx + 1]->arg;
7616 if (name)
7617 bgp = bgp_lookup_by_name(name);
7618 else
7619 bgp = bgp_get_default();
7620
7621 if (!bgp) {
7622 vty_out(vty, "%% No BGP process is configured\n");
7623 return CMD_WARNING;
7624 }
7625 bgp_show_martian_nexthops(vty, bgp);
7626
7627 return CMD_SUCCESS;
7628 }
7629
7630 DEFUN (show_bgp_memory,
7631 show_bgp_memory_cmd,
7632 "show [ip] bgp memory",
7633 SHOW_STR
7634 IP_STR
7635 BGP_STR
7636 "Global BGP memory statistics\n")
7637 {
7638 char memstrbuf[MTYPE_MEMSTR_LEN];
7639 unsigned long count;
7640
7641 /* RIB related usage stats */
7642 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7643 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7644 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7645 count * sizeof(struct bgp_node)));
7646
7647 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7648 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7649 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7650 count * sizeof(struct bgp_path_info)));
7651 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7652 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7653 count,
7654 mtype_memstr(
7655 memstrbuf, sizeof(memstrbuf),
7656 count * sizeof(struct bgp_path_info_extra)));
7657
7658 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7659 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7660 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7661 count * sizeof(struct bgp_static)));
7662
7663 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7664 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7665 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7666 count * sizeof(struct bpacket)));
7667
7668 /* Adj-In/Out */
7669 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7670 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7671 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7672 count * sizeof(struct bgp_adj_in)));
7673 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7674 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7675 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7676 count * sizeof(struct bgp_adj_out)));
7677
7678 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7679 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7680 count,
7681 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7682 count * sizeof(struct bgp_nexthop_cache)));
7683
7684 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7685 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7686 count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct bgp_damp_info)));
7689
7690 /* Attributes */
7691 count = attr_count();
7692 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7693 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7694 count * sizeof(struct attr)));
7695
7696 if ((count = attr_unknown_count()))
7697 vty_out(vty, "%ld unknown attributes\n", count);
7698
7699 /* AS_PATH attributes */
7700 count = aspath_count();
7701 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7702 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7703 count * sizeof(struct aspath)));
7704
7705 count = mtype_stats_alloc(MTYPE_AS_SEG);
7706 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7707 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7708 count * sizeof(struct assegment)));
7709
7710 /* Other attributes */
7711 if ((count = community_count()))
7712 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7713 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7714 count * sizeof(struct community)));
7715 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7716 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7717 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7718 count * sizeof(struct ecommunity)));
7719 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7720 vty_out(vty,
7721 "%ld BGP large-community entries, using %s of memory\n",
7722 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7723 count * sizeof(struct lcommunity)));
7724
7725 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7726 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7727 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7728 count * sizeof(struct cluster_list)));
7729
7730 /* Peer related usage */
7731 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7732 vty_out(vty, "%ld peers, using %s of memory\n", count,
7733 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7734 count * sizeof(struct peer)));
7735
7736 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7737 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7738 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7739 count * sizeof(struct peer_group)));
7740
7741 /* Other */
7742 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7743 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7744 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7745 count * sizeof(struct hash)));
7746 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7747 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7748 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7749 count * sizeof(struct hash_backet)));
7750 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7751 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7752 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7753 count * sizeof(regex_t)));
7754 return CMD_SUCCESS;
7755 }
7756
7757 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7758 {
7759 json_object *bestpath = json_object_new_object();
7760
7761 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7762 json_object_string_add(bestpath, "asPath", "ignore");
7763
7764 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7765 json_object_string_add(bestpath, "asPath", "confed");
7766
7767 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7768 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7769 json_object_string_add(bestpath, "multiPathRelax",
7770 "as-set");
7771 else
7772 json_object_string_add(bestpath, "multiPathRelax",
7773 "true");
7774 } else
7775 json_object_string_add(bestpath, "multiPathRelax", "false");
7776
7777 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7778 json_object_string_add(bestpath, "compareRouterId", "true");
7779 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7780 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7781 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7782 json_object_string_add(bestpath, "med", "confed");
7783 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7784 json_object_string_add(bestpath, "med",
7785 "missing-as-worst");
7786 else
7787 json_object_string_add(bestpath, "med", "true");
7788 }
7789
7790 json_object_object_add(json, "bestPath", bestpath);
7791 }
7792
7793 /* Show BGP peer's summary information. */
7794 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7795 bool use_json, json_object *json)
7796 {
7797 struct peer *peer;
7798 struct listnode *node, *nnode;
7799 unsigned int count = 0, dn_count = 0;
7800 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7801 char neighbor_buf[VTY_BUFSIZ];
7802 int neighbor_col_default_width = 16;
7803 int len;
7804 int max_neighbor_width = 0;
7805 int pfx_rcd_safi;
7806 json_object *json_peer = NULL;
7807 json_object *json_peers = NULL;
7808 struct peer_af *paf;
7809
7810 /* labeled-unicast routes are installed in the unicast table so in order
7811 * to
7812 * display the correct PfxRcd value we must look at SAFI_UNICAST
7813 */
7814 if (safi == SAFI_LABELED_UNICAST)
7815 pfx_rcd_safi = SAFI_UNICAST;
7816 else
7817 pfx_rcd_safi = safi;
7818
7819 if (use_json) {
7820 if (json == NULL)
7821 json = json_object_new_object();
7822
7823 json_peers = json_object_new_object();
7824 } else {
7825 /* Loop over all neighbors that will be displayed to determine
7826 * how many
7827 * characters are needed for the Neighbor column
7828 */
7829 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7830 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7831 continue;
7832
7833 if (peer->afc[afi][safi]) {
7834 memset(dn_flag, '\0', sizeof(dn_flag));
7835 if (peer_dynamic_neighbor(peer))
7836 dn_flag[0] = '*';
7837
7838 if (peer->hostname
7839 && bgp_flag_check(bgp,
7840 BGP_FLAG_SHOW_HOSTNAME))
7841 sprintf(neighbor_buf, "%s%s(%s) ",
7842 dn_flag, peer->hostname,
7843 peer->host);
7844 else
7845 sprintf(neighbor_buf, "%s%s ", dn_flag,
7846 peer->host);
7847
7848 len = strlen(neighbor_buf);
7849
7850 if (len > max_neighbor_width)
7851 max_neighbor_width = len;
7852 }
7853 }
7854
7855 /* Originally we displayed the Neighbor column as 16
7856 * characters wide so make that the default
7857 */
7858 if (max_neighbor_width < neighbor_col_default_width)
7859 max_neighbor_width = neighbor_col_default_width;
7860 }
7861
7862 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7863 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7864 continue;
7865
7866 if (!peer->afc[afi][safi])
7867 continue;
7868
7869 if (!count) {
7870 unsigned long ents;
7871 char memstrbuf[MTYPE_MEMSTR_LEN];
7872 int64_t vrf_id_ui;
7873
7874 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7875 ? -1
7876 : (int64_t)bgp->vrf_id;
7877
7878 /* Usage summary and header */
7879 if (use_json) {
7880 json_object_string_add(
7881 json, "routerId",
7882 inet_ntoa(bgp->router_id));
7883 json_object_int_add(json, "as", bgp->as);
7884 json_object_int_add(json, "vrfId", vrf_id_ui);
7885 json_object_string_add(
7886 json, "vrfName",
7887 (bgp->inst_type
7888 == BGP_INSTANCE_TYPE_DEFAULT)
7889 ? VRF_DEFAULT_NAME
7890 : bgp->name);
7891 } else {
7892 vty_out(vty,
7893 "BGP router identifier %s, local AS number %u vrf-id %d",
7894 inet_ntoa(bgp->router_id), bgp->as,
7895 bgp->vrf_id == VRF_UNKNOWN
7896 ? -1
7897 : (int)bgp->vrf_id);
7898 vty_out(vty, "\n");
7899 }
7900
7901 if (bgp_update_delay_configured(bgp)) {
7902 if (use_json) {
7903 json_object_int_add(
7904 json, "updateDelayLimit",
7905 bgp->v_update_delay);
7906
7907 if (bgp->v_update_delay
7908 != bgp->v_establish_wait)
7909 json_object_int_add(
7910 json,
7911 "updateDelayEstablishWait",
7912 bgp->v_establish_wait);
7913
7914 if (bgp_update_delay_active(bgp)) {
7915 json_object_string_add(
7916 json,
7917 "updateDelayFirstNeighbor",
7918 bgp->update_delay_begin_time);
7919 json_object_boolean_true_add(
7920 json,
7921 "updateDelayInProgress");
7922 } else {
7923 if (bgp->update_delay_over) {
7924 json_object_string_add(
7925 json,
7926 "updateDelayFirstNeighbor",
7927 bgp->update_delay_begin_time);
7928 json_object_string_add(
7929 json,
7930 "updateDelayBestpathResumed",
7931 bgp->update_delay_end_time);
7932 json_object_string_add(
7933 json,
7934 "updateDelayZebraUpdateResume",
7935 bgp->update_delay_zebra_resume_time);
7936 json_object_string_add(
7937 json,
7938 "updateDelayPeerUpdateResume",
7939 bgp->update_delay_peers_resume_time);
7940 }
7941 }
7942 } else {
7943 vty_out(vty,
7944 "Read-only mode update-delay limit: %d seconds\n",
7945 bgp->v_update_delay);
7946 if (bgp->v_update_delay
7947 != bgp->v_establish_wait)
7948 vty_out(vty,
7949 " Establish wait: %d seconds\n",
7950 bgp->v_establish_wait);
7951
7952 if (bgp_update_delay_active(bgp)) {
7953 vty_out(vty,
7954 " First neighbor established: %s\n",
7955 bgp->update_delay_begin_time);
7956 vty_out(vty,
7957 " Delay in progress\n");
7958 } else {
7959 if (bgp->update_delay_over) {
7960 vty_out(vty,
7961 " First neighbor established: %s\n",
7962 bgp->update_delay_begin_time);
7963 vty_out(vty,
7964 " Best-paths resumed: %s\n",
7965 bgp->update_delay_end_time);
7966 vty_out(vty,
7967 " zebra update resumed: %s\n",
7968 bgp->update_delay_zebra_resume_time);
7969 vty_out(vty,
7970 " peers update resumed: %s\n",
7971 bgp->update_delay_peers_resume_time);
7972 }
7973 }
7974 }
7975 }
7976
7977 if (use_json) {
7978 if (bgp_maxmed_onstartup_configured(bgp)
7979 && bgp->maxmed_active)
7980 json_object_boolean_true_add(
7981 json, "maxMedOnStartup");
7982 if (bgp->v_maxmed_admin)
7983 json_object_boolean_true_add(
7984 json, "maxMedAdministrative");
7985
7986 json_object_int_add(
7987 json, "tableVersion",
7988 bgp_table_version(bgp->rib[afi][safi]));
7989
7990 ents = bgp_table_count(bgp->rib[afi][safi]);
7991 json_object_int_add(json, "ribCount", ents);
7992 json_object_int_add(
7993 json, "ribMemory",
7994 ents * sizeof(struct bgp_node));
7995
7996 ents = listcount(bgp->peer);
7997 json_object_int_add(json, "peerCount", ents);
7998 json_object_int_add(json, "peerMemory",
7999 ents * sizeof(struct peer));
8000
8001 if ((ents = listcount(bgp->group))) {
8002 json_object_int_add(
8003 json, "peerGroupCount", ents);
8004 json_object_int_add(
8005 json, "peerGroupMemory",
8006 ents * sizeof(struct
8007 peer_group));
8008 }
8009
8010 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8011 BGP_CONFIG_DAMPENING))
8012 json_object_boolean_true_add(
8013 json, "dampeningEnabled");
8014 } else {
8015 if (bgp_maxmed_onstartup_configured(bgp)
8016 && bgp->maxmed_active)
8017 vty_out(vty,
8018 "Max-med on-startup active\n");
8019 if (bgp->v_maxmed_admin)
8020 vty_out(vty,
8021 "Max-med administrative active\n");
8022
8023 vty_out(vty, "BGP table version %" PRIu64 "\n",
8024 bgp_table_version(bgp->rib[afi][safi]));
8025
8026 ents = bgp_table_count(bgp->rib[afi][safi]);
8027 vty_out(vty,
8028 "RIB entries %ld, using %s of memory\n",
8029 ents,
8030 mtype_memstr(memstrbuf,
8031 sizeof(memstrbuf),
8032 ents * sizeof(struct
8033 bgp_node)));
8034
8035 /* Peer related usage */
8036 ents = listcount(bgp->peer);
8037 vty_out(vty, "Peers %ld, using %s of memory\n",
8038 ents,
8039 mtype_memstr(
8040 memstrbuf, sizeof(memstrbuf),
8041 ents * sizeof(struct peer)));
8042
8043 if ((ents = listcount(bgp->group)))
8044 vty_out(vty,
8045 "Peer groups %ld, using %s of memory\n",
8046 ents,
8047 mtype_memstr(
8048 memstrbuf,
8049 sizeof(memstrbuf),
8050 ents * sizeof(struct
8051 peer_group)));
8052
8053 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8054 BGP_CONFIG_DAMPENING))
8055 vty_out(vty, "Dampening enabled.\n");
8056 vty_out(vty, "\n");
8057
8058 /* Subtract 8 here because 'Neighbor' is
8059 * 8 characters */
8060 vty_out(vty, "Neighbor");
8061 vty_out(vty, "%*s", max_neighbor_width - 8,
8062 " ");
8063 vty_out(vty,
8064 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8065 }
8066 }
8067
8068 count++;
8069
8070 if (use_json) {
8071 json_peer = json_object_new_object();
8072
8073 if (peer_dynamic_neighbor(peer)) {
8074 dn_count++;
8075 json_object_boolean_true_add(json_peer,
8076 "dynamicPeer");
8077 }
8078
8079 if (peer->hostname)
8080 json_object_string_add(json_peer, "hostname",
8081 peer->hostname);
8082
8083 if (peer->domainname)
8084 json_object_string_add(json_peer, "domainname",
8085 peer->domainname);
8086
8087 json_object_int_add(json_peer, "remoteAs", peer->as);
8088 json_object_int_add(json_peer, "version", 4);
8089 json_object_int_add(json_peer, "msgRcvd",
8090 PEER_TOTAL_RX(peer));
8091 json_object_int_add(json_peer, "msgSent",
8092 PEER_TOTAL_TX(peer));
8093
8094 json_object_int_add(json_peer, "tableVersion",
8095 peer->version[afi][safi]);
8096 json_object_int_add(json_peer, "outq",
8097 peer->obuf->count);
8098 json_object_int_add(json_peer, "inq", 0);
8099 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8100 use_json, json_peer);
8101
8102 /*
8103 * Adding "pfxRcd" field to match with the corresponding
8104 * CLI. "prefixReceivedCount" will be deprecated in
8105 * future.
8106 */
8107 json_object_int_add(json_peer, "prefixReceivedCount",
8108 peer->pcount[afi][pfx_rcd_safi]);
8109 json_object_int_add(json_peer, "pfxRcd",
8110 peer->pcount[afi][pfx_rcd_safi]);
8111
8112 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8113 if (paf && PAF_SUBGRP(paf))
8114 json_object_int_add(json_peer,
8115 "pfxSnt",
8116 (PAF_SUBGRP(paf))->scount);
8117
8118 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8119 json_object_string_add(json_peer, "state",
8120 "Idle (Admin)");
8121 else if (peer->afc_recv[afi][safi])
8122 json_object_string_add(
8123 json_peer, "state",
8124 lookup_msg(bgp_status_msg, peer->status,
8125 NULL));
8126 else if (CHECK_FLAG(peer->sflags,
8127 PEER_STATUS_PREFIX_OVERFLOW))
8128 json_object_string_add(json_peer, "state",
8129 "Idle (PfxCt)");
8130 else
8131 json_object_string_add(
8132 json_peer, "state",
8133 lookup_msg(bgp_status_msg, peer->status,
8134 NULL));
8135
8136 if (peer->conf_if)
8137 json_object_string_add(json_peer, "idType",
8138 "interface");
8139 else if (peer->su.sa.sa_family == AF_INET)
8140 json_object_string_add(json_peer, "idType",
8141 "ipv4");
8142 else if (peer->su.sa.sa_family == AF_INET6)
8143 json_object_string_add(json_peer, "idType",
8144 "ipv6");
8145
8146 json_object_object_add(json_peers, peer->host,
8147 json_peer);
8148 } else {
8149 memset(dn_flag, '\0', sizeof(dn_flag));
8150 if (peer_dynamic_neighbor(peer)) {
8151 dn_count++;
8152 dn_flag[0] = '*';
8153 }
8154
8155 if (peer->hostname
8156 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8157 len = vty_out(vty, "%s%s(%s)", dn_flag,
8158 peer->hostname, peer->host);
8159 else
8160 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8161
8162 /* pad the neighbor column with spaces */
8163 if (len < max_neighbor_width)
8164 vty_out(vty, "%*s", max_neighbor_width - len,
8165 " ");
8166
8167 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8168 peer->as, PEER_TOTAL_RX(peer),
8169 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8170 0, peer->obuf->count,
8171 peer_uptime(peer->uptime, timebuf,
8172 BGP_UPTIME_LEN, 0, NULL));
8173
8174 if (peer->status == Established)
8175 if (peer->afc_recv[afi][safi])
8176 vty_out(vty, " %12ld",
8177 peer->pcount[afi]
8178 [pfx_rcd_safi]);
8179 else
8180 vty_out(vty, " NoNeg");
8181 else {
8182 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8183 vty_out(vty, " Idle (Admin)");
8184 else if (CHECK_FLAG(
8185 peer->sflags,
8186 PEER_STATUS_PREFIX_OVERFLOW))
8187 vty_out(vty, " Idle (PfxCt)");
8188 else
8189 vty_out(vty, " %12s",
8190 lookup_msg(bgp_status_msg,
8191 peer->status, NULL));
8192 }
8193 vty_out(vty, "\n");
8194 }
8195 }
8196
8197 if (use_json) {
8198 json_object_object_add(json, "peers", json_peers);
8199
8200 json_object_int_add(json, "totalPeers", count);
8201 json_object_int_add(json, "dynamicPeers", dn_count);
8202
8203 bgp_show_bestpath_json(bgp, json);
8204
8205 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8206 json, JSON_C_TO_STRING_PRETTY));
8207 json_object_free(json);
8208 } else {
8209 if (count)
8210 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8211 else {
8212 vty_out(vty, "No %s neighbor is configured\n",
8213 afi_safi_print(afi, safi));
8214 }
8215
8216 if (dn_count) {
8217 vty_out(vty, "* - dynamic neighbor\n");
8218 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8219 dn_count, bgp->dynamic_neighbors_limit);
8220 }
8221 }
8222
8223 return CMD_SUCCESS;
8224 }
8225
8226 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8227 int safi, bool use_json,
8228 json_object *json)
8229 {
8230 int is_first = 1;
8231 int afi_wildcard = (afi == AFI_MAX);
8232 int safi_wildcard = (safi == SAFI_MAX);
8233 int is_wildcard = (afi_wildcard || safi_wildcard);
8234 bool nbr_output = false;
8235
8236 if (use_json && is_wildcard)
8237 vty_out(vty, "{\n");
8238 if (afi_wildcard)
8239 afi = 1; /* AFI_IP */
8240 while (afi < AFI_MAX) {
8241 if (safi_wildcard)
8242 safi = 1; /* SAFI_UNICAST */
8243 while (safi < SAFI_MAX) {
8244 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8245 nbr_output = true;
8246 if (is_wildcard) {
8247 /*
8248 * So limit output to those afi/safi
8249 * pairs that
8250 * actualy have something interesting in
8251 * them
8252 */
8253 if (use_json) {
8254 json = json_object_new_object();
8255
8256 if (!is_first)
8257 vty_out(vty, ",\n");
8258 else
8259 is_first = 0;
8260
8261 vty_out(vty, "\"%s\":",
8262 afi_safi_json(afi,
8263 safi));
8264 } else {
8265 vty_out(vty, "\n%s Summary:\n",
8266 afi_safi_print(afi,
8267 safi));
8268 }
8269 }
8270 bgp_show_summary(vty, bgp, afi, safi, use_json,
8271 json);
8272 }
8273 safi++;
8274 if (!safi_wildcard)
8275 safi = SAFI_MAX;
8276 }
8277 afi++;
8278 if (!afi_wildcard)
8279 afi = AFI_MAX;
8280 }
8281
8282 if (use_json && is_wildcard)
8283 vty_out(vty, "}\n");
8284 else if (!nbr_output) {
8285 if (use_json)
8286 vty_out(vty, "{}\n");
8287 else
8288 vty_out(vty, "%% No BGP neighbors found\n");
8289 }
8290 }
8291
8292 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8293 safi_t safi, bool use_json)
8294 {
8295 struct listnode *node, *nnode;
8296 struct bgp *bgp;
8297 json_object *json = NULL;
8298 int is_first = 1;
8299 bool nbr_output = false;
8300
8301 if (use_json)
8302 vty_out(vty, "{\n");
8303
8304 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8305 nbr_output = true;
8306 if (use_json) {
8307 json = json_object_new_object();
8308
8309 if (!is_first)
8310 vty_out(vty, ",\n");
8311 else
8312 is_first = 0;
8313
8314 vty_out(vty, "\"%s\":",
8315 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8316 ? VRF_DEFAULT_NAME
8317 : bgp->name);
8318 } else {
8319 vty_out(vty, "\nInstance %s:\n",
8320 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8321 ? VRF_DEFAULT_NAME
8322 : bgp->name);
8323 }
8324 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8325 }
8326
8327 if (use_json)
8328 vty_out(vty, "}\n");
8329 else if (!nbr_output)
8330 vty_out(vty, "%% BGP instance not found\n");
8331 }
8332
8333 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8334 safi_t safi, bool use_json)
8335 {
8336 struct bgp *bgp;
8337
8338 if (name) {
8339 if (strmatch(name, "all")) {
8340 bgp_show_all_instances_summary_vty(vty, afi, safi,
8341 use_json);
8342 return CMD_SUCCESS;
8343 } else {
8344 bgp = bgp_lookup_by_name(name);
8345
8346 if (!bgp) {
8347 if (use_json)
8348 vty_out(vty, "{}\n");
8349 else
8350 vty_out(vty,
8351 "%% BGP instance not found\n");
8352 return CMD_WARNING;
8353 }
8354
8355 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8356 NULL);
8357 return CMD_SUCCESS;
8358 }
8359 }
8360
8361 bgp = bgp_get_default();
8362
8363 if (bgp)
8364 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8365 else {
8366 if (use_json)
8367 vty_out(vty, "{}\n");
8368 else
8369 vty_out(vty, "%% BGP instance not found\n");
8370 return CMD_WARNING;
8371 }
8372
8373 return CMD_SUCCESS;
8374 }
8375
8376 /* `show [ip] bgp summary' commands. */
8377 DEFUN (show_ip_bgp_summary,
8378 show_ip_bgp_summary_cmd,
8379 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8380 SHOW_STR
8381 IP_STR
8382 BGP_STR
8383 BGP_INSTANCE_HELP_STR
8384 BGP_AFI_HELP_STR
8385 BGP_SAFI_WITH_LABEL_HELP_STR
8386 "Summary of BGP neighbor status\n"
8387 JSON_STR)
8388 {
8389 char *vrf = NULL;
8390 afi_t afi = AFI_MAX;
8391 safi_t safi = SAFI_MAX;
8392
8393 int idx = 0;
8394
8395 /* show [ip] bgp */
8396 if (argv_find(argv, argc, "ip", &idx))
8397 afi = AFI_IP;
8398 /* [<vrf> VIEWVRFNAME] */
8399 if (argv_find(argv, argc, "vrf", &idx)) {
8400 vrf = argv[idx + 1]->arg;
8401 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8402 vrf = NULL;
8403 } else if (argv_find(argv, argc, "view", &idx))
8404 /* [<view> VIEWVRFNAME] */
8405 vrf = argv[idx + 1]->arg;
8406 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8407 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8408 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8409 }
8410
8411 bool uj = use_json(argc, argv);
8412
8413 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8414 }
8415
8416 const char *afi_safi_print(afi_t afi, safi_t safi)
8417 {
8418 if (afi == AFI_IP && safi == SAFI_UNICAST)
8419 return "IPv4 Unicast";
8420 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8421 return "IPv4 Multicast";
8422 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8423 return "IPv4 Labeled Unicast";
8424 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8425 return "IPv4 VPN";
8426 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8427 return "IPv4 Encap";
8428 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8429 return "IPv4 Flowspec";
8430 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8431 return "IPv6 Unicast";
8432 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8433 return "IPv6 Multicast";
8434 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8435 return "IPv6 Labeled Unicast";
8436 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8437 return "IPv6 VPN";
8438 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8439 return "IPv6 Encap";
8440 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8441 return "IPv6 Flowspec";
8442 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8443 return "L2VPN EVPN";
8444 else
8445 return "Unknown";
8446 }
8447
8448 /*
8449 * Please note that we have intentionally camelCased
8450 * the return strings here. So if you want
8451 * to use this function, please ensure you
8452 * are doing this within json output
8453 */
8454 const char *afi_safi_json(afi_t afi, safi_t safi)
8455 {
8456 if (afi == AFI_IP && safi == SAFI_UNICAST)
8457 return "ipv4Unicast";
8458 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8459 return "ipv4Multicast";
8460 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8461 return "ipv4LabeledUnicast";
8462 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8463 return "ipv4Vpn";
8464 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8465 return "ipv4Encap";
8466 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8467 return "ipv4Flowspec";
8468 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8469 return "ipv6Unicast";
8470 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8471 return "ipv6Multicast";
8472 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8473 return "ipv6LabeledUnicast";
8474 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8475 return "ipv6Vpn";
8476 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8477 return "ipv6Encap";
8478 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8479 return "ipv6Flowspec";
8480 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8481 return "l2VpnEvpn";
8482 else
8483 return "Unknown";
8484 }
8485
8486 /* Show BGP peer's information. */
8487 enum show_type { show_all, show_peer };
8488
8489 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8490 afi_t afi, safi_t safi,
8491 uint16_t adv_smcap, uint16_t adv_rmcap,
8492 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8493 bool use_json, json_object *json_pref)
8494 {
8495 /* Send-Mode */
8496 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8497 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8498 if (use_json) {
8499 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8500 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8501 json_object_string_add(json_pref, "sendMode",
8502 "advertisedAndReceived");
8503 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8504 json_object_string_add(json_pref, "sendMode",
8505 "advertised");
8506 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8507 json_object_string_add(json_pref, "sendMode",
8508 "received");
8509 } else {
8510 vty_out(vty, " Send-mode: ");
8511 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8512 vty_out(vty, "advertised");
8513 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8514 vty_out(vty, "%sreceived",
8515 CHECK_FLAG(p->af_cap[afi][safi],
8516 adv_smcap)
8517 ? ", "
8518 : "");
8519 vty_out(vty, "\n");
8520 }
8521 }
8522
8523 /* Receive-Mode */
8524 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8525 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8526 if (use_json) {
8527 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8528 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8529 json_object_string_add(json_pref, "recvMode",
8530 "advertisedAndReceived");
8531 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8532 json_object_string_add(json_pref, "recvMode",
8533 "advertised");
8534 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8535 json_object_string_add(json_pref, "recvMode",
8536 "received");
8537 } else {
8538 vty_out(vty, " Receive-mode: ");
8539 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8540 vty_out(vty, "advertised");
8541 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8542 vty_out(vty, "%sreceived",
8543 CHECK_FLAG(p->af_cap[afi][safi],
8544 adv_rmcap)
8545 ? ", "
8546 : "");
8547 vty_out(vty, "\n");
8548 }
8549 }
8550 }
8551
8552 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8553 safi_t safi, bool use_json,
8554 json_object *json_neigh)
8555 {
8556 struct bgp_filter *filter;
8557 struct peer_af *paf;
8558 char orf_pfx_name[BUFSIZ];
8559 int orf_pfx_count;
8560 json_object *json_af = NULL;
8561 json_object *json_prefA = NULL;
8562 json_object *json_prefB = NULL;
8563 json_object *json_addr = NULL;
8564
8565 if (use_json) {
8566 json_addr = json_object_new_object();
8567 json_af = json_object_new_object();
8568 filter = &p->filter[afi][safi];
8569
8570 if (peer_group_active(p))
8571 json_object_string_add(json_addr, "peerGroupMember",
8572 p->group->name);
8573
8574 paf = peer_af_find(p, afi, safi);
8575 if (paf && PAF_SUBGRP(paf)) {
8576 json_object_int_add(json_addr, "updateGroupId",
8577 PAF_UPDGRP(paf)->id);
8578 json_object_int_add(json_addr, "subGroupId",
8579 PAF_SUBGRP(paf)->id);
8580 json_object_int_add(json_addr, "packetQueueLength",
8581 bpacket_queue_virtual_length(paf));
8582 }
8583
8584 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8585 || CHECK_FLAG(p->af_cap[afi][safi],
8586 PEER_CAP_ORF_PREFIX_SM_RCV)
8587 || CHECK_FLAG(p->af_cap[afi][safi],
8588 PEER_CAP_ORF_PREFIX_RM_ADV)
8589 || CHECK_FLAG(p->af_cap[afi][safi],
8590 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8591 json_object_int_add(json_af, "orfType",
8592 ORF_TYPE_PREFIX);
8593 json_prefA = json_object_new_object();
8594 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8595 PEER_CAP_ORF_PREFIX_SM_ADV,
8596 PEER_CAP_ORF_PREFIX_RM_ADV,
8597 PEER_CAP_ORF_PREFIX_SM_RCV,
8598 PEER_CAP_ORF_PREFIX_RM_RCV,
8599 use_json, json_prefA);
8600 json_object_object_add(json_af, "orfPrefixList",
8601 json_prefA);
8602 }
8603
8604 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8605 || CHECK_FLAG(p->af_cap[afi][safi],
8606 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8607 || CHECK_FLAG(p->af_cap[afi][safi],
8608 PEER_CAP_ORF_PREFIX_RM_ADV)
8609 || CHECK_FLAG(p->af_cap[afi][safi],
8610 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8611 json_object_int_add(json_af, "orfOldType",
8612 ORF_TYPE_PREFIX_OLD);
8613 json_prefB = json_object_new_object();
8614 bgp_show_peer_afi_orf_cap(
8615 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8616 PEER_CAP_ORF_PREFIX_RM_ADV,
8617 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8618 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8619 json_prefB);
8620 json_object_object_add(json_af, "orfOldPrefixList",
8621 json_prefB);
8622 }
8623
8624 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_SM_RCV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8629 || CHECK_FLAG(p->af_cap[afi][safi],
8630 PEER_CAP_ORF_PREFIX_RM_ADV)
8631 || CHECK_FLAG(p->af_cap[afi][safi],
8632 PEER_CAP_ORF_PREFIX_RM_RCV)
8633 || CHECK_FLAG(p->af_cap[afi][safi],
8634 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8635 json_object_object_add(json_addr, "afDependentCap",
8636 json_af);
8637 else
8638 json_object_free(json_af);
8639
8640 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8641 orf_pfx_count = prefix_bgp_show_prefix_list(
8642 NULL, afi, orf_pfx_name, use_json);
8643
8644 if (CHECK_FLAG(p->af_sflags[afi][safi],
8645 PEER_STATUS_ORF_PREFIX_SEND)
8646 || orf_pfx_count) {
8647 if (CHECK_FLAG(p->af_sflags[afi][safi],
8648 PEER_STATUS_ORF_PREFIX_SEND))
8649 json_object_boolean_true_add(json_neigh,
8650 "orfSent");
8651 if (orf_pfx_count)
8652 json_object_int_add(json_addr, "orfRecvCounter",
8653 orf_pfx_count);
8654 }
8655 if (CHECK_FLAG(p->af_sflags[afi][safi],
8656 PEER_STATUS_ORF_WAIT_REFRESH))
8657 json_object_string_add(
8658 json_addr, "orfFirstUpdate",
8659 "deferredUntilORFOrRouteRefreshRecvd");
8660
8661 if (CHECK_FLAG(p->af_flags[afi][safi],
8662 PEER_FLAG_REFLECTOR_CLIENT))
8663 json_object_boolean_true_add(json_addr,
8664 "routeReflectorClient");
8665 if (CHECK_FLAG(p->af_flags[afi][safi],
8666 PEER_FLAG_RSERVER_CLIENT))
8667 json_object_boolean_true_add(json_addr,
8668 "routeServerClient");
8669 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8670 json_object_boolean_true_add(json_addr,
8671 "inboundSoftConfigPermit");
8672
8673 if (CHECK_FLAG(p->af_flags[afi][safi],
8674 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8675 json_object_boolean_true_add(
8676 json_addr,
8677 "privateAsNumsAllReplacedInUpdatesToNbr");
8678 else if (CHECK_FLAG(p->af_flags[afi][safi],
8679 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8680 json_object_boolean_true_add(
8681 json_addr,
8682 "privateAsNumsReplacedInUpdatesToNbr");
8683 else if (CHECK_FLAG(p->af_flags[afi][safi],
8684 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8685 json_object_boolean_true_add(
8686 json_addr,
8687 "privateAsNumsAllRemovedInUpdatesToNbr");
8688 else if (CHECK_FLAG(p->af_flags[afi][safi],
8689 PEER_FLAG_REMOVE_PRIVATE_AS))
8690 json_object_boolean_true_add(
8691 json_addr,
8692 "privateAsNumsRemovedInUpdatesToNbr");
8693
8694 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8695 json_object_boolean_true_add(
8696 json_addr,
8697 bgp_addpath_names(p->addpath_type[afi][safi])
8698 ->type_json_name);
8699
8700 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8701 json_object_string_add(json_addr,
8702 "overrideASNsInOutboundUpdates",
8703 "ifAspathEqualRemoteAs");
8704
8705 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8706 || CHECK_FLAG(p->af_flags[afi][safi],
8707 PEER_FLAG_FORCE_NEXTHOP_SELF))
8708 json_object_boolean_true_add(json_addr,
8709 "routerAlwaysNextHop");
8710 if (CHECK_FLAG(p->af_flags[afi][safi],
8711 PEER_FLAG_AS_PATH_UNCHANGED))
8712 json_object_boolean_true_add(
8713 json_addr, "unchangedAsPathPropogatedToNbr");
8714 if (CHECK_FLAG(p->af_flags[afi][safi],
8715 PEER_FLAG_NEXTHOP_UNCHANGED))
8716 json_object_boolean_true_add(
8717 json_addr, "unchangedNextHopPropogatedToNbr");
8718 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8719 json_object_boolean_true_add(
8720 json_addr, "unchangedMedPropogatedToNbr");
8721 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8722 || CHECK_FLAG(p->af_flags[afi][safi],
8723 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8724 if (CHECK_FLAG(p->af_flags[afi][safi],
8725 PEER_FLAG_SEND_COMMUNITY)
8726 && CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_SEND_EXT_COMMUNITY))
8728 json_object_string_add(json_addr,
8729 "commAttriSentToNbr",
8730 "extendedAndStandard");
8731 else if (CHECK_FLAG(p->af_flags[afi][safi],
8732 PEER_FLAG_SEND_EXT_COMMUNITY))
8733 json_object_string_add(json_addr,
8734 "commAttriSentToNbr",
8735 "extended");
8736 else
8737 json_object_string_add(json_addr,
8738 "commAttriSentToNbr",
8739 "standard");
8740 }
8741 if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_DEFAULT_ORIGINATE)) {
8743 if (p->default_rmap[afi][safi].name)
8744 json_object_string_add(
8745 json_addr, "defaultRouteMap",
8746 p->default_rmap[afi][safi].name);
8747
8748 if (paf && PAF_SUBGRP(paf)
8749 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8750 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8751 json_object_boolean_true_add(json_addr,
8752 "defaultSent");
8753 else
8754 json_object_boolean_true_add(json_addr,
8755 "defaultNotSent");
8756 }
8757
8758 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8759 if (is_evpn_enabled())
8760 json_object_boolean_true_add(
8761 json_addr, "advertiseAllVnis");
8762 }
8763
8764 if (filter->plist[FILTER_IN].name
8765 || filter->dlist[FILTER_IN].name
8766 || filter->aslist[FILTER_IN].name
8767 || filter->map[RMAP_IN].name)
8768 json_object_boolean_true_add(json_addr,
8769 "inboundPathPolicyConfig");
8770 if (filter->plist[FILTER_OUT].name
8771 || filter->dlist[FILTER_OUT].name
8772 || filter->aslist[FILTER_OUT].name
8773 || filter->map[RMAP_OUT].name || filter->usmap.name)
8774 json_object_boolean_true_add(
8775 json_addr, "outboundPathPolicyConfig");
8776
8777 /* prefix-list */
8778 if (filter->plist[FILTER_IN].name)
8779 json_object_string_add(json_addr,
8780 "incomingUpdatePrefixFilterList",
8781 filter->plist[FILTER_IN].name);
8782 if (filter->plist[FILTER_OUT].name)
8783 json_object_string_add(json_addr,
8784 "outgoingUpdatePrefixFilterList",
8785 filter->plist[FILTER_OUT].name);
8786
8787 /* distribute-list */
8788 if (filter->dlist[FILTER_IN].name)
8789 json_object_string_add(
8790 json_addr, "incomingUpdateNetworkFilterList",
8791 filter->dlist[FILTER_IN].name);
8792 if (filter->dlist[FILTER_OUT].name)
8793 json_object_string_add(
8794 json_addr, "outgoingUpdateNetworkFilterList",
8795 filter->dlist[FILTER_OUT].name);
8796
8797 /* filter-list. */
8798 if (filter->aslist[FILTER_IN].name)
8799 json_object_string_add(json_addr,
8800 "incomingUpdateAsPathFilterList",
8801 filter->aslist[FILTER_IN].name);
8802 if (filter->aslist[FILTER_OUT].name)
8803 json_object_string_add(json_addr,
8804 "outgoingUpdateAsPathFilterList",
8805 filter->aslist[FILTER_OUT].name);
8806
8807 /* route-map. */
8808 if (filter->map[RMAP_IN].name)
8809 json_object_string_add(
8810 json_addr, "routeMapForIncomingAdvertisements",
8811 filter->map[RMAP_IN].name);
8812 if (filter->map[RMAP_OUT].name)
8813 json_object_string_add(
8814 json_addr, "routeMapForOutgoingAdvertisements",
8815 filter->map[RMAP_OUT].name);
8816
8817 /* unsuppress-map */
8818 if (filter->usmap.name)
8819 json_object_string_add(json_addr,
8820 "selectiveUnsuppressRouteMap",
8821 filter->usmap.name);
8822
8823 /* Receive prefix count */
8824 json_object_int_add(json_addr, "acceptedPrefixCounter",
8825 p->pcount[afi][safi]);
8826 if (paf && PAF_SUBGRP(paf))
8827 json_object_int_add(json_addr, "sentPrefixCounter",
8828 (PAF_SUBGRP(paf))->scount);
8829
8830 /* Maximum prefix */
8831 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8832 json_object_int_add(json_addr, "prefixAllowedMax",
8833 p->pmax[afi][safi]);
8834 if (CHECK_FLAG(p->af_flags[afi][safi],
8835 PEER_FLAG_MAX_PREFIX_WARNING))
8836 json_object_boolean_true_add(
8837 json_addr, "prefixAllowedMaxWarning");
8838 json_object_int_add(json_addr,
8839 "prefixAllowedWarningThresh",
8840 p->pmax_threshold[afi][safi]);
8841 if (p->pmax_restart[afi][safi])
8842 json_object_int_add(
8843 json_addr,
8844 "prefixAllowedRestartIntervalMsecs",
8845 p->pmax_restart[afi][safi] * 60000);
8846 }
8847 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8848 json_addr);
8849
8850 } else {
8851 filter = &p->filter[afi][safi];
8852
8853 vty_out(vty, " For address family: %s\n",
8854 afi_safi_print(afi, safi));
8855
8856 if (peer_group_active(p))
8857 vty_out(vty, " %s peer-group member\n",
8858 p->group->name);
8859
8860 paf = peer_af_find(p, afi, safi);
8861 if (paf && PAF_SUBGRP(paf)) {
8862 vty_out(vty, " Update group %" PRIu64
8863 ", subgroup %" PRIu64 "\n",
8864 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8865 vty_out(vty, " Packet Queue length %d\n",
8866 bpacket_queue_virtual_length(paf));
8867 } else {
8868 vty_out(vty, " Not part of any update group\n");
8869 }
8870 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8871 || CHECK_FLAG(p->af_cap[afi][safi],
8872 PEER_CAP_ORF_PREFIX_SM_RCV)
8873 || CHECK_FLAG(p->af_cap[afi][safi],
8874 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8875 || CHECK_FLAG(p->af_cap[afi][safi],
8876 PEER_CAP_ORF_PREFIX_RM_ADV)
8877 || CHECK_FLAG(p->af_cap[afi][safi],
8878 PEER_CAP_ORF_PREFIX_RM_RCV)
8879 || CHECK_FLAG(p->af_cap[afi][safi],
8880 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8881 vty_out(vty, " AF-dependant capabilities:\n");
8882
8883 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8884 || CHECK_FLAG(p->af_cap[afi][safi],
8885 PEER_CAP_ORF_PREFIX_SM_RCV)
8886 || CHECK_FLAG(p->af_cap[afi][safi],
8887 PEER_CAP_ORF_PREFIX_RM_ADV)
8888 || CHECK_FLAG(p->af_cap[afi][safi],
8889 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8890 vty_out(vty,
8891 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8892 ORF_TYPE_PREFIX);
8893 bgp_show_peer_afi_orf_cap(
8894 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8895 PEER_CAP_ORF_PREFIX_RM_ADV,
8896 PEER_CAP_ORF_PREFIX_SM_RCV,
8897 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8898 }
8899 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8900 || CHECK_FLAG(p->af_cap[afi][safi],
8901 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8902 || CHECK_FLAG(p->af_cap[afi][safi],
8903 PEER_CAP_ORF_PREFIX_RM_ADV)
8904 || CHECK_FLAG(p->af_cap[afi][safi],
8905 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8906 vty_out(vty,
8907 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8908 ORF_TYPE_PREFIX_OLD);
8909 bgp_show_peer_afi_orf_cap(
8910 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8911 PEER_CAP_ORF_PREFIX_RM_ADV,
8912 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8913 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8914 }
8915
8916 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8917 orf_pfx_count = prefix_bgp_show_prefix_list(
8918 NULL, afi, orf_pfx_name, use_json);
8919
8920 if (CHECK_FLAG(p->af_sflags[afi][safi],
8921 PEER_STATUS_ORF_PREFIX_SEND)
8922 || orf_pfx_count) {
8923 vty_out(vty, " Outbound Route Filter (ORF):");
8924 if (CHECK_FLAG(p->af_sflags[afi][safi],
8925 PEER_STATUS_ORF_PREFIX_SEND))
8926 vty_out(vty, " sent;");
8927 if (orf_pfx_count)
8928 vty_out(vty, " received (%d entries)",
8929 orf_pfx_count);
8930 vty_out(vty, "\n");
8931 }
8932 if (CHECK_FLAG(p->af_sflags[afi][safi],
8933 PEER_STATUS_ORF_WAIT_REFRESH))
8934 vty_out(vty,
8935 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8936
8937 if (CHECK_FLAG(p->af_flags[afi][safi],
8938 PEER_FLAG_REFLECTOR_CLIENT))
8939 vty_out(vty, " Route-Reflector Client\n");
8940 if (CHECK_FLAG(p->af_flags[afi][safi],
8941 PEER_FLAG_RSERVER_CLIENT))
8942 vty_out(vty, " Route-Server Client\n");
8943 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8944 vty_out(vty,
8945 " Inbound soft reconfiguration allowed\n");
8946
8947 if (CHECK_FLAG(p->af_flags[afi][safi],
8948 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8949 vty_out(vty,
8950 " Private AS numbers (all) replaced in updates to this neighbor\n");
8951 else if (CHECK_FLAG(p->af_flags[afi][safi],
8952 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8953 vty_out(vty,
8954 " Private AS numbers replaced in updates to this neighbor\n");
8955 else if (CHECK_FLAG(p->af_flags[afi][safi],
8956 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8957 vty_out(vty,
8958 " Private AS numbers (all) removed in updates to this neighbor\n");
8959 else if (CHECK_FLAG(p->af_flags[afi][safi],
8960 PEER_FLAG_REMOVE_PRIVATE_AS))
8961 vty_out(vty,
8962 " Private AS numbers removed in updates to this neighbor\n");
8963
8964 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8965 vty_out(vty, " %s\n",
8966 bgp_addpath_names(p->addpath_type[afi][safi])
8967 ->human_description);
8968
8969 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8970 vty_out(vty,
8971 " Override ASNs in outbound updates if aspath equals remote-as\n");
8972
8973 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8974 || CHECK_FLAG(p->af_flags[afi][safi],
8975 PEER_FLAG_FORCE_NEXTHOP_SELF))
8976 vty_out(vty, " NEXT_HOP is always this router\n");
8977 if (CHECK_FLAG(p->af_flags[afi][safi],
8978 PEER_FLAG_AS_PATH_UNCHANGED))
8979 vty_out(vty,
8980 " AS_PATH is propagated unchanged to this neighbor\n");
8981 if (CHECK_FLAG(p->af_flags[afi][safi],
8982 PEER_FLAG_NEXTHOP_UNCHANGED))
8983 vty_out(vty,
8984 " NEXT_HOP is propagated unchanged to this neighbor\n");
8985 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8986 vty_out(vty,
8987 " MED is propagated unchanged to this neighbor\n");
8988 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8989 || CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_SEND_EXT_COMMUNITY)
8991 || CHECK_FLAG(p->af_flags[afi][safi],
8992 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8993 vty_out(vty,
8994 " Community attribute sent to this neighbor");
8995 if (CHECK_FLAG(p->af_flags[afi][safi],
8996 PEER_FLAG_SEND_COMMUNITY)
8997 && CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_SEND_EXT_COMMUNITY)
8999 && CHECK_FLAG(p->af_flags[afi][safi],
9000 PEER_FLAG_SEND_LARGE_COMMUNITY))
9001 vty_out(vty, "(all)\n");
9002 else if (CHECK_FLAG(p->af_flags[afi][safi],
9003 PEER_FLAG_SEND_LARGE_COMMUNITY))
9004 vty_out(vty, "(large)\n");
9005 else if (CHECK_FLAG(p->af_flags[afi][safi],
9006 PEER_FLAG_SEND_EXT_COMMUNITY))
9007 vty_out(vty, "(extended)\n");
9008 else
9009 vty_out(vty, "(standard)\n");
9010 }
9011 if (CHECK_FLAG(p->af_flags[afi][safi],
9012 PEER_FLAG_DEFAULT_ORIGINATE)) {
9013 vty_out(vty, " Default information originate,");
9014
9015 if (p->default_rmap[afi][safi].name)
9016 vty_out(vty, " default route-map %s%s,",
9017 p->default_rmap[afi][safi].map ? "*"
9018 : "",
9019 p->default_rmap[afi][safi].name);
9020 if (paf && PAF_SUBGRP(paf)
9021 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9022 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9023 vty_out(vty, " default sent\n");
9024 else
9025 vty_out(vty, " default not sent\n");
9026 }
9027
9028 /* advertise-vni-all */
9029 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9030 if (is_evpn_enabled())
9031 vty_out(vty, " advertise-all-vni\n");
9032 }
9033
9034 if (filter->plist[FILTER_IN].name
9035 || filter->dlist[FILTER_IN].name
9036 || filter->aslist[FILTER_IN].name
9037 || filter->map[RMAP_IN].name)
9038 vty_out(vty, " Inbound path policy configured\n");
9039 if (filter->plist[FILTER_OUT].name
9040 || filter->dlist[FILTER_OUT].name
9041 || filter->aslist[FILTER_OUT].name
9042 || filter->map[RMAP_OUT].name || filter->usmap.name)
9043 vty_out(vty, " Outbound path policy configured\n");
9044
9045 /* prefix-list */
9046 if (filter->plist[FILTER_IN].name)
9047 vty_out(vty,
9048 " Incoming update prefix filter list is %s%s\n",
9049 filter->plist[FILTER_IN].plist ? "*" : "",
9050 filter->plist[FILTER_IN].name);
9051 if (filter->plist[FILTER_OUT].name)
9052 vty_out(vty,
9053 " Outgoing update prefix filter list is %s%s\n",
9054 filter->plist[FILTER_OUT].plist ? "*" : "",
9055 filter->plist[FILTER_OUT].name);
9056
9057 /* distribute-list */
9058 if (filter->dlist[FILTER_IN].name)
9059 vty_out(vty,
9060 " Incoming update network filter list is %s%s\n",
9061 filter->dlist[FILTER_IN].alist ? "*" : "",
9062 filter->dlist[FILTER_IN].name);
9063 if (filter->dlist[FILTER_OUT].name)
9064 vty_out(vty,
9065 " Outgoing update network filter list is %s%s\n",
9066 filter->dlist[FILTER_OUT].alist ? "*" : "",
9067 filter->dlist[FILTER_OUT].name);
9068
9069 /* filter-list. */
9070 if (filter->aslist[FILTER_IN].name)
9071 vty_out(vty,
9072 " Incoming update AS path filter list is %s%s\n",
9073 filter->aslist[FILTER_IN].aslist ? "*" : "",
9074 filter->aslist[FILTER_IN].name);
9075 if (filter->aslist[FILTER_OUT].name)
9076 vty_out(vty,
9077 " Outgoing update AS path filter list is %s%s\n",
9078 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9079 filter->aslist[FILTER_OUT].name);
9080
9081 /* route-map. */
9082 if (filter->map[RMAP_IN].name)
9083 vty_out(vty,
9084 " Route map for incoming advertisements is %s%s\n",
9085 filter->map[RMAP_IN].map ? "*" : "",
9086 filter->map[RMAP_IN].name);
9087 if (filter->map[RMAP_OUT].name)
9088 vty_out(vty,
9089 " Route map for outgoing advertisements is %s%s\n",
9090 filter->map[RMAP_OUT].map ? "*" : "",
9091 filter->map[RMAP_OUT].name);
9092
9093 /* unsuppress-map */
9094 if (filter->usmap.name)
9095 vty_out(vty,
9096 " Route map for selective unsuppress is %s%s\n",
9097 filter->usmap.map ? "*" : "",
9098 filter->usmap.name);
9099
9100 /* Receive prefix count */
9101 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9102
9103 /* Maximum prefix */
9104 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9105 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9106 p->pmax[afi][safi],
9107 CHECK_FLAG(p->af_flags[afi][safi],
9108 PEER_FLAG_MAX_PREFIX_WARNING)
9109 ? " (warning-only)"
9110 : "");
9111 vty_out(vty, " Threshold for warning message %d%%",
9112 p->pmax_threshold[afi][safi]);
9113 if (p->pmax_restart[afi][safi])
9114 vty_out(vty, ", restart interval %d min",
9115 p->pmax_restart[afi][safi]);
9116 vty_out(vty, "\n");
9117 }
9118
9119 vty_out(vty, "\n");
9120 }
9121 }
9122
9123 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9124 json_object *json)
9125 {
9126 struct bgp *bgp;
9127 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9128 char timebuf[BGP_UPTIME_LEN];
9129 char dn_flag[2];
9130 const char *subcode_str;
9131 const char *code_str;
9132 afi_t afi;
9133 safi_t safi;
9134 uint16_t i;
9135 uint8_t *msg;
9136 json_object *json_neigh = NULL;
9137 time_t epoch_tbuf;
9138
9139 bgp = p->bgp;
9140
9141 if (use_json)
9142 json_neigh = json_object_new_object();
9143
9144 memset(dn_flag, '\0', sizeof(dn_flag));
9145 if (!p->conf_if && peer_dynamic_neighbor(p))
9146 dn_flag[0] = '*';
9147
9148 if (!use_json) {
9149 if (p->conf_if) /* Configured interface name. */
9150 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9151 BGP_PEER_SU_UNSPEC(p)
9152 ? "None"
9153 : sockunion2str(&p->su, buf,
9154 SU_ADDRSTRLEN));
9155 else /* Configured IP address. */
9156 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9157 p->host);
9158 }
9159
9160 if (use_json) {
9161 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9162 json_object_string_add(json_neigh, "bgpNeighborAddr",
9163 "none");
9164 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9165 json_object_string_add(
9166 json_neigh, "bgpNeighborAddr",
9167 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9168
9169 json_object_int_add(json_neigh, "remoteAs", p->as);
9170
9171 if (p->change_local_as)
9172 json_object_int_add(json_neigh, "localAs",
9173 p->change_local_as);
9174 else
9175 json_object_int_add(json_neigh, "localAs", p->local_as);
9176
9177 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9178 json_object_boolean_true_add(json_neigh,
9179 "localAsNoPrepend");
9180
9181 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9182 json_object_boolean_true_add(json_neigh,
9183 "localAsReplaceAs");
9184 } else {
9185 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9186 || (p->as_type == AS_INTERNAL))
9187 vty_out(vty, "remote AS %u, ", p->as);
9188 else
9189 vty_out(vty, "remote AS Unspecified, ");
9190 vty_out(vty, "local AS %u%s%s, ",
9191 p->change_local_as ? p->change_local_as : p->local_as,
9192 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9193 ? " no-prepend"
9194 : "",
9195 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9196 ? " replace-as"
9197 : "");
9198 }
9199 /* peer type internal, external, confed-internal or confed-external */
9200 if (p->as == p->local_as) {
9201 if (use_json) {
9202 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9203 json_object_boolean_true_add(
9204 json_neigh, "nbrConfedInternalLink");
9205 else
9206 json_object_boolean_true_add(json_neigh,
9207 "nbrInternalLink");
9208 } else {
9209 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9210 vty_out(vty, "confed-internal link\n");
9211 else
9212 vty_out(vty, "internal link\n");
9213 }
9214 } else {
9215 if (use_json) {
9216 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9217 json_object_boolean_true_add(
9218 json_neigh, "nbrConfedExternalLink");
9219 else
9220 json_object_boolean_true_add(json_neigh,
9221 "nbrExternalLink");
9222 } else {
9223 if (bgp_confederation_peers_check(bgp, p->as))
9224 vty_out(vty, "confed-external link\n");
9225 else
9226 vty_out(vty, "external link\n");
9227 }
9228 }
9229
9230 /* Description. */
9231 if (p->desc) {
9232 if (use_json)
9233 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9234 else
9235 vty_out(vty, " Description: %s\n", p->desc);
9236 }
9237
9238 if (p->hostname) {
9239 if (use_json) {
9240 if (p->hostname)
9241 json_object_string_add(json_neigh, "hostname",
9242 p->hostname);
9243
9244 if (p->domainname)
9245 json_object_string_add(json_neigh, "domainname",
9246 p->domainname);
9247 } else {
9248 if (p->domainname && (p->domainname[0] != '\0'))
9249 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9250 p->domainname);
9251 else
9252 vty_out(vty, "Hostname: %s\n", p->hostname);
9253 }
9254 }
9255
9256 /* Peer-group */
9257 if (p->group) {
9258 if (use_json) {
9259 json_object_string_add(json_neigh, "peerGroup",
9260 p->group->name);
9261
9262 if (dn_flag[0]) {
9263 struct prefix prefix, *range = NULL;
9264
9265 sockunion2hostprefix(&(p->su), &prefix);
9266 range = peer_group_lookup_dynamic_neighbor_range(
9267 p->group, &prefix);
9268
9269 if (range) {
9270 prefix2str(range, buf1, sizeof(buf1));
9271 json_object_string_add(
9272 json_neigh,
9273 "peerSubnetRangeGroup", buf1);
9274 }
9275 }
9276 } else {
9277 vty_out(vty,
9278 " Member of peer-group %s for session parameters\n",
9279 p->group->name);
9280
9281 if (dn_flag[0]) {
9282 struct prefix prefix, *range = NULL;
9283
9284 sockunion2hostprefix(&(p->su), &prefix);
9285 range = peer_group_lookup_dynamic_neighbor_range(
9286 p->group, &prefix);
9287
9288 if (range) {
9289 prefix2str(range, buf1, sizeof(buf1));
9290 vty_out(vty,
9291 " Belongs to the subnet range group: %s\n",
9292 buf1);
9293 }
9294 }
9295 }
9296 }
9297
9298 if (use_json) {
9299 /* Administrative shutdown. */
9300 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9301 json_object_boolean_true_add(json_neigh,
9302 "adminShutDown");
9303
9304 /* BGP Version. */
9305 json_object_int_add(json_neigh, "bgpVersion", 4);
9306 json_object_string_add(
9307 json_neigh, "remoteRouterId",
9308 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9309 json_object_string_add(
9310 json_neigh, "localRouterId",
9311 inet_ntop(AF_INET, &bgp->router_id, buf1,
9312 sizeof(buf1)));
9313
9314 /* Confederation */
9315 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9316 && bgp_confederation_peers_check(bgp, p->as))
9317 json_object_boolean_true_add(json_neigh,
9318 "nbrCommonAdmin");
9319
9320 /* Status. */
9321 json_object_string_add(
9322 json_neigh, "bgpState",
9323 lookup_msg(bgp_status_msg, p->status, NULL));
9324
9325 if (p->status == Established) {
9326 time_t uptime;
9327
9328 uptime = bgp_clock();
9329 uptime -= p->uptime;
9330 epoch_tbuf = time(NULL) - uptime;
9331
9332 #if CONFDATE > 20200101
9333 CPP_NOTICE(
9334 "bgpTimerUp should be deprecated and can be removed now");
9335 #endif
9336 /*
9337 * bgpTimerUp was miliseconds that was accurate
9338 * up to 1 day, then the value returned
9339 * became garbage. So in order to provide
9340 * some level of backwards compatability,
9341 * we still provde the data, but now
9342 * we are returning the correct value
9343 * and also adding a new bgpTimerUpMsec
9344 * which will allow us to deprecate
9345 * this eventually
9346 */
9347 json_object_int_add(json_neigh, "bgpTimerUp",
9348 uptime * 1000);
9349 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9350 uptime * 1000);
9351 json_object_string_add(json_neigh, "bgpTimerUpString",
9352 peer_uptime(p->uptime, timebuf,
9353 BGP_UPTIME_LEN, 0,
9354 NULL));
9355 json_object_int_add(json_neigh,
9356 "bgpTimerUpEstablishedEpoch",
9357 epoch_tbuf);
9358 }
9359
9360 else if (p->status == Active) {
9361 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9362 json_object_string_add(json_neigh, "bgpStateIs",
9363 "passive");
9364 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9365 json_object_string_add(json_neigh, "bgpStateIs",
9366 "passiveNSF");
9367 }
9368
9369 /* read timer */
9370 time_t uptime;
9371 struct tm *tm;
9372
9373 uptime = bgp_clock();
9374 uptime -= p->readtime;
9375 tm = gmtime(&uptime);
9376 json_object_int_add(json_neigh, "bgpTimerLastRead",
9377 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9378 + (tm->tm_hour * 3600000));
9379
9380 uptime = bgp_clock();
9381 uptime -= p->last_write;
9382 tm = gmtime(&uptime);
9383 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9384 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9385 + (tm->tm_hour * 3600000));
9386
9387 uptime = bgp_clock();
9388 uptime -= p->update_time;
9389 tm = gmtime(&uptime);
9390 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9391 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9392 + (tm->tm_hour * 3600000));
9393
9394 /* Configured timer values. */
9395 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9396 p->v_holdtime * 1000);
9397 json_object_int_add(json_neigh,
9398 "bgpTimerKeepAliveIntervalMsecs",
9399 p->v_keepalive * 1000);
9400 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9401 json_object_int_add(json_neigh,
9402 "bgpTimerConfiguredHoldTimeMsecs",
9403 p->holdtime * 1000);
9404 json_object_int_add(
9405 json_neigh,
9406 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9407 p->keepalive * 1000);
9408 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9409 || (bgp->default_keepalive
9410 != BGP_DEFAULT_KEEPALIVE)) {
9411 json_object_int_add(json_neigh,
9412 "bgpTimerConfiguredHoldTimeMsecs",
9413 bgp->default_holdtime);
9414 json_object_int_add(
9415 json_neigh,
9416 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9417 bgp->default_keepalive);
9418 }
9419 } else {
9420 /* Administrative shutdown. */
9421 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9422 vty_out(vty, " Administratively shut down\n");
9423
9424 /* BGP Version. */
9425 vty_out(vty, " BGP version 4");
9426 vty_out(vty, ", remote router ID %s",
9427 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9428 vty_out(vty, ", local router ID %s\n",
9429 inet_ntop(AF_INET, &bgp->router_id, buf1,
9430 sizeof(buf1)));
9431
9432 /* Confederation */
9433 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9434 && bgp_confederation_peers_check(bgp, p->as))
9435 vty_out(vty,
9436 " Neighbor under common administration\n");
9437
9438 /* Status. */
9439 vty_out(vty, " BGP state = %s",
9440 lookup_msg(bgp_status_msg, p->status, NULL));
9441
9442 if (p->status == Established)
9443 vty_out(vty, ", up for %8s",
9444 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9445 0, NULL));
9446
9447 else if (p->status == Active) {
9448 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9449 vty_out(vty, " (passive)");
9450 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9451 vty_out(vty, " (NSF passive)");
9452 }
9453 vty_out(vty, "\n");
9454
9455 /* read timer */
9456 vty_out(vty, " Last read %s",
9457 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9458 NULL));
9459 vty_out(vty, ", Last write %s\n",
9460 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9461 NULL));
9462
9463 /* Configured timer values. */
9464 vty_out(vty,
9465 " Hold time is %d, keepalive interval is %d seconds\n",
9466 p->v_holdtime, p->v_keepalive);
9467 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9468 vty_out(vty, " Configured hold time is %d",
9469 p->holdtime);
9470 vty_out(vty, ", keepalive interval is %d seconds\n",
9471 p->keepalive);
9472 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9473 || (bgp->default_keepalive
9474 != BGP_DEFAULT_KEEPALIVE)) {
9475 vty_out(vty, " Configured hold time is %d",
9476 bgp->default_holdtime);
9477 vty_out(vty, ", keepalive interval is %d seconds\n",
9478 bgp->default_keepalive);
9479 }
9480 }
9481 /* Capability. */
9482 if (p->status == Established) {
9483 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9484 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9485 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9486 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9487 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9488 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9489 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9490 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9491 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9492 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9493 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9494 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9495 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9496 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9497 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9498 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9499 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9500 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9501 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9502 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9503 if (use_json) {
9504 json_object *json_cap = NULL;
9505
9506 json_cap = json_object_new_object();
9507
9508 /* AS4 */
9509 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9510 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9511 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9512 && CHECK_FLAG(p->cap,
9513 PEER_CAP_AS4_RCV))
9514 json_object_string_add(
9515 json_cap, "4byteAs",
9516 "advertisedAndReceived");
9517 else if (CHECK_FLAG(p->cap,
9518 PEER_CAP_AS4_ADV))
9519 json_object_string_add(
9520 json_cap, "4byteAs",
9521 "advertised");
9522 else if (CHECK_FLAG(p->cap,
9523 PEER_CAP_AS4_RCV))
9524 json_object_string_add(
9525 json_cap, "4byteAs",
9526 "received");
9527 }
9528
9529 /* AddPath */
9530 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9531 || CHECK_FLAG(p->cap,
9532 PEER_CAP_ADDPATH_ADV)) {
9533 json_object *json_add = NULL;
9534 const char *print_store;
9535
9536 json_add = json_object_new_object();
9537
9538 FOREACH_AFI_SAFI (afi, safi) {
9539 json_object *json_sub = NULL;
9540 json_sub =
9541 json_object_new_object();
9542 print_store = afi_safi_print(
9543 afi, safi);
9544
9545 if (CHECK_FLAG(
9546 p->af_cap[afi]
9547 [safi],
9548 PEER_CAP_ADDPATH_AF_TX_ADV)
9549 || CHECK_FLAG(
9550 p->af_cap[afi]
9551 [safi],
9552 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9553 if (CHECK_FLAG(
9554 p->af_cap
9555 [afi]
9556 [safi],
9557 PEER_CAP_ADDPATH_AF_TX_ADV)
9558 && CHECK_FLAG(
9559 p->af_cap
9560 [afi]
9561 [safi],
9562 PEER_CAP_ADDPATH_AF_TX_RCV))
9563 json_object_boolean_true_add(
9564 json_sub,
9565 "txAdvertisedAndReceived");
9566 else if (
9567 CHECK_FLAG(
9568 p->af_cap
9569 [afi]
9570 [safi],
9571 PEER_CAP_ADDPATH_AF_TX_ADV))
9572 json_object_boolean_true_add(
9573 json_sub,
9574 "txAdvertised");
9575 else if (
9576 CHECK_FLAG(
9577 p->af_cap
9578 [afi]
9579 [safi],
9580 PEER_CAP_ADDPATH_AF_TX_RCV))
9581 json_object_boolean_true_add(
9582 json_sub,
9583 "txReceived");
9584 }
9585
9586 if (CHECK_FLAG(
9587 p->af_cap[afi]
9588 [safi],
9589 PEER_CAP_ADDPATH_AF_RX_ADV)
9590 || CHECK_FLAG(
9591 p->af_cap[afi]
9592 [safi],
9593 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9594 if (CHECK_FLAG(
9595 p->af_cap
9596 [afi]
9597 [safi],
9598 PEER_CAP_ADDPATH_AF_RX_ADV)
9599 && CHECK_FLAG(
9600 p->af_cap
9601 [afi]
9602 [safi],
9603 PEER_CAP_ADDPATH_AF_RX_RCV))
9604 json_object_boolean_true_add(
9605 json_sub,
9606 "rxAdvertisedAndReceived");
9607 else if (
9608 CHECK_FLAG(
9609 p->af_cap
9610 [afi]
9611 [safi],
9612 PEER_CAP_ADDPATH_AF_RX_ADV))
9613 json_object_boolean_true_add(
9614 json_sub,
9615 "rxAdvertised");
9616 else if (
9617 CHECK_FLAG(
9618 p->af_cap
9619 [afi]
9620 [safi],
9621 PEER_CAP_ADDPATH_AF_RX_RCV))
9622 json_object_boolean_true_add(
9623 json_sub,
9624 "rxReceived");
9625 }
9626
9627 if (CHECK_FLAG(
9628 p->af_cap[afi]
9629 [safi],
9630 PEER_CAP_ADDPATH_AF_TX_ADV)
9631 || CHECK_FLAG(
9632 p->af_cap[afi]
9633 [safi],
9634 PEER_CAP_ADDPATH_AF_TX_RCV)
9635 || CHECK_FLAG(
9636 p->af_cap[afi]
9637 [safi],
9638 PEER_CAP_ADDPATH_AF_RX_ADV)
9639 || CHECK_FLAG(
9640 p->af_cap[afi]
9641 [safi],
9642 PEER_CAP_ADDPATH_AF_RX_RCV))
9643 json_object_object_add(
9644 json_add,
9645 print_store,
9646 json_sub);
9647 else
9648 json_object_free(
9649 json_sub);
9650 }
9651
9652 json_object_object_add(
9653 json_cap, "addPath", json_add);
9654 }
9655
9656 /* Dynamic */
9657 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9658 || CHECK_FLAG(p->cap,
9659 PEER_CAP_DYNAMIC_ADV)) {
9660 if (CHECK_FLAG(p->cap,
9661 PEER_CAP_DYNAMIC_ADV)
9662 && CHECK_FLAG(p->cap,
9663 PEER_CAP_DYNAMIC_RCV))
9664 json_object_string_add(
9665 json_cap, "dynamic",
9666 "advertisedAndReceived");
9667 else if (CHECK_FLAG(
9668 p->cap,
9669 PEER_CAP_DYNAMIC_ADV))
9670 json_object_string_add(
9671 json_cap, "dynamic",
9672 "advertised");
9673 else if (CHECK_FLAG(
9674 p->cap,
9675 PEER_CAP_DYNAMIC_RCV))
9676 json_object_string_add(
9677 json_cap, "dynamic",
9678 "received");
9679 }
9680
9681 /* Extended nexthop */
9682 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9683 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9684 json_object *json_nxt = NULL;
9685 const char *print_store;
9686
9687
9688 if (CHECK_FLAG(p->cap,
9689 PEER_CAP_ENHE_ADV)
9690 && CHECK_FLAG(p->cap,
9691 PEER_CAP_ENHE_RCV))
9692 json_object_string_add(
9693 json_cap,
9694 "extendedNexthop",
9695 "advertisedAndReceived");
9696 else if (CHECK_FLAG(p->cap,
9697 PEER_CAP_ENHE_ADV))
9698 json_object_string_add(
9699 json_cap,
9700 "extendedNexthop",
9701 "advertised");
9702 else if (CHECK_FLAG(p->cap,
9703 PEER_CAP_ENHE_RCV))
9704 json_object_string_add(
9705 json_cap,
9706 "extendedNexthop",
9707 "received");
9708
9709 if (CHECK_FLAG(p->cap,
9710 PEER_CAP_ENHE_RCV)) {
9711 json_nxt =
9712 json_object_new_object();
9713
9714 for (safi = SAFI_UNICAST;
9715 safi < SAFI_MAX; safi++) {
9716 if (CHECK_FLAG(
9717 p->af_cap
9718 [AFI_IP]
9719 [safi],
9720 PEER_CAP_ENHE_AF_RCV)) {
9721 print_store = afi_safi_print(
9722 AFI_IP,
9723 safi);
9724 json_object_string_add(
9725 json_nxt,
9726 print_store,
9727 "recieved"); /* misspelled for compatibility */
9728 }
9729 }
9730 json_object_object_add(
9731 json_cap,
9732 "extendedNexthopFamililesByPeer",
9733 json_nxt);
9734 }
9735 }
9736
9737 /* Route Refresh */
9738 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9739 || CHECK_FLAG(p->cap,
9740 PEER_CAP_REFRESH_NEW_RCV)
9741 || CHECK_FLAG(p->cap,
9742 PEER_CAP_REFRESH_OLD_RCV)) {
9743 if (CHECK_FLAG(p->cap,
9744 PEER_CAP_REFRESH_ADV)
9745 && (CHECK_FLAG(
9746 p->cap,
9747 PEER_CAP_REFRESH_NEW_RCV)
9748 || CHECK_FLAG(
9749 p->cap,
9750 PEER_CAP_REFRESH_OLD_RCV))) {
9751 if (CHECK_FLAG(
9752 p->cap,
9753 PEER_CAP_REFRESH_OLD_RCV)
9754 && CHECK_FLAG(
9755 p->cap,
9756 PEER_CAP_REFRESH_NEW_RCV))
9757 json_object_string_add(
9758 json_cap,
9759 "routeRefresh",
9760 "advertisedAndReceivedOldNew");
9761 else {
9762 if (CHECK_FLAG(
9763 p->cap,
9764 PEER_CAP_REFRESH_OLD_RCV))
9765 json_object_string_add(
9766 json_cap,
9767 "routeRefresh",
9768 "advertisedAndReceivedOld");
9769 else
9770 json_object_string_add(
9771 json_cap,
9772 "routeRefresh",
9773 "advertisedAndReceivedNew");
9774 }
9775 } else if (
9776 CHECK_FLAG(
9777 p->cap,
9778 PEER_CAP_REFRESH_ADV))
9779 json_object_string_add(
9780 json_cap,
9781 "routeRefresh",
9782 "advertised");
9783 else if (
9784 CHECK_FLAG(
9785 p->cap,
9786 PEER_CAP_REFRESH_NEW_RCV)
9787 || CHECK_FLAG(
9788 p->cap,
9789 PEER_CAP_REFRESH_OLD_RCV))
9790 json_object_string_add(
9791 json_cap,
9792 "routeRefresh",
9793 "received");
9794 }
9795
9796 /* Multiprotocol Extensions */
9797 json_object *json_multi = NULL;
9798 json_multi = json_object_new_object();
9799
9800 FOREACH_AFI_SAFI (afi, safi) {
9801 if (p->afc_adv[afi][safi]
9802 || p->afc_recv[afi][safi]) {
9803 json_object *json_exten = NULL;
9804 json_exten =
9805 json_object_new_object();
9806
9807 if (p->afc_adv[afi][safi]
9808 && p->afc_recv[afi][safi])
9809 json_object_boolean_true_add(
9810 json_exten,
9811 "advertisedAndReceived");
9812 else if (p->afc_adv[afi][safi])
9813 json_object_boolean_true_add(
9814 json_exten,
9815 "advertised");
9816 else if (p->afc_recv[afi][safi])
9817 json_object_boolean_true_add(
9818 json_exten,
9819 "received");
9820
9821 json_object_object_add(
9822 json_multi,
9823 afi_safi_print(afi,
9824 safi),
9825 json_exten);
9826 }
9827 }
9828 json_object_object_add(
9829 json_cap, "multiprotocolExtensions",
9830 json_multi);
9831
9832 /* Hostname capabilities */
9833 json_object *json_hname = NULL;
9834
9835 json_hname = json_object_new_object();
9836
9837 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9838 json_object_string_add(
9839 json_hname, "advHostName",
9840 bgp->peer_self->hostname
9841 ? bgp->peer_self
9842 ->hostname
9843 : "n/a");
9844 json_object_string_add(
9845 json_hname, "advDomainName",
9846 bgp->peer_self->domainname
9847 ? bgp->peer_self
9848 ->domainname
9849 : "n/a");
9850 }
9851
9852
9853 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9854 json_object_string_add(
9855 json_hname, "rcvHostName",
9856 p->hostname ? p->hostname
9857 : "n/a");
9858 json_object_string_add(
9859 json_hname, "rcvDomainName",
9860 p->domainname ? p->domainname
9861 : "n/a");
9862 }
9863
9864 json_object_object_add(json_cap, "hostName",
9865 json_hname);
9866
9867 /* Gracefull Restart */
9868 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9869 || CHECK_FLAG(p->cap,
9870 PEER_CAP_RESTART_ADV)) {
9871 if (CHECK_FLAG(p->cap,
9872 PEER_CAP_RESTART_ADV)
9873 && CHECK_FLAG(p->cap,
9874 PEER_CAP_RESTART_RCV))
9875 json_object_string_add(
9876 json_cap,
9877 "gracefulRestart",
9878 "advertisedAndReceived");
9879 else if (CHECK_FLAG(
9880 p->cap,
9881 PEER_CAP_RESTART_ADV))
9882 json_object_string_add(
9883 json_cap,
9884 "gracefulRestartCapability",
9885 "advertised");
9886 else if (CHECK_FLAG(
9887 p->cap,
9888 PEER_CAP_RESTART_RCV))
9889 json_object_string_add(
9890 json_cap,
9891 "gracefulRestartCapability",
9892 "received");
9893
9894 if (CHECK_FLAG(p->cap,
9895 PEER_CAP_RESTART_RCV)) {
9896 int restart_af_count = 0;
9897 json_object *json_restart =
9898 NULL;
9899 json_restart =
9900 json_object_new_object();
9901
9902 json_object_int_add(
9903 json_cap,
9904 "gracefulRestartRemoteTimerMsecs",
9905 p->v_gr_restart * 1000);
9906
9907 FOREACH_AFI_SAFI (afi, safi) {
9908 if (CHECK_FLAG(
9909 p->af_cap
9910 [afi]
9911 [safi],
9912 PEER_CAP_RESTART_AF_RCV)) {
9913 json_object *
9914 json_sub =
9915 NULL;
9916 json_sub =
9917 json_object_new_object();
9918
9919 if (CHECK_FLAG(
9920 p->af_cap
9921 [afi]
9922 [safi],
9923 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9924 json_object_boolean_true_add(
9925 json_sub,
9926 "preserved");
9927 restart_af_count++;
9928 json_object_object_add(
9929 json_restart,
9930 afi_safi_print(
9931 afi,
9932 safi),
9933 json_sub);
9934 }
9935 }
9936 if (!restart_af_count) {
9937 json_object_string_add(
9938 json_cap,
9939 "addressFamiliesByPeer",
9940 "none");
9941 json_object_free(
9942 json_restart);
9943 } else
9944 json_object_object_add(
9945 json_cap,
9946 "addressFamiliesByPeer",
9947 json_restart);
9948 }
9949 }
9950 json_object_object_add(json_neigh,
9951 "neighborCapabilities",
9952 json_cap);
9953 } else {
9954 vty_out(vty, " Neighbor capabilities:\n");
9955
9956 /* AS4 */
9957 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9958 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9959 vty_out(vty, " 4 Byte AS:");
9960 if (CHECK_FLAG(p->cap,
9961 PEER_CAP_AS4_ADV))
9962 vty_out(vty, " advertised");
9963 if (CHECK_FLAG(p->cap,
9964 PEER_CAP_AS4_RCV))
9965 vty_out(vty, " %sreceived",
9966 CHECK_FLAG(
9967 p->cap,
9968 PEER_CAP_AS4_ADV)
9969 ? "and "
9970 : "");
9971 vty_out(vty, "\n");
9972 }
9973
9974 /* AddPath */
9975 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9976 || CHECK_FLAG(p->cap,
9977 PEER_CAP_ADDPATH_ADV)) {
9978 vty_out(vty, " AddPath:\n");
9979
9980 FOREACH_AFI_SAFI (afi, safi) {
9981 if (CHECK_FLAG(
9982 p->af_cap[afi]
9983 [safi],
9984 PEER_CAP_ADDPATH_AF_TX_ADV)
9985 || CHECK_FLAG(
9986 p->af_cap[afi]
9987 [safi],
9988 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9989 vty_out(vty,
9990 " %s: TX ",
9991 afi_safi_print(
9992 afi,
9993 safi));
9994
9995 if (CHECK_FLAG(
9996 p->af_cap
9997 [afi]
9998 [safi],
9999 PEER_CAP_ADDPATH_AF_TX_ADV))
10000 vty_out(vty,
10001 "advertised %s",
10002 afi_safi_print(
10003 afi,
10004 safi));
10005
10006 if (CHECK_FLAG(
10007 p->af_cap
10008 [afi]
10009 [safi],
10010 PEER_CAP_ADDPATH_AF_TX_RCV))
10011 vty_out(vty,
10012 "%sreceived",
10013 CHECK_FLAG(
10014 p->af_cap
10015 [afi]
10016 [safi],
10017 PEER_CAP_ADDPATH_AF_TX_ADV)
10018 ? " and "
10019 : "");
10020
10021 vty_out(vty, "\n");
10022 }
10023
10024 if (CHECK_FLAG(
10025 p->af_cap[afi]
10026 [safi],
10027 PEER_CAP_ADDPATH_AF_RX_ADV)
10028 || CHECK_FLAG(
10029 p->af_cap[afi]
10030 [safi],
10031 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10032 vty_out(vty,
10033 " %s: RX ",
10034 afi_safi_print(
10035 afi,
10036 safi));
10037
10038 if (CHECK_FLAG(
10039 p->af_cap
10040 [afi]
10041 [safi],
10042 PEER_CAP_ADDPATH_AF_RX_ADV))
10043 vty_out(vty,
10044 "advertised %s",
10045 afi_safi_print(
10046 afi,
10047 safi));
10048
10049 if (CHECK_FLAG(
10050 p->af_cap
10051 [afi]
10052 [safi],
10053 PEER_CAP_ADDPATH_AF_RX_RCV))
10054 vty_out(vty,
10055 "%sreceived",
10056 CHECK_FLAG(
10057 p->af_cap
10058 [afi]
10059 [safi],
10060 PEER_CAP_ADDPATH_AF_RX_ADV)
10061 ? " and "
10062 : "");
10063
10064 vty_out(vty, "\n");
10065 }
10066 }
10067 }
10068
10069 /* Dynamic */
10070 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10071 || CHECK_FLAG(p->cap,
10072 PEER_CAP_DYNAMIC_ADV)) {
10073 vty_out(vty, " Dynamic:");
10074 if (CHECK_FLAG(p->cap,
10075 PEER_CAP_DYNAMIC_ADV))
10076 vty_out(vty, " advertised");
10077 if (CHECK_FLAG(p->cap,
10078 PEER_CAP_DYNAMIC_RCV))
10079 vty_out(vty, " %sreceived",
10080 CHECK_FLAG(
10081 p->cap,
10082 PEER_CAP_DYNAMIC_ADV)
10083 ? "and "
10084 : "");
10085 vty_out(vty, "\n");
10086 }
10087
10088 /* Extended nexthop */
10089 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10090 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10091 vty_out(vty, " Extended nexthop:");
10092 if (CHECK_FLAG(p->cap,
10093 PEER_CAP_ENHE_ADV))
10094 vty_out(vty, " advertised");
10095 if (CHECK_FLAG(p->cap,
10096 PEER_CAP_ENHE_RCV))
10097 vty_out(vty, " %sreceived",
10098 CHECK_FLAG(
10099 p->cap,
10100 PEER_CAP_ENHE_ADV)
10101 ? "and "
10102 : "");
10103 vty_out(vty, "\n");
10104
10105 if (CHECK_FLAG(p->cap,
10106 PEER_CAP_ENHE_RCV)) {
10107 vty_out(vty,
10108 " Address families by peer:\n ");
10109 for (safi = SAFI_UNICAST;
10110 safi < SAFI_MAX; safi++)
10111 if (CHECK_FLAG(
10112 p->af_cap
10113 [AFI_IP]
10114 [safi],
10115 PEER_CAP_ENHE_AF_RCV))
10116 vty_out(vty,
10117 " %s\n",
10118 afi_safi_print(
10119 AFI_IP,
10120 safi));
10121 }
10122 }
10123
10124 /* Route Refresh */
10125 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10126 || CHECK_FLAG(p->cap,
10127 PEER_CAP_REFRESH_NEW_RCV)
10128 || CHECK_FLAG(p->cap,
10129 PEER_CAP_REFRESH_OLD_RCV)) {
10130 vty_out(vty, " Route refresh:");
10131 if (CHECK_FLAG(p->cap,
10132 PEER_CAP_REFRESH_ADV))
10133 vty_out(vty, " advertised");
10134 if (CHECK_FLAG(p->cap,
10135 PEER_CAP_REFRESH_NEW_RCV)
10136 || CHECK_FLAG(
10137 p->cap,
10138 PEER_CAP_REFRESH_OLD_RCV))
10139 vty_out(vty, " %sreceived(%s)",
10140 CHECK_FLAG(
10141 p->cap,
10142 PEER_CAP_REFRESH_ADV)
10143 ? "and "
10144 : "",
10145 (CHECK_FLAG(
10146 p->cap,
10147 PEER_CAP_REFRESH_OLD_RCV)
10148 && CHECK_FLAG(
10149 p->cap,
10150 PEER_CAP_REFRESH_NEW_RCV))
10151 ? "old & new"
10152 : CHECK_FLAG(
10153 p->cap,
10154 PEER_CAP_REFRESH_OLD_RCV)
10155 ? "old"
10156 : "new");
10157
10158 vty_out(vty, "\n");
10159 }
10160
10161 /* Multiprotocol Extensions */
10162 FOREACH_AFI_SAFI (afi, safi)
10163 if (p->afc_adv[afi][safi]
10164 || p->afc_recv[afi][safi]) {
10165 vty_out(vty,
10166 " Address Family %s:",
10167 afi_safi_print(afi,
10168 safi));
10169 if (p->afc_adv[afi][safi])
10170 vty_out(vty,
10171 " advertised");
10172 if (p->afc_recv[afi][safi])
10173 vty_out(vty,
10174 " %sreceived",
10175 p->afc_adv[afi]
10176 [safi]
10177 ? "and "
10178 : "");
10179 vty_out(vty, "\n");
10180 }
10181
10182 /* Hostname capability */
10183 vty_out(vty, " Hostname Capability:");
10184
10185 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10186 vty_out(vty,
10187 " advertised (name: %s,domain name: %s)",
10188 bgp->peer_self->hostname
10189 ? bgp->peer_self
10190 ->hostname
10191 : "n/a",
10192 bgp->peer_self->domainname
10193 ? bgp->peer_self
10194 ->domainname
10195 : "n/a");
10196 } else {
10197 vty_out(vty, " not advertised");
10198 }
10199
10200 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10201 vty_out(vty,
10202 " received (name: %s,domain name: %s)",
10203 p->hostname ? p->hostname
10204 : "n/a",
10205 p->domainname ? p->domainname
10206 : "n/a");
10207 } else {
10208 vty_out(vty, " not received");
10209 }
10210
10211 vty_out(vty, "\n");
10212
10213 /* Gracefull Restart */
10214 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10215 || CHECK_FLAG(p->cap,
10216 PEER_CAP_RESTART_ADV)) {
10217 vty_out(vty,
10218 " Graceful Restart Capabilty:");
10219 if (CHECK_FLAG(p->cap,
10220 PEER_CAP_RESTART_ADV))
10221 vty_out(vty, " advertised");
10222 if (CHECK_FLAG(p->cap,
10223 PEER_CAP_RESTART_RCV))
10224 vty_out(vty, " %sreceived",
10225 CHECK_FLAG(
10226 p->cap,
10227 PEER_CAP_RESTART_ADV)
10228 ? "and "
10229 : "");
10230 vty_out(vty, "\n");
10231
10232 if (CHECK_FLAG(p->cap,
10233 PEER_CAP_RESTART_RCV)) {
10234 int restart_af_count = 0;
10235
10236 vty_out(vty,
10237 " Remote Restart timer is %d seconds\n",
10238 p->v_gr_restart);
10239 vty_out(vty,
10240 " Address families by peer:\n ");
10241
10242 FOREACH_AFI_SAFI (afi, safi)
10243 if (CHECK_FLAG(
10244 p->af_cap
10245 [afi]
10246 [safi],
10247 PEER_CAP_RESTART_AF_RCV)) {
10248 vty_out(vty,
10249 "%s%s(%s)",
10250 restart_af_count
10251 ? ", "
10252 : "",
10253 afi_safi_print(
10254 afi,
10255 safi),
10256 CHECK_FLAG(
10257 p->af_cap
10258 [afi]
10259 [safi],
10260 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10261 ? "preserved"
10262 : "not preserved");
10263 restart_af_count++;
10264 }
10265 if (!restart_af_count)
10266 vty_out(vty, "none");
10267 vty_out(vty, "\n");
10268 }
10269 }
10270 }
10271 }
10272 }
10273
10274 /* graceful restart information */
10275 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10276 || p->t_gr_stale) {
10277 json_object *json_grace = NULL;
10278 json_object *json_grace_send = NULL;
10279 json_object *json_grace_recv = NULL;
10280 int eor_send_af_count = 0;
10281 int eor_receive_af_count = 0;
10282
10283 if (use_json) {
10284 json_grace = json_object_new_object();
10285 json_grace_send = json_object_new_object();
10286 json_grace_recv = json_object_new_object();
10287
10288 if (p->status == Established) {
10289 FOREACH_AFI_SAFI (afi, safi) {
10290 if (CHECK_FLAG(p->af_sflags[afi][safi],
10291 PEER_STATUS_EOR_SEND)) {
10292 json_object_boolean_true_add(
10293 json_grace_send,
10294 afi_safi_print(afi,
10295 safi));
10296 eor_send_af_count++;
10297 }
10298 }
10299 FOREACH_AFI_SAFI (afi, safi) {
10300 if (CHECK_FLAG(
10301 p->af_sflags[afi][safi],
10302 PEER_STATUS_EOR_RECEIVED)) {
10303 json_object_boolean_true_add(
10304 json_grace_recv,
10305 afi_safi_print(afi,
10306 safi));
10307 eor_receive_af_count++;
10308 }
10309 }
10310 }
10311
10312 json_object_object_add(json_grace, "endOfRibSend",
10313 json_grace_send);
10314 json_object_object_add(json_grace, "endOfRibRecv",
10315 json_grace_recv);
10316
10317 if (p->t_gr_restart)
10318 json_object_int_add(json_grace,
10319 "gracefulRestartTimerMsecs",
10320 thread_timer_remain_second(
10321 p->t_gr_restart)
10322 * 1000);
10323
10324 if (p->t_gr_stale)
10325 json_object_int_add(
10326 json_grace,
10327 "gracefulStalepathTimerMsecs",
10328 thread_timer_remain_second(
10329 p->t_gr_stale)
10330 * 1000);
10331
10332 json_object_object_add(
10333 json_neigh, "gracefulRestartInfo", json_grace);
10334 } else {
10335 vty_out(vty, " Graceful restart information:\n");
10336 if (p->status == Established) {
10337 vty_out(vty, " End-of-RIB send: ");
10338 FOREACH_AFI_SAFI (afi, safi) {
10339 if (CHECK_FLAG(p->af_sflags[afi][safi],
10340 PEER_STATUS_EOR_SEND)) {
10341 vty_out(vty, "%s%s",
10342 eor_send_af_count ? ", "
10343 : "",
10344 afi_safi_print(afi,
10345 safi));
10346 eor_send_af_count++;
10347 }
10348 }
10349 vty_out(vty, "\n");
10350 vty_out(vty, " End-of-RIB received: ");
10351 FOREACH_AFI_SAFI (afi, safi) {
10352 if (CHECK_FLAG(
10353 p->af_sflags[afi][safi],
10354 PEER_STATUS_EOR_RECEIVED)) {
10355 vty_out(vty, "%s%s",
10356 eor_receive_af_count
10357 ? ", "
10358 : "",
10359 afi_safi_print(afi,
10360 safi));
10361 eor_receive_af_count++;
10362 }
10363 }
10364 vty_out(vty, "\n");
10365 }
10366
10367 if (p->t_gr_restart)
10368 vty_out(vty,
10369 " The remaining time of restart timer is %ld\n",
10370 thread_timer_remain_second(
10371 p->t_gr_restart));
10372
10373 if (p->t_gr_stale)
10374 vty_out(vty,
10375 " The remaining time of stalepath timer is %ld\n",
10376 thread_timer_remain_second(
10377 p->t_gr_stale));
10378 }
10379 }
10380 if (use_json) {
10381 json_object *json_stat = NULL;
10382 json_stat = json_object_new_object();
10383 /* Packet counts. */
10384 json_object_int_add(json_stat, "depthInq", 0);
10385 json_object_int_add(json_stat, "depthOutq",
10386 (unsigned long)p->obuf->count);
10387 json_object_int_add(json_stat, "opensSent",
10388 atomic_load_explicit(&p->open_out,
10389 memory_order_relaxed));
10390 json_object_int_add(json_stat, "opensRecv",
10391 atomic_load_explicit(&p->open_in,
10392 memory_order_relaxed));
10393 json_object_int_add(json_stat, "notificationsSent",
10394 atomic_load_explicit(&p->notify_out,
10395 memory_order_relaxed));
10396 json_object_int_add(json_stat, "notificationsRecv",
10397 atomic_load_explicit(&p->notify_in,
10398 memory_order_relaxed));
10399 json_object_int_add(json_stat, "updatesSent",
10400 atomic_load_explicit(&p->update_out,
10401 memory_order_relaxed));
10402 json_object_int_add(json_stat, "updatesRecv",
10403 atomic_load_explicit(&p->update_in,
10404 memory_order_relaxed));
10405 json_object_int_add(json_stat, "keepalivesSent",
10406 atomic_load_explicit(&p->keepalive_out,
10407 memory_order_relaxed));
10408 json_object_int_add(json_stat, "keepalivesRecv",
10409 atomic_load_explicit(&p->keepalive_in,
10410 memory_order_relaxed));
10411 json_object_int_add(json_stat, "routeRefreshSent",
10412 atomic_load_explicit(&p->refresh_out,
10413 memory_order_relaxed));
10414 json_object_int_add(json_stat, "routeRefreshRecv",
10415 atomic_load_explicit(&p->refresh_in,
10416 memory_order_relaxed));
10417 json_object_int_add(json_stat, "capabilitySent",
10418 atomic_load_explicit(&p->dynamic_cap_out,
10419 memory_order_relaxed));
10420 json_object_int_add(json_stat, "capabilityRecv",
10421 atomic_load_explicit(&p->dynamic_cap_in,
10422 memory_order_relaxed));
10423 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10424 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10425 json_object_object_add(json_neigh, "messageStats", json_stat);
10426 } else {
10427 /* Packet counts. */
10428 vty_out(vty, " Message statistics:\n");
10429 vty_out(vty, " Inq depth is 0\n");
10430 vty_out(vty, " Outq depth is %lu\n",
10431 (unsigned long)p->obuf->count);
10432 vty_out(vty, " Sent Rcvd\n");
10433 vty_out(vty, " Opens: %10d %10d\n",
10434 atomic_load_explicit(&p->open_out,
10435 memory_order_relaxed),
10436 atomic_load_explicit(&p->open_in,
10437 memory_order_relaxed));
10438 vty_out(vty, " Notifications: %10d %10d\n",
10439 atomic_load_explicit(&p->notify_out,
10440 memory_order_relaxed),
10441 atomic_load_explicit(&p->notify_in,
10442 memory_order_relaxed));
10443 vty_out(vty, " Updates: %10d %10d\n",
10444 atomic_load_explicit(&p->update_out,
10445 memory_order_relaxed),
10446 atomic_load_explicit(&p->update_in,
10447 memory_order_relaxed));
10448 vty_out(vty, " Keepalives: %10d %10d\n",
10449 atomic_load_explicit(&p->keepalive_out,
10450 memory_order_relaxed),
10451 atomic_load_explicit(&p->keepalive_in,
10452 memory_order_relaxed));
10453 vty_out(vty, " Route Refresh: %10d %10d\n",
10454 atomic_load_explicit(&p->refresh_out,
10455 memory_order_relaxed),
10456 atomic_load_explicit(&p->refresh_in,
10457 memory_order_relaxed));
10458 vty_out(vty, " Capability: %10d %10d\n",
10459 atomic_load_explicit(&p->dynamic_cap_out,
10460 memory_order_relaxed),
10461 atomic_load_explicit(&p->dynamic_cap_in,
10462 memory_order_relaxed));
10463 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10464 PEER_TOTAL_RX(p));
10465 }
10466
10467 if (use_json) {
10468 /* advertisement-interval */
10469 json_object_int_add(json_neigh,
10470 "minBtwnAdvertisementRunsTimerMsecs",
10471 p->v_routeadv * 1000);
10472
10473 /* Update-source. */
10474 if (p->update_if || p->update_source) {
10475 if (p->update_if)
10476 json_object_string_add(json_neigh,
10477 "updateSource",
10478 p->update_if);
10479 else if (p->update_source)
10480 json_object_string_add(
10481 json_neigh, "updateSource",
10482 sockunion2str(p->update_source, buf1,
10483 SU_ADDRSTRLEN));
10484 }
10485 } else {
10486 /* advertisement-interval */
10487 vty_out(vty,
10488 " Minimum time between advertisement runs is %d seconds\n",
10489 p->v_routeadv);
10490
10491 /* Update-source. */
10492 if (p->update_if || p->update_source) {
10493 vty_out(vty, " Update source is ");
10494 if (p->update_if)
10495 vty_out(vty, "%s", p->update_if);
10496 else if (p->update_source)
10497 vty_out(vty, "%s",
10498 sockunion2str(p->update_source, buf1,
10499 SU_ADDRSTRLEN));
10500 vty_out(vty, "\n");
10501 }
10502
10503 vty_out(vty, "\n");
10504 }
10505
10506 /* Address Family Information */
10507 json_object *json_hold = NULL;
10508
10509 if (use_json)
10510 json_hold = json_object_new_object();
10511
10512 FOREACH_AFI_SAFI (afi, safi)
10513 if (p->afc[afi][safi])
10514 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10515 json_hold);
10516
10517 if (use_json) {
10518 json_object_object_add(json_neigh, "addressFamilyInfo",
10519 json_hold);
10520 json_object_int_add(json_neigh, "connectionsEstablished",
10521 p->established);
10522 json_object_int_add(json_neigh, "connectionsDropped",
10523 p->dropped);
10524 } else
10525 vty_out(vty, " Connections established %d; dropped %d\n",
10526 p->established, p->dropped);
10527
10528 if (!p->last_reset) {
10529 if (use_json)
10530 json_object_string_add(json_neigh, "lastReset",
10531 "never");
10532 else
10533 vty_out(vty, " Last reset never\n");
10534 } else {
10535 if (use_json) {
10536 time_t uptime;
10537 struct tm *tm;
10538
10539 uptime = bgp_clock();
10540 uptime -= p->resettime;
10541 tm = gmtime(&uptime);
10542 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10543 (tm->tm_sec * 1000)
10544 + (tm->tm_min * 60000)
10545 + (tm->tm_hour * 3600000));
10546 json_object_string_add(
10547 json_neigh, "lastResetDueTo",
10548 peer_down_str[(int)p->last_reset]);
10549 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10550 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10551 char errorcodesubcode_hexstr[5];
10552 char errorcodesubcode_str[256];
10553
10554 code_str = bgp_notify_code_str(p->notify.code);
10555 subcode_str = bgp_notify_subcode_str(
10556 p->notify.code, p->notify.subcode);
10557
10558 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10559 p->notify.code, p->notify.subcode);
10560 json_object_string_add(json_neigh,
10561 "lastErrorCodeSubcode",
10562 errorcodesubcode_hexstr);
10563 snprintf(errorcodesubcode_str, 255, "%s%s",
10564 code_str, subcode_str);
10565 json_object_string_add(json_neigh,
10566 "lastNotificationReason",
10567 errorcodesubcode_str);
10568 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10569 && p->notify.code == BGP_NOTIFY_CEASE
10570 && (p->notify.subcode
10571 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10572 || p->notify.subcode
10573 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10574 && p->notify.length) {
10575 char msgbuf[1024];
10576 const char *msg_str;
10577
10578 msg_str = bgp_notify_admin_message(
10579 msgbuf, sizeof(msgbuf),
10580 (uint8_t *)p->notify.data,
10581 p->notify.length);
10582 if (msg_str)
10583 json_object_string_add(
10584 json_neigh,
10585 "lastShutdownDescription",
10586 msg_str);
10587 }
10588 }
10589 } else {
10590 vty_out(vty, " Last reset %s, ",
10591 peer_uptime(p->resettime, timebuf,
10592 BGP_UPTIME_LEN, 0, NULL));
10593
10594 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10595 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10596 code_str = bgp_notify_code_str(p->notify.code);
10597 subcode_str = bgp_notify_subcode_str(
10598 p->notify.code, p->notify.subcode);
10599 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10600 p->last_reset == PEER_DOWN_NOTIFY_SEND
10601 ? "sent"
10602 : "received",
10603 code_str, subcode_str);
10604 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10605 && p->notify.code == BGP_NOTIFY_CEASE
10606 && (p->notify.subcode
10607 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10608 || p->notify.subcode
10609 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10610 && p->notify.length) {
10611 char msgbuf[1024];
10612 const char *msg_str;
10613
10614 msg_str = bgp_notify_admin_message(
10615 msgbuf, sizeof(msgbuf),
10616 (uint8_t *)p->notify.data,
10617 p->notify.length);
10618 if (msg_str)
10619 vty_out(vty,
10620 " Message: \"%s\"\n",
10621 msg_str);
10622 }
10623 } else {
10624 vty_out(vty, "due to %s\n",
10625 peer_down_str[(int)p->last_reset]);
10626 }
10627
10628 if (p->last_reset_cause_size) {
10629 msg = p->last_reset_cause;
10630 vty_out(vty,
10631 " Message received that caused BGP to send a NOTIFICATION:\n ");
10632 for (i = 1; i <= p->last_reset_cause_size;
10633 i++) {
10634 vty_out(vty, "%02X", *msg++);
10635
10636 if (i != p->last_reset_cause_size) {
10637 if (i % 16 == 0) {
10638 vty_out(vty, "\n ");
10639 } else if (i % 4 == 0) {
10640 vty_out(vty, " ");
10641 }
10642 }
10643 }
10644 vty_out(vty, "\n");
10645 }
10646 }
10647 }
10648
10649 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10650 if (use_json)
10651 json_object_boolean_true_add(json_neigh,
10652 "prefixesConfigExceedMax");
10653 else
10654 vty_out(vty,
10655 " Peer had exceeded the max. no. of prefixes configured.\n");
10656
10657 if (p->t_pmax_restart) {
10658 if (use_json) {
10659 json_object_boolean_true_add(
10660 json_neigh, "reducePrefixNumFrom");
10661 json_object_int_add(json_neigh,
10662 "restartInTimerMsec",
10663 thread_timer_remain_second(
10664 p->t_pmax_restart)
10665 * 1000);
10666 } else
10667 vty_out(vty,
10668 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10669 p->host, thread_timer_remain_second(
10670 p->t_pmax_restart));
10671 } else {
10672 if (use_json)
10673 json_object_boolean_true_add(
10674 json_neigh,
10675 "reducePrefixNumAndClearIpBgp");
10676 else
10677 vty_out(vty,
10678 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10679 p->host);
10680 }
10681 }
10682
10683 /* EBGP Multihop and GTSM */
10684 if (p->sort != BGP_PEER_IBGP) {
10685 if (use_json) {
10686 if (p->gtsm_hops > 0)
10687 json_object_int_add(json_neigh,
10688 "externalBgpNbrMaxHopsAway",
10689 p->gtsm_hops);
10690 else if (p->ttl > 1)
10691 json_object_int_add(json_neigh,
10692 "externalBgpNbrMaxHopsAway",
10693 p->ttl);
10694 } else {
10695 if (p->gtsm_hops > 0)
10696 vty_out(vty,
10697 " External BGP neighbor may be up to %d hops away.\n",
10698 p->gtsm_hops);
10699 else if (p->ttl > 1)
10700 vty_out(vty,
10701 " External BGP neighbor may be up to %d hops away.\n",
10702 p->ttl);
10703 }
10704 } else {
10705 if (p->gtsm_hops > 0) {
10706 if (use_json)
10707 json_object_int_add(json_neigh,
10708 "internalBgpNbrMaxHopsAway",
10709 p->gtsm_hops);
10710 else
10711 vty_out(vty,
10712 " Internal BGP neighbor may be up to %d hops away.\n",
10713 p->gtsm_hops);
10714 }
10715 }
10716
10717 /* Local address. */
10718 if (p->su_local) {
10719 if (use_json) {
10720 json_object_string_add(json_neigh, "hostLocal",
10721 sockunion2str(p->su_local, buf1,
10722 SU_ADDRSTRLEN));
10723 json_object_int_add(json_neigh, "portLocal",
10724 ntohs(p->su_local->sin.sin_port));
10725 } else
10726 vty_out(vty, "Local host: %s, Local port: %d\n",
10727 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10728 ntohs(p->su_local->sin.sin_port));
10729 }
10730
10731 /* Remote address. */
10732 if (p->su_remote) {
10733 if (use_json) {
10734 json_object_string_add(json_neigh, "hostForeign",
10735 sockunion2str(p->su_remote, buf1,
10736 SU_ADDRSTRLEN));
10737 json_object_int_add(json_neigh, "portForeign",
10738 ntohs(p->su_remote->sin.sin_port));
10739 } else
10740 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10741 sockunion2str(p->su_remote, buf1,
10742 SU_ADDRSTRLEN),
10743 ntohs(p->su_remote->sin.sin_port));
10744 }
10745
10746 /* Nexthop display. */
10747 if (p->su_local) {
10748 if (use_json) {
10749 json_object_string_add(json_neigh, "nexthop",
10750 inet_ntop(AF_INET,
10751 &p->nexthop.v4, buf1,
10752 sizeof(buf1)));
10753 json_object_string_add(json_neigh, "nexthopGlobal",
10754 inet_ntop(AF_INET6,
10755 &p->nexthop.v6_global,
10756 buf1, sizeof(buf1)));
10757 json_object_string_add(json_neigh, "nexthopLocal",
10758 inet_ntop(AF_INET6,
10759 &p->nexthop.v6_local,
10760 buf1, sizeof(buf1)));
10761 if (p->shared_network)
10762 json_object_string_add(json_neigh,
10763 "bgpConnection",
10764 "sharedNetwork");
10765 else
10766 json_object_string_add(json_neigh,
10767 "bgpConnection",
10768 "nonSharedNetwork");
10769 } else {
10770 vty_out(vty, "Nexthop: %s\n",
10771 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10772 sizeof(buf1)));
10773 vty_out(vty, "Nexthop global: %s\n",
10774 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10775 sizeof(buf1)));
10776 vty_out(vty, "Nexthop local: %s\n",
10777 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10778 sizeof(buf1)));
10779 vty_out(vty, "BGP connection: %s\n",
10780 p->shared_network ? "shared network"
10781 : "non shared network");
10782 }
10783 }
10784
10785 /* Timer information. */
10786 if (use_json) {
10787 json_object_int_add(json_neigh, "connectRetryTimer",
10788 p->v_connect);
10789 if (p->status == Established && p->rtt)
10790 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10791 p->rtt);
10792 if (p->t_start)
10793 json_object_int_add(
10794 json_neigh, "nextStartTimerDueInMsecs",
10795 thread_timer_remain_second(p->t_start) * 1000);
10796 if (p->t_connect)
10797 json_object_int_add(
10798 json_neigh, "nextConnectTimerDueInMsecs",
10799 thread_timer_remain_second(p->t_connect)
10800 * 1000);
10801 if (p->t_routeadv) {
10802 json_object_int_add(json_neigh, "mraiInterval",
10803 p->v_routeadv);
10804 json_object_int_add(
10805 json_neigh, "mraiTimerExpireInMsecs",
10806 thread_timer_remain_second(p->t_routeadv)
10807 * 1000);
10808 }
10809 if (p->password)
10810 json_object_int_add(json_neigh, "authenticationEnabled",
10811 1);
10812
10813 if (p->t_read)
10814 json_object_string_add(json_neigh, "readThread", "on");
10815 else
10816 json_object_string_add(json_neigh, "readThread", "off");
10817
10818 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10819 json_object_string_add(json_neigh, "writeThread", "on");
10820 else
10821 json_object_string_add(json_neigh, "writeThread",
10822 "off");
10823 } else {
10824 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10825 p->v_connect);
10826 if (p->status == Established && p->rtt)
10827 vty_out(vty, "Estimated round trip time: %d ms\n",
10828 p->rtt);
10829 if (p->t_start)
10830 vty_out(vty, "Next start timer due in %ld seconds\n",
10831 thread_timer_remain_second(p->t_start));
10832 if (p->t_connect)
10833 vty_out(vty, "Next connect timer due in %ld seconds\n",
10834 thread_timer_remain_second(p->t_connect));
10835 if (p->t_routeadv)
10836 vty_out(vty,
10837 "MRAI (interval %u) timer expires in %ld seconds\n",
10838 p->v_routeadv,
10839 thread_timer_remain_second(p->t_routeadv));
10840 if (p->password)
10841 vty_out(vty, "Peer Authentication Enabled\n");
10842
10843 vty_out(vty, "Read thread: %s Write thread: %s\n",
10844 p->t_read ? "on" : "off",
10845 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10846 ? "on"
10847 : "off");
10848 }
10849
10850 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10851 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10852 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10853
10854 if (!use_json)
10855 vty_out(vty, "\n");
10856
10857 /* BFD information. */
10858 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10859
10860 if (use_json) {
10861 if (p->conf_if) /* Configured interface name. */
10862 json_object_object_add(json, p->conf_if, json_neigh);
10863 else /* Configured IP address. */
10864 json_object_object_add(json, p->host, json_neigh);
10865 }
10866 }
10867
10868 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10869 enum show_type type, union sockunion *su,
10870 const char *conf_if, bool use_json,
10871 json_object *json)
10872 {
10873 struct listnode *node, *nnode;
10874 struct peer *peer;
10875 int find = 0;
10876 bool nbr_output = false;
10877
10878 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10879 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10880 continue;
10881
10882 switch (type) {
10883 case show_all:
10884 bgp_show_peer(vty, peer, use_json, json);
10885 nbr_output = true;
10886 break;
10887 case show_peer:
10888 if (conf_if) {
10889 if ((peer->conf_if
10890 && !strcmp(peer->conf_if, conf_if))
10891 || (peer->hostname
10892 && !strcmp(peer->hostname, conf_if))) {
10893 find = 1;
10894 bgp_show_peer(vty, peer, use_json,
10895 json);
10896 }
10897 } else {
10898 if (sockunion_same(&peer->su, su)) {
10899 find = 1;
10900 bgp_show_peer(vty, peer, use_json,
10901 json);
10902 }
10903 }
10904 break;
10905 }
10906 }
10907
10908 if (type == show_peer && !find) {
10909 if (use_json)
10910 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10911 else
10912 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10913 }
10914
10915 if (type != show_peer && !nbr_output && !use_json)
10916 vty_out(vty, "%% No BGP neighbors found\n");
10917
10918 if (use_json) {
10919 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10920 json, JSON_C_TO_STRING_PRETTY));
10921 } else {
10922 vty_out(vty, "\n");
10923 }
10924
10925 return CMD_SUCCESS;
10926 }
10927
10928 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10929 enum show_type type,
10930 const char *ip_str,
10931 bool use_json)
10932 {
10933 struct listnode *node, *nnode;
10934 struct bgp *bgp;
10935 union sockunion su;
10936 json_object *json = NULL;
10937 int ret, is_first = 1;
10938 bool nbr_output = false;
10939
10940 if (use_json)
10941 vty_out(vty, "{\n");
10942
10943 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10944 nbr_output = true;
10945 if (use_json) {
10946 if (!(json = json_object_new_object())) {
10947 flog_err(
10948 EC_BGP_JSON_MEM_ERROR,
10949 "Unable to allocate memory for JSON object");
10950 vty_out(vty,
10951 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10952 return;
10953 }
10954
10955 json_object_int_add(json, "vrfId",
10956 (bgp->vrf_id == VRF_UNKNOWN)
10957 ? -1
10958 : (int64_t)bgp->vrf_id);
10959 json_object_string_add(
10960 json, "vrfName",
10961 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10962 ? VRF_DEFAULT_NAME
10963 : bgp->name);
10964
10965 if (!is_first)
10966 vty_out(vty, ",\n");
10967 else
10968 is_first = 0;
10969
10970 vty_out(vty, "\"%s\":",
10971 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10972 ? VRF_DEFAULT_NAME
10973 : bgp->name);
10974 } else {
10975 vty_out(vty, "\nInstance %s:\n",
10976 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10977 ? VRF_DEFAULT_NAME
10978 : bgp->name);
10979 }
10980
10981 if (type == show_peer) {
10982 ret = str2sockunion(ip_str, &su);
10983 if (ret < 0)
10984 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10985 use_json, json);
10986 else
10987 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10988 use_json, json);
10989 } else {
10990 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10991 use_json, json);
10992 }
10993 }
10994
10995 if (use_json) {
10996 vty_out(vty, "}\n");
10997 json_object_free(json);
10998 }
10999 else if (!nbr_output)
11000 vty_out(vty, "%% BGP instance not found\n");
11001 }
11002
11003 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11004 enum show_type type, const char *ip_str,
11005 bool use_json)
11006 {
11007 int ret;
11008 struct bgp *bgp;
11009 union sockunion su;
11010 json_object *json = NULL;
11011
11012 if (name) {
11013 if (strmatch(name, "all")) {
11014 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11015 use_json);
11016 return CMD_SUCCESS;
11017 } else {
11018 bgp = bgp_lookup_by_name(name);
11019 if (!bgp) {
11020 if (use_json) {
11021 json = json_object_new_object();
11022 vty_out(vty, "%s\n",
11023 json_object_to_json_string_ext(
11024 json,
11025 JSON_C_TO_STRING_PRETTY));
11026 json_object_free(json);
11027 } else
11028 vty_out(vty,
11029 "%% BGP instance not found\n");
11030
11031 return CMD_WARNING;
11032 }
11033 }
11034 } else {
11035 bgp = bgp_get_default();
11036 }
11037
11038 if (bgp) {
11039 json = json_object_new_object();
11040 if (ip_str) {
11041 ret = str2sockunion(ip_str, &su);
11042 if (ret < 0)
11043 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11044 use_json, json);
11045 else
11046 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11047 use_json, json);
11048 } else {
11049 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11050 json);
11051 }
11052 json_object_free(json);
11053 } else {
11054 if (use_json)
11055 vty_out(vty, "{}\n");
11056 else
11057 vty_out(vty, "%% BGP instance not found\n");
11058 }
11059
11060 return CMD_SUCCESS;
11061 }
11062
11063 /* "show [ip] bgp neighbors" commands. */
11064 DEFUN (show_ip_bgp_neighbors,
11065 show_ip_bgp_neighbors_cmd,
11066 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11067 SHOW_STR
11068 IP_STR
11069 BGP_STR
11070 BGP_INSTANCE_HELP_STR
11071 "Address Family\n"
11072 "Address Family\n"
11073 "Detailed information on TCP and BGP neighbor connections\n"
11074 "Neighbor to display information about\n"
11075 "Neighbor to display information about\n"
11076 "Neighbor on BGP configured interface\n"
11077 JSON_STR)
11078 {
11079 char *vrf = NULL;
11080 char *sh_arg = NULL;
11081 enum show_type sh_type;
11082
11083 bool uj = use_json(argc, argv);
11084
11085 int idx = 0;
11086
11087 /* [<vrf> VIEWVRFNAME] */
11088 if (argv_find(argv, argc, "vrf", &idx)) {
11089 vrf = argv[idx + 1]->arg;
11090 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11091 vrf = NULL;
11092 } else if (argv_find(argv, argc, "view", &idx))
11093 /* [<view> VIEWVRFNAME] */
11094 vrf = argv[idx + 1]->arg;
11095
11096 idx++;
11097 if (argv_find(argv, argc, "A.B.C.D", &idx)
11098 || argv_find(argv, argc, "X:X::X:X", &idx)
11099 || argv_find(argv, argc, "WORD", &idx)) {
11100 sh_type = show_peer;
11101 sh_arg = argv[idx]->arg;
11102 } else
11103 sh_type = show_all;
11104
11105 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11106 }
11107
11108 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11109 paths' and `show ip mbgp paths'. Those functions results are the
11110 same.*/
11111 DEFUN (show_ip_bgp_paths,
11112 show_ip_bgp_paths_cmd,
11113 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11114 SHOW_STR
11115 IP_STR
11116 BGP_STR
11117 BGP_SAFI_HELP_STR
11118 "Path information\n")
11119 {
11120 vty_out(vty, "Address Refcnt Path\n");
11121 aspath_print_all_vty(vty);
11122 return CMD_SUCCESS;
11123 }
11124
11125 #include "hash.h"
11126
11127 static void community_show_all_iterator(struct hash_backet *backet,
11128 struct vty *vty)
11129 {
11130 struct community *com;
11131
11132 com = (struct community *)backet->data;
11133 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11134 community_str(com, false));
11135 }
11136
11137 /* Show BGP's community internal data. */
11138 DEFUN (show_ip_bgp_community_info,
11139 show_ip_bgp_community_info_cmd,
11140 "show [ip] bgp community-info",
11141 SHOW_STR
11142 IP_STR
11143 BGP_STR
11144 "List all bgp community information\n")
11145 {
11146 vty_out(vty, "Address Refcnt Community\n");
11147
11148 hash_iterate(community_hash(),
11149 (void (*)(struct hash_backet *,
11150 void *))community_show_all_iterator,
11151 vty);
11152
11153 return CMD_SUCCESS;
11154 }
11155
11156 static void lcommunity_show_all_iterator(struct hash_backet *backet,
11157 struct vty *vty)
11158 {
11159 struct lcommunity *lcom;
11160
11161 lcom = (struct lcommunity *)backet->data;
11162 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11163 lcommunity_str(lcom, false));
11164 }
11165
11166 /* Show BGP's community internal data. */
11167 DEFUN (show_ip_bgp_lcommunity_info,
11168 show_ip_bgp_lcommunity_info_cmd,
11169 "show ip bgp large-community-info",
11170 SHOW_STR
11171 IP_STR
11172 BGP_STR
11173 "List all bgp large-community information\n")
11174 {
11175 vty_out(vty, "Address Refcnt Large-community\n");
11176
11177 hash_iterate(lcommunity_hash(),
11178 (void (*)(struct hash_backet *,
11179 void *))lcommunity_show_all_iterator,
11180 vty);
11181
11182 return CMD_SUCCESS;
11183 }
11184
11185
11186 DEFUN (show_ip_bgp_attr_info,
11187 show_ip_bgp_attr_info_cmd,
11188 "show [ip] bgp attribute-info",
11189 SHOW_STR
11190 IP_STR
11191 BGP_STR
11192 "List all bgp attribute information\n")
11193 {
11194 attr_show_all(vty);
11195 return CMD_SUCCESS;
11196 }
11197
11198 static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11199 safi_t safi, bool use_json)
11200 {
11201 struct bgp *bgp;
11202 struct listnode *node;
11203 char *vname;
11204 char buf1[INET6_ADDRSTRLEN];
11205 char *ecom_str;
11206 vpn_policy_direction_t dir;
11207
11208 if (use_json) {
11209 json_object *json = NULL;
11210 json_object *json_import_vrfs = NULL;
11211 json_object *json_export_vrfs = NULL;
11212
11213 json = json_object_new_object();
11214
11215 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11216
11217 if (!bgp) {
11218 vty_out(vty, "%s\n",
11219 json_object_to_json_string_ext(
11220 json,
11221 JSON_C_TO_STRING_PRETTY));
11222 json_object_free(json);
11223
11224 return CMD_WARNING;
11225 }
11226
11227 /* Provide context for the block */
11228 json_object_string_add(json, "vrf", name ? name : "default");
11229 json_object_string_add(json, "afiSafi",
11230 afi_safi_print(afi, safi));
11231
11232 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11233 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11234 json_object_string_add(json, "importFromVrfs", "none");
11235 json_object_string_add(json, "importRts", "none");
11236 } else {
11237 json_import_vrfs = json_object_new_array();
11238
11239 for (ALL_LIST_ELEMENTS_RO(
11240 bgp->vpn_policy[afi].import_vrf,
11241 node, vname))
11242 json_object_array_add(json_import_vrfs,
11243 json_object_new_string(vname));
11244
11245 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11246 ecom_str = ecommunity_ecom2str(
11247 bgp->vpn_policy[afi].rtlist[dir],
11248 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11249 json_object_object_add(json, "importFromVrfs",
11250 json_import_vrfs);
11251 json_object_string_add(json, "importRts", ecom_str);
11252
11253 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11254 }
11255
11256 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11257 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11258 json_object_string_add(json, "exportToVrfs", "none");
11259 json_object_string_add(json, "routeDistinguisher",
11260 "none");
11261 json_object_string_add(json, "exportRts", "none");
11262 } else {
11263 json_export_vrfs = json_object_new_array();
11264
11265 for (ALL_LIST_ELEMENTS_RO(
11266 bgp->vpn_policy[afi].export_vrf,
11267 node, vname))
11268 json_object_array_add(json_export_vrfs,
11269 json_object_new_string(vname));
11270 json_object_object_add(json, "exportToVrfs",
11271 json_export_vrfs);
11272 json_object_string_add(json, "routeDistinguisher",
11273 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11274 buf1, RD_ADDRSTRLEN));
11275
11276 dir = BGP_VPN_POLICY_DIR_TOVPN;
11277 ecom_str = ecommunity_ecom2str(
11278 bgp->vpn_policy[afi].rtlist[dir],
11279 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11280 json_object_string_add(json, "exportRts", ecom_str);
11281
11282 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11283 }
11284
11285 vty_out(vty, "%s\n",
11286 json_object_to_json_string_ext(json,
11287 JSON_C_TO_STRING_PRETTY));
11288 json_object_free(json);
11289
11290 } else {
11291 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11292
11293 if (!bgp) {
11294 vty_out(vty, "%% No such BGP instance exist\n");
11295 return CMD_WARNING;
11296 }
11297
11298 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11299 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11300 vty_out(vty,
11301 "This VRF is not importing %s routes from any other VRF\n",
11302 afi_safi_print(afi, safi));
11303 else {
11304 vty_out(vty,
11305 "This VRF is importing %s routes from the following VRFs:\n",
11306 afi_safi_print(afi, safi));
11307
11308 for (ALL_LIST_ELEMENTS_RO(
11309 bgp->vpn_policy[afi].import_vrf,
11310 node, vname))
11311 vty_out(vty, " %s\n", vname);
11312
11313 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11314 ecom_str = ecommunity_ecom2str(
11315 bgp->vpn_policy[afi].rtlist[dir],
11316 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11317 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11318
11319 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11320 }
11321
11322 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11323 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11324 vty_out(vty,
11325 "This VRF is not exporting %s routes to any other VRF\n",
11326 afi_safi_print(afi, safi));
11327 else {
11328 vty_out(vty,
11329 "This VRF is exporting %s routes to the following VRFs:\n",
11330 afi_safi_print(afi, safi));
11331
11332 for (ALL_LIST_ELEMENTS_RO(
11333 bgp->vpn_policy[afi].export_vrf,
11334 node, vname))
11335 vty_out(vty, " %s\n", vname);
11336
11337 vty_out(vty, "RD: %s\n",
11338 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11339 buf1, RD_ADDRSTRLEN));
11340
11341 dir = BGP_VPN_POLICY_DIR_TOVPN;
11342 ecom_str = ecommunity_ecom2str(
11343 bgp->vpn_policy[afi].rtlist[dir],
11344 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11345 vty_out(vty, "Export RT: %s\n", ecom_str);
11346 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11347 }
11348 }
11349
11350 return CMD_SUCCESS;
11351 }
11352
11353 /* "show [ip] bgp route-leak" command. */
11354 DEFUN (show_ip_bgp_route_leak,
11355 show_ip_bgp_route_leak_cmd,
11356 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11357 SHOW_STR
11358 IP_STR
11359 BGP_STR
11360 BGP_INSTANCE_HELP_STR
11361 BGP_AFI_HELP_STR
11362 BGP_SAFI_HELP_STR
11363 "Route leaking information\n"
11364 JSON_STR)
11365 {
11366 char *vrf = NULL;
11367 afi_t afi = AFI_MAX;
11368 safi_t safi = SAFI_MAX;
11369
11370 bool uj = use_json(argc, argv);
11371 int idx = 0;
11372
11373 /* show [ip] bgp */
11374 if (argv_find(argv, argc, "ip", &idx)) {
11375 afi = AFI_IP;
11376 safi = SAFI_UNICAST;
11377 }
11378 /* [vrf VIEWVRFNAME] */
11379 if (argv_find(argv, argc, "view", &idx)) {
11380 vty_out(vty,
11381 "%% This command is not applicable to BGP views\n");
11382 return CMD_WARNING;
11383 }
11384
11385 if (argv_find(argv, argc, "vrf", &idx)) {
11386 vrf = argv[idx + 1]->arg;
11387 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11388 vrf = NULL;
11389 }
11390 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11391 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11392 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11393 }
11394
11395 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11396 vty_out(vty,
11397 "%% This command is applicable only for unicast ipv4|ipv6\n");
11398 return CMD_WARNING;
11399 }
11400
11401 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
11402 }
11403
11404 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11405 safi_t safi)
11406 {
11407 struct listnode *node, *nnode;
11408 struct bgp *bgp;
11409
11410 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11411 vty_out(vty, "\nInstance %s:\n",
11412 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11413 ? VRF_DEFAULT_NAME
11414 : bgp->name);
11415 update_group_show(bgp, afi, safi, vty, 0);
11416 }
11417 }
11418
11419 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11420 int safi, uint64_t subgrp_id)
11421 {
11422 struct bgp *bgp;
11423
11424 if (name) {
11425 if (strmatch(name, "all")) {
11426 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11427 return CMD_SUCCESS;
11428 } else {
11429 bgp = bgp_lookup_by_name(name);
11430 }
11431 } else {
11432 bgp = bgp_get_default();
11433 }
11434
11435 if (bgp)
11436 update_group_show(bgp, afi, safi, vty, subgrp_id);
11437 return CMD_SUCCESS;
11438 }
11439
11440 DEFUN (show_ip_bgp_updgrps,
11441 show_ip_bgp_updgrps_cmd,
11442 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11443 SHOW_STR
11444 IP_STR
11445 BGP_STR
11446 BGP_INSTANCE_HELP_STR
11447 BGP_AFI_HELP_STR
11448 BGP_SAFI_WITH_LABEL_HELP_STR
11449 "Detailed info about dynamic update groups\n"
11450 "Specific subgroup to display detailed info for\n")
11451 {
11452 char *vrf = NULL;
11453 afi_t afi = AFI_IP6;
11454 safi_t safi = SAFI_UNICAST;
11455 uint64_t subgrp_id = 0;
11456
11457 int idx = 0;
11458
11459 /* show [ip] bgp */
11460 if (argv_find(argv, argc, "ip", &idx))
11461 afi = AFI_IP;
11462 /* [<vrf> VIEWVRFNAME] */
11463 if (argv_find(argv, argc, "vrf", &idx)) {
11464 vrf = argv[idx + 1]->arg;
11465 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11466 vrf = NULL;
11467 } else if (argv_find(argv, argc, "view", &idx))
11468 /* [<view> VIEWVRFNAME] */
11469 vrf = argv[idx + 1]->arg;
11470 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11471 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11472 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11473 }
11474
11475 /* get subgroup id, if provided */
11476 idx = argc - 1;
11477 if (argv[idx]->type == VARIABLE_TKN)
11478 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11479
11480 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11481 }
11482
11483 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11484 show_bgp_instance_all_ipv6_updgrps_cmd,
11485 "show [ip] bgp <view|vrf> all update-groups",
11486 SHOW_STR
11487 IP_STR
11488 BGP_STR
11489 BGP_INSTANCE_ALL_HELP_STR
11490 "Detailed info about dynamic update groups\n")
11491 {
11492 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11493 return CMD_SUCCESS;
11494 }
11495
11496 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11497 show_bgp_l2vpn_evpn_updgrps_cmd,
11498 "show [ip] bgp l2vpn evpn update-groups",
11499 SHOW_STR
11500 IP_STR
11501 BGP_STR
11502 "l2vpn address family\n"
11503 "evpn sub-address family\n"
11504 "Detailed info about dynamic update groups\n")
11505 {
11506 char *vrf = NULL;
11507 uint64_t subgrp_id = 0;
11508
11509 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11510 return CMD_SUCCESS;
11511 }
11512
11513 DEFUN (show_bgp_updgrps_stats,
11514 show_bgp_updgrps_stats_cmd,
11515 "show [ip] bgp update-groups statistics",
11516 SHOW_STR
11517 IP_STR
11518 BGP_STR
11519 "Detailed info about dynamic update groups\n"
11520 "Statistics\n")
11521 {
11522 struct bgp *bgp;
11523
11524 bgp = bgp_get_default();
11525 if (bgp)
11526 update_group_show_stats(bgp, vty);
11527
11528 return CMD_SUCCESS;
11529 }
11530
11531 DEFUN (show_bgp_instance_updgrps_stats,
11532 show_bgp_instance_updgrps_stats_cmd,
11533 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11534 SHOW_STR
11535 IP_STR
11536 BGP_STR
11537 BGP_INSTANCE_HELP_STR
11538 "Detailed info about dynamic update groups\n"
11539 "Statistics\n")
11540 {
11541 int idx_word = 3;
11542 struct bgp *bgp;
11543
11544 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11545 if (bgp)
11546 update_group_show_stats(bgp, vty);
11547
11548 return CMD_SUCCESS;
11549 }
11550
11551 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11552 afi_t afi, safi_t safi,
11553 const char *what, uint64_t subgrp_id)
11554 {
11555 struct bgp *bgp;
11556
11557 if (name)
11558 bgp = bgp_lookup_by_name(name);
11559 else
11560 bgp = bgp_get_default();
11561
11562 if (bgp) {
11563 if (!strcmp(what, "advertise-queue"))
11564 update_group_show_adj_queue(bgp, afi, safi, vty,
11565 subgrp_id);
11566 else if (!strcmp(what, "advertised-routes"))
11567 update_group_show_advertised(bgp, afi, safi, vty,
11568 subgrp_id);
11569 else if (!strcmp(what, "packet-queue"))
11570 update_group_show_packet_queue(bgp, afi, safi, vty,
11571 subgrp_id);
11572 }
11573 }
11574
11575 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11576 show_ip_bgp_instance_updgrps_adj_s_cmd,
11577 "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",
11578 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11579 BGP_SAFI_HELP_STR
11580 "Detailed info about dynamic update groups\n"
11581 "Specific subgroup to display info for\n"
11582 "Advertisement queue\n"
11583 "Announced routes\n"
11584 "Packet queue\n")
11585 {
11586 uint64_t subgrp_id = 0;
11587 afi_t afiz;
11588 safi_t safiz;
11589 if (sgid)
11590 subgrp_id = strtoull(sgid, NULL, 10);
11591
11592 if (!ip && !afi)
11593 afiz = AFI_IP6;
11594 if (!ip && afi)
11595 afiz = bgp_vty_afi_from_str(afi);
11596 if (ip && !afi)
11597 afiz = AFI_IP;
11598 if (ip && afi) {
11599 afiz = bgp_vty_afi_from_str(afi);
11600 if (afiz != AFI_IP)
11601 vty_out(vty,
11602 "%% Cannot specify both 'ip' and 'ipv6'\n");
11603 return CMD_WARNING;
11604 }
11605
11606 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11607
11608 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11609 return CMD_SUCCESS;
11610 }
11611
11612 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11613 {
11614 struct listnode *node, *nnode;
11615 struct prefix *range;
11616 struct peer *conf;
11617 struct peer *peer;
11618 char buf[PREFIX2STR_BUFFER];
11619 afi_t afi;
11620 safi_t safi;
11621 const char *peer_status;
11622 const char *af_str;
11623 int lr_count;
11624 int dynamic;
11625 int af_cfgd;
11626
11627 conf = group->conf;
11628
11629 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11630 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11631 conf->as);
11632 } else if (conf->as_type == AS_INTERNAL) {
11633 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11634 group->bgp->as);
11635 } else {
11636 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11637 }
11638
11639 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11640 vty_out(vty, " Peer-group type is internal\n");
11641 else
11642 vty_out(vty, " Peer-group type is external\n");
11643
11644 /* Display AFs configured. */
11645 vty_out(vty, " Configured address-families:");
11646 FOREACH_AFI_SAFI (afi, safi) {
11647 if (conf->afc[afi][safi]) {
11648 af_cfgd = 1;
11649 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11650 }
11651 }
11652 if (!af_cfgd)
11653 vty_out(vty, " none\n");
11654 else
11655 vty_out(vty, "\n");
11656
11657 /* Display listen ranges (for dynamic neighbors), if any */
11658 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11659 if (afi == AFI_IP)
11660 af_str = "IPv4";
11661 else if (afi == AFI_IP6)
11662 af_str = "IPv6";
11663 else
11664 af_str = "???";
11665 lr_count = listcount(group->listen_range[afi]);
11666 if (lr_count) {
11667 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11668 af_str);
11669
11670
11671 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11672 nnode, range)) {
11673 prefix2str(range, buf, sizeof(buf));
11674 vty_out(vty, " %s\n", buf);
11675 }
11676 }
11677 }
11678
11679 /* Display group members and their status */
11680 if (listcount(group->peer)) {
11681 vty_out(vty, " Peer-group members:\n");
11682 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11683 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11684 peer_status = "Idle (Admin)";
11685 else if (CHECK_FLAG(peer->sflags,
11686 PEER_STATUS_PREFIX_OVERFLOW))
11687 peer_status = "Idle (PfxCt)";
11688 else
11689 peer_status = lookup_msg(bgp_status_msg,
11690 peer->status, NULL);
11691
11692 dynamic = peer_dynamic_neighbor(peer);
11693 vty_out(vty, " %s %s %s \n", peer->host,
11694 dynamic ? "(dynamic)" : "", peer_status);
11695 }
11696 }
11697
11698 return CMD_SUCCESS;
11699 }
11700
11701 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11702 const char *group_name)
11703 {
11704 struct bgp *bgp;
11705 struct listnode *node, *nnode;
11706 struct peer_group *group;
11707 bool found = false;
11708
11709 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11710
11711 if (!bgp) {
11712 vty_out(vty, "%% BGP instance not found\n");
11713 return CMD_WARNING;
11714 }
11715
11716 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11717 if (group_name) {
11718 if (strmatch(group->name, group_name)) {
11719 bgp_show_one_peer_group(vty, group);
11720 found = true;
11721 break;
11722 }
11723 } else {
11724 bgp_show_one_peer_group(vty, group);
11725 }
11726 }
11727
11728 if (group_name && !found)
11729 vty_out(vty, "%% No such peer-group\n");
11730
11731 return CMD_SUCCESS;
11732 }
11733
11734 DEFUN (show_ip_bgp_peer_groups,
11735 show_ip_bgp_peer_groups_cmd,
11736 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11737 SHOW_STR
11738 IP_STR
11739 BGP_STR
11740 BGP_INSTANCE_HELP_STR
11741 "Detailed information on BGP peer groups\n"
11742 "Peer group name\n")
11743 {
11744 char *vrf, *pg;
11745 int idx = 0;
11746
11747 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11748 : NULL;
11749 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11750
11751 return bgp_show_peer_group_vty(vty, vrf, pg);
11752 }
11753
11754
11755 /* Redistribute VTY commands. */
11756
11757 DEFUN (bgp_redistribute_ipv4,
11758 bgp_redistribute_ipv4_cmd,
11759 "redistribute " FRR_IP_REDIST_STR_BGPD,
11760 "Redistribute information from another routing protocol\n"
11761 FRR_IP_REDIST_HELP_STR_BGPD)
11762 {
11763 VTY_DECLVAR_CONTEXT(bgp, bgp);
11764 int idx_protocol = 1;
11765 int type;
11766
11767 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11768 if (type < 0) {
11769 vty_out(vty, "%% Invalid route type\n");
11770 return CMD_WARNING_CONFIG_FAILED;
11771 }
11772
11773 bgp_redist_add(bgp, AFI_IP, type, 0);
11774 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11775 }
11776
11777 ALIAS_HIDDEN(
11778 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11779 "redistribute " FRR_IP_REDIST_STR_BGPD,
11780 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11781
11782 DEFUN (bgp_redistribute_ipv4_rmap,
11783 bgp_redistribute_ipv4_rmap_cmd,
11784 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11785 "Redistribute information from another routing protocol\n"
11786 FRR_IP_REDIST_HELP_STR_BGPD
11787 "Route map reference\n"
11788 "Pointer to route-map entries\n")
11789 {
11790 VTY_DECLVAR_CONTEXT(bgp, bgp);
11791 int idx_protocol = 1;
11792 int idx_word = 3;
11793 int type;
11794 struct bgp_redist *red;
11795 bool changed;
11796 struct route_map *route_map = route_map_lookup_warn_noexist(
11797 vty, argv[idx_word]->arg);
11798
11799 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11800 if (type < 0) {
11801 vty_out(vty, "%% Invalid route type\n");
11802 return CMD_WARNING_CONFIG_FAILED;
11803 }
11804
11805 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11806 changed =
11807 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11808 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11809 }
11810
11811 ALIAS_HIDDEN(
11812 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11813 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11814 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11815 "Route map reference\n"
11816 "Pointer to route-map entries\n")
11817
11818 DEFUN (bgp_redistribute_ipv4_metric,
11819 bgp_redistribute_ipv4_metric_cmd,
11820 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11821 "Redistribute information from another routing protocol\n"
11822 FRR_IP_REDIST_HELP_STR_BGPD
11823 "Metric for redistributed routes\n"
11824 "Default metric\n")
11825 {
11826 VTY_DECLVAR_CONTEXT(bgp, bgp);
11827 int idx_protocol = 1;
11828 int idx_number = 3;
11829 int type;
11830 uint32_t metric;
11831 struct bgp_redist *red;
11832 bool changed;
11833
11834 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11835 if (type < 0) {
11836 vty_out(vty, "%% Invalid route type\n");
11837 return CMD_WARNING_CONFIG_FAILED;
11838 }
11839 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11840
11841 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11842 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11843 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11844 }
11845
11846 ALIAS_HIDDEN(
11847 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11848 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11849 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11850 "Metric for redistributed routes\n"
11851 "Default metric\n")
11852
11853 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11854 bgp_redistribute_ipv4_rmap_metric_cmd,
11855 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11856 "Redistribute information from another routing protocol\n"
11857 FRR_IP_REDIST_HELP_STR_BGPD
11858 "Route map reference\n"
11859 "Pointer to route-map entries\n"
11860 "Metric for redistributed routes\n"
11861 "Default metric\n")
11862 {
11863 VTY_DECLVAR_CONTEXT(bgp, bgp);
11864 int idx_protocol = 1;
11865 int idx_word = 3;
11866 int idx_number = 5;
11867 int type;
11868 uint32_t metric;
11869 struct bgp_redist *red;
11870 bool changed;
11871 struct route_map *route_map =
11872 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11873
11874 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11875 if (type < 0) {
11876 vty_out(vty, "%% Invalid route type\n");
11877 return CMD_WARNING_CONFIG_FAILED;
11878 }
11879 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11880
11881 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11882 changed =
11883 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11884 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11885 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11886 }
11887
11888 ALIAS_HIDDEN(
11889 bgp_redistribute_ipv4_rmap_metric,
11890 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11891 "redistribute " FRR_IP_REDIST_STR_BGPD
11892 " route-map WORD metric (0-4294967295)",
11893 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11894 "Route map reference\n"
11895 "Pointer to route-map entries\n"
11896 "Metric for redistributed routes\n"
11897 "Default metric\n")
11898
11899 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11900 bgp_redistribute_ipv4_metric_rmap_cmd,
11901 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11902 "Redistribute information from another routing protocol\n"
11903 FRR_IP_REDIST_HELP_STR_BGPD
11904 "Metric for redistributed routes\n"
11905 "Default metric\n"
11906 "Route map reference\n"
11907 "Pointer to route-map entries\n")
11908 {
11909 VTY_DECLVAR_CONTEXT(bgp, bgp);
11910 int idx_protocol = 1;
11911 int idx_number = 3;
11912 int idx_word = 5;
11913 int type;
11914 uint32_t metric;
11915 struct bgp_redist *red;
11916 bool changed;
11917 struct route_map *route_map =
11918 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11919
11920 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11921 if (type < 0) {
11922 vty_out(vty, "%% Invalid route type\n");
11923 return CMD_WARNING_CONFIG_FAILED;
11924 }
11925 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11926
11927 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11928 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11929 changed |=
11930 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11931 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11932 }
11933
11934 ALIAS_HIDDEN(
11935 bgp_redistribute_ipv4_metric_rmap,
11936 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11937 "redistribute " FRR_IP_REDIST_STR_BGPD
11938 " metric (0-4294967295) route-map WORD",
11939 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11940 "Metric for redistributed routes\n"
11941 "Default metric\n"
11942 "Route map reference\n"
11943 "Pointer to route-map entries\n")
11944
11945 DEFUN (bgp_redistribute_ipv4_ospf,
11946 bgp_redistribute_ipv4_ospf_cmd,
11947 "redistribute <ospf|table> (1-65535)",
11948 "Redistribute information from another routing protocol\n"
11949 "Open Shortest Path First (OSPFv2)\n"
11950 "Non-main Kernel Routing Table\n"
11951 "Instance ID/Table ID\n")
11952 {
11953 VTY_DECLVAR_CONTEXT(bgp, bgp);
11954 int idx_ospf_table = 1;
11955 int idx_number = 2;
11956 unsigned short instance;
11957 unsigned short protocol;
11958
11959 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11960
11961 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11962 protocol = ZEBRA_ROUTE_OSPF;
11963 else
11964 protocol = ZEBRA_ROUTE_TABLE;
11965
11966 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11967 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
11968 }
11969
11970 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11971 "redistribute <ospf|table> (1-65535)",
11972 "Redistribute information from another routing protocol\n"
11973 "Open Shortest Path First (OSPFv2)\n"
11974 "Non-main Kernel Routing Table\n"
11975 "Instance ID/Table ID\n")
11976
11977 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11978 bgp_redistribute_ipv4_ospf_rmap_cmd,
11979 "redistribute <ospf|table> (1-65535) route-map WORD",
11980 "Redistribute information from another routing protocol\n"
11981 "Open Shortest Path First (OSPFv2)\n"
11982 "Non-main Kernel Routing Table\n"
11983 "Instance ID/Table ID\n"
11984 "Route map reference\n"
11985 "Pointer to route-map entries\n")
11986 {
11987 VTY_DECLVAR_CONTEXT(bgp, bgp);
11988 int idx_ospf_table = 1;
11989 int idx_number = 2;
11990 int idx_word = 4;
11991 struct bgp_redist *red;
11992 unsigned short instance;
11993 int protocol;
11994 bool changed;
11995 struct route_map *route_map =
11996 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11997
11998 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11999 protocol = ZEBRA_ROUTE_OSPF;
12000 else
12001 protocol = ZEBRA_ROUTE_TABLE;
12002
12003 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12004 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12005 changed =
12006 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12007 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12008 }
12009
12010 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12011 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12012 "redistribute <ospf|table> (1-65535) route-map WORD",
12013 "Redistribute information from another routing protocol\n"
12014 "Open Shortest Path First (OSPFv2)\n"
12015 "Non-main Kernel Routing Table\n"
12016 "Instance ID/Table ID\n"
12017 "Route map reference\n"
12018 "Pointer to route-map entries\n")
12019
12020 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12021 bgp_redistribute_ipv4_ospf_metric_cmd,
12022 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12023 "Redistribute information from another routing protocol\n"
12024 "Open Shortest Path First (OSPFv2)\n"
12025 "Non-main Kernel Routing Table\n"
12026 "Instance ID/Table ID\n"
12027 "Metric for redistributed routes\n"
12028 "Default metric\n")
12029 {
12030 VTY_DECLVAR_CONTEXT(bgp, bgp);
12031 int idx_ospf_table = 1;
12032 int idx_number = 2;
12033 int idx_number_2 = 4;
12034 uint32_t metric;
12035 struct bgp_redist *red;
12036 unsigned short instance;
12037 int protocol;
12038 bool changed;
12039
12040 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12041 protocol = ZEBRA_ROUTE_OSPF;
12042 else
12043 protocol = ZEBRA_ROUTE_TABLE;
12044
12045 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12046 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12047
12048 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12049 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12050 metric);
12051 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12052 }
12053
12054 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12055 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12056 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12057 "Redistribute information from another routing protocol\n"
12058 "Open Shortest Path First (OSPFv2)\n"
12059 "Non-main Kernel Routing Table\n"
12060 "Instance ID/Table ID\n"
12061 "Metric for redistributed routes\n"
12062 "Default metric\n")
12063
12064 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12065 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12066 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12067 "Redistribute information from another routing protocol\n"
12068 "Open Shortest Path First (OSPFv2)\n"
12069 "Non-main Kernel Routing Table\n"
12070 "Instance ID/Table ID\n"
12071 "Route map reference\n"
12072 "Pointer to route-map entries\n"
12073 "Metric for redistributed routes\n"
12074 "Default metric\n")
12075 {
12076 VTY_DECLVAR_CONTEXT(bgp, bgp);
12077 int idx_ospf_table = 1;
12078 int idx_number = 2;
12079 int idx_word = 4;
12080 int idx_number_2 = 6;
12081 uint32_t metric;
12082 struct bgp_redist *red;
12083 unsigned short instance;
12084 int protocol;
12085 bool changed;
12086 struct route_map *route_map =
12087 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12088
12089 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12090 protocol = ZEBRA_ROUTE_OSPF;
12091 else
12092 protocol = ZEBRA_ROUTE_TABLE;
12093
12094 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12095 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12096
12097 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12098 changed =
12099 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12100 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12101 metric);
12102 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12103 }
12104
12105 ALIAS_HIDDEN(
12106 bgp_redistribute_ipv4_ospf_rmap_metric,
12107 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12108 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12109 "Redistribute information from another routing protocol\n"
12110 "Open Shortest Path First (OSPFv2)\n"
12111 "Non-main Kernel Routing Table\n"
12112 "Instance ID/Table ID\n"
12113 "Route map reference\n"
12114 "Pointer to route-map entries\n"
12115 "Metric for redistributed routes\n"
12116 "Default metric\n")
12117
12118 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12119 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12120 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12121 "Redistribute information from another routing protocol\n"
12122 "Open Shortest Path First (OSPFv2)\n"
12123 "Non-main Kernel Routing Table\n"
12124 "Instance ID/Table ID\n"
12125 "Metric for redistributed routes\n"
12126 "Default metric\n"
12127 "Route map reference\n"
12128 "Pointer to route-map entries\n")
12129 {
12130 VTY_DECLVAR_CONTEXT(bgp, bgp);
12131 int idx_ospf_table = 1;
12132 int idx_number = 2;
12133 int idx_number_2 = 4;
12134 int idx_word = 6;
12135 uint32_t metric;
12136 struct bgp_redist *red;
12137 unsigned short instance;
12138 int protocol;
12139 bool changed;
12140 struct route_map *route_map =
12141 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12142
12143 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12144 protocol = ZEBRA_ROUTE_OSPF;
12145 else
12146 protocol = ZEBRA_ROUTE_TABLE;
12147
12148 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12149 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12150
12151 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12152 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12153 metric);
12154 changed |=
12155 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12156 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12157 }
12158
12159 ALIAS_HIDDEN(
12160 bgp_redistribute_ipv4_ospf_metric_rmap,
12161 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12162 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12163 "Redistribute information from another routing protocol\n"
12164 "Open Shortest Path First (OSPFv2)\n"
12165 "Non-main Kernel Routing Table\n"
12166 "Instance ID/Table ID\n"
12167 "Metric for redistributed routes\n"
12168 "Default metric\n"
12169 "Route map reference\n"
12170 "Pointer to route-map entries\n")
12171
12172 DEFUN (no_bgp_redistribute_ipv4_ospf,
12173 no_bgp_redistribute_ipv4_ospf_cmd,
12174 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12175 NO_STR
12176 "Redistribute information from another routing protocol\n"
12177 "Open Shortest Path First (OSPFv2)\n"
12178 "Non-main Kernel Routing Table\n"
12179 "Instance ID/Table ID\n"
12180 "Metric for redistributed routes\n"
12181 "Default metric\n"
12182 "Route map reference\n"
12183 "Pointer to route-map entries\n")
12184 {
12185 VTY_DECLVAR_CONTEXT(bgp, bgp);
12186 int idx_ospf_table = 2;
12187 int idx_number = 3;
12188 unsigned short instance;
12189 int protocol;
12190
12191 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12192 protocol = ZEBRA_ROUTE_OSPF;
12193 else
12194 protocol = ZEBRA_ROUTE_TABLE;
12195
12196 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12197 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12198 }
12199
12200 ALIAS_HIDDEN(
12201 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12202 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12203 NO_STR
12204 "Redistribute information from another routing protocol\n"
12205 "Open Shortest Path First (OSPFv2)\n"
12206 "Non-main Kernel Routing Table\n"
12207 "Instance ID/Table ID\n"
12208 "Metric for redistributed routes\n"
12209 "Default metric\n"
12210 "Route map reference\n"
12211 "Pointer to route-map entries\n")
12212
12213 DEFUN (no_bgp_redistribute_ipv4,
12214 no_bgp_redistribute_ipv4_cmd,
12215 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12216 NO_STR
12217 "Redistribute information from another routing protocol\n"
12218 FRR_IP_REDIST_HELP_STR_BGPD
12219 "Metric for redistributed routes\n"
12220 "Default metric\n"
12221 "Route map reference\n"
12222 "Pointer to route-map entries\n")
12223 {
12224 VTY_DECLVAR_CONTEXT(bgp, bgp);
12225 int idx_protocol = 2;
12226 int type;
12227
12228 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12229 if (type < 0) {
12230 vty_out(vty, "%% Invalid route type\n");
12231 return CMD_WARNING_CONFIG_FAILED;
12232 }
12233 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12234 }
12235
12236 ALIAS_HIDDEN(
12237 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12238 "no redistribute " FRR_IP_REDIST_STR_BGPD
12239 " [metric (0-4294967295)] [route-map WORD]",
12240 NO_STR
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 "Route map reference\n"
12245 "Pointer to route-map entries\n")
12246
12247 DEFUN (bgp_redistribute_ipv6,
12248 bgp_redistribute_ipv6_cmd,
12249 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12250 "Redistribute information from another routing protocol\n"
12251 FRR_IP6_REDIST_HELP_STR_BGPD)
12252 {
12253 VTY_DECLVAR_CONTEXT(bgp, bgp);
12254 int idx_protocol = 1;
12255 int type;
12256
12257 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12258 if (type < 0) {
12259 vty_out(vty, "%% Invalid route type\n");
12260 return CMD_WARNING_CONFIG_FAILED;
12261 }
12262
12263 bgp_redist_add(bgp, AFI_IP6, type, 0);
12264 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12265 }
12266
12267 DEFUN (bgp_redistribute_ipv6_rmap,
12268 bgp_redistribute_ipv6_rmap_cmd,
12269 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12270 "Redistribute information from another routing protocol\n"
12271 FRR_IP6_REDIST_HELP_STR_BGPD
12272 "Route map reference\n"
12273 "Pointer to route-map entries\n")
12274 {
12275 VTY_DECLVAR_CONTEXT(bgp, bgp);
12276 int idx_protocol = 1;
12277 int idx_word = 3;
12278 int type;
12279 struct bgp_redist *red;
12280 bool changed;
12281 struct route_map *route_map =
12282 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12283
12284 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12285 if (type < 0) {
12286 vty_out(vty, "%% Invalid route type\n");
12287 return CMD_WARNING_CONFIG_FAILED;
12288 }
12289
12290 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12291 changed =
12292 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12293 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12294 }
12295
12296 DEFUN (bgp_redistribute_ipv6_metric,
12297 bgp_redistribute_ipv6_metric_cmd,
12298 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12299 "Redistribute information from another routing protocol\n"
12300 FRR_IP6_REDIST_HELP_STR_BGPD
12301 "Metric for redistributed routes\n"
12302 "Default metric\n")
12303 {
12304 VTY_DECLVAR_CONTEXT(bgp, bgp);
12305 int idx_protocol = 1;
12306 int idx_number = 3;
12307 int type;
12308 uint32_t metric;
12309 struct bgp_redist *red;
12310 bool changed;
12311
12312 type = proto_redistnum(AFI_IP6, 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_IP6, type, 0);
12320 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12321 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12322 }
12323
12324 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12325 bgp_redistribute_ipv6_rmap_metric_cmd,
12326 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12327 "Redistribute information from another routing protocol\n"
12328 FRR_IP6_REDIST_HELP_STR_BGPD
12329 "Route map reference\n"
12330 "Pointer to route-map entries\n"
12331 "Metric for redistributed routes\n"
12332 "Default metric\n")
12333 {
12334 VTY_DECLVAR_CONTEXT(bgp, bgp);
12335 int idx_protocol = 1;
12336 int idx_word = 3;
12337 int idx_number = 5;
12338 int type;
12339 uint32_t metric;
12340 struct bgp_redist *red;
12341 bool changed;
12342 struct route_map *route_map =
12343 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12344
12345 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12346 if (type < 0) {
12347 vty_out(vty, "%% Invalid route type\n");
12348 return CMD_WARNING_CONFIG_FAILED;
12349 }
12350 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12351
12352 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12353 changed =
12354 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12355 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12356 metric);
12357 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12358 }
12359
12360 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12361 bgp_redistribute_ipv6_metric_rmap_cmd,
12362 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12363 "Redistribute information from another routing protocol\n"
12364 FRR_IP6_REDIST_HELP_STR_BGPD
12365 "Metric for redistributed routes\n"
12366 "Default metric\n"
12367 "Route map reference\n"
12368 "Pointer to route-map entries\n")
12369 {
12370 VTY_DECLVAR_CONTEXT(bgp, bgp);
12371 int idx_protocol = 1;
12372 int idx_number = 3;
12373 int idx_word = 5;
12374 int type;
12375 uint32_t metric;
12376 struct bgp_redist *red;
12377 bool changed;
12378 struct route_map *route_map =
12379 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12380
12381 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12382 if (type < 0) {
12383 vty_out(vty, "%% Invalid route type\n");
12384 return CMD_WARNING_CONFIG_FAILED;
12385 }
12386 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12387
12388 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12389 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12390 metric);
12391 changed |=
12392 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12393 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12394 }
12395
12396 DEFUN (no_bgp_redistribute_ipv6,
12397 no_bgp_redistribute_ipv6_cmd,
12398 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12399 NO_STR
12400 "Redistribute information from another routing protocol\n"
12401 FRR_IP6_REDIST_HELP_STR_BGPD
12402 "Metric for redistributed routes\n"
12403 "Default metric\n"
12404 "Route map reference\n"
12405 "Pointer to route-map entries\n")
12406 {
12407 VTY_DECLVAR_CONTEXT(bgp, bgp);
12408 int idx_protocol = 2;
12409 int type;
12410
12411 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12412 if (type < 0) {
12413 vty_out(vty, "%% Invalid route type\n");
12414 return CMD_WARNING_CONFIG_FAILED;
12415 }
12416
12417 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12418 }
12419
12420 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12421 safi_t safi)
12422 {
12423 int i;
12424
12425 /* Unicast redistribution only. */
12426 if (safi != SAFI_UNICAST)
12427 return;
12428
12429 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12430 /* Redistribute BGP does not make sense. */
12431 if (i != ZEBRA_ROUTE_BGP) {
12432 struct list *red_list;
12433 struct listnode *node;
12434 struct bgp_redist *red;
12435
12436 red_list = bgp->redist[afi][i];
12437 if (!red_list)
12438 continue;
12439
12440 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12441 /* "redistribute" configuration. */
12442 vty_out(vty, " redistribute %s",
12443 zebra_route_string(i));
12444 if (red->instance)
12445 vty_out(vty, " %d", red->instance);
12446 if (red->redist_metric_flag)
12447 vty_out(vty, " metric %u",
12448 red->redist_metric);
12449 if (red->rmap.name)
12450 vty_out(vty, " route-map %s",
12451 red->rmap.name);
12452 vty_out(vty, "\n");
12453 }
12454 }
12455 }
12456 }
12457
12458 /* This is part of the address-family block (unicast only) */
12459 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12460 afi_t afi)
12461 {
12462 int indent = 2;
12463
12464 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12465 if (listcount(bgp->vpn_policy[afi].import_vrf))
12466 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12467 bgp->vpn_policy[afi]
12468 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12469 else
12470 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12471 bgp->vpn_policy[afi]
12472 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12473 }
12474 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12475 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12476 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12477 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12478 return;
12479
12480 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12481 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12482
12483 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12484
12485 } else {
12486 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12487 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12488 bgp->vpn_policy[afi].tovpn_label);
12489 }
12490 }
12491 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12492 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12493 char buf[RD_ADDRSTRLEN];
12494 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12495 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12496 sizeof(buf)));
12497 }
12498 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12499 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12500
12501 char buf[PREFIX_STRLEN];
12502 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12503 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12504 sizeof(buf))) {
12505
12506 vty_out(vty, "%*snexthop vpn export %s\n",
12507 indent, "", buf);
12508 }
12509 }
12510 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12511 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12512 && ecommunity_cmp(
12513 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12514 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12515
12516 char *b = ecommunity_ecom2str(
12517 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12518 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12519 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12520 XFREE(MTYPE_ECOMMUNITY_STR, b);
12521 } else {
12522 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12523 char *b = ecommunity_ecom2str(
12524 bgp->vpn_policy[afi]
12525 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12526 ECOMMUNITY_FORMAT_ROUTE_MAP,
12527 ECOMMUNITY_ROUTE_TARGET);
12528 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12529 XFREE(MTYPE_ECOMMUNITY_STR, b);
12530 }
12531 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12532 char *b = ecommunity_ecom2str(
12533 bgp->vpn_policy[afi]
12534 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12535 ECOMMUNITY_FORMAT_ROUTE_MAP,
12536 ECOMMUNITY_ROUTE_TARGET);
12537 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12538 XFREE(MTYPE_ECOMMUNITY_STR, b);
12539 }
12540 }
12541
12542 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12543 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12544 bgp->vpn_policy[afi]
12545 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12546
12547 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12548 char *b = ecommunity_ecom2str(
12549 bgp->vpn_policy[afi]
12550 .import_redirect_rtlist,
12551 ECOMMUNITY_FORMAT_ROUTE_MAP,
12552 ECOMMUNITY_ROUTE_TARGET);
12553
12554 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12555 XFREE(MTYPE_ECOMMUNITY_STR, b);
12556 }
12557 }
12558
12559
12560 /* BGP node structure. */
12561 static struct cmd_node bgp_node = {
12562 BGP_NODE, "%s(config-router)# ", 1,
12563 };
12564
12565 static struct cmd_node bgp_ipv4_unicast_node = {
12566 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12567 };
12568
12569 static struct cmd_node bgp_ipv4_multicast_node = {
12570 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12571 };
12572
12573 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12574 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12575 };
12576
12577 static struct cmd_node bgp_ipv6_unicast_node = {
12578 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12579 };
12580
12581 static struct cmd_node bgp_ipv6_multicast_node = {
12582 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12583 };
12584
12585 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12586 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12587 };
12588
12589 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12590 "%s(config-router-af)# ", 1};
12591
12592 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12593 "%s(config-router-af-vpnv6)# ", 1};
12594
12595 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12596 "%s(config-router-evpn)# ", 1};
12597
12598 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12599 "%s(config-router-af-vni)# ", 1};
12600
12601 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12602 "%s(config-router-af)# ", 1};
12603
12604 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12605 "%s(config-router-af-vpnv6)# ", 1};
12606
12607 static void community_list_vty(void);
12608
12609 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12610 {
12611 struct bgp *bgp;
12612 struct peer *peer;
12613 struct listnode *lnbgp, *lnpeer;
12614
12615 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12616 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12617 /* only provide suggestions on the appropriate input
12618 * token type,
12619 * they'll otherwise show up multiple times */
12620 enum cmd_token_type match_type;
12621 char *name = peer->host;
12622
12623 if (peer->conf_if) {
12624 match_type = VARIABLE_TKN;
12625 name = peer->conf_if;
12626 } else if (strchr(peer->host, ':'))
12627 match_type = IPV6_TKN;
12628 else
12629 match_type = IPV4_TKN;
12630
12631 if (token->type != match_type)
12632 continue;
12633
12634 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12635 }
12636 }
12637 }
12638
12639 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12640 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12641 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12642 {.varname = "peer", .completions = bgp_ac_neighbor},
12643 {.completions = NULL}};
12644
12645 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12646 {
12647 struct bgp *bgp;
12648 struct peer_group *group;
12649 struct listnode *lnbgp, *lnpeer;
12650
12651 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12652 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12653 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12654 group->name));
12655 }
12656 }
12657
12658 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12659 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12660 {.completions = NULL} };
12661
12662 void bgp_vty_init(void)
12663 {
12664 cmd_variable_handler_register(bgp_var_neighbor);
12665 cmd_variable_handler_register(bgp_var_peergroup);
12666
12667 /* Install bgp top node. */
12668 install_node(&bgp_node, bgp_config_write);
12669 install_node(&bgp_ipv4_unicast_node, NULL);
12670 install_node(&bgp_ipv4_multicast_node, NULL);
12671 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12672 install_node(&bgp_ipv6_unicast_node, NULL);
12673 install_node(&bgp_ipv6_multicast_node, NULL);
12674 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12675 install_node(&bgp_vpnv4_node, NULL);
12676 install_node(&bgp_vpnv6_node, NULL);
12677 install_node(&bgp_evpn_node, NULL);
12678 install_node(&bgp_evpn_vni_node, NULL);
12679 install_node(&bgp_flowspecv4_node, NULL);
12680 install_node(&bgp_flowspecv6_node, NULL);
12681
12682 /* Install default VTY commands to new nodes. */
12683 install_default(BGP_NODE);
12684 install_default(BGP_IPV4_NODE);
12685 install_default(BGP_IPV4M_NODE);
12686 install_default(BGP_IPV4L_NODE);
12687 install_default(BGP_IPV6_NODE);
12688 install_default(BGP_IPV6M_NODE);
12689 install_default(BGP_IPV6L_NODE);
12690 install_default(BGP_VPNV4_NODE);
12691 install_default(BGP_VPNV6_NODE);
12692 install_default(BGP_FLOWSPECV4_NODE);
12693 install_default(BGP_FLOWSPECV6_NODE);
12694 install_default(BGP_EVPN_NODE);
12695 install_default(BGP_EVPN_VNI_NODE);
12696
12697 /* "bgp multiple-instance" commands. */
12698 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12699 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12700
12701 /* "bgp config-type" commands. */
12702 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12703 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12704
12705 /* "bgp local-mac" hidden commands. */
12706 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12707 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12708
12709 /* bgp route-map delay-timer commands. */
12710 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12711 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12712
12713 /* Dummy commands (Currently not supported) */
12714 install_element(BGP_NODE, &no_synchronization_cmd);
12715 install_element(BGP_NODE, &no_auto_summary_cmd);
12716
12717 /* "router bgp" commands. */
12718 install_element(CONFIG_NODE, &router_bgp_cmd);
12719
12720 /* "no router bgp" commands. */
12721 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12722
12723 /* "bgp router-id" commands. */
12724 install_element(BGP_NODE, &bgp_router_id_cmd);
12725 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12726
12727 /* "bgp cluster-id" commands. */
12728 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12729 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12730
12731 /* "bgp confederation" commands. */
12732 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12733 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12734
12735 /* "bgp confederation peers" commands. */
12736 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12737 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12738
12739 /* bgp max-med command */
12740 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12741 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12742 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12743 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12744 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12745
12746 /* bgp disable-ebgp-connected-nh-check */
12747 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12748 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12749
12750 /* bgp update-delay command */
12751 install_element(BGP_NODE, &bgp_update_delay_cmd);
12752 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12753 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12754
12755 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12756 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12757 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12758 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12759
12760 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12761 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12762
12763 /* "maximum-paths" commands. */
12764 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12765 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12766 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12767 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12768 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12769 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12770 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12771 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12772 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12773 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12774 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12775 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12776 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12777 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12778 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12779
12780 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12781 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12782 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12783 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12784 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12785
12786 /* "timers bgp" commands. */
12787 install_element(BGP_NODE, &bgp_timers_cmd);
12788 install_element(BGP_NODE, &no_bgp_timers_cmd);
12789
12790 /* route-map delay-timer commands - per instance for backwards compat.
12791 */
12792 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12793 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12794
12795 /* "bgp client-to-client reflection" commands */
12796 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12797 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12798
12799 /* "bgp always-compare-med" commands */
12800 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12801 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12802
12803 /* "bgp deterministic-med" commands */
12804 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12805 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12806
12807 /* "bgp graceful-restart" commands */
12808 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12809 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12810 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12811 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12812 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12813 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12814
12815 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12816 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12817
12818 /* "bgp graceful-shutdown" commands */
12819 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12820 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12821
12822 /* "bgp fast-external-failover" commands */
12823 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12824 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12825
12826 /* "bgp enforce-first-as" commands */
12827 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12828
12829 /* "bgp bestpath compare-routerid" commands */
12830 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12831 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12832
12833 /* "bgp bestpath as-path ignore" commands */
12834 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12835 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12836
12837 /* "bgp bestpath as-path confed" commands */
12838 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12839 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12840
12841 /* "bgp bestpath as-path multipath-relax" commands */
12842 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12843 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12844
12845 /* "bgp log-neighbor-changes" commands */
12846 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12847 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12848
12849 /* "bgp bestpath med" commands */
12850 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12851 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12852
12853 /* "no bgp default ipv4-unicast" commands. */
12854 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12855 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12856
12857 /* "bgp network import-check" commands. */
12858 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12859 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12860 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12861
12862 /* "bgp default local-preference" commands. */
12863 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12864 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12865
12866 /* bgp default show-hostname */
12867 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12868 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12869
12870 /* "bgp default subgroup-pkt-queue-max" commands. */
12871 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12872 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12873
12874 /* bgp ibgp-allow-policy-mods command */
12875 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12876 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12877
12878 /* "bgp listen limit" commands. */
12879 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12880 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12881
12882 /* "bgp listen range" commands. */
12883 install_element(BGP_NODE, &bgp_listen_range_cmd);
12884 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12885
12886 /* "bgp default shutdown" command */
12887 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12888
12889 /* "neighbor remote-as" commands. */
12890 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12891 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12892 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12893 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12894 install_element(BGP_NODE,
12895 &neighbor_interface_v6only_config_remote_as_cmd);
12896 install_element(BGP_NODE, &no_neighbor_cmd);
12897 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12898
12899 /* "neighbor peer-group" commands. */
12900 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12901 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12902 install_element(BGP_NODE,
12903 &no_neighbor_interface_peer_group_remote_as_cmd);
12904
12905 /* "neighbor local-as" commands. */
12906 install_element(BGP_NODE, &neighbor_local_as_cmd);
12907 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12908 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12909 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12910
12911 /* "neighbor solo" commands. */
12912 install_element(BGP_NODE, &neighbor_solo_cmd);
12913 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12914
12915 /* "neighbor password" commands. */
12916 install_element(BGP_NODE, &neighbor_password_cmd);
12917 install_element(BGP_NODE, &no_neighbor_password_cmd);
12918
12919 /* "neighbor activate" commands. */
12920 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12921 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12922 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12923 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12924 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12925 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12926 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12927 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12928 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12929 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12930 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12931 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12932
12933 /* "no neighbor activate" commands. */
12934 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12935 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12936 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12937 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12938 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12939 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12940 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12941 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12942 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12943 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12944 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12945 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12946
12947 /* "neighbor peer-group" set commands. */
12948 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12949 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12950 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12951 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12952 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12953 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12954 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12955 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12956 install_element(BGP_FLOWSPECV4_NODE,
12957 &neighbor_set_peer_group_hidden_cmd);
12958 install_element(BGP_FLOWSPECV6_NODE,
12959 &neighbor_set_peer_group_hidden_cmd);
12960
12961 /* "no neighbor peer-group unset" commands. */
12962 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12963 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12964 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12965 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12966 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12967 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12968 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12969 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12970 install_element(BGP_FLOWSPECV4_NODE,
12971 &no_neighbor_set_peer_group_hidden_cmd);
12972 install_element(BGP_FLOWSPECV6_NODE,
12973 &no_neighbor_set_peer_group_hidden_cmd);
12974
12975 /* "neighbor softreconfiguration inbound" commands.*/
12976 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12977 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12978 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12979 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12980 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12981 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12982 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12983 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12984 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12985 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12986 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12987 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12988 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12989 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12990 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12991 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12992 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12993 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12994 install_element(BGP_FLOWSPECV4_NODE,
12995 &neighbor_soft_reconfiguration_cmd);
12996 install_element(BGP_FLOWSPECV4_NODE,
12997 &no_neighbor_soft_reconfiguration_cmd);
12998 install_element(BGP_FLOWSPECV6_NODE,
12999 &neighbor_soft_reconfiguration_cmd);
13000 install_element(BGP_FLOWSPECV6_NODE,
13001 &no_neighbor_soft_reconfiguration_cmd);
13002
13003 /* "neighbor attribute-unchanged" commands. */
13004 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13005 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13006 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13007 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13008 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13009 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13010 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13011 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13012 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13013 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13014 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13015 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13016 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13017 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13018 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13019 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13020 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13021 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13022
13023 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13024 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13025
13026 /* "nexthop-local unchanged" commands */
13027 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13028 install_element(BGP_IPV6_NODE,
13029 &no_neighbor_nexthop_local_unchanged_cmd);
13030
13031 /* "neighbor next-hop-self" commands. */
13032 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13033 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13034 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13035 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13036 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13037 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13038 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13039 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13040 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13041 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13042 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13043 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13044 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13045 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13046 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13047 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13048 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13049 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13050 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13051 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13052
13053 /* "neighbor next-hop-self force" commands. */
13054 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13055 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13056 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13057 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13058 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13059 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13060 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13061 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13062 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13063 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13064 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13065 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13066 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13067 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13068 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13069 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13070 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13071 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13072
13073 /* "neighbor as-override" commands. */
13074 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13075 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13076 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13077 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13078 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13079 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13080 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13081 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13082 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13083 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13084 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13085 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13086 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13087 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13088 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13089 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13090 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13091 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13092
13093 /* "neighbor remove-private-AS" commands. */
13094 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13095 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13096 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13097 install_element(BGP_NODE,
13098 &no_neighbor_remove_private_as_all_hidden_cmd);
13099 install_element(BGP_NODE,
13100 &neighbor_remove_private_as_replace_as_hidden_cmd);
13101 install_element(BGP_NODE,
13102 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13103 install_element(BGP_NODE,
13104 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13105 install_element(
13106 BGP_NODE,
13107 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13108 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13109 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13110 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13111 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13112 install_element(BGP_IPV4_NODE,
13113 &neighbor_remove_private_as_replace_as_cmd);
13114 install_element(BGP_IPV4_NODE,
13115 &no_neighbor_remove_private_as_replace_as_cmd);
13116 install_element(BGP_IPV4_NODE,
13117 &neighbor_remove_private_as_all_replace_as_cmd);
13118 install_element(BGP_IPV4_NODE,
13119 &no_neighbor_remove_private_as_all_replace_as_cmd);
13120 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13121 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13122 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13123 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13124 install_element(BGP_IPV4M_NODE,
13125 &neighbor_remove_private_as_replace_as_cmd);
13126 install_element(BGP_IPV4M_NODE,
13127 &no_neighbor_remove_private_as_replace_as_cmd);
13128 install_element(BGP_IPV4M_NODE,
13129 &neighbor_remove_private_as_all_replace_as_cmd);
13130 install_element(BGP_IPV4M_NODE,
13131 &no_neighbor_remove_private_as_all_replace_as_cmd);
13132 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13133 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13134 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13135 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13136 install_element(BGP_IPV4L_NODE,
13137 &neighbor_remove_private_as_replace_as_cmd);
13138 install_element(BGP_IPV4L_NODE,
13139 &no_neighbor_remove_private_as_replace_as_cmd);
13140 install_element(BGP_IPV4L_NODE,
13141 &neighbor_remove_private_as_all_replace_as_cmd);
13142 install_element(BGP_IPV4L_NODE,
13143 &no_neighbor_remove_private_as_all_replace_as_cmd);
13144 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13145 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13146 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13147 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13148 install_element(BGP_IPV6_NODE,
13149 &neighbor_remove_private_as_replace_as_cmd);
13150 install_element(BGP_IPV6_NODE,
13151 &no_neighbor_remove_private_as_replace_as_cmd);
13152 install_element(BGP_IPV6_NODE,
13153 &neighbor_remove_private_as_all_replace_as_cmd);
13154 install_element(BGP_IPV6_NODE,
13155 &no_neighbor_remove_private_as_all_replace_as_cmd);
13156 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13157 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13158 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13159 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13160 install_element(BGP_IPV6M_NODE,
13161 &neighbor_remove_private_as_replace_as_cmd);
13162 install_element(BGP_IPV6M_NODE,
13163 &no_neighbor_remove_private_as_replace_as_cmd);
13164 install_element(BGP_IPV6M_NODE,
13165 &neighbor_remove_private_as_all_replace_as_cmd);
13166 install_element(BGP_IPV6M_NODE,
13167 &no_neighbor_remove_private_as_all_replace_as_cmd);
13168 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13169 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13170 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13171 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13172 install_element(BGP_IPV6L_NODE,
13173 &neighbor_remove_private_as_replace_as_cmd);
13174 install_element(BGP_IPV6L_NODE,
13175 &no_neighbor_remove_private_as_replace_as_cmd);
13176 install_element(BGP_IPV6L_NODE,
13177 &neighbor_remove_private_as_all_replace_as_cmd);
13178 install_element(BGP_IPV6L_NODE,
13179 &no_neighbor_remove_private_as_all_replace_as_cmd);
13180 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13181 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13182 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13183 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13184 install_element(BGP_VPNV4_NODE,
13185 &neighbor_remove_private_as_replace_as_cmd);
13186 install_element(BGP_VPNV4_NODE,
13187 &no_neighbor_remove_private_as_replace_as_cmd);
13188 install_element(BGP_VPNV4_NODE,
13189 &neighbor_remove_private_as_all_replace_as_cmd);
13190 install_element(BGP_VPNV4_NODE,
13191 &no_neighbor_remove_private_as_all_replace_as_cmd);
13192 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13193 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13194 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13195 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13196 install_element(BGP_VPNV6_NODE,
13197 &neighbor_remove_private_as_replace_as_cmd);
13198 install_element(BGP_VPNV6_NODE,
13199 &no_neighbor_remove_private_as_replace_as_cmd);
13200 install_element(BGP_VPNV6_NODE,
13201 &neighbor_remove_private_as_all_replace_as_cmd);
13202 install_element(BGP_VPNV6_NODE,
13203 &no_neighbor_remove_private_as_all_replace_as_cmd);
13204
13205 /* "neighbor send-community" commands.*/
13206 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13207 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13208 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13209 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13210 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13211 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13212 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13213 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13214 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13215 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13216 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13217 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13218 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13219 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13220 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13221 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13222 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13223 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13224 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13225 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13226 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13227 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13228 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13229 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13230 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13231 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13232 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13233 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13234 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13235 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13236 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13237 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13238 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13239 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13240 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13241 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13242
13243 /* "neighbor route-reflector" commands.*/
13244 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13245 install_element(BGP_NODE,
13246 &no_neighbor_route_reflector_client_hidden_cmd);
13247 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13248 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13249 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13250 install_element(BGP_IPV4M_NODE,
13251 &no_neighbor_route_reflector_client_cmd);
13252 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13253 install_element(BGP_IPV4L_NODE,
13254 &no_neighbor_route_reflector_client_cmd);
13255 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13256 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13257 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13258 install_element(BGP_IPV6M_NODE,
13259 &no_neighbor_route_reflector_client_cmd);
13260 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13261 install_element(BGP_IPV6L_NODE,
13262 &no_neighbor_route_reflector_client_cmd);
13263 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13264 install_element(BGP_VPNV4_NODE,
13265 &no_neighbor_route_reflector_client_cmd);
13266 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13267 install_element(BGP_VPNV6_NODE,
13268 &no_neighbor_route_reflector_client_cmd);
13269 install_element(BGP_FLOWSPECV4_NODE,
13270 &neighbor_route_reflector_client_cmd);
13271 install_element(BGP_FLOWSPECV4_NODE,
13272 &no_neighbor_route_reflector_client_cmd);
13273 install_element(BGP_FLOWSPECV6_NODE,
13274 &neighbor_route_reflector_client_cmd);
13275 install_element(BGP_FLOWSPECV6_NODE,
13276 &no_neighbor_route_reflector_client_cmd);
13277 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13278 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13279
13280 /* "neighbor route-server" commands.*/
13281 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13282 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13283 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13284 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13285 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13286 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13287 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13288 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13289 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13290 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13291 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13292 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13293 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13294 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13295 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13296 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13297 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13298 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13299 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13300 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13301 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13302 install_element(BGP_FLOWSPECV4_NODE,
13303 &no_neighbor_route_server_client_cmd);
13304 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13305 install_element(BGP_FLOWSPECV6_NODE,
13306 &no_neighbor_route_server_client_cmd);
13307
13308 /* "neighbor addpath-tx-all-paths" commands.*/
13309 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13310 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13311 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13312 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13313 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13314 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13315 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13316 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13317 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13318 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13319 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13320 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13321 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13322 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13323 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13324 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13325 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13326 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13327
13328 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13329 install_element(BGP_NODE,
13330 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13331 install_element(BGP_NODE,
13332 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13333 install_element(BGP_IPV4_NODE,
13334 &neighbor_addpath_tx_bestpath_per_as_cmd);
13335 install_element(BGP_IPV4_NODE,
13336 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13337 install_element(BGP_IPV4M_NODE,
13338 &neighbor_addpath_tx_bestpath_per_as_cmd);
13339 install_element(BGP_IPV4M_NODE,
13340 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13341 install_element(BGP_IPV4L_NODE,
13342 &neighbor_addpath_tx_bestpath_per_as_cmd);
13343 install_element(BGP_IPV4L_NODE,
13344 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13345 install_element(BGP_IPV6_NODE,
13346 &neighbor_addpath_tx_bestpath_per_as_cmd);
13347 install_element(BGP_IPV6_NODE,
13348 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13349 install_element(BGP_IPV6M_NODE,
13350 &neighbor_addpath_tx_bestpath_per_as_cmd);
13351 install_element(BGP_IPV6M_NODE,
13352 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13353 install_element(BGP_IPV6L_NODE,
13354 &neighbor_addpath_tx_bestpath_per_as_cmd);
13355 install_element(BGP_IPV6L_NODE,
13356 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13357 install_element(BGP_VPNV4_NODE,
13358 &neighbor_addpath_tx_bestpath_per_as_cmd);
13359 install_element(BGP_VPNV4_NODE,
13360 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13361 install_element(BGP_VPNV6_NODE,
13362 &neighbor_addpath_tx_bestpath_per_as_cmd);
13363 install_element(BGP_VPNV6_NODE,
13364 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13365
13366 /* "neighbor passive" commands. */
13367 install_element(BGP_NODE, &neighbor_passive_cmd);
13368 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13369
13370
13371 /* "neighbor shutdown" commands. */
13372 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13373 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13374 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13375 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13376
13377 /* "neighbor capability extended-nexthop" commands.*/
13378 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13379 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13380
13381 /* "neighbor capability orf prefix-list" commands.*/
13382 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13383 install_element(BGP_NODE,
13384 &no_neighbor_capability_orf_prefix_hidden_cmd);
13385 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13386 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13387 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13388 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13389 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13390 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13391 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13392 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13393 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13394 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13395 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13396 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13397
13398 /* "neighbor capability dynamic" commands.*/
13399 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13400 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13401
13402 /* "neighbor dont-capability-negotiate" commands. */
13403 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13404 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13405
13406 /* "neighbor ebgp-multihop" commands. */
13407 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13408 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13409 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13410
13411 /* "neighbor disable-connected-check" commands. */
13412 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13413 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13414
13415 /* "neighbor enforce-first-as" commands. */
13416 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13417 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13418
13419 /* "neighbor description" commands. */
13420 install_element(BGP_NODE, &neighbor_description_cmd);
13421 install_element(BGP_NODE, &no_neighbor_description_cmd);
13422 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13423
13424 /* "neighbor update-source" commands. "*/
13425 install_element(BGP_NODE, &neighbor_update_source_cmd);
13426 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13427
13428 /* "neighbor default-originate" commands. */
13429 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13430 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13431 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13432 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13433 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13434 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13435 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13436 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13437 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13438 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13439 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13440 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13441 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13442 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13443 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13444 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13445 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13446 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13447 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13448 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13449 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13450
13451 /* "neighbor port" commands. */
13452 install_element(BGP_NODE, &neighbor_port_cmd);
13453 install_element(BGP_NODE, &no_neighbor_port_cmd);
13454
13455 /* "neighbor weight" commands. */
13456 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13457 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13458
13459 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13460 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13461 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13462 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13463 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13464 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13465 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13466 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13467 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13468 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13469 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13470 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13471 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13472 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13473 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13474 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13475
13476 /* "neighbor override-capability" commands. */
13477 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13478 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13479
13480 /* "neighbor strict-capability-match" commands. */
13481 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13482 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13483
13484 /* "neighbor timers" commands. */
13485 install_element(BGP_NODE, &neighbor_timers_cmd);
13486 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13487
13488 /* "neighbor timers connect" commands. */
13489 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13490 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13491
13492 /* "neighbor advertisement-interval" commands. */
13493 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13494 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13495
13496 /* "neighbor interface" commands. */
13497 install_element(BGP_NODE, &neighbor_interface_cmd);
13498 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13499
13500 /* "neighbor distribute" commands. */
13501 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13502 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13503 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13504 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13505 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13506 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13507 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13508 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13509 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13510 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13511 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13512 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13513 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13514 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13515 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13516 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13517 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13518 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13519
13520 /* "neighbor prefix-list" commands. */
13521 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13522 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13523 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13524 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13525 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13526 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13527 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13528 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13529 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13530 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13531 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13532 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13533 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13534 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13535 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13536 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13537 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13538 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13539 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13540 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13541 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13542 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13543
13544 /* "neighbor filter-list" commands. */
13545 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13546 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13547 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13548 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13549 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13550 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13551 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13552 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13553 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13554 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13555 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13556 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13557 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13558 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13559 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13560 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13561 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13562 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13563 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13564 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13565 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13566 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13567
13568 /* "neighbor route-map" commands. */
13569 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13570 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13571 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13572 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13573 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13574 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13575 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13576 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13577 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13578 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13579 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13580 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13581 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13582 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13583 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13584 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13585 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13586 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13587 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13588 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13589 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13590 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13591 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13592 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13593
13594 /* "neighbor unsuppress-map" commands. */
13595 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13596 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13597 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13598 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13599 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13600 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13601 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13602 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13603 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13604 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13605 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13606 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13607 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13608 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13609 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13610 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13611 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13612 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13613
13614 /* "neighbor maximum-prefix" commands. */
13615 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13616 install_element(BGP_NODE,
13617 &neighbor_maximum_prefix_threshold_hidden_cmd);
13618 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13619 install_element(BGP_NODE,
13620 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13621 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13622 install_element(BGP_NODE,
13623 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13624 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13625 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13626 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13627 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13628 install_element(BGP_IPV4_NODE,
13629 &neighbor_maximum_prefix_threshold_warning_cmd);
13630 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13631 install_element(BGP_IPV4_NODE,
13632 &neighbor_maximum_prefix_threshold_restart_cmd);
13633 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13634 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13635 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13636 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13637 install_element(BGP_IPV4M_NODE,
13638 &neighbor_maximum_prefix_threshold_warning_cmd);
13639 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13640 install_element(BGP_IPV4M_NODE,
13641 &neighbor_maximum_prefix_threshold_restart_cmd);
13642 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13643 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13644 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13645 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13646 install_element(BGP_IPV4L_NODE,
13647 &neighbor_maximum_prefix_threshold_warning_cmd);
13648 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13649 install_element(BGP_IPV4L_NODE,
13650 &neighbor_maximum_prefix_threshold_restart_cmd);
13651 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13652 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13653 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13654 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13655 install_element(BGP_IPV6_NODE,
13656 &neighbor_maximum_prefix_threshold_warning_cmd);
13657 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13658 install_element(BGP_IPV6_NODE,
13659 &neighbor_maximum_prefix_threshold_restart_cmd);
13660 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13661 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13662 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13663 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13664 install_element(BGP_IPV6M_NODE,
13665 &neighbor_maximum_prefix_threshold_warning_cmd);
13666 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13667 install_element(BGP_IPV6M_NODE,
13668 &neighbor_maximum_prefix_threshold_restart_cmd);
13669 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13670 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13671 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13672 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13673 install_element(BGP_IPV6L_NODE,
13674 &neighbor_maximum_prefix_threshold_warning_cmd);
13675 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13676 install_element(BGP_IPV6L_NODE,
13677 &neighbor_maximum_prefix_threshold_restart_cmd);
13678 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13679 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13680 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13681 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13682 install_element(BGP_VPNV4_NODE,
13683 &neighbor_maximum_prefix_threshold_warning_cmd);
13684 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13685 install_element(BGP_VPNV4_NODE,
13686 &neighbor_maximum_prefix_threshold_restart_cmd);
13687 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13688 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13689 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13690 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13691 install_element(BGP_VPNV6_NODE,
13692 &neighbor_maximum_prefix_threshold_warning_cmd);
13693 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13694 install_element(BGP_VPNV6_NODE,
13695 &neighbor_maximum_prefix_threshold_restart_cmd);
13696 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13697
13698 /* "neighbor allowas-in" */
13699 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13700 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13701 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13702 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13703 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13704 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13705 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13706 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13707 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13708 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13709 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13710 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13711 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13712 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13713 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13714 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13715 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13716 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13717 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13718 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13719
13720 /* address-family commands. */
13721 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13722 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13723 #ifdef KEEP_OLD_VPN_COMMANDS
13724 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13725 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13726 #endif /* KEEP_OLD_VPN_COMMANDS */
13727
13728 install_element(BGP_NODE, &address_family_evpn_cmd);
13729
13730 /* "exit-address-family" command. */
13731 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13732 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13733 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13734 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13735 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13736 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13737 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13738 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13739 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13740 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13741 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13742
13743 /* "clear ip bgp commands" */
13744 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13745
13746 /* clear ip bgp prefix */
13747 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13748 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13749 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13750
13751 /* "show [ip] bgp summary" commands. */
13752 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13753 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13754 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13755 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13756 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13757 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13758 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13759
13760 /* "show [ip] bgp neighbors" commands. */
13761 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13762
13763 /* "show [ip] bgp peer-group" commands. */
13764 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13765
13766 /* "show [ip] bgp paths" commands. */
13767 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13768
13769 /* "show [ip] bgp community" commands. */
13770 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13771
13772 /* "show ip bgp large-community" commands. */
13773 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13774 /* "show [ip] bgp attribute-info" commands. */
13775 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13776 /* "show [ip] bgp route-leak" command */
13777 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13778
13779 /* "redistribute" commands. */
13780 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13781 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13782 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13783 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13784 install_element(BGP_NODE,
13785 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13786 install_element(BGP_NODE,
13787 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13788 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13789 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13790 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13791 install_element(BGP_NODE,
13792 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13793 install_element(BGP_NODE,
13794 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13795 install_element(BGP_NODE,
13796 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13797 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13798 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13799 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13800 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13801 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13802 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13803 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13804 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13805 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13806 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13807 install_element(BGP_IPV4_NODE,
13808 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13809 install_element(BGP_IPV4_NODE,
13810 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13811 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13812 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13813 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13814 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13815 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13816 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13817
13818 /* import|export vpn [route-map WORD] */
13819 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13820 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13821
13822 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13823 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13824
13825 /* ttl_security commands */
13826 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13827 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13828
13829 /* "show [ip] bgp memory" commands. */
13830 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13831
13832 /* "show bgp martian next-hop" */
13833 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13834
13835 /* "show [ip] bgp views" commands. */
13836 install_element(VIEW_NODE, &show_bgp_views_cmd);
13837
13838 /* "show [ip] bgp vrfs" commands. */
13839 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13840
13841 /* Community-list. */
13842 community_list_vty();
13843
13844 /* vpn-policy commands */
13845 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13846 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13847 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13848 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13849 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13850 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13851 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13852 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13853 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13854 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13855 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13856 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13857
13858 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13859 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13860
13861 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13862 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13863 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13864 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13865 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13866 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13867 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13868 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13869 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13870 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13871 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13872 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13873 }
13874
13875 #include "memory.h"
13876 #include "bgp_regex.h"
13877 #include "bgp_clist.h"
13878 #include "bgp_ecommunity.h"
13879
13880 /* VTY functions. */
13881
13882 /* Direction value to string conversion. */
13883 static const char *community_direct_str(int direct)
13884 {
13885 switch (direct) {
13886 case COMMUNITY_DENY:
13887 return "deny";
13888 case COMMUNITY_PERMIT:
13889 return "permit";
13890 default:
13891 return "unknown";
13892 }
13893 }
13894
13895 /* Display error string. */
13896 static void community_list_perror(struct vty *vty, int ret)
13897 {
13898 switch (ret) {
13899 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13900 vty_out(vty, "%% Can't find community-list\n");
13901 break;
13902 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13903 vty_out(vty, "%% Malformed community-list value\n");
13904 break;
13905 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13906 vty_out(vty,
13907 "%% Community name conflict, previously defined as standard community\n");
13908 break;
13909 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13910 vty_out(vty,
13911 "%% Community name conflict, previously defined as expanded community\n");
13912 break;
13913 }
13914 }
13915
13916 /* "community-list" keyword help string. */
13917 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13918
13919 /*community-list standard */
13920 DEFUN (community_list_standard,
13921 bgp_community_list_standard_cmd,
13922 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13923 BGP_STR
13924 COMMUNITY_LIST_STR
13925 "Community list number (standard)\n"
13926 "Add an standard community-list entry\n"
13927 "Community list name\n"
13928 "Specify community to reject\n"
13929 "Specify community to accept\n"
13930 COMMUNITY_VAL_STR)
13931 {
13932 char *cl_name_or_number = NULL;
13933 int direct = 0;
13934 int style = COMMUNITY_LIST_STANDARD;
13935
13936 int idx = 0;
13937
13938 if (argv_find(argv, argc, "ip", &idx)) {
13939 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13940 vty_out(vty, "if you are using this please migrate to the below command.\n");
13941 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13942 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13943 }
13944
13945 argv_find(argv, argc, "(1-99)", &idx);
13946 argv_find(argv, argc, "WORD", &idx);
13947 cl_name_or_number = argv[idx]->arg;
13948 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13949 : COMMUNITY_DENY;
13950 argv_find(argv, argc, "AA:NN", &idx);
13951 char *str = argv_concat(argv, argc, idx);
13952
13953 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13954 style);
13955
13956 XFREE(MTYPE_TMP, str);
13957
13958 if (ret < 0) {
13959 /* Display error string. */
13960 community_list_perror(vty, ret);
13961 return CMD_WARNING_CONFIG_FAILED;
13962 }
13963
13964 return CMD_SUCCESS;
13965 }
13966
13967 #if CONFDATE > 20191005
13968 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
13969 #endif
13970 ALIAS (community_list_standard,
13971 ip_community_list_standard_cmd,
13972 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13973 IP_STR
13974 COMMUNITY_LIST_STR
13975 "Community list number (standard)\n"
13976 "Add an standard community-list entry\n"
13977 "Community list name\n"
13978 "Specify community to reject\n"
13979 "Specify community to accept\n"
13980 COMMUNITY_VAL_STR)
13981
13982 DEFUN (no_community_list_standard_all,
13983 no_bgp_community_list_standard_all_cmd,
13984 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13985 NO_STR
13986 BGP_STR
13987 COMMUNITY_LIST_STR
13988 "Community list number (standard)\n"
13989 "Add an standard community-list entry\n"
13990 "Community list name\n"
13991 "Specify community to reject\n"
13992 "Specify community to accept\n"
13993 COMMUNITY_VAL_STR)
13994 {
13995 char *cl_name_or_number = NULL;
13996 char *str = NULL;
13997 int direct = 0;
13998 int style = COMMUNITY_LIST_STANDARD;
13999
14000 int idx = 0;
14001
14002 if (argv_find(argv, argc, "ip", &idx)) {
14003 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14004 vty_out(vty, "if you are using this please migrate to the below command.\n");
14005 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14006 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14007 }
14008
14009 argv_find(argv, argc, "permit", &idx);
14010 argv_find(argv, argc, "deny", &idx);
14011
14012 if (idx) {
14013 direct = argv_find(argv, argc, "permit", &idx)
14014 ? COMMUNITY_PERMIT
14015 : COMMUNITY_DENY;
14016
14017 idx = 0;
14018 argv_find(argv, argc, "AA:NN", &idx);
14019 str = argv_concat(argv, argc, idx);
14020 }
14021
14022 idx = 0;
14023 argv_find(argv, argc, "(1-99)", &idx);
14024 argv_find(argv, argc, "WORD", &idx);
14025 cl_name_or_number = argv[idx]->arg;
14026
14027 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14028 direct, style);
14029
14030 XFREE(MTYPE_TMP, str);
14031
14032 if (ret < 0) {
14033 community_list_perror(vty, ret);
14034 return CMD_WARNING_CONFIG_FAILED;
14035 }
14036
14037 return CMD_SUCCESS;
14038 }
14039 ALIAS (no_community_list_standard_all,
14040 no_ip_community_list_standard_all_cmd,
14041 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14042 NO_STR
14043 IP_STR
14044 COMMUNITY_LIST_STR
14045 "Community list number (standard)\n"
14046 "Add an standard community-list entry\n"
14047 "Community list name\n"
14048 "Specify community to reject\n"
14049 "Specify community to accept\n"
14050 COMMUNITY_VAL_STR)
14051
14052 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14053 "no bgp community-list <(1-99)|standard WORD>",
14054 NO_STR BGP_STR COMMUNITY_LIST_STR
14055 "Community list number (standard)\n"
14056 "Add an standard community-list entry\n"
14057 "Community list name\n")
14058
14059 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14060 "no ip community-list <(1-99)|standard WORD>",
14061 NO_STR BGP_STR COMMUNITY_LIST_STR
14062 "Community list number (standard)\n"
14063 "Add an standard community-list entry\n"
14064 "Community list name\n")
14065
14066 /*community-list expanded */
14067 DEFUN (community_list_expanded_all,
14068 bgp_community_list_expanded_all_cmd,
14069 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14070 BGP_STR
14071 COMMUNITY_LIST_STR
14072 "Community list number (expanded)\n"
14073 "Add an expanded community-list entry\n"
14074 "Community list name\n"
14075 "Specify community to reject\n"
14076 "Specify community to accept\n"
14077 COMMUNITY_VAL_STR)
14078 {
14079 char *cl_name_or_number = NULL;
14080 int direct = 0;
14081 int style = COMMUNITY_LIST_EXPANDED;
14082
14083 int idx = 0;
14084 if (argv_find(argv, argc, "ip", &idx)) {
14085 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14086 vty_out(vty, "if you are using this please migrate to the below command.\n");
14087 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14088 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14089 }
14090 argv_find(argv, argc, "(100-500)", &idx);
14091 argv_find(argv, argc, "WORD", &idx);
14092 cl_name_or_number = argv[idx]->arg;
14093 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14094 : COMMUNITY_DENY;
14095 argv_find(argv, argc, "AA:NN", &idx);
14096 char *str = argv_concat(argv, argc, idx);
14097
14098 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14099 style);
14100
14101 XFREE(MTYPE_TMP, str);
14102
14103 if (ret < 0) {
14104 /* Display error string. */
14105 community_list_perror(vty, ret);
14106 return CMD_WARNING_CONFIG_FAILED;
14107 }
14108
14109 return CMD_SUCCESS;
14110 }
14111
14112 ALIAS (community_list_expanded_all,
14113 ip_community_list_expanded_all_cmd,
14114 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14115 IP_STR
14116 COMMUNITY_LIST_STR
14117 "Community list number (expanded)\n"
14118 "Add an expanded community-list entry\n"
14119 "Community list name\n"
14120 "Specify community to reject\n"
14121 "Specify community to accept\n"
14122 COMMUNITY_VAL_STR)
14123
14124 DEFUN (no_community_list_expanded_all,
14125 no_bgp_community_list_expanded_all_cmd,
14126 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14127 NO_STR
14128 BGP_STR
14129 COMMUNITY_LIST_STR
14130 "Community list number (expanded)\n"
14131 "Add an expanded community-list entry\n"
14132 "Community list name\n"
14133 "Specify community to reject\n"
14134 "Specify community to accept\n"
14135 COMMUNITY_VAL_STR)
14136 {
14137 char *cl_name_or_number = NULL;
14138 char *str = NULL;
14139 int direct = 0;
14140 int style = COMMUNITY_LIST_EXPANDED;
14141
14142 int idx = 0;
14143 if (argv_find(argv, argc, "ip", &idx)) {
14144 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14145 vty_out(vty, "if you are using this please migrate to the below command.\n");
14146 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14147 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14148 }
14149
14150 idx = 0;
14151 argv_find(argv, argc, "permit", &idx);
14152 argv_find(argv, argc, "deny", &idx);
14153
14154 if (idx) {
14155 direct = argv_find(argv, argc, "permit", &idx)
14156 ? COMMUNITY_PERMIT
14157 : COMMUNITY_DENY;
14158
14159 idx = 0;
14160 argv_find(argv, argc, "AA:NN", &idx);
14161 str = argv_concat(argv, argc, idx);
14162 }
14163
14164 idx = 0;
14165 argv_find(argv, argc, "(100-500)", &idx);
14166 argv_find(argv, argc, "WORD", &idx);
14167 cl_name_or_number = argv[idx]->arg;
14168
14169 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14170 direct, style);
14171
14172 XFREE(MTYPE_TMP, str);
14173
14174 if (ret < 0) {
14175 community_list_perror(vty, ret);
14176 return CMD_WARNING_CONFIG_FAILED;
14177 }
14178
14179 return CMD_SUCCESS;
14180 }
14181
14182 ALIAS (no_community_list_expanded_all,
14183 no_ip_community_list_expanded_all_cmd,
14184 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14185 NO_STR
14186 IP_STR
14187 COMMUNITY_LIST_STR
14188 "Community list number (expanded)\n"
14189 "Add an expanded community-list entry\n"
14190 "Community list name\n"
14191 "Specify community to reject\n"
14192 "Specify community to accept\n"
14193 COMMUNITY_VAL_STR)
14194
14195 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14196 "no bgp community-list <(100-500)|expanded WORD>",
14197 NO_STR IP_STR COMMUNITY_LIST_STR
14198 "Community list number (expanded)\n"
14199 "Add an expanded community-list entry\n"
14200 "Community list name\n")
14201
14202 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14203 "no ip community-list <(100-500)|expanded WORD>",
14204 NO_STR IP_STR COMMUNITY_LIST_STR
14205 "Community list number (expanded)\n"
14206 "Add an expanded community-list entry\n"
14207 "Community list name\n")
14208
14209 /* Return configuration string of community-list entry. */
14210 static const char *community_list_config_str(struct community_entry *entry)
14211 {
14212 const char *str;
14213
14214 if (entry->any)
14215 str = "";
14216 else {
14217 if (entry->style == COMMUNITY_LIST_STANDARD)
14218 str = community_str(entry->u.com, false);
14219 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14220 str = lcommunity_str(entry->u.lcom, false);
14221 else
14222 str = entry->config;
14223 }
14224 return str;
14225 }
14226
14227 static void community_list_show(struct vty *vty, struct community_list *list)
14228 {
14229 struct community_entry *entry;
14230
14231 for (entry = list->head; entry; entry = entry->next) {
14232 if (entry == list->head) {
14233 if (all_digit(list->name))
14234 vty_out(vty, "Community %s list %s\n",
14235 entry->style == COMMUNITY_LIST_STANDARD
14236 ? "standard"
14237 : "(expanded) access",
14238 list->name);
14239 else
14240 vty_out(vty, "Named Community %s list %s\n",
14241 entry->style == COMMUNITY_LIST_STANDARD
14242 ? "standard"
14243 : "expanded",
14244 list->name);
14245 }
14246 if (entry->any)
14247 vty_out(vty, " %s\n",
14248 community_direct_str(entry->direct));
14249 else
14250 vty_out(vty, " %s %s\n",
14251 community_direct_str(entry->direct),
14252 community_list_config_str(entry));
14253 }
14254 }
14255
14256 DEFUN (show_community_list,
14257 show_bgp_community_list_cmd,
14258 "show bgp community-list",
14259 SHOW_STR
14260 BGP_STR
14261 "List community-list\n")
14262 {
14263 struct community_list *list;
14264 struct community_list_master *cm;
14265
14266 int idx = 0;
14267 if (argv_find(argv, argc, "ip", &idx)) {
14268 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14269 vty_out(vty, "if you are using this please migrate to the below command.\n");
14270 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14271 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14272 }
14273 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14274 if (!cm)
14275 return CMD_SUCCESS;
14276
14277 for (list = cm->num.head; list; list = list->next)
14278 community_list_show(vty, list);
14279
14280 for (list = cm->str.head; list; list = list->next)
14281 community_list_show(vty, list);
14282
14283 return CMD_SUCCESS;
14284 }
14285
14286 ALIAS (show_community_list,
14287 show_ip_community_list_cmd,
14288 "show ip community-list",
14289 SHOW_STR
14290 IP_STR
14291 "List community-list\n")
14292
14293 DEFUN (show_community_list_arg,
14294 show_bgp_community_list_arg_cmd,
14295 "show bgp community-list <(1-500)|WORD>",
14296 SHOW_STR
14297 BGP_STR
14298 "List community-list\n"
14299 "Community-list number\n"
14300 "Community-list name\n")
14301 {
14302 int idx_comm_list = 3;
14303 struct community_list *list;
14304
14305 int idx = 0;
14306 if (argv_find(argv, argc, "ip", &idx)) {
14307 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14308 vty_out(vty, "if you are using this please migrate to the below command.\n");
14309 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14310 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14311 }
14312 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14313 COMMUNITY_LIST_MASTER);
14314 if (!list) {
14315 vty_out(vty, "%% Can't find community-list\n");
14316 return CMD_WARNING;
14317 }
14318
14319 community_list_show(vty, list);
14320
14321 return CMD_SUCCESS;
14322 }
14323
14324 ALIAS (show_community_list_arg,
14325 show_ip_community_list_arg_cmd,
14326 "show ip community-list <(1-500)|WORD>",
14327 SHOW_STR
14328 IP_STR
14329 "List community-list\n"
14330 "Community-list number\n"
14331 "Community-list name\n")
14332
14333 /*
14334 * Large Community code.
14335 */
14336 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14337 struct cmd_token **argv, int style,
14338 int reject_all_digit_name)
14339 {
14340 int ret;
14341 int direct;
14342 char *str;
14343 int idx = 0;
14344 char *cl_name;
14345
14346 if (argv_find(argv, argc, "ip", &idx)) {
14347 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14348 vty_out(vty, "if you are using this please migrate to the below command.\n");
14349 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14350 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14351 }
14352 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14353 : COMMUNITY_DENY;
14354
14355 /* All digit name check. */
14356 idx = 0;
14357 argv_find(argv, argc, "WORD", &idx);
14358 argv_find(argv, argc, "(1-99)", &idx);
14359 argv_find(argv, argc, "(100-500)", &idx);
14360 cl_name = argv[idx]->arg;
14361 if (reject_all_digit_name && all_digit(cl_name)) {
14362 vty_out(vty, "%% Community name cannot have all digits\n");
14363 return CMD_WARNING_CONFIG_FAILED;
14364 }
14365
14366 idx = 0;
14367 argv_find(argv, argc, "AA:BB:CC", &idx);
14368 argv_find(argv, argc, "LINE", &idx);
14369 /* Concat community string argument. */
14370 if (idx)
14371 str = argv_concat(argv, argc, idx);
14372 else
14373 str = NULL;
14374
14375 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14376
14377 /* Free temporary community list string allocated by
14378 argv_concat(). */
14379 if (str)
14380 XFREE(MTYPE_TMP, str);
14381
14382 if (ret < 0) {
14383 community_list_perror(vty, ret);
14384 return CMD_WARNING_CONFIG_FAILED;
14385 }
14386 return CMD_SUCCESS;
14387 }
14388
14389 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14390 struct cmd_token **argv, int style)
14391 {
14392 int ret;
14393 int direct = 0;
14394 char *str = NULL;
14395 int idx = 0;
14396
14397 if (argv_find(argv, argc, "ip", &idx)) {
14398 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14399 vty_out(vty, "if you are using this please migrate to the below command.\n");
14400 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14401 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14402 }
14403 argv_find(argv, argc, "permit", &idx);
14404 argv_find(argv, argc, "deny", &idx);
14405
14406 if (idx) {
14407 /* Check the list direct. */
14408 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14409 direct = COMMUNITY_PERMIT;
14410 else
14411 direct = COMMUNITY_DENY;
14412
14413 idx = 0;
14414 argv_find(argv, argc, "LINE", &idx);
14415 argv_find(argv, argc, "AA:AA:NN", &idx);
14416 /* Concat community string argument. */
14417 str = argv_concat(argv, argc, idx);
14418 }
14419
14420 idx = 0;
14421 argv_find(argv, argc, "(1-99)", &idx);
14422 argv_find(argv, argc, "(100-500)", &idx);
14423 argv_find(argv, argc, "WORD", &idx);
14424
14425 /* Unset community list. */
14426 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14427 style);
14428
14429 /* Free temporary community list string allocated by
14430 argv_concat(). */
14431 if (str)
14432 XFREE(MTYPE_TMP, str);
14433
14434 if (ret < 0) {
14435 community_list_perror(vty, ret);
14436 return CMD_WARNING_CONFIG_FAILED;
14437 }
14438
14439 return CMD_SUCCESS;
14440 }
14441
14442 /* "large-community-list" keyword help string. */
14443 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14444 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14445
14446 #if CONFDATE > 20191005
14447 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14448 #endif
14449 DEFUN (lcommunity_list_standard,
14450 bgp_lcommunity_list_standard_cmd,
14451 "bgp large-community-list (1-99) <deny|permit>",
14452 BGP_STR
14453 LCOMMUNITY_LIST_STR
14454 "Large Community list number (standard)\n"
14455 "Specify large community to reject\n"
14456 "Specify large community to accept\n")
14457 {
14458 return lcommunity_list_set_vty(vty, argc, argv,
14459 LARGE_COMMUNITY_LIST_STANDARD, 0);
14460 }
14461
14462 ALIAS (lcommunity_list_standard,
14463 ip_lcommunity_list_standard_cmd,
14464 "ip large-community-list (1-99) <deny|permit>",
14465 IP_STR
14466 LCOMMUNITY_LIST_STR
14467 "Large Community list number (standard)\n"
14468 "Specify large community to reject\n"
14469 "Specify large community to accept\n")
14470
14471 DEFUN (lcommunity_list_standard1,
14472 bgp_lcommunity_list_standard1_cmd,
14473 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14474 BGP_STR
14475 LCOMMUNITY_LIST_STR
14476 "Large Community list number (standard)\n"
14477 "Specify large community to reject\n"
14478 "Specify large community to accept\n"
14479 LCOMMUNITY_VAL_STR)
14480 {
14481 return lcommunity_list_set_vty(vty, argc, argv,
14482 LARGE_COMMUNITY_LIST_STANDARD, 0);
14483 }
14484
14485 ALIAS (lcommunity_list_standard1,
14486 ip_lcommunity_list_standard1_cmd,
14487 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14488 IP_STR
14489 LCOMMUNITY_LIST_STR
14490 "Large Community list number (standard)\n"
14491 "Specify large community to reject\n"
14492 "Specify large community to accept\n"
14493 LCOMMUNITY_VAL_STR)
14494
14495 DEFUN (lcommunity_list_expanded,
14496 bgp_lcommunity_list_expanded_cmd,
14497 "bgp large-community-list (100-500) <deny|permit> LINE...",
14498 BGP_STR
14499 LCOMMUNITY_LIST_STR
14500 "Large Community list number (expanded)\n"
14501 "Specify large community to reject\n"
14502 "Specify large community to accept\n"
14503 "An ordered list as a regular-expression\n")
14504 {
14505 return lcommunity_list_set_vty(vty, argc, argv,
14506 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14507 }
14508
14509 ALIAS (lcommunity_list_expanded,
14510 ip_lcommunity_list_expanded_cmd,
14511 "ip large-community-list (100-500) <deny|permit> LINE...",
14512 IP_STR
14513 LCOMMUNITY_LIST_STR
14514 "Large Community list number (expanded)\n"
14515 "Specify large community to reject\n"
14516 "Specify large community to accept\n"
14517 "An ordered list as a regular-expression\n")
14518
14519 DEFUN (lcommunity_list_name_standard,
14520 bgp_lcommunity_list_name_standard_cmd,
14521 "bgp large-community-list standard WORD <deny|permit>",
14522 BGP_STR
14523 LCOMMUNITY_LIST_STR
14524 "Specify standard large-community-list\n"
14525 "Large Community list name\n"
14526 "Specify large community to reject\n"
14527 "Specify large community to accept\n")
14528 {
14529 return lcommunity_list_set_vty(vty, argc, argv,
14530 LARGE_COMMUNITY_LIST_STANDARD, 1);
14531 }
14532
14533 ALIAS (lcommunity_list_name_standard,
14534 ip_lcommunity_list_name_standard_cmd,
14535 "ip large-community-list standard WORD <deny|permit>",
14536 IP_STR
14537 LCOMMUNITY_LIST_STR
14538 "Specify standard large-community-list\n"
14539 "Large Community list name\n"
14540 "Specify large community to reject\n"
14541 "Specify large community to accept\n")
14542
14543 DEFUN (lcommunity_list_name_standard1,
14544 bgp_lcommunity_list_name_standard1_cmd,
14545 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14546 BGP_STR
14547 LCOMMUNITY_LIST_STR
14548 "Specify standard large-community-list\n"
14549 "Large Community list name\n"
14550 "Specify large community to reject\n"
14551 "Specify large community to accept\n"
14552 LCOMMUNITY_VAL_STR)
14553 {
14554 return lcommunity_list_set_vty(vty, argc, argv,
14555 LARGE_COMMUNITY_LIST_STANDARD, 1);
14556 }
14557
14558 ALIAS (lcommunity_list_name_standard1,
14559 ip_lcommunity_list_name_standard1_cmd,
14560 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14561 IP_STR
14562 LCOMMUNITY_LIST_STR
14563 "Specify standard large-community-list\n"
14564 "Large Community list name\n"
14565 "Specify large community to reject\n"
14566 "Specify large community to accept\n"
14567 LCOMMUNITY_VAL_STR)
14568
14569 DEFUN (lcommunity_list_name_expanded,
14570 bgp_lcommunity_list_name_expanded_cmd,
14571 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14572 BGP_STR
14573 LCOMMUNITY_LIST_STR
14574 "Specify expanded large-community-list\n"
14575 "Large Community list name\n"
14576 "Specify large community to reject\n"
14577 "Specify large community to accept\n"
14578 "An ordered list as a regular-expression\n")
14579 {
14580 return lcommunity_list_set_vty(vty, argc, argv,
14581 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14582 }
14583
14584 ALIAS (lcommunity_list_name_expanded,
14585 ip_lcommunity_list_name_expanded_cmd,
14586 "ip large-community-list expanded WORD <deny|permit> LINE...",
14587 IP_STR
14588 LCOMMUNITY_LIST_STR
14589 "Specify expanded large-community-list\n"
14590 "Large Community list name\n"
14591 "Specify large community to reject\n"
14592 "Specify large community to accept\n"
14593 "An ordered list as a regular-expression\n")
14594
14595 DEFUN (no_lcommunity_list_standard_all,
14596 no_bgp_lcommunity_list_standard_all_cmd,
14597 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14598 NO_STR
14599 BGP_STR
14600 LCOMMUNITY_LIST_STR
14601 "Large Community list number (standard)\n"
14602 "Large Community list number (expanded)\n"
14603 "Large Community list name\n")
14604 {
14605 return lcommunity_list_unset_vty(vty, argc, argv,
14606 LARGE_COMMUNITY_LIST_STANDARD);
14607 }
14608
14609 ALIAS (no_lcommunity_list_standard_all,
14610 no_ip_lcommunity_list_standard_all_cmd,
14611 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14612 NO_STR
14613 IP_STR
14614 LCOMMUNITY_LIST_STR
14615 "Large Community list number (standard)\n"
14616 "Large Community list number (expanded)\n"
14617 "Large Community list name\n")
14618
14619 DEFUN (no_lcommunity_list_name_expanded_all,
14620 no_bgp_lcommunity_list_name_expanded_all_cmd,
14621 "no bgp large-community-list expanded WORD",
14622 NO_STR
14623 BGP_STR
14624 LCOMMUNITY_LIST_STR
14625 "Specify expanded large-community-list\n"
14626 "Large Community list name\n")
14627 {
14628 return lcommunity_list_unset_vty(vty, argc, argv,
14629 LARGE_COMMUNITY_LIST_EXPANDED);
14630 }
14631
14632 ALIAS (no_lcommunity_list_name_expanded_all,
14633 no_ip_lcommunity_list_name_expanded_all_cmd,
14634 "no ip large-community-list expanded WORD",
14635 NO_STR
14636 IP_STR
14637 LCOMMUNITY_LIST_STR
14638 "Specify expanded large-community-list\n"
14639 "Large Community list name\n")
14640
14641 DEFUN (no_lcommunity_list_standard,
14642 no_bgp_lcommunity_list_standard_cmd,
14643 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14644 NO_STR
14645 BGP_STR
14646 LCOMMUNITY_LIST_STR
14647 "Large Community list number (standard)\n"
14648 "Specify large community to reject\n"
14649 "Specify large community to accept\n"
14650 LCOMMUNITY_VAL_STR)
14651 {
14652 return lcommunity_list_unset_vty(vty, argc, argv,
14653 LARGE_COMMUNITY_LIST_STANDARD);
14654 }
14655
14656 ALIAS (no_lcommunity_list_standard,
14657 no_ip_lcommunity_list_standard_cmd,
14658 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14659 NO_STR
14660 IP_STR
14661 LCOMMUNITY_LIST_STR
14662 "Large Community list number (standard)\n"
14663 "Specify large community to reject\n"
14664 "Specify large community to accept\n"
14665 LCOMMUNITY_VAL_STR)
14666
14667 DEFUN (no_lcommunity_list_expanded,
14668 no_bgp_lcommunity_list_expanded_cmd,
14669 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14670 NO_STR
14671 BGP_STR
14672 LCOMMUNITY_LIST_STR
14673 "Large Community list number (expanded)\n"
14674 "Specify large community to reject\n"
14675 "Specify large community to accept\n"
14676 "An ordered list as a regular-expression\n")
14677 {
14678 return lcommunity_list_unset_vty(vty, argc, argv,
14679 LARGE_COMMUNITY_LIST_EXPANDED);
14680 }
14681
14682 ALIAS (no_lcommunity_list_expanded,
14683 no_ip_lcommunity_list_expanded_cmd,
14684 "no ip large-community-list (100-500) <deny|permit> LINE...",
14685 NO_STR
14686 IP_STR
14687 LCOMMUNITY_LIST_STR
14688 "Large Community list number (expanded)\n"
14689 "Specify large community to reject\n"
14690 "Specify large community to accept\n"
14691 "An ordered list as a regular-expression\n")
14692
14693 DEFUN (no_lcommunity_list_name_standard,
14694 no_bgp_lcommunity_list_name_standard_cmd,
14695 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14696 NO_STR
14697 BGP_STR
14698 LCOMMUNITY_LIST_STR
14699 "Specify standard large-community-list\n"
14700 "Large Community list name\n"
14701 "Specify large community to reject\n"
14702 "Specify large community to accept\n"
14703 LCOMMUNITY_VAL_STR)
14704 {
14705 return lcommunity_list_unset_vty(vty, argc, argv,
14706 LARGE_COMMUNITY_LIST_STANDARD);
14707 }
14708
14709 ALIAS (no_lcommunity_list_name_standard,
14710 no_ip_lcommunity_list_name_standard_cmd,
14711 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14712 NO_STR
14713 IP_STR
14714 LCOMMUNITY_LIST_STR
14715 "Specify standard large-community-list\n"
14716 "Large Community list name\n"
14717 "Specify large community to reject\n"
14718 "Specify large community to accept\n"
14719 LCOMMUNITY_VAL_STR)
14720
14721 DEFUN (no_lcommunity_list_name_expanded,
14722 no_bgp_lcommunity_list_name_expanded_cmd,
14723 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14724 NO_STR
14725 BGP_STR
14726 LCOMMUNITY_LIST_STR
14727 "Specify expanded large-community-list\n"
14728 "Large community list name\n"
14729 "Specify large community to reject\n"
14730 "Specify large community to accept\n"
14731 "An ordered list as a regular-expression\n")
14732 {
14733 return lcommunity_list_unset_vty(vty, argc, argv,
14734 LARGE_COMMUNITY_LIST_EXPANDED);
14735 }
14736
14737 ALIAS (no_lcommunity_list_name_expanded,
14738 no_ip_lcommunity_list_name_expanded_cmd,
14739 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14740 NO_STR
14741 IP_STR
14742 LCOMMUNITY_LIST_STR
14743 "Specify expanded large-community-list\n"
14744 "Large community list name\n"
14745 "Specify large community to reject\n"
14746 "Specify large community to accept\n"
14747 "An ordered list as a regular-expression\n")
14748
14749 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14750 {
14751 struct community_entry *entry;
14752
14753 for (entry = list->head; entry; entry = entry->next) {
14754 if (entry == list->head) {
14755 if (all_digit(list->name))
14756 vty_out(vty, "Large community %s list %s\n",
14757 entry->style == EXTCOMMUNITY_LIST_STANDARD
14758 ? "standard"
14759 : "(expanded) access",
14760 list->name);
14761 else
14762 vty_out(vty,
14763 "Named large community %s list %s\n",
14764 entry->style == EXTCOMMUNITY_LIST_STANDARD
14765 ? "standard"
14766 : "expanded",
14767 list->name);
14768 }
14769 if (entry->any)
14770 vty_out(vty, " %s\n",
14771 community_direct_str(entry->direct));
14772 else
14773 vty_out(vty, " %s %s\n",
14774 community_direct_str(entry->direct),
14775 community_list_config_str(entry));
14776 }
14777 }
14778
14779 DEFUN (show_lcommunity_list,
14780 show_bgp_lcommunity_list_cmd,
14781 "show bgp large-community-list",
14782 SHOW_STR
14783 BGP_STR
14784 "List large-community list\n")
14785 {
14786 struct community_list *list;
14787 struct community_list_master *cm;
14788 int idx = 0;
14789
14790 if (argv_find(argv, argc, "ip", &idx)) {
14791 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14792 vty_out(vty, "if you are using this please migrate to the below command.\n");
14793 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14794 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14795 }
14796
14797 cm = community_list_master_lookup(bgp_clist,
14798 LARGE_COMMUNITY_LIST_MASTER);
14799 if (!cm)
14800 return CMD_SUCCESS;
14801
14802 for (list = cm->num.head; list; list = list->next)
14803 lcommunity_list_show(vty, list);
14804
14805 for (list = cm->str.head; list; list = list->next)
14806 lcommunity_list_show(vty, list);
14807
14808 return CMD_SUCCESS;
14809 }
14810
14811 ALIAS (show_lcommunity_list,
14812 show_ip_lcommunity_list_cmd,
14813 "show ip large-community-list",
14814 SHOW_STR
14815 IP_STR
14816 "List large-community list\n")
14817
14818 DEFUN (show_lcommunity_list_arg,
14819 show_bgp_lcommunity_list_arg_cmd,
14820 "show bgp large-community-list <(1-500)|WORD>",
14821 SHOW_STR
14822 BGP_STR
14823 "List large-community list\n"
14824 "large-community-list number\n"
14825 "large-community-list name\n")
14826 {
14827 struct community_list *list;
14828 int idx = 0;
14829
14830 if (argv_find(argv, argc, "ip", &idx)) {
14831 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14832 vty_out(vty, "if you are using this please migrate to the below command.\n");
14833 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14834 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14835 }
14836
14837 list = community_list_lookup(bgp_clist, argv[3]->arg,
14838 LARGE_COMMUNITY_LIST_MASTER);
14839 if (!list) {
14840 vty_out(vty, "%% Can't find extcommunity-list\n");
14841 return CMD_WARNING;
14842 }
14843
14844 lcommunity_list_show(vty, list);
14845
14846 return CMD_SUCCESS;
14847 }
14848
14849 ALIAS (show_lcommunity_list_arg,
14850 show_ip_lcommunity_list_arg_cmd,
14851 "show ip large-community-list <(1-500)|WORD>",
14852 SHOW_STR
14853 IP_STR
14854 "List large-community list\n"
14855 "large-community-list number\n"
14856 "large-community-list name\n")
14857
14858 /* "extcommunity-list" keyword help string. */
14859 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14860 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14861
14862 DEFUN (extcommunity_list_standard,
14863 bgp_extcommunity_list_standard_cmd,
14864 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14865 BGP_STR
14866 EXTCOMMUNITY_LIST_STR
14867 "Extended Community list number (standard)\n"
14868 "Specify standard extcommunity-list\n"
14869 "Community list name\n"
14870 "Specify community to reject\n"
14871 "Specify community to accept\n"
14872 EXTCOMMUNITY_VAL_STR)
14873 {
14874 int style = EXTCOMMUNITY_LIST_STANDARD;
14875 int direct = 0;
14876 char *cl_number_or_name = NULL;
14877
14878 int idx = 0;
14879 if (argv_find(argv, argc, "ip", &idx)) {
14880 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14881 vty_out(vty, "if you are using this please migrate to the below command.\n");
14882 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14883 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14884 }
14885 argv_find(argv, argc, "(1-99)", &idx);
14886 argv_find(argv, argc, "WORD", &idx);
14887 cl_number_or_name = argv[idx]->arg;
14888 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14889 : COMMUNITY_DENY;
14890 argv_find(argv, argc, "AA:NN", &idx);
14891 char *str = argv_concat(argv, argc, idx);
14892
14893 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14894 direct, style);
14895
14896 XFREE(MTYPE_TMP, str);
14897
14898 if (ret < 0) {
14899 community_list_perror(vty, ret);
14900 return CMD_WARNING_CONFIG_FAILED;
14901 }
14902
14903 return CMD_SUCCESS;
14904 }
14905
14906 #if CONFDATE > 20191005
14907 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14908 #endif
14909 ALIAS (extcommunity_list_standard,
14910 ip_extcommunity_list_standard_cmd,
14911 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14912 IP_STR
14913 EXTCOMMUNITY_LIST_STR
14914 "Extended Community list number (standard)\n"
14915 "Specify standard extcommunity-list\n"
14916 "Community list name\n"
14917 "Specify community to reject\n"
14918 "Specify community to accept\n"
14919 EXTCOMMUNITY_VAL_STR)
14920
14921 DEFUN (extcommunity_list_name_expanded,
14922 bgp_extcommunity_list_name_expanded_cmd,
14923 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14924 BGP_STR
14925 EXTCOMMUNITY_LIST_STR
14926 "Extended Community list number (expanded)\n"
14927 "Specify expanded extcommunity-list\n"
14928 "Extended Community list name\n"
14929 "Specify community to reject\n"
14930 "Specify community to accept\n"
14931 "An ordered list as a regular-expression\n")
14932 {
14933 int style = EXTCOMMUNITY_LIST_EXPANDED;
14934 int direct = 0;
14935 char *cl_number_or_name = NULL;
14936
14937 int idx = 0;
14938 if (argv_find(argv, argc, "ip", &idx)) {
14939 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14940 vty_out(vty, "if you are using this please migrate to the below command.\n");
14941 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14942 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14943 }
14944
14945 argv_find(argv, argc, "(100-500)", &idx);
14946 argv_find(argv, argc, "WORD", &idx);
14947 cl_number_or_name = argv[idx]->arg;
14948 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14949 : COMMUNITY_DENY;
14950 argv_find(argv, argc, "LINE", &idx);
14951 char *str = argv_concat(argv, argc, idx);
14952
14953 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14954 direct, style);
14955
14956 XFREE(MTYPE_TMP, str);
14957
14958 if (ret < 0) {
14959 community_list_perror(vty, ret);
14960 return CMD_WARNING_CONFIG_FAILED;
14961 }
14962
14963 return CMD_SUCCESS;
14964 }
14965
14966 ALIAS (extcommunity_list_name_expanded,
14967 ip_extcommunity_list_name_expanded_cmd,
14968 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14969 IP_STR
14970 EXTCOMMUNITY_LIST_STR
14971 "Extended Community list number (expanded)\n"
14972 "Specify expanded extcommunity-list\n"
14973 "Extended Community list name\n"
14974 "Specify community to reject\n"
14975 "Specify community to accept\n"
14976 "An ordered list as a regular-expression\n")
14977
14978 DEFUN (no_extcommunity_list_standard_all,
14979 no_bgp_extcommunity_list_standard_all_cmd,
14980 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14981 NO_STR
14982 BGP_STR
14983 EXTCOMMUNITY_LIST_STR
14984 "Extended Community list number (standard)\n"
14985 "Specify standard extcommunity-list\n"
14986 "Community list name\n"
14987 "Specify community to reject\n"
14988 "Specify community to accept\n"
14989 EXTCOMMUNITY_VAL_STR)
14990 {
14991 int style = EXTCOMMUNITY_LIST_STANDARD;
14992 int direct = 0;
14993 char *cl_number_or_name = NULL;
14994 char *str = NULL;
14995
14996 int idx = 0;
14997 if (argv_find(argv, argc, "ip", &idx)) {
14998 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14999 vty_out(vty, "if you are using this please migrate to the below command.\n");
15000 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15001 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15002 }
15003
15004 idx = 0;
15005 argv_find(argv, argc, "permit", &idx);
15006 argv_find(argv, argc, "deny", &idx);
15007
15008 if (idx) {
15009 direct = argv_find(argv, argc, "permit", &idx)
15010 ? COMMUNITY_PERMIT
15011 : COMMUNITY_DENY;
15012
15013 idx = 0;
15014 argv_find(argv, argc, "AA:NN", &idx);
15015 str = argv_concat(argv, argc, idx);
15016 }
15017
15018 idx = 0;
15019 argv_find(argv, argc, "(1-99)", &idx);
15020 argv_find(argv, argc, "WORD", &idx);
15021 cl_number_or_name = argv[idx]->arg;
15022
15023 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15024 direct, style);
15025
15026 XFREE(MTYPE_TMP, str);
15027
15028 if (ret < 0) {
15029 community_list_perror(vty, ret);
15030 return CMD_WARNING_CONFIG_FAILED;
15031 }
15032
15033 return CMD_SUCCESS;
15034 }
15035
15036 ALIAS (no_extcommunity_list_standard_all,
15037 no_ip_extcommunity_list_standard_all_cmd,
15038 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15039 NO_STR
15040 IP_STR
15041 EXTCOMMUNITY_LIST_STR
15042 "Extended Community list number (standard)\n"
15043 "Specify standard extcommunity-list\n"
15044 "Community list name\n"
15045 "Specify community to reject\n"
15046 "Specify community to accept\n"
15047 EXTCOMMUNITY_VAL_STR)
15048
15049 ALIAS(no_extcommunity_list_standard_all,
15050 no_bgp_extcommunity_list_standard_all_list_cmd,
15051 "no bgp extcommunity-list <(1-99)|standard WORD>",
15052 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15053 "Extended Community list number (standard)\n"
15054 "Specify standard extcommunity-list\n"
15055 "Community list name\n")
15056
15057 ALIAS(no_extcommunity_list_standard_all,
15058 no_ip_extcommunity_list_standard_all_list_cmd,
15059 "no ip extcommunity-list <(1-99)|standard WORD>",
15060 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15061 "Extended Community list number (standard)\n"
15062 "Specify standard extcommunity-list\n"
15063 "Community list name\n")
15064
15065 DEFUN (no_extcommunity_list_expanded_all,
15066 no_bgp_extcommunity_list_expanded_all_cmd,
15067 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15068 NO_STR
15069 BGP_STR
15070 EXTCOMMUNITY_LIST_STR
15071 "Extended Community list number (expanded)\n"
15072 "Specify expanded extcommunity-list\n"
15073 "Extended Community list name\n"
15074 "Specify community to reject\n"
15075 "Specify community to accept\n"
15076 "An ordered list as a regular-expression\n")
15077 {
15078 int style = EXTCOMMUNITY_LIST_EXPANDED;
15079 int direct = 0;
15080 char *cl_number_or_name = NULL;
15081 char *str = NULL;
15082
15083 int idx = 0;
15084 if (argv_find(argv, argc, "ip", &idx)) {
15085 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15086 vty_out(vty, "if you are using this please migrate to the below command.\n");
15087 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15088 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15089 }
15090
15091 idx = 0;
15092 argv_find(argv, argc, "permit", &idx);
15093 argv_find(argv, argc, "deny", &idx);
15094
15095 if (idx) {
15096 direct = argv_find(argv, argc, "permit", &idx)
15097 ? COMMUNITY_PERMIT
15098 : COMMUNITY_DENY;
15099
15100 idx = 0;
15101 argv_find(argv, argc, "LINE", &idx);
15102 str = argv_concat(argv, argc, idx);
15103 }
15104
15105 idx = 0;
15106 argv_find(argv, argc, "(100-500)", &idx);
15107 argv_find(argv, argc, "WORD", &idx);
15108 cl_number_or_name = argv[idx]->arg;
15109
15110 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15111 direct, style);
15112
15113 XFREE(MTYPE_TMP, str);
15114
15115 if (ret < 0) {
15116 community_list_perror(vty, ret);
15117 return CMD_WARNING_CONFIG_FAILED;
15118 }
15119
15120 return CMD_SUCCESS;
15121 }
15122
15123 ALIAS (no_extcommunity_list_expanded_all,
15124 no_ip_extcommunity_list_expanded_all_cmd,
15125 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15126 NO_STR
15127 IP_STR
15128 EXTCOMMUNITY_LIST_STR
15129 "Extended Community list number (expanded)\n"
15130 "Specify expanded extcommunity-list\n"
15131 "Extended Community list name\n"
15132 "Specify community to reject\n"
15133 "Specify community to accept\n"
15134 "An ordered list as a regular-expression\n")
15135
15136 ALIAS(no_extcommunity_list_expanded_all,
15137 no_ip_extcommunity_list_expanded_all_list_cmd,
15138 "no ip extcommunity-list <(100-500)|expanded WORD>",
15139 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15140 "Extended Community list number (expanded)\n"
15141 "Specify expanded extcommunity-list\n"
15142 "Extended Community list name\n")
15143
15144 ALIAS(no_extcommunity_list_expanded_all,
15145 no_bgp_extcommunity_list_expanded_all_list_cmd,
15146 "no bgp extcommunity-list <(100-500)|expanded WORD>",
15147 NO_STR IP_STR EXTCOMMUNITY_LIST_STR
15148 "Extended Community list number (expanded)\n"
15149 "Specify expanded extcommunity-list\n"
15150 "Extended Community list name\n")
15151
15152 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15153 {
15154 struct community_entry *entry;
15155
15156 for (entry = list->head; entry; entry = entry->next) {
15157 if (entry == list->head) {
15158 if (all_digit(list->name))
15159 vty_out(vty, "Extended community %s list %s\n",
15160 entry->style == EXTCOMMUNITY_LIST_STANDARD
15161 ? "standard"
15162 : "(expanded) access",
15163 list->name);
15164 else
15165 vty_out(vty,
15166 "Named extended community %s list %s\n",
15167 entry->style == EXTCOMMUNITY_LIST_STANDARD
15168 ? "standard"
15169 : "expanded",
15170 list->name);
15171 }
15172 if (entry->any)
15173 vty_out(vty, " %s\n",
15174 community_direct_str(entry->direct));
15175 else
15176 vty_out(vty, " %s %s\n",
15177 community_direct_str(entry->direct),
15178 community_list_config_str(entry));
15179 }
15180 }
15181
15182 DEFUN (show_extcommunity_list,
15183 show_bgp_extcommunity_list_cmd,
15184 "show bgp extcommunity-list",
15185 SHOW_STR
15186 BGP_STR
15187 "List extended-community list\n")
15188 {
15189 struct community_list *list;
15190 struct community_list_master *cm;
15191 int idx = 0;
15192
15193 if (argv_find(argv, argc, "ip", &idx)) {
15194 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15195 vty_out(vty, "if you are using this please migrate to the below command.\n");
15196 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15197 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15198 }
15199 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15200 if (!cm)
15201 return CMD_SUCCESS;
15202
15203 for (list = cm->num.head; list; list = list->next)
15204 extcommunity_list_show(vty, list);
15205
15206 for (list = cm->str.head; list; list = list->next)
15207 extcommunity_list_show(vty, list);
15208
15209 return CMD_SUCCESS;
15210 }
15211
15212 ALIAS (show_extcommunity_list,
15213 show_ip_extcommunity_list_cmd,
15214 "show ip extcommunity-list",
15215 SHOW_STR
15216 IP_STR
15217 "List extended-community list\n")
15218
15219 DEFUN (show_extcommunity_list_arg,
15220 show_bgp_extcommunity_list_arg_cmd,
15221 "show bgp extcommunity-list <(1-500)|WORD>",
15222 SHOW_STR
15223 BGP_STR
15224 "List extended-community list\n"
15225 "Extcommunity-list number\n"
15226 "Extcommunity-list name\n")
15227 {
15228 int idx_comm_list = 3;
15229 struct community_list *list;
15230 int idx = 0;
15231
15232 if (argv_find(argv, argc, "ip", &idx)) {
15233 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15234 vty_out(vty, "if you are using this please migrate to the below command.\n");
15235 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15236 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15237 }
15238 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
15239 EXTCOMMUNITY_LIST_MASTER);
15240 if (!list) {
15241 vty_out(vty, "%% Can't find extcommunity-list\n");
15242 return CMD_WARNING;
15243 }
15244
15245 extcommunity_list_show(vty, list);
15246
15247 return CMD_SUCCESS;
15248 }
15249
15250 ALIAS (show_extcommunity_list_arg,
15251 show_ip_extcommunity_list_arg_cmd,
15252 "show ip extcommunity-list <(1-500)|WORD>",
15253 SHOW_STR
15254 IP_STR
15255 "List extended-community list\n"
15256 "Extcommunity-list number\n"
15257 "Extcommunity-list name\n")
15258
15259 /* Display community-list and extcommunity-list configuration. */
15260 static int community_list_config_write(struct vty *vty)
15261 {
15262 struct community_list *list;
15263 struct community_entry *entry;
15264 struct community_list_master *cm;
15265 int write = 0;
15266
15267 /* Community-list. */
15268 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15269
15270 for (list = cm->num.head; list; list = list->next)
15271 for (entry = list->head; entry; entry = entry->next) {
15272 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15273 community_direct_str(entry->direct),
15274 community_list_config_str(entry));
15275 write++;
15276 }
15277 for (list = cm->str.head; list; list = list->next)
15278 for (entry = list->head; entry; entry = entry->next) {
15279 vty_out(vty, "bgp community-list %s %s %s %s\n",
15280 entry->style == COMMUNITY_LIST_STANDARD
15281 ? "standard"
15282 : "expanded",
15283 list->name, community_direct_str(entry->direct),
15284 community_list_config_str(entry));
15285 write++;
15286 }
15287
15288 /* Extcommunity-list. */
15289 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15290
15291 for (list = cm->num.head; list; list = list->next)
15292 for (entry = list->head; entry; entry = entry->next) {
15293 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15294 list->name, community_direct_str(entry->direct),
15295 community_list_config_str(entry));
15296 write++;
15297 }
15298 for (list = cm->str.head; list; list = list->next)
15299 for (entry = list->head; entry; entry = entry->next) {
15300 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15301 entry->style == EXTCOMMUNITY_LIST_STANDARD
15302 ? "standard"
15303 : "expanded",
15304 list->name, community_direct_str(entry->direct),
15305 community_list_config_str(entry));
15306 write++;
15307 }
15308
15309
15310 /* lcommunity-list. */
15311 cm = community_list_master_lookup(bgp_clist,
15312 LARGE_COMMUNITY_LIST_MASTER);
15313
15314 for (list = cm->num.head; list; list = list->next)
15315 for (entry = list->head; entry; entry = entry->next) {
15316 vty_out(vty, "bgp large-community-list %s %s %s\n",
15317 list->name, community_direct_str(entry->direct),
15318 community_list_config_str(entry));
15319 write++;
15320 }
15321 for (list = cm->str.head; list; list = list->next)
15322 for (entry = list->head; entry; entry = entry->next) {
15323 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15324 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15325 ? "standard"
15326 : "expanded",
15327 list->name, community_direct_str(entry->direct),
15328 community_list_config_str(entry));
15329 write++;
15330 }
15331
15332 return write;
15333 }
15334
15335 static struct cmd_node community_list_node = {
15336 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15337 };
15338
15339 static void community_list_vty(void)
15340 {
15341 install_node(&community_list_node, community_list_config_write);
15342
15343 /* Community-list. */
15344 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15345 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15346 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15347 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15348 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15349 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15350 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15351 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15352 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15353 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15354 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15355 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15356 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15357 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15358 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15359 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15360
15361 /* Extcommunity-list. */
15362 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15363 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15364 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15365 install_element(CONFIG_NODE,
15366 &no_bgp_extcommunity_list_standard_all_list_cmd);
15367 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15368 install_element(CONFIG_NODE,
15369 &no_bgp_extcommunity_list_expanded_all_list_cmd);
15370 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15371 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15372 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15373 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15374 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15375 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_list_cmd);
15376 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15377 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_list_cmd);
15378 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15379 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15380
15381 /* Large Community List */
15382 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15383 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15384 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15385 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15386 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15387 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15388 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15389 install_element(CONFIG_NODE,
15390 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15391 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15392 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15393 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15394 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15395 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15396 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15397 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15398 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15399 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15400 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15401 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15402 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15403 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15404 install_element(CONFIG_NODE,
15405 &no_ip_lcommunity_list_name_expanded_all_cmd);
15406 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15407 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15408 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15409 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15410 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15411 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15412 }