]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: Make `struct bgp_addr` a private data structure
[mirror_frr.git] / bgpd / bgp_vty.c
1 /* BGP VTY interface.
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "lib/json.h"
25 #include "prefix.h"
26 #include "plist.h"
27 #include "buffer.h"
28 #include "linklist.h"
29 #include "stream.h"
30 #include "thread.h"
31 #include "log.h"
32 #include "memory.h"
33 #include "memory_vty.h"
34 #include "hash.h"
35 #include "queue.h"
36 #include "filter.h"
37 #include "frrstr.h"
38
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_advertise.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_community.h"
44 #include "bgpd/bgp_ecommunity.h"
45 #include "bgpd/bgp_lcommunity.h"
46 #include "bgpd/bgp_damp.h"
47 #include "bgpd/bgp_debug.h"
48 #include "bgpd/bgp_errors.h"
49 #include "bgpd/bgp_fsm.h"
50 #include "bgpd/bgp_nexthop.h"
51 #include "bgpd/bgp_open.h"
52 #include "bgpd/bgp_regex.h"
53 #include "bgpd/bgp_route.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_zebra.h"
56 #include "bgpd/bgp_table.h"
57 #include "bgpd/bgp_vty.h"
58 #include "bgpd/bgp_mpath.h"
59 #include "bgpd/bgp_packet.h"
60 #include "bgpd/bgp_updgrp.h"
61 #include "bgpd/bgp_bfd.h"
62 #include "bgpd/bgp_io.h"
63 #include "bgpd/bgp_evpn.h"
64
65 static struct peer_group *listen_range_exists(struct bgp *bgp,
66 struct prefix *range, int exact);
67
68 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
69 {
70 switch (afi) {
71 case AFI_IP:
72 switch (safi) {
73 case SAFI_UNICAST:
74 return BGP_IPV4_NODE;
75 break;
76 case SAFI_MULTICAST:
77 return BGP_IPV4M_NODE;
78 break;
79 case SAFI_LABELED_UNICAST:
80 return BGP_IPV4L_NODE;
81 break;
82 case SAFI_MPLS_VPN:
83 return BGP_VPNV4_NODE;
84 break;
85 case SAFI_FLOWSPEC:
86 return BGP_FLOWSPECV4_NODE;
87 default:
88 /* not expected */
89 return BGP_IPV4_NODE;
90 break;
91 }
92 break;
93 case AFI_IP6:
94 switch (safi) {
95 case SAFI_UNICAST:
96 return BGP_IPV6_NODE;
97 break;
98 case SAFI_MULTICAST:
99 return BGP_IPV6M_NODE;
100 break;
101 case SAFI_LABELED_UNICAST:
102 return BGP_IPV6L_NODE;
103 break;
104 case SAFI_MPLS_VPN:
105 return BGP_VPNV6_NODE;
106 break;
107 case SAFI_FLOWSPEC:
108 return BGP_FLOWSPECV6_NODE;
109 default:
110 /* not expected */
111 return BGP_IPV4_NODE;
112 break;
113 }
114 break;
115 case AFI_L2VPN:
116 return BGP_EVPN_NODE;
117 break;
118 case AFI_MAX:
119 // We should never be here but to clarify the switch statement..
120 return BGP_IPV4_NODE;
121 break;
122 }
123
124 // Impossible to happen
125 return BGP_IPV4_NODE;
126 }
127
128 /* Utility function to get address family from current node. */
129 afi_t bgp_node_afi(struct vty *vty)
130 {
131 afi_t afi;
132 switch (vty->node) {
133 case BGP_IPV6_NODE:
134 case BGP_IPV6M_NODE:
135 case BGP_IPV6L_NODE:
136 case BGP_VPNV6_NODE:
137 case BGP_FLOWSPECV6_NODE:
138 afi = AFI_IP6;
139 break;
140 case BGP_EVPN_NODE:
141 afi = AFI_L2VPN;
142 break;
143 default:
144 afi = AFI_IP;
145 break;
146 }
147 return afi;
148 }
149
150 /* Utility function to get subsequent address family from current
151 node. */
152 safi_t bgp_node_safi(struct vty *vty)
153 {
154 safi_t safi;
155 switch (vty->node) {
156 case BGP_VPNV4_NODE:
157 case BGP_VPNV6_NODE:
158 safi = SAFI_MPLS_VPN;
159 break;
160 case BGP_IPV4M_NODE:
161 case BGP_IPV6M_NODE:
162 safi = SAFI_MULTICAST;
163 break;
164 case BGP_EVPN_NODE:
165 safi = SAFI_EVPN;
166 break;
167 case BGP_IPV4L_NODE:
168 case BGP_IPV6L_NODE:
169 safi = SAFI_LABELED_UNICAST;
170 break;
171 case BGP_FLOWSPECV4_NODE:
172 case BGP_FLOWSPECV6_NODE:
173 safi = SAFI_FLOWSPEC;
174 break;
175 default:
176 safi = SAFI_UNICAST;
177 break;
178 }
179 return safi;
180 }
181
182 /**
183 * Converts an AFI in string form to afi_t
184 *
185 * @param afi string, one of
186 * - "ipv4"
187 * - "ipv6"
188 * - "l2vpn"
189 * @return the corresponding afi_t
190 */
191 afi_t bgp_vty_afi_from_str(const char *afi_str)
192 {
193 afi_t afi = AFI_MAX; /* unknown */
194 if (strmatch(afi_str, "ipv4"))
195 afi = AFI_IP;
196 else if (strmatch(afi_str, "ipv6"))
197 afi = AFI_IP6;
198 else if (strmatch(afi_str, "l2vpn"))
199 afi = AFI_L2VPN;
200 return afi;
201 }
202
203 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
204 afi_t *afi)
205 {
206 int ret = 0;
207 if (argv_find(argv, argc, "ipv4", index)) {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP;
211 } else if (argv_find(argv, argc, "ipv6", index)) {
212 ret = 1;
213 if (afi)
214 *afi = AFI_IP6;
215 }
216 return ret;
217 }
218
219 /* supports <unicast|multicast|vpn|labeled-unicast> */
220 safi_t bgp_vty_safi_from_str(const char *safi_str)
221 {
222 safi_t safi = SAFI_MAX; /* unknown */
223 if (strmatch(safi_str, "multicast"))
224 safi = SAFI_MULTICAST;
225 else if (strmatch(safi_str, "unicast"))
226 safi = SAFI_UNICAST;
227 else if (strmatch(safi_str, "vpn"))
228 safi = SAFI_MPLS_VPN;
229 else if (strmatch(safi_str, "evpn"))
230 safi = SAFI_EVPN;
231 else if (strmatch(safi_str, "labeled-unicast"))
232 safi = SAFI_LABELED_UNICAST;
233 else if (strmatch(safi_str, "flowspec"))
234 safi = SAFI_FLOWSPEC;
235 return safi;
236 }
237
238 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
239 safi_t *safi)
240 {
241 int ret = 0;
242 if (argv_find(argv, argc, "unicast", index)) {
243 ret = 1;
244 if (safi)
245 *safi = SAFI_UNICAST;
246 } else if (argv_find(argv, argc, "multicast", index)) {
247 ret = 1;
248 if (safi)
249 *safi = SAFI_MULTICAST;
250 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
251 ret = 1;
252 if (safi)
253 *safi = SAFI_LABELED_UNICAST;
254 } else if (argv_find(argv, argc, "vpn", index)) {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_MPLS_VPN;
258 } else if (argv_find(argv, argc, "flowspec", index)) {
259 ret = 1;
260 if (safi)
261 *safi = SAFI_FLOWSPEC;
262 }
263 return ret;
264 }
265
266 /*
267 * bgp_vty_find_and_parse_afi_safi_bgp
268 *
269 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
270 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
271 * to appropriate values for the calling function. This is to allow the
272 * calling function to make decisions appropriate for the show command
273 * that is being parsed.
274 *
275 * The show commands are generally of the form:
276 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
277 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
278 *
279 * Since we use argv_find if the show command in particular doesn't have:
280 * [ip]
281 * [<view|vrf> VIEWVRFNAME]
282 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
283 * The command parsing should still be ok.
284 *
285 * vty -> The vty for the command so we can output some useful data in
286 * the event of a parse error in the vrf.
287 * argv -> The command tokens
288 * argc -> How many command tokens we have
289 * idx -> The current place in the command, generally should be 0 for this
290 * function
291 * afi -> The parsed afi if it was included in the show command, returned here
292 * safi -> The parsed safi if it was included in the show command, returned here
293 * bgp -> Pointer to the bgp data structure we need to fill in.
294 *
295 * The function returns the correct location in the parse tree for the
296 * last token found.
297 *
298 * Returns 0 for failure to parse correctly, else the idx position of where
299 * it found the last token.
300 */
301 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
302 struct cmd_token **argv, int argc,
303 int *idx, afi_t *afi, safi_t *safi,
304 struct bgp **bgp, bool use_json)
305 {
306 char *vrf_name = NULL;
307
308 assert(afi);
309 assert(safi);
310 assert(bgp);
311
312 if (argv_find(argv, argc, "ip", idx))
313 *afi = AFI_IP;
314
315 if (argv_find(argv, argc, "view", idx))
316 vrf_name = argv[*idx + 1]->arg;
317 else if (argv_find(argv, argc, "vrf", idx)) {
318 vrf_name = argv[*idx + 1]->arg;
319 if (strmatch(vrf_name, VRF_DEFAULT_NAME))
320 vrf_name = NULL;
321 }
322 if (vrf_name) {
323 if (strmatch(vrf_name, "all"))
324 *bgp = NULL;
325 else {
326 *bgp = bgp_lookup_by_name(vrf_name);
327 if (!*bgp) {
328 if (use_json)
329 vty_out(vty, "{}\n");
330 else
331 vty_out(vty, "View/Vrf %s is unknown\n",
332 vrf_name);
333 *idx = 0;
334 return 0;
335 }
336 }
337 } else {
338 *bgp = bgp_get_default();
339 if (!*bgp) {
340 if (use_json)
341 vty_out(vty, "{}\n");
342 else
343 vty_out(vty,
344 "Default BGP instance not found\n");
345 *idx = 0;
346 return 0;
347 }
348 }
349
350 if (argv_find_and_parse_afi(argv, argc, idx, afi))
351 argv_find_and_parse_safi(argv, argc, idx, safi);
352
353 *idx += 1;
354 return *idx;
355 }
356
357 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
358 {
359 struct interface *ifp = NULL;
360
361 if (su->sa.sa_family == AF_INET)
362 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
363 else if (su->sa.sa_family == AF_INET6)
364 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
365 su->sin6.sin6_scope_id,
366 bgp->vrf_id);
367
368 if (ifp)
369 return 1;
370
371 return 0;
372 }
373
374 /* Utility function for looking up peer from VTY. */
375 /* This is used only for configuration, so disallow if attempted on
376 * a dynamic neighbor.
377 */
378 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
379 {
380 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
381 int ret;
382 union sockunion su;
383 struct peer *peer;
384
385 if (!bgp) {
386 return NULL;
387 }
388
389 ret = str2sockunion(ip_str, &su);
390 if (ret < 0) {
391 peer = peer_lookup_by_conf_if(bgp, ip_str);
392 if (!peer) {
393 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
394 == NULL) {
395 vty_out(vty,
396 "%% Malformed address or name: %s\n",
397 ip_str);
398 return NULL;
399 }
400 }
401 } else {
402 peer = peer_lookup(bgp, &su);
403 if (!peer) {
404 vty_out(vty,
405 "%% Specify remote-as or peer-group commands first\n");
406 return NULL;
407 }
408 if (peer_dynamic_neighbor(peer)) {
409 vty_out(vty,
410 "%% Operation not allowed on a dynamic neighbor\n");
411 return NULL;
412 }
413 }
414 return peer;
415 }
416
417 /* Utility function for looking up peer or peer group. */
418 /* This is used only for configuration, so disallow if attempted on
419 * a dynamic neighbor.
420 */
421 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
422 {
423 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
424 int ret;
425 union sockunion su;
426 struct peer *peer = NULL;
427 struct peer_group *group = NULL;
428
429 if (!bgp) {
430 return NULL;
431 }
432
433 ret = str2sockunion(peer_str, &su);
434 if (ret == 0) {
435 /* IP address, locate peer. */
436 peer = peer_lookup(bgp, &su);
437 } else {
438 /* Not IP, could match either peer configured on interface or a
439 * group. */
440 peer = peer_lookup_by_conf_if(bgp, peer_str);
441 if (!peer)
442 group = peer_group_lookup(bgp, peer_str);
443 }
444
445 if (peer) {
446 if (peer_dynamic_neighbor(peer)) {
447 vty_out(vty,
448 "%% Operation not allowed on a dynamic neighbor\n");
449 return NULL;
450 }
451
452 return peer;
453 }
454
455 if (group)
456 return group->conf;
457
458 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
459
460 return NULL;
461 }
462
463 int bgp_vty_return(struct vty *vty, int ret)
464 {
465 const char *str = NULL;
466
467 switch (ret) {
468 case BGP_ERR_INVALID_VALUE:
469 str = "Invalid value";
470 break;
471 case BGP_ERR_INVALID_FLAG:
472 str = "Invalid flag";
473 break;
474 case BGP_ERR_PEER_GROUP_SHUTDOWN:
475 str = "Peer-group has been shutdown. Activate the peer-group first";
476 break;
477 case BGP_ERR_PEER_FLAG_CONFLICT:
478 str = "Can't set override-capability and strict-capability-match at the same time";
479 break;
480 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
481 str = "Specify remote-as or peer-group remote AS first";
482 break;
483 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
484 str = "Cannot change the peer-group. Deconfigure first";
485 break;
486 case BGP_ERR_PEER_GROUP_MISMATCH:
487 str = "Peer is not a member of this peer-group";
488 break;
489 case BGP_ERR_PEER_FILTER_CONFLICT:
490 str = "Prefix/distribute list can not co-exist";
491 break;
492 case BGP_ERR_NOT_INTERNAL_PEER:
493 str = "Invalid command. Not an internal neighbor";
494 break;
495 case BGP_ERR_REMOVE_PRIVATE_AS:
496 str = "remove-private-AS cannot be configured for IBGP peers";
497 break;
498 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
499 str = "Local-AS allowed only for EBGP peers";
500 break;
501 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
502 str = "Cannot have local-as same as BGP AS number";
503 break;
504 case BGP_ERR_TCPSIG_FAILED:
505 str = "Error while applying TCP-Sig to session(s)";
506 break;
507 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
508 str = "ebgp-multihop and ttl-security cannot be configured together";
509 break;
510 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
511 str = "ttl-security only allowed for EBGP peers";
512 break;
513 case BGP_ERR_AS_OVERRIDE:
514 str = "as-override cannot be configured for IBGP peers";
515 break;
516 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
517 str = "Invalid limit for number of dynamic neighbors";
518 break;
519 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
520 str = "Dynamic neighbor listen range already exists";
521 break;
522 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
523 str = "Operation not allowed on a dynamic neighbor";
524 break;
525 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
526 str = "Operation not allowed on a directly connected neighbor";
527 break;
528 case BGP_ERR_PEER_SAFI_CONFLICT:
529 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
530 break;
531 }
532 if (str) {
533 vty_out(vty, "%% %s\n", str);
534 return CMD_WARNING_CONFIG_FAILED;
535 }
536 return CMD_SUCCESS;
537 }
538
539 /* BGP clear sort. */
540 enum clear_sort {
541 clear_all,
542 clear_peer,
543 clear_group,
544 clear_external,
545 clear_as
546 };
547
548 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
549 safi_t safi, int error)
550 {
551 switch (error) {
552 case BGP_ERR_AF_UNCONFIGURED:
553 vty_out(vty,
554 "%%BGP: Enable %s address family for the neighbor %s\n",
555 afi_safi_print(afi, safi), peer->host);
556 break;
557 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
558 vty_out(vty,
559 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
560 peer->host);
561 break;
562 default:
563 break;
564 }
565 }
566
567 /* `clear ip bgp' functions. */
568 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
569 enum clear_sort sort, enum bgp_clear_type stype,
570 const char *arg)
571 {
572 int ret;
573 bool found = false;
574 struct peer *peer;
575 struct listnode *node, *nnode;
576
577 /* Clear all neighbors. */
578 /*
579 * Pass along pointer to next node to peer_clear() when walking all
580 * nodes on the BGP instance as that may get freed if it is a
581 * doppelganger
582 */
583 if (sort == clear_all) {
584 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
585 if (!peer->afc[afi][safi])
586 continue;
587
588 if (stype == BGP_CLEAR_SOFT_NONE)
589 ret = peer_clear(peer, &nnode);
590 else
591 ret = peer_clear_soft(peer, afi, safi, stype);
592
593 if (ret < 0)
594 bgp_clear_vty_error(vty, peer, afi, safi, ret);
595 else
596 found = true;
597 }
598
599 /* This is to apply read-only mode on this clear. */
600 if (stype == BGP_CLEAR_SOFT_NONE)
601 bgp->update_delay_over = 0;
602
603 if (!found)
604 vty_out(vty, "%%BGP: No %s peer configured",
605 afi_safi_print(afi, safi));
606
607 return CMD_SUCCESS;
608 }
609
610 /* Clear specified neighbor. */
611 if (sort == clear_peer) {
612 union sockunion su;
613
614 /* Make sockunion for lookup. */
615 ret = str2sockunion(arg, &su);
616 if (ret < 0) {
617 peer = peer_lookup_by_conf_if(bgp, arg);
618 if (!peer) {
619 peer = peer_lookup_by_hostname(bgp, arg);
620 if (!peer) {
621 vty_out(vty,
622 "Malformed address or name: %s\n",
623 arg);
624 return CMD_WARNING;
625 }
626 }
627 } else {
628 peer = peer_lookup(bgp, &su);
629 if (!peer) {
630 vty_out(vty,
631 "%%BGP: Unknown neighbor - \"%s\"\n",
632 arg);
633 return CMD_WARNING;
634 }
635 }
636
637 if (!peer->afc[afi][safi])
638 ret = BGP_ERR_AF_UNCONFIGURED;
639 else if (stype == BGP_CLEAR_SOFT_NONE)
640 ret = peer_clear(peer, NULL);
641 else
642 ret = peer_clear_soft(peer, afi, safi, stype);
643
644 if (ret < 0)
645 bgp_clear_vty_error(vty, peer, afi, safi, ret);
646
647 return CMD_SUCCESS;
648 }
649
650 /* Clear all neighbors belonging to a specific peer-group. */
651 if (sort == clear_group) {
652 struct peer_group *group;
653
654 group = peer_group_lookup(bgp, arg);
655 if (!group) {
656 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
657 return CMD_WARNING;
658 }
659
660 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
661 if (!peer->afc[afi][safi])
662 continue;
663
664 if (stype == BGP_CLEAR_SOFT_NONE)
665 ret = peer_clear(peer, NULL);
666 else
667 ret = peer_clear_soft(peer, afi, safi, stype);
668
669 if (ret < 0)
670 bgp_clear_vty_error(vty, peer, afi, safi, ret);
671 else
672 found = true;
673 }
674
675 if (!found)
676 vty_out(vty,
677 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
678 afi_safi_print(afi, safi), arg);
679
680 return CMD_SUCCESS;
681 }
682
683 /* Clear all external (eBGP) neighbors. */
684 if (sort == clear_external) {
685 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
686 if (peer->sort == BGP_PEER_IBGP)
687 continue;
688
689 if (!peer->afc[afi][safi])
690 continue;
691
692 if (stype == BGP_CLEAR_SOFT_NONE)
693 ret = peer_clear(peer, &nnode);
694 else
695 ret = peer_clear_soft(peer, afi, safi, stype);
696
697 if (ret < 0)
698 bgp_clear_vty_error(vty, peer, afi, safi, ret);
699 else
700 found = true;
701 }
702
703 if (!found)
704 vty_out(vty,
705 "%%BGP: No external %s peer is configured\n",
706 afi_safi_print(afi, safi));
707
708 return CMD_SUCCESS;
709 }
710
711 /* Clear all neighbors belonging to a specific AS. */
712 if (sort == clear_as) {
713 as_t as = strtoul(arg, NULL, 10);
714
715 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
716 if (peer->as != as)
717 continue;
718
719 if (!peer->afc[afi][safi])
720 ret = BGP_ERR_AF_UNCONFIGURED;
721 else if (stype == BGP_CLEAR_SOFT_NONE)
722 ret = peer_clear(peer, &nnode);
723 else
724 ret = peer_clear_soft(peer, afi, safi, stype);
725
726 if (ret < 0)
727 bgp_clear_vty_error(vty, peer, afi, safi, ret);
728 else
729 found = true;
730 }
731
732 if (!found)
733 vty_out(vty,
734 "%%BGP: No %s peer is configured with AS %s\n",
735 afi_safi_print(afi, safi), arg);
736
737 return CMD_SUCCESS;
738 }
739
740 return CMD_SUCCESS;
741 }
742
743 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
744 safi_t safi, enum clear_sort sort,
745 enum bgp_clear_type stype, const char *arg)
746 {
747 struct bgp *bgp;
748
749 /* BGP structure lookup. */
750 if (name) {
751 bgp = bgp_lookup_by_name(name);
752 if (bgp == NULL) {
753 vty_out(vty, "Can't find BGP instance %s\n", name);
754 return CMD_WARNING;
755 }
756 } else {
757 bgp = bgp_get_default();
758 if (bgp == NULL) {
759 vty_out(vty, "No BGP process is configured\n");
760 return CMD_WARNING;
761 }
762 }
763
764 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
765 }
766
767 /* clear soft inbound */
768 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
769 {
770 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
771 BGP_CLEAR_SOFT_IN, NULL);
772 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
773 BGP_CLEAR_SOFT_IN, NULL);
774 }
775
776 /* clear soft outbound */
777 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
778 {
779 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
780 BGP_CLEAR_SOFT_OUT, NULL);
781 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
782 BGP_CLEAR_SOFT_OUT, NULL);
783 }
784
785
786 #ifndef VTYSH_EXTRACT_PL
787 #include "bgpd/bgp_vty_clippy.c"
788 #endif
789
790 /* BGP global configuration. */
791 #if (CONFDATE > 20190601)
792 CPP_NOTICE("bgpd: time to remove deprecated bgp multiple-instance")
793 CPP_NOTICE("This includes BGP_OPT_MULTIPLE_INSTANCE")
794 #endif
795 DEFUN_HIDDEN (bgp_multiple_instance_func,
796 bgp_multiple_instance_cmd,
797 "bgp multiple-instance",
798 BGP_STR
799 "Enable bgp multiple instance\n")
800 {
801 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
802 return CMD_SUCCESS;
803 }
804
805 DEFUN_HIDDEN (no_bgp_multiple_instance,
806 no_bgp_multiple_instance_cmd,
807 "no bgp multiple-instance",
808 NO_STR
809 BGP_STR
810 "BGP multiple instance\n")
811 {
812 int ret;
813
814 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
815 vty_out(vty, "if you are using this please let the developers know\n");
816 zlog_info("Deprecated option: `bgp multiple-instance` being used");
817 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
818 if (ret < 0) {
819 vty_out(vty, "%% There are more than two BGP instances\n");
820 return CMD_WARNING_CONFIG_FAILED;
821 }
822 return CMD_SUCCESS;
823 }
824
825 #if (CONFDATE > 20190601)
826 CPP_NOTICE("bgpd: time to remove deprecated cli bgp config-type cisco")
827 CPP_NOTICE("This includes BGP_OPT_CISCO_CONFIG")
828 #endif
829 DEFUN_HIDDEN (bgp_config_type,
830 bgp_config_type_cmd,
831 "bgp config-type <cisco|zebra>",
832 BGP_STR
833 "Configuration type\n"
834 "cisco\n"
835 "zebra\n")
836 {
837 int idx = 0;
838 if (argv_find(argv, argc, "cisco", &idx)) {
839 vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
840 vty_out(vty, "if you are using this please let the developers know!\n");
841 zlog_info("Deprecated option: `bgp config-type cisco` being used");
842 bgp_option_set(BGP_OPT_CONFIG_CISCO);
843 } else
844 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
845
846 return CMD_SUCCESS;
847 }
848
849 DEFUN_HIDDEN (no_bgp_config_type,
850 no_bgp_config_type_cmd,
851 "no bgp config-type [<cisco|zebra>]",
852 NO_STR
853 BGP_STR
854 "Display configuration type\n"
855 "cisco\n"
856 "zebra\n")
857 {
858 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
859 return CMD_SUCCESS;
860 }
861
862
863 DEFUN (no_synchronization,
864 no_synchronization_cmd,
865 "no synchronization",
866 NO_STR
867 "Perform IGP synchronization\n")
868 {
869 return CMD_SUCCESS;
870 }
871
872 DEFUN (no_auto_summary,
873 no_auto_summary_cmd,
874 "no auto-summary",
875 NO_STR
876 "Enable automatic network number summarization\n")
877 {
878 return CMD_SUCCESS;
879 }
880
881 /* "router bgp" commands. */
882 DEFUN_NOSH (router_bgp,
883 router_bgp_cmd,
884 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
885 ROUTER_STR
886 BGP_STR
887 AS_STR
888 BGP_INSTANCE_HELP_STR)
889 {
890 int idx_asn = 2;
891 int idx_view_vrf = 3;
892 int idx_vrf = 4;
893 int ret;
894 as_t as;
895 struct bgp *bgp;
896 const char *name = NULL;
897 enum bgp_instance_type inst_type;
898
899 // "router bgp" without an ASN
900 if (argc == 2) {
901 // Pending: Make VRF option available for ASN less config
902 bgp = bgp_get_default();
903
904 if (bgp == NULL) {
905 vty_out(vty, "%% No BGP process is configured\n");
906 return CMD_WARNING_CONFIG_FAILED;
907 }
908
909 if (listcount(bm->bgp) > 1) {
910 vty_out(vty, "%% Please specify ASN and VRF\n");
911 return CMD_WARNING_CONFIG_FAILED;
912 }
913 }
914
915 // "router bgp X"
916 else {
917 as = strtoul(argv[idx_asn]->arg, NULL, 10);
918
919 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
920 if (argc > 3) {
921 name = argv[idx_vrf]->arg;
922
923 if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
924 if (strmatch(name, VRF_DEFAULT_NAME))
925 name = NULL;
926 else
927 inst_type = BGP_INSTANCE_TYPE_VRF;
928 } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
929 inst_type = BGP_INSTANCE_TYPE_VIEW;
930 }
931
932 ret = bgp_get(&bgp, &as, name, inst_type);
933 switch (ret) {
934 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
935 vty_out(vty,
936 "Please specify 'bgp multiple-instance' first\n");
937 return CMD_WARNING_CONFIG_FAILED;
938 case BGP_ERR_AS_MISMATCH:
939 vty_out(vty, "BGP is already running; AS is %u\n", as);
940 return CMD_WARNING_CONFIG_FAILED;
941 case BGP_ERR_INSTANCE_MISMATCH:
942 vty_out(vty,
943 "BGP instance name and AS number mismatch\n");
944 vty_out(vty,
945 "BGP instance is already running; AS is %u\n",
946 as);
947 return CMD_WARNING_CONFIG_FAILED;
948 }
949
950 /*
951 * If we just instantiated the default instance, complete
952 * any pending VRF-VPN leaking that was configured via
953 * earlier "router bgp X vrf FOO" blocks.
954 */
955 if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
956 vpn_leak_postchange_all();
957
958 /* Pending: handle when user tries to change a view to vrf n vv.
959 */
960 }
961
962 /* unset the auto created flag as the user config is now present */
963 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
964 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
965
966 return CMD_SUCCESS;
967 }
968
969 /* "no router bgp" commands. */
970 DEFUN (no_router_bgp,
971 no_router_bgp_cmd,
972 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
973 NO_STR
974 ROUTER_STR
975 BGP_STR
976 AS_STR
977 BGP_INSTANCE_HELP_STR)
978 {
979 int idx_asn = 3;
980 int idx_vrf = 5;
981 as_t as;
982 struct bgp *bgp;
983 const char *name = NULL;
984
985 // "no router bgp" without an ASN
986 if (argc == 3) {
987 // Pending: Make VRF option available for ASN less config
988 bgp = bgp_get_default();
989
990 if (bgp == NULL) {
991 vty_out(vty, "%% No BGP process is configured\n");
992 return CMD_WARNING_CONFIG_FAILED;
993 }
994
995 if (listcount(bm->bgp) > 1) {
996 vty_out(vty, "%% Please specify ASN and VRF\n");
997 return CMD_WARNING_CONFIG_FAILED;
998 }
999
1000 if (bgp->l3vni) {
1001 vty_out(vty, "%% Please unconfigure l3vni %u",
1002 bgp->l3vni);
1003 return CMD_WARNING_CONFIG_FAILED;
1004 }
1005 } else {
1006 as = strtoul(argv[idx_asn]->arg, NULL, 10);
1007
1008 if (argc > 4)
1009 name = argv[idx_vrf]->arg;
1010
1011 /* Lookup bgp structure. */
1012 bgp = bgp_lookup(as, name);
1013 if (!bgp) {
1014 vty_out(vty, "%% Can't find BGP instance\n");
1015 return CMD_WARNING_CONFIG_FAILED;
1016 }
1017
1018 if (bgp->l3vni) {
1019 vty_out(vty, "%% Please unconfigure l3vni %u",
1020 bgp->l3vni);
1021 return CMD_WARNING_CONFIG_FAILED;
1022 }
1023 }
1024
1025 bgp_delete(bgp);
1026
1027 return CMD_SUCCESS;
1028 }
1029
1030
1031 /* BGP router-id. */
1032
1033 DEFPY (bgp_router_id,
1034 bgp_router_id_cmd,
1035 "bgp router-id A.B.C.D",
1036 BGP_STR
1037 "Override configured router identifier\n"
1038 "Manually configured router identifier\n")
1039 {
1040 VTY_DECLVAR_CONTEXT(bgp, bgp);
1041 bgp_router_id_static_set(bgp, router_id);
1042 return CMD_SUCCESS;
1043 }
1044
1045 DEFPY (no_bgp_router_id,
1046 no_bgp_router_id_cmd,
1047 "no bgp router-id [A.B.C.D]",
1048 NO_STR
1049 BGP_STR
1050 "Override configured router identifier\n"
1051 "Manually configured router identifier\n")
1052 {
1053 VTY_DECLVAR_CONTEXT(bgp, bgp);
1054
1055 if (router_id_str) {
1056 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1057 vty_out(vty, "%% BGP router-id doesn't match\n");
1058 return CMD_WARNING_CONFIG_FAILED;
1059 }
1060 }
1061
1062 router_id.s_addr = 0;
1063 bgp_router_id_static_set(bgp, router_id);
1064
1065 return CMD_SUCCESS;
1066 }
1067
1068
1069 /* BGP Cluster ID. */
1070 DEFUN (bgp_cluster_id,
1071 bgp_cluster_id_cmd,
1072 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1073 BGP_STR
1074 "Configure Route-Reflector Cluster-id\n"
1075 "Route-Reflector Cluster-id in IP address format\n"
1076 "Route-Reflector Cluster-id as 32 bit quantity\n")
1077 {
1078 VTY_DECLVAR_CONTEXT(bgp, bgp);
1079 int idx_ipv4 = 2;
1080 int ret;
1081 struct in_addr cluster;
1082
1083 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1084 if (!ret) {
1085 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1086 return CMD_WARNING_CONFIG_FAILED;
1087 }
1088
1089 bgp_cluster_id_set(bgp, &cluster);
1090 bgp_clear_star_soft_out(vty, bgp->name);
1091
1092 return CMD_SUCCESS;
1093 }
1094
1095 DEFUN (no_bgp_cluster_id,
1096 no_bgp_cluster_id_cmd,
1097 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1098 NO_STR
1099 BGP_STR
1100 "Configure Route-Reflector Cluster-id\n"
1101 "Route-Reflector Cluster-id in IP address format\n"
1102 "Route-Reflector Cluster-id as 32 bit quantity\n")
1103 {
1104 VTY_DECLVAR_CONTEXT(bgp, bgp);
1105 bgp_cluster_id_unset(bgp);
1106 bgp_clear_star_soft_out(vty, bgp->name);
1107
1108 return CMD_SUCCESS;
1109 }
1110
1111 DEFUN (bgp_confederation_identifier,
1112 bgp_confederation_identifier_cmd,
1113 "bgp confederation identifier (1-4294967295)",
1114 "BGP specific commands\n"
1115 "AS confederation parameters\n"
1116 "AS number\n"
1117 "Set routing domain confederation AS\n")
1118 {
1119 VTY_DECLVAR_CONTEXT(bgp, bgp);
1120 int idx_number = 3;
1121 as_t as;
1122
1123 as = strtoul(argv[idx_number]->arg, NULL, 10);
1124
1125 bgp_confederation_id_set(bgp, as);
1126
1127 return CMD_SUCCESS;
1128 }
1129
1130 DEFUN (no_bgp_confederation_identifier,
1131 no_bgp_confederation_identifier_cmd,
1132 "no bgp confederation identifier [(1-4294967295)]",
1133 NO_STR
1134 "BGP specific commands\n"
1135 "AS confederation parameters\n"
1136 "AS number\n"
1137 "Set routing domain confederation AS\n")
1138 {
1139 VTY_DECLVAR_CONTEXT(bgp, bgp);
1140 bgp_confederation_id_unset(bgp);
1141
1142 return CMD_SUCCESS;
1143 }
1144
1145 DEFUN (bgp_confederation_peers,
1146 bgp_confederation_peers_cmd,
1147 "bgp confederation peers (1-4294967295)...",
1148 "BGP specific commands\n"
1149 "AS confederation parameters\n"
1150 "Peer ASs in BGP confederation\n"
1151 AS_STR)
1152 {
1153 VTY_DECLVAR_CONTEXT(bgp, bgp);
1154 int idx_asn = 3;
1155 as_t as;
1156 int i;
1157
1158 for (i = idx_asn; i < argc; i++) {
1159 as = strtoul(argv[i]->arg, NULL, 10);
1160
1161 if (bgp->as == as) {
1162 vty_out(vty,
1163 "%% Local member-AS not allowed in confed peer list\n");
1164 continue;
1165 }
1166
1167 bgp_confederation_peers_add(bgp, as);
1168 }
1169 return CMD_SUCCESS;
1170 }
1171
1172 DEFUN (no_bgp_confederation_peers,
1173 no_bgp_confederation_peers_cmd,
1174 "no bgp confederation peers (1-4294967295)...",
1175 NO_STR
1176 "BGP specific commands\n"
1177 "AS confederation parameters\n"
1178 "Peer ASs in BGP confederation\n"
1179 AS_STR)
1180 {
1181 VTY_DECLVAR_CONTEXT(bgp, bgp);
1182 int idx_asn = 4;
1183 as_t as;
1184 int i;
1185
1186 for (i = idx_asn; i < argc; i++) {
1187 as = strtoul(argv[i]->arg, NULL, 10);
1188
1189 bgp_confederation_peers_remove(bgp, as);
1190 }
1191 return CMD_SUCCESS;
1192 }
1193
1194 /**
1195 * Central routine for maximum-paths configuration.
1196 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1197 * @set: 1 for setting values, 0 for removing the max-paths config.
1198 */
1199 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1200 const char *mpaths, uint16_t options,
1201 int set)
1202 {
1203 VTY_DECLVAR_CONTEXT(bgp, bgp);
1204 uint16_t maxpaths = 0;
1205 int ret;
1206 afi_t afi;
1207 safi_t safi;
1208
1209 afi = bgp_node_afi(vty);
1210 safi = bgp_node_safi(vty);
1211
1212 if (set) {
1213 maxpaths = strtol(mpaths, NULL, 10);
1214 if (maxpaths > multipath_num) {
1215 vty_out(vty,
1216 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1217 maxpaths, multipath_num);
1218 return CMD_WARNING_CONFIG_FAILED;
1219 }
1220 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1221 options);
1222 } else
1223 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1224
1225 if (ret < 0) {
1226 vty_out(vty,
1227 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1228 (set == 1) ? "" : "un",
1229 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1230 maxpaths, afi, safi);
1231 return CMD_WARNING_CONFIG_FAILED;
1232 }
1233
1234 bgp_recalculate_all_bestpaths(bgp);
1235
1236 return CMD_SUCCESS;
1237 }
1238
1239 DEFUN (bgp_maxmed_admin,
1240 bgp_maxmed_admin_cmd,
1241 "bgp max-med administrative ",
1242 BGP_STR
1243 "Advertise routes with max-med\n"
1244 "Administratively applied, for an indefinite period\n")
1245 {
1246 VTY_DECLVAR_CONTEXT(bgp, bgp);
1247
1248 bgp->v_maxmed_admin = 1;
1249 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1250
1251 bgp_maxmed_update(bgp);
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 DEFUN (bgp_maxmed_admin_medv,
1257 bgp_maxmed_admin_medv_cmd,
1258 "bgp max-med administrative (0-4294967295)",
1259 BGP_STR
1260 "Advertise routes with max-med\n"
1261 "Administratively applied, for an indefinite period\n"
1262 "Max MED value to be used\n")
1263 {
1264 VTY_DECLVAR_CONTEXT(bgp, bgp);
1265 int idx_number = 3;
1266
1267 bgp->v_maxmed_admin = 1;
1268 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1269
1270 bgp_maxmed_update(bgp);
1271
1272 return CMD_SUCCESS;
1273 }
1274
1275 DEFUN (no_bgp_maxmed_admin,
1276 no_bgp_maxmed_admin_cmd,
1277 "no bgp max-med administrative [(0-4294967295)]",
1278 NO_STR
1279 BGP_STR
1280 "Advertise routes with max-med\n"
1281 "Administratively applied, for an indefinite period\n"
1282 "Max MED value to be used\n")
1283 {
1284 VTY_DECLVAR_CONTEXT(bgp, bgp);
1285 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1286 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1287 bgp_maxmed_update(bgp);
1288
1289 return CMD_SUCCESS;
1290 }
1291
1292 DEFUN (bgp_maxmed_onstartup,
1293 bgp_maxmed_onstartup_cmd,
1294 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1295 BGP_STR
1296 "Advertise routes with max-med\n"
1297 "Effective on a startup\n"
1298 "Time (seconds) period for max-med\n"
1299 "Max MED value to be used\n")
1300 {
1301 VTY_DECLVAR_CONTEXT(bgp, bgp);
1302 int idx = 0;
1303
1304 argv_find(argv, argc, "(5-86400)", &idx);
1305 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1306 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1307 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1308 else
1309 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1310
1311 bgp_maxmed_update(bgp);
1312
1313 return CMD_SUCCESS;
1314 }
1315
1316 DEFUN (no_bgp_maxmed_onstartup,
1317 no_bgp_maxmed_onstartup_cmd,
1318 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1319 NO_STR
1320 BGP_STR
1321 "Advertise routes with max-med\n"
1322 "Effective on a startup\n"
1323 "Time (seconds) period for max-med\n"
1324 "Max MED value to be used\n")
1325 {
1326 VTY_DECLVAR_CONTEXT(bgp, bgp);
1327
1328 /* Cancel max-med onstartup if its on */
1329 if (bgp->t_maxmed_onstartup) {
1330 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1331 bgp->maxmed_onstartup_over = 1;
1332 }
1333
1334 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1335 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1336
1337 bgp_maxmed_update(bgp);
1338
1339 return CMD_SUCCESS;
1340 }
1341
1342 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1343 const char *wait)
1344 {
1345 VTY_DECLVAR_CONTEXT(bgp, bgp);
1346 uint16_t update_delay;
1347 uint16_t establish_wait;
1348
1349 update_delay = strtoul(delay, NULL, 10);
1350
1351 if (!wait) /* update-delay <delay> */
1352 {
1353 bgp->v_update_delay = update_delay;
1354 bgp->v_establish_wait = bgp->v_update_delay;
1355 return CMD_SUCCESS;
1356 }
1357
1358 /* update-delay <delay> <establish-wait> */
1359 establish_wait = atoi(wait);
1360 if (update_delay < establish_wait) {
1361 vty_out(vty,
1362 "%%Failed: update-delay less than the establish-wait!\n");
1363 return CMD_WARNING_CONFIG_FAILED;
1364 }
1365
1366 bgp->v_update_delay = update_delay;
1367 bgp->v_establish_wait = establish_wait;
1368
1369 return CMD_SUCCESS;
1370 }
1371
1372 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1373 {
1374 VTY_DECLVAR_CONTEXT(bgp, bgp);
1375
1376 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1377 bgp->v_establish_wait = bgp->v_update_delay;
1378
1379 return CMD_SUCCESS;
1380 }
1381
1382 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1383 {
1384 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1385 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1386 if (bgp->v_update_delay != bgp->v_establish_wait)
1387 vty_out(vty, " %d", bgp->v_establish_wait);
1388 vty_out(vty, "\n");
1389 }
1390 }
1391
1392
1393 /* Update-delay configuration */
1394 DEFUN (bgp_update_delay,
1395 bgp_update_delay_cmd,
1396 "update-delay (0-3600)",
1397 "Force initial delay for best-path and updates\n"
1398 "Seconds\n")
1399 {
1400 int idx_number = 1;
1401 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1402 }
1403
1404 DEFUN (bgp_update_delay_establish_wait,
1405 bgp_update_delay_establish_wait_cmd,
1406 "update-delay (0-3600) (1-3600)",
1407 "Force initial delay for best-path and updates\n"
1408 "Seconds\n"
1409 "Seconds\n")
1410 {
1411 int idx_number = 1;
1412 int idx_number_2 = 2;
1413 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1414 argv[idx_number_2]->arg);
1415 }
1416
1417 /* Update-delay deconfiguration */
1418 DEFUN (no_bgp_update_delay,
1419 no_bgp_update_delay_cmd,
1420 "no update-delay [(0-3600) [(1-3600)]]",
1421 NO_STR
1422 "Force initial delay for best-path and updates\n"
1423 "Seconds\n"
1424 "Seconds\n")
1425 {
1426 return bgp_update_delay_deconfig_vty(vty);
1427 }
1428
1429
1430 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1431 char set)
1432 {
1433 VTY_DECLVAR_CONTEXT(bgp, bgp);
1434
1435 if (set) {
1436 uint32_t quanta = strtoul(num, NULL, 10);
1437 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1438 memory_order_relaxed);
1439 } else {
1440 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1441 memory_order_relaxed);
1442 }
1443
1444 return CMD_SUCCESS;
1445 }
1446
1447 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1448 char set)
1449 {
1450 VTY_DECLVAR_CONTEXT(bgp, bgp);
1451
1452 if (set) {
1453 uint32_t quanta = strtoul(num, NULL, 10);
1454 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1455 memory_order_relaxed);
1456 } else {
1457 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1458 memory_order_relaxed);
1459 }
1460
1461 return CMD_SUCCESS;
1462 }
1463
1464 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1465 {
1466 uint32_t quanta =
1467 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1468 if (quanta != BGP_WRITE_PACKET_MAX)
1469 vty_out(vty, " write-quanta %d\n", quanta);
1470 }
1471
1472 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1473 {
1474 uint32_t quanta =
1475 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1476 if (quanta != BGP_READ_PACKET_MAX)
1477 vty_out(vty, " read-quanta %d\n", quanta);
1478 }
1479
1480 /* Packet quanta configuration */
1481 DEFUN (bgp_wpkt_quanta,
1482 bgp_wpkt_quanta_cmd,
1483 "write-quanta (1-10)",
1484 "How many packets to write to peer socket per run\n"
1485 "Number of packets\n")
1486 {
1487 int idx_number = 1;
1488 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1489 }
1490
1491 DEFUN (no_bgp_wpkt_quanta,
1492 no_bgp_wpkt_quanta_cmd,
1493 "no write-quanta (1-10)",
1494 NO_STR
1495 "How many packets to write to peer socket per I/O cycle\n"
1496 "Number of packets\n")
1497 {
1498 int idx_number = 2;
1499 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1500 }
1501
1502 DEFUN (bgp_rpkt_quanta,
1503 bgp_rpkt_quanta_cmd,
1504 "read-quanta (1-10)",
1505 "How many packets to read from peer socket per I/O cycle\n"
1506 "Number of packets\n")
1507 {
1508 int idx_number = 1;
1509 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1510 }
1511
1512 DEFUN (no_bgp_rpkt_quanta,
1513 no_bgp_rpkt_quanta_cmd,
1514 "no read-quanta (1-10)",
1515 NO_STR
1516 "How many packets to read from peer socket per I/O cycle\n"
1517 "Number of packets\n")
1518 {
1519 int idx_number = 2;
1520 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1521 }
1522
1523 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1524 {
1525 if (!bgp->heuristic_coalesce)
1526 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1527 }
1528
1529
1530 DEFUN (bgp_coalesce_time,
1531 bgp_coalesce_time_cmd,
1532 "coalesce-time (0-4294967295)",
1533 "Subgroup coalesce timer\n"
1534 "Subgroup coalesce timer value (in ms)\n")
1535 {
1536 VTY_DECLVAR_CONTEXT(bgp, bgp);
1537
1538 int idx = 0;
1539 argv_find(argv, argc, "(0-4294967295)", &idx);
1540 bgp->heuristic_coalesce = false;
1541 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1542 return CMD_SUCCESS;
1543 }
1544
1545 DEFUN (no_bgp_coalesce_time,
1546 no_bgp_coalesce_time_cmd,
1547 "no coalesce-time (0-4294967295)",
1548 NO_STR
1549 "Subgroup coalesce timer\n"
1550 "Subgroup coalesce timer value (in ms)\n")
1551 {
1552 VTY_DECLVAR_CONTEXT(bgp, bgp);
1553
1554 bgp->heuristic_coalesce = true;
1555 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1556 return CMD_SUCCESS;
1557 }
1558
1559 /* Maximum-paths configuration */
1560 DEFUN (bgp_maxpaths,
1561 bgp_maxpaths_cmd,
1562 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1563 "Forward packets over multiple paths\n"
1564 "Number of paths\n")
1565 {
1566 int idx_number = 1;
1567 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1568 argv[idx_number]->arg, 0, 1);
1569 }
1570
1571 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1572 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1573 "Forward packets over multiple paths\n"
1574 "Number of paths\n")
1575
1576 DEFUN (bgp_maxpaths_ibgp,
1577 bgp_maxpaths_ibgp_cmd,
1578 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1579 "Forward packets over multiple paths\n"
1580 "iBGP-multipath\n"
1581 "Number of paths\n")
1582 {
1583 int idx_number = 2;
1584 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1585 argv[idx_number]->arg, 0, 1);
1586 }
1587
1588 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1589 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1590 "Forward packets over multiple paths\n"
1591 "iBGP-multipath\n"
1592 "Number of paths\n")
1593
1594 DEFUN (bgp_maxpaths_ibgp_cluster,
1595 bgp_maxpaths_ibgp_cluster_cmd,
1596 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1597 "Forward packets over multiple paths\n"
1598 "iBGP-multipath\n"
1599 "Number of paths\n"
1600 "Match the cluster length\n")
1601 {
1602 int idx_number = 2;
1603 return bgp_maxpaths_config_vty(
1604 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1605 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1606 }
1607
1608 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1609 "maximum-paths ibgp " CMD_RANGE_STR(
1610 1, MULTIPATH_NUM) " equal-cluster-length",
1611 "Forward packets over multiple paths\n"
1612 "iBGP-multipath\n"
1613 "Number of paths\n"
1614 "Match the cluster length\n")
1615
1616 DEFUN (no_bgp_maxpaths,
1617 no_bgp_maxpaths_cmd,
1618 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1619 NO_STR
1620 "Forward packets over multiple paths\n"
1621 "Number of paths\n")
1622 {
1623 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1624 }
1625
1626 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1627 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1628 "Forward packets over multiple paths\n"
1629 "Number of paths\n")
1630
1631 DEFUN (no_bgp_maxpaths_ibgp,
1632 no_bgp_maxpaths_ibgp_cmd,
1633 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1634 NO_STR
1635 "Forward packets over multiple paths\n"
1636 "iBGP-multipath\n"
1637 "Number of paths\n"
1638 "Match the cluster length\n")
1639 {
1640 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1641 }
1642
1643 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1644 "no maximum-paths ibgp [" CMD_RANGE_STR(
1645 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1646 NO_STR
1647 "Forward packets over multiple paths\n"
1648 "iBGP-multipath\n"
1649 "Number of paths\n"
1650 "Match the cluster length\n")
1651
1652 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1653 safi_t safi)
1654 {
1655 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1656 vty_out(vty, " maximum-paths %d\n",
1657 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1658 }
1659
1660 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1661 vty_out(vty, " maximum-paths ibgp %d",
1662 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1663 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1664 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1665 vty_out(vty, " equal-cluster-length");
1666 vty_out(vty, "\n");
1667 }
1668 }
1669
1670 /* BGP timers. */
1671
1672 DEFUN (bgp_timers,
1673 bgp_timers_cmd,
1674 "timers bgp (0-65535) (0-65535)",
1675 "Adjust routing timers\n"
1676 "BGP timers\n"
1677 "Keepalive interval\n"
1678 "Holdtime\n")
1679 {
1680 VTY_DECLVAR_CONTEXT(bgp, bgp);
1681 int idx_number = 2;
1682 int idx_number_2 = 3;
1683 unsigned long keepalive = 0;
1684 unsigned long holdtime = 0;
1685
1686 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1687 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1688
1689 /* Holdtime value check. */
1690 if (holdtime < 3 && holdtime != 0) {
1691 vty_out(vty,
1692 "%% hold time value must be either 0 or greater than 3\n");
1693 return CMD_WARNING_CONFIG_FAILED;
1694 }
1695
1696 bgp_timers_set(bgp, keepalive, holdtime);
1697
1698 return CMD_SUCCESS;
1699 }
1700
1701 DEFUN (no_bgp_timers,
1702 no_bgp_timers_cmd,
1703 "no timers bgp [(0-65535) (0-65535)]",
1704 NO_STR
1705 "Adjust routing timers\n"
1706 "BGP timers\n"
1707 "Keepalive interval\n"
1708 "Holdtime\n")
1709 {
1710 VTY_DECLVAR_CONTEXT(bgp, bgp);
1711 bgp_timers_unset(bgp);
1712
1713 return CMD_SUCCESS;
1714 }
1715
1716
1717 DEFUN (bgp_client_to_client_reflection,
1718 bgp_client_to_client_reflection_cmd,
1719 "bgp client-to-client reflection",
1720 "BGP specific commands\n"
1721 "Configure client to client route reflection\n"
1722 "reflection of routes allowed\n")
1723 {
1724 VTY_DECLVAR_CONTEXT(bgp, bgp);
1725 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1726 bgp_clear_star_soft_out(vty, bgp->name);
1727
1728 return CMD_SUCCESS;
1729 }
1730
1731 DEFUN (no_bgp_client_to_client_reflection,
1732 no_bgp_client_to_client_reflection_cmd,
1733 "no bgp client-to-client reflection",
1734 NO_STR
1735 "BGP specific commands\n"
1736 "Configure client to client route reflection\n"
1737 "reflection of routes allowed\n")
1738 {
1739 VTY_DECLVAR_CONTEXT(bgp, bgp);
1740 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1741 bgp_clear_star_soft_out(vty, bgp->name);
1742
1743 return CMD_SUCCESS;
1744 }
1745
1746 /* "bgp always-compare-med" configuration. */
1747 DEFUN (bgp_always_compare_med,
1748 bgp_always_compare_med_cmd,
1749 "bgp always-compare-med",
1750 "BGP specific commands\n"
1751 "Allow comparing MED from different neighbors\n")
1752 {
1753 VTY_DECLVAR_CONTEXT(bgp, bgp);
1754 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1755 bgp_recalculate_all_bestpaths(bgp);
1756
1757 return CMD_SUCCESS;
1758 }
1759
1760 DEFUN (no_bgp_always_compare_med,
1761 no_bgp_always_compare_med_cmd,
1762 "no bgp always-compare-med",
1763 NO_STR
1764 "BGP specific commands\n"
1765 "Allow comparing MED from different neighbors\n")
1766 {
1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1769 bgp_recalculate_all_bestpaths(bgp);
1770
1771 return CMD_SUCCESS;
1772 }
1773
1774 /* "bgp deterministic-med" configuration. */
1775 DEFUN (bgp_deterministic_med,
1776 bgp_deterministic_med_cmd,
1777 "bgp deterministic-med",
1778 "BGP specific commands\n"
1779 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1780 {
1781 VTY_DECLVAR_CONTEXT(bgp, bgp);
1782
1783 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1784 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1785 bgp_recalculate_all_bestpaths(bgp);
1786 }
1787
1788 return CMD_SUCCESS;
1789 }
1790
1791 DEFUN (no_bgp_deterministic_med,
1792 no_bgp_deterministic_med_cmd,
1793 "no bgp deterministic-med",
1794 NO_STR
1795 "BGP specific commands\n"
1796 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1797 {
1798 VTY_DECLVAR_CONTEXT(bgp, bgp);
1799 int bestpath_per_as_used;
1800 afi_t afi;
1801 safi_t safi;
1802 struct peer *peer;
1803 struct listnode *node, *nnode;
1804
1805 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1806 bestpath_per_as_used = 0;
1807
1808 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1809 FOREACH_AFI_SAFI (afi, safi)
1810 if (CHECK_FLAG(
1811 peer->af_flags[afi][safi],
1812 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1813 bestpath_per_as_used = 1;
1814 break;
1815 }
1816
1817 if (bestpath_per_as_used)
1818 break;
1819 }
1820
1821 if (bestpath_per_as_used) {
1822 vty_out(vty,
1823 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1824 return CMD_WARNING_CONFIG_FAILED;
1825 } else {
1826 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1827 bgp_recalculate_all_bestpaths(bgp);
1828 }
1829 }
1830
1831 return CMD_SUCCESS;
1832 }
1833
1834 /* "bgp graceful-restart" configuration. */
1835 DEFUN (bgp_graceful_restart,
1836 bgp_graceful_restart_cmd,
1837 "bgp graceful-restart",
1838 "BGP specific commands\n"
1839 "Graceful restart capability parameters\n")
1840 {
1841 VTY_DECLVAR_CONTEXT(bgp, bgp);
1842 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1843 return CMD_SUCCESS;
1844 }
1845
1846 DEFUN (no_bgp_graceful_restart,
1847 no_bgp_graceful_restart_cmd,
1848 "no bgp graceful-restart",
1849 NO_STR
1850 "BGP specific commands\n"
1851 "Graceful restart capability parameters\n")
1852 {
1853 VTY_DECLVAR_CONTEXT(bgp, bgp);
1854 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1855 return CMD_SUCCESS;
1856 }
1857
1858 DEFUN (bgp_graceful_restart_stalepath_time,
1859 bgp_graceful_restart_stalepath_time_cmd,
1860 "bgp graceful-restart stalepath-time (1-3600)",
1861 "BGP specific commands\n"
1862 "Graceful restart capability parameters\n"
1863 "Set the max time to hold onto restarting peer's stale paths\n"
1864 "Delay value (seconds)\n")
1865 {
1866 VTY_DECLVAR_CONTEXT(bgp, bgp);
1867 int idx_number = 3;
1868 uint32_t stalepath;
1869
1870 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1871 bgp->stalepath_time = stalepath;
1872 return CMD_SUCCESS;
1873 }
1874
1875 DEFUN (bgp_graceful_restart_restart_time,
1876 bgp_graceful_restart_restart_time_cmd,
1877 "bgp graceful-restart restart-time (1-3600)",
1878 "BGP specific commands\n"
1879 "Graceful restart capability parameters\n"
1880 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1881 "Delay value (seconds)\n")
1882 {
1883 VTY_DECLVAR_CONTEXT(bgp, bgp);
1884 int idx_number = 3;
1885 uint32_t restart;
1886
1887 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1888 bgp->restart_time = restart;
1889 return CMD_SUCCESS;
1890 }
1891
1892 DEFUN (no_bgp_graceful_restart_stalepath_time,
1893 no_bgp_graceful_restart_stalepath_time_cmd,
1894 "no bgp graceful-restart stalepath-time [(1-3600)]",
1895 NO_STR
1896 "BGP specific commands\n"
1897 "Graceful restart capability parameters\n"
1898 "Set the max time to hold onto restarting peer's stale paths\n"
1899 "Delay value (seconds)\n")
1900 {
1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902
1903 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1904 return CMD_SUCCESS;
1905 }
1906
1907 DEFUN (no_bgp_graceful_restart_restart_time,
1908 no_bgp_graceful_restart_restart_time_cmd,
1909 "no bgp graceful-restart restart-time [(1-3600)]",
1910 NO_STR
1911 "BGP specific commands\n"
1912 "Graceful restart capability parameters\n"
1913 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1914 "Delay value (seconds)\n")
1915 {
1916 VTY_DECLVAR_CONTEXT(bgp, bgp);
1917
1918 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1919 return CMD_SUCCESS;
1920 }
1921
1922 DEFUN (bgp_graceful_restart_preserve_fw,
1923 bgp_graceful_restart_preserve_fw_cmd,
1924 "bgp graceful-restart preserve-fw-state",
1925 "BGP specific commands\n"
1926 "Graceful restart capability parameters\n"
1927 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1928 {
1929 VTY_DECLVAR_CONTEXT(bgp, bgp);
1930 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1931 return CMD_SUCCESS;
1932 }
1933
1934 DEFUN (no_bgp_graceful_restart_preserve_fw,
1935 no_bgp_graceful_restart_preserve_fw_cmd,
1936 "no bgp graceful-restart preserve-fw-state",
1937 NO_STR
1938 "BGP specific commands\n"
1939 "Graceful restart capability parameters\n"
1940 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1941 {
1942 VTY_DECLVAR_CONTEXT(bgp, bgp);
1943 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1944 return CMD_SUCCESS;
1945 }
1946
1947 static void bgp_redistribute_redo(struct bgp *bgp)
1948 {
1949 afi_t afi;
1950 int i;
1951 struct list *red_list;
1952 struct listnode *node;
1953 struct bgp_redist *red;
1954
1955 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1956 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1957
1958 red_list = bgp->redist[afi][i];
1959 if (!red_list)
1960 continue;
1961
1962 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1963 bgp_redistribute_resend(bgp, afi, i,
1964 red->instance);
1965 }
1966 }
1967 }
1968 }
1969
1970 /* "bgp graceful-shutdown" configuration */
1971 DEFUN (bgp_graceful_shutdown,
1972 bgp_graceful_shutdown_cmd,
1973 "bgp graceful-shutdown",
1974 BGP_STR
1975 "Graceful shutdown parameters\n")
1976 {
1977 VTY_DECLVAR_CONTEXT(bgp, bgp);
1978
1979 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1980 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1981 bgp_static_redo_import_check(bgp);
1982 bgp_redistribute_redo(bgp);
1983 bgp_clear_star_soft_out(vty, bgp->name);
1984 bgp_clear_star_soft_in(vty, bgp->name);
1985 }
1986
1987 return CMD_SUCCESS;
1988 }
1989
1990 DEFUN (no_bgp_graceful_shutdown,
1991 no_bgp_graceful_shutdown_cmd,
1992 "no bgp graceful-shutdown",
1993 NO_STR
1994 BGP_STR
1995 "Graceful shutdown parameters\n")
1996 {
1997 VTY_DECLVAR_CONTEXT(bgp, bgp);
1998
1999 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
2000 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
2001 bgp_static_redo_import_check(bgp);
2002 bgp_redistribute_redo(bgp);
2003 bgp_clear_star_soft_out(vty, bgp->name);
2004 bgp_clear_star_soft_in(vty, bgp->name);
2005 }
2006
2007 return CMD_SUCCESS;
2008 }
2009
2010 /* "bgp fast-external-failover" configuration. */
2011 DEFUN (bgp_fast_external_failover,
2012 bgp_fast_external_failover_cmd,
2013 "bgp fast-external-failover",
2014 BGP_STR
2015 "Immediately reset session if a link to a directly connected external peer goes down\n")
2016 {
2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2019 return CMD_SUCCESS;
2020 }
2021
2022 DEFUN (no_bgp_fast_external_failover,
2023 no_bgp_fast_external_failover_cmd,
2024 "no bgp fast-external-failover",
2025 NO_STR
2026 BGP_STR
2027 "Immediately reset session if a link to a directly connected external peer goes down\n")
2028 {
2029 VTY_DECLVAR_CONTEXT(bgp, bgp);
2030 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
2031 return CMD_SUCCESS;
2032 }
2033
2034 /* "bgp enforce-first-as" configuration. */
2035 #if CONFDATE > 20190517
2036 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
2037 #endif
2038
2039 DEFUN_HIDDEN (bgp_enforce_first_as,
2040 bgp_enforce_first_as_cmd,
2041 "[no] bgp enforce-first-as",
2042 NO_STR
2043 BGP_STR
2044 "Enforce the first AS for EBGP routes\n")
2045 {
2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
2047
2048 if (strmatch(argv[0]->text, "no"))
2049 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2050 else
2051 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2052
2053 return CMD_SUCCESS;
2054 }
2055
2056 /* "bgp bestpath compare-routerid" configuration. */
2057 DEFUN (bgp_bestpath_compare_router_id,
2058 bgp_bestpath_compare_router_id_cmd,
2059 "bgp bestpath compare-routerid",
2060 "BGP specific commands\n"
2061 "Change the default bestpath selection\n"
2062 "Compare router-id for identical EBGP paths\n")
2063 {
2064 VTY_DECLVAR_CONTEXT(bgp, bgp);
2065 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2066 bgp_recalculate_all_bestpaths(bgp);
2067
2068 return CMD_SUCCESS;
2069 }
2070
2071 DEFUN (no_bgp_bestpath_compare_router_id,
2072 no_bgp_bestpath_compare_router_id_cmd,
2073 "no bgp bestpath compare-routerid",
2074 NO_STR
2075 "BGP specific commands\n"
2076 "Change the default bestpath selection\n"
2077 "Compare router-id for identical EBGP paths\n")
2078 {
2079 VTY_DECLVAR_CONTEXT(bgp, bgp);
2080 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2081 bgp_recalculate_all_bestpaths(bgp);
2082
2083 return CMD_SUCCESS;
2084 }
2085
2086 /* "bgp bestpath as-path ignore" configuration. */
2087 DEFUN (bgp_bestpath_aspath_ignore,
2088 bgp_bestpath_aspath_ignore_cmd,
2089 "bgp bestpath as-path ignore",
2090 "BGP specific commands\n"
2091 "Change the default bestpath selection\n"
2092 "AS-path attribute\n"
2093 "Ignore as-path length in selecting a route\n")
2094 {
2095 VTY_DECLVAR_CONTEXT(bgp, bgp);
2096 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2097 bgp_recalculate_all_bestpaths(bgp);
2098
2099 return CMD_SUCCESS;
2100 }
2101
2102 DEFUN (no_bgp_bestpath_aspath_ignore,
2103 no_bgp_bestpath_aspath_ignore_cmd,
2104 "no bgp bestpath as-path ignore",
2105 NO_STR
2106 "BGP specific commands\n"
2107 "Change the default bestpath selection\n"
2108 "AS-path attribute\n"
2109 "Ignore as-path length in selecting a route\n")
2110 {
2111 VTY_DECLVAR_CONTEXT(bgp, bgp);
2112 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2113 bgp_recalculate_all_bestpaths(bgp);
2114
2115 return CMD_SUCCESS;
2116 }
2117
2118 /* "bgp bestpath as-path confed" configuration. */
2119 DEFUN (bgp_bestpath_aspath_confed,
2120 bgp_bestpath_aspath_confed_cmd,
2121 "bgp bestpath as-path confed",
2122 "BGP specific commands\n"
2123 "Change the default bestpath selection\n"
2124 "AS-path attribute\n"
2125 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2126 {
2127 VTY_DECLVAR_CONTEXT(bgp, bgp);
2128 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2129 bgp_recalculate_all_bestpaths(bgp);
2130
2131 return CMD_SUCCESS;
2132 }
2133
2134 DEFUN (no_bgp_bestpath_aspath_confed,
2135 no_bgp_bestpath_aspath_confed_cmd,
2136 "no bgp bestpath as-path confed",
2137 NO_STR
2138 "BGP specific commands\n"
2139 "Change the default bestpath selection\n"
2140 "AS-path attribute\n"
2141 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2142 {
2143 VTY_DECLVAR_CONTEXT(bgp, bgp);
2144 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2145 bgp_recalculate_all_bestpaths(bgp);
2146
2147 return CMD_SUCCESS;
2148 }
2149
2150 /* "bgp bestpath as-path multipath-relax" configuration. */
2151 DEFUN (bgp_bestpath_aspath_multipath_relax,
2152 bgp_bestpath_aspath_multipath_relax_cmd,
2153 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2154 "BGP specific commands\n"
2155 "Change the default bestpath selection\n"
2156 "AS-path attribute\n"
2157 "Allow load sharing across routes that have different AS paths (but same length)\n"
2158 "Generate an AS_SET\n"
2159 "Do not generate an AS_SET\n")
2160 {
2161 VTY_DECLVAR_CONTEXT(bgp, bgp);
2162 int idx = 0;
2163 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2164
2165 /* no-as-set is now the default behavior so we can silently
2166 * ignore it */
2167 if (argv_find(argv, argc, "as-set", &idx))
2168 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2169 else
2170 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2171
2172 bgp_recalculate_all_bestpaths(bgp);
2173
2174 return CMD_SUCCESS;
2175 }
2176
2177 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2178 no_bgp_bestpath_aspath_multipath_relax_cmd,
2179 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2180 NO_STR
2181 "BGP specific commands\n"
2182 "Change the default bestpath selection\n"
2183 "AS-path attribute\n"
2184 "Allow load sharing across routes that have different AS paths (but same length)\n"
2185 "Generate an AS_SET\n"
2186 "Do not generate an AS_SET\n")
2187 {
2188 VTY_DECLVAR_CONTEXT(bgp, bgp);
2189 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2190 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2191 bgp_recalculate_all_bestpaths(bgp);
2192
2193 return CMD_SUCCESS;
2194 }
2195
2196 /* "bgp log-neighbor-changes" configuration. */
2197 DEFUN (bgp_log_neighbor_changes,
2198 bgp_log_neighbor_changes_cmd,
2199 "bgp log-neighbor-changes",
2200 "BGP specific commands\n"
2201 "Log neighbor up/down and reset reason\n")
2202 {
2203 VTY_DECLVAR_CONTEXT(bgp, bgp);
2204 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2205 return CMD_SUCCESS;
2206 }
2207
2208 DEFUN (no_bgp_log_neighbor_changes,
2209 no_bgp_log_neighbor_changes_cmd,
2210 "no bgp log-neighbor-changes",
2211 NO_STR
2212 "BGP specific commands\n"
2213 "Log neighbor up/down and reset reason\n")
2214 {
2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2217 return CMD_SUCCESS;
2218 }
2219
2220 /* "bgp bestpath med" configuration. */
2221 DEFUN (bgp_bestpath_med,
2222 bgp_bestpath_med_cmd,
2223 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2224 "BGP specific commands\n"
2225 "Change the default bestpath selection\n"
2226 "MED attribute\n"
2227 "Compare MED among confederation paths\n"
2228 "Treat missing MED as the least preferred one\n"
2229 "Treat missing MED as the least preferred one\n"
2230 "Compare MED among confederation paths\n")
2231 {
2232 VTY_DECLVAR_CONTEXT(bgp, bgp);
2233
2234 int idx = 0;
2235 if (argv_find(argv, argc, "confed", &idx))
2236 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2237 idx = 0;
2238 if (argv_find(argv, argc, "missing-as-worst", &idx))
2239 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2240
2241 bgp_recalculate_all_bestpaths(bgp);
2242
2243 return CMD_SUCCESS;
2244 }
2245
2246 DEFUN (no_bgp_bestpath_med,
2247 no_bgp_bestpath_med_cmd,
2248 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2249 NO_STR
2250 "BGP specific commands\n"
2251 "Change the default bestpath selection\n"
2252 "MED attribute\n"
2253 "Compare MED among confederation paths\n"
2254 "Treat missing MED as the least preferred one\n"
2255 "Treat missing MED as the least preferred one\n"
2256 "Compare MED among confederation paths\n")
2257 {
2258 VTY_DECLVAR_CONTEXT(bgp, bgp);
2259
2260 int idx = 0;
2261 if (argv_find(argv, argc, "confed", &idx))
2262 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2263 idx = 0;
2264 if (argv_find(argv, argc, "missing-as-worst", &idx))
2265 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2266
2267 bgp_recalculate_all_bestpaths(bgp);
2268
2269 return CMD_SUCCESS;
2270 }
2271
2272 /* "no bgp default ipv4-unicast". */
2273 DEFUN (no_bgp_default_ipv4_unicast,
2274 no_bgp_default_ipv4_unicast_cmd,
2275 "no bgp default ipv4-unicast",
2276 NO_STR
2277 "BGP specific commands\n"
2278 "Configure BGP defaults\n"
2279 "Activate ipv4-unicast for a peer by default\n")
2280 {
2281 VTY_DECLVAR_CONTEXT(bgp, bgp);
2282 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2283 return CMD_SUCCESS;
2284 }
2285
2286 DEFUN (bgp_default_ipv4_unicast,
2287 bgp_default_ipv4_unicast_cmd,
2288 "bgp default ipv4-unicast",
2289 "BGP specific commands\n"
2290 "Configure BGP defaults\n"
2291 "Activate ipv4-unicast for a peer by default\n")
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2295 return CMD_SUCCESS;
2296 }
2297
2298 /* Display hostname in certain command outputs */
2299 DEFUN (bgp_default_show_hostname,
2300 bgp_default_show_hostname_cmd,
2301 "bgp default show-hostname",
2302 "BGP specific commands\n"
2303 "Configure BGP defaults\n"
2304 "Show hostname in certain command ouputs\n")
2305 {
2306 VTY_DECLVAR_CONTEXT(bgp, bgp);
2307 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2308 return CMD_SUCCESS;
2309 }
2310
2311 DEFUN (no_bgp_default_show_hostname,
2312 no_bgp_default_show_hostname_cmd,
2313 "no bgp default show-hostname",
2314 NO_STR
2315 "BGP specific commands\n"
2316 "Configure BGP defaults\n"
2317 "Show hostname in certain command ouputs\n")
2318 {
2319 VTY_DECLVAR_CONTEXT(bgp, bgp);
2320 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2321 return CMD_SUCCESS;
2322 }
2323
2324 /* "bgp network import-check" configuration. */
2325 DEFUN (bgp_network_import_check,
2326 bgp_network_import_check_cmd,
2327 "bgp network import-check",
2328 "BGP specific commands\n"
2329 "BGP network command\n"
2330 "Check BGP network route exists in IGP\n")
2331 {
2332 VTY_DECLVAR_CONTEXT(bgp, bgp);
2333 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2334 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2335 bgp_static_redo_import_check(bgp);
2336 }
2337
2338 return CMD_SUCCESS;
2339 }
2340
2341 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2342 "bgp network import-check exact",
2343 "BGP specific commands\n"
2344 "BGP network command\n"
2345 "Check BGP network route exists in IGP\n"
2346 "Match route precisely\n")
2347
2348 DEFUN (no_bgp_network_import_check,
2349 no_bgp_network_import_check_cmd,
2350 "no bgp network import-check",
2351 NO_STR
2352 "BGP specific commands\n"
2353 "BGP network command\n"
2354 "Check BGP network route exists in IGP\n")
2355 {
2356 VTY_DECLVAR_CONTEXT(bgp, bgp);
2357 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2358 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2359 bgp_static_redo_import_check(bgp);
2360 }
2361
2362 return CMD_SUCCESS;
2363 }
2364
2365 DEFUN (bgp_default_local_preference,
2366 bgp_default_local_preference_cmd,
2367 "bgp default local-preference (0-4294967295)",
2368 "BGP specific commands\n"
2369 "Configure BGP defaults\n"
2370 "local preference (higher=more preferred)\n"
2371 "Configure default local preference value\n")
2372 {
2373 VTY_DECLVAR_CONTEXT(bgp, bgp);
2374 int idx_number = 3;
2375 uint32_t local_pref;
2376
2377 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2378
2379 bgp_default_local_preference_set(bgp, local_pref);
2380 bgp_clear_star_soft_in(vty, bgp->name);
2381
2382 return CMD_SUCCESS;
2383 }
2384
2385 DEFUN (no_bgp_default_local_preference,
2386 no_bgp_default_local_preference_cmd,
2387 "no bgp default local-preference [(0-4294967295)]",
2388 NO_STR
2389 "BGP specific commands\n"
2390 "Configure BGP defaults\n"
2391 "local preference (higher=more preferred)\n"
2392 "Configure default local preference value\n")
2393 {
2394 VTY_DECLVAR_CONTEXT(bgp, bgp);
2395 bgp_default_local_preference_unset(bgp);
2396 bgp_clear_star_soft_in(vty, bgp->name);
2397
2398 return CMD_SUCCESS;
2399 }
2400
2401
2402 DEFUN (bgp_default_subgroup_pkt_queue_max,
2403 bgp_default_subgroup_pkt_queue_max_cmd,
2404 "bgp default subgroup-pkt-queue-max (20-100)",
2405 "BGP specific commands\n"
2406 "Configure BGP defaults\n"
2407 "subgroup-pkt-queue-max\n"
2408 "Configure subgroup packet queue max\n")
2409 {
2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411 int idx_number = 3;
2412 uint32_t max_size;
2413
2414 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2415
2416 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2417
2418 return CMD_SUCCESS;
2419 }
2420
2421 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2422 no_bgp_default_subgroup_pkt_queue_max_cmd,
2423 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2424 NO_STR
2425 "BGP specific commands\n"
2426 "Configure BGP defaults\n"
2427 "subgroup-pkt-queue-max\n"
2428 "Configure subgroup packet queue max\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(bgp, bgp);
2431 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2432 return CMD_SUCCESS;
2433 }
2434
2435
2436 DEFUN (bgp_rr_allow_outbound_policy,
2437 bgp_rr_allow_outbound_policy_cmd,
2438 "bgp route-reflector allow-outbound-policy",
2439 "BGP specific commands\n"
2440 "Allow modifications made by out route-map\n"
2441 "on ibgp neighbors\n")
2442 {
2443 VTY_DECLVAR_CONTEXT(bgp, bgp);
2444
2445 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2446 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2447 update_group_announce_rrclients(bgp);
2448 bgp_clear_star_soft_out(vty, bgp->name);
2449 }
2450
2451 return CMD_SUCCESS;
2452 }
2453
2454 DEFUN (no_bgp_rr_allow_outbound_policy,
2455 no_bgp_rr_allow_outbound_policy_cmd,
2456 "no bgp route-reflector allow-outbound-policy",
2457 NO_STR
2458 "BGP specific commands\n"
2459 "Allow modifications made by out route-map\n"
2460 "on ibgp neighbors\n")
2461 {
2462 VTY_DECLVAR_CONTEXT(bgp, bgp);
2463
2464 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2465 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2466 update_group_announce_rrclients(bgp);
2467 bgp_clear_star_soft_out(vty, bgp->name);
2468 }
2469
2470 return CMD_SUCCESS;
2471 }
2472
2473 DEFUN (bgp_listen_limit,
2474 bgp_listen_limit_cmd,
2475 "bgp listen limit (1-5000)",
2476 "BGP specific commands\n"
2477 "Configure BGP defaults\n"
2478 "maximum number of BGP Dynamic Neighbors that can be created\n"
2479 "Configure Dynamic Neighbors listen limit value\n")
2480 {
2481 VTY_DECLVAR_CONTEXT(bgp, bgp);
2482 int idx_number = 3;
2483 int listen_limit;
2484
2485 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2486
2487 bgp_listen_limit_set(bgp, listen_limit);
2488
2489 return CMD_SUCCESS;
2490 }
2491
2492 DEFUN (no_bgp_listen_limit,
2493 no_bgp_listen_limit_cmd,
2494 "no bgp listen limit [(1-5000)]",
2495 "BGP specific commands\n"
2496 "Configure BGP defaults\n"
2497 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2498 "Configure Dynamic Neighbors listen limit value to default\n"
2499 "Configure Dynamic Neighbors listen limit value\n")
2500 {
2501 VTY_DECLVAR_CONTEXT(bgp, bgp);
2502 bgp_listen_limit_unset(bgp);
2503 return CMD_SUCCESS;
2504 }
2505
2506
2507 /*
2508 * Check if this listen range is already configured. Check for exact
2509 * match or overlap based on input.
2510 */
2511 static struct peer_group *listen_range_exists(struct bgp *bgp,
2512 struct prefix *range, int exact)
2513 {
2514 struct listnode *node, *nnode;
2515 struct listnode *node1, *nnode1;
2516 struct peer_group *group;
2517 struct prefix *lr;
2518 afi_t afi;
2519 int match;
2520
2521 afi = family2afi(range->family);
2522 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2523 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2524 lr)) {
2525 if (exact)
2526 match = prefix_same(range, lr);
2527 else
2528 match = (prefix_match(range, lr)
2529 || prefix_match(lr, range));
2530 if (match)
2531 return group;
2532 }
2533 }
2534
2535 return NULL;
2536 }
2537
2538 DEFUN (bgp_listen_range,
2539 bgp_listen_range_cmd,
2540 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2541 "BGP specific commands\n"
2542 "Configure BGP dynamic neighbors listen range\n"
2543 "Configure BGP dynamic neighbors listen range\n"
2544 NEIGHBOR_ADDR_STR
2545 "Member of the peer-group\n"
2546 "Peer-group name\n")
2547 {
2548 VTY_DECLVAR_CONTEXT(bgp, bgp);
2549 struct prefix range;
2550 struct peer_group *group, *existing_group;
2551 afi_t afi;
2552 int ret;
2553 int idx = 0;
2554
2555 argv_find(argv, argc, "A.B.C.D/M", &idx);
2556 argv_find(argv, argc, "X:X::X:X/M", &idx);
2557 char *prefix = argv[idx]->arg;
2558 argv_find(argv, argc, "WORD", &idx);
2559 char *peergroup = argv[idx]->arg;
2560
2561 /* Convert IP prefix string to struct prefix. */
2562 ret = str2prefix(prefix, &range);
2563 if (!ret) {
2564 vty_out(vty, "%% Malformed listen range\n");
2565 return CMD_WARNING_CONFIG_FAILED;
2566 }
2567
2568 afi = family2afi(range.family);
2569
2570 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2571 vty_out(vty,
2572 "%% Malformed listen range (link-local address)\n");
2573 return CMD_WARNING_CONFIG_FAILED;
2574 }
2575
2576 apply_mask(&range);
2577
2578 /* Check if same listen range is already configured. */
2579 existing_group = listen_range_exists(bgp, &range, 1);
2580 if (existing_group) {
2581 if (strcmp(existing_group->name, peergroup) == 0)
2582 return CMD_SUCCESS;
2583 else {
2584 vty_out(vty,
2585 "%% Same listen range is attached to peer-group %s\n",
2586 existing_group->name);
2587 return CMD_WARNING_CONFIG_FAILED;
2588 }
2589 }
2590
2591 /* Check if an overlapping listen range exists. */
2592 if (listen_range_exists(bgp, &range, 0)) {
2593 vty_out(vty,
2594 "%% Listen range overlaps with existing listen range\n");
2595 return CMD_WARNING_CONFIG_FAILED;
2596 }
2597
2598 group = peer_group_lookup(bgp, peergroup);
2599 if (!group) {
2600 vty_out(vty, "%% Configure the peer-group first\n");
2601 return CMD_WARNING_CONFIG_FAILED;
2602 }
2603
2604 ret = peer_group_listen_range_add(group, &range);
2605 return bgp_vty_return(vty, ret);
2606 }
2607
2608 DEFUN (no_bgp_listen_range,
2609 no_bgp_listen_range_cmd,
2610 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2611 NO_STR
2612 "BGP specific commands\n"
2613 "Unconfigure BGP dynamic neighbors listen range\n"
2614 "Unconfigure BGP dynamic neighbors listen range\n"
2615 NEIGHBOR_ADDR_STR
2616 "Member of the peer-group\n"
2617 "Peer-group name\n")
2618 {
2619 VTY_DECLVAR_CONTEXT(bgp, bgp);
2620 struct prefix range;
2621 struct peer_group *group;
2622 afi_t afi;
2623 int ret;
2624 int idx = 0;
2625
2626 argv_find(argv, argc, "A.B.C.D/M", &idx);
2627 argv_find(argv, argc, "X:X::X:X/M", &idx);
2628 char *prefix = argv[idx]->arg;
2629 argv_find(argv, argc, "WORD", &idx);
2630 char *peergroup = argv[idx]->arg;
2631
2632 /* Convert IP prefix string to struct prefix. */
2633 ret = str2prefix(prefix, &range);
2634 if (!ret) {
2635 vty_out(vty, "%% Malformed listen range\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 afi = family2afi(range.family);
2640
2641 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2642 vty_out(vty,
2643 "%% Malformed listen range (link-local address)\n");
2644 return CMD_WARNING_CONFIG_FAILED;
2645 }
2646
2647 apply_mask(&range);
2648
2649 group = peer_group_lookup(bgp, peergroup);
2650 if (!group) {
2651 vty_out(vty, "%% Peer-group does not exist\n");
2652 return CMD_WARNING_CONFIG_FAILED;
2653 }
2654
2655 ret = peer_group_listen_range_del(group, &range);
2656 return bgp_vty_return(vty, ret);
2657 }
2658
2659 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2660 {
2661 struct peer_group *group;
2662 struct listnode *node, *nnode, *rnode, *nrnode;
2663 struct prefix *range;
2664 afi_t afi;
2665 char buf[PREFIX2STR_BUFFER];
2666
2667 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2668 vty_out(vty, " bgp listen limit %d\n",
2669 bgp->dynamic_neighbors_limit);
2670
2671 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2672 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2673 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2674 nrnode, range)) {
2675 prefix2str(range, buf, sizeof(buf));
2676 vty_out(vty,
2677 " bgp listen range %s peer-group %s\n",
2678 buf, group->name);
2679 }
2680 }
2681 }
2682 }
2683
2684
2685 DEFUN (bgp_disable_connected_route_check,
2686 bgp_disable_connected_route_check_cmd,
2687 "bgp disable-ebgp-connected-route-check",
2688 "BGP specific commands\n"
2689 "Disable checking if nexthop is connected on ebgp sessions\n")
2690 {
2691 VTY_DECLVAR_CONTEXT(bgp, bgp);
2692 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2693 bgp_clear_star_soft_in(vty, bgp->name);
2694
2695 return CMD_SUCCESS;
2696 }
2697
2698 DEFUN (no_bgp_disable_connected_route_check,
2699 no_bgp_disable_connected_route_check_cmd,
2700 "no bgp disable-ebgp-connected-route-check",
2701 NO_STR
2702 "BGP specific commands\n"
2703 "Disable checking if nexthop is connected on ebgp sessions\n")
2704 {
2705 VTY_DECLVAR_CONTEXT(bgp, bgp);
2706 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2707 bgp_clear_star_soft_in(vty, bgp->name);
2708
2709 return CMD_SUCCESS;
2710 }
2711
2712
2713 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2714 const char *as_str, afi_t afi, safi_t safi)
2715 {
2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
2717 int ret;
2718 as_t as;
2719 int as_type = AS_SPECIFIED;
2720 union sockunion su;
2721
2722 if (as_str[0] == 'i') {
2723 as = 0;
2724 as_type = AS_INTERNAL;
2725 } else if (as_str[0] == 'e') {
2726 as = 0;
2727 as_type = AS_EXTERNAL;
2728 } else {
2729 /* Get AS number. */
2730 as = strtoul(as_str, NULL, 10);
2731 }
2732
2733 /* If peer is peer group, call proper function. */
2734 ret = str2sockunion(peer_str, &su);
2735 if (ret < 0) {
2736 /* Check for peer by interface */
2737 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2738 safi);
2739 if (ret < 0) {
2740 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2741 if (ret < 0) {
2742 vty_out(vty,
2743 "%% Create the peer-group or interface first\n");
2744 return CMD_WARNING_CONFIG_FAILED;
2745 }
2746 return CMD_SUCCESS;
2747 }
2748 } else {
2749 if (peer_address_self_check(bgp, &su)) {
2750 vty_out(vty,
2751 "%% Can not configure the local system as neighbor\n");
2752 return CMD_WARNING_CONFIG_FAILED;
2753 }
2754 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2755 }
2756
2757 /* This peer belongs to peer group. */
2758 switch (ret) {
2759 case BGP_ERR_PEER_GROUP_MEMBER:
2760 vty_out(vty,
2761 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2762 as);
2763 return CMD_WARNING_CONFIG_FAILED;
2764 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2765 vty_out(vty,
2766 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2767 as, as_str);
2768 return CMD_WARNING_CONFIG_FAILED;
2769 }
2770 return bgp_vty_return(vty, ret);
2771 }
2772
2773 DEFUN (bgp_default_shutdown,
2774 bgp_default_shutdown_cmd,
2775 "[no] bgp default shutdown",
2776 NO_STR
2777 BGP_STR
2778 "Configure BGP defaults\n"
2779 "Apply administrative shutdown to newly configured peers\n")
2780 {
2781 VTY_DECLVAR_CONTEXT(bgp, bgp);
2782 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2783 return CMD_SUCCESS;
2784 }
2785
2786 DEFUN (neighbor_remote_as,
2787 neighbor_remote_as_cmd,
2788 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2789 NEIGHBOR_STR
2790 NEIGHBOR_ADDR_STR2
2791 "Specify a BGP neighbor\n"
2792 AS_STR
2793 "Internal BGP peer\n"
2794 "External BGP peer\n")
2795 {
2796 int idx_peer = 1;
2797 int idx_remote_as = 3;
2798 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2799 argv[idx_remote_as]->arg, AFI_IP,
2800 SAFI_UNICAST);
2801 }
2802
2803 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2804 afi_t afi, safi_t safi, int v6only,
2805 const char *peer_group_name,
2806 const char *as_str)
2807 {
2808 VTY_DECLVAR_CONTEXT(bgp, bgp);
2809 as_t as = 0;
2810 int as_type = AS_UNSPECIFIED;
2811 struct peer *peer;
2812 struct peer_group *group;
2813 int ret = 0;
2814 union sockunion su;
2815
2816 group = peer_group_lookup(bgp, conf_if);
2817
2818 if (group) {
2819 vty_out(vty, "%% Name conflict with peer-group \n");
2820 return CMD_WARNING_CONFIG_FAILED;
2821 }
2822
2823 if (as_str) {
2824 if (as_str[0] == 'i') {
2825 as_type = AS_INTERNAL;
2826 } else if (as_str[0] == 'e') {
2827 as_type = AS_EXTERNAL;
2828 } else {
2829 /* Get AS number. */
2830 as = strtoul(as_str, NULL, 10);
2831 as_type = AS_SPECIFIED;
2832 }
2833 }
2834
2835 peer = peer_lookup_by_conf_if(bgp, conf_if);
2836 if (peer) {
2837 if (as_str)
2838 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2839 afi, safi);
2840 } else {
2841 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2842 && afi == AFI_IP && safi == SAFI_UNICAST)
2843 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2844 as_type, 0, 0, NULL);
2845 else
2846 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2847 as_type, afi, safi, NULL);
2848
2849 if (!peer) {
2850 vty_out(vty, "%% BGP failed to create peer\n");
2851 return CMD_WARNING_CONFIG_FAILED;
2852 }
2853
2854 if (v6only)
2855 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2856
2857 /* Request zebra to initiate IPv6 RAs on this interface. We do
2858 * this
2859 * any unnumbered peer in order to not worry about run-time
2860 * transitions
2861 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2862 * address
2863 * gets deleted later etc.)
2864 */
2865 if (peer->ifp)
2866 bgp_zebra_initiate_radv(bgp, peer);
2867 }
2868
2869 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2870 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2871 if (v6only)
2872 peer_flag_set(peer, PEER_FLAG_IFPEER_V6ONLY);
2873 else
2874 peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY);
2875
2876 /* v6only flag changed. Reset bgp seesion */
2877 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2878 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2879 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2880 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2881 } else
2882 bgp_session_reset(peer);
2883 }
2884
2885 if (!CHECK_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE)) {
2886 SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE);
2887 SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_ENHE);
2888 UNSET_FLAG(peer->flags_override, PEER_FLAG_CAPABILITY_ENHE);
2889 }
2890
2891 if (peer_group_name) {
2892 group = peer_group_lookup(bgp, peer_group_name);
2893 if (!group) {
2894 vty_out(vty, "%% Configure the peer-group first\n");
2895 return CMD_WARNING_CONFIG_FAILED;
2896 }
2897
2898 ret = peer_group_bind(bgp, &su, peer, group, &as);
2899 }
2900
2901 return bgp_vty_return(vty, ret);
2902 }
2903
2904 DEFUN (neighbor_interface_config,
2905 neighbor_interface_config_cmd,
2906 "neighbor WORD interface [peer-group WORD]",
2907 NEIGHBOR_STR
2908 "Interface name or neighbor tag\n"
2909 "Enable BGP on interface\n"
2910 "Member of the peer-group\n"
2911 "Peer-group name\n")
2912 {
2913 int idx_word = 1;
2914 int idx_peer_group_word = 4;
2915
2916 if (argc > idx_peer_group_word)
2917 return peer_conf_interface_get(
2918 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2919 argv[idx_peer_group_word]->arg, NULL);
2920 else
2921 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2922 SAFI_UNICAST, 0, NULL, NULL);
2923 }
2924
2925 DEFUN (neighbor_interface_config_v6only,
2926 neighbor_interface_config_v6only_cmd,
2927 "neighbor WORD interface v6only [peer-group WORD]",
2928 NEIGHBOR_STR
2929 "Interface name or neighbor tag\n"
2930 "Enable BGP on interface\n"
2931 "Enable BGP with v6 link-local only\n"
2932 "Member of the peer-group\n"
2933 "Peer-group name\n")
2934 {
2935 int idx_word = 1;
2936 int idx_peer_group_word = 5;
2937
2938 if (argc > idx_peer_group_word)
2939 return peer_conf_interface_get(
2940 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2941 argv[idx_peer_group_word]->arg, NULL);
2942
2943 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2944 SAFI_UNICAST, 1, NULL, NULL);
2945 }
2946
2947
2948 DEFUN (neighbor_interface_config_remote_as,
2949 neighbor_interface_config_remote_as_cmd,
2950 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2951 NEIGHBOR_STR
2952 "Interface name or neighbor tag\n"
2953 "Enable BGP on interface\n"
2954 "Specify a BGP neighbor\n"
2955 AS_STR
2956 "Internal BGP peer\n"
2957 "External BGP peer\n")
2958 {
2959 int idx_word = 1;
2960 int idx_remote_as = 4;
2961 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2962 SAFI_UNICAST, 0, NULL,
2963 argv[idx_remote_as]->arg);
2964 }
2965
2966 DEFUN (neighbor_interface_v6only_config_remote_as,
2967 neighbor_interface_v6only_config_remote_as_cmd,
2968 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2969 NEIGHBOR_STR
2970 "Interface name or neighbor tag\n"
2971 "Enable BGP with v6 link-local only\n"
2972 "Enable BGP on interface\n"
2973 "Specify a BGP neighbor\n"
2974 AS_STR
2975 "Internal BGP peer\n"
2976 "External BGP peer\n")
2977 {
2978 int idx_word = 1;
2979 int idx_remote_as = 5;
2980 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2981 SAFI_UNICAST, 1, NULL,
2982 argv[idx_remote_as]->arg);
2983 }
2984
2985 DEFUN (neighbor_peer_group,
2986 neighbor_peer_group_cmd,
2987 "neighbor WORD peer-group",
2988 NEIGHBOR_STR
2989 "Interface name or neighbor tag\n"
2990 "Configure peer-group\n")
2991 {
2992 VTY_DECLVAR_CONTEXT(bgp, bgp);
2993 int idx_word = 1;
2994 struct peer *peer;
2995 struct peer_group *group;
2996
2997 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2998 if (peer) {
2999 vty_out(vty, "%% Name conflict with interface: \n");
3000 return CMD_WARNING_CONFIG_FAILED;
3001 }
3002
3003 group = peer_group_get(bgp, argv[idx_word]->arg);
3004 if (!group) {
3005 vty_out(vty, "%% BGP failed to find or create peer-group\n");
3006 return CMD_WARNING_CONFIG_FAILED;
3007 }
3008
3009 return CMD_SUCCESS;
3010 }
3011
3012 DEFUN (no_neighbor,
3013 no_neighbor_cmd,
3014 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
3015 NO_STR
3016 NEIGHBOR_STR
3017 NEIGHBOR_ADDR_STR2
3018 "Specify a BGP neighbor\n"
3019 AS_STR
3020 "Internal BGP peer\n"
3021 "External BGP peer\n")
3022 {
3023 VTY_DECLVAR_CONTEXT(bgp, bgp);
3024 int idx_peer = 2;
3025 int ret;
3026 union sockunion su;
3027 struct peer_group *group;
3028 struct peer *peer;
3029 struct peer *other;
3030
3031 ret = str2sockunion(argv[idx_peer]->arg, &su);
3032 if (ret < 0) {
3033 /* look up for neighbor by interface name config. */
3034 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3035 if (peer) {
3036 /* Request zebra to terminate IPv6 RAs on this
3037 * interface. */
3038 if (peer->ifp)
3039 bgp_zebra_terminate_radv(peer->bgp, peer);
3040 peer_delete(peer);
3041 return CMD_SUCCESS;
3042 }
3043
3044 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3045 if (group)
3046 peer_group_delete(group);
3047 else {
3048 vty_out(vty, "%% Create the peer-group first\n");
3049 return CMD_WARNING_CONFIG_FAILED;
3050 }
3051 } else {
3052 peer = peer_lookup(bgp, &su);
3053 if (peer) {
3054 if (peer_dynamic_neighbor(peer)) {
3055 vty_out(vty,
3056 "%% Operation not allowed on a dynamic neighbor\n");
3057 return CMD_WARNING_CONFIG_FAILED;
3058 }
3059
3060 other = peer->doppelganger;
3061 peer_delete(peer);
3062 if (other && other->status != Deleted)
3063 peer_delete(other);
3064 }
3065 }
3066
3067 return CMD_SUCCESS;
3068 }
3069
3070 DEFUN (no_neighbor_interface_config,
3071 no_neighbor_interface_config_cmd,
3072 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3073 NO_STR
3074 NEIGHBOR_STR
3075 "Interface name\n"
3076 "Configure BGP on interface\n"
3077 "Enable BGP with v6 link-local only\n"
3078 "Member of the peer-group\n"
3079 "Peer-group name\n"
3080 "Specify a BGP neighbor\n"
3081 AS_STR
3082 "Internal BGP peer\n"
3083 "External BGP peer\n")
3084 {
3085 VTY_DECLVAR_CONTEXT(bgp, bgp);
3086 int idx_word = 2;
3087 struct peer *peer;
3088
3089 /* look up for neighbor by interface name config. */
3090 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3091 if (peer) {
3092 /* Request zebra to terminate IPv6 RAs on this interface. */
3093 if (peer->ifp)
3094 bgp_zebra_terminate_radv(peer->bgp, peer);
3095 peer_delete(peer);
3096 } else {
3097 vty_out(vty, "%% Create the bgp interface first\n");
3098 return CMD_WARNING_CONFIG_FAILED;
3099 }
3100 return CMD_SUCCESS;
3101 }
3102
3103 DEFUN (no_neighbor_peer_group,
3104 no_neighbor_peer_group_cmd,
3105 "no neighbor WORD peer-group",
3106 NO_STR
3107 NEIGHBOR_STR
3108 "Neighbor tag\n"
3109 "Configure peer-group\n")
3110 {
3111 VTY_DECLVAR_CONTEXT(bgp, bgp);
3112 int idx_word = 2;
3113 struct peer_group *group;
3114
3115 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3116 if (group)
3117 peer_group_delete(group);
3118 else {
3119 vty_out(vty, "%% Create the peer-group first\n");
3120 return CMD_WARNING_CONFIG_FAILED;
3121 }
3122 return CMD_SUCCESS;
3123 }
3124
3125 DEFUN (no_neighbor_interface_peer_group_remote_as,
3126 no_neighbor_interface_peer_group_remote_as_cmd,
3127 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3128 NO_STR
3129 NEIGHBOR_STR
3130 "Interface name or neighbor tag\n"
3131 "Specify a BGP neighbor\n"
3132 AS_STR
3133 "Internal BGP peer\n"
3134 "External BGP peer\n")
3135 {
3136 VTY_DECLVAR_CONTEXT(bgp, bgp);
3137 int idx_word = 2;
3138 struct peer_group *group;
3139 struct peer *peer;
3140
3141 /* look up for neighbor by interface name config. */
3142 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3143 if (peer) {
3144 peer_as_change(peer, 0, AS_SPECIFIED);
3145 return CMD_SUCCESS;
3146 }
3147
3148 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3149 if (group)
3150 peer_group_remote_as_delete(group);
3151 else {
3152 vty_out(vty, "%% Create the peer-group or interface first\n");
3153 return CMD_WARNING_CONFIG_FAILED;
3154 }
3155 return CMD_SUCCESS;
3156 }
3157
3158 DEFUN (neighbor_local_as,
3159 neighbor_local_as_cmd,
3160 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3161 NEIGHBOR_STR
3162 NEIGHBOR_ADDR_STR2
3163 "Specify a local-as number\n"
3164 "AS number used as local AS\n")
3165 {
3166 int idx_peer = 1;
3167 int idx_number = 3;
3168 struct peer *peer;
3169 int ret;
3170 as_t as;
3171
3172 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3173 if (!peer)
3174 return CMD_WARNING_CONFIG_FAILED;
3175
3176 as = strtoul(argv[idx_number]->arg, NULL, 10);
3177 ret = peer_local_as_set(peer, as, 0, 0);
3178 return bgp_vty_return(vty, ret);
3179 }
3180
3181 DEFUN (neighbor_local_as_no_prepend,
3182 neighbor_local_as_no_prepend_cmd,
3183 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3184 NEIGHBOR_STR
3185 NEIGHBOR_ADDR_STR2
3186 "Specify a local-as number\n"
3187 "AS number used as local AS\n"
3188 "Do not prepend local-as to updates from ebgp peers\n")
3189 {
3190 int idx_peer = 1;
3191 int idx_number = 3;
3192 struct peer *peer;
3193 int ret;
3194 as_t as;
3195
3196 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3197 if (!peer)
3198 return CMD_WARNING_CONFIG_FAILED;
3199
3200 as = strtoul(argv[idx_number]->arg, NULL, 10);
3201 ret = peer_local_as_set(peer, as, 1, 0);
3202 return bgp_vty_return(vty, ret);
3203 }
3204
3205 DEFUN (neighbor_local_as_no_prepend_replace_as,
3206 neighbor_local_as_no_prepend_replace_as_cmd,
3207 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3208 NEIGHBOR_STR
3209 NEIGHBOR_ADDR_STR2
3210 "Specify a local-as number\n"
3211 "AS number used as local AS\n"
3212 "Do not prepend local-as to updates from ebgp peers\n"
3213 "Do not prepend local-as to updates from ibgp peers\n")
3214 {
3215 int idx_peer = 1;
3216 int idx_number = 3;
3217 struct peer *peer;
3218 int ret;
3219 as_t as;
3220
3221 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3222 if (!peer)
3223 return CMD_WARNING_CONFIG_FAILED;
3224
3225 as = strtoul(argv[idx_number]->arg, NULL, 10);
3226 ret = peer_local_as_set(peer, as, 1, 1);
3227 return bgp_vty_return(vty, ret);
3228 }
3229
3230 DEFUN (no_neighbor_local_as,
3231 no_neighbor_local_as_cmd,
3232 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3233 NO_STR
3234 NEIGHBOR_STR
3235 NEIGHBOR_ADDR_STR2
3236 "Specify a local-as number\n"
3237 "AS number used as local AS\n"
3238 "Do not prepend local-as to updates from ebgp peers\n"
3239 "Do not prepend local-as to updates from ibgp peers\n")
3240 {
3241 int idx_peer = 2;
3242 struct peer *peer;
3243 int ret;
3244
3245 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3246 if (!peer)
3247 return CMD_WARNING_CONFIG_FAILED;
3248
3249 ret = peer_local_as_unset(peer);
3250 return bgp_vty_return(vty, ret);
3251 }
3252
3253
3254 DEFUN (neighbor_solo,
3255 neighbor_solo_cmd,
3256 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 "Solo peer - part of its own update group\n")
3260 {
3261 int idx_peer = 1;
3262 struct peer *peer;
3263 int ret;
3264
3265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3266 if (!peer)
3267 return CMD_WARNING_CONFIG_FAILED;
3268
3269 ret = update_group_adjust_soloness(peer, 1);
3270 return bgp_vty_return(vty, ret);
3271 }
3272
3273 DEFUN (no_neighbor_solo,
3274 no_neighbor_solo_cmd,
3275 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3276 NO_STR
3277 NEIGHBOR_STR
3278 NEIGHBOR_ADDR_STR2
3279 "Solo peer - part of its own update group\n")
3280 {
3281 int idx_peer = 2;
3282 struct peer *peer;
3283 int ret;
3284
3285 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3286 if (!peer)
3287 return CMD_WARNING_CONFIG_FAILED;
3288
3289 ret = update_group_adjust_soloness(peer, 0);
3290 return bgp_vty_return(vty, ret);
3291 }
3292
3293 DEFUN (neighbor_password,
3294 neighbor_password_cmd,
3295 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3296 NEIGHBOR_STR
3297 NEIGHBOR_ADDR_STR2
3298 "Set a password\n"
3299 "The password\n")
3300 {
3301 int idx_peer = 1;
3302 int idx_line = 3;
3303 struct peer *peer;
3304 int ret;
3305
3306 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3307 if (!peer)
3308 return CMD_WARNING_CONFIG_FAILED;
3309
3310 ret = peer_password_set(peer, argv[idx_line]->arg);
3311 return bgp_vty_return(vty, ret);
3312 }
3313
3314 DEFUN (no_neighbor_password,
3315 no_neighbor_password_cmd,
3316 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3317 NO_STR
3318 NEIGHBOR_STR
3319 NEIGHBOR_ADDR_STR2
3320 "Set a password\n"
3321 "The password\n")
3322 {
3323 int idx_peer = 2;
3324 struct peer *peer;
3325 int ret;
3326
3327 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3328 if (!peer)
3329 return CMD_WARNING_CONFIG_FAILED;
3330
3331 ret = peer_password_unset(peer);
3332 return bgp_vty_return(vty, ret);
3333 }
3334
3335 DEFUN (neighbor_activate,
3336 neighbor_activate_cmd,
3337 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3338 NEIGHBOR_STR
3339 NEIGHBOR_ADDR_STR2
3340 "Enable the Address Family for this Neighbor\n")
3341 {
3342 int idx_peer = 1;
3343 int ret;
3344 struct peer *peer;
3345
3346 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3347 if (!peer)
3348 return CMD_WARNING_CONFIG_FAILED;
3349
3350 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3351 return bgp_vty_return(vty, ret);
3352 }
3353
3354 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3355 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3356 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3357 "Enable the Address Family for this Neighbor\n")
3358
3359 DEFUN (no_neighbor_activate,
3360 no_neighbor_activate_cmd,
3361 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3362 NO_STR
3363 NEIGHBOR_STR
3364 NEIGHBOR_ADDR_STR2
3365 "Enable the Address Family for this Neighbor\n")
3366 {
3367 int idx_peer = 2;
3368 int ret;
3369 struct peer *peer;
3370
3371 /* Lookup peer. */
3372 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3373 if (!peer)
3374 return CMD_WARNING_CONFIG_FAILED;
3375
3376 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3377 return bgp_vty_return(vty, ret);
3378 }
3379
3380 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3381 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3382 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3383 "Enable the Address Family for this Neighbor\n")
3384
3385 DEFUN (neighbor_set_peer_group,
3386 neighbor_set_peer_group_cmd,
3387 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3388 NEIGHBOR_STR
3389 NEIGHBOR_ADDR_STR2
3390 "Member of the peer-group\n"
3391 "Peer-group name\n")
3392 {
3393 VTY_DECLVAR_CONTEXT(bgp, bgp);
3394 int idx_peer = 1;
3395 int idx_word = 3;
3396 int ret;
3397 as_t as;
3398 union sockunion su;
3399 struct peer *peer;
3400 struct peer_group *group;
3401
3402 ret = str2sockunion(argv[idx_peer]->arg, &su);
3403 if (ret < 0) {
3404 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3405 if (!peer) {
3406 vty_out(vty, "%% Malformed address or name: %s\n",
3407 argv[idx_peer]->arg);
3408 return CMD_WARNING_CONFIG_FAILED;
3409 }
3410 } else {
3411 if (peer_address_self_check(bgp, &su)) {
3412 vty_out(vty,
3413 "%% Can not configure the local system as neighbor\n");
3414 return CMD_WARNING_CONFIG_FAILED;
3415 }
3416
3417 /* Disallow for dynamic neighbor. */
3418 peer = peer_lookup(bgp, &su);
3419 if (peer && peer_dynamic_neighbor(peer)) {
3420 vty_out(vty,
3421 "%% Operation not allowed on a dynamic neighbor\n");
3422 return CMD_WARNING_CONFIG_FAILED;
3423 }
3424 }
3425
3426 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3427 if (!group) {
3428 vty_out(vty, "%% Configure the peer-group first\n");
3429 return CMD_WARNING_CONFIG_FAILED;
3430 }
3431
3432 ret = peer_group_bind(bgp, &su, peer, group, &as);
3433
3434 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3435 vty_out(vty,
3436 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3437 as);
3438 return CMD_WARNING_CONFIG_FAILED;
3439 }
3440
3441 return bgp_vty_return(vty, ret);
3442 }
3443
3444 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3445 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3446 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3447 "Member of the peer-group\n"
3448 "Peer-group name\n")
3449
3450 DEFUN (no_neighbor_set_peer_group,
3451 no_neighbor_set_peer_group_cmd,
3452 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3453 NO_STR
3454 NEIGHBOR_STR
3455 NEIGHBOR_ADDR_STR2
3456 "Member of the peer-group\n"
3457 "Peer-group name\n")
3458 {
3459 VTY_DECLVAR_CONTEXT(bgp, bgp);
3460 int idx_peer = 2;
3461 int idx_word = 4;
3462 int ret;
3463 struct peer *peer;
3464 struct peer_group *group;
3465
3466 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3467 if (!peer)
3468 return CMD_WARNING_CONFIG_FAILED;
3469
3470 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3471 if (!group) {
3472 vty_out(vty, "%% Configure the peer-group first\n");
3473 return CMD_WARNING_CONFIG_FAILED;
3474 }
3475
3476 ret = peer_delete(peer);
3477
3478 return bgp_vty_return(vty, ret);
3479 }
3480
3481 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3482 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3483 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3484 "Member of the peer-group\n"
3485 "Peer-group name\n")
3486
3487 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3488 uint32_t flag, int set)
3489 {
3490 int ret;
3491 struct peer *peer;
3492
3493 peer = peer_and_group_lookup_vty(vty, ip_str);
3494 if (!peer)
3495 return CMD_WARNING_CONFIG_FAILED;
3496
3497 /*
3498 * If 'neighbor <interface>', then this is for directly connected peers,
3499 * we should not accept disable-connected-check.
3500 */
3501 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3502 vty_out(vty,
3503 "%s is directly connected peer, cannot accept disable-"
3504 "connected-check\n",
3505 ip_str);
3506 return CMD_WARNING_CONFIG_FAILED;
3507 }
3508
3509 if (!set && flag == PEER_FLAG_SHUTDOWN)
3510 peer_tx_shutdown_message_unset(peer);
3511
3512 if (set)
3513 ret = peer_flag_set(peer, flag);
3514 else
3515 ret = peer_flag_unset(peer, flag);
3516
3517 return bgp_vty_return(vty, ret);
3518 }
3519
3520 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3521 {
3522 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3523 }
3524
3525 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3526 uint32_t flag)
3527 {
3528 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3529 }
3530
3531 /* neighbor passive. */
3532 DEFUN (neighbor_passive,
3533 neighbor_passive_cmd,
3534 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3535 NEIGHBOR_STR
3536 NEIGHBOR_ADDR_STR2
3537 "Don't send open messages to this neighbor\n")
3538 {
3539 int idx_peer = 1;
3540 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3541 }
3542
3543 DEFUN (no_neighbor_passive,
3544 no_neighbor_passive_cmd,
3545 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3546 NO_STR
3547 NEIGHBOR_STR
3548 NEIGHBOR_ADDR_STR2
3549 "Don't send open messages to this neighbor\n")
3550 {
3551 int idx_peer = 2;
3552 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3553 }
3554
3555 /* neighbor shutdown. */
3556 DEFUN (neighbor_shutdown_msg,
3557 neighbor_shutdown_msg_cmd,
3558 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3559 NEIGHBOR_STR
3560 NEIGHBOR_ADDR_STR2
3561 "Administratively shut down this neighbor\n"
3562 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3563 "Shutdown message\n")
3564 {
3565 int idx_peer = 1;
3566
3567 if (argc >= 5) {
3568 struct peer *peer =
3569 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3570 char *message;
3571
3572 if (!peer)
3573 return CMD_WARNING_CONFIG_FAILED;
3574 message = argv_concat(argv, argc, 4);
3575 peer_tx_shutdown_message_set(peer, message);
3576 XFREE(MTYPE_TMP, message);
3577 }
3578
3579 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3580 }
3581
3582 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3583 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3584 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3585 "Administratively shut down this neighbor\n")
3586
3587 DEFUN (no_neighbor_shutdown_msg,
3588 no_neighbor_shutdown_msg_cmd,
3589 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3590 NO_STR
3591 NEIGHBOR_STR
3592 NEIGHBOR_ADDR_STR2
3593 "Administratively shut down this neighbor\n"
3594 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3595 "Shutdown message\n")
3596 {
3597 int idx_peer = 2;
3598
3599 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3600 PEER_FLAG_SHUTDOWN);
3601 }
3602
3603 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3604 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3605 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3606 "Administratively shut down this neighbor\n")
3607
3608 /* neighbor capability dynamic. */
3609 DEFUN (neighbor_capability_dynamic,
3610 neighbor_capability_dynamic_cmd,
3611 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3612 NEIGHBOR_STR
3613 NEIGHBOR_ADDR_STR2
3614 "Advertise capability to the peer\n"
3615 "Advertise dynamic capability to this neighbor\n")
3616 {
3617 int idx_peer = 1;
3618 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3619 PEER_FLAG_DYNAMIC_CAPABILITY);
3620 }
3621
3622 DEFUN (no_neighbor_capability_dynamic,
3623 no_neighbor_capability_dynamic_cmd,
3624 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3625 NO_STR
3626 NEIGHBOR_STR
3627 NEIGHBOR_ADDR_STR2
3628 "Advertise capability to the peer\n"
3629 "Advertise dynamic capability to this neighbor\n")
3630 {
3631 int idx_peer = 2;
3632 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3633 PEER_FLAG_DYNAMIC_CAPABILITY);
3634 }
3635
3636 /* neighbor dont-capability-negotiate */
3637 DEFUN (neighbor_dont_capability_negotiate,
3638 neighbor_dont_capability_negotiate_cmd,
3639 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3640 NEIGHBOR_STR
3641 NEIGHBOR_ADDR_STR2
3642 "Do not perform capability negotiation\n")
3643 {
3644 int idx_peer = 1;
3645 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3646 PEER_FLAG_DONT_CAPABILITY);
3647 }
3648
3649 DEFUN (no_neighbor_dont_capability_negotiate,
3650 no_neighbor_dont_capability_negotiate_cmd,
3651 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3652 NO_STR
3653 NEIGHBOR_STR
3654 NEIGHBOR_ADDR_STR2
3655 "Do not perform capability negotiation\n")
3656 {
3657 int idx_peer = 2;
3658 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3659 PEER_FLAG_DONT_CAPABILITY);
3660 }
3661
3662 /* neighbor capability extended next hop encoding */
3663 DEFUN (neighbor_capability_enhe,
3664 neighbor_capability_enhe_cmd,
3665 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3666 NEIGHBOR_STR
3667 NEIGHBOR_ADDR_STR2
3668 "Advertise capability to the peer\n"
3669 "Advertise extended next-hop capability to the peer\n")
3670 {
3671 int idx_peer = 1;
3672 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3673 PEER_FLAG_CAPABILITY_ENHE);
3674 }
3675
3676 DEFUN (no_neighbor_capability_enhe,
3677 no_neighbor_capability_enhe_cmd,
3678 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3679 NO_STR
3680 NEIGHBOR_STR
3681 NEIGHBOR_ADDR_STR2
3682 "Advertise capability to the peer\n"
3683 "Advertise extended next-hop capability to the peer\n")
3684 {
3685 int idx_peer = 2;
3686 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3687 PEER_FLAG_CAPABILITY_ENHE);
3688 }
3689
3690 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3691 afi_t afi, safi_t safi, uint32_t flag,
3692 int set)
3693 {
3694 int ret;
3695 struct peer *peer;
3696
3697 peer = peer_and_group_lookup_vty(vty, peer_str);
3698 if (!peer)
3699 return CMD_WARNING_CONFIG_FAILED;
3700
3701 if (set)
3702 ret = peer_af_flag_set(peer, afi, safi, flag);
3703 else
3704 ret = peer_af_flag_unset(peer, afi, safi, flag);
3705
3706 return bgp_vty_return(vty, ret);
3707 }
3708
3709 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3710 afi_t afi, safi_t safi, uint32_t flag)
3711 {
3712 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3713 }
3714
3715 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3716 afi_t afi, safi_t safi, uint32_t flag)
3717 {
3718 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3719 }
3720
3721 /* neighbor capability orf prefix-list. */
3722 DEFUN (neighbor_capability_orf_prefix,
3723 neighbor_capability_orf_prefix_cmd,
3724 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3725 NEIGHBOR_STR
3726 NEIGHBOR_ADDR_STR2
3727 "Advertise capability to the peer\n"
3728 "Advertise ORF capability to the peer\n"
3729 "Advertise prefixlist ORF capability to this neighbor\n"
3730 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3731 "Capability to RECEIVE the ORF from this neighbor\n"
3732 "Capability to SEND the ORF to this neighbor\n")
3733 {
3734 int idx_peer = 1;
3735 int idx_send_recv = 5;
3736 uint16_t flag = 0;
3737
3738 if (strmatch(argv[idx_send_recv]->text, "send"))
3739 flag = PEER_FLAG_ORF_PREFIX_SM;
3740 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3741 flag = PEER_FLAG_ORF_PREFIX_RM;
3742 else if (strmatch(argv[idx_send_recv]->text, "both"))
3743 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3744 else {
3745 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3746 return CMD_WARNING_CONFIG_FAILED;
3747 }
3748
3749 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3750 bgp_node_safi(vty), flag);
3751 }
3752
3753 ALIAS_HIDDEN(
3754 neighbor_capability_orf_prefix,
3755 neighbor_capability_orf_prefix_hidden_cmd,
3756 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3757 NEIGHBOR_STR 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 DEFUN (no_neighbor_capability_orf_prefix,
3766 no_neighbor_capability_orf_prefix_cmd,
3767 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3768 NO_STR
3769 NEIGHBOR_STR
3770 NEIGHBOR_ADDR_STR2
3771 "Advertise capability to the peer\n"
3772 "Advertise ORF capability to the peer\n"
3773 "Advertise prefixlist ORF capability to this neighbor\n"
3774 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3775 "Capability to RECEIVE the ORF from this neighbor\n"
3776 "Capability to SEND the ORF to this neighbor\n")
3777 {
3778 int idx_peer = 2;
3779 int idx_send_recv = 6;
3780 uint16_t flag = 0;
3781
3782 if (strmatch(argv[idx_send_recv]->text, "send"))
3783 flag = PEER_FLAG_ORF_PREFIX_SM;
3784 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3785 flag = PEER_FLAG_ORF_PREFIX_RM;
3786 else if (strmatch(argv[idx_send_recv]->text, "both"))
3787 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3788 else {
3789 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3790 return CMD_WARNING_CONFIG_FAILED;
3791 }
3792
3793 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3794 bgp_node_afi(vty), bgp_node_safi(vty),
3795 flag);
3796 }
3797
3798 ALIAS_HIDDEN(
3799 no_neighbor_capability_orf_prefix,
3800 no_neighbor_capability_orf_prefix_hidden_cmd,
3801 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3802 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3803 "Advertise capability to the peer\n"
3804 "Advertise ORF capability to the peer\n"
3805 "Advertise prefixlist ORF capability to this neighbor\n"
3806 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3807 "Capability to RECEIVE the ORF from this neighbor\n"
3808 "Capability to SEND the ORF to this neighbor\n")
3809
3810 /* neighbor next-hop-self. */
3811 DEFUN (neighbor_nexthop_self,
3812 neighbor_nexthop_self_cmd,
3813 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3814 NEIGHBOR_STR
3815 NEIGHBOR_ADDR_STR2
3816 "Disable the next hop calculation for this neighbor\n")
3817 {
3818 int idx_peer = 1;
3819 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3820 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3821 }
3822
3823 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3824 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3825 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3826 "Disable the next hop calculation for this neighbor\n")
3827
3828 /* neighbor next-hop-self. */
3829 DEFUN (neighbor_nexthop_self_force,
3830 neighbor_nexthop_self_force_cmd,
3831 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3832 NEIGHBOR_STR
3833 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 int idx_peer = 1;
3838 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3839 bgp_node_safi(vty),
3840 PEER_FLAG_FORCE_NEXTHOP_SELF);
3841 }
3842
3843 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3844 neighbor_nexthop_self_force_hidden_cmd,
3845 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3846 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3847 "Disable the next hop calculation for this neighbor\n"
3848 "Set the next hop to self for reflected routes\n")
3849
3850 DEFUN (no_neighbor_nexthop_self,
3851 no_neighbor_nexthop_self_cmd,
3852 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3853 NO_STR
3854 NEIGHBOR_STR
3855 NEIGHBOR_ADDR_STR2
3856 "Disable the next hop calculation for this neighbor\n")
3857 {
3858 int idx_peer = 2;
3859 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3860 bgp_node_afi(vty), bgp_node_safi(vty),
3861 PEER_FLAG_NEXTHOP_SELF);
3862 }
3863
3864 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3865 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3867 "Disable the next hop calculation for this neighbor\n")
3868
3869 DEFUN (no_neighbor_nexthop_self_force,
3870 no_neighbor_nexthop_self_force_cmd,
3871 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3872 NO_STR
3873 NEIGHBOR_STR
3874 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 int idx_peer = 2;
3879 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3880 bgp_node_afi(vty), bgp_node_safi(vty),
3881 PEER_FLAG_FORCE_NEXTHOP_SELF);
3882 }
3883
3884 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3885 no_neighbor_nexthop_self_force_hidden_cmd,
3886 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3887 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3888 "Disable the next hop calculation for this neighbor\n"
3889 "Set the next hop to self for reflected routes\n")
3890
3891 /* neighbor as-override */
3892 DEFUN (neighbor_as_override,
3893 neighbor_as_override_cmd,
3894 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3895 NEIGHBOR_STR
3896 NEIGHBOR_ADDR_STR2
3897 "Override ASNs in outbound updates if aspath equals remote-as\n")
3898 {
3899 int idx_peer = 1;
3900 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3901 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3902 }
3903
3904 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3905 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3906 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3907 "Override ASNs in outbound updates if aspath equals remote-as\n")
3908
3909 DEFUN (no_neighbor_as_override,
3910 no_neighbor_as_override_cmd,
3911 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3912 NO_STR
3913 NEIGHBOR_STR
3914 NEIGHBOR_ADDR_STR2
3915 "Override ASNs in outbound updates if aspath equals remote-as\n")
3916 {
3917 int idx_peer = 2;
3918 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3919 bgp_node_afi(vty), bgp_node_safi(vty),
3920 PEER_FLAG_AS_OVERRIDE);
3921 }
3922
3923 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3924 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3925 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3926 "Override ASNs in outbound updates if aspath equals remote-as\n")
3927
3928 /* neighbor remove-private-AS. */
3929 DEFUN (neighbor_remove_private_as,
3930 neighbor_remove_private_as_cmd,
3931 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3932 NEIGHBOR_STR
3933 NEIGHBOR_ADDR_STR2
3934 "Remove private ASNs in outbound updates\n")
3935 {
3936 int idx_peer = 1;
3937 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3938 bgp_node_safi(vty),
3939 PEER_FLAG_REMOVE_PRIVATE_AS);
3940 }
3941
3942 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3943 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3944 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3945 "Remove private ASNs in outbound updates\n")
3946
3947 DEFUN (neighbor_remove_private_as_all,
3948 neighbor_remove_private_as_all_cmd,
3949 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3950 NEIGHBOR_STR
3951 NEIGHBOR_ADDR_STR2
3952 "Remove private ASNs in outbound updates\n"
3953 "Apply to all AS numbers\n")
3954 {
3955 int idx_peer = 1;
3956 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3957 bgp_node_safi(vty),
3958 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3959 }
3960
3961 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3962 neighbor_remove_private_as_all_hidden_cmd,
3963 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3964 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3965 "Remove private ASNs in outbound updates\n"
3966 "Apply to all AS numbers")
3967
3968 DEFUN (neighbor_remove_private_as_replace_as,
3969 neighbor_remove_private_as_replace_as_cmd,
3970 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3971 NEIGHBOR_STR
3972 NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
3974 "Replace private ASNs with our ASN in outbound updates\n")
3975 {
3976 int idx_peer = 1;
3977 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3978 bgp_node_safi(vty),
3979 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3980 }
3981
3982 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3983 neighbor_remove_private_as_replace_as_hidden_cmd,
3984 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3985 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3986 "Remove private ASNs in outbound updates\n"
3987 "Replace private ASNs with our ASN in outbound updates\n")
3988
3989 DEFUN (neighbor_remove_private_as_all_replace_as,
3990 neighbor_remove_private_as_all_replace_as_cmd,
3991 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3992 NEIGHBOR_STR
3993 NEIGHBOR_ADDR_STR2
3994 "Remove private ASNs in outbound updates\n"
3995 "Apply to all AS numbers\n"
3996 "Replace private ASNs with our ASN in outbound updates\n")
3997 {
3998 int idx_peer = 1;
3999 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4000 bgp_node_safi(vty),
4001 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4002 }
4003
4004 ALIAS_HIDDEN(
4005 neighbor_remove_private_as_all_replace_as,
4006 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4007 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4008 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4009 "Remove private ASNs in outbound updates\n"
4010 "Apply to all AS numbers\n"
4011 "Replace private ASNs with our ASN in outbound updates\n")
4012
4013 DEFUN (no_neighbor_remove_private_as,
4014 no_neighbor_remove_private_as_cmd,
4015 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4016 NO_STR
4017 NEIGHBOR_STR
4018 NEIGHBOR_ADDR_STR2
4019 "Remove private ASNs in outbound updates\n")
4020 {
4021 int idx_peer = 2;
4022 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4023 bgp_node_afi(vty), bgp_node_safi(vty),
4024 PEER_FLAG_REMOVE_PRIVATE_AS);
4025 }
4026
4027 ALIAS_HIDDEN(no_neighbor_remove_private_as,
4028 no_neighbor_remove_private_as_hidden_cmd,
4029 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4030 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4031 "Remove private ASNs in outbound updates\n")
4032
4033 DEFUN (no_neighbor_remove_private_as_all,
4034 no_neighbor_remove_private_as_all_cmd,
4035 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4036 NO_STR
4037 NEIGHBOR_STR
4038 NEIGHBOR_ADDR_STR2
4039 "Remove private ASNs in outbound updates\n"
4040 "Apply to all AS numbers\n")
4041 {
4042 int idx_peer = 2;
4043 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4044 bgp_node_afi(vty), bgp_node_safi(vty),
4045 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4046 }
4047
4048 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4049 no_neighbor_remove_private_as_all_hidden_cmd,
4050 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4051 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4052 "Remove private ASNs in outbound updates\n"
4053 "Apply to all AS numbers\n")
4054
4055 DEFUN (no_neighbor_remove_private_as_replace_as,
4056 no_neighbor_remove_private_as_replace_as_cmd,
4057 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4058 NO_STR
4059 NEIGHBOR_STR
4060 NEIGHBOR_ADDR_STR2
4061 "Remove private ASNs in outbound updates\n"
4062 "Replace private ASNs with our ASN in outbound updates\n")
4063 {
4064 int idx_peer = 2;
4065 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4066 bgp_node_afi(vty), bgp_node_safi(vty),
4067 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4068 }
4069
4070 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4071 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4072 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4073 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4074 "Remove private ASNs in outbound updates\n"
4075 "Replace private ASNs with our ASN in outbound updates\n")
4076
4077 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4078 no_neighbor_remove_private_as_all_replace_as_cmd,
4079 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4080 NO_STR
4081 NEIGHBOR_STR
4082 NEIGHBOR_ADDR_STR2
4083 "Remove private ASNs in outbound updates\n"
4084 "Apply to all AS numbers\n"
4085 "Replace private ASNs with our ASN in outbound updates\n")
4086 {
4087 int idx_peer = 2;
4088 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4089 bgp_node_afi(vty), bgp_node_safi(vty),
4090 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4091 }
4092
4093 ALIAS_HIDDEN(
4094 no_neighbor_remove_private_as_all_replace_as,
4095 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4096 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4097 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4098 "Remove private ASNs in outbound updates\n"
4099 "Apply to all AS numbers\n"
4100 "Replace private ASNs with our ASN in outbound updates\n")
4101
4102
4103 /* neighbor send-community. */
4104 DEFUN (neighbor_send_community,
4105 neighbor_send_community_cmd,
4106 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4107 NEIGHBOR_STR
4108 NEIGHBOR_ADDR_STR2
4109 "Send Community attribute to this neighbor\n")
4110 {
4111 int idx_peer = 1;
4112
4113 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4114 bgp_node_safi(vty),
4115 PEER_FLAG_SEND_COMMUNITY);
4116 }
4117
4118 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4119 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4120 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4121 "Send Community attribute to this neighbor\n")
4122
4123 DEFUN (no_neighbor_send_community,
4124 no_neighbor_send_community_cmd,
4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4126 NO_STR
4127 NEIGHBOR_STR
4128 NEIGHBOR_ADDR_STR2
4129 "Send Community attribute to this neighbor\n")
4130 {
4131 int idx_peer = 2;
4132
4133 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4134 bgp_node_afi(vty), bgp_node_safi(vty),
4135 PEER_FLAG_SEND_COMMUNITY);
4136 }
4137
4138 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4139 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4140 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4141 "Send Community attribute to this neighbor\n")
4142
4143 /* neighbor send-community extended. */
4144 DEFUN (neighbor_send_community_type,
4145 neighbor_send_community_type_cmd,
4146 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4147 NEIGHBOR_STR
4148 NEIGHBOR_ADDR_STR2
4149 "Send Community attribute to this neighbor\n"
4150 "Send Standard and Extended Community attributes\n"
4151 "Send Standard, Large and Extended Community attributes\n"
4152 "Send Extended Community attributes\n"
4153 "Send Standard Community attributes\n"
4154 "Send Large Community attributes\n")
4155 {
4156 int idx_peer = 1;
4157 uint32_t flag = 0;
4158 const char *type = argv[argc - 1]->text;
4159
4160 if (strmatch(type, "standard")) {
4161 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4162 } else if (strmatch(type, "extended")) {
4163 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4164 } else if (strmatch(type, "large")) {
4165 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4166 } else if (strmatch(type, "both")) {
4167 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4168 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4169 } else { /* if (strmatch(type, "all")) */
4170 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4171 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4172 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4173 }
4174
4175 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4176 bgp_node_safi(vty), flag);
4177 }
4178
4179 ALIAS_HIDDEN(
4180 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4181 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4182 NEIGHBOR_STR 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 DEFUN (no_neighbor_send_community_type,
4191 no_neighbor_send_community_type_cmd,
4192 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4193 NO_STR
4194 NEIGHBOR_STR
4195 NEIGHBOR_ADDR_STR2
4196 "Send Community attribute to this neighbor\n"
4197 "Send Standard and Extended Community attributes\n"
4198 "Send Standard, Large and Extended Community attributes\n"
4199 "Send Extended Community attributes\n"
4200 "Send Standard Community attributes\n"
4201 "Send Large Community attributes\n")
4202 {
4203 int idx_peer = 2;
4204 uint32_t flag = 0;
4205 const char *type = argv[argc - 1]->text;
4206
4207 if (strmatch(type, "standard")) {
4208 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4209 } else if (strmatch(type, "extended")) {
4210 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4211 } else if (strmatch(type, "large")) {
4212 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4213 } else if (strmatch(type, "both")) {
4214 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4215 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4216 } else { /* if (strmatch(type, "all")) */
4217 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4218 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4219 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4220 }
4221
4222 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4223 bgp_node_afi(vty), bgp_node_safi(vty),
4224 flag);
4225 }
4226
4227 ALIAS_HIDDEN(
4228 no_neighbor_send_community_type,
4229 no_neighbor_send_community_type_hidden_cmd,
4230 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4231 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4232 "Send Community attribute to this neighbor\n"
4233 "Send Standard and Extended Community attributes\n"
4234 "Send Standard, Large and Extended Community attributes\n"
4235 "Send Extended Community attributes\n"
4236 "Send Standard Community attributes\n"
4237 "Send Large Community attributes\n")
4238
4239 /* neighbor soft-reconfig. */
4240 DEFUN (neighbor_soft_reconfiguration,
4241 neighbor_soft_reconfiguration_cmd,
4242 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4243 NEIGHBOR_STR
4244 NEIGHBOR_ADDR_STR2
4245 "Per neighbor soft reconfiguration\n"
4246 "Allow inbound soft reconfiguration for this neighbor\n")
4247 {
4248 int idx_peer = 1;
4249 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4250 bgp_node_safi(vty),
4251 PEER_FLAG_SOFT_RECONFIG);
4252 }
4253
4254 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4255 neighbor_soft_reconfiguration_hidden_cmd,
4256 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4257 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4258 "Per neighbor soft reconfiguration\n"
4259 "Allow inbound soft reconfiguration for this neighbor\n")
4260
4261 DEFUN (no_neighbor_soft_reconfiguration,
4262 no_neighbor_soft_reconfiguration_cmd,
4263 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4264 NO_STR
4265 NEIGHBOR_STR
4266 NEIGHBOR_ADDR_STR2
4267 "Per neighbor soft reconfiguration\n"
4268 "Allow inbound soft reconfiguration for this neighbor\n")
4269 {
4270 int idx_peer = 2;
4271 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4272 bgp_node_afi(vty), bgp_node_safi(vty),
4273 PEER_FLAG_SOFT_RECONFIG);
4274 }
4275
4276 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4277 no_neighbor_soft_reconfiguration_hidden_cmd,
4278 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4279 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4280 "Per neighbor soft reconfiguration\n"
4281 "Allow inbound soft reconfiguration for this neighbor\n")
4282
4283 DEFUN (neighbor_route_reflector_client,
4284 neighbor_route_reflector_client_cmd,
4285 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4286 NEIGHBOR_STR
4287 NEIGHBOR_ADDR_STR2
4288 "Configure a neighbor as Route Reflector client\n")
4289 {
4290 int idx_peer = 1;
4291 struct peer *peer;
4292
4293
4294 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4295 if (!peer)
4296 return CMD_WARNING_CONFIG_FAILED;
4297
4298 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4299 bgp_node_safi(vty),
4300 PEER_FLAG_REFLECTOR_CLIENT);
4301 }
4302
4303 ALIAS_HIDDEN(neighbor_route_reflector_client,
4304 neighbor_route_reflector_client_hidden_cmd,
4305 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4306 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4307 "Configure a neighbor as Route Reflector client\n")
4308
4309 DEFUN (no_neighbor_route_reflector_client,
4310 no_neighbor_route_reflector_client_cmd,
4311 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4312 NO_STR
4313 NEIGHBOR_STR
4314 NEIGHBOR_ADDR_STR2
4315 "Configure a neighbor as Route Reflector client\n")
4316 {
4317 int idx_peer = 2;
4318 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4319 bgp_node_afi(vty), bgp_node_safi(vty),
4320 PEER_FLAG_REFLECTOR_CLIENT);
4321 }
4322
4323 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4324 no_neighbor_route_reflector_client_hidden_cmd,
4325 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4326 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4327 "Configure a neighbor as Route Reflector client\n")
4328
4329 /* neighbor route-server-client. */
4330 DEFUN (neighbor_route_server_client,
4331 neighbor_route_server_client_cmd,
4332 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4333 NEIGHBOR_STR
4334 NEIGHBOR_ADDR_STR2
4335 "Configure a neighbor as Route Server client\n")
4336 {
4337 int idx_peer = 1;
4338 struct peer *peer;
4339
4340 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4341 if (!peer)
4342 return CMD_WARNING_CONFIG_FAILED;
4343 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4344 bgp_node_safi(vty),
4345 PEER_FLAG_RSERVER_CLIENT);
4346 }
4347
4348 ALIAS_HIDDEN(neighbor_route_server_client,
4349 neighbor_route_server_client_hidden_cmd,
4350 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4351 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4352 "Configure a neighbor as Route Server client\n")
4353
4354 DEFUN (no_neighbor_route_server_client,
4355 no_neighbor_route_server_client_cmd,
4356 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4357 NO_STR
4358 NEIGHBOR_STR
4359 NEIGHBOR_ADDR_STR2
4360 "Configure a neighbor as Route Server client\n")
4361 {
4362 int idx_peer = 2;
4363 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4364 bgp_node_afi(vty), bgp_node_safi(vty),
4365 PEER_FLAG_RSERVER_CLIENT);
4366 }
4367
4368 ALIAS_HIDDEN(no_neighbor_route_server_client,
4369 no_neighbor_route_server_client_hidden_cmd,
4370 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4371 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4372 "Configure a neighbor as Route Server client\n")
4373
4374 DEFUN (neighbor_nexthop_local_unchanged,
4375 neighbor_nexthop_local_unchanged_cmd,
4376 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4377 NEIGHBOR_STR
4378 NEIGHBOR_ADDR_STR2
4379 "Configure treatment of outgoing link-local nexthop attribute\n"
4380 "Leave link-local nexthop unchanged for this peer\n")
4381 {
4382 int idx_peer = 1;
4383 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4384 bgp_node_safi(vty),
4385 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4386 }
4387
4388 DEFUN (no_neighbor_nexthop_local_unchanged,
4389 no_neighbor_nexthop_local_unchanged_cmd,
4390 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4391 NO_STR
4392 NEIGHBOR_STR
4393 NEIGHBOR_ADDR_STR2
4394 "Configure treatment of outgoing link-local-nexthop attribute\n"
4395 "Leave link-local nexthop unchanged for this peer\n")
4396 {
4397 int idx_peer = 2;
4398 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4399 bgp_node_afi(vty), bgp_node_safi(vty),
4400 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4401 }
4402
4403 DEFUN (neighbor_attr_unchanged,
4404 neighbor_attr_unchanged_cmd,
4405 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4406 NEIGHBOR_STR
4407 NEIGHBOR_ADDR_STR2
4408 "BGP attribute is propagated unchanged to this neighbor\n"
4409 "As-path attribute\n"
4410 "Nexthop attribute\n"
4411 "Med attribute\n")
4412 {
4413 int idx = 0;
4414 char *peer_str = argv[1]->arg;
4415 struct peer *peer;
4416 uint16_t flags = 0;
4417 afi_t afi = bgp_node_afi(vty);
4418 safi_t safi = bgp_node_safi(vty);
4419
4420 peer = peer_and_group_lookup_vty(vty, peer_str);
4421 if (!peer)
4422 return CMD_WARNING_CONFIG_FAILED;
4423
4424 if (argv_find(argv, argc, "as-path", &idx))
4425 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4426 idx = 0;
4427 if (argv_find(argv, argc, "next-hop", &idx))
4428 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4429 idx = 0;
4430 if (argv_find(argv, argc, "med", &idx))
4431 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4432
4433 /* no flags means all of them! */
4434 if (!flags) {
4435 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4436 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4437 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4438 } else {
4439 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4440 && peer_af_flag_check(peer, afi, safi,
4441 PEER_FLAG_AS_PATH_UNCHANGED)) {
4442 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4443 PEER_FLAG_AS_PATH_UNCHANGED);
4444 }
4445
4446 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4447 && peer_af_flag_check(peer, afi, safi,
4448 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4449 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4450 PEER_FLAG_NEXTHOP_UNCHANGED);
4451 }
4452
4453 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4454 && peer_af_flag_check(peer, afi, safi,
4455 PEER_FLAG_MED_UNCHANGED)) {
4456 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4457 PEER_FLAG_MED_UNCHANGED);
4458 }
4459 }
4460
4461 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4462 }
4463
4464 ALIAS_HIDDEN(
4465 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4466 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4467 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4468 "BGP attribute is propagated unchanged to this neighbor\n"
4469 "As-path attribute\n"
4470 "Nexthop attribute\n"
4471 "Med attribute\n")
4472
4473 DEFUN (no_neighbor_attr_unchanged,
4474 no_neighbor_attr_unchanged_cmd,
4475 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4476 NO_STR
4477 NEIGHBOR_STR
4478 NEIGHBOR_ADDR_STR2
4479 "BGP attribute is propagated unchanged to this neighbor\n"
4480 "As-path attribute\n"
4481 "Nexthop attribute\n"
4482 "Med attribute\n")
4483 {
4484 int idx = 0;
4485 char *peer = argv[2]->arg;
4486 uint16_t flags = 0;
4487
4488 if (argv_find(argv, argc, "as-path", &idx))
4489 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4490 idx = 0;
4491 if (argv_find(argv, argc, "next-hop", &idx))
4492 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4493 idx = 0;
4494 if (argv_find(argv, argc, "med", &idx))
4495 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4496
4497 if (!flags) // no flags means all of them!
4498 {
4499 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4500 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4501 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4502 }
4503
4504 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4505 bgp_node_safi(vty), flags);
4506 }
4507
4508 ALIAS_HIDDEN(
4509 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4510 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4511 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4512 "BGP attribute is propagated unchanged to this neighbor\n"
4513 "As-path attribute\n"
4514 "Nexthop attribute\n"
4515 "Med attribute\n")
4516
4517 /* EBGP multihop configuration. */
4518 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4519 const char *ttl_str)
4520 {
4521 struct peer *peer;
4522 unsigned int ttl;
4523
4524 peer = peer_and_group_lookup_vty(vty, ip_str);
4525 if (!peer)
4526 return CMD_WARNING_CONFIG_FAILED;
4527
4528 if (peer->conf_if)
4529 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4530
4531 if (!ttl_str)
4532 ttl = MAXTTL;
4533 else
4534 ttl = strtoul(ttl_str, NULL, 10);
4535
4536 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4537 }
4538
4539 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4540 {
4541 struct peer *peer;
4542
4543 peer = peer_and_group_lookup_vty(vty, ip_str);
4544 if (!peer)
4545 return CMD_WARNING_CONFIG_FAILED;
4546
4547 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4548 }
4549
4550 /* neighbor ebgp-multihop. */
4551 DEFUN (neighbor_ebgp_multihop,
4552 neighbor_ebgp_multihop_cmd,
4553 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4554 NEIGHBOR_STR
4555 NEIGHBOR_ADDR_STR2
4556 "Allow EBGP neighbors not on directly connected networks\n")
4557 {
4558 int idx_peer = 1;
4559 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4560 }
4561
4562 DEFUN (neighbor_ebgp_multihop_ttl,
4563 neighbor_ebgp_multihop_ttl_cmd,
4564 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4565 NEIGHBOR_STR
4566 NEIGHBOR_ADDR_STR2
4567 "Allow EBGP neighbors not on directly connected networks\n"
4568 "maximum hop count\n")
4569 {
4570 int idx_peer = 1;
4571 int idx_number = 3;
4572 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4573 argv[idx_number]->arg);
4574 }
4575
4576 DEFUN (no_neighbor_ebgp_multihop,
4577 no_neighbor_ebgp_multihop_cmd,
4578 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4579 NO_STR
4580 NEIGHBOR_STR
4581 NEIGHBOR_ADDR_STR2
4582 "Allow EBGP neighbors not on directly connected networks\n"
4583 "maximum hop count\n")
4584 {
4585 int idx_peer = 2;
4586 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4587 }
4588
4589
4590 /* disable-connected-check */
4591 DEFUN (neighbor_disable_connected_check,
4592 neighbor_disable_connected_check_cmd,
4593 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4594 NEIGHBOR_STR
4595 NEIGHBOR_ADDR_STR2
4596 "one-hop away EBGP peer using loopback address\n"
4597 "Enforce EBGP neighbors perform multihop\n")
4598 {
4599 int idx_peer = 1;
4600 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4601 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4602 }
4603
4604 DEFUN (no_neighbor_disable_connected_check,
4605 no_neighbor_disable_connected_check_cmd,
4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4607 NO_STR
4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "one-hop away EBGP peer using loopback address\n"
4611 "Enforce EBGP neighbors perform multihop\n")
4612 {
4613 int idx_peer = 2;
4614 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4615 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4616 }
4617
4618
4619 /* enforce-first-as */
4620 DEFUN (neighbor_enforce_first_as,
4621 neighbor_enforce_first_as_cmd,
4622 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4623 NEIGHBOR_STR
4624 NEIGHBOR_ADDR_STR2
4625 "Enforce the first AS for EBGP routes\n")
4626 {
4627 int idx_peer = 1;
4628
4629 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4630 PEER_FLAG_ENFORCE_FIRST_AS);
4631 }
4632
4633 DEFUN (no_neighbor_enforce_first_as,
4634 no_neighbor_enforce_first_as_cmd,
4635 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4636 NO_STR
4637 NEIGHBOR_STR
4638 NEIGHBOR_ADDR_STR2
4639 "Enforce the first AS for EBGP routes\n")
4640 {
4641 int idx_peer = 2;
4642
4643 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4644 PEER_FLAG_ENFORCE_FIRST_AS);
4645 }
4646
4647
4648 DEFUN (neighbor_description,
4649 neighbor_description_cmd,
4650 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4651 NEIGHBOR_STR
4652 NEIGHBOR_ADDR_STR2
4653 "Neighbor specific description\n"
4654 "Up to 80 characters describing this neighbor\n")
4655 {
4656 int idx_peer = 1;
4657 int idx_line = 3;
4658 struct peer *peer;
4659 char *str;
4660
4661 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4662 if (!peer)
4663 return CMD_WARNING_CONFIG_FAILED;
4664
4665 str = argv_concat(argv, argc, idx_line);
4666
4667 peer_description_set(peer, str);
4668
4669 XFREE(MTYPE_TMP, str);
4670
4671 return CMD_SUCCESS;
4672 }
4673
4674 DEFUN (no_neighbor_description,
4675 no_neighbor_description_cmd,
4676 "no neighbor <A.B.C.D|X:X::X:X|WORD> description",
4677 NO_STR
4678 NEIGHBOR_STR
4679 NEIGHBOR_ADDR_STR2
4680 "Neighbor specific description\n")
4681 {
4682 int idx_peer = 2;
4683 struct peer *peer;
4684
4685 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4686 if (!peer)
4687 return CMD_WARNING_CONFIG_FAILED;
4688
4689 peer_description_unset(peer);
4690
4691 return CMD_SUCCESS;
4692 }
4693
4694 ALIAS(no_neighbor_description, no_neighbor_description_comment_cmd,
4695 "no neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4696 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4697 "Neighbor specific description\n"
4698 "Up to 80 characters describing this neighbor\n")
4699
4700 /* Neighbor update-source. */
4701 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4702 const char *source_str)
4703 {
4704 struct peer *peer;
4705 struct prefix p;
4706 union sockunion su;
4707
4708 peer = peer_and_group_lookup_vty(vty, peer_str);
4709 if (!peer)
4710 return CMD_WARNING_CONFIG_FAILED;
4711
4712 if (peer->conf_if)
4713 return CMD_WARNING;
4714
4715 if (source_str) {
4716 if (str2sockunion(source_str, &su) == 0)
4717 peer_update_source_addr_set(peer, &su);
4718 else {
4719 if (str2prefix(source_str, &p)) {
4720 vty_out(vty,
4721 "%% Invalid update-source, remove prefix length \n");
4722 return CMD_WARNING_CONFIG_FAILED;
4723 } else
4724 peer_update_source_if_set(peer, source_str);
4725 }
4726 } else
4727 peer_update_source_unset(peer);
4728
4729 return CMD_SUCCESS;
4730 }
4731
4732 #define BGP_UPDATE_SOURCE_HELP_STR \
4733 "IPv4 address\n" \
4734 "IPv6 address\n" \
4735 "Interface name (requires zebra to be running)\n"
4736
4737 DEFUN (neighbor_update_source,
4738 neighbor_update_source_cmd,
4739 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4740 NEIGHBOR_STR
4741 NEIGHBOR_ADDR_STR2
4742 "Source of routing updates\n"
4743 BGP_UPDATE_SOURCE_HELP_STR)
4744 {
4745 int idx_peer = 1;
4746 int idx_peer_2 = 3;
4747 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4748 argv[idx_peer_2]->arg);
4749 }
4750
4751 DEFUN (no_neighbor_update_source,
4752 no_neighbor_update_source_cmd,
4753 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4754 NO_STR
4755 NEIGHBOR_STR
4756 NEIGHBOR_ADDR_STR2
4757 "Source of routing updates\n"
4758 BGP_UPDATE_SOURCE_HELP_STR)
4759 {
4760 int idx_peer = 2;
4761 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4762 }
4763
4764 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4765 afi_t afi, safi_t safi,
4766 const char *rmap, int set)
4767 {
4768 int ret;
4769 struct peer *peer;
4770
4771 peer = peer_and_group_lookup_vty(vty, peer_str);
4772 if (!peer)
4773 return CMD_WARNING_CONFIG_FAILED;
4774
4775 if (set)
4776 ret = peer_default_originate_set(peer, afi, safi, rmap);
4777 else
4778 ret = peer_default_originate_unset(peer, afi, safi);
4779
4780 return bgp_vty_return(vty, ret);
4781 }
4782
4783 /* neighbor default-originate. */
4784 DEFUN (neighbor_default_originate,
4785 neighbor_default_originate_cmd,
4786 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4787 NEIGHBOR_STR
4788 NEIGHBOR_ADDR_STR2
4789 "Originate default route to this neighbor\n")
4790 {
4791 int idx_peer = 1;
4792 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4793 bgp_node_afi(vty),
4794 bgp_node_safi(vty), NULL, 1);
4795 }
4796
4797 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4798 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4799 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4800 "Originate default route to this neighbor\n")
4801
4802 DEFUN (neighbor_default_originate_rmap,
4803 neighbor_default_originate_rmap_cmd,
4804 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4805 NEIGHBOR_STR
4806 NEIGHBOR_ADDR_STR2
4807 "Originate default route to this neighbor\n"
4808 "Route-map to specify criteria to originate default\n"
4809 "route-map name\n")
4810 {
4811 int idx_peer = 1;
4812 int idx_word = 4;
4813 return peer_default_originate_set_vty(
4814 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4815 argv[idx_word]->arg, 1);
4816 }
4817
4818 ALIAS_HIDDEN(
4819 neighbor_default_originate_rmap,
4820 neighbor_default_originate_rmap_hidden_cmd,
4821 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4823 "Originate default route to this neighbor\n"
4824 "Route-map to specify criteria to originate default\n"
4825 "route-map name\n")
4826
4827 DEFUN (no_neighbor_default_originate,
4828 no_neighbor_default_originate_cmd,
4829 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4830 NO_STR
4831 NEIGHBOR_STR
4832 NEIGHBOR_ADDR_STR2
4833 "Originate default route to this neighbor\n"
4834 "Route-map to specify criteria to originate default\n"
4835 "route-map name\n")
4836 {
4837 int idx_peer = 2;
4838 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4839 bgp_node_afi(vty),
4840 bgp_node_safi(vty), NULL, 0);
4841 }
4842
4843 ALIAS_HIDDEN(
4844 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4845 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4846 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4847 "Originate default route to this neighbor\n"
4848 "Route-map to specify criteria to originate default\n"
4849 "route-map name\n")
4850
4851
4852 /* Set neighbor's BGP port. */
4853 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4854 const char *port_str)
4855 {
4856 struct peer *peer;
4857 uint16_t port;
4858 struct servent *sp;
4859
4860 peer = peer_lookup_vty(vty, ip_str);
4861 if (!peer)
4862 return CMD_WARNING_CONFIG_FAILED;
4863
4864 if (!port_str) {
4865 sp = getservbyname("bgp", "tcp");
4866 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4867 } else {
4868 port = strtoul(port_str, NULL, 10);
4869 }
4870
4871 peer_port_set(peer, port);
4872
4873 return CMD_SUCCESS;
4874 }
4875
4876 /* Set specified peer's BGP port. */
4877 DEFUN (neighbor_port,
4878 neighbor_port_cmd,
4879 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4880 NEIGHBOR_STR
4881 NEIGHBOR_ADDR_STR
4882 "Neighbor's BGP port\n"
4883 "TCP port number\n")
4884 {
4885 int idx_ip = 1;
4886 int idx_number = 3;
4887 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4888 argv[idx_number]->arg);
4889 }
4890
4891 DEFUN (no_neighbor_port,
4892 no_neighbor_port_cmd,
4893 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4894 NO_STR
4895 NEIGHBOR_STR
4896 NEIGHBOR_ADDR_STR
4897 "Neighbor's BGP port\n"
4898 "TCP port number\n")
4899 {
4900 int idx_ip = 2;
4901 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4902 }
4903
4904
4905 /* neighbor weight. */
4906 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4907 safi_t safi, const char *weight_str)
4908 {
4909 int ret;
4910 struct peer *peer;
4911 unsigned long weight;
4912
4913 peer = peer_and_group_lookup_vty(vty, ip_str);
4914 if (!peer)
4915 return CMD_WARNING_CONFIG_FAILED;
4916
4917 weight = strtoul(weight_str, NULL, 10);
4918
4919 ret = peer_weight_set(peer, afi, safi, weight);
4920 return bgp_vty_return(vty, ret);
4921 }
4922
4923 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4924 safi_t safi)
4925 {
4926 int ret;
4927 struct peer *peer;
4928
4929 peer = peer_and_group_lookup_vty(vty, ip_str);
4930 if (!peer)
4931 return CMD_WARNING_CONFIG_FAILED;
4932
4933 ret = peer_weight_unset(peer, afi, safi);
4934 return bgp_vty_return(vty, ret);
4935 }
4936
4937 DEFUN (neighbor_weight,
4938 neighbor_weight_cmd,
4939 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4940 NEIGHBOR_STR
4941 NEIGHBOR_ADDR_STR2
4942 "Set default weight for routes from this neighbor\n"
4943 "default weight\n")
4944 {
4945 int idx_peer = 1;
4946 int idx_number = 3;
4947 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4948 bgp_node_safi(vty), argv[idx_number]->arg);
4949 }
4950
4951 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4952 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4953 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4954 "Set default weight for routes from this neighbor\n"
4955 "default weight\n")
4956
4957 DEFUN (no_neighbor_weight,
4958 no_neighbor_weight_cmd,
4959 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4960 NO_STR
4961 NEIGHBOR_STR
4962 NEIGHBOR_ADDR_STR2
4963 "Set default weight for routes from this neighbor\n"
4964 "default weight\n")
4965 {
4966 int idx_peer = 2;
4967 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4968 bgp_node_afi(vty), bgp_node_safi(vty));
4969 }
4970
4971 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4972 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4974 "Set default weight for routes from this neighbor\n"
4975 "default weight\n")
4976
4977
4978 /* Override capability negotiation. */
4979 DEFUN (neighbor_override_capability,
4980 neighbor_override_capability_cmd,
4981 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4982 NEIGHBOR_STR
4983 NEIGHBOR_ADDR_STR2
4984 "Override capability negotiation result\n")
4985 {
4986 int idx_peer = 1;
4987 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4988 PEER_FLAG_OVERRIDE_CAPABILITY);
4989 }
4990
4991 DEFUN (no_neighbor_override_capability,
4992 no_neighbor_override_capability_cmd,
4993 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4994 NO_STR
4995 NEIGHBOR_STR
4996 NEIGHBOR_ADDR_STR2
4997 "Override capability negotiation result\n")
4998 {
4999 int idx_peer = 2;
5000 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5001 PEER_FLAG_OVERRIDE_CAPABILITY);
5002 }
5003
5004 DEFUN (neighbor_strict_capability,
5005 neighbor_strict_capability_cmd,
5006 "neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5007 NEIGHBOR_STR
5008 NEIGHBOR_ADDR_STR2
5009 "Strict capability negotiation match\n")
5010 {
5011 int idx_peer = 1;
5012
5013 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
5014 PEER_FLAG_STRICT_CAP_MATCH);
5015 }
5016
5017 DEFUN (no_neighbor_strict_capability,
5018 no_neighbor_strict_capability_cmd,
5019 "no neighbor <A.B.C.D|X:X::X:X|WORD> strict-capability-match",
5020 NO_STR
5021 NEIGHBOR_STR
5022 NEIGHBOR_ADDR_STR2
5023 "Strict capability negotiation match\n")
5024 {
5025 int idx_peer = 2;
5026
5027 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
5028 PEER_FLAG_STRICT_CAP_MATCH);
5029 }
5030
5031 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
5032 const char *keep_str, const char *hold_str)
5033 {
5034 int ret;
5035 struct peer *peer;
5036 uint32_t keepalive;
5037 uint32_t holdtime;
5038
5039 peer = peer_and_group_lookup_vty(vty, ip_str);
5040 if (!peer)
5041 return CMD_WARNING_CONFIG_FAILED;
5042
5043 keepalive = strtoul(keep_str, NULL, 10);
5044 holdtime = strtoul(hold_str, NULL, 10);
5045
5046 ret = peer_timers_set(peer, keepalive, holdtime);
5047
5048 return bgp_vty_return(vty, ret);
5049 }
5050
5051 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5052 {
5053 int ret;
5054 struct peer *peer;
5055
5056 peer = peer_and_group_lookup_vty(vty, ip_str);
5057 if (!peer)
5058 return CMD_WARNING_CONFIG_FAILED;
5059
5060 ret = peer_timers_unset(peer);
5061
5062 return bgp_vty_return(vty, ret);
5063 }
5064
5065 DEFUN (neighbor_timers,
5066 neighbor_timers_cmd,
5067 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5068 NEIGHBOR_STR
5069 NEIGHBOR_ADDR_STR2
5070 "BGP per neighbor timers\n"
5071 "Keepalive interval\n"
5072 "Holdtime\n")
5073 {
5074 int idx_peer = 1;
5075 int idx_number = 3;
5076 int idx_number_2 = 4;
5077 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5078 argv[idx_number]->arg,
5079 argv[idx_number_2]->arg);
5080 }
5081
5082 DEFUN (no_neighbor_timers,
5083 no_neighbor_timers_cmd,
5084 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5085 NO_STR
5086 NEIGHBOR_STR
5087 NEIGHBOR_ADDR_STR2
5088 "BGP per neighbor timers\n"
5089 "Keepalive interval\n"
5090 "Holdtime\n")
5091 {
5092 int idx_peer = 2;
5093 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5094 }
5095
5096
5097 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5098 const char *time_str)
5099 {
5100 int ret;
5101 struct peer *peer;
5102 uint32_t connect;
5103
5104 peer = peer_and_group_lookup_vty(vty, ip_str);
5105 if (!peer)
5106 return CMD_WARNING_CONFIG_FAILED;
5107
5108 connect = strtoul(time_str, NULL, 10);
5109
5110 ret = peer_timers_connect_set(peer, connect);
5111
5112 return bgp_vty_return(vty, ret);
5113 }
5114
5115 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5116 {
5117 int ret;
5118 struct peer *peer;
5119
5120 peer = peer_and_group_lookup_vty(vty, ip_str);
5121 if (!peer)
5122 return CMD_WARNING_CONFIG_FAILED;
5123
5124 ret = peer_timers_connect_unset(peer);
5125
5126 return bgp_vty_return(vty, ret);
5127 }
5128
5129 DEFUN (neighbor_timers_connect,
5130 neighbor_timers_connect_cmd,
5131 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5132 NEIGHBOR_STR
5133 NEIGHBOR_ADDR_STR2
5134 "BGP per neighbor timers\n"
5135 "BGP connect timer\n"
5136 "Connect timer\n")
5137 {
5138 int idx_peer = 1;
5139 int idx_number = 4;
5140 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5141 argv[idx_number]->arg);
5142 }
5143
5144 DEFUN (no_neighbor_timers_connect,
5145 no_neighbor_timers_connect_cmd,
5146 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5147 NO_STR
5148 NEIGHBOR_STR
5149 NEIGHBOR_ADDR_STR2
5150 "BGP per neighbor timers\n"
5151 "BGP connect timer\n"
5152 "Connect timer\n")
5153 {
5154 int idx_peer = 2;
5155 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5156 }
5157
5158
5159 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5160 const char *time_str, int set)
5161 {
5162 int ret;
5163 struct peer *peer;
5164 uint32_t routeadv = 0;
5165
5166 peer = peer_and_group_lookup_vty(vty, ip_str);
5167 if (!peer)
5168 return CMD_WARNING_CONFIG_FAILED;
5169
5170 if (time_str)
5171 routeadv = strtoul(time_str, NULL, 10);
5172
5173 if (set)
5174 ret = peer_advertise_interval_set(peer, routeadv);
5175 else
5176 ret = peer_advertise_interval_unset(peer);
5177
5178 return bgp_vty_return(vty, ret);
5179 }
5180
5181 DEFUN (neighbor_advertise_interval,
5182 neighbor_advertise_interval_cmd,
5183 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5184 NEIGHBOR_STR
5185 NEIGHBOR_ADDR_STR2
5186 "Minimum interval between sending BGP routing updates\n"
5187 "time in seconds\n")
5188 {
5189 int idx_peer = 1;
5190 int idx_number = 3;
5191 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5192 argv[idx_number]->arg, 1);
5193 }
5194
5195 DEFUN (no_neighbor_advertise_interval,
5196 no_neighbor_advertise_interval_cmd,
5197 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5198 NO_STR
5199 NEIGHBOR_STR
5200 NEIGHBOR_ADDR_STR2
5201 "Minimum interval between sending BGP routing updates\n"
5202 "time in seconds\n")
5203 {
5204 int idx_peer = 2;
5205 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5206 }
5207
5208
5209 /* Time to wait before processing route-map updates */
5210 DEFUN (bgp_set_route_map_delay_timer,
5211 bgp_set_route_map_delay_timer_cmd,
5212 "bgp route-map delay-timer (0-600)",
5213 SET_STR
5214 "BGP route-map delay timer\n"
5215 "Time in secs to wait before processing route-map changes\n"
5216 "0 disables the timer, no route updates happen when route-maps change\n")
5217 {
5218 int idx_number = 3;
5219 uint32_t rmap_delay_timer;
5220
5221 if (argv[idx_number]->arg) {
5222 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5223 bm->rmap_update_timer = rmap_delay_timer;
5224
5225 /* if the dynamic update handling is being disabled, and a timer
5226 * is
5227 * running, stop the timer and act as if the timer has already
5228 * fired.
5229 */
5230 if (!rmap_delay_timer && bm->t_rmap_update) {
5231 BGP_TIMER_OFF(bm->t_rmap_update);
5232 thread_execute(bm->master, bgp_route_map_update_timer,
5233 NULL, 0);
5234 }
5235 return CMD_SUCCESS;
5236 } else {
5237 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5238 return CMD_WARNING_CONFIG_FAILED;
5239 }
5240 }
5241
5242 DEFUN (no_bgp_set_route_map_delay_timer,
5243 no_bgp_set_route_map_delay_timer_cmd,
5244 "no bgp route-map delay-timer [(0-600)]",
5245 NO_STR
5246 BGP_STR
5247 "Default BGP route-map delay timer\n"
5248 "Reset to default time to wait for processing route-map changes\n"
5249 "0 disables the timer, no route updates happen when route-maps change\n")
5250 {
5251
5252 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5253
5254 return CMD_SUCCESS;
5255 }
5256
5257
5258 /* neighbor interface */
5259 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5260 const char *str)
5261 {
5262 struct peer *peer;
5263
5264 peer = peer_lookup_vty(vty, ip_str);
5265 if (!peer || peer->conf_if) {
5266 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5267 return CMD_WARNING_CONFIG_FAILED;
5268 }
5269
5270 if (str)
5271 peer_interface_set(peer, str);
5272 else
5273 peer_interface_unset(peer);
5274
5275 return CMD_SUCCESS;
5276 }
5277
5278 DEFUN (neighbor_interface,
5279 neighbor_interface_cmd,
5280 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5281 NEIGHBOR_STR
5282 NEIGHBOR_ADDR_STR
5283 "Interface\n"
5284 "Interface name\n")
5285 {
5286 int idx_ip = 1;
5287 int idx_word = 3;
5288 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5289 }
5290
5291 DEFUN (no_neighbor_interface,
5292 no_neighbor_interface_cmd,
5293 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5294 NO_STR
5295 NEIGHBOR_STR
5296 NEIGHBOR_ADDR_STR2
5297 "Interface\n"
5298 "Interface name\n")
5299 {
5300 int idx_peer = 2;
5301 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5302 }
5303
5304 DEFUN (neighbor_distribute_list,
5305 neighbor_distribute_list_cmd,
5306 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5307 NEIGHBOR_STR
5308 NEIGHBOR_ADDR_STR2
5309 "Filter updates to/from this neighbor\n"
5310 "IP access-list number\n"
5311 "IP access-list number (expanded range)\n"
5312 "IP Access-list name\n"
5313 "Filter incoming updates\n"
5314 "Filter outgoing updates\n")
5315 {
5316 int idx_peer = 1;
5317 int idx_acl = 3;
5318 int direct, ret;
5319 struct peer *peer;
5320
5321 const char *pstr = argv[idx_peer]->arg;
5322 const char *acl = argv[idx_acl]->arg;
5323 const char *inout = argv[argc - 1]->text;
5324
5325 peer = peer_and_group_lookup_vty(vty, pstr);
5326 if (!peer)
5327 return CMD_WARNING_CONFIG_FAILED;
5328
5329 /* Check filter direction. */
5330 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5331 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5332 direct, acl);
5333
5334 return bgp_vty_return(vty, ret);
5335 }
5336
5337 ALIAS_HIDDEN(
5338 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5339 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5340 NEIGHBOR_STR 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 DEFUN (no_neighbor_distribute_list,
5349 no_neighbor_distribute_list_cmd,
5350 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5351 NO_STR
5352 NEIGHBOR_STR
5353 NEIGHBOR_ADDR_STR2
5354 "Filter updates to/from this neighbor\n"
5355 "IP access-list number\n"
5356 "IP access-list number (expanded range)\n"
5357 "IP Access-list name\n"
5358 "Filter incoming updates\n"
5359 "Filter outgoing updates\n")
5360 {
5361 int idx_peer = 2;
5362 int direct, ret;
5363 struct peer *peer;
5364
5365 const char *pstr = argv[idx_peer]->arg;
5366 const char *inout = argv[argc - 1]->text;
5367
5368 peer = peer_and_group_lookup_vty(vty, pstr);
5369 if (!peer)
5370 return CMD_WARNING_CONFIG_FAILED;
5371
5372 /* Check filter direction. */
5373 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5374 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5375 direct);
5376
5377 return bgp_vty_return(vty, ret);
5378 }
5379
5380 ALIAS_HIDDEN(
5381 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5382 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5383 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5384 "Filter updates to/from this neighbor\n"
5385 "IP access-list number\n"
5386 "IP access-list number (expanded range)\n"
5387 "IP Access-list name\n"
5388 "Filter incoming updates\n"
5389 "Filter outgoing updates\n")
5390
5391 /* Set prefix list to the peer. */
5392 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5393 afi_t afi, safi_t safi,
5394 const char *name_str,
5395 const char *direct_str)
5396 {
5397 int ret;
5398 int direct = FILTER_IN;
5399 struct peer *peer;
5400
5401 peer = peer_and_group_lookup_vty(vty, ip_str);
5402 if (!peer)
5403 return CMD_WARNING_CONFIG_FAILED;
5404
5405 /* Check filter direction. */
5406 if (strncmp(direct_str, "i", 1) == 0)
5407 direct = FILTER_IN;
5408 else if (strncmp(direct_str, "o", 1) == 0)
5409 direct = FILTER_OUT;
5410
5411 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5412
5413 return bgp_vty_return(vty, ret);
5414 }
5415
5416 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5417 afi_t afi, safi_t safi,
5418 const char *direct_str)
5419 {
5420 int ret;
5421 struct peer *peer;
5422 int direct = FILTER_IN;
5423
5424 peer = peer_and_group_lookup_vty(vty, ip_str);
5425 if (!peer)
5426 return CMD_WARNING_CONFIG_FAILED;
5427
5428 /* Check filter direction. */
5429 if (strncmp(direct_str, "i", 1) == 0)
5430 direct = FILTER_IN;
5431 else if (strncmp(direct_str, "o", 1) == 0)
5432 direct = FILTER_OUT;
5433
5434 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5435
5436 return bgp_vty_return(vty, ret);
5437 }
5438
5439 DEFUN (neighbor_prefix_list,
5440 neighbor_prefix_list_cmd,
5441 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5442 NEIGHBOR_STR
5443 NEIGHBOR_ADDR_STR2
5444 "Filter updates to/from this neighbor\n"
5445 "Name of a prefix list\n"
5446 "Filter incoming updates\n"
5447 "Filter outgoing updates\n")
5448 {
5449 int idx_peer = 1;
5450 int idx_word = 3;
5451 int idx_in_out = 4;
5452 return peer_prefix_list_set_vty(
5453 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5454 argv[idx_word]->arg, argv[idx_in_out]->arg);
5455 }
5456
5457 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5458 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5459 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5460 "Filter updates to/from this neighbor\n"
5461 "Name of a prefix list\n"
5462 "Filter incoming updates\n"
5463 "Filter outgoing updates\n")
5464
5465 DEFUN (no_neighbor_prefix_list,
5466 no_neighbor_prefix_list_cmd,
5467 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5468 NO_STR
5469 NEIGHBOR_STR
5470 NEIGHBOR_ADDR_STR2
5471 "Filter updates to/from this neighbor\n"
5472 "Name of a prefix list\n"
5473 "Filter incoming updates\n"
5474 "Filter outgoing updates\n")
5475 {
5476 int idx_peer = 2;
5477 int idx_in_out = 5;
5478 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5479 bgp_node_afi(vty), bgp_node_safi(vty),
5480 argv[idx_in_out]->arg);
5481 }
5482
5483 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5484 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5485 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5486 "Filter updates to/from this neighbor\n"
5487 "Name of a prefix list\n"
5488 "Filter incoming updates\n"
5489 "Filter outgoing updates\n")
5490
5491 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5492 safi_t safi, const char *name_str,
5493 const char *direct_str)
5494 {
5495 int ret;
5496 struct peer *peer;
5497 int direct = FILTER_IN;
5498
5499 peer = peer_and_group_lookup_vty(vty, ip_str);
5500 if (!peer)
5501 return CMD_WARNING_CONFIG_FAILED;
5502
5503 /* Check filter direction. */
5504 if (strncmp(direct_str, "i", 1) == 0)
5505 direct = FILTER_IN;
5506 else if (strncmp(direct_str, "o", 1) == 0)
5507 direct = FILTER_OUT;
5508
5509 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5510
5511 return bgp_vty_return(vty, ret);
5512 }
5513
5514 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5515 safi_t safi, const char *direct_str)
5516 {
5517 int ret;
5518 struct peer *peer;
5519 int direct = FILTER_IN;
5520
5521 peer = peer_and_group_lookup_vty(vty, ip_str);
5522 if (!peer)
5523 return CMD_WARNING_CONFIG_FAILED;
5524
5525 /* Check filter direction. */
5526 if (strncmp(direct_str, "i", 1) == 0)
5527 direct = FILTER_IN;
5528 else if (strncmp(direct_str, "o", 1) == 0)
5529 direct = FILTER_OUT;
5530
5531 ret = peer_aslist_unset(peer, afi, safi, direct);
5532
5533 return bgp_vty_return(vty, ret);
5534 }
5535
5536 DEFUN (neighbor_filter_list,
5537 neighbor_filter_list_cmd,
5538 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5539 NEIGHBOR_STR
5540 NEIGHBOR_ADDR_STR2
5541 "Establish BGP filters\n"
5542 "AS path access-list name\n"
5543 "Filter incoming routes\n"
5544 "Filter outgoing routes\n")
5545 {
5546 int idx_peer = 1;
5547 int idx_word = 3;
5548 int idx_in_out = 4;
5549 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5550 bgp_node_safi(vty), argv[idx_word]->arg,
5551 argv[idx_in_out]->arg);
5552 }
5553
5554 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5555 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5556 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5557 "Establish BGP filters\n"
5558 "AS path access-list name\n"
5559 "Filter incoming routes\n"
5560 "Filter outgoing routes\n")
5561
5562 DEFUN (no_neighbor_filter_list,
5563 no_neighbor_filter_list_cmd,
5564 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5565 NO_STR
5566 NEIGHBOR_STR
5567 NEIGHBOR_ADDR_STR2
5568 "Establish BGP filters\n"
5569 "AS path access-list name\n"
5570 "Filter incoming routes\n"
5571 "Filter outgoing routes\n")
5572 {
5573 int idx_peer = 2;
5574 int idx_in_out = 5;
5575 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5576 bgp_node_afi(vty), bgp_node_safi(vty),
5577 argv[idx_in_out]->arg);
5578 }
5579
5580 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5581 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5582 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5583 "Establish BGP filters\n"
5584 "AS path access-list name\n"
5585 "Filter incoming routes\n"
5586 "Filter outgoing routes\n")
5587
5588 /* Set route-map to the peer. */
5589 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5590 afi_t afi, safi_t safi, const char *name_str,
5591 const char *direct_str)
5592 {
5593 int ret;
5594 struct peer *peer;
5595 int direct = RMAP_IN;
5596
5597 peer = peer_and_group_lookup_vty(vty, ip_str);
5598 if (!peer)
5599 return CMD_WARNING_CONFIG_FAILED;
5600
5601 /* Check filter direction. */
5602 if (strncmp(direct_str, "in", 2) == 0)
5603 direct = RMAP_IN;
5604 else if (strncmp(direct_str, "o", 1) == 0)
5605 direct = RMAP_OUT;
5606
5607 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5608
5609 return bgp_vty_return(vty, ret);
5610 }
5611
5612 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5613 afi_t afi, safi_t safi,
5614 const char *direct_str)
5615 {
5616 int ret;
5617 struct peer *peer;
5618 int direct = RMAP_IN;
5619
5620 peer = peer_and_group_lookup_vty(vty, ip_str);
5621 if (!peer)
5622 return CMD_WARNING_CONFIG_FAILED;
5623
5624 /* Check filter direction. */
5625 if (strncmp(direct_str, "in", 2) == 0)
5626 direct = RMAP_IN;
5627 else if (strncmp(direct_str, "o", 1) == 0)
5628 direct = RMAP_OUT;
5629
5630 ret = peer_route_map_unset(peer, afi, safi, direct);
5631
5632 return bgp_vty_return(vty, ret);
5633 }
5634
5635 DEFUN (neighbor_route_map,
5636 neighbor_route_map_cmd,
5637 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5638 NEIGHBOR_STR
5639 NEIGHBOR_ADDR_STR2
5640 "Apply route map to neighbor\n"
5641 "Name of route map\n"
5642 "Apply map to incoming routes\n"
5643 "Apply map to outbound routes\n")
5644 {
5645 int idx_peer = 1;
5646 int idx_word = 3;
5647 int idx_in_out = 4;
5648 return peer_route_map_set_vty(
5649 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5650 argv[idx_word]->arg, argv[idx_in_out]->arg);
5651 }
5652
5653 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5654 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5655 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5656 "Apply route map to neighbor\n"
5657 "Name of route map\n"
5658 "Apply map to incoming routes\n"
5659 "Apply map to outbound routes\n")
5660
5661 DEFUN (no_neighbor_route_map,
5662 no_neighbor_route_map_cmd,
5663 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5664 NO_STR
5665 NEIGHBOR_STR
5666 NEIGHBOR_ADDR_STR2
5667 "Apply route map to neighbor\n"
5668 "Name of route map\n"
5669 "Apply map to incoming routes\n"
5670 "Apply map to outbound routes\n")
5671 {
5672 int idx_peer = 2;
5673 int idx_in_out = 5;
5674 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5675 bgp_node_afi(vty), bgp_node_safi(vty),
5676 argv[idx_in_out]->arg);
5677 }
5678
5679 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5680 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5681 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5682 "Apply route map to neighbor\n"
5683 "Name of route map\n"
5684 "Apply map to incoming routes\n"
5685 "Apply map to outbound routes\n")
5686
5687 /* Set unsuppress-map to the peer. */
5688 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5689 afi_t afi, safi_t safi,
5690 const char *name_str)
5691 {
5692 int ret;
5693 struct peer *peer;
5694
5695 peer = peer_and_group_lookup_vty(vty, ip_str);
5696 if (!peer)
5697 return CMD_WARNING_CONFIG_FAILED;
5698
5699 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5700
5701 return bgp_vty_return(vty, ret);
5702 }
5703
5704 /* Unset route-map from the peer. */
5705 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5706 afi_t afi, safi_t safi)
5707 {
5708 int ret;
5709 struct peer *peer;
5710
5711 peer = peer_and_group_lookup_vty(vty, ip_str);
5712 if (!peer)
5713 return CMD_WARNING_CONFIG_FAILED;
5714
5715 ret = peer_unsuppress_map_unset(peer, afi, safi);
5716
5717 return bgp_vty_return(vty, ret);
5718 }
5719
5720 DEFUN (neighbor_unsuppress_map,
5721 neighbor_unsuppress_map_cmd,
5722 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5723 NEIGHBOR_STR
5724 NEIGHBOR_ADDR_STR2
5725 "Route-map to selectively unsuppress suppressed routes\n"
5726 "Name of route map\n")
5727 {
5728 int idx_peer = 1;
5729 int idx_word = 3;
5730 return peer_unsuppress_map_set_vty(
5731 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5732 argv[idx_word]->arg);
5733 }
5734
5735 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5736 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5738 "Route-map to selectively unsuppress suppressed routes\n"
5739 "Name of route map\n")
5740
5741 DEFUN (no_neighbor_unsuppress_map,
5742 no_neighbor_unsuppress_map_cmd,
5743 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5744 NO_STR
5745 NEIGHBOR_STR
5746 NEIGHBOR_ADDR_STR2
5747 "Route-map to selectively unsuppress suppressed routes\n"
5748 "Name of route map\n")
5749 {
5750 int idx_peer = 2;
5751 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5752 bgp_node_afi(vty),
5753 bgp_node_safi(vty));
5754 }
5755
5756 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5757 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5758 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5759 "Route-map to selectively unsuppress suppressed routes\n"
5760 "Name of route map\n")
5761
5762 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5763 afi_t afi, safi_t safi,
5764 const char *num_str,
5765 const char *threshold_str, int warning,
5766 const char *restart_str)
5767 {
5768 int ret;
5769 struct peer *peer;
5770 uint32_t max;
5771 uint8_t threshold;
5772 uint16_t restart;
5773
5774 peer = peer_and_group_lookup_vty(vty, ip_str);
5775 if (!peer)
5776 return CMD_WARNING_CONFIG_FAILED;
5777
5778 max = strtoul(num_str, NULL, 10);
5779 if (threshold_str)
5780 threshold = atoi(threshold_str);
5781 else
5782 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5783
5784 if (restart_str)
5785 restart = atoi(restart_str);
5786 else
5787 restart = 0;
5788
5789 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5790 restart);
5791
5792 return bgp_vty_return(vty, ret);
5793 }
5794
5795 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5796 afi_t afi, safi_t safi)
5797 {
5798 int ret;
5799 struct peer *peer;
5800
5801 peer = peer_and_group_lookup_vty(vty, ip_str);
5802 if (!peer)
5803 return CMD_WARNING_CONFIG_FAILED;
5804
5805 ret = peer_maximum_prefix_unset(peer, afi, safi);
5806
5807 return bgp_vty_return(vty, ret);
5808 }
5809
5810 /* Maximum number of prefix configuration. prefix count is different
5811 for each peer configuration. So this configuration can be set for
5812 each peer configuration. */
5813 DEFUN (neighbor_maximum_prefix,
5814 neighbor_maximum_prefix_cmd,
5815 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
5818 "Maximum number of prefix accept from this peer\n"
5819 "maximum no. of prefix limit\n")
5820 {
5821 int idx_peer = 1;
5822 int idx_number = 3;
5823 return peer_maximum_prefix_set_vty(
5824 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5825 argv[idx_number]->arg, NULL, 0, NULL);
5826 }
5827
5828 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5830 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5831 "Maximum number of prefix accept from this peer\n"
5832 "maximum no. of prefix limit\n")
5833
5834 DEFUN (neighbor_maximum_prefix_threshold,
5835 neighbor_maximum_prefix_threshold_cmd,
5836 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5837 NEIGHBOR_STR
5838 NEIGHBOR_ADDR_STR2
5839 "Maximum number of prefix accept from this peer\n"
5840 "maximum no. of prefix limit\n"
5841 "Threshold value (%) at which to generate a warning msg\n")
5842 {
5843 int idx_peer = 1;
5844 int idx_number = 3;
5845 int idx_number_2 = 4;
5846 return peer_maximum_prefix_set_vty(
5847 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5848 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5849 }
5850
5851 ALIAS_HIDDEN(
5852 neighbor_maximum_prefix_threshold,
5853 neighbor_maximum_prefix_threshold_hidden_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5855 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5856 "Maximum number of prefix accept from this peer\n"
5857 "maximum no. of prefix limit\n"
5858 "Threshold value (%) at which to generate a warning msg\n")
5859
5860 DEFUN (neighbor_maximum_prefix_warning,
5861 neighbor_maximum_prefix_warning_cmd,
5862 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5863 NEIGHBOR_STR
5864 NEIGHBOR_ADDR_STR2
5865 "Maximum number of prefix accept from this peer\n"
5866 "maximum no. of prefix limit\n"
5867 "Only give warning message when limit is exceeded\n")
5868 {
5869 int idx_peer = 1;
5870 int idx_number = 3;
5871 return peer_maximum_prefix_set_vty(
5872 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5873 argv[idx_number]->arg, NULL, 1, NULL);
5874 }
5875
5876 ALIAS_HIDDEN(
5877 neighbor_maximum_prefix_warning,
5878 neighbor_maximum_prefix_warning_hidden_cmd,
5879 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5880 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5881 "Maximum number of prefix accept from this peer\n"
5882 "maximum no. of prefix limit\n"
5883 "Only give warning message when limit is exceeded\n")
5884
5885 DEFUN (neighbor_maximum_prefix_threshold_warning,
5886 neighbor_maximum_prefix_threshold_warning_cmd,
5887 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5888 NEIGHBOR_STR
5889 NEIGHBOR_ADDR_STR2
5890 "Maximum number of prefix accept from this peer\n"
5891 "maximum no. of prefix limit\n"
5892 "Threshold value (%) at which to generate a warning msg\n"
5893 "Only give warning message when limit is exceeded\n")
5894 {
5895 int idx_peer = 1;
5896 int idx_number = 3;
5897 int idx_number_2 = 4;
5898 return peer_maximum_prefix_set_vty(
5899 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5900 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5901 }
5902
5903 ALIAS_HIDDEN(
5904 neighbor_maximum_prefix_threshold_warning,
5905 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5906 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5908 "Maximum number of prefix accept from this peer\n"
5909 "maximum no. of prefix limit\n"
5910 "Threshold value (%) at which to generate a warning msg\n"
5911 "Only give warning message when limit is exceeded\n")
5912
5913 DEFUN (neighbor_maximum_prefix_restart,
5914 neighbor_maximum_prefix_restart_cmd,
5915 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5916 NEIGHBOR_STR
5917 NEIGHBOR_ADDR_STR2
5918 "Maximum number of prefix accept from this peer\n"
5919 "maximum no. of prefix limit\n"
5920 "Restart bgp connection after limit is exceeded\n"
5921 "Restart interval in minutes\n")
5922 {
5923 int idx_peer = 1;
5924 int idx_number = 3;
5925 int idx_number_2 = 5;
5926 return peer_maximum_prefix_set_vty(
5927 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5928 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5929 }
5930
5931 ALIAS_HIDDEN(
5932 neighbor_maximum_prefix_restart,
5933 neighbor_maximum_prefix_restart_hidden_cmd,
5934 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5935 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5936 "Maximum number of prefix accept from this peer\n"
5937 "maximum no. of prefix limit\n"
5938 "Restart bgp connection after limit is exceeded\n"
5939 "Restart interval in minutes\n")
5940
5941 DEFUN (neighbor_maximum_prefix_threshold_restart,
5942 neighbor_maximum_prefix_threshold_restart_cmd,
5943 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5944 NEIGHBOR_STR
5945 NEIGHBOR_ADDR_STR2
5946 "Maximum number of prefixes to accept from this peer\n"
5947 "maximum no. of prefix limit\n"
5948 "Threshold value (%) at which to generate a warning msg\n"
5949 "Restart bgp connection after limit is exceeded\n"
5950 "Restart interval in minutes\n")
5951 {
5952 int idx_peer = 1;
5953 int idx_number = 3;
5954 int idx_number_2 = 4;
5955 int idx_number_3 = 6;
5956 return peer_maximum_prefix_set_vty(
5957 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5958 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5959 argv[idx_number_3]->arg);
5960 }
5961
5962 ALIAS_HIDDEN(
5963 neighbor_maximum_prefix_threshold_restart,
5964 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5965 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5966 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "Maximum number of prefixes to accept from this peer\n"
5968 "maximum no. of prefix limit\n"
5969 "Threshold value (%) at which to generate a warning msg\n"
5970 "Restart bgp connection after limit is exceeded\n"
5971 "Restart interval in minutes\n")
5972
5973 DEFUN (no_neighbor_maximum_prefix,
5974 no_neighbor_maximum_prefix_cmd,
5975 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5976 NO_STR
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Maximum number of prefixes to accept from this peer\n"
5980 "maximum no. of prefix limit\n"
5981 "Threshold value (%) at which to generate a warning msg\n"
5982 "Restart bgp connection after limit is exceeded\n"
5983 "Restart interval in minutes\n"
5984 "Only give warning message when limit is exceeded\n")
5985 {
5986 int idx_peer = 2;
5987 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5988 bgp_node_afi(vty),
5989 bgp_node_safi(vty));
5990 }
5991
5992 ALIAS_HIDDEN(
5993 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5994 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5995 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5996 "Maximum number of prefixes to accept from this peer\n"
5997 "maximum no. of prefix limit\n"
5998 "Threshold value (%) at which to generate a warning msg\n"
5999 "Restart bgp connection after limit is exceeded\n"
6000 "Restart interval in minutes\n"
6001 "Only give warning message when limit is exceeded\n")
6002
6003
6004 /* "neighbor allowas-in" */
6005 DEFUN (neighbor_allowas_in,
6006 neighbor_allowas_in_cmd,
6007 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6008 NEIGHBOR_STR
6009 NEIGHBOR_ADDR_STR2
6010 "Accept as-path with my AS present in it\n"
6011 "Number of occurances of AS number\n"
6012 "Only accept my AS in the as-path if the route was originated in my AS\n")
6013 {
6014 int idx_peer = 1;
6015 int idx_number_origin = 3;
6016 int ret;
6017 int origin = 0;
6018 struct peer *peer;
6019 int allow_num = 0;
6020
6021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6022 if (!peer)
6023 return CMD_WARNING_CONFIG_FAILED;
6024
6025 if (argc <= idx_number_origin)
6026 allow_num = 3;
6027 else {
6028 if (argv[idx_number_origin]->type == WORD_TKN)
6029 origin = 1;
6030 else
6031 allow_num = atoi(argv[idx_number_origin]->arg);
6032 }
6033
6034 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6035 allow_num, origin);
6036
6037 return bgp_vty_return(vty, ret);
6038 }
6039
6040 ALIAS_HIDDEN(
6041 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6042 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6043 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6044 "Accept as-path with my AS present in it\n"
6045 "Number of occurances of AS number\n"
6046 "Only accept my AS in the as-path if the route was originated in my AS\n")
6047
6048 DEFUN (no_neighbor_allowas_in,
6049 no_neighbor_allowas_in_cmd,
6050 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6051 NO_STR
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "allow local ASN appears in aspath attribute\n"
6055 "Number of occurances of AS number\n"
6056 "Only accept my AS in the as-path if the route was originated in my AS\n")
6057 {
6058 int idx_peer = 2;
6059 int ret;
6060 struct peer *peer;
6061
6062 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6063 if (!peer)
6064 return CMD_WARNING_CONFIG_FAILED;
6065
6066 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6067 bgp_node_safi(vty));
6068
6069 return bgp_vty_return(vty, ret);
6070 }
6071
6072 ALIAS_HIDDEN(
6073 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6074 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6075 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6076 "allow local ASN appears in aspath attribute\n"
6077 "Number of occurances of AS number\n"
6078 "Only accept my AS in the as-path if the route was originated in my AS\n")
6079
6080 DEFUN (neighbor_ttl_security,
6081 neighbor_ttl_security_cmd,
6082 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6083 NEIGHBOR_STR
6084 NEIGHBOR_ADDR_STR2
6085 "BGP ttl-security parameters\n"
6086 "Specify the maximum number of hops to the BGP peer\n"
6087 "Number of hops to BGP peer\n")
6088 {
6089 int idx_peer = 1;
6090 int idx_number = 4;
6091 struct peer *peer;
6092 int gtsm_hops;
6093
6094 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6095 if (!peer)
6096 return CMD_WARNING_CONFIG_FAILED;
6097
6098 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6099
6100 /*
6101 * If 'neighbor swpX', then this is for directly connected peers,
6102 * we should not accept a ttl-security hops value greater than 1.
6103 */
6104 if (peer->conf_if && (gtsm_hops > 1)) {
6105 vty_out(vty,
6106 "%s is directly connected peer, hops cannot exceed 1\n",
6107 argv[idx_peer]->arg);
6108 return CMD_WARNING_CONFIG_FAILED;
6109 }
6110
6111 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6112 }
6113
6114 DEFUN (no_neighbor_ttl_security,
6115 no_neighbor_ttl_security_cmd,
6116 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6117 NO_STR
6118 NEIGHBOR_STR
6119 NEIGHBOR_ADDR_STR2
6120 "BGP ttl-security parameters\n"
6121 "Specify the maximum number of hops to the BGP peer\n"
6122 "Number of hops to BGP peer\n")
6123 {
6124 int idx_peer = 2;
6125 struct peer *peer;
6126
6127 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6128 if (!peer)
6129 return CMD_WARNING_CONFIG_FAILED;
6130
6131 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6132 }
6133
6134 DEFUN (neighbor_addpath_tx_all_paths,
6135 neighbor_addpath_tx_all_paths_cmd,
6136 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6137 NEIGHBOR_STR
6138 NEIGHBOR_ADDR_STR2
6139 "Use addpath to advertise all paths to a neighbor\n")
6140 {
6141 int idx_peer = 1;
6142 struct peer *peer;
6143
6144 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6145 if (!peer)
6146 return CMD_WARNING_CONFIG_FAILED;
6147
6148 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6149 bgp_node_safi(vty),
6150 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6151 }
6152
6153 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6154 neighbor_addpath_tx_all_paths_hidden_cmd,
6155 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6156 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6157 "Use addpath to advertise all paths to a neighbor\n")
6158
6159 DEFUN (no_neighbor_addpath_tx_all_paths,
6160 no_neighbor_addpath_tx_all_paths_cmd,
6161 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6162 NO_STR
6163 NEIGHBOR_STR
6164 NEIGHBOR_ADDR_STR2
6165 "Use addpath to advertise all paths to a neighbor\n")
6166 {
6167 int idx_peer = 2;
6168 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6169 bgp_node_afi(vty), bgp_node_safi(vty),
6170 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6171 }
6172
6173 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6174 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6175 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6176 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6177 "Use addpath to advertise all paths to a neighbor\n")
6178
6179 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6180 neighbor_addpath_tx_bestpath_per_as_cmd,
6181 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6182 NEIGHBOR_STR
6183 NEIGHBOR_ADDR_STR2
6184 "Use addpath to advertise the bestpath per each neighboring AS\n")
6185 {
6186 int idx_peer = 1;
6187 struct peer *peer;
6188
6189 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6190 if (!peer)
6191 return CMD_WARNING_CONFIG_FAILED;
6192
6193 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6194 bgp_node_safi(vty),
6195 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6196 }
6197
6198 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6199 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6200 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6201 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6202 "Use addpath to advertise the bestpath per each neighboring AS\n")
6203
6204 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6205 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6206 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6207 NO_STR
6208 NEIGHBOR_STR
6209 NEIGHBOR_ADDR_STR2
6210 "Use addpath to advertise the bestpath per each neighboring AS\n")
6211 {
6212 int idx_peer = 2;
6213 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6214 bgp_node_afi(vty), bgp_node_safi(vty),
6215 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6216 }
6217
6218 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6219 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6220 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6221 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6222 "Use addpath to advertise the bestpath per each neighboring AS\n")
6223
6224 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6225 struct ecommunity **list)
6226 {
6227 struct ecommunity *ecom = NULL;
6228 struct ecommunity *ecomadd;
6229
6230 for (; argc; --argc, ++argv) {
6231
6232 ecomadd = ecommunity_str2com(argv[0]->arg,
6233 ECOMMUNITY_ROUTE_TARGET, 0);
6234 if (!ecomadd) {
6235 vty_out(vty, "Malformed community-list value\n");
6236 if (ecom)
6237 ecommunity_free(&ecom);
6238 return CMD_WARNING_CONFIG_FAILED;
6239 }
6240
6241 if (ecom) {
6242 ecommunity_merge(ecom, ecomadd);
6243 ecommunity_free(&ecomadd);
6244 } else {
6245 ecom = ecomadd;
6246 }
6247 }
6248
6249 if (*list) {
6250 ecommunity_free(&*list);
6251 }
6252 *list = ecom;
6253
6254 return CMD_SUCCESS;
6255 }
6256
6257 /*
6258 * v2vimport is true if we are handling a `import vrf ...` command
6259 */
6260 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6261 {
6262 afi_t afi;
6263
6264 switch (vty->node) {
6265 case BGP_IPV4_NODE:
6266 afi = AFI_IP;
6267 break;
6268 case BGP_IPV6_NODE:
6269 afi = AFI_IP6;
6270 break;
6271 default:
6272 vty_out(vty,
6273 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6274 return AFI_MAX;
6275 }
6276
6277 if (!v2vimport) {
6278 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6279 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6280 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6281 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6282 vty_out(vty,
6283 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6284 return AFI_MAX;
6285 }
6286 } else {
6287 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6288 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6289 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6290 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6291 vty_out(vty,
6292 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6293 return AFI_MAX;
6294 }
6295 }
6296 return afi;
6297 }
6298
6299 DEFPY (af_rd_vpn_export,
6300 af_rd_vpn_export_cmd,
6301 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6302 NO_STR
6303 "Specify route distinguisher\n"
6304 "Between current address-family and vpn\n"
6305 "For routes leaked from current address-family to vpn\n"
6306 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6307 {
6308 VTY_DECLVAR_CONTEXT(bgp, bgp);
6309 struct prefix_rd prd;
6310 int ret;
6311 afi_t afi;
6312 int idx = 0;
6313 int yes = 1;
6314
6315 if (argv_find(argv, argc, "no", &idx))
6316 yes = 0;
6317
6318 if (yes) {
6319 ret = str2prefix_rd(rd_str, &prd);
6320 if (!ret) {
6321 vty_out(vty, "%% Malformed rd\n");
6322 return CMD_WARNING_CONFIG_FAILED;
6323 }
6324 }
6325
6326 afi = vpn_policy_getafi(vty, bgp, false);
6327 if (afi == AFI_MAX)
6328 return CMD_WARNING_CONFIG_FAILED;
6329
6330 /*
6331 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6332 */
6333 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6334 bgp_get_default(), bgp);
6335
6336 if (yes) {
6337 bgp->vpn_policy[afi].tovpn_rd = prd;
6338 SET_FLAG(bgp->vpn_policy[afi].flags,
6339 BGP_VPN_POLICY_TOVPN_RD_SET);
6340 } else {
6341 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6342 BGP_VPN_POLICY_TOVPN_RD_SET);
6343 }
6344
6345 /* post-change: re-export vpn routes */
6346 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6347 bgp_get_default(), bgp);
6348
6349 return CMD_SUCCESS;
6350 }
6351
6352 ALIAS (af_rd_vpn_export,
6353 af_no_rd_vpn_export_cmd,
6354 "no rd vpn export",
6355 NO_STR
6356 "Specify route distinguisher\n"
6357 "Between current address-family and vpn\n"
6358 "For routes leaked from current address-family to vpn\n")
6359
6360 DEFPY (af_label_vpn_export,
6361 af_label_vpn_export_cmd,
6362 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6363 NO_STR
6364 "label value for VRF\n"
6365 "Between current address-family and vpn\n"
6366 "For routes leaked from current address-family to vpn\n"
6367 "Label Value <0-1048575>\n"
6368 "Automatically assign a label\n")
6369 {
6370 VTY_DECLVAR_CONTEXT(bgp, bgp);
6371 mpls_label_t label = MPLS_LABEL_NONE;
6372 afi_t afi;
6373 int idx = 0;
6374 int yes = 1;
6375
6376 if (argv_find(argv, argc, "no", &idx))
6377 yes = 0;
6378
6379 /* If "no ...", squash trailing parameter */
6380 if (!yes)
6381 label_auto = NULL;
6382
6383 if (yes) {
6384 if (!label_auto)
6385 label = label_val; /* parser should force unsigned */
6386 }
6387
6388 afi = vpn_policy_getafi(vty, bgp, false);
6389 if (afi == AFI_MAX)
6390 return CMD_WARNING_CONFIG_FAILED;
6391
6392
6393 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6394 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6395 /* no change */
6396 return CMD_SUCCESS;
6397
6398 /*
6399 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6400 */
6401 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6402 bgp_get_default(), bgp);
6403
6404 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6405 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6406
6407 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6408
6409 /*
6410 * label has previously been automatically
6411 * assigned by labelpool: release it
6412 *
6413 * NB if tovpn_label == MPLS_LABEL_NONE it
6414 * means the automatic assignment is in flight
6415 * and therefore the labelpool callback must
6416 * detect that the auto label is not needed.
6417 */
6418
6419 bgp_lp_release(LP_TYPE_VRF,
6420 &bgp->vpn_policy[afi],
6421 bgp->vpn_policy[afi].tovpn_label);
6422 }
6423 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6424 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6425 }
6426
6427 bgp->vpn_policy[afi].tovpn_label = label;
6428 if (label_auto) {
6429 SET_FLAG(bgp->vpn_policy[afi].flags,
6430 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6431 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6432 vpn_leak_label_callback);
6433 }
6434
6435 /* post-change: re-export vpn routes */
6436 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6437 bgp_get_default(), bgp);
6438
6439 return CMD_SUCCESS;
6440 }
6441
6442 ALIAS (af_label_vpn_export,
6443 af_no_label_vpn_export_cmd,
6444 "no label vpn export",
6445 NO_STR
6446 "label value for VRF\n"
6447 "Between current address-family and vpn\n"
6448 "For routes leaked from current address-family to vpn\n")
6449
6450 DEFPY (af_nexthop_vpn_export,
6451 af_nexthop_vpn_export_cmd,
6452 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6453 NO_STR
6454 "Specify next hop to use for VRF advertised prefixes\n"
6455 "Between current address-family and vpn\n"
6456 "For routes leaked from current address-family to vpn\n"
6457 "IPv4 prefix\n"
6458 "IPv6 prefix\n")
6459 {
6460 VTY_DECLVAR_CONTEXT(bgp, bgp);
6461 afi_t afi;
6462 struct prefix p;
6463 int idx = 0;
6464 int yes = 1;
6465
6466 if (argv_find(argv, argc, "no", &idx))
6467 yes = 0;
6468
6469 if (yes) {
6470 if (!sockunion2hostprefix(nexthop_str, &p))
6471 return CMD_WARNING_CONFIG_FAILED;
6472 }
6473
6474 afi = vpn_policy_getafi(vty, bgp, false);
6475 if (afi == AFI_MAX)
6476 return CMD_WARNING_CONFIG_FAILED;
6477
6478 /*
6479 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6480 */
6481 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6482 bgp_get_default(), bgp);
6483
6484 if (yes) {
6485 bgp->vpn_policy[afi].tovpn_nexthop = p;
6486 SET_FLAG(bgp->vpn_policy[afi].flags,
6487 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6488 } else {
6489 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6490 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6491 }
6492
6493 /* post-change: re-export vpn routes */
6494 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6495 bgp_get_default(), bgp);
6496
6497 return CMD_SUCCESS;
6498 }
6499
6500 ALIAS (af_nexthop_vpn_export,
6501 af_no_nexthop_vpn_export_cmd,
6502 "no nexthop vpn export",
6503 NO_STR
6504 "Specify next hop to use for VRF advertised prefixes\n"
6505 "Between current address-family and vpn\n"
6506 "For routes leaked from current address-family to vpn\n")
6507
6508 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6509 {
6510 if (!strcmp(dstr, "import")) {
6511 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6512 } else if (!strcmp(dstr, "export")) {
6513 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6514 } else if (!strcmp(dstr, "both")) {
6515 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6516 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6517 } else {
6518 vty_out(vty, "%% direction parse error\n");
6519 return CMD_WARNING_CONFIG_FAILED;
6520 }
6521 return CMD_SUCCESS;
6522 }
6523
6524 DEFPY (af_rt_vpn_imexport,
6525 af_rt_vpn_imexport_cmd,
6526 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6527 NO_STR
6528 "Specify route target list\n"
6529 "Specify route target list\n"
6530 "Between current address-family and vpn\n"
6531 "For routes leaked from vpn to current address-family: match any\n"
6532 "For routes leaked from current address-family to vpn: set\n"
6533 "both import: match any and export: set\n"
6534 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6535 {
6536 VTY_DECLVAR_CONTEXT(bgp, bgp);
6537 int ret;
6538 struct ecommunity *ecom = NULL;
6539 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6540 vpn_policy_direction_t dir;
6541 afi_t afi;
6542 int idx = 0;
6543 int yes = 1;
6544
6545 if (argv_find(argv, argc, "no", &idx))
6546 yes = 0;
6547
6548 afi = vpn_policy_getafi(vty, bgp, false);
6549 if (afi == AFI_MAX)
6550 return CMD_WARNING_CONFIG_FAILED;
6551
6552 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6553 if (ret != CMD_SUCCESS)
6554 return ret;
6555
6556 if (yes) {
6557 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6558 vty_out(vty, "%% Missing RTLIST\n");
6559 return CMD_WARNING_CONFIG_FAILED;
6560 }
6561 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6562 if (ret != CMD_SUCCESS) {
6563 return ret;
6564 }
6565 }
6566
6567 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6568 if (!dodir[dir])
6569 continue;
6570
6571 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6572
6573 if (yes) {
6574 if (bgp->vpn_policy[afi].rtlist[dir])
6575 ecommunity_free(
6576 &bgp->vpn_policy[afi].rtlist[dir]);
6577 bgp->vpn_policy[afi].rtlist[dir] =
6578 ecommunity_dup(ecom);
6579 } else {
6580 if (bgp->vpn_policy[afi].rtlist[dir])
6581 ecommunity_free(
6582 &bgp->vpn_policy[afi].rtlist[dir]);
6583 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6584 }
6585
6586 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6587 }
6588
6589 if (ecom)
6590 ecommunity_free(&ecom);
6591
6592 return CMD_SUCCESS;
6593 }
6594
6595 ALIAS (af_rt_vpn_imexport,
6596 af_no_rt_vpn_imexport_cmd,
6597 "no <rt|route-target> vpn <import|export|both>$direction_str",
6598 NO_STR
6599 "Specify route target list\n"
6600 "Specify route target list\n"
6601 "Between current address-family and vpn\n"
6602 "For routes leaked from vpn to current address-family\n"
6603 "For routes leaked from current address-family to vpn\n"
6604 "both import and export\n")
6605
6606 DEFPY (af_route_map_vpn_imexport,
6607 af_route_map_vpn_imexport_cmd,
6608 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6609 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6610 NO_STR
6611 "Specify route map\n"
6612 "Between current address-family and vpn\n"
6613 "For routes leaked from vpn to current address-family\n"
6614 "For routes leaked from current address-family to vpn\n"
6615 "name of route-map\n")
6616 {
6617 VTY_DECLVAR_CONTEXT(bgp, bgp);
6618 int ret;
6619 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6620 vpn_policy_direction_t dir;
6621 afi_t afi;
6622 int idx = 0;
6623 int yes = 1;
6624
6625 if (argv_find(argv, argc, "no", &idx))
6626 yes = 0;
6627
6628 afi = vpn_policy_getafi(vty, bgp, false);
6629 if (afi == AFI_MAX)
6630 return CMD_WARNING_CONFIG_FAILED;
6631
6632 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6633 if (ret != CMD_SUCCESS)
6634 return ret;
6635
6636 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6637 if (!dodir[dir])
6638 continue;
6639
6640 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6641
6642 if (yes) {
6643 if (bgp->vpn_policy[afi].rmap_name[dir])
6644 XFREE(MTYPE_ROUTE_MAP_NAME,
6645 bgp->vpn_policy[afi].rmap_name[dir]);
6646 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6647 MTYPE_ROUTE_MAP_NAME, rmap_str);
6648 bgp->vpn_policy[afi].rmap[dir] =
6649 route_map_lookup_by_name(rmap_str);
6650 if (!bgp->vpn_policy[afi].rmap[dir])
6651 return CMD_SUCCESS;
6652 } else {
6653 if (bgp->vpn_policy[afi].rmap_name[dir])
6654 XFREE(MTYPE_ROUTE_MAP_NAME,
6655 bgp->vpn_policy[afi].rmap_name[dir]);
6656 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6657 bgp->vpn_policy[afi].rmap[dir] = NULL;
6658 }
6659
6660 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6661 }
6662
6663 return CMD_SUCCESS;
6664 }
6665
6666 ALIAS (af_route_map_vpn_imexport,
6667 af_no_route_map_vpn_imexport_cmd,
6668 "no route-map vpn <import|export>$direction_str",
6669 NO_STR
6670 "Specify route map\n"
6671 "Between current address-family and vpn\n"
6672 "For routes leaked from vpn to current address-family\n"
6673 "For routes leaked from current address-family to vpn\n")
6674
6675 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6676 "[no] import vrf route-map RMAP$rmap_str",
6677 NO_STR
6678 "Import routes from another VRF\n"
6679 "Vrf routes being filtered\n"
6680 "Specify route map\n"
6681 "name of route-map\n")
6682 {
6683 VTY_DECLVAR_CONTEXT(bgp, bgp);
6684 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6685 afi_t afi;
6686 int idx = 0;
6687 int yes = 1;
6688 struct bgp *bgp_default;
6689
6690 if (argv_find(argv, argc, "no", &idx))
6691 yes = 0;
6692
6693 afi = vpn_policy_getafi(vty, bgp, true);
6694 if (afi == AFI_MAX)
6695 return CMD_WARNING_CONFIG_FAILED;
6696
6697 bgp_default = bgp_get_default();
6698 if (!bgp_default) {
6699 int32_t ret;
6700 as_t as = bgp->as;
6701
6702 /* Auto-create assuming the same AS */
6703 ret = bgp_get(&bgp_default, &as, NULL,
6704 BGP_INSTANCE_TYPE_DEFAULT);
6705
6706 if (ret) {
6707 vty_out(vty,
6708 "VRF default is not configured as a bgp instance\n");
6709 return CMD_WARNING;
6710 }
6711 }
6712
6713 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6714
6715 if (yes) {
6716 if (bgp->vpn_policy[afi].rmap_name[dir])
6717 XFREE(MTYPE_ROUTE_MAP_NAME,
6718 bgp->vpn_policy[afi].rmap_name[dir]);
6719 bgp->vpn_policy[afi].rmap_name[dir] =
6720 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6721 bgp->vpn_policy[afi].rmap[dir] =
6722 route_map_lookup_by_name(rmap_str);
6723 if (!bgp->vpn_policy[afi].rmap[dir])
6724 return CMD_SUCCESS;
6725 } else {
6726 if (bgp->vpn_policy[afi].rmap_name[dir])
6727 XFREE(MTYPE_ROUTE_MAP_NAME,
6728 bgp->vpn_policy[afi].rmap_name[dir]);
6729 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6730 bgp->vpn_policy[afi].rmap[dir] = NULL;
6731 }
6732
6733 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6734
6735 return CMD_SUCCESS;
6736 }
6737
6738 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6739 "no import vrf route-map",
6740 NO_STR
6741 "Import routes from another VRF\n"
6742 "Vrf routes being filtered\n"
6743 "Specify route map\n")
6744
6745 DEFPY (bgp_imexport_vrf,
6746 bgp_imexport_vrf_cmd,
6747 "[no] import vrf NAME$import_name",
6748 NO_STR
6749 "Import routes from another VRF\n"
6750 "VRF to import from\n"
6751 "The name of the VRF\n")
6752 {
6753 VTY_DECLVAR_CONTEXT(bgp, bgp);
6754 struct listnode *node;
6755 struct bgp *vrf_bgp, *bgp_default;
6756 int32_t ret = 0;
6757 as_t as = bgp->as;
6758 bool remove = false;
6759 int32_t idx = 0;
6760 char *vname;
6761 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6762 safi_t safi;
6763 afi_t afi;
6764
6765 if (import_name == NULL) {
6766 vty_out(vty, "%% Missing import name\n");
6767 return CMD_WARNING;
6768 }
6769
6770 if (argv_find(argv, argc, "no", &idx))
6771 remove = true;
6772
6773 afi = vpn_policy_getafi(vty, bgp, true);
6774 if (afi == AFI_MAX)
6775 return CMD_WARNING_CONFIG_FAILED;
6776
6777 safi = bgp_node_safi(vty);
6778
6779 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6780 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6781 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6782 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6783 remove ? "unimport" : "import", import_name);
6784 return CMD_WARNING;
6785 }
6786
6787 bgp_default = bgp_get_default();
6788 if (!bgp_default) {
6789 /* Auto-create assuming the same AS */
6790 ret = bgp_get(&bgp_default, &as, NULL,
6791 BGP_INSTANCE_TYPE_DEFAULT);
6792
6793 if (ret) {
6794 vty_out(vty,
6795 "VRF default is not configured as a bgp instance\n");
6796 return CMD_WARNING;
6797 }
6798 }
6799
6800 vrf_bgp = bgp_lookup_by_name(import_name);
6801 if (!vrf_bgp) {
6802 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6803 vrf_bgp = bgp_default;
6804 else
6805 /* Auto-create assuming the same AS */
6806 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6807
6808 if (ret) {
6809 vty_out(vty,
6810 "VRF %s is not configured as a bgp instance\n",
6811 import_name);
6812 return CMD_WARNING;
6813 }
6814 }
6815
6816 if (remove) {
6817 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6818 } else {
6819 /* Already importing from "import_vrf"? */
6820 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6821 vname)) {
6822 if (strcmp(vname, import_name) == 0)
6823 return CMD_WARNING;
6824 }
6825
6826 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6827 }
6828
6829 return CMD_SUCCESS;
6830 }
6831
6832 /* This command is valid only in a bgp vrf instance or the default instance */
6833 DEFPY (bgp_imexport_vpn,
6834 bgp_imexport_vpn_cmd,
6835 "[no] <import|export>$direction_str vpn",
6836 NO_STR
6837 "Import routes to this address-family\n"
6838 "Export routes from this address-family\n"
6839 "to/from default instance VPN RIB\n")
6840 {
6841 VTY_DECLVAR_CONTEXT(bgp, bgp);
6842 int previous_state;
6843 afi_t afi;
6844 safi_t safi;
6845 int idx = 0;
6846 int yes = 1;
6847 int flag;
6848 vpn_policy_direction_t dir;
6849
6850 if (argv_find(argv, argc, "no", &idx))
6851 yes = 0;
6852
6853 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6854 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6855
6856 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6857 return CMD_WARNING_CONFIG_FAILED;
6858 }
6859
6860 afi = bgp_node_afi(vty);
6861 safi = bgp_node_safi(vty);
6862 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6863 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6864 return CMD_WARNING_CONFIG_FAILED;
6865 }
6866
6867 if (!strcmp(direction_str, "import")) {
6868 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6869 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6870 } else if (!strcmp(direction_str, "export")) {
6871 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6872 dir = BGP_VPN_POLICY_DIR_TOVPN;
6873 } else {
6874 vty_out(vty, "%% unknown direction %s\n", direction_str);
6875 return CMD_WARNING_CONFIG_FAILED;
6876 }
6877
6878 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6879
6880 if (yes) {
6881 SET_FLAG(bgp->af_flags[afi][safi], flag);
6882 if (!previous_state) {
6883 /* trigger export current vrf */
6884 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6885 }
6886 } else {
6887 if (previous_state) {
6888 /* trigger un-export current vrf */
6889 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6890 }
6891 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6892 }
6893
6894 return CMD_SUCCESS;
6895 }
6896
6897 DEFPY (af_routetarget_import,
6898 af_routetarget_import_cmd,
6899 "[no] <rt|route-target> redirect import RTLIST...",
6900 NO_STR
6901 "Specify route target list\n"
6902 "Specify route target list\n"
6903 "Flow-spec redirect type route target\n"
6904 "Import routes to this address-family\n"
6905 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6906 {
6907 VTY_DECLVAR_CONTEXT(bgp, bgp);
6908 int ret;
6909 struct ecommunity *ecom = NULL;
6910 afi_t afi;
6911 int idx = 0;
6912 int yes = 1;
6913
6914 if (argv_find(argv, argc, "no", &idx))
6915 yes = 0;
6916
6917 afi = vpn_policy_getafi(vty, bgp, false);
6918 if (afi == AFI_MAX)
6919 return CMD_WARNING_CONFIG_FAILED;
6920
6921 if (yes) {
6922 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6923 vty_out(vty, "%% Missing RTLIST\n");
6924 return CMD_WARNING_CONFIG_FAILED;
6925 }
6926 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6927 if (ret != CMD_SUCCESS)
6928 return ret;
6929 }
6930
6931 if (yes) {
6932 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6933 ecommunity_free(&bgp->vpn_policy[afi]
6934 .import_redirect_rtlist);
6935 bgp->vpn_policy[afi].import_redirect_rtlist =
6936 ecommunity_dup(ecom);
6937 } else {
6938 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6939 ecommunity_free(&bgp->vpn_policy[afi]
6940 .import_redirect_rtlist);
6941 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6942 }
6943
6944 if (ecom)
6945 ecommunity_free(&ecom);
6946
6947 return CMD_SUCCESS;
6948 }
6949
6950 DEFUN_NOSH (address_family_ipv4_safi,
6951 address_family_ipv4_safi_cmd,
6952 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6953 "Enter Address Family command mode\n"
6954 "Address Family\n"
6955 BGP_SAFI_WITH_LABEL_HELP_STR)
6956 {
6957
6958 if (argc == 3) {
6959 VTY_DECLVAR_CONTEXT(bgp, bgp);
6960 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6961 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6962 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6963 && safi != SAFI_EVPN) {
6964 vty_out(vty,
6965 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6966 return CMD_WARNING_CONFIG_FAILED;
6967 }
6968 vty->node = bgp_node_type(AFI_IP, safi);
6969 } else
6970 vty->node = BGP_IPV4_NODE;
6971
6972 return CMD_SUCCESS;
6973 }
6974
6975 DEFUN_NOSH (address_family_ipv6_safi,
6976 address_family_ipv6_safi_cmd,
6977 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6978 "Enter Address Family command mode\n"
6979 "Address Family\n"
6980 BGP_SAFI_WITH_LABEL_HELP_STR)
6981 {
6982 if (argc == 3) {
6983 VTY_DECLVAR_CONTEXT(bgp, bgp);
6984 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6985 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6986 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6987 && safi != SAFI_EVPN) {
6988 vty_out(vty,
6989 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6990 return CMD_WARNING_CONFIG_FAILED;
6991 }
6992 vty->node = bgp_node_type(AFI_IP6, safi);
6993 } else
6994 vty->node = BGP_IPV6_NODE;
6995
6996 return CMD_SUCCESS;
6997 }
6998
6999 #ifdef KEEP_OLD_VPN_COMMANDS
7000 DEFUN_NOSH (address_family_vpnv4,
7001 address_family_vpnv4_cmd,
7002 "address-family vpnv4 [unicast]",
7003 "Enter Address Family command mode\n"
7004 "Address Family\n"
7005 "Address Family modifier\n")
7006 {
7007 vty->node = BGP_VPNV4_NODE;
7008 return CMD_SUCCESS;
7009 }
7010
7011 DEFUN_NOSH (address_family_vpnv6,
7012 address_family_vpnv6_cmd,
7013 "address-family vpnv6 [unicast]",
7014 "Enter Address Family command mode\n"
7015 "Address Family\n"
7016 "Address Family modifier\n")
7017 {
7018 vty->node = BGP_VPNV6_NODE;
7019 return CMD_SUCCESS;
7020 }
7021 #endif
7022
7023 DEFUN_NOSH (address_family_evpn,
7024 address_family_evpn_cmd,
7025 "address-family l2vpn evpn",
7026 "Enter Address Family command mode\n"
7027 "Address Family\n"
7028 "Address Family modifier\n")
7029 {
7030 VTY_DECLVAR_CONTEXT(bgp, bgp);
7031 vty->node = BGP_EVPN_NODE;
7032 return CMD_SUCCESS;
7033 }
7034
7035 DEFUN_NOSH (exit_address_family,
7036 exit_address_family_cmd,
7037 "exit-address-family",
7038 "Exit from Address Family configuration mode\n")
7039 {
7040 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7041 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7042 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7043 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7044 || vty->node == BGP_EVPN_NODE
7045 || vty->node == BGP_FLOWSPECV4_NODE
7046 || vty->node == BGP_FLOWSPECV6_NODE)
7047 vty->node = BGP_NODE;
7048 return CMD_SUCCESS;
7049 }
7050
7051 /* Recalculate bestpath and re-advertise a prefix */
7052 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7053 const char *ip_str, afi_t afi, safi_t safi,
7054 struct prefix_rd *prd)
7055 {
7056 int ret;
7057 struct prefix match;
7058 struct bgp_node *rn;
7059 struct bgp_node *rm;
7060 struct bgp *bgp;
7061 struct bgp_table *table;
7062 struct bgp_table *rib;
7063
7064 /* BGP structure lookup. */
7065 if (view_name) {
7066 bgp = bgp_lookup_by_name(view_name);
7067 if (bgp == NULL) {
7068 vty_out(vty, "%% Can't find BGP instance %s\n",
7069 view_name);
7070 return CMD_WARNING;
7071 }
7072 } else {
7073 bgp = bgp_get_default();
7074 if (bgp == NULL) {
7075 vty_out(vty, "%% No BGP process is configured\n");
7076 return CMD_WARNING;
7077 }
7078 }
7079
7080 /* Check IP address argument. */
7081 ret = str2prefix(ip_str, &match);
7082 if (!ret) {
7083 vty_out(vty, "%% address is malformed\n");
7084 return CMD_WARNING;
7085 }
7086
7087 match.family = afi2family(afi);
7088 rib = bgp->rib[afi][safi];
7089
7090 if (safi == SAFI_MPLS_VPN) {
7091 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7092 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7093 continue;
7094
7095 if ((table = rn->info) != NULL) {
7096 if ((rm = bgp_node_match(table, &match))
7097 != NULL) {
7098 if (rm->p.prefixlen
7099 == match.prefixlen) {
7100 SET_FLAG(rm->flags,
7101 BGP_NODE_USER_CLEAR);
7102 bgp_process(bgp, rm, afi, safi);
7103 }
7104 bgp_unlock_node(rm);
7105 }
7106 }
7107 }
7108 } else {
7109 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7110 if (rn->p.prefixlen == match.prefixlen) {
7111 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7112 bgp_process(bgp, rn, afi, safi);
7113 }
7114 bgp_unlock_node(rn);
7115 }
7116 }
7117
7118 return CMD_SUCCESS;
7119 }
7120
7121 /* one clear bgp command to rule them all */
7122 DEFUN (clear_ip_bgp_all,
7123 clear_ip_bgp_all_cmd,
7124 "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>]",
7125 CLEAR_STR
7126 IP_STR
7127 BGP_STR
7128 BGP_INSTANCE_HELP_STR
7129 BGP_AFI_HELP_STR
7130 BGP_SAFI_WITH_LABEL_HELP_STR
7131 "Clear all peers\n"
7132 "BGP neighbor address to clear\n"
7133 "BGP IPv6 neighbor to clear\n"
7134 "BGP neighbor on interface to clear\n"
7135 "Clear peers with the AS number\n"
7136 "Clear all external peers\n"
7137 "Clear all members of peer-group\n"
7138 "BGP peer-group name\n"
7139 BGP_SOFT_STR
7140 BGP_SOFT_IN_STR
7141 BGP_SOFT_OUT_STR
7142 BGP_SOFT_IN_STR
7143 "Push out prefix-list ORF and do inbound soft reconfig\n"
7144 BGP_SOFT_OUT_STR)
7145 {
7146 char *vrf = NULL;
7147
7148 afi_t afi = AFI_IP6;
7149 safi_t safi = SAFI_UNICAST;
7150 enum clear_sort clr_sort = clear_peer;
7151 enum bgp_clear_type clr_type;
7152 char *clr_arg = NULL;
7153
7154 int idx = 0;
7155
7156 /* clear [ip] bgp */
7157 if (argv_find(argv, argc, "ip", &idx))
7158 afi = AFI_IP;
7159
7160 /* [<vrf> VIEWVRFNAME] */
7161 if (argv_find(argv, argc, "vrf", &idx)) {
7162 vrf = argv[idx + 1]->arg;
7163 idx += 2;
7164 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7165 vrf = NULL;
7166 } else if (argv_find(argv, argc, "view", &idx)) {
7167 /* [<view> VIEWVRFNAME] */
7168 vrf = argv[idx + 1]->arg;
7169 idx += 2;
7170 }
7171 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7172 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7173 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7174
7175 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7176 if (argv_find(argv, argc, "*", &idx)) {
7177 clr_sort = clear_all;
7178 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7179 clr_sort = clear_peer;
7180 clr_arg = argv[idx]->arg;
7181 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7182 clr_sort = clear_peer;
7183 clr_arg = argv[idx]->arg;
7184 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7185 clr_sort = clear_group;
7186 idx++;
7187 clr_arg = argv[idx]->arg;
7188 } else if (argv_find(argv, argc, "WORD", &idx)) {
7189 clr_sort = clear_peer;
7190 clr_arg = argv[idx]->arg;
7191 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7192 clr_sort = clear_as;
7193 clr_arg = argv[idx]->arg;
7194 } else if (argv_find(argv, argc, "external", &idx)) {
7195 clr_sort = clear_external;
7196 }
7197
7198 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7199 if (argv_find(argv, argc, "soft", &idx)) {
7200 if (argv_find(argv, argc, "in", &idx)
7201 || argv_find(argv, argc, "out", &idx))
7202 clr_type = strmatch(argv[idx]->text, "in")
7203 ? BGP_CLEAR_SOFT_IN
7204 : BGP_CLEAR_SOFT_OUT;
7205 else
7206 clr_type = BGP_CLEAR_SOFT_BOTH;
7207 } else if (argv_find(argv, argc, "in", &idx)) {
7208 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7209 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7210 : BGP_CLEAR_SOFT_IN;
7211 } else if (argv_find(argv, argc, "out", &idx)) {
7212 clr_type = BGP_CLEAR_SOFT_OUT;
7213 } else
7214 clr_type = BGP_CLEAR_SOFT_NONE;
7215
7216 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7217 }
7218
7219 DEFUN (clear_ip_bgp_prefix,
7220 clear_ip_bgp_prefix_cmd,
7221 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7222 CLEAR_STR
7223 IP_STR
7224 BGP_STR
7225 BGP_INSTANCE_HELP_STR
7226 "Clear bestpath and re-advertise\n"
7227 "IPv4 prefix\n")
7228 {
7229 char *vrf = NULL;
7230 char *prefix = NULL;
7231
7232 int idx = 0;
7233
7234 /* [<view|vrf> VIEWVRFNAME] */
7235 if (argv_find(argv, argc, "vrf", &idx)) {
7236 vrf = argv[idx + 1]->arg;
7237 idx += 2;
7238 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
7239 vrf = NULL;
7240 } else if (argv_find(argv, argc, "view", &idx)) {
7241 /* [<view> VIEWVRFNAME] */
7242 vrf = argv[idx + 1]->arg;
7243 idx += 2;
7244 }
7245
7246 prefix = argv[argc - 1]->arg;
7247
7248 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7249 }
7250
7251 DEFUN (clear_bgp_ipv6_safi_prefix,
7252 clear_bgp_ipv6_safi_prefix_cmd,
7253 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7254 CLEAR_STR
7255 IP_STR
7256 BGP_STR
7257 "Address Family\n"
7258 BGP_SAFI_HELP_STR
7259 "Clear bestpath and re-advertise\n"
7260 "IPv6 prefix\n")
7261 {
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
7268 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7269 return bgp_clear_prefix(
7270 vty, NULL, prefix, AFI_IP6,
7271 safi, NULL);
7272 }
7273
7274 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7275 clear_bgp_instance_ipv6_safi_prefix_cmd,
7276 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7277 CLEAR_STR
7278 IP_STR
7279 BGP_STR
7280 BGP_INSTANCE_HELP_STR
7281 "Address Family\n"
7282 BGP_SAFI_HELP_STR
7283 "Clear bestpath and re-advertise\n"
7284 "IPv6 prefix\n")
7285 {
7286 int idx_safi = 0;
7287 int idx_vrfview = 0;
7288 int idx_ipv6_prefix = 0;
7289 safi_t safi = SAFI_UNICAST;
7290 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7291 argv[idx_ipv6_prefix]->arg : NULL;
7292 char *vrfview = NULL;
7293
7294 /* [<view|vrf> VIEWVRFNAME] */
7295 if (argv_find(argv, argc, "vrf", &idx_vrfview)) {
7296 vrfview = argv[idx_vrfview + 1]->arg;
7297 if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME))
7298 vrfview = NULL;
7299 } else if (argv_find(argv, argc, "view", &idx_vrfview)) {
7300 /* [<view> VIEWVRFNAME] */
7301 vrfview = argv[idx_vrfview + 1]->arg;
7302 }
7303 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7304
7305 return bgp_clear_prefix(
7306 vty, vrfview, prefix,
7307 AFI_IP6, safi, NULL);
7308 }
7309
7310 DEFUN (show_bgp_views,
7311 show_bgp_views_cmd,
7312 "show [ip] bgp views",
7313 SHOW_STR
7314 IP_STR
7315 BGP_STR
7316 "Show the defined BGP views\n")
7317 {
7318 struct list *inst = bm->bgp;
7319 struct listnode *node;
7320 struct bgp *bgp;
7321
7322 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7323 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7324 return CMD_WARNING;
7325 }
7326
7327 vty_out(vty, "Defined BGP views:\n");
7328 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7329 /* Skip VRFs. */
7330 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7331 continue;
7332 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7333 bgp->as);
7334 }
7335
7336 return CMD_SUCCESS;
7337 }
7338
7339 DEFUN (show_bgp_vrfs,
7340 show_bgp_vrfs_cmd,
7341 "show [ip] bgp vrfs [json]",
7342 SHOW_STR
7343 IP_STR
7344 BGP_STR
7345 "Show BGP VRFs\n"
7346 JSON_STR)
7347 {
7348 char buf[ETHER_ADDR_STRLEN];
7349 struct list *inst = bm->bgp;
7350 struct listnode *node;
7351 struct bgp *bgp;
7352 bool uj = use_json(argc, argv);
7353 json_object *json = NULL;
7354 json_object *json_vrfs = NULL;
7355 int count = 0;
7356
7357 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7358 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7359 return CMD_WARNING;
7360 }
7361
7362 if (uj) {
7363 json = json_object_new_object();
7364 json_vrfs = json_object_new_object();
7365 }
7366
7367 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7368 const char *name, *type;
7369 struct peer *peer;
7370 struct listnode *node2, *nnode2;
7371 int peers_cfg, peers_estb;
7372 json_object *json_vrf = NULL;
7373
7374 /* Skip Views. */
7375 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7376 continue;
7377
7378 count++;
7379 if (!uj && count == 1)
7380 vty_out(vty,
7381 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7382 "Type", "Id", "routerId", "#PeersVfg",
7383 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7384
7385 peers_cfg = peers_estb = 0;
7386 if (uj)
7387 json_vrf = json_object_new_object();
7388
7389
7390 for (ALL_LIST_ELEMENTS(bgp->peer, node2, nnode2, peer)) {
7391 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7392 continue;
7393 peers_cfg++;
7394 if (peer->status == Established)
7395 peers_estb++;
7396 }
7397
7398 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7399 name = "Default";
7400 type = "DFLT";
7401 } else {
7402 name = bgp->name;
7403 type = "VRF";
7404 }
7405
7406
7407 if (uj) {
7408 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7409 ? -1
7410 : (int64_t)bgp->vrf_id;
7411 json_object_string_add(json_vrf, "type", type);
7412 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7413 json_object_string_add(json_vrf, "routerId",
7414 inet_ntoa(bgp->router_id));
7415 json_object_int_add(json_vrf, "numConfiguredPeers",
7416 peers_cfg);
7417 json_object_int_add(json_vrf, "numEstablishedPeers",
7418 peers_estb);
7419
7420 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7421 json_object_string_add(
7422 json_vrf, "rmac",
7423 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7424 json_object_object_add(json_vrfs, name, json_vrf);
7425 } else
7426 vty_out(vty,
7427 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7428 type,
7429 bgp->vrf_id == VRF_UNKNOWN ? -1
7430 : (int)bgp->vrf_id,
7431 inet_ntoa(bgp->router_id), peers_cfg,
7432 peers_estb, name, bgp->l3vni,
7433 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7434 }
7435
7436 if (uj) {
7437 json_object_object_add(json, "vrfs", json_vrfs);
7438
7439 json_object_int_add(json, "totalVrfs", count);
7440
7441 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7442 json, JSON_C_TO_STRING_PRETTY));
7443 json_object_free(json);
7444 } else {
7445 if (count)
7446 vty_out(vty,
7447 "\nTotal number of VRFs (including default): %d\n",
7448 count);
7449 }
7450
7451 return CMD_SUCCESS;
7452 }
7453
7454
7455 static void show_tip_entry(struct hash_backet *backet, void *args)
7456 {
7457 struct vty *vty = (struct vty *)args;
7458 struct tip_addr *tip = (struct tip_addr *)backet->data;
7459
7460 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7461 tip->refcnt);
7462 }
7463
7464 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7465 {
7466 vty_out(vty, "self nexthop database:\n");
7467 bgp_nexthop_show_address_hash(vty, bgp);
7468
7469 vty_out(vty, "Tunnel-ip database:\n");
7470 hash_iterate(bgp->tip_hash,
7471 (void (*)(struct hash_backet *, void *))show_tip_entry,
7472 vty);
7473 }
7474
7475 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7476 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7477 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7478 "martian next-hops\n"
7479 "martian next-hop database\n")
7480 {
7481 struct bgp *bgp = NULL;
7482 int idx = 0;
7483 char *name = NULL;
7484
7485 /* [<vrf> VIEWVRFNAME] */
7486 if (argv_find(argv, argc, "vrf", &idx)) {
7487 name = argv[idx + 1]->arg;
7488 if (name && strmatch(name, VRF_DEFAULT_NAME))
7489 name = NULL;
7490 } else if (argv_find(argv, argc, "view", &idx))
7491 /* [<view> VIEWVRFNAME] */
7492 name = argv[idx + 1]->arg;
7493 if (name)
7494 bgp = bgp_lookup_by_name(name);
7495 else
7496 bgp = bgp_get_default();
7497
7498 if (!bgp) {
7499 vty_out(vty, "%% No BGP process is configured\n");
7500 return CMD_WARNING;
7501 }
7502 bgp_show_martian_nexthops(vty, bgp);
7503
7504 return CMD_SUCCESS;
7505 }
7506
7507 DEFUN (show_bgp_memory,
7508 show_bgp_memory_cmd,
7509 "show [ip] bgp memory",
7510 SHOW_STR
7511 IP_STR
7512 BGP_STR
7513 "Global BGP memory statistics\n")
7514 {
7515 char memstrbuf[MTYPE_MEMSTR_LEN];
7516 unsigned long count;
7517
7518 /* RIB related usage stats */
7519 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7520 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7521 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7522 count * sizeof(struct bgp_node)));
7523
7524 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7525 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7526 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7527 count * sizeof(struct bgp_info)));
7528 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7529 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7530 count,
7531 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7532 count * sizeof(struct bgp_info_extra)));
7533
7534 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7535 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7537 count * sizeof(struct bgp_static)));
7538
7539 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7540 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7541 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7542 count * sizeof(struct bpacket)));
7543
7544 /* Adj-In/Out */
7545 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7546 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7547 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7548 count * sizeof(struct bgp_adj_in)));
7549 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7550 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7551 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7552 count * sizeof(struct bgp_adj_out)));
7553
7554 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7555 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7556 count,
7557 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7558 count * sizeof(struct bgp_nexthop_cache)));
7559
7560 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7561 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7562 count,
7563 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7564 count * sizeof(struct bgp_damp_info)));
7565
7566 /* Attributes */
7567 count = attr_count();
7568 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7569 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7570 count * sizeof(struct attr)));
7571
7572 if ((count = attr_unknown_count()))
7573 vty_out(vty, "%ld unknown attributes\n", count);
7574
7575 /* AS_PATH attributes */
7576 count = aspath_count();
7577 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7578 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7579 count * sizeof(struct aspath)));
7580
7581 count = mtype_stats_alloc(MTYPE_AS_SEG);
7582 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7583 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7584 count * sizeof(struct assegment)));
7585
7586 /* Other attributes */
7587 if ((count = community_count()))
7588 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7589 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7590 count * sizeof(struct community)));
7591 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7592 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7593 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7594 count * sizeof(struct ecommunity)));
7595 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7596 vty_out(vty,
7597 "%ld BGP large-community entries, using %s of memory\n",
7598 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7599 count * sizeof(struct lcommunity)));
7600
7601 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7602 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7603 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7604 count * sizeof(struct cluster_list)));
7605
7606 /* Peer related usage */
7607 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7608 vty_out(vty, "%ld peers, using %s of memory\n", count,
7609 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7610 count * sizeof(struct peer)));
7611
7612 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7613 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7614 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7615 count * sizeof(struct peer_group)));
7616
7617 /* Other */
7618 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7619 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7620 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7621 count * sizeof(struct hash)));
7622 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7623 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7624 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7625 count * sizeof(struct hash_backet)));
7626 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7627 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7628 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7629 count * sizeof(regex_t)));
7630 return CMD_SUCCESS;
7631 }
7632
7633 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7634 {
7635 json_object *bestpath = json_object_new_object();
7636
7637 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7638 json_object_string_add(bestpath, "asPath", "ignore");
7639
7640 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7641 json_object_string_add(bestpath, "asPath", "confed");
7642
7643 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7644 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7645 json_object_string_add(bestpath, "multiPathRelax",
7646 "as-set");
7647 else
7648 json_object_string_add(bestpath, "multiPathRelax",
7649 "true");
7650 } else
7651 json_object_string_add(bestpath, "multiPathRelax", "false");
7652
7653 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7654 json_object_string_add(bestpath, "compareRouterId", "true");
7655 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7656 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7657 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7658 json_object_string_add(bestpath, "med", "confed");
7659 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7660 json_object_string_add(bestpath, "med",
7661 "missing-as-worst");
7662 else
7663 json_object_string_add(bestpath, "med", "true");
7664 }
7665
7666 json_object_object_add(json, "bestPath", bestpath);
7667 }
7668
7669 /* Show BGP peer's summary information. */
7670 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7671 bool use_json, json_object *json)
7672 {
7673 struct peer *peer;
7674 struct listnode *node, *nnode;
7675 unsigned int count = 0, dn_count = 0;
7676 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7677 char neighbor_buf[VTY_BUFSIZ];
7678 int neighbor_col_default_width = 16;
7679 int len;
7680 int max_neighbor_width = 0;
7681 int pfx_rcd_safi;
7682 json_object *json_peer = NULL;
7683 json_object *json_peers = NULL;
7684
7685 /* labeled-unicast routes are installed in the unicast table so in order
7686 * to
7687 * display the correct PfxRcd value we must look at SAFI_UNICAST
7688 */
7689 if (safi == SAFI_LABELED_UNICAST)
7690 pfx_rcd_safi = SAFI_UNICAST;
7691 else
7692 pfx_rcd_safi = safi;
7693
7694 if (use_json) {
7695 if (json == NULL)
7696 json = json_object_new_object();
7697
7698 json_peers = json_object_new_object();
7699 } else {
7700 /* Loop over all neighbors that will be displayed to determine
7701 * how many
7702 * characters are needed for the Neighbor column
7703 */
7704 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7705 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7706 continue;
7707
7708 if (peer->afc[afi][safi]) {
7709 memset(dn_flag, '\0', sizeof(dn_flag));
7710 if (peer_dynamic_neighbor(peer))
7711 dn_flag[0] = '*';
7712
7713 if (peer->hostname
7714 && bgp_flag_check(bgp,
7715 BGP_FLAG_SHOW_HOSTNAME))
7716 sprintf(neighbor_buf, "%s%s(%s) ",
7717 dn_flag, peer->hostname,
7718 peer->host);
7719 else
7720 sprintf(neighbor_buf, "%s%s ", dn_flag,
7721 peer->host);
7722
7723 len = strlen(neighbor_buf);
7724
7725 if (len > max_neighbor_width)
7726 max_neighbor_width = len;
7727 }
7728 }
7729
7730 /* Originally we displayed the Neighbor column as 16
7731 * characters wide so make that the default
7732 */
7733 if (max_neighbor_width < neighbor_col_default_width)
7734 max_neighbor_width = neighbor_col_default_width;
7735 }
7736
7737 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7738 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7739 continue;
7740
7741 if (!peer->afc[afi][safi])
7742 continue;
7743
7744 if (!count) {
7745 unsigned long ents;
7746 char memstrbuf[MTYPE_MEMSTR_LEN];
7747 int64_t vrf_id_ui;
7748
7749 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7750 ? -1
7751 : (int64_t)bgp->vrf_id;
7752
7753 /* Usage summary and header */
7754 if (use_json) {
7755 json_object_string_add(
7756 json, "routerId",
7757 inet_ntoa(bgp->router_id));
7758 json_object_int_add(json, "as", bgp->as);
7759 json_object_int_add(json, "vrfId", vrf_id_ui);
7760 json_object_string_add(
7761 json, "vrfName",
7762 (bgp->inst_type
7763 == BGP_INSTANCE_TYPE_DEFAULT)
7764 ? "Default"
7765 : bgp->name);
7766 } else {
7767 vty_out(vty,
7768 "BGP router identifier %s, local AS number %u vrf-id %d",
7769 inet_ntoa(bgp->router_id), bgp->as,
7770 bgp->vrf_id == VRF_UNKNOWN
7771 ? -1
7772 : (int)bgp->vrf_id);
7773 vty_out(vty, "\n");
7774 }
7775
7776 if (bgp_update_delay_configured(bgp)) {
7777 if (use_json) {
7778 json_object_int_add(
7779 json, "updateDelayLimit",
7780 bgp->v_update_delay);
7781
7782 if (bgp->v_update_delay
7783 != bgp->v_establish_wait)
7784 json_object_int_add(
7785 json,
7786 "updateDelayEstablishWait",
7787 bgp->v_establish_wait);
7788
7789 if (bgp_update_delay_active(bgp)) {
7790 json_object_string_add(
7791 json,
7792 "updateDelayFirstNeighbor",
7793 bgp->update_delay_begin_time);
7794 json_object_boolean_true_add(
7795 json,
7796 "updateDelayInProgress");
7797 } else {
7798 if (bgp->update_delay_over) {
7799 json_object_string_add(
7800 json,
7801 "updateDelayFirstNeighbor",
7802 bgp->update_delay_begin_time);
7803 json_object_string_add(
7804 json,
7805 "updateDelayBestpathResumed",
7806 bgp->update_delay_end_time);
7807 json_object_string_add(
7808 json,
7809 "updateDelayZebraUpdateResume",
7810 bgp->update_delay_zebra_resume_time);
7811 json_object_string_add(
7812 json,
7813 "updateDelayPeerUpdateResume",
7814 bgp->update_delay_peers_resume_time);
7815 }
7816 }
7817 } else {
7818 vty_out(vty,
7819 "Read-only mode update-delay limit: %d seconds\n",
7820 bgp->v_update_delay);
7821 if (bgp->v_update_delay
7822 != bgp->v_establish_wait)
7823 vty_out(vty,
7824 " Establish wait: %d seconds\n",
7825 bgp->v_establish_wait);
7826
7827 if (bgp_update_delay_active(bgp)) {
7828 vty_out(vty,
7829 " First neighbor established: %s\n",
7830 bgp->update_delay_begin_time);
7831 vty_out(vty,
7832 " Delay in progress\n");
7833 } else {
7834 if (bgp->update_delay_over) {
7835 vty_out(vty,
7836 " First neighbor established: %s\n",
7837 bgp->update_delay_begin_time);
7838 vty_out(vty,
7839 " Best-paths resumed: %s\n",
7840 bgp->update_delay_end_time);
7841 vty_out(vty,
7842 " zebra update resumed: %s\n",
7843 bgp->update_delay_zebra_resume_time);
7844 vty_out(vty,
7845 " peers update resumed: %s\n",
7846 bgp->update_delay_peers_resume_time);
7847 }
7848 }
7849 }
7850 }
7851
7852 if (use_json) {
7853 if (bgp_maxmed_onstartup_configured(bgp)
7854 && bgp->maxmed_active)
7855 json_object_boolean_true_add(
7856 json, "maxMedOnStartup");
7857 if (bgp->v_maxmed_admin)
7858 json_object_boolean_true_add(
7859 json, "maxMedAdministrative");
7860
7861 json_object_int_add(
7862 json, "tableVersion",
7863 bgp_table_version(bgp->rib[afi][safi]));
7864
7865 ents = bgp_table_count(bgp->rib[afi][safi]);
7866 json_object_int_add(json, "ribCount", ents);
7867 json_object_int_add(
7868 json, "ribMemory",
7869 ents * sizeof(struct bgp_node));
7870
7871 ents = listcount(bgp->peer);
7872 json_object_int_add(json, "peerCount", ents);
7873 json_object_int_add(json, "peerMemory",
7874 ents * sizeof(struct peer));
7875
7876 if ((ents = listcount(bgp->group))) {
7877 json_object_int_add(
7878 json, "peerGroupCount", ents);
7879 json_object_int_add(
7880 json, "peerGroupMemory",
7881 ents * sizeof(struct
7882 peer_group));
7883 }
7884
7885 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7886 BGP_CONFIG_DAMPENING))
7887 json_object_boolean_true_add(
7888 json, "dampeningEnabled");
7889 } else {
7890 if (bgp_maxmed_onstartup_configured(bgp)
7891 && bgp->maxmed_active)
7892 vty_out(vty,
7893 "Max-med on-startup active\n");
7894 if (bgp->v_maxmed_admin)
7895 vty_out(vty,
7896 "Max-med administrative active\n");
7897
7898 vty_out(vty, "BGP table version %" PRIu64 "\n",
7899 bgp_table_version(bgp->rib[afi][safi]));
7900
7901 ents = bgp_table_count(bgp->rib[afi][safi]);
7902 vty_out(vty,
7903 "RIB entries %ld, using %s of memory\n",
7904 ents,
7905 mtype_memstr(memstrbuf,
7906 sizeof(memstrbuf),
7907 ents * sizeof(struct
7908 bgp_node)));
7909
7910 /* Peer related usage */
7911 ents = listcount(bgp->peer);
7912 vty_out(vty, "Peers %ld, using %s of memory\n",
7913 ents,
7914 mtype_memstr(
7915 memstrbuf, sizeof(memstrbuf),
7916 ents * sizeof(struct peer)));
7917
7918 if ((ents = listcount(bgp->group)))
7919 vty_out(vty,
7920 "Peer groups %ld, using %s of memory\n",
7921 ents,
7922 mtype_memstr(
7923 memstrbuf,
7924 sizeof(memstrbuf),
7925 ents * sizeof(struct
7926 peer_group)));
7927
7928 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7929 BGP_CONFIG_DAMPENING))
7930 vty_out(vty, "Dampening enabled.\n");
7931 vty_out(vty, "\n");
7932
7933 /* Subtract 8 here because 'Neighbor' is
7934 * 8 characters */
7935 vty_out(vty, "Neighbor");
7936 vty_out(vty, "%*s", max_neighbor_width - 8,
7937 " ");
7938 vty_out(vty,
7939 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7940 }
7941 }
7942
7943 count++;
7944
7945 if (use_json) {
7946 json_peer = json_object_new_object();
7947
7948 if (peer_dynamic_neighbor(peer)) {
7949 dn_count++;
7950 json_object_boolean_true_add(json_peer,
7951 "dynamicPeer");
7952 }
7953
7954 if (peer->hostname)
7955 json_object_string_add(json_peer, "hostname",
7956 peer->hostname);
7957
7958 if (peer->domainname)
7959 json_object_string_add(json_peer, "domainname",
7960 peer->domainname);
7961
7962 json_object_int_add(json_peer, "remoteAs", peer->as);
7963 json_object_int_add(json_peer, "version", 4);
7964 json_object_int_add(json_peer, "msgRcvd",
7965 PEER_TOTAL_RX(peer));
7966 json_object_int_add(json_peer, "msgSent",
7967 PEER_TOTAL_TX(peer));
7968
7969 json_object_int_add(json_peer, "tableVersion",
7970 peer->version[afi][safi]);
7971 json_object_int_add(json_peer, "outq",
7972 peer->obuf->count);
7973 json_object_int_add(json_peer, "inq", 0);
7974 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7975 use_json, json_peer);
7976 json_object_int_add(json_peer, "prefixReceivedCount",
7977 peer->pcount[afi][pfx_rcd_safi]);
7978
7979 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7980 json_object_string_add(json_peer, "state",
7981 "Idle (Admin)");
7982 else if (peer->afc_recv[afi][safi])
7983 json_object_string_add(
7984 json_peer, "state",
7985 lookup_msg(bgp_status_msg, peer->status,
7986 NULL));
7987 else if (CHECK_FLAG(peer->sflags,
7988 PEER_STATUS_PREFIX_OVERFLOW))
7989 json_object_string_add(json_peer, "state",
7990 "Idle (PfxCt)");
7991 else
7992 json_object_string_add(
7993 json_peer, "state",
7994 lookup_msg(bgp_status_msg, peer->status,
7995 NULL));
7996
7997 if (peer->conf_if)
7998 json_object_string_add(json_peer, "idType",
7999 "interface");
8000 else if (peer->su.sa.sa_family == AF_INET)
8001 json_object_string_add(json_peer, "idType",
8002 "ipv4");
8003 else if (peer->su.sa.sa_family == AF_INET6)
8004 json_object_string_add(json_peer, "idType",
8005 "ipv6");
8006
8007 json_object_object_add(json_peers, peer->host,
8008 json_peer);
8009 } else {
8010 memset(dn_flag, '\0', sizeof(dn_flag));
8011 if (peer_dynamic_neighbor(peer)) {
8012 dn_count++;
8013 dn_flag[0] = '*';
8014 }
8015
8016 if (peer->hostname
8017 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
8018 len = vty_out(vty, "%s%s(%s)", dn_flag,
8019 peer->hostname, peer->host);
8020 else
8021 len = vty_out(vty, "%s%s", dn_flag, peer->host);
8022
8023 /* pad the neighbor column with spaces */
8024 if (len < max_neighbor_width)
8025 vty_out(vty, "%*s", max_neighbor_width - len,
8026 " ");
8027
8028 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
8029 peer->as, PEER_TOTAL_RX(peer),
8030 PEER_TOTAL_TX(peer), peer->version[afi][safi],
8031 0, peer->obuf->count,
8032 peer_uptime(peer->uptime, timebuf,
8033 BGP_UPTIME_LEN, 0, NULL));
8034
8035 if (peer->status == Established)
8036 if (peer->afc_recv[afi][safi])
8037 vty_out(vty, " %12ld",
8038 peer->pcount[afi]
8039 [pfx_rcd_safi]);
8040 else
8041 vty_out(vty, " NoNeg");
8042 else {
8043 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
8044 vty_out(vty, " Idle (Admin)");
8045 else if (CHECK_FLAG(
8046 peer->sflags,
8047 PEER_STATUS_PREFIX_OVERFLOW))
8048 vty_out(vty, " Idle (PfxCt)");
8049 else
8050 vty_out(vty, " %12s",
8051 lookup_msg(bgp_status_msg,
8052 peer->status, NULL));
8053 }
8054 vty_out(vty, "\n");
8055 }
8056 }
8057
8058 if (use_json) {
8059 json_object_object_add(json, "peers", json_peers);
8060
8061 json_object_int_add(json, "totalPeers", count);
8062 json_object_int_add(json, "dynamicPeers", dn_count);
8063
8064 bgp_show_bestpath_json(bgp, json);
8065
8066 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8067 json, JSON_C_TO_STRING_PRETTY));
8068 json_object_free(json);
8069 } else {
8070 if (count)
8071 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8072 else {
8073 vty_out(vty, "No %s neighbor is configured\n",
8074 afi_safi_print(afi, safi));
8075 }
8076
8077 if (dn_count) {
8078 vty_out(vty, "* - dynamic neighbor\n");
8079 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8080 dn_count, bgp->dynamic_neighbors_limit);
8081 }
8082 }
8083
8084 return CMD_SUCCESS;
8085 }
8086
8087 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8088 int safi, bool use_json,
8089 json_object *json)
8090 {
8091 int is_first = 1;
8092 int afi_wildcard = (afi == AFI_MAX);
8093 int safi_wildcard = (safi == SAFI_MAX);
8094 int is_wildcard = (afi_wildcard || safi_wildcard);
8095 bool nbr_output = false;
8096
8097 if (use_json && is_wildcard)
8098 vty_out(vty, "{\n");
8099 if (afi_wildcard)
8100 afi = 1; /* AFI_IP */
8101 while (afi < AFI_MAX) {
8102 if (safi_wildcard)
8103 safi = 1; /* SAFI_UNICAST */
8104 while (safi < SAFI_MAX) {
8105 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8106 nbr_output = true;
8107 if (is_wildcard) {
8108 /*
8109 * So limit output to those afi/safi
8110 * pairs that
8111 * actualy have something interesting in
8112 * them
8113 */
8114 if (use_json) {
8115 json = json_object_new_object();
8116
8117 if (!is_first)
8118 vty_out(vty, ",\n");
8119 else
8120 is_first = 0;
8121
8122 vty_out(vty, "\"%s\":",
8123 afi_safi_json(afi,
8124 safi));
8125 } else {
8126 vty_out(vty, "\n%s Summary:\n",
8127 afi_safi_print(afi,
8128 safi));
8129 }
8130 }
8131 bgp_show_summary(vty, bgp, afi, safi, use_json,
8132 json);
8133 }
8134 safi++;
8135 if (!safi_wildcard)
8136 safi = SAFI_MAX;
8137 }
8138 afi++;
8139 if (!afi_wildcard)
8140 afi = AFI_MAX;
8141 }
8142
8143 if (use_json && is_wildcard)
8144 vty_out(vty, "}\n");
8145 else if (!nbr_output) {
8146 if (use_json)
8147 vty_out(vty, "{}\n");
8148 else
8149 vty_out(vty, "%% No BGP neighbors found\n");
8150 }
8151 }
8152
8153 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8154 safi_t safi, bool use_json)
8155 {
8156 struct listnode *node, *nnode;
8157 struct bgp *bgp;
8158 json_object *json = NULL;
8159 int is_first = 1;
8160 bool nbr_output = false;
8161
8162 if (use_json)
8163 vty_out(vty, "{\n");
8164
8165 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8166 nbr_output = true;
8167 if (use_json) {
8168 json = json_object_new_object();
8169
8170 if (!is_first)
8171 vty_out(vty, ",\n");
8172 else
8173 is_first = 0;
8174
8175 vty_out(vty, "\"%s\":",
8176 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8177 ? "Default"
8178 : bgp->name);
8179 } else {
8180 vty_out(vty, "\nInstance %s:\n",
8181 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8182 ? "Default"
8183 : bgp->name);
8184 }
8185 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8186 }
8187
8188 if (use_json)
8189 vty_out(vty, "}\n");
8190 else if (!nbr_output)
8191 vty_out(vty, "%% BGP instance not found\n");
8192 }
8193
8194 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8195 safi_t safi, bool use_json)
8196 {
8197 struct bgp *bgp;
8198
8199 if (name) {
8200 if (strmatch(name, "all")) {
8201 bgp_show_all_instances_summary_vty(vty, afi, safi,
8202 use_json);
8203 return CMD_SUCCESS;
8204 } else {
8205 bgp = bgp_lookup_by_name(name);
8206
8207 if (!bgp) {
8208 if (use_json)
8209 vty_out(vty, "{}\n");
8210 else
8211 vty_out(vty,
8212 "%% BGP instance not found\n");
8213 return CMD_WARNING;
8214 }
8215
8216 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8217 NULL);
8218 return CMD_SUCCESS;
8219 }
8220 }
8221
8222 bgp = bgp_get_default();
8223
8224 if (bgp)
8225 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8226 else {
8227 if (use_json)
8228 vty_out(vty, "{}\n");
8229 else
8230 vty_out(vty, "%% BGP instance not found\n");
8231 return CMD_WARNING;
8232 }
8233
8234 return CMD_SUCCESS;
8235 }
8236
8237 /* `show [ip] bgp summary' commands. */
8238 DEFUN (show_ip_bgp_summary,
8239 show_ip_bgp_summary_cmd,
8240 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8241 SHOW_STR
8242 IP_STR
8243 BGP_STR
8244 BGP_INSTANCE_HELP_STR
8245 BGP_AFI_HELP_STR
8246 BGP_SAFI_WITH_LABEL_HELP_STR
8247 "Summary of BGP neighbor status\n"
8248 JSON_STR)
8249 {
8250 char *vrf = NULL;
8251 afi_t afi = AFI_MAX;
8252 safi_t safi = SAFI_MAX;
8253
8254 int idx = 0;
8255
8256 /* show [ip] bgp */
8257 if (argv_find(argv, argc, "ip", &idx))
8258 afi = AFI_IP;
8259 /* [<vrf> VIEWVRFNAME] */
8260 if (argv_find(argv, argc, "vrf", &idx)) {
8261 vrf = argv[idx + 1]->arg;
8262 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
8263 vrf = NULL;
8264 } else if (argv_find(argv, argc, "view", &idx))
8265 /* [<view> VIEWVRFNAME] */
8266 vrf = argv[idx + 1]->arg;
8267 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8268 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8269 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8270 }
8271
8272 bool uj = use_json(argc, argv);
8273
8274 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8275 }
8276
8277 const char *afi_safi_print(afi_t afi, safi_t safi)
8278 {
8279 if (afi == AFI_IP && safi == SAFI_UNICAST)
8280 return "IPv4 Unicast";
8281 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8282 return "IPv4 Multicast";
8283 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8284 return "IPv4 Labeled Unicast";
8285 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8286 return "IPv4 VPN";
8287 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8288 return "IPv4 Encap";
8289 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8290 return "IPv4 Flowspec";
8291 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8292 return "IPv6 Unicast";
8293 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8294 return "IPv6 Multicast";
8295 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8296 return "IPv6 Labeled Unicast";
8297 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8298 return "IPv6 VPN";
8299 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8300 return "IPv6 Encap";
8301 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8302 return "IPv6 Flowspec";
8303 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8304 return "L2VPN EVPN";
8305 else
8306 return "Unknown";
8307 }
8308
8309 /*
8310 * Please note that we have intentionally camelCased
8311 * the return strings here. So if you want
8312 * to use this function, please ensure you
8313 * are doing this within json output
8314 */
8315 const char *afi_safi_json(afi_t afi, safi_t safi)
8316 {
8317 if (afi == AFI_IP && safi == SAFI_UNICAST)
8318 return "ipv4Unicast";
8319 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8320 return "ipv4Multicast";
8321 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8322 return "ipv4LabeledUnicast";
8323 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8324 return "ipv4Vpn";
8325 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8326 return "ipv4Encap";
8327 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8328 return "ipv4Flowspec";
8329 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8330 return "ipv6Unicast";
8331 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8332 return "ipv6Multicast";
8333 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8334 return "ipv6LabeledUnicast";
8335 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8336 return "ipv6Vpn";
8337 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8338 return "ipv6Encap";
8339 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8340 return "ipv6Flowspec";
8341 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8342 return "l2VpnEvpn";
8343 else
8344 return "Unknown";
8345 }
8346
8347 /* Show BGP peer's information. */
8348 enum show_type { show_all, show_peer };
8349
8350 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8351 afi_t afi, safi_t safi,
8352 uint16_t adv_smcap, uint16_t adv_rmcap,
8353 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8354 bool use_json, json_object *json_pref)
8355 {
8356 /* Send-Mode */
8357 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8358 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8359 if (use_json) {
8360 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8361 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8362 json_object_string_add(json_pref, "sendMode",
8363 "advertisedAndReceived");
8364 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8365 json_object_string_add(json_pref, "sendMode",
8366 "advertised");
8367 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8368 json_object_string_add(json_pref, "sendMode",
8369 "received");
8370 } else {
8371 vty_out(vty, " Send-mode: ");
8372 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8373 vty_out(vty, "advertised");
8374 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8375 vty_out(vty, "%sreceived",
8376 CHECK_FLAG(p->af_cap[afi][safi],
8377 adv_smcap)
8378 ? ", "
8379 : "");
8380 vty_out(vty, "\n");
8381 }
8382 }
8383
8384 /* Receive-Mode */
8385 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8386 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8387 if (use_json) {
8388 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8389 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8390 json_object_string_add(json_pref, "recvMode",
8391 "advertisedAndReceived");
8392 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8393 json_object_string_add(json_pref, "recvMode",
8394 "advertised");
8395 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8396 json_object_string_add(json_pref, "recvMode",
8397 "received");
8398 } else {
8399 vty_out(vty, " Receive-mode: ");
8400 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8401 vty_out(vty, "advertised");
8402 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8403 vty_out(vty, "%sreceived",
8404 CHECK_FLAG(p->af_cap[afi][safi],
8405 adv_rmcap)
8406 ? ", "
8407 : "");
8408 vty_out(vty, "\n");
8409 }
8410 }
8411 }
8412
8413 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8414 safi_t safi, bool use_json,
8415 json_object *json_neigh)
8416 {
8417 struct bgp_filter *filter;
8418 struct peer_af *paf;
8419 char orf_pfx_name[BUFSIZ];
8420 int orf_pfx_count;
8421 json_object *json_af = NULL;
8422 json_object *json_prefA = NULL;
8423 json_object *json_prefB = NULL;
8424 json_object *json_addr = NULL;
8425
8426 if (use_json) {
8427 json_addr = json_object_new_object();
8428 json_af = json_object_new_object();
8429 filter = &p->filter[afi][safi];
8430
8431 if (peer_group_active(p))
8432 json_object_string_add(json_addr, "peerGroupMember",
8433 p->group->name);
8434
8435 paf = peer_af_find(p, afi, safi);
8436 if (paf && PAF_SUBGRP(paf)) {
8437 json_object_int_add(json_addr, "updateGroupId",
8438 PAF_UPDGRP(paf)->id);
8439 json_object_int_add(json_addr, "subGroupId",
8440 PAF_SUBGRP(paf)->id);
8441 json_object_int_add(json_addr, "packetQueueLength",
8442 bpacket_queue_virtual_length(paf));
8443 }
8444
8445 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8446 || CHECK_FLAG(p->af_cap[afi][safi],
8447 PEER_CAP_ORF_PREFIX_SM_RCV)
8448 || CHECK_FLAG(p->af_cap[afi][safi],
8449 PEER_CAP_ORF_PREFIX_RM_ADV)
8450 || CHECK_FLAG(p->af_cap[afi][safi],
8451 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8452 json_object_int_add(json_af, "orfType",
8453 ORF_TYPE_PREFIX);
8454 json_prefA = json_object_new_object();
8455 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8456 PEER_CAP_ORF_PREFIX_SM_ADV,
8457 PEER_CAP_ORF_PREFIX_RM_ADV,
8458 PEER_CAP_ORF_PREFIX_SM_RCV,
8459 PEER_CAP_ORF_PREFIX_RM_RCV,
8460 use_json, json_prefA);
8461 json_object_object_add(json_af, "orfPrefixList",
8462 json_prefA);
8463 }
8464
8465 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8466 || CHECK_FLAG(p->af_cap[afi][safi],
8467 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8468 || CHECK_FLAG(p->af_cap[afi][safi],
8469 PEER_CAP_ORF_PREFIX_RM_ADV)
8470 || CHECK_FLAG(p->af_cap[afi][safi],
8471 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8472 json_object_int_add(json_af, "orfOldType",
8473 ORF_TYPE_PREFIX_OLD);
8474 json_prefB = json_object_new_object();
8475 bgp_show_peer_afi_orf_cap(
8476 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8477 PEER_CAP_ORF_PREFIX_RM_ADV,
8478 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8479 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8480 json_prefB);
8481 json_object_object_add(json_af, "orfOldPrefixList",
8482 json_prefB);
8483 }
8484
8485 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8486 || CHECK_FLAG(p->af_cap[afi][safi],
8487 PEER_CAP_ORF_PREFIX_SM_RCV)
8488 || CHECK_FLAG(p->af_cap[afi][safi],
8489 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8490 || CHECK_FLAG(p->af_cap[afi][safi],
8491 PEER_CAP_ORF_PREFIX_RM_ADV)
8492 || CHECK_FLAG(p->af_cap[afi][safi],
8493 PEER_CAP_ORF_PREFIX_RM_RCV)
8494 || CHECK_FLAG(p->af_cap[afi][safi],
8495 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8496 json_object_object_add(json_addr, "afDependentCap",
8497 json_af);
8498 else
8499 json_object_free(json_af);
8500
8501 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8502 orf_pfx_count = prefix_bgp_show_prefix_list(
8503 NULL, afi, orf_pfx_name, use_json);
8504
8505 if (CHECK_FLAG(p->af_sflags[afi][safi],
8506 PEER_STATUS_ORF_PREFIX_SEND)
8507 || orf_pfx_count) {
8508 if (CHECK_FLAG(p->af_sflags[afi][safi],
8509 PEER_STATUS_ORF_PREFIX_SEND))
8510 json_object_boolean_true_add(json_neigh,
8511 "orfSent");
8512 if (orf_pfx_count)
8513 json_object_int_add(json_addr, "orfRecvCounter",
8514 orf_pfx_count);
8515 }
8516 if (CHECK_FLAG(p->af_sflags[afi][safi],
8517 PEER_STATUS_ORF_WAIT_REFRESH))
8518 json_object_string_add(
8519 json_addr, "orfFirstUpdate",
8520 "deferredUntilORFOrRouteRefreshRecvd");
8521
8522 if (CHECK_FLAG(p->af_flags[afi][safi],
8523 PEER_FLAG_REFLECTOR_CLIENT))
8524 json_object_boolean_true_add(json_addr,
8525 "routeReflectorClient");
8526 if (CHECK_FLAG(p->af_flags[afi][safi],
8527 PEER_FLAG_RSERVER_CLIENT))
8528 json_object_boolean_true_add(json_addr,
8529 "routeServerClient");
8530 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8531 json_object_boolean_true_add(json_addr,
8532 "inboundSoftConfigPermit");
8533
8534 if (CHECK_FLAG(p->af_flags[afi][safi],
8535 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8536 json_object_boolean_true_add(
8537 json_addr,
8538 "privateAsNumsAllReplacedInUpdatesToNbr");
8539 else if (CHECK_FLAG(p->af_flags[afi][safi],
8540 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8541 json_object_boolean_true_add(
8542 json_addr,
8543 "privateAsNumsReplacedInUpdatesToNbr");
8544 else if (CHECK_FLAG(p->af_flags[afi][safi],
8545 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8546 json_object_boolean_true_add(
8547 json_addr,
8548 "privateAsNumsAllRemovedInUpdatesToNbr");
8549 else if (CHECK_FLAG(p->af_flags[afi][safi],
8550 PEER_FLAG_REMOVE_PRIVATE_AS))
8551 json_object_boolean_true_add(
8552 json_addr,
8553 "privateAsNumsRemovedInUpdatesToNbr");
8554
8555 if (CHECK_FLAG(p->af_flags[afi][safi],
8556 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8557 json_object_boolean_true_add(json_addr,
8558 "addpathTxAllPaths");
8559
8560 if (CHECK_FLAG(p->af_flags[afi][safi],
8561 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8562 json_object_boolean_true_add(json_addr,
8563 "addpathTxBestpathPerAS");
8564
8565 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8566 json_object_string_add(json_addr,
8567 "overrideASNsInOutboundUpdates",
8568 "ifAspathEqualRemoteAs");
8569
8570 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8571 || CHECK_FLAG(p->af_flags[afi][safi],
8572 PEER_FLAG_FORCE_NEXTHOP_SELF))
8573 json_object_boolean_true_add(json_addr,
8574 "routerAlwaysNextHop");
8575 if (CHECK_FLAG(p->af_flags[afi][safi],
8576 PEER_FLAG_AS_PATH_UNCHANGED))
8577 json_object_boolean_true_add(
8578 json_addr, "unchangedAsPathPropogatedToNbr");
8579 if (CHECK_FLAG(p->af_flags[afi][safi],
8580 PEER_FLAG_NEXTHOP_UNCHANGED))
8581 json_object_boolean_true_add(
8582 json_addr, "unchangedNextHopPropogatedToNbr");
8583 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8584 json_object_boolean_true_add(
8585 json_addr, "unchangedMedPropogatedToNbr");
8586 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8587 || CHECK_FLAG(p->af_flags[afi][safi],
8588 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8589 if (CHECK_FLAG(p->af_flags[afi][safi],
8590 PEER_FLAG_SEND_COMMUNITY)
8591 && CHECK_FLAG(p->af_flags[afi][safi],
8592 PEER_FLAG_SEND_EXT_COMMUNITY))
8593 json_object_string_add(json_addr,
8594 "commAttriSentToNbr",
8595 "extendedAndStandard");
8596 else if (CHECK_FLAG(p->af_flags[afi][safi],
8597 PEER_FLAG_SEND_EXT_COMMUNITY))
8598 json_object_string_add(json_addr,
8599 "commAttriSentToNbr",
8600 "extended");
8601 else
8602 json_object_string_add(json_addr,
8603 "commAttriSentToNbr",
8604 "standard");
8605 }
8606 if (CHECK_FLAG(p->af_flags[afi][safi],
8607 PEER_FLAG_DEFAULT_ORIGINATE)) {
8608 if (p->default_rmap[afi][safi].name)
8609 json_object_string_add(
8610 json_addr, "defaultRouteMap",
8611 p->default_rmap[afi][safi].name);
8612
8613 if (paf && PAF_SUBGRP(paf)
8614 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8615 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8616 json_object_boolean_true_add(json_addr,
8617 "defaultSent");
8618 else
8619 json_object_boolean_true_add(json_addr,
8620 "defaultNotSent");
8621 }
8622
8623 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8624 if (is_evpn_enabled())
8625 json_object_boolean_true_add(
8626 json_addr, "advertiseAllVnis");
8627 }
8628
8629 if (filter->plist[FILTER_IN].name
8630 || filter->dlist[FILTER_IN].name
8631 || filter->aslist[FILTER_IN].name
8632 || filter->map[RMAP_IN].name)
8633 json_object_boolean_true_add(json_addr,
8634 "inboundPathPolicyConfig");
8635 if (filter->plist[FILTER_OUT].name
8636 || filter->dlist[FILTER_OUT].name
8637 || filter->aslist[FILTER_OUT].name
8638 || filter->map[RMAP_OUT].name || filter->usmap.name)
8639 json_object_boolean_true_add(
8640 json_addr, "outboundPathPolicyConfig");
8641
8642 /* prefix-list */
8643 if (filter->plist[FILTER_IN].name)
8644 json_object_string_add(json_addr,
8645 "incomingUpdatePrefixFilterList",
8646 filter->plist[FILTER_IN].name);
8647 if (filter->plist[FILTER_OUT].name)
8648 json_object_string_add(json_addr,
8649 "outgoingUpdatePrefixFilterList",
8650 filter->plist[FILTER_OUT].name);
8651
8652 /* distribute-list */
8653 if (filter->dlist[FILTER_IN].name)
8654 json_object_string_add(
8655 json_addr, "incomingUpdateNetworkFilterList",
8656 filter->dlist[FILTER_IN].name);
8657 if (filter->dlist[FILTER_OUT].name)
8658 json_object_string_add(
8659 json_addr, "outgoingUpdateNetworkFilterList",
8660 filter->dlist[FILTER_OUT].name);
8661
8662 /* filter-list. */
8663 if (filter->aslist[FILTER_IN].name)
8664 json_object_string_add(json_addr,
8665 "incomingUpdateAsPathFilterList",
8666 filter->aslist[FILTER_IN].name);
8667 if (filter->aslist[FILTER_OUT].name)
8668 json_object_string_add(json_addr,
8669 "outgoingUpdateAsPathFilterList",
8670 filter->aslist[FILTER_OUT].name);
8671
8672 /* route-map. */
8673 if (filter->map[RMAP_IN].name)
8674 json_object_string_add(
8675 json_addr, "routeMapForIncomingAdvertisements",
8676 filter->map[RMAP_IN].name);
8677 if (filter->map[RMAP_OUT].name)
8678 json_object_string_add(
8679 json_addr, "routeMapForOutgoingAdvertisements",
8680 filter->map[RMAP_OUT].name);
8681
8682 /* unsuppress-map */
8683 if (filter->usmap.name)
8684 json_object_string_add(json_addr,
8685 "selectiveUnsuppressRouteMap",
8686 filter->usmap.name);
8687
8688 /* Receive prefix count */
8689 json_object_int_add(json_addr, "acceptedPrefixCounter",
8690 p->pcount[afi][safi]);
8691
8692 /* Maximum prefix */
8693 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8694 json_object_int_add(json_addr, "prefixAllowedMax",
8695 p->pmax[afi][safi]);
8696 if (CHECK_FLAG(p->af_flags[afi][safi],
8697 PEER_FLAG_MAX_PREFIX_WARNING))
8698 json_object_boolean_true_add(
8699 json_addr, "prefixAllowedMaxWarning");
8700 json_object_int_add(json_addr,
8701 "prefixAllowedWarningThresh",
8702 p->pmax_threshold[afi][safi]);
8703 if (p->pmax_restart[afi][safi])
8704 json_object_int_add(
8705 json_addr,
8706 "prefixAllowedRestartIntervalMsecs",
8707 p->pmax_restart[afi][safi] * 60000);
8708 }
8709 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8710 json_addr);
8711
8712 } else {
8713 filter = &p->filter[afi][safi];
8714
8715 vty_out(vty, " For address family: %s\n",
8716 afi_safi_print(afi, safi));
8717
8718 if (peer_group_active(p))
8719 vty_out(vty, " %s peer-group member\n",
8720 p->group->name);
8721
8722 paf = peer_af_find(p, afi, safi);
8723 if (paf && PAF_SUBGRP(paf)) {
8724 vty_out(vty, " Update group %" PRIu64
8725 ", subgroup %" PRIu64 "\n",
8726 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8727 vty_out(vty, " Packet Queue length %d\n",
8728 bpacket_queue_virtual_length(paf));
8729 } else {
8730 vty_out(vty, " Not part of any update group\n");
8731 }
8732 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8733 || CHECK_FLAG(p->af_cap[afi][safi],
8734 PEER_CAP_ORF_PREFIX_SM_RCV)
8735 || CHECK_FLAG(p->af_cap[afi][safi],
8736 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8737 || CHECK_FLAG(p->af_cap[afi][safi],
8738 PEER_CAP_ORF_PREFIX_RM_ADV)
8739 || CHECK_FLAG(p->af_cap[afi][safi],
8740 PEER_CAP_ORF_PREFIX_RM_RCV)
8741 || CHECK_FLAG(p->af_cap[afi][safi],
8742 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8743 vty_out(vty, " AF-dependant capabilities:\n");
8744
8745 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8746 || CHECK_FLAG(p->af_cap[afi][safi],
8747 PEER_CAP_ORF_PREFIX_SM_RCV)
8748 || CHECK_FLAG(p->af_cap[afi][safi],
8749 PEER_CAP_ORF_PREFIX_RM_ADV)
8750 || CHECK_FLAG(p->af_cap[afi][safi],
8751 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8752 vty_out(vty,
8753 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8754 ORF_TYPE_PREFIX);
8755 bgp_show_peer_afi_orf_cap(
8756 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8757 PEER_CAP_ORF_PREFIX_RM_ADV,
8758 PEER_CAP_ORF_PREFIX_SM_RCV,
8759 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8760 }
8761 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8762 || CHECK_FLAG(p->af_cap[afi][safi],
8763 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8764 || CHECK_FLAG(p->af_cap[afi][safi],
8765 PEER_CAP_ORF_PREFIX_RM_ADV)
8766 || CHECK_FLAG(p->af_cap[afi][safi],
8767 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8768 vty_out(vty,
8769 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8770 ORF_TYPE_PREFIX_OLD);
8771 bgp_show_peer_afi_orf_cap(
8772 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8773 PEER_CAP_ORF_PREFIX_RM_ADV,
8774 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8775 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8776 }
8777
8778 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8779 orf_pfx_count = prefix_bgp_show_prefix_list(
8780 NULL, afi, orf_pfx_name, use_json);
8781
8782 if (CHECK_FLAG(p->af_sflags[afi][safi],
8783 PEER_STATUS_ORF_PREFIX_SEND)
8784 || orf_pfx_count) {
8785 vty_out(vty, " Outbound Route Filter (ORF):");
8786 if (CHECK_FLAG(p->af_sflags[afi][safi],
8787 PEER_STATUS_ORF_PREFIX_SEND))
8788 vty_out(vty, " sent;");
8789 if (orf_pfx_count)
8790 vty_out(vty, " received (%d entries)",
8791 orf_pfx_count);
8792 vty_out(vty, "\n");
8793 }
8794 if (CHECK_FLAG(p->af_sflags[afi][safi],
8795 PEER_STATUS_ORF_WAIT_REFRESH))
8796 vty_out(vty,
8797 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8798
8799 if (CHECK_FLAG(p->af_flags[afi][safi],
8800 PEER_FLAG_REFLECTOR_CLIENT))
8801 vty_out(vty, " Route-Reflector Client\n");
8802 if (CHECK_FLAG(p->af_flags[afi][safi],
8803 PEER_FLAG_RSERVER_CLIENT))
8804 vty_out(vty, " Route-Server Client\n");
8805 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8806 vty_out(vty,
8807 " Inbound soft reconfiguration allowed\n");
8808
8809 if (CHECK_FLAG(p->af_flags[afi][safi],
8810 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8811 vty_out(vty,
8812 " Private AS numbers (all) replaced in updates to this neighbor\n");
8813 else if (CHECK_FLAG(p->af_flags[afi][safi],
8814 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8815 vty_out(vty,
8816 " Private AS numbers replaced in updates to this neighbor\n");
8817 else if (CHECK_FLAG(p->af_flags[afi][safi],
8818 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8819 vty_out(vty,
8820 " Private AS numbers (all) removed in updates to this neighbor\n");
8821 else if (CHECK_FLAG(p->af_flags[afi][safi],
8822 PEER_FLAG_REMOVE_PRIVATE_AS))
8823 vty_out(vty,
8824 " Private AS numbers removed in updates to this neighbor\n");
8825
8826 if (CHECK_FLAG(p->af_flags[afi][safi],
8827 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8828 vty_out(vty, " Advertise all paths via addpath\n");
8829
8830 if (CHECK_FLAG(p->af_flags[afi][safi],
8831 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8832 vty_out(vty,
8833 " Advertise bestpath per AS via addpath\n");
8834
8835 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8836 vty_out(vty,
8837 " Override ASNs in outbound updates if aspath equals remote-as\n");
8838
8839 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8840 || CHECK_FLAG(p->af_flags[afi][safi],
8841 PEER_FLAG_FORCE_NEXTHOP_SELF))
8842 vty_out(vty, " NEXT_HOP is always this router\n");
8843 if (CHECK_FLAG(p->af_flags[afi][safi],
8844 PEER_FLAG_AS_PATH_UNCHANGED))
8845 vty_out(vty,
8846 " AS_PATH is propagated unchanged to this neighbor\n");
8847 if (CHECK_FLAG(p->af_flags[afi][safi],
8848 PEER_FLAG_NEXTHOP_UNCHANGED))
8849 vty_out(vty,
8850 " NEXT_HOP is propagated unchanged to this neighbor\n");
8851 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8852 vty_out(vty,
8853 " MED is propagated unchanged to this neighbor\n");
8854 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8855 || CHECK_FLAG(p->af_flags[afi][safi],
8856 PEER_FLAG_SEND_EXT_COMMUNITY)
8857 || CHECK_FLAG(p->af_flags[afi][safi],
8858 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8859 vty_out(vty,
8860 " Community attribute sent to this neighbor");
8861 if (CHECK_FLAG(p->af_flags[afi][safi],
8862 PEER_FLAG_SEND_COMMUNITY)
8863 && CHECK_FLAG(p->af_flags[afi][safi],
8864 PEER_FLAG_SEND_EXT_COMMUNITY)
8865 && CHECK_FLAG(p->af_flags[afi][safi],
8866 PEER_FLAG_SEND_LARGE_COMMUNITY))
8867 vty_out(vty, "(all)\n");
8868 else if (CHECK_FLAG(p->af_flags[afi][safi],
8869 PEER_FLAG_SEND_LARGE_COMMUNITY))
8870 vty_out(vty, "(large)\n");
8871 else if (CHECK_FLAG(p->af_flags[afi][safi],
8872 PEER_FLAG_SEND_EXT_COMMUNITY))
8873 vty_out(vty, "(extended)\n");
8874 else
8875 vty_out(vty, "(standard)\n");
8876 }
8877 if (CHECK_FLAG(p->af_flags[afi][safi],
8878 PEER_FLAG_DEFAULT_ORIGINATE)) {
8879 vty_out(vty, " Default information originate,");
8880
8881 if (p->default_rmap[afi][safi].name)
8882 vty_out(vty, " default route-map %s%s,",
8883 p->default_rmap[afi][safi].map ? "*"
8884 : "",
8885 p->default_rmap[afi][safi].name);
8886 if (paf && PAF_SUBGRP(paf)
8887 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8888 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8889 vty_out(vty, " default sent\n");
8890 else
8891 vty_out(vty, " default not sent\n");
8892 }
8893
8894 /* advertise-vni-all */
8895 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8896 if (is_evpn_enabled())
8897 vty_out(vty, " advertise-all-vni\n");
8898 }
8899
8900 if (filter->plist[FILTER_IN].name
8901 || filter->dlist[FILTER_IN].name
8902 || filter->aslist[FILTER_IN].name
8903 || filter->map[RMAP_IN].name)
8904 vty_out(vty, " Inbound path policy configured\n");
8905 if (filter->plist[FILTER_OUT].name
8906 || filter->dlist[FILTER_OUT].name
8907 || filter->aslist[FILTER_OUT].name
8908 || filter->map[RMAP_OUT].name || filter->usmap.name)
8909 vty_out(vty, " Outbound path policy configured\n");
8910
8911 /* prefix-list */
8912 if (filter->plist[FILTER_IN].name)
8913 vty_out(vty,
8914 " Incoming update prefix filter list is %s%s\n",
8915 filter->plist[FILTER_IN].plist ? "*" : "",
8916 filter->plist[FILTER_IN].name);
8917 if (filter->plist[FILTER_OUT].name)
8918 vty_out(vty,
8919 " Outgoing update prefix filter list is %s%s\n",
8920 filter->plist[FILTER_OUT].plist ? "*" : "",
8921 filter->plist[FILTER_OUT].name);
8922
8923 /* distribute-list */
8924 if (filter->dlist[FILTER_IN].name)
8925 vty_out(vty,
8926 " Incoming update network filter list is %s%s\n",
8927 filter->dlist[FILTER_IN].alist ? "*" : "",
8928 filter->dlist[FILTER_IN].name);
8929 if (filter->dlist[FILTER_OUT].name)
8930 vty_out(vty,
8931 " Outgoing update network filter list is %s%s\n",
8932 filter->dlist[FILTER_OUT].alist ? "*" : "",
8933 filter->dlist[FILTER_OUT].name);
8934
8935 /* filter-list. */
8936 if (filter->aslist[FILTER_IN].name)
8937 vty_out(vty,
8938 " Incoming update AS path filter list is %s%s\n",
8939 filter->aslist[FILTER_IN].aslist ? "*" : "",
8940 filter->aslist[FILTER_IN].name);
8941 if (filter->aslist[FILTER_OUT].name)
8942 vty_out(vty,
8943 " Outgoing update AS path filter list is %s%s\n",
8944 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8945 filter->aslist[FILTER_OUT].name);
8946
8947 /* route-map. */
8948 if (filter->map[RMAP_IN].name)
8949 vty_out(vty,
8950 " Route map for incoming advertisements is %s%s\n",
8951 filter->map[RMAP_IN].map ? "*" : "",
8952 filter->map[RMAP_IN].name);
8953 if (filter->map[RMAP_OUT].name)
8954 vty_out(vty,
8955 " Route map for outgoing advertisements is %s%s\n",
8956 filter->map[RMAP_OUT].map ? "*" : "",
8957 filter->map[RMAP_OUT].name);
8958
8959 /* unsuppress-map */
8960 if (filter->usmap.name)
8961 vty_out(vty,
8962 " Route map for selective unsuppress is %s%s\n",
8963 filter->usmap.map ? "*" : "",
8964 filter->usmap.name);
8965
8966 /* Receive prefix count */
8967 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8968
8969 /* Maximum prefix */
8970 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8971 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8972 p->pmax[afi][safi],
8973 CHECK_FLAG(p->af_flags[afi][safi],
8974 PEER_FLAG_MAX_PREFIX_WARNING)
8975 ? " (warning-only)"
8976 : "");
8977 vty_out(vty, " Threshold for warning message %d%%",
8978 p->pmax_threshold[afi][safi]);
8979 if (p->pmax_restart[afi][safi])
8980 vty_out(vty, ", restart interval %d min",
8981 p->pmax_restart[afi][safi]);
8982 vty_out(vty, "\n");
8983 }
8984
8985 vty_out(vty, "\n");
8986 }
8987 }
8988
8989 static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
8990 json_object *json)
8991 {
8992 struct bgp *bgp;
8993 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8994 char timebuf[BGP_UPTIME_LEN];
8995 char dn_flag[2];
8996 const char *subcode_str;
8997 const char *code_str;
8998 afi_t afi;
8999 safi_t safi;
9000 uint16_t i;
9001 uint8_t *msg;
9002 json_object *json_neigh = NULL;
9003 time_t epoch_tbuf;
9004
9005 bgp = p->bgp;
9006
9007 if (use_json)
9008 json_neigh = json_object_new_object();
9009
9010 memset(dn_flag, '\0', sizeof(dn_flag));
9011 if (!p->conf_if && peer_dynamic_neighbor(p))
9012 dn_flag[0] = '*';
9013
9014 if (!use_json) {
9015 if (p->conf_if) /* Configured interface name. */
9016 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
9017 BGP_PEER_SU_UNSPEC(p)
9018 ? "None"
9019 : sockunion2str(&p->su, buf,
9020 SU_ADDRSTRLEN));
9021 else /* Configured IP address. */
9022 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
9023 p->host);
9024 }
9025
9026 if (use_json) {
9027 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
9028 json_object_string_add(json_neigh, "bgpNeighborAddr",
9029 "none");
9030 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
9031 json_object_string_add(
9032 json_neigh, "bgpNeighborAddr",
9033 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
9034
9035 json_object_int_add(json_neigh, "remoteAs", p->as);
9036
9037 if (p->change_local_as)
9038 json_object_int_add(json_neigh, "localAs",
9039 p->change_local_as);
9040 else
9041 json_object_int_add(json_neigh, "localAs", p->local_as);
9042
9043 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
9044 json_object_boolean_true_add(json_neigh,
9045 "localAsNoPrepend");
9046
9047 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
9048 json_object_boolean_true_add(json_neigh,
9049 "localAsReplaceAs");
9050 } else {
9051 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
9052 || (p->as_type == AS_INTERNAL))
9053 vty_out(vty, "remote AS %u, ", p->as);
9054 else
9055 vty_out(vty, "remote AS Unspecified, ");
9056 vty_out(vty, "local AS %u%s%s, ",
9057 p->change_local_as ? p->change_local_as : p->local_as,
9058 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
9059 ? " no-prepend"
9060 : "",
9061 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
9062 ? " replace-as"
9063 : "");
9064 }
9065 /* peer type internal, external, confed-internal or confed-external */
9066 if (p->as == p->local_as) {
9067 if (use_json) {
9068 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9069 json_object_boolean_true_add(
9070 json_neigh, "nbrConfedInternalLink");
9071 else
9072 json_object_boolean_true_add(json_neigh,
9073 "nbrInternalLink");
9074 } else {
9075 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9076 vty_out(vty, "confed-internal link\n");
9077 else
9078 vty_out(vty, "internal link\n");
9079 }
9080 } else {
9081 if (use_json) {
9082 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9083 json_object_boolean_true_add(
9084 json_neigh, "nbrConfedExternalLink");
9085 else
9086 json_object_boolean_true_add(json_neigh,
9087 "nbrExternalLink");
9088 } else {
9089 if (bgp_confederation_peers_check(bgp, p->as))
9090 vty_out(vty, "confed-external link\n");
9091 else
9092 vty_out(vty, "external link\n");
9093 }
9094 }
9095
9096 /* Description. */
9097 if (p->desc) {
9098 if (use_json)
9099 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9100 else
9101 vty_out(vty, " Description: %s\n", p->desc);
9102 }
9103
9104 if (p->hostname) {
9105 if (use_json) {
9106 if (p->hostname)
9107 json_object_string_add(json_neigh, "hostname",
9108 p->hostname);
9109
9110 if (p->domainname)
9111 json_object_string_add(json_neigh, "domainname",
9112 p->domainname);
9113 } else {
9114 if (p->domainname && (p->domainname[0] != '\0'))
9115 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9116 p->domainname);
9117 else
9118 vty_out(vty, "Hostname: %s\n", p->hostname);
9119 }
9120 }
9121
9122 /* Peer-group */
9123 if (p->group) {
9124 if (use_json) {
9125 json_object_string_add(json_neigh, "peerGroup",
9126 p->group->name);
9127
9128 if (dn_flag[0]) {
9129 struct prefix prefix, *range = NULL;
9130
9131 sockunion2hostprefix(&(p->su), &prefix);
9132 range = peer_group_lookup_dynamic_neighbor_range(
9133 p->group, &prefix);
9134
9135 if (range) {
9136 prefix2str(range, buf1, sizeof(buf1));
9137 json_object_string_add(
9138 json_neigh,
9139 "peerSubnetRangeGroup", buf1);
9140 }
9141 }
9142 } else {
9143 vty_out(vty,
9144 " Member of peer-group %s for session parameters\n",
9145 p->group->name);
9146
9147 if (dn_flag[0]) {
9148 struct prefix prefix, *range = NULL;
9149
9150 sockunion2hostprefix(&(p->su), &prefix);
9151 range = peer_group_lookup_dynamic_neighbor_range(
9152 p->group, &prefix);
9153
9154 if (range) {
9155 prefix2str(range, buf1, sizeof(buf1));
9156 vty_out(vty,
9157 " Belongs to the subnet range group: %s\n",
9158 buf1);
9159 }
9160 }
9161 }
9162 }
9163
9164 if (use_json) {
9165 /* Administrative shutdown. */
9166 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9167 json_object_boolean_true_add(json_neigh,
9168 "adminShutDown");
9169
9170 /* BGP Version. */
9171 json_object_int_add(json_neigh, "bgpVersion", 4);
9172 json_object_string_add(
9173 json_neigh, "remoteRouterId",
9174 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9175 json_object_string_add(
9176 json_neigh, "localRouterId",
9177 inet_ntop(AF_INET, &bgp->router_id, buf1,
9178 sizeof(buf1)));
9179
9180 /* Confederation */
9181 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9182 && bgp_confederation_peers_check(bgp, p->as))
9183 json_object_boolean_true_add(json_neigh,
9184 "nbrCommonAdmin");
9185
9186 /* Status. */
9187 json_object_string_add(
9188 json_neigh, "bgpState",
9189 lookup_msg(bgp_status_msg, p->status, NULL));
9190
9191 if (p->status == Established) {
9192 time_t uptime;
9193
9194 uptime = bgp_clock();
9195 uptime -= p->uptime;
9196 epoch_tbuf = time(NULL) - uptime;
9197
9198 #if CONFDATE > 20200101
9199 CPP_NOTICE(
9200 "bgpTimerUp should be deprecated and can be removed now");
9201 #endif
9202 /*
9203 * bgpTimerUp was miliseconds that was accurate
9204 * up to 1 day, then the value returned
9205 * became garbage. So in order to provide
9206 * some level of backwards compatability,
9207 * we still provde the data, but now
9208 * we are returning the correct value
9209 * and also adding a new bgpTimerUpMsec
9210 * which will allow us to deprecate
9211 * this eventually
9212 */
9213 json_object_int_add(json_neigh, "bgpTimerUp",
9214 uptime * 1000);
9215 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9216 uptime * 1000);
9217 json_object_string_add(json_neigh, "bgpTimerUpString",
9218 peer_uptime(p->uptime, timebuf,
9219 BGP_UPTIME_LEN, 0,
9220 NULL));
9221 json_object_int_add(json_neigh,
9222 "bgpTimerUpEstablishedEpoch",
9223 epoch_tbuf);
9224 }
9225
9226 else if (p->status == Active) {
9227 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9228 json_object_string_add(json_neigh, "bgpStateIs",
9229 "passive");
9230 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9231 json_object_string_add(json_neigh, "bgpStateIs",
9232 "passiveNSF");
9233 }
9234
9235 /* read timer */
9236 time_t uptime;
9237 struct tm *tm;
9238
9239 uptime = bgp_clock();
9240 uptime -= p->readtime;
9241 tm = gmtime(&uptime);
9242 json_object_int_add(json_neigh, "bgpTimerLastRead",
9243 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9244 + (tm->tm_hour * 3600000));
9245
9246 uptime = bgp_clock();
9247 uptime -= p->last_write;
9248 tm = gmtime(&uptime);
9249 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9250 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9251 + (tm->tm_hour * 3600000));
9252
9253 uptime = bgp_clock();
9254 uptime -= p->update_time;
9255 tm = gmtime(&uptime);
9256 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9257 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9258 + (tm->tm_hour * 3600000));
9259
9260 /* Configured timer values. */
9261 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9262 p->v_holdtime * 1000);
9263 json_object_int_add(json_neigh,
9264 "bgpTimerKeepAliveIntervalMsecs",
9265 p->v_keepalive * 1000);
9266 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9267 json_object_int_add(json_neigh,
9268 "bgpTimerConfiguredHoldTimeMsecs",
9269 p->holdtime * 1000);
9270 json_object_int_add(
9271 json_neigh,
9272 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9273 p->keepalive * 1000);
9274 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9275 || (bgp->default_keepalive
9276 != BGP_DEFAULT_KEEPALIVE)) {
9277 json_object_int_add(json_neigh,
9278 "bgpTimerConfiguredHoldTimeMsecs",
9279 bgp->default_holdtime);
9280 json_object_int_add(
9281 json_neigh,
9282 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9283 bgp->default_keepalive);
9284 }
9285 } else {
9286 /* Administrative shutdown. */
9287 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9288 vty_out(vty, " Administratively shut down\n");
9289
9290 /* BGP Version. */
9291 vty_out(vty, " BGP version 4");
9292 vty_out(vty, ", remote router ID %s",
9293 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9294 vty_out(vty, ", local router ID %s\n",
9295 inet_ntop(AF_INET, &bgp->router_id, buf1,
9296 sizeof(buf1)));
9297
9298 /* Confederation */
9299 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9300 && bgp_confederation_peers_check(bgp, p->as))
9301 vty_out(vty,
9302 " Neighbor under common administration\n");
9303
9304 /* Status. */
9305 vty_out(vty, " BGP state = %s",
9306 lookup_msg(bgp_status_msg, p->status, NULL));
9307
9308 if (p->status == Established)
9309 vty_out(vty, ", up for %8s",
9310 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9311 0, NULL));
9312
9313 else if (p->status == Active) {
9314 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9315 vty_out(vty, " (passive)");
9316 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9317 vty_out(vty, " (NSF passive)");
9318 }
9319 vty_out(vty, "\n");
9320
9321 /* read timer */
9322 vty_out(vty, " Last read %s",
9323 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9324 NULL));
9325 vty_out(vty, ", Last write %s\n",
9326 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9327 NULL));
9328
9329 /* Configured timer values. */
9330 vty_out(vty,
9331 " Hold time is %d, keepalive interval is %d seconds\n",
9332 p->v_holdtime, p->v_keepalive);
9333 if (CHECK_FLAG(p->flags, PEER_FLAG_TIMER)) {
9334 vty_out(vty, " Configured hold time is %d",
9335 p->holdtime);
9336 vty_out(vty, ", keepalive interval is %d seconds\n",
9337 p->keepalive);
9338 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9339 || (bgp->default_keepalive
9340 != BGP_DEFAULT_KEEPALIVE)) {
9341 vty_out(vty, " Configured hold time is %d",
9342 bgp->default_holdtime);
9343 vty_out(vty, ", keepalive interval is %d seconds\n",
9344 bgp->default_keepalive);
9345 }
9346 }
9347 /* Capability. */
9348 if (p->status == Established) {
9349 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9350 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9351 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9352 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9353 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9354 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9355 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9356 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9357 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9358 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9359 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9360 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9361 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9362 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9363 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9364 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9365 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9366 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9367 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9368 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9369 if (use_json) {
9370 json_object *json_cap = NULL;
9371
9372 json_cap = json_object_new_object();
9373
9374 /* AS4 */
9375 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9376 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9377 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9378 && CHECK_FLAG(p->cap,
9379 PEER_CAP_AS4_RCV))
9380 json_object_string_add(
9381 json_cap, "4byteAs",
9382 "advertisedAndReceived");
9383 else if (CHECK_FLAG(p->cap,
9384 PEER_CAP_AS4_ADV))
9385 json_object_string_add(
9386 json_cap, "4byteAs",
9387 "advertised");
9388 else if (CHECK_FLAG(p->cap,
9389 PEER_CAP_AS4_RCV))
9390 json_object_string_add(
9391 json_cap, "4byteAs",
9392 "received");
9393 }
9394
9395 /* AddPath */
9396 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9397 || CHECK_FLAG(p->cap,
9398 PEER_CAP_ADDPATH_ADV)) {
9399 json_object *json_add = NULL;
9400 const char *print_store;
9401
9402 json_add = json_object_new_object();
9403
9404 FOREACH_AFI_SAFI (afi, safi) {
9405 json_object *json_sub = NULL;
9406 json_sub =
9407 json_object_new_object();
9408 print_store = afi_safi_print(
9409 afi, safi);
9410
9411 if (CHECK_FLAG(
9412 p->af_cap[afi]
9413 [safi],
9414 PEER_CAP_ADDPATH_AF_TX_ADV)
9415 || CHECK_FLAG(
9416 p->af_cap[afi]
9417 [safi],
9418 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9419 if (CHECK_FLAG(
9420 p->af_cap
9421 [afi]
9422 [safi],
9423 PEER_CAP_ADDPATH_AF_TX_ADV)
9424 && CHECK_FLAG(
9425 p->af_cap
9426 [afi]
9427 [safi],
9428 PEER_CAP_ADDPATH_AF_TX_RCV))
9429 json_object_boolean_true_add(
9430 json_sub,
9431 "txAdvertisedAndReceived");
9432 else if (
9433 CHECK_FLAG(
9434 p->af_cap
9435 [afi]
9436 [safi],
9437 PEER_CAP_ADDPATH_AF_TX_ADV))
9438 json_object_boolean_true_add(
9439 json_sub,
9440 "txAdvertised");
9441 else if (
9442 CHECK_FLAG(
9443 p->af_cap
9444 [afi]
9445 [safi],
9446 PEER_CAP_ADDPATH_AF_TX_RCV))
9447 json_object_boolean_true_add(
9448 json_sub,
9449 "txReceived");
9450 }
9451
9452 if (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 if (CHECK_FLAG(
9461 p->af_cap
9462 [afi]
9463 [safi],
9464 PEER_CAP_ADDPATH_AF_RX_ADV)
9465 && CHECK_FLAG(
9466 p->af_cap
9467 [afi]
9468 [safi],
9469 PEER_CAP_ADDPATH_AF_RX_RCV))
9470 json_object_boolean_true_add(
9471 json_sub,
9472 "rxAdvertisedAndReceived");
9473 else if (
9474 CHECK_FLAG(
9475 p->af_cap
9476 [afi]
9477 [safi],
9478 PEER_CAP_ADDPATH_AF_RX_ADV))
9479 json_object_boolean_true_add(
9480 json_sub,
9481 "rxAdvertised");
9482 else if (
9483 CHECK_FLAG(
9484 p->af_cap
9485 [afi]
9486 [safi],
9487 PEER_CAP_ADDPATH_AF_RX_RCV))
9488 json_object_boolean_true_add(
9489 json_sub,
9490 "rxReceived");
9491 }
9492
9493 if (CHECK_FLAG(
9494 p->af_cap[afi]
9495 [safi],
9496 PEER_CAP_ADDPATH_AF_TX_ADV)
9497 || CHECK_FLAG(
9498 p->af_cap[afi]
9499 [safi],
9500 PEER_CAP_ADDPATH_AF_TX_RCV)
9501 || CHECK_FLAG(
9502 p->af_cap[afi]
9503 [safi],
9504 PEER_CAP_ADDPATH_AF_RX_ADV)
9505 || CHECK_FLAG(
9506 p->af_cap[afi]
9507 [safi],
9508 PEER_CAP_ADDPATH_AF_RX_RCV))
9509 json_object_object_add(
9510 json_add,
9511 print_store,
9512 json_sub);
9513 else
9514 json_object_free(
9515 json_sub);
9516 }
9517
9518 json_object_object_add(
9519 json_cap, "addPath", json_add);
9520 }
9521
9522 /* Dynamic */
9523 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9524 || CHECK_FLAG(p->cap,
9525 PEER_CAP_DYNAMIC_ADV)) {
9526 if (CHECK_FLAG(p->cap,
9527 PEER_CAP_DYNAMIC_ADV)
9528 && CHECK_FLAG(p->cap,
9529 PEER_CAP_DYNAMIC_RCV))
9530 json_object_string_add(
9531 json_cap, "dynamic",
9532 "advertisedAndReceived");
9533 else if (CHECK_FLAG(
9534 p->cap,
9535 PEER_CAP_DYNAMIC_ADV))
9536 json_object_string_add(
9537 json_cap, "dynamic",
9538 "advertised");
9539 else if (CHECK_FLAG(
9540 p->cap,
9541 PEER_CAP_DYNAMIC_RCV))
9542 json_object_string_add(
9543 json_cap, "dynamic",
9544 "received");
9545 }
9546
9547 /* Extended nexthop */
9548 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9549 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9550 json_object *json_nxt = NULL;
9551 const char *print_store;
9552
9553
9554 if (CHECK_FLAG(p->cap,
9555 PEER_CAP_ENHE_ADV)
9556 && CHECK_FLAG(p->cap,
9557 PEER_CAP_ENHE_RCV))
9558 json_object_string_add(
9559 json_cap,
9560 "extendedNexthop",
9561 "advertisedAndReceived");
9562 else if (CHECK_FLAG(p->cap,
9563 PEER_CAP_ENHE_ADV))
9564 json_object_string_add(
9565 json_cap,
9566 "extendedNexthop",
9567 "advertised");
9568 else if (CHECK_FLAG(p->cap,
9569 PEER_CAP_ENHE_RCV))
9570 json_object_string_add(
9571 json_cap,
9572 "extendedNexthop",
9573 "received");
9574
9575 if (CHECK_FLAG(p->cap,
9576 PEER_CAP_ENHE_RCV)) {
9577 json_nxt =
9578 json_object_new_object();
9579
9580 for (safi = SAFI_UNICAST;
9581 safi < SAFI_MAX; safi++) {
9582 if (CHECK_FLAG(
9583 p->af_cap
9584 [AFI_IP]
9585 [safi],
9586 PEER_CAP_ENHE_AF_RCV)) {
9587 print_store = afi_safi_print(
9588 AFI_IP,
9589 safi);
9590 json_object_string_add(
9591 json_nxt,
9592 print_store,
9593 "recieved");
9594 }
9595 }
9596 json_object_object_add(
9597 json_cap,
9598 "extendedNexthopFamililesByPeer",
9599 json_nxt);
9600 }
9601 }
9602
9603 /* Route Refresh */
9604 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9605 || CHECK_FLAG(p->cap,
9606 PEER_CAP_REFRESH_NEW_RCV)
9607 || CHECK_FLAG(p->cap,
9608 PEER_CAP_REFRESH_OLD_RCV)) {
9609 if (CHECK_FLAG(p->cap,
9610 PEER_CAP_REFRESH_ADV)
9611 && (CHECK_FLAG(
9612 p->cap,
9613 PEER_CAP_REFRESH_NEW_RCV)
9614 || CHECK_FLAG(
9615 p->cap,
9616 PEER_CAP_REFRESH_OLD_RCV))) {
9617 if (CHECK_FLAG(
9618 p->cap,
9619 PEER_CAP_REFRESH_OLD_RCV)
9620 && CHECK_FLAG(
9621 p->cap,
9622 PEER_CAP_REFRESH_NEW_RCV))
9623 json_object_string_add(
9624 json_cap,
9625 "routeRefresh",
9626 "advertisedAndReceivedOldNew");
9627 else {
9628 if (CHECK_FLAG(
9629 p->cap,
9630 PEER_CAP_REFRESH_OLD_RCV))
9631 json_object_string_add(
9632 json_cap,
9633 "routeRefresh",
9634 "advertisedAndReceivedOld");
9635 else
9636 json_object_string_add(
9637 json_cap,
9638 "routeRefresh",
9639 "advertisedAndReceivedNew");
9640 }
9641 } else if (
9642 CHECK_FLAG(
9643 p->cap,
9644 PEER_CAP_REFRESH_ADV))
9645 json_object_string_add(
9646 json_cap,
9647 "routeRefresh",
9648 "advertised");
9649 else if (
9650 CHECK_FLAG(
9651 p->cap,
9652 PEER_CAP_REFRESH_NEW_RCV)
9653 || CHECK_FLAG(
9654 p->cap,
9655 PEER_CAP_REFRESH_OLD_RCV))
9656 json_object_string_add(
9657 json_cap,
9658 "routeRefresh",
9659 "received");
9660 }
9661
9662 /* Multiprotocol Extensions */
9663 json_object *json_multi = NULL;
9664 json_multi = json_object_new_object();
9665
9666 FOREACH_AFI_SAFI (afi, safi) {
9667 if (p->afc_adv[afi][safi]
9668 || p->afc_recv[afi][safi]) {
9669 json_object *json_exten = NULL;
9670 json_exten =
9671 json_object_new_object();
9672
9673 if (p->afc_adv[afi][safi]
9674 && p->afc_recv[afi][safi])
9675 json_object_boolean_true_add(
9676 json_exten,
9677 "advertisedAndReceived");
9678 else if (p->afc_adv[afi][safi])
9679 json_object_boolean_true_add(
9680 json_exten,
9681 "advertised");
9682 else if (p->afc_recv[afi][safi])
9683 json_object_boolean_true_add(
9684 json_exten,
9685 "received");
9686
9687 json_object_object_add(
9688 json_multi,
9689 afi_safi_print(afi,
9690 safi),
9691 json_exten);
9692 }
9693 }
9694 json_object_object_add(
9695 json_cap, "multiprotocolExtensions",
9696 json_multi);
9697
9698 /* Hostname capabilities */
9699 json_object *json_hname = NULL;
9700
9701 json_hname = json_object_new_object();
9702
9703 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9704 json_object_string_add(
9705 json_hname, "advHostName",
9706 bgp->peer_self->hostname
9707 ? bgp->peer_self
9708 ->hostname
9709 : "n/a");
9710 json_object_string_add(
9711 json_hname, "advDomainName",
9712 bgp->peer_self->domainname
9713 ? bgp->peer_self
9714 ->domainname
9715 : "n/a");
9716 }
9717
9718
9719 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9720 json_object_string_add(
9721 json_hname, "rcvHostName",
9722 p->hostname ? p->hostname
9723 : "n/a");
9724 json_object_string_add(
9725 json_hname, "rcvDomainName",
9726 p->domainname ? p->domainname
9727 : "n/a");
9728 }
9729
9730 json_object_object_add(json_cap, "hostName",
9731 json_hname);
9732
9733 /* Gracefull Restart */
9734 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9735 || CHECK_FLAG(p->cap,
9736 PEER_CAP_RESTART_ADV)) {
9737 if (CHECK_FLAG(p->cap,
9738 PEER_CAP_RESTART_ADV)
9739 && CHECK_FLAG(p->cap,
9740 PEER_CAP_RESTART_RCV))
9741 json_object_string_add(
9742 json_cap,
9743 "gracefulRestart",
9744 "advertisedAndReceived");
9745 else if (CHECK_FLAG(
9746 p->cap,
9747 PEER_CAP_RESTART_ADV))
9748 json_object_string_add(
9749 json_cap,
9750 "gracefulRestartCapability",
9751 "advertised");
9752 else if (CHECK_FLAG(
9753 p->cap,
9754 PEER_CAP_RESTART_RCV))
9755 json_object_string_add(
9756 json_cap,
9757 "gracefulRestartCapability",
9758 "received");
9759
9760 if (CHECK_FLAG(p->cap,
9761 PEER_CAP_RESTART_RCV)) {
9762 int restart_af_count = 0;
9763 json_object *json_restart =
9764 NULL;
9765 json_restart =
9766 json_object_new_object();
9767
9768 json_object_int_add(
9769 json_cap,
9770 "gracefulRestartRemoteTimerMsecs",
9771 p->v_gr_restart * 1000);
9772
9773 FOREACH_AFI_SAFI (afi, safi) {
9774 if (CHECK_FLAG(
9775 p->af_cap
9776 [afi]
9777 [safi],
9778 PEER_CAP_RESTART_AF_RCV)) {
9779 json_object *
9780 json_sub =
9781 NULL;
9782 json_sub =
9783 json_object_new_object();
9784
9785 if (CHECK_FLAG(
9786 p->af_cap
9787 [afi]
9788 [safi],
9789 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9790 json_object_boolean_true_add(
9791 json_sub,
9792 "preserved");
9793 restart_af_count++;
9794 json_object_object_add(
9795 json_restart,
9796 afi_safi_print(
9797 afi,
9798 safi),
9799 json_sub);
9800 }
9801 }
9802 if (!restart_af_count) {
9803 json_object_string_add(
9804 json_cap,
9805 "addressFamiliesByPeer",
9806 "none");
9807 json_object_free(
9808 json_restart);
9809 } else
9810 json_object_object_add(
9811 json_cap,
9812 "addressFamiliesByPeer",
9813 json_restart);
9814 }
9815 }
9816 json_object_object_add(json_neigh,
9817 "neighborCapabilities",
9818 json_cap);
9819 } else {
9820 vty_out(vty, " Neighbor capabilities:\n");
9821
9822 /* AS4 */
9823 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9824 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9825 vty_out(vty, " 4 Byte AS:");
9826 if (CHECK_FLAG(p->cap,
9827 PEER_CAP_AS4_ADV))
9828 vty_out(vty, " advertised");
9829 if (CHECK_FLAG(p->cap,
9830 PEER_CAP_AS4_RCV))
9831 vty_out(vty, " %sreceived",
9832 CHECK_FLAG(
9833 p->cap,
9834 PEER_CAP_AS4_ADV)
9835 ? "and "
9836 : "");
9837 vty_out(vty, "\n");
9838 }
9839
9840 /* AddPath */
9841 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9842 || CHECK_FLAG(p->cap,
9843 PEER_CAP_ADDPATH_ADV)) {
9844 vty_out(vty, " AddPath:\n");
9845
9846 FOREACH_AFI_SAFI (afi, safi) {
9847 if (CHECK_FLAG(
9848 p->af_cap[afi]
9849 [safi],
9850 PEER_CAP_ADDPATH_AF_TX_ADV)
9851 || CHECK_FLAG(
9852 p->af_cap[afi]
9853 [safi],
9854 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9855 vty_out(vty,
9856 " %s: TX ",
9857 afi_safi_print(
9858 afi,
9859 safi));
9860
9861 if (CHECK_FLAG(
9862 p->af_cap
9863 [afi]
9864 [safi],
9865 PEER_CAP_ADDPATH_AF_TX_ADV))
9866 vty_out(vty,
9867 "advertised %s",
9868 afi_safi_print(
9869 afi,
9870 safi));
9871
9872 if (CHECK_FLAG(
9873 p->af_cap
9874 [afi]
9875 [safi],
9876 PEER_CAP_ADDPATH_AF_TX_RCV))
9877 vty_out(vty,
9878 "%sreceived",
9879 CHECK_FLAG(
9880 p->af_cap
9881 [afi]
9882 [safi],
9883 PEER_CAP_ADDPATH_AF_TX_ADV)
9884 ? " and "
9885 : "");
9886
9887 vty_out(vty, "\n");
9888 }
9889
9890 if (CHECK_FLAG(
9891 p->af_cap[afi]
9892 [safi],
9893 PEER_CAP_ADDPATH_AF_RX_ADV)
9894 || CHECK_FLAG(
9895 p->af_cap[afi]
9896 [safi],
9897 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9898 vty_out(vty,
9899 " %s: RX ",
9900 afi_safi_print(
9901 afi,
9902 safi));
9903
9904 if (CHECK_FLAG(
9905 p->af_cap
9906 [afi]
9907 [safi],
9908 PEER_CAP_ADDPATH_AF_RX_ADV))
9909 vty_out(vty,
9910 "advertised %s",
9911 afi_safi_print(
9912 afi,
9913 safi));
9914
9915 if (CHECK_FLAG(
9916 p->af_cap
9917 [afi]
9918 [safi],
9919 PEER_CAP_ADDPATH_AF_RX_RCV))
9920 vty_out(vty,
9921 "%sreceived",
9922 CHECK_FLAG(
9923 p->af_cap
9924 [afi]
9925 [safi],
9926 PEER_CAP_ADDPATH_AF_RX_ADV)
9927 ? " and "
9928 : "");
9929
9930 vty_out(vty, "\n");
9931 }
9932 }
9933 }
9934
9935 /* Dynamic */
9936 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9937 || CHECK_FLAG(p->cap,
9938 PEER_CAP_DYNAMIC_ADV)) {
9939 vty_out(vty, " Dynamic:");
9940 if (CHECK_FLAG(p->cap,
9941 PEER_CAP_DYNAMIC_ADV))
9942 vty_out(vty, " advertised");
9943 if (CHECK_FLAG(p->cap,
9944 PEER_CAP_DYNAMIC_RCV))
9945 vty_out(vty, " %sreceived",
9946 CHECK_FLAG(
9947 p->cap,
9948 PEER_CAP_DYNAMIC_ADV)
9949 ? "and "
9950 : "");
9951 vty_out(vty, "\n");
9952 }
9953
9954 /* Extended nexthop */
9955 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9956 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9957 vty_out(vty, " Extended nexthop:");
9958 if (CHECK_FLAG(p->cap,
9959 PEER_CAP_ENHE_ADV))
9960 vty_out(vty, " advertised");
9961 if (CHECK_FLAG(p->cap,
9962 PEER_CAP_ENHE_RCV))
9963 vty_out(vty, " %sreceived",
9964 CHECK_FLAG(
9965 p->cap,
9966 PEER_CAP_ENHE_ADV)
9967 ? "and "
9968 : "");
9969 vty_out(vty, "\n");
9970
9971 if (CHECK_FLAG(p->cap,
9972 PEER_CAP_ENHE_RCV)) {
9973 vty_out(vty,
9974 " Address families by peer:\n ");
9975 for (safi = SAFI_UNICAST;
9976 safi < SAFI_MAX; safi++)
9977 if (CHECK_FLAG(
9978 p->af_cap
9979 [AFI_IP]
9980 [safi],
9981 PEER_CAP_ENHE_AF_RCV))
9982 vty_out(vty,
9983 " %s\n",
9984 afi_safi_print(
9985 AFI_IP,
9986 safi));
9987 }
9988 }
9989
9990 /* Route Refresh */
9991 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9992 || CHECK_FLAG(p->cap,
9993 PEER_CAP_REFRESH_NEW_RCV)
9994 || CHECK_FLAG(p->cap,
9995 PEER_CAP_REFRESH_OLD_RCV)) {
9996 vty_out(vty, " Route refresh:");
9997 if (CHECK_FLAG(p->cap,
9998 PEER_CAP_REFRESH_ADV))
9999 vty_out(vty, " advertised");
10000 if (CHECK_FLAG(p->cap,
10001 PEER_CAP_REFRESH_NEW_RCV)
10002 || CHECK_FLAG(
10003 p->cap,
10004 PEER_CAP_REFRESH_OLD_RCV))
10005 vty_out(vty, " %sreceived(%s)",
10006 CHECK_FLAG(
10007 p->cap,
10008 PEER_CAP_REFRESH_ADV)
10009 ? "and "
10010 : "",
10011 (CHECK_FLAG(
10012 p->cap,
10013 PEER_CAP_REFRESH_OLD_RCV)
10014 && CHECK_FLAG(
10015 p->cap,
10016 PEER_CAP_REFRESH_NEW_RCV))
10017 ? "old & new"
10018 : CHECK_FLAG(
10019 p->cap,
10020 PEER_CAP_REFRESH_OLD_RCV)
10021 ? "old"
10022 : "new");
10023
10024 vty_out(vty, "\n");
10025 }
10026
10027 /* Multiprotocol Extensions */
10028 FOREACH_AFI_SAFI (afi, safi)
10029 if (p->afc_adv[afi][safi]
10030 || p->afc_recv[afi][safi]) {
10031 vty_out(vty,
10032 " Address Family %s:",
10033 afi_safi_print(afi,
10034 safi));
10035 if (p->afc_adv[afi][safi])
10036 vty_out(vty,
10037 " advertised");
10038 if (p->afc_recv[afi][safi])
10039 vty_out(vty,
10040 " %sreceived",
10041 p->afc_adv[afi]
10042 [safi]
10043 ? "and "
10044 : "");
10045 vty_out(vty, "\n");
10046 }
10047
10048 /* Hostname capability */
10049 vty_out(vty, " Hostname Capability:");
10050
10051 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
10052 vty_out(vty,
10053 " advertised (name: %s,domain name: %s)",
10054 bgp->peer_self->hostname
10055 ? bgp->peer_self
10056 ->hostname
10057 : "n/a",
10058 bgp->peer_self->domainname
10059 ? bgp->peer_self
10060 ->domainname
10061 : "n/a");
10062 } else {
10063 vty_out(vty, " not advertised");
10064 }
10065
10066 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
10067 vty_out(vty,
10068 " received (name: %s,domain name: %s)",
10069 p->hostname ? p->hostname
10070 : "n/a",
10071 p->domainname ? p->domainname
10072 : "n/a");
10073 } else {
10074 vty_out(vty, " not received");
10075 }
10076
10077 vty_out(vty, "\n");
10078
10079 /* Gracefull Restart */
10080 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
10081 || CHECK_FLAG(p->cap,
10082 PEER_CAP_RESTART_ADV)) {
10083 vty_out(vty,
10084 " Graceful Restart Capabilty:");
10085 if (CHECK_FLAG(p->cap,
10086 PEER_CAP_RESTART_ADV))
10087 vty_out(vty, " advertised");
10088 if (CHECK_FLAG(p->cap,
10089 PEER_CAP_RESTART_RCV))
10090 vty_out(vty, " %sreceived",
10091 CHECK_FLAG(
10092 p->cap,
10093 PEER_CAP_RESTART_ADV)
10094 ? "and "
10095 : "");
10096 vty_out(vty, "\n");
10097
10098 if (CHECK_FLAG(p->cap,
10099 PEER_CAP_RESTART_RCV)) {
10100 int restart_af_count = 0;
10101
10102 vty_out(vty,
10103 " Remote Restart timer is %d seconds\n",
10104 p->v_gr_restart);
10105 vty_out(vty,
10106 " Address families by peer:\n ");
10107
10108 FOREACH_AFI_SAFI (afi, safi)
10109 if (CHECK_FLAG(
10110 p->af_cap
10111 [afi]
10112 [safi],
10113 PEER_CAP_RESTART_AF_RCV)) {
10114 vty_out(vty,
10115 "%s%s(%s)",
10116 restart_af_count
10117 ? ", "
10118 : "",
10119 afi_safi_print(
10120 afi,
10121 safi),
10122 CHECK_FLAG(
10123 p->af_cap
10124 [afi]
10125 [safi],
10126 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10127 ? "preserved"
10128 : "not preserved");
10129 restart_af_count++;
10130 }
10131 if (!restart_af_count)
10132 vty_out(vty, "none");
10133 vty_out(vty, "\n");
10134 }
10135 }
10136 }
10137 }
10138 }
10139
10140 /* graceful restart information */
10141 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10142 || p->t_gr_stale) {
10143 json_object *json_grace = NULL;
10144 json_object *json_grace_send = NULL;
10145 json_object *json_grace_recv = NULL;
10146 int eor_send_af_count = 0;
10147 int eor_receive_af_count = 0;
10148
10149 if (use_json) {
10150 json_grace = json_object_new_object();
10151 json_grace_send = json_object_new_object();
10152 json_grace_recv = json_object_new_object();
10153
10154 if (p->status == Established) {
10155 FOREACH_AFI_SAFI (afi, safi) {
10156 if (CHECK_FLAG(p->af_sflags[afi][safi],
10157 PEER_STATUS_EOR_SEND)) {
10158 json_object_boolean_true_add(
10159 json_grace_send,
10160 afi_safi_print(afi,
10161 safi));
10162 eor_send_af_count++;
10163 }
10164 }
10165 FOREACH_AFI_SAFI (afi, safi) {
10166 if (CHECK_FLAG(
10167 p->af_sflags[afi][safi],
10168 PEER_STATUS_EOR_RECEIVED)) {
10169 json_object_boolean_true_add(
10170 json_grace_recv,
10171 afi_safi_print(afi,
10172 safi));
10173 eor_receive_af_count++;
10174 }
10175 }
10176 }
10177
10178 json_object_object_add(json_grace, "endOfRibSend",
10179 json_grace_send);
10180 json_object_object_add(json_grace, "endOfRibRecv",
10181 json_grace_recv);
10182
10183 if (p->t_gr_restart)
10184 json_object_int_add(json_grace,
10185 "gracefulRestartTimerMsecs",
10186 thread_timer_remain_second(
10187 p->t_gr_restart)
10188 * 1000);
10189
10190 if (p->t_gr_stale)
10191 json_object_int_add(
10192 json_grace,
10193 "gracefulStalepathTimerMsecs",
10194 thread_timer_remain_second(
10195 p->t_gr_stale)
10196 * 1000);
10197
10198 json_object_object_add(
10199 json_neigh, "gracefulRestartInfo", json_grace);
10200 } else {
10201 vty_out(vty, " Graceful restart informations:\n");
10202 if (p->status == Established) {
10203 vty_out(vty, " End-of-RIB send: ");
10204 FOREACH_AFI_SAFI (afi, safi) {
10205 if (CHECK_FLAG(p->af_sflags[afi][safi],
10206 PEER_STATUS_EOR_SEND)) {
10207 vty_out(vty, "%s%s",
10208 eor_send_af_count ? ", "
10209 : "",
10210 afi_safi_print(afi,
10211 safi));
10212 eor_send_af_count++;
10213 }
10214 }
10215 vty_out(vty, "\n");
10216 vty_out(vty, " End-of-RIB received: ");
10217 FOREACH_AFI_SAFI (afi, safi) {
10218 if (CHECK_FLAG(
10219 p->af_sflags[afi][safi],
10220 PEER_STATUS_EOR_RECEIVED)) {
10221 vty_out(vty, "%s%s",
10222 eor_receive_af_count
10223 ? ", "
10224 : "",
10225 afi_safi_print(afi,
10226 safi));
10227 eor_receive_af_count++;
10228 }
10229 }
10230 vty_out(vty, "\n");
10231 }
10232
10233 if (p->t_gr_restart)
10234 vty_out(vty,
10235 " The remaining time of restart timer is %ld\n",
10236 thread_timer_remain_second(
10237 p->t_gr_restart));
10238
10239 if (p->t_gr_stale)
10240 vty_out(vty,
10241 " The remaining time of stalepath timer is %ld\n",
10242 thread_timer_remain_second(
10243 p->t_gr_stale));
10244 }
10245 }
10246 if (use_json) {
10247 json_object *json_stat = NULL;
10248 json_stat = json_object_new_object();
10249 /* Packet counts. */
10250 json_object_int_add(json_stat, "depthInq", 0);
10251 json_object_int_add(json_stat, "depthOutq",
10252 (unsigned long)p->obuf->count);
10253 json_object_int_add(json_stat, "opensSent",
10254 atomic_load_explicit(&p->open_out,
10255 memory_order_relaxed));
10256 json_object_int_add(json_stat, "opensRecv",
10257 atomic_load_explicit(&p->open_in,
10258 memory_order_relaxed));
10259 json_object_int_add(json_stat, "notificationsSent",
10260 atomic_load_explicit(&p->notify_out,
10261 memory_order_relaxed));
10262 json_object_int_add(json_stat, "notificationsRecv",
10263 atomic_load_explicit(&p->notify_in,
10264 memory_order_relaxed));
10265 json_object_int_add(json_stat, "updatesSent",
10266 atomic_load_explicit(&p->update_out,
10267 memory_order_relaxed));
10268 json_object_int_add(json_stat, "updatesRecv",
10269 atomic_load_explicit(&p->update_in,
10270 memory_order_relaxed));
10271 json_object_int_add(json_stat, "keepalivesSent",
10272 atomic_load_explicit(&p->keepalive_out,
10273 memory_order_relaxed));
10274 json_object_int_add(json_stat, "keepalivesRecv",
10275 atomic_load_explicit(&p->keepalive_in,
10276 memory_order_relaxed));
10277 json_object_int_add(json_stat, "routeRefreshSent",
10278 atomic_load_explicit(&p->refresh_out,
10279 memory_order_relaxed));
10280 json_object_int_add(json_stat, "routeRefreshRecv",
10281 atomic_load_explicit(&p->refresh_in,
10282 memory_order_relaxed));
10283 json_object_int_add(json_stat, "capabilitySent",
10284 atomic_load_explicit(&p->dynamic_cap_out,
10285 memory_order_relaxed));
10286 json_object_int_add(json_stat, "capabilityRecv",
10287 atomic_load_explicit(&p->dynamic_cap_in,
10288 memory_order_relaxed));
10289 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10290 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10291 json_object_object_add(json_neigh, "messageStats", json_stat);
10292 } else {
10293 /* Packet counts. */
10294 vty_out(vty, " Message statistics:\n");
10295 vty_out(vty, " Inq depth is 0\n");
10296 vty_out(vty, " Outq depth is %lu\n",
10297 (unsigned long)p->obuf->count);
10298 vty_out(vty, " Sent Rcvd\n");
10299 vty_out(vty, " Opens: %10d %10d\n",
10300 atomic_load_explicit(&p->open_out,
10301 memory_order_relaxed),
10302 atomic_load_explicit(&p->open_in,
10303 memory_order_relaxed));
10304 vty_out(vty, " Notifications: %10d %10d\n",
10305 atomic_load_explicit(&p->notify_out,
10306 memory_order_relaxed),
10307 atomic_load_explicit(&p->notify_in,
10308 memory_order_relaxed));
10309 vty_out(vty, " Updates: %10d %10d\n",
10310 atomic_load_explicit(&p->update_out,
10311 memory_order_relaxed),
10312 atomic_load_explicit(&p->update_in,
10313 memory_order_relaxed));
10314 vty_out(vty, " Keepalives: %10d %10d\n",
10315 atomic_load_explicit(&p->keepalive_out,
10316 memory_order_relaxed),
10317 atomic_load_explicit(&p->keepalive_in,
10318 memory_order_relaxed));
10319 vty_out(vty, " Route Refresh: %10d %10d\n",
10320 atomic_load_explicit(&p->refresh_out,
10321 memory_order_relaxed),
10322 atomic_load_explicit(&p->refresh_in,
10323 memory_order_relaxed));
10324 vty_out(vty, " Capability: %10d %10d\n",
10325 atomic_load_explicit(&p->dynamic_cap_out,
10326 memory_order_relaxed),
10327 atomic_load_explicit(&p->dynamic_cap_in,
10328 memory_order_relaxed));
10329 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10330 PEER_TOTAL_RX(p));
10331 }
10332
10333 if (use_json) {
10334 /* advertisement-interval */
10335 json_object_int_add(json_neigh,
10336 "minBtwnAdvertisementRunsTimerMsecs",
10337 p->v_routeadv * 1000);
10338
10339 /* Update-source. */
10340 if (p->update_if || p->update_source) {
10341 if (p->update_if)
10342 json_object_string_add(json_neigh,
10343 "updateSource",
10344 p->update_if);
10345 else if (p->update_source)
10346 json_object_string_add(
10347 json_neigh, "updateSource",
10348 sockunion2str(p->update_source, buf1,
10349 SU_ADDRSTRLEN));
10350 }
10351 } else {
10352 /* advertisement-interval */
10353 vty_out(vty,
10354 " Minimum time between advertisement runs is %d seconds\n",
10355 p->v_routeadv);
10356
10357 /* Update-source. */
10358 if (p->update_if || p->update_source) {
10359 vty_out(vty, " Update source is ");
10360 if (p->update_if)
10361 vty_out(vty, "%s", p->update_if);
10362 else if (p->update_source)
10363 vty_out(vty, "%s",
10364 sockunion2str(p->update_source, buf1,
10365 SU_ADDRSTRLEN));
10366 vty_out(vty, "\n");
10367 }
10368
10369 vty_out(vty, "\n");
10370 }
10371
10372 /* Address Family Information */
10373 json_object *json_hold = NULL;
10374
10375 if (use_json)
10376 json_hold = json_object_new_object();
10377
10378 FOREACH_AFI_SAFI (afi, safi)
10379 if (p->afc[afi][safi])
10380 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10381 json_hold);
10382
10383 if (use_json) {
10384 json_object_object_add(json_neigh, "addressFamilyInfo",
10385 json_hold);
10386 json_object_int_add(json_neigh, "connectionsEstablished",
10387 p->established);
10388 json_object_int_add(json_neigh, "connectionsDropped",
10389 p->dropped);
10390 } else
10391 vty_out(vty, " Connections established %d; dropped %d\n",
10392 p->established, p->dropped);
10393
10394 if (!p->last_reset) {
10395 if (use_json)
10396 json_object_string_add(json_neigh, "lastReset",
10397 "never");
10398 else
10399 vty_out(vty, " Last reset never\n");
10400 } else {
10401 if (use_json) {
10402 time_t uptime;
10403 struct tm *tm;
10404
10405 uptime = bgp_clock();
10406 uptime -= p->resettime;
10407 tm = gmtime(&uptime);
10408 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10409 (tm->tm_sec * 1000)
10410 + (tm->tm_min * 60000)
10411 + (tm->tm_hour * 3600000));
10412 json_object_string_add(
10413 json_neigh, "lastResetDueTo",
10414 peer_down_str[(int)p->last_reset]);
10415 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10416 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10417 char errorcodesubcode_hexstr[5];
10418 char errorcodesubcode_str[256];
10419
10420 code_str = bgp_notify_code_str(p->notify.code);
10421 subcode_str = bgp_notify_subcode_str(
10422 p->notify.code, p->notify.subcode);
10423
10424 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10425 p->notify.code, p->notify.subcode);
10426 json_object_string_add(json_neigh,
10427 "lastErrorCodeSubcode",
10428 errorcodesubcode_hexstr);
10429 snprintf(errorcodesubcode_str, 255, "%s%s",
10430 code_str, subcode_str);
10431 json_object_string_add(json_neigh,
10432 "lastNotificationReason",
10433 errorcodesubcode_str);
10434 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10435 && p->notify.code == BGP_NOTIFY_CEASE
10436 && (p->notify.subcode
10437 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10438 || p->notify.subcode
10439 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10440 && p->notify.length) {
10441 char msgbuf[1024];
10442 const char *msg_str;
10443
10444 msg_str = bgp_notify_admin_message(
10445 msgbuf, sizeof(msgbuf),
10446 (uint8_t *)p->notify.data,
10447 p->notify.length);
10448 if (msg_str)
10449 json_object_string_add(
10450 json_neigh,
10451 "lastShutdownDescription",
10452 msg_str);
10453 }
10454 }
10455 } else {
10456 vty_out(vty, " Last reset %s, ",
10457 peer_uptime(p->resettime, timebuf,
10458 BGP_UPTIME_LEN, 0, NULL));
10459
10460 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10461 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10462 code_str = bgp_notify_code_str(p->notify.code);
10463 subcode_str = bgp_notify_subcode_str(
10464 p->notify.code, p->notify.subcode);
10465 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10466 p->last_reset == PEER_DOWN_NOTIFY_SEND
10467 ? "sent"
10468 : "received",
10469 code_str, subcode_str);
10470 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10471 && p->notify.code == BGP_NOTIFY_CEASE
10472 && (p->notify.subcode
10473 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10474 || p->notify.subcode
10475 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10476 && p->notify.length) {
10477 char msgbuf[1024];
10478 const char *msg_str;
10479
10480 msg_str = bgp_notify_admin_message(
10481 msgbuf, sizeof(msgbuf),
10482 (uint8_t *)p->notify.data,
10483 p->notify.length);
10484 if (msg_str)
10485 vty_out(vty,
10486 " Message: \"%s\"\n",
10487 msg_str);
10488 }
10489 } else {
10490 vty_out(vty, "due to %s\n",
10491 peer_down_str[(int)p->last_reset]);
10492 }
10493
10494 if (p->last_reset_cause_size) {
10495 msg = p->last_reset_cause;
10496 vty_out(vty,
10497 " Message received that caused BGP to send a NOTIFICATION:\n ");
10498 for (i = 1; i <= p->last_reset_cause_size;
10499 i++) {
10500 vty_out(vty, "%02X", *msg++);
10501
10502 if (i != p->last_reset_cause_size) {
10503 if (i % 16 == 0) {
10504 vty_out(vty, "\n ");
10505 } else if (i % 4 == 0) {
10506 vty_out(vty, " ");
10507 }
10508 }
10509 }
10510 vty_out(vty, "\n");
10511 }
10512 }
10513 }
10514
10515 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10516 if (use_json)
10517 json_object_boolean_true_add(json_neigh,
10518 "prefixesConfigExceedMax");
10519 else
10520 vty_out(vty,
10521 " Peer had exceeded the max. no. of prefixes configured.\n");
10522
10523 if (p->t_pmax_restart) {
10524 if (use_json) {
10525 json_object_boolean_true_add(
10526 json_neigh, "reducePrefixNumFrom");
10527 json_object_int_add(json_neigh,
10528 "restartInTimerMsec",
10529 thread_timer_remain_second(
10530 p->t_pmax_restart)
10531 * 1000);
10532 } else
10533 vty_out(vty,
10534 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10535 p->host, thread_timer_remain_second(
10536 p->t_pmax_restart));
10537 } else {
10538 if (use_json)
10539 json_object_boolean_true_add(
10540 json_neigh,
10541 "reducePrefixNumAndClearIpBgp");
10542 else
10543 vty_out(vty,
10544 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10545 p->host);
10546 }
10547 }
10548
10549 /* EBGP Multihop and GTSM */
10550 if (p->sort != BGP_PEER_IBGP) {
10551 if (use_json) {
10552 if (p->gtsm_hops > 0)
10553 json_object_int_add(json_neigh,
10554 "externalBgpNbrMaxHopsAway",
10555 p->gtsm_hops);
10556 else if (p->ttl > 1)
10557 json_object_int_add(json_neigh,
10558 "externalBgpNbrMaxHopsAway",
10559 p->ttl);
10560 } else {
10561 if (p->gtsm_hops > 0)
10562 vty_out(vty,
10563 " External BGP neighbor may be up to %d hops away.\n",
10564 p->gtsm_hops);
10565 else if (p->ttl > 1)
10566 vty_out(vty,
10567 " External BGP neighbor may be up to %d hops away.\n",
10568 p->ttl);
10569 }
10570 } else {
10571 if (p->gtsm_hops > 0) {
10572 if (use_json)
10573 json_object_int_add(json_neigh,
10574 "internalBgpNbrMaxHopsAway",
10575 p->gtsm_hops);
10576 else
10577 vty_out(vty,
10578 " Internal BGP neighbor may be up to %d hops away.\n",
10579 p->gtsm_hops);
10580 }
10581 }
10582
10583 /* Local address. */
10584 if (p->su_local) {
10585 if (use_json) {
10586 json_object_string_add(json_neigh, "hostLocal",
10587 sockunion2str(p->su_local, buf1,
10588 SU_ADDRSTRLEN));
10589 json_object_int_add(json_neigh, "portLocal",
10590 ntohs(p->su_local->sin.sin_port));
10591 } else
10592 vty_out(vty, "Local host: %s, Local port: %d\n",
10593 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10594 ntohs(p->su_local->sin.sin_port));
10595 }
10596
10597 /* Remote address. */
10598 if (p->su_remote) {
10599 if (use_json) {
10600 json_object_string_add(json_neigh, "hostForeign",
10601 sockunion2str(p->su_remote, buf1,
10602 SU_ADDRSTRLEN));
10603 json_object_int_add(json_neigh, "portForeign",
10604 ntohs(p->su_remote->sin.sin_port));
10605 } else
10606 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10607 sockunion2str(p->su_remote, buf1,
10608 SU_ADDRSTRLEN),
10609 ntohs(p->su_remote->sin.sin_port));
10610 }
10611
10612 /* Nexthop display. */
10613 if (p->su_local) {
10614 if (use_json) {
10615 json_object_string_add(json_neigh, "nexthop",
10616 inet_ntop(AF_INET,
10617 &p->nexthop.v4, buf1,
10618 sizeof(buf1)));
10619 json_object_string_add(json_neigh, "nexthopGlobal",
10620 inet_ntop(AF_INET6,
10621 &p->nexthop.v6_global,
10622 buf1, sizeof(buf1)));
10623 json_object_string_add(json_neigh, "nexthopLocal",
10624 inet_ntop(AF_INET6,
10625 &p->nexthop.v6_local,
10626 buf1, sizeof(buf1)));
10627 if (p->shared_network)
10628 json_object_string_add(json_neigh,
10629 "bgpConnection",
10630 "sharedNetwork");
10631 else
10632 json_object_string_add(json_neigh,
10633 "bgpConnection",
10634 "nonSharedNetwork");
10635 } else {
10636 vty_out(vty, "Nexthop: %s\n",
10637 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10638 sizeof(buf1)));
10639 vty_out(vty, "Nexthop global: %s\n",
10640 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10641 sizeof(buf1)));
10642 vty_out(vty, "Nexthop local: %s\n",
10643 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10644 sizeof(buf1)));
10645 vty_out(vty, "BGP connection: %s\n",
10646 p->shared_network ? "shared network"
10647 : "non shared network");
10648 }
10649 }
10650
10651 /* Timer information. */
10652 if (use_json) {
10653 json_object_int_add(json_neigh, "connectRetryTimer",
10654 p->v_connect);
10655 if (p->status == Established && p->rtt)
10656 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10657 p->rtt);
10658 if (p->t_start)
10659 json_object_int_add(
10660 json_neigh, "nextStartTimerDueInMsecs",
10661 thread_timer_remain_second(p->t_start) * 1000);
10662 if (p->t_connect)
10663 json_object_int_add(
10664 json_neigh, "nextConnectTimerDueInMsecs",
10665 thread_timer_remain_second(p->t_connect)
10666 * 1000);
10667 if (p->t_routeadv) {
10668 json_object_int_add(json_neigh, "mraiInterval",
10669 p->v_routeadv);
10670 json_object_int_add(
10671 json_neigh, "mraiTimerExpireInMsecs",
10672 thread_timer_remain_second(p->t_routeadv)
10673 * 1000);
10674 }
10675 if (p->password)
10676 json_object_int_add(json_neigh, "authenticationEnabled",
10677 1);
10678
10679 if (p->t_read)
10680 json_object_string_add(json_neigh, "readThread", "on");
10681 else
10682 json_object_string_add(json_neigh, "readThread", "off");
10683
10684 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10685 json_object_string_add(json_neigh, "writeThread", "on");
10686 else
10687 json_object_string_add(json_neigh, "writeThread",
10688 "off");
10689 } else {
10690 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10691 p->v_connect);
10692 if (p->status == Established && p->rtt)
10693 vty_out(vty, "Estimated round trip time: %d ms\n",
10694 p->rtt);
10695 if (p->t_start)
10696 vty_out(vty, "Next start timer due in %ld seconds\n",
10697 thread_timer_remain_second(p->t_start));
10698 if (p->t_connect)
10699 vty_out(vty, "Next connect timer due in %ld seconds\n",
10700 thread_timer_remain_second(p->t_connect));
10701 if (p->t_routeadv)
10702 vty_out(vty,
10703 "MRAI (interval %u) timer expires in %ld seconds\n",
10704 p->v_routeadv,
10705 thread_timer_remain_second(p->t_routeadv));
10706 if (p->password)
10707 vty_out(vty, "Peer Authentication Enabled\n");
10708
10709 vty_out(vty, "Read thread: %s Write thread: %s\n",
10710 p->t_read ? "on" : "off",
10711 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10712 ? "on"
10713 : "off");
10714 }
10715
10716 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10717 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10718 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10719
10720 if (!use_json)
10721 vty_out(vty, "\n");
10722
10723 /* BFD information. */
10724 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10725
10726 if (use_json) {
10727 if (p->conf_if) /* Configured interface name. */
10728 json_object_object_add(json, p->conf_if, json_neigh);
10729 else /* Configured IP address. */
10730 json_object_object_add(json, p->host, json_neigh);
10731 }
10732 }
10733
10734 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10735 enum show_type type, union sockunion *su,
10736 const char *conf_if, bool use_json,
10737 json_object *json)
10738 {
10739 struct listnode *node, *nnode;
10740 struct peer *peer;
10741 int find = 0;
10742 bool nbr_output = false;
10743
10744 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10745 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10746 continue;
10747
10748 switch (type) {
10749 case show_all:
10750 bgp_show_peer(vty, peer, use_json, json);
10751 nbr_output = true;
10752 break;
10753 case show_peer:
10754 if (conf_if) {
10755 if ((peer->conf_if
10756 && !strcmp(peer->conf_if, conf_if))
10757 || (peer->hostname
10758 && !strcmp(peer->hostname, conf_if))) {
10759 find = 1;
10760 bgp_show_peer(vty, peer, use_json,
10761 json);
10762 }
10763 } else {
10764 if (sockunion_same(&peer->su, su)) {
10765 find = 1;
10766 bgp_show_peer(vty, peer, use_json,
10767 json);
10768 }
10769 }
10770 break;
10771 }
10772 }
10773
10774 if (type == show_peer && !find) {
10775 if (use_json)
10776 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10777 else
10778 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10779 }
10780
10781 if (type != show_peer && !nbr_output && !use_json)
10782 vty_out(vty, "%% No BGP neighbors found\n");
10783
10784 if (use_json) {
10785 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10786 json, JSON_C_TO_STRING_PRETTY));
10787 json_object_free(json);
10788 } else {
10789 vty_out(vty, "\n");
10790 }
10791
10792 return CMD_SUCCESS;
10793 }
10794
10795 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10796 enum show_type type,
10797 const char *ip_str,
10798 bool use_json)
10799 {
10800 struct listnode *node, *nnode;
10801 struct bgp *bgp;
10802 union sockunion su;
10803 json_object *json = NULL;
10804 int ret, is_first = 1;
10805 bool nbr_output = false;
10806
10807 if (use_json)
10808 vty_out(vty, "{\n");
10809
10810 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10811 nbr_output = true;
10812 if (use_json) {
10813 if (!(json = json_object_new_object())) {
10814 flog_err(
10815 EC_BGP_JSON_MEM_ERROR,
10816 "Unable to allocate memory for JSON object");
10817 vty_out(vty,
10818 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10819 return;
10820 }
10821
10822 json_object_int_add(json, "vrfId",
10823 (bgp->vrf_id == VRF_UNKNOWN)
10824 ? -1
10825 : (int64_t)bgp->vrf_id);
10826 json_object_string_add(
10827 json, "vrfName",
10828 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10829 ? "Default"
10830 : bgp->name);
10831
10832 if (!is_first)
10833 vty_out(vty, ",\n");
10834 else
10835 is_first = 0;
10836
10837 vty_out(vty, "\"%s\":",
10838 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10839 ? "Default"
10840 : bgp->name);
10841 } else {
10842 vty_out(vty, "\nInstance %s:\n",
10843 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10844 ? "Default"
10845 : bgp->name);
10846 }
10847
10848 if (type == show_peer) {
10849 ret = str2sockunion(ip_str, &su);
10850 if (ret < 0)
10851 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10852 use_json, json);
10853 else
10854 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10855 use_json, json);
10856 } else {
10857 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10858 use_json, json);
10859 }
10860 }
10861
10862 if (use_json)
10863 vty_out(vty, "}\n");
10864 else if (!nbr_output)
10865 vty_out(vty, "%% BGP instance not found\n");
10866 }
10867
10868 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10869 enum show_type type, const char *ip_str,
10870 bool use_json)
10871 {
10872 int ret;
10873 struct bgp *bgp;
10874 union sockunion su;
10875 json_object *json = NULL;
10876
10877 if (name) {
10878 if (strmatch(name, "all")) {
10879 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10880 use_json);
10881 return CMD_SUCCESS;
10882 } else {
10883 bgp = bgp_lookup_by_name(name);
10884 if (!bgp) {
10885 if (use_json) {
10886 json = json_object_new_object();
10887 vty_out(vty, "%s\n",
10888 json_object_to_json_string_ext(
10889 json,
10890 JSON_C_TO_STRING_PRETTY));
10891 json_object_free(json);
10892 } else
10893 vty_out(vty,
10894 "%% BGP instance not found\n");
10895
10896 return CMD_WARNING;
10897 }
10898 }
10899 } else {
10900 bgp = bgp_get_default();
10901 }
10902
10903 if (bgp) {
10904 json = json_object_new_object();
10905 if (ip_str) {
10906 ret = str2sockunion(ip_str, &su);
10907 if (ret < 0)
10908 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10909 use_json, json);
10910 else
10911 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10912 use_json, json);
10913 } else {
10914 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10915 json);
10916 }
10917 json_object_free(json);
10918 } else {
10919 if (use_json)
10920 vty_out(vty, "{}\n");
10921 else
10922 vty_out(vty, "%% BGP instance not found\n");
10923 }
10924
10925 return CMD_SUCCESS;
10926 }
10927
10928 /* "show [ip] bgp neighbors" commands. */
10929 DEFUN (show_ip_bgp_neighbors,
10930 show_ip_bgp_neighbors_cmd,
10931 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10932 SHOW_STR
10933 IP_STR
10934 BGP_STR
10935 BGP_INSTANCE_HELP_STR
10936 "Address Family\n"
10937 "Address Family\n"
10938 "Detailed information on TCP and BGP neighbor connections\n"
10939 "Neighbor to display information about\n"
10940 "Neighbor to display information about\n"
10941 "Neighbor on BGP configured interface\n"
10942 JSON_STR)
10943 {
10944 char *vrf = NULL;
10945 char *sh_arg = NULL;
10946 enum show_type sh_type;
10947
10948 bool uj = use_json(argc, argv);
10949
10950 int idx = 0;
10951
10952 /* [<vrf> VIEWVRFNAME] */
10953 if (argv_find(argv, argc, "vrf", &idx)) {
10954 vrf = argv[idx + 1]->arg;
10955 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
10956 vrf = NULL;
10957 } else if (argv_find(argv, argc, "view", &idx))
10958 /* [<view> VIEWVRFNAME] */
10959 vrf = argv[idx + 1]->arg;
10960
10961 idx++;
10962 if (argv_find(argv, argc, "A.B.C.D", &idx)
10963 || argv_find(argv, argc, "X:X::X:X", &idx)
10964 || argv_find(argv, argc, "WORD", &idx)) {
10965 sh_type = show_peer;
10966 sh_arg = argv[idx]->arg;
10967 } else
10968 sh_type = show_all;
10969
10970 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10971 }
10972
10973 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10974 paths' and `show ip mbgp paths'. Those functions results are the
10975 same.*/
10976 DEFUN (show_ip_bgp_paths,
10977 show_ip_bgp_paths_cmd,
10978 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10979 SHOW_STR
10980 IP_STR
10981 BGP_STR
10982 BGP_SAFI_HELP_STR
10983 "Path information\n")
10984 {
10985 vty_out(vty, "Address Refcnt Path\n");
10986 aspath_print_all_vty(vty);
10987 return CMD_SUCCESS;
10988 }
10989
10990 #include "hash.h"
10991
10992 static void community_show_all_iterator(struct hash_backet *backet,
10993 struct vty *vty)
10994 {
10995 struct community *com;
10996
10997 com = (struct community *)backet->data;
10998 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10999 community_str(com, false));
11000 }
11001
11002 /* Show BGP's community internal data. */
11003 DEFUN (show_ip_bgp_community_info,
11004 show_ip_bgp_community_info_cmd,
11005 "show [ip] bgp community-info",
11006 SHOW_STR
11007 IP_STR
11008 BGP_STR
11009 "List all bgp community information\n")
11010 {
11011 vty_out(vty, "Address Refcnt Community\n");
11012
11013 hash_iterate(community_hash(),
11014 (void (*)(struct hash_backet *,
11015 void *))community_show_all_iterator,
11016 vty);
11017
11018 return CMD_SUCCESS;
11019 }
11020
11021 static void lcommunity_show_all_iterator(struct hash_backet *backet,
11022 struct vty *vty)
11023 {
11024 struct lcommunity *lcom;
11025
11026 lcom = (struct lcommunity *)backet->data;
11027 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
11028 lcommunity_str(lcom, false));
11029 }
11030
11031 /* Show BGP's community internal data. */
11032 DEFUN (show_ip_bgp_lcommunity_info,
11033 show_ip_bgp_lcommunity_info_cmd,
11034 "show ip bgp large-community-info",
11035 SHOW_STR
11036 IP_STR
11037 BGP_STR
11038 "List all bgp large-community information\n")
11039 {
11040 vty_out(vty, "Address Refcnt Large-community\n");
11041
11042 hash_iterate(lcommunity_hash(),
11043 (void (*)(struct hash_backet *,
11044 void *))lcommunity_show_all_iterator,
11045 vty);
11046
11047 return CMD_SUCCESS;
11048 }
11049
11050
11051 DEFUN (show_ip_bgp_attr_info,
11052 show_ip_bgp_attr_info_cmd,
11053 "show [ip] bgp attribute-info",
11054 SHOW_STR
11055 IP_STR
11056 BGP_STR
11057 "List all bgp attribute information\n")
11058 {
11059 attr_show_all(vty);
11060 return CMD_SUCCESS;
11061 }
11062
11063 static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi,
11064 safi_t safi, bool use_json)
11065 {
11066 struct bgp *bgp;
11067 struct listnode *node;
11068 char *vname;
11069 char buf1[INET6_ADDRSTRLEN];
11070 char *ecom_str;
11071 vpn_policy_direction_t dir;
11072
11073 if (use_json) {
11074 json_object *json = NULL;
11075 json_object *json_import_vrfs = NULL;
11076 json_object *json_export_vrfs = NULL;
11077
11078 json = json_object_new_object();
11079
11080 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11081
11082 if (!bgp) {
11083 vty_out(vty, "%s\n",
11084 json_object_to_json_string_ext(
11085 json,
11086 JSON_C_TO_STRING_PRETTY));
11087 json_object_free(json);
11088
11089 return CMD_WARNING;
11090 }
11091
11092 /* Provide context for the block */
11093 json_object_string_add(json, "vrf", name ? name : "default");
11094 json_object_string_add(json, "afiSafi",
11095 afi_safi_print(afi, safi));
11096
11097 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11098 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
11099 json_object_string_add(json, "importFromVrfs", "none");
11100 json_object_string_add(json, "importRts", "none");
11101 } else {
11102 json_import_vrfs = json_object_new_array();
11103
11104 for (ALL_LIST_ELEMENTS_RO(
11105 bgp->vpn_policy[afi].import_vrf,
11106 node, vname))
11107 json_object_array_add(json_import_vrfs,
11108 json_object_new_string(vname));
11109
11110 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11111 ecom_str = ecommunity_ecom2str(
11112 bgp->vpn_policy[afi].rtlist[dir],
11113 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11114 json_object_object_add(json, "importFromVrfs",
11115 json_import_vrfs);
11116 json_object_string_add(json, "importRts", ecom_str);
11117
11118 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11119 }
11120
11121 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11122 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11123 json_object_string_add(json, "exportToVrfs", "none");
11124 json_object_string_add(json, "routeDistinguisher",
11125 "none");
11126 json_object_string_add(json, "exportRts", "none");
11127 } else {
11128 json_export_vrfs = json_object_new_array();
11129
11130 for (ALL_LIST_ELEMENTS_RO(
11131 bgp->vpn_policy[afi].export_vrf,
11132 node, vname))
11133 json_object_array_add(json_export_vrfs,
11134 json_object_new_string(vname));
11135 json_object_object_add(json, "exportToVrfs",
11136 json_export_vrfs);
11137 json_object_string_add(json, "routeDistinguisher",
11138 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11139 buf1, RD_ADDRSTRLEN));
11140
11141 dir = BGP_VPN_POLICY_DIR_TOVPN;
11142 ecom_str = ecommunity_ecom2str(
11143 bgp->vpn_policy[afi].rtlist[dir],
11144 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11145 json_object_string_add(json, "exportRts", ecom_str);
11146
11147 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11148 }
11149
11150 vty_out(vty, "%s\n",
11151 json_object_to_json_string_ext(json,
11152 JSON_C_TO_STRING_PRETTY));
11153 json_object_free(json);
11154
11155 } else {
11156 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11157
11158 if (!bgp) {
11159 vty_out(vty, "%% No such BGP instance exist\n");
11160 return CMD_WARNING;
11161 }
11162
11163 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11164 BGP_CONFIG_VRF_TO_VRF_IMPORT))
11165 vty_out(vty,
11166 "This VRF is not importing %s routes from any other VRF\n",
11167 afi_safi_print(afi, safi));
11168 else {
11169 vty_out(vty,
11170 "This VRF is importing %s routes from the following VRFs:\n",
11171 afi_safi_print(afi, safi));
11172
11173 for (ALL_LIST_ELEMENTS_RO(
11174 bgp->vpn_policy[afi].import_vrf,
11175 node, vname))
11176 vty_out(vty, " %s\n", vname);
11177
11178 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11179 ecom_str = ecommunity_ecom2str(
11180 bgp->vpn_policy[afi].rtlist[dir],
11181 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11182 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11183
11184 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11185 }
11186
11187 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11188 BGP_CONFIG_VRF_TO_VRF_EXPORT))
11189 vty_out(vty,
11190 "This VRF is not exporting %s routes to any other VRF\n",
11191 afi_safi_print(afi, safi));
11192 else {
11193 vty_out(vty,
11194 "This VRF is exporting %s routes to the following VRFs:\n",
11195 afi_safi_print(afi, safi));
11196
11197 for (ALL_LIST_ELEMENTS_RO(
11198 bgp->vpn_policy[afi].export_vrf,
11199 node, vname))
11200 vty_out(vty, " %s\n", vname);
11201
11202 vty_out(vty, "RD: %s\n",
11203 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11204 buf1, RD_ADDRSTRLEN));
11205
11206 dir = BGP_VPN_POLICY_DIR_TOVPN;
11207 ecom_str = ecommunity_ecom2str(
11208 bgp->vpn_policy[afi].rtlist[dir],
11209 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11210 vty_out(vty, "Export RT: %s\n", ecom_str);
11211 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11212 }
11213 }
11214
11215 return CMD_SUCCESS;
11216 }
11217
11218 /* "show [ip] bgp route-leak" command. */
11219 DEFUN (show_ip_bgp_route_leak,
11220 show_ip_bgp_route_leak_cmd,
11221 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak [json]",
11222 SHOW_STR
11223 IP_STR
11224 BGP_STR
11225 BGP_INSTANCE_HELP_STR
11226 BGP_AFI_HELP_STR
11227 BGP_SAFI_HELP_STR
11228 "Route leaking information\n"
11229 JSON_STR)
11230 {
11231 char *vrf = NULL;
11232 afi_t afi = AFI_MAX;
11233 safi_t safi = SAFI_MAX;
11234
11235 bool uj = use_json(argc, argv);
11236 int idx = 0;
11237
11238 /* show [ip] bgp */
11239 if (argv_find(argv, argc, "ip", &idx)) {
11240 afi = AFI_IP;
11241 safi = SAFI_UNICAST;
11242 }
11243 /* [vrf VIEWVRFNAME] */
11244 if (argv_find(argv, argc, "view", &idx)) {
11245 vty_out(vty,
11246 "%% This command is not applicable to BGP views\n");
11247 return CMD_WARNING;
11248 }
11249
11250 if (argv_find(argv, argc, "vrf", &idx)) {
11251 vrf = argv[idx + 1]->arg;
11252 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11253 vrf = NULL;
11254 }
11255 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11256 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11257 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11258 }
11259
11260 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11261 vty_out(vty,
11262 "%% This command is applicable only for unicast ipv4|ipv6\n");
11263 return CMD_WARNING;
11264 }
11265
11266 return bgp_show_route_leak_vty(vty, vrf, afi, safi, uj);
11267 }
11268
11269 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11270 safi_t safi)
11271 {
11272 struct listnode *node, *nnode;
11273 struct bgp *bgp;
11274
11275 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11276 vty_out(vty, "\nInstance %s:\n",
11277 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11278 ? "Default"
11279 : bgp->name);
11280 update_group_show(bgp, afi, safi, vty, 0);
11281 }
11282 }
11283
11284 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11285 int safi, uint64_t subgrp_id)
11286 {
11287 struct bgp *bgp;
11288
11289 if (name) {
11290 if (strmatch(name, "all")) {
11291 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11292 return CMD_SUCCESS;
11293 } else {
11294 bgp = bgp_lookup_by_name(name);
11295 }
11296 } else {
11297 bgp = bgp_get_default();
11298 }
11299
11300 if (bgp)
11301 update_group_show(bgp, afi, safi, vty, subgrp_id);
11302 return CMD_SUCCESS;
11303 }
11304
11305 DEFUN (show_ip_bgp_updgrps,
11306 show_ip_bgp_updgrps_cmd,
11307 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11308 SHOW_STR
11309 IP_STR
11310 BGP_STR
11311 BGP_INSTANCE_HELP_STR
11312 BGP_AFI_HELP_STR
11313 BGP_SAFI_WITH_LABEL_HELP_STR
11314 "Detailed info about dynamic update groups\n"
11315 "Specific subgroup to display detailed info for\n")
11316 {
11317 char *vrf = NULL;
11318 afi_t afi = AFI_IP6;
11319 safi_t safi = SAFI_UNICAST;
11320 uint64_t subgrp_id = 0;
11321
11322 int idx = 0;
11323
11324 /* show [ip] bgp */
11325 if (argv_find(argv, argc, "ip", &idx))
11326 afi = AFI_IP;
11327 /* [<vrf> VIEWVRFNAME] */
11328 if (argv_find(argv, argc, "vrf", &idx)) {
11329 vrf = argv[idx + 1]->arg;
11330 if (vrf && strmatch(vrf, VRF_DEFAULT_NAME))
11331 vrf = NULL;
11332 } else if (argv_find(argv, argc, "view", &idx))
11333 /* [<view> VIEWVRFNAME] */
11334 vrf = argv[idx + 1]->arg;
11335 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11336 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11337 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11338 }
11339
11340 /* get subgroup id, if provided */
11341 idx = argc - 1;
11342 if (argv[idx]->type == VARIABLE_TKN)
11343 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11344
11345 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11346 }
11347
11348 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11349 show_bgp_instance_all_ipv6_updgrps_cmd,
11350 "show [ip] bgp <view|vrf> all update-groups",
11351 SHOW_STR
11352 IP_STR
11353 BGP_STR
11354 BGP_INSTANCE_ALL_HELP_STR
11355 "Detailed info about dynamic update groups\n")
11356 {
11357 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11358 return CMD_SUCCESS;
11359 }
11360
11361 DEFUN (show_bgp_updgrps_stats,
11362 show_bgp_updgrps_stats_cmd,
11363 "show [ip] bgp update-groups statistics",
11364 SHOW_STR
11365 IP_STR
11366 BGP_STR
11367 "Detailed info about dynamic update groups\n"
11368 "Statistics\n")
11369 {
11370 struct bgp *bgp;
11371
11372 bgp = bgp_get_default();
11373 if (bgp)
11374 update_group_show_stats(bgp, vty);
11375
11376 return CMD_SUCCESS;
11377 }
11378
11379 DEFUN (show_bgp_instance_updgrps_stats,
11380 show_bgp_instance_updgrps_stats_cmd,
11381 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11382 SHOW_STR
11383 IP_STR
11384 BGP_STR
11385 BGP_INSTANCE_HELP_STR
11386 "Detailed info about dynamic update groups\n"
11387 "Statistics\n")
11388 {
11389 int idx_word = 3;
11390 struct bgp *bgp;
11391
11392 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11393 if (bgp)
11394 update_group_show_stats(bgp, vty);
11395
11396 return CMD_SUCCESS;
11397 }
11398
11399 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11400 afi_t afi, safi_t safi,
11401 const char *what, uint64_t subgrp_id)
11402 {
11403 struct bgp *bgp;
11404
11405 if (name)
11406 bgp = bgp_lookup_by_name(name);
11407 else
11408 bgp = bgp_get_default();
11409
11410 if (bgp) {
11411 if (!strcmp(what, "advertise-queue"))
11412 update_group_show_adj_queue(bgp, afi, safi, vty,
11413 subgrp_id);
11414 else if (!strcmp(what, "advertised-routes"))
11415 update_group_show_advertised(bgp, afi, safi, vty,
11416 subgrp_id);
11417 else if (!strcmp(what, "packet-queue"))
11418 update_group_show_packet_queue(bgp, afi, safi, vty,
11419 subgrp_id);
11420 }
11421 }
11422
11423 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11424 show_ip_bgp_instance_updgrps_adj_s_cmd,
11425 "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",
11426 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11427 BGP_SAFI_HELP_STR
11428 "Detailed info about dynamic update groups\n"
11429 "Specific subgroup to display info for\n"
11430 "Advertisement queue\n"
11431 "Announced routes\n"
11432 "Packet queue\n")
11433 {
11434 uint64_t subgrp_id = 0;
11435 afi_t afiz;
11436 safi_t safiz;
11437 if (sgid)
11438 subgrp_id = strtoull(sgid, NULL, 10);
11439
11440 if (!ip && !afi)
11441 afiz = AFI_IP6;
11442 if (!ip && afi)
11443 afiz = bgp_vty_afi_from_str(afi);
11444 if (ip && !afi)
11445 afiz = AFI_IP;
11446 if (ip && afi) {
11447 afiz = bgp_vty_afi_from_str(afi);
11448 if (afiz != AFI_IP)
11449 vty_out(vty,
11450 "%% Cannot specify both 'ip' and 'ipv6'\n");
11451 return CMD_WARNING;
11452 }
11453
11454 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11455
11456 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11457 return CMD_SUCCESS;
11458 }
11459
11460 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11461 {
11462 struct listnode *node, *nnode;
11463 struct prefix *range;
11464 struct peer *conf;
11465 struct peer *peer;
11466 char buf[PREFIX2STR_BUFFER];
11467 afi_t afi;
11468 safi_t safi;
11469 const char *peer_status;
11470 const char *af_str;
11471 int lr_count;
11472 int dynamic;
11473 int af_cfgd;
11474
11475 conf = group->conf;
11476
11477 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11478 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11479 conf->as);
11480 } else if (conf->as_type == AS_INTERNAL) {
11481 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11482 group->bgp->as);
11483 } else {
11484 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11485 }
11486
11487 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11488 vty_out(vty, " Peer-group type is internal\n");
11489 else
11490 vty_out(vty, " Peer-group type is external\n");
11491
11492 /* Display AFs configured. */
11493 vty_out(vty, " Configured address-families:");
11494 FOREACH_AFI_SAFI (afi, safi) {
11495 if (conf->afc[afi][safi]) {
11496 af_cfgd = 1;
11497 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11498 }
11499 }
11500 if (!af_cfgd)
11501 vty_out(vty, " none\n");
11502 else
11503 vty_out(vty, "\n");
11504
11505 /* Display listen ranges (for dynamic neighbors), if any */
11506 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11507 if (afi == AFI_IP)
11508 af_str = "IPv4";
11509 else if (afi == AFI_IP6)
11510 af_str = "IPv6";
11511 else
11512 af_str = "???";
11513 lr_count = listcount(group->listen_range[afi]);
11514 if (lr_count) {
11515 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11516 af_str);
11517
11518
11519 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11520 nnode, range)) {
11521 prefix2str(range, buf, sizeof(buf));
11522 vty_out(vty, " %s\n", buf);
11523 }
11524 }
11525 }
11526
11527 /* Display group members and their status */
11528 if (listcount(group->peer)) {
11529 vty_out(vty, " Peer-group members:\n");
11530 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11531 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11532 peer_status = "Idle (Admin)";
11533 else if (CHECK_FLAG(peer->sflags,
11534 PEER_STATUS_PREFIX_OVERFLOW))
11535 peer_status = "Idle (PfxCt)";
11536 else
11537 peer_status = lookup_msg(bgp_status_msg,
11538 peer->status, NULL);
11539
11540 dynamic = peer_dynamic_neighbor(peer);
11541 vty_out(vty, " %s %s %s \n", peer->host,
11542 dynamic ? "(dynamic)" : "", peer_status);
11543 }
11544 }
11545
11546 return CMD_SUCCESS;
11547 }
11548
11549 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11550 const char *group_name)
11551 {
11552 struct bgp *bgp;
11553 struct listnode *node, *nnode;
11554 struct peer_group *group;
11555 bool found = false;
11556
11557 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11558
11559 if (!bgp) {
11560 vty_out(vty, "%% BGP instance not found\n");
11561 return CMD_WARNING;
11562 }
11563
11564 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11565 if (group_name) {
11566 if (strmatch(group->name, group_name)) {
11567 bgp_show_one_peer_group(vty, group);
11568 found = true;
11569 break;
11570 }
11571 } else {
11572 bgp_show_one_peer_group(vty, group);
11573 }
11574 }
11575
11576 if (group_name && !found)
11577 vty_out(vty, "%% No such peer-group\n");
11578
11579 return CMD_SUCCESS;
11580 }
11581
11582 DEFUN (show_ip_bgp_peer_groups,
11583 show_ip_bgp_peer_groups_cmd,
11584 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11585 SHOW_STR
11586 IP_STR
11587 BGP_STR
11588 BGP_INSTANCE_HELP_STR
11589 "Detailed information on BGP peer groups\n"
11590 "Peer group name\n")
11591 {
11592 char *vrf, *pg;
11593 int idx = 0;
11594
11595 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11596 : NULL;
11597 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11598
11599 return bgp_show_peer_group_vty(vty, vrf, pg);
11600 }
11601
11602
11603 /* Redistribute VTY commands. */
11604
11605 DEFUN (bgp_redistribute_ipv4,
11606 bgp_redistribute_ipv4_cmd,
11607 "redistribute " FRR_IP_REDIST_STR_BGPD,
11608 "Redistribute information from another routing protocol\n"
11609 FRR_IP_REDIST_HELP_STR_BGPD)
11610 {
11611 VTY_DECLVAR_CONTEXT(bgp, bgp);
11612 int idx_protocol = 1;
11613 int type;
11614
11615 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11616 if (type < 0) {
11617 vty_out(vty, "%% Invalid route type\n");
11618 return CMD_WARNING_CONFIG_FAILED;
11619 }
11620
11621 bgp_redist_add(bgp, AFI_IP, type, 0);
11622 return bgp_redistribute_set(bgp, AFI_IP, type, 0, false);
11623 }
11624
11625 ALIAS_HIDDEN(
11626 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11627 "redistribute " FRR_IP_REDIST_STR_BGPD,
11628 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11629
11630 DEFUN (bgp_redistribute_ipv4_rmap,
11631 bgp_redistribute_ipv4_rmap_cmd,
11632 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11633 "Redistribute information from another routing protocol\n"
11634 FRR_IP_REDIST_HELP_STR_BGPD
11635 "Route map reference\n"
11636 "Pointer to route-map entries\n")
11637 {
11638 VTY_DECLVAR_CONTEXT(bgp, bgp);
11639 int idx_protocol = 1;
11640 int idx_word = 3;
11641 int type;
11642 struct bgp_redist *red;
11643 bool changed;
11644
11645 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11646 if (type < 0) {
11647 vty_out(vty, "%% Invalid route type\n");
11648 return CMD_WARNING_CONFIG_FAILED;
11649 }
11650
11651 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11652 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11653 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11654 }
11655
11656 ALIAS_HIDDEN(
11657 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11658 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11659 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11660 "Route map reference\n"
11661 "Pointer to route-map entries\n")
11662
11663 DEFUN (bgp_redistribute_ipv4_metric,
11664 bgp_redistribute_ipv4_metric_cmd,
11665 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11666 "Redistribute information from another routing protocol\n"
11667 FRR_IP_REDIST_HELP_STR_BGPD
11668 "Metric for redistributed routes\n"
11669 "Default metric\n")
11670 {
11671 VTY_DECLVAR_CONTEXT(bgp, bgp);
11672 int idx_protocol = 1;
11673 int idx_number = 3;
11674 int type;
11675 uint32_t metric;
11676 struct bgp_redist *red;
11677 bool changed;
11678
11679 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11680 if (type < 0) {
11681 vty_out(vty, "%% Invalid route type\n");
11682 return CMD_WARNING_CONFIG_FAILED;
11683 }
11684 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11685
11686 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11687 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11688 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11689 }
11690
11691 ALIAS_HIDDEN(
11692 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11693 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11694 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11695 "Metric for redistributed routes\n"
11696 "Default metric\n")
11697
11698 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11699 bgp_redistribute_ipv4_rmap_metric_cmd,
11700 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11701 "Redistribute information from another routing protocol\n"
11702 FRR_IP_REDIST_HELP_STR_BGPD
11703 "Route map reference\n"
11704 "Pointer to route-map entries\n"
11705 "Metric for redistributed routes\n"
11706 "Default metric\n")
11707 {
11708 VTY_DECLVAR_CONTEXT(bgp, bgp);
11709 int idx_protocol = 1;
11710 int idx_word = 3;
11711 int idx_number = 5;
11712 int type;
11713 uint32_t metric;
11714 struct bgp_redist *red;
11715 bool changed;
11716
11717 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11718 if (type < 0) {
11719 vty_out(vty, "%% Invalid route type\n");
11720 return CMD_WARNING_CONFIG_FAILED;
11721 }
11722 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11723
11724 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11725 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11726 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11727 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11728 }
11729
11730 ALIAS_HIDDEN(
11731 bgp_redistribute_ipv4_rmap_metric,
11732 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11733 "redistribute " FRR_IP_REDIST_STR_BGPD
11734 " route-map WORD metric (0-4294967295)",
11735 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11736 "Route map reference\n"
11737 "Pointer to route-map entries\n"
11738 "Metric for redistributed routes\n"
11739 "Default metric\n")
11740
11741 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11742 bgp_redistribute_ipv4_metric_rmap_cmd,
11743 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11744 "Redistribute information from another routing protocol\n"
11745 FRR_IP_REDIST_HELP_STR_BGPD
11746 "Metric for redistributed routes\n"
11747 "Default metric\n"
11748 "Route map reference\n"
11749 "Pointer to route-map entries\n")
11750 {
11751 VTY_DECLVAR_CONTEXT(bgp, bgp);
11752 int idx_protocol = 1;
11753 int idx_number = 3;
11754 int idx_word = 5;
11755 int type;
11756 uint32_t metric;
11757 struct bgp_redist *red;
11758 bool changed;
11759
11760 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11761 if (type < 0) {
11762 vty_out(vty, "%% Invalid route type\n");
11763 return CMD_WARNING_CONFIG_FAILED;
11764 }
11765 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11766
11767 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11768 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11769 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11770 return bgp_redistribute_set(bgp, AFI_IP, type, 0, changed);
11771 }
11772
11773 ALIAS_HIDDEN(
11774 bgp_redistribute_ipv4_metric_rmap,
11775 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11776 "redistribute " FRR_IP_REDIST_STR_BGPD
11777 " metric (0-4294967295) route-map WORD",
11778 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11779 "Metric for redistributed routes\n"
11780 "Default metric\n"
11781 "Route map reference\n"
11782 "Pointer to route-map entries\n")
11783
11784 DEFUN (bgp_redistribute_ipv4_ospf,
11785 bgp_redistribute_ipv4_ospf_cmd,
11786 "redistribute <ospf|table> (1-65535)",
11787 "Redistribute information from another routing protocol\n"
11788 "Open Shortest Path First (OSPFv2)\n"
11789 "Non-main Kernel Routing Table\n"
11790 "Instance ID/Table ID\n")
11791 {
11792 VTY_DECLVAR_CONTEXT(bgp, bgp);
11793 int idx_ospf_table = 1;
11794 int idx_number = 2;
11795 unsigned short instance;
11796 unsigned short protocol;
11797
11798 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11799
11800 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11801 protocol = ZEBRA_ROUTE_OSPF;
11802 else
11803 protocol = ZEBRA_ROUTE_TABLE;
11804
11805 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11806 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
11807 }
11808
11809 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11810 "redistribute <ospf|table> (1-65535)",
11811 "Redistribute information from another routing protocol\n"
11812 "Open Shortest Path First (OSPFv2)\n"
11813 "Non-main Kernel Routing Table\n"
11814 "Instance ID/Table ID\n")
11815
11816 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11817 bgp_redistribute_ipv4_ospf_rmap_cmd,
11818 "redistribute <ospf|table> (1-65535) route-map WORD",
11819 "Redistribute information from another routing protocol\n"
11820 "Open Shortest Path First (OSPFv2)\n"
11821 "Non-main Kernel Routing Table\n"
11822 "Instance ID/Table ID\n"
11823 "Route map reference\n"
11824 "Pointer to route-map entries\n")
11825 {
11826 VTY_DECLVAR_CONTEXT(bgp, bgp);
11827 int idx_ospf_table = 1;
11828 int idx_number = 2;
11829 int idx_word = 4;
11830 struct bgp_redist *red;
11831 unsigned short instance;
11832 int protocol;
11833 bool changed;
11834
11835 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11836 protocol = ZEBRA_ROUTE_OSPF;
11837 else
11838 protocol = ZEBRA_ROUTE_TABLE;
11839
11840 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11841 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11842 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11843 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11844 }
11845
11846 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11847 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11848 "redistribute <ospf|table> (1-65535) route-map WORD",
11849 "Redistribute information from another routing protocol\n"
11850 "Open Shortest Path First (OSPFv2)\n"
11851 "Non-main Kernel Routing Table\n"
11852 "Instance ID/Table ID\n"
11853 "Route map reference\n"
11854 "Pointer to route-map entries\n")
11855
11856 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11857 bgp_redistribute_ipv4_ospf_metric_cmd,
11858 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11859 "Redistribute information from another routing protocol\n"
11860 "Open Shortest Path First (OSPFv2)\n"
11861 "Non-main Kernel Routing Table\n"
11862 "Instance ID/Table ID\n"
11863 "Metric for redistributed routes\n"
11864 "Default metric\n")
11865 {
11866 VTY_DECLVAR_CONTEXT(bgp, bgp);
11867 int idx_ospf_table = 1;
11868 int idx_number = 2;
11869 int idx_number_2 = 4;
11870 uint32_t metric;
11871 struct bgp_redist *red;
11872 unsigned short instance;
11873 int protocol;
11874 bool changed;
11875
11876 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11877 protocol = ZEBRA_ROUTE_OSPF;
11878 else
11879 protocol = ZEBRA_ROUTE_TABLE;
11880
11881 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11882 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11883
11884 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11885 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11886 metric);
11887 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11888 }
11889
11890 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11891 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11892 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11893 "Redistribute information from another routing protocol\n"
11894 "Open Shortest Path First (OSPFv2)\n"
11895 "Non-main Kernel Routing Table\n"
11896 "Instance ID/Table ID\n"
11897 "Metric for redistributed routes\n"
11898 "Default metric\n")
11899
11900 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11901 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11902 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11903 "Redistribute information from another routing protocol\n"
11904 "Open Shortest Path First (OSPFv2)\n"
11905 "Non-main Kernel Routing Table\n"
11906 "Instance ID/Table ID\n"
11907 "Route map reference\n"
11908 "Pointer to route-map entries\n"
11909 "Metric for redistributed routes\n"
11910 "Default metric\n")
11911 {
11912 VTY_DECLVAR_CONTEXT(bgp, bgp);
11913 int idx_ospf_table = 1;
11914 int idx_number = 2;
11915 int idx_word = 4;
11916 int idx_number_2 = 6;
11917 uint32_t metric;
11918 struct bgp_redist *red;
11919 unsigned short instance;
11920 int protocol;
11921 bool changed;
11922
11923 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11924 protocol = ZEBRA_ROUTE_OSPF;
11925 else
11926 protocol = ZEBRA_ROUTE_TABLE;
11927
11928 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11929 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11930
11931 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11932 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11933 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11934 metric);
11935 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11936 }
11937
11938 ALIAS_HIDDEN(
11939 bgp_redistribute_ipv4_ospf_rmap_metric,
11940 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11941 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11942 "Redistribute information from another routing protocol\n"
11943 "Open Shortest Path First (OSPFv2)\n"
11944 "Non-main Kernel Routing Table\n"
11945 "Instance ID/Table ID\n"
11946 "Route map reference\n"
11947 "Pointer to route-map entries\n"
11948 "Metric for redistributed routes\n"
11949 "Default metric\n")
11950
11951 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11952 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11953 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11954 "Redistribute information from another routing protocol\n"
11955 "Open Shortest Path First (OSPFv2)\n"
11956 "Non-main Kernel Routing Table\n"
11957 "Instance ID/Table ID\n"
11958 "Metric for redistributed routes\n"
11959 "Default metric\n"
11960 "Route map reference\n"
11961 "Pointer to route-map entries\n")
11962 {
11963 VTY_DECLVAR_CONTEXT(bgp, bgp);
11964 int idx_ospf_table = 1;
11965 int idx_number = 2;
11966 int idx_number_2 = 4;
11967 int idx_word = 6;
11968 uint32_t metric;
11969 struct bgp_redist *red;
11970 unsigned short instance;
11971 int protocol;
11972 bool changed;
11973
11974 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11975 protocol = ZEBRA_ROUTE_OSPF;
11976 else
11977 protocol = ZEBRA_ROUTE_TABLE;
11978
11979 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11980 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11981
11982 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11983 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol,
11984 metric);
11985 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11986 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, changed);
11987 }
11988
11989 ALIAS_HIDDEN(
11990 bgp_redistribute_ipv4_ospf_metric_rmap,
11991 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11992 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11993 "Redistribute information from another routing protocol\n"
11994 "Open Shortest Path First (OSPFv2)\n"
11995 "Non-main Kernel Routing Table\n"
11996 "Instance ID/Table ID\n"
11997 "Metric for redistributed routes\n"
11998 "Default metric\n"
11999 "Route map reference\n"
12000 "Pointer to route-map entries\n")
12001
12002 DEFUN (no_bgp_redistribute_ipv4_ospf,
12003 no_bgp_redistribute_ipv4_ospf_cmd,
12004 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12005 NO_STR
12006 "Redistribute information from another routing protocol\n"
12007 "Open Shortest Path First (OSPFv2)\n"
12008 "Non-main Kernel Routing Table\n"
12009 "Instance ID/Table ID\n"
12010 "Metric for redistributed routes\n"
12011 "Default metric\n"
12012 "Route map reference\n"
12013 "Pointer to route-map entries\n")
12014 {
12015 VTY_DECLVAR_CONTEXT(bgp, bgp);
12016 int idx_ospf_table = 2;
12017 int idx_number = 3;
12018 unsigned short instance;
12019 int protocol;
12020
12021 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
12022 protocol = ZEBRA_ROUTE_OSPF;
12023 else
12024 protocol = ZEBRA_ROUTE_TABLE;
12025
12026 instance = strtoul(argv[idx_number]->arg, NULL, 10);
12027 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
12028 }
12029
12030 ALIAS_HIDDEN(
12031 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
12032 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
12033 NO_STR
12034 "Redistribute information from another routing protocol\n"
12035 "Open Shortest Path First (OSPFv2)\n"
12036 "Non-main Kernel Routing Table\n"
12037 "Instance ID/Table ID\n"
12038 "Metric for redistributed routes\n"
12039 "Default metric\n"
12040 "Route map reference\n"
12041 "Pointer to route-map entries\n")
12042
12043 DEFUN (no_bgp_redistribute_ipv4,
12044 no_bgp_redistribute_ipv4_cmd,
12045 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12046 NO_STR
12047 "Redistribute information from another routing protocol\n"
12048 FRR_IP_REDIST_HELP_STR_BGPD
12049 "Metric for redistributed routes\n"
12050 "Default metric\n"
12051 "Route map reference\n"
12052 "Pointer to route-map entries\n")
12053 {
12054 VTY_DECLVAR_CONTEXT(bgp, bgp);
12055 int idx_protocol = 2;
12056 int type;
12057
12058 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
12059 if (type < 0) {
12060 vty_out(vty, "%% Invalid route type\n");
12061 return CMD_WARNING_CONFIG_FAILED;
12062 }
12063 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
12064 }
12065
12066 ALIAS_HIDDEN(
12067 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
12068 "no redistribute " FRR_IP_REDIST_STR_BGPD
12069 " [metric (0-4294967295)] [route-map WORD]",
12070 NO_STR
12071 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
12072 "Metric for redistributed routes\n"
12073 "Default metric\n"
12074 "Route map reference\n"
12075 "Pointer to route-map entries\n")
12076
12077 DEFUN (bgp_redistribute_ipv6,
12078 bgp_redistribute_ipv6_cmd,
12079 "redistribute " FRR_IP6_REDIST_STR_BGPD,
12080 "Redistribute information from another routing protocol\n"
12081 FRR_IP6_REDIST_HELP_STR_BGPD)
12082 {
12083 VTY_DECLVAR_CONTEXT(bgp, bgp);
12084 int idx_protocol = 1;
12085 int type;
12086
12087 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12088 if (type < 0) {
12089 vty_out(vty, "%% Invalid route type\n");
12090 return CMD_WARNING_CONFIG_FAILED;
12091 }
12092
12093 bgp_redist_add(bgp, AFI_IP6, type, 0);
12094 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, false);
12095 }
12096
12097 DEFUN (bgp_redistribute_ipv6_rmap,
12098 bgp_redistribute_ipv6_rmap_cmd,
12099 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
12100 "Redistribute information from another routing protocol\n"
12101 FRR_IP6_REDIST_HELP_STR_BGPD
12102 "Route map reference\n"
12103 "Pointer to route-map entries\n")
12104 {
12105 VTY_DECLVAR_CONTEXT(bgp, bgp);
12106 int idx_protocol = 1;
12107 int idx_word = 3;
12108 int type;
12109 struct bgp_redist *red;
12110 bool changed;
12111
12112 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12113 if (type < 0) {
12114 vty_out(vty, "%% Invalid route type\n");
12115 return CMD_WARNING_CONFIG_FAILED;
12116 }
12117
12118 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12119 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12120 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12121 }
12122
12123 DEFUN (bgp_redistribute_ipv6_metric,
12124 bgp_redistribute_ipv6_metric_cmd,
12125 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
12126 "Redistribute information from another routing protocol\n"
12127 FRR_IP6_REDIST_HELP_STR_BGPD
12128 "Metric for redistributed routes\n"
12129 "Default metric\n")
12130 {
12131 VTY_DECLVAR_CONTEXT(bgp, bgp);
12132 int idx_protocol = 1;
12133 int idx_number = 3;
12134 int type;
12135 uint32_t metric;
12136 struct bgp_redist *red;
12137 bool changed;
12138
12139 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12140 if (type < 0) {
12141 vty_out(vty, "%% Invalid route type\n");
12142 return CMD_WARNING_CONFIG_FAILED;
12143 }
12144 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12145
12146 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12147 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
12148 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12149 }
12150
12151 DEFUN (bgp_redistribute_ipv6_rmap_metric,
12152 bgp_redistribute_ipv6_rmap_metric_cmd,
12153 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
12154 "Redistribute information from another routing protocol\n"
12155 FRR_IP6_REDIST_HELP_STR_BGPD
12156 "Route map reference\n"
12157 "Pointer to route-map entries\n"
12158 "Metric for redistributed routes\n"
12159 "Default metric\n")
12160 {
12161 VTY_DECLVAR_CONTEXT(bgp, bgp);
12162 int idx_protocol = 1;
12163 int idx_word = 3;
12164 int idx_number = 5;
12165 int type;
12166 uint32_t metric;
12167 struct bgp_redist *red;
12168 bool changed;
12169
12170 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12171 if (type < 0) {
12172 vty_out(vty, "%% Invalid route type\n");
12173 return CMD_WARNING_CONFIG_FAILED;
12174 }
12175 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12176
12177 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12178 changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12179 changed |= bgp_redistribute_metric_set(bgp, red, AFI_IP6, type,
12180 metric);
12181 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12182 }
12183
12184 DEFUN (bgp_redistribute_ipv6_metric_rmap,
12185 bgp_redistribute_ipv6_metric_rmap_cmd,
12186 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
12187 "Redistribute information from another routing protocol\n"
12188 FRR_IP6_REDIST_HELP_STR_BGPD
12189 "Metric for redistributed routes\n"
12190 "Default metric\n"
12191 "Route map reference\n"
12192 "Pointer to route-map entries\n")
12193 {
12194 VTY_DECLVAR_CONTEXT(bgp, bgp);
12195 int idx_protocol = 1;
12196 int idx_number = 3;
12197 int idx_word = 5;
12198 int type;
12199 uint32_t metric;
12200 struct bgp_redist *red;
12201 bool changed;
12202
12203 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12204 if (type < 0) {
12205 vty_out(vty, "%% Invalid route type\n");
12206 return CMD_WARNING_CONFIG_FAILED;
12207 }
12208 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12209
12210 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12211 changed = bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST,
12212 metric);
12213 changed |= bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12214 return bgp_redistribute_set(bgp, AFI_IP6, type, 0, changed);
12215 }
12216
12217 DEFUN (no_bgp_redistribute_ipv6,
12218 no_bgp_redistribute_ipv6_cmd,
12219 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12220 NO_STR
12221 "Redistribute information from another routing protocol\n"
12222 FRR_IP6_REDIST_HELP_STR_BGPD
12223 "Metric for redistributed routes\n"
12224 "Default metric\n"
12225 "Route map reference\n"
12226 "Pointer to route-map entries\n")
12227 {
12228 VTY_DECLVAR_CONTEXT(bgp, bgp);
12229 int idx_protocol = 2;
12230 int type;
12231
12232 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12233 if (type < 0) {
12234 vty_out(vty, "%% Invalid route type\n");
12235 return CMD_WARNING_CONFIG_FAILED;
12236 }
12237
12238 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12239 }
12240
12241 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12242 safi_t safi)
12243 {
12244 int i;
12245
12246 /* Unicast redistribution only. */
12247 if (safi != SAFI_UNICAST)
12248 return;
12249
12250 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12251 /* Redistribute BGP does not make sense. */
12252 if (i != ZEBRA_ROUTE_BGP) {
12253 struct list *red_list;
12254 struct listnode *node;
12255 struct bgp_redist *red;
12256
12257 red_list = bgp->redist[afi][i];
12258 if (!red_list)
12259 continue;
12260
12261 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12262 /* "redistribute" configuration. */
12263 vty_out(vty, " redistribute %s",
12264 zebra_route_string(i));
12265 if (red->instance)
12266 vty_out(vty, " %d", red->instance);
12267 if (red->redist_metric_flag)
12268 vty_out(vty, " metric %u",
12269 red->redist_metric);
12270 if (red->rmap.name)
12271 vty_out(vty, " route-map %s",
12272 red->rmap.name);
12273 vty_out(vty, "\n");
12274 }
12275 }
12276 }
12277 }
12278
12279 /* This is part of the address-family block (unicast only) */
12280 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12281 afi_t afi)
12282 {
12283 int indent = 2;
12284
12285 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12286 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12287 bgp->vpn_policy[afi]
12288 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12289
12290 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12291 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12292 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12293 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12294 return;
12295
12296 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12297 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12298
12299 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12300
12301 } else {
12302 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12303 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12304 bgp->vpn_policy[afi].tovpn_label);
12305 }
12306 }
12307 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12308 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12309 char buf[RD_ADDRSTRLEN];
12310 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12311 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12312 sizeof(buf)));
12313 }
12314 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12315 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12316
12317 char buf[PREFIX_STRLEN];
12318 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12319 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12320 sizeof(buf))) {
12321
12322 vty_out(vty, "%*snexthop vpn export %s\n",
12323 indent, "", buf);
12324 }
12325 }
12326 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12327 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12328 && ecommunity_cmp(
12329 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12330 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12331
12332 char *b = ecommunity_ecom2str(
12333 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12334 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12335 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12336 XFREE(MTYPE_ECOMMUNITY_STR, b);
12337 } else {
12338 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12339 char *b = ecommunity_ecom2str(
12340 bgp->vpn_policy[afi]
12341 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12342 ECOMMUNITY_FORMAT_ROUTE_MAP,
12343 ECOMMUNITY_ROUTE_TARGET);
12344 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12345 XFREE(MTYPE_ECOMMUNITY_STR, b);
12346 }
12347 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12348 char *b = ecommunity_ecom2str(
12349 bgp->vpn_policy[afi]
12350 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12351 ECOMMUNITY_FORMAT_ROUTE_MAP,
12352 ECOMMUNITY_ROUTE_TARGET);
12353 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12354 XFREE(MTYPE_ECOMMUNITY_STR, b);
12355 }
12356 }
12357
12358 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12359 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12360 bgp->vpn_policy[afi]
12361 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12362
12363 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12364 char *b = ecommunity_ecom2str(
12365 bgp->vpn_policy[afi]
12366 .import_redirect_rtlist,
12367 ECOMMUNITY_FORMAT_ROUTE_MAP,
12368 ECOMMUNITY_ROUTE_TARGET);
12369
12370 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12371 XFREE(MTYPE_ECOMMUNITY_STR, b);
12372 }
12373 }
12374
12375
12376 /* BGP node structure. */
12377 static struct cmd_node bgp_node = {
12378 BGP_NODE, "%s(config-router)# ", 1,
12379 };
12380
12381 static struct cmd_node bgp_ipv4_unicast_node = {
12382 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12383 };
12384
12385 static struct cmd_node bgp_ipv4_multicast_node = {
12386 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12387 };
12388
12389 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12390 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12391 };
12392
12393 static struct cmd_node bgp_ipv6_unicast_node = {
12394 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12395 };
12396
12397 static struct cmd_node bgp_ipv6_multicast_node = {
12398 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12399 };
12400
12401 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12402 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12403 };
12404
12405 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12406 "%s(config-router-af)# ", 1};
12407
12408 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12409 "%s(config-router-af-vpnv6)# ", 1};
12410
12411 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12412 "%s(config-router-evpn)# ", 1};
12413
12414 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12415 "%s(config-router-af-vni)# ", 1};
12416
12417 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12418 "%s(config-router-af)# ", 1};
12419
12420 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12421 "%s(config-router-af-vpnv6)# ", 1};
12422
12423 static void community_list_vty(void);
12424
12425 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12426 {
12427 struct bgp *bgp;
12428 struct peer *peer;
12429 struct listnode *lnbgp, *lnpeer;
12430
12431 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12432 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12433 /* only provide suggestions on the appropriate input
12434 * token type,
12435 * they'll otherwise show up multiple times */
12436 enum cmd_token_type match_type;
12437 char *name = peer->host;
12438
12439 if (peer->conf_if) {
12440 match_type = VARIABLE_TKN;
12441 name = peer->conf_if;
12442 } else if (strchr(peer->host, ':'))
12443 match_type = IPV6_TKN;
12444 else
12445 match_type = IPV4_TKN;
12446
12447 if (token->type != match_type)
12448 continue;
12449
12450 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12451 }
12452 }
12453 }
12454
12455 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12456 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12457 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12458 {.varname = "peer", .completions = bgp_ac_neighbor},
12459 {.completions = NULL}};
12460
12461 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12462 {
12463 struct bgp *bgp;
12464 struct peer_group *group;
12465 struct listnode *lnbgp, *lnpeer;
12466
12467 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12468 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12469 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12470 group->name));
12471 }
12472 }
12473
12474 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12475 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12476 {.completions = NULL} };
12477
12478 void bgp_vty_init(void)
12479 {
12480 cmd_variable_handler_register(bgp_var_neighbor);
12481 cmd_variable_handler_register(bgp_var_peergroup);
12482
12483 /* Install bgp top node. */
12484 install_node(&bgp_node, bgp_config_write);
12485 install_node(&bgp_ipv4_unicast_node, NULL);
12486 install_node(&bgp_ipv4_multicast_node, NULL);
12487 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12488 install_node(&bgp_ipv6_unicast_node, NULL);
12489 install_node(&bgp_ipv6_multicast_node, NULL);
12490 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12491 install_node(&bgp_vpnv4_node, NULL);
12492 install_node(&bgp_vpnv6_node, NULL);
12493 install_node(&bgp_evpn_node, NULL);
12494 install_node(&bgp_evpn_vni_node, NULL);
12495 install_node(&bgp_flowspecv4_node, NULL);
12496 install_node(&bgp_flowspecv6_node, NULL);
12497
12498 /* Install default VTY commands to new nodes. */
12499 install_default(BGP_NODE);
12500 install_default(BGP_IPV4_NODE);
12501 install_default(BGP_IPV4M_NODE);
12502 install_default(BGP_IPV4L_NODE);
12503 install_default(BGP_IPV6_NODE);
12504 install_default(BGP_IPV6M_NODE);
12505 install_default(BGP_IPV6L_NODE);
12506 install_default(BGP_VPNV4_NODE);
12507 install_default(BGP_VPNV6_NODE);
12508 install_default(BGP_FLOWSPECV4_NODE);
12509 install_default(BGP_FLOWSPECV6_NODE);
12510 install_default(BGP_EVPN_NODE);
12511 install_default(BGP_EVPN_VNI_NODE);
12512
12513 /* "bgp multiple-instance" commands. */
12514 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12515 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12516
12517 /* "bgp config-type" commands. */
12518 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12519 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12520
12521 /* bgp route-map delay-timer commands. */
12522 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12523 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12524
12525 /* Dummy commands (Currently not supported) */
12526 install_element(BGP_NODE, &no_synchronization_cmd);
12527 install_element(BGP_NODE, &no_auto_summary_cmd);
12528
12529 /* "router bgp" commands. */
12530 install_element(CONFIG_NODE, &router_bgp_cmd);
12531
12532 /* "no router bgp" commands. */
12533 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12534
12535 /* "bgp router-id" commands. */
12536 install_element(BGP_NODE, &bgp_router_id_cmd);
12537 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12538
12539 /* "bgp cluster-id" commands. */
12540 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12541 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12542
12543 /* "bgp confederation" commands. */
12544 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12545 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12546
12547 /* "bgp confederation peers" commands. */
12548 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12549 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12550
12551 /* bgp max-med command */
12552 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12553 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12554 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12555 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12556 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12557
12558 /* bgp disable-ebgp-connected-nh-check */
12559 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12560 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12561
12562 /* bgp update-delay command */
12563 install_element(BGP_NODE, &bgp_update_delay_cmd);
12564 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12565 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12566
12567 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12568 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12569 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12570 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12571
12572 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12573 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12574
12575 /* "maximum-paths" commands. */
12576 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12577 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12578 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12579 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12580 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12581 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12582 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12583 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12584 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12585 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12586 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12587 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12588 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12589 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12590 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12591
12592 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12593 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12594 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12595 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12596 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12597
12598 /* "timers bgp" commands. */
12599 install_element(BGP_NODE, &bgp_timers_cmd);
12600 install_element(BGP_NODE, &no_bgp_timers_cmd);
12601
12602 /* route-map delay-timer commands - per instance for backwards compat.
12603 */
12604 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12605 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12606
12607 /* "bgp client-to-client reflection" commands */
12608 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12609 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12610
12611 /* "bgp always-compare-med" commands */
12612 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12613 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12614
12615 /* "bgp deterministic-med" commands */
12616 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12617 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12618
12619 /* "bgp graceful-restart" commands */
12620 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12621 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12622 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12623 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12624 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12625 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12626
12627 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12628 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12629
12630 /* "bgp graceful-shutdown" commands */
12631 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12632 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12633
12634 /* "bgp fast-external-failover" commands */
12635 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12636 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12637
12638 /* "bgp enforce-first-as" commands */
12639 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12640
12641 /* "bgp bestpath compare-routerid" commands */
12642 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12643 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12644
12645 /* "bgp bestpath as-path ignore" commands */
12646 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12647 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12648
12649 /* "bgp bestpath as-path confed" commands */
12650 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12651 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12652
12653 /* "bgp bestpath as-path multipath-relax" commands */
12654 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12655 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12656
12657 /* "bgp log-neighbor-changes" commands */
12658 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12659 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12660
12661 /* "bgp bestpath med" commands */
12662 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12663 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12664
12665 /* "no bgp default ipv4-unicast" commands. */
12666 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12667 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12668
12669 /* "bgp network import-check" commands. */
12670 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12671 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12672 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12673
12674 /* "bgp default local-preference" commands. */
12675 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12676 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12677
12678 /* bgp default show-hostname */
12679 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12680 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12681
12682 /* "bgp default subgroup-pkt-queue-max" commands. */
12683 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12684 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12685
12686 /* bgp ibgp-allow-policy-mods command */
12687 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12688 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12689
12690 /* "bgp listen limit" commands. */
12691 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12692 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12693
12694 /* "bgp listen range" commands. */
12695 install_element(BGP_NODE, &bgp_listen_range_cmd);
12696 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12697
12698 /* "bgp default shutdown" command */
12699 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12700
12701 /* "neighbor remote-as" commands. */
12702 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12703 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12704 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12705 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12706 install_element(BGP_NODE,
12707 &neighbor_interface_v6only_config_remote_as_cmd);
12708 install_element(BGP_NODE, &no_neighbor_cmd);
12709 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12710
12711 /* "neighbor peer-group" commands. */
12712 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12713 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12714 install_element(BGP_NODE,
12715 &no_neighbor_interface_peer_group_remote_as_cmd);
12716
12717 /* "neighbor local-as" commands. */
12718 install_element(BGP_NODE, &neighbor_local_as_cmd);
12719 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12720 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12721 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12722
12723 /* "neighbor solo" commands. */
12724 install_element(BGP_NODE, &neighbor_solo_cmd);
12725 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12726
12727 /* "neighbor password" commands. */
12728 install_element(BGP_NODE, &neighbor_password_cmd);
12729 install_element(BGP_NODE, &no_neighbor_password_cmd);
12730
12731 /* "neighbor activate" commands. */
12732 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12733 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12734 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12735 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12736 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12737 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12738 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12739 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12740 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12741 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12742 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12743 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12744
12745 /* "no neighbor activate" commands. */
12746 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12747 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12748 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12749 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12750 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12751 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12752 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12753 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12754 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12755 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12756 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12757 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12758
12759 /* "neighbor peer-group" set commands. */
12760 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12761 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12762 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12763 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12764 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12765 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12766 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12767 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12768 install_element(BGP_FLOWSPECV4_NODE,
12769 &neighbor_set_peer_group_hidden_cmd);
12770 install_element(BGP_FLOWSPECV6_NODE,
12771 &neighbor_set_peer_group_hidden_cmd);
12772
12773 /* "no neighbor peer-group unset" commands. */
12774 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12775 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12776 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12777 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12778 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12779 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12780 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12781 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12782 install_element(BGP_FLOWSPECV4_NODE,
12783 &no_neighbor_set_peer_group_hidden_cmd);
12784 install_element(BGP_FLOWSPECV6_NODE,
12785 &no_neighbor_set_peer_group_hidden_cmd);
12786
12787 /* "neighbor softreconfiguration inbound" commands.*/
12788 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12789 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12790 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12791 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12792 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12793 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12794 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12795 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12796 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12797 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12798 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12799 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12800 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12801 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12802 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12803 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12804 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12805 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12806 install_element(BGP_FLOWSPECV4_NODE,
12807 &neighbor_soft_reconfiguration_cmd);
12808 install_element(BGP_FLOWSPECV4_NODE,
12809 &no_neighbor_soft_reconfiguration_cmd);
12810 install_element(BGP_FLOWSPECV6_NODE,
12811 &neighbor_soft_reconfiguration_cmd);
12812 install_element(BGP_FLOWSPECV6_NODE,
12813 &no_neighbor_soft_reconfiguration_cmd);
12814
12815 /* "neighbor attribute-unchanged" commands. */
12816 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12817 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12818 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12819 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12820 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12821 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12822 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12823 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12824 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12825 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12826 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12827 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12828 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12829 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12830 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12831 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12832 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12833 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12834
12835 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12836 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12837
12838 /* "nexthop-local unchanged" commands */
12839 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12840 install_element(BGP_IPV6_NODE,
12841 &no_neighbor_nexthop_local_unchanged_cmd);
12842
12843 /* "neighbor next-hop-self" commands. */
12844 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12845 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12846 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12847 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12848 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12849 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12850 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12851 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12852 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12853 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12854 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12855 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12856 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12857 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12858 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12859 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12860 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12861 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12862 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12863 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12864
12865 /* "neighbor next-hop-self force" commands. */
12866 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12867 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12868 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12869 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12870 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12871 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12872 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12873 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12874 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12875 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12876 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12877 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12878 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12879 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12880 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12881 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12882 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12883 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12884
12885 /* "neighbor as-override" commands. */
12886 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12887 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12888 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12889 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12890 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12891 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12892 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12893 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12894 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12895 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12896 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12897 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12898 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12899 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12900 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12901 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12902 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12903 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12904
12905 /* "neighbor remove-private-AS" commands. */
12906 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12907 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12908 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12909 install_element(BGP_NODE,
12910 &no_neighbor_remove_private_as_all_hidden_cmd);
12911 install_element(BGP_NODE,
12912 &neighbor_remove_private_as_replace_as_hidden_cmd);
12913 install_element(BGP_NODE,
12914 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12915 install_element(BGP_NODE,
12916 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12917 install_element(
12918 BGP_NODE,
12919 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12920 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12921 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12922 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12923 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12924 install_element(BGP_IPV4_NODE,
12925 &neighbor_remove_private_as_replace_as_cmd);
12926 install_element(BGP_IPV4_NODE,
12927 &no_neighbor_remove_private_as_replace_as_cmd);
12928 install_element(BGP_IPV4_NODE,
12929 &neighbor_remove_private_as_all_replace_as_cmd);
12930 install_element(BGP_IPV4_NODE,
12931 &no_neighbor_remove_private_as_all_replace_as_cmd);
12932 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12933 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12934 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12935 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12936 install_element(BGP_IPV4M_NODE,
12937 &neighbor_remove_private_as_replace_as_cmd);
12938 install_element(BGP_IPV4M_NODE,
12939 &no_neighbor_remove_private_as_replace_as_cmd);
12940 install_element(BGP_IPV4M_NODE,
12941 &neighbor_remove_private_as_all_replace_as_cmd);
12942 install_element(BGP_IPV4M_NODE,
12943 &no_neighbor_remove_private_as_all_replace_as_cmd);
12944 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12945 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12946 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12947 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12948 install_element(BGP_IPV4L_NODE,
12949 &neighbor_remove_private_as_replace_as_cmd);
12950 install_element(BGP_IPV4L_NODE,
12951 &no_neighbor_remove_private_as_replace_as_cmd);
12952 install_element(BGP_IPV4L_NODE,
12953 &neighbor_remove_private_as_all_replace_as_cmd);
12954 install_element(BGP_IPV4L_NODE,
12955 &no_neighbor_remove_private_as_all_replace_as_cmd);
12956 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12957 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12958 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12959 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12960 install_element(BGP_IPV6_NODE,
12961 &neighbor_remove_private_as_replace_as_cmd);
12962 install_element(BGP_IPV6_NODE,
12963 &no_neighbor_remove_private_as_replace_as_cmd);
12964 install_element(BGP_IPV6_NODE,
12965 &neighbor_remove_private_as_all_replace_as_cmd);
12966 install_element(BGP_IPV6_NODE,
12967 &no_neighbor_remove_private_as_all_replace_as_cmd);
12968 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12969 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12970 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12971 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12972 install_element(BGP_IPV6M_NODE,
12973 &neighbor_remove_private_as_replace_as_cmd);
12974 install_element(BGP_IPV6M_NODE,
12975 &no_neighbor_remove_private_as_replace_as_cmd);
12976 install_element(BGP_IPV6M_NODE,
12977 &neighbor_remove_private_as_all_replace_as_cmd);
12978 install_element(BGP_IPV6M_NODE,
12979 &no_neighbor_remove_private_as_all_replace_as_cmd);
12980 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12981 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12982 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12983 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12984 install_element(BGP_IPV6L_NODE,
12985 &neighbor_remove_private_as_replace_as_cmd);
12986 install_element(BGP_IPV6L_NODE,
12987 &no_neighbor_remove_private_as_replace_as_cmd);
12988 install_element(BGP_IPV6L_NODE,
12989 &neighbor_remove_private_as_all_replace_as_cmd);
12990 install_element(BGP_IPV6L_NODE,
12991 &no_neighbor_remove_private_as_all_replace_as_cmd);
12992 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12993 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12994 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12995 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12996 install_element(BGP_VPNV4_NODE,
12997 &neighbor_remove_private_as_replace_as_cmd);
12998 install_element(BGP_VPNV4_NODE,
12999 &no_neighbor_remove_private_as_replace_as_cmd);
13000 install_element(BGP_VPNV4_NODE,
13001 &neighbor_remove_private_as_all_replace_as_cmd);
13002 install_element(BGP_VPNV4_NODE,
13003 &no_neighbor_remove_private_as_all_replace_as_cmd);
13004 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
13005 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
13006 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
13007 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
13008 install_element(BGP_VPNV6_NODE,
13009 &neighbor_remove_private_as_replace_as_cmd);
13010 install_element(BGP_VPNV6_NODE,
13011 &no_neighbor_remove_private_as_replace_as_cmd);
13012 install_element(BGP_VPNV6_NODE,
13013 &neighbor_remove_private_as_all_replace_as_cmd);
13014 install_element(BGP_VPNV6_NODE,
13015 &no_neighbor_remove_private_as_all_replace_as_cmd);
13016
13017 /* "neighbor send-community" commands.*/
13018 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
13019 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
13020 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
13021 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
13022 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
13023 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
13024 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
13025 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
13026 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
13027 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
13028 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
13029 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
13030 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
13031 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
13032 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
13033 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
13034 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
13035 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
13036 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
13037 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
13038 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
13039 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
13040 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
13041 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
13042 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
13043 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
13044 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
13045 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
13046 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
13047 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
13048 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
13049 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
13050 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
13051 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
13052 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
13053 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
13054
13055 /* "neighbor route-reflector" commands.*/
13056 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
13057 install_element(BGP_NODE,
13058 &no_neighbor_route_reflector_client_hidden_cmd);
13059 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
13060 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
13061 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
13062 install_element(BGP_IPV4M_NODE,
13063 &no_neighbor_route_reflector_client_cmd);
13064 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
13065 install_element(BGP_IPV4L_NODE,
13066 &no_neighbor_route_reflector_client_cmd);
13067 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
13068 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
13069 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
13070 install_element(BGP_IPV6M_NODE,
13071 &no_neighbor_route_reflector_client_cmd);
13072 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
13073 install_element(BGP_IPV6L_NODE,
13074 &no_neighbor_route_reflector_client_cmd);
13075 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
13076 install_element(BGP_VPNV4_NODE,
13077 &no_neighbor_route_reflector_client_cmd);
13078 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
13079 install_element(BGP_VPNV6_NODE,
13080 &no_neighbor_route_reflector_client_cmd);
13081 install_element(BGP_FLOWSPECV4_NODE,
13082 &neighbor_route_reflector_client_cmd);
13083 install_element(BGP_FLOWSPECV4_NODE,
13084 &no_neighbor_route_reflector_client_cmd);
13085 install_element(BGP_FLOWSPECV6_NODE,
13086 &neighbor_route_reflector_client_cmd);
13087 install_element(BGP_FLOWSPECV6_NODE,
13088 &no_neighbor_route_reflector_client_cmd);
13089 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
13090 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
13091
13092 /* "neighbor route-server" commands.*/
13093 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
13094 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
13095 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
13096 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
13097 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
13098 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
13099 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
13100 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
13101 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
13102 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
13103 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
13104 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
13105 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
13106 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
13107 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
13108 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
13109 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
13110 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
13111 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
13112 install_element(BGP_FLOWSPECV4_NODE,
13113 &no_neighbor_route_server_client_cmd);
13114 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
13115 install_element(BGP_FLOWSPECV6_NODE,
13116 &no_neighbor_route_server_client_cmd);
13117
13118 /* "neighbor addpath-tx-all-paths" commands.*/
13119 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
13120 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
13121 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13122 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13123 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13124 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13125 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13126 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13127 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13128 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13129 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
13130 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13131 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
13132 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13133 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
13134 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13135 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
13136 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
13137
13138 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
13139 install_element(BGP_NODE,
13140 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13141 install_element(BGP_NODE,
13142 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
13143 install_element(BGP_IPV4_NODE,
13144 &neighbor_addpath_tx_bestpath_per_as_cmd);
13145 install_element(BGP_IPV4_NODE,
13146 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13147 install_element(BGP_IPV4M_NODE,
13148 &neighbor_addpath_tx_bestpath_per_as_cmd);
13149 install_element(BGP_IPV4M_NODE,
13150 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13151 install_element(BGP_IPV4L_NODE,
13152 &neighbor_addpath_tx_bestpath_per_as_cmd);
13153 install_element(BGP_IPV4L_NODE,
13154 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13155 install_element(BGP_IPV6_NODE,
13156 &neighbor_addpath_tx_bestpath_per_as_cmd);
13157 install_element(BGP_IPV6_NODE,
13158 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13159 install_element(BGP_IPV6M_NODE,
13160 &neighbor_addpath_tx_bestpath_per_as_cmd);
13161 install_element(BGP_IPV6M_NODE,
13162 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13163 install_element(BGP_IPV6L_NODE,
13164 &neighbor_addpath_tx_bestpath_per_as_cmd);
13165 install_element(BGP_IPV6L_NODE,
13166 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13167 install_element(BGP_VPNV4_NODE,
13168 &neighbor_addpath_tx_bestpath_per_as_cmd);
13169 install_element(BGP_VPNV4_NODE,
13170 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13171 install_element(BGP_VPNV6_NODE,
13172 &neighbor_addpath_tx_bestpath_per_as_cmd);
13173 install_element(BGP_VPNV6_NODE,
13174 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
13175
13176 /* "neighbor passive" commands. */
13177 install_element(BGP_NODE, &neighbor_passive_cmd);
13178 install_element(BGP_NODE, &no_neighbor_passive_cmd);
13179
13180
13181 /* "neighbor shutdown" commands. */
13182 install_element(BGP_NODE, &neighbor_shutdown_cmd);
13183 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
13184 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
13185 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
13186
13187 /* "neighbor capability extended-nexthop" commands.*/
13188 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
13189 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
13190
13191 /* "neighbor capability orf prefix-list" commands.*/
13192 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
13193 install_element(BGP_NODE,
13194 &no_neighbor_capability_orf_prefix_hidden_cmd);
13195 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
13196 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
13197 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
13198 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13199 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
13200 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13201 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
13202 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
13203 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
13204 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
13205 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13206 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13207
13208 /* "neighbor capability dynamic" commands.*/
13209 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13210 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13211
13212 /* "neighbor dont-capability-negotiate" commands. */
13213 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13214 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13215
13216 /* "neighbor ebgp-multihop" commands. */
13217 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13218 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13219 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13220
13221 /* "neighbor disable-connected-check" commands. */
13222 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13223 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13224
13225 /* "neighbor enforce-first-as" commands. */
13226 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13227 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13228
13229 /* "neighbor description" commands. */
13230 install_element(BGP_NODE, &neighbor_description_cmd);
13231 install_element(BGP_NODE, &no_neighbor_description_cmd);
13232 install_element(BGP_NODE, &no_neighbor_description_comment_cmd);
13233
13234 /* "neighbor update-source" commands. "*/
13235 install_element(BGP_NODE, &neighbor_update_source_cmd);
13236 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13237
13238 /* "neighbor default-originate" commands. */
13239 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13240 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13241 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13242 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13243 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13244 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13245 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13246 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13247 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13248 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13249 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13250 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13251 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13252 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13253 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13254 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13255 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13256 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13257 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13258 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13259 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13260
13261 /* "neighbor port" commands. */
13262 install_element(BGP_NODE, &neighbor_port_cmd);
13263 install_element(BGP_NODE, &no_neighbor_port_cmd);
13264
13265 /* "neighbor weight" commands. */
13266 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13267 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13268
13269 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13270 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13271 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13272 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13273 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13274 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13275 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13276 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13277 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13278 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13279 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13280 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13281 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13282 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13283 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13284 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13285
13286 /* "neighbor override-capability" commands. */
13287 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13288 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13289
13290 /* "neighbor strict-capability-match" commands. */
13291 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13292 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13293
13294 /* "neighbor timers" commands. */
13295 install_element(BGP_NODE, &neighbor_timers_cmd);
13296 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13297
13298 /* "neighbor timers connect" commands. */
13299 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13300 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13301
13302 /* "neighbor advertisement-interval" commands. */
13303 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13304 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13305
13306 /* "neighbor interface" commands. */
13307 install_element(BGP_NODE, &neighbor_interface_cmd);
13308 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13309
13310 /* "neighbor distribute" commands. */
13311 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13312 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13313 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13314 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13315 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13316 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13317 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13318 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13319 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13320 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13321 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13322 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13323 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13324 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13325 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13326 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13327 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13328 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13329
13330 /* "neighbor prefix-list" commands. */
13331 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13332 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13333 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13334 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13335 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13336 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13337 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13338 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13339 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13340 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13341 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13342 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13343 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13344 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13345 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13346 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13347 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13348 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13349 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13350 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13351 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13352 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13353
13354 /* "neighbor filter-list" commands. */
13355 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13356 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13357 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13358 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13359 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13360 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13361 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13362 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13363 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13364 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13365 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13366 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13367 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13368 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13369 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13370 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13371 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13372 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13373 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13374 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13375 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13376 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13377
13378 /* "neighbor route-map" commands. */
13379 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13380 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13381 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13382 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13383 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13384 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13385 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13386 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13387 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13388 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13389 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13390 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13391 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13392 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13393 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13394 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13395 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13396 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13397 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13398 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13399 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13400 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13401 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13402 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13403
13404 /* "neighbor unsuppress-map" commands. */
13405 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13406 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13407 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13408 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13409 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13410 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13411 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13412 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13413 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13414 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13415 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13416 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13417 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13418 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13419 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13420 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13421 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13422 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13423
13424 /* "neighbor maximum-prefix" commands. */
13425 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13426 install_element(BGP_NODE,
13427 &neighbor_maximum_prefix_threshold_hidden_cmd);
13428 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13429 install_element(BGP_NODE,
13430 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13431 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13432 install_element(BGP_NODE,
13433 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13434 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13435 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13436 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13437 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13438 install_element(BGP_IPV4_NODE,
13439 &neighbor_maximum_prefix_threshold_warning_cmd);
13440 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13441 install_element(BGP_IPV4_NODE,
13442 &neighbor_maximum_prefix_threshold_restart_cmd);
13443 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13444 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13445 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13446 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13447 install_element(BGP_IPV4M_NODE,
13448 &neighbor_maximum_prefix_threshold_warning_cmd);
13449 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13450 install_element(BGP_IPV4M_NODE,
13451 &neighbor_maximum_prefix_threshold_restart_cmd);
13452 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13453 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13454 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13455 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13456 install_element(BGP_IPV4L_NODE,
13457 &neighbor_maximum_prefix_threshold_warning_cmd);
13458 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13459 install_element(BGP_IPV4L_NODE,
13460 &neighbor_maximum_prefix_threshold_restart_cmd);
13461 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13462 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13463 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13464 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13465 install_element(BGP_IPV6_NODE,
13466 &neighbor_maximum_prefix_threshold_warning_cmd);
13467 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13468 install_element(BGP_IPV6_NODE,
13469 &neighbor_maximum_prefix_threshold_restart_cmd);
13470 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13471 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13472 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13473 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13474 install_element(BGP_IPV6M_NODE,
13475 &neighbor_maximum_prefix_threshold_warning_cmd);
13476 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13477 install_element(BGP_IPV6M_NODE,
13478 &neighbor_maximum_prefix_threshold_restart_cmd);
13479 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13480 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13481 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13482 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13483 install_element(BGP_IPV6L_NODE,
13484 &neighbor_maximum_prefix_threshold_warning_cmd);
13485 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13486 install_element(BGP_IPV6L_NODE,
13487 &neighbor_maximum_prefix_threshold_restart_cmd);
13488 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13489 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13490 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13491 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13492 install_element(BGP_VPNV4_NODE,
13493 &neighbor_maximum_prefix_threshold_warning_cmd);
13494 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13495 install_element(BGP_VPNV4_NODE,
13496 &neighbor_maximum_prefix_threshold_restart_cmd);
13497 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13498 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13499 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13500 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13501 install_element(BGP_VPNV6_NODE,
13502 &neighbor_maximum_prefix_threshold_warning_cmd);
13503 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13504 install_element(BGP_VPNV6_NODE,
13505 &neighbor_maximum_prefix_threshold_restart_cmd);
13506 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13507
13508 /* "neighbor allowas-in" */
13509 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13510 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13511 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13512 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13513 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13514 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13515 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13516 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13517 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13518 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13519 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13520 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13521 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13522 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13523 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13524 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13525 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13526 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13527 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13528 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13529
13530 /* address-family commands. */
13531 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13532 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13533 #ifdef KEEP_OLD_VPN_COMMANDS
13534 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13535 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13536 #endif /* KEEP_OLD_VPN_COMMANDS */
13537
13538 install_element(BGP_NODE, &address_family_evpn_cmd);
13539
13540 /* "exit-address-family" command. */
13541 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13542 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13543 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13544 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13545 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13546 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13547 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13548 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13549 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13550 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13551 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13552
13553 /* "clear ip bgp commands" */
13554 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13555
13556 /* clear ip bgp prefix */
13557 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13558 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13559 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13560
13561 /* "show [ip] bgp summary" commands. */
13562 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13563 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13564 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13565 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13566 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13567 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13568
13569 /* "show [ip] bgp neighbors" commands. */
13570 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13571
13572 /* "show [ip] bgp peer-group" commands. */
13573 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13574
13575 /* "show [ip] bgp paths" commands. */
13576 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13577
13578 /* "show [ip] bgp community" commands. */
13579 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13580
13581 /* "show ip bgp large-community" commands. */
13582 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13583 /* "show [ip] bgp attribute-info" commands. */
13584 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13585 /* "show [ip] bgp route-leak" command */
13586 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13587
13588 /* "redistribute" commands. */
13589 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13590 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13591 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13592 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13593 install_element(BGP_NODE,
13594 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13595 install_element(BGP_NODE,
13596 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13597 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13598 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13599 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13600 install_element(BGP_NODE,
13601 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13602 install_element(BGP_NODE,
13603 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13604 install_element(BGP_NODE,
13605 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13606 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13607 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13608 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13609 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13610 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13611 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13612 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13613 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13614 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13615 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13616 install_element(BGP_IPV4_NODE,
13617 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13618 install_element(BGP_IPV4_NODE,
13619 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13620 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13621 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13622 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13623 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13624 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13625 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13626
13627 /* import|export vpn [route-map WORD] */
13628 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13629 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13630
13631 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13632 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13633
13634 /* ttl_security commands */
13635 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13636 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13637
13638 /* "show [ip] bgp memory" commands. */
13639 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13640
13641 /* "show bgp martian next-hop" */
13642 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13643
13644 /* "show [ip] bgp views" commands. */
13645 install_element(VIEW_NODE, &show_bgp_views_cmd);
13646
13647 /* "show [ip] bgp vrfs" commands. */
13648 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13649
13650 /* Community-list. */
13651 community_list_vty();
13652
13653 /* vpn-policy commands */
13654 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13655 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13656 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13657 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13658 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13659 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13660 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13661 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13662 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13663 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13664 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13665 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13666
13667 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13668 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13669
13670 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13671 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13672 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13673 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13674 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13675 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13676 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13677 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13678 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13679 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13680 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13681 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13682 }
13683
13684 #include "memory.h"
13685 #include "bgp_regex.h"
13686 #include "bgp_clist.h"
13687 #include "bgp_ecommunity.h"
13688
13689 /* VTY functions. */
13690
13691 /* Direction value to string conversion. */
13692 static const char *community_direct_str(int direct)
13693 {
13694 switch (direct) {
13695 case COMMUNITY_DENY:
13696 return "deny";
13697 case COMMUNITY_PERMIT:
13698 return "permit";
13699 default:
13700 return "unknown";
13701 }
13702 }
13703
13704 /* Display error string. */
13705 static void community_list_perror(struct vty *vty, int ret)
13706 {
13707 switch (ret) {
13708 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13709 vty_out(vty, "%% Can't find community-list\n");
13710 break;
13711 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13712 vty_out(vty, "%% Malformed community-list value\n");
13713 break;
13714 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13715 vty_out(vty,
13716 "%% Community name conflict, previously defined as standard community\n");
13717 break;
13718 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13719 vty_out(vty,
13720 "%% Community name conflict, previously defined as expanded community\n");
13721 break;
13722 }
13723 }
13724
13725 /* "community-list" keyword help string. */
13726 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13727
13728 /* ip community-list standard */
13729 DEFUN (ip_community_list_standard,
13730 ip_community_list_standard_cmd,
13731 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13732 IP_STR
13733 COMMUNITY_LIST_STR
13734 "Community list number (standard)\n"
13735 "Add an standard community-list entry\n"
13736 "Community list name\n"
13737 "Specify community to reject\n"
13738 "Specify community to accept\n"
13739 COMMUNITY_VAL_STR)
13740 {
13741 char *cl_name_or_number = NULL;
13742 int direct = 0;
13743 int style = COMMUNITY_LIST_STANDARD;
13744
13745 int idx = 0;
13746 argv_find(argv, argc, "(1-99)", &idx);
13747 argv_find(argv, argc, "WORD", &idx);
13748 cl_name_or_number = argv[idx]->arg;
13749 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13750 : COMMUNITY_DENY;
13751 argv_find(argv, argc, "AA:NN", &idx);
13752 char *str = argv_concat(argv, argc, idx);
13753
13754 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13755 style);
13756
13757 XFREE(MTYPE_TMP, str);
13758
13759 if (ret < 0) {
13760 /* Display error string. */
13761 community_list_perror(vty, ret);
13762 return CMD_WARNING_CONFIG_FAILED;
13763 }
13764
13765 return CMD_SUCCESS;
13766 }
13767
13768 DEFUN (no_ip_community_list_standard_all,
13769 no_ip_community_list_standard_all_cmd,
13770 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13771 NO_STR
13772 IP_STR
13773 COMMUNITY_LIST_STR
13774 "Community list number (standard)\n"
13775 "Add an standard community-list entry\n"
13776 "Community list name\n"
13777 "Specify community to reject\n"
13778 "Specify community to accept\n"
13779 COMMUNITY_VAL_STR)
13780 {
13781 char *cl_name_or_number = NULL;
13782 int direct = 0;
13783 int style = COMMUNITY_LIST_STANDARD;
13784
13785 int idx = 0;
13786 argv_find(argv, argc, "(1-99)", &idx);
13787 argv_find(argv, argc, "WORD", &idx);
13788 cl_name_or_number = argv[idx]->arg;
13789 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13790 : COMMUNITY_DENY;
13791 argv_find(argv, argc, "AA:NN", &idx);
13792 char *str = argv_concat(argv, argc, idx);
13793
13794 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13795 direct, style);
13796
13797 XFREE(MTYPE_TMP, str);
13798
13799 if (ret < 0) {
13800 community_list_perror(vty, ret);
13801 return CMD_WARNING_CONFIG_FAILED;
13802 }
13803
13804 return CMD_SUCCESS;
13805 }
13806
13807 /* ip community-list expanded */
13808 DEFUN (ip_community_list_expanded_all,
13809 ip_community_list_expanded_all_cmd,
13810 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13811 IP_STR
13812 COMMUNITY_LIST_STR
13813 "Community list number (expanded)\n"
13814 "Add an expanded community-list entry\n"
13815 "Community list name\n"
13816 "Specify community to reject\n"
13817 "Specify community to accept\n"
13818 COMMUNITY_VAL_STR)
13819 {
13820 char *cl_name_or_number = NULL;
13821 int direct = 0;
13822 int style = COMMUNITY_LIST_EXPANDED;
13823
13824 int idx = 0;
13825 argv_find(argv, argc, "(100-500)", &idx);
13826 argv_find(argv, argc, "WORD", &idx);
13827 cl_name_or_number = argv[idx]->arg;
13828 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13829 : COMMUNITY_DENY;
13830 argv_find(argv, argc, "AA:NN", &idx);
13831 char *str = argv_concat(argv, argc, idx);
13832
13833 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13834 style);
13835
13836 XFREE(MTYPE_TMP, str);
13837
13838 if (ret < 0) {
13839 /* Display error string. */
13840 community_list_perror(vty, ret);
13841 return CMD_WARNING_CONFIG_FAILED;
13842 }
13843
13844 return CMD_SUCCESS;
13845 }
13846
13847 DEFUN (no_ip_community_list_expanded_all,
13848 no_ip_community_list_expanded_all_cmd,
13849 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13850 NO_STR
13851 IP_STR
13852 COMMUNITY_LIST_STR
13853 "Community list number (expanded)\n"
13854 "Add an expanded community-list entry\n"
13855 "Community list name\n"
13856 "Specify community to reject\n"
13857 "Specify community to accept\n"
13858 COMMUNITY_VAL_STR)
13859 {
13860 char *cl_name_or_number = NULL;
13861 int direct = 0;
13862 int style = COMMUNITY_LIST_EXPANDED;
13863
13864 int idx = 0;
13865 argv_find(argv, argc, "(100-500)", &idx);
13866 argv_find(argv, argc, "WORD", &idx);
13867 cl_name_or_number = argv[idx]->arg;
13868 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13869 : COMMUNITY_DENY;
13870 argv_find(argv, argc, "AA:NN", &idx);
13871 char *str = argv_concat(argv, argc, idx);
13872
13873 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13874 direct, style);
13875
13876 XFREE(MTYPE_TMP, str);
13877
13878 if (ret < 0) {
13879 community_list_perror(vty, ret);
13880 return CMD_WARNING_CONFIG_FAILED;
13881 }
13882
13883 return CMD_SUCCESS;
13884 }
13885
13886 /* Return configuration string of community-list entry. */
13887 static const char *community_list_config_str(struct community_entry *entry)
13888 {
13889 const char *str;
13890
13891 if (entry->any)
13892 str = "";
13893 else {
13894 if (entry->style == COMMUNITY_LIST_STANDARD)
13895 str = community_str(entry->u.com, false);
13896 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13897 str = lcommunity_str(entry->u.lcom, false);
13898 else
13899 str = entry->config;
13900 }
13901 return str;
13902 }
13903
13904 static void community_list_show(struct vty *vty, struct community_list *list)
13905 {
13906 struct community_entry *entry;
13907
13908 for (entry = list->head; entry; entry = entry->next) {
13909 if (entry == list->head) {
13910 if (all_digit(list->name))
13911 vty_out(vty, "Community %s list %s\n",
13912 entry->style == COMMUNITY_LIST_STANDARD
13913 ? "standard"
13914 : "(expanded) access",
13915 list->name);
13916 else
13917 vty_out(vty, "Named Community %s list %s\n",
13918 entry->style == COMMUNITY_LIST_STANDARD
13919 ? "standard"
13920 : "expanded",
13921 list->name);
13922 }
13923 if (entry->any)
13924 vty_out(vty, " %s\n",
13925 community_direct_str(entry->direct));
13926 else
13927 vty_out(vty, " %s %s\n",
13928 community_direct_str(entry->direct),
13929 community_list_config_str(entry));
13930 }
13931 }
13932
13933 DEFUN (show_ip_community_list,
13934 show_ip_community_list_cmd,
13935 "show ip community-list",
13936 SHOW_STR
13937 IP_STR
13938 "List community-list\n")
13939 {
13940 struct community_list *list;
13941 struct community_list_master *cm;
13942
13943 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13944 if (!cm)
13945 return CMD_SUCCESS;
13946
13947 for (list = cm->num.head; list; list = list->next)
13948 community_list_show(vty, list);
13949
13950 for (list = cm->str.head; list; list = list->next)
13951 community_list_show(vty, list);
13952
13953 return CMD_SUCCESS;
13954 }
13955
13956 DEFUN (show_ip_community_list_arg,
13957 show_ip_community_list_arg_cmd,
13958 "show ip community-list <(1-500)|WORD>",
13959 SHOW_STR
13960 IP_STR
13961 "List community-list\n"
13962 "Community-list number\n"
13963 "Community-list name\n")
13964 {
13965 int idx_comm_list = 3;
13966 struct community_list *list;
13967
13968 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13969 COMMUNITY_LIST_MASTER);
13970 if (!list) {
13971 vty_out(vty, "%% Can't find community-list\n");
13972 return CMD_WARNING;
13973 }
13974
13975 community_list_show(vty, list);
13976
13977 return CMD_SUCCESS;
13978 }
13979
13980 /*
13981 * Large Community code.
13982 */
13983 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13984 struct cmd_token **argv, int style,
13985 int reject_all_digit_name)
13986 {
13987 int ret;
13988 int direct;
13989 char *str;
13990 int idx = 0;
13991 char *cl_name;
13992
13993 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13994 : COMMUNITY_DENY;
13995
13996 /* All digit name check. */
13997 idx = 0;
13998 argv_find(argv, argc, "WORD", &idx);
13999 argv_find(argv, argc, "(1-99)", &idx);
14000 argv_find(argv, argc, "(100-500)", &idx);
14001 cl_name = argv[idx]->arg;
14002 if (reject_all_digit_name && all_digit(cl_name)) {
14003 vty_out(vty, "%% Community name cannot have all digits\n");
14004 return CMD_WARNING_CONFIG_FAILED;
14005 }
14006
14007 idx = 0;
14008 argv_find(argv, argc, "AA:BB:CC", &idx);
14009 argv_find(argv, argc, "LINE", &idx);
14010 /* Concat community string argument. */
14011 if (idx)
14012 str = argv_concat(argv, argc, idx);
14013 else
14014 str = NULL;
14015
14016 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
14017
14018 /* Free temporary community list string allocated by
14019 argv_concat(). */
14020 if (str)
14021 XFREE(MTYPE_TMP, str);
14022
14023 if (ret < 0) {
14024 community_list_perror(vty, ret);
14025 return CMD_WARNING_CONFIG_FAILED;
14026 }
14027 return CMD_SUCCESS;
14028 }
14029
14030 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
14031 struct cmd_token **argv, int style)
14032 {
14033 int ret;
14034 int direct = 0;
14035 char *str = NULL;
14036 int idx = 0;
14037
14038 argv_find(argv, argc, "permit", &idx);
14039 argv_find(argv, argc, "deny", &idx);
14040
14041 if (idx) {
14042 /* Check the list direct. */
14043 if (strncmp(argv[idx]->arg, "p", 1) == 0)
14044 direct = COMMUNITY_PERMIT;
14045 else
14046 direct = COMMUNITY_DENY;
14047
14048 idx = 0;
14049 argv_find(argv, argc, "LINE", &idx);
14050 argv_find(argv, argc, "AA:AA:NN", &idx);
14051 /* Concat community string argument. */
14052 str = argv_concat(argv, argc, idx);
14053 }
14054
14055 idx = 0;
14056 argv_find(argv, argc, "(1-99)", &idx);
14057 argv_find(argv, argc, "(100-500)", &idx);
14058 argv_find(argv, argc, "WORD", &idx);
14059
14060 /* Unset community list. */
14061 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
14062 style);
14063
14064 /* Free temporary community list string allocated by
14065 argv_concat(). */
14066 if (str)
14067 XFREE(MTYPE_TMP, str);
14068
14069 if (ret < 0) {
14070 community_list_perror(vty, ret);
14071 return CMD_WARNING_CONFIG_FAILED;
14072 }
14073
14074 return CMD_SUCCESS;
14075 }
14076
14077 /* "large-community-list" keyword help string. */
14078 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
14079 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
14080
14081 DEFUN (ip_lcommunity_list_standard,
14082 ip_lcommunity_list_standard_cmd,
14083 "ip large-community-list (1-99) <deny|permit>",
14084 IP_STR
14085 LCOMMUNITY_LIST_STR
14086 "Large Community list number (standard)\n"
14087 "Specify large community to reject\n"
14088 "Specify large community to accept\n")
14089 {
14090 return lcommunity_list_set_vty(vty, argc, argv,
14091 LARGE_COMMUNITY_LIST_STANDARD, 0);
14092 }
14093
14094 DEFUN (ip_lcommunity_list_standard1,
14095 ip_lcommunity_list_standard1_cmd,
14096 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
14097 IP_STR
14098 LCOMMUNITY_LIST_STR
14099 "Large Community list number (standard)\n"
14100 "Specify large community to reject\n"
14101 "Specify large community to accept\n"
14102 LCOMMUNITY_VAL_STR)
14103 {
14104 return lcommunity_list_set_vty(vty, argc, argv,
14105 LARGE_COMMUNITY_LIST_STANDARD, 0);
14106 }
14107
14108 DEFUN (ip_lcommunity_list_expanded,
14109 ip_lcommunity_list_expanded_cmd,
14110 "ip large-community-list (100-500) <deny|permit> LINE...",
14111 IP_STR
14112 LCOMMUNITY_LIST_STR
14113 "Large Community list number (expanded)\n"
14114 "Specify large community to reject\n"
14115 "Specify large community to accept\n"
14116 "An ordered list as a regular-expression\n")
14117 {
14118 return lcommunity_list_set_vty(vty, argc, argv,
14119 LARGE_COMMUNITY_LIST_EXPANDED, 0);
14120 }
14121
14122 DEFUN (ip_lcommunity_list_name_standard,
14123 ip_lcommunity_list_name_standard_cmd,
14124 "ip large-community-list standard WORD <deny|permit>",
14125 IP_STR
14126 LCOMMUNITY_LIST_STR
14127 "Specify standard large-community-list\n"
14128 "Large Community list name\n"
14129 "Specify large community to reject\n"
14130 "Specify large community to accept\n")
14131 {
14132 return lcommunity_list_set_vty(vty, argc, argv,
14133 LARGE_COMMUNITY_LIST_STANDARD, 1);
14134 }
14135
14136 DEFUN (ip_lcommunity_list_name_standard1,
14137 ip_lcommunity_list_name_standard1_cmd,
14138 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
14139 IP_STR
14140 LCOMMUNITY_LIST_STR
14141 "Specify standard large-community-list\n"
14142 "Large Community list name\n"
14143 "Specify large community to reject\n"
14144 "Specify large community to accept\n"
14145 LCOMMUNITY_VAL_STR)
14146 {
14147 return lcommunity_list_set_vty(vty, argc, argv,
14148 LARGE_COMMUNITY_LIST_STANDARD, 1);
14149 }
14150
14151 DEFUN (ip_lcommunity_list_name_expanded,
14152 ip_lcommunity_list_name_expanded_cmd,
14153 "ip large-community-list expanded WORD <deny|permit> LINE...",
14154 IP_STR
14155 LCOMMUNITY_LIST_STR
14156 "Specify expanded large-community-list\n"
14157 "Large Community list name\n"
14158 "Specify large community to reject\n"
14159 "Specify large community to accept\n"
14160 "An ordered list as a regular-expression\n")
14161 {
14162 return lcommunity_list_set_vty(vty, argc, argv,
14163 LARGE_COMMUNITY_LIST_EXPANDED, 1);
14164 }
14165
14166 DEFUN (no_ip_lcommunity_list_standard_all,
14167 no_ip_lcommunity_list_standard_all_cmd,
14168 "no ip large-community-list <(1-99)|(100-500)|WORD>",
14169 NO_STR
14170 IP_STR
14171 LCOMMUNITY_LIST_STR
14172 "Large Community list number (standard)\n"
14173 "Large Community list number (expanded)\n"
14174 "Large Community list name\n")
14175 {
14176 return lcommunity_list_unset_vty(vty, argc, argv,
14177 LARGE_COMMUNITY_LIST_STANDARD);
14178 }
14179
14180 DEFUN (no_ip_lcommunity_list_name_expanded_all,
14181 no_ip_lcommunity_list_name_expanded_all_cmd,
14182 "no ip large-community-list expanded WORD",
14183 NO_STR
14184 IP_STR
14185 LCOMMUNITY_LIST_STR
14186 "Specify expanded large-community-list\n"
14187 "Large Community list name\n")
14188 {
14189 return lcommunity_list_unset_vty(vty, argc, argv,
14190 LARGE_COMMUNITY_LIST_EXPANDED);
14191 }
14192
14193 DEFUN (no_ip_lcommunity_list_standard,
14194 no_ip_lcommunity_list_standard_cmd,
14195 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
14196 NO_STR
14197 IP_STR
14198 LCOMMUNITY_LIST_STR
14199 "Large Community list number (standard)\n"
14200 "Specify large community to reject\n"
14201 "Specify large community to accept\n"
14202 LCOMMUNITY_VAL_STR)
14203 {
14204 return lcommunity_list_unset_vty(vty, argc, argv,
14205 LARGE_COMMUNITY_LIST_STANDARD);
14206 }
14207
14208 DEFUN (no_ip_lcommunity_list_expanded,
14209 no_ip_lcommunity_list_expanded_cmd,
14210 "no ip large-community-list (100-500) <deny|permit> LINE...",
14211 NO_STR
14212 IP_STR
14213 LCOMMUNITY_LIST_STR
14214 "Large Community list number (expanded)\n"
14215 "Specify large community to reject\n"
14216 "Specify large community to accept\n"
14217 "An ordered list as a regular-expression\n")
14218 {
14219 return lcommunity_list_unset_vty(vty, argc, argv,
14220 LARGE_COMMUNITY_LIST_EXPANDED);
14221 }
14222
14223 DEFUN (no_ip_lcommunity_list_name_standard,
14224 no_ip_lcommunity_list_name_standard_cmd,
14225 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14226 NO_STR
14227 IP_STR
14228 LCOMMUNITY_LIST_STR
14229 "Specify standard large-community-list\n"
14230 "Large Community list name\n"
14231 "Specify large community to reject\n"
14232 "Specify large community to accept\n"
14233 LCOMMUNITY_VAL_STR)
14234 {
14235 return lcommunity_list_unset_vty(vty, argc, argv,
14236 LARGE_COMMUNITY_LIST_STANDARD);
14237 }
14238
14239 DEFUN (no_ip_lcommunity_list_name_expanded,
14240 no_ip_lcommunity_list_name_expanded_cmd,
14241 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14242 NO_STR
14243 IP_STR
14244 LCOMMUNITY_LIST_STR
14245 "Specify expanded large-community-list\n"
14246 "Large community list name\n"
14247 "Specify large community to reject\n"
14248 "Specify large community to accept\n"
14249 "An ordered list as a regular-expression\n")
14250 {
14251 return lcommunity_list_unset_vty(vty, argc, argv,
14252 LARGE_COMMUNITY_LIST_EXPANDED);
14253 }
14254
14255 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14256 {
14257 struct community_entry *entry;
14258
14259 for (entry = list->head; entry; entry = entry->next) {
14260 if (entry == list->head) {
14261 if (all_digit(list->name))
14262 vty_out(vty, "Large community %s list %s\n",
14263 entry->style == EXTCOMMUNITY_LIST_STANDARD
14264 ? "standard"
14265 : "(expanded) access",
14266 list->name);
14267 else
14268 vty_out(vty,
14269 "Named large community %s list %s\n",
14270 entry->style == EXTCOMMUNITY_LIST_STANDARD
14271 ? "standard"
14272 : "expanded",
14273 list->name);
14274 }
14275 if (entry->any)
14276 vty_out(vty, " %s\n",
14277 community_direct_str(entry->direct));
14278 else
14279 vty_out(vty, " %s %s\n",
14280 community_direct_str(entry->direct),
14281 community_list_config_str(entry));
14282 }
14283 }
14284
14285 DEFUN (show_ip_lcommunity_list,
14286 show_ip_lcommunity_list_cmd,
14287 "show ip large-community-list",
14288 SHOW_STR
14289 IP_STR
14290 "List large-community list\n")
14291 {
14292 struct community_list *list;
14293 struct community_list_master *cm;
14294
14295 cm = community_list_master_lookup(bgp_clist,
14296 LARGE_COMMUNITY_LIST_MASTER);
14297 if (!cm)
14298 return CMD_SUCCESS;
14299
14300 for (list = cm->num.head; list; list = list->next)
14301 lcommunity_list_show(vty, list);
14302
14303 for (list = cm->str.head; list; list = list->next)
14304 lcommunity_list_show(vty, list);
14305
14306 return CMD_SUCCESS;
14307 }
14308
14309 DEFUN (show_ip_lcommunity_list_arg,
14310 show_ip_lcommunity_list_arg_cmd,
14311 "show ip large-community-list <(1-500)|WORD>",
14312 SHOW_STR
14313 IP_STR
14314 "List large-community list\n"
14315 "large-community-list number\n"
14316 "large-community-list name\n")
14317 {
14318 struct community_list *list;
14319
14320 list = community_list_lookup(bgp_clist, argv[3]->arg,
14321 LARGE_COMMUNITY_LIST_MASTER);
14322 if (!list) {
14323 vty_out(vty, "%% Can't find extcommunity-list\n");
14324 return CMD_WARNING;
14325 }
14326
14327 lcommunity_list_show(vty, list);
14328
14329 return CMD_SUCCESS;
14330 }
14331
14332 /* "extcommunity-list" keyword help string. */
14333 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14334 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14335
14336 DEFUN (ip_extcommunity_list_standard,
14337 ip_extcommunity_list_standard_cmd,
14338 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14339 IP_STR
14340 EXTCOMMUNITY_LIST_STR
14341 "Extended Community list number (standard)\n"
14342 "Specify standard extcommunity-list\n"
14343 "Community list name\n"
14344 "Specify community to reject\n"
14345 "Specify community to accept\n"
14346 EXTCOMMUNITY_VAL_STR)
14347 {
14348 int style = EXTCOMMUNITY_LIST_STANDARD;
14349 int direct = 0;
14350 char *cl_number_or_name = NULL;
14351
14352 int idx = 0;
14353 argv_find(argv, argc, "(1-99)", &idx);
14354 argv_find(argv, argc, "WORD", &idx);
14355 cl_number_or_name = argv[idx]->arg;
14356 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14357 : COMMUNITY_DENY;
14358 argv_find(argv, argc, "AA:NN", &idx);
14359 char *str = argv_concat(argv, argc, idx);
14360
14361 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14362 direct, style);
14363
14364 XFREE(MTYPE_TMP, str);
14365
14366 if (ret < 0) {
14367 community_list_perror(vty, ret);
14368 return CMD_WARNING_CONFIG_FAILED;
14369 }
14370
14371 return CMD_SUCCESS;
14372 }
14373
14374 DEFUN (ip_extcommunity_list_name_expanded,
14375 ip_extcommunity_list_name_expanded_cmd,
14376 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14377 IP_STR
14378 EXTCOMMUNITY_LIST_STR
14379 "Extended Community list number (expanded)\n"
14380 "Specify expanded extcommunity-list\n"
14381 "Extended Community list name\n"
14382 "Specify community to reject\n"
14383 "Specify community to accept\n"
14384 "An ordered list as a regular-expression\n")
14385 {
14386 int style = EXTCOMMUNITY_LIST_EXPANDED;
14387 int direct = 0;
14388 char *cl_number_or_name = NULL;
14389
14390 int idx = 0;
14391 argv_find(argv, argc, "(100-500)", &idx);
14392 argv_find(argv, argc, "WORD", &idx);
14393 cl_number_or_name = argv[idx]->arg;
14394 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14395 : COMMUNITY_DENY;
14396 argv_find(argv, argc, "LINE", &idx);
14397 char *str = argv_concat(argv, argc, idx);
14398
14399 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14400 direct, style);
14401
14402 XFREE(MTYPE_TMP, str);
14403
14404 if (ret < 0) {
14405 community_list_perror(vty, ret);
14406 return CMD_WARNING_CONFIG_FAILED;
14407 }
14408
14409 return CMD_SUCCESS;
14410 }
14411
14412 DEFUN (no_ip_extcommunity_list_standard_all,
14413 no_ip_extcommunity_list_standard_all_cmd,
14414 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14415 NO_STR
14416 IP_STR
14417 EXTCOMMUNITY_LIST_STR
14418 "Extended Community list number (standard)\n"
14419 "Specify standard extcommunity-list\n"
14420 "Community list name\n"
14421 "Specify community to reject\n"
14422 "Specify community to accept\n"
14423 EXTCOMMUNITY_VAL_STR)
14424 {
14425 int style = EXTCOMMUNITY_LIST_STANDARD;
14426 int direct = 0;
14427 char *cl_number_or_name = NULL;
14428
14429 int idx = 0;
14430 argv_find(argv, argc, "(1-99)", &idx);
14431 argv_find(argv, argc, "WORD", &idx);
14432 cl_number_or_name = argv[idx]->arg;
14433 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14434 : COMMUNITY_DENY;
14435 argv_find(argv, argc, "AA:NN", &idx);
14436 char *str = argv_concat(argv, argc, idx);
14437
14438 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14439 direct, style);
14440
14441 XFREE(MTYPE_TMP, str);
14442
14443 if (ret < 0) {
14444 community_list_perror(vty, ret);
14445 return CMD_WARNING_CONFIG_FAILED;
14446 }
14447
14448 return CMD_SUCCESS;
14449 }
14450
14451 DEFUN (no_ip_extcommunity_list_expanded_all,
14452 no_ip_extcommunity_list_expanded_all_cmd,
14453 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14454 NO_STR
14455 IP_STR
14456 EXTCOMMUNITY_LIST_STR
14457 "Extended Community list number (expanded)\n"
14458 "Specify expanded extcommunity-list\n"
14459 "Extended Community list name\n"
14460 "Specify community to reject\n"
14461 "Specify community to accept\n"
14462 "An ordered list as a regular-expression\n")
14463 {
14464 int style = EXTCOMMUNITY_LIST_EXPANDED;
14465 int direct = 0;
14466 char *cl_number_or_name = NULL;
14467
14468 int idx = 0;
14469 argv_find(argv, argc, "(100-500)", &idx);
14470 argv_find(argv, argc, "WORD", &idx);
14471 cl_number_or_name = argv[idx]->arg;
14472 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14473 : COMMUNITY_DENY;
14474 argv_find(argv, argc, "LINE", &idx);
14475 char *str = argv_concat(argv, argc, idx);
14476
14477 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14478 direct, style);
14479
14480 XFREE(MTYPE_TMP, str);
14481
14482 if (ret < 0) {
14483 community_list_perror(vty, ret);
14484 return CMD_WARNING_CONFIG_FAILED;
14485 }
14486
14487 return CMD_SUCCESS;
14488 }
14489
14490 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14491 {
14492 struct community_entry *entry;
14493
14494 for (entry = list->head; entry; entry = entry->next) {
14495 if (entry == list->head) {
14496 if (all_digit(list->name))
14497 vty_out(vty, "Extended community %s list %s\n",
14498 entry->style == EXTCOMMUNITY_LIST_STANDARD
14499 ? "standard"
14500 : "(expanded) access",
14501 list->name);
14502 else
14503 vty_out(vty,
14504 "Named extended community %s list %s\n",
14505 entry->style == EXTCOMMUNITY_LIST_STANDARD
14506 ? "standard"
14507 : "expanded",
14508 list->name);
14509 }
14510 if (entry->any)
14511 vty_out(vty, " %s\n",
14512 community_direct_str(entry->direct));
14513 else
14514 vty_out(vty, " %s %s\n",
14515 community_direct_str(entry->direct),
14516 community_list_config_str(entry));
14517 }
14518 }
14519
14520 DEFUN (show_ip_extcommunity_list,
14521 show_ip_extcommunity_list_cmd,
14522 "show ip extcommunity-list",
14523 SHOW_STR
14524 IP_STR
14525 "List extended-community list\n")
14526 {
14527 struct community_list *list;
14528 struct community_list_master *cm;
14529
14530 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14531 if (!cm)
14532 return CMD_SUCCESS;
14533
14534 for (list = cm->num.head; list; list = list->next)
14535 extcommunity_list_show(vty, list);
14536
14537 for (list = cm->str.head; list; list = list->next)
14538 extcommunity_list_show(vty, list);
14539
14540 return CMD_SUCCESS;
14541 }
14542
14543 DEFUN (show_ip_extcommunity_list_arg,
14544 show_ip_extcommunity_list_arg_cmd,
14545 "show ip extcommunity-list <(1-500)|WORD>",
14546 SHOW_STR
14547 IP_STR
14548 "List extended-community list\n"
14549 "Extcommunity-list number\n"
14550 "Extcommunity-list name\n")
14551 {
14552 int idx_comm_list = 3;
14553 struct community_list *list;
14554
14555 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14556 EXTCOMMUNITY_LIST_MASTER);
14557 if (!list) {
14558 vty_out(vty, "%% Can't find extcommunity-list\n");
14559 return CMD_WARNING;
14560 }
14561
14562 extcommunity_list_show(vty, list);
14563
14564 return CMD_SUCCESS;
14565 }
14566
14567 /* Display community-list and extcommunity-list configuration. */
14568 static int community_list_config_write(struct vty *vty)
14569 {
14570 struct community_list *list;
14571 struct community_entry *entry;
14572 struct community_list_master *cm;
14573 int write = 0;
14574
14575 /* Community-list. */
14576 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14577
14578 for (list = cm->num.head; list; list = list->next)
14579 for (entry = list->head; entry; entry = entry->next) {
14580 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14581 community_direct_str(entry->direct),
14582 community_list_config_str(entry));
14583 write++;
14584 }
14585 for (list = cm->str.head; list; list = list->next)
14586 for (entry = list->head; entry; entry = entry->next) {
14587 vty_out(vty, "ip community-list %s %s %s %s\n",
14588 entry->style == COMMUNITY_LIST_STANDARD
14589 ? "standard"
14590 : "expanded",
14591 list->name, community_direct_str(entry->direct),
14592 community_list_config_str(entry));
14593 write++;
14594 }
14595
14596 /* Extcommunity-list. */
14597 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14598
14599 for (list = cm->num.head; list; list = list->next)
14600 for (entry = list->head; entry; entry = entry->next) {
14601 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14602 list->name, community_direct_str(entry->direct),
14603 community_list_config_str(entry));
14604 write++;
14605 }
14606 for (list = cm->str.head; list; list = list->next)
14607 for (entry = list->head; entry; entry = entry->next) {
14608 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14609 entry->style == EXTCOMMUNITY_LIST_STANDARD
14610 ? "standard"
14611 : "expanded",
14612 list->name, community_direct_str(entry->direct),
14613 community_list_config_str(entry));
14614 write++;
14615 }
14616
14617
14618 /* lcommunity-list. */
14619 cm = community_list_master_lookup(bgp_clist,
14620 LARGE_COMMUNITY_LIST_MASTER);
14621
14622 for (list = cm->num.head; list; list = list->next)
14623 for (entry = list->head; entry; entry = entry->next) {
14624 vty_out(vty, "ip large-community-list %s %s %s\n",
14625 list->name, community_direct_str(entry->direct),
14626 community_list_config_str(entry));
14627 write++;
14628 }
14629 for (list = cm->str.head; list; list = list->next)
14630 for (entry = list->head; entry; entry = entry->next) {
14631 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14632 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14633 ? "standard"
14634 : "expanded",
14635 list->name, community_direct_str(entry->direct),
14636 community_list_config_str(entry));
14637 write++;
14638 }
14639
14640 return write;
14641 }
14642
14643 static struct cmd_node community_list_node = {
14644 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14645 };
14646
14647 static void community_list_vty(void)
14648 {
14649 install_node(&community_list_node, community_list_config_write);
14650
14651 /* Community-list. */
14652 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14653 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14654 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14655 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14656 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14657 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14658
14659 /* Extcommunity-list. */
14660 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14661 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14662 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14663 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14664 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14665 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14666
14667 /* Large Community List */
14668 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14669 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14670 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14671 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14672 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14673 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14674 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14675 install_element(CONFIG_NODE,
14676 &no_ip_lcommunity_list_name_expanded_all_cmd);
14677 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14678 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14679 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14680 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14681 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14682 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14683 }