]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #2216 from qlyoung/fix-doc-warnings
[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 struct peer *peer;
557 struct listnode *node, *nnode;
558
559 /* Clear all neighbors. */
560 /*
561 * Pass along pointer to next node to peer_clear() when walking all
562 * nodes
563 * on the BGP instance as that may get freed if it is a doppelganger
564 */
565 if (sort == clear_all) {
566 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
567 if (stype == BGP_CLEAR_SOFT_NONE)
568 ret = peer_clear(peer, &nnode);
569 else if (peer->afc[afi][safi])
570 ret = peer_clear_soft(peer, afi, safi, stype);
571 else
572 ret = 0;
573
574 if (ret < 0)
575 bgp_clear_vty_error(vty, peer, afi, safi, ret);
576 }
577
578 /* This is to apply read-only mode on this clear. */
579 if (stype == BGP_CLEAR_SOFT_NONE)
580 bgp->update_delay_over = 0;
581
582 return CMD_SUCCESS;
583 }
584
585 /* Clear specified neighbors. */
586 if (sort == clear_peer) {
587 union sockunion su;
588 int ret;
589
590 /* Make sockunion for lookup. */
591 ret = str2sockunion(arg, &su);
592 if (ret < 0) {
593 peer = peer_lookup_by_conf_if(bgp, arg);
594 if (!peer) {
595 peer = peer_lookup_by_hostname(bgp, arg);
596 if (!peer) {
597 vty_out(vty,
598 "Malformed address or name: %s\n",
599 arg);
600 return CMD_WARNING;
601 }
602 }
603 } else {
604 peer = peer_lookup(bgp, &su);
605 if (!peer) {
606 vty_out(vty,
607 "%%BGP: Unknown neighbor - \"%s\"\n",
608 arg);
609 return CMD_WARNING;
610 }
611 }
612
613 if (stype == BGP_CLEAR_SOFT_NONE)
614 ret = peer_clear(peer, NULL);
615 else
616 ret = peer_clear_soft(peer, afi, safi, stype);
617
618 if (ret < 0)
619 bgp_clear_vty_error(vty, peer, afi, safi, ret);
620
621 return CMD_SUCCESS;
622 }
623
624 /* Clear all peer-group members. */
625 if (sort == clear_group) {
626 struct peer_group *group;
627
628 group = peer_group_lookup(bgp, arg);
629 if (!group) {
630 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
631 return CMD_WARNING;
632 }
633
634 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
635 if (stype == BGP_CLEAR_SOFT_NONE) {
636 peer_clear(peer, NULL);
637 continue;
638 }
639
640 if (!peer->afc[afi][safi])
641 continue;
642
643 ret = peer_clear_soft(peer, afi, safi, stype);
644
645 if (ret < 0)
646 bgp_clear_vty_error(vty, peer, afi, safi, ret);
647 }
648 return CMD_SUCCESS;
649 }
650
651 if (sort == clear_external) {
652 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
653 if (peer->sort == BGP_PEER_IBGP)
654 continue;
655
656 if (stype == BGP_CLEAR_SOFT_NONE)
657 ret = peer_clear(peer, &nnode);
658 else
659 ret = peer_clear_soft(peer, afi, safi, stype);
660
661 if (ret < 0)
662 bgp_clear_vty_error(vty, peer, afi, safi, ret);
663 }
664 return CMD_SUCCESS;
665 }
666
667 if (sort == clear_as) {
668 as_t as;
669 int find = 0;
670
671 as = strtoul(arg, NULL, 10);
672
673 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
674 if (peer->as != as)
675 continue;
676
677 find = 1;
678 if (stype == BGP_CLEAR_SOFT_NONE)
679 ret = peer_clear(peer, &nnode);
680 else
681 ret = peer_clear_soft(peer, afi, safi, stype);
682
683 if (ret < 0)
684 bgp_clear_vty_error(vty, peer, afi, safi, ret);
685 }
686 if (!find)
687 vty_out(vty,
688 "%%BGP: No peer is configured with AS %s\n",
689 arg);
690 return CMD_SUCCESS;
691 }
692
693 return CMD_SUCCESS;
694 }
695
696 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
697 safi_t safi, enum clear_sort sort,
698 enum bgp_clear_type stype, const char *arg)
699 {
700 struct bgp *bgp;
701
702 /* BGP structure lookup. */
703 if (name) {
704 bgp = bgp_lookup_by_name(name);
705 if (bgp == NULL) {
706 vty_out(vty, "Can't find BGP instance %s\n", name);
707 return CMD_WARNING;
708 }
709 } else {
710 bgp = bgp_get_default();
711 if (bgp == NULL) {
712 vty_out(vty, "No BGP process is configured\n");
713 return CMD_WARNING;
714 }
715 }
716
717 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
718 }
719
720 /* clear soft inbound */
721 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
722 {
723 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
724 BGP_CLEAR_SOFT_IN, NULL);
725 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
726 BGP_CLEAR_SOFT_IN, NULL);
727 }
728
729 /* clear soft outbound */
730 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
731 {
732 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
733 BGP_CLEAR_SOFT_OUT, NULL);
734 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
735 BGP_CLEAR_SOFT_OUT, NULL);
736 }
737
738
739 #ifndef VTYSH_EXTRACT_PL
740 #include "bgpd/bgp_vty_clippy.c"
741 #endif
742
743 /* BGP global configuration. */
744
745 DEFUN (bgp_multiple_instance_func,
746 bgp_multiple_instance_cmd,
747 "bgp multiple-instance",
748 BGP_STR
749 "Enable bgp multiple instance\n")
750 {
751 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
752 return CMD_SUCCESS;
753 }
754
755 DEFUN (no_bgp_multiple_instance,
756 no_bgp_multiple_instance_cmd,
757 "no bgp multiple-instance",
758 NO_STR
759 BGP_STR
760 "BGP multiple instance\n")
761 {
762 int ret;
763
764 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
765 if (ret < 0) {
766 vty_out(vty, "%% There are more than two BGP instances\n");
767 return CMD_WARNING_CONFIG_FAILED;
768 }
769 return CMD_SUCCESS;
770 }
771
772 DEFUN (bgp_config_type,
773 bgp_config_type_cmd,
774 "bgp config-type <cisco|zebra>",
775 BGP_STR
776 "Configuration type\n"
777 "cisco\n"
778 "zebra\n")
779 {
780 int idx = 0;
781 if (argv_find(argv, argc, "cisco", &idx))
782 bgp_option_set(BGP_OPT_CONFIG_CISCO);
783 else
784 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
785
786 return CMD_SUCCESS;
787 }
788
789 DEFUN (no_bgp_config_type,
790 no_bgp_config_type_cmd,
791 "no bgp config-type [<cisco|zebra>]",
792 NO_STR
793 BGP_STR
794 "Display configuration type\n"
795 "cisco\n"
796 "zebra\n")
797 {
798 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
799 return CMD_SUCCESS;
800 }
801
802
803 DEFUN (no_synchronization,
804 no_synchronization_cmd,
805 "no synchronization",
806 NO_STR
807 "Perform IGP synchronization\n")
808 {
809 return CMD_SUCCESS;
810 }
811
812 DEFUN (no_auto_summary,
813 no_auto_summary_cmd,
814 "no auto-summary",
815 NO_STR
816 "Enable automatic network number summarization\n")
817 {
818 return CMD_SUCCESS;
819 }
820
821 /* "router bgp" commands. */
822 DEFUN_NOSH (router_bgp,
823 router_bgp_cmd,
824 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
825 ROUTER_STR
826 BGP_STR
827 AS_STR
828 BGP_INSTANCE_HELP_STR)
829 {
830 int idx_asn = 2;
831 int idx_view_vrf = 3;
832 int idx_vrf = 4;
833 int ret;
834 as_t as;
835 struct bgp *bgp;
836 const char *name = NULL;
837 enum bgp_instance_type inst_type;
838
839 // "router bgp" without an ASN
840 if (argc == 2) {
841 // Pending: Make VRF option available for ASN less config
842 bgp = bgp_get_default();
843
844 if (bgp == NULL) {
845 vty_out(vty, "%% No BGP process is configured\n");
846 return CMD_WARNING_CONFIG_FAILED;
847 }
848
849 if (listcount(bm->bgp) > 1) {
850 vty_out(vty, "%% Please specify ASN and VRF\n");
851 return CMD_WARNING_CONFIG_FAILED;
852 }
853 }
854
855 // "router bgp X"
856 else {
857 as = strtoul(argv[idx_asn]->arg, NULL, 10);
858
859 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
860 if (argc > 3) {
861 name = argv[idx_vrf]->arg;
862
863 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
864 inst_type = BGP_INSTANCE_TYPE_VRF;
865 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
866 inst_type = BGP_INSTANCE_TYPE_VIEW;
867 }
868
869 ret = bgp_get(&bgp, &as, name, inst_type);
870 switch (ret) {
871 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
872 vty_out(vty,
873 "Please specify 'bgp multiple-instance' first\n");
874 return CMD_WARNING_CONFIG_FAILED;
875 case BGP_ERR_AS_MISMATCH:
876 vty_out(vty, "BGP is already running; AS is %u\n", as);
877 return CMD_WARNING_CONFIG_FAILED;
878 case BGP_ERR_INSTANCE_MISMATCH:
879 vty_out(vty,
880 "BGP instance name and AS number mismatch\n");
881 vty_out(vty,
882 "BGP instance is already running; AS is %u\n",
883 as);
884 return CMD_WARNING_CONFIG_FAILED;
885 }
886
887 /* Pending: handle when user tries to change a view to vrf n vv.
888 */
889 }
890
891 /* unset the auto created flag as the user config is now present */
892 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
893 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
894
895 return CMD_SUCCESS;
896 }
897
898 /* "no router bgp" commands. */
899 DEFUN (no_router_bgp,
900 no_router_bgp_cmd,
901 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
902 NO_STR
903 ROUTER_STR
904 BGP_STR
905 AS_STR
906 BGP_INSTANCE_HELP_STR)
907 {
908 int idx_asn = 3;
909 int idx_vrf = 5;
910 as_t as;
911 struct bgp *bgp;
912 const char *name = NULL;
913
914 // "no router bgp" without an ASN
915 if (argc == 3) {
916 // Pending: Make VRF option available for ASN less config
917 bgp = bgp_get_default();
918
919 if (bgp == NULL) {
920 vty_out(vty, "%% No BGP process is configured\n");
921 return CMD_WARNING_CONFIG_FAILED;
922 }
923
924 if (listcount(bm->bgp) > 1) {
925 vty_out(vty, "%% Please specify ASN and VRF\n");
926 return CMD_WARNING_CONFIG_FAILED;
927 }
928
929 if (bgp->l3vni) {
930 vty_out(vty, "%% Please unconfigure l3vni %u",
931 bgp->l3vni);
932 return CMD_WARNING_CONFIG_FAILED;
933 }
934 } else {
935 as = strtoul(argv[idx_asn]->arg, NULL, 10);
936
937 if (argc > 4)
938 name = argv[idx_vrf]->arg;
939
940 /* Lookup bgp structure. */
941 bgp = bgp_lookup(as, name);
942 if (!bgp) {
943 vty_out(vty, "%% Can't find BGP instance\n");
944 return CMD_WARNING_CONFIG_FAILED;
945 }
946
947 if (bgp->l3vni) {
948 vty_out(vty, "%% Please unconfigure l3vni %u",
949 bgp->l3vni);
950 return CMD_WARNING_CONFIG_FAILED;
951 }
952 }
953
954 bgp_delete(bgp);
955
956 return CMD_SUCCESS;
957 }
958
959
960 /* BGP router-id. */
961
962 DEFPY (bgp_router_id,
963 bgp_router_id_cmd,
964 "bgp router-id A.B.C.D",
965 BGP_STR
966 "Override configured router identifier\n"
967 "Manually configured router identifier\n")
968 {
969 VTY_DECLVAR_CONTEXT(bgp, bgp);
970 bgp_router_id_static_set(bgp, router_id);
971 return CMD_SUCCESS;
972 }
973
974 DEFPY (no_bgp_router_id,
975 no_bgp_router_id_cmd,
976 "no bgp router-id [A.B.C.D]",
977 NO_STR
978 BGP_STR
979 "Override configured router identifier\n"
980 "Manually configured router identifier\n")
981 {
982 VTY_DECLVAR_CONTEXT(bgp, bgp);
983
984 if (router_id_str) {
985 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
986 vty_out(vty, "%% BGP router-id doesn't match\n");
987 return CMD_WARNING_CONFIG_FAILED;
988 }
989 }
990
991 router_id.s_addr = 0;
992 bgp_router_id_static_set(bgp, router_id);
993
994 return CMD_SUCCESS;
995 }
996
997
998 /* BGP Cluster ID. */
999 DEFUN (bgp_cluster_id,
1000 bgp_cluster_id_cmd,
1001 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
1002 BGP_STR
1003 "Configure Route-Reflector Cluster-id\n"
1004 "Route-Reflector Cluster-id in IP address format\n"
1005 "Route-Reflector Cluster-id as 32 bit quantity\n")
1006 {
1007 VTY_DECLVAR_CONTEXT(bgp, bgp);
1008 int idx_ipv4 = 2;
1009 int ret;
1010 struct in_addr cluster;
1011
1012 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1013 if (!ret) {
1014 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1015 return CMD_WARNING_CONFIG_FAILED;
1016 }
1017
1018 bgp_cluster_id_set(bgp, &cluster);
1019 bgp_clear_star_soft_out(vty, bgp->name);
1020
1021 return CMD_SUCCESS;
1022 }
1023
1024 DEFUN (no_bgp_cluster_id,
1025 no_bgp_cluster_id_cmd,
1026 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1027 NO_STR
1028 BGP_STR
1029 "Configure Route-Reflector Cluster-id\n"
1030 "Route-Reflector Cluster-id in IP address format\n"
1031 "Route-Reflector Cluster-id as 32 bit quantity\n")
1032 {
1033 VTY_DECLVAR_CONTEXT(bgp, bgp);
1034 bgp_cluster_id_unset(bgp);
1035 bgp_clear_star_soft_out(vty, bgp->name);
1036
1037 return CMD_SUCCESS;
1038 }
1039
1040 DEFUN (bgp_confederation_identifier,
1041 bgp_confederation_identifier_cmd,
1042 "bgp confederation identifier (1-4294967295)",
1043 "BGP specific commands\n"
1044 "AS confederation parameters\n"
1045 "AS number\n"
1046 "Set routing domain confederation AS\n")
1047 {
1048 VTY_DECLVAR_CONTEXT(bgp, bgp);
1049 int idx_number = 3;
1050 as_t as;
1051
1052 as = strtoul(argv[idx_number]->arg, NULL, 10);
1053
1054 bgp_confederation_id_set(bgp, as);
1055
1056 return CMD_SUCCESS;
1057 }
1058
1059 DEFUN (no_bgp_confederation_identifier,
1060 no_bgp_confederation_identifier_cmd,
1061 "no bgp confederation identifier [(1-4294967295)]",
1062 NO_STR
1063 "BGP specific commands\n"
1064 "AS confederation parameters\n"
1065 "AS number\n"
1066 "Set routing domain confederation AS\n")
1067 {
1068 VTY_DECLVAR_CONTEXT(bgp, bgp);
1069 bgp_confederation_id_unset(bgp);
1070
1071 return CMD_SUCCESS;
1072 }
1073
1074 DEFUN (bgp_confederation_peers,
1075 bgp_confederation_peers_cmd,
1076 "bgp confederation peers (1-4294967295)...",
1077 "BGP specific commands\n"
1078 "AS confederation parameters\n"
1079 "Peer ASs in BGP confederation\n"
1080 AS_STR)
1081 {
1082 VTY_DECLVAR_CONTEXT(bgp, bgp);
1083 int idx_asn = 3;
1084 as_t as;
1085 int i;
1086
1087 for (i = idx_asn; i < argc; i++) {
1088 as = strtoul(argv[i]->arg, NULL, 10);
1089
1090 if (bgp->as == as) {
1091 vty_out(vty,
1092 "%% Local member-AS not allowed in confed peer list\n");
1093 continue;
1094 }
1095
1096 bgp_confederation_peers_add(bgp, as);
1097 }
1098 return CMD_SUCCESS;
1099 }
1100
1101 DEFUN (no_bgp_confederation_peers,
1102 no_bgp_confederation_peers_cmd,
1103 "no bgp confederation peers (1-4294967295)...",
1104 NO_STR
1105 "BGP specific commands\n"
1106 "AS confederation parameters\n"
1107 "Peer ASs in BGP confederation\n"
1108 AS_STR)
1109 {
1110 VTY_DECLVAR_CONTEXT(bgp, bgp);
1111 int idx_asn = 4;
1112 as_t as;
1113 int i;
1114
1115 for (i = idx_asn; i < argc; i++) {
1116 as = strtoul(argv[i]->arg, NULL, 10);
1117
1118 bgp_confederation_peers_remove(bgp, as);
1119 }
1120 return CMD_SUCCESS;
1121 }
1122
1123 /**
1124 * Central routine for maximum-paths configuration.
1125 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1126 * @set: 1 for setting values, 0 for removing the max-paths config.
1127 */
1128 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1129 const char *mpaths, uint16_t options,
1130 int set)
1131 {
1132 VTY_DECLVAR_CONTEXT(bgp, bgp);
1133 uint16_t maxpaths = 0;
1134 int ret;
1135 afi_t afi;
1136 safi_t safi;
1137
1138 afi = bgp_node_afi(vty);
1139 safi = bgp_node_safi(vty);
1140
1141 if (set) {
1142 maxpaths = strtol(mpaths, NULL, 10);
1143 if (maxpaths > multipath_num) {
1144 vty_out(vty,
1145 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1146 maxpaths, multipath_num);
1147 return CMD_WARNING_CONFIG_FAILED;
1148 }
1149 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1150 options);
1151 } else
1152 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1153
1154 if (ret < 0) {
1155 vty_out(vty,
1156 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1157 (set == 1) ? "" : "un",
1158 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1159 maxpaths, afi, safi);
1160 return CMD_WARNING_CONFIG_FAILED;
1161 }
1162
1163 bgp_recalculate_all_bestpaths(bgp);
1164
1165 return CMD_SUCCESS;
1166 }
1167
1168 DEFUN (bgp_maxmed_admin,
1169 bgp_maxmed_admin_cmd,
1170 "bgp max-med administrative ",
1171 BGP_STR
1172 "Advertise routes with max-med\n"
1173 "Administratively applied, for an indefinite period\n")
1174 {
1175 VTY_DECLVAR_CONTEXT(bgp, bgp);
1176
1177 bgp->v_maxmed_admin = 1;
1178 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1179
1180 bgp_maxmed_update(bgp);
1181
1182 return CMD_SUCCESS;
1183 }
1184
1185 DEFUN (bgp_maxmed_admin_medv,
1186 bgp_maxmed_admin_medv_cmd,
1187 "bgp max-med administrative (0-4294967295)",
1188 BGP_STR
1189 "Advertise routes with max-med\n"
1190 "Administratively applied, for an indefinite period\n"
1191 "Max MED value to be used\n")
1192 {
1193 VTY_DECLVAR_CONTEXT(bgp, bgp);
1194 int idx_number = 3;
1195
1196 bgp->v_maxmed_admin = 1;
1197 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1198
1199 bgp_maxmed_update(bgp);
1200
1201 return CMD_SUCCESS;
1202 }
1203
1204 DEFUN (no_bgp_maxmed_admin,
1205 no_bgp_maxmed_admin_cmd,
1206 "no bgp max-med administrative [(0-4294967295)]",
1207 NO_STR
1208 BGP_STR
1209 "Advertise routes with max-med\n"
1210 "Administratively applied, for an indefinite period\n"
1211 "Max MED value to be used\n")
1212 {
1213 VTY_DECLVAR_CONTEXT(bgp, bgp);
1214 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1215 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1216 bgp_maxmed_update(bgp);
1217
1218 return CMD_SUCCESS;
1219 }
1220
1221 DEFUN (bgp_maxmed_onstartup,
1222 bgp_maxmed_onstartup_cmd,
1223 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1224 BGP_STR
1225 "Advertise routes with max-med\n"
1226 "Effective on a startup\n"
1227 "Time (seconds) period for max-med\n"
1228 "Max MED value to be used\n")
1229 {
1230 VTY_DECLVAR_CONTEXT(bgp, bgp);
1231 int idx = 0;
1232
1233 argv_find(argv, argc, "(5-86400)", &idx);
1234 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1235 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1236 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1237 else
1238 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1239
1240 bgp_maxmed_update(bgp);
1241
1242 return CMD_SUCCESS;
1243 }
1244
1245 DEFUN (no_bgp_maxmed_onstartup,
1246 no_bgp_maxmed_onstartup_cmd,
1247 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1248 NO_STR
1249 BGP_STR
1250 "Advertise routes with max-med\n"
1251 "Effective on a startup\n"
1252 "Time (seconds) period for max-med\n"
1253 "Max MED value to be used\n")
1254 {
1255 VTY_DECLVAR_CONTEXT(bgp, bgp);
1256
1257 /* Cancel max-med onstartup if its on */
1258 if (bgp->t_maxmed_onstartup) {
1259 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1260 bgp->maxmed_onstartup_over = 1;
1261 }
1262
1263 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1264 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1265
1266 bgp_maxmed_update(bgp);
1267
1268 return CMD_SUCCESS;
1269 }
1270
1271 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1272 const char *wait)
1273 {
1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
1275 uint16_t update_delay;
1276 uint16_t establish_wait;
1277
1278 update_delay = strtoul(delay, NULL, 10);
1279
1280 if (!wait) /* update-delay <delay> */
1281 {
1282 bgp->v_update_delay = update_delay;
1283 bgp->v_establish_wait = bgp->v_update_delay;
1284 return CMD_SUCCESS;
1285 }
1286
1287 /* update-delay <delay> <establish-wait> */
1288 establish_wait = atoi(wait);
1289 if (update_delay < establish_wait) {
1290 vty_out(vty,
1291 "%%Failed: update-delay less than the establish-wait!\n");
1292 return CMD_WARNING_CONFIG_FAILED;
1293 }
1294
1295 bgp->v_update_delay = update_delay;
1296 bgp->v_establish_wait = establish_wait;
1297
1298 return CMD_SUCCESS;
1299 }
1300
1301 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1302 {
1303 VTY_DECLVAR_CONTEXT(bgp, bgp);
1304
1305 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1306 bgp->v_establish_wait = bgp->v_update_delay;
1307
1308 return CMD_SUCCESS;
1309 }
1310
1311 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1312 {
1313 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1314 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1315 if (bgp->v_update_delay != bgp->v_establish_wait)
1316 vty_out(vty, " %d", bgp->v_establish_wait);
1317 vty_out(vty, "\n");
1318 }
1319 }
1320
1321
1322 /* Update-delay configuration */
1323 DEFUN (bgp_update_delay,
1324 bgp_update_delay_cmd,
1325 "update-delay (0-3600)",
1326 "Force initial delay for best-path and updates\n"
1327 "Seconds\n")
1328 {
1329 int idx_number = 1;
1330 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1331 }
1332
1333 DEFUN (bgp_update_delay_establish_wait,
1334 bgp_update_delay_establish_wait_cmd,
1335 "update-delay (0-3600) (1-3600)",
1336 "Force initial delay for best-path and updates\n"
1337 "Seconds\n"
1338 "Seconds\n")
1339 {
1340 int idx_number = 1;
1341 int idx_number_2 = 2;
1342 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1343 argv[idx_number_2]->arg);
1344 }
1345
1346 /* Update-delay deconfiguration */
1347 DEFUN (no_bgp_update_delay,
1348 no_bgp_update_delay_cmd,
1349 "no update-delay [(0-3600) [(1-3600)]]",
1350 NO_STR
1351 "Force initial delay for best-path and updates\n"
1352 "Seconds\n"
1353 "Seconds\n")
1354 {
1355 return bgp_update_delay_deconfig_vty(vty);
1356 }
1357
1358
1359 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1360 char set)
1361 {
1362 VTY_DECLVAR_CONTEXT(bgp, bgp);
1363
1364 if (set) {
1365 uint32_t quanta = strtoul(num, NULL, 10);
1366 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1367 memory_order_relaxed);
1368 } else {
1369 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1370 memory_order_relaxed);
1371 }
1372
1373 return CMD_SUCCESS;
1374 }
1375
1376 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1377 char set)
1378 {
1379 VTY_DECLVAR_CONTEXT(bgp, bgp);
1380
1381 if (set) {
1382 uint32_t quanta = strtoul(num, NULL, 10);
1383 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1384 memory_order_relaxed);
1385 } else {
1386 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1387 memory_order_relaxed);
1388 }
1389
1390 return CMD_SUCCESS;
1391 }
1392
1393 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1394 {
1395 uint32_t quanta =
1396 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1397 if (quanta != BGP_WRITE_PACKET_MAX)
1398 vty_out(vty, " write-quanta %d\n", quanta);
1399 }
1400
1401 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1402 {
1403 uint32_t quanta =
1404 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1405 if (quanta != BGP_READ_PACKET_MAX)
1406 vty_out(vty, " read-quanta %d\n", quanta);
1407 }
1408
1409 /* Packet quanta configuration */
1410 DEFUN (bgp_wpkt_quanta,
1411 bgp_wpkt_quanta_cmd,
1412 "write-quanta (1-10)",
1413 "How many packets to write to peer socket per run\n"
1414 "Number of packets\n")
1415 {
1416 int idx_number = 1;
1417 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1418 }
1419
1420 DEFUN (no_bgp_wpkt_quanta,
1421 no_bgp_wpkt_quanta_cmd,
1422 "no write-quanta (1-10)",
1423 NO_STR
1424 "How many packets to write to peer socket per I/O cycle\n"
1425 "Number of packets\n")
1426 {
1427 int idx_number = 2;
1428 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1429 }
1430
1431 DEFUN (bgp_rpkt_quanta,
1432 bgp_rpkt_quanta_cmd,
1433 "read-quanta (1-10)",
1434 "How many packets to read from peer socket per I/O cycle\n"
1435 "Number of packets\n")
1436 {
1437 int idx_number = 1;
1438 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1439 }
1440
1441 DEFUN (no_bgp_rpkt_quanta,
1442 no_bgp_rpkt_quanta_cmd,
1443 "no read-quanta (1-10)",
1444 NO_STR
1445 "How many packets to read from peer socket per I/O cycle\n"
1446 "Number of packets\n")
1447 {
1448 int idx_number = 2;
1449 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1450 }
1451
1452 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1453 {
1454 if (!bgp->heuristic_coalesce)
1455 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1456 }
1457
1458
1459 DEFUN (bgp_coalesce_time,
1460 bgp_coalesce_time_cmd,
1461 "coalesce-time (0-4294967295)",
1462 "Subgroup coalesce timer\n"
1463 "Subgroup coalesce timer value (in ms)\n")
1464 {
1465 VTY_DECLVAR_CONTEXT(bgp, bgp);
1466
1467 int idx = 0;
1468 argv_find(argv, argc, "(0-4294967295)", &idx);
1469 bgp->heuristic_coalesce = false;
1470 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1471 return CMD_SUCCESS;
1472 }
1473
1474 DEFUN (no_bgp_coalesce_time,
1475 no_bgp_coalesce_time_cmd,
1476 "no coalesce-time (0-4294967295)",
1477 NO_STR
1478 "Subgroup coalesce timer\n"
1479 "Subgroup coalesce timer value (in ms)\n")
1480 {
1481 VTY_DECLVAR_CONTEXT(bgp, bgp);
1482
1483 bgp->heuristic_coalesce = true;
1484 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1485 return CMD_SUCCESS;
1486 }
1487
1488 /* Maximum-paths configuration */
1489 DEFUN (bgp_maxpaths,
1490 bgp_maxpaths_cmd,
1491 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1492 "Forward packets over multiple paths\n"
1493 "Number of paths\n")
1494 {
1495 int idx_number = 1;
1496 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1497 argv[idx_number]->arg, 0, 1);
1498 }
1499
1500 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1501 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1502 "Forward packets over multiple paths\n"
1503 "Number of paths\n")
1504
1505 DEFUN (bgp_maxpaths_ibgp,
1506 bgp_maxpaths_ibgp_cmd,
1507 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1508 "Forward packets over multiple paths\n"
1509 "iBGP-multipath\n"
1510 "Number of paths\n")
1511 {
1512 int idx_number = 2;
1513 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1514 argv[idx_number]->arg, 0, 1);
1515 }
1516
1517 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1518 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1519 "Forward packets over multiple paths\n"
1520 "iBGP-multipath\n"
1521 "Number of paths\n")
1522
1523 DEFUN (bgp_maxpaths_ibgp_cluster,
1524 bgp_maxpaths_ibgp_cluster_cmd,
1525 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1526 "Forward packets over multiple paths\n"
1527 "iBGP-multipath\n"
1528 "Number of paths\n"
1529 "Match the cluster length\n")
1530 {
1531 int idx_number = 2;
1532 return bgp_maxpaths_config_vty(
1533 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1534 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1535 }
1536
1537 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1538 "maximum-paths ibgp " CMD_RANGE_STR(
1539 1, MULTIPATH_NUM) " equal-cluster-length",
1540 "Forward packets over multiple paths\n"
1541 "iBGP-multipath\n"
1542 "Number of paths\n"
1543 "Match the cluster length\n")
1544
1545 DEFUN (no_bgp_maxpaths,
1546 no_bgp_maxpaths_cmd,
1547 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1548 NO_STR
1549 "Forward packets over multiple paths\n"
1550 "Number of paths\n")
1551 {
1552 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1553 }
1554
1555 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1556 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1557 "Forward packets over multiple paths\n"
1558 "Number of paths\n")
1559
1560 DEFUN (no_bgp_maxpaths_ibgp,
1561 no_bgp_maxpaths_ibgp_cmd,
1562 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1563 NO_STR
1564 "Forward packets over multiple paths\n"
1565 "iBGP-multipath\n"
1566 "Number of paths\n"
1567 "Match the cluster length\n")
1568 {
1569 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1570 }
1571
1572 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1573 "no maximum-paths ibgp [" CMD_RANGE_STR(
1574 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1575 NO_STR
1576 "Forward packets over multiple paths\n"
1577 "iBGP-multipath\n"
1578 "Number of paths\n"
1579 "Match the cluster length\n")
1580
1581 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1582 safi_t safi)
1583 {
1584 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1585 vty_out(vty, " maximum-paths %d\n",
1586 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1587 }
1588
1589 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1590 vty_out(vty, " maximum-paths ibgp %d",
1591 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1592 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1593 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1594 vty_out(vty, " equal-cluster-length");
1595 vty_out(vty, "\n");
1596 }
1597 }
1598
1599 /* BGP timers. */
1600
1601 DEFUN (bgp_timers,
1602 bgp_timers_cmd,
1603 "timers bgp (0-65535) (0-65535)",
1604 "Adjust routing timers\n"
1605 "BGP timers\n"
1606 "Keepalive interval\n"
1607 "Holdtime\n")
1608 {
1609 VTY_DECLVAR_CONTEXT(bgp, bgp);
1610 int idx_number = 2;
1611 int idx_number_2 = 3;
1612 unsigned long keepalive = 0;
1613 unsigned long holdtime = 0;
1614
1615 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1616 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1617
1618 /* Holdtime value check. */
1619 if (holdtime < 3 && holdtime != 0) {
1620 vty_out(vty,
1621 "%% hold time value must be either 0 or greater than 3\n");
1622 return CMD_WARNING_CONFIG_FAILED;
1623 }
1624
1625 bgp_timers_set(bgp, keepalive, holdtime);
1626
1627 return CMD_SUCCESS;
1628 }
1629
1630 DEFUN (no_bgp_timers,
1631 no_bgp_timers_cmd,
1632 "no timers bgp [(0-65535) (0-65535)]",
1633 NO_STR
1634 "Adjust routing timers\n"
1635 "BGP timers\n"
1636 "Keepalive interval\n"
1637 "Holdtime\n")
1638 {
1639 VTY_DECLVAR_CONTEXT(bgp, bgp);
1640 bgp_timers_unset(bgp);
1641
1642 return CMD_SUCCESS;
1643 }
1644
1645
1646 DEFUN (bgp_client_to_client_reflection,
1647 bgp_client_to_client_reflection_cmd,
1648 "bgp client-to-client reflection",
1649 "BGP specific commands\n"
1650 "Configure client to client route reflection\n"
1651 "reflection of routes allowed\n")
1652 {
1653 VTY_DECLVAR_CONTEXT(bgp, bgp);
1654 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1655 bgp_clear_star_soft_out(vty, bgp->name);
1656
1657 return CMD_SUCCESS;
1658 }
1659
1660 DEFUN (no_bgp_client_to_client_reflection,
1661 no_bgp_client_to_client_reflection_cmd,
1662 "no bgp client-to-client reflection",
1663 NO_STR
1664 "BGP specific commands\n"
1665 "Configure client to client route reflection\n"
1666 "reflection of routes allowed\n")
1667 {
1668 VTY_DECLVAR_CONTEXT(bgp, bgp);
1669 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1670 bgp_clear_star_soft_out(vty, bgp->name);
1671
1672 return CMD_SUCCESS;
1673 }
1674
1675 /* "bgp always-compare-med" configuration. */
1676 DEFUN (bgp_always_compare_med,
1677 bgp_always_compare_med_cmd,
1678 "bgp always-compare-med",
1679 "BGP specific commands\n"
1680 "Allow comparing MED from different neighbors\n")
1681 {
1682 VTY_DECLVAR_CONTEXT(bgp, bgp);
1683 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1684 bgp_recalculate_all_bestpaths(bgp);
1685
1686 return CMD_SUCCESS;
1687 }
1688
1689 DEFUN (no_bgp_always_compare_med,
1690 no_bgp_always_compare_med_cmd,
1691 "no bgp always-compare-med",
1692 NO_STR
1693 "BGP specific commands\n"
1694 "Allow comparing MED from different neighbors\n")
1695 {
1696 VTY_DECLVAR_CONTEXT(bgp, bgp);
1697 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1698 bgp_recalculate_all_bestpaths(bgp);
1699
1700 return CMD_SUCCESS;
1701 }
1702
1703 /* "bgp deterministic-med" configuration. */
1704 DEFUN (bgp_deterministic_med,
1705 bgp_deterministic_med_cmd,
1706 "bgp deterministic-med",
1707 "BGP specific commands\n"
1708 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1709 {
1710 VTY_DECLVAR_CONTEXT(bgp, bgp);
1711
1712 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1713 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1714 bgp_recalculate_all_bestpaths(bgp);
1715 }
1716
1717 return CMD_SUCCESS;
1718 }
1719
1720 DEFUN (no_bgp_deterministic_med,
1721 no_bgp_deterministic_med_cmd,
1722 "no bgp deterministic-med",
1723 NO_STR
1724 "BGP specific commands\n"
1725 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1726 {
1727 VTY_DECLVAR_CONTEXT(bgp, bgp);
1728 int bestpath_per_as_used;
1729 afi_t afi;
1730 safi_t safi;
1731 struct peer *peer;
1732 struct listnode *node, *nnode;
1733
1734 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1735 bestpath_per_as_used = 0;
1736
1737 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1738 FOREACH_AFI_SAFI (afi, safi)
1739 if (CHECK_FLAG(
1740 peer->af_flags[afi][safi],
1741 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1742 bestpath_per_as_used = 1;
1743 break;
1744 }
1745
1746 if (bestpath_per_as_used)
1747 break;
1748 }
1749
1750 if (bestpath_per_as_used) {
1751 vty_out(vty,
1752 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1753 return CMD_WARNING_CONFIG_FAILED;
1754 } else {
1755 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1756 bgp_recalculate_all_bestpaths(bgp);
1757 }
1758 }
1759
1760 return CMD_SUCCESS;
1761 }
1762
1763 /* "bgp graceful-restart" configuration. */
1764 DEFUN (bgp_graceful_restart,
1765 bgp_graceful_restart_cmd,
1766 "bgp graceful-restart",
1767 "BGP specific commands\n"
1768 "Graceful restart capability parameters\n")
1769 {
1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1771 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1772 return CMD_SUCCESS;
1773 }
1774
1775 DEFUN (no_bgp_graceful_restart,
1776 no_bgp_graceful_restart_cmd,
1777 "no bgp graceful-restart",
1778 NO_STR
1779 "BGP specific commands\n"
1780 "Graceful restart capability parameters\n")
1781 {
1782 VTY_DECLVAR_CONTEXT(bgp, bgp);
1783 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1784 return CMD_SUCCESS;
1785 }
1786
1787 DEFUN (bgp_graceful_restart_stalepath_time,
1788 bgp_graceful_restart_stalepath_time_cmd,
1789 "bgp graceful-restart stalepath-time (1-3600)",
1790 "BGP specific commands\n"
1791 "Graceful restart capability parameters\n"
1792 "Set the max time to hold onto restarting peer's stale paths\n"
1793 "Delay value (seconds)\n")
1794 {
1795 VTY_DECLVAR_CONTEXT(bgp, bgp);
1796 int idx_number = 3;
1797 uint32_t stalepath;
1798
1799 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1800 bgp->stalepath_time = stalepath;
1801 return CMD_SUCCESS;
1802 }
1803
1804 DEFUN (bgp_graceful_restart_restart_time,
1805 bgp_graceful_restart_restart_time_cmd,
1806 "bgp graceful-restart restart-time (1-3600)",
1807 "BGP specific commands\n"
1808 "Graceful restart capability parameters\n"
1809 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1810 "Delay value (seconds)\n")
1811 {
1812 VTY_DECLVAR_CONTEXT(bgp, bgp);
1813 int idx_number = 3;
1814 uint32_t restart;
1815
1816 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1817 bgp->restart_time = restart;
1818 return CMD_SUCCESS;
1819 }
1820
1821 DEFUN (no_bgp_graceful_restart_stalepath_time,
1822 no_bgp_graceful_restart_stalepath_time_cmd,
1823 "no bgp graceful-restart stalepath-time [(1-3600)]",
1824 NO_STR
1825 "BGP specific commands\n"
1826 "Graceful restart capability parameters\n"
1827 "Set the max time to hold onto restarting peer's stale paths\n"
1828 "Delay value (seconds)\n")
1829 {
1830 VTY_DECLVAR_CONTEXT(bgp, bgp);
1831
1832 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1833 return CMD_SUCCESS;
1834 }
1835
1836 DEFUN (no_bgp_graceful_restart_restart_time,
1837 no_bgp_graceful_restart_restart_time_cmd,
1838 "no bgp graceful-restart restart-time [(1-3600)]",
1839 NO_STR
1840 "BGP specific commands\n"
1841 "Graceful restart capability parameters\n"
1842 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1843 "Delay value (seconds)\n")
1844 {
1845 VTY_DECLVAR_CONTEXT(bgp, bgp);
1846
1847 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1848 return CMD_SUCCESS;
1849 }
1850
1851 DEFUN (bgp_graceful_restart_preserve_fw,
1852 bgp_graceful_restart_preserve_fw_cmd,
1853 "bgp graceful-restart preserve-fw-state",
1854 "BGP specific commands\n"
1855 "Graceful restart capability parameters\n"
1856 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1857 {
1858 VTY_DECLVAR_CONTEXT(bgp, bgp);
1859 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1860 return CMD_SUCCESS;
1861 }
1862
1863 DEFUN (no_bgp_graceful_restart_preserve_fw,
1864 no_bgp_graceful_restart_preserve_fw_cmd,
1865 "no bgp graceful-restart preserve-fw-state",
1866 NO_STR
1867 "BGP specific commands\n"
1868 "Graceful restart capability parameters\n"
1869 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1870 {
1871 VTY_DECLVAR_CONTEXT(bgp, bgp);
1872 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1873 return CMD_SUCCESS;
1874 }
1875
1876 static void bgp_redistribute_redo(struct bgp *bgp)
1877 {
1878 afi_t afi;
1879 int i;
1880 struct list *red_list;
1881 struct listnode *node;
1882 struct bgp_redist *red;
1883
1884 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1885 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1886
1887 red_list = bgp->redist[afi][i];
1888 if (!red_list)
1889 continue;
1890
1891 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1892 bgp_redistribute_resend(bgp, afi, i,
1893 red->instance);
1894 }
1895 }
1896 }
1897 }
1898
1899 /* "bgp graceful-shutdown" configuration */
1900 DEFUN (bgp_graceful_shutdown,
1901 bgp_graceful_shutdown_cmd,
1902 "bgp graceful-shutdown",
1903 BGP_STR
1904 "Graceful shutdown parameters\n")
1905 {
1906 VTY_DECLVAR_CONTEXT(bgp, bgp);
1907
1908 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1909 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1910 bgp_static_redo_import_check(bgp);
1911 bgp_redistribute_redo(bgp);
1912 bgp_clear_star_soft_out(vty, bgp->name);
1913 bgp_clear_star_soft_in(vty, bgp->name);
1914 }
1915
1916 return CMD_SUCCESS;
1917 }
1918
1919 DEFUN (no_bgp_graceful_shutdown,
1920 no_bgp_graceful_shutdown_cmd,
1921 "no bgp graceful-shutdown",
1922 NO_STR
1923 BGP_STR
1924 "Graceful shutdown parameters\n")
1925 {
1926 VTY_DECLVAR_CONTEXT(bgp, bgp);
1927
1928 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1929 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1930 bgp_static_redo_import_check(bgp);
1931 bgp_redistribute_redo(bgp);
1932 bgp_clear_star_soft_out(vty, bgp->name);
1933 bgp_clear_star_soft_in(vty, bgp->name);
1934 }
1935
1936 return CMD_SUCCESS;
1937 }
1938
1939 /* "bgp fast-external-failover" configuration. */
1940 DEFUN (bgp_fast_external_failover,
1941 bgp_fast_external_failover_cmd,
1942 "bgp fast-external-failover",
1943 BGP_STR
1944 "Immediately reset session if a link to a directly connected external peer goes down\n")
1945 {
1946 VTY_DECLVAR_CONTEXT(bgp, bgp);
1947 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1948 return CMD_SUCCESS;
1949 }
1950
1951 DEFUN (no_bgp_fast_external_failover,
1952 no_bgp_fast_external_failover_cmd,
1953 "no bgp fast-external-failover",
1954 NO_STR
1955 BGP_STR
1956 "Immediately reset session if a link to a directly connected external peer goes down\n")
1957 {
1958 VTY_DECLVAR_CONTEXT(bgp, bgp);
1959 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1960 return CMD_SUCCESS;
1961 }
1962
1963 /* "bgp enforce-first-as" configuration. */
1964 DEFUN (bgp_enforce_first_as,
1965 bgp_enforce_first_as_cmd,
1966 "bgp enforce-first-as",
1967 BGP_STR
1968 "Enforce the first AS for EBGP routes\n")
1969 {
1970 VTY_DECLVAR_CONTEXT(bgp, bgp);
1971 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1972 bgp_clear_star_soft_in(vty, bgp->name);
1973
1974 return CMD_SUCCESS;
1975 }
1976
1977 DEFUN (no_bgp_enforce_first_as,
1978 no_bgp_enforce_first_as_cmd,
1979 "no bgp enforce-first-as",
1980 NO_STR
1981 BGP_STR
1982 "Enforce the first AS for EBGP routes\n")
1983 {
1984 VTY_DECLVAR_CONTEXT(bgp, bgp);
1985 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1986 bgp_clear_star_soft_in(vty, bgp->name);
1987
1988 return CMD_SUCCESS;
1989 }
1990
1991 /* "bgp bestpath compare-routerid" configuration. */
1992 DEFUN (bgp_bestpath_compare_router_id,
1993 bgp_bestpath_compare_router_id_cmd,
1994 "bgp bestpath compare-routerid",
1995 "BGP specific commands\n"
1996 "Change the default bestpath selection\n"
1997 "Compare router-id for identical EBGP paths\n")
1998 {
1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2001 bgp_recalculate_all_bestpaths(bgp);
2002
2003 return CMD_SUCCESS;
2004 }
2005
2006 DEFUN (no_bgp_bestpath_compare_router_id,
2007 no_bgp_bestpath_compare_router_id_cmd,
2008 "no bgp bestpath compare-routerid",
2009 NO_STR
2010 "BGP specific commands\n"
2011 "Change the default bestpath selection\n"
2012 "Compare router-id for identical EBGP paths\n")
2013 {
2014 VTY_DECLVAR_CONTEXT(bgp, bgp);
2015 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2016 bgp_recalculate_all_bestpaths(bgp);
2017
2018 return CMD_SUCCESS;
2019 }
2020
2021 /* "bgp bestpath as-path ignore" configuration. */
2022 DEFUN (bgp_bestpath_aspath_ignore,
2023 bgp_bestpath_aspath_ignore_cmd,
2024 "bgp bestpath as-path ignore",
2025 "BGP specific commands\n"
2026 "Change the default bestpath selection\n"
2027 "AS-path attribute\n"
2028 "Ignore as-path length in selecting a route\n")
2029 {
2030 VTY_DECLVAR_CONTEXT(bgp, bgp);
2031 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2032 bgp_recalculate_all_bestpaths(bgp);
2033
2034 return CMD_SUCCESS;
2035 }
2036
2037 DEFUN (no_bgp_bestpath_aspath_ignore,
2038 no_bgp_bestpath_aspath_ignore_cmd,
2039 "no bgp bestpath as-path ignore",
2040 NO_STR
2041 "BGP specific commands\n"
2042 "Change the default bestpath selection\n"
2043 "AS-path attribute\n"
2044 "Ignore as-path length in selecting a route\n")
2045 {
2046 VTY_DECLVAR_CONTEXT(bgp, bgp);
2047 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2048 bgp_recalculate_all_bestpaths(bgp);
2049
2050 return CMD_SUCCESS;
2051 }
2052
2053 /* "bgp bestpath as-path confed" configuration. */
2054 DEFUN (bgp_bestpath_aspath_confed,
2055 bgp_bestpath_aspath_confed_cmd,
2056 "bgp bestpath as-path confed",
2057 "BGP specific commands\n"
2058 "Change the default bestpath selection\n"
2059 "AS-path attribute\n"
2060 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2061 {
2062 VTY_DECLVAR_CONTEXT(bgp, bgp);
2063 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2064 bgp_recalculate_all_bestpaths(bgp);
2065
2066 return CMD_SUCCESS;
2067 }
2068
2069 DEFUN (no_bgp_bestpath_aspath_confed,
2070 no_bgp_bestpath_aspath_confed_cmd,
2071 "no bgp bestpath as-path confed",
2072 NO_STR
2073 "BGP specific commands\n"
2074 "Change the default bestpath selection\n"
2075 "AS-path attribute\n"
2076 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2077 {
2078 VTY_DECLVAR_CONTEXT(bgp, bgp);
2079 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2080 bgp_recalculate_all_bestpaths(bgp);
2081
2082 return CMD_SUCCESS;
2083 }
2084
2085 /* "bgp bestpath as-path multipath-relax" configuration. */
2086 DEFUN (bgp_bestpath_aspath_multipath_relax,
2087 bgp_bestpath_aspath_multipath_relax_cmd,
2088 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2089 "BGP specific commands\n"
2090 "Change the default bestpath selection\n"
2091 "AS-path attribute\n"
2092 "Allow load sharing across routes that have different AS paths (but same length)\n"
2093 "Generate an AS_SET\n"
2094 "Do not generate an AS_SET\n")
2095 {
2096 VTY_DECLVAR_CONTEXT(bgp, bgp);
2097 int idx = 0;
2098 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2099
2100 /* no-as-set is now the default behavior so we can silently
2101 * ignore it */
2102 if (argv_find(argv, argc, "as-set", &idx))
2103 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2104 else
2105 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2106
2107 bgp_recalculate_all_bestpaths(bgp);
2108
2109 return CMD_SUCCESS;
2110 }
2111
2112 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2113 no_bgp_bestpath_aspath_multipath_relax_cmd,
2114 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2115 NO_STR
2116 "BGP specific commands\n"
2117 "Change the default bestpath selection\n"
2118 "AS-path attribute\n"
2119 "Allow load sharing across routes that have different AS paths (but same length)\n"
2120 "Generate an AS_SET\n"
2121 "Do not generate an AS_SET\n")
2122 {
2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2125 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2126 bgp_recalculate_all_bestpaths(bgp);
2127
2128 return CMD_SUCCESS;
2129 }
2130
2131 /* "bgp log-neighbor-changes" configuration. */
2132 DEFUN (bgp_log_neighbor_changes,
2133 bgp_log_neighbor_changes_cmd,
2134 "bgp log-neighbor-changes",
2135 "BGP specific commands\n"
2136 "Log neighbor up/down and reset reason\n")
2137 {
2138 VTY_DECLVAR_CONTEXT(bgp, bgp);
2139 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2140 return CMD_SUCCESS;
2141 }
2142
2143 DEFUN (no_bgp_log_neighbor_changes,
2144 no_bgp_log_neighbor_changes_cmd,
2145 "no bgp log-neighbor-changes",
2146 NO_STR
2147 "BGP specific commands\n"
2148 "Log neighbor up/down and reset reason\n")
2149 {
2150 VTY_DECLVAR_CONTEXT(bgp, bgp);
2151 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2152 return CMD_SUCCESS;
2153 }
2154
2155 /* "bgp bestpath med" configuration. */
2156 DEFUN (bgp_bestpath_med,
2157 bgp_bestpath_med_cmd,
2158 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2159 "BGP specific commands\n"
2160 "Change the default bestpath selection\n"
2161 "MED attribute\n"
2162 "Compare MED among confederation paths\n"
2163 "Treat missing MED as the least preferred one\n"
2164 "Treat missing MED as the least preferred one\n"
2165 "Compare MED among confederation paths\n")
2166 {
2167 VTY_DECLVAR_CONTEXT(bgp, bgp);
2168
2169 int idx = 0;
2170 if (argv_find(argv, argc, "confed", &idx))
2171 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2172 idx = 0;
2173 if (argv_find(argv, argc, "missing-as-worst", &idx))
2174 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2175
2176 bgp_recalculate_all_bestpaths(bgp);
2177
2178 return CMD_SUCCESS;
2179 }
2180
2181 DEFUN (no_bgp_bestpath_med,
2182 no_bgp_bestpath_med_cmd,
2183 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2184 NO_STR
2185 "BGP specific commands\n"
2186 "Change the default bestpath selection\n"
2187 "MED attribute\n"
2188 "Compare MED among confederation paths\n"
2189 "Treat missing MED as the least preferred one\n"
2190 "Treat missing MED as the least preferred one\n"
2191 "Compare MED among confederation paths\n")
2192 {
2193 VTY_DECLVAR_CONTEXT(bgp, bgp);
2194
2195 int idx = 0;
2196 if (argv_find(argv, argc, "confed", &idx))
2197 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2198 idx = 0;
2199 if (argv_find(argv, argc, "missing-as-worst", &idx))
2200 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2201
2202 bgp_recalculate_all_bestpaths(bgp);
2203
2204 return CMD_SUCCESS;
2205 }
2206
2207 /* "no bgp default ipv4-unicast". */
2208 DEFUN (no_bgp_default_ipv4_unicast,
2209 no_bgp_default_ipv4_unicast_cmd,
2210 "no bgp default ipv4-unicast",
2211 NO_STR
2212 "BGP specific commands\n"
2213 "Configure BGP defaults\n"
2214 "Activate ipv4-unicast for a peer by default\n")
2215 {
2216 VTY_DECLVAR_CONTEXT(bgp, bgp);
2217 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2218 return CMD_SUCCESS;
2219 }
2220
2221 DEFUN (bgp_default_ipv4_unicast,
2222 bgp_default_ipv4_unicast_cmd,
2223 "bgp default ipv4-unicast",
2224 "BGP specific commands\n"
2225 "Configure BGP defaults\n"
2226 "Activate ipv4-unicast for a peer by default\n")
2227 {
2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2230 return CMD_SUCCESS;
2231 }
2232
2233 /* Display hostname in certain command outputs */
2234 DEFUN (bgp_default_show_hostname,
2235 bgp_default_show_hostname_cmd,
2236 "bgp default show-hostname",
2237 "BGP specific commands\n"
2238 "Configure BGP defaults\n"
2239 "Show hostname in certain command ouputs\n")
2240 {
2241 VTY_DECLVAR_CONTEXT(bgp, bgp);
2242 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2243 return CMD_SUCCESS;
2244 }
2245
2246 DEFUN (no_bgp_default_show_hostname,
2247 no_bgp_default_show_hostname_cmd,
2248 "no bgp default show-hostname",
2249 NO_STR
2250 "BGP specific commands\n"
2251 "Configure BGP defaults\n"
2252 "Show hostname in certain command ouputs\n")
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2256 return CMD_SUCCESS;
2257 }
2258
2259 /* "bgp network import-check" configuration. */
2260 DEFUN (bgp_network_import_check,
2261 bgp_network_import_check_cmd,
2262 "bgp network import-check",
2263 "BGP specific commands\n"
2264 "BGP network command\n"
2265 "Check BGP network route exists in IGP\n")
2266 {
2267 VTY_DECLVAR_CONTEXT(bgp, bgp);
2268 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2269 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2270 bgp_static_redo_import_check(bgp);
2271 }
2272
2273 return CMD_SUCCESS;
2274 }
2275
2276 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2277 "bgp network import-check exact",
2278 "BGP specific commands\n"
2279 "BGP network command\n"
2280 "Check BGP network route exists in IGP\n"
2281 "Match route precisely\n")
2282
2283 DEFUN (no_bgp_network_import_check,
2284 no_bgp_network_import_check_cmd,
2285 "no bgp network import-check",
2286 NO_STR
2287 "BGP specific commands\n"
2288 "BGP network command\n"
2289 "Check BGP network route exists in IGP\n")
2290 {
2291 VTY_DECLVAR_CONTEXT(bgp, bgp);
2292 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2293 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2294 bgp_static_redo_import_check(bgp);
2295 }
2296
2297 return CMD_SUCCESS;
2298 }
2299
2300 DEFUN (bgp_default_local_preference,
2301 bgp_default_local_preference_cmd,
2302 "bgp default local-preference (0-4294967295)",
2303 "BGP specific commands\n"
2304 "Configure BGP defaults\n"
2305 "local preference (higher=more preferred)\n"
2306 "Configure default local preference value\n")
2307 {
2308 VTY_DECLVAR_CONTEXT(bgp, bgp);
2309 int idx_number = 3;
2310 uint32_t local_pref;
2311
2312 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2313
2314 bgp_default_local_preference_set(bgp, local_pref);
2315 bgp_clear_star_soft_in(vty, bgp->name);
2316
2317 return CMD_SUCCESS;
2318 }
2319
2320 DEFUN (no_bgp_default_local_preference,
2321 no_bgp_default_local_preference_cmd,
2322 "no bgp default local-preference [(0-4294967295)]",
2323 NO_STR
2324 "BGP specific commands\n"
2325 "Configure BGP defaults\n"
2326 "local preference (higher=more preferred)\n"
2327 "Configure default local preference value\n")
2328 {
2329 VTY_DECLVAR_CONTEXT(bgp, bgp);
2330 bgp_default_local_preference_unset(bgp);
2331 bgp_clear_star_soft_in(vty, bgp->name);
2332
2333 return CMD_SUCCESS;
2334 }
2335
2336
2337 DEFUN (bgp_default_subgroup_pkt_queue_max,
2338 bgp_default_subgroup_pkt_queue_max_cmd,
2339 "bgp default subgroup-pkt-queue-max (20-100)",
2340 "BGP specific commands\n"
2341 "Configure BGP defaults\n"
2342 "subgroup-pkt-queue-max\n"
2343 "Configure subgroup packet queue max\n")
2344 {
2345 VTY_DECLVAR_CONTEXT(bgp, bgp);
2346 int idx_number = 3;
2347 uint32_t max_size;
2348
2349 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2350
2351 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2352
2353 return CMD_SUCCESS;
2354 }
2355
2356 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2357 no_bgp_default_subgroup_pkt_queue_max_cmd,
2358 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2359 NO_STR
2360 "BGP specific commands\n"
2361 "Configure BGP defaults\n"
2362 "subgroup-pkt-queue-max\n"
2363 "Configure subgroup packet queue max\n")
2364 {
2365 VTY_DECLVAR_CONTEXT(bgp, bgp);
2366 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2367 return CMD_SUCCESS;
2368 }
2369
2370
2371 DEFUN (bgp_rr_allow_outbound_policy,
2372 bgp_rr_allow_outbound_policy_cmd,
2373 "bgp route-reflector allow-outbound-policy",
2374 "BGP specific commands\n"
2375 "Allow modifications made by out route-map\n"
2376 "on ibgp neighbors\n")
2377 {
2378 VTY_DECLVAR_CONTEXT(bgp, bgp);
2379
2380 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2381 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2382 update_group_announce_rrclients(bgp);
2383 bgp_clear_star_soft_out(vty, bgp->name);
2384 }
2385
2386 return CMD_SUCCESS;
2387 }
2388
2389 DEFUN (no_bgp_rr_allow_outbound_policy,
2390 no_bgp_rr_allow_outbound_policy_cmd,
2391 "no bgp route-reflector allow-outbound-policy",
2392 NO_STR
2393 "BGP specific commands\n"
2394 "Allow modifications made by out route-map\n"
2395 "on ibgp neighbors\n")
2396 {
2397 VTY_DECLVAR_CONTEXT(bgp, bgp);
2398
2399 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2400 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2401 update_group_announce_rrclients(bgp);
2402 bgp_clear_star_soft_out(vty, bgp->name);
2403 }
2404
2405 return CMD_SUCCESS;
2406 }
2407
2408 DEFUN (bgp_listen_limit,
2409 bgp_listen_limit_cmd,
2410 "bgp listen limit (1-5000)",
2411 "BGP specific commands\n"
2412 "Configure BGP defaults\n"
2413 "maximum number of BGP Dynamic Neighbors that can be created\n"
2414 "Configure Dynamic Neighbors listen limit value\n")
2415 {
2416 VTY_DECLVAR_CONTEXT(bgp, bgp);
2417 int idx_number = 3;
2418 int listen_limit;
2419
2420 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2421
2422 bgp_listen_limit_set(bgp, listen_limit);
2423
2424 return CMD_SUCCESS;
2425 }
2426
2427 DEFUN (no_bgp_listen_limit,
2428 no_bgp_listen_limit_cmd,
2429 "no bgp listen limit [(1-5000)]",
2430 "BGP specific commands\n"
2431 "Configure BGP defaults\n"
2432 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2433 "Configure Dynamic Neighbors listen limit value to default\n"
2434 "Configure Dynamic Neighbors listen limit value\n")
2435 {
2436 VTY_DECLVAR_CONTEXT(bgp, bgp);
2437 bgp_listen_limit_unset(bgp);
2438 return CMD_SUCCESS;
2439 }
2440
2441
2442 /*
2443 * Check if this listen range is already configured. Check for exact
2444 * match or overlap based on input.
2445 */
2446 static struct peer_group *listen_range_exists(struct bgp *bgp,
2447 struct prefix *range, int exact)
2448 {
2449 struct listnode *node, *nnode;
2450 struct listnode *node1, *nnode1;
2451 struct peer_group *group;
2452 struct prefix *lr;
2453 afi_t afi;
2454 int match;
2455
2456 afi = family2afi(range->family);
2457 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2458 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2459 lr)) {
2460 if (exact)
2461 match = prefix_same(range, lr);
2462 else
2463 match = (prefix_match(range, lr)
2464 || prefix_match(lr, range));
2465 if (match)
2466 return group;
2467 }
2468 }
2469
2470 return NULL;
2471 }
2472
2473 DEFUN (bgp_listen_range,
2474 bgp_listen_range_cmd,
2475 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2476 "BGP specific commands\n"
2477 "Configure BGP dynamic neighbors listen range\n"
2478 "Configure BGP dynamic neighbors listen range\n"
2479 NEIGHBOR_ADDR_STR
2480 "Member of the peer-group\n"
2481 "Peer-group name\n")
2482 {
2483 VTY_DECLVAR_CONTEXT(bgp, bgp);
2484 struct prefix range;
2485 struct peer_group *group, *existing_group;
2486 afi_t afi;
2487 int ret;
2488 int idx = 0;
2489
2490 argv_find(argv, argc, "A.B.C.D/M", &idx);
2491 argv_find(argv, argc, "X:X::X:X/M", &idx);
2492 char *prefix = argv[idx]->arg;
2493 argv_find(argv, argc, "WORD", &idx);
2494 char *peergroup = argv[idx]->arg;
2495
2496 /* Convert IP prefix string to struct prefix. */
2497 ret = str2prefix(prefix, &range);
2498 if (!ret) {
2499 vty_out(vty, "%% Malformed listen range\n");
2500 return CMD_WARNING_CONFIG_FAILED;
2501 }
2502
2503 afi = family2afi(range.family);
2504
2505 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2506 vty_out(vty,
2507 "%% Malformed listen range (link-local address)\n");
2508 return CMD_WARNING_CONFIG_FAILED;
2509 }
2510
2511 apply_mask(&range);
2512
2513 /* Check if same listen range is already configured. */
2514 existing_group = listen_range_exists(bgp, &range, 1);
2515 if (existing_group) {
2516 if (strcmp(existing_group->name, peergroup) == 0)
2517 return CMD_SUCCESS;
2518 else {
2519 vty_out(vty,
2520 "%% Same listen range is attached to peer-group %s\n",
2521 existing_group->name);
2522 return CMD_WARNING_CONFIG_FAILED;
2523 }
2524 }
2525
2526 /* Check if an overlapping listen range exists. */
2527 if (listen_range_exists(bgp, &range, 0)) {
2528 vty_out(vty,
2529 "%% Listen range overlaps with existing listen range\n");
2530 return CMD_WARNING_CONFIG_FAILED;
2531 }
2532
2533 group = peer_group_lookup(bgp, peergroup);
2534 if (!group) {
2535 vty_out(vty, "%% Configure the peer-group first\n");
2536 return CMD_WARNING_CONFIG_FAILED;
2537 }
2538
2539 ret = peer_group_listen_range_add(group, &range);
2540 return bgp_vty_return(vty, ret);
2541 }
2542
2543 DEFUN (no_bgp_listen_range,
2544 no_bgp_listen_range_cmd,
2545 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2546 NO_STR
2547 "BGP specific commands\n"
2548 "Unconfigure BGP dynamic neighbors listen range\n"
2549 "Unconfigure BGP dynamic neighbors listen range\n"
2550 NEIGHBOR_ADDR_STR
2551 "Member of the peer-group\n"
2552 "Peer-group name\n")
2553 {
2554 VTY_DECLVAR_CONTEXT(bgp, bgp);
2555 struct prefix range;
2556 struct peer_group *group;
2557 afi_t afi;
2558 int ret;
2559 int idx = 0;
2560
2561 argv_find(argv, argc, "A.B.C.D/M", &idx);
2562 argv_find(argv, argc, "X:X::X:X/M", &idx);
2563 char *prefix = argv[idx]->arg;
2564 argv_find(argv, argc, "WORD", &idx);
2565 char *peergroup = argv[idx]->arg;
2566
2567 /* Convert IP prefix string to struct prefix. */
2568 ret = str2prefix(prefix, &range);
2569 if (!ret) {
2570 vty_out(vty, "%% Malformed listen range\n");
2571 return CMD_WARNING_CONFIG_FAILED;
2572 }
2573
2574 afi = family2afi(range.family);
2575
2576 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2577 vty_out(vty,
2578 "%% Malformed listen range (link-local address)\n");
2579 return CMD_WARNING_CONFIG_FAILED;
2580 }
2581
2582 apply_mask(&range);
2583
2584 group = peer_group_lookup(bgp, peergroup);
2585 if (!group) {
2586 vty_out(vty, "%% Peer-group does not exist\n");
2587 return CMD_WARNING_CONFIG_FAILED;
2588 }
2589
2590 ret = peer_group_listen_range_del(group, &range);
2591 return bgp_vty_return(vty, ret);
2592 }
2593
2594 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2595 {
2596 struct peer_group *group;
2597 struct listnode *node, *nnode, *rnode, *nrnode;
2598 struct prefix *range;
2599 afi_t afi;
2600 char buf[PREFIX2STR_BUFFER];
2601
2602 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2603 vty_out(vty, " bgp listen limit %d\n",
2604 bgp->dynamic_neighbors_limit);
2605
2606 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2607 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2608 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2609 nrnode, range)) {
2610 prefix2str(range, buf, sizeof(buf));
2611 vty_out(vty,
2612 " bgp listen range %s peer-group %s\n",
2613 buf, group->name);
2614 }
2615 }
2616 }
2617 }
2618
2619
2620 DEFUN (bgp_disable_connected_route_check,
2621 bgp_disable_connected_route_check_cmd,
2622 "bgp disable-ebgp-connected-route-check",
2623 "BGP specific commands\n"
2624 "Disable checking if nexthop is connected on ebgp sessions\n")
2625 {
2626 VTY_DECLVAR_CONTEXT(bgp, bgp);
2627 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2628 bgp_clear_star_soft_in(vty, bgp->name);
2629
2630 return CMD_SUCCESS;
2631 }
2632
2633 DEFUN (no_bgp_disable_connected_route_check,
2634 no_bgp_disable_connected_route_check_cmd,
2635 "no bgp disable-ebgp-connected-route-check",
2636 NO_STR
2637 "BGP specific commands\n"
2638 "Disable checking if nexthop is connected on ebgp sessions\n")
2639 {
2640 VTY_DECLVAR_CONTEXT(bgp, bgp);
2641 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2642 bgp_clear_star_soft_in(vty, bgp->name);
2643
2644 return CMD_SUCCESS;
2645 }
2646
2647
2648 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2649 const char *as_str, afi_t afi, safi_t safi)
2650 {
2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
2652 int ret;
2653 as_t as;
2654 int as_type = AS_SPECIFIED;
2655 union sockunion su;
2656
2657 if (as_str[0] == 'i') {
2658 as = 0;
2659 as_type = AS_INTERNAL;
2660 } else if (as_str[0] == 'e') {
2661 as = 0;
2662 as_type = AS_EXTERNAL;
2663 } else {
2664 /* Get AS number. */
2665 as = strtoul(as_str, NULL, 10);
2666 }
2667
2668 /* If peer is peer group, call proper function. */
2669 ret = str2sockunion(peer_str, &su);
2670 if (ret < 0) {
2671 /* Check for peer by interface */
2672 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2673 safi);
2674 if (ret < 0) {
2675 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2676 if (ret < 0) {
2677 vty_out(vty,
2678 "%% Create the peer-group or interface first\n");
2679 return CMD_WARNING_CONFIG_FAILED;
2680 }
2681 return CMD_SUCCESS;
2682 }
2683 } else {
2684 if (peer_address_self_check(bgp, &su)) {
2685 vty_out(vty,
2686 "%% Can not configure the local system as neighbor\n");
2687 return CMD_WARNING_CONFIG_FAILED;
2688 }
2689 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2690 }
2691
2692 /* This peer belongs to peer group. */
2693 switch (ret) {
2694 case BGP_ERR_PEER_GROUP_MEMBER:
2695 vty_out(vty,
2696 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2697 as);
2698 return CMD_WARNING_CONFIG_FAILED;
2699 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2700 vty_out(vty,
2701 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2702 as, as_str);
2703 return CMD_WARNING_CONFIG_FAILED;
2704 }
2705 return bgp_vty_return(vty, ret);
2706 }
2707
2708 DEFUN (bgp_default_shutdown,
2709 bgp_default_shutdown_cmd,
2710 "[no] bgp default shutdown",
2711 NO_STR
2712 BGP_STR
2713 "Configure BGP defaults\n"
2714 "Apply administrative shutdown to newly configured peers\n")
2715 {
2716 VTY_DECLVAR_CONTEXT(bgp, bgp);
2717 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2718 return CMD_SUCCESS;
2719 }
2720
2721 DEFUN (neighbor_remote_as,
2722 neighbor_remote_as_cmd,
2723 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2724 NEIGHBOR_STR
2725 NEIGHBOR_ADDR_STR2
2726 "Specify a BGP neighbor\n"
2727 AS_STR
2728 "Internal BGP peer\n"
2729 "External BGP peer\n")
2730 {
2731 int idx_peer = 1;
2732 int idx_remote_as = 3;
2733 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2734 argv[idx_remote_as]->arg, AFI_IP,
2735 SAFI_UNICAST);
2736 }
2737
2738 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2739 afi_t afi, safi_t safi, int v6only,
2740 const char *peer_group_name,
2741 const char *as_str)
2742 {
2743 VTY_DECLVAR_CONTEXT(bgp, bgp);
2744 as_t as = 0;
2745 int as_type = AS_UNSPECIFIED;
2746 struct peer *peer;
2747 struct peer_group *group;
2748 int ret = 0;
2749 union sockunion su;
2750
2751 group = peer_group_lookup(bgp, conf_if);
2752
2753 if (group) {
2754 vty_out(vty, "%% Name conflict with peer-group \n");
2755 return CMD_WARNING_CONFIG_FAILED;
2756 }
2757
2758 if (as_str) {
2759 if (as_str[0] == 'i') {
2760 as_type = AS_INTERNAL;
2761 } else if (as_str[0] == 'e') {
2762 as_type = AS_EXTERNAL;
2763 } else {
2764 /* Get AS number. */
2765 as = strtoul(as_str, NULL, 10);
2766 as_type = AS_SPECIFIED;
2767 }
2768 }
2769
2770 peer = peer_lookup_by_conf_if(bgp, conf_if);
2771 if (peer) {
2772 if (as_str)
2773 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2774 afi, safi);
2775 } else {
2776 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2777 && afi == AFI_IP && safi == SAFI_UNICAST)
2778 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2779 as_type, 0, 0, NULL);
2780 else
2781 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2782 as_type, afi, safi, NULL);
2783
2784 if (!peer) {
2785 vty_out(vty, "%% BGP failed to create peer\n");
2786 return CMD_WARNING_CONFIG_FAILED;
2787 }
2788
2789 if (v6only)
2790 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2791
2792 /* Request zebra to initiate IPv6 RAs on this interface. We do
2793 * this
2794 * any unnumbered peer in order to not worry about run-time
2795 * transitions
2796 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2797 * address
2798 * gets deleted later etc.)
2799 */
2800 if (peer->ifp)
2801 bgp_zebra_initiate_radv(bgp, peer);
2802 }
2803
2804 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2805 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2806 if (v6only)
2807 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2808 else
2809 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2810
2811 /* v6only flag changed. Reset bgp seesion */
2812 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2813 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2814 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2815 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2816 } else
2817 bgp_session_reset(peer);
2818 }
2819
2820 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2821 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2822
2823 if (peer_group_name) {
2824 group = peer_group_lookup(bgp, peer_group_name);
2825 if (!group) {
2826 vty_out(vty, "%% Configure the peer-group first\n");
2827 return CMD_WARNING_CONFIG_FAILED;
2828 }
2829
2830 ret = peer_group_bind(bgp, &su, peer, group, &as);
2831 }
2832
2833 return bgp_vty_return(vty, ret);
2834 }
2835
2836 DEFUN (neighbor_interface_config,
2837 neighbor_interface_config_cmd,
2838 "neighbor WORD interface [peer-group WORD]",
2839 NEIGHBOR_STR
2840 "Interface name or neighbor tag\n"
2841 "Enable BGP on interface\n"
2842 "Member of the peer-group\n"
2843 "Peer-group name\n")
2844 {
2845 int idx_word = 1;
2846 int idx_peer_group_word = 4;
2847
2848 if (argc > idx_peer_group_word)
2849 return peer_conf_interface_get(
2850 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2851 argv[idx_peer_group_word]->arg, NULL);
2852 else
2853 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2854 SAFI_UNICAST, 0, NULL, NULL);
2855 }
2856
2857 DEFUN (neighbor_interface_config_v6only,
2858 neighbor_interface_config_v6only_cmd,
2859 "neighbor WORD interface v6only [peer-group WORD]",
2860 NEIGHBOR_STR
2861 "Interface name or neighbor tag\n"
2862 "Enable BGP on interface\n"
2863 "Enable BGP with v6 link-local only\n"
2864 "Member of the peer-group\n"
2865 "Peer-group name\n")
2866 {
2867 int idx_word = 1;
2868 int idx_peer_group_word = 5;
2869
2870 if (argc > idx_peer_group_word)
2871 return peer_conf_interface_get(
2872 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2873 argv[idx_peer_group_word]->arg, NULL);
2874
2875 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2876 SAFI_UNICAST, 1, NULL, NULL);
2877 }
2878
2879
2880 DEFUN (neighbor_interface_config_remote_as,
2881 neighbor_interface_config_remote_as_cmd,
2882 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2883 NEIGHBOR_STR
2884 "Interface name or neighbor tag\n"
2885 "Enable BGP on interface\n"
2886 "Specify a BGP neighbor\n"
2887 AS_STR
2888 "Internal BGP peer\n"
2889 "External BGP peer\n")
2890 {
2891 int idx_word = 1;
2892 int idx_remote_as = 4;
2893 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2894 SAFI_UNICAST, 0, NULL,
2895 argv[idx_remote_as]->arg);
2896 }
2897
2898 DEFUN (neighbor_interface_v6only_config_remote_as,
2899 neighbor_interface_v6only_config_remote_as_cmd,
2900 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2901 NEIGHBOR_STR
2902 "Interface name or neighbor tag\n"
2903 "Enable BGP with v6 link-local only\n"
2904 "Enable BGP on interface\n"
2905 "Specify a BGP neighbor\n"
2906 AS_STR
2907 "Internal BGP peer\n"
2908 "External BGP peer\n")
2909 {
2910 int idx_word = 1;
2911 int idx_remote_as = 5;
2912 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2913 SAFI_UNICAST, 1, NULL,
2914 argv[idx_remote_as]->arg);
2915 }
2916
2917 DEFUN (neighbor_peer_group,
2918 neighbor_peer_group_cmd,
2919 "neighbor WORD peer-group",
2920 NEIGHBOR_STR
2921 "Interface name or neighbor tag\n"
2922 "Configure peer-group\n")
2923 {
2924 VTY_DECLVAR_CONTEXT(bgp, bgp);
2925 int idx_word = 1;
2926 struct peer *peer;
2927 struct peer_group *group;
2928
2929 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2930 if (peer) {
2931 vty_out(vty, "%% Name conflict with interface: \n");
2932 return CMD_WARNING_CONFIG_FAILED;
2933 }
2934
2935 group = peer_group_get(bgp, argv[idx_word]->arg);
2936 if (!group) {
2937 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2938 return CMD_WARNING_CONFIG_FAILED;
2939 }
2940
2941 return CMD_SUCCESS;
2942 }
2943
2944 DEFUN (no_neighbor,
2945 no_neighbor_cmd,
2946 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2947 NO_STR
2948 NEIGHBOR_STR
2949 NEIGHBOR_ADDR_STR2
2950 "Specify a BGP neighbor\n"
2951 AS_STR
2952 "Internal BGP peer\n"
2953 "External BGP peer\n")
2954 {
2955 VTY_DECLVAR_CONTEXT(bgp, bgp);
2956 int idx_peer = 2;
2957 int ret;
2958 union sockunion su;
2959 struct peer_group *group;
2960 struct peer *peer;
2961 struct peer *other;
2962
2963 ret = str2sockunion(argv[idx_peer]->arg, &su);
2964 if (ret < 0) {
2965 /* look up for neighbor by interface name config. */
2966 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2967 if (peer) {
2968 /* Request zebra to terminate IPv6 RAs on this
2969 * interface. */
2970 if (peer->ifp)
2971 bgp_zebra_terminate_radv(peer->bgp, peer);
2972 peer_delete(peer);
2973 return CMD_SUCCESS;
2974 }
2975
2976 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2977 if (group)
2978 peer_group_delete(group);
2979 else {
2980 vty_out(vty, "%% Create the peer-group first\n");
2981 return CMD_WARNING_CONFIG_FAILED;
2982 }
2983 } else {
2984 peer = peer_lookup(bgp, &su);
2985 if (peer) {
2986 if (peer_dynamic_neighbor(peer)) {
2987 vty_out(vty,
2988 "%% Operation not allowed on a dynamic neighbor\n");
2989 return CMD_WARNING_CONFIG_FAILED;
2990 }
2991
2992 other = peer->doppelganger;
2993 peer_delete(peer);
2994 if (other && other->status != Deleted)
2995 peer_delete(other);
2996 }
2997 }
2998
2999 return CMD_SUCCESS;
3000 }
3001
3002 DEFUN (no_neighbor_interface_config,
3003 no_neighbor_interface_config_cmd,
3004 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
3005 NO_STR
3006 NEIGHBOR_STR
3007 "Interface name\n"
3008 "Configure BGP on interface\n"
3009 "Enable BGP with v6 link-local only\n"
3010 "Member of the peer-group\n"
3011 "Peer-group name\n"
3012 "Specify a BGP neighbor\n"
3013 AS_STR
3014 "Internal BGP peer\n"
3015 "External BGP peer\n")
3016 {
3017 VTY_DECLVAR_CONTEXT(bgp, bgp);
3018 int idx_word = 2;
3019 struct peer *peer;
3020
3021 /* look up for neighbor by interface name config. */
3022 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3023 if (peer) {
3024 /* Request zebra to terminate IPv6 RAs on this interface. */
3025 if (peer->ifp)
3026 bgp_zebra_terminate_radv(peer->bgp, peer);
3027 peer_delete(peer);
3028 } else {
3029 vty_out(vty, "%% Create the bgp interface first\n");
3030 return CMD_WARNING_CONFIG_FAILED;
3031 }
3032 return CMD_SUCCESS;
3033 }
3034
3035 DEFUN (no_neighbor_peer_group,
3036 no_neighbor_peer_group_cmd,
3037 "no neighbor WORD peer-group",
3038 NO_STR
3039 NEIGHBOR_STR
3040 "Neighbor tag\n"
3041 "Configure peer-group\n")
3042 {
3043 VTY_DECLVAR_CONTEXT(bgp, bgp);
3044 int idx_word = 2;
3045 struct peer_group *group;
3046
3047 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3048 if (group)
3049 peer_group_delete(group);
3050 else {
3051 vty_out(vty, "%% Create the peer-group first\n");
3052 return CMD_WARNING_CONFIG_FAILED;
3053 }
3054 return CMD_SUCCESS;
3055 }
3056
3057 DEFUN (no_neighbor_interface_peer_group_remote_as,
3058 no_neighbor_interface_peer_group_remote_as_cmd,
3059 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3060 NO_STR
3061 NEIGHBOR_STR
3062 "Interface name or neighbor tag\n"
3063 "Specify a BGP neighbor\n"
3064 AS_STR
3065 "Internal BGP peer\n"
3066 "External BGP peer\n")
3067 {
3068 VTY_DECLVAR_CONTEXT(bgp, bgp);
3069 int idx_word = 2;
3070 struct peer_group *group;
3071 struct peer *peer;
3072
3073 /* look up for neighbor by interface name config. */
3074 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3075 if (peer) {
3076 peer_as_change(peer, 0, AS_SPECIFIED);
3077 return CMD_SUCCESS;
3078 }
3079
3080 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3081 if (group)
3082 peer_group_remote_as_delete(group);
3083 else {
3084 vty_out(vty, "%% Create the peer-group or interface first\n");
3085 return CMD_WARNING_CONFIG_FAILED;
3086 }
3087 return CMD_SUCCESS;
3088 }
3089
3090 DEFUN (neighbor_local_as,
3091 neighbor_local_as_cmd,
3092 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3093 NEIGHBOR_STR
3094 NEIGHBOR_ADDR_STR2
3095 "Specify a local-as number\n"
3096 "AS number used as local AS\n")
3097 {
3098 int idx_peer = 1;
3099 int idx_number = 3;
3100 struct peer *peer;
3101 int ret;
3102 as_t as;
3103
3104 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3105 if (!peer)
3106 return CMD_WARNING_CONFIG_FAILED;
3107
3108 as = strtoul(argv[idx_number]->arg, NULL, 10);
3109 ret = peer_local_as_set(peer, as, 0, 0);
3110 return bgp_vty_return(vty, ret);
3111 }
3112
3113 DEFUN (neighbor_local_as_no_prepend,
3114 neighbor_local_as_no_prepend_cmd,
3115 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3116 NEIGHBOR_STR
3117 NEIGHBOR_ADDR_STR2
3118 "Specify a local-as number\n"
3119 "AS number used as local AS\n"
3120 "Do not prepend local-as to updates from ebgp peers\n")
3121 {
3122 int idx_peer = 1;
3123 int idx_number = 3;
3124 struct peer *peer;
3125 int ret;
3126 as_t as;
3127
3128 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3129 if (!peer)
3130 return CMD_WARNING_CONFIG_FAILED;
3131
3132 as = strtoul(argv[idx_number]->arg, NULL, 10);
3133 ret = peer_local_as_set(peer, as, 1, 0);
3134 return bgp_vty_return(vty, ret);
3135 }
3136
3137 DEFUN (neighbor_local_as_no_prepend_replace_as,
3138 neighbor_local_as_no_prepend_replace_as_cmd,
3139 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3140 NEIGHBOR_STR
3141 NEIGHBOR_ADDR_STR2
3142 "Specify a local-as number\n"
3143 "AS number used as local AS\n"
3144 "Do not prepend local-as to updates from ebgp peers\n"
3145 "Do not prepend local-as to updates from ibgp peers\n")
3146 {
3147 int idx_peer = 1;
3148 int idx_number = 3;
3149 struct peer *peer;
3150 int ret;
3151 as_t as;
3152
3153 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3154 if (!peer)
3155 return CMD_WARNING_CONFIG_FAILED;
3156
3157 as = strtoul(argv[idx_number]->arg, NULL, 10);
3158 ret = peer_local_as_set(peer, as, 1, 1);
3159 return bgp_vty_return(vty, ret);
3160 }
3161
3162 DEFUN (no_neighbor_local_as,
3163 no_neighbor_local_as_cmd,
3164 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3165 NO_STR
3166 NEIGHBOR_STR
3167 NEIGHBOR_ADDR_STR2
3168 "Specify a local-as number\n"
3169 "AS number used as local AS\n"
3170 "Do not prepend local-as to updates from ebgp peers\n"
3171 "Do not prepend local-as to updates from ibgp peers\n")
3172 {
3173 int idx_peer = 2;
3174 struct peer *peer;
3175 int ret;
3176
3177 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3178 if (!peer)
3179 return CMD_WARNING_CONFIG_FAILED;
3180
3181 ret = peer_local_as_unset(peer);
3182 return bgp_vty_return(vty, ret);
3183 }
3184
3185
3186 DEFUN (neighbor_solo,
3187 neighbor_solo_cmd,
3188 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3189 NEIGHBOR_STR
3190 NEIGHBOR_ADDR_STR2
3191 "Solo peer - part of its own update group\n")
3192 {
3193 int idx_peer = 1;
3194 struct peer *peer;
3195 int ret;
3196
3197 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3198 if (!peer)
3199 return CMD_WARNING_CONFIG_FAILED;
3200
3201 ret = update_group_adjust_soloness(peer, 1);
3202 return bgp_vty_return(vty, ret);
3203 }
3204
3205 DEFUN (no_neighbor_solo,
3206 no_neighbor_solo_cmd,
3207 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3208 NO_STR
3209 NEIGHBOR_STR
3210 NEIGHBOR_ADDR_STR2
3211 "Solo peer - part of its own update group\n")
3212 {
3213 int idx_peer = 2;
3214 struct peer *peer;
3215 int ret;
3216
3217 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3218 if (!peer)
3219 return CMD_WARNING_CONFIG_FAILED;
3220
3221 ret = update_group_adjust_soloness(peer, 0);
3222 return bgp_vty_return(vty, ret);
3223 }
3224
3225 DEFUN (neighbor_password,
3226 neighbor_password_cmd,
3227 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3228 NEIGHBOR_STR
3229 NEIGHBOR_ADDR_STR2
3230 "Set a password\n"
3231 "The password\n")
3232 {
3233 int idx_peer = 1;
3234 int idx_line = 3;
3235 struct peer *peer;
3236 int ret;
3237
3238 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3239 if (!peer)
3240 return CMD_WARNING_CONFIG_FAILED;
3241
3242 ret = peer_password_set(peer, argv[idx_line]->arg);
3243 return bgp_vty_return(vty, ret);
3244 }
3245
3246 DEFUN (no_neighbor_password,
3247 no_neighbor_password_cmd,
3248 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3249 NO_STR
3250 NEIGHBOR_STR
3251 NEIGHBOR_ADDR_STR2
3252 "Set a password\n"
3253 "The password\n")
3254 {
3255 int idx_peer = 2;
3256 struct peer *peer;
3257 int ret;
3258
3259 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3260 if (!peer)
3261 return CMD_WARNING_CONFIG_FAILED;
3262
3263 ret = peer_password_unset(peer);
3264 return bgp_vty_return(vty, ret);
3265 }
3266
3267 DEFUN (neighbor_activate,
3268 neighbor_activate_cmd,
3269 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3270 NEIGHBOR_STR
3271 NEIGHBOR_ADDR_STR2
3272 "Enable the Address Family for this Neighbor\n")
3273 {
3274 int idx_peer = 1;
3275 int ret;
3276 struct peer *peer;
3277
3278 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3279 if (!peer)
3280 return CMD_WARNING_CONFIG_FAILED;
3281
3282 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3283 return bgp_vty_return(vty, ret);
3284 }
3285
3286 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3287 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3288 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3289 "Enable the Address Family for this Neighbor\n")
3290
3291 DEFUN (no_neighbor_activate,
3292 no_neighbor_activate_cmd,
3293 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3294 NO_STR
3295 NEIGHBOR_STR
3296 NEIGHBOR_ADDR_STR2
3297 "Enable the Address Family for this Neighbor\n")
3298 {
3299 int idx_peer = 2;
3300 int ret;
3301 struct peer *peer;
3302
3303 /* Lookup peer. */
3304 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3305 if (!peer)
3306 return CMD_WARNING_CONFIG_FAILED;
3307
3308 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3309 return bgp_vty_return(vty, ret);
3310 }
3311
3312 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3313 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3314 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3315 "Enable the Address Family for this Neighbor\n")
3316
3317 DEFUN (neighbor_set_peer_group,
3318 neighbor_set_peer_group_cmd,
3319 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3320 NEIGHBOR_STR
3321 NEIGHBOR_ADDR_STR2
3322 "Member of the peer-group\n"
3323 "Peer-group name\n")
3324 {
3325 VTY_DECLVAR_CONTEXT(bgp, bgp);
3326 int idx_peer = 1;
3327 int idx_word = 3;
3328 int ret;
3329 as_t as;
3330 union sockunion su;
3331 struct peer *peer;
3332 struct peer_group *group;
3333
3334 peer = NULL;
3335
3336 ret = str2sockunion(argv[idx_peer]->arg, &su);
3337 if (ret < 0) {
3338 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3339 if (!peer) {
3340 vty_out(vty, "%% Malformed address or name: %s\n",
3341 argv[idx_peer]->arg);
3342 return CMD_WARNING_CONFIG_FAILED;
3343 }
3344 } else {
3345 if (peer_address_self_check(bgp, &su)) {
3346 vty_out(vty,
3347 "%% Can not configure the local system as neighbor\n");
3348 return CMD_WARNING_CONFIG_FAILED;
3349 }
3350
3351 /* Disallow for dynamic neighbor. */
3352 peer = peer_lookup(bgp, &su);
3353 if (peer && peer_dynamic_neighbor(peer)) {
3354 vty_out(vty,
3355 "%% Operation not allowed on a dynamic neighbor\n");
3356 return CMD_WARNING_CONFIG_FAILED;
3357 }
3358 }
3359
3360 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3361 if (!group) {
3362 vty_out(vty, "%% Configure the peer-group first\n");
3363 return CMD_WARNING_CONFIG_FAILED;
3364 }
3365
3366 ret = peer_group_bind(bgp, &su, peer, group, &as);
3367
3368 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3369 vty_out(vty,
3370 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3371 as);
3372 return CMD_WARNING_CONFIG_FAILED;
3373 }
3374
3375 return bgp_vty_return(vty, ret);
3376 }
3377
3378 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3379 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3380 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3381 "Member of the peer-group\n"
3382 "Peer-group name\n")
3383
3384 DEFUN (no_neighbor_set_peer_group,
3385 no_neighbor_set_peer_group_cmd,
3386 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3387 NO_STR
3388 NEIGHBOR_STR
3389 NEIGHBOR_ADDR_STR2
3390 "Member of the peer-group\n"
3391 "Peer-group name\n")
3392 {
3393 VTY_DECLVAR_CONTEXT(bgp, bgp);
3394 int idx_peer = 2;
3395 int idx_word = 4;
3396 int ret;
3397 struct peer *peer;
3398 struct peer_group *group;
3399
3400 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3401 if (!peer)
3402 return CMD_WARNING_CONFIG_FAILED;
3403
3404 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3405 if (!group) {
3406 vty_out(vty, "%% Configure the peer-group first\n");
3407 return CMD_WARNING_CONFIG_FAILED;
3408 }
3409
3410 ret = peer_delete(peer);
3411
3412 return bgp_vty_return(vty, ret);
3413 }
3414
3415 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3416 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3417 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3418 "Member of the peer-group\n"
3419 "Peer-group name\n")
3420
3421 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3422 uint16_t flag, int set)
3423 {
3424 int ret;
3425 struct peer *peer;
3426
3427 peer = peer_and_group_lookup_vty(vty, ip_str);
3428 if (!peer)
3429 return CMD_WARNING_CONFIG_FAILED;
3430
3431 /*
3432 * If 'neighbor <interface>', then this is for directly connected peers,
3433 * we should not accept disable-connected-check.
3434 */
3435 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3436 vty_out(vty,
3437 "%s is directly connected peer, cannot accept disable-"
3438 "connected-check\n",
3439 ip_str);
3440 return CMD_WARNING_CONFIG_FAILED;
3441 }
3442
3443 if (!set && flag == PEER_FLAG_SHUTDOWN)
3444 peer_tx_shutdown_message_unset(peer);
3445
3446 if (set)
3447 ret = peer_flag_set(peer, flag);
3448 else
3449 ret = peer_flag_unset(peer, flag);
3450
3451 return bgp_vty_return(vty, ret);
3452 }
3453
3454 static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint16_t flag)
3455 {
3456 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3457 }
3458
3459 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3460 uint16_t flag)
3461 {
3462 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3463 }
3464
3465 /* neighbor passive. */
3466 DEFUN (neighbor_passive,
3467 neighbor_passive_cmd,
3468 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3469 NEIGHBOR_STR
3470 NEIGHBOR_ADDR_STR2
3471 "Don't send open messages to this neighbor\n")
3472 {
3473 int idx_peer = 1;
3474 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3475 }
3476
3477 DEFUN (no_neighbor_passive,
3478 no_neighbor_passive_cmd,
3479 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3480 NO_STR
3481 NEIGHBOR_STR
3482 NEIGHBOR_ADDR_STR2
3483 "Don't send open messages to this neighbor\n")
3484 {
3485 int idx_peer = 2;
3486 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3487 }
3488
3489 /* neighbor shutdown. */
3490 DEFUN (neighbor_shutdown_msg,
3491 neighbor_shutdown_msg_cmd,
3492 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3493 NEIGHBOR_STR
3494 NEIGHBOR_ADDR_STR2
3495 "Administratively shut down this neighbor\n"
3496 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3497 "Shutdown message\n")
3498 {
3499 int idx_peer = 1;
3500
3501 if (argc >= 5) {
3502 struct peer *peer =
3503 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3504 char *message;
3505
3506 if (!peer)
3507 return CMD_WARNING_CONFIG_FAILED;
3508 message = argv_concat(argv, argc, 4);
3509 peer_tx_shutdown_message_set(peer, message);
3510 XFREE(MTYPE_TMP, message);
3511 }
3512
3513 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3514 }
3515
3516 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3517 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3518 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3519 "Administratively shut down this neighbor\n")
3520
3521 DEFUN (no_neighbor_shutdown_msg,
3522 no_neighbor_shutdown_msg_cmd,
3523 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3524 NO_STR
3525 NEIGHBOR_STR
3526 NEIGHBOR_ADDR_STR2
3527 "Administratively shut down this neighbor\n"
3528 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3529 "Shutdown message\n")
3530 {
3531 int idx_peer = 2;
3532
3533 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3534 PEER_FLAG_SHUTDOWN);
3535 }
3536
3537 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3538 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3539 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3540 "Administratively shut down this neighbor\n")
3541
3542 /* neighbor capability dynamic. */
3543 DEFUN (neighbor_capability_dynamic,
3544 neighbor_capability_dynamic_cmd,
3545 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3546 NEIGHBOR_STR
3547 NEIGHBOR_ADDR_STR2
3548 "Advertise capability to the peer\n"
3549 "Advertise dynamic capability to this neighbor\n")
3550 {
3551 int idx_peer = 1;
3552 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3553 PEER_FLAG_DYNAMIC_CAPABILITY);
3554 }
3555
3556 DEFUN (no_neighbor_capability_dynamic,
3557 no_neighbor_capability_dynamic_cmd,
3558 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3559 NO_STR
3560 NEIGHBOR_STR
3561 NEIGHBOR_ADDR_STR2
3562 "Advertise capability to the peer\n"
3563 "Advertise dynamic capability to this neighbor\n")
3564 {
3565 int idx_peer = 2;
3566 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3567 PEER_FLAG_DYNAMIC_CAPABILITY);
3568 }
3569
3570 /* neighbor dont-capability-negotiate */
3571 DEFUN (neighbor_dont_capability_negotiate,
3572 neighbor_dont_capability_negotiate_cmd,
3573 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3574 NEIGHBOR_STR
3575 NEIGHBOR_ADDR_STR2
3576 "Do not perform capability negotiation\n")
3577 {
3578 int idx_peer = 1;
3579 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3580 PEER_FLAG_DONT_CAPABILITY);
3581 }
3582
3583 DEFUN (no_neighbor_dont_capability_negotiate,
3584 no_neighbor_dont_capability_negotiate_cmd,
3585 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3586 NO_STR
3587 NEIGHBOR_STR
3588 NEIGHBOR_ADDR_STR2
3589 "Do not perform capability negotiation\n")
3590 {
3591 int idx_peer = 2;
3592 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3593 PEER_FLAG_DONT_CAPABILITY);
3594 }
3595
3596 /* neighbor capability extended next hop encoding */
3597 DEFUN (neighbor_capability_enhe,
3598 neighbor_capability_enhe_cmd,
3599 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3600 NEIGHBOR_STR
3601 NEIGHBOR_ADDR_STR2
3602 "Advertise capability to the peer\n"
3603 "Advertise extended next-hop capability to the peer\n")
3604 {
3605 int idx_peer = 1;
3606 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3607 PEER_FLAG_CAPABILITY_ENHE);
3608 }
3609
3610 DEFUN (no_neighbor_capability_enhe,
3611 no_neighbor_capability_enhe_cmd,
3612 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3613 NO_STR
3614 NEIGHBOR_STR
3615 NEIGHBOR_ADDR_STR2
3616 "Advertise capability to the peer\n"
3617 "Advertise extended next-hop capability to the peer\n")
3618 {
3619 int idx_peer = 2;
3620 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3621 PEER_FLAG_CAPABILITY_ENHE);
3622 }
3623
3624 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3625 afi_t afi, safi_t safi, uint32_t flag,
3626 int set)
3627 {
3628 int ret;
3629 struct peer *peer;
3630
3631 peer = peer_and_group_lookup_vty(vty, peer_str);
3632 if (!peer)
3633 return CMD_WARNING_CONFIG_FAILED;
3634
3635 if (set)
3636 ret = peer_af_flag_set(peer, afi, safi, flag);
3637 else
3638 ret = peer_af_flag_unset(peer, afi, safi, flag);
3639
3640 return bgp_vty_return(vty, ret);
3641 }
3642
3643 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3644 afi_t afi, safi_t safi, uint32_t flag)
3645 {
3646 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3647 }
3648
3649 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3650 afi_t afi, safi_t safi, uint32_t flag)
3651 {
3652 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3653 }
3654
3655 /* neighbor capability orf prefix-list. */
3656 DEFUN (neighbor_capability_orf_prefix,
3657 neighbor_capability_orf_prefix_cmd,
3658 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3659 NEIGHBOR_STR
3660 NEIGHBOR_ADDR_STR2
3661 "Advertise capability to the peer\n"
3662 "Advertise ORF capability to the peer\n"
3663 "Advertise prefixlist ORF capability to this neighbor\n"
3664 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3665 "Capability to RECEIVE the ORF from this neighbor\n"
3666 "Capability to SEND the ORF to this neighbor\n")
3667 {
3668 int idx_peer = 1;
3669 int idx_send_recv = 5;
3670 uint16_t flag = 0;
3671
3672 if (strmatch(argv[idx_send_recv]->text, "send"))
3673 flag = PEER_FLAG_ORF_PREFIX_SM;
3674 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3675 flag = PEER_FLAG_ORF_PREFIX_RM;
3676 else if (strmatch(argv[idx_send_recv]->text, "both"))
3677 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3678 else {
3679 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3680 return CMD_WARNING_CONFIG_FAILED;
3681 }
3682
3683 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3684 bgp_node_safi(vty), flag);
3685 }
3686
3687 ALIAS_HIDDEN(
3688 neighbor_capability_orf_prefix,
3689 neighbor_capability_orf_prefix_hidden_cmd,
3690 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3691 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3692 "Advertise capability to the peer\n"
3693 "Advertise ORF capability to the peer\n"
3694 "Advertise prefixlist ORF capability to this neighbor\n"
3695 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3696 "Capability to RECEIVE the ORF from this neighbor\n"
3697 "Capability to SEND the ORF to this neighbor\n")
3698
3699 DEFUN (no_neighbor_capability_orf_prefix,
3700 no_neighbor_capability_orf_prefix_cmd,
3701 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3702 NO_STR
3703 NEIGHBOR_STR
3704 NEIGHBOR_ADDR_STR2
3705 "Advertise capability to the peer\n"
3706 "Advertise ORF capability to the peer\n"
3707 "Advertise prefixlist ORF capability to this neighbor\n"
3708 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3709 "Capability to RECEIVE the ORF from this neighbor\n"
3710 "Capability to SEND the ORF to this neighbor\n")
3711 {
3712 int idx_peer = 2;
3713 int idx_send_recv = 6;
3714 uint16_t flag = 0;
3715
3716 if (strmatch(argv[idx_send_recv]->text, "send"))
3717 flag = PEER_FLAG_ORF_PREFIX_SM;
3718 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3719 flag = PEER_FLAG_ORF_PREFIX_RM;
3720 else if (strmatch(argv[idx_send_recv]->text, "both"))
3721 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3722 else {
3723 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3724 return CMD_WARNING_CONFIG_FAILED;
3725 }
3726
3727 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3728 bgp_node_afi(vty), bgp_node_safi(vty),
3729 flag);
3730 }
3731
3732 ALIAS_HIDDEN(
3733 no_neighbor_capability_orf_prefix,
3734 no_neighbor_capability_orf_prefix_hidden_cmd,
3735 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3736 NO_STR NEIGHBOR_STR 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 /* neighbor next-hop-self. */
3745 DEFUN (neighbor_nexthop_self,
3746 neighbor_nexthop_self_cmd,
3747 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3748 NEIGHBOR_STR
3749 NEIGHBOR_ADDR_STR2
3750 "Disable the next hop calculation for this neighbor\n")
3751 {
3752 int idx_peer = 1;
3753 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3754 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3755 }
3756
3757 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3758 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3759 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3760 "Disable the next hop calculation for this neighbor\n")
3761
3762 /* neighbor next-hop-self. */
3763 DEFUN (neighbor_nexthop_self_force,
3764 neighbor_nexthop_self_force_cmd,
3765 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3766 NEIGHBOR_STR
3767 NEIGHBOR_ADDR_STR2
3768 "Disable the next hop calculation for this neighbor\n"
3769 "Set the next hop to self for reflected routes\n")
3770 {
3771 int idx_peer = 1;
3772 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3773 bgp_node_safi(vty),
3774 PEER_FLAG_FORCE_NEXTHOP_SELF);
3775 }
3776
3777 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3778 neighbor_nexthop_self_force_hidden_cmd,
3779 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3780 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3781 "Disable the next hop calculation for this neighbor\n"
3782 "Set the next hop to self for reflected routes\n")
3783
3784 DEFUN (no_neighbor_nexthop_self,
3785 no_neighbor_nexthop_self_cmd,
3786 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3787 NO_STR
3788 NEIGHBOR_STR
3789 NEIGHBOR_ADDR_STR2
3790 "Disable the next hop calculation for this neighbor\n")
3791 {
3792 int idx_peer = 2;
3793 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3794 bgp_node_afi(vty), bgp_node_safi(vty),
3795 PEER_FLAG_NEXTHOP_SELF);
3796 }
3797
3798 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3799 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3800 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3801 "Disable the next hop calculation for this neighbor\n")
3802
3803 DEFUN (no_neighbor_nexthop_self_force,
3804 no_neighbor_nexthop_self_force_cmd,
3805 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3806 NO_STR
3807 NEIGHBOR_STR
3808 NEIGHBOR_ADDR_STR2
3809 "Disable the next hop calculation for this neighbor\n"
3810 "Set the next hop to self for reflected routes\n")
3811 {
3812 int idx_peer = 2;
3813 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3814 bgp_node_afi(vty), bgp_node_safi(vty),
3815 PEER_FLAG_FORCE_NEXTHOP_SELF);
3816 }
3817
3818 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3819 no_neighbor_nexthop_self_force_hidden_cmd,
3820 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3821 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3822 "Disable the next hop calculation for this neighbor\n"
3823 "Set the next hop to self for reflected routes\n")
3824
3825 /* neighbor as-override */
3826 DEFUN (neighbor_as_override,
3827 neighbor_as_override_cmd,
3828 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3829 NEIGHBOR_STR
3830 NEIGHBOR_ADDR_STR2
3831 "Override ASNs in outbound updates if aspath equals remote-as\n")
3832 {
3833 int idx_peer = 1;
3834 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3835 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3836 }
3837
3838 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3839 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3840 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3841 "Override ASNs in outbound updates if aspath equals remote-as\n")
3842
3843 DEFUN (no_neighbor_as_override,
3844 no_neighbor_as_override_cmd,
3845 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3846 NO_STR
3847 NEIGHBOR_STR
3848 NEIGHBOR_ADDR_STR2
3849 "Override ASNs in outbound updates if aspath equals remote-as\n")
3850 {
3851 int idx_peer = 2;
3852 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3853 bgp_node_afi(vty), bgp_node_safi(vty),
3854 PEER_FLAG_AS_OVERRIDE);
3855 }
3856
3857 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3858 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3859 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3860 "Override ASNs in outbound updates if aspath equals remote-as\n")
3861
3862 /* neighbor remove-private-AS. */
3863 DEFUN (neighbor_remove_private_as,
3864 neighbor_remove_private_as_cmd,
3865 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3866 NEIGHBOR_STR
3867 NEIGHBOR_ADDR_STR2
3868 "Remove private ASNs in outbound updates\n")
3869 {
3870 int idx_peer = 1;
3871 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3872 bgp_node_safi(vty),
3873 PEER_FLAG_REMOVE_PRIVATE_AS);
3874 }
3875
3876 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3877 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3878 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3879 "Remove private ASNs in outbound updates\n")
3880
3881 DEFUN (neighbor_remove_private_as_all,
3882 neighbor_remove_private_as_all_cmd,
3883 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3884 NEIGHBOR_STR
3885 NEIGHBOR_ADDR_STR2
3886 "Remove private ASNs in outbound updates\n"
3887 "Apply to all AS numbers\n")
3888 {
3889 int idx_peer = 1;
3890 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3891 bgp_node_safi(vty),
3892 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3893 }
3894
3895 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3896 neighbor_remove_private_as_all_hidden_cmd,
3897 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3898 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3899 "Remove private ASNs in outbound updates\n"
3900 "Apply to all AS numbers")
3901
3902 DEFUN (neighbor_remove_private_as_replace_as,
3903 neighbor_remove_private_as_replace_as_cmd,
3904 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3905 NEIGHBOR_STR
3906 NEIGHBOR_ADDR_STR2
3907 "Remove private ASNs in outbound updates\n"
3908 "Replace private ASNs with our ASN in outbound updates\n")
3909 {
3910 int idx_peer = 1;
3911 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3912 bgp_node_safi(vty),
3913 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3914 }
3915
3916 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3917 neighbor_remove_private_as_replace_as_hidden_cmd,
3918 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3919 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3920 "Remove private ASNs in outbound updates\n"
3921 "Replace private ASNs with our ASN in outbound updates\n")
3922
3923 DEFUN (neighbor_remove_private_as_all_replace_as,
3924 neighbor_remove_private_as_all_replace_as_cmd,
3925 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3926 NEIGHBOR_STR
3927 NEIGHBOR_ADDR_STR2
3928 "Remove private ASNs in outbound updates\n"
3929 "Apply to all AS numbers\n"
3930 "Replace private ASNs with our ASN in outbound updates\n")
3931 {
3932 int idx_peer = 1;
3933 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3934 bgp_node_safi(vty),
3935 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3936 }
3937
3938 ALIAS_HIDDEN(
3939 neighbor_remove_private_as_all_replace_as,
3940 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3941 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3942 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3943 "Remove private ASNs in outbound updates\n"
3944 "Apply to all AS numbers\n"
3945 "Replace private ASNs with our ASN in outbound updates\n")
3946
3947 DEFUN (no_neighbor_remove_private_as,
3948 no_neighbor_remove_private_as_cmd,
3949 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3950 NO_STR
3951 NEIGHBOR_STR
3952 NEIGHBOR_ADDR_STR2
3953 "Remove private ASNs in outbound updates\n")
3954 {
3955 int idx_peer = 2;
3956 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3957 bgp_node_afi(vty), bgp_node_safi(vty),
3958 PEER_FLAG_REMOVE_PRIVATE_AS);
3959 }
3960
3961 ALIAS_HIDDEN(no_neighbor_remove_private_as,
3962 no_neighbor_remove_private_as_hidden_cmd,
3963 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3964 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3965 "Remove private ASNs in outbound updates\n")
3966
3967 DEFUN (no_neighbor_remove_private_as_all,
3968 no_neighbor_remove_private_as_all_cmd,
3969 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3970 NO_STR
3971 NEIGHBOR_STR
3972 NEIGHBOR_ADDR_STR2
3973 "Remove private ASNs in outbound updates\n"
3974 "Apply to all AS numbers\n")
3975 {
3976 int idx_peer = 2;
3977 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3978 bgp_node_afi(vty), bgp_node_safi(vty),
3979 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3980 }
3981
3982 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3983 no_neighbor_remove_private_as_all_hidden_cmd,
3984 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3985 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3986 "Remove private ASNs in outbound updates\n"
3987 "Apply to all AS numbers\n")
3988
3989 DEFUN (no_neighbor_remove_private_as_replace_as,
3990 no_neighbor_remove_private_as_replace_as_cmd,
3991 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3992 NO_STR
3993 NEIGHBOR_STR
3994 NEIGHBOR_ADDR_STR2
3995 "Remove private ASNs in outbound updates\n"
3996 "Replace private ASNs with our ASN in outbound updates\n")
3997 {
3998 int idx_peer = 2;
3999 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4000 bgp_node_afi(vty), bgp_node_safi(vty),
4001 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4002 }
4003
4004 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
4005 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4006 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4007 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4008 "Remove private ASNs in outbound updates\n"
4009 "Replace private ASNs with our ASN in outbound updates\n")
4010
4011 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4012 no_neighbor_remove_private_as_all_replace_as_cmd,
4013 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4014 NO_STR
4015 NEIGHBOR_STR
4016 NEIGHBOR_ADDR_STR2
4017 "Remove private ASNs in outbound updates\n"
4018 "Apply to all AS numbers\n"
4019 "Replace private ASNs with our ASN in outbound updates\n")
4020 {
4021 int idx_peer = 2;
4022 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4023 bgp_node_afi(vty), bgp_node_safi(vty),
4024 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4025 }
4026
4027 ALIAS_HIDDEN(
4028 no_neighbor_remove_private_as_all_replace_as,
4029 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4030 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4031 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4032 "Remove private ASNs in outbound updates\n"
4033 "Apply to all AS numbers\n"
4034 "Replace private ASNs with our ASN in outbound updates\n")
4035
4036
4037 /* neighbor send-community. */
4038 DEFUN (neighbor_send_community,
4039 neighbor_send_community_cmd,
4040 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4041 NEIGHBOR_STR
4042 NEIGHBOR_ADDR_STR2
4043 "Send Community attribute to this neighbor\n")
4044 {
4045 int idx_peer = 1;
4046 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4047 bgp_node_safi(vty),
4048 PEER_FLAG_SEND_COMMUNITY);
4049 }
4050
4051 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4052 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4053 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4054 "Send Community attribute to this neighbor\n")
4055
4056 DEFUN (no_neighbor_send_community,
4057 no_neighbor_send_community_cmd,
4058 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4059 NO_STR
4060 NEIGHBOR_STR
4061 NEIGHBOR_ADDR_STR2
4062 "Send Community attribute to this neighbor\n")
4063 {
4064 int idx_peer = 2;
4065 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4066 bgp_node_afi(vty), bgp_node_safi(vty),
4067 PEER_FLAG_SEND_COMMUNITY);
4068 }
4069
4070 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4071 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4072 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4073 "Send Community attribute to this neighbor\n")
4074
4075 /* neighbor send-community extended. */
4076 DEFUN (neighbor_send_community_type,
4077 neighbor_send_community_type_cmd,
4078 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4079 NEIGHBOR_STR
4080 NEIGHBOR_ADDR_STR2
4081 "Send Community attribute to this neighbor\n"
4082 "Send Standard and Extended Community attributes\n"
4083 "Send Standard, Large and Extended Community attributes\n"
4084 "Send Extended Community attributes\n"
4085 "Send Standard Community attributes\n"
4086 "Send Large Community attributes\n")
4087 {
4088 int idx = 0;
4089 uint32_t flag = 0;
4090
4091 char *peer = argv[1]->arg;
4092
4093 if (argv_find(argv, argc, "standard", &idx))
4094 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4095 else if (argv_find(argv, argc, "extended", &idx))
4096 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4097 else if (argv_find(argv, argc, "large", &idx))
4098 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4099 else if (argv_find(argv, argc, "both", &idx)) {
4100 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4101 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4102 } else {
4103 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4104 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4105 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4106 }
4107
4108 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4109 bgp_node_safi(vty), flag);
4110 }
4111
4112 ALIAS_HIDDEN(
4113 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4114 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4115 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4116 "Send Community attribute to this neighbor\n"
4117 "Send Standard and Extended Community attributes\n"
4118 "Send Standard, Large and Extended Community attributes\n"
4119 "Send Extended Community attributes\n"
4120 "Send Standard Community attributes\n"
4121 "Send Large Community attributes\n")
4122
4123 DEFUN (no_neighbor_send_community_type,
4124 no_neighbor_send_community_type_cmd,
4125 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4126 NO_STR
4127 NEIGHBOR_STR
4128 NEIGHBOR_ADDR_STR2
4129 "Send Community attribute to this neighbor\n"
4130 "Send Standard and Extended Community attributes\n"
4131 "Send Standard, Large and Extended Community attributes\n"
4132 "Send Extended Community attributes\n"
4133 "Send Standard Community attributes\n"
4134 "Send Large Community attributes\n")
4135 {
4136 int idx_peer = 2;
4137
4138 const char *type = argv[argc - 1]->text;
4139
4140 if (strmatch(type, "standard"))
4141 return peer_af_flag_unset_vty(
4142 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4143 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4144 if (strmatch(type, "extended"))
4145 return peer_af_flag_unset_vty(
4146 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4147 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4148 if (strmatch(type, "large"))
4149 return peer_af_flag_unset_vty(
4150 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4151 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4152 if (strmatch(type, "both"))
4153 return peer_af_flag_unset_vty(
4154 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4155 bgp_node_safi(vty),
4156 PEER_FLAG_SEND_COMMUNITY
4157 | PEER_FLAG_SEND_EXT_COMMUNITY);
4158
4159 /* if (strmatch (type, "all")) */
4160 return peer_af_flag_unset_vty(
4161 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4162 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4163 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4164 }
4165
4166 ALIAS_HIDDEN(
4167 no_neighbor_send_community_type,
4168 no_neighbor_send_community_type_hidden_cmd,
4169 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4170 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4171 "Send Community attribute to this neighbor\n"
4172 "Send Standard and Extended Community attributes\n"
4173 "Send Standard, Large and Extended Community attributes\n"
4174 "Send Extended Community attributes\n"
4175 "Send Standard Community attributes\n"
4176 "Send Large Community attributes\n")
4177
4178 /* neighbor soft-reconfig. */
4179 DEFUN (neighbor_soft_reconfiguration,
4180 neighbor_soft_reconfiguration_cmd,
4181 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4182 NEIGHBOR_STR
4183 NEIGHBOR_ADDR_STR2
4184 "Per neighbor soft reconfiguration\n"
4185 "Allow inbound soft reconfiguration for this neighbor\n")
4186 {
4187 int idx_peer = 1;
4188 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4189 bgp_node_safi(vty),
4190 PEER_FLAG_SOFT_RECONFIG);
4191 }
4192
4193 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4194 neighbor_soft_reconfiguration_hidden_cmd,
4195 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4196 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4197 "Per neighbor soft reconfiguration\n"
4198 "Allow inbound soft reconfiguration for this neighbor\n")
4199
4200 DEFUN (no_neighbor_soft_reconfiguration,
4201 no_neighbor_soft_reconfiguration_cmd,
4202 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4203 NO_STR
4204 NEIGHBOR_STR
4205 NEIGHBOR_ADDR_STR2
4206 "Per neighbor soft reconfiguration\n"
4207 "Allow inbound soft reconfiguration for this neighbor\n")
4208 {
4209 int idx_peer = 2;
4210 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4211 bgp_node_afi(vty), bgp_node_safi(vty),
4212 PEER_FLAG_SOFT_RECONFIG);
4213 }
4214
4215 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4216 no_neighbor_soft_reconfiguration_hidden_cmd,
4217 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4218 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4219 "Per neighbor soft reconfiguration\n"
4220 "Allow inbound soft reconfiguration for this neighbor\n")
4221
4222 DEFUN (neighbor_route_reflector_client,
4223 neighbor_route_reflector_client_cmd,
4224 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4225 NEIGHBOR_STR
4226 NEIGHBOR_ADDR_STR2
4227 "Configure a neighbor as Route Reflector client\n")
4228 {
4229 int idx_peer = 1;
4230 struct peer *peer;
4231
4232
4233 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4234 if (!peer)
4235 return CMD_WARNING_CONFIG_FAILED;
4236
4237 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4238 bgp_node_safi(vty),
4239 PEER_FLAG_REFLECTOR_CLIENT);
4240 }
4241
4242 ALIAS_HIDDEN(neighbor_route_reflector_client,
4243 neighbor_route_reflector_client_hidden_cmd,
4244 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4246 "Configure a neighbor as Route Reflector client\n")
4247
4248 DEFUN (no_neighbor_route_reflector_client,
4249 no_neighbor_route_reflector_client_cmd,
4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4251 NO_STR
4252 NEIGHBOR_STR
4253 NEIGHBOR_ADDR_STR2
4254 "Configure a neighbor as Route Reflector client\n")
4255 {
4256 int idx_peer = 2;
4257 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4258 bgp_node_afi(vty), bgp_node_safi(vty),
4259 PEER_FLAG_REFLECTOR_CLIENT);
4260 }
4261
4262 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4263 no_neighbor_route_reflector_client_hidden_cmd,
4264 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4265 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4266 "Configure a neighbor as Route Reflector client\n")
4267
4268 /* neighbor route-server-client. */
4269 DEFUN (neighbor_route_server_client,
4270 neighbor_route_server_client_cmd,
4271 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4272 NEIGHBOR_STR
4273 NEIGHBOR_ADDR_STR2
4274 "Configure a neighbor as Route Server client\n")
4275 {
4276 int idx_peer = 1;
4277 struct peer *peer;
4278
4279 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4280 if (!peer)
4281 return CMD_WARNING_CONFIG_FAILED;
4282 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4283 bgp_node_safi(vty),
4284 PEER_FLAG_RSERVER_CLIENT);
4285 }
4286
4287 ALIAS_HIDDEN(neighbor_route_server_client,
4288 neighbor_route_server_client_hidden_cmd,
4289 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4290 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4291 "Configure a neighbor as Route Server client\n")
4292
4293 DEFUN (no_neighbor_route_server_client,
4294 no_neighbor_route_server_client_cmd,
4295 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4296 NO_STR
4297 NEIGHBOR_STR
4298 NEIGHBOR_ADDR_STR2
4299 "Configure a neighbor as Route Server client\n")
4300 {
4301 int idx_peer = 2;
4302 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4303 bgp_node_afi(vty), bgp_node_safi(vty),
4304 PEER_FLAG_RSERVER_CLIENT);
4305 }
4306
4307 ALIAS_HIDDEN(no_neighbor_route_server_client,
4308 no_neighbor_route_server_client_hidden_cmd,
4309 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4310 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4311 "Configure a neighbor as Route Server client\n")
4312
4313 DEFUN (neighbor_nexthop_local_unchanged,
4314 neighbor_nexthop_local_unchanged_cmd,
4315 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4316 NEIGHBOR_STR
4317 NEIGHBOR_ADDR_STR2
4318 "Configure treatment of outgoing link-local nexthop attribute\n"
4319 "Leave link-local nexthop unchanged for this peer\n")
4320 {
4321 int idx_peer = 1;
4322 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4323 bgp_node_safi(vty),
4324 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4325 }
4326
4327 DEFUN (no_neighbor_nexthop_local_unchanged,
4328 no_neighbor_nexthop_local_unchanged_cmd,
4329 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4330 NO_STR
4331 NEIGHBOR_STR
4332 NEIGHBOR_ADDR_STR2
4333 "Configure treatment of outgoing link-local-nexthop attribute\n"
4334 "Leave link-local nexthop unchanged for this peer\n")
4335 {
4336 int idx_peer = 2;
4337 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4338 bgp_node_afi(vty), bgp_node_safi(vty),
4339 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4340 }
4341
4342 DEFUN (neighbor_attr_unchanged,
4343 neighbor_attr_unchanged_cmd,
4344 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4345 NEIGHBOR_STR
4346 NEIGHBOR_ADDR_STR2
4347 "BGP attribute is propagated unchanged to this neighbor\n"
4348 "As-path attribute\n"
4349 "Nexthop attribute\n"
4350 "Med attribute\n")
4351 {
4352 int idx = 0;
4353 char *peer_str = argv[1]->arg;
4354 struct peer *peer;
4355 uint16_t flags = 0;
4356 afi_t afi = bgp_node_afi(vty);
4357 safi_t safi = bgp_node_safi(vty);
4358
4359 peer = peer_and_group_lookup_vty(vty, peer_str);
4360 if (!peer)
4361 return CMD_WARNING_CONFIG_FAILED;
4362
4363 if (argv_find(argv, argc, "as-path", &idx))
4364 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4365 idx = 0;
4366 if (argv_find(argv, argc, "next-hop", &idx))
4367 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4368 idx = 0;
4369 if (argv_find(argv, argc, "med", &idx))
4370 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4371
4372 /* no flags means all of them! */
4373 if (!flags) {
4374 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4375 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4376 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4377 } else {
4378 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4379 && peer_af_flag_check(peer, afi, safi,
4380 PEER_FLAG_AS_PATH_UNCHANGED)) {
4381 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4382 PEER_FLAG_AS_PATH_UNCHANGED);
4383 }
4384
4385 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4386 && peer_af_flag_check(peer, afi, safi,
4387 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4388 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4389 PEER_FLAG_NEXTHOP_UNCHANGED);
4390 }
4391
4392 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4393 && peer_af_flag_check(peer, afi, safi,
4394 PEER_FLAG_MED_UNCHANGED)) {
4395 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4396 PEER_FLAG_MED_UNCHANGED);
4397 }
4398 }
4399
4400 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4401 }
4402
4403 ALIAS_HIDDEN(
4404 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4405 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4406 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4407 "BGP attribute is propagated unchanged to this neighbor\n"
4408 "As-path attribute\n"
4409 "Nexthop attribute\n"
4410 "Med attribute\n")
4411
4412 DEFUN (no_neighbor_attr_unchanged,
4413 no_neighbor_attr_unchanged_cmd,
4414 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4415 NO_STR
4416 NEIGHBOR_STR
4417 NEIGHBOR_ADDR_STR2
4418 "BGP attribute is propagated unchanged to this neighbor\n"
4419 "As-path attribute\n"
4420 "Nexthop attribute\n"
4421 "Med attribute\n")
4422 {
4423 int idx = 0;
4424 char *peer = argv[2]->arg;
4425 uint16_t flags = 0;
4426
4427 if (argv_find(argv, argc, "as-path", &idx))
4428 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4429 idx = 0;
4430 if (argv_find(argv, argc, "next-hop", &idx))
4431 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4432 idx = 0;
4433 if (argv_find(argv, argc, "med", &idx))
4434 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4435
4436 if (!flags) // no flags means all of them!
4437 {
4438 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4439 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4440 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4441 }
4442
4443 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4444 bgp_node_safi(vty), flags);
4445 }
4446
4447 ALIAS_HIDDEN(
4448 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4449 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4450 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4451 "BGP attribute is propagated unchanged to this neighbor\n"
4452 "As-path attribute\n"
4453 "Nexthop attribute\n"
4454 "Med attribute\n")
4455
4456 /* EBGP multihop configuration. */
4457 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4458 const char *ttl_str)
4459 {
4460 struct peer *peer;
4461 unsigned int ttl;
4462
4463 peer = peer_and_group_lookup_vty(vty, ip_str);
4464 if (!peer)
4465 return CMD_WARNING_CONFIG_FAILED;
4466
4467 if (peer->conf_if)
4468 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4469
4470 if (!ttl_str)
4471 ttl = MAXTTL;
4472 else
4473 ttl = strtoul(ttl_str, NULL, 10);
4474
4475 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4476 }
4477
4478 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4479 {
4480 struct peer *peer;
4481
4482 peer = peer_and_group_lookup_vty(vty, ip_str);
4483 if (!peer)
4484 return CMD_WARNING_CONFIG_FAILED;
4485
4486 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4487 }
4488
4489 /* neighbor ebgp-multihop. */
4490 DEFUN (neighbor_ebgp_multihop,
4491 neighbor_ebgp_multihop_cmd,
4492 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4493 NEIGHBOR_STR
4494 NEIGHBOR_ADDR_STR2
4495 "Allow EBGP neighbors not on directly connected networks\n")
4496 {
4497 int idx_peer = 1;
4498 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4499 }
4500
4501 DEFUN (neighbor_ebgp_multihop_ttl,
4502 neighbor_ebgp_multihop_ttl_cmd,
4503 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4504 NEIGHBOR_STR
4505 NEIGHBOR_ADDR_STR2
4506 "Allow EBGP neighbors not on directly connected networks\n"
4507 "maximum hop count\n")
4508 {
4509 int idx_peer = 1;
4510 int idx_number = 3;
4511 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4512 argv[idx_number]->arg);
4513 }
4514
4515 DEFUN (no_neighbor_ebgp_multihop,
4516 no_neighbor_ebgp_multihop_cmd,
4517 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4518 NO_STR
4519 NEIGHBOR_STR
4520 NEIGHBOR_ADDR_STR2
4521 "Allow EBGP neighbors not on directly connected networks\n"
4522 "maximum hop count\n")
4523 {
4524 int idx_peer = 2;
4525 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4526 }
4527
4528
4529 /* disable-connected-check */
4530 DEFUN (neighbor_disable_connected_check,
4531 neighbor_disable_connected_check_cmd,
4532 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4533 NEIGHBOR_STR
4534 NEIGHBOR_ADDR_STR2
4535 "one-hop away EBGP peer using loopback address\n"
4536 "Enforce EBGP neighbors perform multihop\n")
4537 {
4538 int idx_peer = 1;
4539 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4540 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4541 }
4542
4543 DEFUN (no_neighbor_disable_connected_check,
4544 no_neighbor_disable_connected_check_cmd,
4545 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4546 NO_STR
4547 NEIGHBOR_STR
4548 NEIGHBOR_ADDR_STR2
4549 "one-hop away EBGP peer using loopback address\n"
4550 "Enforce EBGP neighbors perform multihop\n")
4551 {
4552 int idx_peer = 2;
4553 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4554 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4555 }
4556
4557 DEFUN (neighbor_description,
4558 neighbor_description_cmd,
4559 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4560 NEIGHBOR_STR
4561 NEIGHBOR_ADDR_STR2
4562 "Neighbor specific description\n"
4563 "Up to 80 characters describing this neighbor\n")
4564 {
4565 int idx_peer = 1;
4566 int idx_line = 3;
4567 struct peer *peer;
4568 char *str;
4569
4570 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4571 if (!peer)
4572 return CMD_WARNING_CONFIG_FAILED;
4573
4574 str = argv_concat(argv, argc, idx_line);
4575
4576 peer_description_set(peer, str);
4577
4578 XFREE(MTYPE_TMP, str);
4579
4580 return CMD_SUCCESS;
4581 }
4582
4583 DEFUN (no_neighbor_description,
4584 no_neighbor_description_cmd,
4585 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
4586 NO_STR
4587 NEIGHBOR_STR
4588 NEIGHBOR_ADDR_STR2
4589 "Neighbor specific description\n"
4590 "Up to 80 characters describing this neighbor\n")
4591 {
4592 int idx_peer = 2;
4593 struct peer *peer;
4594
4595 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4596 if (!peer)
4597 return CMD_WARNING_CONFIG_FAILED;
4598
4599 peer_description_unset(peer);
4600
4601 return CMD_SUCCESS;
4602 }
4603
4604
4605 /* Neighbor update-source. */
4606 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4607 const char *source_str)
4608 {
4609 struct peer *peer;
4610 struct prefix p;
4611
4612 peer = peer_and_group_lookup_vty(vty, peer_str);
4613 if (!peer)
4614 return CMD_WARNING_CONFIG_FAILED;
4615
4616 if (peer->conf_if)
4617 return CMD_WARNING;
4618
4619 if (source_str) {
4620 union sockunion su;
4621 int ret = str2sockunion(source_str, &su);
4622
4623 if (ret == 0)
4624 peer_update_source_addr_set(peer, &su);
4625 else {
4626 if (str2prefix(source_str, &p)) {
4627 vty_out(vty,
4628 "%% Invalid update-source, remove prefix length \n");
4629 return CMD_WARNING_CONFIG_FAILED;
4630 } else
4631 peer_update_source_if_set(peer, source_str);
4632 }
4633 } else
4634 peer_update_source_unset(peer);
4635
4636 return CMD_SUCCESS;
4637 }
4638
4639 #define BGP_UPDATE_SOURCE_HELP_STR \
4640 "IPv4 address\n" \
4641 "IPv6 address\n" \
4642 "Interface name (requires zebra to be running)\n"
4643
4644 DEFUN (neighbor_update_source,
4645 neighbor_update_source_cmd,
4646 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4647 NEIGHBOR_STR
4648 NEIGHBOR_ADDR_STR2
4649 "Source of routing updates\n"
4650 BGP_UPDATE_SOURCE_HELP_STR)
4651 {
4652 int idx_peer = 1;
4653 int idx_peer_2 = 3;
4654 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4655 argv[idx_peer_2]->arg);
4656 }
4657
4658 DEFUN (no_neighbor_update_source,
4659 no_neighbor_update_source_cmd,
4660 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4661 NO_STR
4662 NEIGHBOR_STR
4663 NEIGHBOR_ADDR_STR2
4664 "Source of routing updates\n"
4665 BGP_UPDATE_SOURCE_HELP_STR)
4666 {
4667 int idx_peer = 2;
4668 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4669 }
4670
4671 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4672 afi_t afi, safi_t safi,
4673 const char *rmap, int set)
4674 {
4675 int ret;
4676 struct peer *peer;
4677
4678 peer = peer_and_group_lookup_vty(vty, peer_str);
4679 if (!peer)
4680 return CMD_WARNING_CONFIG_FAILED;
4681
4682 if (set)
4683 ret = peer_default_originate_set(peer, afi, safi, rmap);
4684 else
4685 ret = peer_default_originate_unset(peer, afi, safi);
4686
4687 return bgp_vty_return(vty, ret);
4688 }
4689
4690 /* neighbor default-originate. */
4691 DEFUN (neighbor_default_originate,
4692 neighbor_default_originate_cmd,
4693 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4694 NEIGHBOR_STR
4695 NEIGHBOR_ADDR_STR2
4696 "Originate default route to this neighbor\n")
4697 {
4698 int idx_peer = 1;
4699 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4700 bgp_node_afi(vty),
4701 bgp_node_safi(vty), NULL, 1);
4702 }
4703
4704 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4705 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4706 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4707 "Originate default route to this neighbor\n")
4708
4709 DEFUN (neighbor_default_originate_rmap,
4710 neighbor_default_originate_rmap_cmd,
4711 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4712 NEIGHBOR_STR
4713 NEIGHBOR_ADDR_STR2
4714 "Originate default route to this neighbor\n"
4715 "Route-map to specify criteria to originate default\n"
4716 "route-map name\n")
4717 {
4718 int idx_peer = 1;
4719 int idx_word = 4;
4720 return peer_default_originate_set_vty(
4721 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4722 argv[idx_word]->arg, 1);
4723 }
4724
4725 ALIAS_HIDDEN(
4726 neighbor_default_originate_rmap,
4727 neighbor_default_originate_rmap_hidden_cmd,
4728 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4729 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4730 "Originate default route to this neighbor\n"
4731 "Route-map to specify criteria to originate default\n"
4732 "route-map name\n")
4733
4734 DEFUN (no_neighbor_default_originate,
4735 no_neighbor_default_originate_cmd,
4736 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4737 NO_STR
4738 NEIGHBOR_STR
4739 NEIGHBOR_ADDR_STR2
4740 "Originate default route to this neighbor\n"
4741 "Route-map to specify criteria to originate default\n"
4742 "route-map name\n")
4743 {
4744 int idx_peer = 2;
4745 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4746 bgp_node_afi(vty),
4747 bgp_node_safi(vty), NULL, 0);
4748 }
4749
4750 ALIAS_HIDDEN(
4751 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4752 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4753 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4754 "Originate default route to this neighbor\n"
4755 "Route-map to specify criteria to originate default\n"
4756 "route-map name\n")
4757
4758
4759 /* Set neighbor's BGP port. */
4760 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4761 const char *port_str)
4762 {
4763 struct peer *peer;
4764 uint16_t port;
4765 struct servent *sp;
4766
4767 peer = peer_lookup_vty(vty, ip_str);
4768 if (!peer)
4769 return CMD_WARNING_CONFIG_FAILED;
4770
4771 if (!port_str) {
4772 sp = getservbyname("bgp", "tcp");
4773 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4774 } else {
4775 port = strtoul(port_str, NULL, 10);
4776 }
4777
4778 peer_port_set(peer, port);
4779
4780 return CMD_SUCCESS;
4781 }
4782
4783 /* Set specified peer's BGP port. */
4784 DEFUN (neighbor_port,
4785 neighbor_port_cmd,
4786 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4787 NEIGHBOR_STR
4788 NEIGHBOR_ADDR_STR
4789 "Neighbor's BGP port\n"
4790 "TCP port number\n")
4791 {
4792 int idx_ip = 1;
4793 int idx_number = 3;
4794 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4795 argv[idx_number]->arg);
4796 }
4797
4798 DEFUN (no_neighbor_port,
4799 no_neighbor_port_cmd,
4800 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4801 NO_STR
4802 NEIGHBOR_STR
4803 NEIGHBOR_ADDR_STR
4804 "Neighbor's BGP port\n"
4805 "TCP port number\n")
4806 {
4807 int idx_ip = 2;
4808 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4809 }
4810
4811
4812 /* neighbor weight. */
4813 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4814 safi_t safi, const char *weight_str)
4815 {
4816 int ret;
4817 struct peer *peer;
4818 unsigned long weight;
4819
4820 peer = peer_and_group_lookup_vty(vty, ip_str);
4821 if (!peer)
4822 return CMD_WARNING_CONFIG_FAILED;
4823
4824 weight = strtoul(weight_str, NULL, 10);
4825
4826 ret = peer_weight_set(peer, afi, safi, weight);
4827 return bgp_vty_return(vty, ret);
4828 }
4829
4830 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4831 safi_t safi)
4832 {
4833 int ret;
4834 struct peer *peer;
4835
4836 peer = peer_and_group_lookup_vty(vty, ip_str);
4837 if (!peer)
4838 return CMD_WARNING_CONFIG_FAILED;
4839
4840 ret = peer_weight_unset(peer, afi, safi);
4841 return bgp_vty_return(vty, ret);
4842 }
4843
4844 DEFUN (neighbor_weight,
4845 neighbor_weight_cmd,
4846 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4847 NEIGHBOR_STR
4848 NEIGHBOR_ADDR_STR2
4849 "Set default weight for routes from this neighbor\n"
4850 "default weight\n")
4851 {
4852 int idx_peer = 1;
4853 int idx_number = 3;
4854 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4855 bgp_node_safi(vty), argv[idx_number]->arg);
4856 }
4857
4858 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4859 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4860 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4861 "Set default weight for routes from this neighbor\n"
4862 "default weight\n")
4863
4864 DEFUN (no_neighbor_weight,
4865 no_neighbor_weight_cmd,
4866 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4867 NO_STR
4868 NEIGHBOR_STR
4869 NEIGHBOR_ADDR_STR2
4870 "Set default weight for routes from this neighbor\n"
4871 "default weight\n")
4872 {
4873 int idx_peer = 2;
4874 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4875 bgp_node_afi(vty), bgp_node_safi(vty));
4876 }
4877
4878 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4879 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4880 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4881 "Set default weight for routes from this neighbor\n"
4882 "default weight\n")
4883
4884
4885 /* Override capability negotiation. */
4886 DEFUN (neighbor_override_capability,
4887 neighbor_override_capability_cmd,
4888 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4889 NEIGHBOR_STR
4890 NEIGHBOR_ADDR_STR2
4891 "Override capability negotiation result\n")
4892 {
4893 int idx_peer = 1;
4894 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4895 PEER_FLAG_OVERRIDE_CAPABILITY);
4896 }
4897
4898 DEFUN (no_neighbor_override_capability,
4899 no_neighbor_override_capability_cmd,
4900 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4901 NO_STR
4902 NEIGHBOR_STR
4903 NEIGHBOR_ADDR_STR2
4904 "Override capability negotiation result\n")
4905 {
4906 int idx_peer = 2;
4907 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4908 PEER_FLAG_OVERRIDE_CAPABILITY);
4909 }
4910
4911 DEFUN (neighbor_strict_capability,
4912 neighbor_strict_capability_cmd,
4913 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4914 NEIGHBOR_STR
4915 NEIGHBOR_ADDR_STR
4916 "Strict capability negotiation match\n")
4917 {
4918 int idx_ip = 1;
4919 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4920 PEER_FLAG_STRICT_CAP_MATCH);
4921 }
4922
4923 DEFUN (no_neighbor_strict_capability,
4924 no_neighbor_strict_capability_cmd,
4925 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4926 NO_STR
4927 NEIGHBOR_STR
4928 NEIGHBOR_ADDR_STR
4929 "Strict capability negotiation match\n")
4930 {
4931 int idx_ip = 2;
4932 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4933 PEER_FLAG_STRICT_CAP_MATCH);
4934 }
4935
4936 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4937 const char *keep_str, const char *hold_str)
4938 {
4939 int ret;
4940 struct peer *peer;
4941 uint32_t keepalive;
4942 uint32_t holdtime;
4943
4944 peer = peer_and_group_lookup_vty(vty, ip_str);
4945 if (!peer)
4946 return CMD_WARNING_CONFIG_FAILED;
4947
4948 keepalive = strtoul(keep_str, NULL, 10);
4949 holdtime = strtoul(hold_str, NULL, 10);
4950
4951 ret = peer_timers_set(peer, keepalive, holdtime);
4952
4953 return bgp_vty_return(vty, ret);
4954 }
4955
4956 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
4957 {
4958 int ret;
4959 struct peer *peer;
4960
4961 peer = peer_and_group_lookup_vty(vty, ip_str);
4962 if (!peer)
4963 return CMD_WARNING_CONFIG_FAILED;
4964
4965 ret = peer_timers_unset(peer);
4966
4967 return bgp_vty_return(vty, ret);
4968 }
4969
4970 DEFUN (neighbor_timers,
4971 neighbor_timers_cmd,
4972 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
4973 NEIGHBOR_STR
4974 NEIGHBOR_ADDR_STR2
4975 "BGP per neighbor timers\n"
4976 "Keepalive interval\n"
4977 "Holdtime\n")
4978 {
4979 int idx_peer = 1;
4980 int idx_number = 3;
4981 int idx_number_2 = 4;
4982 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4983 argv[idx_number]->arg,
4984 argv[idx_number_2]->arg);
4985 }
4986
4987 DEFUN (no_neighbor_timers,
4988 no_neighbor_timers_cmd,
4989 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
4990 NO_STR
4991 NEIGHBOR_STR
4992 NEIGHBOR_ADDR_STR2
4993 "BGP per neighbor timers\n"
4994 "Keepalive interval\n"
4995 "Holdtime\n")
4996 {
4997 int idx_peer = 2;
4998 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
4999 }
5000
5001
5002 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
5003 const char *time_str)
5004 {
5005 int ret;
5006 struct peer *peer;
5007 uint32_t connect;
5008
5009 peer = peer_and_group_lookup_vty(vty, ip_str);
5010 if (!peer)
5011 return CMD_WARNING_CONFIG_FAILED;
5012
5013 connect = strtoul(time_str, NULL, 10);
5014
5015 ret = peer_timers_connect_set(peer, connect);
5016
5017 return bgp_vty_return(vty, ret);
5018 }
5019
5020 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5021 {
5022 int ret;
5023 struct peer *peer;
5024
5025 peer = peer_and_group_lookup_vty(vty, ip_str);
5026 if (!peer)
5027 return CMD_WARNING_CONFIG_FAILED;
5028
5029 ret = peer_timers_connect_unset(peer);
5030
5031 return bgp_vty_return(vty, ret);
5032 }
5033
5034 DEFUN (neighbor_timers_connect,
5035 neighbor_timers_connect_cmd,
5036 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5037 NEIGHBOR_STR
5038 NEIGHBOR_ADDR_STR2
5039 "BGP per neighbor timers\n"
5040 "BGP connect timer\n"
5041 "Connect timer\n")
5042 {
5043 int idx_peer = 1;
5044 int idx_number = 4;
5045 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5046 argv[idx_number]->arg);
5047 }
5048
5049 DEFUN (no_neighbor_timers_connect,
5050 no_neighbor_timers_connect_cmd,
5051 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5052 NO_STR
5053 NEIGHBOR_STR
5054 NEIGHBOR_ADDR_STR2
5055 "BGP per neighbor timers\n"
5056 "BGP connect timer\n"
5057 "Connect timer\n")
5058 {
5059 int idx_peer = 2;
5060 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5061 }
5062
5063
5064 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5065 const char *time_str, int set)
5066 {
5067 int ret;
5068 struct peer *peer;
5069 uint32_t routeadv = 0;
5070
5071 peer = peer_and_group_lookup_vty(vty, ip_str);
5072 if (!peer)
5073 return CMD_WARNING_CONFIG_FAILED;
5074
5075 if (time_str)
5076 routeadv = strtoul(time_str, NULL, 10);
5077
5078 if (set)
5079 ret = peer_advertise_interval_set(peer, routeadv);
5080 else
5081 ret = peer_advertise_interval_unset(peer);
5082
5083 return bgp_vty_return(vty, ret);
5084 }
5085
5086 DEFUN (neighbor_advertise_interval,
5087 neighbor_advertise_interval_cmd,
5088 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5089 NEIGHBOR_STR
5090 NEIGHBOR_ADDR_STR2
5091 "Minimum interval between sending BGP routing updates\n"
5092 "time in seconds\n")
5093 {
5094 int idx_peer = 1;
5095 int idx_number = 3;
5096 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5097 argv[idx_number]->arg, 1);
5098 }
5099
5100 DEFUN (no_neighbor_advertise_interval,
5101 no_neighbor_advertise_interval_cmd,
5102 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5103 NO_STR
5104 NEIGHBOR_STR
5105 NEIGHBOR_ADDR_STR2
5106 "Minimum interval between sending BGP routing updates\n"
5107 "time in seconds\n")
5108 {
5109 int idx_peer = 2;
5110 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5111 }
5112
5113
5114 /* Time to wait before processing route-map updates */
5115 DEFUN (bgp_set_route_map_delay_timer,
5116 bgp_set_route_map_delay_timer_cmd,
5117 "bgp route-map delay-timer (0-600)",
5118 SET_STR
5119 "BGP route-map delay timer\n"
5120 "Time in secs to wait before processing route-map changes\n"
5121 "0 disables the timer, no route updates happen when route-maps change\n")
5122 {
5123 int idx_number = 3;
5124 uint32_t rmap_delay_timer;
5125
5126 if (argv[idx_number]->arg) {
5127 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5128 bm->rmap_update_timer = rmap_delay_timer;
5129
5130 /* if the dynamic update handling is being disabled, and a timer
5131 * is
5132 * running, stop the timer and act as if the timer has already
5133 * fired.
5134 */
5135 if (!rmap_delay_timer && bm->t_rmap_update) {
5136 BGP_TIMER_OFF(bm->t_rmap_update);
5137 thread_execute(bm->master, bgp_route_map_update_timer,
5138 NULL, 0);
5139 }
5140 return CMD_SUCCESS;
5141 } else {
5142 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5143 return CMD_WARNING_CONFIG_FAILED;
5144 }
5145 }
5146
5147 DEFUN (no_bgp_set_route_map_delay_timer,
5148 no_bgp_set_route_map_delay_timer_cmd,
5149 "no bgp route-map delay-timer [(0-600)]",
5150 NO_STR
5151 BGP_STR
5152 "Default BGP route-map delay timer\n"
5153 "Reset to default time to wait for processing route-map changes\n"
5154 "0 disables the timer, no route updates happen when route-maps change\n")
5155 {
5156
5157 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5158
5159 return CMD_SUCCESS;
5160 }
5161
5162
5163 /* neighbor interface */
5164 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5165 const char *str)
5166 {
5167 struct peer *peer;
5168
5169 peer = peer_lookup_vty(vty, ip_str);
5170 if (!peer || peer->conf_if) {
5171 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5172 return CMD_WARNING_CONFIG_FAILED;
5173 }
5174
5175 if (str)
5176 peer_interface_set(peer, str);
5177 else
5178 peer_interface_unset(peer);
5179
5180 return CMD_SUCCESS;
5181 }
5182
5183 DEFUN (neighbor_interface,
5184 neighbor_interface_cmd,
5185 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5186 NEIGHBOR_STR
5187 NEIGHBOR_ADDR_STR
5188 "Interface\n"
5189 "Interface name\n")
5190 {
5191 int idx_ip = 1;
5192 int idx_word = 3;
5193 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5194 }
5195
5196 DEFUN (no_neighbor_interface,
5197 no_neighbor_interface_cmd,
5198 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5199 NO_STR
5200 NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Interface\n"
5203 "Interface name\n")
5204 {
5205 int idx_peer = 2;
5206 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5207 }
5208
5209 DEFUN (neighbor_distribute_list,
5210 neighbor_distribute_list_cmd,
5211 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5212 NEIGHBOR_STR
5213 NEIGHBOR_ADDR_STR2
5214 "Filter updates to/from this neighbor\n"
5215 "IP access-list number\n"
5216 "IP access-list number (expanded range)\n"
5217 "IP Access-list name\n"
5218 "Filter incoming updates\n"
5219 "Filter outgoing updates\n")
5220 {
5221 int idx_peer = 1;
5222 int idx_acl = 3;
5223 int direct, ret;
5224 struct peer *peer;
5225
5226 const char *pstr = argv[idx_peer]->arg;
5227 const char *acl = argv[idx_acl]->arg;
5228 const char *inout = argv[argc - 1]->text;
5229
5230 peer = peer_and_group_lookup_vty(vty, pstr);
5231 if (!peer)
5232 return CMD_WARNING_CONFIG_FAILED;
5233
5234 /* Check filter direction. */
5235 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5236 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5237 direct, acl);
5238
5239 return bgp_vty_return(vty, ret);
5240 }
5241
5242 ALIAS_HIDDEN(
5243 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5244 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5245 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5246 "Filter updates to/from this neighbor\n"
5247 "IP access-list number\n"
5248 "IP access-list number (expanded range)\n"
5249 "IP Access-list name\n"
5250 "Filter incoming updates\n"
5251 "Filter outgoing updates\n")
5252
5253 DEFUN (no_neighbor_distribute_list,
5254 no_neighbor_distribute_list_cmd,
5255 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5256 NO_STR
5257 NEIGHBOR_STR
5258 NEIGHBOR_ADDR_STR2
5259 "Filter updates to/from this neighbor\n"
5260 "IP access-list number\n"
5261 "IP access-list number (expanded range)\n"
5262 "IP Access-list name\n"
5263 "Filter incoming updates\n"
5264 "Filter outgoing updates\n")
5265 {
5266 int idx_peer = 2;
5267 int direct, ret;
5268 struct peer *peer;
5269
5270 const char *pstr = argv[idx_peer]->arg;
5271 const char *inout = argv[argc - 1]->text;
5272
5273 peer = peer_and_group_lookup_vty(vty, pstr);
5274 if (!peer)
5275 return CMD_WARNING_CONFIG_FAILED;
5276
5277 /* Check filter direction. */
5278 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5279 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5280 direct);
5281
5282 return bgp_vty_return(vty, ret);
5283 }
5284
5285 ALIAS_HIDDEN(
5286 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5287 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5288 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5289 "Filter updates to/from this neighbor\n"
5290 "IP access-list number\n"
5291 "IP access-list number (expanded range)\n"
5292 "IP Access-list name\n"
5293 "Filter incoming updates\n"
5294 "Filter outgoing updates\n")
5295
5296 /* Set prefix list to the peer. */
5297 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5298 afi_t afi, safi_t safi,
5299 const char *name_str,
5300 const char *direct_str)
5301 {
5302 int ret;
5303 struct peer *peer;
5304 int direct = FILTER_IN;
5305
5306 peer = peer_and_group_lookup_vty(vty, ip_str);
5307 if (!peer)
5308 return CMD_WARNING_CONFIG_FAILED;
5309
5310 /* Check filter direction. */
5311 if (strncmp(direct_str, "i", 1) == 0)
5312 direct = FILTER_IN;
5313 else if (strncmp(direct_str, "o", 1) == 0)
5314 direct = FILTER_OUT;
5315
5316 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5317
5318 return bgp_vty_return(vty, ret);
5319 }
5320
5321 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5322 afi_t afi, safi_t safi,
5323 const char *direct_str)
5324 {
5325 int ret;
5326 struct peer *peer;
5327 int direct = FILTER_IN;
5328
5329 peer = peer_and_group_lookup_vty(vty, ip_str);
5330 if (!peer)
5331 return CMD_WARNING_CONFIG_FAILED;
5332
5333 /* Check filter direction. */
5334 if (strncmp(direct_str, "i", 1) == 0)
5335 direct = FILTER_IN;
5336 else if (strncmp(direct_str, "o", 1) == 0)
5337 direct = FILTER_OUT;
5338
5339 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5340
5341 return bgp_vty_return(vty, ret);
5342 }
5343
5344 DEFUN (neighbor_prefix_list,
5345 neighbor_prefix_list_cmd,
5346 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5347 NEIGHBOR_STR
5348 NEIGHBOR_ADDR_STR2
5349 "Filter updates to/from this neighbor\n"
5350 "Name of a prefix list\n"
5351 "Filter incoming updates\n"
5352 "Filter outgoing updates\n")
5353 {
5354 int idx_peer = 1;
5355 int idx_word = 3;
5356 int idx_in_out = 4;
5357 return peer_prefix_list_set_vty(
5358 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5359 argv[idx_word]->arg, argv[idx_in_out]->arg);
5360 }
5361
5362 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5363 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5364 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5365 "Filter updates to/from this neighbor\n"
5366 "Name of a prefix list\n"
5367 "Filter incoming updates\n"
5368 "Filter outgoing updates\n")
5369
5370 DEFUN (no_neighbor_prefix_list,
5371 no_neighbor_prefix_list_cmd,
5372 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5373 NO_STR
5374 NEIGHBOR_STR
5375 NEIGHBOR_ADDR_STR2
5376 "Filter updates to/from this neighbor\n"
5377 "Name of a prefix list\n"
5378 "Filter incoming updates\n"
5379 "Filter outgoing updates\n")
5380 {
5381 int idx_peer = 2;
5382 int idx_in_out = 5;
5383 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5384 bgp_node_afi(vty), bgp_node_safi(vty),
5385 argv[idx_in_out]->arg);
5386 }
5387
5388 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5389 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5390 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5391 "Filter updates to/from this neighbor\n"
5392 "Name of a prefix list\n"
5393 "Filter incoming updates\n"
5394 "Filter outgoing updates\n")
5395
5396 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5397 safi_t safi, const char *name_str,
5398 const char *direct_str)
5399 {
5400 int ret;
5401 struct peer *peer;
5402 int direct = FILTER_IN;
5403
5404 peer = peer_and_group_lookup_vty(vty, ip_str);
5405 if (!peer)
5406 return CMD_WARNING_CONFIG_FAILED;
5407
5408 /* Check filter direction. */
5409 if (strncmp(direct_str, "i", 1) == 0)
5410 direct = FILTER_IN;
5411 else if (strncmp(direct_str, "o", 1) == 0)
5412 direct = FILTER_OUT;
5413
5414 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5415
5416 return bgp_vty_return(vty, ret);
5417 }
5418
5419 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5420 safi_t safi, const char *direct_str)
5421 {
5422 int ret;
5423 struct peer *peer;
5424 int direct = FILTER_IN;
5425
5426 peer = peer_and_group_lookup_vty(vty, ip_str);
5427 if (!peer)
5428 return CMD_WARNING_CONFIG_FAILED;
5429
5430 /* Check filter direction. */
5431 if (strncmp(direct_str, "i", 1) == 0)
5432 direct = FILTER_IN;
5433 else if (strncmp(direct_str, "o", 1) == 0)
5434 direct = FILTER_OUT;
5435
5436 ret = peer_aslist_unset(peer, afi, safi, direct);
5437
5438 return bgp_vty_return(vty, ret);
5439 }
5440
5441 DEFUN (neighbor_filter_list,
5442 neighbor_filter_list_cmd,
5443 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5444 NEIGHBOR_STR
5445 NEIGHBOR_ADDR_STR2
5446 "Establish BGP filters\n"
5447 "AS path access-list name\n"
5448 "Filter incoming routes\n"
5449 "Filter outgoing routes\n")
5450 {
5451 int idx_peer = 1;
5452 int idx_word = 3;
5453 int idx_in_out = 4;
5454 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5455 bgp_node_safi(vty), argv[idx_word]->arg,
5456 argv[idx_in_out]->arg);
5457 }
5458
5459 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5460 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5461 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5462 "Establish BGP filters\n"
5463 "AS path access-list name\n"
5464 "Filter incoming routes\n"
5465 "Filter outgoing routes\n")
5466
5467 DEFUN (no_neighbor_filter_list,
5468 no_neighbor_filter_list_cmd,
5469 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5470 NO_STR
5471 NEIGHBOR_STR
5472 NEIGHBOR_ADDR_STR2
5473 "Establish BGP filters\n"
5474 "AS path access-list name\n"
5475 "Filter incoming routes\n"
5476 "Filter outgoing routes\n")
5477 {
5478 int idx_peer = 2;
5479 int idx_in_out = 5;
5480 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5481 bgp_node_afi(vty), bgp_node_safi(vty),
5482 argv[idx_in_out]->arg);
5483 }
5484
5485 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5486 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5487 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5488 "Establish BGP filters\n"
5489 "AS path access-list name\n"
5490 "Filter incoming routes\n"
5491 "Filter outgoing routes\n")
5492
5493 /* Set route-map to the peer. */
5494 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5495 afi_t afi, safi_t safi, const char *name_str,
5496 const char *direct_str)
5497 {
5498 int ret;
5499 struct peer *peer;
5500 int direct = RMAP_IN;
5501
5502 peer = peer_and_group_lookup_vty(vty, ip_str);
5503 if (!peer)
5504 return CMD_WARNING_CONFIG_FAILED;
5505
5506 /* Check filter direction. */
5507 if (strncmp(direct_str, "in", 2) == 0)
5508 direct = RMAP_IN;
5509 else if (strncmp(direct_str, "o", 1) == 0)
5510 direct = RMAP_OUT;
5511
5512 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5513
5514 return bgp_vty_return(vty, ret);
5515 }
5516
5517 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5518 afi_t afi, safi_t safi,
5519 const char *direct_str)
5520 {
5521 int ret;
5522 struct peer *peer;
5523 int direct = RMAP_IN;
5524
5525 peer = peer_and_group_lookup_vty(vty, ip_str);
5526 if (!peer)
5527 return CMD_WARNING_CONFIG_FAILED;
5528
5529 /* Check filter direction. */
5530 if (strncmp(direct_str, "in", 2) == 0)
5531 direct = RMAP_IN;
5532 else if (strncmp(direct_str, "o", 1) == 0)
5533 direct = RMAP_OUT;
5534
5535 ret = peer_route_map_unset(peer, afi, safi, direct);
5536
5537 return bgp_vty_return(vty, ret);
5538 }
5539
5540 DEFUN (neighbor_route_map,
5541 neighbor_route_map_cmd,
5542 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5543 NEIGHBOR_STR
5544 NEIGHBOR_ADDR_STR2
5545 "Apply route map to neighbor\n"
5546 "Name of route map\n"
5547 "Apply map to incoming routes\n"
5548 "Apply map to outbound routes\n")
5549 {
5550 int idx_peer = 1;
5551 int idx_word = 3;
5552 int idx_in_out = 4;
5553 return peer_route_map_set_vty(
5554 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5555 argv[idx_word]->arg, argv[idx_in_out]->arg);
5556 }
5557
5558 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5559 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5560 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5561 "Apply route map to neighbor\n"
5562 "Name of route map\n"
5563 "Apply map to incoming routes\n"
5564 "Apply map to outbound routes\n")
5565
5566 DEFUN (no_neighbor_route_map,
5567 no_neighbor_route_map_cmd,
5568 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5569 NO_STR
5570 NEIGHBOR_STR
5571 NEIGHBOR_ADDR_STR2
5572 "Apply route map to neighbor\n"
5573 "Name of route map\n"
5574 "Apply map to incoming routes\n"
5575 "Apply map to outbound routes\n")
5576 {
5577 int idx_peer = 2;
5578 int idx_in_out = 5;
5579 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5580 bgp_node_afi(vty), bgp_node_safi(vty),
5581 argv[idx_in_out]->arg);
5582 }
5583
5584 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5585 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5586 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5587 "Apply route map to neighbor\n"
5588 "Name of route map\n"
5589 "Apply map to incoming routes\n"
5590 "Apply map to outbound routes\n")
5591
5592 /* Set unsuppress-map to the peer. */
5593 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5594 afi_t afi, safi_t safi,
5595 const char *name_str)
5596 {
5597 int ret;
5598 struct peer *peer;
5599
5600 peer = peer_and_group_lookup_vty(vty, ip_str);
5601 if (!peer)
5602 return CMD_WARNING_CONFIG_FAILED;
5603
5604 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5605
5606 return bgp_vty_return(vty, ret);
5607 }
5608
5609 /* Unset route-map from the peer. */
5610 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5611 afi_t afi, safi_t safi)
5612 {
5613 int ret;
5614 struct peer *peer;
5615
5616 peer = peer_and_group_lookup_vty(vty, ip_str);
5617 if (!peer)
5618 return CMD_WARNING_CONFIG_FAILED;
5619
5620 ret = peer_unsuppress_map_unset(peer, afi, safi);
5621
5622 return bgp_vty_return(vty, ret);
5623 }
5624
5625 DEFUN (neighbor_unsuppress_map,
5626 neighbor_unsuppress_map_cmd,
5627 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5628 NEIGHBOR_STR
5629 NEIGHBOR_ADDR_STR2
5630 "Route-map to selectively unsuppress suppressed routes\n"
5631 "Name of route map\n")
5632 {
5633 int idx_peer = 1;
5634 int idx_word = 3;
5635 return peer_unsuppress_map_set_vty(
5636 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5637 argv[idx_word]->arg);
5638 }
5639
5640 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5641 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5642 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5643 "Route-map to selectively unsuppress suppressed routes\n"
5644 "Name of route map\n")
5645
5646 DEFUN (no_neighbor_unsuppress_map,
5647 no_neighbor_unsuppress_map_cmd,
5648 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5649 NO_STR
5650 NEIGHBOR_STR
5651 NEIGHBOR_ADDR_STR2
5652 "Route-map to selectively unsuppress suppressed routes\n"
5653 "Name of route map\n")
5654 {
5655 int idx_peer = 2;
5656 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5657 bgp_node_afi(vty),
5658 bgp_node_safi(vty));
5659 }
5660
5661 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5662 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5663 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5664 "Route-map to selectively unsuppress suppressed routes\n"
5665 "Name of route map\n")
5666
5667 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5668 afi_t afi, safi_t safi,
5669 const char *num_str,
5670 const char *threshold_str, int warning,
5671 const char *restart_str)
5672 {
5673 int ret;
5674 struct peer *peer;
5675 uint32_t max;
5676 uint8_t threshold;
5677 uint16_t restart;
5678
5679 peer = peer_and_group_lookup_vty(vty, ip_str);
5680 if (!peer)
5681 return CMD_WARNING_CONFIG_FAILED;
5682
5683 max = strtoul(num_str, NULL, 10);
5684 if (threshold_str)
5685 threshold = atoi(threshold_str);
5686 else
5687 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5688
5689 if (restart_str)
5690 restart = atoi(restart_str);
5691 else
5692 restart = 0;
5693
5694 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5695 restart);
5696
5697 return bgp_vty_return(vty, ret);
5698 }
5699
5700 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5701 afi_t afi, safi_t safi)
5702 {
5703 int ret;
5704 struct peer *peer;
5705
5706 peer = peer_and_group_lookup_vty(vty, ip_str);
5707 if (!peer)
5708 return CMD_WARNING_CONFIG_FAILED;
5709
5710 ret = peer_maximum_prefix_unset(peer, afi, safi);
5711
5712 return bgp_vty_return(vty, ret);
5713 }
5714
5715 /* Maximum number of prefix configuration. prefix count is different
5716 for each peer configuration. So this configuration can be set for
5717 each peer configuration. */
5718 DEFUN (neighbor_maximum_prefix,
5719 neighbor_maximum_prefix_cmd,
5720 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5721 NEIGHBOR_STR
5722 NEIGHBOR_ADDR_STR2
5723 "Maximum number of prefix accept from this peer\n"
5724 "maximum no. of prefix limit\n")
5725 {
5726 int idx_peer = 1;
5727 int idx_number = 3;
5728 return peer_maximum_prefix_set_vty(
5729 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5730 argv[idx_number]->arg, NULL, 0, NULL);
5731 }
5732
5733 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5734 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5736 "Maximum number of prefix accept from this peer\n"
5737 "maximum no. of prefix limit\n")
5738
5739 DEFUN (neighbor_maximum_prefix_threshold,
5740 neighbor_maximum_prefix_threshold_cmd,
5741 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5742 NEIGHBOR_STR
5743 NEIGHBOR_ADDR_STR2
5744 "Maximum number of prefix accept from this peer\n"
5745 "maximum no. of prefix limit\n"
5746 "Threshold value (%) at which to generate a warning msg\n")
5747 {
5748 int idx_peer = 1;
5749 int idx_number = 3;
5750 int idx_number_2 = 4;
5751 return peer_maximum_prefix_set_vty(
5752 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5753 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5754 }
5755
5756 ALIAS_HIDDEN(
5757 neighbor_maximum_prefix_threshold,
5758 neighbor_maximum_prefix_threshold_hidden_cmd,
5759 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5760 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5761 "Maximum number of prefix accept from this peer\n"
5762 "maximum no. of prefix limit\n"
5763 "Threshold value (%) at which to generate a warning msg\n")
5764
5765 DEFUN (neighbor_maximum_prefix_warning,
5766 neighbor_maximum_prefix_warning_cmd,
5767 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5768 NEIGHBOR_STR
5769 NEIGHBOR_ADDR_STR2
5770 "Maximum number of prefix accept from this peer\n"
5771 "maximum no. of prefix limit\n"
5772 "Only give warning message when limit is exceeded\n")
5773 {
5774 int idx_peer = 1;
5775 int idx_number = 3;
5776 return peer_maximum_prefix_set_vty(
5777 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5778 argv[idx_number]->arg, NULL, 1, NULL);
5779 }
5780
5781 ALIAS_HIDDEN(
5782 neighbor_maximum_prefix_warning,
5783 neighbor_maximum_prefix_warning_hidden_cmd,
5784 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5785 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5786 "Maximum number of prefix accept from this peer\n"
5787 "maximum no. of prefix limit\n"
5788 "Only give warning message when limit is exceeded\n")
5789
5790 DEFUN (neighbor_maximum_prefix_threshold_warning,
5791 neighbor_maximum_prefix_threshold_warning_cmd,
5792 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5793 NEIGHBOR_STR
5794 NEIGHBOR_ADDR_STR2
5795 "Maximum number of prefix accept from this peer\n"
5796 "maximum no. of prefix limit\n"
5797 "Threshold value (%) at which to generate a warning msg\n"
5798 "Only give warning message when limit is exceeded\n")
5799 {
5800 int idx_peer = 1;
5801 int idx_number = 3;
5802 int idx_number_2 = 4;
5803 return peer_maximum_prefix_set_vty(
5804 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5805 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5806 }
5807
5808 ALIAS_HIDDEN(
5809 neighbor_maximum_prefix_threshold_warning,
5810 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5811 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5812 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5813 "Maximum number of prefix accept from this peer\n"
5814 "maximum no. of prefix limit\n"
5815 "Threshold value (%) at which to generate a warning msg\n"
5816 "Only give warning message when limit is exceeded\n")
5817
5818 DEFUN (neighbor_maximum_prefix_restart,
5819 neighbor_maximum_prefix_restart_cmd,
5820 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5821 NEIGHBOR_STR
5822 NEIGHBOR_ADDR_STR2
5823 "Maximum number of prefix accept from this peer\n"
5824 "maximum no. of prefix limit\n"
5825 "Restart bgp connection after limit is exceeded\n"
5826 "Restart interval in minutes\n")
5827 {
5828 int idx_peer = 1;
5829 int idx_number = 3;
5830 int idx_number_2 = 5;
5831 return peer_maximum_prefix_set_vty(
5832 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5833 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5834 }
5835
5836 ALIAS_HIDDEN(
5837 neighbor_maximum_prefix_restart,
5838 neighbor_maximum_prefix_restart_hidden_cmd,
5839 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5840 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5841 "Maximum number of prefix accept from this peer\n"
5842 "maximum no. of prefix limit\n"
5843 "Restart bgp connection after limit is exceeded\n"
5844 "Restart interval in minutes\n")
5845
5846 DEFUN (neighbor_maximum_prefix_threshold_restart,
5847 neighbor_maximum_prefix_threshold_restart_cmd,
5848 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5849 NEIGHBOR_STR
5850 NEIGHBOR_ADDR_STR2
5851 "Maximum number of prefixes to accept from this peer\n"
5852 "maximum no. of prefix limit\n"
5853 "Threshold value (%) at which to generate a warning msg\n"
5854 "Restart bgp connection after limit is exceeded\n"
5855 "Restart interval in minutes\n")
5856 {
5857 int idx_peer = 1;
5858 int idx_number = 3;
5859 int idx_number_2 = 4;
5860 int idx_number_3 = 6;
5861 return peer_maximum_prefix_set_vty(
5862 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5863 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5864 argv[idx_number_3]->arg);
5865 }
5866
5867 ALIAS_HIDDEN(
5868 neighbor_maximum_prefix_threshold_restart,
5869 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5870 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5871 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5872 "Maximum number of prefixes to accept from this peer\n"
5873 "maximum no. of prefix limit\n"
5874 "Threshold value (%) at which to generate a warning msg\n"
5875 "Restart bgp connection after limit is exceeded\n"
5876 "Restart interval in minutes\n")
5877
5878 DEFUN (no_neighbor_maximum_prefix,
5879 no_neighbor_maximum_prefix_cmd,
5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
5884 "Maximum number of prefixes to accept from this peer\n"
5885 "maximum no. of prefix limit\n"
5886 "Threshold value (%) at which to generate a warning msg\n"
5887 "Restart bgp connection after limit is exceeded\n"
5888 "Restart interval in minutes\n"
5889 "Only give warning message when limit is exceeded\n")
5890 {
5891 int idx_peer = 2;
5892 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5893 bgp_node_afi(vty),
5894 bgp_node_safi(vty));
5895 }
5896
5897 ALIAS_HIDDEN(
5898 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5899 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5900 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5901 "Maximum number of prefixes to accept from this peer\n"
5902 "maximum no. of prefix limit\n"
5903 "Threshold value (%) at which to generate a warning msg\n"
5904 "Restart bgp connection after limit is exceeded\n"
5905 "Restart interval in minutes\n"
5906 "Only give warning message when limit is exceeded\n")
5907
5908
5909 /* "neighbor allowas-in" */
5910 DEFUN (neighbor_allowas_in,
5911 neighbor_allowas_in_cmd,
5912 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5913 NEIGHBOR_STR
5914 NEIGHBOR_ADDR_STR2
5915 "Accept as-path with my AS present in it\n"
5916 "Number of occurances of AS number\n"
5917 "Only accept my AS in the as-path if the route was originated in my AS\n")
5918 {
5919 int idx_peer = 1;
5920 int idx_number_origin = 3;
5921 int ret;
5922 int origin = 0;
5923 struct peer *peer;
5924 int allow_num = 0;
5925
5926 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5927 if (!peer)
5928 return CMD_WARNING_CONFIG_FAILED;
5929
5930 if (argc <= idx_number_origin)
5931 allow_num = 3;
5932 else {
5933 if (argv[idx_number_origin]->type == WORD_TKN)
5934 origin = 1;
5935 else
5936 allow_num = atoi(argv[idx_number_origin]->arg);
5937 }
5938
5939 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5940 allow_num, origin);
5941
5942 return bgp_vty_return(vty, ret);
5943 }
5944
5945 ALIAS_HIDDEN(
5946 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5947 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5948 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5949 "Accept as-path with my AS present in it\n"
5950 "Number of occurances of AS number\n"
5951 "Only accept my AS in the as-path if the route was originated in my AS\n")
5952
5953 DEFUN (no_neighbor_allowas_in,
5954 no_neighbor_allowas_in_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5956 NO_STR
5957 NEIGHBOR_STR
5958 NEIGHBOR_ADDR_STR2
5959 "allow local ASN appears in aspath attribute\n"
5960 "Number of occurances of AS number\n"
5961 "Only accept my AS in the as-path if the route was originated in my AS\n")
5962 {
5963 int idx_peer = 2;
5964 int ret;
5965 struct peer *peer;
5966
5967 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5968 if (!peer)
5969 return CMD_WARNING_CONFIG_FAILED;
5970
5971 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5972 bgp_node_safi(vty));
5973
5974 return bgp_vty_return(vty, ret);
5975 }
5976
5977 ALIAS_HIDDEN(
5978 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5979 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5980 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5981 "allow local ASN appears in aspath attribute\n"
5982 "Number of occurances of AS number\n"
5983 "Only accept my AS in the as-path if the route was originated in my AS\n")
5984
5985 DEFUN (neighbor_ttl_security,
5986 neighbor_ttl_security_cmd,
5987 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
5988 NEIGHBOR_STR
5989 NEIGHBOR_ADDR_STR2
5990 "BGP ttl-security parameters\n"
5991 "Specify the maximum number of hops to the BGP peer\n"
5992 "Number of hops to BGP peer\n")
5993 {
5994 int idx_peer = 1;
5995 int idx_number = 4;
5996 struct peer *peer;
5997 int gtsm_hops;
5998
5999 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6000 if (!peer)
6001 return CMD_WARNING_CONFIG_FAILED;
6002
6003 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
6004
6005 /*
6006 * If 'neighbor swpX', then this is for directly connected peers,
6007 * we should not accept a ttl-security hops value greater than 1.
6008 */
6009 if (peer->conf_if && (gtsm_hops > 1)) {
6010 vty_out(vty,
6011 "%s is directly connected peer, hops cannot exceed 1\n",
6012 argv[idx_peer]->arg);
6013 return CMD_WARNING_CONFIG_FAILED;
6014 }
6015
6016 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6017 }
6018
6019 DEFUN (no_neighbor_ttl_security,
6020 no_neighbor_ttl_security_cmd,
6021 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6022 NO_STR
6023 NEIGHBOR_STR
6024 NEIGHBOR_ADDR_STR2
6025 "BGP ttl-security parameters\n"
6026 "Specify the maximum number of hops to the BGP peer\n"
6027 "Number of hops to BGP peer\n")
6028 {
6029 int idx_peer = 2;
6030 struct peer *peer;
6031
6032 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6033 if (!peer)
6034 return CMD_WARNING_CONFIG_FAILED;
6035
6036 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6037 }
6038
6039 DEFUN (neighbor_addpath_tx_all_paths,
6040 neighbor_addpath_tx_all_paths_cmd,
6041 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6042 NEIGHBOR_STR
6043 NEIGHBOR_ADDR_STR2
6044 "Use addpath to advertise all paths to a neighbor\n")
6045 {
6046 int idx_peer = 1;
6047 struct peer *peer;
6048
6049 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6050 if (!peer)
6051 return CMD_WARNING_CONFIG_FAILED;
6052
6053 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6054 bgp_node_safi(vty),
6055 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6056 }
6057
6058 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6059 neighbor_addpath_tx_all_paths_hidden_cmd,
6060 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6061 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6062 "Use addpath to advertise all paths to a neighbor\n")
6063
6064 DEFUN (no_neighbor_addpath_tx_all_paths,
6065 no_neighbor_addpath_tx_all_paths_cmd,
6066 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6067 NO_STR
6068 NEIGHBOR_STR
6069 NEIGHBOR_ADDR_STR2
6070 "Use addpath to advertise all paths to a neighbor\n")
6071 {
6072 int idx_peer = 2;
6073 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6074 bgp_node_afi(vty), bgp_node_safi(vty),
6075 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6076 }
6077
6078 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6079 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6080 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6081 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6082 "Use addpath to advertise all paths to a neighbor\n")
6083
6084 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6085 neighbor_addpath_tx_bestpath_per_as_cmd,
6086 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6087 NEIGHBOR_STR
6088 NEIGHBOR_ADDR_STR2
6089 "Use addpath to advertise the bestpath per each neighboring AS\n")
6090 {
6091 int idx_peer = 1;
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 peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6099 bgp_node_safi(vty),
6100 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6101 }
6102
6103 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6104 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6105 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6106 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6107 "Use addpath to advertise the bestpath per each neighboring AS\n")
6108
6109 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6110 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6112 NO_STR
6113 NEIGHBOR_STR
6114 NEIGHBOR_ADDR_STR2
6115 "Use addpath to advertise the bestpath per each neighboring AS\n")
6116 {
6117 int idx_peer = 2;
6118 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6119 bgp_node_afi(vty), bgp_node_safi(vty),
6120 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6121 }
6122
6123 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6124 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6125 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6126 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6127 "Use addpath to advertise the bestpath per each neighboring AS\n")
6128
6129 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6130 struct ecommunity **list)
6131 {
6132 struct ecommunity *ecom = NULL;
6133 struct ecommunity *ecomadd;
6134
6135 for (; argc; --argc, ++argv) {
6136
6137 ecomadd = ecommunity_str2com(argv[0]->arg,
6138 ECOMMUNITY_ROUTE_TARGET, 0);
6139 if (!ecomadd) {
6140 vty_out(vty, "Malformed community-list value\n");
6141 if (ecom)
6142 ecommunity_free(&ecom);
6143 return CMD_WARNING_CONFIG_FAILED;
6144 }
6145
6146 if (ecom) {
6147 ecommunity_merge(ecom, ecomadd);
6148 ecommunity_free(&ecomadd);
6149 } else {
6150 ecom = ecomadd;
6151 }
6152 }
6153
6154 if (*list) {
6155 ecommunity_free(&*list);
6156 }
6157 *list = ecom;
6158
6159 return CMD_SUCCESS;
6160 }
6161
6162 /*
6163 * v2vimport is true if we are handling a `import vrf ...` command
6164 */
6165 static afi_t vpn_policy_getafi(struct vty *vty, struct bgp *bgp, bool v2vimport)
6166 {
6167 afi_t afi;
6168
6169 switch (vty->node) {
6170 case BGP_IPV4_NODE:
6171 afi = AFI_IP;
6172 break;
6173 case BGP_IPV6_NODE:
6174 afi = AFI_IP6;
6175 break;
6176 default:
6177 vty_out(vty,
6178 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6179 return AFI_MAX;
6180 }
6181
6182 if (!v2vimport) {
6183 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6184 BGP_CONFIG_VRF_TO_VRF_IMPORT)
6185 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6186 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
6187 vty_out(vty,
6188 "%% error: Please unconfigure import vrf commands before using vpn commands\n");
6189 return AFI_MAX;
6190 }
6191 } else {
6192 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6193 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)
6194 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
6195 BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT)) {
6196 vty_out(vty,
6197 "%% error: Please unconfigure vpn to vrf commands before using import vrf commands\n");
6198 return AFI_MAX;
6199 }
6200 }
6201 return afi;
6202 }
6203
6204 DEFPY (af_rd_vpn_export,
6205 af_rd_vpn_export_cmd,
6206 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6207 NO_STR
6208 "Specify route distinguisher\n"
6209 "Between current address-family and vpn\n"
6210 "For routes leaked from current address-family to vpn\n"
6211 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6212 {
6213 VTY_DECLVAR_CONTEXT(bgp, bgp);
6214 struct prefix_rd prd;
6215 int ret;
6216 afi_t afi;
6217 int idx = 0;
6218 int yes = 1;
6219
6220 if (argv_find(argv, argc, "no", &idx))
6221 yes = 0;
6222
6223 if (yes) {
6224 ret = str2prefix_rd(rd_str, &prd);
6225 if (!ret) {
6226 vty_out(vty, "%% Malformed rd\n");
6227 return CMD_WARNING_CONFIG_FAILED;
6228 }
6229 }
6230
6231 afi = vpn_policy_getafi(vty, bgp, false);
6232 if (afi == AFI_MAX)
6233 return CMD_WARNING_CONFIG_FAILED;
6234
6235 /*
6236 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6237 */
6238 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6239 bgp_get_default(), bgp);
6240
6241 if (yes) {
6242 bgp->vpn_policy[afi].tovpn_rd = prd;
6243 SET_FLAG(bgp->vpn_policy[afi].flags,
6244 BGP_VPN_POLICY_TOVPN_RD_SET);
6245 } else {
6246 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6247 BGP_VPN_POLICY_TOVPN_RD_SET);
6248 }
6249
6250 /* post-change: re-export vpn routes */
6251 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6252 bgp_get_default(), bgp);
6253
6254 return CMD_SUCCESS;
6255 }
6256
6257 ALIAS (af_rd_vpn_export,
6258 af_no_rd_vpn_export_cmd,
6259 "no rd vpn export",
6260 NO_STR
6261 "Specify route distinguisher\n"
6262 "Between current address-family and vpn\n"
6263 "For routes leaked from current address-family to vpn\n")
6264
6265 DEFPY (af_label_vpn_export,
6266 af_label_vpn_export_cmd,
6267 "[no] label vpn export <(0-1048575)$label_val|auto$label_auto>",
6268 NO_STR
6269 "label value for VRF\n"
6270 "Between current address-family and vpn\n"
6271 "For routes leaked from current address-family to vpn\n"
6272 "Label Value <0-1048575>\n"
6273 "Automatically assign a label\n")
6274 {
6275 VTY_DECLVAR_CONTEXT(bgp, bgp);
6276 mpls_label_t label = MPLS_LABEL_NONE;
6277 afi_t afi;
6278 int idx = 0;
6279 int yes = 1;
6280
6281 if (argv_find(argv, argc, "no", &idx))
6282 yes = 0;
6283
6284 if (yes) {
6285 if (!label_auto)
6286 label = label_val; /* parser should force unsigned */
6287 }
6288
6289 afi = vpn_policy_getafi(vty, bgp, false);
6290 if (afi == AFI_MAX)
6291 return CMD_WARNING_CONFIG_FAILED;
6292
6293
6294 if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6295 BGP_VPN_POLICY_TOVPN_LABEL_AUTO))
6296 /* no change */
6297 return CMD_SUCCESS;
6298
6299 /*
6300 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6301 */
6302 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6303 bgp_get_default(), bgp);
6304
6305 if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags,
6306 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
6307
6308 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
6309
6310 /*
6311 * label has previously been automatically
6312 * assigned by labelpool: release it
6313 *
6314 * NB if tovpn_label == MPLS_LABEL_NONE it
6315 * means the automatic assignment is in flight
6316 * and therefore the labelpool callback must
6317 * detect that the auto label is not needed.
6318 */
6319
6320 bgp_lp_release(LP_TYPE_VRF,
6321 &bgp->vpn_policy[afi],
6322 bgp->vpn_policy[afi].tovpn_label);
6323 }
6324 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6325 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6326 }
6327
6328 bgp->vpn_policy[afi].tovpn_label = label;
6329 if (label_auto) {
6330 SET_FLAG(bgp->vpn_policy[afi].flags,
6331 BGP_VPN_POLICY_TOVPN_LABEL_AUTO);
6332 bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi],
6333 vpn_leak_label_callback);
6334 }
6335
6336 /* post-change: re-export vpn routes */
6337 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6338 bgp_get_default(), bgp);
6339
6340 return CMD_SUCCESS;
6341 }
6342
6343 ALIAS (af_label_vpn_export,
6344 af_no_label_vpn_export_cmd,
6345 "no label vpn export",
6346 NO_STR
6347 "label value for VRF\n"
6348 "Between current address-family and vpn\n"
6349 "For routes leaked from current address-family to vpn\n")
6350
6351 DEFPY (af_nexthop_vpn_export,
6352 af_nexthop_vpn_export_cmd,
6353 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6354 NO_STR
6355 "Specify next hop to use for VRF advertised prefixes\n"
6356 "Between current address-family and vpn\n"
6357 "For routes leaked from current address-family to vpn\n"
6358 "IPv4 prefix\n"
6359 "IPv6 prefix\n")
6360 {
6361 VTY_DECLVAR_CONTEXT(bgp, bgp);
6362 afi_t afi;
6363 struct prefix p;
6364 int idx = 0;
6365 int yes = 1;
6366
6367 if (argv_find(argv, argc, "no", &idx))
6368 yes = 0;
6369
6370 if (yes) {
6371 if (!sockunion2hostprefix(nexthop_str, &p))
6372 return CMD_WARNING_CONFIG_FAILED;
6373 }
6374
6375 afi = vpn_policy_getafi(vty, bgp, false);
6376 if (afi == AFI_MAX)
6377 return CMD_WARNING_CONFIG_FAILED;
6378
6379 /*
6380 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6381 */
6382 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6383 bgp_get_default(), bgp);
6384
6385 if (yes) {
6386 bgp->vpn_policy[afi].tovpn_nexthop = p;
6387 SET_FLAG(bgp->vpn_policy[afi].flags,
6388 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6389 } else {
6390 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6391 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6392 }
6393
6394 /* post-change: re-export vpn routes */
6395 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6396 bgp_get_default(), bgp);
6397
6398 return CMD_SUCCESS;
6399 }
6400
6401 ALIAS (af_nexthop_vpn_export,
6402 af_no_nexthop_vpn_export_cmd,
6403 "no nexthop vpn export",
6404 NO_STR
6405 "Specify next hop to use for VRF advertised prefixes\n"
6406 "Between current address-family and vpn\n"
6407 "For routes leaked from current address-family to vpn\n")
6408
6409 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6410 {
6411 if (!strcmp(dstr, "import")) {
6412 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6413 } else if (!strcmp(dstr, "export")) {
6414 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6415 } else if (!strcmp(dstr, "both")) {
6416 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6417 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6418 } else {
6419 vty_out(vty, "%% direction parse error\n");
6420 return CMD_WARNING_CONFIG_FAILED;
6421 }
6422 return CMD_SUCCESS;
6423 }
6424
6425 DEFPY (af_rt_vpn_imexport,
6426 af_rt_vpn_imexport_cmd,
6427 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6428 NO_STR
6429 "Specify route target list\n"
6430 "Specify route target list\n"
6431 "Between current address-family and vpn\n"
6432 "For routes leaked from vpn to current address-family: match any\n"
6433 "For routes leaked from current address-family to vpn: set\n"
6434 "both import: match any and export: set\n"
6435 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6436 {
6437 VTY_DECLVAR_CONTEXT(bgp, bgp);
6438 int ret;
6439 struct ecommunity *ecom = NULL;
6440 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6441 vpn_policy_direction_t dir;
6442 afi_t afi;
6443 int idx = 0;
6444 int yes = 1;
6445
6446 if (argv_find(argv, argc, "no", &idx))
6447 yes = 0;
6448
6449 afi = vpn_policy_getafi(vty, bgp, false);
6450 if (afi == AFI_MAX)
6451 return CMD_WARNING_CONFIG_FAILED;
6452
6453 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6454 if (ret != CMD_SUCCESS)
6455 return ret;
6456
6457 if (yes) {
6458 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6459 vty_out(vty, "%% Missing RTLIST\n");
6460 return CMD_WARNING_CONFIG_FAILED;
6461 }
6462 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6463 if (ret != CMD_SUCCESS) {
6464 return ret;
6465 }
6466 }
6467
6468 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6469 if (!dodir[dir])
6470 continue;
6471
6472 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6473
6474 if (yes) {
6475 if (bgp->vpn_policy[afi].rtlist[dir])
6476 ecommunity_free(
6477 &bgp->vpn_policy[afi].rtlist[dir]);
6478 bgp->vpn_policy[afi].rtlist[dir] =
6479 ecommunity_dup(ecom);
6480 } else {
6481 if (bgp->vpn_policy[afi].rtlist[dir])
6482 ecommunity_free(
6483 &bgp->vpn_policy[afi].rtlist[dir]);
6484 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6485 }
6486
6487 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6488 }
6489
6490 if (ecom)
6491 ecommunity_free(&ecom);
6492
6493 return CMD_SUCCESS;
6494 }
6495
6496 ALIAS (af_rt_vpn_imexport,
6497 af_no_rt_vpn_imexport_cmd,
6498 "no <rt|route-target> vpn <import|export|both>$direction_str",
6499 NO_STR
6500 "Specify route target list\n"
6501 "Specify route target list\n"
6502 "Between current address-family and vpn\n"
6503 "For routes leaked from vpn to current address-family\n"
6504 "For routes leaked from current address-family to vpn\n"
6505 "both import and export\n")
6506
6507 DEFPY (af_route_map_vpn_imexport,
6508 af_route_map_vpn_imexport_cmd,
6509 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6510 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6511 NO_STR
6512 "Specify route map\n"
6513 "Between current address-family and vpn\n"
6514 "For routes leaked from vpn to current address-family\n"
6515 "For routes leaked from current address-family to vpn\n"
6516 "name of route-map\n")
6517 {
6518 VTY_DECLVAR_CONTEXT(bgp, bgp);
6519 int ret;
6520 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6521 vpn_policy_direction_t dir;
6522 afi_t afi;
6523 int idx = 0;
6524 int yes = 1;
6525
6526 if (argv_find(argv, argc, "no", &idx))
6527 yes = 0;
6528
6529 afi = vpn_policy_getafi(vty, bgp, false);
6530 if (afi == AFI_MAX)
6531 return CMD_WARNING_CONFIG_FAILED;
6532
6533 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6534 if (ret != CMD_SUCCESS)
6535 return ret;
6536
6537 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6538 if (!dodir[dir])
6539 continue;
6540
6541 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6542
6543 if (yes) {
6544 if (bgp->vpn_policy[afi].rmap_name[dir])
6545 XFREE(MTYPE_ROUTE_MAP_NAME,
6546 bgp->vpn_policy[afi].rmap_name[dir]);
6547 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6548 MTYPE_ROUTE_MAP_NAME, rmap_str);
6549 bgp->vpn_policy[afi].rmap[dir] =
6550 route_map_lookup_by_name(rmap_str);
6551 if (!bgp->vpn_policy[afi].rmap[dir])
6552 return CMD_SUCCESS;
6553 } else {
6554 if (bgp->vpn_policy[afi].rmap_name[dir])
6555 XFREE(MTYPE_ROUTE_MAP_NAME,
6556 bgp->vpn_policy[afi].rmap_name[dir]);
6557 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6558 bgp->vpn_policy[afi].rmap[dir] = NULL;
6559 }
6560
6561 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6562 }
6563
6564 return CMD_SUCCESS;
6565 }
6566
6567 ALIAS (af_route_map_vpn_imexport,
6568 af_no_route_map_vpn_imexport_cmd,
6569 "no route-map vpn <import|export>$direction_str",
6570 NO_STR
6571 "Specify route map\n"
6572 "Between current address-family and vpn\n"
6573 "For routes leaked from vpn to current address-family\n"
6574 "For routes leaked from current address-family to vpn\n")
6575
6576 DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
6577 "[no] import vrf route-map RMAP$rmap_str",
6578 NO_STR
6579 "Import routes from another VRF\n"
6580 "Vrf routes being filtered\n"
6581 "Specify route map\n"
6582 "name of route-map\n")
6583 {
6584 VTY_DECLVAR_CONTEXT(bgp, bgp);
6585 vpn_policy_direction_t dir = BGP_VPN_POLICY_DIR_FROMVPN;
6586 afi_t afi;
6587 int idx = 0;
6588 int yes = 1;
6589 struct bgp *bgp_default;
6590
6591 if (argv_find(argv, argc, "no", &idx))
6592 yes = 0;
6593
6594 afi = vpn_policy_getafi(vty, bgp, true);
6595 if (afi == AFI_MAX)
6596 return CMD_WARNING_CONFIG_FAILED;
6597
6598 bgp_default = bgp_get_default();
6599 if (!bgp_default) {
6600 int32_t ret;
6601 as_t as = bgp->as;
6602
6603 /* Auto-create assuming the same AS */
6604 ret = bgp_get(&bgp_default, &as, NULL,
6605 BGP_INSTANCE_TYPE_DEFAULT);
6606
6607 if (ret) {
6608 vty_out(vty,
6609 "VRF default is not configured as a bgp instance\n");
6610 return CMD_WARNING;
6611 }
6612 }
6613
6614 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6615
6616 if (yes) {
6617 if (bgp->vpn_policy[afi].rmap_name[dir])
6618 XFREE(MTYPE_ROUTE_MAP_NAME,
6619 bgp->vpn_policy[afi].rmap_name[dir]);
6620 bgp->vpn_policy[afi].rmap_name[dir] =
6621 XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
6622 bgp->vpn_policy[afi].rmap[dir] =
6623 route_map_lookup_by_name(rmap_str);
6624 if (!bgp->vpn_policy[afi].rmap[dir])
6625 return CMD_SUCCESS;
6626 } else {
6627 if (bgp->vpn_policy[afi].rmap_name[dir])
6628 XFREE(MTYPE_ROUTE_MAP_NAME,
6629 bgp->vpn_policy[afi].rmap_name[dir]);
6630 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6631 bgp->vpn_policy[afi].rmap[dir] = NULL;
6632 }
6633
6634 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6635
6636 return CMD_SUCCESS;
6637 }
6638
6639 ALIAS(af_import_vrf_route_map, af_no_import_vrf_route_map_cmd,
6640 "no import vrf route-map",
6641 NO_STR
6642 "Import routes from another VRF\n"
6643 "Vrf routes being filtered\n"
6644 "Specify route map\n")
6645
6646 DEFPY (bgp_imexport_vrf,
6647 bgp_imexport_vrf_cmd,
6648 "[no] import vrf NAME$import_name",
6649 NO_STR
6650 "Import routes from another VRF\n"
6651 "VRF to import from\n"
6652 "The name of the VRF\n")
6653 {
6654 VTY_DECLVAR_CONTEXT(bgp, bgp);
6655 struct listnode *node;
6656 struct bgp *vrf_bgp, *bgp_default;
6657 int32_t ret = 0;
6658 as_t as = bgp->as;
6659 bool remove = false;
6660 int32_t idx = 0;
6661 char *vname;
6662 enum bgp_instance_type bgp_type = BGP_INSTANCE_TYPE_VRF;
6663 safi_t safi;
6664 afi_t afi;
6665
6666 if (argv_find(argv, argc, "no", &idx))
6667 remove = true;
6668
6669 afi = vpn_policy_getafi(vty, bgp, true);
6670 if (afi == AFI_MAX)
6671 return CMD_WARNING_CONFIG_FAILED;
6672
6673 safi = bgp_node_safi(vty);
6674
6675 if (((BGP_INSTANCE_TYPE_DEFAULT == bgp->inst_type)
6676 && (strcmp(import_name, BGP_DEFAULT_NAME) == 0))
6677 || (bgp->name && (strcmp(import_name, bgp->name) == 0))) {
6678 vty_out(vty, "%% Cannot %s vrf %s into itself\n",
6679 remove ? "unimport" : "import", import_name);
6680 return CMD_WARNING;
6681 }
6682
6683 bgp_default = bgp_get_default();
6684 if (!bgp_default) {
6685 /* Auto-create assuming the same AS */
6686 ret = bgp_get(&bgp_default, &as, NULL,
6687 BGP_INSTANCE_TYPE_DEFAULT);
6688
6689 if (ret) {
6690 vty_out(vty,
6691 "VRF default is not configured as a bgp instance\n");
6692 return CMD_WARNING;
6693 }
6694 }
6695
6696 vrf_bgp = bgp_lookup_by_name(import_name);
6697 if (!vrf_bgp) {
6698 if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
6699 vrf_bgp = bgp_default;
6700 else
6701 /* Auto-create assuming the same AS */
6702 ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
6703
6704 if (ret) {
6705 vty_out(vty,
6706 "VRF %s is not configured as a bgp instance\n",
6707 import_name);
6708 return CMD_WARNING;
6709 }
6710 }
6711
6712 if (remove) {
6713 vrf_unimport_from_vrf(bgp, vrf_bgp, afi, safi);
6714 } else {
6715 /* Already importing from "import_vrf"? */
6716 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
6717 vname)) {
6718 if (strcmp(vname, import_name) == 0)
6719 return CMD_WARNING;
6720 }
6721
6722 vrf_import_from_vrf(bgp, vrf_bgp, afi, safi);
6723 }
6724
6725 return CMD_SUCCESS;
6726 }
6727
6728 /* This command is valid only in a bgp vrf instance or the default instance */
6729 DEFPY (bgp_imexport_vpn,
6730 bgp_imexport_vpn_cmd,
6731 "[no] <import|export>$direction_str vpn",
6732 NO_STR
6733 "Import routes to this address-family\n"
6734 "Export routes from this address-family\n"
6735 "to/from default instance VPN RIB\n")
6736 {
6737 VTY_DECLVAR_CONTEXT(bgp, bgp);
6738 int previous_state;
6739 afi_t afi;
6740 safi_t safi;
6741 int idx = 0;
6742 int yes = 1;
6743 int flag;
6744 vpn_policy_direction_t dir;
6745
6746 if (argv_find(argv, argc, "no", &idx))
6747 yes = 0;
6748
6749 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6750 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6751
6752 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6753 return CMD_WARNING_CONFIG_FAILED;
6754 }
6755
6756 afi = bgp_node_afi(vty);
6757 safi = bgp_node_safi(vty);
6758 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6759 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6760 return CMD_WARNING_CONFIG_FAILED;
6761 }
6762
6763 if (!strcmp(direction_str, "import")) {
6764 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6765 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6766 } else if (!strcmp(direction_str, "export")) {
6767 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6768 dir = BGP_VPN_POLICY_DIR_TOVPN;
6769 } else {
6770 vty_out(vty, "%% unknown direction %s\n", direction_str);
6771 return CMD_WARNING_CONFIG_FAILED;
6772 }
6773
6774 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6775
6776 if (yes) {
6777 SET_FLAG(bgp->af_flags[afi][safi], flag);
6778 if (!previous_state) {
6779 /* trigger export current vrf */
6780 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6781 }
6782 } else {
6783 if (previous_state) {
6784 /* trigger un-export current vrf */
6785 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6786 }
6787 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6788 }
6789
6790 return CMD_SUCCESS;
6791 }
6792
6793 DEFPY (af_routetarget_import,
6794 af_routetarget_import_cmd,
6795 "[no] <rt|route-target> redirect import RTLIST...",
6796 NO_STR
6797 "Specify route target list\n"
6798 "Specify route target list\n"
6799 "Flow-spec redirect type route target\n"
6800 "Import routes to this address-family\n"
6801 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6802 {
6803 VTY_DECLVAR_CONTEXT(bgp, bgp);
6804 int ret;
6805 struct ecommunity *ecom = NULL;
6806 afi_t afi;
6807 int idx = 0;
6808 int yes = 1;
6809
6810 if (argv_find(argv, argc, "no", &idx))
6811 yes = 0;
6812
6813 afi = vpn_policy_getafi(vty, bgp, false);
6814 if (afi == AFI_MAX)
6815 return CMD_WARNING_CONFIG_FAILED;
6816
6817 if (yes) {
6818 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6819 vty_out(vty, "%% Missing RTLIST\n");
6820 return CMD_WARNING_CONFIG_FAILED;
6821 }
6822 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6823 if (ret != CMD_SUCCESS)
6824 return ret;
6825 }
6826
6827 if (yes) {
6828 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6829 ecommunity_free(&bgp->vpn_policy[afi]
6830 .import_redirect_rtlist);
6831 bgp->vpn_policy[afi].import_redirect_rtlist =
6832 ecommunity_dup(ecom);
6833 } else {
6834 if (bgp->vpn_policy[afi].import_redirect_rtlist)
6835 ecommunity_free(&bgp->vpn_policy[afi]
6836 .import_redirect_rtlist);
6837 bgp->vpn_policy[afi].import_redirect_rtlist = NULL;
6838 }
6839
6840 if (ecom)
6841 ecommunity_free(&ecom);
6842
6843 return CMD_SUCCESS;
6844 }
6845
6846 DEFUN_NOSH (address_family_ipv4_safi,
6847 address_family_ipv4_safi_cmd,
6848 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6849 "Enter Address Family command mode\n"
6850 "Address Family\n"
6851 BGP_SAFI_WITH_LABEL_HELP_STR)
6852 {
6853
6854 if (argc == 3) {
6855 VTY_DECLVAR_CONTEXT(bgp, bgp);
6856 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6857 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6858 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6859 && safi != SAFI_EVPN) {
6860 vty_out(vty,
6861 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6862 return CMD_WARNING_CONFIG_FAILED;
6863 }
6864 vty->node = bgp_node_type(AFI_IP, safi);
6865 } else
6866 vty->node = BGP_IPV4_NODE;
6867
6868 return CMD_SUCCESS;
6869 }
6870
6871 DEFUN_NOSH (address_family_ipv6_safi,
6872 address_family_ipv6_safi_cmd,
6873 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]",
6874 "Enter Address Family command mode\n"
6875 "Address Family\n"
6876 BGP_SAFI_WITH_LABEL_HELP_STR)
6877 {
6878 if (argc == 3) {
6879 VTY_DECLVAR_CONTEXT(bgp, bgp);
6880 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6881 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6882 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6883 && safi != SAFI_EVPN) {
6884 vty_out(vty,
6885 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6886 return CMD_WARNING_CONFIG_FAILED;
6887 }
6888 vty->node = bgp_node_type(AFI_IP6, safi);
6889 } else
6890 vty->node = BGP_IPV6_NODE;
6891
6892 return CMD_SUCCESS;
6893 }
6894
6895 #ifdef KEEP_OLD_VPN_COMMANDS
6896 DEFUN_NOSH (address_family_vpnv4,
6897 address_family_vpnv4_cmd,
6898 "address-family vpnv4 [unicast]",
6899 "Enter Address Family command mode\n"
6900 "Address Family\n"
6901 "Address Family modifier\n")
6902 {
6903 vty->node = BGP_VPNV4_NODE;
6904 return CMD_SUCCESS;
6905 }
6906
6907 DEFUN_NOSH (address_family_vpnv6,
6908 address_family_vpnv6_cmd,
6909 "address-family vpnv6 [unicast]",
6910 "Enter Address Family command mode\n"
6911 "Address Family\n"
6912 "Address Family modifier\n")
6913 {
6914 vty->node = BGP_VPNV6_NODE;
6915 return CMD_SUCCESS;
6916 }
6917 #endif
6918
6919 DEFUN_NOSH (address_family_evpn,
6920 address_family_evpn_cmd,
6921 "address-family l2vpn evpn",
6922 "Enter Address Family command mode\n"
6923 "Address Family\n"
6924 "Address Family modifier\n")
6925 {
6926 VTY_DECLVAR_CONTEXT(bgp, bgp);
6927 vty->node = BGP_EVPN_NODE;
6928 return CMD_SUCCESS;
6929 }
6930
6931 DEFUN_NOSH (exit_address_family,
6932 exit_address_family_cmd,
6933 "exit-address-family",
6934 "Exit from Address Family configuration mode\n")
6935 {
6936 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6937 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6938 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6939 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6940 || vty->node == BGP_EVPN_NODE
6941 || vty->node == BGP_FLOWSPECV4_NODE
6942 || vty->node == BGP_FLOWSPECV6_NODE)
6943 vty->node = BGP_NODE;
6944 return CMD_SUCCESS;
6945 }
6946
6947 /* Recalculate bestpath and re-advertise a prefix */
6948 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6949 const char *ip_str, afi_t afi, safi_t safi,
6950 struct prefix_rd *prd)
6951 {
6952 int ret;
6953 struct prefix match;
6954 struct bgp_node *rn;
6955 struct bgp_node *rm;
6956 struct bgp *bgp;
6957 struct bgp_table *table;
6958 struct bgp_table *rib;
6959
6960 /* BGP structure lookup. */
6961 if (view_name) {
6962 bgp = bgp_lookup_by_name(view_name);
6963 if (bgp == NULL) {
6964 vty_out(vty, "%% Can't find BGP instance %s\n",
6965 view_name);
6966 return CMD_WARNING;
6967 }
6968 } else {
6969 bgp = bgp_get_default();
6970 if (bgp == NULL) {
6971 vty_out(vty, "%% No BGP process is configured\n");
6972 return CMD_WARNING;
6973 }
6974 }
6975
6976 /* Check IP address argument. */
6977 ret = str2prefix(ip_str, &match);
6978 if (!ret) {
6979 vty_out(vty, "%% address is malformed\n");
6980 return CMD_WARNING;
6981 }
6982
6983 match.family = afi2family(afi);
6984 rib = bgp->rib[afi][safi];
6985
6986 if (safi == SAFI_MPLS_VPN) {
6987 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6988 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6989 continue;
6990
6991 if ((table = rn->info) != NULL) {
6992 if ((rm = bgp_node_match(table, &match))
6993 != NULL) {
6994 if (rm->p.prefixlen
6995 == match.prefixlen) {
6996 SET_FLAG(rn->flags,
6997 BGP_NODE_USER_CLEAR);
6998 bgp_process(bgp, rm, afi, safi);
6999 }
7000 bgp_unlock_node(rm);
7001 }
7002 }
7003 }
7004 } else {
7005 if ((rn = bgp_node_match(rib, &match)) != NULL) {
7006 if (rn->p.prefixlen == match.prefixlen) {
7007 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
7008 bgp_process(bgp, rn, afi, safi);
7009 }
7010 bgp_unlock_node(rn);
7011 }
7012 }
7013
7014 return CMD_SUCCESS;
7015 }
7016
7017 /* one clear bgp command to rule them all */
7018 DEFUN (clear_ip_bgp_all,
7019 clear_ip_bgp_all_cmd,
7020 "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>]",
7021 CLEAR_STR
7022 IP_STR
7023 BGP_STR
7024 BGP_INSTANCE_HELP_STR
7025 BGP_AFI_HELP_STR
7026 BGP_SAFI_WITH_LABEL_HELP_STR
7027 "Clear all peers\n"
7028 "BGP neighbor address to clear\n"
7029 "BGP IPv6 neighbor to clear\n"
7030 "BGP neighbor on interface to clear\n"
7031 "Clear peers with the AS number\n"
7032 "Clear all external peers\n"
7033 "Clear all members of peer-group\n"
7034 "BGP peer-group name\n"
7035 BGP_SOFT_STR
7036 BGP_SOFT_IN_STR
7037 BGP_SOFT_OUT_STR
7038 BGP_SOFT_IN_STR
7039 "Push out prefix-list ORF and do inbound soft reconfig\n"
7040 BGP_SOFT_OUT_STR)
7041 {
7042 char *vrf = NULL;
7043
7044 afi_t afi = AFI_IP6;
7045 safi_t safi = SAFI_UNICAST;
7046 enum clear_sort clr_sort = clear_peer;
7047 enum bgp_clear_type clr_type;
7048 char *clr_arg = NULL;
7049
7050 int idx = 0;
7051
7052 /* clear [ip] bgp */
7053 if (argv_find(argv, argc, "ip", &idx))
7054 afi = AFI_IP;
7055
7056 /* [<view|vrf> VIEWVRFNAME] */
7057 if (argv_find(argv, argc, "view", &idx)
7058 || argv_find(argv, argc, "vrf", &idx)) {
7059 vrf = argv[idx + 1]->arg;
7060 idx += 2;
7061 }
7062
7063 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7064 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
7065 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7066
7067 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
7068 if (argv_find(argv, argc, "*", &idx)) {
7069 clr_sort = clear_all;
7070 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7071 clr_sort = clear_peer;
7072 clr_arg = argv[idx]->arg;
7073 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
7074 clr_sort = clear_peer;
7075 clr_arg = argv[idx]->arg;
7076 } else if (argv_find(argv, argc, "peer-group", &idx)) {
7077 clr_sort = clear_group;
7078 idx++;
7079 clr_arg = argv[idx]->arg;
7080 } else if (argv_find(argv, argc, "WORD", &idx)) {
7081 clr_sort = clear_peer;
7082 clr_arg = argv[idx]->arg;
7083 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
7084 clr_sort = clear_as;
7085 clr_arg = argv[idx]->arg;
7086 } else if (argv_find(argv, argc, "external", &idx)) {
7087 clr_sort = clear_external;
7088 }
7089
7090 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
7091 if (argv_find(argv, argc, "soft", &idx)) {
7092 if (argv_find(argv, argc, "in", &idx)
7093 || argv_find(argv, argc, "out", &idx))
7094 clr_type = strmatch(argv[idx]->text, "in")
7095 ? BGP_CLEAR_SOFT_IN
7096 : BGP_CLEAR_SOFT_OUT;
7097 else
7098 clr_type = BGP_CLEAR_SOFT_BOTH;
7099 } else if (argv_find(argv, argc, "in", &idx)) {
7100 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
7101 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
7102 : BGP_CLEAR_SOFT_IN;
7103 } else if (argv_find(argv, argc, "out", &idx)) {
7104 clr_type = BGP_CLEAR_SOFT_OUT;
7105 } else
7106 clr_type = BGP_CLEAR_SOFT_NONE;
7107
7108 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
7109 }
7110
7111 DEFUN (clear_ip_bgp_prefix,
7112 clear_ip_bgp_prefix_cmd,
7113 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
7114 CLEAR_STR
7115 IP_STR
7116 BGP_STR
7117 BGP_INSTANCE_HELP_STR
7118 "Clear bestpath and re-advertise\n"
7119 "IPv4 prefix\n")
7120 {
7121 char *vrf = NULL;
7122 char *prefix = NULL;
7123
7124 int idx = 0;
7125
7126 /* [<view|vrf> VIEWVRFNAME] */
7127 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
7128 vrf = argv[idx]->arg;
7129
7130 prefix = argv[argc - 1]->arg;
7131
7132 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
7133 }
7134
7135 DEFUN (clear_bgp_ipv6_safi_prefix,
7136 clear_bgp_ipv6_safi_prefix_cmd,
7137 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7138 CLEAR_STR
7139 IP_STR
7140 BGP_STR
7141 "Address Family\n"
7142 BGP_SAFI_HELP_STR
7143 "Clear bestpath and re-advertise\n"
7144 "IPv6 prefix\n")
7145 {
7146 int idx_safi = 0;
7147 int idx_ipv6_prefix = 0;
7148 safi_t safi = SAFI_UNICAST;
7149 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7150 argv[idx_ipv6_prefix]->arg : NULL;
7151
7152 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7153 return bgp_clear_prefix(
7154 vty, NULL, prefix, AFI_IP6,
7155 safi, NULL);
7156 }
7157
7158 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
7159 clear_bgp_instance_ipv6_safi_prefix_cmd,
7160 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
7161 CLEAR_STR
7162 IP_STR
7163 BGP_STR
7164 BGP_INSTANCE_HELP_STR
7165 "Address Family\n"
7166 BGP_SAFI_HELP_STR
7167 "Clear bestpath and re-advertise\n"
7168 "IPv6 prefix\n")
7169 {
7170 int idx_word = 3;
7171 int idx_safi = 0;
7172 int idx_ipv6_prefix = 0;
7173 safi_t safi = SAFI_UNICAST;
7174 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
7175 argv[idx_ipv6_prefix]->arg : NULL;
7176 /* [<view|vrf> VIEWVRFNAME] */
7177 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
7178 argv[idx_word]->arg : NULL;
7179
7180 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
7181
7182 return bgp_clear_prefix(
7183 vty, vrfview, prefix,
7184 AFI_IP6, safi, NULL);
7185 }
7186
7187 DEFUN (show_bgp_views,
7188 show_bgp_views_cmd,
7189 "show [ip] bgp views",
7190 SHOW_STR
7191 IP_STR
7192 BGP_STR
7193 "Show the defined BGP views\n")
7194 {
7195 struct list *inst = bm->bgp;
7196 struct listnode *node;
7197 struct bgp *bgp;
7198
7199 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7200 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7201 return CMD_WARNING;
7202 }
7203
7204 vty_out(vty, "Defined BGP views:\n");
7205 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7206 /* Skip VRFs. */
7207 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
7208 continue;
7209 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
7210 bgp->as);
7211 }
7212
7213 return CMD_SUCCESS;
7214 }
7215
7216 DEFUN (show_bgp_vrfs,
7217 show_bgp_vrfs_cmd,
7218 "show [ip] bgp vrfs [json]",
7219 SHOW_STR
7220 IP_STR
7221 BGP_STR
7222 "Show BGP VRFs\n"
7223 JSON_STR)
7224 {
7225 char buf[ETHER_ADDR_STRLEN];
7226 struct list *inst = bm->bgp;
7227 struct listnode *node;
7228 struct bgp *bgp;
7229 uint8_t uj = use_json(argc, argv);
7230 json_object *json = NULL;
7231 json_object *json_vrfs = NULL;
7232 int count = 0;
7233
7234 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7235 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7236 return CMD_WARNING;
7237 }
7238
7239 if (uj) {
7240 json = json_object_new_object();
7241 json_vrfs = json_object_new_object();
7242 }
7243
7244 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7245 const char *name, *type;
7246 struct peer *peer;
7247 struct listnode *node, *nnode;
7248 int peers_cfg, peers_estb;
7249 json_object *json_vrf = NULL;
7250
7251 /* Skip Views. */
7252 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7253 continue;
7254
7255 count++;
7256 if (!uj && count == 1)
7257 vty_out(vty,
7258 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
7259 "Type", "Id", "routerId", "#PeersVfg",
7260 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7261
7262 peers_cfg = peers_estb = 0;
7263 if (uj)
7264 json_vrf = json_object_new_object();
7265
7266
7267 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7268 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7269 continue;
7270 peers_cfg++;
7271 if (peer->status == Established)
7272 peers_estb++;
7273 }
7274
7275 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7276 name = "Default";
7277 type = "DFLT";
7278 } else {
7279 name = bgp->name;
7280 type = "VRF";
7281 }
7282
7283
7284 if (uj) {
7285 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7286 ? -1
7287 : (int64_t)bgp->vrf_id;
7288 json_object_string_add(json_vrf, "type", type);
7289 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7290 json_object_string_add(json_vrf, "routerId",
7291 inet_ntoa(bgp->router_id));
7292 json_object_int_add(json_vrf, "numConfiguredPeers",
7293 peers_cfg);
7294 json_object_int_add(json_vrf, "numEstablishedPeers",
7295 peers_estb);
7296
7297 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7298 json_object_string_add(
7299 json_vrf, "rmac",
7300 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7301 json_object_object_add(json_vrfs, name, json_vrf);
7302 } else
7303 vty_out(vty,
7304 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7305 type,
7306 bgp->vrf_id == VRF_UNKNOWN ? -1
7307 : (int)bgp->vrf_id,
7308 inet_ntoa(bgp->router_id), peers_cfg,
7309 peers_estb, name, bgp->l3vni,
7310 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7311 }
7312
7313 if (uj) {
7314 json_object_object_add(json, "vrfs", json_vrfs);
7315
7316 json_object_int_add(json, "totalVrfs", count);
7317
7318 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7319 json, JSON_C_TO_STRING_PRETTY));
7320 json_object_free(json);
7321 } else {
7322 if (count)
7323 vty_out(vty,
7324 "\nTotal number of VRFs (including default): %d\n",
7325 count);
7326 }
7327
7328 return CMD_SUCCESS;
7329 }
7330
7331 static void show_address_entry(struct hash_backet *backet, void *args)
7332 {
7333 struct vty *vty = (struct vty *)args;
7334 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7335
7336 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7337 addr->refcnt);
7338 }
7339
7340 static void show_tip_entry(struct hash_backet *backet, void *args)
7341 {
7342 struct vty *vty = (struct vty *)args;
7343 struct tip_addr *tip = (struct tip_addr *)backet->data;
7344
7345 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7346 tip->refcnt);
7347 }
7348
7349 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7350 {
7351 vty_out(vty, "self nexthop database:\n");
7352 hash_iterate(bgp->address_hash,
7353 (void (*)(struct hash_backet *, void *))show_address_entry,
7354 vty);
7355
7356 vty_out(vty, "Tunnel-ip database:\n");
7357 hash_iterate(bgp->tip_hash,
7358 (void (*)(struct hash_backet *, void *))show_tip_entry,
7359 vty);
7360 }
7361
7362 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7363 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7364 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7365 "martian next-hops\n"
7366 "martian next-hop database\n")
7367 {
7368 struct bgp *bgp = NULL;
7369 int idx = 0;
7370
7371 if (argv_find(argv, argc, "view", &idx)
7372 || argv_find(argv, argc, "vrf", &idx))
7373 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7374 else
7375 bgp = bgp_get_default();
7376
7377 if (!bgp) {
7378 vty_out(vty, "%% No BGP process is configured\n");
7379 return CMD_WARNING;
7380 }
7381 bgp_show_martian_nexthops(vty, bgp);
7382
7383 return CMD_SUCCESS;
7384 }
7385
7386 DEFUN (show_bgp_memory,
7387 show_bgp_memory_cmd,
7388 "show [ip] bgp memory",
7389 SHOW_STR
7390 IP_STR
7391 BGP_STR
7392 "Global BGP memory statistics\n")
7393 {
7394 char memstrbuf[MTYPE_MEMSTR_LEN];
7395 unsigned long count;
7396
7397 /* RIB related usage stats */
7398 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7399 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7400 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7401 count * sizeof(struct bgp_node)));
7402
7403 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7404 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7405 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7406 count * sizeof(struct bgp_info)));
7407 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7408 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7409 count,
7410 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7411 count * sizeof(struct bgp_info_extra)));
7412
7413 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7414 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7415 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7416 count * sizeof(struct bgp_static)));
7417
7418 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7419 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7420 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7421 count * sizeof(struct bpacket)));
7422
7423 /* Adj-In/Out */
7424 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7425 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7426 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7427 count * sizeof(struct bgp_adj_in)));
7428 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7429 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7430 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7431 count * sizeof(struct bgp_adj_out)));
7432
7433 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7434 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7435 count,
7436 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7437 count * sizeof(struct bgp_nexthop_cache)));
7438
7439 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7440 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7441 count,
7442 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7443 count * sizeof(struct bgp_damp_info)));
7444
7445 /* Attributes */
7446 count = attr_count();
7447 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7448 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7449 count * sizeof(struct attr)));
7450
7451 if ((count = attr_unknown_count()))
7452 vty_out(vty, "%ld unknown attributes\n", count);
7453
7454 /* AS_PATH attributes */
7455 count = aspath_count();
7456 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7457 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7458 count * sizeof(struct aspath)));
7459
7460 count = mtype_stats_alloc(MTYPE_AS_SEG);
7461 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7462 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7463 count * sizeof(struct assegment)));
7464
7465 /* Other attributes */
7466 if ((count = community_count()))
7467 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7468 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7469 count * sizeof(struct community)));
7470 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7471 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7472 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7473 count * sizeof(struct ecommunity)));
7474 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7475 vty_out(vty,
7476 "%ld BGP large-community entries, using %s of memory\n",
7477 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7478 count * sizeof(struct lcommunity)));
7479
7480 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7481 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7482 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7483 count * sizeof(struct cluster_list)));
7484
7485 /* Peer related usage */
7486 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7487 vty_out(vty, "%ld peers, using %s of memory\n", count,
7488 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7489 count * sizeof(struct peer)));
7490
7491 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7492 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7493 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7494 count * sizeof(struct peer_group)));
7495
7496 /* Other */
7497 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7498 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7499 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7500 count * sizeof(struct hash)));
7501 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7502 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7503 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7504 count * sizeof(struct hash_backet)));
7505 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7506 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7507 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7508 count * sizeof(regex_t)));
7509 return CMD_SUCCESS;
7510 }
7511
7512 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7513 {
7514 json_object *bestpath = json_object_new_object();
7515
7516 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7517 json_object_string_add(bestpath, "asPath", "ignore");
7518
7519 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7520 json_object_string_add(bestpath, "asPath", "confed");
7521
7522 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7523 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7524 json_object_string_add(bestpath, "multiPathRelax",
7525 "as-set");
7526 else
7527 json_object_string_add(bestpath, "multiPathRelax",
7528 "true");
7529 } else
7530 json_object_string_add(bestpath, "multiPathRelax", "false");
7531
7532 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7533 json_object_string_add(bestpath, "compareRouterId", "true");
7534 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7535 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7536 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7537 json_object_string_add(bestpath, "med", "confed");
7538 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7539 json_object_string_add(bestpath, "med",
7540 "missing-as-worst");
7541 else
7542 json_object_string_add(bestpath, "med", "true");
7543 }
7544
7545 json_object_object_add(json, "bestPath", bestpath);
7546 }
7547
7548 /* Show BGP peer's summary information. */
7549 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7550 uint8_t use_json, json_object *json)
7551 {
7552 struct peer *peer;
7553 struct listnode *node, *nnode;
7554 unsigned int count = 0, dn_count = 0;
7555 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7556 char neighbor_buf[VTY_BUFSIZ];
7557 int neighbor_col_default_width = 16;
7558 int len;
7559 int max_neighbor_width = 0;
7560 int pfx_rcd_safi;
7561 json_object *json_peer = NULL;
7562 json_object *json_peers = NULL;
7563
7564 /* labeled-unicast routes are installed in the unicast table so in order
7565 * to
7566 * display the correct PfxRcd value we must look at SAFI_UNICAST
7567 */
7568 if (safi == SAFI_LABELED_UNICAST)
7569 pfx_rcd_safi = SAFI_UNICAST;
7570 else
7571 pfx_rcd_safi = safi;
7572
7573 if (use_json) {
7574 if (json == NULL)
7575 json = json_object_new_object();
7576
7577 json_peers = json_object_new_object();
7578 } else {
7579 /* Loop over all neighbors that will be displayed to determine
7580 * how many
7581 * characters are needed for the Neighbor column
7582 */
7583 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7584 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7585 continue;
7586
7587 if (peer->afc[afi][safi]) {
7588 memset(dn_flag, '\0', sizeof(dn_flag));
7589 if (peer_dynamic_neighbor(peer))
7590 dn_flag[0] = '*';
7591
7592 if (peer->hostname
7593 && bgp_flag_check(bgp,
7594 BGP_FLAG_SHOW_HOSTNAME))
7595 sprintf(neighbor_buf, "%s%s(%s) ",
7596 dn_flag, peer->hostname,
7597 peer->host);
7598 else
7599 sprintf(neighbor_buf, "%s%s ", dn_flag,
7600 peer->host);
7601
7602 len = strlen(neighbor_buf);
7603
7604 if (len > max_neighbor_width)
7605 max_neighbor_width = len;
7606 }
7607 }
7608
7609 /* Originally we displayed the Neighbor column as 16
7610 * characters wide so make that the default
7611 */
7612 if (max_neighbor_width < neighbor_col_default_width)
7613 max_neighbor_width = neighbor_col_default_width;
7614 }
7615
7616 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7617 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7618 continue;
7619
7620 if (!peer->afc[afi][safi])
7621 continue;
7622
7623 if (!count) {
7624 unsigned long ents;
7625 char memstrbuf[MTYPE_MEMSTR_LEN];
7626 int64_t vrf_id_ui;
7627
7628 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7629 ? -1
7630 : (int64_t)bgp->vrf_id;
7631
7632 /* Usage summary and header */
7633 if (use_json) {
7634 json_object_string_add(
7635 json, "routerId",
7636 inet_ntoa(bgp->router_id));
7637 json_object_int_add(json, "as", bgp->as);
7638 json_object_int_add(json, "vrfId", vrf_id_ui);
7639 json_object_string_add(
7640 json, "vrfName",
7641 (bgp->inst_type
7642 == BGP_INSTANCE_TYPE_DEFAULT)
7643 ? "Default"
7644 : bgp->name);
7645 } else {
7646 vty_out(vty,
7647 "BGP router identifier %s, local AS number %u vrf-id %d",
7648 inet_ntoa(bgp->router_id), bgp->as,
7649 bgp->vrf_id == VRF_UNKNOWN
7650 ? -1
7651 : (int)bgp->vrf_id);
7652 vty_out(vty, "\n");
7653 }
7654
7655 if (bgp_update_delay_configured(bgp)) {
7656 if (use_json) {
7657 json_object_int_add(
7658 json, "updateDelayLimit",
7659 bgp->v_update_delay);
7660
7661 if (bgp->v_update_delay
7662 != bgp->v_establish_wait)
7663 json_object_int_add(
7664 json,
7665 "updateDelayEstablishWait",
7666 bgp->v_establish_wait);
7667
7668 if (bgp_update_delay_active(bgp)) {
7669 json_object_string_add(
7670 json,
7671 "updateDelayFirstNeighbor",
7672 bgp->update_delay_begin_time);
7673 json_object_boolean_true_add(
7674 json,
7675 "updateDelayInProgress");
7676 } else {
7677 if (bgp->update_delay_over) {
7678 json_object_string_add(
7679 json,
7680 "updateDelayFirstNeighbor",
7681 bgp->update_delay_begin_time);
7682 json_object_string_add(
7683 json,
7684 "updateDelayBestpathResumed",
7685 bgp->update_delay_end_time);
7686 json_object_string_add(
7687 json,
7688 "updateDelayZebraUpdateResume",
7689 bgp->update_delay_zebra_resume_time);
7690 json_object_string_add(
7691 json,
7692 "updateDelayPeerUpdateResume",
7693 bgp->update_delay_peers_resume_time);
7694 }
7695 }
7696 } else {
7697 vty_out(vty,
7698 "Read-only mode update-delay limit: %d seconds\n",
7699 bgp->v_update_delay);
7700 if (bgp->v_update_delay
7701 != bgp->v_establish_wait)
7702 vty_out(vty,
7703 " Establish wait: %d seconds\n",
7704 bgp->v_establish_wait);
7705
7706 if (bgp_update_delay_active(bgp)) {
7707 vty_out(vty,
7708 " First neighbor established: %s\n",
7709 bgp->update_delay_begin_time);
7710 vty_out(vty,
7711 " Delay in progress\n");
7712 } else {
7713 if (bgp->update_delay_over) {
7714 vty_out(vty,
7715 " First neighbor established: %s\n",
7716 bgp->update_delay_begin_time);
7717 vty_out(vty,
7718 " Best-paths resumed: %s\n",
7719 bgp->update_delay_end_time);
7720 vty_out(vty,
7721 " zebra update resumed: %s\n",
7722 bgp->update_delay_zebra_resume_time);
7723 vty_out(vty,
7724 " peers update resumed: %s\n",
7725 bgp->update_delay_peers_resume_time);
7726 }
7727 }
7728 }
7729 }
7730
7731 if (use_json) {
7732 if (bgp_maxmed_onstartup_configured(bgp)
7733 && bgp->maxmed_active)
7734 json_object_boolean_true_add(
7735 json, "maxMedOnStartup");
7736 if (bgp->v_maxmed_admin)
7737 json_object_boolean_true_add(
7738 json, "maxMedAdministrative");
7739
7740 json_object_int_add(
7741 json, "tableVersion",
7742 bgp_table_version(bgp->rib[afi][safi]));
7743
7744 ents = bgp_table_count(bgp->rib[afi][safi]);
7745 json_object_int_add(json, "ribCount", ents);
7746 json_object_int_add(
7747 json, "ribMemory",
7748 ents * sizeof(struct bgp_node));
7749
7750 ents = listcount(bgp->peer);
7751 json_object_int_add(json, "peerCount", ents);
7752 json_object_int_add(json, "peerMemory",
7753 ents * sizeof(struct peer));
7754
7755 if ((ents = listcount(bgp->group))) {
7756 json_object_int_add(
7757 json, "peerGroupCount", ents);
7758 json_object_int_add(
7759 json, "peerGroupMemory",
7760 ents * sizeof(struct
7761 peer_group));
7762 }
7763
7764 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7765 BGP_CONFIG_DAMPENING))
7766 json_object_boolean_true_add(
7767 json, "dampeningEnabled");
7768 } else {
7769 if (bgp_maxmed_onstartup_configured(bgp)
7770 && bgp->maxmed_active)
7771 vty_out(vty,
7772 "Max-med on-startup active\n");
7773 if (bgp->v_maxmed_admin)
7774 vty_out(vty,
7775 "Max-med administrative active\n");
7776
7777 vty_out(vty, "BGP table version %" PRIu64 "\n",
7778 bgp_table_version(bgp->rib[afi][safi]));
7779
7780 ents = bgp_table_count(bgp->rib[afi][safi]);
7781 vty_out(vty,
7782 "RIB entries %ld, using %s of memory\n",
7783 ents,
7784 mtype_memstr(memstrbuf,
7785 sizeof(memstrbuf),
7786 ents * sizeof(struct
7787 bgp_node)));
7788
7789 /* Peer related usage */
7790 ents = listcount(bgp->peer);
7791 vty_out(vty, "Peers %ld, using %s of memory\n",
7792 ents,
7793 mtype_memstr(
7794 memstrbuf, sizeof(memstrbuf),
7795 ents * sizeof(struct peer)));
7796
7797 if ((ents = listcount(bgp->group)))
7798 vty_out(vty,
7799 "Peer groups %ld, using %s of memory\n",
7800 ents,
7801 mtype_memstr(
7802 memstrbuf,
7803 sizeof(memstrbuf),
7804 ents * sizeof(struct
7805 peer_group)));
7806
7807 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7808 BGP_CONFIG_DAMPENING))
7809 vty_out(vty, "Dampening enabled.\n");
7810 vty_out(vty, "\n");
7811
7812 /* Subtract 8 here because 'Neighbor' is
7813 * 8 characters */
7814 vty_out(vty, "Neighbor");
7815 vty_out(vty, "%*s", max_neighbor_width - 8,
7816 " ");
7817 vty_out(vty,
7818 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7819 }
7820 }
7821
7822 count++;
7823
7824 if (use_json) {
7825 json_peer = json_object_new_object();
7826
7827 if (peer_dynamic_neighbor(peer))
7828 json_object_boolean_true_add(json_peer,
7829 "dynamicPeer");
7830
7831 if (peer->hostname)
7832 json_object_string_add(json_peer, "hostname",
7833 peer->hostname);
7834
7835 if (peer->domainname)
7836 json_object_string_add(json_peer, "domainname",
7837 peer->domainname);
7838
7839 json_object_int_add(json_peer, "remoteAs", peer->as);
7840 json_object_int_add(json_peer, "version", 4);
7841 json_object_int_add(json_peer, "msgRcvd",
7842 PEER_TOTAL_RX(peer));
7843 json_object_int_add(json_peer, "msgSent",
7844 PEER_TOTAL_TX(peer));
7845
7846 json_object_int_add(json_peer, "tableVersion",
7847 peer->version[afi][safi]);
7848 json_object_int_add(json_peer, "outq",
7849 peer->obuf->count);
7850 json_object_int_add(json_peer, "inq", 0);
7851 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7852 use_json, json_peer);
7853 json_object_int_add(json_peer, "prefixReceivedCount",
7854 peer->pcount[afi][pfx_rcd_safi]);
7855
7856 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7857 json_object_string_add(json_peer, "state",
7858 "Idle (Admin)");
7859 else if (CHECK_FLAG(peer->sflags,
7860 PEER_STATUS_PREFIX_OVERFLOW))
7861 json_object_string_add(json_peer, "state",
7862 "Idle (PfxCt)");
7863 else
7864 json_object_string_add(
7865 json_peer, "state",
7866 lookup_msg(bgp_status_msg, peer->status,
7867 NULL));
7868
7869 if (peer->conf_if)
7870 json_object_string_add(json_peer, "idType",
7871 "interface");
7872 else if (peer->su.sa.sa_family == AF_INET)
7873 json_object_string_add(json_peer, "idType",
7874 "ipv4");
7875 else if (peer->su.sa.sa_family == AF_INET6)
7876 json_object_string_add(json_peer, "idType",
7877 "ipv6");
7878
7879 json_object_object_add(json_peers, peer->host,
7880 json_peer);
7881 } else {
7882 memset(dn_flag, '\0', sizeof(dn_flag));
7883 if (peer_dynamic_neighbor(peer)) {
7884 dn_count++;
7885 dn_flag[0] = '*';
7886 }
7887
7888 if (peer->hostname
7889 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7890 len = vty_out(vty, "%s%s(%s)", dn_flag,
7891 peer->hostname, peer->host);
7892 else
7893 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7894
7895 /* pad the neighbor column with spaces */
7896 if (len < max_neighbor_width)
7897 vty_out(vty, "%*s", max_neighbor_width - len,
7898 " ");
7899
7900 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7901 peer->as, PEER_TOTAL_RX(peer),
7902 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7903 0, peer->obuf->count,
7904 peer_uptime(peer->uptime, timebuf,
7905 BGP_UPTIME_LEN, 0, NULL));
7906
7907 if (peer->status == Established)
7908 if (peer->afc_recv[afi][pfx_rcd_safi])
7909 vty_out(vty, " %12ld",
7910 peer->pcount[afi]
7911 [pfx_rcd_safi]);
7912 else
7913 vty_out(vty, " NoNeg");
7914 else {
7915 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7916 vty_out(vty, " Idle (Admin)");
7917 else if (CHECK_FLAG(
7918 peer->sflags,
7919 PEER_STATUS_PREFIX_OVERFLOW))
7920 vty_out(vty, " Idle (PfxCt)");
7921 else
7922 vty_out(vty, " %12s",
7923 lookup_msg(bgp_status_msg,
7924 peer->status, NULL));
7925 }
7926 vty_out(vty, "\n");
7927 }
7928 }
7929
7930 if (use_json) {
7931 json_object_object_add(json, "peers", json_peers);
7932
7933 json_object_int_add(json, "totalPeers", count);
7934 json_object_int_add(json, "dynamicPeers", dn_count);
7935
7936 bgp_show_bestpath_json(bgp, json);
7937
7938 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7939 json, JSON_C_TO_STRING_PRETTY));
7940 json_object_free(json);
7941 } else {
7942 if (count)
7943 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7944 else {
7945 if (use_json)
7946 vty_out(vty,
7947 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7948 afi_safi_print(afi, safi));
7949 else
7950 vty_out(vty, "No %s neighbor is configured\n",
7951 afi_safi_print(afi, safi));
7952 }
7953
7954 if (dn_count && !use_json) {
7955 vty_out(vty, "* - dynamic neighbor\n");
7956 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7957 dn_count, bgp->dynamic_neighbors_limit);
7958 }
7959 }
7960
7961 return CMD_SUCCESS;
7962 }
7963
7964 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7965 int safi, uint8_t use_json,
7966 json_object *json)
7967 {
7968 int is_first = 1;
7969 int afi_wildcard = (afi == AFI_MAX);
7970 int safi_wildcard = (safi == SAFI_MAX);
7971 int is_wildcard = (afi_wildcard || safi_wildcard);
7972 bool json_output = false;
7973
7974 if (use_json && is_wildcard)
7975 vty_out(vty, "{\n");
7976 if (afi_wildcard)
7977 afi = 1; /* AFI_IP */
7978 while (afi < AFI_MAX) {
7979 if (safi_wildcard)
7980 safi = 1; /* SAFI_UNICAST */
7981 while (safi < SAFI_MAX) {
7982 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
7983 json_output = true;
7984 if (is_wildcard) {
7985 /*
7986 * So limit output to those afi/safi
7987 * pairs that
7988 * actualy have something interesting in
7989 * them
7990 */
7991 if (use_json) {
7992 json = json_object_new_object();
7993
7994 if (!is_first)
7995 vty_out(vty, ",\n");
7996 else
7997 is_first = 0;
7998
7999 vty_out(vty, "\"%s\":",
8000 afi_safi_json(afi,
8001 safi));
8002 } else {
8003 vty_out(vty, "\n%s Summary:\n",
8004 afi_safi_print(afi,
8005 safi));
8006 }
8007 }
8008 bgp_show_summary(vty, bgp, afi, safi, use_json,
8009 json);
8010 }
8011 safi++;
8012 if (!safi_wildcard)
8013 safi = SAFI_MAX;
8014 }
8015 afi++;
8016 if (!afi_wildcard)
8017 afi = AFI_MAX;
8018 }
8019
8020 if (use_json && is_wildcard)
8021 vty_out(vty, "}\n");
8022 else if (use_json && !json_output)
8023 vty_out(vty, "{}\n");
8024 }
8025
8026 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
8027 safi_t safi, uint8_t use_json)
8028 {
8029 struct listnode *node, *nnode;
8030 struct bgp *bgp;
8031 json_object *json = NULL;
8032 int is_first = 1;
8033
8034 if (use_json)
8035 vty_out(vty, "{\n");
8036
8037 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
8038 if (use_json) {
8039 json = json_object_new_object();
8040
8041 if (!is_first)
8042 vty_out(vty, ",\n");
8043 else
8044 is_first = 0;
8045
8046 vty_out(vty, "\"%s\":",
8047 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8048 ? "Default"
8049 : bgp->name);
8050 } else {
8051 vty_out(vty, "\nInstance %s:\n",
8052 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8053 ? "Default"
8054 : bgp->name);
8055 }
8056 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
8057 }
8058
8059 if (use_json)
8060 vty_out(vty, "}\n");
8061 }
8062
8063 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
8064 safi_t safi, uint8_t use_json)
8065 {
8066 struct bgp *bgp;
8067
8068 if (name) {
8069 if (strmatch(name, "all")) {
8070 bgp_show_all_instances_summary_vty(vty, afi, safi,
8071 use_json);
8072 return CMD_SUCCESS;
8073 } else {
8074 bgp = bgp_lookup_by_name(name);
8075
8076 if (!bgp) {
8077 if (use_json)
8078 vty_out(vty, "{}\n");
8079 else
8080 vty_out(vty,
8081 "%% No such BGP instance exist\n");
8082 return CMD_WARNING;
8083 }
8084
8085 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
8086 NULL);
8087 return CMD_SUCCESS;
8088 }
8089 }
8090
8091 bgp = bgp_get_default();
8092
8093 if (bgp)
8094 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
8095
8096 return CMD_SUCCESS;
8097 }
8098
8099 /* `show [ip] bgp summary' commands. */
8100 DEFUN (show_ip_bgp_summary,
8101 show_ip_bgp_summary_cmd,
8102 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
8103 SHOW_STR
8104 IP_STR
8105 BGP_STR
8106 BGP_INSTANCE_HELP_STR
8107 BGP_AFI_HELP_STR
8108 BGP_SAFI_WITH_LABEL_HELP_STR
8109 "Summary of BGP neighbor status\n"
8110 JSON_STR)
8111 {
8112 char *vrf = NULL;
8113 afi_t afi = AFI_MAX;
8114 safi_t safi = SAFI_MAX;
8115
8116 int idx = 0;
8117
8118 /* show [ip] bgp */
8119 if (argv_find(argv, argc, "ip", &idx))
8120 afi = AFI_IP;
8121 /* [<view|vrf> VIEWVRFNAME] */
8122 if (argv_find(argv, argc, "view", &idx)
8123 || argv_find(argv, argc, "vrf", &idx))
8124 vrf = argv[++idx]->arg;
8125 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8126 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
8127 argv_find_and_parse_safi(argv, argc, &idx, &safi);
8128 }
8129
8130 int uj = use_json(argc, argv);
8131
8132 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
8133 }
8134
8135 const char *afi_safi_print(afi_t afi, safi_t safi)
8136 {
8137 if (afi == AFI_IP && safi == SAFI_UNICAST)
8138 return "IPv4 Unicast";
8139 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8140 return "IPv4 Multicast";
8141 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8142 return "IPv4 Labeled Unicast";
8143 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8144 return "IPv4 VPN";
8145 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8146 return "IPv4 Encap";
8147 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8148 return "IPv4 Flowspec";
8149 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8150 return "IPv6 Unicast";
8151 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8152 return "IPv6 Multicast";
8153 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8154 return "IPv6 Labeled Unicast";
8155 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8156 return "IPv6 VPN";
8157 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8158 return "IPv6 Encap";
8159 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8160 return "IPv6 Flowspec";
8161 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8162 return "L2VPN EVPN";
8163 else
8164 return "Unknown";
8165 }
8166
8167 /*
8168 * Please note that we have intentionally camelCased
8169 * the return strings here. So if you want
8170 * to use this function, please ensure you
8171 * are doing this within json output
8172 */
8173 const char *afi_safi_json(afi_t afi, safi_t safi)
8174 {
8175 if (afi == AFI_IP && safi == SAFI_UNICAST)
8176 return "ipv4Unicast";
8177 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
8178 return "ipv4Multicast";
8179 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
8180 return "ipv4LabeledUnicast";
8181 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8182 return "ipv4Vpn";
8183 else if (afi == AFI_IP && safi == SAFI_ENCAP)
8184 return "ipv4Encap";
8185 else if (afi == AFI_IP && safi == SAFI_FLOWSPEC)
8186 return "ipv4Flowspec";
8187 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
8188 return "ipv6Unicast";
8189 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
8190 return "ipv6Multicast";
8191 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
8192 return "ipv6LabeledUnicast";
8193 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
8194 return "ipv6Vpn";
8195 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
8196 return "ipv6Encap";
8197 else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC)
8198 return "ipv6Flowspec";
8199 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
8200 return "l2VpnEvpn";
8201 else
8202 return "Unknown";
8203 }
8204
8205 /* Show BGP peer's information. */
8206 enum show_type { show_all, show_peer };
8207
8208 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
8209 afi_t afi, safi_t safi,
8210 uint16_t adv_smcap, uint16_t adv_rmcap,
8211 uint16_t rcv_smcap, uint16_t rcv_rmcap,
8212 uint8_t use_json, json_object *json_pref)
8213 {
8214 /* Send-Mode */
8215 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8216 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
8217 if (use_json) {
8218 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
8219 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8220 json_object_string_add(json_pref, "sendMode",
8221 "advertisedAndReceived");
8222 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8223 json_object_string_add(json_pref, "sendMode",
8224 "advertised");
8225 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8226 json_object_string_add(json_pref, "sendMode",
8227 "received");
8228 } else {
8229 vty_out(vty, " Send-mode: ");
8230 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8231 vty_out(vty, "advertised");
8232 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8233 vty_out(vty, "%sreceived",
8234 CHECK_FLAG(p->af_cap[afi][safi],
8235 adv_smcap)
8236 ? ", "
8237 : "");
8238 vty_out(vty, "\n");
8239 }
8240 }
8241
8242 /* Receive-Mode */
8243 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8244 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8245 if (use_json) {
8246 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8247 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8248 json_object_string_add(json_pref, "recvMode",
8249 "advertisedAndReceived");
8250 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8251 json_object_string_add(json_pref, "recvMode",
8252 "advertised");
8253 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8254 json_object_string_add(json_pref, "recvMode",
8255 "received");
8256 } else {
8257 vty_out(vty, " Receive-mode: ");
8258 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8259 vty_out(vty, "advertised");
8260 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8261 vty_out(vty, "%sreceived",
8262 CHECK_FLAG(p->af_cap[afi][safi],
8263 adv_rmcap)
8264 ? ", "
8265 : "");
8266 vty_out(vty, "\n");
8267 }
8268 }
8269 }
8270
8271 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8272 safi_t safi, uint8_t use_json,
8273 json_object *json_neigh)
8274 {
8275 struct bgp_filter *filter;
8276 struct peer_af *paf;
8277 char orf_pfx_name[BUFSIZ];
8278 int orf_pfx_count;
8279 json_object *json_af = NULL;
8280 json_object *json_prefA = NULL;
8281 json_object *json_prefB = NULL;
8282 json_object *json_addr = NULL;
8283
8284 if (use_json) {
8285 json_addr = json_object_new_object();
8286 json_af = json_object_new_object();
8287 filter = &p->filter[afi][safi];
8288
8289 if (peer_group_active(p))
8290 json_object_string_add(json_addr, "peerGroupMember",
8291 p->group->name);
8292
8293 paf = peer_af_find(p, afi, safi);
8294 if (paf && PAF_SUBGRP(paf)) {
8295 json_object_int_add(json_addr, "updateGroupId",
8296 PAF_UPDGRP(paf)->id);
8297 json_object_int_add(json_addr, "subGroupId",
8298 PAF_SUBGRP(paf)->id);
8299 json_object_int_add(json_addr, "packetQueueLength",
8300 bpacket_queue_virtual_length(paf));
8301 }
8302
8303 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8304 || CHECK_FLAG(p->af_cap[afi][safi],
8305 PEER_CAP_ORF_PREFIX_SM_RCV)
8306 || CHECK_FLAG(p->af_cap[afi][safi],
8307 PEER_CAP_ORF_PREFIX_RM_ADV)
8308 || CHECK_FLAG(p->af_cap[afi][safi],
8309 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8310 json_object_int_add(json_af, "orfType",
8311 ORF_TYPE_PREFIX);
8312 json_prefA = json_object_new_object();
8313 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8314 PEER_CAP_ORF_PREFIX_SM_ADV,
8315 PEER_CAP_ORF_PREFIX_RM_ADV,
8316 PEER_CAP_ORF_PREFIX_SM_RCV,
8317 PEER_CAP_ORF_PREFIX_RM_RCV,
8318 use_json, json_prefA);
8319 json_object_object_add(json_af, "orfPrefixList",
8320 json_prefA);
8321 }
8322
8323 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8324 || CHECK_FLAG(p->af_cap[afi][safi],
8325 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8326 || CHECK_FLAG(p->af_cap[afi][safi],
8327 PEER_CAP_ORF_PREFIX_RM_ADV)
8328 || CHECK_FLAG(p->af_cap[afi][safi],
8329 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8330 json_object_int_add(json_af, "orfOldType",
8331 ORF_TYPE_PREFIX_OLD);
8332 json_prefB = json_object_new_object();
8333 bgp_show_peer_afi_orf_cap(
8334 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8335 PEER_CAP_ORF_PREFIX_RM_ADV,
8336 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8337 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8338 json_prefB);
8339 json_object_object_add(json_af, "orfOldPrefixList",
8340 json_prefB);
8341 }
8342
8343 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8344 || CHECK_FLAG(p->af_cap[afi][safi],
8345 PEER_CAP_ORF_PREFIX_SM_RCV)
8346 || CHECK_FLAG(p->af_cap[afi][safi],
8347 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8348 || CHECK_FLAG(p->af_cap[afi][safi],
8349 PEER_CAP_ORF_PREFIX_RM_ADV)
8350 || CHECK_FLAG(p->af_cap[afi][safi],
8351 PEER_CAP_ORF_PREFIX_RM_RCV)
8352 || CHECK_FLAG(p->af_cap[afi][safi],
8353 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8354 json_object_object_add(json_addr, "afDependentCap",
8355 json_af);
8356 else
8357 json_object_free(json_af);
8358
8359 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8360 orf_pfx_count = prefix_bgp_show_prefix_list(
8361 NULL, afi, orf_pfx_name, use_json);
8362
8363 if (CHECK_FLAG(p->af_sflags[afi][safi],
8364 PEER_STATUS_ORF_PREFIX_SEND)
8365 || orf_pfx_count) {
8366 if (CHECK_FLAG(p->af_sflags[afi][safi],
8367 PEER_STATUS_ORF_PREFIX_SEND))
8368 json_object_boolean_true_add(json_neigh,
8369 "orfSent");
8370 if (orf_pfx_count)
8371 json_object_int_add(json_addr, "orfRecvCounter",
8372 orf_pfx_count);
8373 }
8374 if (CHECK_FLAG(p->af_sflags[afi][safi],
8375 PEER_STATUS_ORF_WAIT_REFRESH))
8376 json_object_string_add(
8377 json_addr, "orfFirstUpdate",
8378 "deferredUntilORFOrRouteRefreshRecvd");
8379
8380 if (CHECK_FLAG(p->af_flags[afi][safi],
8381 PEER_FLAG_REFLECTOR_CLIENT))
8382 json_object_boolean_true_add(json_addr,
8383 "routeReflectorClient");
8384 if (CHECK_FLAG(p->af_flags[afi][safi],
8385 PEER_FLAG_RSERVER_CLIENT))
8386 json_object_boolean_true_add(json_addr,
8387 "routeServerClient");
8388 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8389 json_object_boolean_true_add(json_addr,
8390 "inboundSoftConfigPermit");
8391
8392 if (CHECK_FLAG(p->af_flags[afi][safi],
8393 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8394 json_object_boolean_true_add(
8395 json_addr,
8396 "privateAsNumsAllReplacedInUpdatesToNbr");
8397 else if (CHECK_FLAG(p->af_flags[afi][safi],
8398 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8399 json_object_boolean_true_add(
8400 json_addr,
8401 "privateAsNumsReplacedInUpdatesToNbr");
8402 else if (CHECK_FLAG(p->af_flags[afi][safi],
8403 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8404 json_object_boolean_true_add(
8405 json_addr,
8406 "privateAsNumsAllRemovedInUpdatesToNbr");
8407 else if (CHECK_FLAG(p->af_flags[afi][safi],
8408 PEER_FLAG_REMOVE_PRIVATE_AS))
8409 json_object_boolean_true_add(
8410 json_addr,
8411 "privateAsNumsRemovedInUpdatesToNbr");
8412
8413 if (CHECK_FLAG(p->af_flags[afi][safi],
8414 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8415 json_object_boolean_true_add(json_addr,
8416 "addpathTxAllPaths");
8417
8418 if (CHECK_FLAG(p->af_flags[afi][safi],
8419 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8420 json_object_boolean_true_add(json_addr,
8421 "addpathTxBestpathPerAS");
8422
8423 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8424 json_object_string_add(json_addr,
8425 "overrideASNsInOutboundUpdates",
8426 "ifAspathEqualRemoteAs");
8427
8428 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8429 || CHECK_FLAG(p->af_flags[afi][safi],
8430 PEER_FLAG_FORCE_NEXTHOP_SELF))
8431 json_object_boolean_true_add(json_addr,
8432 "routerAlwaysNextHop");
8433 if (CHECK_FLAG(p->af_flags[afi][safi],
8434 PEER_FLAG_AS_PATH_UNCHANGED))
8435 json_object_boolean_true_add(
8436 json_addr, "unchangedAsPathPropogatedToNbr");
8437 if (CHECK_FLAG(p->af_flags[afi][safi],
8438 PEER_FLAG_NEXTHOP_UNCHANGED))
8439 json_object_boolean_true_add(
8440 json_addr, "unchangedNextHopPropogatedToNbr");
8441 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8442 json_object_boolean_true_add(
8443 json_addr, "unchangedMedPropogatedToNbr");
8444 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8445 || CHECK_FLAG(p->af_flags[afi][safi],
8446 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8447 if (CHECK_FLAG(p->af_flags[afi][safi],
8448 PEER_FLAG_SEND_COMMUNITY)
8449 && CHECK_FLAG(p->af_flags[afi][safi],
8450 PEER_FLAG_SEND_EXT_COMMUNITY))
8451 json_object_string_add(json_addr,
8452 "commAttriSentToNbr",
8453 "extendedAndStandard");
8454 else if (CHECK_FLAG(p->af_flags[afi][safi],
8455 PEER_FLAG_SEND_EXT_COMMUNITY))
8456 json_object_string_add(json_addr,
8457 "commAttriSentToNbr",
8458 "extended");
8459 else
8460 json_object_string_add(json_addr,
8461 "commAttriSentToNbr",
8462 "standard");
8463 }
8464 if (CHECK_FLAG(p->af_flags[afi][safi],
8465 PEER_FLAG_DEFAULT_ORIGINATE)) {
8466 if (p->default_rmap[afi][safi].name)
8467 json_object_string_add(
8468 json_addr, "defaultRouteMap",
8469 p->default_rmap[afi][safi].name);
8470
8471 if (paf && PAF_SUBGRP(paf)
8472 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8473 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8474 json_object_boolean_true_add(json_addr,
8475 "defaultSent");
8476 else
8477 json_object_boolean_true_add(json_addr,
8478 "defaultNotSent");
8479 }
8480
8481 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8482 if (is_evpn_enabled())
8483 json_object_boolean_true_add(
8484 json_addr, "advertiseAllVnis");
8485 }
8486
8487 if (filter->plist[FILTER_IN].name
8488 || filter->dlist[FILTER_IN].name
8489 || filter->aslist[FILTER_IN].name
8490 || filter->map[RMAP_IN].name)
8491 json_object_boolean_true_add(json_addr,
8492 "inboundPathPolicyConfig");
8493 if (filter->plist[FILTER_OUT].name
8494 || filter->dlist[FILTER_OUT].name
8495 || filter->aslist[FILTER_OUT].name
8496 || filter->map[RMAP_OUT].name || filter->usmap.name)
8497 json_object_boolean_true_add(
8498 json_addr, "outboundPathPolicyConfig");
8499
8500 /* prefix-list */
8501 if (filter->plist[FILTER_IN].name)
8502 json_object_string_add(json_addr,
8503 "incomingUpdatePrefixFilterList",
8504 filter->plist[FILTER_IN].name);
8505 if (filter->plist[FILTER_OUT].name)
8506 json_object_string_add(json_addr,
8507 "outgoingUpdatePrefixFilterList",
8508 filter->plist[FILTER_OUT].name);
8509
8510 /* distribute-list */
8511 if (filter->dlist[FILTER_IN].name)
8512 json_object_string_add(
8513 json_addr, "incomingUpdateNetworkFilterList",
8514 filter->dlist[FILTER_IN].name);
8515 if (filter->dlist[FILTER_OUT].name)
8516 json_object_string_add(
8517 json_addr, "outgoingUpdateNetworkFilterList",
8518 filter->dlist[FILTER_OUT].name);
8519
8520 /* filter-list. */
8521 if (filter->aslist[FILTER_IN].name)
8522 json_object_string_add(json_addr,
8523 "incomingUpdateAsPathFilterList",
8524 filter->aslist[FILTER_IN].name);
8525 if (filter->aslist[FILTER_OUT].name)
8526 json_object_string_add(json_addr,
8527 "outgoingUpdateAsPathFilterList",
8528 filter->aslist[FILTER_OUT].name);
8529
8530 /* route-map. */
8531 if (filter->map[RMAP_IN].name)
8532 json_object_string_add(
8533 json_addr, "routeMapForIncomingAdvertisements",
8534 filter->map[RMAP_IN].name);
8535 if (filter->map[RMAP_OUT].name)
8536 json_object_string_add(
8537 json_addr, "routeMapForOutgoingAdvertisements",
8538 filter->map[RMAP_OUT].name);
8539
8540 /* unsuppress-map */
8541 if (filter->usmap.name)
8542 json_object_string_add(json_addr,
8543 "selectiveUnsuppressRouteMap",
8544 filter->usmap.name);
8545
8546 /* Receive prefix count */
8547 json_object_int_add(json_addr, "acceptedPrefixCounter",
8548 p->pcount[afi][safi]);
8549
8550 /* Maximum prefix */
8551 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8552 json_object_int_add(json_addr, "prefixAllowedMax",
8553 p->pmax[afi][safi]);
8554 if (CHECK_FLAG(p->af_flags[afi][safi],
8555 PEER_FLAG_MAX_PREFIX_WARNING))
8556 json_object_boolean_true_add(
8557 json_addr, "prefixAllowedMaxWarning");
8558 json_object_int_add(json_addr,
8559 "prefixAllowedWarningThresh",
8560 p->pmax_threshold[afi][safi]);
8561 if (p->pmax_restart[afi][safi])
8562 json_object_int_add(
8563 json_addr,
8564 "prefixAllowedRestartIntervalMsecs",
8565 p->pmax_restart[afi][safi] * 60000);
8566 }
8567 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8568 json_addr);
8569
8570 } else {
8571 filter = &p->filter[afi][safi];
8572
8573 vty_out(vty, " For address family: %s\n",
8574 afi_safi_print(afi, safi));
8575
8576 if (peer_group_active(p))
8577 vty_out(vty, " %s peer-group member\n",
8578 p->group->name);
8579
8580 paf = peer_af_find(p, afi, safi);
8581 if (paf && PAF_SUBGRP(paf)) {
8582 vty_out(vty, " Update group %" PRIu64
8583 ", subgroup %" PRIu64 "\n",
8584 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8585 vty_out(vty, " Packet Queue length %d\n",
8586 bpacket_queue_virtual_length(paf));
8587 } else {
8588 vty_out(vty, " Not part of any update group\n");
8589 }
8590 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8591 || CHECK_FLAG(p->af_cap[afi][safi],
8592 PEER_CAP_ORF_PREFIX_SM_RCV)
8593 || CHECK_FLAG(p->af_cap[afi][safi],
8594 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8595 || CHECK_FLAG(p->af_cap[afi][safi],
8596 PEER_CAP_ORF_PREFIX_RM_ADV)
8597 || CHECK_FLAG(p->af_cap[afi][safi],
8598 PEER_CAP_ORF_PREFIX_RM_RCV)
8599 || CHECK_FLAG(p->af_cap[afi][safi],
8600 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8601 vty_out(vty, " AF-dependant capabilities:\n");
8602
8603 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8604 || CHECK_FLAG(p->af_cap[afi][safi],
8605 PEER_CAP_ORF_PREFIX_SM_RCV)
8606 || CHECK_FLAG(p->af_cap[afi][safi],
8607 PEER_CAP_ORF_PREFIX_RM_ADV)
8608 || CHECK_FLAG(p->af_cap[afi][safi],
8609 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8610 vty_out(vty,
8611 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8612 ORF_TYPE_PREFIX);
8613 bgp_show_peer_afi_orf_cap(
8614 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8615 PEER_CAP_ORF_PREFIX_RM_ADV,
8616 PEER_CAP_ORF_PREFIX_SM_RCV,
8617 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8618 }
8619 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8620 || CHECK_FLAG(p->af_cap[afi][safi],
8621 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8622 || CHECK_FLAG(p->af_cap[afi][safi],
8623 PEER_CAP_ORF_PREFIX_RM_ADV)
8624 || CHECK_FLAG(p->af_cap[afi][safi],
8625 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8626 vty_out(vty,
8627 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8628 ORF_TYPE_PREFIX_OLD);
8629 bgp_show_peer_afi_orf_cap(
8630 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8631 PEER_CAP_ORF_PREFIX_RM_ADV,
8632 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8633 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8634 }
8635
8636 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8637 orf_pfx_count = prefix_bgp_show_prefix_list(
8638 NULL, afi, orf_pfx_name, use_json);
8639
8640 if (CHECK_FLAG(p->af_sflags[afi][safi],
8641 PEER_STATUS_ORF_PREFIX_SEND)
8642 || orf_pfx_count) {
8643 vty_out(vty, " Outbound Route Filter (ORF):");
8644 if (CHECK_FLAG(p->af_sflags[afi][safi],
8645 PEER_STATUS_ORF_PREFIX_SEND))
8646 vty_out(vty, " sent;");
8647 if (orf_pfx_count)
8648 vty_out(vty, " received (%d entries)",
8649 orf_pfx_count);
8650 vty_out(vty, "\n");
8651 }
8652 if (CHECK_FLAG(p->af_sflags[afi][safi],
8653 PEER_STATUS_ORF_WAIT_REFRESH))
8654 vty_out(vty,
8655 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8656
8657 if (CHECK_FLAG(p->af_flags[afi][safi],
8658 PEER_FLAG_REFLECTOR_CLIENT))
8659 vty_out(vty, " Route-Reflector Client\n");
8660 if (CHECK_FLAG(p->af_flags[afi][safi],
8661 PEER_FLAG_RSERVER_CLIENT))
8662 vty_out(vty, " Route-Server Client\n");
8663 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8664 vty_out(vty,
8665 " Inbound soft reconfiguration allowed\n");
8666
8667 if (CHECK_FLAG(p->af_flags[afi][safi],
8668 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8669 vty_out(vty,
8670 " Private AS numbers (all) replaced in updates to this neighbor\n");
8671 else if (CHECK_FLAG(p->af_flags[afi][safi],
8672 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8673 vty_out(vty,
8674 " Private AS numbers replaced in updates to this neighbor\n");
8675 else if (CHECK_FLAG(p->af_flags[afi][safi],
8676 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8677 vty_out(vty,
8678 " Private AS numbers (all) removed in updates to this neighbor\n");
8679 else if (CHECK_FLAG(p->af_flags[afi][safi],
8680 PEER_FLAG_REMOVE_PRIVATE_AS))
8681 vty_out(vty,
8682 " Private AS numbers removed in updates to this neighbor\n");
8683
8684 if (CHECK_FLAG(p->af_flags[afi][safi],
8685 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8686 vty_out(vty, " Advertise all paths via addpath\n");
8687
8688 if (CHECK_FLAG(p->af_flags[afi][safi],
8689 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8690 vty_out(vty,
8691 " Advertise bestpath per AS via addpath\n");
8692
8693 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8694 vty_out(vty,
8695 " Override ASNs in outbound updates if aspath equals remote-as\n");
8696
8697 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8698 || CHECK_FLAG(p->af_flags[afi][safi],
8699 PEER_FLAG_FORCE_NEXTHOP_SELF))
8700 vty_out(vty, " NEXT_HOP is always this router\n");
8701 if (CHECK_FLAG(p->af_flags[afi][safi],
8702 PEER_FLAG_AS_PATH_UNCHANGED))
8703 vty_out(vty,
8704 " AS_PATH is propagated unchanged to this neighbor\n");
8705 if (CHECK_FLAG(p->af_flags[afi][safi],
8706 PEER_FLAG_NEXTHOP_UNCHANGED))
8707 vty_out(vty,
8708 " NEXT_HOP is propagated unchanged to this neighbor\n");
8709 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8710 vty_out(vty,
8711 " MED is propagated unchanged to this neighbor\n");
8712 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8713 || CHECK_FLAG(p->af_flags[afi][safi],
8714 PEER_FLAG_SEND_EXT_COMMUNITY)
8715 || CHECK_FLAG(p->af_flags[afi][safi],
8716 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8717 vty_out(vty,
8718 " Community attribute sent to this neighbor");
8719 if (CHECK_FLAG(p->af_flags[afi][safi],
8720 PEER_FLAG_SEND_COMMUNITY)
8721 && CHECK_FLAG(p->af_flags[afi][safi],
8722 PEER_FLAG_SEND_EXT_COMMUNITY)
8723 && CHECK_FLAG(p->af_flags[afi][safi],
8724 PEER_FLAG_SEND_LARGE_COMMUNITY))
8725 vty_out(vty, "(all)\n");
8726 else if (CHECK_FLAG(p->af_flags[afi][safi],
8727 PEER_FLAG_SEND_LARGE_COMMUNITY))
8728 vty_out(vty, "(large)\n");
8729 else if (CHECK_FLAG(p->af_flags[afi][safi],
8730 PEER_FLAG_SEND_EXT_COMMUNITY))
8731 vty_out(vty, "(extended)\n");
8732 else
8733 vty_out(vty, "(standard)\n");
8734 }
8735 if (CHECK_FLAG(p->af_flags[afi][safi],
8736 PEER_FLAG_DEFAULT_ORIGINATE)) {
8737 vty_out(vty, " Default information originate,");
8738
8739 if (p->default_rmap[afi][safi].name)
8740 vty_out(vty, " default route-map %s%s,",
8741 p->default_rmap[afi][safi].map ? "*"
8742 : "",
8743 p->default_rmap[afi][safi].name);
8744 if (paf && PAF_SUBGRP(paf)
8745 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8746 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8747 vty_out(vty, " default sent\n");
8748 else
8749 vty_out(vty, " default not sent\n");
8750 }
8751
8752 /* advertise-vni-all */
8753 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8754 if (is_evpn_enabled())
8755 vty_out(vty, " advertise-all-vni\n");
8756 }
8757
8758 if (filter->plist[FILTER_IN].name
8759 || filter->dlist[FILTER_IN].name
8760 || filter->aslist[FILTER_IN].name
8761 || filter->map[RMAP_IN].name)
8762 vty_out(vty, " Inbound path policy configured\n");
8763 if (filter->plist[FILTER_OUT].name
8764 || filter->dlist[FILTER_OUT].name
8765 || filter->aslist[FILTER_OUT].name
8766 || filter->map[RMAP_OUT].name || filter->usmap.name)
8767 vty_out(vty, " Outbound path policy configured\n");
8768
8769 /* prefix-list */
8770 if (filter->plist[FILTER_IN].name)
8771 vty_out(vty,
8772 " Incoming update prefix filter list is %s%s\n",
8773 filter->plist[FILTER_IN].plist ? "*" : "",
8774 filter->plist[FILTER_IN].name);
8775 if (filter->plist[FILTER_OUT].name)
8776 vty_out(vty,
8777 " Outgoing update prefix filter list is %s%s\n",
8778 filter->plist[FILTER_OUT].plist ? "*" : "",
8779 filter->plist[FILTER_OUT].name);
8780
8781 /* distribute-list */
8782 if (filter->dlist[FILTER_IN].name)
8783 vty_out(vty,
8784 " Incoming update network filter list is %s%s\n",
8785 filter->dlist[FILTER_IN].alist ? "*" : "",
8786 filter->dlist[FILTER_IN].name);
8787 if (filter->dlist[FILTER_OUT].name)
8788 vty_out(vty,
8789 " Outgoing update network filter list is %s%s\n",
8790 filter->dlist[FILTER_OUT].alist ? "*" : "",
8791 filter->dlist[FILTER_OUT].name);
8792
8793 /* filter-list. */
8794 if (filter->aslist[FILTER_IN].name)
8795 vty_out(vty,
8796 " Incoming update AS path filter list is %s%s\n",
8797 filter->aslist[FILTER_IN].aslist ? "*" : "",
8798 filter->aslist[FILTER_IN].name);
8799 if (filter->aslist[FILTER_OUT].name)
8800 vty_out(vty,
8801 " Outgoing update AS path filter list is %s%s\n",
8802 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8803 filter->aslist[FILTER_OUT].name);
8804
8805 /* route-map. */
8806 if (filter->map[RMAP_IN].name)
8807 vty_out(vty,
8808 " Route map for incoming advertisements is %s%s\n",
8809 filter->map[RMAP_IN].map ? "*" : "",
8810 filter->map[RMAP_IN].name);
8811 if (filter->map[RMAP_OUT].name)
8812 vty_out(vty,
8813 " Route map for outgoing advertisements is %s%s\n",
8814 filter->map[RMAP_OUT].map ? "*" : "",
8815 filter->map[RMAP_OUT].name);
8816
8817 /* unsuppress-map */
8818 if (filter->usmap.name)
8819 vty_out(vty,
8820 " Route map for selective unsuppress is %s%s\n",
8821 filter->usmap.map ? "*" : "",
8822 filter->usmap.name);
8823
8824 /* Receive prefix count */
8825 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8826
8827 /* Maximum prefix */
8828 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8829 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8830 p->pmax[afi][safi],
8831 CHECK_FLAG(p->af_flags[afi][safi],
8832 PEER_FLAG_MAX_PREFIX_WARNING)
8833 ? " (warning-only)"
8834 : "");
8835 vty_out(vty, " Threshold for warning message %d%%",
8836 p->pmax_threshold[afi][safi]);
8837 if (p->pmax_restart[afi][safi])
8838 vty_out(vty, ", restart interval %d min",
8839 p->pmax_restart[afi][safi]);
8840 vty_out(vty, "\n");
8841 }
8842
8843 vty_out(vty, "\n");
8844 }
8845 }
8846
8847 static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json,
8848 json_object *json)
8849 {
8850 struct bgp *bgp;
8851 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8852 char timebuf[BGP_UPTIME_LEN];
8853 char dn_flag[2];
8854 const char *subcode_str;
8855 const char *code_str;
8856 afi_t afi;
8857 safi_t safi;
8858 uint16_t i;
8859 uint8_t *msg;
8860 json_object *json_neigh = NULL;
8861 time_t epoch_tbuf;
8862
8863 bgp = p->bgp;
8864
8865 if (use_json)
8866 json_neigh = json_object_new_object();
8867
8868 memset(dn_flag, '\0', sizeof(dn_flag));
8869 if (!p->conf_if && peer_dynamic_neighbor(p))
8870 dn_flag[0] = '*';
8871
8872 if (!use_json) {
8873 if (p->conf_if) /* Configured interface name. */
8874 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8875 BGP_PEER_SU_UNSPEC(p)
8876 ? "None"
8877 : sockunion2str(&p->su, buf,
8878 SU_ADDRSTRLEN));
8879 else /* Configured IP address. */
8880 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8881 p->host);
8882 }
8883
8884 if (use_json) {
8885 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8886 json_object_string_add(json_neigh, "bgpNeighborAddr",
8887 "none");
8888 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8889 json_object_string_add(
8890 json_neigh, "bgpNeighborAddr",
8891 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8892
8893 json_object_int_add(json_neigh, "remoteAs", p->as);
8894
8895 if (p->change_local_as)
8896 json_object_int_add(json_neigh, "localAs",
8897 p->change_local_as);
8898 else
8899 json_object_int_add(json_neigh, "localAs", p->local_as);
8900
8901 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8902 json_object_boolean_true_add(json_neigh,
8903 "localAsNoPrepend");
8904
8905 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8906 json_object_boolean_true_add(json_neigh,
8907 "localAsReplaceAs");
8908 } else {
8909 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8910 || (p->as_type == AS_INTERNAL))
8911 vty_out(vty, "remote AS %u, ", p->as);
8912 else
8913 vty_out(vty, "remote AS Unspecified, ");
8914 vty_out(vty, "local AS %u%s%s, ",
8915 p->change_local_as ? p->change_local_as : p->local_as,
8916 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8917 ? " no-prepend"
8918 : "",
8919 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8920 ? " replace-as"
8921 : "");
8922 }
8923 /* peer type internal, external, confed-internal or confed-external */
8924 if (p->as == p->local_as) {
8925 if (use_json) {
8926 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8927 json_object_boolean_true_add(
8928 json_neigh, "nbrConfedInternalLink");
8929 else
8930 json_object_boolean_true_add(json_neigh,
8931 "nbrInternalLink");
8932 } else {
8933 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8934 vty_out(vty, "confed-internal link\n");
8935 else
8936 vty_out(vty, "internal link\n");
8937 }
8938 } else {
8939 if (use_json) {
8940 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8941 json_object_boolean_true_add(
8942 json_neigh, "nbrConfedExternalLink");
8943 else
8944 json_object_boolean_true_add(json_neigh,
8945 "nbrExternalLink");
8946 } else {
8947 if (bgp_confederation_peers_check(bgp, p->as))
8948 vty_out(vty, "confed-external link\n");
8949 else
8950 vty_out(vty, "external link\n");
8951 }
8952 }
8953
8954 /* Description. */
8955 if (p->desc) {
8956 if (use_json)
8957 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8958 else
8959 vty_out(vty, " Description: %s\n", p->desc);
8960 }
8961
8962 if (p->hostname) {
8963 if (use_json) {
8964 if (p->hostname)
8965 json_object_string_add(json_neigh, "hostname",
8966 p->hostname);
8967
8968 if (p->domainname)
8969 json_object_string_add(json_neigh, "domainname",
8970 p->domainname);
8971 } else {
8972 if (p->domainname && (p->domainname[0] != '\0'))
8973 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8974 p->domainname);
8975 else
8976 vty_out(vty, "Hostname: %s\n", p->hostname);
8977 }
8978 }
8979
8980 /* Peer-group */
8981 if (p->group) {
8982 if (use_json) {
8983 json_object_string_add(json_neigh, "peerGroup",
8984 p->group->name);
8985
8986 if (dn_flag[0]) {
8987 struct prefix prefix, *range = NULL;
8988
8989 sockunion2hostprefix(&(p->su), &prefix);
8990 range = peer_group_lookup_dynamic_neighbor_range(
8991 p->group, &prefix);
8992
8993 if (range) {
8994 prefix2str(range, buf1, sizeof(buf1));
8995 json_object_string_add(
8996 json_neigh,
8997 "peerSubnetRangeGroup", buf1);
8998 }
8999 }
9000 } else {
9001 vty_out(vty,
9002 " Member of peer-group %s for session parameters\n",
9003 p->group->name);
9004
9005 if (dn_flag[0]) {
9006 struct prefix prefix, *range = NULL;
9007
9008 sockunion2hostprefix(&(p->su), &prefix);
9009 range = peer_group_lookup_dynamic_neighbor_range(
9010 p->group, &prefix);
9011
9012 if (range) {
9013 prefix2str(range, buf1, sizeof(buf1));
9014 vty_out(vty,
9015 " Belongs to the subnet range group: %s\n",
9016 buf1);
9017 }
9018 }
9019 }
9020 }
9021
9022 if (use_json) {
9023 /* Administrative shutdown. */
9024 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9025 json_object_boolean_true_add(json_neigh,
9026 "adminShutDown");
9027
9028 /* BGP Version. */
9029 json_object_int_add(json_neigh, "bgpVersion", 4);
9030 json_object_string_add(
9031 json_neigh, "remoteRouterId",
9032 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9033
9034 /* Confederation */
9035 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9036 && bgp_confederation_peers_check(bgp, p->as))
9037 json_object_boolean_true_add(json_neigh,
9038 "nbrCommonAdmin");
9039
9040 /* Status. */
9041 json_object_string_add(
9042 json_neigh, "bgpState",
9043 lookup_msg(bgp_status_msg, p->status, NULL));
9044
9045 if (p->status == Established) {
9046 time_t uptime;
9047
9048 uptime = bgp_clock();
9049 uptime -= p->uptime;
9050 epoch_tbuf = time(NULL) - uptime;
9051
9052 #if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101
9053 CPP_NOTICE(
9054 "bgpTimerUp should be deprecated and can be removed now");
9055 #endif
9056 /*
9057 * bgpTimerUp was miliseconds that was accurate
9058 * up to 1 day, then the value returned
9059 * became garbage. So in order to provide
9060 * some level of backwards compatability,
9061 * we still provde the data, but now
9062 * we are returning the correct value
9063 * and also adding a new bgpTimerUpMsec
9064 * which will allow us to deprecate
9065 * this eventually
9066 */
9067 json_object_int_add(json_neigh, "bgpTimerUp",
9068 uptime * 1000);
9069 json_object_int_add(json_neigh, "bgpTimerUpMsec",
9070 uptime * 1000);
9071 json_object_string_add(json_neigh, "bgpTimerUpString",
9072 peer_uptime(p->uptime, timebuf,
9073 BGP_UPTIME_LEN, 0,
9074 NULL));
9075 json_object_int_add(json_neigh,
9076 "bgpTimerUpEstablishedEpoch",
9077 epoch_tbuf);
9078 }
9079
9080 else if (p->status == Active) {
9081 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9082 json_object_string_add(json_neigh, "bgpStateIs",
9083 "passive");
9084 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9085 json_object_string_add(json_neigh, "bgpStateIs",
9086 "passiveNSF");
9087 }
9088
9089 /* read timer */
9090 time_t uptime;
9091 struct tm *tm;
9092
9093 uptime = bgp_clock();
9094 uptime -= p->readtime;
9095 tm = gmtime(&uptime);
9096 json_object_int_add(json_neigh, "bgpTimerLastRead",
9097 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9098 + (tm->tm_hour * 3600000));
9099
9100 uptime = bgp_clock();
9101 uptime -= p->last_write;
9102 tm = gmtime(&uptime);
9103 json_object_int_add(json_neigh, "bgpTimerLastWrite",
9104 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9105 + (tm->tm_hour * 3600000));
9106
9107 uptime = bgp_clock();
9108 uptime -= p->update_time;
9109 tm = gmtime(&uptime);
9110 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
9111 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
9112 + (tm->tm_hour * 3600000));
9113
9114 /* Configured timer values. */
9115 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
9116 p->v_holdtime * 1000);
9117 json_object_int_add(json_neigh,
9118 "bgpTimerKeepAliveIntervalMsecs",
9119 p->v_keepalive * 1000);
9120
9121 if (PEER_OR_GROUP_TIMER_SET(p)) {
9122 json_object_int_add(json_neigh,
9123 "bgpTimerConfiguredHoldTimeMsecs",
9124 p->holdtime * 1000);
9125 json_object_int_add(
9126 json_neigh,
9127 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9128 p->keepalive * 1000);
9129 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9130 || (bgp->default_keepalive
9131 != BGP_DEFAULT_KEEPALIVE)) {
9132 json_object_int_add(json_neigh,
9133 "bgpTimerConfiguredHoldTimeMsecs",
9134 bgp->default_holdtime);
9135 json_object_int_add(
9136 json_neigh,
9137 "bgpTimerConfiguredKeepAliveIntervalMsecs",
9138 bgp->default_keepalive);
9139 }
9140 } else {
9141 /* Administrative shutdown. */
9142 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
9143 vty_out(vty, " Administratively shut down\n");
9144
9145 /* BGP Version. */
9146 vty_out(vty, " BGP version 4");
9147 vty_out(vty, ", remote router ID %s\n",
9148 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
9149
9150 /* Confederation */
9151 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
9152 && bgp_confederation_peers_check(bgp, p->as))
9153 vty_out(vty,
9154 " Neighbor under common administration\n");
9155
9156 /* Status. */
9157 vty_out(vty, " BGP state = %s",
9158 lookup_msg(bgp_status_msg, p->status, NULL));
9159
9160 if (p->status == Established)
9161 vty_out(vty, ", up for %8s",
9162 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
9163 0, NULL));
9164
9165 else if (p->status == Active) {
9166 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
9167 vty_out(vty, " (passive)");
9168 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
9169 vty_out(vty, " (NSF passive)");
9170 }
9171 vty_out(vty, "\n");
9172
9173 /* read timer */
9174 vty_out(vty, " Last read %s",
9175 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
9176 NULL));
9177 vty_out(vty, ", Last write %s\n",
9178 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
9179 NULL));
9180
9181 /* Configured timer values. */
9182 vty_out(vty,
9183 " Hold time is %d, keepalive interval is %d seconds\n",
9184 p->v_holdtime, p->v_keepalive);
9185 if (PEER_OR_GROUP_TIMER_SET(p)) {
9186 vty_out(vty, " Configured hold time is %d",
9187 p->holdtime);
9188 vty_out(vty, ", keepalive interval is %d seconds\n",
9189 p->keepalive);
9190 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
9191 || (bgp->default_keepalive
9192 != BGP_DEFAULT_KEEPALIVE)) {
9193 vty_out(vty, " Configured hold time is %d",
9194 bgp->default_holdtime);
9195 vty_out(vty, ", keepalive interval is %d seconds\n",
9196 bgp->default_keepalive);
9197 }
9198 }
9199 /* Capability. */
9200 if (p->status == Established) {
9201 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
9202 || p->afc_recv[AFI_IP][SAFI_UNICAST]
9203 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
9204 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
9205 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
9206 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
9207 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
9208 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
9209 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
9210 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
9211 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
9212 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
9213 || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC]
9214 || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC]
9215 || p->afc_adv[AFI_IP][SAFI_ENCAP]
9216 || p->afc_recv[AFI_IP][SAFI_ENCAP]
9217 || p->afc_adv[AFI_IP][SAFI_FLOWSPEC]
9218 || p->afc_recv[AFI_IP][SAFI_FLOWSPEC]
9219 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
9220 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
9221 if (use_json) {
9222 json_object *json_cap = NULL;
9223
9224 json_cap = json_object_new_object();
9225
9226 /* AS4 */
9227 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9228 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9229 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9230 && CHECK_FLAG(p->cap,
9231 PEER_CAP_AS4_RCV))
9232 json_object_string_add(
9233 json_cap, "4byteAs",
9234 "advertisedAndReceived");
9235 else if (CHECK_FLAG(p->cap,
9236 PEER_CAP_AS4_ADV))
9237 json_object_string_add(
9238 json_cap, "4byteAs",
9239 "advertised");
9240 else if (CHECK_FLAG(p->cap,
9241 PEER_CAP_AS4_RCV))
9242 json_object_string_add(
9243 json_cap, "4byteAs",
9244 "received");
9245 }
9246
9247 /* AddPath */
9248 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9249 || CHECK_FLAG(p->cap,
9250 PEER_CAP_ADDPATH_ADV)) {
9251 json_object *json_add = NULL;
9252 const char *print_store;
9253
9254 json_add = json_object_new_object();
9255
9256 FOREACH_AFI_SAFI (afi, safi) {
9257 json_object *json_sub = NULL;
9258 json_sub =
9259 json_object_new_object();
9260 print_store = afi_safi_print(
9261 afi, safi);
9262
9263 if (CHECK_FLAG(
9264 p->af_cap[afi]
9265 [safi],
9266 PEER_CAP_ADDPATH_AF_TX_ADV)
9267 || CHECK_FLAG(
9268 p->af_cap[afi]
9269 [safi],
9270 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9271 if (CHECK_FLAG(
9272 p->af_cap
9273 [afi]
9274 [safi],
9275 PEER_CAP_ADDPATH_AF_TX_ADV)
9276 && CHECK_FLAG(
9277 p->af_cap
9278 [afi]
9279 [safi],
9280 PEER_CAP_ADDPATH_AF_TX_RCV))
9281 json_object_boolean_true_add(
9282 json_sub,
9283 "txAdvertisedAndReceived");
9284 else if (
9285 CHECK_FLAG(
9286 p->af_cap
9287 [afi]
9288 [safi],
9289 PEER_CAP_ADDPATH_AF_TX_ADV))
9290 json_object_boolean_true_add(
9291 json_sub,
9292 "txAdvertised");
9293 else if (
9294 CHECK_FLAG(
9295 p->af_cap
9296 [afi]
9297 [safi],
9298 PEER_CAP_ADDPATH_AF_TX_RCV))
9299 json_object_boolean_true_add(
9300 json_sub,
9301 "txReceived");
9302 }
9303
9304 if (CHECK_FLAG(
9305 p->af_cap[afi]
9306 [safi],
9307 PEER_CAP_ADDPATH_AF_RX_ADV)
9308 || CHECK_FLAG(
9309 p->af_cap[afi]
9310 [safi],
9311 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9312 if (CHECK_FLAG(
9313 p->af_cap
9314 [afi]
9315 [safi],
9316 PEER_CAP_ADDPATH_AF_RX_ADV)
9317 && CHECK_FLAG(
9318 p->af_cap
9319 [afi]
9320 [safi],
9321 PEER_CAP_ADDPATH_AF_RX_RCV))
9322 json_object_boolean_true_add(
9323 json_sub,
9324 "rxAdvertisedAndReceived");
9325 else if (
9326 CHECK_FLAG(
9327 p->af_cap
9328 [afi]
9329 [safi],
9330 PEER_CAP_ADDPATH_AF_RX_ADV))
9331 json_object_boolean_true_add(
9332 json_sub,
9333 "rxAdvertised");
9334 else if (
9335 CHECK_FLAG(
9336 p->af_cap
9337 [afi]
9338 [safi],
9339 PEER_CAP_ADDPATH_AF_RX_RCV))
9340 json_object_boolean_true_add(
9341 json_sub,
9342 "rxReceived");
9343 }
9344
9345 if (CHECK_FLAG(
9346 p->af_cap[afi]
9347 [safi],
9348 PEER_CAP_ADDPATH_AF_TX_ADV)
9349 || CHECK_FLAG(
9350 p->af_cap[afi]
9351 [safi],
9352 PEER_CAP_ADDPATH_AF_TX_RCV)
9353 || CHECK_FLAG(
9354 p->af_cap[afi]
9355 [safi],
9356 PEER_CAP_ADDPATH_AF_RX_ADV)
9357 || CHECK_FLAG(
9358 p->af_cap[afi]
9359 [safi],
9360 PEER_CAP_ADDPATH_AF_RX_RCV))
9361 json_object_object_add(
9362 json_add,
9363 print_store,
9364 json_sub);
9365 else
9366 json_object_free(
9367 json_sub);
9368 }
9369
9370 json_object_object_add(
9371 json_cap, "addPath", json_add);
9372 }
9373
9374 /* Dynamic */
9375 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9376 || CHECK_FLAG(p->cap,
9377 PEER_CAP_DYNAMIC_ADV)) {
9378 if (CHECK_FLAG(p->cap,
9379 PEER_CAP_DYNAMIC_ADV)
9380 && CHECK_FLAG(p->cap,
9381 PEER_CAP_DYNAMIC_RCV))
9382 json_object_string_add(
9383 json_cap, "dynamic",
9384 "advertisedAndReceived");
9385 else if (CHECK_FLAG(
9386 p->cap,
9387 PEER_CAP_DYNAMIC_ADV))
9388 json_object_string_add(
9389 json_cap, "dynamic",
9390 "advertised");
9391 else if (CHECK_FLAG(
9392 p->cap,
9393 PEER_CAP_DYNAMIC_RCV))
9394 json_object_string_add(
9395 json_cap, "dynamic",
9396 "received");
9397 }
9398
9399 /* Extended nexthop */
9400 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9401 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9402 json_object *json_nxt = NULL;
9403 const char *print_store;
9404
9405
9406 if (CHECK_FLAG(p->cap,
9407 PEER_CAP_ENHE_ADV)
9408 && CHECK_FLAG(p->cap,
9409 PEER_CAP_ENHE_RCV))
9410 json_object_string_add(
9411 json_cap,
9412 "extendedNexthop",
9413 "advertisedAndReceived");
9414 else if (CHECK_FLAG(p->cap,
9415 PEER_CAP_ENHE_ADV))
9416 json_object_string_add(
9417 json_cap,
9418 "extendedNexthop",
9419 "advertised");
9420 else if (CHECK_FLAG(p->cap,
9421 PEER_CAP_ENHE_RCV))
9422 json_object_string_add(
9423 json_cap,
9424 "extendedNexthop",
9425 "received");
9426
9427 if (CHECK_FLAG(p->cap,
9428 PEER_CAP_ENHE_RCV)) {
9429 json_nxt =
9430 json_object_new_object();
9431
9432 for (safi = SAFI_UNICAST;
9433 safi < SAFI_MAX; safi++) {
9434 if (CHECK_FLAG(
9435 p->af_cap
9436 [AFI_IP]
9437 [safi],
9438 PEER_CAP_ENHE_AF_RCV)) {
9439 print_store = afi_safi_print(
9440 AFI_IP,
9441 safi);
9442 json_object_string_add(
9443 json_nxt,
9444 print_store,
9445 "recieved");
9446 }
9447 }
9448 json_object_object_add(
9449 json_cap,
9450 "extendedNexthopFamililesByPeer",
9451 json_nxt);
9452 }
9453 }
9454
9455 /* Route Refresh */
9456 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9457 || CHECK_FLAG(p->cap,
9458 PEER_CAP_REFRESH_NEW_RCV)
9459 || CHECK_FLAG(p->cap,
9460 PEER_CAP_REFRESH_OLD_RCV)) {
9461 if (CHECK_FLAG(p->cap,
9462 PEER_CAP_REFRESH_ADV)
9463 && (CHECK_FLAG(
9464 p->cap,
9465 PEER_CAP_REFRESH_NEW_RCV)
9466 || CHECK_FLAG(
9467 p->cap,
9468 PEER_CAP_REFRESH_OLD_RCV))) {
9469 if (CHECK_FLAG(
9470 p->cap,
9471 PEER_CAP_REFRESH_OLD_RCV)
9472 && CHECK_FLAG(
9473 p->cap,
9474 PEER_CAP_REFRESH_NEW_RCV))
9475 json_object_string_add(
9476 json_cap,
9477 "routeRefresh",
9478 "advertisedAndReceivedOldNew");
9479 else {
9480 if (CHECK_FLAG(
9481 p->cap,
9482 PEER_CAP_REFRESH_OLD_RCV))
9483 json_object_string_add(
9484 json_cap,
9485 "routeRefresh",
9486 "advertisedAndReceivedOld");
9487 else
9488 json_object_string_add(
9489 json_cap,
9490 "routeRefresh",
9491 "advertisedAndReceivedNew");
9492 }
9493 } else if (
9494 CHECK_FLAG(
9495 p->cap,
9496 PEER_CAP_REFRESH_ADV))
9497 json_object_string_add(
9498 json_cap,
9499 "routeRefresh",
9500 "advertised");
9501 else if (
9502 CHECK_FLAG(
9503 p->cap,
9504 PEER_CAP_REFRESH_NEW_RCV)
9505 || CHECK_FLAG(
9506 p->cap,
9507 PEER_CAP_REFRESH_OLD_RCV))
9508 json_object_string_add(
9509 json_cap,
9510 "routeRefresh",
9511 "received");
9512 }
9513
9514 /* Multiprotocol Extensions */
9515 json_object *json_multi = NULL;
9516 json_multi = json_object_new_object();
9517
9518 FOREACH_AFI_SAFI (afi, safi) {
9519 if (p->afc_adv[afi][safi]
9520 || p->afc_recv[afi][safi]) {
9521 json_object *json_exten = NULL;
9522 json_exten =
9523 json_object_new_object();
9524
9525 if (p->afc_adv[afi][safi]
9526 && p->afc_recv[afi][safi])
9527 json_object_boolean_true_add(
9528 json_exten,
9529 "advertisedAndReceived");
9530 else if (p->afc_adv[afi][safi])
9531 json_object_boolean_true_add(
9532 json_exten,
9533 "advertised");
9534 else if (p->afc_recv[afi][safi])
9535 json_object_boolean_true_add(
9536 json_exten,
9537 "received");
9538
9539 json_object_object_add(
9540 json_multi,
9541 afi_safi_print(afi,
9542 safi),
9543 json_exten);
9544 }
9545 }
9546 json_object_object_add(
9547 json_cap, "multiprotocolExtensions",
9548 json_multi);
9549
9550 /* Hostname capabilities */
9551 json_object *json_hname = NULL;
9552
9553 json_hname = json_object_new_object();
9554
9555 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9556 json_object_string_add(
9557 json_hname, "advHostName",
9558 bgp->peer_self->hostname
9559 ? bgp->peer_self
9560 ->hostname
9561 : "n/a");
9562 json_object_string_add(
9563 json_hname, "advDomainName",
9564 bgp->peer_self->domainname
9565 ? bgp->peer_self
9566 ->domainname
9567 : "n/a");
9568 }
9569
9570
9571 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9572 json_object_string_add(
9573 json_hname, "rcvHostName",
9574 p->hostname ? p->hostname
9575 : "n/a");
9576 json_object_string_add(
9577 json_hname, "rcvDomainName",
9578 p->domainname ? p->domainname
9579 : "n/a");
9580 }
9581
9582 json_object_object_add(json_cap, "hostName",
9583 json_hname);
9584
9585 /* Gracefull Restart */
9586 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9587 || CHECK_FLAG(p->cap,
9588 PEER_CAP_RESTART_ADV)) {
9589 if (CHECK_FLAG(p->cap,
9590 PEER_CAP_RESTART_ADV)
9591 && CHECK_FLAG(p->cap,
9592 PEER_CAP_RESTART_RCV))
9593 json_object_string_add(
9594 json_cap,
9595 "gracefulRestart",
9596 "advertisedAndReceived");
9597 else if (CHECK_FLAG(
9598 p->cap,
9599 PEER_CAP_RESTART_ADV))
9600 json_object_string_add(
9601 json_cap,
9602 "gracefulRestartCapability",
9603 "advertised");
9604 else if (CHECK_FLAG(
9605 p->cap,
9606 PEER_CAP_RESTART_RCV))
9607 json_object_string_add(
9608 json_cap,
9609 "gracefulRestartCapability",
9610 "received");
9611
9612 if (CHECK_FLAG(p->cap,
9613 PEER_CAP_RESTART_RCV)) {
9614 int restart_af_count = 0;
9615 json_object *json_restart =
9616 NULL;
9617 json_restart =
9618 json_object_new_object();
9619
9620 json_object_int_add(
9621 json_cap,
9622 "gracefulRestartRemoteTimerMsecs",
9623 p->v_gr_restart * 1000);
9624
9625 FOREACH_AFI_SAFI (afi, safi) {
9626 if (CHECK_FLAG(
9627 p->af_cap
9628 [afi]
9629 [safi],
9630 PEER_CAP_RESTART_AF_RCV)) {
9631 json_object *
9632 json_sub =
9633 NULL;
9634 json_sub =
9635 json_object_new_object();
9636
9637 if (CHECK_FLAG(
9638 p->af_cap
9639 [afi]
9640 [safi],
9641 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9642 json_object_boolean_true_add(
9643 json_sub,
9644 "preserved");
9645 restart_af_count++;
9646 json_object_object_add(
9647 json_restart,
9648 afi_safi_print(
9649 afi,
9650 safi),
9651 json_sub);
9652 }
9653 }
9654 if (!restart_af_count) {
9655 json_object_string_add(
9656 json_cap,
9657 "addressFamiliesByPeer",
9658 "none");
9659 json_object_free(
9660 json_restart);
9661 } else
9662 json_object_object_add(
9663 json_cap,
9664 "addressFamiliesByPeer",
9665 json_restart);
9666 }
9667 }
9668 json_object_object_add(json_neigh,
9669 "neighborCapabilities",
9670 json_cap);
9671 } else {
9672 vty_out(vty, " Neighbor capabilities:\n");
9673
9674 /* AS4 */
9675 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9676 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9677 vty_out(vty, " 4 Byte AS:");
9678 if (CHECK_FLAG(p->cap,
9679 PEER_CAP_AS4_ADV))
9680 vty_out(vty, " advertised");
9681 if (CHECK_FLAG(p->cap,
9682 PEER_CAP_AS4_RCV))
9683 vty_out(vty, " %sreceived",
9684 CHECK_FLAG(
9685 p->cap,
9686 PEER_CAP_AS4_ADV)
9687 ? "and "
9688 : "");
9689 vty_out(vty, "\n");
9690 }
9691
9692 /* AddPath */
9693 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9694 || CHECK_FLAG(p->cap,
9695 PEER_CAP_ADDPATH_ADV)) {
9696 vty_out(vty, " AddPath:\n");
9697
9698 FOREACH_AFI_SAFI (afi, safi) {
9699 if (CHECK_FLAG(
9700 p->af_cap[afi]
9701 [safi],
9702 PEER_CAP_ADDPATH_AF_TX_ADV)
9703 || CHECK_FLAG(
9704 p->af_cap[afi]
9705 [safi],
9706 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9707 vty_out(vty,
9708 " %s: TX ",
9709 afi_safi_print(
9710 afi,
9711 safi));
9712
9713 if (CHECK_FLAG(
9714 p->af_cap
9715 [afi]
9716 [safi],
9717 PEER_CAP_ADDPATH_AF_TX_ADV))
9718 vty_out(vty,
9719 "advertised %s",
9720 afi_safi_print(
9721 afi,
9722 safi));
9723
9724 if (CHECK_FLAG(
9725 p->af_cap
9726 [afi]
9727 [safi],
9728 PEER_CAP_ADDPATH_AF_TX_RCV))
9729 vty_out(vty,
9730 "%sreceived",
9731 CHECK_FLAG(
9732 p->af_cap
9733 [afi]
9734 [safi],
9735 PEER_CAP_ADDPATH_AF_TX_ADV)
9736 ? " and "
9737 : "");
9738
9739 vty_out(vty, "\n");
9740 }
9741
9742 if (CHECK_FLAG(
9743 p->af_cap[afi]
9744 [safi],
9745 PEER_CAP_ADDPATH_AF_RX_ADV)
9746 || CHECK_FLAG(
9747 p->af_cap[afi]
9748 [safi],
9749 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9750 vty_out(vty,
9751 " %s: RX ",
9752 afi_safi_print(
9753 afi,
9754 safi));
9755
9756 if (CHECK_FLAG(
9757 p->af_cap
9758 [afi]
9759 [safi],
9760 PEER_CAP_ADDPATH_AF_RX_ADV))
9761 vty_out(vty,
9762 "advertised %s",
9763 afi_safi_print(
9764 afi,
9765 safi));
9766
9767 if (CHECK_FLAG(
9768 p->af_cap
9769 [afi]
9770 [safi],
9771 PEER_CAP_ADDPATH_AF_RX_RCV))
9772 vty_out(vty,
9773 "%sreceived",
9774 CHECK_FLAG(
9775 p->af_cap
9776 [afi]
9777 [safi],
9778 PEER_CAP_ADDPATH_AF_RX_ADV)
9779 ? " and "
9780 : "");
9781
9782 vty_out(vty, "\n");
9783 }
9784 }
9785 }
9786
9787 /* Dynamic */
9788 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9789 || CHECK_FLAG(p->cap,
9790 PEER_CAP_DYNAMIC_ADV)) {
9791 vty_out(vty, " Dynamic:");
9792 if (CHECK_FLAG(p->cap,
9793 PEER_CAP_DYNAMIC_ADV))
9794 vty_out(vty, " advertised");
9795 if (CHECK_FLAG(p->cap,
9796 PEER_CAP_DYNAMIC_RCV))
9797 vty_out(vty, " %sreceived",
9798 CHECK_FLAG(
9799 p->cap,
9800 PEER_CAP_DYNAMIC_ADV)
9801 ? "and "
9802 : "");
9803 vty_out(vty, "\n");
9804 }
9805
9806 /* Extended nexthop */
9807 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9808 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9809 vty_out(vty, " Extended nexthop:");
9810 if (CHECK_FLAG(p->cap,
9811 PEER_CAP_ENHE_ADV))
9812 vty_out(vty, " advertised");
9813 if (CHECK_FLAG(p->cap,
9814 PEER_CAP_ENHE_RCV))
9815 vty_out(vty, " %sreceived",
9816 CHECK_FLAG(
9817 p->cap,
9818 PEER_CAP_ENHE_ADV)
9819 ? "and "
9820 : "");
9821 vty_out(vty, "\n");
9822
9823 if (CHECK_FLAG(p->cap,
9824 PEER_CAP_ENHE_RCV)) {
9825 vty_out(vty,
9826 " Address families by peer:\n ");
9827 for (safi = SAFI_UNICAST;
9828 safi < SAFI_MAX; safi++)
9829 if (CHECK_FLAG(
9830 p->af_cap
9831 [AFI_IP]
9832 [safi],
9833 PEER_CAP_ENHE_AF_RCV))
9834 vty_out(vty,
9835 " %s\n",
9836 afi_safi_print(
9837 AFI_IP,
9838 safi));
9839 }
9840 }
9841
9842 /* Route Refresh */
9843 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9844 || CHECK_FLAG(p->cap,
9845 PEER_CAP_REFRESH_NEW_RCV)
9846 || CHECK_FLAG(p->cap,
9847 PEER_CAP_REFRESH_OLD_RCV)) {
9848 vty_out(vty, " Route refresh:");
9849 if (CHECK_FLAG(p->cap,
9850 PEER_CAP_REFRESH_ADV))
9851 vty_out(vty, " advertised");
9852 if (CHECK_FLAG(p->cap,
9853 PEER_CAP_REFRESH_NEW_RCV)
9854 || CHECK_FLAG(
9855 p->cap,
9856 PEER_CAP_REFRESH_OLD_RCV))
9857 vty_out(vty, " %sreceived(%s)",
9858 CHECK_FLAG(
9859 p->cap,
9860 PEER_CAP_REFRESH_ADV)
9861 ? "and "
9862 : "",
9863 (CHECK_FLAG(
9864 p->cap,
9865 PEER_CAP_REFRESH_OLD_RCV)
9866 && CHECK_FLAG(
9867 p->cap,
9868 PEER_CAP_REFRESH_NEW_RCV))
9869 ? "old & new"
9870 : CHECK_FLAG(
9871 p->cap,
9872 PEER_CAP_REFRESH_OLD_RCV)
9873 ? "old"
9874 : "new");
9875
9876 vty_out(vty, "\n");
9877 }
9878
9879 /* Multiprotocol Extensions */
9880 FOREACH_AFI_SAFI (afi, safi)
9881 if (p->afc_adv[afi][safi]
9882 || p->afc_recv[afi][safi]) {
9883 vty_out(vty,
9884 " Address Family %s:",
9885 afi_safi_print(afi,
9886 safi));
9887 if (p->afc_adv[afi][safi])
9888 vty_out(vty,
9889 " advertised");
9890 if (p->afc_recv[afi][safi])
9891 vty_out(vty,
9892 " %sreceived",
9893 p->afc_adv[afi]
9894 [safi]
9895 ? "and "
9896 : "");
9897 vty_out(vty, "\n");
9898 }
9899
9900 /* Hostname capability */
9901 vty_out(vty, " Hostname Capability:");
9902
9903 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9904 vty_out(vty,
9905 " advertised (name: %s,domain name: %s)",
9906 bgp->peer_self->hostname
9907 ? bgp->peer_self
9908 ->hostname
9909 : "n/a",
9910 bgp->peer_self->domainname
9911 ? bgp->peer_self
9912 ->domainname
9913 : "n/a");
9914 } else {
9915 vty_out(vty, " not advertised");
9916 }
9917
9918 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9919 vty_out(vty,
9920 " received (name: %s,domain name: %s)",
9921 p->hostname ? p->hostname
9922 : "n/a",
9923 p->domainname ? p->domainname
9924 : "n/a");
9925 } else {
9926 vty_out(vty, " not received");
9927 }
9928
9929 vty_out(vty, "\n");
9930
9931 /* Gracefull Restart */
9932 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9933 || CHECK_FLAG(p->cap,
9934 PEER_CAP_RESTART_ADV)) {
9935 vty_out(vty,
9936 " Graceful Restart Capabilty:");
9937 if (CHECK_FLAG(p->cap,
9938 PEER_CAP_RESTART_ADV))
9939 vty_out(vty, " advertised");
9940 if (CHECK_FLAG(p->cap,
9941 PEER_CAP_RESTART_RCV))
9942 vty_out(vty, " %sreceived",
9943 CHECK_FLAG(
9944 p->cap,
9945 PEER_CAP_RESTART_ADV)
9946 ? "and "
9947 : "");
9948 vty_out(vty, "\n");
9949
9950 if (CHECK_FLAG(p->cap,
9951 PEER_CAP_RESTART_RCV)) {
9952 int restart_af_count = 0;
9953
9954 vty_out(vty,
9955 " Remote Restart timer is %d seconds\n",
9956 p->v_gr_restart);
9957 vty_out(vty,
9958 " Address families by peer:\n ");
9959
9960 FOREACH_AFI_SAFI (afi, safi)
9961 if (CHECK_FLAG(
9962 p->af_cap
9963 [afi]
9964 [safi],
9965 PEER_CAP_RESTART_AF_RCV)) {
9966 vty_out(vty,
9967 "%s%s(%s)",
9968 restart_af_count
9969 ? ", "
9970 : "",
9971 afi_safi_print(
9972 afi,
9973 safi),
9974 CHECK_FLAG(
9975 p->af_cap
9976 [afi]
9977 [safi],
9978 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9979 ? "preserved"
9980 : "not preserved");
9981 restart_af_count++;
9982 }
9983 if (!restart_af_count)
9984 vty_out(vty, "none");
9985 vty_out(vty, "\n");
9986 }
9987 }
9988 }
9989 }
9990 }
9991
9992 /* graceful restart information */
9993 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9994 || p->t_gr_stale) {
9995 json_object *json_grace = NULL;
9996 json_object *json_grace_send = NULL;
9997 json_object *json_grace_recv = NULL;
9998 int eor_send_af_count = 0;
9999 int eor_receive_af_count = 0;
10000
10001 if (use_json) {
10002 json_grace = json_object_new_object();
10003 json_grace_send = json_object_new_object();
10004 json_grace_recv = json_object_new_object();
10005
10006 if (p->status == Established) {
10007 FOREACH_AFI_SAFI (afi, safi) {
10008 if (CHECK_FLAG(p->af_sflags[afi][safi],
10009 PEER_STATUS_EOR_SEND)) {
10010 json_object_boolean_true_add(
10011 json_grace_send,
10012 afi_safi_print(afi,
10013 safi));
10014 eor_send_af_count++;
10015 }
10016 }
10017 FOREACH_AFI_SAFI (afi, safi) {
10018 if (CHECK_FLAG(
10019 p->af_sflags[afi][safi],
10020 PEER_STATUS_EOR_RECEIVED)) {
10021 json_object_boolean_true_add(
10022 json_grace_recv,
10023 afi_safi_print(afi,
10024 safi));
10025 eor_receive_af_count++;
10026 }
10027 }
10028 }
10029
10030 json_object_object_add(json_grace, "endOfRibSend",
10031 json_grace_send);
10032 json_object_object_add(json_grace, "endOfRibRecv",
10033 json_grace_recv);
10034
10035 if (p->t_gr_restart)
10036 json_object_int_add(json_grace,
10037 "gracefulRestartTimerMsecs",
10038 thread_timer_remain_second(
10039 p->t_gr_restart)
10040 * 1000);
10041
10042 if (p->t_gr_stale)
10043 json_object_int_add(
10044 json_grace,
10045 "gracefulStalepathTimerMsecs",
10046 thread_timer_remain_second(
10047 p->t_gr_stale)
10048 * 1000);
10049
10050 json_object_object_add(
10051 json_neigh, "gracefulRestartInfo", json_grace);
10052 } else {
10053 vty_out(vty, " Graceful restart informations:\n");
10054 if (p->status == Established) {
10055 vty_out(vty, " End-of-RIB send: ");
10056 FOREACH_AFI_SAFI (afi, safi) {
10057 if (CHECK_FLAG(p->af_sflags[afi][safi],
10058 PEER_STATUS_EOR_SEND)) {
10059 vty_out(vty, "%s%s",
10060 eor_send_af_count ? ", "
10061 : "",
10062 afi_safi_print(afi,
10063 safi));
10064 eor_send_af_count++;
10065 }
10066 }
10067 vty_out(vty, "\n");
10068 vty_out(vty, " End-of-RIB received: ");
10069 FOREACH_AFI_SAFI (afi, safi) {
10070 if (CHECK_FLAG(
10071 p->af_sflags[afi][safi],
10072 PEER_STATUS_EOR_RECEIVED)) {
10073 vty_out(vty, "%s%s",
10074 eor_receive_af_count
10075 ? ", "
10076 : "",
10077 afi_safi_print(afi,
10078 safi));
10079 eor_receive_af_count++;
10080 }
10081 }
10082 vty_out(vty, "\n");
10083 }
10084
10085 if (p->t_gr_restart)
10086 vty_out(vty,
10087 " The remaining time of restart timer is %ld\n",
10088 thread_timer_remain_second(
10089 p->t_gr_restart));
10090
10091 if (p->t_gr_stale)
10092 vty_out(vty,
10093 " The remaining time of stalepath timer is %ld\n",
10094 thread_timer_remain_second(
10095 p->t_gr_stale));
10096 }
10097 }
10098 if (use_json) {
10099 json_object *json_stat = NULL;
10100 json_stat = json_object_new_object();
10101 /* Packet counts. */
10102 json_object_int_add(json_stat, "depthInq", 0);
10103 json_object_int_add(json_stat, "depthOutq",
10104 (unsigned long)p->obuf->count);
10105 json_object_int_add(json_stat, "opensSent",
10106 atomic_load_explicit(&p->open_out,
10107 memory_order_relaxed));
10108 json_object_int_add(json_stat, "opensRecv",
10109 atomic_load_explicit(&p->open_in,
10110 memory_order_relaxed));
10111 json_object_int_add(json_stat, "notificationsSent",
10112 atomic_load_explicit(&p->notify_out,
10113 memory_order_relaxed));
10114 json_object_int_add(json_stat, "notificationsRecv",
10115 atomic_load_explicit(&p->notify_in,
10116 memory_order_relaxed));
10117 json_object_int_add(json_stat, "updatesSent",
10118 atomic_load_explicit(&p->update_out,
10119 memory_order_relaxed));
10120 json_object_int_add(json_stat, "updatesRecv",
10121 atomic_load_explicit(&p->update_in,
10122 memory_order_relaxed));
10123 json_object_int_add(json_stat, "keepalivesSent",
10124 atomic_load_explicit(&p->keepalive_out,
10125 memory_order_relaxed));
10126 json_object_int_add(json_stat, "keepalivesRecv",
10127 atomic_load_explicit(&p->keepalive_in,
10128 memory_order_relaxed));
10129 json_object_int_add(json_stat, "routeRefreshSent",
10130 atomic_load_explicit(&p->refresh_out,
10131 memory_order_relaxed));
10132 json_object_int_add(json_stat, "routeRefreshRecv",
10133 atomic_load_explicit(&p->refresh_in,
10134 memory_order_relaxed));
10135 json_object_int_add(json_stat, "capabilitySent",
10136 atomic_load_explicit(&p->dynamic_cap_out,
10137 memory_order_relaxed));
10138 json_object_int_add(json_stat, "capabilityRecv",
10139 atomic_load_explicit(&p->dynamic_cap_in,
10140 memory_order_relaxed));
10141 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
10142 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
10143 json_object_object_add(json_neigh, "messageStats", json_stat);
10144 } else {
10145 /* Packet counts. */
10146 vty_out(vty, " Message statistics:\n");
10147 vty_out(vty, " Inq depth is 0\n");
10148 vty_out(vty, " Outq depth is %lu\n",
10149 (unsigned long)p->obuf->count);
10150 vty_out(vty, " Sent Rcvd\n");
10151 vty_out(vty, " Opens: %10d %10d\n",
10152 atomic_load_explicit(&p->open_out,
10153 memory_order_relaxed),
10154 atomic_load_explicit(&p->open_in,
10155 memory_order_relaxed));
10156 vty_out(vty, " Notifications: %10d %10d\n",
10157 atomic_load_explicit(&p->notify_out,
10158 memory_order_relaxed),
10159 atomic_load_explicit(&p->notify_in,
10160 memory_order_relaxed));
10161 vty_out(vty, " Updates: %10d %10d\n",
10162 atomic_load_explicit(&p->update_out,
10163 memory_order_relaxed),
10164 atomic_load_explicit(&p->update_in,
10165 memory_order_relaxed));
10166 vty_out(vty, " Keepalives: %10d %10d\n",
10167 atomic_load_explicit(&p->keepalive_out,
10168 memory_order_relaxed),
10169 atomic_load_explicit(&p->keepalive_in,
10170 memory_order_relaxed));
10171 vty_out(vty, " Route Refresh: %10d %10d\n",
10172 atomic_load_explicit(&p->refresh_out,
10173 memory_order_relaxed),
10174 atomic_load_explicit(&p->refresh_in,
10175 memory_order_relaxed));
10176 vty_out(vty, " Capability: %10d %10d\n",
10177 atomic_load_explicit(&p->dynamic_cap_out,
10178 memory_order_relaxed),
10179 atomic_load_explicit(&p->dynamic_cap_in,
10180 memory_order_relaxed));
10181 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
10182 PEER_TOTAL_RX(p));
10183 }
10184
10185 if (use_json) {
10186 /* advertisement-interval */
10187 json_object_int_add(json_neigh,
10188 "minBtwnAdvertisementRunsTimerMsecs",
10189 p->v_routeadv * 1000);
10190
10191 /* Update-source. */
10192 if (p->update_if || p->update_source) {
10193 if (p->update_if)
10194 json_object_string_add(json_neigh,
10195 "updateSource",
10196 p->update_if);
10197 else if (p->update_source)
10198 json_object_string_add(
10199 json_neigh, "updateSource",
10200 sockunion2str(p->update_source, buf1,
10201 SU_ADDRSTRLEN));
10202 }
10203 } else {
10204 /* advertisement-interval */
10205 vty_out(vty,
10206 " Minimum time between advertisement runs is %d seconds\n",
10207 p->v_routeadv);
10208
10209 /* Update-source. */
10210 if (p->update_if || p->update_source) {
10211 vty_out(vty, " Update source is ");
10212 if (p->update_if)
10213 vty_out(vty, "%s", p->update_if);
10214 else if (p->update_source)
10215 vty_out(vty, "%s",
10216 sockunion2str(p->update_source, buf1,
10217 SU_ADDRSTRLEN));
10218 vty_out(vty, "\n");
10219 }
10220
10221 vty_out(vty, "\n");
10222 }
10223
10224 /* Address Family Information */
10225 json_object *json_hold = NULL;
10226
10227 if (use_json)
10228 json_hold = json_object_new_object();
10229
10230 FOREACH_AFI_SAFI (afi, safi)
10231 if (p->afc[afi][safi])
10232 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10233 json_hold);
10234
10235 if (use_json) {
10236 json_object_object_add(json_neigh, "addressFamilyInfo",
10237 json_hold);
10238 json_object_int_add(json_neigh, "connectionsEstablished",
10239 p->established);
10240 json_object_int_add(json_neigh, "connectionsDropped",
10241 p->dropped);
10242 } else
10243 vty_out(vty, " Connections established %d; dropped %d\n",
10244 p->established, p->dropped);
10245
10246 if (!p->last_reset) {
10247 if (use_json)
10248 json_object_string_add(json_neigh, "lastReset",
10249 "never");
10250 else
10251 vty_out(vty, " Last reset never\n");
10252 } else {
10253 if (use_json) {
10254 time_t uptime;
10255 struct tm *tm;
10256
10257 uptime = bgp_clock();
10258 uptime -= p->resettime;
10259 tm = gmtime(&uptime);
10260 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10261 (tm->tm_sec * 1000)
10262 + (tm->tm_min * 60000)
10263 + (tm->tm_hour * 3600000));
10264 json_object_string_add(
10265 json_neigh, "lastResetDueTo",
10266 peer_down_str[(int)p->last_reset]);
10267 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10268 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10269 char errorcodesubcode_hexstr[5];
10270 char errorcodesubcode_str[256];
10271
10272 code_str = bgp_notify_code_str(p->notify.code);
10273 subcode_str = bgp_notify_subcode_str(
10274 p->notify.code, p->notify.subcode);
10275
10276 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10277 p->notify.code, p->notify.subcode);
10278 json_object_string_add(json_neigh,
10279 "lastErrorCodeSubcode",
10280 errorcodesubcode_hexstr);
10281 snprintf(errorcodesubcode_str, 255, "%s%s",
10282 code_str, subcode_str);
10283 json_object_string_add(json_neigh,
10284 "lastNotificationReason",
10285 errorcodesubcode_str);
10286 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10287 && p->notify.code == BGP_NOTIFY_CEASE
10288 && (p->notify.subcode
10289 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10290 || p->notify.subcode
10291 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10292 && p->notify.length) {
10293 char msgbuf[1024];
10294 const char *msg_str;
10295
10296 msg_str = bgp_notify_admin_message(
10297 msgbuf, sizeof(msgbuf),
10298 (uint8_t *)p->notify.data,
10299 p->notify.length);
10300 if (msg_str)
10301 json_object_string_add(
10302 json_neigh,
10303 "lastShutdownDescription",
10304 msg_str);
10305 }
10306 }
10307 } else {
10308 vty_out(vty, " Last reset %s, ",
10309 peer_uptime(p->resettime, timebuf,
10310 BGP_UPTIME_LEN, 0, NULL));
10311
10312 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10313 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10314 code_str = bgp_notify_code_str(p->notify.code);
10315 subcode_str = bgp_notify_subcode_str(
10316 p->notify.code, p->notify.subcode);
10317 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10318 p->last_reset == PEER_DOWN_NOTIFY_SEND
10319 ? "sent"
10320 : "received",
10321 code_str, subcode_str);
10322 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10323 && p->notify.code == BGP_NOTIFY_CEASE
10324 && (p->notify.subcode
10325 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10326 || p->notify.subcode
10327 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10328 && p->notify.length) {
10329 char msgbuf[1024];
10330 const char *msg_str;
10331
10332 msg_str = bgp_notify_admin_message(
10333 msgbuf, sizeof(msgbuf),
10334 (uint8_t *)p->notify.data,
10335 p->notify.length);
10336 if (msg_str)
10337 vty_out(vty,
10338 " Message: \"%s\"\n",
10339 msg_str);
10340 }
10341 } else {
10342 vty_out(vty, "due to %s\n",
10343 peer_down_str[(int)p->last_reset]);
10344 }
10345
10346 if (p->last_reset_cause_size) {
10347 msg = p->last_reset_cause;
10348 vty_out(vty,
10349 " Message received that caused BGP to send a NOTIFICATION:\n ");
10350 for (i = 1; i <= p->last_reset_cause_size;
10351 i++) {
10352 vty_out(vty, "%02X", *msg++);
10353
10354 if (i != p->last_reset_cause_size) {
10355 if (i % 16 == 0) {
10356 vty_out(vty, "\n ");
10357 } else if (i % 4 == 0) {
10358 vty_out(vty, " ");
10359 }
10360 }
10361 }
10362 vty_out(vty, "\n");
10363 }
10364 }
10365 }
10366
10367 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10368 if (use_json)
10369 json_object_boolean_true_add(json_neigh,
10370 "prefixesConfigExceedMax");
10371 else
10372 vty_out(vty,
10373 " Peer had exceeded the max. no. of prefixes configured.\n");
10374
10375 if (p->t_pmax_restart) {
10376 if (use_json) {
10377 json_object_boolean_true_add(
10378 json_neigh, "reducePrefixNumFrom");
10379 json_object_int_add(json_neigh,
10380 "restartInTimerMsec",
10381 thread_timer_remain_second(
10382 p->t_pmax_restart)
10383 * 1000);
10384 } else
10385 vty_out(vty,
10386 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10387 p->host, thread_timer_remain_second(
10388 p->t_pmax_restart));
10389 } else {
10390 if (use_json)
10391 json_object_boolean_true_add(
10392 json_neigh,
10393 "reducePrefixNumAndClearIpBgp");
10394 else
10395 vty_out(vty,
10396 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10397 p->host);
10398 }
10399 }
10400
10401 /* EBGP Multihop and GTSM */
10402 if (p->sort != BGP_PEER_IBGP) {
10403 if (use_json) {
10404 if (p->gtsm_hops > 0)
10405 json_object_int_add(json_neigh,
10406 "externalBgpNbrMaxHopsAway",
10407 p->gtsm_hops);
10408 else if (p->ttl > 1)
10409 json_object_int_add(json_neigh,
10410 "externalBgpNbrMaxHopsAway",
10411 p->ttl);
10412 } else {
10413 if (p->gtsm_hops > 0)
10414 vty_out(vty,
10415 " External BGP neighbor may be up to %d hops away.\n",
10416 p->gtsm_hops);
10417 else if (p->ttl > 1)
10418 vty_out(vty,
10419 " External BGP neighbor may be up to %d hops away.\n",
10420 p->ttl);
10421 }
10422 } else {
10423 if (p->gtsm_hops > 0) {
10424 if (use_json)
10425 json_object_int_add(json_neigh,
10426 "internalBgpNbrMaxHopsAway",
10427 p->gtsm_hops);
10428 else
10429 vty_out(vty,
10430 " Internal BGP neighbor may be up to %d hops away.\n",
10431 p->gtsm_hops);
10432 }
10433 }
10434
10435 /* Local address. */
10436 if (p->su_local) {
10437 if (use_json) {
10438 json_object_string_add(json_neigh, "hostLocal",
10439 sockunion2str(p->su_local, buf1,
10440 SU_ADDRSTRLEN));
10441 json_object_int_add(json_neigh, "portLocal",
10442 ntohs(p->su_local->sin.sin_port));
10443 } else
10444 vty_out(vty, "Local host: %s, Local port: %d\n",
10445 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10446 ntohs(p->su_local->sin.sin_port));
10447 }
10448
10449 /* Remote address. */
10450 if (p->su_remote) {
10451 if (use_json) {
10452 json_object_string_add(json_neigh, "hostForeign",
10453 sockunion2str(p->su_remote, buf1,
10454 SU_ADDRSTRLEN));
10455 json_object_int_add(json_neigh, "portForeign",
10456 ntohs(p->su_remote->sin.sin_port));
10457 } else
10458 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10459 sockunion2str(p->su_remote, buf1,
10460 SU_ADDRSTRLEN),
10461 ntohs(p->su_remote->sin.sin_port));
10462 }
10463
10464 /* Nexthop display. */
10465 if (p->su_local) {
10466 if (use_json) {
10467 json_object_string_add(json_neigh, "nexthop",
10468 inet_ntop(AF_INET,
10469 &p->nexthop.v4, buf1,
10470 sizeof(buf1)));
10471 json_object_string_add(json_neigh, "nexthopGlobal",
10472 inet_ntop(AF_INET6,
10473 &p->nexthop.v6_global,
10474 buf1, sizeof(buf1)));
10475 json_object_string_add(json_neigh, "nexthopLocal",
10476 inet_ntop(AF_INET6,
10477 &p->nexthop.v6_local,
10478 buf1, sizeof(buf1)));
10479 if (p->shared_network)
10480 json_object_string_add(json_neigh,
10481 "bgpConnection",
10482 "sharedNetwork");
10483 else
10484 json_object_string_add(json_neigh,
10485 "bgpConnection",
10486 "nonSharedNetwork");
10487 } else {
10488 vty_out(vty, "Nexthop: %s\n",
10489 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10490 sizeof(buf1)));
10491 vty_out(vty, "Nexthop global: %s\n",
10492 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10493 sizeof(buf1)));
10494 vty_out(vty, "Nexthop local: %s\n",
10495 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10496 sizeof(buf1)));
10497 vty_out(vty, "BGP connection: %s\n",
10498 p->shared_network ? "shared network"
10499 : "non shared network");
10500 }
10501 }
10502
10503 /* Timer information. */
10504 if (use_json) {
10505 json_object_int_add(json_neigh, "connectRetryTimer",
10506 p->v_connect);
10507 if (p->status == Established && p->rtt)
10508 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10509 p->rtt);
10510 if (p->t_start)
10511 json_object_int_add(
10512 json_neigh, "nextStartTimerDueInMsecs",
10513 thread_timer_remain_second(p->t_start) * 1000);
10514 if (p->t_connect)
10515 json_object_int_add(
10516 json_neigh, "nextConnectTimerDueInMsecs",
10517 thread_timer_remain_second(p->t_connect)
10518 * 1000);
10519 if (p->t_routeadv) {
10520 json_object_int_add(json_neigh, "mraiInterval",
10521 p->v_routeadv);
10522 json_object_int_add(
10523 json_neigh, "mraiTimerExpireInMsecs",
10524 thread_timer_remain_second(p->t_routeadv)
10525 * 1000);
10526 }
10527 if (p->password)
10528 json_object_int_add(json_neigh, "authenticationEnabled",
10529 1);
10530
10531 if (p->t_read)
10532 json_object_string_add(json_neigh, "readThread", "on");
10533 else
10534 json_object_string_add(json_neigh, "readThread", "off");
10535
10536 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10537 json_object_string_add(json_neigh, "writeThread", "on");
10538 else
10539 json_object_string_add(json_neigh, "writeThread",
10540 "off");
10541 } else {
10542 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10543 p->v_connect);
10544 if (p->status == Established && p->rtt)
10545 vty_out(vty, "Estimated round trip time: %d ms\n",
10546 p->rtt);
10547 if (p->t_start)
10548 vty_out(vty, "Next start timer due in %ld seconds\n",
10549 thread_timer_remain_second(p->t_start));
10550 if (p->t_connect)
10551 vty_out(vty, "Next connect timer due in %ld seconds\n",
10552 thread_timer_remain_second(p->t_connect));
10553 if (p->t_routeadv)
10554 vty_out(vty,
10555 "MRAI (interval %u) timer expires in %ld seconds\n",
10556 p->v_routeadv,
10557 thread_timer_remain_second(p->t_routeadv));
10558 if (p->password)
10559 vty_out(vty, "Peer Authentication Enabled\n");
10560
10561 vty_out(vty, "Read thread: %s Write thread: %s\n",
10562 p->t_read ? "on" : "off",
10563 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10564 ? "on"
10565 : "off");
10566 }
10567
10568 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10569 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10570 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10571
10572 if (!use_json)
10573 vty_out(vty, "\n");
10574
10575 /* BFD information. */
10576 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10577
10578 if (use_json) {
10579 if (p->conf_if) /* Configured interface name. */
10580 json_object_object_add(json, p->conf_if, json_neigh);
10581 else /* Configured IP address. */
10582 json_object_object_add(json, p->host, json_neigh);
10583 }
10584 }
10585
10586 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10587 enum show_type type, union sockunion *su,
10588 const char *conf_if, uint8_t use_json,
10589 json_object *json)
10590 {
10591 struct listnode *node, *nnode;
10592 struct peer *peer;
10593 int find = 0;
10594
10595 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10596 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10597 continue;
10598
10599 switch (type) {
10600 case show_all:
10601 bgp_show_peer(vty, peer, use_json, json);
10602 break;
10603 case show_peer:
10604 if (conf_if) {
10605 if ((peer->conf_if
10606 && !strcmp(peer->conf_if, conf_if))
10607 || (peer->hostname
10608 && !strcmp(peer->hostname, conf_if))) {
10609 find = 1;
10610 bgp_show_peer(vty, peer, use_json,
10611 json);
10612 }
10613 } else {
10614 if (sockunion_same(&peer->su, su)) {
10615 find = 1;
10616 bgp_show_peer(vty, peer, use_json,
10617 json);
10618 }
10619 }
10620 break;
10621 }
10622 }
10623
10624 if (type == show_peer && !find) {
10625 if (use_json)
10626 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10627 else
10628 vty_out(vty, "%% No such neighbor\n");
10629 }
10630
10631 if (use_json) {
10632 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10633 json, JSON_C_TO_STRING_PRETTY));
10634 json_object_free(json);
10635 } else {
10636 vty_out(vty, "\n");
10637 }
10638
10639 return CMD_SUCCESS;
10640 }
10641
10642 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10643 enum show_type type,
10644 const char *ip_str,
10645 uint8_t use_json)
10646 {
10647 struct listnode *node, *nnode;
10648 struct bgp *bgp;
10649 union sockunion su;
10650 json_object *json = NULL;
10651 int ret, is_first = 1;
10652
10653 if (use_json)
10654 vty_out(vty, "{\n");
10655
10656 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10657 if (use_json) {
10658 if (!(json = json_object_new_object())) {
10659 zlog_err(
10660 "Unable to allocate memory for JSON object");
10661 vty_out(vty,
10662 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10663 return;
10664 }
10665
10666 json_object_int_add(json, "vrfId",
10667 (bgp->vrf_id == VRF_UNKNOWN)
10668 ? -1
10669 : (int64_t)bgp->vrf_id);
10670 json_object_string_add(
10671 json, "vrfName",
10672 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10673 ? "Default"
10674 : bgp->name);
10675
10676 if (!is_first)
10677 vty_out(vty, ",\n");
10678 else
10679 is_first = 0;
10680
10681 vty_out(vty, "\"%s\":",
10682 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10683 ? "Default"
10684 : bgp->name);
10685 } else {
10686 vty_out(vty, "\nInstance %s:\n",
10687 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10688 ? "Default"
10689 : bgp->name);
10690 }
10691
10692 if (type == show_peer) {
10693 ret = str2sockunion(ip_str, &su);
10694 if (ret < 0)
10695 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10696 use_json, json);
10697 else
10698 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10699 use_json, json);
10700 } else {
10701 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10702 use_json, json);
10703 }
10704 }
10705
10706 if (use_json)
10707 vty_out(vty, "}\n");
10708 }
10709
10710 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10711 enum show_type type, const char *ip_str,
10712 uint8_t use_json)
10713 {
10714 int ret;
10715 struct bgp *bgp;
10716 union sockunion su;
10717 json_object *json = NULL;
10718
10719 if (name) {
10720 if (strmatch(name, "all")) {
10721 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10722 use_json);
10723 return CMD_SUCCESS;
10724 } else {
10725 bgp = bgp_lookup_by_name(name);
10726 if (!bgp) {
10727 if (use_json) {
10728 json = json_object_new_object();
10729 json_object_boolean_true_add(
10730 json, "bgpNoSuchInstance");
10731 vty_out(vty, "%s\n",
10732 json_object_to_json_string_ext(
10733 json,
10734 JSON_C_TO_STRING_PRETTY));
10735 json_object_free(json);
10736 } else
10737 vty_out(vty,
10738 "%% No such BGP instance exist\n");
10739
10740 return CMD_WARNING;
10741 }
10742 }
10743 } else {
10744 bgp = bgp_get_default();
10745 }
10746
10747 if (bgp) {
10748 json = json_object_new_object();
10749 if (ip_str) {
10750 ret = str2sockunion(ip_str, &su);
10751 if (ret < 0)
10752 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10753 use_json, json);
10754 else
10755 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10756 use_json, json);
10757 } else {
10758 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10759 json);
10760 }
10761 json_object_free(json);
10762 }
10763
10764 return CMD_SUCCESS;
10765 }
10766
10767 /* "show [ip] bgp neighbors" commands. */
10768 DEFUN (show_ip_bgp_neighbors,
10769 show_ip_bgp_neighbors_cmd,
10770 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10771 SHOW_STR
10772 IP_STR
10773 BGP_STR
10774 BGP_INSTANCE_HELP_STR
10775 "Address Family\n"
10776 "Address Family\n"
10777 "Detailed information on TCP and BGP neighbor connections\n"
10778 "Neighbor to display information about\n"
10779 "Neighbor to display information about\n"
10780 "Neighbor on BGP configured interface\n"
10781 JSON_STR)
10782 {
10783 char *vrf = NULL;
10784 char *sh_arg = NULL;
10785 enum show_type sh_type;
10786
10787 uint8_t uj = use_json(argc, argv);
10788
10789 int idx = 0;
10790
10791 if (argv_find(argv, argc, "view", &idx)
10792 || argv_find(argv, argc, "vrf", &idx))
10793 vrf = argv[idx + 1]->arg;
10794
10795 idx++;
10796 if (argv_find(argv, argc, "A.B.C.D", &idx)
10797 || argv_find(argv, argc, "X:X::X:X", &idx)
10798 || argv_find(argv, argc, "WORD", &idx)) {
10799 sh_type = show_peer;
10800 sh_arg = argv[idx]->arg;
10801 } else
10802 sh_type = show_all;
10803
10804 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10805 }
10806
10807 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10808 paths' and `show ip mbgp paths'. Those functions results are the
10809 same.*/
10810 DEFUN (show_ip_bgp_paths,
10811 show_ip_bgp_paths_cmd,
10812 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10813 SHOW_STR
10814 IP_STR
10815 BGP_STR
10816 BGP_SAFI_HELP_STR
10817 "Path information\n")
10818 {
10819 vty_out(vty, "Address Refcnt Path\n");
10820 aspath_print_all_vty(vty);
10821 return CMD_SUCCESS;
10822 }
10823
10824 #include "hash.h"
10825
10826 static void community_show_all_iterator(struct hash_backet *backet,
10827 struct vty *vty)
10828 {
10829 struct community *com;
10830
10831 com = (struct community *)backet->data;
10832 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10833 community_str(com, false));
10834 }
10835
10836 /* Show BGP's community internal data. */
10837 DEFUN (show_ip_bgp_community_info,
10838 show_ip_bgp_community_info_cmd,
10839 "show [ip] bgp community-info",
10840 SHOW_STR
10841 IP_STR
10842 BGP_STR
10843 "List all bgp community information\n")
10844 {
10845 vty_out(vty, "Address Refcnt Community\n");
10846
10847 hash_iterate(community_hash(),
10848 (void (*)(struct hash_backet *,
10849 void *))community_show_all_iterator,
10850 vty);
10851
10852 return CMD_SUCCESS;
10853 }
10854
10855 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10856 struct vty *vty)
10857 {
10858 struct lcommunity *lcom;
10859
10860 lcom = (struct lcommunity *)backet->data;
10861 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10862 lcommunity_str(lcom));
10863 }
10864
10865 /* Show BGP's community internal data. */
10866 DEFUN (show_ip_bgp_lcommunity_info,
10867 show_ip_bgp_lcommunity_info_cmd,
10868 "show ip bgp large-community-info",
10869 SHOW_STR
10870 IP_STR
10871 BGP_STR
10872 "List all bgp large-community information\n")
10873 {
10874 vty_out(vty, "Address Refcnt Large-community\n");
10875
10876 hash_iterate(lcommunity_hash(),
10877 (void (*)(struct hash_backet *,
10878 void *))lcommunity_show_all_iterator,
10879 vty);
10880
10881 return CMD_SUCCESS;
10882 }
10883
10884
10885 DEFUN (show_ip_bgp_attr_info,
10886 show_ip_bgp_attr_info_cmd,
10887 "show [ip] bgp attribute-info",
10888 SHOW_STR
10889 IP_STR
10890 BGP_STR
10891 "List all bgp attribute information\n")
10892 {
10893 attr_show_all(vty);
10894 return CMD_SUCCESS;
10895 }
10896
10897 static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
10898 afi_t afi, safi_t safi)
10899 {
10900 struct bgp *bgp;
10901 struct listnode *node;
10902 char *vname;
10903 char buf1[INET6_ADDRSTRLEN];
10904 char *ecom_str;
10905 vpn_policy_direction_t dir;
10906
10907 if (name) {
10908 bgp = bgp_lookup_by_name(name);
10909 if (!bgp) {
10910 vty_out(vty, "%% No such BGP instance exist\n");
10911 return CMD_WARNING;
10912 }
10913 } else {
10914 bgp = bgp_get_default();
10915 if (!bgp) {
10916 vty_out(vty,
10917 "%% Default BGP instance does not exist\n");
10918 return CMD_WARNING;
10919 }
10920 }
10921
10922 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10923 BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
10924 vty_out(vty,
10925 "This VRF is not importing %s routes from any other VRF\n",
10926 afi_safi_print(afi, safi));
10927 } else {
10928 vty_out(vty,
10929 "This VRF is importing %s routes from the following VRFs:\n",
10930 afi_safi_print(afi, safi));
10931 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].import_vrf, node,
10932 vname)) {
10933 vty_out(vty, " %s\n", vname);
10934 }
10935 dir = BGP_VPN_POLICY_DIR_FROMVPN;
10936 ecom_str = ecommunity_ecom2str(
10937 bgp->vpn_policy[afi].rtlist[dir],
10938 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
10939 vty_out(vty, "Import RT(s): %s\n", ecom_str);
10940 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
10941 }
10942
10943 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
10944 BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
10945 vty_out(vty,
10946 "This VRF is not exporting %s routes to any other VRF\n",
10947 afi_safi_print(afi, safi));
10948 } else {
10949 vty_out(vty,
10950 "This VRF is exporting %s routes to the following VRFs:\n",
10951 afi_safi_print(afi, safi));
10952 for (ALL_LIST_ELEMENTS_RO(bgp->vpn_policy[afi].export_vrf, node,
10953 vname)) {
10954 vty_out(vty, " %s\n", vname);
10955 }
10956 vty_out(vty, "RD: %s\n",
10957 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd,
10958 buf1, RD_ADDRSTRLEN));
10959 dir = BGP_VPN_POLICY_DIR_TOVPN;
10960 ecom_str = ecommunity_ecom2str(
10961 bgp->vpn_policy[afi].rtlist[dir],
10962 ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
10963 vty_out(vty, "Emport RT: %s\n", ecom_str);
10964 XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
10965 }
10966
10967 return CMD_SUCCESS;
10968 }
10969
10970 /* "show [ip] bgp route-leak" command. */
10971 DEFUN (show_ip_bgp_route_leak,
10972 show_ip_bgp_route_leak_cmd,
10973 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] route-leak",
10974 SHOW_STR
10975 IP_STR
10976 BGP_STR
10977 BGP_INSTANCE_HELP_STR
10978 BGP_AFI_HELP_STR
10979 BGP_SAFI_HELP_STR
10980 "Route leaking information\n")
10981 {
10982 char *vrf = NULL;
10983 afi_t afi = AFI_MAX;
10984 safi_t safi = SAFI_MAX;
10985
10986 int idx = 0;
10987
10988 /* show [ip] bgp */
10989 if (argv_find(argv, argc, "ip", &idx)) {
10990 afi = AFI_IP;
10991 safi = SAFI_UNICAST;
10992 }
10993 /* [vrf VIEWVRFNAME] */
10994 if (argv_find(argv, argc, "view", &idx)) {
10995 vty_out(vty,
10996 "%% This command is not applicable to BGP views\n");
10997 return CMD_WARNING;
10998 }
10999
11000 if (argv_find(argv, argc, "vrf", &idx))
11001 vrf = argv[++idx]->arg;
11002 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11003 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11004 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11005 }
11006
11007 if (!((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_UNICAST)) {
11008 vty_out(vty,
11009 "%% This command is applicable only for unicast ipv4|ipv6\n");
11010 return CMD_WARNING;
11011 }
11012
11013 return bgp_show_route_leak_vty(vty, vrf, afi, safi);
11014 }
11015
11016 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
11017 safi_t safi)
11018 {
11019 struct listnode *node, *nnode;
11020 struct bgp *bgp;
11021
11022 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
11023 vty_out(vty, "\nInstance %s:\n",
11024 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
11025 ? "Default"
11026 : bgp->name);
11027 update_group_show(bgp, afi, safi, vty, 0);
11028 }
11029 }
11030
11031 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
11032 int safi, uint64_t subgrp_id)
11033 {
11034 struct bgp *bgp;
11035
11036 if (name) {
11037 if (strmatch(name, "all")) {
11038 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
11039 return CMD_SUCCESS;
11040 } else {
11041 bgp = bgp_lookup_by_name(name);
11042 }
11043 } else {
11044 bgp = bgp_get_default();
11045 }
11046
11047 if (bgp)
11048 update_group_show(bgp, afi, safi, vty, subgrp_id);
11049 return CMD_SUCCESS;
11050 }
11051
11052 DEFUN (show_ip_bgp_updgrps,
11053 show_ip_bgp_updgrps_cmd,
11054 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
11055 SHOW_STR
11056 IP_STR
11057 BGP_STR
11058 BGP_INSTANCE_HELP_STR
11059 BGP_AFI_HELP_STR
11060 BGP_SAFI_WITH_LABEL_HELP_STR
11061 "Detailed info about dynamic update groups\n"
11062 "Specific subgroup to display detailed info for\n")
11063 {
11064 char *vrf = NULL;
11065 afi_t afi = AFI_IP6;
11066 safi_t safi = SAFI_UNICAST;
11067 uint64_t subgrp_id = 0;
11068
11069 int idx = 0;
11070
11071 /* show [ip] bgp */
11072 if (argv_find(argv, argc, "ip", &idx))
11073 afi = AFI_IP;
11074 /* [<view|vrf> VIEWVRFNAME] */
11075 if (argv_find(argv, argc, "view", &idx)
11076 || argv_find(argv, argc, "vrf", &idx))
11077 vrf = argv[++idx]->arg;
11078 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
11079 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
11080 argv_find_and_parse_safi(argv, argc, &idx, &safi);
11081 }
11082
11083 /* get subgroup id, if provided */
11084 idx = argc - 1;
11085 if (argv[idx]->type == VARIABLE_TKN)
11086 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
11087
11088 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
11089 }
11090
11091 DEFUN (show_bgp_instance_all_ipv6_updgrps,
11092 show_bgp_instance_all_ipv6_updgrps_cmd,
11093 "show [ip] bgp <view|vrf> all update-groups",
11094 SHOW_STR
11095 IP_STR
11096 BGP_STR
11097 BGP_INSTANCE_ALL_HELP_STR
11098 "Detailed info about dynamic update groups\n")
11099 {
11100 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
11101 return CMD_SUCCESS;
11102 }
11103
11104 DEFUN (show_bgp_updgrps_stats,
11105 show_bgp_updgrps_stats_cmd,
11106 "show [ip] bgp update-groups statistics",
11107 SHOW_STR
11108 IP_STR
11109 BGP_STR
11110 "Detailed info about dynamic update groups\n"
11111 "Statistics\n")
11112 {
11113 struct bgp *bgp;
11114
11115 bgp = bgp_get_default();
11116 if (bgp)
11117 update_group_show_stats(bgp, vty);
11118
11119 return CMD_SUCCESS;
11120 }
11121
11122 DEFUN (show_bgp_instance_updgrps_stats,
11123 show_bgp_instance_updgrps_stats_cmd,
11124 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
11125 SHOW_STR
11126 IP_STR
11127 BGP_STR
11128 BGP_INSTANCE_HELP_STR
11129 "Detailed info about dynamic update groups\n"
11130 "Statistics\n")
11131 {
11132 int idx_word = 3;
11133 struct bgp *bgp;
11134
11135 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
11136 if (bgp)
11137 update_group_show_stats(bgp, vty);
11138
11139 return CMD_SUCCESS;
11140 }
11141
11142 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
11143 afi_t afi, safi_t safi,
11144 const char *what, uint64_t subgrp_id)
11145 {
11146 struct bgp *bgp;
11147
11148 if (name)
11149 bgp = bgp_lookup_by_name(name);
11150 else
11151 bgp = bgp_get_default();
11152
11153 if (bgp) {
11154 if (!strcmp(what, "advertise-queue"))
11155 update_group_show_adj_queue(bgp, afi, safi, vty,
11156 subgrp_id);
11157 else if (!strcmp(what, "advertised-routes"))
11158 update_group_show_advertised(bgp, afi, safi, vty,
11159 subgrp_id);
11160 else if (!strcmp(what, "packet-queue"))
11161 update_group_show_packet_queue(bgp, afi, safi, vty,
11162 subgrp_id);
11163 }
11164 }
11165
11166 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
11167 show_ip_bgp_instance_updgrps_adj_s_cmd,
11168 "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",
11169 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
11170 BGP_SAFI_HELP_STR
11171 "Detailed info about dynamic update groups\n"
11172 "Specific subgroup to display info for\n"
11173 "Advertisement queue\n"
11174 "Announced routes\n"
11175 "Packet queue\n")
11176 {
11177 uint64_t subgrp_id = 0;
11178 afi_t afiz;
11179 safi_t safiz;
11180 if (sgid)
11181 subgrp_id = strtoull(sgid, NULL, 10);
11182
11183 if (!ip && !afi)
11184 afiz = AFI_IP6;
11185 if (!ip && afi)
11186 afiz = bgp_vty_afi_from_str(afi);
11187 if (ip && !afi)
11188 afiz = AFI_IP;
11189 if (ip && afi) {
11190 afiz = bgp_vty_afi_from_str(afi);
11191 if (afiz != AFI_IP)
11192 vty_out(vty,
11193 "%% Cannot specify both 'ip' and 'ipv6'\n");
11194 return CMD_WARNING;
11195 }
11196
11197 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
11198
11199 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
11200 return CMD_SUCCESS;
11201 }
11202
11203 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
11204 {
11205 struct listnode *node, *nnode;
11206 struct prefix *range;
11207 struct peer *conf;
11208 struct peer *peer;
11209 char buf[PREFIX2STR_BUFFER];
11210 afi_t afi;
11211 safi_t safi;
11212 const char *peer_status;
11213 const char *af_str;
11214 int lr_count;
11215 int dynamic;
11216 int af_cfgd;
11217
11218 conf = group->conf;
11219
11220 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
11221 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11222 conf->as);
11223 } else if (conf->as_type == AS_INTERNAL) {
11224 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
11225 group->bgp->as);
11226 } else {
11227 vty_out(vty, "\nBGP peer-group %s\n", group->name);
11228 }
11229
11230 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
11231 vty_out(vty, " Peer-group type is internal\n");
11232 else
11233 vty_out(vty, " Peer-group type is external\n");
11234
11235 /* Display AFs configured. */
11236 vty_out(vty, " Configured address-families:");
11237 FOREACH_AFI_SAFI (afi, safi) {
11238 if (conf->afc[afi][safi]) {
11239 af_cfgd = 1;
11240 vty_out(vty, " %s;", afi_safi_print(afi, safi));
11241 }
11242 }
11243 if (!af_cfgd)
11244 vty_out(vty, " none\n");
11245 else
11246 vty_out(vty, "\n");
11247
11248 /* Display listen ranges (for dynamic neighbors), if any */
11249 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
11250 if (afi == AFI_IP)
11251 af_str = "IPv4";
11252 else if (afi == AFI_IP6)
11253 af_str = "IPv6";
11254 else
11255 af_str = "???";
11256 lr_count = listcount(group->listen_range[afi]);
11257 if (lr_count) {
11258 vty_out(vty, " %d %s listen range(s)\n", lr_count,
11259 af_str);
11260
11261
11262 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
11263 nnode, range)) {
11264 prefix2str(range, buf, sizeof(buf));
11265 vty_out(vty, " %s\n", buf);
11266 }
11267 }
11268 }
11269
11270 /* Display group members and their status */
11271 if (listcount(group->peer)) {
11272 vty_out(vty, " Peer-group members:\n");
11273 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
11274 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
11275 peer_status = "Idle (Admin)";
11276 else if (CHECK_FLAG(peer->sflags,
11277 PEER_STATUS_PREFIX_OVERFLOW))
11278 peer_status = "Idle (PfxCt)";
11279 else
11280 peer_status = lookup_msg(bgp_status_msg,
11281 peer->status, NULL);
11282
11283 dynamic = peer_dynamic_neighbor(peer);
11284 vty_out(vty, " %s %s %s \n", peer->host,
11285 dynamic ? "(dynamic)" : "", peer_status);
11286 }
11287 }
11288
11289 return CMD_SUCCESS;
11290 }
11291
11292 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
11293 const char *group_name)
11294 {
11295 struct bgp *bgp;
11296 struct listnode *node, *nnode;
11297 struct peer_group *group;
11298 bool found = false;
11299
11300 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
11301
11302 if (!bgp) {
11303 vty_out(vty, "%% No such BGP instance exists\n");
11304 return CMD_WARNING;
11305 }
11306
11307 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
11308 if (group_name) {
11309 if (strmatch(group->name, group_name)) {
11310 bgp_show_one_peer_group(vty, group);
11311 found = true;
11312 break;
11313 }
11314 } else {
11315 bgp_show_one_peer_group(vty, group);
11316 }
11317 }
11318
11319 if (group_name && !found)
11320 vty_out(vty, "%% No such peer-group\n");
11321
11322 return CMD_SUCCESS;
11323 }
11324
11325 DEFUN (show_ip_bgp_peer_groups,
11326 show_ip_bgp_peer_groups_cmd,
11327 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
11328 SHOW_STR
11329 IP_STR
11330 BGP_STR
11331 BGP_INSTANCE_HELP_STR
11332 "Detailed information on BGP peer groups\n"
11333 "Peer group name\n")
11334 {
11335 char *vrf, *pg;
11336 vrf = pg = NULL;
11337 int idx = 0;
11338
11339 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
11340 : NULL;
11341 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
11342
11343 return bgp_show_peer_group_vty(vty, vrf, pg);
11344 }
11345
11346
11347 /* Redistribute VTY commands. */
11348
11349 DEFUN (bgp_redistribute_ipv4,
11350 bgp_redistribute_ipv4_cmd,
11351 "redistribute " FRR_IP_REDIST_STR_BGPD,
11352 "Redistribute information from another routing protocol\n"
11353 FRR_IP_REDIST_HELP_STR_BGPD)
11354 {
11355 VTY_DECLVAR_CONTEXT(bgp, bgp);
11356 int idx_protocol = 1;
11357 int type;
11358
11359 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11360 if (type < 0) {
11361 vty_out(vty, "%% Invalid route type\n");
11362 return CMD_WARNING_CONFIG_FAILED;
11363 }
11364
11365 bgp_redist_add(bgp, AFI_IP, type, 0);
11366 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11367 }
11368
11369 ALIAS_HIDDEN(
11370 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11371 "redistribute " FRR_IP_REDIST_STR_BGPD,
11372 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
11373
11374 DEFUN (bgp_redistribute_ipv4_rmap,
11375 bgp_redistribute_ipv4_rmap_cmd,
11376 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11377 "Redistribute information from another routing protocol\n"
11378 FRR_IP_REDIST_HELP_STR_BGPD
11379 "Route map reference\n"
11380 "Pointer to route-map entries\n")
11381 {
11382 VTY_DECLVAR_CONTEXT(bgp, bgp);
11383 int idx_protocol = 1;
11384 int idx_word = 3;
11385 int type;
11386 struct bgp_redist *red;
11387
11388 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11389 if (type < 0) {
11390 vty_out(vty, "%% Invalid route type\n");
11391 return CMD_WARNING_CONFIG_FAILED;
11392 }
11393
11394 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11395 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11396 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11397 }
11398
11399 ALIAS_HIDDEN(
11400 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11401 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11402 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11403 "Route map reference\n"
11404 "Pointer to route-map entries\n")
11405
11406 DEFUN (bgp_redistribute_ipv4_metric,
11407 bgp_redistribute_ipv4_metric_cmd,
11408 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11409 "Redistribute information from another routing protocol\n"
11410 FRR_IP_REDIST_HELP_STR_BGPD
11411 "Metric for redistributed routes\n"
11412 "Default metric\n")
11413 {
11414 VTY_DECLVAR_CONTEXT(bgp, bgp);
11415 int idx_protocol = 1;
11416 int idx_number = 3;
11417 int type;
11418 uint32_t metric;
11419 struct bgp_redist *red;
11420
11421 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11422 if (type < 0) {
11423 vty_out(vty, "%% Invalid route type\n");
11424 return CMD_WARNING_CONFIG_FAILED;
11425 }
11426 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11427
11428 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11429 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11430 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11431 }
11432
11433 ALIAS_HIDDEN(
11434 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11435 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11436 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11437 "Metric for redistributed routes\n"
11438 "Default metric\n")
11439
11440 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11441 bgp_redistribute_ipv4_rmap_metric_cmd,
11442 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
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 "Metric for redistributed routes\n"
11448 "Default metric\n")
11449 {
11450 VTY_DECLVAR_CONTEXT(bgp, bgp);
11451 int idx_protocol = 1;
11452 int idx_word = 3;
11453 int idx_number = 5;
11454 int type;
11455 uint32_t metric;
11456 struct bgp_redist *red;
11457
11458 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11459 if (type < 0) {
11460 vty_out(vty, "%% Invalid route type\n");
11461 return CMD_WARNING_CONFIG_FAILED;
11462 }
11463 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11464
11465 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11466 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11467 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11468 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11469 }
11470
11471 ALIAS_HIDDEN(
11472 bgp_redistribute_ipv4_rmap_metric,
11473 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11474 "redistribute " FRR_IP_REDIST_STR_BGPD
11475 " route-map WORD metric (0-4294967295)",
11476 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11477 "Route map reference\n"
11478 "Pointer to route-map entries\n"
11479 "Metric for redistributed routes\n"
11480 "Default metric\n")
11481
11482 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11483 bgp_redistribute_ipv4_metric_rmap_cmd,
11484 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11485 "Redistribute information from another routing protocol\n"
11486 FRR_IP_REDIST_HELP_STR_BGPD
11487 "Metric for redistributed routes\n"
11488 "Default metric\n"
11489 "Route map reference\n"
11490 "Pointer to route-map entries\n")
11491 {
11492 VTY_DECLVAR_CONTEXT(bgp, bgp);
11493 int idx_protocol = 1;
11494 int idx_number = 3;
11495 int idx_word = 5;
11496 int type;
11497 uint32_t metric;
11498 struct bgp_redist *red;
11499
11500 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11501 if (type < 0) {
11502 vty_out(vty, "%% Invalid route type\n");
11503 return CMD_WARNING_CONFIG_FAILED;
11504 }
11505 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11506
11507 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11508 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11509 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11510 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11511 }
11512
11513 ALIAS_HIDDEN(
11514 bgp_redistribute_ipv4_metric_rmap,
11515 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11516 "redistribute " FRR_IP_REDIST_STR_BGPD
11517 " metric (0-4294967295) route-map WORD",
11518 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11519 "Metric for redistributed routes\n"
11520 "Default metric\n"
11521 "Route map reference\n"
11522 "Pointer to route-map entries\n")
11523
11524 DEFUN (bgp_redistribute_ipv4_ospf,
11525 bgp_redistribute_ipv4_ospf_cmd,
11526 "redistribute <ospf|table> (1-65535)",
11527 "Redistribute information from another routing protocol\n"
11528 "Open Shortest Path First (OSPFv2)\n"
11529 "Non-main Kernel Routing Table\n"
11530 "Instance ID/Table ID\n")
11531 {
11532 VTY_DECLVAR_CONTEXT(bgp, bgp);
11533 int idx_ospf_table = 1;
11534 int idx_number = 2;
11535 unsigned short instance;
11536 unsigned short protocol;
11537
11538 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11539
11540 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11541 protocol = ZEBRA_ROUTE_OSPF;
11542 else
11543 protocol = ZEBRA_ROUTE_TABLE;
11544
11545 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11546 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11547 }
11548
11549 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11550 "redistribute <ospf|table> (1-65535)",
11551 "Redistribute information from another routing protocol\n"
11552 "Open Shortest Path First (OSPFv2)\n"
11553 "Non-main Kernel Routing Table\n"
11554 "Instance ID/Table ID\n")
11555
11556 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11557 bgp_redistribute_ipv4_ospf_rmap_cmd,
11558 "redistribute <ospf|table> (1-65535) route-map WORD",
11559 "Redistribute information from another routing protocol\n"
11560 "Open Shortest Path First (OSPFv2)\n"
11561 "Non-main Kernel Routing Table\n"
11562 "Instance ID/Table ID\n"
11563 "Route map reference\n"
11564 "Pointer to route-map entries\n")
11565 {
11566 VTY_DECLVAR_CONTEXT(bgp, bgp);
11567 int idx_ospf_table = 1;
11568 int idx_number = 2;
11569 int idx_word = 4;
11570 struct bgp_redist *red;
11571 unsigned short instance;
11572 int protocol;
11573
11574 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11575 protocol = ZEBRA_ROUTE_OSPF;
11576 else
11577 protocol = ZEBRA_ROUTE_TABLE;
11578
11579 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11580 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11581 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11582 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11583 }
11584
11585 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11586 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11587 "redistribute <ospf|table> (1-65535) route-map WORD",
11588 "Redistribute information from another routing protocol\n"
11589 "Open Shortest Path First (OSPFv2)\n"
11590 "Non-main Kernel Routing Table\n"
11591 "Instance ID/Table ID\n"
11592 "Route map reference\n"
11593 "Pointer to route-map entries\n")
11594
11595 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11596 bgp_redistribute_ipv4_ospf_metric_cmd,
11597 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11598 "Redistribute information from another routing protocol\n"
11599 "Open Shortest Path First (OSPFv2)\n"
11600 "Non-main Kernel Routing Table\n"
11601 "Instance ID/Table ID\n"
11602 "Metric for redistributed routes\n"
11603 "Default metric\n")
11604 {
11605 VTY_DECLVAR_CONTEXT(bgp, bgp);
11606 int idx_ospf_table = 1;
11607 int idx_number = 2;
11608 int idx_number_2 = 4;
11609 uint32_t metric;
11610 struct bgp_redist *red;
11611 unsigned short instance;
11612 int protocol;
11613
11614 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11615 protocol = ZEBRA_ROUTE_OSPF;
11616 else
11617 protocol = ZEBRA_ROUTE_TABLE;
11618
11619 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11620 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11621
11622 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11623 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11624 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11625 }
11626
11627 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11628 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11629 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11630 "Redistribute information from another routing protocol\n"
11631 "Open Shortest Path First (OSPFv2)\n"
11632 "Non-main Kernel Routing Table\n"
11633 "Instance ID/Table ID\n"
11634 "Metric for redistributed routes\n"
11635 "Default metric\n")
11636
11637 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11638 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11639 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11640 "Redistribute information from another routing protocol\n"
11641 "Open Shortest Path First (OSPFv2)\n"
11642 "Non-main Kernel Routing Table\n"
11643 "Instance ID/Table ID\n"
11644 "Route map reference\n"
11645 "Pointer to route-map entries\n"
11646 "Metric for redistributed routes\n"
11647 "Default metric\n")
11648 {
11649 VTY_DECLVAR_CONTEXT(bgp, bgp);
11650 int idx_ospf_table = 1;
11651 int idx_number = 2;
11652 int idx_word = 4;
11653 int idx_number_2 = 6;
11654 uint32_t metric;
11655 struct bgp_redist *red;
11656 unsigned short instance;
11657 int protocol;
11658
11659 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11660 protocol = ZEBRA_ROUTE_OSPF;
11661 else
11662 protocol = ZEBRA_ROUTE_TABLE;
11663
11664 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11665 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11666
11667 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11668 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11669 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11670 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11671 }
11672
11673 ALIAS_HIDDEN(
11674 bgp_redistribute_ipv4_ospf_rmap_metric,
11675 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11676 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11677 "Redistribute information from another routing protocol\n"
11678 "Open Shortest Path First (OSPFv2)\n"
11679 "Non-main Kernel Routing Table\n"
11680 "Instance ID/Table ID\n"
11681 "Route map reference\n"
11682 "Pointer to route-map entries\n"
11683 "Metric for redistributed routes\n"
11684 "Default metric\n")
11685
11686 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11687 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11688 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11689 "Redistribute information from another routing protocol\n"
11690 "Open Shortest Path First (OSPFv2)\n"
11691 "Non-main Kernel Routing Table\n"
11692 "Instance ID/Table ID\n"
11693 "Metric for redistributed routes\n"
11694 "Default metric\n"
11695 "Route map reference\n"
11696 "Pointer to route-map entries\n")
11697 {
11698 VTY_DECLVAR_CONTEXT(bgp, bgp);
11699 int idx_ospf_table = 1;
11700 int idx_number = 2;
11701 int idx_number_2 = 4;
11702 int idx_word = 6;
11703 uint32_t metric;
11704 struct bgp_redist *red;
11705 unsigned short instance;
11706 int protocol;
11707
11708 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11709 protocol = ZEBRA_ROUTE_OSPF;
11710 else
11711 protocol = ZEBRA_ROUTE_TABLE;
11712
11713 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11714 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11715
11716 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11717 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11718 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11719 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11720 }
11721
11722 ALIAS_HIDDEN(
11723 bgp_redistribute_ipv4_ospf_metric_rmap,
11724 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11725 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11726 "Redistribute information from another routing protocol\n"
11727 "Open Shortest Path First (OSPFv2)\n"
11728 "Non-main Kernel Routing Table\n"
11729 "Instance ID/Table ID\n"
11730 "Metric for redistributed routes\n"
11731 "Default metric\n"
11732 "Route map reference\n"
11733 "Pointer to route-map entries\n")
11734
11735 DEFUN (no_bgp_redistribute_ipv4_ospf,
11736 no_bgp_redistribute_ipv4_ospf_cmd,
11737 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11738 NO_STR
11739 "Redistribute information from another routing protocol\n"
11740 "Open Shortest Path First (OSPFv2)\n"
11741 "Non-main Kernel Routing Table\n"
11742 "Instance ID/Table ID\n"
11743 "Metric for redistributed routes\n"
11744 "Default metric\n"
11745 "Route map reference\n"
11746 "Pointer to route-map entries\n")
11747 {
11748 VTY_DECLVAR_CONTEXT(bgp, bgp);
11749 int idx_ospf_table = 2;
11750 int idx_number = 3;
11751 unsigned short instance;
11752 int protocol;
11753
11754 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11755 protocol = ZEBRA_ROUTE_OSPF;
11756 else
11757 protocol = ZEBRA_ROUTE_TABLE;
11758
11759 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11760 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11761 }
11762
11763 ALIAS_HIDDEN(
11764 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11765 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11766 NO_STR
11767 "Redistribute information from another routing protocol\n"
11768 "Open Shortest Path First (OSPFv2)\n"
11769 "Non-main Kernel Routing Table\n"
11770 "Instance ID/Table ID\n"
11771 "Metric for redistributed routes\n"
11772 "Default metric\n"
11773 "Route map reference\n"
11774 "Pointer to route-map entries\n")
11775
11776 DEFUN (no_bgp_redistribute_ipv4,
11777 no_bgp_redistribute_ipv4_cmd,
11778 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11779 NO_STR
11780 "Redistribute information from another routing protocol\n"
11781 FRR_IP_REDIST_HELP_STR_BGPD
11782 "Metric for redistributed routes\n"
11783 "Default metric\n"
11784 "Route map reference\n"
11785 "Pointer to route-map entries\n")
11786 {
11787 VTY_DECLVAR_CONTEXT(bgp, bgp);
11788 int idx_protocol = 2;
11789 int type;
11790
11791 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11792 if (type < 0) {
11793 vty_out(vty, "%% Invalid route type\n");
11794 return CMD_WARNING_CONFIG_FAILED;
11795 }
11796 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11797 }
11798
11799 ALIAS_HIDDEN(
11800 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11801 "no redistribute " FRR_IP_REDIST_STR_BGPD
11802 " [metric (0-4294967295)] [route-map WORD]",
11803 NO_STR
11804 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11805 "Metric for redistributed routes\n"
11806 "Default metric\n"
11807 "Route map reference\n"
11808 "Pointer to route-map entries\n")
11809
11810 DEFUN (bgp_redistribute_ipv6,
11811 bgp_redistribute_ipv6_cmd,
11812 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11813 "Redistribute information from another routing protocol\n"
11814 FRR_IP6_REDIST_HELP_STR_BGPD)
11815 {
11816 VTY_DECLVAR_CONTEXT(bgp, bgp);
11817 int idx_protocol = 1;
11818 int type;
11819
11820 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11821 if (type < 0) {
11822 vty_out(vty, "%% Invalid route type\n");
11823 return CMD_WARNING_CONFIG_FAILED;
11824 }
11825
11826 bgp_redist_add(bgp, AFI_IP6, type, 0);
11827 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11828 }
11829
11830 DEFUN (bgp_redistribute_ipv6_rmap,
11831 bgp_redistribute_ipv6_rmap_cmd,
11832 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11833 "Redistribute information from another routing protocol\n"
11834 FRR_IP6_REDIST_HELP_STR_BGPD
11835 "Route map reference\n"
11836 "Pointer to route-map entries\n")
11837 {
11838 VTY_DECLVAR_CONTEXT(bgp, bgp);
11839 int idx_protocol = 1;
11840 int idx_word = 3;
11841 int type;
11842 struct bgp_redist *red;
11843
11844 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11845 if (type < 0) {
11846 vty_out(vty, "%% Invalid route type\n");
11847 return CMD_WARNING_CONFIG_FAILED;
11848 }
11849
11850 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11851 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11852 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11853 }
11854
11855 DEFUN (bgp_redistribute_ipv6_metric,
11856 bgp_redistribute_ipv6_metric_cmd,
11857 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11858 "Redistribute information from another routing protocol\n"
11859 FRR_IP6_REDIST_HELP_STR_BGPD
11860 "Metric for redistributed routes\n"
11861 "Default metric\n")
11862 {
11863 VTY_DECLVAR_CONTEXT(bgp, bgp);
11864 int idx_protocol = 1;
11865 int idx_number = 3;
11866 int type;
11867 uint32_t metric;
11868 struct bgp_redist *red;
11869
11870 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11871 if (type < 0) {
11872 vty_out(vty, "%% Invalid route type\n");
11873 return CMD_WARNING_CONFIG_FAILED;
11874 }
11875 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11876
11877 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11878 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11879 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11880 }
11881
11882 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11883 bgp_redistribute_ipv6_rmap_metric_cmd,
11884 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11885 "Redistribute information from another routing protocol\n"
11886 FRR_IP6_REDIST_HELP_STR_BGPD
11887 "Route map reference\n"
11888 "Pointer to route-map entries\n"
11889 "Metric for redistributed routes\n"
11890 "Default metric\n")
11891 {
11892 VTY_DECLVAR_CONTEXT(bgp, bgp);
11893 int idx_protocol = 1;
11894 int idx_word = 3;
11895 int idx_number = 5;
11896 int type;
11897 uint32_t metric;
11898 struct bgp_redist *red;
11899
11900 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11901 if (type < 0) {
11902 vty_out(vty, "%% Invalid route type\n");
11903 return CMD_WARNING_CONFIG_FAILED;
11904 }
11905 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11906
11907 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11908 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11909 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11910 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11911 }
11912
11913 DEFUN (bgp_redistribute_ipv6_metric_rmap,
11914 bgp_redistribute_ipv6_metric_rmap_cmd,
11915 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11916 "Redistribute information from another routing protocol\n"
11917 FRR_IP6_REDIST_HELP_STR_BGPD
11918 "Metric for redistributed routes\n"
11919 "Default metric\n"
11920 "Route map reference\n"
11921 "Pointer to route-map entries\n")
11922 {
11923 VTY_DECLVAR_CONTEXT(bgp, bgp);
11924 int idx_protocol = 1;
11925 int idx_number = 3;
11926 int idx_word = 5;
11927 int type;
11928 uint32_t metric;
11929 struct bgp_redist *red;
11930
11931 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11932 if (type < 0) {
11933 vty_out(vty, "%% Invalid route type\n");
11934 return CMD_WARNING_CONFIG_FAILED;
11935 }
11936 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11937
11938 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11939 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11940 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11941 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11942 }
11943
11944 DEFUN (no_bgp_redistribute_ipv6,
11945 no_bgp_redistribute_ipv6_cmd,
11946 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11947 NO_STR
11948 "Redistribute information from another routing protocol\n"
11949 FRR_IP6_REDIST_HELP_STR_BGPD
11950 "Metric for redistributed routes\n"
11951 "Default metric\n"
11952 "Route map reference\n"
11953 "Pointer to route-map entries\n")
11954 {
11955 VTY_DECLVAR_CONTEXT(bgp, bgp);
11956 int idx_protocol = 2;
11957 int type;
11958
11959 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11960 if (type < 0) {
11961 vty_out(vty, "%% Invalid route type\n");
11962 return CMD_WARNING_CONFIG_FAILED;
11963 }
11964
11965 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11966 }
11967
11968 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
11969 safi_t safi)
11970 {
11971 int i;
11972
11973 /* Unicast redistribution only. */
11974 if (safi != SAFI_UNICAST)
11975 return;
11976
11977 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11978 /* Redistribute BGP does not make sense. */
11979 if (i != ZEBRA_ROUTE_BGP) {
11980 struct list *red_list;
11981 struct listnode *node;
11982 struct bgp_redist *red;
11983
11984 red_list = bgp->redist[afi][i];
11985 if (!red_list)
11986 continue;
11987
11988 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
11989 /* "redistribute" configuration. */
11990 vty_out(vty, " redistribute %s",
11991 zebra_route_string(i));
11992 if (red->instance)
11993 vty_out(vty, " %d", red->instance);
11994 if (red->redist_metric_flag)
11995 vty_out(vty, " metric %u",
11996 red->redist_metric);
11997 if (red->rmap.name)
11998 vty_out(vty, " route-map %s",
11999 red->rmap.name);
12000 vty_out(vty, "\n");
12001 }
12002 }
12003 }
12004 }
12005
12006 /* This is part of the address-family block (unicast only) */
12007 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
12008 afi_t afi)
12009 {
12010 int indent = 2;
12011
12012 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN])
12013 vty_out(vty, "%*simport vrf route-map %s\n", indent, "",
12014 bgp->vpn_policy[afi]
12015 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
12016
12017 if (CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12018 BGP_CONFIG_VRF_TO_VRF_IMPORT)
12019 || CHECK_FLAG(bgp->af_flags[afi][SAFI_UNICAST],
12020 BGP_CONFIG_VRF_TO_VRF_EXPORT))
12021 return;
12022
12023 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12024 BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) {
12025
12026 vty_out(vty, "%*slabel vpn export %s\n", indent, "", "auto");
12027
12028 } else {
12029 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
12030 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
12031 bgp->vpn_policy[afi].tovpn_label);
12032 }
12033 }
12034 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12035 BGP_VPN_POLICY_TOVPN_RD_SET)) {
12036 char buf[RD_ADDRSTRLEN];
12037 vty_out(vty, "%*srd vpn export %s\n", indent, "",
12038 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
12039 sizeof(buf)));
12040 }
12041 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
12042 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
12043
12044 char buf[PREFIX_STRLEN];
12045 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
12046 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
12047 sizeof(buf))) {
12048
12049 vty_out(vty, "%*snexthop vpn export %s\n",
12050 indent, "", buf);
12051 }
12052 }
12053 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
12054 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
12055 && ecommunity_cmp(
12056 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12057 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
12058
12059 char *b = ecommunity_ecom2str(
12060 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12061 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
12062 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
12063 XFREE(MTYPE_ECOMMUNITY_STR, b);
12064 } else {
12065 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
12066 char *b = ecommunity_ecom2str(
12067 bgp->vpn_policy[afi]
12068 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
12069 ECOMMUNITY_FORMAT_ROUTE_MAP,
12070 ECOMMUNITY_ROUTE_TARGET);
12071 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
12072 XFREE(MTYPE_ECOMMUNITY_STR, b);
12073 }
12074 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
12075 char *b = ecommunity_ecom2str(
12076 bgp->vpn_policy[afi]
12077 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
12078 ECOMMUNITY_FORMAT_ROUTE_MAP,
12079 ECOMMUNITY_ROUTE_TARGET);
12080 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
12081 XFREE(MTYPE_ECOMMUNITY_STR, b);
12082 }
12083 }
12084
12085 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN])
12086 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
12087 bgp->vpn_policy[afi]
12088 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
12089
12090 if (bgp->vpn_policy[afi].import_redirect_rtlist) {
12091 char *b = ecommunity_ecom2str(
12092 bgp->vpn_policy[afi]
12093 .import_redirect_rtlist,
12094 ECOMMUNITY_FORMAT_ROUTE_MAP,
12095 ECOMMUNITY_ROUTE_TARGET);
12096
12097 vty_out(vty, "%*srt redirect import %s\n", indent, "", b);
12098 XFREE(MTYPE_ECOMMUNITY_STR, b);
12099 }
12100 }
12101
12102
12103 /* BGP node structure. */
12104 static struct cmd_node bgp_node = {
12105 BGP_NODE, "%s(config-router)# ", 1,
12106 };
12107
12108 static struct cmd_node bgp_ipv4_unicast_node = {
12109 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
12110 };
12111
12112 static struct cmd_node bgp_ipv4_multicast_node = {
12113 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
12114 };
12115
12116 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
12117 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
12118 };
12119
12120 static struct cmd_node bgp_ipv6_unicast_node = {
12121 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
12122 };
12123
12124 static struct cmd_node bgp_ipv6_multicast_node = {
12125 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
12126 };
12127
12128 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
12129 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
12130 };
12131
12132 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
12133 "%s(config-router-af)# ", 1};
12134
12135 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
12136 "%s(config-router-af-vpnv6)# ", 1};
12137
12138 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
12139 "%s(config-router-evpn)# ", 1};
12140
12141 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
12142 "%s(config-router-af-vni)# ", 1};
12143
12144 static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE,
12145 "%s(config-router-af)# ", 1};
12146
12147 static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE,
12148 "%s(config-router-af-vpnv6)# ", 1};
12149
12150 static void community_list_vty(void);
12151
12152 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
12153 {
12154 struct bgp *bgp;
12155 struct peer *peer;
12156 struct listnode *lnbgp, *lnpeer;
12157
12158 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12159 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
12160 /* only provide suggestions on the appropriate input
12161 * token type,
12162 * they'll otherwise show up multiple times */
12163 enum cmd_token_type match_type;
12164 char *name = peer->host;
12165
12166 if (peer->conf_if) {
12167 match_type = VARIABLE_TKN;
12168 name = peer->conf_if;
12169 } else if (strchr(peer->host, ':'))
12170 match_type = IPV6_TKN;
12171 else
12172 match_type = IPV4_TKN;
12173
12174 if (token->type != match_type)
12175 continue;
12176
12177 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
12178 }
12179 }
12180 }
12181
12182 static const struct cmd_variable_handler bgp_var_neighbor[] = {
12183 {.varname = "neighbor", .completions = bgp_ac_neighbor},
12184 {.varname = "neighbors", .completions = bgp_ac_neighbor},
12185 {.varname = "peer", .completions = bgp_ac_neighbor},
12186 {.completions = NULL}};
12187
12188 static void bgp_ac_peergroup(vector comps, struct cmd_token *token)
12189 {
12190 struct bgp *bgp;
12191 struct peer_group *group;
12192 struct listnode *lnbgp, *lnpeer;
12193
12194 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
12195 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
12196 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
12197 group->name));
12198 }
12199 }
12200
12201 static const struct cmd_variable_handler bgp_var_peergroup[] = {
12202 {.tokenname = "PGNAME", .completions = bgp_ac_peergroup},
12203 {.completions = NULL} };
12204
12205 void bgp_vty_init(void)
12206 {
12207 cmd_variable_handler_register(bgp_var_neighbor);
12208 cmd_variable_handler_register(bgp_var_peergroup);
12209
12210 /* Install bgp top node. */
12211 install_node(&bgp_node, bgp_config_write);
12212 install_node(&bgp_ipv4_unicast_node, NULL);
12213 install_node(&bgp_ipv4_multicast_node, NULL);
12214 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
12215 install_node(&bgp_ipv6_unicast_node, NULL);
12216 install_node(&bgp_ipv6_multicast_node, NULL);
12217 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
12218 install_node(&bgp_vpnv4_node, NULL);
12219 install_node(&bgp_vpnv6_node, NULL);
12220 install_node(&bgp_evpn_node, NULL);
12221 install_node(&bgp_evpn_vni_node, NULL);
12222 install_node(&bgp_flowspecv4_node, NULL);
12223 install_node(&bgp_flowspecv6_node, NULL);
12224
12225 /* Install default VTY commands to new nodes. */
12226 install_default(BGP_NODE);
12227 install_default(BGP_IPV4_NODE);
12228 install_default(BGP_IPV4M_NODE);
12229 install_default(BGP_IPV4L_NODE);
12230 install_default(BGP_IPV6_NODE);
12231 install_default(BGP_IPV6M_NODE);
12232 install_default(BGP_IPV6L_NODE);
12233 install_default(BGP_VPNV4_NODE);
12234 install_default(BGP_VPNV6_NODE);
12235 install_default(BGP_FLOWSPECV4_NODE);
12236 install_default(BGP_FLOWSPECV6_NODE);
12237 install_default(BGP_EVPN_NODE);
12238 install_default(BGP_EVPN_VNI_NODE);
12239
12240 /* "bgp multiple-instance" commands. */
12241 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
12242 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
12243
12244 /* "bgp config-type" commands. */
12245 install_element(CONFIG_NODE, &bgp_config_type_cmd);
12246 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
12247
12248 /* bgp route-map delay-timer commands. */
12249 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
12250 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12251
12252 /* Dummy commands (Currently not supported) */
12253 install_element(BGP_NODE, &no_synchronization_cmd);
12254 install_element(BGP_NODE, &no_auto_summary_cmd);
12255
12256 /* "router bgp" commands. */
12257 install_element(CONFIG_NODE, &router_bgp_cmd);
12258
12259 /* "no router bgp" commands. */
12260 install_element(CONFIG_NODE, &no_router_bgp_cmd);
12261
12262 /* "bgp router-id" commands. */
12263 install_element(BGP_NODE, &bgp_router_id_cmd);
12264 install_element(BGP_NODE, &no_bgp_router_id_cmd);
12265
12266 /* "bgp cluster-id" commands. */
12267 install_element(BGP_NODE, &bgp_cluster_id_cmd);
12268 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
12269
12270 /* "bgp confederation" commands. */
12271 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
12272 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
12273
12274 /* "bgp confederation peers" commands. */
12275 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
12276 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
12277
12278 /* bgp max-med command */
12279 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
12280 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
12281 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
12282 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
12283 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
12284
12285 /* bgp disable-ebgp-connected-nh-check */
12286 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
12287 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
12288
12289 /* bgp update-delay command */
12290 install_element(BGP_NODE, &bgp_update_delay_cmd);
12291 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
12292 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
12293
12294 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12295 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
12296 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12297 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
12298
12299 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12300 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12301
12302 /* "maximum-paths" commands. */
12303 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12304 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12305 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12306 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12307 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12308 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12309 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12310 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12311 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12312 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12313 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12314 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12315 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12316 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12317 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12318
12319 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12320 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12321 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12322 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12323 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12324
12325 /* "timers bgp" commands. */
12326 install_element(BGP_NODE, &bgp_timers_cmd);
12327 install_element(BGP_NODE, &no_bgp_timers_cmd);
12328
12329 /* route-map delay-timer commands - per instance for backwards compat.
12330 */
12331 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12332 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12333
12334 /* "bgp client-to-client reflection" commands */
12335 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12336 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12337
12338 /* "bgp always-compare-med" commands */
12339 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12340 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12341
12342 /* "bgp deterministic-med" commands */
12343 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12344 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12345
12346 /* "bgp graceful-restart" commands */
12347 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12348 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12349 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12350 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12351 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12352 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12353
12354 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12355 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12356
12357 /* "bgp graceful-shutdown" commands */
12358 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12359 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12360
12361 /* "bgp fast-external-failover" commands */
12362 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12363 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12364
12365 /* "bgp enforce-first-as" commands */
12366 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12367 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12368
12369 /* "bgp bestpath compare-routerid" commands */
12370 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12371 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12372
12373 /* "bgp bestpath as-path ignore" commands */
12374 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12375 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12376
12377 /* "bgp bestpath as-path confed" commands */
12378 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12379 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12380
12381 /* "bgp bestpath as-path multipath-relax" commands */
12382 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12383 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12384
12385 /* "bgp log-neighbor-changes" commands */
12386 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12387 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12388
12389 /* "bgp bestpath med" commands */
12390 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12391 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12392
12393 /* "no bgp default ipv4-unicast" commands. */
12394 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12395 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12396
12397 /* "bgp network import-check" commands. */
12398 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12399 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12400 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12401
12402 /* "bgp default local-preference" commands. */
12403 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12404 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12405
12406 /* bgp default show-hostname */
12407 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12408 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12409
12410 /* "bgp default subgroup-pkt-queue-max" commands. */
12411 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12412 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12413
12414 /* bgp ibgp-allow-policy-mods command */
12415 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12416 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12417
12418 /* "bgp listen limit" commands. */
12419 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12420 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12421
12422 /* "bgp listen range" commands. */
12423 install_element(BGP_NODE, &bgp_listen_range_cmd);
12424 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12425
12426 /* "bgp default shutdown" command */
12427 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12428
12429 /* "neighbor remote-as" commands. */
12430 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12431 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12432 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12433 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12434 install_element(BGP_NODE,
12435 &neighbor_interface_v6only_config_remote_as_cmd);
12436 install_element(BGP_NODE, &no_neighbor_cmd);
12437 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12438
12439 /* "neighbor peer-group" commands. */
12440 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12441 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12442 install_element(BGP_NODE,
12443 &no_neighbor_interface_peer_group_remote_as_cmd);
12444
12445 /* "neighbor local-as" commands. */
12446 install_element(BGP_NODE, &neighbor_local_as_cmd);
12447 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12448 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12449 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12450
12451 /* "neighbor solo" commands. */
12452 install_element(BGP_NODE, &neighbor_solo_cmd);
12453 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12454
12455 /* "neighbor password" commands. */
12456 install_element(BGP_NODE, &neighbor_password_cmd);
12457 install_element(BGP_NODE, &no_neighbor_password_cmd);
12458
12459 /* "neighbor activate" commands. */
12460 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12461 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12462 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12463 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12464 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12465 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12466 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12467 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12468 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12469 install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd);
12470 install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd);
12471 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12472
12473 /* "no neighbor activate" commands. */
12474 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12475 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12476 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12477 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12478 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12479 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12480 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12481 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12482 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12483 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd);
12484 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd);
12485 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12486
12487 /* "neighbor peer-group" set commands. */
12488 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12489 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12490 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12491 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12492 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12493 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12494 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12495 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12496 install_element(BGP_FLOWSPECV4_NODE,
12497 &neighbor_set_peer_group_hidden_cmd);
12498 install_element(BGP_FLOWSPECV6_NODE,
12499 &neighbor_set_peer_group_hidden_cmd);
12500
12501 /* "no neighbor peer-group unset" commands. */
12502 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12503 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12504 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12505 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12506 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12507 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12508 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12509 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12510 install_element(BGP_FLOWSPECV4_NODE,
12511 &no_neighbor_set_peer_group_hidden_cmd);
12512 install_element(BGP_FLOWSPECV6_NODE,
12513 &no_neighbor_set_peer_group_hidden_cmd);
12514
12515 /* "neighbor softreconfiguration inbound" commands.*/
12516 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12517 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12518 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12519 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12520 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12521 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12522 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12523 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12524 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12525 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12526 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12527 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12528 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12529 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12530 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12531 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12532 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12533 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12534 install_element(BGP_FLOWSPECV4_NODE,
12535 &neighbor_soft_reconfiguration_cmd);
12536 install_element(BGP_FLOWSPECV4_NODE,
12537 &no_neighbor_soft_reconfiguration_cmd);
12538 install_element(BGP_FLOWSPECV6_NODE,
12539 &neighbor_soft_reconfiguration_cmd);
12540 install_element(BGP_FLOWSPECV6_NODE,
12541 &no_neighbor_soft_reconfiguration_cmd);
12542
12543 /* "neighbor attribute-unchanged" commands. */
12544 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12545 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12546 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12547 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12548 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12549 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12550 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12551 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12552 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12553 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12554 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12555 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12556 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12557 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12558 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12559 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12560 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12561 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12562
12563 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12564 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12565
12566 /* "nexthop-local unchanged" commands */
12567 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12568 install_element(BGP_IPV6_NODE,
12569 &no_neighbor_nexthop_local_unchanged_cmd);
12570
12571 /* "neighbor next-hop-self" commands. */
12572 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12573 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12574 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12575 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12576 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12577 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12578 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12579 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12580 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12581 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12582 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12583 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12584 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12585 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12586 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12587 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12588 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12589 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12590 install_element(BGP_EVPN_NODE, &neighbor_nexthop_self_cmd);
12591 install_element(BGP_EVPN_NODE, &no_neighbor_nexthop_self_cmd);
12592
12593 /* "neighbor next-hop-self force" commands. */
12594 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12595 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12596 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12597 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12598 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12599 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12600 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12601 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12602 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12603 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12604 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12605 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12606 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12607 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12608 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12609 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12610 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12611 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12612
12613 /* "neighbor as-override" commands. */
12614 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12615 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12616 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12617 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12618 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12619 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12620 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12621 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12622 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12623 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12624 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12625 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12626 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12627 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12628 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12629 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12630 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12631 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12632
12633 /* "neighbor remove-private-AS" commands. */
12634 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12635 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12636 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12637 install_element(BGP_NODE,
12638 &no_neighbor_remove_private_as_all_hidden_cmd);
12639 install_element(BGP_NODE,
12640 &neighbor_remove_private_as_replace_as_hidden_cmd);
12641 install_element(BGP_NODE,
12642 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12643 install_element(BGP_NODE,
12644 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12645 install_element(
12646 BGP_NODE,
12647 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12648 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12649 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12650 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12651 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12652 install_element(BGP_IPV4_NODE,
12653 &neighbor_remove_private_as_replace_as_cmd);
12654 install_element(BGP_IPV4_NODE,
12655 &no_neighbor_remove_private_as_replace_as_cmd);
12656 install_element(BGP_IPV4_NODE,
12657 &neighbor_remove_private_as_all_replace_as_cmd);
12658 install_element(BGP_IPV4_NODE,
12659 &no_neighbor_remove_private_as_all_replace_as_cmd);
12660 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12661 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12662 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12663 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12664 install_element(BGP_IPV4M_NODE,
12665 &neighbor_remove_private_as_replace_as_cmd);
12666 install_element(BGP_IPV4M_NODE,
12667 &no_neighbor_remove_private_as_replace_as_cmd);
12668 install_element(BGP_IPV4M_NODE,
12669 &neighbor_remove_private_as_all_replace_as_cmd);
12670 install_element(BGP_IPV4M_NODE,
12671 &no_neighbor_remove_private_as_all_replace_as_cmd);
12672 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12673 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12674 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12675 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12676 install_element(BGP_IPV4L_NODE,
12677 &neighbor_remove_private_as_replace_as_cmd);
12678 install_element(BGP_IPV4L_NODE,
12679 &no_neighbor_remove_private_as_replace_as_cmd);
12680 install_element(BGP_IPV4L_NODE,
12681 &neighbor_remove_private_as_all_replace_as_cmd);
12682 install_element(BGP_IPV4L_NODE,
12683 &no_neighbor_remove_private_as_all_replace_as_cmd);
12684 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12685 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12686 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12687 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12688 install_element(BGP_IPV6_NODE,
12689 &neighbor_remove_private_as_replace_as_cmd);
12690 install_element(BGP_IPV6_NODE,
12691 &no_neighbor_remove_private_as_replace_as_cmd);
12692 install_element(BGP_IPV6_NODE,
12693 &neighbor_remove_private_as_all_replace_as_cmd);
12694 install_element(BGP_IPV6_NODE,
12695 &no_neighbor_remove_private_as_all_replace_as_cmd);
12696 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12697 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12698 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12699 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12700 install_element(BGP_IPV6M_NODE,
12701 &neighbor_remove_private_as_replace_as_cmd);
12702 install_element(BGP_IPV6M_NODE,
12703 &no_neighbor_remove_private_as_replace_as_cmd);
12704 install_element(BGP_IPV6M_NODE,
12705 &neighbor_remove_private_as_all_replace_as_cmd);
12706 install_element(BGP_IPV6M_NODE,
12707 &no_neighbor_remove_private_as_all_replace_as_cmd);
12708 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12709 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12710 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12711 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12712 install_element(BGP_IPV6L_NODE,
12713 &neighbor_remove_private_as_replace_as_cmd);
12714 install_element(BGP_IPV6L_NODE,
12715 &no_neighbor_remove_private_as_replace_as_cmd);
12716 install_element(BGP_IPV6L_NODE,
12717 &neighbor_remove_private_as_all_replace_as_cmd);
12718 install_element(BGP_IPV6L_NODE,
12719 &no_neighbor_remove_private_as_all_replace_as_cmd);
12720 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12721 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12722 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12723 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12724 install_element(BGP_VPNV4_NODE,
12725 &neighbor_remove_private_as_replace_as_cmd);
12726 install_element(BGP_VPNV4_NODE,
12727 &no_neighbor_remove_private_as_replace_as_cmd);
12728 install_element(BGP_VPNV4_NODE,
12729 &neighbor_remove_private_as_all_replace_as_cmd);
12730 install_element(BGP_VPNV4_NODE,
12731 &no_neighbor_remove_private_as_all_replace_as_cmd);
12732 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12733 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12734 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12735 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12736 install_element(BGP_VPNV6_NODE,
12737 &neighbor_remove_private_as_replace_as_cmd);
12738 install_element(BGP_VPNV6_NODE,
12739 &no_neighbor_remove_private_as_replace_as_cmd);
12740 install_element(BGP_VPNV6_NODE,
12741 &neighbor_remove_private_as_all_replace_as_cmd);
12742 install_element(BGP_VPNV6_NODE,
12743 &no_neighbor_remove_private_as_all_replace_as_cmd);
12744
12745 /* "neighbor send-community" commands.*/
12746 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12747 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12748 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12749 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12750 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12751 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12752 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12753 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12754 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12755 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12756 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12757 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12758 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12759 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12760 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12761 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12762 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12763 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12764 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12765 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12766 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12767 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12768 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12769 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12770 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12771 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12772 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12773 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12774 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12775 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12776 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12777 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12778 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12779 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12780 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12781 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12782
12783 /* "neighbor route-reflector" commands.*/
12784 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12785 install_element(BGP_NODE,
12786 &no_neighbor_route_reflector_client_hidden_cmd);
12787 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12788 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12789 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12790 install_element(BGP_IPV4M_NODE,
12791 &no_neighbor_route_reflector_client_cmd);
12792 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12793 install_element(BGP_IPV4L_NODE,
12794 &no_neighbor_route_reflector_client_cmd);
12795 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12796 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12797 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12798 install_element(BGP_IPV6M_NODE,
12799 &no_neighbor_route_reflector_client_cmd);
12800 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12801 install_element(BGP_IPV6L_NODE,
12802 &no_neighbor_route_reflector_client_cmd);
12803 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12804 install_element(BGP_VPNV4_NODE,
12805 &no_neighbor_route_reflector_client_cmd);
12806 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12807 install_element(BGP_VPNV6_NODE,
12808 &no_neighbor_route_reflector_client_cmd);
12809 install_element(BGP_FLOWSPECV4_NODE,
12810 &neighbor_route_reflector_client_cmd);
12811 install_element(BGP_FLOWSPECV4_NODE,
12812 &no_neighbor_route_reflector_client_cmd);
12813 install_element(BGP_FLOWSPECV6_NODE,
12814 &neighbor_route_reflector_client_cmd);
12815 install_element(BGP_FLOWSPECV6_NODE,
12816 &no_neighbor_route_reflector_client_cmd);
12817 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12818 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12819
12820 /* "neighbor route-server" commands.*/
12821 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12822 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12823 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12824 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12825 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12826 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12827 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12828 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12829 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12830 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12831 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12832 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12833 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12834 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12835 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12836 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12837 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12838 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12839 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd);
12840 install_element(BGP_FLOWSPECV4_NODE,
12841 &no_neighbor_route_server_client_cmd);
12842 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd);
12843 install_element(BGP_FLOWSPECV6_NODE,
12844 &no_neighbor_route_server_client_cmd);
12845
12846 /* "neighbor addpath-tx-all-paths" commands.*/
12847 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12848 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12849 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12850 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12851 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12852 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12853 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12854 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12855 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12856 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12857 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12858 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12859 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12860 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12861 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12862 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12863 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12864 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12865
12866 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12867 install_element(BGP_NODE,
12868 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12869 install_element(BGP_NODE,
12870 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12871 install_element(BGP_IPV4_NODE,
12872 &neighbor_addpath_tx_bestpath_per_as_cmd);
12873 install_element(BGP_IPV4_NODE,
12874 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12875 install_element(BGP_IPV4M_NODE,
12876 &neighbor_addpath_tx_bestpath_per_as_cmd);
12877 install_element(BGP_IPV4M_NODE,
12878 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12879 install_element(BGP_IPV4L_NODE,
12880 &neighbor_addpath_tx_bestpath_per_as_cmd);
12881 install_element(BGP_IPV4L_NODE,
12882 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12883 install_element(BGP_IPV6_NODE,
12884 &neighbor_addpath_tx_bestpath_per_as_cmd);
12885 install_element(BGP_IPV6_NODE,
12886 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12887 install_element(BGP_IPV6M_NODE,
12888 &neighbor_addpath_tx_bestpath_per_as_cmd);
12889 install_element(BGP_IPV6M_NODE,
12890 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12891 install_element(BGP_IPV6L_NODE,
12892 &neighbor_addpath_tx_bestpath_per_as_cmd);
12893 install_element(BGP_IPV6L_NODE,
12894 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12895 install_element(BGP_VPNV4_NODE,
12896 &neighbor_addpath_tx_bestpath_per_as_cmd);
12897 install_element(BGP_VPNV4_NODE,
12898 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12899 install_element(BGP_VPNV6_NODE,
12900 &neighbor_addpath_tx_bestpath_per_as_cmd);
12901 install_element(BGP_VPNV6_NODE,
12902 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12903
12904 /* "neighbor passive" commands. */
12905 install_element(BGP_NODE, &neighbor_passive_cmd);
12906 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12907
12908
12909 /* "neighbor shutdown" commands. */
12910 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12911 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12912 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12913 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12914
12915 /* "neighbor capability extended-nexthop" commands.*/
12916 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12917 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12918
12919 /* "neighbor capability orf prefix-list" commands.*/
12920 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12921 install_element(BGP_NODE,
12922 &no_neighbor_capability_orf_prefix_hidden_cmd);
12923 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12924 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12925 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12926 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12927 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12928 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12929 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12930 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12931 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12932 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12933 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12934 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12935
12936 /* "neighbor capability dynamic" commands.*/
12937 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12938 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12939
12940 /* "neighbor dont-capability-negotiate" commands. */
12941 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12942 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12943
12944 /* "neighbor ebgp-multihop" commands. */
12945 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12946 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12947 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12948
12949 /* "neighbor disable-connected-check" commands. */
12950 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12951 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12952
12953 /* "neighbor description" commands. */
12954 install_element(BGP_NODE, &neighbor_description_cmd);
12955 install_element(BGP_NODE, &no_neighbor_description_cmd);
12956
12957 /* "neighbor update-source" commands. "*/
12958 install_element(BGP_NODE, &neighbor_update_source_cmd);
12959 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12960
12961 /* "neighbor default-originate" commands. */
12962 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12963 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12964 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12965 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12966 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12967 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12968 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12969 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12970 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12971 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12972 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12973 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12974 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12975 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12976 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12977 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12978 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12979 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12980 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12981 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12982 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12983
12984 /* "neighbor port" commands. */
12985 install_element(BGP_NODE, &neighbor_port_cmd);
12986 install_element(BGP_NODE, &no_neighbor_port_cmd);
12987
12988 /* "neighbor weight" commands. */
12989 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12990 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12991
12992 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12993 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12994 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12995 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12996 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12997 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12998 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12999 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
13000 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
13001 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
13002 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
13003 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
13004 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
13005 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
13006 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
13007 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
13008
13009 /* "neighbor override-capability" commands. */
13010 install_element(BGP_NODE, &neighbor_override_capability_cmd);
13011 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
13012
13013 /* "neighbor strict-capability-match" commands. */
13014 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
13015 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
13016
13017 /* "neighbor timers" commands. */
13018 install_element(BGP_NODE, &neighbor_timers_cmd);
13019 install_element(BGP_NODE, &no_neighbor_timers_cmd);
13020
13021 /* "neighbor timers connect" commands. */
13022 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
13023 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
13024
13025 /* "neighbor advertisement-interval" commands. */
13026 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
13027 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
13028
13029 /* "neighbor interface" commands. */
13030 install_element(BGP_NODE, &neighbor_interface_cmd);
13031 install_element(BGP_NODE, &no_neighbor_interface_cmd);
13032
13033 /* "neighbor distribute" commands. */
13034 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
13035 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
13036 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
13037 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
13038 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
13039 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
13040 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
13041 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
13042 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
13043 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
13044 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
13045 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
13046 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
13047 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
13048 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
13049 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
13050 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
13051 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
13052
13053 /* "neighbor prefix-list" commands. */
13054 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
13055 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
13056 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
13057 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
13058 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
13059 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
13060 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
13061 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
13062 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
13063 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
13064 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
13065 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
13066 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
13067 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
13068 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
13069 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
13070 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
13071 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
13072 install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd);
13073 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd);
13074 install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd);
13075 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd);
13076
13077 /* "neighbor filter-list" commands. */
13078 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
13079 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
13080 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
13081 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
13082 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
13083 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
13084 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
13085 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
13086 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
13087 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
13088 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
13089 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
13090 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
13091 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
13092 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
13093 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
13094 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
13095 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
13096 install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd);
13097 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd);
13098 install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd);
13099 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd);
13100
13101 /* "neighbor route-map" commands. */
13102 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
13103 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
13104 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
13105 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
13106 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
13107 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
13108 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
13109 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
13110 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
13111 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
13112 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
13113 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
13114 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
13115 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
13116 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
13117 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
13118 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
13119 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
13120 install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd);
13121 install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd);
13122 install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd);
13123 install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd);
13124 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
13125 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
13126
13127 /* "neighbor unsuppress-map" commands. */
13128 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
13129 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
13130 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
13131 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
13132 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
13133 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
13134 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
13135 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
13136 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
13137 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
13138 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
13139 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
13140 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
13141 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
13142 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
13143 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
13144 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
13145 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
13146
13147 /* "neighbor maximum-prefix" commands. */
13148 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
13149 install_element(BGP_NODE,
13150 &neighbor_maximum_prefix_threshold_hidden_cmd);
13151 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
13152 install_element(BGP_NODE,
13153 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
13154 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
13155 install_element(BGP_NODE,
13156 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
13157 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
13158 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
13159 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13160 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13161 install_element(BGP_IPV4_NODE,
13162 &neighbor_maximum_prefix_threshold_warning_cmd);
13163 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13164 install_element(BGP_IPV4_NODE,
13165 &neighbor_maximum_prefix_threshold_restart_cmd);
13166 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
13167 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
13168 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13169 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
13170 install_element(BGP_IPV4M_NODE,
13171 &neighbor_maximum_prefix_threshold_warning_cmd);
13172 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
13173 install_element(BGP_IPV4M_NODE,
13174 &neighbor_maximum_prefix_threshold_restart_cmd);
13175 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
13176 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
13177 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13178 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
13179 install_element(BGP_IPV4L_NODE,
13180 &neighbor_maximum_prefix_threshold_warning_cmd);
13181 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
13182 install_element(BGP_IPV4L_NODE,
13183 &neighbor_maximum_prefix_threshold_restart_cmd);
13184 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
13185 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
13186 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13187 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13188 install_element(BGP_IPV6_NODE,
13189 &neighbor_maximum_prefix_threshold_warning_cmd);
13190 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13191 install_element(BGP_IPV6_NODE,
13192 &neighbor_maximum_prefix_threshold_restart_cmd);
13193 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
13194 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
13195 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
13196 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
13197 install_element(BGP_IPV6M_NODE,
13198 &neighbor_maximum_prefix_threshold_warning_cmd);
13199 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
13200 install_element(BGP_IPV6M_NODE,
13201 &neighbor_maximum_prefix_threshold_restart_cmd);
13202 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
13203 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
13204 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
13205 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
13206 install_element(BGP_IPV6L_NODE,
13207 &neighbor_maximum_prefix_threshold_warning_cmd);
13208 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
13209 install_element(BGP_IPV6L_NODE,
13210 &neighbor_maximum_prefix_threshold_restart_cmd);
13211 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
13212 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
13213 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
13214 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
13215 install_element(BGP_VPNV4_NODE,
13216 &neighbor_maximum_prefix_threshold_warning_cmd);
13217 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
13218 install_element(BGP_VPNV4_NODE,
13219 &neighbor_maximum_prefix_threshold_restart_cmd);
13220 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
13221 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
13222 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
13223 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
13224 install_element(BGP_VPNV6_NODE,
13225 &neighbor_maximum_prefix_threshold_warning_cmd);
13226 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
13227 install_element(BGP_VPNV6_NODE,
13228 &neighbor_maximum_prefix_threshold_restart_cmd);
13229 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
13230
13231 /* "neighbor allowas-in" */
13232 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
13233 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
13234 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
13235 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
13236 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
13237 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
13238 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
13239 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
13240 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
13241 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
13242 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
13243 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
13244 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
13245 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
13246 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
13247 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
13248 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
13249 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
13250 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
13251 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
13252
13253 /* address-family commands. */
13254 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
13255 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
13256 #ifdef KEEP_OLD_VPN_COMMANDS
13257 install_element(BGP_NODE, &address_family_vpnv4_cmd);
13258 install_element(BGP_NODE, &address_family_vpnv6_cmd);
13259 #endif /* KEEP_OLD_VPN_COMMANDS */
13260
13261 install_element(BGP_NODE, &address_family_evpn_cmd);
13262
13263 /* "exit-address-family" command. */
13264 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
13265 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
13266 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
13267 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
13268 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
13269 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
13270 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
13271 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
13272 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
13273 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
13274 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
13275
13276 /* "clear ip bgp commands" */
13277 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
13278
13279 /* clear ip bgp prefix */
13280 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
13281 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
13282 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
13283
13284 /* "show [ip] bgp summary" commands. */
13285 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
13286 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
13287 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
13288 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
13289 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
13290 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
13291
13292 /* "show [ip] bgp neighbors" commands. */
13293 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
13294
13295 /* "show [ip] bgp peer-group" commands. */
13296 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
13297
13298 /* "show [ip] bgp paths" commands. */
13299 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
13300
13301 /* "show [ip] bgp community" commands. */
13302 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
13303
13304 /* "show ip bgp large-community" commands. */
13305 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
13306 /* "show [ip] bgp attribute-info" commands. */
13307 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
13308 /* "show [ip] bgp route-leak" command */
13309 install_element(VIEW_NODE, &show_ip_bgp_route_leak_cmd);
13310
13311 /* "redistribute" commands. */
13312 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
13313 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
13314 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
13315 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
13316 install_element(BGP_NODE,
13317 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
13318 install_element(BGP_NODE,
13319 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
13320 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
13321 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
13322 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
13323 install_element(BGP_NODE,
13324 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
13325 install_element(BGP_NODE,
13326 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
13327 install_element(BGP_NODE,
13328 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
13329 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
13330 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
13331 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
13332 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
13333 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
13334 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
13335 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
13336 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
13337 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
13338 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
13339 install_element(BGP_IPV4_NODE,
13340 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
13341 install_element(BGP_IPV4_NODE,
13342 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
13343 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
13344 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
13345 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13346 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13347 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13348 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13349
13350 /* import|export vpn [route-map WORD] */
13351 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
13352 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
13353
13354 install_element(BGP_IPV4_NODE, &bgp_imexport_vrf_cmd);
13355 install_element(BGP_IPV6_NODE, &bgp_imexport_vrf_cmd);
13356
13357 /* ttl_security commands */
13358 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13359 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13360
13361 /* "show [ip] bgp memory" commands. */
13362 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13363
13364 /* "show bgp martian next-hop" */
13365 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13366
13367 /* "show [ip] bgp views" commands. */
13368 install_element(VIEW_NODE, &show_bgp_views_cmd);
13369
13370 /* "show [ip] bgp vrfs" commands. */
13371 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13372
13373 /* Community-list. */
13374 community_list_vty();
13375
13376 /* vpn-policy commands */
13377 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
13378 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
13379 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
13380 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
13381 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
13382 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
13383 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
13384 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
13385 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
13386 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
13387 install_element(BGP_IPV4_NODE, &af_import_vrf_route_map_cmd);
13388 install_element(BGP_IPV6_NODE, &af_import_vrf_route_map_cmd);
13389
13390 install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd);
13391 install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd);
13392
13393 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
13394 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
13395 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
13396 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
13397 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
13398 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
13399 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
13400 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
13401 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
13402 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
13403 install_element(BGP_IPV4_NODE, &af_no_import_vrf_route_map_cmd);
13404 install_element(BGP_IPV6_NODE, &af_no_import_vrf_route_map_cmd);
13405 }
13406
13407 #include "memory.h"
13408 #include "bgp_regex.h"
13409 #include "bgp_clist.h"
13410 #include "bgp_ecommunity.h"
13411
13412 /* VTY functions. */
13413
13414 /* Direction value to string conversion. */
13415 static const char *community_direct_str(int direct)
13416 {
13417 switch (direct) {
13418 case COMMUNITY_DENY:
13419 return "deny";
13420 case COMMUNITY_PERMIT:
13421 return "permit";
13422 default:
13423 return "unknown";
13424 }
13425 }
13426
13427 /* Display error string. */
13428 static void community_list_perror(struct vty *vty, int ret)
13429 {
13430 switch (ret) {
13431 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13432 vty_out(vty, "%% Can't find community-list\n");
13433 break;
13434 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13435 vty_out(vty, "%% Malformed community-list value\n");
13436 break;
13437 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13438 vty_out(vty,
13439 "%% Community name conflict, previously defined as standard community\n");
13440 break;
13441 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13442 vty_out(vty,
13443 "%% Community name conflict, previously defined as expanded community\n");
13444 break;
13445 }
13446 }
13447
13448 /* "community-list" keyword help string. */
13449 #define COMMUNITY_LIST_STR "Add a community list entry\n"
13450
13451 /* ip community-list standard */
13452 DEFUN (ip_community_list_standard,
13453 ip_community_list_standard_cmd,
13454 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13455 IP_STR
13456 COMMUNITY_LIST_STR
13457 "Community list number (standard)\n"
13458 "Add an standard community-list entry\n"
13459 "Community list name\n"
13460 "Specify community to reject\n"
13461 "Specify community to accept\n"
13462 COMMUNITY_VAL_STR)
13463 {
13464 char *cl_name_or_number = NULL;
13465 int direct = 0;
13466 int style = COMMUNITY_LIST_STANDARD;
13467
13468 int idx = 0;
13469 argv_find(argv, argc, "(1-99)", &idx);
13470 argv_find(argv, argc, "WORD", &idx);
13471 cl_name_or_number = argv[idx]->arg;
13472 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13473 : COMMUNITY_DENY;
13474 argv_find(argv, argc, "AA:NN", &idx);
13475 char *str = argv_concat(argv, argc, idx);
13476
13477 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13478 style);
13479
13480 XFREE(MTYPE_TMP, str);
13481
13482 if (ret < 0) {
13483 /* Display error string. */
13484 community_list_perror(vty, ret);
13485 return CMD_WARNING_CONFIG_FAILED;
13486 }
13487
13488 return CMD_SUCCESS;
13489 }
13490
13491 DEFUN (no_ip_community_list_standard_all,
13492 no_ip_community_list_standard_all_cmd,
13493 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13494 NO_STR
13495 IP_STR
13496 COMMUNITY_LIST_STR
13497 "Community list number (standard)\n"
13498 "Add an standard community-list entry\n"
13499 "Community list name\n"
13500 "Specify community to reject\n"
13501 "Specify community to accept\n"
13502 COMMUNITY_VAL_STR)
13503 {
13504 char *cl_name_or_number = NULL;
13505 int direct = 0;
13506 int style = COMMUNITY_LIST_STANDARD;
13507
13508 int idx = 0;
13509 argv_find(argv, argc, "(1-99)", &idx);
13510 argv_find(argv, argc, "WORD", &idx);
13511 cl_name_or_number = argv[idx]->arg;
13512 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13513 : COMMUNITY_DENY;
13514 argv_find(argv, argc, "AA:NN", &idx);
13515 char *str = argv_concat(argv, argc, idx);
13516
13517 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13518 direct, style);
13519
13520 XFREE(MTYPE_TMP, str);
13521
13522 if (ret < 0) {
13523 community_list_perror(vty, ret);
13524 return CMD_WARNING_CONFIG_FAILED;
13525 }
13526
13527 return CMD_SUCCESS;
13528 }
13529
13530 /* ip community-list expanded */
13531 DEFUN (ip_community_list_expanded_all,
13532 ip_community_list_expanded_all_cmd,
13533 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13534 IP_STR
13535 COMMUNITY_LIST_STR
13536 "Community list number (expanded)\n"
13537 "Add an expanded community-list entry\n"
13538 "Community list name\n"
13539 "Specify community to reject\n"
13540 "Specify community to accept\n"
13541 COMMUNITY_VAL_STR)
13542 {
13543 char *cl_name_or_number = NULL;
13544 int direct = 0;
13545 int style = COMMUNITY_LIST_EXPANDED;
13546
13547 int idx = 0;
13548 argv_find(argv, argc, "(100-500)", &idx);
13549 argv_find(argv, argc, "WORD", &idx);
13550 cl_name_or_number = argv[idx]->arg;
13551 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13552 : COMMUNITY_DENY;
13553 argv_find(argv, argc, "AA:NN", &idx);
13554 char *str = argv_concat(argv, argc, idx);
13555
13556 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13557 style);
13558
13559 XFREE(MTYPE_TMP, str);
13560
13561 if (ret < 0) {
13562 /* Display error string. */
13563 community_list_perror(vty, ret);
13564 return CMD_WARNING_CONFIG_FAILED;
13565 }
13566
13567 return CMD_SUCCESS;
13568 }
13569
13570 DEFUN (no_ip_community_list_expanded_all,
13571 no_ip_community_list_expanded_all_cmd,
13572 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13573 NO_STR
13574 IP_STR
13575 COMMUNITY_LIST_STR
13576 "Community list number (expanded)\n"
13577 "Add an expanded community-list entry\n"
13578 "Community list name\n"
13579 "Specify community to reject\n"
13580 "Specify community to accept\n"
13581 COMMUNITY_VAL_STR)
13582 {
13583 char *cl_name_or_number = NULL;
13584 int direct = 0;
13585 int style = COMMUNITY_LIST_EXPANDED;
13586
13587 int idx = 0;
13588 argv_find(argv, argc, "(100-500)", &idx);
13589 argv_find(argv, argc, "WORD", &idx);
13590 cl_name_or_number = argv[idx]->arg;
13591 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13592 : COMMUNITY_DENY;
13593 argv_find(argv, argc, "AA:NN", &idx);
13594 char *str = argv_concat(argv, argc, idx);
13595
13596 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13597 direct, style);
13598
13599 XFREE(MTYPE_TMP, str);
13600
13601 if (ret < 0) {
13602 community_list_perror(vty, ret);
13603 return CMD_WARNING_CONFIG_FAILED;
13604 }
13605
13606 return CMD_SUCCESS;
13607 }
13608
13609 static void community_list_show(struct vty *vty, struct community_list *list)
13610 {
13611 struct community_entry *entry;
13612
13613 for (entry = list->head; entry; entry = entry->next) {
13614 if (entry == list->head) {
13615 if (all_digit(list->name))
13616 vty_out(vty, "Community %s list %s\n",
13617 entry->style == COMMUNITY_LIST_STANDARD
13618 ? "standard"
13619 : "(expanded) access",
13620 list->name);
13621 else
13622 vty_out(vty, "Named Community %s list %s\n",
13623 entry->style == COMMUNITY_LIST_STANDARD
13624 ? "standard"
13625 : "expanded",
13626 list->name);
13627 }
13628 if (entry->any)
13629 vty_out(vty, " %s\n",
13630 community_direct_str(entry->direct));
13631 else
13632 vty_out(vty, " %s %s\n",
13633 community_direct_str(entry->direct),
13634 entry->style == COMMUNITY_LIST_STANDARD
13635 ? community_str(entry->u.com, false)
13636 : entry->config);
13637 }
13638 }
13639
13640 DEFUN (show_ip_community_list,
13641 show_ip_community_list_cmd,
13642 "show ip community-list",
13643 SHOW_STR
13644 IP_STR
13645 "List community-list\n")
13646 {
13647 struct community_list *list;
13648 struct community_list_master *cm;
13649
13650 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13651 if (!cm)
13652 return CMD_SUCCESS;
13653
13654 for (list = cm->num.head; list; list = list->next)
13655 community_list_show(vty, list);
13656
13657 for (list = cm->str.head; list; list = list->next)
13658 community_list_show(vty, list);
13659
13660 return CMD_SUCCESS;
13661 }
13662
13663 DEFUN (show_ip_community_list_arg,
13664 show_ip_community_list_arg_cmd,
13665 "show ip community-list <(1-500)|WORD>",
13666 SHOW_STR
13667 IP_STR
13668 "List community-list\n"
13669 "Community-list number\n"
13670 "Community-list name\n")
13671 {
13672 int idx_comm_list = 3;
13673 struct community_list *list;
13674
13675 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13676 COMMUNITY_LIST_MASTER);
13677 if (!list) {
13678 vty_out(vty, "%% Can't find community-list\n");
13679 return CMD_WARNING;
13680 }
13681
13682 community_list_show(vty, list);
13683
13684 return CMD_SUCCESS;
13685 }
13686
13687 /*
13688 * Large Community code.
13689 */
13690 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13691 struct cmd_token **argv, int style,
13692 int reject_all_digit_name)
13693 {
13694 int ret;
13695 int direct;
13696 char *str;
13697 int idx = 0;
13698 char *cl_name;
13699
13700 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13701 : COMMUNITY_DENY;
13702
13703 /* All digit name check. */
13704 idx = 0;
13705 argv_find(argv, argc, "WORD", &idx);
13706 argv_find(argv, argc, "(1-99)", &idx);
13707 argv_find(argv, argc, "(100-500)", &idx);
13708 cl_name = argv[idx]->arg;
13709 if (reject_all_digit_name && all_digit(cl_name)) {
13710 vty_out(vty, "%% Community name cannot have all digits\n");
13711 return CMD_WARNING_CONFIG_FAILED;
13712 }
13713
13714 idx = 0;
13715 argv_find(argv, argc, "AA:BB:CC", &idx);
13716 argv_find(argv, argc, "LINE", &idx);
13717 /* Concat community string argument. */
13718 if (idx)
13719 str = argv_concat(argv, argc, idx);
13720 else
13721 str = NULL;
13722
13723 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13724
13725 /* Free temporary community list string allocated by
13726 argv_concat(). */
13727 if (str)
13728 XFREE(MTYPE_TMP, str);
13729
13730 if (ret < 0) {
13731 community_list_perror(vty, ret);
13732 return CMD_WARNING_CONFIG_FAILED;
13733 }
13734 return CMD_SUCCESS;
13735 }
13736
13737 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13738 struct cmd_token **argv, int style)
13739 {
13740 int ret;
13741 int direct = 0;
13742 char *str = NULL;
13743 int idx = 0;
13744
13745 argv_find(argv, argc, "permit", &idx);
13746 argv_find(argv, argc, "deny", &idx);
13747
13748 if (idx) {
13749 /* Check the list direct. */
13750 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13751 direct = COMMUNITY_PERMIT;
13752 else
13753 direct = COMMUNITY_DENY;
13754
13755 idx = 0;
13756 argv_find(argv, argc, "LINE", &idx);
13757 argv_find(argv, argc, "AA:AA:NN", &idx);
13758 /* Concat community string argument. */
13759 str = argv_concat(argv, argc, idx);
13760 }
13761
13762 idx = 0;
13763 argv_find(argv, argc, "(1-99)", &idx);
13764 argv_find(argv, argc, "(100-500)", &idx);
13765 argv_find(argv, argc, "WORD", &idx);
13766
13767 /* Unset community list. */
13768 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13769 style);
13770
13771 /* Free temporary community list string allocated by
13772 argv_concat(). */
13773 if (str)
13774 XFREE(MTYPE_TMP, str);
13775
13776 if (ret < 0) {
13777 community_list_perror(vty, ret);
13778 return CMD_WARNING_CONFIG_FAILED;
13779 }
13780
13781 return CMD_SUCCESS;
13782 }
13783
13784 /* "large-community-list" keyword help string. */
13785 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13786 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13787
13788 DEFUN (ip_lcommunity_list_standard,
13789 ip_lcommunity_list_standard_cmd,
13790 "ip large-community-list (1-99) <deny|permit>",
13791 IP_STR
13792 LCOMMUNITY_LIST_STR
13793 "Large Community list number (standard)\n"
13794 "Specify large community to reject\n"
13795 "Specify large community to accept\n")
13796 {
13797 return lcommunity_list_set_vty(vty, argc, argv,
13798 LARGE_COMMUNITY_LIST_STANDARD, 0);
13799 }
13800
13801 DEFUN (ip_lcommunity_list_standard1,
13802 ip_lcommunity_list_standard1_cmd,
13803 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13804 IP_STR
13805 LCOMMUNITY_LIST_STR
13806 "Large Community list number (standard)\n"
13807 "Specify large community to reject\n"
13808 "Specify large community to accept\n"
13809 LCOMMUNITY_VAL_STR)
13810 {
13811 return lcommunity_list_set_vty(vty, argc, argv,
13812 LARGE_COMMUNITY_LIST_STANDARD, 0);
13813 }
13814
13815 DEFUN (ip_lcommunity_list_expanded,
13816 ip_lcommunity_list_expanded_cmd,
13817 "ip large-community-list (100-500) <deny|permit> LINE...",
13818 IP_STR
13819 LCOMMUNITY_LIST_STR
13820 "Large Community list number (expanded)\n"
13821 "Specify large community to reject\n"
13822 "Specify large community to accept\n"
13823 "An ordered list as a regular-expression\n")
13824 {
13825 return lcommunity_list_set_vty(vty, argc, argv,
13826 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13827 }
13828
13829 DEFUN (ip_lcommunity_list_name_standard,
13830 ip_lcommunity_list_name_standard_cmd,
13831 "ip large-community-list standard WORD <deny|permit>",
13832 IP_STR
13833 LCOMMUNITY_LIST_STR
13834 "Specify standard large-community-list\n"
13835 "Large Community list name\n"
13836 "Specify large community to reject\n"
13837 "Specify large community to accept\n")
13838 {
13839 return lcommunity_list_set_vty(vty, argc, argv,
13840 LARGE_COMMUNITY_LIST_STANDARD, 1);
13841 }
13842
13843 DEFUN (ip_lcommunity_list_name_standard1,
13844 ip_lcommunity_list_name_standard1_cmd,
13845 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13846 IP_STR
13847 LCOMMUNITY_LIST_STR
13848 "Specify standard large-community-list\n"
13849 "Large Community list name\n"
13850 "Specify large community to reject\n"
13851 "Specify large community to accept\n"
13852 LCOMMUNITY_VAL_STR)
13853 {
13854 return lcommunity_list_set_vty(vty, argc, argv,
13855 LARGE_COMMUNITY_LIST_STANDARD, 1);
13856 }
13857
13858 DEFUN (ip_lcommunity_list_name_expanded,
13859 ip_lcommunity_list_name_expanded_cmd,
13860 "ip large-community-list expanded WORD <deny|permit> LINE...",
13861 IP_STR
13862 LCOMMUNITY_LIST_STR
13863 "Specify expanded large-community-list\n"
13864 "Large Community list name\n"
13865 "Specify large community to reject\n"
13866 "Specify large community to accept\n"
13867 "An ordered list as a regular-expression\n")
13868 {
13869 return lcommunity_list_set_vty(vty, argc, argv,
13870 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13871 }
13872
13873 DEFUN (no_ip_lcommunity_list_standard_all,
13874 no_ip_lcommunity_list_standard_all_cmd,
13875 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13876 NO_STR
13877 IP_STR
13878 LCOMMUNITY_LIST_STR
13879 "Large Community list number (standard)\n"
13880 "Large Community list number (expanded)\n"
13881 "Large Community list name\n")
13882 {
13883 return lcommunity_list_unset_vty(vty, argc, argv,
13884 LARGE_COMMUNITY_LIST_STANDARD);
13885 }
13886
13887 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13888 no_ip_lcommunity_list_name_expanded_all_cmd,
13889 "no ip large-community-list expanded WORD",
13890 NO_STR
13891 IP_STR
13892 LCOMMUNITY_LIST_STR
13893 "Specify expanded large-community-list\n"
13894 "Large Community list name\n")
13895 {
13896 return lcommunity_list_unset_vty(vty, argc, argv,
13897 LARGE_COMMUNITY_LIST_EXPANDED);
13898 }
13899
13900 DEFUN (no_ip_lcommunity_list_standard,
13901 no_ip_lcommunity_list_standard_cmd,
13902 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13903 NO_STR
13904 IP_STR
13905 LCOMMUNITY_LIST_STR
13906 "Large Community list number (standard)\n"
13907 "Specify large community to reject\n"
13908 "Specify large community to accept\n"
13909 LCOMMUNITY_VAL_STR)
13910 {
13911 return lcommunity_list_unset_vty(vty, argc, argv,
13912 LARGE_COMMUNITY_LIST_STANDARD);
13913 }
13914
13915 DEFUN (no_ip_lcommunity_list_expanded,
13916 no_ip_lcommunity_list_expanded_cmd,
13917 "no ip large-community-list (100-500) <deny|permit> LINE...",
13918 NO_STR
13919 IP_STR
13920 LCOMMUNITY_LIST_STR
13921 "Large Community list number (expanded)\n"
13922 "Specify large community to reject\n"
13923 "Specify large community to accept\n"
13924 "An ordered list as a regular-expression\n")
13925 {
13926 return lcommunity_list_unset_vty(vty, argc, argv,
13927 LARGE_COMMUNITY_LIST_EXPANDED);
13928 }
13929
13930 DEFUN (no_ip_lcommunity_list_name_standard,
13931 no_ip_lcommunity_list_name_standard_cmd,
13932 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13933 NO_STR
13934 IP_STR
13935 LCOMMUNITY_LIST_STR
13936 "Specify standard large-community-list\n"
13937 "Large Community list name\n"
13938 "Specify large community to reject\n"
13939 "Specify large community to accept\n"
13940 LCOMMUNITY_VAL_STR)
13941 {
13942 return lcommunity_list_unset_vty(vty, argc, argv,
13943 LARGE_COMMUNITY_LIST_STANDARD);
13944 }
13945
13946 DEFUN (no_ip_lcommunity_list_name_expanded,
13947 no_ip_lcommunity_list_name_expanded_cmd,
13948 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13949 NO_STR
13950 IP_STR
13951 LCOMMUNITY_LIST_STR
13952 "Specify expanded large-community-list\n"
13953 "Large community list name\n"
13954 "Specify large community to reject\n"
13955 "Specify large community to accept\n"
13956 "An ordered list as a regular-expression\n")
13957 {
13958 return lcommunity_list_unset_vty(vty, argc, argv,
13959 LARGE_COMMUNITY_LIST_EXPANDED);
13960 }
13961
13962 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13963 {
13964 struct community_entry *entry;
13965
13966 for (entry = list->head; entry; entry = entry->next) {
13967 if (entry == list->head) {
13968 if (all_digit(list->name))
13969 vty_out(vty, "Large community %s list %s\n",
13970 entry->style == EXTCOMMUNITY_LIST_STANDARD
13971 ? "standard"
13972 : "(expanded) access",
13973 list->name);
13974 else
13975 vty_out(vty,
13976 "Named large community %s list %s\n",
13977 entry->style == EXTCOMMUNITY_LIST_STANDARD
13978 ? "standard"
13979 : "expanded",
13980 list->name);
13981 }
13982 if (entry->any)
13983 vty_out(vty, " %s\n",
13984 community_direct_str(entry->direct));
13985 else
13986 vty_out(vty, " %s %s\n",
13987 community_direct_str(entry->direct),
13988 entry->style == EXTCOMMUNITY_LIST_STANDARD
13989 ? entry->u.ecom->str
13990 : entry->config);
13991 }
13992 }
13993
13994 DEFUN (show_ip_lcommunity_list,
13995 show_ip_lcommunity_list_cmd,
13996 "show ip large-community-list",
13997 SHOW_STR
13998 IP_STR
13999 "List large-community list\n")
14000 {
14001 struct community_list *list;
14002 struct community_list_master *cm;
14003
14004 cm = community_list_master_lookup(bgp_clist,
14005 LARGE_COMMUNITY_LIST_MASTER);
14006 if (!cm)
14007 return CMD_SUCCESS;
14008
14009 for (list = cm->num.head; list; list = list->next)
14010 lcommunity_list_show(vty, list);
14011
14012 for (list = cm->str.head; list; list = list->next)
14013 lcommunity_list_show(vty, list);
14014
14015 return CMD_SUCCESS;
14016 }
14017
14018 DEFUN (show_ip_lcommunity_list_arg,
14019 show_ip_lcommunity_list_arg_cmd,
14020 "show ip large-community-list <(1-500)|WORD>",
14021 SHOW_STR
14022 IP_STR
14023 "List large-community list\n"
14024 "large-community-list number\n"
14025 "large-community-list name\n")
14026 {
14027 struct community_list *list;
14028
14029 list = community_list_lookup(bgp_clist, argv[3]->arg,
14030 LARGE_COMMUNITY_LIST_MASTER);
14031 if (!list) {
14032 vty_out(vty, "%% Can't find extcommunity-list\n");
14033 return CMD_WARNING;
14034 }
14035
14036 lcommunity_list_show(vty, list);
14037
14038 return CMD_SUCCESS;
14039 }
14040
14041 /* "extcommunity-list" keyword help string. */
14042 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
14043 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
14044
14045 DEFUN (ip_extcommunity_list_standard,
14046 ip_extcommunity_list_standard_cmd,
14047 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14048 IP_STR
14049 EXTCOMMUNITY_LIST_STR
14050 "Extended Community list number (standard)\n"
14051 "Specify standard extcommunity-list\n"
14052 "Community list name\n"
14053 "Specify community to reject\n"
14054 "Specify community to accept\n"
14055 EXTCOMMUNITY_VAL_STR)
14056 {
14057 int style = EXTCOMMUNITY_LIST_STANDARD;
14058 int direct = 0;
14059 char *cl_number_or_name = NULL;
14060
14061 int idx = 0;
14062 argv_find(argv, argc, "(1-99)", &idx);
14063 argv_find(argv, argc, "WORD", &idx);
14064 cl_number_or_name = argv[idx]->arg;
14065 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14066 : COMMUNITY_DENY;
14067 argv_find(argv, argc, "AA:NN", &idx);
14068 char *str = argv_concat(argv, argc, idx);
14069
14070 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14071 direct, style);
14072
14073 XFREE(MTYPE_TMP, str);
14074
14075 if (ret < 0) {
14076 community_list_perror(vty, ret);
14077 return CMD_WARNING_CONFIG_FAILED;
14078 }
14079
14080 return CMD_SUCCESS;
14081 }
14082
14083 DEFUN (ip_extcommunity_list_name_expanded,
14084 ip_extcommunity_list_name_expanded_cmd,
14085 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14086 IP_STR
14087 EXTCOMMUNITY_LIST_STR
14088 "Extended Community list number (expanded)\n"
14089 "Specify expanded extcommunity-list\n"
14090 "Extended Community list name\n"
14091 "Specify community to reject\n"
14092 "Specify community to accept\n"
14093 "An ordered list as a regular-expression\n")
14094 {
14095 int style = EXTCOMMUNITY_LIST_EXPANDED;
14096 int direct = 0;
14097 char *cl_number_or_name = NULL;
14098
14099 int idx = 0;
14100 argv_find(argv, argc, "(100-500)", &idx);
14101 argv_find(argv, argc, "WORD", &idx);
14102 cl_number_or_name = argv[idx]->arg;
14103 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14104 : COMMUNITY_DENY;
14105 argv_find(argv, argc, "LINE", &idx);
14106 char *str = argv_concat(argv, argc, idx);
14107
14108 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
14109 direct, style);
14110
14111 XFREE(MTYPE_TMP, str);
14112
14113 if (ret < 0) {
14114 community_list_perror(vty, ret);
14115 return CMD_WARNING_CONFIG_FAILED;
14116 }
14117
14118 return CMD_SUCCESS;
14119 }
14120
14121 DEFUN (no_ip_extcommunity_list_standard_all,
14122 no_ip_extcommunity_list_standard_all_cmd,
14123 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
14124 NO_STR
14125 IP_STR
14126 EXTCOMMUNITY_LIST_STR
14127 "Extended Community list number (standard)\n"
14128 "Specify standard extcommunity-list\n"
14129 "Community list name\n"
14130 "Specify community to reject\n"
14131 "Specify community to accept\n"
14132 EXTCOMMUNITY_VAL_STR)
14133 {
14134 int style = EXTCOMMUNITY_LIST_STANDARD;
14135 int direct = 0;
14136 char *cl_number_or_name = NULL;
14137
14138 int idx = 0;
14139 argv_find(argv, argc, "(1-99)", &idx);
14140 argv_find(argv, argc, "WORD", &idx);
14141 cl_number_or_name = argv[idx]->arg;
14142 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14143 : COMMUNITY_DENY;
14144 argv_find(argv, argc, "AA:NN", &idx);
14145 char *str = argv_concat(argv, argc, idx);
14146
14147 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14148 direct, style);
14149
14150 XFREE(MTYPE_TMP, str);
14151
14152 if (ret < 0) {
14153 community_list_perror(vty, ret);
14154 return CMD_WARNING_CONFIG_FAILED;
14155 }
14156
14157 return CMD_SUCCESS;
14158 }
14159
14160 DEFUN (no_ip_extcommunity_list_expanded_all,
14161 no_ip_extcommunity_list_expanded_all_cmd,
14162 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
14163 NO_STR
14164 IP_STR
14165 EXTCOMMUNITY_LIST_STR
14166 "Extended Community list number (expanded)\n"
14167 "Specify expanded extcommunity-list\n"
14168 "Extended Community list name\n"
14169 "Specify community to reject\n"
14170 "Specify community to accept\n"
14171 "An ordered list as a regular-expression\n")
14172 {
14173 int style = EXTCOMMUNITY_LIST_EXPANDED;
14174 int direct = 0;
14175 char *cl_number_or_name = NULL;
14176
14177 int idx = 0;
14178 argv_find(argv, argc, "(100-500)", &idx);
14179 argv_find(argv, argc, "WORD", &idx);
14180 cl_number_or_name = argv[idx]->arg;
14181 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
14182 : COMMUNITY_DENY;
14183 argv_find(argv, argc, "LINE", &idx);
14184 char *str = argv_concat(argv, argc, idx);
14185
14186 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
14187 direct, style);
14188
14189 XFREE(MTYPE_TMP, str);
14190
14191 if (ret < 0) {
14192 community_list_perror(vty, ret);
14193 return CMD_WARNING_CONFIG_FAILED;
14194 }
14195
14196 return CMD_SUCCESS;
14197 }
14198
14199 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
14200 {
14201 struct community_entry *entry;
14202
14203 for (entry = list->head; entry; entry = entry->next) {
14204 if (entry == list->head) {
14205 if (all_digit(list->name))
14206 vty_out(vty, "Extended community %s list %s\n",
14207 entry->style == EXTCOMMUNITY_LIST_STANDARD
14208 ? "standard"
14209 : "(expanded) access",
14210 list->name);
14211 else
14212 vty_out(vty,
14213 "Named extended community %s list %s\n",
14214 entry->style == EXTCOMMUNITY_LIST_STANDARD
14215 ? "standard"
14216 : "expanded",
14217 list->name);
14218 }
14219 if (entry->any)
14220 vty_out(vty, " %s\n",
14221 community_direct_str(entry->direct));
14222 else
14223 vty_out(vty, " %s %s\n",
14224 community_direct_str(entry->direct),
14225 entry->style == EXTCOMMUNITY_LIST_STANDARD
14226 ? entry->u.ecom->str
14227 : entry->config);
14228 }
14229 }
14230
14231 DEFUN (show_ip_extcommunity_list,
14232 show_ip_extcommunity_list_cmd,
14233 "show ip extcommunity-list",
14234 SHOW_STR
14235 IP_STR
14236 "List extended-community list\n")
14237 {
14238 struct community_list *list;
14239 struct community_list_master *cm;
14240
14241 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14242 if (!cm)
14243 return CMD_SUCCESS;
14244
14245 for (list = cm->num.head; list; list = list->next)
14246 extcommunity_list_show(vty, list);
14247
14248 for (list = cm->str.head; list; list = list->next)
14249 extcommunity_list_show(vty, list);
14250
14251 return CMD_SUCCESS;
14252 }
14253
14254 DEFUN (show_ip_extcommunity_list_arg,
14255 show_ip_extcommunity_list_arg_cmd,
14256 "show ip extcommunity-list <(1-500)|WORD>",
14257 SHOW_STR
14258 IP_STR
14259 "List extended-community list\n"
14260 "Extcommunity-list number\n"
14261 "Extcommunity-list name\n")
14262 {
14263 int idx_comm_list = 3;
14264 struct community_list *list;
14265
14266 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
14267 EXTCOMMUNITY_LIST_MASTER);
14268 if (!list) {
14269 vty_out(vty, "%% Can't find extcommunity-list\n");
14270 return CMD_WARNING;
14271 }
14272
14273 extcommunity_list_show(vty, list);
14274
14275 return CMD_SUCCESS;
14276 }
14277
14278 /* Return configuration string of community-list entry. */
14279 static const char *community_list_config_str(struct community_entry *entry)
14280 {
14281 const char *str;
14282
14283 if (entry->any)
14284 str = "";
14285 else {
14286 if (entry->style == COMMUNITY_LIST_STANDARD)
14287 str = community_str(entry->u.com, false);
14288 else
14289 str = entry->config;
14290 }
14291 return str;
14292 }
14293
14294 /* Display community-list and extcommunity-list configuration. */
14295 static int community_list_config_write(struct vty *vty)
14296 {
14297 struct community_list *list;
14298 struct community_entry *entry;
14299 struct community_list_master *cm;
14300 int write = 0;
14301
14302 /* Community-list. */
14303 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
14304
14305 for (list = cm->num.head; list; list = list->next)
14306 for (entry = list->head; entry; entry = entry->next) {
14307 vty_out(vty, "ip community-list %s %s %s\n", list->name,
14308 community_direct_str(entry->direct),
14309 community_list_config_str(entry));
14310 write++;
14311 }
14312 for (list = cm->str.head; list; list = list->next)
14313 for (entry = list->head; entry; entry = entry->next) {
14314 vty_out(vty, "ip community-list %s %s %s %s\n",
14315 entry->style == COMMUNITY_LIST_STANDARD
14316 ? "standard"
14317 : "expanded",
14318 list->name, community_direct_str(entry->direct),
14319 community_list_config_str(entry));
14320 write++;
14321 }
14322
14323 /* Extcommunity-list. */
14324 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
14325
14326 for (list = cm->num.head; list; list = list->next)
14327 for (entry = list->head; entry; entry = entry->next) {
14328 vty_out(vty, "ip extcommunity-list %s %s %s\n",
14329 list->name, community_direct_str(entry->direct),
14330 community_list_config_str(entry));
14331 write++;
14332 }
14333 for (list = cm->str.head; list; list = list->next)
14334 for (entry = list->head; entry; entry = entry->next) {
14335 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
14336 entry->style == EXTCOMMUNITY_LIST_STANDARD
14337 ? "standard"
14338 : "expanded",
14339 list->name, community_direct_str(entry->direct),
14340 community_list_config_str(entry));
14341 write++;
14342 }
14343
14344
14345 /* lcommunity-list. */
14346 cm = community_list_master_lookup(bgp_clist,
14347 LARGE_COMMUNITY_LIST_MASTER);
14348
14349 for (list = cm->num.head; list; list = list->next)
14350 for (entry = list->head; entry; entry = entry->next) {
14351 vty_out(vty, "ip large-community-list %s %s %s\n",
14352 list->name, community_direct_str(entry->direct),
14353 community_list_config_str(entry));
14354 write++;
14355 }
14356 for (list = cm->str.head; list; list = list->next)
14357 for (entry = list->head; entry; entry = entry->next) {
14358 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14359 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14360 ? "standard"
14361 : "expanded",
14362 list->name, community_direct_str(entry->direct),
14363 community_list_config_str(entry));
14364 write++;
14365 }
14366
14367 return write;
14368 }
14369
14370 static struct cmd_node community_list_node = {
14371 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
14372 };
14373
14374 static void community_list_vty(void)
14375 {
14376 install_node(&community_list_node, community_list_config_write);
14377
14378 /* Community-list. */
14379 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14380 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14381 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14382 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14383 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14384 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14385
14386 /* Extcommunity-list. */
14387 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14388 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14389 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14390 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14391 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14392 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14393
14394 /* Large Community List */
14395 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14396 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14397 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14398 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14399 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14400 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14401 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14402 install_element(CONFIG_NODE,
14403 &no_ip_lcommunity_list_name_expanded_all_cmd);
14404 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14405 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14406 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14407 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14408 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14409 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
14410 }