]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #3409 from opensourcerouting/feature/cleanup-topotest-docker-docs
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "prefix.h"
26 #include "plist.h"
27 #include "buffer.h"
28 #include "linklist.h"
29 #include "stream.h"
30 #include "thread.h"
31 #include "log.h"
32 #include "memory.h"
33 #include "memory_vty.h"
34 #include "hash.h"
35 #include "queue.h"
36 #include "filter.h"
37 #include "frrstr.h"
38
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_advertise.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_community.h"
44 #include "bgpd/bgp_ecommunity.h"
45 #include "bgpd/bgp_lcommunity.h"
46 #include "bgpd/bgp_damp.h"
47 #include "bgpd/bgp_debug.h"
48 #include "bgpd/bgp_errors.h"
49 #include "bgpd/bgp_fsm.h"
50 #include "bgpd/bgp_nexthop.h"
51 #include "bgpd/bgp_open.h"
52 #include "bgpd/bgp_regex.h"
53 #include "bgpd/bgp_route.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_zebra.h"
56 #include "bgpd/bgp_table.h"
57 #include "bgpd/bgp_vty.h"
58 #include "bgpd/bgp_mpath.h"
59 #include "bgpd/bgp_packet.h"
60 #include "bgpd/bgp_updgrp.h"
61 #include "bgpd/bgp_bfd.h"
62 #include "bgpd/bgp_io.h"
63 #include "bgpd/bgp_evpn.h"
64 #include "bgpd/bgp_addpath.h"
65
66 static struct peer_group *listen_range_exists(struct bgp *bgp,
67 struct prefix *range, int exact);
68
69 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
70 {
71 switch (afi) {
72 case AFI_IP:
73 switch (safi) {
74 case SAFI_UNICAST:
75 return BGP_IPV4_NODE;
76 break;
77 case SAFI_MULTICAST:
78 return BGP_IPV4M_NODE;
79 break;
80 case SAFI_LABELED_UNICAST:
81 return BGP_IPV4L_NODE;
82 break;
83 case SAFI_MPLS_VPN:
84 return BGP_VPNV4_NODE;
85 break;
86 case SAFI_FLOWSPEC:
87 return BGP_FLOWSPECV4_NODE;
88 default:
89 /* not expected */
90 return BGP_IPV4_NODE;
91 break;
92 }
93 break;
94 case AFI_IP6:
95 switch (safi) {
96 case SAFI_UNICAST:
97 return BGP_IPV6_NODE;
98 break;
99 case SAFI_MULTICAST:
100 return BGP_IPV6M_NODE;
101 break;
102 case SAFI_LABELED_UNICAST:
103 return BGP_IPV6L_NODE;
104 break;
105 case SAFI_MPLS_VPN:
106 return BGP_VPNV6_NODE;
107 break;
108 case SAFI_FLOWSPEC:
109 return BGP_FLOWSPECV6_NODE;
110 default:
111 /* not expected */
112 return BGP_IPV4_NODE;
113 break;
114 }
115 break;
116 case AFI_L2VPN:
117 return BGP_EVPN_NODE;
118 break;
119 case AFI_MAX:
120 // We should never be here but to clarify the switch statement..
121 return BGP_IPV4_NODE;
122 break;
123 }
124
125 // Impossible to happen
126 return BGP_IPV4_NODE;
127 }
128
129 /* Utility function to get address family from current node. */
130 afi_t bgp_node_afi(struct vty *vty)
131 {
132 afi_t afi;
133 switch (vty->node) {
134 case BGP_IPV6_NODE:
135 case BGP_IPV6M_NODE:
136 case BGP_IPV6L_NODE:
137 case BGP_VPNV6_NODE:
138 case BGP_FLOWSPECV6_NODE:
139 afi = AFI_IP6;
140 break;
141 case BGP_EVPN_NODE:
142 afi = AFI_L2VPN;
143 break;
144 default:
145 afi = AFI_IP;
146 break;
147 }
148 return afi;
149 }
150
151 /* Utility function to get subsequent address family from current
152 node. */
153 safi_t bgp_node_safi(struct vty *vty)
154 {
155 safi_t safi;
156 switch (vty->node) {
157 case BGP_VPNV4_NODE:
158 case BGP_VPNV6_NODE:
159 safi = SAFI_MPLS_VPN;
160 break;
161 case BGP_IPV4M_NODE:
162 case BGP_IPV6M_NODE:
163 safi = SAFI_MULTICAST;
164 break;
165 case BGP_EVPN_NODE:
166 safi = SAFI_EVPN;
167 break;
168 case BGP_IPV4L_NODE:
169 case BGP_IPV6L_NODE:
170 safi = SAFI_LABELED_UNICAST;
171 break;
172 case BGP_FLOWSPECV4_NODE:
173 case BGP_FLOWSPECV6_NODE:
174 safi = SAFI_FLOWSPEC;
175 break;
176 default:
177 safi = SAFI_UNICAST;
178 break;
179 }
180 return safi;
181 }
182
183 /**
184 * Converts an AFI in string form to afi_t
185 *
186 * @param afi string, one of
187 * - "ipv4"
188 * - "ipv6"
189 * - "l2vpn"
190 * @return the corresponding afi_t
191 */
192 afi_t bgp_vty_afi_from_str(const char *afi_str)
193 {
194 afi_t afi = AFI_MAX; /* unknown */
195 if (strmatch(afi_str, "ipv4"))
196 afi = AFI_IP;
197 else if (strmatch(afi_str, "ipv6"))
198 afi = AFI_IP6;
199 else if (strmatch(afi_str, "l2vpn"))
200 afi = AFI_L2VPN;
201 return afi;
202 }
203
204 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
205 afi_t *afi)
206 {
207 int ret = 0;
208 if (argv_find(argv, argc, "ipv4", index)) {
209 ret = 1;
210 if (afi)
211 *afi = AFI_IP;
212 } else if (argv_find(argv, argc, "ipv6", index)) {
213 ret = 1;
214 if (afi)
215 *afi = AFI_IP6;
216 }
217 return ret;
218 }
219
220 /* supports <unicast|multicast|vpn|labeled-unicast> */
221 safi_t bgp_vty_safi_from_str(const char *safi_str)
222 {
223 safi_t safi = SAFI_MAX; /* unknown */
224 if (strmatch(safi_str, "multicast"))
225 safi = SAFI_MULTICAST;
226 else if (strmatch(safi_str, "unicast"))
227 safi = SAFI_UNICAST;
228 else if (strmatch(safi_str, "vpn"))
229 safi = SAFI_MPLS_VPN;
230 else if (strmatch(safi_str, "evpn"))
231 safi = SAFI_EVPN;
232 else if (strmatch(safi_str, "labeled-unicast"))
233 safi = SAFI_LABELED_UNICAST;
234 else if (strmatch(safi_str, "flowspec"))
235 safi = SAFI_FLOWSPEC;
236 return safi;
237 }
238
239 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
240 safi_t *safi)
241 {
242 int ret = 0;
243 if (argv_find(argv, argc, "unicast", index)) {
244 ret = 1;
245 if (safi)
246 *safi = SAFI_UNICAST;
247 } else if (argv_find(argv, argc, "multicast", index)) {
248 ret = 1;
249 if (safi)
250 *safi = SAFI_MULTICAST;
251 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_LABELED_UNICAST;
255 } else if (argv_find(argv, argc, "vpn", index)) {
256 ret = 1;
257 if (safi)
258 *safi = SAFI_MPLS_VPN;
259 } else if (argv_find(argv, argc, "flowspec", index)) {
260 ret = 1;
261 if (safi)
262 *safi = SAFI_FLOWSPEC;
263 }
264 return ret;
265 }
266
267 /*
268 * bgp_vty_find_and_parse_afi_safi_bgp
269 *
270 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
271 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
272 * to appropriate values for the calling function. This is to allow the
273 * calling function to make decisions appropriate for the show command
274 * that is being parsed.
275 *
276 * The show commands are generally of the form:
277 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
278 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
279 *
280 * Since we use argv_find if the show command in particular doesn't have:
281 * [ip]
282 * [<view|vrf> VIEWVRFNAME]
283 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
284 * The command parsing should still be ok.
285 *
286 * vty -> The vty for the command so we can output some useful data in
287 * the event of a parse error in the vrf.
288 * argv -> The command tokens
289 * argc -> How many command tokens we have
290 * idx -> The current place in the command, generally should be 0 for this
291 * function
292 * afi -> The parsed afi if it was included in the show command, returned here
293 * safi -> The parsed safi if it was included in the show command, returned here
294 * bgp -> Pointer to the bgp data structure we need to fill in.
295 *
296 * The function returns the correct location in the parse tree for the
297 * last token found.
298 *
299 * Returns 0 for failure to parse correctly, else the idx position of where
300 * it found the last token.
301 */
302 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
303 struct cmd_token **argv, int argc,
304 int *idx, afi_t *afi, safi_t *safi,
305 struct bgp **bgp, bool use_json)
306 {
307 char *vrf_name = NULL;
308
309 assert(afi);
310 assert(safi);
311 assert(bgp);
312
313 if (argv_find(argv, argc, "ip", idx))
314 *afi = AFI_IP;
315
316 if (argv_find(argv, argc, "view", idx))
317 vrf_name = argv[*idx + 1]->arg;
318 else if (argv_find(argv, argc, "vrf", idx)) {
319 vrf_name = argv[*idx + 1]->arg;
320 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
321 vrf_name = NULL;
322 }
323 if (vrf_name) {
324 if (strmatch(vrf_name, "all"))
325 *bgp = NULL;
326 else {
327 *bgp = bgp_lookup_by_name(vrf_name);
328 if (!*bgp) {
329 if (use_json)
330 vty_out(vty, "{}\n");
331 else
332 vty_out(vty, "View/Vrf %s is unknown\n",
333 vrf_name);
334 *idx = 0;
335 return 0;
336 }
337 }
338 } else {
339 *bgp = bgp_get_default();
340 if (!*bgp) {
341 if (use_json)
342 vty_out(vty, "{}\n");
343 else
344 vty_out(vty,
345 "Default BGP instance not found\n");
346 *idx = 0;
347 return 0;
348 }
349 }
350
351 if (argv_find_and_parse_afi(argv, argc, idx, afi))
352 argv_find_and_parse_safi(argv, argc, idx, safi);
353
354 *idx += 1;
355 return *idx;
356 }
357
358 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
359 {
360 struct interface *ifp = NULL;
361
362 if (su->sa.sa_family == AF_INET)
363 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
364 else if (su->sa.sa_family == AF_INET6)
365 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
366 su->sin6.sin6_scope_id,
367 bgp->vrf_id);
368
369 if (ifp)
370 return 1;
371
372 return 0;
373 }
374
375 /* Utility function for looking up peer from VTY. */
376 /* This is used only for configuration, so disallow if attempted on
377 * a dynamic neighbor.
378 */
379 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
380 {
381 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
382 int ret;
383 union sockunion su;
384 struct peer *peer;
385
386 if (!bgp) {
387 return NULL;
388 }
389
390 ret = str2sockunion(ip_str, &su);
391 if (ret < 0) {
392 peer = peer_lookup_by_conf_if(bgp, ip_str);
393 if (!peer) {
394 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
395 == NULL) {
396 vty_out(vty,
397 "%% Malformed address or name: %s\n",
398 ip_str);
399 return NULL;
400 }
401 }
402 } else {
403 peer = peer_lookup(bgp, &su);
404 if (!peer) {
405 vty_out(vty,
406 "%% Specify remote-as or peer-group commands first\n");
407 return NULL;
408 }
409 if (peer_dynamic_neighbor(peer)) {
410 vty_out(vty,
411 "%% Operation not allowed on a dynamic neighbor\n");
412 return NULL;
413 }
414 }
415 return peer;
416 }
417
418 /* Utility function for looking up peer or peer group. */
419 /* This is used only for configuration, so disallow if attempted on
420 * a dynamic neighbor.
421 */
422 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
423 {
424 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
425 int ret;
426 union sockunion su;
427 struct peer *peer = NULL;
428 struct peer_group *group = NULL;
429
430 if (!bgp) {
431 return NULL;
432 }
433
434 ret = str2sockunion(peer_str, &su);
435 if (ret == 0) {
436 /* IP address, locate peer. */
437 peer = peer_lookup(bgp, &su);
438 } else {
439 /* Not IP, could match either peer configured on interface or a
440 * group. */
441 peer = peer_lookup_by_conf_if(bgp, peer_str);
442 if (!peer)
443 group = peer_group_lookup(bgp, peer_str);
444 }
445
446 if (peer) {
447 if (peer_dynamic_neighbor(peer)) {
448 vty_out(vty,
449 "%% Operation not allowed on a dynamic neighbor\n");
450 return NULL;
451 }
452
453 return peer;
454 }
455
456 if (group)
457 return group->conf;
458
459 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
460
461 return NULL;
462 }
463
464 int bgp_vty_return(struct vty *vty, int ret)
465 {
466 const char *str = NULL;
467
468 switch (ret) {
469 case BGP_ERR_INVALID_VALUE:
470 str = "Invalid value";
471 break;
472 case BGP_ERR_INVALID_FLAG:
473 str = "Invalid flag";
474 break;
475 case BGP_ERR_PEER_GROUP_SHUTDOWN:
476 str = "Peer-group has been shutdown. Activate the peer-group first";
477 break;
478 case BGP_ERR_PEER_FLAG_CONFLICT:
479 str = "Can't set override-capability and strict-capability-match at the same time";
480 break;
481 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
482 str = "Specify remote-as or peer-group remote AS first";
483 break;
484 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
485 str = "Cannot change the peer-group. Deconfigure first";
486 break;
487 case BGP_ERR_PEER_GROUP_MISMATCH:
488 str = "Peer is not a member of this peer-group";
489 break;
490 case BGP_ERR_PEER_FILTER_CONFLICT:
491 str = "Prefix/distribute list can not co-exist";
492 break;
493 case BGP_ERR_NOT_INTERNAL_PEER:
494 str = "Invalid command. Not an internal neighbor";
495 break;
496 case BGP_ERR_REMOVE_PRIVATE_AS:
497 str = "remove-private-AS cannot be configured for IBGP peers";
498 break;
499 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
500 str = "Local-AS allowed only for EBGP peers";
501 break;
502 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
503 str = "Cannot have local-as same as BGP AS number";
504 break;
505 case BGP_ERR_TCPSIG_FAILED:
506 str = "Error while applying TCP-Sig to session(s)";
507 break;
508 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
509 str = "ebgp-multihop and ttl-security cannot be configured together";
510 break;
511 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
512 str = "ttl-security only allowed for EBGP peers";
513 break;
514 case BGP_ERR_AS_OVERRIDE:
515 str = "as-override cannot be configured for IBGP peers";
516 break;
517 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
518 str = "Invalid limit for number of dynamic neighbors";
519 break;
520 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
521 str = "Dynamic neighbor listen range already exists";
522 break;
523 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
524 str = "Operation not allowed on a dynamic neighbor";
525 break;
526 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
527 str = "Operation not allowed on a directly connected neighbor";
528 break;
529 case BGP_ERR_PEER_SAFI_CONFLICT:
530 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
531 break;
532 }
533 if (str) {
534 vty_out(vty, "%% %s\n", str);
535 return CMD_WARNING_CONFIG_FAILED;
536 }
537 return CMD_SUCCESS;
538 }
539
540 /* BGP clear sort. */
541 enum clear_sort {
542 clear_all,
543 clear_peer,
544 clear_group,
545 clear_external,
546 clear_as
547 };
548
549 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
550 safi_t safi, int error)
551 {
552 switch (error) {
553 case BGP_ERR_AF_UNCONFIGURED:
554 vty_out(vty,
555 "%%BGP: Enable %s address family for the neighbor %s\n",
556 afi_safi_print(afi, safi), peer->host);
557 break;
558 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
559 vty_out(vty,
560 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
561 peer->host);
562 break;
563 default:
564 break;
565 }
566 }
567
568 /* `clear ip bgp' functions. */
569 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
570 enum clear_sort sort, enum bgp_clear_type stype,
571 const char *arg)
572 {
573 int ret;
574 bool found = false;
575 struct peer *peer;
576 struct listnode *node, *nnode;
577
578 /* Clear all neighbors. */
579 /*
580 * Pass along pointer to next node to peer_clear() when walking all
581 * nodes on the BGP instance as that may get freed if it is a
582 * doppelganger
583 */
584 if (sort == clear_all) {
585 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
586 if (!peer->afc[afi][safi])
587 continue;
588
589 if (stype == BGP_CLEAR_SOFT_NONE)
590 ret = peer_clear(peer, &nnode);
591 else
592 ret = peer_clear_soft(peer, afi, safi, stype);
593
594 if (ret < 0)
595 bgp_clear_vty_error(vty, peer, afi, safi, ret);
596 else
597 found = true;
598 }
599
600 /* This is to apply read-only mode on this clear. */
601 if (stype == BGP_CLEAR_SOFT_NONE)
602 bgp->update_delay_over = 0;
603
604 if (!found)
605 vty_out(vty, "%%BGP: No %s peer configured\n",
606 afi_safi_print(afi, safi));
607
608 return CMD_SUCCESS;
609 }
610
611 /* Clear specified neighbor. */
612 if (sort == clear_peer) {
613 union sockunion su;
614
615 /* Make sockunion for lookup. */
616 ret = str2sockunion(arg, &su);
617 if (ret < 0) {
618 peer = peer_lookup_by_conf_if(bgp, arg);
619 if (!peer) {
620 peer = peer_lookup_by_hostname(bgp, arg);
621 if (!peer) {
622 vty_out(vty,
623 "Malformed address or name: %s\n",
624 arg);
625 return CMD_WARNING;
626 }
627 }
628 } else {
629 peer = peer_lookup(bgp, &su);
630 if (!peer) {
631 vty_out(vty,
632 "%%BGP: Unknown neighbor - \"%s\"\n",
633 arg);
634 return CMD_WARNING;
635 }
636 }
637
638 if (!peer->afc[afi][safi])
639 ret = BGP_ERR_AF_UNCONFIGURED;
640 else if (stype == BGP_CLEAR_SOFT_NONE)
641 ret = peer_clear(peer, NULL);
642 else
643 ret = peer_clear_soft(peer, afi, safi, stype);
644
645 if (ret < 0)
646 bgp_clear_vty_error(vty, peer, afi, safi, ret);
647
648 return CMD_SUCCESS;
649 }
650
651 /* Clear all neighbors belonging to a specific peer-group. */
652 if (sort == clear_group) {
653 struct peer_group *group;
654
655 group = peer_group_lookup(bgp, arg);
656 if (!group) {
657 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
658 return CMD_WARNING;
659 }
660
661 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
662 if (!peer->afc[afi][safi])
663 continue;
664
665 if (stype == BGP_CLEAR_SOFT_NONE)
666 ret = peer_clear(peer, NULL);
667 else
668 ret = peer_clear_soft(peer, afi, safi, stype);
669
670 if (ret < 0)
671 bgp_clear_vty_error(vty, peer, afi, safi, ret);
672 else
673 found = true;
674 }
675
676 if (!found)
677 vty_out(vty,
678 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
679 afi_safi_print(afi, safi), arg);
680
681 return CMD_SUCCESS;
682 }
683
684 /* Clear all external (eBGP) neighbors. */
685 if (sort == clear_external) {
686 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
687 if (peer->sort == BGP_PEER_IBGP)
688 continue;
689
690 if (!peer->afc[afi][safi])
691 continue;
692
693 if (stype == BGP_CLEAR_SOFT_NONE)
694 ret = peer_clear(peer, &nnode);
695 else
696 ret = peer_clear_soft(peer, afi, safi, stype);
697
698 if (ret < 0)
699 bgp_clear_vty_error(vty, peer, afi, safi, ret);
700 else
701 found = true;
702 }
703
704 if (!found)
705 vty_out(vty,
706 "%%BGP: No external %s peer is configured\n",
707 afi_safi_print(afi, safi));
708
709 return CMD_SUCCESS;
710 }
711
712 /* Clear all neighbors belonging to a specific AS. */
713 if (sort == clear_as) {
714 as_t as = strtoul(arg, NULL, 10);
715
716 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
717 if (peer->as != as)
718 continue;
719
720 if (!peer->afc[afi][safi])
721 ret = BGP_ERR_AF_UNCONFIGURED;
722 else if (stype == BGP_CLEAR_SOFT_NONE)
723 ret = peer_clear(peer, &nnode);
724 else
725 ret = peer_clear_soft(peer, afi, safi, stype);
726
727 if (ret < 0)
728 bgp_clear_vty_error(vty, peer, afi, safi, ret);
729 else
730 found = true;
731 }
732
733 if (!found)
734 vty_out(vty,
735 "%%BGP: No %s peer is configured with AS %s\n",
736 afi_safi_print(afi, safi), arg);
737
738 return CMD_SUCCESS;
739 }
740
741 return CMD_SUCCESS;
742 }
743
744 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
745 safi_t safi, enum clear_sort sort,
746 enum bgp_clear_type stype, const char *arg)
747 {
748 struct bgp *bgp;
749
750 /* BGP structure lookup. */
751 if (name) {
752 bgp = bgp_lookup_by_name(name);
753 if (bgp == NULL) {
754 vty_out(vty, "Can't find BGP instance %s\n", name);
755 return CMD_WARNING;
756 }
757 } else {
758 bgp = bgp_get_default();
759 if (bgp == NULL) {
760 vty_out(vty, "No BGP process is configured\n");
761 return CMD_WARNING;
762 }
763 }
764
765 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
766 }
767
768 /* clear soft inbound */
769 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
770 {
771 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
772 BGP_CLEAR_SOFT_IN, NULL);
773 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
774 BGP_CLEAR_SOFT_IN, NULL);
775 }
776
777 /* clear soft outbound */
778 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
779 {
780 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
781 BGP_CLEAR_SOFT_OUT, NULL);
782 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
783 BGP_CLEAR_SOFT_OUT, NULL);
784 }
785
786
787 #ifndef VTYSH_EXTRACT_PL
788 #include "bgpd/bgp_vty_clippy.c"
789 #endif
790
791 /* BGP global configuration. */
792 #if (CONFDATE > 20190601)
793 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
794 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
795 #endif
796 DEFUN_HIDDEN (bgp_multiple_instance_func,
797 bgp_multiple_instance_cmd,
798 "bgp multiple-instance",
799 BGP_STR
800 "Enable bgp multiple instance\n")
801 {
802 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
803 return CMD_SUCCESS;
804 }
805
806 DEFUN_HIDDEN (no_bgp_multiple_instance,
807 no_bgp_multiple_instance_cmd,
808 "no bgp multiple-instance",
809 NO_STR
810 BGP_STR
811 "BGP multiple instance\n")
812 {
813 int ret;
814
815 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
816 vty_out(vty, "if you are using this please let the developers know\n");
817 zlog_info("Deprecated option: `bgp multiple-instance` being used");
818 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
819 if (ret < 0) {
820 vty_out(vty, "%% There are more than two BGP instances\n");
821 return CMD_WARNING_CONFIG_FAILED;
822 }
823 return CMD_SUCCESS;
824 }
825
826 DEFUN_HIDDEN (bgp_local_mac,
827 bgp_local_mac_cmd,
828 "bgp local-mac vni " CMD_VNI_RANGE " mac WORD seq (0-4294967295)",
829 BGP_STR
830 "Local MAC config\n"
831 "VxLAN Network Identifier\n"
832 "VNI number\n"
833 "local mac\n"
834 "mac address\n"
835 "mac-mobility sequence\n"
836 "seq number\n")
837 {
838 int rv;
839 vni_t vni;
840 struct ethaddr mac;
841 struct ipaddr ip;
842 uint32_t seq;
843 struct bgp *bgp;
844
845 vni = strtoul(argv[3]->arg, NULL, 10);
846 if (!prefix_str2mac(argv[5]->arg, &mac)) {
847 vty_out(vty, "%% Malformed MAC address\n");
848 return CMD_WARNING;
849 }
850 memset(&ip, 0, sizeof(ip));
851 seq = strtoul(argv[7]->arg, NULL, 10);
852
853 bgp = bgp_get_default();
854 if (!bgp) {
855 vty_out(vty, "Default BGP instance is not there\n");
856 return CMD_WARNING;
857 }
858
859 rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
860 if (rv < 0) {
861 vty_out(vty, "Internal error\n");
862 return CMD_WARNING;
863 }
864
865 return CMD_SUCCESS;
866 }
867
868 DEFUN_HIDDEN (no_bgp_local_mac,
869 no_bgp_local_mac_cmd,
870 "no bgp local-mac vni " CMD_VNI_RANGE " mac WORD",
871 NO_STR
872 BGP_STR
873 "Local MAC config\n"
874 "VxLAN Network Identifier\n"
875 "VNI number\n"
876 "local mac\n"
877 "mac address\n")
878 {
879 int rv;
880 vni_t vni;
881 struct ethaddr mac;
882 struct ipaddr ip;
883 struct bgp *bgp;
884
885 vni = strtoul(argv[4]->arg, NULL, 10);
886 if (!prefix_str2mac(argv[6]->arg, &mac)) {
887 vty_out(vty, "%% Malformed MAC address\n");
888 return CMD_WARNING;
889 }
890 memset(&ip, 0, sizeof(ip));
891
892 bgp = bgp_get_default();
893 if (!bgp) {
894 vty_out(vty, "Default BGP instance is not there\n");
895 return CMD_WARNING;
896 }
897
898 rv = bgp_evpn_local_macip_del(bgp, vni, &mac, &ip);
899 if (rv < 0) {
900 vty_out(vty, "Internal error\n");
901 return CMD_WARNING;
902 }
903
904 return CMD_SUCCESS;
905 }
906
907 #if (CONFDATE > 20190601)
908 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
909 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
910 #endif
911 DEFUN_HIDDEN (bgp_config_type,
912 bgp_config_type_cmd,
913 "bgp config-type <cisco|zebra>",
914 BGP_STR
915 "Configuration type\n"
916 "cisco\n"
917 "zebra\n")
918 {
919 int idx = 0;
920 if (argv_find(argv, argc, "cisco", &idx)) {
921 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
922 vty_out(vty, "if you are using this please let the developers know!\n");
923 zlog_info("Deprecated option: `bgp config-type cisco` being used");
924 bgp_option_set(BGP_OPT_CONFIG_CISCO);
925 } else
926 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
927
928 return CMD_SUCCESS;
929 }
930
931 DEFUN_HIDDEN (no_bgp_config_type,
932 no_bgp_config_type_cmd,
933 "no bgp config-type [<cisco|zebra>]",
934 NO_STR
935 BGP_STR
936 "Display configuration type\n"
937 "cisco\n"
938 "zebra\n")
939 {
940 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
941 return CMD_SUCCESS;
942 }
943
944
945 DEFUN (no_synchronization,
946 no_synchronization_cmd,
947 "no synchronization",
948 NO_STR
949 "Perform IGP synchronization\n")
950 {
951 return CMD_SUCCESS;
952 }
953
954 DEFUN (no_auto_summary,
955 no_auto_summary_cmd,
956 "no auto-summary",
957 NO_STR
958 "Enable automatic network number summarization\n")
959 {
960 return CMD_SUCCESS;
961 }
962
963 /* "router bgp" commands. */
964 DEFUN_NOSH (router_bgp,
965 router_bgp_cmd,
966 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
967 ROUTER_STR
968 BGP_STR
969 AS_STR
970 BGP_INSTANCE_HELP_STR)
971 {
972 int idx_asn = 2;
973 int idx_view_vrf = 3;
974 int idx_vrf = 4;
975 int is_new_bgp = 0;
976 int ret;
977 as_t as;
978 struct bgp *bgp;
979 const char *name = NULL;
980 enum bgp_instance_type inst_type;
981
982 // "router bgp" without an ASN
983 if (argc == 2) {
984 // Pending: Make VRF option available for ASN less config
985 bgp = bgp_get_default();
986
987 if (bgp == NULL) {
988 vty_out(vty, "%% No BGP process is configured\n");
989 return CMD_WARNING_CONFIG_FAILED;
990 }
991
992 if (listcount(bm->bgp) > 1) {
993 vty_out(vty, "%% Please specify ASN and VRF\n");
994 return CMD_WARNING_CONFIG_FAILED;
995 }
996 }
997
998 // "router bgp X"
999 else {
1000 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1001
1002 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
1003 if (argc > 3) {
1004 name = argv[idx_vrf]->arg;
1005
1006 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
1007 if (strmatch(name, VRF_DEFAULT_NAME))
1008 name = NULL;
1009 else
1010 inst_type = BGP_INSTANCE_TYPE_VRF;
1011 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
1012 inst_type = BGP_INSTANCE_TYPE_VIEW;
1013 }
1014
1015 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1016 is_new_bgp = (bgp_lookup(as, name) == NULL);
1017
1018 ret = bgp_get(&bgp, &as, name, inst_type);
1019 switch (ret) {
1020 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
1021 vty_out(vty,
1022 "Please specify 'bgp multiple-instance' first\n");
1023 return CMD_WARNING_CONFIG_FAILED;
1024 case BGP_ERR_AS_MISMATCH:
1025 vty_out(vty, "BGP is already running; AS is %u\n", as);
1026 return CMD_WARNING_CONFIG_FAILED;
1027 case BGP_ERR_INSTANCE_MISMATCH:
1028 vty_out(vty,
1029 "BGP instance name and AS number mismatch\n");
1030 vty_out(vty,
1031 "BGP instance is already running; AS is %u\n",
1032 as);
1033 return CMD_WARNING_CONFIG_FAILED;
1034 }
1035
1036 /*
1037 * If we just instantiated the default instance, complete
1038 * any pending VRF-VPN leaking that was configured via
1039 * earlier "router bgp X vrf FOO" blocks.
1040 */
1041 if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
1042 vpn_leak_postchange_all();
1043
1044 /* Pending: handle when user tries to change a view to vrf n vv.
1045 */
1046 }
1047
1048 /* unset the auto created flag as the user config is now present */
1049 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
1050 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
1051
1052 return CMD_SUCCESS;
1053 }
1054
1055 /* "no router bgp" commands. */
1056 DEFUN (no_router_bgp,
1057 no_router_bgp_cmd,
1058 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
1059 NO_STR
1060 ROUTER_STR
1061 BGP_STR
1062 AS_STR
1063 BGP_INSTANCE_HELP_STR)
1064 {
1065 int idx_asn = 3;
1066 int idx_vrf = 5;
1067 as_t as;
1068 struct bgp *bgp;
1069 const char *name = NULL;
1070
1071 // "no router bgp" without an ASN
1072 if (argc == 3) {
1073 // Pending: Make VRF option available for ASN less config
1074 bgp = bgp_get_default();
1075
1076 if (bgp == NULL) {
1077 vty_out(vty, "%% No BGP process is configured\n");
1078 return CMD_WARNING_CONFIG_FAILED;
1079 }
1080
1081 if (listcount(bm->bgp) > 1) {
1082 vty_out(vty, "%% Please specify ASN and VRF\n");
1083 return CMD_WARNING_CONFIG_FAILED;
1084 }
1085
1086 if (bgp->l3vni) {
1087 vty_out(vty, "%% Please unconfigure l3vni %u",
1088 bgp->l3vni);
1089 return CMD_WARNING_CONFIG_FAILED;
1090 }
1091 } else {
1092 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1093
1094 if (argc > 4)
1095 name = argv[idx_vrf]->arg;
1096
1097 /* Lookup bgp structure. */
1098 bgp = bgp_lookup(as, name);
1099 if (!bgp) {
1100 vty_out(vty, "%% Can't find BGP instance\n");
1101 return CMD_WARNING_CONFIG_FAILED;
1102 }
1103
1104 if (bgp->l3vni) {
1105 vty_out(vty, "%% Please unconfigure l3vni %u",
1106 bgp->l3vni);
1107 return CMD_WARNING_CONFIG_FAILED;
1108 }
1109 }
1110
1111 bgp_delete(bgp);
1112
1113 return CMD_SUCCESS;
1114 }
1115
1116
1117 /* BGP router-id. */
1118
1119 DEFPY (bgp_router_id,
1120 bgp_router_id_cmd,
1121 "bgp router-id A.B.C.D",
1122 BGP_STR
1123 "Override configured router identifier\n"
1124 "Manually configured router identifier\n")
1125 {
1126 VTY_DECLVAR_CONTEXT(bgp, bgp);
1127 bgp_router_id_static_set(bgp, router_id);
1128 return CMD_SUCCESS;
1129 }
1130
1131 DEFPY (no_bgp_router_id,
1132 no_bgp_router_id_cmd,
1133 "no bgp router-id [A.B.C.D]",
1134 NO_STR
1135 BGP_STR
1136 "Override configured router identifier\n"
1137 "Manually configured router identifier\n")
1138 {
1139 VTY_DECLVAR_CONTEXT(bgp, bgp);
1140
1141 if (router_id_str) {
1142 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1143 vty_out(vty, "%% BGP router-id doesn't match\n");
1144 return CMD_WARNING_CONFIG_FAILED;
1145 }
1146 }
1147
1148 router_id.s_addr = 0;
1149 bgp_router_id_static_set(bgp, router_id);
1150
1151 return CMD_SUCCESS;
1152 }
1153
1154
1155 /* BGP Cluster ID. */
1156 DEFUN (bgp_cluster_id,
1157 bgp_cluster_id_cmd,
1158 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1159 BGP_STR
1160 "Configure Route-Reflector Cluster-id\n"
1161 "Route-Reflector Cluster-id in IP address format\n"
1162 "Route-Reflector Cluster-id as 32 bit quantity\n")
1163 {
1164 VTY_DECLVAR_CONTEXT(bgp, bgp);
1165 int idx_ipv4 = 2;
1166 int ret;
1167 struct in_addr cluster;
1168
1169 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1170 if (!ret) {
1171 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1172 return CMD_WARNING_CONFIG_FAILED;
1173 }
1174
1175 bgp_cluster_id_set(bgp, &cluster);
1176 bgp_clear_star_soft_out(vty, bgp->name);
1177
1178 return CMD_SUCCESS;
1179 }
1180
1181 DEFUN (no_bgp_cluster_id,
1182 no_bgp_cluster_id_cmd,
1183 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1184 NO_STR
1185 BGP_STR
1186 "Configure Route-Reflector Cluster-id\n"
1187 "Route-Reflector Cluster-id in IP address format\n"
1188 "Route-Reflector Cluster-id as 32 bit quantity\n")
1189 {
1190 VTY_DECLVAR_CONTEXT(bgp, bgp);
1191 bgp_cluster_id_unset(bgp);
1192 bgp_clear_star_soft_out(vty, bgp->name);
1193
1194 return CMD_SUCCESS;
1195 }
1196
1197 DEFUN (bgp_confederation_identifier,
1198 bgp_confederation_identifier_cmd,
1199 "bgp confederation identifier (1-4294967295)",
1200 "BGP specific commands\n"
1201 "AS confederation parameters\n"
1202 "AS number\n"
1203 "Set routing domain confederation AS\n")
1204 {
1205 VTY_DECLVAR_CONTEXT(bgp, bgp);
1206 int idx_number = 3;
1207 as_t as;
1208
1209 as = strtoul(argv[idx_number]->arg, NULL, 10);
1210
1211 bgp_confederation_id_set(bgp, as);
1212
1213 return CMD_SUCCESS;
1214 }
1215
1216 DEFUN (no_bgp_confederation_identifier,
1217 no_bgp_confederation_identifier_cmd,
1218 "no bgp confederation identifier [(1-4294967295)]",
1219 NO_STR
1220 "BGP specific commands\n"
1221 "AS confederation parameters\n"
1222 "AS number\n"
1223 "Set routing domain confederation AS\n")
1224 {
1225 VTY_DECLVAR_CONTEXT(bgp, bgp);
1226 bgp_confederation_id_unset(bgp);
1227
1228 return CMD_SUCCESS;
1229 }
1230
1231 DEFUN (bgp_confederation_peers,
1232 bgp_confederation_peers_cmd,
1233 "bgp confederation peers (1-4294967295)...",
1234 "BGP specific commands\n"
1235 "AS confederation parameters\n"
1236 "Peer ASs in BGP confederation\n"
1237 AS_STR)
1238 {
1239 VTY_DECLVAR_CONTEXT(bgp, bgp);
1240 int idx_asn = 3;
1241 as_t as;
1242 int i;
1243
1244 for (i = idx_asn; i < argc; i++) {
1245 as = strtoul(argv[i]->arg, NULL, 10);
1246
1247 if (bgp->as == as) {
1248 vty_out(vty,
1249 "%% Local member-AS not allowed in confed peer list\n");
1250 continue;
1251 }
1252
1253 bgp_confederation_peers_add(bgp, as);
1254 }
1255 return CMD_SUCCESS;
1256 }
1257
1258 DEFUN (no_bgp_confederation_peers,
1259 no_bgp_confederation_peers_cmd,
1260 "no bgp confederation peers (1-4294967295)...",
1261 NO_STR
1262 "BGP specific commands\n"
1263 "AS confederation parameters\n"
1264 "Peer ASs in BGP confederation\n"
1265 AS_STR)
1266 {
1267 VTY_DECLVAR_CONTEXT(bgp, bgp);
1268 int idx_asn = 4;
1269 as_t as;
1270 int i;
1271
1272 for (i = idx_asn; i < argc; i++) {
1273 as = strtoul(argv[i]->arg, NULL, 10);
1274
1275 bgp_confederation_peers_remove(bgp, as);
1276 }
1277 return CMD_SUCCESS;
1278 }
1279
1280 /**
1281 * Central routine for maximum-paths configuration.
1282 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1283 * @set: 1 for setting values, 0 for removing the max-paths config.
1284 */
1285 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1286 const char *mpaths, uint16_t options,
1287 int set)
1288 {
1289 VTY_DECLVAR_CONTEXT(bgp, bgp);
1290 uint16_t maxpaths = 0;
1291 int ret;
1292 afi_t afi;
1293 safi_t safi;
1294
1295 afi = bgp_node_afi(vty);
1296 safi = bgp_node_safi(vty);
1297
1298 if (set) {
1299 maxpaths = strtol(mpaths, NULL, 10);
1300 if (maxpaths > multipath_num) {
1301 vty_out(vty,
1302 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1303 maxpaths, multipath_num);
1304 return CMD_WARNING_CONFIG_FAILED;
1305 }
1306 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1307 options);
1308 } else
1309 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1310
1311 if (ret < 0) {
1312 vty_out(vty,
1313 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1314 (set == 1) ? "" : "un",
1315 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1316 maxpaths, afi, safi);
1317 return CMD_WARNING_CONFIG_FAILED;
1318 }
1319
1320 bgp_recalculate_all_bestpaths(bgp);
1321
1322 return CMD_SUCCESS;
1323 }
1324
1325 DEFUN (bgp_maxmed_admin,
1326 bgp_maxmed_admin_cmd,
1327 "bgp max-med administrative ",
1328 BGP_STR
1329 "Advertise routes with max-med\n"
1330 "Administratively applied, for an indefinite period\n")
1331 {
1332 VTY_DECLVAR_CONTEXT(bgp, bgp);
1333
1334 bgp->v_maxmed_admin = 1;
1335 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1336
1337 bgp_maxmed_update(bgp);
1338
1339 return CMD_SUCCESS;
1340 }
1341
1342 DEFUN (bgp_maxmed_admin_medv,
1343 bgp_maxmed_admin_medv_cmd,
1344 "bgp max-med administrative (0-4294967295)",
1345 BGP_STR
1346 "Advertise routes with max-med\n"
1347 "Administratively applied, for an indefinite period\n"
1348 "Max MED value to be used\n")
1349 {
1350 VTY_DECLVAR_CONTEXT(bgp, bgp);
1351 int idx_number = 3;
1352
1353 bgp->v_maxmed_admin = 1;
1354 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1355
1356 bgp_maxmed_update(bgp);
1357
1358 return CMD_SUCCESS;
1359 }
1360
1361 DEFUN (no_bgp_maxmed_admin,
1362 no_bgp_maxmed_admin_cmd,
1363 "no bgp max-med administrative [(0-4294967295)]",
1364 NO_STR
1365 BGP_STR
1366 "Advertise routes with max-med\n"
1367 "Administratively applied, for an indefinite period\n"
1368 "Max MED value to be used\n")
1369 {
1370 VTY_DECLVAR_CONTEXT(bgp, bgp);
1371 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1372 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1373 bgp_maxmed_update(bgp);
1374
1375 return CMD_SUCCESS;
1376 }
1377
1378 DEFUN (bgp_maxmed_onstartup,
1379 bgp_maxmed_onstartup_cmd,
1380 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1381 BGP_STR
1382 "Advertise routes with max-med\n"
1383 "Effective on a startup\n"
1384 "Time (seconds) period for max-med\n"
1385 "Max MED value to be used\n")
1386 {
1387 VTY_DECLVAR_CONTEXT(bgp, bgp);
1388 int idx = 0;
1389
1390 argv_find(argv, argc, "(5-86400)", &idx);
1391 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1392 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1393 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1394 else
1395 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1396
1397 bgp_maxmed_update(bgp);
1398
1399 return CMD_SUCCESS;
1400 }
1401
1402 DEFUN (no_bgp_maxmed_onstartup,
1403 no_bgp_maxmed_onstartup_cmd,
1404 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1405 NO_STR
1406 BGP_STR
1407 "Advertise routes with max-med\n"
1408 "Effective on a startup\n"
1409 "Time (seconds) period for max-med\n"
1410 "Max MED value to be used\n")
1411 {
1412 VTY_DECLVAR_CONTEXT(bgp, bgp);
1413
1414 /* Cancel max-med onstartup if its on */
1415 if (bgp->t_maxmed_onstartup) {
1416 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1417 bgp->maxmed_onstartup_over = 1;
1418 }
1419
1420 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1421 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1422
1423 bgp_maxmed_update(bgp);
1424
1425 return CMD_SUCCESS;
1426 }
1427
1428 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1429 const char *wait)
1430 {
1431 VTY_DECLVAR_CONTEXT(bgp, bgp);
1432 uint16_t update_delay;
1433 uint16_t establish_wait;
1434
1435 update_delay = strtoul(delay, NULL, 10);
1436
1437 if (!wait) /* update-delay <delay> */
1438 {
1439 bgp->v_update_delay = update_delay;
1440 bgp->v_establish_wait = bgp->v_update_delay;
1441 return CMD_SUCCESS;
1442 }
1443
1444 /* update-delay <delay> <establish-wait> */
1445 establish_wait = atoi(wait);
1446 if (update_delay < establish_wait) {
1447 vty_out(vty,
1448 "%%Failed: update-delay less than the establish-wait!\n");
1449 return CMD_WARNING_CONFIG_FAILED;
1450 }
1451
1452 bgp->v_update_delay = update_delay;
1453 bgp->v_establish_wait = establish_wait;
1454
1455 return CMD_SUCCESS;
1456 }
1457
1458 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1459 {
1460 VTY_DECLVAR_CONTEXT(bgp, bgp);
1461
1462 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1463 bgp->v_establish_wait = bgp->v_update_delay;
1464
1465 return CMD_SUCCESS;
1466 }
1467
1468 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1469 {
1470 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1471 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1472 if (bgp->v_update_delay != bgp->v_establish_wait)
1473 vty_out(vty, " %d", bgp->v_establish_wait);
1474 vty_out(vty, "\n");
1475 }
1476 }
1477
1478
1479 /* Update-delay configuration */
1480 DEFUN (bgp_update_delay,
1481 bgp_update_delay_cmd,
1482 "update-delay (0-3600)",
1483 "Force initial delay for best-path and updates\n"
1484 "Seconds\n")
1485 {
1486 int idx_number = 1;
1487 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1488 }
1489
1490 DEFUN (bgp_update_delay_establish_wait,
1491 bgp_update_delay_establish_wait_cmd,
1492 "update-delay (0-3600) (1-3600)",
1493 "Force initial delay for best-path and updates\n"
1494 "Seconds\n"
1495 "Seconds\n")
1496 {
1497 int idx_number = 1;
1498 int idx_number_2 = 2;
1499 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1500 argv[idx_number_2]->arg);
1501 }
1502
1503 /* Update-delay deconfiguration */
1504 DEFUN (no_bgp_update_delay,
1505 no_bgp_update_delay_cmd,
1506 "no update-delay [(0-3600) [(1-3600)]]",
1507 NO_STR
1508 "Force initial delay for best-path and updates\n"
1509 "Seconds\n"
1510 "Seconds\n")
1511 {
1512 return bgp_update_delay_deconfig_vty(vty);
1513 }
1514
1515
1516 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1517 char set)
1518 {
1519 VTY_DECLVAR_CONTEXT(bgp, bgp);
1520
1521 if (set) {
1522 uint32_t quanta = strtoul(num, NULL, 10);
1523 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1524 memory_order_relaxed);
1525 } else {
1526 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1527 memory_order_relaxed);
1528 }
1529
1530 return CMD_SUCCESS;
1531 }
1532
1533 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1534 char set)
1535 {
1536 VTY_DECLVAR_CONTEXT(bgp, bgp);
1537
1538 if (set) {
1539 uint32_t quanta = strtoul(num, NULL, 10);
1540 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1541 memory_order_relaxed);
1542 } else {
1543 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1544 memory_order_relaxed);
1545 }
1546
1547 return CMD_SUCCESS;
1548 }
1549
1550 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1551 {
1552 uint32_t quanta =
1553 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1554 if (quanta != BGP_WRITE_PACKET_MAX)
1555 vty_out(vty, " write-quanta %d\n", quanta);
1556 }
1557
1558 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1559 {
1560 uint32_t quanta =
1561 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1562 if (quanta != BGP_READ_PACKET_MAX)
1563 vty_out(vty, " read-quanta %d\n", quanta);
1564 }
1565
1566 /* Packet quanta configuration */
1567 DEFUN (bgp_wpkt_quanta,
1568 bgp_wpkt_quanta_cmd,
1569 "write-quanta (1-10)",
1570 "How many packets to write to peer socket per run\n"
1571 "Number of packets\n")
1572 {
1573 int idx_number = 1;
1574 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1575 }
1576
1577 DEFUN (no_bgp_wpkt_quanta,
1578 no_bgp_wpkt_quanta_cmd,
1579 "no write-quanta (1-10)",
1580 NO_STR
1581 "How many packets to write to peer socket per I/O cycle\n"
1582 "Number of packets\n")
1583 {
1584 int idx_number = 2;
1585 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1586 }
1587
1588 DEFUN (bgp_rpkt_quanta,
1589 bgp_rpkt_quanta_cmd,
1590 "read-quanta (1-10)",
1591 "How many packets to read from peer socket per I/O cycle\n"
1592 "Number of packets\n")
1593 {
1594 int idx_number = 1;
1595 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1596 }
1597
1598 DEFUN (no_bgp_rpkt_quanta,
1599 no_bgp_rpkt_quanta_cmd,
1600 "no read-quanta (1-10)",
1601 NO_STR
1602 "How many packets to read from peer socket per I/O cycle\n"
1603 "Number of packets\n")
1604 {
1605 int idx_number = 2;
1606 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1607 }
1608
1609 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1610 {
1611 if (!bgp->heuristic_coalesce)
1612 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1613 }
1614
1615
1616 DEFUN (bgp_coalesce_time,
1617 bgp_coalesce_time_cmd,
1618 "coalesce-time (0-4294967295)",
1619 "Subgroup coalesce timer\n"
1620 "Subgroup coalesce timer value (in ms)\n")
1621 {
1622 VTY_DECLVAR_CONTEXT(bgp, bgp);
1623
1624 int idx = 0;
1625 argv_find(argv, argc, "(0-4294967295)", &idx);
1626 bgp->heuristic_coalesce = false;
1627 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1628 return CMD_SUCCESS;
1629 }
1630
1631 DEFUN (no_bgp_coalesce_time,
1632 no_bgp_coalesce_time_cmd,
1633 "no coalesce-time (0-4294967295)",
1634 NO_STR
1635 "Subgroup coalesce timer\n"
1636 "Subgroup coalesce timer value (in ms)\n")
1637 {
1638 VTY_DECLVAR_CONTEXT(bgp, bgp);
1639
1640 bgp->heuristic_coalesce = true;
1641 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1642 return CMD_SUCCESS;
1643 }
1644
1645 /* Maximum-paths configuration */
1646 DEFUN (bgp_maxpaths,
1647 bgp_maxpaths_cmd,
1648 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1649 "Forward packets over multiple paths\n"
1650 "Number of paths\n")
1651 {
1652 int idx_number = 1;
1653 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1654 argv[idx_number]->arg, 0, 1);
1655 }
1656
1657 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1658 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1659 "Forward packets over multiple paths\n"
1660 "Number of paths\n")
1661
1662 DEFUN (bgp_maxpaths_ibgp,
1663 bgp_maxpaths_ibgp_cmd,
1664 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1665 "Forward packets over multiple paths\n"
1666 "iBGP-multipath\n"
1667 "Number of paths\n")
1668 {
1669 int idx_number = 2;
1670 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1671 argv[idx_number]->arg, 0, 1);
1672 }
1673
1674 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1675 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1676 "Forward packets over multiple paths\n"
1677 "iBGP-multipath\n"
1678 "Number of paths\n")
1679
1680 DEFUN (bgp_maxpaths_ibgp_cluster,
1681 bgp_maxpaths_ibgp_cluster_cmd,
1682 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1683 "Forward packets over multiple paths\n"
1684 "iBGP-multipath\n"
1685 "Number of paths\n"
1686 "Match the cluster length\n")
1687 {
1688 int idx_number = 2;
1689 return bgp_maxpaths_config_vty(
1690 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1691 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1692 }
1693
1694 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1695 "maximum-paths ibgp " CMD_RANGE_STR(
1696 1, MULTIPATH_NUM) " equal-cluster-length",
1697 "Forward packets over multiple paths\n"
1698 "iBGP-multipath\n"
1699 "Number of paths\n"
1700 "Match the cluster length\n")
1701
1702 DEFUN (no_bgp_maxpaths,
1703 no_bgp_maxpaths_cmd,
1704 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1705 NO_STR
1706 "Forward packets over multiple paths\n"
1707 "Number of paths\n")
1708 {
1709 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1710 }
1711
1712 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1713 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1714 "Forward packets over multiple paths\n"
1715 "Number of paths\n")
1716
1717 DEFUN (no_bgp_maxpaths_ibgp,
1718 no_bgp_maxpaths_ibgp_cmd,
1719 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1720 NO_STR
1721 "Forward packets over multiple paths\n"
1722 "iBGP-multipath\n"
1723 "Number of paths\n"
1724 "Match the cluster length\n")
1725 {
1726 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1727 }
1728
1729 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1730 "no maximum-paths ibgp [" CMD_RANGE_STR(
1731 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1732 NO_STR
1733 "Forward packets over multiple paths\n"
1734 "iBGP-multipath\n"
1735 "Number of paths\n"
1736 "Match the cluster length\n")
1737
1738 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1739 safi_t safi)
1740 {
1741 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1742 vty_out(vty, " maximum-paths %d\n",
1743 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1744 }
1745
1746 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1747 vty_out(vty, " maximum-paths ibgp %d",
1748 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1749 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1750 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1751 vty_out(vty, " equal-cluster-length");
1752 vty_out(vty, "\n");
1753 }
1754 }
1755
1756 /* BGP timers. */
1757
1758 DEFUN (bgp_timers,
1759 bgp_timers_cmd,
1760 "timers bgp (0-65535) (0-65535)",
1761 "Adjust routing timers\n"
1762 "BGP timers\n"
1763 "Keepalive interval\n"
1764 "Holdtime\n")
1765 {
1766 VTY_DECLVAR_CONTEXT(bgp, bgp);
1767 int idx_number = 2;
1768 int idx_number_2 = 3;
1769 unsigned long keepalive = 0;
1770 unsigned long holdtime = 0;
1771
1772 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1773 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1774
1775 /* Holdtime value check. */
1776 if (holdtime < 3 && holdtime != 0) {
1777 vty_out(vty,
1778 "%% hold time value must be either 0 or greater than 3\n");
1779 return CMD_WARNING_CONFIG_FAILED;
1780 }
1781
1782 bgp_timers_set(bgp, keepalive, holdtime);
1783
1784 return CMD_SUCCESS;
1785 }
1786
1787 DEFUN (no_bgp_timers,
1788 no_bgp_timers_cmd,
1789 "no timers bgp [(0-65535) (0-65535)]",
1790 NO_STR
1791 "Adjust routing timers\n"
1792 "BGP timers\n"
1793 "Keepalive interval\n"
1794 "Holdtime\n")
1795 {
1796 VTY_DECLVAR_CONTEXT(bgp, bgp);
1797 bgp_timers_unset(bgp);
1798
1799 return CMD_SUCCESS;
1800 }
1801
1802
1803 DEFUN (bgp_client_to_client_reflection,
1804 bgp_client_to_client_reflection_cmd,
1805 "bgp client-to-client reflection",
1806 "BGP specific commands\n"
1807 "Configure client to client route reflection\n"
1808 "reflection of routes allowed\n")
1809 {
1810 VTY_DECLVAR_CONTEXT(bgp, bgp);
1811 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1812 bgp_clear_star_soft_out(vty, bgp->name);
1813
1814 return CMD_SUCCESS;
1815 }
1816
1817 DEFUN (no_bgp_client_to_client_reflection,
1818 no_bgp_client_to_client_reflection_cmd,
1819 "no bgp client-to-client reflection",
1820 NO_STR
1821 "BGP specific commands\n"
1822 "Configure client to client route reflection\n"
1823 "reflection of routes allowed\n")
1824 {
1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1827 bgp_clear_star_soft_out(vty, bgp->name);
1828
1829 return CMD_SUCCESS;
1830 }
1831
1832 /* "bgp always-compare-med" configuration. */
1833 DEFUN (bgp_always_compare_med,
1834 bgp_always_compare_med_cmd,
1835 "bgp always-compare-med",
1836 "BGP specific commands\n"
1837 "Allow comparing MED from different neighbors\n")
1838 {
1839 VTY_DECLVAR_CONTEXT(bgp, bgp);
1840 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1841 bgp_recalculate_all_bestpaths(bgp);
1842
1843 return CMD_SUCCESS;
1844 }
1845
1846 DEFUN (no_bgp_always_compare_med,
1847 no_bgp_always_compare_med_cmd,
1848 "no bgp always-compare-med",
1849 NO_STR
1850 "BGP specific commands\n"
1851 "Allow comparing MED from different neighbors\n")
1852 {
1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
1854 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1855 bgp_recalculate_all_bestpaths(bgp);
1856
1857 return CMD_SUCCESS;
1858 }
1859
1860 /* "bgp deterministic-med" configuration. */
1861 DEFUN (bgp_deterministic_med,
1862 bgp_deterministic_med_cmd,
1863 "bgp deterministic-med",
1864 "BGP specific commands\n"
1865 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1866 {
1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868
1869 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1870 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1871 bgp_recalculate_all_bestpaths(bgp);
1872 }
1873
1874 return CMD_SUCCESS;
1875 }
1876
1877 DEFUN (no_bgp_deterministic_med,
1878 no_bgp_deterministic_med_cmd,
1879 "no bgp deterministic-med",
1880 NO_STR
1881 "BGP specific commands\n"
1882 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1883 {
1884 VTY_DECLVAR_CONTEXT(bgp, bgp);
1885 int bestpath_per_as_used;
1886 afi_t afi;
1887 safi_t safi;
1888 struct peer *peer;
1889 struct listnode *node, *nnode;
1890
1891 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1892 bestpath_per_as_used = 0;
1893
1894 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1895 FOREACH_AFI_SAFI (afi, safi)
1896 if (bgp_addpath_dmed_required(
1897 peer->addpath_type[afi][safi])) {
1898 bestpath_per_as_used = 1;
1899 break;
1900 }
1901
1902 if (bestpath_per_as_used)
1903 break;
1904 }
1905
1906 if (bestpath_per_as_used) {
1907 vty_out(vty,
1908 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1909 return CMD_WARNING_CONFIG_FAILED;
1910 } else {
1911 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1912 bgp_recalculate_all_bestpaths(bgp);
1913 }
1914 }
1915
1916 return CMD_SUCCESS;
1917 }
1918
1919 /* "bgp graceful-restart" configuration. */
1920 DEFUN (bgp_graceful_restart,
1921 bgp_graceful_restart_cmd,
1922 "bgp graceful-restart",
1923 "BGP specific commands\n"
1924 "Graceful restart capability parameters\n")
1925 {
1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1928 return CMD_SUCCESS;
1929 }
1930
1931 DEFUN (no_bgp_graceful_restart,
1932 no_bgp_graceful_restart_cmd,
1933 "no bgp graceful-restart",
1934 NO_STR
1935 "BGP specific commands\n"
1936 "Graceful restart capability parameters\n")
1937 {
1938 VTY_DECLVAR_CONTEXT(bgp, bgp);
1939 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1940 return CMD_SUCCESS;
1941 }
1942
1943 DEFUN (bgp_graceful_restart_stalepath_time,
1944 bgp_graceful_restart_stalepath_time_cmd,
1945 "bgp graceful-restart stalepath-time (1-3600)",
1946 "BGP specific commands\n"
1947 "Graceful restart capability parameters\n"
1948 "Set the max time to hold onto restarting peer's stale paths\n"
1949 "Delay value (seconds)\n")
1950 {
1951 VTY_DECLVAR_CONTEXT(bgp, bgp);
1952 int idx_number = 3;
1953 uint32_t stalepath;
1954
1955 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1956 bgp->stalepath_time = stalepath;
1957 return CMD_SUCCESS;
1958 }
1959
1960 DEFUN (bgp_graceful_restart_restart_time,
1961 bgp_graceful_restart_restart_time_cmd,
1962 "bgp graceful-restart restart-time (1-3600)",
1963 "BGP specific commands\n"
1964 "Graceful restart capability parameters\n"
1965 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1966 "Delay value (seconds)\n")
1967 {
1968 VTY_DECLVAR_CONTEXT(bgp, bgp);
1969 int idx_number = 3;
1970 uint32_t restart;
1971
1972 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1973 bgp->restart_time = restart;
1974 return CMD_SUCCESS;
1975 }
1976
1977 DEFUN (no_bgp_graceful_restart_stalepath_time,
1978 no_bgp_graceful_restart_stalepath_time_cmd,
1979 "no bgp graceful-restart stalepath-time [(1-3600)]",
1980 NO_STR
1981 "BGP specific commands\n"
1982 "Graceful restart capability parameters\n"
1983 "Set the max time to hold onto restarting peer's stale paths\n"
1984 "Delay value (seconds)\n")
1985 {
1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
1987
1988 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1989 return CMD_SUCCESS;
1990 }
1991
1992 DEFUN (no_bgp_graceful_restart_restart_time,
1993 no_bgp_graceful_restart_restart_time_cmd,
1994 "no bgp graceful-restart restart-time [(1-3600)]",
1995 NO_STR
1996 "BGP specific commands\n"
1997 "Graceful restart capability parameters\n"
1998 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1999 "Delay value (seconds)\n")
2000 {
2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002
2003 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
2004 return CMD_SUCCESS;
2005 }
2006
2007 DEFUN (bgp_graceful_restart_preserve_fw,
2008 bgp_graceful_restart_preserve_fw_cmd,
2009 "bgp graceful-restart preserve-fw-state",
2010 "BGP specific commands\n"
2011 "Graceful restart capability parameters\n"
2012 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
2013 {
2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2016 return CMD_SUCCESS;
2017 }
2018
2019 DEFUN (no_bgp_graceful_restart_preserve_fw,
2020 no_bgp_graceful_restart_preserve_fw_cmd,
2021 "no bgp graceful-restart preserve-fw-state",
2022 NO_STR
2023 "BGP specific commands\n"
2024 "Graceful restart capability parameters\n"
2025 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
2026 {
2027 VTY_DECLVAR_CONTEXT(bgp, bgp);
2028 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
2029 return CMD_SUCCESS;
2030 }
2031
2032 static void bgp_redistribute_redo(struct bgp *bgp)
2033 {
2034 afi_t afi;
2035 int i;
2036 struct list *red_list;
2037 struct listnode *node;
2038 struct bgp_redist *red;
2039
2040 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2041 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
2042
2043 red_list = bgp->redist[afi][i];
2044 if (!red_list)
2045 continue;
2046
2047 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
2048 bgp_redistribute_resend(bgp, afi, i,
2049 red->instance);
2050 }
2051 }
2052 }
2053 }
2054
2055 /* "bgp graceful-shutdown" configuration */
2056 DEFUN (bgp_graceful_shutdown,
2057 bgp_graceful_shutdown_cmd,
2058 "bgp graceful-shutdown",
2059 BGP_STR
2060 "Graceful shutdown parameters\n")
2061 {
2062 VTY_DECLVAR_CONTEXT(bgp, bgp);
2063
2064 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2065 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2066 bgp_static_redo_import_check(bgp);
2067 bgp_redistribute_redo(bgp);
2068 bgp_clear_star_soft_out(vty, bgp->name);
2069 bgp_clear_star_soft_in(vty, bgp->name);
2070 }
2071
2072 return CMD_SUCCESS;
2073 }
2074
2075 DEFUN (no_bgp_graceful_shutdown,
2076 no_bgp_graceful_shutdown_cmd,
2077 "no bgp graceful-shutdown",
2078 NO_STR
2079 BGP_STR
2080 "Graceful shutdown parameters\n")
2081 {
2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083
2084 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2085 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2086 bgp_static_redo_import_check(bgp);
2087 bgp_redistribute_redo(bgp);
2088 bgp_clear_star_soft_out(vty, bgp->name);
2089 bgp_clear_star_soft_in(vty, bgp->name);
2090 }
2091
2092 return CMD_SUCCESS;
2093 }
2094
2095 /* "bgp fast-external-failover" configuration. */
2096 DEFUN (bgp_fast_external_failover,
2097 bgp_fast_external_failover_cmd,
2098 "bgp fast-external-failover",
2099 BGP_STR
2100 "Immediately reset session if a link to a directly connected external peer goes down\n")
2101 {
2102 VTY_DECLVAR_CONTEXT(bgp, bgp);
2103 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2104 return CMD_SUCCESS;
2105 }
2106
2107 DEFUN (no_bgp_fast_external_failover,
2108 no_bgp_fast_external_failover_cmd,
2109 "no bgp fast-external-failover",
2110 NO_STR
2111 BGP_STR
2112 "Immediately reset session if a link to a directly connected external peer goes down\n")
2113 {
2114 VTY_DECLVAR_CONTEXT(bgp, bgp);
2115 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2116 return CMD_SUCCESS;
2117 }
2118
2119 /* "bgp enforce-first-as" configuration. */
2120 #if CONFDATE > 20190517
2121 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2122 #endif
2123
2124 DEFUN_HIDDEN (bgp_enforce_first_as,
2125 bgp_enforce_first_as_cmd,
2126 "[no] bgp enforce-first-as",
2127 NO_STR
2128 BGP_STR
2129 "Enforce the first AS for EBGP routes\n")
2130 {
2131 VTY_DECLVAR_CONTEXT(bgp, bgp);
2132
2133 if (strmatch(argv[0]->text, "no"))
2134 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2135 else
2136 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2137
2138 return CMD_SUCCESS;
2139 }
2140
2141 /* "bgp bestpath compare-routerid" configuration. */
2142 DEFUN (bgp_bestpath_compare_router_id,
2143 bgp_bestpath_compare_router_id_cmd,
2144 "bgp bestpath compare-routerid",
2145 "BGP specific commands\n"
2146 "Change the default bestpath selection\n"
2147 "Compare router-id for identical EBGP paths\n")
2148 {
2149 VTY_DECLVAR_CONTEXT(bgp, bgp);
2150 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2151 bgp_recalculate_all_bestpaths(bgp);
2152
2153 return CMD_SUCCESS;
2154 }
2155
2156 DEFUN (no_bgp_bestpath_compare_router_id,
2157 no_bgp_bestpath_compare_router_id_cmd,
2158 "no bgp bestpath compare-routerid",
2159 NO_STR
2160 "BGP specific commands\n"
2161 "Change the default bestpath selection\n"
2162 "Compare router-id for identical EBGP paths\n")
2163 {
2164 VTY_DECLVAR_CONTEXT(bgp, bgp);
2165 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2166 bgp_recalculate_all_bestpaths(bgp);
2167
2168 return CMD_SUCCESS;
2169 }
2170
2171 /* "bgp bestpath as-path ignore" configuration. */
2172 DEFUN (bgp_bestpath_aspath_ignore,
2173 bgp_bestpath_aspath_ignore_cmd,
2174 "bgp bestpath as-path ignore",
2175 "BGP specific commands\n"
2176 "Change the default bestpath selection\n"
2177 "AS-path attribute\n"
2178 "Ignore as-path length in selecting a route\n")
2179 {
2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
2181 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2182 bgp_recalculate_all_bestpaths(bgp);
2183
2184 return CMD_SUCCESS;
2185 }
2186
2187 DEFUN (no_bgp_bestpath_aspath_ignore,
2188 no_bgp_bestpath_aspath_ignore_cmd,
2189 "no bgp bestpath as-path ignore",
2190 NO_STR
2191 "BGP specific commands\n"
2192 "Change the default bestpath selection\n"
2193 "AS-path attribute\n"
2194 "Ignore as-path length in selecting a route\n")
2195 {
2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
2197 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2198 bgp_recalculate_all_bestpaths(bgp);
2199
2200 return CMD_SUCCESS;
2201 }
2202
2203 /* "bgp bestpath as-path confed" configuration. */
2204 DEFUN (bgp_bestpath_aspath_confed,
2205 bgp_bestpath_aspath_confed_cmd,
2206 "bgp bestpath as-path confed",
2207 "BGP specific commands\n"
2208 "Change the default bestpath selection\n"
2209 "AS-path attribute\n"
2210 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2211 {
2212 VTY_DECLVAR_CONTEXT(bgp, bgp);
2213 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2214 bgp_recalculate_all_bestpaths(bgp);
2215
2216 return CMD_SUCCESS;
2217 }
2218
2219 DEFUN (no_bgp_bestpath_aspath_confed,
2220 no_bgp_bestpath_aspath_confed_cmd,
2221 "no bgp bestpath as-path confed",
2222 NO_STR
2223 "BGP specific commands\n"
2224 "Change the default bestpath selection\n"
2225 "AS-path attribute\n"
2226 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2227 {
2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2230 bgp_recalculate_all_bestpaths(bgp);
2231
2232 return CMD_SUCCESS;
2233 }
2234
2235 /* "bgp bestpath as-path multipath-relax" configuration. */
2236 DEFUN (bgp_bestpath_aspath_multipath_relax,
2237 bgp_bestpath_aspath_multipath_relax_cmd,
2238 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2239 "BGP specific commands\n"
2240 "Change the default bestpath selection\n"
2241 "AS-path attribute\n"
2242 "Allow load sharing across routes that have different AS paths (but same length)\n"
2243 "Generate an AS_SET\n"
2244 "Do not generate an AS_SET\n")
2245 {
2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
2247 int idx = 0;
2248 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2249
2250 /* no-as-set is now the default behavior so we can silently
2251 * ignore it */
2252 if (argv_find(argv, argc, "as-set", &idx))
2253 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2254 else
2255 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2256
2257 bgp_recalculate_all_bestpaths(bgp);
2258
2259 return CMD_SUCCESS;
2260 }
2261
2262 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2263 no_bgp_bestpath_aspath_multipath_relax_cmd,
2264 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2265 NO_STR
2266 "BGP specific commands\n"
2267 "Change the default bestpath selection\n"
2268 "AS-path attribute\n"
2269 "Allow load sharing across routes that have different AS paths (but same length)\n"
2270 "Generate an AS_SET\n"
2271 "Do not generate an AS_SET\n")
2272 {
2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2275 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2276 bgp_recalculate_all_bestpaths(bgp);
2277
2278 return CMD_SUCCESS;
2279 }
2280
2281 /* "bgp log-neighbor-changes" configuration. */
2282 DEFUN (bgp_log_neighbor_changes,
2283 bgp_log_neighbor_changes_cmd,
2284 "bgp log-neighbor-changes",
2285 "BGP specific commands\n"
2286 "Log neighbor up/down and reset reason\n")
2287 {
2288 VTY_DECLVAR_CONTEXT(bgp, bgp);
2289 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2290 return CMD_SUCCESS;
2291 }
2292
2293 DEFUN (no_bgp_log_neighbor_changes,
2294 no_bgp_log_neighbor_changes_cmd,
2295 "no bgp log-neighbor-changes",
2296 NO_STR
2297 "BGP specific commands\n"
2298 "Log neighbor up/down and reset reason\n")
2299 {
2300 VTY_DECLVAR_CONTEXT(bgp, bgp);
2301 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2302 return CMD_SUCCESS;
2303 }
2304
2305 /* "bgp bestpath med" configuration. */
2306 DEFUN (bgp_bestpath_med,
2307 bgp_bestpath_med_cmd,
2308 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2309 "BGP specific commands\n"
2310 "Change the default bestpath selection\n"
2311 "MED attribute\n"
2312 "Compare MED among confederation paths\n"
2313 "Treat missing MED as the least preferred one\n"
2314 "Treat missing MED as the least preferred one\n"
2315 "Compare MED among confederation paths\n")
2316 {
2317 VTY_DECLVAR_CONTEXT(bgp, bgp);
2318
2319 int idx = 0;
2320 if (argv_find(argv, argc, "confed", &idx))
2321 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2322 idx = 0;
2323 if (argv_find(argv, argc, "missing-as-worst", &idx))
2324 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2325
2326 bgp_recalculate_all_bestpaths(bgp);
2327
2328 return CMD_SUCCESS;
2329 }
2330
2331 DEFUN (no_bgp_bestpath_med,
2332 no_bgp_bestpath_med_cmd,
2333 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2334 NO_STR
2335 "BGP specific commands\n"
2336 "Change the default bestpath selection\n"
2337 "MED attribute\n"
2338 "Compare MED among confederation paths\n"
2339 "Treat missing MED as the least preferred one\n"
2340 "Treat missing MED as the least preferred one\n"
2341 "Compare MED among confederation paths\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344
2345 int idx = 0;
2346 if (argv_find(argv, argc, "confed", &idx))
2347 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2348 idx = 0;
2349 if (argv_find(argv, argc, "missing-as-worst", &idx))
2350 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2351
2352 bgp_recalculate_all_bestpaths(bgp);
2353
2354 return CMD_SUCCESS;
2355 }
2356
2357 /* "no bgp default ipv4-unicast". */
2358 DEFUN (no_bgp_default_ipv4_unicast,
2359 no_bgp_default_ipv4_unicast_cmd,
2360 "no bgp default ipv4-unicast",
2361 NO_STR
2362 "BGP specific commands\n"
2363 "Configure BGP defaults\n"
2364 "Activate ipv4-unicast for a peer by default\n")
2365 {
2366 VTY_DECLVAR_CONTEXT(bgp, bgp);
2367 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2368 return CMD_SUCCESS;
2369 }
2370
2371 DEFUN (bgp_default_ipv4_unicast,
2372 bgp_default_ipv4_unicast_cmd,
2373 "bgp default ipv4-unicast",
2374 "BGP specific commands\n"
2375 "Configure BGP defaults\n"
2376 "Activate ipv4-unicast for a peer by default\n")
2377 {
2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
2379 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2380 return CMD_SUCCESS;
2381 }
2382
2383 /* Display hostname in certain command outputs */
2384 DEFUN (bgp_default_show_hostname,
2385 bgp_default_show_hostname_cmd,
2386 "bgp default show-hostname",
2387 "BGP specific commands\n"
2388 "Configure BGP defaults\n"
2389 "Show hostname in certain command outputs\n")
2390 {
2391 VTY_DECLVAR_CONTEXT(bgp, bgp);
2392 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2393 return CMD_SUCCESS;
2394 }
2395
2396 DEFUN (no_bgp_default_show_hostname,
2397 no_bgp_default_show_hostname_cmd,
2398 "no bgp default show-hostname",
2399 NO_STR
2400 "BGP specific commands\n"
2401 "Configure BGP defaults\n"
2402 "Show hostname in certain command outputs\n")
2403 {
2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2406 return CMD_SUCCESS;
2407 }
2408
2409 /* "bgp network import-check" configuration. */
2410 DEFUN (bgp_network_import_check,
2411 bgp_network_import_check_cmd,
2412 "bgp network import-check",
2413 "BGP specific commands\n"
2414 "BGP network command\n"
2415 "Check BGP network route exists in IGP\n")
2416 {
2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2419 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2420 bgp_static_redo_import_check(bgp);
2421 }
2422
2423 return CMD_SUCCESS;
2424 }
2425
2426 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2427 "bgp network import-check exact",
2428 "BGP specific commands\n"
2429 "BGP network command\n"
2430 "Check BGP network route exists in IGP\n"
2431 "Match route precisely\n")
2432
2433 DEFUN (no_bgp_network_import_check,
2434 no_bgp_network_import_check_cmd,
2435 "no bgp network import-check",
2436 NO_STR
2437 "BGP specific commands\n"
2438 "BGP network command\n"
2439 "Check BGP network route exists in IGP\n")
2440 {
2441 VTY_DECLVAR_CONTEXT(bgp, bgp);
2442 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2443 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2444 bgp_static_redo_import_check(bgp);
2445 }
2446
2447 return CMD_SUCCESS;
2448 }
2449
2450 DEFUN (bgp_default_local_preference,
2451 bgp_default_local_preference_cmd,
2452 "bgp default local-preference (0-4294967295)",
2453 "BGP specific commands\n"
2454 "Configure BGP defaults\n"
2455 "local preference (higher=more preferred)\n"
2456 "Configure default local preference value\n")
2457 {
2458 VTY_DECLVAR_CONTEXT(bgp, bgp);
2459 int idx_number = 3;
2460 uint32_t local_pref;
2461
2462 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2463
2464 bgp_default_local_preference_set(bgp, local_pref);
2465 bgp_clear_star_soft_in(vty, bgp->name);
2466
2467 return CMD_SUCCESS;
2468 }
2469
2470 DEFUN (no_bgp_default_local_preference,
2471 no_bgp_default_local_preference_cmd,
2472 "no bgp default local-preference [(0-4294967295)]",
2473 NO_STR
2474 "BGP specific commands\n"
2475 "Configure BGP defaults\n"
2476 "local preference (higher=more preferred)\n"
2477 "Configure default local preference value\n")
2478 {
2479 VTY_DECLVAR_CONTEXT(bgp, bgp);
2480 bgp_default_local_preference_unset(bgp);
2481 bgp_clear_star_soft_in(vty, bgp->name);
2482
2483 return CMD_SUCCESS;
2484 }
2485
2486
2487 DEFUN (bgp_default_subgroup_pkt_queue_max,
2488 bgp_default_subgroup_pkt_queue_max_cmd,
2489 "bgp default subgroup-pkt-queue-max (20-100)",
2490 "BGP specific commands\n"
2491 "Configure BGP defaults\n"
2492 "subgroup-pkt-queue-max\n"
2493 "Configure subgroup packet queue max\n")
2494 {
2495 VTY_DECLVAR_CONTEXT(bgp, bgp);
2496 int idx_number = 3;
2497 uint32_t max_size;
2498
2499 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2500
2501 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2502
2503 return CMD_SUCCESS;
2504 }
2505
2506 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2507 no_bgp_default_subgroup_pkt_queue_max_cmd,
2508 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2509 NO_STR
2510 "BGP specific commands\n"
2511 "Configure BGP defaults\n"
2512 "subgroup-pkt-queue-max\n"
2513 "Configure subgroup packet queue max\n")
2514 {
2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
2516 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2517 return CMD_SUCCESS;
2518 }
2519
2520
2521 DEFUN (bgp_rr_allow_outbound_policy,
2522 bgp_rr_allow_outbound_policy_cmd,
2523 "bgp route-reflector allow-outbound-policy",
2524 "BGP specific commands\n"
2525 "Allow modifications made by out route-map\n"
2526 "on ibgp neighbors\n")
2527 {
2528 VTY_DECLVAR_CONTEXT(bgp, bgp);
2529
2530 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2531 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2532 update_group_announce_rrclients(bgp);
2533 bgp_clear_star_soft_out(vty, bgp->name);
2534 }
2535
2536 return CMD_SUCCESS;
2537 }
2538
2539 DEFUN (no_bgp_rr_allow_outbound_policy,
2540 no_bgp_rr_allow_outbound_policy_cmd,
2541 "no bgp route-reflector allow-outbound-policy",
2542 NO_STR
2543 "BGP specific commands\n"
2544 "Allow modifications made by out route-map\n"
2545 "on ibgp neighbors\n")
2546 {
2547 VTY_DECLVAR_CONTEXT(bgp, bgp);
2548
2549 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2550 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2551 update_group_announce_rrclients(bgp);
2552 bgp_clear_star_soft_out(vty, bgp->name);
2553 }
2554
2555 return CMD_SUCCESS;
2556 }
2557
2558 DEFUN (bgp_listen_limit,
2559 bgp_listen_limit_cmd,
2560 "bgp listen limit (1-5000)",
2561 "BGP specific commands\n"
2562 "Configure BGP defaults\n"
2563 "maximum number of BGP Dynamic Neighbors that can be created\n"
2564 "Configure Dynamic Neighbors listen limit value\n")
2565 {
2566 VTY_DECLVAR_CONTEXT(bgp, bgp);
2567 int idx_number = 3;
2568 int listen_limit;
2569
2570 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2571
2572 bgp_listen_limit_set(bgp, listen_limit);
2573
2574 return CMD_SUCCESS;
2575 }
2576
2577 DEFUN (no_bgp_listen_limit,
2578 no_bgp_listen_limit_cmd,
2579 "no bgp listen limit [(1-5000)]",
2580 "BGP specific commands\n"
2581 "Configure BGP defaults\n"
2582 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2583 "Configure Dynamic Neighbors listen limit value to default\n"
2584 "Configure Dynamic Neighbors listen limit value\n")
2585 {
2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 bgp_listen_limit_unset(bgp);
2588 return CMD_SUCCESS;
2589 }
2590
2591
2592 /*
2593 * Check if this listen range is already configured. Check for exact
2594 * match or overlap based on input.
2595 */
2596 static struct peer_group *listen_range_exists(struct bgp *bgp,
2597 struct prefix *range, int exact)
2598 {
2599 struct listnode *node, *nnode;
2600 struct listnode *node1, *nnode1;
2601 struct peer_group *group;
2602 struct prefix *lr;
2603 afi_t afi;
2604 int match;
2605
2606 afi = family2afi(range->family);
2607 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2608 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2609 lr)) {
2610 if (exact)
2611 match = prefix_same(range, lr);
2612 else
2613 match = (prefix_match(range, lr)
2614 || prefix_match(lr, range));
2615 if (match)
2616 return group;
2617 }
2618 }
2619
2620 return NULL;
2621 }
2622
2623 DEFUN (bgp_listen_range,
2624 bgp_listen_range_cmd,
2625 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2626 "BGP specific commands\n"
2627 "Configure BGP dynamic neighbors listen range\n"
2628 "Configure BGP dynamic neighbors listen range\n"
2629 NEIGHBOR_ADDR_STR
2630 "Member of the peer-group\n"
2631 "Peer-group name\n")
2632 {
2633 VTY_DECLVAR_CONTEXT(bgp, bgp);
2634 struct prefix range;
2635 struct peer_group *group, *existing_group;
2636 afi_t afi;
2637 int ret;
2638 int idx = 0;
2639
2640 argv_find(argv, argc, "A.B.C.D/M", &idx);
2641 argv_find(argv, argc, "X:X::X:X/M", &idx);
2642 char *prefix = argv[idx]->arg;
2643 argv_find(argv, argc, "WORD", &idx);
2644 char *peergroup = argv[idx]->arg;
2645
2646 /* Convert IP prefix string to struct prefix. */
2647 ret = str2prefix(prefix, &range);
2648 if (!ret) {
2649 vty_out(vty, "%% Malformed listen range\n");
2650 return CMD_WARNING_CONFIG_FAILED;
2651 }
2652
2653 afi = family2afi(range.family);
2654
2655 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2656 vty_out(vty,
2657 "%% Malformed listen range (link-local address)\n");
2658 return CMD_WARNING_CONFIG_FAILED;
2659 }
2660
2661 apply_mask(&range);
2662
2663 /* Check if same listen range is already configured. */
2664 existing_group = listen_range_exists(bgp, &range, 1);
2665 if (existing_group) {
2666 if (strcmp(existing_group->name, peergroup) == 0)
2667 return CMD_SUCCESS;
2668 else {
2669 vty_out(vty,
2670 "%% Same listen range is attached to peer-group %s\n",
2671 existing_group->name);
2672 return CMD_WARNING_CONFIG_FAILED;
2673 }
2674 }
2675
2676 /* Check if an overlapping listen range exists. */
2677 if (listen_range_exists(bgp, &range, 0)) {
2678 vty_out(vty,
2679 "%% Listen range overlaps with existing listen range\n");
2680 return CMD_WARNING_CONFIG_FAILED;
2681 }
2682
2683 group = peer_group_lookup(bgp, peergroup);
2684 if (!group) {
2685 vty_out(vty, "%% Configure the peer-group first\n");
2686 return CMD_WARNING_CONFIG_FAILED;
2687 }
2688
2689 ret = peer_group_listen_range_add(group, &range);
2690 return bgp_vty_return(vty, ret);
2691 }
2692
2693 DEFUN (no_bgp_listen_range,
2694 no_bgp_listen_range_cmd,
2695 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2696 NO_STR
2697 "BGP specific commands\n"
2698 "Unconfigure BGP dynamic neighbors listen range\n"
2699 "Unconfigure BGP dynamic neighbors listen range\n"
2700 NEIGHBOR_ADDR_STR
2701 "Member of the peer-group\n"
2702 "Peer-group name\n")
2703 {
2704 VTY_DECLVAR_CONTEXT(bgp, bgp);
2705 struct prefix range;
2706 struct peer_group *group;
2707 afi_t afi;
2708 int ret;
2709 int idx = 0;
2710
2711 argv_find(argv, argc, "A.B.C.D/M", &idx);
2712 argv_find(argv, argc, "X:X::X:X/M", &idx);
2713 char *prefix = argv[idx]->arg;
2714 argv_find(argv, argc, "WORD", &idx);
2715 char *peergroup = argv[idx]->arg;
2716
2717 /* Convert IP prefix string to struct prefix. */
2718 ret = str2prefix(prefix, &range);
2719 if (!ret) {
2720 vty_out(vty, "%% Malformed listen range\n");
2721 return CMD_WARNING_CONFIG_FAILED;
2722 }
2723
2724 afi = family2afi(range.family);
2725
2726 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2727 vty_out(vty,
2728 "%% Malformed listen range (link-local address)\n");
2729 return CMD_WARNING_CONFIG_FAILED;
2730 }
2731
2732 apply_mask(&range);
2733
2734 group = peer_group_lookup(bgp, peergroup);
2735 if (!group) {
2736 vty_out(vty, "%% Peer-group does not exist\n");
2737 return CMD_WARNING_CONFIG_FAILED;
2738 }
2739
2740 ret = peer_group_listen_range_del(group, &range);
2741 return bgp_vty_return(vty, ret);
2742 }
2743
2744 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2745 {
2746 struct peer_group *group;
2747 struct listnode *node, *nnode, *rnode, *nrnode;
2748 struct prefix *range;
2749 afi_t afi;
2750 char buf[PREFIX2STR_BUFFER];
2751
2752 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2753 vty_out(vty, " bgp listen limit %d\n",
2754 bgp->dynamic_neighbors_limit);
2755
2756 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2757 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2758 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2759 nrnode, range)) {
2760 prefix2str(range, buf, sizeof(buf));
2761 vty_out(vty,
2762 " bgp listen range %s peer-group %s\n",
2763 buf, group->name);
2764 }
2765 }
2766 }
2767 }
2768
2769
2770 DEFUN (bgp_disable_connected_route_check,
2771 bgp_disable_connected_route_check_cmd,
2772 "bgp disable-ebgp-connected-route-check",
2773 "BGP specific commands\n"
2774 "Disable checking if nexthop is connected on ebgp sessions\n")
2775 {
2776 VTY_DECLVAR_CONTEXT(bgp, bgp);
2777 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2778 bgp_clear_star_soft_in(vty, bgp->name);
2779
2780 return CMD_SUCCESS;
2781 }
2782
2783 DEFUN (no_bgp_disable_connected_route_check,
2784 no_bgp_disable_connected_route_check_cmd,
2785 "no bgp disable-ebgp-connected-route-check",
2786 NO_STR
2787 "BGP specific commands\n"
2788 "Disable checking if nexthop is connected on ebgp sessions\n")
2789 {
2790 VTY_DECLVAR_CONTEXT(bgp, bgp);
2791 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2792 bgp_clear_star_soft_in(vty, bgp->name);
2793
2794 return CMD_SUCCESS;
2795 }
2796
2797
2798 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2799 const char *as_str, afi_t afi, safi_t safi)
2800 {
2801 VTY_DECLVAR_CONTEXT(bgp, bgp);
2802 int ret;
2803 as_t as;
2804 int as_type = AS_SPECIFIED;
2805 union sockunion su;
2806
2807 if (as_str[0] == 'i') {
2808 as = 0;
2809 as_type = AS_INTERNAL;
2810 } else if (as_str[0] == 'e') {
2811 as = 0;
2812 as_type = AS_EXTERNAL;
2813 } else {
2814 /* Get AS number. */
2815 as = strtoul(as_str, NULL, 10);
2816 }
2817
2818 /* If peer is peer group, call proper function. */
2819 ret = str2sockunion(peer_str, &su);
2820 if (ret < 0) {
2821 /* Check for peer by interface */
2822 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2823 safi);
2824 if (ret < 0) {
2825 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2826 if (ret < 0) {
2827 vty_out(vty,
2828 "%% Create the peer-group or interface first or specify \"interface\" keyword\n");
2829 vty_out(vty, "%% if using an unnumbered interface neighbor\n");
2830 return CMD_WARNING_CONFIG_FAILED;
2831 }
2832 return CMD_SUCCESS;
2833 }
2834 } else {
2835 if (peer_address_self_check(bgp, &su)) {
2836 vty_out(vty,
2837 "%% Can not configure the local system as neighbor\n");
2838 return CMD_WARNING_CONFIG_FAILED;
2839 }
2840 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2841 }
2842
2843 /* This peer belongs to peer group. */
2844 switch (ret) {
2845 case BGP_ERR_PEER_GROUP_MEMBER:
2846 vty_out(vty,
2847 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2848 as);
2849 return CMD_WARNING_CONFIG_FAILED;
2850 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2851 vty_out(vty,
2852 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2853 as, as_str);
2854 return CMD_WARNING_CONFIG_FAILED;
2855 }
2856 return bgp_vty_return(vty, ret);
2857 }
2858
2859 DEFUN (bgp_default_shutdown,
2860 bgp_default_shutdown_cmd,
2861 "[no] bgp default shutdown",
2862 NO_STR
2863 BGP_STR
2864 "Configure BGP defaults\n"
2865 "Apply administrative shutdown to newly configured peers\n")
2866 {
2867 VTY_DECLVAR_CONTEXT(bgp, bgp);
2868 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2869 return CMD_SUCCESS;
2870 }
2871
2872 DEFUN (neighbor_remote_as,
2873 neighbor_remote_as_cmd,
2874 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2875 NEIGHBOR_STR
2876 NEIGHBOR_ADDR_STR2
2877 "Specify a BGP neighbor\n"
2878 AS_STR
2879 "Internal BGP peer\n"
2880 "External BGP peer\n")
2881 {
2882 int idx_peer = 1;
2883 int idx_remote_as = 3;
2884 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2885 argv[idx_remote_as]->arg, AFI_IP,
2886 SAFI_UNICAST);
2887 }
2888
2889 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2890 afi_t afi, safi_t safi, int v6only,
2891 const char *peer_group_name,
2892 const char *as_str)
2893 {
2894 VTY_DECLVAR_CONTEXT(bgp, bgp);
2895 as_t as = 0;
2896 int as_type = AS_UNSPECIFIED;
2897 struct peer *peer;
2898 struct peer_group *group;
2899 int ret = 0;
2900 union sockunion su;
2901
2902 group = peer_group_lookup(bgp, conf_if);
2903
2904 if (group) {
2905 vty_out(vty, "%% Name conflict with peer-group \n");
2906 return CMD_WARNING_CONFIG_FAILED;
2907 }
2908
2909 if (as_str) {
2910 if (as_str[0] == 'i') {
2911 as_type = AS_INTERNAL;
2912 } else if (as_str[0] == 'e') {
2913 as_type = AS_EXTERNAL;
2914 } else {
2915 /* Get AS number. */
2916 as = strtoul(as_str, NULL, 10);
2917 as_type = AS_SPECIFIED;
2918 }
2919 }
2920
2921 peer = peer_lookup_by_conf_if(bgp, conf_if);
2922 if (peer) {
2923 if (as_str)
2924 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2925 afi, safi);
2926 } else {
2927 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2928 && afi == AFI_IP && safi == SAFI_UNICAST)
2929 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2930 as_type, 0, 0, NULL);
2931 else
2932 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2933 as_type, afi, safi, NULL);
2934
2935 if (!peer) {
2936 vty_out(vty, "%% BGP failed to create peer\n");
2937 return CMD_WARNING_CONFIG_FAILED;
2938 }
2939
2940 if (v6only)
2941 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2942
2943 /* Request zebra to initiate IPv6 RAs on this interface. We do
2944 * this
2945 * any unnumbered peer in order to not worry about run-time
2946 * transitions
2947 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2948 * address
2949 * gets deleted later etc.)
2950 */
2951 if (peer->ifp)
2952 bgp_zebra_initiate_radv(bgp, peer);
2953 }
2954
2955 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2956 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2957 if (v6only)
2958 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2959 else
2960 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2961
2962 /* v6only flag changed. Reset bgp seesion */
2963 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2964 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2965 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2966 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2967 } else
2968 bgp_session_reset(peer);
2969 }
2970
2971 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2972 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2973 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2974 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2975 }
2976
2977 if (peer_group_name) {
2978 group = peer_group_lookup(bgp, peer_group_name);
2979 if (!group) {
2980 vty_out(vty, "%% Configure the peer-group first\n");
2981 return CMD_WARNING_CONFIG_FAILED;
2982 }
2983
2984 ret = peer_group_bind(bgp, &su, peer, group, &as);
2985 }
2986
2987 return bgp_vty_return(vty, ret);
2988 }
2989
2990 DEFUN (neighbor_interface_config,
2991 neighbor_interface_config_cmd,
2992 "neighbor WORD interface [peer-group WORD]",
2993 NEIGHBOR_STR
2994 "Interface name or neighbor tag\n"
2995 "Enable BGP on interface\n"
2996 "Member of the peer-group\n"
2997 "Peer-group name\n")
2998 {
2999 int idx_word = 1;
3000 int idx_peer_group_word = 4;
3001
3002 if (argc > idx_peer_group_word)
3003 return peer_conf_interface_get(
3004 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
3005 argv[idx_peer_group_word]->arg, NULL);
3006 else
3007 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3008 SAFI_UNICAST, 0, NULL, NULL);
3009 }
3010
3011 DEFUN (neighbor_interface_config_v6only,
3012 neighbor_interface_config_v6only_cmd,
3013 "neighbor WORD interface v6only [peer-group WORD]",
3014 NEIGHBOR_STR
3015 "Interface name or neighbor tag\n"
3016 "Enable BGP on interface\n"
3017 "Enable BGP with v6 link-local only\n"
3018 "Member of the peer-group\n"
3019 "Peer-group name\n")
3020 {
3021 int idx_word = 1;
3022 int idx_peer_group_word = 5;
3023
3024 if (argc > idx_peer_group_word)
3025 return peer_conf_interface_get(
3026 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
3027 argv[idx_peer_group_word]->arg, NULL);
3028
3029 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3030 SAFI_UNICAST, 1, NULL, NULL);
3031 }
3032
3033
3034 DEFUN (neighbor_interface_config_remote_as,
3035 neighbor_interface_config_remote_as_cmd,
3036 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
3037 NEIGHBOR_STR
3038 "Interface name or neighbor tag\n"
3039 "Enable BGP on interface\n"
3040 "Specify a BGP neighbor\n"
3041 AS_STR
3042 "Internal BGP peer\n"
3043 "External BGP peer\n")
3044 {
3045 int idx_word = 1;
3046 int idx_remote_as = 4;
3047 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3048 SAFI_UNICAST, 0, NULL,
3049 argv[idx_remote_as]->arg);
3050 }
3051
3052 DEFUN (neighbor_interface_v6only_config_remote_as,
3053 neighbor_interface_v6only_config_remote_as_cmd,
3054 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
3055 NEIGHBOR_STR
3056 "Interface name or neighbor tag\n"
3057 "Enable BGP with v6 link-local only\n"
3058 "Enable BGP on interface\n"
3059 "Specify a BGP neighbor\n"
3060 AS_STR
3061 "Internal BGP peer\n"
3062 "External BGP peer\n")
3063 {
3064 int idx_word = 1;
3065 int idx_remote_as = 5;
3066 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
3067 SAFI_UNICAST, 1, NULL,
3068 argv[idx_remote_as]->arg);
3069 }
3070
3071 DEFUN (neighbor_peer_group,
3072 neighbor_peer_group_cmd,
3073 "neighbor WORD peer-group",
3074 NEIGHBOR_STR
3075 "Interface name or neighbor tag\n"
3076 "Configure peer-group\n")
3077 {
3078 VTY_DECLVAR_CONTEXT(bgp, bgp);
3079 int idx_word = 1;
3080 struct peer *peer;
3081 struct peer_group *group;
3082
3083 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3084 if (peer) {
3085 vty_out(vty, "%% Name conflict with interface: \n");
3086 return CMD_WARNING_CONFIG_FAILED;
3087 }
3088
3089 group = peer_group_get(bgp, argv[idx_word]->arg);
3090 if (!group) {
3091 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3092 return CMD_WARNING_CONFIG_FAILED;
3093 }
3094
3095 return CMD_SUCCESS;
3096 }
3097
3098 DEFUN (no_neighbor,
3099 no_neighbor_cmd,
3100 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3101 NO_STR
3102 NEIGHBOR_STR
3103 NEIGHBOR_ADDR_STR2
3104 "Specify a BGP neighbor\n"
3105 AS_STR
3106 "Internal BGP peer\n"
3107 "External BGP peer\n")
3108 {
3109 VTY_DECLVAR_CONTEXT(bgp, bgp);
3110 int idx_peer = 2;
3111 int ret;
3112 union sockunion su;
3113 struct peer_group *group;
3114 struct peer *peer;
3115 struct peer *other;
3116
3117 ret = str2sockunion(argv[idx_peer]->arg, &su);
3118 if (ret < 0) {
3119 /* look up for neighbor by interface name config. */
3120 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3121 if (peer) {
3122 /* Request zebra to terminate IPv6 RAs on this
3123 * interface. */
3124 if (peer->ifp)
3125 bgp_zebra_terminate_radv(peer->bgp, peer);
3126 peer_delete(peer);
3127 return CMD_SUCCESS;
3128 }
3129
3130 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3131 if (group)
3132 peer_group_delete(group);
3133 else {
3134 vty_out(vty, "%% Create the peer-group first\n");
3135 return CMD_WARNING_CONFIG_FAILED;
3136 }
3137 } else {
3138 peer = peer_lookup(bgp, &su);
3139 if (peer) {
3140 if (peer_dynamic_neighbor(peer)) {
3141 vty_out(vty,
3142 "%% Operation not allowed on a dynamic neighbor\n");
3143 return CMD_WARNING_CONFIG_FAILED;
3144 }
3145
3146 other = peer->doppelganger;
3147 peer_delete(peer);
3148 if (other && other->status != Deleted)
3149 peer_delete(other);
3150 }
3151 }
3152
3153 return CMD_SUCCESS;
3154 }
3155
3156 DEFUN (no_neighbor_interface_config,
3157 no_neighbor_interface_config_cmd,
3158 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3159 NO_STR
3160 NEIGHBOR_STR
3161 "Interface name\n"
3162 "Configure BGP on interface\n"
3163 "Enable BGP with v6 link-local only\n"
3164 "Member of the peer-group\n"
3165 "Peer-group name\n"
3166 "Specify a BGP neighbor\n"
3167 AS_STR
3168 "Internal BGP peer\n"
3169 "External BGP peer\n")
3170 {
3171 VTY_DECLVAR_CONTEXT(bgp, bgp);
3172 int idx_word = 2;
3173 struct peer *peer;
3174
3175 /* look up for neighbor by interface name config. */
3176 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3177 if (peer) {
3178 /* Request zebra to terminate IPv6 RAs on this interface. */
3179 if (peer->ifp)
3180 bgp_zebra_terminate_radv(peer->bgp, peer);
3181 peer_delete(peer);
3182 } else {
3183 vty_out(vty, "%% Create the bgp interface first\n");
3184 return CMD_WARNING_CONFIG_FAILED;
3185 }
3186 return CMD_SUCCESS;
3187 }
3188
3189 DEFUN (no_neighbor_peer_group,
3190 no_neighbor_peer_group_cmd,
3191 "no neighbor WORD peer-group",
3192 NO_STR
3193 NEIGHBOR_STR
3194 "Neighbor tag\n"
3195 "Configure peer-group\n")
3196 {
3197 VTY_DECLVAR_CONTEXT(bgp, bgp);
3198 int idx_word = 2;
3199 struct peer_group *group;
3200
3201 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3202 if (group)
3203 peer_group_delete(group);
3204 else {
3205 vty_out(vty, "%% Create the peer-group first\n");
3206 return CMD_WARNING_CONFIG_FAILED;
3207 }
3208 return CMD_SUCCESS;
3209 }
3210
3211 DEFUN (no_neighbor_interface_peer_group_remote_as,
3212 no_neighbor_interface_peer_group_remote_as_cmd,
3213 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3214 NO_STR
3215 NEIGHBOR_STR
3216 "Interface name or neighbor tag\n"
3217 "Specify a BGP neighbor\n"
3218 AS_STR
3219 "Internal BGP peer\n"
3220 "External BGP peer\n")
3221 {
3222 VTY_DECLVAR_CONTEXT(bgp, bgp);
3223 int idx_word = 2;
3224 struct peer_group *group;
3225 struct peer *peer;
3226
3227 /* look up for neighbor by interface name config. */
3228 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3229 if (peer) {
3230 peer_as_change(peer, 0, AS_SPECIFIED);
3231 return CMD_SUCCESS;
3232 }
3233
3234 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3235 if (group)
3236 peer_group_remote_as_delete(group);
3237 else {
3238 vty_out(vty, "%% Create the peer-group or interface first\n");
3239 return CMD_WARNING_CONFIG_FAILED;
3240 }
3241 return CMD_SUCCESS;
3242 }
3243
3244 DEFUN (neighbor_local_as,
3245 neighbor_local_as_cmd,
3246 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3247 NEIGHBOR_STR
3248 NEIGHBOR_ADDR_STR2
3249 "Specify a local-as number\n"
3250 "AS number used as local AS\n")
3251 {
3252 int idx_peer = 1;
3253 int idx_number = 3;
3254 struct peer *peer;
3255 int ret;
3256 as_t as;
3257
3258 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3259 if (!peer)
3260 return CMD_WARNING_CONFIG_FAILED;
3261
3262 as = strtoul(argv[idx_number]->arg, NULL, 10);
3263 ret = peer_local_as_set(peer, as, 0, 0);
3264 return bgp_vty_return(vty, ret);
3265 }
3266
3267 DEFUN (neighbor_local_as_no_prepend,
3268 neighbor_local_as_no_prepend_cmd,
3269 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3270 NEIGHBOR_STR
3271 NEIGHBOR_ADDR_STR2
3272 "Specify a local-as number\n"
3273 "AS number used as local AS\n"
3274 "Do not prepend local-as to updates from ebgp peers\n")
3275 {
3276 int idx_peer = 1;
3277 int idx_number = 3;
3278 struct peer *peer;
3279 int ret;
3280 as_t as;
3281
3282 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3283 if (!peer)
3284 return CMD_WARNING_CONFIG_FAILED;
3285
3286 as = strtoul(argv[idx_number]->arg, NULL, 10);
3287 ret = peer_local_as_set(peer, as, 1, 0);
3288 return bgp_vty_return(vty, ret);
3289 }
3290
3291 DEFUN (neighbor_local_as_no_prepend_replace_as,
3292 neighbor_local_as_no_prepend_replace_as_cmd,
3293 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3294 NEIGHBOR_STR
3295 NEIGHBOR_ADDR_STR2
3296 "Specify a local-as number\n"
3297 "AS number used as local AS\n"
3298 "Do not prepend local-as to updates from ebgp peers\n"
3299 "Do not prepend local-as to updates from ibgp peers\n")
3300 {
3301 int idx_peer = 1;
3302 int idx_number = 3;
3303 struct peer *peer;
3304 int ret;
3305 as_t as;
3306
3307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3308 if (!peer)
3309 return CMD_WARNING_CONFIG_FAILED;
3310
3311 as = strtoul(argv[idx_number]->arg, NULL, 10);
3312 ret = peer_local_as_set(peer, as, 1, 1);
3313 return bgp_vty_return(vty, ret);
3314 }
3315
3316 DEFUN (no_neighbor_local_as,
3317 no_neighbor_local_as_cmd,
3318 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3319 NO_STR
3320 NEIGHBOR_STR
3321 NEIGHBOR_ADDR_STR2
3322 "Specify a local-as number\n"
3323 "AS number used as local AS\n"
3324 "Do not prepend local-as to updates from ebgp peers\n"
3325 "Do not prepend local-as to updates from ibgp peers\n")
3326 {
3327 int idx_peer = 2;
3328 struct peer *peer;
3329 int ret;
3330
3331 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3332 if (!peer)
3333 return CMD_WARNING_CONFIG_FAILED;
3334
3335 ret = peer_local_as_unset(peer);
3336 return bgp_vty_return(vty, ret);
3337 }
3338
3339
3340 DEFUN (neighbor_solo,
3341 neighbor_solo_cmd,
3342 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3343 NEIGHBOR_STR
3344 NEIGHBOR_ADDR_STR2
3345 "Solo peer - part of its own update group\n")
3346 {
3347 int idx_peer = 1;
3348 struct peer *peer;
3349 int ret;
3350
3351 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3352 if (!peer)
3353 return CMD_WARNING_CONFIG_FAILED;
3354
3355 ret = update_group_adjust_soloness(peer, 1);
3356 return bgp_vty_return(vty, ret);
3357 }
3358
3359 DEFUN (no_neighbor_solo,
3360 no_neighbor_solo_cmd,
3361 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3362 NO_STR
3363 NEIGHBOR_STR
3364 NEIGHBOR_ADDR_STR2
3365 "Solo peer - part of its own update group\n")
3366 {
3367 int idx_peer = 2;
3368 struct peer *peer;
3369 int ret;
3370
3371 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3372 if (!peer)
3373 return CMD_WARNING_CONFIG_FAILED;
3374
3375 ret = update_group_adjust_soloness(peer, 0);
3376 return bgp_vty_return(vty, ret);
3377 }
3378
3379 DEFUN (neighbor_password,
3380 neighbor_password_cmd,
3381 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3382 NEIGHBOR_STR
3383 NEIGHBOR_ADDR_STR2
3384 "Set a password\n"
3385 "The password\n")
3386 {
3387 int idx_peer = 1;
3388 int idx_line = 3;
3389 struct peer *peer;
3390 int ret;
3391
3392 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3393 if (!peer)
3394 return CMD_WARNING_CONFIG_FAILED;
3395
3396 ret = peer_password_set(peer, argv[idx_line]->arg);
3397 return bgp_vty_return(vty, ret);
3398 }
3399
3400 DEFUN (no_neighbor_password,
3401 no_neighbor_password_cmd,
3402 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3403 NO_STR
3404 NEIGHBOR_STR
3405 NEIGHBOR_ADDR_STR2
3406 "Set a password\n"
3407 "The password\n")
3408 {
3409 int idx_peer = 2;
3410 struct peer *peer;
3411 int ret;
3412
3413 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3414 if (!peer)
3415 return CMD_WARNING_CONFIG_FAILED;
3416
3417 ret = peer_password_unset(peer);
3418 return bgp_vty_return(vty, ret);
3419 }
3420
3421 DEFUN (neighbor_activate,
3422 neighbor_activate_cmd,
3423 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3424 NEIGHBOR_STR
3425 NEIGHBOR_ADDR_STR2
3426 "Enable the Address Family for this Neighbor\n")
3427 {
3428 int idx_peer = 1;
3429 int ret;
3430 struct peer *peer;
3431
3432 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3433 if (!peer)
3434 return CMD_WARNING_CONFIG_FAILED;
3435
3436 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3437 return bgp_vty_return(vty, ret);
3438 }
3439
3440 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3441 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3442 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3443 "Enable the Address Family for this Neighbor\n")
3444
3445 DEFUN (no_neighbor_activate,
3446 no_neighbor_activate_cmd,
3447 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3448 NO_STR
3449 NEIGHBOR_STR
3450 NEIGHBOR_ADDR_STR2
3451 "Enable the Address Family for this Neighbor\n")
3452 {
3453 int idx_peer = 2;
3454 int ret;
3455 struct peer *peer;
3456
3457 /* Lookup peer. */
3458 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3459 if (!peer)
3460 return CMD_WARNING_CONFIG_FAILED;
3461
3462 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3463 return bgp_vty_return(vty, ret);
3464 }
3465
3466 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3467 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3468 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3469 "Enable the Address Family for this Neighbor\n")
3470
3471 DEFUN (neighbor_set_peer_group,
3472 neighbor_set_peer_group_cmd,
3473 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3474 NEIGHBOR_STR
3475 NEIGHBOR_ADDR_STR2
3476 "Member of the peer-group\n"
3477 "Peer-group name\n")
3478 {
3479 VTY_DECLVAR_CONTEXT(bgp, bgp);
3480 int idx_peer = 1;
3481 int idx_word = 3;
3482 int ret;
3483 as_t as;
3484 union sockunion su;
3485 struct peer *peer;
3486 struct peer_group *group;
3487
3488 ret = str2sockunion(argv[idx_peer]->arg, &su);
3489 if (ret < 0) {
3490 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3491 if (!peer) {
3492 vty_out(vty, "%% Malformed address or name: %s\n",
3493 argv[idx_peer]->arg);
3494 return CMD_WARNING_CONFIG_FAILED;
3495 }
3496 } else {
3497 if (peer_address_self_check(bgp, &su)) {
3498 vty_out(vty,
3499 "%% Can not configure the local system as neighbor\n");
3500 return CMD_WARNING_CONFIG_FAILED;
3501 }
3502
3503 /* Disallow for dynamic neighbor. */
3504 peer = peer_lookup(bgp, &su);
3505 if (peer && peer_dynamic_neighbor(peer)) {
3506 vty_out(vty,
3507 "%% Operation not allowed on a dynamic neighbor\n");
3508 return CMD_WARNING_CONFIG_FAILED;
3509 }
3510 }
3511
3512 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3513 if (!group) {
3514 vty_out(vty, "%% Configure the peer-group first\n");
3515 return CMD_WARNING_CONFIG_FAILED;
3516 }
3517
3518 ret = peer_group_bind(bgp, &su, peer, group, &as);
3519
3520 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3521 vty_out(vty,
3522 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3523 as);
3524 return CMD_WARNING_CONFIG_FAILED;
3525 }
3526
3527 return bgp_vty_return(vty, ret);
3528 }
3529
3530 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3531 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3532 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3533 "Member of the peer-group\n"
3534 "Peer-group name\n")
3535
3536 DEFUN (no_neighbor_set_peer_group,
3537 no_neighbor_set_peer_group_cmd,
3538 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3539 NO_STR
3540 NEIGHBOR_STR
3541 NEIGHBOR_ADDR_STR2
3542 "Member of the peer-group\n"
3543 "Peer-group name\n")
3544 {
3545 VTY_DECLVAR_CONTEXT(bgp, bgp);
3546 int idx_peer = 2;
3547 int idx_word = 4;
3548 int ret;
3549 struct peer *peer;
3550 struct peer_group *group;
3551
3552 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3553 if (!peer)
3554 return CMD_WARNING_CONFIG_FAILED;
3555
3556 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3557 if (!group) {
3558 vty_out(vty, "%% Configure the peer-group first\n");
3559 return CMD_WARNING_CONFIG_FAILED;
3560 }
3561
3562 ret = peer_delete(peer);
3563
3564 return bgp_vty_return(vty, ret);
3565 }
3566
3567 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3568 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3570 "Member of the peer-group\n"
3571 "Peer-group name\n")
3572
3573 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3574 uint32_t flag, int set)
3575 {
3576 int ret;
3577 struct peer *peer;
3578
3579 peer = peer_and_group_lookup_vty(vty, ip_str);
3580 if (!peer)
3581 return CMD_WARNING_CONFIG_FAILED;
3582
3583 /*
3584 * If 'neighbor <interface>', then this is for directly connected peers,
3585 * we should not accept disable-connected-check.
3586 */
3587 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3588 vty_out(vty,
3589 "%s is directly connected peer, cannot accept disable-"
3590 "connected-check\n",
3591 ip_str);
3592 return CMD_WARNING_CONFIG_FAILED;
3593 }
3594
3595 if (!set && flag == PEER_FLAG_SHUTDOWN)
3596 peer_tx_shutdown_message_unset(peer);
3597
3598 if (set)
3599 ret = peer_flag_set(peer, flag);
3600 else
3601 ret = peer_flag_unset(peer, flag);
3602
3603 return bgp_vty_return(vty, ret);
3604 }
3605
3606 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3607 {
3608 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3609 }
3610
3611 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3612 uint32_t flag)
3613 {
3614 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3615 }
3616
3617 /* neighbor passive. */
3618 DEFUN (neighbor_passive,
3619 neighbor_passive_cmd,
3620 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3621 NEIGHBOR_STR
3622 NEIGHBOR_ADDR_STR2
3623 "Don't send open messages to this neighbor\n")
3624 {
3625 int idx_peer = 1;
3626 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3627 }
3628
3629 DEFUN (no_neighbor_passive,
3630 no_neighbor_passive_cmd,
3631 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3632 NO_STR
3633 NEIGHBOR_STR
3634 NEIGHBOR_ADDR_STR2
3635 "Don't send open messages to this neighbor\n")
3636 {
3637 int idx_peer = 2;
3638 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3639 }
3640
3641 /* neighbor shutdown. */
3642 DEFUN (neighbor_shutdown_msg,
3643 neighbor_shutdown_msg_cmd,
3644 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
3647 "Administratively shut down this neighbor\n"
3648 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3649 "Shutdown message\n")
3650 {
3651 int idx_peer = 1;
3652
3653 if (argc >= 5) {
3654 struct peer *peer =
3655 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3656 char *message;
3657
3658 if (!peer)
3659 return CMD_WARNING_CONFIG_FAILED;
3660 message = argv_concat(argv, argc, 4);
3661 peer_tx_shutdown_message_set(peer, message);
3662 XFREE(MTYPE_TMP, message);
3663 }
3664
3665 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3666 }
3667
3668 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3669 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3670 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3671 "Administratively shut down this neighbor\n")
3672
3673 DEFUN (no_neighbor_shutdown_msg,
3674 no_neighbor_shutdown_msg_cmd,
3675 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3676 NO_STR
3677 NEIGHBOR_STR
3678 NEIGHBOR_ADDR_STR2
3679 "Administratively shut down this neighbor\n"
3680 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3681 "Shutdown message\n")
3682 {
3683 int idx_peer = 2;
3684
3685 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3686 PEER_FLAG_SHUTDOWN);
3687 }
3688
3689 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3690 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3691 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3692 "Administratively shut down this neighbor\n")
3693
3694 /* neighbor capability dynamic. */
3695 DEFUN (neighbor_capability_dynamic,
3696 neighbor_capability_dynamic_cmd,
3697 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3698 NEIGHBOR_STR
3699 NEIGHBOR_ADDR_STR2
3700 "Advertise capability to the peer\n"
3701 "Advertise dynamic capability to this neighbor\n")
3702 {
3703 int idx_peer = 1;
3704 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3705 PEER_FLAG_DYNAMIC_CAPABILITY);
3706 }
3707
3708 DEFUN (no_neighbor_capability_dynamic,
3709 no_neighbor_capability_dynamic_cmd,
3710 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3711 NO_STR
3712 NEIGHBOR_STR
3713 NEIGHBOR_ADDR_STR2
3714 "Advertise capability to the peer\n"
3715 "Advertise dynamic capability to this neighbor\n")
3716 {
3717 int idx_peer = 2;
3718 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3719 PEER_FLAG_DYNAMIC_CAPABILITY);
3720 }
3721
3722 /* neighbor dont-capability-negotiate */
3723 DEFUN (neighbor_dont_capability_negotiate,
3724 neighbor_dont_capability_negotiate_cmd,
3725 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3726 NEIGHBOR_STR
3727 NEIGHBOR_ADDR_STR2
3728 "Do not perform capability negotiation\n")
3729 {
3730 int idx_peer = 1;
3731 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3732 PEER_FLAG_DONT_CAPABILITY);
3733 }
3734
3735 DEFUN (no_neighbor_dont_capability_negotiate,
3736 no_neighbor_dont_capability_negotiate_cmd,
3737 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3738 NO_STR
3739 NEIGHBOR_STR
3740 NEIGHBOR_ADDR_STR2
3741 "Do not perform capability negotiation\n")
3742 {
3743 int idx_peer = 2;
3744 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3745 PEER_FLAG_DONT_CAPABILITY);
3746 }
3747
3748 /* neighbor capability extended next hop encoding */
3749 DEFUN (neighbor_capability_enhe,
3750 neighbor_capability_enhe_cmd,
3751 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3752 NEIGHBOR_STR
3753 NEIGHBOR_ADDR_STR2
3754 "Advertise capability to the peer\n"
3755 "Advertise extended next-hop capability to the peer\n")
3756 {
3757 int idx_peer = 1;
3758 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3759 PEER_FLAG_CAPABILITY_ENHE);
3760 }
3761
3762 DEFUN (no_neighbor_capability_enhe,
3763 no_neighbor_capability_enhe_cmd,
3764 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3765 NO_STR
3766 NEIGHBOR_STR
3767 NEIGHBOR_ADDR_STR2
3768 "Advertise capability to the peer\n"
3769 "Advertise extended next-hop capability to the peer\n")
3770 {
3771 int idx_peer = 2;
3772 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3773 PEER_FLAG_CAPABILITY_ENHE);
3774 }
3775
3776 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3777 afi_t afi, safi_t safi, uint32_t flag,
3778 int set)
3779 {
3780 int ret;
3781 struct peer *peer;
3782
3783 peer = peer_and_group_lookup_vty(vty, peer_str);
3784 if (!peer)
3785 return CMD_WARNING_CONFIG_FAILED;
3786
3787 if (set)
3788 ret = peer_af_flag_set(peer, afi, safi, flag);
3789 else
3790 ret = peer_af_flag_unset(peer, afi, safi, flag);
3791
3792 return bgp_vty_return(vty, ret);
3793 }
3794
3795 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3796 afi_t afi, safi_t safi, uint32_t flag)
3797 {
3798 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3799 }
3800
3801 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3802 afi_t afi, safi_t safi, uint32_t flag)
3803 {
3804 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3805 }
3806
3807 /* neighbor capability orf prefix-list. */
3808 DEFUN (neighbor_capability_orf_prefix,
3809 neighbor_capability_orf_prefix_cmd,
3810 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3811 NEIGHBOR_STR
3812 NEIGHBOR_ADDR_STR2
3813 "Advertise capability to the peer\n"
3814 "Advertise ORF capability to the peer\n"
3815 "Advertise prefixlist ORF capability to this neighbor\n"
3816 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3817 "Capability to RECEIVE the ORF from this neighbor\n"
3818 "Capability to SEND the ORF to this neighbor\n")
3819 {
3820 int idx_peer = 1;
3821 int idx_send_recv = 5;
3822 uint16_t flag = 0;
3823
3824 if (strmatch(argv[idx_send_recv]->text, "send"))
3825 flag = PEER_FLAG_ORF_PREFIX_SM;
3826 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3827 flag = PEER_FLAG_ORF_PREFIX_RM;
3828 else if (strmatch(argv[idx_send_recv]->text, "both"))
3829 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3830 else {
3831 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3832 return CMD_WARNING_CONFIG_FAILED;
3833 }
3834
3835 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3836 bgp_node_safi(vty), flag);
3837 }
3838
3839 ALIAS_HIDDEN(
3840 neighbor_capability_orf_prefix,
3841 neighbor_capability_orf_prefix_hidden_cmd,
3842 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3843 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3844 "Advertise capability to the peer\n"
3845 "Advertise ORF capability to the peer\n"
3846 "Advertise prefixlist ORF capability to this neighbor\n"
3847 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3848 "Capability to RECEIVE the ORF from this neighbor\n"
3849 "Capability to SEND the ORF to this neighbor\n")
3850
3851 DEFUN (no_neighbor_capability_orf_prefix,
3852 no_neighbor_capability_orf_prefix_cmd,
3853 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3854 NO_STR
3855 NEIGHBOR_STR
3856 NEIGHBOR_ADDR_STR2
3857 "Advertise capability to the peer\n"
3858 "Advertise ORF capability to the peer\n"
3859 "Advertise prefixlist ORF capability to this neighbor\n"
3860 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3861 "Capability to RECEIVE the ORF from this neighbor\n"
3862 "Capability to SEND the ORF to this neighbor\n")
3863 {
3864 int idx_peer = 2;
3865 int idx_send_recv = 6;
3866 uint16_t flag = 0;
3867
3868 if (strmatch(argv[idx_send_recv]->text, "send"))
3869 flag = PEER_FLAG_ORF_PREFIX_SM;
3870 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3871 flag = PEER_FLAG_ORF_PREFIX_RM;
3872 else if (strmatch(argv[idx_send_recv]->text, "both"))
3873 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3874 else {
3875 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3876 return CMD_WARNING_CONFIG_FAILED;
3877 }
3878
3879 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3880 bgp_node_afi(vty), bgp_node_safi(vty),
3881 flag);
3882 }
3883
3884 ALIAS_HIDDEN(
3885 no_neighbor_capability_orf_prefix,
3886 no_neighbor_capability_orf_prefix_hidden_cmd,
3887 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3888 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3889 "Advertise capability to the peer\n"
3890 "Advertise ORF capability to the peer\n"
3891 "Advertise prefixlist ORF capability to this neighbor\n"
3892 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3893 "Capability to RECEIVE the ORF from this neighbor\n"
3894 "Capability to SEND the ORF to this neighbor\n")
3895
3896 /* neighbor next-hop-self. */
3897 DEFUN (neighbor_nexthop_self,
3898 neighbor_nexthop_self_cmd,
3899 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3900 NEIGHBOR_STR
3901 NEIGHBOR_ADDR_STR2
3902 "Disable the next hop calculation for this neighbor\n")
3903 {
3904 int idx_peer = 1;
3905 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3906 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3907 }
3908
3909 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3910 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3912 "Disable the next hop calculation for this neighbor\n")
3913
3914 /* neighbor next-hop-self. */
3915 DEFUN (neighbor_nexthop_self_force,
3916 neighbor_nexthop_self_force_cmd,
3917 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3918 NEIGHBOR_STR
3919 NEIGHBOR_ADDR_STR2
3920 "Disable the next hop calculation for this neighbor\n"
3921 "Set the next hop to self for reflected routes\n")
3922 {
3923 int idx_peer = 1;
3924 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3925 bgp_node_safi(vty),
3926 PEER_FLAG_FORCE_NEXTHOP_SELF);
3927 }
3928
3929 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3930 neighbor_nexthop_self_force_hidden_cmd,
3931 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3932 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3933 "Disable the next hop calculation for this neighbor\n"
3934 "Set the next hop to self for reflected routes\n")
3935
3936 DEFUN (no_neighbor_nexthop_self,
3937 no_neighbor_nexthop_self_cmd,
3938 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3939 NO_STR
3940 NEIGHBOR_STR
3941 NEIGHBOR_ADDR_STR2
3942 "Disable the next hop calculation for this neighbor\n")
3943 {
3944 int idx_peer = 2;
3945 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3946 bgp_node_afi(vty), bgp_node_safi(vty),
3947 PEER_FLAG_NEXTHOP_SELF);
3948 }
3949
3950 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3951 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3952 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3953 "Disable the next hop calculation for this neighbor\n")
3954
3955 DEFUN (no_neighbor_nexthop_self_force,
3956 no_neighbor_nexthop_self_force_cmd,
3957 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3958 NO_STR
3959 NEIGHBOR_STR
3960 NEIGHBOR_ADDR_STR2
3961 "Disable the next hop calculation for this neighbor\n"
3962 "Set the next hop to self for reflected routes\n")
3963 {
3964 int idx_peer = 2;
3965 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3966 bgp_node_afi(vty), bgp_node_safi(vty),
3967 PEER_FLAG_FORCE_NEXTHOP_SELF);
3968 }
3969
3970 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3971 no_neighbor_nexthop_self_force_hidden_cmd,
3972 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3974 "Disable the next hop calculation for this neighbor\n"
3975 "Set the next hop to self for reflected routes\n")
3976
3977 /* neighbor as-override */
3978 DEFUN (neighbor_as_override,
3979 neighbor_as_override_cmd,
3980 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3981 NEIGHBOR_STR
3982 NEIGHBOR_ADDR_STR2
3983 "Override ASNs in outbound updates if aspath equals remote-as\n")
3984 {
3985 int idx_peer = 1;
3986 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3987 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3988 }
3989
3990 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3991 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3992 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3993 "Override ASNs in outbound updates if aspath equals remote-as\n")
3994
3995 DEFUN (no_neighbor_as_override,
3996 no_neighbor_as_override_cmd,
3997 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3998 NO_STR
3999 NEIGHBOR_STR
4000 NEIGHBOR_ADDR_STR2
4001 "Override ASNs in outbound updates if aspath equals remote-as\n")
4002 {
4003 int idx_peer = 2;
4004 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4005 bgp_node_afi(vty), bgp_node_safi(vty),
4006 PEER_FLAG_AS_OVERRIDE);
4007 }
4008
4009 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
4010 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
4011 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4012 "Override ASNs in outbound updates if aspath equals remote-as\n")
4013
4014 /* neighbor remove-private-AS. */
4015 DEFUN (neighbor_remove_private_as,
4016 neighbor_remove_private_as_cmd,
4017 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4018 NEIGHBOR_STR
4019 NEIGHBOR_ADDR_STR2
4020 "Remove private ASNs in outbound updates\n")
4021 {
4022 int idx_peer = 1;
4023 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4024 bgp_node_safi(vty),
4025 PEER_FLAG_REMOVE_PRIVATE_AS);
4026 }
4027
4028 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
4029 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n")
4032
4033 DEFUN (neighbor_remove_private_as_all,
4034 neighbor_remove_private_as_all_cmd,
4035 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4036 NEIGHBOR_STR
4037 NEIGHBOR_ADDR_STR2
4038 "Remove private ASNs in outbound updates\n"
4039 "Apply to all AS numbers\n")
4040 {
4041 int idx_peer = 1;
4042 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4043 bgp_node_safi(vty),
4044 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4045 }
4046
4047 ALIAS_HIDDEN(neighbor_remove_private_as_all,
4048 neighbor_remove_private_as_all_hidden_cmd,
4049 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4050 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4051 "Remove private ASNs in outbound updates\n"
4052 "Apply to all AS numbers")
4053
4054 DEFUN (neighbor_remove_private_as_replace_as,
4055 neighbor_remove_private_as_replace_as_cmd,
4056 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4057 NEIGHBOR_STR
4058 NEIGHBOR_ADDR_STR2
4059 "Remove private ASNs in outbound updates\n"
4060 "Replace private ASNs with our ASN in outbound updates\n")
4061 {
4062 int idx_peer = 1;
4063 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4064 bgp_node_safi(vty),
4065 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4066 }
4067
4068 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
4069 neighbor_remove_private_as_replace_as_hidden_cmd,
4070 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4072 "Remove private ASNs in outbound updates\n"
4073 "Replace private ASNs with our ASN in outbound updates\n")
4074
4075 DEFUN (neighbor_remove_private_as_all_replace_as,
4076 neighbor_remove_private_as_all_replace_as_cmd,
4077 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4078 NEIGHBOR_STR
4079 NEIGHBOR_ADDR_STR2
4080 "Remove private ASNs in outbound updates\n"
4081 "Apply to all AS numbers\n"
4082 "Replace private ASNs with our ASN in outbound updates\n")
4083 {
4084 int idx_peer = 1;
4085 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4086 bgp_node_safi(vty),
4087 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4088 }
4089
4090 ALIAS_HIDDEN(
4091 neighbor_remove_private_as_all_replace_as,
4092 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4093 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4094 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4095 "Remove private ASNs in outbound updates\n"
4096 "Apply to all AS numbers\n"
4097 "Replace private ASNs with our ASN in outbound updates\n")
4098
4099 DEFUN (no_neighbor_remove_private_as,
4100 no_neighbor_remove_private_as_cmd,
4101 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4102 NO_STR
4103 NEIGHBOR_STR
4104 NEIGHBOR_ADDR_STR2
4105 "Remove private ASNs in outbound updates\n")
4106 {
4107 int idx_peer = 2;
4108 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4109 bgp_node_afi(vty), bgp_node_safi(vty),
4110 PEER_FLAG_REMOVE_PRIVATE_AS);
4111 }
4112
4113 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4114 no_neighbor_remove_private_as_hidden_cmd,
4115 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4116 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4117 "Remove private ASNs in outbound updates\n")
4118
4119 DEFUN (no_neighbor_remove_private_as_all,
4120 no_neighbor_remove_private_as_all_cmd,
4121 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4122 NO_STR
4123 NEIGHBOR_STR
4124 NEIGHBOR_ADDR_STR2
4125 "Remove private ASNs in outbound updates\n"
4126 "Apply to all AS numbers\n")
4127 {
4128 int idx_peer = 2;
4129 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4130 bgp_node_afi(vty), bgp_node_safi(vty),
4131 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4132 }
4133
4134 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4135 no_neighbor_remove_private_as_all_hidden_cmd,
4136 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4137 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4138 "Remove private ASNs in outbound updates\n"
4139 "Apply to all AS numbers\n")
4140
4141 DEFUN (no_neighbor_remove_private_as_replace_as,
4142 no_neighbor_remove_private_as_replace_as_cmd,
4143 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4144 NO_STR
4145 NEIGHBOR_STR
4146 NEIGHBOR_ADDR_STR2
4147 "Remove private ASNs in outbound updates\n"
4148 "Replace private ASNs with our ASN in outbound updates\n")
4149 {
4150 int idx_peer = 2;
4151 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4152 bgp_node_afi(vty), bgp_node_safi(vty),
4153 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4154 }
4155
4156 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4157 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4158 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4160 "Remove private ASNs in outbound updates\n"
4161 "Replace private ASNs with our ASN in outbound updates\n")
4162
4163 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4164 no_neighbor_remove_private_as_all_replace_as_cmd,
4165 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4166 NO_STR
4167 NEIGHBOR_STR
4168 NEIGHBOR_ADDR_STR2
4169 "Remove private ASNs in outbound updates\n"
4170 "Apply to all AS numbers\n"
4171 "Replace private ASNs with our ASN in outbound updates\n")
4172 {
4173 int idx_peer = 2;
4174 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4175 bgp_node_afi(vty), bgp_node_safi(vty),
4176 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4177 }
4178
4179 ALIAS_HIDDEN(
4180 no_neighbor_remove_private_as_all_replace_as,
4181 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4182 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4183 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4184 "Remove private ASNs in outbound updates\n"
4185 "Apply to all AS numbers\n"
4186 "Replace private ASNs with our ASN in outbound updates\n")
4187
4188
4189 /* neighbor send-community. */
4190 DEFUN (neighbor_send_community,
4191 neighbor_send_community_cmd,
4192 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4193 NEIGHBOR_STR
4194 NEIGHBOR_ADDR_STR2
4195 "Send Community attribute to this neighbor\n")
4196 {
4197 int idx_peer = 1;
4198
4199 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4200 bgp_node_safi(vty),
4201 PEER_FLAG_SEND_COMMUNITY);
4202 }
4203
4204 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4205 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4206 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4207 "Send Community attribute to this neighbor\n")
4208
4209 DEFUN (no_neighbor_send_community,
4210 no_neighbor_send_community_cmd,
4211 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4212 NO_STR
4213 NEIGHBOR_STR
4214 NEIGHBOR_ADDR_STR2
4215 "Send Community attribute to this neighbor\n")
4216 {
4217 int idx_peer = 2;
4218
4219 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4220 bgp_node_afi(vty), bgp_node_safi(vty),
4221 PEER_FLAG_SEND_COMMUNITY);
4222 }
4223
4224 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4225 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4226 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4227 "Send Community attribute to this neighbor\n")
4228
4229 /* neighbor send-community extended. */
4230 DEFUN (neighbor_send_community_type,
4231 neighbor_send_community_type_cmd,
4232 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4233 NEIGHBOR_STR
4234 NEIGHBOR_ADDR_STR2
4235 "Send Community attribute to this neighbor\n"
4236 "Send Standard and Extended Community attributes\n"
4237 "Send Standard, Large and Extended Community attributes\n"
4238 "Send Extended Community attributes\n"
4239 "Send Standard Community attributes\n"
4240 "Send Large Community attributes\n")
4241 {
4242 int idx_peer = 1;
4243 uint32_t flag = 0;
4244 const char *type = argv[argc - 1]->text;
4245
4246 if (strmatch(type, "standard")) {
4247 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4248 } else if (strmatch(type, "extended")) {
4249 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4250 } else if (strmatch(type, "large")) {
4251 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4252 } else if (strmatch(type, "both")) {
4253 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4254 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4255 } else { /* if (strmatch(type, "all")) */
4256 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4257 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4258 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4259 }
4260
4261 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4262 bgp_node_safi(vty), flag);
4263 }
4264
4265 ALIAS_HIDDEN(
4266 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4267 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4268 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4269 "Send Community attribute to this neighbor\n"
4270 "Send Standard and Extended Community attributes\n"
4271 "Send Standard, Large and Extended Community attributes\n"
4272 "Send Extended Community attributes\n"
4273 "Send Standard Community attributes\n"
4274 "Send Large Community attributes\n")
4275
4276 DEFUN (no_neighbor_send_community_type,
4277 no_neighbor_send_community_type_cmd,
4278 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4279 NO_STR
4280 NEIGHBOR_STR
4281 NEIGHBOR_ADDR_STR2
4282 "Send Community attribute to this neighbor\n"
4283 "Send Standard and Extended Community attributes\n"
4284 "Send Standard, Large and Extended Community attributes\n"
4285 "Send Extended Community attributes\n"
4286 "Send Standard Community attributes\n"
4287 "Send Large Community attributes\n")
4288 {
4289 int idx_peer = 2;
4290 uint32_t flag = 0;
4291 const char *type = argv[argc - 1]->text;
4292
4293 if (strmatch(type, "standard")) {
4294 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4295 } else if (strmatch(type, "extended")) {
4296 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4297 } else if (strmatch(type, "large")) {
4298 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4299 } else if (strmatch(type, "both")) {
4300 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4301 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4302 } else { /* if (strmatch(type, "all")) */
4303 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4304 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4305 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4306 }
4307
4308 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4309 bgp_node_afi(vty), bgp_node_safi(vty),
4310 flag);
4311 }
4312
4313 ALIAS_HIDDEN(
4314 no_neighbor_send_community_type,
4315 no_neighbor_send_community_type_hidden_cmd,
4316 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4317 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4318 "Send Community attribute to this neighbor\n"
4319 "Send Standard and Extended Community attributes\n"
4320 "Send Standard, Large and Extended Community attributes\n"
4321 "Send Extended Community attributes\n"
4322 "Send Standard Community attributes\n"
4323 "Send Large Community attributes\n")
4324
4325 /* neighbor soft-reconfig. */
4326 DEFUN (neighbor_soft_reconfiguration,
4327 neighbor_soft_reconfiguration_cmd,
4328 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4329 NEIGHBOR_STR
4330 NEIGHBOR_ADDR_STR2
4331 "Per neighbor soft reconfiguration\n"
4332 "Allow inbound soft reconfiguration for this neighbor\n")
4333 {
4334 int idx_peer = 1;
4335 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4336 bgp_node_safi(vty),
4337 PEER_FLAG_SOFT_RECONFIG);
4338 }
4339
4340 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4341 neighbor_soft_reconfiguration_hidden_cmd,
4342 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4344 "Per neighbor soft reconfiguration\n"
4345 "Allow inbound soft reconfiguration for this neighbor\n")
4346
4347 DEFUN (no_neighbor_soft_reconfiguration,
4348 no_neighbor_soft_reconfiguration_cmd,
4349 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4350 NO_STR
4351 NEIGHBOR_STR
4352 NEIGHBOR_ADDR_STR2
4353 "Per neighbor soft reconfiguration\n"
4354 "Allow inbound soft reconfiguration for this neighbor\n")
4355 {
4356 int idx_peer = 2;
4357 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4358 bgp_node_afi(vty), bgp_node_safi(vty),
4359 PEER_FLAG_SOFT_RECONFIG);
4360 }
4361
4362 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4363 no_neighbor_soft_reconfiguration_hidden_cmd,
4364 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4365 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4366 "Per neighbor soft reconfiguration\n"
4367 "Allow inbound soft reconfiguration for this neighbor\n")
4368
4369 DEFUN (neighbor_route_reflector_client,
4370 neighbor_route_reflector_client_cmd,
4371 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4372 NEIGHBOR_STR
4373 NEIGHBOR_ADDR_STR2
4374 "Configure a neighbor as Route Reflector client\n")
4375 {
4376 int idx_peer = 1;
4377 struct peer *peer;
4378
4379
4380 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4381 if (!peer)
4382 return CMD_WARNING_CONFIG_FAILED;
4383
4384 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4385 bgp_node_safi(vty),
4386 PEER_FLAG_REFLECTOR_CLIENT);
4387 }
4388
4389 ALIAS_HIDDEN(neighbor_route_reflector_client,
4390 neighbor_route_reflector_client_hidden_cmd,
4391 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4392 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4393 "Configure a neighbor as Route Reflector client\n")
4394
4395 DEFUN (no_neighbor_route_reflector_client,
4396 no_neighbor_route_reflector_client_cmd,
4397 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4398 NO_STR
4399 NEIGHBOR_STR
4400 NEIGHBOR_ADDR_STR2
4401 "Configure a neighbor as Route Reflector client\n")
4402 {
4403 int idx_peer = 2;
4404 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4405 bgp_node_afi(vty), bgp_node_safi(vty),
4406 PEER_FLAG_REFLECTOR_CLIENT);
4407 }
4408
4409 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4410 no_neighbor_route_reflector_client_hidden_cmd,
4411 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4412 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4413 "Configure a neighbor as Route Reflector client\n")
4414
4415 /* neighbor route-server-client. */
4416 DEFUN (neighbor_route_server_client,
4417 neighbor_route_server_client_cmd,
4418 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4419 NEIGHBOR_STR
4420 NEIGHBOR_ADDR_STR2
4421 "Configure a neighbor as Route Server client\n")
4422 {
4423 int idx_peer = 1;
4424 struct peer *peer;
4425
4426 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4427 if (!peer)
4428 return CMD_WARNING_CONFIG_FAILED;
4429 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4430 bgp_node_safi(vty),
4431 PEER_FLAG_RSERVER_CLIENT);
4432 }
4433
4434 ALIAS_HIDDEN(neighbor_route_server_client,
4435 neighbor_route_server_client_hidden_cmd,
4436 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4437 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4438 "Configure a neighbor as Route Server client\n")
4439
4440 DEFUN (no_neighbor_route_server_client,
4441 no_neighbor_route_server_client_cmd,
4442 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4443 NO_STR
4444 NEIGHBOR_STR
4445 NEIGHBOR_ADDR_STR2
4446 "Configure a neighbor as Route Server client\n")
4447 {
4448 int idx_peer = 2;
4449 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4450 bgp_node_afi(vty), bgp_node_safi(vty),
4451 PEER_FLAG_RSERVER_CLIENT);
4452 }
4453
4454 ALIAS_HIDDEN(no_neighbor_route_server_client,
4455 no_neighbor_route_server_client_hidden_cmd,
4456 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4457 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4458 "Configure a neighbor as Route Server client\n")
4459
4460 DEFUN (neighbor_nexthop_local_unchanged,
4461 neighbor_nexthop_local_unchanged_cmd,
4462 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4463 NEIGHBOR_STR
4464 NEIGHBOR_ADDR_STR2
4465 "Configure treatment of outgoing link-local nexthop attribute\n"
4466 "Leave link-local nexthop unchanged for this peer\n")
4467 {
4468 int idx_peer = 1;
4469 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4470 bgp_node_safi(vty),
4471 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4472 }
4473
4474 DEFUN (no_neighbor_nexthop_local_unchanged,
4475 no_neighbor_nexthop_local_unchanged_cmd,
4476 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4477 NO_STR
4478 NEIGHBOR_STR
4479 NEIGHBOR_ADDR_STR2
4480 "Configure treatment of outgoing link-local-nexthop attribute\n"
4481 "Leave link-local nexthop unchanged for this peer\n")
4482 {
4483 int idx_peer = 2;
4484 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4485 bgp_node_afi(vty), bgp_node_safi(vty),
4486 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4487 }
4488
4489 DEFUN (neighbor_attr_unchanged,
4490 neighbor_attr_unchanged_cmd,
4491 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4492 NEIGHBOR_STR
4493 NEIGHBOR_ADDR_STR2
4494 "BGP attribute is propagated unchanged to this neighbor\n"
4495 "As-path attribute\n"
4496 "Nexthop attribute\n"
4497 "Med attribute\n")
4498 {
4499 int idx = 0;
4500 char *peer_str = argv[1]->arg;
4501 struct peer *peer;
4502 uint16_t flags = 0;
4503 afi_t afi = bgp_node_afi(vty);
4504 safi_t safi = bgp_node_safi(vty);
4505
4506 peer = peer_and_group_lookup_vty(vty, peer_str);
4507 if (!peer)
4508 return CMD_WARNING_CONFIG_FAILED;
4509
4510 if (argv_find(argv, argc, "as-path", &idx))
4511 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4512 idx = 0;
4513 if (argv_find(argv, argc, "next-hop", &idx))
4514 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4515 idx = 0;
4516 if (argv_find(argv, argc, "med", &idx))
4517 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4518
4519 /* no flags means all of them! */
4520 if (!flags) {
4521 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4522 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4523 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4524 } else {
4525 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4526 && peer_af_flag_check(peer, afi, safi,
4527 PEER_FLAG_AS_PATH_UNCHANGED)) {
4528 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4529 PEER_FLAG_AS_PATH_UNCHANGED);
4530 }
4531
4532 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4533 && peer_af_flag_check(peer, afi, safi,
4534 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4535 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4536 PEER_FLAG_NEXTHOP_UNCHANGED);
4537 }
4538
4539 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4540 && peer_af_flag_check(peer, afi, safi,
4541 PEER_FLAG_MED_UNCHANGED)) {
4542 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4543 PEER_FLAG_MED_UNCHANGED);
4544 }
4545 }
4546
4547 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4548 }
4549
4550 ALIAS_HIDDEN(
4551 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4552 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4553 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4554 "BGP attribute is propagated unchanged to this neighbor\n"
4555 "As-path attribute\n"
4556 "Nexthop attribute\n"
4557 "Med attribute\n")
4558
4559 DEFUN (no_neighbor_attr_unchanged,
4560 no_neighbor_attr_unchanged_cmd,
4561 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4562 NO_STR
4563 NEIGHBOR_STR
4564 NEIGHBOR_ADDR_STR2
4565 "BGP attribute is propagated unchanged to this neighbor\n"
4566 "As-path attribute\n"
4567 "Nexthop attribute\n"
4568 "Med attribute\n")
4569 {
4570 int idx = 0;
4571 char *peer = argv[2]->arg;
4572 uint16_t flags = 0;
4573
4574 if (argv_find(argv, argc, "as-path", &idx))
4575 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4576 idx = 0;
4577 if (argv_find(argv, argc, "next-hop", &idx))
4578 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4579 idx = 0;
4580 if (argv_find(argv, argc, "med", &idx))
4581 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4582
4583 if (!flags) // no flags means all of them!
4584 {
4585 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4586 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4587 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4588 }
4589
4590 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4591 bgp_node_safi(vty), flags);
4592 }
4593
4594 ALIAS_HIDDEN(
4595 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4596 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4597 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4598 "BGP attribute is propagated unchanged to this neighbor\n"
4599 "As-path attribute\n"
4600 "Nexthop attribute\n"
4601 "Med attribute\n")
4602
4603 /* EBGP multihop configuration. */
4604 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4605 const char *ttl_str)
4606 {
4607 struct peer *peer;
4608 unsigned int ttl;
4609
4610 peer = peer_and_group_lookup_vty(vty, ip_str);
4611 if (!peer)
4612 return CMD_WARNING_CONFIG_FAILED;
4613
4614 if (peer->conf_if)
4615 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4616
4617 if (!ttl_str)
4618 ttl = MAXTTL;
4619 else
4620 ttl = strtoul(ttl_str, NULL, 10);
4621
4622 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4623 }
4624
4625 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4626 {
4627 struct peer *peer;
4628
4629 peer = peer_and_group_lookup_vty(vty, ip_str);
4630 if (!peer)
4631 return CMD_WARNING_CONFIG_FAILED;
4632
4633 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4634 }
4635
4636 /* neighbor ebgp-multihop. */
4637 DEFUN (neighbor_ebgp_multihop,
4638 neighbor_ebgp_multihop_cmd,
4639 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4640 NEIGHBOR_STR
4641 NEIGHBOR_ADDR_STR2
4642 "Allow EBGP neighbors not on directly connected networks\n")
4643 {
4644 int idx_peer = 1;
4645 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4646 }
4647
4648 DEFUN (neighbor_ebgp_multihop_ttl,
4649 neighbor_ebgp_multihop_ttl_cmd,
4650 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4651 NEIGHBOR_STR
4652 NEIGHBOR_ADDR_STR2
4653 "Allow EBGP neighbors not on directly connected networks\n"
4654 "maximum hop count\n")
4655 {
4656 int idx_peer = 1;
4657 int idx_number = 3;
4658 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4659 argv[idx_number]->arg);
4660 }
4661
4662 DEFUN (no_neighbor_ebgp_multihop,
4663 no_neighbor_ebgp_multihop_cmd,
4664 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4665 NO_STR
4666 NEIGHBOR_STR
4667 NEIGHBOR_ADDR_STR2
4668 "Allow EBGP neighbors not on directly connected networks\n"
4669 "maximum hop count\n")
4670 {
4671 int idx_peer = 2;
4672 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4673 }
4674
4675
4676 /* disable-connected-check */
4677 DEFUN (neighbor_disable_connected_check,
4678 neighbor_disable_connected_check_cmd,
4679 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "one-hop away EBGP peer using loopback address\n"
4683 "Enforce EBGP neighbors perform multihop\n")
4684 {
4685 int idx_peer = 1;
4686 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4687 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4688 }
4689
4690 DEFUN (no_neighbor_disable_connected_check,
4691 no_neighbor_disable_connected_check_cmd,
4692 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4693 NO_STR
4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "one-hop away EBGP peer using loopback address\n"
4697 "Enforce EBGP neighbors perform multihop\n")
4698 {
4699 int idx_peer = 2;
4700 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4701 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4702 }
4703
4704
4705 /* enforce-first-as */
4706 DEFUN (neighbor_enforce_first_as,
4707 neighbor_enforce_first_as_cmd,
4708 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "Enforce the first AS for EBGP routes\n")
4712 {
4713 int idx_peer = 1;
4714
4715 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4716 PEER_FLAG_ENFORCE_FIRST_AS);
4717 }
4718
4719 DEFUN (no_neighbor_enforce_first_as,
4720 no_neighbor_enforce_first_as_cmd,
4721 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4722 NO_STR
4723 NEIGHBOR_STR
4724 NEIGHBOR_ADDR_STR2
4725 "Enforce the first AS for EBGP routes\n")
4726 {
4727 int idx_peer = 2;
4728
4729 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4730 PEER_FLAG_ENFORCE_FIRST_AS);
4731 }
4732
4733
4734 DEFUN (neighbor_description,
4735 neighbor_description_cmd,
4736 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4737 NEIGHBOR_STR
4738 NEIGHBOR_ADDR_STR2
4739 "Neighbor specific description\n"
4740 "Up to 80 characters describing this neighbor\n")
4741 {
4742 int idx_peer = 1;
4743 int idx_line = 3;
4744 struct peer *peer;
4745 char *str;
4746
4747 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4748 if (!peer)
4749 return CMD_WARNING_CONFIG_FAILED;
4750
4751 str = argv_concat(argv, argc, idx_line);
4752
4753 peer_description_set(peer, str);
4754
4755 XFREE(MTYPE_TMP, str);
4756
4757 return CMD_SUCCESS;
4758 }
4759
4760 DEFUN (no_neighbor_description,
4761 no_neighbor_description_cmd,
4762 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4763 NO_STR
4764 NEIGHBOR_STR
4765 NEIGHBOR_ADDR_STR2
4766 "Neighbor specific description\n")
4767 {
4768 int idx_peer = 2;
4769 struct peer *peer;
4770
4771 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4772 if (!peer)
4773 return CMD_WARNING_CONFIG_FAILED;
4774
4775 peer_description_unset(peer);
4776
4777 return CMD_SUCCESS;
4778 }
4779
4780 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4781 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4782 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4783 "Neighbor specific description\n"
4784 "Up to 80 characters describing this neighbor\n")
4785
4786 /* Neighbor update-source. */
4787 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4788 const char *source_str)
4789 {
4790 struct peer *peer;
4791 struct prefix p;
4792 union sockunion su;
4793
4794 peer = peer_and_group_lookup_vty(vty, peer_str);
4795 if (!peer)
4796 return CMD_WARNING_CONFIG_FAILED;
4797
4798 if (peer->conf_if)
4799 return CMD_WARNING;
4800
4801 if (source_str) {
4802 if (str2sockunion(source_str, &su) == 0)
4803 peer_update_source_addr_set(peer, &su);
4804 else {
4805 if (str2prefix(source_str, &p)) {
4806 vty_out(vty,
4807 "%% Invalid update-source, remove prefix length \n");
4808 return CMD_WARNING_CONFIG_FAILED;
4809 } else
4810 peer_update_source_if_set(peer, source_str);
4811 }
4812 } else
4813 peer_update_source_unset(peer);
4814
4815 return CMD_SUCCESS;
4816 }
4817
4818 #define BGP_UPDATE_SOURCE_HELP_STR \
4819 "IPv4 address\n" \
4820 "IPv6 address\n" \
4821 "Interface name (requires zebra to be running)\n"
4822
4823 DEFUN (neighbor_update_source,
4824 neighbor_update_source_cmd,
4825 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4826 NEIGHBOR_STR
4827 NEIGHBOR_ADDR_STR2
4828 "Source of routing updates\n"
4829 BGP_UPDATE_SOURCE_HELP_STR)
4830 {
4831 int idx_peer = 1;
4832 int idx_peer_2 = 3;
4833 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4834 argv[idx_peer_2]->arg);
4835 }
4836
4837 DEFUN (no_neighbor_update_source,
4838 no_neighbor_update_source_cmd,
4839 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4840 NO_STR
4841 NEIGHBOR_STR
4842 NEIGHBOR_ADDR_STR2
4843 "Source of routing updates\n"
4844 BGP_UPDATE_SOURCE_HELP_STR)
4845 {
4846 int idx_peer = 2;
4847 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4848 }
4849
4850 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4851 afi_t afi, safi_t safi,
4852 const char *rmap, int set)
4853 {
4854 int ret;
4855 struct peer *peer;
4856 struct route_map *route_map;
4857
4858 peer = peer_and_group_lookup_vty(vty, peer_str);
4859 if (!peer)
4860 return CMD_WARNING_CONFIG_FAILED;
4861
4862 if (set) {
4863 route_map = route_map_lookup_warn_noexist(vty, rmap);
4864 ret = peer_default_originate_set(peer, afi, safi,
4865 rmap, route_map);
4866 } else
4867 ret = peer_default_originate_unset(peer, afi, safi);
4868
4869 return bgp_vty_return(vty, ret);
4870 }
4871
4872 /* neighbor default-originate. */
4873 DEFUN (neighbor_default_originate,
4874 neighbor_default_originate_cmd,
4875 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4876 NEIGHBOR_STR
4877 NEIGHBOR_ADDR_STR2
4878 "Originate default route to this neighbor\n")
4879 {
4880 int idx_peer = 1;
4881 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4882 bgp_node_afi(vty),
4883 bgp_node_safi(vty), NULL, 1);
4884 }
4885
4886 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4887 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4888 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4889 "Originate default route to this neighbor\n")
4890
4891 DEFUN (neighbor_default_originate_rmap,
4892 neighbor_default_originate_rmap_cmd,
4893 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4894 NEIGHBOR_STR
4895 NEIGHBOR_ADDR_STR2
4896 "Originate default route to this neighbor\n"
4897 "Route-map to specify criteria to originate default\n"
4898 "route-map name\n")
4899 {
4900 int idx_peer = 1;
4901 int idx_word = 4;
4902 return peer_default_originate_set_vty(
4903 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4904 argv[idx_word]->arg, 1);
4905 }
4906
4907 ALIAS_HIDDEN(
4908 neighbor_default_originate_rmap,
4909 neighbor_default_originate_rmap_hidden_cmd,
4910 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4911 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4912 "Originate default route to this neighbor\n"
4913 "Route-map to specify criteria to originate default\n"
4914 "route-map name\n")
4915
4916 DEFUN (no_neighbor_default_originate,
4917 no_neighbor_default_originate_cmd,
4918 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4919 NO_STR
4920 NEIGHBOR_STR
4921 NEIGHBOR_ADDR_STR2
4922 "Originate default route to this neighbor\n"
4923 "Route-map to specify criteria to originate default\n"
4924 "route-map name\n")
4925 {
4926 int idx_peer = 2;
4927 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4928 bgp_node_afi(vty),
4929 bgp_node_safi(vty), NULL, 0);
4930 }
4931
4932 ALIAS_HIDDEN(
4933 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4934 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4935 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4936 "Originate default route to this neighbor\n"
4937 "Route-map to specify criteria to originate default\n"
4938 "route-map name\n")
4939
4940
4941 /* Set neighbor's BGP port. */
4942 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4943 const char *port_str)
4944 {
4945 struct peer *peer;
4946 uint16_t port;
4947 struct servent *sp;
4948
4949 peer = peer_lookup_vty(vty, ip_str);
4950 if (!peer)
4951 return CMD_WARNING_CONFIG_FAILED;
4952
4953 if (!port_str) {
4954 sp = getservbyname("bgp", "tcp");
4955 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4956 } else {
4957 port = strtoul(port_str, NULL, 10);
4958 }
4959
4960 peer_port_set(peer, port);
4961
4962 return CMD_SUCCESS;
4963 }
4964
4965 /* Set specified peer's BGP port. */
4966 DEFUN (neighbor_port,
4967 neighbor_port_cmd,
4968 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4969 NEIGHBOR_STR
4970 NEIGHBOR_ADDR_STR
4971 "Neighbor's BGP port\n"
4972 "TCP port number\n")
4973 {
4974 int idx_ip = 1;
4975 int idx_number = 3;
4976 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4977 argv[idx_number]->arg);
4978 }
4979
4980 DEFUN (no_neighbor_port,
4981 no_neighbor_port_cmd,
4982 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4983 NO_STR
4984 NEIGHBOR_STR
4985 NEIGHBOR_ADDR_STR
4986 "Neighbor's BGP port\n"
4987 "TCP port number\n")
4988 {
4989 int idx_ip = 2;
4990 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4991 }
4992
4993
4994 /* neighbor weight. */
4995 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4996 safi_t safi, const char *weight_str)
4997 {
4998 int ret;
4999 struct peer *peer;
5000 unsigned long weight;
5001
5002 peer = peer_and_group_lookup_vty(vty, ip_str);
5003 if (!peer)
5004 return CMD_WARNING_CONFIG_FAILED;
5005
5006 weight = strtoul(weight_str, NULL, 10);
5007
5008 ret = peer_weight_set(peer, afi, safi, weight);
5009 return bgp_vty_return(vty, ret);
5010 }
5011
5012 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5013 safi_t safi)
5014 {
5015 int ret;
5016 struct peer *peer;
5017
5018 peer = peer_and_group_lookup_vty(vty, ip_str);
5019 if (!peer)
5020 return CMD_WARNING_CONFIG_FAILED;
5021
5022 ret = peer_weight_unset(peer, afi, safi);
5023 return bgp_vty_return(vty, ret);
5024 }
5025
5026 DEFUN (neighbor_weight,
5027 neighbor_weight_cmd,
5028 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5029 NEIGHBOR_STR
5030 NEIGHBOR_ADDR_STR2
5031 "Set default weight for routes from this neighbor\n"
5032 "default weight\n")
5033 {
5034 int idx_peer = 1;
5035 int idx_number = 3;
5036 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5037 bgp_node_safi(vty), argv[idx_number]->arg);
5038 }
5039
5040 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
5041 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5042 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5043 "Set default weight for routes from this neighbor\n"
5044 "default weight\n")
5045
5046 DEFUN (no_neighbor_weight,
5047 no_neighbor_weight_cmd,
5048 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5049 NO_STR
5050 NEIGHBOR_STR
5051 NEIGHBOR_ADDR_STR2
5052 "Set default weight for routes from this neighbor\n"
5053 "default weight\n")
5054 {
5055 int idx_peer = 2;
5056 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
5057 bgp_node_afi(vty), bgp_node_safi(vty));
5058 }
5059
5060 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
5061 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5063 "Set default weight for routes from this neighbor\n"
5064 "default weight\n")
5065
5066
5067 /* Override capability negotiation. */
5068 DEFUN (neighbor_override_capability,
5069 neighbor_override_capability_cmd,
5070 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5071 NEIGHBOR_STR
5072 NEIGHBOR_ADDR_STR2
5073 "Override capability negotiation result\n")
5074 {
5075 int idx_peer = 1;
5076 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5077 PEER_FLAG_OVERRIDE_CAPABILITY);
5078 }
5079
5080 DEFUN (no_neighbor_override_capability,
5081 no_neighbor_override_capability_cmd,
5082 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
5083 NO_STR
5084 NEIGHBOR_STR
5085 NEIGHBOR_ADDR_STR2
5086 "Override capability negotiation result\n")
5087 {
5088 int idx_peer = 2;
5089 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5090 PEER_FLAG_OVERRIDE_CAPABILITY);
5091 }
5092
5093 DEFUN (neighbor_strict_capability,
5094 neighbor_strict_capability_cmd,
5095 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5096 NEIGHBOR_STR
5097 NEIGHBOR_ADDR_STR2
5098 "Strict capability negotiation match\n")
5099 {
5100 int idx_peer = 1;
5101
5102 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5103 PEER_FLAG_STRICT_CAP_MATCH);
5104 }
5105
5106 DEFUN (no_neighbor_strict_capability,
5107 no_neighbor_strict_capability_cmd,
5108 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5109 NO_STR
5110 NEIGHBOR_STR
5111 NEIGHBOR_ADDR_STR2
5112 "Strict capability negotiation match\n")
5113 {
5114 int idx_peer = 2;
5115
5116 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5117 PEER_FLAG_STRICT_CAP_MATCH);
5118 }
5119
5120 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5121 const char *keep_str, const char *hold_str)
5122 {
5123 int ret;
5124 struct peer *peer;
5125 uint32_t keepalive;
5126 uint32_t holdtime;
5127
5128 peer = peer_and_group_lookup_vty(vty, ip_str);
5129 if (!peer)
5130 return CMD_WARNING_CONFIG_FAILED;
5131
5132 keepalive = strtoul(keep_str, NULL, 10);
5133 holdtime = strtoul(hold_str, NULL, 10);
5134
5135 ret = peer_timers_set(peer, keepalive, holdtime);
5136
5137 return bgp_vty_return(vty, ret);
5138 }
5139
5140 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5141 {
5142 int ret;
5143 struct peer *peer;
5144
5145 peer = peer_and_group_lookup_vty(vty, ip_str);
5146 if (!peer)
5147 return CMD_WARNING_CONFIG_FAILED;
5148
5149 ret = peer_timers_unset(peer);
5150
5151 return bgp_vty_return(vty, ret);
5152 }
5153
5154 DEFUN (neighbor_timers,
5155 neighbor_timers_cmd,
5156 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5157 NEIGHBOR_STR
5158 NEIGHBOR_ADDR_STR2
5159 "BGP per neighbor timers\n"
5160 "Keepalive interval\n"
5161 "Holdtime\n")
5162 {
5163 int idx_peer = 1;
5164 int idx_number = 3;
5165 int idx_number_2 = 4;
5166 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5167 argv[idx_number]->arg,
5168 argv[idx_number_2]->arg);
5169 }
5170
5171 DEFUN (no_neighbor_timers,
5172 no_neighbor_timers_cmd,
5173 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5174 NO_STR
5175 NEIGHBOR_STR
5176 NEIGHBOR_ADDR_STR2
5177 "BGP per neighbor timers\n"
5178 "Keepalive interval\n"
5179 "Holdtime\n")
5180 {
5181 int idx_peer = 2;
5182 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5183 }
5184
5185
5186 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5187 const char *time_str)
5188 {
5189 int ret;
5190 struct peer *peer;
5191 uint32_t connect;
5192
5193 peer = peer_and_group_lookup_vty(vty, ip_str);
5194 if (!peer)
5195 return CMD_WARNING_CONFIG_FAILED;
5196
5197 connect = strtoul(time_str, NULL, 10);
5198
5199 ret = peer_timers_connect_set(peer, connect);
5200
5201 return bgp_vty_return(vty, ret);
5202 }
5203
5204 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5205 {
5206 int ret;
5207 struct peer *peer;
5208
5209 peer = peer_and_group_lookup_vty(vty, ip_str);
5210 if (!peer)
5211 return CMD_WARNING_CONFIG_FAILED;
5212
5213 ret = peer_timers_connect_unset(peer);
5214
5215 return bgp_vty_return(vty, ret);
5216 }
5217
5218 DEFUN (neighbor_timers_connect,
5219 neighbor_timers_connect_cmd,
5220 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5221 NEIGHBOR_STR
5222 NEIGHBOR_ADDR_STR2
5223 "BGP per neighbor timers\n"
5224 "BGP connect timer\n"
5225 "Connect timer\n")
5226 {
5227 int idx_peer = 1;
5228 int idx_number = 4;
5229 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5230 argv[idx_number]->arg);
5231 }
5232
5233 DEFUN (no_neighbor_timers_connect,
5234 no_neighbor_timers_connect_cmd,
5235 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5236 NO_STR
5237 NEIGHBOR_STR
5238 NEIGHBOR_ADDR_STR2
5239 "BGP per neighbor timers\n"
5240 "BGP connect timer\n"
5241 "Connect timer\n")
5242 {
5243 int idx_peer = 2;
5244 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5245 }
5246
5247
5248 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5249 const char *time_str, int set)
5250 {
5251 int ret;
5252 struct peer *peer;
5253 uint32_t routeadv = 0;
5254
5255 peer = peer_and_group_lookup_vty(vty, ip_str);
5256 if (!peer)
5257 return CMD_WARNING_CONFIG_FAILED;
5258
5259 if (time_str)
5260 routeadv = strtoul(time_str, NULL, 10);
5261
5262 if (set)
5263 ret = peer_advertise_interval_set(peer, routeadv);
5264 else
5265 ret = peer_advertise_interval_unset(peer);
5266
5267 return bgp_vty_return(vty, ret);
5268 }
5269
5270 DEFUN (neighbor_advertise_interval,
5271 neighbor_advertise_interval_cmd,
5272 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5273 NEIGHBOR_STR
5274 NEIGHBOR_ADDR_STR2
5275 "Minimum interval between sending BGP routing updates\n"
5276 "time in seconds\n")
5277 {
5278 int idx_peer = 1;
5279 int idx_number = 3;
5280 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5281 argv[idx_number]->arg, 1);
5282 }
5283
5284 DEFUN (no_neighbor_advertise_interval,
5285 no_neighbor_advertise_interval_cmd,
5286 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5287 NO_STR
5288 NEIGHBOR_STR
5289 NEIGHBOR_ADDR_STR2
5290 "Minimum interval between sending BGP routing updates\n"
5291 "time in seconds\n")
5292 {
5293 int idx_peer = 2;
5294 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5295 }
5296
5297
5298 /* Time to wait before processing route-map updates */
5299 DEFUN (bgp_set_route_map_delay_timer,
5300 bgp_set_route_map_delay_timer_cmd,
5301 "bgp route-map delay-timer (0-600)",
5302 SET_STR
5303 "BGP route-map delay timer\n"
5304 "Time in secs to wait before processing route-map changes\n"
5305 "0 disables the timer, no route updates happen when route-maps change\n")
5306 {
5307 int idx_number = 3;
5308 uint32_t rmap_delay_timer;
5309
5310 if (argv[idx_number]->arg) {
5311 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5312 bm->rmap_update_timer = rmap_delay_timer;
5313
5314 /* if the dynamic update handling is being disabled, and a timer
5315 * is
5316 * running, stop the timer and act as if the timer has already
5317 * fired.
5318 */
5319 if (!rmap_delay_timer && bm->t_rmap_update) {
5320 BGP_TIMER_OFF(bm->t_rmap_update);
5321 thread_execute(bm->master, bgp_route_map_update_timer,
5322 NULL, 0);
5323 }
5324 return CMD_SUCCESS;
5325 } else {
5326 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5327 return CMD_WARNING_CONFIG_FAILED;
5328 }
5329 }
5330
5331 DEFUN (no_bgp_set_route_map_delay_timer,
5332 no_bgp_set_route_map_delay_timer_cmd,
5333 "no bgp route-map delay-timer [(0-600)]",
5334 NO_STR
5335 BGP_STR
5336 "Default BGP route-map delay timer\n"
5337 "Reset to default time to wait for processing route-map changes\n"
5338 "0 disables the timer, no route updates happen when route-maps change\n")
5339 {
5340
5341 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5342
5343 return CMD_SUCCESS;
5344 }
5345
5346
5347 /* neighbor interface */
5348 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5349 const char *str)
5350 {
5351 struct peer *peer;
5352
5353 peer = peer_lookup_vty(vty, ip_str);
5354 if (!peer || peer->conf_if) {
5355 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5356 return CMD_WARNING_CONFIG_FAILED;
5357 }
5358
5359 if (str)
5360 peer_interface_set(peer, str);
5361 else
5362 peer_interface_unset(peer);
5363
5364 return CMD_SUCCESS;
5365 }
5366
5367 DEFUN (neighbor_interface,
5368 neighbor_interface_cmd,
5369 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5370 NEIGHBOR_STR
5371 NEIGHBOR_ADDR_STR
5372 "Interface\n"
5373 "Interface name\n")
5374 {
5375 int idx_ip = 1;
5376 int idx_word = 3;
5377 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5378 }
5379
5380 DEFUN (no_neighbor_interface,
5381 no_neighbor_interface_cmd,
5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5383 NO_STR
5384 NEIGHBOR_STR
5385 NEIGHBOR_ADDR_STR2
5386 "Interface\n"
5387 "Interface name\n")
5388 {
5389 int idx_peer = 2;
5390 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5391 }
5392
5393 DEFUN (neighbor_distribute_list,
5394 neighbor_distribute_list_cmd,
5395 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5396 NEIGHBOR_STR
5397 NEIGHBOR_ADDR_STR2
5398 "Filter updates to/from this neighbor\n"
5399 "IP access-list number\n"
5400 "IP access-list number (expanded range)\n"
5401 "IP Access-list name\n"
5402 "Filter incoming updates\n"
5403 "Filter outgoing updates\n")
5404 {
5405 int idx_peer = 1;
5406 int idx_acl = 3;
5407 int direct, ret;
5408 struct peer *peer;
5409
5410 const char *pstr = argv[idx_peer]->arg;
5411 const char *acl = argv[idx_acl]->arg;
5412 const char *inout = argv[argc - 1]->text;
5413
5414 peer = peer_and_group_lookup_vty(vty, pstr);
5415 if (!peer)
5416 return CMD_WARNING_CONFIG_FAILED;
5417
5418 /* Check filter direction. */
5419 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5420 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5421 direct, acl);
5422
5423 return bgp_vty_return(vty, ret);
5424 }
5425
5426 ALIAS_HIDDEN(
5427 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5428 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5429 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5430 "Filter updates to/from this neighbor\n"
5431 "IP access-list number\n"
5432 "IP access-list number (expanded range)\n"
5433 "IP Access-list name\n"
5434 "Filter incoming updates\n"
5435 "Filter outgoing updates\n")
5436
5437 DEFUN (no_neighbor_distribute_list,
5438 no_neighbor_distribute_list_cmd,
5439 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5440 NO_STR
5441 NEIGHBOR_STR
5442 NEIGHBOR_ADDR_STR2
5443 "Filter updates to/from this neighbor\n"
5444 "IP access-list number\n"
5445 "IP access-list number (expanded range)\n"
5446 "IP Access-list name\n"
5447 "Filter incoming updates\n"
5448 "Filter outgoing updates\n")
5449 {
5450 int idx_peer = 2;
5451 int direct, ret;
5452 struct peer *peer;
5453
5454 const char *pstr = argv[idx_peer]->arg;
5455 const char *inout = argv[argc - 1]->text;
5456
5457 peer = peer_and_group_lookup_vty(vty, pstr);
5458 if (!peer)
5459 return CMD_WARNING_CONFIG_FAILED;
5460
5461 /* Check filter direction. */
5462 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5463 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5464 direct);
5465
5466 return bgp_vty_return(vty, ret);
5467 }
5468
5469 ALIAS_HIDDEN(
5470 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5471 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5472 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5473 "Filter updates to/from this neighbor\n"
5474 "IP access-list number\n"
5475 "IP access-list number (expanded range)\n"
5476 "IP Access-list name\n"
5477 "Filter incoming updates\n"
5478 "Filter outgoing updates\n")
5479
5480 /* Set prefix list to the peer. */
5481 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5482 afi_t afi, safi_t safi,
5483 const char *name_str,
5484 const char *direct_str)
5485 {
5486 int ret;
5487 int direct = FILTER_IN;
5488 struct peer *peer;
5489
5490 peer = peer_and_group_lookup_vty(vty, ip_str);
5491 if (!peer)
5492 return CMD_WARNING_CONFIG_FAILED;
5493
5494 /* Check filter direction. */
5495 if (strncmp(direct_str, "i", 1) == 0)
5496 direct = FILTER_IN;
5497 else if (strncmp(direct_str, "o", 1) == 0)
5498 direct = FILTER_OUT;
5499
5500 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5501
5502 return bgp_vty_return(vty, ret);
5503 }
5504
5505 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5506 afi_t afi, safi_t safi,
5507 const char *direct_str)
5508 {
5509 int ret;
5510 struct peer *peer;
5511 int direct = FILTER_IN;
5512
5513 peer = peer_and_group_lookup_vty(vty, ip_str);
5514 if (!peer)
5515 return CMD_WARNING_CONFIG_FAILED;
5516
5517 /* Check filter direction. */
5518 if (strncmp(direct_str, "i", 1) == 0)
5519 direct = FILTER_IN;
5520 else if (strncmp(direct_str, "o", 1) == 0)
5521 direct = FILTER_OUT;
5522
5523 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5524
5525 return bgp_vty_return(vty, ret);
5526 }
5527
5528 DEFUN (neighbor_prefix_list,
5529 neighbor_prefix_list_cmd,
5530 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Filter updates to/from this neighbor\n"
5534 "Name of a prefix list\n"
5535 "Filter incoming updates\n"
5536 "Filter outgoing updates\n")
5537 {
5538 int idx_peer = 1;
5539 int idx_word = 3;
5540 int idx_in_out = 4;
5541 return peer_prefix_list_set_vty(
5542 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5543 argv[idx_word]->arg, argv[idx_in_out]->arg);
5544 }
5545
5546 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5547 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5549 "Filter updates to/from this neighbor\n"
5550 "Name of a prefix list\n"
5551 "Filter incoming updates\n"
5552 "Filter outgoing updates\n")
5553
5554 DEFUN (no_neighbor_prefix_list,
5555 no_neighbor_prefix_list_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5557 NO_STR
5558 NEIGHBOR_STR
5559 NEIGHBOR_ADDR_STR2
5560 "Filter updates to/from this neighbor\n"
5561 "Name of a prefix list\n"
5562 "Filter incoming updates\n"
5563 "Filter outgoing updates\n")
5564 {
5565 int idx_peer = 2;
5566 int idx_in_out = 5;
5567 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5568 bgp_node_afi(vty), bgp_node_safi(vty),
5569 argv[idx_in_out]->arg);
5570 }
5571
5572 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5573 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5574 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5575 "Filter updates to/from this neighbor\n"
5576 "Name of a prefix list\n"
5577 "Filter incoming updates\n"
5578 "Filter outgoing updates\n")
5579
5580 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5581 safi_t safi, const char *name_str,
5582 const char *direct_str)
5583 {
5584 int ret;
5585 struct peer *peer;
5586 int direct = FILTER_IN;
5587
5588 peer = peer_and_group_lookup_vty(vty, ip_str);
5589 if (!peer)
5590 return CMD_WARNING_CONFIG_FAILED;
5591
5592 /* Check filter direction. */
5593 if (strncmp(direct_str, "i", 1) == 0)
5594 direct = FILTER_IN;
5595 else if (strncmp(direct_str, "o", 1) == 0)
5596 direct = FILTER_OUT;
5597
5598 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5599
5600 return bgp_vty_return(vty, ret);
5601 }
5602
5603 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5604 safi_t safi, const char *direct_str)
5605 {
5606 int ret;
5607 struct peer *peer;
5608 int direct = FILTER_IN;
5609
5610 peer = peer_and_group_lookup_vty(vty, ip_str);
5611 if (!peer)
5612 return CMD_WARNING_CONFIG_FAILED;
5613
5614 /* Check filter direction. */
5615 if (strncmp(direct_str, "i", 1) == 0)
5616 direct = FILTER_IN;
5617 else if (strncmp(direct_str, "o", 1) == 0)
5618 direct = FILTER_OUT;
5619
5620 ret = peer_aslist_unset(peer, afi, safi, direct);
5621
5622 return bgp_vty_return(vty, ret);
5623 }
5624
5625 DEFUN (neighbor_filter_list,
5626 neighbor_filter_list_cmd,
5627 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5628 NEIGHBOR_STR
5629 NEIGHBOR_ADDR_STR2
5630 "Establish BGP filters\n"
5631 "AS path access-list name\n"
5632 "Filter incoming routes\n"
5633 "Filter outgoing routes\n")
5634 {
5635 int idx_peer = 1;
5636 int idx_word = 3;
5637 int idx_in_out = 4;
5638 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5639 bgp_node_safi(vty), argv[idx_word]->arg,
5640 argv[idx_in_out]->arg);
5641 }
5642
5643 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5644 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5645 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5646 "Establish BGP filters\n"
5647 "AS path access-list name\n"
5648 "Filter incoming routes\n"
5649 "Filter outgoing routes\n")
5650
5651 DEFUN (no_neighbor_filter_list,
5652 no_neighbor_filter_list_cmd,
5653 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5654 NO_STR
5655 NEIGHBOR_STR
5656 NEIGHBOR_ADDR_STR2
5657 "Establish BGP filters\n"
5658 "AS path access-list name\n"
5659 "Filter incoming routes\n"
5660 "Filter outgoing routes\n")
5661 {
5662 int idx_peer = 2;
5663 int idx_in_out = 5;
5664 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5665 bgp_node_afi(vty), bgp_node_safi(vty),
5666 argv[idx_in_out]->arg);
5667 }
5668
5669 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5670 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5671 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5672 "Establish BGP filters\n"
5673 "AS path access-list name\n"
5674 "Filter incoming routes\n"
5675 "Filter outgoing routes\n")
5676
5677 /* Set route-map to the peer. */
5678 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5679 afi_t afi, safi_t safi, const char *name_str,
5680 const char *direct_str)
5681 {
5682 int ret;
5683 struct peer *peer;
5684 int direct = RMAP_IN;
5685 struct route_map *route_map;
5686
5687 peer = peer_and_group_lookup_vty(vty, ip_str);
5688 if (!peer)
5689 return CMD_WARNING_CONFIG_FAILED;
5690
5691 /* Check filter direction. */
5692 if (strncmp(direct_str, "in", 2) == 0)
5693 direct = RMAP_IN;
5694 else if (strncmp(direct_str, "o", 1) == 0)
5695 direct = RMAP_OUT;
5696
5697 route_map = route_map_lookup_warn_noexist(vty, name_str);
5698 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5699
5700 return bgp_vty_return(vty, ret);
5701 }
5702
5703 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5704 afi_t afi, safi_t safi,
5705 const char *direct_str)
5706 {
5707 int ret;
5708 struct peer *peer;
5709 int direct = RMAP_IN;
5710
5711 peer = peer_and_group_lookup_vty(vty, ip_str);
5712 if (!peer)
5713 return CMD_WARNING_CONFIG_FAILED;
5714
5715 /* Check filter direction. */
5716 if (strncmp(direct_str, "in", 2) == 0)
5717 direct = RMAP_IN;
5718 else if (strncmp(direct_str, "o", 1) == 0)
5719 direct = RMAP_OUT;
5720
5721 ret = peer_route_map_unset(peer, afi, safi, direct);
5722
5723 return bgp_vty_return(vty, ret);
5724 }
5725
5726 DEFUN (neighbor_route_map,
5727 neighbor_route_map_cmd,
5728 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5729 NEIGHBOR_STR
5730 NEIGHBOR_ADDR_STR2
5731 "Apply route map to neighbor\n"
5732 "Name of route map\n"
5733 "Apply map to incoming routes\n"
5734 "Apply map to outbound routes\n")
5735 {
5736 int idx_peer = 1;
5737 int idx_word = 3;
5738 int idx_in_out = 4;
5739 return peer_route_map_set_vty(
5740 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5741 argv[idx_word]->arg, argv[idx_in_out]->arg);
5742 }
5743
5744 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5745 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5746 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Apply route map to neighbor\n"
5748 "Name of route map\n"
5749 "Apply map to incoming routes\n"
5750 "Apply map to outbound routes\n")
5751
5752 DEFUN (no_neighbor_route_map,
5753 no_neighbor_route_map_cmd,
5754 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5755 NO_STR
5756 NEIGHBOR_STR
5757 NEIGHBOR_ADDR_STR2
5758 "Apply route map to neighbor\n"
5759 "Name of route map\n"
5760 "Apply map to incoming routes\n"
5761 "Apply map to outbound routes\n")
5762 {
5763 int idx_peer = 2;
5764 int idx_in_out = 5;
5765 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5766 bgp_node_afi(vty), bgp_node_safi(vty),
5767 argv[idx_in_out]->arg);
5768 }
5769
5770 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5771 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5772 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5773 "Apply route map to neighbor\n"
5774 "Name of route map\n"
5775 "Apply map to incoming routes\n"
5776 "Apply map to outbound routes\n")
5777
5778 /* Set unsuppress-map to the peer. */
5779 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5780 afi_t afi, safi_t safi,
5781 const char *name_str)
5782 {
5783 int ret;
5784 struct peer *peer;
5785 struct route_map *route_map;
5786
5787 peer = peer_and_group_lookup_vty(vty, ip_str);
5788 if (!peer)
5789 return CMD_WARNING_CONFIG_FAILED;
5790
5791 route_map = route_map_lookup_warn_noexist(vty, name_str);
5792 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5793
5794 return bgp_vty_return(vty, ret);
5795 }
5796
5797 /* Unset route-map from the peer. */
5798 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5799 afi_t afi, safi_t safi)
5800 {
5801 int ret;
5802 struct peer *peer;
5803
5804 peer = peer_and_group_lookup_vty(vty, ip_str);
5805 if (!peer)
5806 return CMD_WARNING_CONFIG_FAILED;
5807
5808 ret = peer_unsuppress_map_unset(peer, afi, safi);
5809
5810 return bgp_vty_return(vty, ret);
5811 }
5812
5813 DEFUN (neighbor_unsuppress_map,
5814 neighbor_unsuppress_map_cmd,
5815 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
5818 "Route-map to selectively unsuppress suppressed routes\n"
5819 "Name of route map\n")
5820 {
5821 int idx_peer = 1;
5822 int idx_word = 3;
5823 return peer_unsuppress_map_set_vty(
5824 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5825 argv[idx_word]->arg);
5826 }
5827
5828 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Route-map to selectively unsuppress suppressed routes\n"
5832 "Name of route map\n")
5833
5834 DEFUN (no_neighbor_unsuppress_map,
5835 no_neighbor_unsuppress_map_cmd,
5836 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5837 NO_STR
5838 NEIGHBOR_STR
5839 NEIGHBOR_ADDR_STR2
5840 "Route-map to selectively unsuppress suppressed routes\n"
5841 "Name of route map\n")
5842 {
5843 int idx_peer = 2;
5844 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5845 bgp_node_afi(vty),
5846 bgp_node_safi(vty));
5847 }
5848
5849 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5850 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5851 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5852 "Route-map to selectively unsuppress suppressed routes\n"
5853 "Name of route map\n")
5854
5855 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5856 afi_t afi, safi_t safi,
5857 const char *num_str,
5858 const char *threshold_str, int warning,
5859 const char *restart_str)
5860 {
5861 int ret;
5862 struct peer *peer;
5863 uint32_t max;
5864 uint8_t threshold;
5865 uint16_t restart;
5866
5867 peer = peer_and_group_lookup_vty(vty, ip_str);
5868 if (!peer)
5869 return CMD_WARNING_CONFIG_FAILED;
5870
5871 max = strtoul(num_str, NULL, 10);
5872 if (threshold_str)
5873 threshold = atoi(threshold_str);
5874 else
5875 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5876
5877 if (restart_str)
5878 restart = atoi(restart_str);
5879 else
5880 restart = 0;
5881
5882 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5883 restart);
5884
5885 return bgp_vty_return(vty, ret);
5886 }
5887
5888 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5889 afi_t afi, safi_t safi)
5890 {
5891 int ret;
5892 struct peer *peer;
5893
5894 peer = peer_and_group_lookup_vty(vty, ip_str);
5895 if (!peer)
5896 return CMD_WARNING_CONFIG_FAILED;
5897
5898 ret = peer_maximum_prefix_unset(peer, afi, safi);
5899
5900 return bgp_vty_return(vty, ret);
5901 }
5902
5903 /* Maximum number of prefix configuration. prefix count is different
5904 for each peer configuration. So this configuration can be set for
5905 each peer configuration. */
5906 DEFUN (neighbor_maximum_prefix,
5907 neighbor_maximum_prefix_cmd,
5908 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5909 NEIGHBOR_STR
5910 NEIGHBOR_ADDR_STR2
5911 "Maximum number of prefix accept from this peer\n"
5912 "maximum no. of prefix limit\n")
5913 {
5914 int idx_peer = 1;
5915 int idx_number = 3;
5916 return peer_maximum_prefix_set_vty(
5917 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5918 argv[idx_number]->arg, NULL, 0, NULL);
5919 }
5920
5921 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5922 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5923 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5924 "Maximum number of prefix accept from this peer\n"
5925 "maximum no. of prefix limit\n")
5926
5927 DEFUN (neighbor_maximum_prefix_threshold,
5928 neighbor_maximum_prefix_threshold_cmd,
5929 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5930 NEIGHBOR_STR
5931 NEIGHBOR_ADDR_STR2
5932 "Maximum number of prefix accept from this peer\n"
5933 "maximum no. of prefix limit\n"
5934 "Threshold value (%) at which to generate a warning msg\n")
5935 {
5936 int idx_peer = 1;
5937 int idx_number = 3;
5938 int idx_number_2 = 4;
5939 return peer_maximum_prefix_set_vty(
5940 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5941 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5942 }
5943
5944 ALIAS_HIDDEN(
5945 neighbor_maximum_prefix_threshold,
5946 neighbor_maximum_prefix_threshold_hidden_cmd,
5947 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5949 "Maximum number of prefix accept from this peer\n"
5950 "maximum no. of prefix limit\n"
5951 "Threshold value (%) at which to generate a warning msg\n")
5952
5953 DEFUN (neighbor_maximum_prefix_warning,
5954 neighbor_maximum_prefix_warning_cmd,
5955 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5956 NEIGHBOR_STR
5957 NEIGHBOR_ADDR_STR2
5958 "Maximum number of prefix accept from this peer\n"
5959 "maximum no. of prefix limit\n"
5960 "Only give warning message when limit is exceeded\n")
5961 {
5962 int idx_peer = 1;
5963 int idx_number = 3;
5964 return peer_maximum_prefix_set_vty(
5965 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5966 argv[idx_number]->arg, NULL, 1, NULL);
5967 }
5968
5969 ALIAS_HIDDEN(
5970 neighbor_maximum_prefix_warning,
5971 neighbor_maximum_prefix_warning_hidden_cmd,
5972 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5973 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5974 "Maximum number of prefix accept from this peer\n"
5975 "maximum no. of prefix limit\n"
5976 "Only give warning message when limit is exceeded\n")
5977
5978 DEFUN (neighbor_maximum_prefix_threshold_warning,
5979 neighbor_maximum_prefix_threshold_warning_cmd,
5980 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5981 NEIGHBOR_STR
5982 NEIGHBOR_ADDR_STR2
5983 "Maximum number of prefix accept from this peer\n"
5984 "maximum no. of prefix limit\n"
5985 "Threshold value (%) at which to generate a warning msg\n"
5986 "Only give warning message when limit is exceeded\n")
5987 {
5988 int idx_peer = 1;
5989 int idx_number = 3;
5990 int idx_number_2 = 4;
5991 return peer_maximum_prefix_set_vty(
5992 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5993 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5994 }
5995
5996 ALIAS_HIDDEN(
5997 neighbor_maximum_prefix_threshold_warning,
5998 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5999 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6000 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6001 "Maximum number of prefix accept from this peer\n"
6002 "maximum no. of prefix limit\n"
6003 "Threshold value (%) at which to generate a warning msg\n"
6004 "Only give warning message when limit is exceeded\n")
6005
6006 DEFUN (neighbor_maximum_prefix_restart,
6007 neighbor_maximum_prefix_restart_cmd,
6008 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6009 NEIGHBOR_STR
6010 NEIGHBOR_ADDR_STR2
6011 "Maximum number of prefix accept from this peer\n"
6012 "maximum no. of prefix limit\n"
6013 "Restart bgp connection after limit is exceeded\n"
6014 "Restart interval in minutes\n")
6015 {
6016 int idx_peer = 1;
6017 int idx_number = 3;
6018 int idx_number_2 = 5;
6019 return peer_maximum_prefix_set_vty(
6020 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6021 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
6022 }
6023
6024 ALIAS_HIDDEN(
6025 neighbor_maximum_prefix_restart,
6026 neighbor_maximum_prefix_restart_hidden_cmd,
6027 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6028 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6029 "Maximum number of prefix accept from this peer\n"
6030 "maximum no. of prefix limit\n"
6031 "Restart bgp connection after limit is exceeded\n"
6032 "Restart interval in minutes\n")
6033
6034 DEFUN (neighbor_maximum_prefix_threshold_restart,
6035 neighbor_maximum_prefix_threshold_restart_cmd,
6036 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6037 NEIGHBOR_STR
6038 NEIGHBOR_ADDR_STR2
6039 "Maximum number of prefixes to accept from this peer\n"
6040 "maximum no. of prefix limit\n"
6041 "Threshold value (%) at which to generate a warning msg\n"
6042 "Restart bgp connection after limit is exceeded\n"
6043 "Restart interval in minutes\n")
6044 {
6045 int idx_peer = 1;
6046 int idx_number = 3;
6047 int idx_number_2 = 4;
6048 int idx_number_3 = 6;
6049 return peer_maximum_prefix_set_vty(
6050 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
6051 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
6052 argv[idx_number_3]->arg);
6053 }
6054
6055 ALIAS_HIDDEN(
6056 neighbor_maximum_prefix_threshold_restart,
6057 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6058 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6059 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6060 "Maximum number of prefixes to accept from this peer\n"
6061 "maximum no. of prefix limit\n"
6062 "Threshold value (%) at which to generate a warning msg\n"
6063 "Restart bgp connection after limit is exceeded\n"
6064 "Restart interval in minutes\n")
6065
6066 DEFUN (no_neighbor_maximum_prefix,
6067 no_neighbor_maximum_prefix_cmd,
6068 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6069 NO_STR
6070 NEIGHBOR_STR
6071 NEIGHBOR_ADDR_STR2
6072 "Maximum number of prefixes to accept from this peer\n"
6073 "maximum no. of prefix limit\n"
6074 "Threshold value (%) at which to generate a warning msg\n"
6075 "Restart bgp connection after limit is exceeded\n"
6076 "Restart interval in minutes\n"
6077 "Only give warning message when limit is exceeded\n")
6078 {
6079 int idx_peer = 2;
6080 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
6081 bgp_node_afi(vty),
6082 bgp_node_safi(vty));
6083 }
6084
6085 ALIAS_HIDDEN(
6086 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6087 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6088 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6089 "Maximum number of prefixes to accept from this peer\n"
6090 "maximum no. of prefix limit\n"
6091 "Threshold value (%) at which to generate a warning msg\n"
6092 "Restart bgp connection after limit is exceeded\n"
6093 "Restart interval in minutes\n"
6094 "Only give warning message when limit is exceeded\n")
6095
6096
6097 /* "neighbor allowas-in" */
6098 DEFUN (neighbor_allowas_in,
6099 neighbor_allowas_in_cmd,
6100 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "Accept as-path with my AS present in it\n"
6104 "Number of occurences of AS number\n"
6105 "Only accept my AS in the as-path if the route was originated in my AS\n")
6106 {
6107 int idx_peer = 1;
6108 int idx_number_origin = 3;
6109 int ret;
6110 int origin = 0;
6111 struct peer *peer;
6112 int allow_num = 0;
6113
6114 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6115 if (!peer)
6116 return CMD_WARNING_CONFIG_FAILED;
6117
6118 if (argc <= idx_number_origin)
6119 allow_num = 3;
6120 else {
6121 if (argv[idx_number_origin]->type == WORD_TKN)
6122 origin = 1;
6123 else
6124 allow_num = atoi(argv[idx_number_origin]->arg);
6125 }
6126
6127 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6128 allow_num, origin);
6129
6130 return bgp_vty_return(vty, ret);
6131 }
6132
6133 ALIAS_HIDDEN(
6134 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6135 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6136 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6137 "Accept as-path with my AS present in it\n"
6138 "Number of occurences of AS number\n"
6139 "Only accept my AS in the as-path if the route was originated in my AS\n")
6140
6141 DEFUN (no_neighbor_allowas_in,
6142 no_neighbor_allowas_in_cmd,
6143 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6144 NO_STR
6145 NEIGHBOR_STR
6146 NEIGHBOR_ADDR_STR2
6147 "allow local ASN appears in aspath attribute\n"
6148 "Number of occurences of AS number\n"
6149 "Only accept my AS in the as-path if the route was originated in my AS\n")
6150 {
6151 int idx_peer = 2;
6152 int ret;
6153 struct peer *peer;
6154
6155 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6156 if (!peer)
6157 return CMD_WARNING_CONFIG_FAILED;
6158
6159 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6160 bgp_node_safi(vty));
6161
6162 return bgp_vty_return(vty, ret);
6163 }
6164
6165 ALIAS_HIDDEN(
6166 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6167 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6168 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6169 "allow local ASN appears in aspath attribute\n"
6170 "Number of occurences of AS number\n"
6171 "Only accept my AS in the as-path if the route was originated in my AS\n")
6172
6173 DEFUN (neighbor_ttl_security,
6174 neighbor_ttl_security_cmd,
6175 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6176 NEIGHBOR_STR
6177 NEIGHBOR_ADDR_STR2
6178 "BGP ttl-security parameters\n"
6179 "Specify the maximum number of hops to the BGP peer\n"
6180 "Number of hops to BGP peer\n")
6181 {
6182 int idx_peer = 1;
6183 int idx_number = 4;
6184 struct peer *peer;
6185 int gtsm_hops;
6186
6187 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6188 if (!peer)
6189 return CMD_WARNING_CONFIG_FAILED;
6190
6191 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6192
6193 /*
6194 * If 'neighbor swpX', then this is for directly connected peers,
6195 * we should not accept a ttl-security hops value greater than 1.
6196 */
6197 if (peer->conf_if && (gtsm_hops > 1)) {
6198 vty_out(vty,
6199 "%s is directly connected peer, hops cannot exceed 1\n",
6200 argv[idx_peer]->arg);
6201 return CMD_WARNING_CONFIG_FAILED;
6202 }
6203
6204 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6205 }
6206
6207 DEFUN (no_neighbor_ttl_security,
6208 no_neighbor_ttl_security_cmd,
6209 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6210 NO_STR
6211 NEIGHBOR_STR
6212 NEIGHBOR_ADDR_STR2
6213 "BGP ttl-security parameters\n"
6214 "Specify the maximum number of hops to the BGP peer\n"
6215 "Number of hops to BGP peer\n")
6216 {
6217 int idx_peer = 2;
6218 struct peer *peer;
6219
6220 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6221 if (!peer)
6222 return CMD_WARNING_CONFIG_FAILED;
6223
6224 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6225 }
6226
6227 DEFUN (neighbor_addpath_tx_all_paths,
6228 neighbor_addpath_tx_all_paths_cmd,
6229 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6230 NEIGHBOR_STR
6231 NEIGHBOR_ADDR_STR2
6232 "Use addpath to advertise all paths to a neighbor\n")
6233 {
6234 int idx_peer = 1;
6235 struct peer *peer;
6236
6237 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6238 if (!peer)
6239 return CMD_WARNING_CONFIG_FAILED;
6240
6241 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6242 BGP_ADDPATH_ALL);
6243 return CMD_SUCCESS;
6244 }
6245
6246 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6247 neighbor_addpath_tx_all_paths_hidden_cmd,
6248 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6249 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6250 "Use addpath to advertise all paths to a neighbor\n")
6251
6252 DEFUN (no_neighbor_addpath_tx_all_paths,
6253 no_neighbor_addpath_tx_all_paths_cmd,
6254 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6255 NO_STR
6256 NEIGHBOR_STR
6257 NEIGHBOR_ADDR_STR2
6258 "Use addpath to advertise all paths to a neighbor\n")
6259 {
6260 int idx_peer = 2;
6261 struct peer *peer;
6262
6263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6264 if (!peer)
6265 return CMD_WARNING_CONFIG_FAILED;
6266
6267 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6268 != BGP_ADDPATH_ALL) {
6269 vty_out(vty,
6270 "%% Peer not currently configured to transmit all paths.");
6271 return CMD_WARNING_CONFIG_FAILED;
6272 }
6273
6274 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6275 BGP_ADDPATH_NONE);
6276
6277 return CMD_SUCCESS;
6278 }
6279
6280 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6281 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6282 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6283 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6284 "Use addpath to advertise all paths to a neighbor\n")
6285
6286 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6287 neighbor_addpath_tx_bestpath_per_as_cmd,
6288 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6289 NEIGHBOR_STR
6290 NEIGHBOR_ADDR_STR2
6291 "Use addpath to advertise the bestpath per each neighboring AS\n")
6292 {
6293 int idx_peer = 1;
6294 struct peer *peer;
6295
6296 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6297 if (!peer)
6298 return CMD_WARNING_CONFIG_FAILED;
6299
6300 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6301 BGP_ADDPATH_BEST_PER_AS);
6302
6303 return CMD_SUCCESS;
6304 }
6305
6306 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6307 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6308 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6309 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6310 "Use addpath to advertise the bestpath per each neighboring AS\n")
6311
6312 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6313 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6314 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6315 NO_STR
6316 NEIGHBOR_STR
6317 NEIGHBOR_ADDR_STR2
6318 "Use addpath to advertise the bestpath per each neighboring AS\n")
6319 {
6320 int idx_peer = 2;
6321 struct peer *peer;
6322
6323 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6324 if (!peer)
6325 return CMD_WARNING_CONFIG_FAILED;
6326
6327 if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)]
6328 != BGP_ADDPATH_BEST_PER_AS) {
6329 vty_out(vty,
6330 "%% Peer not currently configured to transmit all best path per as.");
6331 return CMD_WARNING_CONFIG_FAILED;
6332 }
6333
6334 bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6335 BGP_ADDPATH_NONE);
6336
6337 return CMD_SUCCESS;
6338 }
6339
6340 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6341 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6342 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6343 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6344 "Use addpath to advertise the bestpath per each neighboring AS\n")
6345
6346 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6347 struct ecommunity **list)
6348 {
6349 struct ecommunity *ecom = NULL;
6350 struct ecommunity *ecomadd;
6351
6352 for (; argc; --argc, ++argv) {
6353
6354 ecomadd = ecommunity_str2com(argv[0]->arg,
6355 ECOMMUNITY_ROUTE_TARGET, 0);
6356 if (!ecomadd) {
6357 vty_out(vty, "Malformed community-list value\n");
6358 if (ecom)
6359 ecommunity_free(&ecom);
6360 return CMD_WARNING_CONFIG_FAILED;
6361 }
6362
6363 if (ecom) {
6364 ecommunity_merge(ecom, ecomadd);
6365 ecommunity_free(&ecomadd);
6366 } else {
6367 ecom = ecomadd;
6368 }
6369 }
6370
6371 if (*list) {
6372 ecommunity_free(&*list);
6373 }
6374 *list = ecom;
6375
6376 return CMD_SUCCESS;
6377 }
6378
6379 /*
6380 * v2vimport is true if we are handling a `import vrf ...` command
6381 */
6382 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6383 {
6384 afi_t afi;
6385
6386 switch (vty->node) {
6387 case BGP_IPV4_NODE:
6388 afi = AFI_IP;
6389 break;
6390 case BGP_IPV6_NODE:
6391 afi = AFI_IP6;
6392 break;
6393 default:
6394 vty_out(vty,
6395 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6396 return AFI_MAX;
6397 }
6398
6399 if (!v2vimport) {
6400 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6401 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6402 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6403 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6404 vty_out(vty,
6405 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6406 return AFI_MAX;
6407 }
6408 } else {
6409 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6410 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6411 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6412 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6413 vty_out(vty,
6414 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6415 return AFI_MAX;
6416 }
6417 }
6418 return afi;
6419 }
6420
6421 DEFPY (af_rd_vpn_export,
6422 af_rd_vpn_export_cmd,
6423 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6424 NO_STR
6425 "Specify route distinguisher\n"
6426 "Between current address-family and vpn\n"
6427 "For routes leaked from current address-family to vpn\n"
6428 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6429 {
6430 VTY_DECLVAR_CONTEXT(bgp, bgp);
6431 struct prefix_rd prd;
6432 int ret;
6433 afi_t afi;
6434 int idx = 0;
6435 int yes = 1;
6436
6437 if (argv_find(argv, argc, "no", &idx))
6438 yes = 0;
6439
6440 if (yes) {
6441 ret = str2prefix_rd(rd_str, &prd);
6442 if (!ret) {
6443 vty_out(vty, "%% Malformed rd\n");
6444 return CMD_WARNING_CONFIG_FAILED;
6445 }
6446 }
6447
6448 afi = vpn_policy_getafi(vty, bgp, false);
6449 if (afi == AFI_MAX)
6450 return CMD_WARNING_CONFIG_FAILED;
6451
6452 /*
6453 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6454 */
6455 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6456 bgp_get_default(), bgp);
6457
6458 if (yes) {
6459 bgp->vpn_policy[afi].tovpn_rd = prd;
6460 SET_FLAG(bgp->vpn_policy[afi].flags,
6461 BGP_VPN_POLICY_TOVPN_RD_SET);
6462 } else {
6463 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6464 BGP_VPN_POLICY_TOVPN_RD_SET);
6465 }
6466
6467 /* post-change: re-export vpn routes */
6468 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6469 bgp_get_default(), bgp);
6470
6471 return CMD_SUCCESS;
6472 }
6473
6474 ALIAS (af_rd_vpn_export,
6475 af_no_rd_vpn_export_cmd,
6476 "no rd vpn export",
6477 NO_STR
6478 "Specify route distinguisher\n"
6479 "Between current address-family and vpn\n"
6480 "For routes leaked from current address-family to vpn\n")
6481
6482 DEFPY (af_label_vpn_export,
6483 af_label_vpn_export_cmd,
6484 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6485 NO_STR
6486 "label value for VRF\n"
6487 "Between current address-family and vpn\n"
6488 "For routes leaked from current address-family to vpn\n"
6489 "Label Value <0-1048575>\n"
6490 "Automatically assign a label\n")
6491 {
6492 VTY_DECLVAR_CONTEXT(bgp, bgp);
6493 mpls_label_t label = MPLS_LABEL_NONE;
6494 afi_t afi;
6495 int idx = 0;
6496 int yes = 1;
6497
6498 if (argv_find(argv, argc, "no", &idx))
6499 yes = 0;
6500
6501 /* If "no ...", squash trailing parameter */
6502 if (!yes)
6503 label_auto = NULL;
6504
6505 if (yes) {
6506 if (!label_auto)
6507 label = label_val; /* parser should force unsigned */
6508 }
6509
6510 afi = vpn_policy_getafi(vty, bgp, false);
6511 if (afi == AFI_MAX)
6512 return CMD_WARNING_CONFIG_FAILED;
6513
6514
6515 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6516 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6517 /* no change */
6518 return CMD_SUCCESS;
6519
6520 /*
6521 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6522 */
6523 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6524 bgp_get_default(), bgp);
6525
6526 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6527 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6528
6529 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6530
6531 /*
6532 * label has previously been automatically
6533 * assigned by labelpool: release it
6534 *
6535 * NB if tovpn_label == MPLS_LABEL_NONE it
6536 * means the automatic assignment is in flight
6537 * and therefore the labelpool callback must
6538 * detect that the auto label is not needed.
6539 */
6540
6541 bgp_lp_release(LP_TYPE_VRF,
6542 &bgp->vpn_policy[afi],
6543 bgp->vpn_policy[afi].tovpn_label);
6544 }
6545 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6546 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6547 }
6548
6549 bgp->vpn_policy[afi].tovpn_label = label;
6550 if (label_auto) {
6551 SET_FLAG(bgp->vpn_policy[afi].flags,
6552 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6553 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6554 vpn_leak_label_callback);
6555 }
6556
6557 /* post-change: re-export vpn routes */
6558 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6559 bgp_get_default(), bgp);
6560
6561 return CMD_SUCCESS;
6562 }
6563
6564 ALIAS (af_label_vpn_export,
6565 af_no_label_vpn_export_cmd,
6566 "no label vpn export",
6567 NO_STR
6568 "label value for VRF\n"
6569 "Between current address-family and vpn\n"
6570 "For routes leaked from current address-family to vpn\n")
6571
6572 DEFPY (af_nexthop_vpn_export,
6573 af_nexthop_vpn_export_cmd,
6574 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6575 NO_STR
6576 "Specify next hop to use for VRF advertised prefixes\n"
6577 "Between current address-family and vpn\n"
6578 "For routes leaked from current address-family to vpn\n"
6579 "IPv4 prefix\n"
6580 "IPv6 prefix\n")
6581 {
6582 VTY_DECLVAR_CONTEXT(bgp, bgp);
6583 afi_t afi;
6584 struct prefix p;
6585 int idx = 0;
6586 int yes = 1;
6587
6588 if (argv_find(argv, argc, "no", &idx))
6589 yes = 0;
6590
6591 if (yes) {
6592 if (!sockunion2hostprefix(nexthop_str, &p))
6593 return CMD_WARNING_CONFIG_FAILED;
6594 }
6595
6596 afi = vpn_policy_getafi(vty, bgp, false);
6597 if (afi == AFI_MAX)
6598 return CMD_WARNING_CONFIG_FAILED;
6599
6600 /*
6601 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6602 */
6603 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6604 bgp_get_default(), bgp);
6605
6606 if (yes) {
6607 bgp->vpn_policy[afi].tovpn_nexthop = p;
6608 SET_FLAG(bgp->vpn_policy[afi].flags,
6609 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6610 } else {
6611 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6612 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6613 }
6614
6615 /* post-change: re-export vpn routes */
6616 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6617 bgp_get_default(), bgp);
6618
6619 return CMD_SUCCESS;
6620 }
6621
6622 ALIAS (af_nexthop_vpn_export,
6623 af_no_nexthop_vpn_export_cmd,
6624 "no nexthop vpn export",
6625 NO_STR
6626 "Specify next hop to use for VRF advertised prefixes\n"
6627 "Between current address-family and vpn\n"
6628 "For routes leaked from current address-family to vpn\n")
6629
6630 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6631 {
6632 if (!strcmp(dstr, "import")) {
6633 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6634 } else if (!strcmp(dstr, "export")) {
6635 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6636 } else if (!strcmp(dstr, "both")) {
6637 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6638 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6639 } else {
6640 vty_out(vty, "%% direction parse error\n");
6641 return CMD_WARNING_CONFIG_FAILED;
6642 }
6643 return CMD_SUCCESS;
6644 }
6645
6646 DEFPY (af_rt_vpn_imexport,
6647 af_rt_vpn_imexport_cmd,
6648 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6649 NO_STR
6650 "Specify route target list\n"
6651 "Specify route target list\n"
6652 "Between current address-family and vpn\n"
6653 "For routes leaked from vpn to current address-family: match any\n"
6654 "For routes leaked from current address-family to vpn: set\n"
6655 "both import: match any and export: set\n"
6656 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6657 {
6658 VTY_DECLVAR_CONTEXT(bgp, bgp);
6659 int ret;
6660 struct ecommunity *ecom = NULL;
6661 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6662 vpn_policy_direction_t dir;
6663 afi_t afi;
6664 int idx = 0;
6665 int yes = 1;
6666
6667 if (argv_find(argv, argc, "no", &idx))
6668 yes = 0;
6669
6670 afi = vpn_policy_getafi(vty, bgp, false);
6671 if (afi == AFI_MAX)
6672 return CMD_WARNING_CONFIG_FAILED;
6673
6674 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6675 if (ret != CMD_SUCCESS)
6676 return ret;
6677
6678 if (yes) {
6679 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6680 vty_out(vty, "%% Missing RTLIST\n");
6681 return CMD_WARNING_CONFIG_FAILED;
6682 }
6683 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6684 if (ret != CMD_SUCCESS) {
6685 return ret;
6686 }
6687 }
6688
6689 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6690 if (!dodir[dir])
6691 continue;
6692
6693 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6694
6695 if (yes) {
6696 if (bgp->vpn_policy[afi].rtlist[dir])
6697 ecommunity_free(
6698 &bgp->vpn_policy[afi].rtlist[dir]);
6699 bgp->vpn_policy[afi].rtlist[dir] =
6700 ecommunity_dup(ecom);
6701 } else {
6702 if (bgp->vpn_policy[afi].rtlist[dir])
6703 ecommunity_free(
6704 &bgp->vpn_policy[afi].rtlist[dir]);
6705 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6706 }
6707
6708 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6709 }
6710
6711 if (ecom)
6712 ecommunity_free(&ecom);
6713
6714 return CMD_SUCCESS;
6715 }
6716
6717 ALIAS (af_rt_vpn_imexport,
6718 af_no_rt_vpn_imexport_cmd,
6719 "no <rt|route-target> vpn <import|export|both>$direction_str",
6720 NO_STR
6721 "Specify route target list\n"
6722 "Specify route target list\n"
6723 "Between current address-family and vpn\n"
6724 "For routes leaked from vpn to current address-family\n"
6725 "For routes leaked from current address-family to vpn\n"
6726 "both import and export\n")
6727
6728 DEFPY (af_route_map_vpn_imexport,
6729 af_route_map_vpn_imexport_cmd,
6730 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6731 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6732 NO_STR
6733 "Specify route map\n"
6734 "Between current address-family and vpn\n"
6735 "For routes leaked from vpn to current address-family\n"
6736 "For routes leaked from current address-family to vpn\n"
6737 "name of route-map\n")
6738 {
6739 VTY_DECLVAR_CONTEXT(bgp, bgp);
6740 int ret;
6741 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6742 vpn_policy_direction_t dir;
6743 afi_t afi;
6744 int idx = 0;
6745 int yes = 1;
6746
6747 if (argv_find(argv, argc, "no", &idx))
6748 yes = 0;
6749
6750 afi = vpn_policy_getafi(vty, bgp, false);
6751 if (afi == AFI_MAX)
6752 return CMD_WARNING_CONFIG_FAILED;
6753
6754 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6755 if (ret != CMD_SUCCESS)
6756 return ret;
6757
6758 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6759 if (!dodir[dir])
6760 continue;
6761
6762 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6763
6764 if (yes) {
6765 if (bgp->vpn_policy[afi].rmap_name[dir])
6766 XFREE(MTYPE_ROUTE_MAP_NAME,
6767 bgp->vpn_policy[afi].rmap_name[dir]);
6768 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6769 MTYPE_ROUTE_MAP_NAME, rmap_str);
6770 bgp->vpn_policy[afi].rmap[dir] =
6771 route_map_lookup_warn_noexist(vty, rmap_str);
6772 if (!bgp->vpn_policy[afi].rmap[dir])
6773 return CMD_SUCCESS;
6774 } else {
6775 if (bgp->vpn_policy[afi].rmap_name[dir])
6776 XFREE(MTYPE_ROUTE_MAP_NAME,
6777 bgp->vpn_policy[afi].rmap_name[dir]);
6778 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6779 bgp->vpn_policy[afi].rmap[dir] = NULL;
6780 }
6781
6782 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6783 }
6784
6785 return CMD_SUCCESS;
6786 }
6787
6788 ALIAS (af_route_map_vpn_imexport,
6789 af_no_route_map_vpn_imexport_cmd,
6790 "no route-map vpn <import|export>$direction_str",
6791 NO_STR
6792 "Specify route map\n"
6793 "Between current address-family and vpn\n"
6794 "For routes leaked from vpn to current address-family\n"
6795 "For routes leaked from current address-family to vpn\n")
6796
6797 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6798 "[no] import vrf route-map RMAP$rmap_str",
6799 NO_STR
6800 "Import routes from another VRF\n"
6801 "Vrf routes being filtered\n"
6802 "Specify route map\n"
6803 "name of route-map\n")
6804 {
6805 VTY_DECLVAR_CONTEXT(bgp, bgp);
6806 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6807 afi_t afi;
6808 int idx = 0;
6809 int yes = 1;
6810 struct bgp *bgp_default;
6811
6812 if (argv_find(argv, argc, "no", &idx))
6813 yes = 0;
6814
6815 afi = vpn_policy_getafi(vty, bgp, true);
6816 if (afi == AFI_MAX)
6817 return CMD_WARNING_CONFIG_FAILED;
6818
6819 bgp_default = bgp_get_default();
6820 if (!bgp_default) {
6821 int32_t ret;
6822 as_t as = bgp->as;
6823
6824 /* Auto-create assuming the same AS */
6825 ret = bgp_get(&bgp_default, &as, NULL,
6826 BGP_INSTANCE_TYPE_DEFAULT);
6827
6828 if (ret) {
6829 vty_out(vty,
6830 "VRF default is not configured as a bgp instance\n");
6831 return CMD_WARNING;
6832 }
6833 }
6834
6835 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6836
6837 if (yes) {
6838 if (bgp->vpn_policy[afi].rmap_name[dir])
6839 XFREE(MTYPE_ROUTE_MAP_NAME,
6840 bgp->vpn_policy[afi].rmap_name[dir]);
6841 bgp->vpn_policy[afi].rmap_name[dir] =
6842 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6843 bgp->vpn_policy[afi].rmap[dir] =
6844 route_map_lookup_warn_noexist(vty, rmap_str);
6845 if (!bgp->vpn_policy[afi].rmap[dir])
6846 return CMD_SUCCESS;
6847 } else {
6848 if (bgp->vpn_policy[afi].rmap_name[dir])
6849 XFREE(MTYPE_ROUTE_MAP_NAME,
6850 bgp->vpn_policy[afi].rmap_name[dir]);
6851 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6852 bgp->vpn_policy[afi].rmap[dir] = NULL;
6853 }
6854
6855 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6856
6857 return CMD_SUCCESS;
6858 }
6859
6860 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6861 "no import vrf route-map",
6862 NO_STR
6863 "Import routes from another VRF\n"
6864 "Vrf routes being filtered\n"
6865 "Specify route map\n")
6866
6867 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6868 "[no] import vrf VIEWVRFNAME$import_name",
6869 NO_STR
6870 "Import routes from another VRF\n"
6871 "VRF to import from\n"
6872 "The name of the VRF\n")
6873 {
6874 VTY_DECLVAR_CONTEXT(bgp, bgp);
6875 struct listnode *node;
6876 struct bgp *vrf_bgp, *bgp_default;
6877 int32_t ret = 0;
6878 as_t as = bgp->as;
6879 bool remove = false;
6880 int32_t idx = 0;
6881 char *vname;
6882 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6883 safi_t safi;
6884 afi_t afi;
6885
6886 if (import_name == NULL) {
6887 vty_out(vty, "%% Missing import name\n");
6888 return CMD_WARNING;
6889 }
6890
6891 if (argv_find(argv, argc, "no", &idx))
6892 remove = true;
6893
6894 afi = vpn_policy_getafi(vty, bgp, true);
6895 if (afi == AFI_MAX)
6896 return CMD_WARNING_CONFIG_FAILED;
6897
6898 safi = bgp_node_safi(vty);
6899
6900 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6901 && (strcmp(import_name, VRF_DEFAULT_NAME) == 0))
6902 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6903 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6904 remove ? "unimport" : "import", import_name);
6905 return CMD_WARNING;
6906 }
6907
6908 bgp_default = bgp_get_default();
6909 if (!bgp_default) {
6910 /* Auto-create assuming the same AS */
6911 ret = bgp_get(&bgp_default, &as, NULL,
6912 BGP_INSTANCE_TYPE_DEFAULT);
6913
6914 if (ret) {
6915 vty_out(vty,
6916 "VRF default is not configured as a bgp instance\n");
6917 return CMD_WARNING;
6918 }
6919 }
6920
6921 vrf_bgp = bgp_lookup_by_name(import_name);
6922 if (!vrf_bgp) {
6923 if (strcmp(import_name, VRF_DEFAULT_NAME) == 0)
6924 vrf_bgp = bgp_default;
6925 else
6926 /* Auto-create assuming the same AS */
6927 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6928
6929 if (ret) {
6930 vty_out(vty,
6931 "VRF %s is not configured as a bgp instance\n",
6932 import_name);
6933 return CMD_WARNING;
6934 }
6935 }
6936
6937 if (remove) {
6938 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6939 } else {
6940 /* Already importing from "import_vrf"? */
6941 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6942 vname)) {
6943 if (strcmp(vname, import_name) == 0)
6944 return CMD_WARNING;
6945 }
6946
6947 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6948 }
6949
6950 return CMD_SUCCESS;
6951 }
6952
6953 /* This command is valid only in a bgp vrf instance or the default instance */
6954 DEFPY (bgp_imexport_vpn,
6955 bgp_imexport_vpn_cmd,
6956 "[no] <import|export>$direction_str vpn",
6957 NO_STR
6958 "Import routes to this address-family\n"
6959 "Export routes from this address-family\n"
6960 "to/from default instance VPN RIB\n")
6961 {
6962 VTY_DECLVAR_CONTEXT(bgp, bgp);
6963 int previous_state;
6964 afi_t afi;
6965 safi_t safi;
6966 int idx = 0;
6967 int yes = 1;
6968 int flag;
6969 vpn_policy_direction_t dir;
6970
6971 if (argv_find(argv, argc, "no", &idx))
6972 yes = 0;
6973
6974 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6975 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6976
6977 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6978 return CMD_WARNING_CONFIG_FAILED;
6979 }
6980
6981 afi = bgp_node_afi(vty);
6982 safi = bgp_node_safi(vty);
6983 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6984 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6985 return CMD_WARNING_CONFIG_FAILED;
6986 }
6987
6988 if (!strcmp(direction_str, "import")) {
6989 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6990 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6991 } else if (!strcmp(direction_str, "export")) {
6992 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6993 dir = BGP_VPN_POLICY_DIR_TOVPN;
6994 } else {
6995 vty_out(vty, "%% unknown direction %s\n", direction_str);
6996 return CMD_WARNING_CONFIG_FAILED;
6997 }
6998
6999 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
7000
7001 if (yes) {
7002 SET_FLAG(bgp->af_flags[afi][safi], flag);
7003 if (!previous_state) {
7004 /* trigger export current vrf */
7005 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
7006 }
7007 } else {
7008 if (previous_state) {
7009 /* trigger un-export current vrf */
7010 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
7011 }
7012 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
7013 }
7014
7015 return CMD_SUCCESS;
7016 }
7017
7018 DEFPY (af_routetarget_import,
7019 af_routetarget_import_cmd,
7020 "[no] <rt|route-target> redirect import RTLIST...",
7021 NO_STR
7022 "Specify route target list\n"
7023 "Specify route target list\n"
7024 "Flow-spec redirect type route target\n"
7025 "Import routes to this address-family\n"
7026 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
7027 {
7028 VTY_DECLVAR_CONTEXT(bgp, bgp);
7029 int ret;
7030 struct ecommunity *ecom = NULL;
7031 afi_t afi;
7032 int idx = 0;
7033 int yes = 1;
7034
7035 if (argv_find(argv, argc, "no", &idx))
7036 yes = 0;
7037
7038 afi = vpn_policy_getafi(vty, bgp, false);
7039 if (afi == AFI_MAX)
7040 return CMD_WARNING_CONFIG_FAILED;
7041
7042 if (yes) {
7043 if (!argv_find(argv, argc, "RTLIST", &idx)) {
7044 vty_out(vty, "%% Missing RTLIST\n");
7045 return CMD_WARNING_CONFIG_FAILED;
7046 }
7047 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
7048 if (ret != CMD_SUCCESS)
7049 return ret;
7050 }
7051
7052 if (yes) {
7053 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7054 ecommunity_free(&bgp->vpn_policy[afi]
7055 .import_redirect_rtlist);
7056 bgp->vpn_policy[afi].import_redirect_rtlist =
7057 ecommunity_dup(ecom);
7058 } else {
7059 if (bgp->vpn_policy[afi].import_redirect_rtlist)
7060 ecommunity_free(&bgp->vpn_policy[afi]
7061 .import_redirect_rtlist);
7062 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
7063 }
7064
7065 if (ecom)
7066 ecommunity_free(&ecom);
7067
7068 return CMD_SUCCESS;
7069 }
7070
7071 DEFUN_NOSH (address_family_ipv4_safi,
7072 address_family_ipv4_safi_cmd,
7073 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7074 "Enter Address Family command mode\n"
7075 "Address Family\n"
7076 BGP_SAFI_WITH_LABEL_HELP_STR)
7077 {
7078
7079 if (argc == 3) {
7080 VTY_DECLVAR_CONTEXT(bgp, bgp);
7081 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7082 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7083 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7084 && safi != SAFI_EVPN) {
7085 vty_out(vty,
7086 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7087 return CMD_WARNING_CONFIG_FAILED;
7088 }
7089 vty->node = bgp_node_type(AFI_IP, safi);
7090 } else
7091 vty->node = BGP_IPV4_NODE;
7092
7093 return CMD_SUCCESS;
7094 }
7095
7096 DEFUN_NOSH (address_family_ipv6_safi,
7097 address_family_ipv6_safi_cmd,
7098 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
7099 "Enter Address Family command mode\n"
7100 "Address Family\n"
7101 BGP_SAFI_WITH_LABEL_HELP_STR)
7102 {
7103 if (argc == 3) {
7104 VTY_DECLVAR_CONTEXT(bgp, bgp);
7105 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
7106 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
7107 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
7108 && safi != SAFI_EVPN) {
7109 vty_out(vty,
7110 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
7111 return CMD_WARNING_CONFIG_FAILED;
7112 }
7113 vty->node = bgp_node_type(AFI_IP6, safi);
7114 } else
7115 vty->node = BGP_IPV6_NODE;
7116
7117 return CMD_SUCCESS;
7118 }
7119
7120 #ifdef KEEP_OLD_VPN_COMMANDS
7121 DEFUN_NOSH (address_family_vpnv4,
7122 address_family_vpnv4_cmd,
7123 "address-family vpnv4 [unicast]",
7124 "Enter Address Family command mode\n"
7125 "Address Family\n"
7126 "Address Family modifier\n")
7127 {
7128 vty->node = BGP_VPNV4_NODE;
7129 return CMD_SUCCESS;
7130 }
7131
7132 DEFUN_NOSH (address_family_vpnv6,
7133 address_family_vpnv6_cmd,
7134 "address-family vpnv6 [unicast]",
7135 "Enter Address Family command mode\n"
7136 "Address Family\n"
7137 "Address Family modifier\n")
7138 {
7139 vty->node = BGP_VPNV6_NODE;
7140 return CMD_SUCCESS;
7141 }
7142 #endif
7143
7144 DEFUN_NOSH (address_family_evpn,
7145 address_family_evpn_cmd,
7146 "address-family l2vpn evpn",
7147 "Enter Address Family command mode\n"
7148 "Address Family\n"
7149 "Address Family modifier\n")
7150 {
7151 VTY_DECLVAR_CONTEXT(bgp, bgp);
7152 vty->node = BGP_EVPN_NODE;
7153 return CMD_SUCCESS;
7154 }
7155
7156 DEFUN_NOSH (exit_address_family,
7157 exit_address_family_cmd,
7158 "exit-address-family",
7159 "Exit from Address Family configuration mode\n")
7160 {
7161 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7162 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7163 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7164 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7165 || vty->node == BGP_EVPN_NODE
7166 || vty->node == BGP_FLOWSPECV4_NODE
7167 || vty->node == BGP_FLOWSPECV6_NODE)
7168 vty->node = BGP_NODE;
7169 return CMD_SUCCESS;
7170 }
7171
7172 /* Recalculate bestpath and re-advertise a prefix */
7173 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7174 const char *ip_str, afi_t afi, safi_t safi,
7175 struct prefix_rd *prd)
7176 {
7177 int ret;
7178 struct prefix match;
7179 struct bgp_node *rn;
7180 struct bgp_node *rm;
7181 struct bgp *bgp;
7182 struct bgp_table *table;
7183 struct bgp_table *rib;
7184
7185 /* BGP structure lookup. */
7186 if (view_name) {
7187 bgp = bgp_lookup_by_name(view_name);
7188 if (bgp == NULL) {
7189 vty_out(vty, "%% Can't find BGP instance %s\n",
7190 view_name);
7191 return CMD_WARNING;
7192 }
7193 } else {
7194 bgp = bgp_get_default();
7195 if (bgp == NULL) {
7196 vty_out(vty, "%% No BGP process is configured\n");
7197 return CMD_WARNING;
7198 }
7199 }
7200
7201 /* Check IP address argument. */
7202 ret = str2prefix(ip_str, &match);
7203 if (!ret) {
7204 vty_out(vty, "%% address is malformed\n");
7205 return CMD_WARNING;
7206 }
7207
7208 match.family = afi2family(afi);
7209 rib = bgp->rib[afi][safi];
7210
7211 if (safi == SAFI_MPLS_VPN) {
7212 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7213 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7214 continue;
7215
7216 if ((table = rn->info) != NULL) {
7217 if ((rm = bgp_node_match(table, &match))
7218 != NULL) {
7219 if (rm->p.prefixlen
7220 == match.prefixlen) {
7221 SET_FLAG(rm->flags,
7222 BGP_NODE_USER_CLEAR);
7223 bgp_process(bgp, rm, afi, safi);
7224 }
7225 bgp_unlock_node(rm);
7226 }
7227 }
7228 }
7229 } else {
7230 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7231 if (rn->p.prefixlen == match.prefixlen) {
7232 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7233 bgp_process(bgp, rn, afi, safi);
7234 }
7235 bgp_unlock_node(rn);
7236 }
7237 }
7238
7239 return CMD_SUCCESS;
7240 }
7241
7242 /* one clear bgp command to rule them all */
7243 DEFUN (clear_ip_bgp_all,
7244 clear_ip_bgp_all_cmd,
7245 "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>]",
7246 CLEAR_STR
7247 IP_STR
7248 BGP_STR
7249 BGP_INSTANCE_HELP_STR
7250 BGP_AFI_HELP_STR
7251 BGP_SAFI_WITH_LABEL_HELP_STR
7252 "Clear all peers\n"
7253 "BGP neighbor address to clear\n"
7254 "BGP IPv6 neighbor to clear\n"
7255 "BGP neighbor on interface to clear\n"
7256 "Clear peers with the AS number\n"
7257 "Clear all external peers\n"
7258 "Clear all members of peer-group\n"
7259 "BGP peer-group name\n"
7260 BGP_SOFT_STR
7261 BGP_SOFT_IN_STR
7262 BGP_SOFT_OUT_STR
7263 BGP_SOFT_IN_STR
7264 "Push out prefix-list ORF and do inbound soft reconfig\n"
7265 BGP_SOFT_OUT_STR)
7266 {
7267 char *vrf = NULL;
7268
7269 afi_t afi = AFI_IP6;
7270 safi_t safi = SAFI_UNICAST;
7271 enum clear_sort clr_sort = clear_peer;
7272 enum bgp_clear_type clr_type;
7273 char *clr_arg = NULL;
7274
7275 int idx = 0;
7276
7277 /* clear [ip] bgp */
7278 if (argv_find(argv, argc, "ip", &idx))
7279 afi = AFI_IP;
7280
7281 /* [<vrf> VIEWVRFNAME] */
7282 if (argv_find(argv, argc, "vrf", &idx)) {
7283 vrf = argv[idx + 1]->arg;
7284 idx += 2;
7285 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7286 vrf = NULL;
7287 } else if (argv_find(argv, argc, "view", &idx)) {
7288 /* [<view> VIEWVRFNAME] */
7289 vrf = argv[idx + 1]->arg;
7290 idx += 2;
7291 }
7292 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7293 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7294 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7295
7296 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7297 if (argv_find(argv, argc, "*", &idx)) {
7298 clr_sort = clear_all;
7299 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7300 clr_sort = clear_peer;
7301 clr_arg = argv[idx]->arg;
7302 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7303 clr_sort = clear_peer;
7304 clr_arg = argv[idx]->arg;
7305 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7306 clr_sort = clear_group;
7307 idx++;
7308 clr_arg = argv[idx]->arg;
7309 } else if (argv_find(argv, argc, "WORD", &idx)) {
7310 clr_sort = clear_peer;
7311 clr_arg = argv[idx]->arg;
7312 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7313 clr_sort = clear_as;
7314 clr_arg = argv[idx]->arg;
7315 } else if (argv_find(argv, argc, "external", &idx)) {
7316 clr_sort = clear_external;
7317 }
7318
7319 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7320 if (argv_find(argv, argc, "soft", &idx)) {
7321 if (argv_find(argv, argc, "in", &idx)
7322 || argv_find(argv, argc, "out", &idx))
7323 clr_type = strmatch(argv[idx]->text, "in")
7324 ? BGP_CLEAR_SOFT_IN
7325 : BGP_CLEAR_SOFT_OUT;
7326 else
7327 clr_type = BGP_CLEAR_SOFT_BOTH;
7328 } else if (argv_find(argv, argc, "in", &idx)) {
7329 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7330 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7331 : BGP_CLEAR_SOFT_IN;
7332 } else if (argv_find(argv, argc, "out", &idx)) {
7333 clr_type = BGP_CLEAR_SOFT_OUT;
7334 } else
7335 clr_type = BGP_CLEAR_SOFT_NONE;
7336
7337 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7338 }
7339
7340 DEFUN (clear_ip_bgp_prefix,
7341 clear_ip_bgp_prefix_cmd,
7342 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7343 CLEAR_STR
7344 IP_STR
7345 BGP_STR
7346 BGP_INSTANCE_HELP_STR
7347 "Clear bestpath and re-advertise\n"
7348 "IPv4 prefix\n")
7349 {
7350 char *vrf = NULL;
7351 char *prefix = NULL;
7352
7353 int idx = 0;
7354
7355 /* [<view|vrf> VIEWVRFNAME] */
7356 if (argv_find(argv, argc, "vrf", &idx)) {
7357 vrf = argv[idx + 1]->arg;
7358 idx += 2;
7359 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7360 vrf = NULL;
7361 } else if (argv_find(argv, argc, "view", &idx)) {
7362 /* [<view> VIEWVRFNAME] */
7363 vrf = argv[idx + 1]->arg;
7364 idx += 2;
7365 }
7366
7367 prefix = argv[argc - 1]->arg;
7368
7369 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7370 }
7371
7372 DEFUN (clear_bgp_ipv6_safi_prefix,
7373 clear_bgp_ipv6_safi_prefix_cmd,
7374 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7375 CLEAR_STR
7376 IP_STR
7377 BGP_STR
7378 "Address Family\n"
7379 BGP_SAFI_HELP_STR
7380 "Clear bestpath and re-advertise\n"
7381 "IPv6 prefix\n")
7382 {
7383 int idx_safi = 0;
7384 int idx_ipv6_prefix = 0;
7385 safi_t safi = SAFI_UNICAST;
7386 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7387 argv[idx_ipv6_prefix]->arg : NULL;
7388
7389 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7390 return bgp_clear_prefix(
7391 vty, NULL, prefix, AFI_IP6,
7392 safi, NULL);
7393 }
7394
7395 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7396 clear_bgp_instance_ipv6_safi_prefix_cmd,
7397 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7398 CLEAR_STR
7399 IP_STR
7400 BGP_STR
7401 BGP_INSTANCE_HELP_STR
7402 "Address Family\n"
7403 BGP_SAFI_HELP_STR
7404 "Clear bestpath and re-advertise\n"
7405 "IPv6 prefix\n")
7406 {
7407 int idx_safi = 0;
7408 int idx_vrfview = 0;
7409 int idx_ipv6_prefix = 0;
7410 safi_t safi = SAFI_UNICAST;
7411 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7412 argv[idx_ipv6_prefix]->arg : NULL;
7413 char *vrfview = NULL;
7414
7415 /* [<view|vrf> VIEWVRFNAME] */
7416 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7417 vrfview = argv[idx_vrfview + 1]->arg;
7418 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7419 vrfview = NULL;
7420 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7421 /* [<view> VIEWVRFNAME] */
7422 vrfview = argv[idx_vrfview + 1]->arg;
7423 }
7424 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7425
7426 return bgp_clear_prefix(
7427 vty, vrfview, prefix,
7428 AFI_IP6, safi, NULL);
7429 }
7430
7431 DEFUN (show_bgp_views,
7432 show_bgp_views_cmd,
7433 "show [ip] bgp views",
7434 SHOW_STR
7435 IP_STR
7436 BGP_STR
7437 "Show the defined BGP views\n")
7438 {
7439 struct list *inst = bm->bgp;
7440 struct listnode *node;
7441 struct bgp *bgp;
7442
7443 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7444 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7445 return CMD_WARNING;
7446 }
7447
7448 vty_out(vty, "Defined BGP views:\n");
7449 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7450 /* Skip VRFs. */
7451 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7452 continue;
7453 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7454 bgp->as);
7455 }
7456
7457 return CMD_SUCCESS;
7458 }
7459
7460 DEFUN (show_bgp_vrfs,
7461 show_bgp_vrfs_cmd,
7462 "show [ip] bgp vrfs [json]",
7463 SHOW_STR
7464 IP_STR
7465 BGP_STR
7466 "Show BGP VRFs\n"
7467 JSON_STR)
7468 {
7469 char buf[ETHER_ADDR_STRLEN];
7470 struct list *inst = bm->bgp;
7471 struct listnode *node;
7472 struct bgp *bgp;
7473 bool uj = use_json(argc, argv);
7474 json_object *json = NULL;
7475 json_object *json_vrfs = NULL;
7476 int count = 0;
7477
7478 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7479 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7480 return CMD_WARNING;
7481 }
7482
7483 if (uj) {
7484 json = json_object_new_object();
7485 json_vrfs = json_object_new_object();
7486 }
7487
7488 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7489 const char *name, *type;
7490 struct peer *peer;
7491 struct listnode *node2, *nnode2;
7492 int peers_cfg, peers_estb;
7493 json_object *json_vrf = NULL;
7494
7495 /* Skip Views. */
7496 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7497 continue;
7498
7499 count++;
7500 if (!uj && count == 1)
7501 vty_out(vty,
7502 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7503 "Type", "Id", "routerId", "#PeersVfg",
7504 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7505
7506 peers_cfg = peers_estb = 0;
7507 if (uj)
7508 json_vrf = json_object_new_object();
7509
7510
7511 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7512 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7513 continue;
7514 peers_cfg++;
7515 if (peer->status == Established)
7516 peers_estb++;
7517 }
7518
7519 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7520 name = VRF_DEFAULT_NAME;
7521 type = "DFLT";
7522 } else {
7523 name = bgp->name;
7524 type = "VRF";
7525 }
7526
7527
7528 if (uj) {
7529 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7530 ? -1
7531 : (int64_t)bgp->vrf_id;
7532 json_object_string_add(json_vrf, "type", type);
7533 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7534 json_object_string_add(json_vrf, "routerId",
7535 inet_ntoa(bgp->router_id));
7536 json_object_int_add(json_vrf, "numConfiguredPeers",
7537 peers_cfg);
7538 json_object_int_add(json_vrf, "numEstablishedPeers",
7539 peers_estb);
7540
7541 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7542 json_object_string_add(
7543 json_vrf, "rmac",
7544 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7545 json_object_object_add(json_vrfs, name, json_vrf);
7546 } else
7547 vty_out(vty,
7548 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7549 type,
7550 bgp->vrf_id == VRF_UNKNOWN ? -1
7551 : (int)bgp->vrf_id,
7552 inet_ntoa(bgp->router_id), peers_cfg,
7553 peers_estb, name, bgp->l3vni,
7554 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7555 }
7556
7557 if (uj) {
7558 json_object_object_add(json, "vrfs", json_vrfs);
7559
7560 json_object_int_add(json, "totalVrfs", count);
7561
7562 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7563 json, JSON_C_TO_STRING_PRETTY));
7564 json_object_free(json);
7565 } else {
7566 if (count)
7567 vty_out(vty,
7568 "\nTotal number of VRFs (including default): %d\n",
7569 count);
7570 }
7571
7572 return CMD_SUCCESS;
7573 }
7574
7575
7576 static void show_tip_entry(struct hash_backet *backet, void *args)
7577 {
7578 struct vty *vty = (struct vty *)args;
7579 struct tip_addr *tip = (struct tip_addr *)backet->data;
7580
7581 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7582 tip->refcnt);
7583 }
7584
7585 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7586 {
7587 vty_out(vty, "self nexthop database:\n");
7588 bgp_nexthop_show_address_hash(vty, bgp);
7589
7590 vty_out(vty, "Tunnel-ip database:\n");
7591 hash_iterate(bgp->tip_hash,
7592 (void (*)(struct hash_backet *, void *))show_tip_entry,
7593 vty);
7594 }
7595
7596 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7597 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7598 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7599 "martian next-hops\n"
7600 "martian next-hop database\n")
7601 {
7602 struct bgp *bgp = NULL;
7603 int idx = 0;
7604 char *name = NULL;
7605
7606 /* [<vrf> VIEWVRFNAME] */
7607 if (argv_find(argv, argc, "vrf", &idx)) {
7608 name = argv[idx + 1]->arg;
7609 if (name && strmatch(name, VRF_DEFAULT_NAME))
7610 name = NULL;
7611 } else if (argv_find(argv, argc, "view", &idx))
7612 /* [<view> VIEWVRFNAME] */
7613 name = argv[idx + 1]->arg;
7614 if (name)
7615 bgp = bgp_lookup_by_name(name);
7616 else
7617 bgp = bgp_get_default();
7618
7619 if (!bgp) {
7620 vty_out(vty, "%% No BGP process is configured\n");
7621 return CMD_WARNING;
7622 }
7623 bgp_show_martian_nexthops(vty, bgp);
7624
7625 return CMD_SUCCESS;
7626 }
7627
7628 DEFUN (show_bgp_memory,
7629 show_bgp_memory_cmd,
7630 "show [ip] bgp memory",
7631 SHOW_STR
7632 IP_STR
7633 BGP_STR
7634 "Global BGP memory statistics\n")
7635 {
7636 char memstrbuf[MTYPE_MEMSTR_LEN];
7637 unsigned long count;
7638
7639 /* RIB related usage stats */
7640 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7641 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7642 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7643 count * sizeof(struct bgp_node)));
7644
7645 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7646 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7647 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7648 count * sizeof(struct bgp_path_info)));
7649 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7650 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7651 count,
7652 mtype_memstr(
7653 memstrbuf, sizeof(memstrbuf),
7654 count * sizeof(struct bgp_path_info_extra)));
7655
7656 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7657 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7658 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7659 count * sizeof(struct bgp_static)));
7660
7661 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7662 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7663 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7664 count * sizeof(struct bpacket)));
7665
7666 /* Adj-In/Out */
7667 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7668 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7669 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7670 count * sizeof(struct bgp_adj_in)));
7671 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7672 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7673 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7674 count * sizeof(struct bgp_adj_out)));
7675
7676 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7677 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7678 count,
7679 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7680 count * sizeof(struct bgp_nexthop_cache)));
7681
7682 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7683 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7684 count,
7685 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7686 count * sizeof(struct bgp_damp_info)));
7687
7688 /* Attributes */
7689 count = attr_count();
7690 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7691 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7692 count * sizeof(struct attr)));
7693
7694 if ((count = attr_unknown_count()))
7695 vty_out(vty, "%ld unknown attributes\n", count);
7696
7697 /* AS_PATH attributes */
7698 count = aspath_count();
7699 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7700 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7701 count * sizeof(struct aspath)));
7702
7703 count = mtype_stats_alloc(MTYPE_AS_SEG);
7704 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7705 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7706 count * sizeof(struct assegment)));
7707
7708 /* Other attributes */
7709 if ((count = community_count()))
7710 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7711 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7712 count * sizeof(struct community)));
7713 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7714 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7715 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7716 count * sizeof(struct ecommunity)));
7717 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7718 vty_out(vty,
7719 "%ld BGP large-community entries, using %s of memory\n",
7720 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7721 count * sizeof(struct lcommunity)));
7722
7723 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7724 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7725 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7726 count * sizeof(struct cluster_list)));
7727
7728 /* Peer related usage */
7729 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7730 vty_out(vty, "%ld peers, using %s of memory\n", count,
7731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7732 count * sizeof(struct peer)));
7733
7734 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7735 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7736 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7737 count * sizeof(struct peer_group)));
7738
7739 /* Other */
7740 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7741 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7742 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7743 count * sizeof(struct hash)));
7744 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7745 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7746 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7747 count * sizeof(struct hash_backet)));
7748 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7749 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7750 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7751 count * sizeof(regex_t)));
7752 return CMD_SUCCESS;
7753 }
7754
7755 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7756 {
7757 json_object *bestpath = json_object_new_object();
7758
7759 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7760 json_object_string_add(bestpath, "asPath", "ignore");
7761
7762 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7763 json_object_string_add(bestpath, "asPath", "confed");
7764
7765 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7766 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7767 json_object_string_add(bestpath, "multiPathRelax",
7768 "as-set");
7769 else
7770 json_object_string_add(bestpath, "multiPathRelax",
7771 "true");
7772 } else
7773 json_object_string_add(bestpath, "multiPathRelax", "false");
7774
7775 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7776 json_object_string_add(bestpath, "compareRouterId", "true");
7777 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7778 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7779 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7780 json_object_string_add(bestpath, "med", "confed");
7781 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7782 json_object_string_add(bestpath, "med",
7783 "missing-as-worst");
7784 else
7785 json_object_string_add(bestpath, "med", "true");
7786 }
7787
7788 json_object_object_add(json, "bestPath", bestpath);
7789 }
7790
7791 /* Show BGP peer's summary information. */
7792 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7793 bool use_json, json_object *json)
7794 {
7795 struct peer *peer;
7796 struct listnode *node, *nnode;
7797 unsigned int count = 0, dn_count = 0;
7798 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7799 char neighbor_buf[VTY_BUFSIZ];
7800 int neighbor_col_default_width = 16;
7801 int len;
7802 int max_neighbor_width = 0;
7803 int pfx_rcd_safi;
7804 json_object *json_peer = NULL;
7805 json_object *json_peers = NULL;
7806 struct peer_af *paf;
7807
7808 /* labeled-unicast routes are installed in the unicast table so in order
7809 * to
7810 * display the correct PfxRcd value we must look at SAFI_UNICAST
7811 */
7812 if (safi == SAFI_LABELED_UNICAST)
7813 pfx_rcd_safi = SAFI_UNICAST;
7814 else
7815 pfx_rcd_safi = safi;
7816
7817 if (use_json) {
7818 if (json == NULL)
7819 json = json_object_new_object();
7820
7821 json_peers = json_object_new_object();
7822 } else {
7823 /* Loop over all neighbors that will be displayed to determine
7824 * how many
7825 * characters are needed for the Neighbor column
7826 */
7827 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7828 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7829 continue;
7830
7831 if (peer->afc[afi][safi]) {
7832 memset(dn_flag, '\0', sizeof(dn_flag));
7833 if (peer_dynamic_neighbor(peer))
7834 dn_flag[0] = '*';
7835
7836 if (peer->hostname
7837 && bgp_flag_check(bgp,
7838 BGP_FLAG_SHOW_HOSTNAME))
7839 sprintf(neighbor_buf, "%s%s(%s) ",
7840 dn_flag, peer->hostname,
7841 peer->host);
7842 else
7843 sprintf(neighbor_buf, "%s%s ", dn_flag,
7844 peer->host);
7845
7846 len = strlen(neighbor_buf);
7847
7848 if (len > max_neighbor_width)
7849 max_neighbor_width = len;
7850 }
7851 }
7852
7853 /* Originally we displayed the Neighbor column as 16
7854 * characters wide so make that the default
7855 */
7856 if (max_neighbor_width < neighbor_col_default_width)
7857 max_neighbor_width = neighbor_col_default_width;
7858 }
7859
7860 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7861 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7862 continue;
7863
7864 if (!peer->afc[afi][safi])
7865 continue;
7866
7867 if (!count) {
7868 unsigned long ents;
7869 char memstrbuf[MTYPE_MEMSTR_LEN];
7870 int64_t vrf_id_ui;
7871
7872 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7873 ? -1
7874 : (int64_t)bgp->vrf_id;
7875
7876 /* Usage summary and header */
7877 if (use_json) {
7878 json_object_string_add(
7879 json, "routerId",
7880 inet_ntoa(bgp->router_id));
7881 json_object_int_add(json, "as", bgp->as);
7882 json_object_int_add(json, "vrfId", vrf_id_ui);
7883 json_object_string_add(
7884 json, "vrfName",
7885 (bgp->inst_type
7886 == BGP_INSTANCE_TYPE_DEFAULT)
7887 ? VRF_DEFAULT_NAME
7888 : bgp->name);
7889 } else {
7890 vty_out(vty,
7891 "BGP router identifier %s, local AS number %u vrf-id %d",
7892 inet_ntoa(bgp->router_id), bgp->as,
7893 bgp->vrf_id == VRF_UNKNOWN
7894 ? -1
7895 : (int)bgp->vrf_id);
7896 vty_out(vty, "\n");
7897 }
7898
7899 if (bgp_update_delay_configured(bgp)) {
7900 if (use_json) {
7901 json_object_int_add(
7902 json, "updateDelayLimit",
7903 bgp->v_update_delay);
7904
7905 if (bgp->v_update_delay
7906 != bgp->v_establish_wait)
7907 json_object_int_add(
7908 json,
7909 "updateDelayEstablishWait",
7910 bgp->v_establish_wait);
7911
7912 if (bgp_update_delay_active(bgp)) {
7913 json_object_string_add(
7914 json,
7915 "updateDelayFirstNeighbor",
7916 bgp->update_delay_begin_time);
7917 json_object_boolean_true_add(
7918 json,
7919 "updateDelayInProgress");
7920 } else {
7921 if (bgp->update_delay_over) {
7922 json_object_string_add(
7923 json,
7924 "updateDelayFirstNeighbor",
7925 bgp->update_delay_begin_time);
7926 json_object_string_add(
7927 json,
7928 "updateDelayBestpathResumed",
7929 bgp->update_delay_end_time);
7930 json_object_string_add(
7931 json,
7932 "updateDelayZebraUpdateResume",
7933 bgp->update_delay_zebra_resume_time);
7934 json_object_string_add(
7935 json,
7936 "updateDelayPeerUpdateResume",
7937 bgp->update_delay_peers_resume_time);
7938 }
7939 }
7940 } else {
7941 vty_out(vty,
7942 "Read-only mode update-delay limit: %d seconds\n",
7943 bgp->v_update_delay);
7944 if (bgp->v_update_delay
7945 != bgp->v_establish_wait)
7946 vty_out(vty,
7947 " Establish wait: %d seconds\n",
7948 bgp->v_establish_wait);
7949
7950 if (bgp_update_delay_active(bgp)) {
7951 vty_out(vty,
7952 " First neighbor established: %s\n",
7953 bgp->update_delay_begin_time);
7954 vty_out(vty,
7955 " Delay in progress\n");
7956 } else {
7957 if (bgp->update_delay_over) {
7958 vty_out(vty,
7959 " First neighbor established: %s\n",
7960 bgp->update_delay_begin_time);
7961 vty_out(vty,
7962 " Best-paths resumed: %s\n",
7963 bgp->update_delay_end_time);
7964 vty_out(vty,
7965 " zebra update resumed: %s\n",
7966 bgp->update_delay_zebra_resume_time);
7967 vty_out(vty,
7968 " peers update resumed: %s\n",
7969 bgp->update_delay_peers_resume_time);
7970 }
7971 }
7972 }
7973 }
7974
7975 if (use_json) {
7976 if (bgp_maxmed_onstartup_configured(bgp)
7977 && bgp->maxmed_active)
7978 json_object_boolean_true_add(
7979 json, "maxMedOnStartup");
7980 if (bgp->v_maxmed_admin)
7981 json_object_boolean_true_add(
7982 json, "maxMedAdministrative");
7983
7984 json_object_int_add(
7985 json, "tableVersion",
7986 bgp_table_version(bgp->rib[afi][safi]));
7987
7988 ents = bgp_table_count(bgp->rib[afi][safi]);
7989 json_object_int_add(json, "ribCount", ents);
7990 json_object_int_add(
7991 json, "ribMemory",
7992 ents * sizeof(struct bgp_node));
7993
7994 ents = listcount(bgp->peer);
7995 json_object_int_add(json, "peerCount", ents);
7996 json_object_int_add(json, "peerMemory",
7997 ents * sizeof(struct peer));
7998
7999 if ((ents = listcount(bgp->group))) {
8000 json_object_int_add(
8001 json, "peerGroupCount", ents);
8002 json_object_int_add(
8003 json, "peerGroupMemory",
8004 ents * sizeof(struct
8005 peer_group));
8006 }
8007
8008 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8009 BGP_CONFIG_DAMPENING))
8010 json_object_boolean_true_add(
8011 json, "dampeningEnabled");
8012 } else {
8013 if (bgp_maxmed_onstartup_configured(bgp)
8014 && bgp->maxmed_active)
8015 vty_out(vty,
8016 "Max-med on-startup active\n");
8017 if (bgp->v_maxmed_admin)
8018 vty_out(vty,
8019 "Max-med administrative active\n");
8020
8021 vty_out(vty, "BGP table version %" PRIu64 "\n",
8022 bgp_table_version(bgp->rib[afi][safi]));
8023
8024 ents = bgp_table_count(bgp->rib[afi][safi]);
8025 vty_out(vty,
8026 "RIB entries %ld, using %s of memory\n",
8027 ents,
8028 mtype_memstr(memstrbuf,
8029 sizeof(memstrbuf),
8030 ents * sizeof(struct
8031 bgp_node)));
8032
8033 /* Peer related usage */
8034 ents = listcount(bgp->peer);
8035 vty_out(vty, "Peers %ld, using %s of memory\n",
8036 ents,
8037 mtype_memstr(
8038 memstrbuf, sizeof(memstrbuf),
8039 ents * sizeof(struct peer)));
8040
8041 if ((ents = listcount(bgp->group)))
8042 vty_out(vty,
8043 "Peer groups %ld, using %s of memory\n",
8044 ents,
8045 mtype_memstr(
8046 memstrbuf,
8047 sizeof(memstrbuf),
8048 ents * sizeof(struct
8049 peer_group)));
8050
8051 if (CHECK_FLAG(bgp->af_flags[afi][safi],
8052 BGP_CONFIG_DAMPENING))
8053 vty_out(vty, "Dampening enabled.\n");
8054 vty_out(vty, "\n");
8055
8056 /* Subtract 8 here because 'Neighbor' is
8057 * 8 characters */
8058 vty_out(vty, "Neighbor");
8059 vty_out(vty, "%*s", max_neighbor_width - 8,
8060 " ");
8061 vty_out(vty,
8062 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
8063 }
8064 }
8065
8066 count++;
8067
8068 if (use_json) {
8069 json_peer = json_object_new_object();
8070
8071 if (peer_dynamic_neighbor(peer)) {
8072 dn_count++;
8073 json_object_boolean_true_add(json_peer,
8074 "dynamicPeer");
8075 }
8076
8077 if (peer->hostname)
8078 json_object_string_add(json_peer, "hostname",
8079 peer->hostname);
8080
8081 if (peer->domainname)
8082 json_object_string_add(json_peer, "domainname",
8083 peer->domainname);
8084
8085 json_object_int_add(json_peer, "remoteAs", peer->as);
8086 json_object_int_add(json_peer, "version", 4);
8087 json_object_int_add(json_peer, "msgRcvd",
8088 PEER_TOTAL_RX(peer));
8089 json_object_int_add(json_peer, "msgSent",
8090 PEER_TOTAL_TX(peer));
8091
8092 json_object_int_add(json_peer, "tableVersion",
8093 peer->version[afi][safi]);
8094 json_object_int_add(json_peer, "outq",
8095 peer->obuf->count);
8096 json_object_int_add(json_peer, "inq", 0);
8097 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
8098 use_json, json_peer);
8099
8100 /*
8101 * Adding "pfxRcd" field to match with the corresponding
8102 * CLI. "prefixReceivedCount" will be deprecated in
8103 * future.
8104 */
8105 json_object_int_add(json_peer, "prefixReceivedCount",
8106 peer->pcount[afi][pfx_rcd_safi]);
8107 json_object_int_add(json_peer, "pfxRcd",
8108 peer->pcount[afi][pfx_rcd_safi]);
8109
8110 paf = peer_af_find(peer, afi, pfx_rcd_safi);
8111 if (paf && PAF_SUBGRP(paf))
8112 json_object_int_add(json_peer,
8113 "pfxSnt",
8114 (PAF_SUBGRP(paf))->scount);
8115
8116 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8117 json_object_string_add(json_peer, "state",
8118 "Idle (Admin)");
8119 else if (peer->afc_recv[afi][safi])
8120 json_object_string_add(
8121 json_peer, "state",
8122 lookup_msg(bgp_status_msg, peer->status,
8123 NULL));
8124 else if (CHECK_FLAG(peer->sflags,
8125 PEER_STATUS_PREFIX_OVERFLOW))
8126 json_object_string_add(json_peer, "state",
8127 "Idle (PfxCt)");
8128 else
8129 json_object_string_add(
8130 json_peer, "state",
8131 lookup_msg(bgp_status_msg, peer->status,
8132 NULL));
8133
8134 if (peer->conf_if)
8135 json_object_string_add(json_peer, "idType",
8136 "interface");
8137 else if (peer->su.sa.sa_family == AF_INET)
8138 json_object_string_add(json_peer, "idType",
8139 "ipv4");
8140 else if (peer->su.sa.sa_family == AF_INET6)
8141 json_object_string_add(json_peer, "idType",
8142 "ipv6");
8143
8144 json_object_object_add(json_peers, peer->host,
8145 json_peer);
8146 } else {
8147 memset(dn_flag, '\0', sizeof(dn_flag));
8148 if (peer_dynamic_neighbor(peer)) {
8149 dn_count++;
8150 dn_flag[0] = '*';
8151 }
8152
8153 if (peer->hostname
8154 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8155 len = vty_out(vty, "%s%s(%s)", dn_flag,
8156 peer->hostname, peer->host);
8157 else
8158 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8159
8160 /* pad the neighbor column with spaces */
8161 if (len < max_neighbor_width)
8162 vty_out(vty, "%*s", max_neighbor_width - len,
8163 " ");
8164
8165 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8166 peer->as, PEER_TOTAL_RX(peer),
8167 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8168 0, peer->obuf->count,
8169 peer_uptime(peer->uptime, timebuf,
8170 BGP_UPTIME_LEN, 0, NULL));
8171
8172 if (peer->status == Established)
8173 if (peer->afc_recv[afi][safi])
8174 vty_out(vty, " %12ld",
8175 peer->pcount[afi]
8176 [pfx_rcd_safi]);
8177 else
8178 vty_out(vty, " NoNeg");
8179 else {
8180 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8181 vty_out(vty, " Idle (Admin)");
8182 else if (CHECK_FLAG(
8183 peer->sflags,
8184 PEER_STATUS_PREFIX_OVERFLOW))
8185 vty_out(vty, " Idle (PfxCt)");
8186 else
8187 vty_out(vty, " %12s",
8188 lookup_msg(bgp_status_msg,
8189 peer->status, NULL));
8190 }
8191 vty_out(vty, "\n");
8192 }
8193 }
8194
8195 if (use_json) {
8196 json_object_object_add(json, "peers", json_peers);
8197
8198 json_object_int_add(json, "totalPeers", count);
8199 json_object_int_add(json, "dynamicPeers", dn_count);
8200
8201 bgp_show_bestpath_json(bgp, json);
8202
8203 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8204 json, JSON_C_TO_STRING_PRETTY));
8205 json_object_free(json);
8206 } else {
8207 if (count)
8208 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8209 else {
8210 vty_out(vty, "No %s neighbor is configured\n",
8211 afi_safi_print(afi, safi));
8212 }
8213
8214 if (dn_count) {
8215 vty_out(vty, "* - dynamic neighbor\n");
8216 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8217 dn_count, bgp->dynamic_neighbors_limit);
8218 }
8219 }
8220
8221 return CMD_SUCCESS;
8222 }
8223
8224 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8225 int safi, bool use_json,
8226 json_object *json)
8227 {
8228 int is_first = 1;
8229 int afi_wildcard = (afi == AFI_MAX);
8230 int safi_wildcard = (safi == SAFI_MAX);
8231 int is_wildcard = (afi_wildcard || safi_wildcard);
8232 bool nbr_output = false;
8233
8234 if (use_json && is_wildcard)
8235 vty_out(vty, "{\n");
8236 if (afi_wildcard)
8237 afi = 1; /* AFI_IP */
8238 while (afi < AFI_MAX) {
8239 if (safi_wildcard)
8240 safi = 1; /* SAFI_UNICAST */
8241 while (safi < SAFI_MAX) {
8242 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8243 nbr_output = true;
8244 if (is_wildcard) {
8245 /*
8246 * So limit output to those afi/safi
8247 * pairs that
8248 * actualy have something interesting in
8249 * them
8250 */
8251 if (use_json) {
8252 json = json_object_new_object();
8253
8254 if (!is_first)
8255 vty_out(vty, ",\n");
8256 else
8257 is_first = 0;
8258
8259 vty_out(vty, "\"%s\":",
8260 afi_safi_json(afi,
8261 safi));
8262 } else {
8263 vty_out(vty, "\n%s Summary:\n",
8264 afi_safi_print(afi,
8265 safi));
8266 }
8267 }
8268 bgp_show_summary(vty, bgp, afi, safi, use_json,
8269 json);
8270 }
8271 safi++;
8272 if (!safi_wildcard)
8273 safi = SAFI_MAX;
8274 }
8275 afi++;
8276 if (!afi_wildcard)
8277 afi = AFI_MAX;
8278 }
8279
8280 if (use_json && is_wildcard)
8281 vty_out(vty, "}\n");
8282 else if (!nbr_output) {
8283 if (use_json)
8284 vty_out(vty, "{}\n");
8285 else
8286 vty_out(vty, "%% No BGP neighbors found\n");
8287 }
8288 }
8289
8290 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8291 safi_t safi, bool use_json)
8292 {
8293 struct listnode *node, *nnode;
8294 struct bgp *bgp;
8295 json_object *json = NULL;
8296 int is_first = 1;
8297 bool nbr_output = false;
8298
8299 if (use_json)
8300 vty_out(vty, "{\n");
8301
8302 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8303 nbr_output = true;
8304 if (use_json) {
8305 json = json_object_new_object();
8306
8307 if (!is_first)
8308 vty_out(vty, ",\n");
8309 else
8310 is_first = 0;
8311
8312 vty_out(vty, "\"%s\":",
8313 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8314 ? VRF_DEFAULT_NAME
8315 : bgp->name);
8316 } else {
8317 vty_out(vty, "\nInstance %s:\n",
8318 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8319 ? VRF_DEFAULT_NAME
8320 : bgp->name);
8321 }
8322 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8323 }
8324
8325 if (use_json)
8326 vty_out(vty, "}\n");
8327 else if (!nbr_output)
8328 vty_out(vty, "%% BGP instance not found\n");
8329 }
8330
8331 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8332 safi_t safi, bool use_json)
8333 {
8334 struct bgp *bgp;
8335
8336 if (name) {
8337 if (strmatch(name, "all")) {
8338 bgp_show_all_instances_summary_vty(vty, afi, safi,
8339 use_json);
8340 return CMD_SUCCESS;
8341 } else {
8342 bgp = bgp_lookup_by_name(name);
8343
8344 if (!bgp) {
8345 if (use_json)
8346 vty_out(vty, "{}\n");
8347 else
8348 vty_out(vty,
8349 "%% BGP instance not found\n");
8350 return CMD_WARNING;
8351 }
8352
8353 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8354 NULL);
8355 return CMD_SUCCESS;
8356 }
8357 }
8358
8359 bgp = bgp_get_default();
8360
8361 if (bgp)
8362 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8363 else {
8364 if (use_json)
8365 vty_out(vty, "{}\n");
8366 else
8367 vty_out(vty, "%% BGP instance not found\n");
8368 return CMD_WARNING;
8369 }
8370
8371 return CMD_SUCCESS;
8372 }
8373
8374 /* `show [ip] bgp summary' commands. */
8375 DEFUN (show_ip_bgp_summary,
8376 show_ip_bgp_summary_cmd,
8377 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8378 SHOW_STR
8379 IP_STR
8380 BGP_STR
8381 BGP_INSTANCE_HELP_STR
8382 BGP_AFI_HELP_STR
8383 BGP_SAFI_WITH_LABEL_HELP_STR
8384 "Summary of BGP neighbor status\n"
8385 JSON_STR)
8386 {
8387 char *vrf = NULL;
8388 afi_t afi = AFI_MAX;
8389 safi_t safi = SAFI_MAX;
8390
8391 int idx = 0;
8392
8393 /* show [ip] bgp */
8394 if (argv_find(argv, argc, "ip", &idx))
8395 afi = AFI_IP;
8396 /* [<vrf> VIEWVRFNAME] */
8397 if (argv_find(argv, argc, "vrf", &idx)) {
8398 vrf = argv[idx + 1]->arg;
8399 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8400 vrf = NULL;
8401 } else if (argv_find(argv, argc, "view", &idx))
8402 /* [<view> VIEWVRFNAME] */
8403 vrf = argv[idx + 1]->arg;
8404 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8405 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8406 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8407 }
8408
8409 bool uj = use_json(argc, argv);
8410
8411 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8412 }
8413
8414 const char *afi_safi_print(afi_t afi, safi_t safi)
8415 {
8416 if (afi == AFI_IP && safi == SAFI_UNICAST)
8417 return "IPv4 Unicast";
8418 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8419 return "IPv4 Multicast";
8420 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8421 return "IPv4 Labeled Unicast";
8422 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8423 return "IPv4 VPN";
8424 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8425 return "IPv4 Encap";
8426 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8427 return "IPv4 Flowspec";
8428 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8429 return "IPv6 Unicast";
8430 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8431 return "IPv6 Multicast";
8432 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8433 return "IPv6 Labeled Unicast";
8434 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8435 return "IPv6 VPN";
8436 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8437 return "IPv6 Encap";
8438 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8439 return "IPv6 Flowspec";
8440 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8441 return "L2VPN EVPN";
8442 else
8443 return "Unknown";
8444 }
8445
8446 /*
8447 * Please note that we have intentionally camelCased
8448 * the return strings here. So if you want
8449 * to use this function, please ensure you
8450 * are doing this within json output
8451 */
8452 const char *afi_safi_json(afi_t afi, safi_t safi)
8453 {
8454 if (afi == AFI_IP && safi == SAFI_UNICAST)
8455 return "ipv4Unicast";
8456 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8457 return "ipv4Multicast";
8458 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8459 return "ipv4LabeledUnicast";
8460 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8461 return "ipv4Vpn";
8462 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8463 return "ipv4Encap";
8464 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8465 return "ipv4Flowspec";
8466 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8467 return "ipv6Unicast";
8468 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8469 return "ipv6Multicast";
8470 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8471 return "ipv6LabeledUnicast";
8472 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8473 return "ipv6Vpn";
8474 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8475 return "ipv6Encap";
8476 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8477 return "ipv6Flowspec";
8478 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8479 return "l2VpnEvpn";
8480 else
8481 return "Unknown";
8482 }
8483
8484 /* Show BGP peer's information. */
8485 enum show_type { show_all, show_peer };
8486
8487 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8488 afi_t afi, safi_t safi,
8489 uint16_t adv_smcap, uint16_t adv_rmcap,
8490 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8491 bool use_json, json_object *json_pref)
8492 {
8493 /* Send-Mode */
8494 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8495 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8496 if (use_json) {
8497 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8498 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8499 json_object_string_add(json_pref, "sendMode",
8500 "advertisedAndReceived");
8501 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8502 json_object_string_add(json_pref, "sendMode",
8503 "advertised");
8504 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8505 json_object_string_add(json_pref, "sendMode",
8506 "received");
8507 } else {
8508 vty_out(vty, " Send-mode: ");
8509 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8510 vty_out(vty, "advertised");
8511 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8512 vty_out(vty, "%sreceived",
8513 CHECK_FLAG(p->af_cap[afi][safi],
8514 adv_smcap)
8515 ? ", "
8516 : "");
8517 vty_out(vty, "\n");
8518 }
8519 }
8520
8521 /* Receive-Mode */
8522 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8523 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8524 if (use_json) {
8525 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8526 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8527 json_object_string_add(json_pref, "recvMode",
8528 "advertisedAndReceived");
8529 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8530 json_object_string_add(json_pref, "recvMode",
8531 "advertised");
8532 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8533 json_object_string_add(json_pref, "recvMode",
8534 "received");
8535 } else {
8536 vty_out(vty, " Receive-mode: ");
8537 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8538 vty_out(vty, "advertised");
8539 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8540 vty_out(vty, "%sreceived",
8541 CHECK_FLAG(p->af_cap[afi][safi],
8542 adv_rmcap)
8543 ? ", "
8544 : "");
8545 vty_out(vty, "\n");
8546 }
8547 }
8548 }
8549
8550 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8551 safi_t safi, bool use_json,
8552 json_object *json_neigh)
8553 {
8554 struct bgp_filter *filter;
8555 struct peer_af *paf;
8556 char orf_pfx_name[BUFSIZ];
8557 int orf_pfx_count;
8558 json_object *json_af = NULL;
8559 json_object *json_prefA = NULL;
8560 json_object *json_prefB = NULL;
8561 json_object *json_addr = NULL;
8562
8563 if (use_json) {
8564 json_addr = json_object_new_object();
8565 json_af = json_object_new_object();
8566 filter = &p->filter[afi][safi];
8567
8568 if (peer_group_active(p))
8569 json_object_string_add(json_addr, "peerGroupMember",
8570 p->group->name);
8571
8572 paf = peer_af_find(p, afi, safi);
8573 if (paf && PAF_SUBGRP(paf)) {
8574 json_object_int_add(json_addr, "updateGroupId",
8575 PAF_UPDGRP(paf)->id);
8576 json_object_int_add(json_addr, "subGroupId",
8577 PAF_SUBGRP(paf)->id);
8578 json_object_int_add(json_addr, "packetQueueLength",
8579 bpacket_queue_virtual_length(paf));
8580 }
8581
8582 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8583 || CHECK_FLAG(p->af_cap[afi][safi],
8584 PEER_CAP_ORF_PREFIX_SM_RCV)
8585 || CHECK_FLAG(p->af_cap[afi][safi],
8586 PEER_CAP_ORF_PREFIX_RM_ADV)
8587 || CHECK_FLAG(p->af_cap[afi][safi],
8588 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8589 json_object_int_add(json_af, "orfType",
8590 ORF_TYPE_PREFIX);
8591 json_prefA = json_object_new_object();
8592 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8593 PEER_CAP_ORF_PREFIX_SM_ADV,
8594 PEER_CAP_ORF_PREFIX_RM_ADV,
8595 PEER_CAP_ORF_PREFIX_SM_RCV,
8596 PEER_CAP_ORF_PREFIX_RM_RCV,
8597 use_json, json_prefA);
8598 json_object_object_add(json_af, "orfPrefixList",
8599 json_prefA);
8600 }
8601
8602 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8603 || CHECK_FLAG(p->af_cap[afi][safi],
8604 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8605 || CHECK_FLAG(p->af_cap[afi][safi],
8606 PEER_CAP_ORF_PREFIX_RM_ADV)
8607 || CHECK_FLAG(p->af_cap[afi][safi],
8608 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8609 json_object_int_add(json_af, "orfOldType",
8610 ORF_TYPE_PREFIX_OLD);
8611 json_prefB = json_object_new_object();
8612 bgp_show_peer_afi_orf_cap(
8613 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8614 PEER_CAP_ORF_PREFIX_RM_ADV,
8615 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8616 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8617 json_prefB);
8618 json_object_object_add(json_af, "orfOldPrefixList",
8619 json_prefB);
8620 }
8621
8622 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8623 || CHECK_FLAG(p->af_cap[afi][safi],
8624 PEER_CAP_ORF_PREFIX_SM_RCV)
8625 || CHECK_FLAG(p->af_cap[afi][safi],
8626 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8627 || CHECK_FLAG(p->af_cap[afi][safi],
8628 PEER_CAP_ORF_PREFIX_RM_ADV)
8629 || CHECK_FLAG(p->af_cap[afi][safi],
8630 PEER_CAP_ORF_PREFIX_RM_RCV)
8631 || CHECK_FLAG(p->af_cap[afi][safi],
8632 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8633 json_object_object_add(json_addr, "afDependentCap",
8634 json_af);
8635 else
8636 json_object_free(json_af);
8637
8638 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8639 orf_pfx_count = prefix_bgp_show_prefix_list(
8640 NULL, afi, orf_pfx_name, use_json);
8641
8642 if (CHECK_FLAG(p->af_sflags[afi][safi],
8643 PEER_STATUS_ORF_PREFIX_SEND)
8644 || orf_pfx_count) {
8645 if (CHECK_FLAG(p->af_sflags[afi][safi],
8646 PEER_STATUS_ORF_PREFIX_SEND))
8647 json_object_boolean_true_add(json_neigh,
8648 "orfSent");
8649 if (orf_pfx_count)
8650 json_object_int_add(json_addr, "orfRecvCounter",
8651 orf_pfx_count);
8652 }
8653 if (CHECK_FLAG(p->af_sflags[afi][safi],
8654 PEER_STATUS_ORF_WAIT_REFRESH))
8655 json_object_string_add(
8656 json_addr, "orfFirstUpdate",
8657 "deferredUntilORFOrRouteRefreshRecvd");
8658
8659 if (CHECK_FLAG(p->af_flags[afi][safi],
8660 PEER_FLAG_REFLECTOR_CLIENT))
8661 json_object_boolean_true_add(json_addr,
8662 "routeReflectorClient");
8663 if (CHECK_FLAG(p->af_flags[afi][safi],
8664 PEER_FLAG_RSERVER_CLIENT))
8665 json_object_boolean_true_add(json_addr,
8666 "routeServerClient");
8667 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8668 json_object_boolean_true_add(json_addr,
8669 "inboundSoftConfigPermit");
8670
8671 if (CHECK_FLAG(p->af_flags[afi][safi],
8672 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8673 json_object_boolean_true_add(
8674 json_addr,
8675 "privateAsNumsAllReplacedInUpdatesToNbr");
8676 else if (CHECK_FLAG(p->af_flags[afi][safi],
8677 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8678 json_object_boolean_true_add(
8679 json_addr,
8680 "privateAsNumsReplacedInUpdatesToNbr");
8681 else if (CHECK_FLAG(p->af_flags[afi][safi],
8682 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8683 json_object_boolean_true_add(
8684 json_addr,
8685 "privateAsNumsAllRemovedInUpdatesToNbr");
8686 else if (CHECK_FLAG(p->af_flags[afi][safi],
8687 PEER_FLAG_REMOVE_PRIVATE_AS))
8688 json_object_boolean_true_add(
8689 json_addr,
8690 "privateAsNumsRemovedInUpdatesToNbr");
8691
8692 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8693 json_object_boolean_true_add(
8694 json_addr,
8695 bgp_addpath_names(p->addpath_type[afi][safi])
8696 ->type_json_name);
8697
8698 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8699 json_object_string_add(json_addr,
8700 "overrideASNsInOutboundUpdates",
8701 "ifAspathEqualRemoteAs");
8702
8703 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8704 || CHECK_FLAG(p->af_flags[afi][safi],
8705 PEER_FLAG_FORCE_NEXTHOP_SELF))
8706 json_object_boolean_true_add(json_addr,
8707 "routerAlwaysNextHop");
8708 if (CHECK_FLAG(p->af_flags[afi][safi],
8709 PEER_FLAG_AS_PATH_UNCHANGED))
8710 json_object_boolean_true_add(
8711 json_addr, "unchangedAsPathPropogatedToNbr");
8712 if (CHECK_FLAG(p->af_flags[afi][safi],
8713 PEER_FLAG_NEXTHOP_UNCHANGED))
8714 json_object_boolean_true_add(
8715 json_addr, "unchangedNextHopPropogatedToNbr");
8716 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8717 json_object_boolean_true_add(
8718 json_addr, "unchangedMedPropogatedToNbr");
8719 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8720 || CHECK_FLAG(p->af_flags[afi][safi],
8721 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8722 if (CHECK_FLAG(p->af_flags[afi][safi],
8723 PEER_FLAG_SEND_COMMUNITY)
8724 && CHECK_FLAG(p->af_flags[afi][safi],
8725 PEER_FLAG_SEND_EXT_COMMUNITY))
8726 json_object_string_add(json_addr,
8727 "commAttriSentToNbr",
8728 "extendedAndStandard");
8729 else if (CHECK_FLAG(p->af_flags[afi][safi],
8730 PEER_FLAG_SEND_EXT_COMMUNITY))
8731 json_object_string_add(json_addr,
8732 "commAttriSentToNbr",
8733 "extended");
8734 else
8735 json_object_string_add(json_addr,
8736 "commAttriSentToNbr",
8737 "standard");
8738 }
8739 if (CHECK_FLAG(p->af_flags[afi][safi],
8740 PEER_FLAG_DEFAULT_ORIGINATE)) {
8741 if (p->default_rmap[afi][safi].name)
8742 json_object_string_add(
8743 json_addr, "defaultRouteMap",
8744 p->default_rmap[afi][safi].name);
8745
8746 if (paf && PAF_SUBGRP(paf)
8747 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8748 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8749 json_object_boolean_true_add(json_addr,
8750 "defaultSent");
8751 else
8752 json_object_boolean_true_add(json_addr,
8753 "defaultNotSent");
8754 }
8755
8756 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8757 if (is_evpn_enabled())
8758 json_object_boolean_true_add(
8759 json_addr, "advertiseAllVnis");
8760 }
8761
8762 if (filter->plist[FILTER_IN].name
8763 || filter->dlist[FILTER_IN].name
8764 || filter->aslist[FILTER_IN].name
8765 || filter->map[RMAP_IN].name)
8766 json_object_boolean_true_add(json_addr,
8767 "inboundPathPolicyConfig");
8768 if (filter->plist[FILTER_OUT].name
8769 || filter->dlist[FILTER_OUT].name
8770 || filter->aslist[FILTER_OUT].name
8771 || filter->map[RMAP_OUT].name || filter->usmap.name)
8772 json_object_boolean_true_add(
8773 json_addr, "outboundPathPolicyConfig");
8774
8775 /* prefix-list */
8776 if (filter->plist[FILTER_IN].name)
8777 json_object_string_add(json_addr,
8778 "incomingUpdatePrefixFilterList",
8779 filter->plist[FILTER_IN].name);
8780 if (filter->plist[FILTER_OUT].name)
8781 json_object_string_add(json_addr,
8782 "outgoingUpdatePrefixFilterList",
8783 filter->plist[FILTER_OUT].name);
8784
8785 /* distribute-list */
8786 if (filter->dlist[FILTER_IN].name)
8787 json_object_string_add(
8788 json_addr, "incomingUpdateNetworkFilterList",
8789 filter->dlist[FILTER_IN].name);
8790 if (filter->dlist[FILTER_OUT].name)
8791 json_object_string_add(
8792 json_addr, "outgoingUpdateNetworkFilterList",
8793 filter->dlist[FILTER_OUT].name);
8794
8795 /* filter-list. */
8796 if (filter->aslist[FILTER_IN].name)
8797 json_object_string_add(json_addr,
8798 "incomingUpdateAsPathFilterList",
8799 filter->aslist[FILTER_IN].name);
8800 if (filter->aslist[FILTER_OUT].name)
8801 json_object_string_add(json_addr,
8802 "outgoingUpdateAsPathFilterList",
8803 filter->aslist[FILTER_OUT].name);
8804
8805 /* route-map. */
8806 if (filter->map[RMAP_IN].name)
8807 json_object_string_add(
8808 json_addr, "routeMapForIncomingAdvertisements",
8809 filter->map[RMAP_IN].name);
8810 if (filter->map[RMAP_OUT].name)
8811 json_object_string_add(
8812 json_addr, "routeMapForOutgoingAdvertisements",
8813 filter->map[RMAP_OUT].name);
8814
8815 /* unsuppress-map */
8816 if (filter->usmap.name)
8817 json_object_string_add(json_addr,
8818 "selectiveUnsuppressRouteMap",
8819 filter->usmap.name);
8820
8821 /* Receive prefix count */
8822 json_object_int_add(json_addr, "acceptedPrefixCounter",
8823 p->pcount[afi][safi]);
8824 if (paf && PAF_SUBGRP(paf))
8825 json_object_int_add(json_addr, "sentPrefixCounter",
8826 (PAF_SUBGRP(paf))->scount);
8827
8828 /* Maximum prefix */
8829 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8830 json_object_int_add(json_addr, "prefixAllowedMax",
8831 p->pmax[afi][safi]);
8832 if (CHECK_FLAG(p->af_flags[afi][safi],
8833 PEER_FLAG_MAX_PREFIX_WARNING))
8834 json_object_boolean_true_add(
8835 json_addr, "prefixAllowedMaxWarning");
8836 json_object_int_add(json_addr,
8837 "prefixAllowedWarningThresh",
8838 p->pmax_threshold[afi][safi]);
8839 if (p->pmax_restart[afi][safi])
8840 json_object_int_add(
8841 json_addr,
8842 "prefixAllowedRestartIntervalMsecs",
8843 p->pmax_restart[afi][safi] * 60000);
8844 }
8845 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8846 json_addr);
8847
8848 } else {
8849 filter = &p->filter[afi][safi];
8850
8851 vty_out(vty, " For address family: %s\n",
8852 afi_safi_print(afi, safi));
8853
8854 if (peer_group_active(p))
8855 vty_out(vty, " %s peer-group member\n",
8856 p->group->name);
8857
8858 paf = peer_af_find(p, afi, safi);
8859 if (paf && PAF_SUBGRP(paf)) {
8860 vty_out(vty, " Update group %" PRIu64
8861 ", subgroup %" PRIu64 "\n",
8862 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8863 vty_out(vty, " Packet Queue length %d\n",
8864 bpacket_queue_virtual_length(paf));
8865 } else {
8866 vty_out(vty, " Not part of any update group\n");
8867 }
8868 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8869 || CHECK_FLAG(p->af_cap[afi][safi],
8870 PEER_CAP_ORF_PREFIX_SM_RCV)
8871 || CHECK_FLAG(p->af_cap[afi][safi],
8872 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8873 || CHECK_FLAG(p->af_cap[afi][safi],
8874 PEER_CAP_ORF_PREFIX_RM_ADV)
8875 || CHECK_FLAG(p->af_cap[afi][safi],
8876 PEER_CAP_ORF_PREFIX_RM_RCV)
8877 || CHECK_FLAG(p->af_cap[afi][safi],
8878 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8879 vty_out(vty, " AF-dependant capabilities:\n");
8880
8881 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8882 || CHECK_FLAG(p->af_cap[afi][safi],
8883 PEER_CAP_ORF_PREFIX_SM_RCV)
8884 || CHECK_FLAG(p->af_cap[afi][safi],
8885 PEER_CAP_ORF_PREFIX_RM_ADV)
8886 || CHECK_FLAG(p->af_cap[afi][safi],
8887 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8888 vty_out(vty,
8889 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8890 ORF_TYPE_PREFIX);
8891 bgp_show_peer_afi_orf_cap(
8892 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8893 PEER_CAP_ORF_PREFIX_RM_ADV,
8894 PEER_CAP_ORF_PREFIX_SM_RCV,
8895 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8896 }
8897 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8898 || CHECK_FLAG(p->af_cap[afi][safi],
8899 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8900 || CHECK_FLAG(p->af_cap[afi][safi],
8901 PEER_CAP_ORF_PREFIX_RM_ADV)
8902 || CHECK_FLAG(p->af_cap[afi][safi],
8903 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8904 vty_out(vty,
8905 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8906 ORF_TYPE_PREFIX_OLD);
8907 bgp_show_peer_afi_orf_cap(
8908 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8909 PEER_CAP_ORF_PREFIX_RM_ADV,
8910 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8911 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8912 }
8913
8914 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8915 orf_pfx_count = prefix_bgp_show_prefix_list(
8916 NULL, afi, orf_pfx_name, use_json);
8917
8918 if (CHECK_FLAG(p->af_sflags[afi][safi],
8919 PEER_STATUS_ORF_PREFIX_SEND)
8920 || orf_pfx_count) {
8921 vty_out(vty, " Outbound Route Filter (ORF):");
8922 if (CHECK_FLAG(p->af_sflags[afi][safi],
8923 PEER_STATUS_ORF_PREFIX_SEND))
8924 vty_out(vty, " sent;");
8925 if (orf_pfx_count)
8926 vty_out(vty, " received (%d entries)",
8927 orf_pfx_count);
8928 vty_out(vty, "\n");
8929 }
8930 if (CHECK_FLAG(p->af_sflags[afi][safi],
8931 PEER_STATUS_ORF_WAIT_REFRESH))
8932 vty_out(vty,
8933 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8934
8935 if (CHECK_FLAG(p->af_flags[afi][safi],
8936 PEER_FLAG_REFLECTOR_CLIENT))
8937 vty_out(vty, " Route-Reflector Client\n");
8938 if (CHECK_FLAG(p->af_flags[afi][safi],
8939 PEER_FLAG_RSERVER_CLIENT))
8940 vty_out(vty, " Route-Server Client\n");
8941 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8942 vty_out(vty,
8943 " Inbound soft reconfiguration allowed\n");
8944
8945 if (CHECK_FLAG(p->af_flags[afi][safi],
8946 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8947 vty_out(vty,
8948 " Private AS numbers (all) replaced in updates to this neighbor\n");
8949 else if (CHECK_FLAG(p->af_flags[afi][safi],
8950 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8951 vty_out(vty,
8952 " Private AS numbers replaced in updates to this neighbor\n");
8953 else if (CHECK_FLAG(p->af_flags[afi][safi],
8954 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8955 vty_out(vty,
8956 " Private AS numbers (all) removed in updates to this neighbor\n");
8957 else if (CHECK_FLAG(p->af_flags[afi][safi],
8958 PEER_FLAG_REMOVE_PRIVATE_AS))
8959 vty_out(vty,
8960 " Private AS numbers removed in updates to this neighbor\n");
8961
8962 if (p->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
8963 vty_out(vty, " %s\n",
8964 bgp_addpath_names(p->addpath_type[afi][safi])
8965 ->human_description);
8966
8967 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8968 vty_out(vty,
8969 " Override ASNs in outbound updates if aspath equals remote-as\n");
8970
8971 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8972 || CHECK_FLAG(p->af_flags[afi][safi],
8973 PEER_FLAG_FORCE_NEXTHOP_SELF))
8974 vty_out(vty, " NEXT_HOP is always this router\n");
8975 if (CHECK_FLAG(p->af_flags[afi][safi],
8976 PEER_FLAG_AS_PATH_UNCHANGED))
8977 vty_out(vty,
8978 " AS_PATH is propagated unchanged to this neighbor\n");
8979 if (CHECK_FLAG(p->af_flags[afi][safi],
8980 PEER_FLAG_NEXTHOP_UNCHANGED))
8981 vty_out(vty,
8982 " NEXT_HOP is propagated unchanged to this neighbor\n");
8983 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8984 vty_out(vty,
8985 " MED is propagated unchanged to this neighbor\n");
8986 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8987 || CHECK_FLAG(p->af_flags[afi][safi],
8988 PEER_FLAG_SEND_EXT_COMMUNITY)
8989 || CHECK_FLAG(p->af_flags[afi][safi],
8990 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8991 vty_out(vty,
8992 " Community attribute sent to this neighbor");
8993 if (CHECK_FLAG(p->af_flags[afi][safi],
8994 PEER_FLAG_SEND_COMMUNITY)
8995 && CHECK_FLAG(p->af_flags[afi][safi],
8996 PEER_FLAG_SEND_EXT_COMMUNITY)
8997 && CHECK_FLAG(p->af_flags[afi][safi],
8998 PEER_FLAG_SEND_LARGE_COMMUNITY))
8999 vty_out(vty, "(all)\n");
9000 else if (CHECK_FLAG(p->af_flags[afi][safi],
9001 PEER_FLAG_SEND_LARGE_COMMUNITY))
9002 vty_out(vty, "(large)\n");
9003 else if (CHECK_FLAG(p->af_flags[afi][safi],
9004 PEER_FLAG_SEND_EXT_COMMUNITY))
9005 vty_out(vty, "(extended)\n");
9006 else
9007 vty_out(vty, "(standard)\n");
9008 }
9009 if (CHECK_FLAG(p->af_flags[afi][safi],
9010 PEER_FLAG_DEFAULT_ORIGINATE)) {
9011 vty_out(vty, " Default information originate,");
9012
9013 if (p->default_rmap[afi][safi].name)
9014 vty_out(vty, " default route-map %s%s,",
9015 p->default_rmap[afi][safi].map ? "*"
9016 : "",
9017 p->default_rmap[afi][safi].name);
9018 if (paf && PAF_SUBGRP(paf)
9019 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
9020 SUBGRP_STATUS_DEFAULT_ORIGINATE))
9021 vty_out(vty, " default sent\n");
9022 else
9023 vty_out(vty, " default not sent\n");
9024 }
9025
9026 /* advertise-vni-all */
9027 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
9028 if (is_evpn_enabled())
9029 vty_out(vty, " advertise-all-vni\n");
9030 }
9031
9032 if (filter->plist[FILTER_IN].name
9033 || filter->dlist[FILTER_IN].name
9034 || filter->aslist[FILTER_IN].name
9035 || filter->map[RMAP_IN].name)
9036 vty_out(vty, " Inbound path policy configured\n");
9037 if (filter->plist[FILTER_OUT].name
9038 || filter->dlist[FILTER_OUT].name
9039 || filter->aslist[FILTER_OUT].name
9040 || filter->map[RMAP_OUT].name || filter->usmap.name)
9041 vty_out(vty, " Outbound path policy configured\n");
9042
9043 /* prefix-list */
9044 if (filter->plist[FILTER_IN].name)
9045 vty_out(vty,
9046 " Incoming update prefix filter list is %s%s\n",
9047 filter->plist[FILTER_IN].plist ? "*" : "",
9048 filter->plist[FILTER_IN].name);
9049 if (filter->plist[FILTER_OUT].name)
9050 vty_out(vty,
9051 " Outgoing update prefix filter list is %s%s\n",
9052 filter->plist[FILTER_OUT].plist ? "*" : "",
9053 filter->plist[FILTER_OUT].name);
9054
9055 /* distribute-list */
9056 if (filter->dlist[FILTER_IN].name)
9057 vty_out(vty,
9058 " Incoming update network filter list is %s%s\n",
9059 filter->dlist[FILTER_IN].alist ? "*" : "",
9060 filter->dlist[FILTER_IN].name);
9061 if (filter->dlist[FILTER_OUT].name)
9062 vty_out(vty,
9063 " Outgoing update network filter list is %s%s\n",
9064 filter->dlist[FILTER_OUT].alist ? "*" : "",
9065 filter->dlist[FILTER_OUT].name);
9066
9067 /* filter-list. */
9068 if (filter->aslist[FILTER_IN].name)
9069 vty_out(vty,
9070 " Incoming update AS path filter list is %s%s\n",
9071 filter->aslist[FILTER_IN].aslist ? "*" : "",
9072 filter->aslist[FILTER_IN].name);
9073 if (filter->aslist[FILTER_OUT].name)
9074 vty_out(vty,
9075 " Outgoing update AS path filter list is %s%s\n",
9076 filter->aslist[FILTER_OUT].aslist ? "*" : "",
9077 filter->aslist[FILTER_OUT].name);
9078
9079 /* route-map. */
9080 if (filter->map[RMAP_IN].name)
9081 vty_out(vty,
9082 " Route map for incoming advertisements is %s%s\n",
9083 filter->map[RMAP_IN].map ? "*" : "",
9084 filter->map[RMAP_IN].name);
9085 if (filter->map[RMAP_OUT].name)
9086 vty_out(vty,
9087 " Route map for outgoing advertisements is %s%s\n",
9088 filter->map[RMAP_OUT].map ? "*" : "",
9089 filter->map[RMAP_OUT].name);
9090
9091 /* unsuppress-map */
9092 if (filter->usmap.name)
9093 vty_out(vty,
9094 " Route map for selective unsuppress is %s%s\n",
9095 filter->usmap.map ? "*" : "",
9096 filter->usmap.name);
9097
9098 /* Receive prefix count */
9099 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
9100
9101 /* Maximum prefix */
9102 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
9103 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
9104 p->pmax[afi][safi],
9105 CHECK_FLAG(p->af_flags[afi][safi],
9106 PEER_FLAG_MAX_PREFIX_WARNING)
9107 ? " (warning-only)"
9108 : "");
9109 vty_out(vty, " Threshold for warning message %d%%",
9110 p->pmax_threshold[afi][safi]);
9111 if (p->pmax_restart[afi][safi])
9112 vty_out(vty, ", restart interval %d min",
9113 p->pmax_restart[afi][safi]);
9114 vty_out(vty, "\n");
9115 }
9116
9117 vty_out(vty, "\n");
9118 }
9119 }
9120
9121 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9122 json_object *json)
9123 {
9124 struct bgp *bgp;
9125 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9126 char timebuf[BGP_UPTIME_LEN];
9127 char dn_flag[2];
9128 const char *subcode_str;
9129 const char *code_str;
9130 afi_t afi;
9131 safi_t safi;
9132 uint16_t i;
9133 uint8_t *msg;
9134 json_object *json_neigh = NULL;
9135 time_t epoch_tbuf;
9136
9137 bgp = p->bgp;
9138
9139 if (use_json)
9140 json_neigh = json_object_new_object();
9141
9142 memset(dn_flag, '\0', sizeof(dn_flag));
9143 if (!p->conf_if && peer_dynamic_neighbor(p))
9144 dn_flag[0] = '*';
9145
9146 if (!use_json) {
9147 if (p->conf_if) /* Configured interface name. */
9148 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9149 BGP_PEER_SU_UNSPEC(p)
9150 ? "None"
9151 : sockunion2str(&p->su, buf,
9152 SU_ADDRSTRLEN));
9153 else /* Configured IP address. */
9154 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9155 p->host);
9156 }
9157
9158 if (use_json) {
9159 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9160 json_object_string_add(json_neigh, "bgpNeighborAddr",
9161 "none");
9162 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9163 json_object_string_add(
9164 json_neigh, "bgpNeighborAddr",
9165 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9166
9167 json_object_int_add(json_neigh, "remoteAs", p->as);
9168
9169 if (p->change_local_as)
9170 json_object_int_add(json_neigh, "localAs",
9171 p->change_local_as);
9172 else
9173 json_object_int_add(json_neigh, "localAs", p->local_as);
9174
9175 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9176 json_object_boolean_true_add(json_neigh,
9177 "localAsNoPrepend");
9178
9179 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9180 json_object_boolean_true_add(json_neigh,
9181 "localAsReplaceAs");
9182 } else {
9183 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9184 || (p->as_type == AS_INTERNAL))
9185 vty_out(vty, "remote AS %u, ", p->as);
9186 else
9187 vty_out(vty, "remote AS Unspecified, ");
9188 vty_out(vty, "local AS %u%s%s, ",
9189 p->change_local_as ? p->change_local_as : p->local_as,
9190 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9191 ? " no-prepend"
9192 : "",
9193 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9194 ? " replace-as"
9195 : "");
9196 }
9197 /* peer type internal, external, confed-internal or confed-external */
9198 if (p->as == p->local_as) {
9199 if (use_json) {
9200 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9201 json_object_boolean_true_add(
9202 json_neigh, "nbrConfedInternalLink");
9203 else
9204 json_object_boolean_true_add(json_neigh,
9205 "nbrInternalLink");
9206 } else {
9207 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9208 vty_out(vty, "confed-internal link\n");
9209 else
9210 vty_out(vty, "internal link\n");
9211 }
9212 } else {
9213 if (use_json) {
9214 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9215 json_object_boolean_true_add(
9216 json_neigh, "nbrConfedExternalLink");
9217 else
9218 json_object_boolean_true_add(json_neigh,
9219 "nbrExternalLink");
9220 } else {
9221 if (bgp_confederation_peers_check(bgp, p->as))
9222 vty_out(vty, "confed-external link\n");
9223 else
9224 vty_out(vty, "external link\n");
9225 }
9226 }
9227
9228 /* Description. */
9229 if (p->desc) {
9230 if (use_json)
9231 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9232 else
9233 vty_out(vty, " Description: %s\n", p->desc);
9234 }
9235
9236 if (p->hostname) {
9237 if (use_json) {
9238 if (p->hostname)
9239 json_object_string_add(json_neigh, "hostname",
9240 p->hostname);
9241
9242 if (p->domainname)
9243 json_object_string_add(json_neigh, "domainname",
9244 p->domainname);
9245 } else {
9246 if (p->domainname && (p->domainname[0] != '\0'))
9247 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9248 p->domainname);
9249 else
9250 vty_out(vty, "Hostname: %s\n", p->hostname);
9251 }
9252 }
9253
9254 /* Peer-group */
9255 if (p->group) {
9256 if (use_json) {
9257 json_object_string_add(json_neigh, "peerGroup",
9258 p->group->name);
9259
9260 if (dn_flag[0]) {
9261 struct prefix prefix, *range = NULL;
9262
9263 sockunion2hostprefix(&(p->su), &prefix);
9264 range = peer_group_lookup_dynamic_neighbor_range(
9265 p->group, &prefix);
9266
9267 if (range) {
9268 prefix2str(range, buf1, sizeof(buf1));
9269 json_object_string_add(
9270 json_neigh,
9271 "peerSubnetRangeGroup", buf1);
9272 }
9273 }
9274 } else {
9275 vty_out(vty,
9276 " Member of peer-group %s for session parameters\n",
9277 p->group->name);
9278
9279 if (dn_flag[0]) {
9280 struct prefix prefix, *range = NULL;
9281
9282 sockunion2hostprefix(&(p->su), &prefix);
9283 range = peer_group_lookup_dynamic_neighbor_range(
9284 p->group, &prefix);
9285
9286 if (range) {
9287 prefix2str(range, buf1, sizeof(buf1));
9288 vty_out(vty,
9289 " Belongs to the subnet range group: %s\n",
9290 buf1);
9291 }
9292 }
9293 }
9294 }
9295
9296 if (use_json) {
9297 /* Administrative shutdown. */
9298 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9299 json_object_boolean_true_add(json_neigh,
9300 "adminShutDown");
9301
9302 /* BGP Version. */
9303 json_object_int_add(json_neigh, "bgpVersion", 4);
9304 json_object_string_add(
9305 json_neigh, "remoteRouterId",
9306 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9307 json_object_string_add(
9308 json_neigh, "localRouterId",
9309 inet_ntop(AF_INET, &bgp->router_id, buf1,
9310 sizeof(buf1)));
9311
9312 /* Confederation */
9313 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9314 && bgp_confederation_peers_check(bgp, p->as))
9315 json_object_boolean_true_add(json_neigh,
9316 "nbrCommonAdmin");
9317
9318 /* Status. */
9319 json_object_string_add(
9320 json_neigh, "bgpState",
9321 lookup_msg(bgp_status_msg, p->status, NULL));
9322
9323 if (p->status == Established) {
9324 time_t uptime;
9325
9326 uptime = bgp_clock();
9327 uptime -= p->uptime;
9328 epoch_tbuf = time(NULL) - uptime;
9329
9330 #if CONFDATE > 20200101
9331 CPP_NOTICE(
9332 "bgpTimerUp should be deprecated and can be removed now");
9333 #endif
9334 /*
9335 * bgpTimerUp was miliseconds that was accurate
9336 * up to 1 day, then the value returned
9337 * became garbage. So in order to provide
9338 * some level of backwards compatability,
9339 * we still provde the data, but now
9340 * we are returning the correct value
9341 * and also adding a new bgpTimerUpMsec
9342 * which will allow us to deprecate
9343 * this eventually
9344 */
9345 json_object_int_add(json_neigh, "bgpTimerUp",
9346 uptime * 1000);
9347 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9348 uptime * 1000);
9349 json_object_string_add(json_neigh, "bgpTimerUpString",
9350 peer_uptime(p->uptime, timebuf,
9351 BGP_UPTIME_LEN, 0,
9352 NULL));
9353 json_object_int_add(json_neigh,
9354 "bgpTimerUpEstablishedEpoch",
9355 epoch_tbuf);
9356 }
9357
9358 else if (p->status == Active) {
9359 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9360 json_object_string_add(json_neigh, "bgpStateIs",
9361 "passive");
9362 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9363 json_object_string_add(json_neigh, "bgpStateIs",
9364 "passiveNSF");
9365 }
9366
9367 /* read timer */
9368 time_t uptime;
9369 struct tm *tm;
9370
9371 uptime = bgp_clock();
9372 uptime -= p->readtime;
9373 tm = gmtime(&uptime);
9374 json_object_int_add(json_neigh, "bgpTimerLastRead",
9375 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9376 + (tm->tm_hour * 3600000));
9377
9378 uptime = bgp_clock();
9379 uptime -= p->last_write;
9380 tm = gmtime(&uptime);
9381 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9382 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9383 + (tm->tm_hour * 3600000));
9384
9385 uptime = bgp_clock();
9386 uptime -= p->update_time;
9387 tm = gmtime(&uptime);
9388 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9389 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9390 + (tm->tm_hour * 3600000));
9391
9392 /* Configured timer values. */
9393 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9394 p->v_holdtime * 1000);
9395 json_object_int_add(json_neigh,
9396 "bgpTimerKeepAliveIntervalMsecs",
9397 p->v_keepalive * 1000);
9398 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9399 json_object_int_add(json_neigh,
9400 "bgpTimerConfiguredHoldTimeMsecs",
9401 p->holdtime * 1000);
9402 json_object_int_add(
9403 json_neigh,
9404 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9405 p->keepalive * 1000);
9406 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9407 || (bgp->default_keepalive
9408 != BGP_DEFAULT_KEEPALIVE)) {
9409 json_object_int_add(json_neigh,
9410 "bgpTimerConfiguredHoldTimeMsecs",
9411 bgp->default_holdtime);
9412 json_object_int_add(
9413 json_neigh,
9414 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9415 bgp->default_keepalive);
9416 }
9417 } else {
9418 /* Administrative shutdown. */
9419 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9420 vty_out(vty, " Administratively shut down\n");
9421
9422 /* BGP Version. */
9423 vty_out(vty, " BGP version 4");
9424 vty_out(vty, ", remote router ID %s",
9425 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9426 vty_out(vty, ", local router ID %s\n",
9427 inet_ntop(AF_INET, &bgp->router_id, buf1,
9428 sizeof(buf1)));
9429
9430 /* Confederation */
9431 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9432 && bgp_confederation_peers_check(bgp, p->as))
9433 vty_out(vty,
9434 " Neighbor under common administration\n");
9435
9436 /* Status. */
9437 vty_out(vty, " BGP state = %s",
9438 lookup_msg(bgp_status_msg, p->status, NULL));
9439
9440 if (p->status == Established)
9441 vty_out(vty, ", up for %8s",
9442 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9443 0, NULL));
9444
9445 else if (p->status == Active) {
9446 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9447 vty_out(vty, " (passive)");
9448 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9449 vty_out(vty, " (NSF passive)");
9450 }
9451 vty_out(vty, "\n");
9452
9453 /* read timer */
9454 vty_out(vty, " Last read %s",
9455 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9456 NULL));
9457 vty_out(vty, ", Last write %s\n",
9458 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9459 NULL));
9460
9461 /* Configured timer values. */
9462 vty_out(vty,
9463 " Hold time is %d, keepalive interval is %d seconds\n",
9464 p->v_holdtime, p->v_keepalive);
9465 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9466 vty_out(vty, " Configured hold time is %d",
9467 p->holdtime);
9468 vty_out(vty, ", keepalive interval is %d seconds\n",
9469 p->keepalive);
9470 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9471 || (bgp->default_keepalive
9472 != BGP_DEFAULT_KEEPALIVE)) {
9473 vty_out(vty, " Configured hold time is %d",
9474 bgp->default_holdtime);
9475 vty_out(vty, ", keepalive interval is %d seconds\n",
9476 bgp->default_keepalive);
9477 }
9478 }
9479 /* Capability. */
9480 if (p->status == Established) {
9481 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9482 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9483 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9484 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9485 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9486 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9487 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9488 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9489 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9490 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9491 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9492 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9493 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9494 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9495 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9496 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9497 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9498 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9499 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9500 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9501 if (use_json) {
9502 json_object *json_cap = NULL;
9503
9504 json_cap = json_object_new_object();
9505
9506 /* AS4 */
9507 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9508 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9509 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9510 && CHECK_FLAG(p->cap,
9511 PEER_CAP_AS4_RCV))
9512 json_object_string_add(
9513 json_cap, "4byteAs",
9514 "advertisedAndReceived");
9515 else if (CHECK_FLAG(p->cap,
9516 PEER_CAP_AS4_ADV))
9517 json_object_string_add(
9518 json_cap, "4byteAs",
9519 "advertised");
9520 else if (CHECK_FLAG(p->cap,
9521 PEER_CAP_AS4_RCV))
9522 json_object_string_add(
9523 json_cap, "4byteAs",
9524 "received");
9525 }
9526
9527 /* AddPath */
9528 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9529 || CHECK_FLAG(p->cap,
9530 PEER_CAP_ADDPATH_ADV)) {
9531 json_object *json_add = NULL;
9532 const char *print_store;
9533
9534 json_add = json_object_new_object();
9535
9536 FOREACH_AFI_SAFI (afi, safi) {
9537 json_object *json_sub = NULL;
9538 json_sub =
9539 json_object_new_object();
9540 print_store = afi_safi_print(
9541 afi, safi);
9542
9543 if (CHECK_FLAG(
9544 p->af_cap[afi]
9545 [safi],
9546 PEER_CAP_ADDPATH_AF_TX_ADV)
9547 || CHECK_FLAG(
9548 p->af_cap[afi]
9549 [safi],
9550 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9551 if (CHECK_FLAG(
9552 p->af_cap
9553 [afi]
9554 [safi],
9555 PEER_CAP_ADDPATH_AF_TX_ADV)
9556 && CHECK_FLAG(
9557 p->af_cap
9558 [afi]
9559 [safi],
9560 PEER_CAP_ADDPATH_AF_TX_RCV))
9561 json_object_boolean_true_add(
9562 json_sub,
9563 "txAdvertisedAndReceived");
9564 else if (
9565 CHECK_FLAG(
9566 p->af_cap
9567 [afi]
9568 [safi],
9569 PEER_CAP_ADDPATH_AF_TX_ADV))
9570 json_object_boolean_true_add(
9571 json_sub,
9572 "txAdvertised");
9573 else if (
9574 CHECK_FLAG(
9575 p->af_cap
9576 [afi]
9577 [safi],
9578 PEER_CAP_ADDPATH_AF_TX_RCV))
9579 json_object_boolean_true_add(
9580 json_sub,
9581 "txReceived");
9582 }
9583
9584 if (CHECK_FLAG(
9585 p->af_cap[afi]
9586 [safi],
9587 PEER_CAP_ADDPATH_AF_RX_ADV)
9588 || CHECK_FLAG(
9589 p->af_cap[afi]
9590 [safi],
9591 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9592 if (CHECK_FLAG(
9593 p->af_cap
9594 [afi]
9595 [safi],
9596 PEER_CAP_ADDPATH_AF_RX_ADV)
9597 && CHECK_FLAG(
9598 p->af_cap
9599 [afi]
9600 [safi],
9601 PEER_CAP_ADDPATH_AF_RX_RCV))
9602 json_object_boolean_true_add(
9603 json_sub,
9604 "rxAdvertisedAndReceived");
9605 else if (
9606 CHECK_FLAG(
9607 p->af_cap
9608 [afi]
9609 [safi],
9610 PEER_CAP_ADDPATH_AF_RX_ADV))
9611 json_object_boolean_true_add(
9612 json_sub,
9613 "rxAdvertised");
9614 else if (
9615 CHECK_FLAG(
9616 p->af_cap
9617 [afi]
9618 [safi],
9619 PEER_CAP_ADDPATH_AF_RX_RCV))
9620 json_object_boolean_true_add(
9621 json_sub,
9622 "rxReceived");
9623 }
9624
9625 if (CHECK_FLAG(
9626 p->af_cap[afi]
9627 [safi],
9628 PEER_CAP_ADDPATH_AF_TX_ADV)
9629 || CHECK_FLAG(
9630 p->af_cap[afi]
9631 [safi],
9632 PEER_CAP_ADDPATH_AF_TX_RCV)
9633 || CHECK_FLAG(
9634 p->af_cap[afi]
9635 [safi],
9636 PEER_CAP_ADDPATH_AF_RX_ADV)
9637 || CHECK_FLAG(
9638 p->af_cap[afi]
9639 [safi],
9640 PEER_CAP_ADDPATH_AF_RX_RCV))
9641 json_object_object_add(
9642 json_add,
9643 print_store,
9644 json_sub);
9645 else
9646 json_object_free(
9647 json_sub);
9648 }
9649
9650 json_object_object_add(
9651 json_cap, "addPath", json_add);
9652 }
9653
9654 /* Dynamic */
9655 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9656 || CHECK_FLAG(p->cap,
9657 PEER_CAP_DYNAMIC_ADV)) {
9658 if (CHECK_FLAG(p->cap,
9659 PEER_CAP_DYNAMIC_ADV)
9660 && CHECK_FLAG(p->cap,
9661 PEER_CAP_DYNAMIC_RCV))
9662 json_object_string_add(
9663 json_cap, "dynamic",
9664 "advertisedAndReceived");
9665 else if (CHECK_FLAG(
9666 p->cap,
9667 PEER_CAP_DYNAMIC_ADV))
9668 json_object_string_add(
9669 json_cap, "dynamic",
9670 "advertised");
9671 else if (CHECK_FLAG(
9672 p->cap,
9673 PEER_CAP_DYNAMIC_RCV))
9674 json_object_string_add(
9675 json_cap, "dynamic",
9676 "received");
9677 }
9678
9679 /* Extended nexthop */
9680 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9681 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9682 json_object *json_nxt = NULL;
9683 const char *print_store;
9684
9685
9686 if (CHECK_FLAG(p->cap,
9687 PEER_CAP_ENHE_ADV)
9688 && CHECK_FLAG(p->cap,
9689 PEER_CAP_ENHE_RCV))
9690 json_object_string_add(
9691 json_cap,
9692 "extendedNexthop",
9693 "advertisedAndReceived");
9694 else if (CHECK_FLAG(p->cap,
9695 PEER_CAP_ENHE_ADV))
9696 json_object_string_add(
9697 json_cap,
9698 "extendedNexthop",
9699 "advertised");
9700 else if (CHECK_FLAG(p->cap,
9701 PEER_CAP_ENHE_RCV))
9702 json_object_string_add(
9703 json_cap,
9704 "extendedNexthop",
9705 "received");
9706
9707 if (CHECK_FLAG(p->cap,
9708 PEER_CAP_ENHE_RCV)) {
9709 json_nxt =
9710 json_object_new_object();
9711
9712 for (safi = SAFI_UNICAST;
9713 safi < SAFI_MAX; safi++) {
9714 if (CHECK_FLAG(
9715 p->af_cap
9716 [AFI_IP]
9717 [safi],
9718 PEER_CAP_ENHE_AF_RCV)) {
9719 print_store = afi_safi_print(
9720 AFI_IP,
9721 safi);
9722 json_object_string_add(
9723 json_nxt,
9724 print_store,
9725 "received");
9726 }
9727 }
9728 json_object_object_add(
9729 json_cap,
9730 "extendedNexthopFamililesByPeer",
9731 json_nxt);
9732 }
9733 }
9734
9735 /* Route Refresh */
9736 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9737 || CHECK_FLAG(p->cap,
9738 PEER_CAP_REFRESH_NEW_RCV)
9739 || CHECK_FLAG(p->cap,
9740 PEER_CAP_REFRESH_OLD_RCV)) {
9741 if (CHECK_FLAG(p->cap,
9742 PEER_CAP_REFRESH_ADV)
9743 && (CHECK_FLAG(
9744 p->cap,
9745 PEER_CAP_REFRESH_NEW_RCV)
9746 || CHECK_FLAG(
9747 p->cap,
9748 PEER_CAP_REFRESH_OLD_RCV))) {
9749 if (CHECK_FLAG(
9750 p->cap,
9751 PEER_CAP_REFRESH_OLD_RCV)
9752 && CHECK_FLAG(
9753 p->cap,
9754 PEER_CAP_REFRESH_NEW_RCV))
9755 json_object_string_add(
9756 json_cap,
9757 "routeRefresh",
9758 "advertisedAndReceivedOldNew");
9759 else {
9760 if (CHECK_FLAG(
9761 p->cap,
9762 PEER_CAP_REFRESH_OLD_RCV))
9763 json_object_string_add(
9764 json_cap,
9765 "routeRefresh",
9766 "advertisedAndReceivedOld");
9767 else
9768 json_object_string_add(
9769 json_cap,
9770 "routeRefresh",
9771 "advertisedAndReceivedNew");
9772 }
9773 } else if (
9774 CHECK_FLAG(
9775 p->cap,
9776 PEER_CAP_REFRESH_ADV))
9777 json_object_string_add(
9778 json_cap,
9779 "routeRefresh",
9780 "advertised");
9781 else if (
9782 CHECK_FLAG(
9783 p->cap,
9784 PEER_CAP_REFRESH_NEW_RCV)
9785 || CHECK_FLAG(
9786 p->cap,
9787 PEER_CAP_REFRESH_OLD_RCV))
9788 json_object_string_add(
9789 json_cap,
9790 "routeRefresh",
9791 "received");
9792 }
9793
9794 /* Multiprotocol Extensions */
9795 json_object *json_multi = NULL;
9796 json_multi = json_object_new_object();
9797
9798 FOREACH_AFI_SAFI (afi, safi) {
9799 if (p->afc_adv[afi][safi]
9800 || p->afc_recv[afi][safi]) {
9801 json_object *json_exten = NULL;
9802 json_exten =
9803 json_object_new_object();
9804
9805 if (p->afc_adv[afi][safi]
9806 && p->afc_recv[afi][safi])
9807 json_object_boolean_true_add(
9808 json_exten,
9809 "advertisedAndReceived");
9810 else if (p->afc_adv[afi][safi])
9811 json_object_boolean_true_add(
9812 json_exten,
9813 "advertised");
9814 else if (p->afc_recv[afi][safi])
9815 json_object_boolean_true_add(
9816 json_exten,
9817 "received");
9818
9819 json_object_object_add(
9820 json_multi,
9821 afi_safi_print(afi,
9822 safi),
9823 json_exten);
9824 }
9825 }
9826 json_object_object_add(
9827 json_cap, "multiprotocolExtensions",
9828 json_multi);
9829
9830 /* Hostname capabilities */
9831 json_object *json_hname = NULL;
9832
9833 json_hname = json_object_new_object();
9834
9835 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9836 json_object_string_add(
9837 json_hname, "advHostName",
9838 bgp->peer_self->hostname
9839 ? bgp->peer_self
9840 ->hostname
9841 : "n/a");
9842 json_object_string_add(
9843 json_hname, "advDomainName",
9844 bgp->peer_self->domainname
9845 ? bgp->peer_self
9846 ->domainname
9847 : "n/a");
9848 }
9849
9850
9851 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9852 json_object_string_add(
9853 json_hname, "rcvHostName",
9854 p->hostname ? p->hostname
9855 : "n/a");
9856 json_object_string_add(
9857 json_hname, "rcvDomainName",
9858 p->domainname ? p->domainname
9859 : "n/a");
9860 }
9861
9862 json_object_object_add(json_cap, "hostName",
9863 json_hname);
9864
9865 /* Gracefull Restart */
9866 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9867 || CHECK_FLAG(p->cap,
9868 PEER_CAP_RESTART_ADV)) {
9869 if (CHECK_FLAG(p->cap,
9870 PEER_CAP_RESTART_ADV)
9871 && CHECK_FLAG(p->cap,
9872 PEER_CAP_RESTART_RCV))
9873 json_object_string_add(
9874 json_cap,
9875 "gracefulRestart",
9876 "advertisedAndReceived");
9877 else if (CHECK_FLAG(
9878 p->cap,
9879 PEER_CAP_RESTART_ADV))
9880 json_object_string_add(
9881 json_cap,
9882 "gracefulRestartCapability",
9883 "advertised");
9884 else if (CHECK_FLAG(
9885 p->cap,
9886 PEER_CAP_RESTART_RCV))
9887 json_object_string_add(
9888 json_cap,
9889 "gracefulRestartCapability",
9890 "received");
9891
9892 if (CHECK_FLAG(p->cap,
9893 PEER_CAP_RESTART_RCV)) {
9894 int restart_af_count = 0;
9895 json_object *json_restart =
9896 NULL;
9897 json_restart =
9898 json_object_new_object();
9899
9900 json_object_int_add(
9901 json_cap,
9902 "gracefulRestartRemoteTimerMsecs",
9903 p->v_gr_restart * 1000);
9904
9905 FOREACH_AFI_SAFI (afi, safi) {
9906 if (CHECK_FLAG(
9907 p->af_cap
9908 [afi]
9909 [safi],
9910 PEER_CAP_RESTART_AF_RCV)) {
9911 json_object *
9912 json_sub =
9913 NULL;
9914 json_sub =
9915 json_object_new_object();
9916
9917 if (CHECK_FLAG(
9918 p->af_cap
9919 [afi]
9920 [safi],
9921 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9922 json_object_boolean_true_add(
9923 json_sub,
9924 "preserved");
9925 restart_af_count++;
9926 json_object_object_add(
9927 json_restart,
9928 afi_safi_print(
9929 afi,
9930 safi),
9931 json_sub);
9932 }
9933 }
9934 if (!restart_af_count) {
9935 json_object_string_add(
9936 json_cap,
9937 "addressFamiliesByPeer",
9938 "none");
9939 json_object_free(
9940 json_restart);
9941 } else
9942 json_object_object_add(
9943 json_cap,
9944 "addressFamiliesByPeer",
9945 json_restart);
9946 }
9947 }
9948 json_object_object_add(json_neigh,
9949 "neighborCapabilities",
9950 json_cap);
9951 } else {
9952 vty_out(vty, " Neighbor capabilities:\n");
9953
9954 /* AS4 */
9955 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9956 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9957 vty_out(vty, " 4 Byte AS:");
9958 if (CHECK_FLAG(p->cap,
9959 PEER_CAP_AS4_ADV))
9960 vty_out(vty, " advertised");
9961 if (CHECK_FLAG(p->cap,
9962 PEER_CAP_AS4_RCV))
9963 vty_out(vty, " %sreceived",
9964 CHECK_FLAG(
9965 p->cap,
9966 PEER_CAP_AS4_ADV)
9967 ? "and "
9968 : "");
9969 vty_out(vty, "\n");
9970 }
9971
9972 /* AddPath */
9973 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9974 || CHECK_FLAG(p->cap,
9975 PEER_CAP_ADDPATH_ADV)) {
9976 vty_out(vty, " AddPath:\n");
9977
9978 FOREACH_AFI_SAFI (afi, safi) {
9979 if (CHECK_FLAG(
9980 p->af_cap[afi]
9981 [safi],
9982 PEER_CAP_ADDPATH_AF_TX_ADV)
9983 || CHECK_FLAG(
9984 p->af_cap[afi]
9985 [safi],
9986 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9987 vty_out(vty,
9988 " %s: TX ",
9989 afi_safi_print(
9990 afi,
9991 safi));
9992
9993 if (CHECK_FLAG(
9994 p->af_cap
9995 [afi]
9996 [safi],
9997 PEER_CAP_ADDPATH_AF_TX_ADV))
9998 vty_out(vty,
9999 "advertised %s",
10000 afi_safi_print(
10001 afi,
10002 safi));
10003
10004 if (CHECK_FLAG(
10005 p->af_cap
10006 [afi]
10007 [safi],
10008 PEER_CAP_ADDPATH_AF_TX_RCV))
10009 vty_out(vty,
10010 "%sreceived",
10011 CHECK_FLAG(
10012 p->af_cap
10013 [afi]
10014 [safi],
10015 PEER_CAP_ADDPATH_AF_TX_ADV)
10016 ? " and "
10017 : "");
10018
10019 vty_out(vty, "\n");
10020 }
10021
10022 if (CHECK_FLAG(
10023 p->af_cap[afi]
10024 [safi],
10025 PEER_CAP_ADDPATH_AF_RX_ADV)
10026 || CHECK_FLAG(
10027 p->af_cap[afi]
10028 [safi],
10029 PEER_CAP_ADDPATH_AF_RX_RCV)) {
10030 vty_out(vty,
10031 " %s: RX ",
10032 afi_safi_print(
10033 afi,
10034 safi));
10035
10036 if (CHECK_FLAG(
10037 p->af_cap
10038 [afi]
10039 [safi],
10040 PEER_CAP_ADDPATH_AF_RX_ADV))
10041 vty_out(vty,
10042 "advertised %s",
10043 afi_safi_print(
10044 afi,
10045 safi));
10046
10047 if (CHECK_FLAG(
10048 p->af_cap
10049 [afi]
10050 [safi],
10051 PEER_CAP_ADDPATH_AF_RX_RCV))
10052 vty_out(vty,
10053 "%sreceived",
10054 CHECK_FLAG(
10055 p->af_cap
10056 [afi]
10057 [safi],
10058 PEER_CAP_ADDPATH_AF_RX_ADV)
10059 ? " and "
10060 : "");
10061
10062 vty_out(vty, "\n");
10063 }
10064 }
10065 }
10066
10067 /* Dynamic */
10068 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
10069 || CHECK_FLAG(p->cap,
10070 PEER_CAP_DYNAMIC_ADV)) {
10071 vty_out(vty, " Dynamic:");
10072 if (CHECK_FLAG(p->cap,
10073 PEER_CAP_DYNAMIC_ADV))
10074 vty_out(vty, " advertised");
10075 if (CHECK_FLAG(p->cap,
10076 PEER_CAP_DYNAMIC_RCV))
10077 vty_out(vty, " %sreceived",
10078 CHECK_FLAG(
10079 p->cap,
10080 PEER_CAP_DYNAMIC_ADV)
10081 ? "and "
10082 : "");
10083 vty_out(vty, "\n");
10084 }
10085
10086 /* Extended nexthop */
10087 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
10088 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
10089 vty_out(vty, " Extended nexthop:");
10090 if (CHECK_FLAG(p->cap,
10091 PEER_CAP_ENHE_ADV))
10092 vty_out(vty, " advertised");
10093 if (CHECK_FLAG(p->cap,
10094 PEER_CAP_ENHE_RCV))
10095 vty_out(vty, " %sreceived",
10096 CHECK_FLAG(
10097 p->cap,
10098 PEER_CAP_ENHE_ADV)
10099 ? "and "
10100 : "");
10101 vty_out(vty, "\n");
10102
10103 if (CHECK_FLAG(p->cap,
10104 PEER_CAP_ENHE_RCV)) {
10105 vty_out(vty,
10106 " Address families by peer:\n ");
10107 for (safi = SAFI_UNICAST;
10108 safi < SAFI_MAX; safi++)
10109 if (CHECK_FLAG(
10110 p->af_cap
10111 [AFI_IP]
10112 [safi],
10113 PEER_CAP_ENHE_AF_RCV))
10114 vty_out(vty,
10115 " %s\n",
10116 afi_safi_print(
10117 AFI_IP,
10118 safi));
10119 }
10120 }
10121
10122 /* Route Refresh */
10123 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10124 || CHECK_FLAG(p->cap,
10125 PEER_CAP_REFRESH_NEW_RCV)
10126 || CHECK_FLAG(p->cap,
10127 PEER_CAP_REFRESH_OLD_RCV)) {
10128 vty_out(vty, " Route refresh:");
10129 if (CHECK_FLAG(p->cap,
10130 PEER_CAP_REFRESH_ADV))
10131 vty_out(vty, " advertised");
10132 if (CHECK_FLAG(p->cap,
10133 PEER_CAP_REFRESH_NEW_RCV)
10134 || CHECK_FLAG(
10135 p->cap,
10136 PEER_CAP_REFRESH_OLD_RCV))
10137 vty_out(vty, " %sreceived(%s)",
10138 CHECK_FLAG(
10139 p->cap,
10140 PEER_CAP_REFRESH_ADV)
10141 ? "and "
10142 : "",
10143 (CHECK_FLAG(
10144 p->cap,
10145 PEER_CAP_REFRESH_OLD_RCV)
10146 && CHECK_FLAG(
10147 p->cap,
10148 PEER_CAP_REFRESH_NEW_RCV))
10149 ? "old & new"
10150 : CHECK_FLAG(
10151 p->cap,
10152 PEER_CAP_REFRESH_OLD_RCV)
10153 ? "old"
10154 : "new");
10155
10156 vty_out(vty, "\n");
10157 }
10158
10159 /* Multiprotocol Extensions */
10160 FOREACH_AFI_SAFI (afi, safi)
10161 if (p->afc_adv[afi][safi]
10162 || p->afc_recv[afi][safi]) {
10163 vty_out(vty,
10164 " Address Family %s:",
10165 afi_safi_print(afi,
10166 safi));
10167 if (p->afc_adv[afi][safi])
10168 vty_out(vty,
10169 " advertised");
10170 if (p->afc_recv[afi][safi])
10171 vty_out(vty,
10172 " %sreceived",
10173 p->afc_adv[afi]
10174 [safi]
10175 ? "and "
10176 : "");
10177 vty_out(vty, "\n");
10178 }
10179
10180 /* Hostname capability */
10181 vty_out(vty, " Hostname Capability:");
10182
10183 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10184 vty_out(vty,
10185 " advertised (name: %s,domain name: %s)",
10186 bgp->peer_self->hostname
10187 ? bgp->peer_self
10188 ->hostname
10189 : "n/a",
10190 bgp->peer_self->domainname
10191 ? bgp->peer_self
10192 ->domainname
10193 : "n/a");
10194 } else {
10195 vty_out(vty, " not advertised");
10196 }
10197
10198 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10199 vty_out(vty,
10200 " received (name: %s,domain name: %s)",
10201 p->hostname ? p->hostname
10202 : "n/a",
10203 p->domainname ? p->domainname
10204 : "n/a");
10205 } else {
10206 vty_out(vty, " not received");
10207 }
10208
10209 vty_out(vty, "\n");
10210
10211 /* Gracefull Restart */
10212 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10213 || CHECK_FLAG(p->cap,
10214 PEER_CAP_RESTART_ADV)) {
10215 vty_out(vty,
10216 " Graceful Restart Capabilty:");
10217 if (CHECK_FLAG(p->cap,
10218 PEER_CAP_RESTART_ADV))
10219 vty_out(vty, " advertised");
10220 if (CHECK_FLAG(p->cap,
10221 PEER_CAP_RESTART_RCV))
10222 vty_out(vty, " %sreceived",
10223 CHECK_FLAG(
10224 p->cap,
10225 PEER_CAP_RESTART_ADV)
10226 ? "and "
10227 : "");
10228 vty_out(vty, "\n");
10229
10230 if (CHECK_FLAG(p->cap,
10231 PEER_CAP_RESTART_RCV)) {
10232 int restart_af_count = 0;
10233
10234 vty_out(vty,
10235 " Remote Restart timer is %d seconds\n",
10236 p->v_gr_restart);
10237 vty_out(vty,
10238 " Address families by peer:\n ");
10239
10240 FOREACH_AFI_SAFI (afi, safi)
10241 if (CHECK_FLAG(
10242 p->af_cap
10243 [afi]
10244 [safi],
10245 PEER_CAP_RESTART_AF_RCV)) {
10246 vty_out(vty,
10247 "%s%s(%s)",
10248 restart_af_count
10249 ? ", "
10250 : "",
10251 afi_safi_print(
10252 afi,
10253 safi),
10254 CHECK_FLAG(
10255 p->af_cap
10256 [afi]
10257 [safi],
10258 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10259 ? "preserved"
10260 : "not preserved");
10261 restart_af_count++;
10262 }
10263 if (!restart_af_count)
10264 vty_out(vty, "none");
10265 vty_out(vty, "\n");
10266 }
10267 }
10268 }
10269 }
10270 }
10271
10272 /* graceful restart information */
10273 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10274 || p->t_gr_stale) {
10275 json_object *json_grace = NULL;
10276 json_object *json_grace_send = NULL;
10277 json_object *json_grace_recv = NULL;
10278 int eor_send_af_count = 0;
10279 int eor_receive_af_count = 0;
10280
10281 if (use_json) {
10282 json_grace = json_object_new_object();
10283 json_grace_send = json_object_new_object();
10284 json_grace_recv = json_object_new_object();
10285
10286 if (p->status == Established) {
10287 FOREACH_AFI_SAFI (afi, safi) {
10288 if (CHECK_FLAG(p->af_sflags[afi][safi],
10289 PEER_STATUS_EOR_SEND)) {
10290 json_object_boolean_true_add(
10291 json_grace_send,
10292 afi_safi_print(afi,
10293 safi));
10294 eor_send_af_count++;
10295 }
10296 }
10297 FOREACH_AFI_SAFI (afi, safi) {
10298 if (CHECK_FLAG(
10299 p->af_sflags[afi][safi],
10300 PEER_STATUS_EOR_RECEIVED)) {
10301 json_object_boolean_true_add(
10302 json_grace_recv,
10303 afi_safi_print(afi,
10304 safi));
10305 eor_receive_af_count++;
10306 }
10307 }
10308 }
10309
10310 json_object_object_add(json_grace, "endOfRibSend",
10311 json_grace_send);
10312 json_object_object_add(json_grace, "endOfRibRecv",
10313 json_grace_recv);
10314
10315 if (p->t_gr_restart)
10316 json_object_int_add(json_grace,
10317 "gracefulRestartTimerMsecs",
10318 thread_timer_remain_second(
10319 p->t_gr_restart)
10320 * 1000);
10321
10322 if (p->t_gr_stale)
10323 json_object_int_add(
10324 json_grace,
10325 "gracefulStalepathTimerMsecs",
10326 thread_timer_remain_second(
10327 p->t_gr_stale)
10328 * 1000);
10329
10330 json_object_object_add(
10331 json_neigh, "gracefulRestartInfo", json_grace);
10332 } else {
10333 vty_out(vty, " Graceful restart information:\n");
10334 if (p->status == Established) {
10335 vty_out(vty, " End-of-RIB send: ");
10336 FOREACH_AFI_SAFI (afi, safi) {
10337 if (CHECK_FLAG(p->af_sflags[afi][safi],
10338 PEER_STATUS_EOR_SEND)) {
10339 vty_out(vty, "%s%s",
10340 eor_send_af_count ? ", "
10341 : "",
10342 afi_safi_print(afi,
10343 safi));
10344 eor_send_af_count++;
10345 }
10346 }
10347 vty_out(vty, "\n");
10348 vty_out(vty, " End-of-RIB received: ");
10349 FOREACH_AFI_SAFI (afi, safi) {
10350 if (CHECK_FLAG(
10351 p->af_sflags[afi][safi],
10352 PEER_STATUS_EOR_RECEIVED)) {
10353 vty_out(vty, "%s%s",
10354 eor_receive_af_count
10355 ? ", "
10356 : "",
10357 afi_safi_print(afi,
10358 safi));
10359 eor_receive_af_count++;
10360 }
10361 }
10362 vty_out(vty, "\n");
10363 }
10364
10365 if (p->t_gr_restart)
10366 vty_out(vty,
10367 " The remaining time of restart timer is %ld\n",
10368 thread_timer_remain_second(
10369 p->t_gr_restart));
10370
10371 if (p->t_gr_stale)
10372 vty_out(vty,
10373 " The remaining time of stalepath timer is %ld\n",
10374 thread_timer_remain_second(
10375 p->t_gr_stale));
10376 }
10377 }
10378 if (use_json) {
10379 json_object *json_stat = NULL;
10380 json_stat = json_object_new_object();
10381 /* Packet counts. */
10382 json_object_int_add(json_stat, "depthInq", 0);
10383 json_object_int_add(json_stat, "depthOutq",
10384 (unsigned long)p->obuf->count);
10385 json_object_int_add(json_stat, "opensSent",
10386 atomic_load_explicit(&p->open_out,
10387 memory_order_relaxed));
10388 json_object_int_add(json_stat, "opensRecv",
10389 atomic_load_explicit(&p->open_in,
10390 memory_order_relaxed));
10391 json_object_int_add(json_stat, "notificationsSent",
10392 atomic_load_explicit(&p->notify_out,
10393 memory_order_relaxed));
10394 json_object_int_add(json_stat, "notificationsRecv",
10395 atomic_load_explicit(&p->notify_in,
10396 memory_order_relaxed));
10397 json_object_int_add(json_stat, "updatesSent",
10398 atomic_load_explicit(&p->update_out,
10399 memory_order_relaxed));
10400 json_object_int_add(json_stat, "updatesRecv",
10401 atomic_load_explicit(&p->update_in,
10402 memory_order_relaxed));
10403 json_object_int_add(json_stat, "keepalivesSent",
10404 atomic_load_explicit(&p->keepalive_out,
10405 memory_order_relaxed));
10406 json_object_int_add(json_stat, "keepalivesRecv",
10407 atomic_load_explicit(&p->keepalive_in,
10408 memory_order_relaxed));
10409 json_object_int_add(json_stat, "routeRefreshSent",
10410 atomic_load_explicit(&p->refresh_out,
10411 memory_order_relaxed));
10412 json_object_int_add(json_stat, "routeRefreshRecv",
10413 atomic_load_explicit(&p->refresh_in,
10414 memory_order_relaxed));
10415 json_object_int_add(json_stat, "capabilitySent",
10416 atomic_load_explicit(&p->dynamic_cap_out,
10417 memory_order_relaxed));
10418 json_object_int_add(json_stat, "capabilityRecv",
10419 atomic_load_explicit(&p->dynamic_cap_in,
10420 memory_order_relaxed));
10421 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10422 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10423 json_object_object_add(json_neigh, "messageStats", json_stat);
10424 } else {
10425 /* Packet counts. */
10426 vty_out(vty, " Message statistics:\n");
10427 vty_out(vty, " Inq depth is 0\n");
10428 vty_out(vty, " Outq depth is %lu\n",
10429 (unsigned long)p->obuf->count);
10430 vty_out(vty, " Sent Rcvd\n");
10431 vty_out(vty, " Opens: %10d %10d\n",
10432 atomic_load_explicit(&p->open_out,
10433 memory_order_relaxed),
10434 atomic_load_explicit(&p->open_in,
10435 memory_order_relaxed));
10436 vty_out(vty, " Notifications: %10d %10d\n",
10437 atomic_load_explicit(&p->notify_out,
10438 memory_order_relaxed),
10439 atomic_load_explicit(&p->notify_in,
10440 memory_order_relaxed));
10441 vty_out(vty, " Updates: %10d %10d\n",
10442 atomic_load_explicit(&p->update_out,
10443 memory_order_relaxed),
10444 atomic_load_explicit(&p->update_in,
10445 memory_order_relaxed));
10446 vty_out(vty, " Keepalives: %10d %10d\n",
10447 atomic_load_explicit(&p->keepalive_out,
10448 memory_order_relaxed),
10449 atomic_load_explicit(&p->keepalive_in,
10450 memory_order_relaxed));
10451 vty_out(vty, " Route Refresh: %10d %10d\n",
10452 atomic_load_explicit(&p->refresh_out,
10453 memory_order_relaxed),
10454 atomic_load_explicit(&p->refresh_in,
10455 memory_order_relaxed));
10456 vty_out(vty, " Capability: %10d %10d\n",
10457 atomic_load_explicit(&p->dynamic_cap_out,
10458 memory_order_relaxed),
10459 atomic_load_explicit(&p->dynamic_cap_in,
10460 memory_order_relaxed));
10461 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10462 PEER_TOTAL_RX(p));
10463 }
10464
10465 if (use_json) {
10466 /* advertisement-interval */
10467 json_object_int_add(json_neigh,
10468 "minBtwnAdvertisementRunsTimerMsecs",
10469 p->v_routeadv * 1000);
10470
10471 /* Update-source. */
10472 if (p->update_if || p->update_source) {
10473 if (p->update_if)
10474 json_object_string_add(json_neigh,
10475 "updateSource",
10476 p->update_if);
10477 else if (p->update_source)
10478 json_object_string_add(
10479 json_neigh, "updateSource",
10480 sockunion2str(p->update_source, buf1,
10481 SU_ADDRSTRLEN));
10482 }
10483 } else {
10484 /* advertisement-interval */
10485 vty_out(vty,
10486 " Minimum time between advertisement runs is %d seconds\n",
10487 p->v_routeadv);
10488
10489 /* Update-source. */
10490 if (p->update_if || p->update_source) {
10491 vty_out(vty, " Update source is ");
10492 if (p->update_if)
10493 vty_out(vty, "%s", p->update_if);
10494 else if (p->update_source)
10495 vty_out(vty, "%s",
10496 sockunion2str(p->update_source, buf1,
10497 SU_ADDRSTRLEN));
10498 vty_out(vty, "\n");
10499 }
10500
10501 vty_out(vty, "\n");
10502 }
10503
10504 /* Address Family Information */
10505 json_object *json_hold = NULL;
10506
10507 if (use_json)
10508 json_hold = json_object_new_object();
10509
10510 FOREACH_AFI_SAFI (afi, safi)
10511 if (p->afc[afi][safi])
10512 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10513 json_hold);
10514
10515 if (use_json) {
10516 json_object_object_add(json_neigh, "addressFamilyInfo",
10517 json_hold);
10518 json_object_int_add(json_neigh, "connectionsEstablished",
10519 p->established);
10520 json_object_int_add(json_neigh, "connectionsDropped",
10521 p->dropped);
10522 } else
10523 vty_out(vty, " Connections established %d; dropped %d\n",
10524 p->established, p->dropped);
10525
10526 if (!p->last_reset) {
10527 if (use_json)
10528 json_object_string_add(json_neigh, "lastReset",
10529 "never");
10530 else
10531 vty_out(vty, " Last reset never\n");
10532 } else {
10533 if (use_json) {
10534 time_t uptime;
10535 struct tm *tm;
10536
10537 uptime = bgp_clock();
10538 uptime -= p->resettime;
10539 tm = gmtime(&uptime);
10540 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10541 (tm->tm_sec * 1000)
10542 + (tm->tm_min * 60000)
10543 + (tm->tm_hour * 3600000));
10544 json_object_string_add(
10545 json_neigh, "lastResetDueTo",
10546 peer_down_str[(int)p->last_reset]);
10547 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10548 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10549 char errorcodesubcode_hexstr[5];
10550 char errorcodesubcode_str[256];
10551
10552 code_str = bgp_notify_code_str(p->notify.code);
10553 subcode_str = bgp_notify_subcode_str(
10554 p->notify.code, p->notify.subcode);
10555
10556 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10557 p->notify.code, p->notify.subcode);
10558 json_object_string_add(json_neigh,
10559 "lastErrorCodeSubcode",
10560 errorcodesubcode_hexstr);
10561 snprintf(errorcodesubcode_str, 255, "%s%s",
10562 code_str, subcode_str);
10563 json_object_string_add(json_neigh,
10564 "lastNotificationReason",
10565 errorcodesubcode_str);
10566 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10567 && p->notify.code == BGP_NOTIFY_CEASE
10568 && (p->notify.subcode
10569 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10570 || p->notify.subcode
10571 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10572 && p->notify.length) {
10573 char msgbuf[1024];
10574 const char *msg_str;
10575
10576 msg_str = bgp_notify_admin_message(
10577 msgbuf, sizeof(msgbuf),
10578 (uint8_t *)p->notify.data,
10579 p->notify.length);
10580 if (msg_str)
10581 json_object_string_add(
10582 json_neigh,
10583 "lastShutdownDescription",
10584 msg_str);
10585 }
10586 }
10587 } else {
10588 vty_out(vty, " Last reset %s, ",
10589 peer_uptime(p->resettime, timebuf,
10590 BGP_UPTIME_LEN, 0, NULL));
10591
10592 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10593 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10594 code_str = bgp_notify_code_str(p->notify.code);
10595 subcode_str = bgp_notify_subcode_str(
10596 p->notify.code, p->notify.subcode);
10597 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10598 p->last_reset == PEER_DOWN_NOTIFY_SEND
10599 ? "sent"
10600 : "received",
10601 code_str, subcode_str);
10602 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10603 && p->notify.code == BGP_NOTIFY_CEASE
10604 && (p->notify.subcode
10605 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10606 || p->notify.subcode
10607 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10608 && p->notify.length) {
10609 char msgbuf[1024];
10610 const char *msg_str;
10611
10612 msg_str = bgp_notify_admin_message(
10613 msgbuf, sizeof(msgbuf),
10614 (uint8_t *)p->notify.data,
10615 p->notify.length);
10616 if (msg_str)
10617 vty_out(vty,
10618 " Message: \"%s\"\n",
10619 msg_str);
10620 }
10621 } else {
10622 vty_out(vty, "due to %s\n",
10623 peer_down_str[(int)p->last_reset]);
10624 }
10625
10626 if (p->last_reset_cause_size) {
10627 msg = p->last_reset_cause;
10628 vty_out(vty,
10629 " Message received that caused BGP to send a NOTIFICATION:\n ");
10630 for (i = 1; i <= p->last_reset_cause_size;
10631 i++) {
10632 vty_out(vty, "%02X", *msg++);
10633
10634 if (i != p->last_reset_cause_size) {
10635 if (i % 16 == 0) {
10636 vty_out(vty, "\n ");
10637 } else if (i % 4 == 0) {
10638 vty_out(vty, " ");
10639 }
10640 }
10641 }
10642 vty_out(vty, "\n");
10643 }
10644 }
10645 }
10646
10647 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10648 if (use_json)
10649 json_object_boolean_true_add(json_neigh,
10650 "prefixesConfigExceedMax");
10651 else
10652 vty_out(vty,
10653 " Peer had exceeded the max. no. of prefixes configured.\n");
10654
10655 if (p->t_pmax_restart) {
10656 if (use_json) {
10657 json_object_boolean_true_add(
10658 json_neigh, "reducePrefixNumFrom");
10659 json_object_int_add(json_neigh,
10660 "restartInTimerMsec",
10661 thread_timer_remain_second(
10662 p->t_pmax_restart)
10663 * 1000);
10664 } else
10665 vty_out(vty,
10666 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10667 p->host, thread_timer_remain_second(
10668 p->t_pmax_restart));
10669 } else {
10670 if (use_json)
10671 json_object_boolean_true_add(
10672 json_neigh,
10673 "reducePrefixNumAndClearIpBgp");
10674 else
10675 vty_out(vty,
10676 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10677 p->host);
10678 }
10679 }
10680
10681 /* EBGP Multihop and GTSM */
10682 if (p->sort != BGP_PEER_IBGP) {
10683 if (use_json) {
10684 if (p->gtsm_hops > 0)
10685 json_object_int_add(json_neigh,
10686 "externalBgpNbrMaxHopsAway",
10687 p->gtsm_hops);
10688 else if (p->ttl > 1)
10689 json_object_int_add(json_neigh,
10690 "externalBgpNbrMaxHopsAway",
10691 p->ttl);
10692 } else {
10693 if (p->gtsm_hops > 0)
10694 vty_out(vty,
10695 " External BGP neighbor may be up to %d hops away.\n",
10696 p->gtsm_hops);
10697 else if (p->ttl > 1)
10698 vty_out(vty,
10699 " External BGP neighbor may be up to %d hops away.\n",
10700 p->ttl);
10701 }
10702 } else {
10703 if (p->gtsm_hops > 0) {
10704 if (use_json)
10705 json_object_int_add(json_neigh,
10706 "internalBgpNbrMaxHopsAway",
10707 p->gtsm_hops);
10708 else
10709 vty_out(vty,
10710 " Internal BGP neighbor may be up to %d hops away.\n",
10711 p->gtsm_hops);
10712 }
10713 }
10714
10715 /* Local address. */
10716 if (p->su_local) {
10717 if (use_json) {
10718 json_object_string_add(json_neigh, "hostLocal",
10719 sockunion2str(p->su_local, buf1,
10720 SU_ADDRSTRLEN));
10721 json_object_int_add(json_neigh, "portLocal",
10722 ntohs(p->su_local->sin.sin_port));
10723 } else
10724 vty_out(vty, "Local host: %s, Local port: %d\n",
10725 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10726 ntohs(p->su_local->sin.sin_port));
10727 }
10728
10729 /* Remote address. */
10730 if (p->su_remote) {
10731 if (use_json) {
10732 json_object_string_add(json_neigh, "hostForeign",
10733 sockunion2str(p->su_remote, buf1,
10734 SU_ADDRSTRLEN));
10735 json_object_int_add(json_neigh, "portForeign",
10736 ntohs(p->su_remote->sin.sin_port));
10737 } else
10738 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10739 sockunion2str(p->su_remote, buf1,
10740 SU_ADDRSTRLEN),
10741 ntohs(p->su_remote->sin.sin_port));
10742 }
10743
10744 /* Nexthop display. */
10745 if (p->su_local) {
10746 if (use_json) {
10747 json_object_string_add(json_neigh, "nexthop",
10748 inet_ntop(AF_INET,
10749 &p->nexthop.v4, buf1,
10750 sizeof(buf1)));
10751 json_object_string_add(json_neigh, "nexthopGlobal",
10752 inet_ntop(AF_INET6,
10753 &p->nexthop.v6_global,
10754 buf1, sizeof(buf1)));
10755 json_object_string_add(json_neigh, "nexthopLocal",
10756 inet_ntop(AF_INET6,
10757 &p->nexthop.v6_local,
10758 buf1, sizeof(buf1)));
10759 if (p->shared_network)
10760 json_object_string_add(json_neigh,
10761 "bgpConnection",
10762 "sharedNetwork");
10763 else
10764 json_object_string_add(json_neigh,
10765 "bgpConnection",
10766 "nonSharedNetwork");
10767 } else {
10768 vty_out(vty, "Nexthop: %s\n",
10769 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10770 sizeof(buf1)));
10771 vty_out(vty, "Nexthop global: %s\n",
10772 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10773 sizeof(buf1)));
10774 vty_out(vty, "Nexthop local: %s\n",
10775 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10776 sizeof(buf1)));
10777 vty_out(vty, "BGP connection: %s\n",
10778 p->shared_network ? "shared network"
10779 : "non shared network");
10780 }
10781 }
10782
10783 /* Timer information. */
10784 if (use_json) {
10785 json_object_int_add(json_neigh, "connectRetryTimer",
10786 p->v_connect);
10787 if (p->status == Established && p->rtt)
10788 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10789 p->rtt);
10790 if (p->t_start)
10791 json_object_int_add(
10792 json_neigh, "nextStartTimerDueInMsecs",
10793 thread_timer_remain_second(p->t_start) * 1000);
10794 if (p->t_connect)
10795 json_object_int_add(
10796 json_neigh, "nextConnectTimerDueInMsecs",
10797 thread_timer_remain_second(p->t_connect)
10798 * 1000);
10799 if (p->t_routeadv) {
10800 json_object_int_add(json_neigh, "mraiInterval",
10801 p->v_routeadv);
10802 json_object_int_add(
10803 json_neigh, "mraiTimerExpireInMsecs",
10804 thread_timer_remain_second(p->t_routeadv)
10805 * 1000);
10806 }
10807 if (p->password)
10808 json_object_int_add(json_neigh, "authenticationEnabled",
10809 1);
10810
10811 if (p->t_read)
10812 json_object_string_add(json_neigh, "readThread", "on");
10813 else
10814 json_object_string_add(json_neigh, "readThread", "off");
10815
10816 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10817 json_object_string_add(json_neigh, "writeThread", "on");
10818 else
10819 json_object_string_add(json_neigh, "writeThread",
10820 "off");
10821 } else {
10822 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10823 p->v_connect);
10824 if (p->status == Established && p->rtt)
10825 vty_out(vty, "Estimated round trip time: %d ms\n",
10826 p->rtt);
10827 if (p->t_start)
10828 vty_out(vty, "Next start timer due in %ld seconds\n",
10829 thread_timer_remain_second(p->t_start));
10830 if (p->t_connect)
10831 vty_out(vty, "Next connect timer due in %ld seconds\n",
10832 thread_timer_remain_second(p->t_connect));
10833 if (p->t_routeadv)
10834 vty_out(vty,
10835 "MRAI (interval %u) timer expires in %ld seconds\n",
10836 p->v_routeadv,
10837 thread_timer_remain_second(p->t_routeadv));
10838 if (p->password)
10839 vty_out(vty, "Peer Authentication Enabled\n");
10840
10841 vty_out(vty, "Read thread: %s Write thread: %s\n",
10842 p->t_read ? "on" : "off",
10843 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10844 ? "on"
10845 : "off");
10846 }
10847
10848 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10849 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10850 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10851
10852 if (!use_json)
10853 vty_out(vty, "\n");
10854
10855 /* BFD information. */
10856 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10857
10858 if (use_json) {
10859 if (p->conf_if) /* Configured interface name. */
10860 json_object_object_add(json, p->conf_if, json_neigh);
10861 else /* Configured IP address. */
10862 json_object_object_add(json, p->host, json_neigh);
10863 }
10864 }
10865
10866 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10867 enum show_type type, union sockunion *su,
10868 const char *conf_if, bool use_json,
10869 json_object *json)
10870 {
10871 struct listnode *node, *nnode;
10872 struct peer *peer;
10873 int find = 0;
10874 bool nbr_output = false;
10875
10876 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10877 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10878 continue;
10879
10880 switch (type) {
10881 case show_all:
10882 bgp_show_peer(vty, peer, use_json, json);
10883 nbr_output = true;
10884 break;
10885 case show_peer:
10886 if (conf_if) {
10887 if ((peer->conf_if
10888 && !strcmp(peer->conf_if, conf_if))
10889 || (peer->hostname
10890 && !strcmp(peer->hostname, conf_if))) {
10891 find = 1;
10892 bgp_show_peer(vty, peer, use_json,
10893 json);
10894 }
10895 } else {
10896 if (sockunion_same(&peer->su, su)) {
10897 find = 1;
10898 bgp_show_peer(vty, peer, use_json,
10899 json);
10900 }
10901 }
10902 break;
10903 }
10904 }
10905
10906 if (type == show_peer && !find) {
10907 if (use_json)
10908 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10909 else
10910 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10911 }
10912
10913 if (type != show_peer && !nbr_output && !use_json)
10914 vty_out(vty, "%% No BGP neighbors found\n");
10915
10916 if (use_json) {
10917 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10918 json, JSON_C_TO_STRING_PRETTY));
10919 json_object_free(json);
10920 } else {
10921 vty_out(vty, "\n");
10922 }
10923
10924 return CMD_SUCCESS;
10925 }
10926
10927 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10928 enum show_type type,
10929 const char *ip_str,
10930 bool use_json)
10931 {
10932 struct listnode *node, *nnode;
10933 struct bgp *bgp;
10934 union sockunion su;
10935 json_object *json = NULL;
10936 int ret, is_first = 1;
10937 bool nbr_output = false;
10938
10939 if (use_json)
10940 vty_out(vty, "{\n");
10941
10942 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10943 nbr_output = true;
10944 if (use_json) {
10945 if (!(json = json_object_new_object())) {
10946 flog_err(
10947 EC_BGP_JSON_MEM_ERROR,
10948 "Unable to allocate memory for JSON object");
10949 vty_out(vty,
10950 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10951 return;
10952 }
10953
10954 json_object_int_add(json, "vrfId",
10955 (bgp->vrf_id == VRF_UNKNOWN)
10956 ? -1
10957 : (int64_t)bgp->vrf_id);
10958 json_object_string_add(
10959 json, "vrfName",
10960 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10961 ? VRF_DEFAULT_NAME
10962 : bgp->name);
10963
10964 if (!is_first)
10965 vty_out(vty, ",\n");
10966 else
10967 is_first = 0;
10968
10969 vty_out(vty, "\"%s\":",
10970 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10971 ? VRF_DEFAULT_NAME
10972 : bgp->name);
10973 } else {
10974 vty_out(vty, "\nInstance %s:\n",
10975 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10976 ? VRF_DEFAULT_NAME
10977 : bgp->name);
10978 }
10979
10980 if (type == show_peer) {
10981 ret = str2sockunion(ip_str, &su);
10982 if (ret < 0)
10983 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10984 use_json, json);
10985 else
10986 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10987 use_json, json);
10988 } else {
10989 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10990 use_json, json);
10991 }
10992 }
10993
10994 if (use_json)
10995 vty_out(vty, "}\n");
10996 else if (!nbr_output)
10997 vty_out(vty, "%% BGP instance not found\n");
10998 }
10999
11000 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
11001 enum show_type type, const char *ip_str,
11002 bool use_json)
11003 {
11004 int ret;
11005 struct bgp *bgp;
11006 union sockunion su;
11007 json_object *json = NULL;
11008
11009 if (name) {
11010 if (strmatch(name, "all")) {
11011 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
11012 use_json);
11013 return CMD_SUCCESS;
11014 } else {
11015 bgp = bgp_lookup_by_name(name);
11016 if (!bgp) {
11017 if (use_json) {
11018 json = json_object_new_object();
11019 vty_out(vty, "%s\n",
11020 json_object_to_json_string_ext(
11021 json,
11022 JSON_C_TO_STRING_PRETTY));
11023 json_object_free(json);
11024 } else
11025 vty_out(vty,
11026 "%% BGP instance not found\n");
11027
11028 return CMD_WARNING;
11029 }
11030 }
11031 } else {
11032 bgp = bgp_get_default();
11033 }
11034
11035 if (bgp) {
11036 json = json_object_new_object();
11037 if (ip_str) {
11038 ret = str2sockunion(ip_str, &su);
11039 if (ret < 0)
11040 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
11041 use_json, json);
11042 else
11043 bgp_show_neighbor(vty, bgp, type, &su, NULL,
11044 use_json, json);
11045 } else {
11046 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
11047 json);
11048 }
11049 json_object_free(json);
11050 } else {
11051 if (use_json)
11052 vty_out(vty, "{}\n");
11053 else
11054 vty_out(vty, "%% BGP instance not found\n");
11055 }
11056
11057 return CMD_SUCCESS;
11058 }
11059
11060 /* "show [ip] bgp neighbors" commands. */
11061 DEFUN (show_ip_bgp_neighbors,
11062 show_ip_bgp_neighbors_cmd,
11063 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
11064 SHOW_STR
11065 IP_STR
11066 BGP_STR
11067 BGP_INSTANCE_HELP_STR
11068 "Address Family\n"
11069 "Address Family\n"
11070 "Detailed information on TCP and BGP neighbor connections\n"
11071 "Neighbor to display information about\n"
11072 "Neighbor to display information about\n"
11073 "Neighbor on BGP configured interface\n"
11074 JSON_STR)
11075 {
11076 char *vrf = NULL;
11077 char *sh_arg = NULL;
11078 enum show_type sh_type;
11079
11080 bool uj = use_json(argc, argv);
11081
11082 int idx = 0;
11083
11084 /* [<vrf> VIEWVRFNAME] */
11085 if (argv_find(argv, argc, "vrf", &idx)) {
11086 vrf = argv[idx + 1]->arg;
11087 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11088 vrf = NULL;
11089 } else if (argv_find(argv, argc, "view", &idx))
11090 /* [<view> VIEWVRFNAME] */
11091 vrf = argv[idx + 1]->arg;
11092
11093 idx++;
11094 if (argv_find(argv, argc, "A.B.C.D", &idx)
11095 || argv_find(argv, argc, "X:X::X:X", &idx)
11096 || argv_find(argv, argc, "WORD", &idx)) {
11097 sh_type = show_peer;
11098 sh_arg = argv[idx]->arg;
11099 } else
11100 sh_type = show_all;
11101
11102 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
11103 }
11104
11105 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11106 paths' and `show ip mbgp paths'. Those functions results are the
11107 same.*/
11108 DEFUN (show_ip_bgp_paths,
11109 show_ip_bgp_paths_cmd,
11110 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11111 SHOW_STR
11112 IP_STR
11113 BGP_STR
11114 BGP_SAFI_HELP_STR
11115 "Path information\n")
11116 {
11117 vty_out(vty, "Address Refcnt Path\n");
11118 aspath_print_all_vty(vty);
11119 return CMD_SUCCESS;
11120 }
11121
11122 #include "hash.h"
11123
11124 static void community_show_all_iterator(struct hash_backet *backet,
11125 struct vty *vty)
11126 {
11127 struct community *com;
11128
11129 com = (struct community *)backet->data;
11130 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11131 community_str(com, false));
11132 }
11133
11134 /* Show BGP's community internal data. */
11135 DEFUN (show_ip_bgp_community_info,
11136 show_ip_bgp_community_info_cmd,
11137 "show [ip] bgp community-info",
11138 SHOW_STR
11139 IP_STR
11140 BGP_STR
11141 "List all bgp community information\n")
11142 {
11143 vty_out(vty, "Address Refcnt Community\n");
11144
11145 hash_iterate(community_hash(),
11146 (void (*)(struct hash_backet *,
11147 void *))community_show_all_iterator,
11148 vty);
11149
11150 return CMD_SUCCESS;
11151 }
11152
11153 static void lcommunity_show_all_iterator(struct hash_backet *backet,
11154 struct vty *vty)
11155 {
11156 struct lcommunity *lcom;
11157
11158 lcom = (struct lcommunity *)backet->data;
11159 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11160 lcommunity_str(lcom, false));
11161 }
11162
11163 /* Show BGP's community internal data. */
11164 DEFUN (show_ip_bgp_lcommunity_info,
11165 show_ip_bgp_lcommunity_info_cmd,
11166 "show ip bgp large-community-info",
11167 SHOW_STR
11168 IP_STR
11169 BGP_STR
11170 "List all bgp large-community information\n")
11171 {
11172 vty_out(vty, "Address Refcnt Large-community\n");
11173
11174 hash_iterate(lcommunity_hash(),
11175 (void (*)(struct hash_backet *,
11176 void *))lcommunity_show_all_iterator,
11177 vty);
11178
11179 return CMD_SUCCESS;
11180 }
11181
11182
11183 DEFUN (show_ip_bgp_attr_info,
11184 show_ip_bgp_attr_info_cmd,
11185 "show [ip] bgp attribute-info",
11186 SHOW_STR
11187 IP_STR
11188 BGP_STR
11189 "List all bgp attribute information\n")
11190 {
11191 attr_show_all(vty);
11192 return CMD_SUCCESS;
11193 }
11194
11195 static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11196 safi_t safi, bool use_json)
11197 {
11198 struct bgp *bgp;
11199 struct listnode *node;
11200 char *vname;
11201 char buf1[INET6_ADDRSTRLEN];
11202 char *ecom_str;
11203 vpn_policy_direction_t dir;
11204
11205 if (use_json) {
11206 json_object *json = NULL;
11207 json_object *json_import_vrfs = NULL;
11208 json_object *json_export_vrfs = NULL;
11209
11210 json = json_object_new_object();
11211
11212 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11213
11214 if (!bgp) {
11215 vty_out(vty, "%s\n",
11216 json_object_to_json_string_ext(
11217 json,
11218 JSON_C_TO_STRING_PRETTY));
11219 json_object_free(json);
11220
11221 return CMD_WARNING;
11222 }
11223
11224 /* Provide context for the block */
11225 json_object_string_add(json, "vrf", name ? name : "default");
11226 json_object_string_add(json, "afiSafi",
11227 afi_safi_print(afi, safi));
11228
11229 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11230 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11231 json_object_string_add(json, "importFromVrfs", "none");
11232 json_object_string_add(json, "importRts", "none");
11233 } else {
11234 json_import_vrfs = json_object_new_array();
11235
11236 for (ALL_LIST_ELEMENTS_RO(
11237 bgp->vpn_policy[afi].import_vrf,
11238 node, vname))
11239 json_object_array_add(json_import_vrfs,
11240 json_object_new_string(vname));
11241
11242 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11243 ecom_str = ecommunity_ecom2str(
11244 bgp->vpn_policy[afi].rtlist[dir],
11245 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11246 json_object_object_add(json, "importFromVrfs",
11247 json_import_vrfs);
11248 json_object_string_add(json, "importRts", ecom_str);
11249
11250 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11251 }
11252
11253 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11254 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11255 json_object_string_add(json, "exportToVrfs", "none");
11256 json_object_string_add(json, "routeDistinguisher",
11257 "none");
11258 json_object_string_add(json, "exportRts", "none");
11259 } else {
11260 json_export_vrfs = json_object_new_array();
11261
11262 for (ALL_LIST_ELEMENTS_RO(
11263 bgp->vpn_policy[afi].export_vrf,
11264 node, vname))
11265 json_object_array_add(json_export_vrfs,
11266 json_object_new_string(vname));
11267 json_object_object_add(json, "exportToVrfs",
11268 json_export_vrfs);
11269 json_object_string_add(json, "routeDistinguisher",
11270 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11271 buf1, RD_ADDRSTRLEN));
11272
11273 dir = BGP_VPN_POLICY_DIR_TOVPN;
11274 ecom_str = ecommunity_ecom2str(
11275 bgp->vpn_policy[afi].rtlist[dir],
11276 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11277 json_object_string_add(json, "exportRts", ecom_str);
11278
11279 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11280 }
11281
11282 vty_out(vty, "%s\n",
11283 json_object_to_json_string_ext(json,
11284 JSON_C_TO_STRING_PRETTY));
11285 json_object_free(json);
11286
11287 } else {
11288 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11289
11290 if (!bgp) {
11291 vty_out(vty, "%% No such BGP instance exist\n");
11292 return CMD_WARNING;
11293 }
11294
11295 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11296 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11297 vty_out(vty,
11298 "This VRF is not importing %s routes from any other VRF\n",
11299 afi_safi_print(afi, safi));
11300 else {
11301 vty_out(vty,
11302 "This VRF is importing %s routes from the following VRFs:\n",
11303 afi_safi_print(afi, safi));
11304
11305 for (ALL_LIST_ELEMENTS_RO(
11306 bgp->vpn_policy[afi].import_vrf,
11307 node, vname))
11308 vty_out(vty, " %s\n", vname);
11309
11310 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11311 ecom_str = ecommunity_ecom2str(
11312 bgp->vpn_policy[afi].rtlist[dir],
11313 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11314 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11315
11316 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11317 }
11318
11319 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11320 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11321 vty_out(vty,
11322 "This VRF is not exporting %s routes to any other VRF\n",
11323 afi_safi_print(afi, safi));
11324 else {
11325 vty_out(vty,
11326 "This VRF is exporting %s routes to the following VRFs:\n",
11327 afi_safi_print(afi, safi));
11328
11329 for (ALL_LIST_ELEMENTS_RO(
11330 bgp->vpn_policy[afi].export_vrf,
11331 node, vname))
11332 vty_out(vty, " %s\n", vname);
11333
11334 vty_out(vty, "RD: %s\n",
11335 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11336 buf1, RD_ADDRSTRLEN));
11337
11338 dir = BGP_VPN_POLICY_DIR_TOVPN;
11339 ecom_str = ecommunity_ecom2str(
11340 bgp->vpn_policy[afi].rtlist[dir],
11341 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11342 vty_out(vty, "Export RT: %s\n", ecom_str);
11343 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11344 }
11345 }
11346
11347 return CMD_SUCCESS;
11348 }
11349
11350 /* "show [ip] bgp route-leak" command. */
11351 DEFUN (show_ip_bgp_route_leak,
11352 show_ip_bgp_route_leak_cmd,
11353 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11354 SHOW_STR
11355 IP_STR
11356 BGP_STR
11357 BGP_INSTANCE_HELP_STR
11358 BGP_AFI_HELP_STR
11359 BGP_SAFI_HELP_STR
11360 "Route leaking information\n"
11361 JSON_STR)
11362 {
11363 char *vrf = NULL;
11364 afi_t afi = AFI_MAX;
11365 safi_t safi = SAFI_MAX;
11366
11367 bool uj = use_json(argc, argv);
11368 int idx = 0;
11369
11370 /* show [ip] bgp */
11371 if (argv_find(argv, argc, "ip", &idx)) {
11372 afi = AFI_IP;
11373 safi = SAFI_UNICAST;
11374 }
11375 /* [vrf VIEWVRFNAME] */
11376 if (argv_find(argv, argc, "view", &idx)) {
11377 vty_out(vty,
11378 "%% This command is not applicable to BGP views\n");
11379 return CMD_WARNING;
11380 }
11381
11382 if (argv_find(argv, argc, "vrf", &idx)) {
11383 vrf = argv[idx + 1]->arg;
11384 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11385 vrf = NULL;
11386 }
11387 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11388 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11389 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11390 }
11391
11392 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11393 vty_out(vty,
11394 "%% This command is applicable only for unicast ipv4|ipv6\n");
11395 return CMD_WARNING;
11396 }
11397
11398 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
11399 }
11400
11401 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11402 safi_t safi)
11403 {
11404 struct listnode *node, *nnode;
11405 struct bgp *bgp;
11406
11407 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11408 vty_out(vty, "\nInstance %s:\n",
11409 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11410 ? VRF_DEFAULT_NAME
11411 : bgp->name);
11412 update_group_show(bgp, afi, safi, vty, 0);
11413 }
11414 }
11415
11416 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11417 int safi, uint64_t subgrp_id)
11418 {
11419 struct bgp *bgp;
11420
11421 if (name) {
11422 if (strmatch(name, "all")) {
11423 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11424 return CMD_SUCCESS;
11425 } else {
11426 bgp = bgp_lookup_by_name(name);
11427 }
11428 } else {
11429 bgp = bgp_get_default();
11430 }
11431
11432 if (bgp)
11433 update_group_show(bgp, afi, safi, vty, subgrp_id);
11434 return CMD_SUCCESS;
11435 }
11436
11437 DEFUN (show_ip_bgp_updgrps,
11438 show_ip_bgp_updgrps_cmd,
11439 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11440 SHOW_STR
11441 IP_STR
11442 BGP_STR
11443 BGP_INSTANCE_HELP_STR
11444 BGP_AFI_HELP_STR
11445 BGP_SAFI_WITH_LABEL_HELP_STR
11446 "Detailed info about dynamic update groups\n"
11447 "Specific subgroup to display detailed info for\n")
11448 {
11449 char *vrf = NULL;
11450 afi_t afi = AFI_IP6;
11451 safi_t safi = SAFI_UNICAST;
11452 uint64_t subgrp_id = 0;
11453
11454 int idx = 0;
11455
11456 /* show [ip] bgp */
11457 if (argv_find(argv, argc, "ip", &idx))
11458 afi = AFI_IP;
11459 /* [<vrf> VIEWVRFNAME] */
11460 if (argv_find(argv, argc, "vrf", &idx)) {
11461 vrf = argv[idx + 1]->arg;
11462 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11463 vrf = NULL;
11464 } else if (argv_find(argv, argc, "view", &idx))
11465 /* [<view> VIEWVRFNAME] */
11466 vrf = argv[idx + 1]->arg;
11467 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11468 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11469 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11470 }
11471
11472 /* get subgroup id, if provided */
11473 idx = argc - 1;
11474 if (argv[idx]->type == VARIABLE_TKN)
11475 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11476
11477 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11478 }
11479
11480 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11481 show_bgp_instance_all_ipv6_updgrps_cmd,
11482 "show [ip] bgp <view|vrf> all update-groups",
11483 SHOW_STR
11484 IP_STR
11485 BGP_STR
11486 BGP_INSTANCE_ALL_HELP_STR
11487 "Detailed info about dynamic update groups\n")
11488 {
11489 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11490 return CMD_SUCCESS;
11491 }
11492
11493 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11494 show_bgp_l2vpn_evpn_updgrps_cmd,
11495 "show [ip] bgp l2vpn evpn update-groups",
11496 SHOW_STR
11497 IP_STR
11498 BGP_STR
11499 "l2vpn address family\n"
11500 "evpn sub-address family\n"
11501 "Detailed info about dynamic update groups\n")
11502 {
11503 char *vrf = NULL;
11504 uint64_t subgrp_id = 0;
11505
11506 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11507 return CMD_SUCCESS;
11508 }
11509
11510 DEFUN (show_bgp_updgrps_stats,
11511 show_bgp_updgrps_stats_cmd,
11512 "show [ip] bgp update-groups statistics",
11513 SHOW_STR
11514 IP_STR
11515 BGP_STR
11516 "Detailed info about dynamic update groups\n"
11517 "Statistics\n")
11518 {
11519 struct bgp *bgp;
11520
11521 bgp = bgp_get_default();
11522 if (bgp)
11523 update_group_show_stats(bgp, vty);
11524
11525 return CMD_SUCCESS;
11526 }
11527
11528 DEFUN (show_bgp_instance_updgrps_stats,
11529 show_bgp_instance_updgrps_stats_cmd,
11530 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11531 SHOW_STR
11532 IP_STR
11533 BGP_STR
11534 BGP_INSTANCE_HELP_STR
11535 "Detailed info about dynamic update groups\n"
11536 "Statistics\n")
11537 {
11538 int idx_word = 3;
11539 struct bgp *bgp;
11540
11541 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11542 if (bgp)
11543 update_group_show_stats(bgp, vty);
11544
11545 return CMD_SUCCESS;
11546 }
11547
11548 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11549 afi_t afi, safi_t safi,
11550 const char *what, uint64_t subgrp_id)
11551 {
11552 struct bgp *bgp;
11553
11554 if (name)
11555 bgp = bgp_lookup_by_name(name);
11556 else
11557 bgp = bgp_get_default();
11558
11559 if (bgp) {
11560 if (!strcmp(what, "advertise-queue"))
11561 update_group_show_adj_queue(bgp, afi, safi, vty,
11562 subgrp_id);
11563 else if (!strcmp(what, "advertised-routes"))
11564 update_group_show_advertised(bgp, afi, safi, vty,
11565 subgrp_id);
11566 else if (!strcmp(what, "packet-queue"))
11567 update_group_show_packet_queue(bgp, afi, safi, vty,
11568 subgrp_id);
11569 }
11570 }
11571
11572 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11573 show_ip_bgp_instance_updgrps_adj_s_cmd,
11574 "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",
11575 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11576 BGP_SAFI_HELP_STR
11577 "Detailed info about dynamic update groups\n"
11578 "Specific subgroup to display info for\n"
11579 "Advertisement queue\n"
11580 "Announced routes\n"
11581 "Packet queue\n")
11582 {
11583 uint64_t subgrp_id = 0;
11584 afi_t afiz;
11585 safi_t safiz;
11586 if (sgid)
11587 subgrp_id = strtoull(sgid, NULL, 10);
11588
11589 if (!ip && !afi)
11590 afiz = AFI_IP6;
11591 if (!ip && afi)
11592 afiz = bgp_vty_afi_from_str(afi);
11593 if (ip && !afi)
11594 afiz = AFI_IP;
11595 if (ip && afi) {
11596 afiz = bgp_vty_afi_from_str(afi);
11597 if (afiz != AFI_IP)
11598 vty_out(vty,
11599 "%% Cannot specify both 'ip' and 'ipv6'\n");
11600 return CMD_WARNING;
11601 }
11602
11603 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11604
11605 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11606 return CMD_SUCCESS;
11607 }
11608
11609 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11610 {
11611 struct listnode *node, *nnode;
11612 struct prefix *range;
11613 struct peer *conf;
11614 struct peer *peer;
11615 char buf[PREFIX2STR_BUFFER];
11616 afi_t afi;
11617 safi_t safi;
11618 const char *peer_status;
11619 const char *af_str;
11620 int lr_count;
11621 int dynamic;
11622 int af_cfgd;
11623
11624 conf = group->conf;
11625
11626 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11627 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11628 conf->as);
11629 } else if (conf->as_type == AS_INTERNAL) {
11630 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11631 group->bgp->as);
11632 } else {
11633 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11634 }
11635
11636 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11637 vty_out(vty, " Peer-group type is internal\n");
11638 else
11639 vty_out(vty, " Peer-group type is external\n");
11640
11641 /* Display AFs configured. */
11642 vty_out(vty, " Configured address-families:");
11643 FOREACH_AFI_SAFI (afi, safi) {
11644 if (conf->afc[afi][safi]) {
11645 af_cfgd = 1;
11646 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11647 }
11648 }
11649 if (!af_cfgd)
11650 vty_out(vty, " none\n");
11651 else
11652 vty_out(vty, "\n");
11653
11654 /* Display listen ranges (for dynamic neighbors), if any */
11655 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11656 if (afi == AFI_IP)
11657 af_str = "IPv4";
11658 else if (afi == AFI_IP6)
11659 af_str = "IPv6";
11660 else
11661 af_str = "???";
11662 lr_count = listcount(group->listen_range[afi]);
11663 if (lr_count) {
11664 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11665 af_str);
11666
11667
11668 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11669 nnode, range)) {
11670 prefix2str(range, buf, sizeof(buf));
11671 vty_out(vty, " %s\n", buf);
11672 }
11673 }
11674 }
11675
11676 /* Display group members and their status */
11677 if (listcount(group->peer)) {
11678 vty_out(vty, " Peer-group members:\n");
11679 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11680 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11681 peer_status = "Idle (Admin)";
11682 else if (CHECK_FLAG(peer->sflags,
11683 PEER_STATUS_PREFIX_OVERFLOW))
11684 peer_status = "Idle (PfxCt)";
11685 else
11686 peer_status = lookup_msg(bgp_status_msg,
11687 peer->status, NULL);
11688
11689 dynamic = peer_dynamic_neighbor(peer);
11690 vty_out(vty, " %s %s %s \n", peer->host,
11691 dynamic ? "(dynamic)" : "", peer_status);
11692 }
11693 }
11694
11695 return CMD_SUCCESS;
11696 }
11697
11698 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11699 const char *group_name)
11700 {
11701 struct bgp *bgp;
11702 struct listnode *node, *nnode;
11703 struct peer_group *group;
11704 bool found = false;
11705
11706 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11707
11708 if (!bgp) {
11709 vty_out(vty, "%% BGP instance not found\n");
11710 return CMD_WARNING;
11711 }
11712
11713 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11714 if (group_name) {
11715 if (strmatch(group->name, group_name)) {
11716 bgp_show_one_peer_group(vty, group);
11717 found = true;
11718 break;
11719 }
11720 } else {
11721 bgp_show_one_peer_group(vty, group);
11722 }
11723 }
11724
11725 if (group_name && !found)
11726 vty_out(vty, "%% No such peer-group\n");
11727
11728 return CMD_SUCCESS;
11729 }
11730
11731 DEFUN (show_ip_bgp_peer_groups,
11732 show_ip_bgp_peer_groups_cmd,
11733 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11734 SHOW_STR
11735 IP_STR
11736 BGP_STR
11737 BGP_INSTANCE_HELP_STR
11738 "Detailed information on BGP peer groups\n"
11739 "Peer group name\n")
11740 {
11741 char *vrf, *pg;
11742 int idx = 0;
11743
11744 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11745 : NULL;
11746 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11747
11748 return bgp_show_peer_group_vty(vty, vrf, pg);
11749 }
11750
11751
11752 /* Redistribute VTY commands. */
11753
11754 DEFUN (bgp_redistribute_ipv4,
11755 bgp_redistribute_ipv4_cmd,
11756 "redistribute " FRR_IP_REDIST_STR_BGPD,
11757 "Redistribute information from another routing protocol\n"
11758 FRR_IP_REDIST_HELP_STR_BGPD)
11759 {
11760 VTY_DECLVAR_CONTEXT(bgp, bgp);
11761 int idx_protocol = 1;
11762 int type;
11763
11764 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11765 if (type < 0) {
11766 vty_out(vty, "%% Invalid route type\n");
11767 return CMD_WARNING_CONFIG_FAILED;
11768 }
11769
11770 bgp_redist_add(bgp, AFI_IP, type, 0);
11771 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11772 }
11773
11774 ALIAS_HIDDEN(
11775 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11776 "redistribute " FRR_IP_REDIST_STR_BGPD,
11777 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11778
11779 DEFUN (bgp_redistribute_ipv4_rmap,
11780 bgp_redistribute_ipv4_rmap_cmd,
11781 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11782 "Redistribute information from another routing protocol\n"
11783 FRR_IP_REDIST_HELP_STR_BGPD
11784 "Route map reference\n"
11785 "Pointer to route-map entries\n")
11786 {
11787 VTY_DECLVAR_CONTEXT(bgp, bgp);
11788 int idx_protocol = 1;
11789 int idx_word = 3;
11790 int type;
11791 struct bgp_redist *red;
11792 bool changed;
11793 struct route_map *route_map = route_map_lookup_warn_noexist(
11794 vty, argv[idx_word]->arg);
11795
11796 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11797 if (type < 0) {
11798 vty_out(vty, "%% Invalid route type\n");
11799 return CMD_WARNING_CONFIG_FAILED;
11800 }
11801
11802 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11803 changed =
11804 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11805 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11806 }
11807
11808 ALIAS_HIDDEN(
11809 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11810 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11811 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11812 "Route map reference\n"
11813 "Pointer to route-map entries\n")
11814
11815 DEFUN (bgp_redistribute_ipv4_metric,
11816 bgp_redistribute_ipv4_metric_cmd,
11817 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11818 "Redistribute information from another routing protocol\n"
11819 FRR_IP_REDIST_HELP_STR_BGPD
11820 "Metric for redistributed routes\n"
11821 "Default metric\n")
11822 {
11823 VTY_DECLVAR_CONTEXT(bgp, bgp);
11824 int idx_protocol = 1;
11825 int idx_number = 3;
11826 int type;
11827 uint32_t metric;
11828 struct bgp_redist *red;
11829 bool changed;
11830
11831 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11832 if (type < 0) {
11833 vty_out(vty, "%% Invalid route type\n");
11834 return CMD_WARNING_CONFIG_FAILED;
11835 }
11836 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11837
11838 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11839 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11840 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11841 }
11842
11843 ALIAS_HIDDEN(
11844 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11845 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11846 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11847 "Metric for redistributed routes\n"
11848 "Default metric\n")
11849
11850 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11851 bgp_redistribute_ipv4_rmap_metric_cmd,
11852 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11853 "Redistribute information from another routing protocol\n"
11854 FRR_IP_REDIST_HELP_STR_BGPD
11855 "Route map reference\n"
11856 "Pointer to route-map entries\n"
11857 "Metric for redistributed routes\n"
11858 "Default metric\n")
11859 {
11860 VTY_DECLVAR_CONTEXT(bgp, bgp);
11861 int idx_protocol = 1;
11862 int idx_word = 3;
11863 int idx_number = 5;
11864 int type;
11865 uint32_t metric;
11866 struct bgp_redist *red;
11867 bool changed;
11868 struct route_map *route_map =
11869 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11870
11871 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11872 if (type < 0) {
11873 vty_out(vty, "%% Invalid route type\n");
11874 return CMD_WARNING_CONFIG_FAILED;
11875 }
11876 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11877
11878 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11879 changed =
11880 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11881 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11882 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11883 }
11884
11885 ALIAS_HIDDEN(
11886 bgp_redistribute_ipv4_rmap_metric,
11887 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11888 "redistribute " FRR_IP_REDIST_STR_BGPD
11889 " route-map WORD metric (0-4294967295)",
11890 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11891 "Route map reference\n"
11892 "Pointer to route-map entries\n"
11893 "Metric for redistributed routes\n"
11894 "Default metric\n")
11895
11896 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11897 bgp_redistribute_ipv4_metric_rmap_cmd,
11898 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11899 "Redistribute information from another routing protocol\n"
11900 FRR_IP_REDIST_HELP_STR_BGPD
11901 "Metric for redistributed routes\n"
11902 "Default metric\n"
11903 "Route map reference\n"
11904 "Pointer to route-map entries\n")
11905 {
11906 VTY_DECLVAR_CONTEXT(bgp, bgp);
11907 int idx_protocol = 1;
11908 int idx_number = 3;
11909 int idx_word = 5;
11910 int type;
11911 uint32_t metric;
11912 struct bgp_redist *red;
11913 bool changed;
11914 struct route_map *route_map =
11915 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11916
11917 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11918 if (type < 0) {
11919 vty_out(vty, "%% Invalid route type\n");
11920 return CMD_WARNING_CONFIG_FAILED;
11921 }
11922 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11923
11924 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11925 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11926 changed |=
11927 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11928 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11929 }
11930
11931 ALIAS_HIDDEN(
11932 bgp_redistribute_ipv4_metric_rmap,
11933 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11934 "redistribute " FRR_IP_REDIST_STR_BGPD
11935 " metric (0-4294967295) route-map WORD",
11936 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11937 "Metric for redistributed routes\n"
11938 "Default metric\n"
11939 "Route map reference\n"
11940 "Pointer to route-map entries\n")
11941
11942 DEFUN (bgp_redistribute_ipv4_ospf,
11943 bgp_redistribute_ipv4_ospf_cmd,
11944 "redistribute <ospf|table> (1-65535)",
11945 "Redistribute information from another routing protocol\n"
11946 "Open Shortest Path First (OSPFv2)\n"
11947 "Non-main Kernel Routing Table\n"
11948 "Instance ID/Table ID\n")
11949 {
11950 VTY_DECLVAR_CONTEXT(bgp, bgp);
11951 int idx_ospf_table = 1;
11952 int idx_number = 2;
11953 unsigned short instance;
11954 unsigned short protocol;
11955
11956 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11957
11958 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11959 protocol = ZEBRA_ROUTE_OSPF;
11960 else
11961 protocol = ZEBRA_ROUTE_TABLE;
11962
11963 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11964 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
11965 }
11966
11967 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11968 "redistribute <ospf|table> (1-65535)",
11969 "Redistribute information from another routing protocol\n"
11970 "Open Shortest Path First (OSPFv2)\n"
11971 "Non-main Kernel Routing Table\n"
11972 "Instance ID/Table ID\n")
11973
11974 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11975 bgp_redistribute_ipv4_ospf_rmap_cmd,
11976 "redistribute <ospf|table> (1-65535) route-map WORD",
11977 "Redistribute information from another routing protocol\n"
11978 "Open Shortest Path First (OSPFv2)\n"
11979 "Non-main Kernel Routing Table\n"
11980 "Instance ID/Table ID\n"
11981 "Route map reference\n"
11982 "Pointer to route-map entries\n")
11983 {
11984 VTY_DECLVAR_CONTEXT(bgp, bgp);
11985 int idx_ospf_table = 1;
11986 int idx_number = 2;
11987 int idx_word = 4;
11988 struct bgp_redist *red;
11989 unsigned short instance;
11990 int protocol;
11991 bool changed;
11992 struct route_map *route_map =
11993 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11994
11995 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11996 protocol = ZEBRA_ROUTE_OSPF;
11997 else
11998 protocol = ZEBRA_ROUTE_TABLE;
11999
12000 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12001 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12002 changed =
12003 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12004 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12005 }
12006
12007 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
12008 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
12009 "redistribute <ospf|table> (1-65535) route-map WORD",
12010 "Redistribute information from another routing protocol\n"
12011 "Open Shortest Path First (OSPFv2)\n"
12012 "Non-main Kernel Routing Table\n"
12013 "Instance ID/Table ID\n"
12014 "Route map reference\n"
12015 "Pointer to route-map entries\n")
12016
12017 DEFUN (bgp_redistribute_ipv4_ospf_metric,
12018 bgp_redistribute_ipv4_ospf_metric_cmd,
12019 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12020 "Redistribute information from another routing protocol\n"
12021 "Open Shortest Path First (OSPFv2)\n"
12022 "Non-main Kernel Routing Table\n"
12023 "Instance ID/Table ID\n"
12024 "Metric for redistributed routes\n"
12025 "Default metric\n")
12026 {
12027 VTY_DECLVAR_CONTEXT(bgp, bgp);
12028 int idx_ospf_table = 1;
12029 int idx_number = 2;
12030 int idx_number_2 = 4;
12031 uint32_t metric;
12032 struct bgp_redist *red;
12033 unsigned short instance;
12034 int protocol;
12035 bool changed;
12036
12037 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12038 protocol = ZEBRA_ROUTE_OSPF;
12039 else
12040 protocol = ZEBRA_ROUTE_TABLE;
12041
12042 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12043 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12044
12045 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12046 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12047 metric);
12048 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12049 }
12050
12051 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
12052 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
12053 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
12054 "Redistribute information from another routing protocol\n"
12055 "Open Shortest Path First (OSPFv2)\n"
12056 "Non-main Kernel Routing Table\n"
12057 "Instance ID/Table ID\n"
12058 "Metric for redistributed routes\n"
12059 "Default metric\n")
12060
12061 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
12062 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
12063 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12064 "Redistribute information from another routing protocol\n"
12065 "Open Shortest Path First (OSPFv2)\n"
12066 "Non-main Kernel Routing Table\n"
12067 "Instance ID/Table ID\n"
12068 "Route map reference\n"
12069 "Pointer to route-map entries\n"
12070 "Metric for redistributed routes\n"
12071 "Default metric\n")
12072 {
12073 VTY_DECLVAR_CONTEXT(bgp, bgp);
12074 int idx_ospf_table = 1;
12075 int idx_number = 2;
12076 int idx_word = 4;
12077 int idx_number_2 = 6;
12078 uint32_t metric;
12079 struct bgp_redist *red;
12080 unsigned short instance;
12081 int protocol;
12082 bool changed;
12083 struct route_map *route_map =
12084 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12085
12086 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12087 protocol = ZEBRA_ROUTE_OSPF;
12088 else
12089 protocol = ZEBRA_ROUTE_TABLE;
12090
12091 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12092 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12093
12094 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12095 changed =
12096 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12097 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12098 metric);
12099 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12100 }
12101
12102 ALIAS_HIDDEN(
12103 bgp_redistribute_ipv4_ospf_rmap_metric,
12104 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
12105 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12106 "Redistribute information from another routing protocol\n"
12107 "Open Shortest Path First (OSPFv2)\n"
12108 "Non-main Kernel Routing Table\n"
12109 "Instance ID/Table ID\n"
12110 "Route map reference\n"
12111 "Pointer to route-map entries\n"
12112 "Metric for redistributed routes\n"
12113 "Default metric\n")
12114
12115 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12116 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12117 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12118 "Redistribute information from another routing protocol\n"
12119 "Open Shortest Path First (OSPFv2)\n"
12120 "Non-main Kernel Routing Table\n"
12121 "Instance ID/Table ID\n"
12122 "Metric for redistributed routes\n"
12123 "Default metric\n"
12124 "Route map reference\n"
12125 "Pointer to route-map entries\n")
12126 {
12127 VTY_DECLVAR_CONTEXT(bgp, bgp);
12128 int idx_ospf_table = 1;
12129 int idx_number = 2;
12130 int idx_number_2 = 4;
12131 int idx_word = 6;
12132 uint32_t metric;
12133 struct bgp_redist *red;
12134 unsigned short instance;
12135 int protocol;
12136 bool changed;
12137 struct route_map *route_map =
12138 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12139
12140 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12141 protocol = ZEBRA_ROUTE_OSPF;
12142 else
12143 protocol = ZEBRA_ROUTE_TABLE;
12144
12145 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12146 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12147
12148 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12149 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12150 metric);
12151 changed |=
12152 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12153 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12154 }
12155
12156 ALIAS_HIDDEN(
12157 bgp_redistribute_ipv4_ospf_metric_rmap,
12158 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12159 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12160 "Redistribute information from another routing protocol\n"
12161 "Open Shortest Path First (OSPFv2)\n"
12162 "Non-main Kernel Routing Table\n"
12163 "Instance ID/Table ID\n"
12164 "Metric for redistributed routes\n"
12165 "Default metric\n"
12166 "Route map reference\n"
12167 "Pointer to route-map entries\n")
12168
12169 DEFUN (no_bgp_redistribute_ipv4_ospf,
12170 no_bgp_redistribute_ipv4_ospf_cmd,
12171 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12172 NO_STR
12173 "Redistribute information from another routing protocol\n"
12174 "Open Shortest Path First (OSPFv2)\n"
12175 "Non-main Kernel Routing Table\n"
12176 "Instance ID/Table ID\n"
12177 "Metric for redistributed routes\n"
12178 "Default metric\n"
12179 "Route map reference\n"
12180 "Pointer to route-map entries\n")
12181 {
12182 VTY_DECLVAR_CONTEXT(bgp, bgp);
12183 int idx_ospf_table = 2;
12184 int idx_number = 3;
12185 unsigned short instance;
12186 int protocol;
12187
12188 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12189 protocol = ZEBRA_ROUTE_OSPF;
12190 else
12191 protocol = ZEBRA_ROUTE_TABLE;
12192
12193 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12194 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12195 }
12196
12197 ALIAS_HIDDEN(
12198 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12199 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12200 NO_STR
12201 "Redistribute information from another routing protocol\n"
12202 "Open Shortest Path First (OSPFv2)\n"
12203 "Non-main Kernel Routing Table\n"
12204 "Instance ID/Table ID\n"
12205 "Metric for redistributed routes\n"
12206 "Default metric\n"
12207 "Route map reference\n"
12208 "Pointer to route-map entries\n")
12209
12210 DEFUN (no_bgp_redistribute_ipv4,
12211 no_bgp_redistribute_ipv4_cmd,
12212 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12213 NO_STR
12214 "Redistribute information from another routing protocol\n"
12215 FRR_IP_REDIST_HELP_STR_BGPD
12216 "Metric for redistributed routes\n"
12217 "Default metric\n"
12218 "Route map reference\n"
12219 "Pointer to route-map entries\n")
12220 {
12221 VTY_DECLVAR_CONTEXT(bgp, bgp);
12222 int idx_protocol = 2;
12223 int type;
12224
12225 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12226 if (type < 0) {
12227 vty_out(vty, "%% Invalid route type\n");
12228 return CMD_WARNING_CONFIG_FAILED;
12229 }
12230 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12231 }
12232
12233 ALIAS_HIDDEN(
12234 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12235 "no redistribute " FRR_IP_REDIST_STR_BGPD
12236 " [metric (0-4294967295)] [route-map WORD]",
12237 NO_STR
12238 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12239 "Metric for redistributed routes\n"
12240 "Default metric\n"
12241 "Route map reference\n"
12242 "Pointer to route-map entries\n")
12243
12244 DEFUN (bgp_redistribute_ipv6,
12245 bgp_redistribute_ipv6_cmd,
12246 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12247 "Redistribute information from another routing protocol\n"
12248 FRR_IP6_REDIST_HELP_STR_BGPD)
12249 {
12250 VTY_DECLVAR_CONTEXT(bgp, bgp);
12251 int idx_protocol = 1;
12252 int type;
12253
12254 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12255 if (type < 0) {
12256 vty_out(vty, "%% Invalid route type\n");
12257 return CMD_WARNING_CONFIG_FAILED;
12258 }
12259
12260 bgp_redist_add(bgp, AFI_IP6, type, 0);
12261 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12262 }
12263
12264 DEFUN (bgp_redistribute_ipv6_rmap,
12265 bgp_redistribute_ipv6_rmap_cmd,
12266 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12267 "Redistribute information from another routing protocol\n"
12268 FRR_IP6_REDIST_HELP_STR_BGPD
12269 "Route map reference\n"
12270 "Pointer to route-map entries\n")
12271 {
12272 VTY_DECLVAR_CONTEXT(bgp, bgp);
12273 int idx_protocol = 1;
12274 int idx_word = 3;
12275 int type;
12276 struct bgp_redist *red;
12277 bool changed;
12278 struct route_map *route_map =
12279 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12280
12281 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12282 if (type < 0) {
12283 vty_out(vty, "%% Invalid route type\n");
12284 return CMD_WARNING_CONFIG_FAILED;
12285 }
12286
12287 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12288 changed =
12289 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12290 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12291 }
12292
12293 DEFUN (bgp_redistribute_ipv6_metric,
12294 bgp_redistribute_ipv6_metric_cmd,
12295 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12296 "Redistribute information from another routing protocol\n"
12297 FRR_IP6_REDIST_HELP_STR_BGPD
12298 "Metric for redistributed routes\n"
12299 "Default metric\n")
12300 {
12301 VTY_DECLVAR_CONTEXT(bgp, bgp);
12302 int idx_protocol = 1;
12303 int idx_number = 3;
12304 int type;
12305 uint32_t metric;
12306 struct bgp_redist *red;
12307 bool changed;
12308
12309 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12310 if (type < 0) {
12311 vty_out(vty, "%% Invalid route type\n");
12312 return CMD_WARNING_CONFIG_FAILED;
12313 }
12314 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12315
12316 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12317 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12318 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12319 }
12320
12321 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12322 bgp_redistribute_ipv6_rmap_metric_cmd,
12323 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12324 "Redistribute information from another routing protocol\n"
12325 FRR_IP6_REDIST_HELP_STR_BGPD
12326 "Route map reference\n"
12327 "Pointer to route-map entries\n"
12328 "Metric for redistributed routes\n"
12329 "Default metric\n")
12330 {
12331 VTY_DECLVAR_CONTEXT(bgp, bgp);
12332 int idx_protocol = 1;
12333 int idx_word = 3;
12334 int idx_number = 5;
12335 int type;
12336 uint32_t metric;
12337 struct bgp_redist *red;
12338 bool changed;
12339 struct route_map *route_map =
12340 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12341
12342 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12343 if (type < 0) {
12344 vty_out(vty, "%% Invalid route type\n");
12345 return CMD_WARNING_CONFIG_FAILED;
12346 }
12347 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12348
12349 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12350 changed =
12351 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12352 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12353 metric);
12354 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12355 }
12356
12357 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12358 bgp_redistribute_ipv6_metric_rmap_cmd,
12359 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12360 "Redistribute information from another routing protocol\n"
12361 FRR_IP6_REDIST_HELP_STR_BGPD
12362 "Metric for redistributed routes\n"
12363 "Default metric\n"
12364 "Route map reference\n"
12365 "Pointer to route-map entries\n")
12366 {
12367 VTY_DECLVAR_CONTEXT(bgp, bgp);
12368 int idx_protocol = 1;
12369 int idx_number = 3;
12370 int idx_word = 5;
12371 int type;
12372 uint32_t metric;
12373 struct bgp_redist *red;
12374 bool changed;
12375 struct route_map *route_map =
12376 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12377
12378 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12379 if (type < 0) {
12380 vty_out(vty, "%% Invalid route type\n");
12381 return CMD_WARNING_CONFIG_FAILED;
12382 }
12383 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12384
12385 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12386 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12387 metric);
12388 changed |=
12389 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12390 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12391 }
12392
12393 DEFUN (no_bgp_redistribute_ipv6,
12394 no_bgp_redistribute_ipv6_cmd,
12395 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12396 NO_STR
12397 "Redistribute information from another routing protocol\n"
12398 FRR_IP6_REDIST_HELP_STR_BGPD
12399 "Metric for redistributed routes\n"
12400 "Default metric\n"
12401 "Route map reference\n"
12402 "Pointer to route-map entries\n")
12403 {
12404 VTY_DECLVAR_CONTEXT(bgp, bgp);
12405 int idx_protocol = 2;
12406 int type;
12407
12408 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12409 if (type < 0) {
12410 vty_out(vty, "%% Invalid route type\n");
12411 return CMD_WARNING_CONFIG_FAILED;
12412 }
12413
12414 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12415 }
12416
12417 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12418 safi_t safi)
12419 {
12420 int i;
12421
12422 /* Unicast redistribution only. */
12423 if (safi != SAFI_UNICAST)
12424 return;
12425
12426 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12427 /* Redistribute BGP does not make sense. */
12428 if (i != ZEBRA_ROUTE_BGP) {
12429 struct list *red_list;
12430 struct listnode *node;
12431 struct bgp_redist *red;
12432
12433 red_list = bgp->redist[afi][i];
12434 if (!red_list)
12435 continue;
12436
12437 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12438 /* "redistribute" configuration. */
12439 vty_out(vty, " redistribute %s",
12440 zebra_route_string(i));
12441 if (red->instance)
12442 vty_out(vty, " %d", red->instance);
12443 if (red->redist_metric_flag)
12444 vty_out(vty, " metric %u",
12445 red->redist_metric);
12446 if (red->rmap.name)
12447 vty_out(vty, " route-map %s",
12448 red->rmap.name);
12449 vty_out(vty, "\n");
12450 }
12451 }
12452 }
12453 }
12454
12455 /* This is part of the address-family block (unicast only) */
12456 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12457 afi_t afi)
12458 {
12459 int indent = 2;
12460
12461 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12462 if (listcount(bgp->vpn_policy[afi].import_vrf))
12463 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12464 bgp->vpn_policy[afi]
12465 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12466 else
12467 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12468 bgp->vpn_policy[afi]
12469 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12470 }
12471 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12472 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12473 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12474 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12475 return;
12476
12477 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12478 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12479
12480 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12481
12482 } else {
12483 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12484 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12485 bgp->vpn_policy[afi].tovpn_label);
12486 }
12487 }
12488 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12489 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12490 char buf[RD_ADDRSTRLEN];
12491 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12492 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12493 sizeof(buf)));
12494 }
12495 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12496 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12497
12498 char buf[PREFIX_STRLEN];
12499 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12500 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12501 sizeof(buf))) {
12502
12503 vty_out(vty, "%*snexthop vpn export %s\n",
12504 indent, "", buf);
12505 }
12506 }
12507 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12508 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12509 && ecommunity_cmp(
12510 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12511 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12512
12513 char *b = ecommunity_ecom2str(
12514 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12515 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12516 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12517 XFREE(MTYPE_ECOMMUNITY_STR, b);
12518 } else {
12519 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12520 char *b = ecommunity_ecom2str(
12521 bgp->vpn_policy[afi]
12522 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12523 ECOMMUNITY_FORMAT_ROUTE_MAP,
12524 ECOMMUNITY_ROUTE_TARGET);
12525 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12526 XFREE(MTYPE_ECOMMUNITY_STR, b);
12527 }
12528 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12529 char *b = ecommunity_ecom2str(
12530 bgp->vpn_policy[afi]
12531 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12532 ECOMMUNITY_FORMAT_ROUTE_MAP,
12533 ECOMMUNITY_ROUTE_TARGET);
12534 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12535 XFREE(MTYPE_ECOMMUNITY_STR, b);
12536 }
12537 }
12538
12539 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12540 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12541 bgp->vpn_policy[afi]
12542 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12543
12544 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12545 char *b = ecommunity_ecom2str(
12546 bgp->vpn_policy[afi]
12547 .import_redirect_rtlist,
12548 ECOMMUNITY_FORMAT_ROUTE_MAP,
12549 ECOMMUNITY_ROUTE_TARGET);
12550
12551 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12552 XFREE(MTYPE_ECOMMUNITY_STR, b);
12553 }
12554 }
12555
12556
12557 /* BGP node structure. */
12558 static struct cmd_node bgp_node = {
12559 BGP_NODE, "%s(config-router)# ", 1,
12560 };
12561
12562 static struct cmd_node bgp_ipv4_unicast_node = {
12563 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12564 };
12565
12566 static struct cmd_node bgp_ipv4_multicast_node = {
12567 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12568 };
12569
12570 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12571 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12572 };
12573
12574 static struct cmd_node bgp_ipv6_unicast_node = {
12575 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12576 };
12577
12578 static struct cmd_node bgp_ipv6_multicast_node = {
12579 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12580 };
12581
12582 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12583 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12584 };
12585
12586 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12587 "%s(config-router-af)# ", 1};
12588
12589 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12590 "%s(config-router-af-vpnv6)# ", 1};
12591
12592 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12593 "%s(config-router-evpn)# ", 1};
12594
12595 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12596 "%s(config-router-af-vni)# ", 1};
12597
12598 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12599 "%s(config-router-af)# ", 1};
12600
12601 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12602 "%s(config-router-af-vpnv6)# ", 1};
12603
12604 static void community_list_vty(void);
12605
12606 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12607 {
12608 struct bgp *bgp;
12609 struct peer *peer;
12610 struct listnode *lnbgp, *lnpeer;
12611
12612 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12613 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12614 /* only provide suggestions on the appropriate input
12615 * token type,
12616 * they'll otherwise show up multiple times */
12617 enum cmd_token_type match_type;
12618 char *name = peer->host;
12619
12620 if (peer->conf_if) {
12621 match_type = VARIABLE_TKN;
12622 name = peer->conf_if;
12623 } else if (strchr(peer->host, ':'))
12624 match_type = IPV6_TKN;
12625 else
12626 match_type = IPV4_TKN;
12627
12628 if (token->type != match_type)
12629 continue;
12630
12631 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12632 }
12633 }
12634 }
12635
12636 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12637 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12638 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12639 {.varname = "peer", .completions = bgp_ac_neighbor},
12640 {.completions = NULL}};
12641
12642 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12643 {
12644 struct bgp *bgp;
12645 struct peer_group *group;
12646 struct listnode *lnbgp, *lnpeer;
12647
12648 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12649 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12650 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12651 group->name));
12652 }
12653 }
12654
12655 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12656 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12657 {.completions = NULL} };
12658
12659 void bgp_vty_init(void)
12660 {
12661 cmd_variable_handler_register(bgp_var_neighbor);
12662 cmd_variable_handler_register(bgp_var_peergroup);
12663
12664 /* Install bgp top node. */
12665 install_node(&bgp_node, bgp_config_write);
12666 install_node(&bgp_ipv4_unicast_node, NULL);
12667 install_node(&bgp_ipv4_multicast_node, NULL);
12668 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12669 install_node(&bgp_ipv6_unicast_node, NULL);
12670 install_node(&bgp_ipv6_multicast_node, NULL);
12671 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12672 install_node(&bgp_vpnv4_node, NULL);
12673 install_node(&bgp_vpnv6_node, NULL);
12674 install_node(&bgp_evpn_node, NULL);
12675 install_node(&bgp_evpn_vni_node, NULL);
12676 install_node(&bgp_flowspecv4_node, NULL);
12677 install_node(&bgp_flowspecv6_node, NULL);
12678
12679 /* Install default VTY commands to new nodes. */
12680 install_default(BGP_NODE);
12681 install_default(BGP_IPV4_NODE);
12682 install_default(BGP_IPV4M_NODE);
12683 install_default(BGP_IPV4L_NODE);
12684 install_default(BGP_IPV6_NODE);
12685 install_default(BGP_IPV6M_NODE);
12686 install_default(BGP_IPV6L_NODE);
12687 install_default(BGP_VPNV4_NODE);
12688 install_default(BGP_VPNV6_NODE);
12689 install_default(BGP_FLOWSPECV4_NODE);
12690 install_default(BGP_FLOWSPECV6_NODE);
12691 install_default(BGP_EVPN_NODE);
12692 install_default(BGP_EVPN_VNI_NODE);
12693
12694 /* "bgp multiple-instance" commands. */
12695 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12696 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12697
12698 /* "bgp config-type" commands. */
12699 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12700 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12701
12702 /* "bgp local-mac" hidden commands. */
12703 install_element(CONFIG_NODE, &bgp_local_mac_cmd);
12704 install_element(CONFIG_NODE, &no_bgp_local_mac_cmd);
12705
12706 /* bgp route-map delay-timer commands. */
12707 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12708 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12709
12710 /* Dummy commands (Currently not supported) */
12711 install_element(BGP_NODE, &no_synchronization_cmd);
12712 install_element(BGP_NODE, &no_auto_summary_cmd);
12713
12714 /* "router bgp" commands. */
12715 install_element(CONFIG_NODE, &router_bgp_cmd);
12716
12717 /* "no router bgp" commands. */
12718 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12719
12720 /* "bgp router-id" commands. */
12721 install_element(BGP_NODE, &bgp_router_id_cmd);
12722 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12723
12724 /* "bgp cluster-id" commands. */
12725 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12726 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12727
12728 /* "bgp confederation" commands. */
12729 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12730 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12731
12732 /* "bgp confederation peers" commands. */
12733 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12734 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12735
12736 /* bgp max-med command */
12737 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12738 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12739 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12740 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12741 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12742
12743 /* bgp disable-ebgp-connected-nh-check */
12744 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12745 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12746
12747 /* bgp update-delay command */
12748 install_element(BGP_NODE, &bgp_update_delay_cmd);
12749 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12750 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12751
12752 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12753 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12754 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12755 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12756
12757 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12758 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12759
12760 /* "maximum-paths" commands. */
12761 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12762 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12763 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12764 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12765 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12766 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12767 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12768 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12769 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12770 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12771 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12772 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12773 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12774 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12775 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12776
12777 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12778 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12779 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12780 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12781 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12782
12783 /* "timers bgp" commands. */
12784 install_element(BGP_NODE, &bgp_timers_cmd);
12785 install_element(BGP_NODE, &no_bgp_timers_cmd);
12786
12787 /* route-map delay-timer commands - per instance for backwards compat.
12788 */
12789 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12790 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12791
12792 /* "bgp client-to-client reflection" commands */
12793 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12794 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12795
12796 /* "bgp always-compare-med" commands */
12797 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12798 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12799
12800 /* "bgp deterministic-med" commands */
12801 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12802 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12803
12804 /* "bgp graceful-restart" commands */
12805 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12806 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12807 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12808 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12809 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12810 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12811
12812 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12813 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12814
12815 /* "bgp graceful-shutdown" commands */
12816 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12817 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12818
12819 /* "bgp fast-external-failover" commands */
12820 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12821 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12822
12823 /* "bgp enforce-first-as" commands */
12824 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12825
12826 /* "bgp bestpath compare-routerid" commands */
12827 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12828 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12829
12830 /* "bgp bestpath as-path ignore" commands */
12831 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12832 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12833
12834 /* "bgp bestpath as-path confed" commands */
12835 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12836 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12837
12838 /* "bgp bestpath as-path multipath-relax" commands */
12839 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12840 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12841
12842 /* "bgp log-neighbor-changes" commands */
12843 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12844 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12845
12846 /* "bgp bestpath med" commands */
12847 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12848 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12849
12850 /* "no bgp default ipv4-unicast" commands. */
12851 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12852 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12853
12854 /* "bgp network import-check" commands. */
12855 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12856 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12857 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12858
12859 /* "bgp default local-preference" commands. */
12860 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12861 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12862
12863 /* bgp default show-hostname */
12864 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12865 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12866
12867 /* "bgp default subgroup-pkt-queue-max" commands. */
12868 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12869 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12870
12871 /* bgp ibgp-allow-policy-mods command */
12872 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12873 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12874
12875 /* "bgp listen limit" commands. */
12876 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12877 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12878
12879 /* "bgp listen range" commands. */
12880 install_element(BGP_NODE, &bgp_listen_range_cmd);
12881 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12882
12883 /* "bgp default shutdown" command */
12884 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12885
12886 /* "neighbor remote-as" commands. */
12887 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12888 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12889 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12890 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12891 install_element(BGP_NODE,
12892 &neighbor_interface_v6only_config_remote_as_cmd);
12893 install_element(BGP_NODE, &no_neighbor_cmd);
12894 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12895
12896 /* "neighbor peer-group" commands. */
12897 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12898 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12899 install_element(BGP_NODE,
12900 &no_neighbor_interface_peer_group_remote_as_cmd);
12901
12902 /* "neighbor local-as" commands. */
12903 install_element(BGP_NODE, &neighbor_local_as_cmd);
12904 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12905 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12906 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12907
12908 /* "neighbor solo" commands. */
12909 install_element(BGP_NODE, &neighbor_solo_cmd);
12910 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12911
12912 /* "neighbor password" commands. */
12913 install_element(BGP_NODE, &neighbor_password_cmd);
12914 install_element(BGP_NODE, &no_neighbor_password_cmd);
12915
12916 /* "neighbor activate" commands. */
12917 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12918 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12919 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12920 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12921 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12922 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12923 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12924 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12925 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12926 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12927 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12928 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12929
12930 /* "no neighbor activate" commands. */
12931 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12932 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12933 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12934 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12935 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12936 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12937 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12938 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12939 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12940 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12941 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12942 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12943
12944 /* "neighbor peer-group" set commands. */
12945 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12946 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12947 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12948 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12949 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12950 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12951 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12952 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12953 install_element(BGP_FLOWSPECV4_NODE,
12954 &neighbor_set_peer_group_hidden_cmd);
12955 install_element(BGP_FLOWSPECV6_NODE,
12956 &neighbor_set_peer_group_hidden_cmd);
12957
12958 /* "no neighbor peer-group unset" commands. */
12959 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12960 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12961 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12962 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12963 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12964 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12965 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12966 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12967 install_element(BGP_FLOWSPECV4_NODE,
12968 &no_neighbor_set_peer_group_hidden_cmd);
12969 install_element(BGP_FLOWSPECV6_NODE,
12970 &no_neighbor_set_peer_group_hidden_cmd);
12971
12972 /* "neighbor softreconfiguration inbound" commands.*/
12973 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12974 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12975 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12976 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12977 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12978 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12979 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12980 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12981 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12982 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12983 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12984 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12985 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12986 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12987 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12988 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12989 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12990 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12991 install_element(BGP_FLOWSPECV4_NODE,
12992 &neighbor_soft_reconfiguration_cmd);
12993 install_element(BGP_FLOWSPECV4_NODE,
12994 &no_neighbor_soft_reconfiguration_cmd);
12995 install_element(BGP_FLOWSPECV6_NODE,
12996 &neighbor_soft_reconfiguration_cmd);
12997 install_element(BGP_FLOWSPECV6_NODE,
12998 &no_neighbor_soft_reconfiguration_cmd);
12999
13000 /* "neighbor attribute-unchanged" commands. */
13001 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
13002 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
13003 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
13004 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
13005 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
13006 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
13007 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
13008 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
13009 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
13010 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
13011 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
13012 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
13013 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
13014 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
13015 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
13016 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
13017 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
13018 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
13019
13020 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
13021 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
13022
13023 /* "nexthop-local unchanged" commands */
13024 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
13025 install_element(BGP_IPV6_NODE,
13026 &no_neighbor_nexthop_local_unchanged_cmd);
13027
13028 /* "neighbor next-hop-self" commands. */
13029 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
13030 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
13031 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
13032 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
13033 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
13034 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
13035 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
13036 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
13037 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
13038 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
13039 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
13040 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
13041 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
13042 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
13043 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
13044 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
13045 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
13046 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
13047 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
13048 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
13049
13050 /* "neighbor next-hop-self force" commands. */
13051 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
13052 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
13053 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
13054 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13055 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
13056 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
13057 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
13058 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
13059 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
13060 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13061 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
13062 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
13063 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
13064 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
13065 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
13066 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
13067 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
13068 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
13069
13070 /* "neighbor as-override" commands. */
13071 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
13072 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
13073 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
13074 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
13075 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
13076 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
13077 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
13078 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
13079 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
13080 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
13081 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
13082 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
13083 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
13084 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
13085 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
13086 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
13087 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
13088 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
13089
13090 /* "neighbor remove-private-AS" commands. */
13091 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
13092 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
13093 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
13094 install_element(BGP_NODE,
13095 &no_neighbor_remove_private_as_all_hidden_cmd);
13096 install_element(BGP_NODE,
13097 &neighbor_remove_private_as_replace_as_hidden_cmd);
13098 install_element(BGP_NODE,
13099 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
13100 install_element(BGP_NODE,
13101 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
13102 install_element(
13103 BGP_NODE,
13104 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
13105 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
13106 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
13107 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
13108 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13109 install_element(BGP_IPV4_NODE,
13110 &neighbor_remove_private_as_replace_as_cmd);
13111 install_element(BGP_IPV4_NODE,
13112 &no_neighbor_remove_private_as_replace_as_cmd);
13113 install_element(BGP_IPV4_NODE,
13114 &neighbor_remove_private_as_all_replace_as_cmd);
13115 install_element(BGP_IPV4_NODE,
13116 &no_neighbor_remove_private_as_all_replace_as_cmd);
13117 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13118 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13119 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13120 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13121 install_element(BGP_IPV4M_NODE,
13122 &neighbor_remove_private_as_replace_as_cmd);
13123 install_element(BGP_IPV4M_NODE,
13124 &no_neighbor_remove_private_as_replace_as_cmd);
13125 install_element(BGP_IPV4M_NODE,
13126 &neighbor_remove_private_as_all_replace_as_cmd);
13127 install_element(BGP_IPV4M_NODE,
13128 &no_neighbor_remove_private_as_all_replace_as_cmd);
13129 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13130 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13131 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13132 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13133 install_element(BGP_IPV4L_NODE,
13134 &neighbor_remove_private_as_replace_as_cmd);
13135 install_element(BGP_IPV4L_NODE,
13136 &no_neighbor_remove_private_as_replace_as_cmd);
13137 install_element(BGP_IPV4L_NODE,
13138 &neighbor_remove_private_as_all_replace_as_cmd);
13139 install_element(BGP_IPV4L_NODE,
13140 &no_neighbor_remove_private_as_all_replace_as_cmd);
13141 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13142 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13143 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13144 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13145 install_element(BGP_IPV6_NODE,
13146 &neighbor_remove_private_as_replace_as_cmd);
13147 install_element(BGP_IPV6_NODE,
13148 &no_neighbor_remove_private_as_replace_as_cmd);
13149 install_element(BGP_IPV6_NODE,
13150 &neighbor_remove_private_as_all_replace_as_cmd);
13151 install_element(BGP_IPV6_NODE,
13152 &no_neighbor_remove_private_as_all_replace_as_cmd);
13153 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13154 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13155 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13156 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13157 install_element(BGP_IPV6M_NODE,
13158 &neighbor_remove_private_as_replace_as_cmd);
13159 install_element(BGP_IPV6M_NODE,
13160 &no_neighbor_remove_private_as_replace_as_cmd);
13161 install_element(BGP_IPV6M_NODE,
13162 &neighbor_remove_private_as_all_replace_as_cmd);
13163 install_element(BGP_IPV6M_NODE,
13164 &no_neighbor_remove_private_as_all_replace_as_cmd);
13165 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13166 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13167 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13168 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13169 install_element(BGP_IPV6L_NODE,
13170 &neighbor_remove_private_as_replace_as_cmd);
13171 install_element(BGP_IPV6L_NODE,
13172 &no_neighbor_remove_private_as_replace_as_cmd);
13173 install_element(BGP_IPV6L_NODE,
13174 &neighbor_remove_private_as_all_replace_as_cmd);
13175 install_element(BGP_IPV6L_NODE,
13176 &no_neighbor_remove_private_as_all_replace_as_cmd);
13177 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13178 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13179 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13180 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13181 install_element(BGP_VPNV4_NODE,
13182 &neighbor_remove_private_as_replace_as_cmd);
13183 install_element(BGP_VPNV4_NODE,
13184 &no_neighbor_remove_private_as_replace_as_cmd);
13185 install_element(BGP_VPNV4_NODE,
13186 &neighbor_remove_private_as_all_replace_as_cmd);
13187 install_element(BGP_VPNV4_NODE,
13188 &no_neighbor_remove_private_as_all_replace_as_cmd);
13189 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13190 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13191 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13192 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13193 install_element(BGP_VPNV6_NODE,
13194 &neighbor_remove_private_as_replace_as_cmd);
13195 install_element(BGP_VPNV6_NODE,
13196 &no_neighbor_remove_private_as_replace_as_cmd);
13197 install_element(BGP_VPNV6_NODE,
13198 &neighbor_remove_private_as_all_replace_as_cmd);
13199 install_element(BGP_VPNV6_NODE,
13200 &no_neighbor_remove_private_as_all_replace_as_cmd);
13201
13202 /* "neighbor send-community" commands.*/
13203 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13204 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13205 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13206 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13207 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13208 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13209 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13210 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13211 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13212 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13213 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13214 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13215 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13216 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13217 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13218 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13219 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13220 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13221 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13222 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13223 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13224 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13225 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13226 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13227 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13228 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13229 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13230 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13231 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13232 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13233 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13234 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13235 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13236 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13237 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13238 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13239
13240 /* "neighbor route-reflector" commands.*/
13241 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13242 install_element(BGP_NODE,
13243 &no_neighbor_route_reflector_client_hidden_cmd);
13244 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13245 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13246 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13247 install_element(BGP_IPV4M_NODE,
13248 &no_neighbor_route_reflector_client_cmd);
13249 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13250 install_element(BGP_IPV4L_NODE,
13251 &no_neighbor_route_reflector_client_cmd);
13252 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13253 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13254 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13255 install_element(BGP_IPV6M_NODE,
13256 &no_neighbor_route_reflector_client_cmd);
13257 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13258 install_element(BGP_IPV6L_NODE,
13259 &no_neighbor_route_reflector_client_cmd);
13260 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13261 install_element(BGP_VPNV4_NODE,
13262 &no_neighbor_route_reflector_client_cmd);
13263 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13264 install_element(BGP_VPNV6_NODE,
13265 &no_neighbor_route_reflector_client_cmd);
13266 install_element(BGP_FLOWSPECV4_NODE,
13267 &neighbor_route_reflector_client_cmd);
13268 install_element(BGP_FLOWSPECV4_NODE,
13269 &no_neighbor_route_reflector_client_cmd);
13270 install_element(BGP_FLOWSPECV6_NODE,
13271 &neighbor_route_reflector_client_cmd);
13272 install_element(BGP_FLOWSPECV6_NODE,
13273 &no_neighbor_route_reflector_client_cmd);
13274 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13275 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13276
13277 /* "neighbor route-server" commands.*/
13278 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13279 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13280 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13281 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13282 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13283 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13284 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13285 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13286 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13287 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13288 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13289 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13290 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13291 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13292 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13293 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13294 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13295 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13296 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13297 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13298 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13299 install_element(BGP_FLOWSPECV4_NODE,
13300 &no_neighbor_route_server_client_cmd);
13301 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13302 install_element(BGP_FLOWSPECV6_NODE,
13303 &no_neighbor_route_server_client_cmd);
13304
13305 /* "neighbor addpath-tx-all-paths" commands.*/
13306 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13307 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13308 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13309 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13310 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13311 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13312 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13313 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13314 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13315 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13316 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13317 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13318 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13319 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13320 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13321 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13322 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13323 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13324
13325 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13326 install_element(BGP_NODE,
13327 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13328 install_element(BGP_NODE,
13329 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13330 install_element(BGP_IPV4_NODE,
13331 &neighbor_addpath_tx_bestpath_per_as_cmd);
13332 install_element(BGP_IPV4_NODE,
13333 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13334 install_element(BGP_IPV4M_NODE,
13335 &neighbor_addpath_tx_bestpath_per_as_cmd);
13336 install_element(BGP_IPV4M_NODE,
13337 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13338 install_element(BGP_IPV4L_NODE,
13339 &neighbor_addpath_tx_bestpath_per_as_cmd);
13340 install_element(BGP_IPV4L_NODE,
13341 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13342 install_element(BGP_IPV6_NODE,
13343 &neighbor_addpath_tx_bestpath_per_as_cmd);
13344 install_element(BGP_IPV6_NODE,
13345 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13346 install_element(BGP_IPV6M_NODE,
13347 &neighbor_addpath_tx_bestpath_per_as_cmd);
13348 install_element(BGP_IPV6M_NODE,
13349 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13350 install_element(BGP_IPV6L_NODE,
13351 &neighbor_addpath_tx_bestpath_per_as_cmd);
13352 install_element(BGP_IPV6L_NODE,
13353 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13354 install_element(BGP_VPNV4_NODE,
13355 &neighbor_addpath_tx_bestpath_per_as_cmd);
13356 install_element(BGP_VPNV4_NODE,
13357 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13358 install_element(BGP_VPNV6_NODE,
13359 &neighbor_addpath_tx_bestpath_per_as_cmd);
13360 install_element(BGP_VPNV6_NODE,
13361 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13362
13363 /* "neighbor passive" commands. */
13364 install_element(BGP_NODE, &neighbor_passive_cmd);
13365 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13366
13367
13368 /* "neighbor shutdown" commands. */
13369 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13370 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13371 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13372 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13373
13374 /* "neighbor capability extended-nexthop" commands.*/
13375 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13376 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13377
13378 /* "neighbor capability orf prefix-list" commands.*/
13379 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13380 install_element(BGP_NODE,
13381 &no_neighbor_capability_orf_prefix_hidden_cmd);
13382 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13383 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13384 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13385 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13386 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13387 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13388 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13389 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13390 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13391 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13392 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13393 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13394
13395 /* "neighbor capability dynamic" commands.*/
13396 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13397 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13398
13399 /* "neighbor dont-capability-negotiate" commands. */
13400 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13401 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13402
13403 /* "neighbor ebgp-multihop" commands. */
13404 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13405 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13406 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13407
13408 /* "neighbor disable-connected-check" commands. */
13409 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13410 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13411
13412 /* "neighbor enforce-first-as" commands. */
13413 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13414 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13415
13416 /* "neighbor description" commands. */
13417 install_element(BGP_NODE, &neighbor_description_cmd);
13418 install_element(BGP_NODE, &no_neighbor_description_cmd);
13419 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13420
13421 /* "neighbor update-source" commands. "*/
13422 install_element(BGP_NODE, &neighbor_update_source_cmd);
13423 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13424
13425 /* "neighbor default-originate" commands. */
13426 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13427 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13428 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13429 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13430 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13431 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13432 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13433 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13434 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13435 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13436 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13437 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13438 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13439 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13440 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13441 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13442 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13443 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13444 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13445 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13446 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13447
13448 /* "neighbor port" commands. */
13449 install_element(BGP_NODE, &neighbor_port_cmd);
13450 install_element(BGP_NODE, &no_neighbor_port_cmd);
13451
13452 /* "neighbor weight" commands. */
13453 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13454 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13455
13456 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13457 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13458 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13459 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13460 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13461 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13462 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13463 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13464 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13465 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13466 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13467 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13468 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13469 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13470 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13471 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13472
13473 /* "neighbor override-capability" commands. */
13474 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13475 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13476
13477 /* "neighbor strict-capability-match" commands. */
13478 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13479 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13480
13481 /* "neighbor timers" commands. */
13482 install_element(BGP_NODE, &neighbor_timers_cmd);
13483 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13484
13485 /* "neighbor timers connect" commands. */
13486 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13487 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13488
13489 /* "neighbor advertisement-interval" commands. */
13490 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13491 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13492
13493 /* "neighbor interface" commands. */
13494 install_element(BGP_NODE, &neighbor_interface_cmd);
13495 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13496
13497 /* "neighbor distribute" commands. */
13498 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13499 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13500 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13501 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13502 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13503 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13504 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13505 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13506 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13507 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13508 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13509 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13510 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13511 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13512 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13513 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13514 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13515 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13516
13517 /* "neighbor prefix-list" commands. */
13518 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13519 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13520 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13521 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13522 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13523 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13524 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13525 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13526 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13527 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13528 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13529 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13530 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13531 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13532 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13533 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13534 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13535 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13536 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13537 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13538 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13539 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13540
13541 /* "neighbor filter-list" commands. */
13542 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13543 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13544 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13545 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13546 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13547 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13548 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13549 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13550 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13551 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13552 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13553 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13554 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13555 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13556 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13557 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13558 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13559 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13560 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13561 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13562 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13563 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13564
13565 /* "neighbor route-map" commands. */
13566 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13567 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13568 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13569 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13570 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13571 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13572 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13573 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13574 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13575 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13576 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13577 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13578 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13579 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13580 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13581 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13582 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13583 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13584 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13585 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13586 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13587 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13588 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13589 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13590
13591 /* "neighbor unsuppress-map" commands. */
13592 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13593 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13594 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13595 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13596 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13597 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13598 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13599 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13600 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13601 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13602 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13603 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13604 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13605 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13606 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13607 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13608 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13609 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13610
13611 /* "neighbor maximum-prefix" commands. */
13612 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13613 install_element(BGP_NODE,
13614 &neighbor_maximum_prefix_threshold_hidden_cmd);
13615 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13616 install_element(BGP_NODE,
13617 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13618 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13619 install_element(BGP_NODE,
13620 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13621 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13622 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13623 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13624 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13625 install_element(BGP_IPV4_NODE,
13626 &neighbor_maximum_prefix_threshold_warning_cmd);
13627 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13628 install_element(BGP_IPV4_NODE,
13629 &neighbor_maximum_prefix_threshold_restart_cmd);
13630 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13631 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13632 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13633 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13634 install_element(BGP_IPV4M_NODE,
13635 &neighbor_maximum_prefix_threshold_warning_cmd);
13636 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13637 install_element(BGP_IPV4M_NODE,
13638 &neighbor_maximum_prefix_threshold_restart_cmd);
13639 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13640 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13641 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13642 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13643 install_element(BGP_IPV4L_NODE,
13644 &neighbor_maximum_prefix_threshold_warning_cmd);
13645 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13646 install_element(BGP_IPV4L_NODE,
13647 &neighbor_maximum_prefix_threshold_restart_cmd);
13648 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13649 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13650 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13651 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13652 install_element(BGP_IPV6_NODE,
13653 &neighbor_maximum_prefix_threshold_warning_cmd);
13654 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13655 install_element(BGP_IPV6_NODE,
13656 &neighbor_maximum_prefix_threshold_restart_cmd);
13657 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13658 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13659 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13660 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13661 install_element(BGP_IPV6M_NODE,
13662 &neighbor_maximum_prefix_threshold_warning_cmd);
13663 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13664 install_element(BGP_IPV6M_NODE,
13665 &neighbor_maximum_prefix_threshold_restart_cmd);
13666 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13667 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13668 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13669 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13670 install_element(BGP_IPV6L_NODE,
13671 &neighbor_maximum_prefix_threshold_warning_cmd);
13672 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13673 install_element(BGP_IPV6L_NODE,
13674 &neighbor_maximum_prefix_threshold_restart_cmd);
13675 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13676 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13677 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13678 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13679 install_element(BGP_VPNV4_NODE,
13680 &neighbor_maximum_prefix_threshold_warning_cmd);
13681 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13682 install_element(BGP_VPNV4_NODE,
13683 &neighbor_maximum_prefix_threshold_restart_cmd);
13684 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13685 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13686 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13687 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13688 install_element(BGP_VPNV6_NODE,
13689 &neighbor_maximum_prefix_threshold_warning_cmd);
13690 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13691 install_element(BGP_VPNV6_NODE,
13692 &neighbor_maximum_prefix_threshold_restart_cmd);
13693 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13694
13695 /* "neighbor allowas-in" */
13696 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13697 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13698 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13699 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13700 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13701 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13702 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13703 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13704 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13705 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13706 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13707 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13708 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13709 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13710 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13711 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13712 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13713 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13714 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13715 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13716
13717 /* address-family commands. */
13718 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13719 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13720 #ifdef KEEP_OLD_VPN_COMMANDS
13721 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13722 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13723 #endif /* KEEP_OLD_VPN_COMMANDS */
13724
13725 install_element(BGP_NODE, &address_family_evpn_cmd);
13726
13727 /* "exit-address-family" command. */
13728 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13729 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13730 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13731 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13732 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13733 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13734 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13735 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13736 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13737 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13738 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13739
13740 /* "clear ip bgp commands" */
13741 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13742
13743 /* clear ip bgp prefix */
13744 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13745 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13746 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13747
13748 /* "show [ip] bgp summary" commands. */
13749 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13750 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13751 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13752 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13753 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13754 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13755 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13756
13757 /* "show [ip] bgp neighbors" commands. */
13758 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13759
13760 /* "show [ip] bgp peer-group" commands. */
13761 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13762
13763 /* "show [ip] bgp paths" commands. */
13764 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13765
13766 /* "show [ip] bgp community" commands. */
13767 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13768
13769 /* "show ip bgp large-community" commands. */
13770 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13771 /* "show [ip] bgp attribute-info" commands. */
13772 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13773 /* "show [ip] bgp route-leak" command */
13774 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13775
13776 /* "redistribute" commands. */
13777 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13778 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13779 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13780 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13781 install_element(BGP_NODE,
13782 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13783 install_element(BGP_NODE,
13784 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13785 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13786 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13787 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13788 install_element(BGP_NODE,
13789 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13790 install_element(BGP_NODE,
13791 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13792 install_element(BGP_NODE,
13793 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13794 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13795 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13796 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13797 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13798 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13799 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13800 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13801 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13802 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13803 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13804 install_element(BGP_IPV4_NODE,
13805 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13806 install_element(BGP_IPV4_NODE,
13807 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13808 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13809 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13810 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13811 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13812 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13813 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13814
13815 /* import|export vpn [route-map WORD] */
13816 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13817 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13818
13819 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13820 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13821
13822 /* ttl_security commands */
13823 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13824 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13825
13826 /* "show [ip] bgp memory" commands. */
13827 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13828
13829 /* "show bgp martian next-hop" */
13830 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13831
13832 /* "show [ip] bgp views" commands. */
13833 install_element(VIEW_NODE, &show_bgp_views_cmd);
13834
13835 /* "show [ip] bgp vrfs" commands. */
13836 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13837
13838 /* Community-list. */
13839 community_list_vty();
13840
13841 /* vpn-policy commands */
13842 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13843 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13844 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13845 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13846 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13847 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13848 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13849 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13850 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13851 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13852 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13853 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13854
13855 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13856 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13857
13858 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13859 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13860 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13861 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13862 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13863 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13864 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13865 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13866 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13867 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13868 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13869 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13870 }
13871
13872 #include "memory.h"
13873 #include "bgp_regex.h"
13874 #include "bgp_clist.h"
13875 #include "bgp_ecommunity.h"
13876
13877 /* VTY functions. */
13878
13879 /* Direction value to string conversion. */
13880 static const char *community_direct_str(int direct)
13881 {
13882 switch (direct) {
13883 case COMMUNITY_DENY:
13884 return "deny";
13885 case COMMUNITY_PERMIT:
13886 return "permit";
13887 default:
13888 return "unknown";
13889 }
13890 }
13891
13892 /* Display error string. */
13893 static void community_list_perror(struct vty *vty, int ret)
13894 {
13895 switch (ret) {
13896 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13897 vty_out(vty, "%% Can't find community-list\n");
13898 break;
13899 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13900 vty_out(vty, "%% Malformed community-list value\n");
13901 break;
13902 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13903 vty_out(vty,
13904 "%% Community name conflict, previously defined as standard community\n");
13905 break;
13906 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13907 vty_out(vty,
13908 "%% Community name conflict, previously defined as expanded community\n");
13909 break;
13910 }
13911 }
13912
13913 /* "community-list" keyword help string. */
13914 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13915
13916 /*community-list standard */
13917 DEFUN (community_list_standard,
13918 bgp_community_list_standard_cmd,
13919 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13920 BGP_STR
13921 COMMUNITY_LIST_STR
13922 "Community list number (standard)\n"
13923 "Add an standard community-list entry\n"
13924 "Community list name\n"
13925 "Specify community to reject\n"
13926 "Specify community to accept\n"
13927 COMMUNITY_VAL_STR)
13928 {
13929 char *cl_name_or_number = NULL;
13930 int direct = 0;
13931 int style = COMMUNITY_LIST_STANDARD;
13932
13933 int idx = 0;
13934
13935 if (argv_find(argv, argc, "ip", &idx)) {
13936 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13937 vty_out(vty, "if you are using this please migrate to the below command.\n");
13938 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13939 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13940 }
13941
13942 argv_find(argv, argc, "(1-99)", &idx);
13943 argv_find(argv, argc, "WORD", &idx);
13944 cl_name_or_number = argv[idx]->arg;
13945 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13946 : COMMUNITY_DENY;
13947 argv_find(argv, argc, "AA:NN", &idx);
13948 char *str = argv_concat(argv, argc, idx);
13949
13950 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13951 style);
13952
13953 XFREE(MTYPE_TMP, str);
13954
13955 if (ret < 0) {
13956 /* Display error string. */
13957 community_list_perror(vty, ret);
13958 return CMD_WARNING_CONFIG_FAILED;
13959 }
13960
13961 return CMD_SUCCESS;
13962 }
13963
13964 #if CONFDATE > 20191005
13965 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
13966 #endif
13967 ALIAS (community_list_standard,
13968 ip_community_list_standard_cmd,
13969 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13970 IP_STR
13971 COMMUNITY_LIST_STR
13972 "Community list number (standard)\n"
13973 "Add an standard community-list entry\n"
13974 "Community list name\n"
13975 "Specify community to reject\n"
13976 "Specify community to accept\n"
13977 COMMUNITY_VAL_STR)
13978
13979 DEFUN (no_community_list_standard_all,
13980 no_bgp_community_list_standard_all_cmd,
13981 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13982 NO_STR
13983 BGP_STR
13984 COMMUNITY_LIST_STR
13985 "Community list number (standard)\n"
13986 "Add an standard community-list entry\n"
13987 "Community list name\n"
13988 "Specify community to reject\n"
13989 "Specify community to accept\n"
13990 COMMUNITY_VAL_STR)
13991 {
13992 char *cl_name_or_number = NULL;
13993 char *str = NULL;
13994 int direct = 0;
13995 int style = COMMUNITY_LIST_STANDARD;
13996
13997 int idx = 0;
13998
13999 if (argv_find(argv, argc, "ip", &idx)) {
14000 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14001 vty_out(vty, "if you are using this please migrate to the below command.\n");
14002 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14003 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
14004 }
14005
14006 argv_find(argv, argc, "permit", &idx);
14007 argv_find(argv, argc, "deny", &idx);
14008
14009 if (idx) {
14010 direct = argv_find(argv, argc, "permit", &idx)
14011 ? COMMUNITY_PERMIT
14012 : COMMUNITY_DENY;
14013
14014 idx = 0;
14015 argv_find(argv, argc, "AA:NN", &idx);
14016 str = argv_concat(argv, argc, idx);
14017 }
14018
14019 idx = 0;
14020 argv_find(argv, argc, "(1-99)", &idx);
14021 argv_find(argv, argc, "WORD", &idx);
14022 cl_name_or_number = argv[idx]->arg;
14023
14024 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14025 direct, style);
14026
14027 XFREE(MTYPE_TMP, str);
14028
14029 if (ret < 0) {
14030 community_list_perror(vty, ret);
14031 return CMD_WARNING_CONFIG_FAILED;
14032 }
14033
14034 return CMD_SUCCESS;
14035 }
14036 ALIAS (no_community_list_standard_all,
14037 no_ip_community_list_standard_all_cmd,
14038 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14039 NO_STR
14040 IP_STR
14041 COMMUNITY_LIST_STR
14042 "Community list number (standard)\n"
14043 "Add an standard community-list entry\n"
14044 "Community list name\n"
14045 "Specify community to reject\n"
14046 "Specify community to accept\n"
14047 COMMUNITY_VAL_STR)
14048
14049 ALIAS(no_community_list_standard_all, no_bgp_community_list_standard_all_list_cmd,
14050 "no bgp community-list <(1-99)|standard WORD>",
14051 NO_STR BGP_STR COMMUNITY_LIST_STR
14052 "Community list number (standard)\n"
14053 "Add an standard community-list entry\n"
14054 "Community list name\n")
14055
14056 ALIAS(no_community_list_standard_all, no_ip_community_list_standard_all_list_cmd,
14057 "no ip community-list <(1-99)|standard WORD>",
14058 NO_STR BGP_STR COMMUNITY_LIST_STR
14059 "Community list number (standard)\n"
14060 "Add an standard community-list entry\n"
14061 "Community list name\n")
14062
14063 /*community-list expanded */
14064 DEFUN (community_list_expanded_all,
14065 bgp_community_list_expanded_all_cmd,
14066 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14067 BGP_STR
14068 COMMUNITY_LIST_STR
14069 "Community list number (expanded)\n"
14070 "Add an expanded community-list entry\n"
14071 "Community list name\n"
14072 "Specify community to reject\n"
14073 "Specify community to accept\n"
14074 COMMUNITY_VAL_STR)
14075 {
14076 char *cl_name_or_number = NULL;
14077 int direct = 0;
14078 int style = COMMUNITY_LIST_EXPANDED;
14079
14080 int idx = 0;
14081 if (argv_find(argv, argc, "ip", &idx)) {
14082 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14083 vty_out(vty, "if you are using this please migrate to the below command.\n");
14084 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14085 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14086 }
14087 argv_find(argv, argc, "(100-500)", &idx);
14088 argv_find(argv, argc, "WORD", &idx);
14089 cl_name_or_number = argv[idx]->arg;
14090 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14091 : COMMUNITY_DENY;
14092 argv_find(argv, argc, "AA:NN", &idx);
14093 char *str = argv_concat(argv, argc, idx);
14094
14095 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
14096 style);
14097
14098 XFREE(MTYPE_TMP, str);
14099
14100 if (ret < 0) {
14101 /* Display error string. */
14102 community_list_perror(vty, ret);
14103 return CMD_WARNING_CONFIG_FAILED;
14104 }
14105
14106 return CMD_SUCCESS;
14107 }
14108
14109 ALIAS (community_list_expanded_all,
14110 ip_community_list_expanded_all_cmd,
14111 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14112 IP_STR
14113 COMMUNITY_LIST_STR
14114 "Community list number (expanded)\n"
14115 "Add an expanded community-list entry\n"
14116 "Community list name\n"
14117 "Specify community to reject\n"
14118 "Specify community to accept\n"
14119 COMMUNITY_VAL_STR)
14120
14121 DEFUN (no_community_list_expanded_all,
14122 no_bgp_community_list_expanded_all_cmd,
14123 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14124 NO_STR
14125 BGP_STR
14126 COMMUNITY_LIST_STR
14127 "Community list number (expanded)\n"
14128 "Add an expanded community-list entry\n"
14129 "Community list name\n"
14130 "Specify community to reject\n"
14131 "Specify community to accept\n"
14132 COMMUNITY_VAL_STR)
14133 {
14134 char *cl_name_or_number = NULL;
14135 char *str = NULL;
14136 int direct = 0;
14137 int style = COMMUNITY_LIST_EXPANDED;
14138
14139 int idx = 0;
14140 if (argv_find(argv, argc, "ip", &idx)) {
14141 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14142 vty_out(vty, "if you are using this please migrate to the below command.\n");
14143 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14144 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14145 }
14146
14147 idx = 0;
14148 argv_find(argv, argc, "permit", &idx);
14149 argv_find(argv, argc, "deny", &idx);
14150
14151 if (idx) {
14152 direct = argv_find(argv, argc, "permit", &idx)
14153 ? COMMUNITY_PERMIT
14154 : COMMUNITY_DENY;
14155
14156 idx = 0;
14157 argv_find(argv, argc, "AA:NN", &idx);
14158 str = argv_concat(argv, argc, idx);
14159 }
14160
14161 idx = 0;
14162 argv_find(argv, argc, "(100-500)", &idx);
14163 argv_find(argv, argc, "WORD", &idx);
14164 cl_name_or_number = argv[idx]->arg;
14165
14166 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14167 direct, style);
14168
14169 XFREE(MTYPE_TMP, str);
14170
14171 if (ret < 0) {
14172 community_list_perror(vty, ret);
14173 return CMD_WARNING_CONFIG_FAILED;
14174 }
14175
14176 return CMD_SUCCESS;
14177 }
14178
14179 ALIAS (no_community_list_expanded_all,
14180 no_ip_community_list_expanded_all_cmd,
14181 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14182 NO_STR
14183 IP_STR
14184 COMMUNITY_LIST_STR
14185 "Community list number (expanded)\n"
14186 "Add an expanded community-list entry\n"
14187 "Community list name\n"
14188 "Specify community to reject\n"
14189 "Specify community to accept\n"
14190 COMMUNITY_VAL_STR)
14191
14192 ALIAS(no_community_list_expanded_all, no_bgp_community_list_expanded_all_list_cmd,
14193 "no bgp community-list <(100-500)|expanded WORD>",
14194 NO_STR IP_STR COMMUNITY_LIST_STR
14195 "Community list number (expanded)\n"
14196 "Add an expanded community-list entry\n"
14197 "Community list name\n")
14198
14199 ALIAS(no_community_list_expanded_all, no_ip_community_list_expanded_all_list_cmd,
14200 "no ip community-list <(100-500)|expanded WORD>",
14201 NO_STR IP_STR COMMUNITY_LIST_STR
14202 "Community list number (expanded)\n"
14203 "Add an expanded community-list entry\n"
14204 "Community list name\n")
14205
14206 /* Return configuration string of community-list entry. */
14207 static const char *community_list_config_str(struct community_entry *entry)
14208 {
14209 const char *str;
14210
14211 if (entry->any)
14212 str = "";
14213 else {
14214 if (entry->style == COMMUNITY_LIST_STANDARD)
14215 str = community_str(entry->u.com, false);
14216 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14217 str = lcommunity_str(entry->u.lcom, false);
14218 else
14219 str = entry->config;
14220 }
14221 return str;
14222 }
14223
14224 static void community_list_show(struct vty *vty, struct community_list *list)
14225 {
14226 struct community_entry *entry;
14227
14228 for (entry = list->head; entry; entry = entry->next) {
14229 if (entry == list->head) {
14230 if (all_digit(list->name))
14231 vty_out(vty, "Community %s list %s\n",
14232 entry->style == COMMUNITY_LIST_STANDARD
14233 ? "standard"
14234 : "(expanded) access",
14235 list->name);
14236 else
14237 vty_out(vty, "Named Community %s list %s\n",
14238 entry->style == COMMUNITY_LIST_STANDARD
14239 ? "standard"
14240 : "expanded",
14241 list->name);
14242 }
14243 if (entry->any)
14244 vty_out(vty, " %s\n",
14245 community_direct_str(entry->direct));
14246 else
14247 vty_out(vty, " %s %s\n",
14248 community_direct_str(entry->direct),
14249 community_list_config_str(entry));
14250 }
14251 }
14252
14253 DEFUN (show_community_list,
14254 show_bgp_community_list_cmd,
14255 "show bgp community-list",
14256 SHOW_STR
14257 BGP_STR
14258 "List community-list\n")
14259 {
14260 struct community_list *list;
14261 struct community_list_master *cm;
14262
14263 int idx = 0;
14264 if (argv_find(argv, argc, "ip", &idx)) {
14265 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14266 vty_out(vty, "if you are using this please migrate to the below command.\n");
14267 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14268 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14269 }
14270 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14271 if (!cm)
14272 return CMD_SUCCESS;
14273
14274 for (list = cm->num.head; list; list = list->next)
14275 community_list_show(vty, list);
14276
14277 for (list = cm->str.head; list; list = list->next)
14278 community_list_show(vty, list);
14279
14280 return CMD_SUCCESS;
14281 }
14282
14283 ALIAS (show_community_list,
14284 show_ip_community_list_cmd,
14285 "show ip community-list",
14286 SHOW_STR
14287 IP_STR
14288 "List community-list\n")
14289
14290 DEFUN (show_community_list_arg,
14291 show_bgp_community_list_arg_cmd,
14292 "show bgp community-list <(1-500)|WORD>",
14293 SHOW_STR
14294 BGP_STR
14295 "List community-list\n"
14296 "Community-list number\n"
14297 "Community-list name\n")
14298 {
14299 int idx_comm_list = 3;
14300 struct community_list *list;
14301
14302 int idx = 0;
14303 if (argv_find(argv, argc, "ip", &idx)) {
14304 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14305 vty_out(vty, "if you are using this please migrate to the below command.\n");
14306 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14307 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14308 }
14309 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14310 COMMUNITY_LIST_MASTER);
14311 if (!list) {
14312 vty_out(vty, "%% Can't find community-list\n");
14313 return CMD_WARNING;
14314 }
14315
14316 community_list_show(vty, list);
14317
14318 return CMD_SUCCESS;
14319 }
14320
14321 ALIAS (show_community_list_arg,
14322 show_ip_community_list_arg_cmd,
14323 "show ip community-list <(1-500)|WORD>",
14324 SHOW_STR
14325 IP_STR
14326 "List community-list\n"
14327 "Community-list number\n"
14328 "Community-list name\n")
14329
14330 /*
14331 * Large Community code.
14332 */
14333 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14334 struct cmd_token **argv, int style,
14335 int reject_all_digit_name)
14336 {
14337 int ret;
14338 int direct;
14339 char *str;
14340 int idx = 0;
14341 char *cl_name;
14342
14343 if (argv_find(argv, argc, "ip", &idx)) {
14344 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14345 vty_out(vty, "if you are using this please migrate to the below command.\n");
14346 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14347 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14348 }
14349 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14350 : COMMUNITY_DENY;
14351
14352 /* All digit name check. */
14353 idx = 0;
14354 argv_find(argv, argc, "WORD", &idx);
14355 argv_find(argv, argc, "(1-99)", &idx);
14356 argv_find(argv, argc, "(100-500)", &idx);
14357 cl_name = argv[idx]->arg;
14358 if (reject_all_digit_name && all_digit(cl_name)) {
14359 vty_out(vty, "%% Community name cannot have all digits\n");
14360 return CMD_WARNING_CONFIG_FAILED;
14361 }
14362
14363 idx = 0;
14364 argv_find(argv, argc, "AA:BB:CC", &idx);
14365 argv_find(argv, argc, "LINE", &idx);
14366 /* Concat community string argument. */
14367 if (idx)
14368 str = argv_concat(argv, argc, idx);
14369 else
14370 str = NULL;
14371
14372 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14373
14374 /* Free temporary community list string allocated by
14375 argv_concat(). */
14376 if (str)
14377 XFREE(MTYPE_TMP, str);
14378
14379 if (ret < 0) {
14380 community_list_perror(vty, ret);
14381 return CMD_WARNING_CONFIG_FAILED;
14382 }
14383 return CMD_SUCCESS;
14384 }
14385
14386 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14387 struct cmd_token **argv, int style)
14388 {
14389 int ret;
14390 int direct = 0;
14391 char *str = NULL;
14392 int idx = 0;
14393
14394 if (argv_find(argv, argc, "ip", &idx)) {
14395 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14396 vty_out(vty, "if you are using this please migrate to the below command.\n");
14397 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14398 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14399 }
14400 argv_find(argv, argc, "permit", &idx);
14401 argv_find(argv, argc, "deny", &idx);
14402
14403 if (idx) {
14404 /* Check the list direct. */
14405 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14406 direct = COMMUNITY_PERMIT;
14407 else
14408 direct = COMMUNITY_DENY;
14409
14410 idx = 0;
14411 argv_find(argv, argc, "LINE", &idx);
14412 argv_find(argv, argc, "AA:AA:NN", &idx);
14413 /* Concat community string argument. */
14414 str = argv_concat(argv, argc, idx);
14415 }
14416
14417 idx = 0;
14418 argv_find(argv, argc, "(1-99)", &idx);
14419 argv_find(argv, argc, "(100-500)", &idx);
14420 argv_find(argv, argc, "WORD", &idx);
14421
14422 /* Unset community list. */
14423 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14424 style);
14425
14426 /* Free temporary community list string allocated by
14427 argv_concat(). */
14428 if (str)
14429 XFREE(MTYPE_TMP, str);
14430
14431 if (ret < 0) {
14432 community_list_perror(vty, ret);
14433 return CMD_WARNING_CONFIG_FAILED;
14434 }
14435
14436 return CMD_SUCCESS;
14437 }
14438
14439 /* "large-community-list" keyword help string. */
14440 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14441 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14442
14443 #if CONFDATE > 20191005
14444 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14445 #endif
14446 DEFUN (lcommunity_list_standard,
14447 bgp_lcommunity_list_standard_cmd,
14448 "bgp large-community-list (1-99) <deny|permit>",
14449 BGP_STR
14450 LCOMMUNITY_LIST_STR
14451 "Large Community list number (standard)\n"
14452 "Specify large community to reject\n"
14453 "Specify large community to accept\n")
14454 {
14455 return lcommunity_list_set_vty(vty, argc, argv,
14456 LARGE_COMMUNITY_LIST_STANDARD, 0);
14457 }
14458
14459 ALIAS (lcommunity_list_standard,
14460 ip_lcommunity_list_standard_cmd,
14461 "ip large-community-list (1-99) <deny|permit>",
14462 IP_STR
14463 LCOMMUNITY_LIST_STR
14464 "Large Community list number (standard)\n"
14465 "Specify large community to reject\n"
14466 "Specify large community to accept\n")
14467
14468 DEFUN (lcommunity_list_standard1,
14469 bgp_lcommunity_list_standard1_cmd,
14470 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14471 BGP_STR
14472 LCOMMUNITY_LIST_STR
14473 "Large Community list number (standard)\n"
14474 "Specify large community to reject\n"
14475 "Specify large community to accept\n"
14476 LCOMMUNITY_VAL_STR)
14477 {
14478 return lcommunity_list_set_vty(vty, argc, argv,
14479 LARGE_COMMUNITY_LIST_STANDARD, 0);
14480 }
14481
14482 ALIAS (lcommunity_list_standard1,
14483 ip_lcommunity_list_standard1_cmd,
14484 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14485 IP_STR
14486 LCOMMUNITY_LIST_STR
14487 "Large Community list number (standard)\n"
14488 "Specify large community to reject\n"
14489 "Specify large community to accept\n"
14490 LCOMMUNITY_VAL_STR)
14491
14492 DEFUN (lcommunity_list_expanded,
14493 bgp_lcommunity_list_expanded_cmd,
14494 "bgp large-community-list (100-500) <deny|permit> LINE...",
14495 BGP_STR
14496 LCOMMUNITY_LIST_STR
14497 "Large Community list number (expanded)\n"
14498 "Specify large community to reject\n"
14499 "Specify large community to accept\n"
14500 "An ordered list as a regular-expression\n")
14501 {
14502 return lcommunity_list_set_vty(vty, argc, argv,
14503 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14504 }
14505
14506 ALIAS (lcommunity_list_expanded,
14507 ip_lcommunity_list_expanded_cmd,
14508 "ip large-community-list (100-500) <deny|permit> LINE...",
14509 IP_STR
14510 LCOMMUNITY_LIST_STR
14511 "Large Community list number (expanded)\n"
14512 "Specify large community to reject\n"
14513 "Specify large community to accept\n"
14514 "An ordered list as a regular-expression\n")
14515
14516 DEFUN (lcommunity_list_name_standard,
14517 bgp_lcommunity_list_name_standard_cmd,
14518 "bgp large-community-list standard WORD <deny|permit>",
14519 BGP_STR
14520 LCOMMUNITY_LIST_STR
14521 "Specify standard large-community-list\n"
14522 "Large Community list name\n"
14523 "Specify large community to reject\n"
14524 "Specify large community to accept\n")
14525 {
14526 return lcommunity_list_set_vty(vty, argc, argv,
14527 LARGE_COMMUNITY_LIST_STANDARD, 1);
14528 }
14529
14530 ALIAS (lcommunity_list_name_standard,
14531 ip_lcommunity_list_name_standard_cmd,
14532 "ip large-community-list standard WORD <deny|permit>",
14533 IP_STR
14534 LCOMMUNITY_LIST_STR
14535 "Specify standard large-community-list\n"
14536 "Large Community list name\n"
14537 "Specify large community to reject\n"
14538 "Specify large community to accept\n")
14539
14540 DEFUN (lcommunity_list_name_standard1,
14541 bgp_lcommunity_list_name_standard1_cmd,
14542 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14543 BGP_STR
14544 LCOMMUNITY_LIST_STR
14545 "Specify standard large-community-list\n"
14546 "Large Community list name\n"
14547 "Specify large community to reject\n"
14548 "Specify large community to accept\n"
14549 LCOMMUNITY_VAL_STR)
14550 {
14551 return lcommunity_list_set_vty(vty, argc, argv,
14552 LARGE_COMMUNITY_LIST_STANDARD, 1);
14553 }
14554
14555 ALIAS (lcommunity_list_name_standard1,
14556 ip_lcommunity_list_name_standard1_cmd,
14557 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14558 IP_STR
14559 LCOMMUNITY_LIST_STR
14560 "Specify standard large-community-list\n"
14561 "Large Community list name\n"
14562 "Specify large community to reject\n"
14563 "Specify large community to accept\n"
14564 LCOMMUNITY_VAL_STR)
14565
14566 DEFUN (lcommunity_list_name_expanded,
14567 bgp_lcommunity_list_name_expanded_cmd,
14568 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14569 BGP_STR
14570 LCOMMUNITY_LIST_STR
14571 "Specify expanded large-community-list\n"
14572 "Large Community list name\n"
14573 "Specify large community to reject\n"
14574 "Specify large community to accept\n"
14575 "An ordered list as a regular-expression\n")
14576 {
14577 return lcommunity_list_set_vty(vty, argc, argv,
14578 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14579 }
14580
14581 ALIAS (lcommunity_list_name_expanded,
14582 ip_lcommunity_list_name_expanded_cmd,
14583 "ip large-community-list expanded WORD <deny|permit> LINE...",
14584 IP_STR
14585 LCOMMUNITY_LIST_STR
14586 "Specify expanded large-community-list\n"
14587 "Large Community list name\n"
14588 "Specify large community to reject\n"
14589 "Specify large community to accept\n"
14590 "An ordered list as a regular-expression\n")
14591
14592 DEFUN (no_lcommunity_list_standard_all,
14593 no_bgp_lcommunity_list_standard_all_cmd,
14594 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14595 NO_STR
14596 BGP_STR
14597 LCOMMUNITY_LIST_STR
14598 "Large Community list number (standard)\n"
14599 "Large Community list number (expanded)\n"
14600 "Large Community list name\n")
14601 {
14602 return lcommunity_list_unset_vty(vty, argc, argv,
14603 LARGE_COMMUNITY_LIST_STANDARD);
14604 }
14605
14606 ALIAS (no_lcommunity_list_standard_all,
14607 no_ip_lcommunity_list_standard_all_cmd,
14608 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14609 NO_STR
14610 IP_STR
14611 LCOMMUNITY_LIST_STR
14612 "Large Community list number (standard)\n"
14613 "Large Community list number (expanded)\n"
14614 "Large Community list name\n")
14615
14616 DEFUN (no_lcommunity_list_name_expanded_all,
14617 no_bgp_lcommunity_list_name_expanded_all_cmd,
14618 "no bgp large-community-list expanded WORD",
14619 NO_STR
14620 BGP_STR
14621 LCOMMUNITY_LIST_STR
14622 "Specify expanded large-community-list\n"
14623 "Large Community list name\n")
14624 {
14625 return lcommunity_list_unset_vty(vty, argc, argv,
14626 LARGE_COMMUNITY_LIST_EXPANDED);
14627 }
14628
14629 ALIAS (no_lcommunity_list_name_expanded_all,
14630 no_ip_lcommunity_list_name_expanded_all_cmd,
14631 "no ip large-community-list expanded WORD",
14632 NO_STR
14633 IP_STR
14634 LCOMMUNITY_LIST_STR
14635 "Specify expanded large-community-list\n"
14636 "Large Community list name\n")
14637
14638 DEFUN (no_lcommunity_list_standard,
14639 no_bgp_lcommunity_list_standard_cmd,
14640 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14641 NO_STR
14642 BGP_STR
14643 LCOMMUNITY_LIST_STR
14644 "Large Community list number (standard)\n"
14645 "Specify large community to reject\n"
14646 "Specify large community to accept\n"
14647 LCOMMUNITY_VAL_STR)
14648 {
14649 return lcommunity_list_unset_vty(vty, argc, argv,
14650 LARGE_COMMUNITY_LIST_STANDARD);
14651 }
14652
14653 ALIAS (no_lcommunity_list_standard,
14654 no_ip_lcommunity_list_standard_cmd,
14655 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14656 NO_STR
14657 IP_STR
14658 LCOMMUNITY_LIST_STR
14659 "Large Community list number (standard)\n"
14660 "Specify large community to reject\n"
14661 "Specify large community to accept\n"
14662 LCOMMUNITY_VAL_STR)
14663
14664 DEFUN (no_lcommunity_list_expanded,
14665 no_bgp_lcommunity_list_expanded_cmd,
14666 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14667 NO_STR
14668 BGP_STR
14669 LCOMMUNITY_LIST_STR
14670 "Large Community list number (expanded)\n"
14671 "Specify large community to reject\n"
14672 "Specify large community to accept\n"
14673 "An ordered list as a regular-expression\n")
14674 {
14675 return lcommunity_list_unset_vty(vty, argc, argv,
14676 LARGE_COMMUNITY_LIST_EXPANDED);
14677 }
14678
14679 ALIAS (no_lcommunity_list_expanded,
14680 no_ip_lcommunity_list_expanded_cmd,
14681 "no ip large-community-list (100-500) <deny|permit> LINE...",
14682 NO_STR
14683 IP_STR
14684 LCOMMUNITY_LIST_STR
14685 "Large Community list number (expanded)\n"
14686 "Specify large community to reject\n"
14687 "Specify large community to accept\n"
14688 "An ordered list as a regular-expression\n")
14689
14690 DEFUN (no_lcommunity_list_name_standard,
14691 no_bgp_lcommunity_list_name_standard_cmd,
14692 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14693 NO_STR
14694 BGP_STR
14695 LCOMMUNITY_LIST_STR
14696 "Specify standard large-community-list\n"
14697 "Large Community list name\n"
14698 "Specify large community to reject\n"
14699 "Specify large community to accept\n"
14700 LCOMMUNITY_VAL_STR)
14701 {
14702 return lcommunity_list_unset_vty(vty, argc, argv,
14703 LARGE_COMMUNITY_LIST_STANDARD);
14704 }
14705
14706 ALIAS (no_lcommunity_list_name_standard,
14707 no_ip_lcommunity_list_name_standard_cmd,
14708 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14709 NO_STR
14710 IP_STR
14711 LCOMMUNITY_LIST_STR
14712 "Specify standard large-community-list\n"
14713 "Large Community list name\n"
14714 "Specify large community to reject\n"
14715 "Specify large community to accept\n"
14716 LCOMMUNITY_VAL_STR)
14717
14718 DEFUN (no_lcommunity_list_name_expanded,
14719 no_bgp_lcommunity_list_name_expanded_cmd,
14720 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14721 NO_STR
14722 BGP_STR
14723 LCOMMUNITY_LIST_STR
14724 "Specify expanded large-community-list\n"
14725 "Large community list name\n"
14726 "Specify large community to reject\n"
14727 "Specify large community to accept\n"
14728 "An ordered list as a regular-expression\n")
14729 {
14730 return lcommunity_list_unset_vty(vty, argc, argv,
14731 LARGE_COMMUNITY_LIST_EXPANDED);
14732 }
14733
14734 ALIAS (no_lcommunity_list_name_expanded,
14735 no_ip_lcommunity_list_name_expanded_cmd,
14736 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14737 NO_STR
14738 IP_STR
14739 LCOMMUNITY_LIST_STR
14740 "Specify expanded large-community-list\n"
14741 "Large community list name\n"
14742 "Specify large community to reject\n"
14743 "Specify large community to accept\n"
14744 "An ordered list as a regular-expression\n")
14745
14746 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14747 {
14748 struct community_entry *entry;
14749
14750 for (entry = list->head; entry; entry = entry->next) {
14751 if (entry == list->head) {
14752 if (all_digit(list->name))
14753 vty_out(vty, "Large community %s list %s\n",
14754 entry->style == EXTCOMMUNITY_LIST_STANDARD
14755 ? "standard"
14756 : "(expanded) access",
14757 list->name);
14758 else
14759 vty_out(vty,
14760 "Named large community %s list %s\n",
14761 entry->style == EXTCOMMUNITY_LIST_STANDARD
14762 ? "standard"
14763 : "expanded",
14764 list->name);
14765 }
14766 if (entry->any)
14767 vty_out(vty, " %s\n",
14768 community_direct_str(entry->direct));
14769 else
14770 vty_out(vty, " %s %s\n",
14771 community_direct_str(entry->direct),
14772 community_list_config_str(entry));
14773 }
14774 }
14775
14776 DEFUN (show_lcommunity_list,
14777 show_bgp_lcommunity_list_cmd,
14778 "show bgp large-community-list",
14779 SHOW_STR
14780 BGP_STR
14781 "List large-community list\n")
14782 {
14783 struct community_list *list;
14784 struct community_list_master *cm;
14785 int idx = 0;
14786
14787 if (argv_find(argv, argc, "ip", &idx)) {
14788 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14789 vty_out(vty, "if you are using this please migrate to the below command.\n");
14790 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14791 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14792 }
14793
14794 cm = community_list_master_lookup(bgp_clist,
14795 LARGE_COMMUNITY_LIST_MASTER);
14796 if (!cm)
14797 return CMD_SUCCESS;
14798
14799 for (list = cm->num.head; list; list = list->next)
14800 lcommunity_list_show(vty, list);
14801
14802 for (list = cm->str.head; list; list = list->next)
14803 lcommunity_list_show(vty, list);
14804
14805 return CMD_SUCCESS;
14806 }
14807
14808 ALIAS (show_lcommunity_list,
14809 show_ip_lcommunity_list_cmd,
14810 "show ip large-community-list",
14811 SHOW_STR
14812 IP_STR
14813 "List large-community list\n")
14814
14815 DEFUN (show_lcommunity_list_arg,
14816 show_bgp_lcommunity_list_arg_cmd,
14817 "show bgp large-community-list <(1-500)|WORD>",
14818 SHOW_STR
14819 BGP_STR
14820 "List large-community list\n"
14821 "large-community-list number\n"
14822 "large-community-list name\n")
14823 {
14824 struct community_list *list;
14825 int idx = 0;
14826
14827 if (argv_find(argv, argc, "ip", &idx)) {
14828 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14829 vty_out(vty, "if you are using this please migrate to the below command.\n");
14830 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14831 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14832 }
14833
14834 list = community_list_lookup(bgp_clist, argv[3]->arg,
14835 LARGE_COMMUNITY_LIST_MASTER);
14836 if (!list) {
14837 vty_out(vty, "%% Can't find extcommunity-list\n");
14838 return CMD_WARNING;
14839 }
14840
14841 lcommunity_list_show(vty, list);
14842
14843 return CMD_SUCCESS;
14844 }
14845
14846 ALIAS (show_lcommunity_list_arg,
14847 show_ip_lcommunity_list_arg_cmd,
14848 "show ip large-community-list <(1-500)|WORD>",
14849 SHOW_STR
14850 IP_STR
14851 "List large-community list\n"
14852 "large-community-list number\n"
14853 "large-community-list name\n")
14854
14855 /* "extcommunity-list" keyword help string. */
14856 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14857 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14858
14859 DEFUN (extcommunity_list_standard,
14860 bgp_extcommunity_list_standard_cmd,
14861 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14862 BGP_STR
14863 EXTCOMMUNITY_LIST_STR
14864 "Extended Community list number (standard)\n"
14865 "Specify standard extcommunity-list\n"
14866 "Community list name\n"
14867 "Specify community to reject\n"
14868 "Specify community to accept\n"
14869 EXTCOMMUNITY_VAL_STR)
14870 {
14871 int style = EXTCOMMUNITY_LIST_STANDARD;
14872 int direct = 0;
14873 char *cl_number_or_name = NULL;
14874
14875 int idx = 0;
14876 if (argv_find(argv, argc, "ip", &idx)) {
14877 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14878 vty_out(vty, "if you are using this please migrate to the below command.\n");
14879 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14880 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14881 }
14882 argv_find(argv, argc, "(1-99)", &idx);
14883 argv_find(argv, argc, "WORD", &idx);
14884 cl_number_or_name = argv[idx]->arg;
14885 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14886 : COMMUNITY_DENY;
14887 argv_find(argv, argc, "AA:NN", &idx);
14888 char *str = argv_concat(argv, argc, idx);
14889
14890 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14891 direct, style);
14892
14893 XFREE(MTYPE_TMP, str);
14894
14895 if (ret < 0) {
14896 community_list_perror(vty, ret);
14897 return CMD_WARNING_CONFIG_FAILED;
14898 }
14899
14900 return CMD_SUCCESS;
14901 }
14902
14903 #if CONFDATE > 20191005
14904 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14905 #endif
14906 ALIAS (extcommunity_list_standard,
14907 ip_extcommunity_list_standard_cmd,
14908 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14909 IP_STR
14910 EXTCOMMUNITY_LIST_STR
14911 "Extended Community list number (standard)\n"
14912 "Specify standard extcommunity-list\n"
14913 "Community list name\n"
14914 "Specify community to reject\n"
14915 "Specify community to accept\n"
14916 EXTCOMMUNITY_VAL_STR)
14917
14918 DEFUN (extcommunity_list_name_expanded,
14919 bgp_extcommunity_list_name_expanded_cmd,
14920 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14921 BGP_STR
14922 EXTCOMMUNITY_LIST_STR
14923 "Extended Community list number (expanded)\n"
14924 "Specify expanded extcommunity-list\n"
14925 "Extended Community list name\n"
14926 "Specify community to reject\n"
14927 "Specify community to accept\n"
14928 "An ordered list as a regular-expression\n")
14929 {
14930 int style = EXTCOMMUNITY_LIST_EXPANDED;
14931 int direct = 0;
14932 char *cl_number_or_name = NULL;
14933
14934 int idx = 0;
14935 if (argv_find(argv, argc, "ip", &idx)) {
14936 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14937 vty_out(vty, "if you are using this please migrate to the below command.\n");
14938 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14939 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14940 }
14941
14942 argv_find(argv, argc, "(100-500)", &idx);
14943 argv_find(argv, argc, "WORD", &idx);
14944 cl_number_or_name = argv[idx]->arg;
14945 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14946 : COMMUNITY_DENY;
14947 argv_find(argv, argc, "LINE", &idx);
14948 char *str = argv_concat(argv, argc, idx);
14949
14950 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14951 direct, style);
14952
14953 XFREE(MTYPE_TMP, str);
14954
14955 if (ret < 0) {
14956 community_list_perror(vty, ret);
14957 return CMD_WARNING_CONFIG_FAILED;
14958 }
14959
14960 return CMD_SUCCESS;
14961 }
14962
14963 ALIAS (extcommunity_list_name_expanded,
14964 ip_extcommunity_list_name_expanded_cmd,
14965 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14966 IP_STR
14967 EXTCOMMUNITY_LIST_STR
14968 "Extended Community list number (expanded)\n"
14969 "Specify expanded extcommunity-list\n"
14970 "Extended Community list name\n"
14971 "Specify community to reject\n"
14972 "Specify community to accept\n"
14973 "An ordered list as a regular-expression\n")
14974
14975 DEFUN (no_extcommunity_list_standard_all,
14976 no_bgp_extcommunity_list_standard_all_cmd,
14977 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14978 NO_STR
14979 BGP_STR
14980 EXTCOMMUNITY_LIST_STR
14981 "Extended Community list number (standard)\n"
14982 "Specify standard extcommunity-list\n"
14983 "Community list name\n"
14984 "Specify community to reject\n"
14985 "Specify community to accept\n"
14986 EXTCOMMUNITY_VAL_STR)
14987 {
14988 int style = EXTCOMMUNITY_LIST_STANDARD;
14989 int direct = 0;
14990 char *cl_number_or_name = NULL;
14991
14992 int idx = 0;
14993 if (argv_find(argv, argc, "ip", &idx)) {
14994 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14995 vty_out(vty, "if you are using this please migrate to the below command.\n");
14996 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14997 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14998 }
14999 argv_find(argv, argc, "(1-99)", &idx);
15000 argv_find(argv, argc, "WORD", &idx);
15001 cl_number_or_name = argv[idx]->arg;
15002 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15003 : COMMUNITY_DENY;
15004 argv_find(argv, argc, "AA:NN", &idx);
15005 char *str = argv_concat(argv, argc, idx);
15006
15007 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15008 direct, style);
15009
15010 XFREE(MTYPE_TMP, str);
15011
15012 if (ret < 0) {
15013 community_list_perror(vty, ret);
15014 return CMD_WARNING_CONFIG_FAILED;
15015 }
15016
15017 return CMD_SUCCESS;
15018 }
15019
15020 ALIAS (no_extcommunity_list_standard_all,
15021 no_ip_extcommunity_list_standard_all_cmd,
15022 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
15023 NO_STR
15024 IP_STR
15025 EXTCOMMUNITY_LIST_STR
15026 "Extended Community list number (standard)\n"
15027 "Specify standard extcommunity-list\n"
15028 "Community list name\n"
15029 "Specify community to reject\n"
15030 "Specify community to accept\n"
15031 EXTCOMMUNITY_VAL_STR)
15032
15033 DEFUN (no_extcommunity_list_expanded_all,
15034 no_bgp_extcommunity_list_expanded_all_cmd,
15035 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15036 NO_STR
15037 BGP_STR
15038 EXTCOMMUNITY_LIST_STR
15039 "Extended Community list number (expanded)\n"
15040 "Specify expanded extcommunity-list\n"
15041 "Extended Community list name\n"
15042 "Specify community to reject\n"
15043 "Specify community to accept\n"
15044 "An ordered list as a regular-expression\n")
15045 {
15046 int style = EXTCOMMUNITY_LIST_EXPANDED;
15047 int direct = 0;
15048 char *cl_number_or_name = NULL;
15049
15050 int idx = 0;
15051 if (argv_find(argv, argc, "ip", &idx)) {
15052 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15053 vty_out(vty, "if you are using this please migrate to the below command.\n");
15054 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
15055 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
15056 }
15057 argv_find(argv, argc, "(100-500)", &idx);
15058 argv_find(argv, argc, "WORD", &idx);
15059 cl_number_or_name = argv[idx]->arg;
15060 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
15061 : COMMUNITY_DENY;
15062 argv_find(argv, argc, "LINE", &idx);
15063 char *str = argv_concat(argv, argc, idx);
15064
15065 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
15066 direct, style);
15067
15068 XFREE(MTYPE_TMP, str);
15069
15070 if (ret < 0) {
15071 community_list_perror(vty, ret);
15072 return CMD_WARNING_CONFIG_FAILED;
15073 }
15074
15075 return CMD_SUCCESS;
15076 }
15077
15078 ALIAS (no_extcommunity_list_expanded_all,
15079 no_ip_extcommunity_list_expanded_all_cmd,
15080 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
15081 NO_STR
15082 IP_STR
15083 EXTCOMMUNITY_LIST_STR
15084 "Extended Community list number (expanded)\n"
15085 "Specify expanded extcommunity-list\n"
15086 "Extended Community list name\n"
15087 "Specify community to reject\n"
15088 "Specify community to accept\n"
15089 "An ordered list as a regular-expression\n")
15090
15091 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
15092 {
15093 struct community_entry *entry;
15094
15095 for (entry = list->head; entry; entry = entry->next) {
15096 if (entry == list->head) {
15097 if (all_digit(list->name))
15098 vty_out(vty, "Extended community %s list %s\n",
15099 entry->style == EXTCOMMUNITY_LIST_STANDARD
15100 ? "standard"
15101 : "(expanded) access",
15102 list->name);
15103 else
15104 vty_out(vty,
15105 "Named extended community %s list %s\n",
15106 entry->style == EXTCOMMUNITY_LIST_STANDARD
15107 ? "standard"
15108 : "expanded",
15109 list->name);
15110 }
15111 if (entry->any)
15112 vty_out(vty, " %s\n",
15113 community_direct_str(entry->direct));
15114 else
15115 vty_out(vty, " %s %s\n",
15116 community_direct_str(entry->direct),
15117 community_list_config_str(entry));
15118 }
15119 }
15120
15121 DEFUN (show_extcommunity_list,
15122 show_bgp_extcommunity_list_cmd,
15123 "show bgp extcommunity-list",
15124 SHOW_STR
15125 BGP_STR
15126 "List extended-community list\n")
15127 {
15128 struct community_list *list;
15129 struct community_list_master *cm;
15130 int idx = 0;
15131
15132 if (argv_find(argv, argc, "ip", &idx)) {
15133 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
15134 vty_out(vty, "if you are using this please migrate to the below command.\n");
15135 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15136 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15137 }
15138 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15139 if (!cm)
15140 return CMD_SUCCESS;
15141
15142 for (list = cm->num.head; list; list = list->next)
15143 extcommunity_list_show(vty, list);
15144
15145 for (list = cm->str.head; list; list = list->next)
15146 extcommunity_list_show(vty, list);
15147
15148 return CMD_SUCCESS;
15149 }
15150
15151 ALIAS (show_extcommunity_list,
15152 show_ip_extcommunity_list_cmd,
15153 "show ip extcommunity-list",
15154 SHOW_STR
15155 IP_STR
15156 "List extended-community list\n")
15157
15158 DEFUN (show_extcommunity_list_arg,
15159 show_bgp_extcommunity_list_arg_cmd,
15160 "show bgp extcommunity-list <(1-500)|WORD>",
15161 SHOW_STR
15162 BGP_STR
15163 "List extended-community list\n"
15164 "Extcommunity-list number\n"
15165 "Extcommunity-list name\n")
15166 {
15167 int idx_comm_list = 3;
15168 struct community_list *list;
15169 int idx = 0;
15170
15171 if (argv_find(argv, argc, "ip", &idx)) {
15172 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15173 vty_out(vty, "if you are using this please migrate to the below command.\n");
15174 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15175 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15176 }
15177 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
15178 EXTCOMMUNITY_LIST_MASTER);
15179 if (!list) {
15180 vty_out(vty, "%% Can't find extcommunity-list\n");
15181 return CMD_WARNING;
15182 }
15183
15184 extcommunity_list_show(vty, list);
15185
15186 return CMD_SUCCESS;
15187 }
15188
15189 ALIAS (show_extcommunity_list_arg,
15190 show_ip_extcommunity_list_arg_cmd,
15191 "show ip extcommunity-list <(1-500)|WORD>",
15192 SHOW_STR
15193 IP_STR
15194 "List extended-community list\n"
15195 "Extcommunity-list number\n"
15196 "Extcommunity-list name\n")
15197
15198 /* Display community-list and extcommunity-list configuration. */
15199 static int community_list_config_write(struct vty *vty)
15200 {
15201 struct community_list *list;
15202 struct community_entry *entry;
15203 struct community_list_master *cm;
15204 int write = 0;
15205
15206 /* Community-list. */
15207 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15208
15209 for (list = cm->num.head; list; list = list->next)
15210 for (entry = list->head; entry; entry = entry->next) {
15211 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15212 community_direct_str(entry->direct),
15213 community_list_config_str(entry));
15214 write++;
15215 }
15216 for (list = cm->str.head; list; list = list->next)
15217 for (entry = list->head; entry; entry = entry->next) {
15218 vty_out(vty, "bgp community-list %s %s %s %s\n",
15219 entry->style == COMMUNITY_LIST_STANDARD
15220 ? "standard"
15221 : "expanded",
15222 list->name, community_direct_str(entry->direct),
15223 community_list_config_str(entry));
15224 write++;
15225 }
15226
15227 /* Extcommunity-list. */
15228 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15229
15230 for (list = cm->num.head; list; list = list->next)
15231 for (entry = list->head; entry; entry = entry->next) {
15232 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15233 list->name, community_direct_str(entry->direct),
15234 community_list_config_str(entry));
15235 write++;
15236 }
15237 for (list = cm->str.head; list; list = list->next)
15238 for (entry = list->head; entry; entry = entry->next) {
15239 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15240 entry->style == EXTCOMMUNITY_LIST_STANDARD
15241 ? "standard"
15242 : "expanded",
15243 list->name, community_direct_str(entry->direct),
15244 community_list_config_str(entry));
15245 write++;
15246 }
15247
15248
15249 /* lcommunity-list. */
15250 cm = community_list_master_lookup(bgp_clist,
15251 LARGE_COMMUNITY_LIST_MASTER);
15252
15253 for (list = cm->num.head; list; list = list->next)
15254 for (entry = list->head; entry; entry = entry->next) {
15255 vty_out(vty, "bgp large-community-list %s %s %s\n",
15256 list->name, community_direct_str(entry->direct),
15257 community_list_config_str(entry));
15258 write++;
15259 }
15260 for (list = cm->str.head; list; list = list->next)
15261 for (entry = list->head; entry; entry = entry->next) {
15262 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15263 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15264 ? "standard"
15265 : "expanded",
15266 list->name, community_direct_str(entry->direct),
15267 community_list_config_str(entry));
15268 write++;
15269 }
15270
15271 return write;
15272 }
15273
15274 static struct cmd_node community_list_node = {
15275 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15276 };
15277
15278 static void community_list_vty(void)
15279 {
15280 install_node(&community_list_node, community_list_config_write);
15281
15282 /* Community-list. */
15283 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15284 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15285 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15286 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_list_cmd);
15287 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15288 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_list_cmd);
15289 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15290 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15291 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15292 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15293 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15294 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_list_cmd);
15295 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15296 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_list_cmd);
15297 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15298 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15299
15300 /* Extcommunity-list. */
15301 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15302 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15303 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15304 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15305 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15306 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15307 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15308 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15309 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15310 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15311 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15312 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15313
15314 /* Large Community List */
15315 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15316 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15317 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15318 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15319 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15320 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15321 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15322 install_element(CONFIG_NODE,
15323 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15324 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15325 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15326 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15327 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15328 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15329 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15330 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15331 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15332 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15333 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15334 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15335 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15336 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15337 install_element(CONFIG_NODE,
15338 &no_ip_lcommunity_list_name_expanded_all_cmd);
15339 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15340 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15341 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15342 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15343 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15344 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15345 }