]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #3344 from ton31337/fix/optional_args_for_community-lists
[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",
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 ret;
976 as_t as;
977 struct bgp *bgp;
978 const char *name = NULL;
979 enum bgp_instance_type inst_type;
980
981 // "router bgp" without an ASN
982 if (argc == 2) {
983 // Pending: Make VRF option available for ASN less config
984 bgp = bgp_get_default();
985
986 if (bgp == NULL) {
987 vty_out(vty, "%% No BGP process is configured\n");
988 return CMD_WARNING_CONFIG_FAILED;
989 }
990
991 if (listcount(bm->bgp) > 1) {
992 vty_out(vty, "%% Please specify ASN and VRF\n");
993 return CMD_WARNING_CONFIG_FAILED;
994 }
995 }
996
997 // "router bgp X"
998 else {
999 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1000
1001 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1002 if (argc > 3) {
1003 name = argv[idx_vrf]->arg;
1004
1005 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1006 if (strmatch(name, VRF_DEFAULT_NAME))
1007 name = NULL;
1008 else
1009 inst_type = BGP_INSTANCE_TYPE_VRF;
1010 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1011 inst_type = BGP_INSTANCE_TYPE_VIEW;
1012 }
1013
1014 ret = bgp_get(&bgp, &as, name, inst_type);
1015 switch (ret) {
1016 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1017 vty_out(vty,
1018 "Please specify 'bgp multiple-instance' first\n");
1019 return CMD_WARNING_CONFIG_FAILED;
1020 case BGP_ERR_AS_MISMATCH:
1021 vty_out(vty, "BGP is already running; AS is %u\n", as);
1022 return CMD_WARNING_CONFIG_FAILED;
1023 case BGP_ERR_INSTANCE_MISMATCH:
1024 vty_out(vty,
1025 "BGP instance name and AS number mismatch\n");
1026 vty_out(vty,
1027 "BGP instance is already running; AS is %u\n",
1028 as);
1029 return CMD_WARNING_CONFIG_FAILED;
1030 }
1031
1032 /*
1033 * If we just instantiated the default instance, complete
1034 * any pending VRF-VPN leaking that was configured via
1035 * earlier "router bgp X vrf FOO" blocks.
1036 */
1037 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1038 vpn_leak_postchange_all();
1039
1040 /* Pending: handle when user tries to change a view to vrf n vv.
1041 */
1042 }
1043
1044 /* unset the auto created flag as the user config is now present */
1045 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1046 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1047
1048 return CMD_SUCCESS;
1049 }
1050
1051 /* "no router bgp" commands. */
1052 DEFUN (no_router_bgp,
1053 no_router_bgp_cmd,
1054 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1055 NO_STR
1056 ROUTER_STR
1057 BGP_STR
1058 AS_STR
1059 BGP_INSTANCE_HELP_STR)
1060 {
1061 int idx_asn = 3;
1062 int idx_vrf = 5;
1063 as_t as;
1064 struct bgp *bgp;
1065 const char *name = NULL;
1066
1067 // "no router bgp" without an ASN
1068 if (argc == 3) {
1069 // Pending: Make VRF option available for ASN less config
1070 bgp = bgp_get_default();
1071
1072 if (bgp == NULL) {
1073 vty_out(vty, "%% No BGP process is configured\n");
1074 return CMD_WARNING_CONFIG_FAILED;
1075 }
1076
1077 if (listcount(bm->bgp) > 1) {
1078 vty_out(vty, "%% Please specify ASN and VRF\n");
1079 return CMD_WARNING_CONFIG_FAILED;
1080 }
1081
1082 if (bgp->l3vni) {
1083 vty_out(vty, "%% Please unconfigure l3vni %u",
1084 bgp->l3vni);
1085 return CMD_WARNING_CONFIG_FAILED;
1086 }
1087 } else {
1088 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1089
1090 if (argc > 4)
1091 name = argv[idx_vrf]->arg;
1092
1093 /* Lookup bgp structure. */
1094 bgp = bgp_lookup(as, name);
1095 if (!bgp) {
1096 vty_out(vty, "%% Can't find BGP instance\n");
1097 return CMD_WARNING_CONFIG_FAILED;
1098 }
1099
1100 if (bgp->l3vni) {
1101 vty_out(vty, "%% Please unconfigure l3vni %u",
1102 bgp->l3vni);
1103 return CMD_WARNING_CONFIG_FAILED;
1104 }
1105 }
1106
1107 bgp_delete(bgp);
1108
1109 return CMD_SUCCESS;
1110 }
1111
1112
1113 /* BGP router-id. */
1114
1115 DEFPY (bgp_router_id,
1116 bgp_router_id_cmd,
1117 "bgp router-id A.B.C.D",
1118 BGP_STR
1119 "Override configured router identifier\n"
1120 "Manually configured router identifier\n")
1121 {
1122 VTY_DECLVAR_CONTEXT(bgp, bgp);
1123 bgp_router_id_static_set(bgp, router_id);
1124 return CMD_SUCCESS;
1125 }
1126
1127 DEFPY (no_bgp_router_id,
1128 no_bgp_router_id_cmd,
1129 "no bgp router-id [A.B.C.D]",
1130 NO_STR
1131 BGP_STR
1132 "Override configured router identifier\n"
1133 "Manually configured router identifier\n")
1134 {
1135 VTY_DECLVAR_CONTEXT(bgp, bgp);
1136
1137 if (router_id_str) {
1138 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1139 vty_out(vty, "%% BGP router-id doesn't match\n");
1140 return CMD_WARNING_CONFIG_FAILED;
1141 }
1142 }
1143
1144 router_id.s_addr = 0;
1145 bgp_router_id_static_set(bgp, router_id);
1146
1147 return CMD_SUCCESS;
1148 }
1149
1150
1151 /* BGP Cluster ID. */
1152 DEFUN (bgp_cluster_id,
1153 bgp_cluster_id_cmd,
1154 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1155 BGP_STR
1156 "Configure Route-Reflector Cluster-id\n"
1157 "Route-Reflector Cluster-id in IP address format\n"
1158 "Route-Reflector Cluster-id as 32 bit quantity\n")
1159 {
1160 VTY_DECLVAR_CONTEXT(bgp, bgp);
1161 int idx_ipv4 = 2;
1162 int ret;
1163 struct in_addr cluster;
1164
1165 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1166 if (!ret) {
1167 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1168 return CMD_WARNING_CONFIG_FAILED;
1169 }
1170
1171 bgp_cluster_id_set(bgp, &cluster);
1172 bgp_clear_star_soft_out(vty, bgp->name);
1173
1174 return CMD_SUCCESS;
1175 }
1176
1177 DEFUN (no_bgp_cluster_id,
1178 no_bgp_cluster_id_cmd,
1179 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1180 NO_STR
1181 BGP_STR
1182 "Configure Route-Reflector Cluster-id\n"
1183 "Route-Reflector Cluster-id in IP address format\n"
1184 "Route-Reflector Cluster-id as 32 bit quantity\n")
1185 {
1186 VTY_DECLVAR_CONTEXT(bgp, bgp);
1187 bgp_cluster_id_unset(bgp);
1188 bgp_clear_star_soft_out(vty, bgp->name);
1189
1190 return CMD_SUCCESS;
1191 }
1192
1193 DEFUN (bgp_confederation_identifier,
1194 bgp_confederation_identifier_cmd,
1195 "bgp confederation identifier (1-4294967295)",
1196 "BGP specific commands\n"
1197 "AS confederation parameters\n"
1198 "AS number\n"
1199 "Set routing domain confederation AS\n")
1200 {
1201 VTY_DECLVAR_CONTEXT(bgp, bgp);
1202 int idx_number = 3;
1203 as_t as;
1204
1205 as = strtoul(argv[idx_number]->arg, NULL, 10);
1206
1207 bgp_confederation_id_set(bgp, as);
1208
1209 return CMD_SUCCESS;
1210 }
1211
1212 DEFUN (no_bgp_confederation_identifier,
1213 no_bgp_confederation_identifier_cmd,
1214 "no bgp confederation identifier [(1-4294967295)]",
1215 NO_STR
1216 "BGP specific commands\n"
1217 "AS confederation parameters\n"
1218 "AS number\n"
1219 "Set routing domain confederation AS\n")
1220 {
1221 VTY_DECLVAR_CONTEXT(bgp, bgp);
1222 bgp_confederation_id_unset(bgp);
1223
1224 return CMD_SUCCESS;
1225 }
1226
1227 DEFUN (bgp_confederation_peers,
1228 bgp_confederation_peers_cmd,
1229 "bgp confederation peers (1-4294967295)...",
1230 "BGP specific commands\n"
1231 "AS confederation parameters\n"
1232 "Peer ASs in BGP confederation\n"
1233 AS_STR)
1234 {
1235 VTY_DECLVAR_CONTEXT(bgp, bgp);
1236 int idx_asn = 3;
1237 as_t as;
1238 int i;
1239
1240 for (i = idx_asn; i < argc; i++) {
1241 as = strtoul(argv[i]->arg, NULL, 10);
1242
1243 if (bgp->as == as) {
1244 vty_out(vty,
1245 "%% Local member-AS not allowed in confed peer list\n");
1246 continue;
1247 }
1248
1249 bgp_confederation_peers_add(bgp, as);
1250 }
1251 return CMD_SUCCESS;
1252 }
1253
1254 DEFUN (no_bgp_confederation_peers,
1255 no_bgp_confederation_peers_cmd,
1256 "no bgp confederation peers (1-4294967295)...",
1257 NO_STR
1258 "BGP specific commands\n"
1259 "AS confederation parameters\n"
1260 "Peer ASs in BGP confederation\n"
1261 AS_STR)
1262 {
1263 VTY_DECLVAR_CONTEXT(bgp, bgp);
1264 int idx_asn = 4;
1265 as_t as;
1266 int i;
1267
1268 for (i = idx_asn; i < argc; i++) {
1269 as = strtoul(argv[i]->arg, NULL, 10);
1270
1271 bgp_confederation_peers_remove(bgp, as);
1272 }
1273 return CMD_SUCCESS;
1274 }
1275
1276 /**
1277 * Central routine for maximum-paths configuration.
1278 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1279 * @set: 1 for setting values, 0 for removing the max-paths config.
1280 */
1281 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1282 const char *mpaths, uint16_t options,
1283 int set)
1284 {
1285 VTY_DECLVAR_CONTEXT(bgp, bgp);
1286 uint16_t maxpaths = 0;
1287 int ret;
1288 afi_t afi;
1289 safi_t safi;
1290
1291 afi = bgp_node_afi(vty);
1292 safi = bgp_node_safi(vty);
1293
1294 if (set) {
1295 maxpaths = strtol(mpaths, NULL, 10);
1296 if (maxpaths > multipath_num) {
1297 vty_out(vty,
1298 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1299 maxpaths, multipath_num);
1300 return CMD_WARNING_CONFIG_FAILED;
1301 }
1302 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1303 options);
1304 } else
1305 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1306
1307 if (ret < 0) {
1308 vty_out(vty,
1309 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1310 (set == 1) ? "" : "un",
1311 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1312 maxpaths, afi, safi);
1313 return CMD_WARNING_CONFIG_FAILED;
1314 }
1315
1316 bgp_recalculate_all_bestpaths(bgp);
1317
1318 return CMD_SUCCESS;
1319 }
1320
1321 DEFUN (bgp_maxmed_admin,
1322 bgp_maxmed_admin_cmd,
1323 "bgp max-med administrative ",
1324 BGP_STR
1325 "Advertise routes with max-med\n"
1326 "Administratively applied, for an indefinite period\n")
1327 {
1328 VTY_DECLVAR_CONTEXT(bgp, bgp);
1329
1330 bgp->v_maxmed_admin = 1;
1331 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1332
1333 bgp_maxmed_update(bgp);
1334
1335 return CMD_SUCCESS;
1336 }
1337
1338 DEFUN (bgp_maxmed_admin_medv,
1339 bgp_maxmed_admin_medv_cmd,
1340 "bgp max-med administrative (0-4294967295)",
1341 BGP_STR
1342 "Advertise routes with max-med\n"
1343 "Administratively applied, for an indefinite period\n"
1344 "Max MED value to be used\n")
1345 {
1346 VTY_DECLVAR_CONTEXT(bgp, bgp);
1347 int idx_number = 3;
1348
1349 bgp->v_maxmed_admin = 1;
1350 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1351
1352 bgp_maxmed_update(bgp);
1353
1354 return CMD_SUCCESS;
1355 }
1356
1357 DEFUN (no_bgp_maxmed_admin,
1358 no_bgp_maxmed_admin_cmd,
1359 "no bgp max-med administrative [(0-4294967295)]",
1360 NO_STR
1361 BGP_STR
1362 "Advertise routes with max-med\n"
1363 "Administratively applied, for an indefinite period\n"
1364 "Max MED value to be used\n")
1365 {
1366 VTY_DECLVAR_CONTEXT(bgp, bgp);
1367 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1368 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1369 bgp_maxmed_update(bgp);
1370
1371 return CMD_SUCCESS;
1372 }
1373
1374 DEFUN (bgp_maxmed_onstartup,
1375 bgp_maxmed_onstartup_cmd,
1376 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1377 BGP_STR
1378 "Advertise routes with max-med\n"
1379 "Effective on a startup\n"
1380 "Time (seconds) period for max-med\n"
1381 "Max MED value to be used\n")
1382 {
1383 VTY_DECLVAR_CONTEXT(bgp, bgp);
1384 int idx = 0;
1385
1386 argv_find(argv, argc, "(5-86400)", &idx);
1387 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1388 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1389 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1390 else
1391 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1392
1393 bgp_maxmed_update(bgp);
1394
1395 return CMD_SUCCESS;
1396 }
1397
1398 DEFUN (no_bgp_maxmed_onstartup,
1399 no_bgp_maxmed_onstartup_cmd,
1400 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1401 NO_STR
1402 BGP_STR
1403 "Advertise routes with max-med\n"
1404 "Effective on a startup\n"
1405 "Time (seconds) period for max-med\n"
1406 "Max MED value to be used\n")
1407 {
1408 VTY_DECLVAR_CONTEXT(bgp, bgp);
1409
1410 /* Cancel max-med onstartup if its on */
1411 if (bgp->t_maxmed_onstartup) {
1412 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1413 bgp->maxmed_onstartup_over = 1;
1414 }
1415
1416 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1417 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1418
1419 bgp_maxmed_update(bgp);
1420
1421 return CMD_SUCCESS;
1422 }
1423
1424 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1425 const char *wait)
1426 {
1427 VTY_DECLVAR_CONTEXT(bgp, bgp);
1428 uint16_t update_delay;
1429 uint16_t establish_wait;
1430
1431 update_delay = strtoul(delay, NULL, 10);
1432
1433 if (!wait) /* update-delay <delay> */
1434 {
1435 bgp->v_update_delay = update_delay;
1436 bgp->v_establish_wait = bgp->v_update_delay;
1437 return CMD_SUCCESS;
1438 }
1439
1440 /* update-delay <delay> <establish-wait> */
1441 establish_wait = atoi(wait);
1442 if (update_delay < establish_wait) {
1443 vty_out(vty,
1444 "%%Failed: update-delay less than the establish-wait!\n");
1445 return CMD_WARNING_CONFIG_FAILED;
1446 }
1447
1448 bgp->v_update_delay = update_delay;
1449 bgp->v_establish_wait = establish_wait;
1450
1451 return CMD_SUCCESS;
1452 }
1453
1454 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1455 {
1456 VTY_DECLVAR_CONTEXT(bgp, bgp);
1457
1458 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1459 bgp->v_establish_wait = bgp->v_update_delay;
1460
1461 return CMD_SUCCESS;
1462 }
1463
1464 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1465 {
1466 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1467 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1468 if (bgp->v_update_delay != bgp->v_establish_wait)
1469 vty_out(vty, " %d", bgp->v_establish_wait);
1470 vty_out(vty, "\n");
1471 }
1472 }
1473
1474
1475 /* Update-delay configuration */
1476 DEFUN (bgp_update_delay,
1477 bgp_update_delay_cmd,
1478 "update-delay (0-3600)",
1479 "Force initial delay for best-path and updates\n"
1480 "Seconds\n")
1481 {
1482 int idx_number = 1;
1483 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1484 }
1485
1486 DEFUN (bgp_update_delay_establish_wait,
1487 bgp_update_delay_establish_wait_cmd,
1488 "update-delay (0-3600) (1-3600)",
1489 "Force initial delay for best-path and updates\n"
1490 "Seconds\n"
1491 "Seconds\n")
1492 {
1493 int idx_number = 1;
1494 int idx_number_2 = 2;
1495 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1496 argv[idx_number_2]->arg);
1497 }
1498
1499 /* Update-delay deconfiguration */
1500 DEFUN (no_bgp_update_delay,
1501 no_bgp_update_delay_cmd,
1502 "no update-delay [(0-3600) [(1-3600)]]",
1503 NO_STR
1504 "Force initial delay for best-path and updates\n"
1505 "Seconds\n"
1506 "Seconds\n")
1507 {
1508 return bgp_update_delay_deconfig_vty(vty);
1509 }
1510
1511
1512 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1513 char set)
1514 {
1515 VTY_DECLVAR_CONTEXT(bgp, bgp);
1516
1517 if (set) {
1518 uint32_t quanta = strtoul(num, NULL, 10);
1519 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1520 memory_order_relaxed);
1521 } else {
1522 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1523 memory_order_relaxed);
1524 }
1525
1526 return CMD_SUCCESS;
1527 }
1528
1529 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1530 char set)
1531 {
1532 VTY_DECLVAR_CONTEXT(bgp, bgp);
1533
1534 if (set) {
1535 uint32_t quanta = strtoul(num, NULL, 10);
1536 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1537 memory_order_relaxed);
1538 } else {
1539 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1540 memory_order_relaxed);
1541 }
1542
1543 return CMD_SUCCESS;
1544 }
1545
1546 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1547 {
1548 uint32_t quanta =
1549 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1550 if (quanta != BGP_WRITE_PACKET_MAX)
1551 vty_out(vty, " write-quanta %d\n", quanta);
1552 }
1553
1554 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1555 {
1556 uint32_t quanta =
1557 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1558 if (quanta != BGP_READ_PACKET_MAX)
1559 vty_out(vty, " read-quanta %d\n", quanta);
1560 }
1561
1562 /* Packet quanta configuration */
1563 DEFUN (bgp_wpkt_quanta,
1564 bgp_wpkt_quanta_cmd,
1565 "write-quanta (1-10)",
1566 "How many packets to write to peer socket per run\n"
1567 "Number of packets\n")
1568 {
1569 int idx_number = 1;
1570 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1571 }
1572
1573 DEFUN (no_bgp_wpkt_quanta,
1574 no_bgp_wpkt_quanta_cmd,
1575 "no write-quanta (1-10)",
1576 NO_STR
1577 "How many packets to write to peer socket per I/O cycle\n"
1578 "Number of packets\n")
1579 {
1580 int idx_number = 2;
1581 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1582 }
1583
1584 DEFUN (bgp_rpkt_quanta,
1585 bgp_rpkt_quanta_cmd,
1586 "read-quanta (1-10)",
1587 "How many packets to read from peer socket per I/O cycle\n"
1588 "Number of packets\n")
1589 {
1590 int idx_number = 1;
1591 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1592 }
1593
1594 DEFUN (no_bgp_rpkt_quanta,
1595 no_bgp_rpkt_quanta_cmd,
1596 "no read-quanta (1-10)",
1597 NO_STR
1598 "How many packets to read from peer socket per I/O cycle\n"
1599 "Number of packets\n")
1600 {
1601 int idx_number = 2;
1602 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1603 }
1604
1605 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1606 {
1607 if (!bgp->heuristic_coalesce)
1608 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1609 }
1610
1611
1612 DEFUN (bgp_coalesce_time,
1613 bgp_coalesce_time_cmd,
1614 "coalesce-time (0-4294967295)",
1615 "Subgroup coalesce timer\n"
1616 "Subgroup coalesce timer value (in ms)\n")
1617 {
1618 VTY_DECLVAR_CONTEXT(bgp, bgp);
1619
1620 int idx = 0;
1621 argv_find(argv, argc, "(0-4294967295)", &idx);
1622 bgp->heuristic_coalesce = false;
1623 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1624 return CMD_SUCCESS;
1625 }
1626
1627 DEFUN (no_bgp_coalesce_time,
1628 no_bgp_coalesce_time_cmd,
1629 "no coalesce-time (0-4294967295)",
1630 NO_STR
1631 "Subgroup coalesce timer\n"
1632 "Subgroup coalesce timer value (in ms)\n")
1633 {
1634 VTY_DECLVAR_CONTEXT(bgp, bgp);
1635
1636 bgp->heuristic_coalesce = true;
1637 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1638 return CMD_SUCCESS;
1639 }
1640
1641 /* Maximum-paths configuration */
1642 DEFUN (bgp_maxpaths,
1643 bgp_maxpaths_cmd,
1644 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1645 "Forward packets over multiple paths\n"
1646 "Number of paths\n")
1647 {
1648 int idx_number = 1;
1649 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1650 argv[idx_number]->arg, 0, 1);
1651 }
1652
1653 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1654 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1655 "Forward packets over multiple paths\n"
1656 "Number of paths\n")
1657
1658 DEFUN (bgp_maxpaths_ibgp,
1659 bgp_maxpaths_ibgp_cmd,
1660 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1661 "Forward packets over multiple paths\n"
1662 "iBGP-multipath\n"
1663 "Number of paths\n")
1664 {
1665 int idx_number = 2;
1666 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1667 argv[idx_number]->arg, 0, 1);
1668 }
1669
1670 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1671 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1672 "Forward packets over multiple paths\n"
1673 "iBGP-multipath\n"
1674 "Number of paths\n")
1675
1676 DEFUN (bgp_maxpaths_ibgp_cluster,
1677 bgp_maxpaths_ibgp_cluster_cmd,
1678 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1679 "Forward packets over multiple paths\n"
1680 "iBGP-multipath\n"
1681 "Number of paths\n"
1682 "Match the cluster length\n")
1683 {
1684 int idx_number = 2;
1685 return bgp_maxpaths_config_vty(
1686 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1687 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1688 }
1689
1690 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1691 "maximum-paths ibgp " CMD_RANGE_STR(
1692 1, MULTIPATH_NUM) " equal-cluster-length",
1693 "Forward packets over multiple paths\n"
1694 "iBGP-multipath\n"
1695 "Number of paths\n"
1696 "Match the cluster length\n")
1697
1698 DEFUN (no_bgp_maxpaths,
1699 no_bgp_maxpaths_cmd,
1700 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1701 NO_STR
1702 "Forward packets over multiple paths\n"
1703 "Number of paths\n")
1704 {
1705 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1706 }
1707
1708 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1709 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1710 "Forward packets over multiple paths\n"
1711 "Number of paths\n")
1712
1713 DEFUN (no_bgp_maxpaths_ibgp,
1714 no_bgp_maxpaths_ibgp_cmd,
1715 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1716 NO_STR
1717 "Forward packets over multiple paths\n"
1718 "iBGP-multipath\n"
1719 "Number of paths\n"
1720 "Match the cluster length\n")
1721 {
1722 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1723 }
1724
1725 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1726 "no maximum-paths ibgp [" CMD_RANGE_STR(
1727 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1728 NO_STR
1729 "Forward packets over multiple paths\n"
1730 "iBGP-multipath\n"
1731 "Number of paths\n"
1732 "Match the cluster length\n")
1733
1734 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1735 safi_t safi)
1736 {
1737 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1738 vty_out(vty, " maximum-paths %d\n",
1739 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1740 }
1741
1742 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1743 vty_out(vty, " maximum-paths ibgp %d",
1744 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1745 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1746 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1747 vty_out(vty, " equal-cluster-length");
1748 vty_out(vty, "\n");
1749 }
1750 }
1751
1752 /* BGP timers. */
1753
1754 DEFUN (bgp_timers,
1755 bgp_timers_cmd,
1756 "timers bgp (0-65535) (0-65535)",
1757 "Adjust routing timers\n"
1758 "BGP timers\n"
1759 "Keepalive interval\n"
1760 "Holdtime\n")
1761 {
1762 VTY_DECLVAR_CONTEXT(bgp, bgp);
1763 int idx_number = 2;
1764 int idx_number_2 = 3;
1765 unsigned long keepalive = 0;
1766 unsigned long holdtime = 0;
1767
1768 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1769 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1770
1771 /* Holdtime value check. */
1772 if (holdtime < 3 && holdtime != 0) {
1773 vty_out(vty,
1774 "%% hold time value must be either 0 or greater than 3\n");
1775 return CMD_WARNING_CONFIG_FAILED;
1776 }
1777
1778 bgp_timers_set(bgp, keepalive, holdtime);
1779
1780 return CMD_SUCCESS;
1781 }
1782
1783 DEFUN (no_bgp_timers,
1784 no_bgp_timers_cmd,
1785 "no timers bgp [(0-65535) (0-65535)]",
1786 NO_STR
1787 "Adjust routing timers\n"
1788 "BGP timers\n"
1789 "Keepalive interval\n"
1790 "Holdtime\n")
1791 {
1792 VTY_DECLVAR_CONTEXT(bgp, bgp);
1793 bgp_timers_unset(bgp);
1794
1795 return CMD_SUCCESS;
1796 }
1797
1798
1799 DEFUN (bgp_client_to_client_reflection,
1800 bgp_client_to_client_reflection_cmd,
1801 "bgp client-to-client reflection",
1802 "BGP specific commands\n"
1803 "Configure client to client route reflection\n"
1804 "reflection of routes allowed\n")
1805 {
1806 VTY_DECLVAR_CONTEXT(bgp, bgp);
1807 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1808 bgp_clear_star_soft_out(vty, bgp->name);
1809
1810 return CMD_SUCCESS;
1811 }
1812
1813 DEFUN (no_bgp_client_to_client_reflection,
1814 no_bgp_client_to_client_reflection_cmd,
1815 "no bgp client-to-client reflection",
1816 NO_STR
1817 "BGP specific commands\n"
1818 "Configure client to client route reflection\n"
1819 "reflection of routes allowed\n")
1820 {
1821 VTY_DECLVAR_CONTEXT(bgp, bgp);
1822 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1823 bgp_clear_star_soft_out(vty, bgp->name);
1824
1825 return CMD_SUCCESS;
1826 }
1827
1828 /* "bgp always-compare-med" configuration. */
1829 DEFUN (bgp_always_compare_med,
1830 bgp_always_compare_med_cmd,
1831 "bgp always-compare-med",
1832 "BGP specific commands\n"
1833 "Allow comparing MED from different neighbors\n")
1834 {
1835 VTY_DECLVAR_CONTEXT(bgp, bgp);
1836 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1837 bgp_recalculate_all_bestpaths(bgp);
1838
1839 return CMD_SUCCESS;
1840 }
1841
1842 DEFUN (no_bgp_always_compare_med,
1843 no_bgp_always_compare_med_cmd,
1844 "no bgp always-compare-med",
1845 NO_STR
1846 "BGP specific commands\n"
1847 "Allow comparing MED from different neighbors\n")
1848 {
1849 VTY_DECLVAR_CONTEXT(bgp, bgp);
1850 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1851 bgp_recalculate_all_bestpaths(bgp);
1852
1853 return CMD_SUCCESS;
1854 }
1855
1856 /* "bgp deterministic-med" configuration. */
1857 DEFUN (bgp_deterministic_med,
1858 bgp_deterministic_med_cmd,
1859 "bgp deterministic-med",
1860 "BGP specific commands\n"
1861 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1862 {
1863 VTY_DECLVAR_CONTEXT(bgp, bgp);
1864
1865 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1866 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1867 bgp_recalculate_all_bestpaths(bgp);
1868 }
1869
1870 return CMD_SUCCESS;
1871 }
1872
1873 DEFUN (no_bgp_deterministic_med,
1874 no_bgp_deterministic_med_cmd,
1875 "no bgp deterministic-med",
1876 NO_STR
1877 "BGP specific commands\n"
1878 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1879 {
1880 VTY_DECLVAR_CONTEXT(bgp, bgp);
1881 int bestpath_per_as_used;
1882 afi_t afi;
1883 safi_t safi;
1884 struct peer *peer;
1885 struct listnode *node, *nnode;
1886
1887 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1888 bestpath_per_as_used = 0;
1889
1890 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1891 FOREACH_AFI_SAFI (afi, safi)
1892 if (bgp_addpath_dmed_required(
1893 peer->addpath_type[afi][safi])) {
1894 bestpath_per_as_used = 1;
1895 break;
1896 }
1897
1898 if (bestpath_per_as_used)
1899 break;
1900 }
1901
1902 if (bestpath_per_as_used) {
1903 vty_out(vty,
1904 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1905 return CMD_WARNING_CONFIG_FAILED;
1906 } else {
1907 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1908 bgp_recalculate_all_bestpaths(bgp);
1909 }
1910 }
1911
1912 return CMD_SUCCESS;
1913 }
1914
1915 /* "bgp graceful-restart" configuration. */
1916 DEFUN (bgp_graceful_restart,
1917 bgp_graceful_restart_cmd,
1918 "bgp graceful-restart",
1919 "BGP specific commands\n"
1920 "Graceful restart capability parameters\n")
1921 {
1922 VTY_DECLVAR_CONTEXT(bgp, bgp);
1923 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1924 return CMD_SUCCESS;
1925 }
1926
1927 DEFUN (no_bgp_graceful_restart,
1928 no_bgp_graceful_restart_cmd,
1929 "no bgp graceful-restart",
1930 NO_STR
1931 "BGP specific commands\n"
1932 "Graceful restart capability parameters\n")
1933 {
1934 VTY_DECLVAR_CONTEXT(bgp, bgp);
1935 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1936 return CMD_SUCCESS;
1937 }
1938
1939 DEFUN (bgp_graceful_restart_stalepath_time,
1940 bgp_graceful_restart_stalepath_time_cmd,
1941 "bgp graceful-restart stalepath-time (1-3600)",
1942 "BGP specific commands\n"
1943 "Graceful restart capability parameters\n"
1944 "Set the max time to hold onto restarting peer's stale paths\n"
1945 "Delay value (seconds)\n")
1946 {
1947 VTY_DECLVAR_CONTEXT(bgp, bgp);
1948 int idx_number = 3;
1949 uint32_t stalepath;
1950
1951 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1952 bgp->stalepath_time = stalepath;
1953 return CMD_SUCCESS;
1954 }
1955
1956 DEFUN (bgp_graceful_restart_restart_time,
1957 bgp_graceful_restart_restart_time_cmd,
1958 "bgp graceful-restart restart-time (1-3600)",
1959 "BGP specific commands\n"
1960 "Graceful restart capability parameters\n"
1961 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1962 "Delay value (seconds)\n")
1963 {
1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 int idx_number = 3;
1966 uint32_t restart;
1967
1968 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1969 bgp->restart_time = restart;
1970 return CMD_SUCCESS;
1971 }
1972
1973 DEFUN (no_bgp_graceful_restart_stalepath_time,
1974 no_bgp_graceful_restart_stalepath_time_cmd,
1975 "no bgp graceful-restart stalepath-time [(1-3600)]",
1976 NO_STR
1977 "BGP specific commands\n"
1978 "Graceful restart capability parameters\n"
1979 "Set the max time to hold onto restarting peer's stale paths\n"
1980 "Delay value (seconds)\n")
1981 {
1982 VTY_DECLVAR_CONTEXT(bgp, bgp);
1983
1984 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1985 return CMD_SUCCESS;
1986 }
1987
1988 DEFUN (no_bgp_graceful_restart_restart_time,
1989 no_bgp_graceful_restart_restart_time_cmd,
1990 "no bgp graceful-restart restart-time [(1-3600)]",
1991 NO_STR
1992 "BGP specific commands\n"
1993 "Graceful restart capability parameters\n"
1994 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1995 "Delay value (seconds)\n")
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998
1999 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2000 return CMD_SUCCESS;
2001 }
2002
2003 DEFUN (bgp_graceful_restart_preserve_fw,
2004 bgp_graceful_restart_preserve_fw_cmd,
2005 "bgp graceful-restart preserve-fw-state",
2006 "BGP specific commands\n"
2007 "Graceful restart capability parameters\n"
2008 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2009 {
2010 VTY_DECLVAR_CONTEXT(bgp, bgp);
2011 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2012 return CMD_SUCCESS;
2013 }
2014
2015 DEFUN (no_bgp_graceful_restart_preserve_fw,
2016 no_bgp_graceful_restart_preserve_fw_cmd,
2017 "no bgp graceful-restart preserve-fw-state",
2018 NO_STR
2019 "BGP specific commands\n"
2020 "Graceful restart capability parameters\n"
2021 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2022 {
2023 VTY_DECLVAR_CONTEXT(bgp, bgp);
2024 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2025 return CMD_SUCCESS;
2026 }
2027
2028 static void bgp_redistribute_redo(struct bgp *bgp)
2029 {
2030 afi_t afi;
2031 int i;
2032 struct list *red_list;
2033 struct listnode *node;
2034 struct bgp_redist *red;
2035
2036 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2037 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
2038
2039 red_list = bgp->redist[afi][i];
2040 if (!red_list)
2041 continue;
2042
2043 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
2044 bgp_redistribute_resend(bgp, afi, i,
2045 red->instance);
2046 }
2047 }
2048 }
2049 }
2050
2051 /* "bgp graceful-shutdown" configuration */
2052 DEFUN (bgp_graceful_shutdown,
2053 bgp_graceful_shutdown_cmd,
2054 "bgp graceful-shutdown",
2055 BGP_STR
2056 "Graceful shutdown parameters\n")
2057 {
2058 VTY_DECLVAR_CONTEXT(bgp, bgp);
2059
2060 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2061 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2062 bgp_static_redo_import_check(bgp);
2063 bgp_redistribute_redo(bgp);
2064 bgp_clear_star_soft_out(vty, bgp->name);
2065 bgp_clear_star_soft_in(vty, bgp->name);
2066 }
2067
2068 return CMD_SUCCESS;
2069 }
2070
2071 DEFUN (no_bgp_graceful_shutdown,
2072 no_bgp_graceful_shutdown_cmd,
2073 "no bgp graceful-shutdown",
2074 NO_STR
2075 BGP_STR
2076 "Graceful shutdown parameters\n")
2077 {
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079
2080 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2081 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2082 bgp_static_redo_import_check(bgp);
2083 bgp_redistribute_redo(bgp);
2084 bgp_clear_star_soft_out(vty, bgp->name);
2085 bgp_clear_star_soft_in(vty, bgp->name);
2086 }
2087
2088 return CMD_SUCCESS;
2089 }
2090
2091 /* "bgp fast-external-failover" configuration. */
2092 DEFUN (bgp_fast_external_failover,
2093 bgp_fast_external_failover_cmd,
2094 "bgp fast-external-failover",
2095 BGP_STR
2096 "Immediately reset session if a link to a directly connected external peer goes down\n")
2097 {
2098 VTY_DECLVAR_CONTEXT(bgp, bgp);
2099 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2100 return CMD_SUCCESS;
2101 }
2102
2103 DEFUN (no_bgp_fast_external_failover,
2104 no_bgp_fast_external_failover_cmd,
2105 "no bgp fast-external-failover",
2106 NO_STR
2107 BGP_STR
2108 "Immediately reset session if a link to a directly connected external peer goes down\n")
2109 {
2110 VTY_DECLVAR_CONTEXT(bgp, bgp);
2111 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2112 return CMD_SUCCESS;
2113 }
2114
2115 /* "bgp enforce-first-as" configuration. */
2116 #if CONFDATE > 20190517
2117 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2118 #endif
2119
2120 DEFUN_HIDDEN (bgp_enforce_first_as,
2121 bgp_enforce_first_as_cmd,
2122 "[no] bgp enforce-first-as",
2123 NO_STR
2124 BGP_STR
2125 "Enforce the first AS for EBGP routes\n")
2126 {
2127 VTY_DECLVAR_CONTEXT(bgp, bgp);
2128
2129 if (strmatch(argv[0]->text, "no"))
2130 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2131 else
2132 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2133
2134 return CMD_SUCCESS;
2135 }
2136
2137 /* "bgp bestpath compare-routerid" configuration. */
2138 DEFUN (bgp_bestpath_compare_router_id,
2139 bgp_bestpath_compare_router_id_cmd,
2140 "bgp bestpath compare-routerid",
2141 "BGP specific commands\n"
2142 "Change the default bestpath selection\n"
2143 "Compare router-id for identical EBGP paths\n")
2144 {
2145 VTY_DECLVAR_CONTEXT(bgp, bgp);
2146 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2147 bgp_recalculate_all_bestpaths(bgp);
2148
2149 return CMD_SUCCESS;
2150 }
2151
2152 DEFUN (no_bgp_bestpath_compare_router_id,
2153 no_bgp_bestpath_compare_router_id_cmd,
2154 "no bgp bestpath compare-routerid",
2155 NO_STR
2156 "BGP specific commands\n"
2157 "Change the default bestpath selection\n"
2158 "Compare router-id for identical EBGP paths\n")
2159 {
2160 VTY_DECLVAR_CONTEXT(bgp, bgp);
2161 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2162 bgp_recalculate_all_bestpaths(bgp);
2163
2164 return CMD_SUCCESS;
2165 }
2166
2167 /* "bgp bestpath as-path ignore" configuration. */
2168 DEFUN (bgp_bestpath_aspath_ignore,
2169 bgp_bestpath_aspath_ignore_cmd,
2170 "bgp bestpath as-path ignore",
2171 "BGP specific commands\n"
2172 "Change the default bestpath selection\n"
2173 "AS-path attribute\n"
2174 "Ignore as-path length in selecting a route\n")
2175 {
2176 VTY_DECLVAR_CONTEXT(bgp, bgp);
2177 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2178 bgp_recalculate_all_bestpaths(bgp);
2179
2180 return CMD_SUCCESS;
2181 }
2182
2183 DEFUN (no_bgp_bestpath_aspath_ignore,
2184 no_bgp_bestpath_aspath_ignore_cmd,
2185 "no bgp bestpath as-path ignore",
2186 NO_STR
2187 "BGP specific commands\n"
2188 "Change the default bestpath selection\n"
2189 "AS-path attribute\n"
2190 "Ignore as-path length in selecting a route\n")
2191 {
2192 VTY_DECLVAR_CONTEXT(bgp, bgp);
2193 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2194 bgp_recalculate_all_bestpaths(bgp);
2195
2196 return CMD_SUCCESS;
2197 }
2198
2199 /* "bgp bestpath as-path confed" configuration. */
2200 DEFUN (bgp_bestpath_aspath_confed,
2201 bgp_bestpath_aspath_confed_cmd,
2202 "bgp bestpath as-path confed",
2203 "BGP specific commands\n"
2204 "Change the default bestpath selection\n"
2205 "AS-path attribute\n"
2206 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2207 {
2208 VTY_DECLVAR_CONTEXT(bgp, bgp);
2209 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2210 bgp_recalculate_all_bestpaths(bgp);
2211
2212 return CMD_SUCCESS;
2213 }
2214
2215 DEFUN (no_bgp_bestpath_aspath_confed,
2216 no_bgp_bestpath_aspath_confed_cmd,
2217 "no bgp bestpath as-path confed",
2218 NO_STR
2219 "BGP specific commands\n"
2220 "Change the default bestpath selection\n"
2221 "AS-path attribute\n"
2222 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2223 {
2224 VTY_DECLVAR_CONTEXT(bgp, bgp);
2225 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2226 bgp_recalculate_all_bestpaths(bgp);
2227
2228 return CMD_SUCCESS;
2229 }
2230
2231 /* "bgp bestpath as-path multipath-relax" configuration. */
2232 DEFUN (bgp_bestpath_aspath_multipath_relax,
2233 bgp_bestpath_aspath_multipath_relax_cmd,
2234 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2235 "BGP specific commands\n"
2236 "Change the default bestpath selection\n"
2237 "AS-path attribute\n"
2238 "Allow load sharing across routes that have different AS paths (but same length)\n"
2239 "Generate an AS_SET\n"
2240 "Do not generate an AS_SET\n")
2241 {
2242 VTY_DECLVAR_CONTEXT(bgp, bgp);
2243 int idx = 0;
2244 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2245
2246 /* no-as-set is now the default behavior so we can silently
2247 * ignore it */
2248 if (argv_find(argv, argc, "as-set", &idx))
2249 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2250 else
2251 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2252
2253 bgp_recalculate_all_bestpaths(bgp);
2254
2255 return CMD_SUCCESS;
2256 }
2257
2258 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2259 no_bgp_bestpath_aspath_multipath_relax_cmd,
2260 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2261 NO_STR
2262 "BGP specific commands\n"
2263 "Change the default bestpath selection\n"
2264 "AS-path attribute\n"
2265 "Allow load sharing across routes that have different AS paths (but same length)\n"
2266 "Generate an AS_SET\n"
2267 "Do not generate an AS_SET\n")
2268 {
2269 VTY_DECLVAR_CONTEXT(bgp, bgp);
2270 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2271 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2272 bgp_recalculate_all_bestpaths(bgp);
2273
2274 return CMD_SUCCESS;
2275 }
2276
2277 /* "bgp log-neighbor-changes" configuration. */
2278 DEFUN (bgp_log_neighbor_changes,
2279 bgp_log_neighbor_changes_cmd,
2280 "bgp log-neighbor-changes",
2281 "BGP specific commands\n"
2282 "Log neighbor up/down and reset reason\n")
2283 {
2284 VTY_DECLVAR_CONTEXT(bgp, bgp);
2285 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2286 return CMD_SUCCESS;
2287 }
2288
2289 DEFUN (no_bgp_log_neighbor_changes,
2290 no_bgp_log_neighbor_changes_cmd,
2291 "no bgp log-neighbor-changes",
2292 NO_STR
2293 "BGP specific commands\n"
2294 "Log neighbor up/down and reset reason\n")
2295 {
2296 VTY_DECLVAR_CONTEXT(bgp, bgp);
2297 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2298 return CMD_SUCCESS;
2299 }
2300
2301 /* "bgp bestpath med" configuration. */
2302 DEFUN (bgp_bestpath_med,
2303 bgp_bestpath_med_cmd,
2304 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2305 "BGP specific commands\n"
2306 "Change the default bestpath selection\n"
2307 "MED attribute\n"
2308 "Compare MED among confederation paths\n"
2309 "Treat missing MED as the least preferred one\n"
2310 "Treat missing MED as the least preferred one\n"
2311 "Compare MED among confederation paths\n")
2312 {
2313 VTY_DECLVAR_CONTEXT(bgp, bgp);
2314
2315 int idx = 0;
2316 if (argv_find(argv, argc, "confed", &idx))
2317 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2318 idx = 0;
2319 if (argv_find(argv, argc, "missing-as-worst", &idx))
2320 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2321
2322 bgp_recalculate_all_bestpaths(bgp);
2323
2324 return CMD_SUCCESS;
2325 }
2326
2327 DEFUN (no_bgp_bestpath_med,
2328 no_bgp_bestpath_med_cmd,
2329 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2330 NO_STR
2331 "BGP specific commands\n"
2332 "Change the default bestpath selection\n"
2333 "MED attribute\n"
2334 "Compare MED among confederation paths\n"
2335 "Treat missing MED as the least preferred one\n"
2336 "Treat missing MED as the least preferred one\n"
2337 "Compare MED among confederation paths\n")
2338 {
2339 VTY_DECLVAR_CONTEXT(bgp, bgp);
2340
2341 int idx = 0;
2342 if (argv_find(argv, argc, "confed", &idx))
2343 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2344 idx = 0;
2345 if (argv_find(argv, argc, "missing-as-worst", &idx))
2346 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2347
2348 bgp_recalculate_all_bestpaths(bgp);
2349
2350 return CMD_SUCCESS;
2351 }
2352
2353 /* "no bgp default ipv4-unicast". */
2354 DEFUN (no_bgp_default_ipv4_unicast,
2355 no_bgp_default_ipv4_unicast_cmd,
2356 "no bgp default ipv4-unicast",
2357 NO_STR
2358 "BGP specific commands\n"
2359 "Configure BGP defaults\n"
2360 "Activate ipv4-unicast for a peer by default\n")
2361 {
2362 VTY_DECLVAR_CONTEXT(bgp, bgp);
2363 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2364 return CMD_SUCCESS;
2365 }
2366
2367 DEFUN (bgp_default_ipv4_unicast,
2368 bgp_default_ipv4_unicast_cmd,
2369 "bgp default ipv4-unicast",
2370 "BGP specific commands\n"
2371 "Configure BGP defaults\n"
2372 "Activate ipv4-unicast for a peer by default\n")
2373 {
2374 VTY_DECLVAR_CONTEXT(bgp, bgp);
2375 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2376 return CMD_SUCCESS;
2377 }
2378
2379 /* Display hostname in certain command outputs */
2380 DEFUN (bgp_default_show_hostname,
2381 bgp_default_show_hostname_cmd,
2382 "bgp default show-hostname",
2383 "BGP specific commands\n"
2384 "Configure BGP defaults\n"
2385 "Show hostname in certain command outputs\n")
2386 {
2387 VTY_DECLVAR_CONTEXT(bgp, bgp);
2388 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2389 return CMD_SUCCESS;
2390 }
2391
2392 DEFUN (no_bgp_default_show_hostname,
2393 no_bgp_default_show_hostname_cmd,
2394 "no bgp default show-hostname",
2395 NO_STR
2396 "BGP specific commands\n"
2397 "Configure BGP defaults\n"
2398 "Show hostname in certain command outputs\n")
2399 {
2400 VTY_DECLVAR_CONTEXT(bgp, bgp);
2401 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2402 return CMD_SUCCESS;
2403 }
2404
2405 /* "bgp network import-check" configuration. */
2406 DEFUN (bgp_network_import_check,
2407 bgp_network_import_check_cmd,
2408 "bgp network import-check",
2409 "BGP specific commands\n"
2410 "BGP network command\n"
2411 "Check BGP network route exists in IGP\n")
2412 {
2413 VTY_DECLVAR_CONTEXT(bgp, bgp);
2414 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2415 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2416 bgp_static_redo_import_check(bgp);
2417 }
2418
2419 return CMD_SUCCESS;
2420 }
2421
2422 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2423 "bgp network import-check exact",
2424 "BGP specific commands\n"
2425 "BGP network command\n"
2426 "Check BGP network route exists in IGP\n"
2427 "Match route precisely\n")
2428
2429 DEFUN (no_bgp_network_import_check,
2430 no_bgp_network_import_check_cmd,
2431 "no bgp network import-check",
2432 NO_STR
2433 "BGP specific commands\n"
2434 "BGP network command\n"
2435 "Check BGP network route exists in IGP\n")
2436 {
2437 VTY_DECLVAR_CONTEXT(bgp, bgp);
2438 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2439 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2440 bgp_static_redo_import_check(bgp);
2441 }
2442
2443 return CMD_SUCCESS;
2444 }
2445
2446 DEFUN (bgp_default_local_preference,
2447 bgp_default_local_preference_cmd,
2448 "bgp default local-preference (0-4294967295)",
2449 "BGP specific commands\n"
2450 "Configure BGP defaults\n"
2451 "local preference (higher=more preferred)\n"
2452 "Configure default local preference value\n")
2453 {
2454 VTY_DECLVAR_CONTEXT(bgp, bgp);
2455 int idx_number = 3;
2456 uint32_t local_pref;
2457
2458 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2459
2460 bgp_default_local_preference_set(bgp, local_pref);
2461 bgp_clear_star_soft_in(vty, bgp->name);
2462
2463 return CMD_SUCCESS;
2464 }
2465
2466 DEFUN (no_bgp_default_local_preference,
2467 no_bgp_default_local_preference_cmd,
2468 "no bgp default local-preference [(0-4294967295)]",
2469 NO_STR
2470 "BGP specific commands\n"
2471 "Configure BGP defaults\n"
2472 "local preference (higher=more preferred)\n"
2473 "Configure default local preference value\n")
2474 {
2475 VTY_DECLVAR_CONTEXT(bgp, bgp);
2476 bgp_default_local_preference_unset(bgp);
2477 bgp_clear_star_soft_in(vty, bgp->name);
2478
2479 return CMD_SUCCESS;
2480 }
2481
2482
2483 DEFUN (bgp_default_subgroup_pkt_queue_max,
2484 bgp_default_subgroup_pkt_queue_max_cmd,
2485 "bgp default subgroup-pkt-queue-max (20-100)",
2486 "BGP specific commands\n"
2487 "Configure BGP defaults\n"
2488 "subgroup-pkt-queue-max\n"
2489 "Configure subgroup packet queue max\n")
2490 {
2491 VTY_DECLVAR_CONTEXT(bgp, bgp);
2492 int idx_number = 3;
2493 uint32_t max_size;
2494
2495 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2496
2497 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2498
2499 return CMD_SUCCESS;
2500 }
2501
2502 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2503 no_bgp_default_subgroup_pkt_queue_max_cmd,
2504 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2505 NO_STR
2506 "BGP specific commands\n"
2507 "Configure BGP defaults\n"
2508 "subgroup-pkt-queue-max\n"
2509 "Configure subgroup packet queue max\n")
2510 {
2511 VTY_DECLVAR_CONTEXT(bgp, bgp);
2512 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2513 return CMD_SUCCESS;
2514 }
2515
2516
2517 DEFUN (bgp_rr_allow_outbound_policy,
2518 bgp_rr_allow_outbound_policy_cmd,
2519 "bgp route-reflector allow-outbound-policy",
2520 "BGP specific commands\n"
2521 "Allow modifications made by out route-map\n"
2522 "on ibgp neighbors\n")
2523 {
2524 VTY_DECLVAR_CONTEXT(bgp, bgp);
2525
2526 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2527 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2528 update_group_announce_rrclients(bgp);
2529 bgp_clear_star_soft_out(vty, bgp->name);
2530 }
2531
2532 return CMD_SUCCESS;
2533 }
2534
2535 DEFUN (no_bgp_rr_allow_outbound_policy,
2536 no_bgp_rr_allow_outbound_policy_cmd,
2537 "no bgp route-reflector allow-outbound-policy",
2538 NO_STR
2539 "BGP specific commands\n"
2540 "Allow modifications made by out route-map\n"
2541 "on ibgp neighbors\n")
2542 {
2543 VTY_DECLVAR_CONTEXT(bgp, bgp);
2544
2545 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2546 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2547 update_group_announce_rrclients(bgp);
2548 bgp_clear_star_soft_out(vty, bgp->name);
2549 }
2550
2551 return CMD_SUCCESS;
2552 }
2553
2554 DEFUN (bgp_listen_limit,
2555 bgp_listen_limit_cmd,
2556 "bgp listen limit (1-5000)",
2557 "BGP specific commands\n"
2558 "Configure BGP defaults\n"
2559 "maximum number of BGP Dynamic Neighbors that can be created\n"
2560 "Configure Dynamic Neighbors listen limit value\n")
2561 {
2562 VTY_DECLVAR_CONTEXT(bgp, bgp);
2563 int idx_number = 3;
2564 int listen_limit;
2565
2566 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2567
2568 bgp_listen_limit_set(bgp, listen_limit);
2569
2570 return CMD_SUCCESS;
2571 }
2572
2573 DEFUN (no_bgp_listen_limit,
2574 no_bgp_listen_limit_cmd,
2575 "no bgp listen limit [(1-5000)]",
2576 "BGP specific commands\n"
2577 "Configure BGP defaults\n"
2578 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2579 "Configure Dynamic Neighbors listen limit value to default\n"
2580 "Configure Dynamic Neighbors listen limit value\n")
2581 {
2582 VTY_DECLVAR_CONTEXT(bgp, bgp);
2583 bgp_listen_limit_unset(bgp);
2584 return CMD_SUCCESS;
2585 }
2586
2587
2588 /*
2589 * Check if this listen range is already configured. Check for exact
2590 * match or overlap based on input.
2591 */
2592 static struct peer_group *listen_range_exists(struct bgp *bgp,
2593 struct prefix *range, int exact)
2594 {
2595 struct listnode *node, *nnode;
2596 struct listnode *node1, *nnode1;
2597 struct peer_group *group;
2598 struct prefix *lr;
2599 afi_t afi;
2600 int match;
2601
2602 afi = family2afi(range->family);
2603 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2604 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2605 lr)) {
2606 if (exact)
2607 match = prefix_same(range, lr);
2608 else
2609 match = (prefix_match(range, lr)
2610 || prefix_match(lr, range));
2611 if (match)
2612 return group;
2613 }
2614 }
2615
2616 return NULL;
2617 }
2618
2619 DEFUN (bgp_listen_range,
2620 bgp_listen_range_cmd,
2621 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2622 "BGP specific commands\n"
2623 "Configure BGP dynamic neighbors listen range\n"
2624 "Configure BGP dynamic neighbors listen range\n"
2625 NEIGHBOR_ADDR_STR
2626 "Member of the peer-group\n"
2627 "Peer-group name\n")
2628 {
2629 VTY_DECLVAR_CONTEXT(bgp, bgp);
2630 struct prefix range;
2631 struct peer_group *group, *existing_group;
2632 afi_t afi;
2633 int ret;
2634 int idx = 0;
2635
2636 argv_find(argv, argc, "A.B.C.D/M", &idx);
2637 argv_find(argv, argc, "X:X::X:X/M", &idx);
2638 char *prefix = argv[idx]->arg;
2639 argv_find(argv, argc, "WORD", &idx);
2640 char *peergroup = argv[idx]->arg;
2641
2642 /* Convert IP prefix string to struct prefix. */
2643 ret = str2prefix(prefix, &range);
2644 if (!ret) {
2645 vty_out(vty, "%% Malformed listen range\n");
2646 return CMD_WARNING_CONFIG_FAILED;
2647 }
2648
2649 afi = family2afi(range.family);
2650
2651 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2652 vty_out(vty,
2653 "%% Malformed listen range (link-local address)\n");
2654 return CMD_WARNING_CONFIG_FAILED;
2655 }
2656
2657 apply_mask(&range);
2658
2659 /* Check if same listen range is already configured. */
2660 existing_group = listen_range_exists(bgp, &range, 1);
2661 if (existing_group) {
2662 if (strcmp(existing_group->name, peergroup) == 0)
2663 return CMD_SUCCESS;
2664 else {
2665 vty_out(vty,
2666 "%% Same listen range is attached to peer-group %s\n",
2667 existing_group->name);
2668 return CMD_WARNING_CONFIG_FAILED;
2669 }
2670 }
2671
2672 /* Check if an overlapping listen range exists. */
2673 if (listen_range_exists(bgp, &range, 0)) {
2674 vty_out(vty,
2675 "%% Listen range overlaps with existing listen range\n");
2676 return CMD_WARNING_CONFIG_FAILED;
2677 }
2678
2679 group = peer_group_lookup(bgp, peergroup);
2680 if (!group) {
2681 vty_out(vty, "%% Configure the peer-group first\n");
2682 return CMD_WARNING_CONFIG_FAILED;
2683 }
2684
2685 ret = peer_group_listen_range_add(group, &range);
2686 return bgp_vty_return(vty, ret);
2687 }
2688
2689 DEFUN (no_bgp_listen_range,
2690 no_bgp_listen_range_cmd,
2691 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2692 NO_STR
2693 "BGP specific commands\n"
2694 "Unconfigure BGP dynamic neighbors listen range\n"
2695 "Unconfigure BGP dynamic neighbors listen range\n"
2696 NEIGHBOR_ADDR_STR
2697 "Member of the peer-group\n"
2698 "Peer-group name\n")
2699 {
2700 VTY_DECLVAR_CONTEXT(bgp, bgp);
2701 struct prefix range;
2702 struct peer_group *group;
2703 afi_t afi;
2704 int ret;
2705 int idx = 0;
2706
2707 argv_find(argv, argc, "A.B.C.D/M", &idx);
2708 argv_find(argv, argc, "X:X::X:X/M", &idx);
2709 char *prefix = argv[idx]->arg;
2710 argv_find(argv, argc, "WORD", &idx);
2711 char *peergroup = argv[idx]->arg;
2712
2713 /* Convert IP prefix string to struct prefix. */
2714 ret = str2prefix(prefix, &range);
2715 if (!ret) {
2716 vty_out(vty, "%% Malformed listen range\n");
2717 return CMD_WARNING_CONFIG_FAILED;
2718 }
2719
2720 afi = family2afi(range.family);
2721
2722 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2723 vty_out(vty,
2724 "%% Malformed listen range (link-local address)\n");
2725 return CMD_WARNING_CONFIG_FAILED;
2726 }
2727
2728 apply_mask(&range);
2729
2730 group = peer_group_lookup(bgp, peergroup);
2731 if (!group) {
2732 vty_out(vty, "%% Peer-group does not exist\n");
2733 return CMD_WARNING_CONFIG_FAILED;
2734 }
2735
2736 ret = peer_group_listen_range_del(group, &range);
2737 return bgp_vty_return(vty, ret);
2738 }
2739
2740 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2741 {
2742 struct peer_group *group;
2743 struct listnode *node, *nnode, *rnode, *nrnode;
2744 struct prefix *range;
2745 afi_t afi;
2746 char buf[PREFIX2STR_BUFFER];
2747
2748 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2749 vty_out(vty, " bgp listen limit %d\n",
2750 bgp->dynamic_neighbors_limit);
2751
2752 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2753 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2754 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2755 nrnode, range)) {
2756 prefix2str(range, buf, sizeof(buf));
2757 vty_out(vty,
2758 " bgp listen range %s peer-group %s\n",
2759 buf, group->name);
2760 }
2761 }
2762 }
2763 }
2764
2765
2766 DEFUN (bgp_disable_connected_route_check,
2767 bgp_disable_connected_route_check_cmd,
2768 "bgp disable-ebgp-connected-route-check",
2769 "BGP specific commands\n"
2770 "Disable checking if nexthop is connected on ebgp sessions\n")
2771 {
2772 VTY_DECLVAR_CONTEXT(bgp, bgp);
2773 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2774 bgp_clear_star_soft_in(vty, bgp->name);
2775
2776 return CMD_SUCCESS;
2777 }
2778
2779 DEFUN (no_bgp_disable_connected_route_check,
2780 no_bgp_disable_connected_route_check_cmd,
2781 "no bgp disable-ebgp-connected-route-check",
2782 NO_STR
2783 "BGP specific commands\n"
2784 "Disable checking if nexthop is connected on ebgp sessions\n")
2785 {
2786 VTY_DECLVAR_CONTEXT(bgp, bgp);
2787 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2788 bgp_clear_star_soft_in(vty, bgp->name);
2789
2790 return CMD_SUCCESS;
2791 }
2792
2793
2794 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2795 const char *as_str, afi_t afi, safi_t safi)
2796 {
2797 VTY_DECLVAR_CONTEXT(bgp, bgp);
2798 int ret;
2799 as_t as;
2800 int as_type = AS_SPECIFIED;
2801 union sockunion su;
2802
2803 if (as_str[0] == 'i') {
2804 as = 0;
2805 as_type = AS_INTERNAL;
2806 } else if (as_str[0] == 'e') {
2807 as = 0;
2808 as_type = AS_EXTERNAL;
2809 } else {
2810 /* Get AS number. */
2811 as = strtoul(as_str, NULL, 10);
2812 }
2813
2814 /* If peer is peer group, call proper function. */
2815 ret = str2sockunion(peer_str, &su);
2816 if (ret < 0) {
2817 /* Check for peer by interface */
2818 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2819 safi);
2820 if (ret < 0) {
2821 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2822 if (ret < 0) {
2823 vty_out(vty,
2824 "%% Create the peer-group or interface first or specify \"interface\" keyword\n");
2825 vty_out(vty, "%% if using an unnumbered interface neighbor\n");
2826 return CMD_WARNING_CONFIG_FAILED;
2827 }
2828 return CMD_SUCCESS;
2829 }
2830 } else {
2831 if (peer_address_self_check(bgp, &su)) {
2832 vty_out(vty,
2833 "%% Can not configure the local system as neighbor\n");
2834 return CMD_WARNING_CONFIG_FAILED;
2835 }
2836 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2837 }
2838
2839 /* This peer belongs to peer group. */
2840 switch (ret) {
2841 case BGP_ERR_PEER_GROUP_MEMBER:
2842 vty_out(vty,
2843 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2844 as);
2845 return CMD_WARNING_CONFIG_FAILED;
2846 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2847 vty_out(vty,
2848 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2849 as, as_str);
2850 return CMD_WARNING_CONFIG_FAILED;
2851 }
2852 return bgp_vty_return(vty, ret);
2853 }
2854
2855 DEFUN (bgp_default_shutdown,
2856 bgp_default_shutdown_cmd,
2857 "[no] bgp default shutdown",
2858 NO_STR
2859 BGP_STR
2860 "Configure BGP defaults\n"
2861 "Apply administrative shutdown to newly configured peers\n")
2862 {
2863 VTY_DECLVAR_CONTEXT(bgp, bgp);
2864 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2865 return CMD_SUCCESS;
2866 }
2867
2868 DEFUN (neighbor_remote_as,
2869 neighbor_remote_as_cmd,
2870 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2871 NEIGHBOR_STR
2872 NEIGHBOR_ADDR_STR2
2873 "Specify a BGP neighbor\n"
2874 AS_STR
2875 "Internal BGP peer\n"
2876 "External BGP peer\n")
2877 {
2878 int idx_peer = 1;
2879 int idx_remote_as = 3;
2880 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2881 argv[idx_remote_as]->arg, AFI_IP,
2882 SAFI_UNICAST);
2883 }
2884
2885 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2886 afi_t afi, safi_t safi, int v6only,
2887 const char *peer_group_name,
2888 const char *as_str)
2889 {
2890 VTY_DECLVAR_CONTEXT(bgp, bgp);
2891 as_t as = 0;
2892 int as_type = AS_UNSPECIFIED;
2893 struct peer *peer;
2894 struct peer_group *group;
2895 int ret = 0;
2896 union sockunion su;
2897
2898 group = peer_group_lookup(bgp, conf_if);
2899
2900 if (group) {
2901 vty_out(vty, "%% Name conflict with peer-group \n");
2902 return CMD_WARNING_CONFIG_FAILED;
2903 }
2904
2905 if (as_str) {
2906 if (as_str[0] == 'i') {
2907 as_type = AS_INTERNAL;
2908 } else if (as_str[0] == 'e') {
2909 as_type = AS_EXTERNAL;
2910 } else {
2911 /* Get AS number. */
2912 as = strtoul(as_str, NULL, 10);
2913 as_type = AS_SPECIFIED;
2914 }
2915 }
2916
2917 peer = peer_lookup_by_conf_if(bgp, conf_if);
2918 if (peer) {
2919 if (as_str)
2920 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2921 afi, safi);
2922 } else {
2923 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2924 && afi == AFI_IP && safi == SAFI_UNICAST)
2925 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2926 as_type, 0, 0, NULL);
2927 else
2928 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2929 as_type, afi, safi, NULL);
2930
2931 if (!peer) {
2932 vty_out(vty, "%% BGP failed to create peer\n");
2933 return CMD_WARNING_CONFIG_FAILED;
2934 }
2935
2936 if (v6only)
2937 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2938
2939 /* Request zebra to initiate IPv6 RAs on this interface. We do
2940 * this
2941 * any unnumbered peer in order to not worry about run-time
2942 * transitions
2943 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2944 * address
2945 * gets deleted later etc.)
2946 */
2947 if (peer->ifp)
2948 bgp_zebra_initiate_radv(bgp, peer);
2949 }
2950
2951 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2952 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2953 if (v6only)
2954 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2955 else
2956 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2957
2958 /* v6only flag changed. Reset bgp seesion */
2959 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2960 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2961 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2962 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2963 } else
2964 bgp_session_reset(peer);
2965 }
2966
2967 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2968 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2969 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2970 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2971 }
2972
2973 if (peer_group_name) {
2974 group = peer_group_lookup(bgp, peer_group_name);
2975 if (!group) {
2976 vty_out(vty, "%% Configure the peer-group first\n");
2977 return CMD_WARNING_CONFIG_FAILED;
2978 }
2979
2980 ret = peer_group_bind(bgp, &su, peer, group, &as);
2981 }
2982
2983 return bgp_vty_return(vty, ret);
2984 }
2985
2986 DEFUN (neighbor_interface_config,
2987 neighbor_interface_config_cmd,
2988 "neighbor WORD interface [peer-group WORD]",
2989 NEIGHBOR_STR
2990 "Interface name or neighbor tag\n"
2991 "Enable BGP on interface\n"
2992 "Member of the peer-group\n"
2993 "Peer-group name\n")
2994 {
2995 int idx_word = 1;
2996 int idx_peer_group_word = 4;
2997
2998 if (argc > idx_peer_group_word)
2999 return peer_conf_interface_get(
3000 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3001 argv[idx_peer_group_word]->arg, NULL);
3002 else
3003 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3004 SAFI_UNICAST, 0, NULL, NULL);
3005 }
3006
3007 DEFUN (neighbor_interface_config_v6only,
3008 neighbor_interface_config_v6only_cmd,
3009 "neighbor WORD interface v6only [peer-group WORD]",
3010 NEIGHBOR_STR
3011 "Interface name or neighbor tag\n"
3012 "Enable BGP on interface\n"
3013 "Enable BGP with v6 link-local only\n"
3014 "Member of the peer-group\n"
3015 "Peer-group name\n")
3016 {
3017 int idx_word = 1;
3018 int idx_peer_group_word = 5;
3019
3020 if (argc > idx_peer_group_word)
3021 return peer_conf_interface_get(
3022 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3023 argv[idx_peer_group_word]->arg, NULL);
3024
3025 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3026 SAFI_UNICAST, 1, NULL, NULL);
3027 }
3028
3029
3030 DEFUN (neighbor_interface_config_remote_as,
3031 neighbor_interface_config_remote_as_cmd,
3032 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3033 NEIGHBOR_STR
3034 "Interface name or neighbor tag\n"
3035 "Enable BGP on interface\n"
3036 "Specify a BGP neighbor\n"
3037 AS_STR
3038 "Internal BGP peer\n"
3039 "External BGP peer\n")
3040 {
3041 int idx_word = 1;
3042 int idx_remote_as = 4;
3043 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3044 SAFI_UNICAST, 0, NULL,
3045 argv[idx_remote_as]->arg);
3046 }
3047
3048 DEFUN (neighbor_interface_v6only_config_remote_as,
3049 neighbor_interface_v6only_config_remote_as_cmd,
3050 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3051 NEIGHBOR_STR
3052 "Interface name or neighbor tag\n"
3053 "Enable BGP with v6 link-local only\n"
3054 "Enable BGP on interface\n"
3055 "Specify a BGP neighbor\n"
3056 AS_STR
3057 "Internal BGP peer\n"
3058 "External BGP peer\n")
3059 {
3060 int idx_word = 1;
3061 int idx_remote_as = 5;
3062 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3063 SAFI_UNICAST, 1, NULL,
3064 argv[idx_remote_as]->arg);
3065 }
3066
3067 DEFUN (neighbor_peer_group,
3068 neighbor_peer_group_cmd,
3069 "neighbor WORD peer-group",
3070 NEIGHBOR_STR
3071 "Interface name or neighbor tag\n"
3072 "Configure peer-group\n")
3073 {
3074 VTY_DECLVAR_CONTEXT(bgp, bgp);
3075 int idx_word = 1;
3076 struct peer *peer;
3077 struct peer_group *group;
3078
3079 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3080 if (peer) {
3081 vty_out(vty, "%% Name conflict with interface: \n");
3082 return CMD_WARNING_CONFIG_FAILED;
3083 }
3084
3085 group = peer_group_get(bgp, argv[idx_word]->arg);
3086 if (!group) {
3087 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3088 return CMD_WARNING_CONFIG_FAILED;
3089 }
3090
3091 return CMD_SUCCESS;
3092 }
3093
3094 DEFUN (no_neighbor,
3095 no_neighbor_cmd,
3096 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3097 NO_STR
3098 NEIGHBOR_STR
3099 NEIGHBOR_ADDR_STR2
3100 "Specify a BGP neighbor\n"
3101 AS_STR
3102 "Internal BGP peer\n"
3103 "External BGP peer\n")
3104 {
3105 VTY_DECLVAR_CONTEXT(bgp, bgp);
3106 int idx_peer = 2;
3107 int ret;
3108 union sockunion su;
3109 struct peer_group *group;
3110 struct peer *peer;
3111 struct peer *other;
3112
3113 ret = str2sockunion(argv[idx_peer]->arg, &su);
3114 if (ret < 0) {
3115 /* look up for neighbor by interface name config. */
3116 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3117 if (peer) {
3118 /* Request zebra to terminate IPv6 RAs on this
3119 * interface. */
3120 if (peer->ifp)
3121 bgp_zebra_terminate_radv(peer->bgp, peer);
3122 peer_delete(peer);
3123 return CMD_SUCCESS;
3124 }
3125
3126 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3127 if (group)
3128 peer_group_delete(group);
3129 else {
3130 vty_out(vty, "%% Create the peer-group first\n");
3131 return CMD_WARNING_CONFIG_FAILED;
3132 }
3133 } else {
3134 peer = peer_lookup(bgp, &su);
3135 if (peer) {
3136 if (peer_dynamic_neighbor(peer)) {
3137 vty_out(vty,
3138 "%% Operation not allowed on a dynamic neighbor\n");
3139 return CMD_WARNING_CONFIG_FAILED;
3140 }
3141
3142 other = peer->doppelganger;
3143 peer_delete(peer);
3144 if (other && other->status != Deleted)
3145 peer_delete(other);
3146 }
3147 }
3148
3149 return CMD_SUCCESS;
3150 }
3151
3152 DEFUN (no_neighbor_interface_config,
3153 no_neighbor_interface_config_cmd,
3154 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3155 NO_STR
3156 NEIGHBOR_STR
3157 "Interface name\n"
3158 "Configure BGP on interface\n"
3159 "Enable BGP with v6 link-local only\n"
3160 "Member of the peer-group\n"
3161 "Peer-group name\n"
3162 "Specify a BGP neighbor\n"
3163 AS_STR
3164 "Internal BGP peer\n"
3165 "External BGP peer\n")
3166 {
3167 VTY_DECLVAR_CONTEXT(bgp, bgp);
3168 int idx_word = 2;
3169 struct peer *peer;
3170
3171 /* look up for neighbor by interface name config. */
3172 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3173 if (peer) {
3174 /* Request zebra to terminate IPv6 RAs on this interface. */
3175 if (peer->ifp)
3176 bgp_zebra_terminate_radv(peer->bgp, peer);
3177 peer_delete(peer);
3178 } else {
3179 vty_out(vty, "%% Create the bgp interface first\n");
3180 return CMD_WARNING_CONFIG_FAILED;
3181 }
3182 return CMD_SUCCESS;
3183 }
3184
3185 DEFUN (no_neighbor_peer_group,
3186 no_neighbor_peer_group_cmd,
3187 "no neighbor WORD peer-group",
3188 NO_STR
3189 NEIGHBOR_STR
3190 "Neighbor tag\n"
3191 "Configure peer-group\n")
3192 {
3193 VTY_DECLVAR_CONTEXT(bgp, bgp);
3194 int idx_word = 2;
3195 struct peer_group *group;
3196
3197 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3198 if (group)
3199 peer_group_delete(group);
3200 else {
3201 vty_out(vty, "%% Create the peer-group first\n");
3202 return CMD_WARNING_CONFIG_FAILED;
3203 }
3204 return CMD_SUCCESS;
3205 }
3206
3207 DEFUN (no_neighbor_interface_peer_group_remote_as,
3208 no_neighbor_interface_peer_group_remote_as_cmd,
3209 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3210 NO_STR
3211 NEIGHBOR_STR
3212 "Interface name or neighbor tag\n"
3213 "Specify a BGP neighbor\n"
3214 AS_STR
3215 "Internal BGP peer\n"
3216 "External BGP peer\n")
3217 {
3218 VTY_DECLVAR_CONTEXT(bgp, bgp);
3219 int idx_word = 2;
3220 struct peer_group *group;
3221 struct peer *peer;
3222
3223 /* look up for neighbor by interface name config. */
3224 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3225 if (peer) {
3226 peer_as_change(peer, 0, AS_SPECIFIED);
3227 return CMD_SUCCESS;
3228 }
3229
3230 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3231 if (group)
3232 peer_group_remote_as_delete(group);
3233 else {
3234 vty_out(vty, "%% Create the peer-group or interface first\n");
3235 return CMD_WARNING_CONFIG_FAILED;
3236 }
3237 return CMD_SUCCESS;
3238 }
3239
3240 DEFUN (neighbor_local_as,
3241 neighbor_local_as_cmd,
3242 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3243 NEIGHBOR_STR
3244 NEIGHBOR_ADDR_STR2
3245 "Specify a local-as number\n"
3246 "AS number used as local AS\n")
3247 {
3248 int idx_peer = 1;
3249 int idx_number = 3;
3250 struct peer *peer;
3251 int ret;
3252 as_t as;
3253
3254 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3255 if (!peer)
3256 return CMD_WARNING_CONFIG_FAILED;
3257
3258 as = strtoul(argv[idx_number]->arg, NULL, 10);
3259 ret = peer_local_as_set(peer, as, 0, 0);
3260 return bgp_vty_return(vty, ret);
3261 }
3262
3263 DEFUN (neighbor_local_as_no_prepend,
3264 neighbor_local_as_no_prepend_cmd,
3265 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3266 NEIGHBOR_STR
3267 NEIGHBOR_ADDR_STR2
3268 "Specify a local-as number\n"
3269 "AS number used as local AS\n"
3270 "Do not prepend local-as to updates from ebgp peers\n")
3271 {
3272 int idx_peer = 1;
3273 int idx_number = 3;
3274 struct peer *peer;
3275 int ret;
3276 as_t as;
3277
3278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3279 if (!peer)
3280 return CMD_WARNING_CONFIG_FAILED;
3281
3282 as = strtoul(argv[idx_number]->arg, NULL, 10);
3283 ret = peer_local_as_set(peer, as, 1, 0);
3284 return bgp_vty_return(vty, ret);
3285 }
3286
3287 DEFUN (neighbor_local_as_no_prepend_replace_as,
3288 neighbor_local_as_no_prepend_replace_as_cmd,
3289 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3290 NEIGHBOR_STR
3291 NEIGHBOR_ADDR_STR2
3292 "Specify a local-as number\n"
3293 "AS number used as local AS\n"
3294 "Do not prepend local-as to updates from ebgp peers\n"
3295 "Do not prepend local-as to updates from ibgp peers\n")
3296 {
3297 int idx_peer = 1;
3298 int idx_number = 3;
3299 struct peer *peer;
3300 int ret;
3301 as_t as;
3302
3303 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3304 if (!peer)
3305 return CMD_WARNING_CONFIG_FAILED;
3306
3307 as = strtoul(argv[idx_number]->arg, NULL, 10);
3308 ret = peer_local_as_set(peer, as, 1, 1);
3309 return bgp_vty_return(vty, ret);
3310 }
3311
3312 DEFUN (no_neighbor_local_as,
3313 no_neighbor_local_as_cmd,
3314 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3315 NO_STR
3316 NEIGHBOR_STR
3317 NEIGHBOR_ADDR_STR2
3318 "Specify a local-as number\n"
3319 "AS number used as local AS\n"
3320 "Do not prepend local-as to updates from ebgp peers\n"
3321 "Do not prepend local-as to updates from ibgp peers\n")
3322 {
3323 int idx_peer = 2;
3324 struct peer *peer;
3325 int ret;
3326
3327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3328 if (!peer)
3329 return CMD_WARNING_CONFIG_FAILED;
3330
3331 ret = peer_local_as_unset(peer);
3332 return bgp_vty_return(vty, ret);
3333 }
3334
3335
3336 DEFUN (neighbor_solo,
3337 neighbor_solo_cmd,
3338 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3339 NEIGHBOR_STR
3340 NEIGHBOR_ADDR_STR2
3341 "Solo peer - part of its own update group\n")
3342 {
3343 int idx_peer = 1;
3344 struct peer *peer;
3345 int ret;
3346
3347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3348 if (!peer)
3349 return CMD_WARNING_CONFIG_FAILED;
3350
3351 ret = update_group_adjust_soloness(peer, 1);
3352 return bgp_vty_return(vty, ret);
3353 }
3354
3355 DEFUN (no_neighbor_solo,
3356 no_neighbor_solo_cmd,
3357 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3358 NO_STR
3359 NEIGHBOR_STR
3360 NEIGHBOR_ADDR_STR2
3361 "Solo peer - part of its own update group\n")
3362 {
3363 int idx_peer = 2;
3364 struct peer *peer;
3365 int ret;
3366
3367 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3368 if (!peer)
3369 return CMD_WARNING_CONFIG_FAILED;
3370
3371 ret = update_group_adjust_soloness(peer, 0);
3372 return bgp_vty_return(vty, ret);
3373 }
3374
3375 DEFUN (neighbor_password,
3376 neighbor_password_cmd,
3377 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3378 NEIGHBOR_STR
3379 NEIGHBOR_ADDR_STR2
3380 "Set a password\n"
3381 "The password\n")
3382 {
3383 int idx_peer = 1;
3384 int idx_line = 3;
3385 struct peer *peer;
3386 int ret;
3387
3388 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3389 if (!peer)
3390 return CMD_WARNING_CONFIG_FAILED;
3391
3392 ret = peer_password_set(peer, argv[idx_line]->arg);
3393 return bgp_vty_return(vty, ret);
3394 }
3395
3396 DEFUN (no_neighbor_password,
3397 no_neighbor_password_cmd,
3398 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3399 NO_STR
3400 NEIGHBOR_STR
3401 NEIGHBOR_ADDR_STR2
3402 "Set a password\n"
3403 "The password\n")
3404 {
3405 int idx_peer = 2;
3406 struct peer *peer;
3407 int ret;
3408
3409 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3410 if (!peer)
3411 return CMD_WARNING_CONFIG_FAILED;
3412
3413 ret = peer_password_unset(peer);
3414 return bgp_vty_return(vty, ret);
3415 }
3416
3417 DEFUN (neighbor_activate,
3418 neighbor_activate_cmd,
3419 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3420 NEIGHBOR_STR
3421 NEIGHBOR_ADDR_STR2
3422 "Enable the Address Family for this Neighbor\n")
3423 {
3424 int idx_peer = 1;
3425 int ret;
3426 struct peer *peer;
3427
3428 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3429 if (!peer)
3430 return CMD_WARNING_CONFIG_FAILED;
3431
3432 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3433 return bgp_vty_return(vty, ret);
3434 }
3435
3436 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3437 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3438 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3439 "Enable the Address Family for this Neighbor\n")
3440
3441 DEFUN (no_neighbor_activate,
3442 no_neighbor_activate_cmd,
3443 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3444 NO_STR
3445 NEIGHBOR_STR
3446 NEIGHBOR_ADDR_STR2
3447 "Enable the Address Family for this Neighbor\n")
3448 {
3449 int idx_peer = 2;
3450 int ret;
3451 struct peer *peer;
3452
3453 /* Lookup peer. */
3454 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3455 if (!peer)
3456 return CMD_WARNING_CONFIG_FAILED;
3457
3458 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3459 return bgp_vty_return(vty, ret);
3460 }
3461
3462 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3463 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3464 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3465 "Enable the Address Family for this Neighbor\n")
3466
3467 DEFUN (neighbor_set_peer_group,
3468 neighbor_set_peer_group_cmd,
3469 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3470 NEIGHBOR_STR
3471 NEIGHBOR_ADDR_STR2
3472 "Member of the peer-group\n"
3473 "Peer-group name\n")
3474 {
3475 VTY_DECLVAR_CONTEXT(bgp, bgp);
3476 int idx_peer = 1;
3477 int idx_word = 3;
3478 int ret;
3479 as_t as;
3480 union sockunion su;
3481 struct peer *peer;
3482 struct peer_group *group;
3483
3484 ret = str2sockunion(argv[idx_peer]->arg, &su);
3485 if (ret < 0) {
3486 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3487 if (!peer) {
3488 vty_out(vty, "%% Malformed address or name: %s\n",
3489 argv[idx_peer]->arg);
3490 return CMD_WARNING_CONFIG_FAILED;
3491 }
3492 } else {
3493 if (peer_address_self_check(bgp, &su)) {
3494 vty_out(vty,
3495 "%% Can not configure the local system as neighbor\n");
3496 return CMD_WARNING_CONFIG_FAILED;
3497 }
3498
3499 /* Disallow for dynamic neighbor. */
3500 peer = peer_lookup(bgp, &su);
3501 if (peer && peer_dynamic_neighbor(peer)) {
3502 vty_out(vty,
3503 "%% Operation not allowed on a dynamic neighbor\n");
3504 return CMD_WARNING_CONFIG_FAILED;
3505 }
3506 }
3507
3508 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3509 if (!group) {
3510 vty_out(vty, "%% Configure the peer-group first\n");
3511 return CMD_WARNING_CONFIG_FAILED;
3512 }
3513
3514 ret = peer_group_bind(bgp, &su, peer, group, &as);
3515
3516 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3517 vty_out(vty,
3518 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3519 as);
3520 return CMD_WARNING_CONFIG_FAILED;
3521 }
3522
3523 return bgp_vty_return(vty, ret);
3524 }
3525
3526 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3527 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3528 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3529 "Member of the peer-group\n"
3530 "Peer-group name\n")
3531
3532 DEFUN (no_neighbor_set_peer_group,
3533 no_neighbor_set_peer_group_cmd,
3534 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3535 NO_STR
3536 NEIGHBOR_STR
3537 NEIGHBOR_ADDR_STR2
3538 "Member of the peer-group\n"
3539 "Peer-group name\n")
3540 {
3541 VTY_DECLVAR_CONTEXT(bgp, bgp);
3542 int idx_peer = 2;
3543 int idx_word = 4;
3544 int ret;
3545 struct peer *peer;
3546 struct peer_group *group;
3547
3548 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3549 if (!peer)
3550 return CMD_WARNING_CONFIG_FAILED;
3551
3552 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3553 if (!group) {
3554 vty_out(vty, "%% Configure the peer-group first\n");
3555 return CMD_WARNING_CONFIG_FAILED;
3556 }
3557
3558 ret = peer_delete(peer);
3559
3560 return bgp_vty_return(vty, ret);
3561 }
3562
3563 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3564 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3565 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3566 "Member of the peer-group\n"
3567 "Peer-group name\n")
3568
3569 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3570 uint32_t flag, int set)
3571 {
3572 int ret;
3573 struct peer *peer;
3574
3575 peer = peer_and_group_lookup_vty(vty, ip_str);
3576 if (!peer)
3577 return CMD_WARNING_CONFIG_FAILED;
3578
3579 /*
3580 * If 'neighbor <interface>', then this is for directly connected peers,
3581 * we should not accept disable-connected-check.
3582 */
3583 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3584 vty_out(vty,
3585 "%s is directly connected peer, cannot accept disable-"
3586 "connected-check\n",
3587 ip_str);
3588 return CMD_WARNING_CONFIG_FAILED;
3589 }
3590
3591 if (!set && flag == PEER_FLAG_SHUTDOWN)
3592 peer_tx_shutdown_message_unset(peer);
3593
3594 if (set)
3595 ret = peer_flag_set(peer, flag);
3596 else
3597 ret = peer_flag_unset(peer, flag);
3598
3599 return bgp_vty_return(vty, ret);
3600 }
3601
3602 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3603 {
3604 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3605 }
3606
3607 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3608 uint32_t flag)
3609 {
3610 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3611 }
3612
3613 /* neighbor passive. */
3614 DEFUN (neighbor_passive,
3615 neighbor_passive_cmd,
3616 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3617 NEIGHBOR_STR
3618 NEIGHBOR_ADDR_STR2
3619 "Don't send open messages to this neighbor\n")
3620 {
3621 int idx_peer = 1;
3622 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3623 }
3624
3625 DEFUN (no_neighbor_passive,
3626 no_neighbor_passive_cmd,
3627 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3628 NO_STR
3629 NEIGHBOR_STR
3630 NEIGHBOR_ADDR_STR2
3631 "Don't send open messages to this neighbor\n")
3632 {
3633 int idx_peer = 2;
3634 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3635 }
3636
3637 /* neighbor shutdown. */
3638 DEFUN (neighbor_shutdown_msg,
3639 neighbor_shutdown_msg_cmd,
3640 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3641 NEIGHBOR_STR
3642 NEIGHBOR_ADDR_STR2
3643 "Administratively shut down this neighbor\n"
3644 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3645 "Shutdown message\n")
3646 {
3647 int idx_peer = 1;
3648
3649 if (argc >= 5) {
3650 struct peer *peer =
3651 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3652 char *message;
3653
3654 if (!peer)
3655 return CMD_WARNING_CONFIG_FAILED;
3656 message = argv_concat(argv, argc, 4);
3657 peer_tx_shutdown_message_set(peer, message);
3658 XFREE(MTYPE_TMP, message);
3659 }
3660
3661 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3662 }
3663
3664 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3665 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3666 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3667 "Administratively shut down this neighbor\n")
3668
3669 DEFUN (no_neighbor_shutdown_msg,
3670 no_neighbor_shutdown_msg_cmd,
3671 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3672 NO_STR
3673 NEIGHBOR_STR
3674 NEIGHBOR_ADDR_STR2
3675 "Administratively shut down this neighbor\n"
3676 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3677 "Shutdown message\n")
3678 {
3679 int idx_peer = 2;
3680
3681 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3682 PEER_FLAG_SHUTDOWN);
3683 }
3684
3685 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3686 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3687 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3688 "Administratively shut down this neighbor\n")
3689
3690 /* neighbor capability dynamic. */
3691 DEFUN (neighbor_capability_dynamic,
3692 neighbor_capability_dynamic_cmd,
3693 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3694 NEIGHBOR_STR
3695 NEIGHBOR_ADDR_STR2
3696 "Advertise capability to the peer\n"
3697 "Advertise dynamic capability to this neighbor\n")
3698 {
3699 int idx_peer = 1;
3700 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3701 PEER_FLAG_DYNAMIC_CAPABILITY);
3702 }
3703
3704 DEFUN (no_neighbor_capability_dynamic,
3705 no_neighbor_capability_dynamic_cmd,
3706 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3707 NO_STR
3708 NEIGHBOR_STR
3709 NEIGHBOR_ADDR_STR2
3710 "Advertise capability to the peer\n"
3711 "Advertise dynamic capability to this neighbor\n")
3712 {
3713 int idx_peer = 2;
3714 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3715 PEER_FLAG_DYNAMIC_CAPABILITY);
3716 }
3717
3718 /* neighbor dont-capability-negotiate */
3719 DEFUN (neighbor_dont_capability_negotiate,
3720 neighbor_dont_capability_negotiate_cmd,
3721 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3722 NEIGHBOR_STR
3723 NEIGHBOR_ADDR_STR2
3724 "Do not perform capability negotiation\n")
3725 {
3726 int idx_peer = 1;
3727 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3728 PEER_FLAG_DONT_CAPABILITY);
3729 }
3730
3731 DEFUN (no_neighbor_dont_capability_negotiate,
3732 no_neighbor_dont_capability_negotiate_cmd,
3733 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3734 NO_STR
3735 NEIGHBOR_STR
3736 NEIGHBOR_ADDR_STR2
3737 "Do not perform capability negotiation\n")
3738 {
3739 int idx_peer = 2;
3740 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3741 PEER_FLAG_DONT_CAPABILITY);
3742 }
3743
3744 /* neighbor capability extended next hop encoding */
3745 DEFUN (neighbor_capability_enhe,
3746 neighbor_capability_enhe_cmd,
3747 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3748 NEIGHBOR_STR
3749 NEIGHBOR_ADDR_STR2
3750 "Advertise capability to the peer\n"
3751 "Advertise extended next-hop capability to the peer\n")
3752 {
3753 int idx_peer = 1;
3754 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3755 PEER_FLAG_CAPABILITY_ENHE);
3756 }
3757
3758 DEFUN (no_neighbor_capability_enhe,
3759 no_neighbor_capability_enhe_cmd,
3760 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3761 NO_STR
3762 NEIGHBOR_STR
3763 NEIGHBOR_ADDR_STR2
3764 "Advertise capability to the peer\n"
3765 "Advertise extended next-hop capability to the peer\n")
3766 {
3767 int idx_peer = 2;
3768 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3769 PEER_FLAG_CAPABILITY_ENHE);
3770 }
3771
3772 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3773 afi_t afi, safi_t safi, uint32_t flag,
3774 int set)
3775 {
3776 int ret;
3777 struct peer *peer;
3778
3779 peer = peer_and_group_lookup_vty(vty, peer_str);
3780 if (!peer)
3781 return CMD_WARNING_CONFIG_FAILED;
3782
3783 if (set)
3784 ret = peer_af_flag_set(peer, afi, safi, flag);
3785 else
3786 ret = peer_af_flag_unset(peer, afi, safi, flag);
3787
3788 return bgp_vty_return(vty, ret);
3789 }
3790
3791 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3792 afi_t afi, safi_t safi, uint32_t flag)
3793 {
3794 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3795 }
3796
3797 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3798 afi_t afi, safi_t safi, uint32_t flag)
3799 {
3800 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3801 }
3802
3803 /* neighbor capability orf prefix-list. */
3804 DEFUN (neighbor_capability_orf_prefix,
3805 neighbor_capability_orf_prefix_cmd,
3806 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3807 NEIGHBOR_STR
3808 NEIGHBOR_ADDR_STR2
3809 "Advertise capability to the peer\n"
3810 "Advertise ORF capability to the peer\n"
3811 "Advertise prefixlist ORF capability to this neighbor\n"
3812 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3813 "Capability to RECEIVE the ORF from this neighbor\n"
3814 "Capability to SEND the ORF to this neighbor\n")
3815 {
3816 int idx_peer = 1;
3817 int idx_send_recv = 5;
3818 uint16_t flag = 0;
3819
3820 if (strmatch(argv[idx_send_recv]->text, "send"))
3821 flag = PEER_FLAG_ORF_PREFIX_SM;
3822 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3823 flag = PEER_FLAG_ORF_PREFIX_RM;
3824 else if (strmatch(argv[idx_send_recv]->text, "both"))
3825 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3826 else {
3827 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3828 return CMD_WARNING_CONFIG_FAILED;
3829 }
3830
3831 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3832 bgp_node_safi(vty), flag);
3833 }
3834
3835 ALIAS_HIDDEN(
3836 neighbor_capability_orf_prefix,
3837 neighbor_capability_orf_prefix_hidden_cmd,
3838 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3839 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3840 "Advertise capability to the peer\n"
3841 "Advertise ORF capability to the peer\n"
3842 "Advertise prefixlist ORF capability to this neighbor\n"
3843 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3844 "Capability to RECEIVE the ORF from this neighbor\n"
3845 "Capability to SEND the ORF to this neighbor\n")
3846
3847 DEFUN (no_neighbor_capability_orf_prefix,
3848 no_neighbor_capability_orf_prefix_cmd,
3849 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3850 NO_STR
3851 NEIGHBOR_STR
3852 NEIGHBOR_ADDR_STR2
3853 "Advertise capability to the peer\n"
3854 "Advertise ORF capability to the peer\n"
3855 "Advertise prefixlist ORF capability to this neighbor\n"
3856 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3857 "Capability to RECEIVE the ORF from this neighbor\n"
3858 "Capability to SEND the ORF to this neighbor\n")
3859 {
3860 int idx_peer = 2;
3861 int idx_send_recv = 6;
3862 uint16_t flag = 0;
3863
3864 if (strmatch(argv[idx_send_recv]->text, "send"))
3865 flag = PEER_FLAG_ORF_PREFIX_SM;
3866 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3867 flag = PEER_FLAG_ORF_PREFIX_RM;
3868 else if (strmatch(argv[idx_send_recv]->text, "both"))
3869 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3870 else {
3871 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3872 return CMD_WARNING_CONFIG_FAILED;
3873 }
3874
3875 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3876 bgp_node_afi(vty), bgp_node_safi(vty),
3877 flag);
3878 }
3879
3880 ALIAS_HIDDEN(
3881 no_neighbor_capability_orf_prefix,
3882 no_neighbor_capability_orf_prefix_hidden_cmd,
3883 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3884 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3885 "Advertise capability to the peer\n"
3886 "Advertise ORF capability to the peer\n"
3887 "Advertise prefixlist ORF capability to this neighbor\n"
3888 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3889 "Capability to RECEIVE the ORF from this neighbor\n"
3890 "Capability to SEND the ORF to this neighbor\n")
3891
3892 /* neighbor next-hop-self. */
3893 DEFUN (neighbor_nexthop_self,
3894 neighbor_nexthop_self_cmd,
3895 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3896 NEIGHBOR_STR
3897 NEIGHBOR_ADDR_STR2
3898 "Disable the next hop calculation for this neighbor\n")
3899 {
3900 int idx_peer = 1;
3901 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3902 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3903 }
3904
3905 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3906 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3908 "Disable the next hop calculation for this neighbor\n")
3909
3910 /* neighbor next-hop-self. */
3911 DEFUN (neighbor_nexthop_self_force,
3912 neighbor_nexthop_self_force_cmd,
3913 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3914 NEIGHBOR_STR
3915 NEIGHBOR_ADDR_STR2
3916 "Disable the next hop calculation for this neighbor\n"
3917 "Set the next hop to self for reflected routes\n")
3918 {
3919 int idx_peer = 1;
3920 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3921 bgp_node_safi(vty),
3922 PEER_FLAG_FORCE_NEXTHOP_SELF);
3923 }
3924
3925 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3926 neighbor_nexthop_self_force_hidden_cmd,
3927 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3929 "Disable the next hop calculation for this neighbor\n"
3930 "Set the next hop to self for reflected routes\n")
3931
3932 DEFUN (no_neighbor_nexthop_self,
3933 no_neighbor_nexthop_self_cmd,
3934 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3935 NO_STR
3936 NEIGHBOR_STR
3937 NEIGHBOR_ADDR_STR2
3938 "Disable the next hop calculation for this neighbor\n")
3939 {
3940 int idx_peer = 2;
3941 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3942 bgp_node_afi(vty), bgp_node_safi(vty),
3943 PEER_FLAG_NEXTHOP_SELF);
3944 }
3945
3946 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3947 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3948 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3949 "Disable the next hop calculation for this neighbor\n")
3950
3951 DEFUN (no_neighbor_nexthop_self_force,
3952 no_neighbor_nexthop_self_force_cmd,
3953 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3954 NO_STR
3955 NEIGHBOR_STR
3956 NEIGHBOR_ADDR_STR2
3957 "Disable the next hop calculation for this neighbor\n"
3958 "Set the next hop to self for reflected routes\n")
3959 {
3960 int idx_peer = 2;
3961 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3962 bgp_node_afi(vty), bgp_node_safi(vty),
3963 PEER_FLAG_FORCE_NEXTHOP_SELF);
3964 }
3965
3966 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3967 no_neighbor_nexthop_self_force_hidden_cmd,
3968 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3970 "Disable the next hop calculation for this neighbor\n"
3971 "Set the next hop to self for reflected routes\n")
3972
3973 /* neighbor as-override */
3974 DEFUN (neighbor_as_override,
3975 neighbor_as_override_cmd,
3976 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3977 NEIGHBOR_STR
3978 NEIGHBOR_ADDR_STR2
3979 "Override ASNs in outbound updates if aspath equals remote-as\n")
3980 {
3981 int idx_peer = 1;
3982 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3983 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3984 }
3985
3986 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3987 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3988 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3989 "Override ASNs in outbound updates if aspath equals remote-as\n")
3990
3991 DEFUN (no_neighbor_as_override,
3992 no_neighbor_as_override_cmd,
3993 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3994 NO_STR
3995 NEIGHBOR_STR
3996 NEIGHBOR_ADDR_STR2
3997 "Override ASNs in outbound updates if aspath equals remote-as\n")
3998 {
3999 int idx_peer = 2;
4000 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4001 bgp_node_afi(vty), bgp_node_safi(vty),
4002 PEER_FLAG_AS_OVERRIDE);
4003 }
4004
4005 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4006 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4007 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4008 "Override ASNs in outbound updates if aspath equals remote-as\n")
4009
4010 /* neighbor remove-private-AS. */
4011 DEFUN (neighbor_remove_private_as,
4012 neighbor_remove_private_as_cmd,
4013 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4014 NEIGHBOR_STR
4015 NEIGHBOR_ADDR_STR2
4016 "Remove private ASNs in outbound updates\n")
4017 {
4018 int idx_peer = 1;
4019 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4020 bgp_node_safi(vty),
4021 PEER_FLAG_REMOVE_PRIVATE_AS);
4022 }
4023
4024 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4025 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4026 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4027 "Remove private ASNs in outbound updates\n")
4028
4029 DEFUN (neighbor_remove_private_as_all,
4030 neighbor_remove_private_as_all_cmd,
4031 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4032 NEIGHBOR_STR
4033 NEIGHBOR_ADDR_STR2
4034 "Remove private ASNs in outbound updates\n"
4035 "Apply to all AS numbers\n")
4036 {
4037 int idx_peer = 1;
4038 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4039 bgp_node_safi(vty),
4040 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4041 }
4042
4043 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4044 neighbor_remove_private_as_all_hidden_cmd,
4045 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4046 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4047 "Remove private ASNs in outbound updates\n"
4048 "Apply to all AS numbers")
4049
4050 DEFUN (neighbor_remove_private_as_replace_as,
4051 neighbor_remove_private_as_replace_as_cmd,
4052 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4053 NEIGHBOR_STR
4054 NEIGHBOR_ADDR_STR2
4055 "Remove private ASNs in outbound updates\n"
4056 "Replace private ASNs with our ASN in outbound updates\n")
4057 {
4058 int idx_peer = 1;
4059 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4060 bgp_node_safi(vty),
4061 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4062 }
4063
4064 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4065 neighbor_remove_private_as_replace_as_hidden_cmd,
4066 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4067 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4068 "Remove private ASNs in outbound updates\n"
4069 "Replace private ASNs with our ASN in outbound updates\n")
4070
4071 DEFUN (neighbor_remove_private_as_all_replace_as,
4072 neighbor_remove_private_as_all_replace_as_cmd,
4073 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4074 NEIGHBOR_STR
4075 NEIGHBOR_ADDR_STR2
4076 "Remove private ASNs in outbound updates\n"
4077 "Apply to all AS numbers\n"
4078 "Replace private ASNs with our ASN in outbound updates\n")
4079 {
4080 int idx_peer = 1;
4081 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4082 bgp_node_safi(vty),
4083 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4084 }
4085
4086 ALIAS_HIDDEN(
4087 neighbor_remove_private_as_all_replace_as,
4088 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4089 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4090 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4091 "Remove private ASNs in outbound updates\n"
4092 "Apply to all AS numbers\n"
4093 "Replace private ASNs with our ASN in outbound updates\n")
4094
4095 DEFUN (no_neighbor_remove_private_as,
4096 no_neighbor_remove_private_as_cmd,
4097 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4098 NO_STR
4099 NEIGHBOR_STR
4100 NEIGHBOR_ADDR_STR2
4101 "Remove private ASNs in outbound updates\n")
4102 {
4103 int idx_peer = 2;
4104 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4105 bgp_node_afi(vty), bgp_node_safi(vty),
4106 PEER_FLAG_REMOVE_PRIVATE_AS);
4107 }
4108
4109 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4110 no_neighbor_remove_private_as_hidden_cmd,
4111 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4113 "Remove private ASNs in outbound updates\n")
4114
4115 DEFUN (no_neighbor_remove_private_as_all,
4116 no_neighbor_remove_private_as_all_cmd,
4117 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4118 NO_STR
4119 NEIGHBOR_STR
4120 NEIGHBOR_ADDR_STR2
4121 "Remove private ASNs in outbound updates\n"
4122 "Apply to all AS numbers\n")
4123 {
4124 int idx_peer = 2;
4125 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4126 bgp_node_afi(vty), bgp_node_safi(vty),
4127 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4128 }
4129
4130 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4131 no_neighbor_remove_private_as_all_hidden_cmd,
4132 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4133 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4134 "Remove private ASNs in outbound updates\n"
4135 "Apply to all AS numbers\n")
4136
4137 DEFUN (no_neighbor_remove_private_as_replace_as,
4138 no_neighbor_remove_private_as_replace_as_cmd,
4139 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4140 NO_STR
4141 NEIGHBOR_STR
4142 NEIGHBOR_ADDR_STR2
4143 "Remove private ASNs in outbound updates\n"
4144 "Replace private ASNs with our ASN in outbound updates\n")
4145 {
4146 int idx_peer = 2;
4147 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4148 bgp_node_afi(vty), bgp_node_safi(vty),
4149 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4150 }
4151
4152 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4153 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4154 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4155 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4156 "Remove private ASNs in outbound updates\n"
4157 "Replace private ASNs with our ASN in outbound updates\n")
4158
4159 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4160 no_neighbor_remove_private_as_all_replace_as_cmd,
4161 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4162 NO_STR
4163 NEIGHBOR_STR
4164 NEIGHBOR_ADDR_STR2
4165 "Remove private ASNs in outbound updates\n"
4166 "Apply to all AS numbers\n"
4167 "Replace private ASNs with our ASN in outbound updates\n")
4168 {
4169 int idx_peer = 2;
4170 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4171 bgp_node_afi(vty), bgp_node_safi(vty),
4172 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4173 }
4174
4175 ALIAS_HIDDEN(
4176 no_neighbor_remove_private_as_all_replace_as,
4177 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4178 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4179 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4180 "Remove private ASNs in outbound updates\n"
4181 "Apply to all AS numbers\n"
4182 "Replace private ASNs with our ASN in outbound updates\n")
4183
4184
4185 /* neighbor send-community. */
4186 DEFUN (neighbor_send_community,
4187 neighbor_send_community_cmd,
4188 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4189 NEIGHBOR_STR
4190 NEIGHBOR_ADDR_STR2
4191 "Send Community attribute to this neighbor\n")
4192 {
4193 int idx_peer = 1;
4194
4195 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4196 bgp_node_safi(vty),
4197 PEER_FLAG_SEND_COMMUNITY);
4198 }
4199
4200 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4201 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4202 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4203 "Send Community attribute to this neighbor\n")
4204
4205 DEFUN (no_neighbor_send_community,
4206 no_neighbor_send_community_cmd,
4207 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4208 NO_STR
4209 NEIGHBOR_STR
4210 NEIGHBOR_ADDR_STR2
4211 "Send Community attribute to this neighbor\n")
4212 {
4213 int idx_peer = 2;
4214
4215 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4216 bgp_node_afi(vty), bgp_node_safi(vty),
4217 PEER_FLAG_SEND_COMMUNITY);
4218 }
4219
4220 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4221 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4222 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4223 "Send Community attribute to this neighbor\n")
4224
4225 /* neighbor send-community extended. */
4226 DEFUN (neighbor_send_community_type,
4227 neighbor_send_community_type_cmd,
4228 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4229 NEIGHBOR_STR
4230 NEIGHBOR_ADDR_STR2
4231 "Send Community attribute to this neighbor\n"
4232 "Send Standard and Extended Community attributes\n"
4233 "Send Standard, Large and Extended Community attributes\n"
4234 "Send Extended Community attributes\n"
4235 "Send Standard Community attributes\n"
4236 "Send Large Community attributes\n")
4237 {
4238 int idx_peer = 1;
4239 uint32_t flag = 0;
4240 const char *type = argv[argc - 1]->text;
4241
4242 if (strmatch(type, "standard")) {
4243 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4244 } else if (strmatch(type, "extended")) {
4245 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4246 } else if (strmatch(type, "large")) {
4247 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4248 } else if (strmatch(type, "both")) {
4249 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4250 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4251 } else { /* if (strmatch(type, "all")) */
4252 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4253 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4254 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4255 }
4256
4257 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4258 bgp_node_safi(vty), flag);
4259 }
4260
4261 ALIAS_HIDDEN(
4262 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4263 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4264 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4265 "Send Community attribute to this neighbor\n"
4266 "Send Standard and Extended Community attributes\n"
4267 "Send Standard, Large and Extended Community attributes\n"
4268 "Send Extended Community attributes\n"
4269 "Send Standard Community attributes\n"
4270 "Send Large Community attributes\n")
4271
4272 DEFUN (no_neighbor_send_community_type,
4273 no_neighbor_send_community_type_cmd,
4274 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4275 NO_STR
4276 NEIGHBOR_STR
4277 NEIGHBOR_ADDR_STR2
4278 "Send Community attribute to this neighbor\n"
4279 "Send Standard and Extended Community attributes\n"
4280 "Send Standard, Large and Extended Community attributes\n"
4281 "Send Extended Community attributes\n"
4282 "Send Standard Community attributes\n"
4283 "Send Large Community attributes\n")
4284 {
4285 int idx_peer = 2;
4286 uint32_t flag = 0;
4287 const char *type = argv[argc - 1]->text;
4288
4289 if (strmatch(type, "standard")) {
4290 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4291 } else if (strmatch(type, "extended")) {
4292 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4293 } else if (strmatch(type, "large")) {
4294 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4295 } else if (strmatch(type, "both")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4297 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4298 } else { /* if (strmatch(type, "all")) */
4299 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4300 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4301 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4302 }
4303
4304 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4305 bgp_node_afi(vty), bgp_node_safi(vty),
4306 flag);
4307 }
4308
4309 ALIAS_HIDDEN(
4310 no_neighbor_send_community_type,
4311 no_neighbor_send_community_type_hidden_cmd,
4312 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4313 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4314 "Send Community attribute to this neighbor\n"
4315 "Send Standard and Extended Community attributes\n"
4316 "Send Standard, Large and Extended Community attributes\n"
4317 "Send Extended Community attributes\n"
4318 "Send Standard Community attributes\n"
4319 "Send Large Community attributes\n")
4320
4321 /* neighbor soft-reconfig. */
4322 DEFUN (neighbor_soft_reconfiguration,
4323 neighbor_soft_reconfiguration_cmd,
4324 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4325 NEIGHBOR_STR
4326 NEIGHBOR_ADDR_STR2
4327 "Per neighbor soft reconfiguration\n"
4328 "Allow inbound soft reconfiguration for this neighbor\n")
4329 {
4330 int idx_peer = 1;
4331 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4332 bgp_node_safi(vty),
4333 PEER_FLAG_SOFT_RECONFIG);
4334 }
4335
4336 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4337 neighbor_soft_reconfiguration_hidden_cmd,
4338 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4339 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4340 "Per neighbor soft reconfiguration\n"
4341 "Allow inbound soft reconfiguration for this neighbor\n")
4342
4343 DEFUN (no_neighbor_soft_reconfiguration,
4344 no_neighbor_soft_reconfiguration_cmd,
4345 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4346 NO_STR
4347 NEIGHBOR_STR
4348 NEIGHBOR_ADDR_STR2
4349 "Per neighbor soft reconfiguration\n"
4350 "Allow inbound soft reconfiguration for this neighbor\n")
4351 {
4352 int idx_peer = 2;
4353 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4354 bgp_node_afi(vty), bgp_node_safi(vty),
4355 PEER_FLAG_SOFT_RECONFIG);
4356 }
4357
4358 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4359 no_neighbor_soft_reconfiguration_hidden_cmd,
4360 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4361 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4362 "Per neighbor soft reconfiguration\n"
4363 "Allow inbound soft reconfiguration for this neighbor\n")
4364
4365 DEFUN (neighbor_route_reflector_client,
4366 neighbor_route_reflector_client_cmd,
4367 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4368 NEIGHBOR_STR
4369 NEIGHBOR_ADDR_STR2
4370 "Configure a neighbor as Route Reflector client\n")
4371 {
4372 int idx_peer = 1;
4373 struct peer *peer;
4374
4375
4376 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4377 if (!peer)
4378 return CMD_WARNING_CONFIG_FAILED;
4379
4380 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4381 bgp_node_safi(vty),
4382 PEER_FLAG_REFLECTOR_CLIENT);
4383 }
4384
4385 ALIAS_HIDDEN(neighbor_route_reflector_client,
4386 neighbor_route_reflector_client_hidden_cmd,
4387 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4388 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4389 "Configure a neighbor as Route Reflector client\n")
4390
4391 DEFUN (no_neighbor_route_reflector_client,
4392 no_neighbor_route_reflector_client_cmd,
4393 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4394 NO_STR
4395 NEIGHBOR_STR
4396 NEIGHBOR_ADDR_STR2
4397 "Configure a neighbor as Route Reflector client\n")
4398 {
4399 int idx_peer = 2;
4400 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4401 bgp_node_afi(vty), bgp_node_safi(vty),
4402 PEER_FLAG_REFLECTOR_CLIENT);
4403 }
4404
4405 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4406 no_neighbor_route_reflector_client_hidden_cmd,
4407 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4408 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4409 "Configure a neighbor as Route Reflector client\n")
4410
4411 /* neighbor route-server-client. */
4412 DEFUN (neighbor_route_server_client,
4413 neighbor_route_server_client_cmd,
4414 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4415 NEIGHBOR_STR
4416 NEIGHBOR_ADDR_STR2
4417 "Configure a neighbor as Route Server client\n")
4418 {
4419 int idx_peer = 1;
4420 struct peer *peer;
4421
4422 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4423 if (!peer)
4424 return CMD_WARNING_CONFIG_FAILED;
4425 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4426 bgp_node_safi(vty),
4427 PEER_FLAG_RSERVER_CLIENT);
4428 }
4429
4430 ALIAS_HIDDEN(neighbor_route_server_client,
4431 neighbor_route_server_client_hidden_cmd,
4432 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4433 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4434 "Configure a neighbor as Route Server client\n")
4435
4436 DEFUN (no_neighbor_route_server_client,
4437 no_neighbor_route_server_client_cmd,
4438 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4439 NO_STR
4440 NEIGHBOR_STR
4441 NEIGHBOR_ADDR_STR2
4442 "Configure a neighbor as Route Server client\n")
4443 {
4444 int idx_peer = 2;
4445 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4446 bgp_node_afi(vty), bgp_node_safi(vty),
4447 PEER_FLAG_RSERVER_CLIENT);
4448 }
4449
4450 ALIAS_HIDDEN(no_neighbor_route_server_client,
4451 no_neighbor_route_server_client_hidden_cmd,
4452 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4453 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4454 "Configure a neighbor as Route Server client\n")
4455
4456 DEFUN (neighbor_nexthop_local_unchanged,
4457 neighbor_nexthop_local_unchanged_cmd,
4458 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4459 NEIGHBOR_STR
4460 NEIGHBOR_ADDR_STR2
4461 "Configure treatment of outgoing link-local nexthop attribute\n"
4462 "Leave link-local nexthop unchanged for this peer\n")
4463 {
4464 int idx_peer = 1;
4465 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4466 bgp_node_safi(vty),
4467 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4468 }
4469
4470 DEFUN (no_neighbor_nexthop_local_unchanged,
4471 no_neighbor_nexthop_local_unchanged_cmd,
4472 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4473 NO_STR
4474 NEIGHBOR_STR
4475 NEIGHBOR_ADDR_STR2
4476 "Configure treatment of outgoing link-local-nexthop attribute\n"
4477 "Leave link-local nexthop unchanged for this peer\n")
4478 {
4479 int idx_peer = 2;
4480 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4481 bgp_node_afi(vty), bgp_node_safi(vty),
4482 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4483 }
4484
4485 DEFUN (neighbor_attr_unchanged,
4486 neighbor_attr_unchanged_cmd,
4487 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4488 NEIGHBOR_STR
4489 NEIGHBOR_ADDR_STR2
4490 "BGP attribute is propagated unchanged to this neighbor\n"
4491 "As-path attribute\n"
4492 "Nexthop attribute\n"
4493 "Med attribute\n")
4494 {
4495 int idx = 0;
4496 char *peer_str = argv[1]->arg;
4497 struct peer *peer;
4498 uint16_t flags = 0;
4499 afi_t afi = bgp_node_afi(vty);
4500 safi_t safi = bgp_node_safi(vty);
4501
4502 peer = peer_and_group_lookup_vty(vty, peer_str);
4503 if (!peer)
4504 return CMD_WARNING_CONFIG_FAILED;
4505
4506 if (argv_find(argv, argc, "as-path", &idx))
4507 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4508 idx = 0;
4509 if (argv_find(argv, argc, "next-hop", &idx))
4510 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4511 idx = 0;
4512 if (argv_find(argv, argc, "med", &idx))
4513 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4514
4515 /* no flags means all of them! */
4516 if (!flags) {
4517 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4518 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4519 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4520 } else {
4521 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4522 && peer_af_flag_check(peer, afi, safi,
4523 PEER_FLAG_AS_PATH_UNCHANGED)) {
4524 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4525 PEER_FLAG_AS_PATH_UNCHANGED);
4526 }
4527
4528 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4529 && peer_af_flag_check(peer, afi, safi,
4530 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4531 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4532 PEER_FLAG_NEXTHOP_UNCHANGED);
4533 }
4534
4535 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4536 && peer_af_flag_check(peer, afi, safi,
4537 PEER_FLAG_MED_UNCHANGED)) {
4538 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4539 PEER_FLAG_MED_UNCHANGED);
4540 }
4541 }
4542
4543 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4544 }
4545
4546 ALIAS_HIDDEN(
4547 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4548 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4549 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4550 "BGP attribute is propagated unchanged to this neighbor\n"
4551 "As-path attribute\n"
4552 "Nexthop attribute\n"
4553 "Med attribute\n")
4554
4555 DEFUN (no_neighbor_attr_unchanged,
4556 no_neighbor_attr_unchanged_cmd,
4557 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4558 NO_STR
4559 NEIGHBOR_STR
4560 NEIGHBOR_ADDR_STR2
4561 "BGP attribute is propagated unchanged to this neighbor\n"
4562 "As-path attribute\n"
4563 "Nexthop attribute\n"
4564 "Med attribute\n")
4565 {
4566 int idx = 0;
4567 char *peer = argv[2]->arg;
4568 uint16_t flags = 0;
4569
4570 if (argv_find(argv, argc, "as-path", &idx))
4571 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4572 idx = 0;
4573 if (argv_find(argv, argc, "next-hop", &idx))
4574 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4575 idx = 0;
4576 if (argv_find(argv, argc, "med", &idx))
4577 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4578
4579 if (!flags) // no flags means all of them!
4580 {
4581 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4582 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4583 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4584 }
4585
4586 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4587 bgp_node_safi(vty), flags);
4588 }
4589
4590 ALIAS_HIDDEN(
4591 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4592 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4593 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4594 "BGP attribute is propagated unchanged to this neighbor\n"
4595 "As-path attribute\n"
4596 "Nexthop attribute\n"
4597 "Med attribute\n")
4598
4599 /* EBGP multihop configuration. */
4600 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4601 const char *ttl_str)
4602 {
4603 struct peer *peer;
4604 unsigned int ttl;
4605
4606 peer = peer_and_group_lookup_vty(vty, ip_str);
4607 if (!peer)
4608 return CMD_WARNING_CONFIG_FAILED;
4609
4610 if (peer->conf_if)
4611 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4612
4613 if (!ttl_str)
4614 ttl = MAXTTL;
4615 else
4616 ttl = strtoul(ttl_str, NULL, 10);
4617
4618 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4619 }
4620
4621 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4622 {
4623 struct peer *peer;
4624
4625 peer = peer_and_group_lookup_vty(vty, ip_str);
4626 if (!peer)
4627 return CMD_WARNING_CONFIG_FAILED;
4628
4629 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4630 }
4631
4632 /* neighbor ebgp-multihop. */
4633 DEFUN (neighbor_ebgp_multihop,
4634 neighbor_ebgp_multihop_cmd,
4635 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4636 NEIGHBOR_STR
4637 NEIGHBOR_ADDR_STR2
4638 "Allow EBGP neighbors not on directly connected networks\n")
4639 {
4640 int idx_peer = 1;
4641 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4642 }
4643
4644 DEFUN (neighbor_ebgp_multihop_ttl,
4645 neighbor_ebgp_multihop_ttl_cmd,
4646 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4647 NEIGHBOR_STR
4648 NEIGHBOR_ADDR_STR2
4649 "Allow EBGP neighbors not on directly connected networks\n"
4650 "maximum hop count\n")
4651 {
4652 int idx_peer = 1;
4653 int idx_number = 3;
4654 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4655 argv[idx_number]->arg);
4656 }
4657
4658 DEFUN (no_neighbor_ebgp_multihop,
4659 no_neighbor_ebgp_multihop_cmd,
4660 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4661 NO_STR
4662 NEIGHBOR_STR
4663 NEIGHBOR_ADDR_STR2
4664 "Allow EBGP neighbors not on directly connected networks\n"
4665 "maximum hop count\n")
4666 {
4667 int idx_peer = 2;
4668 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4669 }
4670
4671
4672 /* disable-connected-check */
4673 DEFUN (neighbor_disable_connected_check,
4674 neighbor_disable_connected_check_cmd,
4675 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4676 NEIGHBOR_STR
4677 NEIGHBOR_ADDR_STR2
4678 "one-hop away EBGP peer using loopback address\n"
4679 "Enforce EBGP neighbors perform multihop\n")
4680 {
4681 int idx_peer = 1;
4682 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4683 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4684 }
4685
4686 DEFUN (no_neighbor_disable_connected_check,
4687 no_neighbor_disable_connected_check_cmd,
4688 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4689 NO_STR
4690 NEIGHBOR_STR
4691 NEIGHBOR_ADDR_STR2
4692 "one-hop away EBGP peer using loopback address\n"
4693 "Enforce EBGP neighbors perform multihop\n")
4694 {
4695 int idx_peer = 2;
4696 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4697 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4698 }
4699
4700
4701 /* enforce-first-as */
4702 DEFUN (neighbor_enforce_first_as,
4703 neighbor_enforce_first_as_cmd,
4704 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4705 NEIGHBOR_STR
4706 NEIGHBOR_ADDR_STR2
4707 "Enforce the first AS for EBGP routes\n")
4708 {
4709 int idx_peer = 1;
4710
4711 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4712 PEER_FLAG_ENFORCE_FIRST_AS);
4713 }
4714
4715 DEFUN (no_neighbor_enforce_first_as,
4716 no_neighbor_enforce_first_as_cmd,
4717 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4718 NO_STR
4719 NEIGHBOR_STR
4720 NEIGHBOR_ADDR_STR2
4721 "Enforce the first AS for EBGP routes\n")
4722 {
4723 int idx_peer = 2;
4724
4725 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4726 PEER_FLAG_ENFORCE_FIRST_AS);
4727 }
4728
4729
4730 DEFUN (neighbor_description,
4731 neighbor_description_cmd,
4732 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4733 NEIGHBOR_STR
4734 NEIGHBOR_ADDR_STR2
4735 "Neighbor specific description\n"
4736 "Up to 80 characters describing this neighbor\n")
4737 {
4738 int idx_peer = 1;
4739 int idx_line = 3;
4740 struct peer *peer;
4741 char *str;
4742
4743 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4744 if (!peer)
4745 return CMD_WARNING_CONFIG_FAILED;
4746
4747 str = argv_concat(argv, argc, idx_line);
4748
4749 peer_description_set(peer, str);
4750
4751 XFREE(MTYPE_TMP, str);
4752
4753 return CMD_SUCCESS;
4754 }
4755
4756 DEFUN (no_neighbor_description,
4757 no_neighbor_description_cmd,
4758 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4759 NO_STR
4760 NEIGHBOR_STR
4761 NEIGHBOR_ADDR_STR2
4762 "Neighbor specific description\n")
4763 {
4764 int idx_peer = 2;
4765 struct peer *peer;
4766
4767 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4768 if (!peer)
4769 return CMD_WARNING_CONFIG_FAILED;
4770
4771 peer_description_unset(peer);
4772
4773 return CMD_SUCCESS;
4774 }
4775
4776 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4777 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4778 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4779 "Neighbor specific description\n"
4780 "Up to 80 characters describing this neighbor\n")
4781
4782 /* Neighbor update-source. */
4783 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4784 const char *source_str)
4785 {
4786 struct peer *peer;
4787 struct prefix p;
4788 union sockunion su;
4789
4790 peer = peer_and_group_lookup_vty(vty, peer_str);
4791 if (!peer)
4792 return CMD_WARNING_CONFIG_FAILED;
4793
4794 if (peer->conf_if)
4795 return CMD_WARNING;
4796
4797 if (source_str) {
4798 if (str2sockunion(source_str, &su) == 0)
4799 peer_update_source_addr_set(peer, &su);
4800 else {
4801 if (str2prefix(source_str, &p)) {
4802 vty_out(vty,
4803 "%% Invalid update-source, remove prefix length \n");
4804 return CMD_WARNING_CONFIG_FAILED;
4805 } else
4806 peer_update_source_if_set(peer, source_str);
4807 }
4808 } else
4809 peer_update_source_unset(peer);
4810
4811 return CMD_SUCCESS;
4812 }
4813
4814 #define BGP_UPDATE_SOURCE_HELP_STR \
4815 "IPv4 address\n" \
4816 "IPv6 address\n" \
4817 "Interface name (requires zebra to be running)\n"
4818
4819 DEFUN (neighbor_update_source,
4820 neighbor_update_source_cmd,
4821 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4822 NEIGHBOR_STR
4823 NEIGHBOR_ADDR_STR2
4824 "Source of routing updates\n"
4825 BGP_UPDATE_SOURCE_HELP_STR)
4826 {
4827 int idx_peer = 1;
4828 int idx_peer_2 = 3;
4829 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4830 argv[idx_peer_2]->arg);
4831 }
4832
4833 DEFUN (no_neighbor_update_source,
4834 no_neighbor_update_source_cmd,
4835 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4836 NO_STR
4837 NEIGHBOR_STR
4838 NEIGHBOR_ADDR_STR2
4839 "Source of routing updates\n"
4840 BGP_UPDATE_SOURCE_HELP_STR)
4841 {
4842 int idx_peer = 2;
4843 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4844 }
4845
4846 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4847 afi_t afi, safi_t safi,
4848 const char *rmap, int set)
4849 {
4850 int ret;
4851 struct peer *peer;
4852 struct route_map *route_map;
4853
4854 peer = peer_and_group_lookup_vty(vty, peer_str);
4855 if (!peer)
4856 return CMD_WARNING_CONFIG_FAILED;
4857
4858 if (set) {
4859 route_map = route_map_lookup_warn_noexist(vty, rmap);
4860 ret = peer_default_originate_set(peer, afi, safi,
4861 rmap, route_map);
4862 } else
4863 ret = peer_default_originate_unset(peer, afi, safi);
4864
4865 return bgp_vty_return(vty, ret);
4866 }
4867
4868 /* neighbor default-originate. */
4869 DEFUN (neighbor_default_originate,
4870 neighbor_default_originate_cmd,
4871 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4872 NEIGHBOR_STR
4873 NEIGHBOR_ADDR_STR2
4874 "Originate default route to this neighbor\n")
4875 {
4876 int idx_peer = 1;
4877 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4878 bgp_node_afi(vty),
4879 bgp_node_safi(vty), NULL, 1);
4880 }
4881
4882 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4883 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4884 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4885 "Originate default route to this neighbor\n")
4886
4887 DEFUN (neighbor_default_originate_rmap,
4888 neighbor_default_originate_rmap_cmd,
4889 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4890 NEIGHBOR_STR
4891 NEIGHBOR_ADDR_STR2
4892 "Originate default route to this neighbor\n"
4893 "Route-map to specify criteria to originate default\n"
4894 "route-map name\n")
4895 {
4896 int idx_peer = 1;
4897 int idx_word = 4;
4898 return peer_default_originate_set_vty(
4899 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4900 argv[idx_word]->arg, 1);
4901 }
4902
4903 ALIAS_HIDDEN(
4904 neighbor_default_originate_rmap,
4905 neighbor_default_originate_rmap_hidden_cmd,
4906 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4908 "Originate default route to this neighbor\n"
4909 "Route-map to specify criteria to originate default\n"
4910 "route-map name\n")
4911
4912 DEFUN (no_neighbor_default_originate,
4913 no_neighbor_default_originate_cmd,
4914 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4915 NO_STR
4916 NEIGHBOR_STR
4917 NEIGHBOR_ADDR_STR2
4918 "Originate default route to this neighbor\n"
4919 "Route-map to specify criteria to originate default\n"
4920 "route-map name\n")
4921 {
4922 int idx_peer = 2;
4923 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4924 bgp_node_afi(vty),
4925 bgp_node_safi(vty), NULL, 0);
4926 }
4927
4928 ALIAS_HIDDEN(
4929 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4930 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4931 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4932 "Originate default route to this neighbor\n"
4933 "Route-map to specify criteria to originate default\n"
4934 "route-map name\n")
4935
4936
4937 /* Set neighbor's BGP port. */
4938 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4939 const char *port_str)
4940 {
4941 struct peer *peer;
4942 uint16_t port;
4943 struct servent *sp;
4944
4945 peer = peer_lookup_vty(vty, ip_str);
4946 if (!peer)
4947 return CMD_WARNING_CONFIG_FAILED;
4948
4949 if (!port_str) {
4950 sp = getservbyname("bgp", "tcp");
4951 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4952 } else {
4953 port = strtoul(port_str, NULL, 10);
4954 }
4955
4956 peer_port_set(peer, port);
4957
4958 return CMD_SUCCESS;
4959 }
4960
4961 /* Set specified peer's BGP port. */
4962 DEFUN (neighbor_port,
4963 neighbor_port_cmd,
4964 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4965 NEIGHBOR_STR
4966 NEIGHBOR_ADDR_STR
4967 "Neighbor's BGP port\n"
4968 "TCP port number\n")
4969 {
4970 int idx_ip = 1;
4971 int idx_number = 3;
4972 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4973 argv[idx_number]->arg);
4974 }
4975
4976 DEFUN (no_neighbor_port,
4977 no_neighbor_port_cmd,
4978 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4979 NO_STR
4980 NEIGHBOR_STR
4981 NEIGHBOR_ADDR_STR
4982 "Neighbor's BGP port\n"
4983 "TCP port number\n")
4984 {
4985 int idx_ip = 2;
4986 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4987 }
4988
4989
4990 /* neighbor weight. */
4991 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4992 safi_t safi, const char *weight_str)
4993 {
4994 int ret;
4995 struct peer *peer;
4996 unsigned long weight;
4997
4998 peer = peer_and_group_lookup_vty(vty, ip_str);
4999 if (!peer)
5000 return CMD_WARNING_CONFIG_FAILED;
5001
5002 weight = strtoul(weight_str, NULL, 10);
5003
5004 ret = peer_weight_set(peer, afi, safi, weight);
5005 return bgp_vty_return(vty, ret);
5006 }
5007
5008 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5009 safi_t safi)
5010 {
5011 int ret;
5012 struct peer *peer;
5013
5014 peer = peer_and_group_lookup_vty(vty, ip_str);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
5017
5018 ret = peer_weight_unset(peer, afi, safi);
5019 return bgp_vty_return(vty, ret);
5020 }
5021
5022 DEFUN (neighbor_weight,
5023 neighbor_weight_cmd,
5024 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5025 NEIGHBOR_STR
5026 NEIGHBOR_ADDR_STR2
5027 "Set default weight for routes from this neighbor\n"
5028 "default weight\n")
5029 {
5030 int idx_peer = 1;
5031 int idx_number = 3;
5032 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5033 bgp_node_safi(vty), argv[idx_number]->arg);
5034 }
5035
5036 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5037 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5038 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5039 "Set default weight for routes from this neighbor\n"
5040 "default weight\n")
5041
5042 DEFUN (no_neighbor_weight,
5043 no_neighbor_weight_cmd,
5044 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5045 NO_STR
5046 NEIGHBOR_STR
5047 NEIGHBOR_ADDR_STR2
5048 "Set default weight for routes from this neighbor\n"
5049 "default weight\n")
5050 {
5051 int idx_peer = 2;
5052 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5053 bgp_node_afi(vty), bgp_node_safi(vty));
5054 }
5055
5056 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5057 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5058 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5059 "Set default weight for routes from this neighbor\n"
5060 "default weight\n")
5061
5062
5063 /* Override capability negotiation. */
5064 DEFUN (neighbor_override_capability,
5065 neighbor_override_capability_cmd,
5066 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5067 NEIGHBOR_STR
5068 NEIGHBOR_ADDR_STR2
5069 "Override capability negotiation result\n")
5070 {
5071 int idx_peer = 1;
5072 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5073 PEER_FLAG_OVERRIDE_CAPABILITY);
5074 }
5075
5076 DEFUN (no_neighbor_override_capability,
5077 no_neighbor_override_capability_cmd,
5078 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5079 NO_STR
5080 NEIGHBOR_STR
5081 NEIGHBOR_ADDR_STR2
5082 "Override capability negotiation result\n")
5083 {
5084 int idx_peer = 2;
5085 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5086 PEER_FLAG_OVERRIDE_CAPABILITY);
5087 }
5088
5089 DEFUN (neighbor_strict_capability,
5090 neighbor_strict_capability_cmd,
5091 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5092 NEIGHBOR_STR
5093 NEIGHBOR_ADDR_STR2
5094 "Strict capability negotiation match\n")
5095 {
5096 int idx_peer = 1;
5097
5098 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5099 PEER_FLAG_STRICT_CAP_MATCH);
5100 }
5101
5102 DEFUN (no_neighbor_strict_capability,
5103 no_neighbor_strict_capability_cmd,
5104 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5105 NO_STR
5106 NEIGHBOR_STR
5107 NEIGHBOR_ADDR_STR2
5108 "Strict capability negotiation match\n")
5109 {
5110 int idx_peer = 2;
5111
5112 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5113 PEER_FLAG_STRICT_CAP_MATCH);
5114 }
5115
5116 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5117 const char *keep_str, const char *hold_str)
5118 {
5119 int ret;
5120 struct peer *peer;
5121 uint32_t keepalive;
5122 uint32_t holdtime;
5123
5124 peer = peer_and_group_lookup_vty(vty, ip_str);
5125 if (!peer)
5126 return CMD_WARNING_CONFIG_FAILED;
5127
5128 keepalive = strtoul(keep_str, NULL, 10);
5129 holdtime = strtoul(hold_str, NULL, 10);
5130
5131 ret = peer_timers_set(peer, keepalive, holdtime);
5132
5133 return bgp_vty_return(vty, ret);
5134 }
5135
5136 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5137 {
5138 int ret;
5139 struct peer *peer;
5140
5141 peer = peer_and_group_lookup_vty(vty, ip_str);
5142 if (!peer)
5143 return CMD_WARNING_CONFIG_FAILED;
5144
5145 ret = peer_timers_unset(peer);
5146
5147 return bgp_vty_return(vty, ret);
5148 }
5149
5150 DEFUN (neighbor_timers,
5151 neighbor_timers_cmd,
5152 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5153 NEIGHBOR_STR
5154 NEIGHBOR_ADDR_STR2
5155 "BGP per neighbor timers\n"
5156 "Keepalive interval\n"
5157 "Holdtime\n")
5158 {
5159 int idx_peer = 1;
5160 int idx_number = 3;
5161 int idx_number_2 = 4;
5162 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5163 argv[idx_number]->arg,
5164 argv[idx_number_2]->arg);
5165 }
5166
5167 DEFUN (no_neighbor_timers,
5168 no_neighbor_timers_cmd,
5169 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5170 NO_STR
5171 NEIGHBOR_STR
5172 NEIGHBOR_ADDR_STR2
5173 "BGP per neighbor timers\n"
5174 "Keepalive interval\n"
5175 "Holdtime\n")
5176 {
5177 int idx_peer = 2;
5178 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5179 }
5180
5181
5182 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5183 const char *time_str)
5184 {
5185 int ret;
5186 struct peer *peer;
5187 uint32_t connect;
5188
5189 peer = peer_and_group_lookup_vty(vty, ip_str);
5190 if (!peer)
5191 return CMD_WARNING_CONFIG_FAILED;
5192
5193 connect = strtoul(time_str, NULL, 10);
5194
5195 ret = peer_timers_connect_set(peer, connect);
5196
5197 return bgp_vty_return(vty, ret);
5198 }
5199
5200 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5201 {
5202 int ret;
5203 struct peer *peer;
5204
5205 peer = peer_and_group_lookup_vty(vty, ip_str);
5206 if (!peer)
5207 return CMD_WARNING_CONFIG_FAILED;
5208
5209 ret = peer_timers_connect_unset(peer);
5210
5211 return bgp_vty_return(vty, ret);
5212 }
5213
5214 DEFUN (neighbor_timers_connect,
5215 neighbor_timers_connect_cmd,
5216 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5217 NEIGHBOR_STR
5218 NEIGHBOR_ADDR_STR2
5219 "BGP per neighbor timers\n"
5220 "BGP connect timer\n"
5221 "Connect timer\n")
5222 {
5223 int idx_peer = 1;
5224 int idx_number = 4;
5225 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5226 argv[idx_number]->arg);
5227 }
5228
5229 DEFUN (no_neighbor_timers_connect,
5230 no_neighbor_timers_connect_cmd,
5231 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5232 NO_STR
5233 NEIGHBOR_STR
5234 NEIGHBOR_ADDR_STR2
5235 "BGP per neighbor timers\n"
5236 "BGP connect timer\n"
5237 "Connect timer\n")
5238 {
5239 int idx_peer = 2;
5240 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5241 }
5242
5243
5244 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5245 const char *time_str, int set)
5246 {
5247 int ret;
5248 struct peer *peer;
5249 uint32_t routeadv = 0;
5250
5251 peer = peer_and_group_lookup_vty(vty, ip_str);
5252 if (!peer)
5253 return CMD_WARNING_CONFIG_FAILED;
5254
5255 if (time_str)
5256 routeadv = strtoul(time_str, NULL, 10);
5257
5258 if (set)
5259 ret = peer_advertise_interval_set(peer, routeadv);
5260 else
5261 ret = peer_advertise_interval_unset(peer);
5262
5263 return bgp_vty_return(vty, ret);
5264 }
5265
5266 DEFUN (neighbor_advertise_interval,
5267 neighbor_advertise_interval_cmd,
5268 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5269 NEIGHBOR_STR
5270 NEIGHBOR_ADDR_STR2
5271 "Minimum interval between sending BGP routing updates\n"
5272 "time in seconds\n")
5273 {
5274 int idx_peer = 1;
5275 int idx_number = 3;
5276 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5277 argv[idx_number]->arg, 1);
5278 }
5279
5280 DEFUN (no_neighbor_advertise_interval,
5281 no_neighbor_advertise_interval_cmd,
5282 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5283 NO_STR
5284 NEIGHBOR_STR
5285 NEIGHBOR_ADDR_STR2
5286 "Minimum interval between sending BGP routing updates\n"
5287 "time in seconds\n")
5288 {
5289 int idx_peer = 2;
5290 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5291 }
5292
5293
5294 /* Time to wait before processing route-map updates */
5295 DEFUN (bgp_set_route_map_delay_timer,
5296 bgp_set_route_map_delay_timer_cmd,
5297 "bgp route-map delay-timer (0-600)",
5298 SET_STR
5299 "BGP route-map delay timer\n"
5300 "Time in secs to wait before processing route-map changes\n"
5301 "0 disables the timer, no route updates happen when route-maps change\n")
5302 {
5303 int idx_number = 3;
5304 uint32_t rmap_delay_timer;
5305
5306 if (argv[idx_number]->arg) {
5307 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5308 bm->rmap_update_timer = rmap_delay_timer;
5309
5310 /* if the dynamic update handling is being disabled, and a timer
5311 * is
5312 * running, stop the timer and act as if the timer has already
5313 * fired.
5314 */
5315 if (!rmap_delay_timer && bm->t_rmap_update) {
5316 BGP_TIMER_OFF(bm->t_rmap_update);
5317 thread_execute(bm->master, bgp_route_map_update_timer,
5318 NULL, 0);
5319 }
5320 return CMD_SUCCESS;
5321 } else {
5322 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5323 return CMD_WARNING_CONFIG_FAILED;
5324 }
5325 }
5326
5327 DEFUN (no_bgp_set_route_map_delay_timer,
5328 no_bgp_set_route_map_delay_timer_cmd,
5329 "no bgp route-map delay-timer [(0-600)]",
5330 NO_STR
5331 BGP_STR
5332 "Default BGP route-map delay timer\n"
5333 "Reset to default time to wait for processing route-map changes\n"
5334 "0 disables the timer, no route updates happen when route-maps change\n")
5335 {
5336
5337 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5338
5339 return CMD_SUCCESS;
5340 }
5341
5342
5343 /* neighbor interface */
5344 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5345 const char *str)
5346 {
5347 struct peer *peer;
5348
5349 peer = peer_lookup_vty(vty, ip_str);
5350 if (!peer || peer->conf_if) {
5351 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5352 return CMD_WARNING_CONFIG_FAILED;
5353 }
5354
5355 if (str)
5356 peer_interface_set(peer, str);
5357 else
5358 peer_interface_unset(peer);
5359
5360 return CMD_SUCCESS;
5361 }
5362
5363 DEFUN (neighbor_interface,
5364 neighbor_interface_cmd,
5365 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5366 NEIGHBOR_STR
5367 NEIGHBOR_ADDR_STR
5368 "Interface\n"
5369 "Interface name\n")
5370 {
5371 int idx_ip = 1;
5372 int idx_word = 3;
5373 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5374 }
5375
5376 DEFUN (no_neighbor_interface,
5377 no_neighbor_interface_cmd,
5378 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5379 NO_STR
5380 NEIGHBOR_STR
5381 NEIGHBOR_ADDR_STR2
5382 "Interface\n"
5383 "Interface name\n")
5384 {
5385 int idx_peer = 2;
5386 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5387 }
5388
5389 DEFUN (neighbor_distribute_list,
5390 neighbor_distribute_list_cmd,
5391 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5392 NEIGHBOR_STR
5393 NEIGHBOR_ADDR_STR2
5394 "Filter updates to/from this neighbor\n"
5395 "IP access-list number\n"
5396 "IP access-list number (expanded range)\n"
5397 "IP Access-list name\n"
5398 "Filter incoming updates\n"
5399 "Filter outgoing updates\n")
5400 {
5401 int idx_peer = 1;
5402 int idx_acl = 3;
5403 int direct, ret;
5404 struct peer *peer;
5405
5406 const char *pstr = argv[idx_peer]->arg;
5407 const char *acl = argv[idx_acl]->arg;
5408 const char *inout = argv[argc - 1]->text;
5409
5410 peer = peer_and_group_lookup_vty(vty, pstr);
5411 if (!peer)
5412 return CMD_WARNING_CONFIG_FAILED;
5413
5414 /* Check filter direction. */
5415 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5416 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5417 direct, acl);
5418
5419 return bgp_vty_return(vty, ret);
5420 }
5421
5422 ALIAS_HIDDEN(
5423 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5424 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5425 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5426 "Filter updates to/from this neighbor\n"
5427 "IP access-list number\n"
5428 "IP access-list number (expanded range)\n"
5429 "IP Access-list name\n"
5430 "Filter incoming updates\n"
5431 "Filter outgoing updates\n")
5432
5433 DEFUN (no_neighbor_distribute_list,
5434 no_neighbor_distribute_list_cmd,
5435 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5436 NO_STR
5437 NEIGHBOR_STR
5438 NEIGHBOR_ADDR_STR2
5439 "Filter updates to/from this neighbor\n"
5440 "IP access-list number\n"
5441 "IP access-list number (expanded range)\n"
5442 "IP Access-list name\n"
5443 "Filter incoming updates\n"
5444 "Filter outgoing updates\n")
5445 {
5446 int idx_peer = 2;
5447 int direct, ret;
5448 struct peer *peer;
5449
5450 const char *pstr = argv[idx_peer]->arg;
5451 const char *inout = argv[argc - 1]->text;
5452
5453 peer = peer_and_group_lookup_vty(vty, pstr);
5454 if (!peer)
5455 return CMD_WARNING_CONFIG_FAILED;
5456
5457 /* Check filter direction. */
5458 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5459 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5460 direct);
5461
5462 return bgp_vty_return(vty, ret);
5463 }
5464
5465 ALIAS_HIDDEN(
5466 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5467 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5468 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5469 "Filter updates to/from this neighbor\n"
5470 "IP access-list number\n"
5471 "IP access-list number (expanded range)\n"
5472 "IP Access-list name\n"
5473 "Filter incoming updates\n"
5474 "Filter outgoing updates\n")
5475
5476 /* Set prefix list to the peer. */
5477 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5478 afi_t afi, safi_t safi,
5479 const char *name_str,
5480 const char *direct_str)
5481 {
5482 int ret;
5483 int direct = FILTER_IN;
5484 struct peer *peer;
5485
5486 peer = peer_and_group_lookup_vty(vty, ip_str);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
5489
5490 /* Check filter direction. */
5491 if (strncmp(direct_str, "i", 1) == 0)
5492 direct = FILTER_IN;
5493 else if (strncmp(direct_str, "o", 1) == 0)
5494 direct = FILTER_OUT;
5495
5496 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5497
5498 return bgp_vty_return(vty, ret);
5499 }
5500
5501 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5502 afi_t afi, safi_t safi,
5503 const char *direct_str)
5504 {
5505 int ret;
5506 struct peer *peer;
5507 int direct = FILTER_IN;
5508
5509 peer = peer_and_group_lookup_vty(vty, ip_str);
5510 if (!peer)
5511 return CMD_WARNING_CONFIG_FAILED;
5512
5513 /* Check filter direction. */
5514 if (strncmp(direct_str, "i", 1) == 0)
5515 direct = FILTER_IN;
5516 else if (strncmp(direct_str, "o", 1) == 0)
5517 direct = FILTER_OUT;
5518
5519 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5520
5521 return bgp_vty_return(vty, ret);
5522 }
5523
5524 DEFUN (neighbor_prefix_list,
5525 neighbor_prefix_list_cmd,
5526 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5527 NEIGHBOR_STR
5528 NEIGHBOR_ADDR_STR2
5529 "Filter updates to/from this neighbor\n"
5530 "Name of a prefix list\n"
5531 "Filter incoming updates\n"
5532 "Filter outgoing updates\n")
5533 {
5534 int idx_peer = 1;
5535 int idx_word = 3;
5536 int idx_in_out = 4;
5537 return peer_prefix_list_set_vty(
5538 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5539 argv[idx_word]->arg, argv[idx_in_out]->arg);
5540 }
5541
5542 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5543 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5544 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5545 "Filter updates to/from this neighbor\n"
5546 "Name of a prefix list\n"
5547 "Filter incoming updates\n"
5548 "Filter outgoing updates\n")
5549
5550 DEFUN (no_neighbor_prefix_list,
5551 no_neighbor_prefix_list_cmd,
5552 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5553 NO_STR
5554 NEIGHBOR_STR
5555 NEIGHBOR_ADDR_STR2
5556 "Filter updates to/from this neighbor\n"
5557 "Name of a prefix list\n"
5558 "Filter incoming updates\n"
5559 "Filter outgoing updates\n")
5560 {
5561 int idx_peer = 2;
5562 int idx_in_out = 5;
5563 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5564 bgp_node_afi(vty), bgp_node_safi(vty),
5565 argv[idx_in_out]->arg);
5566 }
5567
5568 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5569 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5570 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5571 "Filter updates to/from this neighbor\n"
5572 "Name of a prefix list\n"
5573 "Filter incoming updates\n"
5574 "Filter outgoing updates\n")
5575
5576 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5577 safi_t safi, const char *name_str,
5578 const char *direct_str)
5579 {
5580 int ret;
5581 struct peer *peer;
5582 int direct = FILTER_IN;
5583
5584 peer = peer_and_group_lookup_vty(vty, ip_str);
5585 if (!peer)
5586 return CMD_WARNING_CONFIG_FAILED;
5587
5588 /* Check filter direction. */
5589 if (strncmp(direct_str, "i", 1) == 0)
5590 direct = FILTER_IN;
5591 else if (strncmp(direct_str, "o", 1) == 0)
5592 direct = FILTER_OUT;
5593
5594 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5595
5596 return bgp_vty_return(vty, ret);
5597 }
5598
5599 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5600 safi_t safi, const char *direct_str)
5601 {
5602 int ret;
5603 struct peer *peer;
5604 int direct = FILTER_IN;
5605
5606 peer = peer_and_group_lookup_vty(vty, ip_str);
5607 if (!peer)
5608 return CMD_WARNING_CONFIG_FAILED;
5609
5610 /* Check filter direction. */
5611 if (strncmp(direct_str, "i", 1) == 0)
5612 direct = FILTER_IN;
5613 else if (strncmp(direct_str, "o", 1) == 0)
5614 direct = FILTER_OUT;
5615
5616 ret = peer_aslist_unset(peer, afi, safi, direct);
5617
5618 return bgp_vty_return(vty, ret);
5619 }
5620
5621 DEFUN (neighbor_filter_list,
5622 neighbor_filter_list_cmd,
5623 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5624 NEIGHBOR_STR
5625 NEIGHBOR_ADDR_STR2
5626 "Establish BGP filters\n"
5627 "AS path access-list name\n"
5628 "Filter incoming routes\n"
5629 "Filter outgoing routes\n")
5630 {
5631 int idx_peer = 1;
5632 int idx_word = 3;
5633 int idx_in_out = 4;
5634 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5635 bgp_node_safi(vty), argv[idx_word]->arg,
5636 argv[idx_in_out]->arg);
5637 }
5638
5639 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5641 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5642 "Establish BGP filters\n"
5643 "AS path access-list name\n"
5644 "Filter incoming routes\n"
5645 "Filter outgoing routes\n")
5646
5647 DEFUN (no_neighbor_filter_list,
5648 no_neighbor_filter_list_cmd,
5649 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5650 NO_STR
5651 NEIGHBOR_STR
5652 NEIGHBOR_ADDR_STR2
5653 "Establish BGP filters\n"
5654 "AS path access-list name\n"
5655 "Filter incoming routes\n"
5656 "Filter outgoing routes\n")
5657 {
5658 int idx_peer = 2;
5659 int idx_in_out = 5;
5660 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5661 bgp_node_afi(vty), bgp_node_safi(vty),
5662 argv[idx_in_out]->arg);
5663 }
5664
5665 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5666 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5667 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5668 "Establish BGP filters\n"
5669 "AS path access-list name\n"
5670 "Filter incoming routes\n"
5671 "Filter outgoing routes\n")
5672
5673 /* Set route-map to the peer. */
5674 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5675 afi_t afi, safi_t safi, const char *name_str,
5676 const char *direct_str)
5677 {
5678 int ret;
5679 struct peer *peer;
5680 int direct = RMAP_IN;
5681 struct route_map *route_map;
5682
5683 peer = peer_and_group_lookup_vty(vty, ip_str);
5684 if (!peer)
5685 return CMD_WARNING_CONFIG_FAILED;
5686
5687 /* Check filter direction. */
5688 if (strncmp(direct_str, "in", 2) == 0)
5689 direct = RMAP_IN;
5690 else if (strncmp(direct_str, "o", 1) == 0)
5691 direct = RMAP_OUT;
5692
5693 route_map = route_map_lookup_warn_noexist(vty, name_str);
5694 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5695
5696 return bgp_vty_return(vty, ret);
5697 }
5698
5699 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5700 afi_t afi, safi_t safi,
5701 const char *direct_str)
5702 {
5703 int ret;
5704 struct peer *peer;
5705 int direct = RMAP_IN;
5706
5707 peer = peer_and_group_lookup_vty(vty, ip_str);
5708 if (!peer)
5709 return CMD_WARNING_CONFIG_FAILED;
5710
5711 /* Check filter direction. */
5712 if (strncmp(direct_str, "in", 2) == 0)
5713 direct = RMAP_IN;
5714 else if (strncmp(direct_str, "o", 1) == 0)
5715 direct = RMAP_OUT;
5716
5717 ret = peer_route_map_unset(peer, afi, safi, direct);
5718
5719 return bgp_vty_return(vty, ret);
5720 }
5721
5722 DEFUN (neighbor_route_map,
5723 neighbor_route_map_cmd,
5724 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5725 NEIGHBOR_STR
5726 NEIGHBOR_ADDR_STR2
5727 "Apply route map to neighbor\n"
5728 "Name of route map\n"
5729 "Apply map to incoming routes\n"
5730 "Apply map to outbound routes\n")
5731 {
5732 int idx_peer = 1;
5733 int idx_word = 3;
5734 int idx_in_out = 4;
5735 return peer_route_map_set_vty(
5736 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5737 argv[idx_word]->arg, argv[idx_in_out]->arg);
5738 }
5739
5740 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5741 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5742 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5743 "Apply route map to neighbor\n"
5744 "Name of route map\n"
5745 "Apply map to incoming routes\n"
5746 "Apply map to outbound routes\n")
5747
5748 DEFUN (no_neighbor_route_map,
5749 no_neighbor_route_map_cmd,
5750 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5751 NO_STR
5752 NEIGHBOR_STR
5753 NEIGHBOR_ADDR_STR2
5754 "Apply route map to neighbor\n"
5755 "Name of route map\n"
5756 "Apply map to incoming routes\n"
5757 "Apply map to outbound routes\n")
5758 {
5759 int idx_peer = 2;
5760 int idx_in_out = 5;
5761 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5762 bgp_node_afi(vty), bgp_node_safi(vty),
5763 argv[idx_in_out]->arg);
5764 }
5765
5766 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5767 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5768 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5769 "Apply route map to neighbor\n"
5770 "Name of route map\n"
5771 "Apply map to incoming routes\n"
5772 "Apply map to outbound routes\n")
5773
5774 /* Set unsuppress-map to the peer. */
5775 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5776 afi_t afi, safi_t safi,
5777 const char *name_str)
5778 {
5779 int ret;
5780 struct peer *peer;
5781 struct route_map *route_map;
5782
5783 peer = peer_and_group_lookup_vty(vty, ip_str);
5784 if (!peer)
5785 return CMD_WARNING_CONFIG_FAILED;
5786
5787 route_map = route_map_lookup_warn_noexist(vty, name_str);
5788 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5789
5790 return bgp_vty_return(vty, ret);
5791 }
5792
5793 /* Unset route-map from the peer. */
5794 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5795 afi_t afi, safi_t safi)
5796 {
5797 int ret;
5798 struct peer *peer;
5799
5800 peer = peer_and_group_lookup_vty(vty, ip_str);
5801 if (!peer)
5802 return CMD_WARNING_CONFIG_FAILED;
5803
5804 ret = peer_unsuppress_map_unset(peer, afi, safi);
5805
5806 return bgp_vty_return(vty, ret);
5807 }
5808
5809 DEFUN (neighbor_unsuppress_map,
5810 neighbor_unsuppress_map_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5812 NEIGHBOR_STR
5813 NEIGHBOR_ADDR_STR2
5814 "Route-map to selectively unsuppress suppressed routes\n"
5815 "Name of route map\n")
5816 {
5817 int idx_peer = 1;
5818 int idx_word = 3;
5819 return peer_unsuppress_map_set_vty(
5820 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5821 argv[idx_word]->arg);
5822 }
5823
5824 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5825 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5827 "Route-map to selectively unsuppress suppressed routes\n"
5828 "Name of route map\n")
5829
5830 DEFUN (no_neighbor_unsuppress_map,
5831 no_neighbor_unsuppress_map_cmd,
5832 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5833 NO_STR
5834 NEIGHBOR_STR
5835 NEIGHBOR_ADDR_STR2
5836 "Route-map to selectively unsuppress suppressed routes\n"
5837 "Name of route map\n")
5838 {
5839 int idx_peer = 2;
5840 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5841 bgp_node_afi(vty),
5842 bgp_node_safi(vty));
5843 }
5844
5845 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5846 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Route-map to selectively unsuppress suppressed routes\n"
5849 "Name of route map\n")
5850
5851 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5852 afi_t afi, safi_t safi,
5853 const char *num_str,
5854 const char *threshold_str, int warning,
5855 const char *restart_str)
5856 {
5857 int ret;
5858 struct peer *peer;
5859 uint32_t max;
5860 uint8_t threshold;
5861 uint16_t restart;
5862
5863 peer = peer_and_group_lookup_vty(vty, ip_str);
5864 if (!peer)
5865 return CMD_WARNING_CONFIG_FAILED;
5866
5867 max = strtoul(num_str, NULL, 10);
5868 if (threshold_str)
5869 threshold = atoi(threshold_str);
5870 else
5871 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5872
5873 if (restart_str)
5874 restart = atoi(restart_str);
5875 else
5876 restart = 0;
5877
5878 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5879 restart);
5880
5881 return bgp_vty_return(vty, ret);
5882 }
5883
5884 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5885 afi_t afi, safi_t safi)
5886 {
5887 int ret;
5888 struct peer *peer;
5889
5890 peer = peer_and_group_lookup_vty(vty, ip_str);
5891 if (!peer)
5892 return CMD_WARNING_CONFIG_FAILED;
5893
5894 ret = peer_maximum_prefix_unset(peer, afi, safi);
5895
5896 return bgp_vty_return(vty, ret);
5897 }
5898
5899 /* Maximum number of prefix configuration. prefix count is different
5900 for each peer configuration. So this configuration can be set for
5901 each peer configuration. */
5902 DEFUN (neighbor_maximum_prefix,
5903 neighbor_maximum_prefix_cmd,
5904 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5905 NEIGHBOR_STR
5906 NEIGHBOR_ADDR_STR2
5907 "Maximum number of prefix accept from this peer\n"
5908 "maximum no. of prefix limit\n")
5909 {
5910 int idx_peer = 1;
5911 int idx_number = 3;
5912 return peer_maximum_prefix_set_vty(
5913 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5914 argv[idx_number]->arg, NULL, 0, NULL);
5915 }
5916
5917 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5918 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5920 "Maximum number of prefix accept from this peer\n"
5921 "maximum no. of prefix limit\n")
5922
5923 DEFUN (neighbor_maximum_prefix_threshold,
5924 neighbor_maximum_prefix_threshold_cmd,
5925 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5926 NEIGHBOR_STR
5927 NEIGHBOR_ADDR_STR2
5928 "Maximum number of prefix accept from this peer\n"
5929 "maximum no. of prefix limit\n"
5930 "Threshold value (%) at which to generate a warning msg\n")
5931 {
5932 int idx_peer = 1;
5933 int idx_number = 3;
5934 int idx_number_2 = 4;
5935 return peer_maximum_prefix_set_vty(
5936 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5937 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5938 }
5939
5940 ALIAS_HIDDEN(
5941 neighbor_maximum_prefix_threshold,
5942 neighbor_maximum_prefix_threshold_hidden_cmd,
5943 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5944 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5945 "Maximum number of prefix accept from this peer\n"
5946 "maximum no. of prefix limit\n"
5947 "Threshold value (%) at which to generate a warning msg\n")
5948
5949 DEFUN (neighbor_maximum_prefix_warning,
5950 neighbor_maximum_prefix_warning_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Maximum number of prefix accept from this peer\n"
5955 "maximum no. of prefix limit\n"
5956 "Only give warning message when limit is exceeded\n")
5957 {
5958 int idx_peer = 1;
5959 int idx_number = 3;
5960 return peer_maximum_prefix_set_vty(
5961 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5962 argv[idx_number]->arg, NULL, 1, NULL);
5963 }
5964
5965 ALIAS_HIDDEN(
5966 neighbor_maximum_prefix_warning,
5967 neighbor_maximum_prefix_warning_hidden_cmd,
5968 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5969 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5970 "Maximum number of prefix accept from this peer\n"
5971 "maximum no. of prefix limit\n"
5972 "Only give warning message when limit is exceeded\n")
5973
5974 DEFUN (neighbor_maximum_prefix_threshold_warning,
5975 neighbor_maximum_prefix_threshold_warning_cmd,
5976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Maximum number of prefix accept from this peer\n"
5980 "maximum no. of prefix limit\n"
5981 "Threshold value (%) at which to generate a warning msg\n"
5982 "Only give warning message when limit is exceeded\n")
5983 {
5984 int idx_peer = 1;
5985 int idx_number = 3;
5986 int idx_number_2 = 4;
5987 return peer_maximum_prefix_set_vty(
5988 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5989 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5990 }
5991
5992 ALIAS_HIDDEN(
5993 neighbor_maximum_prefix_threshold_warning,
5994 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5995 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5996 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5997 "Maximum number of prefix accept from this peer\n"
5998 "maximum no. of prefix limit\n"
5999 "Threshold value (%) at which to generate a warning msg\n"
6000 "Only give warning message when limit is exceeded\n")
6001
6002 DEFUN (neighbor_maximum_prefix_restart,
6003 neighbor_maximum_prefix_restart_cmd,
6004 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6005 NEIGHBOR_STR
6006 NEIGHBOR_ADDR_STR2
6007 "Maximum number of prefix accept from this peer\n"
6008 "maximum no. of prefix limit\n"
6009 "Restart bgp connection after limit is exceeded\n"
6010 "Restart interval in minutes\n")
6011 {
6012 int idx_peer = 1;
6013 int idx_number = 3;
6014 int idx_number_2 = 5;
6015 return peer_maximum_prefix_set_vty(
6016 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6017 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6018 }
6019
6020 ALIAS_HIDDEN(
6021 neighbor_maximum_prefix_restart,
6022 neighbor_maximum_prefix_restart_hidden_cmd,
6023 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6024 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6025 "Maximum number of prefix accept from this peer\n"
6026 "maximum no. of prefix limit\n"
6027 "Restart bgp connection after limit is exceeded\n"
6028 "Restart interval in minutes\n")
6029
6030 DEFUN (neighbor_maximum_prefix_threshold_restart,
6031 neighbor_maximum_prefix_threshold_restart_cmd,
6032 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "Maximum number of prefixes to accept from this peer\n"
6036 "maximum no. of prefix limit\n"
6037 "Threshold value (%) at which to generate a warning msg\n"
6038 "Restart bgp connection after limit is exceeded\n"
6039 "Restart interval in minutes\n")
6040 {
6041 int idx_peer = 1;
6042 int idx_number = 3;
6043 int idx_number_2 = 4;
6044 int idx_number_3 = 6;
6045 return peer_maximum_prefix_set_vty(
6046 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6047 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6048 argv[idx_number_3]->arg);
6049 }
6050
6051 ALIAS_HIDDEN(
6052 neighbor_maximum_prefix_threshold_restart,
6053 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6054 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6055 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6056 "Maximum number of prefixes to accept from this peer\n"
6057 "maximum no. of prefix limit\n"
6058 "Threshold value (%) at which to generate a warning msg\n"
6059 "Restart bgp connection after limit is exceeded\n"
6060 "Restart interval in minutes\n")
6061
6062 DEFUN (no_neighbor_maximum_prefix,
6063 no_neighbor_maximum_prefix_cmd,
6064 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6065 NO_STR
6066 NEIGHBOR_STR
6067 NEIGHBOR_ADDR_STR2
6068 "Maximum number of prefixes to accept from this peer\n"
6069 "maximum no. of prefix limit\n"
6070 "Threshold value (%) at which to generate a warning msg\n"
6071 "Restart bgp connection after limit is exceeded\n"
6072 "Restart interval in minutes\n"
6073 "Only give warning message when limit is exceeded\n")
6074 {
6075 int idx_peer = 2;
6076 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6077 bgp_node_afi(vty),
6078 bgp_node_safi(vty));
6079 }
6080
6081 ALIAS_HIDDEN(
6082 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6083 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6084 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6085 "Maximum number of prefixes to accept from this peer\n"
6086 "maximum no. of prefix limit\n"
6087 "Threshold value (%) at which to generate a warning msg\n"
6088 "Restart bgp connection after limit is exceeded\n"
6089 "Restart interval in minutes\n"
6090 "Only give warning message when limit is exceeded\n")
6091
6092
6093 /* "neighbor allowas-in" */
6094 DEFUN (neighbor_allowas_in,
6095 neighbor_allowas_in_cmd,
6096 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6097 NEIGHBOR_STR
6098 NEIGHBOR_ADDR_STR2
6099 "Accept as-path with my AS present in it\n"
6100 "Number of occurences of AS number\n"
6101 "Only accept my AS in the as-path if the route was originated in my AS\n")
6102 {
6103 int idx_peer = 1;
6104 int idx_number_origin = 3;
6105 int ret;
6106 int origin = 0;
6107 struct peer *peer;
6108 int allow_num = 0;
6109
6110 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6111 if (!peer)
6112 return CMD_WARNING_CONFIG_FAILED;
6113
6114 if (argc <= idx_number_origin)
6115 allow_num = 3;
6116 else {
6117 if (argv[idx_number_origin]->type == WORD_TKN)
6118 origin = 1;
6119 else
6120 allow_num = atoi(argv[idx_number_origin]->arg);
6121 }
6122
6123 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6124 allow_num, origin);
6125
6126 return bgp_vty_return(vty, ret);
6127 }
6128
6129 ALIAS_HIDDEN(
6130 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6131 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6132 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6133 "Accept as-path with my AS present in it\n"
6134 "Number of occurences of AS number\n"
6135 "Only accept my AS in the as-path if the route was originated in my AS\n")
6136
6137 DEFUN (no_neighbor_allowas_in,
6138 no_neighbor_allowas_in_cmd,
6139 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6140 NO_STR
6141 NEIGHBOR_STR
6142 NEIGHBOR_ADDR_STR2
6143 "allow local ASN appears in aspath attribute\n"
6144 "Number of occurences of AS number\n"
6145 "Only accept my AS in the as-path if the route was originated in my AS\n")
6146 {
6147 int idx_peer = 2;
6148 int ret;
6149 struct peer *peer;
6150
6151 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6152 if (!peer)
6153 return CMD_WARNING_CONFIG_FAILED;
6154
6155 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6156 bgp_node_safi(vty));
6157
6158 return bgp_vty_return(vty, ret);
6159 }
6160
6161 ALIAS_HIDDEN(
6162 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6163 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6164 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6165 "allow local ASN appears in aspath attribute\n"
6166 "Number of occurences of AS number\n"
6167 "Only accept my AS in the as-path if the route was originated in my AS\n")
6168
6169 DEFUN (neighbor_ttl_security,
6170 neighbor_ttl_security_cmd,
6171 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6172 NEIGHBOR_STR
6173 NEIGHBOR_ADDR_STR2
6174 "BGP ttl-security parameters\n"
6175 "Specify the maximum number of hops to the BGP peer\n"
6176 "Number of hops to BGP peer\n")
6177 {
6178 int idx_peer = 1;
6179 int idx_number = 4;
6180 struct peer *peer;
6181 int gtsm_hops;
6182
6183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6184 if (!peer)
6185 return CMD_WARNING_CONFIG_FAILED;
6186
6187 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6188
6189 /*
6190 * If 'neighbor swpX', then this is for directly connected peers,
6191 * we should not accept a ttl-security hops value greater than 1.
6192 */
6193 if (peer->conf_if && (gtsm_hops > 1)) {
6194 vty_out(vty,
6195 "%s is directly connected peer, hops cannot exceed 1\n",
6196 argv[idx_peer]->arg);
6197 return CMD_WARNING_CONFIG_FAILED;
6198 }
6199
6200 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6201 }
6202
6203 DEFUN (no_neighbor_ttl_security,
6204 no_neighbor_ttl_security_cmd,
6205 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6206 NO_STR
6207 NEIGHBOR_STR
6208 NEIGHBOR_ADDR_STR2
6209 "BGP ttl-security parameters\n"
6210 "Specify the maximum number of hops to the BGP peer\n"
6211 "Number of hops to BGP peer\n")
6212 {
6213 int idx_peer = 2;
6214 struct peer *peer;
6215
6216 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6217 if (!peer)
6218 return CMD_WARNING_CONFIG_FAILED;
6219
6220 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6221 }
6222
6223 DEFUN (neighbor_addpath_tx_all_paths,
6224 neighbor_addpath_tx_all_paths_cmd,
6225 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6226 NEIGHBOR_STR
6227 NEIGHBOR_ADDR_STR2
6228 "Use addpath to advertise all paths to a neighbor\n")
6229 {
6230 int idx_peer = 1;
6231 struct peer *peer;
6232
6233 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6234 if (!peer)
6235 return CMD_WARNING_CONFIG_FAILED;
6236
6237 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6238 BGP_ADDPATH_ALL);
6239 return CMD_SUCCESS;
6240 }
6241
6242 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6243 neighbor_addpath_tx_all_paths_hidden_cmd,
6244 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6246 "Use addpath to advertise all paths to a neighbor\n")
6247
6248 DEFUN (no_neighbor_addpath_tx_all_paths,
6249 no_neighbor_addpath_tx_all_paths_cmd,
6250 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6251 NO_STR
6252 NEIGHBOR_STR
6253 NEIGHBOR_ADDR_STR2
6254 "Use addpath to advertise all paths to a neighbor\n")
6255 {
6256 int idx_peer = 2;
6257 struct peer *peer;
6258
6259 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6260 if (!peer)
6261 return CMD_WARNING_CONFIG_FAILED;
6262
6263 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6264 != BGP_ADDPATH_ALL) {
6265 vty_out(vty,
6266 "%% Peer not currently configured to transmit all paths.");
6267 return CMD_WARNING_CONFIG_FAILED;
6268 }
6269
6270 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6271 BGP_ADDPATH_NONE);
6272
6273 return CMD_SUCCESS;
6274 }
6275
6276 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6277 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6278 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6279 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6280 "Use addpath to advertise all paths to a neighbor\n")
6281
6282 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6283 neighbor_addpath_tx_bestpath_per_as_cmd,
6284 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6285 NEIGHBOR_STR
6286 NEIGHBOR_ADDR_STR2
6287 "Use addpath to advertise the bestpath per each neighboring AS\n")
6288 {
6289 int idx_peer = 1;
6290 struct peer *peer;
6291
6292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6293 if (!peer)
6294 return CMD_WARNING_CONFIG_FAILED;
6295
6296 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6297 BGP_ADDPATH_BEST_PER_AS);
6298
6299 return CMD_SUCCESS;
6300 }
6301
6302 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6303 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6304 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6305 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6306 "Use addpath to advertise the bestpath per each neighboring AS\n")
6307
6308 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6309 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6310 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6311 NO_STR
6312 NEIGHBOR_STR
6313 NEIGHBOR_ADDR_STR2
6314 "Use addpath to advertise the bestpath per each neighboring AS\n")
6315 {
6316 int idx_peer = 2;
6317 struct peer *peer;
6318
6319 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6320 if (!peer)
6321 return CMD_WARNING_CONFIG_FAILED;
6322
6323 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6324 != BGP_ADDPATH_BEST_PER_AS) {
6325 vty_out(vty,
6326 "%% Peer not currently configured to transmit all best path per as.");
6327 return CMD_WARNING_CONFIG_FAILED;
6328 }
6329
6330 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6331 BGP_ADDPATH_NONE);
6332
6333 return CMD_SUCCESS;
6334 }
6335
6336 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6337 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6338 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6339 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6340 "Use addpath to advertise the bestpath per each neighboring AS\n")
6341
6342 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6343 struct ecommunity **list)
6344 {
6345 struct ecommunity *ecom = NULL;
6346 struct ecommunity *ecomadd;
6347
6348 for (; argc; --argc, ++argv) {
6349
6350 ecomadd = ecommunity_str2com(argv[0]->arg,
6351 ECOMMUNITY_ROUTE_TARGET, 0);
6352 if (!ecomadd) {
6353 vty_out(vty, "Malformed community-list value\n");
6354 if (ecom)
6355 ecommunity_free(&ecom);
6356 return CMD_WARNING_CONFIG_FAILED;
6357 }
6358
6359 if (ecom) {
6360 ecommunity_merge(ecom, ecomadd);
6361 ecommunity_free(&ecomadd);
6362 } else {
6363 ecom = ecomadd;
6364 }
6365 }
6366
6367 if (*list) {
6368 ecommunity_free(&*list);
6369 }
6370 *list = ecom;
6371
6372 return CMD_SUCCESS;
6373 }
6374
6375 /*
6376 * v2vimport is true if we are handling a `import vrf ...` command
6377 */
6378 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6379 {
6380 afi_t afi;
6381
6382 switch (vty->node) {
6383 case BGP_IPV4_NODE:
6384 afi = AFI_IP;
6385 break;
6386 case BGP_IPV6_NODE:
6387 afi = AFI_IP6;
6388 break;
6389 default:
6390 vty_out(vty,
6391 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6392 return AFI_MAX;
6393 }
6394
6395 if (!v2vimport) {
6396 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6397 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6398 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6399 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6400 vty_out(vty,
6401 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6402 return AFI_MAX;
6403 }
6404 } else {
6405 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6406 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6407 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6408 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6409 vty_out(vty,
6410 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6411 return AFI_MAX;
6412 }
6413 }
6414 return afi;
6415 }
6416
6417 DEFPY (af_rd_vpn_export,
6418 af_rd_vpn_export_cmd,
6419 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6420 NO_STR
6421 "Specify route distinguisher\n"
6422 "Between current address-family and vpn\n"
6423 "For routes leaked from current address-family to vpn\n"
6424 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6425 {
6426 VTY_DECLVAR_CONTEXT(bgp, bgp);
6427 struct prefix_rd prd;
6428 int ret;
6429 afi_t afi;
6430 int idx = 0;
6431 int yes = 1;
6432
6433 if (argv_find(argv, argc, "no", &idx))
6434 yes = 0;
6435
6436 if (yes) {
6437 ret = str2prefix_rd(rd_str, &prd);
6438 if (!ret) {
6439 vty_out(vty, "%% Malformed rd\n");
6440 return CMD_WARNING_CONFIG_FAILED;
6441 }
6442 }
6443
6444 afi = vpn_policy_getafi(vty, bgp, false);
6445 if (afi == AFI_MAX)
6446 return CMD_WARNING_CONFIG_FAILED;
6447
6448 /*
6449 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6450 */
6451 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6452 bgp_get_default(), bgp);
6453
6454 if (yes) {
6455 bgp->vpn_policy[afi].tovpn_rd = prd;
6456 SET_FLAG(bgp->vpn_policy[afi].flags,
6457 BGP_VPN_POLICY_TOVPN_RD_SET);
6458 } else {
6459 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6460 BGP_VPN_POLICY_TOVPN_RD_SET);
6461 }
6462
6463 /* post-change: re-export vpn routes */
6464 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6465 bgp_get_default(), bgp);
6466
6467 return CMD_SUCCESS;
6468 }
6469
6470 ALIAS (af_rd_vpn_export,
6471 af_no_rd_vpn_export_cmd,
6472 "no rd vpn export",
6473 NO_STR
6474 "Specify route distinguisher\n"
6475 "Between current address-family and vpn\n"
6476 "For routes leaked from current address-family to vpn\n")
6477
6478 DEFPY (af_label_vpn_export,
6479 af_label_vpn_export_cmd,
6480 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6481 NO_STR
6482 "label value for VRF\n"
6483 "Between current address-family and vpn\n"
6484 "For routes leaked from current address-family to vpn\n"
6485 "Label Value <0-1048575>\n"
6486 "Automatically assign a label\n")
6487 {
6488 VTY_DECLVAR_CONTEXT(bgp, bgp);
6489 mpls_label_t label = MPLS_LABEL_NONE;
6490 afi_t afi;
6491 int idx = 0;
6492 int yes = 1;
6493
6494 if (argv_find(argv, argc, "no", &idx))
6495 yes = 0;
6496
6497 /* If "no ...", squash trailing parameter */
6498 if (!yes)
6499 label_auto = NULL;
6500
6501 if (yes) {
6502 if (!label_auto)
6503 label = label_val; /* parser should force unsigned */
6504 }
6505
6506 afi = vpn_policy_getafi(vty, bgp, false);
6507 if (afi == AFI_MAX)
6508 return CMD_WARNING_CONFIG_FAILED;
6509
6510
6511 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6512 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6513 /* no change */
6514 return CMD_SUCCESS;
6515
6516 /*
6517 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6518 */
6519 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6520 bgp_get_default(), bgp);
6521
6522 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6523 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6524
6525 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6526
6527 /*
6528 * label has previously been automatically
6529 * assigned by labelpool: release it
6530 *
6531 * NB if tovpn_label == MPLS_LABEL_NONE it
6532 * means the automatic assignment is in flight
6533 * and therefore the labelpool callback must
6534 * detect that the auto label is not needed.
6535 */
6536
6537 bgp_lp_release(LP_TYPE_VRF,
6538 &bgp->vpn_policy[afi],
6539 bgp->vpn_policy[afi].tovpn_label);
6540 }
6541 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6542 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6543 }
6544
6545 bgp->vpn_policy[afi].tovpn_label = label;
6546 if (label_auto) {
6547 SET_FLAG(bgp->vpn_policy[afi].flags,
6548 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6549 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6550 vpn_leak_label_callback);
6551 }
6552
6553 /* post-change: re-export vpn routes */
6554 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6555 bgp_get_default(), bgp);
6556
6557 return CMD_SUCCESS;
6558 }
6559
6560 ALIAS (af_label_vpn_export,
6561 af_no_label_vpn_export_cmd,
6562 "no label vpn export",
6563 NO_STR
6564 "label value for VRF\n"
6565 "Between current address-family and vpn\n"
6566 "For routes leaked from current address-family to vpn\n")
6567
6568 DEFPY (af_nexthop_vpn_export,
6569 af_nexthop_vpn_export_cmd,
6570 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6571 NO_STR
6572 "Specify next hop to use for VRF advertised prefixes\n"
6573 "Between current address-family and vpn\n"
6574 "For routes leaked from current address-family to vpn\n"
6575 "IPv4 prefix\n"
6576 "IPv6 prefix\n")
6577 {
6578 VTY_DECLVAR_CONTEXT(bgp, bgp);
6579 afi_t afi;
6580 struct prefix p;
6581 int idx = 0;
6582 int yes = 1;
6583
6584 if (argv_find(argv, argc, "no", &idx))
6585 yes = 0;
6586
6587 if (yes) {
6588 if (!sockunion2hostprefix(nexthop_str, &p))
6589 return CMD_WARNING_CONFIG_FAILED;
6590 }
6591
6592 afi = vpn_policy_getafi(vty, bgp, false);
6593 if (afi == AFI_MAX)
6594 return CMD_WARNING_CONFIG_FAILED;
6595
6596 /*
6597 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6598 */
6599 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6600 bgp_get_default(), bgp);
6601
6602 if (yes) {
6603 bgp->vpn_policy[afi].tovpn_nexthop = p;
6604 SET_FLAG(bgp->vpn_policy[afi].flags,
6605 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6606 } else {
6607 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6608 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6609 }
6610
6611 /* post-change: re-export vpn routes */
6612 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6613 bgp_get_default(), bgp);
6614
6615 return CMD_SUCCESS;
6616 }
6617
6618 ALIAS (af_nexthop_vpn_export,
6619 af_no_nexthop_vpn_export_cmd,
6620 "no nexthop vpn export",
6621 NO_STR
6622 "Specify next hop to use for VRF advertised prefixes\n"
6623 "Between current address-family and vpn\n"
6624 "For routes leaked from current address-family to vpn\n")
6625
6626 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6627 {
6628 if (!strcmp(dstr, "import")) {
6629 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6630 } else if (!strcmp(dstr, "export")) {
6631 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6632 } else if (!strcmp(dstr, "both")) {
6633 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6634 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6635 } else {
6636 vty_out(vty, "%% direction parse error\n");
6637 return CMD_WARNING_CONFIG_FAILED;
6638 }
6639 return CMD_SUCCESS;
6640 }
6641
6642 DEFPY (af_rt_vpn_imexport,
6643 af_rt_vpn_imexport_cmd,
6644 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6645 NO_STR
6646 "Specify route target list\n"
6647 "Specify route target list\n"
6648 "Between current address-family and vpn\n"
6649 "For routes leaked from vpn to current address-family: match any\n"
6650 "For routes leaked from current address-family to vpn: set\n"
6651 "both import: match any and export: set\n"
6652 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6653 {
6654 VTY_DECLVAR_CONTEXT(bgp, bgp);
6655 int ret;
6656 struct ecommunity *ecom = NULL;
6657 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6658 vpn_policy_direction_t dir;
6659 afi_t afi;
6660 int idx = 0;
6661 int yes = 1;
6662
6663 if (argv_find(argv, argc, "no", &idx))
6664 yes = 0;
6665
6666 afi = vpn_policy_getafi(vty, bgp, false);
6667 if (afi == AFI_MAX)
6668 return CMD_WARNING_CONFIG_FAILED;
6669
6670 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6671 if (ret != CMD_SUCCESS)
6672 return ret;
6673
6674 if (yes) {
6675 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6676 vty_out(vty, "%% Missing RTLIST\n");
6677 return CMD_WARNING_CONFIG_FAILED;
6678 }
6679 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6680 if (ret != CMD_SUCCESS) {
6681 return ret;
6682 }
6683 }
6684
6685 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6686 if (!dodir[dir])
6687 continue;
6688
6689 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6690
6691 if (yes) {
6692 if (bgp->vpn_policy[afi].rtlist[dir])
6693 ecommunity_free(
6694 &bgp->vpn_policy[afi].rtlist[dir]);
6695 bgp->vpn_policy[afi].rtlist[dir] =
6696 ecommunity_dup(ecom);
6697 } else {
6698 if (bgp->vpn_policy[afi].rtlist[dir])
6699 ecommunity_free(
6700 &bgp->vpn_policy[afi].rtlist[dir]);
6701 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6702 }
6703
6704 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6705 }
6706
6707 if (ecom)
6708 ecommunity_free(&ecom);
6709
6710 return CMD_SUCCESS;
6711 }
6712
6713 ALIAS (af_rt_vpn_imexport,
6714 af_no_rt_vpn_imexport_cmd,
6715 "no <rt|route-target> vpn <import|export|both>$direction_str",
6716 NO_STR
6717 "Specify route target list\n"
6718 "Specify route target list\n"
6719 "Between current address-family and vpn\n"
6720 "For routes leaked from vpn to current address-family\n"
6721 "For routes leaked from current address-family to vpn\n"
6722 "both import and export\n")
6723
6724 DEFPY (af_route_map_vpn_imexport,
6725 af_route_map_vpn_imexport_cmd,
6726 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6727 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6728 NO_STR
6729 "Specify route map\n"
6730 "Between current address-family and vpn\n"
6731 "For routes leaked from vpn to current address-family\n"
6732 "For routes leaked from current address-family to vpn\n"
6733 "name of route-map\n")
6734 {
6735 VTY_DECLVAR_CONTEXT(bgp, bgp);
6736 int ret;
6737 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6738 vpn_policy_direction_t dir;
6739 afi_t afi;
6740 int idx = 0;
6741 int yes = 1;
6742
6743 if (argv_find(argv, argc, "no", &idx))
6744 yes = 0;
6745
6746 afi = vpn_policy_getafi(vty, bgp, false);
6747 if (afi == AFI_MAX)
6748 return CMD_WARNING_CONFIG_FAILED;
6749
6750 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6751 if (ret != CMD_SUCCESS)
6752 return ret;
6753
6754 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6755 if (!dodir[dir])
6756 continue;
6757
6758 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6759
6760 if (yes) {
6761 if (bgp->vpn_policy[afi].rmap_name[dir])
6762 XFREE(MTYPE_ROUTE_MAP_NAME,
6763 bgp->vpn_policy[afi].rmap_name[dir]);
6764 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6765 MTYPE_ROUTE_MAP_NAME, rmap_str);
6766 bgp->vpn_policy[afi].rmap[dir] =
6767 route_map_lookup_warn_noexist(vty, rmap_str);
6768 if (!bgp->vpn_policy[afi].rmap[dir])
6769 return CMD_SUCCESS;
6770 } else {
6771 if (bgp->vpn_policy[afi].rmap_name[dir])
6772 XFREE(MTYPE_ROUTE_MAP_NAME,
6773 bgp->vpn_policy[afi].rmap_name[dir]);
6774 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6775 bgp->vpn_policy[afi].rmap[dir] = NULL;
6776 }
6777
6778 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6779 }
6780
6781 return CMD_SUCCESS;
6782 }
6783
6784 ALIAS (af_route_map_vpn_imexport,
6785 af_no_route_map_vpn_imexport_cmd,
6786 "no route-map vpn <import|export>$direction_str",
6787 NO_STR
6788 "Specify route map\n"
6789 "Between current address-family and vpn\n"
6790 "For routes leaked from vpn to current address-family\n"
6791 "For routes leaked from current address-family to vpn\n")
6792
6793 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6794 "[no] import vrf route-map RMAP$rmap_str",
6795 NO_STR
6796 "Import routes from another VRF\n"
6797 "Vrf routes being filtered\n"
6798 "Specify route map\n"
6799 "name of route-map\n")
6800 {
6801 VTY_DECLVAR_CONTEXT(bgp, bgp);
6802 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6803 afi_t afi;
6804 int idx = 0;
6805 int yes = 1;
6806 struct bgp *bgp_default;
6807
6808 if (argv_find(argv, argc, "no", &idx))
6809 yes = 0;
6810
6811 afi = vpn_policy_getafi(vty, bgp, true);
6812 if (afi == AFI_MAX)
6813 return CMD_WARNING_CONFIG_FAILED;
6814
6815 bgp_default = bgp_get_default();
6816 if (!bgp_default) {
6817 int32_t ret;
6818 as_t as = bgp->as;
6819
6820 /* Auto-create assuming the same AS */
6821 ret = bgp_get(&bgp_default, &as, NULL,
6822 BGP_INSTANCE_TYPE_DEFAULT);
6823
6824 if (ret) {
6825 vty_out(vty,
6826 "VRF default is not configured as a bgp instance\n");
6827 return CMD_WARNING;
6828 }
6829 }
6830
6831 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6832
6833 if (yes) {
6834 if (bgp->vpn_policy[afi].rmap_name[dir])
6835 XFREE(MTYPE_ROUTE_MAP_NAME,
6836 bgp->vpn_policy[afi].rmap_name[dir]);
6837 bgp->vpn_policy[afi].rmap_name[dir] =
6838 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6839 bgp->vpn_policy[afi].rmap[dir] =
6840 route_map_lookup_warn_noexist(vty, rmap_str);
6841 if (!bgp->vpn_policy[afi].rmap[dir])
6842 return CMD_SUCCESS;
6843 } else {
6844 if (bgp->vpn_policy[afi].rmap_name[dir])
6845 XFREE(MTYPE_ROUTE_MAP_NAME,
6846 bgp->vpn_policy[afi].rmap_name[dir]);
6847 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6848 bgp->vpn_policy[afi].rmap[dir] = NULL;
6849 }
6850
6851 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6852
6853 return CMD_SUCCESS;
6854 }
6855
6856 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6857 "no import vrf route-map",
6858 NO_STR
6859 "Import routes from another VRF\n"
6860 "Vrf routes being filtered\n"
6861 "Specify route map\n")
6862
6863 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6864 "[no] import vrf VIEWVRFNAME$import_name",
6865 NO_STR
6866 "Import routes from another VRF\n"
6867 "VRF to import from\n"
6868 "The name of the VRF\n")
6869 {
6870 VTY_DECLVAR_CONTEXT(bgp, bgp);
6871 struct listnode *node;
6872 struct bgp *vrf_bgp, *bgp_default;
6873 int32_t ret = 0;
6874 as_t as = bgp->as;
6875 bool remove = false;
6876 int32_t idx = 0;
6877 char *vname;
6878 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6879 safi_t safi;
6880 afi_t afi;
6881
6882 if (import_name == NULL) {
6883 vty_out(vty, "%% Missing import name\n");
6884 return CMD_WARNING;
6885 }
6886
6887 if (argv_find(argv, argc, "no", &idx))
6888 remove = true;
6889
6890 afi = vpn_policy_getafi(vty, bgp, true);
6891 if (afi == AFI_MAX)
6892 return CMD_WARNING_CONFIG_FAILED;
6893
6894 safi = bgp_node_safi(vty);
6895
6896 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6897 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6898 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6899 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6900 remove ? "unimport" : "import", import_name);
6901 return CMD_WARNING;
6902 }
6903
6904 bgp_default = bgp_get_default();
6905 if (!bgp_default) {
6906 /* Auto-create assuming the same AS */
6907 ret = bgp_get(&bgp_default, &as, NULL,
6908 BGP_INSTANCE_TYPE_DEFAULT);
6909
6910 if (ret) {
6911 vty_out(vty,
6912 "VRF default is not configured as a bgp instance\n");
6913 return CMD_WARNING;
6914 }
6915 }
6916
6917 vrf_bgp = bgp_lookup_by_name(import_name);
6918 if (!vrf_bgp) {
6919 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6920 vrf_bgp = bgp_default;
6921 else
6922 /* Auto-create assuming the same AS */
6923 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6924
6925 if (ret) {
6926 vty_out(vty,
6927 "VRF %s is not configured as a bgp instance\n",
6928 import_name);
6929 return CMD_WARNING;
6930 }
6931 }
6932
6933 if (remove) {
6934 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6935 } else {
6936 /* Already importing from "import_vrf"? */
6937 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6938 vname)) {
6939 if (strcmp(vname, import_name) == 0)
6940 return CMD_WARNING;
6941 }
6942
6943 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6944 }
6945
6946 return CMD_SUCCESS;
6947 }
6948
6949 /* This command is valid only in a bgp vrf instance or the default instance */
6950 DEFPY (bgp_imexport_vpn,
6951 bgp_imexport_vpn_cmd,
6952 "[no] <import|export>$direction_str vpn",
6953 NO_STR
6954 "Import routes to this address-family\n"
6955 "Export routes from this address-family\n"
6956 "to/from default instance VPN RIB\n")
6957 {
6958 VTY_DECLVAR_CONTEXT(bgp, bgp);
6959 int previous_state;
6960 afi_t afi;
6961 safi_t safi;
6962 int idx = 0;
6963 int yes = 1;
6964 int flag;
6965 vpn_policy_direction_t dir;
6966
6967 if (argv_find(argv, argc, "no", &idx))
6968 yes = 0;
6969
6970 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6971 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6972
6973 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6974 return CMD_WARNING_CONFIG_FAILED;
6975 }
6976
6977 afi = bgp_node_afi(vty);
6978 safi = bgp_node_safi(vty);
6979 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6980 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6981 return CMD_WARNING_CONFIG_FAILED;
6982 }
6983
6984 if (!strcmp(direction_str, "import")) {
6985 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6986 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6987 } else if (!strcmp(direction_str, "export")) {
6988 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6989 dir = BGP_VPN_POLICY_DIR_TOVPN;
6990 } else {
6991 vty_out(vty, "%% unknown direction %s\n", direction_str);
6992 return CMD_WARNING_CONFIG_FAILED;
6993 }
6994
6995 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6996
6997 if (yes) {
6998 SET_FLAG(bgp->af_flags[afi][safi], flag);
6999 if (!previous_state) {
7000 /* trigger export current vrf */
7001 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7002 }
7003 } else {
7004 if (previous_state) {
7005 /* trigger un-export current vrf */
7006 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7007 }
7008 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7009 }
7010
7011 return CMD_SUCCESS;
7012 }
7013
7014 DEFPY (af_routetarget_import,
7015 af_routetarget_import_cmd,
7016 "[no] <rt|route-target> redirect import RTLIST...",
7017 NO_STR
7018 "Specify route target list\n"
7019 "Specify route target list\n"
7020 "Flow-spec redirect type route target\n"
7021 "Import routes to this address-family\n"
7022 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7023 {
7024 VTY_DECLVAR_CONTEXT(bgp, bgp);
7025 int ret;
7026 struct ecommunity *ecom = NULL;
7027 afi_t afi;
7028 int idx = 0;
7029 int yes = 1;
7030
7031 if (argv_find(argv, argc, "no", &idx))
7032 yes = 0;
7033
7034 afi = vpn_policy_getafi(vty, bgp, false);
7035 if (afi == AFI_MAX)
7036 return CMD_WARNING_CONFIG_FAILED;
7037
7038 if (yes) {
7039 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7040 vty_out(vty, "%% Missing RTLIST\n");
7041 return CMD_WARNING_CONFIG_FAILED;
7042 }
7043 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7044 if (ret != CMD_SUCCESS)
7045 return ret;
7046 }
7047
7048 if (yes) {
7049 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7050 ecommunity_free(&bgp->vpn_policy[afi]
7051 .import_redirect_rtlist);
7052 bgp->vpn_policy[afi].import_redirect_rtlist =
7053 ecommunity_dup(ecom);
7054 } else {
7055 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7056 ecommunity_free(&bgp->vpn_policy[afi]
7057 .import_redirect_rtlist);
7058 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7059 }
7060
7061 if (ecom)
7062 ecommunity_free(&ecom);
7063
7064 return CMD_SUCCESS;
7065 }
7066
7067 DEFUN_NOSH (address_family_ipv4_safi,
7068 address_family_ipv4_safi_cmd,
7069 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7070 "Enter Address Family command mode\n"
7071 "Address Family\n"
7072 BGP_SAFI_WITH_LABEL_HELP_STR)
7073 {
7074
7075 if (argc == 3) {
7076 VTY_DECLVAR_CONTEXT(bgp, bgp);
7077 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7078 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7079 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7080 && safi != SAFI_EVPN) {
7081 vty_out(vty,
7082 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7083 return CMD_WARNING_CONFIG_FAILED;
7084 }
7085 vty->node = bgp_node_type(AFI_IP, safi);
7086 } else
7087 vty->node = BGP_IPV4_NODE;
7088
7089 return CMD_SUCCESS;
7090 }
7091
7092 DEFUN_NOSH (address_family_ipv6_safi,
7093 address_family_ipv6_safi_cmd,
7094 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7095 "Enter Address Family command mode\n"
7096 "Address Family\n"
7097 BGP_SAFI_WITH_LABEL_HELP_STR)
7098 {
7099 if (argc == 3) {
7100 VTY_DECLVAR_CONTEXT(bgp, bgp);
7101 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7102 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7103 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7104 && safi != SAFI_EVPN) {
7105 vty_out(vty,
7106 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7107 return CMD_WARNING_CONFIG_FAILED;
7108 }
7109 vty->node = bgp_node_type(AFI_IP6, safi);
7110 } else
7111 vty->node = BGP_IPV6_NODE;
7112
7113 return CMD_SUCCESS;
7114 }
7115
7116 #ifdef KEEP_OLD_VPN_COMMANDS
7117 DEFUN_NOSH (address_family_vpnv4,
7118 address_family_vpnv4_cmd,
7119 "address-family vpnv4 [unicast]",
7120 "Enter Address Family command mode\n"
7121 "Address Family\n"
7122 "Address Family modifier\n")
7123 {
7124 vty->node = BGP_VPNV4_NODE;
7125 return CMD_SUCCESS;
7126 }
7127
7128 DEFUN_NOSH (address_family_vpnv6,
7129 address_family_vpnv6_cmd,
7130 "address-family vpnv6 [unicast]",
7131 "Enter Address Family command mode\n"
7132 "Address Family\n"
7133 "Address Family modifier\n")
7134 {
7135 vty->node = BGP_VPNV6_NODE;
7136 return CMD_SUCCESS;
7137 }
7138 #endif
7139
7140 DEFUN_NOSH (address_family_evpn,
7141 address_family_evpn_cmd,
7142 "address-family l2vpn evpn",
7143 "Enter Address Family command mode\n"
7144 "Address Family\n"
7145 "Address Family modifier\n")
7146 {
7147 VTY_DECLVAR_CONTEXT(bgp, bgp);
7148 vty->node = BGP_EVPN_NODE;
7149 return CMD_SUCCESS;
7150 }
7151
7152 DEFUN_NOSH (exit_address_family,
7153 exit_address_family_cmd,
7154 "exit-address-family",
7155 "Exit from Address Family configuration mode\n")
7156 {
7157 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7158 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7159 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7160 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7161 || vty->node == BGP_EVPN_NODE
7162 || vty->node == BGP_FLOWSPECV4_NODE
7163 || vty->node == BGP_FLOWSPECV6_NODE)
7164 vty->node = BGP_NODE;
7165 return CMD_SUCCESS;
7166 }
7167
7168 /* Recalculate bestpath and re-advertise a prefix */
7169 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7170 const char *ip_str, afi_t afi, safi_t safi,
7171 struct prefix_rd *prd)
7172 {
7173 int ret;
7174 struct prefix match;
7175 struct bgp_node *rn;
7176 struct bgp_node *rm;
7177 struct bgp *bgp;
7178 struct bgp_table *table;
7179 struct bgp_table *rib;
7180
7181 /* BGP structure lookup. */
7182 if (view_name) {
7183 bgp = bgp_lookup_by_name(view_name);
7184 if (bgp == NULL) {
7185 vty_out(vty, "%% Can't find BGP instance %s\n",
7186 view_name);
7187 return CMD_WARNING;
7188 }
7189 } else {
7190 bgp = bgp_get_default();
7191 if (bgp == NULL) {
7192 vty_out(vty, "%% No BGP process is configured\n");
7193 return CMD_WARNING;
7194 }
7195 }
7196
7197 /* Check IP address argument. */
7198 ret = str2prefix(ip_str, &match);
7199 if (!ret) {
7200 vty_out(vty, "%% address is malformed\n");
7201 return CMD_WARNING;
7202 }
7203
7204 match.family = afi2family(afi);
7205 rib = bgp->rib[afi][safi];
7206
7207 if (safi == SAFI_MPLS_VPN) {
7208 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7209 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7210 continue;
7211
7212 if ((table = rn->info) != NULL) {
7213 if ((rm = bgp_node_match(table, &match))
7214 != NULL) {
7215 if (rm->p.prefixlen
7216 == match.prefixlen) {
7217 SET_FLAG(rm->flags,
7218 BGP_NODE_USER_CLEAR);
7219 bgp_process(bgp, rm, afi, safi);
7220 }
7221 bgp_unlock_node(rm);
7222 }
7223 }
7224 }
7225 } else {
7226 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7227 if (rn->p.prefixlen == match.prefixlen) {
7228 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7229 bgp_process(bgp, rn, afi, safi);
7230 }
7231 bgp_unlock_node(rn);
7232 }
7233 }
7234
7235 return CMD_SUCCESS;
7236 }
7237
7238 /* one clear bgp command to rule them all */
7239 DEFUN (clear_ip_bgp_all,
7240 clear_ip_bgp_all_cmd,
7241 "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>]",
7242 CLEAR_STR
7243 IP_STR
7244 BGP_STR
7245 BGP_INSTANCE_HELP_STR
7246 BGP_AFI_HELP_STR
7247 BGP_SAFI_WITH_LABEL_HELP_STR
7248 "Clear all peers\n"
7249 "BGP neighbor address to clear\n"
7250 "BGP IPv6 neighbor to clear\n"
7251 "BGP neighbor on interface to clear\n"
7252 "Clear peers with the AS number\n"
7253 "Clear all external peers\n"
7254 "Clear all members of peer-group\n"
7255 "BGP peer-group name\n"
7256 BGP_SOFT_STR
7257 BGP_SOFT_IN_STR
7258 BGP_SOFT_OUT_STR
7259 BGP_SOFT_IN_STR
7260 "Push out prefix-list ORF and do inbound soft reconfig\n"
7261 BGP_SOFT_OUT_STR)
7262 {
7263 char *vrf = NULL;
7264
7265 afi_t afi = AFI_IP6;
7266 safi_t safi = SAFI_UNICAST;
7267 enum clear_sort clr_sort = clear_peer;
7268 enum bgp_clear_type clr_type;
7269 char *clr_arg = NULL;
7270
7271 int idx = 0;
7272
7273 /* clear [ip] bgp */
7274 if (argv_find(argv, argc, "ip", &idx))
7275 afi = AFI_IP;
7276
7277 /* [<vrf> VIEWVRFNAME] */
7278 if (argv_find(argv, argc, "vrf", &idx)) {
7279 vrf = argv[idx + 1]->arg;
7280 idx += 2;
7281 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7282 vrf = NULL;
7283 } else if (argv_find(argv, argc, "view", &idx)) {
7284 /* [<view> VIEWVRFNAME] */
7285 vrf = argv[idx + 1]->arg;
7286 idx += 2;
7287 }
7288 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7289 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7290 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7291
7292 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7293 if (argv_find(argv, argc, "*", &idx)) {
7294 clr_sort = clear_all;
7295 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7296 clr_sort = clear_peer;
7297 clr_arg = argv[idx]->arg;
7298 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7299 clr_sort = clear_peer;
7300 clr_arg = argv[idx]->arg;
7301 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7302 clr_sort = clear_group;
7303 idx++;
7304 clr_arg = argv[idx]->arg;
7305 } else if (argv_find(argv, argc, "WORD", &idx)) {
7306 clr_sort = clear_peer;
7307 clr_arg = argv[idx]->arg;
7308 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7309 clr_sort = clear_as;
7310 clr_arg = argv[idx]->arg;
7311 } else if (argv_find(argv, argc, "external", &idx)) {
7312 clr_sort = clear_external;
7313 }
7314
7315 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7316 if (argv_find(argv, argc, "soft", &idx)) {
7317 if (argv_find(argv, argc, "in", &idx)
7318 || argv_find(argv, argc, "out", &idx))
7319 clr_type = strmatch(argv[idx]->text, "in")
7320 ? BGP_CLEAR_SOFT_IN
7321 : BGP_CLEAR_SOFT_OUT;
7322 else
7323 clr_type = BGP_CLEAR_SOFT_BOTH;
7324 } else if (argv_find(argv, argc, "in", &idx)) {
7325 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7326 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7327 : BGP_CLEAR_SOFT_IN;
7328 } else if (argv_find(argv, argc, "out", &idx)) {
7329 clr_type = BGP_CLEAR_SOFT_OUT;
7330 } else
7331 clr_type = BGP_CLEAR_SOFT_NONE;
7332
7333 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7334 }
7335
7336 DEFUN (clear_ip_bgp_prefix,
7337 clear_ip_bgp_prefix_cmd,
7338 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7339 CLEAR_STR
7340 IP_STR
7341 BGP_STR
7342 BGP_INSTANCE_HELP_STR
7343 "Clear bestpath and re-advertise\n"
7344 "IPv4 prefix\n")
7345 {
7346 char *vrf = NULL;
7347 char *prefix = NULL;
7348
7349 int idx = 0;
7350
7351 /* [<view|vrf> VIEWVRFNAME] */
7352 if (argv_find(argv, argc, "vrf", &idx)) {
7353 vrf = argv[idx + 1]->arg;
7354 idx += 2;
7355 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7356 vrf = NULL;
7357 } else if (argv_find(argv, argc, "view", &idx)) {
7358 /* [<view> VIEWVRFNAME] */
7359 vrf = argv[idx + 1]->arg;
7360 idx += 2;
7361 }
7362
7363 prefix = argv[argc - 1]->arg;
7364
7365 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7366 }
7367
7368 DEFUN (clear_bgp_ipv6_safi_prefix,
7369 clear_bgp_ipv6_safi_prefix_cmd,
7370 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7371 CLEAR_STR
7372 IP_STR
7373 BGP_STR
7374 "Address Family\n"
7375 BGP_SAFI_HELP_STR
7376 "Clear bestpath and re-advertise\n"
7377 "IPv6 prefix\n")
7378 {
7379 int idx_safi = 0;
7380 int idx_ipv6_prefix = 0;
7381 safi_t safi = SAFI_UNICAST;
7382 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7383 argv[idx_ipv6_prefix]->arg : NULL;
7384
7385 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7386 return bgp_clear_prefix(
7387 vty, NULL, prefix, AFI_IP6,
7388 safi, NULL);
7389 }
7390
7391 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7392 clear_bgp_instance_ipv6_safi_prefix_cmd,
7393 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7394 CLEAR_STR
7395 IP_STR
7396 BGP_STR
7397 BGP_INSTANCE_HELP_STR
7398 "Address Family\n"
7399 BGP_SAFI_HELP_STR
7400 "Clear bestpath and re-advertise\n"
7401 "IPv6 prefix\n")
7402 {
7403 int idx_safi = 0;
7404 int idx_vrfview = 0;
7405 int idx_ipv6_prefix = 0;
7406 safi_t safi = SAFI_UNICAST;
7407 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7408 argv[idx_ipv6_prefix]->arg : NULL;
7409 char *vrfview = NULL;
7410
7411 /* [<view|vrf> VIEWVRFNAME] */
7412 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7413 vrfview = argv[idx_vrfview + 1]->arg;
7414 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7415 vrfview = NULL;
7416 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7417 /* [<view> VIEWVRFNAME] */
7418 vrfview = argv[idx_vrfview + 1]->arg;
7419 }
7420 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7421
7422 return bgp_clear_prefix(
7423 vty, vrfview, prefix,
7424 AFI_IP6, safi, NULL);
7425 }
7426
7427 DEFUN (show_bgp_views,
7428 show_bgp_views_cmd,
7429 "show [ip] bgp views",
7430 SHOW_STR
7431 IP_STR
7432 BGP_STR
7433 "Show the defined BGP views\n")
7434 {
7435 struct list *inst = bm->bgp;
7436 struct listnode *node;
7437 struct bgp *bgp;
7438
7439 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7440 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7441 return CMD_WARNING;
7442 }
7443
7444 vty_out(vty, "Defined BGP views:\n");
7445 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7446 /* Skip VRFs. */
7447 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7448 continue;
7449 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7450 bgp->as);
7451 }
7452
7453 return CMD_SUCCESS;
7454 }
7455
7456 DEFUN (show_bgp_vrfs,
7457 show_bgp_vrfs_cmd,
7458 "show [ip] bgp vrfs [json]",
7459 SHOW_STR
7460 IP_STR
7461 BGP_STR
7462 "Show BGP VRFs\n"
7463 JSON_STR)
7464 {
7465 char buf[ETHER_ADDR_STRLEN];
7466 struct list *inst = bm->bgp;
7467 struct listnode *node;
7468 struct bgp *bgp;
7469 bool uj = use_json(argc, argv);
7470 json_object *json = NULL;
7471 json_object *json_vrfs = NULL;
7472 int count = 0;
7473
7474 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7475 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7476 return CMD_WARNING;
7477 }
7478
7479 if (uj) {
7480 json = json_object_new_object();
7481 json_vrfs = json_object_new_object();
7482 }
7483
7484 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7485 const char *name, *type;
7486 struct peer *peer;
7487 struct listnode *node2, *nnode2;
7488 int peers_cfg, peers_estb;
7489 json_object *json_vrf = NULL;
7490
7491 /* Skip Views. */
7492 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7493 continue;
7494
7495 count++;
7496 if (!uj && count == 1)
7497 vty_out(vty,
7498 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7499 "Type", "Id", "routerId", "#PeersVfg",
7500 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7501
7502 peers_cfg = peers_estb = 0;
7503 if (uj)
7504 json_vrf = json_object_new_object();
7505
7506
7507 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7508 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7509 continue;
7510 peers_cfg++;
7511 if (peer->status == Established)
7512 peers_estb++;
7513 }
7514
7515 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7516 name = VRF_DEFAULT_NAME;
7517 type = "DFLT";
7518 } else {
7519 name = bgp->name;
7520 type = "VRF";
7521 }
7522
7523
7524 if (uj) {
7525 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7526 ? -1
7527 : (int64_t)bgp->vrf_id;
7528 json_object_string_add(json_vrf, "type", type);
7529 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7530 json_object_string_add(json_vrf, "routerId",
7531 inet_ntoa(bgp->router_id));
7532 json_object_int_add(json_vrf, "numConfiguredPeers",
7533 peers_cfg);
7534 json_object_int_add(json_vrf, "numEstablishedPeers",
7535 peers_estb);
7536
7537 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7538 json_object_string_add(
7539 json_vrf, "rmac",
7540 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7541 json_object_object_add(json_vrfs, name, json_vrf);
7542 } else
7543 vty_out(vty,
7544 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7545 type,
7546 bgp->vrf_id == VRF_UNKNOWN ? -1
7547 : (int)bgp->vrf_id,
7548 inet_ntoa(bgp->router_id), peers_cfg,
7549 peers_estb, name, bgp->l3vni,
7550 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7551 }
7552
7553 if (uj) {
7554 json_object_object_add(json, "vrfs", json_vrfs);
7555
7556 json_object_int_add(json, "totalVrfs", count);
7557
7558 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7559 json, JSON_C_TO_STRING_PRETTY));
7560 json_object_free(json);
7561 } else {
7562 if (count)
7563 vty_out(vty,
7564 "\nTotal number of VRFs (including default): %d\n",
7565 count);
7566 }
7567
7568 return CMD_SUCCESS;
7569 }
7570
7571
7572 static void show_tip_entry(struct hash_backet *backet, void *args)
7573 {
7574 struct vty *vty = (struct vty *)args;
7575 struct tip_addr *tip = (struct tip_addr *)backet->data;
7576
7577 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7578 tip->refcnt);
7579 }
7580
7581 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7582 {
7583 vty_out(vty, "self nexthop database:\n");
7584 bgp_nexthop_show_address_hash(vty, bgp);
7585
7586 vty_out(vty, "Tunnel-ip database:\n");
7587 hash_iterate(bgp->tip_hash,
7588 (void (*)(struct hash_backet *, void *))show_tip_entry,
7589 vty);
7590 }
7591
7592 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7593 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7594 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7595 "martian next-hops\n"
7596 "martian next-hop database\n")
7597 {
7598 struct bgp *bgp = NULL;
7599 int idx = 0;
7600 char *name = NULL;
7601
7602 /* [<vrf> VIEWVRFNAME] */
7603 if (argv_find(argv, argc, "vrf", &idx)) {
7604 name = argv[idx + 1]->arg;
7605 if (name && strmatch(name, VRF_DEFAULT_NAME))
7606 name = NULL;
7607 } else if (argv_find(argv, argc, "view", &idx))
7608 /* [<view> VIEWVRFNAME] */
7609 name = argv[idx + 1]->arg;
7610 if (name)
7611 bgp = bgp_lookup_by_name(name);
7612 else
7613 bgp = bgp_get_default();
7614
7615 if (!bgp) {
7616 vty_out(vty, "%% No BGP process is configured\n");
7617 return CMD_WARNING;
7618 }
7619 bgp_show_martian_nexthops(vty, bgp);
7620
7621 return CMD_SUCCESS;
7622 }
7623
7624 DEFUN (show_bgp_memory,
7625 show_bgp_memory_cmd,
7626 "show [ip] bgp memory",
7627 SHOW_STR
7628 IP_STR
7629 BGP_STR
7630 "Global BGP memory statistics\n")
7631 {
7632 char memstrbuf[MTYPE_MEMSTR_LEN];
7633 unsigned long count;
7634
7635 /* RIB related usage stats */
7636 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7637 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7638 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7639 count * sizeof(struct bgp_node)));
7640
7641 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7642 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7643 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7644 count * sizeof(struct bgp_path_info)));
7645 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7646 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7647 count,
7648 mtype_memstr(
7649 memstrbuf, sizeof(memstrbuf),
7650 count * sizeof(struct bgp_path_info_extra)));
7651
7652 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7653 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7654 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7655 count * sizeof(struct bgp_static)));
7656
7657 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7658 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7659 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7660 count * sizeof(struct bpacket)));
7661
7662 /* Adj-In/Out */
7663 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7664 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7665 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7666 count * sizeof(struct bgp_adj_in)));
7667 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7668 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7669 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7670 count * sizeof(struct bgp_adj_out)));
7671
7672 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7673 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7674 count,
7675 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7676 count * sizeof(struct bgp_nexthop_cache)));
7677
7678 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7679 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7680 count,
7681 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7682 count * sizeof(struct bgp_damp_info)));
7683
7684 /* Attributes */
7685 count = attr_count();
7686 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7688 count * sizeof(struct attr)));
7689
7690 if ((count = attr_unknown_count()))
7691 vty_out(vty, "%ld unknown attributes\n", count);
7692
7693 /* AS_PATH attributes */
7694 count = aspath_count();
7695 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7696 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7697 count * sizeof(struct aspath)));
7698
7699 count = mtype_stats_alloc(MTYPE_AS_SEG);
7700 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7701 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7702 count * sizeof(struct assegment)));
7703
7704 /* Other attributes */
7705 if ((count = community_count()))
7706 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7707 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7708 count * sizeof(struct community)));
7709 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7710 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7711 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7712 count * sizeof(struct ecommunity)));
7713 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7714 vty_out(vty,
7715 "%ld BGP large-community entries, using %s of memory\n",
7716 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7717 count * sizeof(struct lcommunity)));
7718
7719 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7720 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7721 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7722 count * sizeof(struct cluster_list)));
7723
7724 /* Peer related usage */
7725 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7726 vty_out(vty, "%ld peers, using %s of memory\n", count,
7727 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7728 count * sizeof(struct peer)));
7729
7730 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7731 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7732 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7733 count * sizeof(struct peer_group)));
7734
7735 /* Other */
7736 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7737 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7738 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7739 count * sizeof(struct hash)));
7740 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7741 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7742 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7743 count * sizeof(struct hash_backet)));
7744 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7745 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7746 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7747 count * sizeof(regex_t)));
7748 return CMD_SUCCESS;
7749 }
7750
7751 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7752 {
7753 json_object *bestpath = json_object_new_object();
7754
7755 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7756 json_object_string_add(bestpath, "asPath", "ignore");
7757
7758 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7759 json_object_string_add(bestpath, "asPath", "confed");
7760
7761 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7762 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7763 json_object_string_add(bestpath, "multiPathRelax",
7764 "as-set");
7765 else
7766 json_object_string_add(bestpath, "multiPathRelax",
7767 "true");
7768 } else
7769 json_object_string_add(bestpath, "multiPathRelax", "false");
7770
7771 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7772 json_object_string_add(bestpath, "compareRouterId", "true");
7773 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7774 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7775 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7776 json_object_string_add(bestpath, "med", "confed");
7777 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7778 json_object_string_add(bestpath, "med",
7779 "missing-as-worst");
7780 else
7781 json_object_string_add(bestpath, "med", "true");
7782 }
7783
7784 json_object_object_add(json, "bestPath", bestpath);
7785 }
7786
7787 /* Show BGP peer's summary information. */
7788 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7789 bool use_json, json_object *json)
7790 {
7791 struct peer *peer;
7792 struct listnode *node, *nnode;
7793 unsigned int count = 0, dn_count = 0;
7794 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7795 char neighbor_buf[VTY_BUFSIZ];
7796 int neighbor_col_default_width = 16;
7797 int len;
7798 int max_neighbor_width = 0;
7799 int pfx_rcd_safi;
7800 json_object *json_peer = NULL;
7801 json_object *json_peers = NULL;
7802 struct peer_af *paf;
7803
7804 /* labeled-unicast routes are installed in the unicast table so in order
7805 * to
7806 * display the correct PfxRcd value we must look at SAFI_UNICAST
7807 */
7808 if (safi == SAFI_LABELED_UNICAST)
7809 pfx_rcd_safi = SAFI_UNICAST;
7810 else
7811 pfx_rcd_safi = safi;
7812
7813 if (use_json) {
7814 if (json == NULL)
7815 json = json_object_new_object();
7816
7817 json_peers = json_object_new_object();
7818 } else {
7819 /* Loop over all neighbors that will be displayed to determine
7820 * how many
7821 * characters are needed for the Neighbor column
7822 */
7823 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7824 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7825 continue;
7826
7827 if (peer->afc[afi][safi]) {
7828 memset(dn_flag, '\0', sizeof(dn_flag));
7829 if (peer_dynamic_neighbor(peer))
7830 dn_flag[0] = '*';
7831
7832 if (peer->hostname
7833 && bgp_flag_check(bgp,
7834 BGP_FLAG_SHOW_HOSTNAME))
7835 sprintf(neighbor_buf, "%s%s(%s) ",
7836 dn_flag, peer->hostname,
7837 peer->host);
7838 else
7839 sprintf(neighbor_buf, "%s%s ", dn_flag,
7840 peer->host);
7841
7842 len = strlen(neighbor_buf);
7843
7844 if (len > max_neighbor_width)
7845 max_neighbor_width = len;
7846 }
7847 }
7848
7849 /* Originally we displayed the Neighbor column as 16
7850 * characters wide so make that the default
7851 */
7852 if (max_neighbor_width < neighbor_col_default_width)
7853 max_neighbor_width = neighbor_col_default_width;
7854 }
7855
7856 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7857 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7858 continue;
7859
7860 if (!peer->afc[afi][safi])
7861 continue;
7862
7863 if (!count) {
7864 unsigned long ents;
7865 char memstrbuf[MTYPE_MEMSTR_LEN];
7866 int64_t vrf_id_ui;
7867
7868 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7869 ? -1
7870 : (int64_t)bgp->vrf_id;
7871
7872 /* Usage summary and header */
7873 if (use_json) {
7874 json_object_string_add(
7875 json, "routerId",
7876 inet_ntoa(bgp->router_id));
7877 json_object_int_add(json, "as", bgp->as);
7878 json_object_int_add(json, "vrfId", vrf_id_ui);
7879 json_object_string_add(
7880 json, "vrfName",
7881 (bgp->inst_type
7882 == BGP_INSTANCE_TYPE_DEFAULT)
7883 ? VRF_DEFAULT_NAME
7884 : bgp->name);
7885 } else {
7886 vty_out(vty,
7887 "BGP router identifier %s, local AS number %u vrf-id %d",
7888 inet_ntoa(bgp->router_id), bgp->as,
7889 bgp->vrf_id == VRF_UNKNOWN
7890 ? -1
7891 : (int)bgp->vrf_id);
7892 vty_out(vty, "\n");
7893 }
7894
7895 if (bgp_update_delay_configured(bgp)) {
7896 if (use_json) {
7897 json_object_int_add(
7898 json, "updateDelayLimit",
7899 bgp->v_update_delay);
7900
7901 if (bgp->v_update_delay
7902 != bgp->v_establish_wait)
7903 json_object_int_add(
7904 json,
7905 "updateDelayEstablishWait",
7906 bgp->v_establish_wait);
7907
7908 if (bgp_update_delay_active(bgp)) {
7909 json_object_string_add(
7910 json,
7911 "updateDelayFirstNeighbor",
7912 bgp->update_delay_begin_time);
7913 json_object_boolean_true_add(
7914 json,
7915 "updateDelayInProgress");
7916 } else {
7917 if (bgp->update_delay_over) {
7918 json_object_string_add(
7919 json,
7920 "updateDelayFirstNeighbor",
7921 bgp->update_delay_begin_time);
7922 json_object_string_add(
7923 json,
7924 "updateDelayBestpathResumed",
7925 bgp->update_delay_end_time);
7926 json_object_string_add(
7927 json,
7928 "updateDelayZebraUpdateResume",
7929 bgp->update_delay_zebra_resume_time);
7930 json_object_string_add(
7931 json,
7932 "updateDelayPeerUpdateResume",
7933 bgp->update_delay_peers_resume_time);
7934 }
7935 }
7936 } else {
7937 vty_out(vty,
7938 "Read-only mode update-delay limit: %d seconds\n",
7939 bgp->v_update_delay);
7940 if (bgp->v_update_delay
7941 != bgp->v_establish_wait)
7942 vty_out(vty,
7943 " Establish wait: %d seconds\n",
7944 bgp->v_establish_wait);
7945
7946 if (bgp_update_delay_active(bgp)) {
7947 vty_out(vty,
7948 " First neighbor established: %s\n",
7949 bgp->update_delay_begin_time);
7950 vty_out(vty,
7951 " Delay in progress\n");
7952 } else {
7953 if (bgp->update_delay_over) {
7954 vty_out(vty,
7955 " First neighbor established: %s\n",
7956 bgp->update_delay_begin_time);
7957 vty_out(vty,
7958 " Best-paths resumed: %s\n",
7959 bgp->update_delay_end_time);
7960 vty_out(vty,
7961 " zebra update resumed: %s\n",
7962 bgp->update_delay_zebra_resume_time);
7963 vty_out(vty,
7964 " peers update resumed: %s\n",
7965 bgp->update_delay_peers_resume_time);
7966 }
7967 }
7968 }
7969 }
7970
7971 if (use_json) {
7972 if (bgp_maxmed_onstartup_configured(bgp)
7973 && bgp->maxmed_active)
7974 json_object_boolean_true_add(
7975 json, "maxMedOnStartup");
7976 if (bgp->v_maxmed_admin)
7977 json_object_boolean_true_add(
7978 json, "maxMedAdministrative");
7979
7980 json_object_int_add(
7981 json, "tableVersion",
7982 bgp_table_version(bgp->rib[afi][safi]));
7983
7984 ents = bgp_table_count(bgp->rib[afi][safi]);
7985 json_object_int_add(json, "ribCount", ents);
7986 json_object_int_add(
7987 json, "ribMemory",
7988 ents * sizeof(struct bgp_node));
7989
7990 ents = listcount(bgp->peer);
7991 json_object_int_add(json, "peerCount", ents);
7992 json_object_int_add(json, "peerMemory",
7993 ents * sizeof(struct peer));
7994
7995 if ((ents = listcount(bgp->group))) {
7996 json_object_int_add(
7997 json, "peerGroupCount", ents);
7998 json_object_int_add(
7999 json, "peerGroupMemory",
8000 ents * sizeof(struct
8001 peer_group));
8002 }
8003
8004 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8005 BGP_CONFIG_DAMPENING))
8006 json_object_boolean_true_add(
8007 json, "dampeningEnabled");
8008 } else {
8009 if (bgp_maxmed_onstartup_configured(bgp)
8010 && bgp->maxmed_active)
8011 vty_out(vty,
8012 "Max-med on-startup active\n");
8013 if (bgp->v_maxmed_admin)
8014 vty_out(vty,
8015 "Max-med administrative active\n");
8016
8017 vty_out(vty, "BGP table version %" PRIu64 "\n",
8018 bgp_table_version(bgp->rib[afi][safi]));
8019
8020 ents = bgp_table_count(bgp->rib[afi][safi]);
8021 vty_out(vty,
8022 "RIB entries %ld, using %s of memory\n",
8023 ents,
8024 mtype_memstr(memstrbuf,
8025 sizeof(memstrbuf),
8026 ents * sizeof(struct
8027 bgp_node)));
8028
8029 /* Peer related usage */
8030 ents = listcount(bgp->peer);
8031 vty_out(vty, "Peers %ld, using %s of memory\n",
8032 ents,
8033 mtype_memstr(
8034 memstrbuf, sizeof(memstrbuf),
8035 ents * sizeof(struct peer)));
8036
8037 if ((ents = listcount(bgp->group)))
8038 vty_out(vty,
8039 "Peer groups %ld, using %s of memory\n",
8040 ents,
8041 mtype_memstr(
8042 memstrbuf,
8043 sizeof(memstrbuf),
8044 ents * sizeof(struct
8045 peer_group)));
8046
8047 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8048 BGP_CONFIG_DAMPENING))
8049 vty_out(vty, "Dampening enabled.\n");
8050 vty_out(vty, "\n");
8051
8052 /* Subtract 8 here because 'Neighbor' is
8053 * 8 characters */
8054 vty_out(vty, "Neighbor");
8055 vty_out(vty, "%*s", max_neighbor_width - 8,
8056 " ");
8057 vty_out(vty,
8058 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8059 }
8060 }
8061
8062 count++;
8063
8064 if (use_json) {
8065 json_peer = json_object_new_object();
8066
8067 if (peer_dynamic_neighbor(peer)) {
8068 dn_count++;
8069 json_object_boolean_true_add(json_peer,
8070 "dynamicPeer");
8071 }
8072
8073 if (peer->hostname)
8074 json_object_string_add(json_peer, "hostname",
8075 peer->hostname);
8076
8077 if (peer->domainname)
8078 json_object_string_add(json_peer, "domainname",
8079 peer->domainname);
8080
8081 json_object_int_add(json_peer, "remoteAs", peer->as);
8082 json_object_int_add(json_peer, "version", 4);
8083 json_object_int_add(json_peer, "msgRcvd",
8084 PEER_TOTAL_RX(peer));
8085 json_object_int_add(json_peer, "msgSent",
8086 PEER_TOTAL_TX(peer));
8087
8088 json_object_int_add(json_peer, "tableVersion",
8089 peer->version[afi][safi]);
8090 json_object_int_add(json_peer, "outq",
8091 peer->obuf->count);
8092 json_object_int_add(json_peer, "inq", 0);
8093 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8094 use_json, json_peer);
8095
8096 /*
8097 * Adding "pfxRcd" field to match with the corresponding
8098 * CLI. "prefixReceivedCount" will be deprecated in
8099 * future.
8100 */
8101 json_object_int_add(json_peer, "prefixReceivedCount",
8102 peer->pcount[afi][pfx_rcd_safi]);
8103 json_object_int_add(json_peer, "pfxRcd",
8104 peer->pcount[afi][pfx_rcd_safi]);
8105
8106 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8107 if (paf && PAF_SUBGRP(paf))
8108 json_object_int_add(json_peer,
8109 "pfxSnt",
8110 (PAF_SUBGRP(paf))->scount);
8111
8112 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8113 json_object_string_add(json_peer, "state",
8114 "Idle (Admin)");
8115 else if (peer->afc_recv[afi][safi])
8116 json_object_string_add(
8117 json_peer, "state",
8118 lookup_msg(bgp_status_msg, peer->status,
8119 NULL));
8120 else if (CHECK_FLAG(peer->sflags,
8121 PEER_STATUS_PREFIX_OVERFLOW))
8122 json_object_string_add(json_peer, "state",
8123 "Idle (PfxCt)");
8124 else
8125 json_object_string_add(
8126 json_peer, "state",
8127 lookup_msg(bgp_status_msg, peer->status,
8128 NULL));
8129
8130 if (peer->conf_if)
8131 json_object_string_add(json_peer, "idType",
8132 "interface");
8133 else if (peer->su.sa.sa_family == AF_INET)
8134 json_object_string_add(json_peer, "idType",
8135 "ipv4");
8136 else if (peer->su.sa.sa_family == AF_INET6)
8137 json_object_string_add(json_peer, "idType",
8138 "ipv6");
8139
8140 json_object_object_add(json_peers, peer->host,
8141 json_peer);
8142 } else {
8143 memset(dn_flag, '\0', sizeof(dn_flag));
8144 if (peer_dynamic_neighbor(peer)) {
8145 dn_count++;
8146 dn_flag[0] = '*';
8147 }
8148
8149 if (peer->hostname
8150 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8151 len = vty_out(vty, "%s%s(%s)", dn_flag,
8152 peer->hostname, peer->host);
8153 else
8154 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8155
8156 /* pad the neighbor column with spaces */
8157 if (len < max_neighbor_width)
8158 vty_out(vty, "%*s", max_neighbor_width - len,
8159 " ");
8160
8161 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8162 peer->as, PEER_TOTAL_RX(peer),
8163 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8164 0, peer->obuf->count,
8165 peer_uptime(peer->uptime, timebuf,
8166 BGP_UPTIME_LEN, 0, NULL));
8167
8168 if (peer->status == Established)
8169 if (peer->afc_recv[afi][safi])
8170 vty_out(vty, " %12ld",
8171 peer->pcount[afi]
8172 [pfx_rcd_safi]);
8173 else
8174 vty_out(vty, " NoNeg");
8175 else {
8176 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8177 vty_out(vty, " Idle (Admin)");
8178 else if (CHECK_FLAG(
8179 peer->sflags,
8180 PEER_STATUS_PREFIX_OVERFLOW))
8181 vty_out(vty, " Idle (PfxCt)");
8182 else
8183 vty_out(vty, " %12s",
8184 lookup_msg(bgp_status_msg,
8185 peer->status, NULL));
8186 }
8187 vty_out(vty, "\n");
8188 }
8189 }
8190
8191 if (use_json) {
8192 json_object_object_add(json, "peers", json_peers);
8193
8194 json_object_int_add(json, "totalPeers", count);
8195 json_object_int_add(json, "dynamicPeers", dn_count);
8196
8197 bgp_show_bestpath_json(bgp, json);
8198
8199 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8200 json, JSON_C_TO_STRING_PRETTY));
8201 json_object_free(json);
8202 } else {
8203 if (count)
8204 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8205 else {
8206 vty_out(vty, "No %s neighbor is configured\n",
8207 afi_safi_print(afi, safi));
8208 }
8209
8210 if (dn_count) {
8211 vty_out(vty, "* - dynamic neighbor\n");
8212 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8213 dn_count, bgp->dynamic_neighbors_limit);
8214 }
8215 }
8216
8217 return CMD_SUCCESS;
8218 }
8219
8220 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8221 int safi, bool use_json,
8222 json_object *json)
8223 {
8224 int is_first = 1;
8225 int afi_wildcard = (afi == AFI_MAX);
8226 int safi_wildcard = (safi == SAFI_MAX);
8227 int is_wildcard = (afi_wildcard || safi_wildcard);
8228 bool nbr_output = false;
8229
8230 if (use_json && is_wildcard)
8231 vty_out(vty, "{\n");
8232 if (afi_wildcard)
8233 afi = 1; /* AFI_IP */
8234 while (afi < AFI_MAX) {
8235 if (safi_wildcard)
8236 safi = 1; /* SAFI_UNICAST */
8237 while (safi < SAFI_MAX) {
8238 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8239 nbr_output = true;
8240 if (is_wildcard) {
8241 /*
8242 * So limit output to those afi/safi
8243 * pairs that
8244 * actualy have something interesting in
8245 * them
8246 */
8247 if (use_json) {
8248 json = json_object_new_object();
8249
8250 if (!is_first)
8251 vty_out(vty, ",\n");
8252 else
8253 is_first = 0;
8254
8255 vty_out(vty, "\"%s\":",
8256 afi_safi_json(afi,
8257 safi));
8258 } else {
8259 vty_out(vty, "\n%s Summary:\n",
8260 afi_safi_print(afi,
8261 safi));
8262 }
8263 }
8264 bgp_show_summary(vty, bgp, afi, safi, use_json,
8265 json);
8266 }
8267 safi++;
8268 if (!safi_wildcard)
8269 safi = SAFI_MAX;
8270 }
8271 afi++;
8272 if (!afi_wildcard)
8273 afi = AFI_MAX;
8274 }
8275
8276 if (use_json && is_wildcard)
8277 vty_out(vty, "}\n");
8278 else if (!nbr_output) {
8279 if (use_json)
8280 vty_out(vty, "{}\n");
8281 else
8282 vty_out(vty, "%% No BGP neighbors found\n");
8283 }
8284 }
8285
8286 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8287 safi_t safi, bool use_json)
8288 {
8289 struct listnode *node, *nnode;
8290 struct bgp *bgp;
8291 json_object *json = NULL;
8292 int is_first = 1;
8293 bool nbr_output = false;
8294
8295 if (use_json)
8296 vty_out(vty, "{\n");
8297
8298 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8299 nbr_output = true;
8300 if (use_json) {
8301 json = json_object_new_object();
8302
8303 if (!is_first)
8304 vty_out(vty, ",\n");
8305 else
8306 is_first = 0;
8307
8308 vty_out(vty, "\"%s\":",
8309 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8310 ? VRF_DEFAULT_NAME
8311 : bgp->name);
8312 } else {
8313 vty_out(vty, "\nInstance %s:\n",
8314 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8315 ? VRF_DEFAULT_NAME
8316 : bgp->name);
8317 }
8318 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8319 }
8320
8321 if (use_json)
8322 vty_out(vty, "}\n");
8323 else if (!nbr_output)
8324 vty_out(vty, "%% BGP instance not found\n");
8325 }
8326
8327 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8328 safi_t safi, bool use_json)
8329 {
8330 struct bgp *bgp;
8331
8332 if (name) {
8333 if (strmatch(name, "all")) {
8334 bgp_show_all_instances_summary_vty(vty, afi, safi,
8335 use_json);
8336 return CMD_SUCCESS;
8337 } else {
8338 bgp = bgp_lookup_by_name(name);
8339
8340 if (!bgp) {
8341 if (use_json)
8342 vty_out(vty, "{}\n");
8343 else
8344 vty_out(vty,
8345 "%% BGP instance not found\n");
8346 return CMD_WARNING;
8347 }
8348
8349 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8350 NULL);
8351 return CMD_SUCCESS;
8352 }
8353 }
8354
8355 bgp = bgp_get_default();
8356
8357 if (bgp)
8358 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8359 else {
8360 if (use_json)
8361 vty_out(vty, "{}\n");
8362 else
8363 vty_out(vty, "%% BGP instance not found\n");
8364 return CMD_WARNING;
8365 }
8366
8367 return CMD_SUCCESS;
8368 }
8369
8370 /* `show [ip] bgp summary' commands. */
8371 DEFUN (show_ip_bgp_summary,
8372 show_ip_bgp_summary_cmd,
8373 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8374 SHOW_STR
8375 IP_STR
8376 BGP_STR
8377 BGP_INSTANCE_HELP_STR
8378 BGP_AFI_HELP_STR
8379 BGP_SAFI_WITH_LABEL_HELP_STR
8380 "Summary of BGP neighbor status\n"
8381 JSON_STR)
8382 {
8383 char *vrf = NULL;
8384 afi_t afi = AFI_MAX;
8385 safi_t safi = SAFI_MAX;
8386
8387 int idx = 0;
8388
8389 /* show [ip] bgp */
8390 if (argv_find(argv, argc, "ip", &idx))
8391 afi = AFI_IP;
8392 /* [<vrf> VIEWVRFNAME] */
8393 if (argv_find(argv, argc, "vrf", &idx)) {
8394 vrf = argv[idx + 1]->arg;
8395 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8396 vrf = NULL;
8397 } else if (argv_find(argv, argc, "view", &idx))
8398 /* [<view> VIEWVRFNAME] */
8399 vrf = argv[idx + 1]->arg;
8400 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8401 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8402 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8403 }
8404
8405 bool uj = use_json(argc, argv);
8406
8407 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8408 }
8409
8410 const char *afi_safi_print(afi_t afi, safi_t safi)
8411 {
8412 if (afi == AFI_IP && safi == SAFI_UNICAST)
8413 return "IPv4 Unicast";
8414 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8415 return "IPv4 Multicast";
8416 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8417 return "IPv4 Labeled Unicast";
8418 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8419 return "IPv4 VPN";
8420 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8421 return "IPv4 Encap";
8422 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8423 return "IPv4 Flowspec";
8424 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8425 return "IPv6 Unicast";
8426 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8427 return "IPv6 Multicast";
8428 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8429 return "IPv6 Labeled Unicast";
8430 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8431 return "IPv6 VPN";
8432 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8433 return "IPv6 Encap";
8434 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8435 return "IPv6 Flowspec";
8436 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8437 return "L2VPN EVPN";
8438 else
8439 return "Unknown";
8440 }
8441
8442 /*
8443 * Please note that we have intentionally camelCased
8444 * the return strings here. So if you want
8445 * to use this function, please ensure you
8446 * are doing this within json output
8447 */
8448 const char *afi_safi_json(afi_t afi, safi_t safi)
8449 {
8450 if (afi == AFI_IP && safi == SAFI_UNICAST)
8451 return "ipv4Unicast";
8452 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8453 return "ipv4Multicast";
8454 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8455 return "ipv4LabeledUnicast";
8456 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8457 return "ipv4Vpn";
8458 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8459 return "ipv4Encap";
8460 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8461 return "ipv4Flowspec";
8462 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8463 return "ipv6Unicast";
8464 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8465 return "ipv6Multicast";
8466 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8467 return "ipv6LabeledUnicast";
8468 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8469 return "ipv6Vpn";
8470 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8471 return "ipv6Encap";
8472 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8473 return "ipv6Flowspec";
8474 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8475 return "l2VpnEvpn";
8476 else
8477 return "Unknown";
8478 }
8479
8480 /* Show BGP peer's information. */
8481 enum show_type { show_all, show_peer };
8482
8483 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8484 afi_t afi, safi_t safi,
8485 uint16_t adv_smcap, uint16_t adv_rmcap,
8486 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8487 bool use_json, json_object *json_pref)
8488 {
8489 /* Send-Mode */
8490 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8491 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8492 if (use_json) {
8493 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8494 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8495 json_object_string_add(json_pref, "sendMode",
8496 "advertisedAndReceived");
8497 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8498 json_object_string_add(json_pref, "sendMode",
8499 "advertised");
8500 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8501 json_object_string_add(json_pref, "sendMode",
8502 "received");
8503 } else {
8504 vty_out(vty, " Send-mode: ");
8505 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8506 vty_out(vty, "advertised");
8507 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8508 vty_out(vty, "%sreceived",
8509 CHECK_FLAG(p->af_cap[afi][safi],
8510 adv_smcap)
8511 ? ", "
8512 : "");
8513 vty_out(vty, "\n");
8514 }
8515 }
8516
8517 /* Receive-Mode */
8518 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8519 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8520 if (use_json) {
8521 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8522 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8523 json_object_string_add(json_pref, "recvMode",
8524 "advertisedAndReceived");
8525 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8526 json_object_string_add(json_pref, "recvMode",
8527 "advertised");
8528 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8529 json_object_string_add(json_pref, "recvMode",
8530 "received");
8531 } else {
8532 vty_out(vty, " Receive-mode: ");
8533 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8534 vty_out(vty, "advertised");
8535 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8536 vty_out(vty, "%sreceived",
8537 CHECK_FLAG(p->af_cap[afi][safi],
8538 adv_rmcap)
8539 ? ", "
8540 : "");
8541 vty_out(vty, "\n");
8542 }
8543 }
8544 }
8545
8546 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8547 safi_t safi, bool use_json,
8548 json_object *json_neigh)
8549 {
8550 struct bgp_filter *filter;
8551 struct peer_af *paf;
8552 char orf_pfx_name[BUFSIZ];
8553 int orf_pfx_count;
8554 json_object *json_af = NULL;
8555 json_object *json_prefA = NULL;
8556 json_object *json_prefB = NULL;
8557 json_object *json_addr = NULL;
8558
8559 if (use_json) {
8560 json_addr = json_object_new_object();
8561 json_af = json_object_new_object();
8562 filter = &p->filter[afi][safi];
8563
8564 if (peer_group_active(p))
8565 json_object_string_add(json_addr, "peerGroupMember",
8566 p->group->name);
8567
8568 paf = peer_af_find(p, afi, safi);
8569 if (paf && PAF_SUBGRP(paf)) {
8570 json_object_int_add(json_addr, "updateGroupId",
8571 PAF_UPDGRP(paf)->id);
8572 json_object_int_add(json_addr, "subGroupId",
8573 PAF_SUBGRP(paf)->id);
8574 json_object_int_add(json_addr, "packetQueueLength",
8575 bpacket_queue_virtual_length(paf));
8576 }
8577
8578 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8579 || CHECK_FLAG(p->af_cap[afi][safi],
8580 PEER_CAP_ORF_PREFIX_SM_RCV)
8581 || CHECK_FLAG(p->af_cap[afi][safi],
8582 PEER_CAP_ORF_PREFIX_RM_ADV)
8583 || CHECK_FLAG(p->af_cap[afi][safi],
8584 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8585 json_object_int_add(json_af, "orfType",
8586 ORF_TYPE_PREFIX);
8587 json_prefA = json_object_new_object();
8588 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8589 PEER_CAP_ORF_PREFIX_SM_ADV,
8590 PEER_CAP_ORF_PREFIX_RM_ADV,
8591 PEER_CAP_ORF_PREFIX_SM_RCV,
8592 PEER_CAP_ORF_PREFIX_RM_RCV,
8593 use_json, json_prefA);
8594 json_object_object_add(json_af, "orfPrefixList",
8595 json_prefA);
8596 }
8597
8598 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8599 || CHECK_FLAG(p->af_cap[afi][safi],
8600 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8601 || CHECK_FLAG(p->af_cap[afi][safi],
8602 PEER_CAP_ORF_PREFIX_RM_ADV)
8603 || CHECK_FLAG(p->af_cap[afi][safi],
8604 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8605 json_object_int_add(json_af, "orfOldType",
8606 ORF_TYPE_PREFIX_OLD);
8607 json_prefB = json_object_new_object();
8608 bgp_show_peer_afi_orf_cap(
8609 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8610 PEER_CAP_ORF_PREFIX_RM_ADV,
8611 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8612 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8613 json_prefB);
8614 json_object_object_add(json_af, "orfOldPrefixList",
8615 json_prefB);
8616 }
8617
8618 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8619 || CHECK_FLAG(p->af_cap[afi][safi],
8620 PEER_CAP_ORF_PREFIX_SM_RCV)
8621 || CHECK_FLAG(p->af_cap[afi][safi],
8622 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8623 || CHECK_FLAG(p->af_cap[afi][safi],
8624 PEER_CAP_ORF_PREFIX_RM_ADV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_RM_RCV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8629 json_object_object_add(json_addr, "afDependentCap",
8630 json_af);
8631 else
8632 json_object_free(json_af);
8633
8634 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8635 orf_pfx_count = prefix_bgp_show_prefix_list(
8636 NULL, afi, orf_pfx_name, use_json);
8637
8638 if (CHECK_FLAG(p->af_sflags[afi][safi],
8639 PEER_STATUS_ORF_PREFIX_SEND)
8640 || orf_pfx_count) {
8641 if (CHECK_FLAG(p->af_sflags[afi][safi],
8642 PEER_STATUS_ORF_PREFIX_SEND))
8643 json_object_boolean_true_add(json_neigh,
8644 "orfSent");
8645 if (orf_pfx_count)
8646 json_object_int_add(json_addr, "orfRecvCounter",
8647 orf_pfx_count);
8648 }
8649 if (CHECK_FLAG(p->af_sflags[afi][safi],
8650 PEER_STATUS_ORF_WAIT_REFRESH))
8651 json_object_string_add(
8652 json_addr, "orfFirstUpdate",
8653 "deferredUntilORFOrRouteRefreshRecvd");
8654
8655 if (CHECK_FLAG(p->af_flags[afi][safi],
8656 PEER_FLAG_REFLECTOR_CLIENT))
8657 json_object_boolean_true_add(json_addr,
8658 "routeReflectorClient");
8659 if (CHECK_FLAG(p->af_flags[afi][safi],
8660 PEER_FLAG_RSERVER_CLIENT))
8661 json_object_boolean_true_add(json_addr,
8662 "routeServerClient");
8663 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8664 json_object_boolean_true_add(json_addr,
8665 "inboundSoftConfigPermit");
8666
8667 if (CHECK_FLAG(p->af_flags[afi][safi],
8668 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8669 json_object_boolean_true_add(
8670 json_addr,
8671 "privateAsNumsAllReplacedInUpdatesToNbr");
8672 else if (CHECK_FLAG(p->af_flags[afi][safi],
8673 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8674 json_object_boolean_true_add(
8675 json_addr,
8676 "privateAsNumsReplacedInUpdatesToNbr");
8677 else if (CHECK_FLAG(p->af_flags[afi][safi],
8678 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8679 json_object_boolean_true_add(
8680 json_addr,
8681 "privateAsNumsAllRemovedInUpdatesToNbr");
8682 else if (CHECK_FLAG(p->af_flags[afi][safi],
8683 PEER_FLAG_REMOVE_PRIVATE_AS))
8684 json_object_boolean_true_add(
8685 json_addr,
8686 "privateAsNumsRemovedInUpdatesToNbr");
8687
8688 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8689 json_object_boolean_true_add(
8690 json_addr,
8691 bgp_addpath_names(p->addpath_type[afi][safi])
8692 ->type_json_name);
8693
8694 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8695 json_object_string_add(json_addr,
8696 "overrideASNsInOutboundUpdates",
8697 "ifAspathEqualRemoteAs");
8698
8699 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8700 || CHECK_FLAG(p->af_flags[afi][safi],
8701 PEER_FLAG_FORCE_NEXTHOP_SELF))
8702 json_object_boolean_true_add(json_addr,
8703 "routerAlwaysNextHop");
8704 if (CHECK_FLAG(p->af_flags[afi][safi],
8705 PEER_FLAG_AS_PATH_UNCHANGED))
8706 json_object_boolean_true_add(
8707 json_addr, "unchangedAsPathPropogatedToNbr");
8708 if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_NEXTHOP_UNCHANGED))
8710 json_object_boolean_true_add(
8711 json_addr, "unchangedNextHopPropogatedToNbr");
8712 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8713 json_object_boolean_true_add(
8714 json_addr, "unchangedMedPropogatedToNbr");
8715 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8716 || CHECK_FLAG(p->af_flags[afi][safi],
8717 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8718 if (CHECK_FLAG(p->af_flags[afi][safi],
8719 PEER_FLAG_SEND_COMMUNITY)
8720 && CHECK_FLAG(p->af_flags[afi][safi],
8721 PEER_FLAG_SEND_EXT_COMMUNITY))
8722 json_object_string_add(json_addr,
8723 "commAttriSentToNbr",
8724 "extendedAndStandard");
8725 else if (CHECK_FLAG(p->af_flags[afi][safi],
8726 PEER_FLAG_SEND_EXT_COMMUNITY))
8727 json_object_string_add(json_addr,
8728 "commAttriSentToNbr",
8729 "extended");
8730 else
8731 json_object_string_add(json_addr,
8732 "commAttriSentToNbr",
8733 "standard");
8734 }
8735 if (CHECK_FLAG(p->af_flags[afi][safi],
8736 PEER_FLAG_DEFAULT_ORIGINATE)) {
8737 if (p->default_rmap[afi][safi].name)
8738 json_object_string_add(
8739 json_addr, "defaultRouteMap",
8740 p->default_rmap[afi][safi].name);
8741
8742 if (paf && PAF_SUBGRP(paf)
8743 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8744 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8745 json_object_boolean_true_add(json_addr,
8746 "defaultSent");
8747 else
8748 json_object_boolean_true_add(json_addr,
8749 "defaultNotSent");
8750 }
8751
8752 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8753 if (is_evpn_enabled())
8754 json_object_boolean_true_add(
8755 json_addr, "advertiseAllVnis");
8756 }
8757
8758 if (filter->plist[FILTER_IN].name
8759 || filter->dlist[FILTER_IN].name
8760 || filter->aslist[FILTER_IN].name
8761 || filter->map[RMAP_IN].name)
8762 json_object_boolean_true_add(json_addr,
8763 "inboundPathPolicyConfig");
8764 if (filter->plist[FILTER_OUT].name
8765 || filter->dlist[FILTER_OUT].name
8766 || filter->aslist[FILTER_OUT].name
8767 || filter->map[RMAP_OUT].name || filter->usmap.name)
8768 json_object_boolean_true_add(
8769 json_addr, "outboundPathPolicyConfig");
8770
8771 /* prefix-list */
8772 if (filter->plist[FILTER_IN].name)
8773 json_object_string_add(json_addr,
8774 "incomingUpdatePrefixFilterList",
8775 filter->plist[FILTER_IN].name);
8776 if (filter->plist[FILTER_OUT].name)
8777 json_object_string_add(json_addr,
8778 "outgoingUpdatePrefixFilterList",
8779 filter->plist[FILTER_OUT].name);
8780
8781 /* distribute-list */
8782 if (filter->dlist[FILTER_IN].name)
8783 json_object_string_add(
8784 json_addr, "incomingUpdateNetworkFilterList",
8785 filter->dlist[FILTER_IN].name);
8786 if (filter->dlist[FILTER_OUT].name)
8787 json_object_string_add(
8788 json_addr, "outgoingUpdateNetworkFilterList",
8789 filter->dlist[FILTER_OUT].name);
8790
8791 /* filter-list. */
8792 if (filter->aslist[FILTER_IN].name)
8793 json_object_string_add(json_addr,
8794 "incomingUpdateAsPathFilterList",
8795 filter->aslist[FILTER_IN].name);
8796 if (filter->aslist[FILTER_OUT].name)
8797 json_object_string_add(json_addr,
8798 "outgoingUpdateAsPathFilterList",
8799 filter->aslist[FILTER_OUT].name);
8800
8801 /* route-map. */
8802 if (filter->map[RMAP_IN].name)
8803 json_object_string_add(
8804 json_addr, "routeMapForIncomingAdvertisements",
8805 filter->map[RMAP_IN].name);
8806 if (filter->map[RMAP_OUT].name)
8807 json_object_string_add(
8808 json_addr, "routeMapForOutgoingAdvertisements",
8809 filter->map[RMAP_OUT].name);
8810
8811 /* unsuppress-map */
8812 if (filter->usmap.name)
8813 json_object_string_add(json_addr,
8814 "selectiveUnsuppressRouteMap",
8815 filter->usmap.name);
8816
8817 /* Receive prefix count */
8818 json_object_int_add(json_addr, "acceptedPrefixCounter",
8819 p->pcount[afi][safi]);
8820 if (paf && PAF_SUBGRP(paf))
8821 json_object_int_add(json_addr, "sentPrefixCounter",
8822 (PAF_SUBGRP(paf))->scount);
8823
8824 /* Maximum prefix */
8825 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8826 json_object_int_add(json_addr, "prefixAllowedMax",
8827 p->pmax[afi][safi]);
8828 if (CHECK_FLAG(p->af_flags[afi][safi],
8829 PEER_FLAG_MAX_PREFIX_WARNING))
8830 json_object_boolean_true_add(
8831 json_addr, "prefixAllowedMaxWarning");
8832 json_object_int_add(json_addr,
8833 "prefixAllowedWarningThresh",
8834 p->pmax_threshold[afi][safi]);
8835 if (p->pmax_restart[afi][safi])
8836 json_object_int_add(
8837 json_addr,
8838 "prefixAllowedRestartIntervalMsecs",
8839 p->pmax_restart[afi][safi] * 60000);
8840 }
8841 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8842 json_addr);
8843
8844 } else {
8845 filter = &p->filter[afi][safi];
8846
8847 vty_out(vty, " For address family: %s\n",
8848 afi_safi_print(afi, safi));
8849
8850 if (peer_group_active(p))
8851 vty_out(vty, " %s peer-group member\n",
8852 p->group->name);
8853
8854 paf = peer_af_find(p, afi, safi);
8855 if (paf && PAF_SUBGRP(paf)) {
8856 vty_out(vty, " Update group %" PRIu64
8857 ", subgroup %" PRIu64 "\n",
8858 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8859 vty_out(vty, " Packet Queue length %d\n",
8860 bpacket_queue_virtual_length(paf));
8861 } else {
8862 vty_out(vty, " Not part of any update group\n");
8863 }
8864 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8865 || CHECK_FLAG(p->af_cap[afi][safi],
8866 PEER_CAP_ORF_PREFIX_SM_RCV)
8867 || CHECK_FLAG(p->af_cap[afi][safi],
8868 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8869 || CHECK_FLAG(p->af_cap[afi][safi],
8870 PEER_CAP_ORF_PREFIX_RM_ADV)
8871 || CHECK_FLAG(p->af_cap[afi][safi],
8872 PEER_CAP_ORF_PREFIX_RM_RCV)
8873 || CHECK_FLAG(p->af_cap[afi][safi],
8874 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8875 vty_out(vty, " AF-dependant capabilities:\n");
8876
8877 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8878 || CHECK_FLAG(p->af_cap[afi][safi],
8879 PEER_CAP_ORF_PREFIX_SM_RCV)
8880 || CHECK_FLAG(p->af_cap[afi][safi],
8881 PEER_CAP_ORF_PREFIX_RM_ADV)
8882 || CHECK_FLAG(p->af_cap[afi][safi],
8883 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8884 vty_out(vty,
8885 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8886 ORF_TYPE_PREFIX);
8887 bgp_show_peer_afi_orf_cap(
8888 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8889 PEER_CAP_ORF_PREFIX_RM_ADV,
8890 PEER_CAP_ORF_PREFIX_SM_RCV,
8891 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8892 }
8893 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8894 || CHECK_FLAG(p->af_cap[afi][safi],
8895 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8896 || CHECK_FLAG(p->af_cap[afi][safi],
8897 PEER_CAP_ORF_PREFIX_RM_ADV)
8898 || CHECK_FLAG(p->af_cap[afi][safi],
8899 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8900 vty_out(vty,
8901 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8902 ORF_TYPE_PREFIX_OLD);
8903 bgp_show_peer_afi_orf_cap(
8904 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8905 PEER_CAP_ORF_PREFIX_RM_ADV,
8906 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8907 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8908 }
8909
8910 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8911 orf_pfx_count = prefix_bgp_show_prefix_list(
8912 NULL, afi, orf_pfx_name, use_json);
8913
8914 if (CHECK_FLAG(p->af_sflags[afi][safi],
8915 PEER_STATUS_ORF_PREFIX_SEND)
8916 || orf_pfx_count) {
8917 vty_out(vty, " Outbound Route Filter (ORF):");
8918 if (CHECK_FLAG(p->af_sflags[afi][safi],
8919 PEER_STATUS_ORF_PREFIX_SEND))
8920 vty_out(vty, " sent;");
8921 if (orf_pfx_count)
8922 vty_out(vty, " received (%d entries)",
8923 orf_pfx_count);
8924 vty_out(vty, "\n");
8925 }
8926 if (CHECK_FLAG(p->af_sflags[afi][safi],
8927 PEER_STATUS_ORF_WAIT_REFRESH))
8928 vty_out(vty,
8929 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8930
8931 if (CHECK_FLAG(p->af_flags[afi][safi],
8932 PEER_FLAG_REFLECTOR_CLIENT))
8933 vty_out(vty, " Route-Reflector Client\n");
8934 if (CHECK_FLAG(p->af_flags[afi][safi],
8935 PEER_FLAG_RSERVER_CLIENT))
8936 vty_out(vty, " Route-Server Client\n");
8937 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8938 vty_out(vty,
8939 " Inbound soft reconfiguration allowed\n");
8940
8941 if (CHECK_FLAG(p->af_flags[afi][safi],
8942 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8943 vty_out(vty,
8944 " Private AS numbers (all) replaced in updates to this neighbor\n");
8945 else if (CHECK_FLAG(p->af_flags[afi][safi],
8946 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8947 vty_out(vty,
8948 " Private AS numbers replaced in updates to this neighbor\n");
8949 else if (CHECK_FLAG(p->af_flags[afi][safi],
8950 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8951 vty_out(vty,
8952 " Private AS numbers (all) removed in updates to this neighbor\n");
8953 else if (CHECK_FLAG(p->af_flags[afi][safi],
8954 PEER_FLAG_REMOVE_PRIVATE_AS))
8955 vty_out(vty,
8956 " Private AS numbers removed in updates to this neighbor\n");
8957
8958 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8959 vty_out(vty, " %s\n",
8960 bgp_addpath_names(p->addpath_type[afi][safi])
8961 ->human_description);
8962
8963 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8964 vty_out(vty,
8965 " Override ASNs in outbound updates if aspath equals remote-as\n");
8966
8967 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8968 || CHECK_FLAG(p->af_flags[afi][safi],
8969 PEER_FLAG_FORCE_NEXTHOP_SELF))
8970 vty_out(vty, " NEXT_HOP is always this router\n");
8971 if (CHECK_FLAG(p->af_flags[afi][safi],
8972 PEER_FLAG_AS_PATH_UNCHANGED))
8973 vty_out(vty,
8974 " AS_PATH is propagated unchanged to this neighbor\n");
8975 if (CHECK_FLAG(p->af_flags[afi][safi],
8976 PEER_FLAG_NEXTHOP_UNCHANGED))
8977 vty_out(vty,
8978 " NEXT_HOP is propagated unchanged to this neighbor\n");
8979 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8980 vty_out(vty,
8981 " MED is propagated unchanged to this neighbor\n");
8982 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8983 || CHECK_FLAG(p->af_flags[afi][safi],
8984 PEER_FLAG_SEND_EXT_COMMUNITY)
8985 || CHECK_FLAG(p->af_flags[afi][safi],
8986 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8987 vty_out(vty,
8988 " Community attribute sent to this neighbor");
8989 if (CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_SEND_COMMUNITY)
8991 && CHECK_FLAG(p->af_flags[afi][safi],
8992 PEER_FLAG_SEND_EXT_COMMUNITY)
8993 && CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_SEND_LARGE_COMMUNITY))
8995 vty_out(vty, "(all)\n");
8996 else if (CHECK_FLAG(p->af_flags[afi][safi],
8997 PEER_FLAG_SEND_LARGE_COMMUNITY))
8998 vty_out(vty, "(large)\n");
8999 else if (CHECK_FLAG(p->af_flags[afi][safi],
9000 PEER_FLAG_SEND_EXT_COMMUNITY))
9001 vty_out(vty, "(extended)\n");
9002 else
9003 vty_out(vty, "(standard)\n");
9004 }
9005 if (CHECK_FLAG(p->af_flags[afi][safi],
9006 PEER_FLAG_DEFAULT_ORIGINATE)) {
9007 vty_out(vty, " Default information originate,");
9008
9009 if (p->default_rmap[afi][safi].name)
9010 vty_out(vty, " default route-map %s%s,",
9011 p->default_rmap[afi][safi].map ? "*"
9012 : "",
9013 p->default_rmap[afi][safi].name);
9014 if (paf && PAF_SUBGRP(paf)
9015 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9016 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9017 vty_out(vty, " default sent\n");
9018 else
9019 vty_out(vty, " default not sent\n");
9020 }
9021
9022 /* advertise-vni-all */
9023 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9024 if (is_evpn_enabled())
9025 vty_out(vty, " advertise-all-vni\n");
9026 }
9027
9028 if (filter->plist[FILTER_IN].name
9029 || filter->dlist[FILTER_IN].name
9030 || filter->aslist[FILTER_IN].name
9031 || filter->map[RMAP_IN].name)
9032 vty_out(vty, " Inbound path policy configured\n");
9033 if (filter->plist[FILTER_OUT].name
9034 || filter->dlist[FILTER_OUT].name
9035 || filter->aslist[FILTER_OUT].name
9036 || filter->map[RMAP_OUT].name || filter->usmap.name)
9037 vty_out(vty, " Outbound path policy configured\n");
9038
9039 /* prefix-list */
9040 if (filter->plist[FILTER_IN].name)
9041 vty_out(vty,
9042 " Incoming update prefix filter list is %s%s\n",
9043 filter->plist[FILTER_IN].plist ? "*" : "",
9044 filter->plist[FILTER_IN].name);
9045 if (filter->plist[FILTER_OUT].name)
9046 vty_out(vty,
9047 " Outgoing update prefix filter list is %s%s\n",
9048 filter->plist[FILTER_OUT].plist ? "*" : "",
9049 filter->plist[FILTER_OUT].name);
9050
9051 /* distribute-list */
9052 if (filter->dlist[FILTER_IN].name)
9053 vty_out(vty,
9054 " Incoming update network filter list is %s%s\n",
9055 filter->dlist[FILTER_IN].alist ? "*" : "",
9056 filter->dlist[FILTER_IN].name);
9057 if (filter->dlist[FILTER_OUT].name)
9058 vty_out(vty,
9059 " Outgoing update network filter list is %s%s\n",
9060 filter->dlist[FILTER_OUT].alist ? "*" : "",
9061 filter->dlist[FILTER_OUT].name);
9062
9063 /* filter-list. */
9064 if (filter->aslist[FILTER_IN].name)
9065 vty_out(vty,
9066 " Incoming update AS path filter list is %s%s\n",
9067 filter->aslist[FILTER_IN].aslist ? "*" : "",
9068 filter->aslist[FILTER_IN].name);
9069 if (filter->aslist[FILTER_OUT].name)
9070 vty_out(vty,
9071 " Outgoing update AS path filter list is %s%s\n",
9072 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9073 filter->aslist[FILTER_OUT].name);
9074
9075 /* route-map. */
9076 if (filter->map[RMAP_IN].name)
9077 vty_out(vty,
9078 " Route map for incoming advertisements is %s%s\n",
9079 filter->map[RMAP_IN].map ? "*" : "",
9080 filter->map[RMAP_IN].name);
9081 if (filter->map[RMAP_OUT].name)
9082 vty_out(vty,
9083 " Route map for outgoing advertisements is %s%s\n",
9084 filter->map[RMAP_OUT].map ? "*" : "",
9085 filter->map[RMAP_OUT].name);
9086
9087 /* unsuppress-map */
9088 if (filter->usmap.name)
9089 vty_out(vty,
9090 " Route map for selective unsuppress is %s%s\n",
9091 filter->usmap.map ? "*" : "",
9092 filter->usmap.name);
9093
9094 /* Receive prefix count */
9095 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9096
9097 /* Maximum prefix */
9098 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9099 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9100 p->pmax[afi][safi],
9101 CHECK_FLAG(p->af_flags[afi][safi],
9102 PEER_FLAG_MAX_PREFIX_WARNING)
9103 ? " (warning-only)"
9104 : "");
9105 vty_out(vty, " Threshold for warning message %d%%",
9106 p->pmax_threshold[afi][safi]);
9107 if (p->pmax_restart[afi][safi])
9108 vty_out(vty, ", restart interval %d min",
9109 p->pmax_restart[afi][safi]);
9110 vty_out(vty, "\n");
9111 }
9112
9113 vty_out(vty, "\n");
9114 }
9115 }
9116
9117 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9118 json_object *json)
9119 {
9120 struct bgp *bgp;
9121 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9122 char timebuf[BGP_UPTIME_LEN];
9123 char dn_flag[2];
9124 const char *subcode_str;
9125 const char *code_str;
9126 afi_t afi;
9127 safi_t safi;
9128 uint16_t i;
9129 uint8_t *msg;
9130 json_object *json_neigh = NULL;
9131 time_t epoch_tbuf;
9132
9133 bgp = p->bgp;
9134
9135 if (use_json)
9136 json_neigh = json_object_new_object();
9137
9138 memset(dn_flag, '\0', sizeof(dn_flag));
9139 if (!p->conf_if && peer_dynamic_neighbor(p))
9140 dn_flag[0] = '*';
9141
9142 if (!use_json) {
9143 if (p->conf_if) /* Configured interface name. */
9144 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9145 BGP_PEER_SU_UNSPEC(p)
9146 ? "None"
9147 : sockunion2str(&p->su, buf,
9148 SU_ADDRSTRLEN));
9149 else /* Configured IP address. */
9150 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9151 p->host);
9152 }
9153
9154 if (use_json) {
9155 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9156 json_object_string_add(json_neigh, "bgpNeighborAddr",
9157 "none");
9158 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9159 json_object_string_add(
9160 json_neigh, "bgpNeighborAddr",
9161 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9162
9163 json_object_int_add(json_neigh, "remoteAs", p->as);
9164
9165 if (p->change_local_as)
9166 json_object_int_add(json_neigh, "localAs",
9167 p->change_local_as);
9168 else
9169 json_object_int_add(json_neigh, "localAs", p->local_as);
9170
9171 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9172 json_object_boolean_true_add(json_neigh,
9173 "localAsNoPrepend");
9174
9175 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9176 json_object_boolean_true_add(json_neigh,
9177 "localAsReplaceAs");
9178 } else {
9179 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9180 || (p->as_type == AS_INTERNAL))
9181 vty_out(vty, "remote AS %u, ", p->as);
9182 else
9183 vty_out(vty, "remote AS Unspecified, ");
9184 vty_out(vty, "local AS %u%s%s, ",
9185 p->change_local_as ? p->change_local_as : p->local_as,
9186 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9187 ? " no-prepend"
9188 : "",
9189 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9190 ? " replace-as"
9191 : "");
9192 }
9193 /* peer type internal, external, confed-internal or confed-external */
9194 if (p->as == p->local_as) {
9195 if (use_json) {
9196 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9197 json_object_boolean_true_add(
9198 json_neigh, "nbrConfedInternalLink");
9199 else
9200 json_object_boolean_true_add(json_neigh,
9201 "nbrInternalLink");
9202 } else {
9203 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9204 vty_out(vty, "confed-internal link\n");
9205 else
9206 vty_out(vty, "internal link\n");
9207 }
9208 } else {
9209 if (use_json) {
9210 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9211 json_object_boolean_true_add(
9212 json_neigh, "nbrConfedExternalLink");
9213 else
9214 json_object_boolean_true_add(json_neigh,
9215 "nbrExternalLink");
9216 } else {
9217 if (bgp_confederation_peers_check(bgp, p->as))
9218 vty_out(vty, "confed-external link\n");
9219 else
9220 vty_out(vty, "external link\n");
9221 }
9222 }
9223
9224 /* Description. */
9225 if (p->desc) {
9226 if (use_json)
9227 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9228 else
9229 vty_out(vty, " Description: %s\n", p->desc);
9230 }
9231
9232 if (p->hostname) {
9233 if (use_json) {
9234 if (p->hostname)
9235 json_object_string_add(json_neigh, "hostname",
9236 p->hostname);
9237
9238 if (p->domainname)
9239 json_object_string_add(json_neigh, "domainname",
9240 p->domainname);
9241 } else {
9242 if (p->domainname && (p->domainname[0] != '\0'))
9243 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9244 p->domainname);
9245 else
9246 vty_out(vty, "Hostname: %s\n", p->hostname);
9247 }
9248 }
9249
9250 /* Peer-group */
9251 if (p->group) {
9252 if (use_json) {
9253 json_object_string_add(json_neigh, "peerGroup",
9254 p->group->name);
9255
9256 if (dn_flag[0]) {
9257 struct prefix prefix, *range = NULL;
9258
9259 sockunion2hostprefix(&(p->su), &prefix);
9260 range = peer_group_lookup_dynamic_neighbor_range(
9261 p->group, &prefix);
9262
9263 if (range) {
9264 prefix2str(range, buf1, sizeof(buf1));
9265 json_object_string_add(
9266 json_neigh,
9267 "peerSubnetRangeGroup", buf1);
9268 }
9269 }
9270 } else {
9271 vty_out(vty,
9272 " Member of peer-group %s for session parameters\n",
9273 p->group->name);
9274
9275 if (dn_flag[0]) {
9276 struct prefix prefix, *range = NULL;
9277
9278 sockunion2hostprefix(&(p->su), &prefix);
9279 range = peer_group_lookup_dynamic_neighbor_range(
9280 p->group, &prefix);
9281
9282 if (range) {
9283 prefix2str(range, buf1, sizeof(buf1));
9284 vty_out(vty,
9285 " Belongs to the subnet range group: %s\n",
9286 buf1);
9287 }
9288 }
9289 }
9290 }
9291
9292 if (use_json) {
9293 /* Administrative shutdown. */
9294 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9295 json_object_boolean_true_add(json_neigh,
9296 "adminShutDown");
9297
9298 /* BGP Version. */
9299 json_object_int_add(json_neigh, "bgpVersion", 4);
9300 json_object_string_add(
9301 json_neigh, "remoteRouterId",
9302 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9303 json_object_string_add(
9304 json_neigh, "localRouterId",
9305 inet_ntop(AF_INET, &bgp->router_id, buf1,
9306 sizeof(buf1)));
9307
9308 /* Confederation */
9309 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9310 && bgp_confederation_peers_check(bgp, p->as))
9311 json_object_boolean_true_add(json_neigh,
9312 "nbrCommonAdmin");
9313
9314 /* Status. */
9315 json_object_string_add(
9316 json_neigh, "bgpState",
9317 lookup_msg(bgp_status_msg, p->status, NULL));
9318
9319 if (p->status == Established) {
9320 time_t uptime;
9321
9322 uptime = bgp_clock();
9323 uptime -= p->uptime;
9324 epoch_tbuf = time(NULL) - uptime;
9325
9326 #if CONFDATE > 20200101
9327 CPP_NOTICE(
9328 "bgpTimerUp should be deprecated and can be removed now");
9329 #endif
9330 /*
9331 * bgpTimerUp was miliseconds that was accurate
9332 * up to 1 day, then the value returned
9333 * became garbage. So in order to provide
9334 * some level of backwards compatability,
9335 * we still provde the data, but now
9336 * we are returning the correct value
9337 * and also adding a new bgpTimerUpMsec
9338 * which will allow us to deprecate
9339 * this eventually
9340 */
9341 json_object_int_add(json_neigh, "bgpTimerUp",
9342 uptime * 1000);
9343 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9344 uptime * 1000);
9345 json_object_string_add(json_neigh, "bgpTimerUpString",
9346 peer_uptime(p->uptime, timebuf,
9347 BGP_UPTIME_LEN, 0,
9348 NULL));
9349 json_object_int_add(json_neigh,
9350 "bgpTimerUpEstablishedEpoch",
9351 epoch_tbuf);
9352 }
9353
9354 else if (p->status == Active) {
9355 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9356 json_object_string_add(json_neigh, "bgpStateIs",
9357 "passive");
9358 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9359 json_object_string_add(json_neigh, "bgpStateIs",
9360 "passiveNSF");
9361 }
9362
9363 /* read timer */
9364 time_t uptime;
9365 struct tm *tm;
9366
9367 uptime = bgp_clock();
9368 uptime -= p->readtime;
9369 tm = gmtime(&uptime);
9370 json_object_int_add(json_neigh, "bgpTimerLastRead",
9371 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9372 + (tm->tm_hour * 3600000));
9373
9374 uptime = bgp_clock();
9375 uptime -= p->last_write;
9376 tm = gmtime(&uptime);
9377 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9378 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9379 + (tm->tm_hour * 3600000));
9380
9381 uptime = bgp_clock();
9382 uptime -= p->update_time;
9383 tm = gmtime(&uptime);
9384 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9385 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9386 + (tm->tm_hour * 3600000));
9387
9388 /* Configured timer values. */
9389 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9390 p->v_holdtime * 1000);
9391 json_object_int_add(json_neigh,
9392 "bgpTimerKeepAliveIntervalMsecs",
9393 p->v_keepalive * 1000);
9394 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9395 json_object_int_add(json_neigh,
9396 "bgpTimerConfiguredHoldTimeMsecs",
9397 p->holdtime * 1000);
9398 json_object_int_add(
9399 json_neigh,
9400 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9401 p->keepalive * 1000);
9402 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9403 || (bgp->default_keepalive
9404 != BGP_DEFAULT_KEEPALIVE)) {
9405 json_object_int_add(json_neigh,
9406 "bgpTimerConfiguredHoldTimeMsecs",
9407 bgp->default_holdtime);
9408 json_object_int_add(
9409 json_neigh,
9410 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9411 bgp->default_keepalive);
9412 }
9413 } else {
9414 /* Administrative shutdown. */
9415 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9416 vty_out(vty, " Administratively shut down\n");
9417
9418 /* BGP Version. */
9419 vty_out(vty, " BGP version 4");
9420 vty_out(vty, ", remote router ID %s",
9421 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9422 vty_out(vty, ", local router ID %s\n",
9423 inet_ntop(AF_INET, &bgp->router_id, buf1,
9424 sizeof(buf1)));
9425
9426 /* Confederation */
9427 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9428 && bgp_confederation_peers_check(bgp, p->as))
9429 vty_out(vty,
9430 " Neighbor under common administration\n");
9431
9432 /* Status. */
9433 vty_out(vty, " BGP state = %s",
9434 lookup_msg(bgp_status_msg, p->status, NULL));
9435
9436 if (p->status == Established)
9437 vty_out(vty, ", up for %8s",
9438 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9439 0, NULL));
9440
9441 else if (p->status == Active) {
9442 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9443 vty_out(vty, " (passive)");
9444 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9445 vty_out(vty, " (NSF passive)");
9446 }
9447 vty_out(vty, "\n");
9448
9449 /* read timer */
9450 vty_out(vty, " Last read %s",
9451 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9452 NULL));
9453 vty_out(vty, ", Last write %s\n",
9454 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9455 NULL));
9456
9457 /* Configured timer values. */
9458 vty_out(vty,
9459 " Hold time is %d, keepalive interval is %d seconds\n",
9460 p->v_holdtime, p->v_keepalive);
9461 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9462 vty_out(vty, " Configured hold time is %d",
9463 p->holdtime);
9464 vty_out(vty, ", keepalive interval is %d seconds\n",
9465 p->keepalive);
9466 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9467 || (bgp->default_keepalive
9468 != BGP_DEFAULT_KEEPALIVE)) {
9469 vty_out(vty, " Configured hold time is %d",
9470 bgp->default_holdtime);
9471 vty_out(vty, ", keepalive interval is %d seconds\n",
9472 bgp->default_keepalive);
9473 }
9474 }
9475 /* Capability. */
9476 if (p->status == Established) {
9477 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9478 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9479 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9480 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9481 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9482 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9483 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9484 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9485 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9486 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9487 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9488 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9489 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9490 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9491 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9492 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9493 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9494 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9495 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9496 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9497 if (use_json) {
9498 json_object *json_cap = NULL;
9499
9500 json_cap = json_object_new_object();
9501
9502 /* AS4 */
9503 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9504 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9505 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9506 && CHECK_FLAG(p->cap,
9507 PEER_CAP_AS4_RCV))
9508 json_object_string_add(
9509 json_cap, "4byteAs",
9510 "advertisedAndReceived");
9511 else if (CHECK_FLAG(p->cap,
9512 PEER_CAP_AS4_ADV))
9513 json_object_string_add(
9514 json_cap, "4byteAs",
9515 "advertised");
9516 else if (CHECK_FLAG(p->cap,
9517 PEER_CAP_AS4_RCV))
9518 json_object_string_add(
9519 json_cap, "4byteAs",
9520 "received");
9521 }
9522
9523 /* AddPath */
9524 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9525 || CHECK_FLAG(p->cap,
9526 PEER_CAP_ADDPATH_ADV)) {
9527 json_object *json_add = NULL;
9528 const char *print_store;
9529
9530 json_add = json_object_new_object();
9531
9532 FOREACH_AFI_SAFI (afi, safi) {
9533 json_object *json_sub = NULL;
9534 json_sub =
9535 json_object_new_object();
9536 print_store = afi_safi_print(
9537 afi, safi);
9538
9539 if (CHECK_FLAG(
9540 p->af_cap[afi]
9541 [safi],
9542 PEER_CAP_ADDPATH_AF_TX_ADV)
9543 || CHECK_FLAG(
9544 p->af_cap[afi]
9545 [safi],
9546 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9547 if (CHECK_FLAG(
9548 p->af_cap
9549 [afi]
9550 [safi],
9551 PEER_CAP_ADDPATH_AF_TX_ADV)
9552 && CHECK_FLAG(
9553 p->af_cap
9554 [afi]
9555 [safi],
9556 PEER_CAP_ADDPATH_AF_TX_RCV))
9557 json_object_boolean_true_add(
9558 json_sub,
9559 "txAdvertisedAndReceived");
9560 else if (
9561 CHECK_FLAG(
9562 p->af_cap
9563 [afi]
9564 [safi],
9565 PEER_CAP_ADDPATH_AF_TX_ADV))
9566 json_object_boolean_true_add(
9567 json_sub,
9568 "txAdvertised");
9569 else if (
9570 CHECK_FLAG(
9571 p->af_cap
9572 [afi]
9573 [safi],
9574 PEER_CAP_ADDPATH_AF_TX_RCV))
9575 json_object_boolean_true_add(
9576 json_sub,
9577 "txReceived");
9578 }
9579
9580 if (CHECK_FLAG(
9581 p->af_cap[afi]
9582 [safi],
9583 PEER_CAP_ADDPATH_AF_RX_ADV)
9584 || CHECK_FLAG(
9585 p->af_cap[afi]
9586 [safi],
9587 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9588 if (CHECK_FLAG(
9589 p->af_cap
9590 [afi]
9591 [safi],
9592 PEER_CAP_ADDPATH_AF_RX_ADV)
9593 && CHECK_FLAG(
9594 p->af_cap
9595 [afi]
9596 [safi],
9597 PEER_CAP_ADDPATH_AF_RX_RCV))
9598 json_object_boolean_true_add(
9599 json_sub,
9600 "rxAdvertisedAndReceived");
9601 else if (
9602 CHECK_FLAG(
9603 p->af_cap
9604 [afi]
9605 [safi],
9606 PEER_CAP_ADDPATH_AF_RX_ADV))
9607 json_object_boolean_true_add(
9608 json_sub,
9609 "rxAdvertised");
9610 else if (
9611 CHECK_FLAG(
9612 p->af_cap
9613 [afi]
9614 [safi],
9615 PEER_CAP_ADDPATH_AF_RX_RCV))
9616 json_object_boolean_true_add(
9617 json_sub,
9618 "rxReceived");
9619 }
9620
9621 if (CHECK_FLAG(
9622 p->af_cap[afi]
9623 [safi],
9624 PEER_CAP_ADDPATH_AF_TX_ADV)
9625 || CHECK_FLAG(
9626 p->af_cap[afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_TX_RCV)
9629 || CHECK_FLAG(
9630 p->af_cap[afi]
9631 [safi],
9632 PEER_CAP_ADDPATH_AF_RX_ADV)
9633 || CHECK_FLAG(
9634 p->af_cap[afi]
9635 [safi],
9636 PEER_CAP_ADDPATH_AF_RX_RCV))
9637 json_object_object_add(
9638 json_add,
9639 print_store,
9640 json_sub);
9641 else
9642 json_object_free(
9643 json_sub);
9644 }
9645
9646 json_object_object_add(
9647 json_cap, "addPath", json_add);
9648 }
9649
9650 /* Dynamic */
9651 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9652 || CHECK_FLAG(p->cap,
9653 PEER_CAP_DYNAMIC_ADV)) {
9654 if (CHECK_FLAG(p->cap,
9655 PEER_CAP_DYNAMIC_ADV)
9656 && CHECK_FLAG(p->cap,
9657 PEER_CAP_DYNAMIC_RCV))
9658 json_object_string_add(
9659 json_cap, "dynamic",
9660 "advertisedAndReceived");
9661 else if (CHECK_FLAG(
9662 p->cap,
9663 PEER_CAP_DYNAMIC_ADV))
9664 json_object_string_add(
9665 json_cap, "dynamic",
9666 "advertised");
9667 else if (CHECK_FLAG(
9668 p->cap,
9669 PEER_CAP_DYNAMIC_RCV))
9670 json_object_string_add(
9671 json_cap, "dynamic",
9672 "received");
9673 }
9674
9675 /* Extended nexthop */
9676 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9677 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9678 json_object *json_nxt = NULL;
9679 const char *print_store;
9680
9681
9682 if (CHECK_FLAG(p->cap,
9683 PEER_CAP_ENHE_ADV)
9684 && CHECK_FLAG(p->cap,
9685 PEER_CAP_ENHE_RCV))
9686 json_object_string_add(
9687 json_cap,
9688 "extendedNexthop",
9689 "advertisedAndReceived");
9690 else if (CHECK_FLAG(p->cap,
9691 PEER_CAP_ENHE_ADV))
9692 json_object_string_add(
9693 json_cap,
9694 "extendedNexthop",
9695 "advertised");
9696 else if (CHECK_FLAG(p->cap,
9697 PEER_CAP_ENHE_RCV))
9698 json_object_string_add(
9699 json_cap,
9700 "extendedNexthop",
9701 "received");
9702
9703 if (CHECK_FLAG(p->cap,
9704 PEER_CAP_ENHE_RCV)) {
9705 json_nxt =
9706 json_object_new_object();
9707
9708 for (safi = SAFI_UNICAST;
9709 safi < SAFI_MAX; safi++) {
9710 if (CHECK_FLAG(
9711 p->af_cap
9712 [AFI_IP]
9713 [safi],
9714 PEER_CAP_ENHE_AF_RCV)) {
9715 print_store = afi_safi_print(
9716 AFI_IP,
9717 safi);
9718 json_object_string_add(
9719 json_nxt,
9720 print_store,
9721 "received");
9722 }
9723 }
9724 json_object_object_add(
9725 json_cap,
9726 "extendedNexthopFamililesByPeer",
9727 json_nxt);
9728 }
9729 }
9730
9731 /* Route Refresh */
9732 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9733 || CHECK_FLAG(p->cap,
9734 PEER_CAP_REFRESH_NEW_RCV)
9735 || CHECK_FLAG(p->cap,
9736 PEER_CAP_REFRESH_OLD_RCV)) {
9737 if (CHECK_FLAG(p->cap,
9738 PEER_CAP_REFRESH_ADV)
9739 && (CHECK_FLAG(
9740 p->cap,
9741 PEER_CAP_REFRESH_NEW_RCV)
9742 || CHECK_FLAG(
9743 p->cap,
9744 PEER_CAP_REFRESH_OLD_RCV))) {
9745 if (CHECK_FLAG(
9746 p->cap,
9747 PEER_CAP_REFRESH_OLD_RCV)
9748 && CHECK_FLAG(
9749 p->cap,
9750 PEER_CAP_REFRESH_NEW_RCV))
9751 json_object_string_add(
9752 json_cap,
9753 "routeRefresh",
9754 "advertisedAndReceivedOldNew");
9755 else {
9756 if (CHECK_FLAG(
9757 p->cap,
9758 PEER_CAP_REFRESH_OLD_RCV))
9759 json_object_string_add(
9760 json_cap,
9761 "routeRefresh",
9762 "advertisedAndReceivedOld");
9763 else
9764 json_object_string_add(
9765 json_cap,
9766 "routeRefresh",
9767 "advertisedAndReceivedNew");
9768 }
9769 } else if (
9770 CHECK_FLAG(
9771 p->cap,
9772 PEER_CAP_REFRESH_ADV))
9773 json_object_string_add(
9774 json_cap,
9775 "routeRefresh",
9776 "advertised");
9777 else if (
9778 CHECK_FLAG(
9779 p->cap,
9780 PEER_CAP_REFRESH_NEW_RCV)
9781 || CHECK_FLAG(
9782 p->cap,
9783 PEER_CAP_REFRESH_OLD_RCV))
9784 json_object_string_add(
9785 json_cap,
9786 "routeRefresh",
9787 "received");
9788 }
9789
9790 /* Multiprotocol Extensions */
9791 json_object *json_multi = NULL;
9792 json_multi = json_object_new_object();
9793
9794 FOREACH_AFI_SAFI (afi, safi) {
9795 if (p->afc_adv[afi][safi]
9796 || p->afc_recv[afi][safi]) {
9797 json_object *json_exten = NULL;
9798 json_exten =
9799 json_object_new_object();
9800
9801 if (p->afc_adv[afi][safi]
9802 && p->afc_recv[afi][safi])
9803 json_object_boolean_true_add(
9804 json_exten,
9805 "advertisedAndReceived");
9806 else if (p->afc_adv[afi][safi])
9807 json_object_boolean_true_add(
9808 json_exten,
9809 "advertised");
9810 else if (p->afc_recv[afi][safi])
9811 json_object_boolean_true_add(
9812 json_exten,
9813 "received");
9814
9815 json_object_object_add(
9816 json_multi,
9817 afi_safi_print(afi,
9818 safi),
9819 json_exten);
9820 }
9821 }
9822 json_object_object_add(
9823 json_cap, "multiprotocolExtensions",
9824 json_multi);
9825
9826 /* Hostname capabilities */
9827 json_object *json_hname = NULL;
9828
9829 json_hname = json_object_new_object();
9830
9831 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9832 json_object_string_add(
9833 json_hname, "advHostName",
9834 bgp->peer_self->hostname
9835 ? bgp->peer_self
9836 ->hostname
9837 : "n/a");
9838 json_object_string_add(
9839 json_hname, "advDomainName",
9840 bgp->peer_self->domainname
9841 ? bgp->peer_self
9842 ->domainname
9843 : "n/a");
9844 }
9845
9846
9847 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9848 json_object_string_add(
9849 json_hname, "rcvHostName",
9850 p->hostname ? p->hostname
9851 : "n/a");
9852 json_object_string_add(
9853 json_hname, "rcvDomainName",
9854 p->domainname ? p->domainname
9855 : "n/a");
9856 }
9857
9858 json_object_object_add(json_cap, "hostName",
9859 json_hname);
9860
9861 /* Gracefull Restart */
9862 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9863 || CHECK_FLAG(p->cap,
9864 PEER_CAP_RESTART_ADV)) {
9865 if (CHECK_FLAG(p->cap,
9866 PEER_CAP_RESTART_ADV)
9867 && CHECK_FLAG(p->cap,
9868 PEER_CAP_RESTART_RCV))
9869 json_object_string_add(
9870 json_cap,
9871 "gracefulRestart",
9872 "advertisedAndReceived");
9873 else if (CHECK_FLAG(
9874 p->cap,
9875 PEER_CAP_RESTART_ADV))
9876 json_object_string_add(
9877 json_cap,
9878 "gracefulRestartCapability",
9879 "advertised");
9880 else if (CHECK_FLAG(
9881 p->cap,
9882 PEER_CAP_RESTART_RCV))
9883 json_object_string_add(
9884 json_cap,
9885 "gracefulRestartCapability",
9886 "received");
9887
9888 if (CHECK_FLAG(p->cap,
9889 PEER_CAP_RESTART_RCV)) {
9890 int restart_af_count = 0;
9891 json_object *json_restart =
9892 NULL;
9893 json_restart =
9894 json_object_new_object();
9895
9896 json_object_int_add(
9897 json_cap,
9898 "gracefulRestartRemoteTimerMsecs",
9899 p->v_gr_restart * 1000);
9900
9901 FOREACH_AFI_SAFI (afi, safi) {
9902 if (CHECK_FLAG(
9903 p->af_cap
9904 [afi]
9905 [safi],
9906 PEER_CAP_RESTART_AF_RCV)) {
9907 json_object *
9908 json_sub =
9909 NULL;
9910 json_sub =
9911 json_object_new_object();
9912
9913 if (CHECK_FLAG(
9914 p->af_cap
9915 [afi]
9916 [safi],
9917 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9918 json_object_boolean_true_add(
9919 json_sub,
9920 "preserved");
9921 restart_af_count++;
9922 json_object_object_add(
9923 json_restart,
9924 afi_safi_print(
9925 afi,
9926 safi),
9927 json_sub);
9928 }
9929 }
9930 if (!restart_af_count) {
9931 json_object_string_add(
9932 json_cap,
9933 "addressFamiliesByPeer",
9934 "none");
9935 json_object_free(
9936 json_restart);
9937 } else
9938 json_object_object_add(
9939 json_cap,
9940 "addressFamiliesByPeer",
9941 json_restart);
9942 }
9943 }
9944 json_object_object_add(json_neigh,
9945 "neighborCapabilities",
9946 json_cap);
9947 } else {
9948 vty_out(vty, " Neighbor capabilities:\n");
9949
9950 /* AS4 */
9951 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9952 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9953 vty_out(vty, " 4 Byte AS:");
9954 if (CHECK_FLAG(p->cap,
9955 PEER_CAP_AS4_ADV))
9956 vty_out(vty, " advertised");
9957 if (CHECK_FLAG(p->cap,
9958 PEER_CAP_AS4_RCV))
9959 vty_out(vty, " %sreceived",
9960 CHECK_FLAG(
9961 p->cap,
9962 PEER_CAP_AS4_ADV)
9963 ? "and "
9964 : "");
9965 vty_out(vty, "\n");
9966 }
9967
9968 /* AddPath */
9969 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9970 || CHECK_FLAG(p->cap,
9971 PEER_CAP_ADDPATH_ADV)) {
9972 vty_out(vty, " AddPath:\n");
9973
9974 FOREACH_AFI_SAFI (afi, safi) {
9975 if (CHECK_FLAG(
9976 p->af_cap[afi]
9977 [safi],
9978 PEER_CAP_ADDPATH_AF_TX_ADV)
9979 || CHECK_FLAG(
9980 p->af_cap[afi]
9981 [safi],
9982 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9983 vty_out(vty,
9984 " %s: TX ",
9985 afi_safi_print(
9986 afi,
9987 safi));
9988
9989 if (CHECK_FLAG(
9990 p->af_cap
9991 [afi]
9992 [safi],
9993 PEER_CAP_ADDPATH_AF_TX_ADV))
9994 vty_out(vty,
9995 "advertised %s",
9996 afi_safi_print(
9997 afi,
9998 safi));
9999
10000 if (CHECK_FLAG(
10001 p->af_cap
10002 [afi]
10003 [safi],
10004 PEER_CAP_ADDPATH_AF_TX_RCV))
10005 vty_out(vty,
10006 "%sreceived",
10007 CHECK_FLAG(
10008 p->af_cap
10009 [afi]
10010 [safi],
10011 PEER_CAP_ADDPATH_AF_TX_ADV)
10012 ? " and "
10013 : "");
10014
10015 vty_out(vty, "\n");
10016 }
10017
10018 if (CHECK_FLAG(
10019 p->af_cap[afi]
10020 [safi],
10021 PEER_CAP_ADDPATH_AF_RX_ADV)
10022 || CHECK_FLAG(
10023 p->af_cap[afi]
10024 [safi],
10025 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10026 vty_out(vty,
10027 " %s: RX ",
10028 afi_safi_print(
10029 afi,
10030 safi));
10031
10032 if (CHECK_FLAG(
10033 p->af_cap
10034 [afi]
10035 [safi],
10036 PEER_CAP_ADDPATH_AF_RX_ADV))
10037 vty_out(vty,
10038 "advertised %s",
10039 afi_safi_print(
10040 afi,
10041 safi));
10042
10043 if (CHECK_FLAG(
10044 p->af_cap
10045 [afi]
10046 [safi],
10047 PEER_CAP_ADDPATH_AF_RX_RCV))
10048 vty_out(vty,
10049 "%sreceived",
10050 CHECK_FLAG(
10051 p->af_cap
10052 [afi]
10053 [safi],
10054 PEER_CAP_ADDPATH_AF_RX_ADV)
10055 ? " and "
10056 : "");
10057
10058 vty_out(vty, "\n");
10059 }
10060 }
10061 }
10062
10063 /* Dynamic */
10064 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10065 || CHECK_FLAG(p->cap,
10066 PEER_CAP_DYNAMIC_ADV)) {
10067 vty_out(vty, " Dynamic:");
10068 if (CHECK_FLAG(p->cap,
10069 PEER_CAP_DYNAMIC_ADV))
10070 vty_out(vty, " advertised");
10071 if (CHECK_FLAG(p->cap,
10072 PEER_CAP_DYNAMIC_RCV))
10073 vty_out(vty, " %sreceived",
10074 CHECK_FLAG(
10075 p->cap,
10076 PEER_CAP_DYNAMIC_ADV)
10077 ? "and "
10078 : "");
10079 vty_out(vty, "\n");
10080 }
10081
10082 /* Extended nexthop */
10083 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10084 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10085 vty_out(vty, " Extended nexthop:");
10086 if (CHECK_FLAG(p->cap,
10087 PEER_CAP_ENHE_ADV))
10088 vty_out(vty, " advertised");
10089 if (CHECK_FLAG(p->cap,
10090 PEER_CAP_ENHE_RCV))
10091 vty_out(vty, " %sreceived",
10092 CHECK_FLAG(
10093 p->cap,
10094 PEER_CAP_ENHE_ADV)
10095 ? "and "
10096 : "");
10097 vty_out(vty, "\n");
10098
10099 if (CHECK_FLAG(p->cap,
10100 PEER_CAP_ENHE_RCV)) {
10101 vty_out(vty,
10102 " Address families by peer:\n ");
10103 for (safi = SAFI_UNICAST;
10104 safi < SAFI_MAX; safi++)
10105 if (CHECK_FLAG(
10106 p->af_cap
10107 [AFI_IP]
10108 [safi],
10109 PEER_CAP_ENHE_AF_RCV))
10110 vty_out(vty,
10111 " %s\n",
10112 afi_safi_print(
10113 AFI_IP,
10114 safi));
10115 }
10116 }
10117
10118 /* Route Refresh */
10119 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10120 || CHECK_FLAG(p->cap,
10121 PEER_CAP_REFRESH_NEW_RCV)
10122 || CHECK_FLAG(p->cap,
10123 PEER_CAP_REFRESH_OLD_RCV)) {
10124 vty_out(vty, " Route refresh:");
10125 if (CHECK_FLAG(p->cap,
10126 PEER_CAP_REFRESH_ADV))
10127 vty_out(vty, " advertised");
10128 if (CHECK_FLAG(p->cap,
10129 PEER_CAP_REFRESH_NEW_RCV)
10130 || CHECK_FLAG(
10131 p->cap,
10132 PEER_CAP_REFRESH_OLD_RCV))
10133 vty_out(vty, " %sreceived(%s)",
10134 CHECK_FLAG(
10135 p->cap,
10136 PEER_CAP_REFRESH_ADV)
10137 ? "and "
10138 : "",
10139 (CHECK_FLAG(
10140 p->cap,
10141 PEER_CAP_REFRESH_OLD_RCV)
10142 && CHECK_FLAG(
10143 p->cap,
10144 PEER_CAP_REFRESH_NEW_RCV))
10145 ? "old & new"
10146 : CHECK_FLAG(
10147 p->cap,
10148 PEER_CAP_REFRESH_OLD_RCV)
10149 ? "old"
10150 : "new");
10151
10152 vty_out(vty, "\n");
10153 }
10154
10155 /* Multiprotocol Extensions */
10156 FOREACH_AFI_SAFI (afi, safi)
10157 if (p->afc_adv[afi][safi]
10158 || p->afc_recv[afi][safi]) {
10159 vty_out(vty,
10160 " Address Family %s:",
10161 afi_safi_print(afi,
10162 safi));
10163 if (p->afc_adv[afi][safi])
10164 vty_out(vty,
10165 " advertised");
10166 if (p->afc_recv[afi][safi])
10167 vty_out(vty,
10168 " %sreceived",
10169 p->afc_adv[afi]
10170 [safi]
10171 ? "and "
10172 : "");
10173 vty_out(vty, "\n");
10174 }
10175
10176 /* Hostname capability */
10177 vty_out(vty, " Hostname Capability:");
10178
10179 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10180 vty_out(vty,
10181 " advertised (name: %s,domain name: %s)",
10182 bgp->peer_self->hostname
10183 ? bgp->peer_self
10184 ->hostname
10185 : "n/a",
10186 bgp->peer_self->domainname
10187 ? bgp->peer_self
10188 ->domainname
10189 : "n/a");
10190 } else {
10191 vty_out(vty, " not advertised");
10192 }
10193
10194 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10195 vty_out(vty,
10196 " received (name: %s,domain name: %s)",
10197 p->hostname ? p->hostname
10198 : "n/a",
10199 p->domainname ? p->domainname
10200 : "n/a");
10201 } else {
10202 vty_out(vty, " not received");
10203 }
10204
10205 vty_out(vty, "\n");
10206
10207 /* Gracefull Restart */
10208 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10209 || CHECK_FLAG(p->cap,
10210 PEER_CAP_RESTART_ADV)) {
10211 vty_out(vty,
10212 " Graceful Restart Capabilty:");
10213 if (CHECK_FLAG(p->cap,
10214 PEER_CAP_RESTART_ADV))
10215 vty_out(vty, " advertised");
10216 if (CHECK_FLAG(p->cap,
10217 PEER_CAP_RESTART_RCV))
10218 vty_out(vty, " %sreceived",
10219 CHECK_FLAG(
10220 p->cap,
10221 PEER_CAP_RESTART_ADV)
10222 ? "and "
10223 : "");
10224 vty_out(vty, "\n");
10225
10226 if (CHECK_FLAG(p->cap,
10227 PEER_CAP_RESTART_RCV)) {
10228 int restart_af_count = 0;
10229
10230 vty_out(vty,
10231 " Remote Restart timer is %d seconds\n",
10232 p->v_gr_restart);
10233 vty_out(vty,
10234 " Address families by peer:\n ");
10235
10236 FOREACH_AFI_SAFI (afi, safi)
10237 if (CHECK_FLAG(
10238 p->af_cap
10239 [afi]
10240 [safi],
10241 PEER_CAP_RESTART_AF_RCV)) {
10242 vty_out(vty,
10243 "%s%s(%s)",
10244 restart_af_count
10245 ? ", "
10246 : "",
10247 afi_safi_print(
10248 afi,
10249 safi),
10250 CHECK_FLAG(
10251 p->af_cap
10252 [afi]
10253 [safi],
10254 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10255 ? "preserved"
10256 : "not preserved");
10257 restart_af_count++;
10258 }
10259 if (!restart_af_count)
10260 vty_out(vty, "none");
10261 vty_out(vty, "\n");
10262 }
10263 }
10264 }
10265 }
10266 }
10267
10268 /* graceful restart information */
10269 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10270 || p->t_gr_stale) {
10271 json_object *json_grace = NULL;
10272 json_object *json_grace_send = NULL;
10273 json_object *json_grace_recv = NULL;
10274 int eor_send_af_count = 0;
10275 int eor_receive_af_count = 0;
10276
10277 if (use_json) {
10278 json_grace = json_object_new_object();
10279 json_grace_send = json_object_new_object();
10280 json_grace_recv = json_object_new_object();
10281
10282 if (p->status == Established) {
10283 FOREACH_AFI_SAFI (afi, safi) {
10284 if (CHECK_FLAG(p->af_sflags[afi][safi],
10285 PEER_STATUS_EOR_SEND)) {
10286 json_object_boolean_true_add(
10287 json_grace_send,
10288 afi_safi_print(afi,
10289 safi));
10290 eor_send_af_count++;
10291 }
10292 }
10293 FOREACH_AFI_SAFI (afi, safi) {
10294 if (CHECK_FLAG(
10295 p->af_sflags[afi][safi],
10296 PEER_STATUS_EOR_RECEIVED)) {
10297 json_object_boolean_true_add(
10298 json_grace_recv,
10299 afi_safi_print(afi,
10300 safi));
10301 eor_receive_af_count++;
10302 }
10303 }
10304 }
10305
10306 json_object_object_add(json_grace, "endOfRibSend",
10307 json_grace_send);
10308 json_object_object_add(json_grace, "endOfRibRecv",
10309 json_grace_recv);
10310
10311 if (p->t_gr_restart)
10312 json_object_int_add(json_grace,
10313 "gracefulRestartTimerMsecs",
10314 thread_timer_remain_second(
10315 p->t_gr_restart)
10316 * 1000);
10317
10318 if (p->t_gr_stale)
10319 json_object_int_add(
10320 json_grace,
10321 "gracefulStalepathTimerMsecs",
10322 thread_timer_remain_second(
10323 p->t_gr_stale)
10324 * 1000);
10325
10326 json_object_object_add(
10327 json_neigh, "gracefulRestartInfo", json_grace);
10328 } else {
10329 vty_out(vty, " Graceful restart information:\n");
10330 if (p->status == Established) {
10331 vty_out(vty, " End-of-RIB send: ");
10332 FOREACH_AFI_SAFI (afi, safi) {
10333 if (CHECK_FLAG(p->af_sflags[afi][safi],
10334 PEER_STATUS_EOR_SEND)) {
10335 vty_out(vty, "%s%s",
10336 eor_send_af_count ? ", "
10337 : "",
10338 afi_safi_print(afi,
10339 safi));
10340 eor_send_af_count++;
10341 }
10342 }
10343 vty_out(vty, "\n");
10344 vty_out(vty, " End-of-RIB received: ");
10345 FOREACH_AFI_SAFI (afi, safi) {
10346 if (CHECK_FLAG(
10347 p->af_sflags[afi][safi],
10348 PEER_STATUS_EOR_RECEIVED)) {
10349 vty_out(vty, "%s%s",
10350 eor_receive_af_count
10351 ? ", "
10352 : "",
10353 afi_safi_print(afi,
10354 safi));
10355 eor_receive_af_count++;
10356 }
10357 }
10358 vty_out(vty, "\n");
10359 }
10360
10361 if (p->t_gr_restart)
10362 vty_out(vty,
10363 " The remaining time of restart timer is %ld\n",
10364 thread_timer_remain_second(
10365 p->t_gr_restart));
10366
10367 if (p->t_gr_stale)
10368 vty_out(vty,
10369 " The remaining time of stalepath timer is %ld\n",
10370 thread_timer_remain_second(
10371 p->t_gr_stale));
10372 }
10373 }
10374 if (use_json) {
10375 json_object *json_stat = NULL;
10376 json_stat = json_object_new_object();
10377 /* Packet counts. */
10378 json_object_int_add(json_stat, "depthInq", 0);
10379 json_object_int_add(json_stat, "depthOutq",
10380 (unsigned long)p->obuf->count);
10381 json_object_int_add(json_stat, "opensSent",
10382 atomic_load_explicit(&p->open_out,
10383 memory_order_relaxed));
10384 json_object_int_add(json_stat, "opensRecv",
10385 atomic_load_explicit(&p->open_in,
10386 memory_order_relaxed));
10387 json_object_int_add(json_stat, "notificationsSent",
10388 atomic_load_explicit(&p->notify_out,
10389 memory_order_relaxed));
10390 json_object_int_add(json_stat, "notificationsRecv",
10391 atomic_load_explicit(&p->notify_in,
10392 memory_order_relaxed));
10393 json_object_int_add(json_stat, "updatesSent",
10394 atomic_load_explicit(&p->update_out,
10395 memory_order_relaxed));
10396 json_object_int_add(json_stat, "updatesRecv",
10397 atomic_load_explicit(&p->update_in,
10398 memory_order_relaxed));
10399 json_object_int_add(json_stat, "keepalivesSent",
10400 atomic_load_explicit(&p->keepalive_out,
10401 memory_order_relaxed));
10402 json_object_int_add(json_stat, "keepalivesRecv",
10403 atomic_load_explicit(&p->keepalive_in,
10404 memory_order_relaxed));
10405 json_object_int_add(json_stat, "routeRefreshSent",
10406 atomic_load_explicit(&p->refresh_out,
10407 memory_order_relaxed));
10408 json_object_int_add(json_stat, "routeRefreshRecv",
10409 atomic_load_explicit(&p->refresh_in,
10410 memory_order_relaxed));
10411 json_object_int_add(json_stat, "capabilitySent",
10412 atomic_load_explicit(&p->dynamic_cap_out,
10413 memory_order_relaxed));
10414 json_object_int_add(json_stat, "capabilityRecv",
10415 atomic_load_explicit(&p->dynamic_cap_in,
10416 memory_order_relaxed));
10417 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10418 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10419 json_object_object_add(json_neigh, "messageStats", json_stat);
10420 } else {
10421 /* Packet counts. */
10422 vty_out(vty, " Message statistics:\n");
10423 vty_out(vty, " Inq depth is 0\n");
10424 vty_out(vty, " Outq depth is %lu\n",
10425 (unsigned long)p->obuf->count);
10426 vty_out(vty, " Sent Rcvd\n");
10427 vty_out(vty, " Opens: %10d %10d\n",
10428 atomic_load_explicit(&p->open_out,
10429 memory_order_relaxed),
10430 atomic_load_explicit(&p->open_in,
10431 memory_order_relaxed));
10432 vty_out(vty, " Notifications: %10d %10d\n",
10433 atomic_load_explicit(&p->notify_out,
10434 memory_order_relaxed),
10435 atomic_load_explicit(&p->notify_in,
10436 memory_order_relaxed));
10437 vty_out(vty, " Updates: %10d %10d\n",
10438 atomic_load_explicit(&p->update_out,
10439 memory_order_relaxed),
10440 atomic_load_explicit(&p->update_in,
10441 memory_order_relaxed));
10442 vty_out(vty, " Keepalives: %10d %10d\n",
10443 atomic_load_explicit(&p->keepalive_out,
10444 memory_order_relaxed),
10445 atomic_load_explicit(&p->keepalive_in,
10446 memory_order_relaxed));
10447 vty_out(vty, " Route Refresh: %10d %10d\n",
10448 atomic_load_explicit(&p->refresh_out,
10449 memory_order_relaxed),
10450 atomic_load_explicit(&p->refresh_in,
10451 memory_order_relaxed));
10452 vty_out(vty, " Capability: %10d %10d\n",
10453 atomic_load_explicit(&p->dynamic_cap_out,
10454 memory_order_relaxed),
10455 atomic_load_explicit(&p->dynamic_cap_in,
10456 memory_order_relaxed));
10457 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10458 PEER_TOTAL_RX(p));
10459 }
10460
10461 if (use_json) {
10462 /* advertisement-interval */
10463 json_object_int_add(json_neigh,
10464 "minBtwnAdvertisementRunsTimerMsecs",
10465 p->v_routeadv * 1000);
10466
10467 /* Update-source. */
10468 if (p->update_if || p->update_source) {
10469 if (p->update_if)
10470 json_object_string_add(json_neigh,
10471 "updateSource",
10472 p->update_if);
10473 else if (p->update_source)
10474 json_object_string_add(
10475 json_neigh, "updateSource",
10476 sockunion2str(p->update_source, buf1,
10477 SU_ADDRSTRLEN));
10478 }
10479 } else {
10480 /* advertisement-interval */
10481 vty_out(vty,
10482 " Minimum time between advertisement runs is %d seconds\n",
10483 p->v_routeadv);
10484
10485 /* Update-source. */
10486 if (p->update_if || p->update_source) {
10487 vty_out(vty, " Update source is ");
10488 if (p->update_if)
10489 vty_out(vty, "%s", p->update_if);
10490 else if (p->update_source)
10491 vty_out(vty, "%s",
10492 sockunion2str(p->update_source, buf1,
10493 SU_ADDRSTRLEN));
10494 vty_out(vty, "\n");
10495 }
10496
10497 vty_out(vty, "\n");
10498 }
10499
10500 /* Address Family Information */
10501 json_object *json_hold = NULL;
10502
10503 if (use_json)
10504 json_hold = json_object_new_object();
10505
10506 FOREACH_AFI_SAFI (afi, safi)
10507 if (p->afc[afi][safi])
10508 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10509 json_hold);
10510
10511 if (use_json) {
10512 json_object_object_add(json_neigh, "addressFamilyInfo",
10513 json_hold);
10514 json_object_int_add(json_neigh, "connectionsEstablished",
10515 p->established);
10516 json_object_int_add(json_neigh, "connectionsDropped",
10517 p->dropped);
10518 } else
10519 vty_out(vty, " Connections established %d; dropped %d\n",
10520 p->established, p->dropped);
10521
10522 if (!p->last_reset) {
10523 if (use_json)
10524 json_object_string_add(json_neigh, "lastReset",
10525 "never");
10526 else
10527 vty_out(vty, " Last reset never\n");
10528 } else {
10529 if (use_json) {
10530 time_t uptime;
10531 struct tm *tm;
10532
10533 uptime = bgp_clock();
10534 uptime -= p->resettime;
10535 tm = gmtime(&uptime);
10536 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10537 (tm->tm_sec * 1000)
10538 + (tm->tm_min * 60000)
10539 + (tm->tm_hour * 3600000));
10540 json_object_string_add(
10541 json_neigh, "lastResetDueTo",
10542 peer_down_str[(int)p->last_reset]);
10543 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10544 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10545 char errorcodesubcode_hexstr[5];
10546 char errorcodesubcode_str[256];
10547
10548 code_str = bgp_notify_code_str(p->notify.code);
10549 subcode_str = bgp_notify_subcode_str(
10550 p->notify.code, p->notify.subcode);
10551
10552 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10553 p->notify.code, p->notify.subcode);
10554 json_object_string_add(json_neigh,
10555 "lastErrorCodeSubcode",
10556 errorcodesubcode_hexstr);
10557 snprintf(errorcodesubcode_str, 255, "%s%s",
10558 code_str, subcode_str);
10559 json_object_string_add(json_neigh,
10560 "lastNotificationReason",
10561 errorcodesubcode_str);
10562 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10563 && p->notify.code == BGP_NOTIFY_CEASE
10564 && (p->notify.subcode
10565 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10566 || p->notify.subcode
10567 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10568 && p->notify.length) {
10569 char msgbuf[1024];
10570 const char *msg_str;
10571
10572 msg_str = bgp_notify_admin_message(
10573 msgbuf, sizeof(msgbuf),
10574 (uint8_t *)p->notify.data,
10575 p->notify.length);
10576 if (msg_str)
10577 json_object_string_add(
10578 json_neigh,
10579 "lastShutdownDescription",
10580 msg_str);
10581 }
10582 }
10583 } else {
10584 vty_out(vty, " Last reset %s, ",
10585 peer_uptime(p->resettime, timebuf,
10586 BGP_UPTIME_LEN, 0, NULL));
10587
10588 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10589 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10590 code_str = bgp_notify_code_str(p->notify.code);
10591 subcode_str = bgp_notify_subcode_str(
10592 p->notify.code, p->notify.subcode);
10593 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10594 p->last_reset == PEER_DOWN_NOTIFY_SEND
10595 ? "sent"
10596 : "received",
10597 code_str, subcode_str);
10598 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10599 && p->notify.code == BGP_NOTIFY_CEASE
10600 && (p->notify.subcode
10601 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10602 || p->notify.subcode
10603 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10604 && p->notify.length) {
10605 char msgbuf[1024];
10606 const char *msg_str;
10607
10608 msg_str = bgp_notify_admin_message(
10609 msgbuf, sizeof(msgbuf),
10610 (uint8_t *)p->notify.data,
10611 p->notify.length);
10612 if (msg_str)
10613 vty_out(vty,
10614 " Message: \"%s\"\n",
10615 msg_str);
10616 }
10617 } else {
10618 vty_out(vty, "due to %s\n",
10619 peer_down_str[(int)p->last_reset]);
10620 }
10621
10622 if (p->last_reset_cause_size) {
10623 msg = p->last_reset_cause;
10624 vty_out(vty,
10625 " Message received that caused BGP to send a NOTIFICATION:\n ");
10626 for (i = 1; i <= p->last_reset_cause_size;
10627 i++) {
10628 vty_out(vty, "%02X", *msg++);
10629
10630 if (i != p->last_reset_cause_size) {
10631 if (i % 16 == 0) {
10632 vty_out(vty, "\n ");
10633 } else if (i % 4 == 0) {
10634 vty_out(vty, " ");
10635 }
10636 }
10637 }
10638 vty_out(vty, "\n");
10639 }
10640 }
10641 }
10642
10643 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10644 if (use_json)
10645 json_object_boolean_true_add(json_neigh,
10646 "prefixesConfigExceedMax");
10647 else
10648 vty_out(vty,
10649 " Peer had exceeded the max. no. of prefixes configured.\n");
10650
10651 if (p->t_pmax_restart) {
10652 if (use_json) {
10653 json_object_boolean_true_add(
10654 json_neigh, "reducePrefixNumFrom");
10655 json_object_int_add(json_neigh,
10656 "restartInTimerMsec",
10657 thread_timer_remain_second(
10658 p->t_pmax_restart)
10659 * 1000);
10660 } else
10661 vty_out(vty,
10662 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10663 p->host, thread_timer_remain_second(
10664 p->t_pmax_restart));
10665 } else {
10666 if (use_json)
10667 json_object_boolean_true_add(
10668 json_neigh,
10669 "reducePrefixNumAndClearIpBgp");
10670 else
10671 vty_out(vty,
10672 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10673 p->host);
10674 }
10675 }
10676
10677 /* EBGP Multihop and GTSM */
10678 if (p->sort != BGP_PEER_IBGP) {
10679 if (use_json) {
10680 if (p->gtsm_hops > 0)
10681 json_object_int_add(json_neigh,
10682 "externalBgpNbrMaxHopsAway",
10683 p->gtsm_hops);
10684 else if (p->ttl > 1)
10685 json_object_int_add(json_neigh,
10686 "externalBgpNbrMaxHopsAway",
10687 p->ttl);
10688 } else {
10689 if (p->gtsm_hops > 0)
10690 vty_out(vty,
10691 " External BGP neighbor may be up to %d hops away.\n",
10692 p->gtsm_hops);
10693 else if (p->ttl > 1)
10694 vty_out(vty,
10695 " External BGP neighbor may be up to %d hops away.\n",
10696 p->ttl);
10697 }
10698 } else {
10699 if (p->gtsm_hops > 0) {
10700 if (use_json)
10701 json_object_int_add(json_neigh,
10702 "internalBgpNbrMaxHopsAway",
10703 p->gtsm_hops);
10704 else
10705 vty_out(vty,
10706 " Internal BGP neighbor may be up to %d hops away.\n",
10707 p->gtsm_hops);
10708 }
10709 }
10710
10711 /* Local address. */
10712 if (p->su_local) {
10713 if (use_json) {
10714 json_object_string_add(json_neigh, "hostLocal",
10715 sockunion2str(p->su_local, buf1,
10716 SU_ADDRSTRLEN));
10717 json_object_int_add(json_neigh, "portLocal",
10718 ntohs(p->su_local->sin.sin_port));
10719 } else
10720 vty_out(vty, "Local host: %s, Local port: %d\n",
10721 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10722 ntohs(p->su_local->sin.sin_port));
10723 }
10724
10725 /* Remote address. */
10726 if (p->su_remote) {
10727 if (use_json) {
10728 json_object_string_add(json_neigh, "hostForeign",
10729 sockunion2str(p->su_remote, buf1,
10730 SU_ADDRSTRLEN));
10731 json_object_int_add(json_neigh, "portForeign",
10732 ntohs(p->su_remote->sin.sin_port));
10733 } else
10734 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10735 sockunion2str(p->su_remote, buf1,
10736 SU_ADDRSTRLEN),
10737 ntohs(p->su_remote->sin.sin_port));
10738 }
10739
10740 /* Nexthop display. */
10741 if (p->su_local) {
10742 if (use_json) {
10743 json_object_string_add(json_neigh, "nexthop",
10744 inet_ntop(AF_INET,
10745 &p->nexthop.v4, buf1,
10746 sizeof(buf1)));
10747 json_object_string_add(json_neigh, "nexthopGlobal",
10748 inet_ntop(AF_INET6,
10749 &p->nexthop.v6_global,
10750 buf1, sizeof(buf1)));
10751 json_object_string_add(json_neigh, "nexthopLocal",
10752 inet_ntop(AF_INET6,
10753 &p->nexthop.v6_local,
10754 buf1, sizeof(buf1)));
10755 if (p->shared_network)
10756 json_object_string_add(json_neigh,
10757 "bgpConnection",
10758 "sharedNetwork");
10759 else
10760 json_object_string_add(json_neigh,
10761 "bgpConnection",
10762 "nonSharedNetwork");
10763 } else {
10764 vty_out(vty, "Nexthop: %s\n",
10765 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10766 sizeof(buf1)));
10767 vty_out(vty, "Nexthop global: %s\n",
10768 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10769 sizeof(buf1)));
10770 vty_out(vty, "Nexthop local: %s\n",
10771 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10772 sizeof(buf1)));
10773 vty_out(vty, "BGP connection: %s\n",
10774 p->shared_network ? "shared network"
10775 : "non shared network");
10776 }
10777 }
10778
10779 /* Timer information. */
10780 if (use_json) {
10781 json_object_int_add(json_neigh, "connectRetryTimer",
10782 p->v_connect);
10783 if (p->status == Established && p->rtt)
10784 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10785 p->rtt);
10786 if (p->t_start)
10787 json_object_int_add(
10788 json_neigh, "nextStartTimerDueInMsecs",
10789 thread_timer_remain_second(p->t_start) * 1000);
10790 if (p->t_connect)
10791 json_object_int_add(
10792 json_neigh, "nextConnectTimerDueInMsecs",
10793 thread_timer_remain_second(p->t_connect)
10794 * 1000);
10795 if (p->t_routeadv) {
10796 json_object_int_add(json_neigh, "mraiInterval",
10797 p->v_routeadv);
10798 json_object_int_add(
10799 json_neigh, "mraiTimerExpireInMsecs",
10800 thread_timer_remain_second(p->t_routeadv)
10801 * 1000);
10802 }
10803 if (p->password)
10804 json_object_int_add(json_neigh, "authenticationEnabled",
10805 1);
10806
10807 if (p->t_read)
10808 json_object_string_add(json_neigh, "readThread", "on");
10809 else
10810 json_object_string_add(json_neigh, "readThread", "off");
10811
10812 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10813 json_object_string_add(json_neigh, "writeThread", "on");
10814 else
10815 json_object_string_add(json_neigh, "writeThread",
10816 "off");
10817 } else {
10818 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10819 p->v_connect);
10820 if (p->status == Established && p->rtt)
10821 vty_out(vty, "Estimated round trip time: %d ms\n",
10822 p->rtt);
10823 if (p->t_start)
10824 vty_out(vty, "Next start timer due in %ld seconds\n",
10825 thread_timer_remain_second(p->t_start));
10826 if (p->t_connect)
10827 vty_out(vty, "Next connect timer due in %ld seconds\n",
10828 thread_timer_remain_second(p->t_connect));
10829 if (p->t_routeadv)
10830 vty_out(vty,
10831 "MRAI (interval %u) timer expires in %ld seconds\n",
10832 p->v_routeadv,
10833 thread_timer_remain_second(p->t_routeadv));
10834 if (p->password)
10835 vty_out(vty, "Peer Authentication Enabled\n");
10836
10837 vty_out(vty, "Read thread: %s Write thread: %s\n",
10838 p->t_read ? "on" : "off",
10839 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10840 ? "on"
10841 : "off");
10842 }
10843
10844 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10845 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10846 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10847
10848 if (!use_json)
10849 vty_out(vty, "\n");
10850
10851 /* BFD information. */
10852 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10853
10854 if (use_json) {
10855 if (p->conf_if) /* Configured interface name. */
10856 json_object_object_add(json, p->conf_if, json_neigh);
10857 else /* Configured IP address. */
10858 json_object_object_add(json, p->host, json_neigh);
10859 }
10860 }
10861
10862 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10863 enum show_type type, union sockunion *su,
10864 const char *conf_if, bool use_json,
10865 json_object *json)
10866 {
10867 struct listnode *node, *nnode;
10868 struct peer *peer;
10869 int find = 0;
10870 bool nbr_output = false;
10871
10872 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10873 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10874 continue;
10875
10876 switch (type) {
10877 case show_all:
10878 bgp_show_peer(vty, peer, use_json, json);
10879 nbr_output = true;
10880 break;
10881 case show_peer:
10882 if (conf_if) {
10883 if ((peer->conf_if
10884 && !strcmp(peer->conf_if, conf_if))
10885 || (peer->hostname
10886 && !strcmp(peer->hostname, conf_if))) {
10887 find = 1;
10888 bgp_show_peer(vty, peer, use_json,
10889 json);
10890 }
10891 } else {
10892 if (sockunion_same(&peer->su, su)) {
10893 find = 1;
10894 bgp_show_peer(vty, peer, use_json,
10895 json);
10896 }
10897 }
10898 break;
10899 }
10900 }
10901
10902 if (type == show_peer && !find) {
10903 if (use_json)
10904 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10905 else
10906 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10907 }
10908
10909 if (type != show_peer && !nbr_output && !use_json)
10910 vty_out(vty, "%% No BGP neighbors found\n");
10911
10912 if (use_json) {
10913 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10914 json, JSON_C_TO_STRING_PRETTY));
10915 json_object_free(json);
10916 } else {
10917 vty_out(vty, "\n");
10918 }
10919
10920 return CMD_SUCCESS;
10921 }
10922
10923 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10924 enum show_type type,
10925 const char *ip_str,
10926 bool use_json)
10927 {
10928 struct listnode *node, *nnode;
10929 struct bgp *bgp;
10930 union sockunion su;
10931 json_object *json = NULL;
10932 int ret, is_first = 1;
10933 bool nbr_output = false;
10934
10935 if (use_json)
10936 vty_out(vty, "{\n");
10937
10938 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10939 nbr_output = true;
10940 if (use_json) {
10941 if (!(json = json_object_new_object())) {
10942 flog_err(
10943 EC_BGP_JSON_MEM_ERROR,
10944 "Unable to allocate memory for JSON object");
10945 vty_out(vty,
10946 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10947 return;
10948 }
10949
10950 json_object_int_add(json, "vrfId",
10951 (bgp->vrf_id == VRF_UNKNOWN)
10952 ? -1
10953 : (int64_t)bgp->vrf_id);
10954 json_object_string_add(
10955 json, "vrfName",
10956 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10957 ? VRF_DEFAULT_NAME
10958 : bgp->name);
10959
10960 if (!is_first)
10961 vty_out(vty, ",\n");
10962 else
10963 is_first = 0;
10964
10965 vty_out(vty, "\"%s\":",
10966 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10967 ? VRF_DEFAULT_NAME
10968 : bgp->name);
10969 } else {
10970 vty_out(vty, "\nInstance %s:\n",
10971 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10972 ? VRF_DEFAULT_NAME
10973 : bgp->name);
10974 }
10975
10976 if (type == show_peer) {
10977 ret = str2sockunion(ip_str, &su);
10978 if (ret < 0)
10979 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10980 use_json, json);
10981 else
10982 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10983 use_json, json);
10984 } else {
10985 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10986 use_json, json);
10987 }
10988 }
10989
10990 if (use_json)
10991 vty_out(vty, "}\n");
10992 else if (!nbr_output)
10993 vty_out(vty, "%% BGP instance not found\n");
10994 }
10995
10996 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10997 enum show_type type, const char *ip_str,
10998 bool use_json)
10999 {
11000 int ret;
11001 struct bgp *bgp;
11002 union sockunion su;
11003 json_object *json = NULL;
11004
11005 if (name) {
11006 if (strmatch(name, "all")) {
11007 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11008 use_json);
11009 return CMD_SUCCESS;
11010 } else {
11011 bgp = bgp_lookup_by_name(name);
11012 if (!bgp) {
11013 if (use_json) {
11014 json = json_object_new_object();
11015 vty_out(vty, "%s\n",
11016 json_object_to_json_string_ext(
11017 json,
11018 JSON_C_TO_STRING_PRETTY));
11019 json_object_free(json);
11020 } else
11021 vty_out(vty,
11022 "%% BGP instance not found\n");
11023
11024 return CMD_WARNING;
11025 }
11026 }
11027 } else {
11028 bgp = bgp_get_default();
11029 }
11030
11031 if (bgp) {
11032 json = json_object_new_object();
11033 if (ip_str) {
11034 ret = str2sockunion(ip_str, &su);
11035 if (ret < 0)
11036 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11037 use_json, json);
11038 else
11039 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11040 use_json, json);
11041 } else {
11042 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11043 json);
11044 }
11045 json_object_free(json);
11046 } else {
11047 if (use_json)
11048 vty_out(vty, "{}\n");
11049 else
11050 vty_out(vty, "%% BGP instance not found\n");
11051 }
11052
11053 return CMD_SUCCESS;
11054 }
11055
11056 /* "show [ip] bgp neighbors" commands. */
11057 DEFUN (show_ip_bgp_neighbors,
11058 show_ip_bgp_neighbors_cmd,
11059 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11060 SHOW_STR
11061 IP_STR
11062 BGP_STR
11063 BGP_INSTANCE_HELP_STR
11064 "Address Family\n"
11065 "Address Family\n"
11066 "Detailed information on TCP and BGP neighbor connections\n"
11067 "Neighbor to display information about\n"
11068 "Neighbor to display information about\n"
11069 "Neighbor on BGP configured interface\n"
11070 JSON_STR)
11071 {
11072 char *vrf = NULL;
11073 char *sh_arg = NULL;
11074 enum show_type sh_type;
11075
11076 bool uj = use_json(argc, argv);
11077
11078 int idx = 0;
11079
11080 /* [<vrf> VIEWVRFNAME] */
11081 if (argv_find(argv, argc, "vrf", &idx)) {
11082 vrf = argv[idx + 1]->arg;
11083 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11084 vrf = NULL;
11085 } else if (argv_find(argv, argc, "view", &idx))
11086 /* [<view> VIEWVRFNAME] */
11087 vrf = argv[idx + 1]->arg;
11088
11089 idx++;
11090 if (argv_find(argv, argc, "A.B.C.D", &idx)
11091 || argv_find(argv, argc, "X:X::X:X", &idx)
11092 || argv_find(argv, argc, "WORD", &idx)) {
11093 sh_type = show_peer;
11094 sh_arg = argv[idx]->arg;
11095 } else
11096 sh_type = show_all;
11097
11098 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11099 }
11100
11101 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11102 paths' and `show ip mbgp paths'. Those functions results are the
11103 same.*/
11104 DEFUN (show_ip_bgp_paths,
11105 show_ip_bgp_paths_cmd,
11106 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11107 SHOW_STR
11108 IP_STR
11109 BGP_STR
11110 BGP_SAFI_HELP_STR
11111 "Path information\n")
11112 {
11113 vty_out(vty, "Address Refcnt Path\n");
11114 aspath_print_all_vty(vty);
11115 return CMD_SUCCESS;
11116 }
11117
11118 #include "hash.h"
11119
11120 static void community_show_all_iterator(struct hash_backet *backet,
11121 struct vty *vty)
11122 {
11123 struct community *com;
11124
11125 com = (struct community *)backet->data;
11126 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11127 community_str(com, false));
11128 }
11129
11130 /* Show BGP's community internal data. */
11131 DEFUN (show_ip_bgp_community_info,
11132 show_ip_bgp_community_info_cmd,
11133 "show [ip] bgp community-info",
11134 SHOW_STR
11135 IP_STR
11136 BGP_STR
11137 "List all bgp community information\n")
11138 {
11139 vty_out(vty, "Address Refcnt Community\n");
11140
11141 hash_iterate(community_hash(),
11142 (void (*)(struct hash_backet *,
11143 void *))community_show_all_iterator,
11144 vty);
11145
11146 return CMD_SUCCESS;
11147 }
11148
11149 static void lcommunity_show_all_iterator(struct hash_backet *backet,
11150 struct vty *vty)
11151 {
11152 struct lcommunity *lcom;
11153
11154 lcom = (struct lcommunity *)backet->data;
11155 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11156 lcommunity_str(lcom, false));
11157 }
11158
11159 /* Show BGP's community internal data. */
11160 DEFUN (show_ip_bgp_lcommunity_info,
11161 show_ip_bgp_lcommunity_info_cmd,
11162 "show ip bgp large-community-info",
11163 SHOW_STR
11164 IP_STR
11165 BGP_STR
11166 "List all bgp large-community information\n")
11167 {
11168 vty_out(vty, "Address Refcnt Large-community\n");
11169
11170 hash_iterate(lcommunity_hash(),
11171 (void (*)(struct hash_backet *,
11172 void *))lcommunity_show_all_iterator,
11173 vty);
11174
11175 return CMD_SUCCESS;
11176 }
11177
11178
11179 DEFUN (show_ip_bgp_attr_info,
11180 show_ip_bgp_attr_info_cmd,
11181 "show [ip] bgp attribute-info",
11182 SHOW_STR
11183 IP_STR
11184 BGP_STR
11185 "List all bgp attribute information\n")
11186 {
11187 attr_show_all(vty);
11188 return CMD_SUCCESS;
11189 }
11190
11191 static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11192 safi_t safi, bool use_json)
11193 {
11194 struct bgp *bgp;
11195 struct listnode *node;
11196 char *vname;
11197 char buf1[INET6_ADDRSTRLEN];
11198 char *ecom_str;
11199 vpn_policy_direction_t dir;
11200
11201 if (use_json) {
11202 json_object *json = NULL;
11203 json_object *json_import_vrfs = NULL;
11204 json_object *json_export_vrfs = NULL;
11205
11206 json = json_object_new_object();
11207
11208 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11209
11210 if (!bgp) {
11211 vty_out(vty, "%s\n",
11212 json_object_to_json_string_ext(
11213 json,
11214 JSON_C_TO_STRING_PRETTY));
11215 json_object_free(json);
11216
11217 return CMD_WARNING;
11218 }
11219
11220 /* Provide context for the block */
11221 json_object_string_add(json, "vrf", name ? name : "default");
11222 json_object_string_add(json, "afiSafi",
11223 afi_safi_print(afi, safi));
11224
11225 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11226 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11227 json_object_string_add(json, "importFromVrfs", "none");
11228 json_object_string_add(json, "importRts", "none");
11229 } else {
11230 json_import_vrfs = json_object_new_array();
11231
11232 for (ALL_LIST_ELEMENTS_RO(
11233 bgp->vpn_policy[afi].import_vrf,
11234 node, vname))
11235 json_object_array_add(json_import_vrfs,
11236 json_object_new_string(vname));
11237
11238 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11239 ecom_str = ecommunity_ecom2str(
11240 bgp->vpn_policy[afi].rtlist[dir],
11241 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11242 json_object_object_add(json, "importFromVrfs",
11243 json_import_vrfs);
11244 json_object_string_add(json, "importRts", ecom_str);
11245
11246 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11247 }
11248
11249 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11250 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11251 json_object_string_add(json, "exportToVrfs", "none");
11252 json_object_string_add(json, "routeDistinguisher",
11253 "none");
11254 json_object_string_add(json, "exportRts", "none");
11255 } else {
11256 json_export_vrfs = json_object_new_array();
11257
11258 for (ALL_LIST_ELEMENTS_RO(
11259 bgp->vpn_policy[afi].export_vrf,
11260 node, vname))
11261 json_object_array_add(json_export_vrfs,
11262 json_object_new_string(vname));
11263 json_object_object_add(json, "exportToVrfs",
11264 json_export_vrfs);
11265 json_object_string_add(json, "routeDistinguisher",
11266 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11267 buf1, RD_ADDRSTRLEN));
11268
11269 dir = BGP_VPN_POLICY_DIR_TOVPN;
11270 ecom_str = ecommunity_ecom2str(
11271 bgp->vpn_policy[afi].rtlist[dir],
11272 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11273 json_object_string_add(json, "exportRts", ecom_str);
11274
11275 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11276 }
11277
11278 vty_out(vty, "%s\n",
11279 json_object_to_json_string_ext(json,
11280 JSON_C_TO_STRING_PRETTY));
11281 json_object_free(json);
11282
11283 } else {
11284 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11285
11286 if (!bgp) {
11287 vty_out(vty, "%% No such BGP instance exist\n");
11288 return CMD_WARNING;
11289 }
11290
11291 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11292 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11293 vty_out(vty,
11294 "This VRF is not importing %s routes from any other VRF\n",
11295 afi_safi_print(afi, safi));
11296 else {
11297 vty_out(vty,
11298 "This VRF is importing %s routes from the following VRFs:\n",
11299 afi_safi_print(afi, safi));
11300
11301 for (ALL_LIST_ELEMENTS_RO(
11302 bgp->vpn_policy[afi].import_vrf,
11303 node, vname))
11304 vty_out(vty, " %s\n", vname);
11305
11306 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11307 ecom_str = ecommunity_ecom2str(
11308 bgp->vpn_policy[afi].rtlist[dir],
11309 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11310 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11311
11312 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11313 }
11314
11315 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11316 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11317 vty_out(vty,
11318 "This VRF is not exporting %s routes to any other VRF\n",
11319 afi_safi_print(afi, safi));
11320 else {
11321 vty_out(vty,
11322 "This VRF is exporting %s routes to the following VRFs:\n",
11323 afi_safi_print(afi, safi));
11324
11325 for (ALL_LIST_ELEMENTS_RO(
11326 bgp->vpn_policy[afi].export_vrf,
11327 node, vname))
11328 vty_out(vty, " %s\n", vname);
11329
11330 vty_out(vty, "RD: %s\n",
11331 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11332 buf1, RD_ADDRSTRLEN));
11333
11334 dir = BGP_VPN_POLICY_DIR_TOVPN;
11335 ecom_str = ecommunity_ecom2str(
11336 bgp->vpn_policy[afi].rtlist[dir],
11337 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11338 vty_out(vty, "Export RT: %s\n", ecom_str);
11339 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11340 }
11341 }
11342
11343 return CMD_SUCCESS;
11344 }
11345
11346 /* "show [ip] bgp route-leak" command. */
11347 DEFUN (show_ip_bgp_route_leak,
11348 show_ip_bgp_route_leak_cmd,
11349 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11350 SHOW_STR
11351 IP_STR
11352 BGP_STR
11353 BGP_INSTANCE_HELP_STR
11354 BGP_AFI_HELP_STR
11355 BGP_SAFI_HELP_STR
11356 "Route leaking information\n"
11357 JSON_STR)
11358 {
11359 char *vrf = NULL;
11360 afi_t afi = AFI_MAX;
11361 safi_t safi = SAFI_MAX;
11362
11363 bool uj = use_json(argc, argv);
11364 int idx = 0;
11365
11366 /* show [ip] bgp */
11367 if (argv_find(argv, argc, "ip", &idx)) {
11368 afi = AFI_IP;
11369 safi = SAFI_UNICAST;
11370 }
11371 /* [vrf VIEWVRFNAME] */
11372 if (argv_find(argv, argc, "view", &idx)) {
11373 vty_out(vty,
11374 "%% This command is not applicable to BGP views\n");
11375 return CMD_WARNING;
11376 }
11377
11378 if (argv_find(argv, argc, "vrf", &idx)) {
11379 vrf = argv[idx + 1]->arg;
11380 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11381 vrf = NULL;
11382 }
11383 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11384 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11385 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11386 }
11387
11388 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11389 vty_out(vty,
11390 "%% This command is applicable only for unicast ipv4|ipv6\n");
11391 return CMD_WARNING;
11392 }
11393
11394 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
11395 }
11396
11397 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11398 safi_t safi)
11399 {
11400 struct listnode *node, *nnode;
11401 struct bgp *bgp;
11402
11403 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11404 vty_out(vty, "\nInstance %s:\n",
11405 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11406 ? VRF_DEFAULT_NAME
11407 : bgp->name);
11408 update_group_show(bgp, afi, safi, vty, 0);
11409 }
11410 }
11411
11412 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11413 int safi, uint64_t subgrp_id)
11414 {
11415 struct bgp *bgp;
11416
11417 if (name) {
11418 if (strmatch(name, "all")) {
11419 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11420 return CMD_SUCCESS;
11421 } else {
11422 bgp = bgp_lookup_by_name(name);
11423 }
11424 } else {
11425 bgp = bgp_get_default();
11426 }
11427
11428 if (bgp)
11429 update_group_show(bgp, afi, safi, vty, subgrp_id);
11430 return CMD_SUCCESS;
11431 }
11432
11433 DEFUN (show_ip_bgp_updgrps,
11434 show_ip_bgp_updgrps_cmd,
11435 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11436 SHOW_STR
11437 IP_STR
11438 BGP_STR
11439 BGP_INSTANCE_HELP_STR
11440 BGP_AFI_HELP_STR
11441 BGP_SAFI_WITH_LABEL_HELP_STR
11442 "Detailed info about dynamic update groups\n"
11443 "Specific subgroup to display detailed info for\n")
11444 {
11445 char *vrf = NULL;
11446 afi_t afi = AFI_IP6;
11447 safi_t safi = SAFI_UNICAST;
11448 uint64_t subgrp_id = 0;
11449
11450 int idx = 0;
11451
11452 /* show [ip] bgp */
11453 if (argv_find(argv, argc, "ip", &idx))
11454 afi = AFI_IP;
11455 /* [<vrf> VIEWVRFNAME] */
11456 if (argv_find(argv, argc, "vrf", &idx)) {
11457 vrf = argv[idx + 1]->arg;
11458 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11459 vrf = NULL;
11460 } else if (argv_find(argv, argc, "view", &idx))
11461 /* [<view> VIEWVRFNAME] */
11462 vrf = argv[idx + 1]->arg;
11463 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11464 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11465 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11466 }
11467
11468 /* get subgroup id, if provided */
11469 idx = argc - 1;
11470 if (argv[idx]->type == VARIABLE_TKN)
11471 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11472
11473 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11474 }
11475
11476 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11477 show_bgp_instance_all_ipv6_updgrps_cmd,
11478 "show [ip] bgp <view|vrf> all update-groups",
11479 SHOW_STR
11480 IP_STR
11481 BGP_STR
11482 BGP_INSTANCE_ALL_HELP_STR
11483 "Detailed info about dynamic update groups\n")
11484 {
11485 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11486 return CMD_SUCCESS;
11487 }
11488
11489 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11490 show_bgp_l2vpn_evpn_updgrps_cmd,
11491 "show [ip] bgp l2vpn evpn update-groups",
11492 SHOW_STR
11493 IP_STR
11494 BGP_STR
11495 "l2vpn address family\n"
11496 "evpn sub-address family\n"
11497 "Detailed info about dynamic update groups\n")
11498 {
11499 char *vrf = NULL;
11500 uint64_t subgrp_id = 0;
11501
11502 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11503 return CMD_SUCCESS;
11504 }
11505
11506 DEFUN (show_bgp_updgrps_stats,
11507 show_bgp_updgrps_stats_cmd,
11508 "show [ip] bgp update-groups statistics",
11509 SHOW_STR
11510 IP_STR
11511 BGP_STR
11512 "Detailed info about dynamic update groups\n"
11513 "Statistics\n")
11514 {
11515 struct bgp *bgp;
11516
11517 bgp = bgp_get_default();
11518 if (bgp)
11519 update_group_show_stats(bgp, vty);
11520
11521 return CMD_SUCCESS;
11522 }
11523
11524 DEFUN (show_bgp_instance_updgrps_stats,
11525 show_bgp_instance_updgrps_stats_cmd,
11526 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11527 SHOW_STR
11528 IP_STR
11529 BGP_STR
11530 BGP_INSTANCE_HELP_STR
11531 "Detailed info about dynamic update groups\n"
11532 "Statistics\n")
11533 {
11534 int idx_word = 3;
11535 struct bgp *bgp;
11536
11537 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11538 if (bgp)
11539 update_group_show_stats(bgp, vty);
11540
11541 return CMD_SUCCESS;
11542 }
11543
11544 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11545 afi_t afi, safi_t safi,
11546 const char *what, uint64_t subgrp_id)
11547 {
11548 struct bgp *bgp;
11549
11550 if (name)
11551 bgp = bgp_lookup_by_name(name);
11552 else
11553 bgp = bgp_get_default();
11554
11555 if (bgp) {
11556 if (!strcmp(what, "advertise-queue"))
11557 update_group_show_adj_queue(bgp, afi, safi, vty,
11558 subgrp_id);
11559 else if (!strcmp(what, "advertised-routes"))
11560 update_group_show_advertised(bgp, afi, safi, vty,
11561 subgrp_id);
11562 else if (!strcmp(what, "packet-queue"))
11563 update_group_show_packet_queue(bgp, afi, safi, vty,
11564 subgrp_id);
11565 }
11566 }
11567
11568 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11569 show_ip_bgp_instance_updgrps_adj_s_cmd,
11570 "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",
11571 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11572 BGP_SAFI_HELP_STR
11573 "Detailed info about dynamic update groups\n"
11574 "Specific subgroup to display info for\n"
11575 "Advertisement queue\n"
11576 "Announced routes\n"
11577 "Packet queue\n")
11578 {
11579 uint64_t subgrp_id = 0;
11580 afi_t afiz;
11581 safi_t safiz;
11582 if (sgid)
11583 subgrp_id = strtoull(sgid, NULL, 10);
11584
11585 if (!ip && !afi)
11586 afiz = AFI_IP6;
11587 if (!ip && afi)
11588 afiz = bgp_vty_afi_from_str(afi);
11589 if (ip && !afi)
11590 afiz = AFI_IP;
11591 if (ip && afi) {
11592 afiz = bgp_vty_afi_from_str(afi);
11593 if (afiz != AFI_IP)
11594 vty_out(vty,
11595 "%% Cannot specify both 'ip' and 'ipv6'\n");
11596 return CMD_WARNING;
11597 }
11598
11599 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11600
11601 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11602 return CMD_SUCCESS;
11603 }
11604
11605 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11606 {
11607 struct listnode *node, *nnode;
11608 struct prefix *range;
11609 struct peer *conf;
11610 struct peer *peer;
11611 char buf[PREFIX2STR_BUFFER];
11612 afi_t afi;
11613 safi_t safi;
11614 const char *peer_status;
11615 const char *af_str;
11616 int lr_count;
11617 int dynamic;
11618 int af_cfgd;
11619
11620 conf = group->conf;
11621
11622 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11623 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11624 conf->as);
11625 } else if (conf->as_type == AS_INTERNAL) {
11626 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11627 group->bgp->as);
11628 } else {
11629 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11630 }
11631
11632 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11633 vty_out(vty, " Peer-group type is internal\n");
11634 else
11635 vty_out(vty, " Peer-group type is external\n");
11636
11637 /* Display AFs configured. */
11638 vty_out(vty, " Configured address-families:");
11639 FOREACH_AFI_SAFI (afi, safi) {
11640 if (conf->afc[afi][safi]) {
11641 af_cfgd = 1;
11642 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11643 }
11644 }
11645 if (!af_cfgd)
11646 vty_out(vty, " none\n");
11647 else
11648 vty_out(vty, "\n");
11649
11650 /* Display listen ranges (for dynamic neighbors), if any */
11651 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11652 if (afi == AFI_IP)
11653 af_str = "IPv4";
11654 else if (afi == AFI_IP6)
11655 af_str = "IPv6";
11656 else
11657 af_str = "???";
11658 lr_count = listcount(group->listen_range[afi]);
11659 if (lr_count) {
11660 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11661 af_str);
11662
11663
11664 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11665 nnode, range)) {
11666 prefix2str(range, buf, sizeof(buf));
11667 vty_out(vty, " %s\n", buf);
11668 }
11669 }
11670 }
11671
11672 /* Display group members and their status */
11673 if (listcount(group->peer)) {
11674 vty_out(vty, " Peer-group members:\n");
11675 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11676 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11677 peer_status = "Idle (Admin)";
11678 else if (CHECK_FLAG(peer->sflags,
11679 PEER_STATUS_PREFIX_OVERFLOW))
11680 peer_status = "Idle (PfxCt)";
11681 else
11682 peer_status = lookup_msg(bgp_status_msg,
11683 peer->status, NULL);
11684
11685 dynamic = peer_dynamic_neighbor(peer);
11686 vty_out(vty, " %s %s %s \n", peer->host,
11687 dynamic ? "(dynamic)" : "", peer_status);
11688 }
11689 }
11690
11691 return CMD_SUCCESS;
11692 }
11693
11694 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11695 const char *group_name)
11696 {
11697 struct bgp *bgp;
11698 struct listnode *node, *nnode;
11699 struct peer_group *group;
11700 bool found = false;
11701
11702 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11703
11704 if (!bgp) {
11705 vty_out(vty, "%% BGP instance not found\n");
11706 return CMD_WARNING;
11707 }
11708
11709 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11710 if (group_name) {
11711 if (strmatch(group->name, group_name)) {
11712 bgp_show_one_peer_group(vty, group);
11713 found = true;
11714 break;
11715 }
11716 } else {
11717 bgp_show_one_peer_group(vty, group);
11718 }
11719 }
11720
11721 if (group_name && !found)
11722 vty_out(vty, "%% No such peer-group\n");
11723
11724 return CMD_SUCCESS;
11725 }
11726
11727 DEFUN (show_ip_bgp_peer_groups,
11728 show_ip_bgp_peer_groups_cmd,
11729 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11730 SHOW_STR
11731 IP_STR
11732 BGP_STR
11733 BGP_INSTANCE_HELP_STR
11734 "Detailed information on BGP peer groups\n"
11735 "Peer group name\n")
11736 {
11737 char *vrf, *pg;
11738 int idx = 0;
11739
11740 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11741 : NULL;
11742 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11743
11744 return bgp_show_peer_group_vty(vty, vrf, pg);
11745 }
11746
11747
11748 /* Redistribute VTY commands. */
11749
11750 DEFUN (bgp_redistribute_ipv4,
11751 bgp_redistribute_ipv4_cmd,
11752 "redistribute " FRR_IP_REDIST_STR_BGPD,
11753 "Redistribute information from another routing protocol\n"
11754 FRR_IP_REDIST_HELP_STR_BGPD)
11755 {
11756 VTY_DECLVAR_CONTEXT(bgp, bgp);
11757 int idx_protocol = 1;
11758 int type;
11759
11760 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11761 if (type < 0) {
11762 vty_out(vty, "%% Invalid route type\n");
11763 return CMD_WARNING_CONFIG_FAILED;
11764 }
11765
11766 bgp_redist_add(bgp, AFI_IP, type, 0);
11767 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11768 }
11769
11770 ALIAS_HIDDEN(
11771 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11772 "redistribute " FRR_IP_REDIST_STR_BGPD,
11773 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11774
11775 DEFUN (bgp_redistribute_ipv4_rmap,
11776 bgp_redistribute_ipv4_rmap_cmd,
11777 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11778 "Redistribute information from another routing protocol\n"
11779 FRR_IP_REDIST_HELP_STR_BGPD
11780 "Route map reference\n"
11781 "Pointer to route-map entries\n")
11782 {
11783 VTY_DECLVAR_CONTEXT(bgp, bgp);
11784 int idx_protocol = 1;
11785 int idx_word = 3;
11786 int type;
11787 struct bgp_redist *red;
11788 bool changed;
11789 struct route_map *route_map = route_map_lookup_warn_noexist(
11790 vty, argv[idx_word]->arg);
11791
11792 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11793 if (type < 0) {
11794 vty_out(vty, "%% Invalid route type\n");
11795 return CMD_WARNING_CONFIG_FAILED;
11796 }
11797
11798 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11799 changed =
11800 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11801 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11802 }
11803
11804 ALIAS_HIDDEN(
11805 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11806 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11807 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11808 "Route map reference\n"
11809 "Pointer to route-map entries\n")
11810
11811 DEFUN (bgp_redistribute_ipv4_metric,
11812 bgp_redistribute_ipv4_metric_cmd,
11813 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11814 "Redistribute information from another routing protocol\n"
11815 FRR_IP_REDIST_HELP_STR_BGPD
11816 "Metric for redistributed routes\n"
11817 "Default metric\n")
11818 {
11819 VTY_DECLVAR_CONTEXT(bgp, bgp);
11820 int idx_protocol = 1;
11821 int idx_number = 3;
11822 int type;
11823 uint32_t metric;
11824 struct bgp_redist *red;
11825 bool changed;
11826
11827 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11828 if (type < 0) {
11829 vty_out(vty, "%% Invalid route type\n");
11830 return CMD_WARNING_CONFIG_FAILED;
11831 }
11832 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11833
11834 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11835 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11836 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11837 }
11838
11839 ALIAS_HIDDEN(
11840 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11841 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11842 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11843 "Metric for redistributed routes\n"
11844 "Default metric\n")
11845
11846 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11847 bgp_redistribute_ipv4_rmap_metric_cmd,
11848 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11849 "Redistribute information from another routing protocol\n"
11850 FRR_IP_REDIST_HELP_STR_BGPD
11851 "Route map reference\n"
11852 "Pointer to route-map entries\n"
11853 "Metric for redistributed routes\n"
11854 "Default metric\n")
11855 {
11856 VTY_DECLVAR_CONTEXT(bgp, bgp);
11857 int idx_protocol = 1;
11858 int idx_word = 3;
11859 int idx_number = 5;
11860 int type;
11861 uint32_t metric;
11862 struct bgp_redist *red;
11863 bool changed;
11864 struct route_map *route_map =
11865 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11866
11867 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11868 if (type < 0) {
11869 vty_out(vty, "%% Invalid route type\n");
11870 return CMD_WARNING_CONFIG_FAILED;
11871 }
11872 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11873
11874 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11875 changed =
11876 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11877 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11878 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11879 }
11880
11881 ALIAS_HIDDEN(
11882 bgp_redistribute_ipv4_rmap_metric,
11883 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11884 "redistribute " FRR_IP_REDIST_STR_BGPD
11885 " route-map WORD metric (0-4294967295)",
11886 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11887 "Route map reference\n"
11888 "Pointer to route-map entries\n"
11889 "Metric for redistributed routes\n"
11890 "Default metric\n")
11891
11892 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11893 bgp_redistribute_ipv4_metric_rmap_cmd,
11894 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11895 "Redistribute information from another routing protocol\n"
11896 FRR_IP_REDIST_HELP_STR_BGPD
11897 "Metric for redistributed routes\n"
11898 "Default metric\n"
11899 "Route map reference\n"
11900 "Pointer to route-map entries\n")
11901 {
11902 VTY_DECLVAR_CONTEXT(bgp, bgp);
11903 int idx_protocol = 1;
11904 int idx_number = 3;
11905 int idx_word = 5;
11906 int type;
11907 uint32_t metric;
11908 struct bgp_redist *red;
11909 bool changed;
11910 struct route_map *route_map =
11911 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11912
11913 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11914 if (type < 0) {
11915 vty_out(vty, "%% Invalid route type\n");
11916 return CMD_WARNING_CONFIG_FAILED;
11917 }
11918 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11919
11920 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11921 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11922 changed |=
11923 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11924 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11925 }
11926
11927 ALIAS_HIDDEN(
11928 bgp_redistribute_ipv4_metric_rmap,
11929 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11930 "redistribute " FRR_IP_REDIST_STR_BGPD
11931 " metric (0-4294967295) route-map WORD",
11932 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11933 "Metric for redistributed routes\n"
11934 "Default metric\n"
11935 "Route map reference\n"
11936 "Pointer to route-map entries\n")
11937
11938 DEFUN (bgp_redistribute_ipv4_ospf,
11939 bgp_redistribute_ipv4_ospf_cmd,
11940 "redistribute <ospf|table> (1-65535)",
11941 "Redistribute information from another routing protocol\n"
11942 "Open Shortest Path First (OSPFv2)\n"
11943 "Non-main Kernel Routing Table\n"
11944 "Instance ID/Table ID\n")
11945 {
11946 VTY_DECLVAR_CONTEXT(bgp, bgp);
11947 int idx_ospf_table = 1;
11948 int idx_number = 2;
11949 unsigned short instance;
11950 unsigned short protocol;
11951
11952 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11953
11954 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11955 protocol = ZEBRA_ROUTE_OSPF;
11956 else
11957 protocol = ZEBRA_ROUTE_TABLE;
11958
11959 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11960 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
11961 }
11962
11963 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11964 "redistribute <ospf|table> (1-65535)",
11965 "Redistribute information from another routing protocol\n"
11966 "Open Shortest Path First (OSPFv2)\n"
11967 "Non-main Kernel Routing Table\n"
11968 "Instance ID/Table ID\n")
11969
11970 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11971 bgp_redistribute_ipv4_ospf_rmap_cmd,
11972 "redistribute <ospf|table> (1-65535) route-map WORD",
11973 "Redistribute information from another routing protocol\n"
11974 "Open Shortest Path First (OSPFv2)\n"
11975 "Non-main Kernel Routing Table\n"
11976 "Instance ID/Table ID\n"
11977 "Route map reference\n"
11978 "Pointer to route-map entries\n")
11979 {
11980 VTY_DECLVAR_CONTEXT(bgp, bgp);
11981 int idx_ospf_table = 1;
11982 int idx_number = 2;
11983 int idx_word = 4;
11984 struct bgp_redist *red;
11985 unsigned short instance;
11986 int protocol;
11987 bool changed;
11988 struct route_map *route_map =
11989 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11990
11991 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11992 protocol = ZEBRA_ROUTE_OSPF;
11993 else
11994 protocol = ZEBRA_ROUTE_TABLE;
11995
11996 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11997 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11998 changed =
11999 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12000 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12001 }
12002
12003 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12004 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12005 "redistribute <ospf|table> (1-65535) route-map WORD",
12006 "Redistribute information from another routing protocol\n"
12007 "Open Shortest Path First (OSPFv2)\n"
12008 "Non-main Kernel Routing Table\n"
12009 "Instance ID/Table ID\n"
12010 "Route map reference\n"
12011 "Pointer to route-map entries\n")
12012
12013 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12014 bgp_redistribute_ipv4_ospf_metric_cmd,
12015 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12016 "Redistribute information from another routing protocol\n"
12017 "Open Shortest Path First (OSPFv2)\n"
12018 "Non-main Kernel Routing Table\n"
12019 "Instance ID/Table ID\n"
12020 "Metric for redistributed routes\n"
12021 "Default metric\n")
12022 {
12023 VTY_DECLVAR_CONTEXT(bgp, bgp);
12024 int idx_ospf_table = 1;
12025 int idx_number = 2;
12026 int idx_number_2 = 4;
12027 uint32_t metric;
12028 struct bgp_redist *red;
12029 unsigned short instance;
12030 int protocol;
12031 bool changed;
12032
12033 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12034 protocol = ZEBRA_ROUTE_OSPF;
12035 else
12036 protocol = ZEBRA_ROUTE_TABLE;
12037
12038 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12039 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12040
12041 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12042 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12043 metric);
12044 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12045 }
12046
12047 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12048 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12049 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12050 "Redistribute information from another routing protocol\n"
12051 "Open Shortest Path First (OSPFv2)\n"
12052 "Non-main Kernel Routing Table\n"
12053 "Instance ID/Table ID\n"
12054 "Metric for redistributed routes\n"
12055 "Default metric\n")
12056
12057 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12058 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12059 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12060 "Redistribute information from another routing protocol\n"
12061 "Open Shortest Path First (OSPFv2)\n"
12062 "Non-main Kernel Routing Table\n"
12063 "Instance ID/Table ID\n"
12064 "Route map reference\n"
12065 "Pointer to route-map entries\n"
12066 "Metric for redistributed routes\n"
12067 "Default metric\n")
12068 {
12069 VTY_DECLVAR_CONTEXT(bgp, bgp);
12070 int idx_ospf_table = 1;
12071 int idx_number = 2;
12072 int idx_word = 4;
12073 int idx_number_2 = 6;
12074 uint32_t metric;
12075 struct bgp_redist *red;
12076 unsigned short instance;
12077 int protocol;
12078 bool changed;
12079 struct route_map *route_map =
12080 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12081
12082 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12083 protocol = ZEBRA_ROUTE_OSPF;
12084 else
12085 protocol = ZEBRA_ROUTE_TABLE;
12086
12087 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12088 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12089
12090 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12091 changed =
12092 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12093 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12094 metric);
12095 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12096 }
12097
12098 ALIAS_HIDDEN(
12099 bgp_redistribute_ipv4_ospf_rmap_metric,
12100 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12101 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12102 "Redistribute information from another routing protocol\n"
12103 "Open Shortest Path First (OSPFv2)\n"
12104 "Non-main Kernel Routing Table\n"
12105 "Instance ID/Table ID\n"
12106 "Route map reference\n"
12107 "Pointer to route-map entries\n"
12108 "Metric for redistributed routes\n"
12109 "Default metric\n")
12110
12111 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12112 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12113 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12114 "Redistribute information from another routing protocol\n"
12115 "Open Shortest Path First (OSPFv2)\n"
12116 "Non-main Kernel Routing Table\n"
12117 "Instance ID/Table ID\n"
12118 "Metric for redistributed routes\n"
12119 "Default metric\n"
12120 "Route map reference\n"
12121 "Pointer to route-map entries\n")
12122 {
12123 VTY_DECLVAR_CONTEXT(bgp, bgp);
12124 int idx_ospf_table = 1;
12125 int idx_number = 2;
12126 int idx_number_2 = 4;
12127 int idx_word = 6;
12128 uint32_t metric;
12129 struct bgp_redist *red;
12130 unsigned short instance;
12131 int protocol;
12132 bool changed;
12133 struct route_map *route_map =
12134 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12135
12136 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12137 protocol = ZEBRA_ROUTE_OSPF;
12138 else
12139 protocol = ZEBRA_ROUTE_TABLE;
12140
12141 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12142 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12143
12144 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12145 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12146 metric);
12147 changed |=
12148 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12149 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12150 }
12151
12152 ALIAS_HIDDEN(
12153 bgp_redistribute_ipv4_ospf_metric_rmap,
12154 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12155 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12156 "Redistribute information from another routing protocol\n"
12157 "Open Shortest Path First (OSPFv2)\n"
12158 "Non-main Kernel Routing Table\n"
12159 "Instance ID/Table ID\n"
12160 "Metric for redistributed routes\n"
12161 "Default metric\n"
12162 "Route map reference\n"
12163 "Pointer to route-map entries\n")
12164
12165 DEFUN (no_bgp_redistribute_ipv4_ospf,
12166 no_bgp_redistribute_ipv4_ospf_cmd,
12167 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12168 NO_STR
12169 "Redistribute information from another routing protocol\n"
12170 "Open Shortest Path First (OSPFv2)\n"
12171 "Non-main Kernel Routing Table\n"
12172 "Instance ID/Table ID\n"
12173 "Metric for redistributed routes\n"
12174 "Default metric\n"
12175 "Route map reference\n"
12176 "Pointer to route-map entries\n")
12177 {
12178 VTY_DECLVAR_CONTEXT(bgp, bgp);
12179 int idx_ospf_table = 2;
12180 int idx_number = 3;
12181 unsigned short instance;
12182 int protocol;
12183
12184 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12185 protocol = ZEBRA_ROUTE_OSPF;
12186 else
12187 protocol = ZEBRA_ROUTE_TABLE;
12188
12189 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12190 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12191 }
12192
12193 ALIAS_HIDDEN(
12194 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12195 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12196 NO_STR
12197 "Redistribute information from another routing protocol\n"
12198 "Open Shortest Path First (OSPFv2)\n"
12199 "Non-main Kernel Routing Table\n"
12200 "Instance ID/Table ID\n"
12201 "Metric for redistributed routes\n"
12202 "Default metric\n"
12203 "Route map reference\n"
12204 "Pointer to route-map entries\n")
12205
12206 DEFUN (no_bgp_redistribute_ipv4,
12207 no_bgp_redistribute_ipv4_cmd,
12208 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12209 NO_STR
12210 "Redistribute information from another routing protocol\n"
12211 FRR_IP_REDIST_HELP_STR_BGPD
12212 "Metric for redistributed routes\n"
12213 "Default metric\n"
12214 "Route map reference\n"
12215 "Pointer to route-map entries\n")
12216 {
12217 VTY_DECLVAR_CONTEXT(bgp, bgp);
12218 int idx_protocol = 2;
12219 int type;
12220
12221 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12222 if (type < 0) {
12223 vty_out(vty, "%% Invalid route type\n");
12224 return CMD_WARNING_CONFIG_FAILED;
12225 }
12226 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12227 }
12228
12229 ALIAS_HIDDEN(
12230 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12231 "no redistribute " FRR_IP_REDIST_STR_BGPD
12232 " [metric (0-4294967295)] [route-map WORD]",
12233 NO_STR
12234 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12235 "Metric for redistributed routes\n"
12236 "Default metric\n"
12237 "Route map reference\n"
12238 "Pointer to route-map entries\n")
12239
12240 DEFUN (bgp_redistribute_ipv6,
12241 bgp_redistribute_ipv6_cmd,
12242 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12243 "Redistribute information from another routing protocol\n"
12244 FRR_IP6_REDIST_HELP_STR_BGPD)
12245 {
12246 VTY_DECLVAR_CONTEXT(bgp, bgp);
12247 int idx_protocol = 1;
12248 int type;
12249
12250 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12251 if (type < 0) {
12252 vty_out(vty, "%% Invalid route type\n");
12253 return CMD_WARNING_CONFIG_FAILED;
12254 }
12255
12256 bgp_redist_add(bgp, AFI_IP6, type, 0);
12257 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12258 }
12259
12260 DEFUN (bgp_redistribute_ipv6_rmap,
12261 bgp_redistribute_ipv6_rmap_cmd,
12262 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12263 "Redistribute information from another routing protocol\n"
12264 FRR_IP6_REDIST_HELP_STR_BGPD
12265 "Route map reference\n"
12266 "Pointer to route-map entries\n")
12267 {
12268 VTY_DECLVAR_CONTEXT(bgp, bgp);
12269 int idx_protocol = 1;
12270 int idx_word = 3;
12271 int type;
12272 struct bgp_redist *red;
12273 bool changed;
12274 struct route_map *route_map =
12275 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12276
12277 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12278 if (type < 0) {
12279 vty_out(vty, "%% Invalid route type\n");
12280 return CMD_WARNING_CONFIG_FAILED;
12281 }
12282
12283 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12284 changed =
12285 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12286 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12287 }
12288
12289 DEFUN (bgp_redistribute_ipv6_metric,
12290 bgp_redistribute_ipv6_metric_cmd,
12291 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12292 "Redistribute information from another routing protocol\n"
12293 FRR_IP6_REDIST_HELP_STR_BGPD
12294 "Metric for redistributed routes\n"
12295 "Default metric\n")
12296 {
12297 VTY_DECLVAR_CONTEXT(bgp, bgp);
12298 int idx_protocol = 1;
12299 int idx_number = 3;
12300 int type;
12301 uint32_t metric;
12302 struct bgp_redist *red;
12303 bool changed;
12304
12305 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12306 if (type < 0) {
12307 vty_out(vty, "%% Invalid route type\n");
12308 return CMD_WARNING_CONFIG_FAILED;
12309 }
12310 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12311
12312 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12313 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12314 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12315 }
12316
12317 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12318 bgp_redistribute_ipv6_rmap_metric_cmd,
12319 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12320 "Redistribute information from another routing protocol\n"
12321 FRR_IP6_REDIST_HELP_STR_BGPD
12322 "Route map reference\n"
12323 "Pointer to route-map entries\n"
12324 "Metric for redistributed routes\n"
12325 "Default metric\n")
12326 {
12327 VTY_DECLVAR_CONTEXT(bgp, bgp);
12328 int idx_protocol = 1;
12329 int idx_word = 3;
12330 int idx_number = 5;
12331 int type;
12332 uint32_t metric;
12333 struct bgp_redist *red;
12334 bool changed;
12335 struct route_map *route_map =
12336 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12337
12338 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12339 if (type < 0) {
12340 vty_out(vty, "%% Invalid route type\n");
12341 return CMD_WARNING_CONFIG_FAILED;
12342 }
12343 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12344
12345 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12346 changed =
12347 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12348 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12349 metric);
12350 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12351 }
12352
12353 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12354 bgp_redistribute_ipv6_metric_rmap_cmd,
12355 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12356 "Redistribute information from another routing protocol\n"
12357 FRR_IP6_REDIST_HELP_STR_BGPD
12358 "Metric for redistributed routes\n"
12359 "Default metric\n"
12360 "Route map reference\n"
12361 "Pointer to route-map entries\n")
12362 {
12363 VTY_DECLVAR_CONTEXT(bgp, bgp);
12364 int idx_protocol = 1;
12365 int idx_number = 3;
12366 int idx_word = 5;
12367 int type;
12368 uint32_t metric;
12369 struct bgp_redist *red;
12370 bool changed;
12371 struct route_map *route_map =
12372 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12373
12374 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12375 if (type < 0) {
12376 vty_out(vty, "%% Invalid route type\n");
12377 return CMD_WARNING_CONFIG_FAILED;
12378 }
12379 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12380
12381 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12382 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12383 metric);
12384 changed |=
12385 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12386 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12387 }
12388
12389 DEFUN (no_bgp_redistribute_ipv6,
12390 no_bgp_redistribute_ipv6_cmd,
12391 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12392 NO_STR
12393 "Redistribute information from another routing protocol\n"
12394 FRR_IP6_REDIST_HELP_STR_BGPD
12395 "Metric for redistributed routes\n"
12396 "Default metric\n"
12397 "Route map reference\n"
12398 "Pointer to route-map entries\n")
12399 {
12400 VTY_DECLVAR_CONTEXT(bgp, bgp);
12401 int idx_protocol = 2;
12402 int type;
12403
12404 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12405 if (type < 0) {
12406 vty_out(vty, "%% Invalid route type\n");
12407 return CMD_WARNING_CONFIG_FAILED;
12408 }
12409
12410 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12411 }
12412
12413 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12414 safi_t safi)
12415 {
12416 int i;
12417
12418 /* Unicast redistribution only. */
12419 if (safi != SAFI_UNICAST)
12420 return;
12421
12422 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12423 /* Redistribute BGP does not make sense. */
12424 if (i != ZEBRA_ROUTE_BGP) {
12425 struct list *red_list;
12426 struct listnode *node;
12427 struct bgp_redist *red;
12428
12429 red_list = bgp->redist[afi][i];
12430 if (!red_list)
12431 continue;
12432
12433 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12434 /* "redistribute" configuration. */
12435 vty_out(vty, " redistribute %s",
12436 zebra_route_string(i));
12437 if (red->instance)
12438 vty_out(vty, " %d", red->instance);
12439 if (red->redist_metric_flag)
12440 vty_out(vty, " metric %u",
12441 red->redist_metric);
12442 if (red->rmap.name)
12443 vty_out(vty, " route-map %s",
12444 red->rmap.name);
12445 vty_out(vty, "\n");
12446 }
12447 }
12448 }
12449 }
12450
12451 /* This is part of the address-family block (unicast only) */
12452 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12453 afi_t afi)
12454 {
12455 int indent = 2;
12456
12457 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12458 if (listcount(bgp->vpn_policy[afi].import_vrf))
12459 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12460 bgp->vpn_policy[afi]
12461 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12462 else
12463 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12464 bgp->vpn_policy[afi]
12465 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12466 }
12467 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12468 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12469 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12470 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12471 return;
12472
12473 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12474 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12475
12476 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12477
12478 } else {
12479 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12480 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12481 bgp->vpn_policy[afi].tovpn_label);
12482 }
12483 }
12484 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12485 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12486 char buf[RD_ADDRSTRLEN];
12487 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12488 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12489 sizeof(buf)));
12490 }
12491 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12492 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12493
12494 char buf[PREFIX_STRLEN];
12495 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12496 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12497 sizeof(buf))) {
12498
12499 vty_out(vty, "%*snexthop vpn export %s\n",
12500 indent, "", buf);
12501 }
12502 }
12503 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12504 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12505 && ecommunity_cmp(
12506 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12507 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12508
12509 char *b = ecommunity_ecom2str(
12510 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12511 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12512 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12513 XFREE(MTYPE_ECOMMUNITY_STR, b);
12514 } else {
12515 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12516 char *b = ecommunity_ecom2str(
12517 bgp->vpn_policy[afi]
12518 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12519 ECOMMUNITY_FORMAT_ROUTE_MAP,
12520 ECOMMUNITY_ROUTE_TARGET);
12521 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12522 XFREE(MTYPE_ECOMMUNITY_STR, b);
12523 }
12524 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12525 char *b = ecommunity_ecom2str(
12526 bgp->vpn_policy[afi]
12527 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12528 ECOMMUNITY_FORMAT_ROUTE_MAP,
12529 ECOMMUNITY_ROUTE_TARGET);
12530 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12531 XFREE(MTYPE_ECOMMUNITY_STR, b);
12532 }
12533 }
12534
12535 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12536 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12537 bgp->vpn_policy[afi]
12538 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12539
12540 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12541 char *b = ecommunity_ecom2str(
12542 bgp->vpn_policy[afi]
12543 .import_redirect_rtlist,
12544 ECOMMUNITY_FORMAT_ROUTE_MAP,
12545 ECOMMUNITY_ROUTE_TARGET);
12546
12547 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12548 XFREE(MTYPE_ECOMMUNITY_STR, b);
12549 }
12550 }
12551
12552
12553 /* BGP node structure. */
12554 static struct cmd_node bgp_node = {
12555 BGP_NODE, "%s(config-router)# ", 1,
12556 };
12557
12558 static struct cmd_node bgp_ipv4_unicast_node = {
12559 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12560 };
12561
12562 static struct cmd_node bgp_ipv4_multicast_node = {
12563 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12564 };
12565
12566 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12567 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12568 };
12569
12570 static struct cmd_node bgp_ipv6_unicast_node = {
12571 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12572 };
12573
12574 static struct cmd_node bgp_ipv6_multicast_node = {
12575 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12576 };
12577
12578 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12579 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12580 };
12581
12582 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12583 "%s(config-router-af)# ", 1};
12584
12585 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12586 "%s(config-router-af-vpnv6)# ", 1};
12587
12588 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12589 "%s(config-router-evpn)# ", 1};
12590
12591 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12592 "%s(config-router-af-vni)# ", 1};
12593
12594 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12595 "%s(config-router-af)# ", 1};
12596
12597 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12598 "%s(config-router-af-vpnv6)# ", 1};
12599
12600 static void community_list_vty(void);
12601
12602 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12603 {
12604 struct bgp *bgp;
12605 struct peer *peer;
12606 struct listnode *lnbgp, *lnpeer;
12607
12608 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12609 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12610 /* only provide suggestions on the appropriate input
12611 * token type,
12612 * they'll otherwise show up multiple times */
12613 enum cmd_token_type match_type;
12614 char *name = peer->host;
12615
12616 if (peer->conf_if) {
12617 match_type = VARIABLE_TKN;
12618 name = peer->conf_if;
12619 } else if (strchr(peer->host, ':'))
12620 match_type = IPV6_TKN;
12621 else
12622 match_type = IPV4_TKN;
12623
12624 if (token->type != match_type)
12625 continue;
12626
12627 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12628 }
12629 }
12630 }
12631
12632 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12633 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12634 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12635 {.varname = "peer", .completions = bgp_ac_neighbor},
12636 {.completions = NULL}};
12637
12638 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12639 {
12640 struct bgp *bgp;
12641 struct peer_group *group;
12642 struct listnode *lnbgp, *lnpeer;
12643
12644 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12645 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12646 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12647 group->name));
12648 }
12649 }
12650
12651 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12652 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12653 {.completions = NULL} };
12654
12655 void bgp_vty_init(void)
12656 {
12657 cmd_variable_handler_register(bgp_var_neighbor);
12658 cmd_variable_handler_register(bgp_var_peergroup);
12659
12660 /* Install bgp top node. */
12661 install_node(&bgp_node, bgp_config_write);
12662 install_node(&bgp_ipv4_unicast_node, NULL);
12663 install_node(&bgp_ipv4_multicast_node, NULL);
12664 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12665 install_node(&bgp_ipv6_unicast_node, NULL);
12666 install_node(&bgp_ipv6_multicast_node, NULL);
12667 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12668 install_node(&bgp_vpnv4_node, NULL);
12669 install_node(&bgp_vpnv6_node, NULL);
12670 install_node(&bgp_evpn_node, NULL);
12671 install_node(&bgp_evpn_vni_node, NULL);
12672 install_node(&bgp_flowspecv4_node, NULL);
12673 install_node(&bgp_flowspecv6_node, NULL);
12674
12675 /* Install default VTY commands to new nodes. */
12676 install_default(BGP_NODE);
12677 install_default(BGP_IPV4_NODE);
12678 install_default(BGP_IPV4M_NODE);
12679 install_default(BGP_IPV4L_NODE);
12680 install_default(BGP_IPV6_NODE);
12681 install_default(BGP_IPV6M_NODE);
12682 install_default(BGP_IPV6L_NODE);
12683 install_default(BGP_VPNV4_NODE);
12684 install_default(BGP_VPNV6_NODE);
12685 install_default(BGP_FLOWSPECV4_NODE);
12686 install_default(BGP_FLOWSPECV6_NODE);
12687 install_default(BGP_EVPN_NODE);
12688 install_default(BGP_EVPN_VNI_NODE);
12689
12690 /* "bgp multiple-instance" commands. */
12691 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12692 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12693
12694 /* "bgp config-type" commands. */
12695 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12696 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12697
12698 /* "bgp local-mac" hidden commands. */
12699 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12700 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12701
12702 /* bgp route-map delay-timer commands. */
12703 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12704 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12705
12706 /* Dummy commands (Currently not supported) */
12707 install_element(BGP_NODE, &no_synchronization_cmd);
12708 install_element(BGP_NODE, &no_auto_summary_cmd);
12709
12710 /* "router bgp" commands. */
12711 install_element(CONFIG_NODE, &router_bgp_cmd);
12712
12713 /* "no router bgp" commands. */
12714 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12715
12716 /* "bgp router-id" commands. */
12717 install_element(BGP_NODE, &bgp_router_id_cmd);
12718 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12719
12720 /* "bgp cluster-id" commands. */
12721 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12722 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12723
12724 /* "bgp confederation" commands. */
12725 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12726 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12727
12728 /* "bgp confederation peers" commands. */
12729 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12730 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12731
12732 /* bgp max-med command */
12733 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12734 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12735 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12736 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12737 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12738
12739 /* bgp disable-ebgp-connected-nh-check */
12740 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12741 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12742
12743 /* bgp update-delay command */
12744 install_element(BGP_NODE, &bgp_update_delay_cmd);
12745 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12746 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12747
12748 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12749 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12750 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12751 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12752
12753 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12754 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12755
12756 /* "maximum-paths" commands. */
12757 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12758 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12759 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12760 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12761 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12762 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12763 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12764 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12765 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12766 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12767 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12768 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12769 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12770 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12771 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12772
12773 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12774 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12775 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12776 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12777 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12778
12779 /* "timers bgp" commands. */
12780 install_element(BGP_NODE, &bgp_timers_cmd);
12781 install_element(BGP_NODE, &no_bgp_timers_cmd);
12782
12783 /* route-map delay-timer commands - per instance for backwards compat.
12784 */
12785 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12786 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12787
12788 /* "bgp client-to-client reflection" commands */
12789 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12790 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12791
12792 /* "bgp always-compare-med" commands */
12793 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12794 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12795
12796 /* "bgp deterministic-med" commands */
12797 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12798 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12799
12800 /* "bgp graceful-restart" commands */
12801 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12802 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12803 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12804 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12805 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12806 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12807
12808 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12809 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12810
12811 /* "bgp graceful-shutdown" commands */
12812 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12813 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12814
12815 /* "bgp fast-external-failover" commands */
12816 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12817 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12818
12819 /* "bgp enforce-first-as" commands */
12820 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12821
12822 /* "bgp bestpath compare-routerid" commands */
12823 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12824 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12825
12826 /* "bgp bestpath as-path ignore" commands */
12827 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12828 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12829
12830 /* "bgp bestpath as-path confed" commands */
12831 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12832 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12833
12834 /* "bgp bestpath as-path multipath-relax" commands */
12835 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12836 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12837
12838 /* "bgp log-neighbor-changes" commands */
12839 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12840 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12841
12842 /* "bgp bestpath med" commands */
12843 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12844 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12845
12846 /* "no bgp default ipv4-unicast" commands. */
12847 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12848 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12849
12850 /* "bgp network import-check" commands. */
12851 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12852 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12853 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12854
12855 /* "bgp default local-preference" commands. */
12856 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12857 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12858
12859 /* bgp default show-hostname */
12860 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12861 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12862
12863 /* "bgp default subgroup-pkt-queue-max" commands. */
12864 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12865 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12866
12867 /* bgp ibgp-allow-policy-mods command */
12868 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12869 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12870
12871 /* "bgp listen limit" commands. */
12872 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12873 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12874
12875 /* "bgp listen range" commands. */
12876 install_element(BGP_NODE, &bgp_listen_range_cmd);
12877 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12878
12879 /* "bgp default shutdown" command */
12880 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12881
12882 /* "neighbor remote-as" commands. */
12883 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12884 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12885 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12886 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12887 install_element(BGP_NODE,
12888 &neighbor_interface_v6only_config_remote_as_cmd);
12889 install_element(BGP_NODE, &no_neighbor_cmd);
12890 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12891
12892 /* "neighbor peer-group" commands. */
12893 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12894 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12895 install_element(BGP_NODE,
12896 &no_neighbor_interface_peer_group_remote_as_cmd);
12897
12898 /* "neighbor local-as" commands. */
12899 install_element(BGP_NODE, &neighbor_local_as_cmd);
12900 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12901 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12902 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12903
12904 /* "neighbor solo" commands. */
12905 install_element(BGP_NODE, &neighbor_solo_cmd);
12906 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12907
12908 /* "neighbor password" commands. */
12909 install_element(BGP_NODE, &neighbor_password_cmd);
12910 install_element(BGP_NODE, &no_neighbor_password_cmd);
12911
12912 /* "neighbor activate" commands. */
12913 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12914 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12915 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12916 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12917 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12918 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12919 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12920 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12921 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12922 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12923 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12924 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12925
12926 /* "no neighbor activate" commands. */
12927 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12928 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12929 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12930 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12931 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12932 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12933 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12934 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12935 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12936 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12937 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12938 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12939
12940 /* "neighbor peer-group" set commands. */
12941 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12942 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12943 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12944 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12945 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12946 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12947 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12948 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12949 install_element(BGP_FLOWSPECV4_NODE,
12950 &neighbor_set_peer_group_hidden_cmd);
12951 install_element(BGP_FLOWSPECV6_NODE,
12952 &neighbor_set_peer_group_hidden_cmd);
12953
12954 /* "no neighbor peer-group unset" commands. */
12955 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12956 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12957 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12958 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12959 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12960 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12961 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12962 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12963 install_element(BGP_FLOWSPECV4_NODE,
12964 &no_neighbor_set_peer_group_hidden_cmd);
12965 install_element(BGP_FLOWSPECV6_NODE,
12966 &no_neighbor_set_peer_group_hidden_cmd);
12967
12968 /* "neighbor softreconfiguration inbound" commands.*/
12969 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12970 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12971 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12972 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12973 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12974 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12975 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12976 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12977 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12978 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12979 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12980 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12981 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12982 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12983 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12984 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12985 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12986 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12987 install_element(BGP_FLOWSPECV4_NODE,
12988 &neighbor_soft_reconfiguration_cmd);
12989 install_element(BGP_FLOWSPECV4_NODE,
12990 &no_neighbor_soft_reconfiguration_cmd);
12991 install_element(BGP_FLOWSPECV6_NODE,
12992 &neighbor_soft_reconfiguration_cmd);
12993 install_element(BGP_FLOWSPECV6_NODE,
12994 &no_neighbor_soft_reconfiguration_cmd);
12995
12996 /* "neighbor attribute-unchanged" commands. */
12997 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12998 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12999 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13000 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13001 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13002 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13003 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13004 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13005 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13006 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13007 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13008 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13009 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13010 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13011 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13012 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13013 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13014 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13015
13016 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13017 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13018
13019 /* "nexthop-local unchanged" commands */
13020 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13021 install_element(BGP_IPV6_NODE,
13022 &no_neighbor_nexthop_local_unchanged_cmd);
13023
13024 /* "neighbor next-hop-self" commands. */
13025 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13026 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13027 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13028 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13029 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13030 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13031 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13032 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13033 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13034 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13035 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13036 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13037 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13038 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13039 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13040 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13041 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13042 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13043 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13044 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13045
13046 /* "neighbor next-hop-self force" commands. */
13047 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13048 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13049 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13050 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13051 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13052 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13053 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13054 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13055 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13056 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13057 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13058 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13059 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13060 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13061 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13062 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13063 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13064 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13065
13066 /* "neighbor as-override" commands. */
13067 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13068 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13069 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13070 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13071 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13072 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13073 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13074 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13075 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13076 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13077 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13078 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13079 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13080 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13081 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13082 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13083 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13084 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13085
13086 /* "neighbor remove-private-AS" commands. */
13087 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13088 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13089 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13090 install_element(BGP_NODE,
13091 &no_neighbor_remove_private_as_all_hidden_cmd);
13092 install_element(BGP_NODE,
13093 &neighbor_remove_private_as_replace_as_hidden_cmd);
13094 install_element(BGP_NODE,
13095 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13096 install_element(BGP_NODE,
13097 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13098 install_element(
13099 BGP_NODE,
13100 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13101 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13102 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13103 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13104 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13105 install_element(BGP_IPV4_NODE,
13106 &neighbor_remove_private_as_replace_as_cmd);
13107 install_element(BGP_IPV4_NODE,
13108 &no_neighbor_remove_private_as_replace_as_cmd);
13109 install_element(BGP_IPV4_NODE,
13110 &neighbor_remove_private_as_all_replace_as_cmd);
13111 install_element(BGP_IPV4_NODE,
13112 &no_neighbor_remove_private_as_all_replace_as_cmd);
13113 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13114 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13115 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13116 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13117 install_element(BGP_IPV4M_NODE,
13118 &neighbor_remove_private_as_replace_as_cmd);
13119 install_element(BGP_IPV4M_NODE,
13120 &no_neighbor_remove_private_as_replace_as_cmd);
13121 install_element(BGP_IPV4M_NODE,
13122 &neighbor_remove_private_as_all_replace_as_cmd);
13123 install_element(BGP_IPV4M_NODE,
13124 &no_neighbor_remove_private_as_all_replace_as_cmd);
13125 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13126 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13127 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13128 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13129 install_element(BGP_IPV4L_NODE,
13130 &neighbor_remove_private_as_replace_as_cmd);
13131 install_element(BGP_IPV4L_NODE,
13132 &no_neighbor_remove_private_as_replace_as_cmd);
13133 install_element(BGP_IPV4L_NODE,
13134 &neighbor_remove_private_as_all_replace_as_cmd);
13135 install_element(BGP_IPV4L_NODE,
13136 &no_neighbor_remove_private_as_all_replace_as_cmd);
13137 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13138 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13139 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13140 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13141 install_element(BGP_IPV6_NODE,
13142 &neighbor_remove_private_as_replace_as_cmd);
13143 install_element(BGP_IPV6_NODE,
13144 &no_neighbor_remove_private_as_replace_as_cmd);
13145 install_element(BGP_IPV6_NODE,
13146 &neighbor_remove_private_as_all_replace_as_cmd);
13147 install_element(BGP_IPV6_NODE,
13148 &no_neighbor_remove_private_as_all_replace_as_cmd);
13149 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13150 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13151 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13152 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13153 install_element(BGP_IPV6M_NODE,
13154 &neighbor_remove_private_as_replace_as_cmd);
13155 install_element(BGP_IPV6M_NODE,
13156 &no_neighbor_remove_private_as_replace_as_cmd);
13157 install_element(BGP_IPV6M_NODE,
13158 &neighbor_remove_private_as_all_replace_as_cmd);
13159 install_element(BGP_IPV6M_NODE,
13160 &no_neighbor_remove_private_as_all_replace_as_cmd);
13161 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13162 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13163 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13164 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13165 install_element(BGP_IPV6L_NODE,
13166 &neighbor_remove_private_as_replace_as_cmd);
13167 install_element(BGP_IPV6L_NODE,
13168 &no_neighbor_remove_private_as_replace_as_cmd);
13169 install_element(BGP_IPV6L_NODE,
13170 &neighbor_remove_private_as_all_replace_as_cmd);
13171 install_element(BGP_IPV6L_NODE,
13172 &no_neighbor_remove_private_as_all_replace_as_cmd);
13173 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13174 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13175 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13176 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13177 install_element(BGP_VPNV4_NODE,
13178 &neighbor_remove_private_as_replace_as_cmd);
13179 install_element(BGP_VPNV4_NODE,
13180 &no_neighbor_remove_private_as_replace_as_cmd);
13181 install_element(BGP_VPNV4_NODE,
13182 &neighbor_remove_private_as_all_replace_as_cmd);
13183 install_element(BGP_VPNV4_NODE,
13184 &no_neighbor_remove_private_as_all_replace_as_cmd);
13185 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13186 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13187 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13188 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13189 install_element(BGP_VPNV6_NODE,
13190 &neighbor_remove_private_as_replace_as_cmd);
13191 install_element(BGP_VPNV6_NODE,
13192 &no_neighbor_remove_private_as_replace_as_cmd);
13193 install_element(BGP_VPNV6_NODE,
13194 &neighbor_remove_private_as_all_replace_as_cmd);
13195 install_element(BGP_VPNV6_NODE,
13196 &no_neighbor_remove_private_as_all_replace_as_cmd);
13197
13198 /* "neighbor send-community" commands.*/
13199 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13200 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13201 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13202 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13203 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13204 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13205 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13206 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13207 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13208 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13209 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13210 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13211 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13212 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13213 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13214 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13215 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13216 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13217 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13218 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13219 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13220 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13221 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13222 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13223 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13224 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13225 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13226 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13227 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13228 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13229 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13230 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13231 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13232 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13233 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13234 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13235
13236 /* "neighbor route-reflector" commands.*/
13237 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13238 install_element(BGP_NODE,
13239 &no_neighbor_route_reflector_client_hidden_cmd);
13240 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13241 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13242 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13243 install_element(BGP_IPV4M_NODE,
13244 &no_neighbor_route_reflector_client_cmd);
13245 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13246 install_element(BGP_IPV4L_NODE,
13247 &no_neighbor_route_reflector_client_cmd);
13248 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13249 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13250 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13251 install_element(BGP_IPV6M_NODE,
13252 &no_neighbor_route_reflector_client_cmd);
13253 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13254 install_element(BGP_IPV6L_NODE,
13255 &no_neighbor_route_reflector_client_cmd);
13256 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13257 install_element(BGP_VPNV4_NODE,
13258 &no_neighbor_route_reflector_client_cmd);
13259 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13260 install_element(BGP_VPNV6_NODE,
13261 &no_neighbor_route_reflector_client_cmd);
13262 install_element(BGP_FLOWSPECV4_NODE,
13263 &neighbor_route_reflector_client_cmd);
13264 install_element(BGP_FLOWSPECV4_NODE,
13265 &no_neighbor_route_reflector_client_cmd);
13266 install_element(BGP_FLOWSPECV6_NODE,
13267 &neighbor_route_reflector_client_cmd);
13268 install_element(BGP_FLOWSPECV6_NODE,
13269 &no_neighbor_route_reflector_client_cmd);
13270 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13271 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13272
13273 /* "neighbor route-server" commands.*/
13274 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13275 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13276 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13277 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13278 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13279 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13280 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13281 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13282 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13283 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13284 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13285 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13286 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13287 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13288 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13289 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13290 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13291 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13292 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13293 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13294 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13295 install_element(BGP_FLOWSPECV4_NODE,
13296 &no_neighbor_route_server_client_cmd);
13297 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13298 install_element(BGP_FLOWSPECV6_NODE,
13299 &no_neighbor_route_server_client_cmd);
13300
13301 /* "neighbor addpath-tx-all-paths" commands.*/
13302 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13303 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13304 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13305 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13306 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13307 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13308 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13309 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13310 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13311 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13312 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13313 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13314 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13315 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13316 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13317 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13318 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13319 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13320
13321 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13322 install_element(BGP_NODE,
13323 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13324 install_element(BGP_NODE,
13325 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13326 install_element(BGP_IPV4_NODE,
13327 &neighbor_addpath_tx_bestpath_per_as_cmd);
13328 install_element(BGP_IPV4_NODE,
13329 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13330 install_element(BGP_IPV4M_NODE,
13331 &neighbor_addpath_tx_bestpath_per_as_cmd);
13332 install_element(BGP_IPV4M_NODE,
13333 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13334 install_element(BGP_IPV4L_NODE,
13335 &neighbor_addpath_tx_bestpath_per_as_cmd);
13336 install_element(BGP_IPV4L_NODE,
13337 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13338 install_element(BGP_IPV6_NODE,
13339 &neighbor_addpath_tx_bestpath_per_as_cmd);
13340 install_element(BGP_IPV6_NODE,
13341 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13342 install_element(BGP_IPV6M_NODE,
13343 &neighbor_addpath_tx_bestpath_per_as_cmd);
13344 install_element(BGP_IPV6M_NODE,
13345 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13346 install_element(BGP_IPV6L_NODE,
13347 &neighbor_addpath_tx_bestpath_per_as_cmd);
13348 install_element(BGP_IPV6L_NODE,
13349 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13350 install_element(BGP_VPNV4_NODE,
13351 &neighbor_addpath_tx_bestpath_per_as_cmd);
13352 install_element(BGP_VPNV4_NODE,
13353 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13354 install_element(BGP_VPNV6_NODE,
13355 &neighbor_addpath_tx_bestpath_per_as_cmd);
13356 install_element(BGP_VPNV6_NODE,
13357 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13358
13359 /* "neighbor passive" commands. */
13360 install_element(BGP_NODE, &neighbor_passive_cmd);
13361 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13362
13363
13364 /* "neighbor shutdown" commands. */
13365 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13366 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13367 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13368 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13369
13370 /* "neighbor capability extended-nexthop" commands.*/
13371 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13372 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13373
13374 /* "neighbor capability orf prefix-list" commands.*/
13375 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13376 install_element(BGP_NODE,
13377 &no_neighbor_capability_orf_prefix_hidden_cmd);
13378 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13379 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13380 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13381 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13382 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13383 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13384 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13385 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13386 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13387 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13388 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13389 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13390
13391 /* "neighbor capability dynamic" commands.*/
13392 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13393 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13394
13395 /* "neighbor dont-capability-negotiate" commands. */
13396 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13397 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13398
13399 /* "neighbor ebgp-multihop" commands. */
13400 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13401 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13402 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13403
13404 /* "neighbor disable-connected-check" commands. */
13405 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13406 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13407
13408 /* "neighbor enforce-first-as" commands. */
13409 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13410 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13411
13412 /* "neighbor description" commands. */
13413 install_element(BGP_NODE, &neighbor_description_cmd);
13414 install_element(BGP_NODE, &no_neighbor_description_cmd);
13415 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13416
13417 /* "neighbor update-source" commands. "*/
13418 install_element(BGP_NODE, &neighbor_update_source_cmd);
13419 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13420
13421 /* "neighbor default-originate" commands. */
13422 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13423 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13424 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13425 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13426 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13427 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13428 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13429 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13430 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13431 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13432 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13433 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13434 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13435 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13436 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13437 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13438 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13439 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13440 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13441 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13442 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13443
13444 /* "neighbor port" commands. */
13445 install_element(BGP_NODE, &neighbor_port_cmd);
13446 install_element(BGP_NODE, &no_neighbor_port_cmd);
13447
13448 /* "neighbor weight" commands. */
13449 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13450 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13451
13452 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13453 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13454 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13455 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13456 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13457 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13458 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13459 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13460 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13461 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13462 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13463 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13464 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13465 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13466 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13467 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13468
13469 /* "neighbor override-capability" commands. */
13470 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13471 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13472
13473 /* "neighbor strict-capability-match" commands. */
13474 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13475 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13476
13477 /* "neighbor timers" commands. */
13478 install_element(BGP_NODE, &neighbor_timers_cmd);
13479 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13480
13481 /* "neighbor timers connect" commands. */
13482 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13483 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13484
13485 /* "neighbor advertisement-interval" commands. */
13486 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13487 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13488
13489 /* "neighbor interface" commands. */
13490 install_element(BGP_NODE, &neighbor_interface_cmd);
13491 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13492
13493 /* "neighbor distribute" commands. */
13494 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13495 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13496 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13497 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13498 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13499 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13500 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13501 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13502 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13503 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13504 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13505 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13506 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13507 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13508 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13509 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13510 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13511 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13512
13513 /* "neighbor prefix-list" commands. */
13514 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13515 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13516 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13517 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13518 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13519 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13520 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13521 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13522 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13523 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13524 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13525 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13526 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13527 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13528 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13529 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13530 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13531 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13532 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13533 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13534 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13535 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13536
13537 /* "neighbor filter-list" commands. */
13538 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13539 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13540 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13541 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13542 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13543 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13544 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13545 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13546 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13547 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13548 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13549 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13550 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13551 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13552 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13553 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13554 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13555 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13556 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13557 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13558 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13559 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13560
13561 /* "neighbor route-map" commands. */
13562 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13563 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13564 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13565 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13566 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13567 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13568 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13569 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13570 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13571 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13572 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13573 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13574 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13575 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13576 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13577 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13578 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13579 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13580 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13581 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13582 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13583 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13584 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13585 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13586
13587 /* "neighbor unsuppress-map" commands. */
13588 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13589 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13590 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13591 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13592 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13593 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13594 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13595 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13596 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13597 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13598 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13599 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13600 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13601 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13602 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13603 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13604 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13605 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13606
13607 /* "neighbor maximum-prefix" commands. */
13608 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13609 install_element(BGP_NODE,
13610 &neighbor_maximum_prefix_threshold_hidden_cmd);
13611 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13612 install_element(BGP_NODE,
13613 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13614 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13615 install_element(BGP_NODE,
13616 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13617 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13618 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13619 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13620 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13621 install_element(BGP_IPV4_NODE,
13622 &neighbor_maximum_prefix_threshold_warning_cmd);
13623 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13624 install_element(BGP_IPV4_NODE,
13625 &neighbor_maximum_prefix_threshold_restart_cmd);
13626 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13627 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13628 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13629 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13630 install_element(BGP_IPV4M_NODE,
13631 &neighbor_maximum_prefix_threshold_warning_cmd);
13632 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13633 install_element(BGP_IPV4M_NODE,
13634 &neighbor_maximum_prefix_threshold_restart_cmd);
13635 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13636 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13637 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13638 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13639 install_element(BGP_IPV4L_NODE,
13640 &neighbor_maximum_prefix_threshold_warning_cmd);
13641 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13642 install_element(BGP_IPV4L_NODE,
13643 &neighbor_maximum_prefix_threshold_restart_cmd);
13644 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13645 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13646 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13647 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13648 install_element(BGP_IPV6_NODE,
13649 &neighbor_maximum_prefix_threshold_warning_cmd);
13650 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13651 install_element(BGP_IPV6_NODE,
13652 &neighbor_maximum_prefix_threshold_restart_cmd);
13653 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13654 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13655 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13656 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13657 install_element(BGP_IPV6M_NODE,
13658 &neighbor_maximum_prefix_threshold_warning_cmd);
13659 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13660 install_element(BGP_IPV6M_NODE,
13661 &neighbor_maximum_prefix_threshold_restart_cmd);
13662 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13663 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13664 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13665 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13666 install_element(BGP_IPV6L_NODE,
13667 &neighbor_maximum_prefix_threshold_warning_cmd);
13668 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13669 install_element(BGP_IPV6L_NODE,
13670 &neighbor_maximum_prefix_threshold_restart_cmd);
13671 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13672 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13673 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13674 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13675 install_element(BGP_VPNV4_NODE,
13676 &neighbor_maximum_prefix_threshold_warning_cmd);
13677 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13678 install_element(BGP_VPNV4_NODE,
13679 &neighbor_maximum_prefix_threshold_restart_cmd);
13680 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13681 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13682 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13683 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13684 install_element(BGP_VPNV6_NODE,
13685 &neighbor_maximum_prefix_threshold_warning_cmd);
13686 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13687 install_element(BGP_VPNV6_NODE,
13688 &neighbor_maximum_prefix_threshold_restart_cmd);
13689 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13690
13691 /* "neighbor allowas-in" */
13692 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13693 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13694 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13695 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13696 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13697 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13698 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13699 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13700 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13701 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13702 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13703 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13704 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13705 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13706 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13707 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13708 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13709 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13710 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13711 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13712
13713 /* address-family commands. */
13714 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13715 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13716 #ifdef KEEP_OLD_VPN_COMMANDS
13717 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13718 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13719 #endif /* KEEP_OLD_VPN_COMMANDS */
13720
13721 install_element(BGP_NODE, &address_family_evpn_cmd);
13722
13723 /* "exit-address-family" command. */
13724 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13725 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13726 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13727 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13728 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13729 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13730 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13731 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13732 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13733 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13734 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13735
13736 /* "clear ip bgp commands" */
13737 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13738
13739 /* clear ip bgp prefix */
13740 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13741 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13742 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13743
13744 /* "show [ip] bgp summary" commands. */
13745 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13746 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13747 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13748 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13749 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13750 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13751 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13752
13753 /* "show [ip] bgp neighbors" commands. */
13754 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13755
13756 /* "show [ip] bgp peer-group" commands. */
13757 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13758
13759 /* "show [ip] bgp paths" commands. */
13760 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13761
13762 /* "show [ip] bgp community" commands. */
13763 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13764
13765 /* "show ip bgp large-community" commands. */
13766 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13767 /* "show [ip] bgp attribute-info" commands. */
13768 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13769 /* "show [ip] bgp route-leak" command */
13770 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13771
13772 /* "redistribute" commands. */
13773 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13774 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13775 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13776 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13777 install_element(BGP_NODE,
13778 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13779 install_element(BGP_NODE,
13780 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13781 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13782 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13783 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13784 install_element(BGP_NODE,
13785 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13786 install_element(BGP_NODE,
13787 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13788 install_element(BGP_NODE,
13789 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13790 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13791 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13792 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13793 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13794 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13795 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13796 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13797 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13798 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13799 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13800 install_element(BGP_IPV4_NODE,
13801 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13802 install_element(BGP_IPV4_NODE,
13803 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13804 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13805 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13806 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13807 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13808 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13809 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13810
13811 /* import|export vpn [route-map WORD] */
13812 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13813 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13814
13815 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13816 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13817
13818 /* ttl_security commands */
13819 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13820 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13821
13822 /* "show [ip] bgp memory" commands. */
13823 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13824
13825 /* "show bgp martian next-hop" */
13826 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13827
13828 /* "show [ip] bgp views" commands. */
13829 install_element(VIEW_NODE, &show_bgp_views_cmd);
13830
13831 /* "show [ip] bgp vrfs" commands. */
13832 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13833
13834 /* Community-list. */
13835 community_list_vty();
13836
13837 /* vpn-policy commands */
13838 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13839 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13840 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13841 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13842 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13843 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13844 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13845 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13846 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13847 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13848 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13849 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13850
13851 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13852 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13853
13854 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13855 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13856 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13857 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13858 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13859 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13860 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13861 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13862 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13863 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13864 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13865 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13866 }
13867
13868 #include "memory.h"
13869 #include "bgp_regex.h"
13870 #include "bgp_clist.h"
13871 #include "bgp_ecommunity.h"
13872
13873 /* VTY functions. */
13874
13875 /* Direction value to string conversion. */
13876 static const char *community_direct_str(int direct)
13877 {
13878 switch (direct) {
13879 case COMMUNITY_DENY:
13880 return "deny";
13881 case COMMUNITY_PERMIT:
13882 return "permit";
13883 default:
13884 return "unknown";
13885 }
13886 }
13887
13888 /* Display error string. */
13889 static void community_list_perror(struct vty *vty, int ret)
13890 {
13891 switch (ret) {
13892 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13893 vty_out(vty, "%% Can't find community-list\n");
13894 break;
13895 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13896 vty_out(vty, "%% Malformed community-list value\n");
13897 break;
13898 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13899 vty_out(vty,
13900 "%% Community name conflict, previously defined as standard community\n");
13901 break;
13902 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13903 vty_out(vty,
13904 "%% Community name conflict, previously defined as expanded community\n");
13905 break;
13906 }
13907 }
13908
13909 /* "community-list" keyword help string. */
13910 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13911
13912 /*community-list standard */
13913 DEFUN (community_list_standard,
13914 bgp_community_list_standard_cmd,
13915 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13916 BGP_STR
13917 COMMUNITY_LIST_STR
13918 "Community list number (standard)\n"
13919 "Add an standard community-list entry\n"
13920 "Community list name\n"
13921 "Specify community to reject\n"
13922 "Specify community to accept\n"
13923 COMMUNITY_VAL_STR)
13924 {
13925 char *cl_name_or_number = NULL;
13926 int direct = 0;
13927 int style = COMMUNITY_LIST_STANDARD;
13928
13929 int idx = 0;
13930
13931 if (argv_find(argv, argc, "ip", &idx)) {
13932 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13933 vty_out(vty, "if you are using this please migrate to the below command.\n");
13934 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13935 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13936 }
13937
13938 argv_find(argv, argc, "(1-99)", &idx);
13939 argv_find(argv, argc, "WORD", &idx);
13940 cl_name_or_number = argv[idx]->arg;
13941 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13942 : COMMUNITY_DENY;
13943 argv_find(argv, argc, "AA:NN", &idx);
13944 char *str = argv_concat(argv, argc, idx);
13945
13946 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13947 style);
13948
13949 XFREE(MTYPE_TMP, str);
13950
13951 if (ret < 0) {
13952 /* Display error string. */
13953 community_list_perror(vty, ret);
13954 return CMD_WARNING_CONFIG_FAILED;
13955 }
13956
13957 return CMD_SUCCESS;
13958 }
13959
13960 #if CONFDATE > 20191005
13961 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
13962 #endif
13963 ALIAS (community_list_standard,
13964 ip_community_list_standard_cmd,
13965 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13966 IP_STR
13967 COMMUNITY_LIST_STR
13968 "Community list number (standard)\n"
13969 "Add an standard community-list entry\n"
13970 "Community list name\n"
13971 "Specify community to reject\n"
13972 "Specify community to accept\n"
13973 COMMUNITY_VAL_STR)
13974
13975 DEFUN (no_community_list_standard_all,
13976 no_bgp_community_list_standard_all_cmd,
13977 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13978 NO_STR
13979 BGP_STR
13980 COMMUNITY_LIST_STR
13981 "Community list number (standard)\n"
13982 "Add an standard community-list entry\n"
13983 "Community list name\n"
13984 "Specify community to reject\n"
13985 "Specify community to accept\n"
13986 COMMUNITY_VAL_STR)
13987 {
13988 char *cl_name_or_number = NULL;
13989 char *str = NULL;
13990 int direct = 0;
13991 int style = COMMUNITY_LIST_STANDARD;
13992
13993 int idx = 0;
13994
13995 if (argv_find(argv, argc, "ip", &idx)) {
13996 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
13997 vty_out(vty, "if you are using this please migrate to the below command.\n");
13998 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13999 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14000 }
14001
14002 argv_find(argv, argc, "permit", &idx);
14003 argv_find(argv, argc, "deny", &idx);
14004
14005 if (idx) {
14006 direct = argv_find(argv, argc, "permit", &idx)
14007 ? COMMUNITY_PERMIT
14008 : COMMUNITY_DENY;
14009
14010 idx = 0;
14011 argv_find(argv, argc, "AA:NN", &idx);
14012 str = argv_concat(argv, argc, idx);
14013 }
14014
14015 idx = 0;
14016 argv_find(argv, argc, "(1-99)", &idx);
14017 argv_find(argv, argc, "WORD", &idx);
14018 cl_name_or_number = argv[idx]->arg;
14019
14020 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14021 direct, style);
14022
14023 XFREE(MTYPE_TMP, str);
14024
14025 if (ret < 0) {
14026 community_list_perror(vty, ret);
14027 return CMD_WARNING_CONFIG_FAILED;
14028 }
14029
14030 return CMD_SUCCESS;
14031 }
14032 ALIAS (no_community_list_standard_all,
14033 no_ip_community_list_standard_all_cmd,
14034 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14035 NO_STR
14036 IP_STR
14037 COMMUNITY_LIST_STR
14038 "Community list number (standard)\n"
14039 "Add an standard community-list entry\n"
14040 "Community list name\n"
14041 "Specify community to reject\n"
14042 "Specify community to accept\n"
14043 COMMUNITY_VAL_STR)
14044
14045 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14046 "no bgp community-list <(1-99)|standard WORD>",
14047 NO_STR BGP_STR COMMUNITY_LIST_STR
14048 "Community list number (standard)\n"
14049 "Add an standard community-list entry\n"
14050 "Community list name\n")
14051
14052 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14053 "no ip 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 /*community-list expanded */
14060 DEFUN (community_list_expanded_all,
14061 bgp_community_list_expanded_all_cmd,
14062 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14063 BGP_STR
14064 COMMUNITY_LIST_STR
14065 "Community list number (expanded)\n"
14066 "Add an expanded community-list entry\n"
14067 "Community list name\n"
14068 "Specify community to reject\n"
14069 "Specify community to accept\n"
14070 COMMUNITY_VAL_STR)
14071 {
14072 char *cl_name_or_number = NULL;
14073 int direct = 0;
14074 int style = COMMUNITY_LIST_EXPANDED;
14075
14076 int idx = 0;
14077 if (argv_find(argv, argc, "ip", &idx)) {
14078 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14079 vty_out(vty, "if you are using this please migrate to the below command.\n");
14080 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14081 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14082 }
14083 argv_find(argv, argc, "(100-500)", &idx);
14084 argv_find(argv, argc, "WORD", &idx);
14085 cl_name_or_number = argv[idx]->arg;
14086 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14087 : COMMUNITY_DENY;
14088 argv_find(argv, argc, "AA:NN", &idx);
14089 char *str = argv_concat(argv, argc, idx);
14090
14091 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14092 style);
14093
14094 XFREE(MTYPE_TMP, str);
14095
14096 if (ret < 0) {
14097 /* Display error string. */
14098 community_list_perror(vty, ret);
14099 return CMD_WARNING_CONFIG_FAILED;
14100 }
14101
14102 return CMD_SUCCESS;
14103 }
14104
14105 ALIAS (community_list_expanded_all,
14106 ip_community_list_expanded_all_cmd,
14107 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14108 IP_STR
14109 COMMUNITY_LIST_STR
14110 "Community list number (expanded)\n"
14111 "Add an expanded community-list entry\n"
14112 "Community list name\n"
14113 "Specify community to reject\n"
14114 "Specify community to accept\n"
14115 COMMUNITY_VAL_STR)
14116
14117 DEFUN (no_community_list_expanded_all,
14118 no_bgp_community_list_expanded_all_cmd,
14119 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14120 NO_STR
14121 BGP_STR
14122 COMMUNITY_LIST_STR
14123 "Community list number (expanded)\n"
14124 "Add an expanded community-list entry\n"
14125 "Community list name\n"
14126 "Specify community to reject\n"
14127 "Specify community to accept\n"
14128 COMMUNITY_VAL_STR)
14129 {
14130 char *cl_name_or_number = NULL;
14131 char *str = NULL;
14132 int direct = 0;
14133 int style = COMMUNITY_LIST_EXPANDED;
14134
14135 int idx = 0;
14136 if (argv_find(argv, argc, "ip", &idx)) {
14137 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14138 vty_out(vty, "if you are using this please migrate to the below command.\n");
14139 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14140 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14141 }
14142
14143 argv_find(argv, argc, "permit", &idx);
14144 argv_find(argv, argc, "deny", &idx);
14145
14146 if (idx) {
14147 direct = argv_find(argv, argc, "permit", &idx)
14148 ? COMMUNITY_PERMIT
14149 : COMMUNITY_DENY;
14150
14151 idx = 0;
14152 argv_find(argv, argc, "AA:NN", &idx);
14153 str = argv_concat(argv, argc, idx);
14154 }
14155
14156 idx = 0;
14157 argv_find(argv, argc, "(100-500)", &idx);
14158 argv_find(argv, argc, "WORD", &idx);
14159 cl_name_or_number = argv[idx]->arg;
14160
14161 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14162 direct, style);
14163
14164 XFREE(MTYPE_TMP, str);
14165
14166 if (ret < 0) {
14167 community_list_perror(vty, ret);
14168 return CMD_WARNING_CONFIG_FAILED;
14169 }
14170
14171 return CMD_SUCCESS;
14172 }
14173
14174 ALIAS (no_community_list_expanded_all,
14175 no_ip_community_list_expanded_all_cmd,
14176 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14177 NO_STR
14178 IP_STR
14179 COMMUNITY_LIST_STR
14180 "Community list number (expanded)\n"
14181 "Add an expanded community-list entry\n"
14182 "Community list name\n"
14183 "Specify community to reject\n"
14184 "Specify community to accept\n"
14185 COMMUNITY_VAL_STR)
14186
14187 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14188 "no bgp community-list <(100-500)|expanded WORD>",
14189 NO_STR IP_STR COMMUNITY_LIST_STR
14190 "Community list number (expanded)\n"
14191 "Add an expanded community-list entry\n"
14192 "Community list name\n")
14193
14194 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14195 "no ip community-list <(100-500)|expanded WORD>",
14196 NO_STR IP_STR COMMUNITY_LIST_STR
14197 "Community list number (expanded)\n"
14198 "Add an expanded community-list entry\n"
14199 "Community list name\n")
14200
14201 /* Return configuration string of community-list entry. */
14202 static const char *community_list_config_str(struct community_entry *entry)
14203 {
14204 const char *str;
14205
14206 if (entry->any)
14207 str = "";
14208 else {
14209 if (entry->style == COMMUNITY_LIST_STANDARD)
14210 str = community_str(entry->u.com, false);
14211 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14212 str = lcommunity_str(entry->u.lcom, false);
14213 else
14214 str = entry->config;
14215 }
14216 return str;
14217 }
14218
14219 static void community_list_show(struct vty *vty, struct community_list *list)
14220 {
14221 struct community_entry *entry;
14222
14223 for (entry = list->head; entry; entry = entry->next) {
14224 if (entry == list->head) {
14225 if (all_digit(list->name))
14226 vty_out(vty, "Community %s list %s\n",
14227 entry->style == COMMUNITY_LIST_STANDARD
14228 ? "standard"
14229 : "(expanded) access",
14230 list->name);
14231 else
14232 vty_out(vty, "Named Community %s list %s\n",
14233 entry->style == COMMUNITY_LIST_STANDARD
14234 ? "standard"
14235 : "expanded",
14236 list->name);
14237 }
14238 if (entry->any)
14239 vty_out(vty, " %s\n",
14240 community_direct_str(entry->direct));
14241 else
14242 vty_out(vty, " %s %s\n",
14243 community_direct_str(entry->direct),
14244 community_list_config_str(entry));
14245 }
14246 }
14247
14248 DEFUN (show_community_list,
14249 show_bgp_community_list_cmd,
14250 "show bgp community-list",
14251 SHOW_STR
14252 BGP_STR
14253 "List community-list\n")
14254 {
14255 struct community_list *list;
14256 struct community_list_master *cm;
14257
14258 int idx = 0;
14259 if (argv_find(argv, argc, "ip", &idx)) {
14260 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14261 vty_out(vty, "if you are using this please migrate to the below command.\n");
14262 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14263 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14264 }
14265 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14266 if (!cm)
14267 return CMD_SUCCESS;
14268
14269 for (list = cm->num.head; list; list = list->next)
14270 community_list_show(vty, list);
14271
14272 for (list = cm->str.head; list; list = list->next)
14273 community_list_show(vty, list);
14274
14275 return CMD_SUCCESS;
14276 }
14277
14278 ALIAS (show_community_list,
14279 show_ip_community_list_cmd,
14280 "show ip community-list",
14281 SHOW_STR
14282 IP_STR
14283 "List community-list\n")
14284
14285 DEFUN (show_community_list_arg,
14286 show_bgp_community_list_arg_cmd,
14287 "show bgp community-list <(1-500)|WORD>",
14288 SHOW_STR
14289 BGP_STR
14290 "List community-list\n"
14291 "Community-list number\n"
14292 "Community-list name\n")
14293 {
14294 int idx_comm_list = 3;
14295 struct community_list *list;
14296
14297 int idx = 0;
14298 if (argv_find(argv, argc, "ip", &idx)) {
14299 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14300 vty_out(vty, "if you are using this please migrate to the below command.\n");
14301 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14302 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14303 }
14304 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14305 COMMUNITY_LIST_MASTER);
14306 if (!list) {
14307 vty_out(vty, "%% Can't find community-list\n");
14308 return CMD_WARNING;
14309 }
14310
14311 community_list_show(vty, list);
14312
14313 return CMD_SUCCESS;
14314 }
14315
14316 ALIAS (show_community_list_arg,
14317 show_ip_community_list_arg_cmd,
14318 "show ip community-list <(1-500)|WORD>",
14319 SHOW_STR
14320 IP_STR
14321 "List community-list\n"
14322 "Community-list number\n"
14323 "Community-list name\n")
14324
14325 /*
14326 * Large Community code.
14327 */
14328 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14329 struct cmd_token **argv, int style,
14330 int reject_all_digit_name)
14331 {
14332 int ret;
14333 int direct;
14334 char *str;
14335 int idx = 0;
14336 char *cl_name;
14337
14338 if (argv_find(argv, argc, "ip", &idx)) {
14339 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14340 vty_out(vty, "if you are using this please migrate to the below command.\n");
14341 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14342 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14343 }
14344 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14345 : COMMUNITY_DENY;
14346
14347 /* All digit name check. */
14348 idx = 0;
14349 argv_find(argv, argc, "WORD", &idx);
14350 argv_find(argv, argc, "(1-99)", &idx);
14351 argv_find(argv, argc, "(100-500)", &idx);
14352 cl_name = argv[idx]->arg;
14353 if (reject_all_digit_name && all_digit(cl_name)) {
14354 vty_out(vty, "%% Community name cannot have all digits\n");
14355 return CMD_WARNING_CONFIG_FAILED;
14356 }
14357
14358 idx = 0;
14359 argv_find(argv, argc, "AA:BB:CC", &idx);
14360 argv_find(argv, argc, "LINE", &idx);
14361 /* Concat community string argument. */
14362 if (idx)
14363 str = argv_concat(argv, argc, idx);
14364 else
14365 str = NULL;
14366
14367 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14368
14369 /* Free temporary community list string allocated by
14370 argv_concat(). */
14371 if (str)
14372 XFREE(MTYPE_TMP, str);
14373
14374 if (ret < 0) {
14375 community_list_perror(vty, ret);
14376 return CMD_WARNING_CONFIG_FAILED;
14377 }
14378 return CMD_SUCCESS;
14379 }
14380
14381 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14382 struct cmd_token **argv, int style)
14383 {
14384 int ret;
14385 int direct = 0;
14386 char *str = NULL;
14387 int idx = 0;
14388
14389 if (argv_find(argv, argc, "ip", &idx)) {
14390 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14391 vty_out(vty, "if you are using this please migrate to the below command.\n");
14392 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14393 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14394 }
14395 argv_find(argv, argc, "permit", &idx);
14396 argv_find(argv, argc, "deny", &idx);
14397
14398 if (idx) {
14399 /* Check the list direct. */
14400 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14401 direct = COMMUNITY_PERMIT;
14402 else
14403 direct = COMMUNITY_DENY;
14404
14405 idx = 0;
14406 argv_find(argv, argc, "LINE", &idx);
14407 argv_find(argv, argc, "AA:AA:NN", &idx);
14408 /* Concat community string argument. */
14409 str = argv_concat(argv, argc, idx);
14410 }
14411
14412 idx = 0;
14413 argv_find(argv, argc, "(1-99)", &idx);
14414 argv_find(argv, argc, "(100-500)", &idx);
14415 argv_find(argv, argc, "WORD", &idx);
14416
14417 /* Unset community list. */
14418 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14419 style);
14420
14421 /* Free temporary community list string allocated by
14422 argv_concat(). */
14423 if (str)
14424 XFREE(MTYPE_TMP, str);
14425
14426 if (ret < 0) {
14427 community_list_perror(vty, ret);
14428 return CMD_WARNING_CONFIG_FAILED;
14429 }
14430
14431 return CMD_SUCCESS;
14432 }
14433
14434 /* "large-community-list" keyword help string. */
14435 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14436 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14437
14438 #if CONFDATE > 20191005
14439 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14440 #endif
14441 DEFUN (lcommunity_list_standard,
14442 bgp_lcommunity_list_standard_cmd,
14443 "bgp large-community-list (1-99) <deny|permit>",
14444 BGP_STR
14445 LCOMMUNITY_LIST_STR
14446 "Large Community list number (standard)\n"
14447 "Specify large community to reject\n"
14448 "Specify large community to accept\n")
14449 {
14450 return lcommunity_list_set_vty(vty, argc, argv,
14451 LARGE_COMMUNITY_LIST_STANDARD, 0);
14452 }
14453
14454 ALIAS (lcommunity_list_standard,
14455 ip_lcommunity_list_standard_cmd,
14456 "ip large-community-list (1-99) <deny|permit>",
14457 IP_STR
14458 LCOMMUNITY_LIST_STR
14459 "Large Community list number (standard)\n"
14460 "Specify large community to reject\n"
14461 "Specify large community to accept\n")
14462
14463 DEFUN (lcommunity_list_standard1,
14464 bgp_lcommunity_list_standard1_cmd,
14465 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14466 BGP_STR
14467 LCOMMUNITY_LIST_STR
14468 "Large Community list number (standard)\n"
14469 "Specify large community to reject\n"
14470 "Specify large community to accept\n"
14471 LCOMMUNITY_VAL_STR)
14472 {
14473 return lcommunity_list_set_vty(vty, argc, argv,
14474 LARGE_COMMUNITY_LIST_STANDARD, 0);
14475 }
14476
14477 ALIAS (lcommunity_list_standard1,
14478 ip_lcommunity_list_standard1_cmd,
14479 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14480 IP_STR
14481 LCOMMUNITY_LIST_STR
14482 "Large Community list number (standard)\n"
14483 "Specify large community to reject\n"
14484 "Specify large community to accept\n"
14485 LCOMMUNITY_VAL_STR)
14486
14487 DEFUN (lcommunity_list_expanded,
14488 bgp_lcommunity_list_expanded_cmd,
14489 "bgp large-community-list (100-500) <deny|permit> LINE...",
14490 BGP_STR
14491 LCOMMUNITY_LIST_STR
14492 "Large Community list number (expanded)\n"
14493 "Specify large community to reject\n"
14494 "Specify large community to accept\n"
14495 "An ordered list as a regular-expression\n")
14496 {
14497 return lcommunity_list_set_vty(vty, argc, argv,
14498 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14499 }
14500
14501 ALIAS (lcommunity_list_expanded,
14502 ip_lcommunity_list_expanded_cmd,
14503 "ip large-community-list (100-500) <deny|permit> LINE...",
14504 IP_STR
14505 LCOMMUNITY_LIST_STR
14506 "Large Community list number (expanded)\n"
14507 "Specify large community to reject\n"
14508 "Specify large community to accept\n"
14509 "An ordered list as a regular-expression\n")
14510
14511 DEFUN (lcommunity_list_name_standard,
14512 bgp_lcommunity_list_name_standard_cmd,
14513 "bgp large-community-list standard WORD <deny|permit>",
14514 BGP_STR
14515 LCOMMUNITY_LIST_STR
14516 "Specify standard large-community-list\n"
14517 "Large Community list name\n"
14518 "Specify large community to reject\n"
14519 "Specify large community to accept\n")
14520 {
14521 return lcommunity_list_set_vty(vty, argc, argv,
14522 LARGE_COMMUNITY_LIST_STANDARD, 1);
14523 }
14524
14525 ALIAS (lcommunity_list_name_standard,
14526 ip_lcommunity_list_name_standard_cmd,
14527 "ip large-community-list standard WORD <deny|permit>",
14528 IP_STR
14529 LCOMMUNITY_LIST_STR
14530 "Specify standard large-community-list\n"
14531 "Large Community list name\n"
14532 "Specify large community to reject\n"
14533 "Specify large community to accept\n")
14534
14535 DEFUN (lcommunity_list_name_standard1,
14536 bgp_lcommunity_list_name_standard1_cmd,
14537 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14538 BGP_STR
14539 LCOMMUNITY_LIST_STR
14540 "Specify standard large-community-list\n"
14541 "Large Community list name\n"
14542 "Specify large community to reject\n"
14543 "Specify large community to accept\n"
14544 LCOMMUNITY_VAL_STR)
14545 {
14546 return lcommunity_list_set_vty(vty, argc, argv,
14547 LARGE_COMMUNITY_LIST_STANDARD, 1);
14548 }
14549
14550 ALIAS (lcommunity_list_name_standard1,
14551 ip_lcommunity_list_name_standard1_cmd,
14552 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14553 IP_STR
14554 LCOMMUNITY_LIST_STR
14555 "Specify standard large-community-list\n"
14556 "Large Community list name\n"
14557 "Specify large community to reject\n"
14558 "Specify large community to accept\n"
14559 LCOMMUNITY_VAL_STR)
14560
14561 DEFUN (lcommunity_list_name_expanded,
14562 bgp_lcommunity_list_name_expanded_cmd,
14563 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14564 BGP_STR
14565 LCOMMUNITY_LIST_STR
14566 "Specify expanded large-community-list\n"
14567 "Large Community list name\n"
14568 "Specify large community to reject\n"
14569 "Specify large community to accept\n"
14570 "An ordered list as a regular-expression\n")
14571 {
14572 return lcommunity_list_set_vty(vty, argc, argv,
14573 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14574 }
14575
14576 ALIAS (lcommunity_list_name_expanded,
14577 ip_lcommunity_list_name_expanded_cmd,
14578 "ip large-community-list expanded WORD <deny|permit> LINE...",
14579 IP_STR
14580 LCOMMUNITY_LIST_STR
14581 "Specify expanded large-community-list\n"
14582 "Large Community list name\n"
14583 "Specify large community to reject\n"
14584 "Specify large community to accept\n"
14585 "An ordered list as a regular-expression\n")
14586
14587 DEFUN (no_lcommunity_list_standard_all,
14588 no_bgp_lcommunity_list_standard_all_cmd,
14589 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14590 NO_STR
14591 BGP_STR
14592 LCOMMUNITY_LIST_STR
14593 "Large Community list number (standard)\n"
14594 "Large Community list number (expanded)\n"
14595 "Large Community list name\n")
14596 {
14597 return lcommunity_list_unset_vty(vty, argc, argv,
14598 LARGE_COMMUNITY_LIST_STANDARD);
14599 }
14600
14601 ALIAS (no_lcommunity_list_standard_all,
14602 no_ip_lcommunity_list_standard_all_cmd,
14603 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14604 NO_STR
14605 IP_STR
14606 LCOMMUNITY_LIST_STR
14607 "Large Community list number (standard)\n"
14608 "Large Community list number (expanded)\n"
14609 "Large Community list name\n")
14610
14611 DEFUN (no_lcommunity_list_name_expanded_all,
14612 no_bgp_lcommunity_list_name_expanded_all_cmd,
14613 "no bgp large-community-list expanded WORD",
14614 NO_STR
14615 BGP_STR
14616 LCOMMUNITY_LIST_STR
14617 "Specify expanded large-community-list\n"
14618 "Large Community list name\n")
14619 {
14620 return lcommunity_list_unset_vty(vty, argc, argv,
14621 LARGE_COMMUNITY_LIST_EXPANDED);
14622 }
14623
14624 ALIAS (no_lcommunity_list_name_expanded_all,
14625 no_ip_lcommunity_list_name_expanded_all_cmd,
14626 "no ip large-community-list expanded WORD",
14627 NO_STR
14628 IP_STR
14629 LCOMMUNITY_LIST_STR
14630 "Specify expanded large-community-list\n"
14631 "Large Community list name\n")
14632
14633 DEFUN (no_lcommunity_list_standard,
14634 no_bgp_lcommunity_list_standard_cmd,
14635 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14636 NO_STR
14637 BGP_STR
14638 LCOMMUNITY_LIST_STR
14639 "Large Community list number (standard)\n"
14640 "Specify large community to reject\n"
14641 "Specify large community to accept\n"
14642 LCOMMUNITY_VAL_STR)
14643 {
14644 return lcommunity_list_unset_vty(vty, argc, argv,
14645 LARGE_COMMUNITY_LIST_STANDARD);
14646 }
14647
14648 ALIAS (no_lcommunity_list_standard,
14649 no_ip_lcommunity_list_standard_cmd,
14650 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14651 NO_STR
14652 IP_STR
14653 LCOMMUNITY_LIST_STR
14654 "Large Community list number (standard)\n"
14655 "Specify large community to reject\n"
14656 "Specify large community to accept\n"
14657 LCOMMUNITY_VAL_STR)
14658
14659 DEFUN (no_lcommunity_list_expanded,
14660 no_bgp_lcommunity_list_expanded_cmd,
14661 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14662 NO_STR
14663 BGP_STR
14664 LCOMMUNITY_LIST_STR
14665 "Large Community list number (expanded)\n"
14666 "Specify large community to reject\n"
14667 "Specify large community to accept\n"
14668 "An ordered list as a regular-expression\n")
14669 {
14670 return lcommunity_list_unset_vty(vty, argc, argv,
14671 LARGE_COMMUNITY_LIST_EXPANDED);
14672 }
14673
14674 ALIAS (no_lcommunity_list_expanded,
14675 no_ip_lcommunity_list_expanded_cmd,
14676 "no ip large-community-list (100-500) <deny|permit> LINE...",
14677 NO_STR
14678 IP_STR
14679 LCOMMUNITY_LIST_STR
14680 "Large Community list number (expanded)\n"
14681 "Specify large community to reject\n"
14682 "Specify large community to accept\n"
14683 "An ordered list as a regular-expression\n")
14684
14685 DEFUN (no_lcommunity_list_name_standard,
14686 no_bgp_lcommunity_list_name_standard_cmd,
14687 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14688 NO_STR
14689 BGP_STR
14690 LCOMMUNITY_LIST_STR
14691 "Specify standard large-community-list\n"
14692 "Large Community list name\n"
14693 "Specify large community to reject\n"
14694 "Specify large community to accept\n"
14695 LCOMMUNITY_VAL_STR)
14696 {
14697 return lcommunity_list_unset_vty(vty, argc, argv,
14698 LARGE_COMMUNITY_LIST_STANDARD);
14699 }
14700
14701 ALIAS (no_lcommunity_list_name_standard,
14702 no_ip_lcommunity_list_name_standard_cmd,
14703 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14704 NO_STR
14705 IP_STR
14706 LCOMMUNITY_LIST_STR
14707 "Specify standard large-community-list\n"
14708 "Large Community list name\n"
14709 "Specify large community to reject\n"
14710 "Specify large community to accept\n"
14711 LCOMMUNITY_VAL_STR)
14712
14713 DEFUN (no_lcommunity_list_name_expanded,
14714 no_bgp_lcommunity_list_name_expanded_cmd,
14715 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14716 NO_STR
14717 BGP_STR
14718 LCOMMUNITY_LIST_STR
14719 "Specify expanded large-community-list\n"
14720 "Large community list name\n"
14721 "Specify large community to reject\n"
14722 "Specify large community to accept\n"
14723 "An ordered list as a regular-expression\n")
14724 {
14725 return lcommunity_list_unset_vty(vty, argc, argv,
14726 LARGE_COMMUNITY_LIST_EXPANDED);
14727 }
14728
14729 ALIAS (no_lcommunity_list_name_expanded,
14730 no_ip_lcommunity_list_name_expanded_cmd,
14731 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14732 NO_STR
14733 IP_STR
14734 LCOMMUNITY_LIST_STR
14735 "Specify expanded large-community-list\n"
14736 "Large community list name\n"
14737 "Specify large community to reject\n"
14738 "Specify large community to accept\n"
14739 "An ordered list as a regular-expression\n")
14740
14741 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14742 {
14743 struct community_entry *entry;
14744
14745 for (entry = list->head; entry; entry = entry->next) {
14746 if (entry == list->head) {
14747 if (all_digit(list->name))
14748 vty_out(vty, "Large community %s list %s\n",
14749 entry->style == EXTCOMMUNITY_LIST_STANDARD
14750 ? "standard"
14751 : "(expanded) access",
14752 list->name);
14753 else
14754 vty_out(vty,
14755 "Named large community %s list %s\n",
14756 entry->style == EXTCOMMUNITY_LIST_STANDARD
14757 ? "standard"
14758 : "expanded",
14759 list->name);
14760 }
14761 if (entry->any)
14762 vty_out(vty, " %s\n",
14763 community_direct_str(entry->direct));
14764 else
14765 vty_out(vty, " %s %s\n",
14766 community_direct_str(entry->direct),
14767 community_list_config_str(entry));
14768 }
14769 }
14770
14771 DEFUN (show_lcommunity_list,
14772 show_bgp_lcommunity_list_cmd,
14773 "show bgp large-community-list",
14774 SHOW_STR
14775 BGP_STR
14776 "List large-community list\n")
14777 {
14778 struct community_list *list;
14779 struct community_list_master *cm;
14780 int idx = 0;
14781
14782 if (argv_find(argv, argc, "ip", &idx)) {
14783 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14784 vty_out(vty, "if you are using this please migrate to the below command.\n");
14785 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14786 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14787 }
14788
14789 cm = community_list_master_lookup(bgp_clist,
14790 LARGE_COMMUNITY_LIST_MASTER);
14791 if (!cm)
14792 return CMD_SUCCESS;
14793
14794 for (list = cm->num.head; list; list = list->next)
14795 lcommunity_list_show(vty, list);
14796
14797 for (list = cm->str.head; list; list = list->next)
14798 lcommunity_list_show(vty, list);
14799
14800 return CMD_SUCCESS;
14801 }
14802
14803 ALIAS (show_lcommunity_list,
14804 show_ip_lcommunity_list_cmd,
14805 "show ip large-community-list",
14806 SHOW_STR
14807 IP_STR
14808 "List large-community list\n")
14809
14810 DEFUN (show_lcommunity_list_arg,
14811 show_bgp_lcommunity_list_arg_cmd,
14812 "show bgp large-community-list <(1-500)|WORD>",
14813 SHOW_STR
14814 BGP_STR
14815 "List large-community list\n"
14816 "large-community-list number\n"
14817 "large-community-list name\n")
14818 {
14819 struct community_list *list;
14820 int idx = 0;
14821
14822 if (argv_find(argv, argc, "ip", &idx)) {
14823 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14824 vty_out(vty, "if you are using this please migrate to the below command.\n");
14825 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14826 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14827 }
14828
14829 list = community_list_lookup(bgp_clist, argv[3]->arg,
14830 LARGE_COMMUNITY_LIST_MASTER);
14831 if (!list) {
14832 vty_out(vty, "%% Can't find extcommunity-list\n");
14833 return CMD_WARNING;
14834 }
14835
14836 lcommunity_list_show(vty, list);
14837
14838 return CMD_SUCCESS;
14839 }
14840
14841 ALIAS (show_lcommunity_list_arg,
14842 show_ip_lcommunity_list_arg_cmd,
14843 "show ip large-community-list <(1-500)|WORD>",
14844 SHOW_STR
14845 IP_STR
14846 "List large-community list\n"
14847 "large-community-list number\n"
14848 "large-community-list name\n")
14849
14850 /* "extcommunity-list" keyword help string. */
14851 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14852 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14853
14854 DEFUN (extcommunity_list_standard,
14855 bgp_extcommunity_list_standard_cmd,
14856 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14857 BGP_STR
14858 EXTCOMMUNITY_LIST_STR
14859 "Extended Community list number (standard)\n"
14860 "Specify standard extcommunity-list\n"
14861 "Community list name\n"
14862 "Specify community to reject\n"
14863 "Specify community to accept\n"
14864 EXTCOMMUNITY_VAL_STR)
14865 {
14866 int style = EXTCOMMUNITY_LIST_STANDARD;
14867 int direct = 0;
14868 char *cl_number_or_name = NULL;
14869
14870 int idx = 0;
14871 if (argv_find(argv, argc, "ip", &idx)) {
14872 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14873 vty_out(vty, "if you are using this please migrate to the below command.\n");
14874 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14875 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14876 }
14877 argv_find(argv, argc, "(1-99)", &idx);
14878 argv_find(argv, argc, "WORD", &idx);
14879 cl_number_or_name = argv[idx]->arg;
14880 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14881 : COMMUNITY_DENY;
14882 argv_find(argv, argc, "AA:NN", &idx);
14883 char *str = argv_concat(argv, argc, idx);
14884
14885 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14886 direct, style);
14887
14888 XFREE(MTYPE_TMP, str);
14889
14890 if (ret < 0) {
14891 community_list_perror(vty, ret);
14892 return CMD_WARNING_CONFIG_FAILED;
14893 }
14894
14895 return CMD_SUCCESS;
14896 }
14897
14898 #if CONFDATE > 20191005
14899 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14900 #endif
14901 ALIAS (extcommunity_list_standard,
14902 ip_extcommunity_list_standard_cmd,
14903 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14904 IP_STR
14905 EXTCOMMUNITY_LIST_STR
14906 "Extended Community list number (standard)\n"
14907 "Specify standard extcommunity-list\n"
14908 "Community list name\n"
14909 "Specify community to reject\n"
14910 "Specify community to accept\n"
14911 EXTCOMMUNITY_VAL_STR)
14912
14913 DEFUN (extcommunity_list_name_expanded,
14914 bgp_extcommunity_list_name_expanded_cmd,
14915 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14916 BGP_STR
14917 EXTCOMMUNITY_LIST_STR
14918 "Extended Community list number (expanded)\n"
14919 "Specify expanded extcommunity-list\n"
14920 "Extended Community list name\n"
14921 "Specify community to reject\n"
14922 "Specify community to accept\n"
14923 "An ordered list as a regular-expression\n")
14924 {
14925 int style = EXTCOMMUNITY_LIST_EXPANDED;
14926 int direct = 0;
14927 char *cl_number_or_name = NULL;
14928
14929 int idx = 0;
14930 if (argv_find(argv, argc, "ip", &idx)) {
14931 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14932 vty_out(vty, "if you are using this please migrate to the below command.\n");
14933 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14934 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14935 }
14936
14937 argv_find(argv, argc, "(100-500)", &idx);
14938 argv_find(argv, argc, "WORD", &idx);
14939 cl_number_or_name = argv[idx]->arg;
14940 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14941 : COMMUNITY_DENY;
14942 argv_find(argv, argc, "LINE", &idx);
14943 char *str = argv_concat(argv, argc, idx);
14944
14945 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14946 direct, style);
14947
14948 XFREE(MTYPE_TMP, str);
14949
14950 if (ret < 0) {
14951 community_list_perror(vty, ret);
14952 return CMD_WARNING_CONFIG_FAILED;
14953 }
14954
14955 return CMD_SUCCESS;
14956 }
14957
14958 ALIAS (extcommunity_list_name_expanded,
14959 ip_extcommunity_list_name_expanded_cmd,
14960 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14961 IP_STR
14962 EXTCOMMUNITY_LIST_STR
14963 "Extended Community list number (expanded)\n"
14964 "Specify expanded extcommunity-list\n"
14965 "Extended Community list name\n"
14966 "Specify community to reject\n"
14967 "Specify community to accept\n"
14968 "An ordered list as a regular-expression\n")
14969
14970 DEFUN (no_extcommunity_list_standard_all,
14971 no_bgp_extcommunity_list_standard_all_cmd,
14972 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14973 NO_STR
14974 BGP_STR
14975 EXTCOMMUNITY_LIST_STR
14976 "Extended Community list number (standard)\n"
14977 "Specify standard extcommunity-list\n"
14978 "Community list name\n"
14979 "Specify community to reject\n"
14980 "Specify community to accept\n"
14981 EXTCOMMUNITY_VAL_STR)
14982 {
14983 int style = EXTCOMMUNITY_LIST_STANDARD;
14984 int direct = 0;
14985 char *cl_number_or_name = NULL;
14986
14987 int idx = 0;
14988 if (argv_find(argv, argc, "ip", &idx)) {
14989 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14990 vty_out(vty, "if you are using this please migrate to the below command.\n");
14991 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14992 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14993 }
14994 argv_find(argv, argc, "(1-99)", &idx);
14995 argv_find(argv, argc, "WORD", &idx);
14996 cl_number_or_name = argv[idx]->arg;
14997 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14998 : COMMUNITY_DENY;
14999 argv_find(argv, argc, "AA:NN", &idx);
15000 char *str = argv_concat(argv, argc, idx);
15001
15002 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15003 direct, style);
15004
15005 XFREE(MTYPE_TMP, str);
15006
15007 if (ret < 0) {
15008 community_list_perror(vty, ret);
15009 return CMD_WARNING_CONFIG_FAILED;
15010 }
15011
15012 return CMD_SUCCESS;
15013 }
15014
15015 ALIAS (no_extcommunity_list_standard_all,
15016 no_ip_extcommunity_list_standard_all_cmd,
15017 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15018 NO_STR
15019 IP_STR
15020 EXTCOMMUNITY_LIST_STR
15021 "Extended Community list number (standard)\n"
15022 "Specify standard extcommunity-list\n"
15023 "Community list name\n"
15024 "Specify community to reject\n"
15025 "Specify community to accept\n"
15026 EXTCOMMUNITY_VAL_STR)
15027
15028 DEFUN (no_extcommunity_list_expanded_all,
15029 no_bgp_extcommunity_list_expanded_all_cmd,
15030 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15031 NO_STR
15032 BGP_STR
15033 EXTCOMMUNITY_LIST_STR
15034 "Extended Community list number (expanded)\n"
15035 "Specify expanded extcommunity-list\n"
15036 "Extended Community list name\n"
15037 "Specify community to reject\n"
15038 "Specify community to accept\n"
15039 "An ordered list as a regular-expression\n")
15040 {
15041 int style = EXTCOMMUNITY_LIST_EXPANDED;
15042 int direct = 0;
15043 char *cl_number_or_name = NULL;
15044
15045 int idx = 0;
15046 if (argv_find(argv, argc, "ip", &idx)) {
15047 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15048 vty_out(vty, "if you are using this please migrate to the below command.\n");
15049 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15050 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15051 }
15052 argv_find(argv, argc, "(100-500)", &idx);
15053 argv_find(argv, argc, "WORD", &idx);
15054 cl_number_or_name = argv[idx]->arg;
15055 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15056 : COMMUNITY_DENY;
15057 argv_find(argv, argc, "LINE", &idx);
15058 char *str = argv_concat(argv, argc, idx);
15059
15060 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15061 direct, style);
15062
15063 XFREE(MTYPE_TMP, str);
15064
15065 if (ret < 0) {
15066 community_list_perror(vty, ret);
15067 return CMD_WARNING_CONFIG_FAILED;
15068 }
15069
15070 return CMD_SUCCESS;
15071 }
15072
15073 ALIAS (no_extcommunity_list_expanded_all,
15074 no_ip_extcommunity_list_expanded_all_cmd,
15075 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15076 NO_STR
15077 IP_STR
15078 EXTCOMMUNITY_LIST_STR
15079 "Extended Community list number (expanded)\n"
15080 "Specify expanded extcommunity-list\n"
15081 "Extended Community list name\n"
15082 "Specify community to reject\n"
15083 "Specify community to accept\n"
15084 "An ordered list as a regular-expression\n")
15085
15086 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15087 {
15088 struct community_entry *entry;
15089
15090 for (entry = list->head; entry; entry = entry->next) {
15091 if (entry == list->head) {
15092 if (all_digit(list->name))
15093 vty_out(vty, "Extended community %s list %s\n",
15094 entry->style == EXTCOMMUNITY_LIST_STANDARD
15095 ? "standard"
15096 : "(expanded) access",
15097 list->name);
15098 else
15099 vty_out(vty,
15100 "Named extended community %s list %s\n",
15101 entry->style == EXTCOMMUNITY_LIST_STANDARD
15102 ? "standard"
15103 : "expanded",
15104 list->name);
15105 }
15106 if (entry->any)
15107 vty_out(vty, " %s\n",
15108 community_direct_str(entry->direct));
15109 else
15110 vty_out(vty, " %s %s\n",
15111 community_direct_str(entry->direct),
15112 community_list_config_str(entry));
15113 }
15114 }
15115
15116 DEFUN (show_extcommunity_list,
15117 show_bgp_extcommunity_list_cmd,
15118 "show bgp extcommunity-list",
15119 SHOW_STR
15120 BGP_STR
15121 "List extended-community list\n")
15122 {
15123 struct community_list *list;
15124 struct community_list_master *cm;
15125 int idx = 0;
15126
15127 if (argv_find(argv, argc, "ip", &idx)) {
15128 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15129 vty_out(vty, "if you are using this please migrate to the below command.\n");
15130 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15131 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15132 }
15133 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15134 if (!cm)
15135 return CMD_SUCCESS;
15136
15137 for (list = cm->num.head; list; list = list->next)
15138 extcommunity_list_show(vty, list);
15139
15140 for (list = cm->str.head; list; list = list->next)
15141 extcommunity_list_show(vty, list);
15142
15143 return CMD_SUCCESS;
15144 }
15145
15146 ALIAS (show_extcommunity_list,
15147 show_ip_extcommunity_list_cmd,
15148 "show ip extcommunity-list",
15149 SHOW_STR
15150 IP_STR
15151 "List extended-community list\n")
15152
15153 DEFUN (show_extcommunity_list_arg,
15154 show_bgp_extcommunity_list_arg_cmd,
15155 "show bgp extcommunity-list <(1-500)|WORD>",
15156 SHOW_STR
15157 BGP_STR
15158 "List extended-community list\n"
15159 "Extcommunity-list number\n"
15160 "Extcommunity-list name\n")
15161 {
15162 int idx_comm_list = 3;
15163 struct community_list *list;
15164 int idx = 0;
15165
15166 if (argv_find(argv, argc, "ip", &idx)) {
15167 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15168 vty_out(vty, "if you are using this please migrate to the below command.\n");
15169 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15170 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15171 }
15172 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
15173 EXTCOMMUNITY_LIST_MASTER);
15174 if (!list) {
15175 vty_out(vty, "%% Can't find extcommunity-list\n");
15176 return CMD_WARNING;
15177 }
15178
15179 extcommunity_list_show(vty, list);
15180
15181 return CMD_SUCCESS;
15182 }
15183
15184 ALIAS (show_extcommunity_list_arg,
15185 show_ip_extcommunity_list_arg_cmd,
15186 "show ip extcommunity-list <(1-500)|WORD>",
15187 SHOW_STR
15188 IP_STR
15189 "List extended-community list\n"
15190 "Extcommunity-list number\n"
15191 "Extcommunity-list name\n")
15192
15193 /* Display community-list and extcommunity-list configuration. */
15194 static int community_list_config_write(struct vty *vty)
15195 {
15196 struct community_list *list;
15197 struct community_entry *entry;
15198 struct community_list_master *cm;
15199 int write = 0;
15200
15201 /* Community-list. */
15202 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15203
15204 for (list = cm->num.head; list; list = list->next)
15205 for (entry = list->head; entry; entry = entry->next) {
15206 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15207 community_direct_str(entry->direct),
15208 community_list_config_str(entry));
15209 write++;
15210 }
15211 for (list = cm->str.head; list; list = list->next)
15212 for (entry = list->head; entry; entry = entry->next) {
15213 vty_out(vty, "bgp community-list %s %s %s %s\n",
15214 entry->style == COMMUNITY_LIST_STANDARD
15215 ? "standard"
15216 : "expanded",
15217 list->name, community_direct_str(entry->direct),
15218 community_list_config_str(entry));
15219 write++;
15220 }
15221
15222 /* Extcommunity-list. */
15223 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15224
15225 for (list = cm->num.head; list; list = list->next)
15226 for (entry = list->head; entry; entry = entry->next) {
15227 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15228 list->name, community_direct_str(entry->direct),
15229 community_list_config_str(entry));
15230 write++;
15231 }
15232 for (list = cm->str.head; list; list = list->next)
15233 for (entry = list->head; entry; entry = entry->next) {
15234 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15235 entry->style == EXTCOMMUNITY_LIST_STANDARD
15236 ? "standard"
15237 : "expanded",
15238 list->name, community_direct_str(entry->direct),
15239 community_list_config_str(entry));
15240 write++;
15241 }
15242
15243
15244 /* lcommunity-list. */
15245 cm = community_list_master_lookup(bgp_clist,
15246 LARGE_COMMUNITY_LIST_MASTER);
15247
15248 for (list = cm->num.head; list; list = list->next)
15249 for (entry = list->head; entry; entry = entry->next) {
15250 vty_out(vty, "bgp large-community-list %s %s %s\n",
15251 list->name, community_direct_str(entry->direct),
15252 community_list_config_str(entry));
15253 write++;
15254 }
15255 for (list = cm->str.head; list; list = list->next)
15256 for (entry = list->head; entry; entry = entry->next) {
15257 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15258 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15259 ? "standard"
15260 : "expanded",
15261 list->name, community_direct_str(entry->direct),
15262 community_list_config_str(entry));
15263 write++;
15264 }
15265
15266 return write;
15267 }
15268
15269 static struct cmd_node community_list_node = {
15270 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15271 };
15272
15273 static void community_list_vty(void)
15274 {
15275 install_node(&community_list_node, community_list_config_write);
15276
15277 /* Community-list. */
15278 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15279 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15280 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15281 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15282 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15283 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15284 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15285 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15286 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15287 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15288 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15289 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15290 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15291 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15292 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15293 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15294
15295 /* Extcommunity-list. */
15296 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15297 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15298 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15299 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15300 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15301 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15302 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15303 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15304 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15305 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15306 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15307 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15308
15309 /* Large Community List */
15310 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15311 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15312 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15313 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15314 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15315 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15316 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15317 install_element(CONFIG_NODE,
15318 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15319 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15320 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15321 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15322 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15323 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15324 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15325 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15326 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15327 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15328 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15329 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15330 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15331 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15332 install_element(CONFIG_NODE,
15333 &no_ip_lcommunity_list_name_expanded_all_cmd);
15334 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15335 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15336 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15337 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15338 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15339 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15340 }