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