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