]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #3162 from pguibert6WIND/vpn_route_map_issue
[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
65 static struct peer_group *listen_range_exists(struct bgp *bgp,
66 struct prefix *range, int exact);
67
68 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
69 {
70 switch (afi) {
71 case AFI_IP:
72 switch (safi) {
73 case SAFI_UNICAST:
74 return BGP_IPV4_NODE;
75 break;
76 case SAFI_MULTICAST:
77 return BGP_IPV4M_NODE;
78 break;
79 case SAFI_LABELED_UNICAST:
80 return BGP_IPV4L_NODE;
81 break;
82 case SAFI_MPLS_VPN:
83 return BGP_VPNV4_NODE;
84 break;
85 case SAFI_FLOWSPEC:
86 return BGP_FLOWSPECV4_NODE;
87 default:
88 /* not expected */
89 return BGP_IPV4_NODE;
90 break;
91 }
92 break;
93 case AFI_IP6:
94 switch (safi) {
95 case SAFI_UNICAST:
96 return BGP_IPV6_NODE;
97 break;
98 case SAFI_MULTICAST:
99 return BGP_IPV6M_NODE;
100 break;
101 case SAFI_LABELED_UNICAST:
102 return BGP_IPV6L_NODE;
103 break;
104 case SAFI_MPLS_VPN:
105 return BGP_VPNV6_NODE;
106 break;
107 case SAFI_FLOWSPEC:
108 return BGP_FLOWSPECV6_NODE;
109 default:
110 /* not expected */
111 return BGP_IPV4_NODE;
112 break;
113 }
114 break;
115 case AFI_L2VPN:
116 return BGP_EVPN_NODE;
117 break;
118 case AFI_MAX:
119 // We should never be here but to clarify the switch statement..
120 return BGP_IPV4_NODE;
121 break;
122 }
123
124 // Impossible to happen
125 return BGP_IPV4_NODE;
126 }
127
128 /* Utility function to get address family from current node. */
129 afi_t bgp_node_afi(struct vty *vty)
130 {
131 afi_t afi;
132 switch (vty->node) {
133 case BGP_IPV6_NODE:
134 case BGP_IPV6M_NODE:
135 case BGP_IPV6L_NODE:
136 case BGP_VPNV6_NODE:
137 case BGP_FLOWSPECV6_NODE:
138 afi = AFI_IP6;
139 break;
140 case BGP_EVPN_NODE:
141 afi = AFI_L2VPN;
142 break;
143 default:
144 afi = AFI_IP;
145 break;
146 }
147 return afi;
148 }
149
150 /* Utility function to get subsequent address family from current
151 node. */
152 safi_t bgp_node_safi(struct vty *vty)
153 {
154 safi_t safi;
155 switch (vty->node) {
156 case BGP_VPNV4_NODE:
157 case BGP_VPNV6_NODE:
158 safi = SAFI_MPLS_VPN;
159 break;
160 case BGP_IPV4M_NODE:
161 case BGP_IPV6M_NODE:
162 safi = SAFI_MULTICAST;
163 break;
164 case BGP_EVPN_NODE:
165 safi = SAFI_EVPN;
166 break;
167 case BGP_IPV4L_NODE:
168 case BGP_IPV6L_NODE:
169 safi = SAFI_LABELED_UNICAST;
170 break;
171 case BGP_FLOWSPECV4_NODE:
172 case BGP_FLOWSPECV6_NODE:
173 safi = SAFI_FLOWSPEC;
174 break;
175 default:
176 safi = SAFI_UNICAST;
177 break;
178 }
179 return safi;
180 }
181
182 /**
183 * Converts an AFI in string form to afi_t
184 *
185 * @param afi string, one of
186 * - "ipv4"
187 * - "ipv6"
188 * - "l2vpn"
189 * @return the corresponding afi_t
190 */
191 afi_t bgp_vty_afi_from_str(const char *afi_str)
192 {
193 afi_t afi = AFI_MAX; /* unknown */
194 if (strmatch(afi_str, "ipv4"))
195 afi = AFI_IP;
196 else if (strmatch(afi_str, "ipv6"))
197 afi = AFI_IP6;
198 else if (strmatch(afi_str, "l2vpn"))
199 afi = AFI_L2VPN;
200 return afi;
201 }
202
203 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
204 afi_t *afi)
205 {
206 int ret = 0;
207 if (argv_find(argv, argc, "ipv4", index)) {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP;
211 } else if (argv_find(argv, argc, "ipv6", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP6;
215 }
216 return ret;
217 }
218
219 /* supports <unicast|multicast|vpn|labeled-unicast> */
220 safi_t bgp_vty_safi_from_str(const char *safi_str)
221 {
222 safi_t safi = SAFI_MAX; /* unknown */
223 if (strmatch(safi_str, "multicast"))
224 safi = SAFI_MULTICAST;
225 else if (strmatch(safi_str, "unicast"))
226 safi = SAFI_UNICAST;
227 else if (strmatch(safi_str, "vpn"))
228 safi = SAFI_MPLS_VPN;
229 else if (strmatch(safi_str, "evpn"))
230 safi = SAFI_EVPN;
231 else if (strmatch(safi_str, "labeled-unicast"))
232 safi = SAFI_LABELED_UNICAST;
233 else if (strmatch(safi_str, "flowspec"))
234 safi = SAFI_FLOWSPEC;
235 return safi;
236 }
237
238 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
239 safi_t *safi)
240 {
241 int ret = 0;
242 if (argv_find(argv, argc, "unicast", index)) {
243 ret = 1;
244 if (safi)
245 *safi = SAFI_UNICAST;
246 } else if (argv_find(argv, argc, "multicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_MULTICAST;
250 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_LABELED_UNICAST;
254 } else if (argv_find(argv, argc, "vpn", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_MPLS_VPN;
258 } else if (argv_find(argv, argc, "flowspec", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_FLOWSPEC;
262 }
263 return ret;
264 }
265
266 /*
267 * bgp_vty_find_and_parse_afi_safi_bgp
268 *
269 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
270 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
271 * to appropriate values for the calling function. This is to allow the
272 * calling function to make decisions appropriate for the show command
273 * that is being parsed.
274 *
275 * The show commands are generally of the form:
276 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
277 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
278 *
279 * Since we use argv_find if the show command in particular doesn't have:
280 * [ip]
281 * [<view|vrf> VIEWVRFNAME]
282 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
283 * The command parsing should still be ok.
284 *
285 * vty -> The vty for the command so we can output some useful data in
286 * the event of a parse error in the vrf.
287 * argv -> The command tokens
288 * argc -> How many command tokens we have
289 * idx -> The current place in the command, generally should be 0 for this
290 * function
291 * afi -> The parsed afi if it was included in the show command, returned here
292 * safi -> The parsed safi if it was included in the show command, returned here
293 * bgp -> Pointer to the bgp data structure we need to fill in.
294 *
295 * The function returns the correct location in the parse tree for the
296 * last token found.
297 *
298 * Returns 0 for failure to parse correctly, else the idx position of where
299 * it found the last token.
300 */
301 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
302 struct cmd_token **argv, int argc,
303 int *idx, afi_t *afi, safi_t *safi,
304 struct bgp **bgp, bool use_json)
305 {
306 char *vrf_name = NULL;
307
308 assert(afi);
309 assert(safi);
310 assert(bgp);
311
312 if (argv_find(argv, argc, "ip", idx))
313 *afi = AFI_IP;
314
315 if (argv_find(argv, argc, "view", idx))
316 vrf_name = argv[*idx + 1]->arg;
317 else if (argv_find(argv, argc, "vrf", idx)) {
318 vrf_name = argv[*idx + 1]->arg;
319 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
320 vrf_name = NULL;
321 }
322 if (vrf_name) {
323 if (strmatch(vrf_name, "all"))
324 *bgp = NULL;
325 else {
326 *bgp = bgp_lookup_by_name(vrf_name);
327 if (!*bgp) {
328 if (use_json)
329 vty_out(vty, "{}\n");
330 else
331 vty_out(vty, "View/Vrf %s is unknown\n",
332 vrf_name);
333 *idx = 0;
334 return 0;
335 }
336 }
337 } else {
338 *bgp = bgp_get_default();
339 if (!*bgp) {
340 if (use_json)
341 vty_out(vty, "{}\n");
342 else
343 vty_out(vty,
344 "Default BGP instance not found\n");
345 *idx = 0;
346 return 0;
347 }
348 }
349
350 if (argv_find_and_parse_afi(argv, argc, idx, afi))
351 argv_find_and_parse_safi(argv, argc, idx, safi);
352
353 *idx += 1;
354 return *idx;
355 }
356
357 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
358 {
359 struct interface *ifp = NULL;
360
361 if (su->sa.sa_family == AF_INET)
362 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
363 else if (su->sa.sa_family == AF_INET6)
364 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
365 su->sin6.sin6_scope_id,
366 bgp->vrf_id);
367
368 if (ifp)
369 return 1;
370
371 return 0;
372 }
373
374 /* Utility function for looking up peer from VTY. */
375 /* This is used only for configuration, so disallow if attempted on
376 * a dynamic neighbor.
377 */
378 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
379 {
380 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
381 int ret;
382 union sockunion su;
383 struct peer *peer;
384
385 if (!bgp) {
386 return NULL;
387 }
388
389 ret = str2sockunion(ip_str, &su);
390 if (ret < 0) {
391 peer = peer_lookup_by_conf_if(bgp, ip_str);
392 if (!peer) {
393 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
394 == NULL) {
395 vty_out(vty,
396 "%% Malformed address or name: %s\n",
397 ip_str);
398 return NULL;
399 }
400 }
401 } else {
402 peer = peer_lookup(bgp, &su);
403 if (!peer) {
404 vty_out(vty,
405 "%% Specify remote-as or peer-group commands first\n");
406 return NULL;
407 }
408 if (peer_dynamic_neighbor(peer)) {
409 vty_out(vty,
410 "%% Operation not allowed on a dynamic neighbor\n");
411 return NULL;
412 }
413 }
414 return peer;
415 }
416
417 /* Utility function for looking up peer or peer group. */
418 /* This is used only for configuration, so disallow if attempted on
419 * a dynamic neighbor.
420 */
421 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
422 {
423 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
424 int ret;
425 union sockunion su;
426 struct peer *peer = NULL;
427 struct peer_group *group = NULL;
428
429 if (!bgp) {
430 return NULL;
431 }
432
433 ret = str2sockunion(peer_str, &su);
434 if (ret == 0) {
435 /* IP address, locate peer. */
436 peer = peer_lookup(bgp, &su);
437 } else {
438 /* Not IP, could match either peer configured on interface or a
439 * group. */
440 peer = peer_lookup_by_conf_if(bgp, peer_str);
441 if (!peer)
442 group = peer_group_lookup(bgp, peer_str);
443 }
444
445 if (peer) {
446 if (peer_dynamic_neighbor(peer)) {
447 vty_out(vty,
448 "%% Operation not allowed on a dynamic neighbor\n");
449 return NULL;
450 }
451
452 return peer;
453 }
454
455 if (group)
456 return group->conf;
457
458 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
459
460 return NULL;
461 }
462
463 int bgp_vty_return(struct vty *vty, int ret)
464 {
465 const char *str = NULL;
466
467 switch (ret) {
468 case BGP_ERR_INVALID_VALUE:
469 str = "Invalid value";
470 break;
471 case BGP_ERR_INVALID_FLAG:
472 str = "Invalid flag";
473 break;
474 case BGP_ERR_PEER_GROUP_SHUTDOWN:
475 str = "Peer-group has been shutdown. Activate the peer-group first";
476 break;
477 case BGP_ERR_PEER_FLAG_CONFLICT:
478 str = "Can't set override-capability and strict-capability-match at the same time";
479 break;
480 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
481 str = "Specify remote-as or peer-group remote AS first";
482 break;
483 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
484 str = "Cannot change the peer-group. Deconfigure first";
485 break;
486 case BGP_ERR_PEER_GROUP_MISMATCH:
487 str = "Peer is not a member of this peer-group";
488 break;
489 case BGP_ERR_PEER_FILTER_CONFLICT:
490 str = "Prefix/distribute list can not co-exist";
491 break;
492 case BGP_ERR_NOT_INTERNAL_PEER:
493 str = "Invalid command. Not an internal neighbor";
494 break;
495 case BGP_ERR_REMOVE_PRIVATE_AS:
496 str = "remove-private-AS cannot be configured for IBGP peers";
497 break;
498 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
499 str = "Local-AS allowed only for EBGP peers";
500 break;
501 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
502 str = "Cannot have local-as same as BGP AS number";
503 break;
504 case BGP_ERR_TCPSIG_FAILED:
505 str = "Error while applying TCP-Sig to session(s)";
506 break;
507 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
508 str = "ebgp-multihop and ttl-security cannot be configured together";
509 break;
510 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
511 str = "ttl-security only allowed for EBGP peers";
512 break;
513 case BGP_ERR_AS_OVERRIDE:
514 str = "as-override cannot be configured for IBGP peers";
515 break;
516 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
517 str = "Invalid limit for number of dynamic neighbors";
518 break;
519 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
520 str = "Dynamic neighbor listen range already exists";
521 break;
522 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
523 str = "Operation not allowed on a dynamic neighbor";
524 break;
525 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
526 str = "Operation not allowed on a directly connected neighbor";
527 break;
528 case BGP_ERR_PEER_SAFI_CONFLICT:
529 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
530 break;
531 }
532 if (str) {
533 vty_out(vty, "%% %s\n", str);
534 return CMD_WARNING_CONFIG_FAILED;
535 }
536 return CMD_SUCCESS;
537 }
538
539 /* BGP clear sort. */
540 enum clear_sort {
541 clear_all,
542 clear_peer,
543 clear_group,
544 clear_external,
545 clear_as
546 };
547
548 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
549 safi_t safi, int error)
550 {
551 switch (error) {
552 case BGP_ERR_AF_UNCONFIGURED:
553 vty_out(vty,
554 "%%BGP: Enable %s address family for the neighbor %s\n",
555 afi_safi_print(afi, safi), peer->host);
556 break;
557 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
558 vty_out(vty,
559 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
560 peer->host);
561 break;
562 default:
563 break;
564 }
565 }
566
567 /* `clear ip bgp' functions. */
568 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
569 enum clear_sort sort, enum bgp_clear_type stype,
570 const char *arg)
571 {
572 int ret;
573 bool found = false;
574 struct peer *peer;
575 struct listnode *node, *nnode;
576
577 /* Clear all neighbors. */
578 /*
579 * Pass along pointer to next node to peer_clear() when walking all
580 * nodes on the BGP instance as that may get freed if it is a
581 * doppelganger
582 */
583 if (sort == clear_all) {
584 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
585 if (!peer->afc[afi][safi])
586 continue;
587
588 if (stype == BGP_CLEAR_SOFT_NONE)
589 ret = peer_clear(peer, &nnode);
590 else
591 ret = peer_clear_soft(peer, afi, safi, stype);
592
593 if (ret < 0)
594 bgp_clear_vty_error(vty, peer, afi, safi, ret);
595 else
596 found = true;
597 }
598
599 /* This is to apply read-only mode on this clear. */
600 if (stype == BGP_CLEAR_SOFT_NONE)
601 bgp->update_delay_over = 0;
602
603 if (!found)
604 vty_out(vty, "%%BGP: No %s peer configured",
605 afi_safi_print(afi, safi));
606
607 return CMD_SUCCESS;
608 }
609
610 /* Clear specified neighbor. */
611 if (sort == clear_peer) {
612 union sockunion su;
613
614 /* Make sockunion for lookup. */
615 ret = str2sockunion(arg, &su);
616 if (ret < 0) {
617 peer = peer_lookup_by_conf_if(bgp, arg);
618 if (!peer) {
619 peer = peer_lookup_by_hostname(bgp, arg);
620 if (!peer) {
621 vty_out(vty,
622 "Malformed address or name: %s\n",
623 arg);
624 return CMD_WARNING;
625 }
626 }
627 } else {
628 peer = peer_lookup(bgp, &su);
629 if (!peer) {
630 vty_out(vty,
631 "%%BGP: Unknown neighbor - \"%s\"\n",
632 arg);
633 return CMD_WARNING;
634 }
635 }
636
637 if (!peer->afc[afi][safi])
638 ret = BGP_ERR_AF_UNCONFIGURED;
639 else if (stype == BGP_CLEAR_SOFT_NONE)
640 ret = peer_clear(peer, NULL);
641 else
642 ret = peer_clear_soft(peer, afi, safi, stype);
643
644 if (ret < 0)
645 bgp_clear_vty_error(vty, peer, afi, safi, ret);
646
647 return CMD_SUCCESS;
648 }
649
650 /* Clear all neighbors belonging to a specific peer-group. */
651 if (sort == clear_group) {
652 struct peer_group *group;
653
654 group = peer_group_lookup(bgp, arg);
655 if (!group) {
656 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
657 return CMD_WARNING;
658 }
659
660 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
661 if (!peer->afc[afi][safi])
662 continue;
663
664 if (stype == BGP_CLEAR_SOFT_NONE)
665 ret = peer_clear(peer, NULL);
666 else
667 ret = peer_clear_soft(peer, afi, safi, stype);
668
669 if (ret < 0)
670 bgp_clear_vty_error(vty, peer, afi, safi, ret);
671 else
672 found = true;
673 }
674
675 if (!found)
676 vty_out(vty,
677 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
678 afi_safi_print(afi, safi), arg);
679
680 return CMD_SUCCESS;
681 }
682
683 /* Clear all external (eBGP) neighbors. */
684 if (sort == clear_external) {
685 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
686 if (peer->sort == BGP_PEER_IBGP)
687 continue;
688
689 if (!peer->afc[afi][safi])
690 continue;
691
692 if (stype == BGP_CLEAR_SOFT_NONE)
693 ret = peer_clear(peer, &nnode);
694 else
695 ret = peer_clear_soft(peer, afi, safi, stype);
696
697 if (ret < 0)
698 bgp_clear_vty_error(vty, peer, afi, safi, ret);
699 else
700 found = true;
701 }
702
703 if (!found)
704 vty_out(vty,
705 "%%BGP: No external %s peer is configured\n",
706 afi_safi_print(afi, safi));
707
708 return CMD_SUCCESS;
709 }
710
711 /* Clear all neighbors belonging to a specific AS. */
712 if (sort == clear_as) {
713 as_t as = strtoul(arg, NULL, 10);
714
715 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
716 if (peer->as != as)
717 continue;
718
719 if (!peer->afc[afi][safi])
720 ret = BGP_ERR_AF_UNCONFIGURED;
721 else if (stype == BGP_CLEAR_SOFT_NONE)
722 ret = peer_clear(peer, &nnode);
723 else
724 ret = peer_clear_soft(peer, afi, safi, stype);
725
726 if (ret < 0)
727 bgp_clear_vty_error(vty, peer, afi, safi, ret);
728 else
729 found = true;
730 }
731
732 if (!found)
733 vty_out(vty,
734 "%%BGP: No %s peer is configured with AS %s\n",
735 afi_safi_print(afi, safi), arg);
736
737 return CMD_SUCCESS;
738 }
739
740 return CMD_SUCCESS;
741 }
742
743 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
744 safi_t safi, enum clear_sort sort,
745 enum bgp_clear_type stype, const char *arg)
746 {
747 struct bgp *bgp;
748
749 /* BGP structure lookup. */
750 if (name) {
751 bgp = bgp_lookup_by_name(name);
752 if (bgp == NULL) {
753 vty_out(vty, "Can't find BGP instance %s\n", name);
754 return CMD_WARNING;
755 }
756 } else {
757 bgp = bgp_get_default();
758 if (bgp == NULL) {
759 vty_out(vty, "No BGP process is configured\n");
760 return CMD_WARNING;
761 }
762 }
763
764 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
765 }
766
767 /* clear soft inbound */
768 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
769 {
770 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
771 BGP_CLEAR_SOFT_IN, NULL);
772 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
773 BGP_CLEAR_SOFT_IN, NULL);
774 }
775
776 /* clear soft outbound */
777 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
778 {
779 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
780 BGP_CLEAR_SOFT_OUT, NULL);
781 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
782 BGP_CLEAR_SOFT_OUT, NULL);
783 }
784
785
786 #ifndef VTYSH_EXTRACT_PL
787 #include "bgpd/bgp_vty_clippy.c"
788 #endif
789
790 /* BGP global configuration. */
791 #if (CONFDATE > 20190601)
792 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
793 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
794 #endif
795 DEFUN_HIDDEN (bgp_multiple_instance_func,
796 bgp_multiple_instance_cmd,
797 "bgp multiple-instance",
798 BGP_STR
799 "Enable bgp multiple instance\n")
800 {
801 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
802 return CMD_SUCCESS;
803 }
804
805 DEFUN_HIDDEN (no_bgp_multiple_instance,
806 no_bgp_multiple_instance_cmd,
807 "no bgp multiple-instance",
808 NO_STR
809 BGP_STR
810 "BGP multiple instance\n")
811 {
812 int ret;
813
814 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
815 vty_out(vty, "if you are using this please let the developers know\n");
816 zlog_info("Deprecated option: `bgp multiple-instance` being used");
817 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
818 if (ret < 0) {
819 vty_out(vty, "%% There are more than two BGP instances\n");
820 return CMD_WARNING_CONFIG_FAILED;
821 }
822 return CMD_SUCCESS;
823 }
824
825 #if (CONFDATE > 20190601)
826 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
827 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
828 #endif
829 DEFUN_HIDDEN (bgp_config_type,
830 bgp_config_type_cmd,
831 "bgp config-type <cisco|zebra>",
832 BGP_STR
833 "Configuration type\n"
834 "cisco\n"
835 "zebra\n")
836 {
837 int idx = 0;
838 if (argv_find(argv, argc, "cisco", &idx)) {
839 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
840 vty_out(vty, "if you are using this please let the developers know!\n");
841 zlog_info("Deprecated option: `bgp config-type cisco` being used");
842 bgp_option_set(BGP_OPT_CONFIG_CISCO);
843 } else
844 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
845
846 return CMD_SUCCESS;
847 }
848
849 DEFUN_HIDDEN (no_bgp_config_type,
850 no_bgp_config_type_cmd,
851 "no bgp config-type [<cisco|zebra>]",
852 NO_STR
853 BGP_STR
854 "Display configuration type\n"
855 "cisco\n"
856 "zebra\n")
857 {
858 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
859 return CMD_SUCCESS;
860 }
861
862
863 DEFUN (no_synchronization,
864 no_synchronization_cmd,
865 "no synchronization",
866 NO_STR
867 "Perform IGP synchronization\n")
868 {
869 return CMD_SUCCESS;
870 }
871
872 DEFUN (no_auto_summary,
873 no_auto_summary_cmd,
874 "no auto-summary",
875 NO_STR
876 "Enable automatic network number summarization\n")
877 {
878 return CMD_SUCCESS;
879 }
880
881 /* "router bgp" commands. */
882 DEFUN_NOSH (router_bgp,
883 router_bgp_cmd,
884 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
885 ROUTER_STR
886 BGP_STR
887 AS_STR
888 BGP_INSTANCE_HELP_STR)
889 {
890 int idx_asn = 2;
891 int idx_view_vrf = 3;
892 int idx_vrf = 4;
893 int ret;
894 as_t as;
895 struct bgp *bgp;
896 const char *name = NULL;
897 enum bgp_instance_type inst_type;
898
899 // "router bgp" without an ASN
900 if (argc == 2) {
901 // Pending: Make VRF option available for ASN less config
902 bgp = bgp_get_default();
903
904 if (bgp == NULL) {
905 vty_out(vty, "%% No BGP process is configured\n");
906 return CMD_WARNING_CONFIG_FAILED;
907 }
908
909 if (listcount(bm->bgp) > 1) {
910 vty_out(vty, "%% Please specify ASN and VRF\n");
911 return CMD_WARNING_CONFIG_FAILED;
912 }
913 }
914
915 // "router bgp X"
916 else {
917 as = strtoul(argv[idx_asn]->arg, NULL, 10);
918
919 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
920 if (argc > 3) {
921 name = argv[idx_vrf]->arg;
922
923 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
924 if (strmatch(name, VRF_DEFAULT_NAME))
925 name = NULL;
926 else
927 inst_type = BGP_INSTANCE_TYPE_VRF;
928 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
929 inst_type = BGP_INSTANCE_TYPE_VIEW;
930 }
931
932 ret = bgp_get(&bgp, &as, name, inst_type);
933 switch (ret) {
934 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
935 vty_out(vty,
936 "Please specify 'bgp multiple-instance' first\n");
937 return CMD_WARNING_CONFIG_FAILED;
938 case BGP_ERR_AS_MISMATCH:
939 vty_out(vty, "BGP is already running; AS is %u\n", as);
940 return CMD_WARNING_CONFIG_FAILED;
941 case BGP_ERR_INSTANCE_MISMATCH:
942 vty_out(vty,
943 "BGP instance name and AS number mismatch\n");
944 vty_out(vty,
945 "BGP instance is already running; AS is %u\n",
946 as);
947 return CMD_WARNING_CONFIG_FAILED;
948 }
949
950 /*
951 * If we just instantiated the default instance, complete
952 * any pending VRF-VPN leaking that was configured via
953 * earlier "router bgp X vrf FOO" blocks.
954 */
955 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
956 vpn_leak_postchange_all();
957
958 /* Pending: handle when user tries to change a view to vrf n vv.
959 */
960 }
961
962 /* unset the auto created flag as the user config is now present */
963 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
964 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
965
966 return CMD_SUCCESS;
967 }
968
969 /* "no router bgp" commands. */
970 DEFUN (no_router_bgp,
971 no_router_bgp_cmd,
972 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
973 NO_STR
974 ROUTER_STR
975 BGP_STR
976 AS_STR
977 BGP_INSTANCE_HELP_STR)
978 {
979 int idx_asn = 3;
980 int idx_vrf = 5;
981 as_t as;
982 struct bgp *bgp;
983 const char *name = NULL;
984
985 // "no router bgp" without an ASN
986 if (argc == 3) {
987 // Pending: Make VRF option available for ASN less config
988 bgp = bgp_get_default();
989
990 if (bgp == NULL) {
991 vty_out(vty, "%% No BGP process is configured\n");
992 return CMD_WARNING_CONFIG_FAILED;
993 }
994
995 if (listcount(bm->bgp) > 1) {
996 vty_out(vty, "%% Please specify ASN and VRF\n");
997 return CMD_WARNING_CONFIG_FAILED;
998 }
999
1000 if (bgp->l3vni) {
1001 vty_out(vty, "%% Please unconfigure l3vni %u",
1002 bgp->l3vni);
1003 return CMD_WARNING_CONFIG_FAILED;
1004 }
1005 } else {
1006 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1007
1008 if (argc > 4)
1009 name = argv[idx_vrf]->arg;
1010
1011 /* Lookup bgp structure. */
1012 bgp = bgp_lookup(as, name);
1013 if (!bgp) {
1014 vty_out(vty, "%% Can't find BGP instance\n");
1015 return CMD_WARNING_CONFIG_FAILED;
1016 }
1017
1018 if (bgp->l3vni) {
1019 vty_out(vty, "%% Please unconfigure l3vni %u",
1020 bgp->l3vni);
1021 return CMD_WARNING_CONFIG_FAILED;
1022 }
1023 }
1024
1025 bgp_delete(bgp);
1026
1027 return CMD_SUCCESS;
1028 }
1029
1030
1031 /* BGP router-id. */
1032
1033 DEFPY (bgp_router_id,
1034 bgp_router_id_cmd,
1035 "bgp router-id A.B.C.D",
1036 BGP_STR
1037 "Override configured router identifier\n"
1038 "Manually configured router identifier\n")
1039 {
1040 VTY_DECLVAR_CONTEXT(bgp, bgp);
1041 bgp_router_id_static_set(bgp, router_id);
1042 return CMD_SUCCESS;
1043 }
1044
1045 DEFPY (no_bgp_router_id,
1046 no_bgp_router_id_cmd,
1047 "no bgp router-id [A.B.C.D]",
1048 NO_STR
1049 BGP_STR
1050 "Override configured router identifier\n"
1051 "Manually configured router identifier\n")
1052 {
1053 VTY_DECLVAR_CONTEXT(bgp, bgp);
1054
1055 if (router_id_str) {
1056 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1057 vty_out(vty, "%% BGP router-id doesn't match\n");
1058 return CMD_WARNING_CONFIG_FAILED;
1059 }
1060 }
1061
1062 router_id.s_addr = 0;
1063 bgp_router_id_static_set(bgp, router_id);
1064
1065 return CMD_SUCCESS;
1066 }
1067
1068
1069 /* BGP Cluster ID. */
1070 DEFUN (bgp_cluster_id,
1071 bgp_cluster_id_cmd,
1072 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1073 BGP_STR
1074 "Configure Route-Reflector Cluster-id\n"
1075 "Route-Reflector Cluster-id in IP address format\n"
1076 "Route-Reflector Cluster-id as 32 bit quantity\n")
1077 {
1078 VTY_DECLVAR_CONTEXT(bgp, bgp);
1079 int idx_ipv4 = 2;
1080 int ret;
1081 struct in_addr cluster;
1082
1083 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1084 if (!ret) {
1085 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1086 return CMD_WARNING_CONFIG_FAILED;
1087 }
1088
1089 bgp_cluster_id_set(bgp, &cluster);
1090 bgp_clear_star_soft_out(vty, bgp->name);
1091
1092 return CMD_SUCCESS;
1093 }
1094
1095 DEFUN (no_bgp_cluster_id,
1096 no_bgp_cluster_id_cmd,
1097 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1098 NO_STR
1099 BGP_STR
1100 "Configure Route-Reflector Cluster-id\n"
1101 "Route-Reflector Cluster-id in IP address format\n"
1102 "Route-Reflector Cluster-id as 32 bit quantity\n")
1103 {
1104 VTY_DECLVAR_CONTEXT(bgp, bgp);
1105 bgp_cluster_id_unset(bgp);
1106 bgp_clear_star_soft_out(vty, bgp->name);
1107
1108 return CMD_SUCCESS;
1109 }
1110
1111 DEFUN (bgp_confederation_identifier,
1112 bgp_confederation_identifier_cmd,
1113 "bgp confederation identifier (1-4294967295)",
1114 "BGP specific commands\n"
1115 "AS confederation parameters\n"
1116 "AS number\n"
1117 "Set routing domain confederation AS\n")
1118 {
1119 VTY_DECLVAR_CONTEXT(bgp, bgp);
1120 int idx_number = 3;
1121 as_t as;
1122
1123 as = strtoul(argv[idx_number]->arg, NULL, 10);
1124
1125 bgp_confederation_id_set(bgp, as);
1126
1127 return CMD_SUCCESS;
1128 }
1129
1130 DEFUN (no_bgp_confederation_identifier,
1131 no_bgp_confederation_identifier_cmd,
1132 "no bgp confederation identifier [(1-4294967295)]",
1133 NO_STR
1134 "BGP specific commands\n"
1135 "AS confederation parameters\n"
1136 "AS number\n"
1137 "Set routing domain confederation AS\n")
1138 {
1139 VTY_DECLVAR_CONTEXT(bgp, bgp);
1140 bgp_confederation_id_unset(bgp);
1141
1142 return CMD_SUCCESS;
1143 }
1144
1145 DEFUN (bgp_confederation_peers,
1146 bgp_confederation_peers_cmd,
1147 "bgp confederation peers (1-4294967295)...",
1148 "BGP specific commands\n"
1149 "AS confederation parameters\n"
1150 "Peer ASs in BGP confederation\n"
1151 AS_STR)
1152 {
1153 VTY_DECLVAR_CONTEXT(bgp, bgp);
1154 int idx_asn = 3;
1155 as_t as;
1156 int i;
1157
1158 for (i = idx_asn; i < argc; i++) {
1159 as = strtoul(argv[i]->arg, NULL, 10);
1160
1161 if (bgp->as == as) {
1162 vty_out(vty,
1163 "%% Local member-AS not allowed in confed peer list\n");
1164 continue;
1165 }
1166
1167 bgp_confederation_peers_add(bgp, as);
1168 }
1169 return CMD_SUCCESS;
1170 }
1171
1172 DEFUN (no_bgp_confederation_peers,
1173 no_bgp_confederation_peers_cmd,
1174 "no bgp confederation peers (1-4294967295)...",
1175 NO_STR
1176 "BGP specific commands\n"
1177 "AS confederation parameters\n"
1178 "Peer ASs in BGP confederation\n"
1179 AS_STR)
1180 {
1181 VTY_DECLVAR_CONTEXT(bgp, bgp);
1182 int idx_asn = 4;
1183 as_t as;
1184 int i;
1185
1186 for (i = idx_asn; i < argc; i++) {
1187 as = strtoul(argv[i]->arg, NULL, 10);
1188
1189 bgp_confederation_peers_remove(bgp, as);
1190 }
1191 return CMD_SUCCESS;
1192 }
1193
1194 /**
1195 * Central routine for maximum-paths configuration.
1196 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1197 * @set: 1 for setting values, 0 for removing the max-paths config.
1198 */
1199 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1200 const char *mpaths, uint16_t options,
1201 int set)
1202 {
1203 VTY_DECLVAR_CONTEXT(bgp, bgp);
1204 uint16_t maxpaths = 0;
1205 int ret;
1206 afi_t afi;
1207 safi_t safi;
1208
1209 afi = bgp_node_afi(vty);
1210 safi = bgp_node_safi(vty);
1211
1212 if (set) {
1213 maxpaths = strtol(mpaths, NULL, 10);
1214 if (maxpaths > multipath_num) {
1215 vty_out(vty,
1216 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1217 maxpaths, multipath_num);
1218 return CMD_WARNING_CONFIG_FAILED;
1219 }
1220 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1221 options);
1222 } else
1223 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1224
1225 if (ret < 0) {
1226 vty_out(vty,
1227 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1228 (set == 1) ? "" : "un",
1229 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1230 maxpaths, afi, safi);
1231 return CMD_WARNING_CONFIG_FAILED;
1232 }
1233
1234 bgp_recalculate_all_bestpaths(bgp);
1235
1236 return CMD_SUCCESS;
1237 }
1238
1239 DEFUN (bgp_maxmed_admin,
1240 bgp_maxmed_admin_cmd,
1241 "bgp max-med administrative ",
1242 BGP_STR
1243 "Advertise routes with max-med\n"
1244 "Administratively applied, for an indefinite period\n")
1245 {
1246 VTY_DECLVAR_CONTEXT(bgp, bgp);
1247
1248 bgp->v_maxmed_admin = 1;
1249 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1250
1251 bgp_maxmed_update(bgp);
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 DEFUN (bgp_maxmed_admin_medv,
1257 bgp_maxmed_admin_medv_cmd,
1258 "bgp max-med administrative (0-4294967295)",
1259 BGP_STR
1260 "Advertise routes with max-med\n"
1261 "Administratively applied, for an indefinite period\n"
1262 "Max MED value to be used\n")
1263 {
1264 VTY_DECLVAR_CONTEXT(bgp, bgp);
1265 int idx_number = 3;
1266
1267 bgp->v_maxmed_admin = 1;
1268 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1269
1270 bgp_maxmed_update(bgp);
1271
1272 return CMD_SUCCESS;
1273 }
1274
1275 DEFUN (no_bgp_maxmed_admin,
1276 no_bgp_maxmed_admin_cmd,
1277 "no bgp max-med administrative [(0-4294967295)]",
1278 NO_STR
1279 BGP_STR
1280 "Advertise routes with max-med\n"
1281 "Administratively applied, for an indefinite period\n"
1282 "Max MED value to be used\n")
1283 {
1284 VTY_DECLVAR_CONTEXT(bgp, bgp);
1285 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1286 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1287 bgp_maxmed_update(bgp);
1288
1289 return CMD_SUCCESS;
1290 }
1291
1292 DEFUN (bgp_maxmed_onstartup,
1293 bgp_maxmed_onstartup_cmd,
1294 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1295 BGP_STR
1296 "Advertise routes with max-med\n"
1297 "Effective on a startup\n"
1298 "Time (seconds) period for max-med\n"
1299 "Max MED value to be used\n")
1300 {
1301 VTY_DECLVAR_CONTEXT(bgp, bgp);
1302 int idx = 0;
1303
1304 argv_find(argv, argc, "(5-86400)", &idx);
1305 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1306 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1307 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1308 else
1309 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1310
1311 bgp_maxmed_update(bgp);
1312
1313 return CMD_SUCCESS;
1314 }
1315
1316 DEFUN (no_bgp_maxmed_onstartup,
1317 no_bgp_maxmed_onstartup_cmd,
1318 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1319 NO_STR
1320 BGP_STR
1321 "Advertise routes with max-med\n"
1322 "Effective on a startup\n"
1323 "Time (seconds) period for max-med\n"
1324 "Max MED value to be used\n")
1325 {
1326 VTY_DECLVAR_CONTEXT(bgp, bgp);
1327
1328 /* Cancel max-med onstartup if its on */
1329 if (bgp->t_maxmed_onstartup) {
1330 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1331 bgp->maxmed_onstartup_over = 1;
1332 }
1333
1334 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1335 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1336
1337 bgp_maxmed_update(bgp);
1338
1339 return CMD_SUCCESS;
1340 }
1341
1342 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1343 const char *wait)
1344 {
1345 VTY_DECLVAR_CONTEXT(bgp, bgp);
1346 uint16_t update_delay;
1347 uint16_t establish_wait;
1348
1349 update_delay = strtoul(delay, NULL, 10);
1350
1351 if (!wait) /* update-delay <delay> */
1352 {
1353 bgp->v_update_delay = update_delay;
1354 bgp->v_establish_wait = bgp->v_update_delay;
1355 return CMD_SUCCESS;
1356 }
1357
1358 /* update-delay <delay> <establish-wait> */
1359 establish_wait = atoi(wait);
1360 if (update_delay < establish_wait) {
1361 vty_out(vty,
1362 "%%Failed: update-delay less than the establish-wait!\n");
1363 return CMD_WARNING_CONFIG_FAILED;
1364 }
1365
1366 bgp->v_update_delay = update_delay;
1367 bgp->v_establish_wait = establish_wait;
1368
1369 return CMD_SUCCESS;
1370 }
1371
1372 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1373 {
1374 VTY_DECLVAR_CONTEXT(bgp, bgp);
1375
1376 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1377 bgp->v_establish_wait = bgp->v_update_delay;
1378
1379 return CMD_SUCCESS;
1380 }
1381
1382 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1383 {
1384 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1385 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1386 if (bgp->v_update_delay != bgp->v_establish_wait)
1387 vty_out(vty, " %d", bgp->v_establish_wait);
1388 vty_out(vty, "\n");
1389 }
1390 }
1391
1392
1393 /* Update-delay configuration */
1394 DEFUN (bgp_update_delay,
1395 bgp_update_delay_cmd,
1396 "update-delay (0-3600)",
1397 "Force initial delay for best-path and updates\n"
1398 "Seconds\n")
1399 {
1400 int idx_number = 1;
1401 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1402 }
1403
1404 DEFUN (bgp_update_delay_establish_wait,
1405 bgp_update_delay_establish_wait_cmd,
1406 "update-delay (0-3600) (1-3600)",
1407 "Force initial delay for best-path and updates\n"
1408 "Seconds\n"
1409 "Seconds\n")
1410 {
1411 int idx_number = 1;
1412 int idx_number_2 = 2;
1413 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1414 argv[idx_number_2]->arg);
1415 }
1416
1417 /* Update-delay deconfiguration */
1418 DEFUN (no_bgp_update_delay,
1419 no_bgp_update_delay_cmd,
1420 "no update-delay [(0-3600) [(1-3600)]]",
1421 NO_STR
1422 "Force initial delay for best-path and updates\n"
1423 "Seconds\n"
1424 "Seconds\n")
1425 {
1426 return bgp_update_delay_deconfig_vty(vty);
1427 }
1428
1429
1430 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1431 char set)
1432 {
1433 VTY_DECLVAR_CONTEXT(bgp, bgp);
1434
1435 if (set) {
1436 uint32_t quanta = strtoul(num, NULL, 10);
1437 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1438 memory_order_relaxed);
1439 } else {
1440 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1441 memory_order_relaxed);
1442 }
1443
1444 return CMD_SUCCESS;
1445 }
1446
1447 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1448 char set)
1449 {
1450 VTY_DECLVAR_CONTEXT(bgp, bgp);
1451
1452 if (set) {
1453 uint32_t quanta = strtoul(num, NULL, 10);
1454 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1455 memory_order_relaxed);
1456 } else {
1457 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1458 memory_order_relaxed);
1459 }
1460
1461 return CMD_SUCCESS;
1462 }
1463
1464 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1465 {
1466 uint32_t quanta =
1467 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1468 if (quanta != BGP_WRITE_PACKET_MAX)
1469 vty_out(vty, " write-quanta %d\n", quanta);
1470 }
1471
1472 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1473 {
1474 uint32_t quanta =
1475 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1476 if (quanta != BGP_READ_PACKET_MAX)
1477 vty_out(vty, " read-quanta %d\n", quanta);
1478 }
1479
1480 /* Packet quanta configuration */
1481 DEFUN (bgp_wpkt_quanta,
1482 bgp_wpkt_quanta_cmd,
1483 "write-quanta (1-10)",
1484 "How many packets to write to peer socket per run\n"
1485 "Number of packets\n")
1486 {
1487 int idx_number = 1;
1488 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1489 }
1490
1491 DEFUN (no_bgp_wpkt_quanta,
1492 no_bgp_wpkt_quanta_cmd,
1493 "no write-quanta (1-10)",
1494 NO_STR
1495 "How many packets to write to peer socket per I/O cycle\n"
1496 "Number of packets\n")
1497 {
1498 int idx_number = 2;
1499 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1500 }
1501
1502 DEFUN (bgp_rpkt_quanta,
1503 bgp_rpkt_quanta_cmd,
1504 "read-quanta (1-10)",
1505 "How many packets to read from peer socket per I/O cycle\n"
1506 "Number of packets\n")
1507 {
1508 int idx_number = 1;
1509 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1510 }
1511
1512 DEFUN (no_bgp_rpkt_quanta,
1513 no_bgp_rpkt_quanta_cmd,
1514 "no read-quanta (1-10)",
1515 NO_STR
1516 "How many packets to read from peer socket per I/O cycle\n"
1517 "Number of packets\n")
1518 {
1519 int idx_number = 2;
1520 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1521 }
1522
1523 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1524 {
1525 if (!bgp->heuristic_coalesce)
1526 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1527 }
1528
1529
1530 DEFUN (bgp_coalesce_time,
1531 bgp_coalesce_time_cmd,
1532 "coalesce-time (0-4294967295)",
1533 "Subgroup coalesce timer\n"
1534 "Subgroup coalesce timer value (in ms)\n")
1535 {
1536 VTY_DECLVAR_CONTEXT(bgp, bgp);
1537
1538 int idx = 0;
1539 argv_find(argv, argc, "(0-4294967295)", &idx);
1540 bgp->heuristic_coalesce = false;
1541 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1542 return CMD_SUCCESS;
1543 }
1544
1545 DEFUN (no_bgp_coalesce_time,
1546 no_bgp_coalesce_time_cmd,
1547 "no coalesce-time (0-4294967295)",
1548 NO_STR
1549 "Subgroup coalesce timer\n"
1550 "Subgroup coalesce timer value (in ms)\n")
1551 {
1552 VTY_DECLVAR_CONTEXT(bgp, bgp);
1553
1554 bgp->heuristic_coalesce = true;
1555 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1556 return CMD_SUCCESS;
1557 }
1558
1559 /* Maximum-paths configuration */
1560 DEFUN (bgp_maxpaths,
1561 bgp_maxpaths_cmd,
1562 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1563 "Forward packets over multiple paths\n"
1564 "Number of paths\n")
1565 {
1566 int idx_number = 1;
1567 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1568 argv[idx_number]->arg, 0, 1);
1569 }
1570
1571 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1572 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1573 "Forward packets over multiple paths\n"
1574 "Number of paths\n")
1575
1576 DEFUN (bgp_maxpaths_ibgp,
1577 bgp_maxpaths_ibgp_cmd,
1578 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1579 "Forward packets over multiple paths\n"
1580 "iBGP-multipath\n"
1581 "Number of paths\n")
1582 {
1583 int idx_number = 2;
1584 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1585 argv[idx_number]->arg, 0, 1);
1586 }
1587
1588 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1589 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1590 "Forward packets over multiple paths\n"
1591 "iBGP-multipath\n"
1592 "Number of paths\n")
1593
1594 DEFUN (bgp_maxpaths_ibgp_cluster,
1595 bgp_maxpaths_ibgp_cluster_cmd,
1596 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1597 "Forward packets over multiple paths\n"
1598 "iBGP-multipath\n"
1599 "Number of paths\n"
1600 "Match the cluster length\n")
1601 {
1602 int idx_number = 2;
1603 return bgp_maxpaths_config_vty(
1604 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1605 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1606 }
1607
1608 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1609 "maximum-paths ibgp " CMD_RANGE_STR(
1610 1, MULTIPATH_NUM) " equal-cluster-length",
1611 "Forward packets over multiple paths\n"
1612 "iBGP-multipath\n"
1613 "Number of paths\n"
1614 "Match the cluster length\n")
1615
1616 DEFUN (no_bgp_maxpaths,
1617 no_bgp_maxpaths_cmd,
1618 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1619 NO_STR
1620 "Forward packets over multiple paths\n"
1621 "Number of paths\n")
1622 {
1623 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1624 }
1625
1626 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1627 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1628 "Forward packets over multiple paths\n"
1629 "Number of paths\n")
1630
1631 DEFUN (no_bgp_maxpaths_ibgp,
1632 no_bgp_maxpaths_ibgp_cmd,
1633 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1634 NO_STR
1635 "Forward packets over multiple paths\n"
1636 "iBGP-multipath\n"
1637 "Number of paths\n"
1638 "Match the cluster length\n")
1639 {
1640 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1641 }
1642
1643 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1644 "no maximum-paths ibgp [" CMD_RANGE_STR(
1645 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1646 NO_STR
1647 "Forward packets over multiple paths\n"
1648 "iBGP-multipath\n"
1649 "Number of paths\n"
1650 "Match the cluster length\n")
1651
1652 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1653 safi_t safi)
1654 {
1655 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1656 vty_out(vty, " maximum-paths %d\n",
1657 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1658 }
1659
1660 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1661 vty_out(vty, " maximum-paths ibgp %d",
1662 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1663 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1664 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1665 vty_out(vty, " equal-cluster-length");
1666 vty_out(vty, "\n");
1667 }
1668 }
1669
1670 /* BGP timers. */
1671
1672 DEFUN (bgp_timers,
1673 bgp_timers_cmd,
1674 "timers bgp (0-65535) (0-65535)",
1675 "Adjust routing timers\n"
1676 "BGP timers\n"
1677 "Keepalive interval\n"
1678 "Holdtime\n")
1679 {
1680 VTY_DECLVAR_CONTEXT(bgp, bgp);
1681 int idx_number = 2;
1682 int idx_number_2 = 3;
1683 unsigned long keepalive = 0;
1684 unsigned long holdtime = 0;
1685
1686 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1687 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1688
1689 /* Holdtime value check. */
1690 if (holdtime < 3 && holdtime != 0) {
1691 vty_out(vty,
1692 "%% hold time value must be either 0 or greater than 3\n");
1693 return CMD_WARNING_CONFIG_FAILED;
1694 }
1695
1696 bgp_timers_set(bgp, keepalive, holdtime);
1697
1698 return CMD_SUCCESS;
1699 }
1700
1701 DEFUN (no_bgp_timers,
1702 no_bgp_timers_cmd,
1703 "no timers bgp [(0-65535) (0-65535)]",
1704 NO_STR
1705 "Adjust routing timers\n"
1706 "BGP timers\n"
1707 "Keepalive interval\n"
1708 "Holdtime\n")
1709 {
1710 VTY_DECLVAR_CONTEXT(bgp, bgp);
1711 bgp_timers_unset(bgp);
1712
1713 return CMD_SUCCESS;
1714 }
1715
1716
1717 DEFUN (bgp_client_to_client_reflection,
1718 bgp_client_to_client_reflection_cmd,
1719 "bgp client-to-client reflection",
1720 "BGP specific commands\n"
1721 "Configure client to client route reflection\n"
1722 "reflection of routes allowed\n")
1723 {
1724 VTY_DECLVAR_CONTEXT(bgp, bgp);
1725 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1726 bgp_clear_star_soft_out(vty, bgp->name);
1727
1728 return CMD_SUCCESS;
1729 }
1730
1731 DEFUN (no_bgp_client_to_client_reflection,
1732 no_bgp_client_to_client_reflection_cmd,
1733 "no bgp client-to-client reflection",
1734 NO_STR
1735 "BGP specific commands\n"
1736 "Configure client to client route reflection\n"
1737 "reflection of routes allowed\n")
1738 {
1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1741 bgp_clear_star_soft_out(vty, bgp->name);
1742
1743 return CMD_SUCCESS;
1744 }
1745
1746 /* "bgp always-compare-med" configuration. */
1747 DEFUN (bgp_always_compare_med,
1748 bgp_always_compare_med_cmd,
1749 "bgp always-compare-med",
1750 "BGP specific commands\n"
1751 "Allow comparing MED from different neighbors\n")
1752 {
1753 VTY_DECLVAR_CONTEXT(bgp, bgp);
1754 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1755 bgp_recalculate_all_bestpaths(bgp);
1756
1757 return CMD_SUCCESS;
1758 }
1759
1760 DEFUN (no_bgp_always_compare_med,
1761 no_bgp_always_compare_med_cmd,
1762 "no bgp always-compare-med",
1763 NO_STR
1764 "BGP specific commands\n"
1765 "Allow comparing MED from different neighbors\n")
1766 {
1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1769 bgp_recalculate_all_bestpaths(bgp);
1770
1771 return CMD_SUCCESS;
1772 }
1773
1774 /* "bgp deterministic-med" configuration. */
1775 DEFUN (bgp_deterministic_med,
1776 bgp_deterministic_med_cmd,
1777 "bgp deterministic-med",
1778 "BGP specific commands\n"
1779 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1780 {
1781 VTY_DECLVAR_CONTEXT(bgp, bgp);
1782
1783 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1784 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1785 bgp_recalculate_all_bestpaths(bgp);
1786 }
1787
1788 return CMD_SUCCESS;
1789 }
1790
1791 DEFUN (no_bgp_deterministic_med,
1792 no_bgp_deterministic_med_cmd,
1793 "no bgp deterministic-med",
1794 NO_STR
1795 "BGP specific commands\n"
1796 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1797 {
1798 VTY_DECLVAR_CONTEXT(bgp, bgp);
1799 int bestpath_per_as_used;
1800 afi_t afi;
1801 safi_t safi;
1802 struct peer *peer;
1803 struct listnode *node, *nnode;
1804
1805 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1806 bestpath_per_as_used = 0;
1807
1808 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1809 FOREACH_AFI_SAFI (afi, safi)
1810 if (CHECK_FLAG(
1811 peer->af_flags[afi][safi],
1812 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1813 bestpath_per_as_used = 1;
1814 break;
1815 }
1816
1817 if (bestpath_per_as_used)
1818 break;
1819 }
1820
1821 if (bestpath_per_as_used) {
1822 vty_out(vty,
1823 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1824 return CMD_WARNING_CONFIG_FAILED;
1825 } else {
1826 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1827 bgp_recalculate_all_bestpaths(bgp);
1828 }
1829 }
1830
1831 return CMD_SUCCESS;
1832 }
1833
1834 /* "bgp graceful-restart" configuration. */
1835 DEFUN (bgp_graceful_restart,
1836 bgp_graceful_restart_cmd,
1837 "bgp graceful-restart",
1838 "BGP specific commands\n"
1839 "Graceful restart capability parameters\n")
1840 {
1841 VTY_DECLVAR_CONTEXT(bgp, bgp);
1842 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1843 return CMD_SUCCESS;
1844 }
1845
1846 DEFUN (no_bgp_graceful_restart,
1847 no_bgp_graceful_restart_cmd,
1848 "no bgp graceful-restart",
1849 NO_STR
1850 "BGP specific commands\n"
1851 "Graceful restart capability parameters\n")
1852 {
1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
1854 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1855 return CMD_SUCCESS;
1856 }
1857
1858 DEFUN (bgp_graceful_restart_stalepath_time,
1859 bgp_graceful_restart_stalepath_time_cmd,
1860 "bgp graceful-restart stalepath-time (1-3600)",
1861 "BGP specific commands\n"
1862 "Graceful restart capability parameters\n"
1863 "Set the max time to hold onto restarting peer's stale paths\n"
1864 "Delay value (seconds)\n")
1865 {
1866 VTY_DECLVAR_CONTEXT(bgp, bgp);
1867 int idx_number = 3;
1868 uint32_t stalepath;
1869
1870 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1871 bgp->stalepath_time = stalepath;
1872 return CMD_SUCCESS;
1873 }
1874
1875 DEFUN (bgp_graceful_restart_restart_time,
1876 bgp_graceful_restart_restart_time_cmd,
1877 "bgp graceful-restart restart-time (1-3600)",
1878 "BGP specific commands\n"
1879 "Graceful restart capability parameters\n"
1880 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1881 "Delay value (seconds)\n")
1882 {
1883 VTY_DECLVAR_CONTEXT(bgp, bgp);
1884 int idx_number = 3;
1885 uint32_t restart;
1886
1887 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1888 bgp->restart_time = restart;
1889 return CMD_SUCCESS;
1890 }
1891
1892 DEFUN (no_bgp_graceful_restart_stalepath_time,
1893 no_bgp_graceful_restart_stalepath_time_cmd,
1894 "no bgp graceful-restart stalepath-time [(1-3600)]",
1895 NO_STR
1896 "BGP specific commands\n"
1897 "Graceful restart capability parameters\n"
1898 "Set the max time to hold onto restarting peer's stale paths\n"
1899 "Delay value (seconds)\n")
1900 {
1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902
1903 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (no_bgp_graceful_restart_restart_time,
1908 no_bgp_graceful_restart_restart_time_cmd,
1909 "no bgp graceful-restart restart-time [(1-3600)]",
1910 NO_STR
1911 "BGP specific commands\n"
1912 "Graceful restart capability parameters\n"
1913 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1914 "Delay value (seconds)\n")
1915 {
1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917
1918 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1919 return CMD_SUCCESS;
1920 }
1921
1922 DEFUN (bgp_graceful_restart_preserve_fw,
1923 bgp_graceful_restart_preserve_fw_cmd,
1924 "bgp graceful-restart preserve-fw-state",
1925 "BGP specific commands\n"
1926 "Graceful restart capability parameters\n"
1927 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1928 {
1929 VTY_DECLVAR_CONTEXT(bgp, bgp);
1930 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1931 return CMD_SUCCESS;
1932 }
1933
1934 DEFUN (no_bgp_graceful_restart_preserve_fw,
1935 no_bgp_graceful_restart_preserve_fw_cmd,
1936 "no bgp graceful-restart preserve-fw-state",
1937 NO_STR
1938 "BGP specific commands\n"
1939 "Graceful restart capability parameters\n"
1940 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1941 {
1942 VTY_DECLVAR_CONTEXT(bgp, bgp);
1943 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1944 return CMD_SUCCESS;
1945 }
1946
1947 static void bgp_redistribute_redo(struct bgp *bgp)
1948 {
1949 afi_t afi;
1950 int i;
1951 struct list *red_list;
1952 struct listnode *node;
1953 struct bgp_redist *red;
1954
1955 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1956 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1957
1958 red_list = bgp->redist[afi][i];
1959 if (!red_list)
1960 continue;
1961
1962 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1963 bgp_redistribute_resend(bgp, afi, i,
1964 red->instance);
1965 }
1966 }
1967 }
1968 }
1969
1970 /* "bgp graceful-shutdown" configuration */
1971 DEFUN (bgp_graceful_shutdown,
1972 bgp_graceful_shutdown_cmd,
1973 "bgp graceful-shutdown",
1974 BGP_STR
1975 "Graceful shutdown parameters\n")
1976 {
1977 VTY_DECLVAR_CONTEXT(bgp, bgp);
1978
1979 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1980 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1981 bgp_static_redo_import_check(bgp);
1982 bgp_redistribute_redo(bgp);
1983 bgp_clear_star_soft_out(vty, bgp->name);
1984 bgp_clear_star_soft_in(vty, bgp->name);
1985 }
1986
1987 return CMD_SUCCESS;
1988 }
1989
1990 DEFUN (no_bgp_graceful_shutdown,
1991 no_bgp_graceful_shutdown_cmd,
1992 "no bgp graceful-shutdown",
1993 NO_STR
1994 BGP_STR
1995 "Graceful shutdown parameters\n")
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998
1999 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2000 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2001 bgp_static_redo_import_check(bgp);
2002 bgp_redistribute_redo(bgp);
2003 bgp_clear_star_soft_out(vty, bgp->name);
2004 bgp_clear_star_soft_in(vty, bgp->name);
2005 }
2006
2007 return CMD_SUCCESS;
2008 }
2009
2010 /* "bgp fast-external-failover" configuration. */
2011 DEFUN (bgp_fast_external_failover,
2012 bgp_fast_external_failover_cmd,
2013 "bgp fast-external-failover",
2014 BGP_STR
2015 "Immediately reset session if a link to a directly connected external peer goes down\n")
2016 {
2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2019 return CMD_SUCCESS;
2020 }
2021
2022 DEFUN (no_bgp_fast_external_failover,
2023 no_bgp_fast_external_failover_cmd,
2024 "no bgp fast-external-failover",
2025 NO_STR
2026 BGP_STR
2027 "Immediately reset session if a link to a directly connected external peer goes down\n")
2028 {
2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2031 return CMD_SUCCESS;
2032 }
2033
2034 /* "bgp enforce-first-as" configuration. */
2035 #if CONFDATE > 20190517
2036 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2037 #endif
2038
2039 DEFUN_HIDDEN (bgp_enforce_first_as,
2040 bgp_enforce_first_as_cmd,
2041 "[no] bgp enforce-first-as",
2042 NO_STR
2043 BGP_STR
2044 "Enforce the first AS for EBGP routes\n")
2045 {
2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
2047
2048 if (strmatch(argv[0]->text, "no"))
2049 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2050 else
2051 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2052
2053 return CMD_SUCCESS;
2054 }
2055
2056 /* "bgp bestpath compare-routerid" configuration. */
2057 DEFUN (bgp_bestpath_compare_router_id,
2058 bgp_bestpath_compare_router_id_cmd,
2059 "bgp bestpath compare-routerid",
2060 "BGP specific commands\n"
2061 "Change the default bestpath selection\n"
2062 "Compare router-id for identical EBGP paths\n")
2063 {
2064 VTY_DECLVAR_CONTEXT(bgp, bgp);
2065 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2066 bgp_recalculate_all_bestpaths(bgp);
2067
2068 return CMD_SUCCESS;
2069 }
2070
2071 DEFUN (no_bgp_bestpath_compare_router_id,
2072 no_bgp_bestpath_compare_router_id_cmd,
2073 "no bgp bestpath compare-routerid",
2074 NO_STR
2075 "BGP specific commands\n"
2076 "Change the default bestpath selection\n"
2077 "Compare router-id for identical EBGP paths\n")
2078 {
2079 VTY_DECLVAR_CONTEXT(bgp, bgp);
2080 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2081 bgp_recalculate_all_bestpaths(bgp);
2082
2083 return CMD_SUCCESS;
2084 }
2085
2086 /* "bgp bestpath as-path ignore" configuration. */
2087 DEFUN (bgp_bestpath_aspath_ignore,
2088 bgp_bestpath_aspath_ignore_cmd,
2089 "bgp bestpath as-path ignore",
2090 "BGP specific commands\n"
2091 "Change the default bestpath selection\n"
2092 "AS-path attribute\n"
2093 "Ignore as-path length in selecting a route\n")
2094 {
2095 VTY_DECLVAR_CONTEXT(bgp, bgp);
2096 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2097 bgp_recalculate_all_bestpaths(bgp);
2098
2099 return CMD_SUCCESS;
2100 }
2101
2102 DEFUN (no_bgp_bestpath_aspath_ignore,
2103 no_bgp_bestpath_aspath_ignore_cmd,
2104 "no bgp bestpath as-path ignore",
2105 NO_STR
2106 "BGP specific commands\n"
2107 "Change the default bestpath selection\n"
2108 "AS-path attribute\n"
2109 "Ignore as-path length in selecting a route\n")
2110 {
2111 VTY_DECLVAR_CONTEXT(bgp, bgp);
2112 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2113 bgp_recalculate_all_bestpaths(bgp);
2114
2115 return CMD_SUCCESS;
2116 }
2117
2118 /* "bgp bestpath as-path confed" configuration. */
2119 DEFUN (bgp_bestpath_aspath_confed,
2120 bgp_bestpath_aspath_confed_cmd,
2121 "bgp bestpath as-path confed",
2122 "BGP specific commands\n"
2123 "Change the default bestpath selection\n"
2124 "AS-path attribute\n"
2125 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2126 {
2127 VTY_DECLVAR_CONTEXT(bgp, bgp);
2128 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2129 bgp_recalculate_all_bestpaths(bgp);
2130
2131 return CMD_SUCCESS;
2132 }
2133
2134 DEFUN (no_bgp_bestpath_aspath_confed,
2135 no_bgp_bestpath_aspath_confed_cmd,
2136 "no bgp bestpath as-path confed",
2137 NO_STR
2138 "BGP specific commands\n"
2139 "Change the default bestpath selection\n"
2140 "AS-path attribute\n"
2141 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2142 {
2143 VTY_DECLVAR_CONTEXT(bgp, bgp);
2144 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2145 bgp_recalculate_all_bestpaths(bgp);
2146
2147 return CMD_SUCCESS;
2148 }
2149
2150 /* "bgp bestpath as-path multipath-relax" configuration. */
2151 DEFUN (bgp_bestpath_aspath_multipath_relax,
2152 bgp_bestpath_aspath_multipath_relax_cmd,
2153 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2154 "BGP specific commands\n"
2155 "Change the default bestpath selection\n"
2156 "AS-path attribute\n"
2157 "Allow load sharing across routes that have different AS paths (but same length)\n"
2158 "Generate an AS_SET\n"
2159 "Do not generate an AS_SET\n")
2160 {
2161 VTY_DECLVAR_CONTEXT(bgp, bgp);
2162 int idx = 0;
2163 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2164
2165 /* no-as-set is now the default behavior so we can silently
2166 * ignore it */
2167 if (argv_find(argv, argc, "as-set", &idx))
2168 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2169 else
2170 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2171
2172 bgp_recalculate_all_bestpaths(bgp);
2173
2174 return CMD_SUCCESS;
2175 }
2176
2177 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2178 no_bgp_bestpath_aspath_multipath_relax_cmd,
2179 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2180 NO_STR
2181 "BGP specific commands\n"
2182 "Change the default bestpath selection\n"
2183 "AS-path attribute\n"
2184 "Allow load sharing across routes that have different AS paths (but same length)\n"
2185 "Generate an AS_SET\n"
2186 "Do not generate an AS_SET\n")
2187 {
2188 VTY_DECLVAR_CONTEXT(bgp, bgp);
2189 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2190 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2191 bgp_recalculate_all_bestpaths(bgp);
2192
2193 return CMD_SUCCESS;
2194 }
2195
2196 /* "bgp log-neighbor-changes" configuration. */
2197 DEFUN (bgp_log_neighbor_changes,
2198 bgp_log_neighbor_changes_cmd,
2199 "bgp log-neighbor-changes",
2200 "BGP specific commands\n"
2201 "Log neighbor up/down and reset reason\n")
2202 {
2203 VTY_DECLVAR_CONTEXT(bgp, bgp);
2204 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2205 return CMD_SUCCESS;
2206 }
2207
2208 DEFUN (no_bgp_log_neighbor_changes,
2209 no_bgp_log_neighbor_changes_cmd,
2210 "no bgp log-neighbor-changes",
2211 NO_STR
2212 "BGP specific commands\n"
2213 "Log neighbor up/down and reset reason\n")
2214 {
2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2217 return CMD_SUCCESS;
2218 }
2219
2220 /* "bgp bestpath med" configuration. */
2221 DEFUN (bgp_bestpath_med,
2222 bgp_bestpath_med_cmd,
2223 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2224 "BGP specific commands\n"
2225 "Change the default bestpath selection\n"
2226 "MED attribute\n"
2227 "Compare MED among confederation paths\n"
2228 "Treat missing MED as the least preferred one\n"
2229 "Treat missing MED as the least preferred one\n"
2230 "Compare MED among confederation paths\n")
2231 {
2232 VTY_DECLVAR_CONTEXT(bgp, bgp);
2233
2234 int idx = 0;
2235 if (argv_find(argv, argc, "confed", &idx))
2236 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2237 idx = 0;
2238 if (argv_find(argv, argc, "missing-as-worst", &idx))
2239 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2240
2241 bgp_recalculate_all_bestpaths(bgp);
2242
2243 return CMD_SUCCESS;
2244 }
2245
2246 DEFUN (no_bgp_bestpath_med,
2247 no_bgp_bestpath_med_cmd,
2248 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2249 NO_STR
2250 "BGP specific commands\n"
2251 "Change the default bestpath selection\n"
2252 "MED attribute\n"
2253 "Compare MED among confederation paths\n"
2254 "Treat missing MED as the least preferred one\n"
2255 "Treat missing MED as the least preferred one\n"
2256 "Compare MED among confederation paths\n")
2257 {
2258 VTY_DECLVAR_CONTEXT(bgp, bgp);
2259
2260 int idx = 0;
2261 if (argv_find(argv, argc, "confed", &idx))
2262 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2263 idx = 0;
2264 if (argv_find(argv, argc, "missing-as-worst", &idx))
2265 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2266
2267 bgp_recalculate_all_bestpaths(bgp);
2268
2269 return CMD_SUCCESS;
2270 }
2271
2272 /* "no bgp default ipv4-unicast". */
2273 DEFUN (no_bgp_default_ipv4_unicast,
2274 no_bgp_default_ipv4_unicast_cmd,
2275 "no bgp default ipv4-unicast",
2276 NO_STR
2277 "BGP specific commands\n"
2278 "Configure BGP defaults\n"
2279 "Activate ipv4-unicast for a peer by default\n")
2280 {
2281 VTY_DECLVAR_CONTEXT(bgp, bgp);
2282 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2283 return CMD_SUCCESS;
2284 }
2285
2286 DEFUN (bgp_default_ipv4_unicast,
2287 bgp_default_ipv4_unicast_cmd,
2288 "bgp default ipv4-unicast",
2289 "BGP specific commands\n"
2290 "Configure BGP defaults\n"
2291 "Activate ipv4-unicast for a peer by default\n")
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2295 return CMD_SUCCESS;
2296 }
2297
2298 /* Display hostname in certain command outputs */
2299 DEFUN (bgp_default_show_hostname,
2300 bgp_default_show_hostname_cmd,
2301 "bgp default show-hostname",
2302 "BGP specific commands\n"
2303 "Configure BGP defaults\n"
2304 "Show hostname in certain command outputs\n")
2305 {
2306 VTY_DECLVAR_CONTEXT(bgp, bgp);
2307 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2308 return CMD_SUCCESS;
2309 }
2310
2311 DEFUN (no_bgp_default_show_hostname,
2312 no_bgp_default_show_hostname_cmd,
2313 "no bgp default show-hostname",
2314 NO_STR
2315 "BGP specific commands\n"
2316 "Configure BGP defaults\n"
2317 "Show hostname in certain command outputs\n")
2318 {
2319 VTY_DECLVAR_CONTEXT(bgp, bgp);
2320 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2321 return CMD_SUCCESS;
2322 }
2323
2324 /* "bgp network import-check" configuration. */
2325 DEFUN (bgp_network_import_check,
2326 bgp_network_import_check_cmd,
2327 "bgp network import-check",
2328 "BGP specific commands\n"
2329 "BGP network command\n"
2330 "Check BGP network route exists in IGP\n")
2331 {
2332 VTY_DECLVAR_CONTEXT(bgp, bgp);
2333 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2334 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2335 bgp_static_redo_import_check(bgp);
2336 }
2337
2338 return CMD_SUCCESS;
2339 }
2340
2341 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2342 "bgp network import-check exact",
2343 "BGP specific commands\n"
2344 "BGP network command\n"
2345 "Check BGP network route exists in IGP\n"
2346 "Match route precisely\n")
2347
2348 DEFUN (no_bgp_network_import_check,
2349 no_bgp_network_import_check_cmd,
2350 "no bgp network import-check",
2351 NO_STR
2352 "BGP specific commands\n"
2353 "BGP network command\n"
2354 "Check BGP network route exists in IGP\n")
2355 {
2356 VTY_DECLVAR_CONTEXT(bgp, bgp);
2357 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2358 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2359 bgp_static_redo_import_check(bgp);
2360 }
2361
2362 return CMD_SUCCESS;
2363 }
2364
2365 DEFUN (bgp_default_local_preference,
2366 bgp_default_local_preference_cmd,
2367 "bgp default local-preference (0-4294967295)",
2368 "BGP specific commands\n"
2369 "Configure BGP defaults\n"
2370 "local preference (higher=more preferred)\n"
2371 "Configure default local preference value\n")
2372 {
2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
2374 int idx_number = 3;
2375 uint32_t local_pref;
2376
2377 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2378
2379 bgp_default_local_preference_set(bgp, local_pref);
2380 bgp_clear_star_soft_in(vty, bgp->name);
2381
2382 return CMD_SUCCESS;
2383 }
2384
2385 DEFUN (no_bgp_default_local_preference,
2386 no_bgp_default_local_preference_cmd,
2387 "no bgp default local-preference [(0-4294967295)]",
2388 NO_STR
2389 "BGP specific commands\n"
2390 "Configure BGP defaults\n"
2391 "local preference (higher=more preferred)\n"
2392 "Configure default local preference value\n")
2393 {
2394 VTY_DECLVAR_CONTEXT(bgp, bgp);
2395 bgp_default_local_preference_unset(bgp);
2396 bgp_clear_star_soft_in(vty, bgp->name);
2397
2398 return CMD_SUCCESS;
2399 }
2400
2401
2402 DEFUN (bgp_default_subgroup_pkt_queue_max,
2403 bgp_default_subgroup_pkt_queue_max_cmd,
2404 "bgp default subgroup-pkt-queue-max (20-100)",
2405 "BGP specific commands\n"
2406 "Configure BGP defaults\n"
2407 "subgroup-pkt-queue-max\n"
2408 "Configure subgroup packet queue max\n")
2409 {
2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 int idx_number = 3;
2412 uint32_t max_size;
2413
2414 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2415
2416 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2417
2418 return CMD_SUCCESS;
2419 }
2420
2421 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2422 no_bgp_default_subgroup_pkt_queue_max_cmd,
2423 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2424 NO_STR
2425 "BGP specific commands\n"
2426 "Configure BGP defaults\n"
2427 "subgroup-pkt-queue-max\n"
2428 "Configure subgroup packet queue max\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2432 return CMD_SUCCESS;
2433 }
2434
2435
2436 DEFUN (bgp_rr_allow_outbound_policy,
2437 bgp_rr_allow_outbound_policy_cmd,
2438 "bgp route-reflector allow-outbound-policy",
2439 "BGP specific commands\n"
2440 "Allow modifications made by out route-map\n"
2441 "on ibgp neighbors\n")
2442 {
2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444
2445 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2446 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2447 update_group_announce_rrclients(bgp);
2448 bgp_clear_star_soft_out(vty, bgp->name);
2449 }
2450
2451 return CMD_SUCCESS;
2452 }
2453
2454 DEFUN (no_bgp_rr_allow_outbound_policy,
2455 no_bgp_rr_allow_outbound_policy_cmd,
2456 "no bgp route-reflector allow-outbound-policy",
2457 NO_STR
2458 "BGP specific commands\n"
2459 "Allow modifications made by out route-map\n"
2460 "on ibgp neighbors\n")
2461 {
2462 VTY_DECLVAR_CONTEXT(bgp, bgp);
2463
2464 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2465 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2466 update_group_announce_rrclients(bgp);
2467 bgp_clear_star_soft_out(vty, bgp->name);
2468 }
2469
2470 return CMD_SUCCESS;
2471 }
2472
2473 DEFUN (bgp_listen_limit,
2474 bgp_listen_limit_cmd,
2475 "bgp listen limit (1-5000)",
2476 "BGP specific commands\n"
2477 "Configure BGP defaults\n"
2478 "maximum number of BGP Dynamic Neighbors that can be created\n"
2479 "Configure Dynamic Neighbors listen limit value\n")
2480 {
2481 VTY_DECLVAR_CONTEXT(bgp, bgp);
2482 int idx_number = 3;
2483 int listen_limit;
2484
2485 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2486
2487 bgp_listen_limit_set(bgp, listen_limit);
2488
2489 return CMD_SUCCESS;
2490 }
2491
2492 DEFUN (no_bgp_listen_limit,
2493 no_bgp_listen_limit_cmd,
2494 "no bgp listen limit [(1-5000)]",
2495 "BGP specific commands\n"
2496 "Configure BGP defaults\n"
2497 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2498 "Configure Dynamic Neighbors listen limit value to default\n"
2499 "Configure Dynamic Neighbors listen limit value\n")
2500 {
2501 VTY_DECLVAR_CONTEXT(bgp, bgp);
2502 bgp_listen_limit_unset(bgp);
2503 return CMD_SUCCESS;
2504 }
2505
2506
2507 /*
2508 * Check if this listen range is already configured. Check for exact
2509 * match or overlap based on input.
2510 */
2511 static struct peer_group *listen_range_exists(struct bgp *bgp,
2512 struct prefix *range, int exact)
2513 {
2514 struct listnode *node, *nnode;
2515 struct listnode *node1, *nnode1;
2516 struct peer_group *group;
2517 struct prefix *lr;
2518 afi_t afi;
2519 int match;
2520
2521 afi = family2afi(range->family);
2522 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2523 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2524 lr)) {
2525 if (exact)
2526 match = prefix_same(range, lr);
2527 else
2528 match = (prefix_match(range, lr)
2529 || prefix_match(lr, range));
2530 if (match)
2531 return group;
2532 }
2533 }
2534
2535 return NULL;
2536 }
2537
2538 DEFUN (bgp_listen_range,
2539 bgp_listen_range_cmd,
2540 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2541 "BGP specific commands\n"
2542 "Configure BGP dynamic neighbors listen range\n"
2543 "Configure BGP dynamic neighbors listen range\n"
2544 NEIGHBOR_ADDR_STR
2545 "Member of the peer-group\n"
2546 "Peer-group name\n")
2547 {
2548 VTY_DECLVAR_CONTEXT(bgp, bgp);
2549 struct prefix range;
2550 struct peer_group *group, *existing_group;
2551 afi_t afi;
2552 int ret;
2553 int idx = 0;
2554
2555 argv_find(argv, argc, "A.B.C.D/M", &idx);
2556 argv_find(argv, argc, "X:X::X:X/M", &idx);
2557 char *prefix = argv[idx]->arg;
2558 argv_find(argv, argc, "WORD", &idx);
2559 char *peergroup = argv[idx]->arg;
2560
2561 /* Convert IP prefix string to struct prefix. */
2562 ret = str2prefix(prefix, &range);
2563 if (!ret) {
2564 vty_out(vty, "%% Malformed listen range\n");
2565 return CMD_WARNING_CONFIG_FAILED;
2566 }
2567
2568 afi = family2afi(range.family);
2569
2570 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2571 vty_out(vty,
2572 "%% Malformed listen range (link-local address)\n");
2573 return CMD_WARNING_CONFIG_FAILED;
2574 }
2575
2576 apply_mask(&range);
2577
2578 /* Check if same listen range is already configured. */
2579 existing_group = listen_range_exists(bgp, &range, 1);
2580 if (existing_group) {
2581 if (strcmp(existing_group->name, peergroup) == 0)
2582 return CMD_SUCCESS;
2583 else {
2584 vty_out(vty,
2585 "%% Same listen range is attached to peer-group %s\n",
2586 existing_group->name);
2587 return CMD_WARNING_CONFIG_FAILED;
2588 }
2589 }
2590
2591 /* Check if an overlapping listen range exists. */
2592 if (listen_range_exists(bgp, &range, 0)) {
2593 vty_out(vty,
2594 "%% Listen range overlaps with existing listen range\n");
2595 return CMD_WARNING_CONFIG_FAILED;
2596 }
2597
2598 group = peer_group_lookup(bgp, peergroup);
2599 if (!group) {
2600 vty_out(vty, "%% Configure the peer-group first\n");
2601 return CMD_WARNING_CONFIG_FAILED;
2602 }
2603
2604 ret = peer_group_listen_range_add(group, &range);
2605 return bgp_vty_return(vty, ret);
2606 }
2607
2608 DEFUN (no_bgp_listen_range,
2609 no_bgp_listen_range_cmd,
2610 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2611 NO_STR
2612 "BGP specific commands\n"
2613 "Unconfigure BGP dynamic neighbors listen range\n"
2614 "Unconfigure BGP dynamic neighbors listen range\n"
2615 NEIGHBOR_ADDR_STR
2616 "Member of the peer-group\n"
2617 "Peer-group name\n")
2618 {
2619 VTY_DECLVAR_CONTEXT(bgp, bgp);
2620 struct prefix range;
2621 struct peer_group *group;
2622 afi_t afi;
2623 int ret;
2624 int idx = 0;
2625
2626 argv_find(argv, argc, "A.B.C.D/M", &idx);
2627 argv_find(argv, argc, "X:X::X:X/M", &idx);
2628 char *prefix = argv[idx]->arg;
2629 argv_find(argv, argc, "WORD", &idx);
2630 char *peergroup = argv[idx]->arg;
2631
2632 /* Convert IP prefix string to struct prefix. */
2633 ret = str2prefix(prefix, &range);
2634 if (!ret) {
2635 vty_out(vty, "%% Malformed listen range\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 afi = family2afi(range.family);
2640
2641 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2642 vty_out(vty,
2643 "%% Malformed listen range (link-local address)\n");
2644 return CMD_WARNING_CONFIG_FAILED;
2645 }
2646
2647 apply_mask(&range);
2648
2649 group = peer_group_lookup(bgp, peergroup);
2650 if (!group) {
2651 vty_out(vty, "%% Peer-group does not exist\n");
2652 return CMD_WARNING_CONFIG_FAILED;
2653 }
2654
2655 ret = peer_group_listen_range_del(group, &range);
2656 return bgp_vty_return(vty, ret);
2657 }
2658
2659 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2660 {
2661 struct peer_group *group;
2662 struct listnode *node, *nnode, *rnode, *nrnode;
2663 struct prefix *range;
2664 afi_t afi;
2665 char buf[PREFIX2STR_BUFFER];
2666
2667 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2668 vty_out(vty, " bgp listen limit %d\n",
2669 bgp->dynamic_neighbors_limit);
2670
2671 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2672 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2673 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2674 nrnode, range)) {
2675 prefix2str(range, buf, sizeof(buf));
2676 vty_out(vty,
2677 " bgp listen range %s peer-group %s\n",
2678 buf, group->name);
2679 }
2680 }
2681 }
2682 }
2683
2684
2685 DEFUN (bgp_disable_connected_route_check,
2686 bgp_disable_connected_route_check_cmd,
2687 "bgp disable-ebgp-connected-route-check",
2688 "BGP specific commands\n"
2689 "Disable checking if nexthop is connected on ebgp sessions\n")
2690 {
2691 VTY_DECLVAR_CONTEXT(bgp, bgp);
2692 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2693 bgp_clear_star_soft_in(vty, bgp->name);
2694
2695 return CMD_SUCCESS;
2696 }
2697
2698 DEFUN (no_bgp_disable_connected_route_check,
2699 no_bgp_disable_connected_route_check_cmd,
2700 "no bgp disable-ebgp-connected-route-check",
2701 NO_STR
2702 "BGP specific commands\n"
2703 "Disable checking if nexthop is connected on ebgp sessions\n")
2704 {
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2707 bgp_clear_star_soft_in(vty, bgp->name);
2708
2709 return CMD_SUCCESS;
2710 }
2711
2712
2713 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2714 const char *as_str, afi_t afi, safi_t safi)
2715 {
2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
2717 int ret;
2718 as_t as;
2719 int as_type = AS_SPECIFIED;
2720 union sockunion su;
2721
2722 if (as_str[0] == 'i') {
2723 as = 0;
2724 as_type = AS_INTERNAL;
2725 } else if (as_str[0] == 'e') {
2726 as = 0;
2727 as_type = AS_EXTERNAL;
2728 } else {
2729 /* Get AS number. */
2730 as = strtoul(as_str, NULL, 10);
2731 }
2732
2733 /* If peer is peer group, call proper function. */
2734 ret = str2sockunion(peer_str, &su);
2735 if (ret < 0) {
2736 /* Check for peer by interface */
2737 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2738 safi);
2739 if (ret < 0) {
2740 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2741 if (ret < 0) {
2742 vty_out(vty,
2743 "%% Create the peer-group or interface first or specify \"interface\" keyword\n");
2744 vty_out(vty, "%% if using an unnumbered interface neighbor\n");
2745 return CMD_WARNING_CONFIG_FAILED;
2746 }
2747 return CMD_SUCCESS;
2748 }
2749 } else {
2750 if (peer_address_self_check(bgp, &su)) {
2751 vty_out(vty,
2752 "%% Can not configure the local system as neighbor\n");
2753 return CMD_WARNING_CONFIG_FAILED;
2754 }
2755 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2756 }
2757
2758 /* This peer belongs to peer group. */
2759 switch (ret) {
2760 case BGP_ERR_PEER_GROUP_MEMBER:
2761 vty_out(vty,
2762 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2763 as);
2764 return CMD_WARNING_CONFIG_FAILED;
2765 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2766 vty_out(vty,
2767 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2768 as, as_str);
2769 return CMD_WARNING_CONFIG_FAILED;
2770 }
2771 return bgp_vty_return(vty, ret);
2772 }
2773
2774 DEFUN (bgp_default_shutdown,
2775 bgp_default_shutdown_cmd,
2776 "[no] bgp default shutdown",
2777 NO_STR
2778 BGP_STR
2779 "Configure BGP defaults\n"
2780 "Apply administrative shutdown to newly configured peers\n")
2781 {
2782 VTY_DECLVAR_CONTEXT(bgp, bgp);
2783 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2784 return CMD_SUCCESS;
2785 }
2786
2787 DEFUN (neighbor_remote_as,
2788 neighbor_remote_as_cmd,
2789 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2790 NEIGHBOR_STR
2791 NEIGHBOR_ADDR_STR2
2792 "Specify a BGP neighbor\n"
2793 AS_STR
2794 "Internal BGP peer\n"
2795 "External BGP peer\n")
2796 {
2797 int idx_peer = 1;
2798 int idx_remote_as = 3;
2799 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2800 argv[idx_remote_as]->arg, AFI_IP,
2801 SAFI_UNICAST);
2802 }
2803
2804 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2805 afi_t afi, safi_t safi, int v6only,
2806 const char *peer_group_name,
2807 const char *as_str)
2808 {
2809 VTY_DECLVAR_CONTEXT(bgp, bgp);
2810 as_t as = 0;
2811 int as_type = AS_UNSPECIFIED;
2812 struct peer *peer;
2813 struct peer_group *group;
2814 int ret = 0;
2815 union sockunion su;
2816
2817 group = peer_group_lookup(bgp, conf_if);
2818
2819 if (group) {
2820 vty_out(vty, "%% Name conflict with peer-group \n");
2821 return CMD_WARNING_CONFIG_FAILED;
2822 }
2823
2824 if (as_str) {
2825 if (as_str[0] == 'i') {
2826 as_type = AS_INTERNAL;
2827 } else if (as_str[0] == 'e') {
2828 as_type = AS_EXTERNAL;
2829 } else {
2830 /* Get AS number. */
2831 as = strtoul(as_str, NULL, 10);
2832 as_type = AS_SPECIFIED;
2833 }
2834 }
2835
2836 peer = peer_lookup_by_conf_if(bgp, conf_if);
2837 if (peer) {
2838 if (as_str)
2839 ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
2840 afi, safi);
2841 } else {
2842 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2843 && afi == AFI_IP && safi == SAFI_UNICAST)
2844 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2845 as_type, 0, 0, NULL);
2846 else
2847 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2848 as_type, afi, safi, NULL);
2849
2850 if (!peer) {
2851 vty_out(vty, "%% BGP failed to create peer\n");
2852 return CMD_WARNING_CONFIG_FAILED;
2853 }
2854
2855 if (v6only)
2856 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2857
2858 /* Request zebra to initiate IPv6 RAs on this interface. We do
2859 * this
2860 * any unnumbered peer in order to not worry about run-time
2861 * transitions
2862 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2863 * address
2864 * gets deleted later etc.)
2865 */
2866 if (peer->ifp)
2867 bgp_zebra_initiate_radv(bgp, peer);
2868 }
2869
2870 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2871 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2872 if (v6only)
2873 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2874 else
2875 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2876
2877 /* v6only flag changed. Reset bgp seesion */
2878 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2879 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2880 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2881 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2882 } else
2883 bgp_session_reset(peer);
2884 }
2885
2886 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2887 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2888 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2889 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2890 }
2891
2892 if (peer_group_name) {
2893 group = peer_group_lookup(bgp, peer_group_name);
2894 if (!group) {
2895 vty_out(vty, "%% Configure the peer-group first\n");
2896 return CMD_WARNING_CONFIG_FAILED;
2897 }
2898
2899 ret = peer_group_bind(bgp, &su, peer, group, &as);
2900 }
2901
2902 return bgp_vty_return(vty, ret);
2903 }
2904
2905 DEFUN (neighbor_interface_config,
2906 neighbor_interface_config_cmd,
2907 "neighbor WORD interface [peer-group WORD]",
2908 NEIGHBOR_STR
2909 "Interface name or neighbor tag\n"
2910 "Enable BGP on interface\n"
2911 "Member of the peer-group\n"
2912 "Peer-group name\n")
2913 {
2914 int idx_word = 1;
2915 int idx_peer_group_word = 4;
2916
2917 if (argc > idx_peer_group_word)
2918 return peer_conf_interface_get(
2919 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2920 argv[idx_peer_group_word]->arg, NULL);
2921 else
2922 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2923 SAFI_UNICAST, 0, NULL, NULL);
2924 }
2925
2926 DEFUN (neighbor_interface_config_v6only,
2927 neighbor_interface_config_v6only_cmd,
2928 "neighbor WORD interface v6only [peer-group WORD]",
2929 NEIGHBOR_STR
2930 "Interface name or neighbor tag\n"
2931 "Enable BGP on interface\n"
2932 "Enable BGP with v6 link-local only\n"
2933 "Member of the peer-group\n"
2934 "Peer-group name\n")
2935 {
2936 int idx_word = 1;
2937 int idx_peer_group_word = 5;
2938
2939 if (argc > idx_peer_group_word)
2940 return peer_conf_interface_get(
2941 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2942 argv[idx_peer_group_word]->arg, NULL);
2943
2944 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2945 SAFI_UNICAST, 1, NULL, NULL);
2946 }
2947
2948
2949 DEFUN (neighbor_interface_config_remote_as,
2950 neighbor_interface_config_remote_as_cmd,
2951 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2952 NEIGHBOR_STR
2953 "Interface name or neighbor tag\n"
2954 "Enable BGP on interface\n"
2955 "Specify a BGP neighbor\n"
2956 AS_STR
2957 "Internal BGP peer\n"
2958 "External BGP peer\n")
2959 {
2960 int idx_word = 1;
2961 int idx_remote_as = 4;
2962 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2963 SAFI_UNICAST, 0, NULL,
2964 argv[idx_remote_as]->arg);
2965 }
2966
2967 DEFUN (neighbor_interface_v6only_config_remote_as,
2968 neighbor_interface_v6only_config_remote_as_cmd,
2969 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2970 NEIGHBOR_STR
2971 "Interface name or neighbor tag\n"
2972 "Enable BGP with v6 link-local only\n"
2973 "Enable BGP on interface\n"
2974 "Specify a BGP neighbor\n"
2975 AS_STR
2976 "Internal BGP peer\n"
2977 "External BGP peer\n")
2978 {
2979 int idx_word = 1;
2980 int idx_remote_as = 5;
2981 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2982 SAFI_UNICAST, 1, NULL,
2983 argv[idx_remote_as]->arg);
2984 }
2985
2986 DEFUN (neighbor_peer_group,
2987 neighbor_peer_group_cmd,
2988 "neighbor WORD peer-group",
2989 NEIGHBOR_STR
2990 "Interface name or neighbor tag\n"
2991 "Configure peer-group\n")
2992 {
2993 VTY_DECLVAR_CONTEXT(bgp, bgp);
2994 int idx_word = 1;
2995 struct peer *peer;
2996 struct peer_group *group;
2997
2998 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2999 if (peer) {
3000 vty_out(vty, "%% Name conflict with interface: \n");
3001 return CMD_WARNING_CONFIG_FAILED;
3002 }
3003
3004 group = peer_group_get(bgp, argv[idx_word]->arg);
3005 if (!group) {
3006 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3007 return CMD_WARNING_CONFIG_FAILED;
3008 }
3009
3010 return CMD_SUCCESS;
3011 }
3012
3013 DEFUN (no_neighbor,
3014 no_neighbor_cmd,
3015 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3016 NO_STR
3017 NEIGHBOR_STR
3018 NEIGHBOR_ADDR_STR2
3019 "Specify a BGP neighbor\n"
3020 AS_STR
3021 "Internal BGP peer\n"
3022 "External BGP peer\n")
3023 {
3024 VTY_DECLVAR_CONTEXT(bgp, bgp);
3025 int idx_peer = 2;
3026 int ret;
3027 union sockunion su;
3028 struct peer_group *group;
3029 struct peer *peer;
3030 struct peer *other;
3031
3032 ret = str2sockunion(argv[idx_peer]->arg, &su);
3033 if (ret < 0) {
3034 /* look up for neighbor by interface name config. */
3035 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3036 if (peer) {
3037 /* Request zebra to terminate IPv6 RAs on this
3038 * interface. */
3039 if (peer->ifp)
3040 bgp_zebra_terminate_radv(peer->bgp, peer);
3041 peer_delete(peer);
3042 return CMD_SUCCESS;
3043 }
3044
3045 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3046 if (group)
3047 peer_group_delete(group);
3048 else {
3049 vty_out(vty, "%% Create the peer-group first\n");
3050 return CMD_WARNING_CONFIG_FAILED;
3051 }
3052 } else {
3053 peer = peer_lookup(bgp, &su);
3054 if (peer) {
3055 if (peer_dynamic_neighbor(peer)) {
3056 vty_out(vty,
3057 "%% Operation not allowed on a dynamic neighbor\n");
3058 return CMD_WARNING_CONFIG_FAILED;
3059 }
3060
3061 other = peer->doppelganger;
3062 peer_delete(peer);
3063 if (other && other->status != Deleted)
3064 peer_delete(other);
3065 }
3066 }
3067
3068 return CMD_SUCCESS;
3069 }
3070
3071 DEFUN (no_neighbor_interface_config,
3072 no_neighbor_interface_config_cmd,
3073 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3074 NO_STR
3075 NEIGHBOR_STR
3076 "Interface name\n"
3077 "Configure BGP on interface\n"
3078 "Enable BGP with v6 link-local only\n"
3079 "Member of the peer-group\n"
3080 "Peer-group name\n"
3081 "Specify a BGP neighbor\n"
3082 AS_STR
3083 "Internal BGP peer\n"
3084 "External BGP peer\n")
3085 {
3086 VTY_DECLVAR_CONTEXT(bgp, bgp);
3087 int idx_word = 2;
3088 struct peer *peer;
3089
3090 /* look up for neighbor by interface name config. */
3091 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3092 if (peer) {
3093 /* Request zebra to terminate IPv6 RAs on this interface. */
3094 if (peer->ifp)
3095 bgp_zebra_terminate_radv(peer->bgp, peer);
3096 peer_delete(peer);
3097 } else {
3098 vty_out(vty, "%% Create the bgp interface first\n");
3099 return CMD_WARNING_CONFIG_FAILED;
3100 }
3101 return CMD_SUCCESS;
3102 }
3103
3104 DEFUN (no_neighbor_peer_group,
3105 no_neighbor_peer_group_cmd,
3106 "no neighbor WORD peer-group",
3107 NO_STR
3108 NEIGHBOR_STR
3109 "Neighbor tag\n"
3110 "Configure peer-group\n")
3111 {
3112 VTY_DECLVAR_CONTEXT(bgp, bgp);
3113 int idx_word = 2;
3114 struct peer_group *group;
3115
3116 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3117 if (group)
3118 peer_group_delete(group);
3119 else {
3120 vty_out(vty, "%% Create the peer-group first\n");
3121 return CMD_WARNING_CONFIG_FAILED;
3122 }
3123 return CMD_SUCCESS;
3124 }
3125
3126 DEFUN (no_neighbor_interface_peer_group_remote_as,
3127 no_neighbor_interface_peer_group_remote_as_cmd,
3128 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3129 NO_STR
3130 NEIGHBOR_STR
3131 "Interface name or neighbor tag\n"
3132 "Specify a BGP neighbor\n"
3133 AS_STR
3134 "Internal BGP peer\n"
3135 "External BGP peer\n")
3136 {
3137 VTY_DECLVAR_CONTEXT(bgp, bgp);
3138 int idx_word = 2;
3139 struct peer_group *group;
3140 struct peer *peer;
3141
3142 /* look up for neighbor by interface name config. */
3143 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3144 if (peer) {
3145 peer_as_change(peer, 0, AS_SPECIFIED);
3146 return CMD_SUCCESS;
3147 }
3148
3149 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3150 if (group)
3151 peer_group_remote_as_delete(group);
3152 else {
3153 vty_out(vty, "%% Create the peer-group or interface first\n");
3154 return CMD_WARNING_CONFIG_FAILED;
3155 }
3156 return CMD_SUCCESS;
3157 }
3158
3159 DEFUN (neighbor_local_as,
3160 neighbor_local_as_cmd,
3161 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3162 NEIGHBOR_STR
3163 NEIGHBOR_ADDR_STR2
3164 "Specify a local-as number\n"
3165 "AS number used as local AS\n")
3166 {
3167 int idx_peer = 1;
3168 int idx_number = 3;
3169 struct peer *peer;
3170 int ret;
3171 as_t as;
3172
3173 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3174 if (!peer)
3175 return CMD_WARNING_CONFIG_FAILED;
3176
3177 as = strtoul(argv[idx_number]->arg, NULL, 10);
3178 ret = peer_local_as_set(peer, as, 0, 0);
3179 return bgp_vty_return(vty, ret);
3180 }
3181
3182 DEFUN (neighbor_local_as_no_prepend,
3183 neighbor_local_as_no_prepend_cmd,
3184 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3185 NEIGHBOR_STR
3186 NEIGHBOR_ADDR_STR2
3187 "Specify a local-as number\n"
3188 "AS number used as local AS\n"
3189 "Do not prepend local-as to updates from ebgp peers\n")
3190 {
3191 int idx_peer = 1;
3192 int idx_number = 3;
3193 struct peer *peer;
3194 int ret;
3195 as_t as;
3196
3197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3198 if (!peer)
3199 return CMD_WARNING_CONFIG_FAILED;
3200
3201 as = strtoul(argv[idx_number]->arg, NULL, 10);
3202 ret = peer_local_as_set(peer, as, 1, 0);
3203 return bgp_vty_return(vty, ret);
3204 }
3205
3206 DEFUN (neighbor_local_as_no_prepend_replace_as,
3207 neighbor_local_as_no_prepend_replace_as_cmd,
3208 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3209 NEIGHBOR_STR
3210 NEIGHBOR_ADDR_STR2
3211 "Specify a local-as number\n"
3212 "AS number used as local AS\n"
3213 "Do not prepend local-as to updates from ebgp peers\n"
3214 "Do not prepend local-as to updates from ibgp peers\n")
3215 {
3216 int idx_peer = 1;
3217 int idx_number = 3;
3218 struct peer *peer;
3219 int ret;
3220 as_t as;
3221
3222 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3223 if (!peer)
3224 return CMD_WARNING_CONFIG_FAILED;
3225
3226 as = strtoul(argv[idx_number]->arg, NULL, 10);
3227 ret = peer_local_as_set(peer, as, 1, 1);
3228 return bgp_vty_return(vty, ret);
3229 }
3230
3231 DEFUN (no_neighbor_local_as,
3232 no_neighbor_local_as_cmd,
3233 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3234 NO_STR
3235 NEIGHBOR_STR
3236 NEIGHBOR_ADDR_STR2
3237 "Specify a local-as number\n"
3238 "AS number used as local AS\n"
3239 "Do not prepend local-as to updates from ebgp peers\n"
3240 "Do not prepend local-as to updates from ibgp peers\n")
3241 {
3242 int idx_peer = 2;
3243 struct peer *peer;
3244 int ret;
3245
3246 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3247 if (!peer)
3248 return CMD_WARNING_CONFIG_FAILED;
3249
3250 ret = peer_local_as_unset(peer);
3251 return bgp_vty_return(vty, ret);
3252 }
3253
3254
3255 DEFUN (neighbor_solo,
3256 neighbor_solo_cmd,
3257 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3258 NEIGHBOR_STR
3259 NEIGHBOR_ADDR_STR2
3260 "Solo peer - part of its own update group\n")
3261 {
3262 int idx_peer = 1;
3263 struct peer *peer;
3264 int ret;
3265
3266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3267 if (!peer)
3268 return CMD_WARNING_CONFIG_FAILED;
3269
3270 ret = update_group_adjust_soloness(peer, 1);
3271 return bgp_vty_return(vty, ret);
3272 }
3273
3274 DEFUN (no_neighbor_solo,
3275 no_neighbor_solo_cmd,
3276 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3277 NO_STR
3278 NEIGHBOR_STR
3279 NEIGHBOR_ADDR_STR2
3280 "Solo peer - part of its own update group\n")
3281 {
3282 int idx_peer = 2;
3283 struct peer *peer;
3284 int ret;
3285
3286 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3287 if (!peer)
3288 return CMD_WARNING_CONFIG_FAILED;
3289
3290 ret = update_group_adjust_soloness(peer, 0);
3291 return bgp_vty_return(vty, ret);
3292 }
3293
3294 DEFUN (neighbor_password,
3295 neighbor_password_cmd,
3296 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3297 NEIGHBOR_STR
3298 NEIGHBOR_ADDR_STR2
3299 "Set a password\n"
3300 "The password\n")
3301 {
3302 int idx_peer = 1;
3303 int idx_line = 3;
3304 struct peer *peer;
3305 int ret;
3306
3307 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3308 if (!peer)
3309 return CMD_WARNING_CONFIG_FAILED;
3310
3311 ret = peer_password_set(peer, argv[idx_line]->arg);
3312 return bgp_vty_return(vty, ret);
3313 }
3314
3315 DEFUN (no_neighbor_password,
3316 no_neighbor_password_cmd,
3317 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3318 NO_STR
3319 NEIGHBOR_STR
3320 NEIGHBOR_ADDR_STR2
3321 "Set a password\n"
3322 "The password\n")
3323 {
3324 int idx_peer = 2;
3325 struct peer *peer;
3326 int ret;
3327
3328 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3329 if (!peer)
3330 return CMD_WARNING_CONFIG_FAILED;
3331
3332 ret = peer_password_unset(peer);
3333 return bgp_vty_return(vty, ret);
3334 }
3335
3336 DEFUN (neighbor_activate,
3337 neighbor_activate_cmd,
3338 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3339 NEIGHBOR_STR
3340 NEIGHBOR_ADDR_STR2
3341 "Enable the Address Family for this Neighbor\n")
3342 {
3343 int idx_peer = 1;
3344 int ret;
3345 struct peer *peer;
3346
3347 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3348 if (!peer)
3349 return CMD_WARNING_CONFIG_FAILED;
3350
3351 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3352 return bgp_vty_return(vty, ret);
3353 }
3354
3355 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3356 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3357 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3358 "Enable the Address Family for this Neighbor\n")
3359
3360 DEFUN (no_neighbor_activate,
3361 no_neighbor_activate_cmd,
3362 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3363 NO_STR
3364 NEIGHBOR_STR
3365 NEIGHBOR_ADDR_STR2
3366 "Enable the Address Family for this Neighbor\n")
3367 {
3368 int idx_peer = 2;
3369 int ret;
3370 struct peer *peer;
3371
3372 /* Lookup peer. */
3373 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3374 if (!peer)
3375 return CMD_WARNING_CONFIG_FAILED;
3376
3377 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3378 return bgp_vty_return(vty, ret);
3379 }
3380
3381 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3382 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3383 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3384 "Enable the Address Family for this Neighbor\n")
3385
3386 DEFUN (neighbor_set_peer_group,
3387 neighbor_set_peer_group_cmd,
3388 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3389 NEIGHBOR_STR
3390 NEIGHBOR_ADDR_STR2
3391 "Member of the peer-group\n"
3392 "Peer-group name\n")
3393 {
3394 VTY_DECLVAR_CONTEXT(bgp, bgp);
3395 int idx_peer = 1;
3396 int idx_word = 3;
3397 int ret;
3398 as_t as;
3399 union sockunion su;
3400 struct peer *peer;
3401 struct peer_group *group;
3402
3403 ret = str2sockunion(argv[idx_peer]->arg, &su);
3404 if (ret < 0) {
3405 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3406 if (!peer) {
3407 vty_out(vty, "%% Malformed address or name: %s\n",
3408 argv[idx_peer]->arg);
3409 return CMD_WARNING_CONFIG_FAILED;
3410 }
3411 } else {
3412 if (peer_address_self_check(bgp, &su)) {
3413 vty_out(vty,
3414 "%% Can not configure the local system as neighbor\n");
3415 return CMD_WARNING_CONFIG_FAILED;
3416 }
3417
3418 /* Disallow for dynamic neighbor. */
3419 peer = peer_lookup(bgp, &su);
3420 if (peer && peer_dynamic_neighbor(peer)) {
3421 vty_out(vty,
3422 "%% Operation not allowed on a dynamic neighbor\n");
3423 return CMD_WARNING_CONFIG_FAILED;
3424 }
3425 }
3426
3427 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3428 if (!group) {
3429 vty_out(vty, "%% Configure the peer-group first\n");
3430 return CMD_WARNING_CONFIG_FAILED;
3431 }
3432
3433 ret = peer_group_bind(bgp, &su, peer, group, &as);
3434
3435 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3436 vty_out(vty,
3437 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3438 as);
3439 return CMD_WARNING_CONFIG_FAILED;
3440 }
3441
3442 return bgp_vty_return(vty, ret);
3443 }
3444
3445 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3446 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3447 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3448 "Member of the peer-group\n"
3449 "Peer-group name\n")
3450
3451 DEFUN (no_neighbor_set_peer_group,
3452 no_neighbor_set_peer_group_cmd,
3453 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3454 NO_STR
3455 NEIGHBOR_STR
3456 NEIGHBOR_ADDR_STR2
3457 "Member of the peer-group\n"
3458 "Peer-group name\n")
3459 {
3460 VTY_DECLVAR_CONTEXT(bgp, bgp);
3461 int idx_peer = 2;
3462 int idx_word = 4;
3463 int ret;
3464 struct peer *peer;
3465 struct peer_group *group;
3466
3467 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3468 if (!peer)
3469 return CMD_WARNING_CONFIG_FAILED;
3470
3471 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3472 if (!group) {
3473 vty_out(vty, "%% Configure the peer-group first\n");
3474 return CMD_WARNING_CONFIG_FAILED;
3475 }
3476
3477 ret = peer_delete(peer);
3478
3479 return bgp_vty_return(vty, ret);
3480 }
3481
3482 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3483 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3484 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3485 "Member of the peer-group\n"
3486 "Peer-group name\n")
3487
3488 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3489 uint32_t flag, int set)
3490 {
3491 int ret;
3492 struct peer *peer;
3493
3494 peer = peer_and_group_lookup_vty(vty, ip_str);
3495 if (!peer)
3496 return CMD_WARNING_CONFIG_FAILED;
3497
3498 /*
3499 * If 'neighbor <interface>', then this is for directly connected peers,
3500 * we should not accept disable-connected-check.
3501 */
3502 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3503 vty_out(vty,
3504 "%s is directly connected peer, cannot accept disable-"
3505 "connected-check\n",
3506 ip_str);
3507 return CMD_WARNING_CONFIG_FAILED;
3508 }
3509
3510 if (!set && flag == PEER_FLAG_SHUTDOWN)
3511 peer_tx_shutdown_message_unset(peer);
3512
3513 if (set)
3514 ret = peer_flag_set(peer, flag);
3515 else
3516 ret = peer_flag_unset(peer, flag);
3517
3518 return bgp_vty_return(vty, ret);
3519 }
3520
3521 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3522 {
3523 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3524 }
3525
3526 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3527 uint32_t flag)
3528 {
3529 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3530 }
3531
3532 /* neighbor passive. */
3533 DEFUN (neighbor_passive,
3534 neighbor_passive_cmd,
3535 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3536 NEIGHBOR_STR
3537 NEIGHBOR_ADDR_STR2
3538 "Don't send open messages to this neighbor\n")
3539 {
3540 int idx_peer = 1;
3541 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3542 }
3543
3544 DEFUN (no_neighbor_passive,
3545 no_neighbor_passive_cmd,
3546 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3547 NO_STR
3548 NEIGHBOR_STR
3549 NEIGHBOR_ADDR_STR2
3550 "Don't send open messages to this neighbor\n")
3551 {
3552 int idx_peer = 2;
3553 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3554 }
3555
3556 /* neighbor shutdown. */
3557 DEFUN (neighbor_shutdown_msg,
3558 neighbor_shutdown_msg_cmd,
3559 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3560 NEIGHBOR_STR
3561 NEIGHBOR_ADDR_STR2
3562 "Administratively shut down this neighbor\n"
3563 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3564 "Shutdown message\n")
3565 {
3566 int idx_peer = 1;
3567
3568 if (argc >= 5) {
3569 struct peer *peer =
3570 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3571 char *message;
3572
3573 if (!peer)
3574 return CMD_WARNING_CONFIG_FAILED;
3575 message = argv_concat(argv, argc, 4);
3576 peer_tx_shutdown_message_set(peer, message);
3577 XFREE(MTYPE_TMP, message);
3578 }
3579
3580 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3581 }
3582
3583 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3584 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3585 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3586 "Administratively shut down this neighbor\n")
3587
3588 DEFUN (no_neighbor_shutdown_msg,
3589 no_neighbor_shutdown_msg_cmd,
3590 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3591 NO_STR
3592 NEIGHBOR_STR
3593 NEIGHBOR_ADDR_STR2
3594 "Administratively shut down this neighbor\n"
3595 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3596 "Shutdown message\n")
3597 {
3598 int idx_peer = 2;
3599
3600 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3601 PEER_FLAG_SHUTDOWN);
3602 }
3603
3604 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3605 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3606 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3607 "Administratively shut down this neighbor\n")
3608
3609 /* neighbor capability dynamic. */
3610 DEFUN (neighbor_capability_dynamic,
3611 neighbor_capability_dynamic_cmd,
3612 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3613 NEIGHBOR_STR
3614 NEIGHBOR_ADDR_STR2
3615 "Advertise capability to the peer\n"
3616 "Advertise dynamic capability to this neighbor\n")
3617 {
3618 int idx_peer = 1;
3619 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3620 PEER_FLAG_DYNAMIC_CAPABILITY);
3621 }
3622
3623 DEFUN (no_neighbor_capability_dynamic,
3624 no_neighbor_capability_dynamic_cmd,
3625 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3626 NO_STR
3627 NEIGHBOR_STR
3628 NEIGHBOR_ADDR_STR2
3629 "Advertise capability to the peer\n"
3630 "Advertise dynamic capability to this neighbor\n")
3631 {
3632 int idx_peer = 2;
3633 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3634 PEER_FLAG_DYNAMIC_CAPABILITY);
3635 }
3636
3637 /* neighbor dont-capability-negotiate */
3638 DEFUN (neighbor_dont_capability_negotiate,
3639 neighbor_dont_capability_negotiate_cmd,
3640 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3641 NEIGHBOR_STR
3642 NEIGHBOR_ADDR_STR2
3643 "Do not perform capability negotiation\n")
3644 {
3645 int idx_peer = 1;
3646 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3647 PEER_FLAG_DONT_CAPABILITY);
3648 }
3649
3650 DEFUN (no_neighbor_dont_capability_negotiate,
3651 no_neighbor_dont_capability_negotiate_cmd,
3652 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3653 NO_STR
3654 NEIGHBOR_STR
3655 NEIGHBOR_ADDR_STR2
3656 "Do not perform capability negotiation\n")
3657 {
3658 int idx_peer = 2;
3659 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3660 PEER_FLAG_DONT_CAPABILITY);
3661 }
3662
3663 /* neighbor capability extended next hop encoding */
3664 DEFUN (neighbor_capability_enhe,
3665 neighbor_capability_enhe_cmd,
3666 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3667 NEIGHBOR_STR
3668 NEIGHBOR_ADDR_STR2
3669 "Advertise capability to the peer\n"
3670 "Advertise extended next-hop capability to the peer\n")
3671 {
3672 int idx_peer = 1;
3673 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3674 PEER_FLAG_CAPABILITY_ENHE);
3675 }
3676
3677 DEFUN (no_neighbor_capability_enhe,
3678 no_neighbor_capability_enhe_cmd,
3679 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3680 NO_STR
3681 NEIGHBOR_STR
3682 NEIGHBOR_ADDR_STR2
3683 "Advertise capability to the peer\n"
3684 "Advertise extended next-hop capability to the peer\n")
3685 {
3686 int idx_peer = 2;
3687 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3688 PEER_FLAG_CAPABILITY_ENHE);
3689 }
3690
3691 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3692 afi_t afi, safi_t safi, uint32_t flag,
3693 int set)
3694 {
3695 int ret;
3696 struct peer *peer;
3697
3698 peer = peer_and_group_lookup_vty(vty, peer_str);
3699 if (!peer)
3700 return CMD_WARNING_CONFIG_FAILED;
3701
3702 if (set)
3703 ret = peer_af_flag_set(peer, afi, safi, flag);
3704 else
3705 ret = peer_af_flag_unset(peer, afi, safi, flag);
3706
3707 return bgp_vty_return(vty, ret);
3708 }
3709
3710 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3711 afi_t afi, safi_t safi, uint32_t flag)
3712 {
3713 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3714 }
3715
3716 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3717 afi_t afi, safi_t safi, uint32_t flag)
3718 {
3719 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3720 }
3721
3722 /* neighbor capability orf prefix-list. */
3723 DEFUN (neighbor_capability_orf_prefix,
3724 neighbor_capability_orf_prefix_cmd,
3725 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3726 NEIGHBOR_STR
3727 NEIGHBOR_ADDR_STR2
3728 "Advertise capability to the peer\n"
3729 "Advertise ORF capability to the peer\n"
3730 "Advertise prefixlist ORF capability to this neighbor\n"
3731 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3732 "Capability to RECEIVE the ORF from this neighbor\n"
3733 "Capability to SEND the ORF to this neighbor\n")
3734 {
3735 int idx_peer = 1;
3736 int idx_send_recv = 5;
3737 uint16_t flag = 0;
3738
3739 if (strmatch(argv[idx_send_recv]->text, "send"))
3740 flag = PEER_FLAG_ORF_PREFIX_SM;
3741 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3742 flag = PEER_FLAG_ORF_PREFIX_RM;
3743 else if (strmatch(argv[idx_send_recv]->text, "both"))
3744 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3745 else {
3746 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3747 return CMD_WARNING_CONFIG_FAILED;
3748 }
3749
3750 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3751 bgp_node_safi(vty), flag);
3752 }
3753
3754 ALIAS_HIDDEN(
3755 neighbor_capability_orf_prefix,
3756 neighbor_capability_orf_prefix_hidden_cmd,
3757 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3758 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3759 "Advertise capability to the peer\n"
3760 "Advertise ORF capability to the peer\n"
3761 "Advertise prefixlist ORF capability to this neighbor\n"
3762 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3763 "Capability to RECEIVE the ORF from this neighbor\n"
3764 "Capability to SEND the ORF to this neighbor\n")
3765
3766 DEFUN (no_neighbor_capability_orf_prefix,
3767 no_neighbor_capability_orf_prefix_cmd,
3768 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3769 NO_STR
3770 NEIGHBOR_STR
3771 NEIGHBOR_ADDR_STR2
3772 "Advertise capability to the peer\n"
3773 "Advertise ORF capability to the peer\n"
3774 "Advertise prefixlist ORF capability to this neighbor\n"
3775 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3776 "Capability to RECEIVE the ORF from this neighbor\n"
3777 "Capability to SEND the ORF to this neighbor\n")
3778 {
3779 int idx_peer = 2;
3780 int idx_send_recv = 6;
3781 uint16_t flag = 0;
3782
3783 if (strmatch(argv[idx_send_recv]->text, "send"))
3784 flag = PEER_FLAG_ORF_PREFIX_SM;
3785 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3786 flag = PEER_FLAG_ORF_PREFIX_RM;
3787 else if (strmatch(argv[idx_send_recv]->text, "both"))
3788 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3789 else {
3790 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3791 return CMD_WARNING_CONFIG_FAILED;
3792 }
3793
3794 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3795 bgp_node_afi(vty), bgp_node_safi(vty),
3796 flag);
3797 }
3798
3799 ALIAS_HIDDEN(
3800 no_neighbor_capability_orf_prefix,
3801 no_neighbor_capability_orf_prefix_hidden_cmd,
3802 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3803 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3804 "Advertise capability to the peer\n"
3805 "Advertise ORF capability to the peer\n"
3806 "Advertise prefixlist ORF capability to this neighbor\n"
3807 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3808 "Capability to RECEIVE the ORF from this neighbor\n"
3809 "Capability to SEND the ORF to this neighbor\n")
3810
3811 /* neighbor next-hop-self. */
3812 DEFUN (neighbor_nexthop_self,
3813 neighbor_nexthop_self_cmd,
3814 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3815 NEIGHBOR_STR
3816 NEIGHBOR_ADDR_STR2
3817 "Disable the next hop calculation for this neighbor\n")
3818 {
3819 int idx_peer = 1;
3820 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3821 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3822 }
3823
3824 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3825 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3827 "Disable the next hop calculation for this neighbor\n")
3828
3829 /* neighbor next-hop-self. */
3830 DEFUN (neighbor_nexthop_self_force,
3831 neighbor_nexthop_self_force_cmd,
3832 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3833 NEIGHBOR_STR
3834 NEIGHBOR_ADDR_STR2
3835 "Disable the next hop calculation for this neighbor\n"
3836 "Set the next hop to self for reflected routes\n")
3837 {
3838 int idx_peer = 1;
3839 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3840 bgp_node_safi(vty),
3841 PEER_FLAG_FORCE_NEXTHOP_SELF);
3842 }
3843
3844 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3845 neighbor_nexthop_self_force_hidden_cmd,
3846 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3847 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3848 "Disable the next hop calculation for this neighbor\n"
3849 "Set the next hop to self for reflected routes\n")
3850
3851 DEFUN (no_neighbor_nexthop_self,
3852 no_neighbor_nexthop_self_cmd,
3853 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3854 NO_STR
3855 NEIGHBOR_STR
3856 NEIGHBOR_ADDR_STR2
3857 "Disable the next hop calculation for this neighbor\n")
3858 {
3859 int idx_peer = 2;
3860 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3861 bgp_node_afi(vty), bgp_node_safi(vty),
3862 PEER_FLAG_NEXTHOP_SELF);
3863 }
3864
3865 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3866 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3867 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3868 "Disable the next hop calculation for this neighbor\n")
3869
3870 DEFUN (no_neighbor_nexthop_self_force,
3871 no_neighbor_nexthop_self_force_cmd,
3872 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3873 NO_STR
3874 NEIGHBOR_STR
3875 NEIGHBOR_ADDR_STR2
3876 "Disable the next hop calculation for this neighbor\n"
3877 "Set the next hop to self for reflected routes\n")
3878 {
3879 int idx_peer = 2;
3880 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3881 bgp_node_afi(vty), bgp_node_safi(vty),
3882 PEER_FLAG_FORCE_NEXTHOP_SELF);
3883 }
3884
3885 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3886 no_neighbor_nexthop_self_force_hidden_cmd,
3887 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3888 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3889 "Disable the next hop calculation for this neighbor\n"
3890 "Set the next hop to self for reflected routes\n")
3891
3892 /* neighbor as-override */
3893 DEFUN (neighbor_as_override,
3894 neighbor_as_override_cmd,
3895 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3896 NEIGHBOR_STR
3897 NEIGHBOR_ADDR_STR2
3898 "Override ASNs in outbound updates if aspath equals remote-as\n")
3899 {
3900 int idx_peer = 1;
3901 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3902 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3903 }
3904
3905 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3906 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3908 "Override ASNs in outbound updates if aspath equals remote-as\n")
3909
3910 DEFUN (no_neighbor_as_override,
3911 no_neighbor_as_override_cmd,
3912 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3913 NO_STR
3914 NEIGHBOR_STR
3915 NEIGHBOR_ADDR_STR2
3916 "Override ASNs in outbound updates if aspath equals remote-as\n")
3917 {
3918 int idx_peer = 2;
3919 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3920 bgp_node_afi(vty), bgp_node_safi(vty),
3921 PEER_FLAG_AS_OVERRIDE);
3922 }
3923
3924 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3925 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3926 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3927 "Override ASNs in outbound updates if aspath equals remote-as\n")
3928
3929 /* neighbor remove-private-AS. */
3930 DEFUN (neighbor_remove_private_as,
3931 neighbor_remove_private_as_cmd,
3932 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3933 NEIGHBOR_STR
3934 NEIGHBOR_ADDR_STR2
3935 "Remove private ASNs in outbound updates\n")
3936 {
3937 int idx_peer = 1;
3938 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3939 bgp_node_safi(vty),
3940 PEER_FLAG_REMOVE_PRIVATE_AS);
3941 }
3942
3943 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3944 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3945 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3946 "Remove private ASNs in outbound updates\n")
3947
3948 DEFUN (neighbor_remove_private_as_all,
3949 neighbor_remove_private_as_all_cmd,
3950 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3951 NEIGHBOR_STR
3952 NEIGHBOR_ADDR_STR2
3953 "Remove private ASNs in outbound updates\n"
3954 "Apply to all AS numbers\n")
3955 {
3956 int idx_peer = 1;
3957 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3958 bgp_node_safi(vty),
3959 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3960 }
3961
3962 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3963 neighbor_remove_private_as_all_hidden_cmd,
3964 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3966 "Remove private ASNs in outbound updates\n"
3967 "Apply to all AS numbers")
3968
3969 DEFUN (neighbor_remove_private_as_replace_as,
3970 neighbor_remove_private_as_replace_as_cmd,
3971 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3972 NEIGHBOR_STR
3973 NEIGHBOR_ADDR_STR2
3974 "Remove private ASNs in outbound updates\n"
3975 "Replace private ASNs with our ASN in outbound updates\n")
3976 {
3977 int idx_peer = 1;
3978 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3979 bgp_node_safi(vty),
3980 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3981 }
3982
3983 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3984 neighbor_remove_private_as_replace_as_hidden_cmd,
3985 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3986 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3987 "Remove private ASNs in outbound updates\n"
3988 "Replace private ASNs with our ASN in outbound updates\n")
3989
3990 DEFUN (neighbor_remove_private_as_all_replace_as,
3991 neighbor_remove_private_as_all_replace_as_cmd,
3992 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3993 NEIGHBOR_STR
3994 NEIGHBOR_ADDR_STR2
3995 "Remove private ASNs in outbound updates\n"
3996 "Apply to all AS numbers\n"
3997 "Replace private ASNs with our ASN in outbound updates\n")
3998 {
3999 int idx_peer = 1;
4000 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4001 bgp_node_safi(vty),
4002 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4003 }
4004
4005 ALIAS_HIDDEN(
4006 neighbor_remove_private_as_all_replace_as,
4007 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4008 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4009 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4010 "Remove private ASNs in outbound updates\n"
4011 "Apply to all AS numbers\n"
4012 "Replace private ASNs with our ASN in outbound updates\n")
4013
4014 DEFUN (no_neighbor_remove_private_as,
4015 no_neighbor_remove_private_as_cmd,
4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4017 NO_STR
4018 NEIGHBOR_STR
4019 NEIGHBOR_ADDR_STR2
4020 "Remove private ASNs in outbound updates\n")
4021 {
4022 int idx_peer = 2;
4023 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4024 bgp_node_afi(vty), bgp_node_safi(vty),
4025 PEER_FLAG_REMOVE_PRIVATE_AS);
4026 }
4027
4028 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4029 no_neighbor_remove_private_as_hidden_cmd,
4030 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4031 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4032 "Remove private ASNs in outbound updates\n")
4033
4034 DEFUN (no_neighbor_remove_private_as_all,
4035 no_neighbor_remove_private_as_all_cmd,
4036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4037 NO_STR
4038 NEIGHBOR_STR
4039 NEIGHBOR_ADDR_STR2
4040 "Remove private ASNs in outbound updates\n"
4041 "Apply to all AS numbers\n")
4042 {
4043 int idx_peer = 2;
4044 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4045 bgp_node_afi(vty), bgp_node_safi(vty),
4046 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4047 }
4048
4049 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4050 no_neighbor_remove_private_as_all_hidden_cmd,
4051 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4052 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4053 "Remove private ASNs in outbound updates\n"
4054 "Apply to all AS numbers\n")
4055
4056 DEFUN (no_neighbor_remove_private_as_replace_as,
4057 no_neighbor_remove_private_as_replace_as_cmd,
4058 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4059 NO_STR
4060 NEIGHBOR_STR
4061 NEIGHBOR_ADDR_STR2
4062 "Remove private ASNs in outbound updates\n"
4063 "Replace private ASNs with our ASN in outbound updates\n")
4064 {
4065 int idx_peer = 2;
4066 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4067 bgp_node_afi(vty), bgp_node_safi(vty),
4068 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4069 }
4070
4071 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4072 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4073 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4074 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4075 "Remove private ASNs in outbound updates\n"
4076 "Replace private ASNs with our ASN in outbound updates\n")
4077
4078 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4079 no_neighbor_remove_private_as_all_replace_as_cmd,
4080 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4081 NO_STR
4082 NEIGHBOR_STR
4083 NEIGHBOR_ADDR_STR2
4084 "Remove private ASNs in outbound updates\n"
4085 "Apply to all AS numbers\n"
4086 "Replace private ASNs with our ASN in outbound updates\n")
4087 {
4088 int idx_peer = 2;
4089 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4090 bgp_node_afi(vty), bgp_node_safi(vty),
4091 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4092 }
4093
4094 ALIAS_HIDDEN(
4095 no_neighbor_remove_private_as_all_replace_as,
4096 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4097 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4098 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4099 "Remove private ASNs in outbound updates\n"
4100 "Apply to all AS numbers\n"
4101 "Replace private ASNs with our ASN in outbound updates\n")
4102
4103
4104 /* neighbor send-community. */
4105 DEFUN (neighbor_send_community,
4106 neighbor_send_community_cmd,
4107 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4108 NEIGHBOR_STR
4109 NEIGHBOR_ADDR_STR2
4110 "Send Community attribute to this neighbor\n")
4111 {
4112 int idx_peer = 1;
4113
4114 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4115 bgp_node_safi(vty),
4116 PEER_FLAG_SEND_COMMUNITY);
4117 }
4118
4119 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4120 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4121 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4122 "Send Community attribute to this neighbor\n")
4123
4124 DEFUN (no_neighbor_send_community,
4125 no_neighbor_send_community_cmd,
4126 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4127 NO_STR
4128 NEIGHBOR_STR
4129 NEIGHBOR_ADDR_STR2
4130 "Send Community attribute to this neighbor\n")
4131 {
4132 int idx_peer = 2;
4133
4134 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4135 bgp_node_afi(vty), bgp_node_safi(vty),
4136 PEER_FLAG_SEND_COMMUNITY);
4137 }
4138
4139 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4140 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4141 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4142 "Send Community attribute to this neighbor\n")
4143
4144 /* neighbor send-community extended. */
4145 DEFUN (neighbor_send_community_type,
4146 neighbor_send_community_type_cmd,
4147 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4148 NEIGHBOR_STR
4149 NEIGHBOR_ADDR_STR2
4150 "Send Community attribute to this neighbor\n"
4151 "Send Standard and Extended Community attributes\n"
4152 "Send Standard, Large and Extended Community attributes\n"
4153 "Send Extended Community attributes\n"
4154 "Send Standard Community attributes\n"
4155 "Send Large Community attributes\n")
4156 {
4157 int idx_peer = 1;
4158 uint32_t flag = 0;
4159 const char *type = argv[argc - 1]->text;
4160
4161 if (strmatch(type, "standard")) {
4162 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4163 } else if (strmatch(type, "extended")) {
4164 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4165 } else if (strmatch(type, "large")) {
4166 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4167 } else if (strmatch(type, "both")) {
4168 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4169 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4170 } else { /* if (strmatch(type, "all")) */
4171 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4172 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4173 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4174 }
4175
4176 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4177 bgp_node_safi(vty), flag);
4178 }
4179
4180 ALIAS_HIDDEN(
4181 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4182 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4183 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4184 "Send Community attribute to this neighbor\n"
4185 "Send Standard and Extended Community attributes\n"
4186 "Send Standard, Large and Extended Community attributes\n"
4187 "Send Extended Community attributes\n"
4188 "Send Standard Community attributes\n"
4189 "Send Large Community attributes\n")
4190
4191 DEFUN (no_neighbor_send_community_type,
4192 no_neighbor_send_community_type_cmd,
4193 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4194 NO_STR
4195 NEIGHBOR_STR
4196 NEIGHBOR_ADDR_STR2
4197 "Send Community attribute to this neighbor\n"
4198 "Send Standard and Extended Community attributes\n"
4199 "Send Standard, Large and Extended Community attributes\n"
4200 "Send Extended Community attributes\n"
4201 "Send Standard Community attributes\n"
4202 "Send Large Community attributes\n")
4203 {
4204 int idx_peer = 2;
4205 uint32_t flag = 0;
4206 const char *type = argv[argc - 1]->text;
4207
4208 if (strmatch(type, "standard")) {
4209 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4210 } else if (strmatch(type, "extended")) {
4211 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4212 } else if (strmatch(type, "large")) {
4213 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4214 } else if (strmatch(type, "both")) {
4215 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4216 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4217 } else { /* if (strmatch(type, "all")) */
4218 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4219 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4220 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4221 }
4222
4223 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4224 bgp_node_afi(vty), bgp_node_safi(vty),
4225 flag);
4226 }
4227
4228 ALIAS_HIDDEN(
4229 no_neighbor_send_community_type,
4230 no_neighbor_send_community_type_hidden_cmd,
4231 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4232 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4233 "Send Community attribute to this neighbor\n"
4234 "Send Standard and Extended Community attributes\n"
4235 "Send Standard, Large and Extended Community attributes\n"
4236 "Send Extended Community attributes\n"
4237 "Send Standard Community attributes\n"
4238 "Send Large Community attributes\n")
4239
4240 /* neighbor soft-reconfig. */
4241 DEFUN (neighbor_soft_reconfiguration,
4242 neighbor_soft_reconfiguration_cmd,
4243 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4244 NEIGHBOR_STR
4245 NEIGHBOR_ADDR_STR2
4246 "Per neighbor soft reconfiguration\n"
4247 "Allow inbound soft reconfiguration for this neighbor\n")
4248 {
4249 int idx_peer = 1;
4250 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4251 bgp_node_safi(vty),
4252 PEER_FLAG_SOFT_RECONFIG);
4253 }
4254
4255 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4256 neighbor_soft_reconfiguration_hidden_cmd,
4257 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4258 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4259 "Per neighbor soft reconfiguration\n"
4260 "Allow inbound soft reconfiguration for this neighbor\n")
4261
4262 DEFUN (no_neighbor_soft_reconfiguration,
4263 no_neighbor_soft_reconfiguration_cmd,
4264 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4265 NO_STR
4266 NEIGHBOR_STR
4267 NEIGHBOR_ADDR_STR2
4268 "Per neighbor soft reconfiguration\n"
4269 "Allow inbound soft reconfiguration for this neighbor\n")
4270 {
4271 int idx_peer = 2;
4272 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4273 bgp_node_afi(vty), bgp_node_safi(vty),
4274 PEER_FLAG_SOFT_RECONFIG);
4275 }
4276
4277 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4278 no_neighbor_soft_reconfiguration_hidden_cmd,
4279 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4280 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4281 "Per neighbor soft reconfiguration\n"
4282 "Allow inbound soft reconfiguration for this neighbor\n")
4283
4284 DEFUN (neighbor_route_reflector_client,
4285 neighbor_route_reflector_client_cmd,
4286 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4287 NEIGHBOR_STR
4288 NEIGHBOR_ADDR_STR2
4289 "Configure a neighbor as Route Reflector client\n")
4290 {
4291 int idx_peer = 1;
4292 struct peer *peer;
4293
4294
4295 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4296 if (!peer)
4297 return CMD_WARNING_CONFIG_FAILED;
4298
4299 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4300 bgp_node_safi(vty),
4301 PEER_FLAG_REFLECTOR_CLIENT);
4302 }
4303
4304 ALIAS_HIDDEN(neighbor_route_reflector_client,
4305 neighbor_route_reflector_client_hidden_cmd,
4306 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4307 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4308 "Configure a neighbor as Route Reflector client\n")
4309
4310 DEFUN (no_neighbor_route_reflector_client,
4311 no_neighbor_route_reflector_client_cmd,
4312 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4313 NO_STR
4314 NEIGHBOR_STR
4315 NEIGHBOR_ADDR_STR2
4316 "Configure a neighbor as Route Reflector client\n")
4317 {
4318 int idx_peer = 2;
4319 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4320 bgp_node_afi(vty), bgp_node_safi(vty),
4321 PEER_FLAG_REFLECTOR_CLIENT);
4322 }
4323
4324 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4325 no_neighbor_route_reflector_client_hidden_cmd,
4326 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4327 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4328 "Configure a neighbor as Route Reflector client\n")
4329
4330 /* neighbor route-server-client. */
4331 DEFUN (neighbor_route_server_client,
4332 neighbor_route_server_client_cmd,
4333 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4334 NEIGHBOR_STR
4335 NEIGHBOR_ADDR_STR2
4336 "Configure a neighbor as Route Server client\n")
4337 {
4338 int idx_peer = 1;
4339 struct peer *peer;
4340
4341 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4342 if (!peer)
4343 return CMD_WARNING_CONFIG_FAILED;
4344 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4345 bgp_node_safi(vty),
4346 PEER_FLAG_RSERVER_CLIENT);
4347 }
4348
4349 ALIAS_HIDDEN(neighbor_route_server_client,
4350 neighbor_route_server_client_hidden_cmd,
4351 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4352 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4353 "Configure a neighbor as Route Server client\n")
4354
4355 DEFUN (no_neighbor_route_server_client,
4356 no_neighbor_route_server_client_cmd,
4357 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4358 NO_STR
4359 NEIGHBOR_STR
4360 NEIGHBOR_ADDR_STR2
4361 "Configure a neighbor as Route Server client\n")
4362 {
4363 int idx_peer = 2;
4364 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4365 bgp_node_afi(vty), bgp_node_safi(vty),
4366 PEER_FLAG_RSERVER_CLIENT);
4367 }
4368
4369 ALIAS_HIDDEN(no_neighbor_route_server_client,
4370 no_neighbor_route_server_client_hidden_cmd,
4371 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4372 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4373 "Configure a neighbor as Route Server client\n")
4374
4375 DEFUN (neighbor_nexthop_local_unchanged,
4376 neighbor_nexthop_local_unchanged_cmd,
4377 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4378 NEIGHBOR_STR
4379 NEIGHBOR_ADDR_STR2
4380 "Configure treatment of outgoing link-local nexthop attribute\n"
4381 "Leave link-local nexthop unchanged for this peer\n")
4382 {
4383 int idx_peer = 1;
4384 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4385 bgp_node_safi(vty),
4386 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4387 }
4388
4389 DEFUN (no_neighbor_nexthop_local_unchanged,
4390 no_neighbor_nexthop_local_unchanged_cmd,
4391 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4392 NO_STR
4393 NEIGHBOR_STR
4394 NEIGHBOR_ADDR_STR2
4395 "Configure treatment of outgoing link-local-nexthop attribute\n"
4396 "Leave link-local nexthop unchanged for this peer\n")
4397 {
4398 int idx_peer = 2;
4399 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4400 bgp_node_afi(vty), bgp_node_safi(vty),
4401 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4402 }
4403
4404 DEFUN (neighbor_attr_unchanged,
4405 neighbor_attr_unchanged_cmd,
4406 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4407 NEIGHBOR_STR
4408 NEIGHBOR_ADDR_STR2
4409 "BGP attribute is propagated unchanged to this neighbor\n"
4410 "As-path attribute\n"
4411 "Nexthop attribute\n"
4412 "Med attribute\n")
4413 {
4414 int idx = 0;
4415 char *peer_str = argv[1]->arg;
4416 struct peer *peer;
4417 uint16_t flags = 0;
4418 afi_t afi = bgp_node_afi(vty);
4419 safi_t safi = bgp_node_safi(vty);
4420
4421 peer = peer_and_group_lookup_vty(vty, peer_str);
4422 if (!peer)
4423 return CMD_WARNING_CONFIG_FAILED;
4424
4425 if (argv_find(argv, argc, "as-path", &idx))
4426 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4427 idx = 0;
4428 if (argv_find(argv, argc, "next-hop", &idx))
4429 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4430 idx = 0;
4431 if (argv_find(argv, argc, "med", &idx))
4432 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4433
4434 /* no flags means all of them! */
4435 if (!flags) {
4436 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4437 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4438 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4439 } else {
4440 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4441 && peer_af_flag_check(peer, afi, safi,
4442 PEER_FLAG_AS_PATH_UNCHANGED)) {
4443 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4444 PEER_FLAG_AS_PATH_UNCHANGED);
4445 }
4446
4447 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4448 && peer_af_flag_check(peer, afi, safi,
4449 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4450 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4451 PEER_FLAG_NEXTHOP_UNCHANGED);
4452 }
4453
4454 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4455 && peer_af_flag_check(peer, afi, safi,
4456 PEER_FLAG_MED_UNCHANGED)) {
4457 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4458 PEER_FLAG_MED_UNCHANGED);
4459 }
4460 }
4461
4462 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4463 }
4464
4465 ALIAS_HIDDEN(
4466 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4467 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4468 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4469 "BGP attribute is propagated unchanged to this neighbor\n"
4470 "As-path attribute\n"
4471 "Nexthop attribute\n"
4472 "Med attribute\n")
4473
4474 DEFUN (no_neighbor_attr_unchanged,
4475 no_neighbor_attr_unchanged_cmd,
4476 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4477 NO_STR
4478 NEIGHBOR_STR
4479 NEIGHBOR_ADDR_STR2
4480 "BGP attribute is propagated unchanged to this neighbor\n"
4481 "As-path attribute\n"
4482 "Nexthop attribute\n"
4483 "Med attribute\n")
4484 {
4485 int idx = 0;
4486 char *peer = argv[2]->arg;
4487 uint16_t flags = 0;
4488
4489 if (argv_find(argv, argc, "as-path", &idx))
4490 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4491 idx = 0;
4492 if (argv_find(argv, argc, "next-hop", &idx))
4493 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4494 idx = 0;
4495 if (argv_find(argv, argc, "med", &idx))
4496 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4497
4498 if (!flags) // no flags means all of them!
4499 {
4500 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4501 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4502 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4503 }
4504
4505 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4506 bgp_node_safi(vty), flags);
4507 }
4508
4509 ALIAS_HIDDEN(
4510 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4511 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4512 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4513 "BGP attribute is propagated unchanged to this neighbor\n"
4514 "As-path attribute\n"
4515 "Nexthop attribute\n"
4516 "Med attribute\n")
4517
4518 /* EBGP multihop configuration. */
4519 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4520 const char *ttl_str)
4521 {
4522 struct peer *peer;
4523 unsigned int ttl;
4524
4525 peer = peer_and_group_lookup_vty(vty, ip_str);
4526 if (!peer)
4527 return CMD_WARNING_CONFIG_FAILED;
4528
4529 if (peer->conf_if)
4530 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4531
4532 if (!ttl_str)
4533 ttl = MAXTTL;
4534 else
4535 ttl = strtoul(ttl_str, NULL, 10);
4536
4537 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4538 }
4539
4540 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4541 {
4542 struct peer *peer;
4543
4544 peer = peer_and_group_lookup_vty(vty, ip_str);
4545 if (!peer)
4546 return CMD_WARNING_CONFIG_FAILED;
4547
4548 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4549 }
4550
4551 /* neighbor ebgp-multihop. */
4552 DEFUN (neighbor_ebgp_multihop,
4553 neighbor_ebgp_multihop_cmd,
4554 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4555 NEIGHBOR_STR
4556 NEIGHBOR_ADDR_STR2
4557 "Allow EBGP neighbors not on directly connected networks\n")
4558 {
4559 int idx_peer = 1;
4560 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4561 }
4562
4563 DEFUN (neighbor_ebgp_multihop_ttl,
4564 neighbor_ebgp_multihop_ttl_cmd,
4565 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4566 NEIGHBOR_STR
4567 NEIGHBOR_ADDR_STR2
4568 "Allow EBGP neighbors not on directly connected networks\n"
4569 "maximum hop count\n")
4570 {
4571 int idx_peer = 1;
4572 int idx_number = 3;
4573 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4574 argv[idx_number]->arg);
4575 }
4576
4577 DEFUN (no_neighbor_ebgp_multihop,
4578 no_neighbor_ebgp_multihop_cmd,
4579 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4580 NO_STR
4581 NEIGHBOR_STR
4582 NEIGHBOR_ADDR_STR2
4583 "Allow EBGP neighbors not on directly connected networks\n"
4584 "maximum hop count\n")
4585 {
4586 int idx_peer = 2;
4587 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4588 }
4589
4590
4591 /* disable-connected-check */
4592 DEFUN (neighbor_disable_connected_check,
4593 neighbor_disable_connected_check_cmd,
4594 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4595 NEIGHBOR_STR
4596 NEIGHBOR_ADDR_STR2
4597 "one-hop away EBGP peer using loopback address\n"
4598 "Enforce EBGP neighbors perform multihop\n")
4599 {
4600 int idx_peer = 1;
4601 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4602 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4603 }
4604
4605 DEFUN (no_neighbor_disable_connected_check,
4606 no_neighbor_disable_connected_check_cmd,
4607 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4608 NO_STR
4609 NEIGHBOR_STR
4610 NEIGHBOR_ADDR_STR2
4611 "one-hop away EBGP peer using loopback address\n"
4612 "Enforce EBGP neighbors perform multihop\n")
4613 {
4614 int idx_peer = 2;
4615 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4616 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4617 }
4618
4619
4620 /* enforce-first-as */
4621 DEFUN (neighbor_enforce_first_as,
4622 neighbor_enforce_first_as_cmd,
4623 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4624 NEIGHBOR_STR
4625 NEIGHBOR_ADDR_STR2
4626 "Enforce the first AS for EBGP routes\n")
4627 {
4628 int idx_peer = 1;
4629
4630 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4631 PEER_FLAG_ENFORCE_FIRST_AS);
4632 }
4633
4634 DEFUN (no_neighbor_enforce_first_as,
4635 no_neighbor_enforce_first_as_cmd,
4636 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4637 NO_STR
4638 NEIGHBOR_STR
4639 NEIGHBOR_ADDR_STR2
4640 "Enforce the first AS for EBGP routes\n")
4641 {
4642 int idx_peer = 2;
4643
4644 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4645 PEER_FLAG_ENFORCE_FIRST_AS);
4646 }
4647
4648
4649 DEFUN (neighbor_description,
4650 neighbor_description_cmd,
4651 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4652 NEIGHBOR_STR
4653 NEIGHBOR_ADDR_STR2
4654 "Neighbor specific description\n"
4655 "Up to 80 characters describing this neighbor\n")
4656 {
4657 int idx_peer = 1;
4658 int idx_line = 3;
4659 struct peer *peer;
4660 char *str;
4661
4662 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4663 if (!peer)
4664 return CMD_WARNING_CONFIG_FAILED;
4665
4666 str = argv_concat(argv, argc, idx_line);
4667
4668 peer_description_set(peer, str);
4669
4670 XFREE(MTYPE_TMP, str);
4671
4672 return CMD_SUCCESS;
4673 }
4674
4675 DEFUN (no_neighbor_description,
4676 no_neighbor_description_cmd,
4677 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4678 NO_STR
4679 NEIGHBOR_STR
4680 NEIGHBOR_ADDR_STR2
4681 "Neighbor specific description\n")
4682 {
4683 int idx_peer = 2;
4684 struct peer *peer;
4685
4686 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4687 if (!peer)
4688 return CMD_WARNING_CONFIG_FAILED;
4689
4690 peer_description_unset(peer);
4691
4692 return CMD_SUCCESS;
4693 }
4694
4695 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4696 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4697 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4698 "Neighbor specific description\n"
4699 "Up to 80 characters describing this neighbor\n")
4700
4701 /* Neighbor update-source. */
4702 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4703 const char *source_str)
4704 {
4705 struct peer *peer;
4706 struct prefix p;
4707 union sockunion su;
4708
4709 peer = peer_and_group_lookup_vty(vty, peer_str);
4710 if (!peer)
4711 return CMD_WARNING_CONFIG_FAILED;
4712
4713 if (peer->conf_if)
4714 return CMD_WARNING;
4715
4716 if (source_str) {
4717 if (str2sockunion(source_str, &su) == 0)
4718 peer_update_source_addr_set(peer, &su);
4719 else {
4720 if (str2prefix(source_str, &p)) {
4721 vty_out(vty,
4722 "%% Invalid update-source, remove prefix length \n");
4723 return CMD_WARNING_CONFIG_FAILED;
4724 } else
4725 peer_update_source_if_set(peer, source_str);
4726 }
4727 } else
4728 peer_update_source_unset(peer);
4729
4730 return CMD_SUCCESS;
4731 }
4732
4733 #define BGP_UPDATE_SOURCE_HELP_STR \
4734 "IPv4 address\n" \
4735 "IPv6 address\n" \
4736 "Interface name (requires zebra to be running)\n"
4737
4738 DEFUN (neighbor_update_source,
4739 neighbor_update_source_cmd,
4740 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4741 NEIGHBOR_STR
4742 NEIGHBOR_ADDR_STR2
4743 "Source of routing updates\n"
4744 BGP_UPDATE_SOURCE_HELP_STR)
4745 {
4746 int idx_peer = 1;
4747 int idx_peer_2 = 3;
4748 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4749 argv[idx_peer_2]->arg);
4750 }
4751
4752 DEFUN (no_neighbor_update_source,
4753 no_neighbor_update_source_cmd,
4754 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4755 NO_STR
4756 NEIGHBOR_STR
4757 NEIGHBOR_ADDR_STR2
4758 "Source of routing updates\n"
4759 BGP_UPDATE_SOURCE_HELP_STR)
4760 {
4761 int idx_peer = 2;
4762 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4763 }
4764
4765 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4766 afi_t afi, safi_t safi,
4767 const char *rmap, int set)
4768 {
4769 int ret;
4770 struct peer *peer;
4771 struct route_map *route_map;
4772
4773 peer = peer_and_group_lookup_vty(vty, peer_str);
4774 if (!peer)
4775 return CMD_WARNING_CONFIG_FAILED;
4776
4777 if (set) {
4778 route_map = route_map_lookup_warn_noexist(vty, rmap);
4779 ret = peer_default_originate_set(peer, afi, safi,
4780 rmap, route_map);
4781 } else
4782 ret = peer_default_originate_unset(peer, afi, safi);
4783
4784 return bgp_vty_return(vty, ret);
4785 }
4786
4787 /* neighbor default-originate. */
4788 DEFUN (neighbor_default_originate,
4789 neighbor_default_originate_cmd,
4790 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4791 NEIGHBOR_STR
4792 NEIGHBOR_ADDR_STR2
4793 "Originate default route to this neighbor\n")
4794 {
4795 int idx_peer = 1;
4796 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4797 bgp_node_afi(vty),
4798 bgp_node_safi(vty), NULL, 1);
4799 }
4800
4801 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4802 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4803 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4804 "Originate default route to this neighbor\n")
4805
4806 DEFUN (neighbor_default_originate_rmap,
4807 neighbor_default_originate_rmap_cmd,
4808 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4809 NEIGHBOR_STR
4810 NEIGHBOR_ADDR_STR2
4811 "Originate default route to this neighbor\n"
4812 "Route-map to specify criteria to originate default\n"
4813 "route-map name\n")
4814 {
4815 int idx_peer = 1;
4816 int idx_word = 4;
4817 return peer_default_originate_set_vty(
4818 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4819 argv[idx_word]->arg, 1);
4820 }
4821
4822 ALIAS_HIDDEN(
4823 neighbor_default_originate_rmap,
4824 neighbor_default_originate_rmap_hidden_cmd,
4825 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4827 "Originate default route to this neighbor\n"
4828 "Route-map to specify criteria to originate default\n"
4829 "route-map name\n")
4830
4831 DEFUN (no_neighbor_default_originate,
4832 no_neighbor_default_originate_cmd,
4833 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4834 NO_STR
4835 NEIGHBOR_STR
4836 NEIGHBOR_ADDR_STR2
4837 "Originate default route to this neighbor\n"
4838 "Route-map to specify criteria to originate default\n"
4839 "route-map name\n")
4840 {
4841 int idx_peer = 2;
4842 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4843 bgp_node_afi(vty),
4844 bgp_node_safi(vty), NULL, 0);
4845 }
4846
4847 ALIAS_HIDDEN(
4848 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4849 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4850 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4851 "Originate default route to this neighbor\n"
4852 "Route-map to specify criteria to originate default\n"
4853 "route-map name\n")
4854
4855
4856 /* Set neighbor's BGP port. */
4857 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4858 const char *port_str)
4859 {
4860 struct peer *peer;
4861 uint16_t port;
4862 struct servent *sp;
4863
4864 peer = peer_lookup_vty(vty, ip_str);
4865 if (!peer)
4866 return CMD_WARNING_CONFIG_FAILED;
4867
4868 if (!port_str) {
4869 sp = getservbyname("bgp", "tcp");
4870 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4871 } else {
4872 port = strtoul(port_str, NULL, 10);
4873 }
4874
4875 peer_port_set(peer, port);
4876
4877 return CMD_SUCCESS;
4878 }
4879
4880 /* Set specified peer's BGP port. */
4881 DEFUN (neighbor_port,
4882 neighbor_port_cmd,
4883 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4884 NEIGHBOR_STR
4885 NEIGHBOR_ADDR_STR
4886 "Neighbor's BGP port\n"
4887 "TCP port number\n")
4888 {
4889 int idx_ip = 1;
4890 int idx_number = 3;
4891 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4892 argv[idx_number]->arg);
4893 }
4894
4895 DEFUN (no_neighbor_port,
4896 no_neighbor_port_cmd,
4897 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4898 NO_STR
4899 NEIGHBOR_STR
4900 NEIGHBOR_ADDR_STR
4901 "Neighbor's BGP port\n"
4902 "TCP port number\n")
4903 {
4904 int idx_ip = 2;
4905 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4906 }
4907
4908
4909 /* neighbor weight. */
4910 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4911 safi_t safi, const char *weight_str)
4912 {
4913 int ret;
4914 struct peer *peer;
4915 unsigned long weight;
4916
4917 peer = peer_and_group_lookup_vty(vty, ip_str);
4918 if (!peer)
4919 return CMD_WARNING_CONFIG_FAILED;
4920
4921 weight = strtoul(weight_str, NULL, 10);
4922
4923 ret = peer_weight_set(peer, afi, safi, weight);
4924 return bgp_vty_return(vty, ret);
4925 }
4926
4927 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4928 safi_t safi)
4929 {
4930 int ret;
4931 struct peer *peer;
4932
4933 peer = peer_and_group_lookup_vty(vty, ip_str);
4934 if (!peer)
4935 return CMD_WARNING_CONFIG_FAILED;
4936
4937 ret = peer_weight_unset(peer, afi, safi);
4938 return bgp_vty_return(vty, ret);
4939 }
4940
4941 DEFUN (neighbor_weight,
4942 neighbor_weight_cmd,
4943 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4944 NEIGHBOR_STR
4945 NEIGHBOR_ADDR_STR2
4946 "Set default weight for routes from this neighbor\n"
4947 "default weight\n")
4948 {
4949 int idx_peer = 1;
4950 int idx_number = 3;
4951 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4952 bgp_node_safi(vty), argv[idx_number]->arg);
4953 }
4954
4955 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4956 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4957 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4958 "Set default weight for routes from this neighbor\n"
4959 "default weight\n")
4960
4961 DEFUN (no_neighbor_weight,
4962 no_neighbor_weight_cmd,
4963 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4964 NO_STR
4965 NEIGHBOR_STR
4966 NEIGHBOR_ADDR_STR2
4967 "Set default weight for routes from this neighbor\n"
4968 "default weight\n")
4969 {
4970 int idx_peer = 2;
4971 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4972 bgp_node_afi(vty), bgp_node_safi(vty));
4973 }
4974
4975 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4976 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4977 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4978 "Set default weight for routes from this neighbor\n"
4979 "default weight\n")
4980
4981
4982 /* Override capability negotiation. */
4983 DEFUN (neighbor_override_capability,
4984 neighbor_override_capability_cmd,
4985 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4986 NEIGHBOR_STR
4987 NEIGHBOR_ADDR_STR2
4988 "Override capability negotiation result\n")
4989 {
4990 int idx_peer = 1;
4991 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4992 PEER_FLAG_OVERRIDE_CAPABILITY);
4993 }
4994
4995 DEFUN (no_neighbor_override_capability,
4996 no_neighbor_override_capability_cmd,
4997 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4998 NO_STR
4999 NEIGHBOR_STR
5000 NEIGHBOR_ADDR_STR2
5001 "Override capability negotiation result\n")
5002 {
5003 int idx_peer = 2;
5004 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5005 PEER_FLAG_OVERRIDE_CAPABILITY);
5006 }
5007
5008 DEFUN (neighbor_strict_capability,
5009 neighbor_strict_capability_cmd,
5010 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5011 NEIGHBOR_STR
5012 NEIGHBOR_ADDR_STR2
5013 "Strict capability negotiation match\n")
5014 {
5015 int idx_peer = 1;
5016
5017 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5018 PEER_FLAG_STRICT_CAP_MATCH);
5019 }
5020
5021 DEFUN (no_neighbor_strict_capability,
5022 no_neighbor_strict_capability_cmd,
5023 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5024 NO_STR
5025 NEIGHBOR_STR
5026 NEIGHBOR_ADDR_STR2
5027 "Strict capability negotiation match\n")
5028 {
5029 int idx_peer = 2;
5030
5031 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5032 PEER_FLAG_STRICT_CAP_MATCH);
5033 }
5034
5035 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5036 const char *keep_str, const char *hold_str)
5037 {
5038 int ret;
5039 struct peer *peer;
5040 uint32_t keepalive;
5041 uint32_t holdtime;
5042
5043 peer = peer_and_group_lookup_vty(vty, ip_str);
5044 if (!peer)
5045 return CMD_WARNING_CONFIG_FAILED;
5046
5047 keepalive = strtoul(keep_str, NULL, 10);
5048 holdtime = strtoul(hold_str, NULL, 10);
5049
5050 ret = peer_timers_set(peer, keepalive, holdtime);
5051
5052 return bgp_vty_return(vty, ret);
5053 }
5054
5055 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5056 {
5057 int ret;
5058 struct peer *peer;
5059
5060 peer = peer_and_group_lookup_vty(vty, ip_str);
5061 if (!peer)
5062 return CMD_WARNING_CONFIG_FAILED;
5063
5064 ret = peer_timers_unset(peer);
5065
5066 return bgp_vty_return(vty, ret);
5067 }
5068
5069 DEFUN (neighbor_timers,
5070 neighbor_timers_cmd,
5071 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5072 NEIGHBOR_STR
5073 NEIGHBOR_ADDR_STR2
5074 "BGP per neighbor timers\n"
5075 "Keepalive interval\n"
5076 "Holdtime\n")
5077 {
5078 int idx_peer = 1;
5079 int idx_number = 3;
5080 int idx_number_2 = 4;
5081 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5082 argv[idx_number]->arg,
5083 argv[idx_number_2]->arg);
5084 }
5085
5086 DEFUN (no_neighbor_timers,
5087 no_neighbor_timers_cmd,
5088 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5089 NO_STR
5090 NEIGHBOR_STR
5091 NEIGHBOR_ADDR_STR2
5092 "BGP per neighbor timers\n"
5093 "Keepalive interval\n"
5094 "Holdtime\n")
5095 {
5096 int idx_peer = 2;
5097 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5098 }
5099
5100
5101 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5102 const char *time_str)
5103 {
5104 int ret;
5105 struct peer *peer;
5106 uint32_t connect;
5107
5108 peer = peer_and_group_lookup_vty(vty, ip_str);
5109 if (!peer)
5110 return CMD_WARNING_CONFIG_FAILED;
5111
5112 connect = strtoul(time_str, NULL, 10);
5113
5114 ret = peer_timers_connect_set(peer, connect);
5115
5116 return bgp_vty_return(vty, ret);
5117 }
5118
5119 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5120 {
5121 int ret;
5122 struct peer *peer;
5123
5124 peer = peer_and_group_lookup_vty(vty, ip_str);
5125 if (!peer)
5126 return CMD_WARNING_CONFIG_FAILED;
5127
5128 ret = peer_timers_connect_unset(peer);
5129
5130 return bgp_vty_return(vty, ret);
5131 }
5132
5133 DEFUN (neighbor_timers_connect,
5134 neighbor_timers_connect_cmd,
5135 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5136 NEIGHBOR_STR
5137 NEIGHBOR_ADDR_STR2
5138 "BGP per neighbor timers\n"
5139 "BGP connect timer\n"
5140 "Connect timer\n")
5141 {
5142 int idx_peer = 1;
5143 int idx_number = 4;
5144 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5145 argv[idx_number]->arg);
5146 }
5147
5148 DEFUN (no_neighbor_timers_connect,
5149 no_neighbor_timers_connect_cmd,
5150 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5151 NO_STR
5152 NEIGHBOR_STR
5153 NEIGHBOR_ADDR_STR2
5154 "BGP per neighbor timers\n"
5155 "BGP connect timer\n"
5156 "Connect timer\n")
5157 {
5158 int idx_peer = 2;
5159 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5160 }
5161
5162
5163 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5164 const char *time_str, int set)
5165 {
5166 int ret;
5167 struct peer *peer;
5168 uint32_t routeadv = 0;
5169
5170 peer = peer_and_group_lookup_vty(vty, ip_str);
5171 if (!peer)
5172 return CMD_WARNING_CONFIG_FAILED;
5173
5174 if (time_str)
5175 routeadv = strtoul(time_str, NULL, 10);
5176
5177 if (set)
5178 ret = peer_advertise_interval_set(peer, routeadv);
5179 else
5180 ret = peer_advertise_interval_unset(peer);
5181
5182 return bgp_vty_return(vty, ret);
5183 }
5184
5185 DEFUN (neighbor_advertise_interval,
5186 neighbor_advertise_interval_cmd,
5187 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5188 NEIGHBOR_STR
5189 NEIGHBOR_ADDR_STR2
5190 "Minimum interval between sending BGP routing updates\n"
5191 "time in seconds\n")
5192 {
5193 int idx_peer = 1;
5194 int idx_number = 3;
5195 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5196 argv[idx_number]->arg, 1);
5197 }
5198
5199 DEFUN (no_neighbor_advertise_interval,
5200 no_neighbor_advertise_interval_cmd,
5201 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5202 NO_STR
5203 NEIGHBOR_STR
5204 NEIGHBOR_ADDR_STR2
5205 "Minimum interval between sending BGP routing updates\n"
5206 "time in seconds\n")
5207 {
5208 int idx_peer = 2;
5209 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5210 }
5211
5212
5213 /* Time to wait before processing route-map updates */
5214 DEFUN (bgp_set_route_map_delay_timer,
5215 bgp_set_route_map_delay_timer_cmd,
5216 "bgp route-map delay-timer (0-600)",
5217 SET_STR
5218 "BGP route-map delay timer\n"
5219 "Time in secs to wait before processing route-map changes\n"
5220 "0 disables the timer, no route updates happen when route-maps change\n")
5221 {
5222 int idx_number = 3;
5223 uint32_t rmap_delay_timer;
5224
5225 if (argv[idx_number]->arg) {
5226 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5227 bm->rmap_update_timer = rmap_delay_timer;
5228
5229 /* if the dynamic update handling is being disabled, and a timer
5230 * is
5231 * running, stop the timer and act as if the timer has already
5232 * fired.
5233 */
5234 if (!rmap_delay_timer && bm->t_rmap_update) {
5235 BGP_TIMER_OFF(bm->t_rmap_update);
5236 thread_execute(bm->master, bgp_route_map_update_timer,
5237 NULL, 0);
5238 }
5239 return CMD_SUCCESS;
5240 } else {
5241 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5242 return CMD_WARNING_CONFIG_FAILED;
5243 }
5244 }
5245
5246 DEFUN (no_bgp_set_route_map_delay_timer,
5247 no_bgp_set_route_map_delay_timer_cmd,
5248 "no bgp route-map delay-timer [(0-600)]",
5249 NO_STR
5250 BGP_STR
5251 "Default BGP route-map delay timer\n"
5252 "Reset to default time to wait for processing route-map changes\n"
5253 "0 disables the timer, no route updates happen when route-maps change\n")
5254 {
5255
5256 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5257
5258 return CMD_SUCCESS;
5259 }
5260
5261
5262 /* neighbor interface */
5263 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5264 const char *str)
5265 {
5266 struct peer *peer;
5267
5268 peer = peer_lookup_vty(vty, ip_str);
5269 if (!peer || peer->conf_if) {
5270 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5271 return CMD_WARNING_CONFIG_FAILED;
5272 }
5273
5274 if (str)
5275 peer_interface_set(peer, str);
5276 else
5277 peer_interface_unset(peer);
5278
5279 return CMD_SUCCESS;
5280 }
5281
5282 DEFUN (neighbor_interface,
5283 neighbor_interface_cmd,
5284 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5285 NEIGHBOR_STR
5286 NEIGHBOR_ADDR_STR
5287 "Interface\n"
5288 "Interface name\n")
5289 {
5290 int idx_ip = 1;
5291 int idx_word = 3;
5292 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5293 }
5294
5295 DEFUN (no_neighbor_interface,
5296 no_neighbor_interface_cmd,
5297 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5298 NO_STR
5299 NEIGHBOR_STR
5300 NEIGHBOR_ADDR_STR2
5301 "Interface\n"
5302 "Interface name\n")
5303 {
5304 int idx_peer = 2;
5305 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5306 }
5307
5308 DEFUN (neighbor_distribute_list,
5309 neighbor_distribute_list_cmd,
5310 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5311 NEIGHBOR_STR
5312 NEIGHBOR_ADDR_STR2
5313 "Filter updates to/from this neighbor\n"
5314 "IP access-list number\n"
5315 "IP access-list number (expanded range)\n"
5316 "IP Access-list name\n"
5317 "Filter incoming updates\n"
5318 "Filter outgoing updates\n")
5319 {
5320 int idx_peer = 1;
5321 int idx_acl = 3;
5322 int direct, ret;
5323 struct peer *peer;
5324
5325 const char *pstr = argv[idx_peer]->arg;
5326 const char *acl = argv[idx_acl]->arg;
5327 const char *inout = argv[argc - 1]->text;
5328
5329 peer = peer_and_group_lookup_vty(vty, pstr);
5330 if (!peer)
5331 return CMD_WARNING_CONFIG_FAILED;
5332
5333 /* Check filter direction. */
5334 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5335 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5336 direct, acl);
5337
5338 return bgp_vty_return(vty, ret);
5339 }
5340
5341 ALIAS_HIDDEN(
5342 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5343 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5344 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5345 "Filter updates to/from this neighbor\n"
5346 "IP access-list number\n"
5347 "IP access-list number (expanded range)\n"
5348 "IP Access-list name\n"
5349 "Filter incoming updates\n"
5350 "Filter outgoing updates\n")
5351
5352 DEFUN (no_neighbor_distribute_list,
5353 no_neighbor_distribute_list_cmd,
5354 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5355 NO_STR
5356 NEIGHBOR_STR
5357 NEIGHBOR_ADDR_STR2
5358 "Filter updates to/from this neighbor\n"
5359 "IP access-list number\n"
5360 "IP access-list number (expanded range)\n"
5361 "IP Access-list name\n"
5362 "Filter incoming updates\n"
5363 "Filter outgoing updates\n")
5364 {
5365 int idx_peer = 2;
5366 int direct, ret;
5367 struct peer *peer;
5368
5369 const char *pstr = argv[idx_peer]->arg;
5370 const char *inout = argv[argc - 1]->text;
5371
5372 peer = peer_and_group_lookup_vty(vty, pstr);
5373 if (!peer)
5374 return CMD_WARNING_CONFIG_FAILED;
5375
5376 /* Check filter direction. */
5377 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5378 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5379 direct);
5380
5381 return bgp_vty_return(vty, ret);
5382 }
5383
5384 ALIAS_HIDDEN(
5385 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5386 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5387 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5388 "Filter updates to/from this neighbor\n"
5389 "IP access-list number\n"
5390 "IP access-list number (expanded range)\n"
5391 "IP Access-list name\n"
5392 "Filter incoming updates\n"
5393 "Filter outgoing updates\n")
5394
5395 /* Set prefix list to the peer. */
5396 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5397 afi_t afi, safi_t safi,
5398 const char *name_str,
5399 const char *direct_str)
5400 {
5401 int ret;
5402 int direct = FILTER_IN;
5403 struct peer *peer;
5404
5405 peer = peer_and_group_lookup_vty(vty, ip_str);
5406 if (!peer)
5407 return CMD_WARNING_CONFIG_FAILED;
5408
5409 /* Check filter direction. */
5410 if (strncmp(direct_str, "i", 1) == 0)
5411 direct = FILTER_IN;
5412 else if (strncmp(direct_str, "o", 1) == 0)
5413 direct = FILTER_OUT;
5414
5415 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5416
5417 return bgp_vty_return(vty, ret);
5418 }
5419
5420 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5421 afi_t afi, safi_t safi,
5422 const char *direct_str)
5423 {
5424 int ret;
5425 struct peer *peer;
5426 int direct = FILTER_IN;
5427
5428 peer = peer_and_group_lookup_vty(vty, ip_str);
5429 if (!peer)
5430 return CMD_WARNING_CONFIG_FAILED;
5431
5432 /* Check filter direction. */
5433 if (strncmp(direct_str, "i", 1) == 0)
5434 direct = FILTER_IN;
5435 else if (strncmp(direct_str, "o", 1) == 0)
5436 direct = FILTER_OUT;
5437
5438 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5439
5440 return bgp_vty_return(vty, ret);
5441 }
5442
5443 DEFUN (neighbor_prefix_list,
5444 neighbor_prefix_list_cmd,
5445 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5446 NEIGHBOR_STR
5447 NEIGHBOR_ADDR_STR2
5448 "Filter updates to/from this neighbor\n"
5449 "Name of a prefix list\n"
5450 "Filter incoming updates\n"
5451 "Filter outgoing updates\n")
5452 {
5453 int idx_peer = 1;
5454 int idx_word = 3;
5455 int idx_in_out = 4;
5456 return peer_prefix_list_set_vty(
5457 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5458 argv[idx_word]->arg, argv[idx_in_out]->arg);
5459 }
5460
5461 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5462 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5463 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5464 "Filter updates to/from this neighbor\n"
5465 "Name of a prefix list\n"
5466 "Filter incoming updates\n"
5467 "Filter outgoing updates\n")
5468
5469 DEFUN (no_neighbor_prefix_list,
5470 no_neighbor_prefix_list_cmd,
5471 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5472 NO_STR
5473 NEIGHBOR_STR
5474 NEIGHBOR_ADDR_STR2
5475 "Filter updates to/from this neighbor\n"
5476 "Name of a prefix list\n"
5477 "Filter incoming updates\n"
5478 "Filter outgoing updates\n")
5479 {
5480 int idx_peer = 2;
5481 int idx_in_out = 5;
5482 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5483 bgp_node_afi(vty), bgp_node_safi(vty),
5484 argv[idx_in_out]->arg);
5485 }
5486
5487 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5488 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5489 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5490 "Filter updates to/from this neighbor\n"
5491 "Name of a prefix list\n"
5492 "Filter incoming updates\n"
5493 "Filter outgoing updates\n")
5494
5495 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5496 safi_t safi, const char *name_str,
5497 const char *direct_str)
5498 {
5499 int ret;
5500 struct peer *peer;
5501 int direct = FILTER_IN;
5502
5503 peer = peer_and_group_lookup_vty(vty, ip_str);
5504 if (!peer)
5505 return CMD_WARNING_CONFIG_FAILED;
5506
5507 /* Check filter direction. */
5508 if (strncmp(direct_str, "i", 1) == 0)
5509 direct = FILTER_IN;
5510 else if (strncmp(direct_str, "o", 1) == 0)
5511 direct = FILTER_OUT;
5512
5513 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5514
5515 return bgp_vty_return(vty, ret);
5516 }
5517
5518 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5519 safi_t safi, const char *direct_str)
5520 {
5521 int ret;
5522 struct peer *peer;
5523 int direct = FILTER_IN;
5524
5525 peer = peer_and_group_lookup_vty(vty, ip_str);
5526 if (!peer)
5527 return CMD_WARNING_CONFIG_FAILED;
5528
5529 /* Check filter direction. */
5530 if (strncmp(direct_str, "i", 1) == 0)
5531 direct = FILTER_IN;
5532 else if (strncmp(direct_str, "o", 1) == 0)
5533 direct = FILTER_OUT;
5534
5535 ret = peer_aslist_unset(peer, afi, safi, direct);
5536
5537 return bgp_vty_return(vty, ret);
5538 }
5539
5540 DEFUN (neighbor_filter_list,
5541 neighbor_filter_list_cmd,
5542 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5543 NEIGHBOR_STR
5544 NEIGHBOR_ADDR_STR2
5545 "Establish BGP filters\n"
5546 "AS path access-list name\n"
5547 "Filter incoming routes\n"
5548 "Filter outgoing routes\n")
5549 {
5550 int idx_peer = 1;
5551 int idx_word = 3;
5552 int idx_in_out = 4;
5553 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5554 bgp_node_safi(vty), argv[idx_word]->arg,
5555 argv[idx_in_out]->arg);
5556 }
5557
5558 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5559 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5560 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5561 "Establish BGP filters\n"
5562 "AS path access-list name\n"
5563 "Filter incoming routes\n"
5564 "Filter outgoing routes\n")
5565
5566 DEFUN (no_neighbor_filter_list,
5567 no_neighbor_filter_list_cmd,
5568 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5569 NO_STR
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR2
5572 "Establish BGP filters\n"
5573 "AS path access-list name\n"
5574 "Filter incoming routes\n"
5575 "Filter outgoing routes\n")
5576 {
5577 int idx_peer = 2;
5578 int idx_in_out = 5;
5579 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5580 bgp_node_afi(vty), bgp_node_safi(vty),
5581 argv[idx_in_out]->arg);
5582 }
5583
5584 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5585 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5586 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5587 "Establish BGP filters\n"
5588 "AS path access-list name\n"
5589 "Filter incoming routes\n"
5590 "Filter outgoing routes\n")
5591
5592 /* Set route-map to the peer. */
5593 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5594 afi_t afi, safi_t safi, const char *name_str,
5595 const char *direct_str)
5596 {
5597 int ret;
5598 struct peer *peer;
5599 int direct = RMAP_IN;
5600 struct route_map *route_map;
5601
5602 peer = peer_and_group_lookup_vty(vty, ip_str);
5603 if (!peer)
5604 return CMD_WARNING_CONFIG_FAILED;
5605
5606 /* Check filter direction. */
5607 if (strncmp(direct_str, "in", 2) == 0)
5608 direct = RMAP_IN;
5609 else if (strncmp(direct_str, "o", 1) == 0)
5610 direct = RMAP_OUT;
5611
5612 route_map = route_map_lookup_warn_noexist(vty, name_str);
5613 ret = peer_route_map_set(peer, afi, safi, direct, name_str, route_map);
5614
5615 return bgp_vty_return(vty, ret);
5616 }
5617
5618 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5619 afi_t afi, safi_t safi,
5620 const char *direct_str)
5621 {
5622 int ret;
5623 struct peer *peer;
5624 int direct = RMAP_IN;
5625
5626 peer = peer_and_group_lookup_vty(vty, ip_str);
5627 if (!peer)
5628 return CMD_WARNING_CONFIG_FAILED;
5629
5630 /* Check filter direction. */
5631 if (strncmp(direct_str, "in", 2) == 0)
5632 direct = RMAP_IN;
5633 else if (strncmp(direct_str, "o", 1) == 0)
5634 direct = RMAP_OUT;
5635
5636 ret = peer_route_map_unset(peer, afi, safi, direct);
5637
5638 return bgp_vty_return(vty, ret);
5639 }
5640
5641 DEFUN (neighbor_route_map,
5642 neighbor_route_map_cmd,
5643 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5644 NEIGHBOR_STR
5645 NEIGHBOR_ADDR_STR2
5646 "Apply route map to neighbor\n"
5647 "Name of route map\n"
5648 "Apply map to incoming routes\n"
5649 "Apply map to outbound routes\n")
5650 {
5651 int idx_peer = 1;
5652 int idx_word = 3;
5653 int idx_in_out = 4;
5654 return peer_route_map_set_vty(
5655 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5656 argv[idx_word]->arg, argv[idx_in_out]->arg);
5657 }
5658
5659 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5660 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5661 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5662 "Apply route map to neighbor\n"
5663 "Name of route map\n"
5664 "Apply map to incoming routes\n"
5665 "Apply map to outbound routes\n")
5666
5667 DEFUN (no_neighbor_route_map,
5668 no_neighbor_route_map_cmd,
5669 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5670 NO_STR
5671 NEIGHBOR_STR
5672 NEIGHBOR_ADDR_STR2
5673 "Apply route map to neighbor\n"
5674 "Name of route map\n"
5675 "Apply map to incoming routes\n"
5676 "Apply map to outbound routes\n")
5677 {
5678 int idx_peer = 2;
5679 int idx_in_out = 5;
5680 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5681 bgp_node_afi(vty), bgp_node_safi(vty),
5682 argv[idx_in_out]->arg);
5683 }
5684
5685 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5686 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5687 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5688 "Apply route map to neighbor\n"
5689 "Name of route map\n"
5690 "Apply map to incoming routes\n"
5691 "Apply map to outbound routes\n")
5692
5693 /* Set unsuppress-map to the peer. */
5694 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5695 afi_t afi, safi_t safi,
5696 const char *name_str)
5697 {
5698 int ret;
5699 struct peer *peer;
5700 struct route_map *route_map;
5701
5702 peer = peer_and_group_lookup_vty(vty, ip_str);
5703 if (!peer)
5704 return CMD_WARNING_CONFIG_FAILED;
5705
5706 route_map = route_map_lookup_warn_noexist(vty, name_str);
5707 ret = peer_unsuppress_map_set(peer, afi, safi, name_str, route_map);
5708
5709 return bgp_vty_return(vty, ret);
5710 }
5711
5712 /* Unset route-map from the peer. */
5713 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5714 afi_t afi, safi_t safi)
5715 {
5716 int ret;
5717 struct peer *peer;
5718
5719 peer = peer_and_group_lookup_vty(vty, ip_str);
5720 if (!peer)
5721 return CMD_WARNING_CONFIG_FAILED;
5722
5723 ret = peer_unsuppress_map_unset(peer, afi, safi);
5724
5725 return bgp_vty_return(vty, ret);
5726 }
5727
5728 DEFUN (neighbor_unsuppress_map,
5729 neighbor_unsuppress_map_cmd,
5730 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5731 NEIGHBOR_STR
5732 NEIGHBOR_ADDR_STR2
5733 "Route-map to selectively unsuppress suppressed routes\n"
5734 "Name of route map\n")
5735 {
5736 int idx_peer = 1;
5737 int idx_word = 3;
5738 return peer_unsuppress_map_set_vty(
5739 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5740 argv[idx_word]->arg);
5741 }
5742
5743 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5744 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5745 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5746 "Route-map to selectively unsuppress suppressed routes\n"
5747 "Name of route map\n")
5748
5749 DEFUN (no_neighbor_unsuppress_map,
5750 no_neighbor_unsuppress_map_cmd,
5751 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5752 NO_STR
5753 NEIGHBOR_STR
5754 NEIGHBOR_ADDR_STR2
5755 "Route-map to selectively unsuppress suppressed routes\n"
5756 "Name of route map\n")
5757 {
5758 int idx_peer = 2;
5759 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5760 bgp_node_afi(vty),
5761 bgp_node_safi(vty));
5762 }
5763
5764 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5765 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5766 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5767 "Route-map to selectively unsuppress suppressed routes\n"
5768 "Name of route map\n")
5769
5770 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5771 afi_t afi, safi_t safi,
5772 const char *num_str,
5773 const char *threshold_str, int warning,
5774 const char *restart_str)
5775 {
5776 int ret;
5777 struct peer *peer;
5778 uint32_t max;
5779 uint8_t threshold;
5780 uint16_t restart;
5781
5782 peer = peer_and_group_lookup_vty(vty, ip_str);
5783 if (!peer)
5784 return CMD_WARNING_CONFIG_FAILED;
5785
5786 max = strtoul(num_str, NULL, 10);
5787 if (threshold_str)
5788 threshold = atoi(threshold_str);
5789 else
5790 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5791
5792 if (restart_str)
5793 restart = atoi(restart_str);
5794 else
5795 restart = 0;
5796
5797 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5798 restart);
5799
5800 return bgp_vty_return(vty, ret);
5801 }
5802
5803 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5804 afi_t afi, safi_t safi)
5805 {
5806 int ret;
5807 struct peer *peer;
5808
5809 peer = peer_and_group_lookup_vty(vty, ip_str);
5810 if (!peer)
5811 return CMD_WARNING_CONFIG_FAILED;
5812
5813 ret = peer_maximum_prefix_unset(peer, afi, safi);
5814
5815 return bgp_vty_return(vty, ret);
5816 }
5817
5818 /* Maximum number of prefix configuration. prefix count is different
5819 for each peer configuration. So this configuration can be set for
5820 each peer configuration. */
5821 DEFUN (neighbor_maximum_prefix,
5822 neighbor_maximum_prefix_cmd,
5823 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5824 NEIGHBOR_STR
5825 NEIGHBOR_ADDR_STR2
5826 "Maximum number of prefix accept from this peer\n"
5827 "maximum no. of prefix limit\n")
5828 {
5829 int idx_peer = 1;
5830 int idx_number = 3;
5831 return peer_maximum_prefix_set_vty(
5832 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5833 argv[idx_number]->arg, NULL, 0, NULL);
5834 }
5835
5836 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5838 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5839 "Maximum number of prefix accept from this peer\n"
5840 "maximum no. of prefix limit\n")
5841
5842 DEFUN (neighbor_maximum_prefix_threshold,
5843 neighbor_maximum_prefix_threshold_cmd,
5844 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5845 NEIGHBOR_STR
5846 NEIGHBOR_ADDR_STR2
5847 "Maximum number of prefix accept from this peer\n"
5848 "maximum no. of prefix limit\n"
5849 "Threshold value (%) at which to generate a warning msg\n")
5850 {
5851 int idx_peer = 1;
5852 int idx_number = 3;
5853 int idx_number_2 = 4;
5854 return peer_maximum_prefix_set_vty(
5855 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5856 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5857 }
5858
5859 ALIAS_HIDDEN(
5860 neighbor_maximum_prefix_threshold,
5861 neighbor_maximum_prefix_threshold_hidden_cmd,
5862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5863 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5864 "Maximum number of prefix accept from this peer\n"
5865 "maximum no. of prefix limit\n"
5866 "Threshold value (%) at which to generate a warning msg\n")
5867
5868 DEFUN (neighbor_maximum_prefix_warning,
5869 neighbor_maximum_prefix_warning_cmd,
5870 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5871 NEIGHBOR_STR
5872 NEIGHBOR_ADDR_STR2
5873 "Maximum number of prefix accept from this peer\n"
5874 "maximum no. of prefix limit\n"
5875 "Only give warning message when limit is exceeded\n")
5876 {
5877 int idx_peer = 1;
5878 int idx_number = 3;
5879 return peer_maximum_prefix_set_vty(
5880 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5881 argv[idx_number]->arg, NULL, 1, NULL);
5882 }
5883
5884 ALIAS_HIDDEN(
5885 neighbor_maximum_prefix_warning,
5886 neighbor_maximum_prefix_warning_hidden_cmd,
5887 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5888 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5889 "Maximum number of prefix accept from this peer\n"
5890 "maximum no. of prefix limit\n"
5891 "Only give warning message when limit is exceeded\n")
5892
5893 DEFUN (neighbor_maximum_prefix_threshold_warning,
5894 neighbor_maximum_prefix_threshold_warning_cmd,
5895 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5896 NEIGHBOR_STR
5897 NEIGHBOR_ADDR_STR2
5898 "Maximum number of prefix accept from this peer\n"
5899 "maximum no. of prefix limit\n"
5900 "Threshold value (%) at which to generate a warning msg\n"
5901 "Only give warning message when limit is exceeded\n")
5902 {
5903 int idx_peer = 1;
5904 int idx_number = 3;
5905 int idx_number_2 = 4;
5906 return peer_maximum_prefix_set_vty(
5907 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5908 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5909 }
5910
5911 ALIAS_HIDDEN(
5912 neighbor_maximum_prefix_threshold_warning,
5913 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5914 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5915 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5916 "Maximum number of prefix accept from this peer\n"
5917 "maximum no. of prefix limit\n"
5918 "Threshold value (%) at which to generate a warning msg\n"
5919 "Only give warning message when limit is exceeded\n")
5920
5921 DEFUN (neighbor_maximum_prefix_restart,
5922 neighbor_maximum_prefix_restart_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5924 NEIGHBOR_STR
5925 NEIGHBOR_ADDR_STR2
5926 "Maximum number of prefix accept from this peer\n"
5927 "maximum no. of prefix limit\n"
5928 "Restart bgp connection after limit is exceeded\n"
5929 "Restart interval in minutes\n")
5930 {
5931 int idx_peer = 1;
5932 int idx_number = 3;
5933 int idx_number_2 = 5;
5934 return peer_maximum_prefix_set_vty(
5935 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5936 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5937 }
5938
5939 ALIAS_HIDDEN(
5940 neighbor_maximum_prefix_restart,
5941 neighbor_maximum_prefix_restart_hidden_cmd,
5942 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5943 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5944 "Maximum number of prefix accept from this peer\n"
5945 "maximum no. of prefix limit\n"
5946 "Restart bgp connection after limit is exceeded\n"
5947 "Restart interval in minutes\n")
5948
5949 DEFUN (neighbor_maximum_prefix_threshold_restart,
5950 neighbor_maximum_prefix_threshold_restart_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Maximum number of prefixes to accept from this peer\n"
5955 "maximum no. of prefix limit\n"
5956 "Threshold value (%) at which to generate a warning msg\n"
5957 "Restart bgp connection after limit is exceeded\n"
5958 "Restart interval in minutes\n")
5959 {
5960 int idx_peer = 1;
5961 int idx_number = 3;
5962 int idx_number_2 = 4;
5963 int idx_number_3 = 6;
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, argv[idx_number_2]->arg, 0,
5967 argv[idx_number_3]->arg);
5968 }
5969
5970 ALIAS_HIDDEN(
5971 neighbor_maximum_prefix_threshold_restart,
5972 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5973 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5975 "Maximum number of prefixes to accept from this peer\n"
5976 "maximum no. of prefix limit\n"
5977 "Threshold value (%) at which to generate a warning msg\n"
5978 "Restart bgp connection after limit is exceeded\n"
5979 "Restart interval in minutes\n")
5980
5981 DEFUN (no_neighbor_maximum_prefix,
5982 no_neighbor_maximum_prefix_cmd,
5983 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5984 NO_STR
5985 NEIGHBOR_STR
5986 NEIGHBOR_ADDR_STR2
5987 "Maximum number of prefixes to accept from this peer\n"
5988 "maximum no. of prefix limit\n"
5989 "Threshold value (%) at which to generate a warning msg\n"
5990 "Restart bgp connection after limit is exceeded\n"
5991 "Restart interval in minutes\n"
5992 "Only give warning message when limit is exceeded\n")
5993 {
5994 int idx_peer = 2;
5995 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5996 bgp_node_afi(vty),
5997 bgp_node_safi(vty));
5998 }
5999
6000 ALIAS_HIDDEN(
6001 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
6002 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6003 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6004 "Maximum number of prefixes to accept from this peer\n"
6005 "maximum no. of prefix limit\n"
6006 "Threshold value (%) at which to generate a warning msg\n"
6007 "Restart bgp connection after limit is exceeded\n"
6008 "Restart interval in minutes\n"
6009 "Only give warning message when limit is exceeded\n")
6010
6011
6012 /* "neighbor allowas-in" */
6013 DEFUN (neighbor_allowas_in,
6014 neighbor_allowas_in_cmd,
6015 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6016 NEIGHBOR_STR
6017 NEIGHBOR_ADDR_STR2
6018 "Accept as-path with my AS present in it\n"
6019 "Number of occurences of AS number\n"
6020 "Only accept my AS in the as-path if the route was originated in my AS\n")
6021 {
6022 int idx_peer = 1;
6023 int idx_number_origin = 3;
6024 int ret;
6025 int origin = 0;
6026 struct peer *peer;
6027 int allow_num = 0;
6028
6029 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6030 if (!peer)
6031 return CMD_WARNING_CONFIG_FAILED;
6032
6033 if (argc <= idx_number_origin)
6034 allow_num = 3;
6035 else {
6036 if (argv[idx_number_origin]->type == WORD_TKN)
6037 origin = 1;
6038 else
6039 allow_num = atoi(argv[idx_number_origin]->arg);
6040 }
6041
6042 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6043 allow_num, origin);
6044
6045 return bgp_vty_return(vty, ret);
6046 }
6047
6048 ALIAS_HIDDEN(
6049 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6050 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6051 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6052 "Accept as-path with my AS present in it\n"
6053 "Number of occurences of AS number\n"
6054 "Only accept my AS in the as-path if the route was originated in my AS\n")
6055
6056 DEFUN (no_neighbor_allowas_in,
6057 no_neighbor_allowas_in_cmd,
6058 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6059 NO_STR
6060 NEIGHBOR_STR
6061 NEIGHBOR_ADDR_STR2
6062 "allow local ASN appears in aspath attribute\n"
6063 "Number of occurences of AS number\n"
6064 "Only accept my AS in the as-path if the route was originated in my AS\n")
6065 {
6066 int idx_peer = 2;
6067 int ret;
6068 struct peer *peer;
6069
6070 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6071 if (!peer)
6072 return CMD_WARNING_CONFIG_FAILED;
6073
6074 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6075 bgp_node_safi(vty));
6076
6077 return bgp_vty_return(vty, ret);
6078 }
6079
6080 ALIAS_HIDDEN(
6081 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6082 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6083 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6084 "allow local ASN appears in aspath attribute\n"
6085 "Number of occurences of AS number\n"
6086 "Only accept my AS in the as-path if the route was originated in my AS\n")
6087
6088 DEFUN (neighbor_ttl_security,
6089 neighbor_ttl_security_cmd,
6090 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6091 NEIGHBOR_STR
6092 NEIGHBOR_ADDR_STR2
6093 "BGP ttl-security parameters\n"
6094 "Specify the maximum number of hops to the BGP peer\n"
6095 "Number of hops to BGP peer\n")
6096 {
6097 int idx_peer = 1;
6098 int idx_number = 4;
6099 struct peer *peer;
6100 int gtsm_hops;
6101
6102 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6103 if (!peer)
6104 return CMD_WARNING_CONFIG_FAILED;
6105
6106 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6107
6108 /*
6109 * If 'neighbor swpX', then this is for directly connected peers,
6110 * we should not accept a ttl-security hops value greater than 1.
6111 */
6112 if (peer->conf_if && (gtsm_hops > 1)) {
6113 vty_out(vty,
6114 "%s is directly connected peer, hops cannot exceed 1\n",
6115 argv[idx_peer]->arg);
6116 return CMD_WARNING_CONFIG_FAILED;
6117 }
6118
6119 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6120 }
6121
6122 DEFUN (no_neighbor_ttl_security,
6123 no_neighbor_ttl_security_cmd,
6124 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6125 NO_STR
6126 NEIGHBOR_STR
6127 NEIGHBOR_ADDR_STR2
6128 "BGP ttl-security parameters\n"
6129 "Specify the maximum number of hops to the BGP peer\n"
6130 "Number of hops to BGP peer\n")
6131 {
6132 int idx_peer = 2;
6133 struct peer *peer;
6134
6135 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6136 if (!peer)
6137 return CMD_WARNING_CONFIG_FAILED;
6138
6139 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6140 }
6141
6142 DEFUN (neighbor_addpath_tx_all_paths,
6143 neighbor_addpath_tx_all_paths_cmd,
6144 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6145 NEIGHBOR_STR
6146 NEIGHBOR_ADDR_STR2
6147 "Use addpath to advertise all paths to a neighbor\n")
6148 {
6149 int idx_peer = 1;
6150 struct peer *peer;
6151
6152 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6153 if (!peer)
6154 return CMD_WARNING_CONFIG_FAILED;
6155
6156 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6157 bgp_node_safi(vty),
6158 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6159 }
6160
6161 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6162 neighbor_addpath_tx_all_paths_hidden_cmd,
6163 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6164 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6165 "Use addpath to advertise all paths to a neighbor\n")
6166
6167 DEFUN (no_neighbor_addpath_tx_all_paths,
6168 no_neighbor_addpath_tx_all_paths_cmd,
6169 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6170 NO_STR
6171 NEIGHBOR_STR
6172 NEIGHBOR_ADDR_STR2
6173 "Use addpath to advertise all paths to a neighbor\n")
6174 {
6175 int idx_peer = 2;
6176 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6177 bgp_node_afi(vty), bgp_node_safi(vty),
6178 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6179 }
6180
6181 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6182 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6183 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6184 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6185 "Use addpath to advertise all paths to a neighbor\n")
6186
6187 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6188 neighbor_addpath_tx_bestpath_per_as_cmd,
6189 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6190 NEIGHBOR_STR
6191 NEIGHBOR_ADDR_STR2
6192 "Use addpath to advertise the bestpath per each neighboring AS\n")
6193 {
6194 int idx_peer = 1;
6195 struct peer *peer;
6196
6197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6198 if (!peer)
6199 return CMD_WARNING_CONFIG_FAILED;
6200
6201 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6202 bgp_node_safi(vty),
6203 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6204 }
6205
6206 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6207 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6208 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6209 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6210 "Use addpath to advertise the bestpath per each neighboring AS\n")
6211
6212 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6213 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6214 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6215 NO_STR
6216 NEIGHBOR_STR
6217 NEIGHBOR_ADDR_STR2
6218 "Use addpath to advertise the bestpath per each neighboring AS\n")
6219 {
6220 int idx_peer = 2;
6221 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6222 bgp_node_afi(vty), bgp_node_safi(vty),
6223 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6224 }
6225
6226 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6227 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6228 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6229 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6230 "Use addpath to advertise the bestpath per each neighboring AS\n")
6231
6232 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6233 struct ecommunity **list)
6234 {
6235 struct ecommunity *ecom = NULL;
6236 struct ecommunity *ecomadd;
6237
6238 for (; argc; --argc, ++argv) {
6239
6240 ecomadd = ecommunity_str2com(argv[0]->arg,
6241 ECOMMUNITY_ROUTE_TARGET, 0);
6242 if (!ecomadd) {
6243 vty_out(vty, "Malformed community-list value\n");
6244 if (ecom)
6245 ecommunity_free(&ecom);
6246 return CMD_WARNING_CONFIG_FAILED;
6247 }
6248
6249 if (ecom) {
6250 ecommunity_merge(ecom, ecomadd);
6251 ecommunity_free(&ecomadd);
6252 } else {
6253 ecom = ecomadd;
6254 }
6255 }
6256
6257 if (*list) {
6258 ecommunity_free(&*list);
6259 }
6260 *list = ecom;
6261
6262 return CMD_SUCCESS;
6263 }
6264
6265 /*
6266 * v2vimport is true if we are handling a `import vrf ...` command
6267 */
6268 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6269 {
6270 afi_t afi;
6271
6272 switch (vty->node) {
6273 case BGP_IPV4_NODE:
6274 afi = AFI_IP;
6275 break;
6276 case BGP_IPV6_NODE:
6277 afi = AFI_IP6;
6278 break;
6279 default:
6280 vty_out(vty,
6281 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6282 return AFI_MAX;
6283 }
6284
6285 if (!v2vimport) {
6286 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6287 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6288 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6289 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6290 vty_out(vty,
6291 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6292 return AFI_MAX;
6293 }
6294 } else {
6295 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6296 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6297 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6298 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6299 vty_out(vty,
6300 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6301 return AFI_MAX;
6302 }
6303 }
6304 return afi;
6305 }
6306
6307 DEFPY (af_rd_vpn_export,
6308 af_rd_vpn_export_cmd,
6309 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6310 NO_STR
6311 "Specify route distinguisher\n"
6312 "Between current address-family and vpn\n"
6313 "For routes leaked from current address-family to vpn\n"
6314 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6315 {
6316 VTY_DECLVAR_CONTEXT(bgp, bgp);
6317 struct prefix_rd prd;
6318 int ret;
6319 afi_t afi;
6320 int idx = 0;
6321 int yes = 1;
6322
6323 if (argv_find(argv, argc, "no", &idx))
6324 yes = 0;
6325
6326 if (yes) {
6327 ret = str2prefix_rd(rd_str, &prd);
6328 if (!ret) {
6329 vty_out(vty, "%% Malformed rd\n");
6330 return CMD_WARNING_CONFIG_FAILED;
6331 }
6332 }
6333
6334 afi = vpn_policy_getafi(vty, bgp, false);
6335 if (afi == AFI_MAX)
6336 return CMD_WARNING_CONFIG_FAILED;
6337
6338 /*
6339 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6340 */
6341 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6342 bgp_get_default(), bgp);
6343
6344 if (yes) {
6345 bgp->vpn_policy[afi].tovpn_rd = prd;
6346 SET_FLAG(bgp->vpn_policy[afi].flags,
6347 BGP_VPN_POLICY_TOVPN_RD_SET);
6348 } else {
6349 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6350 BGP_VPN_POLICY_TOVPN_RD_SET);
6351 }
6352
6353 /* post-change: re-export vpn routes */
6354 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6355 bgp_get_default(), bgp);
6356
6357 return CMD_SUCCESS;
6358 }
6359
6360 ALIAS (af_rd_vpn_export,
6361 af_no_rd_vpn_export_cmd,
6362 "no rd vpn export",
6363 NO_STR
6364 "Specify route distinguisher\n"
6365 "Between current address-family and vpn\n"
6366 "For routes leaked from current address-family to vpn\n")
6367
6368 DEFPY (af_label_vpn_export,
6369 af_label_vpn_export_cmd,
6370 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6371 NO_STR
6372 "label value for VRF\n"
6373 "Between current address-family and vpn\n"
6374 "For routes leaked from current address-family to vpn\n"
6375 "Label Value <0-1048575>\n"
6376 "Automatically assign a label\n")
6377 {
6378 VTY_DECLVAR_CONTEXT(bgp, bgp);
6379 mpls_label_t label = MPLS_LABEL_NONE;
6380 afi_t afi;
6381 int idx = 0;
6382 int yes = 1;
6383
6384 if (argv_find(argv, argc, "no", &idx))
6385 yes = 0;
6386
6387 /* If "no ...", squash trailing parameter */
6388 if (!yes)
6389 label_auto = NULL;
6390
6391 if (yes) {
6392 if (!label_auto)
6393 label = label_val; /* parser should force unsigned */
6394 }
6395
6396 afi = vpn_policy_getafi(vty, bgp, false);
6397 if (afi == AFI_MAX)
6398 return CMD_WARNING_CONFIG_FAILED;
6399
6400
6401 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6402 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6403 /* no change */
6404 return CMD_SUCCESS;
6405
6406 /*
6407 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6408 */
6409 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6410 bgp_get_default(), bgp);
6411
6412 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6413 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6414
6415 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6416
6417 /*
6418 * label has previously been automatically
6419 * assigned by labelpool: release it
6420 *
6421 * NB if tovpn_label == MPLS_LABEL_NONE it
6422 * means the automatic assignment is in flight
6423 * and therefore the labelpool callback must
6424 * detect that the auto label is not needed.
6425 */
6426
6427 bgp_lp_release(LP_TYPE_VRF,
6428 &bgp->vpn_policy[afi],
6429 bgp->vpn_policy[afi].tovpn_label);
6430 }
6431 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6432 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6433 }
6434
6435 bgp->vpn_policy[afi].tovpn_label = label;
6436 if (label_auto) {
6437 SET_FLAG(bgp->vpn_policy[afi].flags,
6438 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6439 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6440 vpn_leak_label_callback);
6441 }
6442
6443 /* post-change: re-export vpn routes */
6444 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6445 bgp_get_default(), bgp);
6446
6447 return CMD_SUCCESS;
6448 }
6449
6450 ALIAS (af_label_vpn_export,
6451 af_no_label_vpn_export_cmd,
6452 "no label vpn export",
6453 NO_STR
6454 "label value for VRF\n"
6455 "Between current address-family and vpn\n"
6456 "For routes leaked from current address-family to vpn\n")
6457
6458 DEFPY (af_nexthop_vpn_export,
6459 af_nexthop_vpn_export_cmd,
6460 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6461 NO_STR
6462 "Specify next hop to use for VRF advertised prefixes\n"
6463 "Between current address-family and vpn\n"
6464 "For routes leaked from current address-family to vpn\n"
6465 "IPv4 prefix\n"
6466 "IPv6 prefix\n")
6467 {
6468 VTY_DECLVAR_CONTEXT(bgp, bgp);
6469 afi_t afi;
6470 struct prefix p;
6471 int idx = 0;
6472 int yes = 1;
6473
6474 if (argv_find(argv, argc, "no", &idx))
6475 yes = 0;
6476
6477 if (yes) {
6478 if (!sockunion2hostprefix(nexthop_str, &p))
6479 return CMD_WARNING_CONFIG_FAILED;
6480 }
6481
6482 afi = vpn_policy_getafi(vty, bgp, false);
6483 if (afi == AFI_MAX)
6484 return CMD_WARNING_CONFIG_FAILED;
6485
6486 /*
6487 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6488 */
6489 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6490 bgp_get_default(), bgp);
6491
6492 if (yes) {
6493 bgp->vpn_policy[afi].tovpn_nexthop = p;
6494 SET_FLAG(bgp->vpn_policy[afi].flags,
6495 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6496 } else {
6497 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6498 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6499 }
6500
6501 /* post-change: re-export vpn routes */
6502 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6503 bgp_get_default(), bgp);
6504
6505 return CMD_SUCCESS;
6506 }
6507
6508 ALIAS (af_nexthop_vpn_export,
6509 af_no_nexthop_vpn_export_cmd,
6510 "no nexthop vpn export",
6511 NO_STR
6512 "Specify next hop to use for VRF advertised prefixes\n"
6513 "Between current address-family and vpn\n"
6514 "For routes leaked from current address-family to vpn\n")
6515
6516 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6517 {
6518 if (!strcmp(dstr, "import")) {
6519 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6520 } else if (!strcmp(dstr, "export")) {
6521 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6522 } else if (!strcmp(dstr, "both")) {
6523 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6524 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6525 } else {
6526 vty_out(vty, "%% direction parse error\n");
6527 return CMD_WARNING_CONFIG_FAILED;
6528 }
6529 return CMD_SUCCESS;
6530 }
6531
6532 DEFPY (af_rt_vpn_imexport,
6533 af_rt_vpn_imexport_cmd,
6534 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6535 NO_STR
6536 "Specify route target list\n"
6537 "Specify route target list\n"
6538 "Between current address-family and vpn\n"
6539 "For routes leaked from vpn to current address-family: match any\n"
6540 "For routes leaked from current address-family to vpn: set\n"
6541 "both import: match any and export: set\n"
6542 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6543 {
6544 VTY_DECLVAR_CONTEXT(bgp, bgp);
6545 int ret;
6546 struct ecommunity *ecom = NULL;
6547 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6548 vpn_policy_direction_t dir;
6549 afi_t afi;
6550 int idx = 0;
6551 int yes = 1;
6552
6553 if (argv_find(argv, argc, "no", &idx))
6554 yes = 0;
6555
6556 afi = vpn_policy_getafi(vty, bgp, false);
6557 if (afi == AFI_MAX)
6558 return CMD_WARNING_CONFIG_FAILED;
6559
6560 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6561 if (ret != CMD_SUCCESS)
6562 return ret;
6563
6564 if (yes) {
6565 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6566 vty_out(vty, "%% Missing RTLIST\n");
6567 return CMD_WARNING_CONFIG_FAILED;
6568 }
6569 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6570 if (ret != CMD_SUCCESS) {
6571 return ret;
6572 }
6573 }
6574
6575 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6576 if (!dodir[dir])
6577 continue;
6578
6579 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6580
6581 if (yes) {
6582 if (bgp->vpn_policy[afi].rtlist[dir])
6583 ecommunity_free(
6584 &bgp->vpn_policy[afi].rtlist[dir]);
6585 bgp->vpn_policy[afi].rtlist[dir] =
6586 ecommunity_dup(ecom);
6587 } else {
6588 if (bgp->vpn_policy[afi].rtlist[dir])
6589 ecommunity_free(
6590 &bgp->vpn_policy[afi].rtlist[dir]);
6591 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6592 }
6593
6594 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6595 }
6596
6597 if (ecom)
6598 ecommunity_free(&ecom);
6599
6600 return CMD_SUCCESS;
6601 }
6602
6603 ALIAS (af_rt_vpn_imexport,
6604 af_no_rt_vpn_imexport_cmd,
6605 "no <rt|route-target> vpn <import|export|both>$direction_str",
6606 NO_STR
6607 "Specify route target list\n"
6608 "Specify route target list\n"
6609 "Between current address-family and vpn\n"
6610 "For routes leaked from vpn to current address-family\n"
6611 "For routes leaked from current address-family to vpn\n"
6612 "both import and export\n")
6613
6614 DEFPY (af_route_map_vpn_imexport,
6615 af_route_map_vpn_imexport_cmd,
6616 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6617 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6618 NO_STR
6619 "Specify route map\n"
6620 "Between current address-family and vpn\n"
6621 "For routes leaked from vpn to current address-family\n"
6622 "For routes leaked from current address-family to vpn\n"
6623 "name of route-map\n")
6624 {
6625 VTY_DECLVAR_CONTEXT(bgp, bgp);
6626 int ret;
6627 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6628 vpn_policy_direction_t dir;
6629 afi_t afi;
6630 int idx = 0;
6631 int yes = 1;
6632
6633 if (argv_find(argv, argc, "no", &idx))
6634 yes = 0;
6635
6636 afi = vpn_policy_getafi(vty, bgp, false);
6637 if (afi == AFI_MAX)
6638 return CMD_WARNING_CONFIG_FAILED;
6639
6640 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6641 if (ret != CMD_SUCCESS)
6642 return ret;
6643
6644 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6645 if (!dodir[dir])
6646 continue;
6647
6648 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6649
6650 if (yes) {
6651 if (bgp->vpn_policy[afi].rmap_name[dir])
6652 XFREE(MTYPE_ROUTE_MAP_NAME,
6653 bgp->vpn_policy[afi].rmap_name[dir]);
6654 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6655 MTYPE_ROUTE_MAP_NAME, rmap_str);
6656 bgp->vpn_policy[afi].rmap[dir] =
6657 route_map_lookup_warn_noexist(vty, rmap_str);
6658 if (!bgp->vpn_policy[afi].rmap[dir])
6659 return CMD_SUCCESS;
6660 } else {
6661 if (bgp->vpn_policy[afi].rmap_name[dir])
6662 XFREE(MTYPE_ROUTE_MAP_NAME,
6663 bgp->vpn_policy[afi].rmap_name[dir]);
6664 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6665 bgp->vpn_policy[afi].rmap[dir] = NULL;
6666 }
6667
6668 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6669 }
6670
6671 return CMD_SUCCESS;
6672 }
6673
6674 ALIAS (af_route_map_vpn_imexport,
6675 af_no_route_map_vpn_imexport_cmd,
6676 "no route-map vpn <import|export>$direction_str",
6677 NO_STR
6678 "Specify route map\n"
6679 "Between current address-family and vpn\n"
6680 "For routes leaked from vpn to current address-family\n"
6681 "For routes leaked from current address-family to vpn\n")
6682
6683 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6684 "[no] import vrf route-map RMAP$rmap_str",
6685 NO_STR
6686 "Import routes from another VRF\n"
6687 "Vrf routes being filtered\n"
6688 "Specify route map\n"
6689 "name of route-map\n")
6690 {
6691 VTY_DECLVAR_CONTEXT(bgp, bgp);
6692 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6693 afi_t afi;
6694 int idx = 0;
6695 int yes = 1;
6696 struct bgp *bgp_default;
6697
6698 if (argv_find(argv, argc, "no", &idx))
6699 yes = 0;
6700
6701 afi = vpn_policy_getafi(vty, bgp, true);
6702 if (afi == AFI_MAX)
6703 return CMD_WARNING_CONFIG_FAILED;
6704
6705 bgp_default = bgp_get_default();
6706 if (!bgp_default) {
6707 int32_t ret;
6708 as_t as = bgp->as;
6709
6710 /* Auto-create assuming the same AS */
6711 ret = bgp_get(&bgp_default, &as, NULL,
6712 BGP_INSTANCE_TYPE_DEFAULT);
6713
6714 if (ret) {
6715 vty_out(vty,
6716 "VRF default is not configured as a bgp instance\n");
6717 return CMD_WARNING;
6718 }
6719 }
6720
6721 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6722
6723 if (yes) {
6724 if (bgp->vpn_policy[afi].rmap_name[dir])
6725 XFREE(MTYPE_ROUTE_MAP_NAME,
6726 bgp->vpn_policy[afi].rmap_name[dir]);
6727 bgp->vpn_policy[afi].rmap_name[dir] =
6728 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6729 bgp->vpn_policy[afi].rmap[dir] =
6730 route_map_lookup_warn_noexist(vty, rmap_str);
6731 if (!bgp->vpn_policy[afi].rmap[dir])
6732 return CMD_SUCCESS;
6733 } else {
6734 if (bgp->vpn_policy[afi].rmap_name[dir])
6735 XFREE(MTYPE_ROUTE_MAP_NAME,
6736 bgp->vpn_policy[afi].rmap_name[dir]);
6737 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6738 bgp->vpn_policy[afi].rmap[dir] = NULL;
6739 }
6740
6741 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6742
6743 return CMD_SUCCESS;
6744 }
6745
6746 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6747 "no import vrf route-map",
6748 NO_STR
6749 "Import routes from another VRF\n"
6750 "Vrf routes being filtered\n"
6751 "Specify route map\n")
6752
6753 DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
6754 "[no] import vrf VIEWVRFNAME$import_name",
6755 NO_STR
6756 "Import routes from another VRF\n"
6757 "VRF to import from\n"
6758 "The name of the VRF\n")
6759 {
6760 VTY_DECLVAR_CONTEXT(bgp, bgp);
6761 struct listnode *node;
6762 struct bgp *vrf_bgp, *bgp_default;
6763 int32_t ret = 0;
6764 as_t as = bgp->as;
6765 bool remove = false;
6766 int32_t idx = 0;
6767 char *vname;
6768 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6769 safi_t safi;
6770 afi_t afi;
6771
6772 if (import_name == NULL) {
6773 vty_out(vty, "%% Missing import name\n");
6774 return CMD_WARNING;
6775 }
6776
6777 if (argv_find(argv, argc, "no", &idx))
6778 remove = true;
6779
6780 afi = vpn_policy_getafi(vty, bgp, true);
6781 if (afi == AFI_MAX)
6782 return CMD_WARNING_CONFIG_FAILED;
6783
6784 safi = bgp_node_safi(vty);
6785
6786 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6787 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6788 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6789 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6790 remove ? "unimport" : "import", import_name);
6791 return CMD_WARNING;
6792 }
6793
6794 bgp_default = bgp_get_default();
6795 if (!bgp_default) {
6796 /* Auto-create assuming the same AS */
6797 ret = bgp_get(&bgp_default, &as, NULL,
6798 BGP_INSTANCE_TYPE_DEFAULT);
6799
6800 if (ret) {
6801 vty_out(vty,
6802 "VRF default is not configured as a bgp instance\n");
6803 return CMD_WARNING;
6804 }
6805 }
6806
6807 vrf_bgp = bgp_lookup_by_name(import_name);
6808 if (!vrf_bgp) {
6809 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6810 vrf_bgp = bgp_default;
6811 else
6812 /* Auto-create assuming the same AS */
6813 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6814
6815 if (ret) {
6816 vty_out(vty,
6817 "VRF %s is not configured as a bgp instance\n",
6818 import_name);
6819 return CMD_WARNING;
6820 }
6821 }
6822
6823 if (remove) {
6824 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6825 } else {
6826 /* Already importing from "import_vrf"? */
6827 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6828 vname)) {
6829 if (strcmp(vname, import_name) == 0)
6830 return CMD_WARNING;
6831 }
6832
6833 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6834 }
6835
6836 return CMD_SUCCESS;
6837 }
6838
6839 /* This command is valid only in a bgp vrf instance or the default instance */
6840 DEFPY (bgp_imexport_vpn,
6841 bgp_imexport_vpn_cmd,
6842 "[no] <import|export>$direction_str vpn",
6843 NO_STR
6844 "Import routes to this address-family\n"
6845 "Export routes from this address-family\n"
6846 "to/from default instance VPN RIB\n")
6847 {
6848 VTY_DECLVAR_CONTEXT(bgp, bgp);
6849 int previous_state;
6850 afi_t afi;
6851 safi_t safi;
6852 int idx = 0;
6853 int yes = 1;
6854 int flag;
6855 vpn_policy_direction_t dir;
6856
6857 if (argv_find(argv, argc, "no", &idx))
6858 yes = 0;
6859
6860 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6861 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6862
6863 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6864 return CMD_WARNING_CONFIG_FAILED;
6865 }
6866
6867 afi = bgp_node_afi(vty);
6868 safi = bgp_node_safi(vty);
6869 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6870 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6871 return CMD_WARNING_CONFIG_FAILED;
6872 }
6873
6874 if (!strcmp(direction_str, "import")) {
6875 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6876 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6877 } else if (!strcmp(direction_str, "export")) {
6878 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6879 dir = BGP_VPN_POLICY_DIR_TOVPN;
6880 } else {
6881 vty_out(vty, "%% unknown direction %s\n", direction_str);
6882 return CMD_WARNING_CONFIG_FAILED;
6883 }
6884
6885 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6886
6887 if (yes) {
6888 SET_FLAG(bgp->af_flags[afi][safi], flag);
6889 if (!previous_state) {
6890 /* trigger export current vrf */
6891 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6892 }
6893 } else {
6894 if (previous_state) {
6895 /* trigger un-export current vrf */
6896 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6897 }
6898 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6899 }
6900
6901 return CMD_SUCCESS;
6902 }
6903
6904 DEFPY (af_routetarget_import,
6905 af_routetarget_import_cmd,
6906 "[no] <rt|route-target> redirect import RTLIST...",
6907 NO_STR
6908 "Specify route target list\n"
6909 "Specify route target list\n"
6910 "Flow-spec redirect type route target\n"
6911 "Import routes to this address-family\n"
6912 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6913 {
6914 VTY_DECLVAR_CONTEXT(bgp, bgp);
6915 int ret;
6916 struct ecommunity *ecom = NULL;
6917 afi_t afi;
6918 int idx = 0;
6919 int yes = 1;
6920
6921 if (argv_find(argv, argc, "no", &idx))
6922 yes = 0;
6923
6924 afi = vpn_policy_getafi(vty, bgp, false);
6925 if (afi == AFI_MAX)
6926 return CMD_WARNING_CONFIG_FAILED;
6927
6928 if (yes) {
6929 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6930 vty_out(vty, "%% Missing RTLIST\n");
6931 return CMD_WARNING_CONFIG_FAILED;
6932 }
6933 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6934 if (ret != CMD_SUCCESS)
6935 return ret;
6936 }
6937
6938 if (yes) {
6939 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6940 ecommunity_free(&bgp->vpn_policy[afi]
6941 .import_redirect_rtlist);
6942 bgp->vpn_policy[afi].import_redirect_rtlist =
6943 ecommunity_dup(ecom);
6944 } else {
6945 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6946 ecommunity_free(&bgp->vpn_policy[afi]
6947 .import_redirect_rtlist);
6948 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6949 }
6950
6951 if (ecom)
6952 ecommunity_free(&ecom);
6953
6954 return CMD_SUCCESS;
6955 }
6956
6957 DEFUN_NOSH (address_family_ipv4_safi,
6958 address_family_ipv4_safi_cmd,
6959 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6960 "Enter Address Family command mode\n"
6961 "Address Family\n"
6962 BGP_SAFI_WITH_LABEL_HELP_STR)
6963 {
6964
6965 if (argc == 3) {
6966 VTY_DECLVAR_CONTEXT(bgp, bgp);
6967 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6968 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6969 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6970 && safi != SAFI_EVPN) {
6971 vty_out(vty,
6972 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6973 return CMD_WARNING_CONFIG_FAILED;
6974 }
6975 vty->node = bgp_node_type(AFI_IP, safi);
6976 } else
6977 vty->node = BGP_IPV4_NODE;
6978
6979 return CMD_SUCCESS;
6980 }
6981
6982 DEFUN_NOSH (address_family_ipv6_safi,
6983 address_family_ipv6_safi_cmd,
6984 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6985 "Enter Address Family command mode\n"
6986 "Address Family\n"
6987 BGP_SAFI_WITH_LABEL_HELP_STR)
6988 {
6989 if (argc == 3) {
6990 VTY_DECLVAR_CONTEXT(bgp, bgp);
6991 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6992 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6993 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6994 && safi != SAFI_EVPN) {
6995 vty_out(vty,
6996 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6997 return CMD_WARNING_CONFIG_FAILED;
6998 }
6999 vty->node = bgp_node_type(AFI_IP6, safi);
7000 } else
7001 vty->node = BGP_IPV6_NODE;
7002
7003 return CMD_SUCCESS;
7004 }
7005
7006 #ifdef KEEP_OLD_VPN_COMMANDS
7007 DEFUN_NOSH (address_family_vpnv4,
7008 address_family_vpnv4_cmd,
7009 "address-family vpnv4 [unicast]",
7010 "Enter Address Family command mode\n"
7011 "Address Family\n"
7012 "Address Family modifier\n")
7013 {
7014 vty->node = BGP_VPNV4_NODE;
7015 return CMD_SUCCESS;
7016 }
7017
7018 DEFUN_NOSH (address_family_vpnv6,
7019 address_family_vpnv6_cmd,
7020 "address-family vpnv6 [unicast]",
7021 "Enter Address Family command mode\n"
7022 "Address Family\n"
7023 "Address Family modifier\n")
7024 {
7025 vty->node = BGP_VPNV6_NODE;
7026 return CMD_SUCCESS;
7027 }
7028 #endif
7029
7030 DEFUN_NOSH (address_family_evpn,
7031 address_family_evpn_cmd,
7032 "address-family l2vpn evpn",
7033 "Enter Address Family command mode\n"
7034 "Address Family\n"
7035 "Address Family modifier\n")
7036 {
7037 VTY_DECLVAR_CONTEXT(bgp, bgp);
7038 vty->node = BGP_EVPN_NODE;
7039 return CMD_SUCCESS;
7040 }
7041
7042 DEFUN_NOSH (exit_address_family,
7043 exit_address_family_cmd,
7044 "exit-address-family",
7045 "Exit from Address Family configuration mode\n")
7046 {
7047 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7048 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7049 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7050 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7051 || vty->node == BGP_EVPN_NODE
7052 || vty->node == BGP_FLOWSPECV4_NODE
7053 || vty->node == BGP_FLOWSPECV6_NODE)
7054 vty->node = BGP_NODE;
7055 return CMD_SUCCESS;
7056 }
7057
7058 /* Recalculate bestpath and re-advertise a prefix */
7059 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7060 const char *ip_str, afi_t afi, safi_t safi,
7061 struct prefix_rd *prd)
7062 {
7063 int ret;
7064 struct prefix match;
7065 struct bgp_node *rn;
7066 struct bgp_node *rm;
7067 struct bgp *bgp;
7068 struct bgp_table *table;
7069 struct bgp_table *rib;
7070
7071 /* BGP structure lookup. */
7072 if (view_name) {
7073 bgp = bgp_lookup_by_name(view_name);
7074 if (bgp == NULL) {
7075 vty_out(vty, "%% Can't find BGP instance %s\n",
7076 view_name);
7077 return CMD_WARNING;
7078 }
7079 } else {
7080 bgp = bgp_get_default();
7081 if (bgp == NULL) {
7082 vty_out(vty, "%% No BGP process is configured\n");
7083 return CMD_WARNING;
7084 }
7085 }
7086
7087 /* Check IP address argument. */
7088 ret = str2prefix(ip_str, &match);
7089 if (!ret) {
7090 vty_out(vty, "%% address is malformed\n");
7091 return CMD_WARNING;
7092 }
7093
7094 match.family = afi2family(afi);
7095 rib = bgp->rib[afi][safi];
7096
7097 if (safi == SAFI_MPLS_VPN) {
7098 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7099 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7100 continue;
7101
7102 if ((table = rn->info) != NULL) {
7103 if ((rm = bgp_node_match(table, &match))
7104 != NULL) {
7105 if (rm->p.prefixlen
7106 == match.prefixlen) {
7107 SET_FLAG(rm->flags,
7108 BGP_NODE_USER_CLEAR);
7109 bgp_process(bgp, rm, afi, safi);
7110 }
7111 bgp_unlock_node(rm);
7112 }
7113 }
7114 }
7115 } else {
7116 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7117 if (rn->p.prefixlen == match.prefixlen) {
7118 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7119 bgp_process(bgp, rn, afi, safi);
7120 }
7121 bgp_unlock_node(rn);
7122 }
7123 }
7124
7125 return CMD_SUCCESS;
7126 }
7127
7128 /* one clear bgp command to rule them all */
7129 DEFUN (clear_ip_bgp_all,
7130 clear_ip_bgp_all_cmd,
7131 "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>]",
7132 CLEAR_STR
7133 IP_STR
7134 BGP_STR
7135 BGP_INSTANCE_HELP_STR
7136 BGP_AFI_HELP_STR
7137 BGP_SAFI_WITH_LABEL_HELP_STR
7138 "Clear all peers\n"
7139 "BGP neighbor address to clear\n"
7140 "BGP IPv6 neighbor to clear\n"
7141 "BGP neighbor on interface to clear\n"
7142 "Clear peers with the AS number\n"
7143 "Clear all external peers\n"
7144 "Clear all members of peer-group\n"
7145 "BGP peer-group name\n"
7146 BGP_SOFT_STR
7147 BGP_SOFT_IN_STR
7148 BGP_SOFT_OUT_STR
7149 BGP_SOFT_IN_STR
7150 "Push out prefix-list ORF and do inbound soft reconfig\n"
7151 BGP_SOFT_OUT_STR)
7152 {
7153 char *vrf = NULL;
7154
7155 afi_t afi = AFI_IP6;
7156 safi_t safi = SAFI_UNICAST;
7157 enum clear_sort clr_sort = clear_peer;
7158 enum bgp_clear_type clr_type;
7159 char *clr_arg = NULL;
7160
7161 int idx = 0;
7162
7163 /* clear [ip] bgp */
7164 if (argv_find(argv, argc, "ip", &idx))
7165 afi = AFI_IP;
7166
7167 /* [<vrf> VIEWVRFNAME] */
7168 if (argv_find(argv, argc, "vrf", &idx)) {
7169 vrf = argv[idx + 1]->arg;
7170 idx += 2;
7171 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7172 vrf = NULL;
7173 } else if (argv_find(argv, argc, "view", &idx)) {
7174 /* [<view> VIEWVRFNAME] */
7175 vrf = argv[idx + 1]->arg;
7176 idx += 2;
7177 }
7178 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7179 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7180 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7181
7182 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7183 if (argv_find(argv, argc, "*", &idx)) {
7184 clr_sort = clear_all;
7185 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7186 clr_sort = clear_peer;
7187 clr_arg = argv[idx]->arg;
7188 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7189 clr_sort = clear_peer;
7190 clr_arg = argv[idx]->arg;
7191 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7192 clr_sort = clear_group;
7193 idx++;
7194 clr_arg = argv[idx]->arg;
7195 } else if (argv_find(argv, argc, "WORD", &idx)) {
7196 clr_sort = clear_peer;
7197 clr_arg = argv[idx]->arg;
7198 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7199 clr_sort = clear_as;
7200 clr_arg = argv[idx]->arg;
7201 } else if (argv_find(argv, argc, "external", &idx)) {
7202 clr_sort = clear_external;
7203 }
7204
7205 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7206 if (argv_find(argv, argc, "soft", &idx)) {
7207 if (argv_find(argv, argc, "in", &idx)
7208 || argv_find(argv, argc, "out", &idx))
7209 clr_type = strmatch(argv[idx]->text, "in")
7210 ? BGP_CLEAR_SOFT_IN
7211 : BGP_CLEAR_SOFT_OUT;
7212 else
7213 clr_type = BGP_CLEAR_SOFT_BOTH;
7214 } else if (argv_find(argv, argc, "in", &idx)) {
7215 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7216 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7217 : BGP_CLEAR_SOFT_IN;
7218 } else if (argv_find(argv, argc, "out", &idx)) {
7219 clr_type = BGP_CLEAR_SOFT_OUT;
7220 } else
7221 clr_type = BGP_CLEAR_SOFT_NONE;
7222
7223 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7224 }
7225
7226 DEFUN (clear_ip_bgp_prefix,
7227 clear_ip_bgp_prefix_cmd,
7228 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7229 CLEAR_STR
7230 IP_STR
7231 BGP_STR
7232 BGP_INSTANCE_HELP_STR
7233 "Clear bestpath and re-advertise\n"
7234 "IPv4 prefix\n")
7235 {
7236 char *vrf = NULL;
7237 char *prefix = NULL;
7238
7239 int idx = 0;
7240
7241 /* [<view|vrf> VIEWVRFNAME] */
7242 if (argv_find(argv, argc, "vrf", &idx)) {
7243 vrf = argv[idx + 1]->arg;
7244 idx += 2;
7245 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7246 vrf = NULL;
7247 } else if (argv_find(argv, argc, "view", &idx)) {
7248 /* [<view> VIEWVRFNAME] */
7249 vrf = argv[idx + 1]->arg;
7250 idx += 2;
7251 }
7252
7253 prefix = argv[argc - 1]->arg;
7254
7255 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7256 }
7257
7258 DEFUN (clear_bgp_ipv6_safi_prefix,
7259 clear_bgp_ipv6_safi_prefix_cmd,
7260 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7261 CLEAR_STR
7262 IP_STR
7263 BGP_STR
7264 "Address Family\n"
7265 BGP_SAFI_HELP_STR
7266 "Clear bestpath and re-advertise\n"
7267 "IPv6 prefix\n")
7268 {
7269 int idx_safi = 0;
7270 int idx_ipv6_prefix = 0;
7271 safi_t safi = SAFI_UNICAST;
7272 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7273 argv[idx_ipv6_prefix]->arg : NULL;
7274
7275 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7276 return bgp_clear_prefix(
7277 vty, NULL, prefix, AFI_IP6,
7278 safi, NULL);
7279 }
7280
7281 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7282 clear_bgp_instance_ipv6_safi_prefix_cmd,
7283 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7284 CLEAR_STR
7285 IP_STR
7286 BGP_STR
7287 BGP_INSTANCE_HELP_STR
7288 "Address Family\n"
7289 BGP_SAFI_HELP_STR
7290 "Clear bestpath and re-advertise\n"
7291 "IPv6 prefix\n")
7292 {
7293 int idx_safi = 0;
7294 int idx_vrfview = 0;
7295 int idx_ipv6_prefix = 0;
7296 safi_t safi = SAFI_UNICAST;
7297 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7298 argv[idx_ipv6_prefix]->arg : NULL;
7299 char *vrfview = NULL;
7300
7301 /* [<view|vrf> VIEWVRFNAME] */
7302 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7303 vrfview = argv[idx_vrfview + 1]->arg;
7304 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7305 vrfview = NULL;
7306 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7307 /* [<view> VIEWVRFNAME] */
7308 vrfview = argv[idx_vrfview + 1]->arg;
7309 }
7310 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7311
7312 return bgp_clear_prefix(
7313 vty, vrfview, prefix,
7314 AFI_IP6, safi, NULL);
7315 }
7316
7317 DEFUN (show_bgp_views,
7318 show_bgp_views_cmd,
7319 "show [ip] bgp views",
7320 SHOW_STR
7321 IP_STR
7322 BGP_STR
7323 "Show the defined BGP views\n")
7324 {
7325 struct list *inst = bm->bgp;
7326 struct listnode *node;
7327 struct bgp *bgp;
7328
7329 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7330 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7331 return CMD_WARNING;
7332 }
7333
7334 vty_out(vty, "Defined BGP views:\n");
7335 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7336 /* Skip VRFs. */
7337 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7338 continue;
7339 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7340 bgp->as);
7341 }
7342
7343 return CMD_SUCCESS;
7344 }
7345
7346 DEFUN (show_bgp_vrfs,
7347 show_bgp_vrfs_cmd,
7348 "show [ip] bgp vrfs [json]",
7349 SHOW_STR
7350 IP_STR
7351 BGP_STR
7352 "Show BGP VRFs\n"
7353 JSON_STR)
7354 {
7355 char buf[ETHER_ADDR_STRLEN];
7356 struct list *inst = bm->bgp;
7357 struct listnode *node;
7358 struct bgp *bgp;
7359 bool uj = use_json(argc, argv);
7360 json_object *json = NULL;
7361 json_object *json_vrfs = NULL;
7362 int count = 0;
7363
7364 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7365 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7366 return CMD_WARNING;
7367 }
7368
7369 if (uj) {
7370 json = json_object_new_object();
7371 json_vrfs = json_object_new_object();
7372 }
7373
7374 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7375 const char *name, *type;
7376 struct peer *peer;
7377 struct listnode *node2, *nnode2;
7378 int peers_cfg, peers_estb;
7379 json_object *json_vrf = NULL;
7380
7381 /* Skip Views. */
7382 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7383 continue;
7384
7385 count++;
7386 if (!uj && count == 1)
7387 vty_out(vty,
7388 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7389 "Type", "Id", "routerId", "#PeersVfg",
7390 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7391
7392 peers_cfg = peers_estb = 0;
7393 if (uj)
7394 json_vrf = json_object_new_object();
7395
7396
7397 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7398 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7399 continue;
7400 peers_cfg++;
7401 if (peer->status == Established)
7402 peers_estb++;
7403 }
7404
7405 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7406 name = "Default";
7407 type = "DFLT";
7408 } else {
7409 name = bgp->name;
7410 type = "VRF";
7411 }
7412
7413
7414 if (uj) {
7415 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7416 ? -1
7417 : (int64_t)bgp->vrf_id;
7418 json_object_string_add(json_vrf, "type", type);
7419 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7420 json_object_string_add(json_vrf, "routerId",
7421 inet_ntoa(bgp->router_id));
7422 json_object_int_add(json_vrf, "numConfiguredPeers",
7423 peers_cfg);
7424 json_object_int_add(json_vrf, "numEstablishedPeers",
7425 peers_estb);
7426
7427 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7428 json_object_string_add(
7429 json_vrf, "rmac",
7430 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7431 json_object_object_add(json_vrfs, name, json_vrf);
7432 } else
7433 vty_out(vty,
7434 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7435 type,
7436 bgp->vrf_id == VRF_UNKNOWN ? -1
7437 : (int)bgp->vrf_id,
7438 inet_ntoa(bgp->router_id), peers_cfg,
7439 peers_estb, name, bgp->l3vni,
7440 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7441 }
7442
7443 if (uj) {
7444 json_object_object_add(json, "vrfs", json_vrfs);
7445
7446 json_object_int_add(json, "totalVrfs", count);
7447
7448 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7449 json, JSON_C_TO_STRING_PRETTY));
7450 json_object_free(json);
7451 } else {
7452 if (count)
7453 vty_out(vty,
7454 "\nTotal number of VRFs (including default): %d\n",
7455 count);
7456 }
7457
7458 return CMD_SUCCESS;
7459 }
7460
7461
7462 static void show_tip_entry(struct hash_backet *backet, void *args)
7463 {
7464 struct vty *vty = (struct vty *)args;
7465 struct tip_addr *tip = (struct tip_addr *)backet->data;
7466
7467 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7468 tip->refcnt);
7469 }
7470
7471 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7472 {
7473 vty_out(vty, "self nexthop database:\n");
7474 bgp_nexthop_show_address_hash(vty, bgp);
7475
7476 vty_out(vty, "Tunnel-ip database:\n");
7477 hash_iterate(bgp->tip_hash,
7478 (void (*)(struct hash_backet *, void *))show_tip_entry,
7479 vty);
7480 }
7481
7482 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7483 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7484 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7485 "martian next-hops\n"
7486 "martian next-hop database\n")
7487 {
7488 struct bgp *bgp = NULL;
7489 int idx = 0;
7490 char *name = NULL;
7491
7492 /* [<vrf> VIEWVRFNAME] */
7493 if (argv_find(argv, argc, "vrf", &idx)) {
7494 name = argv[idx + 1]->arg;
7495 if (name && strmatch(name, VRF_DEFAULT_NAME))
7496 name = NULL;
7497 } else if (argv_find(argv, argc, "view", &idx))
7498 /* [<view> VIEWVRFNAME] */
7499 name = argv[idx + 1]->arg;
7500 if (name)
7501 bgp = bgp_lookup_by_name(name);
7502 else
7503 bgp = bgp_get_default();
7504
7505 if (!bgp) {
7506 vty_out(vty, "%% No BGP process is configured\n");
7507 return CMD_WARNING;
7508 }
7509 bgp_show_martian_nexthops(vty, bgp);
7510
7511 return CMD_SUCCESS;
7512 }
7513
7514 DEFUN (show_bgp_memory,
7515 show_bgp_memory_cmd,
7516 "show [ip] bgp memory",
7517 SHOW_STR
7518 IP_STR
7519 BGP_STR
7520 "Global BGP memory statistics\n")
7521 {
7522 char memstrbuf[MTYPE_MEMSTR_LEN];
7523 unsigned long count;
7524
7525 /* RIB related usage stats */
7526 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7527 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7528 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7529 count * sizeof(struct bgp_node)));
7530
7531 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7532 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7533 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7534 count * sizeof(struct bgp_path_info)));
7535 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7536 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7537 count,
7538 mtype_memstr(
7539 memstrbuf, sizeof(memstrbuf),
7540 count * sizeof(struct bgp_path_info_extra)));
7541
7542 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7543 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7544 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7545 count * sizeof(struct bgp_static)));
7546
7547 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7548 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7549 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7550 count * sizeof(struct bpacket)));
7551
7552 /* Adj-In/Out */
7553 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7554 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7555 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7556 count * sizeof(struct bgp_adj_in)));
7557 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7558 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7559 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7560 count * sizeof(struct bgp_adj_out)));
7561
7562 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7563 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7564 count,
7565 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7566 count * sizeof(struct bgp_nexthop_cache)));
7567
7568 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7569 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7570 count,
7571 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7572 count * sizeof(struct bgp_damp_info)));
7573
7574 /* Attributes */
7575 count = attr_count();
7576 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7577 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7578 count * sizeof(struct attr)));
7579
7580 if ((count = attr_unknown_count()))
7581 vty_out(vty, "%ld unknown attributes\n", count);
7582
7583 /* AS_PATH attributes */
7584 count = aspath_count();
7585 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7586 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7587 count * sizeof(struct aspath)));
7588
7589 count = mtype_stats_alloc(MTYPE_AS_SEG);
7590 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7591 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7592 count * sizeof(struct assegment)));
7593
7594 /* Other attributes */
7595 if ((count = community_count()))
7596 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7597 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7598 count * sizeof(struct community)));
7599 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7600 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7601 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7602 count * sizeof(struct ecommunity)));
7603 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7604 vty_out(vty,
7605 "%ld BGP large-community entries, using %s of memory\n",
7606 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7607 count * sizeof(struct lcommunity)));
7608
7609 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7610 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7611 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7612 count * sizeof(struct cluster_list)));
7613
7614 /* Peer related usage */
7615 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7616 vty_out(vty, "%ld peers, using %s of memory\n", count,
7617 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7618 count * sizeof(struct peer)));
7619
7620 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7621 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7622 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7623 count * sizeof(struct peer_group)));
7624
7625 /* Other */
7626 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7627 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7628 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7629 count * sizeof(struct hash)));
7630 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7631 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7632 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7633 count * sizeof(struct hash_backet)));
7634 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7635 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7636 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7637 count * sizeof(regex_t)));
7638 return CMD_SUCCESS;
7639 }
7640
7641 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7642 {
7643 json_object *bestpath = json_object_new_object();
7644
7645 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7646 json_object_string_add(bestpath, "asPath", "ignore");
7647
7648 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7649 json_object_string_add(bestpath, "asPath", "confed");
7650
7651 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7652 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7653 json_object_string_add(bestpath, "multiPathRelax",
7654 "as-set");
7655 else
7656 json_object_string_add(bestpath, "multiPathRelax",
7657 "true");
7658 } else
7659 json_object_string_add(bestpath, "multiPathRelax", "false");
7660
7661 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7662 json_object_string_add(bestpath, "compareRouterId", "true");
7663 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7664 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7665 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7666 json_object_string_add(bestpath, "med", "confed");
7667 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7668 json_object_string_add(bestpath, "med",
7669 "missing-as-worst");
7670 else
7671 json_object_string_add(bestpath, "med", "true");
7672 }
7673
7674 json_object_object_add(json, "bestPath", bestpath);
7675 }
7676
7677 /* Show BGP peer's summary information. */
7678 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7679 bool use_json, json_object *json)
7680 {
7681 struct peer *peer;
7682 struct listnode *node, *nnode;
7683 unsigned int count = 0, dn_count = 0;
7684 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7685 char neighbor_buf[VTY_BUFSIZ];
7686 int neighbor_col_default_width = 16;
7687 int len;
7688 int max_neighbor_width = 0;
7689 int pfx_rcd_safi;
7690 json_object *json_peer = NULL;
7691 json_object *json_peers = NULL;
7692 struct peer_af *paf;
7693
7694 /* labeled-unicast routes are installed in the unicast table so in order
7695 * to
7696 * display the correct PfxRcd value we must look at SAFI_UNICAST
7697 */
7698 if (safi == SAFI_LABELED_UNICAST)
7699 pfx_rcd_safi = SAFI_UNICAST;
7700 else
7701 pfx_rcd_safi = safi;
7702
7703 if (use_json) {
7704 if (json == NULL)
7705 json = json_object_new_object();
7706
7707 json_peers = json_object_new_object();
7708 } else {
7709 /* Loop over all neighbors that will be displayed to determine
7710 * how many
7711 * characters are needed for the Neighbor column
7712 */
7713 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7714 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7715 continue;
7716
7717 if (peer->afc[afi][safi]) {
7718 memset(dn_flag, '\0', sizeof(dn_flag));
7719 if (peer_dynamic_neighbor(peer))
7720 dn_flag[0] = '*';
7721
7722 if (peer->hostname
7723 && bgp_flag_check(bgp,
7724 BGP_FLAG_SHOW_HOSTNAME))
7725 sprintf(neighbor_buf, "%s%s(%s) ",
7726 dn_flag, peer->hostname,
7727 peer->host);
7728 else
7729 sprintf(neighbor_buf, "%s%s ", dn_flag,
7730 peer->host);
7731
7732 len = strlen(neighbor_buf);
7733
7734 if (len > max_neighbor_width)
7735 max_neighbor_width = len;
7736 }
7737 }
7738
7739 /* Originally we displayed the Neighbor column as 16
7740 * characters wide so make that the default
7741 */
7742 if (max_neighbor_width < neighbor_col_default_width)
7743 max_neighbor_width = neighbor_col_default_width;
7744 }
7745
7746 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7747 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7748 continue;
7749
7750 if (!peer->afc[afi][safi])
7751 continue;
7752
7753 if (!count) {
7754 unsigned long ents;
7755 char memstrbuf[MTYPE_MEMSTR_LEN];
7756 int64_t vrf_id_ui;
7757
7758 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7759 ? -1
7760 : (int64_t)bgp->vrf_id;
7761
7762 /* Usage summary and header */
7763 if (use_json) {
7764 json_object_string_add(
7765 json, "routerId",
7766 inet_ntoa(bgp->router_id));
7767 json_object_int_add(json, "as", bgp->as);
7768 json_object_int_add(json, "vrfId", vrf_id_ui);
7769 json_object_string_add(
7770 json, "vrfName",
7771 (bgp->inst_type
7772 == BGP_INSTANCE_TYPE_DEFAULT)
7773 ? "Default"
7774 : bgp->name);
7775 } else {
7776 vty_out(vty,
7777 "BGP router identifier %s, local AS number %u vrf-id %d",
7778 inet_ntoa(bgp->router_id), bgp->as,
7779 bgp->vrf_id == VRF_UNKNOWN
7780 ? -1
7781 : (int)bgp->vrf_id);
7782 vty_out(vty, "\n");
7783 }
7784
7785 if (bgp_update_delay_configured(bgp)) {
7786 if (use_json) {
7787 json_object_int_add(
7788 json, "updateDelayLimit",
7789 bgp->v_update_delay);
7790
7791 if (bgp->v_update_delay
7792 != bgp->v_establish_wait)
7793 json_object_int_add(
7794 json,
7795 "updateDelayEstablishWait",
7796 bgp->v_establish_wait);
7797
7798 if (bgp_update_delay_active(bgp)) {
7799 json_object_string_add(
7800 json,
7801 "updateDelayFirstNeighbor",
7802 bgp->update_delay_begin_time);
7803 json_object_boolean_true_add(
7804 json,
7805 "updateDelayInProgress");
7806 } else {
7807 if (bgp->update_delay_over) {
7808 json_object_string_add(
7809 json,
7810 "updateDelayFirstNeighbor",
7811 bgp->update_delay_begin_time);
7812 json_object_string_add(
7813 json,
7814 "updateDelayBestpathResumed",
7815 bgp->update_delay_end_time);
7816 json_object_string_add(
7817 json,
7818 "updateDelayZebraUpdateResume",
7819 bgp->update_delay_zebra_resume_time);
7820 json_object_string_add(
7821 json,
7822 "updateDelayPeerUpdateResume",
7823 bgp->update_delay_peers_resume_time);
7824 }
7825 }
7826 } else {
7827 vty_out(vty,
7828 "Read-only mode update-delay limit: %d seconds\n",
7829 bgp->v_update_delay);
7830 if (bgp->v_update_delay
7831 != bgp->v_establish_wait)
7832 vty_out(vty,
7833 " Establish wait: %d seconds\n",
7834 bgp->v_establish_wait);
7835
7836 if (bgp_update_delay_active(bgp)) {
7837 vty_out(vty,
7838 " First neighbor established: %s\n",
7839 bgp->update_delay_begin_time);
7840 vty_out(vty,
7841 " Delay in progress\n");
7842 } else {
7843 if (bgp->update_delay_over) {
7844 vty_out(vty,
7845 " First neighbor established: %s\n",
7846 bgp->update_delay_begin_time);
7847 vty_out(vty,
7848 " Best-paths resumed: %s\n",
7849 bgp->update_delay_end_time);
7850 vty_out(vty,
7851 " zebra update resumed: %s\n",
7852 bgp->update_delay_zebra_resume_time);
7853 vty_out(vty,
7854 " peers update resumed: %s\n",
7855 bgp->update_delay_peers_resume_time);
7856 }
7857 }
7858 }
7859 }
7860
7861 if (use_json) {
7862 if (bgp_maxmed_onstartup_configured(bgp)
7863 && bgp->maxmed_active)
7864 json_object_boolean_true_add(
7865 json, "maxMedOnStartup");
7866 if (bgp->v_maxmed_admin)
7867 json_object_boolean_true_add(
7868 json, "maxMedAdministrative");
7869
7870 json_object_int_add(
7871 json, "tableVersion",
7872 bgp_table_version(bgp->rib[afi][safi]));
7873
7874 ents = bgp_table_count(bgp->rib[afi][safi]);
7875 json_object_int_add(json, "ribCount", ents);
7876 json_object_int_add(
7877 json, "ribMemory",
7878 ents * sizeof(struct bgp_node));
7879
7880 ents = listcount(bgp->peer);
7881 json_object_int_add(json, "peerCount", ents);
7882 json_object_int_add(json, "peerMemory",
7883 ents * sizeof(struct peer));
7884
7885 if ((ents = listcount(bgp->group))) {
7886 json_object_int_add(
7887 json, "peerGroupCount", ents);
7888 json_object_int_add(
7889 json, "peerGroupMemory",
7890 ents * sizeof(struct
7891 peer_group));
7892 }
7893
7894 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7895 BGP_CONFIG_DAMPENING))
7896 json_object_boolean_true_add(
7897 json, "dampeningEnabled");
7898 } else {
7899 if (bgp_maxmed_onstartup_configured(bgp)
7900 && bgp->maxmed_active)
7901 vty_out(vty,
7902 "Max-med on-startup active\n");
7903 if (bgp->v_maxmed_admin)
7904 vty_out(vty,
7905 "Max-med administrative active\n");
7906
7907 vty_out(vty, "BGP table version %" PRIu64 "\n",
7908 bgp_table_version(bgp->rib[afi][safi]));
7909
7910 ents = bgp_table_count(bgp->rib[afi][safi]);
7911 vty_out(vty,
7912 "RIB entries %ld, using %s of memory\n",
7913 ents,
7914 mtype_memstr(memstrbuf,
7915 sizeof(memstrbuf),
7916 ents * sizeof(struct
7917 bgp_node)));
7918
7919 /* Peer related usage */
7920 ents = listcount(bgp->peer);
7921 vty_out(vty, "Peers %ld, using %s of memory\n",
7922 ents,
7923 mtype_memstr(
7924 memstrbuf, sizeof(memstrbuf),
7925 ents * sizeof(struct peer)));
7926
7927 if ((ents = listcount(bgp->group)))
7928 vty_out(vty,
7929 "Peer groups %ld, using %s of memory\n",
7930 ents,
7931 mtype_memstr(
7932 memstrbuf,
7933 sizeof(memstrbuf),
7934 ents * sizeof(struct
7935 peer_group)));
7936
7937 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7938 BGP_CONFIG_DAMPENING))
7939 vty_out(vty, "Dampening enabled.\n");
7940 vty_out(vty, "\n");
7941
7942 /* Subtract 8 here because 'Neighbor' is
7943 * 8 characters */
7944 vty_out(vty, "Neighbor");
7945 vty_out(vty, "%*s", max_neighbor_width - 8,
7946 " ");
7947 vty_out(vty,
7948 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7949 }
7950 }
7951
7952 count++;
7953
7954 if (use_json) {
7955 json_peer = json_object_new_object();
7956
7957 if (peer_dynamic_neighbor(peer)) {
7958 dn_count++;
7959 json_object_boolean_true_add(json_peer,
7960 "dynamicPeer");
7961 }
7962
7963 if (peer->hostname)
7964 json_object_string_add(json_peer, "hostname",
7965 peer->hostname);
7966
7967 if (peer->domainname)
7968 json_object_string_add(json_peer, "domainname",
7969 peer->domainname);
7970
7971 json_object_int_add(json_peer, "remoteAs", peer->as);
7972 json_object_int_add(json_peer, "version", 4);
7973 json_object_int_add(json_peer, "msgRcvd",
7974 PEER_TOTAL_RX(peer));
7975 json_object_int_add(json_peer, "msgSent",
7976 PEER_TOTAL_TX(peer));
7977
7978 json_object_int_add(json_peer, "tableVersion",
7979 peer->version[afi][safi]);
7980 json_object_int_add(json_peer, "outq",
7981 peer->obuf->count);
7982 json_object_int_add(json_peer, "inq", 0);
7983 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7984 use_json, json_peer);
7985
7986 /*
7987 * Adding "pfxRcd" field to match with the corresponding
7988 * CLI. "prefixReceivedCount" will be deprecated in
7989 * future.
7990 */
7991 json_object_int_add(json_peer, "prefixReceivedCount",
7992 peer->pcount[afi][pfx_rcd_safi]);
7993 json_object_int_add(json_peer, "pfxRcd",
7994 peer->pcount[afi][pfx_rcd_safi]);
7995
7996 paf = peer_af_find(peer, afi, pfx_rcd_safi);
7997 if (paf && PAF_SUBGRP(paf))
7998 json_object_int_add(json_peer,
7999 "pfxSnt",
8000 (PAF_SUBGRP(paf))->scount);
8001
8002 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8003 json_object_string_add(json_peer, "state",
8004 "Idle (Admin)");
8005 else if (peer->afc_recv[afi][safi])
8006 json_object_string_add(
8007 json_peer, "state",
8008 lookup_msg(bgp_status_msg, peer->status,
8009 NULL));
8010 else if (CHECK_FLAG(peer->sflags,
8011 PEER_STATUS_PREFIX_OVERFLOW))
8012 json_object_string_add(json_peer, "state",
8013 "Idle (PfxCt)");
8014 else
8015 json_object_string_add(
8016 json_peer, "state",
8017 lookup_msg(bgp_status_msg, peer->status,
8018 NULL));
8019
8020 if (peer->conf_if)
8021 json_object_string_add(json_peer, "idType",
8022 "interface");
8023 else if (peer->su.sa.sa_family == AF_INET)
8024 json_object_string_add(json_peer, "idType",
8025 "ipv4");
8026 else if (peer->su.sa.sa_family == AF_INET6)
8027 json_object_string_add(json_peer, "idType",
8028 "ipv6");
8029
8030 json_object_object_add(json_peers, peer->host,
8031 json_peer);
8032 } else {
8033 memset(dn_flag, '\0', sizeof(dn_flag));
8034 if (peer_dynamic_neighbor(peer)) {
8035 dn_count++;
8036 dn_flag[0] = '*';
8037 }
8038
8039 if (peer->hostname
8040 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8041 len = vty_out(vty, "%s%s(%s)", dn_flag,
8042 peer->hostname, peer->host);
8043 else
8044 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8045
8046 /* pad the neighbor column with spaces */
8047 if (len < max_neighbor_width)
8048 vty_out(vty, "%*s", max_neighbor_width - len,
8049 " ");
8050
8051 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8052 peer->as, PEER_TOTAL_RX(peer),
8053 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8054 0, peer->obuf->count,
8055 peer_uptime(peer->uptime, timebuf,
8056 BGP_UPTIME_LEN, 0, NULL));
8057
8058 if (peer->status == Established)
8059 if (peer->afc_recv[afi][safi])
8060 vty_out(vty, " %12ld",
8061 peer->pcount[afi]
8062 [pfx_rcd_safi]);
8063 else
8064 vty_out(vty, " NoNeg");
8065 else {
8066 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8067 vty_out(vty, " Idle (Admin)");
8068 else if (CHECK_FLAG(
8069 peer->sflags,
8070 PEER_STATUS_PREFIX_OVERFLOW))
8071 vty_out(vty, " Idle (PfxCt)");
8072 else
8073 vty_out(vty, " %12s",
8074 lookup_msg(bgp_status_msg,
8075 peer->status, NULL));
8076 }
8077 vty_out(vty, "\n");
8078 }
8079 }
8080
8081 if (use_json) {
8082 json_object_object_add(json, "peers", json_peers);
8083
8084 json_object_int_add(json, "totalPeers", count);
8085 json_object_int_add(json, "dynamicPeers", dn_count);
8086
8087 bgp_show_bestpath_json(bgp, json);
8088
8089 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8090 json, JSON_C_TO_STRING_PRETTY));
8091 json_object_free(json);
8092 } else {
8093 if (count)
8094 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8095 else {
8096 vty_out(vty, "No %s neighbor is configured\n",
8097 afi_safi_print(afi, safi));
8098 }
8099
8100 if (dn_count) {
8101 vty_out(vty, "* - dynamic neighbor\n");
8102 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8103 dn_count, bgp->dynamic_neighbors_limit);
8104 }
8105 }
8106
8107 return CMD_SUCCESS;
8108 }
8109
8110 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8111 int safi, bool use_json,
8112 json_object *json)
8113 {
8114 int is_first = 1;
8115 int afi_wildcard = (afi == AFI_MAX);
8116 int safi_wildcard = (safi == SAFI_MAX);
8117 int is_wildcard = (afi_wildcard || safi_wildcard);
8118 bool nbr_output = false;
8119
8120 if (use_json && is_wildcard)
8121 vty_out(vty, "{\n");
8122 if (afi_wildcard)
8123 afi = 1; /* AFI_IP */
8124 while (afi < AFI_MAX) {
8125 if (safi_wildcard)
8126 safi = 1; /* SAFI_UNICAST */
8127 while (safi < SAFI_MAX) {
8128 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8129 nbr_output = true;
8130 if (is_wildcard) {
8131 /*
8132 * So limit output to those afi/safi
8133 * pairs that
8134 * actualy have something interesting in
8135 * them
8136 */
8137 if (use_json) {
8138 json = json_object_new_object();
8139
8140 if (!is_first)
8141 vty_out(vty, ",\n");
8142 else
8143 is_first = 0;
8144
8145 vty_out(vty, "\"%s\":",
8146 afi_safi_json(afi,
8147 safi));
8148 } else {
8149 vty_out(vty, "\n%s Summary:\n",
8150 afi_safi_print(afi,
8151 safi));
8152 }
8153 }
8154 bgp_show_summary(vty, bgp, afi, safi, use_json,
8155 json);
8156 }
8157 safi++;
8158 if (!safi_wildcard)
8159 safi = SAFI_MAX;
8160 }
8161 afi++;
8162 if (!afi_wildcard)
8163 afi = AFI_MAX;
8164 }
8165
8166 if (use_json && is_wildcard)
8167 vty_out(vty, "}\n");
8168 else if (!nbr_output) {
8169 if (use_json)
8170 vty_out(vty, "{}\n");
8171 else
8172 vty_out(vty, "%% No BGP neighbors found\n");
8173 }
8174 }
8175
8176 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8177 safi_t safi, bool use_json)
8178 {
8179 struct listnode *node, *nnode;
8180 struct bgp *bgp;
8181 json_object *json = NULL;
8182 int is_first = 1;
8183 bool nbr_output = false;
8184
8185 if (use_json)
8186 vty_out(vty, "{\n");
8187
8188 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8189 nbr_output = true;
8190 if (use_json) {
8191 json = json_object_new_object();
8192
8193 if (!is_first)
8194 vty_out(vty, ",\n");
8195 else
8196 is_first = 0;
8197
8198 vty_out(vty, "\"%s\":",
8199 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8200 ? "Default"
8201 : bgp->name);
8202 } else {
8203 vty_out(vty, "\nInstance %s:\n",
8204 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8205 ? "Default"
8206 : bgp->name);
8207 }
8208 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8209 }
8210
8211 if (use_json)
8212 vty_out(vty, "}\n");
8213 else if (!nbr_output)
8214 vty_out(vty, "%% BGP instance not found\n");
8215 }
8216
8217 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8218 safi_t safi, bool use_json)
8219 {
8220 struct bgp *bgp;
8221
8222 if (name) {
8223 if (strmatch(name, "all")) {
8224 bgp_show_all_instances_summary_vty(vty, afi, safi,
8225 use_json);
8226 return CMD_SUCCESS;
8227 } else {
8228 bgp = bgp_lookup_by_name(name);
8229
8230 if (!bgp) {
8231 if (use_json)
8232 vty_out(vty, "{}\n");
8233 else
8234 vty_out(vty,
8235 "%% BGP instance not found\n");
8236 return CMD_WARNING;
8237 }
8238
8239 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8240 NULL);
8241 return CMD_SUCCESS;
8242 }
8243 }
8244
8245 bgp = bgp_get_default();
8246
8247 if (bgp)
8248 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8249 else {
8250 if (use_json)
8251 vty_out(vty, "{}\n");
8252 else
8253 vty_out(vty, "%% BGP instance not found\n");
8254 return CMD_WARNING;
8255 }
8256
8257 return CMD_SUCCESS;
8258 }
8259
8260 /* `show [ip] bgp summary' commands. */
8261 DEFUN (show_ip_bgp_summary,
8262 show_ip_bgp_summary_cmd,
8263 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8264 SHOW_STR
8265 IP_STR
8266 BGP_STR
8267 BGP_INSTANCE_HELP_STR
8268 BGP_AFI_HELP_STR
8269 BGP_SAFI_WITH_LABEL_HELP_STR
8270 "Summary of BGP neighbor status\n"
8271 JSON_STR)
8272 {
8273 char *vrf = NULL;
8274 afi_t afi = AFI_MAX;
8275 safi_t safi = SAFI_MAX;
8276
8277 int idx = 0;
8278
8279 /* show [ip] bgp */
8280 if (argv_find(argv, argc, "ip", &idx))
8281 afi = AFI_IP;
8282 /* [<vrf> VIEWVRFNAME] */
8283 if (argv_find(argv, argc, "vrf", &idx)) {
8284 vrf = argv[idx + 1]->arg;
8285 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8286 vrf = NULL;
8287 } else if (argv_find(argv, argc, "view", &idx))
8288 /* [<view> VIEWVRFNAME] */
8289 vrf = argv[idx + 1]->arg;
8290 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8291 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8292 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8293 }
8294
8295 bool uj = use_json(argc, argv);
8296
8297 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8298 }
8299
8300 const char *afi_safi_print(afi_t afi, safi_t safi)
8301 {
8302 if (afi == AFI_IP && safi == SAFI_UNICAST)
8303 return "IPv4 Unicast";
8304 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8305 return "IPv4 Multicast";
8306 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8307 return "IPv4 Labeled Unicast";
8308 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8309 return "IPv4 VPN";
8310 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8311 return "IPv4 Encap";
8312 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8313 return "IPv4 Flowspec";
8314 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8315 return "IPv6 Unicast";
8316 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8317 return "IPv6 Multicast";
8318 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8319 return "IPv6 Labeled Unicast";
8320 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8321 return "IPv6 VPN";
8322 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8323 return "IPv6 Encap";
8324 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8325 return "IPv6 Flowspec";
8326 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8327 return "L2VPN EVPN";
8328 else
8329 return "Unknown";
8330 }
8331
8332 /*
8333 * Please note that we have intentionally camelCased
8334 * the return strings here. So if you want
8335 * to use this function, please ensure you
8336 * are doing this within json output
8337 */
8338 const char *afi_safi_json(afi_t afi, safi_t safi)
8339 {
8340 if (afi == AFI_IP && safi == SAFI_UNICAST)
8341 return "ipv4Unicast";
8342 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8343 return "ipv4Multicast";
8344 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8345 return "ipv4LabeledUnicast";
8346 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8347 return "ipv4Vpn";
8348 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8349 return "ipv4Encap";
8350 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8351 return "ipv4Flowspec";
8352 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8353 return "ipv6Unicast";
8354 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8355 return "ipv6Multicast";
8356 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8357 return "ipv6LabeledUnicast";
8358 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8359 return "ipv6Vpn";
8360 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8361 return "ipv6Encap";
8362 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8363 return "ipv6Flowspec";
8364 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8365 return "l2VpnEvpn";
8366 else
8367 return "Unknown";
8368 }
8369
8370 /* Show BGP peer's information. */
8371 enum show_type { show_all, show_peer };
8372
8373 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8374 afi_t afi, safi_t safi,
8375 uint16_t adv_smcap, uint16_t adv_rmcap,
8376 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8377 bool use_json, json_object *json_pref)
8378 {
8379 /* Send-Mode */
8380 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8381 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8382 if (use_json) {
8383 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8384 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8385 json_object_string_add(json_pref, "sendMode",
8386 "advertisedAndReceived");
8387 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8388 json_object_string_add(json_pref, "sendMode",
8389 "advertised");
8390 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8391 json_object_string_add(json_pref, "sendMode",
8392 "received");
8393 } else {
8394 vty_out(vty, " Send-mode: ");
8395 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8396 vty_out(vty, "advertised");
8397 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8398 vty_out(vty, "%sreceived",
8399 CHECK_FLAG(p->af_cap[afi][safi],
8400 adv_smcap)
8401 ? ", "
8402 : "");
8403 vty_out(vty, "\n");
8404 }
8405 }
8406
8407 /* Receive-Mode */
8408 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8409 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8410 if (use_json) {
8411 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8412 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8413 json_object_string_add(json_pref, "recvMode",
8414 "advertisedAndReceived");
8415 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8416 json_object_string_add(json_pref, "recvMode",
8417 "advertised");
8418 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8419 json_object_string_add(json_pref, "recvMode",
8420 "received");
8421 } else {
8422 vty_out(vty, " Receive-mode: ");
8423 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8424 vty_out(vty, "advertised");
8425 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8426 vty_out(vty, "%sreceived",
8427 CHECK_FLAG(p->af_cap[afi][safi],
8428 adv_rmcap)
8429 ? ", "
8430 : "");
8431 vty_out(vty, "\n");
8432 }
8433 }
8434 }
8435
8436 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8437 safi_t safi, bool use_json,
8438 json_object *json_neigh)
8439 {
8440 struct bgp_filter *filter;
8441 struct peer_af *paf;
8442 char orf_pfx_name[BUFSIZ];
8443 int orf_pfx_count;
8444 json_object *json_af = NULL;
8445 json_object *json_prefA = NULL;
8446 json_object *json_prefB = NULL;
8447 json_object *json_addr = NULL;
8448
8449 if (use_json) {
8450 json_addr = json_object_new_object();
8451 json_af = json_object_new_object();
8452 filter = &p->filter[afi][safi];
8453
8454 if (peer_group_active(p))
8455 json_object_string_add(json_addr, "peerGroupMember",
8456 p->group->name);
8457
8458 paf = peer_af_find(p, afi, safi);
8459 if (paf && PAF_SUBGRP(paf)) {
8460 json_object_int_add(json_addr, "updateGroupId",
8461 PAF_UPDGRP(paf)->id);
8462 json_object_int_add(json_addr, "subGroupId",
8463 PAF_SUBGRP(paf)->id);
8464 json_object_int_add(json_addr, "packetQueueLength",
8465 bpacket_queue_virtual_length(paf));
8466 }
8467
8468 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8469 || CHECK_FLAG(p->af_cap[afi][safi],
8470 PEER_CAP_ORF_PREFIX_SM_RCV)
8471 || CHECK_FLAG(p->af_cap[afi][safi],
8472 PEER_CAP_ORF_PREFIX_RM_ADV)
8473 || CHECK_FLAG(p->af_cap[afi][safi],
8474 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8475 json_object_int_add(json_af, "orfType",
8476 ORF_TYPE_PREFIX);
8477 json_prefA = json_object_new_object();
8478 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8479 PEER_CAP_ORF_PREFIX_SM_ADV,
8480 PEER_CAP_ORF_PREFIX_RM_ADV,
8481 PEER_CAP_ORF_PREFIX_SM_RCV,
8482 PEER_CAP_ORF_PREFIX_RM_RCV,
8483 use_json, json_prefA);
8484 json_object_object_add(json_af, "orfPrefixList",
8485 json_prefA);
8486 }
8487
8488 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8489 || CHECK_FLAG(p->af_cap[afi][safi],
8490 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8491 || CHECK_FLAG(p->af_cap[afi][safi],
8492 PEER_CAP_ORF_PREFIX_RM_ADV)
8493 || CHECK_FLAG(p->af_cap[afi][safi],
8494 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8495 json_object_int_add(json_af, "orfOldType",
8496 ORF_TYPE_PREFIX_OLD);
8497 json_prefB = json_object_new_object();
8498 bgp_show_peer_afi_orf_cap(
8499 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8500 PEER_CAP_ORF_PREFIX_RM_ADV,
8501 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8502 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8503 json_prefB);
8504 json_object_object_add(json_af, "orfOldPrefixList",
8505 json_prefB);
8506 }
8507
8508 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8509 || CHECK_FLAG(p->af_cap[afi][safi],
8510 PEER_CAP_ORF_PREFIX_SM_RCV)
8511 || CHECK_FLAG(p->af_cap[afi][safi],
8512 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8513 || CHECK_FLAG(p->af_cap[afi][safi],
8514 PEER_CAP_ORF_PREFIX_RM_ADV)
8515 || CHECK_FLAG(p->af_cap[afi][safi],
8516 PEER_CAP_ORF_PREFIX_RM_RCV)
8517 || CHECK_FLAG(p->af_cap[afi][safi],
8518 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8519 json_object_object_add(json_addr, "afDependentCap",
8520 json_af);
8521 else
8522 json_object_free(json_af);
8523
8524 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8525 orf_pfx_count = prefix_bgp_show_prefix_list(
8526 NULL, afi, orf_pfx_name, use_json);
8527
8528 if (CHECK_FLAG(p->af_sflags[afi][safi],
8529 PEER_STATUS_ORF_PREFIX_SEND)
8530 || orf_pfx_count) {
8531 if (CHECK_FLAG(p->af_sflags[afi][safi],
8532 PEER_STATUS_ORF_PREFIX_SEND))
8533 json_object_boolean_true_add(json_neigh,
8534 "orfSent");
8535 if (orf_pfx_count)
8536 json_object_int_add(json_addr, "orfRecvCounter",
8537 orf_pfx_count);
8538 }
8539 if (CHECK_FLAG(p->af_sflags[afi][safi],
8540 PEER_STATUS_ORF_WAIT_REFRESH))
8541 json_object_string_add(
8542 json_addr, "orfFirstUpdate",
8543 "deferredUntilORFOrRouteRefreshRecvd");
8544
8545 if (CHECK_FLAG(p->af_flags[afi][safi],
8546 PEER_FLAG_REFLECTOR_CLIENT))
8547 json_object_boolean_true_add(json_addr,
8548 "routeReflectorClient");
8549 if (CHECK_FLAG(p->af_flags[afi][safi],
8550 PEER_FLAG_RSERVER_CLIENT))
8551 json_object_boolean_true_add(json_addr,
8552 "routeServerClient");
8553 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8554 json_object_boolean_true_add(json_addr,
8555 "inboundSoftConfigPermit");
8556
8557 if (CHECK_FLAG(p->af_flags[afi][safi],
8558 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8559 json_object_boolean_true_add(
8560 json_addr,
8561 "privateAsNumsAllReplacedInUpdatesToNbr");
8562 else if (CHECK_FLAG(p->af_flags[afi][safi],
8563 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8564 json_object_boolean_true_add(
8565 json_addr,
8566 "privateAsNumsReplacedInUpdatesToNbr");
8567 else if (CHECK_FLAG(p->af_flags[afi][safi],
8568 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8569 json_object_boolean_true_add(
8570 json_addr,
8571 "privateAsNumsAllRemovedInUpdatesToNbr");
8572 else if (CHECK_FLAG(p->af_flags[afi][safi],
8573 PEER_FLAG_REMOVE_PRIVATE_AS))
8574 json_object_boolean_true_add(
8575 json_addr,
8576 "privateAsNumsRemovedInUpdatesToNbr");
8577
8578 if (CHECK_FLAG(p->af_flags[afi][safi],
8579 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8580 json_object_boolean_true_add(json_addr,
8581 "addpathTxAllPaths");
8582
8583 if (CHECK_FLAG(p->af_flags[afi][safi],
8584 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8585 json_object_boolean_true_add(json_addr,
8586 "addpathTxBestpathPerAS");
8587
8588 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8589 json_object_string_add(json_addr,
8590 "overrideASNsInOutboundUpdates",
8591 "ifAspathEqualRemoteAs");
8592
8593 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8594 || CHECK_FLAG(p->af_flags[afi][safi],
8595 PEER_FLAG_FORCE_NEXTHOP_SELF))
8596 json_object_boolean_true_add(json_addr,
8597 "routerAlwaysNextHop");
8598 if (CHECK_FLAG(p->af_flags[afi][safi],
8599 PEER_FLAG_AS_PATH_UNCHANGED))
8600 json_object_boolean_true_add(
8601 json_addr, "unchangedAsPathPropogatedToNbr");
8602 if (CHECK_FLAG(p->af_flags[afi][safi],
8603 PEER_FLAG_NEXTHOP_UNCHANGED))
8604 json_object_boolean_true_add(
8605 json_addr, "unchangedNextHopPropogatedToNbr");
8606 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8607 json_object_boolean_true_add(
8608 json_addr, "unchangedMedPropogatedToNbr");
8609 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8610 || CHECK_FLAG(p->af_flags[afi][safi],
8611 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8612 if (CHECK_FLAG(p->af_flags[afi][safi],
8613 PEER_FLAG_SEND_COMMUNITY)
8614 && CHECK_FLAG(p->af_flags[afi][safi],
8615 PEER_FLAG_SEND_EXT_COMMUNITY))
8616 json_object_string_add(json_addr,
8617 "commAttriSentToNbr",
8618 "extendedAndStandard");
8619 else if (CHECK_FLAG(p->af_flags[afi][safi],
8620 PEER_FLAG_SEND_EXT_COMMUNITY))
8621 json_object_string_add(json_addr,
8622 "commAttriSentToNbr",
8623 "extended");
8624 else
8625 json_object_string_add(json_addr,
8626 "commAttriSentToNbr",
8627 "standard");
8628 }
8629 if (CHECK_FLAG(p->af_flags[afi][safi],
8630 PEER_FLAG_DEFAULT_ORIGINATE)) {
8631 if (p->default_rmap[afi][safi].name)
8632 json_object_string_add(
8633 json_addr, "defaultRouteMap",
8634 p->default_rmap[afi][safi].name);
8635
8636 if (paf && PAF_SUBGRP(paf)
8637 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8638 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8639 json_object_boolean_true_add(json_addr,
8640 "defaultSent");
8641 else
8642 json_object_boolean_true_add(json_addr,
8643 "defaultNotSent");
8644 }
8645
8646 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8647 if (is_evpn_enabled())
8648 json_object_boolean_true_add(
8649 json_addr, "advertiseAllVnis");
8650 }
8651
8652 if (filter->plist[FILTER_IN].name
8653 || filter->dlist[FILTER_IN].name
8654 || filter->aslist[FILTER_IN].name
8655 || filter->map[RMAP_IN].name)
8656 json_object_boolean_true_add(json_addr,
8657 "inboundPathPolicyConfig");
8658 if (filter->plist[FILTER_OUT].name
8659 || filter->dlist[FILTER_OUT].name
8660 || filter->aslist[FILTER_OUT].name
8661 || filter->map[RMAP_OUT].name || filter->usmap.name)
8662 json_object_boolean_true_add(
8663 json_addr, "outboundPathPolicyConfig");
8664
8665 /* prefix-list */
8666 if (filter->plist[FILTER_IN].name)
8667 json_object_string_add(json_addr,
8668 "incomingUpdatePrefixFilterList",
8669 filter->plist[FILTER_IN].name);
8670 if (filter->plist[FILTER_OUT].name)
8671 json_object_string_add(json_addr,
8672 "outgoingUpdatePrefixFilterList",
8673 filter->plist[FILTER_OUT].name);
8674
8675 /* distribute-list */
8676 if (filter->dlist[FILTER_IN].name)
8677 json_object_string_add(
8678 json_addr, "incomingUpdateNetworkFilterList",
8679 filter->dlist[FILTER_IN].name);
8680 if (filter->dlist[FILTER_OUT].name)
8681 json_object_string_add(
8682 json_addr, "outgoingUpdateNetworkFilterList",
8683 filter->dlist[FILTER_OUT].name);
8684
8685 /* filter-list. */
8686 if (filter->aslist[FILTER_IN].name)
8687 json_object_string_add(json_addr,
8688 "incomingUpdateAsPathFilterList",
8689 filter->aslist[FILTER_IN].name);
8690 if (filter->aslist[FILTER_OUT].name)
8691 json_object_string_add(json_addr,
8692 "outgoingUpdateAsPathFilterList",
8693 filter->aslist[FILTER_OUT].name);
8694
8695 /* route-map. */
8696 if (filter->map[RMAP_IN].name)
8697 json_object_string_add(
8698 json_addr, "routeMapForIncomingAdvertisements",
8699 filter->map[RMAP_IN].name);
8700 if (filter->map[RMAP_OUT].name)
8701 json_object_string_add(
8702 json_addr, "routeMapForOutgoingAdvertisements",
8703 filter->map[RMAP_OUT].name);
8704
8705 /* unsuppress-map */
8706 if (filter->usmap.name)
8707 json_object_string_add(json_addr,
8708 "selectiveUnsuppressRouteMap",
8709 filter->usmap.name);
8710
8711 /* Receive prefix count */
8712 json_object_int_add(json_addr, "acceptedPrefixCounter",
8713 p->pcount[afi][safi]);
8714 if (paf && PAF_SUBGRP(paf))
8715 json_object_int_add(json_addr, "sentPrefixCounter",
8716 (PAF_SUBGRP(paf))->scount);
8717
8718 /* Maximum prefix */
8719 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8720 json_object_int_add(json_addr, "prefixAllowedMax",
8721 p->pmax[afi][safi]);
8722 if (CHECK_FLAG(p->af_flags[afi][safi],
8723 PEER_FLAG_MAX_PREFIX_WARNING))
8724 json_object_boolean_true_add(
8725 json_addr, "prefixAllowedMaxWarning");
8726 json_object_int_add(json_addr,
8727 "prefixAllowedWarningThresh",
8728 p->pmax_threshold[afi][safi]);
8729 if (p->pmax_restart[afi][safi])
8730 json_object_int_add(
8731 json_addr,
8732 "prefixAllowedRestartIntervalMsecs",
8733 p->pmax_restart[afi][safi] * 60000);
8734 }
8735 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8736 json_addr);
8737
8738 } else {
8739 filter = &p->filter[afi][safi];
8740
8741 vty_out(vty, " For address family: %s\n",
8742 afi_safi_print(afi, safi));
8743
8744 if (peer_group_active(p))
8745 vty_out(vty, " %s peer-group member\n",
8746 p->group->name);
8747
8748 paf = peer_af_find(p, afi, safi);
8749 if (paf && PAF_SUBGRP(paf)) {
8750 vty_out(vty, " Update group %" PRIu64
8751 ", subgroup %" PRIu64 "\n",
8752 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8753 vty_out(vty, " Packet Queue length %d\n",
8754 bpacket_queue_virtual_length(paf));
8755 } else {
8756 vty_out(vty, " Not part of any update group\n");
8757 }
8758 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8759 || CHECK_FLAG(p->af_cap[afi][safi],
8760 PEER_CAP_ORF_PREFIX_SM_RCV)
8761 || CHECK_FLAG(p->af_cap[afi][safi],
8762 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8763 || CHECK_FLAG(p->af_cap[afi][safi],
8764 PEER_CAP_ORF_PREFIX_RM_ADV)
8765 || CHECK_FLAG(p->af_cap[afi][safi],
8766 PEER_CAP_ORF_PREFIX_RM_RCV)
8767 || CHECK_FLAG(p->af_cap[afi][safi],
8768 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8769 vty_out(vty, " AF-dependant capabilities:\n");
8770
8771 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8772 || CHECK_FLAG(p->af_cap[afi][safi],
8773 PEER_CAP_ORF_PREFIX_SM_RCV)
8774 || CHECK_FLAG(p->af_cap[afi][safi],
8775 PEER_CAP_ORF_PREFIX_RM_ADV)
8776 || CHECK_FLAG(p->af_cap[afi][safi],
8777 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8778 vty_out(vty,
8779 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8780 ORF_TYPE_PREFIX);
8781 bgp_show_peer_afi_orf_cap(
8782 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8783 PEER_CAP_ORF_PREFIX_RM_ADV,
8784 PEER_CAP_ORF_PREFIX_SM_RCV,
8785 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8786 }
8787 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8788 || CHECK_FLAG(p->af_cap[afi][safi],
8789 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8790 || CHECK_FLAG(p->af_cap[afi][safi],
8791 PEER_CAP_ORF_PREFIX_RM_ADV)
8792 || CHECK_FLAG(p->af_cap[afi][safi],
8793 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8794 vty_out(vty,
8795 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8796 ORF_TYPE_PREFIX_OLD);
8797 bgp_show_peer_afi_orf_cap(
8798 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8799 PEER_CAP_ORF_PREFIX_RM_ADV,
8800 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8801 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8802 }
8803
8804 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8805 orf_pfx_count = prefix_bgp_show_prefix_list(
8806 NULL, afi, orf_pfx_name, use_json);
8807
8808 if (CHECK_FLAG(p->af_sflags[afi][safi],
8809 PEER_STATUS_ORF_PREFIX_SEND)
8810 || orf_pfx_count) {
8811 vty_out(vty, " Outbound Route Filter (ORF):");
8812 if (CHECK_FLAG(p->af_sflags[afi][safi],
8813 PEER_STATUS_ORF_PREFIX_SEND))
8814 vty_out(vty, " sent;");
8815 if (orf_pfx_count)
8816 vty_out(vty, " received (%d entries)",
8817 orf_pfx_count);
8818 vty_out(vty, "\n");
8819 }
8820 if (CHECK_FLAG(p->af_sflags[afi][safi],
8821 PEER_STATUS_ORF_WAIT_REFRESH))
8822 vty_out(vty,
8823 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8824
8825 if (CHECK_FLAG(p->af_flags[afi][safi],
8826 PEER_FLAG_REFLECTOR_CLIENT))
8827 vty_out(vty, " Route-Reflector Client\n");
8828 if (CHECK_FLAG(p->af_flags[afi][safi],
8829 PEER_FLAG_RSERVER_CLIENT))
8830 vty_out(vty, " Route-Server Client\n");
8831 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8832 vty_out(vty,
8833 " Inbound soft reconfiguration allowed\n");
8834
8835 if (CHECK_FLAG(p->af_flags[afi][safi],
8836 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8837 vty_out(vty,
8838 " Private AS numbers (all) replaced in updates to this neighbor\n");
8839 else if (CHECK_FLAG(p->af_flags[afi][safi],
8840 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8841 vty_out(vty,
8842 " Private AS numbers replaced in updates to this neighbor\n");
8843 else if (CHECK_FLAG(p->af_flags[afi][safi],
8844 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8845 vty_out(vty,
8846 " Private AS numbers (all) removed in updates to this neighbor\n");
8847 else if (CHECK_FLAG(p->af_flags[afi][safi],
8848 PEER_FLAG_REMOVE_PRIVATE_AS))
8849 vty_out(vty,
8850 " Private AS numbers removed in updates to this neighbor\n");
8851
8852 if (CHECK_FLAG(p->af_flags[afi][safi],
8853 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8854 vty_out(vty, " Advertise all paths via addpath\n");
8855
8856 if (CHECK_FLAG(p->af_flags[afi][safi],
8857 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8858 vty_out(vty,
8859 " Advertise bestpath per AS via addpath\n");
8860
8861 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8862 vty_out(vty,
8863 " Override ASNs in outbound updates if aspath equals remote-as\n");
8864
8865 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8866 || CHECK_FLAG(p->af_flags[afi][safi],
8867 PEER_FLAG_FORCE_NEXTHOP_SELF))
8868 vty_out(vty, " NEXT_HOP is always this router\n");
8869 if (CHECK_FLAG(p->af_flags[afi][safi],
8870 PEER_FLAG_AS_PATH_UNCHANGED))
8871 vty_out(vty,
8872 " AS_PATH is propagated unchanged to this neighbor\n");
8873 if (CHECK_FLAG(p->af_flags[afi][safi],
8874 PEER_FLAG_NEXTHOP_UNCHANGED))
8875 vty_out(vty,
8876 " NEXT_HOP is propagated unchanged to this neighbor\n");
8877 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8878 vty_out(vty,
8879 " MED is propagated unchanged to this neighbor\n");
8880 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8881 || CHECK_FLAG(p->af_flags[afi][safi],
8882 PEER_FLAG_SEND_EXT_COMMUNITY)
8883 || CHECK_FLAG(p->af_flags[afi][safi],
8884 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8885 vty_out(vty,
8886 " Community attribute sent to this neighbor");
8887 if (CHECK_FLAG(p->af_flags[afi][safi],
8888 PEER_FLAG_SEND_COMMUNITY)
8889 && CHECK_FLAG(p->af_flags[afi][safi],
8890 PEER_FLAG_SEND_EXT_COMMUNITY)
8891 && CHECK_FLAG(p->af_flags[afi][safi],
8892 PEER_FLAG_SEND_LARGE_COMMUNITY))
8893 vty_out(vty, "(all)\n");
8894 else if (CHECK_FLAG(p->af_flags[afi][safi],
8895 PEER_FLAG_SEND_LARGE_COMMUNITY))
8896 vty_out(vty, "(large)\n");
8897 else if (CHECK_FLAG(p->af_flags[afi][safi],
8898 PEER_FLAG_SEND_EXT_COMMUNITY))
8899 vty_out(vty, "(extended)\n");
8900 else
8901 vty_out(vty, "(standard)\n");
8902 }
8903 if (CHECK_FLAG(p->af_flags[afi][safi],
8904 PEER_FLAG_DEFAULT_ORIGINATE)) {
8905 vty_out(vty, " Default information originate,");
8906
8907 if (p->default_rmap[afi][safi].name)
8908 vty_out(vty, " default route-map %s%s,",
8909 p->default_rmap[afi][safi].map ? "*"
8910 : "",
8911 p->default_rmap[afi][safi].name);
8912 if (paf && PAF_SUBGRP(paf)
8913 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8914 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8915 vty_out(vty, " default sent\n");
8916 else
8917 vty_out(vty, " default not sent\n");
8918 }
8919
8920 /* advertise-vni-all */
8921 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8922 if (is_evpn_enabled())
8923 vty_out(vty, " advertise-all-vni\n");
8924 }
8925
8926 if (filter->plist[FILTER_IN].name
8927 || filter->dlist[FILTER_IN].name
8928 || filter->aslist[FILTER_IN].name
8929 || filter->map[RMAP_IN].name)
8930 vty_out(vty, " Inbound path policy configured\n");
8931 if (filter->plist[FILTER_OUT].name
8932 || filter->dlist[FILTER_OUT].name
8933 || filter->aslist[FILTER_OUT].name
8934 || filter->map[RMAP_OUT].name || filter->usmap.name)
8935 vty_out(vty, " Outbound path policy configured\n");
8936
8937 /* prefix-list */
8938 if (filter->plist[FILTER_IN].name)
8939 vty_out(vty,
8940 " Incoming update prefix filter list is %s%s\n",
8941 filter->plist[FILTER_IN].plist ? "*" : "",
8942 filter->plist[FILTER_IN].name);
8943 if (filter->plist[FILTER_OUT].name)
8944 vty_out(vty,
8945 " Outgoing update prefix filter list is %s%s\n",
8946 filter->plist[FILTER_OUT].plist ? "*" : "",
8947 filter->plist[FILTER_OUT].name);
8948
8949 /* distribute-list */
8950 if (filter->dlist[FILTER_IN].name)
8951 vty_out(vty,
8952 " Incoming update network filter list is %s%s\n",
8953 filter->dlist[FILTER_IN].alist ? "*" : "",
8954 filter->dlist[FILTER_IN].name);
8955 if (filter->dlist[FILTER_OUT].name)
8956 vty_out(vty,
8957 " Outgoing update network filter list is %s%s\n",
8958 filter->dlist[FILTER_OUT].alist ? "*" : "",
8959 filter->dlist[FILTER_OUT].name);
8960
8961 /* filter-list. */
8962 if (filter->aslist[FILTER_IN].name)
8963 vty_out(vty,
8964 " Incoming update AS path filter list is %s%s\n",
8965 filter->aslist[FILTER_IN].aslist ? "*" : "",
8966 filter->aslist[FILTER_IN].name);
8967 if (filter->aslist[FILTER_OUT].name)
8968 vty_out(vty,
8969 " Outgoing update AS path filter list is %s%s\n",
8970 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8971 filter->aslist[FILTER_OUT].name);
8972
8973 /* route-map. */
8974 if (filter->map[RMAP_IN].name)
8975 vty_out(vty,
8976 " Route map for incoming advertisements is %s%s\n",
8977 filter->map[RMAP_IN].map ? "*" : "",
8978 filter->map[RMAP_IN].name);
8979 if (filter->map[RMAP_OUT].name)
8980 vty_out(vty,
8981 " Route map for outgoing advertisements is %s%s\n",
8982 filter->map[RMAP_OUT].map ? "*" : "",
8983 filter->map[RMAP_OUT].name);
8984
8985 /* unsuppress-map */
8986 if (filter->usmap.name)
8987 vty_out(vty,
8988 " Route map for selective unsuppress is %s%s\n",
8989 filter->usmap.map ? "*" : "",
8990 filter->usmap.name);
8991
8992 /* Receive prefix count */
8993 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8994
8995 /* Maximum prefix */
8996 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8997 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8998 p->pmax[afi][safi],
8999 CHECK_FLAG(p->af_flags[afi][safi],
9000 PEER_FLAG_MAX_PREFIX_WARNING)
9001 ? " (warning-only)"
9002 : "");
9003 vty_out(vty, " Threshold for warning message %d%%",
9004 p->pmax_threshold[afi][safi]);
9005 if (p->pmax_restart[afi][safi])
9006 vty_out(vty, ", restart interval %d min",
9007 p->pmax_restart[afi][safi]);
9008 vty_out(vty, "\n");
9009 }
9010
9011 vty_out(vty, "\n");
9012 }
9013 }
9014
9015 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
9016 json_object *json)
9017 {
9018 struct bgp *bgp;
9019 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
9020 char timebuf[BGP_UPTIME_LEN];
9021 char dn_flag[2];
9022 const char *subcode_str;
9023 const char *code_str;
9024 afi_t afi;
9025 safi_t safi;
9026 uint16_t i;
9027 uint8_t *msg;
9028 json_object *json_neigh = NULL;
9029 time_t epoch_tbuf;
9030
9031 bgp = p->bgp;
9032
9033 if (use_json)
9034 json_neigh = json_object_new_object();
9035
9036 memset(dn_flag, '\0', sizeof(dn_flag));
9037 if (!p->conf_if && peer_dynamic_neighbor(p))
9038 dn_flag[0] = '*';
9039
9040 if (!use_json) {
9041 if (p->conf_if) /* Configured interface name. */
9042 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9043 BGP_PEER_SU_UNSPEC(p)
9044 ? "None"
9045 : sockunion2str(&p->su, buf,
9046 SU_ADDRSTRLEN));
9047 else /* Configured IP address. */
9048 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9049 p->host);
9050 }
9051
9052 if (use_json) {
9053 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9054 json_object_string_add(json_neigh, "bgpNeighborAddr",
9055 "none");
9056 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9057 json_object_string_add(
9058 json_neigh, "bgpNeighborAddr",
9059 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9060
9061 json_object_int_add(json_neigh, "remoteAs", p->as);
9062
9063 if (p->change_local_as)
9064 json_object_int_add(json_neigh, "localAs",
9065 p->change_local_as);
9066 else
9067 json_object_int_add(json_neigh, "localAs", p->local_as);
9068
9069 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9070 json_object_boolean_true_add(json_neigh,
9071 "localAsNoPrepend");
9072
9073 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9074 json_object_boolean_true_add(json_neigh,
9075 "localAsReplaceAs");
9076 } else {
9077 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9078 || (p->as_type == AS_INTERNAL))
9079 vty_out(vty, "remote AS %u, ", p->as);
9080 else
9081 vty_out(vty, "remote AS Unspecified, ");
9082 vty_out(vty, "local AS %u%s%s, ",
9083 p->change_local_as ? p->change_local_as : p->local_as,
9084 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9085 ? " no-prepend"
9086 : "",
9087 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9088 ? " replace-as"
9089 : "");
9090 }
9091 /* peer type internal, external, confed-internal or confed-external */
9092 if (p->as == p->local_as) {
9093 if (use_json) {
9094 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9095 json_object_boolean_true_add(
9096 json_neigh, "nbrConfedInternalLink");
9097 else
9098 json_object_boolean_true_add(json_neigh,
9099 "nbrInternalLink");
9100 } else {
9101 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9102 vty_out(vty, "confed-internal link\n");
9103 else
9104 vty_out(vty, "internal link\n");
9105 }
9106 } else {
9107 if (use_json) {
9108 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9109 json_object_boolean_true_add(
9110 json_neigh, "nbrConfedExternalLink");
9111 else
9112 json_object_boolean_true_add(json_neigh,
9113 "nbrExternalLink");
9114 } else {
9115 if (bgp_confederation_peers_check(bgp, p->as))
9116 vty_out(vty, "confed-external link\n");
9117 else
9118 vty_out(vty, "external link\n");
9119 }
9120 }
9121
9122 /* Description. */
9123 if (p->desc) {
9124 if (use_json)
9125 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9126 else
9127 vty_out(vty, " Description: %s\n", p->desc);
9128 }
9129
9130 if (p->hostname) {
9131 if (use_json) {
9132 if (p->hostname)
9133 json_object_string_add(json_neigh, "hostname",
9134 p->hostname);
9135
9136 if (p->domainname)
9137 json_object_string_add(json_neigh, "domainname",
9138 p->domainname);
9139 } else {
9140 if (p->domainname && (p->domainname[0] != '\0'))
9141 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9142 p->domainname);
9143 else
9144 vty_out(vty, "Hostname: %s\n", p->hostname);
9145 }
9146 }
9147
9148 /* Peer-group */
9149 if (p->group) {
9150 if (use_json) {
9151 json_object_string_add(json_neigh, "peerGroup",
9152 p->group->name);
9153
9154 if (dn_flag[0]) {
9155 struct prefix prefix, *range = NULL;
9156
9157 sockunion2hostprefix(&(p->su), &prefix);
9158 range = peer_group_lookup_dynamic_neighbor_range(
9159 p->group, &prefix);
9160
9161 if (range) {
9162 prefix2str(range, buf1, sizeof(buf1));
9163 json_object_string_add(
9164 json_neigh,
9165 "peerSubnetRangeGroup", buf1);
9166 }
9167 }
9168 } else {
9169 vty_out(vty,
9170 " Member of peer-group %s for session parameters\n",
9171 p->group->name);
9172
9173 if (dn_flag[0]) {
9174 struct prefix prefix, *range = NULL;
9175
9176 sockunion2hostprefix(&(p->su), &prefix);
9177 range = peer_group_lookup_dynamic_neighbor_range(
9178 p->group, &prefix);
9179
9180 if (range) {
9181 prefix2str(range, buf1, sizeof(buf1));
9182 vty_out(vty,
9183 " Belongs to the subnet range group: %s\n",
9184 buf1);
9185 }
9186 }
9187 }
9188 }
9189
9190 if (use_json) {
9191 /* Administrative shutdown. */
9192 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9193 json_object_boolean_true_add(json_neigh,
9194 "adminShutDown");
9195
9196 /* BGP Version. */
9197 json_object_int_add(json_neigh, "bgpVersion", 4);
9198 json_object_string_add(
9199 json_neigh, "remoteRouterId",
9200 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9201 json_object_string_add(
9202 json_neigh, "localRouterId",
9203 inet_ntop(AF_INET, &bgp->router_id, buf1,
9204 sizeof(buf1)));
9205
9206 /* Confederation */
9207 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9208 && bgp_confederation_peers_check(bgp, p->as))
9209 json_object_boolean_true_add(json_neigh,
9210 "nbrCommonAdmin");
9211
9212 /* Status. */
9213 json_object_string_add(
9214 json_neigh, "bgpState",
9215 lookup_msg(bgp_status_msg, p->status, NULL));
9216
9217 if (p->status == Established) {
9218 time_t uptime;
9219
9220 uptime = bgp_clock();
9221 uptime -= p->uptime;
9222 epoch_tbuf = time(NULL) - uptime;
9223
9224 #if CONFDATE > 20200101
9225 CPP_NOTICE(
9226 "bgpTimerUp should be deprecated and can be removed now");
9227 #endif
9228 /*
9229 * bgpTimerUp was miliseconds that was accurate
9230 * up to 1 day, then the value returned
9231 * became garbage. So in order to provide
9232 * some level of backwards compatability,
9233 * we still provde the data, but now
9234 * we are returning the correct value
9235 * and also adding a new bgpTimerUpMsec
9236 * which will allow us to deprecate
9237 * this eventually
9238 */
9239 json_object_int_add(json_neigh, "bgpTimerUp",
9240 uptime * 1000);
9241 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9242 uptime * 1000);
9243 json_object_string_add(json_neigh, "bgpTimerUpString",
9244 peer_uptime(p->uptime, timebuf,
9245 BGP_UPTIME_LEN, 0,
9246 NULL));
9247 json_object_int_add(json_neigh,
9248 "bgpTimerUpEstablishedEpoch",
9249 epoch_tbuf);
9250 }
9251
9252 else if (p->status == Active) {
9253 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9254 json_object_string_add(json_neigh, "bgpStateIs",
9255 "passive");
9256 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9257 json_object_string_add(json_neigh, "bgpStateIs",
9258 "passiveNSF");
9259 }
9260
9261 /* read timer */
9262 time_t uptime;
9263 struct tm *tm;
9264
9265 uptime = bgp_clock();
9266 uptime -= p->readtime;
9267 tm = gmtime(&uptime);
9268 json_object_int_add(json_neigh, "bgpTimerLastRead",
9269 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9270 + (tm->tm_hour * 3600000));
9271
9272 uptime = bgp_clock();
9273 uptime -= p->last_write;
9274 tm = gmtime(&uptime);
9275 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9276 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9277 + (tm->tm_hour * 3600000));
9278
9279 uptime = bgp_clock();
9280 uptime -= p->update_time;
9281 tm = gmtime(&uptime);
9282 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9283 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9284 + (tm->tm_hour * 3600000));
9285
9286 /* Configured timer values. */
9287 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9288 p->v_holdtime * 1000);
9289 json_object_int_add(json_neigh,
9290 "bgpTimerKeepAliveIntervalMsecs",
9291 p->v_keepalive * 1000);
9292 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9293 json_object_int_add(json_neigh,
9294 "bgpTimerConfiguredHoldTimeMsecs",
9295 p->holdtime * 1000);
9296 json_object_int_add(
9297 json_neigh,
9298 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9299 p->keepalive * 1000);
9300 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9301 || (bgp->default_keepalive
9302 != BGP_DEFAULT_KEEPALIVE)) {
9303 json_object_int_add(json_neigh,
9304 "bgpTimerConfiguredHoldTimeMsecs",
9305 bgp->default_holdtime);
9306 json_object_int_add(
9307 json_neigh,
9308 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9309 bgp->default_keepalive);
9310 }
9311 } else {
9312 /* Administrative shutdown. */
9313 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9314 vty_out(vty, " Administratively shut down\n");
9315
9316 /* BGP Version. */
9317 vty_out(vty, " BGP version 4");
9318 vty_out(vty, ", remote router ID %s",
9319 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9320 vty_out(vty, ", local router ID %s\n",
9321 inet_ntop(AF_INET, &bgp->router_id, buf1,
9322 sizeof(buf1)));
9323
9324 /* Confederation */
9325 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9326 && bgp_confederation_peers_check(bgp, p->as))
9327 vty_out(vty,
9328 " Neighbor under common administration\n");
9329
9330 /* Status. */
9331 vty_out(vty, " BGP state = %s",
9332 lookup_msg(bgp_status_msg, p->status, NULL));
9333
9334 if (p->status == Established)
9335 vty_out(vty, ", up for %8s",
9336 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9337 0, NULL));
9338
9339 else if (p->status == Active) {
9340 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9341 vty_out(vty, " (passive)");
9342 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9343 vty_out(vty, " (NSF passive)");
9344 }
9345 vty_out(vty, "\n");
9346
9347 /* read timer */
9348 vty_out(vty, " Last read %s",
9349 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9350 NULL));
9351 vty_out(vty, ", Last write %s\n",
9352 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9353 NULL));
9354
9355 /* Configured timer values. */
9356 vty_out(vty,
9357 " Hold time is %d, keepalive interval is %d seconds\n",
9358 p->v_holdtime, p->v_keepalive);
9359 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9360 vty_out(vty, " Configured hold time is %d",
9361 p->holdtime);
9362 vty_out(vty, ", keepalive interval is %d seconds\n",
9363 p->keepalive);
9364 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9365 || (bgp->default_keepalive
9366 != BGP_DEFAULT_KEEPALIVE)) {
9367 vty_out(vty, " Configured hold time is %d",
9368 bgp->default_holdtime);
9369 vty_out(vty, ", keepalive interval is %d seconds\n",
9370 bgp->default_keepalive);
9371 }
9372 }
9373 /* Capability. */
9374 if (p->status == Established) {
9375 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9376 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9377 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9378 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9379 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9380 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9381 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9382 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9383 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9384 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9385 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9386 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9387 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9388 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9389 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9390 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9391 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9392 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9393 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9394 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9395 if (use_json) {
9396 json_object *json_cap = NULL;
9397
9398 json_cap = json_object_new_object();
9399
9400 /* AS4 */
9401 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9402 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9403 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9404 && CHECK_FLAG(p->cap,
9405 PEER_CAP_AS4_RCV))
9406 json_object_string_add(
9407 json_cap, "4byteAs",
9408 "advertisedAndReceived");
9409 else if (CHECK_FLAG(p->cap,
9410 PEER_CAP_AS4_ADV))
9411 json_object_string_add(
9412 json_cap, "4byteAs",
9413 "advertised");
9414 else if (CHECK_FLAG(p->cap,
9415 PEER_CAP_AS4_RCV))
9416 json_object_string_add(
9417 json_cap, "4byteAs",
9418 "received");
9419 }
9420
9421 /* AddPath */
9422 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9423 || CHECK_FLAG(p->cap,
9424 PEER_CAP_ADDPATH_ADV)) {
9425 json_object *json_add = NULL;
9426 const char *print_store;
9427
9428 json_add = json_object_new_object();
9429
9430 FOREACH_AFI_SAFI (afi, safi) {
9431 json_object *json_sub = NULL;
9432 json_sub =
9433 json_object_new_object();
9434 print_store = afi_safi_print(
9435 afi, safi);
9436
9437 if (CHECK_FLAG(
9438 p->af_cap[afi]
9439 [safi],
9440 PEER_CAP_ADDPATH_AF_TX_ADV)
9441 || CHECK_FLAG(
9442 p->af_cap[afi]
9443 [safi],
9444 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9445 if (CHECK_FLAG(
9446 p->af_cap
9447 [afi]
9448 [safi],
9449 PEER_CAP_ADDPATH_AF_TX_ADV)
9450 && CHECK_FLAG(
9451 p->af_cap
9452 [afi]
9453 [safi],
9454 PEER_CAP_ADDPATH_AF_TX_RCV))
9455 json_object_boolean_true_add(
9456 json_sub,
9457 "txAdvertisedAndReceived");
9458 else if (
9459 CHECK_FLAG(
9460 p->af_cap
9461 [afi]
9462 [safi],
9463 PEER_CAP_ADDPATH_AF_TX_ADV))
9464 json_object_boolean_true_add(
9465 json_sub,
9466 "txAdvertised");
9467 else if (
9468 CHECK_FLAG(
9469 p->af_cap
9470 [afi]
9471 [safi],
9472 PEER_CAP_ADDPATH_AF_TX_RCV))
9473 json_object_boolean_true_add(
9474 json_sub,
9475 "txReceived");
9476 }
9477
9478 if (CHECK_FLAG(
9479 p->af_cap[afi]
9480 [safi],
9481 PEER_CAP_ADDPATH_AF_RX_ADV)
9482 || CHECK_FLAG(
9483 p->af_cap[afi]
9484 [safi],
9485 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9486 if (CHECK_FLAG(
9487 p->af_cap
9488 [afi]
9489 [safi],
9490 PEER_CAP_ADDPATH_AF_RX_ADV)
9491 && CHECK_FLAG(
9492 p->af_cap
9493 [afi]
9494 [safi],
9495 PEER_CAP_ADDPATH_AF_RX_RCV))
9496 json_object_boolean_true_add(
9497 json_sub,
9498 "rxAdvertisedAndReceived");
9499 else if (
9500 CHECK_FLAG(
9501 p->af_cap
9502 [afi]
9503 [safi],
9504 PEER_CAP_ADDPATH_AF_RX_ADV))
9505 json_object_boolean_true_add(
9506 json_sub,
9507 "rxAdvertised");
9508 else if (
9509 CHECK_FLAG(
9510 p->af_cap
9511 [afi]
9512 [safi],
9513 PEER_CAP_ADDPATH_AF_RX_RCV))
9514 json_object_boolean_true_add(
9515 json_sub,
9516 "rxReceived");
9517 }
9518
9519 if (CHECK_FLAG(
9520 p->af_cap[afi]
9521 [safi],
9522 PEER_CAP_ADDPATH_AF_TX_ADV)
9523 || CHECK_FLAG(
9524 p->af_cap[afi]
9525 [safi],
9526 PEER_CAP_ADDPATH_AF_TX_RCV)
9527 || CHECK_FLAG(
9528 p->af_cap[afi]
9529 [safi],
9530 PEER_CAP_ADDPATH_AF_RX_ADV)
9531 || CHECK_FLAG(
9532 p->af_cap[afi]
9533 [safi],
9534 PEER_CAP_ADDPATH_AF_RX_RCV))
9535 json_object_object_add(
9536 json_add,
9537 print_store,
9538 json_sub);
9539 else
9540 json_object_free(
9541 json_sub);
9542 }
9543
9544 json_object_object_add(
9545 json_cap, "addPath", json_add);
9546 }
9547
9548 /* Dynamic */
9549 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9550 || CHECK_FLAG(p->cap,
9551 PEER_CAP_DYNAMIC_ADV)) {
9552 if (CHECK_FLAG(p->cap,
9553 PEER_CAP_DYNAMIC_ADV)
9554 && CHECK_FLAG(p->cap,
9555 PEER_CAP_DYNAMIC_RCV))
9556 json_object_string_add(
9557 json_cap, "dynamic",
9558 "advertisedAndReceived");
9559 else if (CHECK_FLAG(
9560 p->cap,
9561 PEER_CAP_DYNAMIC_ADV))
9562 json_object_string_add(
9563 json_cap, "dynamic",
9564 "advertised");
9565 else if (CHECK_FLAG(
9566 p->cap,
9567 PEER_CAP_DYNAMIC_RCV))
9568 json_object_string_add(
9569 json_cap, "dynamic",
9570 "received");
9571 }
9572
9573 /* Extended nexthop */
9574 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9575 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9576 json_object *json_nxt = NULL;
9577 const char *print_store;
9578
9579
9580 if (CHECK_FLAG(p->cap,
9581 PEER_CAP_ENHE_ADV)
9582 && CHECK_FLAG(p->cap,
9583 PEER_CAP_ENHE_RCV))
9584 json_object_string_add(
9585 json_cap,
9586 "extendedNexthop",
9587 "advertisedAndReceived");
9588 else if (CHECK_FLAG(p->cap,
9589 PEER_CAP_ENHE_ADV))
9590 json_object_string_add(
9591 json_cap,
9592 "extendedNexthop",
9593 "advertised");
9594 else if (CHECK_FLAG(p->cap,
9595 PEER_CAP_ENHE_RCV))
9596 json_object_string_add(
9597 json_cap,
9598 "extendedNexthop",
9599 "received");
9600
9601 if (CHECK_FLAG(p->cap,
9602 PEER_CAP_ENHE_RCV)) {
9603 json_nxt =
9604 json_object_new_object();
9605
9606 for (safi = SAFI_UNICAST;
9607 safi < SAFI_MAX; safi++) {
9608 if (CHECK_FLAG(
9609 p->af_cap
9610 [AFI_IP]
9611 [safi],
9612 PEER_CAP_ENHE_AF_RCV)) {
9613 print_store = afi_safi_print(
9614 AFI_IP,
9615 safi);
9616 json_object_string_add(
9617 json_nxt,
9618 print_store,
9619 "received");
9620 }
9621 }
9622 json_object_object_add(
9623 json_cap,
9624 "extendedNexthopFamililesByPeer",
9625 json_nxt);
9626 }
9627 }
9628
9629 /* Route Refresh */
9630 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9631 || CHECK_FLAG(p->cap,
9632 PEER_CAP_REFRESH_NEW_RCV)
9633 || CHECK_FLAG(p->cap,
9634 PEER_CAP_REFRESH_OLD_RCV)) {
9635 if (CHECK_FLAG(p->cap,
9636 PEER_CAP_REFRESH_ADV)
9637 && (CHECK_FLAG(
9638 p->cap,
9639 PEER_CAP_REFRESH_NEW_RCV)
9640 || CHECK_FLAG(
9641 p->cap,
9642 PEER_CAP_REFRESH_OLD_RCV))) {
9643 if (CHECK_FLAG(
9644 p->cap,
9645 PEER_CAP_REFRESH_OLD_RCV)
9646 && CHECK_FLAG(
9647 p->cap,
9648 PEER_CAP_REFRESH_NEW_RCV))
9649 json_object_string_add(
9650 json_cap,
9651 "routeRefresh",
9652 "advertisedAndReceivedOldNew");
9653 else {
9654 if (CHECK_FLAG(
9655 p->cap,
9656 PEER_CAP_REFRESH_OLD_RCV))
9657 json_object_string_add(
9658 json_cap,
9659 "routeRefresh",
9660 "advertisedAndReceivedOld");
9661 else
9662 json_object_string_add(
9663 json_cap,
9664 "routeRefresh",
9665 "advertisedAndReceivedNew");
9666 }
9667 } else if (
9668 CHECK_FLAG(
9669 p->cap,
9670 PEER_CAP_REFRESH_ADV))
9671 json_object_string_add(
9672 json_cap,
9673 "routeRefresh",
9674 "advertised");
9675 else if (
9676 CHECK_FLAG(
9677 p->cap,
9678 PEER_CAP_REFRESH_NEW_RCV)
9679 || CHECK_FLAG(
9680 p->cap,
9681 PEER_CAP_REFRESH_OLD_RCV))
9682 json_object_string_add(
9683 json_cap,
9684 "routeRefresh",
9685 "received");
9686 }
9687
9688 /* Multiprotocol Extensions */
9689 json_object *json_multi = NULL;
9690 json_multi = json_object_new_object();
9691
9692 FOREACH_AFI_SAFI (afi, safi) {
9693 if (p->afc_adv[afi][safi]
9694 || p->afc_recv[afi][safi]) {
9695 json_object *json_exten = NULL;
9696 json_exten =
9697 json_object_new_object();
9698
9699 if (p->afc_adv[afi][safi]
9700 && p->afc_recv[afi][safi])
9701 json_object_boolean_true_add(
9702 json_exten,
9703 "advertisedAndReceived");
9704 else if (p->afc_adv[afi][safi])
9705 json_object_boolean_true_add(
9706 json_exten,
9707 "advertised");
9708 else if (p->afc_recv[afi][safi])
9709 json_object_boolean_true_add(
9710 json_exten,
9711 "received");
9712
9713 json_object_object_add(
9714 json_multi,
9715 afi_safi_print(afi,
9716 safi),
9717 json_exten);
9718 }
9719 }
9720 json_object_object_add(
9721 json_cap, "multiprotocolExtensions",
9722 json_multi);
9723
9724 /* Hostname capabilities */
9725 json_object *json_hname = NULL;
9726
9727 json_hname = json_object_new_object();
9728
9729 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9730 json_object_string_add(
9731 json_hname, "advHostName",
9732 bgp->peer_self->hostname
9733 ? bgp->peer_self
9734 ->hostname
9735 : "n/a");
9736 json_object_string_add(
9737 json_hname, "advDomainName",
9738 bgp->peer_self->domainname
9739 ? bgp->peer_self
9740 ->domainname
9741 : "n/a");
9742 }
9743
9744
9745 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9746 json_object_string_add(
9747 json_hname, "rcvHostName",
9748 p->hostname ? p->hostname
9749 : "n/a");
9750 json_object_string_add(
9751 json_hname, "rcvDomainName",
9752 p->domainname ? p->domainname
9753 : "n/a");
9754 }
9755
9756 json_object_object_add(json_cap, "hostName",
9757 json_hname);
9758
9759 /* Gracefull Restart */
9760 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9761 || CHECK_FLAG(p->cap,
9762 PEER_CAP_RESTART_ADV)) {
9763 if (CHECK_FLAG(p->cap,
9764 PEER_CAP_RESTART_ADV)
9765 && CHECK_FLAG(p->cap,
9766 PEER_CAP_RESTART_RCV))
9767 json_object_string_add(
9768 json_cap,
9769 "gracefulRestart",
9770 "advertisedAndReceived");
9771 else if (CHECK_FLAG(
9772 p->cap,
9773 PEER_CAP_RESTART_ADV))
9774 json_object_string_add(
9775 json_cap,
9776 "gracefulRestartCapability",
9777 "advertised");
9778 else if (CHECK_FLAG(
9779 p->cap,
9780 PEER_CAP_RESTART_RCV))
9781 json_object_string_add(
9782 json_cap,
9783 "gracefulRestartCapability",
9784 "received");
9785
9786 if (CHECK_FLAG(p->cap,
9787 PEER_CAP_RESTART_RCV)) {
9788 int restart_af_count = 0;
9789 json_object *json_restart =
9790 NULL;
9791 json_restart =
9792 json_object_new_object();
9793
9794 json_object_int_add(
9795 json_cap,
9796 "gracefulRestartRemoteTimerMsecs",
9797 p->v_gr_restart * 1000);
9798
9799 FOREACH_AFI_SAFI (afi, safi) {
9800 if (CHECK_FLAG(
9801 p->af_cap
9802 [afi]
9803 [safi],
9804 PEER_CAP_RESTART_AF_RCV)) {
9805 json_object *
9806 json_sub =
9807 NULL;
9808 json_sub =
9809 json_object_new_object();
9810
9811 if (CHECK_FLAG(
9812 p->af_cap
9813 [afi]
9814 [safi],
9815 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9816 json_object_boolean_true_add(
9817 json_sub,
9818 "preserved");
9819 restart_af_count++;
9820 json_object_object_add(
9821 json_restart,
9822 afi_safi_print(
9823 afi,
9824 safi),
9825 json_sub);
9826 }
9827 }
9828 if (!restart_af_count) {
9829 json_object_string_add(
9830 json_cap,
9831 "addressFamiliesByPeer",
9832 "none");
9833 json_object_free(
9834 json_restart);
9835 } else
9836 json_object_object_add(
9837 json_cap,
9838 "addressFamiliesByPeer",
9839 json_restart);
9840 }
9841 }
9842 json_object_object_add(json_neigh,
9843 "neighborCapabilities",
9844 json_cap);
9845 } else {
9846 vty_out(vty, " Neighbor capabilities:\n");
9847
9848 /* AS4 */
9849 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9850 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9851 vty_out(vty, " 4 Byte AS:");
9852 if (CHECK_FLAG(p->cap,
9853 PEER_CAP_AS4_ADV))
9854 vty_out(vty, " advertised");
9855 if (CHECK_FLAG(p->cap,
9856 PEER_CAP_AS4_RCV))
9857 vty_out(vty, " %sreceived",
9858 CHECK_FLAG(
9859 p->cap,
9860 PEER_CAP_AS4_ADV)
9861 ? "and "
9862 : "");
9863 vty_out(vty, "\n");
9864 }
9865
9866 /* AddPath */
9867 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9868 || CHECK_FLAG(p->cap,
9869 PEER_CAP_ADDPATH_ADV)) {
9870 vty_out(vty, " AddPath:\n");
9871
9872 FOREACH_AFI_SAFI (afi, safi) {
9873 if (CHECK_FLAG(
9874 p->af_cap[afi]
9875 [safi],
9876 PEER_CAP_ADDPATH_AF_TX_ADV)
9877 || CHECK_FLAG(
9878 p->af_cap[afi]
9879 [safi],
9880 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9881 vty_out(vty,
9882 " %s: TX ",
9883 afi_safi_print(
9884 afi,
9885 safi));
9886
9887 if (CHECK_FLAG(
9888 p->af_cap
9889 [afi]
9890 [safi],
9891 PEER_CAP_ADDPATH_AF_TX_ADV))
9892 vty_out(vty,
9893 "advertised %s",
9894 afi_safi_print(
9895 afi,
9896 safi));
9897
9898 if (CHECK_FLAG(
9899 p->af_cap
9900 [afi]
9901 [safi],
9902 PEER_CAP_ADDPATH_AF_TX_RCV))
9903 vty_out(vty,
9904 "%sreceived",
9905 CHECK_FLAG(
9906 p->af_cap
9907 [afi]
9908 [safi],
9909 PEER_CAP_ADDPATH_AF_TX_ADV)
9910 ? " and "
9911 : "");
9912
9913 vty_out(vty, "\n");
9914 }
9915
9916 if (CHECK_FLAG(
9917 p->af_cap[afi]
9918 [safi],
9919 PEER_CAP_ADDPATH_AF_RX_ADV)
9920 || CHECK_FLAG(
9921 p->af_cap[afi]
9922 [safi],
9923 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9924 vty_out(vty,
9925 " %s: RX ",
9926 afi_safi_print(
9927 afi,
9928 safi));
9929
9930 if (CHECK_FLAG(
9931 p->af_cap
9932 [afi]
9933 [safi],
9934 PEER_CAP_ADDPATH_AF_RX_ADV))
9935 vty_out(vty,
9936 "advertised %s",
9937 afi_safi_print(
9938 afi,
9939 safi));
9940
9941 if (CHECK_FLAG(
9942 p->af_cap
9943 [afi]
9944 [safi],
9945 PEER_CAP_ADDPATH_AF_RX_RCV))
9946 vty_out(vty,
9947 "%sreceived",
9948 CHECK_FLAG(
9949 p->af_cap
9950 [afi]
9951 [safi],
9952 PEER_CAP_ADDPATH_AF_RX_ADV)
9953 ? " and "
9954 : "");
9955
9956 vty_out(vty, "\n");
9957 }
9958 }
9959 }
9960
9961 /* Dynamic */
9962 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9963 || CHECK_FLAG(p->cap,
9964 PEER_CAP_DYNAMIC_ADV)) {
9965 vty_out(vty, " Dynamic:");
9966 if (CHECK_FLAG(p->cap,
9967 PEER_CAP_DYNAMIC_ADV))
9968 vty_out(vty, " advertised");
9969 if (CHECK_FLAG(p->cap,
9970 PEER_CAP_DYNAMIC_RCV))
9971 vty_out(vty, " %sreceived",
9972 CHECK_FLAG(
9973 p->cap,
9974 PEER_CAP_DYNAMIC_ADV)
9975 ? "and "
9976 : "");
9977 vty_out(vty, "\n");
9978 }
9979
9980 /* Extended nexthop */
9981 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9982 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9983 vty_out(vty, " Extended nexthop:");
9984 if (CHECK_FLAG(p->cap,
9985 PEER_CAP_ENHE_ADV))
9986 vty_out(vty, " advertised");
9987 if (CHECK_FLAG(p->cap,
9988 PEER_CAP_ENHE_RCV))
9989 vty_out(vty, " %sreceived",
9990 CHECK_FLAG(
9991 p->cap,
9992 PEER_CAP_ENHE_ADV)
9993 ? "and "
9994 : "");
9995 vty_out(vty, "\n");
9996
9997 if (CHECK_FLAG(p->cap,
9998 PEER_CAP_ENHE_RCV)) {
9999 vty_out(vty,
10000 " Address families by peer:\n ");
10001 for (safi = SAFI_UNICAST;
10002 safi < SAFI_MAX; safi++)
10003 if (CHECK_FLAG(
10004 p->af_cap
10005 [AFI_IP]
10006 [safi],
10007 PEER_CAP_ENHE_AF_RCV))
10008 vty_out(vty,
10009 " %s\n",
10010 afi_safi_print(
10011 AFI_IP,
10012 safi));
10013 }
10014 }
10015
10016 /* Route Refresh */
10017 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
10018 || CHECK_FLAG(p->cap,
10019 PEER_CAP_REFRESH_NEW_RCV)
10020 || CHECK_FLAG(p->cap,
10021 PEER_CAP_REFRESH_OLD_RCV)) {
10022 vty_out(vty, " Route refresh:");
10023 if (CHECK_FLAG(p->cap,
10024 PEER_CAP_REFRESH_ADV))
10025 vty_out(vty, " advertised");
10026 if (CHECK_FLAG(p->cap,
10027 PEER_CAP_REFRESH_NEW_RCV)
10028 || CHECK_FLAG(
10029 p->cap,
10030 PEER_CAP_REFRESH_OLD_RCV))
10031 vty_out(vty, " %sreceived(%s)",
10032 CHECK_FLAG(
10033 p->cap,
10034 PEER_CAP_REFRESH_ADV)
10035 ? "and "
10036 : "",
10037 (CHECK_FLAG(
10038 p->cap,
10039 PEER_CAP_REFRESH_OLD_RCV)
10040 && CHECK_FLAG(
10041 p->cap,
10042 PEER_CAP_REFRESH_NEW_RCV))
10043 ? "old & new"
10044 : CHECK_FLAG(
10045 p->cap,
10046 PEER_CAP_REFRESH_OLD_RCV)
10047 ? "old"
10048 : "new");
10049
10050 vty_out(vty, "\n");
10051 }
10052
10053 /* Multiprotocol Extensions */
10054 FOREACH_AFI_SAFI (afi, safi)
10055 if (p->afc_adv[afi][safi]
10056 || p->afc_recv[afi][safi]) {
10057 vty_out(vty,
10058 " Address Family %s:",
10059 afi_safi_print(afi,
10060 safi));
10061 if (p->afc_adv[afi][safi])
10062 vty_out(vty,
10063 " advertised");
10064 if (p->afc_recv[afi][safi])
10065 vty_out(vty,
10066 " %sreceived",
10067 p->afc_adv[afi]
10068 [safi]
10069 ? "and "
10070 : "");
10071 vty_out(vty, "\n");
10072 }
10073
10074 /* Hostname capability */
10075 vty_out(vty, " Hostname Capability:");
10076
10077 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10078 vty_out(vty,
10079 " advertised (name: %s,domain name: %s)",
10080 bgp->peer_self->hostname
10081 ? bgp->peer_self
10082 ->hostname
10083 : "n/a",
10084 bgp->peer_self->domainname
10085 ? bgp->peer_self
10086 ->domainname
10087 : "n/a");
10088 } else {
10089 vty_out(vty, " not advertised");
10090 }
10091
10092 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10093 vty_out(vty,
10094 " received (name: %s,domain name: %s)",
10095 p->hostname ? p->hostname
10096 : "n/a",
10097 p->domainname ? p->domainname
10098 : "n/a");
10099 } else {
10100 vty_out(vty, " not received");
10101 }
10102
10103 vty_out(vty, "\n");
10104
10105 /* Gracefull Restart */
10106 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10107 || CHECK_FLAG(p->cap,
10108 PEER_CAP_RESTART_ADV)) {
10109 vty_out(vty,
10110 " Graceful Restart Capabilty:");
10111 if (CHECK_FLAG(p->cap,
10112 PEER_CAP_RESTART_ADV))
10113 vty_out(vty, " advertised");
10114 if (CHECK_FLAG(p->cap,
10115 PEER_CAP_RESTART_RCV))
10116 vty_out(vty, " %sreceived",
10117 CHECK_FLAG(
10118 p->cap,
10119 PEER_CAP_RESTART_ADV)
10120 ? "and "
10121 : "");
10122 vty_out(vty, "\n");
10123
10124 if (CHECK_FLAG(p->cap,
10125 PEER_CAP_RESTART_RCV)) {
10126 int restart_af_count = 0;
10127
10128 vty_out(vty,
10129 " Remote Restart timer is %d seconds\n",
10130 p->v_gr_restart);
10131 vty_out(vty,
10132 " Address families by peer:\n ");
10133
10134 FOREACH_AFI_SAFI (afi, safi)
10135 if (CHECK_FLAG(
10136 p->af_cap
10137 [afi]
10138 [safi],
10139 PEER_CAP_RESTART_AF_RCV)) {
10140 vty_out(vty,
10141 "%s%s(%s)",
10142 restart_af_count
10143 ? ", "
10144 : "",
10145 afi_safi_print(
10146 afi,
10147 safi),
10148 CHECK_FLAG(
10149 p->af_cap
10150 [afi]
10151 [safi],
10152 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10153 ? "preserved"
10154 : "not preserved");
10155 restart_af_count++;
10156 }
10157 if (!restart_af_count)
10158 vty_out(vty, "none");
10159 vty_out(vty, "\n");
10160 }
10161 }
10162 }
10163 }
10164 }
10165
10166 /* graceful restart information */
10167 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10168 || p->t_gr_stale) {
10169 json_object *json_grace = NULL;
10170 json_object *json_grace_send = NULL;
10171 json_object *json_grace_recv = NULL;
10172 int eor_send_af_count = 0;
10173 int eor_receive_af_count = 0;
10174
10175 if (use_json) {
10176 json_grace = json_object_new_object();
10177 json_grace_send = json_object_new_object();
10178 json_grace_recv = json_object_new_object();
10179
10180 if (p->status == Established) {
10181 FOREACH_AFI_SAFI (afi, safi) {
10182 if (CHECK_FLAG(p->af_sflags[afi][safi],
10183 PEER_STATUS_EOR_SEND)) {
10184 json_object_boolean_true_add(
10185 json_grace_send,
10186 afi_safi_print(afi,
10187 safi));
10188 eor_send_af_count++;
10189 }
10190 }
10191 FOREACH_AFI_SAFI (afi, safi) {
10192 if (CHECK_FLAG(
10193 p->af_sflags[afi][safi],
10194 PEER_STATUS_EOR_RECEIVED)) {
10195 json_object_boolean_true_add(
10196 json_grace_recv,
10197 afi_safi_print(afi,
10198 safi));
10199 eor_receive_af_count++;
10200 }
10201 }
10202 }
10203
10204 json_object_object_add(json_grace, "endOfRibSend",
10205 json_grace_send);
10206 json_object_object_add(json_grace, "endOfRibRecv",
10207 json_grace_recv);
10208
10209 if (p->t_gr_restart)
10210 json_object_int_add(json_grace,
10211 "gracefulRestartTimerMsecs",
10212 thread_timer_remain_second(
10213 p->t_gr_restart)
10214 * 1000);
10215
10216 if (p->t_gr_stale)
10217 json_object_int_add(
10218 json_grace,
10219 "gracefulStalepathTimerMsecs",
10220 thread_timer_remain_second(
10221 p->t_gr_stale)
10222 * 1000);
10223
10224 json_object_object_add(
10225 json_neigh, "gracefulRestartInfo", json_grace);
10226 } else {
10227 vty_out(vty, " Graceful restart information:\n");
10228 if (p->status == Established) {
10229 vty_out(vty, " End-of-RIB send: ");
10230 FOREACH_AFI_SAFI (afi, safi) {
10231 if (CHECK_FLAG(p->af_sflags[afi][safi],
10232 PEER_STATUS_EOR_SEND)) {
10233 vty_out(vty, "%s%s",
10234 eor_send_af_count ? ", "
10235 : "",
10236 afi_safi_print(afi,
10237 safi));
10238 eor_send_af_count++;
10239 }
10240 }
10241 vty_out(vty, "\n");
10242 vty_out(vty, " End-of-RIB received: ");
10243 FOREACH_AFI_SAFI (afi, safi) {
10244 if (CHECK_FLAG(
10245 p->af_sflags[afi][safi],
10246 PEER_STATUS_EOR_RECEIVED)) {
10247 vty_out(vty, "%s%s",
10248 eor_receive_af_count
10249 ? ", "
10250 : "",
10251 afi_safi_print(afi,
10252 safi));
10253 eor_receive_af_count++;
10254 }
10255 }
10256 vty_out(vty, "\n");
10257 }
10258
10259 if (p->t_gr_restart)
10260 vty_out(vty,
10261 " The remaining time of restart timer is %ld\n",
10262 thread_timer_remain_second(
10263 p->t_gr_restart));
10264
10265 if (p->t_gr_stale)
10266 vty_out(vty,
10267 " The remaining time of stalepath timer is %ld\n",
10268 thread_timer_remain_second(
10269 p->t_gr_stale));
10270 }
10271 }
10272 if (use_json) {
10273 json_object *json_stat = NULL;
10274 json_stat = json_object_new_object();
10275 /* Packet counts. */
10276 json_object_int_add(json_stat, "depthInq", 0);
10277 json_object_int_add(json_stat, "depthOutq",
10278 (unsigned long)p->obuf->count);
10279 json_object_int_add(json_stat, "opensSent",
10280 atomic_load_explicit(&p->open_out,
10281 memory_order_relaxed));
10282 json_object_int_add(json_stat, "opensRecv",
10283 atomic_load_explicit(&p->open_in,
10284 memory_order_relaxed));
10285 json_object_int_add(json_stat, "notificationsSent",
10286 atomic_load_explicit(&p->notify_out,
10287 memory_order_relaxed));
10288 json_object_int_add(json_stat, "notificationsRecv",
10289 atomic_load_explicit(&p->notify_in,
10290 memory_order_relaxed));
10291 json_object_int_add(json_stat, "updatesSent",
10292 atomic_load_explicit(&p->update_out,
10293 memory_order_relaxed));
10294 json_object_int_add(json_stat, "updatesRecv",
10295 atomic_load_explicit(&p->update_in,
10296 memory_order_relaxed));
10297 json_object_int_add(json_stat, "keepalivesSent",
10298 atomic_load_explicit(&p->keepalive_out,
10299 memory_order_relaxed));
10300 json_object_int_add(json_stat, "keepalivesRecv",
10301 atomic_load_explicit(&p->keepalive_in,
10302 memory_order_relaxed));
10303 json_object_int_add(json_stat, "routeRefreshSent",
10304 atomic_load_explicit(&p->refresh_out,
10305 memory_order_relaxed));
10306 json_object_int_add(json_stat, "routeRefreshRecv",
10307 atomic_load_explicit(&p->refresh_in,
10308 memory_order_relaxed));
10309 json_object_int_add(json_stat, "capabilitySent",
10310 atomic_load_explicit(&p->dynamic_cap_out,
10311 memory_order_relaxed));
10312 json_object_int_add(json_stat, "capabilityRecv",
10313 atomic_load_explicit(&p->dynamic_cap_in,
10314 memory_order_relaxed));
10315 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10316 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10317 json_object_object_add(json_neigh, "messageStats", json_stat);
10318 } else {
10319 /* Packet counts. */
10320 vty_out(vty, " Message statistics:\n");
10321 vty_out(vty, " Inq depth is 0\n");
10322 vty_out(vty, " Outq depth is %lu\n",
10323 (unsigned long)p->obuf->count);
10324 vty_out(vty, " Sent Rcvd\n");
10325 vty_out(vty, " Opens: %10d %10d\n",
10326 atomic_load_explicit(&p->open_out,
10327 memory_order_relaxed),
10328 atomic_load_explicit(&p->open_in,
10329 memory_order_relaxed));
10330 vty_out(vty, " Notifications: %10d %10d\n",
10331 atomic_load_explicit(&p->notify_out,
10332 memory_order_relaxed),
10333 atomic_load_explicit(&p->notify_in,
10334 memory_order_relaxed));
10335 vty_out(vty, " Updates: %10d %10d\n",
10336 atomic_load_explicit(&p->update_out,
10337 memory_order_relaxed),
10338 atomic_load_explicit(&p->update_in,
10339 memory_order_relaxed));
10340 vty_out(vty, " Keepalives: %10d %10d\n",
10341 atomic_load_explicit(&p->keepalive_out,
10342 memory_order_relaxed),
10343 atomic_load_explicit(&p->keepalive_in,
10344 memory_order_relaxed));
10345 vty_out(vty, " Route Refresh: %10d %10d\n",
10346 atomic_load_explicit(&p->refresh_out,
10347 memory_order_relaxed),
10348 atomic_load_explicit(&p->refresh_in,
10349 memory_order_relaxed));
10350 vty_out(vty, " Capability: %10d %10d\n",
10351 atomic_load_explicit(&p->dynamic_cap_out,
10352 memory_order_relaxed),
10353 atomic_load_explicit(&p->dynamic_cap_in,
10354 memory_order_relaxed));
10355 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10356 PEER_TOTAL_RX(p));
10357 }
10358
10359 if (use_json) {
10360 /* advertisement-interval */
10361 json_object_int_add(json_neigh,
10362 "minBtwnAdvertisementRunsTimerMsecs",
10363 p->v_routeadv * 1000);
10364
10365 /* Update-source. */
10366 if (p->update_if || p->update_source) {
10367 if (p->update_if)
10368 json_object_string_add(json_neigh,
10369 "updateSource",
10370 p->update_if);
10371 else if (p->update_source)
10372 json_object_string_add(
10373 json_neigh, "updateSource",
10374 sockunion2str(p->update_source, buf1,
10375 SU_ADDRSTRLEN));
10376 }
10377 } else {
10378 /* advertisement-interval */
10379 vty_out(vty,
10380 " Minimum time between advertisement runs is %d seconds\n",
10381 p->v_routeadv);
10382
10383 /* Update-source. */
10384 if (p->update_if || p->update_source) {
10385 vty_out(vty, " Update source is ");
10386 if (p->update_if)
10387 vty_out(vty, "%s", p->update_if);
10388 else if (p->update_source)
10389 vty_out(vty, "%s",
10390 sockunion2str(p->update_source, buf1,
10391 SU_ADDRSTRLEN));
10392 vty_out(vty, "\n");
10393 }
10394
10395 vty_out(vty, "\n");
10396 }
10397
10398 /* Address Family Information */
10399 json_object *json_hold = NULL;
10400
10401 if (use_json)
10402 json_hold = json_object_new_object();
10403
10404 FOREACH_AFI_SAFI (afi, safi)
10405 if (p->afc[afi][safi])
10406 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10407 json_hold);
10408
10409 if (use_json) {
10410 json_object_object_add(json_neigh, "addressFamilyInfo",
10411 json_hold);
10412 json_object_int_add(json_neigh, "connectionsEstablished",
10413 p->established);
10414 json_object_int_add(json_neigh, "connectionsDropped",
10415 p->dropped);
10416 } else
10417 vty_out(vty, " Connections established %d; dropped %d\n",
10418 p->established, p->dropped);
10419
10420 if (!p->last_reset) {
10421 if (use_json)
10422 json_object_string_add(json_neigh, "lastReset",
10423 "never");
10424 else
10425 vty_out(vty, " Last reset never\n");
10426 } else {
10427 if (use_json) {
10428 time_t uptime;
10429 struct tm *tm;
10430
10431 uptime = bgp_clock();
10432 uptime -= p->resettime;
10433 tm = gmtime(&uptime);
10434 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10435 (tm->tm_sec * 1000)
10436 + (tm->tm_min * 60000)
10437 + (tm->tm_hour * 3600000));
10438 json_object_string_add(
10439 json_neigh, "lastResetDueTo",
10440 peer_down_str[(int)p->last_reset]);
10441 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10442 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10443 char errorcodesubcode_hexstr[5];
10444 char errorcodesubcode_str[256];
10445
10446 code_str = bgp_notify_code_str(p->notify.code);
10447 subcode_str = bgp_notify_subcode_str(
10448 p->notify.code, p->notify.subcode);
10449
10450 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10451 p->notify.code, p->notify.subcode);
10452 json_object_string_add(json_neigh,
10453 "lastErrorCodeSubcode",
10454 errorcodesubcode_hexstr);
10455 snprintf(errorcodesubcode_str, 255, "%s%s",
10456 code_str, subcode_str);
10457 json_object_string_add(json_neigh,
10458 "lastNotificationReason",
10459 errorcodesubcode_str);
10460 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10461 && p->notify.code == BGP_NOTIFY_CEASE
10462 && (p->notify.subcode
10463 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10464 || p->notify.subcode
10465 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10466 && p->notify.length) {
10467 char msgbuf[1024];
10468 const char *msg_str;
10469
10470 msg_str = bgp_notify_admin_message(
10471 msgbuf, sizeof(msgbuf),
10472 (uint8_t *)p->notify.data,
10473 p->notify.length);
10474 if (msg_str)
10475 json_object_string_add(
10476 json_neigh,
10477 "lastShutdownDescription",
10478 msg_str);
10479 }
10480 }
10481 } else {
10482 vty_out(vty, " Last reset %s, ",
10483 peer_uptime(p->resettime, timebuf,
10484 BGP_UPTIME_LEN, 0, NULL));
10485
10486 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10487 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10488 code_str = bgp_notify_code_str(p->notify.code);
10489 subcode_str = bgp_notify_subcode_str(
10490 p->notify.code, p->notify.subcode);
10491 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10492 p->last_reset == PEER_DOWN_NOTIFY_SEND
10493 ? "sent"
10494 : "received",
10495 code_str, subcode_str);
10496 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10497 && p->notify.code == BGP_NOTIFY_CEASE
10498 && (p->notify.subcode
10499 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10500 || p->notify.subcode
10501 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10502 && p->notify.length) {
10503 char msgbuf[1024];
10504 const char *msg_str;
10505
10506 msg_str = bgp_notify_admin_message(
10507 msgbuf, sizeof(msgbuf),
10508 (uint8_t *)p->notify.data,
10509 p->notify.length);
10510 if (msg_str)
10511 vty_out(vty,
10512 " Message: \"%s\"\n",
10513 msg_str);
10514 }
10515 } else {
10516 vty_out(vty, "due to %s\n",
10517 peer_down_str[(int)p->last_reset]);
10518 }
10519
10520 if (p->last_reset_cause_size) {
10521 msg = p->last_reset_cause;
10522 vty_out(vty,
10523 " Message received that caused BGP to send a NOTIFICATION:\n ");
10524 for (i = 1; i <= p->last_reset_cause_size;
10525 i++) {
10526 vty_out(vty, "%02X", *msg++);
10527
10528 if (i != p->last_reset_cause_size) {
10529 if (i % 16 == 0) {
10530 vty_out(vty, "\n ");
10531 } else if (i % 4 == 0) {
10532 vty_out(vty, " ");
10533 }
10534 }
10535 }
10536 vty_out(vty, "\n");
10537 }
10538 }
10539 }
10540
10541 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10542 if (use_json)
10543 json_object_boolean_true_add(json_neigh,
10544 "prefixesConfigExceedMax");
10545 else
10546 vty_out(vty,
10547 " Peer had exceeded the max. no. of prefixes configured.\n");
10548
10549 if (p->t_pmax_restart) {
10550 if (use_json) {
10551 json_object_boolean_true_add(
10552 json_neigh, "reducePrefixNumFrom");
10553 json_object_int_add(json_neigh,
10554 "restartInTimerMsec",
10555 thread_timer_remain_second(
10556 p->t_pmax_restart)
10557 * 1000);
10558 } else
10559 vty_out(vty,
10560 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10561 p->host, thread_timer_remain_second(
10562 p->t_pmax_restart));
10563 } else {
10564 if (use_json)
10565 json_object_boolean_true_add(
10566 json_neigh,
10567 "reducePrefixNumAndClearIpBgp");
10568 else
10569 vty_out(vty,
10570 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10571 p->host);
10572 }
10573 }
10574
10575 /* EBGP Multihop and GTSM */
10576 if (p->sort != BGP_PEER_IBGP) {
10577 if (use_json) {
10578 if (p->gtsm_hops > 0)
10579 json_object_int_add(json_neigh,
10580 "externalBgpNbrMaxHopsAway",
10581 p->gtsm_hops);
10582 else if (p->ttl > 1)
10583 json_object_int_add(json_neigh,
10584 "externalBgpNbrMaxHopsAway",
10585 p->ttl);
10586 } else {
10587 if (p->gtsm_hops > 0)
10588 vty_out(vty,
10589 " External BGP neighbor may be up to %d hops away.\n",
10590 p->gtsm_hops);
10591 else if (p->ttl > 1)
10592 vty_out(vty,
10593 " External BGP neighbor may be up to %d hops away.\n",
10594 p->ttl);
10595 }
10596 } else {
10597 if (p->gtsm_hops > 0) {
10598 if (use_json)
10599 json_object_int_add(json_neigh,
10600 "internalBgpNbrMaxHopsAway",
10601 p->gtsm_hops);
10602 else
10603 vty_out(vty,
10604 " Internal BGP neighbor may be up to %d hops away.\n",
10605 p->gtsm_hops);
10606 }
10607 }
10608
10609 /* Local address. */
10610 if (p->su_local) {
10611 if (use_json) {
10612 json_object_string_add(json_neigh, "hostLocal",
10613 sockunion2str(p->su_local, buf1,
10614 SU_ADDRSTRLEN));
10615 json_object_int_add(json_neigh, "portLocal",
10616 ntohs(p->su_local->sin.sin_port));
10617 } else
10618 vty_out(vty, "Local host: %s, Local port: %d\n",
10619 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10620 ntohs(p->su_local->sin.sin_port));
10621 }
10622
10623 /* Remote address. */
10624 if (p->su_remote) {
10625 if (use_json) {
10626 json_object_string_add(json_neigh, "hostForeign",
10627 sockunion2str(p->su_remote, buf1,
10628 SU_ADDRSTRLEN));
10629 json_object_int_add(json_neigh, "portForeign",
10630 ntohs(p->su_remote->sin.sin_port));
10631 } else
10632 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10633 sockunion2str(p->su_remote, buf1,
10634 SU_ADDRSTRLEN),
10635 ntohs(p->su_remote->sin.sin_port));
10636 }
10637
10638 /* Nexthop display. */
10639 if (p->su_local) {
10640 if (use_json) {
10641 json_object_string_add(json_neigh, "nexthop",
10642 inet_ntop(AF_INET,
10643 &p->nexthop.v4, buf1,
10644 sizeof(buf1)));
10645 json_object_string_add(json_neigh, "nexthopGlobal",
10646 inet_ntop(AF_INET6,
10647 &p->nexthop.v6_global,
10648 buf1, sizeof(buf1)));
10649 json_object_string_add(json_neigh, "nexthopLocal",
10650 inet_ntop(AF_INET6,
10651 &p->nexthop.v6_local,
10652 buf1, sizeof(buf1)));
10653 if (p->shared_network)
10654 json_object_string_add(json_neigh,
10655 "bgpConnection",
10656 "sharedNetwork");
10657 else
10658 json_object_string_add(json_neigh,
10659 "bgpConnection",
10660 "nonSharedNetwork");
10661 } else {
10662 vty_out(vty, "Nexthop: %s\n",
10663 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10664 sizeof(buf1)));
10665 vty_out(vty, "Nexthop global: %s\n",
10666 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10667 sizeof(buf1)));
10668 vty_out(vty, "Nexthop local: %s\n",
10669 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10670 sizeof(buf1)));
10671 vty_out(vty, "BGP connection: %s\n",
10672 p->shared_network ? "shared network"
10673 : "non shared network");
10674 }
10675 }
10676
10677 /* Timer information. */
10678 if (use_json) {
10679 json_object_int_add(json_neigh, "connectRetryTimer",
10680 p->v_connect);
10681 if (p->status == Established && p->rtt)
10682 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10683 p->rtt);
10684 if (p->t_start)
10685 json_object_int_add(
10686 json_neigh, "nextStartTimerDueInMsecs",
10687 thread_timer_remain_second(p->t_start) * 1000);
10688 if (p->t_connect)
10689 json_object_int_add(
10690 json_neigh, "nextConnectTimerDueInMsecs",
10691 thread_timer_remain_second(p->t_connect)
10692 * 1000);
10693 if (p->t_routeadv) {
10694 json_object_int_add(json_neigh, "mraiInterval",
10695 p->v_routeadv);
10696 json_object_int_add(
10697 json_neigh, "mraiTimerExpireInMsecs",
10698 thread_timer_remain_second(p->t_routeadv)
10699 * 1000);
10700 }
10701 if (p->password)
10702 json_object_int_add(json_neigh, "authenticationEnabled",
10703 1);
10704
10705 if (p->t_read)
10706 json_object_string_add(json_neigh, "readThread", "on");
10707 else
10708 json_object_string_add(json_neigh, "readThread", "off");
10709
10710 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10711 json_object_string_add(json_neigh, "writeThread", "on");
10712 else
10713 json_object_string_add(json_neigh, "writeThread",
10714 "off");
10715 } else {
10716 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10717 p->v_connect);
10718 if (p->status == Established && p->rtt)
10719 vty_out(vty, "Estimated round trip time: %d ms\n",
10720 p->rtt);
10721 if (p->t_start)
10722 vty_out(vty, "Next start timer due in %ld seconds\n",
10723 thread_timer_remain_second(p->t_start));
10724 if (p->t_connect)
10725 vty_out(vty, "Next connect timer due in %ld seconds\n",
10726 thread_timer_remain_second(p->t_connect));
10727 if (p->t_routeadv)
10728 vty_out(vty,
10729 "MRAI (interval %u) timer expires in %ld seconds\n",
10730 p->v_routeadv,
10731 thread_timer_remain_second(p->t_routeadv));
10732 if (p->password)
10733 vty_out(vty, "Peer Authentication Enabled\n");
10734
10735 vty_out(vty, "Read thread: %s Write thread: %s\n",
10736 p->t_read ? "on" : "off",
10737 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10738 ? "on"
10739 : "off");
10740 }
10741
10742 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10743 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10744 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10745
10746 if (!use_json)
10747 vty_out(vty, "\n");
10748
10749 /* BFD information. */
10750 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10751
10752 if (use_json) {
10753 if (p->conf_if) /* Configured interface name. */
10754 json_object_object_add(json, p->conf_if, json_neigh);
10755 else /* Configured IP address. */
10756 json_object_object_add(json, p->host, json_neigh);
10757 }
10758 }
10759
10760 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10761 enum show_type type, union sockunion *su,
10762 const char *conf_if, bool use_json,
10763 json_object *json)
10764 {
10765 struct listnode *node, *nnode;
10766 struct peer *peer;
10767 int find = 0;
10768 bool nbr_output = false;
10769
10770 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10771 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10772 continue;
10773
10774 switch (type) {
10775 case show_all:
10776 bgp_show_peer(vty, peer, use_json, json);
10777 nbr_output = true;
10778 break;
10779 case show_peer:
10780 if (conf_if) {
10781 if ((peer->conf_if
10782 && !strcmp(peer->conf_if, conf_if))
10783 || (peer->hostname
10784 && !strcmp(peer->hostname, conf_if))) {
10785 find = 1;
10786 bgp_show_peer(vty, peer, use_json,
10787 json);
10788 }
10789 } else {
10790 if (sockunion_same(&peer->su, su)) {
10791 find = 1;
10792 bgp_show_peer(vty, peer, use_json,
10793 json);
10794 }
10795 }
10796 break;
10797 }
10798 }
10799
10800 if (type == show_peer && !find) {
10801 if (use_json)
10802 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10803 else
10804 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10805 }
10806
10807 if (type != show_peer && !nbr_output && !use_json)
10808 vty_out(vty, "%% No BGP neighbors found\n");
10809
10810 if (use_json) {
10811 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10812 json, JSON_C_TO_STRING_PRETTY));
10813 json_object_free(json);
10814 } else {
10815 vty_out(vty, "\n");
10816 }
10817
10818 return CMD_SUCCESS;
10819 }
10820
10821 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10822 enum show_type type,
10823 const char *ip_str,
10824 bool use_json)
10825 {
10826 struct listnode *node, *nnode;
10827 struct bgp *bgp;
10828 union sockunion su;
10829 json_object *json = NULL;
10830 int ret, is_first = 1;
10831 bool nbr_output = false;
10832
10833 if (use_json)
10834 vty_out(vty, "{\n");
10835
10836 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10837 nbr_output = true;
10838 if (use_json) {
10839 if (!(json = json_object_new_object())) {
10840 flog_err(
10841 EC_BGP_JSON_MEM_ERROR,
10842 "Unable to allocate memory for JSON object");
10843 vty_out(vty,
10844 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10845 return;
10846 }
10847
10848 json_object_int_add(json, "vrfId",
10849 (bgp->vrf_id == VRF_UNKNOWN)
10850 ? -1
10851 : (int64_t)bgp->vrf_id);
10852 json_object_string_add(
10853 json, "vrfName",
10854 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10855 ? "Default"
10856 : bgp->name);
10857
10858 if (!is_first)
10859 vty_out(vty, ",\n");
10860 else
10861 is_first = 0;
10862
10863 vty_out(vty, "\"%s\":",
10864 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10865 ? "Default"
10866 : bgp->name);
10867 } else {
10868 vty_out(vty, "\nInstance %s:\n",
10869 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10870 ? "Default"
10871 : bgp->name);
10872 }
10873
10874 if (type == show_peer) {
10875 ret = str2sockunion(ip_str, &su);
10876 if (ret < 0)
10877 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10878 use_json, json);
10879 else
10880 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10881 use_json, json);
10882 } else {
10883 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10884 use_json, json);
10885 }
10886 }
10887
10888 if (use_json)
10889 vty_out(vty, "}\n");
10890 else if (!nbr_output)
10891 vty_out(vty, "%% BGP instance not found\n");
10892 }
10893
10894 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10895 enum show_type type, const char *ip_str,
10896 bool use_json)
10897 {
10898 int ret;
10899 struct bgp *bgp;
10900 union sockunion su;
10901 json_object *json = NULL;
10902
10903 if (name) {
10904 if (strmatch(name, "all")) {
10905 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10906 use_json);
10907 return CMD_SUCCESS;
10908 } else {
10909 bgp = bgp_lookup_by_name(name);
10910 if (!bgp) {
10911 if (use_json) {
10912 json = json_object_new_object();
10913 vty_out(vty, "%s\n",
10914 json_object_to_json_string_ext(
10915 json,
10916 JSON_C_TO_STRING_PRETTY));
10917 json_object_free(json);
10918 } else
10919 vty_out(vty,
10920 "%% BGP instance not found\n");
10921
10922 return CMD_WARNING;
10923 }
10924 }
10925 } else {
10926 bgp = bgp_get_default();
10927 }
10928
10929 if (bgp) {
10930 json = json_object_new_object();
10931 if (ip_str) {
10932 ret = str2sockunion(ip_str, &su);
10933 if (ret < 0)
10934 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10935 use_json, json);
10936 else
10937 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10938 use_json, json);
10939 } else {
10940 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10941 json);
10942 }
10943 json_object_free(json);
10944 } else {
10945 if (use_json)
10946 vty_out(vty, "{}\n");
10947 else
10948 vty_out(vty, "%% BGP instance not found\n");
10949 }
10950
10951 return CMD_SUCCESS;
10952 }
10953
10954 /* "show [ip] bgp neighbors" commands. */
10955 DEFUN (show_ip_bgp_neighbors,
10956 show_ip_bgp_neighbors_cmd,
10957 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10958 SHOW_STR
10959 IP_STR
10960 BGP_STR
10961 BGP_INSTANCE_HELP_STR
10962 "Address Family\n"
10963 "Address Family\n"
10964 "Detailed information on TCP and BGP neighbor connections\n"
10965 "Neighbor to display information about\n"
10966 "Neighbor to display information about\n"
10967 "Neighbor on BGP configured interface\n"
10968 JSON_STR)
10969 {
10970 char *vrf = NULL;
10971 char *sh_arg = NULL;
10972 enum show_type sh_type;
10973
10974 bool uj = use_json(argc, argv);
10975
10976 int idx = 0;
10977
10978 /* [<vrf> VIEWVRFNAME] */
10979 if (argv_find(argv, argc, "vrf", &idx)) {
10980 vrf = argv[idx + 1]->arg;
10981 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10982 vrf = NULL;
10983 } else if (argv_find(argv, argc, "view", &idx))
10984 /* [<view> VIEWVRFNAME] */
10985 vrf = argv[idx + 1]->arg;
10986
10987 idx++;
10988 if (argv_find(argv, argc, "A.B.C.D", &idx)
10989 || argv_find(argv, argc, "X:X::X:X", &idx)
10990 || argv_find(argv, argc, "WORD", &idx)) {
10991 sh_type = show_peer;
10992 sh_arg = argv[idx]->arg;
10993 } else
10994 sh_type = show_all;
10995
10996 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10997 }
10998
10999 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
11000 paths' and `show ip mbgp paths'. Those functions results are the
11001 same.*/
11002 DEFUN (show_ip_bgp_paths,
11003 show_ip_bgp_paths_cmd,
11004 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
11005 SHOW_STR
11006 IP_STR
11007 BGP_STR
11008 BGP_SAFI_HELP_STR
11009 "Path information\n")
11010 {
11011 vty_out(vty, "Address Refcnt Path\n");
11012 aspath_print_all_vty(vty);
11013 return CMD_SUCCESS;
11014 }
11015
11016 #include "hash.h"
11017
11018 static void community_show_all_iterator(struct hash_backet *backet,
11019 struct vty *vty)
11020 {
11021 struct community *com;
11022
11023 com = (struct community *)backet->data;
11024 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
11025 community_str(com, false));
11026 }
11027
11028 /* Show BGP's community internal data. */
11029 DEFUN (show_ip_bgp_community_info,
11030 show_ip_bgp_community_info_cmd,
11031 "show [ip] bgp community-info",
11032 SHOW_STR
11033 IP_STR
11034 BGP_STR
11035 "List all bgp community information\n")
11036 {
11037 vty_out(vty, "Address Refcnt Community\n");
11038
11039 hash_iterate(community_hash(),
11040 (void (*)(struct hash_backet *,
11041 void *))community_show_all_iterator,
11042 vty);
11043
11044 return CMD_SUCCESS;
11045 }
11046
11047 static void lcommunity_show_all_iterator(struct hash_backet *backet,
11048 struct vty *vty)
11049 {
11050 struct lcommunity *lcom;
11051
11052 lcom = (struct lcommunity *)backet->data;
11053 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11054 lcommunity_str(lcom, false));
11055 }
11056
11057 /* Show BGP's community internal data. */
11058 DEFUN (show_ip_bgp_lcommunity_info,
11059 show_ip_bgp_lcommunity_info_cmd,
11060 "show ip bgp large-community-info",
11061 SHOW_STR
11062 IP_STR
11063 BGP_STR
11064 "List all bgp large-community information\n")
11065 {
11066 vty_out(vty, "Address Refcnt Large-community\n");
11067
11068 hash_iterate(lcommunity_hash(),
11069 (void (*)(struct hash_backet *,
11070 void *))lcommunity_show_all_iterator,
11071 vty);
11072
11073 return CMD_SUCCESS;
11074 }
11075
11076
11077 DEFUN (show_ip_bgp_attr_info,
11078 show_ip_bgp_attr_info_cmd,
11079 "show [ip] bgp attribute-info",
11080 SHOW_STR
11081 IP_STR
11082 BGP_STR
11083 "List all bgp attribute information\n")
11084 {
11085 attr_show_all(vty);
11086 return CMD_SUCCESS;
11087 }
11088
11089 static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11090 safi_t safi, bool use_json)
11091 {
11092 struct bgp *bgp;
11093 struct listnode *node;
11094 char *vname;
11095 char buf1[INET6_ADDRSTRLEN];
11096 char *ecom_str;
11097 vpn_policy_direction_t dir;
11098
11099 if (use_json) {
11100 json_object *json = NULL;
11101 json_object *json_import_vrfs = NULL;
11102 json_object *json_export_vrfs = NULL;
11103
11104 json = json_object_new_object();
11105
11106 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11107
11108 if (!bgp) {
11109 vty_out(vty, "%s\n",
11110 json_object_to_json_string_ext(
11111 json,
11112 JSON_C_TO_STRING_PRETTY));
11113 json_object_free(json);
11114
11115 return CMD_WARNING;
11116 }
11117
11118 /* Provide context for the block */
11119 json_object_string_add(json, "vrf", name ? name : "default");
11120 json_object_string_add(json, "afiSafi",
11121 afi_safi_print(afi, safi));
11122
11123 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11124 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11125 json_object_string_add(json, "importFromVrfs", "none");
11126 json_object_string_add(json, "importRts", "none");
11127 } else {
11128 json_import_vrfs = json_object_new_array();
11129
11130 for (ALL_LIST_ELEMENTS_RO(
11131 bgp->vpn_policy[afi].import_vrf,
11132 node, vname))
11133 json_object_array_add(json_import_vrfs,
11134 json_object_new_string(vname));
11135
11136 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11137 ecom_str = ecommunity_ecom2str(
11138 bgp->vpn_policy[afi].rtlist[dir],
11139 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11140 json_object_object_add(json, "importFromVrfs",
11141 json_import_vrfs);
11142 json_object_string_add(json, "importRts", ecom_str);
11143
11144 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11145 }
11146
11147 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11148 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11149 json_object_string_add(json, "exportToVrfs", "none");
11150 json_object_string_add(json, "routeDistinguisher",
11151 "none");
11152 json_object_string_add(json, "exportRts", "none");
11153 } else {
11154 json_export_vrfs = json_object_new_array();
11155
11156 for (ALL_LIST_ELEMENTS_RO(
11157 bgp->vpn_policy[afi].export_vrf,
11158 node, vname))
11159 json_object_array_add(json_export_vrfs,
11160 json_object_new_string(vname));
11161 json_object_object_add(json, "exportToVrfs",
11162 json_export_vrfs);
11163 json_object_string_add(json, "routeDistinguisher",
11164 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11165 buf1, RD_ADDRSTRLEN));
11166
11167 dir = BGP_VPN_POLICY_DIR_TOVPN;
11168 ecom_str = ecommunity_ecom2str(
11169 bgp->vpn_policy[afi].rtlist[dir],
11170 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11171 json_object_string_add(json, "exportRts", ecom_str);
11172
11173 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11174 }
11175
11176 vty_out(vty, "%s\n",
11177 json_object_to_json_string_ext(json,
11178 JSON_C_TO_STRING_PRETTY));
11179 json_object_free(json);
11180
11181 } else {
11182 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11183
11184 if (!bgp) {
11185 vty_out(vty, "%% No such BGP instance exist\n");
11186 return CMD_WARNING;
11187 }
11188
11189 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11190 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11191 vty_out(vty,
11192 "This VRF is not importing %s routes from any other VRF\n",
11193 afi_safi_print(afi, safi));
11194 else {
11195 vty_out(vty,
11196 "This VRF is importing %s routes from the following VRFs:\n",
11197 afi_safi_print(afi, safi));
11198
11199 for (ALL_LIST_ELEMENTS_RO(
11200 bgp->vpn_policy[afi].import_vrf,
11201 node, vname))
11202 vty_out(vty, " %s\n", vname);
11203
11204 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11205 ecom_str = ecommunity_ecom2str(
11206 bgp->vpn_policy[afi].rtlist[dir],
11207 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11208 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11209
11210 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11211 }
11212
11213 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11214 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11215 vty_out(vty,
11216 "This VRF is not exporting %s routes to any other VRF\n",
11217 afi_safi_print(afi, safi));
11218 else {
11219 vty_out(vty,
11220 "This VRF is exporting %s routes to the following VRFs:\n",
11221 afi_safi_print(afi, safi));
11222
11223 for (ALL_LIST_ELEMENTS_RO(
11224 bgp->vpn_policy[afi].export_vrf,
11225 node, vname))
11226 vty_out(vty, " %s\n", vname);
11227
11228 vty_out(vty, "RD: %s\n",
11229 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11230 buf1, RD_ADDRSTRLEN));
11231
11232 dir = BGP_VPN_POLICY_DIR_TOVPN;
11233 ecom_str = ecommunity_ecom2str(
11234 bgp->vpn_policy[afi].rtlist[dir],
11235 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11236 vty_out(vty, "Export RT: %s\n", ecom_str);
11237 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11238 }
11239 }
11240
11241 return CMD_SUCCESS;
11242 }
11243
11244 /* "show [ip] bgp route-leak" command. */
11245 DEFUN (show_ip_bgp_route_leak,
11246 show_ip_bgp_route_leak_cmd,
11247 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11248 SHOW_STR
11249 IP_STR
11250 BGP_STR
11251 BGP_INSTANCE_HELP_STR
11252 BGP_AFI_HELP_STR
11253 BGP_SAFI_HELP_STR
11254 "Route leaking information\n"
11255 JSON_STR)
11256 {
11257 char *vrf = NULL;
11258 afi_t afi = AFI_MAX;
11259 safi_t safi = SAFI_MAX;
11260
11261 bool uj = use_json(argc, argv);
11262 int idx = 0;
11263
11264 /* show [ip] bgp */
11265 if (argv_find(argv, argc, "ip", &idx)) {
11266 afi = AFI_IP;
11267 safi = SAFI_UNICAST;
11268 }
11269 /* [vrf VIEWVRFNAME] */
11270 if (argv_find(argv, argc, "view", &idx)) {
11271 vty_out(vty,
11272 "%% This command is not applicable to BGP views\n");
11273 return CMD_WARNING;
11274 }
11275
11276 if (argv_find(argv, argc, "vrf", &idx)) {
11277 vrf = argv[idx + 1]->arg;
11278 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11279 vrf = NULL;
11280 }
11281 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11282 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11283 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11284 }
11285
11286 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11287 vty_out(vty,
11288 "%% This command is applicable only for unicast ipv4|ipv6\n");
11289 return CMD_WARNING;
11290 }
11291
11292 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
11293 }
11294
11295 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11296 safi_t safi)
11297 {
11298 struct listnode *node, *nnode;
11299 struct bgp *bgp;
11300
11301 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11302 vty_out(vty, "\nInstance %s:\n",
11303 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11304 ? "Default"
11305 : bgp->name);
11306 update_group_show(bgp, afi, safi, vty, 0);
11307 }
11308 }
11309
11310 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11311 int safi, uint64_t subgrp_id)
11312 {
11313 struct bgp *bgp;
11314
11315 if (name) {
11316 if (strmatch(name, "all")) {
11317 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11318 return CMD_SUCCESS;
11319 } else {
11320 bgp = bgp_lookup_by_name(name);
11321 }
11322 } else {
11323 bgp = bgp_get_default();
11324 }
11325
11326 if (bgp)
11327 update_group_show(bgp, afi, safi, vty, subgrp_id);
11328 return CMD_SUCCESS;
11329 }
11330
11331 DEFUN (show_ip_bgp_updgrps,
11332 show_ip_bgp_updgrps_cmd,
11333 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11334 SHOW_STR
11335 IP_STR
11336 BGP_STR
11337 BGP_INSTANCE_HELP_STR
11338 BGP_AFI_HELP_STR
11339 BGP_SAFI_WITH_LABEL_HELP_STR
11340 "Detailed info about dynamic update groups\n"
11341 "Specific subgroup to display detailed info for\n")
11342 {
11343 char *vrf = NULL;
11344 afi_t afi = AFI_IP6;
11345 safi_t safi = SAFI_UNICAST;
11346 uint64_t subgrp_id = 0;
11347
11348 int idx = 0;
11349
11350 /* show [ip] bgp */
11351 if (argv_find(argv, argc, "ip", &idx))
11352 afi = AFI_IP;
11353 /* [<vrf> VIEWVRFNAME] */
11354 if (argv_find(argv, argc, "vrf", &idx)) {
11355 vrf = argv[idx + 1]->arg;
11356 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11357 vrf = NULL;
11358 } else if (argv_find(argv, argc, "view", &idx))
11359 /* [<view> VIEWVRFNAME] */
11360 vrf = argv[idx + 1]->arg;
11361 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11362 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11363 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11364 }
11365
11366 /* get subgroup id, if provided */
11367 idx = argc - 1;
11368 if (argv[idx]->type == VARIABLE_TKN)
11369 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11370
11371 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11372 }
11373
11374 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11375 show_bgp_instance_all_ipv6_updgrps_cmd,
11376 "show [ip] bgp <view|vrf> all update-groups",
11377 SHOW_STR
11378 IP_STR
11379 BGP_STR
11380 BGP_INSTANCE_ALL_HELP_STR
11381 "Detailed info about dynamic update groups\n")
11382 {
11383 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11384 return CMD_SUCCESS;
11385 }
11386
11387 DEFUN (show_bgp_l2vpn_evpn_updgrps,
11388 show_bgp_l2vpn_evpn_updgrps_cmd,
11389 "show [ip] bgp l2vpn evpn update-groups",
11390 SHOW_STR
11391 IP_STR
11392 BGP_STR
11393 "l2vpn address family\n"
11394 "evpn sub-address family\n"
11395 "Detailed info about dynamic update groups\n")
11396 {
11397 char *vrf = NULL;
11398 uint64_t subgrp_id = 0;
11399
11400 bgp_show_update_groups(vty, vrf, AFI_L2VPN, SAFI_EVPN, subgrp_id);
11401 return CMD_SUCCESS;
11402 }
11403
11404 DEFUN (show_bgp_updgrps_stats,
11405 show_bgp_updgrps_stats_cmd,
11406 "show [ip] bgp update-groups statistics",
11407 SHOW_STR
11408 IP_STR
11409 BGP_STR
11410 "Detailed info about dynamic update groups\n"
11411 "Statistics\n")
11412 {
11413 struct bgp *bgp;
11414
11415 bgp = bgp_get_default();
11416 if (bgp)
11417 update_group_show_stats(bgp, vty);
11418
11419 return CMD_SUCCESS;
11420 }
11421
11422 DEFUN (show_bgp_instance_updgrps_stats,
11423 show_bgp_instance_updgrps_stats_cmd,
11424 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11425 SHOW_STR
11426 IP_STR
11427 BGP_STR
11428 BGP_INSTANCE_HELP_STR
11429 "Detailed info about dynamic update groups\n"
11430 "Statistics\n")
11431 {
11432 int idx_word = 3;
11433 struct bgp *bgp;
11434
11435 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11436 if (bgp)
11437 update_group_show_stats(bgp, vty);
11438
11439 return CMD_SUCCESS;
11440 }
11441
11442 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11443 afi_t afi, safi_t safi,
11444 const char *what, uint64_t subgrp_id)
11445 {
11446 struct bgp *bgp;
11447
11448 if (name)
11449 bgp = bgp_lookup_by_name(name);
11450 else
11451 bgp = bgp_get_default();
11452
11453 if (bgp) {
11454 if (!strcmp(what, "advertise-queue"))
11455 update_group_show_adj_queue(bgp, afi, safi, vty,
11456 subgrp_id);
11457 else if (!strcmp(what, "advertised-routes"))
11458 update_group_show_advertised(bgp, afi, safi, vty,
11459 subgrp_id);
11460 else if (!strcmp(what, "packet-queue"))
11461 update_group_show_packet_queue(bgp, afi, safi, vty,
11462 subgrp_id);
11463 }
11464 }
11465
11466 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11467 show_ip_bgp_instance_updgrps_adj_s_cmd,
11468 "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",
11469 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11470 BGP_SAFI_HELP_STR
11471 "Detailed info about dynamic update groups\n"
11472 "Specific subgroup to display info for\n"
11473 "Advertisement queue\n"
11474 "Announced routes\n"
11475 "Packet queue\n")
11476 {
11477 uint64_t subgrp_id = 0;
11478 afi_t afiz;
11479 safi_t safiz;
11480 if (sgid)
11481 subgrp_id = strtoull(sgid, NULL, 10);
11482
11483 if (!ip && !afi)
11484 afiz = AFI_IP6;
11485 if (!ip && afi)
11486 afiz = bgp_vty_afi_from_str(afi);
11487 if (ip && !afi)
11488 afiz = AFI_IP;
11489 if (ip && afi) {
11490 afiz = bgp_vty_afi_from_str(afi);
11491 if (afiz != AFI_IP)
11492 vty_out(vty,
11493 "%% Cannot specify both 'ip' and 'ipv6'\n");
11494 return CMD_WARNING;
11495 }
11496
11497 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11498
11499 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11500 return CMD_SUCCESS;
11501 }
11502
11503 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11504 {
11505 struct listnode *node, *nnode;
11506 struct prefix *range;
11507 struct peer *conf;
11508 struct peer *peer;
11509 char buf[PREFIX2STR_BUFFER];
11510 afi_t afi;
11511 safi_t safi;
11512 const char *peer_status;
11513 const char *af_str;
11514 int lr_count;
11515 int dynamic;
11516 int af_cfgd;
11517
11518 conf = group->conf;
11519
11520 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11521 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11522 conf->as);
11523 } else if (conf->as_type == AS_INTERNAL) {
11524 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11525 group->bgp->as);
11526 } else {
11527 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11528 }
11529
11530 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11531 vty_out(vty, " Peer-group type is internal\n");
11532 else
11533 vty_out(vty, " Peer-group type is external\n");
11534
11535 /* Display AFs configured. */
11536 vty_out(vty, " Configured address-families:");
11537 FOREACH_AFI_SAFI (afi, safi) {
11538 if (conf->afc[afi][safi]) {
11539 af_cfgd = 1;
11540 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11541 }
11542 }
11543 if (!af_cfgd)
11544 vty_out(vty, " none\n");
11545 else
11546 vty_out(vty, "\n");
11547
11548 /* Display listen ranges (for dynamic neighbors), if any */
11549 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11550 if (afi == AFI_IP)
11551 af_str = "IPv4";
11552 else if (afi == AFI_IP6)
11553 af_str = "IPv6";
11554 else
11555 af_str = "???";
11556 lr_count = listcount(group->listen_range[afi]);
11557 if (lr_count) {
11558 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11559 af_str);
11560
11561
11562 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11563 nnode, range)) {
11564 prefix2str(range, buf, sizeof(buf));
11565 vty_out(vty, " %s\n", buf);
11566 }
11567 }
11568 }
11569
11570 /* Display group members and their status */
11571 if (listcount(group->peer)) {
11572 vty_out(vty, " Peer-group members:\n");
11573 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11574 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11575 peer_status = "Idle (Admin)";
11576 else if (CHECK_FLAG(peer->sflags,
11577 PEER_STATUS_PREFIX_OVERFLOW))
11578 peer_status = "Idle (PfxCt)";
11579 else
11580 peer_status = lookup_msg(bgp_status_msg,
11581 peer->status, NULL);
11582
11583 dynamic = peer_dynamic_neighbor(peer);
11584 vty_out(vty, " %s %s %s \n", peer->host,
11585 dynamic ? "(dynamic)" : "", peer_status);
11586 }
11587 }
11588
11589 return CMD_SUCCESS;
11590 }
11591
11592 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11593 const char *group_name)
11594 {
11595 struct bgp *bgp;
11596 struct listnode *node, *nnode;
11597 struct peer_group *group;
11598 bool found = false;
11599
11600 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11601
11602 if (!bgp) {
11603 vty_out(vty, "%% BGP instance not found\n");
11604 return CMD_WARNING;
11605 }
11606
11607 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11608 if (group_name) {
11609 if (strmatch(group->name, group_name)) {
11610 bgp_show_one_peer_group(vty, group);
11611 found = true;
11612 break;
11613 }
11614 } else {
11615 bgp_show_one_peer_group(vty, group);
11616 }
11617 }
11618
11619 if (group_name && !found)
11620 vty_out(vty, "%% No such peer-group\n");
11621
11622 return CMD_SUCCESS;
11623 }
11624
11625 DEFUN (show_ip_bgp_peer_groups,
11626 show_ip_bgp_peer_groups_cmd,
11627 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11628 SHOW_STR
11629 IP_STR
11630 BGP_STR
11631 BGP_INSTANCE_HELP_STR
11632 "Detailed information on BGP peer groups\n"
11633 "Peer group name\n")
11634 {
11635 char *vrf, *pg;
11636 int idx = 0;
11637
11638 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11639 : NULL;
11640 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11641
11642 return bgp_show_peer_group_vty(vty, vrf, pg);
11643 }
11644
11645
11646 /* Redistribute VTY commands. */
11647
11648 DEFUN (bgp_redistribute_ipv4,
11649 bgp_redistribute_ipv4_cmd,
11650 "redistribute " FRR_IP_REDIST_STR_BGPD,
11651 "Redistribute information from another routing protocol\n"
11652 FRR_IP_REDIST_HELP_STR_BGPD)
11653 {
11654 VTY_DECLVAR_CONTEXT(bgp, bgp);
11655 int idx_protocol = 1;
11656 int type;
11657
11658 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11659 if (type < 0) {
11660 vty_out(vty, "%% Invalid route type\n");
11661 return CMD_WARNING_CONFIG_FAILED;
11662 }
11663
11664 bgp_redist_add(bgp, AFI_IP, type, 0);
11665 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11666 }
11667
11668 ALIAS_HIDDEN(
11669 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11670 "redistribute " FRR_IP_REDIST_STR_BGPD,
11671 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11672
11673 DEFUN (bgp_redistribute_ipv4_rmap,
11674 bgp_redistribute_ipv4_rmap_cmd,
11675 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11676 "Redistribute information from another routing protocol\n"
11677 FRR_IP_REDIST_HELP_STR_BGPD
11678 "Route map reference\n"
11679 "Pointer to route-map entries\n")
11680 {
11681 VTY_DECLVAR_CONTEXT(bgp, bgp);
11682 int idx_protocol = 1;
11683 int idx_word = 3;
11684 int type;
11685 struct bgp_redist *red;
11686 bool changed;
11687 struct route_map *route_map = route_map_lookup_warn_noexist(
11688 vty, argv[idx_word]->arg);
11689
11690 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11691 if (type < 0) {
11692 vty_out(vty, "%% Invalid route type\n");
11693 return CMD_WARNING_CONFIG_FAILED;
11694 }
11695
11696 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11697 changed =
11698 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11699 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11700 }
11701
11702 ALIAS_HIDDEN(
11703 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11704 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11705 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11706 "Route map reference\n"
11707 "Pointer to route-map entries\n")
11708
11709 DEFUN (bgp_redistribute_ipv4_metric,
11710 bgp_redistribute_ipv4_metric_cmd,
11711 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11712 "Redistribute information from another routing protocol\n"
11713 FRR_IP_REDIST_HELP_STR_BGPD
11714 "Metric for redistributed routes\n"
11715 "Default metric\n")
11716 {
11717 VTY_DECLVAR_CONTEXT(bgp, bgp);
11718 int idx_protocol = 1;
11719 int idx_number = 3;
11720 int type;
11721 uint32_t metric;
11722 struct bgp_redist *red;
11723 bool changed;
11724
11725 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11726 if (type < 0) {
11727 vty_out(vty, "%% Invalid route type\n");
11728 return CMD_WARNING_CONFIG_FAILED;
11729 }
11730 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11731
11732 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11733 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11734 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11735 }
11736
11737 ALIAS_HIDDEN(
11738 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11739 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11740 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11741 "Metric for redistributed routes\n"
11742 "Default metric\n")
11743
11744 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11745 bgp_redistribute_ipv4_rmap_metric_cmd,
11746 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11747 "Redistribute information from another routing protocol\n"
11748 FRR_IP_REDIST_HELP_STR_BGPD
11749 "Route map reference\n"
11750 "Pointer to route-map entries\n"
11751 "Metric for redistributed routes\n"
11752 "Default metric\n")
11753 {
11754 VTY_DECLVAR_CONTEXT(bgp, bgp);
11755 int idx_protocol = 1;
11756 int idx_word = 3;
11757 int idx_number = 5;
11758 int type;
11759 uint32_t metric;
11760 struct bgp_redist *red;
11761 bool changed;
11762 struct route_map *route_map =
11763 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11764
11765 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11766 if (type < 0) {
11767 vty_out(vty, "%% Invalid route type\n");
11768 return CMD_WARNING_CONFIG_FAILED;
11769 }
11770 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11771
11772 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11773 changed =
11774 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11775 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11776 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11777 }
11778
11779 ALIAS_HIDDEN(
11780 bgp_redistribute_ipv4_rmap_metric,
11781 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11782 "redistribute " FRR_IP_REDIST_STR_BGPD
11783 " route-map WORD metric (0-4294967295)",
11784 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11785 "Route map reference\n"
11786 "Pointer to route-map entries\n"
11787 "Metric for redistributed routes\n"
11788 "Default metric\n")
11789
11790 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11791 bgp_redistribute_ipv4_metric_rmap_cmd,
11792 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11793 "Redistribute information from another routing protocol\n"
11794 FRR_IP_REDIST_HELP_STR_BGPD
11795 "Metric for redistributed routes\n"
11796 "Default metric\n"
11797 "Route map reference\n"
11798 "Pointer to route-map entries\n")
11799 {
11800 VTY_DECLVAR_CONTEXT(bgp, bgp);
11801 int idx_protocol = 1;
11802 int idx_number = 3;
11803 int idx_word = 5;
11804 int type;
11805 uint32_t metric;
11806 struct bgp_redist *red;
11807 bool changed;
11808 struct route_map *route_map =
11809 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11810
11811 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11812 if (type < 0) {
11813 vty_out(vty, "%% Invalid route type\n");
11814 return CMD_WARNING_CONFIG_FAILED;
11815 }
11816 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11817
11818 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11819 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11820 changed |=
11821 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11822 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11823 }
11824
11825 ALIAS_HIDDEN(
11826 bgp_redistribute_ipv4_metric_rmap,
11827 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11828 "redistribute " FRR_IP_REDIST_STR_BGPD
11829 " metric (0-4294967295) route-map WORD",
11830 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11831 "Metric for redistributed routes\n"
11832 "Default metric\n"
11833 "Route map reference\n"
11834 "Pointer to route-map entries\n")
11835
11836 DEFUN (bgp_redistribute_ipv4_ospf,
11837 bgp_redistribute_ipv4_ospf_cmd,
11838 "redistribute <ospf|table> (1-65535)",
11839 "Redistribute information from another routing protocol\n"
11840 "Open Shortest Path First (OSPFv2)\n"
11841 "Non-main Kernel Routing Table\n"
11842 "Instance ID/Table ID\n")
11843 {
11844 VTY_DECLVAR_CONTEXT(bgp, bgp);
11845 int idx_ospf_table = 1;
11846 int idx_number = 2;
11847 unsigned short instance;
11848 unsigned short protocol;
11849
11850 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11851
11852 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11853 protocol = ZEBRA_ROUTE_OSPF;
11854 else
11855 protocol = ZEBRA_ROUTE_TABLE;
11856
11857 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11858 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
11859 }
11860
11861 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11862 "redistribute <ospf|table> (1-65535)",
11863 "Redistribute information from another routing protocol\n"
11864 "Open Shortest Path First (OSPFv2)\n"
11865 "Non-main Kernel Routing Table\n"
11866 "Instance ID/Table ID\n")
11867
11868 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11869 bgp_redistribute_ipv4_ospf_rmap_cmd,
11870 "redistribute <ospf|table> (1-65535) route-map WORD",
11871 "Redistribute information from another routing protocol\n"
11872 "Open Shortest Path First (OSPFv2)\n"
11873 "Non-main Kernel Routing Table\n"
11874 "Instance ID/Table ID\n"
11875 "Route map reference\n"
11876 "Pointer to route-map entries\n")
11877 {
11878 VTY_DECLVAR_CONTEXT(bgp, bgp);
11879 int idx_ospf_table = 1;
11880 int idx_number = 2;
11881 int idx_word = 4;
11882 struct bgp_redist *red;
11883 unsigned short instance;
11884 int protocol;
11885 bool changed;
11886 struct route_map *route_map =
11887 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11888
11889 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11890 protocol = ZEBRA_ROUTE_OSPF;
11891 else
11892 protocol = ZEBRA_ROUTE_TABLE;
11893
11894 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11895 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11896 changed =
11897 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11898 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11899 }
11900
11901 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11902 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11903 "redistribute <ospf|table> (1-65535) route-map WORD",
11904 "Redistribute information from another routing protocol\n"
11905 "Open Shortest Path First (OSPFv2)\n"
11906 "Non-main Kernel Routing Table\n"
11907 "Instance ID/Table ID\n"
11908 "Route map reference\n"
11909 "Pointer to route-map entries\n")
11910
11911 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11912 bgp_redistribute_ipv4_ospf_metric_cmd,
11913 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11914 "Redistribute information from another routing protocol\n"
11915 "Open Shortest Path First (OSPFv2)\n"
11916 "Non-main Kernel Routing Table\n"
11917 "Instance ID/Table ID\n"
11918 "Metric for redistributed routes\n"
11919 "Default metric\n")
11920 {
11921 VTY_DECLVAR_CONTEXT(bgp, bgp);
11922 int idx_ospf_table = 1;
11923 int idx_number = 2;
11924 int idx_number_2 = 4;
11925 uint32_t metric;
11926 struct bgp_redist *red;
11927 unsigned short instance;
11928 int protocol;
11929 bool changed;
11930
11931 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11932 protocol = ZEBRA_ROUTE_OSPF;
11933 else
11934 protocol = ZEBRA_ROUTE_TABLE;
11935
11936 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11937 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11938
11939 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11940 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11941 metric);
11942 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11943 }
11944
11945 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11946 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11947 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11948 "Redistribute information from another routing protocol\n"
11949 "Open Shortest Path First (OSPFv2)\n"
11950 "Non-main Kernel Routing Table\n"
11951 "Instance ID/Table ID\n"
11952 "Metric for redistributed routes\n"
11953 "Default metric\n")
11954
11955 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11956 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11957 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11958 "Redistribute information from another routing protocol\n"
11959 "Open Shortest Path First (OSPFv2)\n"
11960 "Non-main Kernel Routing Table\n"
11961 "Instance ID/Table ID\n"
11962 "Route map reference\n"
11963 "Pointer to route-map entries\n"
11964 "Metric for redistributed routes\n"
11965 "Default metric\n")
11966 {
11967 VTY_DECLVAR_CONTEXT(bgp, bgp);
11968 int idx_ospf_table = 1;
11969 int idx_number = 2;
11970 int idx_word = 4;
11971 int idx_number_2 = 6;
11972 uint32_t metric;
11973 struct bgp_redist *red;
11974 unsigned short instance;
11975 int protocol;
11976 bool changed;
11977 struct route_map *route_map =
11978 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
11979
11980 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11981 protocol = ZEBRA_ROUTE_OSPF;
11982 else
11983 protocol = ZEBRA_ROUTE_TABLE;
11984
11985 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11986 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11987
11988 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11989 changed =
11990 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
11991 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11992 metric);
11993 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11994 }
11995
11996 ALIAS_HIDDEN(
11997 bgp_redistribute_ipv4_ospf_rmap_metric,
11998 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11999 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
12000 "Redistribute information from another routing protocol\n"
12001 "Open Shortest Path First (OSPFv2)\n"
12002 "Non-main Kernel Routing Table\n"
12003 "Instance ID/Table ID\n"
12004 "Route map reference\n"
12005 "Pointer to route-map entries\n"
12006 "Metric for redistributed routes\n"
12007 "Default metric\n")
12008
12009 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
12010 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
12011 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
12012 "Redistribute information from another routing protocol\n"
12013 "Open Shortest Path First (OSPFv2)\n"
12014 "Non-main Kernel Routing Table\n"
12015 "Instance ID/Table ID\n"
12016 "Metric for redistributed routes\n"
12017 "Default metric\n"
12018 "Route map reference\n"
12019 "Pointer to route-map entries\n")
12020 {
12021 VTY_DECLVAR_CONTEXT(bgp, bgp);
12022 int idx_ospf_table = 1;
12023 int idx_number = 2;
12024 int idx_number_2 = 4;
12025 int idx_word = 6;
12026 uint32_t metric;
12027 struct bgp_redist *red;
12028 unsigned short instance;
12029 int protocol;
12030 bool changed;
12031 struct route_map *route_map =
12032 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12033
12034 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12035 protocol = ZEBRA_ROUTE_OSPF;
12036 else
12037 protocol = ZEBRA_ROUTE_TABLE;
12038
12039 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12040 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
12041
12042 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
12043 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
12044 metric);
12045 changed |=
12046 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12047 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
12048 }
12049
12050 ALIAS_HIDDEN(
12051 bgp_redistribute_ipv4_ospf_metric_rmap,
12052 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
12053 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
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 "Route map reference\n"
12061 "Pointer to route-map entries\n")
12062
12063 DEFUN (no_bgp_redistribute_ipv4_ospf,
12064 no_bgp_redistribute_ipv4_ospf_cmd,
12065 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12066 NO_STR
12067 "Redistribute information from another routing protocol\n"
12068 "Open Shortest Path First (OSPFv2)\n"
12069 "Non-main Kernel Routing Table\n"
12070 "Instance ID/Table ID\n"
12071 "Metric for redistributed routes\n"
12072 "Default metric\n"
12073 "Route map reference\n"
12074 "Pointer to route-map entries\n")
12075 {
12076 VTY_DECLVAR_CONTEXT(bgp, bgp);
12077 int idx_ospf_table = 2;
12078 int idx_number = 3;
12079 unsigned short instance;
12080 int protocol;
12081
12082 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12083 protocol = ZEBRA_ROUTE_OSPF;
12084 else
12085 protocol = ZEBRA_ROUTE_TABLE;
12086
12087 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12088 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12089 }
12090
12091 ALIAS_HIDDEN(
12092 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12093 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12094 NO_STR
12095 "Redistribute information from another routing protocol\n"
12096 "Open Shortest Path First (OSPFv2)\n"
12097 "Non-main Kernel Routing Table\n"
12098 "Instance ID/Table ID\n"
12099 "Metric for redistributed routes\n"
12100 "Default metric\n"
12101 "Route map reference\n"
12102 "Pointer to route-map entries\n")
12103
12104 DEFUN (no_bgp_redistribute_ipv4,
12105 no_bgp_redistribute_ipv4_cmd,
12106 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12107 NO_STR
12108 "Redistribute information from another routing protocol\n"
12109 FRR_IP_REDIST_HELP_STR_BGPD
12110 "Metric for redistributed routes\n"
12111 "Default metric\n"
12112 "Route map reference\n"
12113 "Pointer to route-map entries\n")
12114 {
12115 VTY_DECLVAR_CONTEXT(bgp, bgp);
12116 int idx_protocol = 2;
12117 int type;
12118
12119 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12120 if (type < 0) {
12121 vty_out(vty, "%% Invalid route type\n");
12122 return CMD_WARNING_CONFIG_FAILED;
12123 }
12124 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12125 }
12126
12127 ALIAS_HIDDEN(
12128 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12129 "no redistribute " FRR_IP_REDIST_STR_BGPD
12130 " [metric (0-4294967295)] [route-map WORD]",
12131 NO_STR
12132 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12133 "Metric for redistributed routes\n"
12134 "Default metric\n"
12135 "Route map reference\n"
12136 "Pointer to route-map entries\n")
12137
12138 DEFUN (bgp_redistribute_ipv6,
12139 bgp_redistribute_ipv6_cmd,
12140 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12141 "Redistribute information from another routing protocol\n"
12142 FRR_IP6_REDIST_HELP_STR_BGPD)
12143 {
12144 VTY_DECLVAR_CONTEXT(bgp, bgp);
12145 int idx_protocol = 1;
12146 int type;
12147
12148 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12149 if (type < 0) {
12150 vty_out(vty, "%% Invalid route type\n");
12151 return CMD_WARNING_CONFIG_FAILED;
12152 }
12153
12154 bgp_redist_add(bgp, AFI_IP6, type, 0);
12155 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12156 }
12157
12158 DEFUN (bgp_redistribute_ipv6_rmap,
12159 bgp_redistribute_ipv6_rmap_cmd,
12160 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12161 "Redistribute information from another routing protocol\n"
12162 FRR_IP6_REDIST_HELP_STR_BGPD
12163 "Route map reference\n"
12164 "Pointer to route-map entries\n")
12165 {
12166 VTY_DECLVAR_CONTEXT(bgp, bgp);
12167 int idx_protocol = 1;
12168 int idx_word = 3;
12169 int type;
12170 struct bgp_redist *red;
12171 bool changed;
12172 struct route_map *route_map =
12173 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12174
12175 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12176 if (type < 0) {
12177 vty_out(vty, "%% Invalid route type\n");
12178 return CMD_WARNING_CONFIG_FAILED;
12179 }
12180
12181 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12182 changed =
12183 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12184 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12185 }
12186
12187 DEFUN (bgp_redistribute_ipv6_metric,
12188 bgp_redistribute_ipv6_metric_cmd,
12189 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12190 "Redistribute information from another routing protocol\n"
12191 FRR_IP6_REDIST_HELP_STR_BGPD
12192 "Metric for redistributed routes\n"
12193 "Default metric\n")
12194 {
12195 VTY_DECLVAR_CONTEXT(bgp, bgp);
12196 int idx_protocol = 1;
12197 int idx_number = 3;
12198 int type;
12199 uint32_t metric;
12200 struct bgp_redist *red;
12201 bool changed;
12202
12203 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12204 if (type < 0) {
12205 vty_out(vty, "%% Invalid route type\n");
12206 return CMD_WARNING_CONFIG_FAILED;
12207 }
12208 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12209
12210 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12211 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12212 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12213 }
12214
12215 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12216 bgp_redistribute_ipv6_rmap_metric_cmd,
12217 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12218 "Redistribute information from another routing protocol\n"
12219 FRR_IP6_REDIST_HELP_STR_BGPD
12220 "Route map reference\n"
12221 "Pointer to route-map entries\n"
12222 "Metric for redistributed routes\n"
12223 "Default metric\n")
12224 {
12225 VTY_DECLVAR_CONTEXT(bgp, bgp);
12226 int idx_protocol = 1;
12227 int idx_word = 3;
12228 int idx_number = 5;
12229 int type;
12230 uint32_t metric;
12231 struct bgp_redist *red;
12232 bool changed;
12233 struct route_map *route_map =
12234 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12235
12236 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12237 if (type < 0) {
12238 vty_out(vty, "%% Invalid route type\n");
12239 return CMD_WARNING_CONFIG_FAILED;
12240 }
12241 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12242
12243 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12244 changed =
12245 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12246 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12247 metric);
12248 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12249 }
12250
12251 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12252 bgp_redistribute_ipv6_metric_rmap_cmd,
12253 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12254 "Redistribute information from another routing protocol\n"
12255 FRR_IP6_REDIST_HELP_STR_BGPD
12256 "Metric for redistributed routes\n"
12257 "Default metric\n"
12258 "Route map reference\n"
12259 "Pointer to route-map entries\n")
12260 {
12261 VTY_DECLVAR_CONTEXT(bgp, bgp);
12262 int idx_protocol = 1;
12263 int idx_number = 3;
12264 int idx_word = 5;
12265 int type;
12266 uint32_t metric;
12267 struct bgp_redist *red;
12268 bool changed;
12269 struct route_map *route_map =
12270 route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);
12271
12272 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12273 if (type < 0) {
12274 vty_out(vty, "%% Invalid route type\n");
12275 return CMD_WARNING_CONFIG_FAILED;
12276 }
12277 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12278
12279 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12280 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12281 metric);
12282 changed |=
12283 bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
12284 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12285 }
12286
12287 DEFUN (no_bgp_redistribute_ipv6,
12288 no_bgp_redistribute_ipv6_cmd,
12289 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12290 NO_STR
12291 "Redistribute information from another routing protocol\n"
12292 FRR_IP6_REDIST_HELP_STR_BGPD
12293 "Metric for redistributed routes\n"
12294 "Default metric\n"
12295 "Route map reference\n"
12296 "Pointer to route-map entries\n")
12297 {
12298 VTY_DECLVAR_CONTEXT(bgp, bgp);
12299 int idx_protocol = 2;
12300 int type;
12301
12302 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12303 if (type < 0) {
12304 vty_out(vty, "%% Invalid route type\n");
12305 return CMD_WARNING_CONFIG_FAILED;
12306 }
12307
12308 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12309 }
12310
12311 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12312 safi_t safi)
12313 {
12314 int i;
12315
12316 /* Unicast redistribution only. */
12317 if (safi != SAFI_UNICAST)
12318 return;
12319
12320 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12321 /* Redistribute BGP does not make sense. */
12322 if (i != ZEBRA_ROUTE_BGP) {
12323 struct list *red_list;
12324 struct listnode *node;
12325 struct bgp_redist *red;
12326
12327 red_list = bgp->redist[afi][i];
12328 if (!red_list)
12329 continue;
12330
12331 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12332 /* "redistribute" configuration. */
12333 vty_out(vty, " redistribute %s",
12334 zebra_route_string(i));
12335 if (red->instance)
12336 vty_out(vty, " %d", red->instance);
12337 if (red->redist_metric_flag)
12338 vty_out(vty, " metric %u",
12339 red->redist_metric);
12340 if (red->rmap.name)
12341 vty_out(vty, " route-map %s",
12342 red->rmap.name);
12343 vty_out(vty, "\n");
12344 }
12345 }
12346 }
12347 }
12348
12349 /* This is part of the address-family block (unicast only) */
12350 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12351 afi_t afi)
12352 {
12353 int indent = 2;
12354
12355 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
12356 if (listcount(bgp->vpn_policy[afi].import_vrf))
12357 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12358 bgp->vpn_policy[afi]
12359 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12360 else
12361 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
12362 bgp->vpn_policy[afi]
12363 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12364 }
12365 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12366 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12367 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12368 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12369 return;
12370
12371 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12372 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12373
12374 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12375
12376 } else {
12377 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12378 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12379 bgp->vpn_policy[afi].tovpn_label);
12380 }
12381 }
12382 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12383 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12384 char buf[RD_ADDRSTRLEN];
12385 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12386 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12387 sizeof(buf)));
12388 }
12389 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12390 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12391
12392 char buf[PREFIX_STRLEN];
12393 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12394 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12395 sizeof(buf))) {
12396
12397 vty_out(vty, "%*snexthop vpn export %s\n",
12398 indent, "", buf);
12399 }
12400 }
12401 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12402 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12403 && ecommunity_cmp(
12404 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12405 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12406
12407 char *b = ecommunity_ecom2str(
12408 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12409 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12410 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12411 XFREE(MTYPE_ECOMMUNITY_STR, b);
12412 } else {
12413 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12414 char *b = ecommunity_ecom2str(
12415 bgp->vpn_policy[afi]
12416 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12417 ECOMMUNITY_FORMAT_ROUTE_MAP,
12418 ECOMMUNITY_ROUTE_TARGET);
12419 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12420 XFREE(MTYPE_ECOMMUNITY_STR, b);
12421 }
12422 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12423 char *b = ecommunity_ecom2str(
12424 bgp->vpn_policy[afi]
12425 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12426 ECOMMUNITY_FORMAT_ROUTE_MAP,
12427 ECOMMUNITY_ROUTE_TARGET);
12428 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12429 XFREE(MTYPE_ECOMMUNITY_STR, b);
12430 }
12431 }
12432
12433 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12434 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12435 bgp->vpn_policy[afi]
12436 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12437
12438 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12439 char *b = ecommunity_ecom2str(
12440 bgp->vpn_policy[afi]
12441 .import_redirect_rtlist,
12442 ECOMMUNITY_FORMAT_ROUTE_MAP,
12443 ECOMMUNITY_ROUTE_TARGET);
12444
12445 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12446 XFREE(MTYPE_ECOMMUNITY_STR, b);
12447 }
12448 }
12449
12450
12451 /* BGP node structure. */
12452 static struct cmd_node bgp_node = {
12453 BGP_NODE, "%s(config-router)# ", 1,
12454 };
12455
12456 static struct cmd_node bgp_ipv4_unicast_node = {
12457 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12458 };
12459
12460 static struct cmd_node bgp_ipv4_multicast_node = {
12461 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12462 };
12463
12464 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12465 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12466 };
12467
12468 static struct cmd_node bgp_ipv6_unicast_node = {
12469 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12470 };
12471
12472 static struct cmd_node bgp_ipv6_multicast_node = {
12473 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12474 };
12475
12476 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12477 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12478 };
12479
12480 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12481 "%s(config-router-af)# ", 1};
12482
12483 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12484 "%s(config-router-af-vpnv6)# ", 1};
12485
12486 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12487 "%s(config-router-evpn)# ", 1};
12488
12489 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12490 "%s(config-router-af-vni)# ", 1};
12491
12492 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12493 "%s(config-router-af)# ", 1};
12494
12495 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12496 "%s(config-router-af-vpnv6)# ", 1};
12497
12498 static void community_list_vty(void);
12499
12500 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12501 {
12502 struct bgp *bgp;
12503 struct peer *peer;
12504 struct listnode *lnbgp, *lnpeer;
12505
12506 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12507 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12508 /* only provide suggestions on the appropriate input
12509 * token type,
12510 * they'll otherwise show up multiple times */
12511 enum cmd_token_type match_type;
12512 char *name = peer->host;
12513
12514 if (peer->conf_if) {
12515 match_type = VARIABLE_TKN;
12516 name = peer->conf_if;
12517 } else if (strchr(peer->host, ':'))
12518 match_type = IPV6_TKN;
12519 else
12520 match_type = IPV4_TKN;
12521
12522 if (token->type != match_type)
12523 continue;
12524
12525 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12526 }
12527 }
12528 }
12529
12530 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12531 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12532 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12533 {.varname = "peer", .completions = bgp_ac_neighbor},
12534 {.completions = NULL}};
12535
12536 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12537 {
12538 struct bgp *bgp;
12539 struct peer_group *group;
12540 struct listnode *lnbgp, *lnpeer;
12541
12542 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12543 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12544 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12545 group->name));
12546 }
12547 }
12548
12549 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12550 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12551 {.completions = NULL} };
12552
12553 void bgp_vty_init(void)
12554 {
12555 cmd_variable_handler_register(bgp_var_neighbor);
12556 cmd_variable_handler_register(bgp_var_peergroup);
12557
12558 /* Install bgp top node. */
12559 install_node(&bgp_node, bgp_config_write);
12560 install_node(&bgp_ipv4_unicast_node, NULL);
12561 install_node(&bgp_ipv4_multicast_node, NULL);
12562 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12563 install_node(&bgp_ipv6_unicast_node, NULL);
12564 install_node(&bgp_ipv6_multicast_node, NULL);
12565 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12566 install_node(&bgp_vpnv4_node, NULL);
12567 install_node(&bgp_vpnv6_node, NULL);
12568 install_node(&bgp_evpn_node, NULL);
12569 install_node(&bgp_evpn_vni_node, NULL);
12570 install_node(&bgp_flowspecv4_node, NULL);
12571 install_node(&bgp_flowspecv6_node, NULL);
12572
12573 /* Install default VTY commands to new nodes. */
12574 install_default(BGP_NODE);
12575 install_default(BGP_IPV4_NODE);
12576 install_default(BGP_IPV4M_NODE);
12577 install_default(BGP_IPV4L_NODE);
12578 install_default(BGP_IPV6_NODE);
12579 install_default(BGP_IPV6M_NODE);
12580 install_default(BGP_IPV6L_NODE);
12581 install_default(BGP_VPNV4_NODE);
12582 install_default(BGP_VPNV6_NODE);
12583 install_default(BGP_FLOWSPECV4_NODE);
12584 install_default(BGP_FLOWSPECV6_NODE);
12585 install_default(BGP_EVPN_NODE);
12586 install_default(BGP_EVPN_VNI_NODE);
12587
12588 /* "bgp multiple-instance" commands. */
12589 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12590 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12591
12592 /* "bgp config-type" commands. */
12593 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12594 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12595
12596 /* bgp route-map delay-timer commands. */
12597 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12598 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12599
12600 /* Dummy commands (Currently not supported) */
12601 install_element(BGP_NODE, &no_synchronization_cmd);
12602 install_element(BGP_NODE, &no_auto_summary_cmd);
12603
12604 /* "router bgp" commands. */
12605 install_element(CONFIG_NODE, &router_bgp_cmd);
12606
12607 /* "no router bgp" commands. */
12608 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12609
12610 /* "bgp router-id" commands. */
12611 install_element(BGP_NODE, &bgp_router_id_cmd);
12612 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12613
12614 /* "bgp cluster-id" commands. */
12615 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12616 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12617
12618 /* "bgp confederation" commands. */
12619 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12620 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12621
12622 /* "bgp confederation peers" commands. */
12623 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12624 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12625
12626 /* bgp max-med command */
12627 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12628 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12629 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12630 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12631 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12632
12633 /* bgp disable-ebgp-connected-nh-check */
12634 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12635 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12636
12637 /* bgp update-delay command */
12638 install_element(BGP_NODE, &bgp_update_delay_cmd);
12639 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12640 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12641
12642 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12643 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12644 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12645 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12646
12647 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12648 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12649
12650 /* "maximum-paths" commands. */
12651 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12652 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12653 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12654 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12655 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12656 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12657 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12658 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12659 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12660 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12661 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12662 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12663 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12664 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12665 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12666
12667 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12668 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12669 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12670 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12671 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12672
12673 /* "timers bgp" commands. */
12674 install_element(BGP_NODE, &bgp_timers_cmd);
12675 install_element(BGP_NODE, &no_bgp_timers_cmd);
12676
12677 /* route-map delay-timer commands - per instance for backwards compat.
12678 */
12679 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12680 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12681
12682 /* "bgp client-to-client reflection" commands */
12683 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12684 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12685
12686 /* "bgp always-compare-med" commands */
12687 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12688 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12689
12690 /* "bgp deterministic-med" commands */
12691 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12692 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12693
12694 /* "bgp graceful-restart" commands */
12695 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12696 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12697 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12698 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12699 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12700 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12701
12702 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12703 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12704
12705 /* "bgp graceful-shutdown" commands */
12706 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12707 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12708
12709 /* "bgp fast-external-failover" commands */
12710 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12711 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12712
12713 /* "bgp enforce-first-as" commands */
12714 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12715
12716 /* "bgp bestpath compare-routerid" commands */
12717 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12718 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12719
12720 /* "bgp bestpath as-path ignore" commands */
12721 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12722 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12723
12724 /* "bgp bestpath as-path confed" commands */
12725 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12726 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12727
12728 /* "bgp bestpath as-path multipath-relax" commands */
12729 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12730 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12731
12732 /* "bgp log-neighbor-changes" commands */
12733 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12734 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12735
12736 /* "bgp bestpath med" commands */
12737 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12738 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12739
12740 /* "no bgp default ipv4-unicast" commands. */
12741 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12742 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12743
12744 /* "bgp network import-check" commands. */
12745 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12746 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12747 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12748
12749 /* "bgp default local-preference" commands. */
12750 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12751 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12752
12753 /* bgp default show-hostname */
12754 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12755 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12756
12757 /* "bgp default subgroup-pkt-queue-max" commands. */
12758 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12759 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12760
12761 /* bgp ibgp-allow-policy-mods command */
12762 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12763 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12764
12765 /* "bgp listen limit" commands. */
12766 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12767 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12768
12769 /* "bgp listen range" commands. */
12770 install_element(BGP_NODE, &bgp_listen_range_cmd);
12771 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12772
12773 /* "bgp default shutdown" command */
12774 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12775
12776 /* "neighbor remote-as" commands. */
12777 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12778 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12779 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12780 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12781 install_element(BGP_NODE,
12782 &neighbor_interface_v6only_config_remote_as_cmd);
12783 install_element(BGP_NODE, &no_neighbor_cmd);
12784 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12785
12786 /* "neighbor peer-group" commands. */
12787 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12788 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12789 install_element(BGP_NODE,
12790 &no_neighbor_interface_peer_group_remote_as_cmd);
12791
12792 /* "neighbor local-as" commands. */
12793 install_element(BGP_NODE, &neighbor_local_as_cmd);
12794 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12795 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12796 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12797
12798 /* "neighbor solo" commands. */
12799 install_element(BGP_NODE, &neighbor_solo_cmd);
12800 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12801
12802 /* "neighbor password" commands. */
12803 install_element(BGP_NODE, &neighbor_password_cmd);
12804 install_element(BGP_NODE, &no_neighbor_password_cmd);
12805
12806 /* "neighbor activate" commands. */
12807 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12808 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12809 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12810 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12811 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12812 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12813 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12814 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12815 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12816 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12817 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12818 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12819
12820 /* "no neighbor activate" commands. */
12821 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12822 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12823 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12824 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12825 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12826 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12827 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12828 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12829 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12830 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12831 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12832 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12833
12834 /* "neighbor peer-group" set commands. */
12835 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12836 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12837 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12838 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12839 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12840 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12841 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12842 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12843 install_element(BGP_FLOWSPECV4_NODE,
12844 &neighbor_set_peer_group_hidden_cmd);
12845 install_element(BGP_FLOWSPECV6_NODE,
12846 &neighbor_set_peer_group_hidden_cmd);
12847
12848 /* "no neighbor peer-group unset" commands. */
12849 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12850 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12851 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12852 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12853 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12854 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12855 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12856 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12857 install_element(BGP_FLOWSPECV4_NODE,
12858 &no_neighbor_set_peer_group_hidden_cmd);
12859 install_element(BGP_FLOWSPECV6_NODE,
12860 &no_neighbor_set_peer_group_hidden_cmd);
12861
12862 /* "neighbor softreconfiguration inbound" commands.*/
12863 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12864 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12865 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12866 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12867 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12868 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12869 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12870 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12871 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12872 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12873 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12874 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12875 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12876 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12877 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12878 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12879 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12880 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12881 install_element(BGP_FLOWSPECV4_NODE,
12882 &neighbor_soft_reconfiguration_cmd);
12883 install_element(BGP_FLOWSPECV4_NODE,
12884 &no_neighbor_soft_reconfiguration_cmd);
12885 install_element(BGP_FLOWSPECV6_NODE,
12886 &neighbor_soft_reconfiguration_cmd);
12887 install_element(BGP_FLOWSPECV6_NODE,
12888 &no_neighbor_soft_reconfiguration_cmd);
12889
12890 /* "neighbor attribute-unchanged" commands. */
12891 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12892 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12893 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12894 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12895 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12896 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12897 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12898 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12899 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12900 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12901 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12902 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12903 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12904 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12905 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12906 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12907 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12908 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12909
12910 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12911 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12912
12913 /* "nexthop-local unchanged" commands */
12914 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12915 install_element(BGP_IPV6_NODE,
12916 &no_neighbor_nexthop_local_unchanged_cmd);
12917
12918 /* "neighbor next-hop-self" commands. */
12919 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12920 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12921 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12922 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12923 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12924 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12925 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12926 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12927 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12928 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12929 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12930 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12931 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12932 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12933 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12934 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12935 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12936 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12937 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12938 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12939
12940 /* "neighbor next-hop-self force" commands. */
12941 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12942 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12943 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12944 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12945 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12946 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12947 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12948 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12949 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12950 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12951 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12952 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12953 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12954 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12955 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12956 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12957 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12958 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12959
12960 /* "neighbor as-override" commands. */
12961 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12962 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12963 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12964 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12965 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12966 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12967 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12968 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12969 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12970 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12971 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12972 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12973 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12974 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12975 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12976 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12977 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12978 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12979
12980 /* "neighbor remove-private-AS" commands. */
12981 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12982 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12983 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12984 install_element(BGP_NODE,
12985 &no_neighbor_remove_private_as_all_hidden_cmd);
12986 install_element(BGP_NODE,
12987 &neighbor_remove_private_as_replace_as_hidden_cmd);
12988 install_element(BGP_NODE,
12989 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12990 install_element(BGP_NODE,
12991 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12992 install_element(
12993 BGP_NODE,
12994 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12995 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12996 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12997 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12998 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12999 install_element(BGP_IPV4_NODE,
13000 &neighbor_remove_private_as_replace_as_cmd);
13001 install_element(BGP_IPV4_NODE,
13002 &no_neighbor_remove_private_as_replace_as_cmd);
13003 install_element(BGP_IPV4_NODE,
13004 &neighbor_remove_private_as_all_replace_as_cmd);
13005 install_element(BGP_IPV4_NODE,
13006 &no_neighbor_remove_private_as_all_replace_as_cmd);
13007 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
13008 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
13009 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
13010 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
13011 install_element(BGP_IPV4M_NODE,
13012 &neighbor_remove_private_as_replace_as_cmd);
13013 install_element(BGP_IPV4M_NODE,
13014 &no_neighbor_remove_private_as_replace_as_cmd);
13015 install_element(BGP_IPV4M_NODE,
13016 &neighbor_remove_private_as_all_replace_as_cmd);
13017 install_element(BGP_IPV4M_NODE,
13018 &no_neighbor_remove_private_as_all_replace_as_cmd);
13019 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
13020 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
13021 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
13022 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
13023 install_element(BGP_IPV4L_NODE,
13024 &neighbor_remove_private_as_replace_as_cmd);
13025 install_element(BGP_IPV4L_NODE,
13026 &no_neighbor_remove_private_as_replace_as_cmd);
13027 install_element(BGP_IPV4L_NODE,
13028 &neighbor_remove_private_as_all_replace_as_cmd);
13029 install_element(BGP_IPV4L_NODE,
13030 &no_neighbor_remove_private_as_all_replace_as_cmd);
13031 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
13032 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
13033 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
13034 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13035 install_element(BGP_IPV6_NODE,
13036 &neighbor_remove_private_as_replace_as_cmd);
13037 install_element(BGP_IPV6_NODE,
13038 &no_neighbor_remove_private_as_replace_as_cmd);
13039 install_element(BGP_IPV6_NODE,
13040 &neighbor_remove_private_as_all_replace_as_cmd);
13041 install_element(BGP_IPV6_NODE,
13042 &no_neighbor_remove_private_as_all_replace_as_cmd);
13043 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
13044 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
13045 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
13046 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
13047 install_element(BGP_IPV6M_NODE,
13048 &neighbor_remove_private_as_replace_as_cmd);
13049 install_element(BGP_IPV6M_NODE,
13050 &no_neighbor_remove_private_as_replace_as_cmd);
13051 install_element(BGP_IPV6M_NODE,
13052 &neighbor_remove_private_as_all_replace_as_cmd);
13053 install_element(BGP_IPV6M_NODE,
13054 &no_neighbor_remove_private_as_all_replace_as_cmd);
13055 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
13056 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
13057 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
13058 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
13059 install_element(BGP_IPV6L_NODE,
13060 &neighbor_remove_private_as_replace_as_cmd);
13061 install_element(BGP_IPV6L_NODE,
13062 &no_neighbor_remove_private_as_replace_as_cmd);
13063 install_element(BGP_IPV6L_NODE,
13064 &neighbor_remove_private_as_all_replace_as_cmd);
13065 install_element(BGP_IPV6L_NODE,
13066 &no_neighbor_remove_private_as_all_replace_as_cmd);
13067 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
13068 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
13069 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
13070 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
13071 install_element(BGP_VPNV4_NODE,
13072 &neighbor_remove_private_as_replace_as_cmd);
13073 install_element(BGP_VPNV4_NODE,
13074 &no_neighbor_remove_private_as_replace_as_cmd);
13075 install_element(BGP_VPNV4_NODE,
13076 &neighbor_remove_private_as_all_replace_as_cmd);
13077 install_element(BGP_VPNV4_NODE,
13078 &no_neighbor_remove_private_as_all_replace_as_cmd);
13079 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13080 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13081 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13082 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13083 install_element(BGP_VPNV6_NODE,
13084 &neighbor_remove_private_as_replace_as_cmd);
13085 install_element(BGP_VPNV6_NODE,
13086 &no_neighbor_remove_private_as_replace_as_cmd);
13087 install_element(BGP_VPNV6_NODE,
13088 &neighbor_remove_private_as_all_replace_as_cmd);
13089 install_element(BGP_VPNV6_NODE,
13090 &no_neighbor_remove_private_as_all_replace_as_cmd);
13091
13092 /* "neighbor send-community" commands.*/
13093 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13094 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13095 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13096 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13097 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13098 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13099 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13100 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13101 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13102 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13103 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13104 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13105 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13106 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13107 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13108 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13109 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13110 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13111 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13112 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13113 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13114 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13115 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13116 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13117 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13118 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13119 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13120 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13121 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13122 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13123 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13124 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13125 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13126 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13127 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13128 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13129
13130 /* "neighbor route-reflector" commands.*/
13131 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13132 install_element(BGP_NODE,
13133 &no_neighbor_route_reflector_client_hidden_cmd);
13134 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13135 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13136 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13137 install_element(BGP_IPV4M_NODE,
13138 &no_neighbor_route_reflector_client_cmd);
13139 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13140 install_element(BGP_IPV4L_NODE,
13141 &no_neighbor_route_reflector_client_cmd);
13142 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13143 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13144 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13145 install_element(BGP_IPV6M_NODE,
13146 &no_neighbor_route_reflector_client_cmd);
13147 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13148 install_element(BGP_IPV6L_NODE,
13149 &no_neighbor_route_reflector_client_cmd);
13150 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13151 install_element(BGP_VPNV4_NODE,
13152 &no_neighbor_route_reflector_client_cmd);
13153 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13154 install_element(BGP_VPNV6_NODE,
13155 &no_neighbor_route_reflector_client_cmd);
13156 install_element(BGP_FLOWSPECV4_NODE,
13157 &neighbor_route_reflector_client_cmd);
13158 install_element(BGP_FLOWSPECV4_NODE,
13159 &no_neighbor_route_reflector_client_cmd);
13160 install_element(BGP_FLOWSPECV6_NODE,
13161 &neighbor_route_reflector_client_cmd);
13162 install_element(BGP_FLOWSPECV6_NODE,
13163 &no_neighbor_route_reflector_client_cmd);
13164 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13165 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13166
13167 /* "neighbor route-server" commands.*/
13168 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13169 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13170 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13171 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13172 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13173 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13174 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13175 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13176 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13177 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13178 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13179 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13180 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13181 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13182 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13183 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13184 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13185 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13186 install_element(BGP_EVPN_NODE, &neighbor_route_server_client_cmd);
13187 install_element(BGP_EVPN_NODE, &no_neighbor_route_server_client_cmd);
13188 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13189 install_element(BGP_FLOWSPECV4_NODE,
13190 &no_neighbor_route_server_client_cmd);
13191 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13192 install_element(BGP_FLOWSPECV6_NODE,
13193 &no_neighbor_route_server_client_cmd);
13194
13195 /* "neighbor addpath-tx-all-paths" commands.*/
13196 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13197 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13198 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13199 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13200 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13201 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13202 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13203 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13204 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13205 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13206 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13207 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13208 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13209 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13210 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13211 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13212 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13213 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13214
13215 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13216 install_element(BGP_NODE,
13217 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13218 install_element(BGP_NODE,
13219 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13220 install_element(BGP_IPV4_NODE,
13221 &neighbor_addpath_tx_bestpath_per_as_cmd);
13222 install_element(BGP_IPV4_NODE,
13223 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13224 install_element(BGP_IPV4M_NODE,
13225 &neighbor_addpath_tx_bestpath_per_as_cmd);
13226 install_element(BGP_IPV4M_NODE,
13227 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13228 install_element(BGP_IPV4L_NODE,
13229 &neighbor_addpath_tx_bestpath_per_as_cmd);
13230 install_element(BGP_IPV4L_NODE,
13231 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13232 install_element(BGP_IPV6_NODE,
13233 &neighbor_addpath_tx_bestpath_per_as_cmd);
13234 install_element(BGP_IPV6_NODE,
13235 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13236 install_element(BGP_IPV6M_NODE,
13237 &neighbor_addpath_tx_bestpath_per_as_cmd);
13238 install_element(BGP_IPV6M_NODE,
13239 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13240 install_element(BGP_IPV6L_NODE,
13241 &neighbor_addpath_tx_bestpath_per_as_cmd);
13242 install_element(BGP_IPV6L_NODE,
13243 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13244 install_element(BGP_VPNV4_NODE,
13245 &neighbor_addpath_tx_bestpath_per_as_cmd);
13246 install_element(BGP_VPNV4_NODE,
13247 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13248 install_element(BGP_VPNV6_NODE,
13249 &neighbor_addpath_tx_bestpath_per_as_cmd);
13250 install_element(BGP_VPNV6_NODE,
13251 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13252
13253 /* "neighbor passive" commands. */
13254 install_element(BGP_NODE, &neighbor_passive_cmd);
13255 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13256
13257
13258 /* "neighbor shutdown" commands. */
13259 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13260 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13261 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13262 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13263
13264 /* "neighbor capability extended-nexthop" commands.*/
13265 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13266 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13267
13268 /* "neighbor capability orf prefix-list" commands.*/
13269 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13270 install_element(BGP_NODE,
13271 &no_neighbor_capability_orf_prefix_hidden_cmd);
13272 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13273 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13274 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13275 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13276 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13277 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13278 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13279 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13280 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13281 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13282 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13283 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13284
13285 /* "neighbor capability dynamic" commands.*/
13286 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13287 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13288
13289 /* "neighbor dont-capability-negotiate" commands. */
13290 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13291 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13292
13293 /* "neighbor ebgp-multihop" commands. */
13294 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13295 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13296 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13297
13298 /* "neighbor disable-connected-check" commands. */
13299 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13300 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13301
13302 /* "neighbor enforce-first-as" commands. */
13303 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13304 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13305
13306 /* "neighbor description" commands. */
13307 install_element(BGP_NODE, &neighbor_description_cmd);
13308 install_element(BGP_NODE, &no_neighbor_description_cmd);
13309 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13310
13311 /* "neighbor update-source" commands. "*/
13312 install_element(BGP_NODE, &neighbor_update_source_cmd);
13313 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13314
13315 /* "neighbor default-originate" commands. */
13316 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13317 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13318 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13319 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13320 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13321 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13322 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13323 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13324 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13325 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13326 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13327 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13328 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13329 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13330 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13331 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13332 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13333 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13334 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13335 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13336 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13337
13338 /* "neighbor port" commands. */
13339 install_element(BGP_NODE, &neighbor_port_cmd);
13340 install_element(BGP_NODE, &no_neighbor_port_cmd);
13341
13342 /* "neighbor weight" commands. */
13343 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13344 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13345
13346 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13347 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13348 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13349 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13350 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13351 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13352 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13353 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13354 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13355 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13356 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13357 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13358 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13359 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13360 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13361 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13362
13363 /* "neighbor override-capability" commands. */
13364 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13365 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13366
13367 /* "neighbor strict-capability-match" commands. */
13368 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13369 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13370
13371 /* "neighbor timers" commands. */
13372 install_element(BGP_NODE, &neighbor_timers_cmd);
13373 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13374
13375 /* "neighbor timers connect" commands. */
13376 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13377 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13378
13379 /* "neighbor advertisement-interval" commands. */
13380 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13381 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13382
13383 /* "neighbor interface" commands. */
13384 install_element(BGP_NODE, &neighbor_interface_cmd);
13385 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13386
13387 /* "neighbor distribute" commands. */
13388 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13389 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13390 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13391 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13392 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13393 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13394 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13395 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13396 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13397 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13398 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13399 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13400 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13401 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13402 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13403 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13404 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13405 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13406
13407 /* "neighbor prefix-list" commands. */
13408 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13409 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13410 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13411 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13412 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13413 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13414 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13415 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13416 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13417 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13418 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13419 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13420 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13421 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13422 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13423 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13424 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13425 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13426 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13427 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13428 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13429 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13430
13431 /* "neighbor filter-list" commands. */
13432 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13433 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13434 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13435 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13436 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13437 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13438 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13439 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13440 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13441 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13442 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13443 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13444 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13445 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13446 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13447 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13448 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13449 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13450 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13451 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13452 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13453 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13454
13455 /* "neighbor route-map" commands. */
13456 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13457 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13458 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13459 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13460 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13461 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13462 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13463 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13464 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13465 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13466 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13467 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13468 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13469 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13470 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13471 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13472 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13473 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13474 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13475 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13476 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13477 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13478 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13479 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13480
13481 /* "neighbor unsuppress-map" commands. */
13482 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13483 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13484 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13485 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13486 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13487 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13488 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13489 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13490 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13491 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13492 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13493 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13494 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13495 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13496 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13497 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13498 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13499 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13500
13501 /* "neighbor maximum-prefix" commands. */
13502 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13503 install_element(BGP_NODE,
13504 &neighbor_maximum_prefix_threshold_hidden_cmd);
13505 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13506 install_element(BGP_NODE,
13507 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13508 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13509 install_element(BGP_NODE,
13510 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13511 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13512 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13513 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13514 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13515 install_element(BGP_IPV4_NODE,
13516 &neighbor_maximum_prefix_threshold_warning_cmd);
13517 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13518 install_element(BGP_IPV4_NODE,
13519 &neighbor_maximum_prefix_threshold_restart_cmd);
13520 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13521 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13522 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13523 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13524 install_element(BGP_IPV4M_NODE,
13525 &neighbor_maximum_prefix_threshold_warning_cmd);
13526 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13527 install_element(BGP_IPV4M_NODE,
13528 &neighbor_maximum_prefix_threshold_restart_cmd);
13529 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13530 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13531 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13532 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13533 install_element(BGP_IPV4L_NODE,
13534 &neighbor_maximum_prefix_threshold_warning_cmd);
13535 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13536 install_element(BGP_IPV4L_NODE,
13537 &neighbor_maximum_prefix_threshold_restart_cmd);
13538 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13539 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13540 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13541 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13542 install_element(BGP_IPV6_NODE,
13543 &neighbor_maximum_prefix_threshold_warning_cmd);
13544 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13545 install_element(BGP_IPV6_NODE,
13546 &neighbor_maximum_prefix_threshold_restart_cmd);
13547 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13548 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13549 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13550 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13551 install_element(BGP_IPV6M_NODE,
13552 &neighbor_maximum_prefix_threshold_warning_cmd);
13553 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13554 install_element(BGP_IPV6M_NODE,
13555 &neighbor_maximum_prefix_threshold_restart_cmd);
13556 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13557 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13558 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13559 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13560 install_element(BGP_IPV6L_NODE,
13561 &neighbor_maximum_prefix_threshold_warning_cmd);
13562 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13563 install_element(BGP_IPV6L_NODE,
13564 &neighbor_maximum_prefix_threshold_restart_cmd);
13565 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13566 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13567 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13568 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13569 install_element(BGP_VPNV4_NODE,
13570 &neighbor_maximum_prefix_threshold_warning_cmd);
13571 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13572 install_element(BGP_VPNV4_NODE,
13573 &neighbor_maximum_prefix_threshold_restart_cmd);
13574 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13575 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13576 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13577 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13578 install_element(BGP_VPNV6_NODE,
13579 &neighbor_maximum_prefix_threshold_warning_cmd);
13580 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13581 install_element(BGP_VPNV6_NODE,
13582 &neighbor_maximum_prefix_threshold_restart_cmd);
13583 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13584
13585 /* "neighbor allowas-in" */
13586 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13587 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13588 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13589 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13590 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13591 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13592 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13593 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13594 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13595 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13596 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13597 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13598 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13599 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13600 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13601 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13602 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13603 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13604 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13605 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13606
13607 /* address-family commands. */
13608 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13609 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13610 #ifdef KEEP_OLD_VPN_COMMANDS
13611 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13612 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13613 #endif /* KEEP_OLD_VPN_COMMANDS */
13614
13615 install_element(BGP_NODE, &address_family_evpn_cmd);
13616
13617 /* "exit-address-family" command. */
13618 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13619 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13620 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13621 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13622 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13623 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13624 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13625 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13626 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13627 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13628 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13629
13630 /* "clear ip bgp commands" */
13631 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13632
13633 /* clear ip bgp prefix */
13634 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13635 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13636 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13637
13638 /* "show [ip] bgp summary" commands. */
13639 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13640 install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_updgrps_cmd);
13641 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13642 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13643 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13644 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13645 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13646
13647 /* "show [ip] bgp neighbors" commands. */
13648 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13649
13650 /* "show [ip] bgp peer-group" commands. */
13651 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13652
13653 /* "show [ip] bgp paths" commands. */
13654 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13655
13656 /* "show [ip] bgp community" commands. */
13657 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13658
13659 /* "show ip bgp large-community" commands. */
13660 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13661 /* "show [ip] bgp attribute-info" commands. */
13662 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13663 /* "show [ip] bgp route-leak" command */
13664 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13665
13666 /* "redistribute" commands. */
13667 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13668 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13669 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13670 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13671 install_element(BGP_NODE,
13672 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13673 install_element(BGP_NODE,
13674 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13675 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13676 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13677 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13678 install_element(BGP_NODE,
13679 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13680 install_element(BGP_NODE,
13681 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13682 install_element(BGP_NODE,
13683 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13684 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13685 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13686 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13687 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13688 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13689 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13690 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13691 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13692 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13693 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13694 install_element(BGP_IPV4_NODE,
13695 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13696 install_element(BGP_IPV4_NODE,
13697 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13698 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13699 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13700 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13701 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13702 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13703 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13704
13705 /* import|export vpn [route-map WORD] */
13706 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13707 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13708
13709 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13710 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13711
13712 /* ttl_security commands */
13713 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13714 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13715
13716 /* "show [ip] bgp memory" commands. */
13717 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13718
13719 /* "show bgp martian next-hop" */
13720 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13721
13722 /* "show [ip] bgp views" commands. */
13723 install_element(VIEW_NODE, &show_bgp_views_cmd);
13724
13725 /* "show [ip] bgp vrfs" commands. */
13726 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13727
13728 /* Community-list. */
13729 community_list_vty();
13730
13731 /* vpn-policy commands */
13732 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13733 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13734 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13735 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13736 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13737 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13738 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13739 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13740 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13741 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13742 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13743 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13744
13745 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13746 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13747
13748 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13749 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13750 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13751 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13752 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13753 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13754 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13755 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13756 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13757 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13758 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13759 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13760 }
13761
13762 #include "memory.h"
13763 #include "bgp_regex.h"
13764 #include "bgp_clist.h"
13765 #include "bgp_ecommunity.h"
13766
13767 /* VTY functions. */
13768
13769 /* Direction value to string conversion. */
13770 static const char *community_direct_str(int direct)
13771 {
13772 switch (direct) {
13773 case COMMUNITY_DENY:
13774 return "deny";
13775 case COMMUNITY_PERMIT:
13776 return "permit";
13777 default:
13778 return "unknown";
13779 }
13780 }
13781
13782 /* Display error string. */
13783 static void community_list_perror(struct vty *vty, int ret)
13784 {
13785 switch (ret) {
13786 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13787 vty_out(vty, "%% Can't find community-list\n");
13788 break;
13789 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13790 vty_out(vty, "%% Malformed community-list value\n");
13791 break;
13792 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13793 vty_out(vty,
13794 "%% Community name conflict, previously defined as standard community\n");
13795 break;
13796 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13797 vty_out(vty,
13798 "%% Community name conflict, previously defined as expanded community\n");
13799 break;
13800 }
13801 }
13802
13803 /* "community-list" keyword help string. */
13804 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13805
13806 /*community-list standard */
13807 DEFUN (community_list_standard,
13808 bgp_community_list_standard_cmd,
13809 "bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13810 BGP_STR
13811 COMMUNITY_LIST_STR
13812 "Community list number (standard)\n"
13813 "Add an standard community-list entry\n"
13814 "Community list name\n"
13815 "Specify community to reject\n"
13816 "Specify community to accept\n"
13817 COMMUNITY_VAL_STR)
13818 {
13819 char *cl_name_or_number = NULL;
13820 int direct = 0;
13821 int style = COMMUNITY_LIST_STANDARD;
13822
13823 int idx = 0;
13824
13825 if (argv_find(argv, argc, "ip", &idx)) {
13826 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13827 vty_out(vty, "if you are using this please migrate to the below command.\n");
13828 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13829 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13830 }
13831
13832 argv_find(argv, argc, "(1-99)", &idx);
13833 argv_find(argv, argc, "WORD", &idx);
13834 cl_name_or_number = argv[idx]->arg;
13835 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13836 : COMMUNITY_DENY;
13837 argv_find(argv, argc, "AA:NN", &idx);
13838 char *str = argv_concat(argv, argc, idx);
13839
13840 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13841 style);
13842
13843 XFREE(MTYPE_TMP, str);
13844
13845 if (ret < 0) {
13846 /* Display error string. */
13847 community_list_perror(vty, ret);
13848 return CMD_WARNING_CONFIG_FAILED;
13849 }
13850
13851 return CMD_SUCCESS;
13852 }
13853
13854 #if CONFDATE > 20191005
13855 CPP_NOTICE("bgpd: remove deprecated 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' command")
13856 #endif
13857 ALIAS (community_list_standard,
13858 ip_community_list_standard_cmd,
13859 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13860 IP_STR
13861 COMMUNITY_LIST_STR
13862 "Community list number (standard)\n"
13863 "Add an standard community-list entry\n"
13864 "Community list name\n"
13865 "Specify community to reject\n"
13866 "Specify community to accept\n"
13867 COMMUNITY_VAL_STR)
13868
13869 DEFUN (no_community_list_standard_all,
13870 no_bgp_community_list_standard_all_cmd,
13871 "no bgp community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13872 NO_STR
13873 BGP_STR
13874 COMMUNITY_LIST_STR
13875 "Community list number (standard)\n"
13876 "Add an standard community-list entry\n"
13877 "Community list name\n"
13878 "Specify community to reject\n"
13879 "Specify community to accept\n"
13880 COMMUNITY_VAL_STR)
13881 {
13882 char *cl_name_or_number = NULL;
13883 int direct = 0;
13884 int style = COMMUNITY_LIST_STANDARD;
13885
13886 int idx = 0;
13887
13888 if (argv_find(argv, argc, "ip", &idx)) {
13889 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
13890 vty_out(vty, "if you are using this please migrate to the below command.\n");
13891 vty_out(vty, "'no bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13892 zlog_warn("Deprecated option: 'no ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> |AA:NN' being used");
13893 }
13894
13895 argv_find(argv, argc, "(1-99)", &idx);
13896 argv_find(argv, argc, "WORD", &idx);
13897 cl_name_or_number = argv[idx]->arg;
13898 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13899 : COMMUNITY_DENY;
13900 argv_find(argv, argc, "AA:NN", &idx);
13901 char *str = argv_concat(argv, argc, idx);
13902
13903 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13904 direct, style);
13905
13906 XFREE(MTYPE_TMP, str);
13907
13908 if (ret < 0) {
13909 community_list_perror(vty, ret);
13910 return CMD_WARNING_CONFIG_FAILED;
13911 }
13912
13913 return CMD_SUCCESS;
13914 }
13915 ALIAS (no_community_list_standard_all,
13916 no_ip_community_list_standard_all_cmd,
13917 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13918 NO_STR
13919 IP_STR
13920 COMMUNITY_LIST_STR
13921 "Community list number (standard)\n"
13922 "Add an standard community-list entry\n"
13923 "Community list name\n"
13924 "Specify community to reject\n"
13925 "Specify community to accept\n"
13926 COMMUNITY_VAL_STR)
13927
13928 /*community-list expanded */
13929 DEFUN (community_list_expanded_all,
13930 bgp_community_list_expanded_all_cmd,
13931 "bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13932 BGP_STR
13933 COMMUNITY_LIST_STR
13934 "Community list number (expanded)\n"
13935 "Add an expanded community-list entry\n"
13936 "Community list name\n"
13937 "Specify community to reject\n"
13938 "Specify community to accept\n"
13939 COMMUNITY_VAL_STR)
13940 {
13941 char *cl_name_or_number = NULL;
13942 int direct = 0;
13943 int style = COMMUNITY_LIST_EXPANDED;
13944
13945 int idx = 0;
13946 if (argv_find(argv, argc, "ip", &idx)) {
13947 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
13948 vty_out(vty, "if you are using this please migrate to the below command.\n");
13949 vty_out(vty, "'bgp community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
13950 zlog_warn("Deprecated option: 'ip community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
13951 }
13952 argv_find(argv, argc, "(100-500)", &idx);
13953 argv_find(argv, argc, "WORD", &idx);
13954 cl_name_or_number = argv[idx]->arg;
13955 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13956 : COMMUNITY_DENY;
13957 argv_find(argv, argc, "AA:NN", &idx);
13958 char *str = argv_concat(argv, argc, idx);
13959
13960 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13961 style);
13962
13963 XFREE(MTYPE_TMP, str);
13964
13965 if (ret < 0) {
13966 /* Display error string. */
13967 community_list_perror(vty, ret);
13968 return CMD_WARNING_CONFIG_FAILED;
13969 }
13970
13971 return CMD_SUCCESS;
13972 }
13973
13974 ALIAS (community_list_expanded_all,
13975 ip_community_list_expanded_all_cmd,
13976 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13977 IP_STR
13978 COMMUNITY_LIST_STR
13979 "Community list number (expanded)\n"
13980 "Add an expanded community-list entry\n"
13981 "Community list name\n"
13982 "Specify community to reject\n"
13983 "Specify community to accept\n"
13984 COMMUNITY_VAL_STR)
13985
13986 DEFUN (no_community_list_expanded_all,
13987 no_bgp_community_list_expanded_all_cmd,
13988 "no bgp community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13989 NO_STR
13990 BGP_STR
13991 COMMUNITY_LIST_STR
13992 "Community list number (expanded)\n"
13993 "Add an expanded community-list entry\n"
13994 "Community list name\n"
13995 "Specify community to reject\n"
13996 "Specify community to accept\n"
13997 COMMUNITY_VAL_STR)
13998 {
13999 char *cl_name_or_number = NULL;
14000 int direct = 0;
14001 int style = COMMUNITY_LIST_EXPANDED;
14002
14003 int idx = 0;
14004 if (argv_find(argv, argc, "ip", &idx)) {
14005 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14006 vty_out(vty, "if you are using this please migrate to the below command.\n");
14007 vty_out(vty, "'no community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN'\n");
14008 zlog_warn("Deprecated option: 'no community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> AA:NN' being used");
14009 }
14010 argv_find(argv, argc, "(100-500)", &idx);
14011 argv_find(argv, argc, "WORD", &idx);
14012 cl_name_or_number = argv[idx]->arg;
14013 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14014 : COMMUNITY_DENY;
14015 argv_find(argv, argc, "AA:NN", &idx);
14016 char *str = argv_concat(argv, argc, idx);
14017
14018 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
14019 direct, style);
14020
14021 XFREE(MTYPE_TMP, str);
14022
14023 if (ret < 0) {
14024 community_list_perror(vty, ret);
14025 return CMD_WARNING_CONFIG_FAILED;
14026 }
14027
14028 return CMD_SUCCESS;
14029 }
14030
14031 ALIAS (no_community_list_expanded_all,
14032 no_ip_community_list_expanded_all_cmd,
14033 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
14034 NO_STR
14035 IP_STR
14036 COMMUNITY_LIST_STR
14037 "Community list number (expanded)\n"
14038 "Add an expanded community-list entry\n"
14039 "Community list name\n"
14040 "Specify community to reject\n"
14041 "Specify community to accept\n"
14042 COMMUNITY_VAL_STR)
14043
14044 /* Return configuration string of community-list entry. */
14045 static const char *community_list_config_str(struct community_entry *entry)
14046 {
14047 const char *str;
14048
14049 if (entry->any)
14050 str = "";
14051 else {
14052 if (entry->style == COMMUNITY_LIST_STANDARD)
14053 str = community_str(entry->u.com, false);
14054 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
14055 str = lcommunity_str(entry->u.lcom, false);
14056 else
14057 str = entry->config;
14058 }
14059 return str;
14060 }
14061
14062 static void community_list_show(struct vty *vty, struct community_list *list)
14063 {
14064 struct community_entry *entry;
14065
14066 for (entry = list->head; entry; entry = entry->next) {
14067 if (entry == list->head) {
14068 if (all_digit(list->name))
14069 vty_out(vty, "Community %s list %s\n",
14070 entry->style == COMMUNITY_LIST_STANDARD
14071 ? "standard"
14072 : "(expanded) access",
14073 list->name);
14074 else
14075 vty_out(vty, "Named Community %s list %s\n",
14076 entry->style == COMMUNITY_LIST_STANDARD
14077 ? "standard"
14078 : "expanded",
14079 list->name);
14080 }
14081 if (entry->any)
14082 vty_out(vty, " %s\n",
14083 community_direct_str(entry->direct));
14084 else
14085 vty_out(vty, " %s %s\n",
14086 community_direct_str(entry->direct),
14087 community_list_config_str(entry));
14088 }
14089 }
14090
14091 DEFUN (show_community_list,
14092 show_bgp_community_list_cmd,
14093 "show bgp community-list",
14094 SHOW_STR
14095 BGP_STR
14096 "List community-list\n")
14097 {
14098 struct community_list *list;
14099 struct community_list_master *cm;
14100
14101 int idx = 0;
14102 if (argv_find(argv, argc, "ip", &idx)) {
14103 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14104 vty_out(vty, "if you are using this please migrate to the below command.\n");
14105 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14106 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14107 }
14108 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14109 if (!cm)
14110 return CMD_SUCCESS;
14111
14112 for (list = cm->num.head; list; list = list->next)
14113 community_list_show(vty, list);
14114
14115 for (list = cm->str.head; list; list = list->next)
14116 community_list_show(vty, list);
14117
14118 return CMD_SUCCESS;
14119 }
14120
14121 ALIAS (show_community_list,
14122 show_ip_community_list_cmd,
14123 "show ip community-list",
14124 SHOW_STR
14125 IP_STR
14126 "List community-list\n")
14127
14128 DEFUN (show_community_list_arg,
14129 show_bgp_community_list_arg_cmd,
14130 "show bgp community-list <(1-500)|WORD>",
14131 SHOW_STR
14132 BGP_STR
14133 "List community-list\n"
14134 "Community-list number\n"
14135 "Community-list name\n")
14136 {
14137 int idx_comm_list = 3;
14138 struct community_list *list;
14139
14140 int idx = 0;
14141 if (argv_find(argv, argc, "ip", &idx)) {
14142 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14143 vty_out(vty, "if you are using this please migrate to the below command.\n");
14144 vty_out(vty, "'show bgp community-list <(1-500)|WORD>'\n");
14145 zlog_warn("Deprecated option: 'ip show community-list <(1-500)|WORD>' being used");
14146 }
14147 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14148 COMMUNITY_LIST_MASTER);
14149 if (!list) {
14150 vty_out(vty, "%% Can't find community-list\n");
14151 return CMD_WARNING;
14152 }
14153
14154 community_list_show(vty, list);
14155
14156 return CMD_SUCCESS;
14157 }
14158
14159 ALIAS (show_community_list_arg,
14160 show_ip_community_list_arg_cmd,
14161 "show ip community-list <(1-500)|WORD>",
14162 SHOW_STR
14163 IP_STR
14164 "List community-list\n"
14165 "Community-list number\n"
14166 "Community-list name\n")
14167
14168 /*
14169 * Large Community code.
14170 */
14171 static int lcommunity_list_set_vty(struct vty *vty, int argc,
14172 struct cmd_token **argv, int style,
14173 int reject_all_digit_name)
14174 {
14175 int ret;
14176 int direct;
14177 char *str;
14178 int idx = 0;
14179 char *cl_name;
14180
14181 if (argv_find(argv, argc, "ip", &idx)) {
14182 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14183 vty_out(vty, "if you are using this please migrate to the below command.\n");
14184 vty_out(vty, "'bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14185 zlog_warn("Deprecated option: 'large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14186 }
14187 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14188 : COMMUNITY_DENY;
14189
14190 /* All digit name check. */
14191 idx = 0;
14192 argv_find(argv, argc, "WORD", &idx);
14193 argv_find(argv, argc, "(1-99)", &idx);
14194 argv_find(argv, argc, "(100-500)", &idx);
14195 cl_name = argv[idx]->arg;
14196 if (reject_all_digit_name && all_digit(cl_name)) {
14197 vty_out(vty, "%% Community name cannot have all digits\n");
14198 return CMD_WARNING_CONFIG_FAILED;
14199 }
14200
14201 idx = 0;
14202 argv_find(argv, argc, "AA:BB:CC", &idx);
14203 argv_find(argv, argc, "LINE", &idx);
14204 /* Concat community string argument. */
14205 if (idx)
14206 str = argv_concat(argv, argc, idx);
14207 else
14208 str = NULL;
14209
14210 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14211
14212 /* Free temporary community list string allocated by
14213 argv_concat(). */
14214 if (str)
14215 XFREE(MTYPE_TMP, str);
14216
14217 if (ret < 0) {
14218 community_list_perror(vty, ret);
14219 return CMD_WARNING_CONFIG_FAILED;
14220 }
14221 return CMD_SUCCESS;
14222 }
14223
14224 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14225 struct cmd_token **argv, int style)
14226 {
14227 int ret;
14228 int direct = 0;
14229 char *str = NULL;
14230 int idx = 0;
14231
14232 if (argv_find(argv, argc, "ip", &idx)) {
14233 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14234 vty_out(vty, "if you are using this please migrate to the below command.\n");
14235 vty_out(vty, "'no bgp large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>'\n");
14236 zlog_warn("Deprecated option: 'no ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' being used");
14237 }
14238 argv_find(argv, argc, "permit", &idx);
14239 argv_find(argv, argc, "deny", &idx);
14240
14241 if (idx) {
14242 /* Check the list direct. */
14243 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14244 direct = COMMUNITY_PERMIT;
14245 else
14246 direct = COMMUNITY_DENY;
14247
14248 idx = 0;
14249 argv_find(argv, argc, "LINE", &idx);
14250 argv_find(argv, argc, "AA:AA:NN", &idx);
14251 /* Concat community string argument. */
14252 str = argv_concat(argv, argc, idx);
14253 }
14254
14255 idx = 0;
14256 argv_find(argv, argc, "(1-99)", &idx);
14257 argv_find(argv, argc, "(100-500)", &idx);
14258 argv_find(argv, argc, "WORD", &idx);
14259
14260 /* Unset community list. */
14261 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14262 style);
14263
14264 /* Free temporary community list string allocated by
14265 argv_concat(). */
14266 if (str)
14267 XFREE(MTYPE_TMP, str);
14268
14269 if (ret < 0) {
14270 community_list_perror(vty, ret);
14271 return CMD_WARNING_CONFIG_FAILED;
14272 }
14273
14274 return CMD_SUCCESS;
14275 }
14276
14277 /* "large-community-list" keyword help string. */
14278 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14279 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14280
14281 #if CONFDATE > 20191005
14282 CPP_NOTICE("bgpd: remove deprecated 'ip large-community-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:BB:CC>' command")
14283 #endif
14284 DEFUN (lcommunity_list_standard,
14285 bgp_lcommunity_list_standard_cmd,
14286 "bgp large-community-list (1-99) <deny|permit>",
14287 BGP_STR
14288 LCOMMUNITY_LIST_STR
14289 "Large Community list number (standard)\n"
14290 "Specify large community to reject\n"
14291 "Specify large community to accept\n")
14292 {
14293 return lcommunity_list_set_vty(vty, argc, argv,
14294 LARGE_COMMUNITY_LIST_STANDARD, 0);
14295 }
14296
14297 ALIAS (lcommunity_list_standard,
14298 ip_lcommunity_list_standard_cmd,
14299 "ip large-community-list (1-99) <deny|permit>",
14300 IP_STR
14301 LCOMMUNITY_LIST_STR
14302 "Large Community list number (standard)\n"
14303 "Specify large community to reject\n"
14304 "Specify large community to accept\n")
14305
14306 DEFUN (lcommunity_list_standard1,
14307 bgp_lcommunity_list_standard1_cmd,
14308 "bgp large-community-list (1-99) <deny|permit> AA:BB:CC...",
14309 BGP_STR
14310 LCOMMUNITY_LIST_STR
14311 "Large Community list number (standard)\n"
14312 "Specify large community to reject\n"
14313 "Specify large community to accept\n"
14314 LCOMMUNITY_VAL_STR)
14315 {
14316 return lcommunity_list_set_vty(vty, argc, argv,
14317 LARGE_COMMUNITY_LIST_STANDARD, 0);
14318 }
14319
14320 ALIAS (lcommunity_list_standard1,
14321 ip_lcommunity_list_standard1_cmd,
14322 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14323 IP_STR
14324 LCOMMUNITY_LIST_STR
14325 "Large Community list number (standard)\n"
14326 "Specify large community to reject\n"
14327 "Specify large community to accept\n"
14328 LCOMMUNITY_VAL_STR)
14329
14330 DEFUN (lcommunity_list_expanded,
14331 bgp_lcommunity_list_expanded_cmd,
14332 "bgp large-community-list (100-500) <deny|permit> LINE...",
14333 BGP_STR
14334 LCOMMUNITY_LIST_STR
14335 "Large Community list number (expanded)\n"
14336 "Specify large community to reject\n"
14337 "Specify large community to accept\n"
14338 "An ordered list as a regular-expression\n")
14339 {
14340 return lcommunity_list_set_vty(vty, argc, argv,
14341 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14342 }
14343
14344 ALIAS (lcommunity_list_expanded,
14345 ip_lcommunity_list_expanded_cmd,
14346 "ip large-community-list (100-500) <deny|permit> LINE...",
14347 IP_STR
14348 LCOMMUNITY_LIST_STR
14349 "Large Community list number (expanded)\n"
14350 "Specify large community to reject\n"
14351 "Specify large community to accept\n"
14352 "An ordered list as a regular-expression\n")
14353
14354 DEFUN (lcommunity_list_name_standard,
14355 bgp_lcommunity_list_name_standard_cmd,
14356 "bgp large-community-list standard WORD <deny|permit>",
14357 BGP_STR
14358 LCOMMUNITY_LIST_STR
14359 "Specify standard large-community-list\n"
14360 "Large Community list name\n"
14361 "Specify large community to reject\n"
14362 "Specify large community to accept\n")
14363 {
14364 return lcommunity_list_set_vty(vty, argc, argv,
14365 LARGE_COMMUNITY_LIST_STANDARD, 1);
14366 }
14367
14368 ALIAS (lcommunity_list_name_standard,
14369 ip_lcommunity_list_name_standard_cmd,
14370 "ip large-community-list standard WORD <deny|permit>",
14371 IP_STR
14372 LCOMMUNITY_LIST_STR
14373 "Specify standard large-community-list\n"
14374 "Large Community list name\n"
14375 "Specify large community to reject\n"
14376 "Specify large community to accept\n")
14377
14378 DEFUN (lcommunity_list_name_standard1,
14379 bgp_lcommunity_list_name_standard1_cmd,
14380 "bgp large-community-list standard WORD <deny|permit> AA:BB:CC...",
14381 BGP_STR
14382 LCOMMUNITY_LIST_STR
14383 "Specify standard large-community-list\n"
14384 "Large Community list name\n"
14385 "Specify large community to reject\n"
14386 "Specify large community to accept\n"
14387 LCOMMUNITY_VAL_STR)
14388 {
14389 return lcommunity_list_set_vty(vty, argc, argv,
14390 LARGE_COMMUNITY_LIST_STANDARD, 1);
14391 }
14392
14393 ALIAS (lcommunity_list_name_standard1,
14394 ip_lcommunity_list_name_standard1_cmd,
14395 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14396 IP_STR
14397 LCOMMUNITY_LIST_STR
14398 "Specify standard large-community-list\n"
14399 "Large Community list name\n"
14400 "Specify large community to reject\n"
14401 "Specify large community to accept\n"
14402 LCOMMUNITY_VAL_STR)
14403
14404 DEFUN (lcommunity_list_name_expanded,
14405 bgp_lcommunity_list_name_expanded_cmd,
14406 "bgp large-community-list expanded WORD <deny|permit> LINE...",
14407 BGP_STR
14408 LCOMMUNITY_LIST_STR
14409 "Specify expanded large-community-list\n"
14410 "Large Community list name\n"
14411 "Specify large community to reject\n"
14412 "Specify large community to accept\n"
14413 "An ordered list as a regular-expression\n")
14414 {
14415 return lcommunity_list_set_vty(vty, argc, argv,
14416 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14417 }
14418
14419 ALIAS (lcommunity_list_name_expanded,
14420 ip_lcommunity_list_name_expanded_cmd,
14421 "ip large-community-list expanded WORD <deny|permit> LINE...",
14422 IP_STR
14423 LCOMMUNITY_LIST_STR
14424 "Specify expanded large-community-list\n"
14425 "Large Community list name\n"
14426 "Specify large community to reject\n"
14427 "Specify large community to accept\n"
14428 "An ordered list as a regular-expression\n")
14429
14430 DEFUN (no_lcommunity_list_standard_all,
14431 no_bgp_lcommunity_list_standard_all_cmd,
14432 "no bgp large-community-list <(1-99)|(100-500)|WORD>",
14433 NO_STR
14434 BGP_STR
14435 LCOMMUNITY_LIST_STR
14436 "Large Community list number (standard)\n"
14437 "Large Community list number (expanded)\n"
14438 "Large Community list name\n")
14439 {
14440 return lcommunity_list_unset_vty(vty, argc, argv,
14441 LARGE_COMMUNITY_LIST_STANDARD);
14442 }
14443
14444 ALIAS (no_lcommunity_list_standard_all,
14445 no_ip_lcommunity_list_standard_all_cmd,
14446 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14447 NO_STR
14448 IP_STR
14449 LCOMMUNITY_LIST_STR
14450 "Large Community list number (standard)\n"
14451 "Large Community list number (expanded)\n"
14452 "Large Community list name\n")
14453
14454 DEFUN (no_lcommunity_list_name_expanded_all,
14455 no_bgp_lcommunity_list_name_expanded_all_cmd,
14456 "no bgp large-community-list expanded WORD",
14457 NO_STR
14458 BGP_STR
14459 LCOMMUNITY_LIST_STR
14460 "Specify expanded large-community-list\n"
14461 "Large Community list name\n")
14462 {
14463 return lcommunity_list_unset_vty(vty, argc, argv,
14464 LARGE_COMMUNITY_LIST_EXPANDED);
14465 }
14466
14467 ALIAS (no_lcommunity_list_name_expanded_all,
14468 no_ip_lcommunity_list_name_expanded_all_cmd,
14469 "no ip large-community-list expanded WORD",
14470 NO_STR
14471 IP_STR
14472 LCOMMUNITY_LIST_STR
14473 "Specify expanded large-community-list\n"
14474 "Large Community list name\n")
14475
14476 DEFUN (no_lcommunity_list_standard,
14477 no_bgp_lcommunity_list_standard_cmd,
14478 "no bgp large-community-list (1-99) <deny|permit> AA:AA:NN...",
14479 NO_STR
14480 BGP_STR
14481 LCOMMUNITY_LIST_STR
14482 "Large Community list number (standard)\n"
14483 "Specify large community to reject\n"
14484 "Specify large community to accept\n"
14485 LCOMMUNITY_VAL_STR)
14486 {
14487 return lcommunity_list_unset_vty(vty, argc, argv,
14488 LARGE_COMMUNITY_LIST_STANDARD);
14489 }
14490
14491 ALIAS (no_lcommunity_list_standard,
14492 no_ip_lcommunity_list_standard_cmd,
14493 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14494 NO_STR
14495 IP_STR
14496 LCOMMUNITY_LIST_STR
14497 "Large Community list number (standard)\n"
14498 "Specify large community to reject\n"
14499 "Specify large community to accept\n"
14500 LCOMMUNITY_VAL_STR)
14501
14502 DEFUN (no_lcommunity_list_expanded,
14503 no_bgp_lcommunity_list_expanded_cmd,
14504 "no bgp large-community-list (100-500) <deny|permit> LINE...",
14505 NO_STR
14506 BGP_STR
14507 LCOMMUNITY_LIST_STR
14508 "Large Community list number (expanded)\n"
14509 "Specify large community to reject\n"
14510 "Specify large community to accept\n"
14511 "An ordered list as a regular-expression\n")
14512 {
14513 return lcommunity_list_unset_vty(vty, argc, argv,
14514 LARGE_COMMUNITY_LIST_EXPANDED);
14515 }
14516
14517 ALIAS (no_lcommunity_list_expanded,
14518 no_ip_lcommunity_list_expanded_cmd,
14519 "no ip large-community-list (100-500) <deny|permit> LINE...",
14520 NO_STR
14521 IP_STR
14522 LCOMMUNITY_LIST_STR
14523 "Large Community list number (expanded)\n"
14524 "Specify large community to reject\n"
14525 "Specify large community to accept\n"
14526 "An ordered list as a regular-expression\n")
14527
14528 DEFUN (no_lcommunity_list_name_standard,
14529 no_bgp_lcommunity_list_name_standard_cmd,
14530 "no bgp large-community-list standard WORD <deny|permit> AA:AA:NN...",
14531 NO_STR
14532 BGP_STR
14533 LCOMMUNITY_LIST_STR
14534 "Specify standard large-community-list\n"
14535 "Large Community list name\n"
14536 "Specify large community to reject\n"
14537 "Specify large community to accept\n"
14538 LCOMMUNITY_VAL_STR)
14539 {
14540 return lcommunity_list_unset_vty(vty, argc, argv,
14541 LARGE_COMMUNITY_LIST_STANDARD);
14542 }
14543
14544 ALIAS (no_lcommunity_list_name_standard,
14545 no_ip_lcommunity_list_name_standard_cmd,
14546 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14547 NO_STR
14548 IP_STR
14549 LCOMMUNITY_LIST_STR
14550 "Specify standard large-community-list\n"
14551 "Large Community list name\n"
14552 "Specify large community to reject\n"
14553 "Specify large community to accept\n"
14554 LCOMMUNITY_VAL_STR)
14555
14556 DEFUN (no_lcommunity_list_name_expanded,
14557 no_bgp_lcommunity_list_name_expanded_cmd,
14558 "no bgp large-community-list expanded WORD <deny|permit> LINE...",
14559 NO_STR
14560 BGP_STR
14561 LCOMMUNITY_LIST_STR
14562 "Specify expanded large-community-list\n"
14563 "Large community list name\n"
14564 "Specify large community to reject\n"
14565 "Specify large community to accept\n"
14566 "An ordered list as a regular-expression\n")
14567 {
14568 return lcommunity_list_unset_vty(vty, argc, argv,
14569 LARGE_COMMUNITY_LIST_EXPANDED);
14570 }
14571
14572 ALIAS (no_lcommunity_list_name_expanded,
14573 no_ip_lcommunity_list_name_expanded_cmd,
14574 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14575 NO_STR
14576 IP_STR
14577 LCOMMUNITY_LIST_STR
14578 "Specify expanded large-community-list\n"
14579 "Large community list name\n"
14580 "Specify large community to reject\n"
14581 "Specify large community to accept\n"
14582 "An ordered list as a regular-expression\n")
14583
14584 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14585 {
14586 struct community_entry *entry;
14587
14588 for (entry = list->head; entry; entry = entry->next) {
14589 if (entry == list->head) {
14590 if (all_digit(list->name))
14591 vty_out(vty, "Large community %s list %s\n",
14592 entry->style == EXTCOMMUNITY_LIST_STANDARD
14593 ? "standard"
14594 : "(expanded) access",
14595 list->name);
14596 else
14597 vty_out(vty,
14598 "Named large community %s list %s\n",
14599 entry->style == EXTCOMMUNITY_LIST_STANDARD
14600 ? "standard"
14601 : "expanded",
14602 list->name);
14603 }
14604 if (entry->any)
14605 vty_out(vty, " %s\n",
14606 community_direct_str(entry->direct));
14607 else
14608 vty_out(vty, " %s %s\n",
14609 community_direct_str(entry->direct),
14610 community_list_config_str(entry));
14611 }
14612 }
14613
14614 DEFUN (show_lcommunity_list,
14615 show_bgp_lcommunity_list_cmd,
14616 "show bgp large-community-list",
14617 SHOW_STR
14618 BGP_STR
14619 "List large-community list\n")
14620 {
14621 struct community_list *list;
14622 struct community_list_master *cm;
14623 int idx = 0;
14624
14625 if (argv_find(argv, argc, "ip", &idx)) {
14626 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14627 vty_out(vty, "if you are using this please migrate to the below command.\n");
14628 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14629 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14630 }
14631
14632 cm = community_list_master_lookup(bgp_clist,
14633 LARGE_COMMUNITY_LIST_MASTER);
14634 if (!cm)
14635 return CMD_SUCCESS;
14636
14637 for (list = cm->num.head; list; list = list->next)
14638 lcommunity_list_show(vty, list);
14639
14640 for (list = cm->str.head; list; list = list->next)
14641 lcommunity_list_show(vty, list);
14642
14643 return CMD_SUCCESS;
14644 }
14645
14646 ALIAS (show_lcommunity_list,
14647 show_ip_lcommunity_list_cmd,
14648 "show ip large-community-list",
14649 SHOW_STR
14650 IP_STR
14651 "List large-community list\n")
14652
14653 DEFUN (show_lcommunity_list_arg,
14654 show_bgp_lcommunity_list_arg_cmd,
14655 "show bgp large-community-list <(1-500)|WORD>",
14656 SHOW_STR
14657 BGP_STR
14658 "List large-community list\n"
14659 "large-community-list number\n"
14660 "large-community-list name\n")
14661 {
14662 struct community_list *list;
14663 int idx = 0;
14664
14665 if (argv_find(argv, argc, "ip", &idx)) {
14666 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14667 vty_out(vty, "if you are using this please migrate to the below command.\n");
14668 vty_out(vty, "'show bgp large-community-list <(1-500)|WORD>'\n");
14669 zlog_warn("Deprecated option: 'ip show large-community-list <(1-500)|WORD>' being used");
14670 }
14671
14672 list = community_list_lookup(bgp_clist, argv[3]->arg,
14673 LARGE_COMMUNITY_LIST_MASTER);
14674 if (!list) {
14675 vty_out(vty, "%% Can't find extcommunity-list\n");
14676 return CMD_WARNING;
14677 }
14678
14679 lcommunity_list_show(vty, list);
14680
14681 return CMD_SUCCESS;
14682 }
14683
14684 ALIAS (show_lcommunity_list_arg,
14685 show_ip_lcommunity_list_arg_cmd,
14686 "show ip large-community-list <(1-500)|WORD>",
14687 SHOW_STR
14688 IP_STR
14689 "List large-community list\n"
14690 "large-community-list number\n"
14691 "large-community-list name\n")
14692
14693 /* "extcommunity-list" keyword help string. */
14694 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14695 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14696
14697 DEFUN (extcommunity_list_standard,
14698 bgp_extcommunity_list_standard_cmd,
14699 "bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14700 BGP_STR
14701 EXTCOMMUNITY_LIST_STR
14702 "Extended Community list number (standard)\n"
14703 "Specify standard extcommunity-list\n"
14704 "Community list name\n"
14705 "Specify community to reject\n"
14706 "Specify community to accept\n"
14707 EXTCOMMUNITY_VAL_STR)
14708 {
14709 int style = EXTCOMMUNITY_LIST_STANDARD;
14710 int direct = 0;
14711 char *cl_number_or_name = NULL;
14712
14713 int idx = 0;
14714 if (argv_find(argv, argc, "ip", &idx)) {
14715 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14716 vty_out(vty, "if you are using this please migrate to the below command.\n");
14717 vty_out(vty, "'bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14718 zlog_warn("Deprecated option: 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14719 }
14720 argv_find(argv, argc, "(1-99)", &idx);
14721 argv_find(argv, argc, "WORD", &idx);
14722 cl_number_or_name = argv[idx]->arg;
14723 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14724 : COMMUNITY_DENY;
14725 argv_find(argv, argc, "AA:NN", &idx);
14726 char *str = argv_concat(argv, argc, idx);
14727
14728 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14729 direct, style);
14730
14731 XFREE(MTYPE_TMP, str);
14732
14733 if (ret < 0) {
14734 community_list_perror(vty, ret);
14735 return CMD_WARNING_CONFIG_FAILED;
14736 }
14737
14738 return CMD_SUCCESS;
14739 }
14740
14741 #if CONFDATE > 20191005
14742 CPP_NOTICE("bgpd: remove deprecated 'ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' command")
14743 #endif
14744 ALIAS (extcommunity_list_standard,
14745 ip_extcommunity_list_standard_cmd,
14746 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14747 IP_STR
14748 EXTCOMMUNITY_LIST_STR
14749 "Extended Community list number (standard)\n"
14750 "Specify standard extcommunity-list\n"
14751 "Community list name\n"
14752 "Specify community to reject\n"
14753 "Specify community to accept\n"
14754 EXTCOMMUNITY_VAL_STR)
14755
14756 DEFUN (extcommunity_list_name_expanded,
14757 bgp_extcommunity_list_name_expanded_cmd,
14758 "bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14759 BGP_STR
14760 EXTCOMMUNITY_LIST_STR
14761 "Extended Community list number (expanded)\n"
14762 "Specify expanded extcommunity-list\n"
14763 "Extended Community list name\n"
14764 "Specify community to reject\n"
14765 "Specify community to accept\n"
14766 "An ordered list as a regular-expression\n")
14767 {
14768 int style = EXTCOMMUNITY_LIST_EXPANDED;
14769 int direct = 0;
14770 char *cl_number_or_name = NULL;
14771
14772 int idx = 0;
14773 if (argv_find(argv, argc, "ip", &idx)) {
14774 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14775 vty_out(vty, "if you are using this please migrate to the below command.\n");
14776 vty_out(vty, "'extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14777 zlog_warn("Deprecated option: ‘ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14778 }
14779
14780 argv_find(argv, argc, "(100-500)", &idx);
14781 argv_find(argv, argc, "WORD", &idx);
14782 cl_number_or_name = argv[idx]->arg;
14783 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14784 : COMMUNITY_DENY;
14785 argv_find(argv, argc, "LINE", &idx);
14786 char *str = argv_concat(argv, argc, idx);
14787
14788 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14789 direct, style);
14790
14791 XFREE(MTYPE_TMP, str);
14792
14793 if (ret < 0) {
14794 community_list_perror(vty, ret);
14795 return CMD_WARNING_CONFIG_FAILED;
14796 }
14797
14798 return CMD_SUCCESS;
14799 }
14800
14801 ALIAS (extcommunity_list_name_expanded,
14802 ip_extcommunity_list_name_expanded_cmd,
14803 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14804 IP_STR
14805 EXTCOMMUNITY_LIST_STR
14806 "Extended Community list number (expanded)\n"
14807 "Specify expanded extcommunity-list\n"
14808 "Extended Community list name\n"
14809 "Specify community to reject\n"
14810 "Specify community to accept\n"
14811 "An ordered list as a regular-expression\n")
14812
14813 DEFUN (no_extcommunity_list_standard_all,
14814 no_bgp_extcommunity_list_standard_all_cmd,
14815 "no bgp extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14816 NO_STR
14817 BGP_STR
14818 EXTCOMMUNITY_LIST_STR
14819 "Extended Community list number (standard)\n"
14820 "Specify standard extcommunity-list\n"
14821 "Community list name\n"
14822 "Specify community to reject\n"
14823 "Specify community to accept\n"
14824 EXTCOMMUNITY_VAL_STR)
14825 {
14826 int style = EXTCOMMUNITY_LIST_STANDARD;
14827 int direct = 0;
14828 char *cl_number_or_name = NULL;
14829
14830 int idx = 0;
14831 if (argv_find(argv, argc, "ip", &idx)) {
14832 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14833 vty_out(vty, "if you are using this please migrate to the below command.\n");
14834 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14835 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14836 }
14837 argv_find(argv, argc, "(1-99)", &idx);
14838 argv_find(argv, argc, "WORD", &idx);
14839 cl_number_or_name = argv[idx]->arg;
14840 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14841 : COMMUNITY_DENY;
14842 argv_find(argv, argc, "AA:NN", &idx);
14843 char *str = argv_concat(argv, argc, idx);
14844
14845 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14846 direct, style);
14847
14848 XFREE(MTYPE_TMP, str);
14849
14850 if (ret < 0) {
14851 community_list_perror(vty, ret);
14852 return CMD_WARNING_CONFIG_FAILED;
14853 }
14854
14855 return CMD_SUCCESS;
14856 }
14857
14858 ALIAS (no_extcommunity_list_standard_all,
14859 no_ip_extcommunity_list_standard_all_cmd,
14860 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14861 NO_STR
14862 IP_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 DEFUN (no_extcommunity_list_expanded_all,
14872 no_bgp_extcommunity_list_expanded_all_cmd,
14873 "no bgp extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14874 NO_STR
14875 BGP_STR
14876 EXTCOMMUNITY_LIST_STR
14877 "Extended Community list number (expanded)\n"
14878 "Specify expanded extcommunity-list\n"
14879 "Extended Community list name\n"
14880 "Specify community to reject\n"
14881 "Specify community to accept\n"
14882 "An ordered list as a regular-expression\n")
14883 {
14884 int style = EXTCOMMUNITY_LIST_EXPANDED;
14885 int direct = 0;
14886 char *cl_number_or_name = NULL;
14887
14888 int idx = 0;
14889 if (argv_find(argv, argc, "ip", &idx)) {
14890 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
14891 vty_out(vty, "if you are using this please migrate to the below command.\n");
14892 vty_out(vty, "'no bgp extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>'\n");
14893 zlog_warn("Deprecated option: ‘no ip extcommunity-list <(1-99)|(100-500)|standard|expanded> <deny|permit> <LINE|AA:NN>' being used");
14894 }
14895 argv_find(argv, argc, "(100-500)", &idx);
14896 argv_find(argv, argc, "WORD", &idx);
14897 cl_number_or_name = argv[idx]->arg;
14898 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14899 : COMMUNITY_DENY;
14900 argv_find(argv, argc, "LINE", &idx);
14901 char *str = argv_concat(argv, argc, idx);
14902
14903 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14904 direct, style);
14905
14906 XFREE(MTYPE_TMP, str);
14907
14908 if (ret < 0) {
14909 community_list_perror(vty, ret);
14910 return CMD_WARNING_CONFIG_FAILED;
14911 }
14912
14913 return CMD_SUCCESS;
14914 }
14915
14916 ALIAS (no_extcommunity_list_expanded_all,
14917 no_ip_extcommunity_list_expanded_all_cmd,
14918 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14919 NO_STR
14920 IP_STR
14921 EXTCOMMUNITY_LIST_STR
14922 "Extended Community list number (expanded)\n"
14923 "Specify expanded extcommunity-list\n"
14924 "Extended Community list name\n"
14925 "Specify community to reject\n"
14926 "Specify community to accept\n"
14927 "An ordered list as a regular-expression\n")
14928
14929 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14930 {
14931 struct community_entry *entry;
14932
14933 for (entry = list->head; entry; entry = entry->next) {
14934 if (entry == list->head) {
14935 if (all_digit(list->name))
14936 vty_out(vty, "Extended community %s list %s\n",
14937 entry->style == EXTCOMMUNITY_LIST_STANDARD
14938 ? "standard"
14939 : "(expanded) access",
14940 list->name);
14941 else
14942 vty_out(vty,
14943 "Named extended community %s list %s\n",
14944 entry->style == EXTCOMMUNITY_LIST_STANDARD
14945 ? "standard"
14946 : "expanded",
14947 list->name);
14948 }
14949 if (entry->any)
14950 vty_out(vty, " %s\n",
14951 community_direct_str(entry->direct));
14952 else
14953 vty_out(vty, " %s %s\n",
14954 community_direct_str(entry->direct),
14955 community_list_config_str(entry));
14956 }
14957 }
14958
14959 DEFUN (show_extcommunity_list,
14960 show_bgp_extcommunity_list_cmd,
14961 "show bgp extcommunity-list",
14962 SHOW_STR
14963 BGP_STR
14964 "List extended-community list\n")
14965 {
14966 struct community_list *list;
14967 struct community_list_master *cm;
14968 int idx = 0;
14969
14970 if (argv_find(argv, argc, "ip", &idx)) {
14971 vty_out(vty, "This config option is deprecated, and is scheduled for removal\n");
14972 vty_out(vty, "if you are using this please migrate to the below command.\n");
14973 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
14974 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
14975 }
14976 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14977 if (!cm)
14978 return CMD_SUCCESS;
14979
14980 for (list = cm->num.head; list; list = list->next)
14981 extcommunity_list_show(vty, list);
14982
14983 for (list = cm->str.head; list; list = list->next)
14984 extcommunity_list_show(vty, list);
14985
14986 return CMD_SUCCESS;
14987 }
14988
14989 ALIAS (show_extcommunity_list,
14990 show_ip_extcommunity_list_cmd,
14991 "show ip extcommunity-list",
14992 SHOW_STR
14993 IP_STR
14994 "List extended-community list\n")
14995
14996 DEFUN (show_extcommunity_list_arg,
14997 show_bgp_extcommunity_list_arg_cmd,
14998 "show bgp extcommunity-list <(1-500)|WORD>",
14999 SHOW_STR
15000 BGP_STR
15001 "List extended-community list\n"
15002 "Extcommunity-list number\n"
15003 "Extcommunity-list name\n")
15004 {
15005 int idx_comm_list = 3;
15006 struct community_list *list;
15007 int idx = 0;
15008
15009 if (argv_find(argv, argc, "ip", &idx)) {
15010 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
15011 vty_out(vty, "if you are using this please migrate to the below command.\n");
15012 vty_out(vty, "'show bgp extcommunity-list <(1-500)|WORD>'\n");
15013 zlog_warn("Deprecated option: 'ip show extcommunity-list <(1-500)|WORD>' being used");
15014 }
15015 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
15016 EXTCOMMUNITY_LIST_MASTER);
15017 if (!list) {
15018 vty_out(vty, "%% Can't find extcommunity-list\n");
15019 return CMD_WARNING;
15020 }
15021
15022 extcommunity_list_show(vty, list);
15023
15024 return CMD_SUCCESS;
15025 }
15026
15027 ALIAS (show_extcommunity_list_arg,
15028 show_ip_extcommunity_list_arg_cmd,
15029 "show ip extcommunity-list <(1-500)|WORD>",
15030 SHOW_STR
15031 IP_STR
15032 "List extended-community list\n"
15033 "Extcommunity-list number\n"
15034 "Extcommunity-list name\n")
15035
15036 /* Display community-list and extcommunity-list configuration. */
15037 static int community_list_config_write(struct vty *vty)
15038 {
15039 struct community_list *list;
15040 struct community_entry *entry;
15041 struct community_list_master *cm;
15042 int write = 0;
15043
15044 /* Community-list. */
15045 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
15046
15047 for (list = cm->num.head; list; list = list->next)
15048 for (entry = list->head; entry; entry = entry->next) {
15049 vty_out(vty, "bgp community-list %s %s %s\n", list->name,
15050 community_direct_str(entry->direct),
15051 community_list_config_str(entry));
15052 write++;
15053 }
15054 for (list = cm->str.head; list; list = list->next)
15055 for (entry = list->head; entry; entry = entry->next) {
15056 vty_out(vty, "bgp community-list %s %s %s %s\n",
15057 entry->style == COMMUNITY_LIST_STANDARD
15058 ? "standard"
15059 : "expanded",
15060 list->name, community_direct_str(entry->direct),
15061 community_list_config_str(entry));
15062 write++;
15063 }
15064
15065 /* Extcommunity-list. */
15066 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
15067
15068 for (list = cm->num.head; list; list = list->next)
15069 for (entry = list->head; entry; entry = entry->next) {
15070 vty_out(vty, "bgp extcommunity-list %s %s %s\n",
15071 list->name, community_direct_str(entry->direct),
15072 community_list_config_str(entry));
15073 write++;
15074 }
15075 for (list = cm->str.head; list; list = list->next)
15076 for (entry = list->head; entry; entry = entry->next) {
15077 vty_out(vty, "bgp extcommunity-list %s %s %s %s\n",
15078 entry->style == EXTCOMMUNITY_LIST_STANDARD
15079 ? "standard"
15080 : "expanded",
15081 list->name, community_direct_str(entry->direct),
15082 community_list_config_str(entry));
15083 write++;
15084 }
15085
15086
15087 /* lcommunity-list. */
15088 cm = community_list_master_lookup(bgp_clist,
15089 LARGE_COMMUNITY_LIST_MASTER);
15090
15091 for (list = cm->num.head; list; list = list->next)
15092 for (entry = list->head; entry; entry = entry->next) {
15093 vty_out(vty, "bgp large-community-list %s %s %s\n",
15094 list->name, community_direct_str(entry->direct),
15095 community_list_config_str(entry));
15096 write++;
15097 }
15098 for (list = cm->str.head; list; list = list->next)
15099 for (entry = list->head; entry; entry = entry->next) {
15100 vty_out(vty, "bgp large-community-list %s %s %s %s\n",
15101 entry->style == LARGE_COMMUNITY_LIST_STANDARD
15102 ? "standard"
15103 : "expanded",
15104 list->name, community_direct_str(entry->direct),
15105 community_list_config_str(entry));
15106 write++;
15107 }
15108
15109 return write;
15110 }
15111
15112 static struct cmd_node community_list_node = {
15113 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
15114 };
15115
15116 static void community_list_vty(void)
15117 {
15118 install_node(&community_list_node, community_list_config_write);
15119
15120 /* Community-list. */
15121 install_element(CONFIG_NODE, &bgp_community_list_standard_cmd);
15122 install_element(CONFIG_NODE, &bgp_community_list_expanded_all_cmd);
15123 install_element(CONFIG_NODE, &no_bgp_community_list_standard_all_cmd);
15124 install_element(CONFIG_NODE, &no_bgp_community_list_expanded_all_cmd);
15125 install_element(VIEW_NODE, &show_bgp_community_list_cmd);
15126 install_element(VIEW_NODE, &show_bgp_community_list_arg_cmd);
15127 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
15128 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
15129 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
15130 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
15131 install_element(VIEW_NODE, &show_ip_community_list_cmd);
15132 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
15133
15134 /* Extcommunity-list. */
15135 install_element(CONFIG_NODE, &bgp_extcommunity_list_standard_cmd);
15136 install_element(CONFIG_NODE, &bgp_extcommunity_list_name_expanded_cmd);
15137 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_standard_all_cmd);
15138 install_element(CONFIG_NODE, &no_bgp_extcommunity_list_expanded_all_cmd);
15139 install_element(VIEW_NODE, &show_bgp_extcommunity_list_cmd);
15140 install_element(VIEW_NODE, &show_bgp_extcommunity_list_arg_cmd);
15141 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
15142 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
15143 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
15144 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
15145 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
15146 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
15147
15148 /* Large Community List */
15149 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard_cmd);
15150 install_element(CONFIG_NODE, &bgp_lcommunity_list_standard1_cmd);
15151 install_element(CONFIG_NODE, &bgp_lcommunity_list_expanded_cmd);
15152 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard_cmd);
15153 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_standard1_cmd);
15154 install_element(CONFIG_NODE, &bgp_lcommunity_list_name_expanded_cmd);
15155 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_all_cmd);
15156 install_element(CONFIG_NODE,
15157 &no_bgp_lcommunity_list_name_expanded_all_cmd);
15158 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_standard_cmd);
15159 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_expanded_cmd);
15160 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_standard_cmd);
15161 install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd);
15162 install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd);
15163 install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd);
15164 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
15165 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
15166 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
15167 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
15168 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
15169 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
15170 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
15171 install_element(CONFIG_NODE,
15172 &no_ip_lcommunity_list_name_expanded_all_cmd);
15173 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
15174 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
15175 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
15176 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
15177 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
15178 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
15179 }