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