]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #1654 from mkanjari/evpn-symm-routing-enhancements
[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,
836 "%% Multiple BGP processes are configured\n");
837 return CMD_WARNING_CONFIG_FAILED;
838 }
839 }
840
841 // "router bgp X"
842 else {
843 as = strtoul(argv[idx_asn]->arg, NULL, 10);
844
845 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
846 if (argc > 3) {
847 name = argv[idx_vrf]->arg;
848
849 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
850 inst_type = BGP_INSTANCE_TYPE_VRF;
851 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
852 inst_type = BGP_INSTANCE_TYPE_VIEW;
853 }
854
855 ret = bgp_get(&bgp, &as, name, inst_type);
856 switch (ret) {
857 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
858 vty_out(vty,
859 "Please specify 'bgp multiple-instance' first\n");
860 return CMD_WARNING_CONFIG_FAILED;
861 case BGP_ERR_AS_MISMATCH:
862 vty_out(vty, "BGP is already running; AS is %u\n", as);
863 return CMD_WARNING_CONFIG_FAILED;
864 case BGP_ERR_INSTANCE_MISMATCH:
865 vty_out(vty,
866 "BGP instance name and AS number mismatch\n");
867 vty_out(vty,
868 "BGP instance is already running; AS is %u\n",
869 as);
870 return CMD_WARNING_CONFIG_FAILED;
871 }
872
873 /* Pending: handle when user tries to change a view to vrf n vv.
874 */
875 }
876
877 /* unset the auto created flag as the user config is now present */
878 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
879 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
880
881 return CMD_SUCCESS;
882 }
883
884 /* "no router bgp" commands. */
885 DEFUN (no_router_bgp,
886 no_router_bgp_cmd,
887 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
888 NO_STR
889 ROUTER_STR
890 BGP_STR
891 AS_STR
892 BGP_INSTANCE_HELP_STR)
893 {
894 int idx_asn = 3;
895 int idx_vrf = 5;
896 as_t as;
897 struct bgp *bgp;
898 const char *name = NULL;
899
900 // "no router bgp" without an ASN
901 if (argc == 3) {
902 // Pending: Make VRF option available for ASN less config
903 bgp = bgp_get_default();
904
905 if (bgp == NULL) {
906 vty_out(vty, "%% No BGP process is configured\n");
907 return CMD_WARNING_CONFIG_FAILED;
908 }
909
910 if (listcount(bm->bgp) > 1) {
911 vty_out(vty,
912 "%% Multiple BGP processes are configured\n");
913 return CMD_WARNING_CONFIG_FAILED;
914 }
915
916 if (bgp->l3vni) {
917 vty_out(vty, "%% Please unconfigure l3vni %u",
918 bgp->l3vni);
919 return CMD_WARNING_CONFIG_FAILED;
920 }
921 } else {
922 as = strtoul(argv[idx_asn]->arg, NULL, 10);
923
924 if (argc > 4)
925 name = argv[idx_vrf]->arg;
926
927 /* Lookup bgp structure. */
928 bgp = bgp_lookup(as, name);
929 if (!bgp) {
930 vty_out(vty, "%% Can't find BGP instance\n");
931 return CMD_WARNING_CONFIG_FAILED;
932 }
933
934 if (bgp->l3vni) {
935 vty_out(vty, "%% Please unconfigure l3vni %u",
936 bgp->l3vni);
937 return CMD_WARNING_CONFIG_FAILED;
938 }
939 }
940
941 bgp_delete(bgp);
942
943 return CMD_SUCCESS;
944 }
945
946
947 /* BGP router-id. */
948
949 DEFPY (bgp_router_id,
950 bgp_router_id_cmd,
951 "bgp router-id A.B.C.D",
952 BGP_STR
953 "Override configured router identifier\n"
954 "Manually configured router identifier\n")
955 {
956 VTY_DECLVAR_CONTEXT(bgp, bgp);
957 bgp_router_id_static_set(bgp, router_id);
958 return CMD_SUCCESS;
959 }
960
961 DEFPY (no_bgp_router_id,
962 no_bgp_router_id_cmd,
963 "no bgp router-id [A.B.C.D]",
964 NO_STR
965 BGP_STR
966 "Override configured router identifier\n"
967 "Manually configured router identifier\n")
968 {
969 VTY_DECLVAR_CONTEXT(bgp, bgp);
970
971 if (router_id_str) {
972 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
973 vty_out(vty, "%% BGP router-id doesn't match\n");
974 return CMD_WARNING_CONFIG_FAILED;
975 }
976 }
977
978 router_id.s_addr = 0;
979 bgp_router_id_static_set(bgp, router_id);
980
981 return CMD_SUCCESS;
982 }
983
984
985 /* BGP Cluster ID. */
986 DEFUN (bgp_cluster_id,
987 bgp_cluster_id_cmd,
988 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
989 BGP_STR
990 "Configure Route-Reflector Cluster-id\n"
991 "Route-Reflector Cluster-id in IP address format\n"
992 "Route-Reflector Cluster-id as 32 bit quantity\n")
993 {
994 VTY_DECLVAR_CONTEXT(bgp, bgp);
995 int idx_ipv4 = 2;
996 int ret;
997 struct in_addr cluster;
998
999 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1000 if (!ret) {
1001 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1002 return CMD_WARNING_CONFIG_FAILED;
1003 }
1004
1005 bgp_cluster_id_set(bgp, &cluster);
1006 bgp_clear_star_soft_out(vty, bgp->name);
1007
1008 return CMD_SUCCESS;
1009 }
1010
1011 DEFUN (no_bgp_cluster_id,
1012 no_bgp_cluster_id_cmd,
1013 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
1014 NO_STR
1015 BGP_STR
1016 "Configure Route-Reflector Cluster-id\n"
1017 "Route-Reflector Cluster-id in IP address format\n"
1018 "Route-Reflector Cluster-id as 32 bit quantity\n")
1019 {
1020 VTY_DECLVAR_CONTEXT(bgp, bgp);
1021 bgp_cluster_id_unset(bgp);
1022 bgp_clear_star_soft_out(vty, bgp->name);
1023
1024 return CMD_SUCCESS;
1025 }
1026
1027 DEFUN (bgp_confederation_identifier,
1028 bgp_confederation_identifier_cmd,
1029 "bgp confederation identifier (1-4294967295)",
1030 "BGP specific commands\n"
1031 "AS confederation parameters\n"
1032 "AS number\n"
1033 "Set routing domain confederation AS\n")
1034 {
1035 VTY_DECLVAR_CONTEXT(bgp, bgp);
1036 int idx_number = 3;
1037 as_t as;
1038
1039 as = strtoul(argv[idx_number]->arg, NULL, 10);
1040
1041 bgp_confederation_id_set(bgp, as);
1042
1043 return CMD_SUCCESS;
1044 }
1045
1046 DEFUN (no_bgp_confederation_identifier,
1047 no_bgp_confederation_identifier_cmd,
1048 "no bgp confederation identifier [(1-4294967295)]",
1049 NO_STR
1050 "BGP specific commands\n"
1051 "AS confederation parameters\n"
1052 "AS number\n"
1053 "Set routing domain confederation AS\n")
1054 {
1055 VTY_DECLVAR_CONTEXT(bgp, bgp);
1056 bgp_confederation_id_unset(bgp);
1057
1058 return CMD_SUCCESS;
1059 }
1060
1061 DEFUN (bgp_confederation_peers,
1062 bgp_confederation_peers_cmd,
1063 "bgp confederation peers (1-4294967295)...",
1064 "BGP specific commands\n"
1065 "AS confederation parameters\n"
1066 "Peer ASs in BGP confederation\n"
1067 AS_STR)
1068 {
1069 VTY_DECLVAR_CONTEXT(bgp, bgp);
1070 int idx_asn = 3;
1071 as_t as;
1072 int i;
1073
1074 for (i = idx_asn; i < argc; i++) {
1075 as = strtoul(argv[i]->arg, NULL, 10);
1076
1077 if (bgp->as == as) {
1078 vty_out(vty,
1079 "%% Local member-AS not allowed in confed peer list\n");
1080 continue;
1081 }
1082
1083 bgp_confederation_peers_add(bgp, as);
1084 }
1085 return CMD_SUCCESS;
1086 }
1087
1088 DEFUN (no_bgp_confederation_peers,
1089 no_bgp_confederation_peers_cmd,
1090 "no bgp confederation peers (1-4294967295)...",
1091 NO_STR
1092 "BGP specific commands\n"
1093 "AS confederation parameters\n"
1094 "Peer ASs in BGP confederation\n"
1095 AS_STR)
1096 {
1097 VTY_DECLVAR_CONTEXT(bgp, bgp);
1098 int idx_asn = 4;
1099 as_t as;
1100 int i;
1101
1102 for (i = idx_asn; i < argc; i++) {
1103 as = strtoul(argv[i]->arg, NULL, 10);
1104
1105 bgp_confederation_peers_remove(bgp, as);
1106 }
1107 return CMD_SUCCESS;
1108 }
1109
1110 /**
1111 * Central routine for maximum-paths configuration.
1112 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1113 * @set: 1 for setting values, 0 for removing the max-paths config.
1114 */
1115 static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1116 const char *mpaths, u_int16_t options,
1117 int set)
1118 {
1119 VTY_DECLVAR_CONTEXT(bgp, bgp);
1120 u_int16_t maxpaths = 0;
1121 int ret;
1122 afi_t afi;
1123 safi_t safi;
1124
1125 afi = bgp_node_afi(vty);
1126 safi = bgp_node_safi(vty);
1127
1128 if (set) {
1129 maxpaths = strtol(mpaths, NULL, 10);
1130 if (maxpaths > multipath_num) {
1131 vty_out(vty,
1132 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1133 maxpaths, multipath_num);
1134 return CMD_WARNING_CONFIG_FAILED;
1135 }
1136 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1137 options);
1138 } else
1139 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1140
1141 if (ret < 0) {
1142 vty_out(vty,
1143 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1144 (set == 1) ? "" : "un",
1145 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1146 maxpaths, afi, safi);
1147 return CMD_WARNING_CONFIG_FAILED;
1148 }
1149
1150 bgp_recalculate_all_bestpaths(bgp);
1151
1152 return CMD_SUCCESS;
1153 }
1154
1155 DEFUN (bgp_maxmed_admin,
1156 bgp_maxmed_admin_cmd,
1157 "bgp max-med administrative ",
1158 BGP_STR
1159 "Advertise routes with max-med\n"
1160 "Administratively applied, for an indefinite period\n")
1161 {
1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
1163
1164 bgp->v_maxmed_admin = 1;
1165 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1166
1167 bgp_maxmed_update(bgp);
1168
1169 return CMD_SUCCESS;
1170 }
1171
1172 DEFUN (bgp_maxmed_admin_medv,
1173 bgp_maxmed_admin_medv_cmd,
1174 "bgp max-med administrative (0-4294967295)",
1175 BGP_STR
1176 "Advertise routes with max-med\n"
1177 "Administratively applied, for an indefinite period\n"
1178 "Max MED value to be used\n")
1179 {
1180 VTY_DECLVAR_CONTEXT(bgp, bgp);
1181 int idx_number = 3;
1182
1183 bgp->v_maxmed_admin = 1;
1184 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
1185
1186 bgp_maxmed_update(bgp);
1187
1188 return CMD_SUCCESS;
1189 }
1190
1191 DEFUN (no_bgp_maxmed_admin,
1192 no_bgp_maxmed_admin_cmd,
1193 "no bgp max-med administrative [(0-4294967295)]",
1194 NO_STR
1195 BGP_STR
1196 "Advertise routes with max-med\n"
1197 "Administratively applied, for an indefinite period\n"
1198 "Max MED value to be used\n")
1199 {
1200 VTY_DECLVAR_CONTEXT(bgp, bgp);
1201 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1202 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1203 bgp_maxmed_update(bgp);
1204
1205 return CMD_SUCCESS;
1206 }
1207
1208 DEFUN (bgp_maxmed_onstartup,
1209 bgp_maxmed_onstartup_cmd,
1210 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
1211 BGP_STR
1212 "Advertise routes with max-med\n"
1213 "Effective on a startup\n"
1214 "Time (seconds) period for max-med\n"
1215 "Max MED value to be used\n")
1216 {
1217 VTY_DECLVAR_CONTEXT(bgp, bgp);
1218 int idx = 0;
1219
1220 argv_find(argv, argc, "(5-86400)", &idx);
1221 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1222 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1223 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1224 else
1225 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1226
1227 bgp_maxmed_update(bgp);
1228
1229 return CMD_SUCCESS;
1230 }
1231
1232 DEFUN (no_bgp_maxmed_onstartup,
1233 no_bgp_maxmed_onstartup_cmd,
1234 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
1235 NO_STR
1236 BGP_STR
1237 "Advertise routes with max-med\n"
1238 "Effective on a startup\n"
1239 "Time (seconds) period for max-med\n"
1240 "Max MED value to be used\n")
1241 {
1242 VTY_DECLVAR_CONTEXT(bgp, bgp);
1243
1244 /* Cancel max-med onstartup if its on */
1245 if (bgp->t_maxmed_onstartup) {
1246 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1247 bgp->maxmed_onstartup_over = 1;
1248 }
1249
1250 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1251 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1252
1253 bgp_maxmed_update(bgp);
1254
1255 return CMD_SUCCESS;
1256 }
1257
1258 static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1259 const char *wait)
1260 {
1261 VTY_DECLVAR_CONTEXT(bgp, bgp);
1262 u_int16_t update_delay;
1263 u_int16_t establish_wait;
1264
1265 update_delay = strtoul(delay, NULL, 10);
1266
1267 if (!wait) /* update-delay <delay> */
1268 {
1269 bgp->v_update_delay = update_delay;
1270 bgp->v_establish_wait = bgp->v_update_delay;
1271 return CMD_SUCCESS;
1272 }
1273
1274 /* update-delay <delay> <establish-wait> */
1275 establish_wait = atoi(wait);
1276 if (update_delay < establish_wait) {
1277 vty_out(vty,
1278 "%%Failed: update-delay less than the establish-wait!\n");
1279 return CMD_WARNING_CONFIG_FAILED;
1280 }
1281
1282 bgp->v_update_delay = update_delay;
1283 bgp->v_establish_wait = establish_wait;
1284
1285 return CMD_SUCCESS;
1286 }
1287
1288 static int bgp_update_delay_deconfig_vty(struct vty *vty)
1289 {
1290 VTY_DECLVAR_CONTEXT(bgp, bgp);
1291
1292 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1293 bgp->v_establish_wait = bgp->v_update_delay;
1294
1295 return CMD_SUCCESS;
1296 }
1297
1298 void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
1299 {
1300 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1301 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1302 if (bgp->v_update_delay != bgp->v_establish_wait)
1303 vty_out(vty, " %d", bgp->v_establish_wait);
1304 vty_out(vty, "\n");
1305 }
1306 }
1307
1308
1309 /* Update-delay configuration */
1310 DEFUN (bgp_update_delay,
1311 bgp_update_delay_cmd,
1312 "update-delay (0-3600)",
1313 "Force initial delay for best-path and updates\n"
1314 "Seconds\n")
1315 {
1316 int idx_number = 1;
1317 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
1318 }
1319
1320 DEFUN (bgp_update_delay_establish_wait,
1321 bgp_update_delay_establish_wait_cmd,
1322 "update-delay (0-3600) (1-3600)",
1323 "Force initial delay for best-path and updates\n"
1324 "Seconds\n"
1325 "Seconds\n")
1326 {
1327 int idx_number = 1;
1328 int idx_number_2 = 2;
1329 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1330 argv[idx_number_2]->arg);
1331 }
1332
1333 /* Update-delay deconfiguration */
1334 DEFUN (no_bgp_update_delay,
1335 no_bgp_update_delay_cmd,
1336 "no update-delay [(0-3600) [(1-3600)]]",
1337 NO_STR
1338 "Force initial delay for best-path and updates\n"
1339 "Seconds\n"
1340 "Seconds\n")
1341 {
1342 return bgp_update_delay_deconfig_vty(vty);
1343 }
1344
1345
1346 static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1347 char set)
1348 {
1349 VTY_DECLVAR_CONTEXT(bgp, bgp);
1350
1351 if (set) {
1352 uint32_t quanta = strtoul(num, NULL, 10);
1353 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1354 memory_order_relaxed);
1355 } else {
1356 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1357 memory_order_relaxed);
1358 }
1359
1360 return CMD_SUCCESS;
1361 }
1362
1363 static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1364 char set)
1365 {
1366 VTY_DECLVAR_CONTEXT(bgp, bgp);
1367
1368 if (set) {
1369 uint32_t quanta = strtoul(num, NULL, 10);
1370 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1371 memory_order_relaxed);
1372 } else {
1373 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1374 memory_order_relaxed);
1375 }
1376
1377 return CMD_SUCCESS;
1378 }
1379
1380 void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
1381 {
1382 uint32_t quanta =
1383 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1384 if (quanta != BGP_WRITE_PACKET_MAX)
1385 vty_out(vty, " write-quanta %d\n", quanta);
1386 }
1387
1388 void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1389 {
1390 uint32_t quanta =
1391 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1392 if (quanta != BGP_READ_PACKET_MAX)
1393 vty_out(vty, " read-quanta %d\n", quanta);
1394 }
1395
1396 /* Packet quanta configuration */
1397 DEFUN (bgp_wpkt_quanta,
1398 bgp_wpkt_quanta_cmd,
1399 "write-quanta (1-10)",
1400 "How many packets to write to peer socket per run\n"
1401 "Number of packets\n")
1402 {
1403 int idx_number = 1;
1404 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1405 }
1406
1407 DEFUN (no_bgp_wpkt_quanta,
1408 no_bgp_wpkt_quanta_cmd,
1409 "no write-quanta (1-10)",
1410 NO_STR
1411 "How many packets to write to peer socket per I/O cycle\n"
1412 "Number of packets\n")
1413 {
1414 int idx_number = 2;
1415 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1416 }
1417
1418 DEFUN (bgp_rpkt_quanta,
1419 bgp_rpkt_quanta_cmd,
1420 "read-quanta (1-10)",
1421 "How many packets to read from peer socket per I/O cycle\n"
1422 "Number of packets\n")
1423 {
1424 int idx_number = 1;
1425 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1426 }
1427
1428 DEFUN (no_bgp_rpkt_quanta,
1429 no_bgp_rpkt_quanta_cmd,
1430 "no read-quanta (1-10)",
1431 NO_STR
1432 "How many packets to read from peer socket per I/O cycle\n"
1433 "Number of packets\n")
1434 {
1435 int idx_number = 2;
1436 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1437 }
1438
1439 void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
1440 {
1441 if (!bgp->heuristic_coalesce)
1442 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
1443 }
1444
1445
1446 DEFUN (bgp_coalesce_time,
1447 bgp_coalesce_time_cmd,
1448 "coalesce-time (0-4294967295)",
1449 "Subgroup coalesce timer\n"
1450 "Subgroup coalesce timer value (in ms)\n")
1451 {
1452 VTY_DECLVAR_CONTEXT(bgp, bgp);
1453
1454 int idx = 0;
1455 argv_find(argv, argc, "(0-4294967295)", &idx);
1456 bgp->heuristic_coalesce = false;
1457 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1458 return CMD_SUCCESS;
1459 }
1460
1461 DEFUN (no_bgp_coalesce_time,
1462 no_bgp_coalesce_time_cmd,
1463 "no coalesce-time (0-4294967295)",
1464 NO_STR
1465 "Subgroup coalesce timer\n"
1466 "Subgroup coalesce timer value (in ms)\n")
1467 {
1468 VTY_DECLVAR_CONTEXT(bgp, bgp);
1469
1470 bgp->heuristic_coalesce = true;
1471 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1472 return CMD_SUCCESS;
1473 }
1474
1475 /* Maximum-paths configuration */
1476 DEFUN (bgp_maxpaths,
1477 bgp_maxpaths_cmd,
1478 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1479 "Forward packets over multiple paths\n"
1480 "Number of paths\n")
1481 {
1482 int idx_number = 1;
1483 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1484 argv[idx_number]->arg, 0, 1);
1485 }
1486
1487 ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1488 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1489 "Forward packets over multiple paths\n"
1490 "Number of paths\n")
1491
1492 DEFUN (bgp_maxpaths_ibgp,
1493 bgp_maxpaths_ibgp_cmd,
1494 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1495 "Forward packets over multiple paths\n"
1496 "iBGP-multipath\n"
1497 "Number of paths\n")
1498 {
1499 int idx_number = 2;
1500 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1501 argv[idx_number]->arg, 0, 1);
1502 }
1503
1504 ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1505 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1506 "Forward packets over multiple paths\n"
1507 "iBGP-multipath\n"
1508 "Number of paths\n")
1509
1510 DEFUN (bgp_maxpaths_ibgp_cluster,
1511 bgp_maxpaths_ibgp_cluster_cmd,
1512 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
1513 "Forward packets over multiple paths\n"
1514 "iBGP-multipath\n"
1515 "Number of paths\n"
1516 "Match the cluster length\n")
1517 {
1518 int idx_number = 2;
1519 return bgp_maxpaths_config_vty(
1520 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1521 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
1522 }
1523
1524 ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1525 "maximum-paths ibgp " CMD_RANGE_STR(
1526 1, MULTIPATH_NUM) " equal-cluster-length",
1527 "Forward packets over multiple paths\n"
1528 "iBGP-multipath\n"
1529 "Number of paths\n"
1530 "Match the cluster length\n")
1531
1532 DEFUN (no_bgp_maxpaths,
1533 no_bgp_maxpaths_cmd,
1534 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1535 NO_STR
1536 "Forward packets over multiple paths\n"
1537 "Number of paths\n")
1538 {
1539 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
1540 }
1541
1542 ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
1543 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
1544 "Forward packets over multiple paths\n"
1545 "Number of paths\n")
1546
1547 DEFUN (no_bgp_maxpaths_ibgp,
1548 no_bgp_maxpaths_ibgp_cmd,
1549 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
1550 NO_STR
1551 "Forward packets over multiple paths\n"
1552 "iBGP-multipath\n"
1553 "Number of paths\n"
1554 "Match the cluster length\n")
1555 {
1556 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
1557 }
1558
1559 ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1560 "no maximum-paths ibgp [" CMD_RANGE_STR(
1561 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1562 NO_STR
1563 "Forward packets over multiple paths\n"
1564 "iBGP-multipath\n"
1565 "Number of paths\n"
1566 "Match the cluster length\n")
1567
1568 void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1569 safi_t safi)
1570 {
1571 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1572 vty_out(vty, " maximum-paths %d\n",
1573 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1574 }
1575
1576 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1577 vty_out(vty, " maximum-paths ibgp %d",
1578 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1579 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1580 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1581 vty_out(vty, " equal-cluster-length");
1582 vty_out(vty, "\n");
1583 }
1584 }
1585
1586 /* BGP timers. */
1587
1588 DEFUN (bgp_timers,
1589 bgp_timers_cmd,
1590 "timers bgp (0-65535) (0-65535)",
1591 "Adjust routing timers\n"
1592 "BGP timers\n"
1593 "Keepalive interval\n"
1594 "Holdtime\n")
1595 {
1596 VTY_DECLVAR_CONTEXT(bgp, bgp);
1597 int idx_number = 2;
1598 int idx_number_2 = 3;
1599 unsigned long keepalive = 0;
1600 unsigned long holdtime = 0;
1601
1602 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1603 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
1604
1605 /* Holdtime value check. */
1606 if (holdtime < 3 && holdtime != 0) {
1607 vty_out(vty,
1608 "%% hold time value must be either 0 or greater than 3\n");
1609 return CMD_WARNING_CONFIG_FAILED;
1610 }
1611
1612 bgp_timers_set(bgp, keepalive, holdtime);
1613
1614 return CMD_SUCCESS;
1615 }
1616
1617 DEFUN (no_bgp_timers,
1618 no_bgp_timers_cmd,
1619 "no timers bgp [(0-65535) (0-65535)]",
1620 NO_STR
1621 "Adjust routing timers\n"
1622 "BGP timers\n"
1623 "Keepalive interval\n"
1624 "Holdtime\n")
1625 {
1626 VTY_DECLVAR_CONTEXT(bgp, bgp);
1627 bgp_timers_unset(bgp);
1628
1629 return CMD_SUCCESS;
1630 }
1631
1632
1633 DEFUN (bgp_client_to_client_reflection,
1634 bgp_client_to_client_reflection_cmd,
1635 "bgp client-to-client reflection",
1636 "BGP specific commands\n"
1637 "Configure client to client route reflection\n"
1638 "reflection of routes allowed\n")
1639 {
1640 VTY_DECLVAR_CONTEXT(bgp, bgp);
1641 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1642 bgp_clear_star_soft_out(vty, bgp->name);
1643
1644 return CMD_SUCCESS;
1645 }
1646
1647 DEFUN (no_bgp_client_to_client_reflection,
1648 no_bgp_client_to_client_reflection_cmd,
1649 "no bgp client-to-client reflection",
1650 NO_STR
1651 "BGP specific commands\n"
1652 "Configure client to client route reflection\n"
1653 "reflection of routes allowed\n")
1654 {
1655 VTY_DECLVAR_CONTEXT(bgp, bgp);
1656 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1657 bgp_clear_star_soft_out(vty, bgp->name);
1658
1659 return CMD_SUCCESS;
1660 }
1661
1662 /* "bgp always-compare-med" configuration. */
1663 DEFUN (bgp_always_compare_med,
1664 bgp_always_compare_med_cmd,
1665 "bgp always-compare-med",
1666 "BGP specific commands\n"
1667 "Allow comparing MED from different neighbors\n")
1668 {
1669 VTY_DECLVAR_CONTEXT(bgp, bgp);
1670 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1671 bgp_recalculate_all_bestpaths(bgp);
1672
1673 return CMD_SUCCESS;
1674 }
1675
1676 DEFUN (no_bgp_always_compare_med,
1677 no_bgp_always_compare_med_cmd,
1678 "no bgp always-compare-med",
1679 NO_STR
1680 "BGP specific commands\n"
1681 "Allow comparing MED from different neighbors\n")
1682 {
1683 VTY_DECLVAR_CONTEXT(bgp, bgp);
1684 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1685 bgp_recalculate_all_bestpaths(bgp);
1686
1687 return CMD_SUCCESS;
1688 }
1689
1690 /* "bgp deterministic-med" configuration. */
1691 DEFUN (bgp_deterministic_med,
1692 bgp_deterministic_med_cmd,
1693 "bgp deterministic-med",
1694 "BGP specific commands\n"
1695 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1696 {
1697 VTY_DECLVAR_CONTEXT(bgp, bgp);
1698
1699 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1700 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1701 bgp_recalculate_all_bestpaths(bgp);
1702 }
1703
1704 return CMD_SUCCESS;
1705 }
1706
1707 DEFUN (no_bgp_deterministic_med,
1708 no_bgp_deterministic_med_cmd,
1709 "no bgp deterministic-med",
1710 NO_STR
1711 "BGP specific commands\n"
1712 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1713 {
1714 VTY_DECLVAR_CONTEXT(bgp, bgp);
1715 int bestpath_per_as_used;
1716 afi_t afi;
1717 safi_t safi;
1718 struct peer *peer;
1719 struct listnode *node, *nnode;
1720
1721 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1722 bestpath_per_as_used = 0;
1723
1724 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1725 FOREACH_AFI_SAFI (afi, safi)
1726 if (CHECK_FLAG(
1727 peer->af_flags[afi][safi],
1728 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1729 bestpath_per_as_used = 1;
1730 break;
1731 }
1732
1733 if (bestpath_per_as_used)
1734 break;
1735 }
1736
1737 if (bestpath_per_as_used) {
1738 vty_out(vty,
1739 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1740 return CMD_WARNING_CONFIG_FAILED;
1741 } else {
1742 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1743 bgp_recalculate_all_bestpaths(bgp);
1744 }
1745 }
1746
1747 return CMD_SUCCESS;
1748 }
1749
1750 /* "bgp graceful-restart" configuration. */
1751 DEFUN (bgp_graceful_restart,
1752 bgp_graceful_restart_cmd,
1753 "bgp graceful-restart",
1754 "BGP specific commands\n"
1755 "Graceful restart capability parameters\n")
1756 {
1757 VTY_DECLVAR_CONTEXT(bgp, bgp);
1758 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1759 return CMD_SUCCESS;
1760 }
1761
1762 DEFUN (no_bgp_graceful_restart,
1763 no_bgp_graceful_restart_cmd,
1764 "no bgp graceful-restart",
1765 NO_STR
1766 "BGP specific commands\n"
1767 "Graceful restart capability parameters\n")
1768 {
1769 VTY_DECLVAR_CONTEXT(bgp, bgp);
1770 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1771 return CMD_SUCCESS;
1772 }
1773
1774 DEFUN (bgp_graceful_restart_stalepath_time,
1775 bgp_graceful_restart_stalepath_time_cmd,
1776 "bgp graceful-restart stalepath-time (1-3600)",
1777 "BGP specific commands\n"
1778 "Graceful restart capability parameters\n"
1779 "Set the max time to hold onto restarting peer's stale paths\n"
1780 "Delay value (seconds)\n")
1781 {
1782 VTY_DECLVAR_CONTEXT(bgp, bgp);
1783 int idx_number = 3;
1784 u_int32_t stalepath;
1785
1786 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1787 bgp->stalepath_time = stalepath;
1788 return CMD_SUCCESS;
1789 }
1790
1791 DEFUN (bgp_graceful_restart_restart_time,
1792 bgp_graceful_restart_restart_time_cmd,
1793 "bgp graceful-restart restart-time (1-3600)",
1794 "BGP specific commands\n"
1795 "Graceful restart capability parameters\n"
1796 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1797 "Delay value (seconds)\n")
1798 {
1799 VTY_DECLVAR_CONTEXT(bgp, bgp);
1800 int idx_number = 3;
1801 u_int32_t restart;
1802
1803 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1804 bgp->restart_time = restart;
1805 return CMD_SUCCESS;
1806 }
1807
1808 DEFUN (no_bgp_graceful_restart_stalepath_time,
1809 no_bgp_graceful_restart_stalepath_time_cmd,
1810 "no bgp graceful-restart stalepath-time [(1-3600)]",
1811 NO_STR
1812 "BGP specific commands\n"
1813 "Graceful restart capability parameters\n"
1814 "Set the max time to hold onto restarting peer's stale paths\n"
1815 "Delay value (seconds)\n")
1816 {
1817 VTY_DECLVAR_CONTEXT(bgp, bgp);
1818
1819 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1820 return CMD_SUCCESS;
1821 }
1822
1823 DEFUN (no_bgp_graceful_restart_restart_time,
1824 no_bgp_graceful_restart_restart_time_cmd,
1825 "no bgp graceful-restart restart-time [(1-3600)]",
1826 NO_STR
1827 "BGP specific commands\n"
1828 "Graceful restart capability parameters\n"
1829 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1830 "Delay value (seconds)\n")
1831 {
1832 VTY_DECLVAR_CONTEXT(bgp, bgp);
1833
1834 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1835 return CMD_SUCCESS;
1836 }
1837
1838 DEFUN (bgp_graceful_restart_preserve_fw,
1839 bgp_graceful_restart_preserve_fw_cmd,
1840 "bgp graceful-restart preserve-fw-state",
1841 "BGP specific commands\n"
1842 "Graceful restart capability parameters\n"
1843 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1844 {
1845 VTY_DECLVAR_CONTEXT(bgp, bgp);
1846 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1847 return CMD_SUCCESS;
1848 }
1849
1850 DEFUN (no_bgp_graceful_restart_preserve_fw,
1851 no_bgp_graceful_restart_preserve_fw_cmd,
1852 "no bgp graceful-restart preserve-fw-state",
1853 NO_STR
1854 "BGP specific commands\n"
1855 "Graceful restart capability parameters\n"
1856 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1857 {
1858 VTY_DECLVAR_CONTEXT(bgp, bgp);
1859 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1860 return CMD_SUCCESS;
1861 }
1862
1863 static void bgp_redistribute_redo(struct bgp *bgp)
1864 {
1865 afi_t afi;
1866 int i;
1867 struct list *red_list;
1868 struct listnode *node;
1869 struct bgp_redist *red;
1870
1871 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1872 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1873
1874 red_list = bgp->redist[afi][i];
1875 if (!red_list)
1876 continue;
1877
1878 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1879 bgp_redistribute_resend(bgp, afi, i,
1880 red->instance);
1881 }
1882 }
1883 }
1884 }
1885
1886 /* "bgp graceful-shutdown" configuration */
1887 DEFUN (bgp_graceful_shutdown,
1888 bgp_graceful_shutdown_cmd,
1889 "bgp graceful-shutdown",
1890 BGP_STR
1891 "Graceful shutdown parameters\n")
1892 {
1893 VTY_DECLVAR_CONTEXT(bgp, bgp);
1894
1895 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1896 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1897 bgp_static_redo_import_check(bgp);
1898 bgp_redistribute_redo(bgp);
1899 bgp_clear_star_soft_out(vty, bgp->name);
1900 bgp_clear_star_soft_in(vty, bgp->name);
1901 }
1902
1903 return CMD_SUCCESS;
1904 }
1905
1906 DEFUN (no_bgp_graceful_shutdown,
1907 no_bgp_graceful_shutdown_cmd,
1908 "no bgp graceful-shutdown",
1909 NO_STR
1910 BGP_STR
1911 "Graceful shutdown parameters\n")
1912 {
1913 VTY_DECLVAR_CONTEXT(bgp, bgp);
1914
1915 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1916 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1917 bgp_static_redo_import_check(bgp);
1918 bgp_redistribute_redo(bgp);
1919 bgp_clear_star_soft_out(vty, bgp->name);
1920 bgp_clear_star_soft_in(vty, bgp->name);
1921 }
1922
1923 return CMD_SUCCESS;
1924 }
1925
1926 /* "bgp fast-external-failover" configuration. */
1927 DEFUN (bgp_fast_external_failover,
1928 bgp_fast_external_failover_cmd,
1929 "bgp fast-external-failover",
1930 BGP_STR
1931 "Immediately reset session if a link to a directly connected external peer goes down\n")
1932 {
1933 VTY_DECLVAR_CONTEXT(bgp, bgp);
1934 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1935 return CMD_SUCCESS;
1936 }
1937
1938 DEFUN (no_bgp_fast_external_failover,
1939 no_bgp_fast_external_failover_cmd,
1940 "no bgp fast-external-failover",
1941 NO_STR
1942 BGP_STR
1943 "Immediately reset session if a link to a directly connected external peer goes down\n")
1944 {
1945 VTY_DECLVAR_CONTEXT(bgp, bgp);
1946 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1947 return CMD_SUCCESS;
1948 }
1949
1950 /* "bgp enforce-first-as" configuration. */
1951 DEFUN (bgp_enforce_first_as,
1952 bgp_enforce_first_as_cmd,
1953 "bgp enforce-first-as",
1954 BGP_STR
1955 "Enforce the first AS for EBGP routes\n")
1956 {
1957 VTY_DECLVAR_CONTEXT(bgp, bgp);
1958 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1959 bgp_clear_star_soft_in(vty, bgp->name);
1960
1961 return CMD_SUCCESS;
1962 }
1963
1964 DEFUN (no_bgp_enforce_first_as,
1965 no_bgp_enforce_first_as_cmd,
1966 "no bgp enforce-first-as",
1967 NO_STR
1968 BGP_STR
1969 "Enforce the first AS for EBGP routes\n")
1970 {
1971 VTY_DECLVAR_CONTEXT(bgp, bgp);
1972 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1973 bgp_clear_star_soft_in(vty, bgp->name);
1974
1975 return CMD_SUCCESS;
1976 }
1977
1978 /* "bgp bestpath compare-routerid" configuration. */
1979 DEFUN (bgp_bestpath_compare_router_id,
1980 bgp_bestpath_compare_router_id_cmd,
1981 "bgp bestpath compare-routerid",
1982 "BGP specific commands\n"
1983 "Change the default bestpath selection\n"
1984 "Compare router-id for identical EBGP paths\n")
1985 {
1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
1987 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1988 bgp_recalculate_all_bestpaths(bgp);
1989
1990 return CMD_SUCCESS;
1991 }
1992
1993 DEFUN (no_bgp_bestpath_compare_router_id,
1994 no_bgp_bestpath_compare_router_id_cmd,
1995 "no bgp bestpath compare-routerid",
1996 NO_STR
1997 "BGP specific commands\n"
1998 "Change the default bestpath selection\n"
1999 "Compare router-id for identical EBGP paths\n")
2000 {
2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2003 bgp_recalculate_all_bestpaths(bgp);
2004
2005 return CMD_SUCCESS;
2006 }
2007
2008 /* "bgp bestpath as-path ignore" configuration. */
2009 DEFUN (bgp_bestpath_aspath_ignore,
2010 bgp_bestpath_aspath_ignore_cmd,
2011 "bgp bestpath as-path ignore",
2012 "BGP specific commands\n"
2013 "Change the default bestpath selection\n"
2014 "AS-path attribute\n"
2015 "Ignore as-path length in selecting a route\n")
2016 {
2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2019 bgp_recalculate_all_bestpaths(bgp);
2020
2021 return CMD_SUCCESS;
2022 }
2023
2024 DEFUN (no_bgp_bestpath_aspath_ignore,
2025 no_bgp_bestpath_aspath_ignore_cmd,
2026 "no bgp bestpath as-path ignore",
2027 NO_STR
2028 "BGP specific commands\n"
2029 "Change the default bestpath selection\n"
2030 "AS-path attribute\n"
2031 "Ignore as-path length in selecting a route\n")
2032 {
2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
2034 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2035 bgp_recalculate_all_bestpaths(bgp);
2036
2037 return CMD_SUCCESS;
2038 }
2039
2040 /* "bgp bestpath as-path confed" configuration. */
2041 DEFUN (bgp_bestpath_aspath_confed,
2042 bgp_bestpath_aspath_confed_cmd,
2043 "bgp bestpath as-path confed",
2044 "BGP specific commands\n"
2045 "Change the default bestpath selection\n"
2046 "AS-path attribute\n"
2047 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2048 {
2049 VTY_DECLVAR_CONTEXT(bgp, bgp);
2050 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2051 bgp_recalculate_all_bestpaths(bgp);
2052
2053 return CMD_SUCCESS;
2054 }
2055
2056 DEFUN (no_bgp_bestpath_aspath_confed,
2057 no_bgp_bestpath_aspath_confed_cmd,
2058 "no bgp bestpath as-path confed",
2059 NO_STR
2060 "BGP specific commands\n"
2061 "Change the default bestpath selection\n"
2062 "AS-path attribute\n"
2063 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2064 {
2065 VTY_DECLVAR_CONTEXT(bgp, bgp);
2066 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2067 bgp_recalculate_all_bestpaths(bgp);
2068
2069 return CMD_SUCCESS;
2070 }
2071
2072 /* "bgp bestpath as-path multipath-relax" configuration. */
2073 DEFUN (bgp_bestpath_aspath_multipath_relax,
2074 bgp_bestpath_aspath_multipath_relax_cmd,
2075 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2076 "BGP specific commands\n"
2077 "Change the default bestpath selection\n"
2078 "AS-path attribute\n"
2079 "Allow load sharing across routes that have different AS paths (but same length)\n"
2080 "Generate an AS_SET\n"
2081 "Do not generate an AS_SET\n")
2082 {
2083 VTY_DECLVAR_CONTEXT(bgp, bgp);
2084 int idx = 0;
2085 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2086
2087 /* no-as-set is now the default behavior so we can silently
2088 * ignore it */
2089 if (argv_find(argv, argc, "as-set", &idx))
2090 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2091 else
2092 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2093
2094 bgp_recalculate_all_bestpaths(bgp);
2095
2096 return CMD_SUCCESS;
2097 }
2098
2099 DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2100 no_bgp_bestpath_aspath_multipath_relax_cmd,
2101 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
2102 NO_STR
2103 "BGP specific commands\n"
2104 "Change the default bestpath selection\n"
2105 "AS-path attribute\n"
2106 "Allow load sharing across routes that have different AS paths (but same length)\n"
2107 "Generate an AS_SET\n"
2108 "Do not generate an AS_SET\n")
2109 {
2110 VTY_DECLVAR_CONTEXT(bgp, bgp);
2111 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2112 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2113 bgp_recalculate_all_bestpaths(bgp);
2114
2115 return CMD_SUCCESS;
2116 }
2117
2118 /* "bgp log-neighbor-changes" configuration. */
2119 DEFUN (bgp_log_neighbor_changes,
2120 bgp_log_neighbor_changes_cmd,
2121 "bgp log-neighbor-changes",
2122 "BGP specific commands\n"
2123 "Log neighbor up/down and reset reason\n")
2124 {
2125 VTY_DECLVAR_CONTEXT(bgp, bgp);
2126 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2127 return CMD_SUCCESS;
2128 }
2129
2130 DEFUN (no_bgp_log_neighbor_changes,
2131 no_bgp_log_neighbor_changes_cmd,
2132 "no bgp log-neighbor-changes",
2133 NO_STR
2134 "BGP specific commands\n"
2135 "Log neighbor up/down and reset reason\n")
2136 {
2137 VTY_DECLVAR_CONTEXT(bgp, bgp);
2138 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2139 return CMD_SUCCESS;
2140 }
2141
2142 /* "bgp bestpath med" configuration. */
2143 DEFUN (bgp_bestpath_med,
2144 bgp_bestpath_med_cmd,
2145 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2146 "BGP specific commands\n"
2147 "Change the default bestpath selection\n"
2148 "MED attribute\n"
2149 "Compare MED among confederation paths\n"
2150 "Treat missing MED as the least preferred one\n"
2151 "Treat missing MED as the least preferred one\n"
2152 "Compare MED among confederation paths\n")
2153 {
2154 VTY_DECLVAR_CONTEXT(bgp, bgp);
2155
2156 int idx = 0;
2157 if (argv_find(argv, argc, "confed", &idx))
2158 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2159 idx = 0;
2160 if (argv_find(argv, argc, "missing-as-worst", &idx))
2161 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2162
2163 bgp_recalculate_all_bestpaths(bgp);
2164
2165 return CMD_SUCCESS;
2166 }
2167
2168 DEFUN (no_bgp_bestpath_med,
2169 no_bgp_bestpath_med_cmd,
2170 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
2171 NO_STR
2172 "BGP specific commands\n"
2173 "Change the default bestpath selection\n"
2174 "MED attribute\n"
2175 "Compare MED among confederation paths\n"
2176 "Treat missing MED as the least preferred one\n"
2177 "Treat missing MED as the least preferred one\n"
2178 "Compare MED among confederation paths\n")
2179 {
2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
2181
2182 int idx = 0;
2183 if (argv_find(argv, argc, "confed", &idx))
2184 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2185 idx = 0;
2186 if (argv_find(argv, argc, "missing-as-worst", &idx))
2187 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2188
2189 bgp_recalculate_all_bestpaths(bgp);
2190
2191 return CMD_SUCCESS;
2192 }
2193
2194 /* "no bgp default ipv4-unicast". */
2195 DEFUN (no_bgp_default_ipv4_unicast,
2196 no_bgp_default_ipv4_unicast_cmd,
2197 "no bgp default ipv4-unicast",
2198 NO_STR
2199 "BGP specific commands\n"
2200 "Configure BGP defaults\n"
2201 "Activate ipv4-unicast for a peer by default\n")
2202 {
2203 VTY_DECLVAR_CONTEXT(bgp, bgp);
2204 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2205 return CMD_SUCCESS;
2206 }
2207
2208 DEFUN (bgp_default_ipv4_unicast,
2209 bgp_default_ipv4_unicast_cmd,
2210 "bgp default ipv4-unicast",
2211 "BGP specific commands\n"
2212 "Configure BGP defaults\n"
2213 "Activate ipv4-unicast for a peer by default\n")
2214 {
2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2217 return CMD_SUCCESS;
2218 }
2219
2220 /* Display hostname in certain command outputs */
2221 DEFUN (bgp_default_show_hostname,
2222 bgp_default_show_hostname_cmd,
2223 "bgp default show-hostname",
2224 "BGP specific commands\n"
2225 "Configure BGP defaults\n"
2226 "Show hostname in certain command ouputs\n")
2227 {
2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2230 return CMD_SUCCESS;
2231 }
2232
2233 DEFUN (no_bgp_default_show_hostname,
2234 no_bgp_default_show_hostname_cmd,
2235 "no bgp default show-hostname",
2236 NO_STR
2237 "BGP specific commands\n"
2238 "Configure BGP defaults\n"
2239 "Show hostname in certain command ouputs\n")
2240 {
2241 VTY_DECLVAR_CONTEXT(bgp, bgp);
2242 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2243 return CMD_SUCCESS;
2244 }
2245
2246 /* "bgp network import-check" configuration. */
2247 DEFUN (bgp_network_import_check,
2248 bgp_network_import_check_cmd,
2249 "bgp network import-check",
2250 "BGP specific commands\n"
2251 "BGP network command\n"
2252 "Check BGP network route exists in IGP\n")
2253 {
2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2256 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2257 bgp_static_redo_import_check(bgp);
2258 }
2259
2260 return CMD_SUCCESS;
2261 }
2262
2263 ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2264 "bgp network import-check exact",
2265 "BGP specific commands\n"
2266 "BGP network command\n"
2267 "Check BGP network route exists in IGP\n"
2268 "Match route precisely\n")
2269
2270 DEFUN (no_bgp_network_import_check,
2271 no_bgp_network_import_check_cmd,
2272 "no bgp network import-check",
2273 NO_STR
2274 "BGP specific commands\n"
2275 "BGP network command\n"
2276 "Check BGP network route exists in IGP\n")
2277 {
2278 VTY_DECLVAR_CONTEXT(bgp, bgp);
2279 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2280 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2281 bgp_static_redo_import_check(bgp);
2282 }
2283
2284 return CMD_SUCCESS;
2285 }
2286
2287 DEFUN (bgp_default_local_preference,
2288 bgp_default_local_preference_cmd,
2289 "bgp default local-preference (0-4294967295)",
2290 "BGP specific commands\n"
2291 "Configure BGP defaults\n"
2292 "local preference (higher=more preferred)\n"
2293 "Configure default local preference value\n")
2294 {
2295 VTY_DECLVAR_CONTEXT(bgp, bgp);
2296 int idx_number = 3;
2297 u_int32_t local_pref;
2298
2299 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
2300
2301 bgp_default_local_preference_set(bgp, local_pref);
2302 bgp_clear_star_soft_in(vty, bgp->name);
2303
2304 return CMD_SUCCESS;
2305 }
2306
2307 DEFUN (no_bgp_default_local_preference,
2308 no_bgp_default_local_preference_cmd,
2309 "no bgp default local-preference [(0-4294967295)]",
2310 NO_STR
2311 "BGP specific commands\n"
2312 "Configure BGP defaults\n"
2313 "local preference (higher=more preferred)\n"
2314 "Configure default local preference value\n")
2315 {
2316 VTY_DECLVAR_CONTEXT(bgp, bgp);
2317 bgp_default_local_preference_unset(bgp);
2318 bgp_clear_star_soft_in(vty, bgp->name);
2319
2320 return CMD_SUCCESS;
2321 }
2322
2323
2324 DEFUN (bgp_default_subgroup_pkt_queue_max,
2325 bgp_default_subgroup_pkt_queue_max_cmd,
2326 "bgp default subgroup-pkt-queue-max (20-100)",
2327 "BGP specific commands\n"
2328 "Configure BGP defaults\n"
2329 "subgroup-pkt-queue-max\n"
2330 "Configure subgroup packet queue max\n")
2331 {
2332 VTY_DECLVAR_CONTEXT(bgp, bgp);
2333 int idx_number = 3;
2334 u_int32_t max_size;
2335
2336 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
2337
2338 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
2339
2340 return CMD_SUCCESS;
2341 }
2342
2343 DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2344 no_bgp_default_subgroup_pkt_queue_max_cmd,
2345 "no bgp default subgroup-pkt-queue-max [(20-100)]",
2346 NO_STR
2347 "BGP specific commands\n"
2348 "Configure BGP defaults\n"
2349 "subgroup-pkt-queue-max\n"
2350 "Configure subgroup packet queue max\n")
2351 {
2352 VTY_DECLVAR_CONTEXT(bgp, bgp);
2353 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2354 return CMD_SUCCESS;
2355 }
2356
2357
2358 DEFUN (bgp_rr_allow_outbound_policy,
2359 bgp_rr_allow_outbound_policy_cmd,
2360 "bgp route-reflector allow-outbound-policy",
2361 "BGP specific commands\n"
2362 "Allow modifications made by out route-map\n"
2363 "on ibgp neighbors\n")
2364 {
2365 VTY_DECLVAR_CONTEXT(bgp, bgp);
2366
2367 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2368 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2369 update_group_announce_rrclients(bgp);
2370 bgp_clear_star_soft_out(vty, bgp->name);
2371 }
2372
2373 return CMD_SUCCESS;
2374 }
2375
2376 DEFUN (no_bgp_rr_allow_outbound_policy,
2377 no_bgp_rr_allow_outbound_policy_cmd,
2378 "no bgp route-reflector allow-outbound-policy",
2379 NO_STR
2380 "BGP specific commands\n"
2381 "Allow modifications made by out route-map\n"
2382 "on ibgp neighbors\n")
2383 {
2384 VTY_DECLVAR_CONTEXT(bgp, bgp);
2385
2386 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2387 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2388 update_group_announce_rrclients(bgp);
2389 bgp_clear_star_soft_out(vty, bgp->name);
2390 }
2391
2392 return CMD_SUCCESS;
2393 }
2394
2395 DEFUN (bgp_listen_limit,
2396 bgp_listen_limit_cmd,
2397 "bgp listen limit (1-5000)",
2398 "BGP specific commands\n"
2399 "Configure BGP defaults\n"
2400 "maximum number of BGP Dynamic Neighbors that can be created\n"
2401 "Configure Dynamic Neighbors listen limit value\n")
2402 {
2403 VTY_DECLVAR_CONTEXT(bgp, bgp);
2404 int idx_number = 3;
2405 int listen_limit;
2406
2407 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
2408
2409 bgp_listen_limit_set(bgp, listen_limit);
2410
2411 return CMD_SUCCESS;
2412 }
2413
2414 DEFUN (no_bgp_listen_limit,
2415 no_bgp_listen_limit_cmd,
2416 "no bgp listen limit [(1-5000)]",
2417 "BGP specific commands\n"
2418 "Configure BGP defaults\n"
2419 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
2420 "Configure Dynamic Neighbors listen limit value to default\n"
2421 "Configure Dynamic Neighbors listen limit value\n")
2422 {
2423 VTY_DECLVAR_CONTEXT(bgp, bgp);
2424 bgp_listen_limit_unset(bgp);
2425 return CMD_SUCCESS;
2426 }
2427
2428
2429 /*
2430 * Check if this listen range is already configured. Check for exact
2431 * match or overlap based on input.
2432 */
2433 static struct peer_group *listen_range_exists(struct bgp *bgp,
2434 struct prefix *range, int exact)
2435 {
2436 struct listnode *node, *nnode;
2437 struct listnode *node1, *nnode1;
2438 struct peer_group *group;
2439 struct prefix *lr;
2440 afi_t afi;
2441 int match;
2442
2443 afi = family2afi(range->family);
2444 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2445 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2446 lr)) {
2447 if (exact)
2448 match = prefix_same(range, lr);
2449 else
2450 match = (prefix_match(range, lr)
2451 || prefix_match(lr, range));
2452 if (match)
2453 return group;
2454 }
2455 }
2456
2457 return NULL;
2458 }
2459
2460 DEFUN (bgp_listen_range,
2461 bgp_listen_range_cmd,
2462 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2463 "BGP specific commands\n"
2464 "Configure BGP dynamic neighbors listen range\n"
2465 "Configure BGP dynamic neighbors listen range\n"
2466 NEIGHBOR_ADDR_STR
2467 "Member of the peer-group\n"
2468 "Peer-group name\n")
2469 {
2470 VTY_DECLVAR_CONTEXT(bgp, bgp);
2471 struct prefix range;
2472 struct peer_group *group, *existing_group;
2473 afi_t afi;
2474 int ret;
2475 int idx = 0;
2476
2477 argv_find(argv, argc, "A.B.C.D/M", &idx);
2478 argv_find(argv, argc, "X:X::X:X/M", &idx);
2479 char *prefix = argv[idx]->arg;
2480 argv_find(argv, argc, "WORD", &idx);
2481 char *peergroup = argv[idx]->arg;
2482
2483 /* Convert IP prefix string to struct prefix. */
2484 ret = str2prefix(prefix, &range);
2485 if (!ret) {
2486 vty_out(vty, "%% Malformed listen range\n");
2487 return CMD_WARNING_CONFIG_FAILED;
2488 }
2489
2490 afi = family2afi(range.family);
2491
2492 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2493 vty_out(vty,
2494 "%% Malformed listen range (link-local address)\n");
2495 return CMD_WARNING_CONFIG_FAILED;
2496 }
2497
2498 apply_mask(&range);
2499
2500 /* Check if same listen range is already configured. */
2501 existing_group = listen_range_exists(bgp, &range, 1);
2502 if (existing_group) {
2503 if (strcmp(existing_group->name, peergroup) == 0)
2504 return CMD_SUCCESS;
2505 else {
2506 vty_out(vty,
2507 "%% Same listen range is attached to peer-group %s\n",
2508 existing_group->name);
2509 return CMD_WARNING_CONFIG_FAILED;
2510 }
2511 }
2512
2513 /* Check if an overlapping listen range exists. */
2514 if (listen_range_exists(bgp, &range, 0)) {
2515 vty_out(vty,
2516 "%% Listen range overlaps with existing listen range\n");
2517 return CMD_WARNING_CONFIG_FAILED;
2518 }
2519
2520 group = peer_group_lookup(bgp, peergroup);
2521 if (!group) {
2522 vty_out(vty, "%% Configure the peer-group first\n");
2523 return CMD_WARNING_CONFIG_FAILED;
2524 }
2525
2526 ret = peer_group_listen_range_add(group, &range);
2527 return bgp_vty_return(vty, ret);
2528 }
2529
2530 DEFUN (no_bgp_listen_range,
2531 no_bgp_listen_range_cmd,
2532 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2533 NO_STR
2534 "BGP specific commands\n"
2535 "Unconfigure BGP dynamic neighbors listen range\n"
2536 "Unconfigure BGP dynamic neighbors listen range\n"
2537 NEIGHBOR_ADDR_STR
2538 "Member of the peer-group\n"
2539 "Peer-group name\n")
2540 {
2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 struct prefix range;
2543 struct peer_group *group;
2544 afi_t afi;
2545 int ret;
2546 int idx = 0;
2547
2548 argv_find(argv, argc, "A.B.C.D/M", &idx);
2549 argv_find(argv, argc, "X:X::X:X/M", &idx);
2550 char *prefix = argv[idx]->arg;
2551 argv_find(argv, argc, "WORD", &idx);
2552 char *peergroup = argv[idx]->arg;
2553
2554 /* Convert IP prefix string to struct prefix. */
2555 ret = str2prefix(prefix, &range);
2556 if (!ret) {
2557 vty_out(vty, "%% Malformed listen range\n");
2558 return CMD_WARNING_CONFIG_FAILED;
2559 }
2560
2561 afi = family2afi(range.family);
2562
2563 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2564 vty_out(vty,
2565 "%% Malformed listen range (link-local address)\n");
2566 return CMD_WARNING_CONFIG_FAILED;
2567 }
2568
2569 apply_mask(&range);
2570
2571 group = peer_group_lookup(bgp, peergroup);
2572 if (!group) {
2573 vty_out(vty, "%% Peer-group does not exist\n");
2574 return CMD_WARNING_CONFIG_FAILED;
2575 }
2576
2577 ret = peer_group_listen_range_del(group, &range);
2578 return bgp_vty_return(vty, ret);
2579 }
2580
2581 void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2582 {
2583 struct peer_group *group;
2584 struct listnode *node, *nnode, *rnode, *nrnode;
2585 struct prefix *range;
2586 afi_t afi;
2587 char buf[PREFIX2STR_BUFFER];
2588
2589 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2590 vty_out(vty, " bgp listen limit %d\n",
2591 bgp->dynamic_neighbors_limit);
2592
2593 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2594 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2595 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2596 nrnode, range)) {
2597 prefix2str(range, buf, sizeof(buf));
2598 vty_out(vty,
2599 " bgp listen range %s peer-group %s\n",
2600 buf, group->name);
2601 }
2602 }
2603 }
2604 }
2605
2606
2607 DEFUN (bgp_disable_connected_route_check,
2608 bgp_disable_connected_route_check_cmd,
2609 "bgp disable-ebgp-connected-route-check",
2610 "BGP specific commands\n"
2611 "Disable checking if nexthop is connected on ebgp sessions\n")
2612 {
2613 VTY_DECLVAR_CONTEXT(bgp, bgp);
2614 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2615 bgp_clear_star_soft_in(vty, bgp->name);
2616
2617 return CMD_SUCCESS;
2618 }
2619
2620 DEFUN (no_bgp_disable_connected_route_check,
2621 no_bgp_disable_connected_route_check_cmd,
2622 "no bgp disable-ebgp-connected-route-check",
2623 NO_STR
2624 "BGP specific commands\n"
2625 "Disable checking if nexthop is connected on ebgp sessions\n")
2626 {
2627 VTY_DECLVAR_CONTEXT(bgp, bgp);
2628 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2629 bgp_clear_star_soft_in(vty, bgp->name);
2630
2631 return CMD_SUCCESS;
2632 }
2633
2634
2635 static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2636 const char *as_str, afi_t afi, safi_t safi)
2637 {
2638 VTY_DECLVAR_CONTEXT(bgp, bgp);
2639 int ret;
2640 as_t as;
2641 int as_type = AS_SPECIFIED;
2642 union sockunion su;
2643
2644 if (as_str[0] == 'i') {
2645 as = 0;
2646 as_type = AS_INTERNAL;
2647 } else if (as_str[0] == 'e') {
2648 as = 0;
2649 as_type = AS_EXTERNAL;
2650 } else {
2651 /* Get AS number. */
2652 as = strtoul(as_str, NULL, 10);
2653 }
2654
2655 /* If peer is peer group, call proper function. */
2656 ret = str2sockunion(peer_str, &su);
2657 if (ret < 0) {
2658 /* Check for peer by interface */
2659 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2660 safi);
2661 if (ret < 0) {
2662 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2663 if (ret < 0) {
2664 vty_out(vty,
2665 "%% Create the peer-group or interface first\n");
2666 return CMD_WARNING_CONFIG_FAILED;
2667 }
2668 return CMD_SUCCESS;
2669 }
2670 } else {
2671 if (peer_address_self_check(bgp, &su)) {
2672 vty_out(vty,
2673 "%% Can not configure the local system as neighbor\n");
2674 return CMD_WARNING_CONFIG_FAILED;
2675 }
2676 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2677 }
2678
2679 /* This peer belongs to peer group. */
2680 switch (ret) {
2681 case BGP_ERR_PEER_GROUP_MEMBER:
2682 vty_out(vty,
2683 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2684 as);
2685 return CMD_WARNING_CONFIG_FAILED;
2686 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2687 vty_out(vty,
2688 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2689 as, as_str);
2690 return CMD_WARNING_CONFIG_FAILED;
2691 }
2692 return bgp_vty_return(vty, ret);
2693 }
2694
2695 DEFUN (bgp_default_shutdown,
2696 bgp_default_shutdown_cmd,
2697 "[no] bgp default shutdown",
2698 NO_STR
2699 BGP_STR
2700 "Configure BGP defaults\n"
2701 "Apply administrative shutdown to newly configured peers\n")
2702 {
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2705 return CMD_SUCCESS;
2706 }
2707
2708 DEFUN (neighbor_remote_as,
2709 neighbor_remote_as_cmd,
2710 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
2711 NEIGHBOR_STR
2712 NEIGHBOR_ADDR_STR2
2713 "Specify a BGP neighbor\n"
2714 AS_STR
2715 "Internal BGP peer\n"
2716 "External BGP peer\n")
2717 {
2718 int idx_peer = 1;
2719 int idx_remote_as = 3;
2720 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2721 argv[idx_remote_as]->arg, AFI_IP,
2722 SAFI_UNICAST);
2723 }
2724
2725 static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2726 afi_t afi, safi_t safi, int v6only,
2727 const char *peer_group_name,
2728 const char *as_str)
2729 {
2730 VTY_DECLVAR_CONTEXT(bgp, bgp);
2731 as_t as = 0;
2732 int as_type = AS_UNSPECIFIED;
2733 struct peer *peer;
2734 struct peer_group *group;
2735 int ret = 0;
2736 union sockunion su;
2737
2738 group = peer_group_lookup(bgp, conf_if);
2739
2740 if (group) {
2741 vty_out(vty, "%% Name conflict with peer-group \n");
2742 return CMD_WARNING_CONFIG_FAILED;
2743 }
2744
2745 if (as_str) {
2746 if (as_str[0] == 'i') {
2747 as_type = AS_INTERNAL;
2748 } else if (as_str[0] == 'e') {
2749 as_type = AS_EXTERNAL;
2750 } else {
2751 /* Get AS number. */
2752 as = strtoul(as_str, NULL, 10);
2753 as_type = AS_SPECIFIED;
2754 }
2755 }
2756
2757 peer = peer_lookup_by_conf_if(bgp, conf_if);
2758 if (peer) {
2759 if (as_str)
2760 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2761 afi, safi);
2762 } else {
2763 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2764 && afi == AFI_IP && safi == SAFI_UNICAST)
2765 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2766 as_type, 0, 0, NULL);
2767 else
2768 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2769 as_type, afi, safi, NULL);
2770
2771 if (!peer) {
2772 vty_out(vty, "%% BGP failed to create peer\n");
2773 return CMD_WARNING_CONFIG_FAILED;
2774 }
2775
2776 if (v6only)
2777 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2778
2779 /* Request zebra to initiate IPv6 RAs on this interface. We do
2780 * this
2781 * any unnumbered peer in order to not worry about run-time
2782 * transitions
2783 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2784 * address
2785 * gets deleted later etc.)
2786 */
2787 if (peer->ifp)
2788 bgp_zebra_initiate_radv(bgp, peer);
2789 }
2790
2791 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2792 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2793 if (v6only)
2794 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2795 else
2796 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2797
2798 /* v6only flag changed. Reset bgp seesion */
2799 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2800 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2801 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2802 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2803 } else
2804 bgp_session_reset(peer);
2805 }
2806
2807 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2808 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2809
2810 if (peer_group_name) {
2811 group = peer_group_lookup(bgp, peer_group_name);
2812 if (!group) {
2813 vty_out(vty, "%% Configure the peer-group first\n");
2814 return CMD_WARNING_CONFIG_FAILED;
2815 }
2816
2817 ret = peer_group_bind(bgp, &su, peer, group, &as);
2818 }
2819
2820 return bgp_vty_return(vty, ret);
2821 }
2822
2823 DEFUN (neighbor_interface_config,
2824 neighbor_interface_config_cmd,
2825 "neighbor WORD interface [peer-group WORD]",
2826 NEIGHBOR_STR
2827 "Interface name or neighbor tag\n"
2828 "Enable BGP on interface\n"
2829 "Member of the peer-group\n"
2830 "Peer-group name\n")
2831 {
2832 int idx_word = 1;
2833 int idx_peer_group_word = 4;
2834
2835 if (argc > idx_peer_group_word)
2836 return peer_conf_interface_get(
2837 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2838 argv[idx_peer_group_word]->arg, NULL);
2839 else
2840 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2841 SAFI_UNICAST, 0, NULL, NULL);
2842 }
2843
2844 DEFUN (neighbor_interface_config_v6only,
2845 neighbor_interface_config_v6only_cmd,
2846 "neighbor WORD interface v6only [peer-group WORD]",
2847 NEIGHBOR_STR
2848 "Interface name or neighbor tag\n"
2849 "Enable BGP on interface\n"
2850 "Enable BGP with v6 link-local only\n"
2851 "Member of the peer-group\n"
2852 "Peer-group name\n")
2853 {
2854 int idx_word = 1;
2855 int idx_peer_group_word = 5;
2856
2857 if (argc > idx_peer_group_word)
2858 return peer_conf_interface_get(
2859 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2860 argv[idx_peer_group_word]->arg, NULL);
2861
2862 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2863 SAFI_UNICAST, 1, NULL, NULL);
2864 }
2865
2866
2867 DEFUN (neighbor_interface_config_remote_as,
2868 neighbor_interface_config_remote_as_cmd,
2869 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
2870 NEIGHBOR_STR
2871 "Interface name or neighbor tag\n"
2872 "Enable BGP on interface\n"
2873 "Specify a BGP neighbor\n"
2874 AS_STR
2875 "Internal BGP peer\n"
2876 "External BGP peer\n")
2877 {
2878 int idx_word = 1;
2879 int idx_remote_as = 4;
2880 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2881 SAFI_UNICAST, 0, NULL,
2882 argv[idx_remote_as]->arg);
2883 }
2884
2885 DEFUN (neighbor_interface_v6only_config_remote_as,
2886 neighbor_interface_v6only_config_remote_as_cmd,
2887 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
2888 NEIGHBOR_STR
2889 "Interface name or neighbor tag\n"
2890 "Enable BGP with v6 link-local only\n"
2891 "Enable BGP on interface\n"
2892 "Specify a BGP neighbor\n"
2893 AS_STR
2894 "Internal BGP peer\n"
2895 "External BGP peer\n")
2896 {
2897 int idx_word = 1;
2898 int idx_remote_as = 5;
2899 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2900 SAFI_UNICAST, 1, NULL,
2901 argv[idx_remote_as]->arg);
2902 }
2903
2904 DEFUN (neighbor_peer_group,
2905 neighbor_peer_group_cmd,
2906 "neighbor WORD peer-group",
2907 NEIGHBOR_STR
2908 "Interface name or neighbor tag\n"
2909 "Configure peer-group\n")
2910 {
2911 VTY_DECLVAR_CONTEXT(bgp, bgp);
2912 int idx_word = 1;
2913 struct peer *peer;
2914 struct peer_group *group;
2915
2916 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2917 if (peer) {
2918 vty_out(vty, "%% Name conflict with interface: \n");
2919 return CMD_WARNING_CONFIG_FAILED;
2920 }
2921
2922 group = peer_group_get(bgp, argv[idx_word]->arg);
2923 if (!group) {
2924 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2925 return CMD_WARNING_CONFIG_FAILED;
2926 }
2927
2928 return CMD_SUCCESS;
2929 }
2930
2931 DEFUN (no_neighbor,
2932 no_neighbor_cmd,
2933 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
2934 NO_STR
2935 NEIGHBOR_STR
2936 NEIGHBOR_ADDR_STR2
2937 "Specify a BGP neighbor\n"
2938 AS_STR
2939 "Internal BGP peer\n"
2940 "External BGP peer\n")
2941 {
2942 VTY_DECLVAR_CONTEXT(bgp, bgp);
2943 int idx_peer = 2;
2944 int ret;
2945 union sockunion su;
2946 struct peer_group *group;
2947 struct peer *peer;
2948 struct peer *other;
2949
2950 ret = str2sockunion(argv[idx_peer]->arg, &su);
2951 if (ret < 0) {
2952 /* look up for neighbor by interface name config. */
2953 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2954 if (peer) {
2955 /* Request zebra to terminate IPv6 RAs on this
2956 * interface. */
2957 if (peer->ifp)
2958 bgp_zebra_terminate_radv(peer->bgp, peer);
2959 peer_delete(peer);
2960 return CMD_SUCCESS;
2961 }
2962
2963 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2964 if (group)
2965 peer_group_delete(group);
2966 else {
2967 vty_out(vty, "%% Create the peer-group first\n");
2968 return CMD_WARNING_CONFIG_FAILED;
2969 }
2970 } else {
2971 peer = peer_lookup(bgp, &su);
2972 if (peer) {
2973 if (peer_dynamic_neighbor(peer)) {
2974 vty_out(vty,
2975 "%% Operation not allowed on a dynamic neighbor\n");
2976 return CMD_WARNING_CONFIG_FAILED;
2977 }
2978
2979 other = peer->doppelganger;
2980 peer_delete(peer);
2981 if (other && other->status != Deleted)
2982 peer_delete(other);
2983 }
2984 }
2985
2986 return CMD_SUCCESS;
2987 }
2988
2989 DEFUN (no_neighbor_interface_config,
2990 no_neighbor_interface_config_cmd,
2991 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
2992 NO_STR
2993 NEIGHBOR_STR
2994 "Interface name\n"
2995 "Configure BGP on interface\n"
2996 "Enable BGP with v6 link-local only\n"
2997 "Member of the peer-group\n"
2998 "Peer-group name\n"
2999 "Specify a BGP neighbor\n"
3000 AS_STR
3001 "Internal BGP peer\n"
3002 "External BGP peer\n")
3003 {
3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
3005 int idx_word = 2;
3006 struct peer *peer;
3007
3008 /* look up for neighbor by interface name config. */
3009 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3010 if (peer) {
3011 /* Request zebra to terminate IPv6 RAs on this interface. */
3012 if (peer->ifp)
3013 bgp_zebra_terminate_radv(peer->bgp, peer);
3014 peer_delete(peer);
3015 } else {
3016 vty_out(vty, "%% Create the bgp interface first\n");
3017 return CMD_WARNING_CONFIG_FAILED;
3018 }
3019 return CMD_SUCCESS;
3020 }
3021
3022 DEFUN (no_neighbor_peer_group,
3023 no_neighbor_peer_group_cmd,
3024 "no neighbor WORD peer-group",
3025 NO_STR
3026 NEIGHBOR_STR
3027 "Neighbor tag\n"
3028 "Configure peer-group\n")
3029 {
3030 VTY_DECLVAR_CONTEXT(bgp, bgp);
3031 int idx_word = 2;
3032 struct peer_group *group;
3033
3034 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3035 if (group)
3036 peer_group_delete(group);
3037 else {
3038 vty_out(vty, "%% Create the peer-group first\n");
3039 return CMD_WARNING_CONFIG_FAILED;
3040 }
3041 return CMD_SUCCESS;
3042 }
3043
3044 DEFUN (no_neighbor_interface_peer_group_remote_as,
3045 no_neighbor_interface_peer_group_remote_as_cmd,
3046 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
3047 NO_STR
3048 NEIGHBOR_STR
3049 "Interface name or neighbor tag\n"
3050 "Specify a BGP neighbor\n"
3051 AS_STR
3052 "Internal BGP peer\n"
3053 "External BGP peer\n")
3054 {
3055 VTY_DECLVAR_CONTEXT(bgp, bgp);
3056 int idx_word = 2;
3057 struct peer_group *group;
3058 struct peer *peer;
3059
3060 /* look up for neighbor by interface name config. */
3061 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3062 if (peer) {
3063 peer_as_change(peer, 0, AS_SPECIFIED);
3064 return CMD_SUCCESS;
3065 }
3066
3067 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3068 if (group)
3069 peer_group_remote_as_delete(group);
3070 else {
3071 vty_out(vty, "%% Create the peer-group or interface first\n");
3072 return CMD_WARNING_CONFIG_FAILED;
3073 }
3074 return CMD_SUCCESS;
3075 }
3076
3077 DEFUN (neighbor_local_as,
3078 neighbor_local_as_cmd,
3079 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
3080 NEIGHBOR_STR
3081 NEIGHBOR_ADDR_STR2
3082 "Specify a local-as number\n"
3083 "AS number used as local AS\n")
3084 {
3085 int idx_peer = 1;
3086 int idx_number = 3;
3087 struct peer *peer;
3088 int ret;
3089 as_t as;
3090
3091 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3092 if (!peer)
3093 return CMD_WARNING_CONFIG_FAILED;
3094
3095 as = strtoul(argv[idx_number]->arg, NULL, 10);
3096 ret = peer_local_as_set(peer, as, 0, 0);
3097 return bgp_vty_return(vty, ret);
3098 }
3099
3100 DEFUN (neighbor_local_as_no_prepend,
3101 neighbor_local_as_no_prepend_cmd,
3102 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
3103 NEIGHBOR_STR
3104 NEIGHBOR_ADDR_STR2
3105 "Specify a local-as number\n"
3106 "AS number used as local AS\n"
3107 "Do not prepend local-as to updates from ebgp peers\n")
3108 {
3109 int idx_peer = 1;
3110 int idx_number = 3;
3111 struct peer *peer;
3112 int ret;
3113 as_t as;
3114
3115 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3116 if (!peer)
3117 return CMD_WARNING_CONFIG_FAILED;
3118
3119 as = strtoul(argv[idx_number]->arg, NULL, 10);
3120 ret = peer_local_as_set(peer, as, 1, 0);
3121 return bgp_vty_return(vty, ret);
3122 }
3123
3124 DEFUN (neighbor_local_as_no_prepend_replace_as,
3125 neighbor_local_as_no_prepend_replace_as_cmd,
3126 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
3127 NEIGHBOR_STR
3128 NEIGHBOR_ADDR_STR2
3129 "Specify a local-as number\n"
3130 "AS number used as local AS\n"
3131 "Do not prepend local-as to updates from ebgp peers\n"
3132 "Do not prepend local-as to updates from ibgp peers\n")
3133 {
3134 int idx_peer = 1;
3135 int idx_number = 3;
3136 struct peer *peer;
3137 int ret;
3138 as_t as;
3139
3140 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3141 if (!peer)
3142 return CMD_WARNING_CONFIG_FAILED;
3143
3144 as = strtoul(argv[idx_number]->arg, NULL, 10);
3145 ret = peer_local_as_set(peer, as, 1, 1);
3146 return bgp_vty_return(vty, ret);
3147 }
3148
3149 DEFUN (no_neighbor_local_as,
3150 no_neighbor_local_as_cmd,
3151 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
3152 NO_STR
3153 NEIGHBOR_STR
3154 NEIGHBOR_ADDR_STR2
3155 "Specify a local-as number\n"
3156 "AS number used as local AS\n"
3157 "Do not prepend local-as to updates from ebgp peers\n"
3158 "Do not prepend local-as to updates from ibgp peers\n")
3159 {
3160 int idx_peer = 2;
3161 struct peer *peer;
3162 int ret;
3163
3164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3165 if (!peer)
3166 return CMD_WARNING_CONFIG_FAILED;
3167
3168 ret = peer_local_as_unset(peer);
3169 return bgp_vty_return(vty, ret);
3170 }
3171
3172
3173 DEFUN (neighbor_solo,
3174 neighbor_solo_cmd,
3175 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3176 NEIGHBOR_STR
3177 NEIGHBOR_ADDR_STR2
3178 "Solo peer - part of its own update group\n")
3179 {
3180 int idx_peer = 1;
3181 struct peer *peer;
3182 int ret;
3183
3184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3185 if (!peer)
3186 return CMD_WARNING_CONFIG_FAILED;
3187
3188 ret = update_group_adjust_soloness(peer, 1);
3189 return bgp_vty_return(vty, ret);
3190 }
3191
3192 DEFUN (no_neighbor_solo,
3193 no_neighbor_solo_cmd,
3194 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3195 NO_STR
3196 NEIGHBOR_STR
3197 NEIGHBOR_ADDR_STR2
3198 "Solo peer - part of its own update group\n")
3199 {
3200 int idx_peer = 2;
3201 struct peer *peer;
3202 int ret;
3203
3204 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3205 if (!peer)
3206 return CMD_WARNING_CONFIG_FAILED;
3207
3208 ret = update_group_adjust_soloness(peer, 0);
3209 return bgp_vty_return(vty, ret);
3210 }
3211
3212 DEFUN (neighbor_password,
3213 neighbor_password_cmd,
3214 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
3215 NEIGHBOR_STR
3216 NEIGHBOR_ADDR_STR2
3217 "Set a password\n"
3218 "The password\n")
3219 {
3220 int idx_peer = 1;
3221 int idx_line = 3;
3222 struct peer *peer;
3223 int ret;
3224
3225 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3226 if (!peer)
3227 return CMD_WARNING_CONFIG_FAILED;
3228
3229 ret = peer_password_set(peer, argv[idx_line]->arg);
3230 return bgp_vty_return(vty, ret);
3231 }
3232
3233 DEFUN (no_neighbor_password,
3234 no_neighbor_password_cmd,
3235 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
3236 NO_STR
3237 NEIGHBOR_STR
3238 NEIGHBOR_ADDR_STR2
3239 "Set a password\n"
3240 "The password\n")
3241 {
3242 int idx_peer = 2;
3243 struct peer *peer;
3244 int ret;
3245
3246 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3247 if (!peer)
3248 return CMD_WARNING_CONFIG_FAILED;
3249
3250 ret = peer_password_unset(peer);
3251 return bgp_vty_return(vty, ret);
3252 }
3253
3254 DEFUN (neighbor_activate,
3255 neighbor_activate_cmd,
3256 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 "Enable the Address Family for this Neighbor\n")
3260 {
3261 int idx_peer = 1;
3262 int ret;
3263 struct peer *peer;
3264
3265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3266 if (!peer)
3267 return CMD_WARNING_CONFIG_FAILED;
3268
3269 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3270 return bgp_vty_return(vty, ret);
3271 }
3272
3273 ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3274 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3275 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3276 "Enable the Address Family for this Neighbor\n")
3277
3278 DEFUN (no_neighbor_activate,
3279 no_neighbor_activate_cmd,
3280 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3281 NO_STR
3282 NEIGHBOR_STR
3283 NEIGHBOR_ADDR_STR2
3284 "Enable the Address Family for this Neighbor\n")
3285 {
3286 int idx_peer = 2;
3287 int ret;
3288 struct peer *peer;
3289
3290 /* Lookup peer. */
3291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3292 if (!peer)
3293 return CMD_WARNING_CONFIG_FAILED;
3294
3295 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3296 return bgp_vty_return(vty, ret);
3297 }
3298
3299 ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3300 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3301 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3302 "Enable the Address Family for this Neighbor\n")
3303
3304 DEFUN (neighbor_set_peer_group,
3305 neighbor_set_peer_group_cmd,
3306 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3307 NEIGHBOR_STR
3308 NEIGHBOR_ADDR_STR2
3309 "Member of the peer-group\n"
3310 "Peer-group name\n")
3311 {
3312 VTY_DECLVAR_CONTEXT(bgp, bgp);
3313 int idx_peer = 1;
3314 int idx_word = 3;
3315 int ret;
3316 as_t as;
3317 union sockunion su;
3318 struct peer *peer;
3319 struct peer_group *group;
3320
3321 peer = NULL;
3322
3323 ret = str2sockunion(argv[idx_peer]->arg, &su);
3324 if (ret < 0) {
3325 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3326 if (!peer) {
3327 vty_out(vty, "%% Malformed address or name: %s\n",
3328 argv[idx_peer]->arg);
3329 return CMD_WARNING_CONFIG_FAILED;
3330 }
3331 } else {
3332 if (peer_address_self_check(bgp, &su)) {
3333 vty_out(vty,
3334 "%% Can not configure the local system as neighbor\n");
3335 return CMD_WARNING_CONFIG_FAILED;
3336 }
3337
3338 /* Disallow for dynamic neighbor. */
3339 peer = peer_lookup(bgp, &su);
3340 if (peer && peer_dynamic_neighbor(peer)) {
3341 vty_out(vty,
3342 "%% Operation not allowed on a dynamic neighbor\n");
3343 return CMD_WARNING_CONFIG_FAILED;
3344 }
3345 }
3346
3347 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3348 if (!group) {
3349 vty_out(vty, "%% Configure the peer-group first\n");
3350 return CMD_WARNING_CONFIG_FAILED;
3351 }
3352
3353 ret = peer_group_bind(bgp, &su, peer, group, &as);
3354
3355 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3356 vty_out(vty,
3357 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3358 as);
3359 return CMD_WARNING_CONFIG_FAILED;
3360 }
3361
3362 return bgp_vty_return(vty, ret);
3363 }
3364
3365 ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3366 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3367 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3368 "Member of the peer-group\n"
3369 "Peer-group name\n")
3370
3371 DEFUN (no_neighbor_set_peer_group,
3372 no_neighbor_set_peer_group_cmd,
3373 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3374 NO_STR
3375 NEIGHBOR_STR
3376 NEIGHBOR_ADDR_STR2
3377 "Member of the peer-group\n"
3378 "Peer-group name\n")
3379 {
3380 VTY_DECLVAR_CONTEXT(bgp, bgp);
3381 int idx_peer = 2;
3382 int idx_word = 4;
3383 int ret;
3384 struct peer *peer;
3385 struct peer_group *group;
3386
3387 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3388 if (!peer)
3389 return CMD_WARNING_CONFIG_FAILED;
3390
3391 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3392 if (!group) {
3393 vty_out(vty, "%% Configure the peer-group first\n");
3394 return CMD_WARNING_CONFIG_FAILED;
3395 }
3396
3397 ret = peer_group_unbind(bgp, peer, group);
3398
3399 return bgp_vty_return(vty, ret);
3400 }
3401
3402 ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3403 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3404 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3405 "Member of the peer-group\n"
3406 "Peer-group name\n")
3407
3408 static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3409 u_int16_t flag, int set)
3410 {
3411 int ret;
3412 struct peer *peer;
3413
3414 peer = peer_and_group_lookup_vty(vty, ip_str);
3415 if (!peer)
3416 return CMD_WARNING_CONFIG_FAILED;
3417
3418 /*
3419 * If 'neighbor <interface>', then this is for directly connected peers,
3420 * we should not accept disable-connected-check.
3421 */
3422 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3423 vty_out(vty,
3424 "%s is directly connected peer, cannot accept disable-"
3425 "connected-check\n",
3426 ip_str);
3427 return CMD_WARNING_CONFIG_FAILED;
3428 }
3429
3430 if (!set && flag == PEER_FLAG_SHUTDOWN)
3431 peer_tx_shutdown_message_unset(peer);
3432
3433 if (set)
3434 ret = peer_flag_set(peer, flag);
3435 else
3436 ret = peer_flag_unset(peer, flag);
3437
3438 return bgp_vty_return(vty, ret);
3439 }
3440
3441 static int peer_flag_set_vty(struct vty *vty, const char *ip_str,
3442 u_int16_t flag)
3443 {
3444 return peer_flag_modify_vty(vty, ip_str, flag, 1);
3445 }
3446
3447 static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3448 u_int16_t flag)
3449 {
3450 return peer_flag_modify_vty(vty, ip_str, flag, 0);
3451 }
3452
3453 /* neighbor passive. */
3454 DEFUN (neighbor_passive,
3455 neighbor_passive_cmd,
3456 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3457 NEIGHBOR_STR
3458 NEIGHBOR_ADDR_STR2
3459 "Don't send open messages to this neighbor\n")
3460 {
3461 int idx_peer = 1;
3462 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3463 }
3464
3465 DEFUN (no_neighbor_passive,
3466 no_neighbor_passive_cmd,
3467 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3468 NO_STR
3469 NEIGHBOR_STR
3470 NEIGHBOR_ADDR_STR2
3471 "Don't send open messages to this neighbor\n")
3472 {
3473 int idx_peer = 2;
3474 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3475 }
3476
3477 /* neighbor shutdown. */
3478 DEFUN (neighbor_shutdown_msg,
3479 neighbor_shutdown_msg_cmd,
3480 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3481 NEIGHBOR_STR
3482 NEIGHBOR_ADDR_STR2
3483 "Administratively shut down this neighbor\n"
3484 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3485 "Shutdown message\n")
3486 {
3487 int idx_peer = 1;
3488
3489 if (argc >= 5) {
3490 struct peer *peer =
3491 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3492 char *message;
3493
3494 if (!peer)
3495 return CMD_WARNING_CONFIG_FAILED;
3496 message = argv_concat(argv, argc, 4);
3497 peer_tx_shutdown_message_set(peer, message);
3498 XFREE(MTYPE_TMP, message);
3499 }
3500
3501 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3502 }
3503
3504 ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3505 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3506 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3507 "Administratively shut down this neighbor\n")
3508
3509 DEFUN (no_neighbor_shutdown_msg,
3510 no_neighbor_shutdown_msg_cmd,
3511 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3512 NO_STR
3513 NEIGHBOR_STR
3514 NEIGHBOR_ADDR_STR2
3515 "Administratively shut down this neighbor\n"
3516 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3517 "Shutdown message\n")
3518 {
3519 int idx_peer = 2;
3520
3521 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3522 PEER_FLAG_SHUTDOWN);
3523 }
3524
3525 ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3526 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3527 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3528 "Administratively shut down this neighbor\n")
3529
3530 /* neighbor capability dynamic. */
3531 DEFUN (neighbor_capability_dynamic,
3532 neighbor_capability_dynamic_cmd,
3533 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3534 NEIGHBOR_STR
3535 NEIGHBOR_ADDR_STR2
3536 "Advertise capability to the peer\n"
3537 "Advertise dynamic capability to this neighbor\n")
3538 {
3539 int idx_peer = 1;
3540 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3541 PEER_FLAG_DYNAMIC_CAPABILITY);
3542 }
3543
3544 DEFUN (no_neighbor_capability_dynamic,
3545 no_neighbor_capability_dynamic_cmd,
3546 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3547 NO_STR
3548 NEIGHBOR_STR
3549 NEIGHBOR_ADDR_STR2
3550 "Advertise capability to the peer\n"
3551 "Advertise dynamic capability to this neighbor\n")
3552 {
3553 int idx_peer = 2;
3554 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3555 PEER_FLAG_DYNAMIC_CAPABILITY);
3556 }
3557
3558 /* neighbor dont-capability-negotiate */
3559 DEFUN (neighbor_dont_capability_negotiate,
3560 neighbor_dont_capability_negotiate_cmd,
3561 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3562 NEIGHBOR_STR
3563 NEIGHBOR_ADDR_STR2
3564 "Do not perform capability negotiation\n")
3565 {
3566 int idx_peer = 1;
3567 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3568 PEER_FLAG_DONT_CAPABILITY);
3569 }
3570
3571 DEFUN (no_neighbor_dont_capability_negotiate,
3572 no_neighbor_dont_capability_negotiate_cmd,
3573 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3574 NO_STR
3575 NEIGHBOR_STR
3576 NEIGHBOR_ADDR_STR2
3577 "Do not perform capability negotiation\n")
3578 {
3579 int idx_peer = 2;
3580 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3581 PEER_FLAG_DONT_CAPABILITY);
3582 }
3583
3584 /* neighbor capability extended next hop encoding */
3585 DEFUN (neighbor_capability_enhe,
3586 neighbor_capability_enhe_cmd,
3587 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3588 NEIGHBOR_STR
3589 NEIGHBOR_ADDR_STR2
3590 "Advertise capability to the peer\n"
3591 "Advertise extended next-hop capability to the peer\n")
3592 {
3593 int idx_peer = 1;
3594 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3595 PEER_FLAG_CAPABILITY_ENHE);
3596 }
3597
3598 DEFUN (no_neighbor_capability_enhe,
3599 no_neighbor_capability_enhe_cmd,
3600 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3601 NO_STR
3602 NEIGHBOR_STR
3603 NEIGHBOR_ADDR_STR2
3604 "Advertise capability to the peer\n"
3605 "Advertise extended next-hop capability to the peer\n")
3606 {
3607 int idx_peer = 2;
3608 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3609 PEER_FLAG_CAPABILITY_ENHE);
3610 }
3611
3612 static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3613 afi_t afi, safi_t safi, u_int32_t flag,
3614 int set)
3615 {
3616 int ret;
3617 struct peer *peer;
3618
3619 peer = peer_and_group_lookup_vty(vty, peer_str);
3620 if (!peer)
3621 return CMD_WARNING_CONFIG_FAILED;
3622
3623 if (set)
3624 ret = peer_af_flag_set(peer, afi, safi, flag);
3625 else
3626 ret = peer_af_flag_unset(peer, afi, safi, flag);
3627
3628 return bgp_vty_return(vty, ret);
3629 }
3630
3631 static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3632 afi_t afi, safi_t safi, u_int32_t flag)
3633 {
3634 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
3635 }
3636
3637 static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3638 afi_t afi, safi_t safi, u_int32_t flag)
3639 {
3640 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
3641 }
3642
3643 /* neighbor capability orf prefix-list. */
3644 DEFUN (neighbor_capability_orf_prefix,
3645 neighbor_capability_orf_prefix_cmd,
3646 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3647 NEIGHBOR_STR
3648 NEIGHBOR_ADDR_STR2
3649 "Advertise capability to the peer\n"
3650 "Advertise ORF capability to the peer\n"
3651 "Advertise prefixlist ORF capability to this neighbor\n"
3652 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3653 "Capability to RECEIVE the ORF from this neighbor\n"
3654 "Capability to SEND the ORF to this neighbor\n")
3655 {
3656 int idx_peer = 1;
3657 int idx_send_recv = 5;
3658 u_int16_t flag = 0;
3659
3660 if (strmatch(argv[idx_send_recv]->text, "send"))
3661 flag = PEER_FLAG_ORF_PREFIX_SM;
3662 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3663 flag = PEER_FLAG_ORF_PREFIX_RM;
3664 else if (strmatch(argv[idx_send_recv]->text, "both"))
3665 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3666 else {
3667 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3668 return CMD_WARNING_CONFIG_FAILED;
3669 }
3670
3671 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3672 bgp_node_safi(vty), flag);
3673 }
3674
3675 ALIAS_HIDDEN(
3676 neighbor_capability_orf_prefix,
3677 neighbor_capability_orf_prefix_hidden_cmd,
3678 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3679 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3680 "Advertise capability to the peer\n"
3681 "Advertise ORF capability to the peer\n"
3682 "Advertise prefixlist ORF capability to this neighbor\n"
3683 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3684 "Capability to RECEIVE the ORF from this neighbor\n"
3685 "Capability to SEND the ORF to this neighbor\n")
3686
3687 DEFUN (no_neighbor_capability_orf_prefix,
3688 no_neighbor_capability_orf_prefix_cmd,
3689 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3690 NO_STR
3691 NEIGHBOR_STR
3692 NEIGHBOR_ADDR_STR2
3693 "Advertise capability to the peer\n"
3694 "Advertise ORF capability to the peer\n"
3695 "Advertise prefixlist ORF capability to this neighbor\n"
3696 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3697 "Capability to RECEIVE the ORF from this neighbor\n"
3698 "Capability to SEND the ORF to this neighbor\n")
3699 {
3700 int idx_peer = 2;
3701 int idx_send_recv = 6;
3702 u_int16_t flag = 0;
3703
3704 if (strmatch(argv[idx_send_recv]->text, "send"))
3705 flag = PEER_FLAG_ORF_PREFIX_SM;
3706 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3707 flag = PEER_FLAG_ORF_PREFIX_RM;
3708 else if (strmatch(argv[idx_send_recv]->text, "both"))
3709 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3710 else {
3711 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3712 return CMD_WARNING_CONFIG_FAILED;
3713 }
3714
3715 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3716 bgp_node_afi(vty), bgp_node_safi(vty),
3717 flag);
3718 }
3719
3720 ALIAS_HIDDEN(
3721 no_neighbor_capability_orf_prefix,
3722 no_neighbor_capability_orf_prefix_hidden_cmd,
3723 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3724 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3725 "Advertise capability to the peer\n"
3726 "Advertise ORF capability to the peer\n"
3727 "Advertise prefixlist ORF capability to this neighbor\n"
3728 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3729 "Capability to RECEIVE the ORF from this neighbor\n"
3730 "Capability to SEND the ORF to this neighbor\n")
3731
3732 /* neighbor next-hop-self. */
3733 DEFUN (neighbor_nexthop_self,
3734 neighbor_nexthop_self_cmd,
3735 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3736 NEIGHBOR_STR
3737 NEIGHBOR_ADDR_STR2
3738 "Disable the next hop calculation for this neighbor\n")
3739 {
3740 int idx_peer = 1;
3741 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3742 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
3743 }
3744
3745 ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3746 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3747 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3748 "Disable the next hop calculation for this neighbor\n")
3749
3750 /* neighbor next-hop-self. */
3751 DEFUN (neighbor_nexthop_self_force,
3752 neighbor_nexthop_self_force_cmd,
3753 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3754 NEIGHBOR_STR
3755 NEIGHBOR_ADDR_STR2
3756 "Disable the next hop calculation for this neighbor\n"
3757 "Set the next hop to self for reflected routes\n")
3758 {
3759 int idx_peer = 1;
3760 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3761 bgp_node_safi(vty),
3762 PEER_FLAG_FORCE_NEXTHOP_SELF);
3763 }
3764
3765 ALIAS_HIDDEN(neighbor_nexthop_self_force,
3766 neighbor_nexthop_self_force_hidden_cmd,
3767 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3768 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3769 "Disable the next hop calculation for this neighbor\n"
3770 "Set the next hop to self for reflected routes\n")
3771
3772 DEFUN (no_neighbor_nexthop_self,
3773 no_neighbor_nexthop_self_cmd,
3774 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3775 NO_STR
3776 NEIGHBOR_STR
3777 NEIGHBOR_ADDR_STR2
3778 "Disable the next hop calculation for this neighbor\n")
3779 {
3780 int idx_peer = 2;
3781 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3782 bgp_node_afi(vty), bgp_node_safi(vty),
3783 PEER_FLAG_NEXTHOP_SELF);
3784 }
3785
3786 ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3787 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3788 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3789 "Disable the next hop calculation for this neighbor\n")
3790
3791 DEFUN (no_neighbor_nexthop_self_force,
3792 no_neighbor_nexthop_self_force_cmd,
3793 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3794 NO_STR
3795 NEIGHBOR_STR
3796 NEIGHBOR_ADDR_STR2
3797 "Disable the next hop calculation for this neighbor\n"
3798 "Set the next hop to self for reflected routes\n")
3799 {
3800 int idx_peer = 2;
3801 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3802 bgp_node_afi(vty), bgp_node_safi(vty),
3803 PEER_FLAG_FORCE_NEXTHOP_SELF);
3804 }
3805
3806 ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3807 no_neighbor_nexthop_self_force_hidden_cmd,
3808 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3809 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3810 "Disable the next hop calculation for this neighbor\n"
3811 "Set the next hop to self for reflected routes\n")
3812
3813 /* neighbor as-override */
3814 DEFUN (neighbor_as_override,
3815 neighbor_as_override_cmd,
3816 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3817 NEIGHBOR_STR
3818 NEIGHBOR_ADDR_STR2
3819 "Override ASNs in outbound updates if aspath equals remote-as\n")
3820 {
3821 int idx_peer = 1;
3822 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3823 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
3824 }
3825
3826 ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3827 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3829 "Override ASNs in outbound updates if aspath equals remote-as\n")
3830
3831 DEFUN (no_neighbor_as_override,
3832 no_neighbor_as_override_cmd,
3833 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3834 NO_STR
3835 NEIGHBOR_STR
3836 NEIGHBOR_ADDR_STR2
3837 "Override ASNs in outbound updates if aspath equals remote-as\n")
3838 {
3839 int idx_peer = 2;
3840 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3841 bgp_node_afi(vty), bgp_node_safi(vty),
3842 PEER_FLAG_AS_OVERRIDE);
3843 }
3844
3845 ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3846 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3847 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3848 "Override ASNs in outbound updates if aspath equals remote-as\n")
3849
3850 /* neighbor remove-private-AS. */
3851 DEFUN (neighbor_remove_private_as,
3852 neighbor_remove_private_as_cmd,
3853 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3854 NEIGHBOR_STR
3855 NEIGHBOR_ADDR_STR2
3856 "Remove private ASNs in outbound updates\n")
3857 {
3858 int idx_peer = 1;
3859 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3860 bgp_node_safi(vty),
3861 PEER_FLAG_REMOVE_PRIVATE_AS);
3862 }
3863
3864 ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3865 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3866 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3867 "Remove private ASNs in outbound updates\n")
3868
3869 DEFUN (neighbor_remove_private_as_all,
3870 neighbor_remove_private_as_all_cmd,
3871 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3872 NEIGHBOR_STR
3873 NEIGHBOR_ADDR_STR2
3874 "Remove private ASNs in outbound updates\n"
3875 "Apply to all AS numbers\n")
3876 {
3877 int idx_peer = 1;
3878 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3879 bgp_node_safi(vty),
3880 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3881 }
3882
3883 ALIAS_HIDDEN(neighbor_remove_private_as_all,
3884 neighbor_remove_private_as_all_hidden_cmd,
3885 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3886 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3887 "Remove private ASNs in outbound updates\n"
3888 "Apply to all AS numbers")
3889
3890 DEFUN (neighbor_remove_private_as_replace_as,
3891 neighbor_remove_private_as_replace_as_cmd,
3892 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3893 NEIGHBOR_STR
3894 NEIGHBOR_ADDR_STR2
3895 "Remove private ASNs in outbound updates\n"
3896 "Replace private ASNs with our ASN in outbound updates\n")
3897 {
3898 int idx_peer = 1;
3899 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3900 bgp_node_safi(vty),
3901 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3902 }
3903
3904 ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3905 neighbor_remove_private_as_replace_as_hidden_cmd,
3906 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3907 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3908 "Remove private ASNs in outbound updates\n"
3909 "Replace private ASNs with our ASN in outbound updates\n")
3910
3911 DEFUN (neighbor_remove_private_as_all_replace_as,
3912 neighbor_remove_private_as_all_replace_as_cmd,
3913 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3914 NEIGHBOR_STR
3915 NEIGHBOR_ADDR_STR2
3916 "Remove private ASNs in outbound updates\n"
3917 "Apply to all AS numbers\n"
3918 "Replace private ASNs with our ASN in outbound updates\n")
3919 {
3920 int idx_peer = 1;
3921 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3922 bgp_node_safi(vty),
3923 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3924 }
3925
3926 ALIAS_HIDDEN(
3927 neighbor_remove_private_as_all_replace_as,
3928 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3929 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3930 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3931 "Remove private ASNs in outbound updates\n"
3932 "Apply to all AS numbers\n"
3933 "Replace private ASNs with our ASN in outbound updates\n")
3934
3935 DEFUN (no_neighbor_remove_private_as,
3936 no_neighbor_remove_private_as_cmd,
3937 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3938 NO_STR
3939 NEIGHBOR_STR
3940 NEIGHBOR_ADDR_STR2
3941 "Remove private ASNs in outbound updates\n")
3942 {
3943 int idx_peer = 2;
3944 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3945 bgp_node_afi(vty), bgp_node_safi(vty),
3946 PEER_FLAG_REMOVE_PRIVATE_AS);
3947 }
3948
3949 ALIAS_HIDDEN(no_neighbor_remove_private_as,
3950 no_neighbor_remove_private_as_hidden_cmd,
3951 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3952 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3953 "Remove private ASNs in outbound updates\n")
3954
3955 DEFUN (no_neighbor_remove_private_as_all,
3956 no_neighbor_remove_private_as_all_cmd,
3957 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3958 NO_STR
3959 NEIGHBOR_STR
3960 NEIGHBOR_ADDR_STR2
3961 "Remove private ASNs in outbound updates\n"
3962 "Apply to all AS numbers\n")
3963 {
3964 int idx_peer = 2;
3965 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3966 bgp_node_afi(vty), bgp_node_safi(vty),
3967 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3968 }
3969
3970 ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3971 no_neighbor_remove_private_as_all_hidden_cmd,
3972 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3973 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3974 "Remove private ASNs in outbound updates\n"
3975 "Apply to all AS numbers\n")
3976
3977 DEFUN (no_neighbor_remove_private_as_replace_as,
3978 no_neighbor_remove_private_as_replace_as_cmd,
3979 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3980 NO_STR
3981 NEIGHBOR_STR
3982 NEIGHBOR_ADDR_STR2
3983 "Remove private ASNs in outbound updates\n"
3984 "Replace private ASNs with our ASN in outbound updates\n")
3985 {
3986 int idx_peer = 2;
3987 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3988 bgp_node_afi(vty), bgp_node_safi(vty),
3989 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3990 }
3991
3992 ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
3993 no_neighbor_remove_private_as_replace_as_hidden_cmd,
3994 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3995 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3996 "Remove private ASNs in outbound updates\n"
3997 "Replace private ASNs with our ASN in outbound updates\n")
3998
3999 DEFUN (no_neighbor_remove_private_as_all_replace_as,
4000 no_neighbor_remove_private_as_all_replace_as_cmd,
4001 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4002 NO_STR
4003 NEIGHBOR_STR
4004 NEIGHBOR_ADDR_STR2
4005 "Remove private ASNs in outbound updates\n"
4006 "Apply to all AS numbers\n"
4007 "Replace private ASNs with our ASN in outbound updates\n")
4008 {
4009 int idx_peer = 2;
4010 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4011 bgp_node_afi(vty), bgp_node_safi(vty),
4012 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4013 }
4014
4015 ALIAS_HIDDEN(
4016 no_neighbor_remove_private_as_all_replace_as,
4017 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4018 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4019 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4020 "Remove private ASNs in outbound updates\n"
4021 "Apply to all AS numbers\n"
4022 "Replace private ASNs with our ASN in outbound updates\n")
4023
4024
4025 /* neighbor send-community. */
4026 DEFUN (neighbor_send_community,
4027 neighbor_send_community_cmd,
4028 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4029 NEIGHBOR_STR
4030 NEIGHBOR_ADDR_STR2
4031 "Send Community attribute to this neighbor\n")
4032 {
4033 int idx_peer = 1;
4034 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4035 bgp_node_safi(vty),
4036 PEER_FLAG_SEND_COMMUNITY);
4037 }
4038
4039 ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4040 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4041 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4042 "Send Community attribute to this neighbor\n")
4043
4044 DEFUN (no_neighbor_send_community,
4045 no_neighbor_send_community_cmd,
4046 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4047 NO_STR
4048 NEIGHBOR_STR
4049 NEIGHBOR_ADDR_STR2
4050 "Send Community attribute to this neighbor\n")
4051 {
4052 int idx_peer = 2;
4053 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4054 bgp_node_afi(vty), bgp_node_safi(vty),
4055 PEER_FLAG_SEND_COMMUNITY);
4056 }
4057
4058 ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4059 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4060 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4061 "Send Community attribute to this neighbor\n")
4062
4063 /* neighbor send-community extended. */
4064 DEFUN (neighbor_send_community_type,
4065 neighbor_send_community_type_cmd,
4066 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4067 NEIGHBOR_STR
4068 NEIGHBOR_ADDR_STR2
4069 "Send Community attribute to this neighbor\n"
4070 "Send Standard and Extended Community attributes\n"
4071 "Send Standard, Large and Extended Community attributes\n"
4072 "Send Extended Community attributes\n"
4073 "Send Standard Community attributes\n"
4074 "Send Large Community attributes\n")
4075 {
4076 int idx = 0;
4077 u_int32_t flag = 0;
4078
4079 char *peer = argv[1]->arg;
4080
4081 if (argv_find(argv, argc, "standard", &idx))
4082 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4083 else if (argv_find(argv, argc, "extended", &idx))
4084 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4085 else if (argv_find(argv, argc, "large", &idx))
4086 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4087 else if (argv_find(argv, argc, "both", &idx)) {
4088 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4089 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4090 } else {
4091 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4092 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4093 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4094 }
4095
4096 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4097 bgp_node_safi(vty), flag);
4098 }
4099
4100 ALIAS_HIDDEN(
4101 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4102 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4103 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4104 "Send Community attribute to this neighbor\n"
4105 "Send Standard and Extended Community attributes\n"
4106 "Send Standard, Large and Extended Community attributes\n"
4107 "Send Extended Community attributes\n"
4108 "Send Standard Community attributes\n"
4109 "Send Large Community attributes\n")
4110
4111 DEFUN (no_neighbor_send_community_type,
4112 no_neighbor_send_community_type_cmd,
4113 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4114 NO_STR
4115 NEIGHBOR_STR
4116 NEIGHBOR_ADDR_STR2
4117 "Send Community attribute to this neighbor\n"
4118 "Send Standard and Extended Community attributes\n"
4119 "Send Standard, Large and Extended Community attributes\n"
4120 "Send Extended Community attributes\n"
4121 "Send Standard Community attributes\n"
4122 "Send Large Community attributes\n")
4123 {
4124 int idx_peer = 2;
4125
4126 const char *type = argv[argc - 1]->text;
4127
4128 if (strmatch(type, "standard"))
4129 return peer_af_flag_unset_vty(
4130 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4131 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4132 if (strmatch(type, "extended"))
4133 return peer_af_flag_unset_vty(
4134 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4135 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4136 if (strmatch(type, "large"))
4137 return peer_af_flag_unset_vty(
4138 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4139 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4140 if (strmatch(type, "both"))
4141 return peer_af_flag_unset_vty(
4142 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4143 bgp_node_safi(vty),
4144 PEER_FLAG_SEND_COMMUNITY
4145 | PEER_FLAG_SEND_EXT_COMMUNITY);
4146
4147 /* if (strmatch (type, "all")) */
4148 return peer_af_flag_unset_vty(
4149 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4150 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4151 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4152 }
4153
4154 ALIAS_HIDDEN(
4155 no_neighbor_send_community_type,
4156 no_neighbor_send_community_type_hidden_cmd,
4157 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4158 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4159 "Send Community attribute to this neighbor\n"
4160 "Send Standard and Extended Community attributes\n"
4161 "Send Standard, Large and Extended Community attributes\n"
4162 "Send Extended Community attributes\n"
4163 "Send Standard Community attributes\n"
4164 "Send Large Community attributes\n")
4165
4166 /* neighbor soft-reconfig. */
4167 DEFUN (neighbor_soft_reconfiguration,
4168 neighbor_soft_reconfiguration_cmd,
4169 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4170 NEIGHBOR_STR
4171 NEIGHBOR_ADDR_STR2
4172 "Per neighbor soft reconfiguration\n"
4173 "Allow inbound soft reconfiguration for this neighbor\n")
4174 {
4175 int idx_peer = 1;
4176 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4177 bgp_node_safi(vty),
4178 PEER_FLAG_SOFT_RECONFIG);
4179 }
4180
4181 ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4182 neighbor_soft_reconfiguration_hidden_cmd,
4183 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4184 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4185 "Per neighbor soft reconfiguration\n"
4186 "Allow inbound soft reconfiguration for this neighbor\n")
4187
4188 DEFUN (no_neighbor_soft_reconfiguration,
4189 no_neighbor_soft_reconfiguration_cmd,
4190 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4191 NO_STR
4192 NEIGHBOR_STR
4193 NEIGHBOR_ADDR_STR2
4194 "Per neighbor soft reconfiguration\n"
4195 "Allow inbound soft reconfiguration for this neighbor\n")
4196 {
4197 int idx_peer = 2;
4198 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4199 bgp_node_afi(vty), bgp_node_safi(vty),
4200 PEER_FLAG_SOFT_RECONFIG);
4201 }
4202
4203 ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4204 no_neighbor_soft_reconfiguration_hidden_cmd,
4205 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4206 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4207 "Per neighbor soft reconfiguration\n"
4208 "Allow inbound soft reconfiguration for this neighbor\n")
4209
4210 DEFUN (neighbor_route_reflector_client,
4211 neighbor_route_reflector_client_cmd,
4212 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4213 NEIGHBOR_STR
4214 NEIGHBOR_ADDR_STR2
4215 "Configure a neighbor as Route Reflector client\n")
4216 {
4217 int idx_peer = 1;
4218 struct peer *peer;
4219
4220
4221 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4222 if (!peer)
4223 return CMD_WARNING_CONFIG_FAILED;
4224
4225 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4226 bgp_node_safi(vty),
4227 PEER_FLAG_REFLECTOR_CLIENT);
4228 }
4229
4230 ALIAS_HIDDEN(neighbor_route_reflector_client,
4231 neighbor_route_reflector_client_hidden_cmd,
4232 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4233 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4234 "Configure a neighbor as Route Reflector client\n")
4235
4236 DEFUN (no_neighbor_route_reflector_client,
4237 no_neighbor_route_reflector_client_cmd,
4238 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4239 NO_STR
4240 NEIGHBOR_STR
4241 NEIGHBOR_ADDR_STR2
4242 "Configure a neighbor as Route Reflector client\n")
4243 {
4244 int idx_peer = 2;
4245 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4246 bgp_node_afi(vty), bgp_node_safi(vty),
4247 PEER_FLAG_REFLECTOR_CLIENT);
4248 }
4249
4250 ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4251 no_neighbor_route_reflector_client_hidden_cmd,
4252 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4253 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4254 "Configure a neighbor as Route Reflector client\n")
4255
4256 /* neighbor route-server-client. */
4257 DEFUN (neighbor_route_server_client,
4258 neighbor_route_server_client_cmd,
4259 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4260 NEIGHBOR_STR
4261 NEIGHBOR_ADDR_STR2
4262 "Configure a neighbor as Route Server client\n")
4263 {
4264 int idx_peer = 1;
4265 struct peer *peer;
4266
4267 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4268 if (!peer)
4269 return CMD_WARNING_CONFIG_FAILED;
4270 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4271 bgp_node_safi(vty),
4272 PEER_FLAG_RSERVER_CLIENT);
4273 }
4274
4275 ALIAS_HIDDEN(neighbor_route_server_client,
4276 neighbor_route_server_client_hidden_cmd,
4277 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4278 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4279 "Configure a neighbor as Route Server client\n")
4280
4281 DEFUN (no_neighbor_route_server_client,
4282 no_neighbor_route_server_client_cmd,
4283 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4284 NO_STR
4285 NEIGHBOR_STR
4286 NEIGHBOR_ADDR_STR2
4287 "Configure a neighbor as Route Server client\n")
4288 {
4289 int idx_peer = 2;
4290 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4291 bgp_node_afi(vty), bgp_node_safi(vty),
4292 PEER_FLAG_RSERVER_CLIENT);
4293 }
4294
4295 ALIAS_HIDDEN(no_neighbor_route_server_client,
4296 no_neighbor_route_server_client_hidden_cmd,
4297 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4298 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4299 "Configure a neighbor as Route Server client\n")
4300
4301 DEFUN (neighbor_nexthop_local_unchanged,
4302 neighbor_nexthop_local_unchanged_cmd,
4303 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4304 NEIGHBOR_STR
4305 NEIGHBOR_ADDR_STR2
4306 "Configure treatment of outgoing link-local nexthop attribute\n"
4307 "Leave link-local nexthop unchanged for this peer\n")
4308 {
4309 int idx_peer = 1;
4310 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4311 bgp_node_safi(vty),
4312 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4313 }
4314
4315 DEFUN (no_neighbor_nexthop_local_unchanged,
4316 no_neighbor_nexthop_local_unchanged_cmd,
4317 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4318 NO_STR
4319 NEIGHBOR_STR
4320 NEIGHBOR_ADDR_STR2
4321 "Configure treatment of outgoing link-local-nexthop attribute\n"
4322 "Leave link-local nexthop unchanged for this peer\n")
4323 {
4324 int idx_peer = 2;
4325 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4326 bgp_node_afi(vty), bgp_node_safi(vty),
4327 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
4328 }
4329
4330 DEFUN (neighbor_attr_unchanged,
4331 neighbor_attr_unchanged_cmd,
4332 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4333 NEIGHBOR_STR
4334 NEIGHBOR_ADDR_STR2
4335 "BGP attribute is propagated unchanged to this neighbor\n"
4336 "As-path attribute\n"
4337 "Nexthop attribute\n"
4338 "Med attribute\n")
4339 {
4340 int idx = 0;
4341 char *peer_str = argv[1]->arg;
4342 struct peer *peer;
4343 u_int16_t flags = 0;
4344 afi_t afi = bgp_node_afi(vty);
4345 safi_t safi = bgp_node_safi(vty);
4346
4347 peer = peer_and_group_lookup_vty(vty, peer_str);
4348 if (!peer)
4349 return CMD_WARNING_CONFIG_FAILED;
4350
4351 if (argv_find(argv, argc, "as-path", &idx))
4352 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4353 idx = 0;
4354 if (argv_find(argv, argc, "next-hop", &idx))
4355 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4356 idx = 0;
4357 if (argv_find(argv, argc, "med", &idx))
4358 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4359
4360 /* no flags means all of them! */
4361 if (!flags) {
4362 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4363 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4364 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4365 } else {
4366 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED) &&
4367 peer_af_flag_check(peer, afi, safi,
4368 PEER_FLAG_AS_PATH_UNCHANGED)) {
4369 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4370 PEER_FLAG_AS_PATH_UNCHANGED);
4371 }
4372
4373 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED) &&
4374 peer_af_flag_check(peer, afi, safi,
4375 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4376 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4377 PEER_FLAG_NEXTHOP_UNCHANGED);
4378 }
4379
4380 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED) &&
4381 peer_af_flag_check(peer, afi, safi,
4382 PEER_FLAG_MED_UNCHANGED)) {
4383 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4384 PEER_FLAG_MED_UNCHANGED);
4385 }
4386 }
4387
4388 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
4389 }
4390
4391 ALIAS_HIDDEN(
4392 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4393 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4394 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4395 "BGP attribute is propagated unchanged to this neighbor\n"
4396 "As-path attribute\n"
4397 "Nexthop attribute\n"
4398 "Med attribute\n")
4399
4400 DEFUN (no_neighbor_attr_unchanged,
4401 no_neighbor_attr_unchanged_cmd,
4402 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4403 NO_STR
4404 NEIGHBOR_STR
4405 NEIGHBOR_ADDR_STR2
4406 "BGP attribute is propagated unchanged to this neighbor\n"
4407 "As-path attribute\n"
4408 "Nexthop attribute\n"
4409 "Med attribute\n")
4410 {
4411 int idx = 0;
4412 char *peer = argv[2]->arg;
4413 u_int16_t flags = 0;
4414
4415 if (argv_find(argv, argc, "as-path", &idx))
4416 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4417 idx = 0;
4418 if (argv_find(argv, argc, "next-hop", &idx))
4419 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4420 idx = 0;
4421 if (argv_find(argv, argc, "med", &idx))
4422 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4423
4424 if (!flags) // no flags means all of them!
4425 {
4426 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4427 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4428 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4429 }
4430
4431 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4432 bgp_node_safi(vty), flags);
4433 }
4434
4435 ALIAS_HIDDEN(
4436 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4437 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4438 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4439 "BGP attribute is propagated unchanged to this neighbor\n"
4440 "As-path attribute\n"
4441 "Nexthop attribute\n"
4442 "Med attribute\n")
4443
4444 /* EBGP multihop configuration. */
4445 static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4446 const char *ttl_str)
4447 {
4448 struct peer *peer;
4449 unsigned int ttl;
4450
4451 peer = peer_and_group_lookup_vty(vty, ip_str);
4452 if (!peer)
4453 return CMD_WARNING_CONFIG_FAILED;
4454
4455 if (peer->conf_if)
4456 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4457
4458 if (!ttl_str)
4459 ttl = MAXTTL;
4460 else
4461 ttl = strtoul(ttl_str, NULL, 10);
4462
4463 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
4464 }
4465
4466 static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
4467 {
4468 struct peer *peer;
4469
4470 peer = peer_and_group_lookup_vty(vty, ip_str);
4471 if (!peer)
4472 return CMD_WARNING_CONFIG_FAILED;
4473
4474 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
4475 }
4476
4477 /* neighbor ebgp-multihop. */
4478 DEFUN (neighbor_ebgp_multihop,
4479 neighbor_ebgp_multihop_cmd,
4480 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4481 NEIGHBOR_STR
4482 NEIGHBOR_ADDR_STR2
4483 "Allow EBGP neighbors not on directly connected networks\n")
4484 {
4485 int idx_peer = 1;
4486 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
4487 }
4488
4489 DEFUN (neighbor_ebgp_multihop_ttl,
4490 neighbor_ebgp_multihop_ttl_cmd,
4491 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4492 NEIGHBOR_STR
4493 NEIGHBOR_ADDR_STR2
4494 "Allow EBGP neighbors not on directly connected networks\n"
4495 "maximum hop count\n")
4496 {
4497 int idx_peer = 1;
4498 int idx_number = 3;
4499 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4500 argv[idx_number]->arg);
4501 }
4502
4503 DEFUN (no_neighbor_ebgp_multihop,
4504 no_neighbor_ebgp_multihop_cmd,
4505 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4506 NO_STR
4507 NEIGHBOR_STR
4508 NEIGHBOR_ADDR_STR2
4509 "Allow EBGP neighbors not on directly connected networks\n"
4510 "maximum hop count\n")
4511 {
4512 int idx_peer = 2;
4513 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
4514 }
4515
4516
4517 /* disable-connected-check */
4518 DEFUN (neighbor_disable_connected_check,
4519 neighbor_disable_connected_check_cmd,
4520 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
4523 "one-hop away EBGP peer using loopback address\n"
4524 "Enforce EBGP neighbors perform multihop\n")
4525 {
4526 int idx_peer = 1;
4527 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4528 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4529 }
4530
4531 DEFUN (no_neighbor_disable_connected_check,
4532 no_neighbor_disable_connected_check_cmd,
4533 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4534 NO_STR
4535 NEIGHBOR_STR
4536 NEIGHBOR_ADDR_STR2
4537 "one-hop away EBGP peer using loopback address\n"
4538 "Enforce EBGP neighbors perform multihop\n")
4539 {
4540 int idx_peer = 2;
4541 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4542 PEER_FLAG_DISABLE_CONNECTED_CHECK);
4543 }
4544
4545 DEFUN (neighbor_description,
4546 neighbor_description_cmd,
4547 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4548 NEIGHBOR_STR
4549 NEIGHBOR_ADDR_STR2
4550 "Neighbor specific description\n"
4551 "Up to 80 characters describing this neighbor\n")
4552 {
4553 int idx_peer = 1;
4554 int idx_line = 3;
4555 struct peer *peer;
4556 char *str;
4557
4558 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4559 if (!peer)
4560 return CMD_WARNING_CONFIG_FAILED;
4561
4562 str = argv_concat(argv, argc, idx_line);
4563
4564 peer_description_set(peer, str);
4565
4566 XFREE(MTYPE_TMP, str);
4567
4568 return CMD_SUCCESS;
4569 }
4570
4571 DEFUN (no_neighbor_description,
4572 no_neighbor_description_cmd,
4573 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
4574 NO_STR
4575 NEIGHBOR_STR
4576 NEIGHBOR_ADDR_STR2
4577 "Neighbor specific description\n"
4578 "Up to 80 characters describing this neighbor\n")
4579 {
4580 int idx_peer = 2;
4581 struct peer *peer;
4582
4583 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4584 if (!peer)
4585 return CMD_WARNING_CONFIG_FAILED;
4586
4587 peer_description_unset(peer);
4588
4589 return CMD_SUCCESS;
4590 }
4591
4592
4593 /* Neighbor update-source. */
4594 static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4595 const char *source_str)
4596 {
4597 struct peer *peer;
4598 struct prefix p;
4599
4600 peer = peer_and_group_lookup_vty(vty, peer_str);
4601 if (!peer)
4602 return CMD_WARNING_CONFIG_FAILED;
4603
4604 if (peer->conf_if)
4605 return CMD_WARNING;
4606
4607 if (source_str) {
4608 union sockunion su;
4609 int ret = str2sockunion(source_str, &su);
4610
4611 if (ret == 0)
4612 peer_update_source_addr_set(peer, &su);
4613 else {
4614 if (str2prefix(source_str, &p)) {
4615 vty_out(vty,
4616 "%% Invalid update-source, remove prefix length \n");
4617 return CMD_WARNING_CONFIG_FAILED;
4618 } else
4619 peer_update_source_if_set(peer, source_str);
4620 }
4621 } else
4622 peer_update_source_unset(peer);
4623
4624 return CMD_SUCCESS;
4625 }
4626
4627 #define BGP_UPDATE_SOURCE_HELP_STR \
4628 "IPv4 address\n" \
4629 "IPv6 address\n" \
4630 "Interface name (requires zebra to be running)\n"
4631
4632 DEFUN (neighbor_update_source,
4633 neighbor_update_source_cmd,
4634 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4635 NEIGHBOR_STR
4636 NEIGHBOR_ADDR_STR2
4637 "Source of routing updates\n"
4638 BGP_UPDATE_SOURCE_HELP_STR)
4639 {
4640 int idx_peer = 1;
4641 int idx_peer_2 = 3;
4642 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4643 argv[idx_peer_2]->arg);
4644 }
4645
4646 DEFUN (no_neighbor_update_source,
4647 no_neighbor_update_source_cmd,
4648 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4649 NO_STR
4650 NEIGHBOR_STR
4651 NEIGHBOR_ADDR_STR2
4652 "Source of routing updates\n"
4653 BGP_UPDATE_SOURCE_HELP_STR)
4654 {
4655 int idx_peer = 2;
4656 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
4657 }
4658
4659 static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4660 afi_t afi, safi_t safi,
4661 const char *rmap, int set)
4662 {
4663 int ret;
4664 struct peer *peer;
4665
4666 peer = peer_and_group_lookup_vty(vty, peer_str);
4667 if (!peer)
4668 return CMD_WARNING_CONFIG_FAILED;
4669
4670 if (set)
4671 ret = peer_default_originate_set(peer, afi, safi, rmap);
4672 else
4673 ret = peer_default_originate_unset(peer, afi, safi);
4674
4675 return bgp_vty_return(vty, ret);
4676 }
4677
4678 /* neighbor default-originate. */
4679 DEFUN (neighbor_default_originate,
4680 neighbor_default_originate_cmd,
4681 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4682 NEIGHBOR_STR
4683 NEIGHBOR_ADDR_STR2
4684 "Originate default route to this neighbor\n")
4685 {
4686 int idx_peer = 1;
4687 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4688 bgp_node_afi(vty),
4689 bgp_node_safi(vty), NULL, 1);
4690 }
4691
4692 ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4693 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4694 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4695 "Originate default route to this neighbor\n")
4696
4697 DEFUN (neighbor_default_originate_rmap,
4698 neighbor_default_originate_rmap_cmd,
4699 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4700 NEIGHBOR_STR
4701 NEIGHBOR_ADDR_STR2
4702 "Originate default route to this neighbor\n"
4703 "Route-map to specify criteria to originate default\n"
4704 "route-map name\n")
4705 {
4706 int idx_peer = 1;
4707 int idx_word = 4;
4708 return peer_default_originate_set_vty(
4709 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4710 argv[idx_word]->arg, 1);
4711 }
4712
4713 ALIAS_HIDDEN(
4714 neighbor_default_originate_rmap,
4715 neighbor_default_originate_rmap_hidden_cmd,
4716 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4717 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4718 "Originate default route to this neighbor\n"
4719 "Route-map to specify criteria to originate default\n"
4720 "route-map name\n")
4721
4722 DEFUN (no_neighbor_default_originate,
4723 no_neighbor_default_originate_cmd,
4724 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4725 NO_STR
4726 NEIGHBOR_STR
4727 NEIGHBOR_ADDR_STR2
4728 "Originate default route to this neighbor\n"
4729 "Route-map to specify criteria to originate default\n"
4730 "route-map name\n")
4731 {
4732 int idx_peer = 2;
4733 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4734 bgp_node_afi(vty),
4735 bgp_node_safi(vty), NULL, 0);
4736 }
4737
4738 ALIAS_HIDDEN(
4739 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4740 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4741 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4742 "Originate default route to this neighbor\n"
4743 "Route-map to specify criteria to originate default\n"
4744 "route-map name\n")
4745
4746
4747 /* Set neighbor's BGP port. */
4748 static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4749 const char *port_str)
4750 {
4751 struct peer *peer;
4752 u_int16_t port;
4753 struct servent *sp;
4754
4755 peer = peer_lookup_vty(vty, ip_str);
4756 if (!peer)
4757 return CMD_WARNING_CONFIG_FAILED;
4758
4759 if (!port_str) {
4760 sp = getservbyname("bgp", "tcp");
4761 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4762 } else {
4763 port = strtoul(port_str, NULL, 10);
4764 }
4765
4766 peer_port_set(peer, port);
4767
4768 return CMD_SUCCESS;
4769 }
4770
4771 /* Set specified peer's BGP port. */
4772 DEFUN (neighbor_port,
4773 neighbor_port_cmd,
4774 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4775 NEIGHBOR_STR
4776 NEIGHBOR_ADDR_STR
4777 "Neighbor's BGP port\n"
4778 "TCP port number\n")
4779 {
4780 int idx_ip = 1;
4781 int idx_number = 3;
4782 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4783 argv[idx_number]->arg);
4784 }
4785
4786 DEFUN (no_neighbor_port,
4787 no_neighbor_port_cmd,
4788 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4789 NO_STR
4790 NEIGHBOR_STR
4791 NEIGHBOR_ADDR_STR
4792 "Neighbor's BGP port\n"
4793 "TCP port number\n")
4794 {
4795 int idx_ip = 2;
4796 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
4797 }
4798
4799
4800 /* neighbor weight. */
4801 static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4802 safi_t safi, const char *weight_str)
4803 {
4804 int ret;
4805 struct peer *peer;
4806 unsigned long weight;
4807
4808 peer = peer_and_group_lookup_vty(vty, ip_str);
4809 if (!peer)
4810 return CMD_WARNING_CONFIG_FAILED;
4811
4812 weight = strtoul(weight_str, NULL, 10);
4813
4814 ret = peer_weight_set(peer, afi, safi, weight);
4815 return bgp_vty_return(vty, ret);
4816 }
4817
4818 static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4819 safi_t safi)
4820 {
4821 int ret;
4822 struct peer *peer;
4823
4824 peer = peer_and_group_lookup_vty(vty, ip_str);
4825 if (!peer)
4826 return CMD_WARNING_CONFIG_FAILED;
4827
4828 ret = peer_weight_unset(peer, afi, safi);
4829 return bgp_vty_return(vty, ret);
4830 }
4831
4832 DEFUN (neighbor_weight,
4833 neighbor_weight_cmd,
4834 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4835 NEIGHBOR_STR
4836 NEIGHBOR_ADDR_STR2
4837 "Set default weight for routes from this neighbor\n"
4838 "default weight\n")
4839 {
4840 int idx_peer = 1;
4841 int idx_number = 3;
4842 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4843 bgp_node_safi(vty), argv[idx_number]->arg);
4844 }
4845
4846 ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4847 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4848 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4849 "Set default weight for routes from this neighbor\n"
4850 "default weight\n")
4851
4852 DEFUN (no_neighbor_weight,
4853 no_neighbor_weight_cmd,
4854 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4855 NO_STR
4856 NEIGHBOR_STR
4857 NEIGHBOR_ADDR_STR2
4858 "Set default weight for routes from this neighbor\n"
4859 "default weight\n")
4860 {
4861 int idx_peer = 2;
4862 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4863 bgp_node_afi(vty), bgp_node_safi(vty));
4864 }
4865
4866 ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4867 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4868 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4869 "Set default weight for routes from this neighbor\n"
4870 "default weight\n")
4871
4872
4873 /* Override capability negotiation. */
4874 DEFUN (neighbor_override_capability,
4875 neighbor_override_capability_cmd,
4876 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4877 NEIGHBOR_STR
4878 NEIGHBOR_ADDR_STR2
4879 "Override capability negotiation result\n")
4880 {
4881 int idx_peer = 1;
4882 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4883 PEER_FLAG_OVERRIDE_CAPABILITY);
4884 }
4885
4886 DEFUN (no_neighbor_override_capability,
4887 no_neighbor_override_capability_cmd,
4888 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4889 NO_STR
4890 NEIGHBOR_STR
4891 NEIGHBOR_ADDR_STR2
4892 "Override capability negotiation result\n")
4893 {
4894 int idx_peer = 2;
4895 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4896 PEER_FLAG_OVERRIDE_CAPABILITY);
4897 }
4898
4899 DEFUN (neighbor_strict_capability,
4900 neighbor_strict_capability_cmd,
4901 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4902 NEIGHBOR_STR
4903 NEIGHBOR_ADDR_STR
4904 "Strict capability negotiation match\n")
4905 {
4906 int idx_ip = 1;
4907 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4908 PEER_FLAG_STRICT_CAP_MATCH);
4909 }
4910
4911 DEFUN (no_neighbor_strict_capability,
4912 no_neighbor_strict_capability_cmd,
4913 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4914 NO_STR
4915 NEIGHBOR_STR
4916 NEIGHBOR_ADDR_STR
4917 "Strict capability negotiation match\n")
4918 {
4919 int idx_ip = 2;
4920 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4921 PEER_FLAG_STRICT_CAP_MATCH);
4922 }
4923
4924 static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4925 const char *keep_str, const char *hold_str)
4926 {
4927 int ret;
4928 struct peer *peer;
4929 u_int32_t keepalive;
4930 u_int32_t holdtime;
4931
4932 peer = peer_and_group_lookup_vty(vty, ip_str);
4933 if (!peer)
4934 return CMD_WARNING_CONFIG_FAILED;
4935
4936 keepalive = strtoul(keep_str, NULL, 10);
4937 holdtime = strtoul(hold_str, NULL, 10);
4938
4939 ret = peer_timers_set(peer, keepalive, holdtime);
4940
4941 return bgp_vty_return(vty, ret);
4942 }
4943
4944 static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
4945 {
4946 int ret;
4947 struct peer *peer;
4948
4949 peer = peer_and_group_lookup_vty(vty, ip_str);
4950 if (!peer)
4951 return CMD_WARNING_CONFIG_FAILED;
4952
4953 ret = peer_timers_unset(peer);
4954
4955 return bgp_vty_return(vty, ret);
4956 }
4957
4958 DEFUN (neighbor_timers,
4959 neighbor_timers_cmd,
4960 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
4961 NEIGHBOR_STR
4962 NEIGHBOR_ADDR_STR2
4963 "BGP per neighbor timers\n"
4964 "Keepalive interval\n"
4965 "Holdtime\n")
4966 {
4967 int idx_peer = 1;
4968 int idx_number = 3;
4969 int idx_number_2 = 4;
4970 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4971 argv[idx_number]->arg,
4972 argv[idx_number_2]->arg);
4973 }
4974
4975 DEFUN (no_neighbor_timers,
4976 no_neighbor_timers_cmd,
4977 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
4978 NO_STR
4979 NEIGHBOR_STR
4980 NEIGHBOR_ADDR_STR2
4981 "BGP per neighbor timers\n"
4982 "Keepalive interval\n"
4983 "Holdtime\n")
4984 {
4985 int idx_peer = 2;
4986 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
4987 }
4988
4989
4990 static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
4991 const char *time_str)
4992 {
4993 int ret;
4994 struct peer *peer;
4995 u_int32_t connect;
4996
4997 peer = peer_and_group_lookup_vty(vty, ip_str);
4998 if (!peer)
4999 return CMD_WARNING_CONFIG_FAILED;
5000
5001 connect = strtoul(time_str, NULL, 10);
5002
5003 ret = peer_timers_connect_set(peer, connect);
5004
5005 return bgp_vty_return(vty, ret);
5006 }
5007
5008 static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
5009 {
5010 int ret;
5011 struct peer *peer;
5012
5013 peer = peer_and_group_lookup_vty(vty, ip_str);
5014 if (!peer)
5015 return CMD_WARNING_CONFIG_FAILED;
5016
5017 ret = peer_timers_connect_unset(peer);
5018
5019 return bgp_vty_return(vty, ret);
5020 }
5021
5022 DEFUN (neighbor_timers_connect,
5023 neighbor_timers_connect_cmd,
5024 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
5025 NEIGHBOR_STR
5026 NEIGHBOR_ADDR_STR2
5027 "BGP per neighbor timers\n"
5028 "BGP connect timer\n"
5029 "Connect timer\n")
5030 {
5031 int idx_peer = 1;
5032 int idx_number = 4;
5033 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5034 argv[idx_number]->arg);
5035 }
5036
5037 DEFUN (no_neighbor_timers_connect,
5038 no_neighbor_timers_connect_cmd,
5039 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
5040 NO_STR
5041 NEIGHBOR_STR
5042 NEIGHBOR_ADDR_STR2
5043 "BGP per neighbor timers\n"
5044 "BGP connect timer\n"
5045 "Connect timer\n")
5046 {
5047 int idx_peer = 2;
5048 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
5049 }
5050
5051
5052 static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5053 const char *time_str, int set)
5054 {
5055 int ret;
5056 struct peer *peer;
5057 u_int32_t routeadv = 0;
5058
5059 peer = peer_and_group_lookup_vty(vty, ip_str);
5060 if (!peer)
5061 return CMD_WARNING_CONFIG_FAILED;
5062
5063 if (time_str)
5064 routeadv = strtoul(time_str, NULL, 10);
5065
5066 if (set)
5067 ret = peer_advertise_interval_set(peer, routeadv);
5068 else
5069 ret = peer_advertise_interval_unset(peer);
5070
5071 return bgp_vty_return(vty, ret);
5072 }
5073
5074 DEFUN (neighbor_advertise_interval,
5075 neighbor_advertise_interval_cmd,
5076 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
5077 NEIGHBOR_STR
5078 NEIGHBOR_ADDR_STR2
5079 "Minimum interval between sending BGP routing updates\n"
5080 "time in seconds\n")
5081 {
5082 int idx_peer = 1;
5083 int idx_number = 3;
5084 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5085 argv[idx_number]->arg, 1);
5086 }
5087
5088 DEFUN (no_neighbor_advertise_interval,
5089 no_neighbor_advertise_interval_cmd,
5090 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
5091 NO_STR
5092 NEIGHBOR_STR
5093 NEIGHBOR_ADDR_STR2
5094 "Minimum interval between sending BGP routing updates\n"
5095 "time in seconds\n")
5096 {
5097 int idx_peer = 2;
5098 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
5099 }
5100
5101
5102 /* Time to wait before processing route-map updates */
5103 DEFUN (bgp_set_route_map_delay_timer,
5104 bgp_set_route_map_delay_timer_cmd,
5105 "bgp route-map delay-timer (0-600)",
5106 SET_STR
5107 "BGP route-map delay timer\n"
5108 "Time in secs to wait before processing route-map changes\n"
5109 "0 disables the timer, no route updates happen when route-maps change\n")
5110 {
5111 int idx_number = 3;
5112 u_int32_t rmap_delay_timer;
5113
5114 if (argv[idx_number]->arg) {
5115 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5116 bm->rmap_update_timer = rmap_delay_timer;
5117
5118 /* if the dynamic update handling is being disabled, and a timer
5119 * is
5120 * running, stop the timer and act as if the timer has already
5121 * fired.
5122 */
5123 if (!rmap_delay_timer && bm->t_rmap_update) {
5124 BGP_TIMER_OFF(bm->t_rmap_update);
5125 thread_execute(bm->master, bgp_route_map_update_timer,
5126 NULL, 0);
5127 }
5128 return CMD_SUCCESS;
5129 } else {
5130 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5131 return CMD_WARNING_CONFIG_FAILED;
5132 }
5133 }
5134
5135 DEFUN (no_bgp_set_route_map_delay_timer,
5136 no_bgp_set_route_map_delay_timer_cmd,
5137 "no bgp route-map delay-timer [(0-600)]",
5138 NO_STR
5139 BGP_STR
5140 "Default BGP route-map delay timer\n"
5141 "Reset to default time to wait for processing route-map changes\n"
5142 "0 disables the timer, no route updates happen when route-maps change\n")
5143 {
5144
5145 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
5146
5147 return CMD_SUCCESS;
5148 }
5149
5150
5151 /* neighbor interface */
5152 static int peer_interface_vty(struct vty *vty, const char *ip_str,
5153 const char *str)
5154 {
5155 struct peer *peer;
5156
5157 peer = peer_lookup_vty(vty, ip_str);
5158 if (!peer || peer->conf_if) {
5159 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5160 return CMD_WARNING_CONFIG_FAILED;
5161 }
5162
5163 if (str)
5164 peer_interface_set(peer, str);
5165 else
5166 peer_interface_unset(peer);
5167
5168 return CMD_SUCCESS;
5169 }
5170
5171 DEFUN (neighbor_interface,
5172 neighbor_interface_cmd,
5173 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
5174 NEIGHBOR_STR
5175 NEIGHBOR_ADDR_STR
5176 "Interface\n"
5177 "Interface name\n")
5178 {
5179 int idx_ip = 1;
5180 int idx_word = 3;
5181 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
5182 }
5183
5184 DEFUN (no_neighbor_interface,
5185 no_neighbor_interface_cmd,
5186 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
5187 NO_STR
5188 NEIGHBOR_STR
5189 NEIGHBOR_ADDR_STR2
5190 "Interface\n"
5191 "Interface name\n")
5192 {
5193 int idx_peer = 2;
5194 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
5195 }
5196
5197 DEFUN (neighbor_distribute_list,
5198 neighbor_distribute_list_cmd,
5199 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5200 NEIGHBOR_STR
5201 NEIGHBOR_ADDR_STR2
5202 "Filter updates to/from this neighbor\n"
5203 "IP access-list number\n"
5204 "IP access-list number (expanded range)\n"
5205 "IP Access-list name\n"
5206 "Filter incoming updates\n"
5207 "Filter outgoing updates\n")
5208 {
5209 int idx_peer = 1;
5210 int idx_acl = 3;
5211 int direct, ret;
5212 struct peer *peer;
5213
5214 const char *pstr = argv[idx_peer]->arg;
5215 const char *acl = argv[idx_acl]->arg;
5216 const char *inout = argv[argc - 1]->text;
5217
5218 peer = peer_and_group_lookup_vty(vty, pstr);
5219 if (!peer)
5220 return CMD_WARNING_CONFIG_FAILED;
5221
5222 /* Check filter direction. */
5223 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5224 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5225 direct, acl);
5226
5227 return bgp_vty_return(vty, ret);
5228 }
5229
5230 ALIAS_HIDDEN(
5231 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5232 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5233 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5234 "Filter updates to/from this neighbor\n"
5235 "IP access-list number\n"
5236 "IP access-list number (expanded range)\n"
5237 "IP Access-list name\n"
5238 "Filter incoming updates\n"
5239 "Filter outgoing updates\n")
5240
5241 DEFUN (no_neighbor_distribute_list,
5242 no_neighbor_distribute_list_cmd,
5243 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5244 NO_STR
5245 NEIGHBOR_STR
5246 NEIGHBOR_ADDR_STR2
5247 "Filter updates to/from this neighbor\n"
5248 "IP access-list number\n"
5249 "IP access-list number (expanded range)\n"
5250 "IP Access-list name\n"
5251 "Filter incoming updates\n"
5252 "Filter outgoing updates\n")
5253 {
5254 int idx_peer = 2;
5255 int direct, ret;
5256 struct peer *peer;
5257
5258 const char *pstr = argv[idx_peer]->arg;
5259 const char *inout = argv[argc - 1]->text;
5260
5261 peer = peer_and_group_lookup_vty(vty, pstr);
5262 if (!peer)
5263 return CMD_WARNING_CONFIG_FAILED;
5264
5265 /* Check filter direction. */
5266 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5267 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5268 direct);
5269
5270 return bgp_vty_return(vty, ret);
5271 }
5272
5273 ALIAS_HIDDEN(
5274 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5275 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5276 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5277 "Filter updates to/from this neighbor\n"
5278 "IP access-list number\n"
5279 "IP access-list number (expanded range)\n"
5280 "IP Access-list name\n"
5281 "Filter incoming updates\n"
5282 "Filter outgoing updates\n")
5283
5284 /* Set prefix list to the peer. */
5285 static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5286 afi_t afi, safi_t safi,
5287 const char *name_str,
5288 const char *direct_str)
5289 {
5290 int ret;
5291 struct peer *peer;
5292 int direct = FILTER_IN;
5293
5294 peer = peer_and_group_lookup_vty(vty, ip_str);
5295 if (!peer)
5296 return CMD_WARNING_CONFIG_FAILED;
5297
5298 /* Check filter direction. */
5299 if (strncmp(direct_str, "i", 1) == 0)
5300 direct = FILTER_IN;
5301 else if (strncmp(direct_str, "o", 1) == 0)
5302 direct = FILTER_OUT;
5303
5304 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
5305
5306 return bgp_vty_return(vty, ret);
5307 }
5308
5309 static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5310 afi_t afi, safi_t safi,
5311 const char *direct_str)
5312 {
5313 int ret;
5314 struct peer *peer;
5315 int direct = FILTER_IN;
5316
5317 peer = peer_and_group_lookup_vty(vty, ip_str);
5318 if (!peer)
5319 return CMD_WARNING_CONFIG_FAILED;
5320
5321 /* Check filter direction. */
5322 if (strncmp(direct_str, "i", 1) == 0)
5323 direct = FILTER_IN;
5324 else if (strncmp(direct_str, "o", 1) == 0)
5325 direct = FILTER_OUT;
5326
5327 ret = peer_prefix_list_unset(peer, afi, safi, direct);
5328
5329 return bgp_vty_return(vty, ret);
5330 }
5331
5332 DEFUN (neighbor_prefix_list,
5333 neighbor_prefix_list_cmd,
5334 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5335 NEIGHBOR_STR
5336 NEIGHBOR_ADDR_STR2
5337 "Filter updates to/from this neighbor\n"
5338 "Name of a prefix list\n"
5339 "Filter incoming updates\n"
5340 "Filter outgoing updates\n")
5341 {
5342 int idx_peer = 1;
5343 int idx_word = 3;
5344 int idx_in_out = 4;
5345 return peer_prefix_list_set_vty(
5346 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5347 argv[idx_word]->arg, argv[idx_in_out]->arg);
5348 }
5349
5350 ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5351 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5352 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5353 "Filter updates to/from this neighbor\n"
5354 "Name of a prefix list\n"
5355 "Filter incoming updates\n"
5356 "Filter outgoing updates\n")
5357
5358 DEFUN (no_neighbor_prefix_list,
5359 no_neighbor_prefix_list_cmd,
5360 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5361 NO_STR
5362 NEIGHBOR_STR
5363 NEIGHBOR_ADDR_STR2
5364 "Filter updates to/from this neighbor\n"
5365 "Name of a prefix list\n"
5366 "Filter incoming updates\n"
5367 "Filter outgoing updates\n")
5368 {
5369 int idx_peer = 2;
5370 int idx_in_out = 5;
5371 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5372 bgp_node_afi(vty), bgp_node_safi(vty),
5373 argv[idx_in_out]->arg);
5374 }
5375
5376 ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5377 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5378 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5379 "Filter updates to/from this neighbor\n"
5380 "Name of a prefix list\n"
5381 "Filter incoming updates\n"
5382 "Filter outgoing updates\n")
5383
5384 static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5385 safi_t safi, const char *name_str,
5386 const char *direct_str)
5387 {
5388 int ret;
5389 struct peer *peer;
5390 int direct = FILTER_IN;
5391
5392 peer = peer_and_group_lookup_vty(vty, ip_str);
5393 if (!peer)
5394 return CMD_WARNING_CONFIG_FAILED;
5395
5396 /* Check filter direction. */
5397 if (strncmp(direct_str, "i", 1) == 0)
5398 direct = FILTER_IN;
5399 else if (strncmp(direct_str, "o", 1) == 0)
5400 direct = FILTER_OUT;
5401
5402 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
5403
5404 return bgp_vty_return(vty, ret);
5405 }
5406
5407 static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5408 safi_t safi, const char *direct_str)
5409 {
5410 int ret;
5411 struct peer *peer;
5412 int direct = FILTER_IN;
5413
5414 peer = peer_and_group_lookup_vty(vty, ip_str);
5415 if (!peer)
5416 return CMD_WARNING_CONFIG_FAILED;
5417
5418 /* Check filter direction. */
5419 if (strncmp(direct_str, "i", 1) == 0)
5420 direct = FILTER_IN;
5421 else if (strncmp(direct_str, "o", 1) == 0)
5422 direct = FILTER_OUT;
5423
5424 ret = peer_aslist_unset(peer, afi, safi, direct);
5425
5426 return bgp_vty_return(vty, ret);
5427 }
5428
5429 DEFUN (neighbor_filter_list,
5430 neighbor_filter_list_cmd,
5431 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5432 NEIGHBOR_STR
5433 NEIGHBOR_ADDR_STR2
5434 "Establish BGP filters\n"
5435 "AS path access-list name\n"
5436 "Filter incoming routes\n"
5437 "Filter outgoing routes\n")
5438 {
5439 int idx_peer = 1;
5440 int idx_word = 3;
5441 int idx_in_out = 4;
5442 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5443 bgp_node_safi(vty), argv[idx_word]->arg,
5444 argv[idx_in_out]->arg);
5445 }
5446
5447 ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5448 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5449 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5450 "Establish BGP filters\n"
5451 "AS path access-list name\n"
5452 "Filter incoming routes\n"
5453 "Filter outgoing routes\n")
5454
5455 DEFUN (no_neighbor_filter_list,
5456 no_neighbor_filter_list_cmd,
5457 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5458 NO_STR
5459 NEIGHBOR_STR
5460 NEIGHBOR_ADDR_STR2
5461 "Establish BGP filters\n"
5462 "AS path access-list name\n"
5463 "Filter incoming routes\n"
5464 "Filter outgoing routes\n")
5465 {
5466 int idx_peer = 2;
5467 int idx_in_out = 5;
5468 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5469 bgp_node_afi(vty), bgp_node_safi(vty),
5470 argv[idx_in_out]->arg);
5471 }
5472
5473 ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5474 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5475 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5476 "Establish BGP filters\n"
5477 "AS path access-list name\n"
5478 "Filter incoming routes\n"
5479 "Filter outgoing routes\n")
5480
5481 /* Set route-map to the peer. */
5482 static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5483 afi_t afi, safi_t safi, const char *name_str,
5484 const char *direct_str)
5485 {
5486 int ret;
5487 struct peer *peer;
5488 int direct = RMAP_IN;
5489
5490 peer = peer_and_group_lookup_vty(vty, ip_str);
5491 if (!peer)
5492 return CMD_WARNING_CONFIG_FAILED;
5493
5494 /* Check filter direction. */
5495 if (strncmp(direct_str, "in", 2) == 0)
5496 direct = RMAP_IN;
5497 else if (strncmp(direct_str, "o", 1) == 0)
5498 direct = RMAP_OUT;
5499
5500 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
5501
5502 return bgp_vty_return(vty, ret);
5503 }
5504
5505 static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5506 afi_t afi, safi_t safi,
5507 const char *direct_str)
5508 {
5509 int ret;
5510 struct peer *peer;
5511 int direct = RMAP_IN;
5512
5513 peer = peer_and_group_lookup_vty(vty, ip_str);
5514 if (!peer)
5515 return CMD_WARNING_CONFIG_FAILED;
5516
5517 /* Check filter direction. */
5518 if (strncmp(direct_str, "in", 2) == 0)
5519 direct = RMAP_IN;
5520 else if (strncmp(direct_str, "o", 1) == 0)
5521 direct = RMAP_OUT;
5522
5523 ret = peer_route_map_unset(peer, afi, safi, direct);
5524
5525 return bgp_vty_return(vty, ret);
5526 }
5527
5528 DEFUN (neighbor_route_map,
5529 neighbor_route_map_cmd,
5530 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5531 NEIGHBOR_STR
5532 NEIGHBOR_ADDR_STR2
5533 "Apply route map to neighbor\n"
5534 "Name of route map\n"
5535 "Apply map to incoming routes\n"
5536 "Apply map to outbound routes\n")
5537 {
5538 int idx_peer = 1;
5539 int idx_word = 3;
5540 int idx_in_out = 4;
5541 return peer_route_map_set_vty(
5542 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5543 argv[idx_word]->arg, argv[idx_in_out]->arg);
5544 }
5545
5546 ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5547 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5548 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5549 "Apply route map to neighbor\n"
5550 "Name of route map\n"
5551 "Apply map to incoming routes\n"
5552 "Apply map to outbound routes\n")
5553
5554 DEFUN (no_neighbor_route_map,
5555 no_neighbor_route_map_cmd,
5556 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5557 NO_STR
5558 NEIGHBOR_STR
5559 NEIGHBOR_ADDR_STR2
5560 "Apply route map to neighbor\n"
5561 "Name of route map\n"
5562 "Apply map to incoming routes\n"
5563 "Apply map to outbound routes\n")
5564 {
5565 int idx_peer = 2;
5566 int idx_in_out = 5;
5567 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5568 bgp_node_afi(vty), bgp_node_safi(vty),
5569 argv[idx_in_out]->arg);
5570 }
5571
5572 ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5573 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5574 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5575 "Apply route map to neighbor\n"
5576 "Name of route map\n"
5577 "Apply map to incoming routes\n"
5578 "Apply map to outbound routes\n")
5579
5580 /* Set unsuppress-map to the peer. */
5581 static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5582 afi_t afi, safi_t safi,
5583 const char *name_str)
5584 {
5585 int ret;
5586 struct peer *peer;
5587
5588 peer = peer_and_group_lookup_vty(vty, ip_str);
5589 if (!peer)
5590 return CMD_WARNING_CONFIG_FAILED;
5591
5592 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
5593
5594 return bgp_vty_return(vty, ret);
5595 }
5596
5597 /* Unset route-map from the peer. */
5598 static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5599 afi_t afi, safi_t safi)
5600 {
5601 int ret;
5602 struct peer *peer;
5603
5604 peer = peer_and_group_lookup_vty(vty, ip_str);
5605 if (!peer)
5606 return CMD_WARNING_CONFIG_FAILED;
5607
5608 ret = peer_unsuppress_map_unset(peer, afi, safi);
5609
5610 return bgp_vty_return(vty, ret);
5611 }
5612
5613 DEFUN (neighbor_unsuppress_map,
5614 neighbor_unsuppress_map_cmd,
5615 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5616 NEIGHBOR_STR
5617 NEIGHBOR_ADDR_STR2
5618 "Route-map to selectively unsuppress suppressed routes\n"
5619 "Name of route map\n")
5620 {
5621 int idx_peer = 1;
5622 int idx_word = 3;
5623 return peer_unsuppress_map_set_vty(
5624 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5625 argv[idx_word]->arg);
5626 }
5627
5628 ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5629 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5630 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5631 "Route-map to selectively unsuppress suppressed routes\n"
5632 "Name of route map\n")
5633
5634 DEFUN (no_neighbor_unsuppress_map,
5635 no_neighbor_unsuppress_map_cmd,
5636 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5637 NO_STR
5638 NEIGHBOR_STR
5639 NEIGHBOR_ADDR_STR2
5640 "Route-map to selectively unsuppress suppressed routes\n"
5641 "Name of route map\n")
5642 {
5643 int idx_peer = 2;
5644 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5645 bgp_node_afi(vty),
5646 bgp_node_safi(vty));
5647 }
5648
5649 ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5650 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5651 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5652 "Route-map to selectively unsuppress suppressed routes\n"
5653 "Name of route map\n")
5654
5655 static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5656 afi_t afi, safi_t safi,
5657 const char *num_str,
5658 const char *threshold_str, int warning,
5659 const char *restart_str)
5660 {
5661 int ret;
5662 struct peer *peer;
5663 u_int32_t max;
5664 u_char threshold;
5665 u_int16_t restart;
5666
5667 peer = peer_and_group_lookup_vty(vty, ip_str);
5668 if (!peer)
5669 return CMD_WARNING_CONFIG_FAILED;
5670
5671 max = strtoul(num_str, NULL, 10);
5672 if (threshold_str)
5673 threshold = atoi(threshold_str);
5674 else
5675 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5676
5677 if (restart_str)
5678 restart = atoi(restart_str);
5679 else
5680 restart = 0;
5681
5682 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5683 restart);
5684
5685 return bgp_vty_return(vty, ret);
5686 }
5687
5688 static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5689 afi_t afi, safi_t safi)
5690 {
5691 int ret;
5692 struct peer *peer;
5693
5694 peer = peer_and_group_lookup_vty(vty, ip_str);
5695 if (!peer)
5696 return CMD_WARNING_CONFIG_FAILED;
5697
5698 ret = peer_maximum_prefix_unset(peer, afi, safi);
5699
5700 return bgp_vty_return(vty, ret);
5701 }
5702
5703 /* Maximum number of prefix configuration. prefix count is different
5704 for each peer configuration. So this configuration can be set for
5705 each peer configuration. */
5706 DEFUN (neighbor_maximum_prefix,
5707 neighbor_maximum_prefix_cmd,
5708 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5709 NEIGHBOR_STR
5710 NEIGHBOR_ADDR_STR2
5711 "Maximum number of prefix accept from this peer\n"
5712 "maximum no. of prefix limit\n")
5713 {
5714 int idx_peer = 1;
5715 int idx_number = 3;
5716 return peer_maximum_prefix_set_vty(
5717 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5718 argv[idx_number]->arg, NULL, 0, NULL);
5719 }
5720
5721 ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5722 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5723 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5724 "Maximum number of prefix accept from this peer\n"
5725 "maximum no. of prefix limit\n")
5726
5727 DEFUN (neighbor_maximum_prefix_threshold,
5728 neighbor_maximum_prefix_threshold_cmd,
5729 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5730 NEIGHBOR_STR
5731 NEIGHBOR_ADDR_STR2
5732 "Maximum number of prefix accept from this peer\n"
5733 "maximum no. of prefix limit\n"
5734 "Threshold value (%) at which to generate a warning msg\n")
5735 {
5736 int idx_peer = 1;
5737 int idx_number = 3;
5738 int idx_number_2 = 4;
5739 return peer_maximum_prefix_set_vty(
5740 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5741 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
5742 }
5743
5744 ALIAS_HIDDEN(
5745 neighbor_maximum_prefix_threshold,
5746 neighbor_maximum_prefix_threshold_hidden_cmd,
5747 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5748 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5749 "Maximum number of prefix accept from this peer\n"
5750 "maximum no. of prefix limit\n"
5751 "Threshold value (%) at which to generate a warning msg\n")
5752
5753 DEFUN (neighbor_maximum_prefix_warning,
5754 neighbor_maximum_prefix_warning_cmd,
5755 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5756 NEIGHBOR_STR
5757 NEIGHBOR_ADDR_STR2
5758 "Maximum number of prefix accept from this peer\n"
5759 "maximum no. of prefix limit\n"
5760 "Only give warning message when limit is exceeded\n")
5761 {
5762 int idx_peer = 1;
5763 int idx_number = 3;
5764 return peer_maximum_prefix_set_vty(
5765 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5766 argv[idx_number]->arg, NULL, 1, NULL);
5767 }
5768
5769 ALIAS_HIDDEN(
5770 neighbor_maximum_prefix_warning,
5771 neighbor_maximum_prefix_warning_hidden_cmd,
5772 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5773 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5774 "Maximum number of prefix accept from this peer\n"
5775 "maximum no. of prefix limit\n"
5776 "Only give warning message when limit is exceeded\n")
5777
5778 DEFUN (neighbor_maximum_prefix_threshold_warning,
5779 neighbor_maximum_prefix_threshold_warning_cmd,
5780 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5781 NEIGHBOR_STR
5782 NEIGHBOR_ADDR_STR2
5783 "Maximum number of prefix accept from this peer\n"
5784 "maximum no. of prefix limit\n"
5785 "Threshold value (%) at which to generate a warning msg\n"
5786 "Only give warning message when limit is exceeded\n")
5787 {
5788 int idx_peer = 1;
5789 int idx_number = 3;
5790 int idx_number_2 = 4;
5791 return peer_maximum_prefix_set_vty(
5792 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5793 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5794 }
5795
5796 ALIAS_HIDDEN(
5797 neighbor_maximum_prefix_threshold_warning,
5798 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5799 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5800 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5801 "Maximum number of prefix accept from this peer\n"
5802 "maximum no. of prefix limit\n"
5803 "Threshold value (%) at which to generate a warning msg\n"
5804 "Only give warning message when limit is exceeded\n")
5805
5806 DEFUN (neighbor_maximum_prefix_restart,
5807 neighbor_maximum_prefix_restart_cmd,
5808 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5809 NEIGHBOR_STR
5810 NEIGHBOR_ADDR_STR2
5811 "Maximum number of prefix accept from this peer\n"
5812 "maximum no. of prefix limit\n"
5813 "Restart bgp connection after limit is exceeded\n"
5814 "Restart interval in minutes\n")
5815 {
5816 int idx_peer = 1;
5817 int idx_number = 3;
5818 int idx_number_2 = 5;
5819 return peer_maximum_prefix_set_vty(
5820 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5821 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5822 }
5823
5824 ALIAS_HIDDEN(
5825 neighbor_maximum_prefix_restart,
5826 neighbor_maximum_prefix_restart_hidden_cmd,
5827 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5828 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5829 "Maximum number of prefix accept from this peer\n"
5830 "maximum no. of prefix limit\n"
5831 "Restart bgp connection after limit is exceeded\n"
5832 "Restart interval in minutes\n")
5833
5834 DEFUN (neighbor_maximum_prefix_threshold_restart,
5835 neighbor_maximum_prefix_threshold_restart_cmd,
5836 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5837 NEIGHBOR_STR
5838 NEIGHBOR_ADDR_STR2
5839 "Maximum number of prefixes to accept from this peer\n"
5840 "maximum no. of prefix limit\n"
5841 "Threshold value (%) at which to generate a warning msg\n"
5842 "Restart bgp connection after limit is exceeded\n"
5843 "Restart interval in minutes\n")
5844 {
5845 int idx_peer = 1;
5846 int idx_number = 3;
5847 int idx_number_2 = 4;
5848 int idx_number_3 = 6;
5849 return peer_maximum_prefix_set_vty(
5850 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5851 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5852 argv[idx_number_3]->arg);
5853 }
5854
5855 ALIAS_HIDDEN(
5856 neighbor_maximum_prefix_threshold_restart,
5857 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5858 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5859 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5860 "Maximum number of prefixes to accept from this peer\n"
5861 "maximum no. of prefix limit\n"
5862 "Threshold value (%) at which to generate a warning msg\n"
5863 "Restart bgp connection after limit is exceeded\n"
5864 "Restart interval in minutes\n")
5865
5866 DEFUN (no_neighbor_maximum_prefix,
5867 no_neighbor_maximum_prefix_cmd,
5868 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5869 NO_STR
5870 NEIGHBOR_STR
5871 NEIGHBOR_ADDR_STR2
5872 "Maximum number of prefixes to accept from this peer\n"
5873 "maximum no. of prefix limit\n"
5874 "Threshold value (%) at which to generate a warning msg\n"
5875 "Restart bgp connection after limit is exceeded\n"
5876 "Restart interval in minutes\n"
5877 "Only give warning message when limit is exceeded\n")
5878 {
5879 int idx_peer = 2;
5880 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5881 bgp_node_afi(vty),
5882 bgp_node_safi(vty));
5883 }
5884
5885 ALIAS_HIDDEN(
5886 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5887 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5888 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5889 "Maximum number of prefixes to accept from this peer\n"
5890 "maximum no. of prefix limit\n"
5891 "Threshold value (%) at which to generate a warning msg\n"
5892 "Restart bgp connection after limit is exceeded\n"
5893 "Restart interval in minutes\n"
5894 "Only give warning message when limit is exceeded\n")
5895
5896
5897 /* "neighbor allowas-in" */
5898 DEFUN (neighbor_allowas_in,
5899 neighbor_allowas_in_cmd,
5900 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5901 NEIGHBOR_STR
5902 NEIGHBOR_ADDR_STR2
5903 "Accept as-path with my AS present in it\n"
5904 "Number of occurances of AS number\n"
5905 "Only accept my AS in the as-path if the route was originated in my AS\n")
5906 {
5907 int idx_peer = 1;
5908 int idx_number_origin = 3;
5909 int ret;
5910 int origin = 0;
5911 struct peer *peer;
5912 int allow_num = 0;
5913
5914 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5915 if (!peer)
5916 return CMD_WARNING_CONFIG_FAILED;
5917
5918 if (argc <= idx_number_origin)
5919 allow_num = 3;
5920 else {
5921 if (argv[idx_number_origin]->type == WORD_TKN)
5922 origin = 1;
5923 else
5924 allow_num = atoi(argv[idx_number_origin]->arg);
5925 }
5926
5927 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5928 allow_num, origin);
5929
5930 return bgp_vty_return(vty, ret);
5931 }
5932
5933 ALIAS_HIDDEN(
5934 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5935 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5936 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5937 "Accept as-path with my AS present in it\n"
5938 "Number of occurances of AS number\n"
5939 "Only accept my AS in the as-path if the route was originated in my AS\n")
5940
5941 DEFUN (no_neighbor_allowas_in,
5942 no_neighbor_allowas_in_cmd,
5943 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5944 NO_STR
5945 NEIGHBOR_STR
5946 NEIGHBOR_ADDR_STR2
5947 "allow local ASN appears in aspath attribute\n"
5948 "Number of occurances of AS number\n"
5949 "Only accept my AS in the as-path if the route was originated in my AS\n")
5950 {
5951 int idx_peer = 2;
5952 int ret;
5953 struct peer *peer;
5954
5955 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5956 if (!peer)
5957 return CMD_WARNING_CONFIG_FAILED;
5958
5959 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5960 bgp_node_safi(vty));
5961
5962 return bgp_vty_return(vty, ret);
5963 }
5964
5965 ALIAS_HIDDEN(
5966 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5967 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5968 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5969 "allow local ASN appears in aspath attribute\n"
5970 "Number of occurances of AS number\n"
5971 "Only accept my AS in the as-path if the route was originated in my AS\n")
5972
5973 DEFUN (neighbor_ttl_security,
5974 neighbor_ttl_security_cmd,
5975 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
5976 NEIGHBOR_STR
5977 NEIGHBOR_ADDR_STR2
5978 "BGP ttl-security parameters\n"
5979 "Specify the maximum number of hops to the BGP peer\n"
5980 "Number of hops to BGP peer\n")
5981 {
5982 int idx_peer = 1;
5983 int idx_number = 4;
5984 struct peer *peer;
5985 int gtsm_hops;
5986
5987 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5988 if (!peer)
5989 return CMD_WARNING_CONFIG_FAILED;
5990
5991 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
5992
5993 /*
5994 * If 'neighbor swpX', then this is for directly connected peers,
5995 * we should not accept a ttl-security hops value greater than 1.
5996 */
5997 if (peer->conf_if && (gtsm_hops > 1)) {
5998 vty_out(vty,
5999 "%s is directly connected peer, hops cannot exceed 1\n",
6000 argv[idx_peer]->arg);
6001 return CMD_WARNING_CONFIG_FAILED;
6002 }
6003
6004 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
6005 }
6006
6007 DEFUN (no_neighbor_ttl_security,
6008 no_neighbor_ttl_security_cmd,
6009 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
6010 NO_STR
6011 NEIGHBOR_STR
6012 NEIGHBOR_ADDR_STR2
6013 "BGP ttl-security parameters\n"
6014 "Specify the maximum number of hops to the BGP peer\n"
6015 "Number of hops to BGP peer\n")
6016 {
6017 int idx_peer = 2;
6018 struct peer *peer;
6019
6020 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6021 if (!peer)
6022 return CMD_WARNING_CONFIG_FAILED;
6023
6024 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
6025 }
6026
6027 DEFUN (neighbor_addpath_tx_all_paths,
6028 neighbor_addpath_tx_all_paths_cmd,
6029 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6030 NEIGHBOR_STR
6031 NEIGHBOR_ADDR_STR2
6032 "Use addpath to advertise all paths to a neighbor\n")
6033 {
6034 int idx_peer = 1;
6035 struct peer *peer;
6036
6037 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6038 if (!peer)
6039 return CMD_WARNING_CONFIG_FAILED;
6040
6041 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6042 bgp_node_safi(vty),
6043 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6044 }
6045
6046 ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6047 neighbor_addpath_tx_all_paths_hidden_cmd,
6048 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6049 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6050 "Use addpath to advertise all paths to a neighbor\n")
6051
6052 DEFUN (no_neighbor_addpath_tx_all_paths,
6053 no_neighbor_addpath_tx_all_paths_cmd,
6054 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6055 NO_STR
6056 NEIGHBOR_STR
6057 NEIGHBOR_ADDR_STR2
6058 "Use addpath to advertise all paths to a neighbor\n")
6059 {
6060 int idx_peer = 2;
6061 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6062 bgp_node_afi(vty), bgp_node_safi(vty),
6063 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6064 }
6065
6066 ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6067 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6068 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6069 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6070 "Use addpath to advertise all paths to a neighbor\n")
6071
6072 DEFUN (neighbor_addpath_tx_bestpath_per_as,
6073 neighbor_addpath_tx_bestpath_per_as_cmd,
6074 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6075 NEIGHBOR_STR
6076 NEIGHBOR_ADDR_STR2
6077 "Use addpath to advertise the bestpath per each neighboring AS\n")
6078 {
6079 int idx_peer = 1;
6080 struct peer *peer;
6081
6082 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6083 if (!peer)
6084 return CMD_WARNING_CONFIG_FAILED;
6085
6086 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6087 bgp_node_safi(vty),
6088 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6089 }
6090
6091 ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6092 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6093 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6094 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6095 "Use addpath to advertise the bestpath per each neighboring AS\n")
6096
6097 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6098 no_neighbor_addpath_tx_bestpath_per_as_cmd,
6099 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6100 NO_STR
6101 NEIGHBOR_STR
6102 NEIGHBOR_ADDR_STR2
6103 "Use addpath to advertise the bestpath per each neighboring AS\n")
6104 {
6105 int idx_peer = 2;
6106 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6107 bgp_node_afi(vty), bgp_node_safi(vty),
6108 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6109 }
6110
6111 ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6112 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6113 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6114 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6115 "Use addpath to advertise the bestpath per each neighboring AS\n")
6116
6117 DEFUN_NOSH (address_family_ipv4_safi,
6118 address_family_ipv4_safi_cmd,
6119 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
6120 "Enter Address Family command mode\n"
6121 "Address Family\n"
6122 BGP_SAFI_WITH_LABEL_HELP_STR)
6123 {
6124
6125 if (argc == 3) {
6126 VTY_DECLVAR_CONTEXT(bgp, bgp);
6127 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6128 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT &&
6129 safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6130 && safi != SAFI_EVPN) {
6131 vty_out(vty,
6132 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6133 return CMD_WARNING_CONFIG_FAILED;
6134 }
6135 vty->node = bgp_node_type(AFI_IP, safi);
6136 } else
6137 vty->node = BGP_IPV4_NODE;
6138
6139 return CMD_SUCCESS;
6140 }
6141
6142 DEFUN_NOSH (address_family_ipv6_safi,
6143 address_family_ipv6_safi_cmd,
6144 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
6145 "Enter Address Family command mode\n"
6146 "Address Family\n"
6147 BGP_SAFI_WITH_LABEL_HELP_STR)
6148 {
6149 if (argc == 3) {
6150 VTY_DECLVAR_CONTEXT(bgp, bgp);
6151 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6152 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT &&
6153 safi != SAFI_UNICAST && safi != SAFI_MULTICAST
6154 && safi != SAFI_EVPN) {
6155 vty_out(vty,
6156 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
6157 return CMD_WARNING_CONFIG_FAILED;
6158 }
6159 vty->node = bgp_node_type(AFI_IP6, safi);
6160 } else
6161 vty->node = BGP_IPV6_NODE;
6162
6163 return CMD_SUCCESS;
6164 }
6165
6166 #ifdef KEEP_OLD_VPN_COMMANDS
6167 DEFUN_NOSH (address_family_vpnv4,
6168 address_family_vpnv4_cmd,
6169 "address-family vpnv4 [unicast]",
6170 "Enter Address Family command mode\n"
6171 "Address Family\n"
6172 "Address Family modifier\n")
6173 {
6174 vty->node = BGP_VPNV4_NODE;
6175 return CMD_SUCCESS;
6176 }
6177
6178 DEFUN_NOSH (address_family_vpnv6,
6179 address_family_vpnv6_cmd,
6180 "address-family vpnv6 [unicast]",
6181 "Enter Address Family command mode\n"
6182 "Address Family\n"
6183 "Address Family modifier\n")
6184 {
6185 vty->node = BGP_VPNV6_NODE;
6186 return CMD_SUCCESS;
6187 }
6188 #endif
6189
6190 DEFUN_NOSH (address_family_evpn,
6191 address_family_evpn_cmd,
6192 "address-family l2vpn evpn",
6193 "Enter Address Family command mode\n"
6194 "Address Family\n"
6195 "Address Family modifier\n")
6196 {
6197 VTY_DECLVAR_CONTEXT(bgp, bgp);
6198 vty->node = BGP_EVPN_NODE;
6199 return CMD_SUCCESS;
6200 }
6201
6202 DEFUN_NOSH (exit_address_family,
6203 exit_address_family_cmd,
6204 "exit-address-family",
6205 "Exit from Address Family configuration mode\n")
6206 {
6207 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6208 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6209 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6210 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6211 || vty->node == BGP_EVPN_NODE)
6212 vty->node = BGP_NODE;
6213 return CMD_SUCCESS;
6214 }
6215
6216 /* Recalculate bestpath and re-advertise a prefix */
6217 static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6218 const char *ip_str, afi_t afi, safi_t safi,
6219 struct prefix_rd *prd)
6220 {
6221 int ret;
6222 struct prefix match;
6223 struct bgp_node *rn;
6224 struct bgp_node *rm;
6225 struct bgp *bgp;
6226 struct bgp_table *table;
6227 struct bgp_table *rib;
6228
6229 /* BGP structure lookup. */
6230 if (view_name) {
6231 bgp = bgp_lookup_by_name(view_name);
6232 if (bgp == NULL) {
6233 vty_out(vty, "%% Can't find BGP instance %s\n",
6234 view_name);
6235 return CMD_WARNING;
6236 }
6237 } else {
6238 bgp = bgp_get_default();
6239 if (bgp == NULL) {
6240 vty_out(vty, "%% No BGP process is configured\n");
6241 return CMD_WARNING;
6242 }
6243 }
6244
6245 /* Check IP address argument. */
6246 ret = str2prefix(ip_str, &match);
6247 if (!ret) {
6248 vty_out(vty, "%% address is malformed\n");
6249 return CMD_WARNING;
6250 }
6251
6252 match.family = afi2family(afi);
6253 rib = bgp->rib[afi][safi];
6254
6255 if (safi == SAFI_MPLS_VPN) {
6256 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6257 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6258 continue;
6259
6260 if ((table = rn->info) != NULL) {
6261 if ((rm = bgp_node_match(table, &match))
6262 != NULL) {
6263 if (rm->p.prefixlen
6264 == match.prefixlen) {
6265 SET_FLAG(rn->flags,
6266 BGP_NODE_USER_CLEAR);
6267 bgp_process(bgp, rm, afi, safi);
6268 }
6269 bgp_unlock_node(rm);
6270 }
6271 }
6272 }
6273 } else {
6274 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6275 if (rn->p.prefixlen == match.prefixlen) {
6276 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6277 bgp_process(bgp, rn, afi, safi);
6278 }
6279 bgp_unlock_node(rn);
6280 }
6281 }
6282
6283 return CMD_SUCCESS;
6284 }
6285
6286 /* one clear bgp command to rule them all */
6287 DEFUN (clear_ip_bgp_all,
6288 clear_ip_bgp_all_cmd,
6289 "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>]",
6290 CLEAR_STR
6291 IP_STR
6292 BGP_STR
6293 BGP_INSTANCE_HELP_STR
6294 BGP_AFI_HELP_STR
6295 BGP_SAFI_WITH_LABEL_HELP_STR
6296 "Clear all peers\n"
6297 "BGP neighbor address to clear\n"
6298 "BGP IPv6 neighbor to clear\n"
6299 "BGP neighbor on interface to clear\n"
6300 "Clear peers with the AS number\n"
6301 "Clear all external peers\n"
6302 "Clear all members of peer-group\n"
6303 "BGP peer-group name\n"
6304 BGP_SOFT_STR
6305 BGP_SOFT_IN_STR
6306 BGP_SOFT_OUT_STR
6307 BGP_SOFT_IN_STR
6308 "Push out prefix-list ORF and do inbound soft reconfig\n"
6309 BGP_SOFT_OUT_STR)
6310 {
6311 char *vrf = NULL;
6312
6313 afi_t afi = AFI_IP6;
6314 safi_t safi = SAFI_UNICAST;
6315 enum clear_sort clr_sort = clear_peer;
6316 enum bgp_clear_type clr_type;
6317 char *clr_arg = NULL;
6318
6319 int idx = 0;
6320
6321 /* clear [ip] bgp */
6322 if (argv_find(argv, argc, "ip", &idx))
6323 afi = AFI_IP;
6324
6325 /* [<view|vrf> VIEWVRFNAME] */
6326 if (argv_find(argv, argc, "view", &idx)
6327 || argv_find(argv, argc, "vrf", &idx)) {
6328 vrf = argv[idx + 1]->arg;
6329 idx += 2;
6330 }
6331
6332 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6333 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6334 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6335
6336 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6337 if (argv_find(argv, argc, "*", &idx)) {
6338 clr_sort = clear_all;
6339 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6340 clr_sort = clear_peer;
6341 clr_arg = argv[idx]->arg;
6342 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6343 clr_sort = clear_peer;
6344 clr_arg = argv[idx]->arg;
6345 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6346 clr_sort = clear_group;
6347 idx++;
6348 clr_arg = argv[idx]->arg;
6349 } else if (argv_find(argv, argc, "WORD", &idx)) {
6350 clr_sort = clear_peer;
6351 clr_arg = argv[idx]->arg;
6352 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6353 clr_sort = clear_as;
6354 clr_arg = argv[idx]->arg;
6355 } else if (argv_find(argv, argc, "external", &idx)) {
6356 clr_sort = clear_external;
6357 }
6358
6359 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6360 if (argv_find(argv, argc, "soft", &idx)) {
6361 if (argv_find(argv, argc, "in", &idx)
6362 || argv_find(argv, argc, "out", &idx))
6363 clr_type = strmatch(argv[idx]->text, "in")
6364 ? BGP_CLEAR_SOFT_IN
6365 : BGP_CLEAR_SOFT_OUT;
6366 else
6367 clr_type = BGP_CLEAR_SOFT_BOTH;
6368 } else if (argv_find(argv, argc, "in", &idx)) {
6369 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6370 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6371 : BGP_CLEAR_SOFT_IN;
6372 } else if (argv_find(argv, argc, "out", &idx)) {
6373 clr_type = BGP_CLEAR_SOFT_OUT;
6374 } else
6375 clr_type = BGP_CLEAR_SOFT_NONE;
6376
6377 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
6378 }
6379
6380 DEFUN (clear_ip_bgp_prefix,
6381 clear_ip_bgp_prefix_cmd,
6382 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
6383 CLEAR_STR
6384 IP_STR
6385 BGP_STR
6386 BGP_INSTANCE_HELP_STR
6387 "Clear bestpath and re-advertise\n"
6388 "IPv4 prefix\n")
6389 {
6390 char *vrf = NULL;
6391 char *prefix = NULL;
6392
6393 int idx = 0;
6394
6395 /* [<view|vrf> VIEWVRFNAME] */
6396 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
6397 vrf = argv[idx]->arg;
6398
6399 prefix = argv[argc - 1]->arg;
6400
6401 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
6402 }
6403
6404 DEFUN (clear_bgp_ipv6_safi_prefix,
6405 clear_bgp_ipv6_safi_prefix_cmd,
6406 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
6407 CLEAR_STR
6408 IP_STR
6409 BGP_STR
6410 "Address Family\n"
6411 BGP_SAFI_HELP_STR
6412 "Clear bestpath and re-advertise\n"
6413 "IPv6 prefix\n")
6414 {
6415 int idx_safi = 3;
6416 int idx_ipv6_prefixlen = 5;
6417 return bgp_clear_prefix(
6418 vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6419 bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
6420 }
6421
6422 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6423 clear_bgp_instance_ipv6_safi_prefix_cmd,
6424 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
6425 CLEAR_STR
6426 IP_STR
6427 BGP_STR
6428 BGP_INSTANCE_HELP_STR
6429 "Address Family\n"
6430 BGP_SAFI_HELP_STR
6431 "Clear bestpath and re-advertise\n"
6432 "IPv6 prefix\n")
6433 {
6434 int idx_word = 3;
6435 int idx_safi = 5;
6436 int idx_ipv6_prefixlen = 7;
6437 return bgp_clear_prefix(
6438 vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg,
6439 AFI_IP6, bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
6440 }
6441
6442 DEFUN (show_bgp_views,
6443 show_bgp_views_cmd,
6444 "show [ip] bgp views",
6445 SHOW_STR
6446 IP_STR
6447 BGP_STR
6448 "Show the defined BGP views\n")
6449 {
6450 struct list *inst = bm->bgp;
6451 struct listnode *node;
6452 struct bgp *bgp;
6453
6454 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6455 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6456 return CMD_WARNING;
6457 }
6458
6459 vty_out(vty, "Defined BGP views:\n");
6460 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6461 /* Skip VRFs. */
6462 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6463 continue;
6464 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6465 bgp->as);
6466 }
6467
6468 return CMD_SUCCESS;
6469 }
6470
6471 DEFUN (show_bgp_vrfs,
6472 show_bgp_vrfs_cmd,
6473 "show [ip] bgp vrfs [json]",
6474 SHOW_STR
6475 IP_STR
6476 BGP_STR
6477 "Show BGP VRFs\n"
6478 JSON_STR)
6479 {
6480 char buf[ETHER_ADDR_STRLEN];
6481 struct list *inst = bm->bgp;
6482 struct listnode *node;
6483 struct bgp *bgp;
6484 u_char uj = use_json(argc, argv);
6485 json_object *json = NULL;
6486 json_object *json_vrfs = NULL;
6487 int count = 0;
6488
6489 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6490 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6491 return CMD_WARNING;
6492 }
6493
6494 if (uj) {
6495 json = json_object_new_object();
6496 json_vrfs = json_object_new_object();
6497 }
6498
6499 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6500 const char *name, *type;
6501 struct peer *peer;
6502 struct listnode *node, *nnode;
6503 int peers_cfg, peers_estb;
6504 json_object *json_vrf = NULL;
6505
6506 /* Skip Views. */
6507 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6508 continue;
6509
6510 count++;
6511 if (!uj && count == 1)
6512 vty_out(vty,
6513 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
6514 "Type", "Id", "routerId", "#PeersVfg",
6515 "#PeersEstb", "Name", "L3-VNI", "Rmac");
6516
6517 peers_cfg = peers_estb = 0;
6518 if (uj)
6519 json_vrf = json_object_new_object();
6520
6521
6522 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6523 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6524 continue;
6525 peers_cfg++;
6526 if (peer->status == Established)
6527 peers_estb++;
6528 }
6529
6530 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
6531 name = "Default";
6532 type = "DFLT";
6533 } else {
6534 name = bgp->name;
6535 type = "VRF";
6536 }
6537
6538
6539 if (uj) {
6540 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 :
6541 (int64_t)bgp->vrf_id;
6542 json_object_string_add(json_vrf, "type", type);
6543 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
6544 json_object_string_add(json_vrf, "routerId",
6545 inet_ntoa(bgp->router_id));
6546 json_object_int_add(json_vrf, "numConfiguredPeers",
6547 peers_cfg);
6548 json_object_int_add(json_vrf, "numEstablishedPeers",
6549 peers_estb);
6550
6551 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
6552 json_object_string_add(json_vrf, "rmac",
6553 prefix_mac2str(&bgp->rmac, buf,
6554 sizeof(buf)));
6555 json_object_object_add(json_vrfs, name, json_vrf);
6556 } else
6557 vty_out(vty,
6558 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
6559 type, bgp->vrf_id == VRF_UNKNOWN ?
6560 -1 : (int)bgp->vrf_id,
6561 inet_ntoa(bgp->router_id),
6562 peers_cfg, peers_estb, name, bgp->l3vni,
6563 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
6564 }
6565
6566 if (uj) {
6567 json_object_object_add(json, "vrfs", json_vrfs);
6568
6569 json_object_int_add(json, "totalVrfs", count);
6570
6571 vty_out(vty, "%s\n", json_object_to_json_string_ext(
6572 json, JSON_C_TO_STRING_PRETTY));
6573 json_object_free(json);
6574 } else {
6575 if (count)
6576 vty_out(vty,
6577 "\nTotal number of VRFs (including default): %d\n",
6578 count);
6579 }
6580
6581 return CMD_SUCCESS;
6582 }
6583
6584 static void show_address_entry(struct hash_backet *backet, void *args)
6585 {
6586 struct vty *vty = (struct vty *)args;
6587 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
6588
6589 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
6590 addr->refcnt);
6591 }
6592
6593 static void show_tip_entry(struct hash_backet *backet, void *args)
6594 {
6595 struct vty *vty = (struct vty *)args;
6596 struct tip_addr *tip = (struct tip_addr *)backet->data;
6597
6598 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
6599 tip->refcnt);
6600 }
6601
6602 static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
6603 {
6604 vty_out(vty, "self nexthop database:\n");
6605 hash_iterate(bgp->address_hash,
6606 (void (*)(struct hash_backet *, void *))show_address_entry,
6607 vty);
6608
6609 vty_out(vty, "Tunnel-ip database:\n");
6610 hash_iterate(bgp->tip_hash,
6611 (void (*)(struct hash_backet *, void *))show_tip_entry,
6612 vty);
6613 }
6614
6615 DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
6616 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
6617 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
6618 "martian next-hops\n"
6619 "martian next-hop database\n")
6620 {
6621 struct bgp *bgp = NULL;
6622 int idx = 0;
6623
6624 if (argv_find(argv, argc, "view", &idx)
6625 || argv_find(argv, argc, "vrf", &idx))
6626 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
6627 else
6628 bgp = bgp_get_default();
6629
6630 if (!bgp) {
6631 vty_out(vty, "%% No BGP process is configured\n");
6632 return CMD_WARNING;
6633 }
6634 bgp_show_martian_nexthops(vty, bgp);
6635
6636 return CMD_SUCCESS;
6637 }
6638
6639 DEFUN (show_bgp_memory,
6640 show_bgp_memory_cmd,
6641 "show [ip] bgp memory",
6642 SHOW_STR
6643 IP_STR
6644 BGP_STR
6645 "Global BGP memory statistics\n")
6646 {
6647 char memstrbuf[MTYPE_MEMSTR_LEN];
6648 unsigned long count;
6649
6650 /* RIB related usage stats */
6651 count = mtype_stats_alloc(MTYPE_BGP_NODE);
6652 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
6653 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6654 count * sizeof(struct bgp_node)));
6655
6656 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
6657 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
6658 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6659 count * sizeof(struct bgp_info)));
6660 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
6661 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
6662 count,
6663 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6664 count * sizeof(struct bgp_info_extra)));
6665
6666 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
6667 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
6668 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6669 count * sizeof(struct bgp_static)));
6670
6671 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
6672 vty_out(vty, "%ld Packets, using %s of memory\n", count,
6673 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6674 count * sizeof(struct bpacket)));
6675
6676 /* Adj-In/Out */
6677 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
6678 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
6679 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6680 count * sizeof(struct bgp_adj_in)));
6681 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
6682 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
6683 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6684 count * sizeof(struct bgp_adj_out)));
6685
6686 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
6687 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
6688 count,
6689 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6690 count * sizeof(struct bgp_nexthop_cache)));
6691
6692 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
6693 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
6694 count,
6695 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6696 count * sizeof(struct bgp_damp_info)));
6697
6698 /* Attributes */
6699 count = attr_count();
6700 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
6701 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6702 count * sizeof(struct attr)));
6703
6704 if ((count = attr_unknown_count()))
6705 vty_out(vty, "%ld unknown attributes\n", count);
6706
6707 /* AS_PATH attributes */
6708 count = aspath_count();
6709 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
6710 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6711 count * sizeof(struct aspath)));
6712
6713 count = mtype_stats_alloc(MTYPE_AS_SEG);
6714 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
6715 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6716 count * sizeof(struct assegment)));
6717
6718 /* Other attributes */
6719 if ((count = community_count()))
6720 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
6721 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6722 count * sizeof(struct community)));
6723 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
6724 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
6725 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6726 count * sizeof(struct ecommunity)));
6727 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
6728 vty_out(vty,
6729 "%ld BGP large-community entries, using %s of memory\n",
6730 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6731 count * sizeof(struct lcommunity)));
6732
6733 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
6734 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
6735 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6736 count * sizeof(struct cluster_list)));
6737
6738 /* Peer related usage */
6739 count = mtype_stats_alloc(MTYPE_BGP_PEER);
6740 vty_out(vty, "%ld peers, using %s of memory\n", count,
6741 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6742 count * sizeof(struct peer)));
6743
6744 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
6745 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
6746 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6747 count * sizeof(struct peer_group)));
6748
6749 /* Other */
6750 if ((count = mtype_stats_alloc(MTYPE_HASH)))
6751 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
6752 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6753 count * sizeof(struct hash)));
6754 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
6755 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
6756 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6757 count * sizeof(struct hash_backet)));
6758 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
6759 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
6760 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6761 count * sizeof(regex_t)));
6762 return CMD_SUCCESS;
6763 }
6764
6765 static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
6766 {
6767 json_object *bestpath = json_object_new_object();
6768
6769 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
6770 json_object_string_add(bestpath, "asPath", "ignore");
6771
6772 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
6773 json_object_string_add(bestpath, "asPath", "confed");
6774
6775 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
6776 if (bgp_flag_check(bgp,
6777 BGP_FLAG_MULTIPATH_RELAX_AS_SET))
6778 json_object_string_add(bestpath,
6779 "multiPathRelax",
6780 "as-set");
6781 else
6782 json_object_string_add(bestpath,
6783 "multiPathRelax",
6784 "true");
6785 } else
6786 json_object_string_add(bestpath,
6787 "multiPathRelax",
6788 "false");
6789
6790 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
6791 json_object_string_add(bestpath, "compareRouterId", "true");
6792 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
6793 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
6794 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
6795 json_object_string_add(bestpath, "med",
6796 "confed");
6797 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
6798 json_object_string_add(bestpath, "med",
6799 "missing-as-worst");
6800 else
6801 json_object_string_add(bestpath, "med", "true");
6802 }
6803
6804 json_object_object_add(json, "bestPath", bestpath);
6805 }
6806
6807 /* Show BGP peer's summary information. */
6808 static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
6809 u_char use_json, json_object *json)
6810 {
6811 struct peer *peer;
6812 struct listnode *node, *nnode;
6813 unsigned int count = 0, dn_count = 0;
6814 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
6815 char neighbor_buf[VTY_BUFSIZ];
6816 int neighbor_col_default_width = 16;
6817 int len;
6818 int max_neighbor_width = 0;
6819 int pfx_rcd_safi;
6820 json_object *json_peer = NULL;
6821 json_object *json_peers = NULL;
6822
6823 /* labeled-unicast routes are installed in the unicast table so in order
6824 * to
6825 * display the correct PfxRcd value we must look at SAFI_UNICAST
6826 */
6827 if (safi == SAFI_LABELED_UNICAST)
6828 pfx_rcd_safi = SAFI_UNICAST;
6829 else
6830 pfx_rcd_safi = safi;
6831
6832 if (use_json) {
6833 if (json == NULL)
6834 json = json_object_new_object();
6835
6836 json_peers = json_object_new_object();
6837 } else {
6838 /* Loop over all neighbors that will be displayed to determine
6839 * how many
6840 * characters are needed for the Neighbor column
6841 */
6842 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6843 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6844 continue;
6845
6846 if (peer->afc[afi][safi]) {
6847 memset(dn_flag, '\0', sizeof(dn_flag));
6848 if (peer_dynamic_neighbor(peer))
6849 dn_flag[0] = '*';
6850
6851 if (peer->hostname
6852 && bgp_flag_check(bgp,
6853 BGP_FLAG_SHOW_HOSTNAME))
6854 sprintf(neighbor_buf, "%s%s(%s) ",
6855 dn_flag, peer->hostname,
6856 peer->host);
6857 else
6858 sprintf(neighbor_buf, "%s%s ", dn_flag,
6859 peer->host);
6860
6861 len = strlen(neighbor_buf);
6862
6863 if (len > max_neighbor_width)
6864 max_neighbor_width = len;
6865 }
6866 }
6867
6868 /* Originally we displayed the Neighbor column as 16
6869 * characters wide so make that the default
6870 */
6871 if (max_neighbor_width < neighbor_col_default_width)
6872 max_neighbor_width = neighbor_col_default_width;
6873 }
6874
6875 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6876 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6877 continue;
6878
6879 if (!peer->afc[afi][safi])
6880 continue;
6881
6882 if (!count) {
6883 unsigned long ents;
6884 char memstrbuf[MTYPE_MEMSTR_LEN];
6885 int64_t vrf_id_ui;
6886
6887 vrf_id_ui =
6888 (bgp->vrf_id == VRF_UNKNOWN) ? -1 :
6889 (int64_t)bgp->vrf_id;
6890
6891 /* Usage summary and header */
6892 if (use_json) {
6893 json_object_string_add(
6894 json, "routerId",
6895 inet_ntoa(bgp->router_id));
6896 json_object_int_add(json, "as", bgp->as);
6897 json_object_int_add(json, "vrfId", vrf_id_ui);
6898 json_object_string_add(
6899 json, "vrfName",
6900 (bgp->inst_type
6901 == BGP_INSTANCE_TYPE_DEFAULT)
6902 ? "Default"
6903 : bgp->name);
6904 } else {
6905 vty_out(vty,
6906 "BGP router identifier %s, local AS number %u vrf-id %d",
6907 inet_ntoa(bgp->router_id), bgp->as,
6908 bgp->vrf_id == VRF_UNKNOWN ? -1 :
6909 (int)bgp->vrf_id);
6910 vty_out(vty, "\n");
6911 }
6912
6913 if (bgp_update_delay_configured(bgp)) {
6914 if (use_json) {
6915 json_object_int_add(
6916 json, "updateDelayLimit",
6917 bgp->v_update_delay);
6918
6919 if (bgp->v_update_delay
6920 != bgp->v_establish_wait)
6921 json_object_int_add(
6922 json,
6923 "updateDelayEstablishWait",
6924 bgp->v_establish_wait);
6925
6926 if (bgp_update_delay_active(bgp)) {
6927 json_object_string_add(
6928 json,
6929 "updateDelayFirstNeighbor",
6930 bgp->update_delay_begin_time);
6931 json_object_boolean_true_add(
6932 json,
6933 "updateDelayInProgress");
6934 } else {
6935 if (bgp->update_delay_over) {
6936 json_object_string_add(
6937 json,
6938 "updateDelayFirstNeighbor",
6939 bgp->update_delay_begin_time);
6940 json_object_string_add(
6941 json,
6942 "updateDelayBestpathResumed",
6943 bgp->update_delay_end_time);
6944 json_object_string_add(
6945 json,
6946 "updateDelayZebraUpdateResume",
6947 bgp->update_delay_zebra_resume_time);
6948 json_object_string_add(
6949 json,
6950 "updateDelayPeerUpdateResume",
6951 bgp->update_delay_peers_resume_time);
6952 }
6953 }
6954 } else {
6955 vty_out(vty,
6956 "Read-only mode update-delay limit: %d seconds\n",
6957 bgp->v_update_delay);
6958 if (bgp->v_update_delay
6959 != bgp->v_establish_wait)
6960 vty_out(vty,
6961 " Establish wait: %d seconds\n",
6962 bgp->v_establish_wait);
6963
6964 if (bgp_update_delay_active(bgp)) {
6965 vty_out(vty,
6966 " First neighbor established: %s\n",
6967 bgp->update_delay_begin_time);
6968 vty_out(vty,
6969 " Delay in progress\n");
6970 } else {
6971 if (bgp->update_delay_over) {
6972 vty_out(vty,
6973 " First neighbor established: %s\n",
6974 bgp->update_delay_begin_time);
6975 vty_out(vty,
6976 " Best-paths resumed: %s\n",
6977 bgp->update_delay_end_time);
6978 vty_out(vty,
6979 " zebra update resumed: %s\n",
6980 bgp->update_delay_zebra_resume_time);
6981 vty_out(vty,
6982 " peers update resumed: %s\n",
6983 bgp->update_delay_peers_resume_time);
6984 }
6985 }
6986 }
6987 }
6988
6989 if (use_json) {
6990 if (bgp_maxmed_onstartup_configured(bgp)
6991 && bgp->maxmed_active)
6992 json_object_boolean_true_add(
6993 json, "maxMedOnStartup");
6994 if (bgp->v_maxmed_admin)
6995 json_object_boolean_true_add(
6996 json, "maxMedAdministrative");
6997
6998 json_object_int_add(
6999 json, "tableVersion",
7000 bgp_table_version(bgp->rib[afi][safi]));
7001
7002 ents = bgp_table_count(bgp->rib[afi][safi]);
7003 json_object_int_add(json, "ribCount", ents);
7004 json_object_int_add(
7005 json, "ribMemory",
7006 ents * sizeof(struct bgp_node));
7007
7008 ents = listcount(bgp->peer);
7009 json_object_int_add(json, "peerCount", ents);
7010 json_object_int_add(json, "peerMemory",
7011 ents * sizeof(struct peer));
7012
7013 if ((ents = listcount(bgp->group))) {
7014 json_object_int_add(
7015 json, "peerGroupCount", ents);
7016 json_object_int_add(
7017 json, "peerGroupMemory",
7018 ents * sizeof(struct
7019 peer_group));
7020 }
7021
7022 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7023 BGP_CONFIG_DAMPENING))
7024 json_object_boolean_true_add(
7025 json, "dampeningEnabled");
7026 } else {
7027 if (bgp_maxmed_onstartup_configured(bgp)
7028 && bgp->maxmed_active)
7029 vty_out(vty,
7030 "Max-med on-startup active\n");
7031 if (bgp->v_maxmed_admin)
7032 vty_out(vty,
7033 "Max-med administrative active\n");
7034
7035 vty_out(vty, "BGP table version %" PRIu64 "\n",
7036 bgp_table_version(bgp->rib[afi][safi]));
7037
7038 ents = bgp_table_count(bgp->rib[afi][safi]);
7039 vty_out(vty,
7040 "RIB entries %ld, using %s of memory\n",
7041 ents,
7042 mtype_memstr(memstrbuf,
7043 sizeof(memstrbuf),
7044 ents * sizeof(struct
7045 bgp_node)));
7046
7047 /* Peer related usage */
7048 ents = listcount(bgp->peer);
7049 vty_out(vty, "Peers %ld, using %s of memory\n",
7050 ents,
7051 mtype_memstr(
7052 memstrbuf, sizeof(memstrbuf),
7053 ents * sizeof(struct peer)));
7054
7055 if ((ents = listcount(bgp->group)))
7056 vty_out(vty,
7057 "Peer groups %ld, using %s of memory\n",
7058 ents,
7059 mtype_memstr(
7060 memstrbuf,
7061 sizeof(memstrbuf),
7062 ents * sizeof(struct
7063 peer_group)));
7064
7065 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7066 BGP_CONFIG_DAMPENING))
7067 vty_out(vty, "Dampening enabled.\n");
7068 vty_out(vty, "\n");
7069
7070 /* Subtract 8 here because 'Neighbor' is
7071 * 8 characters */
7072 vty_out(vty, "Neighbor");
7073 vty_out(vty, "%*s", max_neighbor_width - 8,
7074 " ");
7075 vty_out(vty,
7076 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
7077 }
7078 }
7079
7080 count++;
7081
7082 if (use_json) {
7083 json_peer = json_object_new_object();
7084
7085 if (peer_dynamic_neighbor(peer))
7086 json_object_boolean_true_add(json_peer,
7087 "dynamicPeer");
7088
7089 if (peer->hostname)
7090 json_object_string_add(json_peer, "hostname",
7091 peer->hostname);
7092
7093 if (peer->domainname)
7094 json_object_string_add(json_peer, "domainname",
7095 peer->domainname);
7096
7097 json_object_int_add(json_peer, "remoteAs", peer->as);
7098 json_object_int_add(json_peer, "version", 4);
7099 json_object_int_add(json_peer, "msgRcvd",
7100 PEER_TOTAL_RX(peer));
7101 json_object_int_add(json_peer, "msgSent",
7102 PEER_TOTAL_TX(peer));
7103
7104 json_object_int_add(json_peer, "tableVersion",
7105 peer->version[afi][safi]);
7106 json_object_int_add(json_peer, "outq",
7107 peer->obuf->count);
7108 json_object_int_add(json_peer, "inq", 0);
7109 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7110 use_json, json_peer);
7111 json_object_int_add(json_peer, "prefixReceivedCount",
7112 peer->pcount[afi][pfx_rcd_safi]);
7113
7114 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7115 json_object_string_add(json_peer, "state",
7116 "Idle (Admin)");
7117 else if (CHECK_FLAG(peer->sflags,
7118 PEER_STATUS_PREFIX_OVERFLOW))
7119 json_object_string_add(json_peer, "state",
7120 "Idle (PfxCt)");
7121 else
7122 json_object_string_add(
7123 json_peer, "state",
7124 lookup_msg(bgp_status_msg, peer->status,
7125 NULL));
7126
7127 if (peer->conf_if)
7128 json_object_string_add(json_peer, "idType",
7129 "interface");
7130 else if (peer->su.sa.sa_family == AF_INET)
7131 json_object_string_add(json_peer, "idType",
7132 "ipv4");
7133 else if (peer->su.sa.sa_family == AF_INET6)
7134 json_object_string_add(json_peer, "idType",
7135 "ipv6");
7136
7137 json_object_object_add(json_peers, peer->host,
7138 json_peer);
7139 } else {
7140 memset(dn_flag, '\0', sizeof(dn_flag));
7141 if (peer_dynamic_neighbor(peer)) {
7142 dn_count++;
7143 dn_flag[0] = '*';
7144 }
7145
7146 if (peer->hostname
7147 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7148 len = vty_out(vty, "%s%s(%s)", dn_flag,
7149 peer->hostname, peer->host);
7150 else
7151 len = vty_out(vty, "%s%s", dn_flag, peer->host);
7152
7153 /* pad the neighbor column with spaces */
7154 if (len < max_neighbor_width)
7155 vty_out(vty, "%*s", max_neighbor_width - len,
7156 " ");
7157
7158 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
7159 peer->as, PEER_TOTAL_RX(peer),
7160 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7161 0, peer->obuf->count,
7162 peer_uptime(peer->uptime, timebuf,
7163 BGP_UPTIME_LEN, 0, NULL));
7164
7165 if (peer->status == Established)
7166 if (peer->afc_recv[afi][pfx_rcd_safi])
7167 vty_out(vty, " %12ld",
7168 peer->pcount[afi][pfx_rcd_safi]);
7169 else
7170 vty_out(vty, " NoNeg");
7171 else {
7172 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
7173 vty_out(vty, " Idle (Admin)");
7174 else if (CHECK_FLAG(
7175 peer->sflags,
7176 PEER_STATUS_PREFIX_OVERFLOW))
7177 vty_out(vty, " Idle (PfxCt)");
7178 else
7179 vty_out(vty, " %12s",
7180 lookup_msg(bgp_status_msg,
7181 peer->status, NULL));
7182 }
7183 vty_out(vty, "\n");
7184 }
7185 }
7186
7187 if (use_json) {
7188 json_object_object_add(json, "peers", json_peers);
7189
7190 json_object_int_add(json, "totalPeers", count);
7191 json_object_int_add(json, "dynamicPeers", dn_count);
7192
7193 bgp_show_bestpath_json(bgp, json);
7194
7195 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7196 json, JSON_C_TO_STRING_PRETTY));
7197 json_object_free(json);
7198 } else {
7199 if (count)
7200 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7201 else {
7202 if (use_json)
7203 vty_out(vty,
7204 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7205 afi_safi_print(afi, safi));
7206 else
7207 vty_out(vty, "No %s neighbor is configured\n",
7208 afi_safi_print(afi, safi));
7209 }
7210
7211 if (dn_count && !use_json) {
7212 vty_out(vty, "* - dynamic neighbor\n");
7213 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7214 dn_count, bgp->dynamic_neighbors_limit);
7215 }
7216 }
7217
7218 return CMD_SUCCESS;
7219 }
7220
7221 static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7222 int safi, u_char use_json,
7223 json_object *json)
7224 {
7225 int is_first = 1;
7226 int afi_wildcard = (afi == AFI_MAX);
7227 int safi_wildcard = (safi == SAFI_MAX);
7228 int is_wildcard = (afi_wildcard || safi_wildcard);
7229 bool json_output = false;
7230
7231 if (use_json && is_wildcard)
7232 vty_out(vty, "{\n");
7233 if (afi_wildcard)
7234 afi = 1; /* AFI_IP */
7235 while (afi < AFI_MAX) {
7236 if (safi_wildcard)
7237 safi = 1; /* SAFI_UNICAST */
7238 while (safi < SAFI_MAX) {
7239 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
7240 json_output = true;
7241 if (is_wildcard) {
7242 /*
7243 * So limit output to those afi/safi
7244 * pairs that
7245 * actualy have something interesting in
7246 * them
7247 */
7248 if (use_json) {
7249 json = json_object_new_object();
7250
7251 if (!is_first)
7252 vty_out(vty, ",\n");
7253 else
7254 is_first = 0;
7255
7256 vty_out(vty, "\"%s\":",
7257 afi_safi_json(afi,
7258 safi));
7259 } else {
7260 vty_out(vty, "\n%s Summary:\n",
7261 afi_safi_print(afi,
7262 safi));
7263 }
7264 }
7265 bgp_show_summary(vty, bgp, afi, safi, use_json,
7266 json);
7267 }
7268 safi++;
7269 if (!safi_wildcard)
7270 safi = SAFI_MAX;
7271 }
7272 afi++;
7273 if (!afi_wildcard
7274 || afi == AFI_L2VPN) /* special case, not handled yet */
7275 afi = AFI_MAX;
7276 }
7277
7278 if (use_json && is_wildcard)
7279 vty_out(vty, "}\n");
7280 else if (use_json && !json_output)
7281 vty_out(vty, "{}\n");
7282 }
7283
7284 static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7285 safi_t safi, u_char use_json)
7286 {
7287 struct listnode *node, *nnode;
7288 struct bgp *bgp;
7289 json_object *json = NULL;
7290 int is_first = 1;
7291
7292 if (use_json)
7293 vty_out(vty, "{\n");
7294
7295 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
7296 if (use_json) {
7297 json = json_object_new_object();
7298
7299 if (!is_first)
7300 vty_out(vty, ",\n");
7301 else
7302 is_first = 0;
7303
7304 vty_out(vty, "\"%s\":",
7305 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7306 ? "Default"
7307 : bgp->name);
7308 } else {
7309 vty_out(vty, "\nInstance %s:\n",
7310 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7311 ? "Default"
7312 : bgp->name);
7313 }
7314 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7315 }
7316
7317 if (use_json)
7318 vty_out(vty, "}\n");
7319 }
7320
7321 int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7322 safi_t safi, u_char use_json)
7323 {
7324 struct bgp *bgp;
7325
7326 if (name) {
7327 if (strmatch(name, "all")) {
7328 bgp_show_all_instances_summary_vty(vty, afi, safi,
7329 use_json);
7330 return CMD_SUCCESS;
7331 } else {
7332 bgp = bgp_lookup_by_name(name);
7333
7334 if (!bgp) {
7335 if (use_json)
7336 vty_out(vty, "{}\n");
7337 else
7338 vty_out(vty,
7339 "%% No such BGP instance exist\n");
7340 return CMD_WARNING;
7341 }
7342
7343 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7344 NULL);
7345 return CMD_SUCCESS;
7346 }
7347 }
7348
7349 bgp = bgp_get_default();
7350
7351 if (bgp)
7352 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7353
7354 return CMD_SUCCESS;
7355 }
7356
7357 /* `show [ip] bgp summary' commands. */
7358 DEFUN (show_ip_bgp_summary,
7359 show_ip_bgp_summary_cmd,
7360 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
7361 SHOW_STR
7362 IP_STR
7363 BGP_STR
7364 BGP_INSTANCE_HELP_STR
7365 BGP_AFI_HELP_STR
7366 BGP_SAFI_WITH_LABEL_HELP_STR
7367 "Summary of BGP neighbor status\n"
7368 JSON_STR)
7369 {
7370 char *vrf = NULL;
7371 afi_t afi = AFI_MAX;
7372 safi_t safi = SAFI_MAX;
7373
7374 int idx = 0;
7375
7376 /* show [ip] bgp */
7377 if (argv_find(argv, argc, "ip", &idx))
7378 afi = AFI_IP;
7379 /* [<view|vrf> VIEWVRFNAME] */
7380 if (argv_find(argv, argc, "view", &idx)
7381 || argv_find(argv, argc, "vrf", &idx))
7382 vrf = argv[++idx]->arg;
7383 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7384 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7385 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7386 }
7387
7388 int uj = use_json(argc, argv);
7389
7390 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7391 }
7392
7393 const char *afi_safi_print(afi_t afi, safi_t safi)
7394 {
7395 if (afi == AFI_IP && safi == SAFI_UNICAST)
7396 return "IPv4 Unicast";
7397 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7398 return "IPv4 Multicast";
7399 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7400 return "IPv4 Labeled Unicast";
7401 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7402 return "IPv4 VPN";
7403 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7404 return "IPv4 Encap";
7405 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7406 return "IPv6 Unicast";
7407 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7408 return "IPv6 Multicast";
7409 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7410 return "IPv6 Labeled Unicast";
7411 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7412 return "IPv6 VPN";
7413 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7414 return "IPv6 Encap";
7415 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7416 return "L2VPN EVPN";
7417 else
7418 return "Unknown";
7419 }
7420
7421 /*
7422 * Please note that we have intentionally camelCased
7423 * the return strings here. So if you want
7424 * to use this function, please ensure you
7425 * are doing this within json output
7426 */
7427 const char *afi_safi_json(afi_t afi, safi_t safi)
7428 {
7429 if (afi == AFI_IP && safi == SAFI_UNICAST)
7430 return "ipv4Unicast";
7431 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7432 return "ipv4Multicast";
7433 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7434 return "ipv4LabeledUnicast";
7435 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7436 return "ipv4Vpn";
7437 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7438 return "ipv4Encap";
7439 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7440 return "ipv6Unicast";
7441 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7442 return "ipv6Multicast";
7443 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7444 return "ipv6LabeledUnicast";
7445 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7446 return "ipv6Vpn";
7447 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7448 return "ipv6Encap";
7449 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7450 return "l2VpnEvpn";
7451 else
7452 return "Unknown";
7453 }
7454
7455 /* Show BGP peer's information. */
7456 enum show_type { show_all, show_peer };
7457
7458 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7459 afi_t afi, safi_t safi,
7460 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7461 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7462 u_char use_json, json_object *json_pref)
7463 {
7464 /* Send-Mode */
7465 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7466 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7467 if (use_json) {
7468 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7469 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7470 json_object_string_add(json_pref, "sendMode",
7471 "advertisedAndReceived");
7472 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7473 json_object_string_add(json_pref, "sendMode",
7474 "advertised");
7475 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7476 json_object_string_add(json_pref, "sendMode",
7477 "received");
7478 } else {
7479 vty_out(vty, " Send-mode: ");
7480 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7481 vty_out(vty, "advertised");
7482 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7483 vty_out(vty, "%sreceived",
7484 CHECK_FLAG(p->af_cap[afi][safi],
7485 adv_smcap)
7486 ? ", "
7487 : "");
7488 vty_out(vty, "\n");
7489 }
7490 }
7491
7492 /* Receive-Mode */
7493 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7494 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
7495 if (use_json) {
7496 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7497 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7498 json_object_string_add(json_pref, "recvMode",
7499 "advertisedAndReceived");
7500 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7501 json_object_string_add(json_pref, "recvMode",
7502 "advertised");
7503 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7504 json_object_string_add(json_pref, "recvMode",
7505 "received");
7506 } else {
7507 vty_out(vty, " Receive-mode: ");
7508 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7509 vty_out(vty, "advertised");
7510 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7511 vty_out(vty, "%sreceived",
7512 CHECK_FLAG(p->af_cap[afi][safi],
7513 adv_rmcap)
7514 ? ", "
7515 : "");
7516 vty_out(vty, "\n");
7517 }
7518 }
7519 }
7520
7521 static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
7522 safi_t safi, u_char use_json,
7523 json_object *json_neigh)
7524 {
7525 struct bgp_filter *filter;
7526 struct peer_af *paf;
7527 char orf_pfx_name[BUFSIZ];
7528 int orf_pfx_count;
7529 json_object *json_af = NULL;
7530 json_object *json_prefA = NULL;
7531 json_object *json_prefB = NULL;
7532 json_object *json_addr = NULL;
7533
7534 if (use_json) {
7535 json_addr = json_object_new_object();
7536 json_af = json_object_new_object();
7537 filter = &p->filter[afi][safi];
7538
7539 if (peer_group_active(p))
7540 json_object_string_add(json_addr, "peerGroupMember",
7541 p->group->name);
7542
7543 paf = peer_af_find(p, afi, safi);
7544 if (paf && PAF_SUBGRP(paf)) {
7545 json_object_int_add(json_addr, "updateGroupId",
7546 PAF_UPDGRP(paf)->id);
7547 json_object_int_add(json_addr, "subGroupId",
7548 PAF_SUBGRP(paf)->id);
7549 json_object_int_add(json_addr, "packetQueueLength",
7550 bpacket_queue_virtual_length(paf));
7551 }
7552
7553 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7554 || CHECK_FLAG(p->af_cap[afi][safi],
7555 PEER_CAP_ORF_PREFIX_SM_RCV)
7556 || CHECK_FLAG(p->af_cap[afi][safi],
7557 PEER_CAP_ORF_PREFIX_RM_ADV)
7558 || CHECK_FLAG(p->af_cap[afi][safi],
7559 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7560 json_object_int_add(json_af, "orfType",
7561 ORF_TYPE_PREFIX);
7562 json_prefA = json_object_new_object();
7563 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
7564 PEER_CAP_ORF_PREFIX_SM_ADV,
7565 PEER_CAP_ORF_PREFIX_RM_ADV,
7566 PEER_CAP_ORF_PREFIX_SM_RCV,
7567 PEER_CAP_ORF_PREFIX_RM_RCV,
7568 use_json, json_prefA);
7569 json_object_object_add(json_af, "orfPrefixList",
7570 json_prefA);
7571 }
7572
7573 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7574 || CHECK_FLAG(p->af_cap[afi][safi],
7575 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7576 || CHECK_FLAG(p->af_cap[afi][safi],
7577 PEER_CAP_ORF_PREFIX_RM_ADV)
7578 || CHECK_FLAG(p->af_cap[afi][safi],
7579 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7580 json_object_int_add(json_af, "orfOldType",
7581 ORF_TYPE_PREFIX_OLD);
7582 json_prefB = json_object_new_object();
7583 bgp_show_peer_afi_orf_cap(
7584 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7585 PEER_CAP_ORF_PREFIX_RM_ADV,
7586 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7587 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
7588 json_prefB);
7589 json_object_object_add(json_af, "orfOldPrefixList",
7590 json_prefB);
7591 }
7592
7593 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7594 || CHECK_FLAG(p->af_cap[afi][safi],
7595 PEER_CAP_ORF_PREFIX_SM_RCV)
7596 || CHECK_FLAG(p->af_cap[afi][safi],
7597 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7598 || CHECK_FLAG(p->af_cap[afi][safi],
7599 PEER_CAP_ORF_PREFIX_RM_ADV)
7600 || CHECK_FLAG(p->af_cap[afi][safi],
7601 PEER_CAP_ORF_PREFIX_RM_RCV)
7602 || CHECK_FLAG(p->af_cap[afi][safi],
7603 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7604 json_object_object_add(json_addr, "afDependentCap",
7605 json_af);
7606 else
7607 json_object_free(json_af);
7608
7609 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7610 orf_pfx_count = prefix_bgp_show_prefix_list(
7611 NULL, afi, orf_pfx_name, use_json);
7612
7613 if (CHECK_FLAG(p->af_sflags[afi][safi],
7614 PEER_STATUS_ORF_PREFIX_SEND)
7615 || orf_pfx_count) {
7616 if (CHECK_FLAG(p->af_sflags[afi][safi],
7617 PEER_STATUS_ORF_PREFIX_SEND))
7618 json_object_boolean_true_add(json_neigh,
7619 "orfSent");
7620 if (orf_pfx_count)
7621 json_object_int_add(json_addr, "orfRecvCounter",
7622 orf_pfx_count);
7623 }
7624 if (CHECK_FLAG(p->af_sflags[afi][safi],
7625 PEER_STATUS_ORF_WAIT_REFRESH))
7626 json_object_string_add(
7627 json_addr, "orfFirstUpdate",
7628 "deferredUntilORFOrRouteRefreshRecvd");
7629
7630 if (CHECK_FLAG(p->af_flags[afi][safi],
7631 PEER_FLAG_REFLECTOR_CLIENT))
7632 json_object_boolean_true_add(json_addr,
7633 "routeReflectorClient");
7634 if (CHECK_FLAG(p->af_flags[afi][safi],
7635 PEER_FLAG_RSERVER_CLIENT))
7636 json_object_boolean_true_add(json_addr,
7637 "routeServerClient");
7638 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7639 json_object_boolean_true_add(json_addr,
7640 "inboundSoftConfigPermit");
7641
7642 if (CHECK_FLAG(p->af_flags[afi][safi],
7643 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7644 json_object_boolean_true_add(
7645 json_addr,
7646 "privateAsNumsAllReplacedInUpdatesToNbr");
7647 else if (CHECK_FLAG(p->af_flags[afi][safi],
7648 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7649 json_object_boolean_true_add(
7650 json_addr,
7651 "privateAsNumsReplacedInUpdatesToNbr");
7652 else if (CHECK_FLAG(p->af_flags[afi][safi],
7653 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7654 json_object_boolean_true_add(
7655 json_addr,
7656 "privateAsNumsAllRemovedInUpdatesToNbr");
7657 else if (CHECK_FLAG(p->af_flags[afi][safi],
7658 PEER_FLAG_REMOVE_PRIVATE_AS))
7659 json_object_boolean_true_add(
7660 json_addr,
7661 "privateAsNumsRemovedInUpdatesToNbr");
7662
7663 if (CHECK_FLAG(p->af_flags[afi][safi],
7664 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7665 json_object_boolean_true_add(json_addr,
7666 "addpathTxAllPaths");
7667
7668 if (CHECK_FLAG(p->af_flags[afi][safi],
7669 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7670 json_object_boolean_true_add(json_addr,
7671 "addpathTxBestpathPerAS");
7672
7673 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7674 json_object_string_add(json_addr,
7675 "overrideASNsInOutboundUpdates",
7676 "ifAspathEqualRemoteAs");
7677
7678 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7679 || CHECK_FLAG(p->af_flags[afi][safi],
7680 PEER_FLAG_FORCE_NEXTHOP_SELF))
7681 json_object_boolean_true_add(json_addr,
7682 "routerAlwaysNextHop");
7683 if (CHECK_FLAG(p->af_flags[afi][safi],
7684 PEER_FLAG_AS_PATH_UNCHANGED))
7685 json_object_boolean_true_add(
7686 json_addr, "unchangedAsPathPropogatedToNbr");
7687 if (CHECK_FLAG(p->af_flags[afi][safi],
7688 PEER_FLAG_NEXTHOP_UNCHANGED))
7689 json_object_boolean_true_add(
7690 json_addr, "unchangedNextHopPropogatedToNbr");
7691 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7692 json_object_boolean_true_add(
7693 json_addr, "unchangedMedPropogatedToNbr");
7694 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7695 || CHECK_FLAG(p->af_flags[afi][safi],
7696 PEER_FLAG_SEND_EXT_COMMUNITY)) {
7697 if (CHECK_FLAG(p->af_flags[afi][safi],
7698 PEER_FLAG_SEND_COMMUNITY)
7699 && CHECK_FLAG(p->af_flags[afi][safi],
7700 PEER_FLAG_SEND_EXT_COMMUNITY))
7701 json_object_string_add(json_addr,
7702 "commAttriSentToNbr",
7703 "extendedAndStandard");
7704 else if (CHECK_FLAG(p->af_flags[afi][safi],
7705 PEER_FLAG_SEND_EXT_COMMUNITY))
7706 json_object_string_add(json_addr,
7707 "commAttriSentToNbr",
7708 "extended");
7709 else
7710 json_object_string_add(json_addr,
7711 "commAttriSentToNbr",
7712 "standard");
7713 }
7714 if (CHECK_FLAG(p->af_flags[afi][safi],
7715 PEER_FLAG_DEFAULT_ORIGINATE)) {
7716 if (p->default_rmap[afi][safi].name)
7717 json_object_string_add(
7718 json_addr, "defaultRouteMap",
7719 p->default_rmap[afi][safi].name);
7720
7721 if (paf && PAF_SUBGRP(paf)
7722 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7723 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7724 json_object_boolean_true_add(json_addr,
7725 "defaultSent");
7726 else
7727 json_object_boolean_true_add(json_addr,
7728 "defaultNotSent");
7729 }
7730
7731 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
7732 if (is_evpn_enabled())
7733 json_object_boolean_true_add(
7734 json_addr, "advertiseAllVnis");
7735 }
7736
7737 if (filter->plist[FILTER_IN].name
7738 || filter->dlist[FILTER_IN].name
7739 || filter->aslist[FILTER_IN].name
7740 || filter->map[RMAP_IN].name)
7741 json_object_boolean_true_add(json_addr,
7742 "inboundPathPolicyConfig");
7743 if (filter->plist[FILTER_OUT].name
7744 || filter->dlist[FILTER_OUT].name
7745 || filter->aslist[FILTER_OUT].name
7746 || filter->map[RMAP_OUT].name || filter->usmap.name)
7747 json_object_boolean_true_add(
7748 json_addr, "outboundPathPolicyConfig");
7749
7750 /* prefix-list */
7751 if (filter->plist[FILTER_IN].name)
7752 json_object_string_add(json_addr,
7753 "incomingUpdatePrefixFilterList",
7754 filter->plist[FILTER_IN].name);
7755 if (filter->plist[FILTER_OUT].name)
7756 json_object_string_add(json_addr,
7757 "outgoingUpdatePrefixFilterList",
7758 filter->plist[FILTER_OUT].name);
7759
7760 /* distribute-list */
7761 if (filter->dlist[FILTER_IN].name)
7762 json_object_string_add(
7763 json_addr, "incomingUpdateNetworkFilterList",
7764 filter->dlist[FILTER_IN].name);
7765 if (filter->dlist[FILTER_OUT].name)
7766 json_object_string_add(
7767 json_addr, "outgoingUpdateNetworkFilterList",
7768 filter->dlist[FILTER_OUT].name);
7769
7770 /* filter-list. */
7771 if (filter->aslist[FILTER_IN].name)
7772 json_object_string_add(json_addr,
7773 "incomingUpdateAsPathFilterList",
7774 filter->aslist[FILTER_IN].name);
7775 if (filter->aslist[FILTER_OUT].name)
7776 json_object_string_add(json_addr,
7777 "outgoingUpdateAsPathFilterList",
7778 filter->aslist[FILTER_OUT].name);
7779
7780 /* route-map. */
7781 if (filter->map[RMAP_IN].name)
7782 json_object_string_add(
7783 json_addr, "routeMapForIncomingAdvertisements",
7784 filter->map[RMAP_IN].name);
7785 if (filter->map[RMAP_OUT].name)
7786 json_object_string_add(
7787 json_addr, "routeMapForOutgoingAdvertisements",
7788 filter->map[RMAP_OUT].name);
7789
7790 /* unsuppress-map */
7791 if (filter->usmap.name)
7792 json_object_string_add(json_addr,
7793 "selectiveUnsuppressRouteMap",
7794 filter->usmap.name);
7795
7796 /* Receive prefix count */
7797 json_object_int_add(json_addr, "acceptedPrefixCounter",
7798 p->pcount[afi][safi]);
7799
7800 /* Maximum prefix */
7801 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7802 json_object_int_add(json_addr, "prefixAllowedMax",
7803 p->pmax[afi][safi]);
7804 if (CHECK_FLAG(p->af_flags[afi][safi],
7805 PEER_FLAG_MAX_PREFIX_WARNING))
7806 json_object_boolean_true_add(
7807 json_addr, "prefixAllowedMaxWarning");
7808 json_object_int_add(json_addr,
7809 "prefixAllowedWarningThresh",
7810 p->pmax_threshold[afi][safi]);
7811 if (p->pmax_restart[afi][safi])
7812 json_object_int_add(
7813 json_addr,
7814 "prefixAllowedRestartIntervalMsecs",
7815 p->pmax_restart[afi][safi] * 60000);
7816 }
7817 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
7818 json_addr);
7819
7820 } else {
7821 filter = &p->filter[afi][safi];
7822
7823 vty_out(vty, " For address family: %s\n",
7824 afi_safi_print(afi, safi));
7825
7826 if (peer_group_active(p))
7827 vty_out(vty, " %s peer-group member\n",
7828 p->group->name);
7829
7830 paf = peer_af_find(p, afi, safi);
7831 if (paf && PAF_SUBGRP(paf)) {
7832 vty_out(vty, " Update group %" PRIu64
7833 ", subgroup %" PRIu64 "\n",
7834 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
7835 vty_out(vty, " Packet Queue length %d\n",
7836 bpacket_queue_virtual_length(paf));
7837 } else {
7838 vty_out(vty, " Not part of any update group\n");
7839 }
7840 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7841 || CHECK_FLAG(p->af_cap[afi][safi],
7842 PEER_CAP_ORF_PREFIX_SM_RCV)
7843 || CHECK_FLAG(p->af_cap[afi][safi],
7844 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7845 || CHECK_FLAG(p->af_cap[afi][safi],
7846 PEER_CAP_ORF_PREFIX_RM_ADV)
7847 || CHECK_FLAG(p->af_cap[afi][safi],
7848 PEER_CAP_ORF_PREFIX_RM_RCV)
7849 || CHECK_FLAG(p->af_cap[afi][safi],
7850 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7851 vty_out(vty, " AF-dependant capabilities:\n");
7852
7853 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7854 || CHECK_FLAG(p->af_cap[afi][safi],
7855 PEER_CAP_ORF_PREFIX_SM_RCV)
7856 || CHECK_FLAG(p->af_cap[afi][safi],
7857 PEER_CAP_ORF_PREFIX_RM_ADV)
7858 || CHECK_FLAG(p->af_cap[afi][safi],
7859 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7860 vty_out(vty,
7861 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7862 ORF_TYPE_PREFIX);
7863 bgp_show_peer_afi_orf_cap(
7864 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7865 PEER_CAP_ORF_PREFIX_RM_ADV,
7866 PEER_CAP_ORF_PREFIX_SM_RCV,
7867 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7868 }
7869 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7870 || CHECK_FLAG(p->af_cap[afi][safi],
7871 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7872 || CHECK_FLAG(p->af_cap[afi][safi],
7873 PEER_CAP_ORF_PREFIX_RM_ADV)
7874 || CHECK_FLAG(p->af_cap[afi][safi],
7875 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7876 vty_out(vty,
7877 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7878 ORF_TYPE_PREFIX_OLD);
7879 bgp_show_peer_afi_orf_cap(
7880 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7881 PEER_CAP_ORF_PREFIX_RM_ADV,
7882 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7883 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7884 }
7885
7886 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7887 orf_pfx_count = prefix_bgp_show_prefix_list(
7888 NULL, afi, orf_pfx_name, use_json);
7889
7890 if (CHECK_FLAG(p->af_sflags[afi][safi],
7891 PEER_STATUS_ORF_PREFIX_SEND)
7892 || orf_pfx_count) {
7893 vty_out(vty, " Outbound Route Filter (ORF):");
7894 if (CHECK_FLAG(p->af_sflags[afi][safi],
7895 PEER_STATUS_ORF_PREFIX_SEND))
7896 vty_out(vty, " sent;");
7897 if (orf_pfx_count)
7898 vty_out(vty, " received (%d entries)",
7899 orf_pfx_count);
7900 vty_out(vty, "\n");
7901 }
7902 if (CHECK_FLAG(p->af_sflags[afi][safi],
7903 PEER_STATUS_ORF_WAIT_REFRESH))
7904 vty_out(vty,
7905 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
7906
7907 if (CHECK_FLAG(p->af_flags[afi][safi],
7908 PEER_FLAG_REFLECTOR_CLIENT))
7909 vty_out(vty, " Route-Reflector Client\n");
7910 if (CHECK_FLAG(p->af_flags[afi][safi],
7911 PEER_FLAG_RSERVER_CLIENT))
7912 vty_out(vty, " Route-Server Client\n");
7913 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7914 vty_out(vty,
7915 " Inbound soft reconfiguration allowed\n");
7916
7917 if (CHECK_FLAG(p->af_flags[afi][safi],
7918 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7919 vty_out(vty,
7920 " Private AS numbers (all) replaced in updates to this neighbor\n");
7921 else if (CHECK_FLAG(p->af_flags[afi][safi],
7922 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7923 vty_out(vty,
7924 " Private AS numbers replaced in updates to this neighbor\n");
7925 else if (CHECK_FLAG(p->af_flags[afi][safi],
7926 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7927 vty_out(vty,
7928 " Private AS numbers (all) removed in updates to this neighbor\n");
7929 else if (CHECK_FLAG(p->af_flags[afi][safi],
7930 PEER_FLAG_REMOVE_PRIVATE_AS))
7931 vty_out(vty,
7932 " Private AS numbers removed in updates to this neighbor\n");
7933
7934 if (CHECK_FLAG(p->af_flags[afi][safi],
7935 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7936 vty_out(vty, " Advertise all paths via addpath\n");
7937
7938 if (CHECK_FLAG(p->af_flags[afi][safi],
7939 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7940 vty_out(vty,
7941 " Advertise bestpath per AS via addpath\n");
7942
7943 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7944 vty_out(vty,
7945 " Override ASNs in outbound updates if aspath equals remote-as\n");
7946
7947 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7948 || CHECK_FLAG(p->af_flags[afi][safi],
7949 PEER_FLAG_FORCE_NEXTHOP_SELF))
7950 vty_out(vty, " NEXT_HOP is always this router\n");
7951 if (CHECK_FLAG(p->af_flags[afi][safi],
7952 PEER_FLAG_AS_PATH_UNCHANGED))
7953 vty_out(vty,
7954 " AS_PATH is propagated unchanged to this neighbor\n");
7955 if (CHECK_FLAG(p->af_flags[afi][safi],
7956 PEER_FLAG_NEXTHOP_UNCHANGED))
7957 vty_out(vty,
7958 " NEXT_HOP is propagated unchanged to this neighbor\n");
7959 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7960 vty_out(vty,
7961 " MED is propagated unchanged to this neighbor\n");
7962 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7963 || CHECK_FLAG(p->af_flags[afi][safi],
7964 PEER_FLAG_SEND_EXT_COMMUNITY)
7965 || CHECK_FLAG(p->af_flags[afi][safi],
7966 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
7967 vty_out(vty,
7968 " Community attribute sent to this neighbor");
7969 if (CHECK_FLAG(p->af_flags[afi][safi],
7970 PEER_FLAG_SEND_COMMUNITY)
7971 && CHECK_FLAG(p->af_flags[afi][safi],
7972 PEER_FLAG_SEND_EXT_COMMUNITY)
7973 && CHECK_FLAG(p->af_flags[afi][safi],
7974 PEER_FLAG_SEND_LARGE_COMMUNITY))
7975 vty_out(vty, "(all)\n");
7976 else if (CHECK_FLAG(p->af_flags[afi][safi],
7977 PEER_FLAG_SEND_LARGE_COMMUNITY))
7978 vty_out(vty, "(large)\n");
7979 else if (CHECK_FLAG(p->af_flags[afi][safi],
7980 PEER_FLAG_SEND_EXT_COMMUNITY))
7981 vty_out(vty, "(extended)\n");
7982 else
7983 vty_out(vty, "(standard)\n");
7984 }
7985 if (CHECK_FLAG(p->af_flags[afi][safi],
7986 PEER_FLAG_DEFAULT_ORIGINATE)) {
7987 vty_out(vty, " Default information originate,");
7988
7989 if (p->default_rmap[afi][safi].name)
7990 vty_out(vty, " default route-map %s%s,",
7991 p->default_rmap[afi][safi].map ? "*"
7992 : "",
7993 p->default_rmap[afi][safi].name);
7994 if (paf && PAF_SUBGRP(paf)
7995 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7996 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7997 vty_out(vty, " default sent\n");
7998 else
7999 vty_out(vty, " default not sent\n");
8000 }
8001
8002 /* advertise-vni-all */
8003 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
8004 if (is_evpn_enabled())
8005 vty_out(vty, " advertise-all-vni\n");
8006 }
8007
8008 if (filter->plist[FILTER_IN].name
8009 || filter->dlist[FILTER_IN].name
8010 || filter->aslist[FILTER_IN].name
8011 || filter->map[RMAP_IN].name)
8012 vty_out(vty, " Inbound path policy configured\n");
8013 if (filter->plist[FILTER_OUT].name
8014 || filter->dlist[FILTER_OUT].name
8015 || filter->aslist[FILTER_OUT].name
8016 || filter->map[RMAP_OUT].name || filter->usmap.name)
8017 vty_out(vty, " Outbound path policy configured\n");
8018
8019 /* prefix-list */
8020 if (filter->plist[FILTER_IN].name)
8021 vty_out(vty,
8022 " Incoming update prefix filter list is %s%s\n",
8023 filter->plist[FILTER_IN].plist ? "*" : "",
8024 filter->plist[FILTER_IN].name);
8025 if (filter->plist[FILTER_OUT].name)
8026 vty_out(vty,
8027 " Outgoing update prefix filter list is %s%s\n",
8028 filter->plist[FILTER_OUT].plist ? "*" : "",
8029 filter->plist[FILTER_OUT].name);
8030
8031 /* distribute-list */
8032 if (filter->dlist[FILTER_IN].name)
8033 vty_out(vty,
8034 " Incoming update network filter list is %s%s\n",
8035 filter->dlist[FILTER_IN].alist ? "*" : "",
8036 filter->dlist[FILTER_IN].name);
8037 if (filter->dlist[FILTER_OUT].name)
8038 vty_out(vty,
8039 " Outgoing update network filter list is %s%s\n",
8040 filter->dlist[FILTER_OUT].alist ? "*" : "",
8041 filter->dlist[FILTER_OUT].name);
8042
8043 /* filter-list. */
8044 if (filter->aslist[FILTER_IN].name)
8045 vty_out(vty,
8046 " Incoming update AS path filter list is %s%s\n",
8047 filter->aslist[FILTER_IN].aslist ? "*" : "",
8048 filter->aslist[FILTER_IN].name);
8049 if (filter->aslist[FILTER_OUT].name)
8050 vty_out(vty,
8051 " Outgoing update AS path filter list is %s%s\n",
8052 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8053 filter->aslist[FILTER_OUT].name);
8054
8055 /* route-map. */
8056 if (filter->map[RMAP_IN].name)
8057 vty_out(vty,
8058 " Route map for incoming advertisements is %s%s\n",
8059 filter->map[RMAP_IN].map ? "*" : "",
8060 filter->map[RMAP_IN].name);
8061 if (filter->map[RMAP_OUT].name)
8062 vty_out(vty,
8063 " Route map for outgoing advertisements is %s%s\n",
8064 filter->map[RMAP_OUT].map ? "*" : "",
8065 filter->map[RMAP_OUT].name);
8066
8067 /* unsuppress-map */
8068 if (filter->usmap.name)
8069 vty_out(vty,
8070 " Route map for selective unsuppress is %s%s\n",
8071 filter->usmap.map ? "*" : "",
8072 filter->usmap.name);
8073
8074 /* Receive prefix count */
8075 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8076
8077 /* Maximum prefix */
8078 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8079 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8080 p->pmax[afi][safi],
8081 CHECK_FLAG(p->af_flags[afi][safi],
8082 PEER_FLAG_MAX_PREFIX_WARNING)
8083 ? " (warning-only)"
8084 : "");
8085 vty_out(vty, " Threshold for warning message %d%%",
8086 p->pmax_threshold[afi][safi]);
8087 if (p->pmax_restart[afi][safi])
8088 vty_out(vty, ", restart interval %d min",
8089 p->pmax_restart[afi][safi]);
8090 vty_out(vty, "\n");
8091 }
8092
8093 vty_out(vty, "\n");
8094 }
8095 }
8096
8097 static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
8098 json_object *json)
8099 {
8100 struct bgp *bgp;
8101 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8102 char timebuf[BGP_UPTIME_LEN];
8103 char dn_flag[2];
8104 const char *subcode_str;
8105 const char *code_str;
8106 afi_t afi;
8107 safi_t safi;
8108 u_int16_t i;
8109 u_char *msg;
8110 json_object *json_neigh = NULL;
8111 time_t epoch_tbuf;
8112
8113 bgp = p->bgp;
8114
8115 if (use_json)
8116 json_neigh = json_object_new_object();
8117
8118 memset(dn_flag, '\0', sizeof(dn_flag));
8119 if (!p->conf_if && peer_dynamic_neighbor(p))
8120 dn_flag[0] = '*';
8121
8122 if (!use_json) {
8123 if (p->conf_if) /* Configured interface name. */
8124 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8125 BGP_PEER_SU_UNSPEC(p)
8126 ? "None"
8127 : sockunion2str(&p->su, buf,
8128 SU_ADDRSTRLEN));
8129 else /* Configured IP address. */
8130 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8131 p->host);
8132 }
8133
8134 if (use_json) {
8135 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8136 json_object_string_add(json_neigh, "bgpNeighborAddr",
8137 "none");
8138 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8139 json_object_string_add(
8140 json_neigh, "bgpNeighborAddr",
8141 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8142
8143 json_object_int_add(json_neigh, "remoteAs", p->as);
8144
8145 if (p->change_local_as)
8146 json_object_int_add(json_neigh, "localAs",
8147 p->change_local_as);
8148 else
8149 json_object_int_add(json_neigh, "localAs", p->local_as);
8150
8151 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8152 json_object_boolean_true_add(json_neigh,
8153 "localAsNoPrepend");
8154
8155 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8156 json_object_boolean_true_add(json_neigh,
8157 "localAsReplaceAs");
8158 } else {
8159 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8160 || (p->as_type == AS_INTERNAL))
8161 vty_out(vty, "remote AS %u, ", p->as);
8162 else
8163 vty_out(vty, "remote AS Unspecified, ");
8164 vty_out(vty, "local AS %u%s%s, ",
8165 p->change_local_as ? p->change_local_as : p->local_as,
8166 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8167 ? " no-prepend"
8168 : "",
8169 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8170 ? " replace-as"
8171 : "");
8172 }
8173 /* peer type internal, external, confed-internal or confed-external */
8174 if (p->as == p->local_as) {
8175 if (use_json) {
8176 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8177 json_object_boolean_true_add(
8178 json_neigh, "nbrConfedInternalLink");
8179 else
8180 json_object_boolean_true_add(json_neigh,
8181 "nbrInternalLink");
8182 } else {
8183 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8184 vty_out(vty, "confed-internal link\n");
8185 else
8186 vty_out(vty, "internal link\n");
8187 }
8188 } else {
8189 if (use_json) {
8190 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8191 json_object_boolean_true_add(
8192 json_neigh, "nbrConfedExternalLink");
8193 else
8194 json_object_boolean_true_add(json_neigh,
8195 "nbrExternalLink");
8196 } else {
8197 if (bgp_confederation_peers_check(bgp, p->as))
8198 vty_out(vty, "confed-external link\n");
8199 else
8200 vty_out(vty, "external link\n");
8201 }
8202 }
8203
8204 /* Description. */
8205 if (p->desc) {
8206 if (use_json)
8207 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8208 else
8209 vty_out(vty, " Description: %s\n", p->desc);
8210 }
8211
8212 if (p->hostname) {
8213 if (use_json) {
8214 if (p->hostname)
8215 json_object_string_add(json_neigh, "hostname",
8216 p->hostname);
8217
8218 if (p->domainname)
8219 json_object_string_add(json_neigh, "domainname",
8220 p->domainname);
8221 } else {
8222 if (p->domainname && (p->domainname[0] != '\0'))
8223 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8224 p->domainname);
8225 else
8226 vty_out(vty, "Hostname: %s\n", p->hostname);
8227 }
8228 }
8229
8230 /* Peer-group */
8231 if (p->group) {
8232 if (use_json) {
8233 json_object_string_add(json_neigh, "peerGroup",
8234 p->group->name);
8235
8236 if (dn_flag[0]) {
8237 struct prefix prefix, *range = NULL;
8238
8239 sockunion2hostprefix(&(p->su), &prefix);
8240 range = peer_group_lookup_dynamic_neighbor_range(
8241 p->group, &prefix);
8242
8243 if (range) {
8244 prefix2str(range, buf1, sizeof(buf1));
8245 json_object_string_add(
8246 json_neigh,
8247 "peerSubnetRangeGroup", buf1);
8248 }
8249 }
8250 } else {
8251 vty_out(vty,
8252 " Member of peer-group %s for session parameters\n",
8253 p->group->name);
8254
8255 if (dn_flag[0]) {
8256 struct prefix prefix, *range = NULL;
8257
8258 sockunion2hostprefix(&(p->su), &prefix);
8259 range = peer_group_lookup_dynamic_neighbor_range(
8260 p->group, &prefix);
8261
8262 if (range) {
8263 prefix2str(range, buf1, sizeof(buf1));
8264 vty_out(vty,
8265 " Belongs to the subnet range group: %s\n",
8266 buf1);
8267 }
8268 }
8269 }
8270 }
8271
8272 if (use_json) {
8273 /* Administrative shutdown. */
8274 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8275 json_object_boolean_true_add(json_neigh,
8276 "adminShutDown");
8277
8278 /* BGP Version. */
8279 json_object_int_add(json_neigh, "bgpVersion", 4);
8280 json_object_string_add(
8281 json_neigh, "remoteRouterId",
8282 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8283
8284 /* Confederation */
8285 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8286 && bgp_confederation_peers_check(bgp, p->as))
8287 json_object_boolean_true_add(json_neigh,
8288 "nbrCommonAdmin");
8289
8290 /* Status. */
8291 json_object_string_add(
8292 json_neigh, "bgpState",
8293 lookup_msg(bgp_status_msg, p->status, NULL));
8294
8295 if (p->status == Established) {
8296 time_t uptime;
8297
8298 uptime = bgp_clock();
8299 uptime -= p->uptime;
8300 epoch_tbuf = time(NULL) - uptime;
8301
8302 #if CONFDATE > 20200101
8303 CPP_NOTICE("bgpTimerUp should be deprecated and can be removed now");
8304 #endif
8305 /*
8306 * bgpTimerUp was miliseconds that was accurate
8307 * up to 1 day, then the value returned
8308 * became garbage. So in order to provide
8309 * some level of backwards compatability,
8310 * we still provde the data, but now
8311 * we are returning the correct value
8312 * and also adding a new bgpTimerUpMsec
8313 * which will allow us to deprecate
8314 * this eventually
8315 */
8316 json_object_int_add(json_neigh, "bgpTimerUp",
8317 uptime * 1000);
8318 json_object_int_add(json_neigh, "bgpTimerUpMsec",
8319 uptime * 1000);
8320 json_object_string_add(json_neigh, "bgpTimerUpString",
8321 peer_uptime(p->uptime, timebuf,
8322 BGP_UPTIME_LEN, 0,
8323 NULL));
8324 json_object_int_add(json_neigh,
8325 "bgpTimerUpEstablishedEpoch",
8326 epoch_tbuf);
8327 }
8328
8329 else if (p->status == Active) {
8330 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8331 json_object_string_add(json_neigh, "bgpStateIs",
8332 "passive");
8333 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8334 json_object_string_add(json_neigh, "bgpStateIs",
8335 "passiveNSF");
8336 }
8337
8338 /* read timer */
8339 time_t uptime;
8340 struct tm *tm;
8341
8342 uptime = bgp_clock();
8343 uptime -= p->readtime;
8344 tm = gmtime(&uptime);
8345 json_object_int_add(json_neigh, "bgpTimerLastRead",
8346 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8347 + (tm->tm_hour * 3600000));
8348
8349 uptime = bgp_clock();
8350 uptime -= p->last_write;
8351 tm = gmtime(&uptime);
8352 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8353 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8354 + (tm->tm_hour * 3600000));
8355
8356 uptime = bgp_clock();
8357 uptime -= p->update_time;
8358 tm = gmtime(&uptime);
8359 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8360 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8361 + (tm->tm_hour * 3600000));
8362
8363 /* Configured timer values. */
8364 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8365 p->v_holdtime * 1000);
8366 json_object_int_add(json_neigh,
8367 "bgpTimerKeepAliveIntervalMsecs",
8368 p->v_keepalive * 1000);
8369
8370 if (PEER_OR_GROUP_TIMER_SET(p)) {
8371 json_object_int_add(json_neigh,
8372 "bgpTimerConfiguredHoldTimeMsecs",
8373 p->holdtime * 1000);
8374 json_object_int_add(
8375 json_neigh,
8376 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8377 p->keepalive * 1000);
8378 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8379 || (bgp->default_keepalive !=
8380 BGP_DEFAULT_KEEPALIVE)) {
8381 json_object_int_add(json_neigh,
8382 "bgpTimerConfiguredHoldTimeMsecs",
8383 bgp->default_holdtime);
8384 json_object_int_add(
8385 json_neigh,
8386 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8387 bgp->default_keepalive);
8388 }
8389 } else {
8390 /* Administrative shutdown. */
8391 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8392 vty_out(vty, " Administratively shut down\n");
8393
8394 /* BGP Version. */
8395 vty_out(vty, " BGP version 4");
8396 vty_out(vty, ", remote router ID %s\n",
8397 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8398
8399 /* Confederation */
8400 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8401 && bgp_confederation_peers_check(bgp, p->as))
8402 vty_out(vty,
8403 " Neighbor under common administration\n");
8404
8405 /* Status. */
8406 vty_out(vty, " BGP state = %s",
8407 lookup_msg(bgp_status_msg, p->status, NULL));
8408
8409 if (p->status == Established)
8410 vty_out(vty, ", up for %8s",
8411 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8412 0, NULL));
8413
8414 else if (p->status == Active) {
8415 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8416 vty_out(vty, " (passive)");
8417 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8418 vty_out(vty, " (NSF passive)");
8419 }
8420 vty_out(vty, "\n");
8421
8422 /* read timer */
8423 vty_out(vty, " Last read %s",
8424 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8425 NULL));
8426 vty_out(vty, ", Last write %s\n",
8427 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8428 NULL));
8429
8430 /* Configured timer values. */
8431 vty_out(vty,
8432 " Hold time is %d, keepalive interval is %d seconds\n",
8433 p->v_holdtime, p->v_keepalive);
8434 if (PEER_OR_GROUP_TIMER_SET(p)) {
8435 vty_out(vty, " Configured hold time is %d",
8436 p->holdtime);
8437 vty_out(vty, ", keepalive interval is %d seconds\n",
8438 p->keepalive);
8439 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8440 || (bgp->default_keepalive !=
8441 BGP_DEFAULT_KEEPALIVE)) {
8442 vty_out(vty, " Configured hold time is %d",
8443 bgp->default_holdtime);
8444 vty_out(vty, ", keepalive interval is %d seconds\n",
8445 bgp->default_keepalive);
8446 }
8447 }
8448 /* Capability. */
8449 if (p->status == Established) {
8450 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8451 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8452 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8453 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8454 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8455 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8456 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8457 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8458 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8459 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8460 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8461 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8462 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8463 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8464 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8465 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8466 if (use_json) {
8467 json_object *json_cap = NULL;
8468
8469 json_cap = json_object_new_object();
8470
8471 /* AS4 */
8472 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8473 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8474 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8475 && CHECK_FLAG(p->cap,
8476 PEER_CAP_AS4_RCV))
8477 json_object_string_add(
8478 json_cap, "4byteAs",
8479 "advertisedAndReceived");
8480 else if (CHECK_FLAG(p->cap,
8481 PEER_CAP_AS4_ADV))
8482 json_object_string_add(
8483 json_cap, "4byteAs",
8484 "advertised");
8485 else if (CHECK_FLAG(p->cap,
8486 PEER_CAP_AS4_RCV))
8487 json_object_string_add(
8488 json_cap, "4byteAs",
8489 "received");
8490 }
8491
8492 /* AddPath */
8493 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8494 || CHECK_FLAG(p->cap,
8495 PEER_CAP_ADDPATH_ADV)) {
8496 json_object *json_add = NULL;
8497 const char *print_store;
8498
8499 json_add = json_object_new_object();
8500
8501 FOREACH_AFI_SAFI (afi, safi) {
8502 json_object *json_sub = NULL;
8503 json_sub =
8504 json_object_new_object();
8505 print_store = afi_safi_print(
8506 afi, safi);
8507
8508 if (CHECK_FLAG(
8509 p->af_cap[afi]
8510 [safi],
8511 PEER_CAP_ADDPATH_AF_TX_ADV)
8512 || CHECK_FLAG(
8513 p->af_cap[afi]
8514 [safi],
8515 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8516 if (CHECK_FLAG(
8517 p->af_cap
8518 [afi]
8519 [safi],
8520 PEER_CAP_ADDPATH_AF_TX_ADV)
8521 && CHECK_FLAG(
8522 p->af_cap
8523 [afi]
8524 [safi],
8525 PEER_CAP_ADDPATH_AF_TX_RCV))
8526 json_object_boolean_true_add(
8527 json_sub,
8528 "txAdvertisedAndReceived");
8529 else if (
8530 CHECK_FLAG(
8531 p->af_cap
8532 [afi]
8533 [safi],
8534 PEER_CAP_ADDPATH_AF_TX_ADV))
8535 json_object_boolean_true_add(
8536 json_sub,
8537 "txAdvertised");
8538 else if (
8539 CHECK_FLAG(
8540 p->af_cap
8541 [afi]
8542 [safi],
8543 PEER_CAP_ADDPATH_AF_TX_RCV))
8544 json_object_boolean_true_add(
8545 json_sub,
8546 "txReceived");
8547 }
8548
8549 if (CHECK_FLAG(
8550 p->af_cap[afi]
8551 [safi],
8552 PEER_CAP_ADDPATH_AF_RX_ADV)
8553 || CHECK_FLAG(
8554 p->af_cap[afi]
8555 [safi],
8556 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8557 if (CHECK_FLAG(
8558 p->af_cap
8559 [afi]
8560 [safi],
8561 PEER_CAP_ADDPATH_AF_RX_ADV)
8562 && CHECK_FLAG(
8563 p->af_cap
8564 [afi]
8565 [safi],
8566 PEER_CAP_ADDPATH_AF_RX_RCV))
8567 json_object_boolean_true_add(
8568 json_sub,
8569 "rxAdvertisedAndReceived");
8570 else if (
8571 CHECK_FLAG(
8572 p->af_cap
8573 [afi]
8574 [safi],
8575 PEER_CAP_ADDPATH_AF_RX_ADV))
8576 json_object_boolean_true_add(
8577 json_sub,
8578 "rxAdvertised");
8579 else if (
8580 CHECK_FLAG(
8581 p->af_cap
8582 [afi]
8583 [safi],
8584 PEER_CAP_ADDPATH_AF_RX_RCV))
8585 json_object_boolean_true_add(
8586 json_sub,
8587 "rxReceived");
8588 }
8589
8590 if (CHECK_FLAG(
8591 p->af_cap[afi]
8592 [safi],
8593 PEER_CAP_ADDPATH_AF_TX_ADV)
8594 || CHECK_FLAG(
8595 p->af_cap[afi]
8596 [safi],
8597 PEER_CAP_ADDPATH_AF_TX_RCV)
8598 || CHECK_FLAG(
8599 p->af_cap[afi]
8600 [safi],
8601 PEER_CAP_ADDPATH_AF_RX_ADV)
8602 || CHECK_FLAG(
8603 p->af_cap[afi]
8604 [safi],
8605 PEER_CAP_ADDPATH_AF_RX_RCV))
8606 json_object_object_add(
8607 json_add,
8608 print_store,
8609 json_sub);
8610 else
8611 json_object_free(
8612 json_sub);
8613 }
8614
8615 json_object_object_add(
8616 json_cap, "addPath", json_add);
8617 }
8618
8619 /* Dynamic */
8620 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8621 || CHECK_FLAG(p->cap,
8622 PEER_CAP_DYNAMIC_ADV)) {
8623 if (CHECK_FLAG(p->cap,
8624 PEER_CAP_DYNAMIC_ADV)
8625 && CHECK_FLAG(p->cap,
8626 PEER_CAP_DYNAMIC_RCV))
8627 json_object_string_add(
8628 json_cap, "dynamic",
8629 "advertisedAndReceived");
8630 else if (CHECK_FLAG(
8631 p->cap,
8632 PEER_CAP_DYNAMIC_ADV))
8633 json_object_string_add(
8634 json_cap, "dynamic",
8635 "advertised");
8636 else if (CHECK_FLAG(
8637 p->cap,
8638 PEER_CAP_DYNAMIC_RCV))
8639 json_object_string_add(
8640 json_cap, "dynamic",
8641 "received");
8642 }
8643
8644 /* Extended nexthop */
8645 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8646 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8647 json_object *json_nxt = NULL;
8648 const char *print_store;
8649
8650
8651 if (CHECK_FLAG(p->cap,
8652 PEER_CAP_ENHE_ADV)
8653 && CHECK_FLAG(p->cap,
8654 PEER_CAP_ENHE_RCV))
8655 json_object_string_add(
8656 json_cap,
8657 "extendedNexthop",
8658 "advertisedAndReceived");
8659 else if (CHECK_FLAG(p->cap,
8660 PEER_CAP_ENHE_ADV))
8661 json_object_string_add(
8662 json_cap,
8663 "extendedNexthop",
8664 "advertised");
8665 else if (CHECK_FLAG(p->cap,
8666 PEER_CAP_ENHE_RCV))
8667 json_object_string_add(
8668 json_cap,
8669 "extendedNexthop",
8670 "received");
8671
8672 if (CHECK_FLAG(p->cap,
8673 PEER_CAP_ENHE_RCV)) {
8674 json_nxt =
8675 json_object_new_object();
8676
8677 for (safi = SAFI_UNICAST;
8678 safi < SAFI_MAX; safi++) {
8679 if (CHECK_FLAG(
8680 p->af_cap
8681 [AFI_IP]
8682 [safi],
8683 PEER_CAP_ENHE_AF_RCV)) {
8684 print_store = afi_safi_print(
8685 AFI_IP,
8686 safi);
8687 json_object_string_add(
8688 json_nxt,
8689 print_store,
8690 "recieved");
8691 }
8692 }
8693 json_object_object_add(
8694 json_cap,
8695 "extendedNexthopFamililesByPeer",
8696 json_nxt);
8697 }
8698 }
8699
8700 /* Route Refresh */
8701 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8702 || CHECK_FLAG(p->cap,
8703 PEER_CAP_REFRESH_NEW_RCV)
8704 || CHECK_FLAG(p->cap,
8705 PEER_CAP_REFRESH_OLD_RCV)) {
8706 if (CHECK_FLAG(p->cap,
8707 PEER_CAP_REFRESH_ADV)
8708 && (CHECK_FLAG(
8709 p->cap,
8710 PEER_CAP_REFRESH_NEW_RCV)
8711 || CHECK_FLAG(
8712 p->cap,
8713 PEER_CAP_REFRESH_OLD_RCV))) {
8714 if (CHECK_FLAG(
8715 p->cap,
8716 PEER_CAP_REFRESH_OLD_RCV)
8717 && CHECK_FLAG(
8718 p->cap,
8719 PEER_CAP_REFRESH_NEW_RCV))
8720 json_object_string_add(
8721 json_cap,
8722 "routeRefresh",
8723 "advertisedAndReceivedOldNew");
8724 else {
8725 if (CHECK_FLAG(
8726 p->cap,
8727 PEER_CAP_REFRESH_OLD_RCV))
8728 json_object_string_add(
8729 json_cap,
8730 "routeRefresh",
8731 "advertisedAndReceivedOld");
8732 else
8733 json_object_string_add(
8734 json_cap,
8735 "routeRefresh",
8736 "advertisedAndReceivedNew");
8737 }
8738 } else if (
8739 CHECK_FLAG(
8740 p->cap,
8741 PEER_CAP_REFRESH_ADV))
8742 json_object_string_add(
8743 json_cap,
8744 "routeRefresh",
8745 "advertised");
8746 else if (
8747 CHECK_FLAG(
8748 p->cap,
8749 PEER_CAP_REFRESH_NEW_RCV)
8750 || CHECK_FLAG(
8751 p->cap,
8752 PEER_CAP_REFRESH_OLD_RCV))
8753 json_object_string_add(
8754 json_cap,
8755 "routeRefresh",
8756 "received");
8757 }
8758
8759 /* Multiprotocol Extensions */
8760 json_object *json_multi = NULL;
8761 json_multi = json_object_new_object();
8762
8763 FOREACH_AFI_SAFI (afi, safi) {
8764 if (p->afc_adv[afi][safi]
8765 || p->afc_recv[afi][safi]) {
8766 json_object *json_exten = NULL;
8767 json_exten =
8768 json_object_new_object();
8769
8770 if (p->afc_adv[afi][safi]
8771 && p->afc_recv[afi][safi])
8772 json_object_boolean_true_add(
8773 json_exten,
8774 "advertisedAndReceived");
8775 else if (p->afc_adv[afi][safi])
8776 json_object_boolean_true_add(
8777 json_exten,
8778 "advertised");
8779 else if (p->afc_recv[afi][safi])
8780 json_object_boolean_true_add(
8781 json_exten,
8782 "received");
8783
8784 json_object_object_add(
8785 json_multi,
8786 afi_safi_print(afi,
8787 safi),
8788 json_exten);
8789 }
8790 }
8791 json_object_object_add(
8792 json_cap, "multiprotocolExtensions",
8793 json_multi);
8794
8795 /* Hostname capabilities */
8796 json_object *json_hname = NULL;
8797
8798 json_hname = json_object_new_object();
8799
8800 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
8801 json_object_string_add(
8802 json_hname, "advHostName",
8803 bgp->peer_self->hostname
8804 ? bgp->peer_self
8805 ->hostname
8806 : "n/a");
8807 json_object_string_add(
8808 json_hname, "advDomainName",
8809 bgp->peer_self->domainname
8810 ? bgp->peer_self
8811 ->domainname
8812 : "n/a");
8813 }
8814
8815
8816 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
8817 json_object_string_add(
8818 json_hname, "rcvHostName",
8819 p->hostname ? p->hostname
8820 : "n/a");
8821 json_object_string_add(
8822 json_hname, "rcvDomainName",
8823 p->domainname ? p->domainname
8824 : "n/a");
8825 }
8826
8827 json_object_object_add(json_cap, "hostName",
8828 json_hname);
8829
8830 /* Gracefull Restart */
8831 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
8832 || CHECK_FLAG(p->cap,
8833 PEER_CAP_RESTART_ADV)) {
8834 if (CHECK_FLAG(p->cap,
8835 PEER_CAP_RESTART_ADV)
8836 && CHECK_FLAG(p->cap,
8837 PEER_CAP_RESTART_RCV))
8838 json_object_string_add(
8839 json_cap,
8840 "gracefulRestart",
8841 "advertisedAndReceived");
8842 else if (CHECK_FLAG(
8843 p->cap,
8844 PEER_CAP_RESTART_ADV))
8845 json_object_string_add(
8846 json_cap,
8847 "gracefulRestartCapability",
8848 "advertised");
8849 else if (CHECK_FLAG(
8850 p->cap,
8851 PEER_CAP_RESTART_RCV))
8852 json_object_string_add(
8853 json_cap,
8854 "gracefulRestartCapability",
8855 "received");
8856
8857 if (CHECK_FLAG(p->cap,
8858 PEER_CAP_RESTART_RCV)) {
8859 int restart_af_count = 0;
8860 json_object *json_restart =
8861 NULL;
8862 json_restart =
8863 json_object_new_object();
8864
8865 json_object_int_add(
8866 json_cap,
8867 "gracefulRestartRemoteTimerMsecs",
8868 p->v_gr_restart * 1000);
8869
8870 FOREACH_AFI_SAFI (afi, safi) {
8871 if (CHECK_FLAG(
8872 p->af_cap
8873 [afi]
8874 [safi],
8875 PEER_CAP_RESTART_AF_RCV)) {
8876 json_object *
8877 json_sub =
8878 NULL;
8879 json_sub =
8880 json_object_new_object();
8881
8882 if (CHECK_FLAG(
8883 p->af_cap
8884 [afi]
8885 [safi],
8886 PEER_CAP_RESTART_AF_PRESERVE_RCV))
8887 json_object_boolean_true_add(
8888 json_sub,
8889 "preserved");
8890 restart_af_count++;
8891 json_object_object_add(
8892 json_restart,
8893 afi_safi_print(
8894 afi,
8895 safi),
8896 json_sub);
8897 }
8898 }
8899 if (!restart_af_count) {
8900 json_object_string_add(
8901 json_cap,
8902 "addressFamiliesByPeer",
8903 "none");
8904 json_object_free(
8905 json_restart);
8906 } else
8907 json_object_object_add(
8908 json_cap,
8909 "addressFamiliesByPeer",
8910 json_restart);
8911 }
8912 }
8913 json_object_object_add(json_neigh,
8914 "neighborCapabilities",
8915 json_cap);
8916 } else {
8917 vty_out(vty, " Neighbor capabilities:\n");
8918
8919 /* AS4 */
8920 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8921 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8922 vty_out(vty, " 4 Byte AS:");
8923 if (CHECK_FLAG(p->cap,
8924 PEER_CAP_AS4_ADV))
8925 vty_out(vty, " advertised");
8926 if (CHECK_FLAG(p->cap,
8927 PEER_CAP_AS4_RCV))
8928 vty_out(vty, " %sreceived",
8929 CHECK_FLAG(
8930 p->cap,
8931 PEER_CAP_AS4_ADV)
8932 ? "and "
8933 : "");
8934 vty_out(vty, "\n");
8935 }
8936
8937 /* AddPath */
8938 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8939 || CHECK_FLAG(p->cap,
8940 PEER_CAP_ADDPATH_ADV)) {
8941 vty_out(vty, " AddPath:\n");
8942
8943 FOREACH_AFI_SAFI (afi, safi) {
8944 if (CHECK_FLAG(
8945 p->af_cap[afi]
8946 [safi],
8947 PEER_CAP_ADDPATH_AF_TX_ADV)
8948 || CHECK_FLAG(
8949 p->af_cap[afi]
8950 [safi],
8951 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8952 vty_out(vty,
8953 " %s: TX ",
8954 afi_safi_print(
8955 afi,
8956 safi));
8957
8958 if (CHECK_FLAG(
8959 p->af_cap
8960 [afi]
8961 [safi],
8962 PEER_CAP_ADDPATH_AF_TX_ADV))
8963 vty_out(vty,
8964 "advertised %s",
8965 afi_safi_print(
8966 afi,
8967 safi));
8968
8969 if (CHECK_FLAG(
8970 p->af_cap
8971 [afi]
8972 [safi],
8973 PEER_CAP_ADDPATH_AF_TX_RCV))
8974 vty_out(vty,
8975 "%sreceived",
8976 CHECK_FLAG(
8977 p->af_cap
8978 [afi]
8979 [safi],
8980 PEER_CAP_ADDPATH_AF_TX_ADV)
8981 ? " and "
8982 : "");
8983
8984 vty_out(vty, "\n");
8985 }
8986
8987 if (CHECK_FLAG(
8988 p->af_cap[afi]
8989 [safi],
8990 PEER_CAP_ADDPATH_AF_RX_ADV)
8991 || CHECK_FLAG(
8992 p->af_cap[afi]
8993 [safi],
8994 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8995 vty_out(vty,
8996 " %s: RX ",
8997 afi_safi_print(
8998 afi,
8999 safi));
9000
9001 if (CHECK_FLAG(
9002 p->af_cap
9003 [afi]
9004 [safi],
9005 PEER_CAP_ADDPATH_AF_RX_ADV))
9006 vty_out(vty,
9007 "advertised %s",
9008 afi_safi_print(
9009 afi,
9010 safi));
9011
9012 if (CHECK_FLAG(
9013 p->af_cap
9014 [afi]
9015 [safi],
9016 PEER_CAP_ADDPATH_AF_RX_RCV))
9017 vty_out(vty,
9018 "%sreceived",
9019 CHECK_FLAG(
9020 p->af_cap
9021 [afi]
9022 [safi],
9023 PEER_CAP_ADDPATH_AF_RX_ADV)
9024 ? " and "
9025 : "");
9026
9027 vty_out(vty, "\n");
9028 }
9029 }
9030 }
9031
9032 /* Dynamic */
9033 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9034 || CHECK_FLAG(p->cap,
9035 PEER_CAP_DYNAMIC_ADV)) {
9036 vty_out(vty, " Dynamic:");
9037 if (CHECK_FLAG(p->cap,
9038 PEER_CAP_DYNAMIC_ADV))
9039 vty_out(vty, " advertised");
9040 if (CHECK_FLAG(p->cap,
9041 PEER_CAP_DYNAMIC_RCV))
9042 vty_out(vty, " %sreceived",
9043 CHECK_FLAG(
9044 p->cap,
9045 PEER_CAP_DYNAMIC_ADV)
9046 ? "and "
9047 : "");
9048 vty_out(vty, "\n");
9049 }
9050
9051 /* Extended nexthop */
9052 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9053 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9054 vty_out(vty, " Extended nexthop:");
9055 if (CHECK_FLAG(p->cap,
9056 PEER_CAP_ENHE_ADV))
9057 vty_out(vty, " advertised");
9058 if (CHECK_FLAG(p->cap,
9059 PEER_CAP_ENHE_RCV))
9060 vty_out(vty, " %sreceived",
9061 CHECK_FLAG(
9062 p->cap,
9063 PEER_CAP_ENHE_ADV)
9064 ? "and "
9065 : "");
9066 vty_out(vty, "\n");
9067
9068 if (CHECK_FLAG(p->cap,
9069 PEER_CAP_ENHE_RCV)) {
9070 vty_out(vty,
9071 " Address families by peer:\n ");
9072 for (safi = SAFI_UNICAST;
9073 safi < SAFI_MAX; safi++)
9074 if (CHECK_FLAG(
9075 p->af_cap
9076 [AFI_IP]
9077 [safi],
9078 PEER_CAP_ENHE_AF_RCV))
9079 vty_out(vty,
9080 " %s\n",
9081 afi_safi_print(
9082 AFI_IP,
9083 safi));
9084 }
9085 }
9086
9087 /* Route Refresh */
9088 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9089 || CHECK_FLAG(p->cap,
9090 PEER_CAP_REFRESH_NEW_RCV)
9091 || CHECK_FLAG(p->cap,
9092 PEER_CAP_REFRESH_OLD_RCV)) {
9093 vty_out(vty, " Route refresh:");
9094 if (CHECK_FLAG(p->cap,
9095 PEER_CAP_REFRESH_ADV))
9096 vty_out(vty, " advertised");
9097 if (CHECK_FLAG(p->cap,
9098 PEER_CAP_REFRESH_NEW_RCV)
9099 || CHECK_FLAG(
9100 p->cap,
9101 PEER_CAP_REFRESH_OLD_RCV))
9102 vty_out(vty, " %sreceived(%s)",
9103 CHECK_FLAG(
9104 p->cap,
9105 PEER_CAP_REFRESH_ADV)
9106 ? "and "
9107 : "",
9108 (CHECK_FLAG(
9109 p->cap,
9110 PEER_CAP_REFRESH_OLD_RCV)
9111 && CHECK_FLAG(
9112 p->cap,
9113 PEER_CAP_REFRESH_NEW_RCV))
9114 ? "old & new"
9115 : CHECK_FLAG(
9116 p->cap,
9117 PEER_CAP_REFRESH_OLD_RCV)
9118 ? "old"
9119 : "new");
9120
9121 vty_out(vty, "\n");
9122 }
9123
9124 /* Multiprotocol Extensions */
9125 FOREACH_AFI_SAFI (afi, safi)
9126 if (p->afc_adv[afi][safi]
9127 || p->afc_recv[afi][safi]) {
9128 vty_out(vty,
9129 " Address Family %s:",
9130 afi_safi_print(afi,
9131 safi));
9132 if (p->afc_adv[afi][safi])
9133 vty_out(vty,
9134 " advertised");
9135 if (p->afc_recv[afi][safi])
9136 vty_out(vty,
9137 " %sreceived",
9138 p->afc_adv[afi]
9139 [safi]
9140 ? "and "
9141 : "");
9142 vty_out(vty, "\n");
9143 }
9144
9145 /* Hostname capability */
9146 vty_out(vty, " Hostname Capability:");
9147
9148 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9149 vty_out(vty,
9150 " advertised (name: %s,domain name: %s)",
9151 bgp->peer_self->hostname
9152 ? bgp->peer_self
9153 ->hostname
9154 : "n/a",
9155 bgp->peer_self->domainname
9156 ? bgp->peer_self
9157 ->domainname
9158 : "n/a");
9159 } else {
9160 vty_out(vty, " not advertised");
9161 }
9162
9163 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9164 vty_out(vty,
9165 " received (name: %s,domain name: %s)",
9166 p->hostname ? p->hostname
9167 : "n/a",
9168 p->domainname ? p->domainname
9169 : "n/a");
9170 } else {
9171 vty_out(vty, " not received");
9172 }
9173
9174 vty_out(vty, "\n");
9175
9176 /* Gracefull Restart */
9177 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9178 || CHECK_FLAG(p->cap,
9179 PEER_CAP_RESTART_ADV)) {
9180 vty_out(vty,
9181 " Graceful Restart Capabilty:");
9182 if (CHECK_FLAG(p->cap,
9183 PEER_CAP_RESTART_ADV))
9184 vty_out(vty, " advertised");
9185 if (CHECK_FLAG(p->cap,
9186 PEER_CAP_RESTART_RCV))
9187 vty_out(vty, " %sreceived",
9188 CHECK_FLAG(
9189 p->cap,
9190 PEER_CAP_RESTART_ADV)
9191 ? "and "
9192 : "");
9193 vty_out(vty, "\n");
9194
9195 if (CHECK_FLAG(p->cap,
9196 PEER_CAP_RESTART_RCV)) {
9197 int restart_af_count = 0;
9198
9199 vty_out(vty,
9200 " Remote Restart timer is %d seconds\n",
9201 p->v_gr_restart);
9202 vty_out(vty,
9203 " Address families by peer:\n ");
9204
9205 FOREACH_AFI_SAFI (afi, safi)
9206 if (CHECK_FLAG(
9207 p->af_cap
9208 [afi]
9209 [safi],
9210 PEER_CAP_RESTART_AF_RCV)) {
9211 vty_out(vty,
9212 "%s%s(%s)",
9213 restart_af_count
9214 ? ", "
9215 : "",
9216 afi_safi_print(
9217 afi,
9218 safi),
9219 CHECK_FLAG(
9220 p->af_cap
9221 [afi]
9222 [safi],
9223 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9224 ? "preserved"
9225 : "not preserved");
9226 restart_af_count++;
9227 }
9228 if (!restart_af_count)
9229 vty_out(vty, "none");
9230 vty_out(vty, "\n");
9231 }
9232 }
9233 }
9234 }
9235 }
9236
9237 /* graceful restart information */
9238 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9239 || p->t_gr_stale) {
9240 json_object *json_grace = NULL;
9241 json_object *json_grace_send = NULL;
9242 json_object *json_grace_recv = NULL;
9243 int eor_send_af_count = 0;
9244 int eor_receive_af_count = 0;
9245
9246 if (use_json) {
9247 json_grace = json_object_new_object();
9248 json_grace_send = json_object_new_object();
9249 json_grace_recv = json_object_new_object();
9250
9251 if (p->status == Established) {
9252 FOREACH_AFI_SAFI (afi, safi) {
9253 if (CHECK_FLAG(p->af_sflags[afi][safi],
9254 PEER_STATUS_EOR_SEND)) {
9255 json_object_boolean_true_add(
9256 json_grace_send,
9257 afi_safi_print(afi,
9258 safi));
9259 eor_send_af_count++;
9260 }
9261 }
9262 FOREACH_AFI_SAFI (afi, safi) {
9263 if (CHECK_FLAG(
9264 p->af_sflags[afi][safi],
9265 PEER_STATUS_EOR_RECEIVED)) {
9266 json_object_boolean_true_add(
9267 json_grace_recv,
9268 afi_safi_print(afi,
9269 safi));
9270 eor_receive_af_count++;
9271 }
9272 }
9273 }
9274
9275 json_object_object_add(json_grace, "endOfRibSend",
9276 json_grace_send);
9277 json_object_object_add(json_grace, "endOfRibRecv",
9278 json_grace_recv);
9279
9280 if (p->t_gr_restart)
9281 json_object_int_add(json_grace,
9282 "gracefulRestartTimerMsecs",
9283 thread_timer_remain_second(
9284 p->t_gr_restart)
9285 * 1000);
9286
9287 if (p->t_gr_stale)
9288 json_object_int_add(
9289 json_grace,
9290 "gracefulStalepathTimerMsecs",
9291 thread_timer_remain_second(
9292 p->t_gr_stale)
9293 * 1000);
9294
9295 json_object_object_add(
9296 json_neigh, "gracefulRestartInfo", json_grace);
9297 } else {
9298 vty_out(vty, " Graceful restart informations:\n");
9299 if (p->status == Established) {
9300 vty_out(vty, " End-of-RIB send: ");
9301 FOREACH_AFI_SAFI (afi, safi) {
9302 if (CHECK_FLAG(p->af_sflags[afi][safi],
9303 PEER_STATUS_EOR_SEND)) {
9304 vty_out(vty, "%s%s",
9305 eor_send_af_count ? ", "
9306 : "",
9307 afi_safi_print(afi,
9308 safi));
9309 eor_send_af_count++;
9310 }
9311 }
9312 vty_out(vty, "\n");
9313 vty_out(vty, " End-of-RIB received: ");
9314 FOREACH_AFI_SAFI (afi, safi) {
9315 if (CHECK_FLAG(
9316 p->af_sflags[afi][safi],
9317 PEER_STATUS_EOR_RECEIVED)) {
9318 vty_out(vty, "%s%s",
9319 eor_receive_af_count
9320 ? ", "
9321 : "",
9322 afi_safi_print(afi,
9323 safi));
9324 eor_receive_af_count++;
9325 }
9326 }
9327 vty_out(vty, "\n");
9328 }
9329
9330 if (p->t_gr_restart)
9331 vty_out(vty,
9332 " The remaining time of restart timer is %ld\n",
9333 thread_timer_remain_second(
9334 p->t_gr_restart));
9335
9336 if (p->t_gr_stale)
9337 vty_out(vty,
9338 " The remaining time of stalepath timer is %ld\n",
9339 thread_timer_remain_second(
9340 p->t_gr_stale));
9341 }
9342 }
9343 if (use_json) {
9344 json_object *json_stat = NULL;
9345 json_stat = json_object_new_object();
9346 /* Packet counts. */
9347 json_object_int_add(json_stat, "depthInq", 0);
9348 json_object_int_add(json_stat, "depthOutq",
9349 (unsigned long)p->obuf->count);
9350 json_object_int_add(json_stat, "opensSent",
9351 atomic_load_explicit(&p->open_out,
9352 memory_order_relaxed));
9353 json_object_int_add(json_stat, "opensRecv",
9354 atomic_load_explicit(&p->open_in,
9355 memory_order_relaxed));
9356 json_object_int_add(json_stat, "notificationsSent",
9357 atomic_load_explicit(&p->notify_out,
9358 memory_order_relaxed));
9359 json_object_int_add(json_stat, "notificationsRecv",
9360 atomic_load_explicit(&p->notify_in,
9361 memory_order_relaxed));
9362 json_object_int_add(json_stat, "updatesSent",
9363 atomic_load_explicit(&p->update_out,
9364 memory_order_relaxed));
9365 json_object_int_add(json_stat, "updatesRecv",
9366 atomic_load_explicit(&p->update_in,
9367 memory_order_relaxed));
9368 json_object_int_add(json_stat, "keepalivesSent",
9369 atomic_load_explicit(&p->keepalive_out,
9370 memory_order_relaxed));
9371 json_object_int_add(json_stat, "keepalivesRecv",
9372 atomic_load_explicit(&p->keepalive_in,
9373 memory_order_relaxed));
9374 json_object_int_add(json_stat, "routeRefreshSent",
9375 atomic_load_explicit(&p->refresh_out,
9376 memory_order_relaxed));
9377 json_object_int_add(json_stat, "routeRefreshRecv",
9378 atomic_load_explicit(&p->refresh_in,
9379 memory_order_relaxed));
9380 json_object_int_add(json_stat, "capabilitySent",
9381 atomic_load_explicit(&p->dynamic_cap_out,
9382 memory_order_relaxed));
9383 json_object_int_add(json_stat, "capabilityRecv",
9384 atomic_load_explicit(&p->dynamic_cap_in,
9385 memory_order_relaxed));
9386 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
9387 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
9388 json_object_object_add(json_neigh, "messageStats", json_stat);
9389 } else {
9390 /* Packet counts. */
9391 vty_out(vty, " Message statistics:\n");
9392 vty_out(vty, " Inq depth is 0\n");
9393 vty_out(vty, " Outq depth is %lu\n",
9394 (unsigned long)p->obuf->count);
9395 vty_out(vty, " Sent Rcvd\n");
9396 vty_out(vty, " Opens: %10d %10d\n",
9397 atomic_load_explicit(&p->open_out,
9398 memory_order_relaxed),
9399 atomic_load_explicit(&p->open_in,
9400 memory_order_relaxed));
9401 vty_out(vty, " Notifications: %10d %10d\n",
9402 atomic_load_explicit(&p->notify_out,
9403 memory_order_relaxed),
9404 atomic_load_explicit(&p->notify_in,
9405 memory_order_relaxed));
9406 vty_out(vty, " Updates: %10d %10d\n",
9407 atomic_load_explicit(&p->update_out,
9408 memory_order_relaxed),
9409 atomic_load_explicit(&p->update_in,
9410 memory_order_relaxed));
9411 vty_out(vty, " Keepalives: %10d %10d\n",
9412 atomic_load_explicit(&p->keepalive_out,
9413 memory_order_relaxed),
9414 atomic_load_explicit(&p->keepalive_in,
9415 memory_order_relaxed));
9416 vty_out(vty, " Route Refresh: %10d %10d\n",
9417 atomic_load_explicit(&p->refresh_out,
9418 memory_order_relaxed),
9419 atomic_load_explicit(&p->refresh_in,
9420 memory_order_relaxed));
9421 vty_out(vty, " Capability: %10d %10d\n",
9422 atomic_load_explicit(&p->dynamic_cap_out,
9423 memory_order_relaxed),
9424 atomic_load_explicit(&p->dynamic_cap_in,
9425 memory_order_relaxed));
9426 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
9427 PEER_TOTAL_RX(p));
9428 }
9429
9430 if (use_json) {
9431 /* advertisement-interval */
9432 json_object_int_add(json_neigh,
9433 "minBtwnAdvertisementRunsTimerMsecs",
9434 p->v_routeadv * 1000);
9435
9436 /* Update-source. */
9437 if (p->update_if || p->update_source) {
9438 if (p->update_if)
9439 json_object_string_add(json_neigh,
9440 "updateSource",
9441 p->update_if);
9442 else if (p->update_source)
9443 json_object_string_add(
9444 json_neigh, "updateSource",
9445 sockunion2str(p->update_source, buf1,
9446 SU_ADDRSTRLEN));
9447 }
9448 } else {
9449 /* advertisement-interval */
9450 vty_out(vty,
9451 " Minimum time between advertisement runs is %d seconds\n",
9452 p->v_routeadv);
9453
9454 /* Update-source. */
9455 if (p->update_if || p->update_source) {
9456 vty_out(vty, " Update source is ");
9457 if (p->update_if)
9458 vty_out(vty, "%s", p->update_if);
9459 else if (p->update_source)
9460 vty_out(vty, "%s",
9461 sockunion2str(p->update_source, buf1,
9462 SU_ADDRSTRLEN));
9463 vty_out(vty, "\n");
9464 }
9465
9466 vty_out(vty, "\n");
9467 }
9468
9469 /* Address Family Information */
9470 json_object *json_hold = NULL;
9471
9472 if (use_json)
9473 json_hold = json_object_new_object();
9474
9475 FOREACH_AFI_SAFI (afi, safi)
9476 if (p->afc[afi][safi])
9477 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9478 json_hold);
9479
9480 if (use_json) {
9481 json_object_object_add(json_neigh, "addressFamilyInfo",
9482 json_hold);
9483 json_object_int_add(json_neigh, "connectionsEstablished",
9484 p->established);
9485 json_object_int_add(json_neigh, "connectionsDropped",
9486 p->dropped);
9487 } else
9488 vty_out(vty, " Connections established %d; dropped %d\n",
9489 p->established, p->dropped);
9490
9491 if (!p->last_reset) {
9492 if (use_json)
9493 json_object_string_add(json_neigh, "lastReset",
9494 "never");
9495 else
9496 vty_out(vty, " Last reset never\n");
9497 } else {
9498 if (use_json) {
9499 time_t uptime;
9500 struct tm *tm;
9501
9502 uptime = bgp_clock();
9503 uptime -= p->resettime;
9504 tm = gmtime(&uptime);
9505 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9506 (tm->tm_sec * 1000)
9507 + (tm->tm_min * 60000)
9508 + (tm->tm_hour * 3600000));
9509 json_object_string_add(
9510 json_neigh, "lastResetDueTo",
9511 peer_down_str[(int)p->last_reset]);
9512 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9513 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9514 char errorcodesubcode_hexstr[5];
9515 char errorcodesubcode_str[256];
9516
9517 code_str = bgp_notify_code_str(p->notify.code);
9518 subcode_str = bgp_notify_subcode_str(
9519 p->notify.code, p->notify.subcode);
9520
9521 sprintf(errorcodesubcode_hexstr, "%02X%02X",
9522 p->notify.code, p->notify.subcode);
9523 json_object_string_add(json_neigh,
9524 "lastErrorCodeSubcode",
9525 errorcodesubcode_hexstr);
9526 snprintf(errorcodesubcode_str, 255, "%s%s",
9527 code_str, subcode_str);
9528 json_object_string_add(json_neigh,
9529 "lastNotificationReason",
9530 errorcodesubcode_str);
9531 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9532 && p->notify.code == BGP_NOTIFY_CEASE
9533 && (p->notify.subcode
9534 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9535 || p->notify.subcode
9536 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9537 && p->notify.length) {
9538 char msgbuf[1024];
9539 const char *msg_str;
9540
9541 msg_str = bgp_notify_admin_message(
9542 msgbuf, sizeof(msgbuf),
9543 (u_char *)p->notify.data,
9544 p->notify.length);
9545 if (msg_str)
9546 json_object_string_add(
9547 json_neigh,
9548 "lastShutdownDescription",
9549 msg_str);
9550 }
9551 }
9552 } else {
9553 vty_out(vty, " Last reset %s, ",
9554 peer_uptime(p->resettime, timebuf,
9555 BGP_UPTIME_LEN, 0, NULL));
9556
9557 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9558 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9559 code_str = bgp_notify_code_str(p->notify.code);
9560 subcode_str = bgp_notify_subcode_str(
9561 p->notify.code, p->notify.subcode);
9562 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
9563 p->last_reset == PEER_DOWN_NOTIFY_SEND
9564 ? "sent"
9565 : "received",
9566 code_str, subcode_str);
9567 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9568 && p->notify.code == BGP_NOTIFY_CEASE
9569 && (p->notify.subcode
9570 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9571 || p->notify.subcode
9572 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9573 && p->notify.length) {
9574 char msgbuf[1024];
9575 const char *msg_str;
9576
9577 msg_str = bgp_notify_admin_message(
9578 msgbuf, sizeof(msgbuf),
9579 (u_char *)p->notify.data,
9580 p->notify.length);
9581 if (msg_str)
9582 vty_out(vty,
9583 " Message: \"%s\"\n",
9584 msg_str);
9585 }
9586 } else {
9587 vty_out(vty, "due to %s\n",
9588 peer_down_str[(int)p->last_reset]);
9589 }
9590
9591 if (p->last_reset_cause_size) {
9592 msg = p->last_reset_cause;
9593 vty_out(vty,
9594 " Message received that caused BGP to send a NOTIFICATION:\n ");
9595 for (i = 1; i <= p->last_reset_cause_size;
9596 i++) {
9597 vty_out(vty, "%02X", *msg++);
9598
9599 if (i != p->last_reset_cause_size) {
9600 if (i % 16 == 0) {
9601 vty_out(vty, "\n ");
9602 } else if (i % 4 == 0) {
9603 vty_out(vty, " ");
9604 }
9605 }
9606 }
9607 vty_out(vty, "\n");
9608 }
9609 }
9610 }
9611
9612 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
9613 if (use_json)
9614 json_object_boolean_true_add(json_neigh,
9615 "prefixesConfigExceedMax");
9616 else
9617 vty_out(vty,
9618 " Peer had exceeded the max. no. of prefixes configured.\n");
9619
9620 if (p->t_pmax_restart) {
9621 if (use_json) {
9622 json_object_boolean_true_add(
9623 json_neigh, "reducePrefixNumFrom");
9624 json_object_int_add(json_neigh,
9625 "restartInTimerMsec",
9626 thread_timer_remain_second(
9627 p->t_pmax_restart)
9628 * 1000);
9629 } else
9630 vty_out(vty,
9631 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
9632 p->host, thread_timer_remain_second(
9633 p->t_pmax_restart));
9634 } else {
9635 if (use_json)
9636 json_object_boolean_true_add(
9637 json_neigh,
9638 "reducePrefixNumAndClearIpBgp");
9639 else
9640 vty_out(vty,
9641 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
9642 p->host);
9643 }
9644 }
9645
9646 /* EBGP Multihop and GTSM */
9647 if (p->sort != BGP_PEER_IBGP) {
9648 if (use_json) {
9649 if (p->gtsm_hops > 0)
9650 json_object_int_add(json_neigh,
9651 "externalBgpNbrMaxHopsAway",
9652 p->gtsm_hops);
9653 else if (p->ttl > 1)
9654 json_object_int_add(json_neigh,
9655 "externalBgpNbrMaxHopsAway",
9656 p->ttl);
9657 } else {
9658 if (p->gtsm_hops > 0)
9659 vty_out(vty,
9660 " External BGP neighbor may be up to %d hops away.\n",
9661 p->gtsm_hops);
9662 else if (p->ttl > 1)
9663 vty_out(vty,
9664 " External BGP neighbor may be up to %d hops away.\n",
9665 p->ttl);
9666 }
9667 } else {
9668 if (p->gtsm_hops > 0) {
9669 if (use_json)
9670 json_object_int_add(json_neigh,
9671 "internalBgpNbrMaxHopsAway",
9672 p->gtsm_hops);
9673 else
9674 vty_out(vty,
9675 " Internal BGP neighbor may be up to %d hops away.\n",
9676 p->gtsm_hops);
9677 }
9678 }
9679
9680 /* Local address. */
9681 if (p->su_local) {
9682 if (use_json) {
9683 json_object_string_add(json_neigh, "hostLocal",
9684 sockunion2str(p->su_local, buf1,
9685 SU_ADDRSTRLEN));
9686 json_object_int_add(json_neigh, "portLocal",
9687 ntohs(p->su_local->sin.sin_port));
9688 } else
9689 vty_out(vty, "Local host: %s, Local port: %d\n",
9690 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
9691 ntohs(p->su_local->sin.sin_port));
9692 }
9693
9694 /* Remote address. */
9695 if (p->su_remote) {
9696 if (use_json) {
9697 json_object_string_add(json_neigh, "hostForeign",
9698 sockunion2str(p->su_remote, buf1,
9699 SU_ADDRSTRLEN));
9700 json_object_int_add(json_neigh, "portForeign",
9701 ntohs(p->su_remote->sin.sin_port));
9702 } else
9703 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
9704 sockunion2str(p->su_remote, buf1,
9705 SU_ADDRSTRLEN),
9706 ntohs(p->su_remote->sin.sin_port));
9707 }
9708
9709 /* Nexthop display. */
9710 if (p->su_local) {
9711 if (use_json) {
9712 json_object_string_add(json_neigh, "nexthop",
9713 inet_ntop(AF_INET,
9714 &p->nexthop.v4, buf1,
9715 sizeof(buf1)));
9716 json_object_string_add(json_neigh, "nexthopGlobal",
9717 inet_ntop(AF_INET6,
9718 &p->nexthop.v6_global,
9719 buf1, sizeof(buf1)));
9720 json_object_string_add(json_neigh, "nexthopLocal",
9721 inet_ntop(AF_INET6,
9722 &p->nexthop.v6_local,
9723 buf1, sizeof(buf1)));
9724 if (p->shared_network)
9725 json_object_string_add(json_neigh,
9726 "bgpConnection",
9727 "sharedNetwork");
9728 else
9729 json_object_string_add(json_neigh,
9730 "bgpConnection",
9731 "nonSharedNetwork");
9732 } else {
9733 vty_out(vty, "Nexthop: %s\n",
9734 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
9735 sizeof(buf1)));
9736 vty_out(vty, "Nexthop global: %s\n",
9737 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
9738 sizeof(buf1)));
9739 vty_out(vty, "Nexthop local: %s\n",
9740 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
9741 sizeof(buf1)));
9742 vty_out(vty, "BGP connection: %s\n",
9743 p->shared_network ? "shared network"
9744 : "non shared network");
9745 }
9746 }
9747
9748 /* Timer information. */
9749 if (use_json) {
9750 json_object_int_add(json_neigh, "connectRetryTimer",
9751 p->v_connect);
9752 if (p->status == Established && p->rtt)
9753 json_object_int_add(json_neigh, "estimatedRttInMsecs",
9754 p->rtt);
9755 if (p->t_start)
9756 json_object_int_add(
9757 json_neigh, "nextStartTimerDueInMsecs",
9758 thread_timer_remain_second(p->t_start) * 1000);
9759 if (p->t_connect)
9760 json_object_int_add(
9761 json_neigh, "nextConnectTimerDueInMsecs",
9762 thread_timer_remain_second(p->t_connect)
9763 * 1000);
9764 if (p->t_routeadv) {
9765 json_object_int_add(json_neigh, "mraiInterval",
9766 p->v_routeadv);
9767 json_object_int_add(
9768 json_neigh, "mraiTimerExpireInMsecs",
9769 thread_timer_remain_second(p->t_routeadv)
9770 * 1000);
9771 }
9772 if (p->password)
9773 json_object_int_add(json_neigh, "authenticationEnabled",
9774 1);
9775
9776 if (p->t_read)
9777 json_object_string_add(json_neigh, "readThread", "on");
9778 else
9779 json_object_string_add(json_neigh, "readThread", "off");
9780
9781 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
9782 json_object_string_add(json_neigh, "writeThread", "on");
9783 else
9784 json_object_string_add(json_neigh, "writeThread",
9785 "off");
9786 } else {
9787 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
9788 p->v_connect);
9789 if (p->status == Established && p->rtt)
9790 vty_out(vty, "Estimated round trip time: %d ms\n",
9791 p->rtt);
9792 if (p->t_start)
9793 vty_out(vty, "Next start timer due in %ld seconds\n",
9794 thread_timer_remain_second(p->t_start));
9795 if (p->t_connect)
9796 vty_out(vty, "Next connect timer due in %ld seconds\n",
9797 thread_timer_remain_second(p->t_connect));
9798 if (p->t_routeadv)
9799 vty_out(vty,
9800 "MRAI (interval %u) timer expires in %ld seconds\n",
9801 p->v_routeadv,
9802 thread_timer_remain_second(p->t_routeadv));
9803 if (p->password)
9804 vty_out(vty, "Peer Authentication Enabled\n");
9805
9806 vty_out(vty, "Read thread: %s Write thread: %s\n",
9807 p->t_read ? "on" : "off",
9808 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
9809 ? "on"
9810 : "off");
9811 }
9812
9813 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9814 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
9815 bgp_capability_vty_out(vty, p, use_json, json_neigh);
9816
9817 if (!use_json)
9818 vty_out(vty, "\n");
9819
9820 /* BFD information. */
9821 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9822
9823 if (use_json) {
9824 if (p->conf_if) /* Configured interface name. */
9825 json_object_object_add(json, p->conf_if, json_neigh);
9826 else /* Configured IP address. */
9827 json_object_object_add(json, p->host, json_neigh);
9828 }
9829 }
9830
9831 static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
9832 enum show_type type, union sockunion *su,
9833 const char *conf_if, u_char use_json,
9834 json_object *json)
9835 {
9836 struct listnode *node, *nnode;
9837 struct peer *peer;
9838 int find = 0;
9839
9840 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9841 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9842 continue;
9843
9844 switch (type) {
9845 case show_all:
9846 bgp_show_peer(vty, peer, use_json, json);
9847 break;
9848 case show_peer:
9849 if (conf_if) {
9850 if ((peer->conf_if
9851 && !strcmp(peer->conf_if, conf_if))
9852 || (peer->hostname
9853 && !strcmp(peer->hostname, conf_if))) {
9854 find = 1;
9855 bgp_show_peer(vty, peer, use_json,
9856 json);
9857 }
9858 } else {
9859 if (sockunion_same(&peer->su, su)) {
9860 find = 1;
9861 bgp_show_peer(vty, peer, use_json,
9862 json);
9863 }
9864 }
9865 break;
9866 }
9867 }
9868
9869 if (type == show_peer && !find) {
9870 if (use_json)
9871 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9872 else
9873 vty_out(vty, "%% No such neighbor\n");
9874 }
9875
9876 if (use_json) {
9877 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9878 json, JSON_C_TO_STRING_PRETTY));
9879 json_object_free(json);
9880 } else {
9881 vty_out(vty, "\n");
9882 }
9883
9884 return CMD_SUCCESS;
9885 }
9886
9887 static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
9888 enum show_type type,
9889 const char *ip_str,
9890 u_char use_json)
9891 {
9892 struct listnode *node, *nnode;
9893 struct bgp *bgp;
9894 union sockunion su;
9895 json_object *json = NULL;
9896 int ret, is_first = 1;
9897
9898 if (use_json)
9899 vty_out(vty, "{\n");
9900
9901 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9902 if (use_json) {
9903 if (!(json = json_object_new_object())) {
9904 zlog_err(
9905 "Unable to allocate memory for JSON object");
9906 vty_out(vty,
9907 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
9908 return;
9909 }
9910
9911 json_object_int_add(json, "vrfId",
9912 (bgp->vrf_id == VRF_UNKNOWN)
9913 ? -1 : (int64_t) bgp->vrf_id);
9914 json_object_string_add(
9915 json, "vrfName",
9916 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9917 ? "Default"
9918 : bgp->name);
9919
9920 if (!is_first)
9921 vty_out(vty, ",\n");
9922 else
9923 is_first = 0;
9924
9925 vty_out(vty, "\"%s\":",
9926 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9927 ? "Default"
9928 : bgp->name);
9929 } else {
9930 vty_out(vty, "\nInstance %s:\n",
9931 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9932 ? "Default"
9933 : bgp->name);
9934 }
9935
9936 if (type == show_peer) {
9937 ret = str2sockunion(ip_str, &su);
9938 if (ret < 0)
9939 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
9940 use_json, json);
9941 else
9942 bgp_show_neighbor(vty, bgp, type, &su, NULL,
9943 use_json, json);
9944 } else {
9945 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
9946 use_json, json);
9947 }
9948 }
9949
9950 if (use_json)
9951 vty_out(vty, "}\n");
9952 }
9953
9954 static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
9955 enum show_type type, const char *ip_str,
9956 u_char use_json)
9957 {
9958 int ret;
9959 struct bgp *bgp;
9960 union sockunion su;
9961 json_object *json = NULL;
9962
9963 if (name) {
9964 if (strmatch(name, "all")) {
9965 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
9966 use_json);
9967 return CMD_SUCCESS;
9968 } else {
9969 bgp = bgp_lookup_by_name(name);
9970 if (!bgp) {
9971 if (use_json) {
9972 json = json_object_new_object();
9973 json_object_boolean_true_add(
9974 json, "bgpNoSuchInstance");
9975 vty_out(vty, "%s\n",
9976 json_object_to_json_string_ext(
9977 json,
9978 JSON_C_TO_STRING_PRETTY));
9979 json_object_free(json);
9980 } else
9981 vty_out(vty,
9982 "%% No such BGP instance exist\n");
9983
9984 return CMD_WARNING;
9985 }
9986 }
9987 } else {
9988 bgp = bgp_get_default();
9989 }
9990
9991 if (bgp) {
9992 json = json_object_new_object();
9993 if (ip_str) {
9994 ret = str2sockunion(ip_str, &su);
9995 if (ret < 0)
9996 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
9997 use_json, json);
9998 else
9999 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10000 use_json, json);
10001 } else {
10002 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10003 json);
10004 }
10005 json_object_free(json);
10006 }
10007
10008 return CMD_SUCCESS;
10009 }
10010
10011 /* "show [ip] bgp neighbors" commands. */
10012 DEFUN (show_ip_bgp_neighbors,
10013 show_ip_bgp_neighbors_cmd,
10014 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
10015 SHOW_STR
10016 IP_STR
10017 BGP_STR
10018 BGP_INSTANCE_HELP_STR
10019 "Address Family\n"
10020 "Address Family\n"
10021 "Detailed information on TCP and BGP neighbor connections\n"
10022 "Neighbor to display information about\n"
10023 "Neighbor to display information about\n"
10024 "Neighbor on BGP configured interface\n"
10025 JSON_STR)
10026 {
10027 char *vrf = NULL;
10028 char *sh_arg = NULL;
10029 enum show_type sh_type;
10030
10031 u_char uj = use_json(argc, argv);
10032
10033 int idx = 0;
10034
10035 if (argv_find(argv, argc, "view", &idx)
10036 || argv_find(argv, argc, "vrf", &idx))
10037 vrf = argv[idx + 1]->arg;
10038
10039 idx++;
10040 if (argv_find(argv, argc, "A.B.C.D", &idx)
10041 || argv_find(argv, argc, "X:X::X:X", &idx)
10042 || argv_find(argv, argc, "WORD", &idx)) {
10043 sh_type = show_peer;
10044 sh_arg = argv[idx]->arg;
10045 } else
10046 sh_type = show_all;
10047
10048 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
10049 }
10050
10051 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
10052 paths' and `show ip mbgp paths'. Those functions results are the
10053 same.*/
10054 DEFUN (show_ip_bgp_paths,
10055 show_ip_bgp_paths_cmd,
10056 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
10057 SHOW_STR
10058 IP_STR
10059 BGP_STR
10060 BGP_SAFI_HELP_STR
10061 "Path information\n")
10062 {
10063 vty_out(vty, "Address Refcnt Path\n");
10064 aspath_print_all_vty(vty);
10065 return CMD_SUCCESS;
10066 }
10067
10068 #include "hash.h"
10069
10070 static void community_show_all_iterator(struct hash_backet *backet,
10071 struct vty *vty)
10072 {
10073 struct community *com;
10074
10075 com = (struct community *)backet->data;
10076 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
10077 community_str(com, false));
10078 }
10079
10080 /* Show BGP's community internal data. */
10081 DEFUN (show_ip_bgp_community_info,
10082 show_ip_bgp_community_info_cmd,
10083 "show [ip] bgp community-info",
10084 SHOW_STR
10085 IP_STR
10086 BGP_STR
10087 "List all bgp community information\n")
10088 {
10089 vty_out(vty, "Address Refcnt Community\n");
10090
10091 hash_iterate(community_hash(),
10092 (void (*)(struct hash_backet *,
10093 void *))community_show_all_iterator,
10094 vty);
10095
10096 return CMD_SUCCESS;
10097 }
10098
10099 static void lcommunity_show_all_iterator(struct hash_backet *backet,
10100 struct vty *vty)
10101 {
10102 struct lcommunity *lcom;
10103
10104 lcom = (struct lcommunity *)backet->data;
10105 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
10106 lcommunity_str(lcom));
10107 }
10108
10109 /* Show BGP's community internal data. */
10110 DEFUN (show_ip_bgp_lcommunity_info,
10111 show_ip_bgp_lcommunity_info_cmd,
10112 "show ip bgp large-community-info",
10113 SHOW_STR
10114 IP_STR
10115 BGP_STR
10116 "List all bgp large-community information\n")
10117 {
10118 vty_out(vty, "Address Refcnt Large-community\n");
10119
10120 hash_iterate(lcommunity_hash(),
10121 (void (*)(struct hash_backet *,
10122 void *))lcommunity_show_all_iterator,
10123 vty);
10124
10125 return CMD_SUCCESS;
10126 }
10127
10128
10129 DEFUN (show_ip_bgp_attr_info,
10130 show_ip_bgp_attr_info_cmd,
10131 "show [ip] bgp attribute-info",
10132 SHOW_STR
10133 IP_STR
10134 BGP_STR
10135 "List all bgp attribute information\n")
10136 {
10137 attr_show_all(vty);
10138 return CMD_SUCCESS;
10139 }
10140
10141 static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10142 safi_t safi)
10143 {
10144 struct listnode *node, *nnode;
10145 struct bgp *bgp;
10146
10147 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10148 vty_out(vty, "\nInstance %s:\n",
10149 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10150 ? "Default"
10151 : bgp->name);
10152 update_group_show(bgp, afi, safi, vty, 0);
10153 }
10154 }
10155
10156 static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10157 int safi, uint64_t subgrp_id)
10158 {
10159 struct bgp *bgp;
10160
10161 if (name) {
10162 if (strmatch(name, "all")) {
10163 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10164 return CMD_SUCCESS;
10165 } else {
10166 bgp = bgp_lookup_by_name(name);
10167 }
10168 } else {
10169 bgp = bgp_get_default();
10170 }
10171
10172 if (bgp)
10173 update_group_show(bgp, afi, safi, vty, subgrp_id);
10174 return CMD_SUCCESS;
10175 }
10176
10177 DEFUN (show_ip_bgp_updgrps,
10178 show_ip_bgp_updgrps_cmd,
10179 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
10180 SHOW_STR
10181 IP_STR
10182 BGP_STR
10183 BGP_INSTANCE_HELP_STR
10184 BGP_AFI_HELP_STR
10185 BGP_SAFI_WITH_LABEL_HELP_STR
10186 "Detailed info about dynamic update groups\n"
10187 "Specific subgroup to display detailed info for\n")
10188 {
10189 char *vrf = NULL;
10190 afi_t afi = AFI_IP6;
10191 safi_t safi = SAFI_UNICAST;
10192 uint64_t subgrp_id = 0;
10193
10194 int idx = 0;
10195
10196 /* show [ip] bgp */
10197 if (argv_find(argv, argc, "ip", &idx))
10198 afi = AFI_IP;
10199 /* [<view|vrf> VIEWVRFNAME] */
10200 if (argv_find(argv, argc, "view", &idx)
10201 || argv_find(argv, argc, "vrf", &idx))
10202 vrf = argv[++idx]->arg;
10203 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10204 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10205 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10206 }
10207
10208 /* get subgroup id, if provided */
10209 idx = argc - 1;
10210 if (argv[idx]->type == VARIABLE_TKN)
10211 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
10212
10213 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
10214 }
10215
10216 DEFUN (show_bgp_instance_all_ipv6_updgrps,
10217 show_bgp_instance_all_ipv6_updgrps_cmd,
10218 "show [ip] bgp <view|vrf> all update-groups",
10219 SHOW_STR
10220 IP_STR
10221 BGP_STR
10222 BGP_INSTANCE_ALL_HELP_STR
10223 "Detailed info about dynamic update groups\n")
10224 {
10225 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10226 return CMD_SUCCESS;
10227 }
10228
10229 DEFUN (show_bgp_updgrps_stats,
10230 show_bgp_updgrps_stats_cmd,
10231 "show [ip] bgp update-groups statistics",
10232 SHOW_STR
10233 IP_STR
10234 BGP_STR
10235 "Detailed info about dynamic update groups\n"
10236 "Statistics\n")
10237 {
10238 struct bgp *bgp;
10239
10240 bgp = bgp_get_default();
10241 if (bgp)
10242 update_group_show_stats(bgp, vty);
10243
10244 return CMD_SUCCESS;
10245 }
10246
10247 DEFUN (show_bgp_instance_updgrps_stats,
10248 show_bgp_instance_updgrps_stats_cmd,
10249 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
10250 SHOW_STR
10251 IP_STR
10252 BGP_STR
10253 BGP_INSTANCE_HELP_STR
10254 "Detailed info about dynamic update groups\n"
10255 "Statistics\n")
10256 {
10257 int idx_word = 3;
10258 struct bgp *bgp;
10259
10260 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10261 if (bgp)
10262 update_group_show_stats(bgp, vty);
10263
10264 return CMD_SUCCESS;
10265 }
10266
10267 static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10268 afi_t afi, safi_t safi,
10269 const char *what, uint64_t subgrp_id)
10270 {
10271 struct bgp *bgp;
10272
10273 if (name)
10274 bgp = bgp_lookup_by_name(name);
10275 else
10276 bgp = bgp_get_default();
10277
10278 if (bgp) {
10279 if (!strcmp(what, "advertise-queue"))
10280 update_group_show_adj_queue(bgp, afi, safi, vty,
10281 subgrp_id);
10282 else if (!strcmp(what, "advertised-routes"))
10283 update_group_show_advertised(bgp, afi, safi, vty,
10284 subgrp_id);
10285 else if (!strcmp(what, "packet-queue"))
10286 update_group_show_packet_queue(bgp, afi, safi, vty,
10287 subgrp_id);
10288 }
10289 }
10290
10291 DEFUN (show_ip_bgp_updgrps_adj,
10292 show_ip_bgp_updgrps_adj_cmd,
10293 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
10294 SHOW_STR
10295 IP_STR
10296 BGP_STR
10297 "Detailed info about dynamic update groups\n"
10298 "Advertisement queue\n"
10299 "Announced routes\n"
10300 "Packet queue\n")
10301 {
10302 int idx_type = 4;
10303 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10304 argv[idx_type]->arg, 0);
10305 return CMD_SUCCESS;
10306 }
10307
10308 DEFUN (show_ip_bgp_instance_updgrps_adj,
10309 show_ip_bgp_instance_updgrps_adj_cmd,
10310 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
10311 SHOW_STR
10312 IP_STR
10313 BGP_STR
10314 BGP_INSTANCE_HELP_STR
10315 "Detailed info about dynamic update groups\n"
10316 "Advertisement queue\n"
10317 "Announced routes\n"
10318 "Packet queue\n")
10319 {
10320 int idx_word = 4;
10321 int idx_type = 6;
10322 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP,
10323 SAFI_UNICAST, argv[idx_type]->arg, 0);
10324 return CMD_SUCCESS;
10325 }
10326
10327 DEFUN (show_bgp_updgrps_afi_adj,
10328 show_bgp_updgrps_afi_adj_cmd,
10329 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
10330 SHOW_STR
10331 IP_STR
10332 BGP_STR
10333 BGP_AFI_SAFI_HELP_STR
10334 "Detailed info about dynamic update groups\n"
10335 "Advertisement queue\n"
10336 "Announced routes\n"
10337 "Packet queue\n")
10338 {
10339 int idx_afi = 2;
10340 int idx_safi = 3;
10341 int idx_type = 5;
10342 show_bgp_updgrps_adj_info_aux(
10343 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10344 bgp_vty_safi_from_str(argv[idx_safi]->text),
10345 argv[idx_type]->arg, 0);
10346 return CMD_SUCCESS;
10347 }
10348
10349 DEFUN (show_bgp_updgrps_adj,
10350 show_bgp_updgrps_adj_cmd,
10351 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
10352 SHOW_STR
10353 IP_STR
10354 BGP_STR
10355 "Detailed info about dynamic update groups\n"
10356 "Advertisement queue\n"
10357 "Announced routes\n"
10358 "Packet queue\n")
10359 {
10360 int idx_type = 3;
10361 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10362 argv[idx_type]->arg, 0);
10363 return CMD_SUCCESS;
10364 }
10365
10366 DEFUN (show_bgp_instance_updgrps_adj,
10367 show_bgp_instance_updgrps_adj_cmd,
10368 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
10369 SHOW_STR
10370 IP_STR
10371 BGP_STR
10372 BGP_INSTANCE_HELP_STR
10373 "Detailed info about dynamic update groups\n"
10374 "Advertisement queue\n"
10375 "Announced routes\n"
10376 "Packet queue\n")
10377 {
10378 int idx_word = 3;
10379 int idx_type = 5;
10380 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6,
10381 SAFI_UNICAST, argv[idx_type]->arg, 0);
10382 return CMD_SUCCESS;
10383 }
10384
10385 DEFUN (show_ip_bgp_updgrps_adj_s,
10386 show_ip_bgp_updgrps_adj_s_cmd,
10387 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
10388 SHOW_STR
10389 IP_STR
10390 BGP_STR
10391 "Detailed info about dynamic update groups\n"
10392 "Specific subgroup to display info for\n"
10393 "Advertisement queue\n"
10394 "Announced routes\n"
10395 "Packet queue\n")
10396 {
10397 int idx_subgroup_id = 4;
10398 int idx_type = 5;
10399 uint64_t subgrp_id;
10400
10401 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10402
10403 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10404 argv[idx_type]->arg, subgrp_id);
10405 return CMD_SUCCESS;
10406 }
10407
10408 DEFUN (show_ip_bgp_instance_updgrps_adj_s,
10409 show_ip_bgp_instance_updgrps_adj_s_cmd,
10410 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
10411 SHOW_STR
10412 IP_STR
10413 BGP_STR
10414 BGP_INSTANCE_HELP_STR
10415 "Detailed info about dynamic update groups\n"
10416 "Specific subgroup to display info for\n"
10417 "Advertisement queue\n"
10418 "Announced routes\n"
10419 "Packet queue\n")
10420 {
10421 int idx_vrf = 4;
10422 int idx_subgroup_id = 6;
10423 int idx_type = 7;
10424 uint64_t subgrp_id;
10425
10426 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10427
10428 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP,
10429 SAFI_UNICAST, argv[idx_type]->arg,
10430 subgrp_id);
10431 return CMD_SUCCESS;
10432 }
10433
10434 DEFUN (show_bgp_updgrps_afi_adj_s,
10435 show_bgp_updgrps_afi_adj_s_cmd,
10436 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
10437 SHOW_STR
10438 IP_STR
10439 BGP_STR
10440 BGP_AFI_SAFI_HELP_STR
10441 "Detailed info about dynamic update groups\n"
10442 "Specific subgroup to display info for\n"
10443 "Advertisement queue\n"
10444 "Announced routes\n"
10445 "Packet queue\n")
10446 {
10447 int idx_afi = 2;
10448 int idx_safi = 3;
10449 int idx_subgroup_id = 5;
10450 int idx_type = 6;
10451 uint64_t subgrp_id;
10452
10453 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10454
10455 show_bgp_updgrps_adj_info_aux(
10456 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10457 bgp_vty_safi_from_str(argv[idx_safi]->text),
10458 argv[idx_type]->arg, subgrp_id);
10459 return CMD_SUCCESS;
10460 }
10461
10462 DEFUN (show_bgp_updgrps_adj_s,
10463 show_bgp_updgrps_adj_s_cmd,
10464 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
10465 SHOW_STR
10466 IP_STR
10467 BGP_STR
10468 "Detailed info about dynamic update groups\n"
10469 "Specific subgroup to display info for\n"
10470 "Advertisement queue\n"
10471 "Announced routes\n"
10472 "Packet queue\n")
10473 {
10474 int idx_subgroup_id = 3;
10475 int idx_type = 4;
10476 uint64_t subgrp_id;
10477
10478 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10479
10480 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10481 argv[idx_type]->arg, subgrp_id);
10482 return CMD_SUCCESS;
10483 }
10484
10485 DEFUN (show_bgp_instance_updgrps_adj_s,
10486 show_bgp_instance_updgrps_adj_s_cmd,
10487 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
10488 SHOW_STR
10489 IP_STR
10490 BGP_STR
10491 BGP_INSTANCE_HELP_STR
10492 "Detailed info about dynamic update groups\n"
10493 "Specific subgroup to display info for\n"
10494 "Advertisement queue\n"
10495 "Announced routes\n"
10496 "Packet queue\n")
10497 {
10498 int idx_vrf = 3;
10499 int idx_subgroup_id = 5;
10500 int idx_type = 6;
10501 uint64_t subgrp_id;
10502
10503 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10504
10505 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6,
10506 SAFI_UNICAST, argv[idx_type]->arg,
10507 subgrp_id);
10508 return CMD_SUCCESS;
10509 }
10510
10511
10512 static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10513 {
10514 struct listnode *node, *nnode;
10515 struct prefix *range;
10516 struct peer *conf;
10517 struct peer *peer;
10518 char buf[PREFIX2STR_BUFFER];
10519 afi_t afi;
10520 safi_t safi;
10521 const char *peer_status;
10522 const char *af_str;
10523 int lr_count;
10524 int dynamic;
10525 int af_cfgd;
10526
10527 conf = group->conf;
10528
10529 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10530 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10531 conf->as);
10532 } else if (conf->as_type == AS_INTERNAL) {
10533 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10534 group->bgp->as);
10535 } else {
10536 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10537 }
10538
10539 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10540 vty_out(vty, " Peer-group type is internal\n");
10541 else
10542 vty_out(vty, " Peer-group type is external\n");
10543
10544 /* Display AFs configured. */
10545 vty_out(vty, " Configured address-families:");
10546 FOREACH_AFI_SAFI (afi, safi) {
10547 if (conf->afc[afi][safi]) {
10548 af_cfgd = 1;
10549 vty_out(vty, " %s;", afi_safi_print(afi, safi));
10550 }
10551 }
10552 if (!af_cfgd)
10553 vty_out(vty, " none\n");
10554 else
10555 vty_out(vty, "\n");
10556
10557 /* Display listen ranges (for dynamic neighbors), if any */
10558 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10559 if (afi == AFI_IP)
10560 af_str = "IPv4";
10561 else if (afi == AFI_IP6)
10562 af_str = "IPv6";
10563 else
10564 af_str = "???";
10565 lr_count = listcount(group->listen_range[afi]);
10566 if (lr_count) {
10567 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10568 af_str);
10569
10570
10571 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10572 nnode, range)) {
10573 prefix2str(range, buf, sizeof(buf));
10574 vty_out(vty, " %s\n", buf);
10575 }
10576 }
10577 }
10578
10579 /* Display group members and their status */
10580 if (listcount(group->peer)) {
10581 vty_out(vty, " Peer-group members:\n");
10582 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10583 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10584 peer_status = "Idle (Admin)";
10585 else if (CHECK_FLAG(peer->sflags,
10586 PEER_STATUS_PREFIX_OVERFLOW))
10587 peer_status = "Idle (PfxCt)";
10588 else
10589 peer_status = lookup_msg(bgp_status_msg,
10590 peer->status, NULL);
10591
10592 dynamic = peer_dynamic_neighbor(peer);
10593 vty_out(vty, " %s %s %s \n", peer->host,
10594 dynamic ? "(dynamic)" : "", peer_status);
10595 }
10596 }
10597
10598 return CMD_SUCCESS;
10599 }
10600
10601 static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10602 const char *group_name)
10603 {
10604 struct bgp *bgp;
10605 struct listnode *node, *nnode;
10606 struct peer_group *group;
10607 bool found = false;
10608
10609 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
10610
10611 if (!bgp) {
10612 vty_out(vty, "%% No such BGP instance exists\n");
10613 return CMD_WARNING;
10614 }
10615
10616 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
10617 if (group_name) {
10618 if (strmatch(group->name, group_name)) {
10619 bgp_show_one_peer_group(vty, group);
10620 found = true;
10621 break;
10622 }
10623 } else {
10624 bgp_show_one_peer_group(vty, group);
10625 }
10626 }
10627
10628 if (group_name && !found)
10629 vty_out(vty, "%% No such peer-group\n");
10630
10631 return CMD_SUCCESS;
10632 }
10633
10634 DEFUN (show_ip_bgp_peer_groups,
10635 show_ip_bgp_peer_groups_cmd,
10636 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
10637 SHOW_STR
10638 IP_STR
10639 BGP_STR
10640 BGP_INSTANCE_HELP_STR
10641 "Detailed information on BGP peer groups\n"
10642 "Peer group name\n")
10643 {
10644 char *vrf, *pg;
10645 vrf = pg = NULL;
10646 int idx = 0;
10647
10648 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg : NULL;
10649 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
10650
10651 return bgp_show_peer_group_vty(vty, vrf, pg);
10652 }
10653
10654
10655 /* Redistribute VTY commands. */
10656
10657 DEFUN (bgp_redistribute_ipv4,
10658 bgp_redistribute_ipv4_cmd,
10659 "redistribute " FRR_IP_REDIST_STR_BGPD,
10660 "Redistribute information from another routing protocol\n"
10661 FRR_IP_REDIST_HELP_STR_BGPD)
10662 {
10663 VTY_DECLVAR_CONTEXT(bgp, bgp);
10664 int idx_protocol = 1;
10665 int type;
10666
10667 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10668 if (type < 0) {
10669 vty_out(vty, "%% Invalid route type\n");
10670 return CMD_WARNING_CONFIG_FAILED;
10671 }
10672
10673 bgp_redist_add(bgp, AFI_IP, type, 0);
10674 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10675 }
10676
10677 ALIAS_HIDDEN(
10678 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10679 "redistribute " FRR_IP_REDIST_STR_BGPD,
10680 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
10681
10682 DEFUN (bgp_redistribute_ipv4_rmap,
10683 bgp_redistribute_ipv4_rmap_cmd,
10684 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10685 "Redistribute information from another routing protocol\n"
10686 FRR_IP_REDIST_HELP_STR_BGPD
10687 "Route map reference\n"
10688 "Pointer to route-map entries\n")
10689 {
10690 VTY_DECLVAR_CONTEXT(bgp, bgp);
10691 int idx_protocol = 1;
10692 int idx_word = 3;
10693 int type;
10694 struct bgp_redist *red;
10695
10696 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10697 if (type < 0) {
10698 vty_out(vty, "%% Invalid route type\n");
10699 return CMD_WARNING_CONFIG_FAILED;
10700 }
10701
10702 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10703 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10704 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10705 }
10706
10707 ALIAS_HIDDEN(
10708 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
10709 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10710 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10711 "Route map reference\n"
10712 "Pointer to route-map entries\n")
10713
10714 DEFUN (bgp_redistribute_ipv4_metric,
10715 bgp_redistribute_ipv4_metric_cmd,
10716 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10717 "Redistribute information from another routing protocol\n"
10718 FRR_IP_REDIST_HELP_STR_BGPD
10719 "Metric for redistributed routes\n"
10720 "Default metric\n")
10721 {
10722 VTY_DECLVAR_CONTEXT(bgp, bgp);
10723 int idx_protocol = 1;
10724 int idx_number = 3;
10725 int type;
10726 u_int32_t metric;
10727 struct bgp_redist *red;
10728
10729 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10730 if (type < 0) {
10731 vty_out(vty, "%% Invalid route type\n");
10732 return CMD_WARNING_CONFIG_FAILED;
10733 }
10734 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10735
10736 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10737 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10738 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10739 }
10740
10741 ALIAS_HIDDEN(
10742 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
10743 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10744 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10745 "Metric for redistributed routes\n"
10746 "Default metric\n")
10747
10748 DEFUN (bgp_redistribute_ipv4_rmap_metric,
10749 bgp_redistribute_ipv4_rmap_metric_cmd,
10750 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
10751 "Redistribute information from another routing protocol\n"
10752 FRR_IP_REDIST_HELP_STR_BGPD
10753 "Route map reference\n"
10754 "Pointer to route-map entries\n"
10755 "Metric for redistributed routes\n"
10756 "Default metric\n")
10757 {
10758 VTY_DECLVAR_CONTEXT(bgp, bgp);
10759 int idx_protocol = 1;
10760 int idx_word = 3;
10761 int idx_number = 5;
10762 int type;
10763 u_int32_t metric;
10764 struct bgp_redist *red;
10765
10766 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10767 if (type < 0) {
10768 vty_out(vty, "%% Invalid route type\n");
10769 return CMD_WARNING_CONFIG_FAILED;
10770 }
10771 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10772
10773 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10774 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10775 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10776 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10777 }
10778
10779 ALIAS_HIDDEN(
10780 bgp_redistribute_ipv4_rmap_metric,
10781 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10782 "redistribute " FRR_IP_REDIST_STR_BGPD
10783 " route-map WORD metric (0-4294967295)",
10784 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10785 "Route map reference\n"
10786 "Pointer to route-map entries\n"
10787 "Metric for redistributed routes\n"
10788 "Default metric\n")
10789
10790 DEFUN (bgp_redistribute_ipv4_metric_rmap,
10791 bgp_redistribute_ipv4_metric_rmap_cmd,
10792 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
10793 "Redistribute information from another routing protocol\n"
10794 FRR_IP_REDIST_HELP_STR_BGPD
10795 "Metric for redistributed routes\n"
10796 "Default metric\n"
10797 "Route map reference\n"
10798 "Pointer to route-map entries\n")
10799 {
10800 VTY_DECLVAR_CONTEXT(bgp, bgp);
10801 int idx_protocol = 1;
10802 int idx_number = 3;
10803 int idx_word = 5;
10804 int type;
10805 u_int32_t metric;
10806 struct bgp_redist *red;
10807
10808 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10809 if (type < 0) {
10810 vty_out(vty, "%% Invalid route type\n");
10811 return CMD_WARNING_CONFIG_FAILED;
10812 }
10813 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10814
10815 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10816 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10817 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10818 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10819 }
10820
10821 ALIAS_HIDDEN(
10822 bgp_redistribute_ipv4_metric_rmap,
10823 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10824 "redistribute " FRR_IP_REDIST_STR_BGPD
10825 " metric (0-4294967295) route-map WORD",
10826 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10827 "Metric for redistributed routes\n"
10828 "Default metric\n"
10829 "Route map reference\n"
10830 "Pointer to route-map entries\n")
10831
10832 DEFUN (bgp_redistribute_ipv4_ospf,
10833 bgp_redistribute_ipv4_ospf_cmd,
10834 "redistribute <ospf|table> (1-65535)",
10835 "Redistribute information from another routing protocol\n"
10836 "Open Shortest Path First (OSPFv2)\n"
10837 "Non-main Kernel Routing Table\n"
10838 "Instance ID/Table ID\n")
10839 {
10840 VTY_DECLVAR_CONTEXT(bgp, bgp);
10841 int idx_ospf_table = 1;
10842 int idx_number = 2;
10843 u_short instance;
10844 u_short protocol;
10845
10846 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10847
10848 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10849 protocol = ZEBRA_ROUTE_OSPF;
10850 else
10851 protocol = ZEBRA_ROUTE_TABLE;
10852
10853 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10854 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10855 }
10856
10857 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
10858 "redistribute <ospf|table> (1-65535)",
10859 "Redistribute information from another routing protocol\n"
10860 "Open Shortest Path First (OSPFv2)\n"
10861 "Non-main Kernel Routing Table\n"
10862 "Instance ID/Table ID\n")
10863
10864 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10865 bgp_redistribute_ipv4_ospf_rmap_cmd,
10866 "redistribute <ospf|table> (1-65535) route-map WORD",
10867 "Redistribute information from another routing protocol\n"
10868 "Open Shortest Path First (OSPFv2)\n"
10869 "Non-main Kernel Routing Table\n"
10870 "Instance ID/Table ID\n"
10871 "Route map reference\n"
10872 "Pointer to route-map entries\n")
10873 {
10874 VTY_DECLVAR_CONTEXT(bgp, bgp);
10875 int idx_ospf_table = 1;
10876 int idx_number = 2;
10877 int idx_word = 4;
10878 struct bgp_redist *red;
10879 u_short instance;
10880 int protocol;
10881
10882 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10883 protocol = ZEBRA_ROUTE_OSPF;
10884 else
10885 protocol = ZEBRA_ROUTE_TABLE;
10886
10887 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10888 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10889 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10890 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10891 }
10892
10893 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
10894 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10895 "redistribute <ospf|table> (1-65535) route-map WORD",
10896 "Redistribute information from another routing protocol\n"
10897 "Open Shortest Path First (OSPFv2)\n"
10898 "Non-main Kernel Routing Table\n"
10899 "Instance ID/Table ID\n"
10900 "Route map reference\n"
10901 "Pointer to route-map entries\n")
10902
10903 DEFUN (bgp_redistribute_ipv4_ospf_metric,
10904 bgp_redistribute_ipv4_ospf_metric_cmd,
10905 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10906 "Redistribute information from another routing protocol\n"
10907 "Open Shortest Path First (OSPFv2)\n"
10908 "Non-main Kernel Routing Table\n"
10909 "Instance ID/Table ID\n"
10910 "Metric for redistributed routes\n"
10911 "Default metric\n")
10912 {
10913 VTY_DECLVAR_CONTEXT(bgp, bgp);
10914 int idx_ospf_table = 1;
10915 int idx_number = 2;
10916 int idx_number_2 = 4;
10917 u_int32_t metric;
10918 struct bgp_redist *red;
10919 u_short instance;
10920 int protocol;
10921
10922 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10923 protocol = ZEBRA_ROUTE_OSPF;
10924 else
10925 protocol = ZEBRA_ROUTE_TABLE;
10926
10927 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10928 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10929
10930 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10931 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10932 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10933 }
10934
10935 ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
10936 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10937 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10938 "Redistribute information from another routing protocol\n"
10939 "Open Shortest Path First (OSPFv2)\n"
10940 "Non-main Kernel Routing Table\n"
10941 "Instance ID/Table ID\n"
10942 "Metric for redistributed routes\n"
10943 "Default metric\n")
10944
10945 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10946 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
10947 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10948 "Redistribute information from another routing protocol\n"
10949 "Open Shortest Path First (OSPFv2)\n"
10950 "Non-main Kernel Routing Table\n"
10951 "Instance ID/Table ID\n"
10952 "Route map reference\n"
10953 "Pointer to route-map entries\n"
10954 "Metric for redistributed routes\n"
10955 "Default metric\n")
10956 {
10957 VTY_DECLVAR_CONTEXT(bgp, bgp);
10958 int idx_ospf_table = 1;
10959 int idx_number = 2;
10960 int idx_word = 4;
10961 int idx_number_2 = 6;
10962 u_int32_t metric;
10963 struct bgp_redist *red;
10964 u_short instance;
10965 int protocol;
10966
10967 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10968 protocol = ZEBRA_ROUTE_OSPF;
10969 else
10970 protocol = ZEBRA_ROUTE_TABLE;
10971
10972 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10973 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10974
10975 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10976 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10977 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10978 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10979 }
10980
10981 ALIAS_HIDDEN(
10982 bgp_redistribute_ipv4_ospf_rmap_metric,
10983 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10984 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10985 "Redistribute information from another routing protocol\n"
10986 "Open Shortest Path First (OSPFv2)\n"
10987 "Non-main Kernel Routing Table\n"
10988 "Instance ID/Table ID\n"
10989 "Route map reference\n"
10990 "Pointer to route-map entries\n"
10991 "Metric for redistributed routes\n"
10992 "Default metric\n")
10993
10994 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
10995 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
10996 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10997 "Redistribute information from another routing protocol\n"
10998 "Open Shortest Path First (OSPFv2)\n"
10999 "Non-main Kernel Routing Table\n"
11000 "Instance ID/Table ID\n"
11001 "Metric for redistributed routes\n"
11002 "Default metric\n"
11003 "Route map reference\n"
11004 "Pointer to route-map entries\n")
11005 {
11006 VTY_DECLVAR_CONTEXT(bgp, bgp);
11007 int idx_ospf_table = 1;
11008 int idx_number = 2;
11009 int idx_number_2 = 4;
11010 int idx_word = 6;
11011 u_int32_t metric;
11012 struct bgp_redist *red;
11013 u_short instance;
11014 int protocol;
11015
11016 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11017 protocol = ZEBRA_ROUTE_OSPF;
11018 else
11019 protocol = ZEBRA_ROUTE_TABLE;
11020
11021 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11022 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11023
11024 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11025 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11026 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11027 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11028 }
11029
11030 ALIAS_HIDDEN(
11031 bgp_redistribute_ipv4_ospf_metric_rmap,
11032 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11033 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11034 "Redistribute information from another routing protocol\n"
11035 "Open Shortest Path First (OSPFv2)\n"
11036 "Non-main Kernel Routing Table\n"
11037 "Instance ID/Table ID\n"
11038 "Metric for redistributed routes\n"
11039 "Default metric\n"
11040 "Route map reference\n"
11041 "Pointer to route-map entries\n")
11042
11043 DEFUN (no_bgp_redistribute_ipv4_ospf,
11044 no_bgp_redistribute_ipv4_ospf_cmd,
11045 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11046 NO_STR
11047 "Redistribute information from another routing protocol\n"
11048 "Open Shortest Path First (OSPFv2)\n"
11049 "Non-main Kernel Routing Table\n"
11050 "Instance ID/Table ID\n"
11051 "Metric for redistributed routes\n"
11052 "Default metric\n"
11053 "Route map reference\n"
11054 "Pointer to route-map entries\n")
11055 {
11056 VTY_DECLVAR_CONTEXT(bgp, bgp);
11057 int idx_ospf_table = 2;
11058 int idx_number = 3;
11059 u_short instance;
11060 int protocol;
11061
11062 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11063 protocol = ZEBRA_ROUTE_OSPF;
11064 else
11065 protocol = ZEBRA_ROUTE_TABLE;
11066
11067 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11068 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11069 }
11070
11071 ALIAS_HIDDEN(
11072 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11073 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11074 NO_STR
11075 "Redistribute information from another routing protocol\n"
11076 "Open Shortest Path First (OSPFv2)\n"
11077 "Non-main Kernel Routing Table\n"
11078 "Instance ID/Table ID\n"
11079 "Metric for redistributed routes\n"
11080 "Default metric\n"
11081 "Route map reference\n"
11082 "Pointer to route-map entries\n")
11083
11084 DEFUN (no_bgp_redistribute_ipv4,
11085 no_bgp_redistribute_ipv4_cmd,
11086 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11087 NO_STR
11088 "Redistribute information from another routing protocol\n"
11089 FRR_IP_REDIST_HELP_STR_BGPD
11090 "Metric for redistributed routes\n"
11091 "Default metric\n"
11092 "Route map reference\n"
11093 "Pointer to route-map entries\n")
11094 {
11095 VTY_DECLVAR_CONTEXT(bgp, bgp);
11096 int idx_protocol = 2;
11097 int type;
11098
11099 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11100 if (type < 0) {
11101 vty_out(vty, "%% Invalid route type\n");
11102 return CMD_WARNING_CONFIG_FAILED;
11103 }
11104 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11105 }
11106
11107 ALIAS_HIDDEN(
11108 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11109 "no redistribute " FRR_IP_REDIST_STR_BGPD
11110 " [metric (0-4294967295)] [route-map WORD]",
11111 NO_STR
11112 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11113 "Metric for redistributed routes\n"
11114 "Default metric\n"
11115 "Route map reference\n"
11116 "Pointer to route-map entries\n")
11117
11118 DEFUN (bgp_redistribute_ipv6,
11119 bgp_redistribute_ipv6_cmd,
11120 "redistribute " FRR_IP6_REDIST_STR_BGPD,
11121 "Redistribute information from another routing protocol\n"
11122 FRR_IP6_REDIST_HELP_STR_BGPD)
11123 {
11124 VTY_DECLVAR_CONTEXT(bgp, bgp);
11125 int idx_protocol = 1;
11126 int type;
11127
11128 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11129 if (type < 0) {
11130 vty_out(vty, "%% Invalid route type\n");
11131 return CMD_WARNING_CONFIG_FAILED;
11132 }
11133
11134 bgp_redist_add(bgp, AFI_IP6, type, 0);
11135 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11136 }
11137
11138 DEFUN (bgp_redistribute_ipv6_rmap,
11139 bgp_redistribute_ipv6_rmap_cmd,
11140 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
11141 "Redistribute information from another routing protocol\n"
11142 FRR_IP6_REDIST_HELP_STR_BGPD
11143 "Route map reference\n"
11144 "Pointer to route-map entries\n")
11145 {
11146 VTY_DECLVAR_CONTEXT(bgp, bgp);
11147 int idx_protocol = 1;
11148 int idx_word = 3;
11149 int type;
11150 struct bgp_redist *red;
11151
11152 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11153 if (type < 0) {
11154 vty_out(vty, "%% Invalid route type\n");
11155 return CMD_WARNING_CONFIG_FAILED;
11156 }
11157
11158 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11159 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11160 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11161 }
11162
11163 DEFUN (bgp_redistribute_ipv6_metric,
11164 bgp_redistribute_ipv6_metric_cmd,
11165 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
11166 "Redistribute information from another routing protocol\n"
11167 FRR_IP6_REDIST_HELP_STR_BGPD
11168 "Metric for redistributed routes\n"
11169 "Default metric\n")
11170 {
11171 VTY_DECLVAR_CONTEXT(bgp, bgp);
11172 int idx_protocol = 1;
11173 int idx_number = 3;
11174 int type;
11175 u_int32_t metric;
11176 struct bgp_redist *red;
11177
11178 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11179 if (type < 0) {
11180 vty_out(vty, "%% Invalid route type\n");
11181 return CMD_WARNING_CONFIG_FAILED;
11182 }
11183 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11184
11185 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11186 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11187 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11188 }
11189
11190 DEFUN (bgp_redistribute_ipv6_rmap_metric,
11191 bgp_redistribute_ipv6_rmap_metric_cmd,
11192 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
11193 "Redistribute information from another routing protocol\n"
11194 FRR_IP6_REDIST_HELP_STR_BGPD
11195 "Route map reference\n"
11196 "Pointer to route-map entries\n"
11197 "Metric for redistributed routes\n"
11198 "Default metric\n")
11199 {
11200 VTY_DECLVAR_CONTEXT(bgp, bgp);
11201 int idx_protocol = 1;
11202 int idx_word = 3;
11203 int idx_number = 5;
11204 int type;
11205 u_int32_t metric;
11206 struct bgp_redist *red;
11207
11208 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11209 if (type < 0) {
11210 vty_out(vty, "%% Invalid route type\n");
11211 return CMD_WARNING_CONFIG_FAILED;
11212 }
11213 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11214
11215 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11216 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11217 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11218 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11219 }
11220
11221 DEFUN (bgp_redistribute_ipv6_metric_rmap,
11222 bgp_redistribute_ipv6_metric_rmap_cmd,
11223 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
11224 "Redistribute information from another routing protocol\n"
11225 FRR_IP6_REDIST_HELP_STR_BGPD
11226 "Metric for redistributed routes\n"
11227 "Default metric\n"
11228 "Route map reference\n"
11229 "Pointer to route-map entries\n")
11230 {
11231 VTY_DECLVAR_CONTEXT(bgp, bgp);
11232 int idx_protocol = 1;
11233 int idx_number = 3;
11234 int idx_word = 5;
11235 int type;
11236 u_int32_t metric;
11237 struct bgp_redist *red;
11238
11239 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11240 if (type < 0) {
11241 vty_out(vty, "%% Invalid route type\n");
11242 return CMD_WARNING_CONFIG_FAILED;
11243 }
11244 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11245
11246 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11247 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11248 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11249 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
11250 }
11251
11252 DEFUN (no_bgp_redistribute_ipv6,
11253 no_bgp_redistribute_ipv6_cmd,
11254 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
11255 NO_STR
11256 "Redistribute information from another routing protocol\n"
11257 FRR_IP6_REDIST_HELP_STR_BGPD
11258 "Metric for redistributed routes\n"
11259 "Default metric\n"
11260 "Route map reference\n"
11261 "Pointer to route-map entries\n")
11262 {
11263 VTY_DECLVAR_CONTEXT(bgp, bgp);
11264 int idx_protocol = 2;
11265 int type;
11266
11267 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11268 if (type < 0) {
11269 vty_out(vty, "%% Invalid route type\n");
11270 return CMD_WARNING_CONFIG_FAILED;
11271 }
11272
11273 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11274 }
11275
11276 void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
11277 safi_t safi)
11278 {
11279 int i;
11280
11281 /* Unicast redistribution only. */
11282 if (safi != SAFI_UNICAST)
11283 return;
11284
11285 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11286 /* Redistribute BGP does not make sense. */
11287 if (i != ZEBRA_ROUTE_BGP) {
11288 struct list *red_list;
11289 struct listnode *node;
11290 struct bgp_redist *red;
11291
11292 red_list = bgp->redist[afi][i];
11293 if (!red_list)
11294 continue;
11295
11296 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
11297 /* "redistribute" configuration. */
11298 vty_out(vty, " redistribute %s",
11299 zebra_route_string(i));
11300 if (red->instance)
11301 vty_out(vty, " %d", red->instance);
11302 if (red->redist_metric_flag)
11303 vty_out(vty, " metric %u",
11304 red->redist_metric);
11305 if (red->rmap.name)
11306 vty_out(vty, " route-map %s",
11307 red->rmap.name);
11308 vty_out(vty, "\n");
11309 }
11310 }
11311 }
11312 }
11313
11314 /* BGP node structure. */
11315 static struct cmd_node bgp_node = {
11316 BGP_NODE, "%s(config-router)# ", 1,
11317 };
11318
11319 static struct cmd_node bgp_ipv4_unicast_node = {
11320 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
11321 };
11322
11323 static struct cmd_node bgp_ipv4_multicast_node = {
11324 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
11325 };
11326
11327 static struct cmd_node bgp_ipv4_labeled_unicast_node = {
11328 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
11329 };
11330
11331 static struct cmd_node bgp_ipv6_unicast_node = {
11332 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
11333 };
11334
11335 static struct cmd_node bgp_ipv6_multicast_node = {
11336 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
11337 };
11338
11339 static struct cmd_node bgp_ipv6_labeled_unicast_node = {
11340 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
11341 };
11342
11343 static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11344 "%s(config-router-af)# ", 1};
11345
11346 static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11347 "%s(config-router-af-vpnv6)# ", 1};
11348
11349 static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11350 "%s(config-router-evpn)# ", 1};
11351
11352 static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11353 "%s(config-router-af-vni)# ", 1};
11354
11355 static void community_list_vty(void);
11356
11357 static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
11358 {
11359 struct bgp *bgp;
11360 struct peer *peer;
11361 struct peer_group *group;
11362 struct listnode *lnbgp, *lnpeer;
11363
11364 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11365 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11366 /* only provide suggestions on the appropriate input
11367 * token type,
11368 * they'll otherwise show up multiple times */
11369 enum cmd_token_type match_type;
11370 char *name = peer->host;
11371
11372 if (peer->conf_if) {
11373 match_type = VARIABLE_TKN;
11374 name = peer->conf_if;
11375 } else if (strchr(peer->host, ':'))
11376 match_type = IPV6_TKN;
11377 else
11378 match_type = IPV4_TKN;
11379
11380 if (token->type != match_type)
11381 continue;
11382
11383 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11384 }
11385
11386 if (token->type == VARIABLE_TKN)
11387 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11388 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11389 group->name));
11390 }
11391 }
11392
11393 static const struct cmd_variable_handler bgp_var_neighbor[] = {
11394 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11395 {.varname = "neighbors", .completions = bgp_ac_neighbor},
11396 {.varname = "peer", .completions = bgp_ac_neighbor},
11397 {.completions = NULL}};
11398
11399 void bgp_vty_init(void)
11400 {
11401 cmd_variable_handler_register(bgp_var_neighbor);
11402
11403 /* Install bgp top node. */
11404 install_node(&bgp_node, bgp_config_write);
11405 install_node(&bgp_ipv4_unicast_node, NULL);
11406 install_node(&bgp_ipv4_multicast_node, NULL);
11407 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11408 install_node(&bgp_ipv6_unicast_node, NULL);
11409 install_node(&bgp_ipv6_multicast_node, NULL);
11410 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11411 install_node(&bgp_vpnv4_node, NULL);
11412 install_node(&bgp_vpnv6_node, NULL);
11413 install_node(&bgp_evpn_node, NULL);
11414 install_node(&bgp_evpn_vni_node, NULL);
11415
11416 /* Install default VTY commands to new nodes. */
11417 install_default(BGP_NODE);
11418 install_default(BGP_IPV4_NODE);
11419 install_default(BGP_IPV4M_NODE);
11420 install_default(BGP_IPV4L_NODE);
11421 install_default(BGP_IPV6_NODE);
11422 install_default(BGP_IPV6M_NODE);
11423 install_default(BGP_IPV6L_NODE);
11424 install_default(BGP_VPNV4_NODE);
11425 install_default(BGP_VPNV6_NODE);
11426 install_default(BGP_EVPN_NODE);
11427 install_default(BGP_EVPN_VNI_NODE);
11428
11429 /* "bgp multiple-instance" commands. */
11430 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11431 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11432
11433 /* "bgp config-type" commands. */
11434 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11435 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11436
11437 /* bgp route-map delay-timer commands. */
11438 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11439 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11440
11441 /* Dummy commands (Currently not supported) */
11442 install_element(BGP_NODE, &no_synchronization_cmd);
11443 install_element(BGP_NODE, &no_auto_summary_cmd);
11444
11445 /* "router bgp" commands. */
11446 install_element(CONFIG_NODE, &router_bgp_cmd);
11447
11448 /* "no router bgp" commands. */
11449 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11450
11451 /* "bgp router-id" commands. */
11452 install_element(BGP_NODE, &bgp_router_id_cmd);
11453 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11454
11455 /* "bgp cluster-id" commands. */
11456 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11457 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11458
11459 /* "bgp confederation" commands. */
11460 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11461 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11462
11463 /* "bgp confederation peers" commands. */
11464 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11465 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11466
11467 /* bgp max-med command */
11468 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11469 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11470 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11471 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11472 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11473
11474 /* bgp disable-ebgp-connected-nh-check */
11475 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11476 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11477
11478 /* bgp update-delay command */
11479 install_element(BGP_NODE, &bgp_update_delay_cmd);
11480 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11481 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11482
11483 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11484 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
11485 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
11486 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
11487
11488 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11489 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11490
11491 /* "maximum-paths" commands. */
11492 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11493 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11494 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11495 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11496 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11497 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11498 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11499 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11500 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11501 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11502 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11503 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11504 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11505 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11506 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11507
11508 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11509 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11510 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11511 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11512 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11513
11514 /* "timers bgp" commands. */
11515 install_element(BGP_NODE, &bgp_timers_cmd);
11516 install_element(BGP_NODE, &no_bgp_timers_cmd);
11517
11518 /* route-map delay-timer commands - per instance for backwards compat.
11519 */
11520 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11521 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11522
11523 /* "bgp client-to-client reflection" commands */
11524 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11525 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11526
11527 /* "bgp always-compare-med" commands */
11528 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11529 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11530
11531 /* "bgp deterministic-med" commands */
11532 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11533 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11534
11535 /* "bgp graceful-restart" commands */
11536 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11537 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11538 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11539 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11540 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11541 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11542
11543 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11544 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11545
11546 /* "bgp graceful-shutdown" commands */
11547 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
11548 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
11549
11550 /* "bgp fast-external-failover" commands */
11551 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11552 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11553
11554 /* "bgp enforce-first-as" commands */
11555 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11556 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11557
11558 /* "bgp bestpath compare-routerid" commands */
11559 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11560 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11561
11562 /* "bgp bestpath as-path ignore" commands */
11563 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11564 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11565
11566 /* "bgp bestpath as-path confed" commands */
11567 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11568 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11569
11570 /* "bgp bestpath as-path multipath-relax" commands */
11571 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11572 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11573
11574 /* "bgp log-neighbor-changes" commands */
11575 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11576 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11577
11578 /* "bgp bestpath med" commands */
11579 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11580 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11581
11582 /* "no bgp default ipv4-unicast" commands. */
11583 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11584 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11585
11586 /* "bgp network import-check" commands. */
11587 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11588 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11589 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11590
11591 /* "bgp default local-preference" commands. */
11592 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11593 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11594
11595 /* bgp default show-hostname */
11596 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11597 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11598
11599 /* "bgp default subgroup-pkt-queue-max" commands. */
11600 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11601 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11602
11603 /* bgp ibgp-allow-policy-mods command */
11604 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11605 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11606
11607 /* "bgp listen limit" commands. */
11608 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11609 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11610
11611 /* "bgp listen range" commands. */
11612 install_element(BGP_NODE, &bgp_listen_range_cmd);
11613 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11614
11615 /* "bgp default shutdown" command */
11616 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
11617
11618 /* "neighbor remote-as" commands. */
11619 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11620 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11621 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11622 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11623 install_element(BGP_NODE,
11624 &neighbor_interface_v6only_config_remote_as_cmd);
11625 install_element(BGP_NODE, &no_neighbor_cmd);
11626 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
11627
11628 /* "neighbor peer-group" commands. */
11629 install_element(BGP_NODE, &neighbor_peer_group_cmd);
11630 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
11631 install_element(BGP_NODE,
11632 &no_neighbor_interface_peer_group_remote_as_cmd);
11633
11634 /* "neighbor local-as" commands. */
11635 install_element(BGP_NODE, &neighbor_local_as_cmd);
11636 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
11637 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
11638 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
11639
11640 /* "neighbor solo" commands. */
11641 install_element(BGP_NODE, &neighbor_solo_cmd);
11642 install_element(BGP_NODE, &no_neighbor_solo_cmd);
11643
11644 /* "neighbor password" commands. */
11645 install_element(BGP_NODE, &neighbor_password_cmd);
11646 install_element(BGP_NODE, &no_neighbor_password_cmd);
11647
11648 /* "neighbor activate" commands. */
11649 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
11650 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
11651 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
11652 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
11653 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
11654 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
11655 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
11656 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
11657 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
11658 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
11659
11660 /* "no neighbor activate" commands. */
11661 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
11662 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11663 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
11664 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
11665 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
11666 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
11667 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
11668 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
11669 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
11670 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
11671
11672 /* "neighbor peer-group" set commands. */
11673 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
11674 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11675 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11676 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11677 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11678 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11679 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11680 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11681
11682 /* "no neighbor peer-group unset" commands. */
11683 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
11684 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11685 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11686 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11687 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11688 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11689 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11690 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11691
11692 /* "neighbor softreconfiguration inbound" commands.*/
11693 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11694 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
11695 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11696 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11697 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11698 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11699 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11700 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11701 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11702 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11703 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11704 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11705 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11706 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11707 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11708 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11709 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11710 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11711
11712 /* "neighbor attribute-unchanged" commands. */
11713 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11714 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
11715 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
11716 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
11717 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
11718 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
11719 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11720 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
11721 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
11722 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
11723 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
11724 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
11725 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11726 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
11727 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
11728 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
11729 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
11730 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
11731
11732 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11733 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11734
11735 /* "nexthop-local unchanged" commands */
11736 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11737 install_element(BGP_IPV6_NODE,
11738 &no_neighbor_nexthop_local_unchanged_cmd);
11739
11740 /* "neighbor next-hop-self" commands. */
11741 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11742 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
11743 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11744 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11745 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11746 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
11747 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11748 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
11749 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11750 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
11751 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11752 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
11753 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11754 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
11755 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11756 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
11757 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11758 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
11759
11760 /* "neighbor next-hop-self force" commands. */
11761 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11762 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
11763 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11764 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11765 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11766 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
11767 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11768 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
11769 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11770 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11771 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11772 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
11773 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11774 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
11775 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11776 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11777 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11778 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11779
11780 /* "neighbor as-override" commands. */
11781 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
11782 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
11783 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
11784 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11785 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11786 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
11787 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11788 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
11789 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
11790 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11791 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11792 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
11793 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11794 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
11795 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11796 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
11797 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11798 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
11799
11800 /* "neighbor remove-private-AS" commands. */
11801 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11802 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11803 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11804 install_element(BGP_NODE,
11805 &no_neighbor_remove_private_as_all_hidden_cmd);
11806 install_element(BGP_NODE,
11807 &neighbor_remove_private_as_replace_as_hidden_cmd);
11808 install_element(BGP_NODE,
11809 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11810 install_element(BGP_NODE,
11811 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11812 install_element(
11813 BGP_NODE,
11814 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
11815 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11816 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
11817 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11818 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11819 install_element(BGP_IPV4_NODE,
11820 &neighbor_remove_private_as_replace_as_cmd);
11821 install_element(BGP_IPV4_NODE,
11822 &no_neighbor_remove_private_as_replace_as_cmd);
11823 install_element(BGP_IPV4_NODE,
11824 &neighbor_remove_private_as_all_replace_as_cmd);
11825 install_element(BGP_IPV4_NODE,
11826 &no_neighbor_remove_private_as_all_replace_as_cmd);
11827 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11828 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
11829 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11830 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11831 install_element(BGP_IPV4M_NODE,
11832 &neighbor_remove_private_as_replace_as_cmd);
11833 install_element(BGP_IPV4M_NODE,
11834 &no_neighbor_remove_private_as_replace_as_cmd);
11835 install_element(BGP_IPV4M_NODE,
11836 &neighbor_remove_private_as_all_replace_as_cmd);
11837 install_element(BGP_IPV4M_NODE,
11838 &no_neighbor_remove_private_as_all_replace_as_cmd);
11839 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11840 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11841 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11842 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11843 install_element(BGP_IPV4L_NODE,
11844 &neighbor_remove_private_as_replace_as_cmd);
11845 install_element(BGP_IPV4L_NODE,
11846 &no_neighbor_remove_private_as_replace_as_cmd);
11847 install_element(BGP_IPV4L_NODE,
11848 &neighbor_remove_private_as_all_replace_as_cmd);
11849 install_element(BGP_IPV4L_NODE,
11850 &no_neighbor_remove_private_as_all_replace_as_cmd);
11851 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11852 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
11853 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11854 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11855 install_element(BGP_IPV6_NODE,
11856 &neighbor_remove_private_as_replace_as_cmd);
11857 install_element(BGP_IPV6_NODE,
11858 &no_neighbor_remove_private_as_replace_as_cmd);
11859 install_element(BGP_IPV6_NODE,
11860 &neighbor_remove_private_as_all_replace_as_cmd);
11861 install_element(BGP_IPV6_NODE,
11862 &no_neighbor_remove_private_as_all_replace_as_cmd);
11863 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11864 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
11865 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11866 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11867 install_element(BGP_IPV6M_NODE,
11868 &neighbor_remove_private_as_replace_as_cmd);
11869 install_element(BGP_IPV6M_NODE,
11870 &no_neighbor_remove_private_as_replace_as_cmd);
11871 install_element(BGP_IPV6M_NODE,
11872 &neighbor_remove_private_as_all_replace_as_cmd);
11873 install_element(BGP_IPV6M_NODE,
11874 &no_neighbor_remove_private_as_all_replace_as_cmd);
11875 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11876 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11877 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11878 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11879 install_element(BGP_IPV6L_NODE,
11880 &neighbor_remove_private_as_replace_as_cmd);
11881 install_element(BGP_IPV6L_NODE,
11882 &no_neighbor_remove_private_as_replace_as_cmd);
11883 install_element(BGP_IPV6L_NODE,
11884 &neighbor_remove_private_as_all_replace_as_cmd);
11885 install_element(BGP_IPV6L_NODE,
11886 &no_neighbor_remove_private_as_all_replace_as_cmd);
11887 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11888 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
11889 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11890 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11891 install_element(BGP_VPNV4_NODE,
11892 &neighbor_remove_private_as_replace_as_cmd);
11893 install_element(BGP_VPNV4_NODE,
11894 &no_neighbor_remove_private_as_replace_as_cmd);
11895 install_element(BGP_VPNV4_NODE,
11896 &neighbor_remove_private_as_all_replace_as_cmd);
11897 install_element(BGP_VPNV4_NODE,
11898 &no_neighbor_remove_private_as_all_replace_as_cmd);
11899 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11900 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11901 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11902 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11903 install_element(BGP_VPNV6_NODE,
11904 &neighbor_remove_private_as_replace_as_cmd);
11905 install_element(BGP_VPNV6_NODE,
11906 &no_neighbor_remove_private_as_replace_as_cmd);
11907 install_element(BGP_VPNV6_NODE,
11908 &neighbor_remove_private_as_all_replace_as_cmd);
11909 install_element(BGP_VPNV6_NODE,
11910 &no_neighbor_remove_private_as_all_replace_as_cmd);
11911
11912 /* "neighbor send-community" commands.*/
11913 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
11914 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11915 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11916 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
11917 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
11918 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11919 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11920 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11921 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11922 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11923 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11924 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
11925 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11926 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11927 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11928 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
11929 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
11930 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11931 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11932 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
11933 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11934 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11935 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11936 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
11937 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11938 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11939 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11940 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
11941 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11942 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11943 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11944 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
11945 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11946 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11947 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11948 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
11949
11950 /* "neighbor route-reflector" commands.*/
11951 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11952 install_element(BGP_NODE,
11953 &no_neighbor_route_reflector_client_hidden_cmd);
11954 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11955 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11956 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11957 install_element(BGP_IPV4M_NODE,
11958 &no_neighbor_route_reflector_client_cmd);
11959 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11960 install_element(BGP_IPV4L_NODE,
11961 &no_neighbor_route_reflector_client_cmd);
11962 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11963 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
11964 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11965 install_element(BGP_IPV6M_NODE,
11966 &no_neighbor_route_reflector_client_cmd);
11967 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11968 install_element(BGP_IPV6L_NODE,
11969 &no_neighbor_route_reflector_client_cmd);
11970 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11971 install_element(BGP_VPNV4_NODE,
11972 &no_neighbor_route_reflector_client_cmd);
11973 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11974 install_element(BGP_VPNV6_NODE,
11975 &no_neighbor_route_reflector_client_cmd);
11976 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
11977 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
11978
11979 /* "neighbor route-server" commands.*/
11980 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11981 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
11982 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11983 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11984 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11985 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
11986 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
11987 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
11988 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
11989 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
11990 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
11991 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
11992 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
11993 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
11994 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
11995 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
11996 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
11997 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
11998
11999 /* "neighbor addpath-tx-all-paths" commands.*/
12000 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12001 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12002 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12003 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12004 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12005 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12006 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12007 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12008 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12009 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12010 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12011 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12012 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12013 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12014 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12015 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12016 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12017 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12018
12019 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12020 install_element(BGP_NODE,
12021 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12022 install_element(BGP_NODE,
12023 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12024 install_element(BGP_IPV4_NODE,
12025 &neighbor_addpath_tx_bestpath_per_as_cmd);
12026 install_element(BGP_IPV4_NODE,
12027 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12028 install_element(BGP_IPV4M_NODE,
12029 &neighbor_addpath_tx_bestpath_per_as_cmd);
12030 install_element(BGP_IPV4M_NODE,
12031 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12032 install_element(BGP_IPV4L_NODE,
12033 &neighbor_addpath_tx_bestpath_per_as_cmd);
12034 install_element(BGP_IPV4L_NODE,
12035 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12036 install_element(BGP_IPV6_NODE,
12037 &neighbor_addpath_tx_bestpath_per_as_cmd);
12038 install_element(BGP_IPV6_NODE,
12039 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12040 install_element(BGP_IPV6M_NODE,
12041 &neighbor_addpath_tx_bestpath_per_as_cmd);
12042 install_element(BGP_IPV6M_NODE,
12043 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12044 install_element(BGP_IPV6L_NODE,
12045 &neighbor_addpath_tx_bestpath_per_as_cmd);
12046 install_element(BGP_IPV6L_NODE,
12047 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12048 install_element(BGP_VPNV4_NODE,
12049 &neighbor_addpath_tx_bestpath_per_as_cmd);
12050 install_element(BGP_VPNV4_NODE,
12051 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12052 install_element(BGP_VPNV6_NODE,
12053 &neighbor_addpath_tx_bestpath_per_as_cmd);
12054 install_element(BGP_VPNV6_NODE,
12055 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12056
12057 /* "neighbor passive" commands. */
12058 install_element(BGP_NODE, &neighbor_passive_cmd);
12059 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12060
12061
12062 /* "neighbor shutdown" commands. */
12063 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12064 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12065 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12066 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12067
12068 /* "neighbor capability extended-nexthop" commands.*/
12069 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12070 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12071
12072 /* "neighbor capability orf prefix-list" commands.*/
12073 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12074 install_element(BGP_NODE,
12075 &no_neighbor_capability_orf_prefix_hidden_cmd);
12076 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12077 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12078 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12079 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12080 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12081 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12082 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12083 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12084 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12085 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12086 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12087 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12088
12089 /* "neighbor capability dynamic" commands.*/
12090 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12091 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12092
12093 /* "neighbor dont-capability-negotiate" commands. */
12094 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12095 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12096
12097 /* "neighbor ebgp-multihop" commands. */
12098 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12099 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12100 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12101
12102 /* "neighbor disable-connected-check" commands. */
12103 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12104 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12105
12106 /* "neighbor description" commands. */
12107 install_element(BGP_NODE, &neighbor_description_cmd);
12108 install_element(BGP_NODE, &no_neighbor_description_cmd);
12109
12110 /* "neighbor update-source" commands. "*/
12111 install_element(BGP_NODE, &neighbor_update_source_cmd);
12112 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12113
12114 /* "neighbor default-originate" commands. */
12115 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12116 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12117 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12118 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12119 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12120 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12121 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12122 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12123 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12124 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12125 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12126 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12127 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12128 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12129 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12130 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12131 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12132 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12133 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12134 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12135 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12136
12137 /* "neighbor port" commands. */
12138 install_element(BGP_NODE, &neighbor_port_cmd);
12139 install_element(BGP_NODE, &no_neighbor_port_cmd);
12140
12141 /* "neighbor weight" commands. */
12142 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12143 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12144
12145 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12146 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12147 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12148 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12149 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12150 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12151 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12152 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12153 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12154 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12155 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12156 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12157 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12158 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12159 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12160 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12161
12162 /* "neighbor override-capability" commands. */
12163 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12164 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12165
12166 /* "neighbor strict-capability-match" commands. */
12167 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12168 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12169
12170 /* "neighbor timers" commands. */
12171 install_element(BGP_NODE, &neighbor_timers_cmd);
12172 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12173
12174 /* "neighbor timers connect" commands. */
12175 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12176 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12177
12178 /* "neighbor advertisement-interval" commands. */
12179 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12180 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12181
12182 /* "neighbor interface" commands. */
12183 install_element(BGP_NODE, &neighbor_interface_cmd);
12184 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12185
12186 /* "neighbor distribute" commands. */
12187 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12188 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12189 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12190 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12191 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12192 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12193 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12194 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12195 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12196 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12197 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12198 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12199 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12200 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12201 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12202 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12203 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12204 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12205
12206 /* "neighbor prefix-list" commands. */
12207 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12208 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12209 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12210 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12211 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12212 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12213 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12214 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12215 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12216 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12217 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12218 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12219 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12220 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12221 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12222 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12223 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12224 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12225
12226 /* "neighbor filter-list" commands. */
12227 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12228 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12229 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12230 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12231 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12232 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12233 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12234 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12235 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12236 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12237 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12238 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12239 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12240 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12241 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12242 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12243 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12244 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12245
12246 /* "neighbor route-map" commands. */
12247 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12248 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12249 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12250 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12251 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12252 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12253 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12254 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12255 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12256 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12257 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12258 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12259 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12260 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12261 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12262 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12263 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12264 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
12265 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12266 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
12267
12268 /* "neighbor unsuppress-map" commands. */
12269 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12270 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12271 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12272 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12273 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12274 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12275 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12276 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12277 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12278 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12279 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12280 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12281 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12282 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12283 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12284 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12285 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12286 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12287
12288 /* "neighbor maximum-prefix" commands. */
12289 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12290 install_element(BGP_NODE,
12291 &neighbor_maximum_prefix_threshold_hidden_cmd);
12292 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12293 install_element(BGP_NODE,
12294 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12295 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12296 install_element(BGP_NODE,
12297 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12298 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12299 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12300 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12301 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12302 install_element(BGP_IPV4_NODE,
12303 &neighbor_maximum_prefix_threshold_warning_cmd);
12304 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12305 install_element(BGP_IPV4_NODE,
12306 &neighbor_maximum_prefix_threshold_restart_cmd);
12307 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12308 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12309 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12310 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12311 install_element(BGP_IPV4M_NODE,
12312 &neighbor_maximum_prefix_threshold_warning_cmd);
12313 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12314 install_element(BGP_IPV4M_NODE,
12315 &neighbor_maximum_prefix_threshold_restart_cmd);
12316 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12317 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12318 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12319 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12320 install_element(BGP_IPV4L_NODE,
12321 &neighbor_maximum_prefix_threshold_warning_cmd);
12322 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12323 install_element(BGP_IPV4L_NODE,
12324 &neighbor_maximum_prefix_threshold_restart_cmd);
12325 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12326 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12327 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12328 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12329 install_element(BGP_IPV6_NODE,
12330 &neighbor_maximum_prefix_threshold_warning_cmd);
12331 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12332 install_element(BGP_IPV6_NODE,
12333 &neighbor_maximum_prefix_threshold_restart_cmd);
12334 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12335 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12336 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12337 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12338 install_element(BGP_IPV6M_NODE,
12339 &neighbor_maximum_prefix_threshold_warning_cmd);
12340 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12341 install_element(BGP_IPV6M_NODE,
12342 &neighbor_maximum_prefix_threshold_restart_cmd);
12343 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12344 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12345 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12346 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12347 install_element(BGP_IPV6L_NODE,
12348 &neighbor_maximum_prefix_threshold_warning_cmd);
12349 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12350 install_element(BGP_IPV6L_NODE,
12351 &neighbor_maximum_prefix_threshold_restart_cmd);
12352 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12353 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12354 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12355 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12356 install_element(BGP_VPNV4_NODE,
12357 &neighbor_maximum_prefix_threshold_warning_cmd);
12358 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12359 install_element(BGP_VPNV4_NODE,
12360 &neighbor_maximum_prefix_threshold_restart_cmd);
12361 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12362 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12363 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12364 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12365 install_element(BGP_VPNV6_NODE,
12366 &neighbor_maximum_prefix_threshold_warning_cmd);
12367 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12368 install_element(BGP_VPNV6_NODE,
12369 &neighbor_maximum_prefix_threshold_restart_cmd);
12370 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12371
12372 /* "neighbor allowas-in" */
12373 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12374 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12375 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12376 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12377 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12378 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12379 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12380 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12381 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12382 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12383 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12384 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12385 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12386 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12387 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12388 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12389 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12390 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12391 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12392 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12393
12394 /* address-family commands. */
12395 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12396 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
12397 #ifdef KEEP_OLD_VPN_COMMANDS
12398 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12399 install_element(BGP_NODE, &address_family_vpnv6_cmd);
12400 #endif /* KEEP_OLD_VPN_COMMANDS */
12401
12402 install_element(BGP_NODE, &address_family_evpn_cmd);
12403
12404 /* "exit-address-family" command. */
12405 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12406 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12407 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12408 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12409 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12410 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12411 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12412 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12413 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12414
12415 /* "clear ip bgp commands" */
12416 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12417
12418 /* clear ip bgp prefix */
12419 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12420 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12421 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12422
12423 /* "show [ip] bgp summary" commands. */
12424 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
12425 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
12426 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
12427 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
12428 install_element(VIEW_NODE, &show_bgp_updgrps_adj_cmd);
12429 install_element(VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
12430 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
12431 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
12432 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
12433 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
12434 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12435 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
12436 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
12437 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
12438 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12439
12440 /* "show [ip] bgp neighbors" commands. */
12441 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12442
12443 /* "show [ip] bgp peer-group" commands. */
12444 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12445
12446 /* "show [ip] bgp paths" commands. */
12447 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12448
12449 /* "show [ip] bgp community" commands. */
12450 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12451
12452 /* "show ip bgp large-community" commands. */
12453 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12454 /* "show [ip] bgp attribute-info" commands. */
12455 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12456
12457 /* "redistribute" commands. */
12458 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12459 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12460 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12461 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12462 install_element(BGP_NODE,
12463 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12464 install_element(BGP_NODE,
12465 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12466 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12467 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12468 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12469 install_element(BGP_NODE,
12470 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12471 install_element(BGP_NODE,
12472 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12473 install_element(BGP_NODE,
12474 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12475 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12476 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12477 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12478 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12479 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12480 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12481 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12482 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12483 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12484 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12485 install_element(BGP_IPV4_NODE,
12486 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12487 install_element(BGP_IPV4_NODE,
12488 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12489 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12490 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12491 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12492 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12493 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12494 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12495
12496 /* ttl_security commands */
12497 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12498 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12499
12500 /* "show [ip] bgp memory" commands. */
12501 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12502
12503 /* "show bgp martian next-hop" */
12504 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12505
12506 /* "show [ip] bgp views" commands. */
12507 install_element(VIEW_NODE, &show_bgp_views_cmd);
12508
12509 /* "show [ip] bgp vrfs" commands. */
12510 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12511
12512 /* Community-list. */
12513 community_list_vty();
12514 }
12515
12516 #include "memory.h"
12517 #include "bgp_regex.h"
12518 #include "bgp_clist.h"
12519 #include "bgp_ecommunity.h"
12520
12521 /* VTY functions. */
12522
12523 /* Direction value to string conversion. */
12524 static const char *community_direct_str(int direct)
12525 {
12526 switch (direct) {
12527 case COMMUNITY_DENY:
12528 return "deny";
12529 case COMMUNITY_PERMIT:
12530 return "permit";
12531 default:
12532 return "unknown";
12533 }
12534 }
12535
12536 /* Display error string. */
12537 static void community_list_perror(struct vty *vty, int ret)
12538 {
12539 switch (ret) {
12540 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12541 vty_out(vty, "%% Can't find community-list\n");
12542 break;
12543 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12544 vty_out(vty, "%% Malformed community-list value\n");
12545 break;
12546 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12547 vty_out(vty,
12548 "%% Community name conflict, previously defined as standard community\n");
12549 break;
12550 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12551 vty_out(vty,
12552 "%% Community name conflict, previously defined as expanded community\n");
12553 break;
12554 }
12555 }
12556
12557 /* "community-list" keyword help string. */
12558 #define COMMUNITY_LIST_STR "Add a community list entry\n"
12559
12560 /* ip community-list standard */
12561 DEFUN (ip_community_list_standard,
12562 ip_community_list_standard_cmd,
12563 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
12564 IP_STR
12565 COMMUNITY_LIST_STR
12566 "Community list number (standard)\n"
12567 "Add an standard community-list entry\n"
12568 "Community list name\n"
12569 "Specify community to reject\n"
12570 "Specify community to accept\n"
12571 COMMUNITY_VAL_STR)
12572 {
12573 char *cl_name_or_number = NULL;
12574 int direct = 0;
12575 int style = COMMUNITY_LIST_STANDARD;
12576
12577 int idx = 0;
12578 argv_find(argv, argc, "(1-99)", &idx);
12579 argv_find(argv, argc, "WORD", &idx);
12580 cl_name_or_number = argv[idx]->arg;
12581 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12582 : COMMUNITY_DENY;
12583 argv_find(argv, argc, "AA:NN", &idx);
12584 char *str = argv_concat(argv, argc, idx);
12585
12586 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12587 style);
12588
12589 XFREE(MTYPE_TMP, str);
12590
12591 if (ret < 0) {
12592 /* Display error string. */
12593 community_list_perror(vty, ret);
12594 return CMD_WARNING_CONFIG_FAILED;
12595 }
12596
12597 return CMD_SUCCESS;
12598 }
12599
12600 DEFUN (no_ip_community_list_standard_all,
12601 no_ip_community_list_standard_all_cmd,
12602 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
12603 NO_STR
12604 IP_STR
12605 COMMUNITY_LIST_STR
12606 "Community list number (standard)\n"
12607 "Add an standard community-list entry\n"
12608 "Community list name\n"
12609 "Specify community to reject\n"
12610 "Specify community to accept\n"
12611 COMMUNITY_VAL_STR)
12612 {
12613 int delete_all = 0;
12614
12615 char *cl_name_or_number = NULL;
12616 int direct = 0;
12617 int style = COMMUNITY_LIST_STANDARD;
12618
12619 int idx = 0;
12620 argv_find(argv, argc, "(1-99)", &idx);
12621 argv_find(argv, argc, "WORD", &idx);
12622 cl_name_or_number = argv[idx]->arg;
12623 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12624 : COMMUNITY_DENY;
12625 argv_find(argv, argc, "AA:NN", &idx);
12626 char *str = argv_concat(argv, argc, idx);
12627
12628 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12629 direct, style, delete_all);
12630
12631 XFREE(MTYPE_TMP, str);
12632
12633 if (ret < 0) {
12634 community_list_perror(vty, ret);
12635 return CMD_WARNING_CONFIG_FAILED;
12636 }
12637
12638 return CMD_SUCCESS;
12639 }
12640
12641 /* ip community-list expanded */
12642 DEFUN (ip_community_list_expanded_all,
12643 ip_community_list_expanded_all_cmd,
12644 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
12645 IP_STR
12646 COMMUNITY_LIST_STR
12647 "Community list number (expanded)\n"
12648 "Add an expanded community-list entry\n"
12649 "Community list name\n"
12650 "Specify community to reject\n"
12651 "Specify community to accept\n"
12652 COMMUNITY_VAL_STR)
12653 {
12654 char *cl_name_or_number = NULL;
12655 int direct = 0;
12656 int style = COMMUNITY_LIST_EXPANDED;
12657
12658 int idx = 0;
12659 argv_find(argv, argc, "(100-500)", &idx);
12660 argv_find(argv, argc, "WORD", &idx);
12661 cl_name_or_number = argv[idx]->arg;
12662 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12663 : COMMUNITY_DENY;
12664 argv_find(argv, argc, "AA:NN", &idx);
12665 char *str = argv_concat(argv, argc, idx);
12666
12667 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12668 style);
12669
12670 XFREE(MTYPE_TMP, str);
12671
12672 if (ret < 0) {
12673 /* Display error string. */
12674 community_list_perror(vty, ret);
12675 return CMD_WARNING_CONFIG_FAILED;
12676 }
12677
12678 return CMD_SUCCESS;
12679 }
12680
12681 DEFUN (no_ip_community_list_expanded_all,
12682 no_ip_community_list_expanded_all_cmd,
12683 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
12684 NO_STR
12685 IP_STR
12686 COMMUNITY_LIST_STR
12687 "Community list number (expanded)\n"
12688 "Add an expanded community-list entry\n"
12689 "Community list name\n"
12690 "Specify community to reject\n"
12691 "Specify community to accept\n"
12692 COMMUNITY_VAL_STR)
12693 {
12694 int delete_all = 0;
12695
12696 char *cl_name_or_number = NULL;
12697 int direct = 0;
12698 int style = COMMUNITY_LIST_EXPANDED;
12699
12700 int idx = 0;
12701 argv_find(argv, argc, "(100-500)", &idx);
12702 argv_find(argv, argc, "WORD", &idx);
12703 cl_name_or_number = argv[idx]->arg;
12704 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12705 : COMMUNITY_DENY;
12706 argv_find(argv, argc, "AA:NN", &idx);
12707 char *str = argv_concat(argv, argc, idx);
12708
12709 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12710 direct, style, delete_all);
12711
12712 XFREE(MTYPE_TMP, str);
12713
12714 if (ret < 0) {
12715 community_list_perror(vty, ret);
12716 return CMD_WARNING_CONFIG_FAILED;
12717 }
12718
12719 return CMD_SUCCESS;
12720 }
12721
12722 static void community_list_show(struct vty *vty, struct community_list *list)
12723 {
12724 struct community_entry *entry;
12725
12726 for (entry = list->head; entry; entry = entry->next) {
12727 if (entry == list->head) {
12728 if (all_digit(list->name))
12729 vty_out(vty, "Community %s list %s\n",
12730 entry->style == COMMUNITY_LIST_STANDARD
12731 ? "standard"
12732 : "(expanded) access",
12733 list->name);
12734 else
12735 vty_out(vty, "Named Community %s list %s\n",
12736 entry->style == COMMUNITY_LIST_STANDARD
12737 ? "standard"
12738 : "expanded",
12739 list->name);
12740 }
12741 if (entry->any)
12742 vty_out(vty, " %s\n",
12743 community_direct_str(entry->direct));
12744 else
12745 vty_out(vty, " %s %s\n",
12746 community_direct_str(entry->direct),
12747 entry->style == COMMUNITY_LIST_STANDARD
12748 ? community_str(entry->u.com, false)
12749 : entry->config);
12750 }
12751 }
12752
12753 DEFUN (show_ip_community_list,
12754 show_ip_community_list_cmd,
12755 "show ip community-list",
12756 SHOW_STR
12757 IP_STR
12758 "List community-list\n")
12759 {
12760 struct community_list *list;
12761 struct community_list_master *cm;
12762
12763 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
12764 if (!cm)
12765 return CMD_SUCCESS;
12766
12767 for (list = cm->num.head; list; list = list->next)
12768 community_list_show(vty, list);
12769
12770 for (list = cm->str.head; list; list = list->next)
12771 community_list_show(vty, list);
12772
12773 return CMD_SUCCESS;
12774 }
12775
12776 DEFUN (show_ip_community_list_arg,
12777 show_ip_community_list_arg_cmd,
12778 "show ip community-list <(1-500)|WORD>",
12779 SHOW_STR
12780 IP_STR
12781 "List community-list\n"
12782 "Community-list number\n"
12783 "Community-list name\n")
12784 {
12785 int idx_comm_list = 3;
12786 struct community_list *list;
12787
12788 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
12789 COMMUNITY_LIST_MASTER);
12790 if (!list) {
12791 vty_out(vty, "%% Can't find community-list\n");
12792 return CMD_WARNING;
12793 }
12794
12795 community_list_show(vty, list);
12796
12797 return CMD_SUCCESS;
12798 }
12799
12800 /*
12801 * Large Community code.
12802 */
12803 static int lcommunity_list_set_vty(struct vty *vty, int argc,
12804 struct cmd_token **argv, int style,
12805 int reject_all_digit_name)
12806 {
12807 int ret;
12808 int direct;
12809 char *str;
12810 int idx = 0;
12811 char *cl_name;
12812
12813 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12814 : COMMUNITY_DENY;
12815
12816 /* All digit name check. */
12817 idx = 0;
12818 argv_find(argv, argc, "WORD", &idx);
12819 argv_find(argv, argc, "(1-99)", &idx);
12820 argv_find(argv, argc, "(100-500)", &idx);
12821 cl_name = argv[idx]->arg;
12822 if (reject_all_digit_name && all_digit(cl_name)) {
12823 vty_out(vty, "%% Community name cannot have all digits\n");
12824 return CMD_WARNING_CONFIG_FAILED;
12825 }
12826
12827 idx = 0;
12828 argv_find(argv, argc, "AA:BB:CC", &idx);
12829 argv_find(argv, argc, "LINE", &idx);
12830 /* Concat community string argument. */
12831 if (idx)
12832 str = argv_concat(argv, argc, idx);
12833 else
12834 str = NULL;
12835
12836 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
12837
12838 /* Free temporary community list string allocated by
12839 argv_concat(). */
12840 if (str)
12841 XFREE(MTYPE_TMP, str);
12842
12843 if (ret < 0) {
12844 community_list_perror(vty, ret);
12845 return CMD_WARNING_CONFIG_FAILED;
12846 }
12847 return CMD_SUCCESS;
12848 }
12849
12850 static int lcommunity_list_unset_vty(struct vty *vty, int argc,
12851 struct cmd_token **argv, int style)
12852 {
12853 int ret;
12854 int direct = 0;
12855 char *str = NULL;
12856 int idx = 0;
12857
12858 argv_find(argv, argc, "permit", &idx);
12859 argv_find(argv, argc, "deny", &idx);
12860
12861 if (idx) {
12862 /* Check the list direct. */
12863 if (strncmp(argv[idx]->arg, "p", 1) == 0)
12864 direct = COMMUNITY_PERMIT;
12865 else
12866 direct = COMMUNITY_DENY;
12867
12868 idx = 0;
12869 argv_find(argv, argc, "LINE", &idx);
12870 argv_find(argv, argc, "AA:AA:NN", &idx);
12871 /* Concat community string argument. */
12872 str = argv_concat(argv, argc, idx);
12873 }
12874
12875 idx = 0;
12876 argv_find(argv, argc, "(1-99)", &idx);
12877 argv_find(argv, argc, "(100-500)", &idx);
12878 argv_find(argv, argc, "WORD", &idx);
12879
12880 /* Unset community list. */
12881 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
12882 style);
12883
12884 /* Free temporary community list string allocated by
12885 argv_concat(). */
12886 if (str)
12887 XFREE(MTYPE_TMP, str);
12888
12889 if (ret < 0) {
12890 community_list_perror(vty, ret);
12891 return CMD_WARNING_CONFIG_FAILED;
12892 }
12893
12894 return CMD_SUCCESS;
12895 }
12896
12897 /* "large-community-list" keyword help string. */
12898 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12899 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12900
12901 DEFUN (ip_lcommunity_list_standard,
12902 ip_lcommunity_list_standard_cmd,
12903 "ip large-community-list (1-99) <deny|permit>",
12904 IP_STR
12905 LCOMMUNITY_LIST_STR
12906 "Large Community list number (standard)\n"
12907 "Specify large community to reject\n"
12908 "Specify large community to accept\n")
12909 {
12910 return lcommunity_list_set_vty(vty, argc, argv,
12911 LARGE_COMMUNITY_LIST_STANDARD, 0);
12912 }
12913
12914 DEFUN (ip_lcommunity_list_standard1,
12915 ip_lcommunity_list_standard1_cmd,
12916 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
12917 IP_STR
12918 LCOMMUNITY_LIST_STR
12919 "Large Community list number (standard)\n"
12920 "Specify large community to reject\n"
12921 "Specify large community to accept\n"
12922 LCOMMUNITY_VAL_STR)
12923 {
12924 return lcommunity_list_set_vty(vty, argc, argv,
12925 LARGE_COMMUNITY_LIST_STANDARD, 0);
12926 }
12927
12928 DEFUN (ip_lcommunity_list_expanded,
12929 ip_lcommunity_list_expanded_cmd,
12930 "ip large-community-list (100-500) <deny|permit> LINE...",
12931 IP_STR
12932 LCOMMUNITY_LIST_STR
12933 "Large Community list number (expanded)\n"
12934 "Specify large community to reject\n"
12935 "Specify large community to accept\n"
12936 "An ordered list as a regular-expression\n")
12937 {
12938 return lcommunity_list_set_vty(vty, argc, argv,
12939 LARGE_COMMUNITY_LIST_EXPANDED, 0);
12940 }
12941
12942 DEFUN (ip_lcommunity_list_name_standard,
12943 ip_lcommunity_list_name_standard_cmd,
12944 "ip large-community-list standard WORD <deny|permit>",
12945 IP_STR
12946 LCOMMUNITY_LIST_STR
12947 "Specify standard large-community-list\n"
12948 "Large Community list name\n"
12949 "Specify large community to reject\n"
12950 "Specify large community to accept\n")
12951 {
12952 return lcommunity_list_set_vty(vty, argc, argv,
12953 LARGE_COMMUNITY_LIST_STANDARD, 1);
12954 }
12955
12956 DEFUN (ip_lcommunity_list_name_standard1,
12957 ip_lcommunity_list_name_standard1_cmd,
12958 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
12959 IP_STR
12960 LCOMMUNITY_LIST_STR
12961 "Specify standard large-community-list\n"
12962 "Large Community list name\n"
12963 "Specify large community to reject\n"
12964 "Specify large community to accept\n"
12965 LCOMMUNITY_VAL_STR)
12966 {
12967 return lcommunity_list_set_vty(vty, argc, argv,
12968 LARGE_COMMUNITY_LIST_STANDARD, 1);
12969 }
12970
12971 DEFUN (ip_lcommunity_list_name_expanded,
12972 ip_lcommunity_list_name_expanded_cmd,
12973 "ip large-community-list expanded WORD <deny|permit> LINE...",
12974 IP_STR
12975 LCOMMUNITY_LIST_STR
12976 "Specify expanded large-community-list\n"
12977 "Large Community list name\n"
12978 "Specify large community to reject\n"
12979 "Specify large community to accept\n"
12980 "An ordered list as a regular-expression\n")
12981 {
12982 return lcommunity_list_set_vty(vty, argc, argv,
12983 LARGE_COMMUNITY_LIST_EXPANDED, 1);
12984 }
12985
12986 DEFUN (no_ip_lcommunity_list_standard_all,
12987 no_ip_lcommunity_list_standard_all_cmd,
12988 "no ip large-community-list <(1-99)|(100-500)|WORD>",
12989 NO_STR
12990 IP_STR
12991 LCOMMUNITY_LIST_STR
12992 "Large Community list number (standard)\n"
12993 "Large Community list number (expanded)\n"
12994 "Large Community list name\n")
12995 {
12996 return lcommunity_list_unset_vty(vty, argc, argv,
12997 LARGE_COMMUNITY_LIST_STANDARD);
12998 }
12999
13000 DEFUN (no_ip_lcommunity_list_name_expanded_all,
13001 no_ip_lcommunity_list_name_expanded_all_cmd,
13002 "no ip large-community-list expanded WORD",
13003 NO_STR
13004 IP_STR
13005 LCOMMUNITY_LIST_STR
13006 "Specify expanded large-community-list\n"
13007 "Large Community list name\n")
13008 {
13009 return lcommunity_list_unset_vty(vty, argc, argv,
13010 LARGE_COMMUNITY_LIST_EXPANDED);
13011 }
13012
13013 DEFUN (no_ip_lcommunity_list_standard,
13014 no_ip_lcommunity_list_standard_cmd,
13015 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13016 NO_STR
13017 IP_STR
13018 LCOMMUNITY_LIST_STR
13019 "Large Community list number (standard)\n"
13020 "Specify large community to reject\n"
13021 "Specify large community to accept\n"
13022 LCOMMUNITY_VAL_STR)
13023 {
13024 return lcommunity_list_unset_vty(vty, argc, argv,
13025 LARGE_COMMUNITY_LIST_STANDARD);
13026 }
13027
13028 DEFUN (no_ip_lcommunity_list_expanded,
13029 no_ip_lcommunity_list_expanded_cmd,
13030 "no ip large-community-list (100-500) <deny|permit> LINE...",
13031 NO_STR
13032 IP_STR
13033 LCOMMUNITY_LIST_STR
13034 "Large Community list number (expanded)\n"
13035 "Specify large community to reject\n"
13036 "Specify large community to accept\n"
13037 "An ordered list as a regular-expression\n")
13038 {
13039 return lcommunity_list_unset_vty(vty, argc, argv,
13040 LARGE_COMMUNITY_LIST_EXPANDED);
13041 }
13042
13043 DEFUN (no_ip_lcommunity_list_name_standard,
13044 no_ip_lcommunity_list_name_standard_cmd,
13045 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13046 NO_STR
13047 IP_STR
13048 LCOMMUNITY_LIST_STR
13049 "Specify standard large-community-list\n"
13050 "Large Community list name\n"
13051 "Specify large community to reject\n"
13052 "Specify large community to accept\n"
13053 LCOMMUNITY_VAL_STR)
13054 {
13055 return lcommunity_list_unset_vty(vty, argc, argv,
13056 LARGE_COMMUNITY_LIST_STANDARD);
13057 }
13058
13059 DEFUN (no_ip_lcommunity_list_name_expanded,
13060 no_ip_lcommunity_list_name_expanded_cmd,
13061 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13062 NO_STR
13063 IP_STR
13064 LCOMMUNITY_LIST_STR
13065 "Specify expanded large-community-list\n"
13066 "Large community list name\n"
13067 "Specify large community to reject\n"
13068 "Specify large community to accept\n"
13069 "An ordered list as a regular-expression\n")
13070 {
13071 return lcommunity_list_unset_vty(vty, argc, argv,
13072 LARGE_COMMUNITY_LIST_EXPANDED);
13073 }
13074
13075 static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13076 {
13077 struct community_entry *entry;
13078
13079 for (entry = list->head; entry; entry = entry->next) {
13080 if (entry == list->head) {
13081 if (all_digit(list->name))
13082 vty_out(vty, "Large community %s list %s\n",
13083 entry->style == EXTCOMMUNITY_LIST_STANDARD
13084 ? "standard"
13085 : "(expanded) access",
13086 list->name);
13087 else
13088 vty_out(vty,
13089 "Named large community %s list %s\n",
13090 entry->style == EXTCOMMUNITY_LIST_STANDARD
13091 ? "standard"
13092 : "expanded",
13093 list->name);
13094 }
13095 if (entry->any)
13096 vty_out(vty, " %s\n",
13097 community_direct_str(entry->direct));
13098 else
13099 vty_out(vty, " %s %s\n",
13100 community_direct_str(entry->direct),
13101 entry->style == EXTCOMMUNITY_LIST_STANDARD
13102 ? entry->u.ecom->str
13103 : entry->config);
13104 }
13105 }
13106
13107 DEFUN (show_ip_lcommunity_list,
13108 show_ip_lcommunity_list_cmd,
13109 "show ip large-community-list",
13110 SHOW_STR
13111 IP_STR
13112 "List large-community list\n")
13113 {
13114 struct community_list *list;
13115 struct community_list_master *cm;
13116
13117 cm = community_list_master_lookup(bgp_clist,
13118 LARGE_COMMUNITY_LIST_MASTER);
13119 if (!cm)
13120 return CMD_SUCCESS;
13121
13122 for (list = cm->num.head; list; list = list->next)
13123 lcommunity_list_show(vty, list);
13124
13125 for (list = cm->str.head; list; list = list->next)
13126 lcommunity_list_show(vty, list);
13127
13128 return CMD_SUCCESS;
13129 }
13130
13131 DEFUN (show_ip_lcommunity_list_arg,
13132 show_ip_lcommunity_list_arg_cmd,
13133 "show ip large-community-list <(1-500)|WORD>",
13134 SHOW_STR
13135 IP_STR
13136 "List large-community list\n"
13137 "large-community-list number\n"
13138 "large-community-list name\n")
13139 {
13140 struct community_list *list;
13141
13142 list = community_list_lookup(bgp_clist, argv[3]->arg,
13143 LARGE_COMMUNITY_LIST_MASTER);
13144 if (!list) {
13145 vty_out(vty, "%% Can't find extcommunity-list\n");
13146 return CMD_WARNING;
13147 }
13148
13149 lcommunity_list_show(vty, list);
13150
13151 return CMD_SUCCESS;
13152 }
13153
13154 /* "extcommunity-list" keyword help string. */
13155 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13156 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13157
13158 DEFUN (ip_extcommunity_list_standard,
13159 ip_extcommunity_list_standard_cmd,
13160 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13161 IP_STR
13162 EXTCOMMUNITY_LIST_STR
13163 "Extended Community list number (standard)\n"
13164 "Specify standard extcommunity-list\n"
13165 "Community list name\n"
13166 "Specify community to reject\n"
13167 "Specify community to accept\n"
13168 EXTCOMMUNITY_VAL_STR)
13169 {
13170 int style = EXTCOMMUNITY_LIST_STANDARD;
13171 int direct = 0;
13172 char *cl_number_or_name = NULL;
13173
13174 int idx = 0;
13175 argv_find(argv, argc, "(1-99)", &idx);
13176 argv_find(argv, argc, "WORD", &idx);
13177 cl_number_or_name = argv[idx]->arg;
13178 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13179 : COMMUNITY_DENY;
13180 argv_find(argv, argc, "AA:NN", &idx);
13181 char *str = argv_concat(argv, argc, idx);
13182
13183 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13184 direct, style);
13185
13186 XFREE(MTYPE_TMP, str);
13187
13188 if (ret < 0) {
13189 community_list_perror(vty, ret);
13190 return CMD_WARNING_CONFIG_FAILED;
13191 }
13192
13193 return CMD_SUCCESS;
13194 }
13195
13196 DEFUN (ip_extcommunity_list_name_expanded,
13197 ip_extcommunity_list_name_expanded_cmd,
13198 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
13199 IP_STR
13200 EXTCOMMUNITY_LIST_STR
13201 "Extended Community list number (expanded)\n"
13202 "Specify expanded extcommunity-list\n"
13203 "Extended Community list name\n"
13204 "Specify community to reject\n"
13205 "Specify community to accept\n"
13206 "An ordered list as a regular-expression\n")
13207 {
13208 int style = EXTCOMMUNITY_LIST_EXPANDED;
13209 int direct = 0;
13210 char *cl_number_or_name = NULL;
13211
13212 int idx = 0;
13213 argv_find(argv, argc, "(100-500)", &idx);
13214 argv_find(argv, argc, "WORD", &idx);
13215 cl_number_or_name = argv[idx]->arg;
13216 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13217 : COMMUNITY_DENY;
13218 argv_find(argv, argc, "LINE", &idx);
13219 char *str = argv_concat(argv, argc, idx);
13220
13221 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13222 direct, style);
13223
13224 XFREE(MTYPE_TMP, str);
13225
13226 if (ret < 0) {
13227 community_list_perror(vty, ret);
13228 return CMD_WARNING_CONFIG_FAILED;
13229 }
13230
13231 return CMD_SUCCESS;
13232 }
13233
13234 DEFUN (no_ip_extcommunity_list_standard_all,
13235 no_ip_extcommunity_list_standard_all_cmd,
13236 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
13237 NO_STR
13238 IP_STR
13239 EXTCOMMUNITY_LIST_STR
13240 "Extended Community list number (standard)\n"
13241 "Specify standard extcommunity-list\n"
13242 "Community list name\n"
13243 "Specify community to reject\n"
13244 "Specify community to accept\n"
13245 EXTCOMMUNITY_VAL_STR)
13246 {
13247 int deleteall = 0;
13248
13249 int style = EXTCOMMUNITY_LIST_STANDARD;
13250 int direct = 0;
13251 char *cl_number_or_name = NULL;
13252
13253 int idx = 0;
13254 argv_find(argv, argc, "(1-99)", &idx);
13255 argv_find(argv, argc, "WORD", &idx);
13256 cl_number_or_name = argv[idx]->arg;
13257 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13258 : COMMUNITY_DENY;
13259 argv_find(argv, argc, "AA:NN", &idx);
13260 char *str = argv_concat(argv, argc, idx);
13261
13262 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13263 direct, style, deleteall);
13264
13265 XFREE(MTYPE_TMP, str);
13266
13267 if (ret < 0) {
13268 community_list_perror(vty, ret);
13269 return CMD_WARNING_CONFIG_FAILED;
13270 }
13271
13272 return CMD_SUCCESS;
13273 }
13274
13275 DEFUN (no_ip_extcommunity_list_expanded_all,
13276 no_ip_extcommunity_list_expanded_all_cmd,
13277 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
13278 NO_STR
13279 IP_STR
13280 EXTCOMMUNITY_LIST_STR
13281 "Extended Community list number (expanded)\n"
13282 "Specify expanded extcommunity-list\n"
13283 "Extended Community list name\n"
13284 "Specify community to reject\n"
13285 "Specify community to accept\n"
13286 "An ordered list as a regular-expression\n")
13287 {
13288 int deleteall = 0;
13289
13290 int style = EXTCOMMUNITY_LIST_EXPANDED;
13291 int direct = 0;
13292 char *cl_number_or_name = NULL;
13293
13294 int idx = 0;
13295 argv_find(argv, argc, "(100-500)", &idx);
13296 argv_find(argv, argc, "WORD", &idx);
13297 cl_number_or_name = argv[idx]->arg;
13298 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13299 : COMMUNITY_DENY;
13300 argv_find(argv, argc, "LINE", &idx);
13301 char *str = argv_concat(argv, argc, idx);
13302
13303 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13304 direct, style, deleteall);
13305
13306 XFREE(MTYPE_TMP, str);
13307
13308 if (ret < 0) {
13309 community_list_perror(vty, ret);
13310 return CMD_WARNING_CONFIG_FAILED;
13311 }
13312
13313 return CMD_SUCCESS;
13314 }
13315
13316 static void extcommunity_list_show(struct vty *vty, struct community_list *list)
13317 {
13318 struct community_entry *entry;
13319
13320 for (entry = list->head; entry; entry = entry->next) {
13321 if (entry == list->head) {
13322 if (all_digit(list->name))
13323 vty_out(vty, "Extended community %s list %s\n",
13324 entry->style == EXTCOMMUNITY_LIST_STANDARD
13325 ? "standard"
13326 : "(expanded) access",
13327 list->name);
13328 else
13329 vty_out(vty,
13330 "Named extended community %s list %s\n",
13331 entry->style == EXTCOMMUNITY_LIST_STANDARD
13332 ? "standard"
13333 : "expanded",
13334 list->name);
13335 }
13336 if (entry->any)
13337 vty_out(vty, " %s\n",
13338 community_direct_str(entry->direct));
13339 else
13340 vty_out(vty, " %s %s\n",
13341 community_direct_str(entry->direct),
13342 entry->style == EXTCOMMUNITY_LIST_STANDARD
13343 ? entry->u.ecom->str
13344 : entry->config);
13345 }
13346 }
13347
13348 DEFUN (show_ip_extcommunity_list,
13349 show_ip_extcommunity_list_cmd,
13350 "show ip extcommunity-list",
13351 SHOW_STR
13352 IP_STR
13353 "List extended-community list\n")
13354 {
13355 struct community_list *list;
13356 struct community_list_master *cm;
13357
13358 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13359 if (!cm)
13360 return CMD_SUCCESS;
13361
13362 for (list = cm->num.head; list; list = list->next)
13363 extcommunity_list_show(vty, list);
13364
13365 for (list = cm->str.head; list; list = list->next)
13366 extcommunity_list_show(vty, list);
13367
13368 return CMD_SUCCESS;
13369 }
13370
13371 DEFUN (show_ip_extcommunity_list_arg,
13372 show_ip_extcommunity_list_arg_cmd,
13373 "show ip extcommunity-list <(1-500)|WORD>",
13374 SHOW_STR
13375 IP_STR
13376 "List extended-community list\n"
13377 "Extcommunity-list number\n"
13378 "Extcommunity-list name\n")
13379 {
13380 int idx_comm_list = 3;
13381 struct community_list *list;
13382
13383 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13384 EXTCOMMUNITY_LIST_MASTER);
13385 if (!list) {
13386 vty_out(vty, "%% Can't find extcommunity-list\n");
13387 return CMD_WARNING;
13388 }
13389
13390 extcommunity_list_show(vty, list);
13391
13392 return CMD_SUCCESS;
13393 }
13394
13395 /* Return configuration string of community-list entry. */
13396 static const char *community_list_config_str(struct community_entry *entry)
13397 {
13398 const char *str;
13399
13400 if (entry->any)
13401 str = "";
13402 else {
13403 if (entry->style == COMMUNITY_LIST_STANDARD)
13404 str = community_str(entry->u.com, false);
13405 else
13406 str = entry->config;
13407 }
13408 return str;
13409 }
13410
13411 /* Display community-list and extcommunity-list configuration. */
13412 static int community_list_config_write(struct vty *vty)
13413 {
13414 struct community_list *list;
13415 struct community_entry *entry;
13416 struct community_list_master *cm;
13417 int write = 0;
13418
13419 /* Community-list. */
13420 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13421
13422 for (list = cm->num.head; list; list = list->next)
13423 for (entry = list->head; entry; entry = entry->next) {
13424 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13425 community_direct_str(entry->direct),
13426 community_list_config_str(entry));
13427 write++;
13428 }
13429 for (list = cm->str.head; list; list = list->next)
13430 for (entry = list->head; entry; entry = entry->next) {
13431 vty_out(vty, "ip community-list %s %s %s %s\n",
13432 entry->style == COMMUNITY_LIST_STANDARD
13433 ? "standard"
13434 : "expanded",
13435 list->name, community_direct_str(entry->direct),
13436 community_list_config_str(entry));
13437 write++;
13438 }
13439
13440 /* Extcommunity-list. */
13441 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13442
13443 for (list = cm->num.head; list; list = list->next)
13444 for (entry = list->head; entry; entry = entry->next) {
13445 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13446 list->name, community_direct_str(entry->direct),
13447 community_list_config_str(entry));
13448 write++;
13449 }
13450 for (list = cm->str.head; list; list = list->next)
13451 for (entry = list->head; entry; entry = entry->next) {
13452 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13453 entry->style == EXTCOMMUNITY_LIST_STANDARD
13454 ? "standard"
13455 : "expanded",
13456 list->name, community_direct_str(entry->direct),
13457 community_list_config_str(entry));
13458 write++;
13459 }
13460
13461
13462 /* lcommunity-list. */
13463 cm = community_list_master_lookup(bgp_clist,
13464 LARGE_COMMUNITY_LIST_MASTER);
13465
13466 for (list = cm->num.head; list; list = list->next)
13467 for (entry = list->head; entry; entry = entry->next) {
13468 vty_out(vty, "ip large-community-list %s %s %s\n",
13469 list->name, community_direct_str(entry->direct),
13470 community_list_config_str(entry));
13471 write++;
13472 }
13473 for (list = cm->str.head; list; list = list->next)
13474 for (entry = list->head; entry; entry = entry->next) {
13475 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13476 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13477 ? "standard"
13478 : "expanded",
13479 list->name, community_direct_str(entry->direct),
13480 community_list_config_str(entry));
13481 write++;
13482 }
13483
13484 return write;
13485 }
13486
13487 static struct cmd_node community_list_node = {
13488 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
13489 };
13490
13491 static void community_list_vty(void)
13492 {
13493 install_node(&community_list_node, community_list_config_write);
13494
13495 /* Community-list. */
13496 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13497 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13498 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13499 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13500 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13501 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13502
13503 /* Extcommunity-list. */
13504 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13505 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13506 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13507 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13508 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13509 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13510
13511 /* Large Community List */
13512 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13513 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13514 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13515 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13516 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13517 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13518 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13519 install_element(CONFIG_NODE,
13520 &no_ip_lcommunity_list_name_expanded_all_cmd);
13521 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13522 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13523 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13524 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13525 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13526 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
13527 }