]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Fix format specifier for 4-byte asn print
[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)
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 || argv_find(argv, argc, "vrf", idx)) {
317 vrf_name = argv[*idx + 1]->arg;
318
319 if (strmatch(vrf_name, "all"))
320 *bgp = NULL;
321 else {
322 *bgp = bgp_lookup_by_name(vrf_name);
323 if (!*bgp) {
324 vty_out(vty,
325 "View/Vrf specified is unknown: %s\n",
326 vrf_name);
327 *idx = 0;
328 return 0;
329 }
330 }
331 } else {
332 *bgp = bgp_get_default();
333 if (!*bgp) {
334 vty_out(vty, "Unable to find default BGP instance\n");
335 *idx = 0;
336 return 0;
337 }
338 }
339
340 if (argv_find_and_parse_afi(argv, argc, idx, afi))
341 argv_find_and_parse_safi(argv, argc, idx, safi);
342
343 *idx += 1;
344 return *idx;
345 }
346
347 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
348 {
349 struct interface *ifp = NULL;
350
351 if (su->sa.sa_family == AF_INET)
352 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
353 else if (su->sa.sa_family == AF_INET6)
354 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
355 su->sin6.sin6_scope_id,
356 bgp->vrf_id);
357
358 if (ifp)
359 return 1;
360
361 return 0;
362 }
363
364 /* Utility function for looking up peer from VTY. */
365 /* This is used only for configuration, so disallow if attempted on
366 * a dynamic neighbor.
367 */
368 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
369 {
370 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
371 int ret;
372 union sockunion su;
373 struct peer *peer;
374
375 if (!bgp) {
376 return NULL;
377 }
378
379 ret = str2sockunion(ip_str, &su);
380 if (ret < 0) {
381 peer = peer_lookup_by_conf_if(bgp, ip_str);
382 if (!peer) {
383 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
384 == NULL) {
385 vty_out(vty,
386 "%% Malformed address or name: %s\n",
387 ip_str);
388 return NULL;
389 }
390 }
391 } else {
392 peer = peer_lookup(bgp, &su);
393 if (!peer) {
394 vty_out(vty,
395 "%% Specify remote-as or peer-group commands first\n");
396 return NULL;
397 }
398 if (peer_dynamic_neighbor(peer)) {
399 vty_out(vty,
400 "%% Operation not allowed on a dynamic neighbor\n");
401 return NULL;
402 }
403 }
404 return peer;
405 }
406
407 /* Utility function for looking up peer or peer group. */
408 /* This is used only for configuration, so disallow if attempted on
409 * a dynamic neighbor.
410 */
411 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
412 {
413 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
414 int ret;
415 union sockunion su;
416 struct peer *peer = NULL;
417 struct peer_group *group = NULL;
418
419 if (!bgp) {
420 return NULL;
421 }
422
423 ret = str2sockunion(peer_str, &su);
424 if (ret == 0) {
425 /* IP address, locate peer. */
426 peer = peer_lookup(bgp, &su);
427 } else {
428 /* Not IP, could match either peer configured on interface or a
429 * group. */
430 peer = peer_lookup_by_conf_if(bgp, peer_str);
431 if (!peer)
432 group = peer_group_lookup(bgp, peer_str);
433 }
434
435 if (peer) {
436 if (peer_dynamic_neighbor(peer)) {
437 vty_out(vty,
438 "%% Operation not allowed on a dynamic neighbor\n");
439 return NULL;
440 }
441
442 return peer;
443 }
444
445 if (group)
446 return group->conf;
447
448 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
449
450 return NULL;
451 }
452
453 int bgp_vty_return(struct vty *vty, int ret)
454 {
455 const char *str = NULL;
456
457 switch (ret) {
458 case BGP_ERR_INVALID_VALUE:
459 str = "Invalid value";
460 break;
461 case BGP_ERR_INVALID_FLAG:
462 str = "Invalid flag";
463 break;
464 case BGP_ERR_PEER_GROUP_SHUTDOWN:
465 str = "Peer-group has been shutdown. Activate the peer-group first";
466 break;
467 case BGP_ERR_PEER_FLAG_CONFLICT:
468 str = "Can't set override-capability and strict-capability-match at the same time";
469 break;
470 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
471 str = "Specify remote-as or peer-group remote AS first";
472 break;
473 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
474 str = "Cannot change the peer-group. Deconfigure first";
475 break;
476 case BGP_ERR_PEER_GROUP_MISMATCH:
477 str = "Peer is not a member of this peer-group";
478 break;
479 case BGP_ERR_PEER_FILTER_CONFLICT:
480 str = "Prefix/distribute list can not co-exist";
481 break;
482 case BGP_ERR_NOT_INTERNAL_PEER:
483 str = "Invalid command. Not an internal neighbor";
484 break;
485 case BGP_ERR_REMOVE_PRIVATE_AS:
486 str = "remove-private-AS cannot be configured for IBGP peers";
487 break;
488 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
489 str = "Local-AS allowed only for EBGP peers";
490 break;
491 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
492 str = "Cannot have local-as same as BGP AS number";
493 break;
494 case BGP_ERR_TCPSIG_FAILED:
495 str = "Error while applying TCP-Sig to session(s)";
496 break;
497 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
498 str = "ebgp-multihop and ttl-security cannot be configured together";
499 break;
500 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
501 str = "ttl-security only allowed for EBGP peers";
502 break;
503 case BGP_ERR_AS_OVERRIDE:
504 str = "as-override cannot be configured for IBGP peers";
505 break;
506 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
507 str = "Invalid limit for number of dynamic neighbors";
508 break;
509 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
510 str = "Dynamic neighbor listen range already exists";
511 break;
512 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
513 str = "Operation not allowed on a dynamic neighbor";
514 break;
515 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
516 str = "Operation not allowed on a directly connected neighbor";
517 break;
518 case BGP_ERR_PEER_SAFI_CONFLICT:
519 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
520 break;
521 }
522 if (str) {
523 vty_out(vty, "%% %s\n", str);
524 return CMD_WARNING_CONFIG_FAILED;
525 }
526 return CMD_SUCCESS;
527 }
528
529 /* BGP clear sort. */
530 enum clear_sort {
531 clear_all,
532 clear_peer,
533 clear_group,
534 clear_external,
535 clear_as
536 };
537
538 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
539 safi_t safi, int error)
540 {
541 switch (error) {
542 case BGP_ERR_AF_UNCONFIGURED:
543 vty_out(vty,
544 "%%BGP: Enable %s address family for the neighbor %s\n",
545 afi_safi_print(afi, safi), peer->host);
546 break;
547 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
548 vty_out(vty,
549 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
550 peer->host);
551 break;
552 default:
553 break;
554 }
555 }
556
557 /* `clear ip bgp' functions. */
558 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
559 enum clear_sort sort, enum bgp_clear_type stype,
560 const char *arg)
561 {
562 int ret;
563 bool found = false;
564 struct peer *peer;
565 struct listnode *node, *nnode;
566
567 /* Clear all neighbors. */
568 /*
569 * Pass along pointer to next node to peer_clear() when walking all
570 * nodes on the BGP instance as that may get freed if it is a
571 * doppelganger
572 */
573 if (sort == clear_all) {
574 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
575 if (!peer->afc[afi][safi])
576 continue;
577
578 if (stype == BGP_CLEAR_SOFT_NONE)
579 ret = peer_clear(peer, &nnode);
580 else
581 ret = peer_clear_soft(peer, afi, safi, stype);
582
583 if (ret < 0)
584 bgp_clear_vty_error(vty, peer, afi, safi, ret);
585 else
586 found = true;
587 }
588
589 /* This is to apply read-only mode on this clear. */
590 if (stype == BGP_CLEAR_SOFT_NONE)
591 bgp->update_delay_over = 0;
592
593 if (!found)
594 vty_out(vty, "%%BGP: No %s peer configured",
595 afi_safi_print(afi, safi));
596
597 return CMD_SUCCESS;
598 }
599
600 /* Clear specified neighbor. */
601 if (sort == clear_peer) {
602 union sockunion su;
603
604 /* Make sockunion for lookup. */
605 ret = str2sockunion(arg, &su);
606 if (ret < 0) {
607 peer = peer_lookup_by_conf_if(bgp, arg);
608 if (!peer) {
609 peer = peer_lookup_by_hostname(bgp, arg);
610 if (!peer) {
611 vty_out(vty,
612 "Malformed address or name: %s\n",
613 arg);
614 return CMD_WARNING;
615 }
616 }
617 } else {
618 peer = peer_lookup(bgp, &su);
619 if (!peer) {
620 vty_out(vty,
621 "%%BGP: Unknown neighbor - \"%s\"\n",
622 arg);
623 return CMD_WARNING;
624 }
625 }
626
627 if (!peer->afc[afi][safi])
628 ret = BGP_ERR_AF_UNCONFIGURED;
629 else if (stype == BGP_CLEAR_SOFT_NONE)
630 ret = peer_clear(peer, NULL);
631 else
632 ret = peer_clear_soft(peer, afi, safi, stype);
633
634 if (ret < 0)
635 bgp_clear_vty_error(vty, peer, afi, safi, ret);
636
637 return CMD_SUCCESS;
638 }
639
640 /* Clear all neighbors belonging to a specific peer-group. */
641 if (sort == clear_group) {
642 struct peer_group *group;
643
644 group = peer_group_lookup(bgp, arg);
645 if (!group) {
646 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
647 return CMD_WARNING;
648 }
649
650 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
651 if (!peer->afc[afi][safi])
652 continue;
653
654 if (stype == BGP_CLEAR_SOFT_NONE)
655 ret = peer_clear(peer, NULL);
656 else
657 ret = peer_clear_soft(peer, afi, safi, stype);
658
659 if (ret < 0)
660 bgp_clear_vty_error(vty, peer, afi, safi, ret);
661 else
662 found = true;
663 }
664
665 if (!found)
666 vty_out(vty,
667 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
668 afi_safi_print(afi, safi), arg);
669
670 return CMD_SUCCESS;
671 }
672
673 /* Clear all external (eBGP) neighbors. */
674 if (sort == clear_external) {
675 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
676 if (peer->sort == BGP_PEER_IBGP)
677 continue;
678
679 if (!peer->afc[afi][safi])
680 continue;
681
682 if (stype == BGP_CLEAR_SOFT_NONE)
683 ret = peer_clear(peer, &nnode);
684 else
685 ret = peer_clear_soft(peer, afi, safi, stype);
686
687 if (ret < 0)
688 bgp_clear_vty_error(vty, peer, afi, safi, ret);
689 else
690 found = true;
691 }
692
693 if (!found)
694 vty_out(vty,
695 "%%BGP: No external %s peer is configured\n",
696 afi_safi_print(afi, safi));
697
698 return CMD_SUCCESS;
699 }
700
701 /* Clear all neighbors belonging to a specific AS. */
702 if (sort == clear_as) {
703 as_t as = strtoul(arg, NULL, 10);
704
705 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
706 if (peer->as != as)
707 continue;
708
709 if (!peer->afc[afi][safi])
710 ret = BGP_ERR_AF_UNCONFIGURED;
711 else if (stype == BGP_CLEAR_SOFT_NONE)
712 ret = peer_clear(peer, &nnode);
713 else
714 ret = peer_clear_soft(peer, afi, safi, stype);
715
716 if (ret < 0)
717 bgp_clear_vty_error(vty, peer, afi, safi, ret);
718 else
719 found = true;
720 }
721
722 if (!found)
723 vty_out(vty,
724 "%%BGP: No %s peer is configured with AS %s\n",
725 afi_safi_print(afi, safi), arg);
726
727 return CMD_SUCCESS;
728 }
729
730 return CMD_SUCCESS;
731 }
732
733 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
734 safi_t safi, enum clear_sort sort,
735 enum bgp_clear_type stype, const char *arg)
736 {
737 struct bgp *bgp;
738
739 /* BGP structure lookup. */
740 if (name) {
741 bgp = bgp_lookup_by_name(name);
742 if (bgp == NULL) {
743 vty_out(vty, "Can't find BGP instance %s\n", name);
744 return CMD_WARNING;
745 }
746 } else {
747 bgp = bgp_get_default();
748 if (bgp == NULL) {
749 vty_out(vty, "No BGP process is configured\n");
750 return CMD_WARNING;
751 }
752 }
753
754 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
755 }
756
757 /* clear soft inbound */
758 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
759 {
760 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
761 BGP_CLEAR_SOFT_IN, NULL);
762 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
763 BGP_CLEAR_SOFT_IN, NULL);
764 }
765
766 /* clear soft outbound */
767 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
768 {
769 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
770 BGP_CLEAR_SOFT_OUT, NULL);
771 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
772 BGP_CLEAR_SOFT_OUT, NULL);
773 }
774
775
776 #ifndef VTYSH_EXTRACT_PL
777 #include "bgpd/bgp_vty_clippy.c"
778 #endif
779
780 /* BGP global configuration. */
781 #if (CONFDATE > 20190601)
782 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
783 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
784 #endif
785 DEFUN_HIDDEN (bgp_multiple_instance_func,
786 bgp_multiple_instance_cmd,
787 "bgp multiple-instance",
788 BGP_STR
789 "Enable bgp multiple instance\n")
790 {
791 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
792 return CMD_SUCCESS;
793 }
794
795 DEFUN_HIDDEN (no_bgp_multiple_instance,
796 no_bgp_multiple_instance_cmd,
797 "no bgp multiple-instance",
798 NO_STR
799 BGP_STR
800 "BGP multiple instance\n")
801 {
802 int ret;
803
804 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
805 vty_out(vty, "if you are using this please let the developers know\n");
806 zlog_info("Deprecated option: `bgp multiple-instance` being used");
807 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
808 if (ret < 0) {
809 vty_out(vty, "%% There are more than two BGP instances\n");
810 return CMD_WARNING_CONFIG_FAILED;
811 }
812 return CMD_SUCCESS;
813 }
814
815 #if (CONFDATE > 20190601)
816 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
817 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
818 #endif
819 DEFUN_HIDDEN (bgp_config_type,
820 bgp_config_type_cmd,
821 "bgp config-type <cisco|zebra>",
822 BGP_STR
823 "Configuration type\n"
824 "cisco\n"
825 "zebra\n")
826 {
827 int idx = 0;
828 if (argv_find(argv, argc, "cisco", &idx)) {
829 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
830 vty_out(vty, "if you are using this please let the developers know!\n");
831 zlog_info("Deprecated option: `bgp config-type cisco` being used");
832 bgp_option_set(BGP_OPT_CONFIG_CISCO);
833 } else
834 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
835
836 return CMD_SUCCESS;
837 }
838
839 DEFUN_HIDDEN (no_bgp_config_type,
840 no_bgp_config_type_cmd,
841 "no bgp config-type [<cisco|zebra>]",
842 NO_STR
843 BGP_STR
844 "Display configuration type\n"
845 "cisco\n"
846 "zebra\n")
847 {
848 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
849 return CMD_SUCCESS;
850 }
851
852
853 DEFUN (no_synchronization,
854 no_synchronization_cmd,
855 "no synchronization",
856 NO_STR
857 "Perform IGP synchronization\n")
858 {
859 return CMD_SUCCESS;
860 }
861
862 DEFUN (no_auto_summary,
863 no_auto_summary_cmd,
864 "no auto-summary",
865 NO_STR
866 "Enable automatic network number summarization\n")
867 {
868 return CMD_SUCCESS;
869 }
870
871 /* "router bgp" commands. */
872 DEFUN_NOSH (router_bgp,
873 router_bgp_cmd,
874 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
875 ROUTER_STR
876 BGP_STR
877 AS_STR
878 BGP_INSTANCE_HELP_STR)
879 {
880 int idx_asn = 2;
881 int idx_view_vrf = 3;
882 int idx_vrf = 4;
883 int ret;
884 as_t as;
885 struct bgp *bgp;
886 const char *name = NULL;
887 enum bgp_instance_type inst_type;
888
889 // "router bgp" without an ASN
890 if (argc == 2) {
891 // Pending: Make VRF option available for ASN less config
892 bgp = bgp_get_default();
893
894 if (bgp == NULL) {
895 vty_out(vty, "%% No BGP process is configured\n");
896 return CMD_WARNING_CONFIG_FAILED;
897 }
898
899 if (listcount(bm->bgp) > 1) {
900 vty_out(vty, "%% Please specify ASN and VRF\n");
901 return CMD_WARNING_CONFIG_FAILED;
902 }
903 }
904
905 // "router bgp X"
906 else {
907 as = strtoul(argv[idx_asn]->arg, NULL, 10);
908
909 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
910 if (argc > 3) {
911 name = argv[idx_vrf]->arg;
912
913 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
914 inst_type = BGP_INSTANCE_TYPE_VRF;
915 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
916 inst_type = BGP_INSTANCE_TYPE_VIEW;
917 }
918
919 ret = bgp_get(&bgp, &as, name, inst_type);
920 switch (ret) {
921 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
922 vty_out(vty,
923 "Please specify 'bgp multiple-instance' first\n");
924 return CMD_WARNING_CONFIG_FAILED;
925 case BGP_ERR_AS_MISMATCH:
926 vty_out(vty, "BGP is already running; AS is %u\n", as);
927 return CMD_WARNING_CONFIG_FAILED;
928 case BGP_ERR_INSTANCE_MISMATCH:
929 vty_out(vty,
930 "BGP instance name and AS number mismatch\n");
931 vty_out(vty,
932 "BGP instance is already running; AS is %u\n",
933 as);
934 return CMD_WARNING_CONFIG_FAILED;
935 }
936
937 /*
938 * If we just instantiated the default instance, complete
939 * any pending VRF-VPN leaking that was configured via
940 * earlier "router bgp X vrf FOO" blocks.
941 */
942 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
943 vpn_leak_postchange_all();
944
945 /* Pending: handle when user tries to change a view to vrf n vv.
946 */
947 }
948
949 /* unset the auto created flag as the user config is now present */
950 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
951 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
952
953 return CMD_SUCCESS;
954 }
955
956 /* "no router bgp" commands. */
957 DEFUN (no_router_bgp,
958 no_router_bgp_cmd,
959 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
960 NO_STR
961 ROUTER_STR
962 BGP_STR
963 AS_STR
964 BGP_INSTANCE_HELP_STR)
965 {
966 int idx_asn = 3;
967 int idx_vrf = 5;
968 as_t as;
969 struct bgp *bgp;
970 const char *name = NULL;
971
972 // "no router bgp" without an ASN
973 if (argc == 3) {
974 // Pending: Make VRF option available for ASN less config
975 bgp = bgp_get_default();
976
977 if (bgp == NULL) {
978 vty_out(vty, "%% No BGP process is configured\n");
979 return CMD_WARNING_CONFIG_FAILED;
980 }
981
982 if (listcount(bm->bgp) > 1) {
983 vty_out(vty, "%% Please specify ASN and VRF\n");
984 return CMD_WARNING_CONFIG_FAILED;
985 }
986
987 if (bgp->l3vni) {
988 vty_out(vty, "%% Please unconfigure l3vni %u",
989 bgp->l3vni);
990 return CMD_WARNING_CONFIG_FAILED;
991 }
992 } else {
993 as = strtoul(argv[idx_asn]->arg, NULL, 10);
994
995 if (argc > 4)
996 name = argv[idx_vrf]->arg;
997
998 /* Lookup bgp structure. */
999 bgp = bgp_lookup(as, name);
1000 if (!bgp) {
1001 vty_out(vty, "%% Can't find BGP instance\n");
1002 return CMD_WARNING_CONFIG_FAILED;
1003 }
1004
1005 if (bgp->l3vni) {
1006 vty_out(vty, "%% Please unconfigure l3vni %u",
1007 bgp->l3vni);
1008 return CMD_WARNING_CONFIG_FAILED;
1009 }
1010 }
1011
1012 bgp_delete(bgp);
1013
1014 return CMD_SUCCESS;
1015 }
1016
1017
1018 /* BGP router-id. */
1019
1020 DEFPY (bgp_router_id,
1021 bgp_router_id_cmd,
1022 "bgp router-id A.B.C.D",
1023 BGP_STR
1024 "Override configured router identifier\n"
1025 "Manually configured router identifier\n")
1026 {
1027 VTY_DECLVAR_CONTEXT(bgp, bgp);
1028 bgp_router_id_static_set(bgp, router_id);
1029 return CMD_SUCCESS;
1030 }
1031
1032 DEFPY (no_bgp_router_id,
1033 no_bgp_router_id_cmd,
1034 "no bgp router-id [A.B.C.D]",
1035 NO_STR
1036 BGP_STR
1037 "Override configured router identifier\n"
1038 "Manually configured router identifier\n")
1039 {
1040 VTY_DECLVAR_CONTEXT(bgp, bgp);
1041
1042 if (router_id_str) {
1043 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1044 vty_out(vty, "%% BGP router-id doesn't match\n");
1045 return CMD_WARNING_CONFIG_FAILED;
1046 }
1047 }
1048
1049 router_id.s_addr = 0;
1050 bgp_router_id_static_set(bgp, router_id);
1051
1052 return CMD_SUCCESS;
1053 }
1054
1055
1056 /* BGP Cluster ID. */
1057 DEFUN (bgp_cluster_id,
1058 bgp_cluster_id_cmd,
1059 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1060 BGP_STR
1061 "Configure Route-Reflector Cluster-id\n"
1062 "Route-Reflector Cluster-id in IP address format\n"
1063 "Route-Reflector Cluster-id as 32 bit quantity\n")
1064 {
1065 VTY_DECLVAR_CONTEXT(bgp, bgp);
1066 int idx_ipv4 = 2;
1067 int ret;
1068 struct in_addr cluster;
1069
1070 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1071 if (!ret) {
1072 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1073 return CMD_WARNING_CONFIG_FAILED;
1074 }
1075
1076 bgp_cluster_id_set(bgp, &cluster);
1077 bgp_clear_star_soft_out(vty, bgp->name);
1078
1079 return CMD_SUCCESS;
1080 }
1081
1082 DEFUN (no_bgp_cluster_id,
1083 no_bgp_cluster_id_cmd,
1084 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1085 NO_STR
1086 BGP_STR
1087 "Configure Route-Reflector Cluster-id\n"
1088 "Route-Reflector Cluster-id in IP address format\n"
1089 "Route-Reflector Cluster-id as 32 bit quantity\n")
1090 {
1091 VTY_DECLVAR_CONTEXT(bgp, bgp);
1092 bgp_cluster_id_unset(bgp);
1093 bgp_clear_star_soft_out(vty, bgp->name);
1094
1095 return CMD_SUCCESS;
1096 }
1097
1098 DEFUN (bgp_confederation_identifier,
1099 bgp_confederation_identifier_cmd,
1100 "bgp confederation identifier (1-4294967295)",
1101 "BGP specific commands\n"
1102 "AS confederation parameters\n"
1103 "AS number\n"
1104 "Set routing domain confederation AS\n")
1105 {
1106 VTY_DECLVAR_CONTEXT(bgp, bgp);
1107 int idx_number = 3;
1108 as_t as;
1109
1110 as = strtoul(argv[idx_number]->arg, NULL, 10);
1111
1112 bgp_confederation_id_set(bgp, as);
1113
1114 return CMD_SUCCESS;
1115 }
1116
1117 DEFUN (no_bgp_confederation_identifier,
1118 no_bgp_confederation_identifier_cmd,
1119 "no bgp confederation identifier [(1-4294967295)]",
1120 NO_STR
1121 "BGP specific commands\n"
1122 "AS confederation parameters\n"
1123 "AS number\n"
1124 "Set routing domain confederation AS\n")
1125 {
1126 VTY_DECLVAR_CONTEXT(bgp, bgp);
1127 bgp_confederation_id_unset(bgp);
1128
1129 return CMD_SUCCESS;
1130 }
1131
1132 DEFUN (bgp_confederation_peers,
1133 bgp_confederation_peers_cmd,
1134 "bgp confederation peers (1-4294967295)...",
1135 "BGP specific commands\n"
1136 "AS confederation parameters\n"
1137 "Peer ASs in BGP confederation\n"
1138 AS_STR)
1139 {
1140 VTY_DECLVAR_CONTEXT(bgp, bgp);
1141 int idx_asn = 3;
1142 as_t as;
1143 int i;
1144
1145 for (i = idx_asn; i < argc; i++) {
1146 as = strtoul(argv[i]->arg, NULL, 10);
1147
1148 if (bgp->as == as) {
1149 vty_out(vty,
1150 "%% Local member-AS not allowed in confed peer list\n");
1151 continue;
1152 }
1153
1154 bgp_confederation_peers_add(bgp, as);
1155 }
1156 return CMD_SUCCESS;
1157 }
1158
1159 DEFUN (no_bgp_confederation_peers,
1160 no_bgp_confederation_peers_cmd,
1161 "no bgp confederation peers (1-4294967295)...",
1162 NO_STR
1163 "BGP specific commands\n"
1164 "AS confederation parameters\n"
1165 "Peer ASs in BGP confederation\n"
1166 AS_STR)
1167 {
1168 VTY_DECLVAR_CONTEXT(bgp, bgp);
1169 int idx_asn = 4;
1170 as_t as;
1171 int i;
1172
1173 for (i = idx_asn; i < argc; i++) {
1174 as = strtoul(argv[i]->arg, NULL, 10);
1175
1176 bgp_confederation_peers_remove(bgp, as);
1177 }
1178 return CMD_SUCCESS;
1179 }
1180
1181 /**
1182 * Central routine for maximum-paths configuration.
1183 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1184 * @set: 1 for setting values, 0 for removing the max-paths config.
1185 */
1186 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1187 const char *mpaths, uint16_t options,
1188 int set)
1189 {
1190 VTY_DECLVAR_CONTEXT(bgp, bgp);
1191 uint16_t maxpaths = 0;
1192 int ret;
1193 afi_t afi;
1194 safi_t safi;
1195
1196 afi = bgp_node_afi(vty);
1197 safi = bgp_node_safi(vty);
1198
1199 if (set) {
1200 maxpaths = strtol(mpaths, NULL, 10);
1201 if (maxpaths > multipath_num) {
1202 vty_out(vty,
1203 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1204 maxpaths, multipath_num);
1205 return CMD_WARNING_CONFIG_FAILED;
1206 }
1207 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1208 options);
1209 } else
1210 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1211
1212 if (ret < 0) {
1213 vty_out(vty,
1214 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1215 (set == 1) ? "" : "un",
1216 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1217 maxpaths, afi, safi);
1218 return CMD_WARNING_CONFIG_FAILED;
1219 }
1220
1221 bgp_recalculate_all_bestpaths(bgp);
1222
1223 return CMD_SUCCESS;
1224 }
1225
1226 DEFUN (bgp_maxmed_admin,
1227 bgp_maxmed_admin_cmd,
1228 "bgp max-med administrative ",
1229 BGP_STR
1230 "Advertise routes with max-med\n"
1231 "Administratively applied, for an indefinite period\n")
1232 {
1233 VTY_DECLVAR_CONTEXT(bgp, bgp);
1234
1235 bgp->v_maxmed_admin = 1;
1236 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1237
1238 bgp_maxmed_update(bgp);
1239
1240 return CMD_SUCCESS;
1241 }
1242
1243 DEFUN (bgp_maxmed_admin_medv,
1244 bgp_maxmed_admin_medv_cmd,
1245 "bgp max-med administrative (0-4294967295)",
1246 BGP_STR
1247 "Advertise routes with max-med\n"
1248 "Administratively applied, for an indefinite period\n"
1249 "Max MED value to be used\n")
1250 {
1251 VTY_DECLVAR_CONTEXT(bgp, bgp);
1252 int idx_number = 3;
1253
1254 bgp->v_maxmed_admin = 1;
1255 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1256
1257 bgp_maxmed_update(bgp);
1258
1259 return CMD_SUCCESS;
1260 }
1261
1262 DEFUN (no_bgp_maxmed_admin,
1263 no_bgp_maxmed_admin_cmd,
1264 "no bgp max-med administrative [(0-4294967295)]",
1265 NO_STR
1266 BGP_STR
1267 "Advertise routes with max-med\n"
1268 "Administratively applied, for an indefinite period\n"
1269 "Max MED value to be used\n")
1270 {
1271 VTY_DECLVAR_CONTEXT(bgp, bgp);
1272 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1273 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1274 bgp_maxmed_update(bgp);
1275
1276 return CMD_SUCCESS;
1277 }
1278
1279 DEFUN (bgp_maxmed_onstartup,
1280 bgp_maxmed_onstartup_cmd,
1281 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1282 BGP_STR
1283 "Advertise routes with max-med\n"
1284 "Effective on a startup\n"
1285 "Time (seconds) period for max-med\n"
1286 "Max MED value to be used\n")
1287 {
1288 VTY_DECLVAR_CONTEXT(bgp, bgp);
1289 int idx = 0;
1290
1291 argv_find(argv, argc, "(5-86400)", &idx);
1292 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1293 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1294 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1295 else
1296 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1297
1298 bgp_maxmed_update(bgp);
1299
1300 return CMD_SUCCESS;
1301 }
1302
1303 DEFUN (no_bgp_maxmed_onstartup,
1304 no_bgp_maxmed_onstartup_cmd,
1305 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1306 NO_STR
1307 BGP_STR
1308 "Advertise routes with max-med\n"
1309 "Effective on a startup\n"
1310 "Time (seconds) period for max-med\n"
1311 "Max MED value to be used\n")
1312 {
1313 VTY_DECLVAR_CONTEXT(bgp, bgp);
1314
1315 /* Cancel max-med onstartup if its on */
1316 if (bgp->t_maxmed_onstartup) {
1317 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1318 bgp->maxmed_onstartup_over = 1;
1319 }
1320
1321 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1322 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1323
1324 bgp_maxmed_update(bgp);
1325
1326 return CMD_SUCCESS;
1327 }
1328
1329 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1330 const char *wait)
1331 {
1332 VTY_DECLVAR_CONTEXT(bgp, bgp);
1333 uint16_t update_delay;
1334 uint16_t establish_wait;
1335
1336 update_delay = strtoul(delay, NULL, 10);
1337
1338 if (!wait) /* update-delay <delay> */
1339 {
1340 bgp->v_update_delay = update_delay;
1341 bgp->v_establish_wait = bgp->v_update_delay;
1342 return CMD_SUCCESS;
1343 }
1344
1345 /* update-delay <delay> <establish-wait> */
1346 establish_wait = atoi(wait);
1347 if (update_delay < establish_wait) {
1348 vty_out(vty,
1349 "%%Failed: update-delay less than the establish-wait!\n");
1350 return CMD_WARNING_CONFIG_FAILED;
1351 }
1352
1353 bgp->v_update_delay = update_delay;
1354 bgp->v_establish_wait = establish_wait;
1355
1356 return CMD_SUCCESS;
1357 }
1358
1359 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1360 {
1361 VTY_DECLVAR_CONTEXT(bgp, bgp);
1362
1363 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1364 bgp->v_establish_wait = bgp->v_update_delay;
1365
1366 return CMD_SUCCESS;
1367 }
1368
1369 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1370 {
1371 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1372 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1373 if (bgp->v_update_delay != bgp->v_establish_wait)
1374 vty_out(vty, " %d", bgp->v_establish_wait);
1375 vty_out(vty, "\n");
1376 }
1377 }
1378
1379
1380 /* Update-delay configuration */
1381 DEFUN (bgp_update_delay,
1382 bgp_update_delay_cmd,
1383 "update-delay (0-3600)",
1384 "Force initial delay for best-path and updates\n"
1385 "Seconds\n")
1386 {
1387 int idx_number = 1;
1388 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1389 }
1390
1391 DEFUN (bgp_update_delay_establish_wait,
1392 bgp_update_delay_establish_wait_cmd,
1393 "update-delay (0-3600) (1-3600)",
1394 "Force initial delay for best-path and updates\n"
1395 "Seconds\n"
1396 "Seconds\n")
1397 {
1398 int idx_number = 1;
1399 int idx_number_2 = 2;
1400 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1401 argv[idx_number_2]->arg);
1402 }
1403
1404 /* Update-delay deconfiguration */
1405 DEFUN (no_bgp_update_delay,
1406 no_bgp_update_delay_cmd,
1407 "no update-delay [(0-3600) [(1-3600)]]",
1408 NO_STR
1409 "Force initial delay for best-path and updates\n"
1410 "Seconds\n"
1411 "Seconds\n")
1412 {
1413 return bgp_update_delay_deconfig_vty(vty);
1414 }
1415
1416
1417 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1418 char set)
1419 {
1420 VTY_DECLVAR_CONTEXT(bgp, bgp);
1421
1422 if (set) {
1423 uint32_t quanta = strtoul(num, NULL, 10);
1424 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1425 memory_order_relaxed);
1426 } else {
1427 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1428 memory_order_relaxed);
1429 }
1430
1431 return CMD_SUCCESS;
1432 }
1433
1434 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1435 char set)
1436 {
1437 VTY_DECLVAR_CONTEXT(bgp, bgp);
1438
1439 if (set) {
1440 uint32_t quanta = strtoul(num, NULL, 10);
1441 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1442 memory_order_relaxed);
1443 } else {
1444 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1445 memory_order_relaxed);
1446 }
1447
1448 return CMD_SUCCESS;
1449 }
1450
1451 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1452 {
1453 uint32_t quanta =
1454 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1455 if (quanta != BGP_WRITE_PACKET_MAX)
1456 vty_out(vty, " write-quanta %d\n", quanta);
1457 }
1458
1459 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1460 {
1461 uint32_t quanta =
1462 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1463 if (quanta != BGP_READ_PACKET_MAX)
1464 vty_out(vty, " read-quanta %d\n", quanta);
1465 }
1466
1467 /* Packet quanta configuration */
1468 DEFUN (bgp_wpkt_quanta,
1469 bgp_wpkt_quanta_cmd,
1470 "write-quanta (1-10)",
1471 "How many packets to write to peer socket per run\n"
1472 "Number of packets\n")
1473 {
1474 int idx_number = 1;
1475 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1476 }
1477
1478 DEFUN (no_bgp_wpkt_quanta,
1479 no_bgp_wpkt_quanta_cmd,
1480 "no write-quanta (1-10)",
1481 NO_STR
1482 "How many packets to write to peer socket per I/O cycle\n"
1483 "Number of packets\n")
1484 {
1485 int idx_number = 2;
1486 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1487 }
1488
1489 DEFUN (bgp_rpkt_quanta,
1490 bgp_rpkt_quanta_cmd,
1491 "read-quanta (1-10)",
1492 "How many packets to read from peer socket per I/O cycle\n"
1493 "Number of packets\n")
1494 {
1495 int idx_number = 1;
1496 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1497 }
1498
1499 DEFUN (no_bgp_rpkt_quanta,
1500 no_bgp_rpkt_quanta_cmd,
1501 "no read-quanta (1-10)",
1502 NO_STR
1503 "How many packets to read from peer socket per I/O cycle\n"
1504 "Number of packets\n")
1505 {
1506 int idx_number = 2;
1507 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1508 }
1509
1510 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1511 {
1512 if (!bgp->heuristic_coalesce)
1513 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1514 }
1515
1516
1517 DEFUN (bgp_coalesce_time,
1518 bgp_coalesce_time_cmd,
1519 "coalesce-time (0-4294967295)",
1520 "Subgroup coalesce timer\n"
1521 "Subgroup coalesce timer value (in ms)\n")
1522 {
1523 VTY_DECLVAR_CONTEXT(bgp, bgp);
1524
1525 int idx = 0;
1526 argv_find(argv, argc, "(0-4294967295)", &idx);
1527 bgp->heuristic_coalesce = false;
1528 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1529 return CMD_SUCCESS;
1530 }
1531
1532 DEFUN (no_bgp_coalesce_time,
1533 no_bgp_coalesce_time_cmd,
1534 "no coalesce-time (0-4294967295)",
1535 NO_STR
1536 "Subgroup coalesce timer\n"
1537 "Subgroup coalesce timer value (in ms)\n")
1538 {
1539 VTY_DECLVAR_CONTEXT(bgp, bgp);
1540
1541 bgp->heuristic_coalesce = true;
1542 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1543 return CMD_SUCCESS;
1544 }
1545
1546 /* Maximum-paths configuration */
1547 DEFUN (bgp_maxpaths,
1548 bgp_maxpaths_cmd,
1549 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1550 "Forward packets over multiple paths\n"
1551 "Number of paths\n")
1552 {
1553 int idx_number = 1;
1554 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1555 argv[idx_number]->arg, 0, 1);
1556 }
1557
1558 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1559 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1560 "Forward packets over multiple paths\n"
1561 "Number of paths\n")
1562
1563 DEFUN (bgp_maxpaths_ibgp,
1564 bgp_maxpaths_ibgp_cmd,
1565 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1566 "Forward packets over multiple paths\n"
1567 "iBGP-multipath\n"
1568 "Number of paths\n")
1569 {
1570 int idx_number = 2;
1571 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1572 argv[idx_number]->arg, 0, 1);
1573 }
1574
1575 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1576 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1577 "Forward packets over multiple paths\n"
1578 "iBGP-multipath\n"
1579 "Number of paths\n")
1580
1581 DEFUN (bgp_maxpaths_ibgp_cluster,
1582 bgp_maxpaths_ibgp_cluster_cmd,
1583 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1584 "Forward packets over multiple paths\n"
1585 "iBGP-multipath\n"
1586 "Number of paths\n"
1587 "Match the cluster length\n")
1588 {
1589 int idx_number = 2;
1590 return bgp_maxpaths_config_vty(
1591 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1592 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1593 }
1594
1595 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1596 "maximum-paths ibgp " CMD_RANGE_STR(
1597 1, MULTIPATH_NUM) " equal-cluster-length",
1598 "Forward packets over multiple paths\n"
1599 "iBGP-multipath\n"
1600 "Number of paths\n"
1601 "Match the cluster length\n")
1602
1603 DEFUN (no_bgp_maxpaths,
1604 no_bgp_maxpaths_cmd,
1605 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1606 NO_STR
1607 "Forward packets over multiple paths\n"
1608 "Number of paths\n")
1609 {
1610 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1611 }
1612
1613 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1614 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1615 "Forward packets over multiple paths\n"
1616 "Number of paths\n")
1617
1618 DEFUN (no_bgp_maxpaths_ibgp,
1619 no_bgp_maxpaths_ibgp_cmd,
1620 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1621 NO_STR
1622 "Forward packets over multiple paths\n"
1623 "iBGP-multipath\n"
1624 "Number of paths\n"
1625 "Match the cluster length\n")
1626 {
1627 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1628 }
1629
1630 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1631 "no maximum-paths ibgp [" CMD_RANGE_STR(
1632 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1633 NO_STR
1634 "Forward packets over multiple paths\n"
1635 "iBGP-multipath\n"
1636 "Number of paths\n"
1637 "Match the cluster length\n")
1638
1639 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1640 safi_t safi)
1641 {
1642 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1643 vty_out(vty, " maximum-paths %d\n",
1644 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1645 }
1646
1647 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1648 vty_out(vty, " maximum-paths ibgp %d",
1649 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1650 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1651 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1652 vty_out(vty, " equal-cluster-length");
1653 vty_out(vty, "\n");
1654 }
1655 }
1656
1657 /* BGP timers. */
1658
1659 DEFUN (bgp_timers,
1660 bgp_timers_cmd,
1661 "timers bgp (0-65535) (0-65535)",
1662 "Adjust routing timers\n"
1663 "BGP timers\n"
1664 "Keepalive interval\n"
1665 "Holdtime\n")
1666 {
1667 VTY_DECLVAR_CONTEXT(bgp, bgp);
1668 int idx_number = 2;
1669 int idx_number_2 = 3;
1670 unsigned long keepalive = 0;
1671 unsigned long holdtime = 0;
1672
1673 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1674 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1675
1676 /* Holdtime value check. */
1677 if (holdtime < 3 && holdtime != 0) {
1678 vty_out(vty,
1679 "%% hold time value must be either 0 or greater than 3\n");
1680 return CMD_WARNING_CONFIG_FAILED;
1681 }
1682
1683 bgp_timers_set(bgp, keepalive, holdtime);
1684
1685 return CMD_SUCCESS;
1686 }
1687
1688 DEFUN (no_bgp_timers,
1689 no_bgp_timers_cmd,
1690 "no timers bgp [(0-65535) (0-65535)]",
1691 NO_STR
1692 "Adjust routing timers\n"
1693 "BGP timers\n"
1694 "Keepalive interval\n"
1695 "Holdtime\n")
1696 {
1697 VTY_DECLVAR_CONTEXT(bgp, bgp);
1698 bgp_timers_unset(bgp);
1699
1700 return CMD_SUCCESS;
1701 }
1702
1703
1704 DEFUN (bgp_client_to_client_reflection,
1705 bgp_client_to_client_reflection_cmd,
1706 "bgp client-to-client reflection",
1707 "BGP specific commands\n"
1708 "Configure client to client route reflection\n"
1709 "reflection of routes allowed\n")
1710 {
1711 VTY_DECLVAR_CONTEXT(bgp, bgp);
1712 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1713 bgp_clear_star_soft_out(vty, bgp->name);
1714
1715 return CMD_SUCCESS;
1716 }
1717
1718 DEFUN (no_bgp_client_to_client_reflection,
1719 no_bgp_client_to_client_reflection_cmd,
1720 "no bgp client-to-client reflection",
1721 NO_STR
1722 "BGP specific commands\n"
1723 "Configure client to client route reflection\n"
1724 "reflection of routes allowed\n")
1725 {
1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1728 bgp_clear_star_soft_out(vty, bgp->name);
1729
1730 return CMD_SUCCESS;
1731 }
1732
1733 /* "bgp always-compare-med" configuration. */
1734 DEFUN (bgp_always_compare_med,
1735 bgp_always_compare_med_cmd,
1736 "bgp always-compare-med",
1737 "BGP specific commands\n"
1738 "Allow comparing MED from different neighbors\n")
1739 {
1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1742 bgp_recalculate_all_bestpaths(bgp);
1743
1744 return CMD_SUCCESS;
1745 }
1746
1747 DEFUN (no_bgp_always_compare_med,
1748 no_bgp_always_compare_med_cmd,
1749 "no bgp always-compare-med",
1750 NO_STR
1751 "BGP specific commands\n"
1752 "Allow comparing MED from different neighbors\n")
1753 {
1754 VTY_DECLVAR_CONTEXT(bgp, bgp);
1755 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1756 bgp_recalculate_all_bestpaths(bgp);
1757
1758 return CMD_SUCCESS;
1759 }
1760
1761 /* "bgp deterministic-med" configuration. */
1762 DEFUN (bgp_deterministic_med,
1763 bgp_deterministic_med_cmd,
1764 "bgp deterministic-med",
1765 "BGP specific commands\n"
1766 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1767 {
1768 VTY_DECLVAR_CONTEXT(bgp, bgp);
1769
1770 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1771 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1772 bgp_recalculate_all_bestpaths(bgp);
1773 }
1774
1775 return CMD_SUCCESS;
1776 }
1777
1778 DEFUN (no_bgp_deterministic_med,
1779 no_bgp_deterministic_med_cmd,
1780 "no bgp deterministic-med",
1781 NO_STR
1782 "BGP specific commands\n"
1783 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1784 {
1785 VTY_DECLVAR_CONTEXT(bgp, bgp);
1786 int bestpath_per_as_used;
1787 afi_t afi;
1788 safi_t safi;
1789 struct peer *peer;
1790 struct listnode *node, *nnode;
1791
1792 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1793 bestpath_per_as_used = 0;
1794
1795 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1796 FOREACH_AFI_SAFI (afi, safi)
1797 if (CHECK_FLAG(
1798 peer->af_flags[afi][safi],
1799 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1800 bestpath_per_as_used = 1;
1801 break;
1802 }
1803
1804 if (bestpath_per_as_used)
1805 break;
1806 }
1807
1808 if (bestpath_per_as_used) {
1809 vty_out(vty,
1810 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1811 return CMD_WARNING_CONFIG_FAILED;
1812 } else {
1813 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1814 bgp_recalculate_all_bestpaths(bgp);
1815 }
1816 }
1817
1818 return CMD_SUCCESS;
1819 }
1820
1821 /* "bgp graceful-restart" configuration. */
1822 DEFUN (bgp_graceful_restart,
1823 bgp_graceful_restart_cmd,
1824 "bgp graceful-restart",
1825 "BGP specific commands\n"
1826 "Graceful restart capability parameters\n")
1827 {
1828 VTY_DECLVAR_CONTEXT(bgp, bgp);
1829 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1830 return CMD_SUCCESS;
1831 }
1832
1833 DEFUN (no_bgp_graceful_restart,
1834 no_bgp_graceful_restart_cmd,
1835 "no bgp graceful-restart",
1836 NO_STR
1837 "BGP specific commands\n"
1838 "Graceful restart capability parameters\n")
1839 {
1840 VTY_DECLVAR_CONTEXT(bgp, bgp);
1841 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1842 return CMD_SUCCESS;
1843 }
1844
1845 DEFUN (bgp_graceful_restart_stalepath_time,
1846 bgp_graceful_restart_stalepath_time_cmd,
1847 "bgp graceful-restart stalepath-time (1-3600)",
1848 "BGP specific commands\n"
1849 "Graceful restart capability parameters\n"
1850 "Set the max time to hold onto restarting peer's stale paths\n"
1851 "Delay value (seconds)\n")
1852 {
1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
1854 int idx_number = 3;
1855 uint32_t stalepath;
1856
1857 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1858 bgp->stalepath_time = stalepath;
1859 return CMD_SUCCESS;
1860 }
1861
1862 DEFUN (bgp_graceful_restart_restart_time,
1863 bgp_graceful_restart_restart_time_cmd,
1864 "bgp graceful-restart restart-time (1-3600)",
1865 "BGP specific commands\n"
1866 "Graceful restart capability parameters\n"
1867 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1868 "Delay value (seconds)\n")
1869 {
1870 VTY_DECLVAR_CONTEXT(bgp, bgp);
1871 int idx_number = 3;
1872 uint32_t restart;
1873
1874 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1875 bgp->restart_time = restart;
1876 return CMD_SUCCESS;
1877 }
1878
1879 DEFUN (no_bgp_graceful_restart_stalepath_time,
1880 no_bgp_graceful_restart_stalepath_time_cmd,
1881 "no bgp graceful-restart stalepath-time [(1-3600)]",
1882 NO_STR
1883 "BGP specific commands\n"
1884 "Graceful restart capability parameters\n"
1885 "Set the max time to hold onto restarting peer's stale paths\n"
1886 "Delay value (seconds)\n")
1887 {
1888 VTY_DECLVAR_CONTEXT(bgp, bgp);
1889
1890 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1891 return CMD_SUCCESS;
1892 }
1893
1894 DEFUN (no_bgp_graceful_restart_restart_time,
1895 no_bgp_graceful_restart_restart_time_cmd,
1896 "no bgp graceful-restart restart-time [(1-3600)]",
1897 NO_STR
1898 "BGP specific commands\n"
1899 "Graceful restart capability parameters\n"
1900 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1901 "Delay value (seconds)\n")
1902 {
1903 VTY_DECLVAR_CONTEXT(bgp, bgp);
1904
1905 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1906 return CMD_SUCCESS;
1907 }
1908
1909 DEFUN (bgp_graceful_restart_preserve_fw,
1910 bgp_graceful_restart_preserve_fw_cmd,
1911 "bgp graceful-restart preserve-fw-state",
1912 "BGP specific commands\n"
1913 "Graceful restart capability parameters\n"
1914 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1915 {
1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1918 return CMD_SUCCESS;
1919 }
1920
1921 DEFUN (no_bgp_graceful_restart_preserve_fw,
1922 no_bgp_graceful_restart_preserve_fw_cmd,
1923 "no bgp graceful-restart preserve-fw-state",
1924 NO_STR
1925 "BGP specific commands\n"
1926 "Graceful restart capability parameters\n"
1927 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1928 {
1929 VTY_DECLVAR_CONTEXT(bgp, bgp);
1930 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1931 return CMD_SUCCESS;
1932 }
1933
1934 static void bgp_redistribute_redo(struct bgp *bgp)
1935 {
1936 afi_t afi;
1937 int i;
1938 struct list *red_list;
1939 struct listnode *node;
1940 struct bgp_redist *red;
1941
1942 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1943 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1944
1945 red_list = bgp->redist[afi][i];
1946 if (!red_list)
1947 continue;
1948
1949 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1950 bgp_redistribute_resend(bgp, afi, i,
1951 red->instance);
1952 }
1953 }
1954 }
1955 }
1956
1957 /* "bgp graceful-shutdown" configuration */
1958 DEFUN (bgp_graceful_shutdown,
1959 bgp_graceful_shutdown_cmd,
1960 "bgp graceful-shutdown",
1961 BGP_STR
1962 "Graceful shutdown parameters\n")
1963 {
1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965
1966 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1967 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1968 bgp_static_redo_import_check(bgp);
1969 bgp_redistribute_redo(bgp);
1970 bgp_clear_star_soft_out(vty, bgp->name);
1971 bgp_clear_star_soft_in(vty, bgp->name);
1972 }
1973
1974 return CMD_SUCCESS;
1975 }
1976
1977 DEFUN (no_bgp_graceful_shutdown,
1978 no_bgp_graceful_shutdown_cmd,
1979 "no bgp graceful-shutdown",
1980 NO_STR
1981 BGP_STR
1982 "Graceful shutdown parameters\n")
1983 {
1984 VTY_DECLVAR_CONTEXT(bgp, bgp);
1985
1986 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1987 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1988 bgp_static_redo_import_check(bgp);
1989 bgp_redistribute_redo(bgp);
1990 bgp_clear_star_soft_out(vty, bgp->name);
1991 bgp_clear_star_soft_in(vty, bgp->name);
1992 }
1993
1994 return CMD_SUCCESS;
1995 }
1996
1997 /* "bgp fast-external-failover" configuration. */
1998 DEFUN (bgp_fast_external_failover,
1999 bgp_fast_external_failover_cmd,
2000 "bgp fast-external-failover",
2001 BGP_STR
2002 "Immediately reset session if a link to a directly connected external peer goes down\n")
2003 {
2004 VTY_DECLVAR_CONTEXT(bgp, bgp);
2005 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2006 return CMD_SUCCESS;
2007 }
2008
2009 DEFUN (no_bgp_fast_external_failover,
2010 no_bgp_fast_external_failover_cmd,
2011 "no bgp fast-external-failover",
2012 NO_STR
2013 BGP_STR
2014 "Immediately reset session if a link to a directly connected external peer goes down\n")
2015 {
2016 VTY_DECLVAR_CONTEXT(bgp, bgp);
2017 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2018 return CMD_SUCCESS;
2019 }
2020
2021 /* "bgp enforce-first-as" configuration. */
2022 #if CONFDATE > 20190517
2023 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2024 #endif
2025
2026 DEFUN_HIDDEN (bgp_enforce_first_as,
2027 bgp_enforce_first_as_cmd,
2028 "[no] bgp enforce-first-as",
2029 NO_STR
2030 BGP_STR
2031 "Enforce the first AS for EBGP routes\n")
2032 {
2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
2034
2035 if (strmatch(argv[0]->text, "no"))
2036 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2037 else
2038 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2039
2040 return CMD_SUCCESS;
2041 }
2042
2043 /* "bgp bestpath compare-routerid" configuration. */
2044 DEFUN (bgp_bestpath_compare_router_id,
2045 bgp_bestpath_compare_router_id_cmd,
2046 "bgp bestpath compare-routerid",
2047 "BGP specific commands\n"
2048 "Change the default bestpath selection\n"
2049 "Compare router-id for identical EBGP paths\n")
2050 {
2051 VTY_DECLVAR_CONTEXT(bgp, bgp);
2052 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2053 bgp_recalculate_all_bestpaths(bgp);
2054
2055 return CMD_SUCCESS;
2056 }
2057
2058 DEFUN (no_bgp_bestpath_compare_router_id,
2059 no_bgp_bestpath_compare_router_id_cmd,
2060 "no bgp bestpath compare-routerid",
2061 NO_STR
2062 "BGP specific commands\n"
2063 "Change the default bestpath selection\n"
2064 "Compare router-id for identical EBGP paths\n")
2065 {
2066 VTY_DECLVAR_CONTEXT(bgp, bgp);
2067 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2068 bgp_recalculate_all_bestpaths(bgp);
2069
2070 return CMD_SUCCESS;
2071 }
2072
2073 /* "bgp bestpath as-path ignore" configuration. */
2074 DEFUN (bgp_bestpath_aspath_ignore,
2075 bgp_bestpath_aspath_ignore_cmd,
2076 "bgp bestpath as-path ignore",
2077 "BGP specific commands\n"
2078 "Change the default bestpath selection\n"
2079 "AS-path attribute\n"
2080 "Ignore as-path length in selecting a route\n")
2081 {
2082 VTY_DECLVAR_CONTEXT(bgp, bgp);
2083 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2084 bgp_recalculate_all_bestpaths(bgp);
2085
2086 return CMD_SUCCESS;
2087 }
2088
2089 DEFUN (no_bgp_bestpath_aspath_ignore,
2090 no_bgp_bestpath_aspath_ignore_cmd,
2091 "no bgp bestpath as-path ignore",
2092 NO_STR
2093 "BGP specific commands\n"
2094 "Change the default bestpath selection\n"
2095 "AS-path attribute\n"
2096 "Ignore as-path length in selecting a route\n")
2097 {
2098 VTY_DECLVAR_CONTEXT(bgp, bgp);
2099 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2100 bgp_recalculate_all_bestpaths(bgp);
2101
2102 return CMD_SUCCESS;
2103 }
2104
2105 /* "bgp bestpath as-path confed" configuration. */
2106 DEFUN (bgp_bestpath_aspath_confed,
2107 bgp_bestpath_aspath_confed_cmd,
2108 "bgp bestpath as-path confed",
2109 "BGP specific commands\n"
2110 "Change the default bestpath selection\n"
2111 "AS-path attribute\n"
2112 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2113 {
2114 VTY_DECLVAR_CONTEXT(bgp, bgp);
2115 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2116 bgp_recalculate_all_bestpaths(bgp);
2117
2118 return CMD_SUCCESS;
2119 }
2120
2121 DEFUN (no_bgp_bestpath_aspath_confed,
2122 no_bgp_bestpath_aspath_confed_cmd,
2123 "no bgp bestpath as-path confed",
2124 NO_STR
2125 "BGP specific commands\n"
2126 "Change the default bestpath selection\n"
2127 "AS-path attribute\n"
2128 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2129 {
2130 VTY_DECLVAR_CONTEXT(bgp, bgp);
2131 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2132 bgp_recalculate_all_bestpaths(bgp);
2133
2134 return CMD_SUCCESS;
2135 }
2136
2137 /* "bgp bestpath as-path multipath-relax" configuration. */
2138 DEFUN (bgp_bestpath_aspath_multipath_relax,
2139 bgp_bestpath_aspath_multipath_relax_cmd,
2140 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2141 "BGP specific commands\n"
2142 "Change the default bestpath selection\n"
2143 "AS-path attribute\n"
2144 "Allow load sharing across routes that have different AS paths (but same length)\n"
2145 "Generate an AS_SET\n"
2146 "Do not generate an AS_SET\n")
2147 {
2148 VTY_DECLVAR_CONTEXT(bgp, bgp);
2149 int idx = 0;
2150 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2151
2152 /* no-as-set is now the default behavior so we can silently
2153 * ignore it */
2154 if (argv_find(argv, argc, "as-set", &idx))
2155 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2156 else
2157 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2158
2159 bgp_recalculate_all_bestpaths(bgp);
2160
2161 return CMD_SUCCESS;
2162 }
2163
2164 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2165 no_bgp_bestpath_aspath_multipath_relax_cmd,
2166 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2167 NO_STR
2168 "BGP specific commands\n"
2169 "Change the default bestpath selection\n"
2170 "AS-path attribute\n"
2171 "Allow load sharing across routes that have different AS paths (but same length)\n"
2172 "Generate an AS_SET\n"
2173 "Do not generate an AS_SET\n")
2174 {
2175 VTY_DECLVAR_CONTEXT(bgp, bgp);
2176 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2177 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2178 bgp_recalculate_all_bestpaths(bgp);
2179
2180 return CMD_SUCCESS;
2181 }
2182
2183 /* "bgp log-neighbor-changes" configuration. */
2184 DEFUN (bgp_log_neighbor_changes,
2185 bgp_log_neighbor_changes_cmd,
2186 "bgp log-neighbor-changes",
2187 "BGP specific commands\n"
2188 "Log neighbor up/down and reset reason\n")
2189 {
2190 VTY_DECLVAR_CONTEXT(bgp, bgp);
2191 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2192 return CMD_SUCCESS;
2193 }
2194
2195 DEFUN (no_bgp_log_neighbor_changes,
2196 no_bgp_log_neighbor_changes_cmd,
2197 "no bgp log-neighbor-changes",
2198 NO_STR
2199 "BGP specific commands\n"
2200 "Log neighbor up/down and reset reason\n")
2201 {
2202 VTY_DECLVAR_CONTEXT(bgp, bgp);
2203 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2204 return CMD_SUCCESS;
2205 }
2206
2207 /* "bgp bestpath med" configuration. */
2208 DEFUN (bgp_bestpath_med,
2209 bgp_bestpath_med_cmd,
2210 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2211 "BGP specific commands\n"
2212 "Change the default bestpath selection\n"
2213 "MED attribute\n"
2214 "Compare MED among confederation paths\n"
2215 "Treat missing MED as the least preferred one\n"
2216 "Treat missing MED as the least preferred one\n"
2217 "Compare MED among confederation paths\n")
2218 {
2219 VTY_DECLVAR_CONTEXT(bgp, bgp);
2220
2221 int idx = 0;
2222 if (argv_find(argv, argc, "confed", &idx))
2223 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2224 idx = 0;
2225 if (argv_find(argv, argc, "missing-as-worst", &idx))
2226 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2227
2228 bgp_recalculate_all_bestpaths(bgp);
2229
2230 return CMD_SUCCESS;
2231 }
2232
2233 DEFUN (no_bgp_bestpath_med,
2234 no_bgp_bestpath_med_cmd,
2235 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2236 NO_STR
2237 "BGP specific commands\n"
2238 "Change the default bestpath selection\n"
2239 "MED attribute\n"
2240 "Compare MED among confederation paths\n"
2241 "Treat missing MED as the least preferred one\n"
2242 "Treat missing MED as the least preferred one\n"
2243 "Compare MED among confederation paths\n")
2244 {
2245 VTY_DECLVAR_CONTEXT(bgp, bgp);
2246
2247 int idx = 0;
2248 if (argv_find(argv, argc, "confed", &idx))
2249 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2250 idx = 0;
2251 if (argv_find(argv, argc, "missing-as-worst", &idx))
2252 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2253
2254 bgp_recalculate_all_bestpaths(bgp);
2255
2256 return CMD_SUCCESS;
2257 }
2258
2259 /* "no bgp default ipv4-unicast". */
2260 DEFUN (no_bgp_default_ipv4_unicast,
2261 no_bgp_default_ipv4_unicast_cmd,
2262 "no bgp default ipv4-unicast",
2263 NO_STR
2264 "BGP specific commands\n"
2265 "Configure BGP defaults\n"
2266 "Activate ipv4-unicast for a peer by default\n")
2267 {
2268 VTY_DECLVAR_CONTEXT(bgp, bgp);
2269 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2270 return CMD_SUCCESS;
2271 }
2272
2273 DEFUN (bgp_default_ipv4_unicast,
2274 bgp_default_ipv4_unicast_cmd,
2275 "bgp default ipv4-unicast",
2276 "BGP specific commands\n"
2277 "Configure BGP defaults\n"
2278 "Activate ipv4-unicast for a peer by default\n")
2279 {
2280 VTY_DECLVAR_CONTEXT(bgp, bgp);
2281 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2282 return CMD_SUCCESS;
2283 }
2284
2285 /* Display hostname in certain command outputs */
2286 DEFUN (bgp_default_show_hostname,
2287 bgp_default_show_hostname_cmd,
2288 "bgp default show-hostname",
2289 "BGP specific commands\n"
2290 "Configure BGP defaults\n"
2291 "Show hostname in certain command outputs\n")
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2295 return CMD_SUCCESS;
2296 }
2297
2298 DEFUN (no_bgp_default_show_hostname,
2299 no_bgp_default_show_hostname_cmd,
2300 "no bgp default show-hostname",
2301 NO_STR
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_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2308 return CMD_SUCCESS;
2309 }
2310
2311 /* "bgp network import-check" configuration. */
2312 DEFUN (bgp_network_import_check,
2313 bgp_network_import_check_cmd,
2314 "bgp network import-check",
2315 "BGP specific commands\n"
2316 "BGP network command\n"
2317 "Check BGP network route exists in IGP\n")
2318 {
2319 VTY_DECLVAR_CONTEXT(bgp, bgp);
2320 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2321 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2322 bgp_static_redo_import_check(bgp);
2323 }
2324
2325 return CMD_SUCCESS;
2326 }
2327
2328 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2329 "bgp network import-check exact",
2330 "BGP specific commands\n"
2331 "BGP network command\n"
2332 "Check BGP network route exists in IGP\n"
2333 "Match route precisely\n")
2334
2335 DEFUN (no_bgp_network_import_check,
2336 no_bgp_network_import_check_cmd,
2337 "no bgp network import-check",
2338 NO_STR
2339 "BGP specific commands\n"
2340 "BGP network command\n"
2341 "Check BGP network route exists in IGP\n")
2342 {
2343 VTY_DECLVAR_CONTEXT(bgp, bgp);
2344 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2345 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2346 bgp_static_redo_import_check(bgp);
2347 }
2348
2349 return CMD_SUCCESS;
2350 }
2351
2352 DEFUN (bgp_default_local_preference,
2353 bgp_default_local_preference_cmd,
2354 "bgp default local-preference (0-4294967295)",
2355 "BGP specific commands\n"
2356 "Configure BGP defaults\n"
2357 "local preference (higher=more preferred)\n"
2358 "Configure default local preference value\n")
2359 {
2360 VTY_DECLVAR_CONTEXT(bgp, bgp);
2361 int idx_number = 3;
2362 uint32_t local_pref;
2363
2364 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2365
2366 bgp_default_local_preference_set(bgp, local_pref);
2367 bgp_clear_star_soft_in(vty, bgp->name);
2368
2369 return CMD_SUCCESS;
2370 }
2371
2372 DEFUN (no_bgp_default_local_preference,
2373 no_bgp_default_local_preference_cmd,
2374 "no bgp default local-preference [(0-4294967295)]",
2375 NO_STR
2376 "BGP specific commands\n"
2377 "Configure BGP defaults\n"
2378 "local preference (higher=more preferred)\n"
2379 "Configure default local preference value\n")
2380 {
2381 VTY_DECLVAR_CONTEXT(bgp, bgp);
2382 bgp_default_local_preference_unset(bgp);
2383 bgp_clear_star_soft_in(vty, bgp->name);
2384
2385 return CMD_SUCCESS;
2386 }
2387
2388
2389 DEFUN (bgp_default_subgroup_pkt_queue_max,
2390 bgp_default_subgroup_pkt_queue_max_cmd,
2391 "bgp default subgroup-pkt-queue-max (20-100)",
2392 "BGP specific commands\n"
2393 "Configure BGP defaults\n"
2394 "subgroup-pkt-queue-max\n"
2395 "Configure subgroup packet queue max\n")
2396 {
2397 VTY_DECLVAR_CONTEXT(bgp, bgp);
2398 int idx_number = 3;
2399 uint32_t max_size;
2400
2401 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2402
2403 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2404
2405 return CMD_SUCCESS;
2406 }
2407
2408 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2409 no_bgp_default_subgroup_pkt_queue_max_cmd,
2410 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2411 NO_STR
2412 "BGP specific commands\n"
2413 "Configure BGP defaults\n"
2414 "subgroup-pkt-queue-max\n"
2415 "Configure subgroup packet queue max\n")
2416 {
2417 VTY_DECLVAR_CONTEXT(bgp, bgp);
2418 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2419 return CMD_SUCCESS;
2420 }
2421
2422
2423 DEFUN (bgp_rr_allow_outbound_policy,
2424 bgp_rr_allow_outbound_policy_cmd,
2425 "bgp route-reflector allow-outbound-policy",
2426 "BGP specific commands\n"
2427 "Allow modifications made by out route-map\n"
2428 "on ibgp neighbors\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431
2432 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2433 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2434 update_group_announce_rrclients(bgp);
2435 bgp_clear_star_soft_out(vty, bgp->name);
2436 }
2437
2438 return CMD_SUCCESS;
2439 }
2440
2441 DEFUN (no_bgp_rr_allow_outbound_policy,
2442 no_bgp_rr_allow_outbound_policy_cmd,
2443 "no bgp route-reflector allow-outbound-policy",
2444 NO_STR
2445 "BGP specific commands\n"
2446 "Allow modifications made by out route-map\n"
2447 "on ibgp neighbors\n")
2448 {
2449 VTY_DECLVAR_CONTEXT(bgp, bgp);
2450
2451 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2452 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2453 update_group_announce_rrclients(bgp);
2454 bgp_clear_star_soft_out(vty, bgp->name);
2455 }
2456
2457 return CMD_SUCCESS;
2458 }
2459
2460 DEFUN (bgp_listen_limit,
2461 bgp_listen_limit_cmd,
2462 "bgp listen limit (1-5000)",
2463 "BGP specific commands\n"
2464 "Configure BGP defaults\n"
2465 "maximum number of BGP Dynamic Neighbors that can be created\n"
2466 "Configure Dynamic Neighbors listen limit value\n")
2467 {
2468 VTY_DECLVAR_CONTEXT(bgp, bgp);
2469 int idx_number = 3;
2470 int listen_limit;
2471
2472 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2473
2474 bgp_listen_limit_set(bgp, listen_limit);
2475
2476 return CMD_SUCCESS;
2477 }
2478
2479 DEFUN (no_bgp_listen_limit,
2480 no_bgp_listen_limit_cmd,
2481 "no bgp listen limit [(1-5000)]",
2482 "BGP specific commands\n"
2483 "Configure BGP defaults\n"
2484 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2485 "Configure Dynamic Neighbors listen limit value to default\n"
2486 "Configure Dynamic Neighbors listen limit value\n")
2487 {
2488 VTY_DECLVAR_CONTEXT(bgp, bgp);
2489 bgp_listen_limit_unset(bgp);
2490 return CMD_SUCCESS;
2491 }
2492
2493
2494 /*
2495 * Check if this listen range is already configured. Check for exact
2496 * match or overlap based on input.
2497 */
2498 static struct peer_group *listen_range_exists(struct bgp *bgp,
2499 struct prefix *range, int exact)
2500 {
2501 struct listnode *node, *nnode;
2502 struct listnode *node1, *nnode1;
2503 struct peer_group *group;
2504 struct prefix *lr;
2505 afi_t afi;
2506 int match;
2507
2508 afi = family2afi(range->family);
2509 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2510 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2511 lr)) {
2512 if (exact)
2513 match = prefix_same(range, lr);
2514 else
2515 match = (prefix_match(range, lr)
2516 || prefix_match(lr, range));
2517 if (match)
2518 return group;
2519 }
2520 }
2521
2522 return NULL;
2523 }
2524
2525 DEFUN (bgp_listen_range,
2526 bgp_listen_range_cmd,
2527 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2528 "BGP specific commands\n"
2529 "Configure BGP dynamic neighbors listen range\n"
2530 "Configure BGP dynamic neighbors listen range\n"
2531 NEIGHBOR_ADDR_STR
2532 "Member of the peer-group\n"
2533 "Peer-group name\n")
2534 {
2535 VTY_DECLVAR_CONTEXT(bgp, bgp);
2536 struct prefix range;
2537 struct peer_group *group, *existing_group;
2538 afi_t afi;
2539 int ret;
2540 int idx = 0;
2541
2542 argv_find(argv, argc, "A.B.C.D/M", &idx);
2543 argv_find(argv, argc, "X:X::X:X/M", &idx);
2544 char *prefix = argv[idx]->arg;
2545 argv_find(argv, argc, "WORD", &idx);
2546 char *peergroup = argv[idx]->arg;
2547
2548 /* Convert IP prefix string to struct prefix. */
2549 ret = str2prefix(prefix, &range);
2550 if (!ret) {
2551 vty_out(vty, "%% Malformed listen range\n");
2552 return CMD_WARNING_CONFIG_FAILED;
2553 }
2554
2555 afi = family2afi(range.family);
2556
2557 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2558 vty_out(vty,
2559 "%% Malformed listen range (link-local address)\n");
2560 return CMD_WARNING_CONFIG_FAILED;
2561 }
2562
2563 apply_mask(&range);
2564
2565 /* Check if same listen range is already configured. */
2566 existing_group = listen_range_exists(bgp, &range, 1);
2567 if (existing_group) {
2568 if (strcmp(existing_group->name, peergroup) == 0)
2569 return CMD_SUCCESS;
2570 else {
2571 vty_out(vty,
2572 "%% Same listen range is attached to peer-group %s\n",
2573 existing_group->name);
2574 return CMD_WARNING_CONFIG_FAILED;
2575 }
2576 }
2577
2578 /* Check if an overlapping listen range exists. */
2579 if (listen_range_exists(bgp, &range, 0)) {
2580 vty_out(vty,
2581 "%% Listen range overlaps with existing listen range\n");
2582 return CMD_WARNING_CONFIG_FAILED;
2583 }
2584
2585 group = peer_group_lookup(bgp, peergroup);
2586 if (!group) {
2587 vty_out(vty, "%% Configure the peer-group first\n");
2588 return CMD_WARNING_CONFIG_FAILED;
2589 }
2590
2591 ret = peer_group_listen_range_add(group, &range);
2592 return bgp_vty_return(vty, ret);
2593 }
2594
2595 DEFUN (no_bgp_listen_range,
2596 no_bgp_listen_range_cmd,
2597 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2598 NO_STR
2599 "BGP specific commands\n"
2600 "Unconfigure BGP dynamic neighbors listen range\n"
2601 "Unconfigure BGP dynamic neighbors listen range\n"
2602 NEIGHBOR_ADDR_STR
2603 "Member of the peer-group\n"
2604 "Peer-group name\n")
2605 {
2606 VTY_DECLVAR_CONTEXT(bgp, bgp);
2607 struct prefix range;
2608 struct peer_group *group;
2609 afi_t afi;
2610 int ret;
2611 int idx = 0;
2612
2613 argv_find(argv, argc, "A.B.C.D/M", &idx);
2614 argv_find(argv, argc, "X:X::X:X/M", &idx);
2615 char *prefix = argv[idx]->arg;
2616 argv_find(argv, argc, "WORD", &idx);
2617 char *peergroup = argv[idx]->arg;
2618
2619 /* Convert IP prefix string to struct prefix. */
2620 ret = str2prefix(prefix, &range);
2621 if (!ret) {
2622 vty_out(vty, "%% Malformed listen range\n");
2623 return CMD_WARNING_CONFIG_FAILED;
2624 }
2625
2626 afi = family2afi(range.family);
2627
2628 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2629 vty_out(vty,
2630 "%% Malformed listen range (link-local address)\n");
2631 return CMD_WARNING_CONFIG_FAILED;
2632 }
2633
2634 apply_mask(&range);
2635
2636 group = peer_group_lookup(bgp, peergroup);
2637 if (!group) {
2638 vty_out(vty, "%% Peer-group does not exist\n");
2639 return CMD_WARNING_CONFIG_FAILED;
2640 }
2641
2642 ret = peer_group_listen_range_del(group, &range);
2643 return bgp_vty_return(vty, ret);
2644 }
2645
2646 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2647 {
2648 struct peer_group *group;
2649 struct listnode *node, *nnode, *rnode, *nrnode;
2650 struct prefix *range;
2651 afi_t afi;
2652 char buf[PREFIX2STR_BUFFER];
2653
2654 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2655 vty_out(vty, " bgp listen limit %d\n",
2656 bgp->dynamic_neighbors_limit);
2657
2658 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2659 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2660 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2661 nrnode, range)) {
2662 prefix2str(range, buf, sizeof(buf));
2663 vty_out(vty,
2664 " bgp listen range %s peer-group %s\n",
2665 buf, group->name);
2666 }
2667 }
2668 }
2669 }
2670
2671
2672 DEFUN (bgp_disable_connected_route_check,
2673 bgp_disable_connected_route_check_cmd,
2674 "bgp disable-ebgp-connected-route-check",
2675 "BGP specific commands\n"
2676 "Disable checking if nexthop is connected on ebgp sessions\n")
2677 {
2678 VTY_DECLVAR_CONTEXT(bgp, bgp);
2679 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2680 bgp_clear_star_soft_in(vty, bgp->name);
2681
2682 return CMD_SUCCESS;
2683 }
2684
2685 DEFUN (no_bgp_disable_connected_route_check,
2686 no_bgp_disable_connected_route_check_cmd,
2687 "no bgp disable-ebgp-connected-route-check",
2688 NO_STR
2689 "BGP specific commands\n"
2690 "Disable checking if nexthop is connected on ebgp sessions\n")
2691 {
2692 VTY_DECLVAR_CONTEXT(bgp, bgp);
2693 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2694 bgp_clear_star_soft_in(vty, bgp->name);
2695
2696 return CMD_SUCCESS;
2697 }
2698
2699
2700 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2701 const char *as_str, afi_t afi, safi_t safi)
2702 {
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 int ret;
2705 as_t as;
2706 int as_type = AS_SPECIFIED;
2707 union sockunion su;
2708
2709 if (as_str[0] == 'i') {
2710 as = 0;
2711 as_type = AS_INTERNAL;
2712 } else if (as_str[0] == 'e') {
2713 as = 0;
2714 as_type = AS_EXTERNAL;
2715 } else {
2716 /* Get AS number. */
2717 as = strtoul(as_str, NULL, 10);
2718 }
2719
2720 /* If peer is peer group, call proper function. */
2721 ret = str2sockunion(peer_str, &su);
2722 if (ret < 0) {
2723 /* Check for peer by interface */
2724 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2725 safi);
2726 if (ret < 0) {
2727 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2728 if (ret < 0) {
2729 vty_out(vty,
2730 "%% Create the peer-group or interface first\n");
2731 return CMD_WARNING_CONFIG_FAILED;
2732 }
2733 return CMD_SUCCESS;
2734 }
2735 } else {
2736 if (peer_address_self_check(bgp, &su)) {
2737 vty_out(vty,
2738 "%% Can not configure the local system as neighbor\n");
2739 return CMD_WARNING_CONFIG_FAILED;
2740 }
2741 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2742 }
2743
2744 /* This peer belongs to peer group. */
2745 switch (ret) {
2746 case BGP_ERR_PEER_GROUP_MEMBER:
2747 vty_out(vty,
2748 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2749 as);
2750 return CMD_WARNING_CONFIG_FAILED;
2751 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2752 vty_out(vty,
2753 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2754 as, as_str);
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757 return bgp_vty_return(vty, ret);
2758 }
2759
2760 DEFUN (bgp_default_shutdown,
2761 bgp_default_shutdown_cmd,
2762 "[no] bgp default shutdown",
2763 NO_STR
2764 BGP_STR
2765 "Configure BGP defaults\n"
2766 "Apply administrative shutdown to newly configured peers\n")
2767 {
2768 VTY_DECLVAR_CONTEXT(bgp, bgp);
2769 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2770 return CMD_SUCCESS;
2771 }
2772
2773 DEFUN (neighbor_remote_as,
2774 neighbor_remote_as_cmd,
2775 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2776 NEIGHBOR_STR
2777 NEIGHBOR_ADDR_STR2
2778 "Specify a BGP neighbor\n"
2779 AS_STR
2780 "Internal BGP peer\n"
2781 "External BGP peer\n")
2782 {
2783 int idx_peer = 1;
2784 int idx_remote_as = 3;
2785 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2786 argv[idx_remote_as]->arg, AFI_IP,
2787 SAFI_UNICAST);
2788 }
2789
2790 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2791 afi_t afi, safi_t safi, int v6only,
2792 const char *peer_group_name,
2793 const char *as_str)
2794 {
2795 VTY_DECLVAR_CONTEXT(bgp, bgp);
2796 as_t as = 0;
2797 int as_type = AS_UNSPECIFIED;
2798 struct peer *peer;
2799 struct peer_group *group;
2800 int ret = 0;
2801 union sockunion su;
2802
2803 group = peer_group_lookup(bgp, conf_if);
2804
2805 if (group) {
2806 vty_out(vty, "%% Name conflict with peer-group \n");
2807 return CMD_WARNING_CONFIG_FAILED;
2808 }
2809
2810 if (as_str) {
2811 if (as_str[0] == 'i') {
2812 as_type = AS_INTERNAL;
2813 } else if (as_str[0] == 'e') {
2814 as_type = AS_EXTERNAL;
2815 } else {
2816 /* Get AS number. */
2817 as = strtoul(as_str, NULL, 10);
2818 as_type = AS_SPECIFIED;
2819 }
2820 }
2821
2822 peer = peer_lookup_by_conf_if(bgp, conf_if);
2823 if (peer) {
2824 if (as_str)
2825 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2826 afi, safi);
2827 } else {
2828 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2829 && afi == AFI_IP && safi == SAFI_UNICAST)
2830 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2831 as_type, 0, 0, NULL);
2832 else
2833 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2834 as_type, afi, safi, NULL);
2835
2836 if (!peer) {
2837 vty_out(vty, "%% BGP failed to create peer\n");
2838 return CMD_WARNING_CONFIG_FAILED;
2839 }
2840
2841 if (v6only)
2842 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2843
2844 /* Request zebra to initiate IPv6 RAs on this interface. We do
2845 * this
2846 * any unnumbered peer in order to not worry about run-time
2847 * transitions
2848 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2849 * address
2850 * gets deleted later etc.)
2851 */
2852 if (peer->ifp)
2853 bgp_zebra_initiate_radv(bgp, peer);
2854 }
2855
2856 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2857 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2858 if (v6only)
2859 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2860 else
2861 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2862
2863 /* v6only flag changed. Reset bgp seesion */
2864 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2865 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2866 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2867 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2868 } else
2869 bgp_session_reset(peer);
2870 }
2871
2872 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2873 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2874 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2875 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2876 }
2877
2878 if (peer_group_name) {
2879 group = peer_group_lookup(bgp, peer_group_name);
2880 if (!group) {
2881 vty_out(vty, "%% Configure the peer-group first\n");
2882 return CMD_WARNING_CONFIG_FAILED;
2883 }
2884
2885 ret = peer_group_bind(bgp, &su, peer, group, &as);
2886 }
2887
2888 return bgp_vty_return(vty, ret);
2889 }
2890
2891 DEFUN (neighbor_interface_config,
2892 neighbor_interface_config_cmd,
2893 "neighbor WORD interface [peer-group WORD]",
2894 NEIGHBOR_STR
2895 "Interface name or neighbor tag\n"
2896 "Enable BGP on interface\n"
2897 "Member of the peer-group\n"
2898 "Peer-group name\n")
2899 {
2900 int idx_word = 1;
2901 int idx_peer_group_word = 4;
2902
2903 if (argc > idx_peer_group_word)
2904 return peer_conf_interface_get(
2905 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2906 argv[idx_peer_group_word]->arg, NULL);
2907 else
2908 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2909 SAFI_UNICAST, 0, NULL, NULL);
2910 }
2911
2912 DEFUN (neighbor_interface_config_v6only,
2913 neighbor_interface_config_v6only_cmd,
2914 "neighbor WORD interface v6only [peer-group WORD]",
2915 NEIGHBOR_STR
2916 "Interface name or neighbor tag\n"
2917 "Enable BGP on interface\n"
2918 "Enable BGP with v6 link-local only\n"
2919 "Member of the peer-group\n"
2920 "Peer-group name\n")
2921 {
2922 int idx_word = 1;
2923 int idx_peer_group_word = 5;
2924
2925 if (argc > idx_peer_group_word)
2926 return peer_conf_interface_get(
2927 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2928 argv[idx_peer_group_word]->arg, NULL);
2929
2930 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2931 SAFI_UNICAST, 1, NULL, NULL);
2932 }
2933
2934
2935 DEFUN (neighbor_interface_config_remote_as,
2936 neighbor_interface_config_remote_as_cmd,
2937 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2938 NEIGHBOR_STR
2939 "Interface name or neighbor tag\n"
2940 "Enable BGP on interface\n"
2941 "Specify a BGP neighbor\n"
2942 AS_STR
2943 "Internal BGP peer\n"
2944 "External BGP peer\n")
2945 {
2946 int idx_word = 1;
2947 int idx_remote_as = 4;
2948 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2949 SAFI_UNICAST, 0, NULL,
2950 argv[idx_remote_as]->arg);
2951 }
2952
2953 DEFUN (neighbor_interface_v6only_config_remote_as,
2954 neighbor_interface_v6only_config_remote_as_cmd,
2955 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2956 NEIGHBOR_STR
2957 "Interface name or neighbor tag\n"
2958 "Enable BGP with v6 link-local only\n"
2959 "Enable BGP on interface\n"
2960 "Specify a BGP neighbor\n"
2961 AS_STR
2962 "Internal BGP peer\n"
2963 "External BGP peer\n")
2964 {
2965 int idx_word = 1;
2966 int idx_remote_as = 5;
2967 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2968 SAFI_UNICAST, 1, NULL,
2969 argv[idx_remote_as]->arg);
2970 }
2971
2972 DEFUN (neighbor_peer_group,
2973 neighbor_peer_group_cmd,
2974 "neighbor WORD peer-group",
2975 NEIGHBOR_STR
2976 "Interface name or neighbor tag\n"
2977 "Configure peer-group\n")
2978 {
2979 VTY_DECLVAR_CONTEXT(bgp, bgp);
2980 int idx_word = 1;
2981 struct peer *peer;
2982 struct peer_group *group;
2983
2984 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2985 if (peer) {
2986 vty_out(vty, "%% Name conflict with interface: \n");
2987 return CMD_WARNING_CONFIG_FAILED;
2988 }
2989
2990 group = peer_group_get(bgp, argv[idx_word]->arg);
2991 if (!group) {
2992 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2993 return CMD_WARNING_CONFIG_FAILED;
2994 }
2995
2996 return CMD_SUCCESS;
2997 }
2998
2999 DEFUN (no_neighbor,
3000 no_neighbor_cmd,
3001 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3002 NO_STR
3003 NEIGHBOR_STR
3004 NEIGHBOR_ADDR_STR2
3005 "Specify a BGP neighbor\n"
3006 AS_STR
3007 "Internal BGP peer\n"
3008 "External BGP peer\n")
3009 {
3010 VTY_DECLVAR_CONTEXT(bgp, bgp);
3011 int idx_peer = 2;
3012 int ret;
3013 union sockunion su;
3014 struct peer_group *group;
3015 struct peer *peer;
3016 struct peer *other;
3017
3018 ret = str2sockunion(argv[idx_peer]->arg, &su);
3019 if (ret < 0) {
3020 /* look up for neighbor by interface name config. */
3021 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3022 if (peer) {
3023 /* Request zebra to terminate IPv6 RAs on this
3024 * interface. */
3025 if (peer->ifp)
3026 bgp_zebra_terminate_radv(peer->bgp, peer);
3027 peer_delete(peer);
3028 return CMD_SUCCESS;
3029 }
3030
3031 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3032 if (group)
3033 peer_group_delete(group);
3034 else {
3035 vty_out(vty, "%% Create the peer-group first\n");
3036 return CMD_WARNING_CONFIG_FAILED;
3037 }
3038 } else {
3039 peer = peer_lookup(bgp, &su);
3040 if (peer) {
3041 if (peer_dynamic_neighbor(peer)) {
3042 vty_out(vty,
3043 "%% Operation not allowed on a dynamic neighbor\n");
3044 return CMD_WARNING_CONFIG_FAILED;
3045 }
3046
3047 other = peer->doppelganger;
3048 peer_delete(peer);
3049 if (other && other->status != Deleted)
3050 peer_delete(other);
3051 }
3052 }
3053
3054 return CMD_SUCCESS;
3055 }
3056
3057 DEFUN (no_neighbor_interface_config,
3058 no_neighbor_interface_config_cmd,
3059 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3060 NO_STR
3061 NEIGHBOR_STR
3062 "Interface name\n"
3063 "Configure BGP on interface\n"
3064 "Enable BGP with v6 link-local only\n"
3065 "Member of the peer-group\n"
3066 "Peer-group name\n"
3067 "Specify a BGP neighbor\n"
3068 AS_STR
3069 "Internal BGP peer\n"
3070 "External BGP peer\n")
3071 {
3072 VTY_DECLVAR_CONTEXT(bgp, bgp);
3073 int idx_word = 2;
3074 struct peer *peer;
3075
3076 /* look up for neighbor by interface name config. */
3077 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3078 if (peer) {
3079 /* Request zebra to terminate IPv6 RAs on this interface. */
3080 if (peer->ifp)
3081 bgp_zebra_terminate_radv(peer->bgp, peer);
3082 peer_delete(peer);
3083 } else {
3084 vty_out(vty, "%% Create the bgp interface first\n");
3085 return CMD_WARNING_CONFIG_FAILED;
3086 }
3087 return CMD_SUCCESS;
3088 }
3089
3090 DEFUN (no_neighbor_peer_group,
3091 no_neighbor_peer_group_cmd,
3092 "no neighbor WORD peer-group",
3093 NO_STR
3094 NEIGHBOR_STR
3095 "Neighbor tag\n"
3096 "Configure peer-group\n")
3097 {
3098 VTY_DECLVAR_CONTEXT(bgp, bgp);
3099 int idx_word = 2;
3100 struct peer_group *group;
3101
3102 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3103 if (group)
3104 peer_group_delete(group);
3105 else {
3106 vty_out(vty, "%% Create the peer-group first\n");
3107 return CMD_WARNING_CONFIG_FAILED;
3108 }
3109 return CMD_SUCCESS;
3110 }
3111
3112 DEFUN (no_neighbor_interface_peer_group_remote_as,
3113 no_neighbor_interface_peer_group_remote_as_cmd,
3114 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3115 NO_STR
3116 NEIGHBOR_STR
3117 "Interface name or neighbor tag\n"
3118 "Specify a BGP neighbor\n"
3119 AS_STR
3120 "Internal BGP peer\n"
3121 "External BGP peer\n")
3122 {
3123 VTY_DECLVAR_CONTEXT(bgp, bgp);
3124 int idx_word = 2;
3125 struct peer_group *group;
3126 struct peer *peer;
3127
3128 /* look up for neighbor by interface name config. */
3129 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3130 if (peer) {
3131 peer_as_change(peer, 0, AS_SPECIFIED);
3132 return CMD_SUCCESS;
3133 }
3134
3135 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3136 if (group)
3137 peer_group_remote_as_delete(group);
3138 else {
3139 vty_out(vty, "%% Create the peer-group or interface first\n");
3140 return CMD_WARNING_CONFIG_FAILED;
3141 }
3142 return CMD_SUCCESS;
3143 }
3144
3145 DEFUN (neighbor_local_as,
3146 neighbor_local_as_cmd,
3147 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3148 NEIGHBOR_STR
3149 NEIGHBOR_ADDR_STR2
3150 "Specify a local-as number\n"
3151 "AS number used as local AS\n")
3152 {
3153 int idx_peer = 1;
3154 int idx_number = 3;
3155 struct peer *peer;
3156 int ret;
3157 as_t as;
3158
3159 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3160 if (!peer)
3161 return CMD_WARNING_CONFIG_FAILED;
3162
3163 as = strtoul(argv[idx_number]->arg, NULL, 10);
3164 ret = peer_local_as_set(peer, as, 0, 0);
3165 return bgp_vty_return(vty, ret);
3166 }
3167
3168 DEFUN (neighbor_local_as_no_prepend,
3169 neighbor_local_as_no_prepend_cmd,
3170 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3171 NEIGHBOR_STR
3172 NEIGHBOR_ADDR_STR2
3173 "Specify a local-as number\n"
3174 "AS number used as local AS\n"
3175 "Do not prepend local-as to updates from ebgp peers\n")
3176 {
3177 int idx_peer = 1;
3178 int idx_number = 3;
3179 struct peer *peer;
3180 int ret;
3181 as_t as;
3182
3183 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3184 if (!peer)
3185 return CMD_WARNING_CONFIG_FAILED;
3186
3187 as = strtoul(argv[idx_number]->arg, NULL, 10);
3188 ret = peer_local_as_set(peer, as, 1, 0);
3189 return bgp_vty_return(vty, ret);
3190 }
3191
3192 DEFUN (neighbor_local_as_no_prepend_replace_as,
3193 neighbor_local_as_no_prepend_replace_as_cmd,
3194 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3195 NEIGHBOR_STR
3196 NEIGHBOR_ADDR_STR2
3197 "Specify a local-as number\n"
3198 "AS number used as local AS\n"
3199 "Do not prepend local-as to updates from ebgp peers\n"
3200 "Do not prepend local-as to updates from ibgp peers\n")
3201 {
3202 int idx_peer = 1;
3203 int idx_number = 3;
3204 struct peer *peer;
3205 int ret;
3206 as_t as;
3207
3208 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3209 if (!peer)
3210 return CMD_WARNING_CONFIG_FAILED;
3211
3212 as = strtoul(argv[idx_number]->arg, NULL, 10);
3213 ret = peer_local_as_set(peer, as, 1, 1);
3214 return bgp_vty_return(vty, ret);
3215 }
3216
3217 DEFUN (no_neighbor_local_as,
3218 no_neighbor_local_as_cmd,
3219 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3220 NO_STR
3221 NEIGHBOR_STR
3222 NEIGHBOR_ADDR_STR2
3223 "Specify a local-as number\n"
3224 "AS number used as local AS\n"
3225 "Do not prepend local-as to updates from ebgp peers\n"
3226 "Do not prepend local-as to updates from ibgp peers\n")
3227 {
3228 int idx_peer = 2;
3229 struct peer *peer;
3230 int ret;
3231
3232 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3233 if (!peer)
3234 return CMD_WARNING_CONFIG_FAILED;
3235
3236 ret = peer_local_as_unset(peer);
3237 return bgp_vty_return(vty, ret);
3238 }
3239
3240
3241 DEFUN (neighbor_solo,
3242 neighbor_solo_cmd,
3243 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3244 NEIGHBOR_STR
3245 NEIGHBOR_ADDR_STR2
3246 "Solo peer - part of its own update group\n")
3247 {
3248 int idx_peer = 1;
3249 struct peer *peer;
3250 int ret;
3251
3252 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3253 if (!peer)
3254 return CMD_WARNING_CONFIG_FAILED;
3255
3256 ret = update_group_adjust_soloness(peer, 1);
3257 return bgp_vty_return(vty, ret);
3258 }
3259
3260 DEFUN (no_neighbor_solo,
3261 no_neighbor_solo_cmd,
3262 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3263 NO_STR
3264 NEIGHBOR_STR
3265 NEIGHBOR_ADDR_STR2
3266 "Solo peer - part of its own update group\n")
3267 {
3268 int idx_peer = 2;
3269 struct peer *peer;
3270 int ret;
3271
3272 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3273 if (!peer)
3274 return CMD_WARNING_CONFIG_FAILED;
3275
3276 ret = update_group_adjust_soloness(peer, 0);
3277 return bgp_vty_return(vty, ret);
3278 }
3279
3280 DEFUN (neighbor_password,
3281 neighbor_password_cmd,
3282 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3283 NEIGHBOR_STR
3284 NEIGHBOR_ADDR_STR2
3285 "Set a password\n"
3286 "The password\n")
3287 {
3288 int idx_peer = 1;
3289 int idx_line = 3;
3290 struct peer *peer;
3291 int ret;
3292
3293 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3294 if (!peer)
3295 return CMD_WARNING_CONFIG_FAILED;
3296
3297 ret = peer_password_set(peer, argv[idx_line]->arg);
3298 return bgp_vty_return(vty, ret);
3299 }
3300
3301 DEFUN (no_neighbor_password,
3302 no_neighbor_password_cmd,
3303 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3304 NO_STR
3305 NEIGHBOR_STR
3306 NEIGHBOR_ADDR_STR2
3307 "Set a password\n"
3308 "The password\n")
3309 {
3310 int idx_peer = 2;
3311 struct peer *peer;
3312 int ret;
3313
3314 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3315 if (!peer)
3316 return CMD_WARNING_CONFIG_FAILED;
3317
3318 ret = peer_password_unset(peer);
3319 return bgp_vty_return(vty, ret);
3320 }
3321
3322 DEFUN (neighbor_activate,
3323 neighbor_activate_cmd,
3324 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3325 NEIGHBOR_STR
3326 NEIGHBOR_ADDR_STR2
3327 "Enable the Address Family for this Neighbor\n")
3328 {
3329 int idx_peer = 1;
3330 int ret;
3331 struct peer *peer;
3332
3333 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3334 if (!peer)
3335 return CMD_WARNING_CONFIG_FAILED;
3336
3337 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3338 return bgp_vty_return(vty, ret);
3339 }
3340
3341 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3342 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3343 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3344 "Enable the Address Family for this Neighbor\n")
3345
3346 DEFUN (no_neighbor_activate,
3347 no_neighbor_activate_cmd,
3348 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3349 NO_STR
3350 NEIGHBOR_STR
3351 NEIGHBOR_ADDR_STR2
3352 "Enable the Address Family for this Neighbor\n")
3353 {
3354 int idx_peer = 2;
3355 int ret;
3356 struct peer *peer;
3357
3358 /* Lookup peer. */
3359 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3360 if (!peer)
3361 return CMD_WARNING_CONFIG_FAILED;
3362
3363 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3364 return bgp_vty_return(vty, ret);
3365 }
3366
3367 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3368 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3369 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3370 "Enable the Address Family for this Neighbor\n")
3371
3372 DEFUN (neighbor_set_peer_group,
3373 neighbor_set_peer_group_cmd,
3374 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3375 NEIGHBOR_STR
3376 NEIGHBOR_ADDR_STR2
3377 "Member of the peer-group\n"
3378 "Peer-group name\n")
3379 {
3380 VTY_DECLVAR_CONTEXT(bgp, bgp);
3381 int idx_peer = 1;
3382 int idx_word = 3;
3383 int ret;
3384 as_t as;
3385 union sockunion su;
3386 struct peer *peer;
3387 struct peer_group *group;
3388
3389 ret = str2sockunion(argv[idx_peer]->arg, &su);
3390 if (ret < 0) {
3391 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3392 if (!peer) {
3393 vty_out(vty, "%% Malformed address or name: %s\n",
3394 argv[idx_peer]->arg);
3395 return CMD_WARNING_CONFIG_FAILED;
3396 }
3397 } else {
3398 if (peer_address_self_check(bgp, &su)) {
3399 vty_out(vty,
3400 "%% Can not configure the local system as neighbor\n");
3401 return CMD_WARNING_CONFIG_FAILED;
3402 }
3403
3404 /* Disallow for dynamic neighbor. */
3405 peer = peer_lookup(bgp, &su);
3406 if (peer && peer_dynamic_neighbor(peer)) {
3407 vty_out(vty,
3408 "%% Operation not allowed on a dynamic neighbor\n");
3409 return CMD_WARNING_CONFIG_FAILED;
3410 }
3411 }
3412
3413 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3414 if (!group) {
3415 vty_out(vty, "%% Configure the peer-group first\n");
3416 return CMD_WARNING_CONFIG_FAILED;
3417 }
3418
3419 ret = peer_group_bind(bgp, &su, peer, group, &as);
3420
3421 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3422 vty_out(vty,
3423 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3424 as);
3425 return CMD_WARNING_CONFIG_FAILED;
3426 }
3427
3428 return bgp_vty_return(vty, ret);
3429 }
3430
3431 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3432 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3433 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3434 "Member of the peer-group\n"
3435 "Peer-group name\n")
3436
3437 DEFUN (no_neighbor_set_peer_group,
3438 no_neighbor_set_peer_group_cmd,
3439 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3440 NO_STR
3441 NEIGHBOR_STR
3442 NEIGHBOR_ADDR_STR2
3443 "Member of the peer-group\n"
3444 "Peer-group name\n")
3445 {
3446 VTY_DECLVAR_CONTEXT(bgp, bgp);
3447 int idx_peer = 2;
3448 int idx_word = 4;
3449 int ret;
3450 struct peer *peer;
3451 struct peer_group *group;
3452
3453 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3454 if (!peer)
3455 return CMD_WARNING_CONFIG_FAILED;
3456
3457 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3458 if (!group) {
3459 vty_out(vty, "%% Configure the peer-group first\n");
3460 return CMD_WARNING_CONFIG_FAILED;
3461 }
3462
3463 ret = peer_delete(peer);
3464
3465 return bgp_vty_return(vty, ret);
3466 }
3467
3468 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3469 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3470 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3471 "Member of the peer-group\n"
3472 "Peer-group name\n")
3473
3474 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3475 uint32_t flag, int set)
3476 {
3477 int ret;
3478 struct peer *peer;
3479
3480 peer = peer_and_group_lookup_vty(vty, ip_str);
3481 if (!peer)
3482 return CMD_WARNING_CONFIG_FAILED;
3483
3484 /*
3485 * If 'neighbor <interface>', then this is for directly connected peers,
3486 * we should not accept disable-connected-check.
3487 */
3488 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3489 vty_out(vty,
3490 "%s is directly connected peer, cannot accept disable-"
3491 "connected-check\n",
3492 ip_str);
3493 return CMD_WARNING_CONFIG_FAILED;
3494 }
3495
3496 if (!set && flag == PEER_FLAG_SHUTDOWN)
3497 peer_tx_shutdown_message_unset(peer);
3498
3499 if (set)
3500 ret = peer_flag_set(peer, flag);
3501 else
3502 ret = peer_flag_unset(peer, flag);
3503
3504 return bgp_vty_return(vty, ret);
3505 }
3506
3507 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3508 {
3509 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3510 }
3511
3512 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3513 uint32_t flag)
3514 {
3515 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3516 }
3517
3518 /* neighbor passive. */
3519 DEFUN (neighbor_passive,
3520 neighbor_passive_cmd,
3521 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3522 NEIGHBOR_STR
3523 NEIGHBOR_ADDR_STR2
3524 "Don't send open messages to this neighbor\n")
3525 {
3526 int idx_peer = 1;
3527 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3528 }
3529
3530 DEFUN (no_neighbor_passive,
3531 no_neighbor_passive_cmd,
3532 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3533 NO_STR
3534 NEIGHBOR_STR
3535 NEIGHBOR_ADDR_STR2
3536 "Don't send open messages to this neighbor\n")
3537 {
3538 int idx_peer = 2;
3539 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3540 }
3541
3542 /* neighbor shutdown. */
3543 DEFUN (neighbor_shutdown_msg,
3544 neighbor_shutdown_msg_cmd,
3545 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3546 NEIGHBOR_STR
3547 NEIGHBOR_ADDR_STR2
3548 "Administratively shut down this neighbor\n"
3549 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3550 "Shutdown message\n")
3551 {
3552 int idx_peer = 1;
3553
3554 if (argc >= 5) {
3555 struct peer *peer =
3556 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3557 char *message;
3558
3559 if (!peer)
3560 return CMD_WARNING_CONFIG_FAILED;
3561 message = argv_concat(argv, argc, 4);
3562 peer_tx_shutdown_message_set(peer, message);
3563 XFREE(MTYPE_TMP, message);
3564 }
3565
3566 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3567 }
3568
3569 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3570 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3571 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3572 "Administratively shut down this neighbor\n")
3573
3574 DEFUN (no_neighbor_shutdown_msg,
3575 no_neighbor_shutdown_msg_cmd,
3576 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3577 NO_STR
3578 NEIGHBOR_STR
3579 NEIGHBOR_ADDR_STR2
3580 "Administratively shut down this neighbor\n"
3581 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3582 "Shutdown message\n")
3583 {
3584 int idx_peer = 2;
3585
3586 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3587 PEER_FLAG_SHUTDOWN);
3588 }
3589
3590 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3591 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3592 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3593 "Administratively shut down this neighbor\n")
3594
3595 /* neighbor capability dynamic. */
3596 DEFUN (neighbor_capability_dynamic,
3597 neighbor_capability_dynamic_cmd,
3598 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3599 NEIGHBOR_STR
3600 NEIGHBOR_ADDR_STR2
3601 "Advertise capability to the peer\n"
3602 "Advertise dynamic capability to this neighbor\n")
3603 {
3604 int idx_peer = 1;
3605 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3606 PEER_FLAG_DYNAMIC_CAPABILITY);
3607 }
3608
3609 DEFUN (no_neighbor_capability_dynamic,
3610 no_neighbor_capability_dynamic_cmd,
3611 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3612 NO_STR
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 = 2;
3619 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3620 PEER_FLAG_DYNAMIC_CAPABILITY);
3621 }
3622
3623 /* neighbor dont-capability-negotiate */
3624 DEFUN (neighbor_dont_capability_negotiate,
3625 neighbor_dont_capability_negotiate_cmd,
3626 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3627 NEIGHBOR_STR
3628 NEIGHBOR_ADDR_STR2
3629 "Do not perform capability negotiation\n")
3630 {
3631 int idx_peer = 1;
3632 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3633 PEER_FLAG_DONT_CAPABILITY);
3634 }
3635
3636 DEFUN (no_neighbor_dont_capability_negotiate,
3637 no_neighbor_dont_capability_negotiate_cmd,
3638 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3639 NO_STR
3640 NEIGHBOR_STR
3641 NEIGHBOR_ADDR_STR2
3642 "Do not perform capability negotiation\n")
3643 {
3644 int idx_peer = 2;
3645 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3646 PEER_FLAG_DONT_CAPABILITY);
3647 }
3648
3649 /* neighbor capability extended next hop encoding */
3650 DEFUN (neighbor_capability_enhe,
3651 neighbor_capability_enhe_cmd,
3652 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3653 NEIGHBOR_STR
3654 NEIGHBOR_ADDR_STR2
3655 "Advertise capability to the peer\n"
3656 "Advertise extended next-hop capability to the peer\n")
3657 {
3658 int idx_peer = 1;
3659 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3660 PEER_FLAG_CAPABILITY_ENHE);
3661 }
3662
3663 DEFUN (no_neighbor_capability_enhe,
3664 no_neighbor_capability_enhe_cmd,
3665 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3666 NO_STR
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 = 2;
3673 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3674 PEER_FLAG_CAPABILITY_ENHE);
3675 }
3676
3677 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3678 afi_t afi, safi_t safi, uint32_t flag,
3679 int set)
3680 {
3681 int ret;
3682 struct peer *peer;
3683
3684 peer = peer_and_group_lookup_vty(vty, peer_str);
3685 if (!peer)
3686 return CMD_WARNING_CONFIG_FAILED;
3687
3688 if (set)
3689 ret = peer_af_flag_set(peer, afi, safi, flag);
3690 else
3691 ret = peer_af_flag_unset(peer, afi, safi, flag);
3692
3693 return bgp_vty_return(vty, ret);
3694 }
3695
3696 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3697 afi_t afi, safi_t safi, uint32_t flag)
3698 {
3699 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3700 }
3701
3702 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3703 afi_t afi, safi_t safi, uint32_t flag)
3704 {
3705 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3706 }
3707
3708 /* neighbor capability orf prefix-list. */
3709 DEFUN (neighbor_capability_orf_prefix,
3710 neighbor_capability_orf_prefix_cmd,
3711 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3712 NEIGHBOR_STR
3713 NEIGHBOR_ADDR_STR2
3714 "Advertise capability to the peer\n"
3715 "Advertise ORF capability to the peer\n"
3716 "Advertise prefixlist ORF capability to this neighbor\n"
3717 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3718 "Capability to RECEIVE the ORF from this neighbor\n"
3719 "Capability to SEND the ORF to this neighbor\n")
3720 {
3721 int idx_peer = 1;
3722 int idx_send_recv = 5;
3723 uint16_t flag = 0;
3724
3725 if (strmatch(argv[idx_send_recv]->text, "send"))
3726 flag = PEER_FLAG_ORF_PREFIX_SM;
3727 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3728 flag = PEER_FLAG_ORF_PREFIX_RM;
3729 else if (strmatch(argv[idx_send_recv]->text, "both"))
3730 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3731 else {
3732 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3733 return CMD_WARNING_CONFIG_FAILED;
3734 }
3735
3736 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3737 bgp_node_safi(vty), flag);
3738 }
3739
3740 ALIAS_HIDDEN(
3741 neighbor_capability_orf_prefix,
3742 neighbor_capability_orf_prefix_hidden_cmd,
3743 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3744 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3745 "Advertise capability to the peer\n"
3746 "Advertise ORF capability to the peer\n"
3747 "Advertise prefixlist ORF capability to this neighbor\n"
3748 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3749 "Capability to RECEIVE the ORF from this neighbor\n"
3750 "Capability to SEND the ORF to this neighbor\n")
3751
3752 DEFUN (no_neighbor_capability_orf_prefix,
3753 no_neighbor_capability_orf_prefix_cmd,
3754 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3755 NO_STR
3756 NEIGHBOR_STR
3757 NEIGHBOR_ADDR_STR2
3758 "Advertise capability to the peer\n"
3759 "Advertise ORF capability to the peer\n"
3760 "Advertise prefixlist ORF capability to this neighbor\n"
3761 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3762 "Capability to RECEIVE the ORF from this neighbor\n"
3763 "Capability to SEND the ORF to this neighbor\n")
3764 {
3765 int idx_peer = 2;
3766 int idx_send_recv = 6;
3767 uint16_t flag = 0;
3768
3769 if (strmatch(argv[idx_send_recv]->text, "send"))
3770 flag = PEER_FLAG_ORF_PREFIX_SM;
3771 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3772 flag = PEER_FLAG_ORF_PREFIX_RM;
3773 else if (strmatch(argv[idx_send_recv]->text, "both"))
3774 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3775 else {
3776 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3777 return CMD_WARNING_CONFIG_FAILED;
3778 }
3779
3780 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3781 bgp_node_afi(vty), bgp_node_safi(vty),
3782 flag);
3783 }
3784
3785 ALIAS_HIDDEN(
3786 no_neighbor_capability_orf_prefix,
3787 no_neighbor_capability_orf_prefix_hidden_cmd,
3788 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3789 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3790 "Advertise capability to the peer\n"
3791 "Advertise ORF capability to the peer\n"
3792 "Advertise prefixlist ORF capability to this neighbor\n"
3793 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3794 "Capability to RECEIVE the ORF from this neighbor\n"
3795 "Capability to SEND the ORF to this neighbor\n")
3796
3797 /* neighbor next-hop-self. */
3798 DEFUN (neighbor_nexthop_self,
3799 neighbor_nexthop_self_cmd,
3800 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3801 NEIGHBOR_STR
3802 NEIGHBOR_ADDR_STR2
3803 "Disable the next hop calculation for this neighbor\n")
3804 {
3805 int idx_peer = 1;
3806 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3807 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3808 }
3809
3810 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3811 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3813 "Disable the next hop calculation for this neighbor\n")
3814
3815 /* neighbor next-hop-self. */
3816 DEFUN (neighbor_nexthop_self_force,
3817 neighbor_nexthop_self_force_cmd,
3818 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3819 NEIGHBOR_STR
3820 NEIGHBOR_ADDR_STR2
3821 "Disable the next hop calculation for this neighbor\n"
3822 "Set the next hop to self for reflected routes\n")
3823 {
3824 int idx_peer = 1;
3825 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3826 bgp_node_safi(vty),
3827 PEER_FLAG_FORCE_NEXTHOP_SELF);
3828 }
3829
3830 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3831 neighbor_nexthop_self_force_hidden_cmd,
3832 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3833 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3834 "Disable the next hop calculation for this neighbor\n"
3835 "Set the next hop to self for reflected routes\n")
3836
3837 DEFUN (no_neighbor_nexthop_self,
3838 no_neighbor_nexthop_self_cmd,
3839 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3840 NO_STR
3841 NEIGHBOR_STR
3842 NEIGHBOR_ADDR_STR2
3843 "Disable the next hop calculation for this neighbor\n")
3844 {
3845 int idx_peer = 2;
3846 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3847 bgp_node_afi(vty), bgp_node_safi(vty),
3848 PEER_FLAG_NEXTHOP_SELF);
3849 }
3850
3851 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3852 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3853 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3854 "Disable the next hop calculation for this neighbor\n")
3855
3856 DEFUN (no_neighbor_nexthop_self_force,
3857 no_neighbor_nexthop_self_force_cmd,
3858 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3859 NO_STR
3860 NEIGHBOR_STR
3861 NEIGHBOR_ADDR_STR2
3862 "Disable the next hop calculation for this neighbor\n"
3863 "Set the next hop to self for reflected routes\n")
3864 {
3865 int idx_peer = 2;
3866 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3867 bgp_node_afi(vty), bgp_node_safi(vty),
3868 PEER_FLAG_FORCE_NEXTHOP_SELF);
3869 }
3870
3871 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3872 no_neighbor_nexthop_self_force_hidden_cmd,
3873 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3874 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3875 "Disable the next hop calculation for this neighbor\n"
3876 "Set the next hop to self for reflected routes\n")
3877
3878 /* neighbor as-override */
3879 DEFUN (neighbor_as_override,
3880 neighbor_as_override_cmd,
3881 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3882 NEIGHBOR_STR
3883 NEIGHBOR_ADDR_STR2
3884 "Override ASNs in outbound updates if aspath equals remote-as\n")
3885 {
3886 int idx_peer = 1;
3887 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3888 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3889 }
3890
3891 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3892 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3893 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3894 "Override ASNs in outbound updates if aspath equals remote-as\n")
3895
3896 DEFUN (no_neighbor_as_override,
3897 no_neighbor_as_override_cmd,
3898 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3899 NO_STR
3900 NEIGHBOR_STR
3901 NEIGHBOR_ADDR_STR2
3902 "Override ASNs in outbound updates if aspath equals remote-as\n")
3903 {
3904 int idx_peer = 2;
3905 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3906 bgp_node_afi(vty), bgp_node_safi(vty),
3907 PEER_FLAG_AS_OVERRIDE);
3908 }
3909
3910 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3911 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3912 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3913 "Override ASNs in outbound updates if aspath equals remote-as\n")
3914
3915 /* neighbor remove-private-AS. */
3916 DEFUN (neighbor_remove_private_as,
3917 neighbor_remove_private_as_cmd,
3918 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3919 NEIGHBOR_STR
3920 NEIGHBOR_ADDR_STR2
3921 "Remove private ASNs in outbound updates\n")
3922 {
3923 int idx_peer = 1;
3924 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3925 bgp_node_safi(vty),
3926 PEER_FLAG_REMOVE_PRIVATE_AS);
3927 }
3928
3929 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3930 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3931 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3932 "Remove private ASNs in outbound updates\n")
3933
3934 DEFUN (neighbor_remove_private_as_all,
3935 neighbor_remove_private_as_all_cmd,
3936 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3937 NEIGHBOR_STR
3938 NEIGHBOR_ADDR_STR2
3939 "Remove private ASNs in outbound updates\n"
3940 "Apply to all AS numbers\n")
3941 {
3942 int idx_peer = 1;
3943 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3944 bgp_node_safi(vty),
3945 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3946 }
3947
3948 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3949 neighbor_remove_private_as_all_hidden_cmd,
3950 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3951 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3952 "Remove private ASNs in outbound updates\n"
3953 "Apply to all AS numbers")
3954
3955 DEFUN (neighbor_remove_private_as_replace_as,
3956 neighbor_remove_private_as_replace_as_cmd,
3957 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3958 NEIGHBOR_STR
3959 NEIGHBOR_ADDR_STR2
3960 "Remove private ASNs in outbound updates\n"
3961 "Replace private ASNs with our ASN in outbound updates\n")
3962 {
3963 int idx_peer = 1;
3964 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3965 bgp_node_safi(vty),
3966 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3967 }
3968
3969 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3970 neighbor_remove_private_as_replace_as_hidden_cmd,
3971 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3972 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
3974 "Replace private ASNs with our ASN in outbound updates\n")
3975
3976 DEFUN (neighbor_remove_private_as_all_replace_as,
3977 neighbor_remove_private_as_all_replace_as_cmd,
3978 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3979 NEIGHBOR_STR
3980 NEIGHBOR_ADDR_STR2
3981 "Remove private ASNs in outbound updates\n"
3982 "Apply to all AS numbers\n"
3983 "Replace private ASNs with our ASN in outbound updates\n")
3984 {
3985 int idx_peer = 1;
3986 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3987 bgp_node_safi(vty),
3988 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3989 }
3990
3991 ALIAS_HIDDEN(
3992 neighbor_remove_private_as_all_replace_as,
3993 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3994 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3995 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3996 "Remove private ASNs in outbound updates\n"
3997 "Apply to all AS numbers\n"
3998 "Replace private ASNs with our ASN in outbound updates\n")
3999
4000 DEFUN (no_neighbor_remove_private_as,
4001 no_neighbor_remove_private_as_cmd,
4002 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4003 NO_STR
4004 NEIGHBOR_STR
4005 NEIGHBOR_ADDR_STR2
4006 "Remove private ASNs in outbound updates\n")
4007 {
4008 int idx_peer = 2;
4009 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4010 bgp_node_afi(vty), bgp_node_safi(vty),
4011 PEER_FLAG_REMOVE_PRIVATE_AS);
4012 }
4013
4014 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4015 no_neighbor_remove_private_as_hidden_cmd,
4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4017 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n")
4019
4020 DEFUN (no_neighbor_remove_private_as_all,
4021 no_neighbor_remove_private_as_all_cmd,
4022 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4023 NO_STR
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Remove private ASNs in outbound updates\n"
4027 "Apply to all AS numbers\n")
4028 {
4029 int idx_peer = 2;
4030 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4031 bgp_node_afi(vty), bgp_node_safi(vty),
4032 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4033 }
4034
4035 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4036 no_neighbor_remove_private_as_all_hidden_cmd,
4037 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4038 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4039 "Remove private ASNs in outbound updates\n"
4040 "Apply to all AS numbers\n")
4041
4042 DEFUN (no_neighbor_remove_private_as_replace_as,
4043 no_neighbor_remove_private_as_replace_as_cmd,
4044 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4045 NO_STR
4046 NEIGHBOR_STR
4047 NEIGHBOR_ADDR_STR2
4048 "Remove private ASNs in outbound updates\n"
4049 "Replace private ASNs with our ASN in outbound updates\n")
4050 {
4051 int idx_peer = 2;
4052 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4053 bgp_node_afi(vty), bgp_node_safi(vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4055 }
4056
4057 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4058 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4059 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4060 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4061 "Remove private ASNs in outbound updates\n"
4062 "Replace private ASNs with our ASN in outbound updates\n")
4063
4064 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4065 no_neighbor_remove_private_as_all_replace_as_cmd,
4066 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4067 NO_STR
4068 NEIGHBOR_STR
4069 NEIGHBOR_ADDR_STR2
4070 "Remove private ASNs in outbound updates\n"
4071 "Apply to all AS numbers\n"
4072 "Replace private ASNs with our ASN in outbound updates\n")
4073 {
4074 int idx_peer = 2;
4075 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4076 bgp_node_afi(vty), bgp_node_safi(vty),
4077 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4078 }
4079
4080 ALIAS_HIDDEN(
4081 no_neighbor_remove_private_as_all_replace_as,
4082 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4083 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4084 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4085 "Remove private ASNs in outbound updates\n"
4086 "Apply to all AS numbers\n"
4087 "Replace private ASNs with our ASN in outbound updates\n")
4088
4089
4090 /* neighbor send-community. */
4091 DEFUN (neighbor_send_community,
4092 neighbor_send_community_cmd,
4093 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4094 NEIGHBOR_STR
4095 NEIGHBOR_ADDR_STR2
4096 "Send Community attribute to this neighbor\n")
4097 {
4098 int idx_peer = 1;
4099
4100 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4101 bgp_node_safi(vty),
4102 PEER_FLAG_SEND_COMMUNITY);
4103 }
4104
4105 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4106 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4107 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4108 "Send Community attribute to this neighbor\n")
4109
4110 DEFUN (no_neighbor_send_community,
4111 no_neighbor_send_community_cmd,
4112 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4113 NO_STR
4114 NEIGHBOR_STR
4115 NEIGHBOR_ADDR_STR2
4116 "Send Community attribute to this neighbor\n")
4117 {
4118 int idx_peer = 2;
4119
4120 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4121 bgp_node_afi(vty), bgp_node_safi(vty),
4122 PEER_FLAG_SEND_COMMUNITY);
4123 }
4124
4125 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4126 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4127 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4128 "Send Community attribute to this neighbor\n")
4129
4130 /* neighbor send-community extended. */
4131 DEFUN (neighbor_send_community_type,
4132 neighbor_send_community_type_cmd,
4133 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4134 NEIGHBOR_STR
4135 NEIGHBOR_ADDR_STR2
4136 "Send Community attribute to this neighbor\n"
4137 "Send Standard and Extended Community attributes\n"
4138 "Send Standard, Large and Extended Community attributes\n"
4139 "Send Extended Community attributes\n"
4140 "Send Standard Community attributes\n"
4141 "Send Large Community attributes\n")
4142 {
4143 int idx_peer = 1;
4144 uint32_t flag = 0;
4145 const char *type = argv[argc - 1]->text;
4146
4147 if (strmatch(type, "standard")) {
4148 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4149 } else if (strmatch(type, "extended")) {
4150 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4151 } else if (strmatch(type, "large")) {
4152 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4153 } else if (strmatch(type, "both")) {
4154 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4155 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4156 } else { /* if (strmatch(type, "all")) */
4157 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4158 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4159 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4160 }
4161
4162 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4163 bgp_node_safi(vty), flag);
4164 }
4165
4166 ALIAS_HIDDEN(
4167 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4168 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4169 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4170 "Send Community attribute to this neighbor\n"
4171 "Send Standard and Extended Community attributes\n"
4172 "Send Standard, Large and Extended Community attributes\n"
4173 "Send Extended Community attributes\n"
4174 "Send Standard Community attributes\n"
4175 "Send Large Community attributes\n")
4176
4177 DEFUN (no_neighbor_send_community_type,
4178 no_neighbor_send_community_type_cmd,
4179 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4180 NO_STR
4181 NEIGHBOR_STR
4182 NEIGHBOR_ADDR_STR2
4183 "Send Community attribute to this neighbor\n"
4184 "Send Standard and Extended Community attributes\n"
4185 "Send Standard, Large and Extended Community attributes\n"
4186 "Send Extended Community attributes\n"
4187 "Send Standard Community attributes\n"
4188 "Send Large Community attributes\n")
4189 {
4190 int idx_peer = 2;
4191 uint32_t flag = 0;
4192 const char *type = argv[argc - 1]->text;
4193
4194 if (strmatch(type, "standard")) {
4195 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4196 } else if (strmatch(type, "extended")) {
4197 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4198 } else if (strmatch(type, "large")) {
4199 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4200 } else if (strmatch(type, "both")) {
4201 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4202 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4203 } else { /* if (strmatch(type, "all")) */
4204 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4205 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4206 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4207 }
4208
4209 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4210 bgp_node_afi(vty), bgp_node_safi(vty),
4211 flag);
4212 }
4213
4214 ALIAS_HIDDEN(
4215 no_neighbor_send_community_type,
4216 no_neighbor_send_community_type_hidden_cmd,
4217 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4218 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4219 "Send Community attribute to this neighbor\n"
4220 "Send Standard and Extended Community attributes\n"
4221 "Send Standard, Large and Extended Community attributes\n"
4222 "Send Extended Community attributes\n"
4223 "Send Standard Community attributes\n"
4224 "Send Large Community attributes\n")
4225
4226 /* neighbor soft-reconfig. */
4227 DEFUN (neighbor_soft_reconfiguration,
4228 neighbor_soft_reconfiguration_cmd,
4229 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4230 NEIGHBOR_STR
4231 NEIGHBOR_ADDR_STR2
4232 "Per neighbor soft reconfiguration\n"
4233 "Allow inbound soft reconfiguration for this neighbor\n")
4234 {
4235 int idx_peer = 1;
4236 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4237 bgp_node_safi(vty),
4238 PEER_FLAG_SOFT_RECONFIG);
4239 }
4240
4241 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4242 neighbor_soft_reconfiguration_hidden_cmd,
4243 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4244 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4245 "Per neighbor soft reconfiguration\n"
4246 "Allow inbound soft reconfiguration for this neighbor\n")
4247
4248 DEFUN (no_neighbor_soft_reconfiguration,
4249 no_neighbor_soft_reconfiguration_cmd,
4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4251 NO_STR
4252 NEIGHBOR_STR
4253 NEIGHBOR_ADDR_STR2
4254 "Per neighbor soft reconfiguration\n"
4255 "Allow inbound soft reconfiguration for this neighbor\n")
4256 {
4257 int idx_peer = 2;
4258 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4259 bgp_node_afi(vty), bgp_node_safi(vty),
4260 PEER_FLAG_SOFT_RECONFIG);
4261 }
4262
4263 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4264 no_neighbor_soft_reconfiguration_hidden_cmd,
4265 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4266 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4267 "Per neighbor soft reconfiguration\n"
4268 "Allow inbound soft reconfiguration for this neighbor\n")
4269
4270 DEFUN (neighbor_route_reflector_client,
4271 neighbor_route_reflector_client_cmd,
4272 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4273 NEIGHBOR_STR
4274 NEIGHBOR_ADDR_STR2
4275 "Configure a neighbor as Route Reflector client\n")
4276 {
4277 int idx_peer = 1;
4278 struct peer *peer;
4279
4280
4281 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4282 if (!peer)
4283 return CMD_WARNING_CONFIG_FAILED;
4284
4285 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4286 bgp_node_safi(vty),
4287 PEER_FLAG_REFLECTOR_CLIENT);
4288 }
4289
4290 ALIAS_HIDDEN(neighbor_route_reflector_client,
4291 neighbor_route_reflector_client_hidden_cmd,
4292 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4293 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4294 "Configure a neighbor as Route Reflector client\n")
4295
4296 DEFUN (no_neighbor_route_reflector_client,
4297 no_neighbor_route_reflector_client_cmd,
4298 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4299 NO_STR
4300 NEIGHBOR_STR
4301 NEIGHBOR_ADDR_STR2
4302 "Configure a neighbor as Route Reflector client\n")
4303 {
4304 int idx_peer = 2;
4305 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4306 bgp_node_afi(vty), bgp_node_safi(vty),
4307 PEER_FLAG_REFLECTOR_CLIENT);
4308 }
4309
4310 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4311 no_neighbor_route_reflector_client_hidden_cmd,
4312 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4313 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4314 "Configure a neighbor as Route Reflector client\n")
4315
4316 /* neighbor route-server-client. */
4317 DEFUN (neighbor_route_server_client,
4318 neighbor_route_server_client_cmd,
4319 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4320 NEIGHBOR_STR
4321 NEIGHBOR_ADDR_STR2
4322 "Configure a neighbor as Route Server client\n")
4323 {
4324 int idx_peer = 1;
4325 struct peer *peer;
4326
4327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4328 if (!peer)
4329 return CMD_WARNING_CONFIG_FAILED;
4330 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4331 bgp_node_safi(vty),
4332 PEER_FLAG_RSERVER_CLIENT);
4333 }
4334
4335 ALIAS_HIDDEN(neighbor_route_server_client,
4336 neighbor_route_server_client_hidden_cmd,
4337 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4338 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4339 "Configure a neighbor as Route Server client\n")
4340
4341 DEFUN (no_neighbor_route_server_client,
4342 no_neighbor_route_server_client_cmd,
4343 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4344 NO_STR
4345 NEIGHBOR_STR
4346 NEIGHBOR_ADDR_STR2
4347 "Configure a neighbor as Route Server client\n")
4348 {
4349 int idx_peer = 2;
4350 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4351 bgp_node_afi(vty), bgp_node_safi(vty),
4352 PEER_FLAG_RSERVER_CLIENT);
4353 }
4354
4355 ALIAS_HIDDEN(no_neighbor_route_server_client,
4356 no_neighbor_route_server_client_hidden_cmd,
4357 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4358 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4359 "Configure a neighbor as Route Server client\n")
4360
4361 DEFUN (neighbor_nexthop_local_unchanged,
4362 neighbor_nexthop_local_unchanged_cmd,
4363 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4364 NEIGHBOR_STR
4365 NEIGHBOR_ADDR_STR2
4366 "Configure treatment of outgoing link-local nexthop attribute\n"
4367 "Leave link-local nexthop unchanged for this peer\n")
4368 {
4369 int idx_peer = 1;
4370 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4371 bgp_node_safi(vty),
4372 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4373 }
4374
4375 DEFUN (no_neighbor_nexthop_local_unchanged,
4376 no_neighbor_nexthop_local_unchanged_cmd,
4377 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4378 NO_STR
4379 NEIGHBOR_STR
4380 NEIGHBOR_ADDR_STR2
4381 "Configure treatment of outgoing link-local-nexthop attribute\n"
4382 "Leave link-local nexthop unchanged for this peer\n")
4383 {
4384 int idx_peer = 2;
4385 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4386 bgp_node_afi(vty), bgp_node_safi(vty),
4387 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4388 }
4389
4390 DEFUN (neighbor_attr_unchanged,
4391 neighbor_attr_unchanged_cmd,
4392 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4393 NEIGHBOR_STR
4394 NEIGHBOR_ADDR_STR2
4395 "BGP attribute is propagated unchanged to this neighbor\n"
4396 "As-path attribute\n"
4397 "Nexthop attribute\n"
4398 "Med attribute\n")
4399 {
4400 int idx = 0;
4401 char *peer_str = argv[1]->arg;
4402 struct peer *peer;
4403 uint16_t flags = 0;
4404 afi_t afi = bgp_node_afi(vty);
4405 safi_t safi = bgp_node_safi(vty);
4406
4407 peer = peer_and_group_lookup_vty(vty, peer_str);
4408 if (!peer)
4409 return CMD_WARNING_CONFIG_FAILED;
4410
4411 if (argv_find(argv, argc, "as-path", &idx))
4412 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4413 idx = 0;
4414 if (argv_find(argv, argc, "next-hop", &idx))
4415 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4416 idx = 0;
4417 if (argv_find(argv, argc, "med", &idx))
4418 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4419
4420 /* no flags means all of them! */
4421 if (!flags) {
4422 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4423 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4424 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4425 } else {
4426 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4427 && peer_af_flag_check(peer, afi, safi,
4428 PEER_FLAG_AS_PATH_UNCHANGED)) {
4429 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4430 PEER_FLAG_AS_PATH_UNCHANGED);
4431 }
4432
4433 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4434 && peer_af_flag_check(peer, afi, safi,
4435 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4436 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4437 PEER_FLAG_NEXTHOP_UNCHANGED);
4438 }
4439
4440 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4441 && peer_af_flag_check(peer, afi, safi,
4442 PEER_FLAG_MED_UNCHANGED)) {
4443 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4444 PEER_FLAG_MED_UNCHANGED);
4445 }
4446 }
4447
4448 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4449 }
4450
4451 ALIAS_HIDDEN(
4452 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4453 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4454 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4455 "BGP attribute is propagated unchanged to this neighbor\n"
4456 "As-path attribute\n"
4457 "Nexthop attribute\n"
4458 "Med attribute\n")
4459
4460 DEFUN (no_neighbor_attr_unchanged,
4461 no_neighbor_attr_unchanged_cmd,
4462 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4463 NO_STR
4464 NEIGHBOR_STR
4465 NEIGHBOR_ADDR_STR2
4466 "BGP attribute is propagated unchanged to this neighbor\n"
4467 "As-path attribute\n"
4468 "Nexthop attribute\n"
4469 "Med attribute\n")
4470 {
4471 int idx = 0;
4472 char *peer = argv[2]->arg;
4473 uint16_t flags = 0;
4474
4475 if (argv_find(argv, argc, "as-path", &idx))
4476 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4477 idx = 0;
4478 if (argv_find(argv, argc, "next-hop", &idx))
4479 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4480 idx = 0;
4481 if (argv_find(argv, argc, "med", &idx))
4482 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4483
4484 if (!flags) // no flags means all of them!
4485 {
4486 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4487 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4488 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4489 }
4490
4491 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4492 bgp_node_safi(vty), flags);
4493 }
4494
4495 ALIAS_HIDDEN(
4496 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4497 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4498 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4499 "BGP attribute is propagated unchanged to this neighbor\n"
4500 "As-path attribute\n"
4501 "Nexthop attribute\n"
4502 "Med attribute\n")
4503
4504 /* EBGP multihop configuration. */
4505 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4506 const char *ttl_str)
4507 {
4508 struct peer *peer;
4509 unsigned int ttl;
4510
4511 peer = peer_and_group_lookup_vty(vty, ip_str);
4512 if (!peer)
4513 return CMD_WARNING_CONFIG_FAILED;
4514
4515 if (peer->conf_if)
4516 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4517
4518 if (!ttl_str)
4519 ttl = MAXTTL;
4520 else
4521 ttl = strtoul(ttl_str, NULL, 10);
4522
4523 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4524 }
4525
4526 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4527 {
4528 struct peer *peer;
4529
4530 peer = peer_and_group_lookup_vty(vty, ip_str);
4531 if (!peer)
4532 return CMD_WARNING_CONFIG_FAILED;
4533
4534 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4535 }
4536
4537 /* neighbor ebgp-multihop. */
4538 DEFUN (neighbor_ebgp_multihop,
4539 neighbor_ebgp_multihop_cmd,
4540 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4541 NEIGHBOR_STR
4542 NEIGHBOR_ADDR_STR2
4543 "Allow EBGP neighbors not on directly connected networks\n")
4544 {
4545 int idx_peer = 1;
4546 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4547 }
4548
4549 DEFUN (neighbor_ebgp_multihop_ttl,
4550 neighbor_ebgp_multihop_ttl_cmd,
4551 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4552 NEIGHBOR_STR
4553 NEIGHBOR_ADDR_STR2
4554 "Allow EBGP neighbors not on directly connected networks\n"
4555 "maximum hop count\n")
4556 {
4557 int idx_peer = 1;
4558 int idx_number = 3;
4559 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4560 argv[idx_number]->arg);
4561 }
4562
4563 DEFUN (no_neighbor_ebgp_multihop,
4564 no_neighbor_ebgp_multihop_cmd,
4565 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4566 NO_STR
4567 NEIGHBOR_STR
4568 NEIGHBOR_ADDR_STR2
4569 "Allow EBGP neighbors not on directly connected networks\n"
4570 "maximum hop count\n")
4571 {
4572 int idx_peer = 2;
4573 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4574 }
4575
4576
4577 /* disable-connected-check */
4578 DEFUN (neighbor_disable_connected_check,
4579 neighbor_disable_connected_check_cmd,
4580 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4581 NEIGHBOR_STR
4582 NEIGHBOR_ADDR_STR2
4583 "one-hop away EBGP peer using loopback address\n"
4584 "Enforce EBGP neighbors perform multihop\n")
4585 {
4586 int idx_peer = 1;
4587 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4588 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4589 }
4590
4591 DEFUN (no_neighbor_disable_connected_check,
4592 no_neighbor_disable_connected_check_cmd,
4593 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4594 NO_STR
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 = 2;
4601 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4602 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4603 }
4604
4605
4606 /* enforce-first-as */
4607 DEFUN (neighbor_enforce_first_as,
4608 neighbor_enforce_first_as_cmd,
4609 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4610 NEIGHBOR_STR
4611 NEIGHBOR_ADDR_STR2
4612 "Enforce the first AS for EBGP routes\n")
4613 {
4614 int idx_peer = 1;
4615
4616 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4617 PEER_FLAG_ENFORCE_FIRST_AS);
4618 }
4619
4620 DEFUN (no_neighbor_enforce_first_as,
4621 no_neighbor_enforce_first_as_cmd,
4622 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4623 NO_STR
4624 NEIGHBOR_STR
4625 NEIGHBOR_ADDR_STR2
4626 "Enforce the first AS for EBGP routes\n")
4627 {
4628 int idx_peer = 2;
4629
4630 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4631 PEER_FLAG_ENFORCE_FIRST_AS);
4632 }
4633
4634
4635 DEFUN (neighbor_description,
4636 neighbor_description_cmd,
4637 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4638 NEIGHBOR_STR
4639 NEIGHBOR_ADDR_STR2
4640 "Neighbor specific description\n"
4641 "Up to 80 characters describing this neighbor\n")
4642 {
4643 int idx_peer = 1;
4644 int idx_line = 3;
4645 struct peer *peer;
4646 char *str;
4647
4648 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4649 if (!peer)
4650 return CMD_WARNING_CONFIG_FAILED;
4651
4652 str = argv_concat(argv, argc, idx_line);
4653
4654 peer_description_set(peer, str);
4655
4656 XFREE(MTYPE_TMP, str);
4657
4658 return CMD_SUCCESS;
4659 }
4660
4661 DEFUN (no_neighbor_description,
4662 no_neighbor_description_cmd,
4663 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4664 NO_STR
4665 NEIGHBOR_STR
4666 NEIGHBOR_ADDR_STR2
4667 "Neighbor specific description\n")
4668 {
4669 int idx_peer = 2;
4670 struct peer *peer;
4671
4672 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4673 if (!peer)
4674 return CMD_WARNING_CONFIG_FAILED;
4675
4676 peer_description_unset(peer);
4677
4678 return CMD_SUCCESS;
4679 }
4680
4681 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4682 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4683 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4684 "Neighbor specific description\n"
4685 "Up to 80 characters describing this neighbor\n")
4686
4687 /* Neighbor update-source. */
4688 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4689 const char *source_str)
4690 {
4691 struct peer *peer;
4692 struct prefix p;
4693 union sockunion su;
4694
4695 peer = peer_and_group_lookup_vty(vty, peer_str);
4696 if (!peer)
4697 return CMD_WARNING_CONFIG_FAILED;
4698
4699 if (peer->conf_if)
4700 return CMD_WARNING;
4701
4702 if (source_str) {
4703 if (str2sockunion(source_str, &su) == 0)
4704 peer_update_source_addr_set(peer, &su);
4705 else {
4706 if (str2prefix(source_str, &p)) {
4707 vty_out(vty,
4708 "%% Invalid update-source, remove prefix length \n");
4709 return CMD_WARNING_CONFIG_FAILED;
4710 } else
4711 peer_update_source_if_set(peer, source_str);
4712 }
4713 } else
4714 peer_update_source_unset(peer);
4715
4716 return CMD_SUCCESS;
4717 }
4718
4719 #define BGP_UPDATE_SOURCE_HELP_STR \
4720 "IPv4 address\n" \
4721 "IPv6 address\n" \
4722 "Interface name (requires zebra to be running)\n"
4723
4724 DEFUN (neighbor_update_source,
4725 neighbor_update_source_cmd,
4726 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4727 NEIGHBOR_STR
4728 NEIGHBOR_ADDR_STR2
4729 "Source of routing updates\n"
4730 BGP_UPDATE_SOURCE_HELP_STR)
4731 {
4732 int idx_peer = 1;
4733 int idx_peer_2 = 3;
4734 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4735 argv[idx_peer_2]->arg);
4736 }
4737
4738 DEFUN (no_neighbor_update_source,
4739 no_neighbor_update_source_cmd,
4740 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4741 NO_STR
4742 NEIGHBOR_STR
4743 NEIGHBOR_ADDR_STR2
4744 "Source of routing updates\n"
4745 BGP_UPDATE_SOURCE_HELP_STR)
4746 {
4747 int idx_peer = 2;
4748 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4749 }
4750
4751 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4752 afi_t afi, safi_t safi,
4753 const char *rmap, int set)
4754 {
4755 int ret;
4756 struct peer *peer;
4757
4758 peer = peer_and_group_lookup_vty(vty, peer_str);
4759 if (!peer)
4760 return CMD_WARNING_CONFIG_FAILED;
4761
4762 if (set)
4763 ret = peer_default_originate_set(peer, afi, safi, rmap);
4764 else
4765 ret = peer_default_originate_unset(peer, afi, safi);
4766
4767 return bgp_vty_return(vty, ret);
4768 }
4769
4770 /* neighbor default-originate. */
4771 DEFUN (neighbor_default_originate,
4772 neighbor_default_originate_cmd,
4773 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4774 NEIGHBOR_STR
4775 NEIGHBOR_ADDR_STR2
4776 "Originate default route to this neighbor\n")
4777 {
4778 int idx_peer = 1;
4779 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4780 bgp_node_afi(vty),
4781 bgp_node_safi(vty), NULL, 1);
4782 }
4783
4784 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4785 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4786 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4787 "Originate default route to this neighbor\n")
4788
4789 DEFUN (neighbor_default_originate_rmap,
4790 neighbor_default_originate_rmap_cmd,
4791 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4792 NEIGHBOR_STR
4793 NEIGHBOR_ADDR_STR2
4794 "Originate default route to this neighbor\n"
4795 "Route-map to specify criteria to originate default\n"
4796 "route-map name\n")
4797 {
4798 int idx_peer = 1;
4799 int idx_word = 4;
4800 return peer_default_originate_set_vty(
4801 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4802 argv[idx_word]->arg, 1);
4803 }
4804
4805 ALIAS_HIDDEN(
4806 neighbor_default_originate_rmap,
4807 neighbor_default_originate_rmap_hidden_cmd,
4808 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4809 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4810 "Originate default route to this neighbor\n"
4811 "Route-map to specify criteria to originate default\n"
4812 "route-map name\n")
4813
4814 DEFUN (no_neighbor_default_originate,
4815 no_neighbor_default_originate_cmd,
4816 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4817 NO_STR
4818 NEIGHBOR_STR
4819 NEIGHBOR_ADDR_STR2
4820 "Originate default route to this neighbor\n"
4821 "Route-map to specify criteria to originate default\n"
4822 "route-map name\n")
4823 {
4824 int idx_peer = 2;
4825 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4826 bgp_node_afi(vty),
4827 bgp_node_safi(vty), NULL, 0);
4828 }
4829
4830 ALIAS_HIDDEN(
4831 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4832 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4833 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4834 "Originate default route to this neighbor\n"
4835 "Route-map to specify criteria to originate default\n"
4836 "route-map name\n")
4837
4838
4839 /* Set neighbor's BGP port. */
4840 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4841 const char *port_str)
4842 {
4843 struct peer *peer;
4844 uint16_t port;
4845 struct servent *sp;
4846
4847 peer = peer_lookup_vty(vty, ip_str);
4848 if (!peer)
4849 return CMD_WARNING_CONFIG_FAILED;
4850
4851 if (!port_str) {
4852 sp = getservbyname("bgp", "tcp");
4853 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4854 } else {
4855 port = strtoul(port_str, NULL, 10);
4856 }
4857
4858 peer_port_set(peer, port);
4859
4860 return CMD_SUCCESS;
4861 }
4862
4863 /* Set specified peer's BGP port. */
4864 DEFUN (neighbor_port,
4865 neighbor_port_cmd,
4866 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4867 NEIGHBOR_STR
4868 NEIGHBOR_ADDR_STR
4869 "Neighbor's BGP port\n"
4870 "TCP port number\n")
4871 {
4872 int idx_ip = 1;
4873 int idx_number = 3;
4874 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4875 argv[idx_number]->arg);
4876 }
4877
4878 DEFUN (no_neighbor_port,
4879 no_neighbor_port_cmd,
4880 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4881 NO_STR
4882 NEIGHBOR_STR
4883 NEIGHBOR_ADDR_STR
4884 "Neighbor's BGP port\n"
4885 "TCP port number\n")
4886 {
4887 int idx_ip = 2;
4888 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4889 }
4890
4891
4892 /* neighbor weight. */
4893 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4894 safi_t safi, const char *weight_str)
4895 {
4896 int ret;
4897 struct peer *peer;
4898 unsigned long weight;
4899
4900 peer = peer_and_group_lookup_vty(vty, ip_str);
4901 if (!peer)
4902 return CMD_WARNING_CONFIG_FAILED;
4903
4904 weight = strtoul(weight_str, NULL, 10);
4905
4906 ret = peer_weight_set(peer, afi, safi, weight);
4907 return bgp_vty_return(vty, ret);
4908 }
4909
4910 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4911 safi_t safi)
4912 {
4913 int ret;
4914 struct peer *peer;
4915
4916 peer = peer_and_group_lookup_vty(vty, ip_str);
4917 if (!peer)
4918 return CMD_WARNING_CONFIG_FAILED;
4919
4920 ret = peer_weight_unset(peer, afi, safi);
4921 return bgp_vty_return(vty, ret);
4922 }
4923
4924 DEFUN (neighbor_weight,
4925 neighbor_weight_cmd,
4926 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4927 NEIGHBOR_STR
4928 NEIGHBOR_ADDR_STR2
4929 "Set default weight for routes from this neighbor\n"
4930 "default weight\n")
4931 {
4932 int idx_peer = 1;
4933 int idx_number = 3;
4934 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4935 bgp_node_safi(vty), argv[idx_number]->arg);
4936 }
4937
4938 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4940 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4941 "Set default weight for routes from this neighbor\n"
4942 "default weight\n")
4943
4944 DEFUN (no_neighbor_weight,
4945 no_neighbor_weight_cmd,
4946 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4947 NO_STR
4948 NEIGHBOR_STR
4949 NEIGHBOR_ADDR_STR2
4950 "Set default weight for routes from this neighbor\n"
4951 "default weight\n")
4952 {
4953 int idx_peer = 2;
4954 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4955 bgp_node_afi(vty), bgp_node_safi(vty));
4956 }
4957
4958 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4959 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4960 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4961 "Set default weight for routes from this neighbor\n"
4962 "default weight\n")
4963
4964
4965 /* Override capability negotiation. */
4966 DEFUN (neighbor_override_capability,
4967 neighbor_override_capability_cmd,
4968 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4969 NEIGHBOR_STR
4970 NEIGHBOR_ADDR_STR2
4971 "Override capability negotiation result\n")
4972 {
4973 int idx_peer = 1;
4974 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4975 PEER_FLAG_OVERRIDE_CAPABILITY);
4976 }
4977
4978 DEFUN (no_neighbor_override_capability,
4979 no_neighbor_override_capability_cmd,
4980 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4981 NO_STR
4982 NEIGHBOR_STR
4983 NEIGHBOR_ADDR_STR2
4984 "Override capability negotiation result\n")
4985 {
4986 int idx_peer = 2;
4987 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4988 PEER_FLAG_OVERRIDE_CAPABILITY);
4989 }
4990
4991 DEFUN (neighbor_strict_capability,
4992 neighbor_strict_capability_cmd,
4993 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
4994 NEIGHBOR_STR
4995 NEIGHBOR_ADDR_STR2
4996 "Strict capability negotiation match\n")
4997 {
4998 int idx_peer = 1;
4999
5000 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5001 PEER_FLAG_STRICT_CAP_MATCH);
5002 }
5003
5004 DEFUN (no_neighbor_strict_capability,
5005 no_neighbor_strict_capability_cmd,
5006 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5007 NO_STR
5008 NEIGHBOR_STR
5009 NEIGHBOR_ADDR_STR2
5010 "Strict capability negotiation match\n")
5011 {
5012 int idx_peer = 2;
5013
5014 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5015 PEER_FLAG_STRICT_CAP_MATCH);
5016 }
5017
5018 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5019 const char *keep_str, const char *hold_str)
5020 {
5021 int ret;
5022 struct peer *peer;
5023 uint32_t keepalive;
5024 uint32_t holdtime;
5025
5026 peer = peer_and_group_lookup_vty(vty, ip_str);
5027 if (!peer)
5028 return CMD_WARNING_CONFIG_FAILED;
5029
5030 keepalive = strtoul(keep_str, NULL, 10);
5031 holdtime = strtoul(hold_str, NULL, 10);
5032
5033 ret = peer_timers_set(peer, keepalive, holdtime);
5034
5035 return bgp_vty_return(vty, ret);
5036 }
5037
5038 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5039 {
5040 int ret;
5041 struct peer *peer;
5042
5043 peer = peer_and_group_lookup_vty(vty, ip_str);
5044 if (!peer)
5045 return CMD_WARNING_CONFIG_FAILED;
5046
5047 ret = peer_timers_unset(peer);
5048
5049 return bgp_vty_return(vty, ret);
5050 }
5051
5052 DEFUN (neighbor_timers,
5053 neighbor_timers_cmd,
5054 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5055 NEIGHBOR_STR
5056 NEIGHBOR_ADDR_STR2
5057 "BGP per neighbor timers\n"
5058 "Keepalive interval\n"
5059 "Holdtime\n")
5060 {
5061 int idx_peer = 1;
5062 int idx_number = 3;
5063 int idx_number_2 = 4;
5064 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5065 argv[idx_number]->arg,
5066 argv[idx_number_2]->arg);
5067 }
5068
5069 DEFUN (no_neighbor_timers,
5070 no_neighbor_timers_cmd,
5071 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5072 NO_STR
5073 NEIGHBOR_STR
5074 NEIGHBOR_ADDR_STR2
5075 "BGP per neighbor timers\n"
5076 "Keepalive interval\n"
5077 "Holdtime\n")
5078 {
5079 int idx_peer = 2;
5080 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5081 }
5082
5083
5084 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5085 const char *time_str)
5086 {
5087 int ret;
5088 struct peer *peer;
5089 uint32_t connect;
5090
5091 peer = peer_and_group_lookup_vty(vty, ip_str);
5092 if (!peer)
5093 return CMD_WARNING_CONFIG_FAILED;
5094
5095 connect = strtoul(time_str, NULL, 10);
5096
5097 ret = peer_timers_connect_set(peer, connect);
5098
5099 return bgp_vty_return(vty, ret);
5100 }
5101
5102 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5103 {
5104 int ret;
5105 struct peer *peer;
5106
5107 peer = peer_and_group_lookup_vty(vty, ip_str);
5108 if (!peer)
5109 return CMD_WARNING_CONFIG_FAILED;
5110
5111 ret = peer_timers_connect_unset(peer);
5112
5113 return bgp_vty_return(vty, ret);
5114 }
5115
5116 DEFUN (neighbor_timers_connect,
5117 neighbor_timers_connect_cmd,
5118 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5119 NEIGHBOR_STR
5120 NEIGHBOR_ADDR_STR2
5121 "BGP per neighbor timers\n"
5122 "BGP connect timer\n"
5123 "Connect timer\n")
5124 {
5125 int idx_peer = 1;
5126 int idx_number = 4;
5127 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5128 argv[idx_number]->arg);
5129 }
5130
5131 DEFUN (no_neighbor_timers_connect,
5132 no_neighbor_timers_connect_cmd,
5133 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5134 NO_STR
5135 NEIGHBOR_STR
5136 NEIGHBOR_ADDR_STR2
5137 "BGP per neighbor timers\n"
5138 "BGP connect timer\n"
5139 "Connect timer\n")
5140 {
5141 int idx_peer = 2;
5142 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5143 }
5144
5145
5146 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5147 const char *time_str, int set)
5148 {
5149 int ret;
5150 struct peer *peer;
5151 uint32_t routeadv = 0;
5152
5153 peer = peer_and_group_lookup_vty(vty, ip_str);
5154 if (!peer)
5155 return CMD_WARNING_CONFIG_FAILED;
5156
5157 if (time_str)
5158 routeadv = strtoul(time_str, NULL, 10);
5159
5160 if (set)
5161 ret = peer_advertise_interval_set(peer, routeadv);
5162 else
5163 ret = peer_advertise_interval_unset(peer);
5164
5165 return bgp_vty_return(vty, ret);
5166 }
5167
5168 DEFUN (neighbor_advertise_interval,
5169 neighbor_advertise_interval_cmd,
5170 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5171 NEIGHBOR_STR
5172 NEIGHBOR_ADDR_STR2
5173 "Minimum interval between sending BGP routing updates\n"
5174 "time in seconds\n")
5175 {
5176 int idx_peer = 1;
5177 int idx_number = 3;
5178 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5179 argv[idx_number]->arg, 1);
5180 }
5181
5182 DEFUN (no_neighbor_advertise_interval,
5183 no_neighbor_advertise_interval_cmd,
5184 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5185 NO_STR
5186 NEIGHBOR_STR
5187 NEIGHBOR_ADDR_STR2
5188 "Minimum interval between sending BGP routing updates\n"
5189 "time in seconds\n")
5190 {
5191 int idx_peer = 2;
5192 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5193 }
5194
5195
5196 /* Time to wait before processing route-map updates */
5197 DEFUN (bgp_set_route_map_delay_timer,
5198 bgp_set_route_map_delay_timer_cmd,
5199 "bgp route-map delay-timer (0-600)",
5200 SET_STR
5201 "BGP route-map delay timer\n"
5202 "Time in secs to wait before processing route-map changes\n"
5203 "0 disables the timer, no route updates happen when route-maps change\n")
5204 {
5205 int idx_number = 3;
5206 uint32_t rmap_delay_timer;
5207
5208 if (argv[idx_number]->arg) {
5209 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5210 bm->rmap_update_timer = rmap_delay_timer;
5211
5212 /* if the dynamic update handling is being disabled, and a timer
5213 * is
5214 * running, stop the timer and act as if the timer has already
5215 * fired.
5216 */
5217 if (!rmap_delay_timer && bm->t_rmap_update) {
5218 BGP_TIMER_OFF(bm->t_rmap_update);
5219 thread_execute(bm->master, bgp_route_map_update_timer,
5220 NULL, 0);
5221 }
5222 return CMD_SUCCESS;
5223 } else {
5224 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5225 return CMD_WARNING_CONFIG_FAILED;
5226 }
5227 }
5228
5229 DEFUN (no_bgp_set_route_map_delay_timer,
5230 no_bgp_set_route_map_delay_timer_cmd,
5231 "no bgp route-map delay-timer [(0-600)]",
5232 NO_STR
5233 BGP_STR
5234 "Default BGP route-map delay timer\n"
5235 "Reset to default time to wait for processing route-map changes\n"
5236 "0 disables the timer, no route updates happen when route-maps change\n")
5237 {
5238
5239 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5240
5241 return CMD_SUCCESS;
5242 }
5243
5244
5245 /* neighbor interface */
5246 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5247 const char *str)
5248 {
5249 struct peer *peer;
5250
5251 peer = peer_lookup_vty(vty, ip_str);
5252 if (!peer || peer->conf_if) {
5253 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5254 return CMD_WARNING_CONFIG_FAILED;
5255 }
5256
5257 if (str)
5258 peer_interface_set(peer, str);
5259 else
5260 peer_interface_unset(peer);
5261
5262 return CMD_SUCCESS;
5263 }
5264
5265 DEFUN (neighbor_interface,
5266 neighbor_interface_cmd,
5267 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5268 NEIGHBOR_STR
5269 NEIGHBOR_ADDR_STR
5270 "Interface\n"
5271 "Interface name\n")
5272 {
5273 int idx_ip = 1;
5274 int idx_word = 3;
5275 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5276 }
5277
5278 DEFUN (no_neighbor_interface,
5279 no_neighbor_interface_cmd,
5280 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5281 NO_STR
5282 NEIGHBOR_STR
5283 NEIGHBOR_ADDR_STR2
5284 "Interface\n"
5285 "Interface name\n")
5286 {
5287 int idx_peer = 2;
5288 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5289 }
5290
5291 DEFUN (neighbor_distribute_list,
5292 neighbor_distribute_list_cmd,
5293 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5294 NEIGHBOR_STR
5295 NEIGHBOR_ADDR_STR2
5296 "Filter updates to/from this neighbor\n"
5297 "IP access-list number\n"
5298 "IP access-list number (expanded range)\n"
5299 "IP Access-list name\n"
5300 "Filter incoming updates\n"
5301 "Filter outgoing updates\n")
5302 {
5303 int idx_peer = 1;
5304 int idx_acl = 3;
5305 int direct, ret;
5306 struct peer *peer;
5307
5308 const char *pstr = argv[idx_peer]->arg;
5309 const char *acl = argv[idx_acl]->arg;
5310 const char *inout = argv[argc - 1]->text;
5311
5312 peer = peer_and_group_lookup_vty(vty, pstr);
5313 if (!peer)
5314 return CMD_WARNING_CONFIG_FAILED;
5315
5316 /* Check filter direction. */
5317 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5318 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5319 direct, acl);
5320
5321 return bgp_vty_return(vty, ret);
5322 }
5323
5324 ALIAS_HIDDEN(
5325 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5326 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5327 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5328 "Filter updates to/from this neighbor\n"
5329 "IP access-list number\n"
5330 "IP access-list number (expanded range)\n"
5331 "IP Access-list name\n"
5332 "Filter incoming updates\n"
5333 "Filter outgoing updates\n")
5334
5335 DEFUN (no_neighbor_distribute_list,
5336 no_neighbor_distribute_list_cmd,
5337 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5338 NO_STR
5339 NEIGHBOR_STR
5340 NEIGHBOR_ADDR_STR2
5341 "Filter updates to/from this neighbor\n"
5342 "IP access-list number\n"
5343 "IP access-list number (expanded range)\n"
5344 "IP Access-list name\n"
5345 "Filter incoming updates\n"
5346 "Filter outgoing updates\n")
5347 {
5348 int idx_peer = 2;
5349 int direct, ret;
5350 struct peer *peer;
5351
5352 const char *pstr = argv[idx_peer]->arg;
5353 const char *inout = argv[argc - 1]->text;
5354
5355 peer = peer_and_group_lookup_vty(vty, pstr);
5356 if (!peer)
5357 return CMD_WARNING_CONFIG_FAILED;
5358
5359 /* Check filter direction. */
5360 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5361 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5362 direct);
5363
5364 return bgp_vty_return(vty, ret);
5365 }
5366
5367 ALIAS_HIDDEN(
5368 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5369 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5370 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5371 "Filter updates to/from this neighbor\n"
5372 "IP access-list number\n"
5373 "IP access-list number (expanded range)\n"
5374 "IP Access-list name\n"
5375 "Filter incoming updates\n"
5376 "Filter outgoing updates\n")
5377
5378 /* Set prefix list to the peer. */
5379 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5380 afi_t afi, safi_t safi,
5381 const char *name_str,
5382 const char *direct_str)
5383 {
5384 int ret;
5385 int direct = FILTER_IN;
5386 struct peer *peer;
5387
5388 peer = peer_and_group_lookup_vty(vty, ip_str);
5389 if (!peer)
5390 return CMD_WARNING_CONFIG_FAILED;
5391
5392 /* Check filter direction. */
5393 if (strncmp(direct_str, "i", 1) == 0)
5394 direct = FILTER_IN;
5395 else if (strncmp(direct_str, "o", 1) == 0)
5396 direct = FILTER_OUT;
5397
5398 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5399
5400 return bgp_vty_return(vty, ret);
5401 }
5402
5403 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5404 afi_t afi, safi_t safi,
5405 const char *direct_str)
5406 {
5407 int ret;
5408 struct peer *peer;
5409 int direct = FILTER_IN;
5410
5411 peer = peer_and_group_lookup_vty(vty, ip_str);
5412 if (!peer)
5413 return CMD_WARNING_CONFIG_FAILED;
5414
5415 /* Check filter direction. */
5416 if (strncmp(direct_str, "i", 1) == 0)
5417 direct = FILTER_IN;
5418 else if (strncmp(direct_str, "o", 1) == 0)
5419 direct = FILTER_OUT;
5420
5421 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5422
5423 return bgp_vty_return(vty, ret);
5424 }
5425
5426 DEFUN (neighbor_prefix_list,
5427 neighbor_prefix_list_cmd,
5428 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5429 NEIGHBOR_STR
5430 NEIGHBOR_ADDR_STR2
5431 "Filter updates to/from this neighbor\n"
5432 "Name of a prefix list\n"
5433 "Filter incoming updates\n"
5434 "Filter outgoing updates\n")
5435 {
5436 int idx_peer = 1;
5437 int idx_word = 3;
5438 int idx_in_out = 4;
5439 return peer_prefix_list_set_vty(
5440 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5441 argv[idx_word]->arg, argv[idx_in_out]->arg);
5442 }
5443
5444 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5445 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5446 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5447 "Filter updates to/from this neighbor\n"
5448 "Name of a prefix list\n"
5449 "Filter incoming updates\n"
5450 "Filter outgoing updates\n")
5451
5452 DEFUN (no_neighbor_prefix_list,
5453 no_neighbor_prefix_list_cmd,
5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5455 NO_STR
5456 NEIGHBOR_STR
5457 NEIGHBOR_ADDR_STR2
5458 "Filter updates to/from this neighbor\n"
5459 "Name of a prefix list\n"
5460 "Filter incoming updates\n"
5461 "Filter outgoing updates\n")
5462 {
5463 int idx_peer = 2;
5464 int idx_in_out = 5;
5465 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5466 bgp_node_afi(vty), bgp_node_safi(vty),
5467 argv[idx_in_out]->arg);
5468 }
5469
5470 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5471 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5472 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5473 "Filter updates to/from this neighbor\n"
5474 "Name of a prefix list\n"
5475 "Filter incoming updates\n"
5476 "Filter outgoing updates\n")
5477
5478 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5479 safi_t safi, const char *name_str,
5480 const char *direct_str)
5481 {
5482 int ret;
5483 struct peer *peer;
5484 int direct = FILTER_IN;
5485
5486 peer = peer_and_group_lookup_vty(vty, ip_str);
5487 if (!peer)
5488 return CMD_WARNING_CONFIG_FAILED;
5489
5490 /* Check filter direction. */
5491 if (strncmp(direct_str, "i", 1) == 0)
5492 direct = FILTER_IN;
5493 else if (strncmp(direct_str, "o", 1) == 0)
5494 direct = FILTER_OUT;
5495
5496 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5497
5498 return bgp_vty_return(vty, ret);
5499 }
5500
5501 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5502 safi_t safi, const char *direct_str)
5503 {
5504 int ret;
5505 struct peer *peer;
5506 int direct = FILTER_IN;
5507
5508 peer = peer_and_group_lookup_vty(vty, ip_str);
5509 if (!peer)
5510 return CMD_WARNING_CONFIG_FAILED;
5511
5512 /* Check filter direction. */
5513 if (strncmp(direct_str, "i", 1) == 0)
5514 direct = FILTER_IN;
5515 else if (strncmp(direct_str, "o", 1) == 0)
5516 direct = FILTER_OUT;
5517
5518 ret = peer_aslist_unset(peer, afi, safi, direct);
5519
5520 return bgp_vty_return(vty, ret);
5521 }
5522
5523 DEFUN (neighbor_filter_list,
5524 neighbor_filter_list_cmd,
5525 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5526 NEIGHBOR_STR
5527 NEIGHBOR_ADDR_STR2
5528 "Establish BGP filters\n"
5529 "AS path access-list name\n"
5530 "Filter incoming routes\n"
5531 "Filter outgoing routes\n")
5532 {
5533 int idx_peer = 1;
5534 int idx_word = 3;
5535 int idx_in_out = 4;
5536 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5537 bgp_node_safi(vty), argv[idx_word]->arg,
5538 argv[idx_in_out]->arg);
5539 }
5540
5541 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5542 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5543 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5544 "Establish BGP filters\n"
5545 "AS path access-list name\n"
5546 "Filter incoming routes\n"
5547 "Filter outgoing routes\n")
5548
5549 DEFUN (no_neighbor_filter_list,
5550 no_neighbor_filter_list_cmd,
5551 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5552 NO_STR
5553 NEIGHBOR_STR
5554 NEIGHBOR_ADDR_STR2
5555 "Establish BGP filters\n"
5556 "AS path access-list name\n"
5557 "Filter incoming routes\n"
5558 "Filter outgoing routes\n")
5559 {
5560 int idx_peer = 2;
5561 int idx_in_out = 5;
5562 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5563 bgp_node_afi(vty), bgp_node_safi(vty),
5564 argv[idx_in_out]->arg);
5565 }
5566
5567 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5568 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5569 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5570 "Establish BGP filters\n"
5571 "AS path access-list name\n"
5572 "Filter incoming routes\n"
5573 "Filter outgoing routes\n")
5574
5575 /* Set route-map to the peer. */
5576 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5577 afi_t afi, safi_t safi, const char *name_str,
5578 const char *direct_str)
5579 {
5580 int ret;
5581 struct peer *peer;
5582 int direct = RMAP_IN;
5583
5584 peer = peer_and_group_lookup_vty(vty, ip_str);
5585 if (!peer)
5586 return CMD_WARNING_CONFIG_FAILED;
5587
5588 /* Check filter direction. */
5589 if (strncmp(direct_str, "in", 2) == 0)
5590 direct = RMAP_IN;
5591 else if (strncmp(direct_str, "o", 1) == 0)
5592 direct = RMAP_OUT;
5593
5594 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5595
5596 return bgp_vty_return(vty, ret);
5597 }
5598
5599 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5600 afi_t afi, safi_t safi,
5601 const char *direct_str)
5602 {
5603 int ret;
5604 struct peer *peer;
5605 int direct = RMAP_IN;
5606
5607 peer = peer_and_group_lookup_vty(vty, ip_str);
5608 if (!peer)
5609 return CMD_WARNING_CONFIG_FAILED;
5610
5611 /* Check filter direction. */
5612 if (strncmp(direct_str, "in", 2) == 0)
5613 direct = RMAP_IN;
5614 else if (strncmp(direct_str, "o", 1) == 0)
5615 direct = RMAP_OUT;
5616
5617 ret = peer_route_map_unset(peer, afi, safi, direct);
5618
5619 return bgp_vty_return(vty, ret);
5620 }
5621
5622 DEFUN (neighbor_route_map,
5623 neighbor_route_map_cmd,
5624 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5625 NEIGHBOR_STR
5626 NEIGHBOR_ADDR_STR2
5627 "Apply route map to neighbor\n"
5628 "Name of route map\n"
5629 "Apply map to incoming routes\n"
5630 "Apply map to outbound routes\n")
5631 {
5632 int idx_peer = 1;
5633 int idx_word = 3;
5634 int idx_in_out = 4;
5635 return peer_route_map_set_vty(
5636 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5637 argv[idx_word]->arg, argv[idx_in_out]->arg);
5638 }
5639
5640 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5641 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5642 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5643 "Apply route map to neighbor\n"
5644 "Name of route map\n"
5645 "Apply map to incoming routes\n"
5646 "Apply map to outbound routes\n")
5647
5648 DEFUN (no_neighbor_route_map,
5649 no_neighbor_route_map_cmd,
5650 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5651 NO_STR
5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Apply route map to neighbor\n"
5655 "Name of route map\n"
5656 "Apply map to incoming routes\n"
5657 "Apply map to outbound routes\n")
5658 {
5659 int idx_peer = 2;
5660 int idx_in_out = 5;
5661 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5662 bgp_node_afi(vty), bgp_node_safi(vty),
5663 argv[idx_in_out]->arg);
5664 }
5665
5666 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5667 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5668 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5669 "Apply route map to neighbor\n"
5670 "Name of route map\n"
5671 "Apply map to incoming routes\n"
5672 "Apply map to outbound routes\n")
5673
5674 /* Set unsuppress-map to the peer. */
5675 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5676 afi_t afi, safi_t safi,
5677 const char *name_str)
5678 {
5679 int ret;
5680 struct peer *peer;
5681
5682 peer = peer_and_group_lookup_vty(vty, ip_str);
5683 if (!peer)
5684 return CMD_WARNING_CONFIG_FAILED;
5685
5686 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5687
5688 return bgp_vty_return(vty, ret);
5689 }
5690
5691 /* Unset route-map from the peer. */
5692 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5693 afi_t afi, safi_t safi)
5694 {
5695 int ret;
5696 struct peer *peer;
5697
5698 peer = peer_and_group_lookup_vty(vty, ip_str);
5699 if (!peer)
5700 return CMD_WARNING_CONFIG_FAILED;
5701
5702 ret = peer_unsuppress_map_unset(peer, afi, safi);
5703
5704 return bgp_vty_return(vty, ret);
5705 }
5706
5707 DEFUN (neighbor_unsuppress_map,
5708 neighbor_unsuppress_map_cmd,
5709 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5710 NEIGHBOR_STR
5711 NEIGHBOR_ADDR_STR2
5712 "Route-map to selectively unsuppress suppressed routes\n"
5713 "Name of route map\n")
5714 {
5715 int idx_peer = 1;
5716 int idx_word = 3;
5717 return peer_unsuppress_map_set_vty(
5718 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5719 argv[idx_word]->arg);
5720 }
5721
5722 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5723 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5724 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5725 "Route-map to selectively unsuppress suppressed routes\n"
5726 "Name of route map\n")
5727
5728 DEFUN (no_neighbor_unsuppress_map,
5729 no_neighbor_unsuppress_map_cmd,
5730 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5731 NO_STR
5732 NEIGHBOR_STR
5733 NEIGHBOR_ADDR_STR2
5734 "Route-map to selectively unsuppress suppressed routes\n"
5735 "Name of route map\n")
5736 {
5737 int idx_peer = 2;
5738 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5739 bgp_node_afi(vty),
5740 bgp_node_safi(vty));
5741 }
5742
5743 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5744 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5745 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5746 "Route-map to selectively unsuppress suppressed routes\n"
5747 "Name of route map\n")
5748
5749 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5750 afi_t afi, safi_t safi,
5751 const char *num_str,
5752 const char *threshold_str, int warning,
5753 const char *restart_str)
5754 {
5755 int ret;
5756 struct peer *peer;
5757 uint32_t max;
5758 uint8_t threshold;
5759 uint16_t restart;
5760
5761 peer = peer_and_group_lookup_vty(vty, ip_str);
5762 if (!peer)
5763 return CMD_WARNING_CONFIG_FAILED;
5764
5765 max = strtoul(num_str, NULL, 10);
5766 if (threshold_str)
5767 threshold = atoi(threshold_str);
5768 else
5769 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5770
5771 if (restart_str)
5772 restart = atoi(restart_str);
5773 else
5774 restart = 0;
5775
5776 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5777 restart);
5778
5779 return bgp_vty_return(vty, ret);
5780 }
5781
5782 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5783 afi_t afi, safi_t safi)
5784 {
5785 int ret;
5786 struct peer *peer;
5787
5788 peer = peer_and_group_lookup_vty(vty, ip_str);
5789 if (!peer)
5790 return CMD_WARNING_CONFIG_FAILED;
5791
5792 ret = peer_maximum_prefix_unset(peer, afi, safi);
5793
5794 return bgp_vty_return(vty, ret);
5795 }
5796
5797 /* Maximum number of prefix configuration. prefix count is different
5798 for each peer configuration. So this configuration can be set for
5799 each peer configuration. */
5800 DEFUN (neighbor_maximum_prefix,
5801 neighbor_maximum_prefix_cmd,
5802 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5803 NEIGHBOR_STR
5804 NEIGHBOR_ADDR_STR2
5805 "Maximum number of prefix accept from this peer\n"
5806 "maximum no. of prefix limit\n")
5807 {
5808 int idx_peer = 1;
5809 int idx_number = 3;
5810 return peer_maximum_prefix_set_vty(
5811 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5812 argv[idx_number]->arg, NULL, 0, NULL);
5813 }
5814
5815 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5816 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5817 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5818 "Maximum number of prefix accept from this peer\n"
5819 "maximum no. of prefix limit\n")
5820
5821 DEFUN (neighbor_maximum_prefix_threshold,
5822 neighbor_maximum_prefix_threshold_cmd,
5823 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
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 "Threshold value (%) at which to generate a warning msg\n")
5829 {
5830 int idx_peer = 1;
5831 int idx_number = 3;
5832 int idx_number_2 = 4;
5833 return peer_maximum_prefix_set_vty(
5834 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5835 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5836 }
5837
5838 ALIAS_HIDDEN(
5839 neighbor_maximum_prefix_threshold,
5840 neighbor_maximum_prefix_threshold_hidden_cmd,
5841 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5842 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5843 "Maximum number of prefix accept from this peer\n"
5844 "maximum no. of prefix limit\n"
5845 "Threshold value (%) at which to generate a warning msg\n")
5846
5847 DEFUN (neighbor_maximum_prefix_warning,
5848 neighbor_maximum_prefix_warning_cmd,
5849 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5850 NEIGHBOR_STR
5851 NEIGHBOR_ADDR_STR2
5852 "Maximum number of prefix accept from this peer\n"
5853 "maximum no. of prefix limit\n"
5854 "Only give warning message when limit is exceeded\n")
5855 {
5856 int idx_peer = 1;
5857 int idx_number = 3;
5858 return peer_maximum_prefix_set_vty(
5859 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5860 argv[idx_number]->arg, NULL, 1, NULL);
5861 }
5862
5863 ALIAS_HIDDEN(
5864 neighbor_maximum_prefix_warning,
5865 neighbor_maximum_prefix_warning_hidden_cmd,
5866 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5867 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5868 "Maximum number of prefix accept from this peer\n"
5869 "maximum no. of prefix limit\n"
5870 "Only give warning message when limit is exceeded\n")
5871
5872 DEFUN (neighbor_maximum_prefix_threshold_warning,
5873 neighbor_maximum_prefix_threshold_warning_cmd,
5874 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5875 NEIGHBOR_STR
5876 NEIGHBOR_ADDR_STR2
5877 "Maximum number of prefix accept from this peer\n"
5878 "maximum no. of prefix limit\n"
5879 "Threshold value (%) at which to generate a warning msg\n"
5880 "Only give warning message when limit is exceeded\n")
5881 {
5882 int idx_peer = 1;
5883 int idx_number = 3;
5884 int idx_number_2 = 4;
5885 return peer_maximum_prefix_set_vty(
5886 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5887 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5888 }
5889
5890 ALIAS_HIDDEN(
5891 neighbor_maximum_prefix_threshold_warning,
5892 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5893 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5894 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5895 "Maximum number of prefix accept from this peer\n"
5896 "maximum no. of prefix limit\n"
5897 "Threshold value (%) at which to generate a warning msg\n"
5898 "Only give warning message when limit is exceeded\n")
5899
5900 DEFUN (neighbor_maximum_prefix_restart,
5901 neighbor_maximum_prefix_restart_cmd,
5902 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5903 NEIGHBOR_STR
5904 NEIGHBOR_ADDR_STR2
5905 "Maximum number of prefix accept from this peer\n"
5906 "maximum no. of prefix limit\n"
5907 "Restart bgp connection after limit is exceeded\n"
5908 "Restart interval in minutes\n")
5909 {
5910 int idx_peer = 1;
5911 int idx_number = 3;
5912 int idx_number_2 = 5;
5913 return peer_maximum_prefix_set_vty(
5914 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5915 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5916 }
5917
5918 ALIAS_HIDDEN(
5919 neighbor_maximum_prefix_restart,
5920 neighbor_maximum_prefix_restart_hidden_cmd,
5921 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5922 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5923 "Maximum number of prefix accept from this peer\n"
5924 "maximum no. of prefix limit\n"
5925 "Restart bgp connection after limit is exceeded\n"
5926 "Restart interval in minutes\n")
5927
5928 DEFUN (neighbor_maximum_prefix_threshold_restart,
5929 neighbor_maximum_prefix_threshold_restart_cmd,
5930 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5931 NEIGHBOR_STR
5932 NEIGHBOR_ADDR_STR2
5933 "Maximum number of prefixes to accept from this peer\n"
5934 "maximum no. of prefix limit\n"
5935 "Threshold value (%) at which to generate a warning msg\n"
5936 "Restart bgp connection after limit is exceeded\n"
5937 "Restart interval in minutes\n")
5938 {
5939 int idx_peer = 1;
5940 int idx_number = 3;
5941 int idx_number_2 = 4;
5942 int idx_number_3 = 6;
5943 return peer_maximum_prefix_set_vty(
5944 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5945 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5946 argv[idx_number_3]->arg);
5947 }
5948
5949 ALIAS_HIDDEN(
5950 neighbor_maximum_prefix_threshold_restart,
5951 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5952 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5953 NEIGHBOR_STR 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 DEFUN (no_neighbor_maximum_prefix,
5961 no_neighbor_maximum_prefix_cmd,
5962 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5963 NO_STR
5964 NEIGHBOR_STR
5965 NEIGHBOR_ADDR_STR2
5966 "Maximum number of prefixes to accept from this peer\n"
5967 "maximum no. of prefix limit\n"
5968 "Threshold value (%) at which to generate a warning msg\n"
5969 "Restart bgp connection after limit is exceeded\n"
5970 "Restart interval in minutes\n"
5971 "Only give warning message when limit is exceeded\n")
5972 {
5973 int idx_peer = 2;
5974 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5975 bgp_node_afi(vty),
5976 bgp_node_safi(vty));
5977 }
5978
5979 ALIAS_HIDDEN(
5980 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5981 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5982 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5983 "Maximum number of prefixes to accept from this peer\n"
5984 "maximum no. of prefix limit\n"
5985 "Threshold value (%) at which to generate a warning msg\n"
5986 "Restart bgp connection after limit is exceeded\n"
5987 "Restart interval in minutes\n"
5988 "Only give warning message when limit is exceeded\n")
5989
5990
5991 /* "neighbor allowas-in" */
5992 DEFUN (neighbor_allowas_in,
5993 neighbor_allowas_in_cmd,
5994 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5995 NEIGHBOR_STR
5996 NEIGHBOR_ADDR_STR2
5997 "Accept as-path with my AS present in it\n"
5998 "Number of occurrences of AS number\n"
5999 "Only accept my AS in the as-path if the route was originated in my AS\n")
6000 {
6001 int idx_peer = 1;
6002 int idx_number_origin = 3;
6003 int ret;
6004 int origin = 0;
6005 struct peer *peer;
6006 int allow_num = 0;
6007
6008 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6009 if (!peer)
6010 return CMD_WARNING_CONFIG_FAILED;
6011
6012 if (argc <= idx_number_origin)
6013 allow_num = 3;
6014 else {
6015 if (argv[idx_number_origin]->type == WORD_TKN)
6016 origin = 1;
6017 else
6018 allow_num = atoi(argv[idx_number_origin]->arg);
6019 }
6020
6021 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6022 allow_num, origin);
6023
6024 return bgp_vty_return(vty, ret);
6025 }
6026
6027 ALIAS_HIDDEN(
6028 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6029 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6030 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6031 "Accept as-path with my AS present in it\n"
6032 "Number of occurrences of AS number\n"
6033 "Only accept my AS in the as-path if the route was originated in my AS\n")
6034
6035 DEFUN (no_neighbor_allowas_in,
6036 no_neighbor_allowas_in_cmd,
6037 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6038 NO_STR
6039 NEIGHBOR_STR
6040 NEIGHBOR_ADDR_STR2
6041 "allow local ASN appears in aspath attribute\n"
6042 "Number of occurrences of AS number\n"
6043 "Only accept my AS in the as-path if the route was originated in my AS\n")
6044 {
6045 int idx_peer = 2;
6046 int ret;
6047 struct peer *peer;
6048
6049 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6050 if (!peer)
6051 return CMD_WARNING_CONFIG_FAILED;
6052
6053 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6054 bgp_node_safi(vty));
6055
6056 return bgp_vty_return(vty, ret);
6057 }
6058
6059 ALIAS_HIDDEN(
6060 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6061 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6062 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6063 "allow local ASN appears in aspath attribute\n"
6064 "Number of occurrences of AS number\n"
6065 "Only accept my AS in the as-path if the route was originated in my AS\n")
6066
6067 DEFUN (neighbor_ttl_security,
6068 neighbor_ttl_security_cmd,
6069 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6070 NEIGHBOR_STR
6071 NEIGHBOR_ADDR_STR2
6072 "BGP ttl-security parameters\n"
6073 "Specify the maximum number of hops to the BGP peer\n"
6074 "Number of hops to BGP peer\n")
6075 {
6076 int idx_peer = 1;
6077 int idx_number = 4;
6078 struct peer *peer;
6079 int gtsm_hops;
6080
6081 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6082 if (!peer)
6083 return CMD_WARNING_CONFIG_FAILED;
6084
6085 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6086
6087 /*
6088 * If 'neighbor swpX', then this is for directly connected peers,
6089 * we should not accept a ttl-security hops value greater than 1.
6090 */
6091 if (peer->conf_if && (gtsm_hops > 1)) {
6092 vty_out(vty,
6093 "%s is directly connected peer, hops cannot exceed 1\n",
6094 argv[idx_peer]->arg);
6095 return CMD_WARNING_CONFIG_FAILED;
6096 }
6097
6098 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6099 }
6100
6101 DEFUN (no_neighbor_ttl_security,
6102 no_neighbor_ttl_security_cmd,
6103 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6104 NO_STR
6105 NEIGHBOR_STR
6106 NEIGHBOR_ADDR_STR2
6107 "BGP ttl-security parameters\n"
6108 "Specify the maximum number of hops to the BGP peer\n"
6109 "Number of hops to BGP peer\n")
6110 {
6111 int idx_peer = 2;
6112 struct peer *peer;
6113
6114 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6115 if (!peer)
6116 return CMD_WARNING_CONFIG_FAILED;
6117
6118 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6119 }
6120
6121 DEFUN (neighbor_addpath_tx_all_paths,
6122 neighbor_addpath_tx_all_paths_cmd,
6123 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6124 NEIGHBOR_STR
6125 NEIGHBOR_ADDR_STR2
6126 "Use addpath to advertise all paths to a neighbor\n")
6127 {
6128 int idx_peer = 1;
6129 struct peer *peer;
6130
6131 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6132 if (!peer)
6133 return CMD_WARNING_CONFIG_FAILED;
6134
6135 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6136 bgp_node_safi(vty),
6137 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6138 }
6139
6140 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6141 neighbor_addpath_tx_all_paths_hidden_cmd,
6142 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6143 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6144 "Use addpath to advertise all paths to a neighbor\n")
6145
6146 DEFUN (no_neighbor_addpath_tx_all_paths,
6147 no_neighbor_addpath_tx_all_paths_cmd,
6148 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6149 NO_STR
6150 NEIGHBOR_STR
6151 NEIGHBOR_ADDR_STR2
6152 "Use addpath to advertise all paths to a neighbor\n")
6153 {
6154 int idx_peer = 2;
6155 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6156 bgp_node_afi(vty), bgp_node_safi(vty),
6157 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6158 }
6159
6160 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6161 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6162 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6163 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6164 "Use addpath to advertise all paths to a neighbor\n")
6165
6166 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6167 neighbor_addpath_tx_bestpath_per_as_cmd,
6168 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6169 NEIGHBOR_STR
6170 NEIGHBOR_ADDR_STR2
6171 "Use addpath to advertise the bestpath per each neighboring AS\n")
6172 {
6173 int idx_peer = 1;
6174 struct peer *peer;
6175
6176 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6177 if (!peer)
6178 return CMD_WARNING_CONFIG_FAILED;
6179
6180 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6181 bgp_node_safi(vty),
6182 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6183 }
6184
6185 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6186 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6187 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6188 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6189 "Use addpath to advertise the bestpath per each neighboring AS\n")
6190
6191 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6192 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6193 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6194 NO_STR
6195 NEIGHBOR_STR
6196 NEIGHBOR_ADDR_STR2
6197 "Use addpath to advertise the bestpath per each neighboring AS\n")
6198 {
6199 int idx_peer = 2;
6200 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6201 bgp_node_afi(vty), bgp_node_safi(vty),
6202 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6203 }
6204
6205 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6206 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6207 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6208 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6209 "Use addpath to advertise the bestpath per each neighboring AS\n")
6210
6211 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6212 struct ecommunity **list)
6213 {
6214 struct ecommunity *ecom = NULL;
6215 struct ecommunity *ecomadd;
6216
6217 for (; argc; --argc, ++argv) {
6218
6219 ecomadd = ecommunity_str2com(argv[0]->arg,
6220 ECOMMUNITY_ROUTE_TARGET, 0);
6221 if (!ecomadd) {
6222 vty_out(vty, "Malformed community-list value\n");
6223 if (ecom)
6224 ecommunity_free(&ecom);
6225 return CMD_WARNING_CONFIG_FAILED;
6226 }
6227
6228 if (ecom) {
6229 ecommunity_merge(ecom, ecomadd);
6230 ecommunity_free(&ecomadd);
6231 } else {
6232 ecom = ecomadd;
6233 }
6234 }
6235
6236 if (*list) {
6237 ecommunity_free(&*list);
6238 }
6239 *list = ecom;
6240
6241 return CMD_SUCCESS;
6242 }
6243
6244 /*
6245 * v2vimport is true if we are handling a `import vrf ...` command
6246 */
6247 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6248 {
6249 afi_t afi;
6250
6251 switch (vty->node) {
6252 case BGP_IPV4_NODE:
6253 afi = AFI_IP;
6254 break;
6255 case BGP_IPV6_NODE:
6256 afi = AFI_IP6;
6257 break;
6258 default:
6259 vty_out(vty,
6260 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6261 return AFI_MAX;
6262 }
6263
6264 if (!v2vimport) {
6265 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6266 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6267 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6268 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6269 vty_out(vty,
6270 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6271 return AFI_MAX;
6272 }
6273 } else {
6274 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6275 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6276 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6277 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6278 vty_out(vty,
6279 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6280 return AFI_MAX;
6281 }
6282 }
6283 return afi;
6284 }
6285
6286 DEFPY (af_rd_vpn_export,
6287 af_rd_vpn_export_cmd,
6288 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6289 NO_STR
6290 "Specify route distinguisher\n"
6291 "Between current address-family and vpn\n"
6292 "For routes leaked from current address-family to vpn\n"
6293 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6294 {
6295 VTY_DECLVAR_CONTEXT(bgp, bgp);
6296 struct prefix_rd prd;
6297 int ret;
6298 afi_t afi;
6299 int idx = 0;
6300 int yes = 1;
6301
6302 if (argv_find(argv, argc, "no", &idx))
6303 yes = 0;
6304
6305 if (yes) {
6306 ret = str2prefix_rd(rd_str, &prd);
6307 if (!ret) {
6308 vty_out(vty, "%% Malformed rd\n");
6309 return CMD_WARNING_CONFIG_FAILED;
6310 }
6311 }
6312
6313 afi = vpn_policy_getafi(vty, bgp, false);
6314 if (afi == AFI_MAX)
6315 return CMD_WARNING_CONFIG_FAILED;
6316
6317 /*
6318 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6319 */
6320 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6321 bgp_get_default(), bgp);
6322
6323 if (yes) {
6324 bgp->vpn_policy[afi].tovpn_rd = prd;
6325 SET_FLAG(bgp->vpn_policy[afi].flags,
6326 BGP_VPN_POLICY_TOVPN_RD_SET);
6327 } else {
6328 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6329 BGP_VPN_POLICY_TOVPN_RD_SET);
6330 }
6331
6332 /* post-change: re-export vpn routes */
6333 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6334 bgp_get_default(), bgp);
6335
6336 return CMD_SUCCESS;
6337 }
6338
6339 ALIAS (af_rd_vpn_export,
6340 af_no_rd_vpn_export_cmd,
6341 "no rd vpn export",
6342 NO_STR
6343 "Specify route distinguisher\n"
6344 "Between current address-family and vpn\n"
6345 "For routes leaked from current address-family to vpn\n")
6346
6347 DEFPY (af_label_vpn_export,
6348 af_label_vpn_export_cmd,
6349 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6350 NO_STR
6351 "label value for VRF\n"
6352 "Between current address-family and vpn\n"
6353 "For routes leaked from current address-family to vpn\n"
6354 "Label Value <0-1048575>\n"
6355 "Automatically assign a label\n")
6356 {
6357 VTY_DECLVAR_CONTEXT(bgp, bgp);
6358 mpls_label_t label = MPLS_LABEL_NONE;
6359 afi_t afi;
6360 int idx = 0;
6361 int yes = 1;
6362
6363 if (argv_find(argv, argc, "no", &idx))
6364 yes = 0;
6365
6366 /* If "no ...", squash trailing parameter */
6367 if (!yes)
6368 label_auto = NULL;
6369
6370 if (yes) {
6371 if (!label_auto)
6372 label = label_val; /* parser should force unsigned */
6373 }
6374
6375 afi = vpn_policy_getafi(vty, bgp, false);
6376 if (afi == AFI_MAX)
6377 return CMD_WARNING_CONFIG_FAILED;
6378
6379
6380 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6381 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6382 /* no change */
6383 return CMD_SUCCESS;
6384
6385 /*
6386 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6387 */
6388 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6389 bgp_get_default(), bgp);
6390
6391 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6392 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6393
6394 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6395
6396 /*
6397 * label has previously been automatically
6398 * assigned by labelpool: release it
6399 *
6400 * NB if tovpn_label == MPLS_LABEL_NONE it
6401 * means the automatic assignment is in flight
6402 * and therefore the labelpool callback must
6403 * detect that the auto label is not needed.
6404 */
6405
6406 bgp_lp_release(LP_TYPE_VRF,
6407 &bgp->vpn_policy[afi],
6408 bgp->vpn_policy[afi].tovpn_label);
6409 }
6410 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6411 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6412 }
6413
6414 bgp->vpn_policy[afi].tovpn_label = label;
6415 if (label_auto) {
6416 SET_FLAG(bgp->vpn_policy[afi].flags,
6417 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6418 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6419 vpn_leak_label_callback);
6420 }
6421
6422 /* post-change: re-export vpn routes */
6423 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6424 bgp_get_default(), bgp);
6425
6426 return CMD_SUCCESS;
6427 }
6428
6429 ALIAS (af_label_vpn_export,
6430 af_no_label_vpn_export_cmd,
6431 "no label vpn export",
6432 NO_STR
6433 "label value for VRF\n"
6434 "Between current address-family and vpn\n"
6435 "For routes leaked from current address-family to vpn\n")
6436
6437 DEFPY (af_nexthop_vpn_export,
6438 af_nexthop_vpn_export_cmd,
6439 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6440 NO_STR
6441 "Specify next hop to use for VRF advertised prefixes\n"
6442 "Between current address-family and vpn\n"
6443 "For routes leaked from current address-family to vpn\n"
6444 "IPv4 prefix\n"
6445 "IPv6 prefix\n")
6446 {
6447 VTY_DECLVAR_CONTEXT(bgp, bgp);
6448 afi_t afi;
6449 struct prefix p;
6450 int idx = 0;
6451 int yes = 1;
6452
6453 if (argv_find(argv, argc, "no", &idx))
6454 yes = 0;
6455
6456 if (yes) {
6457 if (!sockunion2hostprefix(nexthop_str, &p))
6458 return CMD_WARNING_CONFIG_FAILED;
6459 }
6460
6461 afi = vpn_policy_getafi(vty, bgp, false);
6462 if (afi == AFI_MAX)
6463 return CMD_WARNING_CONFIG_FAILED;
6464
6465 /*
6466 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6467 */
6468 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6469 bgp_get_default(), bgp);
6470
6471 if (yes) {
6472 bgp->vpn_policy[afi].tovpn_nexthop = p;
6473 SET_FLAG(bgp->vpn_policy[afi].flags,
6474 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6475 } else {
6476 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6477 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6478 }
6479
6480 /* post-change: re-export vpn routes */
6481 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6482 bgp_get_default(), bgp);
6483
6484 return CMD_SUCCESS;
6485 }
6486
6487 ALIAS (af_nexthop_vpn_export,
6488 af_no_nexthop_vpn_export_cmd,
6489 "no nexthop vpn export",
6490 NO_STR
6491 "Specify next hop to use for VRF advertised prefixes\n"
6492 "Between current address-family and vpn\n"
6493 "For routes leaked from current address-family to vpn\n")
6494
6495 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6496 {
6497 if (!strcmp(dstr, "import")) {
6498 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6499 } else if (!strcmp(dstr, "export")) {
6500 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6501 } else if (!strcmp(dstr, "both")) {
6502 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6503 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6504 } else {
6505 vty_out(vty, "%% direction parse error\n");
6506 return CMD_WARNING_CONFIG_FAILED;
6507 }
6508 return CMD_SUCCESS;
6509 }
6510
6511 DEFPY (af_rt_vpn_imexport,
6512 af_rt_vpn_imexport_cmd,
6513 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6514 NO_STR
6515 "Specify route target list\n"
6516 "Specify route target list\n"
6517 "Between current address-family and vpn\n"
6518 "For routes leaked from vpn to current address-family: match any\n"
6519 "For routes leaked from current address-family to vpn: set\n"
6520 "both import: match any and export: set\n"
6521 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6522 {
6523 VTY_DECLVAR_CONTEXT(bgp, bgp);
6524 int ret;
6525 struct ecommunity *ecom = NULL;
6526 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6527 vpn_policy_direction_t dir;
6528 afi_t afi;
6529 int idx = 0;
6530 int yes = 1;
6531
6532 if (argv_find(argv, argc, "no", &idx))
6533 yes = 0;
6534
6535 afi = vpn_policy_getafi(vty, bgp, false);
6536 if (afi == AFI_MAX)
6537 return CMD_WARNING_CONFIG_FAILED;
6538
6539 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6540 if (ret != CMD_SUCCESS)
6541 return ret;
6542
6543 if (yes) {
6544 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6545 vty_out(vty, "%% Missing RTLIST\n");
6546 return CMD_WARNING_CONFIG_FAILED;
6547 }
6548 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6549 if (ret != CMD_SUCCESS) {
6550 return ret;
6551 }
6552 }
6553
6554 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6555 if (!dodir[dir])
6556 continue;
6557
6558 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6559
6560 if (yes) {
6561 if (bgp->vpn_policy[afi].rtlist[dir])
6562 ecommunity_free(
6563 &bgp->vpn_policy[afi].rtlist[dir]);
6564 bgp->vpn_policy[afi].rtlist[dir] =
6565 ecommunity_dup(ecom);
6566 } else {
6567 if (bgp->vpn_policy[afi].rtlist[dir])
6568 ecommunity_free(
6569 &bgp->vpn_policy[afi].rtlist[dir]);
6570 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6571 }
6572
6573 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6574 }
6575
6576 if (ecom)
6577 ecommunity_free(&ecom);
6578
6579 return CMD_SUCCESS;
6580 }
6581
6582 ALIAS (af_rt_vpn_imexport,
6583 af_no_rt_vpn_imexport_cmd,
6584 "no <rt|route-target> vpn <import|export|both>$direction_str",
6585 NO_STR
6586 "Specify route target list\n"
6587 "Specify route target list\n"
6588 "Between current address-family and vpn\n"
6589 "For routes leaked from vpn to current address-family\n"
6590 "For routes leaked from current address-family to vpn\n"
6591 "both import and export\n")
6592
6593 DEFPY (af_route_map_vpn_imexport,
6594 af_route_map_vpn_imexport_cmd,
6595 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6596 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6597 NO_STR
6598 "Specify route map\n"
6599 "Between current address-family and vpn\n"
6600 "For routes leaked from vpn to current address-family\n"
6601 "For routes leaked from current address-family to vpn\n"
6602 "name of route-map\n")
6603 {
6604 VTY_DECLVAR_CONTEXT(bgp, bgp);
6605 int ret;
6606 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6607 vpn_policy_direction_t dir;
6608 afi_t afi;
6609 int idx = 0;
6610 int yes = 1;
6611
6612 if (argv_find(argv, argc, "no", &idx))
6613 yes = 0;
6614
6615 afi = vpn_policy_getafi(vty, bgp, false);
6616 if (afi == AFI_MAX)
6617 return CMD_WARNING_CONFIG_FAILED;
6618
6619 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6620 if (ret != CMD_SUCCESS)
6621 return ret;
6622
6623 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6624 if (!dodir[dir])
6625 continue;
6626
6627 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6628
6629 if (yes) {
6630 if (bgp->vpn_policy[afi].rmap_name[dir])
6631 XFREE(MTYPE_ROUTE_MAP_NAME,
6632 bgp->vpn_policy[afi].rmap_name[dir]);
6633 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6634 MTYPE_ROUTE_MAP_NAME, rmap_str);
6635 bgp->vpn_policy[afi].rmap[dir] =
6636 route_map_lookup_by_name(rmap_str);
6637 if (!bgp->vpn_policy[afi].rmap[dir])
6638 return CMD_SUCCESS;
6639 } else {
6640 if (bgp->vpn_policy[afi].rmap_name[dir])
6641 XFREE(MTYPE_ROUTE_MAP_NAME,
6642 bgp->vpn_policy[afi].rmap_name[dir]);
6643 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6644 bgp->vpn_policy[afi].rmap[dir] = NULL;
6645 }
6646
6647 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6648 }
6649
6650 return CMD_SUCCESS;
6651 }
6652
6653 ALIAS (af_route_map_vpn_imexport,
6654 af_no_route_map_vpn_imexport_cmd,
6655 "no route-map vpn <import|export>$direction_str",
6656 NO_STR
6657 "Specify route map\n"
6658 "Between current address-family and vpn\n"
6659 "For routes leaked from vpn to current address-family\n"
6660 "For routes leaked from current address-family to vpn\n")
6661
6662 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6663 "[no] import vrf route-map RMAP$rmap_str",
6664 NO_STR
6665 "Import routes from another VRF\n"
6666 "Vrf routes being filtered\n"
6667 "Specify route map\n"
6668 "name of route-map\n")
6669 {
6670 VTY_DECLVAR_CONTEXT(bgp, bgp);
6671 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6672 afi_t afi;
6673 int idx = 0;
6674 int yes = 1;
6675 struct bgp *bgp_default;
6676
6677 if (argv_find(argv, argc, "no", &idx))
6678 yes = 0;
6679
6680 afi = vpn_policy_getafi(vty, bgp, true);
6681 if (afi == AFI_MAX)
6682 return CMD_WARNING_CONFIG_FAILED;
6683
6684 bgp_default = bgp_get_default();
6685 if (!bgp_default) {
6686 int32_t ret;
6687 as_t as = bgp->as;
6688
6689 /* Auto-create assuming the same AS */
6690 ret = bgp_get(&bgp_default, &as, NULL,
6691 BGP_INSTANCE_TYPE_DEFAULT);
6692
6693 if (ret) {
6694 vty_out(vty,
6695 "VRF default is not configured as a bgp instance\n");
6696 return CMD_WARNING;
6697 }
6698 }
6699
6700 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6701
6702 if (yes) {
6703 if (bgp->vpn_policy[afi].rmap_name[dir])
6704 XFREE(MTYPE_ROUTE_MAP_NAME,
6705 bgp->vpn_policy[afi].rmap_name[dir]);
6706 bgp->vpn_policy[afi].rmap_name[dir] =
6707 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6708 bgp->vpn_policy[afi].rmap[dir] =
6709 route_map_lookup_by_name(rmap_str);
6710 if (!bgp->vpn_policy[afi].rmap[dir])
6711 return CMD_SUCCESS;
6712 } else {
6713 if (bgp->vpn_policy[afi].rmap_name[dir])
6714 XFREE(MTYPE_ROUTE_MAP_NAME,
6715 bgp->vpn_policy[afi].rmap_name[dir]);
6716 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6717 bgp->vpn_policy[afi].rmap[dir] = NULL;
6718 }
6719
6720 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6721
6722 return CMD_SUCCESS;
6723 }
6724
6725 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6726 "no import vrf route-map",
6727 NO_STR
6728 "Import routes from another VRF\n"
6729 "Vrf routes being filtered\n"
6730 "Specify route map\n")
6731
6732 DEFPY (bgp_imexport_vrf,
6733 bgp_imexport_vrf_cmd,
6734 "[no] import vrf NAME$import_name",
6735 NO_STR
6736 "Import routes from another VRF\n"
6737 "VRF to import from\n"
6738 "The name of the VRF\n")
6739 {
6740 VTY_DECLVAR_CONTEXT(bgp, bgp);
6741 struct listnode *node;
6742 struct bgp *vrf_bgp, *bgp_default;
6743 int32_t ret = 0;
6744 as_t as = bgp->as;
6745 bool remove = false;
6746 int32_t idx = 0;
6747 char *vname;
6748 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6749 safi_t safi;
6750 afi_t afi;
6751
6752 if (import_name == NULL) {
6753 vty_out(vty, "%% Missing import name\n");
6754 return CMD_WARNING;
6755 }
6756
6757 if (argv_find(argv, argc, "no", &idx))
6758 remove = true;
6759
6760 afi = vpn_policy_getafi(vty, bgp, true);
6761 if (afi == AFI_MAX)
6762 return CMD_WARNING_CONFIG_FAILED;
6763
6764 safi = bgp_node_safi(vty);
6765
6766 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6767 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6768 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6769 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6770 remove ? "unimport" : "import", import_name);
6771 return CMD_WARNING;
6772 }
6773
6774 bgp_default = bgp_get_default();
6775 if (!bgp_default) {
6776 /* Auto-create assuming the same AS */
6777 ret = bgp_get(&bgp_default, &as, NULL,
6778 BGP_INSTANCE_TYPE_DEFAULT);
6779
6780 if (ret) {
6781 vty_out(vty,
6782 "VRF default is not configured as a bgp instance\n");
6783 return CMD_WARNING;
6784 }
6785 }
6786
6787 vrf_bgp = bgp_lookup_by_name(import_name);
6788 if (!vrf_bgp) {
6789 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6790 vrf_bgp = bgp_default;
6791 else
6792 /* Auto-create assuming the same AS */
6793 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6794
6795 if (ret) {
6796 vty_out(vty,
6797 "VRF %s is not configured as a bgp instance\n",
6798 import_name);
6799 return CMD_WARNING;
6800 }
6801 }
6802
6803 if (remove) {
6804 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6805 } else {
6806 /* Already importing from "import_vrf"? */
6807 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6808 vname)) {
6809 if (strcmp(vname, import_name) == 0)
6810 return CMD_WARNING;
6811 }
6812
6813 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6814 }
6815
6816 return CMD_SUCCESS;
6817 }
6818
6819 /* This command is valid only in a bgp vrf instance or the default instance */
6820 DEFPY (bgp_imexport_vpn,
6821 bgp_imexport_vpn_cmd,
6822 "[no] <import|export>$direction_str vpn",
6823 NO_STR
6824 "Import routes to this address-family\n"
6825 "Export routes from this address-family\n"
6826 "to/from default instance VPN RIB\n")
6827 {
6828 VTY_DECLVAR_CONTEXT(bgp, bgp);
6829 int previous_state;
6830 afi_t afi;
6831 safi_t safi;
6832 int idx = 0;
6833 int yes = 1;
6834 int flag;
6835 vpn_policy_direction_t dir;
6836
6837 if (argv_find(argv, argc, "no", &idx))
6838 yes = 0;
6839
6840 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6841 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6842
6843 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6844 return CMD_WARNING_CONFIG_FAILED;
6845 }
6846
6847 afi = bgp_node_afi(vty);
6848 safi = bgp_node_safi(vty);
6849 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6850 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6851 return CMD_WARNING_CONFIG_FAILED;
6852 }
6853
6854 if (!strcmp(direction_str, "import")) {
6855 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6856 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6857 } else if (!strcmp(direction_str, "export")) {
6858 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6859 dir = BGP_VPN_POLICY_DIR_TOVPN;
6860 } else {
6861 vty_out(vty, "%% unknown direction %s\n", direction_str);
6862 return CMD_WARNING_CONFIG_FAILED;
6863 }
6864
6865 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6866
6867 if (yes) {
6868 SET_FLAG(bgp->af_flags[afi][safi], flag);
6869 if (!previous_state) {
6870 /* trigger export current vrf */
6871 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6872 }
6873 } else {
6874 if (previous_state) {
6875 /* trigger un-export current vrf */
6876 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6877 }
6878 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6879 }
6880
6881 return CMD_SUCCESS;
6882 }
6883
6884 DEFPY (af_routetarget_import,
6885 af_routetarget_import_cmd,
6886 "[no] <rt|route-target> redirect import RTLIST...",
6887 NO_STR
6888 "Specify route target list\n"
6889 "Specify route target list\n"
6890 "Flow-spec redirect type route target\n"
6891 "Import routes to this address-family\n"
6892 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6893 {
6894 VTY_DECLVAR_CONTEXT(bgp, bgp);
6895 int ret;
6896 struct ecommunity *ecom = NULL;
6897 afi_t afi;
6898 int idx = 0;
6899 int yes = 1;
6900
6901 if (argv_find(argv, argc, "no", &idx))
6902 yes = 0;
6903
6904 afi = vpn_policy_getafi(vty, bgp, false);
6905 if (afi == AFI_MAX)
6906 return CMD_WARNING_CONFIG_FAILED;
6907
6908 if (yes) {
6909 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6910 vty_out(vty, "%% Missing RTLIST\n");
6911 return CMD_WARNING_CONFIG_FAILED;
6912 }
6913 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6914 if (ret != CMD_SUCCESS)
6915 return ret;
6916 }
6917
6918 if (yes) {
6919 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6920 ecommunity_free(&bgp->vpn_policy[afi]
6921 .import_redirect_rtlist);
6922 bgp->vpn_policy[afi].import_redirect_rtlist =
6923 ecommunity_dup(ecom);
6924 } else {
6925 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6926 ecommunity_free(&bgp->vpn_policy[afi]
6927 .import_redirect_rtlist);
6928 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6929 }
6930
6931 if (ecom)
6932 ecommunity_free(&ecom);
6933
6934 return CMD_SUCCESS;
6935 }
6936
6937 DEFUN_NOSH (address_family_ipv4_safi,
6938 address_family_ipv4_safi_cmd,
6939 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6940 "Enter Address Family command mode\n"
6941 "Address Family\n"
6942 BGP_SAFI_WITH_LABEL_HELP_STR)
6943 {
6944
6945 if (argc == 3) {
6946 VTY_DECLVAR_CONTEXT(bgp, bgp);
6947 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6948 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6949 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6950 && safi != SAFI_EVPN) {
6951 vty_out(vty,
6952 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6953 return CMD_WARNING_CONFIG_FAILED;
6954 }
6955 vty->node = bgp_node_type(AFI_IP, safi);
6956 } else
6957 vty->node = BGP_IPV4_NODE;
6958
6959 return CMD_SUCCESS;
6960 }
6961
6962 DEFUN_NOSH (address_family_ipv6_safi,
6963 address_family_ipv6_safi_cmd,
6964 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6965 "Enter Address Family command mode\n"
6966 "Address Family\n"
6967 BGP_SAFI_WITH_LABEL_HELP_STR)
6968 {
6969 if (argc == 3) {
6970 VTY_DECLVAR_CONTEXT(bgp, bgp);
6971 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6972 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6973 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6974 && safi != SAFI_EVPN) {
6975 vty_out(vty,
6976 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6977 return CMD_WARNING_CONFIG_FAILED;
6978 }
6979 vty->node = bgp_node_type(AFI_IP6, safi);
6980 } else
6981 vty->node = BGP_IPV6_NODE;
6982
6983 return CMD_SUCCESS;
6984 }
6985
6986 #ifdef KEEP_OLD_VPN_COMMANDS
6987 DEFUN_NOSH (address_family_vpnv4,
6988 address_family_vpnv4_cmd,
6989 "address-family vpnv4 [unicast]",
6990 "Enter Address Family command mode\n"
6991 "Address Family\n"
6992 "Address Family modifier\n")
6993 {
6994 vty->node = BGP_VPNV4_NODE;
6995 return CMD_SUCCESS;
6996 }
6997
6998 DEFUN_NOSH (address_family_vpnv6,
6999 address_family_vpnv6_cmd,
7000 "address-family vpnv6 [unicast]",
7001 "Enter Address Family command mode\n"
7002 "Address Family\n"
7003 "Address Family modifier\n")
7004 {
7005 vty->node = BGP_VPNV6_NODE;
7006 return CMD_SUCCESS;
7007 }
7008 #endif
7009
7010 DEFUN_NOSH (address_family_evpn,
7011 address_family_evpn_cmd,
7012 "address-family l2vpn evpn",
7013 "Enter Address Family command mode\n"
7014 "Address Family\n"
7015 "Address Family modifier\n")
7016 {
7017 VTY_DECLVAR_CONTEXT(bgp, bgp);
7018 vty->node = BGP_EVPN_NODE;
7019 return CMD_SUCCESS;
7020 }
7021
7022 DEFUN_NOSH (exit_address_family,
7023 exit_address_family_cmd,
7024 "exit-address-family",
7025 "Exit from Address Family configuration mode\n")
7026 {
7027 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7028 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7029 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7030 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7031 || vty->node == BGP_EVPN_NODE
7032 || vty->node == BGP_FLOWSPECV4_NODE
7033 || vty->node == BGP_FLOWSPECV6_NODE)
7034 vty->node = BGP_NODE;
7035 return CMD_SUCCESS;
7036 }
7037
7038 /* Recalculate bestpath and re-advertise a prefix */
7039 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7040 const char *ip_str, afi_t afi, safi_t safi,
7041 struct prefix_rd *prd)
7042 {
7043 int ret;
7044 struct prefix match;
7045 struct bgp_node *rn;
7046 struct bgp_node *rm;
7047 struct bgp *bgp;
7048 struct bgp_table *table;
7049 struct bgp_table *rib;
7050
7051 /* BGP structure lookup. */
7052 if (view_name) {
7053 bgp = bgp_lookup_by_name(view_name);
7054 if (bgp == NULL) {
7055 vty_out(vty, "%% Can't find BGP instance %s\n",
7056 view_name);
7057 return CMD_WARNING;
7058 }
7059 } else {
7060 bgp = bgp_get_default();
7061 if (bgp == NULL) {
7062 vty_out(vty, "%% No BGP process is configured\n");
7063 return CMD_WARNING;
7064 }
7065 }
7066
7067 /* Check IP address argument. */
7068 ret = str2prefix(ip_str, &match);
7069 if (!ret) {
7070 vty_out(vty, "%% address is malformed\n");
7071 return CMD_WARNING;
7072 }
7073
7074 match.family = afi2family(afi);
7075 rib = bgp->rib[afi][safi];
7076
7077 if (safi == SAFI_MPLS_VPN) {
7078 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7079 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7080 continue;
7081
7082 if ((table = rn->info) != NULL) {
7083 if ((rm = bgp_node_match(table, &match))
7084 != NULL) {
7085 if (rm->p.prefixlen
7086 == match.prefixlen) {
7087 SET_FLAG(rm->flags,
7088 BGP_NODE_USER_CLEAR);
7089 bgp_process(bgp, rm, afi, safi);
7090 }
7091 bgp_unlock_node(rm);
7092 }
7093 }
7094 }
7095 } else {
7096 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7097 if (rn->p.prefixlen == match.prefixlen) {
7098 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7099 bgp_process(bgp, rn, afi, safi);
7100 }
7101 bgp_unlock_node(rn);
7102 }
7103 }
7104
7105 return CMD_SUCCESS;
7106 }
7107
7108 /* one clear bgp command to rule them all */
7109 DEFUN (clear_ip_bgp_all,
7110 clear_ip_bgp_all_cmd,
7111 "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>]",
7112 CLEAR_STR
7113 IP_STR
7114 BGP_STR
7115 BGP_INSTANCE_HELP_STR
7116 BGP_AFI_HELP_STR
7117 BGP_SAFI_WITH_LABEL_HELP_STR
7118 "Clear all peers\n"
7119 "BGP neighbor address to clear\n"
7120 "BGP IPv6 neighbor to clear\n"
7121 "BGP neighbor on interface to clear\n"
7122 "Clear peers with the AS number\n"
7123 "Clear all external peers\n"
7124 "Clear all members of peer-group\n"
7125 "BGP peer-group name\n"
7126 BGP_SOFT_STR
7127 BGP_SOFT_IN_STR
7128 BGP_SOFT_OUT_STR
7129 BGP_SOFT_IN_STR
7130 "Push out prefix-list ORF and do inbound soft reconfig\n"
7131 BGP_SOFT_OUT_STR)
7132 {
7133 char *vrf = NULL;
7134
7135 afi_t afi = AFI_IP6;
7136 safi_t safi = SAFI_UNICAST;
7137 enum clear_sort clr_sort = clear_peer;
7138 enum bgp_clear_type clr_type;
7139 char *clr_arg = NULL;
7140
7141 int idx = 0;
7142
7143 /* clear [ip] bgp */
7144 if (argv_find(argv, argc, "ip", &idx))
7145 afi = AFI_IP;
7146
7147 /* [<view|vrf> VIEWVRFNAME] */
7148 if (argv_find(argv, argc, "view", &idx)
7149 || argv_find(argv, argc, "vrf", &idx)) {
7150 vrf = argv[idx + 1]->arg;
7151 idx += 2;
7152 }
7153
7154 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7155 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7156 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7157
7158 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7159 if (argv_find(argv, argc, "*", &idx)) {
7160 clr_sort = clear_all;
7161 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7162 clr_sort = clear_peer;
7163 clr_arg = argv[idx]->arg;
7164 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7165 clr_sort = clear_peer;
7166 clr_arg = argv[idx]->arg;
7167 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7168 clr_sort = clear_group;
7169 idx++;
7170 clr_arg = argv[idx]->arg;
7171 } else if (argv_find(argv, argc, "WORD", &idx)) {
7172 clr_sort = clear_peer;
7173 clr_arg = argv[idx]->arg;
7174 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7175 clr_sort = clear_as;
7176 clr_arg = argv[idx]->arg;
7177 } else if (argv_find(argv, argc, "external", &idx)) {
7178 clr_sort = clear_external;
7179 }
7180
7181 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7182 if (argv_find(argv, argc, "soft", &idx)) {
7183 if (argv_find(argv, argc, "in", &idx)
7184 || argv_find(argv, argc, "out", &idx))
7185 clr_type = strmatch(argv[idx]->text, "in")
7186 ? BGP_CLEAR_SOFT_IN
7187 : BGP_CLEAR_SOFT_OUT;
7188 else
7189 clr_type = BGP_CLEAR_SOFT_BOTH;
7190 } else if (argv_find(argv, argc, "in", &idx)) {
7191 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7192 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7193 : BGP_CLEAR_SOFT_IN;
7194 } else if (argv_find(argv, argc, "out", &idx)) {
7195 clr_type = BGP_CLEAR_SOFT_OUT;
7196 } else
7197 clr_type = BGP_CLEAR_SOFT_NONE;
7198
7199 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7200 }
7201
7202 DEFUN (clear_ip_bgp_prefix,
7203 clear_ip_bgp_prefix_cmd,
7204 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7205 CLEAR_STR
7206 IP_STR
7207 BGP_STR
7208 BGP_INSTANCE_HELP_STR
7209 "Clear bestpath and re-advertise\n"
7210 "IPv4 prefix\n")
7211 {
7212 char *vrf = NULL;
7213 char *prefix = NULL;
7214
7215 int idx = 0;
7216
7217 /* [<view|vrf> VIEWVRFNAME] */
7218 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7219 vrf = argv[idx]->arg;
7220
7221 prefix = argv[argc - 1]->arg;
7222
7223 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7224 }
7225
7226 DEFUN (clear_bgp_ipv6_safi_prefix,
7227 clear_bgp_ipv6_safi_prefix_cmd,
7228 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7229 CLEAR_STR
7230 IP_STR
7231 BGP_STR
7232 "Address Family\n"
7233 BGP_SAFI_HELP_STR
7234 "Clear bestpath and re-advertise\n"
7235 "IPv6 prefix\n")
7236 {
7237 int idx_safi = 0;
7238 int idx_ipv6_prefix = 0;
7239 safi_t safi = SAFI_UNICAST;
7240 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7241 argv[idx_ipv6_prefix]->arg : NULL;
7242
7243 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7244 return bgp_clear_prefix(
7245 vty, NULL, prefix, AFI_IP6,
7246 safi, NULL);
7247 }
7248
7249 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7250 clear_bgp_instance_ipv6_safi_prefix_cmd,
7251 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7252 CLEAR_STR
7253 IP_STR
7254 BGP_STR
7255 BGP_INSTANCE_HELP_STR
7256 "Address Family\n"
7257 BGP_SAFI_HELP_STR
7258 "Clear bestpath and re-advertise\n"
7259 "IPv6 prefix\n")
7260 {
7261 int idx_word = 3;
7262 int idx_safi = 0;
7263 int idx_ipv6_prefix = 0;
7264 safi_t safi = SAFI_UNICAST;
7265 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7266 argv[idx_ipv6_prefix]->arg : NULL;
7267 /* [<view|vrf> VIEWVRFNAME] */
7268 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7269 argv[idx_word]->arg : NULL;
7270
7271 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7272
7273 return bgp_clear_prefix(
7274 vty, vrfview, prefix,
7275 AFI_IP6, safi, NULL);
7276 }
7277
7278 DEFUN (show_bgp_views,
7279 show_bgp_views_cmd,
7280 "show [ip] bgp views",
7281 SHOW_STR
7282 IP_STR
7283 BGP_STR
7284 "Show the defined BGP views\n")
7285 {
7286 struct list *inst = bm->bgp;
7287 struct listnode *node;
7288 struct bgp *bgp;
7289
7290 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7291 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7292 return CMD_WARNING;
7293 }
7294
7295 vty_out(vty, "Defined BGP views:\n");
7296 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7297 /* Skip VRFs. */
7298 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7299 continue;
7300 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7301 bgp->as);
7302 }
7303
7304 return CMD_SUCCESS;
7305 }
7306
7307 DEFUN (show_bgp_vrfs,
7308 show_bgp_vrfs_cmd,
7309 "show [ip] bgp vrfs [json]",
7310 SHOW_STR
7311 IP_STR
7312 BGP_STR
7313 "Show BGP VRFs\n"
7314 JSON_STR)
7315 {
7316 char buf[ETHER_ADDR_STRLEN];
7317 struct list *inst = bm->bgp;
7318 struct listnode *node;
7319 struct bgp *bgp;
7320 uint8_t uj = use_json(argc, argv);
7321 json_object *json = NULL;
7322 json_object *json_vrfs = NULL;
7323 int count = 0;
7324
7325 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7326 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7327 return CMD_WARNING;
7328 }
7329
7330 if (uj) {
7331 json = json_object_new_object();
7332 json_vrfs = json_object_new_object();
7333 }
7334
7335 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7336 const char *name, *type;
7337 struct peer *peer;
7338 struct listnode *node, *nnode;
7339 int peers_cfg, peers_estb;
7340 json_object *json_vrf = NULL;
7341
7342 /* Skip Views. */
7343 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7344 continue;
7345
7346 count++;
7347 if (!uj && count == 1)
7348 vty_out(vty,
7349 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7350 "Type", "Id", "routerId", "#PeersVfg",
7351 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7352
7353 peers_cfg = peers_estb = 0;
7354 if (uj)
7355 json_vrf = json_object_new_object();
7356
7357
7358 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7359 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7360 continue;
7361 peers_cfg++;
7362 if (peer->status == Established)
7363 peers_estb++;
7364 }
7365
7366 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7367 name = "Default";
7368 type = "DFLT";
7369 } else {
7370 name = bgp->name;
7371 type = "VRF";
7372 }
7373
7374
7375 if (uj) {
7376 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7377 ? -1
7378 : (int64_t)bgp->vrf_id;
7379 json_object_string_add(json_vrf, "type", type);
7380 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7381 json_object_string_add(json_vrf, "routerId",
7382 inet_ntoa(bgp->router_id));
7383 json_object_int_add(json_vrf, "numConfiguredPeers",
7384 peers_cfg);
7385 json_object_int_add(json_vrf, "numEstablishedPeers",
7386 peers_estb);
7387
7388 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7389 json_object_string_add(
7390 json_vrf, "rmac",
7391 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7392 json_object_object_add(json_vrfs, name, json_vrf);
7393 } else
7394 vty_out(vty,
7395 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7396 type,
7397 bgp->vrf_id == VRF_UNKNOWN ? -1
7398 : (int)bgp->vrf_id,
7399 inet_ntoa(bgp->router_id), peers_cfg,
7400 peers_estb, name, bgp->l3vni,
7401 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7402 }
7403
7404 if (uj) {
7405 json_object_object_add(json, "vrfs", json_vrfs);
7406
7407 json_object_int_add(json, "totalVrfs", count);
7408
7409 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7410 json, JSON_C_TO_STRING_PRETTY));
7411 json_object_free(json);
7412 } else {
7413 if (count)
7414 vty_out(vty,
7415 "\nTotal number of VRFs (including default): %d\n",
7416 count);
7417 }
7418
7419 return CMD_SUCCESS;
7420 }
7421
7422 static void show_address_entry(struct hash_backet *backet, void *args)
7423 {
7424 struct vty *vty = (struct vty *)args;
7425 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7426
7427 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7428 addr->refcnt);
7429 }
7430
7431 static void show_tip_entry(struct hash_backet *backet, void *args)
7432 {
7433 struct vty *vty = (struct vty *)args;
7434 struct tip_addr *tip = (struct tip_addr *)backet->data;
7435
7436 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7437 tip->refcnt);
7438 }
7439
7440 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7441 {
7442 vty_out(vty, "self nexthop database:\n");
7443 hash_iterate(bgp->address_hash,
7444 (void (*)(struct hash_backet *, void *))show_address_entry,
7445 vty);
7446
7447 vty_out(vty, "Tunnel-ip database:\n");
7448 hash_iterate(bgp->tip_hash,
7449 (void (*)(struct hash_backet *, void *))show_tip_entry,
7450 vty);
7451 }
7452
7453 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7454 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7455 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7456 "martian next-hops\n"
7457 "martian next-hop database\n")
7458 {
7459 struct bgp *bgp = NULL;
7460 int idx = 0;
7461
7462 if (argv_find(argv, argc, "view", &idx)
7463 || argv_find(argv, argc, "vrf", &idx))
7464 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7465 else
7466 bgp = bgp_get_default();
7467
7468 if (!bgp) {
7469 vty_out(vty, "%% No BGP process is configured\n");
7470 return CMD_WARNING;
7471 }
7472 bgp_show_martian_nexthops(vty, bgp);
7473
7474 return CMD_SUCCESS;
7475 }
7476
7477 DEFUN (show_bgp_memory,
7478 show_bgp_memory_cmd,
7479 "show [ip] bgp memory",
7480 SHOW_STR
7481 IP_STR
7482 BGP_STR
7483 "Global BGP memory statistics\n")
7484 {
7485 char memstrbuf[MTYPE_MEMSTR_LEN];
7486 unsigned long count;
7487
7488 /* RIB related usage stats */
7489 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7490 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7491 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7492 count * sizeof(struct bgp_node)));
7493
7494 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7495 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7497 count * sizeof(struct bgp_info)));
7498 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7499 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7500 count,
7501 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7502 count * sizeof(struct bgp_info_extra)));
7503
7504 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7505 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7506 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7507 count * sizeof(struct bgp_static)));
7508
7509 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7510 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7511 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7512 count * sizeof(struct bpacket)));
7513
7514 /* Adj-In/Out */
7515 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7516 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7517 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7518 count * sizeof(struct bgp_adj_in)));
7519 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7520 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7522 count * sizeof(struct bgp_adj_out)));
7523
7524 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7525 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7526 count,
7527 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7528 count * sizeof(struct bgp_nexthop_cache)));
7529
7530 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7531 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7532 count,
7533 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7534 count * sizeof(struct bgp_damp_info)));
7535
7536 /* Attributes */
7537 count = attr_count();
7538 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7539 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7540 count * sizeof(struct attr)));
7541
7542 if ((count = attr_unknown_count()))
7543 vty_out(vty, "%ld unknown attributes\n", count);
7544
7545 /* AS_PATH attributes */
7546 count = aspath_count();
7547 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7548 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7549 count * sizeof(struct aspath)));
7550
7551 count = mtype_stats_alloc(MTYPE_AS_SEG);
7552 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7553 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7554 count * sizeof(struct assegment)));
7555
7556 /* Other attributes */
7557 if ((count = community_count()))
7558 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7559 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7560 count * sizeof(struct community)));
7561 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7562 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7563 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7564 count * sizeof(struct ecommunity)));
7565 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7566 vty_out(vty,
7567 "%ld BGP large-community entries, using %s of memory\n",
7568 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7569 count * sizeof(struct lcommunity)));
7570
7571 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7572 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7573 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(struct cluster_list)));
7575
7576 /* Peer related usage */
7577 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7578 vty_out(vty, "%ld peers, using %s of memory\n", count,
7579 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7580 count * sizeof(struct peer)));
7581
7582 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7583 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7584 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7585 count * sizeof(struct peer_group)));
7586
7587 /* Other */
7588 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7589 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7590 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7591 count * sizeof(struct hash)));
7592 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7593 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7594 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7595 count * sizeof(struct hash_backet)));
7596 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7597 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7598 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7599 count * sizeof(regex_t)));
7600 return CMD_SUCCESS;
7601 }
7602
7603 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7604 {
7605 json_object *bestpath = json_object_new_object();
7606
7607 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7608 json_object_string_add(bestpath, "asPath", "ignore");
7609
7610 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7611 json_object_string_add(bestpath, "asPath", "confed");
7612
7613 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7614 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7615 json_object_string_add(bestpath, "multiPathRelax",
7616 "as-set");
7617 else
7618 json_object_string_add(bestpath, "multiPathRelax",
7619 "true");
7620 } else
7621 json_object_string_add(bestpath, "multiPathRelax", "false");
7622
7623 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7624 json_object_string_add(bestpath, "compareRouterId", "true");
7625 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7626 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7627 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7628 json_object_string_add(bestpath, "med", "confed");
7629 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7630 json_object_string_add(bestpath, "med",
7631 "missing-as-worst");
7632 else
7633 json_object_string_add(bestpath, "med", "true");
7634 }
7635
7636 json_object_object_add(json, "bestPath", bestpath);
7637 }
7638
7639 /* Show BGP peer's summary information. */
7640 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7641 uint8_t use_json, json_object *json)
7642 {
7643 struct peer *peer;
7644 struct listnode *node, *nnode;
7645 unsigned int count = 0, dn_count = 0;
7646 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7647 char neighbor_buf[VTY_BUFSIZ];
7648 int neighbor_col_default_width = 16;
7649 int len;
7650 int max_neighbor_width = 0;
7651 int pfx_rcd_safi;
7652 json_object *json_peer = NULL;
7653 json_object *json_peers = NULL;
7654
7655 /* labeled-unicast routes are installed in the unicast table so in order
7656 * to
7657 * display the correct PfxRcd value we must look at SAFI_UNICAST
7658 */
7659 if (safi == SAFI_LABELED_UNICAST)
7660 pfx_rcd_safi = SAFI_UNICAST;
7661 else
7662 pfx_rcd_safi = safi;
7663
7664 if (use_json) {
7665 if (json == NULL)
7666 json = json_object_new_object();
7667
7668 json_peers = json_object_new_object();
7669 } else {
7670 /* Loop over all neighbors that will be displayed to determine
7671 * how many
7672 * characters are needed for the Neighbor column
7673 */
7674 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7675 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7676 continue;
7677
7678 if (peer->afc[afi][safi]) {
7679 memset(dn_flag, '\0', sizeof(dn_flag));
7680 if (peer_dynamic_neighbor(peer))
7681 dn_flag[0] = '*';
7682
7683 if (peer->hostname
7684 && bgp_flag_check(bgp,
7685 BGP_FLAG_SHOW_HOSTNAME))
7686 sprintf(neighbor_buf, "%s%s(%s) ",
7687 dn_flag, peer->hostname,
7688 peer->host);
7689 else
7690 sprintf(neighbor_buf, "%s%s ", dn_flag,
7691 peer->host);
7692
7693 len = strlen(neighbor_buf);
7694
7695 if (len > max_neighbor_width)
7696 max_neighbor_width = len;
7697 }
7698 }
7699
7700 /* Originally we displayed the Neighbor column as 16
7701 * characters wide so make that the default
7702 */
7703 if (max_neighbor_width < neighbor_col_default_width)
7704 max_neighbor_width = neighbor_col_default_width;
7705 }
7706
7707 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7708 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7709 continue;
7710
7711 if (!peer->afc[afi][safi])
7712 continue;
7713
7714 if (!count) {
7715 unsigned long ents;
7716 char memstrbuf[MTYPE_MEMSTR_LEN];
7717 int64_t vrf_id_ui;
7718
7719 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7720 ? -1
7721 : (int64_t)bgp->vrf_id;
7722
7723 /* Usage summary and header */
7724 if (use_json) {
7725 json_object_string_add(
7726 json, "routerId",
7727 inet_ntoa(bgp->router_id));
7728 json_object_int_add(json, "as", bgp->as);
7729 json_object_int_add(json, "vrfId", vrf_id_ui);
7730 json_object_string_add(
7731 json, "vrfName",
7732 (bgp->inst_type
7733 == BGP_INSTANCE_TYPE_DEFAULT)
7734 ? "Default"
7735 : bgp->name);
7736 } else {
7737 vty_out(vty,
7738 "BGP router identifier %s, local AS number %u vrf-id %d",
7739 inet_ntoa(bgp->router_id), bgp->as,
7740 bgp->vrf_id == VRF_UNKNOWN
7741 ? -1
7742 : (int)bgp->vrf_id);
7743 vty_out(vty, "\n");
7744 }
7745
7746 if (bgp_update_delay_configured(bgp)) {
7747 if (use_json) {
7748 json_object_int_add(
7749 json, "updateDelayLimit",
7750 bgp->v_update_delay);
7751
7752 if (bgp->v_update_delay
7753 != bgp->v_establish_wait)
7754 json_object_int_add(
7755 json,
7756 "updateDelayEstablishWait",
7757 bgp->v_establish_wait);
7758
7759 if (bgp_update_delay_active(bgp)) {
7760 json_object_string_add(
7761 json,
7762 "updateDelayFirstNeighbor",
7763 bgp->update_delay_begin_time);
7764 json_object_boolean_true_add(
7765 json,
7766 "updateDelayInProgress");
7767 } else {
7768 if (bgp->update_delay_over) {
7769 json_object_string_add(
7770 json,
7771 "updateDelayFirstNeighbor",
7772 bgp->update_delay_begin_time);
7773 json_object_string_add(
7774 json,
7775 "updateDelayBestpathResumed",
7776 bgp->update_delay_end_time);
7777 json_object_string_add(
7778 json,
7779 "updateDelayZebraUpdateResume",
7780 bgp->update_delay_zebra_resume_time);
7781 json_object_string_add(
7782 json,
7783 "updateDelayPeerUpdateResume",
7784 bgp->update_delay_peers_resume_time);
7785 }
7786 }
7787 } else {
7788 vty_out(vty,
7789 "Read-only mode update-delay limit: %d seconds\n",
7790 bgp->v_update_delay);
7791 if (bgp->v_update_delay
7792 != bgp->v_establish_wait)
7793 vty_out(vty,
7794 " Establish wait: %d seconds\n",
7795 bgp->v_establish_wait);
7796
7797 if (bgp_update_delay_active(bgp)) {
7798 vty_out(vty,
7799 " First neighbor established: %s\n",
7800 bgp->update_delay_begin_time);
7801 vty_out(vty,
7802 " Delay in progress\n");
7803 } else {
7804 if (bgp->update_delay_over) {
7805 vty_out(vty,
7806 " First neighbor established: %s\n",
7807 bgp->update_delay_begin_time);
7808 vty_out(vty,
7809 " Best-paths resumed: %s\n",
7810 bgp->update_delay_end_time);
7811 vty_out(vty,
7812 " zebra update resumed: %s\n",
7813 bgp->update_delay_zebra_resume_time);
7814 vty_out(vty,
7815 " peers update resumed: %s\n",
7816 bgp->update_delay_peers_resume_time);
7817 }
7818 }
7819 }
7820 }
7821
7822 if (use_json) {
7823 if (bgp_maxmed_onstartup_configured(bgp)
7824 && bgp->maxmed_active)
7825 json_object_boolean_true_add(
7826 json, "maxMedOnStartup");
7827 if (bgp->v_maxmed_admin)
7828 json_object_boolean_true_add(
7829 json, "maxMedAdministrative");
7830
7831 json_object_int_add(
7832 json, "tableVersion",
7833 bgp_table_version(bgp->rib[afi][safi]));
7834
7835 ents = bgp_table_count(bgp->rib[afi][safi]);
7836 json_object_int_add(json, "ribCount", ents);
7837 json_object_int_add(
7838 json, "ribMemory",
7839 ents * sizeof(struct bgp_node));
7840
7841 ents = listcount(bgp->peer);
7842 json_object_int_add(json, "peerCount", ents);
7843 json_object_int_add(json, "peerMemory",
7844 ents * sizeof(struct peer));
7845
7846 if ((ents = listcount(bgp->group))) {
7847 json_object_int_add(
7848 json, "peerGroupCount", ents);
7849 json_object_int_add(
7850 json, "peerGroupMemory",
7851 ents * sizeof(struct
7852 peer_group));
7853 }
7854
7855 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7856 BGP_CONFIG_DAMPENING))
7857 json_object_boolean_true_add(
7858 json, "dampeningEnabled");
7859 } else {
7860 if (bgp_maxmed_onstartup_configured(bgp)
7861 && bgp->maxmed_active)
7862 vty_out(vty,
7863 "Max-med on-startup active\n");
7864 if (bgp->v_maxmed_admin)
7865 vty_out(vty,
7866 "Max-med administrative active\n");
7867
7868 vty_out(vty, "BGP table version %" PRIu64 "\n",
7869 bgp_table_version(bgp->rib[afi][safi]));
7870
7871 ents = bgp_table_count(bgp->rib[afi][safi]);
7872 vty_out(vty,
7873 "RIB entries %ld, using %s of memory\n",
7874 ents,
7875 mtype_memstr(memstrbuf,
7876 sizeof(memstrbuf),
7877 ents * sizeof(struct
7878 bgp_node)));
7879
7880 /* Peer related usage */
7881 ents = listcount(bgp->peer);
7882 vty_out(vty, "Peers %ld, using %s of memory\n",
7883 ents,
7884 mtype_memstr(
7885 memstrbuf, sizeof(memstrbuf),
7886 ents * sizeof(struct peer)));
7887
7888 if ((ents = listcount(bgp->group)))
7889 vty_out(vty,
7890 "Peer groups %ld, using %s of memory\n",
7891 ents,
7892 mtype_memstr(
7893 memstrbuf,
7894 sizeof(memstrbuf),
7895 ents * sizeof(struct
7896 peer_group)));
7897
7898 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7899 BGP_CONFIG_DAMPENING))
7900 vty_out(vty, "Dampening enabled.\n");
7901 vty_out(vty, "\n");
7902
7903 /* Subtract 8 here because 'Neighbor' is
7904 * 8 characters */
7905 vty_out(vty, "Neighbor");
7906 vty_out(vty, "%*s", max_neighbor_width - 8,
7907 " ");
7908 vty_out(vty,
7909 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7910 }
7911 }
7912
7913 count++;
7914
7915 if (use_json) {
7916 json_peer = json_object_new_object();
7917
7918 if (peer_dynamic_neighbor(peer)) {
7919 dn_count++;
7920 json_object_boolean_true_add(json_peer,
7921 "dynamicPeer");
7922 }
7923
7924 if (peer->hostname)
7925 json_object_string_add(json_peer, "hostname",
7926 peer->hostname);
7927
7928 if (peer->domainname)
7929 json_object_string_add(json_peer, "domainname",
7930 peer->domainname);
7931
7932 json_object_int_add(json_peer, "remoteAs", peer->as);
7933 json_object_int_add(json_peer, "version", 4);
7934 json_object_int_add(json_peer, "msgRcvd",
7935 PEER_TOTAL_RX(peer));
7936 json_object_int_add(json_peer, "msgSent",
7937 PEER_TOTAL_TX(peer));
7938
7939 json_object_int_add(json_peer, "tableVersion",
7940 peer->version[afi][safi]);
7941 json_object_int_add(json_peer, "outq",
7942 peer->obuf->count);
7943 json_object_int_add(json_peer, "inq", 0);
7944 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7945 use_json, json_peer);
7946 json_object_int_add(json_peer, "prefixReceivedCount",
7947 peer->pcount[afi][pfx_rcd_safi]);
7948
7949 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7950 json_object_string_add(json_peer, "state",
7951 "Idle (Admin)");
7952 else if (peer->afc_recv[afi][safi])
7953 json_object_string_add(
7954 json_peer, "state",
7955 lookup_msg(bgp_status_msg, peer->status,
7956 NULL));
7957 else if (CHECK_FLAG(peer->sflags,
7958 PEER_STATUS_PREFIX_OVERFLOW))
7959 json_object_string_add(json_peer, "state",
7960 "Idle (PfxCt)");
7961 else
7962 json_object_string_add(
7963 json_peer, "state",
7964 lookup_msg(bgp_status_msg, peer->status,
7965 NULL));
7966
7967 if (peer->conf_if)
7968 json_object_string_add(json_peer, "idType",
7969 "interface");
7970 else if (peer->su.sa.sa_family == AF_INET)
7971 json_object_string_add(json_peer, "idType",
7972 "ipv4");
7973 else if (peer->su.sa.sa_family == AF_INET6)
7974 json_object_string_add(json_peer, "idType",
7975 "ipv6");
7976
7977 json_object_object_add(json_peers, peer->host,
7978 json_peer);
7979 } else {
7980 memset(dn_flag, '\0', sizeof(dn_flag));
7981 if (peer_dynamic_neighbor(peer)) {
7982 dn_count++;
7983 dn_flag[0] = '*';
7984 }
7985
7986 if (peer->hostname
7987 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7988 len = vty_out(vty, "%s%s(%s)", dn_flag,
7989 peer->hostname, peer->host);
7990 else
7991 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7992
7993 /* pad the neighbor column with spaces */
7994 if (len < max_neighbor_width)
7995 vty_out(vty, "%*s", max_neighbor_width - len,
7996 " ");
7997
7998 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7999 peer->as, PEER_TOTAL_RX(peer),
8000 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8001 0, peer->obuf->count,
8002 peer_uptime(peer->uptime, timebuf,
8003 BGP_UPTIME_LEN, 0, NULL));
8004
8005 if (peer->status == Established)
8006 if (peer->afc_recv[afi][safi])
8007 vty_out(vty, " %12ld",
8008 peer->pcount[afi]
8009 [pfx_rcd_safi]);
8010 else
8011 vty_out(vty, " NoNeg");
8012 else {
8013 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8014 vty_out(vty, " Idle (Admin)");
8015 else if (CHECK_FLAG(
8016 peer->sflags,
8017 PEER_STATUS_PREFIX_OVERFLOW))
8018 vty_out(vty, " Idle (PfxCt)");
8019 else
8020 vty_out(vty, " %12s",
8021 lookup_msg(bgp_status_msg,
8022 peer->status, NULL));
8023 }
8024 vty_out(vty, "\n");
8025 }
8026 }
8027
8028 if (use_json) {
8029 json_object_object_add(json, "peers", json_peers);
8030
8031 json_object_int_add(json, "totalPeers", count);
8032 json_object_int_add(json, "dynamicPeers", dn_count);
8033
8034 bgp_show_bestpath_json(bgp, json);
8035
8036 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8037 json, JSON_C_TO_STRING_PRETTY));
8038 json_object_free(json);
8039 } else {
8040 if (count)
8041 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8042 else {
8043 vty_out(vty, "No %s neighbor is configured\n",
8044 afi_safi_print(afi, safi));
8045 }
8046
8047 if (dn_count) {
8048 vty_out(vty, "* - dynamic neighbor\n");
8049 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8050 dn_count, bgp->dynamic_neighbors_limit);
8051 }
8052 }
8053
8054 return CMD_SUCCESS;
8055 }
8056
8057 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8058 int safi, uint8_t use_json,
8059 json_object *json)
8060 {
8061 int is_first = 1;
8062 int afi_wildcard = (afi == AFI_MAX);
8063 int safi_wildcard = (safi == SAFI_MAX);
8064 int is_wildcard = (afi_wildcard || safi_wildcard);
8065 bool json_output = false;
8066
8067 if (use_json && is_wildcard)
8068 vty_out(vty, "{\n");
8069 if (afi_wildcard)
8070 afi = 1; /* AFI_IP */
8071 while (afi < AFI_MAX) {
8072 if (safi_wildcard)
8073 safi = 1; /* SAFI_UNICAST */
8074 while (safi < SAFI_MAX) {
8075 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8076 json_output = true;
8077 if (is_wildcard) {
8078 /*
8079 * So limit output to those afi/safi
8080 * pairs that
8081 * actualy have something interesting in
8082 * them
8083 */
8084 if (use_json) {
8085 json = json_object_new_object();
8086
8087 if (!is_first)
8088 vty_out(vty, ",\n");
8089 else
8090 is_first = 0;
8091
8092 vty_out(vty, "\"%s\":",
8093 afi_safi_json(afi,
8094 safi));
8095 } else {
8096 vty_out(vty, "\n%s Summary:\n",
8097 afi_safi_print(afi,
8098 safi));
8099 }
8100 }
8101 bgp_show_summary(vty, bgp, afi, safi, use_json,
8102 json);
8103 }
8104 safi++;
8105 if (!safi_wildcard)
8106 safi = SAFI_MAX;
8107 }
8108 afi++;
8109 if (!afi_wildcard)
8110 afi = AFI_MAX;
8111 }
8112
8113 if (use_json && is_wildcard)
8114 vty_out(vty, "}\n");
8115 else if (use_json && !json_output)
8116 vty_out(vty, "{}\n");
8117 }
8118
8119 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8120 safi_t safi, uint8_t use_json)
8121 {
8122 struct listnode *node, *nnode;
8123 struct bgp *bgp;
8124 json_object *json = NULL;
8125 int is_first = 1;
8126
8127 if (use_json)
8128 vty_out(vty, "{\n");
8129
8130 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8131 if (use_json) {
8132 json = json_object_new_object();
8133
8134 if (!is_first)
8135 vty_out(vty, ",\n");
8136 else
8137 is_first = 0;
8138
8139 vty_out(vty, "\"%s\":",
8140 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8141 ? "Default"
8142 : bgp->name);
8143 } else {
8144 vty_out(vty, "\nInstance %s:\n",
8145 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8146 ? "Default"
8147 : bgp->name);
8148 }
8149 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8150 }
8151
8152 if (use_json)
8153 vty_out(vty, "}\n");
8154 }
8155
8156 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8157 safi_t safi, uint8_t use_json)
8158 {
8159 struct bgp *bgp;
8160
8161 if (name) {
8162 if (strmatch(name, "all")) {
8163 bgp_show_all_instances_summary_vty(vty, afi, safi,
8164 use_json);
8165 return CMD_SUCCESS;
8166 } else {
8167 bgp = bgp_lookup_by_name(name);
8168
8169 if (!bgp) {
8170 if (use_json)
8171 vty_out(vty, "{}\n");
8172 else
8173 vty_out(vty,
8174 "%% No such BGP instance exist\n");
8175 return CMD_WARNING;
8176 }
8177
8178 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8179 NULL);
8180 return CMD_SUCCESS;
8181 }
8182 }
8183
8184 bgp = bgp_get_default();
8185
8186 if (bgp)
8187 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8188
8189 return CMD_SUCCESS;
8190 }
8191
8192 /* `show [ip] bgp summary' commands. */
8193 DEFUN (show_ip_bgp_summary,
8194 show_ip_bgp_summary_cmd,
8195 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8196 SHOW_STR
8197 IP_STR
8198 BGP_STR
8199 BGP_INSTANCE_HELP_STR
8200 BGP_AFI_HELP_STR
8201 BGP_SAFI_WITH_LABEL_HELP_STR
8202 "Summary of BGP neighbor status\n"
8203 JSON_STR)
8204 {
8205 char *vrf = NULL;
8206 afi_t afi = AFI_MAX;
8207 safi_t safi = SAFI_MAX;
8208
8209 int idx = 0;
8210
8211 /* show [ip] bgp */
8212 if (argv_find(argv, argc, "ip", &idx))
8213 afi = AFI_IP;
8214 /* [<view|vrf> VIEWVRFNAME] */
8215 if (argv_find(argv, argc, "view", &idx)
8216 || argv_find(argv, argc, "vrf", &idx))
8217 vrf = argv[++idx]->arg;
8218 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8219 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8220 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8221 }
8222
8223 int uj = use_json(argc, argv);
8224
8225 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8226 }
8227
8228 const char *afi_safi_print(afi_t afi, safi_t safi)
8229 {
8230 if (afi == AFI_IP && safi == SAFI_UNICAST)
8231 return "IPv4 Unicast";
8232 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8233 return "IPv4 Multicast";
8234 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8235 return "IPv4 Labeled Unicast";
8236 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8237 return "IPv4 VPN";
8238 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8239 return "IPv4 Encap";
8240 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8241 return "IPv4 Flowspec";
8242 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8243 return "IPv6 Unicast";
8244 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8245 return "IPv6 Multicast";
8246 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8247 return "IPv6 Labeled Unicast";
8248 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8249 return "IPv6 VPN";
8250 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8251 return "IPv6 Encap";
8252 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8253 return "IPv6 Flowspec";
8254 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8255 return "L2VPN EVPN";
8256 else
8257 return "Unknown";
8258 }
8259
8260 /*
8261 * Please note that we have intentionally camelCased
8262 * the return strings here. So if you want
8263 * to use this function, please ensure you
8264 * are doing this within json output
8265 */
8266 const char *afi_safi_json(afi_t afi, safi_t safi)
8267 {
8268 if (afi == AFI_IP && safi == SAFI_UNICAST)
8269 return "ipv4Unicast";
8270 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8271 return "ipv4Multicast";
8272 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8273 return "ipv4LabeledUnicast";
8274 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8275 return "ipv4Vpn";
8276 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8277 return "ipv4Encap";
8278 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8279 return "ipv4Flowspec";
8280 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8281 return "ipv6Unicast";
8282 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8283 return "ipv6Multicast";
8284 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8285 return "ipv6LabeledUnicast";
8286 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8287 return "ipv6Vpn";
8288 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8289 return "ipv6Encap";
8290 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8291 return "ipv6Flowspec";
8292 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8293 return "l2VpnEvpn";
8294 else
8295 return "Unknown";
8296 }
8297
8298 /* Show BGP peer's information. */
8299 enum show_type { show_all, show_peer };
8300
8301 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8302 afi_t afi, safi_t safi,
8303 uint16_t adv_smcap, uint16_t adv_rmcap,
8304 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8305 uint8_t use_json, json_object *json_pref)
8306 {
8307 /* Send-Mode */
8308 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8309 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8310 if (use_json) {
8311 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8312 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8313 json_object_string_add(json_pref, "sendMode",
8314 "advertisedAndReceived");
8315 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8316 json_object_string_add(json_pref, "sendMode",
8317 "advertised");
8318 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8319 json_object_string_add(json_pref, "sendMode",
8320 "received");
8321 } else {
8322 vty_out(vty, " Send-mode: ");
8323 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8324 vty_out(vty, "advertised");
8325 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8326 vty_out(vty, "%sreceived",
8327 CHECK_FLAG(p->af_cap[afi][safi],
8328 adv_smcap)
8329 ? ", "
8330 : "");
8331 vty_out(vty, "\n");
8332 }
8333 }
8334
8335 /* Receive-Mode */
8336 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8337 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8338 if (use_json) {
8339 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8340 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8341 json_object_string_add(json_pref, "recvMode",
8342 "advertisedAndReceived");
8343 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8344 json_object_string_add(json_pref, "recvMode",
8345 "advertised");
8346 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8347 json_object_string_add(json_pref, "recvMode",
8348 "received");
8349 } else {
8350 vty_out(vty, " Receive-mode: ");
8351 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8352 vty_out(vty, "advertised");
8353 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8354 vty_out(vty, "%sreceived",
8355 CHECK_FLAG(p->af_cap[afi][safi],
8356 adv_rmcap)
8357 ? ", "
8358 : "");
8359 vty_out(vty, "\n");
8360 }
8361 }
8362 }
8363
8364 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8365 safi_t safi, uint8_t use_json,
8366 json_object *json_neigh)
8367 {
8368 struct bgp_filter *filter;
8369 struct peer_af *paf;
8370 char orf_pfx_name[BUFSIZ];
8371 int orf_pfx_count;
8372 json_object *json_af = NULL;
8373 json_object *json_prefA = NULL;
8374 json_object *json_prefB = NULL;
8375 json_object *json_addr = NULL;
8376
8377 if (use_json) {
8378 json_addr = json_object_new_object();
8379 json_af = json_object_new_object();
8380 filter = &p->filter[afi][safi];
8381
8382 if (peer_group_active(p))
8383 json_object_string_add(json_addr, "peerGroupMember",
8384 p->group->name);
8385
8386 paf = peer_af_find(p, afi, safi);
8387 if (paf && PAF_SUBGRP(paf)) {
8388 json_object_int_add(json_addr, "updateGroupId",
8389 PAF_UPDGRP(paf)->id);
8390 json_object_int_add(json_addr, "subGroupId",
8391 PAF_SUBGRP(paf)->id);
8392 json_object_int_add(json_addr, "packetQueueLength",
8393 bpacket_queue_virtual_length(paf));
8394 }
8395
8396 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8397 || CHECK_FLAG(p->af_cap[afi][safi],
8398 PEER_CAP_ORF_PREFIX_SM_RCV)
8399 || CHECK_FLAG(p->af_cap[afi][safi],
8400 PEER_CAP_ORF_PREFIX_RM_ADV)
8401 || CHECK_FLAG(p->af_cap[afi][safi],
8402 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8403 json_object_int_add(json_af, "orfType",
8404 ORF_TYPE_PREFIX);
8405 json_prefA = json_object_new_object();
8406 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8407 PEER_CAP_ORF_PREFIX_SM_ADV,
8408 PEER_CAP_ORF_PREFIX_RM_ADV,
8409 PEER_CAP_ORF_PREFIX_SM_RCV,
8410 PEER_CAP_ORF_PREFIX_RM_RCV,
8411 use_json, json_prefA);
8412 json_object_object_add(json_af, "orfPrefixList",
8413 json_prefA);
8414 }
8415
8416 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8417 || CHECK_FLAG(p->af_cap[afi][safi],
8418 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8419 || CHECK_FLAG(p->af_cap[afi][safi],
8420 PEER_CAP_ORF_PREFIX_RM_ADV)
8421 || CHECK_FLAG(p->af_cap[afi][safi],
8422 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8423 json_object_int_add(json_af, "orfOldType",
8424 ORF_TYPE_PREFIX_OLD);
8425 json_prefB = json_object_new_object();
8426 bgp_show_peer_afi_orf_cap(
8427 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8428 PEER_CAP_ORF_PREFIX_RM_ADV,
8429 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8430 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8431 json_prefB);
8432 json_object_object_add(json_af, "orfOldPrefixList",
8433 json_prefB);
8434 }
8435
8436 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8437 || CHECK_FLAG(p->af_cap[afi][safi],
8438 PEER_CAP_ORF_PREFIX_SM_RCV)
8439 || CHECK_FLAG(p->af_cap[afi][safi],
8440 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8441 || CHECK_FLAG(p->af_cap[afi][safi],
8442 PEER_CAP_ORF_PREFIX_RM_ADV)
8443 || CHECK_FLAG(p->af_cap[afi][safi],
8444 PEER_CAP_ORF_PREFIX_RM_RCV)
8445 || CHECK_FLAG(p->af_cap[afi][safi],
8446 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8447 json_object_object_add(json_addr, "afDependentCap",
8448 json_af);
8449 else
8450 json_object_free(json_af);
8451
8452 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8453 orf_pfx_count = prefix_bgp_show_prefix_list(
8454 NULL, afi, orf_pfx_name, use_json);
8455
8456 if (CHECK_FLAG(p->af_sflags[afi][safi],
8457 PEER_STATUS_ORF_PREFIX_SEND)
8458 || orf_pfx_count) {
8459 if (CHECK_FLAG(p->af_sflags[afi][safi],
8460 PEER_STATUS_ORF_PREFIX_SEND))
8461 json_object_boolean_true_add(json_neigh,
8462 "orfSent");
8463 if (orf_pfx_count)
8464 json_object_int_add(json_addr, "orfRecvCounter",
8465 orf_pfx_count);
8466 }
8467 if (CHECK_FLAG(p->af_sflags[afi][safi],
8468 PEER_STATUS_ORF_WAIT_REFRESH))
8469 json_object_string_add(
8470 json_addr, "orfFirstUpdate",
8471 "deferredUntilORFOrRouteRefreshRecvd");
8472
8473 if (CHECK_FLAG(p->af_flags[afi][safi],
8474 PEER_FLAG_REFLECTOR_CLIENT))
8475 json_object_boolean_true_add(json_addr,
8476 "routeReflectorClient");
8477 if (CHECK_FLAG(p->af_flags[afi][safi],
8478 PEER_FLAG_RSERVER_CLIENT))
8479 json_object_boolean_true_add(json_addr,
8480 "routeServerClient");
8481 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8482 json_object_boolean_true_add(json_addr,
8483 "inboundSoftConfigPermit");
8484
8485 if (CHECK_FLAG(p->af_flags[afi][safi],
8486 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8487 json_object_boolean_true_add(
8488 json_addr,
8489 "privateAsNumsAllReplacedInUpdatesToNbr");
8490 else if (CHECK_FLAG(p->af_flags[afi][safi],
8491 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8492 json_object_boolean_true_add(
8493 json_addr,
8494 "privateAsNumsReplacedInUpdatesToNbr");
8495 else if (CHECK_FLAG(p->af_flags[afi][safi],
8496 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8497 json_object_boolean_true_add(
8498 json_addr,
8499 "privateAsNumsAllRemovedInUpdatesToNbr");
8500 else if (CHECK_FLAG(p->af_flags[afi][safi],
8501 PEER_FLAG_REMOVE_PRIVATE_AS))
8502 json_object_boolean_true_add(
8503 json_addr,
8504 "privateAsNumsRemovedInUpdatesToNbr");
8505
8506 if (CHECK_FLAG(p->af_flags[afi][safi],
8507 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8508 json_object_boolean_true_add(json_addr,
8509 "addpathTxAllPaths");
8510
8511 if (CHECK_FLAG(p->af_flags[afi][safi],
8512 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8513 json_object_boolean_true_add(json_addr,
8514 "addpathTxBestpathPerAS");
8515
8516 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8517 json_object_string_add(json_addr,
8518 "overrideASNsInOutboundUpdates",
8519 "ifAspathEqualRemoteAs");
8520
8521 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8522 || CHECK_FLAG(p->af_flags[afi][safi],
8523 PEER_FLAG_FORCE_NEXTHOP_SELF))
8524 json_object_boolean_true_add(json_addr,
8525 "routerAlwaysNextHop");
8526 if (CHECK_FLAG(p->af_flags[afi][safi],
8527 PEER_FLAG_AS_PATH_UNCHANGED))
8528 json_object_boolean_true_add(
8529 json_addr, "unchangedAsPathPropogatedToNbr");
8530 if (CHECK_FLAG(p->af_flags[afi][safi],
8531 PEER_FLAG_NEXTHOP_UNCHANGED))
8532 json_object_boolean_true_add(
8533 json_addr, "unchangedNextHopPropogatedToNbr");
8534 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8535 json_object_boolean_true_add(
8536 json_addr, "unchangedMedPropogatedToNbr");
8537 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8538 || CHECK_FLAG(p->af_flags[afi][safi],
8539 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8540 if (CHECK_FLAG(p->af_flags[afi][safi],
8541 PEER_FLAG_SEND_COMMUNITY)
8542 && CHECK_FLAG(p->af_flags[afi][safi],
8543 PEER_FLAG_SEND_EXT_COMMUNITY))
8544 json_object_string_add(json_addr,
8545 "commAttriSentToNbr",
8546 "extendedAndStandard");
8547 else if (CHECK_FLAG(p->af_flags[afi][safi],
8548 PEER_FLAG_SEND_EXT_COMMUNITY))
8549 json_object_string_add(json_addr,
8550 "commAttriSentToNbr",
8551 "extended");
8552 else
8553 json_object_string_add(json_addr,
8554 "commAttriSentToNbr",
8555 "standard");
8556 }
8557 if (CHECK_FLAG(p->af_flags[afi][safi],
8558 PEER_FLAG_DEFAULT_ORIGINATE)) {
8559 if (p->default_rmap[afi][safi].name)
8560 json_object_string_add(
8561 json_addr, "defaultRouteMap",
8562 p->default_rmap[afi][safi].name);
8563
8564 if (paf && PAF_SUBGRP(paf)
8565 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8566 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8567 json_object_boolean_true_add(json_addr,
8568 "defaultSent");
8569 else
8570 json_object_boolean_true_add(json_addr,
8571 "defaultNotSent");
8572 }
8573
8574 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8575 if (is_evpn_enabled())
8576 json_object_boolean_true_add(
8577 json_addr, "advertiseAllVnis");
8578 }
8579
8580 if (filter->plist[FILTER_IN].name
8581 || filter->dlist[FILTER_IN].name
8582 || filter->aslist[FILTER_IN].name
8583 || filter->map[RMAP_IN].name)
8584 json_object_boolean_true_add(json_addr,
8585 "inboundPathPolicyConfig");
8586 if (filter->plist[FILTER_OUT].name
8587 || filter->dlist[FILTER_OUT].name
8588 || filter->aslist[FILTER_OUT].name
8589 || filter->map[RMAP_OUT].name || filter->usmap.name)
8590 json_object_boolean_true_add(
8591 json_addr, "outboundPathPolicyConfig");
8592
8593 /* prefix-list */
8594 if (filter->plist[FILTER_IN].name)
8595 json_object_string_add(json_addr,
8596 "incomingUpdatePrefixFilterList",
8597 filter->plist[FILTER_IN].name);
8598 if (filter->plist[FILTER_OUT].name)
8599 json_object_string_add(json_addr,
8600 "outgoingUpdatePrefixFilterList",
8601 filter->plist[FILTER_OUT].name);
8602
8603 /* distribute-list */
8604 if (filter->dlist[FILTER_IN].name)
8605 json_object_string_add(
8606 json_addr, "incomingUpdateNetworkFilterList",
8607 filter->dlist[FILTER_IN].name);
8608 if (filter->dlist[FILTER_OUT].name)
8609 json_object_string_add(
8610 json_addr, "outgoingUpdateNetworkFilterList",
8611 filter->dlist[FILTER_OUT].name);
8612
8613 /* filter-list. */
8614 if (filter->aslist[FILTER_IN].name)
8615 json_object_string_add(json_addr,
8616 "incomingUpdateAsPathFilterList",
8617 filter->aslist[FILTER_IN].name);
8618 if (filter->aslist[FILTER_OUT].name)
8619 json_object_string_add(json_addr,
8620 "outgoingUpdateAsPathFilterList",
8621 filter->aslist[FILTER_OUT].name);
8622
8623 /* route-map. */
8624 if (filter->map[RMAP_IN].name)
8625 json_object_string_add(
8626 json_addr, "routeMapForIncomingAdvertisements",
8627 filter->map[RMAP_IN].name);
8628 if (filter->map[RMAP_OUT].name)
8629 json_object_string_add(
8630 json_addr, "routeMapForOutgoingAdvertisements",
8631 filter->map[RMAP_OUT].name);
8632
8633 /* unsuppress-map */
8634 if (filter->usmap.name)
8635 json_object_string_add(json_addr,
8636 "selectiveUnsuppressRouteMap",
8637 filter->usmap.name);
8638
8639 /* Receive prefix count */
8640 json_object_int_add(json_addr, "acceptedPrefixCounter",
8641 p->pcount[afi][safi]);
8642
8643 /* Maximum prefix */
8644 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8645 json_object_int_add(json_addr, "prefixAllowedMax",
8646 p->pmax[afi][safi]);
8647 if (CHECK_FLAG(p->af_flags[afi][safi],
8648 PEER_FLAG_MAX_PREFIX_WARNING))
8649 json_object_boolean_true_add(
8650 json_addr, "prefixAllowedMaxWarning");
8651 json_object_int_add(json_addr,
8652 "prefixAllowedWarningThresh",
8653 p->pmax_threshold[afi][safi]);
8654 if (p->pmax_restart[afi][safi])
8655 json_object_int_add(
8656 json_addr,
8657 "prefixAllowedRestartIntervalMsecs",
8658 p->pmax_restart[afi][safi] * 60000);
8659 }
8660 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8661 json_addr);
8662
8663 } else {
8664 filter = &p->filter[afi][safi];
8665
8666 vty_out(vty, " For address family: %s\n",
8667 afi_safi_print(afi, safi));
8668
8669 if (peer_group_active(p))
8670 vty_out(vty, " %s peer-group member\n",
8671 p->group->name);
8672
8673 paf = peer_af_find(p, afi, safi);
8674 if (paf && PAF_SUBGRP(paf)) {
8675 vty_out(vty, " Update group %" PRIu64
8676 ", subgroup %" PRIu64 "\n",
8677 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8678 vty_out(vty, " Packet Queue length %d\n",
8679 bpacket_queue_virtual_length(paf));
8680 } else {
8681 vty_out(vty, " Not part of any update group\n");
8682 }
8683 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8684 || CHECK_FLAG(p->af_cap[afi][safi],
8685 PEER_CAP_ORF_PREFIX_SM_RCV)
8686 || CHECK_FLAG(p->af_cap[afi][safi],
8687 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8688 || CHECK_FLAG(p->af_cap[afi][safi],
8689 PEER_CAP_ORF_PREFIX_RM_ADV)
8690 || CHECK_FLAG(p->af_cap[afi][safi],
8691 PEER_CAP_ORF_PREFIX_RM_RCV)
8692 || CHECK_FLAG(p->af_cap[afi][safi],
8693 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8694 vty_out(vty, " AF-dependant capabilities:\n");
8695
8696 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8697 || CHECK_FLAG(p->af_cap[afi][safi],
8698 PEER_CAP_ORF_PREFIX_SM_RCV)
8699 || CHECK_FLAG(p->af_cap[afi][safi],
8700 PEER_CAP_ORF_PREFIX_RM_ADV)
8701 || CHECK_FLAG(p->af_cap[afi][safi],
8702 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8703 vty_out(vty,
8704 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8705 ORF_TYPE_PREFIX);
8706 bgp_show_peer_afi_orf_cap(
8707 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8708 PEER_CAP_ORF_PREFIX_RM_ADV,
8709 PEER_CAP_ORF_PREFIX_SM_RCV,
8710 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8711 }
8712 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8713 || CHECK_FLAG(p->af_cap[afi][safi],
8714 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8715 || CHECK_FLAG(p->af_cap[afi][safi],
8716 PEER_CAP_ORF_PREFIX_RM_ADV)
8717 || CHECK_FLAG(p->af_cap[afi][safi],
8718 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8719 vty_out(vty,
8720 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8721 ORF_TYPE_PREFIX_OLD);
8722 bgp_show_peer_afi_orf_cap(
8723 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8724 PEER_CAP_ORF_PREFIX_RM_ADV,
8725 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8726 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8727 }
8728
8729 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8730 orf_pfx_count = prefix_bgp_show_prefix_list(
8731 NULL, afi, orf_pfx_name, use_json);
8732
8733 if (CHECK_FLAG(p->af_sflags[afi][safi],
8734 PEER_STATUS_ORF_PREFIX_SEND)
8735 || orf_pfx_count) {
8736 vty_out(vty, " Outbound Route Filter (ORF):");
8737 if (CHECK_FLAG(p->af_sflags[afi][safi],
8738 PEER_STATUS_ORF_PREFIX_SEND))
8739 vty_out(vty, " sent;");
8740 if (orf_pfx_count)
8741 vty_out(vty, " received (%d entries)",
8742 orf_pfx_count);
8743 vty_out(vty, "\n");
8744 }
8745 if (CHECK_FLAG(p->af_sflags[afi][safi],
8746 PEER_STATUS_ORF_WAIT_REFRESH))
8747 vty_out(vty,
8748 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8749
8750 if (CHECK_FLAG(p->af_flags[afi][safi],
8751 PEER_FLAG_REFLECTOR_CLIENT))
8752 vty_out(vty, " Route-Reflector Client\n");
8753 if (CHECK_FLAG(p->af_flags[afi][safi],
8754 PEER_FLAG_RSERVER_CLIENT))
8755 vty_out(vty, " Route-Server Client\n");
8756 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8757 vty_out(vty,
8758 " Inbound soft reconfiguration allowed\n");
8759
8760 if (CHECK_FLAG(p->af_flags[afi][safi],
8761 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8762 vty_out(vty,
8763 " Private AS numbers (all) replaced in updates to this neighbor\n");
8764 else if (CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8766 vty_out(vty,
8767 " Private AS numbers replaced in updates to this neighbor\n");
8768 else if (CHECK_FLAG(p->af_flags[afi][safi],
8769 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8770 vty_out(vty,
8771 " Private AS numbers (all) removed in updates to this neighbor\n");
8772 else if (CHECK_FLAG(p->af_flags[afi][safi],
8773 PEER_FLAG_REMOVE_PRIVATE_AS))
8774 vty_out(vty,
8775 " Private AS numbers removed in updates to this neighbor\n");
8776
8777 if (CHECK_FLAG(p->af_flags[afi][safi],
8778 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8779 vty_out(vty, " Advertise all paths via addpath\n");
8780
8781 if (CHECK_FLAG(p->af_flags[afi][safi],
8782 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8783 vty_out(vty,
8784 " Advertise bestpath per AS via addpath\n");
8785
8786 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8787 vty_out(vty,
8788 " Override ASNs in outbound updates if aspath equals remote-as\n");
8789
8790 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8791 || CHECK_FLAG(p->af_flags[afi][safi],
8792 PEER_FLAG_FORCE_NEXTHOP_SELF))
8793 vty_out(vty, " NEXT_HOP is always this router\n");
8794 if (CHECK_FLAG(p->af_flags[afi][safi],
8795 PEER_FLAG_AS_PATH_UNCHANGED))
8796 vty_out(vty,
8797 " AS_PATH is propagated unchanged to this neighbor\n");
8798 if (CHECK_FLAG(p->af_flags[afi][safi],
8799 PEER_FLAG_NEXTHOP_UNCHANGED))
8800 vty_out(vty,
8801 " NEXT_HOP is propagated unchanged to this neighbor\n");
8802 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8803 vty_out(vty,
8804 " MED is propagated unchanged to this neighbor\n");
8805 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8806 || CHECK_FLAG(p->af_flags[afi][safi],
8807 PEER_FLAG_SEND_EXT_COMMUNITY)
8808 || CHECK_FLAG(p->af_flags[afi][safi],
8809 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8810 vty_out(vty,
8811 " Community attribute sent to this neighbor");
8812 if (CHECK_FLAG(p->af_flags[afi][safi],
8813 PEER_FLAG_SEND_COMMUNITY)
8814 && CHECK_FLAG(p->af_flags[afi][safi],
8815 PEER_FLAG_SEND_EXT_COMMUNITY)
8816 && CHECK_FLAG(p->af_flags[afi][safi],
8817 PEER_FLAG_SEND_LARGE_COMMUNITY))
8818 vty_out(vty, "(all)\n");
8819 else if (CHECK_FLAG(p->af_flags[afi][safi],
8820 PEER_FLAG_SEND_LARGE_COMMUNITY))
8821 vty_out(vty, "(large)\n");
8822 else if (CHECK_FLAG(p->af_flags[afi][safi],
8823 PEER_FLAG_SEND_EXT_COMMUNITY))
8824 vty_out(vty, "(extended)\n");
8825 else
8826 vty_out(vty, "(standard)\n");
8827 }
8828 if (CHECK_FLAG(p->af_flags[afi][safi],
8829 PEER_FLAG_DEFAULT_ORIGINATE)) {
8830 vty_out(vty, " Default information originate,");
8831
8832 if (p->default_rmap[afi][safi].name)
8833 vty_out(vty, " default route-map %s%s,",
8834 p->default_rmap[afi][safi].map ? "*"
8835 : "",
8836 p->default_rmap[afi][safi].name);
8837 if (paf && PAF_SUBGRP(paf)
8838 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8839 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8840 vty_out(vty, " default sent\n");
8841 else
8842 vty_out(vty, " default not sent\n");
8843 }
8844
8845 /* advertise-vni-all */
8846 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8847 if (is_evpn_enabled())
8848 vty_out(vty, " advertise-all-vni\n");
8849 }
8850
8851 if (filter->plist[FILTER_IN].name
8852 || filter->dlist[FILTER_IN].name
8853 || filter->aslist[FILTER_IN].name
8854 || filter->map[RMAP_IN].name)
8855 vty_out(vty, " Inbound path policy configured\n");
8856 if (filter->plist[FILTER_OUT].name
8857 || filter->dlist[FILTER_OUT].name
8858 || filter->aslist[FILTER_OUT].name
8859 || filter->map[RMAP_OUT].name || filter->usmap.name)
8860 vty_out(vty, " Outbound path policy configured\n");
8861
8862 /* prefix-list */
8863 if (filter->plist[FILTER_IN].name)
8864 vty_out(vty,
8865 " Incoming update prefix filter list is %s%s\n",
8866 filter->plist[FILTER_IN].plist ? "*" : "",
8867 filter->plist[FILTER_IN].name);
8868 if (filter->plist[FILTER_OUT].name)
8869 vty_out(vty,
8870 " Outgoing update prefix filter list is %s%s\n",
8871 filter->plist[FILTER_OUT].plist ? "*" : "",
8872 filter->plist[FILTER_OUT].name);
8873
8874 /* distribute-list */
8875 if (filter->dlist[FILTER_IN].name)
8876 vty_out(vty,
8877 " Incoming update network filter list is %s%s\n",
8878 filter->dlist[FILTER_IN].alist ? "*" : "",
8879 filter->dlist[FILTER_IN].name);
8880 if (filter->dlist[FILTER_OUT].name)
8881 vty_out(vty,
8882 " Outgoing update network filter list is %s%s\n",
8883 filter->dlist[FILTER_OUT].alist ? "*" : "",
8884 filter->dlist[FILTER_OUT].name);
8885
8886 /* filter-list. */
8887 if (filter->aslist[FILTER_IN].name)
8888 vty_out(vty,
8889 " Incoming update AS path filter list is %s%s\n",
8890 filter->aslist[FILTER_IN].aslist ? "*" : "",
8891 filter->aslist[FILTER_IN].name);
8892 if (filter->aslist[FILTER_OUT].name)
8893 vty_out(vty,
8894 " Outgoing update AS path filter list is %s%s\n",
8895 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8896 filter->aslist[FILTER_OUT].name);
8897
8898 /* route-map. */
8899 if (filter->map[RMAP_IN].name)
8900 vty_out(vty,
8901 " Route map for incoming advertisements is %s%s\n",
8902 filter->map[RMAP_IN].map ? "*" : "",
8903 filter->map[RMAP_IN].name);
8904 if (filter->map[RMAP_OUT].name)
8905 vty_out(vty,
8906 " Route map for outgoing advertisements is %s%s\n",
8907 filter->map[RMAP_OUT].map ? "*" : "",
8908 filter->map[RMAP_OUT].name);
8909
8910 /* unsuppress-map */
8911 if (filter->usmap.name)
8912 vty_out(vty,
8913 " Route map for selective unsuppress is %s%s\n",
8914 filter->usmap.map ? "*" : "",
8915 filter->usmap.name);
8916
8917 /* Receive prefix count */
8918 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8919
8920 /* Maximum prefix */
8921 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8922 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8923 p->pmax[afi][safi],
8924 CHECK_FLAG(p->af_flags[afi][safi],
8925 PEER_FLAG_MAX_PREFIX_WARNING)
8926 ? " (warning-only)"
8927 : "");
8928 vty_out(vty, " Threshold for warning message %d%%",
8929 p->pmax_threshold[afi][safi]);
8930 if (p->pmax_restart[afi][safi])
8931 vty_out(vty, ", restart interval %d min",
8932 p->pmax_restart[afi][safi]);
8933 vty_out(vty, "\n");
8934 }
8935
8936 vty_out(vty, "\n");
8937 }
8938 }
8939
8940 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8941 json_object *json)
8942 {
8943 struct bgp *bgp;
8944 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8945 char timebuf[BGP_UPTIME_LEN];
8946 char dn_flag[2];
8947 const char *subcode_str;
8948 const char *code_str;
8949 afi_t afi;
8950 safi_t safi;
8951 uint16_t i;
8952 uint8_t *msg;
8953 json_object *json_neigh = NULL;
8954 time_t epoch_tbuf;
8955
8956 bgp = p->bgp;
8957
8958 if (use_json)
8959 json_neigh = json_object_new_object();
8960
8961 memset(dn_flag, '\0', sizeof(dn_flag));
8962 if (!p->conf_if && peer_dynamic_neighbor(p))
8963 dn_flag[0] = '*';
8964
8965 if (!use_json) {
8966 if (p->conf_if) /* Configured interface name. */
8967 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8968 BGP_PEER_SU_UNSPEC(p)
8969 ? "None"
8970 : sockunion2str(&p->su, buf,
8971 SU_ADDRSTRLEN));
8972 else /* Configured IP address. */
8973 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8974 p->host);
8975 }
8976
8977 if (use_json) {
8978 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8979 json_object_string_add(json_neigh, "bgpNeighborAddr",
8980 "none");
8981 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8982 json_object_string_add(
8983 json_neigh, "bgpNeighborAddr",
8984 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8985
8986 json_object_int_add(json_neigh, "remoteAs", p->as);
8987
8988 if (p->change_local_as)
8989 json_object_int_add(json_neigh, "localAs",
8990 p->change_local_as);
8991 else
8992 json_object_int_add(json_neigh, "localAs", p->local_as);
8993
8994 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8995 json_object_boolean_true_add(json_neigh,
8996 "localAsNoPrepend");
8997
8998 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8999 json_object_boolean_true_add(json_neigh,
9000 "localAsReplaceAs");
9001 } else {
9002 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9003 || (p->as_type == AS_INTERNAL))
9004 vty_out(vty, "remote AS %" PRIu32 ", ", p->as);
9005 else
9006 vty_out(vty, "remote AS Unspecified, ");
9007 vty_out(vty, "local AS %u%s%s, ",
9008 p->change_local_as ? p->change_local_as : p->local_as,
9009 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9010 ? " no-prepend"
9011 : "",
9012 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9013 ? " replace-as"
9014 : "");
9015 }
9016 /* peer type internal, external, confed-internal or confed-external */
9017 if (p->as == p->local_as) {
9018 if (use_json) {
9019 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9020 json_object_boolean_true_add(
9021 json_neigh, "nbrConfedInternalLink");
9022 else
9023 json_object_boolean_true_add(json_neigh,
9024 "nbrInternalLink");
9025 } else {
9026 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9027 vty_out(vty, "confed-internal link\n");
9028 else
9029 vty_out(vty, "internal link\n");
9030 }
9031 } else {
9032 if (use_json) {
9033 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9034 json_object_boolean_true_add(
9035 json_neigh, "nbrConfedExternalLink");
9036 else
9037 json_object_boolean_true_add(json_neigh,
9038 "nbrExternalLink");
9039 } else {
9040 if (bgp_confederation_peers_check(bgp, p->as))
9041 vty_out(vty, "confed-external link\n");
9042 else
9043 vty_out(vty, "external link\n");
9044 }
9045 }
9046
9047 /* Description. */
9048 if (p->desc) {
9049 if (use_json)
9050 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9051 else
9052 vty_out(vty, " Description: %s\n", p->desc);
9053 }
9054
9055 if (p->hostname) {
9056 if (use_json) {
9057 if (p->hostname)
9058 json_object_string_add(json_neigh, "hostname",
9059 p->hostname);
9060
9061 if (p->domainname)
9062 json_object_string_add(json_neigh, "domainname",
9063 p->domainname);
9064 } else {
9065 if (p->domainname && (p->domainname[0] != '\0'))
9066 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9067 p->domainname);
9068 else
9069 vty_out(vty, "Hostname: %s\n", p->hostname);
9070 }
9071 }
9072
9073 /* Peer-group */
9074 if (p->group) {
9075 if (use_json) {
9076 json_object_string_add(json_neigh, "peerGroup",
9077 p->group->name);
9078
9079 if (dn_flag[0]) {
9080 struct prefix prefix, *range = NULL;
9081
9082 sockunion2hostprefix(&(p->su), &prefix);
9083 range = peer_group_lookup_dynamic_neighbor_range(
9084 p->group, &prefix);
9085
9086 if (range) {
9087 prefix2str(range, buf1, sizeof(buf1));
9088 json_object_string_add(
9089 json_neigh,
9090 "peerSubnetRangeGroup", buf1);
9091 }
9092 }
9093 } else {
9094 vty_out(vty,
9095 " Member of peer-group %s for session parameters\n",
9096 p->group->name);
9097
9098 if (dn_flag[0]) {
9099 struct prefix prefix, *range = NULL;
9100
9101 sockunion2hostprefix(&(p->su), &prefix);
9102 range = peer_group_lookup_dynamic_neighbor_range(
9103 p->group, &prefix);
9104
9105 if (range) {
9106 prefix2str(range, buf1, sizeof(buf1));
9107 vty_out(vty,
9108 " Belongs to the subnet range group: %s\n",
9109 buf1);
9110 }
9111 }
9112 }
9113 }
9114
9115 if (use_json) {
9116 /* Administrative shutdown. */
9117 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9118 json_object_boolean_true_add(json_neigh,
9119 "adminShutDown");
9120
9121 /* BGP Version. */
9122 json_object_int_add(json_neigh, "bgpVersion", 4);
9123 json_object_string_add(
9124 json_neigh, "remoteRouterId",
9125 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9126 json_object_string_add(
9127 json_neigh, "localRouterId",
9128 inet_ntop(AF_INET, &bgp->router_id, buf1,
9129 sizeof(buf1)));
9130
9131 /* Confederation */
9132 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9133 && bgp_confederation_peers_check(bgp, p->as))
9134 json_object_boolean_true_add(json_neigh,
9135 "nbrCommonAdmin");
9136
9137 /* Status. */
9138 json_object_string_add(
9139 json_neigh, "bgpState",
9140 lookup_msg(bgp_status_msg, p->status, NULL));
9141
9142 if (p->status == Established) {
9143 time_t uptime;
9144
9145 uptime = bgp_clock();
9146 uptime -= p->uptime;
9147 epoch_tbuf = time(NULL) - uptime;
9148
9149 #if CONFDATE > 20200101
9150 CPP_NOTICE(
9151 "bgpTimerUp should be deprecated and can be removed now");
9152 #endif
9153 /*
9154 * bgpTimerUp was miliseconds that was accurate
9155 * up to 1 day, then the value returned
9156 * became garbage. So in order to provide
9157 * some level of backwards compatability,
9158 * we still provde the data, but now
9159 * we are returning the correct value
9160 * and also adding a new bgpTimerUpMsec
9161 * which will allow us to deprecate
9162 * this eventually
9163 */
9164 json_object_int_add(json_neigh, "bgpTimerUp",
9165 uptime * 1000);
9166 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9167 uptime * 1000);
9168 json_object_string_add(json_neigh, "bgpTimerUpString",
9169 peer_uptime(p->uptime, timebuf,
9170 BGP_UPTIME_LEN, 0,
9171 NULL));
9172 json_object_int_add(json_neigh,
9173 "bgpTimerUpEstablishedEpoch",
9174 epoch_tbuf);
9175 }
9176
9177 else if (p->status == Active) {
9178 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9179 json_object_string_add(json_neigh, "bgpStateIs",
9180 "passive");
9181 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9182 json_object_string_add(json_neigh, "bgpStateIs",
9183 "passiveNSF");
9184 }
9185
9186 /* read timer */
9187 time_t uptime;
9188 struct tm *tm;
9189
9190 uptime = bgp_clock();
9191 uptime -= p->readtime;
9192 tm = gmtime(&uptime);
9193 json_object_int_add(json_neigh, "bgpTimerLastRead",
9194 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9195 + (tm->tm_hour * 3600000));
9196
9197 uptime = bgp_clock();
9198 uptime -= p->last_write;
9199 tm = gmtime(&uptime);
9200 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9201 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9202 + (tm->tm_hour * 3600000));
9203
9204 uptime = bgp_clock();
9205 uptime -= p->update_time;
9206 tm = gmtime(&uptime);
9207 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9208 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9209 + (tm->tm_hour * 3600000));
9210
9211 /* Configured timer values. */
9212 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9213 p->v_holdtime * 1000);
9214 json_object_int_add(json_neigh,
9215 "bgpTimerKeepAliveIntervalMsecs",
9216 p->v_keepalive * 1000);
9217 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9218 json_object_int_add(json_neigh,
9219 "bgpTimerConfiguredHoldTimeMsecs",
9220 p->holdtime * 1000);
9221 json_object_int_add(
9222 json_neigh,
9223 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9224 p->keepalive * 1000);
9225 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9226 || (bgp->default_keepalive
9227 != BGP_DEFAULT_KEEPALIVE)) {
9228 json_object_int_add(json_neigh,
9229 "bgpTimerConfiguredHoldTimeMsecs",
9230 bgp->default_holdtime);
9231 json_object_int_add(
9232 json_neigh,
9233 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9234 bgp->default_keepalive);
9235 }
9236 } else {
9237 /* Administrative shutdown. */
9238 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9239 vty_out(vty, " Administratively shut down\n");
9240
9241 /* BGP Version. */
9242 vty_out(vty, " BGP version 4");
9243 vty_out(vty, ", remote router ID %s",
9244 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9245 vty_out(vty, ", local router ID %s\n",
9246 inet_ntop(AF_INET, &bgp->router_id, buf1,
9247 sizeof(buf1)));
9248
9249 /* Confederation */
9250 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9251 && bgp_confederation_peers_check(bgp, p->as))
9252 vty_out(vty,
9253 " Neighbor under common administration\n");
9254
9255 /* Status. */
9256 vty_out(vty, " BGP state = %s",
9257 lookup_msg(bgp_status_msg, p->status, NULL));
9258
9259 if (p->status == Established)
9260 vty_out(vty, ", up for %8s",
9261 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9262 0, NULL));
9263
9264 else if (p->status == Active) {
9265 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9266 vty_out(vty, " (passive)");
9267 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9268 vty_out(vty, " (NSF passive)");
9269 }
9270 vty_out(vty, "\n");
9271
9272 /* read timer */
9273 vty_out(vty, " Last read %s",
9274 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9275 NULL));
9276 vty_out(vty, ", Last write %s\n",
9277 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9278 NULL));
9279
9280 /* Configured timer values. */
9281 vty_out(vty,
9282 " Hold time is %d, keepalive interval is %d seconds\n",
9283 p->v_holdtime, p->v_keepalive);
9284 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9285 vty_out(vty, " Configured hold time is %d",
9286 p->holdtime);
9287 vty_out(vty, ", keepalive interval is %d seconds\n",
9288 p->keepalive);
9289 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9290 || (bgp->default_keepalive
9291 != BGP_DEFAULT_KEEPALIVE)) {
9292 vty_out(vty, " Configured hold time is %d",
9293 bgp->default_holdtime);
9294 vty_out(vty, ", keepalive interval is %d seconds\n",
9295 bgp->default_keepalive);
9296 }
9297 }
9298 /* Capability. */
9299 if (p->status == Established) {
9300 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9301 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9302 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9303 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9304 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9305 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9306 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9307 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9308 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9309 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9310 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9311 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9312 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9313 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9314 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9315 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9316 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9317 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9318 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9319 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9320 if (use_json) {
9321 json_object *json_cap = NULL;
9322
9323 json_cap = json_object_new_object();
9324
9325 /* AS4 */
9326 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9327 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9328 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9329 && CHECK_FLAG(p->cap,
9330 PEER_CAP_AS4_RCV))
9331 json_object_string_add(
9332 json_cap, "4byteAs",
9333 "advertisedAndReceived");
9334 else if (CHECK_FLAG(p->cap,
9335 PEER_CAP_AS4_ADV))
9336 json_object_string_add(
9337 json_cap, "4byteAs",
9338 "advertised");
9339 else if (CHECK_FLAG(p->cap,
9340 PEER_CAP_AS4_RCV))
9341 json_object_string_add(
9342 json_cap, "4byteAs",
9343 "received");
9344 }
9345
9346 /* AddPath */
9347 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9348 || CHECK_FLAG(p->cap,
9349 PEER_CAP_ADDPATH_ADV)) {
9350 json_object *json_add = NULL;
9351 const char *print_store;
9352
9353 json_add = json_object_new_object();
9354
9355 FOREACH_AFI_SAFI (afi, safi) {
9356 json_object *json_sub = NULL;
9357 json_sub =
9358 json_object_new_object();
9359 print_store = afi_safi_print(
9360 afi, safi);
9361
9362 if (CHECK_FLAG(
9363 p->af_cap[afi]
9364 [safi],
9365 PEER_CAP_ADDPATH_AF_TX_ADV)
9366 || CHECK_FLAG(
9367 p->af_cap[afi]
9368 [safi],
9369 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9370 if (CHECK_FLAG(
9371 p->af_cap
9372 [afi]
9373 [safi],
9374 PEER_CAP_ADDPATH_AF_TX_ADV)
9375 && CHECK_FLAG(
9376 p->af_cap
9377 [afi]
9378 [safi],
9379 PEER_CAP_ADDPATH_AF_TX_RCV))
9380 json_object_boolean_true_add(
9381 json_sub,
9382 "txAdvertisedAndReceived");
9383 else if (
9384 CHECK_FLAG(
9385 p->af_cap
9386 [afi]
9387 [safi],
9388 PEER_CAP_ADDPATH_AF_TX_ADV))
9389 json_object_boolean_true_add(
9390 json_sub,
9391 "txAdvertised");
9392 else if (
9393 CHECK_FLAG(
9394 p->af_cap
9395 [afi]
9396 [safi],
9397 PEER_CAP_ADDPATH_AF_TX_RCV))
9398 json_object_boolean_true_add(
9399 json_sub,
9400 "txReceived");
9401 }
9402
9403 if (CHECK_FLAG(
9404 p->af_cap[afi]
9405 [safi],
9406 PEER_CAP_ADDPATH_AF_RX_ADV)
9407 || CHECK_FLAG(
9408 p->af_cap[afi]
9409 [safi],
9410 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9411 if (CHECK_FLAG(
9412 p->af_cap
9413 [afi]
9414 [safi],
9415 PEER_CAP_ADDPATH_AF_RX_ADV)
9416 && CHECK_FLAG(
9417 p->af_cap
9418 [afi]
9419 [safi],
9420 PEER_CAP_ADDPATH_AF_RX_RCV))
9421 json_object_boolean_true_add(
9422 json_sub,
9423 "rxAdvertisedAndReceived");
9424 else if (
9425 CHECK_FLAG(
9426 p->af_cap
9427 [afi]
9428 [safi],
9429 PEER_CAP_ADDPATH_AF_RX_ADV))
9430 json_object_boolean_true_add(
9431 json_sub,
9432 "rxAdvertised");
9433 else if (
9434 CHECK_FLAG(
9435 p->af_cap
9436 [afi]
9437 [safi],
9438 PEER_CAP_ADDPATH_AF_RX_RCV))
9439 json_object_boolean_true_add(
9440 json_sub,
9441 "rxReceived");
9442 }
9443
9444 if (CHECK_FLAG(
9445 p->af_cap[afi]
9446 [safi],
9447 PEER_CAP_ADDPATH_AF_TX_ADV)
9448 || CHECK_FLAG(
9449 p->af_cap[afi]
9450 [safi],
9451 PEER_CAP_ADDPATH_AF_TX_RCV)
9452 || CHECK_FLAG(
9453 p->af_cap[afi]
9454 [safi],
9455 PEER_CAP_ADDPATH_AF_RX_ADV)
9456 || CHECK_FLAG(
9457 p->af_cap[afi]
9458 [safi],
9459 PEER_CAP_ADDPATH_AF_RX_RCV))
9460 json_object_object_add(
9461 json_add,
9462 print_store,
9463 json_sub);
9464 else
9465 json_object_free(
9466 json_sub);
9467 }
9468
9469 json_object_object_add(
9470 json_cap, "addPath", json_add);
9471 }
9472
9473 /* Dynamic */
9474 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9475 || CHECK_FLAG(p->cap,
9476 PEER_CAP_DYNAMIC_ADV)) {
9477 if (CHECK_FLAG(p->cap,
9478 PEER_CAP_DYNAMIC_ADV)
9479 && CHECK_FLAG(p->cap,
9480 PEER_CAP_DYNAMIC_RCV))
9481 json_object_string_add(
9482 json_cap, "dynamic",
9483 "advertisedAndReceived");
9484 else if (CHECK_FLAG(
9485 p->cap,
9486 PEER_CAP_DYNAMIC_ADV))
9487 json_object_string_add(
9488 json_cap, "dynamic",
9489 "advertised");
9490 else if (CHECK_FLAG(
9491 p->cap,
9492 PEER_CAP_DYNAMIC_RCV))
9493 json_object_string_add(
9494 json_cap, "dynamic",
9495 "received");
9496 }
9497
9498 /* Extended nexthop */
9499 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9500 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9501 json_object *json_nxt = NULL;
9502 const char *print_store;
9503
9504
9505 if (CHECK_FLAG(p->cap,
9506 PEER_CAP_ENHE_ADV)
9507 && CHECK_FLAG(p->cap,
9508 PEER_CAP_ENHE_RCV))
9509 json_object_string_add(
9510 json_cap,
9511 "extendedNexthop",
9512 "advertisedAndReceived");
9513 else if (CHECK_FLAG(p->cap,
9514 PEER_CAP_ENHE_ADV))
9515 json_object_string_add(
9516 json_cap,
9517 "extendedNexthop",
9518 "advertised");
9519 else if (CHECK_FLAG(p->cap,
9520 PEER_CAP_ENHE_RCV))
9521 json_object_string_add(
9522 json_cap,
9523 "extendedNexthop",
9524 "received");
9525
9526 if (CHECK_FLAG(p->cap,
9527 PEER_CAP_ENHE_RCV)) {
9528 json_nxt =
9529 json_object_new_object();
9530
9531 for (safi = SAFI_UNICAST;
9532 safi < SAFI_MAX; safi++) {
9533 if (CHECK_FLAG(
9534 p->af_cap
9535 [AFI_IP]
9536 [safi],
9537 PEER_CAP_ENHE_AF_RCV)) {
9538 print_store = afi_safi_print(
9539 AFI_IP,
9540 safi);
9541 json_object_string_add(
9542 json_nxt,
9543 print_store,
9544 "recieved");
9545 }
9546 }
9547 json_object_object_add(
9548 json_cap,
9549 "extendedNexthopFamililesByPeer",
9550 json_nxt);
9551 }
9552 }
9553
9554 /* Route Refresh */
9555 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9556 || CHECK_FLAG(p->cap,
9557 PEER_CAP_REFRESH_NEW_RCV)
9558 || CHECK_FLAG(p->cap,
9559 PEER_CAP_REFRESH_OLD_RCV)) {
9560 if (CHECK_FLAG(p->cap,
9561 PEER_CAP_REFRESH_ADV)
9562 && (CHECK_FLAG(
9563 p->cap,
9564 PEER_CAP_REFRESH_NEW_RCV)
9565 || CHECK_FLAG(
9566 p->cap,
9567 PEER_CAP_REFRESH_OLD_RCV))) {
9568 if (CHECK_FLAG(
9569 p->cap,
9570 PEER_CAP_REFRESH_OLD_RCV)
9571 && CHECK_FLAG(
9572 p->cap,
9573 PEER_CAP_REFRESH_NEW_RCV))
9574 json_object_string_add(
9575 json_cap,
9576 "routeRefresh",
9577 "advertisedAndReceivedOldNew");
9578 else {
9579 if (CHECK_FLAG(
9580 p->cap,
9581 PEER_CAP_REFRESH_OLD_RCV))
9582 json_object_string_add(
9583 json_cap,
9584 "routeRefresh",
9585 "advertisedAndReceivedOld");
9586 else
9587 json_object_string_add(
9588 json_cap,
9589 "routeRefresh",
9590 "advertisedAndReceivedNew");
9591 }
9592 } else if (
9593 CHECK_FLAG(
9594 p->cap,
9595 PEER_CAP_REFRESH_ADV))
9596 json_object_string_add(
9597 json_cap,
9598 "routeRefresh",
9599 "advertised");
9600 else if (
9601 CHECK_FLAG(
9602 p->cap,
9603 PEER_CAP_REFRESH_NEW_RCV)
9604 || CHECK_FLAG(
9605 p->cap,
9606 PEER_CAP_REFRESH_OLD_RCV))
9607 json_object_string_add(
9608 json_cap,
9609 "routeRefresh",
9610 "received");
9611 }
9612
9613 /* Multiprotocol Extensions */
9614 json_object *json_multi = NULL;
9615 json_multi = json_object_new_object();
9616
9617 FOREACH_AFI_SAFI (afi, safi) {
9618 if (p->afc_adv[afi][safi]
9619 || p->afc_recv[afi][safi]) {
9620 json_object *json_exten = NULL;
9621 json_exten =
9622 json_object_new_object();
9623
9624 if (p->afc_adv[afi][safi]
9625 && p->afc_recv[afi][safi])
9626 json_object_boolean_true_add(
9627 json_exten,
9628 "advertisedAndReceived");
9629 else if (p->afc_adv[afi][safi])
9630 json_object_boolean_true_add(
9631 json_exten,
9632 "advertised");
9633 else if (p->afc_recv[afi][safi])
9634 json_object_boolean_true_add(
9635 json_exten,
9636 "received");
9637
9638 json_object_object_add(
9639 json_multi,
9640 afi_safi_print(afi,
9641 safi),
9642 json_exten);
9643 }
9644 }
9645 json_object_object_add(
9646 json_cap, "multiprotocolExtensions",
9647 json_multi);
9648
9649 /* Hostname capabilities */
9650 json_object *json_hname = NULL;
9651
9652 json_hname = json_object_new_object();
9653
9654 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9655 json_object_string_add(
9656 json_hname, "advHostName",
9657 bgp->peer_self->hostname
9658 ? bgp->peer_self
9659 ->hostname
9660 : "n/a");
9661 json_object_string_add(
9662 json_hname, "advDomainName",
9663 bgp->peer_self->domainname
9664 ? bgp->peer_self
9665 ->domainname
9666 : "n/a");
9667 }
9668
9669
9670 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9671 json_object_string_add(
9672 json_hname, "rcvHostName",
9673 p->hostname ? p->hostname
9674 : "n/a");
9675 json_object_string_add(
9676 json_hname, "rcvDomainName",
9677 p->domainname ? p->domainname
9678 : "n/a");
9679 }
9680
9681 json_object_object_add(json_cap, "hostName",
9682 json_hname);
9683
9684 /* Gracefull Restart */
9685 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9686 || CHECK_FLAG(p->cap,
9687 PEER_CAP_RESTART_ADV)) {
9688 if (CHECK_FLAG(p->cap,
9689 PEER_CAP_RESTART_ADV)
9690 && CHECK_FLAG(p->cap,
9691 PEER_CAP_RESTART_RCV))
9692 json_object_string_add(
9693 json_cap,
9694 "gracefulRestart",
9695 "advertisedAndReceived");
9696 else if (CHECK_FLAG(
9697 p->cap,
9698 PEER_CAP_RESTART_ADV))
9699 json_object_string_add(
9700 json_cap,
9701 "gracefulRestartCapability",
9702 "advertised");
9703 else if (CHECK_FLAG(
9704 p->cap,
9705 PEER_CAP_RESTART_RCV))
9706 json_object_string_add(
9707 json_cap,
9708 "gracefulRestartCapability",
9709 "received");
9710
9711 if (CHECK_FLAG(p->cap,
9712 PEER_CAP_RESTART_RCV)) {
9713 int restart_af_count = 0;
9714 json_object *json_restart =
9715 NULL;
9716 json_restart =
9717 json_object_new_object();
9718
9719 json_object_int_add(
9720 json_cap,
9721 "gracefulRestartRemoteTimerMsecs",
9722 p->v_gr_restart * 1000);
9723
9724 FOREACH_AFI_SAFI (afi, safi) {
9725 if (CHECK_FLAG(
9726 p->af_cap
9727 [afi]
9728 [safi],
9729 PEER_CAP_RESTART_AF_RCV)) {
9730 json_object *
9731 json_sub =
9732 NULL;
9733 json_sub =
9734 json_object_new_object();
9735
9736 if (CHECK_FLAG(
9737 p->af_cap
9738 [afi]
9739 [safi],
9740 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9741 json_object_boolean_true_add(
9742 json_sub,
9743 "preserved");
9744 restart_af_count++;
9745 json_object_object_add(
9746 json_restart,
9747 afi_safi_print(
9748 afi,
9749 safi),
9750 json_sub);
9751 }
9752 }
9753 if (!restart_af_count) {
9754 json_object_string_add(
9755 json_cap,
9756 "addressFamiliesByPeer",
9757 "none");
9758 json_object_free(
9759 json_restart);
9760 } else
9761 json_object_object_add(
9762 json_cap,
9763 "addressFamiliesByPeer",
9764 json_restart);
9765 }
9766 }
9767 json_object_object_add(json_neigh,
9768 "neighborCapabilities",
9769 json_cap);
9770 } else {
9771 vty_out(vty, " Neighbor capabilities:\n");
9772
9773 /* AS4 */
9774 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9775 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9776 vty_out(vty, " 4 Byte AS:");
9777 if (CHECK_FLAG(p->cap,
9778 PEER_CAP_AS4_ADV))
9779 vty_out(vty, " advertised");
9780 if (CHECK_FLAG(p->cap,
9781 PEER_CAP_AS4_RCV))
9782 vty_out(vty, " %sreceived",
9783 CHECK_FLAG(
9784 p->cap,
9785 PEER_CAP_AS4_ADV)
9786 ? "and "
9787 : "");
9788 vty_out(vty, "\n");
9789 }
9790
9791 /* AddPath */
9792 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9793 || CHECK_FLAG(p->cap,
9794 PEER_CAP_ADDPATH_ADV)) {
9795 vty_out(vty, " AddPath:\n");
9796
9797 FOREACH_AFI_SAFI (afi, safi) {
9798 if (CHECK_FLAG(
9799 p->af_cap[afi]
9800 [safi],
9801 PEER_CAP_ADDPATH_AF_TX_ADV)
9802 || CHECK_FLAG(
9803 p->af_cap[afi]
9804 [safi],
9805 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9806 vty_out(vty,
9807 " %s: TX ",
9808 afi_safi_print(
9809 afi,
9810 safi));
9811
9812 if (CHECK_FLAG(
9813 p->af_cap
9814 [afi]
9815 [safi],
9816 PEER_CAP_ADDPATH_AF_TX_ADV))
9817 vty_out(vty,
9818 "advertised %s",
9819 afi_safi_print(
9820 afi,
9821 safi));
9822
9823 if (CHECK_FLAG(
9824 p->af_cap
9825 [afi]
9826 [safi],
9827 PEER_CAP_ADDPATH_AF_TX_RCV))
9828 vty_out(vty,
9829 "%sreceived",
9830 CHECK_FLAG(
9831 p->af_cap
9832 [afi]
9833 [safi],
9834 PEER_CAP_ADDPATH_AF_TX_ADV)
9835 ? " and "
9836 : "");
9837
9838 vty_out(vty, "\n");
9839 }
9840
9841 if (CHECK_FLAG(
9842 p->af_cap[afi]
9843 [safi],
9844 PEER_CAP_ADDPATH_AF_RX_ADV)
9845 || CHECK_FLAG(
9846 p->af_cap[afi]
9847 [safi],
9848 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9849 vty_out(vty,
9850 " %s: RX ",
9851 afi_safi_print(
9852 afi,
9853 safi));
9854
9855 if (CHECK_FLAG(
9856 p->af_cap
9857 [afi]
9858 [safi],
9859 PEER_CAP_ADDPATH_AF_RX_ADV))
9860 vty_out(vty,
9861 "advertised %s",
9862 afi_safi_print(
9863 afi,
9864 safi));
9865
9866 if (CHECK_FLAG(
9867 p->af_cap
9868 [afi]
9869 [safi],
9870 PEER_CAP_ADDPATH_AF_RX_RCV))
9871 vty_out(vty,
9872 "%sreceived",
9873 CHECK_FLAG(
9874 p->af_cap
9875 [afi]
9876 [safi],
9877 PEER_CAP_ADDPATH_AF_RX_ADV)
9878 ? " and "
9879 : "");
9880
9881 vty_out(vty, "\n");
9882 }
9883 }
9884 }
9885
9886 /* Dynamic */
9887 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9888 || CHECK_FLAG(p->cap,
9889 PEER_CAP_DYNAMIC_ADV)) {
9890 vty_out(vty, " Dynamic:");
9891 if (CHECK_FLAG(p->cap,
9892 PEER_CAP_DYNAMIC_ADV))
9893 vty_out(vty, " advertised");
9894 if (CHECK_FLAG(p->cap,
9895 PEER_CAP_DYNAMIC_RCV))
9896 vty_out(vty, " %sreceived",
9897 CHECK_FLAG(
9898 p->cap,
9899 PEER_CAP_DYNAMIC_ADV)
9900 ? "and "
9901 : "");
9902 vty_out(vty, "\n");
9903 }
9904
9905 /* Extended nexthop */
9906 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9907 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9908 vty_out(vty, " Extended nexthop:");
9909 if (CHECK_FLAG(p->cap,
9910 PEER_CAP_ENHE_ADV))
9911 vty_out(vty, " advertised");
9912 if (CHECK_FLAG(p->cap,
9913 PEER_CAP_ENHE_RCV))
9914 vty_out(vty, " %sreceived",
9915 CHECK_FLAG(
9916 p->cap,
9917 PEER_CAP_ENHE_ADV)
9918 ? "and "
9919 : "");
9920 vty_out(vty, "\n");
9921
9922 if (CHECK_FLAG(p->cap,
9923 PEER_CAP_ENHE_RCV)) {
9924 vty_out(vty,
9925 " Address families by peer:\n ");
9926 for (safi = SAFI_UNICAST;
9927 safi < SAFI_MAX; safi++)
9928 if (CHECK_FLAG(
9929 p->af_cap
9930 [AFI_IP]
9931 [safi],
9932 PEER_CAP_ENHE_AF_RCV))
9933 vty_out(vty,
9934 " %s\n",
9935 afi_safi_print(
9936 AFI_IP,
9937 safi));
9938 }
9939 }
9940
9941 /* Route Refresh */
9942 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9943 || CHECK_FLAG(p->cap,
9944 PEER_CAP_REFRESH_NEW_RCV)
9945 || CHECK_FLAG(p->cap,
9946 PEER_CAP_REFRESH_OLD_RCV)) {
9947 vty_out(vty, " Route refresh:");
9948 if (CHECK_FLAG(p->cap,
9949 PEER_CAP_REFRESH_ADV))
9950 vty_out(vty, " advertised");
9951 if (CHECK_FLAG(p->cap,
9952 PEER_CAP_REFRESH_NEW_RCV)
9953 || CHECK_FLAG(
9954 p->cap,
9955 PEER_CAP_REFRESH_OLD_RCV))
9956 vty_out(vty, " %sreceived(%s)",
9957 CHECK_FLAG(
9958 p->cap,
9959 PEER_CAP_REFRESH_ADV)
9960 ? "and "
9961 : "",
9962 (CHECK_FLAG(
9963 p->cap,
9964 PEER_CAP_REFRESH_OLD_RCV)
9965 && CHECK_FLAG(
9966 p->cap,
9967 PEER_CAP_REFRESH_NEW_RCV))
9968 ? "old & new"
9969 : CHECK_FLAG(
9970 p->cap,
9971 PEER_CAP_REFRESH_OLD_RCV)
9972 ? "old"
9973 : "new");
9974
9975 vty_out(vty, "\n");
9976 }
9977
9978 /* Multiprotocol Extensions */
9979 FOREACH_AFI_SAFI (afi, safi)
9980 if (p->afc_adv[afi][safi]
9981 || p->afc_recv[afi][safi]) {
9982 vty_out(vty,
9983 " Address Family %s:",
9984 afi_safi_print(afi,
9985 safi));
9986 if (p->afc_adv[afi][safi])
9987 vty_out(vty,
9988 " advertised");
9989 if (p->afc_recv[afi][safi])
9990 vty_out(vty,
9991 " %sreceived",
9992 p->afc_adv[afi]
9993 [safi]
9994 ? "and "
9995 : "");
9996 vty_out(vty, "\n");
9997 }
9998
9999 /* Hostname capability */
10000 vty_out(vty, " Hostname Capability:");
10001
10002 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10003 vty_out(vty,
10004 " advertised (name: %s,domain name: %s)",
10005 bgp->peer_self->hostname
10006 ? bgp->peer_self
10007 ->hostname
10008 : "n/a",
10009 bgp->peer_self->domainname
10010 ? bgp->peer_self
10011 ->domainname
10012 : "n/a");
10013 } else {
10014 vty_out(vty, " not advertised");
10015 }
10016
10017 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10018 vty_out(vty,
10019 " received (name: %s,domain name: %s)",
10020 p->hostname ? p->hostname
10021 : "n/a",
10022 p->domainname ? p->domainname
10023 : "n/a");
10024 } else {
10025 vty_out(vty, " not received");
10026 }
10027
10028 vty_out(vty, "\n");
10029
10030 /* Gracefull Restart */
10031 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10032 || CHECK_FLAG(p->cap,
10033 PEER_CAP_RESTART_ADV)) {
10034 vty_out(vty,
10035 " Graceful Restart Capabilty:");
10036 if (CHECK_FLAG(p->cap,
10037 PEER_CAP_RESTART_ADV))
10038 vty_out(vty, " advertised");
10039 if (CHECK_FLAG(p->cap,
10040 PEER_CAP_RESTART_RCV))
10041 vty_out(vty, " %sreceived",
10042 CHECK_FLAG(
10043 p->cap,
10044 PEER_CAP_RESTART_ADV)
10045 ? "and "
10046 : "");
10047 vty_out(vty, "\n");
10048
10049 if (CHECK_FLAG(p->cap,
10050 PEER_CAP_RESTART_RCV)) {
10051 int restart_af_count = 0;
10052
10053 vty_out(vty,
10054 " Remote Restart timer is %d seconds\n",
10055 p->v_gr_restart);
10056 vty_out(vty,
10057 " Address families by peer:\n ");
10058
10059 FOREACH_AFI_SAFI (afi, safi)
10060 if (CHECK_FLAG(
10061 p->af_cap
10062 [afi]
10063 [safi],
10064 PEER_CAP_RESTART_AF_RCV)) {
10065 vty_out(vty,
10066 "%s%s(%s)",
10067 restart_af_count
10068 ? ", "
10069 : "",
10070 afi_safi_print(
10071 afi,
10072 safi),
10073 CHECK_FLAG(
10074 p->af_cap
10075 [afi]
10076 [safi],
10077 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10078 ? "preserved"
10079 : "not preserved");
10080 restart_af_count++;
10081 }
10082 if (!restart_af_count)
10083 vty_out(vty, "none");
10084 vty_out(vty, "\n");
10085 }
10086 }
10087 }
10088 }
10089 }
10090
10091 /* graceful restart information */
10092 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10093 || p->t_gr_stale) {
10094 json_object *json_grace = NULL;
10095 json_object *json_grace_send = NULL;
10096 json_object *json_grace_recv = NULL;
10097 int eor_send_af_count = 0;
10098 int eor_receive_af_count = 0;
10099
10100 if (use_json) {
10101 json_grace = json_object_new_object();
10102 json_grace_send = json_object_new_object();
10103 json_grace_recv = json_object_new_object();
10104
10105 if (p->status == Established) {
10106 FOREACH_AFI_SAFI (afi, safi) {
10107 if (CHECK_FLAG(p->af_sflags[afi][safi],
10108 PEER_STATUS_EOR_SEND)) {
10109 json_object_boolean_true_add(
10110 json_grace_send,
10111 afi_safi_print(afi,
10112 safi));
10113 eor_send_af_count++;
10114 }
10115 }
10116 FOREACH_AFI_SAFI (afi, safi) {
10117 if (CHECK_FLAG(
10118 p->af_sflags[afi][safi],
10119 PEER_STATUS_EOR_RECEIVED)) {
10120 json_object_boolean_true_add(
10121 json_grace_recv,
10122 afi_safi_print(afi,
10123 safi));
10124 eor_receive_af_count++;
10125 }
10126 }
10127 }
10128
10129 json_object_object_add(json_grace, "endOfRibSend",
10130 json_grace_send);
10131 json_object_object_add(json_grace, "endOfRibRecv",
10132 json_grace_recv);
10133
10134 if (p->t_gr_restart)
10135 json_object_int_add(json_grace,
10136 "gracefulRestartTimerMsecs",
10137 thread_timer_remain_second(
10138 p->t_gr_restart)
10139 * 1000);
10140
10141 if (p->t_gr_stale)
10142 json_object_int_add(
10143 json_grace,
10144 "gracefulStalepathTimerMsecs",
10145 thread_timer_remain_second(
10146 p->t_gr_stale)
10147 * 1000);
10148
10149 json_object_object_add(
10150 json_neigh, "gracefulRestartInfo", json_grace);
10151 } else {
10152 vty_out(vty, " Graceful restart information:\n");
10153 if (p->status == Established) {
10154 vty_out(vty, " End-of-RIB send: ");
10155 FOREACH_AFI_SAFI (afi, safi) {
10156 if (CHECK_FLAG(p->af_sflags[afi][safi],
10157 PEER_STATUS_EOR_SEND)) {
10158 vty_out(vty, "%s%s",
10159 eor_send_af_count ? ", "
10160 : "",
10161 afi_safi_print(afi,
10162 safi));
10163 eor_send_af_count++;
10164 }
10165 }
10166 vty_out(vty, "\n");
10167 vty_out(vty, " End-of-RIB received: ");
10168 FOREACH_AFI_SAFI (afi, safi) {
10169 if (CHECK_FLAG(
10170 p->af_sflags[afi][safi],
10171 PEER_STATUS_EOR_RECEIVED)) {
10172 vty_out(vty, "%s%s",
10173 eor_receive_af_count
10174 ? ", "
10175 : "",
10176 afi_safi_print(afi,
10177 safi));
10178 eor_receive_af_count++;
10179 }
10180 }
10181 vty_out(vty, "\n");
10182 }
10183
10184 if (p->t_gr_restart)
10185 vty_out(vty,
10186 " The remaining time of restart timer is %ld\n",
10187 thread_timer_remain_second(
10188 p->t_gr_restart));
10189
10190 if (p->t_gr_stale)
10191 vty_out(vty,
10192 " The remaining time of stalepath timer is %ld\n",
10193 thread_timer_remain_second(
10194 p->t_gr_stale));
10195 }
10196 }
10197 if (use_json) {
10198 json_object *json_stat = NULL;
10199 json_stat = json_object_new_object();
10200 /* Packet counts. */
10201 json_object_int_add(json_stat, "depthInq", 0);
10202 json_object_int_add(json_stat, "depthOutq",
10203 (unsigned long)p->obuf->count);
10204 json_object_int_add(json_stat, "opensSent",
10205 atomic_load_explicit(&p->open_out,
10206 memory_order_relaxed));
10207 json_object_int_add(json_stat, "opensRecv",
10208 atomic_load_explicit(&p->open_in,
10209 memory_order_relaxed));
10210 json_object_int_add(json_stat, "notificationsSent",
10211 atomic_load_explicit(&p->notify_out,
10212 memory_order_relaxed));
10213 json_object_int_add(json_stat, "notificationsRecv",
10214 atomic_load_explicit(&p->notify_in,
10215 memory_order_relaxed));
10216 json_object_int_add(json_stat, "updatesSent",
10217 atomic_load_explicit(&p->update_out,
10218 memory_order_relaxed));
10219 json_object_int_add(json_stat, "updatesRecv",
10220 atomic_load_explicit(&p->update_in,
10221 memory_order_relaxed));
10222 json_object_int_add(json_stat, "keepalivesSent",
10223 atomic_load_explicit(&p->keepalive_out,
10224 memory_order_relaxed));
10225 json_object_int_add(json_stat, "keepalivesRecv",
10226 atomic_load_explicit(&p->keepalive_in,
10227 memory_order_relaxed));
10228 json_object_int_add(json_stat, "routeRefreshSent",
10229 atomic_load_explicit(&p->refresh_out,
10230 memory_order_relaxed));
10231 json_object_int_add(json_stat, "routeRefreshRecv",
10232 atomic_load_explicit(&p->refresh_in,
10233 memory_order_relaxed));
10234 json_object_int_add(json_stat, "capabilitySent",
10235 atomic_load_explicit(&p->dynamic_cap_out,
10236 memory_order_relaxed));
10237 json_object_int_add(json_stat, "capabilityRecv",
10238 atomic_load_explicit(&p->dynamic_cap_in,
10239 memory_order_relaxed));
10240 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10241 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10242 json_object_object_add(json_neigh, "messageStats", json_stat);
10243 } else {
10244 /* Packet counts. */
10245 vty_out(vty, " Message statistics:\n");
10246 vty_out(vty, " Inq depth is 0\n");
10247 vty_out(vty, " Outq depth is %lu\n",
10248 (unsigned long)p->obuf->count);
10249 vty_out(vty, " Sent Rcvd\n");
10250 vty_out(vty, " Opens: %10d %10d\n",
10251 atomic_load_explicit(&p->open_out,
10252 memory_order_relaxed),
10253 atomic_load_explicit(&p->open_in,
10254 memory_order_relaxed));
10255 vty_out(vty, " Notifications: %10d %10d\n",
10256 atomic_load_explicit(&p->notify_out,
10257 memory_order_relaxed),
10258 atomic_load_explicit(&p->notify_in,
10259 memory_order_relaxed));
10260 vty_out(vty, " Updates: %10d %10d\n",
10261 atomic_load_explicit(&p->update_out,
10262 memory_order_relaxed),
10263 atomic_load_explicit(&p->update_in,
10264 memory_order_relaxed));
10265 vty_out(vty, " Keepalives: %10d %10d\n",
10266 atomic_load_explicit(&p->keepalive_out,
10267 memory_order_relaxed),
10268 atomic_load_explicit(&p->keepalive_in,
10269 memory_order_relaxed));
10270 vty_out(vty, " Route Refresh: %10d %10d\n",
10271 atomic_load_explicit(&p->refresh_out,
10272 memory_order_relaxed),
10273 atomic_load_explicit(&p->refresh_in,
10274 memory_order_relaxed));
10275 vty_out(vty, " Capability: %10d %10d\n",
10276 atomic_load_explicit(&p->dynamic_cap_out,
10277 memory_order_relaxed),
10278 atomic_load_explicit(&p->dynamic_cap_in,
10279 memory_order_relaxed));
10280 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10281 PEER_TOTAL_RX(p));
10282 }
10283
10284 if (use_json) {
10285 /* advertisement-interval */
10286 json_object_int_add(json_neigh,
10287 "minBtwnAdvertisementRunsTimerMsecs",
10288 p->v_routeadv * 1000);
10289
10290 /* Update-source. */
10291 if (p->update_if || p->update_source) {
10292 if (p->update_if)
10293 json_object_string_add(json_neigh,
10294 "updateSource",
10295 p->update_if);
10296 else if (p->update_source)
10297 json_object_string_add(
10298 json_neigh, "updateSource",
10299 sockunion2str(p->update_source, buf1,
10300 SU_ADDRSTRLEN));
10301 }
10302 } else {
10303 /* advertisement-interval */
10304 vty_out(vty,
10305 " Minimum time between advertisement runs is %d seconds\n",
10306 p->v_routeadv);
10307
10308 /* Update-source. */
10309 if (p->update_if || p->update_source) {
10310 vty_out(vty, " Update source is ");
10311 if (p->update_if)
10312 vty_out(vty, "%s", p->update_if);
10313 else if (p->update_source)
10314 vty_out(vty, "%s",
10315 sockunion2str(p->update_source, buf1,
10316 SU_ADDRSTRLEN));
10317 vty_out(vty, "\n");
10318 }
10319
10320 vty_out(vty, "\n");
10321 }
10322
10323 /* Address Family Information */
10324 json_object *json_hold = NULL;
10325
10326 if (use_json)
10327 json_hold = json_object_new_object();
10328
10329 FOREACH_AFI_SAFI (afi, safi)
10330 if (p->afc[afi][safi])
10331 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10332 json_hold);
10333
10334 if (use_json) {
10335 json_object_object_add(json_neigh, "addressFamilyInfo",
10336 json_hold);
10337 json_object_int_add(json_neigh, "connectionsEstablished",
10338 p->established);
10339 json_object_int_add(json_neigh, "connectionsDropped",
10340 p->dropped);
10341 } else
10342 vty_out(vty, " Connections established %d; dropped %d\n",
10343 p->established, p->dropped);
10344
10345 if (!p->last_reset) {
10346 if (use_json)
10347 json_object_string_add(json_neigh, "lastReset",
10348 "never");
10349 else
10350 vty_out(vty, " Last reset never\n");
10351 } else {
10352 if (use_json) {
10353 time_t uptime;
10354 struct tm *tm;
10355
10356 uptime = bgp_clock();
10357 uptime -= p->resettime;
10358 tm = gmtime(&uptime);
10359 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10360 (tm->tm_sec * 1000)
10361 + (tm->tm_min * 60000)
10362 + (tm->tm_hour * 3600000));
10363 json_object_string_add(
10364 json_neigh, "lastResetDueTo",
10365 peer_down_str[(int)p->last_reset]);
10366 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10367 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10368 char errorcodesubcode_hexstr[5];
10369 char errorcodesubcode_str[256];
10370
10371 code_str = bgp_notify_code_str(p->notify.code);
10372 subcode_str = bgp_notify_subcode_str(
10373 p->notify.code, p->notify.subcode);
10374
10375 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10376 p->notify.code, p->notify.subcode);
10377 json_object_string_add(json_neigh,
10378 "lastErrorCodeSubcode",
10379 errorcodesubcode_hexstr);
10380 snprintf(errorcodesubcode_str, 255, "%s%s",
10381 code_str, subcode_str);
10382 json_object_string_add(json_neigh,
10383 "lastNotificationReason",
10384 errorcodesubcode_str);
10385 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10386 && p->notify.code == BGP_NOTIFY_CEASE
10387 && (p->notify.subcode
10388 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10389 || p->notify.subcode
10390 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10391 && p->notify.length) {
10392 char msgbuf[1024];
10393 const char *msg_str;
10394
10395 msg_str = bgp_notify_admin_message(
10396 msgbuf, sizeof(msgbuf),
10397 (uint8_t *)p->notify.data,
10398 p->notify.length);
10399 if (msg_str)
10400 json_object_string_add(
10401 json_neigh,
10402 "lastShutdownDescription",
10403 msg_str);
10404 }
10405 }
10406 } else {
10407 vty_out(vty, " Last reset %s, ",
10408 peer_uptime(p->resettime, timebuf,
10409 BGP_UPTIME_LEN, 0, NULL));
10410
10411 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10412 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10413 code_str = bgp_notify_code_str(p->notify.code);
10414 subcode_str = bgp_notify_subcode_str(
10415 p->notify.code, p->notify.subcode);
10416 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10417 p->last_reset == PEER_DOWN_NOTIFY_SEND
10418 ? "sent"
10419 : "received",
10420 code_str, subcode_str);
10421 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10422 && p->notify.code == BGP_NOTIFY_CEASE
10423 && (p->notify.subcode
10424 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10425 || p->notify.subcode
10426 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10427 && p->notify.length) {
10428 char msgbuf[1024];
10429 const char *msg_str;
10430
10431 msg_str = bgp_notify_admin_message(
10432 msgbuf, sizeof(msgbuf),
10433 (uint8_t *)p->notify.data,
10434 p->notify.length);
10435 if (msg_str)
10436 vty_out(vty,
10437 " Message: \"%s\"\n",
10438 msg_str);
10439 }
10440 } else {
10441 vty_out(vty, "due to %s\n",
10442 peer_down_str[(int)p->last_reset]);
10443 }
10444
10445 if (p->last_reset_cause_size) {
10446 msg = p->last_reset_cause;
10447 vty_out(vty,
10448 " Message received that caused BGP to send a NOTIFICATION:\n ");
10449 for (i = 1; i <= p->last_reset_cause_size;
10450 i++) {
10451 vty_out(vty, "%02X", *msg++);
10452
10453 if (i != p->last_reset_cause_size) {
10454 if (i % 16 == 0) {
10455 vty_out(vty, "\n ");
10456 } else if (i % 4 == 0) {
10457 vty_out(vty, " ");
10458 }
10459 }
10460 }
10461 vty_out(vty, "\n");
10462 }
10463 }
10464 }
10465
10466 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10467 if (use_json)
10468 json_object_boolean_true_add(json_neigh,
10469 "prefixesConfigExceedMax");
10470 else
10471 vty_out(vty,
10472 " Peer had exceeded the max. no. of prefixes configured.\n");
10473
10474 if (p->t_pmax_restart) {
10475 if (use_json) {
10476 json_object_boolean_true_add(
10477 json_neigh, "reducePrefixNumFrom");
10478 json_object_int_add(json_neigh,
10479 "restartInTimerMsec",
10480 thread_timer_remain_second(
10481 p->t_pmax_restart)
10482 * 1000);
10483 } else
10484 vty_out(vty,
10485 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10486 p->host, thread_timer_remain_second(
10487 p->t_pmax_restart));
10488 } else {
10489 if (use_json)
10490 json_object_boolean_true_add(
10491 json_neigh,
10492 "reducePrefixNumAndClearIpBgp");
10493 else
10494 vty_out(vty,
10495 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10496 p->host);
10497 }
10498 }
10499
10500 /* EBGP Multihop and GTSM */
10501 if (p->sort != BGP_PEER_IBGP) {
10502 if (use_json) {
10503 if (p->gtsm_hops > 0)
10504 json_object_int_add(json_neigh,
10505 "externalBgpNbrMaxHopsAway",
10506 p->gtsm_hops);
10507 else if (p->ttl > 1)
10508 json_object_int_add(json_neigh,
10509 "externalBgpNbrMaxHopsAway",
10510 p->ttl);
10511 } else {
10512 if (p->gtsm_hops > 0)
10513 vty_out(vty,
10514 " External BGP neighbor may be up to %d hops away.\n",
10515 p->gtsm_hops);
10516 else if (p->ttl > 1)
10517 vty_out(vty,
10518 " External BGP neighbor may be up to %d hops away.\n",
10519 p->ttl);
10520 }
10521 } else {
10522 if (p->gtsm_hops > 0) {
10523 if (use_json)
10524 json_object_int_add(json_neigh,
10525 "internalBgpNbrMaxHopsAway",
10526 p->gtsm_hops);
10527 else
10528 vty_out(vty,
10529 " Internal BGP neighbor may be up to %d hops away.\n",
10530 p->gtsm_hops);
10531 }
10532 }
10533
10534 /* Local address. */
10535 if (p->su_local) {
10536 if (use_json) {
10537 json_object_string_add(json_neigh, "hostLocal",
10538 sockunion2str(p->su_local, buf1,
10539 SU_ADDRSTRLEN));
10540 json_object_int_add(json_neigh, "portLocal",
10541 ntohs(p->su_local->sin.sin_port));
10542 } else
10543 vty_out(vty, "Local host: %s, Local port: %d\n",
10544 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10545 ntohs(p->su_local->sin.sin_port));
10546 }
10547
10548 /* Remote address. */
10549 if (p->su_remote) {
10550 if (use_json) {
10551 json_object_string_add(json_neigh, "hostForeign",
10552 sockunion2str(p->su_remote, buf1,
10553 SU_ADDRSTRLEN));
10554 json_object_int_add(json_neigh, "portForeign",
10555 ntohs(p->su_remote->sin.sin_port));
10556 } else
10557 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10558 sockunion2str(p->su_remote, buf1,
10559 SU_ADDRSTRLEN),
10560 ntohs(p->su_remote->sin.sin_port));
10561 }
10562
10563 /* Nexthop display. */
10564 if (p->su_local) {
10565 if (use_json) {
10566 json_object_string_add(json_neigh, "nexthop",
10567 inet_ntop(AF_INET,
10568 &p->nexthop.v4, buf1,
10569 sizeof(buf1)));
10570 json_object_string_add(json_neigh, "nexthopGlobal",
10571 inet_ntop(AF_INET6,
10572 &p->nexthop.v6_global,
10573 buf1, sizeof(buf1)));
10574 json_object_string_add(json_neigh, "nexthopLocal",
10575 inet_ntop(AF_INET6,
10576 &p->nexthop.v6_local,
10577 buf1, sizeof(buf1)));
10578 if (p->shared_network)
10579 json_object_string_add(json_neigh,
10580 "bgpConnection",
10581 "sharedNetwork");
10582 else
10583 json_object_string_add(json_neigh,
10584 "bgpConnection",
10585 "nonSharedNetwork");
10586 } else {
10587 vty_out(vty, "Nexthop: %s\n",
10588 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10589 sizeof(buf1)));
10590 vty_out(vty, "Nexthop global: %s\n",
10591 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10592 sizeof(buf1)));
10593 vty_out(vty, "Nexthop local: %s\n",
10594 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10595 sizeof(buf1)));
10596 vty_out(vty, "BGP connection: %s\n",
10597 p->shared_network ? "shared network"
10598 : "non shared network");
10599 }
10600 }
10601
10602 /* Timer information. */
10603 if (use_json) {
10604 json_object_int_add(json_neigh, "connectRetryTimer",
10605 p->v_connect);
10606 if (p->status == Established && p->rtt)
10607 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10608 p->rtt);
10609 if (p->t_start)
10610 json_object_int_add(
10611 json_neigh, "nextStartTimerDueInMsecs",
10612 thread_timer_remain_second(p->t_start) * 1000);
10613 if (p->t_connect)
10614 json_object_int_add(
10615 json_neigh, "nextConnectTimerDueInMsecs",
10616 thread_timer_remain_second(p->t_connect)
10617 * 1000);
10618 if (p->t_routeadv) {
10619 json_object_int_add(json_neigh, "mraiInterval",
10620 p->v_routeadv);
10621 json_object_int_add(
10622 json_neigh, "mraiTimerExpireInMsecs",
10623 thread_timer_remain_second(p->t_routeadv)
10624 * 1000);
10625 }
10626 if (p->password)
10627 json_object_int_add(json_neigh, "authenticationEnabled",
10628 1);
10629
10630 if (p->t_read)
10631 json_object_string_add(json_neigh, "readThread", "on");
10632 else
10633 json_object_string_add(json_neigh, "readThread", "off");
10634
10635 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10636 json_object_string_add(json_neigh, "writeThread", "on");
10637 else
10638 json_object_string_add(json_neigh, "writeThread",
10639 "off");
10640 } else {
10641 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10642 p->v_connect);
10643 if (p->status == Established && p->rtt)
10644 vty_out(vty, "Estimated round trip time: %d ms\n",
10645 p->rtt);
10646 if (p->t_start)
10647 vty_out(vty, "Next start timer due in %ld seconds\n",
10648 thread_timer_remain_second(p->t_start));
10649 if (p->t_connect)
10650 vty_out(vty, "Next connect timer due in %ld seconds\n",
10651 thread_timer_remain_second(p->t_connect));
10652 if (p->t_routeadv)
10653 vty_out(vty,
10654 "MRAI (interval %u) timer expires in %ld seconds\n",
10655 p->v_routeadv,
10656 thread_timer_remain_second(p->t_routeadv));
10657 if (p->password)
10658 vty_out(vty, "Peer Authentication Enabled\n");
10659
10660 vty_out(vty, "Read thread: %s Write thread: %s\n",
10661 p->t_read ? "on" : "off",
10662 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10663 ? "on"
10664 : "off");
10665 }
10666
10667 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10668 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10669 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10670
10671 if (!use_json)
10672 vty_out(vty, "\n");
10673
10674 /* BFD information. */
10675 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10676
10677 if (use_json) {
10678 if (p->conf_if) /* Configured interface name. */
10679 json_object_object_add(json, p->conf_if, json_neigh);
10680 else /* Configured IP address. */
10681 json_object_object_add(json, p->host, json_neigh);
10682 }
10683 }
10684
10685 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10686 enum show_type type, union sockunion *su,
10687 const char *conf_if, uint8_t use_json,
10688 json_object *json)
10689 {
10690 struct listnode *node, *nnode;
10691 struct peer *peer;
10692 int find = 0;
10693
10694 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10695 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10696 continue;
10697
10698 switch (type) {
10699 case show_all:
10700 bgp_show_peer(vty, peer, use_json, json);
10701 break;
10702 case show_peer:
10703 if (conf_if) {
10704 if ((peer->conf_if
10705 && !strcmp(peer->conf_if, conf_if))
10706 || (peer->hostname
10707 && !strcmp(peer->hostname, conf_if))) {
10708 find = 1;
10709 bgp_show_peer(vty, peer, use_json,
10710 json);
10711 }
10712 } else {
10713 if (sockunion_same(&peer->su, su)) {
10714 find = 1;
10715 bgp_show_peer(vty, peer, use_json,
10716 json);
10717 }
10718 }
10719 break;
10720 }
10721 }
10722
10723 if (type == show_peer && !find) {
10724 if (use_json)
10725 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10726 else
10727 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10728 }
10729
10730 if (use_json) {
10731 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10732 json, JSON_C_TO_STRING_PRETTY));
10733 } else {
10734 vty_out(vty, "\n");
10735 }
10736
10737 return CMD_SUCCESS;
10738 }
10739
10740 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10741 enum show_type type,
10742 const char *ip_str,
10743 uint8_t use_json)
10744 {
10745 struct listnode *node, *nnode;
10746 struct bgp *bgp;
10747 union sockunion su;
10748 json_object *json = NULL;
10749 int ret, is_first = 1;
10750
10751 if (use_json)
10752 vty_out(vty, "{\n");
10753
10754 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10755 if (use_json) {
10756 if (!(json = json_object_new_object())) {
10757 flog_err(
10758 BGP_ERR_JSON_MEM_ERROR,
10759 "Unable to allocate memory for JSON object");
10760 vty_out(vty,
10761 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10762 return;
10763 }
10764
10765 json_object_int_add(json, "vrfId",
10766 (bgp->vrf_id == VRF_UNKNOWN)
10767 ? -1
10768 : (int64_t)bgp->vrf_id);
10769 json_object_string_add(
10770 json, "vrfName",
10771 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10772 ? "Default"
10773 : bgp->name);
10774
10775 if (!is_first)
10776 vty_out(vty, ",\n");
10777 else
10778 is_first = 0;
10779
10780 vty_out(vty, "\"%s\":",
10781 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10782 ? "Default"
10783 : bgp->name);
10784 } else {
10785 vty_out(vty, "\nInstance %s:\n",
10786 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10787 ? "Default"
10788 : bgp->name);
10789 }
10790
10791 if (type == show_peer) {
10792 ret = str2sockunion(ip_str, &su);
10793 if (ret < 0)
10794 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10795 use_json, json);
10796 else
10797 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10798 use_json, json);
10799 } else {
10800 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10801 use_json, json);
10802 }
10803 }
10804
10805 if (use_json) {
10806 vty_out(vty, "}\n");
10807 json_object_free(json);
10808 }
10809 }
10810
10811 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10812 enum show_type type, const char *ip_str,
10813 uint8_t use_json)
10814 {
10815 int ret;
10816 struct bgp *bgp;
10817 union sockunion su;
10818 json_object *json = NULL;
10819
10820 if (name) {
10821 if (strmatch(name, "all")) {
10822 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10823 use_json);
10824 return CMD_SUCCESS;
10825 } else {
10826 bgp = bgp_lookup_by_name(name);
10827 if (!bgp) {
10828 if (use_json) {
10829 json = json_object_new_object();
10830 json_object_boolean_true_add(
10831 json, "bgpNoSuchInstance");
10832 vty_out(vty, "%s\n",
10833 json_object_to_json_string_ext(
10834 json,
10835 JSON_C_TO_STRING_PRETTY));
10836 json_object_free(json);
10837 } else
10838 vty_out(vty,
10839 "%% No such BGP instance exist\n");
10840
10841 return CMD_WARNING;
10842 }
10843 }
10844 } else {
10845 bgp = bgp_get_default();
10846 }
10847
10848 if (bgp) {
10849 json = json_object_new_object();
10850 if (ip_str) {
10851 ret = str2sockunion(ip_str, &su);
10852 if (ret < 0)
10853 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10854 use_json, json);
10855 else
10856 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10857 use_json, json);
10858 } else {
10859 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10860 json);
10861 }
10862 json_object_free(json);
10863 }
10864
10865 return CMD_SUCCESS;
10866 }
10867
10868 /* "show [ip] bgp neighbors" commands. */
10869 DEFUN (show_ip_bgp_neighbors,
10870 show_ip_bgp_neighbors_cmd,
10871 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10872 SHOW_STR
10873 IP_STR
10874 BGP_STR
10875 BGP_INSTANCE_HELP_STR
10876 "Address Family\n"
10877 "Address Family\n"
10878 "Detailed information on TCP and BGP neighbor connections\n"
10879 "Neighbor to display information about\n"
10880 "Neighbor to display information about\n"
10881 "Neighbor on BGP configured interface\n"
10882 JSON_STR)
10883 {
10884 char *vrf = NULL;
10885 char *sh_arg = NULL;
10886 enum show_type sh_type;
10887
10888 uint8_t uj = use_json(argc, argv);
10889
10890 int idx = 0;
10891
10892 if (argv_find(argv, argc, "view", &idx)
10893 || argv_find(argv, argc, "vrf", &idx))
10894 vrf = argv[idx + 1]->arg;
10895
10896 idx++;
10897 if (argv_find(argv, argc, "A.B.C.D", &idx)
10898 || argv_find(argv, argc, "X:X::X:X", &idx)
10899 || argv_find(argv, argc, "WORD", &idx)) {
10900 sh_type = show_peer;
10901 sh_arg = argv[idx]->arg;
10902 } else
10903 sh_type = show_all;
10904
10905 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10906 }
10907
10908 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10909 paths' and `show ip mbgp paths'. Those functions results are the
10910 same.*/
10911 DEFUN (show_ip_bgp_paths,
10912 show_ip_bgp_paths_cmd,
10913 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10914 SHOW_STR
10915 IP_STR
10916 BGP_STR
10917 BGP_SAFI_HELP_STR
10918 "Path information\n")
10919 {
10920 vty_out(vty, "Address Refcnt Path\n");
10921 aspath_print_all_vty(vty);
10922 return CMD_SUCCESS;
10923 }
10924
10925 #include "hash.h"
10926
10927 static void community_show_all_iterator(struct hash_backet *backet,
10928 struct vty *vty)
10929 {
10930 struct community *com;
10931
10932 com = (struct community *)backet->data;
10933 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10934 community_str(com, false));
10935 }
10936
10937 /* Show BGP's community internal data. */
10938 DEFUN (show_ip_bgp_community_info,
10939 show_ip_bgp_community_info_cmd,
10940 "show [ip] bgp community-info",
10941 SHOW_STR
10942 IP_STR
10943 BGP_STR
10944 "List all bgp community information\n")
10945 {
10946 vty_out(vty, "Address Refcnt Community\n");
10947
10948 hash_iterate(community_hash(),
10949 (void (*)(struct hash_backet *,
10950 void *))community_show_all_iterator,
10951 vty);
10952
10953 return CMD_SUCCESS;
10954 }
10955
10956 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10957 struct vty *vty)
10958 {
10959 struct lcommunity *lcom;
10960
10961 lcom = (struct lcommunity *)backet->data;
10962 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10963 lcommunity_str(lcom, false));
10964 }
10965
10966 /* Show BGP's community internal data. */
10967 DEFUN (show_ip_bgp_lcommunity_info,
10968 show_ip_bgp_lcommunity_info_cmd,
10969 "show ip bgp large-community-info",
10970 SHOW_STR
10971 IP_STR
10972 BGP_STR
10973 "List all bgp large-community information\n")
10974 {
10975 vty_out(vty, "Address Refcnt Large-community\n");
10976
10977 hash_iterate(lcommunity_hash(),
10978 (void (*)(struct hash_backet *,
10979 void *))lcommunity_show_all_iterator,
10980 vty);
10981
10982 return CMD_SUCCESS;
10983 }
10984
10985
10986 DEFUN (show_ip_bgp_attr_info,
10987 show_ip_bgp_attr_info_cmd,
10988 "show [ip] bgp attribute-info",
10989 SHOW_STR
10990 IP_STR
10991 BGP_STR
10992 "List all bgp attribute information\n")
10993 {
10994 attr_show_all(vty);
10995 return CMD_SUCCESS;
10996 }
10997
10998 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10999 afi_t afi, safi_t safi, uint8_t use_json)
11000 {
11001 struct bgp *bgp;
11002 struct listnode *node;
11003 char *vname;
11004 char buf1[INET6_ADDRSTRLEN];
11005 char *ecom_str;
11006 vpn_policy_direction_t dir;
11007
11008 if (use_json) {
11009 json_object *json = NULL;
11010 json_object *json_import_vrfs = NULL;
11011 json_object *json_export_vrfs = NULL;
11012
11013 json = json_object_new_object();
11014
11015 /* Provide context for the block */
11016 json_object_string_add(json, "vrf", name ? name : "default");
11017 json_object_string_add(json, "afiSafi",
11018 afi_safi_print(afi, safi));
11019
11020 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11021
11022 if (!bgp) {
11023 json_object_boolean_true_add(json,
11024 "bgpNoSuchInstance");
11025 vty_out(vty, "%s\n",
11026 json_object_to_json_string_ext(
11027 json,
11028 JSON_C_TO_STRING_PRETTY));
11029 json_object_free(json);
11030
11031 return CMD_WARNING;
11032 }
11033
11034 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11035 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11036 json_object_string_add(json, "importFromVrfs", "none");
11037 json_object_string_add(json, "importRts", "none");
11038 } else {
11039 json_import_vrfs = json_object_new_array();
11040
11041 for (ALL_LIST_ELEMENTS_RO(
11042 bgp->vpn_policy[afi].import_vrf,
11043 node, vname))
11044 json_object_array_add(json_import_vrfs,
11045 json_object_new_string(vname));
11046
11047 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11048 ecom_str = ecommunity_ecom2str(
11049 bgp->vpn_policy[afi].rtlist[dir],
11050 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11051 json_object_object_add(json, "importFromVrfs",
11052 json_import_vrfs);
11053 json_object_string_add(json, "importRts", ecom_str);
11054
11055 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11056 }
11057
11058 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11059 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11060 json_object_string_add(json, "exportToVrfs", "none");
11061 json_object_string_add(json, "routeDistinguisher",
11062 "none");
11063 json_object_string_add(json, "exportRts", "none");
11064 } else {
11065 json_export_vrfs = json_object_new_array();
11066
11067 for (ALL_LIST_ELEMENTS_RO(
11068 bgp->vpn_policy[afi].export_vrf,
11069 node, vname))
11070 json_object_array_add(json_export_vrfs,
11071 json_object_new_string(vname));
11072 json_object_object_add(json, "exportToVrfs",
11073 json_export_vrfs);
11074 json_object_string_add(json, "routeDistinguisher",
11075 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11076 buf1, RD_ADDRSTRLEN));
11077
11078 dir = BGP_VPN_POLICY_DIR_TOVPN;
11079 ecom_str = ecommunity_ecom2str(
11080 bgp->vpn_policy[afi].rtlist[dir],
11081 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11082 json_object_string_add(json, "exportRts", ecom_str);
11083
11084 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11085 }
11086
11087 vty_out(vty, "%s\n",
11088 json_object_to_json_string_ext(json,
11089 JSON_C_TO_STRING_PRETTY));
11090 json_object_free(json);
11091
11092 } else {
11093 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11094
11095 if (!bgp) {
11096 vty_out(vty, "%% No such BGP instance exist\n");
11097 return CMD_WARNING;
11098 }
11099
11100 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11101 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11102 vty_out(vty,
11103 "This VRF is not importing %s routes from any other VRF\n",
11104 afi_safi_print(afi, safi));
11105 else {
11106 vty_out(vty,
11107 "This VRF is importing %s routes from the following VRFs:\n",
11108 afi_safi_print(afi, safi));
11109
11110 for (ALL_LIST_ELEMENTS_RO(
11111 bgp->vpn_policy[afi].import_vrf,
11112 node, vname))
11113 vty_out(vty, " %s\n", vname);
11114
11115 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11116 ecom_str = ecommunity_ecom2str(
11117 bgp->vpn_policy[afi].rtlist[dir],
11118 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11119 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11120
11121 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11122 }
11123
11124 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11125 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11126 vty_out(vty,
11127 "This VRF is not exporting %s routes to any other VRF\n",
11128 afi_safi_print(afi, safi));
11129 else {
11130 vty_out(vty,
11131 "This VRF is exporting %s routes to the following VRFs:\n",
11132 afi_safi_print(afi, safi));
11133
11134 for (ALL_LIST_ELEMENTS_RO(
11135 bgp->vpn_policy[afi].export_vrf,
11136 node, vname))
11137 vty_out(vty, " %s\n", vname);
11138
11139 vty_out(vty, "RD: %s\n",
11140 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11141 buf1, RD_ADDRSTRLEN));
11142
11143 dir = BGP_VPN_POLICY_DIR_TOVPN;
11144 ecom_str = ecommunity_ecom2str(
11145 bgp->vpn_policy[afi].rtlist[dir],
11146 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11147 vty_out(vty, "Export RT: %s\n", ecom_str);
11148 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11149 }
11150 }
11151
11152 return CMD_SUCCESS;
11153 }
11154
11155 /* "show [ip] bgp route-leak" command. */
11156 DEFUN (show_ip_bgp_route_leak,
11157 show_ip_bgp_route_leak_cmd,
11158 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11159 SHOW_STR
11160 IP_STR
11161 BGP_STR
11162 BGP_INSTANCE_HELP_STR
11163 BGP_AFI_HELP_STR
11164 BGP_SAFI_HELP_STR
11165 "Route leaking information\n"
11166 JSON_STR)
11167 {
11168 char *vrf = NULL;
11169 afi_t afi = AFI_MAX;
11170 safi_t safi = SAFI_MAX;
11171
11172 uint8_t uj = use_json(argc, argv);
11173 int idx = 0;
11174
11175 /* show [ip] bgp */
11176 if (argv_find(argv, argc, "ip", &idx)) {
11177 afi = AFI_IP;
11178 safi = SAFI_UNICAST;
11179 }
11180 /* [vrf VIEWVRFNAME] */
11181 if (argv_find(argv, argc, "view", &idx)) {
11182 vty_out(vty,
11183 "%% This command is not applicable to BGP views\n");
11184 return CMD_WARNING;
11185 }
11186
11187 if (argv_find(argv, argc, "vrf", &idx))
11188 vrf = argv[++idx]->arg;
11189 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11190 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11191 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11192 }
11193
11194 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11195 vty_out(vty,
11196 "%% This command is applicable only for unicast ipv4|ipv6\n");
11197 return CMD_WARNING;
11198 }
11199
11200 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
11201 }
11202
11203 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11204 safi_t safi)
11205 {
11206 struct listnode *node, *nnode;
11207 struct bgp *bgp;
11208
11209 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11210 vty_out(vty, "\nInstance %s:\n",
11211 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11212 ? "Default"
11213 : bgp->name);
11214 update_group_show(bgp, afi, safi, vty, 0);
11215 }
11216 }
11217
11218 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11219 int safi, uint64_t subgrp_id)
11220 {
11221 struct bgp *bgp;
11222
11223 if (name) {
11224 if (strmatch(name, "all")) {
11225 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11226 return CMD_SUCCESS;
11227 } else {
11228 bgp = bgp_lookup_by_name(name);
11229 }
11230 } else {
11231 bgp = bgp_get_default();
11232 }
11233
11234 if (bgp)
11235 update_group_show(bgp, afi, safi, vty, subgrp_id);
11236 return CMD_SUCCESS;
11237 }
11238
11239 DEFUN (show_ip_bgp_updgrps,
11240 show_ip_bgp_updgrps_cmd,
11241 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11242 SHOW_STR
11243 IP_STR
11244 BGP_STR
11245 BGP_INSTANCE_HELP_STR
11246 BGP_AFI_HELP_STR
11247 BGP_SAFI_WITH_LABEL_HELP_STR
11248 "Detailed info about dynamic update groups\n"
11249 "Specific subgroup to display detailed info for\n")
11250 {
11251 char *vrf = NULL;
11252 afi_t afi = AFI_IP6;
11253 safi_t safi = SAFI_UNICAST;
11254 uint64_t subgrp_id = 0;
11255
11256 int idx = 0;
11257
11258 /* show [ip] bgp */
11259 if (argv_find(argv, argc, "ip", &idx))
11260 afi = AFI_IP;
11261 /* [<view|vrf> VIEWVRFNAME] */
11262 if (argv_find(argv, argc, "view", &idx)
11263 || argv_find(argv, argc, "vrf", &idx))
11264 vrf = argv[++idx]->arg;
11265 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11266 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11267 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11268 }
11269
11270 /* get subgroup id, if provided */
11271 idx = argc - 1;
11272 if (argv[idx]->type == VARIABLE_TKN)
11273 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11274
11275 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11276 }
11277
11278 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11279 show_bgp_instance_all_ipv6_updgrps_cmd,
11280 "show [ip] bgp <view|vrf> all update-groups",
11281 SHOW_STR
11282 IP_STR
11283 BGP_STR
11284 BGP_INSTANCE_ALL_HELP_STR
11285 "Detailed info about dynamic update groups\n")
11286 {
11287 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11288 return CMD_SUCCESS;
11289 }
11290
11291 DEFUN (show_bgp_updgrps_stats,
11292 show_bgp_updgrps_stats_cmd,
11293 "show [ip] bgp update-groups statistics",
11294 SHOW_STR
11295 IP_STR
11296 BGP_STR
11297 "Detailed info about dynamic update groups\n"
11298 "Statistics\n")
11299 {
11300 struct bgp *bgp;
11301
11302 bgp = bgp_get_default();
11303 if (bgp)
11304 update_group_show_stats(bgp, vty);
11305
11306 return CMD_SUCCESS;
11307 }
11308
11309 DEFUN (show_bgp_instance_updgrps_stats,
11310 show_bgp_instance_updgrps_stats_cmd,
11311 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11312 SHOW_STR
11313 IP_STR
11314 BGP_STR
11315 BGP_INSTANCE_HELP_STR
11316 "Detailed info about dynamic update groups\n"
11317 "Statistics\n")
11318 {
11319 int idx_word = 3;
11320 struct bgp *bgp;
11321
11322 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11323 if (bgp)
11324 update_group_show_stats(bgp, vty);
11325
11326 return CMD_SUCCESS;
11327 }
11328
11329 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11330 afi_t afi, safi_t safi,
11331 const char *what, uint64_t subgrp_id)
11332 {
11333 struct bgp *bgp;
11334
11335 if (name)
11336 bgp = bgp_lookup_by_name(name);
11337 else
11338 bgp = bgp_get_default();
11339
11340 if (bgp) {
11341 if (!strcmp(what, "advertise-queue"))
11342 update_group_show_adj_queue(bgp, afi, safi, vty,
11343 subgrp_id);
11344 else if (!strcmp(what, "advertised-routes"))
11345 update_group_show_advertised(bgp, afi, safi, vty,
11346 subgrp_id);
11347 else if (!strcmp(what, "packet-queue"))
11348 update_group_show_packet_queue(bgp, afi, safi, vty,
11349 subgrp_id);
11350 }
11351 }
11352
11353 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11354 show_ip_bgp_instance_updgrps_adj_s_cmd,
11355 "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",
11356 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11357 BGP_SAFI_HELP_STR
11358 "Detailed info about dynamic update groups\n"
11359 "Specific subgroup to display info for\n"
11360 "Advertisement queue\n"
11361 "Announced routes\n"
11362 "Packet queue\n")
11363 {
11364 uint64_t subgrp_id = 0;
11365 afi_t afiz;
11366 safi_t safiz;
11367 if (sgid)
11368 subgrp_id = strtoull(sgid, NULL, 10);
11369
11370 if (!ip && !afi)
11371 afiz = AFI_IP6;
11372 if (!ip && afi)
11373 afiz = bgp_vty_afi_from_str(afi);
11374 if (ip && !afi)
11375 afiz = AFI_IP;
11376 if (ip && afi) {
11377 afiz = bgp_vty_afi_from_str(afi);
11378 if (afiz != AFI_IP)
11379 vty_out(vty,
11380 "%% Cannot specify both 'ip' and 'ipv6'\n");
11381 return CMD_WARNING;
11382 }
11383
11384 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11385
11386 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11387 return CMD_SUCCESS;
11388 }
11389
11390 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11391 {
11392 struct listnode *node, *nnode;
11393 struct prefix *range;
11394 struct peer *conf;
11395 struct peer *peer;
11396 char buf[PREFIX2STR_BUFFER];
11397 afi_t afi;
11398 safi_t safi;
11399 const char *peer_status;
11400 const char *af_str;
11401 int lr_count;
11402 int dynamic;
11403 int af_cfgd;
11404
11405 conf = group->conf;
11406
11407 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11408 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11409 group->name, conf->as);
11410 } else if (conf->as_type == AS_INTERNAL) {
11411 vty_out(vty, "\nBGP peer-group %s, remote AS %" PRIu32 "\n",
11412 group->name, group->bgp->as);
11413 } else {
11414 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11415 }
11416
11417 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11418 vty_out(vty, " Peer-group type is internal\n");
11419 else
11420 vty_out(vty, " Peer-group type is external\n");
11421
11422 /* Display AFs configured. */
11423 vty_out(vty, " Configured address-families:");
11424 FOREACH_AFI_SAFI (afi, safi) {
11425 if (conf->afc[afi][safi]) {
11426 af_cfgd = 1;
11427 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11428 }
11429 }
11430 if (!af_cfgd)
11431 vty_out(vty, " none\n");
11432 else
11433 vty_out(vty, "\n");
11434
11435 /* Display listen ranges (for dynamic neighbors), if any */
11436 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11437 if (afi == AFI_IP)
11438 af_str = "IPv4";
11439 else if (afi == AFI_IP6)
11440 af_str = "IPv6";
11441 else
11442 af_str = "???";
11443 lr_count = listcount(group->listen_range[afi]);
11444 if (lr_count) {
11445 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11446 af_str);
11447
11448
11449 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11450 nnode, range)) {
11451 prefix2str(range, buf, sizeof(buf));
11452 vty_out(vty, " %s\n", buf);
11453 }
11454 }
11455 }
11456
11457 /* Display group members and their status */
11458 if (listcount(group->peer)) {
11459 vty_out(vty, " Peer-group members:\n");
11460 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11461 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11462 peer_status = "Idle (Admin)";
11463 else if (CHECK_FLAG(peer->sflags,
11464 PEER_STATUS_PREFIX_OVERFLOW))
11465 peer_status = "Idle (PfxCt)";
11466 else
11467 peer_status = lookup_msg(bgp_status_msg,
11468 peer->status, NULL);
11469
11470 dynamic = peer_dynamic_neighbor(peer);
11471 vty_out(vty, " %s %s %s \n", peer->host,
11472 dynamic ? "(dynamic)" : "", peer_status);
11473 }
11474 }
11475
11476 return CMD_SUCCESS;
11477 }
11478
11479 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11480 const char *group_name)
11481 {
11482 struct bgp *bgp;
11483 struct listnode *node, *nnode;
11484 struct peer_group *group;
11485 bool found = false;
11486
11487 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11488
11489 if (!bgp) {
11490 vty_out(vty, "%% No such BGP instance exists\n");
11491 return CMD_WARNING;
11492 }
11493
11494 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11495 if (group_name) {
11496 if (strmatch(group->name, group_name)) {
11497 bgp_show_one_peer_group(vty, group);
11498 found = true;
11499 break;
11500 }
11501 } else {
11502 bgp_show_one_peer_group(vty, group);
11503 }
11504 }
11505
11506 if (group_name && !found)
11507 vty_out(vty, "%% No such peer-group\n");
11508
11509 return CMD_SUCCESS;
11510 }
11511
11512 DEFUN (show_ip_bgp_peer_groups,
11513 show_ip_bgp_peer_groups_cmd,
11514 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11515 SHOW_STR
11516 IP_STR
11517 BGP_STR
11518 BGP_INSTANCE_HELP_STR
11519 "Detailed information on BGP peer groups\n"
11520 "Peer group name\n")
11521 {
11522 char *vrf, *pg;
11523 int idx = 0;
11524
11525 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11526 : NULL;
11527 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11528
11529 return bgp_show_peer_group_vty(vty, vrf, pg);
11530 }
11531
11532
11533 /* Redistribute VTY commands. */
11534
11535 DEFUN (bgp_redistribute_ipv4,
11536 bgp_redistribute_ipv4_cmd,
11537 "redistribute " FRR_IP_REDIST_STR_BGPD,
11538 "Redistribute information from another routing protocol\n"
11539 FRR_IP_REDIST_HELP_STR_BGPD)
11540 {
11541 VTY_DECLVAR_CONTEXT(bgp, bgp);
11542 int idx_protocol = 1;
11543 int type;
11544
11545 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11546 if (type < 0) {
11547 vty_out(vty, "%% Invalid route type\n");
11548 return CMD_WARNING_CONFIG_FAILED;
11549 }
11550
11551 bgp_redist_add(bgp, AFI_IP, type, 0);
11552 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11553 }
11554
11555 ALIAS_HIDDEN(
11556 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11557 "redistribute " FRR_IP_REDIST_STR_BGPD,
11558 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11559
11560 DEFUN (bgp_redistribute_ipv4_rmap,
11561 bgp_redistribute_ipv4_rmap_cmd,
11562 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11563 "Redistribute information from another routing protocol\n"
11564 FRR_IP_REDIST_HELP_STR_BGPD
11565 "Route map reference\n"
11566 "Pointer to route-map entries\n")
11567 {
11568 VTY_DECLVAR_CONTEXT(bgp, bgp);
11569 int idx_protocol = 1;
11570 int idx_word = 3;
11571 int type;
11572 struct bgp_redist *red;
11573 bool changed;
11574
11575 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11576 if (type < 0) {
11577 vty_out(vty, "%% Invalid route type\n");
11578 return CMD_WARNING_CONFIG_FAILED;
11579 }
11580
11581 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11582 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11583 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11584 }
11585
11586 ALIAS_HIDDEN(
11587 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11588 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11589 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11590 "Route map reference\n"
11591 "Pointer to route-map entries\n")
11592
11593 DEFUN (bgp_redistribute_ipv4_metric,
11594 bgp_redistribute_ipv4_metric_cmd,
11595 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11596 "Redistribute information from another routing protocol\n"
11597 FRR_IP_REDIST_HELP_STR_BGPD
11598 "Metric for redistributed routes\n"
11599 "Default metric\n")
11600 {
11601 VTY_DECLVAR_CONTEXT(bgp, bgp);
11602 int idx_protocol = 1;
11603 int idx_number = 3;
11604 int type;
11605 uint32_t metric;
11606 struct bgp_redist *red;
11607 bool changed;
11608
11609 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11610 if (type < 0) {
11611 vty_out(vty, "%% Invalid route type\n");
11612 return CMD_WARNING_CONFIG_FAILED;
11613 }
11614 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11615
11616 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11617 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11618 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11619 }
11620
11621 ALIAS_HIDDEN(
11622 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11623 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11624 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11625 "Metric for redistributed routes\n"
11626 "Default metric\n")
11627
11628 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11629 bgp_redistribute_ipv4_rmap_metric_cmd,
11630 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11631 "Redistribute information from another routing protocol\n"
11632 FRR_IP_REDIST_HELP_STR_BGPD
11633 "Route map reference\n"
11634 "Pointer to route-map entries\n"
11635 "Metric for redistributed routes\n"
11636 "Default metric\n")
11637 {
11638 VTY_DECLVAR_CONTEXT(bgp, bgp);
11639 int idx_protocol = 1;
11640 int idx_word = 3;
11641 int idx_number = 5;
11642 int type;
11643 uint32_t metric;
11644 struct bgp_redist *red;
11645 bool changed;
11646
11647 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11648 if (type < 0) {
11649 vty_out(vty, "%% Invalid route type\n");
11650 return CMD_WARNING_CONFIG_FAILED;
11651 }
11652 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11653
11654 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11655 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11656 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11657 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11658 }
11659
11660 ALIAS_HIDDEN(
11661 bgp_redistribute_ipv4_rmap_metric,
11662 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11663 "redistribute " FRR_IP_REDIST_STR_BGPD
11664 " route-map WORD metric (0-4294967295)",
11665 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11666 "Route map reference\n"
11667 "Pointer to route-map entries\n"
11668 "Metric for redistributed routes\n"
11669 "Default metric\n")
11670
11671 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11672 bgp_redistribute_ipv4_metric_rmap_cmd,
11673 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11674 "Redistribute information from another routing protocol\n"
11675 FRR_IP_REDIST_HELP_STR_BGPD
11676 "Metric for redistributed routes\n"
11677 "Default metric\n"
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_number = 3;
11684 int idx_word = 5;
11685 int type;
11686 uint32_t metric;
11687 struct bgp_redist *red;
11688 bool changed;
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 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11696
11697 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11698 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11699 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11700 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11701 }
11702
11703 ALIAS_HIDDEN(
11704 bgp_redistribute_ipv4_metric_rmap,
11705 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11706 "redistribute " FRR_IP_REDIST_STR_BGPD
11707 " metric (0-4294967295) route-map WORD",
11708 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11709 "Metric for redistributed routes\n"
11710 "Default metric\n"
11711 "Route map reference\n"
11712 "Pointer to route-map entries\n")
11713
11714 DEFUN (bgp_redistribute_ipv4_ospf,
11715 bgp_redistribute_ipv4_ospf_cmd,
11716 "redistribute <ospf|table> (1-65535)",
11717 "Redistribute information from another routing protocol\n"
11718 "Open Shortest Path First (OSPFv2)\n"
11719 "Non-main Kernel Routing Table\n"
11720 "Instance ID/Table ID\n")
11721 {
11722 VTY_DECLVAR_CONTEXT(bgp, bgp);
11723 int idx_ospf_table = 1;
11724 int idx_number = 2;
11725 unsigned short instance;
11726 unsigned short protocol;
11727
11728 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11729
11730 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11731 protocol = ZEBRA_ROUTE_OSPF;
11732 else
11733 protocol = ZEBRA_ROUTE_TABLE;
11734
11735 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11736 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
11737 }
11738
11739 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11740 "redistribute <ospf|table> (1-65535)",
11741 "Redistribute information from another routing protocol\n"
11742 "Open Shortest Path First (OSPFv2)\n"
11743 "Non-main Kernel Routing Table\n"
11744 "Instance ID/Table ID\n")
11745
11746 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11747 bgp_redistribute_ipv4_ospf_rmap_cmd,
11748 "redistribute <ospf|table> (1-65535) route-map WORD",
11749 "Redistribute information from another routing protocol\n"
11750 "Open Shortest Path First (OSPFv2)\n"
11751 "Non-main Kernel Routing Table\n"
11752 "Instance ID/Table ID\n"
11753 "Route map reference\n"
11754 "Pointer to route-map entries\n")
11755 {
11756 VTY_DECLVAR_CONTEXT(bgp, bgp);
11757 int idx_ospf_table = 1;
11758 int idx_number = 2;
11759 int idx_word = 4;
11760 struct bgp_redist *red;
11761 unsigned short instance;
11762 int protocol;
11763 bool changed;
11764
11765 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11766 protocol = ZEBRA_ROUTE_OSPF;
11767 else
11768 protocol = ZEBRA_ROUTE_TABLE;
11769
11770 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11771 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11772 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11773 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11774 }
11775
11776 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11777 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11778 "redistribute <ospf|table> (1-65535) route-map WORD",
11779 "Redistribute information from another routing protocol\n"
11780 "Open Shortest Path First (OSPFv2)\n"
11781 "Non-main Kernel Routing Table\n"
11782 "Instance ID/Table ID\n"
11783 "Route map reference\n"
11784 "Pointer to route-map entries\n")
11785
11786 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11787 bgp_redistribute_ipv4_ospf_metric_cmd,
11788 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11789 "Redistribute information from another routing protocol\n"
11790 "Open Shortest Path First (OSPFv2)\n"
11791 "Non-main Kernel Routing Table\n"
11792 "Instance ID/Table ID\n"
11793 "Metric for redistributed routes\n"
11794 "Default metric\n")
11795 {
11796 VTY_DECLVAR_CONTEXT(bgp, bgp);
11797 int idx_ospf_table = 1;
11798 int idx_number = 2;
11799 int idx_number_2 = 4;
11800 uint32_t metric;
11801 struct bgp_redist *red;
11802 unsigned short instance;
11803 int protocol;
11804 bool changed;
11805
11806 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11807 protocol = ZEBRA_ROUTE_OSPF;
11808 else
11809 protocol = ZEBRA_ROUTE_TABLE;
11810
11811 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11812 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11813
11814 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11815 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11816 metric);
11817 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11818 }
11819
11820 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11821 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11822 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11823 "Redistribute information from another routing protocol\n"
11824 "Open Shortest Path First (OSPFv2)\n"
11825 "Non-main Kernel Routing Table\n"
11826 "Instance ID/Table ID\n"
11827 "Metric for redistributed routes\n"
11828 "Default metric\n")
11829
11830 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11831 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11832 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11833 "Redistribute information from another routing protocol\n"
11834 "Open Shortest Path First (OSPFv2)\n"
11835 "Non-main Kernel Routing Table\n"
11836 "Instance ID/Table ID\n"
11837 "Route map reference\n"
11838 "Pointer to route-map entries\n"
11839 "Metric for redistributed routes\n"
11840 "Default metric\n")
11841 {
11842 VTY_DECLVAR_CONTEXT(bgp, bgp);
11843 int idx_ospf_table = 1;
11844 int idx_number = 2;
11845 int idx_word = 4;
11846 int idx_number_2 = 6;
11847 uint32_t metric;
11848 struct bgp_redist *red;
11849 unsigned short instance;
11850 int protocol;
11851 bool changed;
11852
11853 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11854 protocol = ZEBRA_ROUTE_OSPF;
11855 else
11856 protocol = ZEBRA_ROUTE_TABLE;
11857
11858 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11859 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11860
11861 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11862 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11863 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11864 metric);
11865 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11866 }
11867
11868 ALIAS_HIDDEN(
11869 bgp_redistribute_ipv4_ospf_rmap_metric,
11870 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11871 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11872 "Redistribute information from another routing protocol\n"
11873 "Open Shortest Path First (OSPFv2)\n"
11874 "Non-main Kernel Routing Table\n"
11875 "Instance ID/Table ID\n"
11876 "Route map reference\n"
11877 "Pointer to route-map entries\n"
11878 "Metric for redistributed routes\n"
11879 "Default metric\n")
11880
11881 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11882 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11883 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11884 "Redistribute information from another routing protocol\n"
11885 "Open Shortest Path First (OSPFv2)\n"
11886 "Non-main Kernel Routing Table\n"
11887 "Instance ID/Table ID\n"
11888 "Metric for redistributed routes\n"
11889 "Default metric\n"
11890 "Route map reference\n"
11891 "Pointer to route-map entries\n")
11892 {
11893 VTY_DECLVAR_CONTEXT(bgp, bgp);
11894 int idx_ospf_table = 1;
11895 int idx_number = 2;
11896 int idx_number_2 = 4;
11897 int idx_word = 6;
11898 uint32_t metric;
11899 struct bgp_redist *red;
11900 unsigned short instance;
11901 int protocol;
11902 bool changed;
11903
11904 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11905 protocol = ZEBRA_ROUTE_OSPF;
11906 else
11907 protocol = ZEBRA_ROUTE_TABLE;
11908
11909 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11910 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11911
11912 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11913 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11914 metric);
11915 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11916 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11917 }
11918
11919 ALIAS_HIDDEN(
11920 bgp_redistribute_ipv4_ospf_metric_rmap,
11921 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11922 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11923 "Redistribute information from another routing protocol\n"
11924 "Open Shortest Path First (OSPFv2)\n"
11925 "Non-main Kernel Routing Table\n"
11926 "Instance ID/Table ID\n"
11927 "Metric for redistributed routes\n"
11928 "Default metric\n"
11929 "Route map reference\n"
11930 "Pointer to route-map entries\n")
11931
11932 DEFUN (no_bgp_redistribute_ipv4_ospf,
11933 no_bgp_redistribute_ipv4_ospf_cmd,
11934 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11935 NO_STR
11936 "Redistribute information from another routing protocol\n"
11937 "Open Shortest Path First (OSPFv2)\n"
11938 "Non-main Kernel Routing Table\n"
11939 "Instance ID/Table ID\n"
11940 "Metric for redistributed routes\n"
11941 "Default metric\n"
11942 "Route map reference\n"
11943 "Pointer to route-map entries\n")
11944 {
11945 VTY_DECLVAR_CONTEXT(bgp, bgp);
11946 int idx_ospf_table = 2;
11947 int idx_number = 3;
11948 unsigned short instance;
11949 int protocol;
11950
11951 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11952 protocol = ZEBRA_ROUTE_OSPF;
11953 else
11954 protocol = ZEBRA_ROUTE_TABLE;
11955
11956 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11957 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11958 }
11959
11960 ALIAS_HIDDEN(
11961 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11962 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11963 NO_STR
11964 "Redistribute information from another routing protocol\n"
11965 "Open Shortest Path First (OSPFv2)\n"
11966 "Non-main Kernel Routing Table\n"
11967 "Instance ID/Table ID\n"
11968 "Metric for redistributed routes\n"
11969 "Default metric\n"
11970 "Route map reference\n"
11971 "Pointer to route-map entries\n")
11972
11973 DEFUN (no_bgp_redistribute_ipv4,
11974 no_bgp_redistribute_ipv4_cmd,
11975 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11976 NO_STR
11977 "Redistribute information from another routing protocol\n"
11978 FRR_IP_REDIST_HELP_STR_BGPD
11979 "Metric for redistributed routes\n"
11980 "Default metric\n"
11981 "Route map reference\n"
11982 "Pointer to route-map entries\n")
11983 {
11984 VTY_DECLVAR_CONTEXT(bgp, bgp);
11985 int idx_protocol = 2;
11986 int type;
11987
11988 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11989 if (type < 0) {
11990 vty_out(vty, "%% Invalid route type\n");
11991 return CMD_WARNING_CONFIG_FAILED;
11992 }
11993 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11994 }
11995
11996 ALIAS_HIDDEN(
11997 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11998 "no redistribute " FRR_IP_REDIST_STR_BGPD
11999 " [metric (0-4294967295)] [route-map WORD]",
12000 NO_STR
12001 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12002 "Metric for redistributed routes\n"
12003 "Default metric\n"
12004 "Route map reference\n"
12005 "Pointer to route-map entries\n")
12006
12007 DEFUN (bgp_redistribute_ipv6,
12008 bgp_redistribute_ipv6_cmd,
12009 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12010 "Redistribute information from another routing protocol\n"
12011 FRR_IP6_REDIST_HELP_STR_BGPD)
12012 {
12013 VTY_DECLVAR_CONTEXT(bgp, bgp);
12014 int idx_protocol = 1;
12015 int type;
12016
12017 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12018 if (type < 0) {
12019 vty_out(vty, "%% Invalid route type\n");
12020 return CMD_WARNING_CONFIG_FAILED;
12021 }
12022
12023 bgp_redist_add(bgp, AFI_IP6, type, 0);
12024 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12025 }
12026
12027 DEFUN (bgp_redistribute_ipv6_rmap,
12028 bgp_redistribute_ipv6_rmap_cmd,
12029 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12030 "Redistribute information from another routing protocol\n"
12031 FRR_IP6_REDIST_HELP_STR_BGPD
12032 "Route map reference\n"
12033 "Pointer to route-map entries\n")
12034 {
12035 VTY_DECLVAR_CONTEXT(bgp, bgp);
12036 int idx_protocol = 1;
12037 int idx_word = 3;
12038 int type;
12039 struct bgp_redist *red;
12040 bool changed;
12041
12042 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12043 if (type < 0) {
12044 vty_out(vty, "%% Invalid route type\n");
12045 return CMD_WARNING_CONFIG_FAILED;
12046 }
12047
12048 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12049 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12050 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12051 }
12052
12053 DEFUN (bgp_redistribute_ipv6_metric,
12054 bgp_redistribute_ipv6_metric_cmd,
12055 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12056 "Redistribute information from another routing protocol\n"
12057 FRR_IP6_REDIST_HELP_STR_BGPD
12058 "Metric for redistributed routes\n"
12059 "Default metric\n")
12060 {
12061 VTY_DECLVAR_CONTEXT(bgp, bgp);
12062 int idx_protocol = 1;
12063 int idx_number = 3;
12064 int type;
12065 uint32_t metric;
12066 struct bgp_redist *red;
12067 bool changed;
12068
12069 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12070 if (type < 0) {
12071 vty_out(vty, "%% Invalid route type\n");
12072 return CMD_WARNING_CONFIG_FAILED;
12073 }
12074 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12075
12076 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12077 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12078 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12079 }
12080
12081 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12082 bgp_redistribute_ipv6_rmap_metric_cmd,
12083 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12084 "Redistribute information from another routing protocol\n"
12085 FRR_IP6_REDIST_HELP_STR_BGPD
12086 "Route map reference\n"
12087 "Pointer to route-map entries\n"
12088 "Metric for redistributed routes\n"
12089 "Default metric\n")
12090 {
12091 VTY_DECLVAR_CONTEXT(bgp, bgp);
12092 int idx_protocol = 1;
12093 int idx_word = 3;
12094 int idx_number = 5;
12095 int type;
12096 uint32_t metric;
12097 struct bgp_redist *red;
12098 bool changed;
12099
12100 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12101 if (type < 0) {
12102 vty_out(vty, "%% Invalid route type\n");
12103 return CMD_WARNING_CONFIG_FAILED;
12104 }
12105 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12106
12107 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12108 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12109 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12110 metric);
12111 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12112 }
12113
12114 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12115 bgp_redistribute_ipv6_metric_rmap_cmd,
12116 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12117 "Redistribute information from another routing protocol\n"
12118 FRR_IP6_REDIST_HELP_STR_BGPD
12119 "Metric for redistributed routes\n"
12120 "Default metric\n"
12121 "Route map reference\n"
12122 "Pointer to route-map entries\n")
12123 {
12124 VTY_DECLVAR_CONTEXT(bgp, bgp);
12125 int idx_protocol = 1;
12126 int idx_number = 3;
12127 int idx_word = 5;
12128 int type;
12129 uint32_t metric;
12130 struct bgp_redist *red;
12131 bool changed;
12132
12133 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12134 if (type < 0) {
12135 vty_out(vty, "%% Invalid route type\n");
12136 return CMD_WARNING_CONFIG_FAILED;
12137 }
12138 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12139
12140 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12141 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12142 metric);
12143 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12144 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12145 }
12146
12147 DEFUN (no_bgp_redistribute_ipv6,
12148 no_bgp_redistribute_ipv6_cmd,
12149 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12150 NO_STR
12151 "Redistribute information from another routing protocol\n"
12152 FRR_IP6_REDIST_HELP_STR_BGPD
12153 "Metric for redistributed routes\n"
12154 "Default metric\n"
12155 "Route map reference\n"
12156 "Pointer to route-map entries\n")
12157 {
12158 VTY_DECLVAR_CONTEXT(bgp, bgp);
12159 int idx_protocol = 2;
12160 int type;
12161
12162 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12163 if (type < 0) {
12164 vty_out(vty, "%% Invalid route type\n");
12165 return CMD_WARNING_CONFIG_FAILED;
12166 }
12167
12168 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12169 }
12170
12171 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12172 safi_t safi)
12173 {
12174 int i;
12175
12176 /* Unicast redistribution only. */
12177 if (safi != SAFI_UNICAST)
12178 return;
12179
12180 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12181 /* Redistribute BGP does not make sense. */
12182 if (i != ZEBRA_ROUTE_BGP) {
12183 struct list *red_list;
12184 struct listnode *node;
12185 struct bgp_redist *red;
12186
12187 red_list = bgp->redist[afi][i];
12188 if (!red_list)
12189 continue;
12190
12191 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12192 /* "redistribute" configuration. */
12193 vty_out(vty, " redistribute %s",
12194 zebra_route_string(i));
12195 if (red->instance)
12196 vty_out(vty, " %d", red->instance);
12197 if (red->redist_metric_flag)
12198 vty_out(vty, " metric %u",
12199 red->redist_metric);
12200 if (red->rmap.name)
12201 vty_out(vty, " route-map %s",
12202 red->rmap.name);
12203 vty_out(vty, "\n");
12204 }
12205 }
12206 }
12207 }
12208
12209 /* This is part of the address-family block (unicast only) */
12210 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12211 afi_t afi)
12212 {
12213 int indent = 2;
12214
12215 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12216 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12217 bgp->vpn_policy[afi]
12218 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12219
12220 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12221 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12222 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12223 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12224 return;
12225
12226 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12227 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12228
12229 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12230
12231 } else {
12232 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12233 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12234 bgp->vpn_policy[afi].tovpn_label);
12235 }
12236 }
12237 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12238 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12239 char buf[RD_ADDRSTRLEN];
12240 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12241 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12242 sizeof(buf)));
12243 }
12244 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12245 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12246
12247 char buf[PREFIX_STRLEN];
12248 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12249 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12250 sizeof(buf))) {
12251
12252 vty_out(vty, "%*snexthop vpn export %s\n",
12253 indent, "", buf);
12254 }
12255 }
12256 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12257 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12258 && ecommunity_cmp(
12259 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12260 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12261
12262 char *b = ecommunity_ecom2str(
12263 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12264 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12265 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12266 XFREE(MTYPE_ECOMMUNITY_STR, b);
12267 } else {
12268 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12269 char *b = ecommunity_ecom2str(
12270 bgp->vpn_policy[afi]
12271 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12272 ECOMMUNITY_FORMAT_ROUTE_MAP,
12273 ECOMMUNITY_ROUTE_TARGET);
12274 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12275 XFREE(MTYPE_ECOMMUNITY_STR, b);
12276 }
12277 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12278 char *b = ecommunity_ecom2str(
12279 bgp->vpn_policy[afi]
12280 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12281 ECOMMUNITY_FORMAT_ROUTE_MAP,
12282 ECOMMUNITY_ROUTE_TARGET);
12283 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12284 XFREE(MTYPE_ECOMMUNITY_STR, b);
12285 }
12286 }
12287
12288 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12289 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12290 bgp->vpn_policy[afi]
12291 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12292
12293 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12294 char *b = ecommunity_ecom2str(
12295 bgp->vpn_policy[afi]
12296 .import_redirect_rtlist,
12297 ECOMMUNITY_FORMAT_ROUTE_MAP,
12298 ECOMMUNITY_ROUTE_TARGET);
12299
12300 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12301 XFREE(MTYPE_ECOMMUNITY_STR, b);
12302 }
12303 }
12304
12305
12306 /* BGP node structure. */
12307 static struct cmd_node bgp_node = {
12308 BGP_NODE, "%s(config-router)# ", 1,
12309 };
12310
12311 static struct cmd_node bgp_ipv4_unicast_node = {
12312 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12313 };
12314
12315 static struct cmd_node bgp_ipv4_multicast_node = {
12316 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12317 };
12318
12319 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12320 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12321 };
12322
12323 static struct cmd_node bgp_ipv6_unicast_node = {
12324 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12325 };
12326
12327 static struct cmd_node bgp_ipv6_multicast_node = {
12328 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12329 };
12330
12331 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12332 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12333 };
12334
12335 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12336 "%s(config-router-af)# ", 1};
12337
12338 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12339 "%s(config-router-af-vpnv6)# ", 1};
12340
12341 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12342 "%s(config-router-evpn)# ", 1};
12343
12344 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12345 "%s(config-router-af-vni)# ", 1};
12346
12347 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12348 "%s(config-router-af)# ", 1};
12349
12350 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12351 "%s(config-router-af-vpnv6)# ", 1};
12352
12353 static void community_list_vty(void);
12354
12355 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12356 {
12357 struct bgp *bgp;
12358 struct peer *peer;
12359 struct listnode *lnbgp, *lnpeer;
12360
12361 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12362 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12363 /* only provide suggestions on the appropriate input
12364 * token type,
12365 * they'll otherwise show up multiple times */
12366 enum cmd_token_type match_type;
12367 char *name = peer->host;
12368
12369 if (peer->conf_if) {
12370 match_type = VARIABLE_TKN;
12371 name = peer->conf_if;
12372 } else if (strchr(peer->host, ':'))
12373 match_type = IPV6_TKN;
12374 else
12375 match_type = IPV4_TKN;
12376
12377 if (token->type != match_type)
12378 continue;
12379
12380 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12381 }
12382 }
12383 }
12384
12385 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12386 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12387 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12388 {.varname = "peer", .completions = bgp_ac_neighbor},
12389 {.completions = NULL}};
12390
12391 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12392 {
12393 struct bgp *bgp;
12394 struct peer_group *group;
12395 struct listnode *lnbgp, *lnpeer;
12396
12397 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12398 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12399 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12400 group->name));
12401 }
12402 }
12403
12404 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12405 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12406 {.completions = NULL} };
12407
12408 void bgp_vty_init(void)
12409 {
12410 cmd_variable_handler_register(bgp_var_neighbor);
12411 cmd_variable_handler_register(bgp_var_peergroup);
12412
12413 /* Install bgp top node. */
12414 install_node(&bgp_node, bgp_config_write);
12415 install_node(&bgp_ipv4_unicast_node, NULL);
12416 install_node(&bgp_ipv4_multicast_node, NULL);
12417 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12418 install_node(&bgp_ipv6_unicast_node, NULL);
12419 install_node(&bgp_ipv6_multicast_node, NULL);
12420 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12421 install_node(&bgp_vpnv4_node, NULL);
12422 install_node(&bgp_vpnv6_node, NULL);
12423 install_node(&bgp_evpn_node, NULL);
12424 install_node(&bgp_evpn_vni_node, NULL);
12425 install_node(&bgp_flowspecv4_node, NULL);
12426 install_node(&bgp_flowspecv6_node, NULL);
12427
12428 /* Install default VTY commands to new nodes. */
12429 install_default(BGP_NODE);
12430 install_default(BGP_IPV4_NODE);
12431 install_default(BGP_IPV4M_NODE);
12432 install_default(BGP_IPV4L_NODE);
12433 install_default(BGP_IPV6_NODE);
12434 install_default(BGP_IPV6M_NODE);
12435 install_default(BGP_IPV6L_NODE);
12436 install_default(BGP_VPNV4_NODE);
12437 install_default(BGP_VPNV6_NODE);
12438 install_default(BGP_FLOWSPECV4_NODE);
12439 install_default(BGP_FLOWSPECV6_NODE);
12440 install_default(BGP_EVPN_NODE);
12441 install_default(BGP_EVPN_VNI_NODE);
12442
12443 /* "bgp multiple-instance" commands. */
12444 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12445 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12446
12447 /* "bgp config-type" commands. */
12448 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12449 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12450
12451 /* bgp route-map delay-timer commands. */
12452 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12453 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12454
12455 /* Dummy commands (Currently not supported) */
12456 install_element(BGP_NODE, &no_synchronization_cmd);
12457 install_element(BGP_NODE, &no_auto_summary_cmd);
12458
12459 /* "router bgp" commands. */
12460 install_element(CONFIG_NODE, &router_bgp_cmd);
12461
12462 /* "no router bgp" commands. */
12463 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12464
12465 /* "bgp router-id" commands. */
12466 install_element(BGP_NODE, &bgp_router_id_cmd);
12467 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12468
12469 /* "bgp cluster-id" commands. */
12470 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12471 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12472
12473 /* "bgp confederation" commands. */
12474 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12475 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12476
12477 /* "bgp confederation peers" commands. */
12478 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12479 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12480
12481 /* bgp max-med command */
12482 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12483 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12484 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12485 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12486 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12487
12488 /* bgp disable-ebgp-connected-nh-check */
12489 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12490 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12491
12492 /* bgp update-delay command */
12493 install_element(BGP_NODE, &bgp_update_delay_cmd);
12494 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12495 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12496
12497 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12498 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12499 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12500 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12501
12502 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12503 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12504
12505 /* "maximum-paths" commands. */
12506 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12507 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12508 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12509 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12510 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12511 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12512 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12513 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12514 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12515 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12516 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12517 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12518 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12519 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12520 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12521
12522 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12523 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12524 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12525 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12526 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12527
12528 /* "timers bgp" commands. */
12529 install_element(BGP_NODE, &bgp_timers_cmd);
12530 install_element(BGP_NODE, &no_bgp_timers_cmd);
12531
12532 /* route-map delay-timer commands - per instance for backwards compat.
12533 */
12534 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12535 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12536
12537 /* "bgp client-to-client reflection" commands */
12538 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12539 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12540
12541 /* "bgp always-compare-med" commands */
12542 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12543 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12544
12545 /* "bgp deterministic-med" commands */
12546 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12547 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12548
12549 /* "bgp graceful-restart" commands */
12550 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12551 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12552 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12553 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12554 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12555 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12556
12557 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12558 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12559
12560 /* "bgp graceful-shutdown" commands */
12561 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12562 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12563
12564 /* "bgp fast-external-failover" commands */
12565 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12566 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12567
12568 /* "bgp enforce-first-as" commands */
12569 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12570
12571 /* "bgp bestpath compare-routerid" commands */
12572 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12573 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12574
12575 /* "bgp bestpath as-path ignore" commands */
12576 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12577 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12578
12579 /* "bgp bestpath as-path confed" commands */
12580 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12581 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12582
12583 /* "bgp bestpath as-path multipath-relax" commands */
12584 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12585 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12586
12587 /* "bgp log-neighbor-changes" commands */
12588 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12589 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12590
12591 /* "bgp bestpath med" commands */
12592 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12593 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12594
12595 /* "no bgp default ipv4-unicast" commands. */
12596 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12597 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12598
12599 /* "bgp network import-check" commands. */
12600 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12601 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12602 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12603
12604 /* "bgp default local-preference" commands. */
12605 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12606 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12607
12608 /* bgp default show-hostname */
12609 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12610 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12611
12612 /* "bgp default subgroup-pkt-queue-max" commands. */
12613 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12614 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12615
12616 /* bgp ibgp-allow-policy-mods command */
12617 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12618 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12619
12620 /* "bgp listen limit" commands. */
12621 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12622 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12623
12624 /* "bgp listen range" commands. */
12625 install_element(BGP_NODE, &bgp_listen_range_cmd);
12626 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12627
12628 /* "bgp default shutdown" command */
12629 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12630
12631 /* "neighbor remote-as" commands. */
12632 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12633 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12634 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12635 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12636 install_element(BGP_NODE,
12637 &neighbor_interface_v6only_config_remote_as_cmd);
12638 install_element(BGP_NODE, &no_neighbor_cmd);
12639 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12640
12641 /* "neighbor peer-group" commands. */
12642 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12643 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12644 install_element(BGP_NODE,
12645 &no_neighbor_interface_peer_group_remote_as_cmd);
12646
12647 /* "neighbor local-as" commands. */
12648 install_element(BGP_NODE, &neighbor_local_as_cmd);
12649 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12650 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12651 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12652
12653 /* "neighbor solo" commands. */
12654 install_element(BGP_NODE, &neighbor_solo_cmd);
12655 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12656
12657 /* "neighbor password" commands. */
12658 install_element(BGP_NODE, &neighbor_password_cmd);
12659 install_element(BGP_NODE, &no_neighbor_password_cmd);
12660
12661 /* "neighbor activate" commands. */
12662 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12663 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12664 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12665 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12666 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12667 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12668 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12669 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12670 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12671 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12672 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12673 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12674
12675 /* "no neighbor activate" commands. */
12676 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12677 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12678 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12679 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12680 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12681 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12682 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12683 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12684 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12685 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12686 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12687 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12688
12689 /* "neighbor peer-group" set commands. */
12690 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12691 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12692 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12693 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12694 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12695 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12696 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12697 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12698 install_element(BGP_FLOWSPECV4_NODE,
12699 &neighbor_set_peer_group_hidden_cmd);
12700 install_element(BGP_FLOWSPECV6_NODE,
12701 &neighbor_set_peer_group_hidden_cmd);
12702
12703 /* "no neighbor peer-group unset" commands. */
12704 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12705 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12706 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12707 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12708 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12709 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12710 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12711 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12712 install_element(BGP_FLOWSPECV4_NODE,
12713 &no_neighbor_set_peer_group_hidden_cmd);
12714 install_element(BGP_FLOWSPECV6_NODE,
12715 &no_neighbor_set_peer_group_hidden_cmd);
12716
12717 /* "neighbor softreconfiguration inbound" commands.*/
12718 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12719 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12720 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12721 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12722 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12723 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12724 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12725 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12726 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12727 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12728 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12729 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12730 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12731 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12732 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12733 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12734 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12735 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12736 install_element(BGP_FLOWSPECV4_NODE,
12737 &neighbor_soft_reconfiguration_cmd);
12738 install_element(BGP_FLOWSPECV4_NODE,
12739 &no_neighbor_soft_reconfiguration_cmd);
12740 install_element(BGP_FLOWSPECV6_NODE,
12741 &neighbor_soft_reconfiguration_cmd);
12742 install_element(BGP_FLOWSPECV6_NODE,
12743 &no_neighbor_soft_reconfiguration_cmd);
12744
12745 /* "neighbor attribute-unchanged" commands. */
12746 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12747 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12748 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12749 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12750 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12751 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12752 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12753 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12754 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12755 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12756 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12757 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12758 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12759 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12760 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12761 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12762 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12763 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12764
12765 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12766 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12767
12768 /* "nexthop-local unchanged" commands */
12769 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12770 install_element(BGP_IPV6_NODE,
12771 &no_neighbor_nexthop_local_unchanged_cmd);
12772
12773 /* "neighbor next-hop-self" commands. */
12774 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12775 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12776 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12777 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12778 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12779 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12780 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12781 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12782 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12783 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12784 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12785 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12786 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12787 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12788 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12789 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12790 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12791 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12792 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12793 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12794
12795 /* "neighbor next-hop-self force" commands. */
12796 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12797 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12798 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12799 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12800 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12801 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12802 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12803 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12804 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12805 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12806 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12807 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12808 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12809 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12810 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12811 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12812 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12813 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12814
12815 /* "neighbor as-override" commands. */
12816 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12817 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12818 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12819 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12820 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12821 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12822 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12823 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12824 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12825 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12826 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12827 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12828 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12829 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12830 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12831 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12832 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12833 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12834
12835 /* "neighbor remove-private-AS" commands. */
12836 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12837 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12838 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12839 install_element(BGP_NODE,
12840 &no_neighbor_remove_private_as_all_hidden_cmd);
12841 install_element(BGP_NODE,
12842 &neighbor_remove_private_as_replace_as_hidden_cmd);
12843 install_element(BGP_NODE,
12844 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12845 install_element(BGP_NODE,
12846 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12847 install_element(
12848 BGP_NODE,
12849 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12850 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12851 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12852 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12853 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12854 install_element(BGP_IPV4_NODE,
12855 &neighbor_remove_private_as_replace_as_cmd);
12856 install_element(BGP_IPV4_NODE,
12857 &no_neighbor_remove_private_as_replace_as_cmd);
12858 install_element(BGP_IPV4_NODE,
12859 &neighbor_remove_private_as_all_replace_as_cmd);
12860 install_element(BGP_IPV4_NODE,
12861 &no_neighbor_remove_private_as_all_replace_as_cmd);
12862 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12863 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12864 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12865 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12866 install_element(BGP_IPV4M_NODE,
12867 &neighbor_remove_private_as_replace_as_cmd);
12868 install_element(BGP_IPV4M_NODE,
12869 &no_neighbor_remove_private_as_replace_as_cmd);
12870 install_element(BGP_IPV4M_NODE,
12871 &neighbor_remove_private_as_all_replace_as_cmd);
12872 install_element(BGP_IPV4M_NODE,
12873 &no_neighbor_remove_private_as_all_replace_as_cmd);
12874 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12875 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12876 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12877 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12878 install_element(BGP_IPV4L_NODE,
12879 &neighbor_remove_private_as_replace_as_cmd);
12880 install_element(BGP_IPV4L_NODE,
12881 &no_neighbor_remove_private_as_replace_as_cmd);
12882 install_element(BGP_IPV4L_NODE,
12883 &neighbor_remove_private_as_all_replace_as_cmd);
12884 install_element(BGP_IPV4L_NODE,
12885 &no_neighbor_remove_private_as_all_replace_as_cmd);
12886 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12887 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12888 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12889 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12890 install_element(BGP_IPV6_NODE,
12891 &neighbor_remove_private_as_replace_as_cmd);
12892 install_element(BGP_IPV6_NODE,
12893 &no_neighbor_remove_private_as_replace_as_cmd);
12894 install_element(BGP_IPV6_NODE,
12895 &neighbor_remove_private_as_all_replace_as_cmd);
12896 install_element(BGP_IPV6_NODE,
12897 &no_neighbor_remove_private_as_all_replace_as_cmd);
12898 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12899 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12900 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12901 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12902 install_element(BGP_IPV6M_NODE,
12903 &neighbor_remove_private_as_replace_as_cmd);
12904 install_element(BGP_IPV6M_NODE,
12905 &no_neighbor_remove_private_as_replace_as_cmd);
12906 install_element(BGP_IPV6M_NODE,
12907 &neighbor_remove_private_as_all_replace_as_cmd);
12908 install_element(BGP_IPV6M_NODE,
12909 &no_neighbor_remove_private_as_all_replace_as_cmd);
12910 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12911 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12912 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12913 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12914 install_element(BGP_IPV6L_NODE,
12915 &neighbor_remove_private_as_replace_as_cmd);
12916 install_element(BGP_IPV6L_NODE,
12917 &no_neighbor_remove_private_as_replace_as_cmd);
12918 install_element(BGP_IPV6L_NODE,
12919 &neighbor_remove_private_as_all_replace_as_cmd);
12920 install_element(BGP_IPV6L_NODE,
12921 &no_neighbor_remove_private_as_all_replace_as_cmd);
12922 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12923 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12924 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12925 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12926 install_element(BGP_VPNV4_NODE,
12927 &neighbor_remove_private_as_replace_as_cmd);
12928 install_element(BGP_VPNV4_NODE,
12929 &no_neighbor_remove_private_as_replace_as_cmd);
12930 install_element(BGP_VPNV4_NODE,
12931 &neighbor_remove_private_as_all_replace_as_cmd);
12932 install_element(BGP_VPNV4_NODE,
12933 &no_neighbor_remove_private_as_all_replace_as_cmd);
12934 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12935 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12936 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12937 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12938 install_element(BGP_VPNV6_NODE,
12939 &neighbor_remove_private_as_replace_as_cmd);
12940 install_element(BGP_VPNV6_NODE,
12941 &no_neighbor_remove_private_as_replace_as_cmd);
12942 install_element(BGP_VPNV6_NODE,
12943 &neighbor_remove_private_as_all_replace_as_cmd);
12944 install_element(BGP_VPNV6_NODE,
12945 &no_neighbor_remove_private_as_all_replace_as_cmd);
12946
12947 /* "neighbor send-community" commands.*/
12948 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12949 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12950 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12951 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12952 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12953 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12954 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12955 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12956 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12957 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12958 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12959 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12960 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12961 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12962 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12963 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12964 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12965 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12966 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12967 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12968 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12969 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12970 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12971 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12972 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12973 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12974 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12975 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12976 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12977 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12978 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12979 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12980 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12981 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12982 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12983 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12984
12985 /* "neighbor route-reflector" commands.*/
12986 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12987 install_element(BGP_NODE,
12988 &no_neighbor_route_reflector_client_hidden_cmd);
12989 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12990 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12991 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12992 install_element(BGP_IPV4M_NODE,
12993 &no_neighbor_route_reflector_client_cmd);
12994 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12995 install_element(BGP_IPV4L_NODE,
12996 &no_neighbor_route_reflector_client_cmd);
12997 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12998 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12999 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13000 install_element(BGP_IPV6M_NODE,
13001 &no_neighbor_route_reflector_client_cmd);
13002 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13003 install_element(BGP_IPV6L_NODE,
13004 &no_neighbor_route_reflector_client_cmd);
13005 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13006 install_element(BGP_VPNV4_NODE,
13007 &no_neighbor_route_reflector_client_cmd);
13008 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13009 install_element(BGP_VPNV6_NODE,
13010 &no_neighbor_route_reflector_client_cmd);
13011 install_element(BGP_FLOWSPECV4_NODE,
13012 &neighbor_route_reflector_client_cmd);
13013 install_element(BGP_FLOWSPECV4_NODE,
13014 &no_neighbor_route_reflector_client_cmd);
13015 install_element(BGP_FLOWSPECV6_NODE,
13016 &neighbor_route_reflector_client_cmd);
13017 install_element(BGP_FLOWSPECV6_NODE,
13018 &no_neighbor_route_reflector_client_cmd);
13019 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13020 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13021
13022 /* "neighbor route-server" commands.*/
13023 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13024 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13025 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13026 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13027 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13028 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13029 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13030 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13031 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13032 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13033 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13034 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13035 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13036 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13037 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13038 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13039 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13040 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13041 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13042 install_element(BGP_FLOWSPECV4_NODE,
13043 &no_neighbor_route_server_client_cmd);
13044 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13045 install_element(BGP_FLOWSPECV6_NODE,
13046 &no_neighbor_route_server_client_cmd);
13047
13048 /* "neighbor addpath-tx-all-paths" commands.*/
13049 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13050 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13051 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13052 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13053 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13054 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13055 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13056 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13057 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13058 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13059 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13060 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13061 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13062 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13063 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13064 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13065 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13066 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13067
13068 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13069 install_element(BGP_NODE,
13070 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13071 install_element(BGP_NODE,
13072 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13073 install_element(BGP_IPV4_NODE,
13074 &neighbor_addpath_tx_bestpath_per_as_cmd);
13075 install_element(BGP_IPV4_NODE,
13076 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13077 install_element(BGP_IPV4M_NODE,
13078 &neighbor_addpath_tx_bestpath_per_as_cmd);
13079 install_element(BGP_IPV4M_NODE,
13080 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13081 install_element(BGP_IPV4L_NODE,
13082 &neighbor_addpath_tx_bestpath_per_as_cmd);
13083 install_element(BGP_IPV4L_NODE,
13084 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13085 install_element(BGP_IPV6_NODE,
13086 &neighbor_addpath_tx_bestpath_per_as_cmd);
13087 install_element(BGP_IPV6_NODE,
13088 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13089 install_element(BGP_IPV6M_NODE,
13090 &neighbor_addpath_tx_bestpath_per_as_cmd);
13091 install_element(BGP_IPV6M_NODE,
13092 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13093 install_element(BGP_IPV6L_NODE,
13094 &neighbor_addpath_tx_bestpath_per_as_cmd);
13095 install_element(BGP_IPV6L_NODE,
13096 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13097 install_element(BGP_VPNV4_NODE,
13098 &neighbor_addpath_tx_bestpath_per_as_cmd);
13099 install_element(BGP_VPNV4_NODE,
13100 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13101 install_element(BGP_VPNV6_NODE,
13102 &neighbor_addpath_tx_bestpath_per_as_cmd);
13103 install_element(BGP_VPNV6_NODE,
13104 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13105
13106 /* "neighbor passive" commands. */
13107 install_element(BGP_NODE, &neighbor_passive_cmd);
13108 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13109
13110
13111 /* "neighbor shutdown" commands. */
13112 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13113 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13114 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13115 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13116
13117 /* "neighbor capability extended-nexthop" commands.*/
13118 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13119 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13120
13121 /* "neighbor capability orf prefix-list" commands.*/
13122 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13123 install_element(BGP_NODE,
13124 &no_neighbor_capability_orf_prefix_hidden_cmd);
13125 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13126 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13127 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13128 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13129 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13130 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13131 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13132 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13133 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13134 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13135 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13136 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13137
13138 /* "neighbor capability dynamic" commands.*/
13139 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13140 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13141
13142 /* "neighbor dont-capability-negotiate" commands. */
13143 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13144 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13145
13146 /* "neighbor ebgp-multihop" commands. */
13147 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13148 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13149 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13150
13151 /* "neighbor disable-connected-check" commands. */
13152 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13153 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13154
13155 /* "neighbor enforce-first-as" commands. */
13156 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13157 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13158
13159 /* "neighbor description" commands. */
13160 install_element(BGP_NODE, &neighbor_description_cmd);
13161 install_element(BGP_NODE, &no_neighbor_description_cmd);
13162 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13163
13164 /* "neighbor update-source" commands. "*/
13165 install_element(BGP_NODE, &neighbor_update_source_cmd);
13166 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13167
13168 /* "neighbor default-originate" commands. */
13169 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13170 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13171 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13172 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13173 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13174 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13175 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13176 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13177 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13178 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13179 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13180 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13181 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13182 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13183 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13184 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13185 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13186 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13187 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13188 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13189 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13190
13191 /* "neighbor port" commands. */
13192 install_element(BGP_NODE, &neighbor_port_cmd);
13193 install_element(BGP_NODE, &no_neighbor_port_cmd);
13194
13195 /* "neighbor weight" commands. */
13196 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13197 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13198
13199 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13200 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13201 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13202 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13203 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13204 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13205 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13206 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13207 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13208 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13209 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13210 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13211 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13212 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13213 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13214 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13215
13216 /* "neighbor override-capability" commands. */
13217 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13218 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13219
13220 /* "neighbor strict-capability-match" commands. */
13221 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13222 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13223
13224 /* "neighbor timers" commands. */
13225 install_element(BGP_NODE, &neighbor_timers_cmd);
13226 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13227
13228 /* "neighbor timers connect" commands. */
13229 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13230 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13231
13232 /* "neighbor advertisement-interval" commands. */
13233 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13234 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13235
13236 /* "neighbor interface" commands. */
13237 install_element(BGP_NODE, &neighbor_interface_cmd);
13238 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13239
13240 /* "neighbor distribute" commands. */
13241 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13242 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13243 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13244 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13245 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13246 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13247 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13248 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13249 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13250 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13251 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13252 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13253 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13254 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13255 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13256 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13257 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13258 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13259
13260 /* "neighbor prefix-list" commands. */
13261 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13262 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13263 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13264 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13265 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13266 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13267 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13268 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13269 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13270 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13271 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13272 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13273 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13274 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13275 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13276 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13277 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13278 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13279 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13280 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13281 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13282 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13283
13284 /* "neighbor filter-list" commands. */
13285 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13286 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13287 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13288 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13289 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13290 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13291 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13292 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13293 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13294 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13295 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13296 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13297 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13298 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13299 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13300 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13301 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13302 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13303 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13304 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13305 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13306 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13307
13308 /* "neighbor route-map" commands. */
13309 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13310 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13311 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13312 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13313 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13314 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13315 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13316 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13317 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13318 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13319 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13320 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13321 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13322 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13323 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13324 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13325 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13326 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13327 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13328 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13329 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13330 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13331 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13332 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13333
13334 /* "neighbor unsuppress-map" commands. */
13335 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13336 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13337 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13338 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13339 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13340 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13341 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13342 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13343 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13344 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13345 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13346 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13347 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13348 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13349 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13350 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13351 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13352 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13353
13354 /* "neighbor maximum-prefix" commands. */
13355 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13356 install_element(BGP_NODE,
13357 &neighbor_maximum_prefix_threshold_hidden_cmd);
13358 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13359 install_element(BGP_NODE,
13360 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13361 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13362 install_element(BGP_NODE,
13363 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13364 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13365 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13366 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13367 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13368 install_element(BGP_IPV4_NODE,
13369 &neighbor_maximum_prefix_threshold_warning_cmd);
13370 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13371 install_element(BGP_IPV4_NODE,
13372 &neighbor_maximum_prefix_threshold_restart_cmd);
13373 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13374 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13375 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13376 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13377 install_element(BGP_IPV4M_NODE,
13378 &neighbor_maximum_prefix_threshold_warning_cmd);
13379 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13380 install_element(BGP_IPV4M_NODE,
13381 &neighbor_maximum_prefix_threshold_restart_cmd);
13382 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13383 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13384 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13385 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13386 install_element(BGP_IPV4L_NODE,
13387 &neighbor_maximum_prefix_threshold_warning_cmd);
13388 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13389 install_element(BGP_IPV4L_NODE,
13390 &neighbor_maximum_prefix_threshold_restart_cmd);
13391 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13392 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13393 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13394 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13395 install_element(BGP_IPV6_NODE,
13396 &neighbor_maximum_prefix_threshold_warning_cmd);
13397 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13398 install_element(BGP_IPV6_NODE,
13399 &neighbor_maximum_prefix_threshold_restart_cmd);
13400 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13401 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13402 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13403 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13404 install_element(BGP_IPV6M_NODE,
13405 &neighbor_maximum_prefix_threshold_warning_cmd);
13406 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13407 install_element(BGP_IPV6M_NODE,
13408 &neighbor_maximum_prefix_threshold_restart_cmd);
13409 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13410 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13411 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13412 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13413 install_element(BGP_IPV6L_NODE,
13414 &neighbor_maximum_prefix_threshold_warning_cmd);
13415 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13416 install_element(BGP_IPV6L_NODE,
13417 &neighbor_maximum_prefix_threshold_restart_cmd);
13418 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13419 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13420 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13421 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13422 install_element(BGP_VPNV4_NODE,
13423 &neighbor_maximum_prefix_threshold_warning_cmd);
13424 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13425 install_element(BGP_VPNV4_NODE,
13426 &neighbor_maximum_prefix_threshold_restart_cmd);
13427 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13428 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13429 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13430 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13431 install_element(BGP_VPNV6_NODE,
13432 &neighbor_maximum_prefix_threshold_warning_cmd);
13433 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13434 install_element(BGP_VPNV6_NODE,
13435 &neighbor_maximum_prefix_threshold_restart_cmd);
13436 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13437
13438 /* "neighbor allowas-in" */
13439 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13440 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13441 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13442 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13443 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13444 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13445 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13446 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13447 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13448 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13449 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13450 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13451 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13452 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13453 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13454 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13455 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13456 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13457 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13458 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13459
13460 /* address-family commands. */
13461 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13462 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13463 #ifdef KEEP_OLD_VPN_COMMANDS
13464 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13465 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13466 #endif /* KEEP_OLD_VPN_COMMANDS */
13467
13468 install_element(BGP_NODE, &address_family_evpn_cmd);
13469
13470 /* "exit-address-family" command. */
13471 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13472 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13473 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13474 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13475 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13476 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13477 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13478 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13479 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13480 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13481 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13482
13483 /* "clear ip bgp commands" */
13484 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13485
13486 /* clear ip bgp prefix */
13487 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13488 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13489 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13490
13491 /* "show [ip] bgp summary" commands. */
13492 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13493 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13494 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13495 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13496 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13497 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13498
13499 /* "show [ip] bgp neighbors" commands. */
13500 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13501
13502 /* "show [ip] bgp peer-group" commands. */
13503 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13504
13505 /* "show [ip] bgp paths" commands. */
13506 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13507
13508 /* "show [ip] bgp community" commands. */
13509 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13510
13511 /* "show ip bgp large-community" commands. */
13512 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13513 /* "show [ip] bgp attribute-info" commands. */
13514 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13515 /* "show [ip] bgp route-leak" command */
13516 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13517
13518 /* "redistribute" commands. */
13519 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13520 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13521 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13522 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13523 install_element(BGP_NODE,
13524 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13525 install_element(BGP_NODE,
13526 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13527 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13528 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13529 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13530 install_element(BGP_NODE,
13531 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13532 install_element(BGP_NODE,
13533 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13534 install_element(BGP_NODE,
13535 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13536 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13537 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13538 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13539 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13540 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13541 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13542 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13543 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13544 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13545 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13546 install_element(BGP_IPV4_NODE,
13547 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13548 install_element(BGP_IPV4_NODE,
13549 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13550 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13551 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13552 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13553 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13554 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13555 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13556
13557 /* import|export vpn [route-map WORD] */
13558 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13559 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13560
13561 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13562 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13563
13564 /* ttl_security commands */
13565 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13566 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13567
13568 /* "show [ip] bgp memory" commands. */
13569 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13570
13571 /* "show bgp martian next-hop" */
13572 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13573
13574 /* "show [ip] bgp views" commands. */
13575 install_element(VIEW_NODE, &show_bgp_views_cmd);
13576
13577 /* "show [ip] bgp vrfs" commands. */
13578 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13579
13580 /* Community-list. */
13581 community_list_vty();
13582
13583 /* vpn-policy commands */
13584 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13585 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13586 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13587 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13588 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13589 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13590 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13591 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13592 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13593 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13594 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13595 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13596
13597 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13598 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13599
13600 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13601 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13602 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13603 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13604 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13605 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13606 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13607 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13608 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13609 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13610 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13611 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13612 }
13613
13614 #include "memory.h"
13615 #include "bgp_regex.h"
13616 #include "bgp_clist.h"
13617 #include "bgp_ecommunity.h"
13618
13619 /* VTY functions. */
13620
13621 /* Direction value to string conversion. */
13622 static const char *community_direct_str(int direct)
13623 {
13624 switch (direct) {
13625 case COMMUNITY_DENY:
13626 return "deny";
13627 case COMMUNITY_PERMIT:
13628 return "permit";
13629 default:
13630 return "unknown";
13631 }
13632 }
13633
13634 /* Display error string. */
13635 static void community_list_perror(struct vty *vty, int ret)
13636 {
13637 switch (ret) {
13638 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13639 vty_out(vty, "%% Can't find community-list\n");
13640 break;
13641 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13642 vty_out(vty, "%% Malformed community-list value\n");
13643 break;
13644 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13645 vty_out(vty,
13646 "%% Community name conflict, previously defined as standard community\n");
13647 break;
13648 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13649 vty_out(vty,
13650 "%% Community name conflict, previously defined as expanded community\n");
13651 break;
13652 }
13653 }
13654
13655 /* "community-list" keyword help string. */
13656 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13657
13658 /* ip community-list standard */
13659 DEFUN (ip_community_list_standard,
13660 ip_community_list_standard_cmd,
13661 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13662 IP_STR
13663 COMMUNITY_LIST_STR
13664 "Community list number (standard)\n"
13665 "Add an standard community-list entry\n"
13666 "Community list name\n"
13667 "Specify community to reject\n"
13668 "Specify community to accept\n"
13669 COMMUNITY_VAL_STR)
13670 {
13671 char *cl_name_or_number = NULL;
13672 int direct = 0;
13673 int style = COMMUNITY_LIST_STANDARD;
13674
13675 int idx = 0;
13676 argv_find(argv, argc, "(1-99)", &idx);
13677 argv_find(argv, argc, "WORD", &idx);
13678 cl_name_or_number = argv[idx]->arg;
13679 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13680 : COMMUNITY_DENY;
13681 argv_find(argv, argc, "AA:NN", &idx);
13682 char *str = argv_concat(argv, argc, idx);
13683
13684 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13685 style);
13686
13687 XFREE(MTYPE_TMP, str);
13688
13689 if (ret < 0) {
13690 /* Display error string. */
13691 community_list_perror(vty, ret);
13692 return CMD_WARNING_CONFIG_FAILED;
13693 }
13694
13695 return CMD_SUCCESS;
13696 }
13697
13698 DEFUN (no_ip_community_list_standard_all,
13699 no_ip_community_list_standard_all_cmd,
13700 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13701 NO_STR
13702 IP_STR
13703 COMMUNITY_LIST_STR
13704 "Community list number (standard)\n"
13705 "Add an standard community-list entry\n"
13706 "Community list name\n"
13707 "Specify community to reject\n"
13708 "Specify community to accept\n"
13709 COMMUNITY_VAL_STR)
13710 {
13711 char *cl_name_or_number = NULL;
13712 int direct = 0;
13713 int style = COMMUNITY_LIST_STANDARD;
13714
13715 int idx = 0;
13716 argv_find(argv, argc, "(1-99)", &idx);
13717 argv_find(argv, argc, "WORD", &idx);
13718 cl_name_or_number = argv[idx]->arg;
13719 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13720 : COMMUNITY_DENY;
13721 argv_find(argv, argc, "AA:NN", &idx);
13722 char *str = argv_concat(argv, argc, idx);
13723
13724 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13725 direct, style);
13726
13727 XFREE(MTYPE_TMP, str);
13728
13729 if (ret < 0) {
13730 community_list_perror(vty, ret);
13731 return CMD_WARNING_CONFIG_FAILED;
13732 }
13733
13734 return CMD_SUCCESS;
13735 }
13736
13737 /* ip community-list expanded */
13738 DEFUN (ip_community_list_expanded_all,
13739 ip_community_list_expanded_all_cmd,
13740 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13741 IP_STR
13742 COMMUNITY_LIST_STR
13743 "Community list number (expanded)\n"
13744 "Add an expanded community-list entry\n"
13745 "Community list name\n"
13746 "Specify community to reject\n"
13747 "Specify community to accept\n"
13748 COMMUNITY_VAL_STR)
13749 {
13750 char *cl_name_or_number = NULL;
13751 int direct = 0;
13752 int style = COMMUNITY_LIST_EXPANDED;
13753
13754 int idx = 0;
13755 argv_find(argv, argc, "(100-500)", &idx);
13756 argv_find(argv, argc, "WORD", &idx);
13757 cl_name_or_number = argv[idx]->arg;
13758 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13759 : COMMUNITY_DENY;
13760 argv_find(argv, argc, "AA:NN", &idx);
13761 char *str = argv_concat(argv, argc, idx);
13762
13763 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13764 style);
13765
13766 XFREE(MTYPE_TMP, str);
13767
13768 if (ret < 0) {
13769 /* Display error string. */
13770 community_list_perror(vty, ret);
13771 return CMD_WARNING_CONFIG_FAILED;
13772 }
13773
13774 return CMD_SUCCESS;
13775 }
13776
13777 DEFUN (no_ip_community_list_expanded_all,
13778 no_ip_community_list_expanded_all_cmd,
13779 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13780 NO_STR
13781 IP_STR
13782 COMMUNITY_LIST_STR
13783 "Community list number (expanded)\n"
13784 "Add an expanded community-list entry\n"
13785 "Community list name\n"
13786 "Specify community to reject\n"
13787 "Specify community to accept\n"
13788 COMMUNITY_VAL_STR)
13789 {
13790 char *cl_name_or_number = NULL;
13791 int direct = 0;
13792 int style = COMMUNITY_LIST_EXPANDED;
13793
13794 int idx = 0;
13795 argv_find(argv, argc, "(100-500)", &idx);
13796 argv_find(argv, argc, "WORD", &idx);
13797 cl_name_or_number = argv[idx]->arg;
13798 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13799 : COMMUNITY_DENY;
13800 argv_find(argv, argc, "AA:NN", &idx);
13801 char *str = argv_concat(argv, argc, idx);
13802
13803 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13804 direct, style);
13805
13806 XFREE(MTYPE_TMP, str);
13807
13808 if (ret < 0) {
13809 community_list_perror(vty, ret);
13810 return CMD_WARNING_CONFIG_FAILED;
13811 }
13812
13813 return CMD_SUCCESS;
13814 }
13815
13816 /* Return configuration string of community-list entry. */
13817 static const char *community_list_config_str(struct community_entry *entry)
13818 {
13819 const char *str;
13820
13821 if (entry->any)
13822 str = "";
13823 else {
13824 if (entry->style == COMMUNITY_LIST_STANDARD)
13825 str = community_str(entry->u.com, false);
13826 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13827 str = lcommunity_str(entry->u.lcom, false);
13828 else
13829 str = entry->config;
13830 }
13831 return str;
13832 }
13833
13834 static void community_list_show(struct vty *vty, struct community_list *list)
13835 {
13836 struct community_entry *entry;
13837
13838 for (entry = list->head; entry; entry = entry->next) {
13839 if (entry == list->head) {
13840 if (all_digit(list->name))
13841 vty_out(vty, "Community %s list %s\n",
13842 entry->style == COMMUNITY_LIST_STANDARD
13843 ? "standard"
13844 : "(expanded) access",
13845 list->name);
13846 else
13847 vty_out(vty, "Named Community %s list %s\n",
13848 entry->style == COMMUNITY_LIST_STANDARD
13849 ? "standard"
13850 : "expanded",
13851 list->name);
13852 }
13853 if (entry->any)
13854 vty_out(vty, " %s\n",
13855 community_direct_str(entry->direct));
13856 else
13857 vty_out(vty, " %s %s\n",
13858 community_direct_str(entry->direct),
13859 community_list_config_str(entry));
13860 }
13861 }
13862
13863 DEFUN (show_ip_community_list,
13864 show_ip_community_list_cmd,
13865 "show ip community-list",
13866 SHOW_STR
13867 IP_STR
13868 "List community-list\n")
13869 {
13870 struct community_list *list;
13871 struct community_list_master *cm;
13872
13873 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13874 if (!cm)
13875 return CMD_SUCCESS;
13876
13877 for (list = cm->num.head; list; list = list->next)
13878 community_list_show(vty, list);
13879
13880 for (list = cm->str.head; list; list = list->next)
13881 community_list_show(vty, list);
13882
13883 return CMD_SUCCESS;
13884 }
13885
13886 DEFUN (show_ip_community_list_arg,
13887 show_ip_community_list_arg_cmd,
13888 "show ip community-list <(1-500)|WORD>",
13889 SHOW_STR
13890 IP_STR
13891 "List community-list\n"
13892 "Community-list number\n"
13893 "Community-list name\n")
13894 {
13895 int idx_comm_list = 3;
13896 struct community_list *list;
13897
13898 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13899 COMMUNITY_LIST_MASTER);
13900 if (!list) {
13901 vty_out(vty, "%% Can't find community-list\n");
13902 return CMD_WARNING;
13903 }
13904
13905 community_list_show(vty, list);
13906
13907 return CMD_SUCCESS;
13908 }
13909
13910 /*
13911 * Large Community code.
13912 */
13913 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13914 struct cmd_token **argv, int style,
13915 int reject_all_digit_name)
13916 {
13917 int ret;
13918 int direct;
13919 char *str;
13920 int idx = 0;
13921 char *cl_name;
13922
13923 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13924 : COMMUNITY_DENY;
13925
13926 /* All digit name check. */
13927 idx = 0;
13928 argv_find(argv, argc, "WORD", &idx);
13929 argv_find(argv, argc, "(1-99)", &idx);
13930 argv_find(argv, argc, "(100-500)", &idx);
13931 cl_name = argv[idx]->arg;
13932 if (reject_all_digit_name && all_digit(cl_name)) {
13933 vty_out(vty, "%% Community name cannot have all digits\n");
13934 return CMD_WARNING_CONFIG_FAILED;
13935 }
13936
13937 idx = 0;
13938 argv_find(argv, argc, "AA:BB:CC", &idx);
13939 argv_find(argv, argc, "LINE", &idx);
13940 /* Concat community string argument. */
13941 if (idx)
13942 str = argv_concat(argv, argc, idx);
13943 else
13944 str = NULL;
13945
13946 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13947
13948 /* Free temporary community list string allocated by
13949 argv_concat(). */
13950 if (str)
13951 XFREE(MTYPE_TMP, str);
13952
13953 if (ret < 0) {
13954 community_list_perror(vty, ret);
13955 return CMD_WARNING_CONFIG_FAILED;
13956 }
13957 return CMD_SUCCESS;
13958 }
13959
13960 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13961 struct cmd_token **argv, int style)
13962 {
13963 int ret;
13964 int direct = 0;
13965 char *str = NULL;
13966 int idx = 0;
13967
13968 argv_find(argv, argc, "permit", &idx);
13969 argv_find(argv, argc, "deny", &idx);
13970
13971 if (idx) {
13972 /* Check the list direct. */
13973 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13974 direct = COMMUNITY_PERMIT;
13975 else
13976 direct = COMMUNITY_DENY;
13977
13978 idx = 0;
13979 argv_find(argv, argc, "LINE", &idx);
13980 argv_find(argv, argc, "AA:AA:NN", &idx);
13981 /* Concat community string argument. */
13982 str = argv_concat(argv, argc, idx);
13983 }
13984
13985 idx = 0;
13986 argv_find(argv, argc, "(1-99)", &idx);
13987 argv_find(argv, argc, "(100-500)", &idx);
13988 argv_find(argv, argc, "WORD", &idx);
13989
13990 /* Unset community list. */
13991 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13992 style);
13993
13994 /* Free temporary community list string allocated by
13995 argv_concat(). */
13996 if (str)
13997 XFREE(MTYPE_TMP, str);
13998
13999 if (ret < 0) {
14000 community_list_perror(vty, ret);
14001 return CMD_WARNING_CONFIG_FAILED;
14002 }
14003
14004 return CMD_SUCCESS;
14005 }
14006
14007 /* "large-community-list" keyword help string. */
14008 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14009 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14010
14011 DEFUN (ip_lcommunity_list_standard,
14012 ip_lcommunity_list_standard_cmd,
14013 "ip large-community-list (1-99) <deny|permit>",
14014 IP_STR
14015 LCOMMUNITY_LIST_STR
14016 "Large Community list number (standard)\n"
14017 "Specify large community to reject\n"
14018 "Specify large community to accept\n")
14019 {
14020 return lcommunity_list_set_vty(vty, argc, argv,
14021 LARGE_COMMUNITY_LIST_STANDARD, 0);
14022 }
14023
14024 DEFUN (ip_lcommunity_list_standard1,
14025 ip_lcommunity_list_standard1_cmd,
14026 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14027 IP_STR
14028 LCOMMUNITY_LIST_STR
14029 "Large Community list number (standard)\n"
14030 "Specify large community to reject\n"
14031 "Specify large community to accept\n"
14032 LCOMMUNITY_VAL_STR)
14033 {
14034 return lcommunity_list_set_vty(vty, argc, argv,
14035 LARGE_COMMUNITY_LIST_STANDARD, 0);
14036 }
14037
14038 DEFUN (ip_lcommunity_list_expanded,
14039 ip_lcommunity_list_expanded_cmd,
14040 "ip large-community-list (100-500) <deny|permit> LINE...",
14041 IP_STR
14042 LCOMMUNITY_LIST_STR
14043 "Large Community list number (expanded)\n"
14044 "Specify large community to reject\n"
14045 "Specify large community to accept\n"
14046 "An ordered list as a regular-expression\n")
14047 {
14048 return lcommunity_list_set_vty(vty, argc, argv,
14049 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14050 }
14051
14052 DEFUN (ip_lcommunity_list_name_standard,
14053 ip_lcommunity_list_name_standard_cmd,
14054 "ip large-community-list standard WORD <deny|permit>",
14055 IP_STR
14056 LCOMMUNITY_LIST_STR
14057 "Specify standard large-community-list\n"
14058 "Large Community list name\n"
14059 "Specify large community to reject\n"
14060 "Specify large community to accept\n")
14061 {
14062 return lcommunity_list_set_vty(vty, argc, argv,
14063 LARGE_COMMUNITY_LIST_STANDARD, 1);
14064 }
14065
14066 DEFUN (ip_lcommunity_list_name_standard1,
14067 ip_lcommunity_list_name_standard1_cmd,
14068 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14069 IP_STR
14070 LCOMMUNITY_LIST_STR
14071 "Specify standard large-community-list\n"
14072 "Large Community list name\n"
14073 "Specify large community to reject\n"
14074 "Specify large community to accept\n"
14075 LCOMMUNITY_VAL_STR)
14076 {
14077 return lcommunity_list_set_vty(vty, argc, argv,
14078 LARGE_COMMUNITY_LIST_STANDARD, 1);
14079 }
14080
14081 DEFUN (ip_lcommunity_list_name_expanded,
14082 ip_lcommunity_list_name_expanded_cmd,
14083 "ip large-community-list expanded WORD <deny|permit> LINE...",
14084 IP_STR
14085 LCOMMUNITY_LIST_STR
14086 "Specify expanded large-community-list\n"
14087 "Large Community list name\n"
14088 "Specify large community to reject\n"
14089 "Specify large community to accept\n"
14090 "An ordered list as a regular-expression\n")
14091 {
14092 return lcommunity_list_set_vty(vty, argc, argv,
14093 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14094 }
14095
14096 DEFUN (no_ip_lcommunity_list_standard_all,
14097 no_ip_lcommunity_list_standard_all_cmd,
14098 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14099 NO_STR
14100 IP_STR
14101 LCOMMUNITY_LIST_STR
14102 "Large Community list number (standard)\n"
14103 "Large Community list number (expanded)\n"
14104 "Large Community list name\n")
14105 {
14106 return lcommunity_list_unset_vty(vty, argc, argv,
14107 LARGE_COMMUNITY_LIST_STANDARD);
14108 }
14109
14110 DEFUN (no_ip_lcommunity_list_name_expanded_all,
14111 no_ip_lcommunity_list_name_expanded_all_cmd,
14112 "no ip large-community-list expanded WORD",
14113 NO_STR
14114 IP_STR
14115 LCOMMUNITY_LIST_STR
14116 "Specify expanded large-community-list\n"
14117 "Large Community list name\n")
14118 {
14119 return lcommunity_list_unset_vty(vty, argc, argv,
14120 LARGE_COMMUNITY_LIST_EXPANDED);
14121 }
14122
14123 DEFUN (no_ip_lcommunity_list_standard,
14124 no_ip_lcommunity_list_standard_cmd,
14125 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14126 NO_STR
14127 IP_STR
14128 LCOMMUNITY_LIST_STR
14129 "Large Community list number (standard)\n"
14130 "Specify large community to reject\n"
14131 "Specify large community to accept\n"
14132 LCOMMUNITY_VAL_STR)
14133 {
14134 return lcommunity_list_unset_vty(vty, argc, argv,
14135 LARGE_COMMUNITY_LIST_STANDARD);
14136 }
14137
14138 DEFUN (no_ip_lcommunity_list_expanded,
14139 no_ip_lcommunity_list_expanded_cmd,
14140 "no ip large-community-list (100-500) <deny|permit> LINE...",
14141 NO_STR
14142 IP_STR
14143 LCOMMUNITY_LIST_STR
14144 "Large Community list number (expanded)\n"
14145 "Specify large community to reject\n"
14146 "Specify large community to accept\n"
14147 "An ordered list as a regular-expression\n")
14148 {
14149 return lcommunity_list_unset_vty(vty, argc, argv,
14150 LARGE_COMMUNITY_LIST_EXPANDED);
14151 }
14152
14153 DEFUN (no_ip_lcommunity_list_name_standard,
14154 no_ip_lcommunity_list_name_standard_cmd,
14155 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14156 NO_STR
14157 IP_STR
14158 LCOMMUNITY_LIST_STR
14159 "Specify standard large-community-list\n"
14160 "Large Community list name\n"
14161 "Specify large community to reject\n"
14162 "Specify large community to accept\n"
14163 LCOMMUNITY_VAL_STR)
14164 {
14165 return lcommunity_list_unset_vty(vty, argc, argv,
14166 LARGE_COMMUNITY_LIST_STANDARD);
14167 }
14168
14169 DEFUN (no_ip_lcommunity_list_name_expanded,
14170 no_ip_lcommunity_list_name_expanded_cmd,
14171 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14172 NO_STR
14173 IP_STR
14174 LCOMMUNITY_LIST_STR
14175 "Specify expanded large-community-list\n"
14176 "Large community list name\n"
14177 "Specify large community to reject\n"
14178 "Specify large community to accept\n"
14179 "An ordered list as a regular-expression\n")
14180 {
14181 return lcommunity_list_unset_vty(vty, argc, argv,
14182 LARGE_COMMUNITY_LIST_EXPANDED);
14183 }
14184
14185 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14186 {
14187 struct community_entry *entry;
14188
14189 for (entry = list->head; entry; entry = entry->next) {
14190 if (entry == list->head) {
14191 if (all_digit(list->name))
14192 vty_out(vty, "Large community %s list %s\n",
14193 entry->style == EXTCOMMUNITY_LIST_STANDARD
14194 ? "standard"
14195 : "(expanded) access",
14196 list->name);
14197 else
14198 vty_out(vty,
14199 "Named large community %s list %s\n",
14200 entry->style == EXTCOMMUNITY_LIST_STANDARD
14201 ? "standard"
14202 : "expanded",
14203 list->name);
14204 }
14205 if (entry->any)
14206 vty_out(vty, " %s\n",
14207 community_direct_str(entry->direct));
14208 else
14209 vty_out(vty, " %s %s\n",
14210 community_direct_str(entry->direct),
14211 community_list_config_str(entry));
14212 }
14213 }
14214
14215 DEFUN (show_ip_lcommunity_list,
14216 show_ip_lcommunity_list_cmd,
14217 "show ip large-community-list",
14218 SHOW_STR
14219 IP_STR
14220 "List large-community list\n")
14221 {
14222 struct community_list *list;
14223 struct community_list_master *cm;
14224
14225 cm = community_list_master_lookup(bgp_clist,
14226 LARGE_COMMUNITY_LIST_MASTER);
14227 if (!cm)
14228 return CMD_SUCCESS;
14229
14230 for (list = cm->num.head; list; list = list->next)
14231 lcommunity_list_show(vty, list);
14232
14233 for (list = cm->str.head; list; list = list->next)
14234 lcommunity_list_show(vty, list);
14235
14236 return CMD_SUCCESS;
14237 }
14238
14239 DEFUN (show_ip_lcommunity_list_arg,
14240 show_ip_lcommunity_list_arg_cmd,
14241 "show ip large-community-list <(1-500)|WORD>",
14242 SHOW_STR
14243 IP_STR
14244 "List large-community list\n"
14245 "large-community-list number\n"
14246 "large-community-list name\n")
14247 {
14248 struct community_list *list;
14249
14250 list = community_list_lookup(bgp_clist, argv[3]->arg,
14251 LARGE_COMMUNITY_LIST_MASTER);
14252 if (!list) {
14253 vty_out(vty, "%% Can't find extcommunity-list\n");
14254 return CMD_WARNING;
14255 }
14256
14257 lcommunity_list_show(vty, list);
14258
14259 return CMD_SUCCESS;
14260 }
14261
14262 /* "extcommunity-list" keyword help string. */
14263 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14264 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14265
14266 DEFUN (ip_extcommunity_list_standard,
14267 ip_extcommunity_list_standard_cmd,
14268 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14269 IP_STR
14270 EXTCOMMUNITY_LIST_STR
14271 "Extended Community list number (standard)\n"
14272 "Specify standard extcommunity-list\n"
14273 "Community list name\n"
14274 "Specify community to reject\n"
14275 "Specify community to accept\n"
14276 EXTCOMMUNITY_VAL_STR)
14277 {
14278 int style = EXTCOMMUNITY_LIST_STANDARD;
14279 int direct = 0;
14280 char *cl_number_or_name = NULL;
14281
14282 int idx = 0;
14283 argv_find(argv, argc, "(1-99)", &idx);
14284 argv_find(argv, argc, "WORD", &idx);
14285 cl_number_or_name = argv[idx]->arg;
14286 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14287 : COMMUNITY_DENY;
14288 argv_find(argv, argc, "AA:NN", &idx);
14289 char *str = argv_concat(argv, argc, idx);
14290
14291 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14292 direct, style);
14293
14294 XFREE(MTYPE_TMP, str);
14295
14296 if (ret < 0) {
14297 community_list_perror(vty, ret);
14298 return CMD_WARNING_CONFIG_FAILED;
14299 }
14300
14301 return CMD_SUCCESS;
14302 }
14303
14304 DEFUN (ip_extcommunity_list_name_expanded,
14305 ip_extcommunity_list_name_expanded_cmd,
14306 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14307 IP_STR
14308 EXTCOMMUNITY_LIST_STR
14309 "Extended Community list number (expanded)\n"
14310 "Specify expanded extcommunity-list\n"
14311 "Extended Community list name\n"
14312 "Specify community to reject\n"
14313 "Specify community to accept\n"
14314 "An ordered list as a regular-expression\n")
14315 {
14316 int style = EXTCOMMUNITY_LIST_EXPANDED;
14317 int direct = 0;
14318 char *cl_number_or_name = NULL;
14319
14320 int idx = 0;
14321 argv_find(argv, argc, "(100-500)", &idx);
14322 argv_find(argv, argc, "WORD", &idx);
14323 cl_number_or_name = argv[idx]->arg;
14324 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14325 : COMMUNITY_DENY;
14326 argv_find(argv, argc, "LINE", &idx);
14327 char *str = argv_concat(argv, argc, idx);
14328
14329 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14330 direct, style);
14331
14332 XFREE(MTYPE_TMP, str);
14333
14334 if (ret < 0) {
14335 community_list_perror(vty, ret);
14336 return CMD_WARNING_CONFIG_FAILED;
14337 }
14338
14339 return CMD_SUCCESS;
14340 }
14341
14342 DEFUN (no_ip_extcommunity_list_standard_all,
14343 no_ip_extcommunity_list_standard_all_cmd,
14344 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14345 NO_STR
14346 IP_STR
14347 EXTCOMMUNITY_LIST_STR
14348 "Extended Community list number (standard)\n"
14349 "Specify standard extcommunity-list\n"
14350 "Community list name\n"
14351 "Specify community to reject\n"
14352 "Specify community to accept\n"
14353 EXTCOMMUNITY_VAL_STR)
14354 {
14355 int style = EXTCOMMUNITY_LIST_STANDARD;
14356 int direct = 0;
14357 char *cl_number_or_name = NULL;
14358
14359 int idx = 0;
14360 argv_find(argv, argc, "(1-99)", &idx);
14361 argv_find(argv, argc, "WORD", &idx);
14362 cl_number_or_name = argv[idx]->arg;
14363 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14364 : COMMUNITY_DENY;
14365 argv_find(argv, argc, "AA:NN", &idx);
14366 char *str = argv_concat(argv, argc, idx);
14367
14368 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14369 direct, style);
14370
14371 XFREE(MTYPE_TMP, str);
14372
14373 if (ret < 0) {
14374 community_list_perror(vty, ret);
14375 return CMD_WARNING_CONFIG_FAILED;
14376 }
14377
14378 return CMD_SUCCESS;
14379 }
14380
14381 DEFUN (no_ip_extcommunity_list_expanded_all,
14382 no_ip_extcommunity_list_expanded_all_cmd,
14383 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14384 NO_STR
14385 IP_STR
14386 EXTCOMMUNITY_LIST_STR
14387 "Extended Community list number (expanded)\n"
14388 "Specify expanded extcommunity-list\n"
14389 "Extended Community list name\n"
14390 "Specify community to reject\n"
14391 "Specify community to accept\n"
14392 "An ordered list as a regular-expression\n")
14393 {
14394 int style = EXTCOMMUNITY_LIST_EXPANDED;
14395 int direct = 0;
14396 char *cl_number_or_name = NULL;
14397
14398 int idx = 0;
14399 argv_find(argv, argc, "(100-500)", &idx);
14400 argv_find(argv, argc, "WORD", &idx);
14401 cl_number_or_name = argv[idx]->arg;
14402 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14403 : COMMUNITY_DENY;
14404 argv_find(argv, argc, "LINE", &idx);
14405 char *str = argv_concat(argv, argc, idx);
14406
14407 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14408 direct, style);
14409
14410 XFREE(MTYPE_TMP, str);
14411
14412 if (ret < 0) {
14413 community_list_perror(vty, ret);
14414 return CMD_WARNING_CONFIG_FAILED;
14415 }
14416
14417 return CMD_SUCCESS;
14418 }
14419
14420 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14421 {
14422 struct community_entry *entry;
14423
14424 for (entry = list->head; entry; entry = entry->next) {
14425 if (entry == list->head) {
14426 if (all_digit(list->name))
14427 vty_out(vty, "Extended community %s list %s\n",
14428 entry->style == EXTCOMMUNITY_LIST_STANDARD
14429 ? "standard"
14430 : "(expanded) access",
14431 list->name);
14432 else
14433 vty_out(vty,
14434 "Named extended community %s list %s\n",
14435 entry->style == EXTCOMMUNITY_LIST_STANDARD
14436 ? "standard"
14437 : "expanded",
14438 list->name);
14439 }
14440 if (entry->any)
14441 vty_out(vty, " %s\n",
14442 community_direct_str(entry->direct));
14443 else
14444 vty_out(vty, " %s %s\n",
14445 community_direct_str(entry->direct),
14446 community_list_config_str(entry));
14447 }
14448 }
14449
14450 DEFUN (show_ip_extcommunity_list,
14451 show_ip_extcommunity_list_cmd,
14452 "show ip extcommunity-list",
14453 SHOW_STR
14454 IP_STR
14455 "List extended-community list\n")
14456 {
14457 struct community_list *list;
14458 struct community_list_master *cm;
14459
14460 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14461 if (!cm)
14462 return CMD_SUCCESS;
14463
14464 for (list = cm->num.head; list; list = list->next)
14465 extcommunity_list_show(vty, list);
14466
14467 for (list = cm->str.head; list; list = list->next)
14468 extcommunity_list_show(vty, list);
14469
14470 return CMD_SUCCESS;
14471 }
14472
14473 DEFUN (show_ip_extcommunity_list_arg,
14474 show_ip_extcommunity_list_arg_cmd,
14475 "show ip extcommunity-list <(1-500)|WORD>",
14476 SHOW_STR
14477 IP_STR
14478 "List extended-community list\n"
14479 "Extcommunity-list number\n"
14480 "Extcommunity-list name\n")
14481 {
14482 int idx_comm_list = 3;
14483 struct community_list *list;
14484
14485 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14486 EXTCOMMUNITY_LIST_MASTER);
14487 if (!list) {
14488 vty_out(vty, "%% Can't find extcommunity-list\n");
14489 return CMD_WARNING;
14490 }
14491
14492 extcommunity_list_show(vty, list);
14493
14494 return CMD_SUCCESS;
14495 }
14496
14497 /* Display community-list and extcommunity-list configuration. */
14498 static int community_list_config_write(struct vty *vty)
14499 {
14500 struct community_list *list;
14501 struct community_entry *entry;
14502 struct community_list_master *cm;
14503 int write = 0;
14504
14505 /* Community-list. */
14506 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14507
14508 for (list = cm->num.head; list; list = list->next)
14509 for (entry = list->head; entry; entry = entry->next) {
14510 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14511 community_direct_str(entry->direct),
14512 community_list_config_str(entry));
14513 write++;
14514 }
14515 for (list = cm->str.head; list; list = list->next)
14516 for (entry = list->head; entry; entry = entry->next) {
14517 vty_out(vty, "ip community-list %s %s %s %s\n",
14518 entry->style == COMMUNITY_LIST_STANDARD
14519 ? "standard"
14520 : "expanded",
14521 list->name, community_direct_str(entry->direct),
14522 community_list_config_str(entry));
14523 write++;
14524 }
14525
14526 /* Extcommunity-list. */
14527 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14528
14529 for (list = cm->num.head; list; list = list->next)
14530 for (entry = list->head; entry; entry = entry->next) {
14531 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14532 list->name, community_direct_str(entry->direct),
14533 community_list_config_str(entry));
14534 write++;
14535 }
14536 for (list = cm->str.head; list; list = list->next)
14537 for (entry = list->head; entry; entry = entry->next) {
14538 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14539 entry->style == EXTCOMMUNITY_LIST_STANDARD
14540 ? "standard"
14541 : "expanded",
14542 list->name, community_direct_str(entry->direct),
14543 community_list_config_str(entry));
14544 write++;
14545 }
14546
14547
14548 /* lcommunity-list. */
14549 cm = community_list_master_lookup(bgp_clist,
14550 LARGE_COMMUNITY_LIST_MASTER);
14551
14552 for (list = cm->num.head; list; list = list->next)
14553 for (entry = list->head; entry; entry = entry->next) {
14554 vty_out(vty, "ip large-community-list %s %s %s\n",
14555 list->name, community_direct_str(entry->direct),
14556 community_list_config_str(entry));
14557 write++;
14558 }
14559 for (list = cm->str.head; list; list = list->next)
14560 for (entry = list->head; entry; entry = entry->next) {
14561 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14562 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14563 ? "standard"
14564 : "expanded",
14565 list->name, community_direct_str(entry->direct),
14566 community_list_config_str(entry));
14567 write++;
14568 }
14569
14570 return write;
14571 }
14572
14573 static struct cmd_node community_list_node = {
14574 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14575 };
14576
14577 static void community_list_vty(void)
14578 {
14579 install_node(&community_list_node, community_list_config_write);
14580
14581 /* Community-list. */
14582 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14583 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14584 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14585 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14586 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14587 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14588
14589 /* Extcommunity-list. */
14590 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14591 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14592 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14593 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14594 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14595 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14596
14597 /* Large Community List */
14598 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14599 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14600 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14601 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14602 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14603 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14604 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14605 install_element(CONFIG_NODE,
14606 &no_ip_lcommunity_list_name_expanded_all_cmd);
14607 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14608 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14609 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14610 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14611 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14612 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14613 }