]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
bgpd: new vpn-policy CLI
[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 default:
84 /* not expected */
85 return BGP_IPV4_NODE;
86 break;
87 }
88 break;
89 case AFI_IP6:
90 switch (safi) {
91 case SAFI_UNICAST:
92 return BGP_IPV6_NODE;
93 break;
94 case SAFI_MULTICAST:
95 return BGP_IPV6M_NODE;
96 break;
97 case SAFI_LABELED_UNICAST:
98 return BGP_IPV6L_NODE;
99 break;
100 case SAFI_MPLS_VPN:
101 return BGP_VPNV6_NODE;
102 break;
103 default:
104 /* not expected */
105 return BGP_IPV4_NODE;
106 break;
107 }
108 break;
109 case AFI_L2VPN:
110 return BGP_EVPN_NODE;
111 break;
112 case AFI_MAX:
113 // We should never be here but to clarify the switch statement..
114 return BGP_IPV4_NODE;
115 break;
116 }
117
118 // Impossible to happen
119 return BGP_IPV4_NODE;
120 }
121
122 /* Utility function to get address family from current node. */
123 afi_t bgp_node_afi(struct vty *vty)
124 {
125 afi_t afi;
126 switch (vty->node) {
127 case BGP_IPV6_NODE:
128 case BGP_IPV6M_NODE:
129 case BGP_IPV6L_NODE:
130 case BGP_VPNV6_NODE:
131 afi = AFI_IP6;
132 break;
133 case BGP_EVPN_NODE:
134 afi = AFI_L2VPN;
135 break;
136 default:
137 afi = AFI_IP;
138 break;
139 }
140 return afi;
141 }
142
143 /* Utility function to get subsequent address family from current
144 node. */
145 safi_t bgp_node_safi(struct vty *vty)
146 {
147 safi_t safi;
148 switch (vty->node) {
149 case BGP_VPNV4_NODE:
150 case BGP_VPNV6_NODE:
151 safi = SAFI_MPLS_VPN;
152 break;
153 case BGP_IPV4M_NODE:
154 case BGP_IPV6M_NODE:
155 safi = SAFI_MULTICAST;
156 break;
157 case BGP_EVPN_NODE:
158 safi = SAFI_EVPN;
159 break;
160 case BGP_IPV4L_NODE:
161 case BGP_IPV6L_NODE:
162 safi = SAFI_LABELED_UNICAST;
163 break;
164 default:
165 safi = SAFI_UNICAST;
166 break;
167 }
168 return safi;
169 }
170
171 /**
172 * Converts an AFI in string form to afi_t
173 *
174 * @param afi string, one of
175 * - "ipv4"
176 * - "ipv6"
177 * @return the corresponding afi_t
178 */
179 afi_t bgp_vty_afi_from_str(const char *afi_str)
180 {
181 afi_t afi = AFI_MAX; /* unknown */
182 if (strmatch(afi_str, "ipv4"))
183 afi = AFI_IP;
184 else if (strmatch(afi_str, "ipv6"))
185 afi = AFI_IP6;
186 return afi;
187 }
188
189 int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
190 afi_t *afi)
191 {
192 int ret = 0;
193 if (argv_find(argv, argc, "ipv4", index)) {
194 ret = 1;
195 if (afi)
196 *afi = AFI_IP;
197 } else if (argv_find(argv, argc, "ipv6", index)) {
198 ret = 1;
199 if (afi)
200 *afi = AFI_IP6;
201 }
202 return ret;
203 }
204
205 /* supports <unicast|multicast|vpn|labeled-unicast> */
206 safi_t bgp_vty_safi_from_str(const char *safi_str)
207 {
208 safi_t safi = SAFI_MAX; /* unknown */
209 if (strmatch(safi_str, "multicast"))
210 safi = SAFI_MULTICAST;
211 else if (strmatch(safi_str, "unicast"))
212 safi = SAFI_UNICAST;
213 else if (strmatch(safi_str, "vpn"))
214 safi = SAFI_MPLS_VPN;
215 else if (strmatch(safi_str, "labeled-unicast"))
216 safi = SAFI_LABELED_UNICAST;
217 return safi;
218 }
219
220 int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
221 safi_t *safi)
222 {
223 int ret = 0;
224 if (argv_find(argv, argc, "unicast", index)) {
225 ret = 1;
226 if (safi)
227 *safi = SAFI_UNICAST;
228 } else if (argv_find(argv, argc, "multicast", index)) {
229 ret = 1;
230 if (safi)
231 *safi = SAFI_MULTICAST;
232 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
233 ret = 1;
234 if (safi)
235 *safi = SAFI_LABELED_UNICAST;
236 } else if (argv_find(argv, argc, "vpn", index)) {
237 ret = 1;
238 if (safi)
239 *safi = SAFI_MPLS_VPN;
240 }
241 return ret;
242 }
243
244 /*
245 * bgp_vty_find_and_parse_afi_safi_bgp
246 *
247 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
248 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
249 * to appropriate values for the calling function. This is to allow the
250 * calling function to make decisions appropriate for the show command
251 * that is being parsed.
252 *
253 * The show commands are generally of the form:
254 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
255 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
256 *
257 * Since we use argv_find if the show command in particular doesn't have:
258 * [ip]
259 * [<view|vrf> VIEWVRFNAME]
260 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
261 * The command parsing should still be ok.
262 *
263 * vty -> The vty for the command so we can output some useful data in
264 * the event of a parse error in the vrf.
265 * argv -> The command tokens
266 * argc -> How many command tokens we have
267 * idx -> The current place in the command, generally should be 0 for this
268 * function
269 * afi -> The parsed afi if it was included in the show command, returned here
270 * safi -> The parsed safi if it was included in the show command, returned here
271 * bgp -> Pointer to the bgp data structure we need to fill in.
272 *
273 * The function returns the correct location in the parse tree for the
274 * last token found.
275 *
276 * Returns 0 for failure to parse correctly, else the idx position of where
277 * it found the last token.
278 */
279 int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
280 struct cmd_token **argv, int argc,
281 int *idx, afi_t *afi, safi_t *safi,
282 struct bgp **bgp)
283 {
284 char *vrf_name = NULL;
285
286 assert(afi);
287 assert(safi);
288 assert(bgp);
289
290 if (argv_find(argv, argc, "ip", idx))
291 *afi = AFI_IP;
292
293 if (argv_find(argv, argc, "view", idx)
294 || argv_find(argv, argc, "vrf", idx)) {
295 vrf_name = argv[*idx + 1]->arg;
296
297 if (strmatch(vrf_name, "all"))
298 *bgp = NULL;
299 else {
300 *bgp = bgp_lookup_by_name(vrf_name);
301 if (!*bgp) {
302 vty_out(vty,
303 "View/Vrf specified is unknown: %s\n",
304 vrf_name);
305 *idx = 0;
306 return 0;
307 }
308 }
309 } else {
310 *bgp = bgp_get_default();
311 if (!*bgp) {
312 vty_out(vty, "Unable to find default BGP instance\n");
313 *idx = 0;
314 return 0;
315 }
316 }
317
318 if (argv_find_and_parse_afi(argv, argc, idx, afi))
319 argv_find_and_parse_safi(argv, argc, idx, safi);
320
321 *idx += 1;
322 return *idx;
323 }
324
325 static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
326 {
327 struct interface *ifp = NULL;
328
329 if (su->sa.sa_family == AF_INET)
330 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
331 else if (su->sa.sa_family == AF_INET6)
332 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
333 su->sin6.sin6_scope_id,
334 bgp->vrf_id);
335
336 if (ifp)
337 return 1;
338
339 return 0;
340 }
341
342 /* Utility function for looking up peer from VTY. */
343 /* This is used only for configuration, so disallow if attempted on
344 * a dynamic neighbor.
345 */
346 static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
347 {
348 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
349 int ret;
350 union sockunion su;
351 struct peer *peer;
352
353 if (!bgp) {
354 return NULL;
355 }
356
357 ret = str2sockunion(ip_str, &su);
358 if (ret < 0) {
359 peer = peer_lookup_by_conf_if(bgp, ip_str);
360 if (!peer) {
361 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
362 == NULL) {
363 vty_out(vty,
364 "%% Malformed address or name: %s\n",
365 ip_str);
366 return NULL;
367 }
368 }
369 } else {
370 peer = peer_lookup(bgp, &su);
371 if (!peer) {
372 vty_out(vty,
373 "%% Specify remote-as or peer-group commands first\n");
374 return NULL;
375 }
376 if (peer_dynamic_neighbor(peer)) {
377 vty_out(vty,
378 "%% Operation not allowed on a dynamic neighbor\n");
379 return NULL;
380 }
381 }
382 return peer;
383 }
384
385 /* Utility function for looking up peer or peer group. */
386 /* This is used only for configuration, so disallow if attempted on
387 * a dynamic neighbor.
388 */
389 struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
390 {
391 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
392 int ret;
393 union sockunion su;
394 struct peer *peer = NULL;
395 struct peer_group *group = NULL;
396
397 if (!bgp) {
398 return NULL;
399 }
400
401 ret = str2sockunion(peer_str, &su);
402 if (ret == 0) {
403 /* IP address, locate peer. */
404 peer = peer_lookup(bgp, &su);
405 } else {
406 /* Not IP, could match either peer configured on interface or a
407 * group. */
408 peer = peer_lookup_by_conf_if(bgp, peer_str);
409 if (!peer)
410 group = peer_group_lookup(bgp, peer_str);
411 }
412
413 if (peer) {
414 if (peer_dynamic_neighbor(peer)) {
415 vty_out(vty,
416 "%% Operation not allowed on a dynamic neighbor\n");
417 return NULL;
418 }
419
420 return peer;
421 }
422
423 if (group)
424 return group->conf;
425
426 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
427
428 return NULL;
429 }
430
431 int bgp_vty_return(struct vty *vty, int ret)
432 {
433 const char *str = NULL;
434
435 switch (ret) {
436 case BGP_ERR_INVALID_VALUE:
437 str = "Invalid value";
438 break;
439 case BGP_ERR_INVALID_FLAG:
440 str = "Invalid flag";
441 break;
442 case BGP_ERR_PEER_GROUP_SHUTDOWN:
443 str = "Peer-group has been shutdown. Activate the peer-group first";
444 break;
445 case BGP_ERR_PEER_FLAG_CONFLICT:
446 str = "Can't set override-capability and strict-capability-match at the same time";
447 break;
448 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
449 str = "Specify remote-as or peer-group remote AS first";
450 break;
451 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
452 str = "Cannot change the peer-group. Deconfigure first";
453 break;
454 case BGP_ERR_PEER_GROUP_MISMATCH:
455 str = "Peer is not a member of this peer-group";
456 break;
457 case BGP_ERR_PEER_FILTER_CONFLICT:
458 str = "Prefix/distribute list can not co-exist";
459 break;
460 case BGP_ERR_NOT_INTERNAL_PEER:
461 str = "Invalid command. Not an internal neighbor";
462 break;
463 case BGP_ERR_REMOVE_PRIVATE_AS:
464 str = "remove-private-AS cannot be configured for IBGP peers";
465 break;
466 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
467 str = "Local-AS allowed only for EBGP peers";
468 break;
469 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
470 str = "Cannot have local-as same as BGP AS number";
471 break;
472 case BGP_ERR_TCPSIG_FAILED:
473 str = "Error while applying TCP-Sig to session(s)";
474 break;
475 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
476 str = "ebgp-multihop and ttl-security cannot be configured together";
477 break;
478 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
479 str = "ttl-security only allowed for EBGP peers";
480 break;
481 case BGP_ERR_AS_OVERRIDE:
482 str = "as-override cannot be configured for IBGP peers";
483 break;
484 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
485 str = "Invalid limit for number of dynamic neighbors";
486 break;
487 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
488 str = "Dynamic neighbor listen range already exists";
489 break;
490 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
491 str = "Operation not allowed on a dynamic neighbor";
492 break;
493 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
494 str = "Operation not allowed on a directly connected neighbor";
495 break;
496 case BGP_ERR_PEER_SAFI_CONFLICT:
497 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
498 break;
499 }
500 if (str) {
501 vty_out(vty, "%% %s\n", str);
502 return CMD_WARNING_CONFIG_FAILED;
503 }
504 return CMD_SUCCESS;
505 }
506
507 /* BGP clear sort. */
508 enum clear_sort {
509 clear_all,
510 clear_peer,
511 clear_group,
512 clear_external,
513 clear_as
514 };
515
516 static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
517 safi_t safi, int error)
518 {
519 switch (error) {
520 case BGP_ERR_AF_UNCONFIGURED:
521 vty_out(vty,
522 "%%BGP: Enable %s address family for the neighbor %s\n",
523 afi_safi_print(afi, safi), peer->host);
524 break;
525 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
526 vty_out(vty,
527 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
528 peer->host);
529 break;
530 default:
531 break;
532 }
533 }
534
535 /* `clear ip bgp' functions. */
536 static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
537 enum clear_sort sort, enum bgp_clear_type stype,
538 const char *arg)
539 {
540 int ret;
541 struct peer *peer;
542 struct listnode *node, *nnode;
543
544 /* Clear all neighbors. */
545 /*
546 * Pass along pointer to next node to peer_clear() when walking all
547 * nodes
548 * on the BGP instance as that may get freed if it is a doppelganger
549 */
550 if (sort == clear_all) {
551 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
552 if (stype == BGP_CLEAR_SOFT_NONE)
553 ret = peer_clear(peer, &nnode);
554 else if (peer->afc[afi][safi])
555 ret = peer_clear_soft(peer, afi, safi, stype);
556 else
557 ret = 0;
558
559 if (ret < 0)
560 bgp_clear_vty_error(vty, peer, afi, safi, ret);
561 }
562
563 /* This is to apply read-only mode on this clear. */
564 if (stype == BGP_CLEAR_SOFT_NONE)
565 bgp->update_delay_over = 0;
566
567 return CMD_SUCCESS;
568 }
569
570 /* Clear specified neighbors. */
571 if (sort == clear_peer) {
572 union sockunion su;
573 int ret;
574
575 /* Make sockunion for lookup. */
576 ret = str2sockunion(arg, &su);
577 if (ret < 0) {
578 peer = peer_lookup_by_conf_if(bgp, arg);
579 if (!peer) {
580 peer = peer_lookup_by_hostname(bgp, arg);
581 if (!peer) {
582 vty_out(vty,
583 "Malformed address or name: %s\n",
584 arg);
585 return CMD_WARNING;
586 }
587 }
588 } else {
589 peer = peer_lookup(bgp, &su);
590 if (!peer) {
591 vty_out(vty,
592 "%%BGP: Unknown neighbor - \"%s\"\n",
593 arg);
594 return CMD_WARNING;
595 }
596 }
597
598 if (stype == BGP_CLEAR_SOFT_NONE)
599 ret = peer_clear(peer, NULL);
600 else
601 ret = peer_clear_soft(peer, afi, safi, stype);
602
603 if (ret < 0)
604 bgp_clear_vty_error(vty, peer, afi, safi, ret);
605
606 return CMD_SUCCESS;
607 }
608
609 /* Clear all peer-group members. */
610 if (sort == clear_group) {
611 struct peer_group *group;
612
613 group = peer_group_lookup(bgp, arg);
614 if (!group) {
615 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
616 return CMD_WARNING;
617 }
618
619 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
620 if (stype == BGP_CLEAR_SOFT_NONE) {
621 peer_clear(peer, NULL);
622 continue;
623 }
624
625 if (!peer->afc[afi][safi])
626 continue;
627
628 ret = peer_clear_soft(peer, afi, safi, stype);
629
630 if (ret < 0)
631 bgp_clear_vty_error(vty, peer, afi, safi, ret);
632 }
633 return CMD_SUCCESS;
634 }
635
636 if (sort == clear_external) {
637 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
638 if (peer->sort == BGP_PEER_IBGP)
639 continue;
640
641 if (stype == BGP_CLEAR_SOFT_NONE)
642 ret = peer_clear(peer, &nnode);
643 else
644 ret = peer_clear_soft(peer, afi, safi, stype);
645
646 if (ret < 0)
647 bgp_clear_vty_error(vty, peer, afi, safi, ret);
648 }
649 return CMD_SUCCESS;
650 }
651
652 if (sort == clear_as) {
653 as_t as;
654 int find = 0;
655
656 as = strtoul(arg, NULL, 10);
657
658 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
659 if (peer->as != as)
660 continue;
661
662 find = 1;
663 if (stype == BGP_CLEAR_SOFT_NONE)
664 ret = peer_clear(peer, &nnode);
665 else
666 ret = peer_clear_soft(peer, afi, safi, stype);
667
668 if (ret < 0)
669 bgp_clear_vty_error(vty, peer, afi, safi, ret);
670 }
671 if (!find)
672 vty_out(vty,
673 "%%BGP: No peer is configured with AS %s\n",
674 arg);
675 return CMD_SUCCESS;
676 }
677
678 return CMD_SUCCESS;
679 }
680
681 static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
682 safi_t safi, enum clear_sort sort,
683 enum bgp_clear_type stype, const char *arg)
684 {
685 struct bgp *bgp;
686
687 /* BGP structure lookup. */
688 if (name) {
689 bgp = bgp_lookup_by_name(name);
690 if (bgp == NULL) {
691 vty_out(vty, "Can't find BGP instance %s\n", name);
692 return CMD_WARNING;
693 }
694 } else {
695 bgp = bgp_get_default();
696 if (bgp == NULL) {
697 vty_out(vty, "No BGP process is configured\n");
698 return CMD_WARNING;
699 }
700 }
701
702 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
703 }
704
705 /* clear soft inbound */
706 static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
707 {
708 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
709 BGP_CLEAR_SOFT_IN, NULL);
710 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
711 BGP_CLEAR_SOFT_IN, NULL);
712 }
713
714 /* clear soft outbound */
715 static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
716 {
717 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
718 BGP_CLEAR_SOFT_OUT, NULL);
719 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
720 BGP_CLEAR_SOFT_OUT, NULL);
721 }
722
723
724 #ifndef VTYSH_EXTRACT_PL
725 #include "bgpd/bgp_vty_clippy.c"
726 #endif
727
728 /* BGP global configuration. */
729
730 DEFUN (bgp_multiple_instance_func,
731 bgp_multiple_instance_cmd,
732 "bgp multiple-instance",
733 BGP_STR
734 "Enable bgp multiple instance\n")
735 {
736 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
737 return CMD_SUCCESS;
738 }
739
740 DEFUN (no_bgp_multiple_instance,
741 no_bgp_multiple_instance_cmd,
742 "no bgp multiple-instance",
743 NO_STR
744 BGP_STR
745 "BGP multiple instance\n")
746 {
747 int ret;
748
749 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
750 if (ret < 0) {
751 vty_out(vty, "%% There are more than two BGP instances\n");
752 return CMD_WARNING_CONFIG_FAILED;
753 }
754 return CMD_SUCCESS;
755 }
756
757 DEFUN (bgp_config_type,
758 bgp_config_type_cmd,
759 "bgp config-type <cisco|zebra>",
760 BGP_STR
761 "Configuration type\n"
762 "cisco\n"
763 "zebra\n")
764 {
765 int idx = 0;
766 if (argv_find(argv, argc, "cisco", &idx))
767 bgp_option_set(BGP_OPT_CONFIG_CISCO);
768 else
769 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
770
771 return CMD_SUCCESS;
772 }
773
774 DEFUN (no_bgp_config_type,
775 no_bgp_config_type_cmd,
776 "no bgp config-type [<cisco|zebra>]",
777 NO_STR
778 BGP_STR
779 "Display configuration type\n"
780 "cisco\n"
781 "zebra\n")
782 {
783 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
784 return CMD_SUCCESS;
785 }
786
787
788 DEFUN (no_synchronization,
789 no_synchronization_cmd,
790 "no synchronization",
791 NO_STR
792 "Perform IGP synchronization\n")
793 {
794 return CMD_SUCCESS;
795 }
796
797 DEFUN (no_auto_summary,
798 no_auto_summary_cmd,
799 "no auto-summary",
800 NO_STR
801 "Enable automatic network number summarization\n")
802 {
803 return CMD_SUCCESS;
804 }
805
806 /* "router bgp" commands. */
807 DEFUN_NOSH (router_bgp,
808 router_bgp_cmd,
809 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
810 ROUTER_STR
811 BGP_STR
812 AS_STR
813 BGP_INSTANCE_HELP_STR)
814 {
815 int idx_asn = 2;
816 int idx_view_vrf = 3;
817 int idx_vrf = 4;
818 int ret;
819 as_t as;
820 struct bgp *bgp;
821 const char *name = NULL;
822 enum bgp_instance_type inst_type;
823
824 // "router bgp" without an ASN
825 if (argc == 2) {
826 // Pending: Make VRF option available for ASN less config
827 bgp = bgp_get_default();
828
829 if (bgp == NULL) {
830 vty_out(vty, "%% No BGP process is configured\n");
831 return CMD_WARNING_CONFIG_FAILED;
832 }
833
834 if (listcount(bm->bgp) > 1) {
835 vty_out(vty, "%% Please specify ASN and VRF\n");
836 return CMD_WARNING_CONFIG_FAILED;
837 }
838 }
839
840 // "router bgp X"
841 else {
842 as = strtoul(argv[idx_asn]->arg, NULL, 10);
843
844 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
845 if (argc > 3) {
846 name = argv[idx_vrf]->arg;
847
848 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
849 inst_type = BGP_INSTANCE_TYPE_VRF;
850 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
851 inst_type = BGP_INSTANCE_TYPE_VIEW;
852 }
853
854 ret = bgp_get(&bgp, &as, name, inst_type);
855 switch (ret) {
856 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
857 vty_out(vty,
858 "Please specify 'bgp multiple-instance' first\n");
859 return CMD_WARNING_CONFIG_FAILED;
860 case BGP_ERR_AS_MISMATCH:
861 vty_out(vty, "BGP is already running; AS is %u\n", as);
862 return CMD_WARNING_CONFIG_FAILED;
863 case BGP_ERR_INSTANCE_MISMATCH:
864 vty_out(vty,
865 "BGP instance name and AS number mismatch\n");
866 vty_out(vty,
867 "BGP instance is already running; AS is %u\n",
868 as);
869 return CMD_WARNING_CONFIG_FAILED;
870 }
871
872 /* Pending: handle when user tries to change a view to vrf n vv.
873 */
874 }
875
876 /* unset the auto created flag as the user config is now present */
877 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
878 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
879
880 return CMD_SUCCESS;
881 }
882
883 /* "no router bgp" commands. */
884 DEFUN (no_router_bgp,
885 no_router_bgp_cmd,
886 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
887 NO_STR
888 ROUTER_STR
889 BGP_STR
890 AS_STR
891 BGP_INSTANCE_HELP_STR)
892 {
893 int idx_asn = 3;
894 int idx_vrf = 5;
895 as_t as;
896 struct bgp *bgp;
897 const char *name = NULL;
898
899 // "no router bgp" without an ASN
900 if (argc == 3) {
901 // Pending: Make VRF option available for ASN less config
902 bgp = bgp_get_default();
903
904 if (bgp == NULL) {
905 vty_out(vty, "%% No BGP process is configured\n");
906 return CMD_WARNING_CONFIG_FAILED;
907 }
908
909 if (listcount(bm->bgp) > 1) {
910 vty_out(vty, "%% Please specify ASN and VRF\n");
911 return CMD_WARNING_CONFIG_FAILED;
912 }
913
914 if (bgp->l3vni) {
915 vty_out(vty, "%% Please unconfigure l3vni %u",
916 bgp->l3vni);
917 return CMD_WARNING_CONFIG_FAILED;
918 }
919 } else {
920 as = strtoul(argv[idx_asn]->arg, NULL, 10);
921
922 if (argc > 4)
923 name = argv[idx_vrf]->arg;
924
925 /* Lookup bgp structure. */
926 bgp = bgp_lookup(as, name);
927 if (!bgp) {
928 vty_out(vty, "%% Can't find BGP instance\n");
929 return CMD_WARNING_CONFIG_FAILED;
930 }
931
932 if (bgp->l3vni) {
933 vty_out(vty, "%% Please unconfigure l3vni %u",
934 bgp->l3vni);
935 return CMD_WARNING_CONFIG_FAILED;
936 }
937 }
938
939 bgp_delete(bgp);
940
941 return CMD_SUCCESS;
942 }
943
944
945 /* BGP router-id. */
946
947 DEFPY (bgp_router_id,
948 bgp_router_id_cmd,
949 "bgp router-id A.B.C.D",
950 BGP_STR
951 "Override configured router identifier\n"
952 "Manually configured router identifier\n")
953 {
954 VTY_DECLVAR_CONTEXT(bgp, bgp);
955 bgp_router_id_static_set(bgp, router_id);
956 return CMD_SUCCESS;
957 }
958
959 DEFPY (no_bgp_router_id,
960 no_bgp_router_id_cmd,
961 "no bgp router-id [A.B.C.D]",
962 NO_STR
963 BGP_STR
964 "Override configured router identifier\n"
965 "Manually configured router identifier\n")
966 {
967 VTY_DECLVAR_CONTEXT(bgp, bgp);
968
969 if (router_id_str) {
970 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
971 vty_out(vty, "%% BGP router-id doesn't match\n");
972 return CMD_WARNING_CONFIG_FAILED;
973 }
974 }
975
976 router_id.s_addr = 0;
977 bgp_router_id_static_set(bgp, router_id);
978
979 return CMD_SUCCESS;
980 }
981
982
983 /* BGP Cluster ID. */
984 DEFUN (bgp_cluster_id,
985 bgp_cluster_id_cmd,
986 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
987 BGP_STR
988 "Configure Route-Reflector Cluster-id\n"
989 "Route-Reflector Cluster-id in IP address format\n"
990 "Route-Reflector Cluster-id as 32 bit quantity\n")
991 {
992 VTY_DECLVAR_CONTEXT(bgp, bgp);
993 int idx_ipv4 = 2;
994 int ret;
995 struct in_addr cluster;
996
997 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
998 if (!ret) {
999 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1000 return CMD_WARNING_CONFIG_FAILED;
1001 }
1002
1003 bgp_cluster_id_set(bgp, &cluster);
1004 bgp_clear_star_soft_out(vty, bgp->name);
1005
1006 return CMD_SUCCESS;
1007 }
1008
1009 DEFUN (no_bgp_cluster_id,
1010 no_bgp_cluster_id_cmd,
1011 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1012 NO_STR
1013 BGP_STR
1014 "Configure Route-Reflector Cluster-id\n"
1015 "Route-Reflector Cluster-id in IP address format\n"
1016 "Route-Reflector Cluster-id as 32 bit quantity\n")
1017 {
1018 VTY_DECLVAR_CONTEXT(bgp, bgp);
1019 bgp_cluster_id_unset(bgp);
1020 bgp_clear_star_soft_out(vty, bgp->name);
1021
1022 return CMD_SUCCESS;
1023 }
1024
1025 DEFUN (bgp_confederation_identifier,
1026 bgp_confederation_identifier_cmd,
1027 "bgp confederation identifier (1-4294967295)",
1028 "BGP specific commands\n"
1029 "AS confederation parameters\n"
1030 "AS number\n"
1031 "Set routing domain confederation AS\n")
1032 {
1033 VTY_DECLVAR_CONTEXT(bgp, bgp);
1034 int idx_number = 3;
1035 as_t as;
1036
1037 as = strtoul(argv[idx_number]->arg, NULL, 10);
1038
1039 bgp_confederation_id_set(bgp, as);
1040
1041 return CMD_SUCCESS;
1042 }
1043
1044 DEFUN (no_bgp_confederation_identifier,
1045 no_bgp_confederation_identifier_cmd,
1046 "no bgp confederation identifier [(1-4294967295)]",
1047 NO_STR
1048 "BGP specific commands\n"
1049 "AS confederation parameters\n"
1050 "AS number\n"
1051 "Set routing domain confederation AS\n")
1052 {
1053 VTY_DECLVAR_CONTEXT(bgp, bgp);
1054 bgp_confederation_id_unset(bgp);
1055
1056 return CMD_SUCCESS;
1057 }
1058
1059 DEFUN (bgp_confederation_peers,
1060 bgp_confederation_peers_cmd,
1061 "bgp confederation peers (1-4294967295)...",
1062 "BGP specific commands\n"
1063 "AS confederation parameters\n"
1064 "Peer ASs in BGP confederation\n"
1065 AS_STR)
1066 {
1067 VTY_DECLVAR_CONTEXT(bgp, bgp);
1068 int idx_asn = 3;
1069 as_t as;
1070 int i;
1071
1072 for (i = idx_asn; i < argc; i++) {
1073 as = strtoul(argv[i]->arg, NULL, 10);
1074
1075 if (bgp->as == as) {
1076 vty_out(vty,
1077 "%% Local member-AS not allowed in confed peer list\n");
1078 continue;
1079 }
1080
1081 bgp_confederation_peers_add(bgp, as);
1082 }
1083 return CMD_SUCCESS;
1084 }
1085
1086 DEFUN (no_bgp_confederation_peers,
1087 no_bgp_confederation_peers_cmd,
1088 "no bgp confederation peers (1-4294967295)...",
1089 NO_STR
1090 "BGP specific commands\n"
1091 "AS confederation parameters\n"
1092 "Peer ASs in BGP confederation\n"
1093 AS_STR)
1094 {
1095 VTY_DECLVAR_CONTEXT(bgp, bgp);
1096 int idx_asn = 4;
1097 as_t as;
1098 int i;
1099
1100 for (i = idx_asn; i < argc; i++) {
1101 as = strtoul(argv[i]->arg, NULL, 10);
1102
1103 bgp_confederation_peers_remove(bgp, as);
1104 }
1105 return CMD_SUCCESS;
1106 }
1107
1108 /**
1109 * Central routine for maximum-paths configuration.
1110 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1111 * @set: 1 for setting values, 0 for removing the max-paths config.
1112 */
1113 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1114 const char *mpaths, u_int16_t options,
1115 int set)
1116 {
1117 VTY_DECLVAR_CONTEXT(bgp, bgp);
1118 u_int16_t maxpaths = 0;
1119 int ret;
1120 afi_t afi;
1121 safi_t safi;
1122
1123 afi = bgp_node_afi(vty);
1124 safi = bgp_node_safi(vty);
1125
1126 if (set) {
1127 maxpaths = strtol(mpaths, NULL, 10);
1128 if (maxpaths > multipath_num) {
1129 vty_out(vty,
1130 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1131 maxpaths, multipath_num);
1132 return CMD_WARNING_CONFIG_FAILED;
1133 }
1134 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1135 options);
1136 } else
1137 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1138
1139 if (ret < 0) {
1140 vty_out(vty,
1141 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1142 (set == 1) ? "" : "un",
1143 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1144 maxpaths, afi, safi);
1145 return CMD_WARNING_CONFIG_FAILED;
1146 }
1147
1148 bgp_recalculate_all_bestpaths(bgp);
1149
1150 return CMD_SUCCESS;
1151 }
1152
1153 DEFUN (bgp_maxmed_admin,
1154 bgp_maxmed_admin_cmd,
1155 "bgp max-med administrative ",
1156 BGP_STR
1157 "Advertise routes with max-med\n"
1158 "Administratively applied, for an indefinite period\n")
1159 {
1160 VTY_DECLVAR_CONTEXT(bgp, bgp);
1161
1162 bgp->v_maxmed_admin = 1;
1163 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1164
1165 bgp_maxmed_update(bgp);
1166
1167 return CMD_SUCCESS;
1168 }
1169
1170 DEFUN (bgp_maxmed_admin_medv,
1171 bgp_maxmed_admin_medv_cmd,
1172 "bgp max-med administrative (0-4294967295)",
1173 BGP_STR
1174 "Advertise routes with max-med\n"
1175 "Administratively applied, for an indefinite period\n"
1176 "Max MED value to be used\n")
1177 {
1178 VTY_DECLVAR_CONTEXT(bgp, bgp);
1179 int idx_number = 3;
1180
1181 bgp->v_maxmed_admin = 1;
1182 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1183
1184 bgp_maxmed_update(bgp);
1185
1186 return CMD_SUCCESS;
1187 }
1188
1189 DEFUN (no_bgp_maxmed_admin,
1190 no_bgp_maxmed_admin_cmd,
1191 "no bgp max-med administrative [(0-4294967295)]",
1192 NO_STR
1193 BGP_STR
1194 "Advertise routes with max-med\n"
1195 "Administratively applied, for an indefinite period\n"
1196 "Max MED value to be used\n")
1197 {
1198 VTY_DECLVAR_CONTEXT(bgp, bgp);
1199 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1200 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1201 bgp_maxmed_update(bgp);
1202
1203 return CMD_SUCCESS;
1204 }
1205
1206 DEFUN (bgp_maxmed_onstartup,
1207 bgp_maxmed_onstartup_cmd,
1208 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1209 BGP_STR
1210 "Advertise routes with max-med\n"
1211 "Effective on a startup\n"
1212 "Time (seconds) period for max-med\n"
1213 "Max MED value to be used\n")
1214 {
1215 VTY_DECLVAR_CONTEXT(bgp, bgp);
1216 int idx = 0;
1217
1218 argv_find(argv, argc, "(5-86400)", &idx);
1219 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1220 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1221 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1222 else
1223 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1224
1225 bgp_maxmed_update(bgp);
1226
1227 return CMD_SUCCESS;
1228 }
1229
1230 DEFUN (no_bgp_maxmed_onstartup,
1231 no_bgp_maxmed_onstartup_cmd,
1232 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1233 NO_STR
1234 BGP_STR
1235 "Advertise routes with max-med\n"
1236 "Effective on a startup\n"
1237 "Time (seconds) period for max-med\n"
1238 "Max MED value to be used\n")
1239 {
1240 VTY_DECLVAR_CONTEXT(bgp, bgp);
1241
1242 /* Cancel max-med onstartup if its on */
1243 if (bgp->t_maxmed_onstartup) {
1244 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1245 bgp->maxmed_onstartup_over = 1;
1246 }
1247
1248 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1249 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1250
1251 bgp_maxmed_update(bgp);
1252
1253 return CMD_SUCCESS;
1254 }
1255
1256 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1257 const char *wait)
1258 {
1259 VTY_DECLVAR_CONTEXT(bgp, bgp);
1260 u_int16_t update_delay;
1261 u_int16_t establish_wait;
1262
1263 update_delay = strtoul(delay, NULL, 10);
1264
1265 if (!wait) /* update-delay <delay> */
1266 {
1267 bgp->v_update_delay = update_delay;
1268 bgp->v_establish_wait = bgp->v_update_delay;
1269 return CMD_SUCCESS;
1270 }
1271
1272 /* update-delay <delay> <establish-wait> */
1273 establish_wait = atoi(wait);
1274 if (update_delay < establish_wait) {
1275 vty_out(vty,
1276 "%%Failed: update-delay less than the establish-wait!\n");
1277 return CMD_WARNING_CONFIG_FAILED;
1278 }
1279
1280 bgp->v_update_delay = update_delay;
1281 bgp->v_establish_wait = establish_wait;
1282
1283 return CMD_SUCCESS;
1284 }
1285
1286 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1287 {
1288 VTY_DECLVAR_CONTEXT(bgp, bgp);
1289
1290 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1291 bgp->v_establish_wait = bgp->v_update_delay;
1292
1293 return CMD_SUCCESS;
1294 }
1295
1296 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1297 {
1298 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1299 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1300 if (bgp->v_update_delay != bgp->v_establish_wait)
1301 vty_out(vty, " %d", bgp->v_establish_wait);
1302 vty_out(vty, "\n");
1303 }
1304 }
1305
1306
1307 /* Update-delay configuration */
1308 DEFUN (bgp_update_delay,
1309 bgp_update_delay_cmd,
1310 "update-delay (0-3600)",
1311 "Force initial delay for best-path and updates\n"
1312 "Seconds\n")
1313 {
1314 int idx_number = 1;
1315 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1316 }
1317
1318 DEFUN (bgp_update_delay_establish_wait,
1319 bgp_update_delay_establish_wait_cmd,
1320 "update-delay (0-3600) (1-3600)",
1321 "Force initial delay for best-path and updates\n"
1322 "Seconds\n"
1323 "Seconds\n")
1324 {
1325 int idx_number = 1;
1326 int idx_number_2 = 2;
1327 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1328 argv[idx_number_2]->arg);
1329 }
1330
1331 /* Update-delay deconfiguration */
1332 DEFUN (no_bgp_update_delay,
1333 no_bgp_update_delay_cmd,
1334 "no update-delay [(0-3600) [(1-3600)]]",
1335 NO_STR
1336 "Force initial delay for best-path and updates\n"
1337 "Seconds\n"
1338 "Seconds\n")
1339 {
1340 return bgp_update_delay_deconfig_vty(vty);
1341 }
1342
1343
1344 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1345 char set)
1346 {
1347 VTY_DECLVAR_CONTEXT(bgp, bgp);
1348
1349 if (set) {
1350 uint32_t quanta = strtoul(num, NULL, 10);
1351 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1352 memory_order_relaxed);
1353 } else {
1354 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1355 memory_order_relaxed);
1356 }
1357
1358 return CMD_SUCCESS;
1359 }
1360
1361 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1362 char set)
1363 {
1364 VTY_DECLVAR_CONTEXT(bgp, bgp);
1365
1366 if (set) {
1367 uint32_t quanta = strtoul(num, NULL, 10);
1368 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1369 memory_order_relaxed);
1370 } else {
1371 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1372 memory_order_relaxed);
1373 }
1374
1375 return CMD_SUCCESS;
1376 }
1377
1378 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1379 {
1380 uint32_t quanta =
1381 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1382 if (quanta != BGP_WRITE_PACKET_MAX)
1383 vty_out(vty, " write-quanta %d\n", quanta);
1384 }
1385
1386 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1387 {
1388 uint32_t quanta =
1389 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1390 if (quanta != BGP_READ_PACKET_MAX)
1391 vty_out(vty, " read-quanta %d\n", quanta);
1392 }
1393
1394 /* Packet quanta configuration */
1395 DEFUN (bgp_wpkt_quanta,
1396 bgp_wpkt_quanta_cmd,
1397 "write-quanta (1-10)",
1398 "How many packets to write to peer socket per run\n"
1399 "Number of packets\n")
1400 {
1401 int idx_number = 1;
1402 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1403 }
1404
1405 DEFUN (no_bgp_wpkt_quanta,
1406 no_bgp_wpkt_quanta_cmd,
1407 "no write-quanta (1-10)",
1408 NO_STR
1409 "How many packets to write to peer socket per I/O cycle\n"
1410 "Number of packets\n")
1411 {
1412 int idx_number = 2;
1413 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1414 }
1415
1416 DEFUN (bgp_rpkt_quanta,
1417 bgp_rpkt_quanta_cmd,
1418 "read-quanta (1-10)",
1419 "How many packets to read from peer socket per I/O cycle\n"
1420 "Number of packets\n")
1421 {
1422 int idx_number = 1;
1423 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1424 }
1425
1426 DEFUN (no_bgp_rpkt_quanta,
1427 no_bgp_rpkt_quanta_cmd,
1428 "no read-quanta (1-10)",
1429 NO_STR
1430 "How many packets to read from peer socket per I/O cycle\n"
1431 "Number of packets\n")
1432 {
1433 int idx_number = 2;
1434 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1435 }
1436
1437 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1438 {
1439 if (!bgp->heuristic_coalesce)
1440 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1441 }
1442
1443
1444 DEFUN (bgp_coalesce_time,
1445 bgp_coalesce_time_cmd,
1446 "coalesce-time (0-4294967295)",
1447 "Subgroup coalesce timer\n"
1448 "Subgroup coalesce timer value (in ms)\n")
1449 {
1450 VTY_DECLVAR_CONTEXT(bgp, bgp);
1451
1452 int idx = 0;
1453 argv_find(argv, argc, "(0-4294967295)", &idx);
1454 bgp->heuristic_coalesce = false;
1455 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1456 return CMD_SUCCESS;
1457 }
1458
1459 DEFUN (no_bgp_coalesce_time,
1460 no_bgp_coalesce_time_cmd,
1461 "no coalesce-time (0-4294967295)",
1462 NO_STR
1463 "Subgroup coalesce timer\n"
1464 "Subgroup coalesce timer value (in ms)\n")
1465 {
1466 VTY_DECLVAR_CONTEXT(bgp, bgp);
1467
1468 bgp->heuristic_coalesce = true;
1469 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1470 return CMD_SUCCESS;
1471 }
1472
1473 /* Maximum-paths configuration */
1474 DEFUN (bgp_maxpaths,
1475 bgp_maxpaths_cmd,
1476 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1477 "Forward packets over multiple paths\n"
1478 "Number of paths\n")
1479 {
1480 int idx_number = 1;
1481 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1482 argv[idx_number]->arg, 0, 1);
1483 }
1484
1485 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1486 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1487 "Forward packets over multiple paths\n"
1488 "Number of paths\n")
1489
1490 DEFUN (bgp_maxpaths_ibgp,
1491 bgp_maxpaths_ibgp_cmd,
1492 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1493 "Forward packets over multiple paths\n"
1494 "iBGP-multipath\n"
1495 "Number of paths\n")
1496 {
1497 int idx_number = 2;
1498 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1499 argv[idx_number]->arg, 0, 1);
1500 }
1501
1502 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1503 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1504 "Forward packets over multiple paths\n"
1505 "iBGP-multipath\n"
1506 "Number of paths\n")
1507
1508 DEFUN (bgp_maxpaths_ibgp_cluster,
1509 bgp_maxpaths_ibgp_cluster_cmd,
1510 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1511 "Forward packets over multiple paths\n"
1512 "iBGP-multipath\n"
1513 "Number of paths\n"
1514 "Match the cluster length\n")
1515 {
1516 int idx_number = 2;
1517 return bgp_maxpaths_config_vty(
1518 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1519 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1520 }
1521
1522 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1523 "maximum-paths ibgp " CMD_RANGE_STR(
1524 1, MULTIPATH_NUM) " equal-cluster-length",
1525 "Forward packets over multiple paths\n"
1526 "iBGP-multipath\n"
1527 "Number of paths\n"
1528 "Match the cluster length\n")
1529
1530 DEFUN (no_bgp_maxpaths,
1531 no_bgp_maxpaths_cmd,
1532 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1533 NO_STR
1534 "Forward packets over multiple paths\n"
1535 "Number of paths\n")
1536 {
1537 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1538 }
1539
1540 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1541 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1542 "Forward packets over multiple paths\n"
1543 "Number of paths\n")
1544
1545 DEFUN (no_bgp_maxpaths_ibgp,
1546 no_bgp_maxpaths_ibgp_cmd,
1547 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1548 NO_STR
1549 "Forward packets over multiple paths\n"
1550 "iBGP-multipath\n"
1551 "Number of paths\n"
1552 "Match the cluster length\n")
1553 {
1554 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1555 }
1556
1557 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1558 "no maximum-paths ibgp [" CMD_RANGE_STR(
1559 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1560 NO_STR
1561 "Forward packets over multiple paths\n"
1562 "iBGP-multipath\n"
1563 "Number of paths\n"
1564 "Match the cluster length\n")
1565
1566 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1567 safi_t safi)
1568 {
1569 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1570 vty_out(vty, " maximum-paths %d\n",
1571 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1572 }
1573
1574 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1575 vty_out(vty, " maximum-paths ibgp %d",
1576 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1577 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1578 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1579 vty_out(vty, " equal-cluster-length");
1580 vty_out(vty, "\n");
1581 }
1582 }
1583
1584 /* BGP timers. */
1585
1586 DEFUN (bgp_timers,
1587 bgp_timers_cmd,
1588 "timers bgp (0-65535) (0-65535)",
1589 "Adjust routing timers\n"
1590 "BGP timers\n"
1591 "Keepalive interval\n"
1592 "Holdtime\n")
1593 {
1594 VTY_DECLVAR_CONTEXT(bgp, bgp);
1595 int idx_number = 2;
1596 int idx_number_2 = 3;
1597 unsigned long keepalive = 0;
1598 unsigned long holdtime = 0;
1599
1600 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1601 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1602
1603 /* Holdtime value check. */
1604 if (holdtime < 3 && holdtime != 0) {
1605 vty_out(vty,
1606 "%% hold time value must be either 0 or greater than 3\n");
1607 return CMD_WARNING_CONFIG_FAILED;
1608 }
1609
1610 bgp_timers_set(bgp, keepalive, holdtime);
1611
1612 return CMD_SUCCESS;
1613 }
1614
1615 DEFUN (no_bgp_timers,
1616 no_bgp_timers_cmd,
1617 "no timers bgp [(0-65535) (0-65535)]",
1618 NO_STR
1619 "Adjust routing timers\n"
1620 "BGP timers\n"
1621 "Keepalive interval\n"
1622 "Holdtime\n")
1623 {
1624 VTY_DECLVAR_CONTEXT(bgp, bgp);
1625 bgp_timers_unset(bgp);
1626
1627 return CMD_SUCCESS;
1628 }
1629
1630
1631 DEFUN (bgp_client_to_client_reflection,
1632 bgp_client_to_client_reflection_cmd,
1633 "bgp client-to-client reflection",
1634 "BGP specific commands\n"
1635 "Configure client to client route reflection\n"
1636 "reflection of routes allowed\n")
1637 {
1638 VTY_DECLVAR_CONTEXT(bgp, bgp);
1639 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1640 bgp_clear_star_soft_out(vty, bgp->name);
1641
1642 return CMD_SUCCESS;
1643 }
1644
1645 DEFUN (no_bgp_client_to_client_reflection,
1646 no_bgp_client_to_client_reflection_cmd,
1647 "no bgp client-to-client reflection",
1648 NO_STR
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_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1655 bgp_clear_star_soft_out(vty, bgp->name);
1656
1657 return CMD_SUCCESS;
1658 }
1659
1660 /* "bgp always-compare-med" configuration. */
1661 DEFUN (bgp_always_compare_med,
1662 bgp_always_compare_med_cmd,
1663 "bgp always-compare-med",
1664 "BGP specific commands\n"
1665 "Allow comparing MED from different neighbors\n")
1666 {
1667 VTY_DECLVAR_CONTEXT(bgp, bgp);
1668 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1669 bgp_recalculate_all_bestpaths(bgp);
1670
1671 return CMD_SUCCESS;
1672 }
1673
1674 DEFUN (no_bgp_always_compare_med,
1675 no_bgp_always_compare_med_cmd,
1676 "no bgp always-compare-med",
1677 NO_STR
1678 "BGP specific commands\n"
1679 "Allow comparing MED from different neighbors\n")
1680 {
1681 VTY_DECLVAR_CONTEXT(bgp, bgp);
1682 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1683 bgp_recalculate_all_bestpaths(bgp);
1684
1685 return CMD_SUCCESS;
1686 }
1687
1688 /* "bgp deterministic-med" configuration. */
1689 DEFUN (bgp_deterministic_med,
1690 bgp_deterministic_med_cmd,
1691 "bgp deterministic-med",
1692 "BGP specific commands\n"
1693 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1694 {
1695 VTY_DECLVAR_CONTEXT(bgp, bgp);
1696
1697 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1698 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1699 bgp_recalculate_all_bestpaths(bgp);
1700 }
1701
1702 return CMD_SUCCESS;
1703 }
1704
1705 DEFUN (no_bgp_deterministic_med,
1706 no_bgp_deterministic_med_cmd,
1707 "no bgp deterministic-med",
1708 NO_STR
1709 "BGP specific commands\n"
1710 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1711 {
1712 VTY_DECLVAR_CONTEXT(bgp, bgp);
1713 int bestpath_per_as_used;
1714 afi_t afi;
1715 safi_t safi;
1716 struct peer *peer;
1717 struct listnode *node, *nnode;
1718
1719 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1720 bestpath_per_as_used = 0;
1721
1722 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1723 FOREACH_AFI_SAFI (afi, safi)
1724 if (CHECK_FLAG(
1725 peer->af_flags[afi][safi],
1726 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1727 bestpath_per_as_used = 1;
1728 break;
1729 }
1730
1731 if (bestpath_per_as_used)
1732 break;
1733 }
1734
1735 if (bestpath_per_as_used) {
1736 vty_out(vty,
1737 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1738 return CMD_WARNING_CONFIG_FAILED;
1739 } else {
1740 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1741 bgp_recalculate_all_bestpaths(bgp);
1742 }
1743 }
1744
1745 return CMD_SUCCESS;
1746 }
1747
1748 /* "bgp graceful-restart" configuration. */
1749 DEFUN (bgp_graceful_restart,
1750 bgp_graceful_restart_cmd,
1751 "bgp graceful-restart",
1752 "BGP specific commands\n"
1753 "Graceful restart capability parameters\n")
1754 {
1755 VTY_DECLVAR_CONTEXT(bgp, bgp);
1756 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1757 return CMD_SUCCESS;
1758 }
1759
1760 DEFUN (no_bgp_graceful_restart,
1761 no_bgp_graceful_restart_cmd,
1762 "no bgp graceful-restart",
1763 NO_STR
1764 "BGP specific commands\n"
1765 "Graceful restart capability parameters\n")
1766 {
1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1769 return CMD_SUCCESS;
1770 }
1771
1772 DEFUN (bgp_graceful_restart_stalepath_time,
1773 bgp_graceful_restart_stalepath_time_cmd,
1774 "bgp graceful-restart stalepath-time (1-3600)",
1775 "BGP specific commands\n"
1776 "Graceful restart capability parameters\n"
1777 "Set the max time to hold onto restarting peer's stale paths\n"
1778 "Delay value (seconds)\n")
1779 {
1780 VTY_DECLVAR_CONTEXT(bgp, bgp);
1781 int idx_number = 3;
1782 u_int32_t stalepath;
1783
1784 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1785 bgp->stalepath_time = stalepath;
1786 return CMD_SUCCESS;
1787 }
1788
1789 DEFUN (bgp_graceful_restart_restart_time,
1790 bgp_graceful_restart_restart_time_cmd,
1791 "bgp graceful-restart restart-time (1-3600)",
1792 "BGP specific commands\n"
1793 "Graceful restart capability parameters\n"
1794 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1795 "Delay value (seconds)\n")
1796 {
1797 VTY_DECLVAR_CONTEXT(bgp, bgp);
1798 int idx_number = 3;
1799 u_int32_t restart;
1800
1801 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1802 bgp->restart_time = restart;
1803 return CMD_SUCCESS;
1804 }
1805
1806 DEFUN (no_bgp_graceful_restart_stalepath_time,
1807 no_bgp_graceful_restart_stalepath_time_cmd,
1808 "no bgp graceful-restart stalepath-time [(1-3600)]",
1809 NO_STR
1810 "BGP specific commands\n"
1811 "Graceful restart capability parameters\n"
1812 "Set the max time to hold onto restarting peer's stale paths\n"
1813 "Delay value (seconds)\n")
1814 {
1815 VTY_DECLVAR_CONTEXT(bgp, bgp);
1816
1817 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1818 return CMD_SUCCESS;
1819 }
1820
1821 DEFUN (no_bgp_graceful_restart_restart_time,
1822 no_bgp_graceful_restart_restart_time_cmd,
1823 "no bgp graceful-restart restart-time [(1-3600)]",
1824 NO_STR
1825 "BGP specific commands\n"
1826 "Graceful restart capability parameters\n"
1827 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1828 "Delay value (seconds)\n")
1829 {
1830 VTY_DECLVAR_CONTEXT(bgp, bgp);
1831
1832 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1833 return CMD_SUCCESS;
1834 }
1835
1836 DEFUN (bgp_graceful_restart_preserve_fw,
1837 bgp_graceful_restart_preserve_fw_cmd,
1838 "bgp graceful-restart preserve-fw-state",
1839 "BGP specific commands\n"
1840 "Graceful restart capability parameters\n"
1841 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1842 {
1843 VTY_DECLVAR_CONTEXT(bgp, bgp);
1844 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1845 return CMD_SUCCESS;
1846 }
1847
1848 DEFUN (no_bgp_graceful_restart_preserve_fw,
1849 no_bgp_graceful_restart_preserve_fw_cmd,
1850 "no bgp graceful-restart preserve-fw-state",
1851 NO_STR
1852 "BGP specific commands\n"
1853 "Graceful restart capability parameters\n"
1854 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1855 {
1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1858 return CMD_SUCCESS;
1859 }
1860
1861 static void bgp_redistribute_redo(struct bgp *bgp)
1862 {
1863 afi_t afi;
1864 int i;
1865 struct list *red_list;
1866 struct listnode *node;
1867 struct bgp_redist *red;
1868
1869 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1870 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1871
1872 red_list = bgp->redist[afi][i];
1873 if (!red_list)
1874 continue;
1875
1876 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1877 bgp_redistribute_resend(bgp, afi, i,
1878 red->instance);
1879 }
1880 }
1881 }
1882 }
1883
1884 /* "bgp graceful-shutdown" configuration */
1885 DEFUN (bgp_graceful_shutdown,
1886 bgp_graceful_shutdown_cmd,
1887 "bgp graceful-shutdown",
1888 BGP_STR
1889 "Graceful shutdown parameters\n")
1890 {
1891 VTY_DECLVAR_CONTEXT(bgp, bgp);
1892
1893 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1894 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1895 bgp_static_redo_import_check(bgp);
1896 bgp_redistribute_redo(bgp);
1897 bgp_clear_star_soft_out(vty, bgp->name);
1898 bgp_clear_star_soft_in(vty, bgp->name);
1899 }
1900
1901 return CMD_SUCCESS;
1902 }
1903
1904 DEFUN (no_bgp_graceful_shutdown,
1905 no_bgp_graceful_shutdown_cmd,
1906 "no bgp graceful-shutdown",
1907 NO_STR
1908 BGP_STR
1909 "Graceful shutdown parameters\n")
1910 {
1911 VTY_DECLVAR_CONTEXT(bgp, bgp);
1912
1913 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1914 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1915 bgp_static_redo_import_check(bgp);
1916 bgp_redistribute_redo(bgp);
1917 bgp_clear_star_soft_out(vty, bgp->name);
1918 bgp_clear_star_soft_in(vty, bgp->name);
1919 }
1920
1921 return CMD_SUCCESS;
1922 }
1923
1924 /* "bgp fast-external-failover" configuration. */
1925 DEFUN (bgp_fast_external_failover,
1926 bgp_fast_external_failover_cmd,
1927 "bgp fast-external-failover",
1928 BGP_STR
1929 "Immediately reset session if a link to a directly connected external peer goes down\n")
1930 {
1931 VTY_DECLVAR_CONTEXT(bgp, bgp);
1932 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1933 return CMD_SUCCESS;
1934 }
1935
1936 DEFUN (no_bgp_fast_external_failover,
1937 no_bgp_fast_external_failover_cmd,
1938 "no bgp fast-external-failover",
1939 NO_STR
1940 BGP_STR
1941 "Immediately reset session if a link to a directly connected external peer goes down\n")
1942 {
1943 VTY_DECLVAR_CONTEXT(bgp, bgp);
1944 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1945 return CMD_SUCCESS;
1946 }
1947
1948 /* "bgp enforce-first-as" configuration. */
1949 DEFUN (bgp_enforce_first_as,
1950 bgp_enforce_first_as_cmd,
1951 "bgp enforce-first-as",
1952 BGP_STR
1953 "Enforce the first AS for EBGP routes\n")
1954 {
1955 VTY_DECLVAR_CONTEXT(bgp, bgp);
1956 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1957 bgp_clear_star_soft_in(vty, bgp->name);
1958
1959 return CMD_SUCCESS;
1960 }
1961
1962 DEFUN (no_bgp_enforce_first_as,
1963 no_bgp_enforce_first_as_cmd,
1964 "no bgp enforce-first-as",
1965 NO_STR
1966 BGP_STR
1967 "Enforce the first AS for EBGP routes\n")
1968 {
1969 VTY_DECLVAR_CONTEXT(bgp, bgp);
1970 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1971 bgp_clear_star_soft_in(vty, bgp->name);
1972
1973 return CMD_SUCCESS;
1974 }
1975
1976 /* "bgp bestpath compare-routerid" configuration. */
1977 DEFUN (bgp_bestpath_compare_router_id,
1978 bgp_bestpath_compare_router_id_cmd,
1979 "bgp bestpath compare-routerid",
1980 "BGP specific commands\n"
1981 "Change the default bestpath selection\n"
1982 "Compare router-id for identical EBGP paths\n")
1983 {
1984 VTY_DECLVAR_CONTEXT(bgp, bgp);
1985 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1986 bgp_recalculate_all_bestpaths(bgp);
1987
1988 return CMD_SUCCESS;
1989 }
1990
1991 DEFUN (no_bgp_bestpath_compare_router_id,
1992 no_bgp_bestpath_compare_router_id_cmd,
1993 "no bgp bestpath compare-routerid",
1994 NO_STR
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_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2001 bgp_recalculate_all_bestpaths(bgp);
2002
2003 return CMD_SUCCESS;
2004 }
2005
2006 /* "bgp bestpath as-path ignore" configuration. */
2007 DEFUN (bgp_bestpath_aspath_ignore,
2008 bgp_bestpath_aspath_ignore_cmd,
2009 "bgp bestpath as-path ignore",
2010 "BGP specific commands\n"
2011 "Change the default bestpath selection\n"
2012 "AS-path attribute\n"
2013 "Ignore as-path length in selecting a route\n")
2014 {
2015 VTY_DECLVAR_CONTEXT(bgp, bgp);
2016 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2017 bgp_recalculate_all_bestpaths(bgp);
2018
2019 return CMD_SUCCESS;
2020 }
2021
2022 DEFUN (no_bgp_bestpath_aspath_ignore,
2023 no_bgp_bestpath_aspath_ignore_cmd,
2024 "no bgp bestpath as-path ignore",
2025 NO_STR
2026 "BGP specific commands\n"
2027 "Change the default bestpath selection\n"
2028 "AS-path attribute\n"
2029 "Ignore as-path length in selecting a route\n")
2030 {
2031 VTY_DECLVAR_CONTEXT(bgp, bgp);
2032 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2033 bgp_recalculate_all_bestpaths(bgp);
2034
2035 return CMD_SUCCESS;
2036 }
2037
2038 /* "bgp bestpath as-path confed" configuration. */
2039 DEFUN (bgp_bestpath_aspath_confed,
2040 bgp_bestpath_aspath_confed_cmd,
2041 "bgp bestpath as-path confed",
2042 "BGP specific commands\n"
2043 "Change the default bestpath selection\n"
2044 "AS-path attribute\n"
2045 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2046 {
2047 VTY_DECLVAR_CONTEXT(bgp, bgp);
2048 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2049 bgp_recalculate_all_bestpaths(bgp);
2050
2051 return CMD_SUCCESS;
2052 }
2053
2054 DEFUN (no_bgp_bestpath_aspath_confed,
2055 no_bgp_bestpath_aspath_confed_cmd,
2056 "no bgp bestpath as-path confed",
2057 NO_STR
2058 "BGP specific commands\n"
2059 "Change the default bestpath selection\n"
2060 "AS-path attribute\n"
2061 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2062 {
2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
2064 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2065 bgp_recalculate_all_bestpaths(bgp);
2066
2067 return CMD_SUCCESS;
2068 }
2069
2070 /* "bgp bestpath as-path multipath-relax" configuration. */
2071 DEFUN (bgp_bestpath_aspath_multipath_relax,
2072 bgp_bestpath_aspath_multipath_relax_cmd,
2073 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2074 "BGP specific commands\n"
2075 "Change the default bestpath selection\n"
2076 "AS-path attribute\n"
2077 "Allow load sharing across routes that have different AS paths (but same length)\n"
2078 "Generate an AS_SET\n"
2079 "Do not generate an AS_SET\n")
2080 {
2081 VTY_DECLVAR_CONTEXT(bgp, bgp);
2082 int idx = 0;
2083 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2084
2085 /* no-as-set is now the default behavior so we can silently
2086 * ignore it */
2087 if (argv_find(argv, argc, "as-set", &idx))
2088 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2089 else
2090 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2091
2092 bgp_recalculate_all_bestpaths(bgp);
2093
2094 return CMD_SUCCESS;
2095 }
2096
2097 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2098 no_bgp_bestpath_aspath_multipath_relax_cmd,
2099 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2100 NO_STR
2101 "BGP specific commands\n"
2102 "Change the default bestpath selection\n"
2103 "AS-path attribute\n"
2104 "Allow load sharing across routes that have different AS paths (but same length)\n"
2105 "Generate an AS_SET\n"
2106 "Do not generate an AS_SET\n")
2107 {
2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2110 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2111 bgp_recalculate_all_bestpaths(bgp);
2112
2113 return CMD_SUCCESS;
2114 }
2115
2116 /* "bgp log-neighbor-changes" configuration. */
2117 DEFUN (bgp_log_neighbor_changes,
2118 bgp_log_neighbor_changes_cmd,
2119 "bgp log-neighbor-changes",
2120 "BGP specific commands\n"
2121 "Log neighbor up/down and reset reason\n")
2122 {
2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2125 return CMD_SUCCESS;
2126 }
2127
2128 DEFUN (no_bgp_log_neighbor_changes,
2129 no_bgp_log_neighbor_changes_cmd,
2130 "no bgp log-neighbor-changes",
2131 NO_STR
2132 "BGP specific commands\n"
2133 "Log neighbor up/down and reset reason\n")
2134 {
2135 VTY_DECLVAR_CONTEXT(bgp, bgp);
2136 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2137 return CMD_SUCCESS;
2138 }
2139
2140 /* "bgp bestpath med" configuration. */
2141 DEFUN (bgp_bestpath_med,
2142 bgp_bestpath_med_cmd,
2143 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2144 "BGP specific commands\n"
2145 "Change the default bestpath selection\n"
2146 "MED attribute\n"
2147 "Compare MED among confederation paths\n"
2148 "Treat missing MED as the least preferred one\n"
2149 "Treat missing MED as the least preferred one\n"
2150 "Compare MED among confederation paths\n")
2151 {
2152 VTY_DECLVAR_CONTEXT(bgp, bgp);
2153
2154 int idx = 0;
2155 if (argv_find(argv, argc, "confed", &idx))
2156 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2157 idx = 0;
2158 if (argv_find(argv, argc, "missing-as-worst", &idx))
2159 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2160
2161 bgp_recalculate_all_bestpaths(bgp);
2162
2163 return CMD_SUCCESS;
2164 }
2165
2166 DEFUN (no_bgp_bestpath_med,
2167 no_bgp_bestpath_med_cmd,
2168 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2169 NO_STR
2170 "BGP specific commands\n"
2171 "Change the default bestpath selection\n"
2172 "MED attribute\n"
2173 "Compare MED among confederation paths\n"
2174 "Treat missing MED as the least preferred one\n"
2175 "Treat missing MED as the least preferred one\n"
2176 "Compare MED among confederation paths\n")
2177 {
2178 VTY_DECLVAR_CONTEXT(bgp, bgp);
2179
2180 int idx = 0;
2181 if (argv_find(argv, argc, "confed", &idx))
2182 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2183 idx = 0;
2184 if (argv_find(argv, argc, "missing-as-worst", &idx))
2185 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2186
2187 bgp_recalculate_all_bestpaths(bgp);
2188
2189 return CMD_SUCCESS;
2190 }
2191
2192 /* "no bgp default ipv4-unicast". */
2193 DEFUN (no_bgp_default_ipv4_unicast,
2194 no_bgp_default_ipv4_unicast_cmd,
2195 "no bgp default ipv4-unicast",
2196 NO_STR
2197 "BGP specific commands\n"
2198 "Configure BGP defaults\n"
2199 "Activate ipv4-unicast for a peer by default\n")
2200 {
2201 VTY_DECLVAR_CONTEXT(bgp, bgp);
2202 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2203 return CMD_SUCCESS;
2204 }
2205
2206 DEFUN (bgp_default_ipv4_unicast,
2207 bgp_default_ipv4_unicast_cmd,
2208 "bgp default ipv4-unicast",
2209 "BGP specific commands\n"
2210 "Configure BGP defaults\n"
2211 "Activate ipv4-unicast for a peer by default\n")
2212 {
2213 VTY_DECLVAR_CONTEXT(bgp, bgp);
2214 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2215 return CMD_SUCCESS;
2216 }
2217
2218 /* Display hostname in certain command outputs */
2219 DEFUN (bgp_default_show_hostname,
2220 bgp_default_show_hostname_cmd,
2221 "bgp default show-hostname",
2222 "BGP specific commands\n"
2223 "Configure BGP defaults\n"
2224 "Show hostname in certain command ouputs\n")
2225 {
2226 VTY_DECLVAR_CONTEXT(bgp, bgp);
2227 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2228 return CMD_SUCCESS;
2229 }
2230
2231 DEFUN (no_bgp_default_show_hostname,
2232 no_bgp_default_show_hostname_cmd,
2233 "no bgp default show-hostname",
2234 NO_STR
2235 "BGP specific commands\n"
2236 "Configure BGP defaults\n"
2237 "Show hostname in certain command ouputs\n")
2238 {
2239 VTY_DECLVAR_CONTEXT(bgp, bgp);
2240 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2241 return CMD_SUCCESS;
2242 }
2243
2244 /* "bgp network import-check" configuration. */
2245 DEFUN (bgp_network_import_check,
2246 bgp_network_import_check_cmd,
2247 "bgp network import-check",
2248 "BGP specific commands\n"
2249 "BGP network command\n"
2250 "Check BGP network route exists in IGP\n")
2251 {
2252 VTY_DECLVAR_CONTEXT(bgp, bgp);
2253 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2254 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2255 bgp_static_redo_import_check(bgp);
2256 }
2257
2258 return CMD_SUCCESS;
2259 }
2260
2261 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2262 "bgp network import-check exact",
2263 "BGP specific commands\n"
2264 "BGP network command\n"
2265 "Check BGP network route exists in IGP\n"
2266 "Match route precisely\n")
2267
2268 DEFUN (no_bgp_network_import_check,
2269 no_bgp_network_import_check_cmd,
2270 "no bgp network import-check",
2271 NO_STR
2272 "BGP specific commands\n"
2273 "BGP network command\n"
2274 "Check BGP network route exists in IGP\n")
2275 {
2276 VTY_DECLVAR_CONTEXT(bgp, bgp);
2277 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2278 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2279 bgp_static_redo_import_check(bgp);
2280 }
2281
2282 return CMD_SUCCESS;
2283 }
2284
2285 DEFUN (bgp_default_local_preference,
2286 bgp_default_local_preference_cmd,
2287 "bgp default local-preference (0-4294967295)",
2288 "BGP specific commands\n"
2289 "Configure BGP defaults\n"
2290 "local preference (higher=more preferred)\n"
2291 "Configure default local preference value\n")
2292 {
2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 int idx_number = 3;
2295 u_int32_t local_pref;
2296
2297 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2298
2299 bgp_default_local_preference_set(bgp, local_pref);
2300 bgp_clear_star_soft_in(vty, bgp->name);
2301
2302 return CMD_SUCCESS;
2303 }
2304
2305 DEFUN (no_bgp_default_local_preference,
2306 no_bgp_default_local_preference_cmd,
2307 "no bgp default local-preference [(0-4294967295)]",
2308 NO_STR
2309 "BGP specific commands\n"
2310 "Configure BGP defaults\n"
2311 "local preference (higher=more preferred)\n"
2312 "Configure default local preference value\n")
2313 {
2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315 bgp_default_local_preference_unset(bgp);
2316 bgp_clear_star_soft_in(vty, bgp->name);
2317
2318 return CMD_SUCCESS;
2319 }
2320
2321
2322 DEFUN (bgp_default_subgroup_pkt_queue_max,
2323 bgp_default_subgroup_pkt_queue_max_cmd,
2324 "bgp default subgroup-pkt-queue-max (20-100)",
2325 "BGP specific commands\n"
2326 "Configure BGP defaults\n"
2327 "subgroup-pkt-queue-max\n"
2328 "Configure subgroup packet queue max\n")
2329 {
2330 VTY_DECLVAR_CONTEXT(bgp, bgp);
2331 int idx_number = 3;
2332 u_int32_t max_size;
2333
2334 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2335
2336 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2337
2338 return CMD_SUCCESS;
2339 }
2340
2341 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2342 no_bgp_default_subgroup_pkt_queue_max_cmd,
2343 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2344 NO_STR
2345 "BGP specific commands\n"
2346 "Configure BGP defaults\n"
2347 "subgroup-pkt-queue-max\n"
2348 "Configure subgroup packet queue max\n")
2349 {
2350 VTY_DECLVAR_CONTEXT(bgp, bgp);
2351 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2352 return CMD_SUCCESS;
2353 }
2354
2355
2356 DEFUN (bgp_rr_allow_outbound_policy,
2357 bgp_rr_allow_outbound_policy_cmd,
2358 "bgp route-reflector allow-outbound-policy",
2359 "BGP specific commands\n"
2360 "Allow modifications made by out route-map\n"
2361 "on ibgp neighbors\n")
2362 {
2363 VTY_DECLVAR_CONTEXT(bgp, bgp);
2364
2365 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2366 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2367 update_group_announce_rrclients(bgp);
2368 bgp_clear_star_soft_out(vty, bgp->name);
2369 }
2370
2371 return CMD_SUCCESS;
2372 }
2373
2374 DEFUN (no_bgp_rr_allow_outbound_policy,
2375 no_bgp_rr_allow_outbound_policy_cmd,
2376 "no bgp route-reflector allow-outbound-policy",
2377 NO_STR
2378 "BGP specific commands\n"
2379 "Allow modifications made by out route-map\n"
2380 "on ibgp neighbors\n")
2381 {
2382 VTY_DECLVAR_CONTEXT(bgp, bgp);
2383
2384 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2385 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2386 update_group_announce_rrclients(bgp);
2387 bgp_clear_star_soft_out(vty, bgp->name);
2388 }
2389
2390 return CMD_SUCCESS;
2391 }
2392
2393 DEFUN (bgp_listen_limit,
2394 bgp_listen_limit_cmd,
2395 "bgp listen limit (1-5000)",
2396 "BGP specific commands\n"
2397 "Configure BGP defaults\n"
2398 "maximum number of BGP Dynamic Neighbors that can be created\n"
2399 "Configure Dynamic Neighbors listen limit value\n")
2400 {
2401 VTY_DECLVAR_CONTEXT(bgp, bgp);
2402 int idx_number = 3;
2403 int listen_limit;
2404
2405 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2406
2407 bgp_listen_limit_set(bgp, listen_limit);
2408
2409 return CMD_SUCCESS;
2410 }
2411
2412 DEFUN (no_bgp_listen_limit,
2413 no_bgp_listen_limit_cmd,
2414 "no bgp listen limit [(1-5000)]",
2415 "BGP specific commands\n"
2416 "Configure BGP defaults\n"
2417 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2418 "Configure Dynamic Neighbors listen limit value to default\n"
2419 "Configure Dynamic Neighbors listen limit value\n")
2420 {
2421 VTY_DECLVAR_CONTEXT(bgp, bgp);
2422 bgp_listen_limit_unset(bgp);
2423 return CMD_SUCCESS;
2424 }
2425
2426
2427 /*
2428 * Check if this listen range is already configured. Check for exact
2429 * match or overlap based on input.
2430 */
2431 static struct peer_group *listen_range_exists(struct bgp *bgp,
2432 struct prefix *range, int exact)
2433 {
2434 struct listnode *node, *nnode;
2435 struct listnode *node1, *nnode1;
2436 struct peer_group *group;
2437 struct prefix *lr;
2438 afi_t afi;
2439 int match;
2440
2441 afi = family2afi(range->family);
2442 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2443 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2444 lr)) {
2445 if (exact)
2446 match = prefix_same(range, lr);
2447 else
2448 match = (prefix_match(range, lr)
2449 || prefix_match(lr, range));
2450 if (match)
2451 return group;
2452 }
2453 }
2454
2455 return NULL;
2456 }
2457
2458 DEFUN (bgp_listen_range,
2459 bgp_listen_range_cmd,
2460 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2461 "BGP specific commands\n"
2462 "Configure BGP dynamic neighbors listen range\n"
2463 "Configure BGP dynamic neighbors listen range\n"
2464 NEIGHBOR_ADDR_STR
2465 "Member of the peer-group\n"
2466 "Peer-group name\n")
2467 {
2468 VTY_DECLVAR_CONTEXT(bgp, bgp);
2469 struct prefix range;
2470 struct peer_group *group, *existing_group;
2471 afi_t afi;
2472 int ret;
2473 int idx = 0;
2474
2475 argv_find(argv, argc, "A.B.C.D/M", &idx);
2476 argv_find(argv, argc, "X:X::X:X/M", &idx);
2477 char *prefix = argv[idx]->arg;
2478 argv_find(argv, argc, "WORD", &idx);
2479 char *peergroup = argv[idx]->arg;
2480
2481 /* Convert IP prefix string to struct prefix. */
2482 ret = str2prefix(prefix, &range);
2483 if (!ret) {
2484 vty_out(vty, "%% Malformed listen range\n");
2485 return CMD_WARNING_CONFIG_FAILED;
2486 }
2487
2488 afi = family2afi(range.family);
2489
2490 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2491 vty_out(vty,
2492 "%% Malformed listen range (link-local address)\n");
2493 return CMD_WARNING_CONFIG_FAILED;
2494 }
2495
2496 apply_mask(&range);
2497
2498 /* Check if same listen range is already configured. */
2499 existing_group = listen_range_exists(bgp, &range, 1);
2500 if (existing_group) {
2501 if (strcmp(existing_group->name, peergroup) == 0)
2502 return CMD_SUCCESS;
2503 else {
2504 vty_out(vty,
2505 "%% Same listen range is attached to peer-group %s\n",
2506 existing_group->name);
2507 return CMD_WARNING_CONFIG_FAILED;
2508 }
2509 }
2510
2511 /* Check if an overlapping listen range exists. */
2512 if (listen_range_exists(bgp, &range, 0)) {
2513 vty_out(vty,
2514 "%% Listen range overlaps with existing listen range\n");
2515 return CMD_WARNING_CONFIG_FAILED;
2516 }
2517
2518 group = peer_group_lookup(bgp, peergroup);
2519 if (!group) {
2520 vty_out(vty, "%% Configure the peer-group first\n");
2521 return CMD_WARNING_CONFIG_FAILED;
2522 }
2523
2524 ret = peer_group_listen_range_add(group, &range);
2525 return bgp_vty_return(vty, ret);
2526 }
2527
2528 DEFUN (no_bgp_listen_range,
2529 no_bgp_listen_range_cmd,
2530 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2531 NO_STR
2532 "BGP specific commands\n"
2533 "Unconfigure BGP dynamic neighbors listen range\n"
2534 "Unconfigure BGP dynamic neighbors listen range\n"
2535 NEIGHBOR_ADDR_STR
2536 "Member of the peer-group\n"
2537 "Peer-group name\n")
2538 {
2539 VTY_DECLVAR_CONTEXT(bgp, bgp);
2540 struct prefix range;
2541 struct peer_group *group;
2542 afi_t afi;
2543 int ret;
2544 int idx = 0;
2545
2546 argv_find(argv, argc, "A.B.C.D/M", &idx);
2547 argv_find(argv, argc, "X:X::X:X/M", &idx);
2548 char *prefix = argv[idx]->arg;
2549 argv_find(argv, argc, "WORD", &idx);
2550 char *peergroup = argv[idx]->arg;
2551
2552 /* Convert IP prefix string to struct prefix. */
2553 ret = str2prefix(prefix, &range);
2554 if (!ret) {
2555 vty_out(vty, "%% Malformed listen range\n");
2556 return CMD_WARNING_CONFIG_FAILED;
2557 }
2558
2559 afi = family2afi(range.family);
2560
2561 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2562 vty_out(vty,
2563 "%% Malformed listen range (link-local address)\n");
2564 return CMD_WARNING_CONFIG_FAILED;
2565 }
2566
2567 apply_mask(&range);
2568
2569 group = peer_group_lookup(bgp, peergroup);
2570 if (!group) {
2571 vty_out(vty, "%% Peer-group does not exist\n");
2572 return CMD_WARNING_CONFIG_FAILED;
2573 }
2574
2575 ret = peer_group_listen_range_del(group, &range);
2576 return bgp_vty_return(vty, ret);
2577 }
2578
2579 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2580 {
2581 struct peer_group *group;
2582 struct listnode *node, *nnode, *rnode, *nrnode;
2583 struct prefix *range;
2584 afi_t afi;
2585 char buf[PREFIX2STR_BUFFER];
2586
2587 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2588 vty_out(vty, " bgp listen limit %d\n",
2589 bgp->dynamic_neighbors_limit);
2590
2591 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2592 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2593 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2594 nrnode, range)) {
2595 prefix2str(range, buf, sizeof(buf));
2596 vty_out(vty,
2597 " bgp listen range %s peer-group %s\n",
2598 buf, group->name);
2599 }
2600 }
2601 }
2602 }
2603
2604
2605 DEFUN (bgp_disable_connected_route_check,
2606 bgp_disable_connected_route_check_cmd,
2607 "bgp disable-ebgp-connected-route-check",
2608 "BGP specific commands\n"
2609 "Disable checking if nexthop is connected on ebgp sessions\n")
2610 {
2611 VTY_DECLVAR_CONTEXT(bgp, bgp);
2612 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2613 bgp_clear_star_soft_in(vty, bgp->name);
2614
2615 return CMD_SUCCESS;
2616 }
2617
2618 DEFUN (no_bgp_disable_connected_route_check,
2619 no_bgp_disable_connected_route_check_cmd,
2620 "no bgp disable-ebgp-connected-route-check",
2621 NO_STR
2622 "BGP specific commands\n"
2623 "Disable checking if nexthop is connected on ebgp sessions\n")
2624 {
2625 VTY_DECLVAR_CONTEXT(bgp, bgp);
2626 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2627 bgp_clear_star_soft_in(vty, bgp->name);
2628
2629 return CMD_SUCCESS;
2630 }
2631
2632
2633 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2634 const char *as_str, afi_t afi, safi_t safi)
2635 {
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637 int ret;
2638 as_t as;
2639 int as_type = AS_SPECIFIED;
2640 union sockunion su;
2641
2642 if (as_str[0] == 'i') {
2643 as = 0;
2644 as_type = AS_INTERNAL;
2645 } else if (as_str[0] == 'e') {
2646 as = 0;
2647 as_type = AS_EXTERNAL;
2648 } else {
2649 /* Get AS number. */
2650 as = strtoul(as_str, NULL, 10);
2651 }
2652
2653 /* If peer is peer group, call proper function. */
2654 ret = str2sockunion(peer_str, &su);
2655 if (ret < 0) {
2656 /* Check for peer by interface */
2657 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2658 safi);
2659 if (ret < 0) {
2660 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2661 if (ret < 0) {
2662 vty_out(vty,
2663 "%% Create the peer-group or interface first\n");
2664 return CMD_WARNING_CONFIG_FAILED;
2665 }
2666 return CMD_SUCCESS;
2667 }
2668 } else {
2669 if (peer_address_self_check(bgp, &su)) {
2670 vty_out(vty,
2671 "%% Can not configure the local system as neighbor\n");
2672 return CMD_WARNING_CONFIG_FAILED;
2673 }
2674 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2675 }
2676
2677 /* This peer belongs to peer group. */
2678 switch (ret) {
2679 case BGP_ERR_PEER_GROUP_MEMBER:
2680 vty_out(vty,
2681 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2682 as);
2683 return CMD_WARNING_CONFIG_FAILED;
2684 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2685 vty_out(vty,
2686 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2687 as, as_str);
2688 return CMD_WARNING_CONFIG_FAILED;
2689 }
2690 return bgp_vty_return(vty, ret);
2691 }
2692
2693 DEFUN (bgp_default_shutdown,
2694 bgp_default_shutdown_cmd,
2695 "[no] bgp default shutdown",
2696 NO_STR
2697 BGP_STR
2698 "Configure BGP defaults\n"
2699 "Apply administrative shutdown to newly configured peers\n")
2700 {
2701 VTY_DECLVAR_CONTEXT(bgp, bgp);
2702 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2703 return CMD_SUCCESS;
2704 }
2705
2706 DEFUN (neighbor_remote_as,
2707 neighbor_remote_as_cmd,
2708 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2709 NEIGHBOR_STR
2710 NEIGHBOR_ADDR_STR2
2711 "Specify a BGP neighbor\n"
2712 AS_STR
2713 "Internal BGP peer\n"
2714 "External BGP peer\n")
2715 {
2716 int idx_peer = 1;
2717 int idx_remote_as = 3;
2718 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2719 argv[idx_remote_as]->arg, AFI_IP,
2720 SAFI_UNICAST);
2721 }
2722
2723 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2724 afi_t afi, safi_t safi, int v6only,
2725 const char *peer_group_name,
2726 const char *as_str)
2727 {
2728 VTY_DECLVAR_CONTEXT(bgp, bgp);
2729 as_t as = 0;
2730 int as_type = AS_UNSPECIFIED;
2731 struct peer *peer;
2732 struct peer_group *group;
2733 int ret = 0;
2734 union sockunion su;
2735
2736 group = peer_group_lookup(bgp, conf_if);
2737
2738 if (group) {
2739 vty_out(vty, "%% Name conflict with peer-group \n");
2740 return CMD_WARNING_CONFIG_FAILED;
2741 }
2742
2743 if (as_str) {
2744 if (as_str[0] == 'i') {
2745 as_type = AS_INTERNAL;
2746 } else if (as_str[0] == 'e') {
2747 as_type = AS_EXTERNAL;
2748 } else {
2749 /* Get AS number. */
2750 as = strtoul(as_str, NULL, 10);
2751 as_type = AS_SPECIFIED;
2752 }
2753 }
2754
2755 peer = peer_lookup_by_conf_if(bgp, conf_if);
2756 if (peer) {
2757 if (as_str)
2758 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2759 afi, safi);
2760 } else {
2761 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2762 && afi == AFI_IP && safi == SAFI_UNICAST)
2763 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2764 as_type, 0, 0, NULL);
2765 else
2766 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2767 as_type, afi, safi, NULL);
2768
2769 if (!peer) {
2770 vty_out(vty, "%% BGP failed to create peer\n");
2771 return CMD_WARNING_CONFIG_FAILED;
2772 }
2773
2774 if (v6only)
2775 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2776
2777 /* Request zebra to initiate IPv6 RAs on this interface. We do
2778 * this
2779 * any unnumbered peer in order to not worry about run-time
2780 * transitions
2781 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2782 * address
2783 * gets deleted later etc.)
2784 */
2785 if (peer->ifp)
2786 bgp_zebra_initiate_radv(bgp, peer);
2787 }
2788
2789 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2790 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2791 if (v6only)
2792 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2793 else
2794 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2795
2796 /* v6only flag changed. Reset bgp seesion */
2797 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2798 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2799 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2800 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2801 } else
2802 bgp_session_reset(peer);
2803 }
2804
2805 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2806 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2807
2808 if (peer_group_name) {
2809 group = peer_group_lookup(bgp, peer_group_name);
2810 if (!group) {
2811 vty_out(vty, "%% Configure the peer-group first\n");
2812 return CMD_WARNING_CONFIG_FAILED;
2813 }
2814
2815 ret = peer_group_bind(bgp, &su, peer, group, &as);
2816 }
2817
2818 return bgp_vty_return(vty, ret);
2819 }
2820
2821 DEFUN (neighbor_interface_config,
2822 neighbor_interface_config_cmd,
2823 "neighbor WORD interface [peer-group WORD]",
2824 NEIGHBOR_STR
2825 "Interface name or neighbor tag\n"
2826 "Enable BGP on interface\n"
2827 "Member of the peer-group\n"
2828 "Peer-group name\n")
2829 {
2830 int idx_word = 1;
2831 int idx_peer_group_word = 4;
2832
2833 if (argc > idx_peer_group_word)
2834 return peer_conf_interface_get(
2835 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2836 argv[idx_peer_group_word]->arg, NULL);
2837 else
2838 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2839 SAFI_UNICAST, 0, NULL, NULL);
2840 }
2841
2842 DEFUN (neighbor_interface_config_v6only,
2843 neighbor_interface_config_v6only_cmd,
2844 "neighbor WORD interface v6only [peer-group WORD]",
2845 NEIGHBOR_STR
2846 "Interface name or neighbor tag\n"
2847 "Enable BGP on interface\n"
2848 "Enable BGP with v6 link-local only\n"
2849 "Member of the peer-group\n"
2850 "Peer-group name\n")
2851 {
2852 int idx_word = 1;
2853 int idx_peer_group_word = 5;
2854
2855 if (argc > idx_peer_group_word)
2856 return peer_conf_interface_get(
2857 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2858 argv[idx_peer_group_word]->arg, NULL);
2859
2860 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2861 SAFI_UNICAST, 1, NULL, NULL);
2862 }
2863
2864
2865 DEFUN (neighbor_interface_config_remote_as,
2866 neighbor_interface_config_remote_as_cmd,
2867 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2868 NEIGHBOR_STR
2869 "Interface name or neighbor tag\n"
2870 "Enable BGP on interface\n"
2871 "Specify a BGP neighbor\n"
2872 AS_STR
2873 "Internal BGP peer\n"
2874 "External BGP peer\n")
2875 {
2876 int idx_word = 1;
2877 int idx_remote_as = 4;
2878 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2879 SAFI_UNICAST, 0, NULL,
2880 argv[idx_remote_as]->arg);
2881 }
2882
2883 DEFUN (neighbor_interface_v6only_config_remote_as,
2884 neighbor_interface_v6only_config_remote_as_cmd,
2885 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2886 NEIGHBOR_STR
2887 "Interface name or neighbor tag\n"
2888 "Enable BGP with v6 link-local only\n"
2889 "Enable BGP on interface\n"
2890 "Specify a BGP neighbor\n"
2891 AS_STR
2892 "Internal BGP peer\n"
2893 "External BGP peer\n")
2894 {
2895 int idx_word = 1;
2896 int idx_remote_as = 5;
2897 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2898 SAFI_UNICAST, 1, NULL,
2899 argv[idx_remote_as]->arg);
2900 }
2901
2902 DEFUN (neighbor_peer_group,
2903 neighbor_peer_group_cmd,
2904 "neighbor WORD peer-group",
2905 NEIGHBOR_STR
2906 "Interface name or neighbor tag\n"
2907 "Configure peer-group\n")
2908 {
2909 VTY_DECLVAR_CONTEXT(bgp, bgp);
2910 int idx_word = 1;
2911 struct peer *peer;
2912 struct peer_group *group;
2913
2914 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2915 if (peer) {
2916 vty_out(vty, "%% Name conflict with interface: \n");
2917 return CMD_WARNING_CONFIG_FAILED;
2918 }
2919
2920 group = peer_group_get(bgp, argv[idx_word]->arg);
2921 if (!group) {
2922 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2923 return CMD_WARNING_CONFIG_FAILED;
2924 }
2925
2926 return CMD_SUCCESS;
2927 }
2928
2929 DEFUN (no_neighbor,
2930 no_neighbor_cmd,
2931 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2932 NO_STR
2933 NEIGHBOR_STR
2934 NEIGHBOR_ADDR_STR2
2935 "Specify a BGP neighbor\n"
2936 AS_STR
2937 "Internal BGP peer\n"
2938 "External BGP peer\n")
2939 {
2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941 int idx_peer = 2;
2942 int ret;
2943 union sockunion su;
2944 struct peer_group *group;
2945 struct peer *peer;
2946 struct peer *other;
2947
2948 ret = str2sockunion(argv[idx_peer]->arg, &su);
2949 if (ret < 0) {
2950 /* look up for neighbor by interface name config. */
2951 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2952 if (peer) {
2953 /* Request zebra to terminate IPv6 RAs on this
2954 * interface. */
2955 if (peer->ifp)
2956 bgp_zebra_terminate_radv(peer->bgp, peer);
2957 peer_delete(peer);
2958 return CMD_SUCCESS;
2959 }
2960
2961 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2962 if (group)
2963 peer_group_delete(group);
2964 else {
2965 vty_out(vty, "%% Create the peer-group first\n");
2966 return CMD_WARNING_CONFIG_FAILED;
2967 }
2968 } else {
2969 peer = peer_lookup(bgp, &su);
2970 if (peer) {
2971 if (peer_dynamic_neighbor(peer)) {
2972 vty_out(vty,
2973 "%% Operation not allowed on a dynamic neighbor\n");
2974 return CMD_WARNING_CONFIG_FAILED;
2975 }
2976
2977 other = peer->doppelganger;
2978 peer_delete(peer);
2979 if (other && other->status != Deleted)
2980 peer_delete(other);
2981 }
2982 }
2983
2984 return CMD_SUCCESS;
2985 }
2986
2987 DEFUN (no_neighbor_interface_config,
2988 no_neighbor_interface_config_cmd,
2989 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
2990 NO_STR
2991 NEIGHBOR_STR
2992 "Interface name\n"
2993 "Configure BGP on interface\n"
2994 "Enable BGP with v6 link-local only\n"
2995 "Member of the peer-group\n"
2996 "Peer-group name\n"
2997 "Specify a BGP neighbor\n"
2998 AS_STR
2999 "Internal BGP peer\n"
3000 "External BGP peer\n")
3001 {
3002 VTY_DECLVAR_CONTEXT(bgp, bgp);
3003 int idx_word = 2;
3004 struct peer *peer;
3005
3006 /* look up for neighbor by interface name config. */
3007 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3008 if (peer) {
3009 /* Request zebra to terminate IPv6 RAs on this interface. */
3010 if (peer->ifp)
3011 bgp_zebra_terminate_radv(peer->bgp, peer);
3012 peer_delete(peer);
3013 } else {
3014 vty_out(vty, "%% Create the bgp interface first\n");
3015 return CMD_WARNING_CONFIG_FAILED;
3016 }
3017 return CMD_SUCCESS;
3018 }
3019
3020 DEFUN (no_neighbor_peer_group,
3021 no_neighbor_peer_group_cmd,
3022 "no neighbor WORD peer-group",
3023 NO_STR
3024 NEIGHBOR_STR
3025 "Neighbor tag\n"
3026 "Configure peer-group\n")
3027 {
3028 VTY_DECLVAR_CONTEXT(bgp, bgp);
3029 int idx_word = 2;
3030 struct peer_group *group;
3031
3032 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3033 if (group)
3034 peer_group_delete(group);
3035 else {
3036 vty_out(vty, "%% Create the peer-group first\n");
3037 return CMD_WARNING_CONFIG_FAILED;
3038 }
3039 return CMD_SUCCESS;
3040 }
3041
3042 DEFUN (no_neighbor_interface_peer_group_remote_as,
3043 no_neighbor_interface_peer_group_remote_as_cmd,
3044 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3045 NO_STR
3046 NEIGHBOR_STR
3047 "Interface name or neighbor tag\n"
3048 "Specify a BGP neighbor\n"
3049 AS_STR
3050 "Internal BGP peer\n"
3051 "External BGP peer\n")
3052 {
3053 VTY_DECLVAR_CONTEXT(bgp, bgp);
3054 int idx_word = 2;
3055 struct peer_group *group;
3056 struct peer *peer;
3057
3058 /* look up for neighbor by interface name config. */
3059 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3060 if (peer) {
3061 peer_as_change(peer, 0, AS_SPECIFIED);
3062 return CMD_SUCCESS;
3063 }
3064
3065 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3066 if (group)
3067 peer_group_remote_as_delete(group);
3068 else {
3069 vty_out(vty, "%% Create the peer-group or interface first\n");
3070 return CMD_WARNING_CONFIG_FAILED;
3071 }
3072 return CMD_SUCCESS;
3073 }
3074
3075 DEFUN (neighbor_local_as,
3076 neighbor_local_as_cmd,
3077 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3078 NEIGHBOR_STR
3079 NEIGHBOR_ADDR_STR2
3080 "Specify a local-as number\n"
3081 "AS number used as local AS\n")
3082 {
3083 int idx_peer = 1;
3084 int idx_number = 3;
3085 struct peer *peer;
3086 int ret;
3087 as_t as;
3088
3089 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3090 if (!peer)
3091 return CMD_WARNING_CONFIG_FAILED;
3092
3093 as = strtoul(argv[idx_number]->arg, NULL, 10);
3094 ret = peer_local_as_set(peer, as, 0, 0);
3095 return bgp_vty_return(vty, ret);
3096 }
3097
3098 DEFUN (neighbor_local_as_no_prepend,
3099 neighbor_local_as_no_prepend_cmd,
3100 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3101 NEIGHBOR_STR
3102 NEIGHBOR_ADDR_STR2
3103 "Specify a local-as number\n"
3104 "AS number used as local AS\n"
3105 "Do not prepend local-as to updates from ebgp peers\n")
3106 {
3107 int idx_peer = 1;
3108 int idx_number = 3;
3109 struct peer *peer;
3110 int ret;
3111 as_t as;
3112
3113 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3114 if (!peer)
3115 return CMD_WARNING_CONFIG_FAILED;
3116
3117 as = strtoul(argv[idx_number]->arg, NULL, 10);
3118 ret = peer_local_as_set(peer, as, 1, 0);
3119 return bgp_vty_return(vty, ret);
3120 }
3121
3122 DEFUN (neighbor_local_as_no_prepend_replace_as,
3123 neighbor_local_as_no_prepend_replace_as_cmd,
3124 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3125 NEIGHBOR_STR
3126 NEIGHBOR_ADDR_STR2
3127 "Specify a local-as number\n"
3128 "AS number used as local AS\n"
3129 "Do not prepend local-as to updates from ebgp peers\n"
3130 "Do not prepend local-as to updates from ibgp peers\n")
3131 {
3132 int idx_peer = 1;
3133 int idx_number = 3;
3134 struct peer *peer;
3135 int ret;
3136 as_t as;
3137
3138 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3139 if (!peer)
3140 return CMD_WARNING_CONFIG_FAILED;
3141
3142 as = strtoul(argv[idx_number]->arg, NULL, 10);
3143 ret = peer_local_as_set(peer, as, 1, 1);
3144 return bgp_vty_return(vty, ret);
3145 }
3146
3147 DEFUN (no_neighbor_local_as,
3148 no_neighbor_local_as_cmd,
3149 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3150 NO_STR
3151 NEIGHBOR_STR
3152 NEIGHBOR_ADDR_STR2
3153 "Specify a local-as number\n"
3154 "AS number used as local AS\n"
3155 "Do not prepend local-as to updates from ebgp peers\n"
3156 "Do not prepend local-as to updates from ibgp peers\n")
3157 {
3158 int idx_peer = 2;
3159 struct peer *peer;
3160 int ret;
3161
3162 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3163 if (!peer)
3164 return CMD_WARNING_CONFIG_FAILED;
3165
3166 ret = peer_local_as_unset(peer);
3167 return bgp_vty_return(vty, ret);
3168 }
3169
3170
3171 DEFUN (neighbor_solo,
3172 neighbor_solo_cmd,
3173 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3174 NEIGHBOR_STR
3175 NEIGHBOR_ADDR_STR2
3176 "Solo peer - part of its own update group\n")
3177 {
3178 int idx_peer = 1;
3179 struct peer *peer;
3180 int ret;
3181
3182 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3183 if (!peer)
3184 return CMD_WARNING_CONFIG_FAILED;
3185
3186 ret = update_group_adjust_soloness(peer, 1);
3187 return bgp_vty_return(vty, ret);
3188 }
3189
3190 DEFUN (no_neighbor_solo,
3191 no_neighbor_solo_cmd,
3192 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3193 NO_STR
3194 NEIGHBOR_STR
3195 NEIGHBOR_ADDR_STR2
3196 "Solo peer - part of its own update group\n")
3197 {
3198 int idx_peer = 2;
3199 struct peer *peer;
3200 int ret;
3201
3202 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3203 if (!peer)
3204 return CMD_WARNING_CONFIG_FAILED;
3205
3206 ret = update_group_adjust_soloness(peer, 0);
3207 return bgp_vty_return(vty, ret);
3208 }
3209
3210 DEFUN (neighbor_password,
3211 neighbor_password_cmd,
3212 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3213 NEIGHBOR_STR
3214 NEIGHBOR_ADDR_STR2
3215 "Set a password\n"
3216 "The password\n")
3217 {
3218 int idx_peer = 1;
3219 int idx_line = 3;
3220 struct peer *peer;
3221 int ret;
3222
3223 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3224 if (!peer)
3225 return CMD_WARNING_CONFIG_FAILED;
3226
3227 ret = peer_password_set(peer, argv[idx_line]->arg);
3228 return bgp_vty_return(vty, ret);
3229 }
3230
3231 DEFUN (no_neighbor_password,
3232 no_neighbor_password_cmd,
3233 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3234 NO_STR
3235 NEIGHBOR_STR
3236 NEIGHBOR_ADDR_STR2
3237 "Set a password\n"
3238 "The password\n")
3239 {
3240 int idx_peer = 2;
3241 struct peer *peer;
3242 int ret;
3243
3244 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3245 if (!peer)
3246 return CMD_WARNING_CONFIG_FAILED;
3247
3248 ret = peer_password_unset(peer);
3249 return bgp_vty_return(vty, ret);
3250 }
3251
3252 DEFUN (neighbor_activate,
3253 neighbor_activate_cmd,
3254 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3255 NEIGHBOR_STR
3256 NEIGHBOR_ADDR_STR2
3257 "Enable the Address Family for this Neighbor\n")
3258 {
3259 int idx_peer = 1;
3260 int ret;
3261 struct peer *peer;
3262
3263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3264 if (!peer)
3265 return CMD_WARNING_CONFIG_FAILED;
3266
3267 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3268 return bgp_vty_return(vty, ret);
3269 }
3270
3271 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3272 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3273 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3274 "Enable the Address Family for this Neighbor\n")
3275
3276 DEFUN (no_neighbor_activate,
3277 no_neighbor_activate_cmd,
3278 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3279 NO_STR
3280 NEIGHBOR_STR
3281 NEIGHBOR_ADDR_STR2
3282 "Enable the Address Family for this Neighbor\n")
3283 {
3284 int idx_peer = 2;
3285 int ret;
3286 struct peer *peer;
3287
3288 /* Lookup peer. */
3289 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3290 if (!peer)
3291 return CMD_WARNING_CONFIG_FAILED;
3292
3293 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3294 return bgp_vty_return(vty, ret);
3295 }
3296
3297 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3298 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3299 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3300 "Enable the Address Family for this Neighbor\n")
3301
3302 DEFUN (neighbor_set_peer_group,
3303 neighbor_set_peer_group_cmd,
3304 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3305 NEIGHBOR_STR
3306 NEIGHBOR_ADDR_STR2
3307 "Member of the peer-group\n"
3308 "Peer-group name\n")
3309 {
3310 VTY_DECLVAR_CONTEXT(bgp, bgp);
3311 int idx_peer = 1;
3312 int idx_word = 3;
3313 int ret;
3314 as_t as;
3315 union sockunion su;
3316 struct peer *peer;
3317 struct peer_group *group;
3318
3319 peer = NULL;
3320
3321 ret = str2sockunion(argv[idx_peer]->arg, &su);
3322 if (ret < 0) {
3323 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3324 if (!peer) {
3325 vty_out(vty, "%% Malformed address or name: %s\n",
3326 argv[idx_peer]->arg);
3327 return CMD_WARNING_CONFIG_FAILED;
3328 }
3329 } else {
3330 if (peer_address_self_check(bgp, &su)) {
3331 vty_out(vty,
3332 "%% Can not configure the local system as neighbor\n");
3333 return CMD_WARNING_CONFIG_FAILED;
3334 }
3335
3336 /* Disallow for dynamic neighbor. */
3337 peer = peer_lookup(bgp, &su);
3338 if (peer && peer_dynamic_neighbor(peer)) {
3339 vty_out(vty,
3340 "%% Operation not allowed on a dynamic neighbor\n");
3341 return CMD_WARNING_CONFIG_FAILED;
3342 }
3343 }
3344
3345 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3346 if (!group) {
3347 vty_out(vty, "%% Configure the peer-group first\n");
3348 return CMD_WARNING_CONFIG_FAILED;
3349 }
3350
3351 ret = peer_group_bind(bgp, &su, peer, group, &as);
3352
3353 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3354 vty_out(vty,
3355 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3356 as);
3357 return CMD_WARNING_CONFIG_FAILED;
3358 }
3359
3360 return bgp_vty_return(vty, ret);
3361 }
3362
3363 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3364 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3365 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3366 "Member of the peer-group\n"
3367 "Peer-group name\n")
3368
3369 DEFUN (no_neighbor_set_peer_group,
3370 no_neighbor_set_peer_group_cmd,
3371 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3372 NO_STR
3373 NEIGHBOR_STR
3374 NEIGHBOR_ADDR_STR2
3375 "Member of the peer-group\n"
3376 "Peer-group name\n")
3377 {
3378 VTY_DECLVAR_CONTEXT(bgp, bgp);
3379 int idx_peer = 2;
3380 int idx_word = 4;
3381 int ret;
3382 struct peer *peer;
3383 struct peer_group *group;
3384
3385 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3386 if (!peer)
3387 return CMD_WARNING_CONFIG_FAILED;
3388
3389 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3390 if (!group) {
3391 vty_out(vty, "%% Configure the peer-group first\n");
3392 return CMD_WARNING_CONFIG_FAILED;
3393 }
3394
3395 ret = peer_delete(peer);
3396
3397 return bgp_vty_return(vty, ret);
3398 }
3399
3400 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3401 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3402 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3403 "Member of the peer-group\n"
3404 "Peer-group name\n")
3405
3406 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3407 u_int16_t flag, int set)
3408 {
3409 int ret;
3410 struct peer *peer;
3411
3412 peer = peer_and_group_lookup_vty(vty, ip_str);
3413 if (!peer)
3414 return CMD_WARNING_CONFIG_FAILED;
3415
3416 /*
3417 * If 'neighbor <interface>', then this is for directly connected peers,
3418 * we should not accept disable-connected-check.
3419 */
3420 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3421 vty_out(vty,
3422 "%s is directly connected peer, cannot accept disable-"
3423 "connected-check\n",
3424 ip_str);
3425 return CMD_WARNING_CONFIG_FAILED;
3426 }
3427
3428 if (!set && flag == PEER_FLAG_SHUTDOWN)
3429 peer_tx_shutdown_message_unset(peer);
3430
3431 if (set)
3432 ret = peer_flag_set(peer, flag);
3433 else
3434 ret = peer_flag_unset(peer, flag);
3435
3436 return bgp_vty_return(vty, ret);
3437 }
3438
3439 static int peer_flag_set_vty(struct vty *vty, const char *ip_str,
3440 u_int16_t flag)
3441 {
3442 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3443 }
3444
3445 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3446 u_int16_t flag)
3447 {
3448 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3449 }
3450
3451 /* neighbor passive. */
3452 DEFUN (neighbor_passive,
3453 neighbor_passive_cmd,
3454 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3455 NEIGHBOR_STR
3456 NEIGHBOR_ADDR_STR2
3457 "Don't send open messages to this neighbor\n")
3458 {
3459 int idx_peer = 1;
3460 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3461 }
3462
3463 DEFUN (no_neighbor_passive,
3464 no_neighbor_passive_cmd,
3465 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3466 NO_STR
3467 NEIGHBOR_STR
3468 NEIGHBOR_ADDR_STR2
3469 "Don't send open messages to this neighbor\n")
3470 {
3471 int idx_peer = 2;
3472 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3473 }
3474
3475 /* neighbor shutdown. */
3476 DEFUN (neighbor_shutdown_msg,
3477 neighbor_shutdown_msg_cmd,
3478 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3479 NEIGHBOR_STR
3480 NEIGHBOR_ADDR_STR2
3481 "Administratively shut down this neighbor\n"
3482 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3483 "Shutdown message\n")
3484 {
3485 int idx_peer = 1;
3486
3487 if (argc >= 5) {
3488 struct peer *peer =
3489 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3490 char *message;
3491
3492 if (!peer)
3493 return CMD_WARNING_CONFIG_FAILED;
3494 message = argv_concat(argv, argc, 4);
3495 peer_tx_shutdown_message_set(peer, message);
3496 XFREE(MTYPE_TMP, message);
3497 }
3498
3499 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3500 }
3501
3502 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3503 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3504 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3505 "Administratively shut down this neighbor\n")
3506
3507 DEFUN (no_neighbor_shutdown_msg,
3508 no_neighbor_shutdown_msg_cmd,
3509 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3510 NO_STR
3511 NEIGHBOR_STR
3512 NEIGHBOR_ADDR_STR2
3513 "Administratively shut down this neighbor\n"
3514 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3515 "Shutdown message\n")
3516 {
3517 int idx_peer = 2;
3518
3519 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3520 PEER_FLAG_SHUTDOWN);
3521 }
3522
3523 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3524 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3525 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3526 "Administratively shut down this neighbor\n")
3527
3528 /* neighbor capability dynamic. */
3529 DEFUN (neighbor_capability_dynamic,
3530 neighbor_capability_dynamic_cmd,
3531 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3532 NEIGHBOR_STR
3533 NEIGHBOR_ADDR_STR2
3534 "Advertise capability to the peer\n"
3535 "Advertise dynamic capability to this neighbor\n")
3536 {
3537 int idx_peer = 1;
3538 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3539 PEER_FLAG_DYNAMIC_CAPABILITY);
3540 }
3541
3542 DEFUN (no_neighbor_capability_dynamic,
3543 no_neighbor_capability_dynamic_cmd,
3544 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3545 NO_STR
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 = 2;
3552 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3553 PEER_FLAG_DYNAMIC_CAPABILITY);
3554 }
3555
3556 /* neighbor dont-capability-negotiate */
3557 DEFUN (neighbor_dont_capability_negotiate,
3558 neighbor_dont_capability_negotiate_cmd,
3559 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3560 NEIGHBOR_STR
3561 NEIGHBOR_ADDR_STR2
3562 "Do not perform capability negotiation\n")
3563 {
3564 int idx_peer = 1;
3565 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3566 PEER_FLAG_DONT_CAPABILITY);
3567 }
3568
3569 DEFUN (no_neighbor_dont_capability_negotiate,
3570 no_neighbor_dont_capability_negotiate_cmd,
3571 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3572 NO_STR
3573 NEIGHBOR_STR
3574 NEIGHBOR_ADDR_STR2
3575 "Do not perform capability negotiation\n")
3576 {
3577 int idx_peer = 2;
3578 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3579 PEER_FLAG_DONT_CAPABILITY);
3580 }
3581
3582 /* neighbor capability extended next hop encoding */
3583 DEFUN (neighbor_capability_enhe,
3584 neighbor_capability_enhe_cmd,
3585 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3586 NEIGHBOR_STR
3587 NEIGHBOR_ADDR_STR2
3588 "Advertise capability to the peer\n"
3589 "Advertise extended next-hop capability to the peer\n")
3590 {
3591 int idx_peer = 1;
3592 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3593 PEER_FLAG_CAPABILITY_ENHE);
3594 }
3595
3596 DEFUN (no_neighbor_capability_enhe,
3597 no_neighbor_capability_enhe_cmd,
3598 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3599 NO_STR
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 = 2;
3606 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3607 PEER_FLAG_CAPABILITY_ENHE);
3608 }
3609
3610 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3611 afi_t afi, safi_t safi, u_int32_t flag,
3612 int set)
3613 {
3614 int ret;
3615 struct peer *peer;
3616
3617 peer = peer_and_group_lookup_vty(vty, peer_str);
3618 if (!peer)
3619 return CMD_WARNING_CONFIG_FAILED;
3620
3621 if (set)
3622 ret = peer_af_flag_set(peer, afi, safi, flag);
3623 else
3624 ret = peer_af_flag_unset(peer, afi, safi, flag);
3625
3626 return bgp_vty_return(vty, ret);
3627 }
3628
3629 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3630 afi_t afi, safi_t safi, u_int32_t flag)
3631 {
3632 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3633 }
3634
3635 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3636 afi_t afi, safi_t safi, u_int32_t flag)
3637 {
3638 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3639 }
3640
3641 /* neighbor capability orf prefix-list. */
3642 DEFUN (neighbor_capability_orf_prefix,
3643 neighbor_capability_orf_prefix_cmd,
3644 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
3647 "Advertise capability to the peer\n"
3648 "Advertise ORF capability to the peer\n"
3649 "Advertise prefixlist ORF capability to this neighbor\n"
3650 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3651 "Capability to RECEIVE the ORF from this neighbor\n"
3652 "Capability to SEND the ORF to this neighbor\n")
3653 {
3654 int idx_peer = 1;
3655 int idx_send_recv = 5;
3656 u_int16_t flag = 0;
3657
3658 if (strmatch(argv[idx_send_recv]->text, "send"))
3659 flag = PEER_FLAG_ORF_PREFIX_SM;
3660 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3661 flag = PEER_FLAG_ORF_PREFIX_RM;
3662 else if (strmatch(argv[idx_send_recv]->text, "both"))
3663 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3664 else {
3665 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3666 return CMD_WARNING_CONFIG_FAILED;
3667 }
3668
3669 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3670 bgp_node_safi(vty), flag);
3671 }
3672
3673 ALIAS_HIDDEN(
3674 neighbor_capability_orf_prefix,
3675 neighbor_capability_orf_prefix_hidden_cmd,
3676 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3677 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3678 "Advertise capability to the peer\n"
3679 "Advertise ORF capability to the peer\n"
3680 "Advertise prefixlist ORF capability to this neighbor\n"
3681 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3682 "Capability to RECEIVE the ORF from this neighbor\n"
3683 "Capability to SEND the ORF to this neighbor\n")
3684
3685 DEFUN (no_neighbor_capability_orf_prefix,
3686 no_neighbor_capability_orf_prefix_cmd,
3687 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3688 NO_STR
3689 NEIGHBOR_STR
3690 NEIGHBOR_ADDR_STR2
3691 "Advertise capability to the peer\n"
3692 "Advertise ORF capability to the peer\n"
3693 "Advertise prefixlist ORF capability to this neighbor\n"
3694 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3695 "Capability to RECEIVE the ORF from this neighbor\n"
3696 "Capability to SEND the ORF to this neighbor\n")
3697 {
3698 int idx_peer = 2;
3699 int idx_send_recv = 6;
3700 u_int16_t flag = 0;
3701
3702 if (strmatch(argv[idx_send_recv]->text, "send"))
3703 flag = PEER_FLAG_ORF_PREFIX_SM;
3704 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3705 flag = PEER_FLAG_ORF_PREFIX_RM;
3706 else if (strmatch(argv[idx_send_recv]->text, "both"))
3707 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3708 else {
3709 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3710 return CMD_WARNING_CONFIG_FAILED;
3711 }
3712
3713 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3714 bgp_node_afi(vty), bgp_node_safi(vty),
3715 flag);
3716 }
3717
3718 ALIAS_HIDDEN(
3719 no_neighbor_capability_orf_prefix,
3720 no_neighbor_capability_orf_prefix_hidden_cmd,
3721 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3722 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3723 "Advertise capability to the peer\n"
3724 "Advertise ORF capability to the peer\n"
3725 "Advertise prefixlist ORF capability to this neighbor\n"
3726 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3727 "Capability to RECEIVE the ORF from this neighbor\n"
3728 "Capability to SEND the ORF to this neighbor\n")
3729
3730 /* neighbor next-hop-self. */
3731 DEFUN (neighbor_nexthop_self,
3732 neighbor_nexthop_self_cmd,
3733 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3734 NEIGHBOR_STR
3735 NEIGHBOR_ADDR_STR2
3736 "Disable the next hop calculation for this neighbor\n")
3737 {
3738 int idx_peer = 1;
3739 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3740 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3741 }
3742
3743 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3744 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3745 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3746 "Disable the next hop calculation for this neighbor\n")
3747
3748 /* neighbor next-hop-self. */
3749 DEFUN (neighbor_nexthop_self_force,
3750 neighbor_nexthop_self_force_cmd,
3751 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3752 NEIGHBOR_STR
3753 NEIGHBOR_ADDR_STR2
3754 "Disable the next hop calculation for this neighbor\n"
3755 "Set the next hop to self for reflected routes\n")
3756 {
3757 int idx_peer = 1;
3758 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3759 bgp_node_safi(vty),
3760 PEER_FLAG_FORCE_NEXTHOP_SELF);
3761 }
3762
3763 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3764 neighbor_nexthop_self_force_hidden_cmd,
3765 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3767 "Disable the next hop calculation for this neighbor\n"
3768 "Set the next hop to self for reflected routes\n")
3769
3770 DEFUN (no_neighbor_nexthop_self,
3771 no_neighbor_nexthop_self_cmd,
3772 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3773 NO_STR
3774 NEIGHBOR_STR
3775 NEIGHBOR_ADDR_STR2
3776 "Disable the next hop calculation for this neighbor\n")
3777 {
3778 int idx_peer = 2;
3779 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3780 bgp_node_afi(vty), bgp_node_safi(vty),
3781 PEER_FLAG_NEXTHOP_SELF);
3782 }
3783
3784 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3785 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3786 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3787 "Disable the next hop calculation for this neighbor\n")
3788
3789 DEFUN (no_neighbor_nexthop_self_force,
3790 no_neighbor_nexthop_self_force_cmd,
3791 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3792 NO_STR
3793 NEIGHBOR_STR
3794 NEIGHBOR_ADDR_STR2
3795 "Disable the next hop calculation for this neighbor\n"
3796 "Set the next hop to self for reflected routes\n")
3797 {
3798 int idx_peer = 2;
3799 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3800 bgp_node_afi(vty), bgp_node_safi(vty),
3801 PEER_FLAG_FORCE_NEXTHOP_SELF);
3802 }
3803
3804 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3805 no_neighbor_nexthop_self_force_hidden_cmd,
3806 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3807 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3808 "Disable the next hop calculation for this neighbor\n"
3809 "Set the next hop to self for reflected routes\n")
3810
3811 /* neighbor as-override */
3812 DEFUN (neighbor_as_override,
3813 neighbor_as_override_cmd,
3814 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3815 NEIGHBOR_STR
3816 NEIGHBOR_ADDR_STR2
3817 "Override ASNs in outbound updates if aspath equals remote-as\n")
3818 {
3819 int idx_peer = 1;
3820 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3821 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3822 }
3823
3824 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3825 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3827 "Override ASNs in outbound updates if aspath equals remote-as\n")
3828
3829 DEFUN (no_neighbor_as_override,
3830 no_neighbor_as_override_cmd,
3831 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3832 NO_STR
3833 NEIGHBOR_STR
3834 NEIGHBOR_ADDR_STR2
3835 "Override ASNs in outbound updates if aspath equals remote-as\n")
3836 {
3837 int idx_peer = 2;
3838 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3839 bgp_node_afi(vty), bgp_node_safi(vty),
3840 PEER_FLAG_AS_OVERRIDE);
3841 }
3842
3843 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3844 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3845 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3846 "Override ASNs in outbound updates if aspath equals remote-as\n")
3847
3848 /* neighbor remove-private-AS. */
3849 DEFUN (neighbor_remove_private_as,
3850 neighbor_remove_private_as_cmd,
3851 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3852 NEIGHBOR_STR
3853 NEIGHBOR_ADDR_STR2
3854 "Remove private ASNs in outbound updates\n")
3855 {
3856 int idx_peer = 1;
3857 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3858 bgp_node_safi(vty),
3859 PEER_FLAG_REMOVE_PRIVATE_AS);
3860 }
3861
3862 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3863 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3864 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3865 "Remove private ASNs in outbound updates\n")
3866
3867 DEFUN (neighbor_remove_private_as_all,
3868 neighbor_remove_private_as_all_cmd,
3869 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3870 NEIGHBOR_STR
3871 NEIGHBOR_ADDR_STR2
3872 "Remove private ASNs in outbound updates\n"
3873 "Apply to all AS numbers\n")
3874 {
3875 int idx_peer = 1;
3876 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3877 bgp_node_safi(vty),
3878 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3879 }
3880
3881 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3882 neighbor_remove_private_as_all_hidden_cmd,
3883 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3884 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3885 "Remove private ASNs in outbound updates\n"
3886 "Apply to all AS numbers")
3887
3888 DEFUN (neighbor_remove_private_as_replace_as,
3889 neighbor_remove_private_as_replace_as_cmd,
3890 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3891 NEIGHBOR_STR
3892 NEIGHBOR_ADDR_STR2
3893 "Remove private ASNs in outbound updates\n"
3894 "Replace private ASNs with our ASN in outbound updates\n")
3895 {
3896 int idx_peer = 1;
3897 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3898 bgp_node_safi(vty),
3899 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3900 }
3901
3902 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3903 neighbor_remove_private_as_replace_as_hidden_cmd,
3904 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3905 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3906 "Remove private ASNs in outbound updates\n"
3907 "Replace private ASNs with our ASN in outbound updates\n")
3908
3909 DEFUN (neighbor_remove_private_as_all_replace_as,
3910 neighbor_remove_private_as_all_replace_as_cmd,
3911 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3912 NEIGHBOR_STR
3913 NEIGHBOR_ADDR_STR2
3914 "Remove private ASNs in outbound updates\n"
3915 "Apply to all AS numbers\n"
3916 "Replace private ASNs with our ASN in outbound updates\n")
3917 {
3918 int idx_peer = 1;
3919 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3920 bgp_node_safi(vty),
3921 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3922 }
3923
3924 ALIAS_HIDDEN(
3925 neighbor_remove_private_as_all_replace_as,
3926 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3927 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3929 "Remove private ASNs in outbound updates\n"
3930 "Apply to all AS numbers\n"
3931 "Replace private ASNs with our ASN in outbound updates\n")
3932
3933 DEFUN (no_neighbor_remove_private_as,
3934 no_neighbor_remove_private_as_cmd,
3935 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3936 NO_STR
3937 NEIGHBOR_STR
3938 NEIGHBOR_ADDR_STR2
3939 "Remove private ASNs in outbound updates\n")
3940 {
3941 int idx_peer = 2;
3942 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3943 bgp_node_afi(vty), bgp_node_safi(vty),
3944 PEER_FLAG_REMOVE_PRIVATE_AS);
3945 }
3946
3947 ALIAS_HIDDEN(no_neighbor_remove_private_as,
3948 no_neighbor_remove_private_as_hidden_cmd,
3949 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3950 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3951 "Remove private ASNs in outbound updates\n")
3952
3953 DEFUN (no_neighbor_remove_private_as_all,
3954 no_neighbor_remove_private_as_all_cmd,
3955 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3956 NO_STR
3957 NEIGHBOR_STR
3958 NEIGHBOR_ADDR_STR2
3959 "Remove private ASNs in outbound updates\n"
3960 "Apply to all AS numbers\n")
3961 {
3962 int idx_peer = 2;
3963 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3964 bgp_node_afi(vty), bgp_node_safi(vty),
3965 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3966 }
3967
3968 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3969 no_neighbor_remove_private_as_all_hidden_cmd,
3970 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3971 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3972 "Remove private ASNs in outbound updates\n"
3973 "Apply to all AS numbers\n")
3974
3975 DEFUN (no_neighbor_remove_private_as_replace_as,
3976 no_neighbor_remove_private_as_replace_as_cmd,
3977 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3978 NO_STR
3979 NEIGHBOR_STR
3980 NEIGHBOR_ADDR_STR2
3981 "Remove private ASNs in outbound updates\n"
3982 "Replace private ASNs with our ASN in outbound updates\n")
3983 {
3984 int idx_peer = 2;
3985 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3986 bgp_node_afi(vty), bgp_node_safi(vty),
3987 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3988 }
3989
3990 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
3991 no_neighbor_remove_private_as_replace_as_hidden_cmd,
3992 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3993 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3994 "Remove private ASNs in outbound updates\n"
3995 "Replace private ASNs with our ASN in outbound updates\n")
3996
3997 DEFUN (no_neighbor_remove_private_as_all_replace_as,
3998 no_neighbor_remove_private_as_all_replace_as_cmd,
3999 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4000 NO_STR
4001 NEIGHBOR_STR
4002 NEIGHBOR_ADDR_STR2
4003 "Remove private ASNs in outbound updates\n"
4004 "Apply to all AS numbers\n"
4005 "Replace private ASNs with our ASN in outbound updates\n")
4006 {
4007 int idx_peer = 2;
4008 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4009 bgp_node_afi(vty), bgp_node_safi(vty),
4010 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4011 }
4012
4013 ALIAS_HIDDEN(
4014 no_neighbor_remove_private_as_all_replace_as,
4015 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4017 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n"
4019 "Apply to all AS numbers\n"
4020 "Replace private ASNs with our ASN in outbound updates\n")
4021
4022
4023 /* neighbor send-community. */
4024 DEFUN (neighbor_send_community,
4025 neighbor_send_community_cmd,
4026 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4027 NEIGHBOR_STR
4028 NEIGHBOR_ADDR_STR2
4029 "Send Community attribute to this neighbor\n")
4030 {
4031 int idx_peer = 1;
4032 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4033 bgp_node_safi(vty),
4034 PEER_FLAG_SEND_COMMUNITY);
4035 }
4036
4037 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4038 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4039 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4040 "Send Community attribute to this neighbor\n")
4041
4042 DEFUN (no_neighbor_send_community,
4043 no_neighbor_send_community_cmd,
4044 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4045 NO_STR
4046 NEIGHBOR_STR
4047 NEIGHBOR_ADDR_STR2
4048 "Send Community attribute to this neighbor\n")
4049 {
4050 int idx_peer = 2;
4051 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4052 bgp_node_afi(vty), bgp_node_safi(vty),
4053 PEER_FLAG_SEND_COMMUNITY);
4054 }
4055
4056 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4057 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4058 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4059 "Send Community attribute to this neighbor\n")
4060
4061 /* neighbor send-community extended. */
4062 DEFUN (neighbor_send_community_type,
4063 neighbor_send_community_type_cmd,
4064 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4065 NEIGHBOR_STR
4066 NEIGHBOR_ADDR_STR2
4067 "Send Community attribute to this neighbor\n"
4068 "Send Standard and Extended Community attributes\n"
4069 "Send Standard, Large and Extended Community attributes\n"
4070 "Send Extended Community attributes\n"
4071 "Send Standard Community attributes\n"
4072 "Send Large Community attributes\n")
4073 {
4074 int idx = 0;
4075 u_int32_t flag = 0;
4076
4077 char *peer = argv[1]->arg;
4078
4079 if (argv_find(argv, argc, "standard", &idx))
4080 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4081 else if (argv_find(argv, argc, "extended", &idx))
4082 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4083 else if (argv_find(argv, argc, "large", &idx))
4084 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4085 else if (argv_find(argv, argc, "both", &idx)) {
4086 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4087 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4088 } else {
4089 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4090 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4091 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4092 }
4093
4094 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4095 bgp_node_safi(vty), flag);
4096 }
4097
4098 ALIAS_HIDDEN(
4099 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4100 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4101 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4102 "Send Community attribute to this neighbor\n"
4103 "Send Standard and Extended Community attributes\n"
4104 "Send Standard, Large and Extended Community attributes\n"
4105 "Send Extended Community attributes\n"
4106 "Send Standard Community attributes\n"
4107 "Send Large Community attributes\n")
4108
4109 DEFUN (no_neighbor_send_community_type,
4110 no_neighbor_send_community_type_cmd,
4111 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4112 NO_STR
4113 NEIGHBOR_STR
4114 NEIGHBOR_ADDR_STR2
4115 "Send Community attribute to this neighbor\n"
4116 "Send Standard and Extended Community attributes\n"
4117 "Send Standard, Large and Extended Community attributes\n"
4118 "Send Extended Community attributes\n"
4119 "Send Standard Community attributes\n"
4120 "Send Large Community attributes\n")
4121 {
4122 int idx_peer = 2;
4123
4124 const char *type = argv[argc - 1]->text;
4125
4126 if (strmatch(type, "standard"))
4127 return peer_af_flag_unset_vty(
4128 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4129 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4130 if (strmatch(type, "extended"))
4131 return peer_af_flag_unset_vty(
4132 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4133 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4134 if (strmatch(type, "large"))
4135 return peer_af_flag_unset_vty(
4136 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4137 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4138 if (strmatch(type, "both"))
4139 return peer_af_flag_unset_vty(
4140 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4141 bgp_node_safi(vty),
4142 PEER_FLAG_SEND_COMMUNITY
4143 | PEER_FLAG_SEND_EXT_COMMUNITY);
4144
4145 /* if (strmatch (type, "all")) */
4146 return peer_af_flag_unset_vty(
4147 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4148 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4149 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4150 }
4151
4152 ALIAS_HIDDEN(
4153 no_neighbor_send_community_type,
4154 no_neighbor_send_community_type_hidden_cmd,
4155 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4157 "Send Community attribute to this neighbor\n"
4158 "Send Standard and Extended Community attributes\n"
4159 "Send Standard, Large and Extended Community attributes\n"
4160 "Send Extended Community attributes\n"
4161 "Send Standard Community attributes\n"
4162 "Send Large Community attributes\n")
4163
4164 /* neighbor soft-reconfig. */
4165 DEFUN (neighbor_soft_reconfiguration,
4166 neighbor_soft_reconfiguration_cmd,
4167 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4168 NEIGHBOR_STR
4169 NEIGHBOR_ADDR_STR2
4170 "Per neighbor soft reconfiguration\n"
4171 "Allow inbound soft reconfiguration for this neighbor\n")
4172 {
4173 int idx_peer = 1;
4174 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4175 bgp_node_safi(vty),
4176 PEER_FLAG_SOFT_RECONFIG);
4177 }
4178
4179 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4180 neighbor_soft_reconfiguration_hidden_cmd,
4181 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4183 "Per neighbor soft reconfiguration\n"
4184 "Allow inbound soft reconfiguration for this neighbor\n")
4185
4186 DEFUN (no_neighbor_soft_reconfiguration,
4187 no_neighbor_soft_reconfiguration_cmd,
4188 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4189 NO_STR
4190 NEIGHBOR_STR
4191 NEIGHBOR_ADDR_STR2
4192 "Per neighbor soft reconfiguration\n"
4193 "Allow inbound soft reconfiguration for this neighbor\n")
4194 {
4195 int idx_peer = 2;
4196 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4197 bgp_node_afi(vty), bgp_node_safi(vty),
4198 PEER_FLAG_SOFT_RECONFIG);
4199 }
4200
4201 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4202 no_neighbor_soft_reconfiguration_hidden_cmd,
4203 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4204 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4205 "Per neighbor soft reconfiguration\n"
4206 "Allow inbound soft reconfiguration for this neighbor\n")
4207
4208 DEFUN (neighbor_route_reflector_client,
4209 neighbor_route_reflector_client_cmd,
4210 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4211 NEIGHBOR_STR
4212 NEIGHBOR_ADDR_STR2
4213 "Configure a neighbor as Route Reflector client\n")
4214 {
4215 int idx_peer = 1;
4216 struct peer *peer;
4217
4218
4219 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4220 if (!peer)
4221 return CMD_WARNING_CONFIG_FAILED;
4222
4223 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4224 bgp_node_safi(vty),
4225 PEER_FLAG_REFLECTOR_CLIENT);
4226 }
4227
4228 ALIAS_HIDDEN(neighbor_route_reflector_client,
4229 neighbor_route_reflector_client_hidden_cmd,
4230 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4231 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4232 "Configure a neighbor as Route Reflector client\n")
4233
4234 DEFUN (no_neighbor_route_reflector_client,
4235 no_neighbor_route_reflector_client_cmd,
4236 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4237 NO_STR
4238 NEIGHBOR_STR
4239 NEIGHBOR_ADDR_STR2
4240 "Configure a neighbor as Route Reflector client\n")
4241 {
4242 int idx_peer = 2;
4243 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4244 bgp_node_afi(vty), bgp_node_safi(vty),
4245 PEER_FLAG_REFLECTOR_CLIENT);
4246 }
4247
4248 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4249 no_neighbor_route_reflector_client_hidden_cmd,
4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4252 "Configure a neighbor as Route Reflector client\n")
4253
4254 /* neighbor route-server-client. */
4255 DEFUN (neighbor_route_server_client,
4256 neighbor_route_server_client_cmd,
4257 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4258 NEIGHBOR_STR
4259 NEIGHBOR_ADDR_STR2
4260 "Configure a neighbor as Route Server client\n")
4261 {
4262 int idx_peer = 1;
4263 struct peer *peer;
4264
4265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4266 if (!peer)
4267 return CMD_WARNING_CONFIG_FAILED;
4268 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4269 bgp_node_safi(vty),
4270 PEER_FLAG_RSERVER_CLIENT);
4271 }
4272
4273 ALIAS_HIDDEN(neighbor_route_server_client,
4274 neighbor_route_server_client_hidden_cmd,
4275 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4276 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4277 "Configure a neighbor as Route Server client\n")
4278
4279 DEFUN (no_neighbor_route_server_client,
4280 no_neighbor_route_server_client_cmd,
4281 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4282 NO_STR
4283 NEIGHBOR_STR
4284 NEIGHBOR_ADDR_STR2
4285 "Configure a neighbor as Route Server client\n")
4286 {
4287 int idx_peer = 2;
4288 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4289 bgp_node_afi(vty), bgp_node_safi(vty),
4290 PEER_FLAG_RSERVER_CLIENT);
4291 }
4292
4293 ALIAS_HIDDEN(no_neighbor_route_server_client,
4294 no_neighbor_route_server_client_hidden_cmd,
4295 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4296 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4297 "Configure a neighbor as Route Server client\n")
4298
4299 DEFUN (neighbor_nexthop_local_unchanged,
4300 neighbor_nexthop_local_unchanged_cmd,
4301 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4302 NEIGHBOR_STR
4303 NEIGHBOR_ADDR_STR2
4304 "Configure treatment of outgoing link-local nexthop attribute\n"
4305 "Leave link-local nexthop unchanged for this peer\n")
4306 {
4307 int idx_peer = 1;
4308 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4309 bgp_node_safi(vty),
4310 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4311 }
4312
4313 DEFUN (no_neighbor_nexthop_local_unchanged,
4314 no_neighbor_nexthop_local_unchanged_cmd,
4315 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4316 NO_STR
4317 NEIGHBOR_STR
4318 NEIGHBOR_ADDR_STR2
4319 "Configure treatment of outgoing link-local-nexthop attribute\n"
4320 "Leave link-local nexthop unchanged for this peer\n")
4321 {
4322 int idx_peer = 2;
4323 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4324 bgp_node_afi(vty), bgp_node_safi(vty),
4325 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4326 }
4327
4328 DEFUN (neighbor_attr_unchanged,
4329 neighbor_attr_unchanged_cmd,
4330 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4331 NEIGHBOR_STR
4332 NEIGHBOR_ADDR_STR2
4333 "BGP attribute is propagated unchanged to this neighbor\n"
4334 "As-path attribute\n"
4335 "Nexthop attribute\n"
4336 "Med attribute\n")
4337 {
4338 int idx = 0;
4339 char *peer_str = argv[1]->arg;
4340 struct peer *peer;
4341 u_int16_t flags = 0;
4342 afi_t afi = bgp_node_afi(vty);
4343 safi_t safi = bgp_node_safi(vty);
4344
4345 peer = peer_and_group_lookup_vty(vty, peer_str);
4346 if (!peer)
4347 return CMD_WARNING_CONFIG_FAILED;
4348
4349 if (argv_find(argv, argc, "as-path", &idx))
4350 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4351 idx = 0;
4352 if (argv_find(argv, argc, "next-hop", &idx))
4353 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4354 idx = 0;
4355 if (argv_find(argv, argc, "med", &idx))
4356 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4357
4358 /* no flags means all of them! */
4359 if (!flags) {
4360 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4361 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4362 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4363 } else {
4364 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4365 && peer_af_flag_check(peer, afi, safi,
4366 PEER_FLAG_AS_PATH_UNCHANGED)) {
4367 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4368 PEER_FLAG_AS_PATH_UNCHANGED);
4369 }
4370
4371 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4372 && peer_af_flag_check(peer, afi, safi,
4373 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4374 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4375 PEER_FLAG_NEXTHOP_UNCHANGED);
4376 }
4377
4378 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4379 && peer_af_flag_check(peer, afi, safi,
4380 PEER_FLAG_MED_UNCHANGED)) {
4381 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4382 PEER_FLAG_MED_UNCHANGED);
4383 }
4384 }
4385
4386 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4387 }
4388
4389 ALIAS_HIDDEN(
4390 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4391 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4392 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4393 "BGP attribute is propagated unchanged to this neighbor\n"
4394 "As-path attribute\n"
4395 "Nexthop attribute\n"
4396 "Med attribute\n")
4397
4398 DEFUN (no_neighbor_attr_unchanged,
4399 no_neighbor_attr_unchanged_cmd,
4400 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4401 NO_STR
4402 NEIGHBOR_STR
4403 NEIGHBOR_ADDR_STR2
4404 "BGP attribute is propagated unchanged to this neighbor\n"
4405 "As-path attribute\n"
4406 "Nexthop attribute\n"
4407 "Med attribute\n")
4408 {
4409 int idx = 0;
4410 char *peer = argv[2]->arg;
4411 u_int16_t flags = 0;
4412
4413 if (argv_find(argv, argc, "as-path", &idx))
4414 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4415 idx = 0;
4416 if (argv_find(argv, argc, "next-hop", &idx))
4417 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4418 idx = 0;
4419 if (argv_find(argv, argc, "med", &idx))
4420 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4421
4422 if (!flags) // no flags means all of them!
4423 {
4424 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4425 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4426 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4427 }
4428
4429 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4430 bgp_node_safi(vty), flags);
4431 }
4432
4433 ALIAS_HIDDEN(
4434 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4435 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4436 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4437 "BGP attribute is propagated unchanged to this neighbor\n"
4438 "As-path attribute\n"
4439 "Nexthop attribute\n"
4440 "Med attribute\n")
4441
4442 /* EBGP multihop configuration. */
4443 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4444 const char *ttl_str)
4445 {
4446 struct peer *peer;
4447 unsigned int ttl;
4448
4449 peer = peer_and_group_lookup_vty(vty, ip_str);
4450 if (!peer)
4451 return CMD_WARNING_CONFIG_FAILED;
4452
4453 if (peer->conf_if)
4454 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4455
4456 if (!ttl_str)
4457 ttl = MAXTTL;
4458 else
4459 ttl = strtoul(ttl_str, NULL, 10);
4460
4461 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4462 }
4463
4464 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4465 {
4466 struct peer *peer;
4467
4468 peer = peer_and_group_lookup_vty(vty, ip_str);
4469 if (!peer)
4470 return CMD_WARNING_CONFIG_FAILED;
4471
4472 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4473 }
4474
4475 /* neighbor ebgp-multihop. */
4476 DEFUN (neighbor_ebgp_multihop,
4477 neighbor_ebgp_multihop_cmd,
4478 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4479 NEIGHBOR_STR
4480 NEIGHBOR_ADDR_STR2
4481 "Allow EBGP neighbors not on directly connected networks\n")
4482 {
4483 int idx_peer = 1;
4484 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4485 }
4486
4487 DEFUN (neighbor_ebgp_multihop_ttl,
4488 neighbor_ebgp_multihop_ttl_cmd,
4489 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4490 NEIGHBOR_STR
4491 NEIGHBOR_ADDR_STR2
4492 "Allow EBGP neighbors not on directly connected networks\n"
4493 "maximum hop count\n")
4494 {
4495 int idx_peer = 1;
4496 int idx_number = 3;
4497 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4498 argv[idx_number]->arg);
4499 }
4500
4501 DEFUN (no_neighbor_ebgp_multihop,
4502 no_neighbor_ebgp_multihop_cmd,
4503 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4504 NO_STR
4505 NEIGHBOR_STR
4506 NEIGHBOR_ADDR_STR2
4507 "Allow EBGP neighbors not on directly connected networks\n"
4508 "maximum hop count\n")
4509 {
4510 int idx_peer = 2;
4511 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4512 }
4513
4514
4515 /* disable-connected-check */
4516 DEFUN (neighbor_disable_connected_check,
4517 neighbor_disable_connected_check_cmd,
4518 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4519 NEIGHBOR_STR
4520 NEIGHBOR_ADDR_STR2
4521 "one-hop away EBGP peer using loopback address\n"
4522 "Enforce EBGP neighbors perform multihop\n")
4523 {
4524 int idx_peer = 1;
4525 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4526 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4527 }
4528
4529 DEFUN (no_neighbor_disable_connected_check,
4530 no_neighbor_disable_connected_check_cmd,
4531 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4532 NO_STR
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 = 2;
4539 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4540 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4541 }
4542
4543 DEFUN (neighbor_description,
4544 neighbor_description_cmd,
4545 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4546 NEIGHBOR_STR
4547 NEIGHBOR_ADDR_STR2
4548 "Neighbor specific description\n"
4549 "Up to 80 characters describing this neighbor\n")
4550 {
4551 int idx_peer = 1;
4552 int idx_line = 3;
4553 struct peer *peer;
4554 char *str;
4555
4556 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4557 if (!peer)
4558 return CMD_WARNING_CONFIG_FAILED;
4559
4560 str = argv_concat(argv, argc, idx_line);
4561
4562 peer_description_set(peer, str);
4563
4564 XFREE(MTYPE_TMP, str);
4565
4566 return CMD_SUCCESS;
4567 }
4568
4569 DEFUN (no_neighbor_description,
4570 no_neighbor_description_cmd,
4571 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
4572 NO_STR
4573 NEIGHBOR_STR
4574 NEIGHBOR_ADDR_STR2
4575 "Neighbor specific description\n"
4576 "Up to 80 characters describing this neighbor\n")
4577 {
4578 int idx_peer = 2;
4579 struct peer *peer;
4580
4581 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4582 if (!peer)
4583 return CMD_WARNING_CONFIG_FAILED;
4584
4585 peer_description_unset(peer);
4586
4587 return CMD_SUCCESS;
4588 }
4589
4590
4591 /* Neighbor update-source. */
4592 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4593 const char *source_str)
4594 {
4595 struct peer *peer;
4596 struct prefix p;
4597
4598 peer = peer_and_group_lookup_vty(vty, peer_str);
4599 if (!peer)
4600 return CMD_WARNING_CONFIG_FAILED;
4601
4602 if (peer->conf_if)
4603 return CMD_WARNING;
4604
4605 if (source_str) {
4606 union sockunion su;
4607 int ret = str2sockunion(source_str, &su);
4608
4609 if (ret == 0)
4610 peer_update_source_addr_set(peer, &su);
4611 else {
4612 if (str2prefix(source_str, &p)) {
4613 vty_out(vty,
4614 "%% Invalid update-source, remove prefix length \n");
4615 return CMD_WARNING_CONFIG_FAILED;
4616 } else
4617 peer_update_source_if_set(peer, source_str);
4618 }
4619 } else
4620 peer_update_source_unset(peer);
4621
4622 return CMD_SUCCESS;
4623 }
4624
4625 #define BGP_UPDATE_SOURCE_HELP_STR \
4626 "IPv4 address\n" \
4627 "IPv6 address\n" \
4628 "Interface name (requires zebra to be running)\n"
4629
4630 DEFUN (neighbor_update_source,
4631 neighbor_update_source_cmd,
4632 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4633 NEIGHBOR_STR
4634 NEIGHBOR_ADDR_STR2
4635 "Source of routing updates\n"
4636 BGP_UPDATE_SOURCE_HELP_STR)
4637 {
4638 int idx_peer = 1;
4639 int idx_peer_2 = 3;
4640 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4641 argv[idx_peer_2]->arg);
4642 }
4643
4644 DEFUN (no_neighbor_update_source,
4645 no_neighbor_update_source_cmd,
4646 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4647 NO_STR
4648 NEIGHBOR_STR
4649 NEIGHBOR_ADDR_STR2
4650 "Source of routing updates\n"
4651 BGP_UPDATE_SOURCE_HELP_STR)
4652 {
4653 int idx_peer = 2;
4654 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4655 }
4656
4657 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4658 afi_t afi, safi_t safi,
4659 const char *rmap, int set)
4660 {
4661 int ret;
4662 struct peer *peer;
4663
4664 peer = peer_and_group_lookup_vty(vty, peer_str);
4665 if (!peer)
4666 return CMD_WARNING_CONFIG_FAILED;
4667
4668 if (set)
4669 ret = peer_default_originate_set(peer, afi, safi, rmap);
4670 else
4671 ret = peer_default_originate_unset(peer, afi, safi);
4672
4673 return bgp_vty_return(vty, ret);
4674 }
4675
4676 /* neighbor default-originate. */
4677 DEFUN (neighbor_default_originate,
4678 neighbor_default_originate_cmd,
4679 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "Originate default route to this neighbor\n")
4683 {
4684 int idx_peer = 1;
4685 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4686 bgp_node_afi(vty),
4687 bgp_node_safi(vty), NULL, 1);
4688 }
4689
4690 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4691 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4692 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4693 "Originate default route to this neighbor\n")
4694
4695 DEFUN (neighbor_default_originate_rmap,
4696 neighbor_default_originate_rmap_cmd,
4697 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4698 NEIGHBOR_STR
4699 NEIGHBOR_ADDR_STR2
4700 "Originate default route to this neighbor\n"
4701 "Route-map to specify criteria to originate default\n"
4702 "route-map name\n")
4703 {
4704 int idx_peer = 1;
4705 int idx_word = 4;
4706 return peer_default_originate_set_vty(
4707 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4708 argv[idx_word]->arg, 1);
4709 }
4710
4711 ALIAS_HIDDEN(
4712 neighbor_default_originate_rmap,
4713 neighbor_default_originate_rmap_hidden_cmd,
4714 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4716 "Originate default route to this neighbor\n"
4717 "Route-map to specify criteria to originate default\n"
4718 "route-map name\n")
4719
4720 DEFUN (no_neighbor_default_originate,
4721 no_neighbor_default_originate_cmd,
4722 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4723 NO_STR
4724 NEIGHBOR_STR
4725 NEIGHBOR_ADDR_STR2
4726 "Originate default route to this neighbor\n"
4727 "Route-map to specify criteria to originate default\n"
4728 "route-map name\n")
4729 {
4730 int idx_peer = 2;
4731 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4732 bgp_node_afi(vty),
4733 bgp_node_safi(vty), NULL, 0);
4734 }
4735
4736 ALIAS_HIDDEN(
4737 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4738 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4739 NO_STR NEIGHBOR_STR 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
4745 /* Set neighbor's BGP port. */
4746 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4747 const char *port_str)
4748 {
4749 struct peer *peer;
4750 u_int16_t port;
4751 struct servent *sp;
4752
4753 peer = peer_lookup_vty(vty, ip_str);
4754 if (!peer)
4755 return CMD_WARNING_CONFIG_FAILED;
4756
4757 if (!port_str) {
4758 sp = getservbyname("bgp", "tcp");
4759 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4760 } else {
4761 port = strtoul(port_str, NULL, 10);
4762 }
4763
4764 peer_port_set(peer, port);
4765
4766 return CMD_SUCCESS;
4767 }
4768
4769 /* Set specified peer's BGP port. */
4770 DEFUN (neighbor_port,
4771 neighbor_port_cmd,
4772 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4773 NEIGHBOR_STR
4774 NEIGHBOR_ADDR_STR
4775 "Neighbor's BGP port\n"
4776 "TCP port number\n")
4777 {
4778 int idx_ip = 1;
4779 int idx_number = 3;
4780 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4781 argv[idx_number]->arg);
4782 }
4783
4784 DEFUN (no_neighbor_port,
4785 no_neighbor_port_cmd,
4786 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4787 NO_STR
4788 NEIGHBOR_STR
4789 NEIGHBOR_ADDR_STR
4790 "Neighbor's BGP port\n"
4791 "TCP port number\n")
4792 {
4793 int idx_ip = 2;
4794 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4795 }
4796
4797
4798 /* neighbor weight. */
4799 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4800 safi_t safi, const char *weight_str)
4801 {
4802 int ret;
4803 struct peer *peer;
4804 unsigned long weight;
4805
4806 peer = peer_and_group_lookup_vty(vty, ip_str);
4807 if (!peer)
4808 return CMD_WARNING_CONFIG_FAILED;
4809
4810 weight = strtoul(weight_str, NULL, 10);
4811
4812 ret = peer_weight_set(peer, afi, safi, weight);
4813 return bgp_vty_return(vty, ret);
4814 }
4815
4816 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4817 safi_t safi)
4818 {
4819 int ret;
4820 struct peer *peer;
4821
4822 peer = peer_and_group_lookup_vty(vty, ip_str);
4823 if (!peer)
4824 return CMD_WARNING_CONFIG_FAILED;
4825
4826 ret = peer_weight_unset(peer, afi, safi);
4827 return bgp_vty_return(vty, ret);
4828 }
4829
4830 DEFUN (neighbor_weight,
4831 neighbor_weight_cmd,
4832 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4833 NEIGHBOR_STR
4834 NEIGHBOR_ADDR_STR2
4835 "Set default weight for routes from this neighbor\n"
4836 "default weight\n")
4837 {
4838 int idx_peer = 1;
4839 int idx_number = 3;
4840 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4841 bgp_node_safi(vty), argv[idx_number]->arg);
4842 }
4843
4844 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4845 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4846 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4847 "Set default weight for routes from this neighbor\n"
4848 "default weight\n")
4849
4850 DEFUN (no_neighbor_weight,
4851 no_neighbor_weight_cmd,
4852 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4853 NO_STR
4854 NEIGHBOR_STR
4855 NEIGHBOR_ADDR_STR2
4856 "Set default weight for routes from this neighbor\n"
4857 "default weight\n")
4858 {
4859 int idx_peer = 2;
4860 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4861 bgp_node_afi(vty), bgp_node_safi(vty));
4862 }
4863
4864 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4865 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4867 "Set default weight for routes from this neighbor\n"
4868 "default weight\n")
4869
4870
4871 /* Override capability negotiation. */
4872 DEFUN (neighbor_override_capability,
4873 neighbor_override_capability_cmd,
4874 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4875 NEIGHBOR_STR
4876 NEIGHBOR_ADDR_STR2
4877 "Override capability negotiation result\n")
4878 {
4879 int idx_peer = 1;
4880 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4881 PEER_FLAG_OVERRIDE_CAPABILITY);
4882 }
4883
4884 DEFUN (no_neighbor_override_capability,
4885 no_neighbor_override_capability_cmd,
4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4887 NO_STR
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Override capability negotiation result\n")
4891 {
4892 int idx_peer = 2;
4893 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4894 PEER_FLAG_OVERRIDE_CAPABILITY);
4895 }
4896
4897 DEFUN (neighbor_strict_capability,
4898 neighbor_strict_capability_cmd,
4899 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4900 NEIGHBOR_STR
4901 NEIGHBOR_ADDR_STR
4902 "Strict capability negotiation match\n")
4903 {
4904 int idx_ip = 1;
4905 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4906 PEER_FLAG_STRICT_CAP_MATCH);
4907 }
4908
4909 DEFUN (no_neighbor_strict_capability,
4910 no_neighbor_strict_capability_cmd,
4911 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4912 NO_STR
4913 NEIGHBOR_STR
4914 NEIGHBOR_ADDR_STR
4915 "Strict capability negotiation match\n")
4916 {
4917 int idx_ip = 2;
4918 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4919 PEER_FLAG_STRICT_CAP_MATCH);
4920 }
4921
4922 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4923 const char *keep_str, const char *hold_str)
4924 {
4925 int ret;
4926 struct peer *peer;
4927 u_int32_t keepalive;
4928 u_int32_t holdtime;
4929
4930 peer = peer_and_group_lookup_vty(vty, ip_str);
4931 if (!peer)
4932 return CMD_WARNING_CONFIG_FAILED;
4933
4934 keepalive = strtoul(keep_str, NULL, 10);
4935 holdtime = strtoul(hold_str, NULL, 10);
4936
4937 ret = peer_timers_set(peer, keepalive, holdtime);
4938
4939 return bgp_vty_return(vty, ret);
4940 }
4941
4942 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
4943 {
4944 int ret;
4945 struct peer *peer;
4946
4947 peer = peer_and_group_lookup_vty(vty, ip_str);
4948 if (!peer)
4949 return CMD_WARNING_CONFIG_FAILED;
4950
4951 ret = peer_timers_unset(peer);
4952
4953 return bgp_vty_return(vty, ret);
4954 }
4955
4956 DEFUN (neighbor_timers,
4957 neighbor_timers_cmd,
4958 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
4959 NEIGHBOR_STR
4960 NEIGHBOR_ADDR_STR2
4961 "BGP per neighbor timers\n"
4962 "Keepalive interval\n"
4963 "Holdtime\n")
4964 {
4965 int idx_peer = 1;
4966 int idx_number = 3;
4967 int idx_number_2 = 4;
4968 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4969 argv[idx_number]->arg,
4970 argv[idx_number_2]->arg);
4971 }
4972
4973 DEFUN (no_neighbor_timers,
4974 no_neighbor_timers_cmd,
4975 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
4976 NO_STR
4977 NEIGHBOR_STR
4978 NEIGHBOR_ADDR_STR2
4979 "BGP per neighbor timers\n"
4980 "Keepalive interval\n"
4981 "Holdtime\n")
4982 {
4983 int idx_peer = 2;
4984 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
4985 }
4986
4987
4988 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
4989 const char *time_str)
4990 {
4991 int ret;
4992 struct peer *peer;
4993 u_int32_t connect;
4994
4995 peer = peer_and_group_lookup_vty(vty, ip_str);
4996 if (!peer)
4997 return CMD_WARNING_CONFIG_FAILED;
4998
4999 connect = strtoul(time_str, NULL, 10);
5000
5001 ret = peer_timers_connect_set(peer, connect);
5002
5003 return bgp_vty_return(vty, ret);
5004 }
5005
5006 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5007 {
5008 int ret;
5009 struct peer *peer;
5010
5011 peer = peer_and_group_lookup_vty(vty, ip_str);
5012 if (!peer)
5013 return CMD_WARNING_CONFIG_FAILED;
5014
5015 ret = peer_timers_connect_unset(peer);
5016
5017 return bgp_vty_return(vty, ret);
5018 }
5019
5020 DEFUN (neighbor_timers_connect,
5021 neighbor_timers_connect_cmd,
5022 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5023 NEIGHBOR_STR
5024 NEIGHBOR_ADDR_STR2
5025 "BGP per neighbor timers\n"
5026 "BGP connect timer\n"
5027 "Connect timer\n")
5028 {
5029 int idx_peer = 1;
5030 int idx_number = 4;
5031 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5032 argv[idx_number]->arg);
5033 }
5034
5035 DEFUN (no_neighbor_timers_connect,
5036 no_neighbor_timers_connect_cmd,
5037 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5038 NO_STR
5039 NEIGHBOR_STR
5040 NEIGHBOR_ADDR_STR2
5041 "BGP per neighbor timers\n"
5042 "BGP connect timer\n"
5043 "Connect timer\n")
5044 {
5045 int idx_peer = 2;
5046 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5047 }
5048
5049
5050 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5051 const char *time_str, int set)
5052 {
5053 int ret;
5054 struct peer *peer;
5055 u_int32_t routeadv = 0;
5056
5057 peer = peer_and_group_lookup_vty(vty, ip_str);
5058 if (!peer)
5059 return CMD_WARNING_CONFIG_FAILED;
5060
5061 if (time_str)
5062 routeadv = strtoul(time_str, NULL, 10);
5063
5064 if (set)
5065 ret = peer_advertise_interval_set(peer, routeadv);
5066 else
5067 ret = peer_advertise_interval_unset(peer);
5068
5069 return bgp_vty_return(vty, ret);
5070 }
5071
5072 DEFUN (neighbor_advertise_interval,
5073 neighbor_advertise_interval_cmd,
5074 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5075 NEIGHBOR_STR
5076 NEIGHBOR_ADDR_STR2
5077 "Minimum interval between sending BGP routing updates\n"
5078 "time in seconds\n")
5079 {
5080 int idx_peer = 1;
5081 int idx_number = 3;
5082 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5083 argv[idx_number]->arg, 1);
5084 }
5085
5086 DEFUN (no_neighbor_advertise_interval,
5087 no_neighbor_advertise_interval_cmd,
5088 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5089 NO_STR
5090 NEIGHBOR_STR
5091 NEIGHBOR_ADDR_STR2
5092 "Minimum interval between sending BGP routing updates\n"
5093 "time in seconds\n")
5094 {
5095 int idx_peer = 2;
5096 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5097 }
5098
5099
5100 /* Time to wait before processing route-map updates */
5101 DEFUN (bgp_set_route_map_delay_timer,
5102 bgp_set_route_map_delay_timer_cmd,
5103 "bgp route-map delay-timer (0-600)",
5104 SET_STR
5105 "BGP route-map delay timer\n"
5106 "Time in secs to wait before processing route-map changes\n"
5107 "0 disables the timer, no route updates happen when route-maps change\n")
5108 {
5109 int idx_number = 3;
5110 u_int32_t rmap_delay_timer;
5111
5112 if (argv[idx_number]->arg) {
5113 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5114 bm->rmap_update_timer = rmap_delay_timer;
5115
5116 /* if the dynamic update handling is being disabled, and a timer
5117 * is
5118 * running, stop the timer and act as if the timer has already
5119 * fired.
5120 */
5121 if (!rmap_delay_timer && bm->t_rmap_update) {
5122 BGP_TIMER_OFF(bm->t_rmap_update);
5123 thread_execute(bm->master, bgp_route_map_update_timer,
5124 NULL, 0);
5125 }
5126 return CMD_SUCCESS;
5127 } else {
5128 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5129 return CMD_WARNING_CONFIG_FAILED;
5130 }
5131 }
5132
5133 DEFUN (no_bgp_set_route_map_delay_timer,
5134 no_bgp_set_route_map_delay_timer_cmd,
5135 "no bgp route-map delay-timer [(0-600)]",
5136 NO_STR
5137 BGP_STR
5138 "Default BGP route-map delay timer\n"
5139 "Reset to default time to wait for processing route-map changes\n"
5140 "0 disables the timer, no route updates happen when route-maps change\n")
5141 {
5142
5143 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5144
5145 return CMD_SUCCESS;
5146 }
5147
5148
5149 /* neighbor interface */
5150 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5151 const char *str)
5152 {
5153 struct peer *peer;
5154
5155 peer = peer_lookup_vty(vty, ip_str);
5156 if (!peer || peer->conf_if) {
5157 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5158 return CMD_WARNING_CONFIG_FAILED;
5159 }
5160
5161 if (str)
5162 peer_interface_set(peer, str);
5163 else
5164 peer_interface_unset(peer);
5165
5166 return CMD_SUCCESS;
5167 }
5168
5169 DEFUN (neighbor_interface,
5170 neighbor_interface_cmd,
5171 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5172 NEIGHBOR_STR
5173 NEIGHBOR_ADDR_STR
5174 "Interface\n"
5175 "Interface name\n")
5176 {
5177 int idx_ip = 1;
5178 int idx_word = 3;
5179 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5180 }
5181
5182 DEFUN (no_neighbor_interface,
5183 no_neighbor_interface_cmd,
5184 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5185 NO_STR
5186 NEIGHBOR_STR
5187 NEIGHBOR_ADDR_STR2
5188 "Interface\n"
5189 "Interface name\n")
5190 {
5191 int idx_peer = 2;
5192 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5193 }
5194
5195 DEFUN (neighbor_distribute_list,
5196 neighbor_distribute_list_cmd,
5197 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5198 NEIGHBOR_STR
5199 NEIGHBOR_ADDR_STR2
5200 "Filter updates to/from this neighbor\n"
5201 "IP access-list number\n"
5202 "IP access-list number (expanded range)\n"
5203 "IP Access-list name\n"
5204 "Filter incoming updates\n"
5205 "Filter outgoing updates\n")
5206 {
5207 int idx_peer = 1;
5208 int idx_acl = 3;
5209 int direct, ret;
5210 struct peer *peer;
5211
5212 const char *pstr = argv[idx_peer]->arg;
5213 const char *acl = argv[idx_acl]->arg;
5214 const char *inout = argv[argc - 1]->text;
5215
5216 peer = peer_and_group_lookup_vty(vty, pstr);
5217 if (!peer)
5218 return CMD_WARNING_CONFIG_FAILED;
5219
5220 /* Check filter direction. */
5221 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5222 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5223 direct, acl);
5224
5225 return bgp_vty_return(vty, ret);
5226 }
5227
5228 ALIAS_HIDDEN(
5229 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5230 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5231 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5232 "Filter updates to/from this neighbor\n"
5233 "IP access-list number\n"
5234 "IP access-list number (expanded range)\n"
5235 "IP Access-list name\n"
5236 "Filter incoming updates\n"
5237 "Filter outgoing updates\n")
5238
5239 DEFUN (no_neighbor_distribute_list,
5240 no_neighbor_distribute_list_cmd,
5241 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5242 NO_STR
5243 NEIGHBOR_STR
5244 NEIGHBOR_ADDR_STR2
5245 "Filter updates to/from this neighbor\n"
5246 "IP access-list number\n"
5247 "IP access-list number (expanded range)\n"
5248 "IP Access-list name\n"
5249 "Filter incoming updates\n"
5250 "Filter outgoing updates\n")
5251 {
5252 int idx_peer = 2;
5253 int direct, ret;
5254 struct peer *peer;
5255
5256 const char *pstr = argv[idx_peer]->arg;
5257 const char *inout = argv[argc - 1]->text;
5258
5259 peer = peer_and_group_lookup_vty(vty, pstr);
5260 if (!peer)
5261 return CMD_WARNING_CONFIG_FAILED;
5262
5263 /* Check filter direction. */
5264 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5265 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5266 direct);
5267
5268 return bgp_vty_return(vty, ret);
5269 }
5270
5271 ALIAS_HIDDEN(
5272 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5273 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5274 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5275 "Filter updates to/from this neighbor\n"
5276 "IP access-list number\n"
5277 "IP access-list number (expanded range)\n"
5278 "IP Access-list name\n"
5279 "Filter incoming updates\n"
5280 "Filter outgoing updates\n")
5281
5282 /* Set prefix list to the peer. */
5283 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5284 afi_t afi, safi_t safi,
5285 const char *name_str,
5286 const char *direct_str)
5287 {
5288 int ret;
5289 struct peer *peer;
5290 int direct = FILTER_IN;
5291
5292 peer = peer_and_group_lookup_vty(vty, ip_str);
5293 if (!peer)
5294 return CMD_WARNING_CONFIG_FAILED;
5295
5296 /* Check filter direction. */
5297 if (strncmp(direct_str, "i", 1) == 0)
5298 direct = FILTER_IN;
5299 else if (strncmp(direct_str, "o", 1) == 0)
5300 direct = FILTER_OUT;
5301
5302 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5303
5304 return bgp_vty_return(vty, ret);
5305 }
5306
5307 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5308 afi_t afi, safi_t safi,
5309 const char *direct_str)
5310 {
5311 int ret;
5312 struct peer *peer;
5313 int direct = FILTER_IN;
5314
5315 peer = peer_and_group_lookup_vty(vty, ip_str);
5316 if (!peer)
5317 return CMD_WARNING_CONFIG_FAILED;
5318
5319 /* Check filter direction. */
5320 if (strncmp(direct_str, "i", 1) == 0)
5321 direct = FILTER_IN;
5322 else if (strncmp(direct_str, "o", 1) == 0)
5323 direct = FILTER_OUT;
5324
5325 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5326
5327 return bgp_vty_return(vty, ret);
5328 }
5329
5330 DEFUN (neighbor_prefix_list,
5331 neighbor_prefix_list_cmd,
5332 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Filter updates to/from this neighbor\n"
5336 "Name of a prefix list\n"
5337 "Filter incoming updates\n"
5338 "Filter outgoing updates\n")
5339 {
5340 int idx_peer = 1;
5341 int idx_word = 3;
5342 int idx_in_out = 4;
5343 return peer_prefix_list_set_vty(
5344 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5345 argv[idx_word]->arg, argv[idx_in_out]->arg);
5346 }
5347
5348 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5349 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5350 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5351 "Filter updates to/from this neighbor\n"
5352 "Name of a prefix list\n"
5353 "Filter incoming updates\n"
5354 "Filter outgoing updates\n")
5355
5356 DEFUN (no_neighbor_prefix_list,
5357 no_neighbor_prefix_list_cmd,
5358 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5359 NO_STR
5360 NEIGHBOR_STR
5361 NEIGHBOR_ADDR_STR2
5362 "Filter updates to/from this neighbor\n"
5363 "Name of a prefix list\n"
5364 "Filter incoming updates\n"
5365 "Filter outgoing updates\n")
5366 {
5367 int idx_peer = 2;
5368 int idx_in_out = 5;
5369 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5370 bgp_node_afi(vty), bgp_node_safi(vty),
5371 argv[idx_in_out]->arg);
5372 }
5373
5374 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5375 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5376 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5377 "Filter updates to/from this neighbor\n"
5378 "Name of a prefix list\n"
5379 "Filter incoming updates\n"
5380 "Filter outgoing updates\n")
5381
5382 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5383 safi_t safi, const char *name_str,
5384 const char *direct_str)
5385 {
5386 int ret;
5387 struct peer *peer;
5388 int direct = FILTER_IN;
5389
5390 peer = peer_and_group_lookup_vty(vty, ip_str);
5391 if (!peer)
5392 return CMD_WARNING_CONFIG_FAILED;
5393
5394 /* Check filter direction. */
5395 if (strncmp(direct_str, "i", 1) == 0)
5396 direct = FILTER_IN;
5397 else if (strncmp(direct_str, "o", 1) == 0)
5398 direct = FILTER_OUT;
5399
5400 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5401
5402 return bgp_vty_return(vty, ret);
5403 }
5404
5405 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5406 safi_t safi, const char *direct_str)
5407 {
5408 int ret;
5409 struct peer *peer;
5410 int direct = FILTER_IN;
5411
5412 peer = peer_and_group_lookup_vty(vty, ip_str);
5413 if (!peer)
5414 return CMD_WARNING_CONFIG_FAILED;
5415
5416 /* Check filter direction. */
5417 if (strncmp(direct_str, "i", 1) == 0)
5418 direct = FILTER_IN;
5419 else if (strncmp(direct_str, "o", 1) == 0)
5420 direct = FILTER_OUT;
5421
5422 ret = peer_aslist_unset(peer, afi, safi, direct);
5423
5424 return bgp_vty_return(vty, ret);
5425 }
5426
5427 DEFUN (neighbor_filter_list,
5428 neighbor_filter_list_cmd,
5429 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5430 NEIGHBOR_STR
5431 NEIGHBOR_ADDR_STR2
5432 "Establish BGP filters\n"
5433 "AS path access-list name\n"
5434 "Filter incoming routes\n"
5435 "Filter outgoing routes\n")
5436 {
5437 int idx_peer = 1;
5438 int idx_word = 3;
5439 int idx_in_out = 4;
5440 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5441 bgp_node_safi(vty), argv[idx_word]->arg,
5442 argv[idx_in_out]->arg);
5443 }
5444
5445 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5446 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5447 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5448 "Establish BGP filters\n"
5449 "AS path access-list name\n"
5450 "Filter incoming routes\n"
5451 "Filter outgoing routes\n")
5452
5453 DEFUN (no_neighbor_filter_list,
5454 no_neighbor_filter_list_cmd,
5455 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5456 NO_STR
5457 NEIGHBOR_STR
5458 NEIGHBOR_ADDR_STR2
5459 "Establish BGP filters\n"
5460 "AS path access-list name\n"
5461 "Filter incoming routes\n"
5462 "Filter outgoing routes\n")
5463 {
5464 int idx_peer = 2;
5465 int idx_in_out = 5;
5466 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5467 bgp_node_afi(vty), bgp_node_safi(vty),
5468 argv[idx_in_out]->arg);
5469 }
5470
5471 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5472 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5473 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5474 "Establish BGP filters\n"
5475 "AS path access-list name\n"
5476 "Filter incoming routes\n"
5477 "Filter outgoing routes\n")
5478
5479 /* Set route-map to the peer. */
5480 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5481 afi_t afi, safi_t safi, const char *name_str,
5482 const char *direct_str)
5483 {
5484 int ret;
5485 struct peer *peer;
5486 int direct = RMAP_IN;
5487
5488 peer = peer_and_group_lookup_vty(vty, ip_str);
5489 if (!peer)
5490 return CMD_WARNING_CONFIG_FAILED;
5491
5492 /* Check filter direction. */
5493 if (strncmp(direct_str, "in", 2) == 0)
5494 direct = RMAP_IN;
5495 else if (strncmp(direct_str, "o", 1) == 0)
5496 direct = RMAP_OUT;
5497
5498 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5499
5500 return bgp_vty_return(vty, ret);
5501 }
5502
5503 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5504 afi_t afi, safi_t safi,
5505 const char *direct_str)
5506 {
5507 int ret;
5508 struct peer *peer;
5509 int direct = RMAP_IN;
5510
5511 peer = peer_and_group_lookup_vty(vty, ip_str);
5512 if (!peer)
5513 return CMD_WARNING_CONFIG_FAILED;
5514
5515 /* Check filter direction. */
5516 if (strncmp(direct_str, "in", 2) == 0)
5517 direct = RMAP_IN;
5518 else if (strncmp(direct_str, "o", 1) == 0)
5519 direct = RMAP_OUT;
5520
5521 ret = peer_route_map_unset(peer, afi, safi, direct);
5522
5523 return bgp_vty_return(vty, ret);
5524 }
5525
5526 DEFUN (neighbor_route_map,
5527 neighbor_route_map_cmd,
5528 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5529 NEIGHBOR_STR
5530 NEIGHBOR_ADDR_STR2
5531 "Apply route map to neighbor\n"
5532 "Name of route map\n"
5533 "Apply map to incoming routes\n"
5534 "Apply map to outbound routes\n")
5535 {
5536 int idx_peer = 1;
5537 int idx_word = 3;
5538 int idx_in_out = 4;
5539 return peer_route_map_set_vty(
5540 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5541 argv[idx_word]->arg, argv[idx_in_out]->arg);
5542 }
5543
5544 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5545 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5546 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5547 "Apply route map to neighbor\n"
5548 "Name of route map\n"
5549 "Apply map to incoming routes\n"
5550 "Apply map to outbound routes\n")
5551
5552 DEFUN (no_neighbor_route_map,
5553 no_neighbor_route_map_cmd,
5554 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5555 NO_STR
5556 NEIGHBOR_STR
5557 NEIGHBOR_ADDR_STR2
5558 "Apply route map to neighbor\n"
5559 "Name of route map\n"
5560 "Apply map to incoming routes\n"
5561 "Apply map to outbound routes\n")
5562 {
5563 int idx_peer = 2;
5564 int idx_in_out = 5;
5565 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5566 bgp_node_afi(vty), bgp_node_safi(vty),
5567 argv[idx_in_out]->arg);
5568 }
5569
5570 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5571 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5572 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5573 "Apply route map to neighbor\n"
5574 "Name of route map\n"
5575 "Apply map to incoming routes\n"
5576 "Apply map to outbound routes\n")
5577
5578 /* Set unsuppress-map to the peer. */
5579 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5580 afi_t afi, safi_t safi,
5581 const char *name_str)
5582 {
5583 int ret;
5584 struct peer *peer;
5585
5586 peer = peer_and_group_lookup_vty(vty, ip_str);
5587 if (!peer)
5588 return CMD_WARNING_CONFIG_FAILED;
5589
5590 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5591
5592 return bgp_vty_return(vty, ret);
5593 }
5594
5595 /* Unset route-map from the peer. */
5596 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5597 afi_t afi, safi_t safi)
5598 {
5599 int ret;
5600 struct peer *peer;
5601
5602 peer = peer_and_group_lookup_vty(vty, ip_str);
5603 if (!peer)
5604 return CMD_WARNING_CONFIG_FAILED;
5605
5606 ret = peer_unsuppress_map_unset(peer, afi, safi);
5607
5608 return bgp_vty_return(vty, ret);
5609 }
5610
5611 DEFUN (neighbor_unsuppress_map,
5612 neighbor_unsuppress_map_cmd,
5613 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5614 NEIGHBOR_STR
5615 NEIGHBOR_ADDR_STR2
5616 "Route-map to selectively unsuppress suppressed routes\n"
5617 "Name of route map\n")
5618 {
5619 int idx_peer = 1;
5620 int idx_word = 3;
5621 return peer_unsuppress_map_set_vty(
5622 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5623 argv[idx_word]->arg);
5624 }
5625
5626 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5627 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5628 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5629 "Route-map to selectively unsuppress suppressed routes\n"
5630 "Name of route map\n")
5631
5632 DEFUN (no_neighbor_unsuppress_map,
5633 no_neighbor_unsuppress_map_cmd,
5634 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5635 NO_STR
5636 NEIGHBOR_STR
5637 NEIGHBOR_ADDR_STR2
5638 "Route-map to selectively unsuppress suppressed routes\n"
5639 "Name of route map\n")
5640 {
5641 int idx_peer = 2;
5642 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5643 bgp_node_afi(vty),
5644 bgp_node_safi(vty));
5645 }
5646
5647 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5648 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5649 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5650 "Route-map to selectively unsuppress suppressed routes\n"
5651 "Name of route map\n")
5652
5653 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5654 afi_t afi, safi_t safi,
5655 const char *num_str,
5656 const char *threshold_str, int warning,
5657 const char *restart_str)
5658 {
5659 int ret;
5660 struct peer *peer;
5661 u_int32_t max;
5662 u_char threshold;
5663 u_int16_t restart;
5664
5665 peer = peer_and_group_lookup_vty(vty, ip_str);
5666 if (!peer)
5667 return CMD_WARNING_CONFIG_FAILED;
5668
5669 max = strtoul(num_str, NULL, 10);
5670 if (threshold_str)
5671 threshold = atoi(threshold_str);
5672 else
5673 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5674
5675 if (restart_str)
5676 restart = atoi(restart_str);
5677 else
5678 restart = 0;
5679
5680 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5681 restart);
5682
5683 return bgp_vty_return(vty, ret);
5684 }
5685
5686 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5687 afi_t afi, safi_t safi)
5688 {
5689 int ret;
5690 struct peer *peer;
5691
5692 peer = peer_and_group_lookup_vty(vty, ip_str);
5693 if (!peer)
5694 return CMD_WARNING_CONFIG_FAILED;
5695
5696 ret = peer_maximum_prefix_unset(peer, afi, safi);
5697
5698 return bgp_vty_return(vty, ret);
5699 }
5700
5701 /* Maximum number of prefix configuration. prefix count is different
5702 for each peer configuration. So this configuration can be set for
5703 each peer configuration. */
5704 DEFUN (neighbor_maximum_prefix,
5705 neighbor_maximum_prefix_cmd,
5706 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5707 NEIGHBOR_STR
5708 NEIGHBOR_ADDR_STR2
5709 "Maximum number of prefix accept from this peer\n"
5710 "maximum no. of prefix limit\n")
5711 {
5712 int idx_peer = 1;
5713 int idx_number = 3;
5714 return peer_maximum_prefix_set_vty(
5715 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5716 argv[idx_number]->arg, NULL, 0, NULL);
5717 }
5718
5719 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5720 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5722 "Maximum number of prefix accept from this peer\n"
5723 "maximum no. of prefix limit\n")
5724
5725 DEFUN (neighbor_maximum_prefix_threshold,
5726 neighbor_maximum_prefix_threshold_cmd,
5727 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Maximum number of prefix accept from this peer\n"
5731 "maximum no. of prefix limit\n"
5732 "Threshold value (%) at which to generate a warning msg\n")
5733 {
5734 int idx_peer = 1;
5735 int idx_number = 3;
5736 int idx_number_2 = 4;
5737 return peer_maximum_prefix_set_vty(
5738 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5739 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5740 }
5741
5742 ALIAS_HIDDEN(
5743 neighbor_maximum_prefix_threshold,
5744 neighbor_maximum_prefix_threshold_hidden_cmd,
5745 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5746 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Maximum number of prefix accept from this peer\n"
5748 "maximum no. of prefix limit\n"
5749 "Threshold value (%) at which to generate a warning msg\n")
5750
5751 DEFUN (neighbor_maximum_prefix_warning,
5752 neighbor_maximum_prefix_warning_cmd,
5753 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5754 NEIGHBOR_STR
5755 NEIGHBOR_ADDR_STR2
5756 "Maximum number of prefix accept from this peer\n"
5757 "maximum no. of prefix limit\n"
5758 "Only give warning message when limit is exceeded\n")
5759 {
5760 int idx_peer = 1;
5761 int idx_number = 3;
5762 return peer_maximum_prefix_set_vty(
5763 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5764 argv[idx_number]->arg, NULL, 1, NULL);
5765 }
5766
5767 ALIAS_HIDDEN(
5768 neighbor_maximum_prefix_warning,
5769 neighbor_maximum_prefix_warning_hidden_cmd,
5770 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5772 "Maximum number of prefix accept from this peer\n"
5773 "maximum no. of prefix limit\n"
5774 "Only give warning message when limit is exceeded\n")
5775
5776 DEFUN (neighbor_maximum_prefix_threshold_warning,
5777 neighbor_maximum_prefix_threshold_warning_cmd,
5778 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5779 NEIGHBOR_STR
5780 NEIGHBOR_ADDR_STR2
5781 "Maximum number of prefix accept from this peer\n"
5782 "maximum no. of prefix limit\n"
5783 "Threshold value (%) at which to generate a warning msg\n"
5784 "Only give warning message when limit is exceeded\n")
5785 {
5786 int idx_peer = 1;
5787 int idx_number = 3;
5788 int idx_number_2 = 4;
5789 return peer_maximum_prefix_set_vty(
5790 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5791 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5792 }
5793
5794 ALIAS_HIDDEN(
5795 neighbor_maximum_prefix_threshold_warning,
5796 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5798 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5799 "Maximum number of prefix accept from this peer\n"
5800 "maximum no. of prefix limit\n"
5801 "Threshold value (%) at which to generate a warning msg\n"
5802 "Only give warning message when limit is exceeded\n")
5803
5804 DEFUN (neighbor_maximum_prefix_restart,
5805 neighbor_maximum_prefix_restart_cmd,
5806 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5807 NEIGHBOR_STR
5808 NEIGHBOR_ADDR_STR2
5809 "Maximum number of prefix accept from this peer\n"
5810 "maximum no. of prefix limit\n"
5811 "Restart bgp connection after limit is exceeded\n"
5812 "Restart interval in minutes\n")
5813 {
5814 int idx_peer = 1;
5815 int idx_number = 3;
5816 int idx_number_2 = 5;
5817 return peer_maximum_prefix_set_vty(
5818 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5819 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5820 }
5821
5822 ALIAS_HIDDEN(
5823 neighbor_maximum_prefix_restart,
5824 neighbor_maximum_prefix_restart_hidden_cmd,
5825 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5827 "Maximum number of prefix accept from this peer\n"
5828 "maximum no. of prefix limit\n"
5829 "Restart bgp connection after limit is exceeded\n"
5830 "Restart interval in minutes\n")
5831
5832 DEFUN (neighbor_maximum_prefix_threshold_restart,
5833 neighbor_maximum_prefix_threshold_restart_cmd,
5834 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5835 NEIGHBOR_STR
5836 NEIGHBOR_ADDR_STR2
5837 "Maximum number of prefixes to accept from this peer\n"
5838 "maximum no. of prefix limit\n"
5839 "Threshold value (%) at which to generate a warning msg\n"
5840 "Restart bgp connection after limit is exceeded\n"
5841 "Restart interval in minutes\n")
5842 {
5843 int idx_peer = 1;
5844 int idx_number = 3;
5845 int idx_number_2 = 4;
5846 int idx_number_3 = 6;
5847 return peer_maximum_prefix_set_vty(
5848 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5849 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5850 argv[idx_number_3]->arg);
5851 }
5852
5853 ALIAS_HIDDEN(
5854 neighbor_maximum_prefix_threshold_restart,
5855 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5856 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5857 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5858 "Maximum number of prefixes to accept from this peer\n"
5859 "maximum no. of prefix limit\n"
5860 "Threshold value (%) at which to generate a warning msg\n"
5861 "Restart bgp connection after limit is exceeded\n"
5862 "Restart interval in minutes\n")
5863
5864 DEFUN (no_neighbor_maximum_prefix,
5865 no_neighbor_maximum_prefix_cmd,
5866 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5867 NO_STR
5868 NEIGHBOR_STR
5869 NEIGHBOR_ADDR_STR2
5870 "Maximum number of prefixes to accept from this peer\n"
5871 "maximum no. of prefix limit\n"
5872 "Threshold value (%) at which to generate a warning msg\n"
5873 "Restart bgp connection after limit is exceeded\n"
5874 "Restart interval in minutes\n"
5875 "Only give warning message when limit is exceeded\n")
5876 {
5877 int idx_peer = 2;
5878 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5879 bgp_node_afi(vty),
5880 bgp_node_safi(vty));
5881 }
5882
5883 ALIAS_HIDDEN(
5884 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5885 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5886 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5887 "Maximum number of prefixes to accept from this peer\n"
5888 "maximum no. of prefix limit\n"
5889 "Threshold value (%) at which to generate a warning msg\n"
5890 "Restart bgp connection after limit is exceeded\n"
5891 "Restart interval in minutes\n"
5892 "Only give warning message when limit is exceeded\n")
5893
5894
5895 /* "neighbor allowas-in" */
5896 DEFUN (neighbor_allowas_in,
5897 neighbor_allowas_in_cmd,
5898 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5899 NEIGHBOR_STR
5900 NEIGHBOR_ADDR_STR2
5901 "Accept as-path with my AS present in it\n"
5902 "Number of occurances of AS number\n"
5903 "Only accept my AS in the as-path if the route was originated in my AS\n")
5904 {
5905 int idx_peer = 1;
5906 int idx_number_origin = 3;
5907 int ret;
5908 int origin = 0;
5909 struct peer *peer;
5910 int allow_num = 0;
5911
5912 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5913 if (!peer)
5914 return CMD_WARNING_CONFIG_FAILED;
5915
5916 if (argc <= idx_number_origin)
5917 allow_num = 3;
5918 else {
5919 if (argv[idx_number_origin]->type == WORD_TKN)
5920 origin = 1;
5921 else
5922 allow_num = atoi(argv[idx_number_origin]->arg);
5923 }
5924
5925 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5926 allow_num, origin);
5927
5928 return bgp_vty_return(vty, ret);
5929 }
5930
5931 ALIAS_HIDDEN(
5932 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5933 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5935 "Accept as-path with my AS present in it\n"
5936 "Number of occurances of AS number\n"
5937 "Only accept my AS in the as-path if the route was originated in my AS\n")
5938
5939 DEFUN (no_neighbor_allowas_in,
5940 no_neighbor_allowas_in_cmd,
5941 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5942 NO_STR
5943 NEIGHBOR_STR
5944 NEIGHBOR_ADDR_STR2
5945 "allow local ASN appears in aspath attribute\n"
5946 "Number of occurances of AS number\n"
5947 "Only accept my AS in the as-path if the route was originated in my AS\n")
5948 {
5949 int idx_peer = 2;
5950 int ret;
5951 struct peer *peer;
5952
5953 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5954 if (!peer)
5955 return CMD_WARNING_CONFIG_FAILED;
5956
5957 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5958 bgp_node_safi(vty));
5959
5960 return bgp_vty_return(vty, ret);
5961 }
5962
5963 ALIAS_HIDDEN(
5964 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5965 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5966 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "allow local ASN appears in aspath attribute\n"
5968 "Number of occurances of AS number\n"
5969 "Only accept my AS in the as-path if the route was originated in my AS\n")
5970
5971 DEFUN (neighbor_ttl_security,
5972 neighbor_ttl_security_cmd,
5973 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
5974 NEIGHBOR_STR
5975 NEIGHBOR_ADDR_STR2
5976 "BGP ttl-security parameters\n"
5977 "Specify the maximum number of hops to the BGP peer\n"
5978 "Number of hops to BGP peer\n")
5979 {
5980 int idx_peer = 1;
5981 int idx_number = 4;
5982 struct peer *peer;
5983 int gtsm_hops;
5984
5985 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5986 if (!peer)
5987 return CMD_WARNING_CONFIG_FAILED;
5988
5989 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
5990
5991 /*
5992 * If 'neighbor swpX', then this is for directly connected peers,
5993 * we should not accept a ttl-security hops value greater than 1.
5994 */
5995 if (peer->conf_if && (gtsm_hops > 1)) {
5996 vty_out(vty,
5997 "%s is directly connected peer, hops cannot exceed 1\n",
5998 argv[idx_peer]->arg);
5999 return CMD_WARNING_CONFIG_FAILED;
6000 }
6001
6002 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6003 }
6004
6005 DEFUN (no_neighbor_ttl_security,
6006 no_neighbor_ttl_security_cmd,
6007 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6008 NO_STR
6009 NEIGHBOR_STR
6010 NEIGHBOR_ADDR_STR2
6011 "BGP ttl-security parameters\n"
6012 "Specify the maximum number of hops to the BGP peer\n"
6013 "Number of hops to BGP peer\n")
6014 {
6015 int idx_peer = 2;
6016 struct peer *peer;
6017
6018 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6019 if (!peer)
6020 return CMD_WARNING_CONFIG_FAILED;
6021
6022 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6023 }
6024
6025 DEFUN (neighbor_addpath_tx_all_paths,
6026 neighbor_addpath_tx_all_paths_cmd,
6027 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6028 NEIGHBOR_STR
6029 NEIGHBOR_ADDR_STR2
6030 "Use addpath to advertise all paths to a neighbor\n")
6031 {
6032 int idx_peer = 1;
6033 struct peer *peer;
6034
6035 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6036 if (!peer)
6037 return CMD_WARNING_CONFIG_FAILED;
6038
6039 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6040 bgp_node_safi(vty),
6041 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6042 }
6043
6044 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6045 neighbor_addpath_tx_all_paths_hidden_cmd,
6046 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6047 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6048 "Use addpath to advertise all paths to a neighbor\n")
6049
6050 DEFUN (no_neighbor_addpath_tx_all_paths,
6051 no_neighbor_addpath_tx_all_paths_cmd,
6052 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6053 NO_STR
6054 NEIGHBOR_STR
6055 NEIGHBOR_ADDR_STR2
6056 "Use addpath to advertise all paths to a neighbor\n")
6057 {
6058 int idx_peer = 2;
6059 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6060 bgp_node_afi(vty), bgp_node_safi(vty),
6061 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6062 }
6063
6064 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6065 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6066 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6067 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6068 "Use addpath to advertise all paths to a neighbor\n")
6069
6070 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6071 neighbor_addpath_tx_bestpath_per_as_cmd,
6072 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6073 NEIGHBOR_STR
6074 NEIGHBOR_ADDR_STR2
6075 "Use addpath to advertise the bestpath per each neighboring AS\n")
6076 {
6077 int idx_peer = 1;
6078 struct peer *peer;
6079
6080 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6081 if (!peer)
6082 return CMD_WARNING_CONFIG_FAILED;
6083
6084 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6085 bgp_node_safi(vty),
6086 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6087 }
6088
6089 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6090 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6091 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6092 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6093 "Use addpath to advertise the bestpath per each neighboring AS\n")
6094
6095 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6096 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6098 NO_STR
6099 NEIGHBOR_STR
6100 NEIGHBOR_ADDR_STR2
6101 "Use addpath to advertise the bestpath per each neighboring AS\n")
6102 {
6103 int idx_peer = 2;
6104 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6105 bgp_node_afi(vty), bgp_node_safi(vty),
6106 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6107 }
6108
6109 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6110 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6113 "Use addpath to advertise the bestpath per each neighboring AS\n")
6114
6115 static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6116 struct ecommunity **list)
6117 {
6118 struct ecommunity *ecom = NULL;
6119 struct ecommunity *ecomadd;
6120
6121 for (; argc; --argc, ++argv) {
6122
6123 ecomadd = ecommunity_str2com(argv[0]->arg,
6124 ECOMMUNITY_ROUTE_TARGET, 0);
6125 if (!ecomadd) {
6126 vty_out(vty, "Malformed community-list value\n");
6127 if (ecom)
6128 ecommunity_free(&ecom);
6129 return CMD_WARNING_CONFIG_FAILED;
6130 }
6131
6132 if (ecom) {
6133 ecommunity_merge(ecom, ecomadd);
6134 ecommunity_free(&ecomadd);
6135 } else {
6136 ecom = ecomadd;
6137 }
6138 }
6139
6140 if (*list) {
6141 ecommunity_free(&*list);
6142 }
6143 *list = ecom;
6144
6145 return CMD_SUCCESS;
6146 }
6147
6148 static int vpn_policy_getafi(struct vty *vty, int *doafi)
6149 {
6150 switch (vty->node) {
6151 case BGP_IPV4_NODE:
6152 doafi[AFI_IP] = 1;
6153 break;
6154 case BGP_IPV6_NODE:
6155 doafi[AFI_IP6] = 1;
6156 break;
6157 default:
6158 vty_out(vty,
6159 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
6160 return CMD_WARNING_CONFIG_FAILED;
6161 }
6162 return CMD_SUCCESS;
6163 }
6164
6165 DEFPY (af_rd_vpn_export,
6166 af_rd_vpn_export_cmd,
6167 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6168 NO_STR
6169 "Specify route distinguisher\n"
6170 "Between current address-family and vpn\n"
6171 "For routes leaked from current address-family to vpn\n"
6172 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6173 {
6174 VTY_DECLVAR_CONTEXT(bgp, bgp);
6175 struct prefix_rd prd;
6176 int ret;
6177 int doafi[AFI_MAX] = {0};
6178 afi_t afi;
6179 int idx = 0;
6180 int yes = 1;
6181
6182 if (argv_find(argv, argc, "no", &idx))
6183 yes = 0;
6184
6185 if (yes) {
6186 ret = str2prefix_rd(rd_str, &prd);
6187 if (!ret) {
6188 vty_out(vty, "%% Malformed rd\n");
6189 return CMD_WARNING_CONFIG_FAILED;
6190 }
6191 }
6192
6193 ret = vpn_policy_getafi(vty, doafi);
6194 if (ret != CMD_SUCCESS)
6195 return ret;
6196
6197
6198 for (afi = 0; afi < AFI_MAX; ++afi) {
6199 if (!doafi[afi])
6200 continue;
6201
6202 /* pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6203 */
6204 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6205 bgp_get_default(), bgp);
6206
6207 if (yes) {
6208 bgp->vpn_policy[afi].tovpn_rd = prd;
6209 SET_FLAG(bgp->vpn_policy[afi].flags,
6210 BGP_VPN_POLICY_TOVPN_RD_SET);
6211 } else {
6212 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6213 BGP_VPN_POLICY_TOVPN_RD_SET);
6214 }
6215
6216 /* post-change: re-export vpn routes */
6217 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6218 bgp_get_default(), bgp);
6219 }
6220
6221 return CMD_SUCCESS;
6222 }
6223
6224 ALIAS (af_rd_vpn_export,
6225 af_no_rd_vpn_export_cmd,
6226 "no rd vpn export",
6227 NO_STR
6228 "Specify route distinguisher\n"
6229 "Between current address-family and vpn\n"
6230 "For routes leaked from current address-family to vpn\n")
6231
6232 DEFPY (af_label_vpn_export,
6233 af_label_vpn_export_cmd,
6234 "[no] label vpn export (0-1048575)$label_val",
6235 NO_STR
6236 "label value for VRF\n"
6237 "Between current address-family and vpn\n"
6238 "For routes leaked from current address-family to vpn\n"
6239 "Label Value <0-1048575>\n")
6240 {
6241 VTY_DECLVAR_CONTEXT(bgp, bgp);
6242 mpls_label_t label = MPLS_LABEL_NONE;
6243 int doafi[AFI_MAX] = {0};
6244 afi_t afi;
6245 int ret;
6246 int idx = 0;
6247 int yes = 1;
6248
6249 if (argv_find(argv, argc, "no", &idx))
6250 yes = 0;
6251
6252 if (yes)
6253 label = label_val; /* rely on parser to force unsigned */
6254
6255 ret = vpn_policy_getafi(vty, doafi);
6256 if (ret != CMD_SUCCESS)
6257 return ret;
6258
6259 for (afi = 0; afi < AFI_MAX; ++afi) {
6260 if (!doafi[afi])
6261 continue;
6262
6263 /*
6264 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6265 */
6266 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6267 bgp_get_default(), bgp);
6268
6269 bgp->vpn_policy[afi].tovpn_label = label;
6270
6271 /* post-change: re-export vpn routes */
6272 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6273 bgp_get_default(), bgp);
6274 }
6275
6276 return CMD_SUCCESS;
6277 }
6278
6279 ALIAS (af_label_vpn_export,
6280 af_no_label_vpn_export_cmd,
6281 "no label vpn export",
6282 NO_STR
6283 "label value for VRF\n"
6284 "Between current address-family and vpn\n"
6285 "For routes leaked from current address-family to vpn\n")
6286
6287 DEFPY (af_nexthop_vpn_export,
6288 af_nexthop_vpn_export_cmd,
6289 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6290 NO_STR
6291 "Specify next hop to use for VRF advertised prefixes\n"
6292 "Between current address-family and vpn\n"
6293 "For routes leaked from current address-family to vpn\n"
6294 "IPv4 prefix\n"
6295 "IPv6 prefix\n")
6296 {
6297 VTY_DECLVAR_CONTEXT(bgp, bgp);
6298 int doafi[AFI_MAX] = {0};
6299 afi_t afi;
6300 int ret;
6301 struct prefix p;
6302 int idx = 0;
6303 int yes = 1;
6304
6305 if (argv_find(argv, argc, "no", &idx))
6306 yes = 0;
6307
6308 if (yes) {
6309 if (!sockunion2hostprefix(nexthop_str, &p))
6310 return CMD_WARNING_CONFIG_FAILED;
6311 }
6312
6313 ret = vpn_policy_getafi(vty, doafi);
6314 if (ret != CMD_SUCCESS)
6315 return ret;
6316
6317 for (afi = 0; afi < AFI_MAX; ++afi) {
6318 if (!doafi[afi])
6319 continue;
6320
6321 /*
6322 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6323 */
6324 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6325 bgp_get_default(), bgp);
6326
6327 if (yes) {
6328 bgp->vpn_policy[afi].tovpn_nexthop = p;
6329 SET_FLAG(bgp->vpn_policy[afi].flags,
6330 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6331 } else {
6332 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6333 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
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
6341 return CMD_SUCCESS;
6342 }
6343
6344 ALIAS (af_nexthop_vpn_export,
6345 af_no_nexthop_vpn_export_cmd,
6346 "no nexthop vpn export",
6347 NO_STR
6348 "Specify next hop to use for VRF advertised prefixes\n"
6349 "Between current address-family and vpn\n"
6350 "For routes leaked from current address-family to vpn\n")
6351
6352 static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
6353 {
6354 if (!strcmp(dstr, "import")) {
6355 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6356 } else if (!strcmp(dstr, "export")) {
6357 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6358 } else if (!strcmp(dstr, "both")) {
6359 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6360 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6361 } else {
6362 vty_out(vty, "%% direction parse error\n");
6363 return CMD_WARNING_CONFIG_FAILED;
6364 }
6365 return CMD_SUCCESS;
6366 }
6367
6368 DEFPY (af_rt_vpn_imexport,
6369 af_rt_vpn_imexport_cmd,
6370 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6371 NO_STR
6372 "Specify route target list\n"
6373 "Specify route target list\n"
6374 "Between current address-family and vpn\n"
6375 "For routes leaked from vpn to current address-family: match any\n"
6376 "For routes leaked from current address-family to vpn: set\n"
6377 "both import: match any and export: set\n"
6378 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6379 {
6380 VTY_DECLVAR_CONTEXT(bgp, bgp);
6381 int ret;
6382 struct ecommunity *ecom = NULL;
6383 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6384 int doafi[AFI_MAX] = {0};
6385 vpn_policy_direction_t dir;
6386 afi_t afi;
6387 int idx = 0;
6388 int yes = 1;
6389
6390 if (argv_find(argv, argc, "no", &idx))
6391 yes = 0;
6392
6393 ret = vpn_policy_getafi(vty, doafi);
6394 if (ret != CMD_SUCCESS)
6395 return ret;
6396
6397 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6398 if (ret != CMD_SUCCESS)
6399 return ret;
6400
6401 if (yes) {
6402 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6403 vty_out(vty, "%% Missing RTLIST\n");
6404 return CMD_WARNING_CONFIG_FAILED;
6405 }
6406 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6407 if (ret != CMD_SUCCESS) {
6408 return ret;
6409 }
6410 }
6411
6412 for (afi = 0; afi < AFI_MAX; ++afi) {
6413 if (!doafi[afi])
6414 continue;
6415 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6416 if (!dodir[dir])
6417 continue;
6418
6419 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6420
6421 if (yes) {
6422 if (bgp->vpn_policy[afi].rtlist[dir])
6423 ecommunity_free(
6424 &bgp->vpn_policy[afi].rtlist[dir]);
6425 bgp->vpn_policy[afi].rtlist[dir] =
6426 ecommunity_dup(ecom);
6427 } else {
6428 if (bgp->vpn_policy[afi].rtlist[dir])
6429 ecommunity_free(
6430 &bgp->vpn_policy[afi].rtlist[dir]);
6431 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6432 }
6433
6434 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6435 }
6436 }
6437 ecommunity_free(&ecom);
6438
6439 return CMD_SUCCESS;
6440 }
6441
6442 ALIAS (af_rt_vpn_imexport,
6443 af_no_rt_vpn_imexport_cmd,
6444 "no <rt|route-target> vpn <import|export|both>$direction_str",
6445 NO_STR
6446 "Specify route target list\n"
6447 "Specify route target list\n"
6448 "Between current address-family and vpn\n"
6449 "For routes leaked from vpn to current address-family\n"
6450 "For routes leaked from current address-family to vpn\n"
6451 "both import and export\n")
6452
6453 DEFPY (af_route_map_vpn_imexport,
6454 af_route_map_vpn_imexport_cmd,
6455 /* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6456 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6457 NO_STR
6458 "Specify route map\n"
6459 "Between current address-family and vpn\n"
6460 "For routes leaked from vpn to current address-family\n"
6461 "For routes leaked from current address-family to vpn\n"
6462 "name of route-map\n")
6463 {
6464 VTY_DECLVAR_CONTEXT(bgp, bgp);
6465 int ret;
6466 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6467 int doafi[AFI_MAX] = {0};
6468 vpn_policy_direction_t dir;
6469 afi_t afi;
6470 int idx = 0;
6471 int yes = 1;
6472
6473 if (argv_find(argv, argc, "no", &idx))
6474 yes = 0;
6475
6476 ret = vpn_policy_getafi(vty, doafi);
6477 if (ret != CMD_SUCCESS)
6478 return ret;
6479
6480 ret = vpn_policy_getdirs(vty, direction_str, dodir);
6481 if (ret != CMD_SUCCESS)
6482 return ret;
6483
6484 for (afi = 0; afi < AFI_MAX; ++afi) {
6485 if (!doafi[afi])
6486 continue;
6487 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6488 if (!dodir[dir])
6489 continue;
6490
6491 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6492
6493 if (yes) {
6494 if (bgp->vpn_policy[afi].rmap_name[dir])
6495 XFREE(MTYPE_ROUTE_MAP_NAME,
6496 bgp->vpn_policy[afi].rmap_name[dir]);
6497 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6498 MTYPE_ROUTE_MAP_NAME, rmap_str);
6499 bgp->vpn_policy[afi].rmap[dir] =
6500 route_map_lookup_by_name(rmap_str);
6501 } else {
6502 if (bgp->vpn_policy[afi].rmap_name[dir])
6503 XFREE(MTYPE_ROUTE_MAP_NAME,
6504 bgp->vpn_policy[afi].rmap_name[dir]);
6505 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6506 bgp->vpn_policy[afi].rmap[dir] = NULL;
6507 }
6508
6509 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6510 }
6511 }
6512
6513 return CMD_SUCCESS;
6514 }
6515
6516 ALIAS (af_route_map_vpn_imexport,
6517 af_no_route_map_vpn_imexport_cmd,
6518 "no route-map vpn <import|export>$direction_str",
6519 NO_STR
6520 "Specify route map\n"
6521 "Between current address-family and vpn\n"
6522 "For routes leaked from vpn to current address-family\n"
6523 "For routes leaked from current address-family to vpn\n")
6524
6525 /* This command is valid only in a bgp vrf instance or the default instance */
6526 DEFPY (bgp_imexport_vpn,
6527 bgp_imexport_vpn_cmd,
6528 "[no] <import|export>$direction_str vpn",
6529 "Export routes to another routing protocol\n"
6530 "to VPN RIB per vpn-policy")
6531 {
6532 VTY_DECLVAR_CONTEXT(bgp, bgp);
6533 int previous_state;
6534 afi_t afi;
6535 safi_t safi;
6536 int idx = 0;
6537 int yes = 1;
6538 int flag;
6539 vpn_policy_direction_t dir;
6540
6541 if (argv_find(argv, argc, "no", &idx))
6542 yes = 0;
6543
6544 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6545 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
6546
6547 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6548 return CMD_WARNING_CONFIG_FAILED;
6549 }
6550
6551 afi = bgp_node_afi(vty);
6552 safi = bgp_node_safi(vty);
6553 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6554 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6555 return CMD_WARNING_CONFIG_FAILED;
6556 }
6557
6558 if (!strcmp(direction_str, "import")) {
6559 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6560 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6561 } else if (!strcmp(direction_str, "export")) {
6562 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6563 dir = BGP_VPN_POLICY_DIR_TOVPN;
6564 } else {
6565 vty_out(vty, "%% unknown direction %s\n", direction_str);
6566 return CMD_WARNING_CONFIG_FAILED;
6567 }
6568
6569 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
6570
6571 if (yes) {
6572 SET_FLAG(bgp->af_flags[afi][safi], flag);
6573 if (!previous_state) {
6574 /* trigger export current vrf */
6575 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6576 }
6577 } else {
6578 if (previous_state) {
6579 /* trigger un-export current vrf */
6580 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6581 }
6582 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
6583 }
6584
6585 return CMD_SUCCESS;
6586 }
6587
6588 DEFUN_NOSH (address_family_ipv4_safi,
6589 address_family_ipv4_safi_cmd,
6590 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
6591 "Enter Address Family command mode\n"
6592 "Address Family\n"
6593 BGP_SAFI_WITH_LABEL_HELP_STR)
6594 {
6595
6596 if (argc == 3) {
6597 VTY_DECLVAR_CONTEXT(bgp, bgp);
6598 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6599 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6600 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6601 && safi != SAFI_EVPN) {
6602 vty_out(vty,
6603 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6604 return CMD_WARNING_CONFIG_FAILED;
6605 }
6606 vty->node = bgp_node_type(AFI_IP, safi);
6607 } else
6608 vty->node = BGP_IPV4_NODE;
6609
6610 return CMD_SUCCESS;
6611 }
6612
6613 DEFUN_NOSH (address_family_ipv6_safi,
6614 address_family_ipv6_safi_cmd,
6615 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
6616 "Enter Address Family command mode\n"
6617 "Address Family\n"
6618 BGP_SAFI_WITH_LABEL_HELP_STR)
6619 {
6620 if (argc == 3) {
6621 VTY_DECLVAR_CONTEXT(bgp, bgp);
6622 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6623 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6624 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6625 && safi != SAFI_EVPN) {
6626 vty_out(vty,
6627 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6628 return CMD_WARNING_CONFIG_FAILED;
6629 }
6630 vty->node = bgp_node_type(AFI_IP6, safi);
6631 } else
6632 vty->node = BGP_IPV6_NODE;
6633
6634 return CMD_SUCCESS;
6635 }
6636
6637 #ifdef KEEP_OLD_VPN_COMMANDS
6638 DEFUN_NOSH (address_family_vpnv4,
6639 address_family_vpnv4_cmd,
6640 "address-family vpnv4 [unicast]",
6641 "Enter Address Family command mode\n"
6642 "Address Family\n"
6643 "Address Family modifier\n")
6644 {
6645 vty->node = BGP_VPNV4_NODE;
6646 return CMD_SUCCESS;
6647 }
6648
6649 DEFUN_NOSH (address_family_vpnv6,
6650 address_family_vpnv6_cmd,
6651 "address-family vpnv6 [unicast]",
6652 "Enter Address Family command mode\n"
6653 "Address Family\n"
6654 "Address Family modifier\n")
6655 {
6656 vty->node = BGP_VPNV6_NODE;
6657 return CMD_SUCCESS;
6658 }
6659 #endif
6660
6661 DEFUN_NOSH (address_family_evpn,
6662 address_family_evpn_cmd,
6663 "address-family l2vpn evpn",
6664 "Enter Address Family command mode\n"
6665 "Address Family\n"
6666 "Address Family modifier\n")
6667 {
6668 VTY_DECLVAR_CONTEXT(bgp, bgp);
6669 vty->node = BGP_EVPN_NODE;
6670 return CMD_SUCCESS;
6671 }
6672
6673 DEFUN_NOSH (exit_address_family,
6674 exit_address_family_cmd,
6675 "exit-address-family",
6676 "Exit from Address Family configuration mode\n")
6677 {
6678 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6679 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6680 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6681 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6682 || vty->node == BGP_EVPN_NODE)
6683 vty->node = BGP_NODE;
6684 return CMD_SUCCESS;
6685 }
6686
6687 /* Recalculate bestpath and re-advertise a prefix */
6688 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6689 const char *ip_str, afi_t afi, safi_t safi,
6690 struct prefix_rd *prd)
6691 {
6692 int ret;
6693 struct prefix match;
6694 struct bgp_node *rn;
6695 struct bgp_node *rm;
6696 struct bgp *bgp;
6697 struct bgp_table *table;
6698 struct bgp_table *rib;
6699
6700 /* BGP structure lookup. */
6701 if (view_name) {
6702 bgp = bgp_lookup_by_name(view_name);
6703 if (bgp == NULL) {
6704 vty_out(vty, "%% Can't find BGP instance %s\n",
6705 view_name);
6706 return CMD_WARNING;
6707 }
6708 } else {
6709 bgp = bgp_get_default();
6710 if (bgp == NULL) {
6711 vty_out(vty, "%% No BGP process is configured\n");
6712 return CMD_WARNING;
6713 }
6714 }
6715
6716 /* Check IP address argument. */
6717 ret = str2prefix(ip_str, &match);
6718 if (!ret) {
6719 vty_out(vty, "%% address is malformed\n");
6720 return CMD_WARNING;
6721 }
6722
6723 match.family = afi2family(afi);
6724 rib = bgp->rib[afi][safi];
6725
6726 if (safi == SAFI_MPLS_VPN) {
6727 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6728 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6729 continue;
6730
6731 if ((table = rn->info) != NULL) {
6732 if ((rm = bgp_node_match(table, &match))
6733 != NULL) {
6734 if (rm->p.prefixlen
6735 == match.prefixlen) {
6736 SET_FLAG(rn->flags,
6737 BGP_NODE_USER_CLEAR);
6738 bgp_process(bgp, rm, afi, safi);
6739 }
6740 bgp_unlock_node(rm);
6741 }
6742 }
6743 }
6744 } else {
6745 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6746 if (rn->p.prefixlen == match.prefixlen) {
6747 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6748 bgp_process(bgp, rn, afi, safi);
6749 }
6750 bgp_unlock_node(rn);
6751 }
6752 }
6753
6754 return CMD_SUCCESS;
6755 }
6756
6757 /* one clear bgp command to rule them all */
6758 DEFUN (clear_ip_bgp_all,
6759 clear_ip_bgp_all_cmd,
6760 "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>]",
6761 CLEAR_STR
6762 IP_STR
6763 BGP_STR
6764 BGP_INSTANCE_HELP_STR
6765 BGP_AFI_HELP_STR
6766 BGP_SAFI_WITH_LABEL_HELP_STR
6767 "Clear all peers\n"
6768 "BGP neighbor address to clear\n"
6769 "BGP IPv6 neighbor to clear\n"
6770 "BGP neighbor on interface to clear\n"
6771 "Clear peers with the AS number\n"
6772 "Clear all external peers\n"
6773 "Clear all members of peer-group\n"
6774 "BGP peer-group name\n"
6775 BGP_SOFT_STR
6776 BGP_SOFT_IN_STR
6777 BGP_SOFT_OUT_STR
6778 BGP_SOFT_IN_STR
6779 "Push out prefix-list ORF and do inbound soft reconfig\n"
6780 BGP_SOFT_OUT_STR)
6781 {
6782 char *vrf = NULL;
6783
6784 afi_t afi = AFI_IP6;
6785 safi_t safi = SAFI_UNICAST;
6786 enum clear_sort clr_sort = clear_peer;
6787 enum bgp_clear_type clr_type;
6788 char *clr_arg = NULL;
6789
6790 int idx = 0;
6791
6792 /* clear [ip] bgp */
6793 if (argv_find(argv, argc, "ip", &idx))
6794 afi = AFI_IP;
6795
6796 /* [<view|vrf> VIEWVRFNAME] */
6797 if (argv_find(argv, argc, "view", &idx)
6798 || argv_find(argv, argc, "vrf", &idx)) {
6799 vrf = argv[idx + 1]->arg;
6800 idx += 2;
6801 }
6802
6803 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6804 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6805 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6806
6807 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6808 if (argv_find(argv, argc, "*", &idx)) {
6809 clr_sort = clear_all;
6810 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6811 clr_sort = clear_peer;
6812 clr_arg = argv[idx]->arg;
6813 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6814 clr_sort = clear_peer;
6815 clr_arg = argv[idx]->arg;
6816 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6817 clr_sort = clear_group;
6818 idx++;
6819 clr_arg = argv[idx]->arg;
6820 } else if (argv_find(argv, argc, "WORD", &idx)) {
6821 clr_sort = clear_peer;
6822 clr_arg = argv[idx]->arg;
6823 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6824 clr_sort = clear_as;
6825 clr_arg = argv[idx]->arg;
6826 } else if (argv_find(argv, argc, "external", &idx)) {
6827 clr_sort = clear_external;
6828 }
6829
6830 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6831 if (argv_find(argv, argc, "soft", &idx)) {
6832 if (argv_find(argv, argc, "in", &idx)
6833 || argv_find(argv, argc, "out", &idx))
6834 clr_type = strmatch(argv[idx]->text, "in")
6835 ? BGP_CLEAR_SOFT_IN
6836 : BGP_CLEAR_SOFT_OUT;
6837 else
6838 clr_type = BGP_CLEAR_SOFT_BOTH;
6839 } else if (argv_find(argv, argc, "in", &idx)) {
6840 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6841 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6842 : BGP_CLEAR_SOFT_IN;
6843 } else if (argv_find(argv, argc, "out", &idx)) {
6844 clr_type = BGP_CLEAR_SOFT_OUT;
6845 } else
6846 clr_type = BGP_CLEAR_SOFT_NONE;
6847
6848 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
6849 }
6850
6851 DEFUN (clear_ip_bgp_prefix,
6852 clear_ip_bgp_prefix_cmd,
6853 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
6854 CLEAR_STR
6855 IP_STR
6856 BGP_STR
6857 BGP_INSTANCE_HELP_STR
6858 "Clear bestpath and re-advertise\n"
6859 "IPv4 prefix\n")
6860 {
6861 char *vrf = NULL;
6862 char *prefix = NULL;
6863
6864 int idx = 0;
6865
6866 /* [<view|vrf> VIEWVRFNAME] */
6867 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
6868 vrf = argv[idx]->arg;
6869
6870 prefix = argv[argc - 1]->arg;
6871
6872 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
6873 }
6874
6875 DEFUN (clear_bgp_ipv6_safi_prefix,
6876 clear_bgp_ipv6_safi_prefix_cmd,
6877 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
6878 CLEAR_STR
6879 IP_STR
6880 BGP_STR
6881 "Address Family\n"
6882 BGP_SAFI_HELP_STR
6883 "Clear bestpath and re-advertise\n"
6884 "IPv6 prefix\n")
6885 {
6886 int idx_safi = 0;
6887 int idx_ipv6_prefix = 0;
6888 safi_t safi = SAFI_UNICAST;
6889 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
6890 argv[idx_ipv6_prefix]->arg : NULL;
6891
6892 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
6893 return bgp_clear_prefix(
6894 vty, NULL, prefix, AFI_IP6,
6895 safi, NULL);
6896 }
6897
6898 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6899 clear_bgp_instance_ipv6_safi_prefix_cmd,
6900 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
6901 CLEAR_STR
6902 IP_STR
6903 BGP_STR
6904 BGP_INSTANCE_HELP_STR
6905 "Address Family\n"
6906 BGP_SAFI_HELP_STR
6907 "Clear bestpath and re-advertise\n"
6908 "IPv6 prefix\n")
6909 {
6910 int idx_word = 3;
6911 int idx_safi = 0;
6912 int idx_ipv6_prefix = 0;
6913 safi_t safi = SAFI_UNICAST;
6914 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
6915 argv[idx_ipv6_prefix]->arg : NULL;
6916 /* [<view|vrf> VIEWVRFNAME] */
6917 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
6918 argv[idx_word]->arg : NULL;
6919
6920 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
6921
6922 return bgp_clear_prefix(
6923 vty, vrfview, prefix,
6924 AFI_IP6, safi, NULL);
6925 }
6926
6927 DEFUN (show_bgp_views,
6928 show_bgp_views_cmd,
6929 "show [ip] bgp views",
6930 SHOW_STR
6931 IP_STR
6932 BGP_STR
6933 "Show the defined BGP views\n")
6934 {
6935 struct list *inst = bm->bgp;
6936 struct listnode *node;
6937 struct bgp *bgp;
6938
6939 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6940 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6941 return CMD_WARNING;
6942 }
6943
6944 vty_out(vty, "Defined BGP views:\n");
6945 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6946 /* Skip VRFs. */
6947 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6948 continue;
6949 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6950 bgp->as);
6951 }
6952
6953 return CMD_SUCCESS;
6954 }
6955
6956 DEFUN (show_bgp_vrfs,
6957 show_bgp_vrfs_cmd,
6958 "show [ip] bgp vrfs [json]",
6959 SHOW_STR
6960 IP_STR
6961 BGP_STR
6962 "Show BGP VRFs\n"
6963 JSON_STR)
6964 {
6965 char buf[ETHER_ADDR_STRLEN];
6966 struct list *inst = bm->bgp;
6967 struct listnode *node;
6968 struct bgp *bgp;
6969 u_char uj = use_json(argc, argv);
6970 json_object *json = NULL;
6971 json_object *json_vrfs = NULL;
6972 int count = 0;
6973
6974 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6975 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6976 return CMD_WARNING;
6977 }
6978
6979 if (uj) {
6980 json = json_object_new_object();
6981 json_vrfs = json_object_new_object();
6982 }
6983
6984 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6985 const char *name, *type;
6986 struct peer *peer;
6987 struct listnode *node, *nnode;
6988 int peers_cfg, peers_estb;
6989 json_object *json_vrf = NULL;
6990
6991 /* Skip Views. */
6992 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6993 continue;
6994
6995 count++;
6996 if (!uj && count == 1)
6997 vty_out(vty,
6998 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
6999 "Type", "Id", "routerId", "#PeersVfg",
7000 "#PeersEstb", "Name", "L3-VNI", "Rmac");
7001
7002 peers_cfg = peers_estb = 0;
7003 if (uj)
7004 json_vrf = json_object_new_object();
7005
7006
7007 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7008 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7009 continue;
7010 peers_cfg++;
7011 if (peer->status == Established)
7012 peers_estb++;
7013 }
7014
7015 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7016 name = "Default";
7017 type = "DFLT";
7018 } else {
7019 name = bgp->name;
7020 type = "VRF";
7021 }
7022
7023
7024 if (uj) {
7025 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7026 ? -1
7027 : (int64_t)bgp->vrf_id;
7028 json_object_string_add(json_vrf, "type", type);
7029 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7030 json_object_string_add(json_vrf, "routerId",
7031 inet_ntoa(bgp->router_id));
7032 json_object_int_add(json_vrf, "numConfiguredPeers",
7033 peers_cfg);
7034 json_object_int_add(json_vrf, "numEstablishedPeers",
7035 peers_estb);
7036
7037 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
7038 json_object_string_add(
7039 json_vrf, "rmac",
7040 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7041 json_object_object_add(json_vrfs, name, json_vrf);
7042 } else
7043 vty_out(vty,
7044 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
7045 type,
7046 bgp->vrf_id == VRF_UNKNOWN ? -1
7047 : (int)bgp->vrf_id,
7048 inet_ntoa(bgp->router_id), peers_cfg,
7049 peers_estb, name, bgp->l3vni,
7050 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
7051 }
7052
7053 if (uj) {
7054 json_object_object_add(json, "vrfs", json_vrfs);
7055
7056 json_object_int_add(json, "totalVrfs", count);
7057
7058 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7059 json, JSON_C_TO_STRING_PRETTY));
7060 json_object_free(json);
7061 } else {
7062 if (count)
7063 vty_out(vty,
7064 "\nTotal number of VRFs (including default): %d\n",
7065 count);
7066 }
7067
7068 return CMD_SUCCESS;
7069 }
7070
7071 static void show_address_entry(struct hash_backet *backet, void *args)
7072 {
7073 struct vty *vty = (struct vty *)args;
7074 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
7075
7076 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
7077 addr->refcnt);
7078 }
7079
7080 static void show_tip_entry(struct hash_backet *backet, void *args)
7081 {
7082 struct vty *vty = (struct vty *)args;
7083 struct tip_addr *tip = (struct tip_addr *)backet->data;
7084
7085 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
7086 tip->refcnt);
7087 }
7088
7089 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7090 {
7091 vty_out(vty, "self nexthop database:\n");
7092 hash_iterate(bgp->address_hash,
7093 (void (*)(struct hash_backet *, void *))show_address_entry,
7094 vty);
7095
7096 vty_out(vty, "Tunnel-ip database:\n");
7097 hash_iterate(bgp->tip_hash,
7098 (void (*)(struct hash_backet *, void *))show_tip_entry,
7099 vty);
7100 }
7101
7102 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7103 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7104 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
7105 "martian next-hops\n"
7106 "martian next-hop database\n")
7107 {
7108 struct bgp *bgp = NULL;
7109 int idx = 0;
7110
7111 if (argv_find(argv, argc, "view", &idx)
7112 || argv_find(argv, argc, "vrf", &idx))
7113 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7114 else
7115 bgp = bgp_get_default();
7116
7117 if (!bgp) {
7118 vty_out(vty, "%% No BGP process is configured\n");
7119 return CMD_WARNING;
7120 }
7121 bgp_show_martian_nexthops(vty, bgp);
7122
7123 return CMD_SUCCESS;
7124 }
7125
7126 DEFUN (show_bgp_memory,
7127 show_bgp_memory_cmd,
7128 "show [ip] bgp memory",
7129 SHOW_STR
7130 IP_STR
7131 BGP_STR
7132 "Global BGP memory statistics\n")
7133 {
7134 char memstrbuf[MTYPE_MEMSTR_LEN];
7135 unsigned long count;
7136
7137 /* RIB related usage stats */
7138 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7139 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7140 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7141 count * sizeof(struct bgp_node)));
7142
7143 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7144 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7145 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7146 count * sizeof(struct bgp_info)));
7147 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7148 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7149 count,
7150 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7151 count * sizeof(struct bgp_info_extra)));
7152
7153 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7154 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7155 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7156 count * sizeof(struct bgp_static)));
7157
7158 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7159 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7160 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7161 count * sizeof(struct bpacket)));
7162
7163 /* Adj-In/Out */
7164 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7165 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7166 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7167 count * sizeof(struct bgp_adj_in)));
7168 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7169 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7170 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7171 count * sizeof(struct bgp_adj_out)));
7172
7173 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7174 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7175 count,
7176 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7177 count * sizeof(struct bgp_nexthop_cache)));
7178
7179 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7180 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7181 count,
7182 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7183 count * sizeof(struct bgp_damp_info)));
7184
7185 /* Attributes */
7186 count = attr_count();
7187 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7188 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7189 count * sizeof(struct attr)));
7190
7191 if ((count = attr_unknown_count()))
7192 vty_out(vty, "%ld unknown attributes\n", count);
7193
7194 /* AS_PATH attributes */
7195 count = aspath_count();
7196 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7197 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7198 count * sizeof(struct aspath)));
7199
7200 count = mtype_stats_alloc(MTYPE_AS_SEG);
7201 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7202 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7203 count * sizeof(struct assegment)));
7204
7205 /* Other attributes */
7206 if ((count = community_count()))
7207 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7208 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7209 count * sizeof(struct community)));
7210 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7211 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
7212 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7213 count * sizeof(struct ecommunity)));
7214 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7215 vty_out(vty,
7216 "%ld BGP large-community entries, using %s of memory\n",
7217 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7218 count * sizeof(struct lcommunity)));
7219
7220 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7221 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7222 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7223 count * sizeof(struct cluster_list)));
7224
7225 /* Peer related usage */
7226 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7227 vty_out(vty, "%ld peers, using %s of memory\n", count,
7228 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7229 count * sizeof(struct peer)));
7230
7231 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7232 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7233 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7234 count * sizeof(struct peer_group)));
7235
7236 /* Other */
7237 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7238 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7239 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7240 count * sizeof(struct hash)));
7241 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7242 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7243 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7244 count * sizeof(struct hash_backet)));
7245 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7246 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
7247 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7248 count * sizeof(regex_t)));
7249 return CMD_SUCCESS;
7250 }
7251
7252 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7253 {
7254 json_object *bestpath = json_object_new_object();
7255
7256 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7257 json_object_string_add(bestpath, "asPath", "ignore");
7258
7259 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7260 json_object_string_add(bestpath, "asPath", "confed");
7261
7262 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
7263 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7264 json_object_string_add(bestpath, "multiPathRelax",
7265 "as-set");
7266 else
7267 json_object_string_add(bestpath, "multiPathRelax",
7268 "true");
7269 } else
7270 json_object_string_add(bestpath, "multiPathRelax", "false");
7271
7272 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7273 json_object_string_add(bestpath, "compareRouterId", "true");
7274 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7275 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7276 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
7277 json_object_string_add(bestpath, "med", "confed");
7278 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7279 json_object_string_add(bestpath, "med",
7280 "missing-as-worst");
7281 else
7282 json_object_string_add(bestpath, "med", "true");
7283 }
7284
7285 json_object_object_add(json, "bestPath", bestpath);
7286 }
7287
7288 /* Show BGP peer's summary information. */
7289 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7290 u_char use_json, json_object *json)
7291 {
7292 struct peer *peer;
7293 struct listnode *node, *nnode;
7294 unsigned int count = 0, dn_count = 0;
7295 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7296 char neighbor_buf[VTY_BUFSIZ];
7297 int neighbor_col_default_width = 16;
7298 int len;
7299 int max_neighbor_width = 0;
7300 int pfx_rcd_safi;
7301 json_object *json_peer = NULL;
7302 json_object *json_peers = NULL;
7303
7304 /* labeled-unicast routes are installed in the unicast table so in order
7305 * to
7306 * display the correct PfxRcd value we must look at SAFI_UNICAST
7307 */
7308 if (safi == SAFI_LABELED_UNICAST)
7309 pfx_rcd_safi = SAFI_UNICAST;
7310 else
7311 pfx_rcd_safi = safi;
7312
7313 if (use_json) {
7314 if (json == NULL)
7315 json = json_object_new_object();
7316
7317 json_peers = json_object_new_object();
7318 } else {
7319 /* Loop over all neighbors that will be displayed to determine
7320 * how many
7321 * characters are needed for the Neighbor column
7322 */
7323 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7324 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7325 continue;
7326
7327 if (peer->afc[afi][safi]) {
7328 memset(dn_flag, '\0', sizeof(dn_flag));
7329 if (peer_dynamic_neighbor(peer))
7330 dn_flag[0] = '*';
7331
7332 if (peer->hostname
7333 && bgp_flag_check(bgp,
7334 BGP_FLAG_SHOW_HOSTNAME))
7335 sprintf(neighbor_buf, "%s%s(%s) ",
7336 dn_flag, peer->hostname,
7337 peer->host);
7338 else
7339 sprintf(neighbor_buf, "%s%s ", dn_flag,
7340 peer->host);
7341
7342 len = strlen(neighbor_buf);
7343
7344 if (len > max_neighbor_width)
7345 max_neighbor_width = len;
7346 }
7347 }
7348
7349 /* Originally we displayed the Neighbor column as 16
7350 * characters wide so make that the default
7351 */
7352 if (max_neighbor_width < neighbor_col_default_width)
7353 max_neighbor_width = neighbor_col_default_width;
7354 }
7355
7356 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7357 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7358 continue;
7359
7360 if (!peer->afc[afi][safi])
7361 continue;
7362
7363 if (!count) {
7364 unsigned long ents;
7365 char memstrbuf[MTYPE_MEMSTR_LEN];
7366 int64_t vrf_id_ui;
7367
7368 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7369 ? -1
7370 : (int64_t)bgp->vrf_id;
7371
7372 /* Usage summary and header */
7373 if (use_json) {
7374 json_object_string_add(
7375 json, "routerId",
7376 inet_ntoa(bgp->router_id));
7377 json_object_int_add(json, "as", bgp->as);
7378 json_object_int_add(json, "vrfId", vrf_id_ui);
7379 json_object_string_add(
7380 json, "vrfName",
7381 (bgp->inst_type
7382 == BGP_INSTANCE_TYPE_DEFAULT)
7383 ? "Default"
7384 : bgp->name);
7385 } else {
7386 vty_out(vty,
7387 "BGP router identifier %s, local AS number %u vrf-id %d",
7388 inet_ntoa(bgp->router_id), bgp->as,
7389 bgp->vrf_id == VRF_UNKNOWN
7390 ? -1
7391 : (int)bgp->vrf_id);
7392 vty_out(vty, "\n");
7393 }
7394
7395 if (bgp_update_delay_configured(bgp)) {
7396 if (use_json) {
7397 json_object_int_add(
7398 json, "updateDelayLimit",
7399 bgp->v_update_delay);
7400
7401 if (bgp->v_update_delay
7402 != bgp->v_establish_wait)
7403 json_object_int_add(
7404 json,
7405 "updateDelayEstablishWait",
7406 bgp->v_establish_wait);
7407
7408 if (bgp_update_delay_active(bgp)) {
7409 json_object_string_add(
7410 json,
7411 "updateDelayFirstNeighbor",
7412 bgp->update_delay_begin_time);
7413 json_object_boolean_true_add(
7414 json,
7415 "updateDelayInProgress");
7416 } else {
7417 if (bgp->update_delay_over) {
7418 json_object_string_add(
7419 json,
7420 "updateDelayFirstNeighbor",
7421 bgp->update_delay_begin_time);
7422 json_object_string_add(
7423 json,
7424 "updateDelayBestpathResumed",
7425 bgp->update_delay_end_time);
7426 json_object_string_add(
7427 json,
7428 "updateDelayZebraUpdateResume",
7429 bgp->update_delay_zebra_resume_time);
7430 json_object_string_add(
7431 json,
7432 "updateDelayPeerUpdateResume",
7433 bgp->update_delay_peers_resume_time);
7434 }
7435 }
7436 } else {
7437 vty_out(vty,
7438 "Read-only mode update-delay limit: %d seconds\n",
7439 bgp->v_update_delay);
7440 if (bgp->v_update_delay
7441 != bgp->v_establish_wait)
7442 vty_out(vty,
7443 " Establish wait: %d seconds\n",
7444 bgp->v_establish_wait);
7445
7446 if (bgp_update_delay_active(bgp)) {
7447 vty_out(vty,
7448 " First neighbor established: %s\n",
7449 bgp->update_delay_begin_time);
7450 vty_out(vty,
7451 " Delay in progress\n");
7452 } else {
7453 if (bgp->update_delay_over) {
7454 vty_out(vty,
7455 " First neighbor established: %s\n",
7456 bgp->update_delay_begin_time);
7457 vty_out(vty,
7458 " Best-paths resumed: %s\n",
7459 bgp->update_delay_end_time);
7460 vty_out(vty,
7461 " zebra update resumed: %s\n",
7462 bgp->update_delay_zebra_resume_time);
7463 vty_out(vty,
7464 " peers update resumed: %s\n",
7465 bgp->update_delay_peers_resume_time);
7466 }
7467 }
7468 }
7469 }
7470
7471 if (use_json) {
7472 if (bgp_maxmed_onstartup_configured(bgp)
7473 && bgp->maxmed_active)
7474 json_object_boolean_true_add(
7475 json, "maxMedOnStartup");
7476 if (bgp->v_maxmed_admin)
7477 json_object_boolean_true_add(
7478 json, "maxMedAdministrative");
7479
7480 json_object_int_add(
7481 json, "tableVersion",
7482 bgp_table_version(bgp->rib[afi][safi]));
7483
7484 ents = bgp_table_count(bgp->rib[afi][safi]);
7485 json_object_int_add(json, "ribCount", ents);
7486 json_object_int_add(
7487 json, "ribMemory",
7488 ents * sizeof(struct bgp_node));
7489
7490 ents = listcount(bgp->peer);
7491 json_object_int_add(json, "peerCount", ents);
7492 json_object_int_add(json, "peerMemory",
7493 ents * sizeof(struct peer));
7494
7495 if ((ents = listcount(bgp->group))) {
7496 json_object_int_add(
7497 json, "peerGroupCount", ents);
7498 json_object_int_add(
7499 json, "peerGroupMemory",
7500 ents * sizeof(struct
7501 peer_group));
7502 }
7503
7504 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7505 BGP_CONFIG_DAMPENING))
7506 json_object_boolean_true_add(
7507 json, "dampeningEnabled");
7508 } else {
7509 if (bgp_maxmed_onstartup_configured(bgp)
7510 && bgp->maxmed_active)
7511 vty_out(vty,
7512 "Max-med on-startup active\n");
7513 if (bgp->v_maxmed_admin)
7514 vty_out(vty,
7515 "Max-med administrative active\n");
7516
7517 vty_out(vty, "BGP table version %" PRIu64 "\n",
7518 bgp_table_version(bgp->rib[afi][safi]));
7519
7520 ents = bgp_table_count(bgp->rib[afi][safi]);
7521 vty_out(vty,
7522 "RIB entries %ld, using %s of memory\n",
7523 ents,
7524 mtype_memstr(memstrbuf,
7525 sizeof(memstrbuf),
7526 ents * sizeof(struct
7527 bgp_node)));
7528
7529 /* Peer related usage */
7530 ents = listcount(bgp->peer);
7531 vty_out(vty, "Peers %ld, using %s of memory\n",
7532 ents,
7533 mtype_memstr(
7534 memstrbuf, sizeof(memstrbuf),
7535 ents * sizeof(struct peer)));
7536
7537 if ((ents = listcount(bgp->group)))
7538 vty_out(vty,
7539 "Peer groups %ld, using %s of memory\n",
7540 ents,
7541 mtype_memstr(
7542 memstrbuf,
7543 sizeof(memstrbuf),
7544 ents * sizeof(struct
7545 peer_group)));
7546
7547 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7548 BGP_CONFIG_DAMPENING))
7549 vty_out(vty, "Dampening enabled.\n");
7550 vty_out(vty, "\n");
7551
7552 /* Subtract 8 here because 'Neighbor' is
7553 * 8 characters */
7554 vty_out(vty, "Neighbor");
7555 vty_out(vty, "%*s", max_neighbor_width - 8,
7556 " ");
7557 vty_out(vty,
7558 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7559 }
7560 }
7561
7562 count++;
7563
7564 if (use_json) {
7565 json_peer = json_object_new_object();
7566
7567 if (peer_dynamic_neighbor(peer))
7568 json_object_boolean_true_add(json_peer,
7569 "dynamicPeer");
7570
7571 if (peer->hostname)
7572 json_object_string_add(json_peer, "hostname",
7573 peer->hostname);
7574
7575 if (peer->domainname)
7576 json_object_string_add(json_peer, "domainname",
7577 peer->domainname);
7578
7579 json_object_int_add(json_peer, "remoteAs", peer->as);
7580 json_object_int_add(json_peer, "version", 4);
7581 json_object_int_add(json_peer, "msgRcvd",
7582 PEER_TOTAL_RX(peer));
7583 json_object_int_add(json_peer, "msgSent",
7584 PEER_TOTAL_TX(peer));
7585
7586 json_object_int_add(json_peer, "tableVersion",
7587 peer->version[afi][safi]);
7588 json_object_int_add(json_peer, "outq",
7589 peer->obuf->count);
7590 json_object_int_add(json_peer, "inq", 0);
7591 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7592 use_json, json_peer);
7593 json_object_int_add(json_peer, "prefixReceivedCount",
7594 peer->pcount[afi][pfx_rcd_safi]);
7595
7596 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7597 json_object_string_add(json_peer, "state",
7598 "Idle (Admin)");
7599 else if (CHECK_FLAG(peer->sflags,
7600 PEER_STATUS_PREFIX_OVERFLOW))
7601 json_object_string_add(json_peer, "state",
7602 "Idle (PfxCt)");
7603 else
7604 json_object_string_add(
7605 json_peer, "state",
7606 lookup_msg(bgp_status_msg, peer->status,
7607 NULL));
7608
7609 if (peer->conf_if)
7610 json_object_string_add(json_peer, "idType",
7611 "interface");
7612 else if (peer->su.sa.sa_family == AF_INET)
7613 json_object_string_add(json_peer, "idType",
7614 "ipv4");
7615 else if (peer->su.sa.sa_family == AF_INET6)
7616 json_object_string_add(json_peer, "idType",
7617 "ipv6");
7618
7619 json_object_object_add(json_peers, peer->host,
7620 json_peer);
7621 } else {
7622 memset(dn_flag, '\0', sizeof(dn_flag));
7623 if (peer_dynamic_neighbor(peer)) {
7624 dn_count++;
7625 dn_flag[0] = '*';
7626 }
7627
7628 if (peer->hostname
7629 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7630 len = vty_out(vty, "%s%s(%s)", dn_flag,
7631 peer->hostname, peer->host);
7632 else
7633 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7634
7635 /* pad the neighbor column with spaces */
7636 if (len < max_neighbor_width)
7637 vty_out(vty, "%*s", max_neighbor_width - len,
7638 " ");
7639
7640 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7641 peer->as, PEER_TOTAL_RX(peer),
7642 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7643 0, peer->obuf->count,
7644 peer_uptime(peer->uptime, timebuf,
7645 BGP_UPTIME_LEN, 0, NULL));
7646
7647 if (peer->status == Established)
7648 if (peer->afc_recv[afi][pfx_rcd_safi])
7649 vty_out(vty, " %12ld",
7650 peer->pcount[afi]
7651 [pfx_rcd_safi]);
7652 else
7653 vty_out(vty, " NoNeg");
7654 else {
7655 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7656 vty_out(vty, " Idle (Admin)");
7657 else if (CHECK_FLAG(
7658 peer->sflags,
7659 PEER_STATUS_PREFIX_OVERFLOW))
7660 vty_out(vty, " Idle (PfxCt)");
7661 else
7662 vty_out(vty, " %12s",
7663 lookup_msg(bgp_status_msg,
7664 peer->status, NULL));
7665 }
7666 vty_out(vty, "\n");
7667 }
7668 }
7669
7670 if (use_json) {
7671 json_object_object_add(json, "peers", json_peers);
7672
7673 json_object_int_add(json, "totalPeers", count);
7674 json_object_int_add(json, "dynamicPeers", dn_count);
7675
7676 bgp_show_bestpath_json(bgp, json);
7677
7678 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7679 json, JSON_C_TO_STRING_PRETTY));
7680 json_object_free(json);
7681 } else {
7682 if (count)
7683 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7684 else {
7685 if (use_json)
7686 vty_out(vty,
7687 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7688 afi_safi_print(afi, safi));
7689 else
7690 vty_out(vty, "No %s neighbor is configured\n",
7691 afi_safi_print(afi, safi));
7692 }
7693
7694 if (dn_count && !use_json) {
7695 vty_out(vty, "* - dynamic neighbor\n");
7696 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7697 dn_count, bgp->dynamic_neighbors_limit);
7698 }
7699 }
7700
7701 return CMD_SUCCESS;
7702 }
7703
7704 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7705 int safi, u_char use_json,
7706 json_object *json)
7707 {
7708 int is_first = 1;
7709 int afi_wildcard = (afi == AFI_MAX);
7710 int safi_wildcard = (safi == SAFI_MAX);
7711 int is_wildcard = (afi_wildcard || safi_wildcard);
7712 bool json_output = false;
7713
7714 if (use_json && is_wildcard)
7715 vty_out(vty, "{\n");
7716 if (afi_wildcard)
7717 afi = 1; /* AFI_IP */
7718 while (afi < AFI_MAX) {
7719 if (safi_wildcard)
7720 safi = 1; /* SAFI_UNICAST */
7721 while (safi < SAFI_MAX) {
7722 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
7723 json_output = true;
7724 if (is_wildcard) {
7725 /*
7726 * So limit output to those afi/safi
7727 * pairs that
7728 * actualy have something interesting in
7729 * them
7730 */
7731 if (use_json) {
7732 json = json_object_new_object();
7733
7734 if (!is_first)
7735 vty_out(vty, ",\n");
7736 else
7737 is_first = 0;
7738
7739 vty_out(vty, "\"%s\":",
7740 afi_safi_json(afi,
7741 safi));
7742 } else {
7743 vty_out(vty, "\n%s Summary:\n",
7744 afi_safi_print(afi,
7745 safi));
7746 }
7747 }
7748 bgp_show_summary(vty, bgp, afi, safi, use_json,
7749 json);
7750 }
7751 safi++;
7752 if (!safi_wildcard)
7753 safi = SAFI_MAX;
7754 }
7755 afi++;
7756 if (!afi_wildcard)
7757 afi = AFI_MAX;
7758 }
7759
7760 if (use_json && is_wildcard)
7761 vty_out(vty, "}\n");
7762 else if (use_json && !json_output)
7763 vty_out(vty, "{}\n");
7764 }
7765
7766 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7767 safi_t safi, u_char use_json)
7768 {
7769 struct listnode *node, *nnode;
7770 struct bgp *bgp;
7771 json_object *json = NULL;
7772 int is_first = 1;
7773
7774 if (use_json)
7775 vty_out(vty, "{\n");
7776
7777 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
7778 if (use_json) {
7779 json = json_object_new_object();
7780
7781 if (!is_first)
7782 vty_out(vty, ",\n");
7783 else
7784 is_first = 0;
7785
7786 vty_out(vty, "\"%s\":",
7787 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7788 ? "Default"
7789 : bgp->name);
7790 } else {
7791 vty_out(vty, "\nInstance %s:\n",
7792 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7793 ? "Default"
7794 : bgp->name);
7795 }
7796 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7797 }
7798
7799 if (use_json)
7800 vty_out(vty, "}\n");
7801 }
7802
7803 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7804 safi_t safi, u_char use_json)
7805 {
7806 struct bgp *bgp;
7807
7808 if (name) {
7809 if (strmatch(name, "all")) {
7810 bgp_show_all_instances_summary_vty(vty, afi, safi,
7811 use_json);
7812 return CMD_SUCCESS;
7813 } else {
7814 bgp = bgp_lookup_by_name(name);
7815
7816 if (!bgp) {
7817 if (use_json)
7818 vty_out(vty, "{}\n");
7819 else
7820 vty_out(vty,
7821 "%% No such BGP instance exist\n");
7822 return CMD_WARNING;
7823 }
7824
7825 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7826 NULL);
7827 return CMD_SUCCESS;
7828 }
7829 }
7830
7831 bgp = bgp_get_default();
7832
7833 if (bgp)
7834 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7835
7836 return CMD_SUCCESS;
7837 }
7838
7839 /* `show [ip] bgp summary' commands. */
7840 DEFUN (show_ip_bgp_summary,
7841 show_ip_bgp_summary_cmd,
7842 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
7843 SHOW_STR
7844 IP_STR
7845 BGP_STR
7846 BGP_INSTANCE_HELP_STR
7847 BGP_AFI_HELP_STR
7848 BGP_SAFI_WITH_LABEL_HELP_STR
7849 "Summary of BGP neighbor status\n"
7850 JSON_STR)
7851 {
7852 char *vrf = NULL;
7853 afi_t afi = AFI_MAX;
7854 safi_t safi = SAFI_MAX;
7855
7856 int idx = 0;
7857
7858 /* show [ip] bgp */
7859 if (argv_find(argv, argc, "ip", &idx))
7860 afi = AFI_IP;
7861 /* [<view|vrf> VIEWVRFNAME] */
7862 if (argv_find(argv, argc, "view", &idx)
7863 || argv_find(argv, argc, "vrf", &idx))
7864 vrf = argv[++idx]->arg;
7865 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7866 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7867 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7868 }
7869
7870 int uj = use_json(argc, argv);
7871
7872 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7873 }
7874
7875 const char *afi_safi_print(afi_t afi, safi_t safi)
7876 {
7877 if (afi == AFI_IP && safi == SAFI_UNICAST)
7878 return "IPv4 Unicast";
7879 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7880 return "IPv4 Multicast";
7881 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7882 return "IPv4 Labeled Unicast";
7883 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7884 return "IPv4 VPN";
7885 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7886 return "IPv4 Encap";
7887 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7888 return "IPv6 Unicast";
7889 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7890 return "IPv6 Multicast";
7891 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7892 return "IPv6 Labeled Unicast";
7893 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7894 return "IPv6 VPN";
7895 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7896 return "IPv6 Encap";
7897 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7898 return "L2VPN EVPN";
7899 else
7900 return "Unknown";
7901 }
7902
7903 /*
7904 * Please note that we have intentionally camelCased
7905 * the return strings here. So if you want
7906 * to use this function, please ensure you
7907 * are doing this within json output
7908 */
7909 const char *afi_safi_json(afi_t afi, safi_t safi)
7910 {
7911 if (afi == AFI_IP && safi == SAFI_UNICAST)
7912 return "ipv4Unicast";
7913 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7914 return "ipv4Multicast";
7915 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7916 return "ipv4LabeledUnicast";
7917 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7918 return "ipv4Vpn";
7919 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7920 return "ipv4Encap";
7921 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7922 return "ipv6Unicast";
7923 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7924 return "ipv6Multicast";
7925 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7926 return "ipv6LabeledUnicast";
7927 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7928 return "ipv6Vpn";
7929 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7930 return "ipv6Encap";
7931 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7932 return "l2VpnEvpn";
7933 else
7934 return "Unknown";
7935 }
7936
7937 /* Show BGP peer's information. */
7938 enum show_type { show_all, show_peer };
7939
7940 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7941 afi_t afi, safi_t safi,
7942 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7943 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7944 u_char use_json, json_object *json_pref)
7945 {
7946 /* Send-Mode */
7947 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7948 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7949 if (use_json) {
7950 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7951 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7952 json_object_string_add(json_pref, "sendMode",
7953 "advertisedAndReceived");
7954 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7955 json_object_string_add(json_pref, "sendMode",
7956 "advertised");
7957 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7958 json_object_string_add(json_pref, "sendMode",
7959 "received");
7960 } else {
7961 vty_out(vty, " Send-mode: ");
7962 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7963 vty_out(vty, "advertised");
7964 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7965 vty_out(vty, "%sreceived",
7966 CHECK_FLAG(p->af_cap[afi][safi],
7967 adv_smcap)
7968 ? ", "
7969 : "");
7970 vty_out(vty, "\n");
7971 }
7972 }
7973
7974 /* Receive-Mode */
7975 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7976 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
7977 if (use_json) {
7978 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7979 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7980 json_object_string_add(json_pref, "recvMode",
7981 "advertisedAndReceived");
7982 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7983 json_object_string_add(json_pref, "recvMode",
7984 "advertised");
7985 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7986 json_object_string_add(json_pref, "recvMode",
7987 "received");
7988 } else {
7989 vty_out(vty, " Receive-mode: ");
7990 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7991 vty_out(vty, "advertised");
7992 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7993 vty_out(vty, "%sreceived",
7994 CHECK_FLAG(p->af_cap[afi][safi],
7995 adv_rmcap)
7996 ? ", "
7997 : "");
7998 vty_out(vty, "\n");
7999 }
8000 }
8001 }
8002
8003 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8004 safi_t safi, u_char use_json,
8005 json_object *json_neigh)
8006 {
8007 struct bgp_filter *filter;
8008 struct peer_af *paf;
8009 char orf_pfx_name[BUFSIZ];
8010 int orf_pfx_count;
8011 json_object *json_af = NULL;
8012 json_object *json_prefA = NULL;
8013 json_object *json_prefB = NULL;
8014 json_object *json_addr = NULL;
8015
8016 if (use_json) {
8017 json_addr = json_object_new_object();
8018 json_af = json_object_new_object();
8019 filter = &p->filter[afi][safi];
8020
8021 if (peer_group_active(p))
8022 json_object_string_add(json_addr, "peerGroupMember",
8023 p->group->name);
8024
8025 paf = peer_af_find(p, afi, safi);
8026 if (paf && PAF_SUBGRP(paf)) {
8027 json_object_int_add(json_addr, "updateGroupId",
8028 PAF_UPDGRP(paf)->id);
8029 json_object_int_add(json_addr, "subGroupId",
8030 PAF_SUBGRP(paf)->id);
8031 json_object_int_add(json_addr, "packetQueueLength",
8032 bpacket_queue_virtual_length(paf));
8033 }
8034
8035 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8036 || CHECK_FLAG(p->af_cap[afi][safi],
8037 PEER_CAP_ORF_PREFIX_SM_RCV)
8038 || CHECK_FLAG(p->af_cap[afi][safi],
8039 PEER_CAP_ORF_PREFIX_RM_ADV)
8040 || CHECK_FLAG(p->af_cap[afi][safi],
8041 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8042 json_object_int_add(json_af, "orfType",
8043 ORF_TYPE_PREFIX);
8044 json_prefA = json_object_new_object();
8045 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8046 PEER_CAP_ORF_PREFIX_SM_ADV,
8047 PEER_CAP_ORF_PREFIX_RM_ADV,
8048 PEER_CAP_ORF_PREFIX_SM_RCV,
8049 PEER_CAP_ORF_PREFIX_RM_RCV,
8050 use_json, json_prefA);
8051 json_object_object_add(json_af, "orfPrefixList",
8052 json_prefA);
8053 }
8054
8055 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8056 || CHECK_FLAG(p->af_cap[afi][safi],
8057 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8058 || CHECK_FLAG(p->af_cap[afi][safi],
8059 PEER_CAP_ORF_PREFIX_RM_ADV)
8060 || CHECK_FLAG(p->af_cap[afi][safi],
8061 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8062 json_object_int_add(json_af, "orfOldType",
8063 ORF_TYPE_PREFIX_OLD);
8064 json_prefB = json_object_new_object();
8065 bgp_show_peer_afi_orf_cap(
8066 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8067 PEER_CAP_ORF_PREFIX_RM_ADV,
8068 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8069 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8070 json_prefB);
8071 json_object_object_add(json_af, "orfOldPrefixList",
8072 json_prefB);
8073 }
8074
8075 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8076 || CHECK_FLAG(p->af_cap[afi][safi],
8077 PEER_CAP_ORF_PREFIX_SM_RCV)
8078 || CHECK_FLAG(p->af_cap[afi][safi],
8079 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8080 || CHECK_FLAG(p->af_cap[afi][safi],
8081 PEER_CAP_ORF_PREFIX_RM_ADV)
8082 || CHECK_FLAG(p->af_cap[afi][safi],
8083 PEER_CAP_ORF_PREFIX_RM_RCV)
8084 || CHECK_FLAG(p->af_cap[afi][safi],
8085 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8086 json_object_object_add(json_addr, "afDependentCap",
8087 json_af);
8088 else
8089 json_object_free(json_af);
8090
8091 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8092 orf_pfx_count = prefix_bgp_show_prefix_list(
8093 NULL, afi, orf_pfx_name, use_json);
8094
8095 if (CHECK_FLAG(p->af_sflags[afi][safi],
8096 PEER_STATUS_ORF_PREFIX_SEND)
8097 || orf_pfx_count) {
8098 if (CHECK_FLAG(p->af_sflags[afi][safi],
8099 PEER_STATUS_ORF_PREFIX_SEND))
8100 json_object_boolean_true_add(json_neigh,
8101 "orfSent");
8102 if (orf_pfx_count)
8103 json_object_int_add(json_addr, "orfRecvCounter",
8104 orf_pfx_count);
8105 }
8106 if (CHECK_FLAG(p->af_sflags[afi][safi],
8107 PEER_STATUS_ORF_WAIT_REFRESH))
8108 json_object_string_add(
8109 json_addr, "orfFirstUpdate",
8110 "deferredUntilORFOrRouteRefreshRecvd");
8111
8112 if (CHECK_FLAG(p->af_flags[afi][safi],
8113 PEER_FLAG_REFLECTOR_CLIENT))
8114 json_object_boolean_true_add(json_addr,
8115 "routeReflectorClient");
8116 if (CHECK_FLAG(p->af_flags[afi][safi],
8117 PEER_FLAG_RSERVER_CLIENT))
8118 json_object_boolean_true_add(json_addr,
8119 "routeServerClient");
8120 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8121 json_object_boolean_true_add(json_addr,
8122 "inboundSoftConfigPermit");
8123
8124 if (CHECK_FLAG(p->af_flags[afi][safi],
8125 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8126 json_object_boolean_true_add(
8127 json_addr,
8128 "privateAsNumsAllReplacedInUpdatesToNbr");
8129 else if (CHECK_FLAG(p->af_flags[afi][safi],
8130 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8131 json_object_boolean_true_add(
8132 json_addr,
8133 "privateAsNumsReplacedInUpdatesToNbr");
8134 else if (CHECK_FLAG(p->af_flags[afi][safi],
8135 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8136 json_object_boolean_true_add(
8137 json_addr,
8138 "privateAsNumsAllRemovedInUpdatesToNbr");
8139 else if (CHECK_FLAG(p->af_flags[afi][safi],
8140 PEER_FLAG_REMOVE_PRIVATE_AS))
8141 json_object_boolean_true_add(
8142 json_addr,
8143 "privateAsNumsRemovedInUpdatesToNbr");
8144
8145 if (CHECK_FLAG(p->af_flags[afi][safi],
8146 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8147 json_object_boolean_true_add(json_addr,
8148 "addpathTxAllPaths");
8149
8150 if (CHECK_FLAG(p->af_flags[afi][safi],
8151 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8152 json_object_boolean_true_add(json_addr,
8153 "addpathTxBestpathPerAS");
8154
8155 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8156 json_object_string_add(json_addr,
8157 "overrideASNsInOutboundUpdates",
8158 "ifAspathEqualRemoteAs");
8159
8160 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8161 || CHECK_FLAG(p->af_flags[afi][safi],
8162 PEER_FLAG_FORCE_NEXTHOP_SELF))
8163 json_object_boolean_true_add(json_addr,
8164 "routerAlwaysNextHop");
8165 if (CHECK_FLAG(p->af_flags[afi][safi],
8166 PEER_FLAG_AS_PATH_UNCHANGED))
8167 json_object_boolean_true_add(
8168 json_addr, "unchangedAsPathPropogatedToNbr");
8169 if (CHECK_FLAG(p->af_flags[afi][safi],
8170 PEER_FLAG_NEXTHOP_UNCHANGED))
8171 json_object_boolean_true_add(
8172 json_addr, "unchangedNextHopPropogatedToNbr");
8173 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8174 json_object_boolean_true_add(
8175 json_addr, "unchangedMedPropogatedToNbr");
8176 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8177 || CHECK_FLAG(p->af_flags[afi][safi],
8178 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8179 if (CHECK_FLAG(p->af_flags[afi][safi],
8180 PEER_FLAG_SEND_COMMUNITY)
8181 && CHECK_FLAG(p->af_flags[afi][safi],
8182 PEER_FLAG_SEND_EXT_COMMUNITY))
8183 json_object_string_add(json_addr,
8184 "commAttriSentToNbr",
8185 "extendedAndStandard");
8186 else if (CHECK_FLAG(p->af_flags[afi][safi],
8187 PEER_FLAG_SEND_EXT_COMMUNITY))
8188 json_object_string_add(json_addr,
8189 "commAttriSentToNbr",
8190 "extended");
8191 else
8192 json_object_string_add(json_addr,
8193 "commAttriSentToNbr",
8194 "standard");
8195 }
8196 if (CHECK_FLAG(p->af_flags[afi][safi],
8197 PEER_FLAG_DEFAULT_ORIGINATE)) {
8198 if (p->default_rmap[afi][safi].name)
8199 json_object_string_add(
8200 json_addr, "defaultRouteMap",
8201 p->default_rmap[afi][safi].name);
8202
8203 if (paf && PAF_SUBGRP(paf)
8204 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8205 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8206 json_object_boolean_true_add(json_addr,
8207 "defaultSent");
8208 else
8209 json_object_boolean_true_add(json_addr,
8210 "defaultNotSent");
8211 }
8212
8213 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8214 if (is_evpn_enabled())
8215 json_object_boolean_true_add(
8216 json_addr, "advertiseAllVnis");
8217 }
8218
8219 if (filter->plist[FILTER_IN].name
8220 || filter->dlist[FILTER_IN].name
8221 || filter->aslist[FILTER_IN].name
8222 || filter->map[RMAP_IN].name)
8223 json_object_boolean_true_add(json_addr,
8224 "inboundPathPolicyConfig");
8225 if (filter->plist[FILTER_OUT].name
8226 || filter->dlist[FILTER_OUT].name
8227 || filter->aslist[FILTER_OUT].name
8228 || filter->map[RMAP_OUT].name || filter->usmap.name)
8229 json_object_boolean_true_add(
8230 json_addr, "outboundPathPolicyConfig");
8231
8232 /* prefix-list */
8233 if (filter->plist[FILTER_IN].name)
8234 json_object_string_add(json_addr,
8235 "incomingUpdatePrefixFilterList",
8236 filter->plist[FILTER_IN].name);
8237 if (filter->plist[FILTER_OUT].name)
8238 json_object_string_add(json_addr,
8239 "outgoingUpdatePrefixFilterList",
8240 filter->plist[FILTER_OUT].name);
8241
8242 /* distribute-list */
8243 if (filter->dlist[FILTER_IN].name)
8244 json_object_string_add(
8245 json_addr, "incomingUpdateNetworkFilterList",
8246 filter->dlist[FILTER_IN].name);
8247 if (filter->dlist[FILTER_OUT].name)
8248 json_object_string_add(
8249 json_addr, "outgoingUpdateNetworkFilterList",
8250 filter->dlist[FILTER_OUT].name);
8251
8252 /* filter-list. */
8253 if (filter->aslist[FILTER_IN].name)
8254 json_object_string_add(json_addr,
8255 "incomingUpdateAsPathFilterList",
8256 filter->aslist[FILTER_IN].name);
8257 if (filter->aslist[FILTER_OUT].name)
8258 json_object_string_add(json_addr,
8259 "outgoingUpdateAsPathFilterList",
8260 filter->aslist[FILTER_OUT].name);
8261
8262 /* route-map. */
8263 if (filter->map[RMAP_IN].name)
8264 json_object_string_add(
8265 json_addr, "routeMapForIncomingAdvertisements",
8266 filter->map[RMAP_IN].name);
8267 if (filter->map[RMAP_OUT].name)
8268 json_object_string_add(
8269 json_addr, "routeMapForOutgoingAdvertisements",
8270 filter->map[RMAP_OUT].name);
8271
8272 /* unsuppress-map */
8273 if (filter->usmap.name)
8274 json_object_string_add(json_addr,
8275 "selectiveUnsuppressRouteMap",
8276 filter->usmap.name);
8277
8278 /* Receive prefix count */
8279 json_object_int_add(json_addr, "acceptedPrefixCounter",
8280 p->pcount[afi][safi]);
8281
8282 /* Maximum prefix */
8283 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8284 json_object_int_add(json_addr, "prefixAllowedMax",
8285 p->pmax[afi][safi]);
8286 if (CHECK_FLAG(p->af_flags[afi][safi],
8287 PEER_FLAG_MAX_PREFIX_WARNING))
8288 json_object_boolean_true_add(
8289 json_addr, "prefixAllowedMaxWarning");
8290 json_object_int_add(json_addr,
8291 "prefixAllowedWarningThresh",
8292 p->pmax_threshold[afi][safi]);
8293 if (p->pmax_restart[afi][safi])
8294 json_object_int_add(
8295 json_addr,
8296 "prefixAllowedRestartIntervalMsecs",
8297 p->pmax_restart[afi][safi] * 60000);
8298 }
8299 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8300 json_addr);
8301
8302 } else {
8303 filter = &p->filter[afi][safi];
8304
8305 vty_out(vty, " For address family: %s\n",
8306 afi_safi_print(afi, safi));
8307
8308 if (peer_group_active(p))
8309 vty_out(vty, " %s peer-group member\n",
8310 p->group->name);
8311
8312 paf = peer_af_find(p, afi, safi);
8313 if (paf && PAF_SUBGRP(paf)) {
8314 vty_out(vty, " Update group %" PRIu64
8315 ", subgroup %" PRIu64 "\n",
8316 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8317 vty_out(vty, " Packet Queue length %d\n",
8318 bpacket_queue_virtual_length(paf));
8319 } else {
8320 vty_out(vty, " Not part of any update group\n");
8321 }
8322 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8323 || CHECK_FLAG(p->af_cap[afi][safi],
8324 PEER_CAP_ORF_PREFIX_SM_RCV)
8325 || CHECK_FLAG(p->af_cap[afi][safi],
8326 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8327 || CHECK_FLAG(p->af_cap[afi][safi],
8328 PEER_CAP_ORF_PREFIX_RM_ADV)
8329 || CHECK_FLAG(p->af_cap[afi][safi],
8330 PEER_CAP_ORF_PREFIX_RM_RCV)
8331 || CHECK_FLAG(p->af_cap[afi][safi],
8332 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8333 vty_out(vty, " AF-dependant capabilities:\n");
8334
8335 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8336 || CHECK_FLAG(p->af_cap[afi][safi],
8337 PEER_CAP_ORF_PREFIX_SM_RCV)
8338 || CHECK_FLAG(p->af_cap[afi][safi],
8339 PEER_CAP_ORF_PREFIX_RM_ADV)
8340 || CHECK_FLAG(p->af_cap[afi][safi],
8341 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8342 vty_out(vty,
8343 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8344 ORF_TYPE_PREFIX);
8345 bgp_show_peer_afi_orf_cap(
8346 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8347 PEER_CAP_ORF_PREFIX_RM_ADV,
8348 PEER_CAP_ORF_PREFIX_SM_RCV,
8349 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8350 }
8351 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8352 || CHECK_FLAG(p->af_cap[afi][safi],
8353 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8354 || CHECK_FLAG(p->af_cap[afi][safi],
8355 PEER_CAP_ORF_PREFIX_RM_ADV)
8356 || CHECK_FLAG(p->af_cap[afi][safi],
8357 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8358 vty_out(vty,
8359 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8360 ORF_TYPE_PREFIX_OLD);
8361 bgp_show_peer_afi_orf_cap(
8362 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8363 PEER_CAP_ORF_PREFIX_RM_ADV,
8364 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8365 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8366 }
8367
8368 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8369 orf_pfx_count = prefix_bgp_show_prefix_list(
8370 NULL, afi, orf_pfx_name, use_json);
8371
8372 if (CHECK_FLAG(p->af_sflags[afi][safi],
8373 PEER_STATUS_ORF_PREFIX_SEND)
8374 || orf_pfx_count) {
8375 vty_out(vty, " Outbound Route Filter (ORF):");
8376 if (CHECK_FLAG(p->af_sflags[afi][safi],
8377 PEER_STATUS_ORF_PREFIX_SEND))
8378 vty_out(vty, " sent;");
8379 if (orf_pfx_count)
8380 vty_out(vty, " received (%d entries)",
8381 orf_pfx_count);
8382 vty_out(vty, "\n");
8383 }
8384 if (CHECK_FLAG(p->af_sflags[afi][safi],
8385 PEER_STATUS_ORF_WAIT_REFRESH))
8386 vty_out(vty,
8387 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8388
8389 if (CHECK_FLAG(p->af_flags[afi][safi],
8390 PEER_FLAG_REFLECTOR_CLIENT))
8391 vty_out(vty, " Route-Reflector Client\n");
8392 if (CHECK_FLAG(p->af_flags[afi][safi],
8393 PEER_FLAG_RSERVER_CLIENT))
8394 vty_out(vty, " Route-Server Client\n");
8395 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8396 vty_out(vty,
8397 " Inbound soft reconfiguration allowed\n");
8398
8399 if (CHECK_FLAG(p->af_flags[afi][safi],
8400 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8401 vty_out(vty,
8402 " Private AS numbers (all) replaced in updates to this neighbor\n");
8403 else if (CHECK_FLAG(p->af_flags[afi][safi],
8404 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8405 vty_out(vty,
8406 " Private AS numbers replaced in updates to this neighbor\n");
8407 else if (CHECK_FLAG(p->af_flags[afi][safi],
8408 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8409 vty_out(vty,
8410 " Private AS numbers (all) removed in updates to this neighbor\n");
8411 else if (CHECK_FLAG(p->af_flags[afi][safi],
8412 PEER_FLAG_REMOVE_PRIVATE_AS))
8413 vty_out(vty,
8414 " Private AS numbers removed in updates to this neighbor\n");
8415
8416 if (CHECK_FLAG(p->af_flags[afi][safi],
8417 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8418 vty_out(vty, " Advertise all paths via addpath\n");
8419
8420 if (CHECK_FLAG(p->af_flags[afi][safi],
8421 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8422 vty_out(vty,
8423 " Advertise bestpath per AS via addpath\n");
8424
8425 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8426 vty_out(vty,
8427 " Override ASNs in outbound updates if aspath equals remote-as\n");
8428
8429 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8430 || CHECK_FLAG(p->af_flags[afi][safi],
8431 PEER_FLAG_FORCE_NEXTHOP_SELF))
8432 vty_out(vty, " NEXT_HOP is always this router\n");
8433 if (CHECK_FLAG(p->af_flags[afi][safi],
8434 PEER_FLAG_AS_PATH_UNCHANGED))
8435 vty_out(vty,
8436 " AS_PATH is propagated unchanged to this neighbor\n");
8437 if (CHECK_FLAG(p->af_flags[afi][safi],
8438 PEER_FLAG_NEXTHOP_UNCHANGED))
8439 vty_out(vty,
8440 " NEXT_HOP is propagated unchanged to this neighbor\n");
8441 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8442 vty_out(vty,
8443 " MED is propagated unchanged to this neighbor\n");
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 || CHECK_FLAG(p->af_flags[afi][safi],
8448 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8449 vty_out(vty,
8450 " Community attribute sent to this neighbor");
8451 if (CHECK_FLAG(p->af_flags[afi][safi],
8452 PEER_FLAG_SEND_COMMUNITY)
8453 && CHECK_FLAG(p->af_flags[afi][safi],
8454 PEER_FLAG_SEND_EXT_COMMUNITY)
8455 && CHECK_FLAG(p->af_flags[afi][safi],
8456 PEER_FLAG_SEND_LARGE_COMMUNITY))
8457 vty_out(vty, "(all)\n");
8458 else if (CHECK_FLAG(p->af_flags[afi][safi],
8459 PEER_FLAG_SEND_LARGE_COMMUNITY))
8460 vty_out(vty, "(large)\n");
8461 else if (CHECK_FLAG(p->af_flags[afi][safi],
8462 PEER_FLAG_SEND_EXT_COMMUNITY))
8463 vty_out(vty, "(extended)\n");
8464 else
8465 vty_out(vty, "(standard)\n");
8466 }
8467 if (CHECK_FLAG(p->af_flags[afi][safi],
8468 PEER_FLAG_DEFAULT_ORIGINATE)) {
8469 vty_out(vty, " Default information originate,");
8470
8471 if (p->default_rmap[afi][safi].name)
8472 vty_out(vty, " default route-map %s%s,",
8473 p->default_rmap[afi][safi].map ? "*"
8474 : "",
8475 p->default_rmap[afi][safi].name);
8476 if (paf && PAF_SUBGRP(paf)
8477 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8478 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8479 vty_out(vty, " default sent\n");
8480 else
8481 vty_out(vty, " default not sent\n");
8482 }
8483
8484 /* advertise-vni-all */
8485 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8486 if (is_evpn_enabled())
8487 vty_out(vty, " advertise-all-vni\n");
8488 }
8489
8490 if (filter->plist[FILTER_IN].name
8491 || filter->dlist[FILTER_IN].name
8492 || filter->aslist[FILTER_IN].name
8493 || filter->map[RMAP_IN].name)
8494 vty_out(vty, " Inbound path policy configured\n");
8495 if (filter->plist[FILTER_OUT].name
8496 || filter->dlist[FILTER_OUT].name
8497 || filter->aslist[FILTER_OUT].name
8498 || filter->map[RMAP_OUT].name || filter->usmap.name)
8499 vty_out(vty, " Outbound path policy configured\n");
8500
8501 /* prefix-list */
8502 if (filter->plist[FILTER_IN].name)
8503 vty_out(vty,
8504 " Incoming update prefix filter list is %s%s\n",
8505 filter->plist[FILTER_IN].plist ? "*" : "",
8506 filter->plist[FILTER_IN].name);
8507 if (filter->plist[FILTER_OUT].name)
8508 vty_out(vty,
8509 " Outgoing update prefix filter list is %s%s\n",
8510 filter->plist[FILTER_OUT].plist ? "*" : "",
8511 filter->plist[FILTER_OUT].name);
8512
8513 /* distribute-list */
8514 if (filter->dlist[FILTER_IN].name)
8515 vty_out(vty,
8516 " Incoming update network filter list is %s%s\n",
8517 filter->dlist[FILTER_IN].alist ? "*" : "",
8518 filter->dlist[FILTER_IN].name);
8519 if (filter->dlist[FILTER_OUT].name)
8520 vty_out(vty,
8521 " Outgoing update network filter list is %s%s\n",
8522 filter->dlist[FILTER_OUT].alist ? "*" : "",
8523 filter->dlist[FILTER_OUT].name);
8524
8525 /* filter-list. */
8526 if (filter->aslist[FILTER_IN].name)
8527 vty_out(vty,
8528 " Incoming update AS path filter list is %s%s\n",
8529 filter->aslist[FILTER_IN].aslist ? "*" : "",
8530 filter->aslist[FILTER_IN].name);
8531 if (filter->aslist[FILTER_OUT].name)
8532 vty_out(vty,
8533 " Outgoing update AS path filter list is %s%s\n",
8534 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8535 filter->aslist[FILTER_OUT].name);
8536
8537 /* route-map. */
8538 if (filter->map[RMAP_IN].name)
8539 vty_out(vty,
8540 " Route map for incoming advertisements is %s%s\n",
8541 filter->map[RMAP_IN].map ? "*" : "",
8542 filter->map[RMAP_IN].name);
8543 if (filter->map[RMAP_OUT].name)
8544 vty_out(vty,
8545 " Route map for outgoing advertisements is %s%s\n",
8546 filter->map[RMAP_OUT].map ? "*" : "",
8547 filter->map[RMAP_OUT].name);
8548
8549 /* unsuppress-map */
8550 if (filter->usmap.name)
8551 vty_out(vty,
8552 " Route map for selective unsuppress is %s%s\n",
8553 filter->usmap.map ? "*" : "",
8554 filter->usmap.name);
8555
8556 /* Receive prefix count */
8557 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8558
8559 /* Maximum prefix */
8560 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8561 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8562 p->pmax[afi][safi],
8563 CHECK_FLAG(p->af_flags[afi][safi],
8564 PEER_FLAG_MAX_PREFIX_WARNING)
8565 ? " (warning-only)"
8566 : "");
8567 vty_out(vty, " Threshold for warning message %d%%",
8568 p->pmax_threshold[afi][safi]);
8569 if (p->pmax_restart[afi][safi])
8570 vty_out(vty, ", restart interval %d min",
8571 p->pmax_restart[afi][safi]);
8572 vty_out(vty, "\n");
8573 }
8574
8575 vty_out(vty, "\n");
8576 }
8577 }
8578
8579 static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
8580 json_object *json)
8581 {
8582 struct bgp *bgp;
8583 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8584 char timebuf[BGP_UPTIME_LEN];
8585 char dn_flag[2];
8586 const char *subcode_str;
8587 const char *code_str;
8588 afi_t afi;
8589 safi_t safi;
8590 u_int16_t i;
8591 u_char *msg;
8592 json_object *json_neigh = NULL;
8593 time_t epoch_tbuf;
8594
8595 bgp = p->bgp;
8596
8597 if (use_json)
8598 json_neigh = json_object_new_object();
8599
8600 memset(dn_flag, '\0', sizeof(dn_flag));
8601 if (!p->conf_if && peer_dynamic_neighbor(p))
8602 dn_flag[0] = '*';
8603
8604 if (!use_json) {
8605 if (p->conf_if) /* Configured interface name. */
8606 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8607 BGP_PEER_SU_UNSPEC(p)
8608 ? "None"
8609 : sockunion2str(&p->su, buf,
8610 SU_ADDRSTRLEN));
8611 else /* Configured IP address. */
8612 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8613 p->host);
8614 }
8615
8616 if (use_json) {
8617 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8618 json_object_string_add(json_neigh, "bgpNeighborAddr",
8619 "none");
8620 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8621 json_object_string_add(
8622 json_neigh, "bgpNeighborAddr",
8623 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8624
8625 json_object_int_add(json_neigh, "remoteAs", p->as);
8626
8627 if (p->change_local_as)
8628 json_object_int_add(json_neigh, "localAs",
8629 p->change_local_as);
8630 else
8631 json_object_int_add(json_neigh, "localAs", p->local_as);
8632
8633 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8634 json_object_boolean_true_add(json_neigh,
8635 "localAsNoPrepend");
8636
8637 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8638 json_object_boolean_true_add(json_neigh,
8639 "localAsReplaceAs");
8640 } else {
8641 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8642 || (p->as_type == AS_INTERNAL))
8643 vty_out(vty, "remote AS %u, ", p->as);
8644 else
8645 vty_out(vty, "remote AS Unspecified, ");
8646 vty_out(vty, "local AS %u%s%s, ",
8647 p->change_local_as ? p->change_local_as : p->local_as,
8648 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8649 ? " no-prepend"
8650 : "",
8651 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8652 ? " replace-as"
8653 : "");
8654 }
8655 /* peer type internal, external, confed-internal or confed-external */
8656 if (p->as == p->local_as) {
8657 if (use_json) {
8658 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8659 json_object_boolean_true_add(
8660 json_neigh, "nbrConfedInternalLink");
8661 else
8662 json_object_boolean_true_add(json_neigh,
8663 "nbrInternalLink");
8664 } else {
8665 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8666 vty_out(vty, "confed-internal link\n");
8667 else
8668 vty_out(vty, "internal link\n");
8669 }
8670 } else {
8671 if (use_json) {
8672 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8673 json_object_boolean_true_add(
8674 json_neigh, "nbrConfedExternalLink");
8675 else
8676 json_object_boolean_true_add(json_neigh,
8677 "nbrExternalLink");
8678 } else {
8679 if (bgp_confederation_peers_check(bgp, p->as))
8680 vty_out(vty, "confed-external link\n");
8681 else
8682 vty_out(vty, "external link\n");
8683 }
8684 }
8685
8686 /* Description. */
8687 if (p->desc) {
8688 if (use_json)
8689 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8690 else
8691 vty_out(vty, " Description: %s\n", p->desc);
8692 }
8693
8694 if (p->hostname) {
8695 if (use_json) {
8696 if (p->hostname)
8697 json_object_string_add(json_neigh, "hostname",
8698 p->hostname);
8699
8700 if (p->domainname)
8701 json_object_string_add(json_neigh, "domainname",
8702 p->domainname);
8703 } else {
8704 if (p->domainname && (p->domainname[0] != '\0'))
8705 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8706 p->domainname);
8707 else
8708 vty_out(vty, "Hostname: %s\n", p->hostname);
8709 }
8710 }
8711
8712 /* Peer-group */
8713 if (p->group) {
8714 if (use_json) {
8715 json_object_string_add(json_neigh, "peerGroup",
8716 p->group->name);
8717
8718 if (dn_flag[0]) {
8719 struct prefix prefix, *range = NULL;
8720
8721 sockunion2hostprefix(&(p->su), &prefix);
8722 range = peer_group_lookup_dynamic_neighbor_range(
8723 p->group, &prefix);
8724
8725 if (range) {
8726 prefix2str(range, buf1, sizeof(buf1));
8727 json_object_string_add(
8728 json_neigh,
8729 "peerSubnetRangeGroup", buf1);
8730 }
8731 }
8732 } else {
8733 vty_out(vty,
8734 " Member of peer-group %s for session parameters\n",
8735 p->group->name);
8736
8737 if (dn_flag[0]) {
8738 struct prefix prefix, *range = NULL;
8739
8740 sockunion2hostprefix(&(p->su), &prefix);
8741 range = peer_group_lookup_dynamic_neighbor_range(
8742 p->group, &prefix);
8743
8744 if (range) {
8745 prefix2str(range, buf1, sizeof(buf1));
8746 vty_out(vty,
8747 " Belongs to the subnet range group: %s\n",
8748 buf1);
8749 }
8750 }
8751 }
8752 }
8753
8754 if (use_json) {
8755 /* Administrative shutdown. */
8756 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8757 json_object_boolean_true_add(json_neigh,
8758 "adminShutDown");
8759
8760 /* BGP Version. */
8761 json_object_int_add(json_neigh, "bgpVersion", 4);
8762 json_object_string_add(
8763 json_neigh, "remoteRouterId",
8764 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8765
8766 /* Confederation */
8767 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8768 && bgp_confederation_peers_check(bgp, p->as))
8769 json_object_boolean_true_add(json_neigh,
8770 "nbrCommonAdmin");
8771
8772 /* Status. */
8773 json_object_string_add(
8774 json_neigh, "bgpState",
8775 lookup_msg(bgp_status_msg, p->status, NULL));
8776
8777 if (p->status == Established) {
8778 time_t uptime;
8779
8780 uptime = bgp_clock();
8781 uptime -= p->uptime;
8782 epoch_tbuf = time(NULL) - uptime;
8783
8784 #if CONFDATE > 20200101
8785 CPP_NOTICE(
8786 "bgpTimerUp should be deprecated and can be removed now");
8787 #endif
8788 /*
8789 * bgpTimerUp was miliseconds that was accurate
8790 * up to 1 day, then the value returned
8791 * became garbage. So in order to provide
8792 * some level of backwards compatability,
8793 * we still provde the data, but now
8794 * we are returning the correct value
8795 * and also adding a new bgpTimerUpMsec
8796 * which will allow us to deprecate
8797 * this eventually
8798 */
8799 json_object_int_add(json_neigh, "bgpTimerUp",
8800 uptime * 1000);
8801 json_object_int_add(json_neigh, "bgpTimerUpMsec",
8802 uptime * 1000);
8803 json_object_string_add(json_neigh, "bgpTimerUpString",
8804 peer_uptime(p->uptime, timebuf,
8805 BGP_UPTIME_LEN, 0,
8806 NULL));
8807 json_object_int_add(json_neigh,
8808 "bgpTimerUpEstablishedEpoch",
8809 epoch_tbuf);
8810 }
8811
8812 else if (p->status == Active) {
8813 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8814 json_object_string_add(json_neigh, "bgpStateIs",
8815 "passive");
8816 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8817 json_object_string_add(json_neigh, "bgpStateIs",
8818 "passiveNSF");
8819 }
8820
8821 /* read timer */
8822 time_t uptime;
8823 struct tm *tm;
8824
8825 uptime = bgp_clock();
8826 uptime -= p->readtime;
8827 tm = gmtime(&uptime);
8828 json_object_int_add(json_neigh, "bgpTimerLastRead",
8829 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8830 + (tm->tm_hour * 3600000));
8831
8832 uptime = bgp_clock();
8833 uptime -= p->last_write;
8834 tm = gmtime(&uptime);
8835 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8836 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8837 + (tm->tm_hour * 3600000));
8838
8839 uptime = bgp_clock();
8840 uptime -= p->update_time;
8841 tm = gmtime(&uptime);
8842 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8843 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8844 + (tm->tm_hour * 3600000));
8845
8846 /* Configured timer values. */
8847 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8848 p->v_holdtime * 1000);
8849 json_object_int_add(json_neigh,
8850 "bgpTimerKeepAliveIntervalMsecs",
8851 p->v_keepalive * 1000);
8852
8853 if (PEER_OR_GROUP_TIMER_SET(p)) {
8854 json_object_int_add(json_neigh,
8855 "bgpTimerConfiguredHoldTimeMsecs",
8856 p->holdtime * 1000);
8857 json_object_int_add(
8858 json_neigh,
8859 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8860 p->keepalive * 1000);
8861 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8862 || (bgp->default_keepalive
8863 != BGP_DEFAULT_KEEPALIVE)) {
8864 json_object_int_add(json_neigh,
8865 "bgpTimerConfiguredHoldTimeMsecs",
8866 bgp->default_holdtime);
8867 json_object_int_add(
8868 json_neigh,
8869 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8870 bgp->default_keepalive);
8871 }
8872 } else {
8873 /* Administrative shutdown. */
8874 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8875 vty_out(vty, " Administratively shut down\n");
8876
8877 /* BGP Version. */
8878 vty_out(vty, " BGP version 4");
8879 vty_out(vty, ", remote router ID %s\n",
8880 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8881
8882 /* Confederation */
8883 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8884 && bgp_confederation_peers_check(bgp, p->as))
8885 vty_out(vty,
8886 " Neighbor under common administration\n");
8887
8888 /* Status. */
8889 vty_out(vty, " BGP state = %s",
8890 lookup_msg(bgp_status_msg, p->status, NULL));
8891
8892 if (p->status == Established)
8893 vty_out(vty, ", up for %8s",
8894 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8895 0, NULL));
8896
8897 else if (p->status == Active) {
8898 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8899 vty_out(vty, " (passive)");
8900 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8901 vty_out(vty, " (NSF passive)");
8902 }
8903 vty_out(vty, "\n");
8904
8905 /* read timer */
8906 vty_out(vty, " Last read %s",
8907 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8908 NULL));
8909 vty_out(vty, ", Last write %s\n",
8910 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8911 NULL));
8912
8913 /* Configured timer values. */
8914 vty_out(vty,
8915 " Hold time is %d, keepalive interval is %d seconds\n",
8916 p->v_holdtime, p->v_keepalive);
8917 if (PEER_OR_GROUP_TIMER_SET(p)) {
8918 vty_out(vty, " Configured hold time is %d",
8919 p->holdtime);
8920 vty_out(vty, ", keepalive interval is %d seconds\n",
8921 p->keepalive);
8922 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8923 || (bgp->default_keepalive
8924 != BGP_DEFAULT_KEEPALIVE)) {
8925 vty_out(vty, " Configured hold time is %d",
8926 bgp->default_holdtime);
8927 vty_out(vty, ", keepalive interval is %d seconds\n",
8928 bgp->default_keepalive);
8929 }
8930 }
8931 /* Capability. */
8932 if (p->status == Established) {
8933 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8934 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8935 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8936 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8937 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8938 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8939 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8940 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8941 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8942 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8943 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8944 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8945 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8946 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8947 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8948 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8949 if (use_json) {
8950 json_object *json_cap = NULL;
8951
8952 json_cap = json_object_new_object();
8953
8954 /* AS4 */
8955 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8956 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8957 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8958 && CHECK_FLAG(p->cap,
8959 PEER_CAP_AS4_RCV))
8960 json_object_string_add(
8961 json_cap, "4byteAs",
8962 "advertisedAndReceived");
8963 else if (CHECK_FLAG(p->cap,
8964 PEER_CAP_AS4_ADV))
8965 json_object_string_add(
8966 json_cap, "4byteAs",
8967 "advertised");
8968 else if (CHECK_FLAG(p->cap,
8969 PEER_CAP_AS4_RCV))
8970 json_object_string_add(
8971 json_cap, "4byteAs",
8972 "received");
8973 }
8974
8975 /* AddPath */
8976 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8977 || CHECK_FLAG(p->cap,
8978 PEER_CAP_ADDPATH_ADV)) {
8979 json_object *json_add = NULL;
8980 const char *print_store;
8981
8982 json_add = json_object_new_object();
8983
8984 FOREACH_AFI_SAFI (afi, safi) {
8985 json_object *json_sub = NULL;
8986 json_sub =
8987 json_object_new_object();
8988 print_store = afi_safi_print(
8989 afi, safi);
8990
8991 if (CHECK_FLAG(
8992 p->af_cap[afi]
8993 [safi],
8994 PEER_CAP_ADDPATH_AF_TX_ADV)
8995 || CHECK_FLAG(
8996 p->af_cap[afi]
8997 [safi],
8998 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8999 if (CHECK_FLAG(
9000 p->af_cap
9001 [afi]
9002 [safi],
9003 PEER_CAP_ADDPATH_AF_TX_ADV)
9004 && CHECK_FLAG(
9005 p->af_cap
9006 [afi]
9007 [safi],
9008 PEER_CAP_ADDPATH_AF_TX_RCV))
9009 json_object_boolean_true_add(
9010 json_sub,
9011 "txAdvertisedAndReceived");
9012 else if (
9013 CHECK_FLAG(
9014 p->af_cap
9015 [afi]
9016 [safi],
9017 PEER_CAP_ADDPATH_AF_TX_ADV))
9018 json_object_boolean_true_add(
9019 json_sub,
9020 "txAdvertised");
9021 else if (
9022 CHECK_FLAG(
9023 p->af_cap
9024 [afi]
9025 [safi],
9026 PEER_CAP_ADDPATH_AF_TX_RCV))
9027 json_object_boolean_true_add(
9028 json_sub,
9029 "txReceived");
9030 }
9031
9032 if (CHECK_FLAG(
9033 p->af_cap[afi]
9034 [safi],
9035 PEER_CAP_ADDPATH_AF_RX_ADV)
9036 || CHECK_FLAG(
9037 p->af_cap[afi]
9038 [safi],
9039 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9040 if (CHECK_FLAG(
9041 p->af_cap
9042 [afi]
9043 [safi],
9044 PEER_CAP_ADDPATH_AF_RX_ADV)
9045 && CHECK_FLAG(
9046 p->af_cap
9047 [afi]
9048 [safi],
9049 PEER_CAP_ADDPATH_AF_RX_RCV))
9050 json_object_boolean_true_add(
9051 json_sub,
9052 "rxAdvertisedAndReceived");
9053 else if (
9054 CHECK_FLAG(
9055 p->af_cap
9056 [afi]
9057 [safi],
9058 PEER_CAP_ADDPATH_AF_RX_ADV))
9059 json_object_boolean_true_add(
9060 json_sub,
9061 "rxAdvertised");
9062 else if (
9063 CHECK_FLAG(
9064 p->af_cap
9065 [afi]
9066 [safi],
9067 PEER_CAP_ADDPATH_AF_RX_RCV))
9068 json_object_boolean_true_add(
9069 json_sub,
9070 "rxReceived");
9071 }
9072
9073 if (CHECK_FLAG(
9074 p->af_cap[afi]
9075 [safi],
9076 PEER_CAP_ADDPATH_AF_TX_ADV)
9077 || CHECK_FLAG(
9078 p->af_cap[afi]
9079 [safi],
9080 PEER_CAP_ADDPATH_AF_TX_RCV)
9081 || CHECK_FLAG(
9082 p->af_cap[afi]
9083 [safi],
9084 PEER_CAP_ADDPATH_AF_RX_ADV)
9085 || CHECK_FLAG(
9086 p->af_cap[afi]
9087 [safi],
9088 PEER_CAP_ADDPATH_AF_RX_RCV))
9089 json_object_object_add(
9090 json_add,
9091 print_store,
9092 json_sub);
9093 else
9094 json_object_free(
9095 json_sub);
9096 }
9097
9098 json_object_object_add(
9099 json_cap, "addPath", json_add);
9100 }
9101
9102 /* Dynamic */
9103 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9104 || CHECK_FLAG(p->cap,
9105 PEER_CAP_DYNAMIC_ADV)) {
9106 if (CHECK_FLAG(p->cap,
9107 PEER_CAP_DYNAMIC_ADV)
9108 && CHECK_FLAG(p->cap,
9109 PEER_CAP_DYNAMIC_RCV))
9110 json_object_string_add(
9111 json_cap, "dynamic",
9112 "advertisedAndReceived");
9113 else if (CHECK_FLAG(
9114 p->cap,
9115 PEER_CAP_DYNAMIC_ADV))
9116 json_object_string_add(
9117 json_cap, "dynamic",
9118 "advertised");
9119 else if (CHECK_FLAG(
9120 p->cap,
9121 PEER_CAP_DYNAMIC_RCV))
9122 json_object_string_add(
9123 json_cap, "dynamic",
9124 "received");
9125 }
9126
9127 /* Extended nexthop */
9128 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9129 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9130 json_object *json_nxt = NULL;
9131 const char *print_store;
9132
9133
9134 if (CHECK_FLAG(p->cap,
9135 PEER_CAP_ENHE_ADV)
9136 && CHECK_FLAG(p->cap,
9137 PEER_CAP_ENHE_RCV))
9138 json_object_string_add(
9139 json_cap,
9140 "extendedNexthop",
9141 "advertisedAndReceived");
9142 else if (CHECK_FLAG(p->cap,
9143 PEER_CAP_ENHE_ADV))
9144 json_object_string_add(
9145 json_cap,
9146 "extendedNexthop",
9147 "advertised");
9148 else if (CHECK_FLAG(p->cap,
9149 PEER_CAP_ENHE_RCV))
9150 json_object_string_add(
9151 json_cap,
9152 "extendedNexthop",
9153 "received");
9154
9155 if (CHECK_FLAG(p->cap,
9156 PEER_CAP_ENHE_RCV)) {
9157 json_nxt =
9158 json_object_new_object();
9159
9160 for (safi = SAFI_UNICAST;
9161 safi < SAFI_MAX; safi++) {
9162 if (CHECK_FLAG(
9163 p->af_cap
9164 [AFI_IP]
9165 [safi],
9166 PEER_CAP_ENHE_AF_RCV)) {
9167 print_store = afi_safi_print(
9168 AFI_IP,
9169 safi);
9170 json_object_string_add(
9171 json_nxt,
9172 print_store,
9173 "recieved");
9174 }
9175 }
9176 json_object_object_add(
9177 json_cap,
9178 "extendedNexthopFamililesByPeer",
9179 json_nxt);
9180 }
9181 }
9182
9183 /* Route Refresh */
9184 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9185 || CHECK_FLAG(p->cap,
9186 PEER_CAP_REFRESH_NEW_RCV)
9187 || CHECK_FLAG(p->cap,
9188 PEER_CAP_REFRESH_OLD_RCV)) {
9189 if (CHECK_FLAG(p->cap,
9190 PEER_CAP_REFRESH_ADV)
9191 && (CHECK_FLAG(
9192 p->cap,
9193 PEER_CAP_REFRESH_NEW_RCV)
9194 || CHECK_FLAG(
9195 p->cap,
9196 PEER_CAP_REFRESH_OLD_RCV))) {
9197 if (CHECK_FLAG(
9198 p->cap,
9199 PEER_CAP_REFRESH_OLD_RCV)
9200 && CHECK_FLAG(
9201 p->cap,
9202 PEER_CAP_REFRESH_NEW_RCV))
9203 json_object_string_add(
9204 json_cap,
9205 "routeRefresh",
9206 "advertisedAndReceivedOldNew");
9207 else {
9208 if (CHECK_FLAG(
9209 p->cap,
9210 PEER_CAP_REFRESH_OLD_RCV))
9211 json_object_string_add(
9212 json_cap,
9213 "routeRefresh",
9214 "advertisedAndReceivedOld");
9215 else
9216 json_object_string_add(
9217 json_cap,
9218 "routeRefresh",
9219 "advertisedAndReceivedNew");
9220 }
9221 } else if (
9222 CHECK_FLAG(
9223 p->cap,
9224 PEER_CAP_REFRESH_ADV))
9225 json_object_string_add(
9226 json_cap,
9227 "routeRefresh",
9228 "advertised");
9229 else if (
9230 CHECK_FLAG(
9231 p->cap,
9232 PEER_CAP_REFRESH_NEW_RCV)
9233 || CHECK_FLAG(
9234 p->cap,
9235 PEER_CAP_REFRESH_OLD_RCV))
9236 json_object_string_add(
9237 json_cap,
9238 "routeRefresh",
9239 "received");
9240 }
9241
9242 /* Multiprotocol Extensions */
9243 json_object *json_multi = NULL;
9244 json_multi = json_object_new_object();
9245
9246 FOREACH_AFI_SAFI (afi, safi) {
9247 if (p->afc_adv[afi][safi]
9248 || p->afc_recv[afi][safi]) {
9249 json_object *json_exten = NULL;
9250 json_exten =
9251 json_object_new_object();
9252
9253 if (p->afc_adv[afi][safi]
9254 && p->afc_recv[afi][safi])
9255 json_object_boolean_true_add(
9256 json_exten,
9257 "advertisedAndReceived");
9258 else if (p->afc_adv[afi][safi])
9259 json_object_boolean_true_add(
9260 json_exten,
9261 "advertised");
9262 else if (p->afc_recv[afi][safi])
9263 json_object_boolean_true_add(
9264 json_exten,
9265 "received");
9266
9267 json_object_object_add(
9268 json_multi,
9269 afi_safi_print(afi,
9270 safi),
9271 json_exten);
9272 }
9273 }
9274 json_object_object_add(
9275 json_cap, "multiprotocolExtensions",
9276 json_multi);
9277
9278 /* Hostname capabilities */
9279 json_object *json_hname = NULL;
9280
9281 json_hname = json_object_new_object();
9282
9283 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9284 json_object_string_add(
9285 json_hname, "advHostName",
9286 bgp->peer_self->hostname
9287 ? bgp->peer_self
9288 ->hostname
9289 : "n/a");
9290 json_object_string_add(
9291 json_hname, "advDomainName",
9292 bgp->peer_self->domainname
9293 ? bgp->peer_self
9294 ->domainname
9295 : "n/a");
9296 }
9297
9298
9299 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9300 json_object_string_add(
9301 json_hname, "rcvHostName",
9302 p->hostname ? p->hostname
9303 : "n/a");
9304 json_object_string_add(
9305 json_hname, "rcvDomainName",
9306 p->domainname ? p->domainname
9307 : "n/a");
9308 }
9309
9310 json_object_object_add(json_cap, "hostName",
9311 json_hname);
9312
9313 /* Gracefull Restart */
9314 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9315 || CHECK_FLAG(p->cap,
9316 PEER_CAP_RESTART_ADV)) {
9317 if (CHECK_FLAG(p->cap,
9318 PEER_CAP_RESTART_ADV)
9319 && CHECK_FLAG(p->cap,
9320 PEER_CAP_RESTART_RCV))
9321 json_object_string_add(
9322 json_cap,
9323 "gracefulRestart",
9324 "advertisedAndReceived");
9325 else if (CHECK_FLAG(
9326 p->cap,
9327 PEER_CAP_RESTART_ADV))
9328 json_object_string_add(
9329 json_cap,
9330 "gracefulRestartCapability",
9331 "advertised");
9332 else if (CHECK_FLAG(
9333 p->cap,
9334 PEER_CAP_RESTART_RCV))
9335 json_object_string_add(
9336 json_cap,
9337 "gracefulRestartCapability",
9338 "received");
9339
9340 if (CHECK_FLAG(p->cap,
9341 PEER_CAP_RESTART_RCV)) {
9342 int restart_af_count = 0;
9343 json_object *json_restart =
9344 NULL;
9345 json_restart =
9346 json_object_new_object();
9347
9348 json_object_int_add(
9349 json_cap,
9350 "gracefulRestartRemoteTimerMsecs",
9351 p->v_gr_restart * 1000);
9352
9353 FOREACH_AFI_SAFI (afi, safi) {
9354 if (CHECK_FLAG(
9355 p->af_cap
9356 [afi]
9357 [safi],
9358 PEER_CAP_RESTART_AF_RCV)) {
9359 json_object *
9360 json_sub =
9361 NULL;
9362 json_sub =
9363 json_object_new_object();
9364
9365 if (CHECK_FLAG(
9366 p->af_cap
9367 [afi]
9368 [safi],
9369 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9370 json_object_boolean_true_add(
9371 json_sub,
9372 "preserved");
9373 restart_af_count++;
9374 json_object_object_add(
9375 json_restart,
9376 afi_safi_print(
9377 afi,
9378 safi),
9379 json_sub);
9380 }
9381 }
9382 if (!restart_af_count) {
9383 json_object_string_add(
9384 json_cap,
9385 "addressFamiliesByPeer",
9386 "none");
9387 json_object_free(
9388 json_restart);
9389 } else
9390 json_object_object_add(
9391 json_cap,
9392 "addressFamiliesByPeer",
9393 json_restart);
9394 }
9395 }
9396 json_object_object_add(json_neigh,
9397 "neighborCapabilities",
9398 json_cap);
9399 } else {
9400 vty_out(vty, " Neighbor capabilities:\n");
9401
9402 /* AS4 */
9403 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9404 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9405 vty_out(vty, " 4 Byte AS:");
9406 if (CHECK_FLAG(p->cap,
9407 PEER_CAP_AS4_ADV))
9408 vty_out(vty, " advertised");
9409 if (CHECK_FLAG(p->cap,
9410 PEER_CAP_AS4_RCV))
9411 vty_out(vty, " %sreceived",
9412 CHECK_FLAG(
9413 p->cap,
9414 PEER_CAP_AS4_ADV)
9415 ? "and "
9416 : "");
9417 vty_out(vty, "\n");
9418 }
9419
9420 /* AddPath */
9421 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9422 || CHECK_FLAG(p->cap,
9423 PEER_CAP_ADDPATH_ADV)) {
9424 vty_out(vty, " AddPath:\n");
9425
9426 FOREACH_AFI_SAFI (afi, safi) {
9427 if (CHECK_FLAG(
9428 p->af_cap[afi]
9429 [safi],
9430 PEER_CAP_ADDPATH_AF_TX_ADV)
9431 || CHECK_FLAG(
9432 p->af_cap[afi]
9433 [safi],
9434 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9435 vty_out(vty,
9436 " %s: TX ",
9437 afi_safi_print(
9438 afi,
9439 safi));
9440
9441 if (CHECK_FLAG(
9442 p->af_cap
9443 [afi]
9444 [safi],
9445 PEER_CAP_ADDPATH_AF_TX_ADV))
9446 vty_out(vty,
9447 "advertised %s",
9448 afi_safi_print(
9449 afi,
9450 safi));
9451
9452 if (CHECK_FLAG(
9453 p->af_cap
9454 [afi]
9455 [safi],
9456 PEER_CAP_ADDPATH_AF_TX_RCV))
9457 vty_out(vty,
9458 "%sreceived",
9459 CHECK_FLAG(
9460 p->af_cap
9461 [afi]
9462 [safi],
9463 PEER_CAP_ADDPATH_AF_TX_ADV)
9464 ? " and "
9465 : "");
9466
9467 vty_out(vty, "\n");
9468 }
9469
9470 if (CHECK_FLAG(
9471 p->af_cap[afi]
9472 [safi],
9473 PEER_CAP_ADDPATH_AF_RX_ADV)
9474 || CHECK_FLAG(
9475 p->af_cap[afi]
9476 [safi],
9477 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9478 vty_out(vty,
9479 " %s: RX ",
9480 afi_safi_print(
9481 afi,
9482 safi));
9483
9484 if (CHECK_FLAG(
9485 p->af_cap
9486 [afi]
9487 [safi],
9488 PEER_CAP_ADDPATH_AF_RX_ADV))
9489 vty_out(vty,
9490 "advertised %s",
9491 afi_safi_print(
9492 afi,
9493 safi));
9494
9495 if (CHECK_FLAG(
9496 p->af_cap
9497 [afi]
9498 [safi],
9499 PEER_CAP_ADDPATH_AF_RX_RCV))
9500 vty_out(vty,
9501 "%sreceived",
9502 CHECK_FLAG(
9503 p->af_cap
9504 [afi]
9505 [safi],
9506 PEER_CAP_ADDPATH_AF_RX_ADV)
9507 ? " and "
9508 : "");
9509
9510 vty_out(vty, "\n");
9511 }
9512 }
9513 }
9514
9515 /* Dynamic */
9516 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9517 || CHECK_FLAG(p->cap,
9518 PEER_CAP_DYNAMIC_ADV)) {
9519 vty_out(vty, " Dynamic:");
9520 if (CHECK_FLAG(p->cap,
9521 PEER_CAP_DYNAMIC_ADV))
9522 vty_out(vty, " advertised");
9523 if (CHECK_FLAG(p->cap,
9524 PEER_CAP_DYNAMIC_RCV))
9525 vty_out(vty, " %sreceived",
9526 CHECK_FLAG(
9527 p->cap,
9528 PEER_CAP_DYNAMIC_ADV)
9529 ? "and "
9530 : "");
9531 vty_out(vty, "\n");
9532 }
9533
9534 /* Extended nexthop */
9535 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9536 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9537 vty_out(vty, " Extended nexthop:");
9538 if (CHECK_FLAG(p->cap,
9539 PEER_CAP_ENHE_ADV))
9540 vty_out(vty, " advertised");
9541 if (CHECK_FLAG(p->cap,
9542 PEER_CAP_ENHE_RCV))
9543 vty_out(vty, " %sreceived",
9544 CHECK_FLAG(
9545 p->cap,
9546 PEER_CAP_ENHE_ADV)
9547 ? "and "
9548 : "");
9549 vty_out(vty, "\n");
9550
9551 if (CHECK_FLAG(p->cap,
9552 PEER_CAP_ENHE_RCV)) {
9553 vty_out(vty,
9554 " Address families by peer:\n ");
9555 for (safi = SAFI_UNICAST;
9556 safi < SAFI_MAX; safi++)
9557 if (CHECK_FLAG(
9558 p->af_cap
9559 [AFI_IP]
9560 [safi],
9561 PEER_CAP_ENHE_AF_RCV))
9562 vty_out(vty,
9563 " %s\n",
9564 afi_safi_print(
9565 AFI_IP,
9566 safi));
9567 }
9568 }
9569
9570 /* Route Refresh */
9571 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9572 || CHECK_FLAG(p->cap,
9573 PEER_CAP_REFRESH_NEW_RCV)
9574 || CHECK_FLAG(p->cap,
9575 PEER_CAP_REFRESH_OLD_RCV)) {
9576 vty_out(vty, " Route refresh:");
9577 if (CHECK_FLAG(p->cap,
9578 PEER_CAP_REFRESH_ADV))
9579 vty_out(vty, " advertised");
9580 if (CHECK_FLAG(p->cap,
9581 PEER_CAP_REFRESH_NEW_RCV)
9582 || CHECK_FLAG(
9583 p->cap,
9584 PEER_CAP_REFRESH_OLD_RCV))
9585 vty_out(vty, " %sreceived(%s)",
9586 CHECK_FLAG(
9587 p->cap,
9588 PEER_CAP_REFRESH_ADV)
9589 ? "and "
9590 : "",
9591 (CHECK_FLAG(
9592 p->cap,
9593 PEER_CAP_REFRESH_OLD_RCV)
9594 && CHECK_FLAG(
9595 p->cap,
9596 PEER_CAP_REFRESH_NEW_RCV))
9597 ? "old & new"
9598 : CHECK_FLAG(
9599 p->cap,
9600 PEER_CAP_REFRESH_OLD_RCV)
9601 ? "old"
9602 : "new");
9603
9604 vty_out(vty, "\n");
9605 }
9606
9607 /* Multiprotocol Extensions */
9608 FOREACH_AFI_SAFI (afi, safi)
9609 if (p->afc_adv[afi][safi]
9610 || p->afc_recv[afi][safi]) {
9611 vty_out(vty,
9612 " Address Family %s:",
9613 afi_safi_print(afi,
9614 safi));
9615 if (p->afc_adv[afi][safi])
9616 vty_out(vty,
9617 " advertised");
9618 if (p->afc_recv[afi][safi])
9619 vty_out(vty,
9620 " %sreceived",
9621 p->afc_adv[afi]
9622 [safi]
9623 ? "and "
9624 : "");
9625 vty_out(vty, "\n");
9626 }
9627
9628 /* Hostname capability */
9629 vty_out(vty, " Hostname Capability:");
9630
9631 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9632 vty_out(vty,
9633 " advertised (name: %s,domain name: %s)",
9634 bgp->peer_self->hostname
9635 ? bgp->peer_self
9636 ->hostname
9637 : "n/a",
9638 bgp->peer_self->domainname
9639 ? bgp->peer_self
9640 ->domainname
9641 : "n/a");
9642 } else {
9643 vty_out(vty, " not advertised");
9644 }
9645
9646 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9647 vty_out(vty,
9648 " received (name: %s,domain name: %s)",
9649 p->hostname ? p->hostname
9650 : "n/a",
9651 p->domainname ? p->domainname
9652 : "n/a");
9653 } else {
9654 vty_out(vty, " not received");
9655 }
9656
9657 vty_out(vty, "\n");
9658
9659 /* Gracefull Restart */
9660 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9661 || CHECK_FLAG(p->cap,
9662 PEER_CAP_RESTART_ADV)) {
9663 vty_out(vty,
9664 " Graceful Restart Capabilty:");
9665 if (CHECK_FLAG(p->cap,
9666 PEER_CAP_RESTART_ADV))
9667 vty_out(vty, " advertised");
9668 if (CHECK_FLAG(p->cap,
9669 PEER_CAP_RESTART_RCV))
9670 vty_out(vty, " %sreceived",
9671 CHECK_FLAG(
9672 p->cap,
9673 PEER_CAP_RESTART_ADV)
9674 ? "and "
9675 : "");
9676 vty_out(vty, "\n");
9677
9678 if (CHECK_FLAG(p->cap,
9679 PEER_CAP_RESTART_RCV)) {
9680 int restart_af_count = 0;
9681
9682 vty_out(vty,
9683 " Remote Restart timer is %d seconds\n",
9684 p->v_gr_restart);
9685 vty_out(vty,
9686 " Address families by peer:\n ");
9687
9688 FOREACH_AFI_SAFI (afi, safi)
9689 if (CHECK_FLAG(
9690 p->af_cap
9691 [afi]
9692 [safi],
9693 PEER_CAP_RESTART_AF_RCV)) {
9694 vty_out(vty,
9695 "%s%s(%s)",
9696 restart_af_count
9697 ? ", "
9698 : "",
9699 afi_safi_print(
9700 afi,
9701 safi),
9702 CHECK_FLAG(
9703 p->af_cap
9704 [afi]
9705 [safi],
9706 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9707 ? "preserved"
9708 : "not preserved");
9709 restart_af_count++;
9710 }
9711 if (!restart_af_count)
9712 vty_out(vty, "none");
9713 vty_out(vty, "\n");
9714 }
9715 }
9716 }
9717 }
9718 }
9719
9720 /* graceful restart information */
9721 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9722 || p->t_gr_stale) {
9723 json_object *json_grace = NULL;
9724 json_object *json_grace_send = NULL;
9725 json_object *json_grace_recv = NULL;
9726 int eor_send_af_count = 0;
9727 int eor_receive_af_count = 0;
9728
9729 if (use_json) {
9730 json_grace = json_object_new_object();
9731 json_grace_send = json_object_new_object();
9732 json_grace_recv = json_object_new_object();
9733
9734 if (p->status == Established) {
9735 FOREACH_AFI_SAFI (afi, safi) {
9736 if (CHECK_FLAG(p->af_sflags[afi][safi],
9737 PEER_STATUS_EOR_SEND)) {
9738 json_object_boolean_true_add(
9739 json_grace_send,
9740 afi_safi_print(afi,
9741 safi));
9742 eor_send_af_count++;
9743 }
9744 }
9745 FOREACH_AFI_SAFI (afi, safi) {
9746 if (CHECK_FLAG(
9747 p->af_sflags[afi][safi],
9748 PEER_STATUS_EOR_RECEIVED)) {
9749 json_object_boolean_true_add(
9750 json_grace_recv,
9751 afi_safi_print(afi,
9752 safi));
9753 eor_receive_af_count++;
9754 }
9755 }
9756 }
9757
9758 json_object_object_add(json_grace, "endOfRibSend",
9759 json_grace_send);
9760 json_object_object_add(json_grace, "endOfRibRecv",
9761 json_grace_recv);
9762
9763 if (p->t_gr_restart)
9764 json_object_int_add(json_grace,
9765 "gracefulRestartTimerMsecs",
9766 thread_timer_remain_second(
9767 p->t_gr_restart)
9768 * 1000);
9769
9770 if (p->t_gr_stale)
9771 json_object_int_add(
9772 json_grace,
9773 "gracefulStalepathTimerMsecs",
9774 thread_timer_remain_second(
9775 p->t_gr_stale)
9776 * 1000);
9777
9778 json_object_object_add(
9779 json_neigh, "gracefulRestartInfo", json_grace);
9780 } else {
9781 vty_out(vty, " Graceful restart informations:\n");
9782 if (p->status == Established) {
9783 vty_out(vty, " End-of-RIB send: ");
9784 FOREACH_AFI_SAFI (afi, safi) {
9785 if (CHECK_FLAG(p->af_sflags[afi][safi],
9786 PEER_STATUS_EOR_SEND)) {
9787 vty_out(vty, "%s%s",
9788 eor_send_af_count ? ", "
9789 : "",
9790 afi_safi_print(afi,
9791 safi));
9792 eor_send_af_count++;
9793 }
9794 }
9795 vty_out(vty, "\n");
9796 vty_out(vty, " End-of-RIB received: ");
9797 FOREACH_AFI_SAFI (afi, safi) {
9798 if (CHECK_FLAG(
9799 p->af_sflags[afi][safi],
9800 PEER_STATUS_EOR_RECEIVED)) {
9801 vty_out(vty, "%s%s",
9802 eor_receive_af_count
9803 ? ", "
9804 : "",
9805 afi_safi_print(afi,
9806 safi));
9807 eor_receive_af_count++;
9808 }
9809 }
9810 vty_out(vty, "\n");
9811 }
9812
9813 if (p->t_gr_restart)
9814 vty_out(vty,
9815 " The remaining time of restart timer is %ld\n",
9816 thread_timer_remain_second(
9817 p->t_gr_restart));
9818
9819 if (p->t_gr_stale)
9820 vty_out(vty,
9821 " The remaining time of stalepath timer is %ld\n",
9822 thread_timer_remain_second(
9823 p->t_gr_stale));
9824 }
9825 }
9826 if (use_json) {
9827 json_object *json_stat = NULL;
9828 json_stat = json_object_new_object();
9829 /* Packet counts. */
9830 json_object_int_add(json_stat, "depthInq", 0);
9831 json_object_int_add(json_stat, "depthOutq",
9832 (unsigned long)p->obuf->count);
9833 json_object_int_add(json_stat, "opensSent",
9834 atomic_load_explicit(&p->open_out,
9835 memory_order_relaxed));
9836 json_object_int_add(json_stat, "opensRecv",
9837 atomic_load_explicit(&p->open_in,
9838 memory_order_relaxed));
9839 json_object_int_add(json_stat, "notificationsSent",
9840 atomic_load_explicit(&p->notify_out,
9841 memory_order_relaxed));
9842 json_object_int_add(json_stat, "notificationsRecv",
9843 atomic_load_explicit(&p->notify_in,
9844 memory_order_relaxed));
9845 json_object_int_add(json_stat, "updatesSent",
9846 atomic_load_explicit(&p->update_out,
9847 memory_order_relaxed));
9848 json_object_int_add(json_stat, "updatesRecv",
9849 atomic_load_explicit(&p->update_in,
9850 memory_order_relaxed));
9851 json_object_int_add(json_stat, "keepalivesSent",
9852 atomic_load_explicit(&p->keepalive_out,
9853 memory_order_relaxed));
9854 json_object_int_add(json_stat, "keepalivesRecv",
9855 atomic_load_explicit(&p->keepalive_in,
9856 memory_order_relaxed));
9857 json_object_int_add(json_stat, "routeRefreshSent",
9858 atomic_load_explicit(&p->refresh_out,
9859 memory_order_relaxed));
9860 json_object_int_add(json_stat, "routeRefreshRecv",
9861 atomic_load_explicit(&p->refresh_in,
9862 memory_order_relaxed));
9863 json_object_int_add(json_stat, "capabilitySent",
9864 atomic_load_explicit(&p->dynamic_cap_out,
9865 memory_order_relaxed));
9866 json_object_int_add(json_stat, "capabilityRecv",
9867 atomic_load_explicit(&p->dynamic_cap_in,
9868 memory_order_relaxed));
9869 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
9870 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
9871 json_object_object_add(json_neigh, "messageStats", json_stat);
9872 } else {
9873 /* Packet counts. */
9874 vty_out(vty, " Message statistics:\n");
9875 vty_out(vty, " Inq depth is 0\n");
9876 vty_out(vty, " Outq depth is %lu\n",
9877 (unsigned long)p->obuf->count);
9878 vty_out(vty, " Sent Rcvd\n");
9879 vty_out(vty, " Opens: %10d %10d\n",
9880 atomic_load_explicit(&p->open_out,
9881 memory_order_relaxed),
9882 atomic_load_explicit(&p->open_in,
9883 memory_order_relaxed));
9884 vty_out(vty, " Notifications: %10d %10d\n",
9885 atomic_load_explicit(&p->notify_out,
9886 memory_order_relaxed),
9887 atomic_load_explicit(&p->notify_in,
9888 memory_order_relaxed));
9889 vty_out(vty, " Updates: %10d %10d\n",
9890 atomic_load_explicit(&p->update_out,
9891 memory_order_relaxed),
9892 atomic_load_explicit(&p->update_in,
9893 memory_order_relaxed));
9894 vty_out(vty, " Keepalives: %10d %10d\n",
9895 atomic_load_explicit(&p->keepalive_out,
9896 memory_order_relaxed),
9897 atomic_load_explicit(&p->keepalive_in,
9898 memory_order_relaxed));
9899 vty_out(vty, " Route Refresh: %10d %10d\n",
9900 atomic_load_explicit(&p->refresh_out,
9901 memory_order_relaxed),
9902 atomic_load_explicit(&p->refresh_in,
9903 memory_order_relaxed));
9904 vty_out(vty, " Capability: %10d %10d\n",
9905 atomic_load_explicit(&p->dynamic_cap_out,
9906 memory_order_relaxed),
9907 atomic_load_explicit(&p->dynamic_cap_in,
9908 memory_order_relaxed));
9909 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
9910 PEER_TOTAL_RX(p));
9911 }
9912
9913 if (use_json) {
9914 /* advertisement-interval */
9915 json_object_int_add(json_neigh,
9916 "minBtwnAdvertisementRunsTimerMsecs",
9917 p->v_routeadv * 1000);
9918
9919 /* Update-source. */
9920 if (p->update_if || p->update_source) {
9921 if (p->update_if)
9922 json_object_string_add(json_neigh,
9923 "updateSource",
9924 p->update_if);
9925 else if (p->update_source)
9926 json_object_string_add(
9927 json_neigh, "updateSource",
9928 sockunion2str(p->update_source, buf1,
9929 SU_ADDRSTRLEN));
9930 }
9931 } else {
9932 /* advertisement-interval */
9933 vty_out(vty,
9934 " Minimum time between advertisement runs is %d seconds\n",
9935 p->v_routeadv);
9936
9937 /* Update-source. */
9938 if (p->update_if || p->update_source) {
9939 vty_out(vty, " Update source is ");
9940 if (p->update_if)
9941 vty_out(vty, "%s", p->update_if);
9942 else if (p->update_source)
9943 vty_out(vty, "%s",
9944 sockunion2str(p->update_source, buf1,
9945 SU_ADDRSTRLEN));
9946 vty_out(vty, "\n");
9947 }
9948
9949 vty_out(vty, "\n");
9950 }
9951
9952 /* Address Family Information */
9953 json_object *json_hold = NULL;
9954
9955 if (use_json)
9956 json_hold = json_object_new_object();
9957
9958 FOREACH_AFI_SAFI (afi, safi)
9959 if (p->afc[afi][safi])
9960 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9961 json_hold);
9962
9963 if (use_json) {
9964 json_object_object_add(json_neigh, "addressFamilyInfo",
9965 json_hold);
9966 json_object_int_add(json_neigh, "connectionsEstablished",
9967 p->established);
9968 json_object_int_add(json_neigh, "connectionsDropped",
9969 p->dropped);
9970 } else
9971 vty_out(vty, " Connections established %d; dropped %d\n",
9972 p->established, p->dropped);
9973
9974 if (!p->last_reset) {
9975 if (use_json)
9976 json_object_string_add(json_neigh, "lastReset",
9977 "never");
9978 else
9979 vty_out(vty, " Last reset never\n");
9980 } else {
9981 if (use_json) {
9982 time_t uptime;
9983 struct tm *tm;
9984
9985 uptime = bgp_clock();
9986 uptime -= p->resettime;
9987 tm = gmtime(&uptime);
9988 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9989 (tm->tm_sec * 1000)
9990 + (tm->tm_min * 60000)
9991 + (tm->tm_hour * 3600000));
9992 json_object_string_add(
9993 json_neigh, "lastResetDueTo",
9994 peer_down_str[(int)p->last_reset]);
9995 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9996 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9997 char errorcodesubcode_hexstr[5];
9998 char errorcodesubcode_str[256];
9999
10000 code_str = bgp_notify_code_str(p->notify.code);
10001 subcode_str = bgp_notify_subcode_str(
10002 p->notify.code, p->notify.subcode);
10003
10004 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10005 p->notify.code, p->notify.subcode);
10006 json_object_string_add(json_neigh,
10007 "lastErrorCodeSubcode",
10008 errorcodesubcode_hexstr);
10009 snprintf(errorcodesubcode_str, 255, "%s%s",
10010 code_str, subcode_str);
10011 json_object_string_add(json_neigh,
10012 "lastNotificationReason",
10013 errorcodesubcode_str);
10014 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10015 && p->notify.code == BGP_NOTIFY_CEASE
10016 && (p->notify.subcode
10017 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10018 || p->notify.subcode
10019 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10020 && p->notify.length) {
10021 char msgbuf[1024];
10022 const char *msg_str;
10023
10024 msg_str = bgp_notify_admin_message(
10025 msgbuf, sizeof(msgbuf),
10026 (u_char *)p->notify.data,
10027 p->notify.length);
10028 if (msg_str)
10029 json_object_string_add(
10030 json_neigh,
10031 "lastShutdownDescription",
10032 msg_str);
10033 }
10034 }
10035 } else {
10036 vty_out(vty, " Last reset %s, ",
10037 peer_uptime(p->resettime, timebuf,
10038 BGP_UPTIME_LEN, 0, NULL));
10039
10040 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10041 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10042 code_str = bgp_notify_code_str(p->notify.code);
10043 subcode_str = bgp_notify_subcode_str(
10044 p->notify.code, p->notify.subcode);
10045 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10046 p->last_reset == PEER_DOWN_NOTIFY_SEND
10047 ? "sent"
10048 : "received",
10049 code_str, subcode_str);
10050 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10051 && p->notify.code == BGP_NOTIFY_CEASE
10052 && (p->notify.subcode
10053 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10054 || p->notify.subcode
10055 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10056 && p->notify.length) {
10057 char msgbuf[1024];
10058 const char *msg_str;
10059
10060 msg_str = bgp_notify_admin_message(
10061 msgbuf, sizeof(msgbuf),
10062 (u_char *)p->notify.data,
10063 p->notify.length);
10064 if (msg_str)
10065 vty_out(vty,
10066 " Message: \"%s\"\n",
10067 msg_str);
10068 }
10069 } else {
10070 vty_out(vty, "due to %s\n",
10071 peer_down_str[(int)p->last_reset]);
10072 }
10073
10074 if (p->last_reset_cause_size) {
10075 msg = p->last_reset_cause;
10076 vty_out(vty,
10077 " Message received that caused BGP to send a NOTIFICATION:\n ");
10078 for (i = 1; i <= p->last_reset_cause_size;
10079 i++) {
10080 vty_out(vty, "%02X", *msg++);
10081
10082 if (i != p->last_reset_cause_size) {
10083 if (i % 16 == 0) {
10084 vty_out(vty, "\n ");
10085 } else if (i % 4 == 0) {
10086 vty_out(vty, " ");
10087 }
10088 }
10089 }
10090 vty_out(vty, "\n");
10091 }
10092 }
10093 }
10094
10095 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10096 if (use_json)
10097 json_object_boolean_true_add(json_neigh,
10098 "prefixesConfigExceedMax");
10099 else
10100 vty_out(vty,
10101 " Peer had exceeded the max. no. of prefixes configured.\n");
10102
10103 if (p->t_pmax_restart) {
10104 if (use_json) {
10105 json_object_boolean_true_add(
10106 json_neigh, "reducePrefixNumFrom");
10107 json_object_int_add(json_neigh,
10108 "restartInTimerMsec",
10109 thread_timer_remain_second(
10110 p->t_pmax_restart)
10111 * 1000);
10112 } else
10113 vty_out(vty,
10114 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
10115 p->host, thread_timer_remain_second(
10116 p->t_pmax_restart));
10117 } else {
10118 if (use_json)
10119 json_object_boolean_true_add(
10120 json_neigh,
10121 "reducePrefixNumAndClearIpBgp");
10122 else
10123 vty_out(vty,
10124 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10125 p->host);
10126 }
10127 }
10128
10129 /* EBGP Multihop and GTSM */
10130 if (p->sort != BGP_PEER_IBGP) {
10131 if (use_json) {
10132 if (p->gtsm_hops > 0)
10133 json_object_int_add(json_neigh,
10134 "externalBgpNbrMaxHopsAway",
10135 p->gtsm_hops);
10136 else if (p->ttl > 1)
10137 json_object_int_add(json_neigh,
10138 "externalBgpNbrMaxHopsAway",
10139 p->ttl);
10140 } else {
10141 if (p->gtsm_hops > 0)
10142 vty_out(vty,
10143 " External BGP neighbor may be up to %d hops away.\n",
10144 p->gtsm_hops);
10145 else if (p->ttl > 1)
10146 vty_out(vty,
10147 " External BGP neighbor may be up to %d hops away.\n",
10148 p->ttl);
10149 }
10150 } else {
10151 if (p->gtsm_hops > 0) {
10152 if (use_json)
10153 json_object_int_add(json_neigh,
10154 "internalBgpNbrMaxHopsAway",
10155 p->gtsm_hops);
10156 else
10157 vty_out(vty,
10158 " Internal BGP neighbor may be up to %d hops away.\n",
10159 p->gtsm_hops);
10160 }
10161 }
10162
10163 /* Local address. */
10164 if (p->su_local) {
10165 if (use_json) {
10166 json_object_string_add(json_neigh, "hostLocal",
10167 sockunion2str(p->su_local, buf1,
10168 SU_ADDRSTRLEN));
10169 json_object_int_add(json_neigh, "portLocal",
10170 ntohs(p->su_local->sin.sin_port));
10171 } else
10172 vty_out(vty, "Local host: %s, Local port: %d\n",
10173 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10174 ntohs(p->su_local->sin.sin_port));
10175 }
10176
10177 /* Remote address. */
10178 if (p->su_remote) {
10179 if (use_json) {
10180 json_object_string_add(json_neigh, "hostForeign",
10181 sockunion2str(p->su_remote, buf1,
10182 SU_ADDRSTRLEN));
10183 json_object_int_add(json_neigh, "portForeign",
10184 ntohs(p->su_remote->sin.sin_port));
10185 } else
10186 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10187 sockunion2str(p->su_remote, buf1,
10188 SU_ADDRSTRLEN),
10189 ntohs(p->su_remote->sin.sin_port));
10190 }
10191
10192 /* Nexthop display. */
10193 if (p->su_local) {
10194 if (use_json) {
10195 json_object_string_add(json_neigh, "nexthop",
10196 inet_ntop(AF_INET,
10197 &p->nexthop.v4, buf1,
10198 sizeof(buf1)));
10199 json_object_string_add(json_neigh, "nexthopGlobal",
10200 inet_ntop(AF_INET6,
10201 &p->nexthop.v6_global,
10202 buf1, sizeof(buf1)));
10203 json_object_string_add(json_neigh, "nexthopLocal",
10204 inet_ntop(AF_INET6,
10205 &p->nexthop.v6_local,
10206 buf1, sizeof(buf1)));
10207 if (p->shared_network)
10208 json_object_string_add(json_neigh,
10209 "bgpConnection",
10210 "sharedNetwork");
10211 else
10212 json_object_string_add(json_neigh,
10213 "bgpConnection",
10214 "nonSharedNetwork");
10215 } else {
10216 vty_out(vty, "Nexthop: %s\n",
10217 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10218 sizeof(buf1)));
10219 vty_out(vty, "Nexthop global: %s\n",
10220 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10221 sizeof(buf1)));
10222 vty_out(vty, "Nexthop local: %s\n",
10223 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10224 sizeof(buf1)));
10225 vty_out(vty, "BGP connection: %s\n",
10226 p->shared_network ? "shared network"
10227 : "non shared network");
10228 }
10229 }
10230
10231 /* Timer information. */
10232 if (use_json) {
10233 json_object_int_add(json_neigh, "connectRetryTimer",
10234 p->v_connect);
10235 if (p->status == Established && p->rtt)
10236 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10237 p->rtt);
10238 if (p->t_start)
10239 json_object_int_add(
10240 json_neigh, "nextStartTimerDueInMsecs",
10241 thread_timer_remain_second(p->t_start) * 1000);
10242 if (p->t_connect)
10243 json_object_int_add(
10244 json_neigh, "nextConnectTimerDueInMsecs",
10245 thread_timer_remain_second(p->t_connect)
10246 * 1000);
10247 if (p->t_routeadv) {
10248 json_object_int_add(json_neigh, "mraiInterval",
10249 p->v_routeadv);
10250 json_object_int_add(
10251 json_neigh, "mraiTimerExpireInMsecs",
10252 thread_timer_remain_second(p->t_routeadv)
10253 * 1000);
10254 }
10255 if (p->password)
10256 json_object_int_add(json_neigh, "authenticationEnabled",
10257 1);
10258
10259 if (p->t_read)
10260 json_object_string_add(json_neigh, "readThread", "on");
10261 else
10262 json_object_string_add(json_neigh, "readThread", "off");
10263
10264 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
10265 json_object_string_add(json_neigh, "writeThread", "on");
10266 else
10267 json_object_string_add(json_neigh, "writeThread",
10268 "off");
10269 } else {
10270 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10271 p->v_connect);
10272 if (p->status == Established && p->rtt)
10273 vty_out(vty, "Estimated round trip time: %d ms\n",
10274 p->rtt);
10275 if (p->t_start)
10276 vty_out(vty, "Next start timer due in %ld seconds\n",
10277 thread_timer_remain_second(p->t_start));
10278 if (p->t_connect)
10279 vty_out(vty, "Next connect timer due in %ld seconds\n",
10280 thread_timer_remain_second(p->t_connect));
10281 if (p->t_routeadv)
10282 vty_out(vty,
10283 "MRAI (interval %u) timer expires in %ld seconds\n",
10284 p->v_routeadv,
10285 thread_timer_remain_second(p->t_routeadv));
10286 if (p->password)
10287 vty_out(vty, "Peer Authentication Enabled\n");
10288
10289 vty_out(vty, "Read thread: %s Write thread: %s\n",
10290 p->t_read ? "on" : "off",
10291 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10292 ? "on"
10293 : "off");
10294 }
10295
10296 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10297 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10298 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10299
10300 if (!use_json)
10301 vty_out(vty, "\n");
10302
10303 /* BFD information. */
10304 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10305
10306 if (use_json) {
10307 if (p->conf_if) /* Configured interface name. */
10308 json_object_object_add(json, p->conf_if, json_neigh);
10309 else /* Configured IP address. */
10310 json_object_object_add(json, p->host, json_neigh);
10311 }
10312 }
10313
10314 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10315 enum show_type type, union sockunion *su,
10316 const char *conf_if, u_char use_json,
10317 json_object *json)
10318 {
10319 struct listnode *node, *nnode;
10320 struct peer *peer;
10321 int find = 0;
10322
10323 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10324 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10325 continue;
10326
10327 switch (type) {
10328 case show_all:
10329 bgp_show_peer(vty, peer, use_json, json);
10330 break;
10331 case show_peer:
10332 if (conf_if) {
10333 if ((peer->conf_if
10334 && !strcmp(peer->conf_if, conf_if))
10335 || (peer->hostname
10336 && !strcmp(peer->hostname, conf_if))) {
10337 find = 1;
10338 bgp_show_peer(vty, peer, use_json,
10339 json);
10340 }
10341 } else {
10342 if (sockunion_same(&peer->su, su)) {
10343 find = 1;
10344 bgp_show_peer(vty, peer, use_json,
10345 json);
10346 }
10347 }
10348 break;
10349 }
10350 }
10351
10352 if (type == show_peer && !find) {
10353 if (use_json)
10354 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10355 else
10356 vty_out(vty, "%% No such neighbor\n");
10357 }
10358
10359 if (use_json) {
10360 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10361 json, JSON_C_TO_STRING_PRETTY));
10362 json_object_free(json);
10363 } else {
10364 vty_out(vty, "\n");
10365 }
10366
10367 return CMD_SUCCESS;
10368 }
10369
10370 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
10371 enum show_type type,
10372 const char *ip_str,
10373 u_char use_json)
10374 {
10375 struct listnode *node, *nnode;
10376 struct bgp *bgp;
10377 union sockunion su;
10378 json_object *json = NULL;
10379 int ret, is_first = 1;
10380
10381 if (use_json)
10382 vty_out(vty, "{\n");
10383
10384 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10385 if (use_json) {
10386 if (!(json = json_object_new_object())) {
10387 zlog_err(
10388 "Unable to allocate memory for JSON object");
10389 vty_out(vty,
10390 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10391 return;
10392 }
10393
10394 json_object_int_add(json, "vrfId",
10395 (bgp->vrf_id == VRF_UNKNOWN)
10396 ? -1
10397 : (int64_t)bgp->vrf_id);
10398 json_object_string_add(
10399 json, "vrfName",
10400 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10401 ? "Default"
10402 : bgp->name);
10403
10404 if (!is_first)
10405 vty_out(vty, ",\n");
10406 else
10407 is_first = 0;
10408
10409 vty_out(vty, "\"%s\":",
10410 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10411 ? "Default"
10412 : bgp->name);
10413 } else {
10414 vty_out(vty, "\nInstance %s:\n",
10415 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10416 ? "Default"
10417 : bgp->name);
10418 }
10419
10420 if (type == show_peer) {
10421 ret = str2sockunion(ip_str, &su);
10422 if (ret < 0)
10423 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10424 use_json, json);
10425 else
10426 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10427 use_json, json);
10428 } else {
10429 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10430 use_json, json);
10431 }
10432 }
10433
10434 if (use_json)
10435 vty_out(vty, "}\n");
10436 }
10437
10438 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10439 enum show_type type, const char *ip_str,
10440 u_char use_json)
10441 {
10442 int ret;
10443 struct bgp *bgp;
10444 union sockunion su;
10445 json_object *json = NULL;
10446
10447 if (name) {
10448 if (strmatch(name, "all")) {
10449 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10450 use_json);
10451 return CMD_SUCCESS;
10452 } else {
10453 bgp = bgp_lookup_by_name(name);
10454 if (!bgp) {
10455 if (use_json) {
10456 json = json_object_new_object();
10457 json_object_boolean_true_add(
10458 json, "bgpNoSuchInstance");
10459 vty_out(vty, "%s\n",
10460 json_object_to_json_string_ext(
10461 json,
10462 JSON_C_TO_STRING_PRETTY));
10463 json_object_free(json);
10464 } else
10465 vty_out(vty,
10466 "%% No such BGP instance exist\n");
10467
10468 return CMD_WARNING;
10469 }
10470 }
10471 } else {
10472 bgp = bgp_get_default();
10473 }
10474
10475 if (bgp) {
10476 json = json_object_new_object();
10477 if (ip_str) {
10478 ret = str2sockunion(ip_str, &su);
10479 if (ret < 0)
10480 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10481 use_json, json);
10482 else
10483 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10484 use_json, json);
10485 } else {
10486 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10487 json);
10488 }
10489 json_object_free(json);
10490 }
10491
10492 return CMD_SUCCESS;
10493 }
10494
10495 /* "show [ip] bgp neighbors" commands. */
10496 DEFUN (show_ip_bgp_neighbors,
10497 show_ip_bgp_neighbors_cmd,
10498 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10499 SHOW_STR
10500 IP_STR
10501 BGP_STR
10502 BGP_INSTANCE_HELP_STR
10503 "Address Family\n"
10504 "Address Family\n"
10505 "Detailed information on TCP and BGP neighbor connections\n"
10506 "Neighbor to display information about\n"
10507 "Neighbor to display information about\n"
10508 "Neighbor on BGP configured interface\n"
10509 JSON_STR)
10510 {
10511 char *vrf = NULL;
10512 char *sh_arg = NULL;
10513 enum show_type sh_type;
10514
10515 u_char uj = use_json(argc, argv);
10516
10517 int idx = 0;
10518
10519 if (argv_find(argv, argc, "view", &idx)
10520 || argv_find(argv, argc, "vrf", &idx))
10521 vrf = argv[idx + 1]->arg;
10522
10523 idx++;
10524 if (argv_find(argv, argc, "A.B.C.D", &idx)
10525 || argv_find(argv, argc, "X:X::X:X", &idx)
10526 || argv_find(argv, argc, "WORD", &idx)) {
10527 sh_type = show_peer;
10528 sh_arg = argv[idx]->arg;
10529 } else
10530 sh_type = show_all;
10531
10532 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10533 }
10534
10535 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10536 paths' and `show ip mbgp paths'. Those functions results are the
10537 same.*/
10538 DEFUN (show_ip_bgp_paths,
10539 show_ip_bgp_paths_cmd,
10540 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10541 SHOW_STR
10542 IP_STR
10543 BGP_STR
10544 BGP_SAFI_HELP_STR
10545 "Path information\n")
10546 {
10547 vty_out(vty, "Address Refcnt Path\n");
10548 aspath_print_all_vty(vty);
10549 return CMD_SUCCESS;
10550 }
10551
10552 #include "hash.h"
10553
10554 static void community_show_all_iterator(struct hash_backet *backet,
10555 struct vty *vty)
10556 {
10557 struct community *com;
10558
10559 com = (struct community *)backet->data;
10560 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10561 community_str(com, false));
10562 }
10563
10564 /* Show BGP's community internal data. */
10565 DEFUN (show_ip_bgp_community_info,
10566 show_ip_bgp_community_info_cmd,
10567 "show [ip] bgp community-info",
10568 SHOW_STR
10569 IP_STR
10570 BGP_STR
10571 "List all bgp community information\n")
10572 {
10573 vty_out(vty, "Address Refcnt Community\n");
10574
10575 hash_iterate(community_hash(),
10576 (void (*)(struct hash_backet *,
10577 void *))community_show_all_iterator,
10578 vty);
10579
10580 return CMD_SUCCESS;
10581 }
10582
10583 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10584 struct vty *vty)
10585 {
10586 struct lcommunity *lcom;
10587
10588 lcom = (struct lcommunity *)backet->data;
10589 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10590 lcommunity_str(lcom));
10591 }
10592
10593 /* Show BGP's community internal data. */
10594 DEFUN (show_ip_bgp_lcommunity_info,
10595 show_ip_bgp_lcommunity_info_cmd,
10596 "show ip bgp large-community-info",
10597 SHOW_STR
10598 IP_STR
10599 BGP_STR
10600 "List all bgp large-community information\n")
10601 {
10602 vty_out(vty, "Address Refcnt Large-community\n");
10603
10604 hash_iterate(lcommunity_hash(),
10605 (void (*)(struct hash_backet *,
10606 void *))lcommunity_show_all_iterator,
10607 vty);
10608
10609 return CMD_SUCCESS;
10610 }
10611
10612
10613 DEFUN (show_ip_bgp_attr_info,
10614 show_ip_bgp_attr_info_cmd,
10615 "show [ip] bgp attribute-info",
10616 SHOW_STR
10617 IP_STR
10618 BGP_STR
10619 "List all bgp attribute information\n")
10620 {
10621 attr_show_all(vty);
10622 return CMD_SUCCESS;
10623 }
10624
10625 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10626 safi_t safi)
10627 {
10628 struct listnode *node, *nnode;
10629 struct bgp *bgp;
10630
10631 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10632 vty_out(vty, "\nInstance %s:\n",
10633 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10634 ? "Default"
10635 : bgp->name);
10636 update_group_show(bgp, afi, safi, vty, 0);
10637 }
10638 }
10639
10640 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10641 int safi, uint64_t subgrp_id)
10642 {
10643 struct bgp *bgp;
10644
10645 if (name) {
10646 if (strmatch(name, "all")) {
10647 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10648 return CMD_SUCCESS;
10649 } else {
10650 bgp = bgp_lookup_by_name(name);
10651 }
10652 } else {
10653 bgp = bgp_get_default();
10654 }
10655
10656 if (bgp)
10657 update_group_show(bgp, afi, safi, vty, subgrp_id);
10658 return CMD_SUCCESS;
10659 }
10660
10661 DEFUN (show_ip_bgp_updgrps,
10662 show_ip_bgp_updgrps_cmd,
10663 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
10664 SHOW_STR
10665 IP_STR
10666 BGP_STR
10667 BGP_INSTANCE_HELP_STR
10668 BGP_AFI_HELP_STR
10669 BGP_SAFI_WITH_LABEL_HELP_STR
10670 "Detailed info about dynamic update groups\n"
10671 "Specific subgroup to display detailed info for\n")
10672 {
10673 char *vrf = NULL;
10674 afi_t afi = AFI_IP6;
10675 safi_t safi = SAFI_UNICAST;
10676 uint64_t subgrp_id = 0;
10677
10678 int idx = 0;
10679
10680 /* show [ip] bgp */
10681 if (argv_find(argv, argc, "ip", &idx))
10682 afi = AFI_IP;
10683 /* [<view|vrf> VIEWVRFNAME] */
10684 if (argv_find(argv, argc, "view", &idx)
10685 || argv_find(argv, argc, "vrf", &idx))
10686 vrf = argv[++idx]->arg;
10687 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10688 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10689 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10690 }
10691
10692 /* get subgroup id, if provided */
10693 idx = argc - 1;
10694 if (argv[idx]->type == VARIABLE_TKN)
10695 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
10696
10697 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
10698 }
10699
10700 DEFUN (show_bgp_instance_all_ipv6_updgrps,
10701 show_bgp_instance_all_ipv6_updgrps_cmd,
10702 "show [ip] bgp <view|vrf> all update-groups",
10703 SHOW_STR
10704 IP_STR
10705 BGP_STR
10706 BGP_INSTANCE_ALL_HELP_STR
10707 "Detailed info about dynamic update groups\n")
10708 {
10709 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10710 return CMD_SUCCESS;
10711 }
10712
10713 DEFUN (show_bgp_updgrps_stats,
10714 show_bgp_updgrps_stats_cmd,
10715 "show [ip] bgp update-groups statistics",
10716 SHOW_STR
10717 IP_STR
10718 BGP_STR
10719 "Detailed info about dynamic update groups\n"
10720 "Statistics\n")
10721 {
10722 struct bgp *bgp;
10723
10724 bgp = bgp_get_default();
10725 if (bgp)
10726 update_group_show_stats(bgp, vty);
10727
10728 return CMD_SUCCESS;
10729 }
10730
10731 DEFUN (show_bgp_instance_updgrps_stats,
10732 show_bgp_instance_updgrps_stats_cmd,
10733 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
10734 SHOW_STR
10735 IP_STR
10736 BGP_STR
10737 BGP_INSTANCE_HELP_STR
10738 "Detailed info about dynamic update groups\n"
10739 "Statistics\n")
10740 {
10741 int idx_word = 3;
10742 struct bgp *bgp;
10743
10744 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10745 if (bgp)
10746 update_group_show_stats(bgp, vty);
10747
10748 return CMD_SUCCESS;
10749 }
10750
10751 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10752 afi_t afi, safi_t safi,
10753 const char *what, uint64_t subgrp_id)
10754 {
10755 struct bgp *bgp;
10756
10757 if (name)
10758 bgp = bgp_lookup_by_name(name);
10759 else
10760 bgp = bgp_get_default();
10761
10762 if (bgp) {
10763 if (!strcmp(what, "advertise-queue"))
10764 update_group_show_adj_queue(bgp, afi, safi, vty,
10765 subgrp_id);
10766 else if (!strcmp(what, "advertised-routes"))
10767 update_group_show_advertised(bgp, afi, safi, vty,
10768 subgrp_id);
10769 else if (!strcmp(what, "packet-queue"))
10770 update_group_show_packet_queue(bgp, afi, safi, vty,
10771 subgrp_id);
10772 }
10773 }
10774
10775 DEFPY(show_ip_bgp_instance_updgrps_adj_s,
10776 show_ip_bgp_instance_updgrps_adj_s_cmd,
10777 "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",
10778 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
10779 BGP_SAFI_HELP_STR
10780 "Detailed info about dynamic update groups\n"
10781 "Specific subgroup to display info for\n"
10782 "Advertisement queue\n"
10783 "Announced routes\n"
10784 "Packet queue\n")
10785 {
10786 uint64_t subgrp_id = 0;
10787 afi_t afiz;
10788 safi_t safiz;
10789 if (sgid)
10790 subgrp_id = strtoull(sgid, NULL, 10);
10791
10792 if (!ip && !afi)
10793 afiz = AFI_IP6;
10794 if (!ip && afi)
10795 afiz = bgp_vty_afi_from_str(afi);
10796 if (ip && !afi)
10797 afiz = AFI_IP;
10798 if (ip && afi) {
10799 afiz = bgp_vty_afi_from_str(afi);
10800 if (afiz != AFI_IP)
10801 vty_out(vty,
10802 "%% Cannot specify both 'ip' and 'ipv6'\n");
10803 return CMD_WARNING;
10804 }
10805
10806 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
10807
10808 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
10809 return CMD_SUCCESS;
10810 }
10811
10812 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10813 {
10814 struct listnode *node, *nnode;
10815 struct prefix *range;
10816 struct peer *conf;
10817 struct peer *peer;
10818 char buf[PREFIX2STR_BUFFER];
10819 afi_t afi;
10820 safi_t safi;
10821 const char *peer_status;
10822 const char *af_str;
10823 int lr_count;
10824 int dynamic;
10825 int af_cfgd;
10826
10827 conf = group->conf;
10828
10829 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10830 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10831 conf->as);
10832 } else if (conf->as_type == AS_INTERNAL) {
10833 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10834 group->bgp->as);
10835 } else {
10836 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10837 }
10838
10839 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10840 vty_out(vty, " Peer-group type is internal\n");
10841 else
10842 vty_out(vty, " Peer-group type is external\n");
10843
10844 /* Display AFs configured. */
10845 vty_out(vty, " Configured address-families:");
10846 FOREACH_AFI_SAFI (afi, safi) {
10847 if (conf->afc[afi][safi]) {
10848 af_cfgd = 1;
10849 vty_out(vty, " %s;", afi_safi_print(afi, safi));
10850 }
10851 }
10852 if (!af_cfgd)
10853 vty_out(vty, " none\n");
10854 else
10855 vty_out(vty, "\n");
10856
10857 /* Display listen ranges (for dynamic neighbors), if any */
10858 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10859 if (afi == AFI_IP)
10860 af_str = "IPv4";
10861 else if (afi == AFI_IP6)
10862 af_str = "IPv6";
10863 else
10864 af_str = "???";
10865 lr_count = listcount(group->listen_range[afi]);
10866 if (lr_count) {
10867 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10868 af_str);
10869
10870
10871 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10872 nnode, range)) {
10873 prefix2str(range, buf, sizeof(buf));
10874 vty_out(vty, " %s\n", buf);
10875 }
10876 }
10877 }
10878
10879 /* Display group members and their status */
10880 if (listcount(group->peer)) {
10881 vty_out(vty, " Peer-group members:\n");
10882 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10883 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10884 peer_status = "Idle (Admin)";
10885 else if (CHECK_FLAG(peer->sflags,
10886 PEER_STATUS_PREFIX_OVERFLOW))
10887 peer_status = "Idle (PfxCt)";
10888 else
10889 peer_status = lookup_msg(bgp_status_msg,
10890 peer->status, NULL);
10891
10892 dynamic = peer_dynamic_neighbor(peer);
10893 vty_out(vty, " %s %s %s \n", peer->host,
10894 dynamic ? "(dynamic)" : "", peer_status);
10895 }
10896 }
10897
10898 return CMD_SUCCESS;
10899 }
10900
10901 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10902 const char *group_name)
10903 {
10904 struct bgp *bgp;
10905 struct listnode *node, *nnode;
10906 struct peer_group *group;
10907 bool found = false;
10908
10909 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
10910
10911 if (!bgp) {
10912 vty_out(vty, "%% No such BGP instance exists\n");
10913 return CMD_WARNING;
10914 }
10915
10916 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
10917 if (group_name) {
10918 if (strmatch(group->name, group_name)) {
10919 bgp_show_one_peer_group(vty, group);
10920 found = true;
10921 break;
10922 }
10923 } else {
10924 bgp_show_one_peer_group(vty, group);
10925 }
10926 }
10927
10928 if (group_name && !found)
10929 vty_out(vty, "%% No such peer-group\n");
10930
10931 return CMD_SUCCESS;
10932 }
10933
10934 DEFUN (show_ip_bgp_peer_groups,
10935 show_ip_bgp_peer_groups_cmd,
10936 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
10937 SHOW_STR
10938 IP_STR
10939 BGP_STR
10940 BGP_INSTANCE_HELP_STR
10941 "Detailed information on BGP peer groups\n"
10942 "Peer group name\n")
10943 {
10944 char *vrf, *pg;
10945 vrf = pg = NULL;
10946 int idx = 0;
10947
10948 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
10949 : NULL;
10950 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
10951
10952 return bgp_show_peer_group_vty(vty, vrf, pg);
10953 }
10954
10955
10956 /* Redistribute VTY commands. */
10957
10958 DEFUN (bgp_redistribute_ipv4,
10959 bgp_redistribute_ipv4_cmd,
10960 "redistribute " FRR_IP_REDIST_STR_BGPD,
10961 "Redistribute information from another routing protocol\n"
10962 FRR_IP_REDIST_HELP_STR_BGPD)
10963 {
10964 VTY_DECLVAR_CONTEXT(bgp, bgp);
10965 int idx_protocol = 1;
10966 int type;
10967
10968 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10969 if (type < 0) {
10970 vty_out(vty, "%% Invalid route type\n");
10971 return CMD_WARNING_CONFIG_FAILED;
10972 }
10973
10974 bgp_redist_add(bgp, AFI_IP, type, 0);
10975 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10976 }
10977
10978 ALIAS_HIDDEN(
10979 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10980 "redistribute " FRR_IP_REDIST_STR_BGPD,
10981 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
10982
10983 DEFUN (bgp_redistribute_ipv4_rmap,
10984 bgp_redistribute_ipv4_rmap_cmd,
10985 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10986 "Redistribute information from another routing protocol\n"
10987 FRR_IP_REDIST_HELP_STR_BGPD
10988 "Route map reference\n"
10989 "Pointer to route-map entries\n")
10990 {
10991 VTY_DECLVAR_CONTEXT(bgp, bgp);
10992 int idx_protocol = 1;
10993 int idx_word = 3;
10994 int type;
10995 struct bgp_redist *red;
10996
10997 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10998 if (type < 0) {
10999 vty_out(vty, "%% Invalid route type\n");
11000 return CMD_WARNING_CONFIG_FAILED;
11001 }
11002
11003 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11004 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11005 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11006 }
11007
11008 ALIAS_HIDDEN(
11009 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11010 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11011 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11012 "Route map reference\n"
11013 "Pointer to route-map entries\n")
11014
11015 DEFUN (bgp_redistribute_ipv4_metric,
11016 bgp_redistribute_ipv4_metric_cmd,
11017 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11018 "Redistribute information from another routing protocol\n"
11019 FRR_IP_REDIST_HELP_STR_BGPD
11020 "Metric for redistributed routes\n"
11021 "Default metric\n")
11022 {
11023 VTY_DECLVAR_CONTEXT(bgp, bgp);
11024 int idx_protocol = 1;
11025 int idx_number = 3;
11026 int type;
11027 u_int32_t metric;
11028 struct bgp_redist *red;
11029
11030 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11031 if (type < 0) {
11032 vty_out(vty, "%% Invalid route type\n");
11033 return CMD_WARNING_CONFIG_FAILED;
11034 }
11035 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11036
11037 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11038 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11039 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11040 }
11041
11042 ALIAS_HIDDEN(
11043 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11044 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11045 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11046 "Metric for redistributed routes\n"
11047 "Default metric\n")
11048
11049 DEFUN (bgp_redistribute_ipv4_rmap_metric,
11050 bgp_redistribute_ipv4_rmap_metric_cmd,
11051 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11052 "Redistribute information from another routing protocol\n"
11053 FRR_IP_REDIST_HELP_STR_BGPD
11054 "Route map reference\n"
11055 "Pointer to route-map entries\n"
11056 "Metric for redistributed routes\n"
11057 "Default metric\n")
11058 {
11059 VTY_DECLVAR_CONTEXT(bgp, bgp);
11060 int idx_protocol = 1;
11061 int idx_word = 3;
11062 int idx_number = 5;
11063 int type;
11064 u_int32_t metric;
11065 struct bgp_redist *red;
11066
11067 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11068 if (type < 0) {
11069 vty_out(vty, "%% Invalid route type\n");
11070 return CMD_WARNING_CONFIG_FAILED;
11071 }
11072 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11073
11074 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11075 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11076 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11077 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11078 }
11079
11080 ALIAS_HIDDEN(
11081 bgp_redistribute_ipv4_rmap_metric,
11082 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11083 "redistribute " FRR_IP_REDIST_STR_BGPD
11084 " route-map WORD metric (0-4294967295)",
11085 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11086 "Route map reference\n"
11087 "Pointer to route-map entries\n"
11088 "Metric for redistributed routes\n"
11089 "Default metric\n")
11090
11091 DEFUN (bgp_redistribute_ipv4_metric_rmap,
11092 bgp_redistribute_ipv4_metric_rmap_cmd,
11093 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11094 "Redistribute information from another routing protocol\n"
11095 FRR_IP_REDIST_HELP_STR_BGPD
11096 "Metric for redistributed routes\n"
11097 "Default metric\n"
11098 "Route map reference\n"
11099 "Pointer to route-map entries\n")
11100 {
11101 VTY_DECLVAR_CONTEXT(bgp, bgp);
11102 int idx_protocol = 1;
11103 int idx_number = 3;
11104 int idx_word = 5;
11105 int type;
11106 u_int32_t metric;
11107 struct bgp_redist *red;
11108
11109 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11110 if (type < 0) {
11111 vty_out(vty, "%% Invalid route type\n");
11112 return CMD_WARNING_CONFIG_FAILED;
11113 }
11114 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11115
11116 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11117 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11118 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11119 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11120 }
11121
11122 ALIAS_HIDDEN(
11123 bgp_redistribute_ipv4_metric_rmap,
11124 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11125 "redistribute " FRR_IP_REDIST_STR_BGPD
11126 " metric (0-4294967295) route-map WORD",
11127 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11128 "Metric for redistributed routes\n"
11129 "Default metric\n"
11130 "Route map reference\n"
11131 "Pointer to route-map entries\n")
11132
11133 DEFUN (bgp_redistribute_ipv4_ospf,
11134 bgp_redistribute_ipv4_ospf_cmd,
11135 "redistribute <ospf|table> (1-65535)",
11136 "Redistribute information from another routing protocol\n"
11137 "Open Shortest Path First (OSPFv2)\n"
11138 "Non-main Kernel Routing Table\n"
11139 "Instance ID/Table ID\n")
11140 {
11141 VTY_DECLVAR_CONTEXT(bgp, bgp);
11142 int idx_ospf_table = 1;
11143 int idx_number = 2;
11144 u_short instance;
11145 u_short protocol;
11146
11147 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11148
11149 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11150 protocol = ZEBRA_ROUTE_OSPF;
11151 else
11152 protocol = ZEBRA_ROUTE_TABLE;
11153
11154 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11155 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11156 }
11157
11158 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11159 "redistribute <ospf|table> (1-65535)",
11160 "Redistribute information from another routing protocol\n"
11161 "Open Shortest Path First (OSPFv2)\n"
11162 "Non-main Kernel Routing Table\n"
11163 "Instance ID/Table ID\n")
11164
11165 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11166 bgp_redistribute_ipv4_ospf_rmap_cmd,
11167 "redistribute <ospf|table> (1-65535) route-map WORD",
11168 "Redistribute information from another routing protocol\n"
11169 "Open Shortest Path First (OSPFv2)\n"
11170 "Non-main Kernel Routing Table\n"
11171 "Instance ID/Table ID\n"
11172 "Route map reference\n"
11173 "Pointer to route-map entries\n")
11174 {
11175 VTY_DECLVAR_CONTEXT(bgp, bgp);
11176 int idx_ospf_table = 1;
11177 int idx_number = 2;
11178 int idx_word = 4;
11179 struct bgp_redist *red;
11180 u_short instance;
11181 int protocol;
11182
11183 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11184 protocol = ZEBRA_ROUTE_OSPF;
11185 else
11186 protocol = ZEBRA_ROUTE_TABLE;
11187
11188 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11189 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11190 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11191 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11192 }
11193
11194 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11195 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11196 "redistribute <ospf|table> (1-65535) route-map WORD",
11197 "Redistribute information from another routing protocol\n"
11198 "Open Shortest Path First (OSPFv2)\n"
11199 "Non-main Kernel Routing Table\n"
11200 "Instance ID/Table ID\n"
11201 "Route map reference\n"
11202 "Pointer to route-map entries\n")
11203
11204 DEFUN (bgp_redistribute_ipv4_ospf_metric,
11205 bgp_redistribute_ipv4_ospf_metric_cmd,
11206 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11207 "Redistribute information from another routing protocol\n"
11208 "Open Shortest Path First (OSPFv2)\n"
11209 "Non-main Kernel Routing Table\n"
11210 "Instance ID/Table ID\n"
11211 "Metric for redistributed routes\n"
11212 "Default metric\n")
11213 {
11214 VTY_DECLVAR_CONTEXT(bgp, bgp);
11215 int idx_ospf_table = 1;
11216 int idx_number = 2;
11217 int idx_number_2 = 4;
11218 u_int32_t metric;
11219 struct bgp_redist *red;
11220 u_short instance;
11221 int protocol;
11222
11223 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11224 protocol = ZEBRA_ROUTE_OSPF;
11225 else
11226 protocol = ZEBRA_ROUTE_TABLE;
11227
11228 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11229 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11230
11231 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11232 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11233 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11234 }
11235
11236 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11237 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11238 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11239 "Redistribute information from another routing protocol\n"
11240 "Open Shortest Path First (OSPFv2)\n"
11241 "Non-main Kernel Routing Table\n"
11242 "Instance ID/Table ID\n"
11243 "Metric for redistributed routes\n"
11244 "Default metric\n")
11245
11246 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11247 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
11248 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11249 "Redistribute information from another routing protocol\n"
11250 "Open Shortest Path First (OSPFv2)\n"
11251 "Non-main Kernel Routing Table\n"
11252 "Instance ID/Table ID\n"
11253 "Route map reference\n"
11254 "Pointer to route-map entries\n"
11255 "Metric for redistributed routes\n"
11256 "Default metric\n")
11257 {
11258 VTY_DECLVAR_CONTEXT(bgp, bgp);
11259 int idx_ospf_table = 1;
11260 int idx_number = 2;
11261 int idx_word = 4;
11262 int idx_number_2 = 6;
11263 u_int32_t metric;
11264 struct bgp_redist *red;
11265 u_short instance;
11266 int protocol;
11267
11268 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11269 protocol = ZEBRA_ROUTE_OSPF;
11270 else
11271 protocol = ZEBRA_ROUTE_TABLE;
11272
11273 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11274 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11275
11276 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11277 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11278 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11279 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11280 }
11281
11282 ALIAS_HIDDEN(
11283 bgp_redistribute_ipv4_ospf_rmap_metric,
11284 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11285 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11286 "Redistribute information from another routing protocol\n"
11287 "Open Shortest Path First (OSPFv2)\n"
11288 "Non-main Kernel Routing Table\n"
11289 "Instance ID/Table ID\n"
11290 "Route map reference\n"
11291 "Pointer to route-map entries\n"
11292 "Metric for redistributed routes\n"
11293 "Default metric\n")
11294
11295 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11296 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
11297 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11298 "Redistribute information from another routing protocol\n"
11299 "Open Shortest Path First (OSPFv2)\n"
11300 "Non-main Kernel Routing Table\n"
11301 "Instance ID/Table ID\n"
11302 "Metric for redistributed routes\n"
11303 "Default metric\n"
11304 "Route map reference\n"
11305 "Pointer to route-map entries\n")
11306 {
11307 VTY_DECLVAR_CONTEXT(bgp, bgp);
11308 int idx_ospf_table = 1;
11309 int idx_number = 2;
11310 int idx_number_2 = 4;
11311 int idx_word = 6;
11312 u_int32_t metric;
11313 struct bgp_redist *red;
11314 u_short instance;
11315 int protocol;
11316
11317 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11318 protocol = ZEBRA_ROUTE_OSPF;
11319 else
11320 protocol = ZEBRA_ROUTE_TABLE;
11321
11322 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11323 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11324
11325 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11326 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11327 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11328 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11329 }
11330
11331 ALIAS_HIDDEN(
11332 bgp_redistribute_ipv4_ospf_metric_rmap,
11333 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11334 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11335 "Redistribute information from another routing protocol\n"
11336 "Open Shortest Path First (OSPFv2)\n"
11337 "Non-main Kernel Routing Table\n"
11338 "Instance ID/Table ID\n"
11339 "Metric for redistributed routes\n"
11340 "Default metric\n"
11341 "Route map reference\n"
11342 "Pointer to route-map entries\n")
11343
11344 DEFUN (no_bgp_redistribute_ipv4_ospf,
11345 no_bgp_redistribute_ipv4_ospf_cmd,
11346 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11347 NO_STR
11348 "Redistribute information from another routing protocol\n"
11349 "Open Shortest Path First (OSPFv2)\n"
11350 "Non-main Kernel Routing Table\n"
11351 "Instance ID/Table ID\n"
11352 "Metric for redistributed routes\n"
11353 "Default metric\n"
11354 "Route map reference\n"
11355 "Pointer to route-map entries\n")
11356 {
11357 VTY_DECLVAR_CONTEXT(bgp, bgp);
11358 int idx_ospf_table = 2;
11359 int idx_number = 3;
11360 u_short instance;
11361 int protocol;
11362
11363 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11364 protocol = ZEBRA_ROUTE_OSPF;
11365 else
11366 protocol = ZEBRA_ROUTE_TABLE;
11367
11368 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11369 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11370 }
11371
11372 ALIAS_HIDDEN(
11373 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11374 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11375 NO_STR
11376 "Redistribute information from another routing protocol\n"
11377 "Open Shortest Path First (OSPFv2)\n"
11378 "Non-main Kernel Routing Table\n"
11379 "Instance ID/Table ID\n"
11380 "Metric for redistributed routes\n"
11381 "Default metric\n"
11382 "Route map reference\n"
11383 "Pointer to route-map entries\n")
11384
11385 DEFUN (no_bgp_redistribute_ipv4,
11386 no_bgp_redistribute_ipv4_cmd,
11387 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11388 NO_STR
11389 "Redistribute information from another routing protocol\n"
11390 FRR_IP_REDIST_HELP_STR_BGPD
11391 "Metric for redistributed routes\n"
11392 "Default metric\n"
11393 "Route map reference\n"
11394 "Pointer to route-map entries\n")
11395 {
11396 VTY_DECLVAR_CONTEXT(bgp, bgp);
11397 int idx_protocol = 2;
11398 int type;
11399
11400 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11401 if (type < 0) {
11402 vty_out(vty, "%% Invalid route type\n");
11403 return CMD_WARNING_CONFIG_FAILED;
11404 }
11405 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11406 }
11407
11408 ALIAS_HIDDEN(
11409 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11410 "no redistribute " FRR_IP_REDIST_STR_BGPD
11411 " [metric (0-4294967295)] [route-map WORD]",
11412 NO_STR
11413 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11414 "Metric for redistributed routes\n"
11415 "Default metric\n"
11416 "Route map reference\n"
11417 "Pointer to route-map entries\n")
11418
11419 DEFUN (bgp_redistribute_ipv6,
11420 bgp_redistribute_ipv6_cmd,
11421 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11422 "Redistribute information from another routing protocol\n"
11423 FRR_IP6_REDIST_HELP_STR_BGPD)
11424 {
11425 VTY_DECLVAR_CONTEXT(bgp, bgp);
11426 int idx_protocol = 1;
11427 int type;
11428
11429 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11430 if (type < 0) {
11431 vty_out(vty, "%% Invalid route type\n");
11432 return CMD_WARNING_CONFIG_FAILED;
11433 }
11434
11435 bgp_redist_add(bgp, AFI_IP6, type, 0);
11436 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11437 }
11438
11439 DEFUN (bgp_redistribute_ipv6_rmap,
11440 bgp_redistribute_ipv6_rmap_cmd,
11441 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11442 "Redistribute information from another routing protocol\n"
11443 FRR_IP6_REDIST_HELP_STR_BGPD
11444 "Route map reference\n"
11445 "Pointer to route-map entries\n")
11446 {
11447 VTY_DECLVAR_CONTEXT(bgp, bgp);
11448 int idx_protocol = 1;
11449 int idx_word = 3;
11450 int type;
11451 struct bgp_redist *red;
11452
11453 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11454 if (type < 0) {
11455 vty_out(vty, "%% Invalid route type\n");
11456 return CMD_WARNING_CONFIG_FAILED;
11457 }
11458
11459 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11460 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11461 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11462 }
11463
11464 DEFUN (bgp_redistribute_ipv6_metric,
11465 bgp_redistribute_ipv6_metric_cmd,
11466 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11467 "Redistribute information from another routing protocol\n"
11468 FRR_IP6_REDIST_HELP_STR_BGPD
11469 "Metric for redistributed routes\n"
11470 "Default metric\n")
11471 {
11472 VTY_DECLVAR_CONTEXT(bgp, bgp);
11473 int idx_protocol = 1;
11474 int idx_number = 3;
11475 int type;
11476 u_int32_t metric;
11477 struct bgp_redist *red;
11478
11479 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11480 if (type < 0) {
11481 vty_out(vty, "%% Invalid route type\n");
11482 return CMD_WARNING_CONFIG_FAILED;
11483 }
11484 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11485
11486 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11487 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11488 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11489 }
11490
11491 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11492 bgp_redistribute_ipv6_rmap_metric_cmd,
11493 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11494 "Redistribute information from another routing protocol\n"
11495 FRR_IP6_REDIST_HELP_STR_BGPD
11496 "Route map reference\n"
11497 "Pointer to route-map entries\n"
11498 "Metric for redistributed routes\n"
11499 "Default metric\n")
11500 {
11501 VTY_DECLVAR_CONTEXT(bgp, bgp);
11502 int idx_protocol = 1;
11503 int idx_word = 3;
11504 int idx_number = 5;
11505 int type;
11506 u_int32_t metric;
11507 struct bgp_redist *red;
11508
11509 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11510 if (type < 0) {
11511 vty_out(vty, "%% Invalid route type\n");
11512 return CMD_WARNING_CONFIG_FAILED;
11513 }
11514 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11515
11516 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11517 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11518 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11519 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11520 }
11521
11522 DEFUN (bgp_redistribute_ipv6_metric_rmap,
11523 bgp_redistribute_ipv6_metric_rmap_cmd,
11524 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11525 "Redistribute information from another routing protocol\n"
11526 FRR_IP6_REDIST_HELP_STR_BGPD
11527 "Metric for redistributed routes\n"
11528 "Default metric\n"
11529 "Route map reference\n"
11530 "Pointer to route-map entries\n")
11531 {
11532 VTY_DECLVAR_CONTEXT(bgp, bgp);
11533 int idx_protocol = 1;
11534 int idx_number = 3;
11535 int idx_word = 5;
11536 int type;
11537 u_int32_t metric;
11538 struct bgp_redist *red;
11539
11540 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11541 if (type < 0) {
11542 vty_out(vty, "%% Invalid route type\n");
11543 return CMD_WARNING_CONFIG_FAILED;
11544 }
11545 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11546
11547 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11548 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11549 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11550 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11551 }
11552
11553 DEFUN (no_bgp_redistribute_ipv6,
11554 no_bgp_redistribute_ipv6_cmd,
11555 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11556 NO_STR
11557 "Redistribute information from another routing protocol\n"
11558 FRR_IP6_REDIST_HELP_STR_BGPD
11559 "Metric for redistributed routes\n"
11560 "Default metric\n"
11561 "Route map reference\n"
11562 "Pointer to route-map entries\n")
11563 {
11564 VTY_DECLVAR_CONTEXT(bgp, bgp);
11565 int idx_protocol = 2;
11566 int type;
11567
11568 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11569 if (type < 0) {
11570 vty_out(vty, "%% Invalid route type\n");
11571 return CMD_WARNING_CONFIG_FAILED;
11572 }
11573
11574 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11575 }
11576
11577 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
11578 safi_t safi)
11579 {
11580 int i;
11581
11582 /* Unicast redistribution only. */
11583 if (safi != SAFI_UNICAST)
11584 return;
11585
11586 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11587 /* Redistribute BGP does not make sense. */
11588 if (i != ZEBRA_ROUTE_BGP) {
11589 struct list *red_list;
11590 struct listnode *node;
11591 struct bgp_redist *red;
11592
11593 red_list = bgp->redist[afi][i];
11594 if (!red_list)
11595 continue;
11596
11597 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
11598 /* "redistribute" configuration. */
11599 vty_out(vty, " redistribute %s",
11600 zebra_route_string(i));
11601 if (red->instance)
11602 vty_out(vty, " %d", red->instance);
11603 if (red->redist_metric_flag)
11604 vty_out(vty, " metric %u",
11605 red->redist_metric);
11606 if (red->rmap.name)
11607 vty_out(vty, " route-map %s",
11608 red->rmap.name);
11609 vty_out(vty, "\n");
11610 }
11611 }
11612 }
11613 }
11614
11615 /* This is part of the address-family block (unicast only) */
11616 void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
11617 afi_t afi)
11618 {
11619 int indent = 2;
11620
11621 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
11622 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
11623 bgp->vpn_policy[afi].tovpn_label);
11624 }
11625 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
11626 BGP_VPN_POLICY_TOVPN_RD_SET)) {
11627 char buf[RD_ADDRSTRLEN];
11628 vty_out(vty, "%*srd vpn export %s\n", indent, "",
11629 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
11630 sizeof(buf)));
11631 }
11632 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
11633 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
11634
11635 char buf[PREFIX_STRLEN];
11636 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
11637 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
11638 sizeof(buf))) {
11639
11640 vty_out(vty, "%*snexthop vpn export %s\n",
11641 indent, "", buf);
11642 }
11643 }
11644 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
11645 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
11646 && ecommunity_cmp(
11647 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
11648 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
11649
11650 char *b = ecommunity_ecom2str(
11651 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
11652 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
11653 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
11654 XFREE(MTYPE_ECOMMUNITY_STR, b);
11655 } else {
11656 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
11657 char *b = ecommunity_ecom2str(
11658 bgp->vpn_policy[afi]
11659 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
11660 ECOMMUNITY_FORMAT_ROUTE_MAP,
11661 ECOMMUNITY_ROUTE_TARGET);
11662 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
11663 XFREE(MTYPE_ECOMMUNITY_STR, b);
11664 }
11665 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
11666 char *b = ecommunity_ecom2str(
11667 bgp->vpn_policy[afi]
11668 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
11669 ECOMMUNITY_FORMAT_ROUTE_MAP,
11670 ECOMMUNITY_ROUTE_TARGET);
11671 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
11672 XFREE(MTYPE_ECOMMUNITY_STR, b);
11673 }
11674 }
11675 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
11676 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
11677 bgp->vpn_policy[afi]
11678 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
11679 }
11680 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN]) {
11681 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
11682 bgp->vpn_policy[afi]
11683 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
11684 }
11685
11686 }
11687
11688
11689 /* BGP node structure. */
11690 static struct cmd_node bgp_node = {
11691 BGP_NODE, "%s(config-router)# ", 1,
11692 };
11693
11694 static struct cmd_node bgp_ipv4_unicast_node = {
11695 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
11696 };
11697
11698 static struct cmd_node bgp_ipv4_multicast_node = {
11699 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
11700 };
11701
11702 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
11703 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
11704 };
11705
11706 static struct cmd_node bgp_ipv6_unicast_node = {
11707 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
11708 };
11709
11710 static struct cmd_node bgp_ipv6_multicast_node = {
11711 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
11712 };
11713
11714 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
11715 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
11716 };
11717
11718 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11719 "%s(config-router-af)# ", 1};
11720
11721 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11722 "%s(config-router-af-vpnv6)# ", 1};
11723
11724 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11725 "%s(config-router-evpn)# ", 1};
11726
11727 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11728 "%s(config-router-af-vni)# ", 1};
11729
11730 static void community_list_vty(void);
11731
11732 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
11733 {
11734 struct bgp *bgp;
11735 struct peer *peer;
11736 struct peer_group *group;
11737 struct listnode *lnbgp, *lnpeer;
11738
11739 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11740 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11741 /* only provide suggestions on the appropriate input
11742 * token type,
11743 * they'll otherwise show up multiple times */
11744 enum cmd_token_type match_type;
11745 char *name = peer->host;
11746
11747 if (peer->conf_if) {
11748 match_type = VARIABLE_TKN;
11749 name = peer->conf_if;
11750 } else if (strchr(peer->host, ':'))
11751 match_type = IPV6_TKN;
11752 else
11753 match_type = IPV4_TKN;
11754
11755 if (token->type != match_type)
11756 continue;
11757
11758 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11759 }
11760
11761 if (token->type == VARIABLE_TKN)
11762 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11763 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11764 group->name));
11765 }
11766 }
11767
11768 static const struct cmd_variable_handler bgp_var_neighbor[] = {
11769 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11770 {.varname = "neighbors", .completions = bgp_ac_neighbor},
11771 {.varname = "peer", .completions = bgp_ac_neighbor},
11772 {.completions = NULL}};
11773
11774 void bgp_vty_init(void)
11775 {
11776 cmd_variable_handler_register(bgp_var_neighbor);
11777
11778 /* Install bgp top node. */
11779 install_node(&bgp_node, bgp_config_write);
11780 install_node(&bgp_ipv4_unicast_node, NULL);
11781 install_node(&bgp_ipv4_multicast_node, NULL);
11782 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11783 install_node(&bgp_ipv6_unicast_node, NULL);
11784 install_node(&bgp_ipv6_multicast_node, NULL);
11785 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11786 install_node(&bgp_vpnv4_node, NULL);
11787 install_node(&bgp_vpnv6_node, NULL);
11788 install_node(&bgp_evpn_node, NULL);
11789 install_node(&bgp_evpn_vni_node, NULL);
11790
11791 /* Install default VTY commands to new nodes. */
11792 install_default(BGP_NODE);
11793 install_default(BGP_IPV4_NODE);
11794 install_default(BGP_IPV4M_NODE);
11795 install_default(BGP_IPV4L_NODE);
11796 install_default(BGP_IPV6_NODE);
11797 install_default(BGP_IPV6M_NODE);
11798 install_default(BGP_IPV6L_NODE);
11799 install_default(BGP_VPNV4_NODE);
11800 install_default(BGP_VPNV6_NODE);
11801 install_default(BGP_EVPN_NODE);
11802 install_default(BGP_EVPN_VNI_NODE);
11803
11804 /* "bgp multiple-instance" commands. */
11805 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11806 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11807
11808 /* "bgp config-type" commands. */
11809 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11810 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11811
11812 /* bgp route-map delay-timer commands. */
11813 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11814 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11815
11816 /* Dummy commands (Currently not supported) */
11817 install_element(BGP_NODE, &no_synchronization_cmd);
11818 install_element(BGP_NODE, &no_auto_summary_cmd);
11819
11820 /* "router bgp" commands. */
11821 install_element(CONFIG_NODE, &router_bgp_cmd);
11822
11823 /* "no router bgp" commands. */
11824 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11825
11826 /* "bgp router-id" commands. */
11827 install_element(BGP_NODE, &bgp_router_id_cmd);
11828 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11829
11830 /* "bgp cluster-id" commands. */
11831 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11832 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11833
11834 /* "bgp confederation" commands. */
11835 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11836 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11837
11838 /* "bgp confederation peers" commands. */
11839 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11840 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11841
11842 /* bgp max-med command */
11843 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11844 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11845 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11846 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11847 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11848
11849 /* bgp disable-ebgp-connected-nh-check */
11850 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11851 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11852
11853 /* bgp update-delay command */
11854 install_element(BGP_NODE, &bgp_update_delay_cmd);
11855 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11856 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11857
11858 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11859 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
11860 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
11861 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
11862
11863 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11864 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11865
11866 /* "maximum-paths" commands. */
11867 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11868 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11869 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11870 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11871 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11872 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11873 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11874 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11875 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11876 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11877 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11878 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11879 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11880 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11881 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11882
11883 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11884 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11885 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11886 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11887 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11888
11889 /* "timers bgp" commands. */
11890 install_element(BGP_NODE, &bgp_timers_cmd);
11891 install_element(BGP_NODE, &no_bgp_timers_cmd);
11892
11893 /* route-map delay-timer commands - per instance for backwards compat.
11894 */
11895 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11896 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11897
11898 /* "bgp client-to-client reflection" commands */
11899 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11900 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11901
11902 /* "bgp always-compare-med" commands */
11903 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11904 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11905
11906 /* "bgp deterministic-med" commands */
11907 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11908 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11909
11910 /* "bgp graceful-restart" commands */
11911 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11912 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11913 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11914 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11915 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11916 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11917
11918 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11919 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11920
11921 /* "bgp graceful-shutdown" commands */
11922 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
11923 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
11924
11925 /* "bgp fast-external-failover" commands */
11926 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11927 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11928
11929 /* "bgp enforce-first-as" commands */
11930 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11931 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11932
11933 /* "bgp bestpath compare-routerid" commands */
11934 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11935 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11936
11937 /* "bgp bestpath as-path ignore" commands */
11938 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11939 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11940
11941 /* "bgp bestpath as-path confed" commands */
11942 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11943 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11944
11945 /* "bgp bestpath as-path multipath-relax" commands */
11946 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11947 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11948
11949 /* "bgp log-neighbor-changes" commands */
11950 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11951 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11952
11953 /* "bgp bestpath med" commands */
11954 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11955 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11956
11957 /* "no bgp default ipv4-unicast" commands. */
11958 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11959 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11960
11961 /* "bgp network import-check" commands. */
11962 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11963 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11964 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11965
11966 /* "bgp default local-preference" commands. */
11967 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11968 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11969
11970 /* bgp default show-hostname */
11971 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11972 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11973
11974 /* "bgp default subgroup-pkt-queue-max" commands. */
11975 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11976 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11977
11978 /* bgp ibgp-allow-policy-mods command */
11979 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11980 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11981
11982 /* "bgp listen limit" commands. */
11983 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11984 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11985
11986 /* "bgp listen range" commands. */
11987 install_element(BGP_NODE, &bgp_listen_range_cmd);
11988 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11989
11990 /* "bgp default shutdown" command */
11991 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
11992
11993 /* "neighbor remote-as" commands. */
11994 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11995 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11996 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11997 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11998 install_element(BGP_NODE,
11999 &neighbor_interface_v6only_config_remote_as_cmd);
12000 install_element(BGP_NODE, &no_neighbor_cmd);
12001 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12002
12003 /* "neighbor peer-group" commands. */
12004 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12005 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12006 install_element(BGP_NODE,
12007 &no_neighbor_interface_peer_group_remote_as_cmd);
12008
12009 /* "neighbor local-as" commands. */
12010 install_element(BGP_NODE, &neighbor_local_as_cmd);
12011 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12012 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12013 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12014
12015 /* "neighbor solo" commands. */
12016 install_element(BGP_NODE, &neighbor_solo_cmd);
12017 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12018
12019 /* "neighbor password" commands. */
12020 install_element(BGP_NODE, &neighbor_password_cmd);
12021 install_element(BGP_NODE, &no_neighbor_password_cmd);
12022
12023 /* "neighbor activate" commands. */
12024 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12025 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12026 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12027 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12028 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12029 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12030 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12031 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12032 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12033 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12034
12035 /* "no neighbor activate" commands. */
12036 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12037 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12038 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12039 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12040 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12041 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12042 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12043 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12044 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12045 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12046
12047 /* "neighbor peer-group" set commands. */
12048 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12049 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12050 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12051 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12052 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12053 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12054 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12055 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12056
12057 /* "no neighbor peer-group unset" commands. */
12058 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12059 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12060 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12061 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12062 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12063 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12064 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12065 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12066
12067 /* "neighbor softreconfiguration inbound" commands.*/
12068 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12069 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12070 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12071 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12072 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12073 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12074 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12075 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12076 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12077 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12078 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12079 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12080 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12081 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12082 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12083 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12084 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12085 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12086
12087 /* "neighbor attribute-unchanged" commands. */
12088 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12089 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12090 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12091 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12092 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12093 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12094 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12095 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12096 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12097 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12098 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12099 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12100 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12101 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12102 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12103 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12104 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12105 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12106
12107 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12108 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12109
12110 /* "nexthop-local unchanged" commands */
12111 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12112 install_element(BGP_IPV6_NODE,
12113 &no_neighbor_nexthop_local_unchanged_cmd);
12114
12115 /* "neighbor next-hop-self" commands. */
12116 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12117 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12118 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12119 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12120 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12121 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12122 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12123 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12124 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12125 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12126 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12127 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12128 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12129 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12130 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12131 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12132 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12133 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12134
12135 /* "neighbor next-hop-self force" commands. */
12136 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12137 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12138 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12139 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12140 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12141 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12142 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12143 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12144 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12145 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12146 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12147 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12148 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12149 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12150 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12151 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12152 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12153 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12154
12155 /* "neighbor as-override" commands. */
12156 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12157 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12158 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12159 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12160 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12161 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12162 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12163 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12164 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12165 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12166 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12167 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12168 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12169 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12170 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12171 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12172 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12173 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12174
12175 /* "neighbor remove-private-AS" commands. */
12176 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12177 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12178 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12179 install_element(BGP_NODE,
12180 &no_neighbor_remove_private_as_all_hidden_cmd);
12181 install_element(BGP_NODE,
12182 &neighbor_remove_private_as_replace_as_hidden_cmd);
12183 install_element(BGP_NODE,
12184 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12185 install_element(BGP_NODE,
12186 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12187 install_element(
12188 BGP_NODE,
12189 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12190 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12191 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12192 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12193 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12194 install_element(BGP_IPV4_NODE,
12195 &neighbor_remove_private_as_replace_as_cmd);
12196 install_element(BGP_IPV4_NODE,
12197 &no_neighbor_remove_private_as_replace_as_cmd);
12198 install_element(BGP_IPV4_NODE,
12199 &neighbor_remove_private_as_all_replace_as_cmd);
12200 install_element(BGP_IPV4_NODE,
12201 &no_neighbor_remove_private_as_all_replace_as_cmd);
12202 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12203 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12204 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12205 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12206 install_element(BGP_IPV4M_NODE,
12207 &neighbor_remove_private_as_replace_as_cmd);
12208 install_element(BGP_IPV4M_NODE,
12209 &no_neighbor_remove_private_as_replace_as_cmd);
12210 install_element(BGP_IPV4M_NODE,
12211 &neighbor_remove_private_as_all_replace_as_cmd);
12212 install_element(BGP_IPV4M_NODE,
12213 &no_neighbor_remove_private_as_all_replace_as_cmd);
12214 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12215 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12216 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12217 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12218 install_element(BGP_IPV4L_NODE,
12219 &neighbor_remove_private_as_replace_as_cmd);
12220 install_element(BGP_IPV4L_NODE,
12221 &no_neighbor_remove_private_as_replace_as_cmd);
12222 install_element(BGP_IPV4L_NODE,
12223 &neighbor_remove_private_as_all_replace_as_cmd);
12224 install_element(BGP_IPV4L_NODE,
12225 &no_neighbor_remove_private_as_all_replace_as_cmd);
12226 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12227 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12228 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12229 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12230 install_element(BGP_IPV6_NODE,
12231 &neighbor_remove_private_as_replace_as_cmd);
12232 install_element(BGP_IPV6_NODE,
12233 &no_neighbor_remove_private_as_replace_as_cmd);
12234 install_element(BGP_IPV6_NODE,
12235 &neighbor_remove_private_as_all_replace_as_cmd);
12236 install_element(BGP_IPV6_NODE,
12237 &no_neighbor_remove_private_as_all_replace_as_cmd);
12238 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12239 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12240 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12241 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12242 install_element(BGP_IPV6M_NODE,
12243 &neighbor_remove_private_as_replace_as_cmd);
12244 install_element(BGP_IPV6M_NODE,
12245 &no_neighbor_remove_private_as_replace_as_cmd);
12246 install_element(BGP_IPV6M_NODE,
12247 &neighbor_remove_private_as_all_replace_as_cmd);
12248 install_element(BGP_IPV6M_NODE,
12249 &no_neighbor_remove_private_as_all_replace_as_cmd);
12250 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12251 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12252 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12253 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12254 install_element(BGP_IPV6L_NODE,
12255 &neighbor_remove_private_as_replace_as_cmd);
12256 install_element(BGP_IPV6L_NODE,
12257 &no_neighbor_remove_private_as_replace_as_cmd);
12258 install_element(BGP_IPV6L_NODE,
12259 &neighbor_remove_private_as_all_replace_as_cmd);
12260 install_element(BGP_IPV6L_NODE,
12261 &no_neighbor_remove_private_as_all_replace_as_cmd);
12262 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12263 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12264 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12265 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12266 install_element(BGP_VPNV4_NODE,
12267 &neighbor_remove_private_as_replace_as_cmd);
12268 install_element(BGP_VPNV4_NODE,
12269 &no_neighbor_remove_private_as_replace_as_cmd);
12270 install_element(BGP_VPNV4_NODE,
12271 &neighbor_remove_private_as_all_replace_as_cmd);
12272 install_element(BGP_VPNV4_NODE,
12273 &no_neighbor_remove_private_as_all_replace_as_cmd);
12274 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12275 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12276 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12277 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12278 install_element(BGP_VPNV6_NODE,
12279 &neighbor_remove_private_as_replace_as_cmd);
12280 install_element(BGP_VPNV6_NODE,
12281 &no_neighbor_remove_private_as_replace_as_cmd);
12282 install_element(BGP_VPNV6_NODE,
12283 &neighbor_remove_private_as_all_replace_as_cmd);
12284 install_element(BGP_VPNV6_NODE,
12285 &no_neighbor_remove_private_as_all_replace_as_cmd);
12286
12287 /* "neighbor send-community" commands.*/
12288 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12289 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12290 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12291 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12292 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12293 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12294 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12295 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12296 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12297 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12298 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12299 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12300 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12301 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12302 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12303 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12304 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12305 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12306 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12307 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12308 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12309 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12310 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12311 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12312 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12313 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12314 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12315 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12316 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12317 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12318 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12319 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12320 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12321 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12322 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12323 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12324
12325 /* "neighbor route-reflector" commands.*/
12326 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12327 install_element(BGP_NODE,
12328 &no_neighbor_route_reflector_client_hidden_cmd);
12329 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12330 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12331 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12332 install_element(BGP_IPV4M_NODE,
12333 &no_neighbor_route_reflector_client_cmd);
12334 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12335 install_element(BGP_IPV4L_NODE,
12336 &no_neighbor_route_reflector_client_cmd);
12337 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12338 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12339 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12340 install_element(BGP_IPV6M_NODE,
12341 &no_neighbor_route_reflector_client_cmd);
12342 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12343 install_element(BGP_IPV6L_NODE,
12344 &no_neighbor_route_reflector_client_cmd);
12345 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12346 install_element(BGP_VPNV4_NODE,
12347 &no_neighbor_route_reflector_client_cmd);
12348 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12349 install_element(BGP_VPNV6_NODE,
12350 &no_neighbor_route_reflector_client_cmd);
12351 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12352 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12353
12354 /* "neighbor route-server" commands.*/
12355 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12356 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12357 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12358 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12359 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12360 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12361 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12362 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12363 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12364 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12365 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12366 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12367 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12368 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12369 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12370 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12371 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12372 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12373
12374 /* "neighbor addpath-tx-all-paths" commands.*/
12375 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12376 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12377 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12378 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12379 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12380 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12381 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12382 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12383 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12384 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12385 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12386 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12387 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12388 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12389 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12390 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12391 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12392 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12393
12394 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12395 install_element(BGP_NODE,
12396 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12397 install_element(BGP_NODE,
12398 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12399 install_element(BGP_IPV4_NODE,
12400 &neighbor_addpath_tx_bestpath_per_as_cmd);
12401 install_element(BGP_IPV4_NODE,
12402 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12403 install_element(BGP_IPV4M_NODE,
12404 &neighbor_addpath_tx_bestpath_per_as_cmd);
12405 install_element(BGP_IPV4M_NODE,
12406 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12407 install_element(BGP_IPV4L_NODE,
12408 &neighbor_addpath_tx_bestpath_per_as_cmd);
12409 install_element(BGP_IPV4L_NODE,
12410 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12411 install_element(BGP_IPV6_NODE,
12412 &neighbor_addpath_tx_bestpath_per_as_cmd);
12413 install_element(BGP_IPV6_NODE,
12414 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12415 install_element(BGP_IPV6M_NODE,
12416 &neighbor_addpath_tx_bestpath_per_as_cmd);
12417 install_element(BGP_IPV6M_NODE,
12418 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12419 install_element(BGP_IPV6L_NODE,
12420 &neighbor_addpath_tx_bestpath_per_as_cmd);
12421 install_element(BGP_IPV6L_NODE,
12422 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12423 install_element(BGP_VPNV4_NODE,
12424 &neighbor_addpath_tx_bestpath_per_as_cmd);
12425 install_element(BGP_VPNV4_NODE,
12426 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12427 install_element(BGP_VPNV6_NODE,
12428 &neighbor_addpath_tx_bestpath_per_as_cmd);
12429 install_element(BGP_VPNV6_NODE,
12430 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12431
12432 /* "neighbor passive" commands. */
12433 install_element(BGP_NODE, &neighbor_passive_cmd);
12434 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12435
12436
12437 /* "neighbor shutdown" commands. */
12438 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12439 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12440 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12441 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12442
12443 /* "neighbor capability extended-nexthop" commands.*/
12444 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12445 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12446
12447 /* "neighbor capability orf prefix-list" commands.*/
12448 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12449 install_element(BGP_NODE,
12450 &no_neighbor_capability_orf_prefix_hidden_cmd);
12451 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12452 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12453 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12454 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12455 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12456 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12457 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12458 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12459 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12460 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12461 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12462 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12463
12464 /* "neighbor capability dynamic" commands.*/
12465 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12466 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12467
12468 /* "neighbor dont-capability-negotiate" commands. */
12469 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12470 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12471
12472 /* "neighbor ebgp-multihop" commands. */
12473 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12474 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12475 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12476
12477 /* "neighbor disable-connected-check" commands. */
12478 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12479 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12480
12481 /* "neighbor description" commands. */
12482 install_element(BGP_NODE, &neighbor_description_cmd);
12483 install_element(BGP_NODE, &no_neighbor_description_cmd);
12484
12485 /* "neighbor update-source" commands. "*/
12486 install_element(BGP_NODE, &neighbor_update_source_cmd);
12487 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12488
12489 /* "neighbor default-originate" commands. */
12490 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12491 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12492 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12493 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12494 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12495 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12496 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12497 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12498 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12499 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12500 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12501 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12502 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12503 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12504 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12505 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12506 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12507 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12508 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12509 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12510 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12511
12512 /* "neighbor port" commands. */
12513 install_element(BGP_NODE, &neighbor_port_cmd);
12514 install_element(BGP_NODE, &no_neighbor_port_cmd);
12515
12516 /* "neighbor weight" commands. */
12517 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12518 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12519
12520 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12521 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12522 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12523 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12524 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12525 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12526 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12527 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12528 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12529 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12530 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12531 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12532 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12533 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12534 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12535 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12536
12537 /* "neighbor override-capability" commands. */
12538 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12539 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12540
12541 /* "neighbor strict-capability-match" commands. */
12542 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12543 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12544
12545 /* "neighbor timers" commands. */
12546 install_element(BGP_NODE, &neighbor_timers_cmd);
12547 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12548
12549 /* "neighbor timers connect" commands. */
12550 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12551 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12552
12553 /* "neighbor advertisement-interval" commands. */
12554 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12555 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12556
12557 /* "neighbor interface" commands. */
12558 install_element(BGP_NODE, &neighbor_interface_cmd);
12559 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12560
12561 /* "neighbor distribute" commands. */
12562 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12563 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12564 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12565 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12566 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12567 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12568 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12569 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12570 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12571 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12572 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12573 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12574 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12575 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12576 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12577 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12578 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12579 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12580
12581 /* "neighbor prefix-list" commands. */
12582 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12583 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12584 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12585 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12586 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12587 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12588 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12589 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12590 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12591 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12592 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12593 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12594 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12595 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12596 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12597 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12598 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12599 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12600
12601 /* "neighbor filter-list" commands. */
12602 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12603 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12604 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12605 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12606 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12607 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12608 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12609 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12610 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12611 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12612 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12613 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12614 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12615 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12616 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12617 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12618 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12619 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12620
12621 /* "neighbor route-map" commands. */
12622 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12623 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12624 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12625 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12626 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12627 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12628 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12629 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12630 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12631 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12632 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12633 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12634 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12635 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12636 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12637 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12638 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12639 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
12640 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12641 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
12642
12643 /* "neighbor unsuppress-map" commands. */
12644 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12645 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12646 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12647 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12648 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12649 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12650 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12651 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12652 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12653 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12654 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12655 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12656 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12657 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12658 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12659 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12660 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12661 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12662
12663 /* "neighbor maximum-prefix" commands. */
12664 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12665 install_element(BGP_NODE,
12666 &neighbor_maximum_prefix_threshold_hidden_cmd);
12667 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12668 install_element(BGP_NODE,
12669 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12670 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12671 install_element(BGP_NODE,
12672 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12673 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12674 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12675 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12676 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12677 install_element(BGP_IPV4_NODE,
12678 &neighbor_maximum_prefix_threshold_warning_cmd);
12679 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12680 install_element(BGP_IPV4_NODE,
12681 &neighbor_maximum_prefix_threshold_restart_cmd);
12682 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12683 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12684 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12685 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12686 install_element(BGP_IPV4M_NODE,
12687 &neighbor_maximum_prefix_threshold_warning_cmd);
12688 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12689 install_element(BGP_IPV4M_NODE,
12690 &neighbor_maximum_prefix_threshold_restart_cmd);
12691 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12692 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12693 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12694 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12695 install_element(BGP_IPV4L_NODE,
12696 &neighbor_maximum_prefix_threshold_warning_cmd);
12697 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12698 install_element(BGP_IPV4L_NODE,
12699 &neighbor_maximum_prefix_threshold_restart_cmd);
12700 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12701 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12702 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12703 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12704 install_element(BGP_IPV6_NODE,
12705 &neighbor_maximum_prefix_threshold_warning_cmd);
12706 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12707 install_element(BGP_IPV6_NODE,
12708 &neighbor_maximum_prefix_threshold_restart_cmd);
12709 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12710 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12711 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12712 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12713 install_element(BGP_IPV6M_NODE,
12714 &neighbor_maximum_prefix_threshold_warning_cmd);
12715 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12716 install_element(BGP_IPV6M_NODE,
12717 &neighbor_maximum_prefix_threshold_restart_cmd);
12718 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12719 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12720 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12721 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12722 install_element(BGP_IPV6L_NODE,
12723 &neighbor_maximum_prefix_threshold_warning_cmd);
12724 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12725 install_element(BGP_IPV6L_NODE,
12726 &neighbor_maximum_prefix_threshold_restart_cmd);
12727 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12728 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12729 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12730 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12731 install_element(BGP_VPNV4_NODE,
12732 &neighbor_maximum_prefix_threshold_warning_cmd);
12733 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12734 install_element(BGP_VPNV4_NODE,
12735 &neighbor_maximum_prefix_threshold_restart_cmd);
12736 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12737 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12738 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12739 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12740 install_element(BGP_VPNV6_NODE,
12741 &neighbor_maximum_prefix_threshold_warning_cmd);
12742 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12743 install_element(BGP_VPNV6_NODE,
12744 &neighbor_maximum_prefix_threshold_restart_cmd);
12745 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12746
12747 /* "neighbor allowas-in" */
12748 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12749 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12750 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12751 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12752 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12753 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12754 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12755 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12756 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12757 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12758 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12759 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12760 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12761 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12762 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12763 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12764 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12765 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12766 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12767 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12768
12769 /* address-family commands. */
12770 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12771 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
12772 #ifdef KEEP_OLD_VPN_COMMANDS
12773 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12774 install_element(BGP_NODE, &address_family_vpnv6_cmd);
12775 #endif /* KEEP_OLD_VPN_COMMANDS */
12776
12777 install_element(BGP_NODE, &address_family_evpn_cmd);
12778
12779 /* "exit-address-family" command. */
12780 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12781 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12782 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12783 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12784 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12785 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12786 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12787 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12788 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12789
12790 /* "clear ip bgp commands" */
12791 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12792
12793 /* clear ip bgp prefix */
12794 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12795 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12796 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12797
12798 /* "show [ip] bgp summary" commands. */
12799 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
12800 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
12801 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
12802 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12803 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
12804 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12805
12806 /* "show [ip] bgp neighbors" commands. */
12807 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12808
12809 /* "show [ip] bgp peer-group" commands. */
12810 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12811
12812 /* "show [ip] bgp paths" commands. */
12813 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12814
12815 /* "show [ip] bgp community" commands. */
12816 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12817
12818 /* "show ip bgp large-community" commands. */
12819 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12820 /* "show [ip] bgp attribute-info" commands. */
12821 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12822
12823 /* "redistribute" commands. */
12824 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12825 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12826 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12827 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12828 install_element(BGP_NODE,
12829 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12830 install_element(BGP_NODE,
12831 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12832 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12833 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12834 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12835 install_element(BGP_NODE,
12836 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12837 install_element(BGP_NODE,
12838 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12839 install_element(BGP_NODE,
12840 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12841 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12842 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12843 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12844 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12845 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12846 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12847 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12848 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12849 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12850 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12851 install_element(BGP_IPV4_NODE,
12852 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12853 install_element(BGP_IPV4_NODE,
12854 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12855 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12856 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12857 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12858 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12859 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12860 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12861
12862 /* import|export vpn [route-map WORD] */
12863 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
12864 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
12865
12866 /* ttl_security commands */
12867 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12868 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12869
12870 /* "show [ip] bgp memory" commands. */
12871 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12872
12873 /* "show bgp martian next-hop" */
12874 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12875
12876 /* "show [ip] bgp views" commands. */
12877 install_element(VIEW_NODE, &show_bgp_views_cmd);
12878
12879 /* "show [ip] bgp vrfs" commands. */
12880 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12881
12882 /* Community-list. */
12883 community_list_vty();
12884
12885 /* vpn-policy commands */
12886 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
12887 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
12888 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
12889 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
12890 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
12891 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
12892 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
12893 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
12894 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
12895 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
12896
12897 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
12898 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
12899 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
12900 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
12901 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
12902 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
12903 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
12904 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
12905 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
12906 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
12907 }
12908
12909 #include "memory.h"
12910 #include "bgp_regex.h"
12911 #include "bgp_clist.h"
12912 #include "bgp_ecommunity.h"
12913
12914 /* VTY functions. */
12915
12916 /* Direction value to string conversion. */
12917 static const char *community_direct_str(int direct)
12918 {
12919 switch (direct) {
12920 case COMMUNITY_DENY:
12921 return "deny";
12922 case COMMUNITY_PERMIT:
12923 return "permit";
12924 default:
12925 return "unknown";
12926 }
12927 }
12928
12929 /* Display error string. */
12930 static void community_list_perror(struct vty *vty, int ret)
12931 {
12932 switch (ret) {
12933 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12934 vty_out(vty, "%% Can't find community-list\n");
12935 break;
12936 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12937 vty_out(vty, "%% Malformed community-list value\n");
12938 break;
12939 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12940 vty_out(vty,
12941 "%% Community name conflict, previously defined as standard community\n");
12942 break;
12943 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12944 vty_out(vty,
12945 "%% Community name conflict, previously defined as expanded community\n");
12946 break;
12947 }
12948 }
12949
12950 /* "community-list" keyword help string. */
12951 #define COMMUNITY_LIST_STR "Add a community list entry\n"
12952
12953 /* ip community-list standard */
12954 DEFUN (ip_community_list_standard,
12955 ip_community_list_standard_cmd,
12956 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
12957 IP_STR
12958 COMMUNITY_LIST_STR
12959 "Community list number (standard)\n"
12960 "Add an standard community-list entry\n"
12961 "Community list name\n"
12962 "Specify community to reject\n"
12963 "Specify community to accept\n"
12964 COMMUNITY_VAL_STR)
12965 {
12966 char *cl_name_or_number = NULL;
12967 int direct = 0;
12968 int style = COMMUNITY_LIST_STANDARD;
12969
12970 int idx = 0;
12971 argv_find(argv, argc, "(1-99)", &idx);
12972 argv_find(argv, argc, "WORD", &idx);
12973 cl_name_or_number = argv[idx]->arg;
12974 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12975 : COMMUNITY_DENY;
12976 argv_find(argv, argc, "AA:NN", &idx);
12977 char *str = argv_concat(argv, argc, idx);
12978
12979 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12980 style);
12981
12982 XFREE(MTYPE_TMP, str);
12983
12984 if (ret < 0) {
12985 /* Display error string. */
12986 community_list_perror(vty, ret);
12987 return CMD_WARNING_CONFIG_FAILED;
12988 }
12989
12990 return CMD_SUCCESS;
12991 }
12992
12993 DEFUN (no_ip_community_list_standard_all,
12994 no_ip_community_list_standard_all_cmd,
12995 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
12996 NO_STR
12997 IP_STR
12998 COMMUNITY_LIST_STR
12999 "Community list number (standard)\n"
13000 "Add an standard community-list entry\n"
13001 "Community list name\n"
13002 "Specify community to reject\n"
13003 "Specify community to accept\n"
13004 COMMUNITY_VAL_STR)
13005 {
13006 int delete_all = 0;
13007
13008 char *cl_name_or_number = NULL;
13009 int direct = 0;
13010 int style = COMMUNITY_LIST_STANDARD;
13011
13012 int idx = 0;
13013 argv_find(argv, argc, "(1-99)", &idx);
13014 argv_find(argv, argc, "WORD", &idx);
13015 cl_name_or_number = argv[idx]->arg;
13016 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13017 : COMMUNITY_DENY;
13018 argv_find(argv, argc, "AA:NN", &idx);
13019 char *str = argv_concat(argv, argc, idx);
13020
13021 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13022 direct, style, delete_all);
13023
13024 XFREE(MTYPE_TMP, str);
13025
13026 if (ret < 0) {
13027 community_list_perror(vty, ret);
13028 return CMD_WARNING_CONFIG_FAILED;
13029 }
13030
13031 return CMD_SUCCESS;
13032 }
13033
13034 /* ip community-list expanded */
13035 DEFUN (ip_community_list_expanded_all,
13036 ip_community_list_expanded_all_cmd,
13037 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13038 IP_STR
13039 COMMUNITY_LIST_STR
13040 "Community list number (expanded)\n"
13041 "Add an expanded community-list entry\n"
13042 "Community list name\n"
13043 "Specify community to reject\n"
13044 "Specify community to accept\n"
13045 COMMUNITY_VAL_STR)
13046 {
13047 char *cl_name_or_number = NULL;
13048 int direct = 0;
13049 int style = COMMUNITY_LIST_EXPANDED;
13050
13051 int idx = 0;
13052 argv_find(argv, argc, "(100-500)", &idx);
13053 argv_find(argv, argc, "WORD", &idx);
13054 cl_name_or_number = argv[idx]->arg;
13055 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13056 : COMMUNITY_DENY;
13057 argv_find(argv, argc, "AA:NN", &idx);
13058 char *str = argv_concat(argv, argc, idx);
13059
13060 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13061 style);
13062
13063 XFREE(MTYPE_TMP, str);
13064
13065 if (ret < 0) {
13066 /* Display error string. */
13067 community_list_perror(vty, ret);
13068 return CMD_WARNING_CONFIG_FAILED;
13069 }
13070
13071 return CMD_SUCCESS;
13072 }
13073
13074 DEFUN (no_ip_community_list_expanded_all,
13075 no_ip_community_list_expanded_all_cmd,
13076 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
13077 NO_STR
13078 IP_STR
13079 COMMUNITY_LIST_STR
13080 "Community list number (expanded)\n"
13081 "Add an expanded community-list entry\n"
13082 "Community list name\n"
13083 "Specify community to reject\n"
13084 "Specify community to accept\n"
13085 COMMUNITY_VAL_STR)
13086 {
13087 int delete_all = 0;
13088
13089 char *cl_name_or_number = NULL;
13090 int direct = 0;
13091 int style = COMMUNITY_LIST_EXPANDED;
13092
13093 int idx = 0;
13094 argv_find(argv, argc, "(100-500)", &idx);
13095 argv_find(argv, argc, "WORD", &idx);
13096 cl_name_or_number = argv[idx]->arg;
13097 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13098 : COMMUNITY_DENY;
13099 argv_find(argv, argc, "AA:NN", &idx);
13100 char *str = argv_concat(argv, argc, idx);
13101
13102 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13103 direct, style, delete_all);
13104
13105 XFREE(MTYPE_TMP, str);
13106
13107 if (ret < 0) {
13108 community_list_perror(vty, ret);
13109 return CMD_WARNING_CONFIG_FAILED;
13110 }
13111
13112 return CMD_SUCCESS;
13113 }
13114
13115 static void community_list_show(struct vty *vty, struct community_list *list)
13116 {
13117 struct community_entry *entry;
13118
13119 for (entry = list->head; entry; entry = entry->next) {
13120 if (entry == list->head) {
13121 if (all_digit(list->name))
13122 vty_out(vty, "Community %s list %s\n",
13123 entry->style == COMMUNITY_LIST_STANDARD
13124 ? "standard"
13125 : "(expanded) access",
13126 list->name);
13127 else
13128 vty_out(vty, "Named Community %s list %s\n",
13129 entry->style == COMMUNITY_LIST_STANDARD
13130 ? "standard"
13131 : "expanded",
13132 list->name);
13133 }
13134 if (entry->any)
13135 vty_out(vty, " %s\n",
13136 community_direct_str(entry->direct));
13137 else
13138 vty_out(vty, " %s %s\n",
13139 community_direct_str(entry->direct),
13140 entry->style == COMMUNITY_LIST_STANDARD
13141 ? community_str(entry->u.com, false)
13142 : entry->config);
13143 }
13144 }
13145
13146 DEFUN (show_ip_community_list,
13147 show_ip_community_list_cmd,
13148 "show ip community-list",
13149 SHOW_STR
13150 IP_STR
13151 "List community-list\n")
13152 {
13153 struct community_list *list;
13154 struct community_list_master *cm;
13155
13156 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13157 if (!cm)
13158 return CMD_SUCCESS;
13159
13160 for (list = cm->num.head; list; list = list->next)
13161 community_list_show(vty, list);
13162
13163 for (list = cm->str.head; list; list = list->next)
13164 community_list_show(vty, list);
13165
13166 return CMD_SUCCESS;
13167 }
13168
13169 DEFUN (show_ip_community_list_arg,
13170 show_ip_community_list_arg_cmd,
13171 "show ip community-list <(1-500)|WORD>",
13172 SHOW_STR
13173 IP_STR
13174 "List community-list\n"
13175 "Community-list number\n"
13176 "Community-list name\n")
13177 {
13178 int idx_comm_list = 3;
13179 struct community_list *list;
13180
13181 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13182 COMMUNITY_LIST_MASTER);
13183 if (!list) {
13184 vty_out(vty, "%% Can't find community-list\n");
13185 return CMD_WARNING;
13186 }
13187
13188 community_list_show(vty, list);
13189
13190 return CMD_SUCCESS;
13191 }
13192
13193 /*
13194 * Large Community code.
13195 */
13196 static int lcommunity_list_set_vty(struct vty *vty, int argc,
13197 struct cmd_token **argv, int style,
13198 int reject_all_digit_name)
13199 {
13200 int ret;
13201 int direct;
13202 char *str;
13203 int idx = 0;
13204 char *cl_name;
13205
13206 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13207 : COMMUNITY_DENY;
13208
13209 /* All digit name check. */
13210 idx = 0;
13211 argv_find(argv, argc, "WORD", &idx);
13212 argv_find(argv, argc, "(1-99)", &idx);
13213 argv_find(argv, argc, "(100-500)", &idx);
13214 cl_name = argv[idx]->arg;
13215 if (reject_all_digit_name && all_digit(cl_name)) {
13216 vty_out(vty, "%% Community name cannot have all digits\n");
13217 return CMD_WARNING_CONFIG_FAILED;
13218 }
13219
13220 idx = 0;
13221 argv_find(argv, argc, "AA:BB:CC", &idx);
13222 argv_find(argv, argc, "LINE", &idx);
13223 /* Concat community string argument. */
13224 if (idx)
13225 str = argv_concat(argv, argc, idx);
13226 else
13227 str = NULL;
13228
13229 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13230
13231 /* Free temporary community list string allocated by
13232 argv_concat(). */
13233 if (str)
13234 XFREE(MTYPE_TMP, str);
13235
13236 if (ret < 0) {
13237 community_list_perror(vty, ret);
13238 return CMD_WARNING_CONFIG_FAILED;
13239 }
13240 return CMD_SUCCESS;
13241 }
13242
13243 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13244 struct cmd_token **argv, int style)
13245 {
13246 int ret;
13247 int direct = 0;
13248 char *str = NULL;
13249 int idx = 0;
13250
13251 argv_find(argv, argc, "permit", &idx);
13252 argv_find(argv, argc, "deny", &idx);
13253
13254 if (idx) {
13255 /* Check the list direct. */
13256 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13257 direct = COMMUNITY_PERMIT;
13258 else
13259 direct = COMMUNITY_DENY;
13260
13261 idx = 0;
13262 argv_find(argv, argc, "LINE", &idx);
13263 argv_find(argv, argc, "AA:AA:NN", &idx);
13264 /* Concat community string argument. */
13265 str = argv_concat(argv, argc, idx);
13266 }
13267
13268 idx = 0;
13269 argv_find(argv, argc, "(1-99)", &idx);
13270 argv_find(argv, argc, "(100-500)", &idx);
13271 argv_find(argv, argc, "WORD", &idx);
13272
13273 /* Unset community list. */
13274 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13275 style);
13276
13277 /* Free temporary community list string allocated by
13278 argv_concat(). */
13279 if (str)
13280 XFREE(MTYPE_TMP, str);
13281
13282 if (ret < 0) {
13283 community_list_perror(vty, ret);
13284 return CMD_WARNING_CONFIG_FAILED;
13285 }
13286
13287 return CMD_SUCCESS;
13288 }
13289
13290 /* "large-community-list" keyword help string. */
13291 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13292 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13293
13294 DEFUN (ip_lcommunity_list_standard,
13295 ip_lcommunity_list_standard_cmd,
13296 "ip large-community-list (1-99) <deny|permit>",
13297 IP_STR
13298 LCOMMUNITY_LIST_STR
13299 "Large Community list number (standard)\n"
13300 "Specify large community to reject\n"
13301 "Specify large community to accept\n")
13302 {
13303 return lcommunity_list_set_vty(vty, argc, argv,
13304 LARGE_COMMUNITY_LIST_STANDARD, 0);
13305 }
13306
13307 DEFUN (ip_lcommunity_list_standard1,
13308 ip_lcommunity_list_standard1_cmd,
13309 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
13310 IP_STR
13311 LCOMMUNITY_LIST_STR
13312 "Large Community list number (standard)\n"
13313 "Specify large community to reject\n"
13314 "Specify large community to accept\n"
13315 LCOMMUNITY_VAL_STR)
13316 {
13317 return lcommunity_list_set_vty(vty, argc, argv,
13318 LARGE_COMMUNITY_LIST_STANDARD, 0);
13319 }
13320
13321 DEFUN (ip_lcommunity_list_expanded,
13322 ip_lcommunity_list_expanded_cmd,
13323 "ip large-community-list (100-500) <deny|permit> LINE...",
13324 IP_STR
13325 LCOMMUNITY_LIST_STR
13326 "Large Community list number (expanded)\n"
13327 "Specify large community to reject\n"
13328 "Specify large community to accept\n"
13329 "An ordered list as a regular-expression\n")
13330 {
13331 return lcommunity_list_set_vty(vty, argc, argv,
13332 LARGE_COMMUNITY_LIST_EXPANDED, 0);
13333 }
13334
13335 DEFUN (ip_lcommunity_list_name_standard,
13336 ip_lcommunity_list_name_standard_cmd,
13337 "ip large-community-list standard WORD <deny|permit>",
13338 IP_STR
13339 LCOMMUNITY_LIST_STR
13340 "Specify standard large-community-list\n"
13341 "Large Community list name\n"
13342 "Specify large community to reject\n"
13343 "Specify large community to accept\n")
13344 {
13345 return lcommunity_list_set_vty(vty, argc, argv,
13346 LARGE_COMMUNITY_LIST_STANDARD, 1);
13347 }
13348
13349 DEFUN (ip_lcommunity_list_name_standard1,
13350 ip_lcommunity_list_name_standard1_cmd,
13351 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
13352 IP_STR
13353 LCOMMUNITY_LIST_STR
13354 "Specify standard large-community-list\n"
13355 "Large Community list name\n"
13356 "Specify large community to reject\n"
13357 "Specify large community to accept\n"
13358 LCOMMUNITY_VAL_STR)
13359 {
13360 return lcommunity_list_set_vty(vty, argc, argv,
13361 LARGE_COMMUNITY_LIST_STANDARD, 1);
13362 }
13363
13364 DEFUN (ip_lcommunity_list_name_expanded,
13365 ip_lcommunity_list_name_expanded_cmd,
13366 "ip large-community-list expanded WORD <deny|permit> LINE...",
13367 IP_STR
13368 LCOMMUNITY_LIST_STR
13369 "Specify expanded large-community-list\n"
13370 "Large Community list name\n"
13371 "Specify large community to reject\n"
13372 "Specify large community to accept\n"
13373 "An ordered list as a regular-expression\n")
13374 {
13375 return lcommunity_list_set_vty(vty, argc, argv,
13376 LARGE_COMMUNITY_LIST_EXPANDED, 1);
13377 }
13378
13379 DEFUN (no_ip_lcommunity_list_standard_all,
13380 no_ip_lcommunity_list_standard_all_cmd,
13381 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13382 NO_STR
13383 IP_STR
13384 LCOMMUNITY_LIST_STR
13385 "Large Community list number (standard)\n"
13386 "Large Community list number (expanded)\n"
13387 "Large Community list name\n")
13388 {
13389 return lcommunity_list_unset_vty(vty, argc, argv,
13390 LARGE_COMMUNITY_LIST_STANDARD);
13391 }
13392
13393 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13394 no_ip_lcommunity_list_name_expanded_all_cmd,
13395 "no ip large-community-list expanded WORD",
13396 NO_STR
13397 IP_STR
13398 LCOMMUNITY_LIST_STR
13399 "Specify expanded large-community-list\n"
13400 "Large Community list name\n")
13401 {
13402 return lcommunity_list_unset_vty(vty, argc, argv,
13403 LARGE_COMMUNITY_LIST_EXPANDED);
13404 }
13405
13406 DEFUN (no_ip_lcommunity_list_standard,
13407 no_ip_lcommunity_list_standard_cmd,
13408 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13409 NO_STR
13410 IP_STR
13411 LCOMMUNITY_LIST_STR
13412 "Large Community list number (standard)\n"
13413 "Specify large community to reject\n"
13414 "Specify large community to accept\n"
13415 LCOMMUNITY_VAL_STR)
13416 {
13417 return lcommunity_list_unset_vty(vty, argc, argv,
13418 LARGE_COMMUNITY_LIST_STANDARD);
13419 }
13420
13421 DEFUN (no_ip_lcommunity_list_expanded,
13422 no_ip_lcommunity_list_expanded_cmd,
13423 "no ip large-community-list (100-500) <deny|permit> LINE...",
13424 NO_STR
13425 IP_STR
13426 LCOMMUNITY_LIST_STR
13427 "Large Community list number (expanded)\n"
13428 "Specify large community to reject\n"
13429 "Specify large community to accept\n"
13430 "An ordered list as a regular-expression\n")
13431 {
13432 return lcommunity_list_unset_vty(vty, argc, argv,
13433 LARGE_COMMUNITY_LIST_EXPANDED);
13434 }
13435
13436 DEFUN (no_ip_lcommunity_list_name_standard,
13437 no_ip_lcommunity_list_name_standard_cmd,
13438 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13439 NO_STR
13440 IP_STR
13441 LCOMMUNITY_LIST_STR
13442 "Specify standard large-community-list\n"
13443 "Large Community list name\n"
13444 "Specify large community to reject\n"
13445 "Specify large community to accept\n"
13446 LCOMMUNITY_VAL_STR)
13447 {
13448 return lcommunity_list_unset_vty(vty, argc, argv,
13449 LARGE_COMMUNITY_LIST_STANDARD);
13450 }
13451
13452 DEFUN (no_ip_lcommunity_list_name_expanded,
13453 no_ip_lcommunity_list_name_expanded_cmd,
13454 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13455 NO_STR
13456 IP_STR
13457 LCOMMUNITY_LIST_STR
13458 "Specify expanded large-community-list\n"
13459 "Large community list name\n"
13460 "Specify large community to reject\n"
13461 "Specify large community to accept\n"
13462 "An ordered list as a regular-expression\n")
13463 {
13464 return lcommunity_list_unset_vty(vty, argc, argv,
13465 LARGE_COMMUNITY_LIST_EXPANDED);
13466 }
13467
13468 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13469 {
13470 struct community_entry *entry;
13471
13472 for (entry = list->head; entry; entry = entry->next) {
13473 if (entry == list->head) {
13474 if (all_digit(list->name))
13475 vty_out(vty, "Large community %s list %s\n",
13476 entry->style == EXTCOMMUNITY_LIST_STANDARD
13477 ? "standard"
13478 : "(expanded) access",
13479 list->name);
13480 else
13481 vty_out(vty,
13482 "Named large community %s list %s\n",
13483 entry->style == EXTCOMMUNITY_LIST_STANDARD
13484 ? "standard"
13485 : "expanded",
13486 list->name);
13487 }
13488 if (entry->any)
13489 vty_out(vty, " %s\n",
13490 community_direct_str(entry->direct));
13491 else
13492 vty_out(vty, " %s %s\n",
13493 community_direct_str(entry->direct),
13494 entry->style == EXTCOMMUNITY_LIST_STANDARD
13495 ? entry->u.ecom->str
13496 : entry->config);
13497 }
13498 }
13499
13500 DEFUN (show_ip_lcommunity_list,
13501 show_ip_lcommunity_list_cmd,
13502 "show ip large-community-list",
13503 SHOW_STR
13504 IP_STR
13505 "List large-community list\n")
13506 {
13507 struct community_list *list;
13508 struct community_list_master *cm;
13509
13510 cm = community_list_master_lookup(bgp_clist,
13511 LARGE_COMMUNITY_LIST_MASTER);
13512 if (!cm)
13513 return CMD_SUCCESS;
13514
13515 for (list = cm->num.head; list; list = list->next)
13516 lcommunity_list_show(vty, list);
13517
13518 for (list = cm->str.head; list; list = list->next)
13519 lcommunity_list_show(vty, list);
13520
13521 return CMD_SUCCESS;
13522 }
13523
13524 DEFUN (show_ip_lcommunity_list_arg,
13525 show_ip_lcommunity_list_arg_cmd,
13526 "show ip large-community-list <(1-500)|WORD>",
13527 SHOW_STR
13528 IP_STR
13529 "List large-community list\n"
13530 "large-community-list number\n"
13531 "large-community-list name\n")
13532 {
13533 struct community_list *list;
13534
13535 list = community_list_lookup(bgp_clist, argv[3]->arg,
13536 LARGE_COMMUNITY_LIST_MASTER);
13537 if (!list) {
13538 vty_out(vty, "%% Can't find extcommunity-list\n");
13539 return CMD_WARNING;
13540 }
13541
13542 lcommunity_list_show(vty, list);
13543
13544 return CMD_SUCCESS;
13545 }
13546
13547 /* "extcommunity-list" keyword help string. */
13548 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13549 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13550
13551 DEFUN (ip_extcommunity_list_standard,
13552 ip_extcommunity_list_standard_cmd,
13553 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13554 IP_STR
13555 EXTCOMMUNITY_LIST_STR
13556 "Extended Community list number (standard)\n"
13557 "Specify standard extcommunity-list\n"
13558 "Community list name\n"
13559 "Specify community to reject\n"
13560 "Specify community to accept\n"
13561 EXTCOMMUNITY_VAL_STR)
13562 {
13563 int style = EXTCOMMUNITY_LIST_STANDARD;
13564 int direct = 0;
13565 char *cl_number_or_name = NULL;
13566
13567 int idx = 0;
13568 argv_find(argv, argc, "(1-99)", &idx);
13569 argv_find(argv, argc, "WORD", &idx);
13570 cl_number_or_name = argv[idx]->arg;
13571 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13572 : COMMUNITY_DENY;
13573 argv_find(argv, argc, "AA:NN", &idx);
13574 char *str = argv_concat(argv, argc, idx);
13575
13576 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13577 direct, style);
13578
13579 XFREE(MTYPE_TMP, str);
13580
13581 if (ret < 0) {
13582 community_list_perror(vty, ret);
13583 return CMD_WARNING_CONFIG_FAILED;
13584 }
13585
13586 return CMD_SUCCESS;
13587 }
13588
13589 DEFUN (ip_extcommunity_list_name_expanded,
13590 ip_extcommunity_list_name_expanded_cmd,
13591 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
13592 IP_STR
13593 EXTCOMMUNITY_LIST_STR
13594 "Extended Community list number (expanded)\n"
13595 "Specify expanded extcommunity-list\n"
13596 "Extended Community list name\n"
13597 "Specify community to reject\n"
13598 "Specify community to accept\n"
13599 "An ordered list as a regular-expression\n")
13600 {
13601 int style = EXTCOMMUNITY_LIST_EXPANDED;
13602 int direct = 0;
13603 char *cl_number_or_name = NULL;
13604
13605 int idx = 0;
13606 argv_find(argv, argc, "(100-500)", &idx);
13607 argv_find(argv, argc, "WORD", &idx);
13608 cl_number_or_name = argv[idx]->arg;
13609 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13610 : COMMUNITY_DENY;
13611 argv_find(argv, argc, "LINE", &idx);
13612 char *str = argv_concat(argv, argc, idx);
13613
13614 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13615 direct, style);
13616
13617 XFREE(MTYPE_TMP, str);
13618
13619 if (ret < 0) {
13620 community_list_perror(vty, ret);
13621 return CMD_WARNING_CONFIG_FAILED;
13622 }
13623
13624 return CMD_SUCCESS;
13625 }
13626
13627 DEFUN (no_ip_extcommunity_list_standard_all,
13628 no_ip_extcommunity_list_standard_all_cmd,
13629 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13630 NO_STR
13631 IP_STR
13632 EXTCOMMUNITY_LIST_STR
13633 "Extended Community list number (standard)\n"
13634 "Specify standard extcommunity-list\n"
13635 "Community list name\n"
13636 "Specify community to reject\n"
13637 "Specify community to accept\n"
13638 EXTCOMMUNITY_VAL_STR)
13639 {
13640 int deleteall = 0;
13641
13642 int style = EXTCOMMUNITY_LIST_STANDARD;
13643 int direct = 0;
13644 char *cl_number_or_name = NULL;
13645
13646 int idx = 0;
13647 argv_find(argv, argc, "(1-99)", &idx);
13648 argv_find(argv, argc, "WORD", &idx);
13649 cl_number_or_name = argv[idx]->arg;
13650 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13651 : COMMUNITY_DENY;
13652 argv_find(argv, argc, "AA:NN", &idx);
13653 char *str = argv_concat(argv, argc, idx);
13654
13655 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13656 direct, style, deleteall);
13657
13658 XFREE(MTYPE_TMP, str);
13659
13660 if (ret < 0) {
13661 community_list_perror(vty, ret);
13662 return CMD_WARNING_CONFIG_FAILED;
13663 }
13664
13665 return CMD_SUCCESS;
13666 }
13667
13668 DEFUN (no_ip_extcommunity_list_expanded_all,
13669 no_ip_extcommunity_list_expanded_all_cmd,
13670 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
13671 NO_STR
13672 IP_STR
13673 EXTCOMMUNITY_LIST_STR
13674 "Extended Community list number (expanded)\n"
13675 "Specify expanded extcommunity-list\n"
13676 "Extended Community list name\n"
13677 "Specify community to reject\n"
13678 "Specify community to accept\n"
13679 "An ordered list as a regular-expression\n")
13680 {
13681 int deleteall = 0;
13682
13683 int style = EXTCOMMUNITY_LIST_EXPANDED;
13684 int direct = 0;
13685 char *cl_number_or_name = NULL;
13686
13687 int idx = 0;
13688 argv_find(argv, argc, "(100-500)", &idx);
13689 argv_find(argv, argc, "WORD", &idx);
13690 cl_number_or_name = argv[idx]->arg;
13691 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13692 : COMMUNITY_DENY;
13693 argv_find(argv, argc, "LINE", &idx);
13694 char *str = argv_concat(argv, argc, idx);
13695
13696 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13697 direct, style, deleteall);
13698
13699 XFREE(MTYPE_TMP, str);
13700
13701 if (ret < 0) {
13702 community_list_perror(vty, ret);
13703 return CMD_WARNING_CONFIG_FAILED;
13704 }
13705
13706 return CMD_SUCCESS;
13707 }
13708
13709 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
13710 {
13711 struct community_entry *entry;
13712
13713 for (entry = list->head; entry; entry = entry->next) {
13714 if (entry == list->head) {
13715 if (all_digit(list->name))
13716 vty_out(vty, "Extended community %s list %s\n",
13717 entry->style == EXTCOMMUNITY_LIST_STANDARD
13718 ? "standard"
13719 : "(expanded) access",
13720 list->name);
13721 else
13722 vty_out(vty,
13723 "Named extended community %s list %s\n",
13724 entry->style == EXTCOMMUNITY_LIST_STANDARD
13725 ? "standard"
13726 : "expanded",
13727 list->name);
13728 }
13729 if (entry->any)
13730 vty_out(vty, " %s\n",
13731 community_direct_str(entry->direct));
13732 else
13733 vty_out(vty, " %s %s\n",
13734 community_direct_str(entry->direct),
13735 entry->style == EXTCOMMUNITY_LIST_STANDARD
13736 ? entry->u.ecom->str
13737 : entry->config);
13738 }
13739 }
13740
13741 DEFUN (show_ip_extcommunity_list,
13742 show_ip_extcommunity_list_cmd,
13743 "show ip extcommunity-list",
13744 SHOW_STR
13745 IP_STR
13746 "List extended-community list\n")
13747 {
13748 struct community_list *list;
13749 struct community_list_master *cm;
13750
13751 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13752 if (!cm)
13753 return CMD_SUCCESS;
13754
13755 for (list = cm->num.head; list; list = list->next)
13756 extcommunity_list_show(vty, list);
13757
13758 for (list = cm->str.head; list; list = list->next)
13759 extcommunity_list_show(vty, list);
13760
13761 return CMD_SUCCESS;
13762 }
13763
13764 DEFUN (show_ip_extcommunity_list_arg,
13765 show_ip_extcommunity_list_arg_cmd,
13766 "show ip extcommunity-list <(1-500)|WORD>",
13767 SHOW_STR
13768 IP_STR
13769 "List extended-community list\n"
13770 "Extcommunity-list number\n"
13771 "Extcommunity-list name\n")
13772 {
13773 int idx_comm_list = 3;
13774 struct community_list *list;
13775
13776 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13777 EXTCOMMUNITY_LIST_MASTER);
13778 if (!list) {
13779 vty_out(vty, "%% Can't find extcommunity-list\n");
13780 return CMD_WARNING;
13781 }
13782
13783 extcommunity_list_show(vty, list);
13784
13785 return CMD_SUCCESS;
13786 }
13787
13788 /* Return configuration string of community-list entry. */
13789 static const char *community_list_config_str(struct community_entry *entry)
13790 {
13791 const char *str;
13792
13793 if (entry->any)
13794 str = "";
13795 else {
13796 if (entry->style == COMMUNITY_LIST_STANDARD)
13797 str = community_str(entry->u.com, false);
13798 else
13799 str = entry->config;
13800 }
13801 return str;
13802 }
13803
13804 /* Display community-list and extcommunity-list configuration. */
13805 static int community_list_config_write(struct vty *vty)
13806 {
13807 struct community_list *list;
13808 struct community_entry *entry;
13809 struct community_list_master *cm;
13810 int write = 0;
13811
13812 /* Community-list. */
13813 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13814
13815 for (list = cm->num.head; list; list = list->next)
13816 for (entry = list->head; entry; entry = entry->next) {
13817 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13818 community_direct_str(entry->direct),
13819 community_list_config_str(entry));
13820 write++;
13821 }
13822 for (list = cm->str.head; list; list = list->next)
13823 for (entry = list->head; entry; entry = entry->next) {
13824 vty_out(vty, "ip community-list %s %s %s %s\n",
13825 entry->style == COMMUNITY_LIST_STANDARD
13826 ? "standard"
13827 : "expanded",
13828 list->name, community_direct_str(entry->direct),
13829 community_list_config_str(entry));
13830 write++;
13831 }
13832
13833 /* Extcommunity-list. */
13834 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13835
13836 for (list = cm->num.head; list; list = list->next)
13837 for (entry = list->head; entry; entry = entry->next) {
13838 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13839 list->name, community_direct_str(entry->direct),
13840 community_list_config_str(entry));
13841 write++;
13842 }
13843 for (list = cm->str.head; list; list = list->next)
13844 for (entry = list->head; entry; entry = entry->next) {
13845 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13846 entry->style == EXTCOMMUNITY_LIST_STANDARD
13847 ? "standard"
13848 : "expanded",
13849 list->name, community_direct_str(entry->direct),
13850 community_list_config_str(entry));
13851 write++;
13852 }
13853
13854
13855 /* lcommunity-list. */
13856 cm = community_list_master_lookup(bgp_clist,
13857 LARGE_COMMUNITY_LIST_MASTER);
13858
13859 for (list = cm->num.head; list; list = list->next)
13860 for (entry = list->head; entry; entry = entry->next) {
13861 vty_out(vty, "ip large-community-list %s %s %s\n",
13862 list->name, community_direct_str(entry->direct),
13863 community_list_config_str(entry));
13864 write++;
13865 }
13866 for (list = cm->str.head; list; list = list->next)
13867 for (entry = list->head; entry; entry = entry->next) {
13868 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13869 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13870 ? "standard"
13871 : "expanded",
13872 list->name, community_direct_str(entry->direct),
13873 community_list_config_str(entry));
13874 write++;
13875 }
13876
13877 return write;
13878 }
13879
13880 static struct cmd_node community_list_node = {
13881 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
13882 };
13883
13884 static void community_list_vty(void)
13885 {
13886 install_node(&community_list_node, community_list_config_write);
13887
13888 /* Community-list. */
13889 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13890 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13891 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13892 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13893 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13894 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13895
13896 /* Extcommunity-list. */
13897 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13898 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13899 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13900 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13901 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13902 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13903
13904 /* Large Community List */
13905 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13906 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13907 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13908 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13909 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13910 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13911 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13912 install_element(CONFIG_NODE,
13913 &no_ip_lcommunity_list_name_expanded_all_cmd);
13914 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13915 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13916 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13917 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13918 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13919 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
13920 }