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