]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #1976 from pguibert6WIND/issue_1968
[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
38 #include "bgpd/bgpd.h"
39 #include "bgpd/bgp_advertise.h"
40 #include "bgpd/bgp_attr.h"
41 #include "bgpd/bgp_aspath.h"
42 #include "bgpd/bgp_community.h"
43 #include "bgpd/bgp_ecommunity.h"
44 #include "bgpd/bgp_lcommunity.h"
45 #include "bgpd/bgp_damp.h"
46 #include "bgpd/bgp_debug.h"
47 #include "bgpd/bgp_fsm.h"
48 #include "bgpd/bgp_nexthop.h"
49 #include "bgpd/bgp_open.h"
50 #include "bgpd/bgp_regex.h"
51 #include "bgpd/bgp_route.h"
52 #include "bgpd/bgp_mplsvpn.h"
53 #include "bgpd/bgp_zebra.h"
54 #include "bgpd/bgp_table.h"
55 #include "bgpd/bgp_vty.h"
56 #include "bgpd/bgp_mpath.h"
57 #include "bgpd/bgp_packet.h"
58 #include "bgpd/bgp_updgrp.h"
59 #include "bgpd/bgp_bfd.h"
60 #include "bgpd/bgp_io.h"
61 #include "bgpd/bgp_evpn.h"
62
63 static struct peer_group *listen_range_exists(struct bgp *bgp,
64 struct prefix *range, int exact);
65
66 static enum node_type bgp_node_type(afi_t afi, safi_t safi)
67 {
68 switch (afi) {
69 case AFI_IP:
70 switch (safi) {
71 case SAFI_UNICAST:
72 return BGP_IPV4_NODE;
73 break;
74 case SAFI_MULTICAST:
75 return BGP_IPV4M_NODE;
76 break;
77 case SAFI_LABELED_UNICAST:
78 return BGP_IPV4L_NODE;
79 break;
80 case SAFI_MPLS_VPN:
81 return BGP_VPNV4_NODE;
82 break;
83 case SAFI_FLOWSPEC:
84 return BGP_FLOWSPECV4_NODE;
85 default:
86 /* not expected */
87 return BGP_IPV4_NODE;
88 break;
89 }
90 break;
91 case AFI_IP6:
92 switch (safi) {
93 case SAFI_UNICAST:
94 return BGP_IPV6_NODE;
95 break;
96 case SAFI_MULTICAST:
97 return BGP_IPV6M_NODE;
98 break;
99 case SAFI_LABELED_UNICAST:
100 return BGP_IPV6L_NODE;
101 break;
102 case SAFI_MPLS_VPN:
103 return BGP_VPNV6_NODE;
104 break;
105 case SAFI_FLOWSPEC:
106 return BGP_FLOWSPECV6_NODE;
107 default:
108 /* not expected */
109 return BGP_IPV4_NODE;
110 break;
111 }
112 break;
113 case AFI_L2VPN:
114 return BGP_EVPN_NODE;
115 break;
116 case AFI_MAX:
117 // We should never be here but to clarify the switch statement..
118 return BGP_IPV4_NODE;
119 break;
120 }
121
122 // Impossible to happen
123 return BGP_IPV4_NODE;
124 }
125
126 /* Utility function to get address family from current node. */
127 afi_t bgp_node_afi(struct vty *vty)
128 {
129 afi_t afi;
130 switch (vty->node) {
131 case BGP_IPV6_NODE:
132 case BGP_IPV6M_NODE:
133 case BGP_IPV6L_NODE:
134 case BGP_VPNV6_NODE:
135 case BGP_FLOWSPECV6_NODE:
136 afi = AFI_IP6;
137 break;
138 case BGP_EVPN_NODE:
139 afi = AFI_L2VPN;
140 break;
141 default:
142 afi = AFI_IP;
143 break;
144 }
145 return afi;
146 }
147
148 /* Utility function to get subsequent address family from current
149 node. */
150 safi_t bgp_node_safi(struct vty *vty)
151 {
152 safi_t safi;
153 switch (vty->node) {
154 case BGP_VPNV4_NODE:
155 case BGP_VPNV6_NODE:
156 safi = SAFI_MPLS_VPN;
157 break;
158 case BGP_IPV4M_NODE:
159 case BGP_IPV6M_NODE:
160 safi = SAFI_MULTICAST;
161 break;
162 case BGP_EVPN_NODE:
163 safi = SAFI_EVPN;
164 break;
165 case BGP_IPV4L_NODE:
166 case BGP_IPV6L_NODE:
167 safi = SAFI_LABELED_UNICAST;
168 break;
169 case BGP_FLOWSPECV4_NODE:
170 case BGP_FLOWSPECV6_NODE:
171 safi = SAFI_FLOWSPEC;
172 break;
173 default:
174 safi = SAFI_UNICAST;
175 break;
176 }
177 return safi;
178 }
179
180 /**
181 * Converts an AFI in string form to afi_t
182 *
183 * @param afi string, one of
184 * - "ipv4"
185 * - "ipv6"
186 * @return the corresponding afi_t
187 */
188 afi_t bgp_vty_afi_from_str(const char *afi_str)
189 {
190 afi_t afi = AFI_MAX; /* unknown */
191 if (strmatch(afi_str, "ipv4"))
192 afi = AFI_IP;
193 else if (strmatch(afi_str, "ipv6"))
194 afi = AFI_IP6;
195 return afi;
196 }
197
198 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
199 afi_t *afi)
200 {
201 int ret = 0;
202 if (argv_find(argv, argc, "ipv4", index)) {
203 ret = 1;
204 if (afi)
205 *afi = AFI_IP;
206 } else if (argv_find(argv, argc, "ipv6", index)) {
207 ret = 1;
208 if (afi)
209 *afi = AFI_IP6;
210 }
211 return ret;
212 }
213
214 /* supports <unicast|multicast|vpn|labeled-unicast> */
215 safi_t bgp_vty_safi_from_str(const char *safi_str)
216 {
217 safi_t safi = SAFI_MAX; /* unknown */
218 if (strmatch(safi_str, "multicast"))
219 safi = SAFI_MULTICAST;
220 else if (strmatch(safi_str, "unicast"))
221 safi = SAFI_UNICAST;
222 else if (strmatch(safi_str, "vpn"))
223 safi = SAFI_MPLS_VPN;
224 else if (strmatch(safi_str, "labeled-unicast"))
225 safi = SAFI_LABELED_UNICAST;
226 else if (strmatch(safi_str, "flowspec"))
227 safi = SAFI_FLOWSPEC;
228 return safi;
229 }
230
231 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
232 safi_t *safi)
233 {
234 int ret = 0;
235 if (argv_find(argv, argc, "unicast", index)) {
236 ret = 1;
237 if (safi)
238 *safi = SAFI_UNICAST;
239 } else if (argv_find(argv, argc, "multicast", index)) {
240 ret = 1;
241 if (safi)
242 *safi = SAFI_MULTICAST;
243 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
244 ret = 1;
245 if (safi)
246 *safi = SAFI_LABELED_UNICAST;
247 } else if (argv_find(argv, argc, "vpn", index)) {
248 ret = 1;
249 if (safi)
250 *safi = SAFI_MPLS_VPN;
251 } else if (argv_find(argv, argc, "flowspec", index)) {
252 ret = 1;
253 if (safi)
254 *safi = SAFI_FLOWSPEC;
255 }
256 return ret;
257 }
258
259 /*
260 * bgp_vty_find_and_parse_afi_safi_bgp
261 *
262 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
263 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
264 * to appropriate values for the calling function. This is to allow the
265 * calling function to make decisions appropriate for the show command
266 * that is being parsed.
267 *
268 * The show commands are generally of the form:
269 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
270 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
271 *
272 * Since we use argv_find if the show command in particular doesn't have:
273 * [ip]
274 * [<view|vrf> VIEWVRFNAME]
275 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
276 * The command parsing should still be ok.
277 *
278 * vty -> The vty for the command so we can output some useful data in
279 * the event of a parse error in the vrf.
280 * argv -> The command tokens
281 * argc -> How many command tokens we have
282 * idx -> The current place in the command, generally should be 0 for this
283 * function
284 * afi -> The parsed afi if it was included in the show command, returned here
285 * safi -> The parsed safi if it was included in the show command, returned here
286 * bgp -> Pointer to the bgp data structure we need to fill in.
287 *
288 * The function returns the correct location in the parse tree for the
289 * last token found.
290 *
291 * Returns 0 for failure to parse correctly, else the idx position of where
292 * it found the last token.
293 */
294 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
295 struct cmd_token **argv, int argc,
296 int *idx, afi_t *afi, safi_t *safi,
297 struct bgp **bgp)
298 {
299 char *vrf_name = NULL;
300
301 assert(afi);
302 assert(safi);
303 assert(bgp);
304
305 if (argv_find(argv, argc, "ip", idx))
306 *afi = AFI_IP;
307
308 if (argv_find(argv, argc, "view", idx)
309 || argv_find(argv, argc, "vrf", idx)) {
310 vrf_name = argv[*idx + 1]->arg;
311
312 if (strmatch(vrf_name, "all"))
313 *bgp = NULL;
314 else {
315 *bgp = bgp_lookup_by_name(vrf_name);
316 if (!*bgp) {
317 vty_out(vty,
318 "View/Vrf specified is unknown: %s\n",
319 vrf_name);
320 *idx = 0;
321 return 0;
322 }
323 }
324 } else {
325 *bgp = bgp_get_default();
326 if (!*bgp) {
327 vty_out(vty, "Unable to find default BGP instance\n");
328 *idx = 0;
329 return 0;
330 }
331 }
332
333 if (argv_find_and_parse_afi(argv, argc, idx, afi))
334 argv_find_and_parse_safi(argv, argc, idx, safi);
335
336 *idx += 1;
337 return *idx;
338 }
339
340 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
341 {
342 struct interface *ifp = NULL;
343
344 if (su->sa.sa_family == AF_INET)
345 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
346 else if (su->sa.sa_family == AF_INET6)
347 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
348 su->sin6.sin6_scope_id,
349 bgp->vrf_id);
350
351 if (ifp)
352 return 1;
353
354 return 0;
355 }
356
357 /* Utility function for looking up peer from VTY. */
358 /* This is used only for configuration, so disallow if attempted on
359 * a dynamic neighbor.
360 */
361 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
362 {
363 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
364 int ret;
365 union sockunion su;
366 struct peer *peer;
367
368 if (!bgp) {
369 return NULL;
370 }
371
372 ret = str2sockunion(ip_str, &su);
373 if (ret < 0) {
374 peer = peer_lookup_by_conf_if(bgp, ip_str);
375 if (!peer) {
376 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
377 == NULL) {
378 vty_out(vty,
379 "%% Malformed address or name: %s\n",
380 ip_str);
381 return NULL;
382 }
383 }
384 } else {
385 peer = peer_lookup(bgp, &su);
386 if (!peer) {
387 vty_out(vty,
388 "%% Specify remote-as or peer-group commands first\n");
389 return NULL;
390 }
391 if (peer_dynamic_neighbor(peer)) {
392 vty_out(vty,
393 "%% Operation not allowed on a dynamic neighbor\n");
394 return NULL;
395 }
396 }
397 return peer;
398 }
399
400 /* Utility function for looking up peer or peer group. */
401 /* This is used only for configuration, so disallow if attempted on
402 * a dynamic neighbor.
403 */
404 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
405 {
406 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
407 int ret;
408 union sockunion su;
409 struct peer *peer = NULL;
410 struct peer_group *group = NULL;
411
412 if (!bgp) {
413 return NULL;
414 }
415
416 ret = str2sockunion(peer_str, &su);
417 if (ret == 0) {
418 /* IP address, locate peer. */
419 peer = peer_lookup(bgp, &su);
420 } else {
421 /* Not IP, could match either peer configured on interface or a
422 * group. */
423 peer = peer_lookup_by_conf_if(bgp, peer_str);
424 if (!peer)
425 group = peer_group_lookup(bgp, peer_str);
426 }
427
428 if (peer) {
429 if (peer_dynamic_neighbor(peer)) {
430 vty_out(vty,
431 "%% Operation not allowed on a dynamic neighbor\n");
432 return NULL;
433 }
434
435 return peer;
436 }
437
438 if (group)
439 return group->conf;
440
441 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
442
443 return NULL;
444 }
445
446 int bgp_vty_return(struct vty *vty, int ret)
447 {
448 const char *str = NULL;
449
450 switch (ret) {
451 case BGP_ERR_INVALID_VALUE:
452 str = "Invalid value";
453 break;
454 case BGP_ERR_INVALID_FLAG:
455 str = "Invalid flag";
456 break;
457 case BGP_ERR_PEER_GROUP_SHUTDOWN:
458 str = "Peer-group has been shutdown. Activate the peer-group first";
459 break;
460 case BGP_ERR_PEER_FLAG_CONFLICT:
461 str = "Can't set override-capability and strict-capability-match at the same time";
462 break;
463 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
464 str = "Specify remote-as or peer-group remote AS first";
465 break;
466 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
467 str = "Cannot change the peer-group. Deconfigure first";
468 break;
469 case BGP_ERR_PEER_GROUP_MISMATCH:
470 str = "Peer is not a member of this peer-group";
471 break;
472 case BGP_ERR_PEER_FILTER_CONFLICT:
473 str = "Prefix/distribute list can not co-exist";
474 break;
475 case BGP_ERR_NOT_INTERNAL_PEER:
476 str = "Invalid command. Not an internal neighbor";
477 break;
478 case BGP_ERR_REMOVE_PRIVATE_AS:
479 str = "remove-private-AS cannot be configured for IBGP peers";
480 break;
481 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
482 str = "Local-AS allowed only for EBGP peers";
483 break;
484 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
485 str = "Cannot have local-as same as BGP AS number";
486 break;
487 case BGP_ERR_TCPSIG_FAILED:
488 str = "Error while applying TCP-Sig to session(s)";
489 break;
490 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
491 str = "ebgp-multihop and ttl-security cannot be configured together";
492 break;
493 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
494 str = "ttl-security only allowed for EBGP peers";
495 break;
496 case BGP_ERR_AS_OVERRIDE:
497 str = "as-override cannot be configured for IBGP peers";
498 break;
499 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
500 str = "Invalid limit for number of dynamic neighbors";
501 break;
502 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
503 str = "Dynamic neighbor listen range already exists";
504 break;
505 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
506 str = "Operation not allowed on a dynamic neighbor";
507 break;
508 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
509 str = "Operation not allowed on a directly connected neighbor";
510 break;
511 case BGP_ERR_PEER_SAFI_CONFLICT:
512 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
513 break;
514 }
515 if (str) {
516 vty_out(vty, "%% %s\n", str);
517 return CMD_WARNING_CONFIG_FAILED;
518 }
519 return CMD_SUCCESS;
520 }
521
522 /* BGP clear sort. */
523 enum clear_sort {
524 clear_all,
525 clear_peer,
526 clear_group,
527 clear_external,
528 clear_as
529 };
530
531 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
532 safi_t safi, int error)
533 {
534 switch (error) {
535 case BGP_ERR_AF_UNCONFIGURED:
536 vty_out(vty,
537 "%%BGP: Enable %s address family for the neighbor %s\n",
538 afi_safi_print(afi, safi), peer->host);
539 break;
540 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
541 vty_out(vty,
542 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
543 peer->host);
544 break;
545 default:
546 break;
547 }
548 }
549
550 /* `clear ip bgp' functions. */
551 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
552 enum clear_sort sort, enum bgp_clear_type stype,
553 const char *arg)
554 {
555 int ret;
556 bool found = false;
557 struct peer *peer;
558 struct listnode *node, *nnode;
559
560 /* Clear all neighbors. */
561 /*
562 * Pass along pointer to next node to peer_clear() when walking all
563 * nodes on the BGP instance as that may get freed if it is a
564 * doppelganger
565 */
566 if (sort == clear_all) {
567 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
568 if (!peer->afc[afi][safi])
569 continue;
570
571 if (stype == BGP_CLEAR_SOFT_NONE)
572 ret = peer_clear(peer, &nnode);
573 else
574 ret = peer_clear_soft(peer, afi, safi, stype);
575
576 if (ret < 0)
577 bgp_clear_vty_error(vty, peer, afi, safi, ret);
578 else
579 found = true;
580 }
581
582 /* This is to apply read-only mode on this clear. */
583 if (stype == BGP_CLEAR_SOFT_NONE)
584 bgp->update_delay_over = 0;
585
586 if (!found)
587 vty_out(vty, "%%BGP: No %s peer configured",
588 afi_safi_print(afi, safi));
589
590 return CMD_SUCCESS;
591 }
592
593 /* Clear specified neighbor. */
594 if (sort == clear_peer) {
595 union sockunion su;
596
597 /* Make sockunion for lookup. */
598 ret = str2sockunion(arg, &su);
599 if (ret < 0) {
600 peer = peer_lookup_by_conf_if(bgp, arg);
601 if (!peer) {
602 peer = peer_lookup_by_hostname(bgp, arg);
603 if (!peer) {
604 vty_out(vty,
605 "Malformed address or name: %s\n",
606 arg);
607 return CMD_WARNING;
608 }
609 }
610 } else {
611 peer = peer_lookup(bgp, &su);
612 if (!peer) {
613 vty_out(vty,
614 "%%BGP: Unknown neighbor - \"%s\"\n",
615 arg);
616 return CMD_WARNING;
617 }
618 }
619
620 if (!peer->afc[afi][safi])
621 ret = BGP_ERR_AF_UNCONFIGURED;
622 else if (stype == BGP_CLEAR_SOFT_NONE)
623 ret = peer_clear(peer, NULL);
624 else
625 ret = peer_clear_soft(peer, afi, safi, stype);
626
627 if (ret < 0)
628 bgp_clear_vty_error(vty, peer, afi, safi, ret);
629
630 return CMD_SUCCESS;
631 }
632
633 /* Clear all neighbors belonging to a specific peer-group. */
634 if (sort == clear_group) {
635 struct peer_group *group;
636
637 group = peer_group_lookup(bgp, arg);
638 if (!group) {
639 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
640 return CMD_WARNING;
641 }
642
643 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
644 if (!peer->afc[afi][safi])
645 continue;
646
647 if (stype == BGP_CLEAR_SOFT_NONE)
648 ret = peer_clear(peer, NULL);
649 else
650 ret = peer_clear_soft(peer, afi, safi, stype);
651
652 if (ret < 0)
653 bgp_clear_vty_error(vty, peer, afi, safi, ret);
654 else
655 found = true;
656 }
657
658 if (!found)
659 vty_out(vty,
660 "%%BGP: No %s peer belonging to peer-group %s is configured\n",
661 afi_safi_print(afi, safi), arg);
662
663 return CMD_SUCCESS;
664 }
665
666 /* Clear all external (eBGP) neighbors. */
667 if (sort == clear_external) {
668 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
669 if (peer->sort == BGP_PEER_IBGP)
670 continue;
671
672 if (!peer->afc[afi][safi])
673 continue;
674
675 if (stype == BGP_CLEAR_SOFT_NONE)
676 ret = peer_clear(peer, &nnode);
677 else
678 ret = peer_clear_soft(peer, afi, safi, stype);
679
680 if (ret < 0)
681 bgp_clear_vty_error(vty, peer, afi, safi, ret);
682 else
683 found = true;
684 }
685
686 if (!found)
687 vty_out(vty,
688 "%%BGP: No external %s peer is configured\n",
689 afi_safi_print(afi, safi));
690
691 return CMD_SUCCESS;
692 }
693
694 /* Clear all neighbors belonging to a specific AS. */
695 if (sort == clear_as) {
696 as_t as = strtoul(arg, NULL, 10);
697
698 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
699 if (peer->as != as)
700 continue;
701
702 if (!peer->afc[afi][safi])
703 ret = BGP_ERR_AF_UNCONFIGURED;
704 else if (stype == BGP_CLEAR_SOFT_NONE)
705 ret = peer_clear(peer, &nnode);
706 else
707 ret = peer_clear_soft(peer, afi, safi, stype);
708
709 if (ret < 0)
710 bgp_clear_vty_error(vty, peer, afi, safi, ret);
711 else
712 found = true;
713 }
714
715 if (!found)
716 vty_out(vty,
717 "%%BGP: No %s peer is configured with AS %s\n",
718 afi_safi_print(afi, safi), arg);
719
720 return CMD_SUCCESS;
721 }
722
723 return CMD_SUCCESS;
724 }
725
726 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
727 safi_t safi, enum clear_sort sort,
728 enum bgp_clear_type stype, const char *arg)
729 {
730 struct bgp *bgp;
731
732 /* BGP structure lookup. */
733 if (name) {
734 bgp = bgp_lookup_by_name(name);
735 if (bgp == NULL) {
736 vty_out(vty, "Can't find BGP instance %s\n", name);
737 return CMD_WARNING;
738 }
739 } else {
740 bgp = bgp_get_default();
741 if (bgp == NULL) {
742 vty_out(vty, "No BGP process is configured\n");
743 return CMD_WARNING;
744 }
745 }
746
747 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
748 }
749
750 /* clear soft inbound */
751 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
752 {
753 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
754 BGP_CLEAR_SOFT_IN, NULL);
755 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
756 BGP_CLEAR_SOFT_IN, NULL);
757 }
758
759 /* clear soft outbound */
760 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
761 {
762 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
763 BGP_CLEAR_SOFT_OUT, NULL);
764 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
765 BGP_CLEAR_SOFT_OUT, NULL);
766 }
767
768
769 #ifndef VTYSH_EXTRACT_PL
770 #include "bgpd/bgp_vty_clippy.c"
771 #endif
772
773 /* BGP global configuration. */
774
775 DEFUN (bgp_multiple_instance_func,
776 bgp_multiple_instance_cmd,
777 "bgp multiple-instance",
778 BGP_STR
779 "Enable bgp multiple instance\n")
780 {
781 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
782 return CMD_SUCCESS;
783 }
784
785 DEFUN (no_bgp_multiple_instance,
786 no_bgp_multiple_instance_cmd,
787 "no bgp multiple-instance",
788 NO_STR
789 BGP_STR
790 "BGP multiple instance\n")
791 {
792 int ret;
793
794 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
795 if (ret < 0) {
796 vty_out(vty, "%% There are more than two BGP instances\n");
797 return CMD_WARNING_CONFIG_FAILED;
798 }
799 return CMD_SUCCESS;
800 }
801
802 DEFUN (bgp_config_type,
803 bgp_config_type_cmd,
804 "bgp config-type <cisco|zebra>",
805 BGP_STR
806 "Configuration type\n"
807 "cisco\n"
808 "zebra\n")
809 {
810 int idx = 0;
811 if (argv_find(argv, argc, "cisco", &idx))
812 bgp_option_set(BGP_OPT_CONFIG_CISCO);
813 else
814 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
815
816 return CMD_SUCCESS;
817 }
818
819 DEFUN (no_bgp_config_type,
820 no_bgp_config_type_cmd,
821 "no bgp config-type [<cisco|zebra>]",
822 NO_STR
823 BGP_STR
824 "Display configuration type\n"
825 "cisco\n"
826 "zebra\n")
827 {
828 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
829 return CMD_SUCCESS;
830 }
831
832
833 DEFUN (no_synchronization,
834 no_synchronization_cmd,
835 "no synchronization",
836 NO_STR
837 "Perform IGP synchronization\n")
838 {
839 return CMD_SUCCESS;
840 }
841
842 DEFUN (no_auto_summary,
843 no_auto_summary_cmd,
844 "no auto-summary",
845 NO_STR
846 "Enable automatic network number summarization\n")
847 {
848 return CMD_SUCCESS;
849 }
850
851 /* "router bgp" commands. */
852 DEFUN_NOSH (router_bgp,
853 router_bgp_cmd,
854 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
855 ROUTER_STR
856 BGP_STR
857 AS_STR
858 BGP_INSTANCE_HELP_STR)
859 {
860 int idx_asn = 2;
861 int idx_view_vrf = 3;
862 int idx_vrf = 4;
863 int ret;
864 as_t as;
865 struct bgp *bgp;
866 const char *name = NULL;
867 enum bgp_instance_type inst_type;
868
869 // "router bgp" without an ASN
870 if (argc == 2) {
871 // Pending: Make VRF option available for ASN less config
872 bgp = bgp_get_default();
873
874 if (bgp == NULL) {
875 vty_out(vty, "%% No BGP process is configured\n");
876 return CMD_WARNING_CONFIG_FAILED;
877 }
878
879 if (listcount(bm->bgp) > 1) {
880 vty_out(vty, "%% Please specify ASN and VRF\n");
881 return CMD_WARNING_CONFIG_FAILED;
882 }
883 }
884
885 // "router bgp X"
886 else {
887 as = strtoul(argv[idx_asn]->arg, NULL, 10);
888
889 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
890 if (argc > 3) {
891 name = argv[idx_vrf]->arg;
892
893 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
894 inst_type = BGP_INSTANCE_TYPE_VRF;
895 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
896 inst_type = BGP_INSTANCE_TYPE_VIEW;
897 }
898
899 ret = bgp_get(&bgp, &as, name, inst_type);
900 switch (ret) {
901 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
902 vty_out(vty,
903 "Please specify 'bgp multiple-instance' first\n");
904 return CMD_WARNING_CONFIG_FAILED;
905 case BGP_ERR_AS_MISMATCH:
906 vty_out(vty, "BGP is already running; AS is %u\n", as);
907 return CMD_WARNING_CONFIG_FAILED;
908 case BGP_ERR_INSTANCE_MISMATCH:
909 vty_out(vty,
910 "BGP instance name and AS number mismatch\n");
911 vty_out(vty,
912 "BGP instance is already running; AS is %u\n",
913 as);
914 return CMD_WARNING_CONFIG_FAILED;
915 }
916
917 /* Pending: handle when user tries to change a view to vrf n vv.
918 */
919 }
920
921 /* unset the auto created flag as the user config is now present */
922 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
923 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
924
925 return CMD_SUCCESS;
926 }
927
928 /* "no router bgp" commands. */
929 DEFUN (no_router_bgp,
930 no_router_bgp_cmd,
931 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
932 NO_STR
933 ROUTER_STR
934 BGP_STR
935 AS_STR
936 BGP_INSTANCE_HELP_STR)
937 {
938 int idx_asn = 3;
939 int idx_vrf = 5;
940 as_t as;
941 struct bgp *bgp;
942 const char *name = NULL;
943
944 // "no router bgp" without an ASN
945 if (argc == 3) {
946 // Pending: Make VRF option available for ASN less config
947 bgp = bgp_get_default();
948
949 if (bgp == NULL) {
950 vty_out(vty, "%% No BGP process is configured\n");
951 return CMD_WARNING_CONFIG_FAILED;
952 }
953
954 if (listcount(bm->bgp) > 1) {
955 vty_out(vty, "%% Please specify ASN and VRF\n");
956 return CMD_WARNING_CONFIG_FAILED;
957 }
958
959 if (bgp->l3vni) {
960 vty_out(vty, "%% Please unconfigure l3vni %u",
961 bgp->l3vni);
962 return CMD_WARNING_CONFIG_FAILED;
963 }
964 } else {
965 as = strtoul(argv[idx_asn]->arg, NULL, 10);
966
967 if (argc > 4)
968 name = argv[idx_vrf]->arg;
969
970 /* Lookup bgp structure. */
971 bgp = bgp_lookup(as, name);
972 if (!bgp) {
973 vty_out(vty, "%% Can't find BGP instance\n");
974 return CMD_WARNING_CONFIG_FAILED;
975 }
976
977 if (bgp->l3vni) {
978 vty_out(vty, "%% Please unconfigure l3vni %u",
979 bgp->l3vni);
980 return CMD_WARNING_CONFIG_FAILED;
981 }
982 }
983
984 bgp_delete(bgp);
985
986 return CMD_SUCCESS;
987 }
988
989
990 /* BGP router-id. */
991
992 DEFPY (bgp_router_id,
993 bgp_router_id_cmd,
994 "bgp router-id A.B.C.D",
995 BGP_STR
996 "Override configured router identifier\n"
997 "Manually configured router identifier\n")
998 {
999 VTY_DECLVAR_CONTEXT(bgp, bgp);
1000 bgp_router_id_static_set(bgp, router_id);
1001 return CMD_SUCCESS;
1002 }
1003
1004 DEFPY (no_bgp_router_id,
1005 no_bgp_router_id_cmd,
1006 "no bgp router-id [A.B.C.D]",
1007 NO_STR
1008 BGP_STR
1009 "Override configured router identifier\n"
1010 "Manually configured router identifier\n")
1011 {
1012 VTY_DECLVAR_CONTEXT(bgp, bgp);
1013
1014 if (router_id_str) {
1015 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
1016 vty_out(vty, "%% BGP router-id doesn't match\n");
1017 return CMD_WARNING_CONFIG_FAILED;
1018 }
1019 }
1020
1021 router_id.s_addr = 0;
1022 bgp_router_id_static_set(bgp, router_id);
1023
1024 return CMD_SUCCESS;
1025 }
1026
1027
1028 /* BGP Cluster ID. */
1029 DEFUN (bgp_cluster_id,
1030 bgp_cluster_id_cmd,
1031 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1032 BGP_STR
1033 "Configure Route-Reflector Cluster-id\n"
1034 "Route-Reflector Cluster-id in IP address format\n"
1035 "Route-Reflector Cluster-id as 32 bit quantity\n")
1036 {
1037 VTY_DECLVAR_CONTEXT(bgp, bgp);
1038 int idx_ipv4 = 2;
1039 int ret;
1040 struct in_addr cluster;
1041
1042 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1043 if (!ret) {
1044 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1045 return CMD_WARNING_CONFIG_FAILED;
1046 }
1047
1048 bgp_cluster_id_set(bgp, &cluster);
1049 bgp_clear_star_soft_out(vty, bgp->name);
1050
1051 return CMD_SUCCESS;
1052 }
1053
1054 DEFUN (no_bgp_cluster_id,
1055 no_bgp_cluster_id_cmd,
1056 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1057 NO_STR
1058 BGP_STR
1059 "Configure Route-Reflector Cluster-id\n"
1060 "Route-Reflector Cluster-id in IP address format\n"
1061 "Route-Reflector Cluster-id as 32 bit quantity\n")
1062 {
1063 VTY_DECLVAR_CONTEXT(bgp, bgp);
1064 bgp_cluster_id_unset(bgp);
1065 bgp_clear_star_soft_out(vty, bgp->name);
1066
1067 return CMD_SUCCESS;
1068 }
1069
1070 DEFUN (bgp_confederation_identifier,
1071 bgp_confederation_identifier_cmd,
1072 "bgp confederation identifier (1-4294967295)",
1073 "BGP specific commands\n"
1074 "AS confederation parameters\n"
1075 "AS number\n"
1076 "Set routing domain confederation AS\n")
1077 {
1078 VTY_DECLVAR_CONTEXT(bgp, bgp);
1079 int idx_number = 3;
1080 as_t as;
1081
1082 as = strtoul(argv[idx_number]->arg, NULL, 10);
1083
1084 bgp_confederation_id_set(bgp, as);
1085
1086 return CMD_SUCCESS;
1087 }
1088
1089 DEFUN (no_bgp_confederation_identifier,
1090 no_bgp_confederation_identifier_cmd,
1091 "no bgp confederation identifier [(1-4294967295)]",
1092 NO_STR
1093 "BGP specific commands\n"
1094 "AS confederation parameters\n"
1095 "AS number\n"
1096 "Set routing domain confederation AS\n")
1097 {
1098 VTY_DECLVAR_CONTEXT(bgp, bgp);
1099 bgp_confederation_id_unset(bgp);
1100
1101 return CMD_SUCCESS;
1102 }
1103
1104 DEFUN (bgp_confederation_peers,
1105 bgp_confederation_peers_cmd,
1106 "bgp confederation peers (1-4294967295)...",
1107 "BGP specific commands\n"
1108 "AS confederation parameters\n"
1109 "Peer ASs in BGP confederation\n"
1110 AS_STR)
1111 {
1112 VTY_DECLVAR_CONTEXT(bgp, bgp);
1113 int idx_asn = 3;
1114 as_t as;
1115 int i;
1116
1117 for (i = idx_asn; i < argc; i++) {
1118 as = strtoul(argv[i]->arg, NULL, 10);
1119
1120 if (bgp->as == as) {
1121 vty_out(vty,
1122 "%% Local member-AS not allowed in confed peer list\n");
1123 continue;
1124 }
1125
1126 bgp_confederation_peers_add(bgp, as);
1127 }
1128 return CMD_SUCCESS;
1129 }
1130
1131 DEFUN (no_bgp_confederation_peers,
1132 no_bgp_confederation_peers_cmd,
1133 "no bgp confederation peers (1-4294967295)...",
1134 NO_STR
1135 "BGP specific commands\n"
1136 "AS confederation parameters\n"
1137 "Peer ASs in BGP confederation\n"
1138 AS_STR)
1139 {
1140 VTY_DECLVAR_CONTEXT(bgp, bgp);
1141 int idx_asn = 4;
1142 as_t as;
1143 int i;
1144
1145 for (i = idx_asn; i < argc; i++) {
1146 as = strtoul(argv[i]->arg, NULL, 10);
1147
1148 bgp_confederation_peers_remove(bgp, as);
1149 }
1150 return CMD_SUCCESS;
1151 }
1152
1153 /**
1154 * Central routine for maximum-paths configuration.
1155 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1156 * @set: 1 for setting values, 0 for removing the max-paths config.
1157 */
1158 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1159 const char *mpaths, uint16_t options,
1160 int set)
1161 {
1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
1163 uint16_t maxpaths = 0;
1164 int ret;
1165 afi_t afi;
1166 safi_t safi;
1167
1168 afi = bgp_node_afi(vty);
1169 safi = bgp_node_safi(vty);
1170
1171 if (set) {
1172 maxpaths = strtol(mpaths, NULL, 10);
1173 if (maxpaths > multipath_num) {
1174 vty_out(vty,
1175 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1176 maxpaths, multipath_num);
1177 return CMD_WARNING_CONFIG_FAILED;
1178 }
1179 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1180 options);
1181 } else
1182 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1183
1184 if (ret < 0) {
1185 vty_out(vty,
1186 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1187 (set == 1) ? "" : "un",
1188 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1189 maxpaths, afi, safi);
1190 return CMD_WARNING_CONFIG_FAILED;
1191 }
1192
1193 bgp_recalculate_all_bestpaths(bgp);
1194
1195 return CMD_SUCCESS;
1196 }
1197
1198 DEFUN (bgp_maxmed_admin,
1199 bgp_maxmed_admin_cmd,
1200 "bgp max-med administrative ",
1201 BGP_STR
1202 "Advertise routes with max-med\n"
1203 "Administratively applied, for an indefinite period\n")
1204 {
1205 VTY_DECLVAR_CONTEXT(bgp, bgp);
1206
1207 bgp->v_maxmed_admin = 1;
1208 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1209
1210 bgp_maxmed_update(bgp);
1211
1212 return CMD_SUCCESS;
1213 }
1214
1215 DEFUN (bgp_maxmed_admin_medv,
1216 bgp_maxmed_admin_medv_cmd,
1217 "bgp max-med administrative (0-4294967295)",
1218 BGP_STR
1219 "Advertise routes with max-med\n"
1220 "Administratively applied, for an indefinite period\n"
1221 "Max MED value to be used\n")
1222 {
1223 VTY_DECLVAR_CONTEXT(bgp, bgp);
1224 int idx_number = 3;
1225
1226 bgp->v_maxmed_admin = 1;
1227 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1228
1229 bgp_maxmed_update(bgp);
1230
1231 return CMD_SUCCESS;
1232 }
1233
1234 DEFUN (no_bgp_maxmed_admin,
1235 no_bgp_maxmed_admin_cmd,
1236 "no bgp max-med administrative [(0-4294967295)]",
1237 NO_STR
1238 BGP_STR
1239 "Advertise routes with max-med\n"
1240 "Administratively applied, for an indefinite period\n"
1241 "Max MED value to be used\n")
1242 {
1243 VTY_DECLVAR_CONTEXT(bgp, bgp);
1244 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1245 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1246 bgp_maxmed_update(bgp);
1247
1248 return CMD_SUCCESS;
1249 }
1250
1251 DEFUN (bgp_maxmed_onstartup,
1252 bgp_maxmed_onstartup_cmd,
1253 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1254 BGP_STR
1255 "Advertise routes with max-med\n"
1256 "Effective on a startup\n"
1257 "Time (seconds) period for max-med\n"
1258 "Max MED value to be used\n")
1259 {
1260 VTY_DECLVAR_CONTEXT(bgp, bgp);
1261 int idx = 0;
1262
1263 argv_find(argv, argc, "(5-86400)", &idx);
1264 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1265 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1266 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1267 else
1268 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1269
1270 bgp_maxmed_update(bgp);
1271
1272 return CMD_SUCCESS;
1273 }
1274
1275 DEFUN (no_bgp_maxmed_onstartup,
1276 no_bgp_maxmed_onstartup_cmd,
1277 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1278 NO_STR
1279 BGP_STR
1280 "Advertise routes with max-med\n"
1281 "Effective on a startup\n"
1282 "Time (seconds) period for max-med\n"
1283 "Max MED value to be used\n")
1284 {
1285 VTY_DECLVAR_CONTEXT(bgp, bgp);
1286
1287 /* Cancel max-med onstartup if its on */
1288 if (bgp->t_maxmed_onstartup) {
1289 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1290 bgp->maxmed_onstartup_over = 1;
1291 }
1292
1293 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1294 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1295
1296 bgp_maxmed_update(bgp);
1297
1298 return CMD_SUCCESS;
1299 }
1300
1301 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1302 const char *wait)
1303 {
1304 VTY_DECLVAR_CONTEXT(bgp, bgp);
1305 uint16_t update_delay;
1306 uint16_t establish_wait;
1307
1308 update_delay = strtoul(delay, NULL, 10);
1309
1310 if (!wait) /* update-delay <delay> */
1311 {
1312 bgp->v_update_delay = update_delay;
1313 bgp->v_establish_wait = bgp->v_update_delay;
1314 return CMD_SUCCESS;
1315 }
1316
1317 /* update-delay <delay> <establish-wait> */
1318 establish_wait = atoi(wait);
1319 if (update_delay < establish_wait) {
1320 vty_out(vty,
1321 "%%Failed: update-delay less than the establish-wait!\n");
1322 return CMD_WARNING_CONFIG_FAILED;
1323 }
1324
1325 bgp->v_update_delay = update_delay;
1326 bgp->v_establish_wait = establish_wait;
1327
1328 return CMD_SUCCESS;
1329 }
1330
1331 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1332 {
1333 VTY_DECLVAR_CONTEXT(bgp, bgp);
1334
1335 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1336 bgp->v_establish_wait = bgp->v_update_delay;
1337
1338 return CMD_SUCCESS;
1339 }
1340
1341 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1342 {
1343 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1344 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1345 if (bgp->v_update_delay != bgp->v_establish_wait)
1346 vty_out(vty, " %d", bgp->v_establish_wait);
1347 vty_out(vty, "\n");
1348 }
1349 }
1350
1351
1352 /* Update-delay configuration */
1353 DEFUN (bgp_update_delay,
1354 bgp_update_delay_cmd,
1355 "update-delay (0-3600)",
1356 "Force initial delay for best-path and updates\n"
1357 "Seconds\n")
1358 {
1359 int idx_number = 1;
1360 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1361 }
1362
1363 DEFUN (bgp_update_delay_establish_wait,
1364 bgp_update_delay_establish_wait_cmd,
1365 "update-delay (0-3600) (1-3600)",
1366 "Force initial delay for best-path and updates\n"
1367 "Seconds\n"
1368 "Seconds\n")
1369 {
1370 int idx_number = 1;
1371 int idx_number_2 = 2;
1372 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1373 argv[idx_number_2]->arg);
1374 }
1375
1376 /* Update-delay deconfiguration */
1377 DEFUN (no_bgp_update_delay,
1378 no_bgp_update_delay_cmd,
1379 "no update-delay [(0-3600) [(1-3600)]]",
1380 NO_STR
1381 "Force initial delay for best-path and updates\n"
1382 "Seconds\n"
1383 "Seconds\n")
1384 {
1385 return bgp_update_delay_deconfig_vty(vty);
1386 }
1387
1388
1389 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1390 char set)
1391 {
1392 VTY_DECLVAR_CONTEXT(bgp, bgp);
1393
1394 if (set) {
1395 uint32_t quanta = strtoul(num, NULL, 10);
1396 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1397 memory_order_relaxed);
1398 } else {
1399 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1400 memory_order_relaxed);
1401 }
1402
1403 return CMD_SUCCESS;
1404 }
1405
1406 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1407 char set)
1408 {
1409 VTY_DECLVAR_CONTEXT(bgp, bgp);
1410
1411 if (set) {
1412 uint32_t quanta = strtoul(num, NULL, 10);
1413 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1414 memory_order_relaxed);
1415 } else {
1416 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1417 memory_order_relaxed);
1418 }
1419
1420 return CMD_SUCCESS;
1421 }
1422
1423 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1424 {
1425 uint32_t quanta =
1426 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1427 if (quanta != BGP_WRITE_PACKET_MAX)
1428 vty_out(vty, " write-quanta %d\n", quanta);
1429 }
1430
1431 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1432 {
1433 uint32_t quanta =
1434 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1435 if (quanta != BGP_READ_PACKET_MAX)
1436 vty_out(vty, " read-quanta %d\n", quanta);
1437 }
1438
1439 /* Packet quanta configuration */
1440 DEFUN (bgp_wpkt_quanta,
1441 bgp_wpkt_quanta_cmd,
1442 "write-quanta (1-10)",
1443 "How many packets to write to peer socket per run\n"
1444 "Number of packets\n")
1445 {
1446 int idx_number = 1;
1447 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1448 }
1449
1450 DEFUN (no_bgp_wpkt_quanta,
1451 no_bgp_wpkt_quanta_cmd,
1452 "no write-quanta (1-10)",
1453 NO_STR
1454 "How many packets to write to peer socket per I/O cycle\n"
1455 "Number of packets\n")
1456 {
1457 int idx_number = 2;
1458 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1459 }
1460
1461 DEFUN (bgp_rpkt_quanta,
1462 bgp_rpkt_quanta_cmd,
1463 "read-quanta (1-10)",
1464 "How many packets to read from peer socket per I/O cycle\n"
1465 "Number of packets\n")
1466 {
1467 int idx_number = 1;
1468 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1469 }
1470
1471 DEFUN (no_bgp_rpkt_quanta,
1472 no_bgp_rpkt_quanta_cmd,
1473 "no read-quanta (1-10)",
1474 NO_STR
1475 "How many packets to read from peer socket per I/O cycle\n"
1476 "Number of packets\n")
1477 {
1478 int idx_number = 2;
1479 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1480 }
1481
1482 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1483 {
1484 if (!bgp->heuristic_coalesce)
1485 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1486 }
1487
1488
1489 DEFUN (bgp_coalesce_time,
1490 bgp_coalesce_time_cmd,
1491 "coalesce-time (0-4294967295)",
1492 "Subgroup coalesce timer\n"
1493 "Subgroup coalesce timer value (in ms)\n")
1494 {
1495 VTY_DECLVAR_CONTEXT(bgp, bgp);
1496
1497 int idx = 0;
1498 argv_find(argv, argc, "(0-4294967295)", &idx);
1499 bgp->heuristic_coalesce = false;
1500 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1501 return CMD_SUCCESS;
1502 }
1503
1504 DEFUN (no_bgp_coalesce_time,
1505 no_bgp_coalesce_time_cmd,
1506 "no coalesce-time (0-4294967295)",
1507 NO_STR
1508 "Subgroup coalesce timer\n"
1509 "Subgroup coalesce timer value (in ms)\n")
1510 {
1511 VTY_DECLVAR_CONTEXT(bgp, bgp);
1512
1513 bgp->heuristic_coalesce = true;
1514 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1515 return CMD_SUCCESS;
1516 }
1517
1518 /* Maximum-paths configuration */
1519 DEFUN (bgp_maxpaths,
1520 bgp_maxpaths_cmd,
1521 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1522 "Forward packets over multiple paths\n"
1523 "Number of paths\n")
1524 {
1525 int idx_number = 1;
1526 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1527 argv[idx_number]->arg, 0, 1);
1528 }
1529
1530 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1531 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1532 "Forward packets over multiple paths\n"
1533 "Number of paths\n")
1534
1535 DEFUN (bgp_maxpaths_ibgp,
1536 bgp_maxpaths_ibgp_cmd,
1537 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1538 "Forward packets over multiple paths\n"
1539 "iBGP-multipath\n"
1540 "Number of paths\n")
1541 {
1542 int idx_number = 2;
1543 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1544 argv[idx_number]->arg, 0, 1);
1545 }
1546
1547 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1548 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1549 "Forward packets over multiple paths\n"
1550 "iBGP-multipath\n"
1551 "Number of paths\n")
1552
1553 DEFUN (bgp_maxpaths_ibgp_cluster,
1554 bgp_maxpaths_ibgp_cluster_cmd,
1555 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1556 "Forward packets over multiple paths\n"
1557 "iBGP-multipath\n"
1558 "Number of paths\n"
1559 "Match the cluster length\n")
1560 {
1561 int idx_number = 2;
1562 return bgp_maxpaths_config_vty(
1563 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1564 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1565 }
1566
1567 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1568 "maximum-paths ibgp " CMD_RANGE_STR(
1569 1, MULTIPATH_NUM) " equal-cluster-length",
1570 "Forward packets over multiple paths\n"
1571 "iBGP-multipath\n"
1572 "Number of paths\n"
1573 "Match the cluster length\n")
1574
1575 DEFUN (no_bgp_maxpaths,
1576 no_bgp_maxpaths_cmd,
1577 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1578 NO_STR
1579 "Forward packets over multiple paths\n"
1580 "Number of paths\n")
1581 {
1582 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1583 }
1584
1585 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1586 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1587 "Forward packets over multiple paths\n"
1588 "Number of paths\n")
1589
1590 DEFUN (no_bgp_maxpaths_ibgp,
1591 no_bgp_maxpaths_ibgp_cmd,
1592 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1593 NO_STR
1594 "Forward packets over multiple paths\n"
1595 "iBGP-multipath\n"
1596 "Number of paths\n"
1597 "Match the cluster length\n")
1598 {
1599 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1600 }
1601
1602 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1603 "no maximum-paths ibgp [" CMD_RANGE_STR(
1604 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1605 NO_STR
1606 "Forward packets over multiple paths\n"
1607 "iBGP-multipath\n"
1608 "Number of paths\n"
1609 "Match the cluster length\n")
1610
1611 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1612 safi_t safi)
1613 {
1614 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1615 vty_out(vty, " maximum-paths %d\n",
1616 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1617 }
1618
1619 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1620 vty_out(vty, " maximum-paths ibgp %d",
1621 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1622 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1623 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1624 vty_out(vty, " equal-cluster-length");
1625 vty_out(vty, "\n");
1626 }
1627 }
1628
1629 /* BGP timers. */
1630
1631 DEFUN (bgp_timers,
1632 bgp_timers_cmd,
1633 "timers bgp (0-65535) (0-65535)",
1634 "Adjust routing timers\n"
1635 "BGP timers\n"
1636 "Keepalive interval\n"
1637 "Holdtime\n")
1638 {
1639 VTY_DECLVAR_CONTEXT(bgp, bgp);
1640 int idx_number = 2;
1641 int idx_number_2 = 3;
1642 unsigned long keepalive = 0;
1643 unsigned long holdtime = 0;
1644
1645 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1646 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1647
1648 /* Holdtime value check. */
1649 if (holdtime < 3 && holdtime != 0) {
1650 vty_out(vty,
1651 "%% hold time value must be either 0 or greater than 3\n");
1652 return CMD_WARNING_CONFIG_FAILED;
1653 }
1654
1655 bgp_timers_set(bgp, keepalive, holdtime);
1656
1657 return CMD_SUCCESS;
1658 }
1659
1660 DEFUN (no_bgp_timers,
1661 no_bgp_timers_cmd,
1662 "no timers bgp [(0-65535) (0-65535)]",
1663 NO_STR
1664 "Adjust routing timers\n"
1665 "BGP timers\n"
1666 "Keepalive interval\n"
1667 "Holdtime\n")
1668 {
1669 VTY_DECLVAR_CONTEXT(bgp, bgp);
1670 bgp_timers_unset(bgp);
1671
1672 return CMD_SUCCESS;
1673 }
1674
1675
1676 DEFUN (bgp_client_to_client_reflection,
1677 bgp_client_to_client_reflection_cmd,
1678 "bgp client-to-client reflection",
1679 "BGP specific commands\n"
1680 "Configure client to client route reflection\n"
1681 "reflection of routes allowed\n")
1682 {
1683 VTY_DECLVAR_CONTEXT(bgp, bgp);
1684 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1685 bgp_clear_star_soft_out(vty, bgp->name);
1686
1687 return CMD_SUCCESS;
1688 }
1689
1690 DEFUN (no_bgp_client_to_client_reflection,
1691 no_bgp_client_to_client_reflection_cmd,
1692 "no bgp client-to-client reflection",
1693 NO_STR
1694 "BGP specific commands\n"
1695 "Configure client to client route reflection\n"
1696 "reflection of routes allowed\n")
1697 {
1698 VTY_DECLVAR_CONTEXT(bgp, bgp);
1699 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1700 bgp_clear_star_soft_out(vty, bgp->name);
1701
1702 return CMD_SUCCESS;
1703 }
1704
1705 /* "bgp always-compare-med" configuration. */
1706 DEFUN (bgp_always_compare_med,
1707 bgp_always_compare_med_cmd,
1708 "bgp always-compare-med",
1709 "BGP specific commands\n"
1710 "Allow comparing MED from different neighbors\n")
1711 {
1712 VTY_DECLVAR_CONTEXT(bgp, bgp);
1713 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1714 bgp_recalculate_all_bestpaths(bgp);
1715
1716 return CMD_SUCCESS;
1717 }
1718
1719 DEFUN (no_bgp_always_compare_med,
1720 no_bgp_always_compare_med_cmd,
1721 "no bgp always-compare-med",
1722 NO_STR
1723 "BGP specific commands\n"
1724 "Allow comparing MED from different neighbors\n")
1725 {
1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1728 bgp_recalculate_all_bestpaths(bgp);
1729
1730 return CMD_SUCCESS;
1731 }
1732
1733 /* "bgp deterministic-med" configuration. */
1734 DEFUN (bgp_deterministic_med,
1735 bgp_deterministic_med_cmd,
1736 "bgp deterministic-med",
1737 "BGP specific commands\n"
1738 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1739 {
1740 VTY_DECLVAR_CONTEXT(bgp, bgp);
1741
1742 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1743 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1744 bgp_recalculate_all_bestpaths(bgp);
1745 }
1746
1747 return CMD_SUCCESS;
1748 }
1749
1750 DEFUN (no_bgp_deterministic_med,
1751 no_bgp_deterministic_med_cmd,
1752 "no bgp deterministic-med",
1753 NO_STR
1754 "BGP specific commands\n"
1755 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1756 {
1757 VTY_DECLVAR_CONTEXT(bgp, bgp);
1758 int bestpath_per_as_used;
1759 afi_t afi;
1760 safi_t safi;
1761 struct peer *peer;
1762 struct listnode *node, *nnode;
1763
1764 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1765 bestpath_per_as_used = 0;
1766
1767 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1768 FOREACH_AFI_SAFI (afi, safi)
1769 if (CHECK_FLAG(
1770 peer->af_flags[afi][safi],
1771 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1772 bestpath_per_as_used = 1;
1773 break;
1774 }
1775
1776 if (bestpath_per_as_used)
1777 break;
1778 }
1779
1780 if (bestpath_per_as_used) {
1781 vty_out(vty,
1782 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1783 return CMD_WARNING_CONFIG_FAILED;
1784 } else {
1785 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1786 bgp_recalculate_all_bestpaths(bgp);
1787 }
1788 }
1789
1790 return CMD_SUCCESS;
1791 }
1792
1793 /* "bgp graceful-restart" configuration. */
1794 DEFUN (bgp_graceful_restart,
1795 bgp_graceful_restart_cmd,
1796 "bgp graceful-restart",
1797 "BGP specific commands\n"
1798 "Graceful restart capability parameters\n")
1799 {
1800 VTY_DECLVAR_CONTEXT(bgp, bgp);
1801 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1802 return CMD_SUCCESS;
1803 }
1804
1805 DEFUN (no_bgp_graceful_restart,
1806 no_bgp_graceful_restart_cmd,
1807 "no bgp graceful-restart",
1808 NO_STR
1809 "BGP specific commands\n"
1810 "Graceful restart capability parameters\n")
1811 {
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1814 return CMD_SUCCESS;
1815 }
1816
1817 DEFUN (bgp_graceful_restart_stalepath_time,
1818 bgp_graceful_restart_stalepath_time_cmd,
1819 "bgp graceful-restart stalepath-time (1-3600)",
1820 "BGP specific commands\n"
1821 "Graceful restart capability parameters\n"
1822 "Set the max time to hold onto restarting peer's stale paths\n"
1823 "Delay value (seconds)\n")
1824 {
1825 VTY_DECLVAR_CONTEXT(bgp, bgp);
1826 int idx_number = 3;
1827 uint32_t stalepath;
1828
1829 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1830 bgp->stalepath_time = stalepath;
1831 return CMD_SUCCESS;
1832 }
1833
1834 DEFUN (bgp_graceful_restart_restart_time,
1835 bgp_graceful_restart_restart_time_cmd,
1836 "bgp graceful-restart restart-time (1-3600)",
1837 "BGP specific commands\n"
1838 "Graceful restart capability parameters\n"
1839 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1840 "Delay value (seconds)\n")
1841 {
1842 VTY_DECLVAR_CONTEXT(bgp, bgp);
1843 int idx_number = 3;
1844 uint32_t restart;
1845
1846 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1847 bgp->restart_time = restart;
1848 return CMD_SUCCESS;
1849 }
1850
1851 DEFUN (no_bgp_graceful_restart_stalepath_time,
1852 no_bgp_graceful_restart_stalepath_time_cmd,
1853 "no bgp graceful-restart stalepath-time [(1-3600)]",
1854 NO_STR
1855 "BGP specific commands\n"
1856 "Graceful restart capability parameters\n"
1857 "Set the max time to hold onto restarting peer's stale paths\n"
1858 "Delay value (seconds)\n")
1859 {
1860 VTY_DECLVAR_CONTEXT(bgp, bgp);
1861
1862 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1863 return CMD_SUCCESS;
1864 }
1865
1866 DEFUN (no_bgp_graceful_restart_restart_time,
1867 no_bgp_graceful_restart_restart_time_cmd,
1868 "no bgp graceful-restart restart-time [(1-3600)]",
1869 NO_STR
1870 "BGP specific commands\n"
1871 "Graceful restart capability parameters\n"
1872 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1873 "Delay value (seconds)\n")
1874 {
1875 VTY_DECLVAR_CONTEXT(bgp, bgp);
1876
1877 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1878 return CMD_SUCCESS;
1879 }
1880
1881 DEFUN (bgp_graceful_restart_preserve_fw,
1882 bgp_graceful_restart_preserve_fw_cmd,
1883 "bgp graceful-restart preserve-fw-state",
1884 "BGP specific commands\n"
1885 "Graceful restart capability parameters\n"
1886 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1887 {
1888 VTY_DECLVAR_CONTEXT(bgp, bgp);
1889 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1890 return CMD_SUCCESS;
1891 }
1892
1893 DEFUN (no_bgp_graceful_restart_preserve_fw,
1894 no_bgp_graceful_restart_preserve_fw_cmd,
1895 "no bgp graceful-restart preserve-fw-state",
1896 NO_STR
1897 "BGP specific commands\n"
1898 "Graceful restart capability parameters\n"
1899 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1900 {
1901 VTY_DECLVAR_CONTEXT(bgp, bgp);
1902 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1903 return CMD_SUCCESS;
1904 }
1905
1906 static void bgp_redistribute_redo(struct bgp *bgp)
1907 {
1908 afi_t afi;
1909 int i;
1910 struct list *red_list;
1911 struct listnode *node;
1912 struct bgp_redist *red;
1913
1914 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1915 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1916
1917 red_list = bgp->redist[afi][i];
1918 if (!red_list)
1919 continue;
1920
1921 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1922 bgp_redistribute_resend(bgp, afi, i,
1923 red->instance);
1924 }
1925 }
1926 }
1927 }
1928
1929 /* "bgp graceful-shutdown" configuration */
1930 DEFUN (bgp_graceful_shutdown,
1931 bgp_graceful_shutdown_cmd,
1932 "bgp graceful-shutdown",
1933 BGP_STR
1934 "Graceful shutdown parameters\n")
1935 {
1936 VTY_DECLVAR_CONTEXT(bgp, bgp);
1937
1938 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1939 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1940 bgp_static_redo_import_check(bgp);
1941 bgp_redistribute_redo(bgp);
1942 bgp_clear_star_soft_out(vty, bgp->name);
1943 bgp_clear_star_soft_in(vty, bgp->name);
1944 }
1945
1946 return CMD_SUCCESS;
1947 }
1948
1949 DEFUN (no_bgp_graceful_shutdown,
1950 no_bgp_graceful_shutdown_cmd,
1951 "no bgp graceful-shutdown",
1952 NO_STR
1953 BGP_STR
1954 "Graceful shutdown parameters\n")
1955 {
1956 VTY_DECLVAR_CONTEXT(bgp, bgp);
1957
1958 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1959 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1960 bgp_static_redo_import_check(bgp);
1961 bgp_redistribute_redo(bgp);
1962 bgp_clear_star_soft_out(vty, bgp->name);
1963 bgp_clear_star_soft_in(vty, bgp->name);
1964 }
1965
1966 return CMD_SUCCESS;
1967 }
1968
1969 /* "bgp fast-external-failover" configuration. */
1970 DEFUN (bgp_fast_external_failover,
1971 bgp_fast_external_failover_cmd,
1972 "bgp fast-external-failover",
1973 BGP_STR
1974 "Immediately reset session if a link to a directly connected external peer goes down\n")
1975 {
1976 VTY_DECLVAR_CONTEXT(bgp, bgp);
1977 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1978 return CMD_SUCCESS;
1979 }
1980
1981 DEFUN (no_bgp_fast_external_failover,
1982 no_bgp_fast_external_failover_cmd,
1983 "no bgp fast-external-failover",
1984 NO_STR
1985 BGP_STR
1986 "Immediately reset session if a link to a directly connected external peer goes down\n")
1987 {
1988 VTY_DECLVAR_CONTEXT(bgp, bgp);
1989 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1990 return CMD_SUCCESS;
1991 }
1992
1993 /* "bgp enforce-first-as" configuration. */
1994 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180517
1995 CPP_NOTICE("bgpd: remove deprecated '[no] bgp enforce-first-as' commands")
1996 #endif
1997
1998 DEFUN_DEPRECATED (bgp_enforce_first_as,
1999 bgp_enforce_first_as_cmd,
2000 "bgp enforce-first-as",
2001 BGP_STR
2002 "Enforce the first AS for EBGP routes\n")
2003 {
2004 VTY_DECLVAR_CONTEXT(bgp, bgp);
2005 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2006
2007 return CMD_SUCCESS;
2008 }
2009
2010 DEFUN_DEPRECATED (no_bgp_enforce_first_as,
2011 no_bgp_enforce_first_as_cmd,
2012 "no bgp enforce-first-as",
2013 NO_STR
2014 BGP_STR
2015 "Enforce the first AS for EBGP routes\n")
2016 {
2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
2019
2020 return CMD_SUCCESS;
2021 }
2022
2023 /* "bgp bestpath compare-routerid" configuration. */
2024 DEFUN (bgp_bestpath_compare_router_id,
2025 bgp_bestpath_compare_router_id_cmd,
2026 "bgp bestpath compare-routerid",
2027 "BGP specific commands\n"
2028 "Change the default bestpath selection\n"
2029 "Compare router-id for identical EBGP paths\n")
2030 {
2031 VTY_DECLVAR_CONTEXT(bgp, bgp);
2032 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2033 bgp_recalculate_all_bestpaths(bgp);
2034
2035 return CMD_SUCCESS;
2036 }
2037
2038 DEFUN (no_bgp_bestpath_compare_router_id,
2039 no_bgp_bestpath_compare_router_id_cmd,
2040 "no bgp bestpath compare-routerid",
2041 NO_STR
2042 "BGP specific commands\n"
2043 "Change the default bestpath selection\n"
2044 "Compare router-id for identical EBGP paths\n")
2045 {
2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
2047 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2048 bgp_recalculate_all_bestpaths(bgp);
2049
2050 return CMD_SUCCESS;
2051 }
2052
2053 /* "bgp bestpath as-path ignore" configuration. */
2054 DEFUN (bgp_bestpath_aspath_ignore,
2055 bgp_bestpath_aspath_ignore_cmd,
2056 "bgp bestpath as-path ignore",
2057 "BGP specific commands\n"
2058 "Change the default bestpath selection\n"
2059 "AS-path attribute\n"
2060 "Ignore as-path length in selecting a route\n")
2061 {
2062 VTY_DECLVAR_CONTEXT(bgp, bgp);
2063 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2064 bgp_recalculate_all_bestpaths(bgp);
2065
2066 return CMD_SUCCESS;
2067 }
2068
2069 DEFUN (no_bgp_bestpath_aspath_ignore,
2070 no_bgp_bestpath_aspath_ignore_cmd,
2071 "no bgp bestpath as-path ignore",
2072 NO_STR
2073 "BGP specific commands\n"
2074 "Change the default bestpath selection\n"
2075 "AS-path attribute\n"
2076 "Ignore as-path length in selecting a route\n")
2077 {
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2080 bgp_recalculate_all_bestpaths(bgp);
2081
2082 return CMD_SUCCESS;
2083 }
2084
2085 /* "bgp bestpath as-path confed" configuration. */
2086 DEFUN (bgp_bestpath_aspath_confed,
2087 bgp_bestpath_aspath_confed_cmd,
2088 "bgp bestpath as-path confed",
2089 "BGP specific commands\n"
2090 "Change the default bestpath selection\n"
2091 "AS-path attribute\n"
2092 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2093 {
2094 VTY_DECLVAR_CONTEXT(bgp, bgp);
2095 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2096 bgp_recalculate_all_bestpaths(bgp);
2097
2098 return CMD_SUCCESS;
2099 }
2100
2101 DEFUN (no_bgp_bestpath_aspath_confed,
2102 no_bgp_bestpath_aspath_confed_cmd,
2103 "no bgp bestpath as-path confed",
2104 NO_STR
2105 "BGP specific commands\n"
2106 "Change the default bestpath selection\n"
2107 "AS-path attribute\n"
2108 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2109 {
2110 VTY_DECLVAR_CONTEXT(bgp, bgp);
2111 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2112 bgp_recalculate_all_bestpaths(bgp);
2113
2114 return CMD_SUCCESS;
2115 }
2116
2117 /* "bgp bestpath as-path multipath-relax" configuration. */
2118 DEFUN (bgp_bestpath_aspath_multipath_relax,
2119 bgp_bestpath_aspath_multipath_relax_cmd,
2120 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2121 "BGP specific commands\n"
2122 "Change the default bestpath selection\n"
2123 "AS-path attribute\n"
2124 "Allow load sharing across routes that have different AS paths (but same length)\n"
2125 "Generate an AS_SET\n"
2126 "Do not generate an AS_SET\n")
2127 {
2128 VTY_DECLVAR_CONTEXT(bgp, bgp);
2129 int idx = 0;
2130 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2131
2132 /* no-as-set is now the default behavior so we can silently
2133 * ignore it */
2134 if (argv_find(argv, argc, "as-set", &idx))
2135 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2136 else
2137 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2138
2139 bgp_recalculate_all_bestpaths(bgp);
2140
2141 return CMD_SUCCESS;
2142 }
2143
2144 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2145 no_bgp_bestpath_aspath_multipath_relax_cmd,
2146 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2147 NO_STR
2148 "BGP specific commands\n"
2149 "Change the default bestpath selection\n"
2150 "AS-path attribute\n"
2151 "Allow load sharing across routes that have different AS paths (but same length)\n"
2152 "Generate an AS_SET\n"
2153 "Do not generate an AS_SET\n")
2154 {
2155 VTY_DECLVAR_CONTEXT(bgp, bgp);
2156 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2157 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2158 bgp_recalculate_all_bestpaths(bgp);
2159
2160 return CMD_SUCCESS;
2161 }
2162
2163 /* "bgp log-neighbor-changes" configuration. */
2164 DEFUN (bgp_log_neighbor_changes,
2165 bgp_log_neighbor_changes_cmd,
2166 "bgp log-neighbor-changes",
2167 "BGP specific commands\n"
2168 "Log neighbor up/down and reset reason\n")
2169 {
2170 VTY_DECLVAR_CONTEXT(bgp, bgp);
2171 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2172 return CMD_SUCCESS;
2173 }
2174
2175 DEFUN (no_bgp_log_neighbor_changes,
2176 no_bgp_log_neighbor_changes_cmd,
2177 "no bgp log-neighbor-changes",
2178 NO_STR
2179 "BGP specific commands\n"
2180 "Log neighbor up/down and reset reason\n")
2181 {
2182 VTY_DECLVAR_CONTEXT(bgp, bgp);
2183 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2184 return CMD_SUCCESS;
2185 }
2186
2187 /* "bgp bestpath med" configuration. */
2188 DEFUN (bgp_bestpath_med,
2189 bgp_bestpath_med_cmd,
2190 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2191 "BGP specific commands\n"
2192 "Change the default bestpath selection\n"
2193 "MED attribute\n"
2194 "Compare MED among confederation paths\n"
2195 "Treat missing MED as the least preferred one\n"
2196 "Treat missing MED as the least preferred one\n"
2197 "Compare MED among confederation paths\n")
2198 {
2199 VTY_DECLVAR_CONTEXT(bgp, bgp);
2200
2201 int idx = 0;
2202 if (argv_find(argv, argc, "confed", &idx))
2203 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2204 idx = 0;
2205 if (argv_find(argv, argc, "missing-as-worst", &idx))
2206 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2207
2208 bgp_recalculate_all_bestpaths(bgp);
2209
2210 return CMD_SUCCESS;
2211 }
2212
2213 DEFUN (no_bgp_bestpath_med,
2214 no_bgp_bestpath_med_cmd,
2215 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2216 NO_STR
2217 "BGP specific commands\n"
2218 "Change the default bestpath selection\n"
2219 "MED attribute\n"
2220 "Compare MED among confederation paths\n"
2221 "Treat missing MED as the least preferred one\n"
2222 "Treat missing MED as the least preferred one\n"
2223 "Compare MED among confederation paths\n")
2224 {
2225 VTY_DECLVAR_CONTEXT(bgp, bgp);
2226
2227 int idx = 0;
2228 if (argv_find(argv, argc, "confed", &idx))
2229 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2230 idx = 0;
2231 if (argv_find(argv, argc, "missing-as-worst", &idx))
2232 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2233
2234 bgp_recalculate_all_bestpaths(bgp);
2235
2236 return CMD_SUCCESS;
2237 }
2238
2239 /* "no bgp default ipv4-unicast". */
2240 DEFUN (no_bgp_default_ipv4_unicast,
2241 no_bgp_default_ipv4_unicast_cmd,
2242 "no bgp default ipv4-unicast",
2243 NO_STR
2244 "BGP specific commands\n"
2245 "Configure BGP defaults\n"
2246 "Activate ipv4-unicast for a peer by default\n")
2247 {
2248 VTY_DECLVAR_CONTEXT(bgp, bgp);
2249 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2250 return CMD_SUCCESS;
2251 }
2252
2253 DEFUN (bgp_default_ipv4_unicast,
2254 bgp_default_ipv4_unicast_cmd,
2255 "bgp default ipv4-unicast",
2256 "BGP specific commands\n"
2257 "Configure BGP defaults\n"
2258 "Activate ipv4-unicast for a peer by default\n")
2259 {
2260 VTY_DECLVAR_CONTEXT(bgp, bgp);
2261 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2262 return CMD_SUCCESS;
2263 }
2264
2265 /* Display hostname in certain command outputs */
2266 DEFUN (bgp_default_show_hostname,
2267 bgp_default_show_hostname_cmd,
2268 "bgp default show-hostname",
2269 "BGP specific commands\n"
2270 "Configure BGP defaults\n"
2271 "Show hostname in certain command ouputs\n")
2272 {
2273 VTY_DECLVAR_CONTEXT(bgp, bgp);
2274 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2275 return CMD_SUCCESS;
2276 }
2277
2278 DEFUN (no_bgp_default_show_hostname,
2279 no_bgp_default_show_hostname_cmd,
2280 "no bgp default show-hostname",
2281 NO_STR
2282 "BGP specific commands\n"
2283 "Configure BGP defaults\n"
2284 "Show hostname in certain command ouputs\n")
2285 {
2286 VTY_DECLVAR_CONTEXT(bgp, bgp);
2287 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2288 return CMD_SUCCESS;
2289 }
2290
2291 /* "bgp network import-check" configuration. */
2292 DEFUN (bgp_network_import_check,
2293 bgp_network_import_check_cmd,
2294 "bgp network import-check",
2295 "BGP specific commands\n"
2296 "BGP network command\n"
2297 "Check BGP network route exists in IGP\n")
2298 {
2299 VTY_DECLVAR_CONTEXT(bgp, bgp);
2300 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2301 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2302 bgp_static_redo_import_check(bgp);
2303 }
2304
2305 return CMD_SUCCESS;
2306 }
2307
2308 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2309 "bgp network import-check exact",
2310 "BGP specific commands\n"
2311 "BGP network command\n"
2312 "Check BGP network route exists in IGP\n"
2313 "Match route precisely\n")
2314
2315 DEFUN (no_bgp_network_import_check,
2316 no_bgp_network_import_check_cmd,
2317 "no bgp network import-check",
2318 NO_STR
2319 "BGP specific commands\n"
2320 "BGP network command\n"
2321 "Check BGP network route exists in IGP\n")
2322 {
2323 VTY_DECLVAR_CONTEXT(bgp, bgp);
2324 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2325 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2326 bgp_static_redo_import_check(bgp);
2327 }
2328
2329 return CMD_SUCCESS;
2330 }
2331
2332 DEFUN (bgp_default_local_preference,
2333 bgp_default_local_preference_cmd,
2334 "bgp default local-preference (0-4294967295)",
2335 "BGP specific commands\n"
2336 "Configure BGP defaults\n"
2337 "local preference (higher=more preferred)\n"
2338 "Configure default local preference value\n")
2339 {
2340 VTY_DECLVAR_CONTEXT(bgp, bgp);
2341 int idx_number = 3;
2342 uint32_t local_pref;
2343
2344 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2345
2346 bgp_default_local_preference_set(bgp, local_pref);
2347 bgp_clear_star_soft_in(vty, bgp->name);
2348
2349 return CMD_SUCCESS;
2350 }
2351
2352 DEFUN (no_bgp_default_local_preference,
2353 no_bgp_default_local_preference_cmd,
2354 "no bgp default local-preference [(0-4294967295)]",
2355 NO_STR
2356 "BGP specific commands\n"
2357 "Configure BGP defaults\n"
2358 "local preference (higher=more preferred)\n"
2359 "Configure default local preference value\n")
2360 {
2361 VTY_DECLVAR_CONTEXT(bgp, bgp);
2362 bgp_default_local_preference_unset(bgp);
2363 bgp_clear_star_soft_in(vty, bgp->name);
2364
2365 return CMD_SUCCESS;
2366 }
2367
2368
2369 DEFUN (bgp_default_subgroup_pkt_queue_max,
2370 bgp_default_subgroup_pkt_queue_max_cmd,
2371 "bgp default subgroup-pkt-queue-max (20-100)",
2372 "BGP specific commands\n"
2373 "Configure BGP defaults\n"
2374 "subgroup-pkt-queue-max\n"
2375 "Configure subgroup packet queue max\n")
2376 {
2377 VTY_DECLVAR_CONTEXT(bgp, bgp);
2378 int idx_number = 3;
2379 uint32_t max_size;
2380
2381 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2382
2383 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2384
2385 return CMD_SUCCESS;
2386 }
2387
2388 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2389 no_bgp_default_subgroup_pkt_queue_max_cmd,
2390 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2391 NO_STR
2392 "BGP specific commands\n"
2393 "Configure BGP defaults\n"
2394 "subgroup-pkt-queue-max\n"
2395 "Configure subgroup packet queue max\n")
2396 {
2397 VTY_DECLVAR_CONTEXT(bgp, bgp);
2398 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2399 return CMD_SUCCESS;
2400 }
2401
2402
2403 DEFUN (bgp_rr_allow_outbound_policy,
2404 bgp_rr_allow_outbound_policy_cmd,
2405 "bgp route-reflector allow-outbound-policy",
2406 "BGP specific commands\n"
2407 "Allow modifications made by out route-map\n"
2408 "on ibgp neighbors\n")
2409 {
2410 VTY_DECLVAR_CONTEXT(bgp, bgp);
2411
2412 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2413 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2414 update_group_announce_rrclients(bgp);
2415 bgp_clear_star_soft_out(vty, bgp->name);
2416 }
2417
2418 return CMD_SUCCESS;
2419 }
2420
2421 DEFUN (no_bgp_rr_allow_outbound_policy,
2422 no_bgp_rr_allow_outbound_policy_cmd,
2423 "no bgp route-reflector allow-outbound-policy",
2424 NO_STR
2425 "BGP specific commands\n"
2426 "Allow modifications made by out route-map\n"
2427 "on ibgp neighbors\n")
2428 {
2429 VTY_DECLVAR_CONTEXT(bgp, bgp);
2430
2431 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2432 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2433 update_group_announce_rrclients(bgp);
2434 bgp_clear_star_soft_out(vty, bgp->name);
2435 }
2436
2437 return CMD_SUCCESS;
2438 }
2439
2440 DEFUN (bgp_listen_limit,
2441 bgp_listen_limit_cmd,
2442 "bgp listen limit (1-5000)",
2443 "BGP specific commands\n"
2444 "Configure BGP defaults\n"
2445 "maximum number of BGP Dynamic Neighbors that can be created\n"
2446 "Configure Dynamic Neighbors listen limit value\n")
2447 {
2448 VTY_DECLVAR_CONTEXT(bgp, bgp);
2449 int idx_number = 3;
2450 int listen_limit;
2451
2452 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2453
2454 bgp_listen_limit_set(bgp, listen_limit);
2455
2456 return CMD_SUCCESS;
2457 }
2458
2459 DEFUN (no_bgp_listen_limit,
2460 no_bgp_listen_limit_cmd,
2461 "no bgp listen limit [(1-5000)]",
2462 "BGP specific commands\n"
2463 "Configure BGP defaults\n"
2464 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2465 "Configure Dynamic Neighbors listen limit value to default\n"
2466 "Configure Dynamic Neighbors listen limit value\n")
2467 {
2468 VTY_DECLVAR_CONTEXT(bgp, bgp);
2469 bgp_listen_limit_unset(bgp);
2470 return CMD_SUCCESS;
2471 }
2472
2473
2474 /*
2475 * Check if this listen range is already configured. Check for exact
2476 * match or overlap based on input.
2477 */
2478 static struct peer_group *listen_range_exists(struct bgp *bgp,
2479 struct prefix *range, int exact)
2480 {
2481 struct listnode *node, *nnode;
2482 struct listnode *node1, *nnode1;
2483 struct peer_group *group;
2484 struct prefix *lr;
2485 afi_t afi;
2486 int match;
2487
2488 afi = family2afi(range->family);
2489 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2490 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2491 lr)) {
2492 if (exact)
2493 match = prefix_same(range, lr);
2494 else
2495 match = (prefix_match(range, lr)
2496 || prefix_match(lr, range));
2497 if (match)
2498 return group;
2499 }
2500 }
2501
2502 return NULL;
2503 }
2504
2505 DEFUN (bgp_listen_range,
2506 bgp_listen_range_cmd,
2507 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2508 "BGP specific commands\n"
2509 "Configure BGP dynamic neighbors listen range\n"
2510 "Configure BGP dynamic neighbors listen range\n"
2511 NEIGHBOR_ADDR_STR
2512 "Member of the peer-group\n"
2513 "Peer-group name\n")
2514 {
2515 VTY_DECLVAR_CONTEXT(bgp, bgp);
2516 struct prefix range;
2517 struct peer_group *group, *existing_group;
2518 afi_t afi;
2519 int ret;
2520 int idx = 0;
2521
2522 argv_find(argv, argc, "A.B.C.D/M", &idx);
2523 argv_find(argv, argc, "X:X::X:X/M", &idx);
2524 char *prefix = argv[idx]->arg;
2525 argv_find(argv, argc, "WORD", &idx);
2526 char *peergroup = argv[idx]->arg;
2527
2528 /* Convert IP prefix string to struct prefix. */
2529 ret = str2prefix(prefix, &range);
2530 if (!ret) {
2531 vty_out(vty, "%% Malformed listen range\n");
2532 return CMD_WARNING_CONFIG_FAILED;
2533 }
2534
2535 afi = family2afi(range.family);
2536
2537 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2538 vty_out(vty,
2539 "%% Malformed listen range (link-local address)\n");
2540 return CMD_WARNING_CONFIG_FAILED;
2541 }
2542
2543 apply_mask(&range);
2544
2545 /* Check if same listen range is already configured. */
2546 existing_group = listen_range_exists(bgp, &range, 1);
2547 if (existing_group) {
2548 if (strcmp(existing_group->name, peergroup) == 0)
2549 return CMD_SUCCESS;
2550 else {
2551 vty_out(vty,
2552 "%% Same listen range is attached to peer-group %s\n",
2553 existing_group->name);
2554 return CMD_WARNING_CONFIG_FAILED;
2555 }
2556 }
2557
2558 /* Check if an overlapping listen range exists. */
2559 if (listen_range_exists(bgp, &range, 0)) {
2560 vty_out(vty,
2561 "%% Listen range overlaps with existing listen range\n");
2562 return CMD_WARNING_CONFIG_FAILED;
2563 }
2564
2565 group = peer_group_lookup(bgp, peergroup);
2566 if (!group) {
2567 vty_out(vty, "%% Configure the peer-group first\n");
2568 return CMD_WARNING_CONFIG_FAILED;
2569 }
2570
2571 ret = peer_group_listen_range_add(group, &range);
2572 return bgp_vty_return(vty, ret);
2573 }
2574
2575 DEFUN (no_bgp_listen_range,
2576 no_bgp_listen_range_cmd,
2577 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2578 NO_STR
2579 "BGP specific commands\n"
2580 "Unconfigure BGP dynamic neighbors listen range\n"
2581 "Unconfigure BGP dynamic neighbors listen range\n"
2582 NEIGHBOR_ADDR_STR
2583 "Member of the peer-group\n"
2584 "Peer-group name\n")
2585 {
2586 VTY_DECLVAR_CONTEXT(bgp, bgp);
2587 struct prefix range;
2588 struct peer_group *group;
2589 afi_t afi;
2590 int ret;
2591 int idx = 0;
2592
2593 argv_find(argv, argc, "A.B.C.D/M", &idx);
2594 argv_find(argv, argc, "X:X::X:X/M", &idx);
2595 char *prefix = argv[idx]->arg;
2596 argv_find(argv, argc, "WORD", &idx);
2597 char *peergroup = argv[idx]->arg;
2598
2599 /* Convert IP prefix string to struct prefix. */
2600 ret = str2prefix(prefix, &range);
2601 if (!ret) {
2602 vty_out(vty, "%% Malformed listen range\n");
2603 return CMD_WARNING_CONFIG_FAILED;
2604 }
2605
2606 afi = family2afi(range.family);
2607
2608 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2609 vty_out(vty,
2610 "%% Malformed listen range (link-local address)\n");
2611 return CMD_WARNING_CONFIG_FAILED;
2612 }
2613
2614 apply_mask(&range);
2615
2616 group = peer_group_lookup(bgp, peergroup);
2617 if (!group) {
2618 vty_out(vty, "%% Peer-group does not exist\n");
2619 return CMD_WARNING_CONFIG_FAILED;
2620 }
2621
2622 ret = peer_group_listen_range_del(group, &range);
2623 return bgp_vty_return(vty, ret);
2624 }
2625
2626 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2627 {
2628 struct peer_group *group;
2629 struct listnode *node, *nnode, *rnode, *nrnode;
2630 struct prefix *range;
2631 afi_t afi;
2632 char buf[PREFIX2STR_BUFFER];
2633
2634 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2635 vty_out(vty, " bgp listen limit %d\n",
2636 bgp->dynamic_neighbors_limit);
2637
2638 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2639 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2640 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2641 nrnode, range)) {
2642 prefix2str(range, buf, sizeof(buf));
2643 vty_out(vty,
2644 " bgp listen range %s peer-group %s\n",
2645 buf, group->name);
2646 }
2647 }
2648 }
2649 }
2650
2651
2652 DEFUN (bgp_disable_connected_route_check,
2653 bgp_disable_connected_route_check_cmd,
2654 "bgp disable-ebgp-connected-route-check",
2655 "BGP specific commands\n"
2656 "Disable checking if nexthop is connected on ebgp sessions\n")
2657 {
2658 VTY_DECLVAR_CONTEXT(bgp, bgp);
2659 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2660 bgp_clear_star_soft_in(vty, bgp->name);
2661
2662 return CMD_SUCCESS;
2663 }
2664
2665 DEFUN (no_bgp_disable_connected_route_check,
2666 no_bgp_disable_connected_route_check_cmd,
2667 "no bgp disable-ebgp-connected-route-check",
2668 NO_STR
2669 "BGP specific commands\n"
2670 "Disable checking if nexthop is connected on ebgp sessions\n")
2671 {
2672 VTY_DECLVAR_CONTEXT(bgp, bgp);
2673 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2674 bgp_clear_star_soft_in(vty, bgp->name);
2675
2676 return CMD_SUCCESS;
2677 }
2678
2679
2680 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2681 const char *as_str, afi_t afi, safi_t safi)
2682 {
2683 VTY_DECLVAR_CONTEXT(bgp, bgp);
2684 int ret;
2685 as_t as;
2686 int as_type = AS_SPECIFIED;
2687 union sockunion su;
2688
2689 if (as_str[0] == 'i') {
2690 as = 0;
2691 as_type = AS_INTERNAL;
2692 } else if (as_str[0] == 'e') {
2693 as = 0;
2694 as_type = AS_EXTERNAL;
2695 } else {
2696 /* Get AS number. */
2697 as = strtoul(as_str, NULL, 10);
2698 }
2699
2700 /* If peer is peer group, call proper function. */
2701 ret = str2sockunion(peer_str, &su);
2702 if (ret < 0) {
2703 /* Check for peer by interface */
2704 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2705 safi);
2706 if (ret < 0) {
2707 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2708 if (ret < 0) {
2709 vty_out(vty,
2710 "%% Create the peer-group or interface first\n");
2711 return CMD_WARNING_CONFIG_FAILED;
2712 }
2713 return CMD_SUCCESS;
2714 }
2715 } else {
2716 if (peer_address_self_check(bgp, &su)) {
2717 vty_out(vty,
2718 "%% Can not configure the local system as neighbor\n");
2719 return CMD_WARNING_CONFIG_FAILED;
2720 }
2721 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2722 }
2723
2724 /* This peer belongs to peer group. */
2725 switch (ret) {
2726 case BGP_ERR_PEER_GROUP_MEMBER:
2727 vty_out(vty,
2728 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2729 as);
2730 return CMD_WARNING_CONFIG_FAILED;
2731 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2732 vty_out(vty,
2733 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2734 as, as_str);
2735 return CMD_WARNING_CONFIG_FAILED;
2736 }
2737 return bgp_vty_return(vty, ret);
2738 }
2739
2740 DEFUN (bgp_default_shutdown,
2741 bgp_default_shutdown_cmd,
2742 "[no] bgp default shutdown",
2743 NO_STR
2744 BGP_STR
2745 "Configure BGP defaults\n"
2746 "Apply administrative shutdown to newly configured peers\n")
2747 {
2748 VTY_DECLVAR_CONTEXT(bgp, bgp);
2749 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2750 return CMD_SUCCESS;
2751 }
2752
2753 DEFUN (neighbor_remote_as,
2754 neighbor_remote_as_cmd,
2755 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2756 NEIGHBOR_STR
2757 NEIGHBOR_ADDR_STR2
2758 "Specify a BGP neighbor\n"
2759 AS_STR
2760 "Internal BGP peer\n"
2761 "External BGP peer\n")
2762 {
2763 int idx_peer = 1;
2764 int idx_remote_as = 3;
2765 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2766 argv[idx_remote_as]->arg, AFI_IP,
2767 SAFI_UNICAST);
2768 }
2769
2770 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2771 afi_t afi, safi_t safi, int v6only,
2772 const char *peer_group_name,
2773 const char *as_str)
2774 {
2775 VTY_DECLVAR_CONTEXT(bgp, bgp);
2776 as_t as = 0;
2777 int as_type = AS_UNSPECIFIED;
2778 struct peer *peer;
2779 struct peer_group *group;
2780 int ret = 0;
2781 union sockunion su;
2782
2783 group = peer_group_lookup(bgp, conf_if);
2784
2785 if (group) {
2786 vty_out(vty, "%% Name conflict with peer-group \n");
2787 return CMD_WARNING_CONFIG_FAILED;
2788 }
2789
2790 if (as_str) {
2791 if (as_str[0] == 'i') {
2792 as_type = AS_INTERNAL;
2793 } else if (as_str[0] == 'e') {
2794 as_type = AS_EXTERNAL;
2795 } else {
2796 /* Get AS number. */
2797 as = strtoul(as_str, NULL, 10);
2798 as_type = AS_SPECIFIED;
2799 }
2800 }
2801
2802 peer = peer_lookup_by_conf_if(bgp, conf_if);
2803 if (peer) {
2804 if (as_str)
2805 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2806 afi, safi);
2807 } else {
2808 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2809 && afi == AFI_IP && safi == SAFI_UNICAST)
2810 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2811 as_type, 0, 0, NULL);
2812 else
2813 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2814 as_type, afi, safi, NULL);
2815
2816 if (!peer) {
2817 vty_out(vty, "%% BGP failed to create peer\n");
2818 return CMD_WARNING_CONFIG_FAILED;
2819 }
2820
2821 if (v6only)
2822 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2823
2824 /* Request zebra to initiate IPv6 RAs on this interface. We do
2825 * this
2826 * any unnumbered peer in order to not worry about run-time
2827 * transitions
2828 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2829 * address
2830 * gets deleted later etc.)
2831 */
2832 if (peer->ifp)
2833 bgp_zebra_initiate_radv(bgp, peer);
2834 }
2835
2836 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2837 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2838 if (v6only)
2839 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2840 else
2841 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2842
2843 /* v6only flag changed. Reset bgp seesion */
2844 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2845 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2846 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2847 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2848 } else
2849 bgp_session_reset(peer);
2850 }
2851
2852 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2853 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2854
2855 if (peer_group_name) {
2856 group = peer_group_lookup(bgp, peer_group_name);
2857 if (!group) {
2858 vty_out(vty, "%% Configure the peer-group first\n");
2859 return CMD_WARNING_CONFIG_FAILED;
2860 }
2861
2862 ret = peer_group_bind(bgp, &su, peer, group, &as);
2863 }
2864
2865 return bgp_vty_return(vty, ret);
2866 }
2867
2868 DEFUN (neighbor_interface_config,
2869 neighbor_interface_config_cmd,
2870 "neighbor WORD interface [peer-group WORD]",
2871 NEIGHBOR_STR
2872 "Interface name or neighbor tag\n"
2873 "Enable BGP on interface\n"
2874 "Member of the peer-group\n"
2875 "Peer-group name\n")
2876 {
2877 int idx_word = 1;
2878 int idx_peer_group_word = 4;
2879
2880 if (argc > idx_peer_group_word)
2881 return peer_conf_interface_get(
2882 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2883 argv[idx_peer_group_word]->arg, NULL);
2884 else
2885 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2886 SAFI_UNICAST, 0, NULL, NULL);
2887 }
2888
2889 DEFUN (neighbor_interface_config_v6only,
2890 neighbor_interface_config_v6only_cmd,
2891 "neighbor WORD interface v6only [peer-group WORD]",
2892 NEIGHBOR_STR
2893 "Interface name or neighbor tag\n"
2894 "Enable BGP on interface\n"
2895 "Enable BGP with v6 link-local only\n"
2896 "Member of the peer-group\n"
2897 "Peer-group name\n")
2898 {
2899 int idx_word = 1;
2900 int idx_peer_group_word = 5;
2901
2902 if (argc > idx_peer_group_word)
2903 return peer_conf_interface_get(
2904 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2905 argv[idx_peer_group_word]->arg, NULL);
2906
2907 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2908 SAFI_UNICAST, 1, NULL, NULL);
2909 }
2910
2911
2912 DEFUN (neighbor_interface_config_remote_as,
2913 neighbor_interface_config_remote_as_cmd,
2914 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2915 NEIGHBOR_STR
2916 "Interface name or neighbor tag\n"
2917 "Enable BGP on interface\n"
2918 "Specify a BGP neighbor\n"
2919 AS_STR
2920 "Internal BGP peer\n"
2921 "External BGP peer\n")
2922 {
2923 int idx_word = 1;
2924 int idx_remote_as = 4;
2925 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2926 SAFI_UNICAST, 0, NULL,
2927 argv[idx_remote_as]->arg);
2928 }
2929
2930 DEFUN (neighbor_interface_v6only_config_remote_as,
2931 neighbor_interface_v6only_config_remote_as_cmd,
2932 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2933 NEIGHBOR_STR
2934 "Interface name or neighbor tag\n"
2935 "Enable BGP with v6 link-local only\n"
2936 "Enable BGP on interface\n"
2937 "Specify a BGP neighbor\n"
2938 AS_STR
2939 "Internal BGP peer\n"
2940 "External BGP peer\n")
2941 {
2942 int idx_word = 1;
2943 int idx_remote_as = 5;
2944 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2945 SAFI_UNICAST, 1, NULL,
2946 argv[idx_remote_as]->arg);
2947 }
2948
2949 DEFUN (neighbor_peer_group,
2950 neighbor_peer_group_cmd,
2951 "neighbor WORD peer-group",
2952 NEIGHBOR_STR
2953 "Interface name or neighbor tag\n"
2954 "Configure peer-group\n")
2955 {
2956 VTY_DECLVAR_CONTEXT(bgp, bgp);
2957 int idx_word = 1;
2958 struct peer *peer;
2959 struct peer_group *group;
2960
2961 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2962 if (peer) {
2963 vty_out(vty, "%% Name conflict with interface: \n");
2964 return CMD_WARNING_CONFIG_FAILED;
2965 }
2966
2967 group = peer_group_get(bgp, argv[idx_word]->arg);
2968 if (!group) {
2969 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2970 return CMD_WARNING_CONFIG_FAILED;
2971 }
2972
2973 return CMD_SUCCESS;
2974 }
2975
2976 DEFUN (no_neighbor,
2977 no_neighbor_cmd,
2978 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2979 NO_STR
2980 NEIGHBOR_STR
2981 NEIGHBOR_ADDR_STR2
2982 "Specify a BGP neighbor\n"
2983 AS_STR
2984 "Internal BGP peer\n"
2985 "External BGP peer\n")
2986 {
2987 VTY_DECLVAR_CONTEXT(bgp, bgp);
2988 int idx_peer = 2;
2989 int ret;
2990 union sockunion su;
2991 struct peer_group *group;
2992 struct peer *peer;
2993 struct peer *other;
2994
2995 ret = str2sockunion(argv[idx_peer]->arg, &su);
2996 if (ret < 0) {
2997 /* look up for neighbor by interface name config. */
2998 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2999 if (peer) {
3000 /* Request zebra to terminate IPv6 RAs on this
3001 * interface. */
3002 if (peer->ifp)
3003 bgp_zebra_terminate_radv(peer->bgp, peer);
3004 peer_delete(peer);
3005 return CMD_SUCCESS;
3006 }
3007
3008 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
3009 if (group)
3010 peer_group_delete(group);
3011 else {
3012 vty_out(vty, "%% Create the peer-group first\n");
3013 return CMD_WARNING_CONFIG_FAILED;
3014 }
3015 } else {
3016 peer = peer_lookup(bgp, &su);
3017 if (peer) {
3018 if (peer_dynamic_neighbor(peer)) {
3019 vty_out(vty,
3020 "%% Operation not allowed on a dynamic neighbor\n");
3021 return CMD_WARNING_CONFIG_FAILED;
3022 }
3023
3024 other = peer->doppelganger;
3025 peer_delete(peer);
3026 if (other && other->status != Deleted)
3027 peer_delete(other);
3028 }
3029 }
3030
3031 return CMD_SUCCESS;
3032 }
3033
3034 DEFUN (no_neighbor_interface_config,
3035 no_neighbor_interface_config_cmd,
3036 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3037 NO_STR
3038 NEIGHBOR_STR
3039 "Interface name\n"
3040 "Configure BGP on interface\n"
3041 "Enable BGP with v6 link-local only\n"
3042 "Member of the peer-group\n"
3043 "Peer-group name\n"
3044 "Specify a BGP neighbor\n"
3045 AS_STR
3046 "Internal BGP peer\n"
3047 "External BGP peer\n")
3048 {
3049 VTY_DECLVAR_CONTEXT(bgp, bgp);
3050 int idx_word = 2;
3051 struct peer *peer;
3052
3053 /* look up for neighbor by interface name config. */
3054 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3055 if (peer) {
3056 /* Request zebra to terminate IPv6 RAs on this interface. */
3057 if (peer->ifp)
3058 bgp_zebra_terminate_radv(peer->bgp, peer);
3059 peer_delete(peer);
3060 } else {
3061 vty_out(vty, "%% Create the bgp interface first\n");
3062 return CMD_WARNING_CONFIG_FAILED;
3063 }
3064 return CMD_SUCCESS;
3065 }
3066
3067 DEFUN (no_neighbor_peer_group,
3068 no_neighbor_peer_group_cmd,
3069 "no neighbor WORD peer-group",
3070 NO_STR
3071 NEIGHBOR_STR
3072 "Neighbor tag\n"
3073 "Configure peer-group\n")
3074 {
3075 VTY_DECLVAR_CONTEXT(bgp, bgp);
3076 int idx_word = 2;
3077 struct peer_group *group;
3078
3079 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3080 if (group)
3081 peer_group_delete(group);
3082 else {
3083 vty_out(vty, "%% Create the peer-group first\n");
3084 return CMD_WARNING_CONFIG_FAILED;
3085 }
3086 return CMD_SUCCESS;
3087 }
3088
3089 DEFUN (no_neighbor_interface_peer_group_remote_as,
3090 no_neighbor_interface_peer_group_remote_as_cmd,
3091 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3092 NO_STR
3093 NEIGHBOR_STR
3094 "Interface name or neighbor tag\n"
3095 "Specify a BGP neighbor\n"
3096 AS_STR
3097 "Internal BGP peer\n"
3098 "External BGP peer\n")
3099 {
3100 VTY_DECLVAR_CONTEXT(bgp, bgp);
3101 int idx_word = 2;
3102 struct peer_group *group;
3103 struct peer *peer;
3104
3105 /* look up for neighbor by interface name config. */
3106 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3107 if (peer) {
3108 peer_as_change(peer, 0, AS_SPECIFIED);
3109 return CMD_SUCCESS;
3110 }
3111
3112 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3113 if (group)
3114 peer_group_remote_as_delete(group);
3115 else {
3116 vty_out(vty, "%% Create the peer-group or interface first\n");
3117 return CMD_WARNING_CONFIG_FAILED;
3118 }
3119 return CMD_SUCCESS;
3120 }
3121
3122 DEFUN (neighbor_local_as,
3123 neighbor_local_as_cmd,
3124 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3125 NEIGHBOR_STR
3126 NEIGHBOR_ADDR_STR2
3127 "Specify a local-as number\n"
3128 "AS number used as local AS\n")
3129 {
3130 int idx_peer = 1;
3131 int idx_number = 3;
3132 struct peer *peer;
3133 int ret;
3134 as_t as;
3135
3136 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3137 if (!peer)
3138 return CMD_WARNING_CONFIG_FAILED;
3139
3140 as = strtoul(argv[idx_number]->arg, NULL, 10);
3141 ret = peer_local_as_set(peer, as, 0, 0);
3142 return bgp_vty_return(vty, ret);
3143 }
3144
3145 DEFUN (neighbor_local_as_no_prepend,
3146 neighbor_local_as_no_prepend_cmd,
3147 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3148 NEIGHBOR_STR
3149 NEIGHBOR_ADDR_STR2
3150 "Specify a local-as number\n"
3151 "AS number used as local AS\n"
3152 "Do not prepend local-as to updates from ebgp peers\n")
3153 {
3154 int idx_peer = 1;
3155 int idx_number = 3;
3156 struct peer *peer;
3157 int ret;
3158 as_t as;
3159
3160 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3161 if (!peer)
3162 return CMD_WARNING_CONFIG_FAILED;
3163
3164 as = strtoul(argv[idx_number]->arg, NULL, 10);
3165 ret = peer_local_as_set(peer, as, 1, 0);
3166 return bgp_vty_return(vty, ret);
3167 }
3168
3169 DEFUN (neighbor_local_as_no_prepend_replace_as,
3170 neighbor_local_as_no_prepend_replace_as_cmd,
3171 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3172 NEIGHBOR_STR
3173 NEIGHBOR_ADDR_STR2
3174 "Specify a local-as number\n"
3175 "AS number used as local AS\n"
3176 "Do not prepend local-as to updates from ebgp peers\n"
3177 "Do not prepend local-as to updates from ibgp peers\n")
3178 {
3179 int idx_peer = 1;
3180 int idx_number = 3;
3181 struct peer *peer;
3182 int ret;
3183 as_t as;
3184
3185 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3186 if (!peer)
3187 return CMD_WARNING_CONFIG_FAILED;
3188
3189 as = strtoul(argv[idx_number]->arg, NULL, 10);
3190 ret = peer_local_as_set(peer, as, 1, 1);
3191 return bgp_vty_return(vty, ret);
3192 }
3193
3194 DEFUN (no_neighbor_local_as,
3195 no_neighbor_local_as_cmd,
3196 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3197 NO_STR
3198 NEIGHBOR_STR
3199 NEIGHBOR_ADDR_STR2
3200 "Specify a local-as number\n"
3201 "AS number used as local AS\n"
3202 "Do not prepend local-as to updates from ebgp peers\n"
3203 "Do not prepend local-as to updates from ibgp peers\n")
3204 {
3205 int idx_peer = 2;
3206 struct peer *peer;
3207 int ret;
3208
3209 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3210 if (!peer)
3211 return CMD_WARNING_CONFIG_FAILED;
3212
3213 ret = peer_local_as_unset(peer);
3214 return bgp_vty_return(vty, ret);
3215 }
3216
3217
3218 DEFUN (neighbor_solo,
3219 neighbor_solo_cmd,
3220 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3221 NEIGHBOR_STR
3222 NEIGHBOR_ADDR_STR2
3223 "Solo peer - part of its own update group\n")
3224 {
3225 int idx_peer = 1;
3226 struct peer *peer;
3227 int ret;
3228
3229 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3230 if (!peer)
3231 return CMD_WARNING_CONFIG_FAILED;
3232
3233 ret = update_group_adjust_soloness(peer, 1);
3234 return bgp_vty_return(vty, ret);
3235 }
3236
3237 DEFUN (no_neighbor_solo,
3238 no_neighbor_solo_cmd,
3239 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3240 NO_STR
3241 NEIGHBOR_STR
3242 NEIGHBOR_ADDR_STR2
3243 "Solo peer - part of its own update group\n")
3244 {
3245 int idx_peer = 2;
3246 struct peer *peer;
3247 int ret;
3248
3249 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3250 if (!peer)
3251 return CMD_WARNING_CONFIG_FAILED;
3252
3253 ret = update_group_adjust_soloness(peer, 0);
3254 return bgp_vty_return(vty, ret);
3255 }
3256
3257 DEFUN (neighbor_password,
3258 neighbor_password_cmd,
3259 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3260 NEIGHBOR_STR
3261 NEIGHBOR_ADDR_STR2
3262 "Set a password\n"
3263 "The password\n")
3264 {
3265 int idx_peer = 1;
3266 int idx_line = 3;
3267 struct peer *peer;
3268 int ret;
3269
3270 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3271 if (!peer)
3272 return CMD_WARNING_CONFIG_FAILED;
3273
3274 ret = peer_password_set(peer, argv[idx_line]->arg);
3275 return bgp_vty_return(vty, ret);
3276 }
3277
3278 DEFUN (no_neighbor_password,
3279 no_neighbor_password_cmd,
3280 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3281 NO_STR
3282 NEIGHBOR_STR
3283 NEIGHBOR_ADDR_STR2
3284 "Set a password\n"
3285 "The password\n")
3286 {
3287 int idx_peer = 2;
3288 struct peer *peer;
3289 int ret;
3290
3291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3292 if (!peer)
3293 return CMD_WARNING_CONFIG_FAILED;
3294
3295 ret = peer_password_unset(peer);
3296 return bgp_vty_return(vty, ret);
3297 }
3298
3299 DEFUN (neighbor_activate,
3300 neighbor_activate_cmd,
3301 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3302 NEIGHBOR_STR
3303 NEIGHBOR_ADDR_STR2
3304 "Enable the Address Family for this Neighbor\n")
3305 {
3306 int idx_peer = 1;
3307 int ret;
3308 struct peer *peer;
3309
3310 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3311 if (!peer)
3312 return CMD_WARNING_CONFIG_FAILED;
3313
3314 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3315 return bgp_vty_return(vty, ret);
3316 }
3317
3318 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3319 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3321 "Enable the Address Family for this Neighbor\n")
3322
3323 DEFUN (no_neighbor_activate,
3324 no_neighbor_activate_cmd,
3325 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3326 NO_STR
3327 NEIGHBOR_STR
3328 NEIGHBOR_ADDR_STR2
3329 "Enable the Address Family for this Neighbor\n")
3330 {
3331 int idx_peer = 2;
3332 int ret;
3333 struct peer *peer;
3334
3335 /* Lookup peer. */
3336 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3337 if (!peer)
3338 return CMD_WARNING_CONFIG_FAILED;
3339
3340 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3341 return bgp_vty_return(vty, ret);
3342 }
3343
3344 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3345 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3346 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3347 "Enable the Address Family for this Neighbor\n")
3348
3349 DEFUN (neighbor_set_peer_group,
3350 neighbor_set_peer_group_cmd,
3351 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3352 NEIGHBOR_STR
3353 NEIGHBOR_ADDR_STR2
3354 "Member of the peer-group\n"
3355 "Peer-group name\n")
3356 {
3357 VTY_DECLVAR_CONTEXT(bgp, bgp);
3358 int idx_peer = 1;
3359 int idx_word = 3;
3360 int ret;
3361 as_t as;
3362 union sockunion su;
3363 struct peer *peer;
3364 struct peer_group *group;
3365
3366 peer = NULL;
3367
3368 ret = str2sockunion(argv[idx_peer]->arg, &su);
3369 if (ret < 0) {
3370 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3371 if (!peer) {
3372 vty_out(vty, "%% Malformed address or name: %s\n",
3373 argv[idx_peer]->arg);
3374 return CMD_WARNING_CONFIG_FAILED;
3375 }
3376 } else {
3377 if (peer_address_self_check(bgp, &su)) {
3378 vty_out(vty,
3379 "%% Can not configure the local system as neighbor\n");
3380 return CMD_WARNING_CONFIG_FAILED;
3381 }
3382
3383 /* Disallow for dynamic neighbor. */
3384 peer = peer_lookup(bgp, &su);
3385 if (peer && peer_dynamic_neighbor(peer)) {
3386 vty_out(vty,
3387 "%% Operation not allowed on a dynamic neighbor\n");
3388 return CMD_WARNING_CONFIG_FAILED;
3389 }
3390 }
3391
3392 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3393 if (!group) {
3394 vty_out(vty, "%% Configure the peer-group first\n");
3395 return CMD_WARNING_CONFIG_FAILED;
3396 }
3397
3398 ret = peer_group_bind(bgp, &su, peer, group, &as);
3399
3400 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3401 vty_out(vty,
3402 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3403 as);
3404 return CMD_WARNING_CONFIG_FAILED;
3405 }
3406
3407 return bgp_vty_return(vty, ret);
3408 }
3409
3410 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3411 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3412 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3413 "Member of the peer-group\n"
3414 "Peer-group name\n")
3415
3416 DEFUN (no_neighbor_set_peer_group,
3417 no_neighbor_set_peer_group_cmd,
3418 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3419 NO_STR
3420 NEIGHBOR_STR
3421 NEIGHBOR_ADDR_STR2
3422 "Member of the peer-group\n"
3423 "Peer-group name\n")
3424 {
3425 VTY_DECLVAR_CONTEXT(bgp, bgp);
3426 int idx_peer = 2;
3427 int idx_word = 4;
3428 int ret;
3429 struct peer *peer;
3430 struct peer_group *group;
3431
3432 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3433 if (!peer)
3434 return CMD_WARNING_CONFIG_FAILED;
3435
3436 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3437 if (!group) {
3438 vty_out(vty, "%% Configure the peer-group first\n");
3439 return CMD_WARNING_CONFIG_FAILED;
3440 }
3441
3442 ret = peer_delete(peer);
3443
3444 return bgp_vty_return(vty, ret);
3445 }
3446
3447 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3448 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3449 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3450 "Member of the peer-group\n"
3451 "Peer-group name\n")
3452
3453 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3454 uint32_t flag, int set)
3455 {
3456 int ret;
3457 struct peer *peer;
3458
3459 peer = peer_and_group_lookup_vty(vty, ip_str);
3460 if (!peer)
3461 return CMD_WARNING_CONFIG_FAILED;
3462
3463 /*
3464 * If 'neighbor <interface>', then this is for directly connected peers,
3465 * we should not accept disable-connected-check.
3466 */
3467 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3468 vty_out(vty,
3469 "%s is directly connected peer, cannot accept disable-"
3470 "connected-check\n",
3471 ip_str);
3472 return CMD_WARNING_CONFIG_FAILED;
3473 }
3474
3475 if (!set && flag == PEER_FLAG_SHUTDOWN)
3476 peer_tx_shutdown_message_unset(peer);
3477
3478 if (set)
3479 ret = peer_flag_set(peer, flag);
3480 else
3481 ret = peer_flag_unset(peer, flag);
3482
3483 return bgp_vty_return(vty, ret);
3484 }
3485
3486 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint32_t flag)
3487 {
3488 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3489 }
3490
3491 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3492 uint32_t flag)
3493 {
3494 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3495 }
3496
3497 /* neighbor passive. */
3498 DEFUN (neighbor_passive,
3499 neighbor_passive_cmd,
3500 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3501 NEIGHBOR_STR
3502 NEIGHBOR_ADDR_STR2
3503 "Don't send open messages to this neighbor\n")
3504 {
3505 int idx_peer = 1;
3506 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3507 }
3508
3509 DEFUN (no_neighbor_passive,
3510 no_neighbor_passive_cmd,
3511 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3512 NO_STR
3513 NEIGHBOR_STR
3514 NEIGHBOR_ADDR_STR2
3515 "Don't send open messages to this neighbor\n")
3516 {
3517 int idx_peer = 2;
3518 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3519 }
3520
3521 /* neighbor shutdown. */
3522 DEFUN (neighbor_shutdown_msg,
3523 neighbor_shutdown_msg_cmd,
3524 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3525 NEIGHBOR_STR
3526 NEIGHBOR_ADDR_STR2
3527 "Administratively shut down this neighbor\n"
3528 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3529 "Shutdown message\n")
3530 {
3531 int idx_peer = 1;
3532
3533 if (argc >= 5) {
3534 struct peer *peer =
3535 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3536 char *message;
3537
3538 if (!peer)
3539 return CMD_WARNING_CONFIG_FAILED;
3540 message = argv_concat(argv, argc, 4);
3541 peer_tx_shutdown_message_set(peer, message);
3542 XFREE(MTYPE_TMP, message);
3543 }
3544
3545 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3546 }
3547
3548 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3549 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3550 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3551 "Administratively shut down this neighbor\n")
3552
3553 DEFUN (no_neighbor_shutdown_msg,
3554 no_neighbor_shutdown_msg_cmd,
3555 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3556 NO_STR
3557 NEIGHBOR_STR
3558 NEIGHBOR_ADDR_STR2
3559 "Administratively shut down this neighbor\n"
3560 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3561 "Shutdown message\n")
3562 {
3563 int idx_peer = 2;
3564
3565 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3566 PEER_FLAG_SHUTDOWN);
3567 }
3568
3569 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3570 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3571 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3572 "Administratively shut down this neighbor\n")
3573
3574 /* neighbor capability dynamic. */
3575 DEFUN (neighbor_capability_dynamic,
3576 neighbor_capability_dynamic_cmd,
3577 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3578 NEIGHBOR_STR
3579 NEIGHBOR_ADDR_STR2
3580 "Advertise capability to the peer\n"
3581 "Advertise dynamic capability to this neighbor\n")
3582 {
3583 int idx_peer = 1;
3584 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3585 PEER_FLAG_DYNAMIC_CAPABILITY);
3586 }
3587
3588 DEFUN (no_neighbor_capability_dynamic,
3589 no_neighbor_capability_dynamic_cmd,
3590 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3591 NO_STR
3592 NEIGHBOR_STR
3593 NEIGHBOR_ADDR_STR2
3594 "Advertise capability to the peer\n"
3595 "Advertise dynamic capability to this neighbor\n")
3596 {
3597 int idx_peer = 2;
3598 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3599 PEER_FLAG_DYNAMIC_CAPABILITY);
3600 }
3601
3602 /* neighbor dont-capability-negotiate */
3603 DEFUN (neighbor_dont_capability_negotiate,
3604 neighbor_dont_capability_negotiate_cmd,
3605 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3606 NEIGHBOR_STR
3607 NEIGHBOR_ADDR_STR2
3608 "Do not perform capability negotiation\n")
3609 {
3610 int idx_peer = 1;
3611 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3612 PEER_FLAG_DONT_CAPABILITY);
3613 }
3614
3615 DEFUN (no_neighbor_dont_capability_negotiate,
3616 no_neighbor_dont_capability_negotiate_cmd,
3617 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3618 NO_STR
3619 NEIGHBOR_STR
3620 NEIGHBOR_ADDR_STR2
3621 "Do not perform capability negotiation\n")
3622 {
3623 int idx_peer = 2;
3624 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3625 PEER_FLAG_DONT_CAPABILITY);
3626 }
3627
3628 /* neighbor capability extended next hop encoding */
3629 DEFUN (neighbor_capability_enhe,
3630 neighbor_capability_enhe_cmd,
3631 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3632 NEIGHBOR_STR
3633 NEIGHBOR_ADDR_STR2
3634 "Advertise capability to the peer\n"
3635 "Advertise extended next-hop capability to the peer\n")
3636 {
3637 int idx_peer = 1;
3638 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3639 PEER_FLAG_CAPABILITY_ENHE);
3640 }
3641
3642 DEFUN (no_neighbor_capability_enhe,
3643 no_neighbor_capability_enhe_cmd,
3644 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3645 NO_STR
3646 NEIGHBOR_STR
3647 NEIGHBOR_ADDR_STR2
3648 "Advertise capability to the peer\n"
3649 "Advertise extended next-hop capability to the peer\n")
3650 {
3651 int idx_peer = 2;
3652 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3653 PEER_FLAG_CAPABILITY_ENHE);
3654 }
3655
3656 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3657 afi_t afi, safi_t safi, uint32_t flag,
3658 int set)
3659 {
3660 int ret;
3661 struct peer *peer;
3662
3663 peer = peer_and_group_lookup_vty(vty, peer_str);
3664 if (!peer)
3665 return CMD_WARNING_CONFIG_FAILED;
3666
3667 if (set)
3668 ret = peer_af_flag_set(peer, afi, safi, flag);
3669 else
3670 ret = peer_af_flag_unset(peer, afi, safi, flag);
3671
3672 return bgp_vty_return(vty, ret);
3673 }
3674
3675 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3676 afi_t afi, safi_t safi, uint32_t flag)
3677 {
3678 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3679 }
3680
3681 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3682 afi_t afi, safi_t safi, uint32_t flag)
3683 {
3684 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3685 }
3686
3687 /* neighbor capability orf prefix-list. */
3688 DEFUN (neighbor_capability_orf_prefix,
3689 neighbor_capability_orf_prefix_cmd,
3690 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3691 NEIGHBOR_STR
3692 NEIGHBOR_ADDR_STR2
3693 "Advertise capability to the peer\n"
3694 "Advertise ORF capability to the peer\n"
3695 "Advertise prefixlist ORF capability to this neighbor\n"
3696 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3697 "Capability to RECEIVE the ORF from this neighbor\n"
3698 "Capability to SEND the ORF to this neighbor\n")
3699 {
3700 int idx_peer = 1;
3701 int idx_send_recv = 5;
3702 uint16_t flag = 0;
3703
3704 if (strmatch(argv[idx_send_recv]->text, "send"))
3705 flag = PEER_FLAG_ORF_PREFIX_SM;
3706 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3707 flag = PEER_FLAG_ORF_PREFIX_RM;
3708 else if (strmatch(argv[idx_send_recv]->text, "both"))
3709 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3710 else {
3711 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3712 return CMD_WARNING_CONFIG_FAILED;
3713 }
3714
3715 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3716 bgp_node_safi(vty), flag);
3717 }
3718
3719 ALIAS_HIDDEN(
3720 neighbor_capability_orf_prefix,
3721 neighbor_capability_orf_prefix_hidden_cmd,
3722 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3723 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3724 "Advertise capability to the peer\n"
3725 "Advertise ORF capability to the peer\n"
3726 "Advertise prefixlist ORF capability to this neighbor\n"
3727 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3728 "Capability to RECEIVE the ORF from this neighbor\n"
3729 "Capability to SEND the ORF to this neighbor\n")
3730
3731 DEFUN (no_neighbor_capability_orf_prefix,
3732 no_neighbor_capability_orf_prefix_cmd,
3733 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3734 NO_STR
3735 NEIGHBOR_STR
3736 NEIGHBOR_ADDR_STR2
3737 "Advertise capability to the peer\n"
3738 "Advertise ORF capability to the peer\n"
3739 "Advertise prefixlist ORF capability to this neighbor\n"
3740 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3741 "Capability to RECEIVE the ORF from this neighbor\n"
3742 "Capability to SEND the ORF to this neighbor\n")
3743 {
3744 int idx_peer = 2;
3745 int idx_send_recv = 6;
3746 uint16_t flag = 0;
3747
3748 if (strmatch(argv[idx_send_recv]->text, "send"))
3749 flag = PEER_FLAG_ORF_PREFIX_SM;
3750 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3751 flag = PEER_FLAG_ORF_PREFIX_RM;
3752 else if (strmatch(argv[idx_send_recv]->text, "both"))
3753 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3754 else {
3755 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3756 return CMD_WARNING_CONFIG_FAILED;
3757 }
3758
3759 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3760 bgp_node_afi(vty), bgp_node_safi(vty),
3761 flag);
3762 }
3763
3764 ALIAS_HIDDEN(
3765 no_neighbor_capability_orf_prefix,
3766 no_neighbor_capability_orf_prefix_hidden_cmd,
3767 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3768 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3769 "Advertise capability to the peer\n"
3770 "Advertise ORF capability to the peer\n"
3771 "Advertise prefixlist ORF capability to this neighbor\n"
3772 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3773 "Capability to RECEIVE the ORF from this neighbor\n"
3774 "Capability to SEND the ORF to this neighbor\n")
3775
3776 /* neighbor next-hop-self. */
3777 DEFUN (neighbor_nexthop_self,
3778 neighbor_nexthop_self_cmd,
3779 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3780 NEIGHBOR_STR
3781 NEIGHBOR_ADDR_STR2
3782 "Disable the next hop calculation for this neighbor\n")
3783 {
3784 int idx_peer = 1;
3785 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3786 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3787 }
3788
3789 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3790 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3791 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3792 "Disable the next hop calculation for this neighbor\n")
3793
3794 /* neighbor next-hop-self. */
3795 DEFUN (neighbor_nexthop_self_force,
3796 neighbor_nexthop_self_force_cmd,
3797 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3798 NEIGHBOR_STR
3799 NEIGHBOR_ADDR_STR2
3800 "Disable the next hop calculation for this neighbor\n"
3801 "Set the next hop to self for reflected routes\n")
3802 {
3803 int idx_peer = 1;
3804 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3805 bgp_node_safi(vty),
3806 PEER_FLAG_FORCE_NEXTHOP_SELF);
3807 }
3808
3809 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3810 neighbor_nexthop_self_force_hidden_cmd,
3811 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3813 "Disable the next hop calculation for this neighbor\n"
3814 "Set the next hop to self for reflected routes\n")
3815
3816 DEFUN (no_neighbor_nexthop_self,
3817 no_neighbor_nexthop_self_cmd,
3818 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3819 NO_STR
3820 NEIGHBOR_STR
3821 NEIGHBOR_ADDR_STR2
3822 "Disable the next hop calculation for this neighbor\n")
3823 {
3824 int idx_peer = 2;
3825 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3826 bgp_node_afi(vty), bgp_node_safi(vty),
3827 PEER_FLAG_NEXTHOP_SELF);
3828 }
3829
3830 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3831 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3832 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3833 "Disable the next hop calculation for this neighbor\n")
3834
3835 DEFUN (no_neighbor_nexthop_self_force,
3836 no_neighbor_nexthop_self_force_cmd,
3837 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3838 NO_STR
3839 NEIGHBOR_STR
3840 NEIGHBOR_ADDR_STR2
3841 "Disable the next hop calculation for this neighbor\n"
3842 "Set the next hop to self for reflected routes\n")
3843 {
3844 int idx_peer = 2;
3845 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3846 bgp_node_afi(vty), bgp_node_safi(vty),
3847 PEER_FLAG_FORCE_NEXTHOP_SELF);
3848 }
3849
3850 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3851 no_neighbor_nexthop_self_force_hidden_cmd,
3852 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3853 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3854 "Disable the next hop calculation for this neighbor\n"
3855 "Set the next hop to self for reflected routes\n")
3856
3857 /* neighbor as-override */
3858 DEFUN (neighbor_as_override,
3859 neighbor_as_override_cmd,
3860 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3861 NEIGHBOR_STR
3862 NEIGHBOR_ADDR_STR2
3863 "Override ASNs in outbound updates if aspath equals remote-as\n")
3864 {
3865 int idx_peer = 1;
3866 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3867 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3868 }
3869
3870 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3871 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3872 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3873 "Override ASNs in outbound updates if aspath equals remote-as\n")
3874
3875 DEFUN (no_neighbor_as_override,
3876 no_neighbor_as_override_cmd,
3877 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3878 NO_STR
3879 NEIGHBOR_STR
3880 NEIGHBOR_ADDR_STR2
3881 "Override ASNs in outbound updates if aspath equals remote-as\n")
3882 {
3883 int idx_peer = 2;
3884 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3885 bgp_node_afi(vty), bgp_node_safi(vty),
3886 PEER_FLAG_AS_OVERRIDE);
3887 }
3888
3889 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3890 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3891 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3892 "Override ASNs in outbound updates if aspath equals remote-as\n")
3893
3894 /* neighbor remove-private-AS. */
3895 DEFUN (neighbor_remove_private_as,
3896 neighbor_remove_private_as_cmd,
3897 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3898 NEIGHBOR_STR
3899 NEIGHBOR_ADDR_STR2
3900 "Remove private ASNs in outbound updates\n")
3901 {
3902 int idx_peer = 1;
3903 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3904 bgp_node_safi(vty),
3905 PEER_FLAG_REMOVE_PRIVATE_AS);
3906 }
3907
3908 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3909 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3910 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3911 "Remove private ASNs in outbound updates\n")
3912
3913 DEFUN (neighbor_remove_private_as_all,
3914 neighbor_remove_private_as_all_cmd,
3915 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3916 NEIGHBOR_STR
3917 NEIGHBOR_ADDR_STR2
3918 "Remove private ASNs in outbound updates\n"
3919 "Apply to all AS numbers\n")
3920 {
3921 int idx_peer = 1;
3922 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3923 bgp_node_safi(vty),
3924 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3925 }
3926
3927 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3928 neighbor_remove_private_as_all_hidden_cmd,
3929 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3931 "Remove private ASNs in outbound updates\n"
3932 "Apply to all AS numbers")
3933
3934 DEFUN (neighbor_remove_private_as_replace_as,
3935 neighbor_remove_private_as_replace_as_cmd,
3936 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3937 NEIGHBOR_STR
3938 NEIGHBOR_ADDR_STR2
3939 "Remove private ASNs in outbound updates\n"
3940 "Replace private ASNs with our ASN in outbound updates\n")
3941 {
3942 int idx_peer = 1;
3943 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3944 bgp_node_safi(vty),
3945 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3946 }
3947
3948 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3949 neighbor_remove_private_as_replace_as_hidden_cmd,
3950 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3951 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3952 "Remove private ASNs in outbound updates\n"
3953 "Replace private ASNs with our ASN in outbound updates\n")
3954
3955 DEFUN (neighbor_remove_private_as_all_replace_as,
3956 neighbor_remove_private_as_all_replace_as_cmd,
3957 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3958 NEIGHBOR_STR
3959 NEIGHBOR_ADDR_STR2
3960 "Remove private ASNs in outbound updates\n"
3961 "Apply to all AS numbers\n"
3962 "Replace private ASNs with our ASN in outbound updates\n")
3963 {
3964 int idx_peer = 1;
3965 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3966 bgp_node_safi(vty),
3967 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3968 }
3969
3970 ALIAS_HIDDEN(
3971 neighbor_remove_private_as_all_replace_as,
3972 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3973 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3975 "Remove private ASNs in outbound updates\n"
3976 "Apply to all AS numbers\n"
3977 "Replace private ASNs with our ASN in outbound updates\n")
3978
3979 DEFUN (no_neighbor_remove_private_as,
3980 no_neighbor_remove_private_as_cmd,
3981 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3982 NO_STR
3983 NEIGHBOR_STR
3984 NEIGHBOR_ADDR_STR2
3985 "Remove private ASNs in outbound updates\n")
3986 {
3987 int idx_peer = 2;
3988 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3989 bgp_node_afi(vty), bgp_node_safi(vty),
3990 PEER_FLAG_REMOVE_PRIVATE_AS);
3991 }
3992
3993 ALIAS_HIDDEN(no_neighbor_remove_private_as,
3994 no_neighbor_remove_private_as_hidden_cmd,
3995 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3996 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3997 "Remove private ASNs in outbound updates\n")
3998
3999 DEFUN (no_neighbor_remove_private_as_all,
4000 no_neighbor_remove_private_as_all_cmd,
4001 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4002 NO_STR
4003 NEIGHBOR_STR
4004 NEIGHBOR_ADDR_STR2
4005 "Remove private ASNs in outbound updates\n"
4006 "Apply to all AS numbers\n")
4007 {
4008 int idx_peer = 2;
4009 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4010 bgp_node_afi(vty), bgp_node_safi(vty),
4011 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4012 }
4013
4014 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
4015 no_neighbor_remove_private_as_all_hidden_cmd,
4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4017 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n"
4019 "Apply to all AS numbers\n")
4020
4021 DEFUN (no_neighbor_remove_private_as_replace_as,
4022 no_neighbor_remove_private_as_replace_as_cmd,
4023 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4024 NO_STR
4025 NEIGHBOR_STR
4026 NEIGHBOR_ADDR_STR2
4027 "Remove private ASNs in outbound updates\n"
4028 "Replace private ASNs with our ASN in outbound updates\n")
4029 {
4030 int idx_peer = 2;
4031 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4032 bgp_node_afi(vty), bgp_node_safi(vty),
4033 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4034 }
4035
4036 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4037 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4038 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4039 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4040 "Remove private ASNs in outbound updates\n"
4041 "Replace private ASNs with our ASN in outbound updates\n")
4042
4043 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4044 no_neighbor_remove_private_as_all_replace_as_cmd,
4045 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4046 NO_STR
4047 NEIGHBOR_STR
4048 NEIGHBOR_ADDR_STR2
4049 "Remove private ASNs in outbound updates\n"
4050 "Apply to all AS numbers\n"
4051 "Replace private ASNs with our ASN in outbound updates\n")
4052 {
4053 int idx_peer = 2;
4054 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4055 bgp_node_afi(vty), bgp_node_safi(vty),
4056 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4057 }
4058
4059 ALIAS_HIDDEN(
4060 no_neighbor_remove_private_as_all_replace_as,
4061 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4062 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4063 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4064 "Remove private ASNs in outbound updates\n"
4065 "Apply to all AS numbers\n"
4066 "Replace private ASNs with our ASN in outbound updates\n")
4067
4068
4069 /* neighbor send-community. */
4070 DEFUN (neighbor_send_community,
4071 neighbor_send_community_cmd,
4072 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4073 NEIGHBOR_STR
4074 NEIGHBOR_ADDR_STR2
4075 "Send Community attribute to this neighbor\n")
4076 {
4077 int idx_peer = 1;
4078 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4079 bgp_node_safi(vty),
4080 PEER_FLAG_SEND_COMMUNITY);
4081 }
4082
4083 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4084 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4085 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4086 "Send Community attribute to this neighbor\n")
4087
4088 DEFUN (no_neighbor_send_community,
4089 no_neighbor_send_community_cmd,
4090 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4091 NO_STR
4092 NEIGHBOR_STR
4093 NEIGHBOR_ADDR_STR2
4094 "Send Community attribute to this neighbor\n")
4095 {
4096 int idx_peer = 2;
4097 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4098 bgp_node_afi(vty), bgp_node_safi(vty),
4099 PEER_FLAG_SEND_COMMUNITY);
4100 }
4101
4102 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4103 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4104 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4105 "Send Community attribute to this neighbor\n")
4106
4107 /* neighbor send-community extended. */
4108 DEFUN (neighbor_send_community_type,
4109 neighbor_send_community_type_cmd,
4110 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4111 NEIGHBOR_STR
4112 NEIGHBOR_ADDR_STR2
4113 "Send Community attribute to this neighbor\n"
4114 "Send Standard and Extended Community attributes\n"
4115 "Send Standard, Large and Extended Community attributes\n"
4116 "Send Extended Community attributes\n"
4117 "Send Standard Community attributes\n"
4118 "Send Large Community attributes\n")
4119 {
4120 int idx = 0;
4121 uint32_t flag = 0;
4122
4123 char *peer = argv[1]->arg;
4124
4125 if (argv_find(argv, argc, "standard", &idx))
4126 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4127 else if (argv_find(argv, argc, "extended", &idx))
4128 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4129 else if (argv_find(argv, argc, "large", &idx))
4130 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4131 else if (argv_find(argv, argc, "both", &idx)) {
4132 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4133 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4134 } else {
4135 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4136 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4137 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4138 }
4139
4140 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4141 bgp_node_safi(vty), flag);
4142 }
4143
4144 ALIAS_HIDDEN(
4145 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4146 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4147 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4148 "Send Community attribute to this neighbor\n"
4149 "Send Standard and Extended Community attributes\n"
4150 "Send Standard, Large and Extended Community attributes\n"
4151 "Send Extended Community attributes\n"
4152 "Send Standard Community attributes\n"
4153 "Send Large Community attributes\n")
4154
4155 DEFUN (no_neighbor_send_community_type,
4156 no_neighbor_send_community_type_cmd,
4157 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4158 NO_STR
4159 NEIGHBOR_STR
4160 NEIGHBOR_ADDR_STR2
4161 "Send Community attribute to this neighbor\n"
4162 "Send Standard and Extended Community attributes\n"
4163 "Send Standard, Large and Extended Community attributes\n"
4164 "Send Extended Community attributes\n"
4165 "Send Standard Community attributes\n"
4166 "Send Large Community attributes\n")
4167 {
4168 int idx_peer = 2;
4169
4170 const char *type = argv[argc - 1]->text;
4171
4172 if (strmatch(type, "standard"))
4173 return peer_af_flag_unset_vty(
4174 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4175 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4176 if (strmatch(type, "extended"))
4177 return peer_af_flag_unset_vty(
4178 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4179 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4180 if (strmatch(type, "large"))
4181 return peer_af_flag_unset_vty(
4182 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4183 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4184 if (strmatch(type, "both"))
4185 return peer_af_flag_unset_vty(
4186 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4187 bgp_node_safi(vty),
4188 PEER_FLAG_SEND_COMMUNITY
4189 | PEER_FLAG_SEND_EXT_COMMUNITY);
4190
4191 /* if (strmatch (type, "all")) */
4192 return peer_af_flag_unset_vty(
4193 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4194 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4195 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4196 }
4197
4198 ALIAS_HIDDEN(
4199 no_neighbor_send_community_type,
4200 no_neighbor_send_community_type_hidden_cmd,
4201 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4202 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4203 "Send Community attribute to this neighbor\n"
4204 "Send Standard and Extended Community attributes\n"
4205 "Send Standard, Large and Extended Community attributes\n"
4206 "Send Extended Community attributes\n"
4207 "Send Standard Community attributes\n"
4208 "Send Large Community attributes\n")
4209
4210 /* neighbor soft-reconfig. */
4211 DEFUN (neighbor_soft_reconfiguration,
4212 neighbor_soft_reconfiguration_cmd,
4213 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4214 NEIGHBOR_STR
4215 NEIGHBOR_ADDR_STR2
4216 "Per neighbor soft reconfiguration\n"
4217 "Allow inbound soft reconfiguration for this neighbor\n")
4218 {
4219 int idx_peer = 1;
4220 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4221 bgp_node_safi(vty),
4222 PEER_FLAG_SOFT_RECONFIG);
4223 }
4224
4225 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4226 neighbor_soft_reconfiguration_hidden_cmd,
4227 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4228 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4229 "Per neighbor soft reconfiguration\n"
4230 "Allow inbound soft reconfiguration for this neighbor\n")
4231
4232 DEFUN (no_neighbor_soft_reconfiguration,
4233 no_neighbor_soft_reconfiguration_cmd,
4234 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4235 NO_STR
4236 NEIGHBOR_STR
4237 NEIGHBOR_ADDR_STR2
4238 "Per neighbor soft reconfiguration\n"
4239 "Allow inbound soft reconfiguration for this neighbor\n")
4240 {
4241 int idx_peer = 2;
4242 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4243 bgp_node_afi(vty), bgp_node_safi(vty),
4244 PEER_FLAG_SOFT_RECONFIG);
4245 }
4246
4247 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4248 no_neighbor_soft_reconfiguration_hidden_cmd,
4249 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4250 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4251 "Per neighbor soft reconfiguration\n"
4252 "Allow inbound soft reconfiguration for this neighbor\n")
4253
4254 DEFUN (neighbor_route_reflector_client,
4255 neighbor_route_reflector_client_cmd,
4256 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4257 NEIGHBOR_STR
4258 NEIGHBOR_ADDR_STR2
4259 "Configure a neighbor as Route Reflector client\n")
4260 {
4261 int idx_peer = 1;
4262 struct peer *peer;
4263
4264
4265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4266 if (!peer)
4267 return CMD_WARNING_CONFIG_FAILED;
4268
4269 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4270 bgp_node_safi(vty),
4271 PEER_FLAG_REFLECTOR_CLIENT);
4272 }
4273
4274 ALIAS_HIDDEN(neighbor_route_reflector_client,
4275 neighbor_route_reflector_client_hidden_cmd,
4276 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4277 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4278 "Configure a neighbor as Route Reflector client\n")
4279
4280 DEFUN (no_neighbor_route_reflector_client,
4281 no_neighbor_route_reflector_client_cmd,
4282 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4283 NO_STR
4284 NEIGHBOR_STR
4285 NEIGHBOR_ADDR_STR2
4286 "Configure a neighbor as Route Reflector client\n")
4287 {
4288 int idx_peer = 2;
4289 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4290 bgp_node_afi(vty), bgp_node_safi(vty),
4291 PEER_FLAG_REFLECTOR_CLIENT);
4292 }
4293
4294 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4295 no_neighbor_route_reflector_client_hidden_cmd,
4296 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4297 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4298 "Configure a neighbor as Route Reflector client\n")
4299
4300 /* neighbor route-server-client. */
4301 DEFUN (neighbor_route_server_client,
4302 neighbor_route_server_client_cmd,
4303 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4304 NEIGHBOR_STR
4305 NEIGHBOR_ADDR_STR2
4306 "Configure a neighbor as Route Server client\n")
4307 {
4308 int idx_peer = 1;
4309 struct peer *peer;
4310
4311 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4312 if (!peer)
4313 return CMD_WARNING_CONFIG_FAILED;
4314 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4315 bgp_node_safi(vty),
4316 PEER_FLAG_RSERVER_CLIENT);
4317 }
4318
4319 ALIAS_HIDDEN(neighbor_route_server_client,
4320 neighbor_route_server_client_hidden_cmd,
4321 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4322 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4323 "Configure a neighbor as Route Server client\n")
4324
4325 DEFUN (no_neighbor_route_server_client,
4326 no_neighbor_route_server_client_cmd,
4327 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4328 NO_STR
4329 NEIGHBOR_STR
4330 NEIGHBOR_ADDR_STR2
4331 "Configure a neighbor as Route Server client\n")
4332 {
4333 int idx_peer = 2;
4334 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4335 bgp_node_afi(vty), bgp_node_safi(vty),
4336 PEER_FLAG_RSERVER_CLIENT);
4337 }
4338
4339 ALIAS_HIDDEN(no_neighbor_route_server_client,
4340 no_neighbor_route_server_client_hidden_cmd,
4341 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4342 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4343 "Configure a neighbor as Route Server client\n")
4344
4345 DEFUN (neighbor_nexthop_local_unchanged,
4346 neighbor_nexthop_local_unchanged_cmd,
4347 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4348 NEIGHBOR_STR
4349 NEIGHBOR_ADDR_STR2
4350 "Configure treatment of outgoing link-local nexthop attribute\n"
4351 "Leave link-local nexthop unchanged for this peer\n")
4352 {
4353 int idx_peer = 1;
4354 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4355 bgp_node_safi(vty),
4356 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4357 }
4358
4359 DEFUN (no_neighbor_nexthop_local_unchanged,
4360 no_neighbor_nexthop_local_unchanged_cmd,
4361 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4362 NO_STR
4363 NEIGHBOR_STR
4364 NEIGHBOR_ADDR_STR2
4365 "Configure treatment of outgoing link-local-nexthop attribute\n"
4366 "Leave link-local nexthop unchanged for this peer\n")
4367 {
4368 int idx_peer = 2;
4369 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4370 bgp_node_afi(vty), bgp_node_safi(vty),
4371 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4372 }
4373
4374 DEFUN (neighbor_attr_unchanged,
4375 neighbor_attr_unchanged_cmd,
4376 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4377 NEIGHBOR_STR
4378 NEIGHBOR_ADDR_STR2
4379 "BGP attribute is propagated unchanged to this neighbor\n"
4380 "As-path attribute\n"
4381 "Nexthop attribute\n"
4382 "Med attribute\n")
4383 {
4384 int idx = 0;
4385 char *peer_str = argv[1]->arg;
4386 struct peer *peer;
4387 uint16_t flags = 0;
4388 afi_t afi = bgp_node_afi(vty);
4389 safi_t safi = bgp_node_safi(vty);
4390
4391 peer = peer_and_group_lookup_vty(vty, peer_str);
4392 if (!peer)
4393 return CMD_WARNING_CONFIG_FAILED;
4394
4395 if (argv_find(argv, argc, "as-path", &idx))
4396 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4397 idx = 0;
4398 if (argv_find(argv, argc, "next-hop", &idx))
4399 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4400 idx = 0;
4401 if (argv_find(argv, argc, "med", &idx))
4402 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4403
4404 /* no flags means all of them! */
4405 if (!flags) {
4406 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4407 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4408 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4409 } else {
4410 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4411 && peer_af_flag_check(peer, afi, safi,
4412 PEER_FLAG_AS_PATH_UNCHANGED)) {
4413 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4414 PEER_FLAG_AS_PATH_UNCHANGED);
4415 }
4416
4417 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4418 && peer_af_flag_check(peer, afi, safi,
4419 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4420 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4421 PEER_FLAG_NEXTHOP_UNCHANGED);
4422 }
4423
4424 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4425 && peer_af_flag_check(peer, afi, safi,
4426 PEER_FLAG_MED_UNCHANGED)) {
4427 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4428 PEER_FLAG_MED_UNCHANGED);
4429 }
4430 }
4431
4432 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4433 }
4434
4435 ALIAS_HIDDEN(
4436 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4437 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4438 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4439 "BGP attribute is propagated unchanged to this neighbor\n"
4440 "As-path attribute\n"
4441 "Nexthop attribute\n"
4442 "Med attribute\n")
4443
4444 DEFUN (no_neighbor_attr_unchanged,
4445 no_neighbor_attr_unchanged_cmd,
4446 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4447 NO_STR
4448 NEIGHBOR_STR
4449 NEIGHBOR_ADDR_STR2
4450 "BGP attribute is propagated unchanged to this neighbor\n"
4451 "As-path attribute\n"
4452 "Nexthop attribute\n"
4453 "Med attribute\n")
4454 {
4455 int idx = 0;
4456 char *peer = argv[2]->arg;
4457 uint16_t flags = 0;
4458
4459 if (argv_find(argv, argc, "as-path", &idx))
4460 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4461 idx = 0;
4462 if (argv_find(argv, argc, "next-hop", &idx))
4463 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4464 idx = 0;
4465 if (argv_find(argv, argc, "med", &idx))
4466 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4467
4468 if (!flags) // no flags means all of them!
4469 {
4470 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4471 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4472 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4473 }
4474
4475 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4476 bgp_node_safi(vty), flags);
4477 }
4478
4479 ALIAS_HIDDEN(
4480 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4481 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4482 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4483 "BGP attribute is propagated unchanged to this neighbor\n"
4484 "As-path attribute\n"
4485 "Nexthop attribute\n"
4486 "Med attribute\n")
4487
4488 /* EBGP multihop configuration. */
4489 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4490 const char *ttl_str)
4491 {
4492 struct peer *peer;
4493 unsigned int ttl;
4494
4495 peer = peer_and_group_lookup_vty(vty, ip_str);
4496 if (!peer)
4497 return CMD_WARNING_CONFIG_FAILED;
4498
4499 if (peer->conf_if)
4500 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4501
4502 if (!ttl_str)
4503 ttl = MAXTTL;
4504 else
4505 ttl = strtoul(ttl_str, NULL, 10);
4506
4507 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4508 }
4509
4510 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4511 {
4512 struct peer *peer;
4513
4514 peer = peer_and_group_lookup_vty(vty, ip_str);
4515 if (!peer)
4516 return CMD_WARNING_CONFIG_FAILED;
4517
4518 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4519 }
4520
4521 /* neighbor ebgp-multihop. */
4522 DEFUN (neighbor_ebgp_multihop,
4523 neighbor_ebgp_multihop_cmd,
4524 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4525 NEIGHBOR_STR
4526 NEIGHBOR_ADDR_STR2
4527 "Allow EBGP neighbors not on directly connected networks\n")
4528 {
4529 int idx_peer = 1;
4530 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4531 }
4532
4533 DEFUN (neighbor_ebgp_multihop_ttl,
4534 neighbor_ebgp_multihop_ttl_cmd,
4535 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4536 NEIGHBOR_STR
4537 NEIGHBOR_ADDR_STR2
4538 "Allow EBGP neighbors not on directly connected networks\n"
4539 "maximum hop count\n")
4540 {
4541 int idx_peer = 1;
4542 int idx_number = 3;
4543 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4544 argv[idx_number]->arg);
4545 }
4546
4547 DEFUN (no_neighbor_ebgp_multihop,
4548 no_neighbor_ebgp_multihop_cmd,
4549 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4550 NO_STR
4551 NEIGHBOR_STR
4552 NEIGHBOR_ADDR_STR2
4553 "Allow EBGP neighbors not on directly connected networks\n"
4554 "maximum hop count\n")
4555 {
4556 int idx_peer = 2;
4557 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4558 }
4559
4560
4561 /* disable-connected-check */
4562 DEFUN (neighbor_disable_connected_check,
4563 neighbor_disable_connected_check_cmd,
4564 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4565 NEIGHBOR_STR
4566 NEIGHBOR_ADDR_STR2
4567 "one-hop away EBGP peer using loopback address\n"
4568 "Enforce EBGP neighbors perform multihop\n")
4569 {
4570 int idx_peer = 1;
4571 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4572 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4573 }
4574
4575 DEFUN (no_neighbor_disable_connected_check,
4576 no_neighbor_disable_connected_check_cmd,
4577 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4578 NO_STR
4579 NEIGHBOR_STR
4580 NEIGHBOR_ADDR_STR2
4581 "one-hop away EBGP peer using loopback address\n"
4582 "Enforce EBGP neighbors perform multihop\n")
4583 {
4584 int idx_peer = 2;
4585 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4586 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4587 }
4588
4589
4590 /* enforce-first-as */
4591 DEFUN (neighbor_enforce_first_as,
4592 neighbor_enforce_first_as_cmd,
4593 "neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4594 NEIGHBOR_STR
4595 NEIGHBOR_ADDR_STR2
4596 "Enforce the first AS for EBGP routes\n")
4597 {
4598 int idx_peer = 1;
4599
4600 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4601 PEER_FLAG_ENFORCE_FIRST_AS);
4602 }
4603
4604 DEFUN (no_neighbor_enforce_first_as,
4605 no_neighbor_enforce_first_as_cmd,
4606 "no neighbor <A.B.C.D|X:X::X:X|WORD> enforce-first-as",
4607 NO_STR
4608 NEIGHBOR_STR
4609 NEIGHBOR_ADDR_STR2
4610 "Enforce the first AS for EBGP routes\n")
4611 {
4612 int idx_peer = 2;
4613
4614 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4615 PEER_FLAG_ENFORCE_FIRST_AS);
4616 }
4617
4618
4619 DEFUN (neighbor_description,
4620 neighbor_description_cmd,
4621 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4622 NEIGHBOR_STR
4623 NEIGHBOR_ADDR_STR2
4624 "Neighbor specific description\n"
4625 "Up to 80 characters describing this neighbor\n")
4626 {
4627 int idx_peer = 1;
4628 int idx_line = 3;
4629 struct peer *peer;
4630 char *str;
4631
4632 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4633 if (!peer)
4634 return CMD_WARNING_CONFIG_FAILED;
4635
4636 str = argv_concat(argv, argc, idx_line);
4637
4638 peer_description_set(peer, str);
4639
4640 XFREE(MTYPE_TMP, str);
4641
4642 return CMD_SUCCESS;
4643 }
4644
4645 DEFUN (no_neighbor_description,
4646 no_neighbor_description_cmd,
4647 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
4648 NO_STR
4649 NEIGHBOR_STR
4650 NEIGHBOR_ADDR_STR2
4651 "Neighbor specific description\n"
4652 "Up to 80 characters describing this neighbor\n")
4653 {
4654 int idx_peer = 2;
4655 struct peer *peer;
4656
4657 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4658 if (!peer)
4659 return CMD_WARNING_CONFIG_FAILED;
4660
4661 peer_description_unset(peer);
4662
4663 return CMD_SUCCESS;
4664 }
4665
4666
4667 /* Neighbor update-source. */
4668 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4669 const char *source_str)
4670 {
4671 struct peer *peer;
4672 struct prefix p;
4673
4674 peer = peer_and_group_lookup_vty(vty, peer_str);
4675 if (!peer)
4676 return CMD_WARNING_CONFIG_FAILED;
4677
4678 if (peer->conf_if)
4679 return CMD_WARNING;
4680
4681 if (source_str) {
4682 union sockunion su;
4683 int ret = str2sockunion(source_str, &su);
4684
4685 if (ret == 0)
4686 peer_update_source_addr_set(peer, &su);
4687 else {
4688 if (str2prefix(source_str, &p)) {
4689 vty_out(vty,
4690 "%% Invalid update-source, remove prefix length \n");
4691 return CMD_WARNING_CONFIG_FAILED;
4692 } else
4693 peer_update_source_if_set(peer, source_str);
4694 }
4695 } else
4696 peer_update_source_unset(peer);
4697
4698 return CMD_SUCCESS;
4699 }
4700
4701 #define BGP_UPDATE_SOURCE_HELP_STR \
4702 "IPv4 address\n" \
4703 "IPv6 address\n" \
4704 "Interface name (requires zebra to be running)\n"
4705
4706 DEFUN (neighbor_update_source,
4707 neighbor_update_source_cmd,
4708 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4709 NEIGHBOR_STR
4710 NEIGHBOR_ADDR_STR2
4711 "Source of routing updates\n"
4712 BGP_UPDATE_SOURCE_HELP_STR)
4713 {
4714 int idx_peer = 1;
4715 int idx_peer_2 = 3;
4716 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4717 argv[idx_peer_2]->arg);
4718 }
4719
4720 DEFUN (no_neighbor_update_source,
4721 no_neighbor_update_source_cmd,
4722 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4723 NO_STR
4724 NEIGHBOR_STR
4725 NEIGHBOR_ADDR_STR2
4726 "Source of routing updates\n"
4727 BGP_UPDATE_SOURCE_HELP_STR)
4728 {
4729 int idx_peer = 2;
4730 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4731 }
4732
4733 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4734 afi_t afi, safi_t safi,
4735 const char *rmap, int set)
4736 {
4737 int ret;
4738 struct peer *peer;
4739
4740 peer = peer_and_group_lookup_vty(vty, peer_str);
4741 if (!peer)
4742 return CMD_WARNING_CONFIG_FAILED;
4743
4744 if (set)
4745 ret = peer_default_originate_set(peer, afi, safi, rmap);
4746 else
4747 ret = peer_default_originate_unset(peer, afi, safi);
4748
4749 return bgp_vty_return(vty, ret);
4750 }
4751
4752 /* neighbor default-originate. */
4753 DEFUN (neighbor_default_originate,
4754 neighbor_default_originate_cmd,
4755 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4756 NEIGHBOR_STR
4757 NEIGHBOR_ADDR_STR2
4758 "Originate default route to this neighbor\n")
4759 {
4760 int idx_peer = 1;
4761 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4762 bgp_node_afi(vty),
4763 bgp_node_safi(vty), NULL, 1);
4764 }
4765
4766 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4767 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4768 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4769 "Originate default route to this neighbor\n")
4770
4771 DEFUN (neighbor_default_originate_rmap,
4772 neighbor_default_originate_rmap_cmd,
4773 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4774 NEIGHBOR_STR
4775 NEIGHBOR_ADDR_STR2
4776 "Originate default route to this neighbor\n"
4777 "Route-map to specify criteria to originate default\n"
4778 "route-map name\n")
4779 {
4780 int idx_peer = 1;
4781 int idx_word = 4;
4782 return peer_default_originate_set_vty(
4783 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4784 argv[idx_word]->arg, 1);
4785 }
4786
4787 ALIAS_HIDDEN(
4788 neighbor_default_originate_rmap,
4789 neighbor_default_originate_rmap_hidden_cmd,
4790 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4791 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4792 "Originate default route to this neighbor\n"
4793 "Route-map to specify criteria to originate default\n"
4794 "route-map name\n")
4795
4796 DEFUN (no_neighbor_default_originate,
4797 no_neighbor_default_originate_cmd,
4798 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4799 NO_STR
4800 NEIGHBOR_STR
4801 NEIGHBOR_ADDR_STR2
4802 "Originate default route to this neighbor\n"
4803 "Route-map to specify criteria to originate default\n"
4804 "route-map name\n")
4805 {
4806 int idx_peer = 2;
4807 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4808 bgp_node_afi(vty),
4809 bgp_node_safi(vty), NULL, 0);
4810 }
4811
4812 ALIAS_HIDDEN(
4813 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4814 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4815 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4816 "Originate default route to this neighbor\n"
4817 "Route-map to specify criteria to originate default\n"
4818 "route-map name\n")
4819
4820
4821 /* Set neighbor's BGP port. */
4822 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4823 const char *port_str)
4824 {
4825 struct peer *peer;
4826 uint16_t port;
4827 struct servent *sp;
4828
4829 peer = peer_lookup_vty(vty, ip_str);
4830 if (!peer)
4831 return CMD_WARNING_CONFIG_FAILED;
4832
4833 if (!port_str) {
4834 sp = getservbyname("bgp", "tcp");
4835 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4836 } else {
4837 port = strtoul(port_str, NULL, 10);
4838 }
4839
4840 peer_port_set(peer, port);
4841
4842 return CMD_SUCCESS;
4843 }
4844
4845 /* Set specified peer's BGP port. */
4846 DEFUN (neighbor_port,
4847 neighbor_port_cmd,
4848 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4849 NEIGHBOR_STR
4850 NEIGHBOR_ADDR_STR
4851 "Neighbor's BGP port\n"
4852 "TCP port number\n")
4853 {
4854 int idx_ip = 1;
4855 int idx_number = 3;
4856 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4857 argv[idx_number]->arg);
4858 }
4859
4860 DEFUN (no_neighbor_port,
4861 no_neighbor_port_cmd,
4862 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4863 NO_STR
4864 NEIGHBOR_STR
4865 NEIGHBOR_ADDR_STR
4866 "Neighbor's BGP port\n"
4867 "TCP port number\n")
4868 {
4869 int idx_ip = 2;
4870 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4871 }
4872
4873
4874 /* neighbor weight. */
4875 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4876 safi_t safi, const char *weight_str)
4877 {
4878 int ret;
4879 struct peer *peer;
4880 unsigned long weight;
4881
4882 peer = peer_and_group_lookup_vty(vty, ip_str);
4883 if (!peer)
4884 return CMD_WARNING_CONFIG_FAILED;
4885
4886 weight = strtoul(weight_str, NULL, 10);
4887
4888 ret = peer_weight_set(peer, afi, safi, weight);
4889 return bgp_vty_return(vty, ret);
4890 }
4891
4892 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4893 safi_t safi)
4894 {
4895 int ret;
4896 struct peer *peer;
4897
4898 peer = peer_and_group_lookup_vty(vty, ip_str);
4899 if (!peer)
4900 return CMD_WARNING_CONFIG_FAILED;
4901
4902 ret = peer_weight_unset(peer, afi, safi);
4903 return bgp_vty_return(vty, ret);
4904 }
4905
4906 DEFUN (neighbor_weight,
4907 neighbor_weight_cmd,
4908 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4909 NEIGHBOR_STR
4910 NEIGHBOR_ADDR_STR2
4911 "Set default weight for routes from this neighbor\n"
4912 "default weight\n")
4913 {
4914 int idx_peer = 1;
4915 int idx_number = 3;
4916 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4917 bgp_node_safi(vty), argv[idx_number]->arg);
4918 }
4919
4920 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4921 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4922 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4923 "Set default weight for routes from this neighbor\n"
4924 "default weight\n")
4925
4926 DEFUN (no_neighbor_weight,
4927 no_neighbor_weight_cmd,
4928 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4929 NO_STR
4930 NEIGHBOR_STR
4931 NEIGHBOR_ADDR_STR2
4932 "Set default weight for routes from this neighbor\n"
4933 "default weight\n")
4934 {
4935 int idx_peer = 2;
4936 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4937 bgp_node_afi(vty), bgp_node_safi(vty));
4938 }
4939
4940 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4941 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4942 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4943 "Set default weight for routes from this neighbor\n"
4944 "default weight\n")
4945
4946
4947 /* Override capability negotiation. */
4948 DEFUN (neighbor_override_capability,
4949 neighbor_override_capability_cmd,
4950 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4951 NEIGHBOR_STR
4952 NEIGHBOR_ADDR_STR2
4953 "Override capability negotiation result\n")
4954 {
4955 int idx_peer = 1;
4956 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4957 PEER_FLAG_OVERRIDE_CAPABILITY);
4958 }
4959
4960 DEFUN (no_neighbor_override_capability,
4961 no_neighbor_override_capability_cmd,
4962 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4963 NO_STR
4964 NEIGHBOR_STR
4965 NEIGHBOR_ADDR_STR2
4966 "Override capability negotiation result\n")
4967 {
4968 int idx_peer = 2;
4969 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4970 PEER_FLAG_OVERRIDE_CAPABILITY);
4971 }
4972
4973 DEFUN (neighbor_strict_capability,
4974 neighbor_strict_capability_cmd,
4975 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4976 NEIGHBOR_STR
4977 NEIGHBOR_ADDR_STR
4978 "Strict capability negotiation match\n")
4979 {
4980 int idx_ip = 1;
4981 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4982 PEER_FLAG_STRICT_CAP_MATCH);
4983 }
4984
4985 DEFUN (no_neighbor_strict_capability,
4986 no_neighbor_strict_capability_cmd,
4987 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4988 NO_STR
4989 NEIGHBOR_STR
4990 NEIGHBOR_ADDR_STR
4991 "Strict capability negotiation match\n")
4992 {
4993 int idx_ip = 2;
4994 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4995 PEER_FLAG_STRICT_CAP_MATCH);
4996 }
4997
4998 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4999 const char *keep_str, const char *hold_str)
5000 {
5001 int ret;
5002 struct peer *peer;
5003 uint32_t keepalive;
5004 uint32_t holdtime;
5005
5006 peer = peer_and_group_lookup_vty(vty, ip_str);
5007 if (!peer)
5008 return CMD_WARNING_CONFIG_FAILED;
5009
5010 keepalive = strtoul(keep_str, NULL, 10);
5011 holdtime = strtoul(hold_str, NULL, 10);
5012
5013 ret = peer_timers_set(peer, keepalive, holdtime);
5014
5015 return bgp_vty_return(vty, ret);
5016 }
5017
5018 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
5019 {
5020 int ret;
5021 struct peer *peer;
5022
5023 peer = peer_and_group_lookup_vty(vty, ip_str);
5024 if (!peer)
5025 return CMD_WARNING_CONFIG_FAILED;
5026
5027 ret = peer_timers_unset(peer);
5028
5029 return bgp_vty_return(vty, ret);
5030 }
5031
5032 DEFUN (neighbor_timers,
5033 neighbor_timers_cmd,
5034 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
5035 NEIGHBOR_STR
5036 NEIGHBOR_ADDR_STR2
5037 "BGP per neighbor timers\n"
5038 "Keepalive interval\n"
5039 "Holdtime\n")
5040 {
5041 int idx_peer = 1;
5042 int idx_number = 3;
5043 int idx_number_2 = 4;
5044 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
5045 argv[idx_number]->arg,
5046 argv[idx_number_2]->arg);
5047 }
5048
5049 DEFUN (no_neighbor_timers,
5050 no_neighbor_timers_cmd,
5051 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
5052 NO_STR
5053 NEIGHBOR_STR
5054 NEIGHBOR_ADDR_STR2
5055 "BGP per neighbor timers\n"
5056 "Keepalive interval\n"
5057 "Holdtime\n")
5058 {
5059 int idx_peer = 2;
5060 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
5061 }
5062
5063
5064 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5065 const char *time_str)
5066 {
5067 int ret;
5068 struct peer *peer;
5069 uint32_t connect;
5070
5071 peer = peer_and_group_lookup_vty(vty, ip_str);
5072 if (!peer)
5073 return CMD_WARNING_CONFIG_FAILED;
5074
5075 connect = strtoul(time_str, NULL, 10);
5076
5077 ret = peer_timers_connect_set(peer, connect);
5078
5079 return bgp_vty_return(vty, ret);
5080 }
5081
5082 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5083 {
5084 int ret;
5085 struct peer *peer;
5086
5087 peer = peer_and_group_lookup_vty(vty, ip_str);
5088 if (!peer)
5089 return CMD_WARNING_CONFIG_FAILED;
5090
5091 ret = peer_timers_connect_unset(peer);
5092
5093 return bgp_vty_return(vty, ret);
5094 }
5095
5096 DEFUN (neighbor_timers_connect,
5097 neighbor_timers_connect_cmd,
5098 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5099 NEIGHBOR_STR
5100 NEIGHBOR_ADDR_STR2
5101 "BGP per neighbor timers\n"
5102 "BGP connect timer\n"
5103 "Connect timer\n")
5104 {
5105 int idx_peer = 1;
5106 int idx_number = 4;
5107 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5108 argv[idx_number]->arg);
5109 }
5110
5111 DEFUN (no_neighbor_timers_connect,
5112 no_neighbor_timers_connect_cmd,
5113 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5114 NO_STR
5115 NEIGHBOR_STR
5116 NEIGHBOR_ADDR_STR2
5117 "BGP per neighbor timers\n"
5118 "BGP connect timer\n"
5119 "Connect timer\n")
5120 {
5121 int idx_peer = 2;
5122 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5123 }
5124
5125
5126 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5127 const char *time_str, int set)
5128 {
5129 int ret;
5130 struct peer *peer;
5131 uint32_t routeadv = 0;
5132
5133 peer = peer_and_group_lookup_vty(vty, ip_str);
5134 if (!peer)
5135 return CMD_WARNING_CONFIG_FAILED;
5136
5137 if (time_str)
5138 routeadv = strtoul(time_str, NULL, 10);
5139
5140 if (set)
5141 ret = peer_advertise_interval_set(peer, routeadv);
5142 else
5143 ret = peer_advertise_interval_unset(peer);
5144
5145 return bgp_vty_return(vty, ret);
5146 }
5147
5148 DEFUN (neighbor_advertise_interval,
5149 neighbor_advertise_interval_cmd,
5150 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5151 NEIGHBOR_STR
5152 NEIGHBOR_ADDR_STR2
5153 "Minimum interval between sending BGP routing updates\n"
5154 "time in seconds\n")
5155 {
5156 int idx_peer = 1;
5157 int idx_number = 3;
5158 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5159 argv[idx_number]->arg, 1);
5160 }
5161
5162 DEFUN (no_neighbor_advertise_interval,
5163 no_neighbor_advertise_interval_cmd,
5164 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5165 NO_STR
5166 NEIGHBOR_STR
5167 NEIGHBOR_ADDR_STR2
5168 "Minimum interval between sending BGP routing updates\n"
5169 "time in seconds\n")
5170 {
5171 int idx_peer = 2;
5172 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5173 }
5174
5175
5176 /* Time to wait before processing route-map updates */
5177 DEFUN (bgp_set_route_map_delay_timer,
5178 bgp_set_route_map_delay_timer_cmd,
5179 "bgp route-map delay-timer (0-600)",
5180 SET_STR
5181 "BGP route-map delay timer\n"
5182 "Time in secs to wait before processing route-map changes\n"
5183 "0 disables the timer, no route updates happen when route-maps change\n")
5184 {
5185 int idx_number = 3;
5186 uint32_t rmap_delay_timer;
5187
5188 if (argv[idx_number]->arg) {
5189 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5190 bm->rmap_update_timer = rmap_delay_timer;
5191
5192 /* if the dynamic update handling is being disabled, and a timer
5193 * is
5194 * running, stop the timer and act as if the timer has already
5195 * fired.
5196 */
5197 if (!rmap_delay_timer && bm->t_rmap_update) {
5198 BGP_TIMER_OFF(bm->t_rmap_update);
5199 thread_execute(bm->master, bgp_route_map_update_timer,
5200 NULL, 0);
5201 }
5202 return CMD_SUCCESS;
5203 } else {
5204 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5205 return CMD_WARNING_CONFIG_FAILED;
5206 }
5207 }
5208
5209 DEFUN (no_bgp_set_route_map_delay_timer,
5210 no_bgp_set_route_map_delay_timer_cmd,
5211 "no bgp route-map delay-timer [(0-600)]",
5212 NO_STR
5213 BGP_STR
5214 "Default BGP route-map delay timer\n"
5215 "Reset to default time to wait for processing route-map changes\n"
5216 "0 disables the timer, no route updates happen when route-maps change\n")
5217 {
5218
5219 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5220
5221 return CMD_SUCCESS;
5222 }
5223
5224
5225 /* neighbor interface */
5226 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5227 const char *str)
5228 {
5229 struct peer *peer;
5230
5231 peer = peer_lookup_vty(vty, ip_str);
5232 if (!peer || peer->conf_if) {
5233 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5234 return CMD_WARNING_CONFIG_FAILED;
5235 }
5236
5237 if (str)
5238 peer_interface_set(peer, str);
5239 else
5240 peer_interface_unset(peer);
5241
5242 return CMD_SUCCESS;
5243 }
5244
5245 DEFUN (neighbor_interface,
5246 neighbor_interface_cmd,
5247 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5248 NEIGHBOR_STR
5249 NEIGHBOR_ADDR_STR
5250 "Interface\n"
5251 "Interface name\n")
5252 {
5253 int idx_ip = 1;
5254 int idx_word = 3;
5255 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5256 }
5257
5258 DEFUN (no_neighbor_interface,
5259 no_neighbor_interface_cmd,
5260 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5261 NO_STR
5262 NEIGHBOR_STR
5263 NEIGHBOR_ADDR_STR2
5264 "Interface\n"
5265 "Interface name\n")
5266 {
5267 int idx_peer = 2;
5268 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5269 }
5270
5271 DEFUN (neighbor_distribute_list,
5272 neighbor_distribute_list_cmd,
5273 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5274 NEIGHBOR_STR
5275 NEIGHBOR_ADDR_STR2
5276 "Filter updates to/from this neighbor\n"
5277 "IP access-list number\n"
5278 "IP access-list number (expanded range)\n"
5279 "IP Access-list name\n"
5280 "Filter incoming updates\n"
5281 "Filter outgoing updates\n")
5282 {
5283 int idx_peer = 1;
5284 int idx_acl = 3;
5285 int direct, ret;
5286 struct peer *peer;
5287
5288 const char *pstr = argv[idx_peer]->arg;
5289 const char *acl = argv[idx_acl]->arg;
5290 const char *inout = argv[argc - 1]->text;
5291
5292 peer = peer_and_group_lookup_vty(vty, pstr);
5293 if (!peer)
5294 return CMD_WARNING_CONFIG_FAILED;
5295
5296 /* Check filter direction. */
5297 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5298 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5299 direct, acl);
5300
5301 return bgp_vty_return(vty, ret);
5302 }
5303
5304 ALIAS_HIDDEN(
5305 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5306 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5307 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5308 "Filter updates to/from this neighbor\n"
5309 "IP access-list number\n"
5310 "IP access-list number (expanded range)\n"
5311 "IP Access-list name\n"
5312 "Filter incoming updates\n"
5313 "Filter outgoing updates\n")
5314
5315 DEFUN (no_neighbor_distribute_list,
5316 no_neighbor_distribute_list_cmd,
5317 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5318 NO_STR
5319 NEIGHBOR_STR
5320 NEIGHBOR_ADDR_STR2
5321 "Filter updates to/from this neighbor\n"
5322 "IP access-list number\n"
5323 "IP access-list number (expanded range)\n"
5324 "IP Access-list name\n"
5325 "Filter incoming updates\n"
5326 "Filter outgoing updates\n")
5327 {
5328 int idx_peer = 2;
5329 int direct, ret;
5330 struct peer *peer;
5331
5332 const char *pstr = argv[idx_peer]->arg;
5333 const char *inout = argv[argc - 1]->text;
5334
5335 peer = peer_and_group_lookup_vty(vty, pstr);
5336 if (!peer)
5337 return CMD_WARNING_CONFIG_FAILED;
5338
5339 /* Check filter direction. */
5340 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5341 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5342 direct);
5343
5344 return bgp_vty_return(vty, ret);
5345 }
5346
5347 ALIAS_HIDDEN(
5348 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5349 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5350 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5351 "Filter updates to/from this neighbor\n"
5352 "IP access-list number\n"
5353 "IP access-list number (expanded range)\n"
5354 "IP Access-list name\n"
5355 "Filter incoming updates\n"
5356 "Filter outgoing updates\n")
5357
5358 /* Set prefix list to the peer. */
5359 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5360 afi_t afi, safi_t safi,
5361 const char *name_str,
5362 const char *direct_str)
5363 {
5364 int ret;
5365 struct peer *peer;
5366 int direct = FILTER_IN;
5367
5368 peer = peer_and_group_lookup_vty(vty, ip_str);
5369 if (!peer)
5370 return CMD_WARNING_CONFIG_FAILED;
5371
5372 /* Check filter direction. */
5373 if (strncmp(direct_str, "i", 1) == 0)
5374 direct = FILTER_IN;
5375 else if (strncmp(direct_str, "o", 1) == 0)
5376 direct = FILTER_OUT;
5377
5378 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5379
5380 return bgp_vty_return(vty, ret);
5381 }
5382
5383 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5384 afi_t afi, safi_t safi,
5385 const char *direct_str)
5386 {
5387 int ret;
5388 struct peer *peer;
5389 int direct = FILTER_IN;
5390
5391 peer = peer_and_group_lookup_vty(vty, ip_str);
5392 if (!peer)
5393 return CMD_WARNING_CONFIG_FAILED;
5394
5395 /* Check filter direction. */
5396 if (strncmp(direct_str, "i", 1) == 0)
5397 direct = FILTER_IN;
5398 else if (strncmp(direct_str, "o", 1) == 0)
5399 direct = FILTER_OUT;
5400
5401 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5402
5403 return bgp_vty_return(vty, ret);
5404 }
5405
5406 DEFUN (neighbor_prefix_list,
5407 neighbor_prefix_list_cmd,
5408 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5409 NEIGHBOR_STR
5410 NEIGHBOR_ADDR_STR2
5411 "Filter updates to/from this neighbor\n"
5412 "Name of a prefix list\n"
5413 "Filter incoming updates\n"
5414 "Filter outgoing updates\n")
5415 {
5416 int idx_peer = 1;
5417 int idx_word = 3;
5418 int idx_in_out = 4;
5419 return peer_prefix_list_set_vty(
5420 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5421 argv[idx_word]->arg, argv[idx_in_out]->arg);
5422 }
5423
5424 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5425 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5426 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5427 "Filter updates to/from this neighbor\n"
5428 "Name of a prefix list\n"
5429 "Filter incoming updates\n"
5430 "Filter outgoing updates\n")
5431
5432 DEFUN (no_neighbor_prefix_list,
5433 no_neighbor_prefix_list_cmd,
5434 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5435 NO_STR
5436 NEIGHBOR_STR
5437 NEIGHBOR_ADDR_STR2
5438 "Filter updates to/from this neighbor\n"
5439 "Name of a prefix list\n"
5440 "Filter incoming updates\n"
5441 "Filter outgoing updates\n")
5442 {
5443 int idx_peer = 2;
5444 int idx_in_out = 5;
5445 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5446 bgp_node_afi(vty), bgp_node_safi(vty),
5447 argv[idx_in_out]->arg);
5448 }
5449
5450 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5451 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5452 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5453 "Filter updates to/from this neighbor\n"
5454 "Name of a prefix list\n"
5455 "Filter incoming updates\n"
5456 "Filter outgoing updates\n")
5457
5458 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5459 safi_t safi, const char *name_str,
5460 const char *direct_str)
5461 {
5462 int ret;
5463 struct peer *peer;
5464 int direct = FILTER_IN;
5465
5466 peer = peer_and_group_lookup_vty(vty, ip_str);
5467 if (!peer)
5468 return CMD_WARNING_CONFIG_FAILED;
5469
5470 /* Check filter direction. */
5471 if (strncmp(direct_str, "i", 1) == 0)
5472 direct = FILTER_IN;
5473 else if (strncmp(direct_str, "o", 1) == 0)
5474 direct = FILTER_OUT;
5475
5476 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5477
5478 return bgp_vty_return(vty, ret);
5479 }
5480
5481 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5482 safi_t safi, const char *direct_str)
5483 {
5484 int ret;
5485 struct peer *peer;
5486 int direct = FILTER_IN;
5487
5488 peer = peer_and_group_lookup_vty(vty, ip_str);
5489 if (!peer)
5490 return CMD_WARNING_CONFIG_FAILED;
5491
5492 /* Check filter direction. */
5493 if (strncmp(direct_str, "i", 1) == 0)
5494 direct = FILTER_IN;
5495 else if (strncmp(direct_str, "o", 1) == 0)
5496 direct = FILTER_OUT;
5497
5498 ret = peer_aslist_unset(peer, afi, safi, direct);
5499
5500 return bgp_vty_return(vty, ret);
5501 }
5502
5503 DEFUN (neighbor_filter_list,
5504 neighbor_filter_list_cmd,
5505 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5506 NEIGHBOR_STR
5507 NEIGHBOR_ADDR_STR2
5508 "Establish BGP filters\n"
5509 "AS path access-list name\n"
5510 "Filter incoming routes\n"
5511 "Filter outgoing routes\n")
5512 {
5513 int idx_peer = 1;
5514 int idx_word = 3;
5515 int idx_in_out = 4;
5516 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5517 bgp_node_safi(vty), argv[idx_word]->arg,
5518 argv[idx_in_out]->arg);
5519 }
5520
5521 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5522 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5523 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5524 "Establish BGP filters\n"
5525 "AS path access-list name\n"
5526 "Filter incoming routes\n"
5527 "Filter outgoing routes\n")
5528
5529 DEFUN (no_neighbor_filter_list,
5530 no_neighbor_filter_list_cmd,
5531 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5532 NO_STR
5533 NEIGHBOR_STR
5534 NEIGHBOR_ADDR_STR2
5535 "Establish BGP filters\n"
5536 "AS path access-list name\n"
5537 "Filter incoming routes\n"
5538 "Filter outgoing routes\n")
5539 {
5540 int idx_peer = 2;
5541 int idx_in_out = 5;
5542 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5543 bgp_node_afi(vty), bgp_node_safi(vty),
5544 argv[idx_in_out]->arg);
5545 }
5546
5547 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5548 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5549 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5550 "Establish BGP filters\n"
5551 "AS path access-list name\n"
5552 "Filter incoming routes\n"
5553 "Filter outgoing routes\n")
5554
5555 /* Set route-map to the peer. */
5556 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5557 afi_t afi, safi_t safi, const char *name_str,
5558 const char *direct_str)
5559 {
5560 int ret;
5561 struct peer *peer;
5562 int direct = RMAP_IN;
5563
5564 peer = peer_and_group_lookup_vty(vty, ip_str);
5565 if (!peer)
5566 return CMD_WARNING_CONFIG_FAILED;
5567
5568 /* Check filter direction. */
5569 if (strncmp(direct_str, "in", 2) == 0)
5570 direct = RMAP_IN;
5571 else if (strncmp(direct_str, "o", 1) == 0)
5572 direct = RMAP_OUT;
5573
5574 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5575
5576 return bgp_vty_return(vty, ret);
5577 }
5578
5579 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5580 afi_t afi, safi_t safi,
5581 const char *direct_str)
5582 {
5583 int ret;
5584 struct peer *peer;
5585 int direct = RMAP_IN;
5586
5587 peer = peer_and_group_lookup_vty(vty, ip_str);
5588 if (!peer)
5589 return CMD_WARNING_CONFIG_FAILED;
5590
5591 /* Check filter direction. */
5592 if (strncmp(direct_str, "in", 2) == 0)
5593 direct = RMAP_IN;
5594 else if (strncmp(direct_str, "o", 1) == 0)
5595 direct = RMAP_OUT;
5596
5597 ret = peer_route_map_unset(peer, afi, safi, direct);
5598
5599 return bgp_vty_return(vty, ret);
5600 }
5601
5602 DEFUN (neighbor_route_map,
5603 neighbor_route_map_cmd,
5604 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5605 NEIGHBOR_STR
5606 NEIGHBOR_ADDR_STR2
5607 "Apply route map to neighbor\n"
5608 "Name of route map\n"
5609 "Apply map to incoming routes\n"
5610 "Apply map to outbound routes\n")
5611 {
5612 int idx_peer = 1;
5613 int idx_word = 3;
5614 int idx_in_out = 4;
5615 return peer_route_map_set_vty(
5616 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5617 argv[idx_word]->arg, argv[idx_in_out]->arg);
5618 }
5619
5620 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5621 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5622 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5623 "Apply route map to neighbor\n"
5624 "Name of route map\n"
5625 "Apply map to incoming routes\n"
5626 "Apply map to outbound routes\n")
5627
5628 DEFUN (no_neighbor_route_map,
5629 no_neighbor_route_map_cmd,
5630 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5631 NO_STR
5632 NEIGHBOR_STR
5633 NEIGHBOR_ADDR_STR2
5634 "Apply route map to neighbor\n"
5635 "Name of route map\n"
5636 "Apply map to incoming routes\n"
5637 "Apply map to outbound routes\n")
5638 {
5639 int idx_peer = 2;
5640 int idx_in_out = 5;
5641 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5642 bgp_node_afi(vty), bgp_node_safi(vty),
5643 argv[idx_in_out]->arg);
5644 }
5645
5646 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5647 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5648 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5649 "Apply route map to neighbor\n"
5650 "Name of route map\n"
5651 "Apply map to incoming routes\n"
5652 "Apply map to outbound routes\n")
5653
5654 /* Set unsuppress-map to the peer. */
5655 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5656 afi_t afi, safi_t safi,
5657 const char *name_str)
5658 {
5659 int ret;
5660 struct peer *peer;
5661
5662 peer = peer_and_group_lookup_vty(vty, ip_str);
5663 if (!peer)
5664 return CMD_WARNING_CONFIG_FAILED;
5665
5666 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5667
5668 return bgp_vty_return(vty, ret);
5669 }
5670
5671 /* Unset route-map from the peer. */
5672 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5673 afi_t afi, safi_t safi)
5674 {
5675 int ret;
5676 struct peer *peer;
5677
5678 peer = peer_and_group_lookup_vty(vty, ip_str);
5679 if (!peer)
5680 return CMD_WARNING_CONFIG_FAILED;
5681
5682 ret = peer_unsuppress_map_unset(peer, afi, safi);
5683
5684 return bgp_vty_return(vty, ret);
5685 }
5686
5687 DEFUN (neighbor_unsuppress_map,
5688 neighbor_unsuppress_map_cmd,
5689 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5690 NEIGHBOR_STR
5691 NEIGHBOR_ADDR_STR2
5692 "Route-map to selectively unsuppress suppressed routes\n"
5693 "Name of route map\n")
5694 {
5695 int idx_peer = 1;
5696 int idx_word = 3;
5697 return peer_unsuppress_map_set_vty(
5698 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5699 argv[idx_word]->arg);
5700 }
5701
5702 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5703 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5704 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5705 "Route-map to selectively unsuppress suppressed routes\n"
5706 "Name of route map\n")
5707
5708 DEFUN (no_neighbor_unsuppress_map,
5709 no_neighbor_unsuppress_map_cmd,
5710 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5711 NO_STR
5712 NEIGHBOR_STR
5713 NEIGHBOR_ADDR_STR2
5714 "Route-map to selectively unsuppress suppressed routes\n"
5715 "Name of route map\n")
5716 {
5717 int idx_peer = 2;
5718 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5719 bgp_node_afi(vty),
5720 bgp_node_safi(vty));
5721 }
5722
5723 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5724 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5725 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5726 "Route-map to selectively unsuppress suppressed routes\n"
5727 "Name of route map\n")
5728
5729 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5730 afi_t afi, safi_t safi,
5731 const char *num_str,
5732 const char *threshold_str, int warning,
5733 const char *restart_str)
5734 {
5735 int ret;
5736 struct peer *peer;
5737 uint32_t max;
5738 uint8_t threshold;
5739 uint16_t restart;
5740
5741 peer = peer_and_group_lookup_vty(vty, ip_str);
5742 if (!peer)
5743 return CMD_WARNING_CONFIG_FAILED;
5744
5745 max = strtoul(num_str, NULL, 10);
5746 if (threshold_str)
5747 threshold = atoi(threshold_str);
5748 else
5749 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5750
5751 if (restart_str)
5752 restart = atoi(restart_str);
5753 else
5754 restart = 0;
5755
5756 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5757 restart);
5758
5759 return bgp_vty_return(vty, ret);
5760 }
5761
5762 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5763 afi_t afi, safi_t safi)
5764 {
5765 int ret;
5766 struct peer *peer;
5767
5768 peer = peer_and_group_lookup_vty(vty, ip_str);
5769 if (!peer)
5770 return CMD_WARNING_CONFIG_FAILED;
5771
5772 ret = peer_maximum_prefix_unset(peer, afi, safi);
5773
5774 return bgp_vty_return(vty, ret);
5775 }
5776
5777 /* Maximum number of prefix configuration. prefix count is different
5778 for each peer configuration. So this configuration can be set for
5779 each peer configuration. */
5780 DEFUN (neighbor_maximum_prefix,
5781 neighbor_maximum_prefix_cmd,
5782 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5783 NEIGHBOR_STR
5784 NEIGHBOR_ADDR_STR2
5785 "Maximum number of prefix accept from this peer\n"
5786 "maximum no. of prefix limit\n")
5787 {
5788 int idx_peer = 1;
5789 int idx_number = 3;
5790 return peer_maximum_prefix_set_vty(
5791 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5792 argv[idx_number]->arg, NULL, 0, NULL);
5793 }
5794
5795 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5796 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5797 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5798 "Maximum number of prefix accept from this peer\n"
5799 "maximum no. of prefix limit\n")
5800
5801 DEFUN (neighbor_maximum_prefix_threshold,
5802 neighbor_maximum_prefix_threshold_cmd,
5803 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5804 NEIGHBOR_STR
5805 NEIGHBOR_ADDR_STR2
5806 "Maximum number of prefix accept from this peer\n"
5807 "maximum no. of prefix limit\n"
5808 "Threshold value (%) at which to generate a warning msg\n")
5809 {
5810 int idx_peer = 1;
5811 int idx_number = 3;
5812 int idx_number_2 = 4;
5813 return peer_maximum_prefix_set_vty(
5814 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5815 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5816 }
5817
5818 ALIAS_HIDDEN(
5819 neighbor_maximum_prefix_threshold,
5820 neighbor_maximum_prefix_threshold_hidden_cmd,
5821 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5822 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5823 "Maximum number of prefix accept from this peer\n"
5824 "maximum no. of prefix limit\n"
5825 "Threshold value (%) at which to generate a warning msg\n")
5826
5827 DEFUN (neighbor_maximum_prefix_warning,
5828 neighbor_maximum_prefix_warning_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5830 NEIGHBOR_STR
5831 NEIGHBOR_ADDR_STR2
5832 "Maximum number of prefix accept from this peer\n"
5833 "maximum no. of prefix limit\n"
5834 "Only give warning message when limit is exceeded\n")
5835 {
5836 int idx_peer = 1;
5837 int idx_number = 3;
5838 return peer_maximum_prefix_set_vty(
5839 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5840 argv[idx_number]->arg, NULL, 1, NULL);
5841 }
5842
5843 ALIAS_HIDDEN(
5844 neighbor_maximum_prefix_warning,
5845 neighbor_maximum_prefix_warning_hidden_cmd,
5846 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5847 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Maximum number of prefix accept from this peer\n"
5849 "maximum no. of prefix limit\n"
5850 "Only give warning message when limit is exceeded\n")
5851
5852 DEFUN (neighbor_maximum_prefix_threshold_warning,
5853 neighbor_maximum_prefix_threshold_warning_cmd,
5854 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5855 NEIGHBOR_STR
5856 NEIGHBOR_ADDR_STR2
5857 "Maximum number of prefix accept from this peer\n"
5858 "maximum no. of prefix limit\n"
5859 "Threshold value (%) at which to generate a warning msg\n"
5860 "Only give warning message when limit is exceeded\n")
5861 {
5862 int idx_peer = 1;
5863 int idx_number = 3;
5864 int idx_number_2 = 4;
5865 return peer_maximum_prefix_set_vty(
5866 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5867 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5868 }
5869
5870 ALIAS_HIDDEN(
5871 neighbor_maximum_prefix_threshold_warning,
5872 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5873 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5875 "Maximum number of prefix accept from this peer\n"
5876 "maximum no. of prefix limit\n"
5877 "Threshold value (%) at which to generate a warning msg\n"
5878 "Only give warning message when limit is exceeded\n")
5879
5880 DEFUN (neighbor_maximum_prefix_restart,
5881 neighbor_maximum_prefix_restart_cmd,
5882 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5883 NEIGHBOR_STR
5884 NEIGHBOR_ADDR_STR2
5885 "Maximum number of prefix accept from this peer\n"
5886 "maximum no. of prefix limit\n"
5887 "Restart bgp connection after limit is exceeded\n"
5888 "Restart interval in minutes\n")
5889 {
5890 int idx_peer = 1;
5891 int idx_number = 3;
5892 int idx_number_2 = 5;
5893 return peer_maximum_prefix_set_vty(
5894 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5895 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5896 }
5897
5898 ALIAS_HIDDEN(
5899 neighbor_maximum_prefix_restart,
5900 neighbor_maximum_prefix_restart_hidden_cmd,
5901 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5902 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5903 "Maximum number of prefix accept from this peer\n"
5904 "maximum no. of prefix limit\n"
5905 "Restart bgp connection after limit is exceeded\n"
5906 "Restart interval in minutes\n")
5907
5908 DEFUN (neighbor_maximum_prefix_threshold_restart,
5909 neighbor_maximum_prefix_threshold_restart_cmd,
5910 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5911 NEIGHBOR_STR
5912 NEIGHBOR_ADDR_STR2
5913 "Maximum number of prefixes to accept from this peer\n"
5914 "maximum no. of prefix limit\n"
5915 "Threshold value (%) at which to generate a warning msg\n"
5916 "Restart bgp connection after limit is exceeded\n"
5917 "Restart interval in minutes\n")
5918 {
5919 int idx_peer = 1;
5920 int idx_number = 3;
5921 int idx_number_2 = 4;
5922 int idx_number_3 = 6;
5923 return peer_maximum_prefix_set_vty(
5924 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5925 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5926 argv[idx_number_3]->arg);
5927 }
5928
5929 ALIAS_HIDDEN(
5930 neighbor_maximum_prefix_threshold_restart,
5931 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5932 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5933 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5934 "Maximum number of prefixes to accept from this peer\n"
5935 "maximum no. of prefix limit\n"
5936 "Threshold value (%) at which to generate a warning msg\n"
5937 "Restart bgp connection after limit is exceeded\n"
5938 "Restart interval in minutes\n")
5939
5940 DEFUN (no_neighbor_maximum_prefix,
5941 no_neighbor_maximum_prefix_cmd,
5942 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5943 NO_STR
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 "Only give warning message when limit is exceeded\n")
5952 {
5953 int idx_peer = 2;
5954 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5955 bgp_node_afi(vty),
5956 bgp_node_safi(vty));
5957 }
5958
5959 ALIAS_HIDDEN(
5960 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5961 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5962 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5963 "Maximum number of prefixes to accept from this peer\n"
5964 "maximum no. of prefix limit\n"
5965 "Threshold value (%) at which to generate a warning msg\n"
5966 "Restart bgp connection after limit is exceeded\n"
5967 "Restart interval in minutes\n"
5968 "Only give warning message when limit is exceeded\n")
5969
5970
5971 /* "neighbor allowas-in" */
5972 DEFUN (neighbor_allowas_in,
5973 neighbor_allowas_in_cmd,
5974 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5975 NEIGHBOR_STR
5976 NEIGHBOR_ADDR_STR2
5977 "Accept as-path with my AS present in it\n"
5978 "Number of occurances of AS number\n"
5979 "Only accept my AS in the as-path if the route was originated in my AS\n")
5980 {
5981 int idx_peer = 1;
5982 int idx_number_origin = 3;
5983 int ret;
5984 int origin = 0;
5985 struct peer *peer;
5986 int allow_num = 0;
5987
5988 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5989 if (!peer)
5990 return CMD_WARNING_CONFIG_FAILED;
5991
5992 if (argc <= idx_number_origin)
5993 allow_num = 3;
5994 else {
5995 if (argv[idx_number_origin]->type == WORD_TKN)
5996 origin = 1;
5997 else
5998 allow_num = atoi(argv[idx_number_origin]->arg);
5999 }
6000
6001 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
6002 allow_num, origin);
6003
6004 return bgp_vty_return(vty, ret);
6005 }
6006
6007 ALIAS_HIDDEN(
6008 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
6009 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6010 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6011 "Accept as-path with my AS present in it\n"
6012 "Number of occurances of AS number\n"
6013 "Only accept my AS in the as-path if the route was originated in my AS\n")
6014
6015 DEFUN (no_neighbor_allowas_in,
6016 no_neighbor_allowas_in_cmd,
6017 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6018 NO_STR
6019 NEIGHBOR_STR
6020 NEIGHBOR_ADDR_STR2
6021 "allow local ASN appears in aspath attribute\n"
6022 "Number of occurances of AS number\n"
6023 "Only accept my AS in the as-path if the route was originated in my AS\n")
6024 {
6025 int idx_peer = 2;
6026 int ret;
6027 struct peer *peer;
6028
6029 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6030 if (!peer)
6031 return CMD_WARNING_CONFIG_FAILED;
6032
6033 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
6034 bgp_node_safi(vty));
6035
6036 return bgp_vty_return(vty, ret);
6037 }
6038
6039 ALIAS_HIDDEN(
6040 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
6041 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6042 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6043 "allow local ASN appears in aspath attribute\n"
6044 "Number of occurances of AS number\n"
6045 "Only accept my AS in the as-path if the route was originated in my AS\n")
6046
6047 DEFUN (neighbor_ttl_security,
6048 neighbor_ttl_security_cmd,
6049 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6050 NEIGHBOR_STR
6051 NEIGHBOR_ADDR_STR2
6052 "BGP ttl-security parameters\n"
6053 "Specify the maximum number of hops to the BGP peer\n"
6054 "Number of hops to BGP peer\n")
6055 {
6056 int idx_peer = 1;
6057 int idx_number = 4;
6058 struct peer *peer;
6059 int gtsm_hops;
6060
6061 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6062 if (!peer)
6063 return CMD_WARNING_CONFIG_FAILED;
6064
6065 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6066
6067 /*
6068 * If 'neighbor swpX', then this is for directly connected peers,
6069 * we should not accept a ttl-security hops value greater than 1.
6070 */
6071 if (peer->conf_if && (gtsm_hops > 1)) {
6072 vty_out(vty,
6073 "%s is directly connected peer, hops cannot exceed 1\n",
6074 argv[idx_peer]->arg);
6075 return CMD_WARNING_CONFIG_FAILED;
6076 }
6077
6078 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6079 }
6080
6081 DEFUN (no_neighbor_ttl_security,
6082 no_neighbor_ttl_security_cmd,
6083 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6084 NO_STR
6085 NEIGHBOR_STR
6086 NEIGHBOR_ADDR_STR2
6087 "BGP ttl-security parameters\n"
6088 "Specify the maximum number of hops to the BGP peer\n"
6089 "Number of hops to BGP peer\n")
6090 {
6091 int idx_peer = 2;
6092 struct peer *peer;
6093
6094 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6095 if (!peer)
6096 return CMD_WARNING_CONFIG_FAILED;
6097
6098 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6099 }
6100
6101 DEFUN (neighbor_addpath_tx_all_paths,
6102 neighbor_addpath_tx_all_paths_cmd,
6103 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6104 NEIGHBOR_STR
6105 NEIGHBOR_ADDR_STR2
6106 "Use addpath to advertise all paths to a neighbor\n")
6107 {
6108 int idx_peer = 1;
6109 struct peer *peer;
6110
6111 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6112 if (!peer)
6113 return CMD_WARNING_CONFIG_FAILED;
6114
6115 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6116 bgp_node_safi(vty),
6117 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6118 }
6119
6120 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6121 neighbor_addpath_tx_all_paths_hidden_cmd,
6122 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6123 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6124 "Use addpath to advertise all paths to a neighbor\n")
6125
6126 DEFUN (no_neighbor_addpath_tx_all_paths,
6127 no_neighbor_addpath_tx_all_paths_cmd,
6128 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6129 NO_STR
6130 NEIGHBOR_STR
6131 NEIGHBOR_ADDR_STR2
6132 "Use addpath to advertise all paths to a neighbor\n")
6133 {
6134 int idx_peer = 2;
6135 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6136 bgp_node_afi(vty), bgp_node_safi(vty),
6137 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6138 }
6139
6140 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6141 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6142 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6143 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6144 "Use addpath to advertise all paths to a neighbor\n")
6145
6146 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6147 neighbor_addpath_tx_bestpath_per_as_cmd,
6148 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6149 NEIGHBOR_STR
6150 NEIGHBOR_ADDR_STR2
6151 "Use addpath to advertise the bestpath per each neighboring AS\n")
6152 {
6153 int idx_peer = 1;
6154 struct peer *peer;
6155
6156 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6157 if (!peer)
6158 return CMD_WARNING_CONFIG_FAILED;
6159
6160 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6161 bgp_node_safi(vty),
6162 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6163 }
6164
6165 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6166 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6167 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6168 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6169 "Use addpath to advertise the bestpath per each neighboring AS\n")
6170
6171 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6172 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6173 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6174 NO_STR
6175 NEIGHBOR_STR
6176 NEIGHBOR_ADDR_STR2
6177 "Use addpath to advertise the bestpath per each neighboring AS\n")
6178 {
6179 int idx_peer = 2;
6180 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6181 bgp_node_afi(vty), bgp_node_safi(vty),
6182 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6183 }
6184
6185 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6186 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6187 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6188 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6189 "Use addpath to advertise the bestpath per each neighboring AS\n")
6190
6191 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6192 struct ecommunity **list)
6193 {
6194 struct ecommunity *ecom = NULL;
6195 struct ecommunity *ecomadd;
6196
6197 for (; argc; --argc, ++argv) {
6198
6199 ecomadd = ecommunity_str2com(argv[0]->arg,
6200 ECOMMUNITY_ROUTE_TARGET, 0);
6201 if (!ecomadd) {
6202 vty_out(vty, "Malformed community-list value\n");
6203 if (ecom)
6204 ecommunity_free(&ecom);
6205 return CMD_WARNING_CONFIG_FAILED;
6206 }
6207
6208 if (ecom) {
6209 ecommunity_merge(ecom, ecomadd);
6210 ecommunity_free(&ecomadd);
6211 } else {
6212 ecom = ecomadd;
6213 }
6214 }
6215
6216 if (*list) {
6217 ecommunity_free(&*list);
6218 }
6219 *list = ecom;
6220
6221 return CMD_SUCCESS;
6222 }
6223
6224 /*
6225 * v2vimport is true if we are handling a `import vrf ...` command
6226 */
6227 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6228 {
6229 afi_t afi;
6230
6231 switch (vty->node) {
6232 case BGP_IPV4_NODE:
6233 afi = AFI_IP;
6234 break;
6235 case BGP_IPV6_NODE:
6236 afi = AFI_IP6;
6237 break;
6238 default:
6239 vty_out(vty,
6240 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6241 return AFI_MAX;
6242 }
6243
6244 if (!v2vimport) {
6245 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6246 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6247 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6248 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6249 vty_out(vty,
6250 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6251 return AFI_MAX;
6252 }
6253 } else {
6254 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6255 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6256 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6257 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6258 vty_out(vty,
6259 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6260 return AFI_MAX;
6261 }
6262 }
6263 return afi;
6264 }
6265
6266 DEFPY (af_rd_vpn_export,
6267 af_rd_vpn_export_cmd,
6268 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6269 NO_STR
6270 "Specify route distinguisher\n"
6271 "Between current address-family and vpn\n"
6272 "For routes leaked from current address-family to vpn\n"
6273 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6274 {
6275 VTY_DECLVAR_CONTEXT(bgp, bgp);
6276 struct prefix_rd prd;
6277 int ret;
6278 afi_t afi;
6279 int idx = 0;
6280 int yes = 1;
6281
6282 if (argv_find(argv, argc, "no", &idx))
6283 yes = 0;
6284
6285 if (yes) {
6286 ret = str2prefix_rd(rd_str, &prd);
6287 if (!ret) {
6288 vty_out(vty, "%% Malformed rd\n");
6289 return CMD_WARNING_CONFIG_FAILED;
6290 }
6291 }
6292
6293 afi = vpn_policy_getafi(vty, bgp, false);
6294 if (afi == AFI_MAX)
6295 return CMD_WARNING_CONFIG_FAILED;
6296
6297 /*
6298 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6299 */
6300 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6301 bgp_get_default(), bgp);
6302
6303 if (yes) {
6304 bgp->vpn_policy[afi].tovpn_rd = prd;
6305 SET_FLAG(bgp->vpn_policy[afi].flags,
6306 BGP_VPN_POLICY_TOVPN_RD_SET);
6307 } else {
6308 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6309 BGP_VPN_POLICY_TOVPN_RD_SET);
6310 }
6311
6312 /* post-change: re-export vpn routes */
6313 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6314 bgp_get_default(), bgp);
6315
6316 return CMD_SUCCESS;
6317 }
6318
6319 ALIAS (af_rd_vpn_export,
6320 af_no_rd_vpn_export_cmd,
6321 "no rd vpn export",
6322 NO_STR
6323 "Specify route distinguisher\n"
6324 "Between current address-family and vpn\n"
6325 "For routes leaked from current address-family to vpn\n")
6326
6327 DEFPY (af_label_vpn_export,
6328 af_label_vpn_export_cmd,
6329 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6330 NO_STR
6331 "label value for VRF\n"
6332 "Between current address-family and vpn\n"
6333 "For routes leaked from current address-family to vpn\n"
6334 "Label Value <0-1048575>\n"
6335 "Automatically assign a label\n")
6336 {
6337 VTY_DECLVAR_CONTEXT(bgp, bgp);
6338 mpls_label_t label = MPLS_LABEL_NONE;
6339 afi_t afi;
6340 int idx = 0;
6341 int yes = 1;
6342
6343 if (argv_find(argv, argc, "no", &idx))
6344 yes = 0;
6345
6346 /* If "no ...", squash trailing parameter */
6347 if (!yes)
6348 label_auto = NULL;
6349
6350 if (yes) {
6351 if (!label_auto)
6352 label = label_val; /* parser should force unsigned */
6353 }
6354
6355 afi = vpn_policy_getafi(vty, bgp, false);
6356 if (afi == AFI_MAX)
6357 return CMD_WARNING_CONFIG_FAILED;
6358
6359
6360 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6361 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6362 /* no change */
6363 return CMD_SUCCESS;
6364
6365 /*
6366 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6367 */
6368 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6369 bgp_get_default(), bgp);
6370
6371 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6372 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6373
6374 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6375
6376 /*
6377 * label has previously been automatically
6378 * assigned by labelpool: release it
6379 *
6380 * NB if tovpn_label == MPLS_LABEL_NONE it
6381 * means the automatic assignment is in flight
6382 * and therefore the labelpool callback must
6383 * detect that the auto label is not needed.
6384 */
6385
6386 bgp_lp_release(LP_TYPE_VRF,
6387 &bgp->vpn_policy[afi],
6388 bgp->vpn_policy[afi].tovpn_label);
6389 }
6390 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6391 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6392 }
6393
6394 bgp->vpn_policy[afi].tovpn_label = label;
6395 if (label_auto) {
6396 SET_FLAG(bgp->vpn_policy[afi].flags,
6397 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6398 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6399 vpn_leak_label_callback);
6400 }
6401
6402 /* post-change: re-export vpn routes */
6403 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6404 bgp_get_default(), bgp);
6405
6406 return CMD_SUCCESS;
6407 }
6408
6409 ALIAS (af_label_vpn_export,
6410 af_no_label_vpn_export_cmd,
6411 "no label vpn export",
6412 NO_STR
6413 "label value for VRF\n"
6414 "Between current address-family and vpn\n"
6415 "For routes leaked from current address-family to vpn\n")
6416
6417 DEFPY (af_nexthop_vpn_export,
6418 af_nexthop_vpn_export_cmd,
6419 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6420 NO_STR
6421 "Specify next hop to use for VRF advertised prefixes\n"
6422 "Between current address-family and vpn\n"
6423 "For routes leaked from current address-family to vpn\n"
6424 "IPv4 prefix\n"
6425 "IPv6 prefix\n")
6426 {
6427 VTY_DECLVAR_CONTEXT(bgp, bgp);
6428 afi_t afi;
6429 struct prefix p;
6430 int idx = 0;
6431 int yes = 1;
6432
6433 if (argv_find(argv, argc, "no", &idx))
6434 yes = 0;
6435
6436 if (yes) {
6437 if (!sockunion2hostprefix(nexthop_str, &p))
6438 return CMD_WARNING_CONFIG_FAILED;
6439 }
6440
6441 afi = vpn_policy_getafi(vty, bgp, false);
6442 if (afi == AFI_MAX)
6443 return CMD_WARNING_CONFIG_FAILED;
6444
6445 /*
6446 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6447 */
6448 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6449 bgp_get_default(), bgp);
6450
6451 if (yes) {
6452 bgp->vpn_policy[afi].tovpn_nexthop = p;
6453 SET_FLAG(bgp->vpn_policy[afi].flags,
6454 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6455 } else {
6456 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6457 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6458 }
6459
6460 /* post-change: re-export vpn routes */
6461 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6462 bgp_get_default(), bgp);
6463
6464 return CMD_SUCCESS;
6465 }
6466
6467 ALIAS (af_nexthop_vpn_export,
6468 af_no_nexthop_vpn_export_cmd,
6469 "no nexthop vpn export",
6470 NO_STR
6471 "Specify next hop to use for VRF advertised prefixes\n"
6472 "Between current address-family and vpn\n"
6473 "For routes leaked from current address-family to vpn\n")
6474
6475 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6476 {
6477 if (!strcmp(dstr, "import")) {
6478 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6479 } else if (!strcmp(dstr, "export")) {
6480 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6481 } else if (!strcmp(dstr, "both")) {
6482 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6483 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6484 } else {
6485 vty_out(vty, "%% direction parse error\n");
6486 return CMD_WARNING_CONFIG_FAILED;
6487 }
6488 return CMD_SUCCESS;
6489 }
6490
6491 DEFPY (af_rt_vpn_imexport,
6492 af_rt_vpn_imexport_cmd,
6493 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6494 NO_STR
6495 "Specify route target list\n"
6496 "Specify route target list\n"
6497 "Between current address-family and vpn\n"
6498 "For routes leaked from vpn to current address-family: match any\n"
6499 "For routes leaked from current address-family to vpn: set\n"
6500 "both import: match any and export: set\n"
6501 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6502 {
6503 VTY_DECLVAR_CONTEXT(bgp, bgp);
6504 int ret;
6505 struct ecommunity *ecom = NULL;
6506 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6507 vpn_policy_direction_t dir;
6508 afi_t afi;
6509 int idx = 0;
6510 int yes = 1;
6511
6512 if (argv_find(argv, argc, "no", &idx))
6513 yes = 0;
6514
6515 afi = vpn_policy_getafi(vty, bgp, false);
6516 if (afi == AFI_MAX)
6517 return CMD_WARNING_CONFIG_FAILED;
6518
6519 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6520 if (ret != CMD_SUCCESS)
6521 return ret;
6522
6523 if (yes) {
6524 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6525 vty_out(vty, "%% Missing RTLIST\n");
6526 return CMD_WARNING_CONFIG_FAILED;
6527 }
6528 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6529 if (ret != CMD_SUCCESS) {
6530 return ret;
6531 }
6532 }
6533
6534 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6535 if (!dodir[dir])
6536 continue;
6537
6538 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6539
6540 if (yes) {
6541 if (bgp->vpn_policy[afi].rtlist[dir])
6542 ecommunity_free(
6543 &bgp->vpn_policy[afi].rtlist[dir]);
6544 bgp->vpn_policy[afi].rtlist[dir] =
6545 ecommunity_dup(ecom);
6546 } else {
6547 if (bgp->vpn_policy[afi].rtlist[dir])
6548 ecommunity_free(
6549 &bgp->vpn_policy[afi].rtlist[dir]);
6550 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6551 }
6552
6553 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6554 }
6555
6556 if (ecom)
6557 ecommunity_free(&ecom);
6558
6559 return CMD_SUCCESS;
6560 }
6561
6562 ALIAS (af_rt_vpn_imexport,
6563 af_no_rt_vpn_imexport_cmd,
6564 "no <rt|route-target> vpn <import|export|both>$direction_str",
6565 NO_STR
6566 "Specify route target list\n"
6567 "Specify route target list\n"
6568 "Between current address-family and vpn\n"
6569 "For routes leaked from vpn to current address-family\n"
6570 "For routes leaked from current address-family to vpn\n"
6571 "both import and export\n")
6572
6573 DEFPY (af_route_map_vpn_imexport,
6574 af_route_map_vpn_imexport_cmd,
6575 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6576 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6577 NO_STR
6578 "Specify route map\n"
6579 "Between current address-family and vpn\n"
6580 "For routes leaked from vpn to current address-family\n"
6581 "For routes leaked from current address-family to vpn\n"
6582 "name of route-map\n")
6583 {
6584 VTY_DECLVAR_CONTEXT(bgp, bgp);
6585 int ret;
6586 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6587 vpn_policy_direction_t dir;
6588 afi_t afi;
6589 int idx = 0;
6590 int yes = 1;
6591
6592 if (argv_find(argv, argc, "no", &idx))
6593 yes = 0;
6594
6595 afi = vpn_policy_getafi(vty, bgp, false);
6596 if (afi == AFI_MAX)
6597 return CMD_WARNING_CONFIG_FAILED;
6598
6599 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6600 if (ret != CMD_SUCCESS)
6601 return ret;
6602
6603 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6604 if (!dodir[dir])
6605 continue;
6606
6607 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6608
6609 if (yes) {
6610 if (bgp->vpn_policy[afi].rmap_name[dir])
6611 XFREE(MTYPE_ROUTE_MAP_NAME,
6612 bgp->vpn_policy[afi].rmap_name[dir]);
6613 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6614 MTYPE_ROUTE_MAP_NAME, rmap_str);
6615 bgp->vpn_policy[afi].rmap[dir] =
6616 route_map_lookup_by_name(rmap_str);
6617 if (!bgp->vpn_policy[afi].rmap[dir])
6618 return CMD_SUCCESS;
6619 } else {
6620 if (bgp->vpn_policy[afi].rmap_name[dir])
6621 XFREE(MTYPE_ROUTE_MAP_NAME,
6622 bgp->vpn_policy[afi].rmap_name[dir]);
6623 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6624 bgp->vpn_policy[afi].rmap[dir] = NULL;
6625 }
6626
6627 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6628 }
6629
6630 return CMD_SUCCESS;
6631 }
6632
6633 ALIAS (af_route_map_vpn_imexport,
6634 af_no_route_map_vpn_imexport_cmd,
6635 "no route-map vpn <import|export>$direction_str",
6636 NO_STR
6637 "Specify route map\n"
6638 "Between current address-family and vpn\n"
6639 "For routes leaked from vpn to current address-family\n"
6640 "For routes leaked from current address-family to vpn\n")
6641
6642 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6643 "[no] import vrf route-map RMAP$rmap_str",
6644 NO_STR
6645 "Import routes from another VRF\n"
6646 "Vrf routes being filtered\n"
6647 "Specify route map\n"
6648 "name of route-map\n")
6649 {
6650 VTY_DECLVAR_CONTEXT(bgp, bgp);
6651 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6652 afi_t afi;
6653 int idx = 0;
6654 int yes = 1;
6655 struct bgp *bgp_default;
6656
6657 if (argv_find(argv, argc, "no", &idx))
6658 yes = 0;
6659
6660 afi = vpn_policy_getafi(vty, bgp, true);
6661 if (afi == AFI_MAX)
6662 return CMD_WARNING_CONFIG_FAILED;
6663
6664 bgp_default = bgp_get_default();
6665 if (!bgp_default) {
6666 int32_t ret;
6667 as_t as = bgp->as;
6668
6669 /* Auto-create assuming the same AS */
6670 ret = bgp_get(&bgp_default, &as, NULL,
6671 BGP_INSTANCE_TYPE_DEFAULT);
6672
6673 if (ret) {
6674 vty_out(vty,
6675 "VRF default is not configured as a bgp instance\n");
6676 return CMD_WARNING;
6677 }
6678 }
6679
6680 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6681
6682 if (yes) {
6683 if (bgp->vpn_policy[afi].rmap_name[dir])
6684 XFREE(MTYPE_ROUTE_MAP_NAME,
6685 bgp->vpn_policy[afi].rmap_name[dir]);
6686 bgp->vpn_policy[afi].rmap_name[dir] =
6687 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6688 bgp->vpn_policy[afi].rmap[dir] =
6689 route_map_lookup_by_name(rmap_str);
6690 if (!bgp->vpn_policy[afi].rmap[dir])
6691 return CMD_SUCCESS;
6692 } else {
6693 if (bgp->vpn_policy[afi].rmap_name[dir])
6694 XFREE(MTYPE_ROUTE_MAP_NAME,
6695 bgp->vpn_policy[afi].rmap_name[dir]);
6696 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6697 bgp->vpn_policy[afi].rmap[dir] = NULL;
6698 }
6699
6700 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6701
6702 return CMD_SUCCESS;
6703 }
6704
6705 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6706 "no import vrf route-map",
6707 NO_STR
6708 "Import routes from another VRF\n"
6709 "Vrf routes being filtered\n"
6710 "Specify route map\n")
6711
6712 DEFPY (bgp_imexport_vrf,
6713 bgp_imexport_vrf_cmd,
6714 "[no] import vrf NAME$import_name",
6715 NO_STR
6716 "Import routes from another VRF\n"
6717 "VRF to import from\n"
6718 "The name of the VRF\n")
6719 {
6720 VTY_DECLVAR_CONTEXT(bgp, bgp);
6721 struct listnode *node;
6722 struct bgp *vrf_bgp, *bgp_default;
6723 int32_t ret = 0;
6724 as_t as = bgp->as;
6725 bool remove = false;
6726 int32_t idx = 0;
6727 char *vname;
6728 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6729 safi_t safi;
6730 afi_t afi;
6731
6732 if (argv_find(argv, argc, "no", &idx))
6733 remove = true;
6734
6735 afi = vpn_policy_getafi(vty, bgp, true);
6736 if (afi == AFI_MAX)
6737 return CMD_WARNING_CONFIG_FAILED;
6738
6739 safi = bgp_node_safi(vty);
6740
6741 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6742 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6743 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6744 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6745 remove ? "unimport" : "import", import_name);
6746 return CMD_WARNING;
6747 }
6748
6749 bgp_default = bgp_get_default();
6750 if (!bgp_default) {
6751 /* Auto-create assuming the same AS */
6752 ret = bgp_get(&bgp_default, &as, NULL,
6753 BGP_INSTANCE_TYPE_DEFAULT);
6754
6755 if (ret) {
6756 vty_out(vty,
6757 "VRF default is not configured as a bgp instance\n");
6758 return CMD_WARNING;
6759 }
6760 }
6761
6762 vrf_bgp = bgp_lookup_by_name(import_name);
6763 if (!vrf_bgp) {
6764 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6765 vrf_bgp = bgp_default;
6766 else
6767 /* Auto-create assuming the same AS */
6768 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6769
6770 if (ret) {
6771 vty_out(vty,
6772 "VRF %s is not configured as a bgp instance\n",
6773 import_name);
6774 return CMD_WARNING;
6775 }
6776 }
6777
6778 if (remove) {
6779 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6780 } else {
6781 /* Already importing from "import_vrf"? */
6782 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6783 vname)) {
6784 if (strcmp(vname, import_name) == 0)
6785 return CMD_WARNING;
6786 }
6787
6788 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6789 }
6790
6791 return CMD_SUCCESS;
6792 }
6793
6794 /* This command is valid only in a bgp vrf instance or the default instance */
6795 DEFPY (bgp_imexport_vpn,
6796 bgp_imexport_vpn_cmd,
6797 "[no] <import|export>$direction_str vpn",
6798 NO_STR
6799 "Import routes to this address-family\n"
6800 "Export routes from this address-family\n"
6801 "to/from default instance VPN RIB\n")
6802 {
6803 VTY_DECLVAR_CONTEXT(bgp, bgp);
6804 int previous_state;
6805 afi_t afi;
6806 safi_t safi;
6807 int idx = 0;
6808 int yes = 1;
6809 int flag;
6810 vpn_policy_direction_t dir;
6811
6812 if (argv_find(argv, argc, "no", &idx))
6813 yes = 0;
6814
6815 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6816 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6817
6818 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6819 return CMD_WARNING_CONFIG_FAILED;
6820 }
6821
6822 afi = bgp_node_afi(vty);
6823 safi = bgp_node_safi(vty);
6824 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6825 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6826 return CMD_WARNING_CONFIG_FAILED;
6827 }
6828
6829 if (!strcmp(direction_str, "import")) {
6830 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6831 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6832 } else if (!strcmp(direction_str, "export")) {
6833 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6834 dir = BGP_VPN_POLICY_DIR_TOVPN;
6835 } else {
6836 vty_out(vty, "%% unknown direction %s\n", direction_str);
6837 return CMD_WARNING_CONFIG_FAILED;
6838 }
6839
6840 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6841
6842 if (yes) {
6843 SET_FLAG(bgp->af_flags[afi][safi], flag);
6844 if (!previous_state) {
6845 /* trigger export current vrf */
6846 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6847 }
6848 } else {
6849 if (previous_state) {
6850 /* trigger un-export current vrf */
6851 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6852 }
6853 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6854 }
6855
6856 return CMD_SUCCESS;
6857 }
6858
6859 DEFPY (af_routetarget_import,
6860 af_routetarget_import_cmd,
6861 "[no] <rt|route-target> redirect import RTLIST...",
6862 NO_STR
6863 "Specify route target list\n"
6864 "Specify route target list\n"
6865 "Flow-spec redirect type route target\n"
6866 "Import routes to this address-family\n"
6867 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6868 {
6869 VTY_DECLVAR_CONTEXT(bgp, bgp);
6870 int ret;
6871 struct ecommunity *ecom = NULL;
6872 afi_t afi;
6873 int idx = 0;
6874 int yes = 1;
6875
6876 if (argv_find(argv, argc, "no", &idx))
6877 yes = 0;
6878
6879 afi = vpn_policy_getafi(vty, bgp, false);
6880 if (afi == AFI_MAX)
6881 return CMD_WARNING_CONFIG_FAILED;
6882
6883 if (yes) {
6884 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6885 vty_out(vty, "%% Missing RTLIST\n");
6886 return CMD_WARNING_CONFIG_FAILED;
6887 }
6888 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6889 if (ret != CMD_SUCCESS)
6890 return ret;
6891 }
6892
6893 if (yes) {
6894 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6895 ecommunity_free(&bgp->vpn_policy[afi]
6896 .import_redirect_rtlist);
6897 bgp->vpn_policy[afi].import_redirect_rtlist =
6898 ecommunity_dup(ecom);
6899 } else {
6900 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6901 ecommunity_free(&bgp->vpn_policy[afi]
6902 .import_redirect_rtlist);
6903 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6904 }
6905
6906 if (ecom)
6907 ecommunity_free(&ecom);
6908
6909 return CMD_SUCCESS;
6910 }
6911
6912 DEFUN_NOSH (address_family_ipv4_safi,
6913 address_family_ipv4_safi_cmd,
6914 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6915 "Enter Address Family command mode\n"
6916 "Address Family\n"
6917 BGP_SAFI_WITH_LABEL_HELP_STR)
6918 {
6919
6920 if (argc == 3) {
6921 VTY_DECLVAR_CONTEXT(bgp, bgp);
6922 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6923 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6924 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6925 && safi != SAFI_EVPN) {
6926 vty_out(vty,
6927 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6928 return CMD_WARNING_CONFIG_FAILED;
6929 }
6930 vty->node = bgp_node_type(AFI_IP, safi);
6931 } else
6932 vty->node = BGP_IPV4_NODE;
6933
6934 return CMD_SUCCESS;
6935 }
6936
6937 DEFUN_NOSH (address_family_ipv6_safi,
6938 address_family_ipv6_safi_cmd,
6939 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6940 "Enter Address Family command mode\n"
6941 "Address Family\n"
6942 BGP_SAFI_WITH_LABEL_HELP_STR)
6943 {
6944 if (argc == 3) {
6945 VTY_DECLVAR_CONTEXT(bgp, bgp);
6946 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6947 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6948 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6949 && safi != SAFI_EVPN) {
6950 vty_out(vty,
6951 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6952 return CMD_WARNING_CONFIG_FAILED;
6953 }
6954 vty->node = bgp_node_type(AFI_IP6, safi);
6955 } else
6956 vty->node = BGP_IPV6_NODE;
6957
6958 return CMD_SUCCESS;
6959 }
6960
6961 #ifdef KEEP_OLD_VPN_COMMANDS
6962 DEFUN_NOSH (address_family_vpnv4,
6963 address_family_vpnv4_cmd,
6964 "address-family vpnv4 [unicast]",
6965 "Enter Address Family command mode\n"
6966 "Address Family\n"
6967 "Address Family modifier\n")
6968 {
6969 vty->node = BGP_VPNV4_NODE;
6970 return CMD_SUCCESS;
6971 }
6972
6973 DEFUN_NOSH (address_family_vpnv6,
6974 address_family_vpnv6_cmd,
6975 "address-family vpnv6 [unicast]",
6976 "Enter Address Family command mode\n"
6977 "Address Family\n"
6978 "Address Family modifier\n")
6979 {
6980 vty->node = BGP_VPNV6_NODE;
6981 return CMD_SUCCESS;
6982 }
6983 #endif
6984
6985 DEFUN_NOSH (address_family_evpn,
6986 address_family_evpn_cmd,
6987 "address-family l2vpn evpn",
6988 "Enter Address Family command mode\n"
6989 "Address Family\n"
6990 "Address Family modifier\n")
6991 {
6992 VTY_DECLVAR_CONTEXT(bgp, bgp);
6993 vty->node = BGP_EVPN_NODE;
6994 return CMD_SUCCESS;
6995 }
6996
6997 DEFUN_NOSH (exit_address_family,
6998 exit_address_family_cmd,
6999 "exit-address-family",
7000 "Exit from Address Family configuration mode\n")
7001 {
7002 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
7003 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
7004 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
7005 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
7006 || vty->node == BGP_EVPN_NODE
7007 || vty->node == BGP_FLOWSPECV4_NODE
7008 || vty->node == BGP_FLOWSPECV6_NODE)
7009 vty->node = BGP_NODE;
7010 return CMD_SUCCESS;
7011 }
7012
7013 /* Recalculate bestpath and re-advertise a prefix */
7014 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
7015 const char *ip_str, afi_t afi, safi_t safi,
7016 struct prefix_rd *prd)
7017 {
7018 int ret;
7019 struct prefix match;
7020 struct bgp_node *rn;
7021 struct bgp_node *rm;
7022 struct bgp *bgp;
7023 struct bgp_table *table;
7024 struct bgp_table *rib;
7025
7026 /* BGP structure lookup. */
7027 if (view_name) {
7028 bgp = bgp_lookup_by_name(view_name);
7029 if (bgp == NULL) {
7030 vty_out(vty, "%% Can't find BGP instance %s\n",
7031 view_name);
7032 return CMD_WARNING;
7033 }
7034 } else {
7035 bgp = bgp_get_default();
7036 if (bgp == NULL) {
7037 vty_out(vty, "%% No BGP process is configured\n");
7038 return CMD_WARNING;
7039 }
7040 }
7041
7042 /* Check IP address argument. */
7043 ret = str2prefix(ip_str, &match);
7044 if (!ret) {
7045 vty_out(vty, "%% address is malformed\n");
7046 return CMD_WARNING;
7047 }
7048
7049 match.family = afi2family(afi);
7050 rib = bgp->rib[afi][safi];
7051
7052 if (safi == SAFI_MPLS_VPN) {
7053 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
7054 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
7055 continue;
7056
7057 if ((table = rn->info) != NULL) {
7058 if ((rm = bgp_node_match(table, &match))
7059 != NULL) {
7060 if (rm->p.prefixlen
7061 == match.prefixlen) {
7062 SET_FLAG(rn->flags,
7063 BGP_NODE_USER_CLEAR);
7064 bgp_process(bgp, rm, afi, safi);
7065 }
7066 bgp_unlock_node(rm);
7067 }
7068 }
7069 }
7070 } else {
7071 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7072 if (rn->p.prefixlen == match.prefixlen) {
7073 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7074 bgp_process(bgp, rn, afi, safi);
7075 }
7076 bgp_unlock_node(rn);
7077 }
7078 }
7079
7080 return CMD_SUCCESS;
7081 }
7082
7083 /* one clear bgp command to rule them all */
7084 DEFUN (clear_ip_bgp_all,
7085 clear_ip_bgp_all_cmd,
7086 "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>]",
7087 CLEAR_STR
7088 IP_STR
7089 BGP_STR
7090 BGP_INSTANCE_HELP_STR
7091 BGP_AFI_HELP_STR
7092 BGP_SAFI_WITH_LABEL_HELP_STR
7093 "Clear all peers\n"
7094 "BGP neighbor address to clear\n"
7095 "BGP IPv6 neighbor to clear\n"
7096 "BGP neighbor on interface to clear\n"
7097 "Clear peers with the AS number\n"
7098 "Clear all external peers\n"
7099 "Clear all members of peer-group\n"
7100 "BGP peer-group name\n"
7101 BGP_SOFT_STR
7102 BGP_SOFT_IN_STR
7103 BGP_SOFT_OUT_STR
7104 BGP_SOFT_IN_STR
7105 "Push out prefix-list ORF and do inbound soft reconfig\n"
7106 BGP_SOFT_OUT_STR)
7107 {
7108 char *vrf = NULL;
7109
7110 afi_t afi = AFI_IP6;
7111 safi_t safi = SAFI_UNICAST;
7112 enum clear_sort clr_sort = clear_peer;
7113 enum bgp_clear_type clr_type;
7114 char *clr_arg = NULL;
7115
7116 int idx = 0;
7117
7118 /* clear [ip] bgp */
7119 if (argv_find(argv, argc, "ip", &idx))
7120 afi = AFI_IP;
7121
7122 /* [<view|vrf> VIEWVRFNAME] */
7123 if (argv_find(argv, argc, "view", &idx)
7124 || argv_find(argv, argc, "vrf", &idx)) {
7125 vrf = argv[idx + 1]->arg;
7126 idx += 2;
7127 }
7128
7129 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7130 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7131 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7132
7133 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7134 if (argv_find(argv, argc, "*", &idx)) {
7135 clr_sort = clear_all;
7136 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7137 clr_sort = clear_peer;
7138 clr_arg = argv[idx]->arg;
7139 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7140 clr_sort = clear_peer;
7141 clr_arg = argv[idx]->arg;
7142 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7143 clr_sort = clear_group;
7144 idx++;
7145 clr_arg = argv[idx]->arg;
7146 } else if (argv_find(argv, argc, "WORD", &idx)) {
7147 clr_sort = clear_peer;
7148 clr_arg = argv[idx]->arg;
7149 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7150 clr_sort = clear_as;
7151 clr_arg = argv[idx]->arg;
7152 } else if (argv_find(argv, argc, "external", &idx)) {
7153 clr_sort = clear_external;
7154 }
7155
7156 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7157 if (argv_find(argv, argc, "soft", &idx)) {
7158 if (argv_find(argv, argc, "in", &idx)
7159 || argv_find(argv, argc, "out", &idx))
7160 clr_type = strmatch(argv[idx]->text, "in")
7161 ? BGP_CLEAR_SOFT_IN
7162 : BGP_CLEAR_SOFT_OUT;
7163 else
7164 clr_type = BGP_CLEAR_SOFT_BOTH;
7165 } else if (argv_find(argv, argc, "in", &idx)) {
7166 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7167 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7168 : BGP_CLEAR_SOFT_IN;
7169 } else if (argv_find(argv, argc, "out", &idx)) {
7170 clr_type = BGP_CLEAR_SOFT_OUT;
7171 } else
7172 clr_type = BGP_CLEAR_SOFT_NONE;
7173
7174 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7175 }
7176
7177 DEFUN (clear_ip_bgp_prefix,
7178 clear_ip_bgp_prefix_cmd,
7179 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7180 CLEAR_STR
7181 IP_STR
7182 BGP_STR
7183 BGP_INSTANCE_HELP_STR
7184 "Clear bestpath and re-advertise\n"
7185 "IPv4 prefix\n")
7186 {
7187 char *vrf = NULL;
7188 char *prefix = NULL;
7189
7190 int idx = 0;
7191
7192 /* [<view|vrf> VIEWVRFNAME] */
7193 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7194 vrf = argv[idx]->arg;
7195
7196 prefix = argv[argc - 1]->arg;
7197
7198 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7199 }
7200
7201 DEFUN (clear_bgp_ipv6_safi_prefix,
7202 clear_bgp_ipv6_safi_prefix_cmd,
7203 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7204 CLEAR_STR
7205 IP_STR
7206 BGP_STR
7207 "Address Family\n"
7208 BGP_SAFI_HELP_STR
7209 "Clear bestpath and re-advertise\n"
7210 "IPv6 prefix\n")
7211 {
7212 int idx_safi = 0;
7213 int idx_ipv6_prefix = 0;
7214 safi_t safi = SAFI_UNICAST;
7215 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7216 argv[idx_ipv6_prefix]->arg : NULL;
7217
7218 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7219 return bgp_clear_prefix(
7220 vty, NULL, prefix, AFI_IP6,
7221 safi, NULL);
7222 }
7223
7224 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7225 clear_bgp_instance_ipv6_safi_prefix_cmd,
7226 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7227 CLEAR_STR
7228 IP_STR
7229 BGP_STR
7230 BGP_INSTANCE_HELP_STR
7231 "Address Family\n"
7232 BGP_SAFI_HELP_STR
7233 "Clear bestpath and re-advertise\n"
7234 "IPv6 prefix\n")
7235 {
7236 int idx_word = 3;
7237 int idx_safi = 0;
7238 int idx_ipv6_prefix = 0;
7239 safi_t safi = SAFI_UNICAST;
7240 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7241 argv[idx_ipv6_prefix]->arg : NULL;
7242 /* [<view|vrf> VIEWVRFNAME] */
7243 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7244 argv[idx_word]->arg : NULL;
7245
7246 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7247
7248 return bgp_clear_prefix(
7249 vty, vrfview, prefix,
7250 AFI_IP6, safi, NULL);
7251 }
7252
7253 DEFUN (show_bgp_views,
7254 show_bgp_views_cmd,
7255 "show [ip] bgp views",
7256 SHOW_STR
7257 IP_STR
7258 BGP_STR
7259 "Show the defined BGP views\n")
7260 {
7261 struct list *inst = bm->bgp;
7262 struct listnode *node;
7263 struct bgp *bgp;
7264
7265 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7266 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7267 return CMD_WARNING;
7268 }
7269
7270 vty_out(vty, "Defined BGP views:\n");
7271 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7272 /* Skip VRFs. */
7273 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7274 continue;
7275 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7276 bgp->as);
7277 }
7278
7279 return CMD_SUCCESS;
7280 }
7281
7282 DEFUN (show_bgp_vrfs,
7283 show_bgp_vrfs_cmd,
7284 "show [ip] bgp vrfs [json]",
7285 SHOW_STR
7286 IP_STR
7287 BGP_STR
7288 "Show BGP VRFs\n"
7289 JSON_STR)
7290 {
7291 char buf[ETHER_ADDR_STRLEN];
7292 struct list *inst = bm->bgp;
7293 struct listnode *node;
7294 struct bgp *bgp;
7295 uint8_t uj = use_json(argc, argv);
7296 json_object *json = NULL;
7297 json_object *json_vrfs = NULL;
7298 int count = 0;
7299
7300 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7301 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7302 return CMD_WARNING;
7303 }
7304
7305 if (uj) {
7306 json = json_object_new_object();
7307 json_vrfs = json_object_new_object();
7308 }
7309
7310 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7311 const char *name, *type;
7312 struct peer *peer;
7313 struct listnode *node, *nnode;
7314 int peers_cfg, peers_estb;
7315 json_object *json_vrf = NULL;
7316
7317 /* Skip Views. */
7318 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7319 continue;
7320
7321 count++;
7322 if (!uj && count == 1)
7323 vty_out(vty,
7324 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7325 "Type", "Id", "routerId", "#PeersVfg",
7326 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7327
7328 peers_cfg = peers_estb = 0;
7329 if (uj)
7330 json_vrf = json_object_new_object();
7331
7332
7333 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7334 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7335 continue;
7336 peers_cfg++;
7337 if (peer->status == Established)
7338 peers_estb++;
7339 }
7340
7341 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7342 name = "Default";
7343 type = "DFLT";
7344 } else {
7345 name = bgp->name;
7346 type = "VRF";
7347 }
7348
7349
7350 if (uj) {
7351 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7352 ? -1
7353 : (int64_t)bgp->vrf_id;
7354 json_object_string_add(json_vrf, "type", type);
7355 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7356 json_object_string_add(json_vrf, "routerId",
7357 inet_ntoa(bgp->router_id));
7358 json_object_int_add(json_vrf, "numConfiguredPeers",
7359 peers_cfg);
7360 json_object_int_add(json_vrf, "numEstablishedPeers",
7361 peers_estb);
7362
7363 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7364 json_object_string_add(
7365 json_vrf, "rmac",
7366 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7367 json_object_object_add(json_vrfs, name, json_vrf);
7368 } else
7369 vty_out(vty,
7370 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7371 type,
7372 bgp->vrf_id == VRF_UNKNOWN ? -1
7373 : (int)bgp->vrf_id,
7374 inet_ntoa(bgp->router_id), peers_cfg,
7375 peers_estb, name, bgp->l3vni,
7376 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7377 }
7378
7379 if (uj) {
7380 json_object_object_add(json, "vrfs", json_vrfs);
7381
7382 json_object_int_add(json, "totalVrfs", count);
7383
7384 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7385 json, JSON_C_TO_STRING_PRETTY));
7386 json_object_free(json);
7387 } else {
7388 if (count)
7389 vty_out(vty,
7390 "\nTotal number of VRFs (including default): %d\n",
7391 count);
7392 }
7393
7394 return CMD_SUCCESS;
7395 }
7396
7397 static void show_address_entry(struct hash_backet *backet, void *args)
7398 {
7399 struct vty *vty = (struct vty *)args;
7400 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7401
7402 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7403 addr->refcnt);
7404 }
7405
7406 static void show_tip_entry(struct hash_backet *backet, void *args)
7407 {
7408 struct vty *vty = (struct vty *)args;
7409 struct tip_addr *tip = (struct tip_addr *)backet->data;
7410
7411 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7412 tip->refcnt);
7413 }
7414
7415 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7416 {
7417 vty_out(vty, "self nexthop database:\n");
7418 hash_iterate(bgp->address_hash,
7419 (void (*)(struct hash_backet *, void *))show_address_entry,
7420 vty);
7421
7422 vty_out(vty, "Tunnel-ip database:\n");
7423 hash_iterate(bgp->tip_hash,
7424 (void (*)(struct hash_backet *, void *))show_tip_entry,
7425 vty);
7426 }
7427
7428 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7429 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7430 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7431 "martian next-hops\n"
7432 "martian next-hop database\n")
7433 {
7434 struct bgp *bgp = NULL;
7435 int idx = 0;
7436
7437 if (argv_find(argv, argc, "view", &idx)
7438 || argv_find(argv, argc, "vrf", &idx))
7439 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7440 else
7441 bgp = bgp_get_default();
7442
7443 if (!bgp) {
7444 vty_out(vty, "%% No BGP process is configured\n");
7445 return CMD_WARNING;
7446 }
7447 bgp_show_martian_nexthops(vty, bgp);
7448
7449 return CMD_SUCCESS;
7450 }
7451
7452 DEFUN (show_bgp_memory,
7453 show_bgp_memory_cmd,
7454 "show [ip] bgp memory",
7455 SHOW_STR
7456 IP_STR
7457 BGP_STR
7458 "Global BGP memory statistics\n")
7459 {
7460 char memstrbuf[MTYPE_MEMSTR_LEN];
7461 unsigned long count;
7462
7463 /* RIB related usage stats */
7464 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7465 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7466 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7467 count * sizeof(struct bgp_node)));
7468
7469 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7470 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7471 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7472 count * sizeof(struct bgp_info)));
7473 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7474 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7475 count,
7476 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7477 count * sizeof(struct bgp_info_extra)));
7478
7479 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7480 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7481 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7482 count * sizeof(struct bgp_static)));
7483
7484 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7485 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7486 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7487 count * sizeof(struct bpacket)));
7488
7489 /* Adj-In/Out */
7490 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7491 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7492 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7493 count * sizeof(struct bgp_adj_in)));
7494 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7495 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7496 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7497 count * sizeof(struct bgp_adj_out)));
7498
7499 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7500 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7501 count,
7502 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7503 count * sizeof(struct bgp_nexthop_cache)));
7504
7505 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7506 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7507 count,
7508 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7509 count * sizeof(struct bgp_damp_info)));
7510
7511 /* Attributes */
7512 count = attr_count();
7513 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7514 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7515 count * sizeof(struct attr)));
7516
7517 if ((count = attr_unknown_count()))
7518 vty_out(vty, "%ld unknown attributes\n", count);
7519
7520 /* AS_PATH attributes */
7521 count = aspath_count();
7522 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7523 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7524 count * sizeof(struct aspath)));
7525
7526 count = mtype_stats_alloc(MTYPE_AS_SEG);
7527 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7528 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7529 count * sizeof(struct assegment)));
7530
7531 /* Other attributes */
7532 if ((count = community_count()))
7533 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7534 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7535 count * sizeof(struct community)));
7536 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7537 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7538 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7539 count * sizeof(struct ecommunity)));
7540 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7541 vty_out(vty,
7542 "%ld BGP large-community entries, using %s of memory\n",
7543 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7544 count * sizeof(struct lcommunity)));
7545
7546 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7547 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7548 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7549 count * sizeof(struct cluster_list)));
7550
7551 /* Peer related usage */
7552 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7553 vty_out(vty, "%ld peers, using %s of memory\n", count,
7554 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7555 count * sizeof(struct peer)));
7556
7557 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7558 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7559 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7560 count * sizeof(struct peer_group)));
7561
7562 /* Other */
7563 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7564 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7565 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7566 count * sizeof(struct hash)));
7567 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7568 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7569 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7570 count * sizeof(struct hash_backet)));
7571 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7572 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7573 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7574 count * sizeof(regex_t)));
7575 return CMD_SUCCESS;
7576 }
7577
7578 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7579 {
7580 json_object *bestpath = json_object_new_object();
7581
7582 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7583 json_object_string_add(bestpath, "asPath", "ignore");
7584
7585 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7586 json_object_string_add(bestpath, "asPath", "confed");
7587
7588 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7589 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7590 json_object_string_add(bestpath, "multiPathRelax",
7591 "as-set");
7592 else
7593 json_object_string_add(bestpath, "multiPathRelax",
7594 "true");
7595 } else
7596 json_object_string_add(bestpath, "multiPathRelax", "false");
7597
7598 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7599 json_object_string_add(bestpath, "compareRouterId", "true");
7600 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7601 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7602 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7603 json_object_string_add(bestpath, "med", "confed");
7604 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7605 json_object_string_add(bestpath, "med",
7606 "missing-as-worst");
7607 else
7608 json_object_string_add(bestpath, "med", "true");
7609 }
7610
7611 json_object_object_add(json, "bestPath", bestpath);
7612 }
7613
7614 /* Show BGP peer's summary information. */
7615 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7616 uint8_t use_json, json_object *json)
7617 {
7618 struct peer *peer;
7619 struct listnode *node, *nnode;
7620 unsigned int count = 0, dn_count = 0;
7621 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7622 char neighbor_buf[VTY_BUFSIZ];
7623 int neighbor_col_default_width = 16;
7624 int len;
7625 int max_neighbor_width = 0;
7626 int pfx_rcd_safi;
7627 json_object *json_peer = NULL;
7628 json_object *json_peers = NULL;
7629
7630 /* labeled-unicast routes are installed in the unicast table so in order
7631 * to
7632 * display the correct PfxRcd value we must look at SAFI_UNICAST
7633 */
7634 if (safi == SAFI_LABELED_UNICAST)
7635 pfx_rcd_safi = SAFI_UNICAST;
7636 else
7637 pfx_rcd_safi = safi;
7638
7639 if (use_json) {
7640 if (json == NULL)
7641 json = json_object_new_object();
7642
7643 json_peers = json_object_new_object();
7644 } else {
7645 /* Loop over all neighbors that will be displayed to determine
7646 * how many
7647 * characters are needed for the Neighbor column
7648 */
7649 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7650 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7651 continue;
7652
7653 if (peer->afc[afi][safi]) {
7654 memset(dn_flag, '\0', sizeof(dn_flag));
7655 if (peer_dynamic_neighbor(peer))
7656 dn_flag[0] = '*';
7657
7658 if (peer->hostname
7659 && bgp_flag_check(bgp,
7660 BGP_FLAG_SHOW_HOSTNAME))
7661 sprintf(neighbor_buf, "%s%s(%s) ",
7662 dn_flag, peer->hostname,
7663 peer->host);
7664 else
7665 sprintf(neighbor_buf, "%s%s ", dn_flag,
7666 peer->host);
7667
7668 len = strlen(neighbor_buf);
7669
7670 if (len > max_neighbor_width)
7671 max_neighbor_width = len;
7672 }
7673 }
7674
7675 /* Originally we displayed the Neighbor column as 16
7676 * characters wide so make that the default
7677 */
7678 if (max_neighbor_width < neighbor_col_default_width)
7679 max_neighbor_width = neighbor_col_default_width;
7680 }
7681
7682 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7683 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7684 continue;
7685
7686 if (!peer->afc[afi][safi])
7687 continue;
7688
7689 if (!count) {
7690 unsigned long ents;
7691 char memstrbuf[MTYPE_MEMSTR_LEN];
7692 int64_t vrf_id_ui;
7693
7694 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7695 ? -1
7696 : (int64_t)bgp->vrf_id;
7697
7698 /* Usage summary and header */
7699 if (use_json) {
7700 json_object_string_add(
7701 json, "routerId",
7702 inet_ntoa(bgp->router_id));
7703 json_object_int_add(json, "as", bgp->as);
7704 json_object_int_add(json, "vrfId", vrf_id_ui);
7705 json_object_string_add(
7706 json, "vrfName",
7707 (bgp->inst_type
7708 == BGP_INSTANCE_TYPE_DEFAULT)
7709 ? "Default"
7710 : bgp->name);
7711 } else {
7712 vty_out(vty,
7713 "BGP router identifier %s, local AS number %u vrf-id %d",
7714 inet_ntoa(bgp->router_id), bgp->as,
7715 bgp->vrf_id == VRF_UNKNOWN
7716 ? -1
7717 : (int)bgp->vrf_id);
7718 vty_out(vty, "\n");
7719 }
7720
7721 if (bgp_update_delay_configured(bgp)) {
7722 if (use_json) {
7723 json_object_int_add(
7724 json, "updateDelayLimit",
7725 bgp->v_update_delay);
7726
7727 if (bgp->v_update_delay
7728 != bgp->v_establish_wait)
7729 json_object_int_add(
7730 json,
7731 "updateDelayEstablishWait",
7732 bgp->v_establish_wait);
7733
7734 if (bgp_update_delay_active(bgp)) {
7735 json_object_string_add(
7736 json,
7737 "updateDelayFirstNeighbor",
7738 bgp->update_delay_begin_time);
7739 json_object_boolean_true_add(
7740 json,
7741 "updateDelayInProgress");
7742 } else {
7743 if (bgp->update_delay_over) {
7744 json_object_string_add(
7745 json,
7746 "updateDelayFirstNeighbor",
7747 bgp->update_delay_begin_time);
7748 json_object_string_add(
7749 json,
7750 "updateDelayBestpathResumed",
7751 bgp->update_delay_end_time);
7752 json_object_string_add(
7753 json,
7754 "updateDelayZebraUpdateResume",
7755 bgp->update_delay_zebra_resume_time);
7756 json_object_string_add(
7757 json,
7758 "updateDelayPeerUpdateResume",
7759 bgp->update_delay_peers_resume_time);
7760 }
7761 }
7762 } else {
7763 vty_out(vty,
7764 "Read-only mode update-delay limit: %d seconds\n",
7765 bgp->v_update_delay);
7766 if (bgp->v_update_delay
7767 != bgp->v_establish_wait)
7768 vty_out(vty,
7769 " Establish wait: %d seconds\n",
7770 bgp->v_establish_wait);
7771
7772 if (bgp_update_delay_active(bgp)) {
7773 vty_out(vty,
7774 " First neighbor established: %s\n",
7775 bgp->update_delay_begin_time);
7776 vty_out(vty,
7777 " Delay in progress\n");
7778 } else {
7779 if (bgp->update_delay_over) {
7780 vty_out(vty,
7781 " First neighbor established: %s\n",
7782 bgp->update_delay_begin_time);
7783 vty_out(vty,
7784 " Best-paths resumed: %s\n",
7785 bgp->update_delay_end_time);
7786 vty_out(vty,
7787 " zebra update resumed: %s\n",
7788 bgp->update_delay_zebra_resume_time);
7789 vty_out(vty,
7790 " peers update resumed: %s\n",
7791 bgp->update_delay_peers_resume_time);
7792 }
7793 }
7794 }
7795 }
7796
7797 if (use_json) {
7798 if (bgp_maxmed_onstartup_configured(bgp)
7799 && bgp->maxmed_active)
7800 json_object_boolean_true_add(
7801 json, "maxMedOnStartup");
7802 if (bgp->v_maxmed_admin)
7803 json_object_boolean_true_add(
7804 json, "maxMedAdministrative");
7805
7806 json_object_int_add(
7807 json, "tableVersion",
7808 bgp_table_version(bgp->rib[afi][safi]));
7809
7810 ents = bgp_table_count(bgp->rib[afi][safi]);
7811 json_object_int_add(json, "ribCount", ents);
7812 json_object_int_add(
7813 json, "ribMemory",
7814 ents * sizeof(struct bgp_node));
7815
7816 ents = listcount(bgp->peer);
7817 json_object_int_add(json, "peerCount", ents);
7818 json_object_int_add(json, "peerMemory",
7819 ents * sizeof(struct peer));
7820
7821 if ((ents = listcount(bgp->group))) {
7822 json_object_int_add(
7823 json, "peerGroupCount", ents);
7824 json_object_int_add(
7825 json, "peerGroupMemory",
7826 ents * sizeof(struct
7827 peer_group));
7828 }
7829
7830 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7831 BGP_CONFIG_DAMPENING))
7832 json_object_boolean_true_add(
7833 json, "dampeningEnabled");
7834 } else {
7835 if (bgp_maxmed_onstartup_configured(bgp)
7836 && bgp->maxmed_active)
7837 vty_out(vty,
7838 "Max-med on-startup active\n");
7839 if (bgp->v_maxmed_admin)
7840 vty_out(vty,
7841 "Max-med administrative active\n");
7842
7843 vty_out(vty, "BGP table version %" PRIu64 "\n",
7844 bgp_table_version(bgp->rib[afi][safi]));
7845
7846 ents = bgp_table_count(bgp->rib[afi][safi]);
7847 vty_out(vty,
7848 "RIB entries %ld, using %s of memory\n",
7849 ents,
7850 mtype_memstr(memstrbuf,
7851 sizeof(memstrbuf),
7852 ents * sizeof(struct
7853 bgp_node)));
7854
7855 /* Peer related usage */
7856 ents = listcount(bgp->peer);
7857 vty_out(vty, "Peers %ld, using %s of memory\n",
7858 ents,
7859 mtype_memstr(
7860 memstrbuf, sizeof(memstrbuf),
7861 ents * sizeof(struct peer)));
7862
7863 if ((ents = listcount(bgp->group)))
7864 vty_out(vty,
7865 "Peer groups %ld, using %s of memory\n",
7866 ents,
7867 mtype_memstr(
7868 memstrbuf,
7869 sizeof(memstrbuf),
7870 ents * sizeof(struct
7871 peer_group)));
7872
7873 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7874 BGP_CONFIG_DAMPENING))
7875 vty_out(vty, "Dampening enabled.\n");
7876 vty_out(vty, "\n");
7877
7878 /* Subtract 8 here because 'Neighbor' is
7879 * 8 characters */
7880 vty_out(vty, "Neighbor");
7881 vty_out(vty, "%*s", max_neighbor_width - 8,
7882 " ");
7883 vty_out(vty,
7884 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7885 }
7886 }
7887
7888 count++;
7889
7890 if (use_json) {
7891 json_peer = json_object_new_object();
7892
7893 if (peer_dynamic_neighbor(peer))
7894 json_object_boolean_true_add(json_peer,
7895 "dynamicPeer");
7896
7897 if (peer->hostname)
7898 json_object_string_add(json_peer, "hostname",
7899 peer->hostname);
7900
7901 if (peer->domainname)
7902 json_object_string_add(json_peer, "domainname",
7903 peer->domainname);
7904
7905 json_object_int_add(json_peer, "remoteAs", peer->as);
7906 json_object_int_add(json_peer, "version", 4);
7907 json_object_int_add(json_peer, "msgRcvd",
7908 PEER_TOTAL_RX(peer));
7909 json_object_int_add(json_peer, "msgSent",
7910 PEER_TOTAL_TX(peer));
7911
7912 json_object_int_add(json_peer, "tableVersion",
7913 peer->version[afi][safi]);
7914 json_object_int_add(json_peer, "outq",
7915 peer->obuf->count);
7916 json_object_int_add(json_peer, "inq", 0);
7917 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7918 use_json, json_peer);
7919 json_object_int_add(json_peer, "prefixReceivedCount",
7920 peer->pcount[afi][pfx_rcd_safi]);
7921
7922 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7923 json_object_string_add(json_peer, "state",
7924 "Idle (Admin)");
7925 else if (CHECK_FLAG(peer->sflags,
7926 PEER_STATUS_PREFIX_OVERFLOW))
7927 json_object_string_add(json_peer, "state",
7928 "Idle (PfxCt)");
7929 else
7930 json_object_string_add(
7931 json_peer, "state",
7932 lookup_msg(bgp_status_msg, peer->status,
7933 NULL));
7934
7935 if (peer->conf_if)
7936 json_object_string_add(json_peer, "idType",
7937 "interface");
7938 else if (peer->su.sa.sa_family == AF_INET)
7939 json_object_string_add(json_peer, "idType",
7940 "ipv4");
7941 else if (peer->su.sa.sa_family == AF_INET6)
7942 json_object_string_add(json_peer, "idType",
7943 "ipv6");
7944
7945 json_object_object_add(json_peers, peer->host,
7946 json_peer);
7947 } else {
7948 memset(dn_flag, '\0', sizeof(dn_flag));
7949 if (peer_dynamic_neighbor(peer)) {
7950 dn_count++;
7951 dn_flag[0] = '*';
7952 }
7953
7954 if (peer->hostname
7955 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7956 len = vty_out(vty, "%s%s(%s)", dn_flag,
7957 peer->hostname, peer->host);
7958 else
7959 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7960
7961 /* pad the neighbor column with spaces */
7962 if (len < max_neighbor_width)
7963 vty_out(vty, "%*s", max_neighbor_width - len,
7964 " ");
7965
7966 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7967 peer->as, PEER_TOTAL_RX(peer),
7968 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7969 0, peer->obuf->count,
7970 peer_uptime(peer->uptime, timebuf,
7971 BGP_UPTIME_LEN, 0, NULL));
7972
7973 if (peer->status == Established)
7974 if (peer->afc_recv[afi][pfx_rcd_safi])
7975 vty_out(vty, " %12ld",
7976 peer->pcount[afi]
7977 [pfx_rcd_safi]);
7978 else
7979 vty_out(vty, " NoNeg");
7980 else {
7981 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7982 vty_out(vty, " Idle (Admin)");
7983 else if (CHECK_FLAG(
7984 peer->sflags,
7985 PEER_STATUS_PREFIX_OVERFLOW))
7986 vty_out(vty, " Idle (PfxCt)");
7987 else
7988 vty_out(vty, " %12s",
7989 lookup_msg(bgp_status_msg,
7990 peer->status, NULL));
7991 }
7992 vty_out(vty, "\n");
7993 }
7994 }
7995
7996 if (use_json) {
7997 json_object_object_add(json, "peers", json_peers);
7998
7999 json_object_int_add(json, "totalPeers", count);
8000 json_object_int_add(json, "dynamicPeers", dn_count);
8001
8002 bgp_show_bestpath_json(bgp, json);
8003
8004 vty_out(vty, "%s\n", json_object_to_json_string_ext(
8005 json, JSON_C_TO_STRING_PRETTY));
8006 json_object_free(json);
8007 } else {
8008 if (count)
8009 vty_out(vty, "\nTotal number of neighbors %d\n", count);
8010 else {
8011 if (use_json)
8012 vty_out(vty,
8013 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
8014 afi_safi_print(afi, safi));
8015 else
8016 vty_out(vty, "No %s neighbor is configured\n",
8017 afi_safi_print(afi, safi));
8018 }
8019
8020 if (dn_count && !use_json) {
8021 vty_out(vty, "* - dynamic neighbor\n");
8022 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
8023 dn_count, bgp->dynamic_neighbors_limit);
8024 }
8025 }
8026
8027 return CMD_SUCCESS;
8028 }
8029
8030 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
8031 int safi, uint8_t use_json,
8032 json_object *json)
8033 {
8034 int is_first = 1;
8035 int afi_wildcard = (afi == AFI_MAX);
8036 int safi_wildcard = (safi == SAFI_MAX);
8037 int is_wildcard = (afi_wildcard || safi_wildcard);
8038 bool json_output = false;
8039
8040 if (use_json && is_wildcard)
8041 vty_out(vty, "{\n");
8042 if (afi_wildcard)
8043 afi = 1; /* AFI_IP */
8044 while (afi < AFI_MAX) {
8045 if (safi_wildcard)
8046 safi = 1; /* SAFI_UNICAST */
8047 while (safi < SAFI_MAX) {
8048 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
8049 json_output = true;
8050 if (is_wildcard) {
8051 /*
8052 * So limit output to those afi/safi
8053 * pairs that
8054 * actualy have something interesting in
8055 * them
8056 */
8057 if (use_json) {
8058 json = json_object_new_object();
8059
8060 if (!is_first)
8061 vty_out(vty, ",\n");
8062 else
8063 is_first = 0;
8064
8065 vty_out(vty, "\"%s\":",
8066 afi_safi_json(afi,
8067 safi));
8068 } else {
8069 vty_out(vty, "\n%s Summary:\n",
8070 afi_safi_print(afi,
8071 safi));
8072 }
8073 }
8074 bgp_show_summary(vty, bgp, afi, safi, use_json,
8075 json);
8076 }
8077 safi++;
8078 if (!safi_wildcard)
8079 safi = SAFI_MAX;
8080 }
8081 afi++;
8082 if (!afi_wildcard)
8083 afi = AFI_MAX;
8084 }
8085
8086 if (use_json && is_wildcard)
8087 vty_out(vty, "}\n");
8088 else if (use_json && !json_output)
8089 vty_out(vty, "{}\n");
8090 }
8091
8092 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8093 safi_t safi, uint8_t use_json)
8094 {
8095 struct listnode *node, *nnode;
8096 struct bgp *bgp;
8097 json_object *json = NULL;
8098 int is_first = 1;
8099
8100 if (use_json)
8101 vty_out(vty, "{\n");
8102
8103 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8104 if (use_json) {
8105 json = json_object_new_object();
8106
8107 if (!is_first)
8108 vty_out(vty, ",\n");
8109 else
8110 is_first = 0;
8111
8112 vty_out(vty, "\"%s\":",
8113 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8114 ? "Default"
8115 : bgp->name);
8116 } else {
8117 vty_out(vty, "\nInstance %s:\n",
8118 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8119 ? "Default"
8120 : bgp->name);
8121 }
8122 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8123 }
8124
8125 if (use_json)
8126 vty_out(vty, "}\n");
8127 }
8128
8129 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8130 safi_t safi, uint8_t use_json)
8131 {
8132 struct bgp *bgp;
8133
8134 if (name) {
8135 if (strmatch(name, "all")) {
8136 bgp_show_all_instances_summary_vty(vty, afi, safi,
8137 use_json);
8138 return CMD_SUCCESS;
8139 } else {
8140 bgp = bgp_lookup_by_name(name);
8141
8142 if (!bgp) {
8143 if (use_json)
8144 vty_out(vty, "{}\n");
8145 else
8146 vty_out(vty,
8147 "%% No such BGP instance exist\n");
8148 return CMD_WARNING;
8149 }
8150
8151 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8152 NULL);
8153 return CMD_SUCCESS;
8154 }
8155 }
8156
8157 bgp = bgp_get_default();
8158
8159 if (bgp)
8160 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8161
8162 return CMD_SUCCESS;
8163 }
8164
8165 /* `show [ip] bgp summary' commands. */
8166 DEFUN (show_ip_bgp_summary,
8167 show_ip_bgp_summary_cmd,
8168 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8169 SHOW_STR
8170 IP_STR
8171 BGP_STR
8172 BGP_INSTANCE_HELP_STR
8173 BGP_AFI_HELP_STR
8174 BGP_SAFI_WITH_LABEL_HELP_STR
8175 "Summary of BGP neighbor status\n"
8176 JSON_STR)
8177 {
8178 char *vrf = NULL;
8179 afi_t afi = AFI_MAX;
8180 safi_t safi = SAFI_MAX;
8181
8182 int idx = 0;
8183
8184 /* show [ip] bgp */
8185 if (argv_find(argv, argc, "ip", &idx))
8186 afi = AFI_IP;
8187 /* [<view|vrf> VIEWVRFNAME] */
8188 if (argv_find(argv, argc, "view", &idx)
8189 || argv_find(argv, argc, "vrf", &idx))
8190 vrf = argv[++idx]->arg;
8191 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8192 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8193 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8194 }
8195
8196 int uj = use_json(argc, argv);
8197
8198 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8199 }
8200
8201 const char *afi_safi_print(afi_t afi, safi_t safi)
8202 {
8203 if (afi == AFI_IP && safi == SAFI_UNICAST)
8204 return "IPv4 Unicast";
8205 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8206 return "IPv4 Multicast";
8207 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8208 return "IPv4 Labeled Unicast";
8209 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8210 return "IPv4 VPN";
8211 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8212 return "IPv4 Encap";
8213 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8214 return "IPv4 Flowspec";
8215 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8216 return "IPv6 Unicast";
8217 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8218 return "IPv6 Multicast";
8219 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8220 return "IPv6 Labeled Unicast";
8221 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8222 return "IPv6 VPN";
8223 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8224 return "IPv6 Encap";
8225 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8226 return "IPv6 Flowspec";
8227 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8228 return "L2VPN EVPN";
8229 else
8230 return "Unknown";
8231 }
8232
8233 /*
8234 * Please note that we have intentionally camelCased
8235 * the return strings here. So if you want
8236 * to use this function, please ensure you
8237 * are doing this within json output
8238 */
8239 const char *afi_safi_json(afi_t afi, safi_t safi)
8240 {
8241 if (afi == AFI_IP && safi == SAFI_UNICAST)
8242 return "ipv4Unicast";
8243 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8244 return "ipv4Multicast";
8245 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8246 return "ipv4LabeledUnicast";
8247 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8248 return "ipv4Vpn";
8249 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8250 return "ipv4Encap";
8251 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8252 return "ipv4Flowspec";
8253 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8254 return "ipv6Unicast";
8255 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8256 return "ipv6Multicast";
8257 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8258 return "ipv6LabeledUnicast";
8259 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8260 return "ipv6Vpn";
8261 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8262 return "ipv6Encap";
8263 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8264 return "ipv6Flowspec";
8265 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8266 return "l2VpnEvpn";
8267 else
8268 return "Unknown";
8269 }
8270
8271 /* Show BGP peer's information. */
8272 enum show_type { show_all, show_peer };
8273
8274 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8275 afi_t afi, safi_t safi,
8276 uint16_t adv_smcap, uint16_t adv_rmcap,
8277 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8278 uint8_t use_json, json_object *json_pref)
8279 {
8280 /* Send-Mode */
8281 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8282 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8283 if (use_json) {
8284 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8285 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8286 json_object_string_add(json_pref, "sendMode",
8287 "advertisedAndReceived");
8288 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8289 json_object_string_add(json_pref, "sendMode",
8290 "advertised");
8291 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8292 json_object_string_add(json_pref, "sendMode",
8293 "received");
8294 } else {
8295 vty_out(vty, " Send-mode: ");
8296 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8297 vty_out(vty, "advertised");
8298 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8299 vty_out(vty, "%sreceived",
8300 CHECK_FLAG(p->af_cap[afi][safi],
8301 adv_smcap)
8302 ? ", "
8303 : "");
8304 vty_out(vty, "\n");
8305 }
8306 }
8307
8308 /* Receive-Mode */
8309 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8310 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8311 if (use_json) {
8312 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8313 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8314 json_object_string_add(json_pref, "recvMode",
8315 "advertisedAndReceived");
8316 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8317 json_object_string_add(json_pref, "recvMode",
8318 "advertised");
8319 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8320 json_object_string_add(json_pref, "recvMode",
8321 "received");
8322 } else {
8323 vty_out(vty, " Receive-mode: ");
8324 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8325 vty_out(vty, "advertised");
8326 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8327 vty_out(vty, "%sreceived",
8328 CHECK_FLAG(p->af_cap[afi][safi],
8329 adv_rmcap)
8330 ? ", "
8331 : "");
8332 vty_out(vty, "\n");
8333 }
8334 }
8335 }
8336
8337 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8338 safi_t safi, uint8_t use_json,
8339 json_object *json_neigh)
8340 {
8341 struct bgp_filter *filter;
8342 struct peer_af *paf;
8343 char orf_pfx_name[BUFSIZ];
8344 int orf_pfx_count;
8345 json_object *json_af = NULL;
8346 json_object *json_prefA = NULL;
8347 json_object *json_prefB = NULL;
8348 json_object *json_addr = NULL;
8349
8350 if (use_json) {
8351 json_addr = json_object_new_object();
8352 json_af = json_object_new_object();
8353 filter = &p->filter[afi][safi];
8354
8355 if (peer_group_active(p))
8356 json_object_string_add(json_addr, "peerGroupMember",
8357 p->group->name);
8358
8359 paf = peer_af_find(p, afi, safi);
8360 if (paf && PAF_SUBGRP(paf)) {
8361 json_object_int_add(json_addr, "updateGroupId",
8362 PAF_UPDGRP(paf)->id);
8363 json_object_int_add(json_addr, "subGroupId",
8364 PAF_SUBGRP(paf)->id);
8365 json_object_int_add(json_addr, "packetQueueLength",
8366 bpacket_queue_virtual_length(paf));
8367 }
8368
8369 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8370 || CHECK_FLAG(p->af_cap[afi][safi],
8371 PEER_CAP_ORF_PREFIX_SM_RCV)
8372 || CHECK_FLAG(p->af_cap[afi][safi],
8373 PEER_CAP_ORF_PREFIX_RM_ADV)
8374 || CHECK_FLAG(p->af_cap[afi][safi],
8375 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8376 json_object_int_add(json_af, "orfType",
8377 ORF_TYPE_PREFIX);
8378 json_prefA = json_object_new_object();
8379 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8380 PEER_CAP_ORF_PREFIX_SM_ADV,
8381 PEER_CAP_ORF_PREFIX_RM_ADV,
8382 PEER_CAP_ORF_PREFIX_SM_RCV,
8383 PEER_CAP_ORF_PREFIX_RM_RCV,
8384 use_json, json_prefA);
8385 json_object_object_add(json_af, "orfPrefixList",
8386 json_prefA);
8387 }
8388
8389 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8390 || CHECK_FLAG(p->af_cap[afi][safi],
8391 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8392 || CHECK_FLAG(p->af_cap[afi][safi],
8393 PEER_CAP_ORF_PREFIX_RM_ADV)
8394 || CHECK_FLAG(p->af_cap[afi][safi],
8395 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8396 json_object_int_add(json_af, "orfOldType",
8397 ORF_TYPE_PREFIX_OLD);
8398 json_prefB = json_object_new_object();
8399 bgp_show_peer_afi_orf_cap(
8400 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8401 PEER_CAP_ORF_PREFIX_RM_ADV,
8402 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8403 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8404 json_prefB);
8405 json_object_object_add(json_af, "orfOldPrefixList",
8406 json_prefB);
8407 }
8408
8409 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8410 || CHECK_FLAG(p->af_cap[afi][safi],
8411 PEER_CAP_ORF_PREFIX_SM_RCV)
8412 || CHECK_FLAG(p->af_cap[afi][safi],
8413 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8414 || CHECK_FLAG(p->af_cap[afi][safi],
8415 PEER_CAP_ORF_PREFIX_RM_ADV)
8416 || CHECK_FLAG(p->af_cap[afi][safi],
8417 PEER_CAP_ORF_PREFIX_RM_RCV)
8418 || CHECK_FLAG(p->af_cap[afi][safi],
8419 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8420 json_object_object_add(json_addr, "afDependentCap",
8421 json_af);
8422 else
8423 json_object_free(json_af);
8424
8425 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8426 orf_pfx_count = prefix_bgp_show_prefix_list(
8427 NULL, afi, orf_pfx_name, use_json);
8428
8429 if (CHECK_FLAG(p->af_sflags[afi][safi],
8430 PEER_STATUS_ORF_PREFIX_SEND)
8431 || orf_pfx_count) {
8432 if (CHECK_FLAG(p->af_sflags[afi][safi],
8433 PEER_STATUS_ORF_PREFIX_SEND))
8434 json_object_boolean_true_add(json_neigh,
8435 "orfSent");
8436 if (orf_pfx_count)
8437 json_object_int_add(json_addr, "orfRecvCounter",
8438 orf_pfx_count);
8439 }
8440 if (CHECK_FLAG(p->af_sflags[afi][safi],
8441 PEER_STATUS_ORF_WAIT_REFRESH))
8442 json_object_string_add(
8443 json_addr, "orfFirstUpdate",
8444 "deferredUntilORFOrRouteRefreshRecvd");
8445
8446 if (CHECK_FLAG(p->af_flags[afi][safi],
8447 PEER_FLAG_REFLECTOR_CLIENT))
8448 json_object_boolean_true_add(json_addr,
8449 "routeReflectorClient");
8450 if (CHECK_FLAG(p->af_flags[afi][safi],
8451 PEER_FLAG_RSERVER_CLIENT))
8452 json_object_boolean_true_add(json_addr,
8453 "routeServerClient");
8454 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8455 json_object_boolean_true_add(json_addr,
8456 "inboundSoftConfigPermit");
8457
8458 if (CHECK_FLAG(p->af_flags[afi][safi],
8459 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8460 json_object_boolean_true_add(
8461 json_addr,
8462 "privateAsNumsAllReplacedInUpdatesToNbr");
8463 else if (CHECK_FLAG(p->af_flags[afi][safi],
8464 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8465 json_object_boolean_true_add(
8466 json_addr,
8467 "privateAsNumsReplacedInUpdatesToNbr");
8468 else if (CHECK_FLAG(p->af_flags[afi][safi],
8469 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8470 json_object_boolean_true_add(
8471 json_addr,
8472 "privateAsNumsAllRemovedInUpdatesToNbr");
8473 else if (CHECK_FLAG(p->af_flags[afi][safi],
8474 PEER_FLAG_REMOVE_PRIVATE_AS))
8475 json_object_boolean_true_add(
8476 json_addr,
8477 "privateAsNumsRemovedInUpdatesToNbr");
8478
8479 if (CHECK_FLAG(p->af_flags[afi][safi],
8480 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8481 json_object_boolean_true_add(json_addr,
8482 "addpathTxAllPaths");
8483
8484 if (CHECK_FLAG(p->af_flags[afi][safi],
8485 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8486 json_object_boolean_true_add(json_addr,
8487 "addpathTxBestpathPerAS");
8488
8489 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8490 json_object_string_add(json_addr,
8491 "overrideASNsInOutboundUpdates",
8492 "ifAspathEqualRemoteAs");
8493
8494 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8495 || CHECK_FLAG(p->af_flags[afi][safi],
8496 PEER_FLAG_FORCE_NEXTHOP_SELF))
8497 json_object_boolean_true_add(json_addr,
8498 "routerAlwaysNextHop");
8499 if (CHECK_FLAG(p->af_flags[afi][safi],
8500 PEER_FLAG_AS_PATH_UNCHANGED))
8501 json_object_boolean_true_add(
8502 json_addr, "unchangedAsPathPropogatedToNbr");
8503 if (CHECK_FLAG(p->af_flags[afi][safi],
8504 PEER_FLAG_NEXTHOP_UNCHANGED))
8505 json_object_boolean_true_add(
8506 json_addr, "unchangedNextHopPropogatedToNbr");
8507 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8508 json_object_boolean_true_add(
8509 json_addr, "unchangedMedPropogatedToNbr");
8510 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8511 || CHECK_FLAG(p->af_flags[afi][safi],
8512 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8513 if (CHECK_FLAG(p->af_flags[afi][safi],
8514 PEER_FLAG_SEND_COMMUNITY)
8515 && CHECK_FLAG(p->af_flags[afi][safi],
8516 PEER_FLAG_SEND_EXT_COMMUNITY))
8517 json_object_string_add(json_addr,
8518 "commAttriSentToNbr",
8519 "extendedAndStandard");
8520 else if (CHECK_FLAG(p->af_flags[afi][safi],
8521 PEER_FLAG_SEND_EXT_COMMUNITY))
8522 json_object_string_add(json_addr,
8523 "commAttriSentToNbr",
8524 "extended");
8525 else
8526 json_object_string_add(json_addr,
8527 "commAttriSentToNbr",
8528 "standard");
8529 }
8530 if (CHECK_FLAG(p->af_flags[afi][safi],
8531 PEER_FLAG_DEFAULT_ORIGINATE)) {
8532 if (p->default_rmap[afi][safi].name)
8533 json_object_string_add(
8534 json_addr, "defaultRouteMap",
8535 p->default_rmap[afi][safi].name);
8536
8537 if (paf && PAF_SUBGRP(paf)
8538 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8539 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8540 json_object_boolean_true_add(json_addr,
8541 "defaultSent");
8542 else
8543 json_object_boolean_true_add(json_addr,
8544 "defaultNotSent");
8545 }
8546
8547 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8548 if (is_evpn_enabled())
8549 json_object_boolean_true_add(
8550 json_addr, "advertiseAllVnis");
8551 }
8552
8553 if (filter->plist[FILTER_IN].name
8554 || filter->dlist[FILTER_IN].name
8555 || filter->aslist[FILTER_IN].name
8556 || filter->map[RMAP_IN].name)
8557 json_object_boolean_true_add(json_addr,
8558 "inboundPathPolicyConfig");
8559 if (filter->plist[FILTER_OUT].name
8560 || filter->dlist[FILTER_OUT].name
8561 || filter->aslist[FILTER_OUT].name
8562 || filter->map[RMAP_OUT].name || filter->usmap.name)
8563 json_object_boolean_true_add(
8564 json_addr, "outboundPathPolicyConfig");
8565
8566 /* prefix-list */
8567 if (filter->plist[FILTER_IN].name)
8568 json_object_string_add(json_addr,
8569 "incomingUpdatePrefixFilterList",
8570 filter->plist[FILTER_IN].name);
8571 if (filter->plist[FILTER_OUT].name)
8572 json_object_string_add(json_addr,
8573 "outgoingUpdatePrefixFilterList",
8574 filter->plist[FILTER_OUT].name);
8575
8576 /* distribute-list */
8577 if (filter->dlist[FILTER_IN].name)
8578 json_object_string_add(
8579 json_addr, "incomingUpdateNetworkFilterList",
8580 filter->dlist[FILTER_IN].name);
8581 if (filter->dlist[FILTER_OUT].name)
8582 json_object_string_add(
8583 json_addr, "outgoingUpdateNetworkFilterList",
8584 filter->dlist[FILTER_OUT].name);
8585
8586 /* filter-list. */
8587 if (filter->aslist[FILTER_IN].name)
8588 json_object_string_add(json_addr,
8589 "incomingUpdateAsPathFilterList",
8590 filter->aslist[FILTER_IN].name);
8591 if (filter->aslist[FILTER_OUT].name)
8592 json_object_string_add(json_addr,
8593 "outgoingUpdateAsPathFilterList",
8594 filter->aslist[FILTER_OUT].name);
8595
8596 /* route-map. */
8597 if (filter->map[RMAP_IN].name)
8598 json_object_string_add(
8599 json_addr, "routeMapForIncomingAdvertisements",
8600 filter->map[RMAP_IN].name);
8601 if (filter->map[RMAP_OUT].name)
8602 json_object_string_add(
8603 json_addr, "routeMapForOutgoingAdvertisements",
8604 filter->map[RMAP_OUT].name);
8605
8606 /* unsuppress-map */
8607 if (filter->usmap.name)
8608 json_object_string_add(json_addr,
8609 "selectiveUnsuppressRouteMap",
8610 filter->usmap.name);
8611
8612 /* Receive prefix count */
8613 json_object_int_add(json_addr, "acceptedPrefixCounter",
8614 p->pcount[afi][safi]);
8615
8616 /* Maximum prefix */
8617 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8618 json_object_int_add(json_addr, "prefixAllowedMax",
8619 p->pmax[afi][safi]);
8620 if (CHECK_FLAG(p->af_flags[afi][safi],
8621 PEER_FLAG_MAX_PREFIX_WARNING))
8622 json_object_boolean_true_add(
8623 json_addr, "prefixAllowedMaxWarning");
8624 json_object_int_add(json_addr,
8625 "prefixAllowedWarningThresh",
8626 p->pmax_threshold[afi][safi]);
8627 if (p->pmax_restart[afi][safi])
8628 json_object_int_add(
8629 json_addr,
8630 "prefixAllowedRestartIntervalMsecs",
8631 p->pmax_restart[afi][safi] * 60000);
8632 }
8633 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8634 json_addr);
8635
8636 } else {
8637 filter = &p->filter[afi][safi];
8638
8639 vty_out(vty, " For address family: %s\n",
8640 afi_safi_print(afi, safi));
8641
8642 if (peer_group_active(p))
8643 vty_out(vty, " %s peer-group member\n",
8644 p->group->name);
8645
8646 paf = peer_af_find(p, afi, safi);
8647 if (paf && PAF_SUBGRP(paf)) {
8648 vty_out(vty, " Update group %" PRIu64
8649 ", subgroup %" PRIu64 "\n",
8650 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8651 vty_out(vty, " Packet Queue length %d\n",
8652 bpacket_queue_virtual_length(paf));
8653 } else {
8654 vty_out(vty, " Not part of any update group\n");
8655 }
8656 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8657 || CHECK_FLAG(p->af_cap[afi][safi],
8658 PEER_CAP_ORF_PREFIX_SM_RCV)
8659 || CHECK_FLAG(p->af_cap[afi][safi],
8660 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8661 || CHECK_FLAG(p->af_cap[afi][safi],
8662 PEER_CAP_ORF_PREFIX_RM_ADV)
8663 || CHECK_FLAG(p->af_cap[afi][safi],
8664 PEER_CAP_ORF_PREFIX_RM_RCV)
8665 || CHECK_FLAG(p->af_cap[afi][safi],
8666 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8667 vty_out(vty, " AF-dependant capabilities:\n");
8668
8669 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8670 || CHECK_FLAG(p->af_cap[afi][safi],
8671 PEER_CAP_ORF_PREFIX_SM_RCV)
8672 || CHECK_FLAG(p->af_cap[afi][safi],
8673 PEER_CAP_ORF_PREFIX_RM_ADV)
8674 || CHECK_FLAG(p->af_cap[afi][safi],
8675 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8676 vty_out(vty,
8677 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8678 ORF_TYPE_PREFIX);
8679 bgp_show_peer_afi_orf_cap(
8680 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8681 PEER_CAP_ORF_PREFIX_RM_ADV,
8682 PEER_CAP_ORF_PREFIX_SM_RCV,
8683 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8684 }
8685 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8686 || CHECK_FLAG(p->af_cap[afi][safi],
8687 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8688 || CHECK_FLAG(p->af_cap[afi][safi],
8689 PEER_CAP_ORF_PREFIX_RM_ADV)
8690 || CHECK_FLAG(p->af_cap[afi][safi],
8691 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8692 vty_out(vty,
8693 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8694 ORF_TYPE_PREFIX_OLD);
8695 bgp_show_peer_afi_orf_cap(
8696 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8697 PEER_CAP_ORF_PREFIX_RM_ADV,
8698 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8699 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8700 }
8701
8702 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8703 orf_pfx_count = prefix_bgp_show_prefix_list(
8704 NULL, afi, orf_pfx_name, use_json);
8705
8706 if (CHECK_FLAG(p->af_sflags[afi][safi],
8707 PEER_STATUS_ORF_PREFIX_SEND)
8708 || orf_pfx_count) {
8709 vty_out(vty, " Outbound Route Filter (ORF):");
8710 if (CHECK_FLAG(p->af_sflags[afi][safi],
8711 PEER_STATUS_ORF_PREFIX_SEND))
8712 vty_out(vty, " sent;");
8713 if (orf_pfx_count)
8714 vty_out(vty, " received (%d entries)",
8715 orf_pfx_count);
8716 vty_out(vty, "\n");
8717 }
8718 if (CHECK_FLAG(p->af_sflags[afi][safi],
8719 PEER_STATUS_ORF_WAIT_REFRESH))
8720 vty_out(vty,
8721 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8722
8723 if (CHECK_FLAG(p->af_flags[afi][safi],
8724 PEER_FLAG_REFLECTOR_CLIENT))
8725 vty_out(vty, " Route-Reflector Client\n");
8726 if (CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_RSERVER_CLIENT))
8728 vty_out(vty, " Route-Server Client\n");
8729 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8730 vty_out(vty,
8731 " Inbound soft reconfiguration allowed\n");
8732
8733 if (CHECK_FLAG(p->af_flags[afi][safi],
8734 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8735 vty_out(vty,
8736 " Private AS numbers (all) replaced in updates to this neighbor\n");
8737 else if (CHECK_FLAG(p->af_flags[afi][safi],
8738 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8739 vty_out(vty,
8740 " Private AS numbers replaced in updates to this neighbor\n");
8741 else if (CHECK_FLAG(p->af_flags[afi][safi],
8742 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8743 vty_out(vty,
8744 " Private AS numbers (all) removed in updates to this neighbor\n");
8745 else if (CHECK_FLAG(p->af_flags[afi][safi],
8746 PEER_FLAG_REMOVE_PRIVATE_AS))
8747 vty_out(vty,
8748 " Private AS numbers removed in updates to this neighbor\n");
8749
8750 if (CHECK_FLAG(p->af_flags[afi][safi],
8751 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8752 vty_out(vty, " Advertise all paths via addpath\n");
8753
8754 if (CHECK_FLAG(p->af_flags[afi][safi],
8755 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8756 vty_out(vty,
8757 " Advertise bestpath per AS via addpath\n");
8758
8759 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8760 vty_out(vty,
8761 " Override ASNs in outbound updates if aspath equals remote-as\n");
8762
8763 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8764 || CHECK_FLAG(p->af_flags[afi][safi],
8765 PEER_FLAG_FORCE_NEXTHOP_SELF))
8766 vty_out(vty, " NEXT_HOP is always this router\n");
8767 if (CHECK_FLAG(p->af_flags[afi][safi],
8768 PEER_FLAG_AS_PATH_UNCHANGED))
8769 vty_out(vty,
8770 " AS_PATH is propagated unchanged to this neighbor\n");
8771 if (CHECK_FLAG(p->af_flags[afi][safi],
8772 PEER_FLAG_NEXTHOP_UNCHANGED))
8773 vty_out(vty,
8774 " NEXT_HOP is propagated unchanged to this neighbor\n");
8775 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8776 vty_out(vty,
8777 " MED is propagated unchanged to this neighbor\n");
8778 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8779 || CHECK_FLAG(p->af_flags[afi][safi],
8780 PEER_FLAG_SEND_EXT_COMMUNITY)
8781 || CHECK_FLAG(p->af_flags[afi][safi],
8782 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8783 vty_out(vty,
8784 " Community attribute sent to this neighbor");
8785 if (CHECK_FLAG(p->af_flags[afi][safi],
8786 PEER_FLAG_SEND_COMMUNITY)
8787 && CHECK_FLAG(p->af_flags[afi][safi],
8788 PEER_FLAG_SEND_EXT_COMMUNITY)
8789 && CHECK_FLAG(p->af_flags[afi][safi],
8790 PEER_FLAG_SEND_LARGE_COMMUNITY))
8791 vty_out(vty, "(all)\n");
8792 else if (CHECK_FLAG(p->af_flags[afi][safi],
8793 PEER_FLAG_SEND_LARGE_COMMUNITY))
8794 vty_out(vty, "(large)\n");
8795 else if (CHECK_FLAG(p->af_flags[afi][safi],
8796 PEER_FLAG_SEND_EXT_COMMUNITY))
8797 vty_out(vty, "(extended)\n");
8798 else
8799 vty_out(vty, "(standard)\n");
8800 }
8801 if (CHECK_FLAG(p->af_flags[afi][safi],
8802 PEER_FLAG_DEFAULT_ORIGINATE)) {
8803 vty_out(vty, " Default information originate,");
8804
8805 if (p->default_rmap[afi][safi].name)
8806 vty_out(vty, " default route-map %s%s,",
8807 p->default_rmap[afi][safi].map ? "*"
8808 : "",
8809 p->default_rmap[afi][safi].name);
8810 if (paf && PAF_SUBGRP(paf)
8811 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8812 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8813 vty_out(vty, " default sent\n");
8814 else
8815 vty_out(vty, " default not sent\n");
8816 }
8817
8818 /* advertise-vni-all */
8819 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8820 if (is_evpn_enabled())
8821 vty_out(vty, " advertise-all-vni\n");
8822 }
8823
8824 if (filter->plist[FILTER_IN].name
8825 || filter->dlist[FILTER_IN].name
8826 || filter->aslist[FILTER_IN].name
8827 || filter->map[RMAP_IN].name)
8828 vty_out(vty, " Inbound path policy configured\n");
8829 if (filter->plist[FILTER_OUT].name
8830 || filter->dlist[FILTER_OUT].name
8831 || filter->aslist[FILTER_OUT].name
8832 || filter->map[RMAP_OUT].name || filter->usmap.name)
8833 vty_out(vty, " Outbound path policy configured\n");
8834
8835 /* prefix-list */
8836 if (filter->plist[FILTER_IN].name)
8837 vty_out(vty,
8838 " Incoming update prefix filter list is %s%s\n",
8839 filter->plist[FILTER_IN].plist ? "*" : "",
8840 filter->plist[FILTER_IN].name);
8841 if (filter->plist[FILTER_OUT].name)
8842 vty_out(vty,
8843 " Outgoing update prefix filter list is %s%s\n",
8844 filter->plist[FILTER_OUT].plist ? "*" : "",
8845 filter->plist[FILTER_OUT].name);
8846
8847 /* distribute-list */
8848 if (filter->dlist[FILTER_IN].name)
8849 vty_out(vty,
8850 " Incoming update network filter list is %s%s\n",
8851 filter->dlist[FILTER_IN].alist ? "*" : "",
8852 filter->dlist[FILTER_IN].name);
8853 if (filter->dlist[FILTER_OUT].name)
8854 vty_out(vty,
8855 " Outgoing update network filter list is %s%s\n",
8856 filter->dlist[FILTER_OUT].alist ? "*" : "",
8857 filter->dlist[FILTER_OUT].name);
8858
8859 /* filter-list. */
8860 if (filter->aslist[FILTER_IN].name)
8861 vty_out(vty,
8862 " Incoming update AS path filter list is %s%s\n",
8863 filter->aslist[FILTER_IN].aslist ? "*" : "",
8864 filter->aslist[FILTER_IN].name);
8865 if (filter->aslist[FILTER_OUT].name)
8866 vty_out(vty,
8867 " Outgoing update AS path filter list is %s%s\n",
8868 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8869 filter->aslist[FILTER_OUT].name);
8870
8871 /* route-map. */
8872 if (filter->map[RMAP_IN].name)
8873 vty_out(vty,
8874 " Route map for incoming advertisements is %s%s\n",
8875 filter->map[RMAP_IN].map ? "*" : "",
8876 filter->map[RMAP_IN].name);
8877 if (filter->map[RMAP_OUT].name)
8878 vty_out(vty,
8879 " Route map for outgoing advertisements is %s%s\n",
8880 filter->map[RMAP_OUT].map ? "*" : "",
8881 filter->map[RMAP_OUT].name);
8882
8883 /* unsuppress-map */
8884 if (filter->usmap.name)
8885 vty_out(vty,
8886 " Route map for selective unsuppress is %s%s\n",
8887 filter->usmap.map ? "*" : "",
8888 filter->usmap.name);
8889
8890 /* Receive prefix count */
8891 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8892
8893 /* Maximum prefix */
8894 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8895 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8896 p->pmax[afi][safi],
8897 CHECK_FLAG(p->af_flags[afi][safi],
8898 PEER_FLAG_MAX_PREFIX_WARNING)
8899 ? " (warning-only)"
8900 : "");
8901 vty_out(vty, " Threshold for warning message %d%%",
8902 p->pmax_threshold[afi][safi]);
8903 if (p->pmax_restart[afi][safi])
8904 vty_out(vty, ", restart interval %d min",
8905 p->pmax_restart[afi][safi]);
8906 vty_out(vty, "\n");
8907 }
8908
8909 vty_out(vty, "\n");
8910 }
8911 }
8912
8913 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8914 json_object *json)
8915 {
8916 struct bgp *bgp;
8917 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8918 char timebuf[BGP_UPTIME_LEN];
8919 char dn_flag[2];
8920 const char *subcode_str;
8921 const char *code_str;
8922 afi_t afi;
8923 safi_t safi;
8924 uint16_t i;
8925 uint8_t *msg;
8926 json_object *json_neigh = NULL;
8927 time_t epoch_tbuf;
8928
8929 bgp = p->bgp;
8930
8931 if (use_json)
8932 json_neigh = json_object_new_object();
8933
8934 memset(dn_flag, '\0', sizeof(dn_flag));
8935 if (!p->conf_if && peer_dynamic_neighbor(p))
8936 dn_flag[0] = '*';
8937
8938 if (!use_json) {
8939 if (p->conf_if) /* Configured interface name. */
8940 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8941 BGP_PEER_SU_UNSPEC(p)
8942 ? "None"
8943 : sockunion2str(&p->su, buf,
8944 SU_ADDRSTRLEN));
8945 else /* Configured IP address. */
8946 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8947 p->host);
8948 }
8949
8950 if (use_json) {
8951 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8952 json_object_string_add(json_neigh, "bgpNeighborAddr",
8953 "none");
8954 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8955 json_object_string_add(
8956 json_neigh, "bgpNeighborAddr",
8957 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8958
8959 json_object_int_add(json_neigh, "remoteAs", p->as);
8960
8961 if (p->change_local_as)
8962 json_object_int_add(json_neigh, "localAs",
8963 p->change_local_as);
8964 else
8965 json_object_int_add(json_neigh, "localAs", p->local_as);
8966
8967 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8968 json_object_boolean_true_add(json_neigh,
8969 "localAsNoPrepend");
8970
8971 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8972 json_object_boolean_true_add(json_neigh,
8973 "localAsReplaceAs");
8974 } else {
8975 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8976 || (p->as_type == AS_INTERNAL))
8977 vty_out(vty, "remote AS %u, ", p->as);
8978 else
8979 vty_out(vty, "remote AS Unspecified, ");
8980 vty_out(vty, "local AS %u%s%s, ",
8981 p->change_local_as ? p->change_local_as : p->local_as,
8982 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8983 ? " no-prepend"
8984 : "",
8985 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8986 ? " replace-as"
8987 : "");
8988 }
8989 /* peer type internal, external, confed-internal or confed-external */
8990 if (p->as == p->local_as) {
8991 if (use_json) {
8992 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8993 json_object_boolean_true_add(
8994 json_neigh, "nbrConfedInternalLink");
8995 else
8996 json_object_boolean_true_add(json_neigh,
8997 "nbrInternalLink");
8998 } else {
8999 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9000 vty_out(vty, "confed-internal link\n");
9001 else
9002 vty_out(vty, "internal link\n");
9003 }
9004 } else {
9005 if (use_json) {
9006 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
9007 json_object_boolean_true_add(
9008 json_neigh, "nbrConfedExternalLink");
9009 else
9010 json_object_boolean_true_add(json_neigh,
9011 "nbrExternalLink");
9012 } else {
9013 if (bgp_confederation_peers_check(bgp, p->as))
9014 vty_out(vty, "confed-external link\n");
9015 else
9016 vty_out(vty, "external link\n");
9017 }
9018 }
9019
9020 /* Description. */
9021 if (p->desc) {
9022 if (use_json)
9023 json_object_string_add(json_neigh, "nbrDesc", p->desc);
9024 else
9025 vty_out(vty, " Description: %s\n", p->desc);
9026 }
9027
9028 if (p->hostname) {
9029 if (use_json) {
9030 if (p->hostname)
9031 json_object_string_add(json_neigh, "hostname",
9032 p->hostname);
9033
9034 if (p->domainname)
9035 json_object_string_add(json_neigh, "domainname",
9036 p->domainname);
9037 } else {
9038 if (p->domainname && (p->domainname[0] != '\0'))
9039 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
9040 p->domainname);
9041 else
9042 vty_out(vty, "Hostname: %s\n", p->hostname);
9043 }
9044 }
9045
9046 /* Peer-group */
9047 if (p->group) {
9048 if (use_json) {
9049 json_object_string_add(json_neigh, "peerGroup",
9050 p->group->name);
9051
9052 if (dn_flag[0]) {
9053 struct prefix prefix, *range = NULL;
9054
9055 sockunion2hostprefix(&(p->su), &prefix);
9056 range = peer_group_lookup_dynamic_neighbor_range(
9057 p->group, &prefix);
9058
9059 if (range) {
9060 prefix2str(range, buf1, sizeof(buf1));
9061 json_object_string_add(
9062 json_neigh,
9063 "peerSubnetRangeGroup", buf1);
9064 }
9065 }
9066 } else {
9067 vty_out(vty,
9068 " Member of peer-group %s for session parameters\n",
9069 p->group->name);
9070
9071 if (dn_flag[0]) {
9072 struct prefix prefix, *range = NULL;
9073
9074 sockunion2hostprefix(&(p->su), &prefix);
9075 range = peer_group_lookup_dynamic_neighbor_range(
9076 p->group, &prefix);
9077
9078 if (range) {
9079 prefix2str(range, buf1, sizeof(buf1));
9080 vty_out(vty,
9081 " Belongs to the subnet range group: %s\n",
9082 buf1);
9083 }
9084 }
9085 }
9086 }
9087
9088 if (use_json) {
9089 /* Administrative shutdown. */
9090 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9091 json_object_boolean_true_add(json_neigh,
9092 "adminShutDown");
9093
9094 /* BGP Version. */
9095 json_object_int_add(json_neigh, "bgpVersion", 4);
9096 json_object_string_add(
9097 json_neigh, "remoteRouterId",
9098 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9099
9100 /* Confederation */
9101 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9102 && bgp_confederation_peers_check(bgp, p->as))
9103 json_object_boolean_true_add(json_neigh,
9104 "nbrCommonAdmin");
9105
9106 /* Status. */
9107 json_object_string_add(
9108 json_neigh, "bgpState",
9109 lookup_msg(bgp_status_msg, p->status, NULL));
9110
9111 if (p->status == Established) {
9112 time_t uptime;
9113
9114 uptime = bgp_clock();
9115 uptime -= p->uptime;
9116 epoch_tbuf = time(NULL) - uptime;
9117
9118 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
9119 CPP_NOTICE(
9120 "bgpTimerUp should be deprecated and can be removed now");
9121 #endif
9122 /*
9123 * bgpTimerUp was miliseconds that was accurate
9124 * up to 1 day, then the value returned
9125 * became garbage. So in order to provide
9126 * some level of backwards compatability,
9127 * we still provde the data, but now
9128 * we are returning the correct value
9129 * and also adding a new bgpTimerUpMsec
9130 * which will allow us to deprecate
9131 * this eventually
9132 */
9133 json_object_int_add(json_neigh, "bgpTimerUp",
9134 uptime * 1000);
9135 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9136 uptime * 1000);
9137 json_object_string_add(json_neigh, "bgpTimerUpString",
9138 peer_uptime(p->uptime, timebuf,
9139 BGP_UPTIME_LEN, 0,
9140 NULL));
9141 json_object_int_add(json_neigh,
9142 "bgpTimerUpEstablishedEpoch",
9143 epoch_tbuf);
9144 }
9145
9146 else if (p->status == Active) {
9147 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9148 json_object_string_add(json_neigh, "bgpStateIs",
9149 "passive");
9150 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9151 json_object_string_add(json_neigh, "bgpStateIs",
9152 "passiveNSF");
9153 }
9154
9155 /* read timer */
9156 time_t uptime;
9157 struct tm *tm;
9158
9159 uptime = bgp_clock();
9160 uptime -= p->readtime;
9161 tm = gmtime(&uptime);
9162 json_object_int_add(json_neigh, "bgpTimerLastRead",
9163 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9164 + (tm->tm_hour * 3600000));
9165
9166 uptime = bgp_clock();
9167 uptime -= p->last_write;
9168 tm = gmtime(&uptime);
9169 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9170 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9171 + (tm->tm_hour * 3600000));
9172
9173 uptime = bgp_clock();
9174 uptime -= p->update_time;
9175 tm = gmtime(&uptime);
9176 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9177 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9178 + (tm->tm_hour * 3600000));
9179
9180 /* Configured timer values. */
9181 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9182 p->v_holdtime * 1000);
9183 json_object_int_add(json_neigh,
9184 "bgpTimerKeepAliveIntervalMsecs",
9185 p->v_keepalive * 1000);
9186
9187 if (PEER_OR_GROUP_TIMER_SET(p)) {
9188 json_object_int_add(json_neigh,
9189 "bgpTimerConfiguredHoldTimeMsecs",
9190 p->holdtime * 1000);
9191 json_object_int_add(
9192 json_neigh,
9193 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9194 p->keepalive * 1000);
9195 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9196 || (bgp->default_keepalive
9197 != BGP_DEFAULT_KEEPALIVE)) {
9198 json_object_int_add(json_neigh,
9199 "bgpTimerConfiguredHoldTimeMsecs",
9200 bgp->default_holdtime);
9201 json_object_int_add(
9202 json_neigh,
9203 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9204 bgp->default_keepalive);
9205 }
9206 } else {
9207 /* Administrative shutdown. */
9208 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9209 vty_out(vty, " Administratively shut down\n");
9210
9211 /* BGP Version. */
9212 vty_out(vty, " BGP version 4");
9213 vty_out(vty, ", remote router ID %s\n",
9214 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9215
9216 /* Confederation */
9217 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9218 && bgp_confederation_peers_check(bgp, p->as))
9219 vty_out(vty,
9220 " Neighbor under common administration\n");
9221
9222 /* Status. */
9223 vty_out(vty, " BGP state = %s",
9224 lookup_msg(bgp_status_msg, p->status, NULL));
9225
9226 if (p->status == Established)
9227 vty_out(vty, ", up for %8s",
9228 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9229 0, NULL));
9230
9231 else if (p->status == Active) {
9232 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9233 vty_out(vty, " (passive)");
9234 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9235 vty_out(vty, " (NSF passive)");
9236 }
9237 vty_out(vty, "\n");
9238
9239 /* read timer */
9240 vty_out(vty, " Last read %s",
9241 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9242 NULL));
9243 vty_out(vty, ", Last write %s\n",
9244 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9245 NULL));
9246
9247 /* Configured timer values. */
9248 vty_out(vty,
9249 " Hold time is %d, keepalive interval is %d seconds\n",
9250 p->v_holdtime, p->v_keepalive);
9251 if (PEER_OR_GROUP_TIMER_SET(p)) {
9252 vty_out(vty, " Configured hold time is %d",
9253 p->holdtime);
9254 vty_out(vty, ", keepalive interval is %d seconds\n",
9255 p->keepalive);
9256 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9257 || (bgp->default_keepalive
9258 != BGP_DEFAULT_KEEPALIVE)) {
9259 vty_out(vty, " Configured hold time is %d",
9260 bgp->default_holdtime);
9261 vty_out(vty, ", keepalive interval is %d seconds\n",
9262 bgp->default_keepalive);
9263 }
9264 }
9265 /* Capability. */
9266 if (p->status == Established) {
9267 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9268 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9269 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9270 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9271 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9272 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9273 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9274 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9275 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9276 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9277 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9278 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9279 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9280 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9281 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9282 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9283 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9284 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9285 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9286 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9287 if (use_json) {
9288 json_object *json_cap = NULL;
9289
9290 json_cap = json_object_new_object();
9291
9292 /* AS4 */
9293 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9294 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9295 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9296 && CHECK_FLAG(p->cap,
9297 PEER_CAP_AS4_RCV))
9298 json_object_string_add(
9299 json_cap, "4byteAs",
9300 "advertisedAndReceived");
9301 else if (CHECK_FLAG(p->cap,
9302 PEER_CAP_AS4_ADV))
9303 json_object_string_add(
9304 json_cap, "4byteAs",
9305 "advertised");
9306 else if (CHECK_FLAG(p->cap,
9307 PEER_CAP_AS4_RCV))
9308 json_object_string_add(
9309 json_cap, "4byteAs",
9310 "received");
9311 }
9312
9313 /* AddPath */
9314 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9315 || CHECK_FLAG(p->cap,
9316 PEER_CAP_ADDPATH_ADV)) {
9317 json_object *json_add = NULL;
9318 const char *print_store;
9319
9320 json_add = json_object_new_object();
9321
9322 FOREACH_AFI_SAFI (afi, safi) {
9323 json_object *json_sub = NULL;
9324 json_sub =
9325 json_object_new_object();
9326 print_store = afi_safi_print(
9327 afi, safi);
9328
9329 if (CHECK_FLAG(
9330 p->af_cap[afi]
9331 [safi],
9332 PEER_CAP_ADDPATH_AF_TX_ADV)
9333 || CHECK_FLAG(
9334 p->af_cap[afi]
9335 [safi],
9336 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9337 if (CHECK_FLAG(
9338 p->af_cap
9339 [afi]
9340 [safi],
9341 PEER_CAP_ADDPATH_AF_TX_ADV)
9342 && CHECK_FLAG(
9343 p->af_cap
9344 [afi]
9345 [safi],
9346 PEER_CAP_ADDPATH_AF_TX_RCV))
9347 json_object_boolean_true_add(
9348 json_sub,
9349 "txAdvertisedAndReceived");
9350 else if (
9351 CHECK_FLAG(
9352 p->af_cap
9353 [afi]
9354 [safi],
9355 PEER_CAP_ADDPATH_AF_TX_ADV))
9356 json_object_boolean_true_add(
9357 json_sub,
9358 "txAdvertised");
9359 else if (
9360 CHECK_FLAG(
9361 p->af_cap
9362 [afi]
9363 [safi],
9364 PEER_CAP_ADDPATH_AF_TX_RCV))
9365 json_object_boolean_true_add(
9366 json_sub,
9367 "txReceived");
9368 }
9369
9370 if (CHECK_FLAG(
9371 p->af_cap[afi]
9372 [safi],
9373 PEER_CAP_ADDPATH_AF_RX_ADV)
9374 || CHECK_FLAG(
9375 p->af_cap[afi]
9376 [safi],
9377 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9378 if (CHECK_FLAG(
9379 p->af_cap
9380 [afi]
9381 [safi],
9382 PEER_CAP_ADDPATH_AF_RX_ADV)
9383 && CHECK_FLAG(
9384 p->af_cap
9385 [afi]
9386 [safi],
9387 PEER_CAP_ADDPATH_AF_RX_RCV))
9388 json_object_boolean_true_add(
9389 json_sub,
9390 "rxAdvertisedAndReceived");
9391 else if (
9392 CHECK_FLAG(
9393 p->af_cap
9394 [afi]
9395 [safi],
9396 PEER_CAP_ADDPATH_AF_RX_ADV))
9397 json_object_boolean_true_add(
9398 json_sub,
9399 "rxAdvertised");
9400 else if (
9401 CHECK_FLAG(
9402 p->af_cap
9403 [afi]
9404 [safi],
9405 PEER_CAP_ADDPATH_AF_RX_RCV))
9406 json_object_boolean_true_add(
9407 json_sub,
9408 "rxReceived");
9409 }
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 || CHECK_FLAG(
9420 p->af_cap[afi]
9421 [safi],
9422 PEER_CAP_ADDPATH_AF_RX_ADV)
9423 || CHECK_FLAG(
9424 p->af_cap[afi]
9425 [safi],
9426 PEER_CAP_ADDPATH_AF_RX_RCV))
9427 json_object_object_add(
9428 json_add,
9429 print_store,
9430 json_sub);
9431 else
9432 json_object_free(
9433 json_sub);
9434 }
9435
9436 json_object_object_add(
9437 json_cap, "addPath", json_add);
9438 }
9439
9440 /* Dynamic */
9441 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9442 || CHECK_FLAG(p->cap,
9443 PEER_CAP_DYNAMIC_ADV)) {
9444 if (CHECK_FLAG(p->cap,
9445 PEER_CAP_DYNAMIC_ADV)
9446 && CHECK_FLAG(p->cap,
9447 PEER_CAP_DYNAMIC_RCV))
9448 json_object_string_add(
9449 json_cap, "dynamic",
9450 "advertisedAndReceived");
9451 else if (CHECK_FLAG(
9452 p->cap,
9453 PEER_CAP_DYNAMIC_ADV))
9454 json_object_string_add(
9455 json_cap, "dynamic",
9456 "advertised");
9457 else if (CHECK_FLAG(
9458 p->cap,
9459 PEER_CAP_DYNAMIC_RCV))
9460 json_object_string_add(
9461 json_cap, "dynamic",
9462 "received");
9463 }
9464
9465 /* Extended nexthop */
9466 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9467 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9468 json_object *json_nxt = NULL;
9469 const char *print_store;
9470
9471
9472 if (CHECK_FLAG(p->cap,
9473 PEER_CAP_ENHE_ADV)
9474 && CHECK_FLAG(p->cap,
9475 PEER_CAP_ENHE_RCV))
9476 json_object_string_add(
9477 json_cap,
9478 "extendedNexthop",
9479 "advertisedAndReceived");
9480 else if (CHECK_FLAG(p->cap,
9481 PEER_CAP_ENHE_ADV))
9482 json_object_string_add(
9483 json_cap,
9484 "extendedNexthop",
9485 "advertised");
9486 else if (CHECK_FLAG(p->cap,
9487 PEER_CAP_ENHE_RCV))
9488 json_object_string_add(
9489 json_cap,
9490 "extendedNexthop",
9491 "received");
9492
9493 if (CHECK_FLAG(p->cap,
9494 PEER_CAP_ENHE_RCV)) {
9495 json_nxt =
9496 json_object_new_object();
9497
9498 for (safi = SAFI_UNICAST;
9499 safi < SAFI_MAX; safi++) {
9500 if (CHECK_FLAG(
9501 p->af_cap
9502 [AFI_IP]
9503 [safi],
9504 PEER_CAP_ENHE_AF_RCV)) {
9505 print_store = afi_safi_print(
9506 AFI_IP,
9507 safi);
9508 json_object_string_add(
9509 json_nxt,
9510 print_store,
9511 "recieved");
9512 }
9513 }
9514 json_object_object_add(
9515 json_cap,
9516 "extendedNexthopFamililesByPeer",
9517 json_nxt);
9518 }
9519 }
9520
9521 /* Route Refresh */
9522 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9523 || CHECK_FLAG(p->cap,
9524 PEER_CAP_REFRESH_NEW_RCV)
9525 || CHECK_FLAG(p->cap,
9526 PEER_CAP_REFRESH_OLD_RCV)) {
9527 if (CHECK_FLAG(p->cap,
9528 PEER_CAP_REFRESH_ADV)
9529 && (CHECK_FLAG(
9530 p->cap,
9531 PEER_CAP_REFRESH_NEW_RCV)
9532 || CHECK_FLAG(
9533 p->cap,
9534 PEER_CAP_REFRESH_OLD_RCV))) {
9535 if (CHECK_FLAG(
9536 p->cap,
9537 PEER_CAP_REFRESH_OLD_RCV)
9538 && CHECK_FLAG(
9539 p->cap,
9540 PEER_CAP_REFRESH_NEW_RCV))
9541 json_object_string_add(
9542 json_cap,
9543 "routeRefresh",
9544 "advertisedAndReceivedOldNew");
9545 else {
9546 if (CHECK_FLAG(
9547 p->cap,
9548 PEER_CAP_REFRESH_OLD_RCV))
9549 json_object_string_add(
9550 json_cap,
9551 "routeRefresh",
9552 "advertisedAndReceivedOld");
9553 else
9554 json_object_string_add(
9555 json_cap,
9556 "routeRefresh",
9557 "advertisedAndReceivedNew");
9558 }
9559 } else if (
9560 CHECK_FLAG(
9561 p->cap,
9562 PEER_CAP_REFRESH_ADV))
9563 json_object_string_add(
9564 json_cap,
9565 "routeRefresh",
9566 "advertised");
9567 else if (
9568 CHECK_FLAG(
9569 p->cap,
9570 PEER_CAP_REFRESH_NEW_RCV)
9571 || CHECK_FLAG(
9572 p->cap,
9573 PEER_CAP_REFRESH_OLD_RCV))
9574 json_object_string_add(
9575 json_cap,
9576 "routeRefresh",
9577 "received");
9578 }
9579
9580 /* Multiprotocol Extensions */
9581 json_object *json_multi = NULL;
9582 json_multi = json_object_new_object();
9583
9584 FOREACH_AFI_SAFI (afi, safi) {
9585 if (p->afc_adv[afi][safi]
9586 || p->afc_recv[afi][safi]) {
9587 json_object *json_exten = NULL;
9588 json_exten =
9589 json_object_new_object();
9590
9591 if (p->afc_adv[afi][safi]
9592 && p->afc_recv[afi][safi])
9593 json_object_boolean_true_add(
9594 json_exten,
9595 "advertisedAndReceived");
9596 else if (p->afc_adv[afi][safi])
9597 json_object_boolean_true_add(
9598 json_exten,
9599 "advertised");
9600 else if (p->afc_recv[afi][safi])
9601 json_object_boolean_true_add(
9602 json_exten,
9603 "received");
9604
9605 json_object_object_add(
9606 json_multi,
9607 afi_safi_print(afi,
9608 safi),
9609 json_exten);
9610 }
9611 }
9612 json_object_object_add(
9613 json_cap, "multiprotocolExtensions",
9614 json_multi);
9615
9616 /* Hostname capabilities */
9617 json_object *json_hname = NULL;
9618
9619 json_hname = json_object_new_object();
9620
9621 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9622 json_object_string_add(
9623 json_hname, "advHostName",
9624 bgp->peer_self->hostname
9625 ? bgp->peer_self
9626 ->hostname
9627 : "n/a");
9628 json_object_string_add(
9629 json_hname, "advDomainName",
9630 bgp->peer_self->domainname
9631 ? bgp->peer_self
9632 ->domainname
9633 : "n/a");
9634 }
9635
9636
9637 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9638 json_object_string_add(
9639 json_hname, "rcvHostName",
9640 p->hostname ? p->hostname
9641 : "n/a");
9642 json_object_string_add(
9643 json_hname, "rcvDomainName",
9644 p->domainname ? p->domainname
9645 : "n/a");
9646 }
9647
9648 json_object_object_add(json_cap, "hostName",
9649 json_hname);
9650
9651 /* Gracefull Restart */
9652 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9653 || CHECK_FLAG(p->cap,
9654 PEER_CAP_RESTART_ADV)) {
9655 if (CHECK_FLAG(p->cap,
9656 PEER_CAP_RESTART_ADV)
9657 && CHECK_FLAG(p->cap,
9658 PEER_CAP_RESTART_RCV))
9659 json_object_string_add(
9660 json_cap,
9661 "gracefulRestart",
9662 "advertisedAndReceived");
9663 else if (CHECK_FLAG(
9664 p->cap,
9665 PEER_CAP_RESTART_ADV))
9666 json_object_string_add(
9667 json_cap,
9668 "gracefulRestartCapability",
9669 "advertised");
9670 else if (CHECK_FLAG(
9671 p->cap,
9672 PEER_CAP_RESTART_RCV))
9673 json_object_string_add(
9674 json_cap,
9675 "gracefulRestartCapability",
9676 "received");
9677
9678 if (CHECK_FLAG(p->cap,
9679 PEER_CAP_RESTART_RCV)) {
9680 int restart_af_count = 0;
9681 json_object *json_restart =
9682 NULL;
9683 json_restart =
9684 json_object_new_object();
9685
9686 json_object_int_add(
9687 json_cap,
9688 "gracefulRestartRemoteTimerMsecs",
9689 p->v_gr_restart * 1000);
9690
9691 FOREACH_AFI_SAFI (afi, safi) {
9692 if (CHECK_FLAG(
9693 p->af_cap
9694 [afi]
9695 [safi],
9696 PEER_CAP_RESTART_AF_RCV)) {
9697 json_object *
9698 json_sub =
9699 NULL;
9700 json_sub =
9701 json_object_new_object();
9702
9703 if (CHECK_FLAG(
9704 p->af_cap
9705 [afi]
9706 [safi],
9707 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9708 json_object_boolean_true_add(
9709 json_sub,
9710 "preserved");
9711 restart_af_count++;
9712 json_object_object_add(
9713 json_restart,
9714 afi_safi_print(
9715 afi,
9716 safi),
9717 json_sub);
9718 }
9719 }
9720 if (!restart_af_count) {
9721 json_object_string_add(
9722 json_cap,
9723 "addressFamiliesByPeer",
9724 "none");
9725 json_object_free(
9726 json_restart);
9727 } else
9728 json_object_object_add(
9729 json_cap,
9730 "addressFamiliesByPeer",
9731 json_restart);
9732 }
9733 }
9734 json_object_object_add(json_neigh,
9735 "neighborCapabilities",
9736 json_cap);
9737 } else {
9738 vty_out(vty, " Neighbor capabilities:\n");
9739
9740 /* AS4 */
9741 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9742 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9743 vty_out(vty, " 4 Byte AS:");
9744 if (CHECK_FLAG(p->cap,
9745 PEER_CAP_AS4_ADV))
9746 vty_out(vty, " advertised");
9747 if (CHECK_FLAG(p->cap,
9748 PEER_CAP_AS4_RCV))
9749 vty_out(vty, " %sreceived",
9750 CHECK_FLAG(
9751 p->cap,
9752 PEER_CAP_AS4_ADV)
9753 ? "and "
9754 : "");
9755 vty_out(vty, "\n");
9756 }
9757
9758 /* AddPath */
9759 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9760 || CHECK_FLAG(p->cap,
9761 PEER_CAP_ADDPATH_ADV)) {
9762 vty_out(vty, " AddPath:\n");
9763
9764 FOREACH_AFI_SAFI (afi, safi) {
9765 if (CHECK_FLAG(
9766 p->af_cap[afi]
9767 [safi],
9768 PEER_CAP_ADDPATH_AF_TX_ADV)
9769 || CHECK_FLAG(
9770 p->af_cap[afi]
9771 [safi],
9772 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9773 vty_out(vty,
9774 " %s: TX ",
9775 afi_safi_print(
9776 afi,
9777 safi));
9778
9779 if (CHECK_FLAG(
9780 p->af_cap
9781 [afi]
9782 [safi],
9783 PEER_CAP_ADDPATH_AF_TX_ADV))
9784 vty_out(vty,
9785 "advertised %s",
9786 afi_safi_print(
9787 afi,
9788 safi));
9789
9790 if (CHECK_FLAG(
9791 p->af_cap
9792 [afi]
9793 [safi],
9794 PEER_CAP_ADDPATH_AF_TX_RCV))
9795 vty_out(vty,
9796 "%sreceived",
9797 CHECK_FLAG(
9798 p->af_cap
9799 [afi]
9800 [safi],
9801 PEER_CAP_ADDPATH_AF_TX_ADV)
9802 ? " and "
9803 : "");
9804
9805 vty_out(vty, "\n");
9806 }
9807
9808 if (CHECK_FLAG(
9809 p->af_cap[afi]
9810 [safi],
9811 PEER_CAP_ADDPATH_AF_RX_ADV)
9812 || CHECK_FLAG(
9813 p->af_cap[afi]
9814 [safi],
9815 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9816 vty_out(vty,
9817 " %s: RX ",
9818 afi_safi_print(
9819 afi,
9820 safi));
9821
9822 if (CHECK_FLAG(
9823 p->af_cap
9824 [afi]
9825 [safi],
9826 PEER_CAP_ADDPATH_AF_RX_ADV))
9827 vty_out(vty,
9828 "advertised %s",
9829 afi_safi_print(
9830 afi,
9831 safi));
9832
9833 if (CHECK_FLAG(
9834 p->af_cap
9835 [afi]
9836 [safi],
9837 PEER_CAP_ADDPATH_AF_RX_RCV))
9838 vty_out(vty,
9839 "%sreceived",
9840 CHECK_FLAG(
9841 p->af_cap
9842 [afi]
9843 [safi],
9844 PEER_CAP_ADDPATH_AF_RX_ADV)
9845 ? " and "
9846 : "");
9847
9848 vty_out(vty, "\n");
9849 }
9850 }
9851 }
9852
9853 /* Dynamic */
9854 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9855 || CHECK_FLAG(p->cap,
9856 PEER_CAP_DYNAMIC_ADV)) {
9857 vty_out(vty, " Dynamic:");
9858 if (CHECK_FLAG(p->cap,
9859 PEER_CAP_DYNAMIC_ADV))
9860 vty_out(vty, " advertised");
9861 if (CHECK_FLAG(p->cap,
9862 PEER_CAP_DYNAMIC_RCV))
9863 vty_out(vty, " %sreceived",
9864 CHECK_FLAG(
9865 p->cap,
9866 PEER_CAP_DYNAMIC_ADV)
9867 ? "and "
9868 : "");
9869 vty_out(vty, "\n");
9870 }
9871
9872 /* Extended nexthop */
9873 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9874 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9875 vty_out(vty, " Extended nexthop:");
9876 if (CHECK_FLAG(p->cap,
9877 PEER_CAP_ENHE_ADV))
9878 vty_out(vty, " advertised");
9879 if (CHECK_FLAG(p->cap,
9880 PEER_CAP_ENHE_RCV))
9881 vty_out(vty, " %sreceived",
9882 CHECK_FLAG(
9883 p->cap,
9884 PEER_CAP_ENHE_ADV)
9885 ? "and "
9886 : "");
9887 vty_out(vty, "\n");
9888
9889 if (CHECK_FLAG(p->cap,
9890 PEER_CAP_ENHE_RCV)) {
9891 vty_out(vty,
9892 " Address families by peer:\n ");
9893 for (safi = SAFI_UNICAST;
9894 safi < SAFI_MAX; safi++)
9895 if (CHECK_FLAG(
9896 p->af_cap
9897 [AFI_IP]
9898 [safi],
9899 PEER_CAP_ENHE_AF_RCV))
9900 vty_out(vty,
9901 " %s\n",
9902 afi_safi_print(
9903 AFI_IP,
9904 safi));
9905 }
9906 }
9907
9908 /* Route Refresh */
9909 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9910 || CHECK_FLAG(p->cap,
9911 PEER_CAP_REFRESH_NEW_RCV)
9912 || CHECK_FLAG(p->cap,
9913 PEER_CAP_REFRESH_OLD_RCV)) {
9914 vty_out(vty, " Route refresh:");
9915 if (CHECK_FLAG(p->cap,
9916 PEER_CAP_REFRESH_ADV))
9917 vty_out(vty, " advertised");
9918 if (CHECK_FLAG(p->cap,
9919 PEER_CAP_REFRESH_NEW_RCV)
9920 || CHECK_FLAG(
9921 p->cap,
9922 PEER_CAP_REFRESH_OLD_RCV))
9923 vty_out(vty, " %sreceived(%s)",
9924 CHECK_FLAG(
9925 p->cap,
9926 PEER_CAP_REFRESH_ADV)
9927 ? "and "
9928 : "",
9929 (CHECK_FLAG(
9930 p->cap,
9931 PEER_CAP_REFRESH_OLD_RCV)
9932 && CHECK_FLAG(
9933 p->cap,
9934 PEER_CAP_REFRESH_NEW_RCV))
9935 ? "old & new"
9936 : CHECK_FLAG(
9937 p->cap,
9938 PEER_CAP_REFRESH_OLD_RCV)
9939 ? "old"
9940 : "new");
9941
9942 vty_out(vty, "\n");
9943 }
9944
9945 /* Multiprotocol Extensions */
9946 FOREACH_AFI_SAFI (afi, safi)
9947 if (p->afc_adv[afi][safi]
9948 || p->afc_recv[afi][safi]) {
9949 vty_out(vty,
9950 " Address Family %s:",
9951 afi_safi_print(afi,
9952 safi));
9953 if (p->afc_adv[afi][safi])
9954 vty_out(vty,
9955 " advertised");
9956 if (p->afc_recv[afi][safi])
9957 vty_out(vty,
9958 " %sreceived",
9959 p->afc_adv[afi]
9960 [safi]
9961 ? "and "
9962 : "");
9963 vty_out(vty, "\n");
9964 }
9965
9966 /* Hostname capability */
9967 vty_out(vty, " Hostname Capability:");
9968
9969 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9970 vty_out(vty,
9971 " advertised (name: %s,domain name: %s)",
9972 bgp->peer_self->hostname
9973 ? bgp->peer_self
9974 ->hostname
9975 : "n/a",
9976 bgp->peer_self->domainname
9977 ? bgp->peer_self
9978 ->domainname
9979 : "n/a");
9980 } else {
9981 vty_out(vty, " not advertised");
9982 }
9983
9984 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9985 vty_out(vty,
9986 " received (name: %s,domain name: %s)",
9987 p->hostname ? p->hostname
9988 : "n/a",
9989 p->domainname ? p->domainname
9990 : "n/a");
9991 } else {
9992 vty_out(vty, " not received");
9993 }
9994
9995 vty_out(vty, "\n");
9996
9997 /* Gracefull Restart */
9998 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9999 || CHECK_FLAG(p->cap,
10000 PEER_CAP_RESTART_ADV)) {
10001 vty_out(vty,
10002 " Graceful Restart Capabilty:");
10003 if (CHECK_FLAG(p->cap,
10004 PEER_CAP_RESTART_ADV))
10005 vty_out(vty, " advertised");
10006 if (CHECK_FLAG(p->cap,
10007 PEER_CAP_RESTART_RCV))
10008 vty_out(vty, " %sreceived",
10009 CHECK_FLAG(
10010 p->cap,
10011 PEER_CAP_RESTART_ADV)
10012 ? "and "
10013 : "");
10014 vty_out(vty, "\n");
10015
10016 if (CHECK_FLAG(p->cap,
10017 PEER_CAP_RESTART_RCV)) {
10018 int restart_af_count = 0;
10019
10020 vty_out(vty,
10021 " Remote Restart timer is %d seconds\n",
10022 p->v_gr_restart);
10023 vty_out(vty,
10024 " Address families by peer:\n ");
10025
10026 FOREACH_AFI_SAFI (afi, safi)
10027 if (CHECK_FLAG(
10028 p->af_cap
10029 [afi]
10030 [safi],
10031 PEER_CAP_RESTART_AF_RCV)) {
10032 vty_out(vty,
10033 "%s%s(%s)",
10034 restart_af_count
10035 ? ", "
10036 : "",
10037 afi_safi_print(
10038 afi,
10039 safi),
10040 CHECK_FLAG(
10041 p->af_cap
10042 [afi]
10043 [safi],
10044 PEER_CAP_RESTART_AF_PRESERVE_RCV)
10045 ? "preserved"
10046 : "not preserved");
10047 restart_af_count++;
10048 }
10049 if (!restart_af_count)
10050 vty_out(vty, "none");
10051 vty_out(vty, "\n");
10052 }
10053 }
10054 }
10055 }
10056 }
10057
10058 /* graceful restart information */
10059 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
10060 || p->t_gr_stale) {
10061 json_object *json_grace = NULL;
10062 json_object *json_grace_send = NULL;
10063 json_object *json_grace_recv = NULL;
10064 int eor_send_af_count = 0;
10065 int eor_receive_af_count = 0;
10066
10067 if (use_json) {
10068 json_grace = json_object_new_object();
10069 json_grace_send = json_object_new_object();
10070 json_grace_recv = json_object_new_object();
10071
10072 if (p->status == Established) {
10073 FOREACH_AFI_SAFI (afi, safi) {
10074 if (CHECK_FLAG(p->af_sflags[afi][safi],
10075 PEER_STATUS_EOR_SEND)) {
10076 json_object_boolean_true_add(
10077 json_grace_send,
10078 afi_safi_print(afi,
10079 safi));
10080 eor_send_af_count++;
10081 }
10082 }
10083 FOREACH_AFI_SAFI (afi, safi) {
10084 if (CHECK_FLAG(
10085 p->af_sflags[afi][safi],
10086 PEER_STATUS_EOR_RECEIVED)) {
10087 json_object_boolean_true_add(
10088 json_grace_recv,
10089 afi_safi_print(afi,
10090 safi));
10091 eor_receive_af_count++;
10092 }
10093 }
10094 }
10095
10096 json_object_object_add(json_grace, "endOfRibSend",
10097 json_grace_send);
10098 json_object_object_add(json_grace, "endOfRibRecv",
10099 json_grace_recv);
10100
10101 if (p->t_gr_restart)
10102 json_object_int_add(json_grace,
10103 "gracefulRestartTimerMsecs",
10104 thread_timer_remain_second(
10105 p->t_gr_restart)
10106 * 1000);
10107
10108 if (p->t_gr_stale)
10109 json_object_int_add(
10110 json_grace,
10111 "gracefulStalepathTimerMsecs",
10112 thread_timer_remain_second(
10113 p->t_gr_stale)
10114 * 1000);
10115
10116 json_object_object_add(
10117 json_neigh, "gracefulRestartInfo", json_grace);
10118 } else {
10119 vty_out(vty, " Graceful restart informations:\n");
10120 if (p->status == Established) {
10121 vty_out(vty, " End-of-RIB send: ");
10122 FOREACH_AFI_SAFI (afi, safi) {
10123 if (CHECK_FLAG(p->af_sflags[afi][safi],
10124 PEER_STATUS_EOR_SEND)) {
10125 vty_out(vty, "%s%s",
10126 eor_send_af_count ? ", "
10127 : "",
10128 afi_safi_print(afi,
10129 safi));
10130 eor_send_af_count++;
10131 }
10132 }
10133 vty_out(vty, "\n");
10134 vty_out(vty, " End-of-RIB received: ");
10135 FOREACH_AFI_SAFI (afi, safi) {
10136 if (CHECK_FLAG(
10137 p->af_sflags[afi][safi],
10138 PEER_STATUS_EOR_RECEIVED)) {
10139 vty_out(vty, "%s%s",
10140 eor_receive_af_count
10141 ? ", "
10142 : "",
10143 afi_safi_print(afi,
10144 safi));
10145 eor_receive_af_count++;
10146 }
10147 }
10148 vty_out(vty, "\n");
10149 }
10150
10151 if (p->t_gr_restart)
10152 vty_out(vty,
10153 " The remaining time of restart timer is %ld\n",
10154 thread_timer_remain_second(
10155 p->t_gr_restart));
10156
10157 if (p->t_gr_stale)
10158 vty_out(vty,
10159 " The remaining time of stalepath timer is %ld\n",
10160 thread_timer_remain_second(
10161 p->t_gr_stale));
10162 }
10163 }
10164 if (use_json) {
10165 json_object *json_stat = NULL;
10166 json_stat = json_object_new_object();
10167 /* Packet counts. */
10168 json_object_int_add(json_stat, "depthInq", 0);
10169 json_object_int_add(json_stat, "depthOutq",
10170 (unsigned long)p->obuf->count);
10171 json_object_int_add(json_stat, "opensSent",
10172 atomic_load_explicit(&p->open_out,
10173 memory_order_relaxed));
10174 json_object_int_add(json_stat, "opensRecv",
10175 atomic_load_explicit(&p->open_in,
10176 memory_order_relaxed));
10177 json_object_int_add(json_stat, "notificationsSent",
10178 atomic_load_explicit(&p->notify_out,
10179 memory_order_relaxed));
10180 json_object_int_add(json_stat, "notificationsRecv",
10181 atomic_load_explicit(&p->notify_in,
10182 memory_order_relaxed));
10183 json_object_int_add(json_stat, "updatesSent",
10184 atomic_load_explicit(&p->update_out,
10185 memory_order_relaxed));
10186 json_object_int_add(json_stat, "updatesRecv",
10187 atomic_load_explicit(&p->update_in,
10188 memory_order_relaxed));
10189 json_object_int_add(json_stat, "keepalivesSent",
10190 atomic_load_explicit(&p->keepalive_out,
10191 memory_order_relaxed));
10192 json_object_int_add(json_stat, "keepalivesRecv",
10193 atomic_load_explicit(&p->keepalive_in,
10194 memory_order_relaxed));
10195 json_object_int_add(json_stat, "routeRefreshSent",
10196 atomic_load_explicit(&p->refresh_out,
10197 memory_order_relaxed));
10198 json_object_int_add(json_stat, "routeRefreshRecv",
10199 atomic_load_explicit(&p->refresh_in,
10200 memory_order_relaxed));
10201 json_object_int_add(json_stat, "capabilitySent",
10202 atomic_load_explicit(&p->dynamic_cap_out,
10203 memory_order_relaxed));
10204 json_object_int_add(json_stat, "capabilityRecv",
10205 atomic_load_explicit(&p->dynamic_cap_in,
10206 memory_order_relaxed));
10207 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10208 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10209 json_object_object_add(json_neigh, "messageStats", json_stat);
10210 } else {
10211 /* Packet counts. */
10212 vty_out(vty, " Message statistics:\n");
10213 vty_out(vty, " Inq depth is 0\n");
10214 vty_out(vty, " Outq depth is %lu\n",
10215 (unsigned long)p->obuf->count);
10216 vty_out(vty, " Sent Rcvd\n");
10217 vty_out(vty, " Opens: %10d %10d\n",
10218 atomic_load_explicit(&p->open_out,
10219 memory_order_relaxed),
10220 atomic_load_explicit(&p->open_in,
10221 memory_order_relaxed));
10222 vty_out(vty, " Notifications: %10d %10d\n",
10223 atomic_load_explicit(&p->notify_out,
10224 memory_order_relaxed),
10225 atomic_load_explicit(&p->notify_in,
10226 memory_order_relaxed));
10227 vty_out(vty, " Updates: %10d %10d\n",
10228 atomic_load_explicit(&p->update_out,
10229 memory_order_relaxed),
10230 atomic_load_explicit(&p->update_in,
10231 memory_order_relaxed));
10232 vty_out(vty, " Keepalives: %10d %10d\n",
10233 atomic_load_explicit(&p->keepalive_out,
10234 memory_order_relaxed),
10235 atomic_load_explicit(&p->keepalive_in,
10236 memory_order_relaxed));
10237 vty_out(vty, " Route Refresh: %10d %10d\n",
10238 atomic_load_explicit(&p->refresh_out,
10239 memory_order_relaxed),
10240 atomic_load_explicit(&p->refresh_in,
10241 memory_order_relaxed));
10242 vty_out(vty, " Capability: %10d %10d\n",
10243 atomic_load_explicit(&p->dynamic_cap_out,
10244 memory_order_relaxed),
10245 atomic_load_explicit(&p->dynamic_cap_in,
10246 memory_order_relaxed));
10247 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10248 PEER_TOTAL_RX(p));
10249 }
10250
10251 if (use_json) {
10252 /* advertisement-interval */
10253 json_object_int_add(json_neigh,
10254 "minBtwnAdvertisementRunsTimerMsecs",
10255 p->v_routeadv * 1000);
10256
10257 /* Update-source. */
10258 if (p->update_if || p->update_source) {
10259 if (p->update_if)
10260 json_object_string_add(json_neigh,
10261 "updateSource",
10262 p->update_if);
10263 else if (p->update_source)
10264 json_object_string_add(
10265 json_neigh, "updateSource",
10266 sockunion2str(p->update_source, buf1,
10267 SU_ADDRSTRLEN));
10268 }
10269 } else {
10270 /* advertisement-interval */
10271 vty_out(vty,
10272 " Minimum time between advertisement runs is %d seconds\n",
10273 p->v_routeadv);
10274
10275 /* Update-source. */
10276 if (p->update_if || p->update_source) {
10277 vty_out(vty, " Update source is ");
10278 if (p->update_if)
10279 vty_out(vty, "%s", p->update_if);
10280 else if (p->update_source)
10281 vty_out(vty, "%s",
10282 sockunion2str(p->update_source, buf1,
10283 SU_ADDRSTRLEN));
10284 vty_out(vty, "\n");
10285 }
10286
10287 vty_out(vty, "\n");
10288 }
10289
10290 /* Address Family Information */
10291 json_object *json_hold = NULL;
10292
10293 if (use_json)
10294 json_hold = json_object_new_object();
10295
10296 FOREACH_AFI_SAFI (afi, safi)
10297 if (p->afc[afi][safi])
10298 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10299 json_hold);
10300
10301 if (use_json) {
10302 json_object_object_add(json_neigh, "addressFamilyInfo",
10303 json_hold);
10304 json_object_int_add(json_neigh, "connectionsEstablished",
10305 p->established);
10306 json_object_int_add(json_neigh, "connectionsDropped",
10307 p->dropped);
10308 } else
10309 vty_out(vty, " Connections established %d; dropped %d\n",
10310 p->established, p->dropped);
10311
10312 if (!p->last_reset) {
10313 if (use_json)
10314 json_object_string_add(json_neigh, "lastReset",
10315 "never");
10316 else
10317 vty_out(vty, " Last reset never\n");
10318 } else {
10319 if (use_json) {
10320 time_t uptime;
10321 struct tm *tm;
10322
10323 uptime = bgp_clock();
10324 uptime -= p->resettime;
10325 tm = gmtime(&uptime);
10326 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10327 (tm->tm_sec * 1000)
10328 + (tm->tm_min * 60000)
10329 + (tm->tm_hour * 3600000));
10330 json_object_string_add(
10331 json_neigh, "lastResetDueTo",
10332 peer_down_str[(int)p->last_reset]);
10333 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10334 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10335 char errorcodesubcode_hexstr[5];
10336 char errorcodesubcode_str[256];
10337
10338 code_str = bgp_notify_code_str(p->notify.code);
10339 subcode_str = bgp_notify_subcode_str(
10340 p->notify.code, p->notify.subcode);
10341
10342 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10343 p->notify.code, p->notify.subcode);
10344 json_object_string_add(json_neigh,
10345 "lastErrorCodeSubcode",
10346 errorcodesubcode_hexstr);
10347 snprintf(errorcodesubcode_str, 255, "%s%s",
10348 code_str, subcode_str);
10349 json_object_string_add(json_neigh,
10350 "lastNotificationReason",
10351 errorcodesubcode_str);
10352 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10353 && p->notify.code == BGP_NOTIFY_CEASE
10354 && (p->notify.subcode
10355 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10356 || p->notify.subcode
10357 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10358 && p->notify.length) {
10359 char msgbuf[1024];
10360 const char *msg_str;
10361
10362 msg_str = bgp_notify_admin_message(
10363 msgbuf, sizeof(msgbuf),
10364 (uint8_t *)p->notify.data,
10365 p->notify.length);
10366 if (msg_str)
10367 json_object_string_add(
10368 json_neigh,
10369 "lastShutdownDescription",
10370 msg_str);
10371 }
10372 }
10373 } else {
10374 vty_out(vty, " Last reset %s, ",
10375 peer_uptime(p->resettime, timebuf,
10376 BGP_UPTIME_LEN, 0, NULL));
10377
10378 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10379 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10380 code_str = bgp_notify_code_str(p->notify.code);
10381 subcode_str = bgp_notify_subcode_str(
10382 p->notify.code, p->notify.subcode);
10383 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10384 p->last_reset == PEER_DOWN_NOTIFY_SEND
10385 ? "sent"
10386 : "received",
10387 code_str, subcode_str);
10388 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10389 && p->notify.code == BGP_NOTIFY_CEASE
10390 && (p->notify.subcode
10391 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10392 || p->notify.subcode
10393 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10394 && p->notify.length) {
10395 char msgbuf[1024];
10396 const char *msg_str;
10397
10398 msg_str = bgp_notify_admin_message(
10399 msgbuf, sizeof(msgbuf),
10400 (uint8_t *)p->notify.data,
10401 p->notify.length);
10402 if (msg_str)
10403 vty_out(vty,
10404 " Message: \"%s\"\n",
10405 msg_str);
10406 }
10407 } else {
10408 vty_out(vty, "due to %s\n",
10409 peer_down_str[(int)p->last_reset]);
10410 }
10411
10412 if (p->last_reset_cause_size) {
10413 msg = p->last_reset_cause;
10414 vty_out(vty,
10415 " Message received that caused BGP to send a NOTIFICATION:\n ");
10416 for (i = 1; i <= p->last_reset_cause_size;
10417 i++) {
10418 vty_out(vty, "%02X", *msg++);
10419
10420 if (i != p->last_reset_cause_size) {
10421 if (i % 16 == 0) {
10422 vty_out(vty, "\n ");
10423 } else if (i % 4 == 0) {
10424 vty_out(vty, " ");
10425 }
10426 }
10427 }
10428 vty_out(vty, "\n");
10429 }
10430 }
10431 }
10432
10433 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10434 if (use_json)
10435 json_object_boolean_true_add(json_neigh,
10436 "prefixesConfigExceedMax");
10437 else
10438 vty_out(vty,
10439 " Peer had exceeded the max. no. of prefixes configured.\n");
10440
10441 if (p->t_pmax_restart) {
10442 if (use_json) {
10443 json_object_boolean_true_add(
10444 json_neigh, "reducePrefixNumFrom");
10445 json_object_int_add(json_neigh,
10446 "restartInTimerMsec",
10447 thread_timer_remain_second(
10448 p->t_pmax_restart)
10449 * 1000);
10450 } else
10451 vty_out(vty,
10452 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10453 p->host, thread_timer_remain_second(
10454 p->t_pmax_restart));
10455 } else {
10456 if (use_json)
10457 json_object_boolean_true_add(
10458 json_neigh,
10459 "reducePrefixNumAndClearIpBgp");
10460 else
10461 vty_out(vty,
10462 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10463 p->host);
10464 }
10465 }
10466
10467 /* EBGP Multihop and GTSM */
10468 if (p->sort != BGP_PEER_IBGP) {
10469 if (use_json) {
10470 if (p->gtsm_hops > 0)
10471 json_object_int_add(json_neigh,
10472 "externalBgpNbrMaxHopsAway",
10473 p->gtsm_hops);
10474 else if (p->ttl > 1)
10475 json_object_int_add(json_neigh,
10476 "externalBgpNbrMaxHopsAway",
10477 p->ttl);
10478 } else {
10479 if (p->gtsm_hops > 0)
10480 vty_out(vty,
10481 " External BGP neighbor may be up to %d hops away.\n",
10482 p->gtsm_hops);
10483 else if (p->ttl > 1)
10484 vty_out(vty,
10485 " External BGP neighbor may be up to %d hops away.\n",
10486 p->ttl);
10487 }
10488 } else {
10489 if (p->gtsm_hops > 0) {
10490 if (use_json)
10491 json_object_int_add(json_neigh,
10492 "internalBgpNbrMaxHopsAway",
10493 p->gtsm_hops);
10494 else
10495 vty_out(vty,
10496 " Internal BGP neighbor may be up to %d hops away.\n",
10497 p->gtsm_hops);
10498 }
10499 }
10500
10501 /* Local address. */
10502 if (p->su_local) {
10503 if (use_json) {
10504 json_object_string_add(json_neigh, "hostLocal",
10505 sockunion2str(p->su_local, buf1,
10506 SU_ADDRSTRLEN));
10507 json_object_int_add(json_neigh, "portLocal",
10508 ntohs(p->su_local->sin.sin_port));
10509 } else
10510 vty_out(vty, "Local host: %s, Local port: %d\n",
10511 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10512 ntohs(p->su_local->sin.sin_port));
10513 }
10514
10515 /* Remote address. */
10516 if (p->su_remote) {
10517 if (use_json) {
10518 json_object_string_add(json_neigh, "hostForeign",
10519 sockunion2str(p->su_remote, buf1,
10520 SU_ADDRSTRLEN));
10521 json_object_int_add(json_neigh, "portForeign",
10522 ntohs(p->su_remote->sin.sin_port));
10523 } else
10524 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10525 sockunion2str(p->su_remote, buf1,
10526 SU_ADDRSTRLEN),
10527 ntohs(p->su_remote->sin.sin_port));
10528 }
10529
10530 /* Nexthop display. */
10531 if (p->su_local) {
10532 if (use_json) {
10533 json_object_string_add(json_neigh, "nexthop",
10534 inet_ntop(AF_INET,
10535 &p->nexthop.v4, buf1,
10536 sizeof(buf1)));
10537 json_object_string_add(json_neigh, "nexthopGlobal",
10538 inet_ntop(AF_INET6,
10539 &p->nexthop.v6_global,
10540 buf1, sizeof(buf1)));
10541 json_object_string_add(json_neigh, "nexthopLocal",
10542 inet_ntop(AF_INET6,
10543 &p->nexthop.v6_local,
10544 buf1, sizeof(buf1)));
10545 if (p->shared_network)
10546 json_object_string_add(json_neigh,
10547 "bgpConnection",
10548 "sharedNetwork");
10549 else
10550 json_object_string_add(json_neigh,
10551 "bgpConnection",
10552 "nonSharedNetwork");
10553 } else {
10554 vty_out(vty, "Nexthop: %s\n",
10555 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10556 sizeof(buf1)));
10557 vty_out(vty, "Nexthop global: %s\n",
10558 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10559 sizeof(buf1)));
10560 vty_out(vty, "Nexthop local: %s\n",
10561 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10562 sizeof(buf1)));
10563 vty_out(vty, "BGP connection: %s\n",
10564 p->shared_network ? "shared network"
10565 : "non shared network");
10566 }
10567 }
10568
10569 /* Timer information. */
10570 if (use_json) {
10571 json_object_int_add(json_neigh, "connectRetryTimer",
10572 p->v_connect);
10573 if (p->status == Established && p->rtt)
10574 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10575 p->rtt);
10576 if (p->t_start)
10577 json_object_int_add(
10578 json_neigh, "nextStartTimerDueInMsecs",
10579 thread_timer_remain_second(p->t_start) * 1000);
10580 if (p->t_connect)
10581 json_object_int_add(
10582 json_neigh, "nextConnectTimerDueInMsecs",
10583 thread_timer_remain_second(p->t_connect)
10584 * 1000);
10585 if (p->t_routeadv) {
10586 json_object_int_add(json_neigh, "mraiInterval",
10587 p->v_routeadv);
10588 json_object_int_add(
10589 json_neigh, "mraiTimerExpireInMsecs",
10590 thread_timer_remain_second(p->t_routeadv)
10591 * 1000);
10592 }
10593 if (p->password)
10594 json_object_int_add(json_neigh, "authenticationEnabled",
10595 1);
10596
10597 if (p->t_read)
10598 json_object_string_add(json_neigh, "readThread", "on");
10599 else
10600 json_object_string_add(json_neigh, "readThread", "off");
10601
10602 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10603 json_object_string_add(json_neigh, "writeThread", "on");
10604 else
10605 json_object_string_add(json_neigh, "writeThread",
10606 "off");
10607 } else {
10608 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10609 p->v_connect);
10610 if (p->status == Established && p->rtt)
10611 vty_out(vty, "Estimated round trip time: %d ms\n",
10612 p->rtt);
10613 if (p->t_start)
10614 vty_out(vty, "Next start timer due in %ld seconds\n",
10615 thread_timer_remain_second(p->t_start));
10616 if (p->t_connect)
10617 vty_out(vty, "Next connect timer due in %ld seconds\n",
10618 thread_timer_remain_second(p->t_connect));
10619 if (p->t_routeadv)
10620 vty_out(vty,
10621 "MRAI (interval %u) timer expires in %ld seconds\n",
10622 p->v_routeadv,
10623 thread_timer_remain_second(p->t_routeadv));
10624 if (p->password)
10625 vty_out(vty, "Peer Authentication Enabled\n");
10626
10627 vty_out(vty, "Read thread: %s Write thread: %s\n",
10628 p->t_read ? "on" : "off",
10629 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10630 ? "on"
10631 : "off");
10632 }
10633
10634 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10635 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10636 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10637
10638 if (!use_json)
10639 vty_out(vty, "\n");
10640
10641 /* BFD information. */
10642 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10643
10644 if (use_json) {
10645 if (p->conf_if) /* Configured interface name. */
10646 json_object_object_add(json, p->conf_if, json_neigh);
10647 else /* Configured IP address. */
10648 json_object_object_add(json, p->host, json_neigh);
10649 }
10650 }
10651
10652 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10653 enum show_type type, union sockunion *su,
10654 const char *conf_if, uint8_t use_json,
10655 json_object *json)
10656 {
10657 struct listnode *node, *nnode;
10658 struct peer *peer;
10659 int find = 0;
10660
10661 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10662 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10663 continue;
10664
10665 switch (type) {
10666 case show_all:
10667 bgp_show_peer(vty, peer, use_json, json);
10668 break;
10669 case show_peer:
10670 if (conf_if) {
10671 if ((peer->conf_if
10672 && !strcmp(peer->conf_if, conf_if))
10673 || (peer->hostname
10674 && !strcmp(peer->hostname, conf_if))) {
10675 find = 1;
10676 bgp_show_peer(vty, peer, use_json,
10677 json);
10678 }
10679 } else {
10680 if (sockunion_same(&peer->su, su)) {
10681 find = 1;
10682 bgp_show_peer(vty, peer, use_json,
10683 json);
10684 }
10685 }
10686 break;
10687 }
10688 }
10689
10690 if (type == show_peer && !find) {
10691 if (use_json)
10692 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10693 else
10694 vty_out(vty, "%% No such neighbor in this view/vrf\n");
10695 }
10696
10697 if (use_json) {
10698 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10699 json, JSON_C_TO_STRING_PRETTY));
10700 json_object_free(json);
10701 } else {
10702 vty_out(vty, "\n");
10703 }
10704
10705 return CMD_SUCCESS;
10706 }
10707
10708 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10709 enum show_type type,
10710 const char *ip_str,
10711 uint8_t use_json)
10712 {
10713 struct listnode *node, *nnode;
10714 struct bgp *bgp;
10715 union sockunion su;
10716 json_object *json = NULL;
10717 int ret, is_first = 1;
10718
10719 if (use_json)
10720 vty_out(vty, "{\n");
10721
10722 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10723 if (use_json) {
10724 if (!(json = json_object_new_object())) {
10725 zlog_err(
10726 "Unable to allocate memory for JSON object");
10727 vty_out(vty,
10728 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10729 return;
10730 }
10731
10732 json_object_int_add(json, "vrfId",
10733 (bgp->vrf_id == VRF_UNKNOWN)
10734 ? -1
10735 : (int64_t)bgp->vrf_id);
10736 json_object_string_add(
10737 json, "vrfName",
10738 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10739 ? "Default"
10740 : bgp->name);
10741
10742 if (!is_first)
10743 vty_out(vty, ",\n");
10744 else
10745 is_first = 0;
10746
10747 vty_out(vty, "\"%s\":",
10748 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10749 ? "Default"
10750 : bgp->name);
10751 } else {
10752 vty_out(vty, "\nInstance %s:\n",
10753 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10754 ? "Default"
10755 : bgp->name);
10756 }
10757
10758 if (type == show_peer) {
10759 ret = str2sockunion(ip_str, &su);
10760 if (ret < 0)
10761 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10762 use_json, json);
10763 else
10764 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10765 use_json, json);
10766 } else {
10767 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10768 use_json, json);
10769 }
10770 }
10771
10772 if (use_json)
10773 vty_out(vty, "}\n");
10774 }
10775
10776 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10777 enum show_type type, const char *ip_str,
10778 uint8_t use_json)
10779 {
10780 int ret;
10781 struct bgp *bgp;
10782 union sockunion su;
10783 json_object *json = NULL;
10784
10785 if (name) {
10786 if (strmatch(name, "all")) {
10787 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10788 use_json);
10789 return CMD_SUCCESS;
10790 } else {
10791 bgp = bgp_lookup_by_name(name);
10792 if (!bgp) {
10793 if (use_json) {
10794 json = json_object_new_object();
10795 json_object_boolean_true_add(
10796 json, "bgpNoSuchInstance");
10797 vty_out(vty, "%s\n",
10798 json_object_to_json_string_ext(
10799 json,
10800 JSON_C_TO_STRING_PRETTY));
10801 json_object_free(json);
10802 } else
10803 vty_out(vty,
10804 "%% No such BGP instance exist\n");
10805
10806 return CMD_WARNING;
10807 }
10808 }
10809 } else {
10810 bgp = bgp_get_default();
10811 }
10812
10813 if (bgp) {
10814 json = json_object_new_object();
10815 if (ip_str) {
10816 ret = str2sockunion(ip_str, &su);
10817 if (ret < 0)
10818 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10819 use_json, json);
10820 else
10821 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10822 use_json, json);
10823 } else {
10824 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10825 json);
10826 }
10827 json_object_free(json);
10828 }
10829
10830 return CMD_SUCCESS;
10831 }
10832
10833 /* "show [ip] bgp neighbors" commands. */
10834 DEFUN (show_ip_bgp_neighbors,
10835 show_ip_bgp_neighbors_cmd,
10836 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10837 SHOW_STR
10838 IP_STR
10839 BGP_STR
10840 BGP_INSTANCE_HELP_STR
10841 "Address Family\n"
10842 "Address Family\n"
10843 "Detailed information on TCP and BGP neighbor connections\n"
10844 "Neighbor to display information about\n"
10845 "Neighbor to display information about\n"
10846 "Neighbor on BGP configured interface\n"
10847 JSON_STR)
10848 {
10849 char *vrf = NULL;
10850 char *sh_arg = NULL;
10851 enum show_type sh_type;
10852
10853 uint8_t uj = use_json(argc, argv);
10854
10855 int idx = 0;
10856
10857 if (argv_find(argv, argc, "view", &idx)
10858 || argv_find(argv, argc, "vrf", &idx))
10859 vrf = argv[idx + 1]->arg;
10860
10861 idx++;
10862 if (argv_find(argv, argc, "A.B.C.D", &idx)
10863 || argv_find(argv, argc, "X:X::X:X", &idx)
10864 || argv_find(argv, argc, "WORD", &idx)) {
10865 sh_type = show_peer;
10866 sh_arg = argv[idx]->arg;
10867 } else
10868 sh_type = show_all;
10869
10870 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10871 }
10872
10873 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10874 paths' and `show ip mbgp paths'. Those functions results are the
10875 same.*/
10876 DEFUN (show_ip_bgp_paths,
10877 show_ip_bgp_paths_cmd,
10878 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10879 SHOW_STR
10880 IP_STR
10881 BGP_STR
10882 BGP_SAFI_HELP_STR
10883 "Path information\n")
10884 {
10885 vty_out(vty, "Address Refcnt Path\n");
10886 aspath_print_all_vty(vty);
10887 return CMD_SUCCESS;
10888 }
10889
10890 #include "hash.h"
10891
10892 static void community_show_all_iterator(struct hash_backet *backet,
10893 struct vty *vty)
10894 {
10895 struct community *com;
10896
10897 com = (struct community *)backet->data;
10898 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10899 community_str(com, false));
10900 }
10901
10902 /* Show BGP's community internal data. */
10903 DEFUN (show_ip_bgp_community_info,
10904 show_ip_bgp_community_info_cmd,
10905 "show [ip] bgp community-info",
10906 SHOW_STR
10907 IP_STR
10908 BGP_STR
10909 "List all bgp community information\n")
10910 {
10911 vty_out(vty, "Address Refcnt Community\n");
10912
10913 hash_iterate(community_hash(),
10914 (void (*)(struct hash_backet *,
10915 void *))community_show_all_iterator,
10916 vty);
10917
10918 return CMD_SUCCESS;
10919 }
10920
10921 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10922 struct vty *vty)
10923 {
10924 struct lcommunity *lcom;
10925
10926 lcom = (struct lcommunity *)backet->data;
10927 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10928 lcommunity_str(lcom, false));
10929 }
10930
10931 /* Show BGP's community internal data. */
10932 DEFUN (show_ip_bgp_lcommunity_info,
10933 show_ip_bgp_lcommunity_info_cmd,
10934 "show ip bgp large-community-info",
10935 SHOW_STR
10936 IP_STR
10937 BGP_STR
10938 "List all bgp large-community information\n")
10939 {
10940 vty_out(vty, "Address Refcnt Large-community\n");
10941
10942 hash_iterate(lcommunity_hash(),
10943 (void (*)(struct hash_backet *,
10944 void *))lcommunity_show_all_iterator,
10945 vty);
10946
10947 return CMD_SUCCESS;
10948 }
10949
10950
10951 DEFUN (show_ip_bgp_attr_info,
10952 show_ip_bgp_attr_info_cmd,
10953 "show [ip] bgp attribute-info",
10954 SHOW_STR
10955 IP_STR
10956 BGP_STR
10957 "List all bgp attribute information\n")
10958 {
10959 attr_show_all(vty);
10960 return CMD_SUCCESS;
10961 }
10962
10963 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10964 afi_t afi, safi_t safi)
10965 {
10966 struct bgp *bgp;
10967 struct listnode *node;
10968 char *vname;
10969 char buf1[INET6_ADDRSTRLEN];
10970 char *ecom_str;
10971 vpn_policy_direction_t dir;
10972
10973 if (name) {
10974 bgp = bgp_lookup_by_name(name);
10975 if (!bgp) {
10976 vty_out(vty, "%% No such BGP instance exist\n");
10977 return CMD_WARNING;
10978 }
10979 } else {
10980 bgp = bgp_get_default();
10981 if (!bgp) {
10982 vty_out(vty,
10983 "%% Default BGP instance does not exist\n");
10984 return CMD_WARNING;
10985 }
10986 }
10987
10988 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10989 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
10990 vty_out(vty,
10991 "This VRF is not importing %s routes from any other VRF\n",
10992 afi_safi_print(afi, safi));
10993 } else {
10994 vty_out(vty,
10995 "This VRF is importing %s routes from the following VRFs:\n",
10996 afi_safi_print(afi, safi));
10997 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
10998 vname)) {
10999 vty_out(vty, " %s\n", vname);
11000 }
11001 dir = BGP_VPN_POLICY_DIR_FROMVPN;
11002 ecom_str = ecommunity_ecom2str(
11003 bgp->vpn_policy[afi].rtlist[dir],
11004 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11005 vty_out(vty, "Import RT(s): %s\n", ecom_str);
11006 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11007 }
11008
11009 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11010 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
11011 vty_out(vty,
11012 "This VRF is not exporting %s routes to any other VRF\n",
11013 afi_safi_print(afi, safi));
11014 } else {
11015 vty_out(vty,
11016 "This VRF is exporting %s routes to the following VRFs:\n",
11017 afi_safi_print(afi, safi));
11018 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
11019 vname)) {
11020 vty_out(vty, " %s\n", vname);
11021 }
11022 vty_out(vty, "RD: %s\n",
11023 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
11024 buf1, RD_ADDRSTRLEN));
11025 dir = BGP_VPN_POLICY_DIR_TOVPN;
11026 ecom_str = ecommunity_ecom2str(
11027 bgp->vpn_policy[afi].rtlist[dir],
11028 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
11029 vty_out(vty, "Emport RT: %s\n", ecom_str);
11030 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
11031 }
11032
11033 return CMD_SUCCESS;
11034 }
11035
11036 /* "show [ip] bgp route-leak" command. */
11037 DEFUN (show_ip_bgp_route_leak,
11038 show_ip_bgp_route_leak_cmd,
11039 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
11040 SHOW_STR
11041 IP_STR
11042 BGP_STR
11043 BGP_INSTANCE_HELP_STR
11044 BGP_AFI_HELP_STR
11045 BGP_SAFI_HELP_STR
11046 "Route leaking information\n")
11047 {
11048 char *vrf = NULL;
11049 afi_t afi = AFI_MAX;
11050 safi_t safi = SAFI_MAX;
11051
11052 int idx = 0;
11053
11054 /* show [ip] bgp */
11055 if (argv_find(argv, argc, "ip", &idx)) {
11056 afi = AFI_IP;
11057 safi = SAFI_UNICAST;
11058 }
11059 /* [vrf VIEWVRFNAME] */
11060 if (argv_find(argv, argc, "view", &idx)) {
11061 vty_out(vty,
11062 "%% This command is not applicable to BGP views\n");
11063 return CMD_WARNING;
11064 }
11065
11066 if (argv_find(argv, argc, "vrf", &idx))
11067 vrf = argv[++idx]->arg;
11068 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11069 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11070 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11071 }
11072
11073 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11074 vty_out(vty,
11075 "%% This command is applicable only for unicast ipv4|ipv6\n");
11076 return CMD_WARNING;
11077 }
11078
11079 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11080 }
11081
11082 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11083 safi_t safi)
11084 {
11085 struct listnode *node, *nnode;
11086 struct bgp *bgp;
11087
11088 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11089 vty_out(vty, "\nInstance %s:\n",
11090 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11091 ? "Default"
11092 : bgp->name);
11093 update_group_show(bgp, afi, safi, vty, 0);
11094 }
11095 }
11096
11097 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11098 int safi, uint64_t subgrp_id)
11099 {
11100 struct bgp *bgp;
11101
11102 if (name) {
11103 if (strmatch(name, "all")) {
11104 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11105 return CMD_SUCCESS;
11106 } else {
11107 bgp = bgp_lookup_by_name(name);
11108 }
11109 } else {
11110 bgp = bgp_get_default();
11111 }
11112
11113 if (bgp)
11114 update_group_show(bgp, afi, safi, vty, subgrp_id);
11115 return CMD_SUCCESS;
11116 }
11117
11118 DEFUN (show_ip_bgp_updgrps,
11119 show_ip_bgp_updgrps_cmd,
11120 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11121 SHOW_STR
11122 IP_STR
11123 BGP_STR
11124 BGP_INSTANCE_HELP_STR
11125 BGP_AFI_HELP_STR
11126 BGP_SAFI_WITH_LABEL_HELP_STR
11127 "Detailed info about dynamic update groups\n"
11128 "Specific subgroup to display detailed info for\n")
11129 {
11130 char *vrf = NULL;
11131 afi_t afi = AFI_IP6;
11132 safi_t safi = SAFI_UNICAST;
11133 uint64_t subgrp_id = 0;
11134
11135 int idx = 0;
11136
11137 /* show [ip] bgp */
11138 if (argv_find(argv, argc, "ip", &idx))
11139 afi = AFI_IP;
11140 /* [<view|vrf> VIEWVRFNAME] */
11141 if (argv_find(argv, argc, "view", &idx)
11142 || argv_find(argv, argc, "vrf", &idx))
11143 vrf = argv[++idx]->arg;
11144 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11145 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11146 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11147 }
11148
11149 /* get subgroup id, if provided */
11150 idx = argc - 1;
11151 if (argv[idx]->type == VARIABLE_TKN)
11152 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11153
11154 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11155 }
11156
11157 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11158 show_bgp_instance_all_ipv6_updgrps_cmd,
11159 "show [ip] bgp <view|vrf> all update-groups",
11160 SHOW_STR
11161 IP_STR
11162 BGP_STR
11163 BGP_INSTANCE_ALL_HELP_STR
11164 "Detailed info about dynamic update groups\n")
11165 {
11166 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11167 return CMD_SUCCESS;
11168 }
11169
11170 DEFUN (show_bgp_updgrps_stats,
11171 show_bgp_updgrps_stats_cmd,
11172 "show [ip] bgp update-groups statistics",
11173 SHOW_STR
11174 IP_STR
11175 BGP_STR
11176 "Detailed info about dynamic update groups\n"
11177 "Statistics\n")
11178 {
11179 struct bgp *bgp;
11180
11181 bgp = bgp_get_default();
11182 if (bgp)
11183 update_group_show_stats(bgp, vty);
11184
11185 return CMD_SUCCESS;
11186 }
11187
11188 DEFUN (show_bgp_instance_updgrps_stats,
11189 show_bgp_instance_updgrps_stats_cmd,
11190 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11191 SHOW_STR
11192 IP_STR
11193 BGP_STR
11194 BGP_INSTANCE_HELP_STR
11195 "Detailed info about dynamic update groups\n"
11196 "Statistics\n")
11197 {
11198 int idx_word = 3;
11199 struct bgp *bgp;
11200
11201 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11202 if (bgp)
11203 update_group_show_stats(bgp, vty);
11204
11205 return CMD_SUCCESS;
11206 }
11207
11208 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11209 afi_t afi, safi_t safi,
11210 const char *what, uint64_t subgrp_id)
11211 {
11212 struct bgp *bgp;
11213
11214 if (name)
11215 bgp = bgp_lookup_by_name(name);
11216 else
11217 bgp = bgp_get_default();
11218
11219 if (bgp) {
11220 if (!strcmp(what, "advertise-queue"))
11221 update_group_show_adj_queue(bgp, afi, safi, vty,
11222 subgrp_id);
11223 else if (!strcmp(what, "advertised-routes"))
11224 update_group_show_advertised(bgp, afi, safi, vty,
11225 subgrp_id);
11226 else if (!strcmp(what, "packet-queue"))
11227 update_group_show_packet_queue(bgp, afi, safi, vty,
11228 subgrp_id);
11229 }
11230 }
11231
11232 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11233 show_ip_bgp_instance_updgrps_adj_s_cmd,
11234 "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",
11235 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11236 BGP_SAFI_HELP_STR
11237 "Detailed info about dynamic update groups\n"
11238 "Specific subgroup to display info for\n"
11239 "Advertisement queue\n"
11240 "Announced routes\n"
11241 "Packet queue\n")
11242 {
11243 uint64_t subgrp_id = 0;
11244 afi_t afiz;
11245 safi_t safiz;
11246 if (sgid)
11247 subgrp_id = strtoull(sgid, NULL, 10);
11248
11249 if (!ip && !afi)
11250 afiz = AFI_IP6;
11251 if (!ip && afi)
11252 afiz = bgp_vty_afi_from_str(afi);
11253 if (ip && !afi)
11254 afiz = AFI_IP;
11255 if (ip && afi) {
11256 afiz = bgp_vty_afi_from_str(afi);
11257 if (afiz != AFI_IP)
11258 vty_out(vty,
11259 "%% Cannot specify both 'ip' and 'ipv6'\n");
11260 return CMD_WARNING;
11261 }
11262
11263 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11264
11265 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11266 return CMD_SUCCESS;
11267 }
11268
11269 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11270 {
11271 struct listnode *node, *nnode;
11272 struct prefix *range;
11273 struct peer *conf;
11274 struct peer *peer;
11275 char buf[PREFIX2STR_BUFFER];
11276 afi_t afi;
11277 safi_t safi;
11278 const char *peer_status;
11279 const char *af_str;
11280 int lr_count;
11281 int dynamic;
11282 int af_cfgd;
11283
11284 conf = group->conf;
11285
11286 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11287 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11288 conf->as);
11289 } else if (conf->as_type == AS_INTERNAL) {
11290 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11291 group->bgp->as);
11292 } else {
11293 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11294 }
11295
11296 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11297 vty_out(vty, " Peer-group type is internal\n");
11298 else
11299 vty_out(vty, " Peer-group type is external\n");
11300
11301 /* Display AFs configured. */
11302 vty_out(vty, " Configured address-families:");
11303 FOREACH_AFI_SAFI (afi, safi) {
11304 if (conf->afc[afi][safi]) {
11305 af_cfgd = 1;
11306 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11307 }
11308 }
11309 if (!af_cfgd)
11310 vty_out(vty, " none\n");
11311 else
11312 vty_out(vty, "\n");
11313
11314 /* Display listen ranges (for dynamic neighbors), if any */
11315 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11316 if (afi == AFI_IP)
11317 af_str = "IPv4";
11318 else if (afi == AFI_IP6)
11319 af_str = "IPv6";
11320 else
11321 af_str = "???";
11322 lr_count = listcount(group->listen_range[afi]);
11323 if (lr_count) {
11324 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11325 af_str);
11326
11327
11328 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11329 nnode, range)) {
11330 prefix2str(range, buf, sizeof(buf));
11331 vty_out(vty, " %s\n", buf);
11332 }
11333 }
11334 }
11335
11336 /* Display group members and their status */
11337 if (listcount(group->peer)) {
11338 vty_out(vty, " Peer-group members:\n");
11339 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11340 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11341 peer_status = "Idle (Admin)";
11342 else if (CHECK_FLAG(peer->sflags,
11343 PEER_STATUS_PREFIX_OVERFLOW))
11344 peer_status = "Idle (PfxCt)";
11345 else
11346 peer_status = lookup_msg(bgp_status_msg,
11347 peer->status, NULL);
11348
11349 dynamic = peer_dynamic_neighbor(peer);
11350 vty_out(vty, " %s %s %s \n", peer->host,
11351 dynamic ? "(dynamic)" : "", peer_status);
11352 }
11353 }
11354
11355 return CMD_SUCCESS;
11356 }
11357
11358 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11359 const char *group_name)
11360 {
11361 struct bgp *bgp;
11362 struct listnode *node, *nnode;
11363 struct peer_group *group;
11364 bool found = false;
11365
11366 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11367
11368 if (!bgp) {
11369 vty_out(vty, "%% No such BGP instance exists\n");
11370 return CMD_WARNING;
11371 }
11372
11373 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11374 if (group_name) {
11375 if (strmatch(group->name, group_name)) {
11376 bgp_show_one_peer_group(vty, group);
11377 found = true;
11378 break;
11379 }
11380 } else {
11381 bgp_show_one_peer_group(vty, group);
11382 }
11383 }
11384
11385 if (group_name && !found)
11386 vty_out(vty, "%% No such peer-group\n");
11387
11388 return CMD_SUCCESS;
11389 }
11390
11391 DEFUN (show_ip_bgp_peer_groups,
11392 show_ip_bgp_peer_groups_cmd,
11393 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11394 SHOW_STR
11395 IP_STR
11396 BGP_STR
11397 BGP_INSTANCE_HELP_STR
11398 "Detailed information on BGP peer groups\n"
11399 "Peer group name\n")
11400 {
11401 char *vrf, *pg;
11402 vrf = pg = NULL;
11403 int idx = 0;
11404
11405 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11406 : NULL;
11407 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11408
11409 return bgp_show_peer_group_vty(vty, vrf, pg);
11410 }
11411
11412
11413 /* Redistribute VTY commands. */
11414
11415 DEFUN (bgp_redistribute_ipv4,
11416 bgp_redistribute_ipv4_cmd,
11417 "redistribute " FRR_IP_REDIST_STR_BGPD,
11418 "Redistribute information from another routing protocol\n"
11419 FRR_IP_REDIST_HELP_STR_BGPD)
11420 {
11421 VTY_DECLVAR_CONTEXT(bgp, bgp);
11422 int idx_protocol = 1;
11423 int type;
11424
11425 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11426 if (type < 0) {
11427 vty_out(vty, "%% Invalid route type\n");
11428 return CMD_WARNING_CONFIG_FAILED;
11429 }
11430
11431 bgp_redist_add(bgp, AFI_IP, type, 0);
11432 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11433 }
11434
11435 ALIAS_HIDDEN(
11436 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11437 "redistribute " FRR_IP_REDIST_STR_BGPD,
11438 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11439
11440 DEFUN (bgp_redistribute_ipv4_rmap,
11441 bgp_redistribute_ipv4_rmap_cmd,
11442 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11443 "Redistribute information from another routing protocol\n"
11444 FRR_IP_REDIST_HELP_STR_BGPD
11445 "Route map reference\n"
11446 "Pointer to route-map entries\n")
11447 {
11448 VTY_DECLVAR_CONTEXT(bgp, bgp);
11449 int idx_protocol = 1;
11450 int idx_word = 3;
11451 int type;
11452 struct bgp_redist *red;
11453
11454 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11455 if (type < 0) {
11456 vty_out(vty, "%% Invalid route type\n");
11457 return CMD_WARNING_CONFIG_FAILED;
11458 }
11459
11460 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11461 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11462 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11463 }
11464
11465 ALIAS_HIDDEN(
11466 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11467 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11468 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11469 "Route map reference\n"
11470 "Pointer to route-map entries\n")
11471
11472 DEFUN (bgp_redistribute_ipv4_metric,
11473 bgp_redistribute_ipv4_metric_cmd,
11474 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11475 "Redistribute information from another routing protocol\n"
11476 FRR_IP_REDIST_HELP_STR_BGPD
11477 "Metric for redistributed routes\n"
11478 "Default metric\n")
11479 {
11480 VTY_DECLVAR_CONTEXT(bgp, bgp);
11481 int idx_protocol = 1;
11482 int idx_number = 3;
11483 int type;
11484 uint32_t metric;
11485 struct bgp_redist *red;
11486
11487 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11488 if (type < 0) {
11489 vty_out(vty, "%% Invalid route type\n");
11490 return CMD_WARNING_CONFIG_FAILED;
11491 }
11492 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11493
11494 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11495 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11496 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11497 }
11498
11499 ALIAS_HIDDEN(
11500 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11501 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11502 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11503 "Metric for redistributed routes\n"
11504 "Default metric\n")
11505
11506 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11507 bgp_redistribute_ipv4_rmap_metric_cmd,
11508 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11509 "Redistribute information from another routing protocol\n"
11510 FRR_IP_REDIST_HELP_STR_BGPD
11511 "Route map reference\n"
11512 "Pointer to route-map entries\n"
11513 "Metric for redistributed routes\n"
11514 "Default metric\n")
11515 {
11516 VTY_DECLVAR_CONTEXT(bgp, bgp);
11517 int idx_protocol = 1;
11518 int idx_word = 3;
11519 int idx_number = 5;
11520 int type;
11521 uint32_t metric;
11522 struct bgp_redist *red;
11523
11524 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11525 if (type < 0) {
11526 vty_out(vty, "%% Invalid route type\n");
11527 return CMD_WARNING_CONFIG_FAILED;
11528 }
11529 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11530
11531 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11532 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11533 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11534 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11535 }
11536
11537 ALIAS_HIDDEN(
11538 bgp_redistribute_ipv4_rmap_metric,
11539 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11540 "redistribute " FRR_IP_REDIST_STR_BGPD
11541 " route-map WORD metric (0-4294967295)",
11542 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11543 "Route map reference\n"
11544 "Pointer to route-map entries\n"
11545 "Metric for redistributed routes\n"
11546 "Default metric\n")
11547
11548 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11549 bgp_redistribute_ipv4_metric_rmap_cmd,
11550 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11551 "Redistribute information from another routing protocol\n"
11552 FRR_IP_REDIST_HELP_STR_BGPD
11553 "Metric for redistributed routes\n"
11554 "Default metric\n"
11555 "Route map reference\n"
11556 "Pointer to route-map entries\n")
11557 {
11558 VTY_DECLVAR_CONTEXT(bgp, bgp);
11559 int idx_protocol = 1;
11560 int idx_number = 3;
11561 int idx_word = 5;
11562 int type;
11563 uint32_t metric;
11564 struct bgp_redist *red;
11565
11566 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11567 if (type < 0) {
11568 vty_out(vty, "%% Invalid route type\n");
11569 return CMD_WARNING_CONFIG_FAILED;
11570 }
11571 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11572
11573 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11574 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11575 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11576 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11577 }
11578
11579 ALIAS_HIDDEN(
11580 bgp_redistribute_ipv4_metric_rmap,
11581 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11582 "redistribute " FRR_IP_REDIST_STR_BGPD
11583 " metric (0-4294967295) route-map WORD",
11584 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11585 "Metric for redistributed routes\n"
11586 "Default metric\n"
11587 "Route map reference\n"
11588 "Pointer to route-map entries\n")
11589
11590 DEFUN (bgp_redistribute_ipv4_ospf,
11591 bgp_redistribute_ipv4_ospf_cmd,
11592 "redistribute <ospf|table> (1-65535)",
11593 "Redistribute information from another routing protocol\n"
11594 "Open Shortest Path First (OSPFv2)\n"
11595 "Non-main Kernel Routing Table\n"
11596 "Instance ID/Table ID\n")
11597 {
11598 VTY_DECLVAR_CONTEXT(bgp, bgp);
11599 int idx_ospf_table = 1;
11600 int idx_number = 2;
11601 unsigned short instance;
11602 unsigned short protocol;
11603
11604 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11605
11606 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11607 protocol = ZEBRA_ROUTE_OSPF;
11608 else
11609 protocol = ZEBRA_ROUTE_TABLE;
11610
11611 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11612 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11613 }
11614
11615 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11616 "redistribute <ospf|table> (1-65535)",
11617 "Redistribute information from another routing protocol\n"
11618 "Open Shortest Path First (OSPFv2)\n"
11619 "Non-main Kernel Routing Table\n"
11620 "Instance ID/Table ID\n")
11621
11622 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11623 bgp_redistribute_ipv4_ospf_rmap_cmd,
11624 "redistribute <ospf|table> (1-65535) route-map WORD",
11625 "Redistribute information from another routing protocol\n"
11626 "Open Shortest Path First (OSPFv2)\n"
11627 "Non-main Kernel Routing Table\n"
11628 "Instance ID/Table ID\n"
11629 "Route map reference\n"
11630 "Pointer to route-map entries\n")
11631 {
11632 VTY_DECLVAR_CONTEXT(bgp, bgp);
11633 int idx_ospf_table = 1;
11634 int idx_number = 2;
11635 int idx_word = 4;
11636 struct bgp_redist *red;
11637 unsigned short instance;
11638 int protocol;
11639
11640 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11641 protocol = ZEBRA_ROUTE_OSPF;
11642 else
11643 protocol = ZEBRA_ROUTE_TABLE;
11644
11645 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11646 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11647 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11648 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11649 }
11650
11651 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11652 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11653 "redistribute <ospf|table> (1-65535) route-map WORD",
11654 "Redistribute information from another routing protocol\n"
11655 "Open Shortest Path First (OSPFv2)\n"
11656 "Non-main Kernel Routing Table\n"
11657 "Instance ID/Table ID\n"
11658 "Route map reference\n"
11659 "Pointer to route-map entries\n")
11660
11661 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11662 bgp_redistribute_ipv4_ospf_metric_cmd,
11663 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11664 "Redistribute information from another routing protocol\n"
11665 "Open Shortest Path First (OSPFv2)\n"
11666 "Non-main Kernel Routing Table\n"
11667 "Instance ID/Table ID\n"
11668 "Metric for redistributed routes\n"
11669 "Default metric\n")
11670 {
11671 VTY_DECLVAR_CONTEXT(bgp, bgp);
11672 int idx_ospf_table = 1;
11673 int idx_number = 2;
11674 int idx_number_2 = 4;
11675 uint32_t metric;
11676 struct bgp_redist *red;
11677 unsigned short instance;
11678 int protocol;
11679
11680 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11681 protocol = ZEBRA_ROUTE_OSPF;
11682 else
11683 protocol = ZEBRA_ROUTE_TABLE;
11684
11685 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11686 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11687
11688 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11689 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11690 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11691 }
11692
11693 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11694 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11695 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11696 "Redistribute information from another routing protocol\n"
11697 "Open Shortest Path First (OSPFv2)\n"
11698 "Non-main Kernel Routing Table\n"
11699 "Instance ID/Table ID\n"
11700 "Metric for redistributed routes\n"
11701 "Default metric\n")
11702
11703 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11704 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11705 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11706 "Redistribute information from another routing protocol\n"
11707 "Open Shortest Path First (OSPFv2)\n"
11708 "Non-main Kernel Routing Table\n"
11709 "Instance ID/Table ID\n"
11710 "Route map reference\n"
11711 "Pointer to route-map entries\n"
11712 "Metric for redistributed routes\n"
11713 "Default metric\n")
11714 {
11715 VTY_DECLVAR_CONTEXT(bgp, bgp);
11716 int idx_ospf_table = 1;
11717 int idx_number = 2;
11718 int idx_word = 4;
11719 int idx_number_2 = 6;
11720 uint32_t metric;
11721 struct bgp_redist *red;
11722 unsigned short instance;
11723 int protocol;
11724
11725 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11726 protocol = ZEBRA_ROUTE_OSPF;
11727 else
11728 protocol = ZEBRA_ROUTE_TABLE;
11729
11730 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11731 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11732
11733 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11734 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11735 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11736 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11737 }
11738
11739 ALIAS_HIDDEN(
11740 bgp_redistribute_ipv4_ospf_rmap_metric,
11741 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11742 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11743 "Redistribute information from another routing protocol\n"
11744 "Open Shortest Path First (OSPFv2)\n"
11745 "Non-main Kernel Routing Table\n"
11746 "Instance ID/Table ID\n"
11747 "Route map reference\n"
11748 "Pointer to route-map entries\n"
11749 "Metric for redistributed routes\n"
11750 "Default metric\n")
11751
11752 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11753 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11754 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11755 "Redistribute information from another routing protocol\n"
11756 "Open Shortest Path First (OSPFv2)\n"
11757 "Non-main Kernel Routing Table\n"
11758 "Instance ID/Table ID\n"
11759 "Metric for redistributed routes\n"
11760 "Default metric\n"
11761 "Route map reference\n"
11762 "Pointer to route-map entries\n")
11763 {
11764 VTY_DECLVAR_CONTEXT(bgp, bgp);
11765 int idx_ospf_table = 1;
11766 int idx_number = 2;
11767 int idx_number_2 = 4;
11768 int idx_word = 6;
11769 uint32_t metric;
11770 struct bgp_redist *red;
11771 unsigned short instance;
11772 int protocol;
11773
11774 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11775 protocol = ZEBRA_ROUTE_OSPF;
11776 else
11777 protocol = ZEBRA_ROUTE_TABLE;
11778
11779 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11780 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11781
11782 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11783 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11784 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11785 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11786 }
11787
11788 ALIAS_HIDDEN(
11789 bgp_redistribute_ipv4_ospf_metric_rmap,
11790 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11791 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11792 "Redistribute information from another routing protocol\n"
11793 "Open Shortest Path First (OSPFv2)\n"
11794 "Non-main Kernel Routing Table\n"
11795 "Instance ID/Table ID\n"
11796 "Metric for redistributed routes\n"
11797 "Default metric\n"
11798 "Route map reference\n"
11799 "Pointer to route-map entries\n")
11800
11801 DEFUN (no_bgp_redistribute_ipv4_ospf,
11802 no_bgp_redistribute_ipv4_ospf_cmd,
11803 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11804 NO_STR
11805 "Redistribute information from another routing protocol\n"
11806 "Open Shortest Path First (OSPFv2)\n"
11807 "Non-main Kernel Routing Table\n"
11808 "Instance ID/Table ID\n"
11809 "Metric for redistributed routes\n"
11810 "Default metric\n"
11811 "Route map reference\n"
11812 "Pointer to route-map entries\n")
11813 {
11814 VTY_DECLVAR_CONTEXT(bgp, bgp);
11815 int idx_ospf_table = 2;
11816 int idx_number = 3;
11817 unsigned short instance;
11818 int protocol;
11819
11820 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11821 protocol = ZEBRA_ROUTE_OSPF;
11822 else
11823 protocol = ZEBRA_ROUTE_TABLE;
11824
11825 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11826 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11827 }
11828
11829 ALIAS_HIDDEN(
11830 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11831 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11832 NO_STR
11833 "Redistribute information from another routing protocol\n"
11834 "Open Shortest Path First (OSPFv2)\n"
11835 "Non-main Kernel Routing Table\n"
11836 "Instance ID/Table ID\n"
11837 "Metric for redistributed routes\n"
11838 "Default metric\n"
11839 "Route map reference\n"
11840 "Pointer to route-map entries\n")
11841
11842 DEFUN (no_bgp_redistribute_ipv4,
11843 no_bgp_redistribute_ipv4_cmd,
11844 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11845 NO_STR
11846 "Redistribute information from another routing protocol\n"
11847 FRR_IP_REDIST_HELP_STR_BGPD
11848 "Metric for redistributed routes\n"
11849 "Default metric\n"
11850 "Route map reference\n"
11851 "Pointer to route-map entries\n")
11852 {
11853 VTY_DECLVAR_CONTEXT(bgp, bgp);
11854 int idx_protocol = 2;
11855 int type;
11856
11857 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11858 if (type < 0) {
11859 vty_out(vty, "%% Invalid route type\n");
11860 return CMD_WARNING_CONFIG_FAILED;
11861 }
11862 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11863 }
11864
11865 ALIAS_HIDDEN(
11866 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11867 "no redistribute " FRR_IP_REDIST_STR_BGPD
11868 " [metric (0-4294967295)] [route-map WORD]",
11869 NO_STR
11870 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11871 "Metric for redistributed routes\n"
11872 "Default metric\n"
11873 "Route map reference\n"
11874 "Pointer to route-map entries\n")
11875
11876 DEFUN (bgp_redistribute_ipv6,
11877 bgp_redistribute_ipv6_cmd,
11878 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11879 "Redistribute information from another routing protocol\n"
11880 FRR_IP6_REDIST_HELP_STR_BGPD)
11881 {
11882 VTY_DECLVAR_CONTEXT(bgp, bgp);
11883 int idx_protocol = 1;
11884 int type;
11885
11886 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11887 if (type < 0) {
11888 vty_out(vty, "%% Invalid route type\n");
11889 return CMD_WARNING_CONFIG_FAILED;
11890 }
11891
11892 bgp_redist_add(bgp, AFI_IP6, type, 0);
11893 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11894 }
11895
11896 DEFUN (bgp_redistribute_ipv6_rmap,
11897 bgp_redistribute_ipv6_rmap_cmd,
11898 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11899 "Redistribute information from another routing protocol\n"
11900 FRR_IP6_REDIST_HELP_STR_BGPD
11901 "Route map reference\n"
11902 "Pointer to route-map entries\n")
11903 {
11904 VTY_DECLVAR_CONTEXT(bgp, bgp);
11905 int idx_protocol = 1;
11906 int idx_word = 3;
11907 int type;
11908 struct bgp_redist *red;
11909
11910 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11911 if (type < 0) {
11912 vty_out(vty, "%% Invalid route type\n");
11913 return CMD_WARNING_CONFIG_FAILED;
11914 }
11915
11916 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11917 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11918 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11919 }
11920
11921 DEFUN (bgp_redistribute_ipv6_metric,
11922 bgp_redistribute_ipv6_metric_cmd,
11923 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11924 "Redistribute information from another routing protocol\n"
11925 FRR_IP6_REDIST_HELP_STR_BGPD
11926 "Metric for redistributed routes\n"
11927 "Default metric\n")
11928 {
11929 VTY_DECLVAR_CONTEXT(bgp, bgp);
11930 int idx_protocol = 1;
11931 int idx_number = 3;
11932 int type;
11933 uint32_t metric;
11934 struct bgp_redist *red;
11935
11936 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11937 if (type < 0) {
11938 vty_out(vty, "%% Invalid route type\n");
11939 return CMD_WARNING_CONFIG_FAILED;
11940 }
11941 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11942
11943 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11944 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11945 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11946 }
11947
11948 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11949 bgp_redistribute_ipv6_rmap_metric_cmd,
11950 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11951 "Redistribute information from another routing protocol\n"
11952 FRR_IP6_REDIST_HELP_STR_BGPD
11953 "Route map reference\n"
11954 "Pointer to route-map entries\n"
11955 "Metric for redistributed routes\n"
11956 "Default metric\n")
11957 {
11958 VTY_DECLVAR_CONTEXT(bgp, bgp);
11959 int idx_protocol = 1;
11960 int idx_word = 3;
11961 int idx_number = 5;
11962 int type;
11963 uint32_t metric;
11964 struct bgp_redist *red;
11965
11966 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11967 if (type < 0) {
11968 vty_out(vty, "%% Invalid route type\n");
11969 return CMD_WARNING_CONFIG_FAILED;
11970 }
11971 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11972
11973 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11974 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11975 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11976 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11977 }
11978
11979 DEFUN (bgp_redistribute_ipv6_metric_rmap,
11980 bgp_redistribute_ipv6_metric_rmap_cmd,
11981 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11982 "Redistribute information from another routing protocol\n"
11983 FRR_IP6_REDIST_HELP_STR_BGPD
11984 "Metric for redistributed routes\n"
11985 "Default metric\n"
11986 "Route map reference\n"
11987 "Pointer to route-map entries\n")
11988 {
11989 VTY_DECLVAR_CONTEXT(bgp, bgp);
11990 int idx_protocol = 1;
11991 int idx_number = 3;
11992 int idx_word = 5;
11993 int type;
11994 uint32_t metric;
11995 struct bgp_redist *red;
11996
11997 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11998 if (type < 0) {
11999 vty_out(vty, "%% Invalid route type\n");
12000 return CMD_WARNING_CONFIG_FAILED;
12001 }
12002 metric = strtoul(argv[idx_number]->arg, NULL, 10);
12003
12004 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
12005 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
12006 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
12007 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
12008 }
12009
12010 DEFUN (no_bgp_redistribute_ipv6,
12011 no_bgp_redistribute_ipv6_cmd,
12012 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
12013 NO_STR
12014 "Redistribute information from another routing protocol\n"
12015 FRR_IP6_REDIST_HELP_STR_BGPD
12016 "Metric for redistributed routes\n"
12017 "Default metric\n"
12018 "Route map reference\n"
12019 "Pointer to route-map entries\n")
12020 {
12021 VTY_DECLVAR_CONTEXT(bgp, bgp);
12022 int idx_protocol = 2;
12023 int type;
12024
12025 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
12026 if (type < 0) {
12027 vty_out(vty, "%% Invalid route type\n");
12028 return CMD_WARNING_CONFIG_FAILED;
12029 }
12030
12031 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
12032 }
12033
12034 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
12035 safi_t safi)
12036 {
12037 int i;
12038
12039 /* Unicast redistribution only. */
12040 if (safi != SAFI_UNICAST)
12041 return;
12042
12043 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
12044 /* Redistribute BGP does not make sense. */
12045 if (i != ZEBRA_ROUTE_BGP) {
12046 struct list *red_list;
12047 struct listnode *node;
12048 struct bgp_redist *red;
12049
12050 red_list = bgp->redist[afi][i];
12051 if (!red_list)
12052 continue;
12053
12054 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12055 /* "redistribute" configuration. */
12056 vty_out(vty, " redistribute %s",
12057 zebra_route_string(i));
12058 if (red->instance)
12059 vty_out(vty, " %d", red->instance);
12060 if (red->redist_metric_flag)
12061 vty_out(vty, " metric %u",
12062 red->redist_metric);
12063 if (red->rmap.name)
12064 vty_out(vty, " route-map %s",
12065 red->rmap.name);
12066 vty_out(vty, "\n");
12067 }
12068 }
12069 }
12070 }
12071
12072 /* This is part of the address-family block (unicast only) */
12073 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12074 afi_t afi)
12075 {
12076 int indent = 2;
12077
12078 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12079 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12080 bgp->vpn_policy[afi]
12081 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12082
12083 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12084 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12085 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12086 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12087 return;
12088
12089 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12090 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12091
12092 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12093
12094 } else {
12095 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12096 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12097 bgp->vpn_policy[afi].tovpn_label);
12098 }
12099 }
12100 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12101 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12102 char buf[RD_ADDRSTRLEN];
12103 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12104 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12105 sizeof(buf)));
12106 }
12107 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12108 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12109
12110 char buf[PREFIX_STRLEN];
12111 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12112 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12113 sizeof(buf))) {
12114
12115 vty_out(vty, "%*snexthop vpn export %s\n",
12116 indent, "", buf);
12117 }
12118 }
12119 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12120 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12121 && ecommunity_cmp(
12122 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12123 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12124
12125 char *b = ecommunity_ecom2str(
12126 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12127 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12128 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12129 XFREE(MTYPE_ECOMMUNITY_STR, b);
12130 } else {
12131 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12132 char *b = ecommunity_ecom2str(
12133 bgp->vpn_policy[afi]
12134 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12135 ECOMMUNITY_FORMAT_ROUTE_MAP,
12136 ECOMMUNITY_ROUTE_TARGET);
12137 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12138 XFREE(MTYPE_ECOMMUNITY_STR, b);
12139 }
12140 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12141 char *b = ecommunity_ecom2str(
12142 bgp->vpn_policy[afi]
12143 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12144 ECOMMUNITY_FORMAT_ROUTE_MAP,
12145 ECOMMUNITY_ROUTE_TARGET);
12146 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12147 XFREE(MTYPE_ECOMMUNITY_STR, b);
12148 }
12149 }
12150
12151 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12152 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12153 bgp->vpn_policy[afi]
12154 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12155
12156 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12157 char *b = ecommunity_ecom2str(
12158 bgp->vpn_policy[afi]
12159 .import_redirect_rtlist,
12160 ECOMMUNITY_FORMAT_ROUTE_MAP,
12161 ECOMMUNITY_ROUTE_TARGET);
12162
12163 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12164 XFREE(MTYPE_ECOMMUNITY_STR, b);
12165 }
12166 }
12167
12168
12169 /* BGP node structure. */
12170 static struct cmd_node bgp_node = {
12171 BGP_NODE, "%s(config-router)# ", 1,
12172 };
12173
12174 static struct cmd_node bgp_ipv4_unicast_node = {
12175 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12176 };
12177
12178 static struct cmd_node bgp_ipv4_multicast_node = {
12179 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12180 };
12181
12182 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12183 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12184 };
12185
12186 static struct cmd_node bgp_ipv6_unicast_node = {
12187 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12188 };
12189
12190 static struct cmd_node bgp_ipv6_multicast_node = {
12191 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12192 };
12193
12194 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12195 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12196 };
12197
12198 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12199 "%s(config-router-af)# ", 1};
12200
12201 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12202 "%s(config-router-af-vpnv6)# ", 1};
12203
12204 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12205 "%s(config-router-evpn)# ", 1};
12206
12207 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12208 "%s(config-router-af-vni)# ", 1};
12209
12210 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12211 "%s(config-router-af)# ", 1};
12212
12213 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12214 "%s(config-router-af-vpnv6)# ", 1};
12215
12216 static void community_list_vty(void);
12217
12218 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12219 {
12220 struct bgp *bgp;
12221 struct peer *peer;
12222 struct listnode *lnbgp, *lnpeer;
12223
12224 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12225 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12226 /* only provide suggestions on the appropriate input
12227 * token type,
12228 * they'll otherwise show up multiple times */
12229 enum cmd_token_type match_type;
12230 char *name = peer->host;
12231
12232 if (peer->conf_if) {
12233 match_type = VARIABLE_TKN;
12234 name = peer->conf_if;
12235 } else if (strchr(peer->host, ':'))
12236 match_type = IPV6_TKN;
12237 else
12238 match_type = IPV4_TKN;
12239
12240 if (token->type != match_type)
12241 continue;
12242
12243 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12244 }
12245 }
12246 }
12247
12248 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12249 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12250 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12251 {.varname = "peer", .completions = bgp_ac_neighbor},
12252 {.completions = NULL}};
12253
12254 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12255 {
12256 struct bgp *bgp;
12257 struct peer_group *group;
12258 struct listnode *lnbgp, *lnpeer;
12259
12260 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12261 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12262 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12263 group->name));
12264 }
12265 }
12266
12267 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12268 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12269 {.completions = NULL} };
12270
12271 void bgp_vty_init(void)
12272 {
12273 cmd_variable_handler_register(bgp_var_neighbor);
12274 cmd_variable_handler_register(bgp_var_peergroup);
12275
12276 /* Install bgp top node. */
12277 install_node(&bgp_node, bgp_config_write);
12278 install_node(&bgp_ipv4_unicast_node, NULL);
12279 install_node(&bgp_ipv4_multicast_node, NULL);
12280 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12281 install_node(&bgp_ipv6_unicast_node, NULL);
12282 install_node(&bgp_ipv6_multicast_node, NULL);
12283 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12284 install_node(&bgp_vpnv4_node, NULL);
12285 install_node(&bgp_vpnv6_node, NULL);
12286 install_node(&bgp_evpn_node, NULL);
12287 install_node(&bgp_evpn_vni_node, NULL);
12288 install_node(&bgp_flowspecv4_node, NULL);
12289 install_node(&bgp_flowspecv6_node, NULL);
12290
12291 /* Install default VTY commands to new nodes. */
12292 install_default(BGP_NODE);
12293 install_default(BGP_IPV4_NODE);
12294 install_default(BGP_IPV4M_NODE);
12295 install_default(BGP_IPV4L_NODE);
12296 install_default(BGP_IPV6_NODE);
12297 install_default(BGP_IPV6M_NODE);
12298 install_default(BGP_IPV6L_NODE);
12299 install_default(BGP_VPNV4_NODE);
12300 install_default(BGP_VPNV6_NODE);
12301 install_default(BGP_FLOWSPECV4_NODE);
12302 install_default(BGP_FLOWSPECV6_NODE);
12303 install_default(BGP_EVPN_NODE);
12304 install_default(BGP_EVPN_VNI_NODE);
12305
12306 /* "bgp multiple-instance" commands. */
12307 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12308 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12309
12310 /* "bgp config-type" commands. */
12311 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12312 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12313
12314 /* bgp route-map delay-timer commands. */
12315 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12316 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12317
12318 /* Dummy commands (Currently not supported) */
12319 install_element(BGP_NODE, &no_synchronization_cmd);
12320 install_element(BGP_NODE, &no_auto_summary_cmd);
12321
12322 /* "router bgp" commands. */
12323 install_element(CONFIG_NODE, &router_bgp_cmd);
12324
12325 /* "no router bgp" commands. */
12326 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12327
12328 /* "bgp router-id" commands. */
12329 install_element(BGP_NODE, &bgp_router_id_cmd);
12330 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12331
12332 /* "bgp cluster-id" commands. */
12333 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12334 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12335
12336 /* "bgp confederation" commands. */
12337 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12338 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12339
12340 /* "bgp confederation peers" commands. */
12341 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12342 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12343
12344 /* bgp max-med command */
12345 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12346 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12347 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12348 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12349 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12350
12351 /* bgp disable-ebgp-connected-nh-check */
12352 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12353 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12354
12355 /* bgp update-delay command */
12356 install_element(BGP_NODE, &bgp_update_delay_cmd);
12357 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12358 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12359
12360 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12361 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12362 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12363 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12364
12365 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12366 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12367
12368 /* "maximum-paths" commands. */
12369 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12370 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12371 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12372 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12373 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12374 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12375 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12376 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12377 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12378 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12379 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12380 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12381 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12382 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12383 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12384
12385 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12386 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12387 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12388 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12389 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12390
12391 /* "timers bgp" commands. */
12392 install_element(BGP_NODE, &bgp_timers_cmd);
12393 install_element(BGP_NODE, &no_bgp_timers_cmd);
12394
12395 /* route-map delay-timer commands - per instance for backwards compat.
12396 */
12397 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12398 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12399
12400 /* "bgp client-to-client reflection" commands */
12401 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12402 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12403
12404 /* "bgp always-compare-med" commands */
12405 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12406 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12407
12408 /* "bgp deterministic-med" commands */
12409 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12410 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12411
12412 /* "bgp graceful-restart" commands */
12413 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12414 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12415 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12416 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12417 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12418 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12419
12420 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12421 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12422
12423 /* "bgp graceful-shutdown" commands */
12424 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12425 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12426
12427 /* "bgp fast-external-failover" commands */
12428 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12429 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12430
12431 /* "bgp enforce-first-as" commands */
12432 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12433 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12434
12435 /* "bgp bestpath compare-routerid" commands */
12436 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12437 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12438
12439 /* "bgp bestpath as-path ignore" commands */
12440 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12441 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12442
12443 /* "bgp bestpath as-path confed" commands */
12444 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12445 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12446
12447 /* "bgp bestpath as-path multipath-relax" commands */
12448 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12449 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12450
12451 /* "bgp log-neighbor-changes" commands */
12452 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12453 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12454
12455 /* "bgp bestpath med" commands */
12456 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12457 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12458
12459 /* "no bgp default ipv4-unicast" commands. */
12460 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12461 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12462
12463 /* "bgp network import-check" commands. */
12464 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12465 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12466 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12467
12468 /* "bgp default local-preference" commands. */
12469 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12470 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12471
12472 /* bgp default show-hostname */
12473 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12474 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12475
12476 /* "bgp default subgroup-pkt-queue-max" commands. */
12477 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12478 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12479
12480 /* bgp ibgp-allow-policy-mods command */
12481 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12482 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12483
12484 /* "bgp listen limit" commands. */
12485 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12486 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12487
12488 /* "bgp listen range" commands. */
12489 install_element(BGP_NODE, &bgp_listen_range_cmd);
12490 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12491
12492 /* "bgp default shutdown" command */
12493 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12494
12495 /* "neighbor remote-as" commands. */
12496 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12497 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12498 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12499 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12500 install_element(BGP_NODE,
12501 &neighbor_interface_v6only_config_remote_as_cmd);
12502 install_element(BGP_NODE, &no_neighbor_cmd);
12503 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12504
12505 /* "neighbor peer-group" commands. */
12506 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12507 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12508 install_element(BGP_NODE,
12509 &no_neighbor_interface_peer_group_remote_as_cmd);
12510
12511 /* "neighbor local-as" commands. */
12512 install_element(BGP_NODE, &neighbor_local_as_cmd);
12513 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12514 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12515 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12516
12517 /* "neighbor solo" commands. */
12518 install_element(BGP_NODE, &neighbor_solo_cmd);
12519 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12520
12521 /* "neighbor password" commands. */
12522 install_element(BGP_NODE, &neighbor_password_cmd);
12523 install_element(BGP_NODE, &no_neighbor_password_cmd);
12524
12525 /* "neighbor activate" commands. */
12526 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12527 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12528 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12529 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12530 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12531 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12532 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12533 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12534 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12535 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12536 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12537 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12538
12539 /* "no neighbor activate" commands. */
12540 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12541 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12542 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12543 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12544 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12545 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12546 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12547 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12548 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12549 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12550 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12551 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12552
12553 /* "neighbor peer-group" set commands. */
12554 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12555 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12556 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12557 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12558 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12559 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12560 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12561 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12562 install_element(BGP_FLOWSPECV4_NODE,
12563 &neighbor_set_peer_group_hidden_cmd);
12564 install_element(BGP_FLOWSPECV6_NODE,
12565 &neighbor_set_peer_group_hidden_cmd);
12566
12567 /* "no neighbor peer-group unset" commands. */
12568 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12569 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12570 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12571 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12572 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12573 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12574 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12575 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12576 install_element(BGP_FLOWSPECV4_NODE,
12577 &no_neighbor_set_peer_group_hidden_cmd);
12578 install_element(BGP_FLOWSPECV6_NODE,
12579 &no_neighbor_set_peer_group_hidden_cmd);
12580
12581 /* "neighbor softreconfiguration inbound" commands.*/
12582 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12583 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12584 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12585 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12586 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12587 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12588 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12589 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12590 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12591 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12592 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12593 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12594 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12595 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12596 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12597 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12598 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12599 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12600 install_element(BGP_FLOWSPECV4_NODE,
12601 &neighbor_soft_reconfiguration_cmd);
12602 install_element(BGP_FLOWSPECV4_NODE,
12603 &no_neighbor_soft_reconfiguration_cmd);
12604 install_element(BGP_FLOWSPECV6_NODE,
12605 &neighbor_soft_reconfiguration_cmd);
12606 install_element(BGP_FLOWSPECV6_NODE,
12607 &no_neighbor_soft_reconfiguration_cmd);
12608
12609 /* "neighbor attribute-unchanged" commands. */
12610 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12611 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12612 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12613 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12614 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12615 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12616 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12617 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12618 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12619 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12620 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12621 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12622 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12623 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12624 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12625 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12626 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12627 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12628
12629 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12630 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12631
12632 /* "nexthop-local unchanged" commands */
12633 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12634 install_element(BGP_IPV6_NODE,
12635 &no_neighbor_nexthop_local_unchanged_cmd);
12636
12637 /* "neighbor next-hop-self" commands. */
12638 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12639 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12640 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12641 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12642 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12643 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12644 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12645 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12646 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12647 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12648 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12649 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12650 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12651 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12652 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12653 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12654 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12655 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12656 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12657 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12658
12659 /* "neighbor next-hop-self force" commands. */
12660 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12661 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12662 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12663 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12664 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12665 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12666 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12667 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12668 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12669 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12670 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12671 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12672 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12673 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12674 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12675 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12676 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12677 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12678
12679 /* "neighbor as-override" commands. */
12680 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12681 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12682 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12683 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12684 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12685 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12686 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12687 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12688 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12689 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12690 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12691 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12692 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12693 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12694 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12695 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12696 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12697 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12698
12699 /* "neighbor remove-private-AS" commands. */
12700 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12701 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12702 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12703 install_element(BGP_NODE,
12704 &no_neighbor_remove_private_as_all_hidden_cmd);
12705 install_element(BGP_NODE,
12706 &neighbor_remove_private_as_replace_as_hidden_cmd);
12707 install_element(BGP_NODE,
12708 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12709 install_element(BGP_NODE,
12710 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12711 install_element(
12712 BGP_NODE,
12713 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12714 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12715 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12716 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12717 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12718 install_element(BGP_IPV4_NODE,
12719 &neighbor_remove_private_as_replace_as_cmd);
12720 install_element(BGP_IPV4_NODE,
12721 &no_neighbor_remove_private_as_replace_as_cmd);
12722 install_element(BGP_IPV4_NODE,
12723 &neighbor_remove_private_as_all_replace_as_cmd);
12724 install_element(BGP_IPV4_NODE,
12725 &no_neighbor_remove_private_as_all_replace_as_cmd);
12726 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12727 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12728 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12729 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12730 install_element(BGP_IPV4M_NODE,
12731 &neighbor_remove_private_as_replace_as_cmd);
12732 install_element(BGP_IPV4M_NODE,
12733 &no_neighbor_remove_private_as_replace_as_cmd);
12734 install_element(BGP_IPV4M_NODE,
12735 &neighbor_remove_private_as_all_replace_as_cmd);
12736 install_element(BGP_IPV4M_NODE,
12737 &no_neighbor_remove_private_as_all_replace_as_cmd);
12738 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12739 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12740 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12741 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12742 install_element(BGP_IPV4L_NODE,
12743 &neighbor_remove_private_as_replace_as_cmd);
12744 install_element(BGP_IPV4L_NODE,
12745 &no_neighbor_remove_private_as_replace_as_cmd);
12746 install_element(BGP_IPV4L_NODE,
12747 &neighbor_remove_private_as_all_replace_as_cmd);
12748 install_element(BGP_IPV4L_NODE,
12749 &no_neighbor_remove_private_as_all_replace_as_cmd);
12750 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12751 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12752 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12753 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12754 install_element(BGP_IPV6_NODE,
12755 &neighbor_remove_private_as_replace_as_cmd);
12756 install_element(BGP_IPV6_NODE,
12757 &no_neighbor_remove_private_as_replace_as_cmd);
12758 install_element(BGP_IPV6_NODE,
12759 &neighbor_remove_private_as_all_replace_as_cmd);
12760 install_element(BGP_IPV6_NODE,
12761 &no_neighbor_remove_private_as_all_replace_as_cmd);
12762 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12763 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12764 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12765 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12766 install_element(BGP_IPV6M_NODE,
12767 &neighbor_remove_private_as_replace_as_cmd);
12768 install_element(BGP_IPV6M_NODE,
12769 &no_neighbor_remove_private_as_replace_as_cmd);
12770 install_element(BGP_IPV6M_NODE,
12771 &neighbor_remove_private_as_all_replace_as_cmd);
12772 install_element(BGP_IPV6M_NODE,
12773 &no_neighbor_remove_private_as_all_replace_as_cmd);
12774 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12775 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12776 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12777 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12778 install_element(BGP_IPV6L_NODE,
12779 &neighbor_remove_private_as_replace_as_cmd);
12780 install_element(BGP_IPV6L_NODE,
12781 &no_neighbor_remove_private_as_replace_as_cmd);
12782 install_element(BGP_IPV6L_NODE,
12783 &neighbor_remove_private_as_all_replace_as_cmd);
12784 install_element(BGP_IPV6L_NODE,
12785 &no_neighbor_remove_private_as_all_replace_as_cmd);
12786 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12787 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12788 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12789 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12790 install_element(BGP_VPNV4_NODE,
12791 &neighbor_remove_private_as_replace_as_cmd);
12792 install_element(BGP_VPNV4_NODE,
12793 &no_neighbor_remove_private_as_replace_as_cmd);
12794 install_element(BGP_VPNV4_NODE,
12795 &neighbor_remove_private_as_all_replace_as_cmd);
12796 install_element(BGP_VPNV4_NODE,
12797 &no_neighbor_remove_private_as_all_replace_as_cmd);
12798 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12799 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12800 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12801 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12802 install_element(BGP_VPNV6_NODE,
12803 &neighbor_remove_private_as_replace_as_cmd);
12804 install_element(BGP_VPNV6_NODE,
12805 &no_neighbor_remove_private_as_replace_as_cmd);
12806 install_element(BGP_VPNV6_NODE,
12807 &neighbor_remove_private_as_all_replace_as_cmd);
12808 install_element(BGP_VPNV6_NODE,
12809 &no_neighbor_remove_private_as_all_replace_as_cmd);
12810
12811 /* "neighbor send-community" commands.*/
12812 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12813 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12814 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12815 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12816 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12817 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12818 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12819 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12820 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12821 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12822 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12823 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12824 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12825 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12826 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12827 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12828 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12829 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12830 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12831 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12832 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12833 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12834 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12835 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12836 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12837 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12838 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12839 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12840 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12841 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12842 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12843 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12844 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12845 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12846 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12847 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12848
12849 /* "neighbor route-reflector" commands.*/
12850 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12851 install_element(BGP_NODE,
12852 &no_neighbor_route_reflector_client_hidden_cmd);
12853 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12854 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12855 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12856 install_element(BGP_IPV4M_NODE,
12857 &no_neighbor_route_reflector_client_cmd);
12858 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12859 install_element(BGP_IPV4L_NODE,
12860 &no_neighbor_route_reflector_client_cmd);
12861 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12862 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12863 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12864 install_element(BGP_IPV6M_NODE,
12865 &no_neighbor_route_reflector_client_cmd);
12866 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12867 install_element(BGP_IPV6L_NODE,
12868 &no_neighbor_route_reflector_client_cmd);
12869 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12870 install_element(BGP_VPNV4_NODE,
12871 &no_neighbor_route_reflector_client_cmd);
12872 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12873 install_element(BGP_VPNV6_NODE,
12874 &no_neighbor_route_reflector_client_cmd);
12875 install_element(BGP_FLOWSPECV4_NODE,
12876 &neighbor_route_reflector_client_cmd);
12877 install_element(BGP_FLOWSPECV4_NODE,
12878 &no_neighbor_route_reflector_client_cmd);
12879 install_element(BGP_FLOWSPECV6_NODE,
12880 &neighbor_route_reflector_client_cmd);
12881 install_element(BGP_FLOWSPECV6_NODE,
12882 &no_neighbor_route_reflector_client_cmd);
12883 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12884 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12885
12886 /* "neighbor route-server" commands.*/
12887 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12888 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12889 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12890 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12891 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12892 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12893 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12894 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12895 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12896 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12897 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12898 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12899 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12900 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12901 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12902 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12903 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12904 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12905 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12906 install_element(BGP_FLOWSPECV4_NODE,
12907 &no_neighbor_route_server_client_cmd);
12908 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12909 install_element(BGP_FLOWSPECV6_NODE,
12910 &no_neighbor_route_server_client_cmd);
12911
12912 /* "neighbor addpath-tx-all-paths" commands.*/
12913 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12914 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12915 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12916 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12917 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12918 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12919 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12920 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12921 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12922 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12923 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12924 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12925 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12926 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12927 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12928 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12929 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12930 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12931
12932 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12933 install_element(BGP_NODE,
12934 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12935 install_element(BGP_NODE,
12936 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12937 install_element(BGP_IPV4_NODE,
12938 &neighbor_addpath_tx_bestpath_per_as_cmd);
12939 install_element(BGP_IPV4_NODE,
12940 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12941 install_element(BGP_IPV4M_NODE,
12942 &neighbor_addpath_tx_bestpath_per_as_cmd);
12943 install_element(BGP_IPV4M_NODE,
12944 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12945 install_element(BGP_IPV4L_NODE,
12946 &neighbor_addpath_tx_bestpath_per_as_cmd);
12947 install_element(BGP_IPV4L_NODE,
12948 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12949 install_element(BGP_IPV6_NODE,
12950 &neighbor_addpath_tx_bestpath_per_as_cmd);
12951 install_element(BGP_IPV6_NODE,
12952 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12953 install_element(BGP_IPV6M_NODE,
12954 &neighbor_addpath_tx_bestpath_per_as_cmd);
12955 install_element(BGP_IPV6M_NODE,
12956 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12957 install_element(BGP_IPV6L_NODE,
12958 &neighbor_addpath_tx_bestpath_per_as_cmd);
12959 install_element(BGP_IPV6L_NODE,
12960 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12961 install_element(BGP_VPNV4_NODE,
12962 &neighbor_addpath_tx_bestpath_per_as_cmd);
12963 install_element(BGP_VPNV4_NODE,
12964 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12965 install_element(BGP_VPNV6_NODE,
12966 &neighbor_addpath_tx_bestpath_per_as_cmd);
12967 install_element(BGP_VPNV6_NODE,
12968 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12969
12970 /* "neighbor passive" commands. */
12971 install_element(BGP_NODE, &neighbor_passive_cmd);
12972 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12973
12974
12975 /* "neighbor shutdown" commands. */
12976 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12977 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12978 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12979 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12980
12981 /* "neighbor capability extended-nexthop" commands.*/
12982 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12983 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12984
12985 /* "neighbor capability orf prefix-list" commands.*/
12986 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12987 install_element(BGP_NODE,
12988 &no_neighbor_capability_orf_prefix_hidden_cmd);
12989 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12990 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12991 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12992 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12993 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12994 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12995 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12996 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12997 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12998 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12999 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
13000 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
13001
13002 /* "neighbor capability dynamic" commands.*/
13003 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
13004 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
13005
13006 /* "neighbor dont-capability-negotiate" commands. */
13007 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
13008 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
13009
13010 /* "neighbor ebgp-multihop" commands. */
13011 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
13012 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
13013 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
13014
13015 /* "neighbor disable-connected-check" commands. */
13016 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
13017 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
13018
13019 /* "neighbor enforce-first-as" commands. */
13020 install_element(BGP_NODE, &neighbor_enforce_first_as_cmd);
13021 install_element(BGP_NODE, &no_neighbor_enforce_first_as_cmd);
13022
13023 /* "neighbor description" commands. */
13024 install_element(BGP_NODE, &neighbor_description_cmd);
13025 install_element(BGP_NODE, &no_neighbor_description_cmd);
13026
13027 /* "neighbor update-source" commands. "*/
13028 install_element(BGP_NODE, &neighbor_update_source_cmd);
13029 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
13030
13031 /* "neighbor default-originate" commands. */
13032 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
13033 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
13034 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
13035 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
13036 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
13037 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
13038 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
13039 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
13040 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
13041 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
13042 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
13043 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
13044 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
13045 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
13046 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
13047 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
13048 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
13049 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
13050 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
13051 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
13052 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
13053
13054 /* "neighbor port" commands. */
13055 install_element(BGP_NODE, &neighbor_port_cmd);
13056 install_element(BGP_NODE, &no_neighbor_port_cmd);
13057
13058 /* "neighbor weight" commands. */
13059 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
13060 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
13061
13062 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
13063 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
13064 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
13065 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
13066 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
13067 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
13068 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
13069 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13070 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13071 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13072 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13073 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13074 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13075 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13076 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13077 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13078
13079 /* "neighbor override-capability" commands. */
13080 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13081 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13082
13083 /* "neighbor strict-capability-match" commands. */
13084 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13085 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13086
13087 /* "neighbor timers" commands. */
13088 install_element(BGP_NODE, &neighbor_timers_cmd);
13089 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13090
13091 /* "neighbor timers connect" commands. */
13092 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13093 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13094
13095 /* "neighbor advertisement-interval" commands. */
13096 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13097 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13098
13099 /* "neighbor interface" commands. */
13100 install_element(BGP_NODE, &neighbor_interface_cmd);
13101 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13102
13103 /* "neighbor distribute" commands. */
13104 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13105 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13106 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13107 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13108 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13109 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13110 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13111 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13112 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13113 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13114 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13115 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13116 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13117 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13118 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13119 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13120 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13121 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13122
13123 /* "neighbor prefix-list" commands. */
13124 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13125 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13126 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13127 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13128 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13129 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13130 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13131 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13132 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13133 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13134 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13135 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13136 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13137 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13138 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13139 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13140 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13141 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13142 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13143 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13144 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13145 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13146
13147 /* "neighbor filter-list" commands. */
13148 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13149 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13150 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13151 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13152 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13153 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13154 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13155 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13156 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13157 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13158 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13159 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13160 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13161 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13162 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13163 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13164 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13165 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13166 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13167 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13168 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13169 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13170
13171 /* "neighbor route-map" commands. */
13172 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13173 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13174 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13175 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13176 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13177 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13178 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13179 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13180 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13181 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13182 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13183 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13184 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13185 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13186 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13187 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13188 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13189 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13190 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13191 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13192 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13193 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13194 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13195 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13196
13197 /* "neighbor unsuppress-map" commands. */
13198 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13199 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13200 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13201 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13202 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13203 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13204 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13205 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13206 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13207 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13208 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13209 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13210 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13211 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13212 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13213 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13214 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13215 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13216
13217 /* "neighbor maximum-prefix" commands. */
13218 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13219 install_element(BGP_NODE,
13220 &neighbor_maximum_prefix_threshold_hidden_cmd);
13221 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13222 install_element(BGP_NODE,
13223 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13224 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13225 install_element(BGP_NODE,
13226 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13227 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13228 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13229 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13230 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13231 install_element(BGP_IPV4_NODE,
13232 &neighbor_maximum_prefix_threshold_warning_cmd);
13233 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13234 install_element(BGP_IPV4_NODE,
13235 &neighbor_maximum_prefix_threshold_restart_cmd);
13236 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13237 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13238 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13239 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13240 install_element(BGP_IPV4M_NODE,
13241 &neighbor_maximum_prefix_threshold_warning_cmd);
13242 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13243 install_element(BGP_IPV4M_NODE,
13244 &neighbor_maximum_prefix_threshold_restart_cmd);
13245 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13246 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13247 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13248 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13249 install_element(BGP_IPV4L_NODE,
13250 &neighbor_maximum_prefix_threshold_warning_cmd);
13251 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13252 install_element(BGP_IPV4L_NODE,
13253 &neighbor_maximum_prefix_threshold_restart_cmd);
13254 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13255 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13256 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13257 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13258 install_element(BGP_IPV6_NODE,
13259 &neighbor_maximum_prefix_threshold_warning_cmd);
13260 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13261 install_element(BGP_IPV6_NODE,
13262 &neighbor_maximum_prefix_threshold_restart_cmd);
13263 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13264 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13265 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13266 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13267 install_element(BGP_IPV6M_NODE,
13268 &neighbor_maximum_prefix_threshold_warning_cmd);
13269 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13270 install_element(BGP_IPV6M_NODE,
13271 &neighbor_maximum_prefix_threshold_restart_cmd);
13272 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13273 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13274 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13275 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13276 install_element(BGP_IPV6L_NODE,
13277 &neighbor_maximum_prefix_threshold_warning_cmd);
13278 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13279 install_element(BGP_IPV6L_NODE,
13280 &neighbor_maximum_prefix_threshold_restart_cmd);
13281 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13282 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13283 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13284 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13285 install_element(BGP_VPNV4_NODE,
13286 &neighbor_maximum_prefix_threshold_warning_cmd);
13287 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13288 install_element(BGP_VPNV4_NODE,
13289 &neighbor_maximum_prefix_threshold_restart_cmd);
13290 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13291 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13292 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13293 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13294 install_element(BGP_VPNV6_NODE,
13295 &neighbor_maximum_prefix_threshold_warning_cmd);
13296 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13297 install_element(BGP_VPNV6_NODE,
13298 &neighbor_maximum_prefix_threshold_restart_cmd);
13299 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13300
13301 /* "neighbor allowas-in" */
13302 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13303 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13304 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13305 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13306 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13307 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13308 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13309 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13310 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13311 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13312 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13313 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13314 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13315 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13316 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13317 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13318 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13319 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13320 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13321 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13322
13323 /* address-family commands. */
13324 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13325 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13326 #ifdef KEEP_OLD_VPN_COMMANDS
13327 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13328 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13329 #endif /* KEEP_OLD_VPN_COMMANDS */
13330
13331 install_element(BGP_NODE, &address_family_evpn_cmd);
13332
13333 /* "exit-address-family" command. */
13334 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13335 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13336 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13337 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13338 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13339 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13340 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13341 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13342 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13343 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13344 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13345
13346 /* "clear ip bgp commands" */
13347 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13348
13349 /* clear ip bgp prefix */
13350 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13351 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13352 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13353
13354 /* "show [ip] bgp summary" commands. */
13355 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13356 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13357 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13358 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13359 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13360 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13361
13362 /* "show [ip] bgp neighbors" commands. */
13363 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13364
13365 /* "show [ip] bgp peer-group" commands. */
13366 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13367
13368 /* "show [ip] bgp paths" commands. */
13369 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13370
13371 /* "show [ip] bgp community" commands. */
13372 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13373
13374 /* "show ip bgp large-community" commands. */
13375 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13376 /* "show [ip] bgp attribute-info" commands. */
13377 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13378 /* "show [ip] bgp route-leak" command */
13379 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13380
13381 /* "redistribute" commands. */
13382 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13383 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13384 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13385 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13386 install_element(BGP_NODE,
13387 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13388 install_element(BGP_NODE,
13389 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13390 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13391 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13392 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13393 install_element(BGP_NODE,
13394 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13395 install_element(BGP_NODE,
13396 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13397 install_element(BGP_NODE,
13398 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13399 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13400 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13401 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13402 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13403 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13404 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13405 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13406 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13407 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13408 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13409 install_element(BGP_IPV4_NODE,
13410 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13411 install_element(BGP_IPV4_NODE,
13412 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13413 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13414 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13415 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13416 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13417 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13418 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13419
13420 /* import|export vpn [route-map WORD] */
13421 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13422 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13423
13424 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13425 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13426
13427 /* ttl_security commands */
13428 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13429 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13430
13431 /* "show [ip] bgp memory" commands. */
13432 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13433
13434 /* "show bgp martian next-hop" */
13435 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13436
13437 /* "show [ip] bgp views" commands. */
13438 install_element(VIEW_NODE, &show_bgp_views_cmd);
13439
13440 /* "show [ip] bgp vrfs" commands. */
13441 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13442
13443 /* Community-list. */
13444 community_list_vty();
13445
13446 /* vpn-policy commands */
13447 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13448 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13449 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13450 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13451 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13452 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13453 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13454 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13455 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13456 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13457 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13458 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13459
13460 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13461 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13462
13463 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13464 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13465 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13466 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13467 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13468 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13469 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13470 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13471 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13472 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13473 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13474 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13475 }
13476
13477 #include "memory.h"
13478 #include "bgp_regex.h"
13479 #include "bgp_clist.h"
13480 #include "bgp_ecommunity.h"
13481
13482 /* VTY functions. */
13483
13484 /* Direction value to string conversion. */
13485 static const char *community_direct_str(int direct)
13486 {
13487 switch (direct) {
13488 case COMMUNITY_DENY:
13489 return "deny";
13490 case COMMUNITY_PERMIT:
13491 return "permit";
13492 default:
13493 return "unknown";
13494 }
13495 }
13496
13497 /* Display error string. */
13498 static void community_list_perror(struct vty *vty, int ret)
13499 {
13500 switch (ret) {
13501 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13502 vty_out(vty, "%% Can't find community-list\n");
13503 break;
13504 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13505 vty_out(vty, "%% Malformed community-list value\n");
13506 break;
13507 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13508 vty_out(vty,
13509 "%% Community name conflict, previously defined as standard community\n");
13510 break;
13511 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13512 vty_out(vty,
13513 "%% Community name conflict, previously defined as expanded community\n");
13514 break;
13515 }
13516 }
13517
13518 /* "community-list" keyword help string. */
13519 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13520
13521 /* ip community-list standard */
13522 DEFUN (ip_community_list_standard,
13523 ip_community_list_standard_cmd,
13524 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13525 IP_STR
13526 COMMUNITY_LIST_STR
13527 "Community list number (standard)\n"
13528 "Add an standard community-list entry\n"
13529 "Community list name\n"
13530 "Specify community to reject\n"
13531 "Specify community to accept\n"
13532 COMMUNITY_VAL_STR)
13533 {
13534 char *cl_name_or_number = NULL;
13535 int direct = 0;
13536 int style = COMMUNITY_LIST_STANDARD;
13537
13538 int idx = 0;
13539 argv_find(argv, argc, "(1-99)", &idx);
13540 argv_find(argv, argc, "WORD", &idx);
13541 cl_name_or_number = argv[idx]->arg;
13542 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13543 : COMMUNITY_DENY;
13544 argv_find(argv, argc, "AA:NN", &idx);
13545 char *str = argv_concat(argv, argc, idx);
13546
13547 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13548 style);
13549
13550 XFREE(MTYPE_TMP, str);
13551
13552 if (ret < 0) {
13553 /* Display error string. */
13554 community_list_perror(vty, ret);
13555 return CMD_WARNING_CONFIG_FAILED;
13556 }
13557
13558 return CMD_SUCCESS;
13559 }
13560
13561 DEFUN (no_ip_community_list_standard_all,
13562 no_ip_community_list_standard_all_cmd,
13563 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13564 NO_STR
13565 IP_STR
13566 COMMUNITY_LIST_STR
13567 "Community list number (standard)\n"
13568 "Add an standard community-list entry\n"
13569 "Community list name\n"
13570 "Specify community to reject\n"
13571 "Specify community to accept\n"
13572 COMMUNITY_VAL_STR)
13573 {
13574 char *cl_name_or_number = NULL;
13575 int direct = 0;
13576 int style = COMMUNITY_LIST_STANDARD;
13577
13578 int idx = 0;
13579 argv_find(argv, argc, "(1-99)", &idx);
13580 argv_find(argv, argc, "WORD", &idx);
13581 cl_name_or_number = argv[idx]->arg;
13582 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13583 : COMMUNITY_DENY;
13584 argv_find(argv, argc, "AA:NN", &idx);
13585 char *str = argv_concat(argv, argc, idx);
13586
13587 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13588 direct, style);
13589
13590 XFREE(MTYPE_TMP, str);
13591
13592 if (ret < 0) {
13593 community_list_perror(vty, ret);
13594 return CMD_WARNING_CONFIG_FAILED;
13595 }
13596
13597 return CMD_SUCCESS;
13598 }
13599
13600 /* ip community-list expanded */
13601 DEFUN (ip_community_list_expanded_all,
13602 ip_community_list_expanded_all_cmd,
13603 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13604 IP_STR
13605 COMMUNITY_LIST_STR
13606 "Community list number (expanded)\n"
13607 "Add an expanded community-list entry\n"
13608 "Community list name\n"
13609 "Specify community to reject\n"
13610 "Specify community to accept\n"
13611 COMMUNITY_VAL_STR)
13612 {
13613 char *cl_name_or_number = NULL;
13614 int direct = 0;
13615 int style = COMMUNITY_LIST_EXPANDED;
13616
13617 int idx = 0;
13618 argv_find(argv, argc, "(100-500)", &idx);
13619 argv_find(argv, argc, "WORD", &idx);
13620 cl_name_or_number = argv[idx]->arg;
13621 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13622 : COMMUNITY_DENY;
13623 argv_find(argv, argc, "AA:NN", &idx);
13624 char *str = argv_concat(argv, argc, idx);
13625
13626 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13627 style);
13628
13629 XFREE(MTYPE_TMP, str);
13630
13631 if (ret < 0) {
13632 /* Display error string. */
13633 community_list_perror(vty, ret);
13634 return CMD_WARNING_CONFIG_FAILED;
13635 }
13636
13637 return CMD_SUCCESS;
13638 }
13639
13640 DEFUN (no_ip_community_list_expanded_all,
13641 no_ip_community_list_expanded_all_cmd,
13642 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13643 NO_STR
13644 IP_STR
13645 COMMUNITY_LIST_STR
13646 "Community list number (expanded)\n"
13647 "Add an expanded community-list entry\n"
13648 "Community list name\n"
13649 "Specify community to reject\n"
13650 "Specify community to accept\n"
13651 COMMUNITY_VAL_STR)
13652 {
13653 char *cl_name_or_number = NULL;
13654 int direct = 0;
13655 int style = COMMUNITY_LIST_EXPANDED;
13656
13657 int idx = 0;
13658 argv_find(argv, argc, "(100-500)", &idx);
13659 argv_find(argv, argc, "WORD", &idx);
13660 cl_name_or_number = argv[idx]->arg;
13661 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13662 : COMMUNITY_DENY;
13663 argv_find(argv, argc, "AA:NN", &idx);
13664 char *str = argv_concat(argv, argc, idx);
13665
13666 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13667 direct, style);
13668
13669 XFREE(MTYPE_TMP, str);
13670
13671 if (ret < 0) {
13672 community_list_perror(vty, ret);
13673 return CMD_WARNING_CONFIG_FAILED;
13674 }
13675
13676 return CMD_SUCCESS;
13677 }
13678
13679 /* Return configuration string of community-list entry. */
13680 static const char *community_list_config_str(struct community_entry *entry)
13681 {
13682 const char *str;
13683
13684 if (entry->any)
13685 str = "";
13686 else {
13687 if (entry->style == COMMUNITY_LIST_STANDARD)
13688 str = community_str(entry->u.com, false);
13689 else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
13690 str = lcommunity_str(entry->u.lcom, false);
13691 else
13692 str = entry->config;
13693 }
13694 return str;
13695 }
13696
13697 static void community_list_show(struct vty *vty, struct community_list *list)
13698 {
13699 struct community_entry *entry;
13700
13701 for (entry = list->head; entry; entry = entry->next) {
13702 if (entry == list->head) {
13703 if (all_digit(list->name))
13704 vty_out(vty, "Community %s list %s\n",
13705 entry->style == COMMUNITY_LIST_STANDARD
13706 ? "standard"
13707 : "(expanded) access",
13708 list->name);
13709 else
13710 vty_out(vty, "Named Community %s list %s\n",
13711 entry->style == COMMUNITY_LIST_STANDARD
13712 ? "standard"
13713 : "expanded",
13714 list->name);
13715 }
13716 if (entry->any)
13717 vty_out(vty, " %s\n",
13718 community_direct_str(entry->direct));
13719 else
13720 vty_out(vty, " %s %s\n",
13721 community_direct_str(entry->direct),
13722 community_list_config_str(entry));
13723 }
13724 }
13725
13726 DEFUN (show_ip_community_list,
13727 show_ip_community_list_cmd,
13728 "show ip community-list",
13729 SHOW_STR
13730 IP_STR
13731 "List community-list\n")
13732 {
13733 struct community_list *list;
13734 struct community_list_master *cm;
13735
13736 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13737 if (!cm)
13738 return CMD_SUCCESS;
13739
13740 for (list = cm->num.head; list; list = list->next)
13741 community_list_show(vty, list);
13742
13743 for (list = cm->str.head; list; list = list->next)
13744 community_list_show(vty, list);
13745
13746 return CMD_SUCCESS;
13747 }
13748
13749 DEFUN (show_ip_community_list_arg,
13750 show_ip_community_list_arg_cmd,
13751 "show ip community-list <(1-500)|WORD>",
13752 SHOW_STR
13753 IP_STR
13754 "List community-list\n"
13755 "Community-list number\n"
13756 "Community-list name\n")
13757 {
13758 int idx_comm_list = 3;
13759 struct community_list *list;
13760
13761 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13762 COMMUNITY_LIST_MASTER);
13763 if (!list) {
13764 vty_out(vty, "%% Can't find community-list\n");
13765 return CMD_WARNING;
13766 }
13767
13768 community_list_show(vty, list);
13769
13770 return CMD_SUCCESS;
13771 }
13772
13773 /*
13774 * Large Community code.
13775 */
13776 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13777 struct cmd_token **argv, int style,
13778 int reject_all_digit_name)
13779 {
13780 int ret;
13781 int direct;
13782 char *str;
13783 int idx = 0;
13784 char *cl_name;
13785
13786 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13787 : COMMUNITY_DENY;
13788
13789 /* All digit name check. */
13790 idx = 0;
13791 argv_find(argv, argc, "WORD", &idx);
13792 argv_find(argv, argc, "(1-99)", &idx);
13793 argv_find(argv, argc, "(100-500)", &idx);
13794 cl_name = argv[idx]->arg;
13795 if (reject_all_digit_name && all_digit(cl_name)) {
13796 vty_out(vty, "%% Community name cannot have all digits\n");
13797 return CMD_WARNING_CONFIG_FAILED;
13798 }
13799
13800 idx = 0;
13801 argv_find(argv, argc, "AA:BB:CC", &idx);
13802 argv_find(argv, argc, "LINE", &idx);
13803 /* Concat community string argument. */
13804 if (idx)
13805 str = argv_concat(argv, argc, idx);
13806 else
13807 str = NULL;
13808
13809 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13810
13811 /* Free temporary community list string allocated by
13812 argv_concat(). */
13813 if (str)
13814 XFREE(MTYPE_TMP, str);
13815
13816 if (ret < 0) {
13817 community_list_perror(vty, ret);
13818 return CMD_WARNING_CONFIG_FAILED;
13819 }
13820 return CMD_SUCCESS;
13821 }
13822
13823 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13824 struct cmd_token **argv, int style)
13825 {
13826 int ret;
13827 int direct = 0;
13828 char *str = NULL;
13829 int idx = 0;
13830
13831 argv_find(argv, argc, "permit", &idx);
13832 argv_find(argv, argc, "deny", &idx);
13833
13834 if (idx) {
13835 /* Check the list direct. */
13836 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13837 direct = COMMUNITY_PERMIT;
13838 else
13839 direct = COMMUNITY_DENY;
13840
13841 idx = 0;
13842 argv_find(argv, argc, "LINE", &idx);
13843 argv_find(argv, argc, "AA:AA:NN", &idx);
13844 /* Concat community string argument. */
13845 str = argv_concat(argv, argc, idx);
13846 }
13847
13848 idx = 0;
13849 argv_find(argv, argc, "(1-99)", &idx);
13850 argv_find(argv, argc, "(100-500)", &idx);
13851 argv_find(argv, argc, "WORD", &idx);
13852
13853 /* Unset community list. */
13854 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13855 style);
13856
13857 /* Free temporary community list string allocated by
13858 argv_concat(). */
13859 if (str)
13860 XFREE(MTYPE_TMP, str);
13861
13862 if (ret < 0) {
13863 community_list_perror(vty, ret);
13864 return CMD_WARNING_CONFIG_FAILED;
13865 }
13866
13867 return CMD_SUCCESS;
13868 }
13869
13870 /* "large-community-list" keyword help string. */
13871 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13872 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13873
13874 DEFUN (ip_lcommunity_list_standard,
13875 ip_lcommunity_list_standard_cmd,
13876 "ip large-community-list (1-99) <deny|permit>",
13877 IP_STR
13878 LCOMMUNITY_LIST_STR
13879 "Large Community list number (standard)\n"
13880 "Specify large community to reject\n"
13881 "Specify large community to accept\n")
13882 {
13883 return lcommunity_list_set_vty(vty, argc, argv,
13884 LARGE_COMMUNITY_LIST_STANDARD, 0);
13885 }
13886
13887 DEFUN (ip_lcommunity_list_standard1,
13888 ip_lcommunity_list_standard1_cmd,
13889 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13890 IP_STR
13891 LCOMMUNITY_LIST_STR
13892 "Large Community list number (standard)\n"
13893 "Specify large community to reject\n"
13894 "Specify large community to accept\n"
13895 LCOMMUNITY_VAL_STR)
13896 {
13897 return lcommunity_list_set_vty(vty, argc, argv,
13898 LARGE_COMMUNITY_LIST_STANDARD, 0);
13899 }
13900
13901 DEFUN (ip_lcommunity_list_expanded,
13902 ip_lcommunity_list_expanded_cmd,
13903 "ip large-community-list (100-500) <deny|permit> LINE...",
13904 IP_STR
13905 LCOMMUNITY_LIST_STR
13906 "Large Community list number (expanded)\n"
13907 "Specify large community to reject\n"
13908 "Specify large community to accept\n"
13909 "An ordered list as a regular-expression\n")
13910 {
13911 return lcommunity_list_set_vty(vty, argc, argv,
13912 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13913 }
13914
13915 DEFUN (ip_lcommunity_list_name_standard,
13916 ip_lcommunity_list_name_standard_cmd,
13917 "ip large-community-list standard WORD <deny|permit>",
13918 IP_STR
13919 LCOMMUNITY_LIST_STR
13920 "Specify standard large-community-list\n"
13921 "Large Community list name\n"
13922 "Specify large community to reject\n"
13923 "Specify large community to accept\n")
13924 {
13925 return lcommunity_list_set_vty(vty, argc, argv,
13926 LARGE_COMMUNITY_LIST_STANDARD, 1);
13927 }
13928
13929 DEFUN (ip_lcommunity_list_name_standard1,
13930 ip_lcommunity_list_name_standard1_cmd,
13931 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13932 IP_STR
13933 LCOMMUNITY_LIST_STR
13934 "Specify standard large-community-list\n"
13935 "Large Community list name\n"
13936 "Specify large community to reject\n"
13937 "Specify large community to accept\n"
13938 LCOMMUNITY_VAL_STR)
13939 {
13940 return lcommunity_list_set_vty(vty, argc, argv,
13941 LARGE_COMMUNITY_LIST_STANDARD, 1);
13942 }
13943
13944 DEFUN (ip_lcommunity_list_name_expanded,
13945 ip_lcommunity_list_name_expanded_cmd,
13946 "ip large-community-list expanded WORD <deny|permit> LINE...",
13947 IP_STR
13948 LCOMMUNITY_LIST_STR
13949 "Specify expanded large-community-list\n"
13950 "Large Community list name\n"
13951 "Specify large community to reject\n"
13952 "Specify large community to accept\n"
13953 "An ordered list as a regular-expression\n")
13954 {
13955 return lcommunity_list_set_vty(vty, argc, argv,
13956 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13957 }
13958
13959 DEFUN (no_ip_lcommunity_list_standard_all,
13960 no_ip_lcommunity_list_standard_all_cmd,
13961 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13962 NO_STR
13963 IP_STR
13964 LCOMMUNITY_LIST_STR
13965 "Large Community list number (standard)\n"
13966 "Large Community list number (expanded)\n"
13967 "Large Community list name\n")
13968 {
13969 return lcommunity_list_unset_vty(vty, argc, argv,
13970 LARGE_COMMUNITY_LIST_STANDARD);
13971 }
13972
13973 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13974 no_ip_lcommunity_list_name_expanded_all_cmd,
13975 "no ip large-community-list expanded WORD",
13976 NO_STR
13977 IP_STR
13978 LCOMMUNITY_LIST_STR
13979 "Specify expanded large-community-list\n"
13980 "Large Community list name\n")
13981 {
13982 return lcommunity_list_unset_vty(vty, argc, argv,
13983 LARGE_COMMUNITY_LIST_EXPANDED);
13984 }
13985
13986 DEFUN (no_ip_lcommunity_list_standard,
13987 no_ip_lcommunity_list_standard_cmd,
13988 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13989 NO_STR
13990 IP_STR
13991 LCOMMUNITY_LIST_STR
13992 "Large Community list number (standard)\n"
13993 "Specify large community to reject\n"
13994 "Specify large community to accept\n"
13995 LCOMMUNITY_VAL_STR)
13996 {
13997 return lcommunity_list_unset_vty(vty, argc, argv,
13998 LARGE_COMMUNITY_LIST_STANDARD);
13999 }
14000
14001 DEFUN (no_ip_lcommunity_list_expanded,
14002 no_ip_lcommunity_list_expanded_cmd,
14003 "no ip large-community-list (100-500) <deny|permit> LINE...",
14004 NO_STR
14005 IP_STR
14006 LCOMMUNITY_LIST_STR
14007 "Large Community list number (expanded)\n"
14008 "Specify large community to reject\n"
14009 "Specify large community to accept\n"
14010 "An ordered list as a regular-expression\n")
14011 {
14012 return lcommunity_list_unset_vty(vty, argc, argv,
14013 LARGE_COMMUNITY_LIST_EXPANDED);
14014 }
14015
14016 DEFUN (no_ip_lcommunity_list_name_standard,
14017 no_ip_lcommunity_list_name_standard_cmd,
14018 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
14019 NO_STR
14020 IP_STR
14021 LCOMMUNITY_LIST_STR
14022 "Specify standard large-community-list\n"
14023 "Large Community list name\n"
14024 "Specify large community to reject\n"
14025 "Specify large community to accept\n"
14026 LCOMMUNITY_VAL_STR)
14027 {
14028 return lcommunity_list_unset_vty(vty, argc, argv,
14029 LARGE_COMMUNITY_LIST_STANDARD);
14030 }
14031
14032 DEFUN (no_ip_lcommunity_list_name_expanded,
14033 no_ip_lcommunity_list_name_expanded_cmd,
14034 "no ip large-community-list expanded WORD <deny|permit> LINE...",
14035 NO_STR
14036 IP_STR
14037 LCOMMUNITY_LIST_STR
14038 "Specify expanded large-community-list\n"
14039 "Large community list name\n"
14040 "Specify large community to reject\n"
14041 "Specify large community to accept\n"
14042 "An ordered list as a regular-expression\n")
14043 {
14044 return lcommunity_list_unset_vty(vty, argc, argv,
14045 LARGE_COMMUNITY_LIST_EXPANDED);
14046 }
14047
14048 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
14049 {
14050 struct community_entry *entry;
14051
14052 for (entry = list->head; entry; entry = entry->next) {
14053 if (entry == list->head) {
14054 if (all_digit(list->name))
14055 vty_out(vty, "Large community %s list %s\n",
14056 entry->style == EXTCOMMUNITY_LIST_STANDARD
14057 ? "standard"
14058 : "(expanded) access",
14059 list->name);
14060 else
14061 vty_out(vty,
14062 "Named large community %s list %s\n",
14063 entry->style == EXTCOMMUNITY_LIST_STANDARD
14064 ? "standard"
14065 : "expanded",
14066 list->name);
14067 }
14068 if (entry->any)
14069 vty_out(vty, " %s\n",
14070 community_direct_str(entry->direct));
14071 else
14072 vty_out(vty, " %s %s\n",
14073 community_direct_str(entry->direct),
14074 community_list_config_str(entry));
14075 }
14076 }
14077
14078 DEFUN (show_ip_lcommunity_list,
14079 show_ip_lcommunity_list_cmd,
14080 "show ip large-community-list",
14081 SHOW_STR
14082 IP_STR
14083 "List large-community list\n")
14084 {
14085 struct community_list *list;
14086 struct community_list_master *cm;
14087
14088 cm = community_list_master_lookup(bgp_clist,
14089 LARGE_COMMUNITY_LIST_MASTER);
14090 if (!cm)
14091 return CMD_SUCCESS;
14092
14093 for (list = cm->num.head; list; list = list->next)
14094 lcommunity_list_show(vty, list);
14095
14096 for (list = cm->str.head; list; list = list->next)
14097 lcommunity_list_show(vty, list);
14098
14099 return CMD_SUCCESS;
14100 }
14101
14102 DEFUN (show_ip_lcommunity_list_arg,
14103 show_ip_lcommunity_list_arg_cmd,
14104 "show ip large-community-list <(1-500)|WORD>",
14105 SHOW_STR
14106 IP_STR
14107 "List large-community list\n"
14108 "large-community-list number\n"
14109 "large-community-list name\n")
14110 {
14111 struct community_list *list;
14112
14113 list = community_list_lookup(bgp_clist, argv[3]->arg,
14114 LARGE_COMMUNITY_LIST_MASTER);
14115 if (!list) {
14116 vty_out(vty, "%% Can't find extcommunity-list\n");
14117 return CMD_WARNING;
14118 }
14119
14120 lcommunity_list_show(vty, list);
14121
14122 return CMD_SUCCESS;
14123 }
14124
14125 /* "extcommunity-list" keyword help string. */
14126 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14127 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14128
14129 DEFUN (ip_extcommunity_list_standard,
14130 ip_extcommunity_list_standard_cmd,
14131 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14132 IP_STR
14133 EXTCOMMUNITY_LIST_STR
14134 "Extended Community list number (standard)\n"
14135 "Specify standard extcommunity-list\n"
14136 "Community list name\n"
14137 "Specify community to reject\n"
14138 "Specify community to accept\n"
14139 EXTCOMMUNITY_VAL_STR)
14140 {
14141 int style = EXTCOMMUNITY_LIST_STANDARD;
14142 int direct = 0;
14143 char *cl_number_or_name = NULL;
14144
14145 int idx = 0;
14146 argv_find(argv, argc, "(1-99)", &idx);
14147 argv_find(argv, argc, "WORD", &idx);
14148 cl_number_or_name = argv[idx]->arg;
14149 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14150 : COMMUNITY_DENY;
14151 argv_find(argv, argc, "AA:NN", &idx);
14152 char *str = argv_concat(argv, argc, idx);
14153
14154 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14155 direct, style);
14156
14157 XFREE(MTYPE_TMP, str);
14158
14159 if (ret < 0) {
14160 community_list_perror(vty, ret);
14161 return CMD_WARNING_CONFIG_FAILED;
14162 }
14163
14164 return CMD_SUCCESS;
14165 }
14166
14167 DEFUN (ip_extcommunity_list_name_expanded,
14168 ip_extcommunity_list_name_expanded_cmd,
14169 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14170 IP_STR
14171 EXTCOMMUNITY_LIST_STR
14172 "Extended Community list number (expanded)\n"
14173 "Specify expanded extcommunity-list\n"
14174 "Extended Community list name\n"
14175 "Specify community to reject\n"
14176 "Specify community to accept\n"
14177 "An ordered list as a regular-expression\n")
14178 {
14179 int style = EXTCOMMUNITY_LIST_EXPANDED;
14180 int direct = 0;
14181 char *cl_number_or_name = NULL;
14182
14183 int idx = 0;
14184 argv_find(argv, argc, "(100-500)", &idx);
14185 argv_find(argv, argc, "WORD", &idx);
14186 cl_number_or_name = argv[idx]->arg;
14187 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14188 : COMMUNITY_DENY;
14189 argv_find(argv, argc, "LINE", &idx);
14190 char *str = argv_concat(argv, argc, idx);
14191
14192 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14193 direct, style);
14194
14195 XFREE(MTYPE_TMP, str);
14196
14197 if (ret < 0) {
14198 community_list_perror(vty, ret);
14199 return CMD_WARNING_CONFIG_FAILED;
14200 }
14201
14202 return CMD_SUCCESS;
14203 }
14204
14205 DEFUN (no_ip_extcommunity_list_standard_all,
14206 no_ip_extcommunity_list_standard_all_cmd,
14207 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14208 NO_STR
14209 IP_STR
14210 EXTCOMMUNITY_LIST_STR
14211 "Extended Community list number (standard)\n"
14212 "Specify standard extcommunity-list\n"
14213 "Community list name\n"
14214 "Specify community to reject\n"
14215 "Specify community to accept\n"
14216 EXTCOMMUNITY_VAL_STR)
14217 {
14218 int style = EXTCOMMUNITY_LIST_STANDARD;
14219 int direct = 0;
14220 char *cl_number_or_name = NULL;
14221
14222 int idx = 0;
14223 argv_find(argv, argc, "(1-99)", &idx);
14224 argv_find(argv, argc, "WORD", &idx);
14225 cl_number_or_name = argv[idx]->arg;
14226 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14227 : COMMUNITY_DENY;
14228 argv_find(argv, argc, "AA:NN", &idx);
14229 char *str = argv_concat(argv, argc, idx);
14230
14231 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14232 direct, style);
14233
14234 XFREE(MTYPE_TMP, str);
14235
14236 if (ret < 0) {
14237 community_list_perror(vty, ret);
14238 return CMD_WARNING_CONFIG_FAILED;
14239 }
14240
14241 return CMD_SUCCESS;
14242 }
14243
14244 DEFUN (no_ip_extcommunity_list_expanded_all,
14245 no_ip_extcommunity_list_expanded_all_cmd,
14246 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14247 NO_STR
14248 IP_STR
14249 EXTCOMMUNITY_LIST_STR
14250 "Extended Community list number (expanded)\n"
14251 "Specify expanded extcommunity-list\n"
14252 "Extended Community list name\n"
14253 "Specify community to reject\n"
14254 "Specify community to accept\n"
14255 "An ordered list as a regular-expression\n")
14256 {
14257 int style = EXTCOMMUNITY_LIST_EXPANDED;
14258 int direct = 0;
14259 char *cl_number_or_name = NULL;
14260
14261 int idx = 0;
14262 argv_find(argv, argc, "(100-500)", &idx);
14263 argv_find(argv, argc, "WORD", &idx);
14264 cl_number_or_name = argv[idx]->arg;
14265 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14266 : COMMUNITY_DENY;
14267 argv_find(argv, argc, "LINE", &idx);
14268 char *str = argv_concat(argv, argc, idx);
14269
14270 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14271 direct, style);
14272
14273 XFREE(MTYPE_TMP, str);
14274
14275 if (ret < 0) {
14276 community_list_perror(vty, ret);
14277 return CMD_WARNING_CONFIG_FAILED;
14278 }
14279
14280 return CMD_SUCCESS;
14281 }
14282
14283 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14284 {
14285 struct community_entry *entry;
14286
14287 for (entry = list->head; entry; entry = entry->next) {
14288 if (entry == list->head) {
14289 if (all_digit(list->name))
14290 vty_out(vty, "Extended community %s list %s\n",
14291 entry->style == EXTCOMMUNITY_LIST_STANDARD
14292 ? "standard"
14293 : "(expanded) access",
14294 list->name);
14295 else
14296 vty_out(vty,
14297 "Named extended community %s list %s\n",
14298 entry->style == EXTCOMMUNITY_LIST_STANDARD
14299 ? "standard"
14300 : "expanded",
14301 list->name);
14302 }
14303 if (entry->any)
14304 vty_out(vty, " %s\n",
14305 community_direct_str(entry->direct));
14306 else
14307 vty_out(vty, " %s %s\n",
14308 community_direct_str(entry->direct),
14309 community_list_config_str(entry));
14310 }
14311 }
14312
14313 DEFUN (show_ip_extcommunity_list,
14314 show_ip_extcommunity_list_cmd,
14315 "show ip extcommunity-list",
14316 SHOW_STR
14317 IP_STR
14318 "List extended-community list\n")
14319 {
14320 struct community_list *list;
14321 struct community_list_master *cm;
14322
14323 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14324 if (!cm)
14325 return CMD_SUCCESS;
14326
14327 for (list = cm->num.head; list; list = list->next)
14328 extcommunity_list_show(vty, list);
14329
14330 for (list = cm->str.head; list; list = list->next)
14331 extcommunity_list_show(vty, list);
14332
14333 return CMD_SUCCESS;
14334 }
14335
14336 DEFUN (show_ip_extcommunity_list_arg,
14337 show_ip_extcommunity_list_arg_cmd,
14338 "show ip extcommunity-list <(1-500)|WORD>",
14339 SHOW_STR
14340 IP_STR
14341 "List extended-community list\n"
14342 "Extcommunity-list number\n"
14343 "Extcommunity-list name\n")
14344 {
14345 int idx_comm_list = 3;
14346 struct community_list *list;
14347
14348 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14349 EXTCOMMUNITY_LIST_MASTER);
14350 if (!list) {
14351 vty_out(vty, "%% Can't find extcommunity-list\n");
14352 return CMD_WARNING;
14353 }
14354
14355 extcommunity_list_show(vty, list);
14356
14357 return CMD_SUCCESS;
14358 }
14359
14360 /* Display community-list and extcommunity-list configuration. */
14361 static int community_list_config_write(struct vty *vty)
14362 {
14363 struct community_list *list;
14364 struct community_entry *entry;
14365 struct community_list_master *cm;
14366 int write = 0;
14367
14368 /* Community-list. */
14369 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14370
14371 for (list = cm->num.head; list; list = list->next)
14372 for (entry = list->head; entry; entry = entry->next) {
14373 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14374 community_direct_str(entry->direct),
14375 community_list_config_str(entry));
14376 write++;
14377 }
14378 for (list = cm->str.head; list; list = list->next)
14379 for (entry = list->head; entry; entry = entry->next) {
14380 vty_out(vty, "ip community-list %s %s %s %s\n",
14381 entry->style == COMMUNITY_LIST_STANDARD
14382 ? "standard"
14383 : "expanded",
14384 list->name, community_direct_str(entry->direct),
14385 community_list_config_str(entry));
14386 write++;
14387 }
14388
14389 /* Extcommunity-list. */
14390 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14391
14392 for (list = cm->num.head; list; list = list->next)
14393 for (entry = list->head; entry; entry = entry->next) {
14394 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14395 list->name, community_direct_str(entry->direct),
14396 community_list_config_str(entry));
14397 write++;
14398 }
14399 for (list = cm->str.head; list; list = list->next)
14400 for (entry = list->head; entry; entry = entry->next) {
14401 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14402 entry->style == EXTCOMMUNITY_LIST_STANDARD
14403 ? "standard"
14404 : "expanded",
14405 list->name, community_direct_str(entry->direct),
14406 community_list_config_str(entry));
14407 write++;
14408 }
14409
14410
14411 /* lcommunity-list. */
14412 cm = community_list_master_lookup(bgp_clist,
14413 LARGE_COMMUNITY_LIST_MASTER);
14414
14415 for (list = cm->num.head; list; list = list->next)
14416 for (entry = list->head; entry; entry = entry->next) {
14417 vty_out(vty, "ip large-community-list %s %s %s\n",
14418 list->name, community_direct_str(entry->direct),
14419 community_list_config_str(entry));
14420 write++;
14421 }
14422 for (list = cm->str.head; list; list = list->next)
14423 for (entry = list->head; entry; entry = entry->next) {
14424 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14425 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14426 ? "standard"
14427 : "expanded",
14428 list->name, community_direct_str(entry->direct),
14429 community_list_config_str(entry));
14430 write++;
14431 }
14432
14433 return write;
14434 }
14435
14436 static struct cmd_node community_list_node = {
14437 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14438 };
14439
14440 static void community_list_vty(void)
14441 {
14442 install_node(&community_list_node, community_list_config_write);
14443
14444 /* Community-list. */
14445 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14446 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14447 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14448 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14449 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14450 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14451
14452 /* Extcommunity-list. */
14453 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14454 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14455 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14456 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14457 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14458 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14459
14460 /* Large Community List */
14461 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14462 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14463 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14464 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14465 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14466 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14467 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14468 install_element(CONFIG_NODE,
14469 &no_ip_lcommunity_list_name_expanded_all_cmd);
14470 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14471 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14472 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14473 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14474 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14475 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14476 }