]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_vty.c
Merge pull request #439 from Jafaral/pim_rpgrp-fix
[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)
3376 ret = peer_flag_set (peer, flag);
3377 else
3378 ret = peer_flag_unset (peer, flag);
3379
3380 return bgp_vty_return (vty, ret);
3381 }
3382
3383 static int
3384 peer_flag_set_vty (struct vty *vty, const char *ip_str, u_int16_t flag)
3385 {
3386 return peer_flag_modify_vty (vty, ip_str, flag, 1);
3387 }
3388
3389 static int
3390 peer_flag_unset_vty (struct vty *vty, const char *ip_str, u_int16_t flag)
3391 {
3392 return peer_flag_modify_vty (vty, ip_str, flag, 0);
3393 }
3394
3395 /* neighbor passive. */
3396 DEFUN (neighbor_passive,
3397 neighbor_passive_cmd,
3398 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3399 NEIGHBOR_STR
3400 NEIGHBOR_ADDR_STR2
3401 "Don't send open messages to this neighbor\n")
3402 {
3403 int idx_peer = 1;
3404 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3405 }
3406
3407 DEFUN (no_neighbor_passive,
3408 no_neighbor_passive_cmd,
3409 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
3410 NO_STR
3411 NEIGHBOR_STR
3412 NEIGHBOR_ADDR_STR2
3413 "Don't send open messages to this neighbor\n")
3414 {
3415 int idx_peer = 2;
3416 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
3417 }
3418
3419 /* neighbor shutdown. */
3420 DEFUN (neighbor_shutdown_msg,
3421 neighbor_shutdown_msg_cmd,
3422 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3423 NEIGHBOR_STR
3424 NEIGHBOR_ADDR_STR2
3425 "Administratively shut down this neighbor\n"
3426 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3427 "Shutdown message\n")
3428 {
3429 int idx_peer = 1;
3430
3431 if (argc >= 5)
3432 {
3433 struct peer *peer = peer_lookup_vty (vty, argv[idx_peer]->arg);
3434 char *message;
3435
3436 message = argv_concat (argv, argc, 4);
3437 peer_tx_shutdown_message_set (peer, message);
3438 XFREE (MTYPE_TMP, message);
3439 }
3440
3441 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3442 }
3443
3444 ALIAS (neighbor_shutdown_msg,
3445 neighbor_shutdown_cmd,
3446 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3447 NEIGHBOR_STR
3448 NEIGHBOR_ADDR_STR2
3449 "Administratively shut down this neighbor\n")
3450
3451 DEFUN (no_neighbor_shutdown_msg,
3452 no_neighbor_shutdown_msg_cmd,
3453 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3454 NO_STR
3455 NEIGHBOR_STR
3456 NEIGHBOR_ADDR_STR2
3457 "Administratively shut down this neighbor\n"
3458 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3459 "Shutdown message\n")
3460 {
3461 int idx_peer = 2;
3462
3463 struct peer *peer = peer_lookup_vty (vty, argv[idx_peer]->arg);
3464 peer_tx_shutdown_message_unset (peer);
3465
3466 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
3467 }
3468
3469 ALIAS (no_neighbor_shutdown_msg,
3470 no_neighbor_shutdown_cmd,
3471 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3472 NO_STR
3473 NEIGHBOR_STR
3474 NEIGHBOR_ADDR_STR2
3475 "Administratively shut down this neighbor\n")
3476
3477 /* neighbor capability dynamic. */
3478 DEFUN (neighbor_capability_dynamic,
3479 neighbor_capability_dynamic_cmd,
3480 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3481 NEIGHBOR_STR
3482 NEIGHBOR_ADDR_STR2
3483 "Advertise capability to the peer\n"
3484 "Advertise dynamic capability to this neighbor\n")
3485 {
3486 int idx_peer = 1;
3487 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DYNAMIC_CAPABILITY);
3488 }
3489
3490 DEFUN (no_neighbor_capability_dynamic,
3491 no_neighbor_capability_dynamic_cmd,
3492 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
3493 NO_STR
3494 NEIGHBOR_STR
3495 NEIGHBOR_ADDR_STR2
3496 "Advertise capability to the peer\n"
3497 "Advertise dynamic capability to this neighbor\n")
3498 {
3499 int idx_peer = 2;
3500 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DYNAMIC_CAPABILITY);
3501 }
3502
3503 /* neighbor dont-capability-negotiate */
3504 DEFUN (neighbor_dont_capability_negotiate,
3505 neighbor_dont_capability_negotiate_cmd,
3506 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3507 NEIGHBOR_STR
3508 NEIGHBOR_ADDR_STR2
3509 "Do not perform capability negotiation\n")
3510 {
3511 int idx_peer = 1;
3512 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DONT_CAPABILITY);
3513 }
3514
3515 DEFUN (no_neighbor_dont_capability_negotiate,
3516 no_neighbor_dont_capability_negotiate_cmd,
3517 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
3518 NO_STR
3519 NEIGHBOR_STR
3520 NEIGHBOR_ADDR_STR2
3521 "Do not perform capability negotiation\n")
3522 {
3523 int idx_peer = 2;
3524 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DONT_CAPABILITY);
3525 }
3526
3527 /* neighbor capability extended next hop encoding */
3528 DEFUN (neighbor_capability_enhe,
3529 neighbor_capability_enhe_cmd,
3530 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3531 NEIGHBOR_STR
3532 NEIGHBOR_ADDR_STR2
3533 "Advertise capability to the peer\n"
3534 "Advertise extended next-hop capability to the peer\n")
3535 {
3536 int idx_peer = 1;
3537 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_CAPABILITY_ENHE);
3538 }
3539
3540 DEFUN (no_neighbor_capability_enhe,
3541 no_neighbor_capability_enhe_cmd,
3542 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
3543 NO_STR
3544 NEIGHBOR_STR
3545 NEIGHBOR_ADDR_STR2
3546 "Advertise capability to the peer\n"
3547 "Advertise extended next-hop capability to the peer\n")
3548 {
3549 int idx_peer = 2;
3550 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_CAPABILITY_ENHE);
3551 }
3552
3553 static int
3554 peer_af_flag_modify_vty (struct vty *vty, const char *peer_str, afi_t afi,
3555 safi_t safi, u_int32_t flag, int set)
3556 {
3557 int ret;
3558 struct peer *peer;
3559
3560 peer = peer_and_group_lookup_vty (vty, peer_str);
3561 if (! peer)
3562 return CMD_WARNING;
3563
3564 if (set)
3565 ret = peer_af_flag_set (peer, afi, safi, flag);
3566 else
3567 ret = peer_af_flag_unset (peer, afi, safi, flag);
3568
3569 return bgp_vty_return (vty, ret);
3570 }
3571
3572 static int
3573 peer_af_flag_set_vty (struct vty *vty, const char *peer_str, afi_t afi,
3574 safi_t safi, u_int32_t flag)
3575 {
3576 return peer_af_flag_modify_vty (vty, peer_str, afi, safi, flag, 1);
3577 }
3578
3579 static int
3580 peer_af_flag_unset_vty (struct vty *vty, const char *peer_str, afi_t afi,
3581 safi_t safi, u_int32_t flag)
3582 {
3583 return peer_af_flag_modify_vty (vty, peer_str, afi, safi, flag, 0);
3584 }
3585
3586 /* neighbor capability orf prefix-list. */
3587 DEFUN (neighbor_capability_orf_prefix,
3588 neighbor_capability_orf_prefix_cmd,
3589 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3590 NEIGHBOR_STR
3591 NEIGHBOR_ADDR_STR2
3592 "Advertise capability to the peer\n"
3593 "Advertise ORF capability to the peer\n"
3594 "Advertise prefixlist ORF capability to this neighbor\n"
3595 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3596 "Capability to RECEIVE the ORF from this neighbor\n"
3597 "Capability to SEND the ORF to this neighbor\n")
3598 {
3599 int idx_peer = 1;
3600 int idx_send_recv = 5;
3601 u_int16_t flag = 0;
3602
3603 if (strncmp (argv[idx_send_recv]->arg, "s", 1) == 0)
3604 flag = PEER_FLAG_ORF_PREFIX_SM;
3605 else if (strncmp (argv[idx_send_recv]->arg, "r", 1) == 0)
3606 flag = PEER_FLAG_ORF_PREFIX_RM;
3607 else if (strncmp (argv[idx_send_recv]->arg, "b", 1) == 0)
3608 flag = PEER_FLAG_ORF_PREFIX_SM|PEER_FLAG_ORF_PREFIX_RM;
3609 else
3610 return CMD_WARNING;
3611
3612 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3613 bgp_node_safi (vty), flag);
3614 }
3615
3616 DEFUN (no_neighbor_capability_orf_prefix,
3617 no_neighbor_capability_orf_prefix_cmd,
3618 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3619 NO_STR
3620 NEIGHBOR_STR
3621 NEIGHBOR_ADDR_STR2
3622 "Advertise capability to the peer\n"
3623 "Advertise ORF capability to the peer\n"
3624 "Advertise prefixlist ORF capability to this neighbor\n"
3625 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3626 "Capability to RECEIVE the ORF from this neighbor\n"
3627 "Capability to SEND the ORF to this neighbor\n")
3628 {
3629 int idx_peer = 2;
3630 int idx_send_recv = 6;
3631 u_int16_t flag = 0;
3632
3633 if (strncmp (argv[idx_send_recv]->arg, "s", 1) == 0)
3634 flag = PEER_FLAG_ORF_PREFIX_SM;
3635 else if (strncmp (argv[idx_send_recv]->arg, "r", 1) == 0)
3636 flag = PEER_FLAG_ORF_PREFIX_RM;
3637 else if (strncmp (argv[idx_send_recv]->arg, "b", 1) == 0)
3638 flag = PEER_FLAG_ORF_PREFIX_SM|PEER_FLAG_ORF_PREFIX_RM;
3639 else
3640 return CMD_WARNING;
3641
3642 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3643 bgp_node_safi (vty), flag);
3644 }
3645
3646 /* neighbor next-hop-self. */
3647 DEFUN (neighbor_nexthop_self,
3648 neighbor_nexthop_self_cmd,
3649 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3650 NEIGHBOR_STR
3651 NEIGHBOR_ADDR_STR2
3652 "Disable the next hop calculation for this neighbor\n")
3653 {
3654 int idx_peer = 1;
3655 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3656 bgp_node_safi (vty), PEER_FLAG_NEXTHOP_SELF);
3657 }
3658
3659 /* neighbor next-hop-self. */
3660 DEFUN (neighbor_nexthop_self_force,
3661 neighbor_nexthop_self_force_cmd,
3662 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3663 NEIGHBOR_STR
3664 NEIGHBOR_ADDR_STR2
3665 "Disable the next hop calculation for this neighbor\n"
3666 "Set the next hop to self for reflected routes\n")
3667 {
3668 int idx_peer = 1;
3669 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3670 bgp_node_safi (vty),
3671 PEER_FLAG_FORCE_NEXTHOP_SELF);
3672 }
3673
3674 DEFUN (no_neighbor_nexthop_self,
3675 no_neighbor_nexthop_self_cmd,
3676 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3677 NO_STR
3678 NEIGHBOR_STR
3679 NEIGHBOR_ADDR_STR2
3680 "Disable the next hop calculation for this neighbor\n")
3681 {
3682 int idx_peer = 2;
3683 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3684 bgp_node_safi (vty),
3685 PEER_FLAG_NEXTHOP_SELF);
3686 }
3687
3688 DEFUN (no_neighbor_nexthop_self_force,
3689 no_neighbor_nexthop_self_force_cmd,
3690 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3691 NO_STR
3692 NEIGHBOR_STR
3693 NEIGHBOR_ADDR_STR2
3694 "Disable the next hop calculation for this neighbor\n"
3695 "Set the next hop to self for reflected routes\n")
3696 {
3697 int idx_peer = 2;
3698 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3699 bgp_node_safi (vty),
3700 PEER_FLAG_FORCE_NEXTHOP_SELF);
3701 }
3702
3703 /* neighbor as-override */
3704 DEFUN (neighbor_as_override,
3705 neighbor_as_override_cmd,
3706 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3707 NEIGHBOR_STR
3708 NEIGHBOR_ADDR_STR2
3709 "Override ASNs in outbound updates if aspath equals remote-as\n")
3710 {
3711 int idx_peer = 1;
3712 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3713 bgp_node_safi (vty),
3714 PEER_FLAG_AS_OVERRIDE);
3715 }
3716
3717 DEFUN (no_neighbor_as_override,
3718 no_neighbor_as_override_cmd,
3719 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3720 NO_STR
3721 NEIGHBOR_STR
3722 NEIGHBOR_ADDR_STR2
3723 "Override ASNs in outbound updates if aspath equals remote-as\n")
3724 {
3725 int idx_peer = 2;
3726 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3727 bgp_node_safi (vty),
3728 PEER_FLAG_AS_OVERRIDE);
3729 }
3730
3731 /* neighbor remove-private-AS. */
3732 DEFUN (neighbor_remove_private_as,
3733 neighbor_remove_private_as_cmd,
3734 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3735 NEIGHBOR_STR
3736 NEIGHBOR_ADDR_STR2
3737 "Remove private ASNs in outbound updates\n")
3738 {
3739 int idx_peer = 1;
3740 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3741 bgp_node_safi (vty),
3742 PEER_FLAG_REMOVE_PRIVATE_AS);
3743 }
3744
3745 DEFUN (neighbor_remove_private_as_all,
3746 neighbor_remove_private_as_all_cmd,
3747 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3748 NEIGHBOR_STR
3749 NEIGHBOR_ADDR_STR2
3750 "Remove private ASNs in outbound updates\n"
3751 "Apply to all AS numbers")
3752 {
3753 int idx_peer = 1;
3754 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3755 bgp_node_safi (vty),
3756 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3757 }
3758
3759 DEFUN (neighbor_remove_private_as_replace_as,
3760 neighbor_remove_private_as_replace_as_cmd,
3761 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3762 NEIGHBOR_STR
3763 NEIGHBOR_ADDR_STR2
3764 "Remove private ASNs in outbound updates\n"
3765 "Replace private ASNs with our ASN in outbound updates\n")
3766 {
3767 int idx_peer = 1;
3768 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3769 bgp_node_safi (vty),
3770 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3771 }
3772
3773 DEFUN (neighbor_remove_private_as_all_replace_as,
3774 neighbor_remove_private_as_all_replace_as_cmd,
3775 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3776 NEIGHBOR_STR
3777 NEIGHBOR_ADDR_STR2
3778 "Remove private ASNs in outbound updates\n"
3779 "Apply to all AS numbers\n"
3780 "Replace private ASNs with our ASN in outbound updates\n")
3781 {
3782 int idx_peer = 1;
3783 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3784 bgp_node_safi (vty),
3785 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3786 }
3787
3788 DEFUN (no_neighbor_remove_private_as,
3789 no_neighbor_remove_private_as_cmd,
3790 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3791 NO_STR
3792 NEIGHBOR_STR
3793 NEIGHBOR_ADDR_STR2
3794 "Remove private ASNs in outbound updates\n")
3795 {
3796 int idx_peer = 2;
3797 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3798 bgp_node_safi (vty),
3799 PEER_FLAG_REMOVE_PRIVATE_AS);
3800 }
3801
3802 DEFUN (no_neighbor_remove_private_as_all,
3803 no_neighbor_remove_private_as_all_cmd,
3804 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3805 NO_STR
3806 NEIGHBOR_STR
3807 NEIGHBOR_ADDR_STR2
3808 "Remove private ASNs in outbound updates\n"
3809 "Apply to all AS numbers\n")
3810 {
3811 int idx_peer = 2;
3812 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3813 bgp_node_safi (vty),
3814 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3815 }
3816
3817 DEFUN (no_neighbor_remove_private_as_replace_as,
3818 no_neighbor_remove_private_as_replace_as_cmd,
3819 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3820 NO_STR
3821 NEIGHBOR_STR
3822 NEIGHBOR_ADDR_STR2
3823 "Remove private ASNs in outbound updates\n"
3824 "Replace private ASNs with our ASN in outbound updates\n")
3825 {
3826 int idx_peer = 2;
3827 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3828 bgp_node_safi (vty),
3829 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3830 }
3831
3832 DEFUN (no_neighbor_remove_private_as_all_replace_as,
3833 no_neighbor_remove_private_as_all_replace_as_cmd,
3834 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3835 NO_STR
3836 NEIGHBOR_STR
3837 NEIGHBOR_ADDR_STR2
3838 "Remove private ASNs in outbound updates\n"
3839 "Apply to all AS numbers\n"
3840 "Replace private ASNs with our ASN in outbound updates\n")
3841 {
3842 int idx_peer = 2;
3843 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3844 bgp_node_safi (vty),
3845 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
3846 }
3847
3848
3849 /* neighbor send-community. */
3850 DEFUN (neighbor_send_community,
3851 neighbor_send_community_cmd,
3852 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
3853 NEIGHBOR_STR
3854 NEIGHBOR_ADDR_STR2
3855 "Send Community attribute to this neighbor\n")
3856 {
3857 int idx_peer = 1;
3858 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3859 bgp_node_safi (vty),
3860 PEER_FLAG_SEND_COMMUNITY);
3861 }
3862
3863 DEFUN (no_neighbor_send_community,
3864 no_neighbor_send_community_cmd,
3865 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
3866 NO_STR
3867 NEIGHBOR_STR
3868 NEIGHBOR_ADDR_STR2
3869 "Send Community attribute to this neighbor\n")
3870 {
3871 int idx_peer = 2;
3872 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3873 bgp_node_safi (vty),
3874 PEER_FLAG_SEND_COMMUNITY);
3875 }
3876
3877 /* neighbor send-community extended. */
3878 DEFUN (neighbor_send_community_type,
3879 neighbor_send_community_type_cmd,
3880 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
3881 NEIGHBOR_STR
3882 NEIGHBOR_ADDR_STR2
3883 "Send Community attribute to this neighbor\n"
3884 "Send Standard and Extended Community attributes\n"
3885 "Send Standard, Large and Extended Community attributes\n"
3886 "Send Extended Community attributes\n"
3887 "Send Standard Community attributes\n"
3888 "Send Large Community attributes\n")
3889 {
3890 int idx = 0;
3891 u_int32_t flag = 0;
3892
3893 char *peer = argv[1]->arg;
3894
3895 if (argv_find (argv, argc, "standard", &idx))
3896 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
3897 else if (argv_find (argv, argc, "extended", &idx))
3898 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
3899 else if (argv_find (argv, argc, "large", &idx))
3900 SET_FLAG (flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
3901 else if (argv_find (argv, argc, "both", &idx))
3902 {
3903 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
3904 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
3905 }
3906 else
3907 {
3908 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
3909 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
3910 SET_FLAG (flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
3911 }
3912
3913 return peer_af_flag_set_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flag);
3914 }
3915
3916 DEFUN (no_neighbor_send_community_type,
3917 no_neighbor_send_community_type_cmd,
3918 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
3919 NO_STR
3920 NEIGHBOR_STR
3921 NEIGHBOR_ADDR_STR2
3922 "Send Community attribute to this neighbor\n"
3923 "Send Standard and Extended Community attributes\n"
3924 "Send Standard, Large and Extended Community attributes\n"
3925 "Send Extended Community attributes\n"
3926 "Send Standard Community attributes\n"
3927 "Send Large Community attributes\n")
3928 {
3929 int idx_peer = 2;
3930 int idx_type = 4;
3931 if (strncmp (argv[idx_type]->arg, "s", 1) == 0)
3932 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3933 bgp_node_safi (vty),
3934 PEER_FLAG_SEND_COMMUNITY);
3935 if (strncmp (argv[idx_type]->arg, "e", 1) == 0)
3936 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3937 bgp_node_safi (vty),
3938 PEER_FLAG_SEND_EXT_COMMUNITY);
3939 if (strncmp (argv[idx_type]->arg, "l", 1) == 0)
3940 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3941 bgp_node_safi (vty),
3942 PEER_FLAG_SEND_LARGE_COMMUNITY);
3943 if (strncmp (argv[idx_type]->arg, "b", 1) == 0)
3944 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3945 bgp_node_safi (vty),
3946 PEER_FLAG_SEND_COMMUNITY |
3947 PEER_FLAG_SEND_EXT_COMMUNITY);
3948
3949 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
3950 bgp_node_safi (vty),
3951 (PEER_FLAG_SEND_COMMUNITY |
3952 PEER_FLAG_SEND_EXT_COMMUNITY|
3953 PEER_FLAG_SEND_LARGE_COMMUNITY));
3954 }
3955
3956 /* neighbor soft-reconfig. */
3957 DEFUN (neighbor_soft_reconfiguration,
3958 neighbor_soft_reconfiguration_cmd,
3959 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
3960 NEIGHBOR_STR
3961 NEIGHBOR_ADDR_STR2
3962 "Per neighbor soft reconfiguration\n"
3963 "Allow inbound soft reconfiguration for this neighbor\n")
3964 {
3965 int idx_peer = 1;
3966 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg,
3967 bgp_node_afi (vty), bgp_node_safi (vty),
3968 PEER_FLAG_SOFT_RECONFIG);
3969 }
3970
3971 DEFUN (no_neighbor_soft_reconfiguration,
3972 no_neighbor_soft_reconfiguration_cmd,
3973 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
3974 NO_STR
3975 NEIGHBOR_STR
3976 NEIGHBOR_ADDR_STR2
3977 "Per neighbor soft reconfiguration\n"
3978 "Allow inbound soft reconfiguration for this neighbor\n")
3979 {
3980 int idx_peer = 2;
3981 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg,
3982 bgp_node_afi (vty), bgp_node_safi (vty),
3983 PEER_FLAG_SOFT_RECONFIG);
3984 }
3985
3986 DEFUN (neighbor_route_reflector_client,
3987 neighbor_route_reflector_client_cmd,
3988 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
3989 NEIGHBOR_STR
3990 NEIGHBOR_ADDR_STR2
3991 "Configure a neighbor as Route Reflector client\n")
3992 {
3993 int idx_peer = 1;
3994 struct peer *peer;
3995
3996
3997 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3998 if (! peer)
3999 return CMD_WARNING;
4000
4001 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4002 bgp_node_safi (vty),
4003 PEER_FLAG_REFLECTOR_CLIENT);
4004 }
4005
4006 DEFUN (no_neighbor_route_reflector_client,
4007 no_neighbor_route_reflector_client_cmd,
4008 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4009 NO_STR
4010 NEIGHBOR_STR
4011 NEIGHBOR_ADDR_STR2
4012 "Configure a neighbor as Route Reflector client\n")
4013 {
4014 int idx_peer = 2;
4015 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4016 bgp_node_safi (vty),
4017 PEER_FLAG_REFLECTOR_CLIENT);
4018 }
4019
4020 /* neighbor route-server-client. */
4021 DEFUN (neighbor_route_server_client,
4022 neighbor_route_server_client_cmd,
4023 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
4026 "Configure a neighbor as Route Server client\n")
4027 {
4028 int idx_peer = 1;
4029 struct peer *peer;
4030
4031 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
4032 if (! peer)
4033 return CMD_WARNING;
4034 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4035 bgp_node_safi (vty),
4036 PEER_FLAG_RSERVER_CLIENT);
4037 }
4038
4039 DEFUN (no_neighbor_route_server_client,
4040 no_neighbor_route_server_client_cmd,
4041 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4042 NO_STR
4043 NEIGHBOR_STR
4044 NEIGHBOR_ADDR_STR2
4045 "Configure a neighbor as Route Server client\n")
4046 {
4047 int idx_peer = 2;
4048 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4049 bgp_node_safi (vty),
4050 PEER_FLAG_RSERVER_CLIENT);
4051 }
4052
4053 DEFUN (neighbor_nexthop_local_unchanged,
4054 neighbor_nexthop_local_unchanged_cmd,
4055 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4056 NEIGHBOR_STR
4057 NEIGHBOR_ADDR_STR2
4058 "Configure treatment of outgoing link-local nexthop attribute\n"
4059 "Leave link-local nexthop unchanged for this peer\n")
4060 {
4061 int idx_peer = 1;
4062 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4063 bgp_node_safi (vty),
4064 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED );
4065 }
4066
4067 DEFUN (no_neighbor_nexthop_local_unchanged,
4068 no_neighbor_nexthop_local_unchanged_cmd,
4069 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
4070 NO_STR
4071 NEIGHBOR_STR
4072 NEIGHBOR_ADDR_STR2
4073 "Configure treatment of outgoing link-local-nexthop attribute\n"
4074 "Leave link-local nexthop unchanged for this peer\n")
4075 {
4076 int idx_peer = 2;
4077 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4078 bgp_node_safi (vty),
4079 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED );
4080 }
4081
4082 DEFUN (neighbor_attr_unchanged,
4083 neighbor_attr_unchanged_cmd,
4084 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged\
4085 [<\
4086 as-path [<next-hop [med]|med [next-hop]>]|\
4087 next-hop [<as-path [med]|med [as-path]>]|\
4088 med [<as-path [next-hop]|next-hop [as-path]>]\
4089 >]",
4090 NEIGHBOR_STR
4091 NEIGHBOR_ADDR_STR2
4092 "BGP attribute is propagated unchanged to this neighbor\n"
4093 "As-path attribute\n"
4094 "Nexthop attribute\n"
4095 "Med attribute\n"
4096 "Med attribute\n"
4097 "Nexthop attribute\n"
4098 "Nexthop attribute\n"
4099 "As-path attribute\n"
4100 "Med attribute\n"
4101 "Med attribute\n"
4102 "As-path attribute\n"
4103 "Med attribute\n"
4104 "As-path attribute\n"
4105 "Nexthop attribute\n"
4106 "Nexthop attribute\n"
4107 "As-path attribute\n")
4108 {
4109 int idx = 0;
4110 char *peer = argv[1]->arg;
4111 u_int16_t flags = 0;
4112
4113 if (argv_find (argv, argc, "as-path", &idx))
4114 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
4115 idx = 0;
4116 if (argv_find (argv, argc, "next-hop", &idx))
4117 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4118 idx = 0;
4119 if (argv_find (argv, argc, "med", &idx))
4120 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4121
4122 if (!flags) // no flags means all of them!
4123 {
4124 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
4125 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4126 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4127 }
4128
4129 return peer_af_flag_set_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flags);
4130 }
4131
4132 DEFUN (no_neighbor_attr_unchanged,
4133 no_neighbor_attr_unchanged_cmd,
4134 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged\
4135 [<\
4136 as-path [<next-hop [med]|med [next-hop]>]|\
4137 next-hop [<as-path [med]|med [as-path]>]|\
4138 med [<as-path [next-hop]|next-hop [as-path]>]\
4139 >]",
4140 NO_STR
4141 NEIGHBOR_STR
4142 NEIGHBOR_ADDR_STR2
4143 "BGP attribute is propagated unchanged to this neighbor\n"
4144 "As-path attribute\n"
4145 "Nexthop attribute\n"
4146 "Med attribute\n"
4147 "Med attribute\n"
4148 "Nexthop attribute\n"
4149 "Nexthop attribute\n"
4150 "As-path attribute\n"
4151 "Med attribute\n"
4152 "Med attribute\n"
4153 "As-path attribute\n"
4154 "Med attribute\n"
4155 "As-path attribute\n"
4156 "Nexthop attribute\n"
4157 "Nexthop attribute\n"
4158 "As-path attribute\n")
4159 {
4160 int idx = 0;
4161 char *peer = argv[2]->arg;
4162 u_int16_t flags = 0;
4163
4164 if (argv_find (argv, argc, "as-path", &idx))
4165 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
4166 idx = 0;
4167 if (argv_find (argv, argc, "next-hop", &idx))
4168 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4169 idx = 0;
4170 if (argv_find (argv, argc, "med", &idx))
4171 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4172
4173 if (!flags) // no flags means all of them!
4174 {
4175 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
4176 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4177 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4178 }
4179
4180 return peer_af_flag_unset_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flags);
4181 }
4182
4183
4184 /* EBGP multihop configuration. */
4185 static int
4186 peer_ebgp_multihop_set_vty (struct vty *vty, const char *ip_str,
4187 const char *ttl_str)
4188 {
4189 struct peer *peer;
4190 unsigned int ttl;
4191
4192 peer = peer_and_group_lookup_vty (vty, ip_str);
4193 if (! peer)
4194 return CMD_WARNING;
4195
4196 if (peer->conf_if)
4197 return bgp_vty_return (vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4198
4199 if (! ttl_str)
4200 ttl = MAXTTL;
4201 else
4202 VTY_GET_INTEGER_RANGE ("TTL", ttl, ttl_str, 1, MAXTTL);
4203
4204 return bgp_vty_return (vty, peer_ebgp_multihop_set (peer, ttl));
4205 }
4206
4207 static int
4208 peer_ebgp_multihop_unset_vty (struct vty *vty, const char *ip_str)
4209 {
4210 struct peer *peer;
4211
4212 peer = peer_and_group_lookup_vty (vty, ip_str);
4213 if (! peer)
4214 return CMD_WARNING;
4215
4216 return bgp_vty_return (vty, peer_ebgp_multihop_unset (peer));
4217 }
4218
4219 /* neighbor ebgp-multihop. */
4220 DEFUN (neighbor_ebgp_multihop,
4221 neighbor_ebgp_multihop_cmd,
4222 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
4223 NEIGHBOR_STR
4224 NEIGHBOR_ADDR_STR2
4225 "Allow EBGP neighbors not on directly connected networks\n")
4226 {
4227 int idx_peer = 1;
4228 return peer_ebgp_multihop_set_vty (vty, argv[idx_peer]->arg, NULL);
4229 }
4230
4231 DEFUN (neighbor_ebgp_multihop_ttl,
4232 neighbor_ebgp_multihop_ttl_cmd,
4233 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
4234 NEIGHBOR_STR
4235 NEIGHBOR_ADDR_STR2
4236 "Allow EBGP neighbors not on directly connected networks\n"
4237 "maximum hop count\n")
4238 {
4239 int idx_peer = 1;
4240 int idx_number = 3;
4241 return peer_ebgp_multihop_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg);
4242 }
4243
4244 DEFUN (no_neighbor_ebgp_multihop,
4245 no_neighbor_ebgp_multihop_cmd,
4246 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
4247 NO_STR
4248 NEIGHBOR_STR
4249 NEIGHBOR_ADDR_STR2
4250 "Allow EBGP neighbors not on directly connected networks\n"
4251 "maximum hop count\n")
4252 {
4253 int idx_peer = 2;
4254 return peer_ebgp_multihop_unset_vty (vty, argv[idx_peer]->arg);
4255 }
4256
4257
4258 /* disable-connected-check */
4259 DEFUN (neighbor_disable_connected_check,
4260 neighbor_disable_connected_check_cmd,
4261 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4262 NEIGHBOR_STR
4263 NEIGHBOR_ADDR_STR2
4264 "one-hop away EBGP peer using loopback address\n"
4265 "Enforce EBGP neighbors perform multihop\n")
4266 {
4267 int idx_peer = 1;
4268 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DISABLE_CONNECTED_CHECK);
4269 }
4270
4271 DEFUN (no_neighbor_disable_connected_check,
4272 no_neighbor_disable_connected_check_cmd,
4273 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
4274 NO_STR
4275 NEIGHBOR_STR
4276 NEIGHBOR_ADDR_STR2
4277 "one-hop away EBGP peer using loopback address\n"
4278 "Enforce EBGP neighbors perform multihop\n")
4279 {
4280 int idx_peer = 2;
4281 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DISABLE_CONNECTED_CHECK);
4282 }
4283
4284 DEFUN (neighbor_description,
4285 neighbor_description_cmd,
4286 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
4287 NEIGHBOR_STR
4288 NEIGHBOR_ADDR_STR2
4289 "Neighbor specific description\n"
4290 "Up to 80 characters describing this neighbor\n")
4291 {
4292 int idx_peer = 1;
4293 int idx_line = 3;
4294 struct peer *peer;
4295 char *str;
4296
4297 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
4298 if (! peer)
4299 return CMD_WARNING;
4300
4301 str = argv_concat(argv, argc, idx_line);
4302
4303 peer_description_set (peer, str);
4304
4305 XFREE (MTYPE_TMP, str);
4306
4307 return CMD_SUCCESS;
4308 }
4309
4310 DEFUN (no_neighbor_description,
4311 no_neighbor_description_cmd,
4312 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
4313 NO_STR
4314 NEIGHBOR_STR
4315 NEIGHBOR_ADDR_STR2
4316 "Neighbor specific description\n"
4317 "Up to 80 characters describing this neighbor\n")
4318 {
4319 int idx_peer = 2;
4320 struct peer *peer;
4321
4322 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
4323 if (! peer)
4324 return CMD_WARNING;
4325
4326 peer_description_unset (peer);
4327
4328 return CMD_SUCCESS;
4329 }
4330
4331
4332 /* Neighbor update-source. */
4333 static int
4334 peer_update_source_vty (struct vty *vty, const char *peer_str,
4335 const char *source_str)
4336 {
4337 struct peer *peer;
4338 struct prefix p;
4339
4340 peer = peer_and_group_lookup_vty (vty, peer_str);
4341 if (! peer)
4342 return CMD_WARNING;
4343
4344 if (peer->conf_if)
4345 return CMD_WARNING;
4346
4347 if (source_str)
4348 {
4349 union sockunion su;
4350 int ret = str2sockunion (source_str, &su);
4351
4352 if (ret == 0)
4353 peer_update_source_addr_set (peer, &su);
4354 else
4355 {
4356 if (str2prefix (source_str, &p))
4357 {
4358 vty_out (vty, "%% Invalid update-source, remove prefix length %s",
4359 VTY_NEWLINE);
4360 return CMD_WARNING;
4361 }
4362 else
4363 peer_update_source_if_set (peer, source_str);
4364 }
4365 }
4366 else
4367 peer_update_source_unset (peer);
4368
4369 return CMD_SUCCESS;
4370 }
4371
4372 #define BGP_UPDATE_SOURCE_HELP_STR \
4373 "IPv4 address\n" \
4374 "IPv6 address\n" \
4375 "Interface name (requires zebra to be running)\n"
4376
4377 DEFUN (neighbor_update_source,
4378 neighbor_update_source_cmd,
4379 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
4380 NEIGHBOR_STR
4381 NEIGHBOR_ADDR_STR2
4382 "Source of routing updates\n"
4383 BGP_UPDATE_SOURCE_HELP_STR)
4384 {
4385 int idx_peer = 1;
4386 int idx_peer_2 = 3;
4387 return peer_update_source_vty (vty, argv[idx_peer]->arg, argv[idx_peer_2]->arg);
4388 }
4389
4390 DEFUN (no_neighbor_update_source,
4391 no_neighbor_update_source_cmd,
4392 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
4393 NO_STR
4394 NEIGHBOR_STR
4395 NEIGHBOR_ADDR_STR2
4396 "Source of routing updates\n"
4397 BGP_UPDATE_SOURCE_HELP_STR)
4398 {
4399 int idx_peer = 2;
4400 return peer_update_source_vty (vty, argv[idx_peer]->arg, NULL);
4401 }
4402
4403 static int
4404 peer_default_originate_set_vty (struct vty *vty, const char *peer_str,
4405 afi_t afi, safi_t safi,
4406 const char *rmap, int set)
4407 {
4408 int ret;
4409 struct peer *peer;
4410
4411 peer = peer_and_group_lookup_vty (vty, peer_str);
4412 if (! peer)
4413 return CMD_WARNING;
4414
4415 if (set)
4416 ret = peer_default_originate_set (peer, afi, safi, rmap);
4417 else
4418 ret = peer_default_originate_unset (peer, afi, safi);
4419
4420 return bgp_vty_return (vty, ret);
4421 }
4422
4423 /* neighbor default-originate. */
4424 DEFUN (neighbor_default_originate,
4425 neighbor_default_originate_cmd,
4426 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4427 NEIGHBOR_STR
4428 NEIGHBOR_ADDR_STR2
4429 "Originate default route to this neighbor\n")
4430 {
4431 int idx_peer = 1;
4432 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4433 bgp_node_safi (vty), NULL, 1);
4434 }
4435
4436 DEFUN (neighbor_default_originate_rmap,
4437 neighbor_default_originate_rmap_cmd,
4438 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4439 NEIGHBOR_STR
4440 NEIGHBOR_ADDR_STR2
4441 "Originate default route to this neighbor\n"
4442 "Route-map to specify criteria to originate default\n"
4443 "route-map name\n")
4444 {
4445 int idx_peer = 1;
4446 int idx_word = 4;
4447 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4448 bgp_node_safi (vty), argv[idx_word]->arg, 1);
4449 }
4450
4451 DEFUN (no_neighbor_default_originate,
4452 no_neighbor_default_originate_cmd,
4453 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4454 NO_STR
4455 NEIGHBOR_STR
4456 NEIGHBOR_ADDR_STR2
4457 "Originate default route to this neighbor\n"
4458 "Route-map to specify criteria to originate default\n"
4459 "route-map name\n")
4460 {
4461 int idx_peer = 2;
4462 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4463 bgp_node_safi (vty), NULL, 0);
4464 }
4465
4466
4467 /* Set neighbor's BGP port. */
4468 static int
4469 peer_port_vty (struct vty *vty, const char *ip_str, int afi,
4470 const char *port_str)
4471 {
4472 struct peer *peer;
4473 u_int16_t port;
4474 struct servent *sp;
4475
4476 peer = peer_lookup_vty (vty, ip_str);
4477 if (! peer)
4478 return CMD_WARNING;
4479
4480 if (! port_str)
4481 {
4482 sp = getservbyname ("bgp", "tcp");
4483 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs (sp->s_port);
4484 }
4485 else
4486 {
4487 VTY_GET_INTEGER("port", port, port_str);
4488 }
4489
4490 peer_port_set (peer, port);
4491
4492 return CMD_SUCCESS;
4493 }
4494
4495 /* Set specified peer's BGP port. */
4496 DEFUN (neighbor_port,
4497 neighbor_port_cmd,
4498 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
4499 NEIGHBOR_STR
4500 NEIGHBOR_ADDR_STR
4501 "Neighbor's BGP port\n"
4502 "TCP port number\n")
4503 {
4504 int idx_ip = 1;
4505 int idx_number = 3;
4506 return peer_port_vty (vty, argv[idx_ip]->arg, AFI_IP, argv[idx_number]->arg);
4507 }
4508
4509 DEFUN (no_neighbor_port,
4510 no_neighbor_port_cmd,
4511 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
4512 NO_STR
4513 NEIGHBOR_STR
4514 NEIGHBOR_ADDR_STR
4515 "Neighbor's BGP port\n"
4516 "TCP port number\n")
4517 {
4518 int idx_ip = 2;
4519 return peer_port_vty (vty, argv[idx_ip]->arg, AFI_IP, NULL);
4520 }
4521
4522
4523 /* neighbor weight. */
4524 static int
4525 peer_weight_set_vty (struct vty *vty, const char *ip_str,
4526 afi_t afi, safi_t safi,
4527 const char *weight_str)
4528 {
4529 int ret;
4530 struct peer *peer;
4531 unsigned long weight;
4532
4533 peer = peer_and_group_lookup_vty (vty, ip_str);
4534 if (! peer)
4535 return CMD_WARNING;
4536
4537 VTY_GET_INTEGER_RANGE("weight", weight, weight_str, 0, 65535);
4538
4539 ret = peer_weight_set (peer, afi, safi, weight);
4540 return bgp_vty_return (vty, ret);
4541 }
4542
4543 static int
4544 peer_weight_unset_vty (struct vty *vty, const char *ip_str,
4545 afi_t afi, safi_t safi)
4546 {
4547 int ret;
4548 struct peer *peer;
4549
4550 peer = peer_and_group_lookup_vty (vty, ip_str);
4551 if (! peer)
4552 return CMD_WARNING;
4553
4554 ret = peer_weight_unset (peer, afi, safi);
4555 return bgp_vty_return (vty, ret);
4556 }
4557
4558 DEFUN (neighbor_weight,
4559 neighbor_weight_cmd,
4560 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4561 NEIGHBOR_STR
4562 NEIGHBOR_ADDR_STR2
4563 "Set default weight for routes from this neighbor\n"
4564 "default weight\n")
4565 {
4566 int idx_peer = 1;
4567 int idx_number = 3;
4568 return peer_weight_set_vty (vty,
4569 argv[idx_peer]->arg,
4570 bgp_node_afi (vty),
4571 bgp_node_safi (vty),
4572 argv[idx_number]->arg);
4573 }
4574
4575 DEFUN (no_neighbor_weight,
4576 no_neighbor_weight_cmd,
4577 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4578 NO_STR
4579 NEIGHBOR_STR
4580 NEIGHBOR_ADDR_STR2
4581 "Set default weight for routes from this neighbor\n"
4582 "default weight\n")
4583 {
4584 int idx_peer = 2;
4585 return peer_weight_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty), bgp_node_safi (vty));
4586 }
4587
4588
4589 /* Override capability negotiation. */
4590 DEFUN (neighbor_override_capability,
4591 neighbor_override_capability_cmd,
4592 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4593 NEIGHBOR_STR
4594 NEIGHBOR_ADDR_STR2
4595 "Override capability negotiation result\n")
4596 {
4597 int idx_peer = 1;
4598 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_OVERRIDE_CAPABILITY);
4599 }
4600
4601 DEFUN (no_neighbor_override_capability,
4602 no_neighbor_override_capability_cmd,
4603 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
4604 NO_STR
4605 NEIGHBOR_STR
4606 NEIGHBOR_ADDR_STR2
4607 "Override capability negotiation result\n")
4608 {
4609 int idx_peer = 2;
4610 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_OVERRIDE_CAPABILITY);
4611 }
4612
4613 DEFUN (neighbor_strict_capability,
4614 neighbor_strict_capability_cmd,
4615 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4616 NEIGHBOR_STR
4617 NEIGHBOR_ADDR_STR
4618 "Strict capability negotiation match\n")
4619 {
4620 int idx_ip = 1;
4621 return peer_flag_set_vty (vty, argv[idx_ip]->arg, PEER_FLAG_STRICT_CAP_MATCH);
4622 }
4623
4624 DEFUN (no_neighbor_strict_capability,
4625 no_neighbor_strict_capability_cmd,
4626 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
4627 NO_STR
4628 NEIGHBOR_STR
4629 NEIGHBOR_ADDR_STR
4630 "Strict capability negotiation match\n")
4631 {
4632 int idx_ip = 2;
4633 return peer_flag_unset_vty (vty, argv[idx_ip]->arg, PEER_FLAG_STRICT_CAP_MATCH);
4634 }
4635
4636 static int
4637 peer_timers_set_vty (struct vty *vty, const char *ip_str,
4638 const char *keep_str, const char *hold_str)
4639 {
4640 int ret;
4641 struct peer *peer;
4642 u_int32_t keepalive;
4643 u_int32_t holdtime;
4644
4645 peer = peer_and_group_lookup_vty (vty, ip_str);
4646 if (! peer)
4647 return CMD_WARNING;
4648
4649 VTY_GET_INTEGER_RANGE ("Keepalive", keepalive, keep_str, 0, 65535);
4650 VTY_GET_INTEGER_RANGE ("Holdtime", holdtime, hold_str, 0, 65535);
4651
4652 ret = peer_timers_set (peer, keepalive, holdtime);
4653
4654 return bgp_vty_return (vty, ret);
4655 }
4656
4657 static int
4658 peer_timers_unset_vty (struct vty *vty, const char *ip_str)
4659 {
4660 int ret;
4661 struct peer *peer;
4662
4663 peer = peer_and_group_lookup_vty (vty, ip_str);
4664 if (! peer)
4665 return CMD_WARNING;
4666
4667 ret = peer_timers_unset (peer);
4668
4669 return bgp_vty_return (vty, ret);
4670 }
4671
4672 DEFUN (neighbor_timers,
4673 neighbor_timers_cmd,
4674 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
4675 NEIGHBOR_STR
4676 NEIGHBOR_ADDR_STR2
4677 "BGP per neighbor timers\n"
4678 "Keepalive interval\n"
4679 "Holdtime\n")
4680 {
4681 int idx_peer = 1;
4682 int idx_number = 3;
4683 int idx_number_2 = 4;
4684 return peer_timers_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg, argv[idx_number_2]->arg);
4685 }
4686
4687 DEFUN (no_neighbor_timers,
4688 no_neighbor_timers_cmd,
4689 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
4690 NO_STR
4691 NEIGHBOR_STR
4692 NEIGHBOR_ADDR_STR2
4693 "BGP per neighbor timers\n"
4694 "Keepalive interval\n"
4695 "Holdtime\n")
4696 {
4697 int idx_peer = 2;
4698 return peer_timers_unset_vty (vty, argv[idx_peer]->arg);
4699 }
4700
4701
4702 static int
4703 peer_timers_connect_set_vty (struct vty *vty, const char *ip_str,
4704 const char *time_str)
4705 {
4706 int ret;
4707 struct peer *peer;
4708 u_int32_t connect;
4709
4710 peer = peer_and_group_lookup_vty (vty, ip_str);
4711 if (! peer)
4712 return CMD_WARNING;
4713
4714 VTY_GET_INTEGER_RANGE ("Connect time", connect, time_str, 0, 65535);
4715
4716 ret = peer_timers_connect_set (peer, connect);
4717
4718 return bgp_vty_return (vty, ret);
4719 }
4720
4721 static int
4722 peer_timers_connect_unset_vty (struct vty *vty, const char *ip_str)
4723 {
4724 int ret;
4725 struct peer *peer;
4726
4727 peer = peer_and_group_lookup_vty (vty, ip_str);
4728 if (! peer)
4729 return CMD_WARNING;
4730
4731 ret = peer_timers_connect_unset (peer);
4732
4733 return bgp_vty_return (vty, ret);
4734 }
4735
4736 DEFUN (neighbor_timers_connect,
4737 neighbor_timers_connect_cmd,
4738 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
4739 NEIGHBOR_STR
4740 NEIGHBOR_ADDR_STR2
4741 "BGP per neighbor timers\n"
4742 "BGP connect timer\n"
4743 "Connect timer\n")
4744 {
4745 int idx_peer = 1;
4746 int idx_number = 4;
4747 return peer_timers_connect_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg);
4748 }
4749
4750 DEFUN (no_neighbor_timers_connect,
4751 no_neighbor_timers_connect_cmd,
4752 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
4753 NO_STR
4754 NEIGHBOR_STR
4755 NEIGHBOR_ADDR_STR2
4756 "BGP per neighbor timers\n"
4757 "BGP connect timer\n"
4758 "Connect timer\n")
4759 {
4760 int idx_peer = 2;
4761 return peer_timers_connect_unset_vty (vty, argv[idx_peer]->arg);
4762 }
4763
4764
4765 static int
4766 peer_advertise_interval_vty (struct vty *vty, const char *ip_str,
4767 const char *time_str, int set)
4768 {
4769 int ret;
4770 struct peer *peer;
4771 u_int32_t routeadv = 0;
4772
4773 peer = peer_and_group_lookup_vty (vty, ip_str);
4774 if (! peer)
4775 return CMD_WARNING;
4776
4777 if (time_str)
4778 VTY_GET_INTEGER_RANGE ("advertise interval", routeadv, time_str, 0, 600);
4779
4780 if (set)
4781 ret = peer_advertise_interval_set (peer, routeadv);
4782 else
4783 ret = peer_advertise_interval_unset (peer);
4784
4785 return bgp_vty_return (vty, ret);
4786 }
4787
4788 DEFUN (neighbor_advertise_interval,
4789 neighbor_advertise_interval_cmd,
4790 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
4791 NEIGHBOR_STR
4792 NEIGHBOR_ADDR_STR2
4793 "Minimum interval between sending BGP routing updates\n"
4794 "time in seconds\n")
4795 {
4796 int idx_peer = 1;
4797 int idx_number = 3;
4798 return peer_advertise_interval_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg, 1);
4799 }
4800
4801 DEFUN (no_neighbor_advertise_interval,
4802 no_neighbor_advertise_interval_cmd,
4803 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
4804 NO_STR
4805 NEIGHBOR_STR
4806 NEIGHBOR_ADDR_STR2
4807 "Minimum interval between sending BGP routing updates\n"
4808 "time in seconds\n")
4809 {
4810 int idx_peer = 2;
4811 return peer_advertise_interval_vty (vty, argv[idx_peer]->arg, NULL, 0);
4812 }
4813
4814
4815 /* Time to wait before processing route-map updates */
4816 DEFUN (bgp_set_route_map_delay_timer,
4817 bgp_set_route_map_delay_timer_cmd,
4818 "bgp route-map delay-timer (0-600)",
4819 SET_STR
4820 "BGP route-map delay timer\n"
4821 "Time in secs to wait before processing route-map changes\n"
4822 "0 disables the timer, no route updates happen when route-maps change\n")
4823 {
4824 int idx_number = 3;
4825 u_int32_t rmap_delay_timer;
4826
4827 if (argv[idx_number]->arg)
4828 {
4829 VTY_GET_INTEGER_RANGE ("delay-timer", rmap_delay_timer, argv[idx_number]->arg, 0, 600);
4830 bm->rmap_update_timer = rmap_delay_timer;
4831
4832 /* if the dynamic update handling is being disabled, and a timer is
4833 * running, stop the timer and act as if the timer has already fired.
4834 */
4835 if (!rmap_delay_timer && bm->t_rmap_update )
4836 {
4837 BGP_TIMER_OFF(bm->t_rmap_update);
4838 thread_execute (bm->master, bgp_route_map_update_timer, NULL, 0);
4839 }
4840 return CMD_SUCCESS;
4841 }
4842 else
4843 return CMD_WARNING;
4844 }
4845
4846 DEFUN (no_bgp_set_route_map_delay_timer,
4847 no_bgp_set_route_map_delay_timer_cmd,
4848 "no bgp route-map delay-timer [(0-600)]",
4849 NO_STR
4850 BGP_STR
4851 "Default BGP route-map delay timer\n"
4852 "Reset to default time to wait for processing route-map changes\n"
4853 "0 disables the timer, no route updates happen when route-maps change\n")
4854 {
4855
4856 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
4857
4858 return CMD_SUCCESS;
4859 }
4860
4861
4862 /* neighbor interface */
4863 static int
4864 peer_interface_vty (struct vty *vty, const char *ip_str, const char *str)
4865 {
4866 struct peer *peer;
4867
4868 peer = peer_lookup_vty (vty, ip_str);
4869 if (! peer || peer->conf_if)
4870 return CMD_WARNING;
4871
4872 if (str)
4873 peer_interface_set (peer, str);
4874 else
4875 peer_interface_unset (peer);
4876
4877 return CMD_SUCCESS;
4878 }
4879
4880 DEFUN (neighbor_interface,
4881 neighbor_interface_cmd,
4882 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
4883 NEIGHBOR_STR
4884 NEIGHBOR_ADDR_STR
4885 "Interface\n"
4886 "Interface name\n")
4887 {
4888 int idx_ip = 1;
4889 int idx_word = 3;
4890 return peer_interface_vty (vty, argv[idx_ip]->arg, argv[idx_word]->arg);
4891 }
4892
4893 DEFUN (no_neighbor_interface,
4894 no_neighbor_interface_cmd,
4895 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
4896 NO_STR
4897 NEIGHBOR_STR
4898 NEIGHBOR_ADDR_STR2
4899 "Interface\n"
4900 "Interface name\n")
4901 {
4902 int idx_peer = 2;
4903 return peer_interface_vty (vty, argv[idx_peer]->arg, NULL);
4904 }
4905
4906 /* Set distribute list to the peer. */
4907 static int
4908 peer_distribute_set_vty (struct vty *vty, const char *ip_str,
4909 afi_t afi, safi_t safi,
4910 const char *name_str, const char *direct_str)
4911 {
4912 int ret;
4913 struct peer *peer;
4914 int direct = FILTER_IN;
4915
4916 peer = peer_and_group_lookup_vty (vty, ip_str);
4917 if (! peer)
4918 return CMD_WARNING;
4919
4920 /* Check filter direction. */
4921 if (strncmp (direct_str, "i", 1) == 0)
4922 direct = FILTER_IN;
4923 else if (strncmp (direct_str, "o", 1) == 0)
4924 direct = FILTER_OUT;
4925
4926 ret = peer_distribute_set (peer, afi, safi, direct, name_str);
4927
4928 return bgp_vty_return (vty, ret);
4929 }
4930
4931 static int
4932 peer_distribute_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
4933 safi_t safi, const char *direct_str)
4934 {
4935 int ret;
4936 struct peer *peer;
4937 int direct = FILTER_IN;
4938
4939 peer = peer_and_group_lookup_vty (vty, ip_str);
4940 if (! peer)
4941 return CMD_WARNING;
4942
4943 /* Check filter direction. */
4944 if (strncmp (direct_str, "i", 1) == 0)
4945 direct = FILTER_IN;
4946 else if (strncmp (direct_str, "o", 1) == 0)
4947 direct = FILTER_OUT;
4948
4949 ret = peer_distribute_unset (peer, afi, safi, direct);
4950
4951 return bgp_vty_return (vty, ret);
4952 }
4953
4954 DEFUN (neighbor_distribute_list,
4955 neighbor_distribute_list_cmd,
4956 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
4957 NEIGHBOR_STR
4958 NEIGHBOR_ADDR_STR2
4959 "Filter updates to/from this neighbor\n"
4960 "IP access-list number\n"
4961 "IP access-list number (expanded range)\n"
4962 "IP Access-list name\n"
4963 "Filter incoming updates\n"
4964 "Filter outgoing updates\n")
4965 {
4966 int idx_peer = 1;
4967 int idx_acl = 3;
4968 int idx_in_out = 4;
4969 return peer_distribute_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4970 bgp_node_safi (vty), argv[idx_acl]->arg, argv[idx_in_out]->arg);
4971 }
4972
4973 DEFUN (no_neighbor_distribute_list,
4974 no_neighbor_distribute_list_cmd,
4975 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
4976 NO_STR
4977 NEIGHBOR_STR
4978 NEIGHBOR_ADDR_STR2
4979 "Filter updates to/from this neighbor\n"
4980 "IP access-list number\n"
4981 "IP access-list number (expanded range)\n"
4982 "IP Access-list name\n"
4983 "Filter incoming updates\n"
4984 "Filter outgoing updates\n")
4985 {
4986 int idx_peer = 2;
4987 int idx_in_out = 5;
4988 return peer_distribute_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4989 bgp_node_safi (vty), argv[idx_in_out]->arg);
4990 }
4991
4992 /* Set prefix list to the peer. */
4993 static int
4994 peer_prefix_list_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
4995 safi_t safi, const char *name_str,
4996 const char *direct_str)
4997 {
4998 int ret;
4999 struct peer *peer;
5000 int direct = FILTER_IN;
5001
5002 peer = peer_and_group_lookup_vty (vty, ip_str);
5003 if (! peer)
5004 return CMD_WARNING;
5005
5006 /* Check filter direction. */
5007 if (strncmp (direct_str, "i", 1) == 0)
5008 direct = FILTER_IN;
5009 else if (strncmp (direct_str, "o", 1) == 0)
5010 direct = FILTER_OUT;
5011
5012 ret = peer_prefix_list_set (peer, afi, safi, direct, name_str);
5013
5014 return bgp_vty_return (vty, ret);
5015 }
5016
5017 static int
5018 peer_prefix_list_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5019 safi_t safi, const char *direct_str)
5020 {
5021 int ret;
5022 struct peer *peer;
5023 int direct = FILTER_IN;
5024
5025 peer = peer_and_group_lookup_vty (vty, ip_str);
5026 if (! peer)
5027 return CMD_WARNING;
5028
5029 /* Check filter direction. */
5030 if (strncmp (direct_str, "i", 1) == 0)
5031 direct = FILTER_IN;
5032 else if (strncmp (direct_str, "o", 1) == 0)
5033 direct = FILTER_OUT;
5034
5035 ret = peer_prefix_list_unset (peer, afi, safi, direct);
5036
5037 return bgp_vty_return (vty, ret);
5038 }
5039
5040 DEFUN (neighbor_prefix_list,
5041 neighbor_prefix_list_cmd,
5042 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5043 NEIGHBOR_STR
5044 NEIGHBOR_ADDR_STR2
5045 "Filter updates to/from this neighbor\n"
5046 "Name of a prefix list\n"
5047 "Filter incoming updates\n"
5048 "Filter outgoing updates\n")
5049 {
5050 int idx_peer = 1;
5051 int idx_word = 3;
5052 int idx_in_out = 4;
5053 return peer_prefix_list_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5054 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
5055 }
5056
5057 DEFUN (no_neighbor_prefix_list,
5058 no_neighbor_prefix_list_cmd,
5059 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5060 NO_STR
5061 NEIGHBOR_STR
5062 NEIGHBOR_ADDR_STR2
5063 "Filter updates to/from this neighbor\n"
5064 "Name of a prefix list\n"
5065 "Filter incoming updates\n"
5066 "Filter outgoing updates\n")
5067 {
5068 int idx_peer = 2;
5069 int idx_in_out = 5;
5070 return peer_prefix_list_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5071 bgp_node_safi (vty), argv[idx_in_out]->arg);
5072 }
5073
5074 static int
5075 peer_aslist_set_vty (struct vty *vty, const char *ip_str,
5076 afi_t afi, safi_t safi,
5077 const char *name_str, const char *direct_str)
5078 {
5079 int ret;
5080 struct peer *peer;
5081 int direct = FILTER_IN;
5082
5083 peer = peer_and_group_lookup_vty (vty, ip_str);
5084 if (! peer)
5085 return CMD_WARNING;
5086
5087 /* Check filter direction. */
5088 if (strncmp (direct_str, "i", 1) == 0)
5089 direct = FILTER_IN;
5090 else if (strncmp (direct_str, "o", 1) == 0)
5091 direct = FILTER_OUT;
5092
5093 ret = peer_aslist_set (peer, afi, safi, direct, name_str);
5094
5095 return bgp_vty_return (vty, ret);
5096 }
5097
5098 static int
5099 peer_aslist_unset_vty (struct vty *vty, const char *ip_str,
5100 afi_t afi, safi_t safi,
5101 const char *direct_str)
5102 {
5103 int ret;
5104 struct peer *peer;
5105 int direct = FILTER_IN;
5106
5107 peer = peer_and_group_lookup_vty (vty, ip_str);
5108 if (! peer)
5109 return CMD_WARNING;
5110
5111 /* Check filter direction. */
5112 if (strncmp (direct_str, "i", 1) == 0)
5113 direct = FILTER_IN;
5114 else if (strncmp (direct_str, "o", 1) == 0)
5115 direct = FILTER_OUT;
5116
5117 ret = peer_aslist_unset (peer, afi, safi, direct);
5118
5119 return bgp_vty_return (vty, ret);
5120 }
5121
5122 DEFUN (neighbor_filter_list,
5123 neighbor_filter_list_cmd,
5124 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5125 NEIGHBOR_STR
5126 NEIGHBOR_ADDR_STR2
5127 "Establish BGP filters\n"
5128 "AS path access-list name\n"
5129 "Filter incoming routes\n"
5130 "Filter outgoing routes\n")
5131 {
5132 int idx_peer = 1;
5133 int idx_word = 3;
5134 int idx_in_out = 4;
5135 return peer_aslist_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5136 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
5137 }
5138
5139 DEFUN (no_neighbor_filter_list,
5140 no_neighbor_filter_list_cmd,
5141 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5142 NO_STR
5143 NEIGHBOR_STR
5144 NEIGHBOR_ADDR_STR2
5145 "Establish BGP filters\n"
5146 "AS path access-list name\n"
5147 "Filter incoming routes\n"
5148 "Filter outgoing routes\n")
5149 {
5150 int idx_peer = 2;
5151 int idx_in_out = 5;
5152 return peer_aslist_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5153 bgp_node_safi (vty), argv[idx_in_out]->arg);
5154 }
5155
5156 /* Set route-map to the peer. */
5157 static int
5158 peer_route_map_set_vty (struct vty *vty, const char *ip_str,
5159 afi_t afi, safi_t safi,
5160 const char *name_str, const char *direct_str)
5161 {
5162 int ret;
5163 struct peer *peer;
5164 int direct = RMAP_IN;
5165
5166 peer = peer_and_group_lookup_vty (vty, ip_str);
5167 if (! peer)
5168 return CMD_WARNING;
5169
5170 /* Check filter direction. */
5171 if (strncmp (direct_str, "in", 2) == 0)
5172 direct = RMAP_IN;
5173 else if (strncmp (direct_str, "o", 1) == 0)
5174 direct = RMAP_OUT;
5175
5176 ret = peer_route_map_set (peer, afi, safi, direct, name_str);
5177
5178 return bgp_vty_return (vty, ret);
5179 }
5180
5181 static int
5182 peer_route_map_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5183 safi_t safi, const char *direct_str)
5184 {
5185 int ret;
5186 struct peer *peer;
5187 int direct = RMAP_IN;
5188
5189 peer = peer_and_group_lookup_vty (vty, ip_str);
5190 if (! peer)
5191 return CMD_WARNING;
5192
5193 /* Check filter direction. */
5194 if (strncmp (direct_str, "in", 2) == 0)
5195 direct = RMAP_IN;
5196 else if (strncmp (direct_str, "o", 1) == 0)
5197 direct = RMAP_OUT;
5198
5199 ret = peer_route_map_unset (peer, afi, safi, direct);
5200
5201 return bgp_vty_return (vty, ret);
5202 }
5203
5204 DEFUN (neighbor_route_map,
5205 neighbor_route_map_cmd,
5206 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5207 NEIGHBOR_STR
5208 NEIGHBOR_ADDR_STR2
5209 "Apply route map to neighbor\n"
5210 "Name of route map\n"
5211 "Apply map to incoming routes\n"
5212 "Apply map to outbound routes\n")
5213 {
5214 int idx_peer = 1;
5215 int idx_word = 3;
5216 int idx_in_out = 4;
5217 return peer_route_map_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5218 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
5219 }
5220
5221 DEFUN (no_neighbor_route_map,
5222 no_neighbor_route_map_cmd,
5223 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5224 NO_STR
5225 NEIGHBOR_STR
5226 NEIGHBOR_ADDR_STR2
5227 "Apply route map to neighbor\n"
5228 "Name of route map\n"
5229 "Apply map to incoming routes\n"
5230 "Apply map to outbound routes\n")
5231 {
5232 int idx_peer = 2;
5233 int idx_in_out = 5;
5234 return peer_route_map_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5235 bgp_node_safi (vty), argv[idx_in_out]->arg);
5236 }
5237
5238 /* Set unsuppress-map to the peer. */
5239 static int
5240 peer_unsuppress_map_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
5241 safi_t safi, const char *name_str)
5242 {
5243 int ret;
5244 struct peer *peer;
5245
5246 peer = peer_and_group_lookup_vty (vty, ip_str);
5247 if (! peer)
5248 return CMD_WARNING;
5249
5250 ret = peer_unsuppress_map_set (peer, afi, safi, name_str);
5251
5252 return bgp_vty_return (vty, ret);
5253 }
5254
5255 /* Unset route-map from the peer. */
5256 static int
5257 peer_unsuppress_map_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5258 safi_t safi)
5259 {
5260 int ret;
5261 struct peer *peer;
5262
5263 peer = peer_and_group_lookup_vty (vty, ip_str);
5264 if (! peer)
5265 return CMD_WARNING;
5266
5267 ret = peer_unsuppress_map_unset (peer, afi, safi);
5268
5269 return bgp_vty_return (vty, ret);
5270 }
5271
5272 DEFUN (neighbor_unsuppress_map,
5273 neighbor_unsuppress_map_cmd,
5274 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5275 NEIGHBOR_STR
5276 NEIGHBOR_ADDR_STR2
5277 "Route-map to selectively unsuppress suppressed routes\n"
5278 "Name of route map\n")
5279 {
5280 int idx_peer = 1;
5281 int idx_word = 3;
5282 return peer_unsuppress_map_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5283 bgp_node_safi (vty), argv[idx_word]->arg);
5284 }
5285
5286 DEFUN (no_neighbor_unsuppress_map,
5287 no_neighbor_unsuppress_map_cmd,
5288 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5289 NO_STR
5290 NEIGHBOR_STR
5291 NEIGHBOR_ADDR_STR2
5292 "Route-map to selectively unsuppress suppressed routes\n"
5293 "Name of route map\n")
5294 {
5295 int idx_peer = 2;
5296 return peer_unsuppress_map_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5297 bgp_node_safi (vty));
5298 }
5299
5300 static int
5301 peer_maximum_prefix_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
5302 safi_t safi, const char *num_str,
5303 const char *threshold_str, int warning,
5304 const char *restart_str)
5305 {
5306 int ret;
5307 struct peer *peer;
5308 u_int32_t max;
5309 u_char threshold;
5310 u_int16_t restart;
5311
5312 peer = peer_and_group_lookup_vty (vty, ip_str);
5313 if (! peer)
5314 return CMD_WARNING;
5315
5316 VTY_GET_INTEGER ("maximum number", max, num_str);
5317 if (threshold_str)
5318 threshold = atoi (threshold_str);
5319 else
5320 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
5321
5322 if (restart_str)
5323 restart = atoi (restart_str);
5324 else
5325 restart = 0;
5326
5327 ret = peer_maximum_prefix_set (peer, afi, safi, max, threshold, warning, restart);
5328
5329 return bgp_vty_return (vty, ret);
5330 }
5331
5332 static int
5333 peer_maximum_prefix_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5334 safi_t safi)
5335 {
5336 int ret;
5337 struct peer *peer;
5338
5339 peer = peer_and_group_lookup_vty (vty, ip_str);
5340 if (! peer)
5341 return CMD_WARNING;
5342
5343 ret = peer_maximum_prefix_unset (peer, afi, safi);
5344
5345 return bgp_vty_return (vty, ret);
5346 }
5347
5348 /* Maximum number of prefix configuration. prefix count is different
5349 for each peer configuration. So this configuration can be set for
5350 each peer configuration. */
5351 DEFUN (neighbor_maximum_prefix,
5352 neighbor_maximum_prefix_cmd,
5353 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5354 NEIGHBOR_STR
5355 NEIGHBOR_ADDR_STR2
5356 "Maximum number of prefix accept from this peer\n"
5357 "maximum no. of prefix limit\n")
5358 {
5359 int idx_peer = 1;
5360 int idx_number = 3;
5361 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5362 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 0,
5363 NULL);
5364 }
5365
5366 DEFUN (neighbor_maximum_prefix_threshold,
5367 neighbor_maximum_prefix_threshold_cmd,
5368 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5369 NEIGHBOR_STR
5370 NEIGHBOR_ADDR_STR2
5371 "Maximum number of prefix accept from this peer\n"
5372 "maximum no. of prefix limit\n"
5373 "Threshold value (%) at which to generate a warning msg\n")
5374 {
5375 int idx_peer = 1;
5376 int idx_number = 3;
5377 int idx_number_2 = 4;
5378 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5379 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5380 NULL);
5381 }
5382
5383 DEFUN (neighbor_maximum_prefix_warning,
5384 neighbor_maximum_prefix_warning_cmd,
5385 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5386 NEIGHBOR_STR
5387 NEIGHBOR_ADDR_STR2
5388 "Maximum number of prefix accept from this peer\n"
5389 "maximum no. of prefix limit\n"
5390 "Only give warning message when limit is exceeded\n")
5391 {
5392 int idx_peer = 1;
5393 int idx_number = 3;
5394 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5395 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 1,
5396 NULL);
5397 }
5398
5399 DEFUN (neighbor_maximum_prefix_threshold_warning,
5400 neighbor_maximum_prefix_threshold_warning_cmd,
5401 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5402 NEIGHBOR_STR
5403 NEIGHBOR_ADDR_STR2
5404 "Maximum number of prefix accept from this peer\n"
5405 "maximum no. of prefix limit\n"
5406 "Threshold value (%) at which to generate a warning msg\n"
5407 "Only give warning message when limit is exceeded\n")
5408 {
5409 int idx_peer = 1;
5410 int idx_number = 3;
5411 int idx_number_2 = 4;
5412 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5413 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
5414 }
5415
5416 DEFUN (neighbor_maximum_prefix_restart,
5417 neighbor_maximum_prefix_restart_cmd,
5418 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5419 NEIGHBOR_STR
5420 NEIGHBOR_ADDR_STR2
5421 "Maximum number of prefix accept from this peer\n"
5422 "maximum no. of prefix limit\n"
5423 "Restart bgp connection after limit is exceeded\n"
5424 "Restart interval in minutes")
5425 {
5426 int idx_peer = 1;
5427 int idx_number = 3;
5428 int idx_number_2 = 5;
5429 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5430 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
5431 }
5432
5433 DEFUN (neighbor_maximum_prefix_threshold_restart,
5434 neighbor_maximum_prefix_threshold_restart_cmd,
5435 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5436 NEIGHBOR_STR
5437 NEIGHBOR_ADDR_STR2
5438 "Maximum number of prefixes to accept from this peer\n"
5439 "maximum no. of prefix limit\n"
5440 "Threshold value (%) at which to generate a warning msg\n"
5441 "Restart bgp connection after limit is exceeded\n"
5442 "Restart interval in minutes\n")
5443 {
5444 int idx_peer = 1;
5445 int idx_number = 3;
5446 int idx_number_2 = 4;
5447 int idx_number_3 = 6;
5448 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5449 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 0, argv[idx_number_3]->arg);
5450 }
5451
5452 DEFUN (no_neighbor_maximum_prefix,
5453 no_neighbor_maximum_prefix_cmd,
5454 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5455 NO_STR
5456 NEIGHBOR_STR
5457 NEIGHBOR_ADDR_STR2
5458 "Maximum number of prefixes to accept from this peer\n"
5459 "maximum no. of prefix limit\n"
5460 "Threshold value (%) at which to generate a warning msg\n"
5461 "Restart bgp connection after limit is exceeded\n"
5462 "Restart interval in minutes\n"
5463 "Only give warning message when limit is exceeded\n")
5464 {
5465 int idx_peer = 2;
5466 return peer_maximum_prefix_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5467 bgp_node_safi (vty));
5468 }
5469
5470
5471 /* "neighbor allowas-in" */
5472 DEFUN (neighbor_allowas_in,
5473 neighbor_allowas_in_cmd,
5474 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5475 NEIGHBOR_STR
5476 NEIGHBOR_ADDR_STR2
5477 "Accept as-path with my AS present in it\n"
5478 "Number of occurances of AS number\n"
5479 "Only accept my AS in the as-path if the route was originated in my AS\n")
5480 {
5481 int idx_peer = 1;
5482 int idx_number_origin = 3;
5483 int ret;
5484 int origin = 0;
5485 struct peer *peer;
5486 int allow_num = 0;
5487
5488 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
5489 if (! peer)
5490 return CMD_WARNING;
5491
5492 if (argc <= idx_number_origin)
5493 allow_num = 3;
5494 else
5495 {
5496 if (argv[idx_number_origin]->type == WORD_TKN)
5497 origin = 1;
5498 else
5499 allow_num = atoi (argv[idx_number_origin]->arg);
5500 }
5501
5502 ret = peer_allowas_in_set (peer, bgp_node_afi (vty), bgp_node_safi (vty),
5503 allow_num, origin);
5504
5505 return bgp_vty_return (vty, ret);
5506 }
5507
5508 DEFUN (no_neighbor_allowas_in,
5509 no_neighbor_allowas_in_cmd,
5510 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5511 NO_STR
5512 NEIGHBOR_STR
5513 NEIGHBOR_ADDR_STR2
5514 "allow local ASN appears in aspath attribute\n"
5515 "Number of occurances of AS number\n"
5516 "Only accept my AS in the as-path if the route was originated in my AS\n")
5517 {
5518 int idx_peer = 2;
5519 int ret;
5520 struct peer *peer;
5521
5522 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
5523 if (! peer)
5524 return CMD_WARNING;
5525
5526 ret = peer_allowas_in_unset (peer, bgp_node_afi (vty), bgp_node_safi (vty));
5527
5528 return bgp_vty_return (vty, ret);
5529 }
5530
5531 DEFUN (neighbor_ttl_security,
5532 neighbor_ttl_security_cmd,
5533 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
5534 NEIGHBOR_STR
5535 NEIGHBOR_ADDR_STR2
5536 "BGP ttl-security parameters\n"
5537 "Specify the maximum number of hops to the BGP peer\n"
5538 "Number of hops to BGP peer\n")
5539 {
5540 int idx_peer = 1;
5541 int idx_number = 4;
5542 struct peer *peer;
5543 int gtsm_hops;
5544
5545 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
5546 if (! peer)
5547 return CMD_WARNING;
5548
5549 VTY_GET_INTEGER_RANGE ("", gtsm_hops, argv[idx_number]->arg, 1, 254);
5550
5551 /*
5552 * If 'neighbor swpX', then this is for directly connected peers,
5553 * we should not accept a ttl-security hops value greater than 1.
5554 */
5555 if (peer->conf_if && (gtsm_hops > 1)) {
5556 vty_out (vty, "%s is directly connected peer, hops cannot exceed 1%s",
5557 argv[idx_peer]->arg, VTY_NEWLINE);
5558 return CMD_WARNING;
5559 }
5560
5561 return bgp_vty_return (vty, peer_ttl_security_hops_set (peer, gtsm_hops));
5562 }
5563
5564 DEFUN (no_neighbor_ttl_security,
5565 no_neighbor_ttl_security_cmd,
5566 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
5567 NO_STR
5568 NEIGHBOR_STR
5569 NEIGHBOR_ADDR_STR2
5570 "BGP ttl-security parameters\n"
5571 "Specify the maximum number of hops to the BGP peer\n"
5572 "Number of hops to BGP peer\n")
5573 {
5574 int idx_peer = 2;
5575 struct peer *peer;
5576
5577 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
5578 if (! peer)
5579 return CMD_WARNING;
5580
5581 return bgp_vty_return (vty, peer_ttl_security_hops_unset (peer));
5582 }
5583
5584 DEFUN (neighbor_addpath_tx_all_paths,
5585 neighbor_addpath_tx_all_paths_cmd,
5586 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
5587 NEIGHBOR_STR
5588 NEIGHBOR_ADDR_STR2
5589 "Use addpath to advertise all paths to a neighbor\n")
5590 {
5591 int idx_peer = 1;
5592 struct peer *peer;
5593
5594 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
5595 if (! peer)
5596 return CMD_WARNING;
5597
5598 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5599 bgp_node_safi (vty),
5600 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
5601 }
5602
5603 DEFUN (no_neighbor_addpath_tx_all_paths,
5604 no_neighbor_addpath_tx_all_paths_cmd,
5605 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
5606 NO_STR
5607 NEIGHBOR_STR
5608 NEIGHBOR_ADDR_STR2
5609 "Use addpath to advertise all paths to a neighbor\n")
5610 {
5611 int idx_peer = 2;
5612 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5613 bgp_node_safi (vty),
5614 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
5615 }
5616
5617 DEFUN (neighbor_addpath_tx_bestpath_per_as,
5618 neighbor_addpath_tx_bestpath_per_as_cmd,
5619 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
5620 NEIGHBOR_STR
5621 NEIGHBOR_ADDR_STR2
5622 "Use addpath to advertise the bestpath per each neighboring AS\n")
5623 {
5624 int idx_peer = 1;
5625 struct peer *peer;
5626
5627 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
5628 if (! peer)
5629 return CMD_WARNING;
5630
5631 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5632 bgp_node_safi (vty),
5633 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
5634 }
5635
5636 DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
5637 no_neighbor_addpath_tx_bestpath_per_as_cmd,
5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
5639 NO_STR
5640 NEIGHBOR_STR
5641 NEIGHBOR_ADDR_STR2
5642 "Use addpath to advertise the bestpath per each neighboring AS\n")
5643 {
5644 int idx_peer = 2;
5645 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5646 bgp_node_safi (vty),
5647 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
5648 }
5649
5650 DEFUN_NOSH (address_family_ipv4_safi,
5651 address_family_ipv4_safi_cmd,
5652 "address-family ipv4 [<unicast|multicast|vpn|encap>]",
5653 "Enter Address Family command mode\n"
5654 "Address Family\n"
5655 BGP_SAFI_HELP_STR)
5656 {
5657 int idx_safi = 2;
5658 if (argc == (idx_safi + 1))
5659 {
5660 switch (bgp_vty_safi_from_arg(argv[idx_safi]->arg))
5661 {
5662 case SAFI_MULTICAST:
5663 vty->node = BGP_IPV4M_NODE;
5664 break;
5665 case SAFI_ENCAP:
5666 vty->node = BGP_ENCAP_NODE;
5667 break;
5668 case SAFI_MPLS_VPN:
5669 vty->node = BGP_VPNV4_NODE;
5670 break;
5671 case SAFI_UNICAST:
5672 default:
5673 vty->node = BGP_IPV4_NODE;
5674 break;
5675 }
5676 }
5677 else
5678 vty->node = BGP_IPV4_NODE;
5679
5680 return CMD_SUCCESS;
5681 }
5682
5683 DEFUN_NOSH (address_family_ipv6_safi,
5684 address_family_ipv6_safi_cmd,
5685 "address-family ipv6 [<unicast|multicast|vpn|encap>]",
5686 "Enter Address Family command mode\n"
5687 "Address Family\n"
5688 BGP_SAFI_HELP_STR)
5689 {
5690 int idx_safi = 2;
5691 if (argc == (idx_safi + 1))
5692 {
5693 switch (bgp_vty_safi_from_arg(argv[idx_safi]->arg))
5694 {
5695 case SAFI_MULTICAST:
5696 vty->node = BGP_IPV6M_NODE;
5697 break;
5698 case SAFI_ENCAP:
5699 vty->node = BGP_ENCAPV6_NODE;
5700 break;
5701 case SAFI_MPLS_VPN:
5702 vty->node = BGP_VPNV6_NODE;
5703 break;
5704 case SAFI_UNICAST:
5705 default:
5706 vty->node = BGP_IPV6_NODE;
5707 break;
5708 }
5709 }
5710 else
5711 vty->node = BGP_IPV6_NODE;
5712
5713 return CMD_SUCCESS;
5714 }
5715
5716 #ifdef KEEP_OLD_VPN_COMMANDS
5717 DEFUN_NOSH (address_family_vpnv4,
5718 address_family_vpnv4_cmd,
5719 "address-family vpnv4 [unicast]",
5720 "Enter Address Family command mode\n"
5721 "Address Family\n"
5722 "Address Family modifier\n")
5723 {
5724 vty->node = BGP_VPNV4_NODE;
5725 return CMD_SUCCESS;
5726 }
5727
5728 DEFUN_NOSH (address_family_vpnv6,
5729 address_family_vpnv6_cmd,
5730 "address-family vpnv6 [unicast]",
5731 "Enter Address Family command mode\n"
5732 "Address Family\n"
5733 "Address Family modifier\n")
5734 {
5735 vty->node = BGP_VPNV6_NODE;
5736 return CMD_SUCCESS;
5737 }
5738 #endif
5739
5740 DEFUN_NOSH (address_family_encap,
5741 address_family_encap_cmd,
5742 "address-family <encap|encapv4>",
5743 "Enter Address Family command mode\n"
5744 "Address Family\n"
5745 "Address Family\n")
5746 {
5747 vty->node = BGP_ENCAP_NODE;
5748 return CMD_SUCCESS;
5749 }
5750
5751
5752 DEFUN_NOSH (address_family_encapv6,
5753 address_family_encapv6_cmd,
5754 "address-family encapv6",
5755 "Enter Address Family command mode\n"
5756 "Address Family\n")
5757 {
5758 vty->node = BGP_ENCAPV6_NODE;
5759 return CMD_SUCCESS;
5760 }
5761
5762 DEFUN_NOSH (address_family_evpn,
5763 address_family_evpn_cmd,
5764 "address-family <l2vpn evpn>",
5765 "Enter Address Family command mode\n"
5766 "EVPN Address family\n"
5767 "Layer2 VPN Address family\n"
5768 "Ethernet Virtual Private Network Subsequent Address Family\n")
5769 {
5770 vty->node = BGP_EVPN_NODE;
5771 return CMD_SUCCESS;
5772 }
5773
5774 DEFUN_NOSH (exit_address_family,
5775 exit_address_family_cmd,
5776 "exit-address-family",
5777 "Exit from Address Family configuration mode\n")
5778 {
5779 if (vty->node == BGP_IPV4_NODE
5780 || vty->node == BGP_IPV4M_NODE
5781 || vty->node == BGP_VPNV4_NODE
5782 || vty->node == BGP_IPV6_NODE
5783 || vty->node == BGP_IPV6M_NODE
5784 || vty->node == BGP_VPNV6_NODE
5785 || vty->node == BGP_ENCAP_NODE
5786 || vty->node == BGP_ENCAPV6_NODE
5787 || vty->node == BGP_EVPN_NODE)
5788 vty->node = BGP_NODE;
5789 return CMD_SUCCESS;
5790 }
5791
5792 /* Recalculate bestpath and re-advertise a prefix */
5793 static int
5794 bgp_clear_prefix (struct vty *vty, const char *view_name, const char *ip_str,
5795 afi_t afi, safi_t safi, struct prefix_rd *prd)
5796 {
5797 int ret;
5798 struct prefix match;
5799 struct bgp_node *rn;
5800 struct bgp_node *rm;
5801 struct bgp *bgp;
5802 struct bgp_table *table;
5803 struct bgp_table *rib;
5804
5805 /* BGP structure lookup. */
5806 if (view_name)
5807 {
5808 bgp = bgp_lookup_by_name (view_name);
5809 if (bgp == NULL)
5810 {
5811 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
5812 return CMD_WARNING;
5813 }
5814 }
5815 else
5816 {
5817 bgp = bgp_get_default ();
5818 if (bgp == NULL)
5819 {
5820 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
5821 return CMD_WARNING;
5822 }
5823 }
5824
5825 /* Check IP address argument. */
5826 ret = str2prefix (ip_str, &match);
5827 if (! ret)
5828 {
5829 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
5830 return CMD_WARNING;
5831 }
5832
5833 match.family = afi2family (afi);
5834 rib = bgp->rib[afi][safi];
5835
5836 if (safi == SAFI_MPLS_VPN)
5837 {
5838 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
5839 {
5840 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5841 continue;
5842
5843 if ((table = rn->info) != NULL)
5844 {
5845 if ((rm = bgp_node_match (table, &match)) != NULL)
5846 {
5847 if (rm->p.prefixlen == match.prefixlen)
5848 {
5849 SET_FLAG (rn->flags, BGP_NODE_USER_CLEAR);
5850 bgp_process (bgp, rm, afi, safi);
5851 }
5852 bgp_unlock_node (rm);
5853 }
5854 }
5855 }
5856 }
5857 else
5858 {
5859 if ((rn = bgp_node_match (rib, &match)) != NULL)
5860 {
5861 if (rn->p.prefixlen == match.prefixlen)
5862 {
5863 SET_FLAG (rn->flags, BGP_NODE_USER_CLEAR);
5864 bgp_process (bgp, rn, afi, safi);
5865 }
5866 bgp_unlock_node (rn);
5867 }
5868 }
5869
5870 return CMD_SUCCESS;
5871 }
5872
5873 /* one clear bgp command to rule them all */
5874 DEFUN (clear_ip_bgp_all,
5875 clear_ip_bgp_all_cmd,
5876 "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>]",
5877 CLEAR_STR
5878 IP_STR
5879 BGP_STR
5880 BGP_INSTANCE_HELP_STR
5881 "Clear all peers\n"
5882 "BGP neighbor address to clear\n"
5883 "BGP IPv6 neighbor to clear\n"
5884 "BGP neighbor on interface to clear\n"
5885 "Clear peers with the AS number\n"
5886 "Clear all external peers\n"
5887 "Clear all members of peer-group\n"
5888 "BGP peer-group name\n"
5889 BGP_AFI_HELP_STR
5890 BGP_SAFI_HELP_STR
5891 BGP_SOFT_STR
5892 BGP_SOFT_IN_STR
5893 BGP_SOFT_OUT_STR
5894 BGP_SOFT_IN_STR
5895 "Push out prefix-list ORF and do inbound soft reconfig\n"
5896 BGP_SOFT_OUT_STR)
5897 {
5898 char *vrf = NULL;
5899
5900 afi_t afi = AFI_IP6;
5901 safi_t safi = SAFI_UNICAST;
5902 enum clear_sort clr_sort = clear_peer;
5903 enum bgp_clear_type clr_type;
5904 char *clr_arg = NULL;
5905
5906 int idx = 0;
5907
5908 /* clear [ip] bgp */
5909 if (argv_find (argv, argc, "ip", &idx))
5910 afi = AFI_IP;
5911 /* [<view|vrf> WORD] */
5912 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
5913 {
5914 vrf = argv[idx + 1]->arg;
5915 idx += 2;
5916 }
5917 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
5918 if (argv_find (argv, argc, "*", &idx))
5919 {
5920 clr_sort = clear_all;
5921 }
5922 else if (argv_find (argv, argc, "A.B.C.D", &idx))
5923 {
5924 clr_sort = clear_peer;
5925 clr_arg = argv[idx]->arg;
5926 }
5927 else if (argv_find (argv, argc, "X:X::X:X", &idx))
5928 {
5929 clr_sort = clear_peer;
5930 clr_arg = argv[idx]->arg;
5931 }
5932 else if (argv_find (argv, argc, "peer-group", &idx))
5933 {
5934 clr_sort = clear_group;
5935 idx++;
5936 clr_arg = argv[idx]->arg;
5937 }
5938 else if (argv_find (argv, argc, "WORD", &idx))
5939 {
5940 clr_sort = clear_peer;
5941 clr_arg = argv[idx]->arg;
5942 }
5943 else if (argv_find (argv, argc, "(1-4294967295)", &idx))
5944 {
5945 clr_sort = clear_as;
5946 clr_arg = argv[idx]->arg;
5947 }
5948 else if (argv_find (argv, argc, "external", &idx))
5949 {
5950 clr_sort = clear_external;
5951 }
5952 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
5953 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
5954 {
5955 argv_find_and_parse_safi (argv, argc, &idx, &safi);
5956 }
5957 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
5958 if (argv_find (argv, argc, "soft", &idx))
5959 {
5960 if (argv_find (argv, argc, "in", &idx) || argv_find (argv, argc, "out", &idx))
5961 clr_type = strmatch (argv[idx]->text, "in") ? BGP_CLEAR_SOFT_IN : BGP_CLEAR_SOFT_OUT;
5962 else
5963 clr_type = BGP_CLEAR_SOFT_BOTH;
5964 }
5965 else if (argv_find (argv, argc, "in", &idx))
5966 {
5967 clr_type = argv_find (argv, argc, "prefix-filter", &idx) ? BGP_CLEAR_SOFT_IN_ORF_PREFIX : BGP_CLEAR_SOFT_IN;
5968 }
5969 else if (argv_find (argv, argc, "out", &idx))
5970 {
5971 clr_type = BGP_CLEAR_SOFT_OUT;
5972 }
5973 else
5974 clr_type = BGP_CLEAR_SOFT_NONE;
5975
5976 return bgp_clear_vty (vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
5977 }
5978
5979 DEFUN (clear_ip_bgp_prefix,
5980 clear_ip_bgp_prefix_cmd,
5981 "clear [ip] bgp [<view|vrf> WORD] prefix A.B.C.D/M",
5982 CLEAR_STR
5983 IP_STR
5984 BGP_STR
5985 BGP_INSTANCE_HELP_STR
5986 "Clear bestpath and re-advertise\n"
5987 "IPv4 prefix\n")
5988 {
5989 char *vrf = NULL;
5990 char *prefix = NULL;
5991
5992 int idx = 0;
5993
5994 /* [<view|vrf> WORD] */
5995 if (argv_find (argv, argc, "WORD", &idx))
5996 vrf = argv[idx]->arg;
5997
5998 prefix = argv[argc-1]->arg;
5999
6000 return bgp_clear_prefix (vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
6001 }
6002
6003 DEFUN (clear_bgp_ipv6_safi_prefix,
6004 clear_bgp_ipv6_safi_prefix_cmd,
6005 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
6006 CLEAR_STR
6007 IP_STR
6008 BGP_STR
6009 "Address Family\n"
6010 BGP_SAFI_HELP_STR
6011 "Clear bestpath and re-advertise\n"
6012 "IPv6 prefix\n")
6013 {
6014 int idx_safi = 3;
6015 int idx_ipv6_prefixlen = 5;
6016 return bgp_clear_prefix (vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6017 bgp_vty_safi_from_arg(argv[idx_safi]->arg), NULL);
6018 }
6019
6020 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6021 clear_bgp_instance_ipv6_safi_prefix_cmd,
6022 "clear [ip] bgp <view|vrf> WORD ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
6023 CLEAR_STR
6024 IP_STR
6025 BGP_STR
6026 BGP_INSTANCE_HELP_STR
6027 "Address Family\n"
6028 BGP_SAFI_HELP_STR
6029 "Clear bestpath and re-advertise\n"
6030 "IPv6 prefix\n")
6031 {
6032 int idx_word = 3;
6033 int idx_safi = 5;
6034 int idx_ipv6_prefixlen = 7;
6035 return bgp_clear_prefix (vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6036 bgp_vty_safi_from_arg(argv[idx_safi]->arg), NULL);
6037 }
6038
6039 DEFUN (show_bgp_views,
6040 show_bgp_views_cmd,
6041 "show [ip] bgp views",
6042 SHOW_STR
6043 IP_STR
6044 BGP_STR
6045 "Show the defined BGP views\n")
6046 {
6047 struct list *inst = bm->bgp;
6048 struct listnode *node;
6049 struct bgp *bgp;
6050
6051 if (!bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
6052 {
6053 vty_out (vty, "BGP Multiple Instance is not enabled%s", VTY_NEWLINE);
6054 return CMD_WARNING;
6055 }
6056
6057 vty_out (vty, "Defined BGP views:%s", VTY_NEWLINE);
6058 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp))
6059 {
6060 /* Skip VRFs. */
6061 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6062 continue;
6063 vty_out (vty, "\t%s (AS%u)%s",
6064 bgp->name ? bgp->name : "(null)",
6065 bgp->as, VTY_NEWLINE);
6066 }
6067
6068 return CMD_SUCCESS;
6069 }
6070
6071 DEFUN (show_bgp_vrfs,
6072 show_bgp_vrfs_cmd,
6073 "show [ip] bgp vrfs [json]",
6074 SHOW_STR
6075 IP_STR
6076 BGP_STR
6077 "Show BGP VRFs\n"
6078 JSON_STR)
6079 {
6080 struct list *inst = bm->bgp;
6081 struct listnode *node;
6082 struct bgp *bgp;
6083 u_char uj = use_json(argc, argv);
6084 json_object *json = NULL;
6085 json_object *json_vrfs = NULL;
6086 int count = 0;
6087 static char header[] = "Type Id RouterId #PeersCfg #PeersEstb Name";
6088
6089 if (!bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
6090 {
6091 vty_out (vty, "BGP Multiple Instance is not enabled%s", VTY_NEWLINE);
6092 return CMD_WARNING;
6093 }
6094
6095 if (uj)
6096 {
6097 json = json_object_new_object();
6098 json_vrfs = json_object_new_object();
6099 }
6100
6101 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp))
6102 {
6103 const char *name, *type;
6104 struct peer *peer;
6105 struct listnode *node, *nnode;
6106 int peers_cfg, peers_estb;
6107 json_object *json_vrf = NULL;
6108 int vrf_id_ui;
6109
6110 /* Skip Views. */
6111 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6112 continue;
6113
6114 count++;
6115 if (!uj && count == 1)
6116 vty_out (vty, "%s%s", header, VTY_NEWLINE);
6117
6118 peers_cfg = peers_estb = 0;
6119 if (uj)
6120 json_vrf = json_object_new_object();
6121
6122
6123 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6124 {
6125 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6126 continue;
6127 peers_cfg++;
6128 if (peer->status == Established)
6129 peers_estb++;
6130 }
6131
6132 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6133 {
6134 name = "Default";
6135 type = "DFLT";
6136 }
6137 else
6138 {
6139 name = bgp->name;
6140 type = "VRF";
6141 }
6142
6143 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
6144 if (uj)
6145 {
6146 json_object_string_add(json_vrf, "type", type);
6147 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
6148 json_object_string_add(json_vrf, "routerId", inet_ntoa (bgp->router_id));
6149 json_object_int_add(json_vrf, "numConfiguredPeers", peers_cfg);
6150 json_object_int_add(json_vrf, "numEstablishedPeers", peers_estb);
6151
6152 json_object_object_add(json_vrfs, name, json_vrf);
6153 }
6154 else
6155 vty_out (vty, "%4s %-5d %-16s %9u %10u %s%s",
6156 type, vrf_id_ui, inet_ntoa (bgp->router_id),
6157 peers_cfg, peers_estb, name,
6158 VTY_NEWLINE);
6159 }
6160
6161 if (uj)
6162 {
6163 json_object_object_add(json, "vrfs", json_vrfs);
6164
6165 json_object_int_add(json, "totalVrfs", count);
6166
6167 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
6168 json_object_free(json);
6169 }
6170 else
6171 {
6172 if (count)
6173 vty_out (vty, "%sTotal number of VRFs (including default): %d%s",
6174 VTY_NEWLINE, count, VTY_NEWLINE);
6175 }
6176
6177 return CMD_SUCCESS;
6178 }
6179
6180 DEFUN (show_bgp_memory,
6181 show_bgp_memory_cmd,
6182 "show [ip] bgp memory",
6183 SHOW_STR
6184 IP_STR
6185 BGP_STR
6186 "Global BGP memory statistics\n")
6187 {
6188 char memstrbuf[MTYPE_MEMSTR_LEN];
6189 unsigned long count;
6190
6191 /* RIB related usage stats */
6192 count = mtype_stats_alloc (MTYPE_BGP_NODE);
6193 vty_out (vty, "%ld RIB nodes, using %s of memory%s", count,
6194 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6195 count * sizeof (struct bgp_node)),
6196 VTY_NEWLINE);
6197
6198 count = mtype_stats_alloc (MTYPE_BGP_ROUTE);
6199 vty_out (vty, "%ld BGP routes, using %s of memory%s", count,
6200 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6201 count * sizeof (struct bgp_info)),
6202 VTY_NEWLINE);
6203 if ((count = mtype_stats_alloc (MTYPE_BGP_ROUTE_EXTRA)))
6204 vty_out (vty, "%ld BGP route ancillaries, using %s of memory%s", count,
6205 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6206 count * sizeof (struct bgp_info_extra)),
6207 VTY_NEWLINE);
6208
6209 if ((count = mtype_stats_alloc (MTYPE_BGP_STATIC)))
6210 vty_out (vty, "%ld Static routes, using %s of memory%s", count,
6211 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6212 count * sizeof (struct bgp_static)),
6213 VTY_NEWLINE);
6214
6215 if ((count = mtype_stats_alloc (MTYPE_BGP_PACKET)))
6216 vty_out (vty, "%ld Packets, using %s of memory%s", count,
6217 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6218 count * sizeof (struct bpacket)),
6219 VTY_NEWLINE);
6220
6221 /* Adj-In/Out */
6222 if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_IN)))
6223 vty_out (vty, "%ld Adj-In entries, using %s of memory%s", count,
6224 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6225 count * sizeof (struct bgp_adj_in)),
6226 VTY_NEWLINE);
6227 if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_OUT)))
6228 vty_out (vty, "%ld Adj-Out entries, using %s of memory%s", count,
6229 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6230 count * sizeof (struct bgp_adj_out)),
6231 VTY_NEWLINE);
6232
6233 if ((count = mtype_stats_alloc (MTYPE_BGP_NEXTHOP_CACHE)))
6234 vty_out (vty, "%ld Nexthop cache entries, using %s of memory%s", count,
6235 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6236 count * sizeof (struct bgp_nexthop_cache)),
6237 VTY_NEWLINE);
6238
6239 if ((count = mtype_stats_alloc (MTYPE_BGP_DAMP_INFO)))
6240 vty_out (vty, "%ld Dampening entries, using %s of memory%s", count,
6241 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6242 count * sizeof (struct bgp_damp_info)),
6243 VTY_NEWLINE);
6244
6245 /* Attributes */
6246 count = attr_count();
6247 vty_out (vty, "%ld BGP attributes, using %s of memory%s", count,
6248 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6249 count * sizeof(struct attr)),
6250 VTY_NEWLINE);
6251 if ((count = mtype_stats_alloc (MTYPE_ATTR_EXTRA)))
6252 vty_out (vty, "%ld BGP extra attributes, using %s of memory%s", count,
6253 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6254 count * sizeof(struct attr_extra)),
6255 VTY_NEWLINE);
6256
6257 if ((count = attr_unknown_count()))
6258 vty_out (vty, "%ld unknown attributes%s", count, VTY_NEWLINE);
6259
6260 /* AS_PATH attributes */
6261 count = aspath_count ();
6262 vty_out (vty, "%ld BGP AS-PATH entries, using %s of memory%s", count,
6263 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6264 count * sizeof (struct aspath)),
6265 VTY_NEWLINE);
6266
6267 count = mtype_stats_alloc (MTYPE_AS_SEG);
6268 vty_out (vty, "%ld BGP AS-PATH segments, using %s of memory%s", count,
6269 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6270 count * sizeof (struct assegment)),
6271 VTY_NEWLINE);
6272
6273 /* Other attributes */
6274 if ((count = community_count ()))
6275 vty_out (vty, "%ld BGP community entries, using %s of memory%s", count,
6276 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6277 count * sizeof (struct community)),
6278 VTY_NEWLINE);
6279 if ((count = mtype_stats_alloc (MTYPE_ECOMMUNITY)))
6280 vty_out (vty, "%ld BGP community entries, using %s of memory%s", count,
6281 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6282 count * sizeof (struct ecommunity)),
6283 VTY_NEWLINE);
6284 if ((count = mtype_stats_alloc (MTYPE_LCOMMUNITY)))
6285 vty_out (vty, "%ld BGP large-community entries, using %s of memory%s",
6286 count,
6287 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6288 count * sizeof (struct lcommunity)),
6289 VTY_NEWLINE);
6290
6291 if ((count = mtype_stats_alloc (MTYPE_CLUSTER)))
6292 vty_out (vty, "%ld Cluster lists, using %s of memory%s", count,
6293 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6294 count * sizeof (struct cluster_list)),
6295 VTY_NEWLINE);
6296
6297 /* Peer related usage */
6298 count = mtype_stats_alloc (MTYPE_BGP_PEER);
6299 vty_out (vty, "%ld peers, using %s of memory%s", count,
6300 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6301 count * sizeof (struct peer)),
6302 VTY_NEWLINE);
6303
6304 if ((count = mtype_stats_alloc (MTYPE_PEER_GROUP)))
6305 vty_out (vty, "%ld peer groups, using %s of memory%s", count,
6306 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6307 count * sizeof (struct peer_group)),
6308 VTY_NEWLINE);
6309
6310 /* Other */
6311 if ((count = mtype_stats_alloc (MTYPE_HASH)))
6312 vty_out (vty, "%ld hash tables, using %s of memory%s", count,
6313 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6314 count * sizeof (struct hash)),
6315 VTY_NEWLINE);
6316 if ((count = mtype_stats_alloc (MTYPE_HASH_BACKET)))
6317 vty_out (vty, "%ld hash buckets, using %s of memory%s", count,
6318 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6319 count * sizeof (struct hash_backet)),
6320 VTY_NEWLINE);
6321 if ((count = mtype_stats_alloc (MTYPE_BGP_REGEXP)))
6322 vty_out (vty, "%ld compiled regexes, using %s of memory%s", count,
6323 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6324 count * sizeof (regex_t)),
6325 VTY_NEWLINE);
6326 return CMD_SUCCESS;
6327 }
6328
6329 /* Show BGP peer's summary information. */
6330 static int
6331 bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
6332 u_char use_json, json_object *json)
6333 {
6334 struct peer *peer;
6335 struct listnode *node, *nnode;
6336 unsigned int count = 0, dn_count = 0;
6337 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
6338 char neighbor_buf[VTY_BUFSIZ];
6339 int neighbor_col_default_width = 16;
6340 int len;
6341 int max_neighbor_width = 0;
6342 json_object *json_peer = NULL;
6343 json_object *json_peers = NULL;
6344
6345 if (use_json)
6346 {
6347 if (json == NULL)
6348 json = json_object_new_object();
6349
6350 json_peers = json_object_new_object();
6351 }
6352 else
6353 {
6354 /* Loop over all neighbors that will be displayed to determine how many
6355 * characters are needed for the Neighbor column
6356 */
6357 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6358 {
6359 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6360 continue;
6361
6362 if (peer->afc[afi][safi])
6363 {
6364 memset(dn_flag, '\0', sizeof(dn_flag));
6365 if (peer_dynamic_neighbor(peer))
6366 dn_flag[0] = '*';
6367
6368 if (peer->hostname && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
6369 sprintf(neighbor_buf, "%s%s(%s) ", dn_flag, peer->hostname, peer->host);
6370 else
6371 sprintf(neighbor_buf, "%s%s ", dn_flag, peer->host);
6372
6373 len = strlen(neighbor_buf);
6374
6375 if (len > max_neighbor_width)
6376 max_neighbor_width = len;
6377 }
6378 }
6379
6380 /* Originally we displayed the Neighbor column as 16
6381 * characters wide so make that the default
6382 */
6383 if (max_neighbor_width < neighbor_col_default_width)
6384 max_neighbor_width = neighbor_col_default_width;
6385 }
6386
6387 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6388 {
6389 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6390 continue;
6391
6392 if (peer->afc[afi][safi])
6393 {
6394 if (!count)
6395 {
6396 unsigned long ents;
6397 char memstrbuf[MTYPE_MEMSTR_LEN];
6398 int vrf_id_ui;
6399
6400 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
6401
6402 /* Usage summary and header */
6403 if (use_json)
6404 {
6405 json_object_string_add(json, "routerId", inet_ntoa (bgp->router_id));
6406 json_object_int_add(json, "as", bgp->as);
6407 json_object_int_add(json, "vrfId", vrf_id_ui);
6408 json_object_string_add(json, "vrfName",
6409 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6410 ? "Default" : bgp->name);
6411 }
6412 else
6413 {
6414 vty_out (vty,
6415 "BGP router identifier %s, local AS number %u vrf-id %d",
6416 inet_ntoa (bgp->router_id), bgp->as, vrf_id_ui);
6417 vty_out (vty, "%s", VTY_NEWLINE);
6418 }
6419
6420 if (bgp_update_delay_configured(bgp))
6421 {
6422 if (use_json)
6423 {
6424 json_object_int_add(json, "updateDelayLimit", bgp->v_update_delay);
6425
6426 if (bgp->v_update_delay != bgp->v_establish_wait)
6427 json_object_int_add(json, "updateDelayEstablishWait", bgp->v_establish_wait);
6428
6429 if (bgp_update_delay_active(bgp))
6430 {
6431 json_object_string_add(json, "updateDelayFirstNeighbor", bgp->update_delay_begin_time);
6432 json_object_boolean_true_add(json, "updateDelayInProgress");
6433 }
6434 else
6435 {
6436 if (bgp->update_delay_over)
6437 {
6438 json_object_string_add(json, "updateDelayFirstNeighbor",
6439 bgp->update_delay_begin_time);
6440 json_object_string_add(json, "updateDelayBestpathResumed",
6441 bgp->update_delay_end_time);
6442 json_object_string_add(json, "updateDelayZebraUpdateResume",
6443 bgp->update_delay_zebra_resume_time);
6444 json_object_string_add(json, "updateDelayPeerUpdateResume",
6445 bgp->update_delay_peers_resume_time);
6446 }
6447 }
6448 }
6449 else
6450 {
6451 vty_out (vty, "Read-only mode update-delay limit: %d seconds%s",
6452 bgp->v_update_delay, VTY_NEWLINE);
6453 if (bgp->v_update_delay != bgp->v_establish_wait)
6454 vty_out (vty, " Establish wait: %d seconds%s",
6455 bgp->v_establish_wait, VTY_NEWLINE);
6456
6457 if (bgp_update_delay_active(bgp))
6458 {
6459 vty_out (vty, " First neighbor established: %s%s",
6460 bgp->update_delay_begin_time, VTY_NEWLINE);
6461 vty_out (vty, " Delay in progress%s", VTY_NEWLINE);
6462 }
6463 else
6464 {
6465 if (bgp->update_delay_over)
6466 {
6467 vty_out (vty, " First neighbor established: %s%s",
6468 bgp->update_delay_begin_time, VTY_NEWLINE);
6469 vty_out (vty, " Best-paths resumed: %s%s",
6470 bgp->update_delay_end_time, VTY_NEWLINE);
6471 vty_out (vty, " zebra update resumed: %s%s",
6472 bgp->update_delay_zebra_resume_time, VTY_NEWLINE);
6473 vty_out (vty, " peers update resumed: %s%s",
6474 bgp->update_delay_peers_resume_time, VTY_NEWLINE);
6475 }
6476 }
6477 }
6478 }
6479
6480 if (use_json)
6481 {
6482 if (bgp_maxmed_onstartup_configured(bgp) && bgp->maxmed_active)
6483 json_object_boolean_true_add(json, "maxMedOnStartup");
6484 if (bgp->v_maxmed_admin)
6485 json_object_boolean_true_add(json, "maxMedAdministrative");
6486
6487 json_object_int_add(json, "tableVersion", bgp_table_version(bgp->rib[afi][safi]));
6488
6489 ents = bgp_table_count (bgp->rib[afi][safi]);
6490 json_object_int_add(json, "ribCount", ents);
6491 json_object_int_add(json, "ribMemory", ents * sizeof (struct bgp_node));
6492
6493 ents = listcount (bgp->peer);
6494 json_object_int_add(json, "peerCount", ents);
6495 json_object_int_add(json, "peerMemory", ents * sizeof (struct peer));
6496
6497 if ((ents = listcount (bgp->group)))
6498 {
6499 json_object_int_add(json, "peerGroupCount", ents);
6500 json_object_int_add(json, "peerGroupMemory", ents * sizeof (struct peer_group));
6501 }
6502
6503 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6504 json_object_boolean_true_add(json, "dampeningEnabled");
6505 }
6506 else
6507 {
6508 if (bgp_maxmed_onstartup_configured(bgp) && bgp->maxmed_active)
6509 vty_out (vty, "Max-med on-startup active%s", VTY_NEWLINE);
6510 if (bgp->v_maxmed_admin)
6511 vty_out (vty, "Max-med administrative active%s", VTY_NEWLINE);
6512
6513 vty_out(vty, "BGP table version %" PRIu64 "%s",
6514 bgp_table_version(bgp->rib[afi][safi]), VTY_NEWLINE);
6515
6516 ents = bgp_table_count (bgp->rib[afi][safi]);
6517 vty_out (vty, "RIB entries %ld, using %s of memory%s", ents,
6518 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6519 ents * sizeof (struct bgp_node)),
6520 VTY_NEWLINE);
6521
6522 /* Peer related usage */
6523 ents = listcount (bgp->peer);
6524 vty_out (vty, "Peers %ld, using %s of memory%s",
6525 ents,
6526 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6527 ents * sizeof (struct peer)),
6528 VTY_NEWLINE);
6529
6530 if ((ents = listcount (bgp->group)))
6531 vty_out (vty, "Peer groups %ld, using %s of memory%s", ents,
6532 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6533 ents * sizeof (struct peer_group)),
6534 VTY_NEWLINE);
6535
6536 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6537 vty_out (vty, "Dampening enabled.%s", VTY_NEWLINE);
6538 vty_out (vty, "%s", VTY_NEWLINE);
6539
6540 /* Subtract 8 here because 'Neighbor' is 8 characters */
6541 vty_out (vty, "Neighbor");
6542 vty_out (vty, "%*s", max_neighbor_width - 8, " ");
6543 vty_out (vty, "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd%s", VTY_NEWLINE);
6544 }
6545 }
6546
6547 count++;
6548
6549 if (use_json)
6550 {
6551 json_peer = json_object_new_object();
6552
6553 if (peer_dynamic_neighbor(peer))
6554 json_object_boolean_true_add(json_peer, "dynamicPeer");
6555
6556 if (peer->hostname)
6557 json_object_string_add(json_peer, "hostname", peer->hostname);
6558
6559 if (peer->domainname)
6560 json_object_string_add(json_peer, "domainname", peer->domainname);
6561
6562 json_object_int_add(json_peer, "remoteAs", peer->as);
6563 json_object_int_add(json_peer, "version", 4);
6564 json_object_int_add(json_peer, "msgRcvd",
6565 peer->open_in + peer->update_in + peer->keepalive_in
6566 + peer->notify_in + peer->refresh_in
6567 + peer->dynamic_cap_in);
6568 json_object_int_add(json_peer, "msgSent",
6569 peer->open_out + peer->update_out + peer->keepalive_out
6570 + peer->notify_out + peer->refresh_out
6571 + peer->dynamic_cap_out);
6572
6573 json_object_int_add(json_peer, "tableVersion", peer->version[afi][safi]);
6574 json_object_int_add(json_peer, "outq", peer->obuf->count);
6575 json_object_int_add(json_peer, "inq", 0);
6576 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN, use_json, json_peer);
6577 json_object_int_add(json_peer, "prefixReceivedCount", peer->pcount[afi][safi]);
6578
6579 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
6580 json_object_string_add(json_peer, "state", "Idle (Admin)");
6581 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
6582 json_object_string_add(json_peer, "state", "Idle (PfxCt)");
6583 else
6584 json_object_string_add(json_peer, "state", LOOKUP(bgp_status_msg, peer->status));
6585
6586 if (peer->conf_if)
6587 json_object_string_add(json_peer, "idType", "interface");
6588 else if (peer->su.sa.sa_family == AF_INET)
6589 json_object_string_add(json_peer, "idType", "ipv4");
6590 else if (peer->su.sa.sa_family == AF_INET6)
6591 json_object_string_add(json_peer, "idType", "ipv6");
6592
6593 json_object_object_add(json_peers, peer->host, json_peer);
6594 }
6595 else
6596 {
6597 memset(dn_flag, '\0', sizeof(dn_flag));
6598 if (peer_dynamic_neighbor(peer))
6599 {
6600 dn_count++;
6601 dn_flag[0] = '*';
6602 }
6603
6604 if (peer->hostname && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
6605 len = vty_out (vty, "%s%s(%s)", dn_flag, peer->hostname,
6606 peer->host);
6607 else
6608 len = vty_out (vty, "%s%s", dn_flag, peer->host);
6609
6610 /* pad the neighbor column with spaces */
6611 if (len < max_neighbor_width)
6612 vty_out (vty, "%*s", max_neighbor_width - len, " ");
6613
6614 vty_out (vty, "4 %10u %7d %7d %8" PRIu64 " %4d %4zd %8s",
6615 peer->as,
6616 peer->open_in + peer->update_in + peer->keepalive_in
6617 + peer->notify_in + peer->refresh_in
6618 + peer->dynamic_cap_in,
6619 peer->open_out + peer->update_out + peer->keepalive_out
6620 + peer->notify_out + peer->refresh_out
6621 + peer->dynamic_cap_out,
6622 peer->version[afi][safi],
6623 0,
6624 peer->obuf->count,
6625 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
6626
6627 if (peer->status == Established)
6628 vty_out (vty, " %12ld", peer->pcount[afi][safi]);
6629 else
6630 {
6631 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
6632 vty_out (vty, " Idle (Admin)");
6633 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
6634 vty_out (vty, " Idle (PfxCt)");
6635 else
6636 vty_out (vty, " %12s", LOOKUP(bgp_status_msg, peer->status));
6637 }
6638 vty_out (vty, "%s", VTY_NEWLINE);
6639 }
6640 }
6641 }
6642
6643 if (use_json)
6644 {
6645 json_object_object_add(json, "peers", json_peers);
6646
6647 json_object_int_add(json, "totalPeers", count);
6648 json_object_int_add(json, "dynamicPeers", dn_count);
6649
6650 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
6651 json_object_free(json);
6652 }
6653 else
6654 {
6655 if (count)
6656 vty_out (vty, "%sTotal number of neighbors %d%s", VTY_NEWLINE,
6657 count, VTY_NEWLINE);
6658 else
6659 {
6660 if (use_json)
6661 vty_out(vty, "{\"error\": {\"message\": \"No %s neighbor configured\"}}%s",
6662 afi_safi_print(afi, safi), VTY_NEWLINE);
6663 else
6664 vty_out (vty, "No %s neighbor is configured%s",
6665 afi_safi_print(afi, safi), VTY_NEWLINE);
6666 }
6667
6668 if (dn_count && ! use_json)
6669 {
6670 vty_out(vty, "* - dynamic neighbor%s", VTY_NEWLINE);
6671 vty_out(vty,
6672 "%d dynamic neighbor(s), limit %d%s",
6673 dn_count, bgp->dynamic_neighbors_limit, VTY_NEWLINE);
6674 }
6675 }
6676
6677 return CMD_SUCCESS;
6678 }
6679
6680 /*
6681 * Return if we have a peer configured to use this afi/safi
6682 */
6683 static int
6684 bgp_show_summary_afi_safi_peer_exists (struct bgp *bgp, int afi, int safi)
6685 {
6686 struct listnode *node;
6687 struct peer *peer;
6688
6689 for (ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer))
6690 {
6691 if (!CHECK_FLAG (peer->flags, PEER_FLAG_CONFIG_NODE))
6692 continue;
6693
6694 if (peer->afc[afi][safi])
6695 return 1;
6696 }
6697
6698 return 0;
6699 }
6700
6701 static void
6702 bgp_show_summary_afi_safi (struct vty *vty, struct bgp *bgp, int afi, int safi,
6703 u_char use_json, json_object *json)
6704 {
6705 int is_first = 1;
6706 int afi_wildcard = (afi == AFI_MAX);
6707 int safi_wildcard = (safi == SAFI_MAX);
6708 int is_wildcard = (afi_wildcard || safi_wildcard);
6709
6710 if (use_json && is_wildcard)
6711 vty_out (vty, "{%s", VTY_NEWLINE);
6712 if (afi_wildcard)
6713 afi = 1; /* AFI_IP */
6714 while (afi < AFI_MAX)
6715 {
6716 if (safi_wildcard)
6717 safi = 1; /* SAFI_UNICAST */
6718 while (safi < SAFI_MAX)
6719 {
6720 if (bgp_show_summary_afi_safi_peer_exists (bgp, afi, safi))
6721 {
6722 if (is_wildcard)
6723 {
6724 /*
6725 * So limit output to those afi/safi pairs that
6726 * actualy have something interesting in them
6727 */
6728 if (use_json)
6729 {
6730 json = json_object_new_object();
6731
6732 if (! is_first)
6733 vty_out (vty, ",%s", VTY_NEWLINE);
6734 else
6735 is_first = 0;
6736
6737 vty_out(vty, "\"%s\":", afi_safi_json(afi, safi));
6738 }
6739 else
6740 {
6741 vty_out (vty, "%s%s Summary:%s",
6742 VTY_NEWLINE, afi_safi_print(afi, safi), VTY_NEWLINE);
6743 }
6744 }
6745 bgp_show_summary (vty, bgp, afi, safi, use_json, json);
6746 }
6747 safi++;
6748 if (safi == SAFI_RESERVED_4 ||
6749 safi == SAFI_RESERVED_5) /* handle special cases to match zebra.h */
6750 safi++;
6751 if (! safi_wildcard)
6752 safi = SAFI_MAX;
6753 }
6754 afi++;
6755 if (! afi_wildcard ||
6756 afi == AFI_L2VPN) /* special case, not handled yet */
6757 afi = AFI_MAX;
6758 }
6759
6760 if (use_json && is_wildcard)
6761 vty_out (vty, "}%s", VTY_NEWLINE);
6762
6763 }
6764
6765 static void
6766 bgp_show_all_instances_summary_vty (struct vty *vty, afi_t afi, safi_t safi,
6767 u_char use_json)
6768 {
6769 struct listnode *node, *nnode;
6770 struct bgp *bgp;
6771 json_object *json = NULL;
6772 int is_first = 1;
6773
6774 if (use_json)
6775 vty_out (vty, "{%s", VTY_NEWLINE);
6776
6777 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
6778 {
6779 if (use_json)
6780 {
6781 json = json_object_new_object();
6782
6783 if (! is_first)
6784 vty_out (vty, ",%s", VTY_NEWLINE);
6785 else
6786 is_first = 0;
6787
6788 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6789 ? "Default" : bgp->name);
6790 }
6791 else
6792 {
6793 vty_out (vty, "%sInstance %s:%s",
6794 VTY_NEWLINE,
6795 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6796 ? "Default" : bgp->name, VTY_NEWLINE);
6797 }
6798 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, json);
6799 }
6800
6801 if (use_json)
6802 vty_out (vty, "}%s", VTY_NEWLINE);
6803
6804 }
6805
6806 static int
6807 bgp_show_summary_vty (struct vty *vty, const char *name,
6808 afi_t afi, safi_t safi, u_char use_json)
6809 {
6810 struct bgp *bgp;
6811
6812 if (name)
6813 {
6814 if (strmatch(name, "all"))
6815 {
6816 bgp_show_all_instances_summary_vty (vty, afi, safi, use_json);
6817 return CMD_SUCCESS;
6818 }
6819 else
6820 {
6821 bgp = bgp_lookup_by_name (name);
6822
6823 if (! bgp)
6824 {
6825 if (use_json)
6826 vty_out (vty, "{}%s", VTY_NEWLINE);
6827 else
6828 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
6829 return CMD_WARNING;
6830 }
6831
6832 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL);
6833 return CMD_SUCCESS;
6834 }
6835 }
6836
6837 bgp = bgp_get_default ();
6838
6839 if (bgp)
6840 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL);
6841
6842 return CMD_SUCCESS;
6843 }
6844
6845 /* `show [ip] bgp summary' commands. */
6846 DEFUN (show_ip_bgp_summary,
6847 show_ip_bgp_summary_cmd,
6848 "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] summary [json]",
6849 SHOW_STR
6850 IP_STR
6851 BGP_STR
6852 BGP_INSTANCE_HELP_STR
6853 BGP_AFI_HELP_STR
6854 BGP_SAFI_HELP_STR
6855 "Summary of BGP neighbor status\n"
6856 JSON_STR)
6857 {
6858 char *vrf = NULL;
6859 afi_t afi = AFI_MAX;
6860 safi_t safi = SAFI_MAX;
6861
6862 int idx = 0;
6863
6864 /* show [ip] bgp */
6865 if (argv_find (argv, argc, "ip", &idx))
6866 afi = AFI_IP;
6867 /* [<view|vrf> WORD] */
6868 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
6869 vrf = argv[++idx]->arg;
6870 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6871 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
6872 {
6873 argv_find_and_parse_safi (argv, argc, &idx, &safi);
6874 }
6875
6876 int uj = use_json (argc, argv);
6877
6878 return bgp_show_summary_vty (vty, vrf, afi, safi, uj);
6879 }
6880
6881 const char *
6882 afi_safi_print (afi_t afi, safi_t safi)
6883 {
6884 if (afi == AFI_IP && safi == SAFI_UNICAST)
6885 return "IPv4 Unicast";
6886 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
6887 return "IPv4 Multicast";
6888 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
6889 return "IPv4 VPN";
6890 else if (afi == AFI_IP && safi == SAFI_ENCAP)
6891 return "IPv4 Encap";
6892 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
6893 return "IPv6 Unicast";
6894 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
6895 return "IPv6 Multicast";
6896 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
6897 return "IPv6 VPN";
6898 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
6899 return "IPv6 Encap";
6900 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
6901 return "L2VPN EVPN";
6902 else
6903 return "Unknown";
6904 }
6905
6906 /*
6907 * Please note that we have intentionally camelCased
6908 * the return strings here. So if you want
6909 * to use this function, please ensure you
6910 * are doing this within json output
6911 */
6912 const char *
6913 afi_safi_json (afi_t afi, safi_t safi)
6914 {
6915 if (afi == AFI_IP && safi == SAFI_UNICAST)
6916 return "ipv4Unicast";
6917 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
6918 return "ipv4Multicast";
6919 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
6920 return "ipv4Vpn";
6921 else if (afi == AFI_IP && safi == SAFI_ENCAP)
6922 return "ipv4Encap";
6923 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
6924 return "ipv6Unicast";
6925 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
6926 return "ipv6Multicast";
6927 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
6928 return "ipv6Vpn";
6929 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
6930 return "ipv6Encap";
6931 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
6932 return "l2VpnEvpn";
6933 else
6934 return "Unknown";
6935 }
6936
6937 /* Show BGP peer's information. */
6938 enum show_type
6939 {
6940 show_all,
6941 show_peer
6942 };
6943
6944 static void
6945 bgp_show_peer_afi_orf_cap (struct vty *vty, struct peer *p, afi_t afi, safi_t safi,
6946 u_int16_t adv_smcap, u_int16_t adv_rmcap, u_int16_t rcv_smcap,
6947 u_int16_t rcv_rmcap, u_char use_json, json_object *json_pref)
6948 {
6949 /* Send-Mode */
6950 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap)
6951 || CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
6952 {
6953 if (use_json)
6954 {
6955 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap) && CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
6956 json_object_string_add(json_pref, "sendMode", "advertisedAndReceived");
6957 else if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap))
6958 json_object_string_add(json_pref, "sendMode", "advertised");
6959 else if (CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
6960 json_object_string_add(json_pref, "sendMode", "received");
6961 }
6962 else
6963 {
6964 vty_out (vty, " Send-mode: ");
6965 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap))
6966 vty_out (vty, "advertised");
6967 if (CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
6968 vty_out (vty, "%sreceived",
6969 CHECK_FLAG (p->af_cap[afi][safi], adv_smcap) ?
6970 ", " : "");
6971 vty_out (vty, "%s", VTY_NEWLINE);
6972 }
6973 }
6974
6975 /* Receive-Mode */
6976 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap)
6977 || CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
6978 {
6979 if (use_json)
6980 {
6981 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap) && CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
6982 json_object_string_add(json_pref, "recvMode", "advertisedAndReceived");
6983 else if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap))
6984 json_object_string_add(json_pref, "recvMode", "advertised");
6985 else if (CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
6986 json_object_string_add(json_pref, "recvMode", "received");
6987 }
6988 else
6989 {
6990 vty_out (vty, " Receive-mode: ");
6991 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap))
6992 vty_out (vty, "advertised");
6993 if (CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
6994 vty_out (vty, "%sreceived",
6995 CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap) ?
6996 ", " : "");
6997 vty_out (vty, "%s", VTY_NEWLINE);
6998 }
6999 }
7000 }
7001
7002 static void
7003 bgp_show_peer_afi (struct vty *vty, struct peer *p, afi_t afi, safi_t safi,
7004 u_char use_json, json_object *json_neigh)
7005 {
7006 struct bgp_filter *filter;
7007 struct peer_af *paf;
7008 char orf_pfx_name[BUFSIZ];
7009 int orf_pfx_count;
7010 json_object *json_af = NULL;
7011 json_object *json_prefA = NULL;
7012 json_object *json_prefB = NULL;
7013 json_object *json_addr = NULL;
7014
7015 if (use_json)
7016 {
7017 json_addr = json_object_new_object();
7018 json_af = json_object_new_object();
7019 filter = &p->filter[afi][safi];
7020
7021 if (peer_group_active(p))
7022 json_object_string_add(json_addr, "peerGroupMember", p->group->name);
7023
7024 paf = peer_af_find(p, afi, safi);
7025 if (paf && PAF_SUBGRP(paf))
7026 {
7027 json_object_int_add(json_addr, "updateGroupId", PAF_UPDGRP(paf)->id);
7028 json_object_int_add(json_addr, "subGroupId", PAF_SUBGRP(paf)->id);
7029 json_object_int_add(json_addr, "packetQueueLength", bpacket_queue_virtual_length(paf));
7030 }
7031
7032 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7033 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7034 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7035 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV))
7036 {
7037 json_object_int_add(json_af, "orfType", ORF_TYPE_PREFIX);
7038 json_prefA = json_object_new_object();
7039 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7040 PEER_CAP_ORF_PREFIX_SM_ADV,
7041 PEER_CAP_ORF_PREFIX_RM_ADV,
7042 PEER_CAP_ORF_PREFIX_SM_RCV,
7043 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, json_prefA);
7044 json_object_object_add(json_af, "orfPrefixList", json_prefA);
7045 }
7046
7047 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7048 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7049 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7050 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7051 {
7052 json_object_int_add(json_af, "orfOldType", ORF_TYPE_PREFIX_OLD);
7053 json_prefB = json_object_new_object();
7054 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7055 PEER_CAP_ORF_PREFIX_SM_ADV,
7056 PEER_CAP_ORF_PREFIX_RM_ADV,
7057 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7058 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, json_prefB);
7059 json_object_object_add(json_af, "orfOldPrefixList", json_prefB);
7060 }
7061
7062 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7063 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7064 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7065 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7066 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)
7067 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7068 json_object_object_add(json_addr, "afDependentCap", json_af);
7069 else
7070 json_object_free(json_af);
7071
7072 sprintf (orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7073 orf_pfx_count = prefix_bgp_show_prefix_list (NULL, afi, orf_pfx_name, use_json);
7074
7075 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND)
7076 || orf_pfx_count)
7077 {
7078 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND))
7079 json_object_boolean_true_add(json_neigh, "orfSent");
7080 if (orf_pfx_count)
7081 json_object_int_add(json_addr, "orfRecvCounter", orf_pfx_count);
7082 }
7083 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
7084 json_object_string_add(json_addr, "orfFirstUpdate", "deferredUntilORFOrRouteRefreshRecvd");
7085
7086 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7087 json_object_boolean_true_add(json_addr, "routeReflectorClient");
7088 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7089 json_object_boolean_true_add(json_addr, "routeServerClient");
7090 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7091 json_object_boolean_true_add(json_addr, "inboundSoftConfigPermit");
7092
7093 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7094 json_object_boolean_true_add(json_addr, "privateAsNumsAllReplacedInUpdatesToNbr");
7095 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7096 json_object_boolean_true_add(json_addr, "privateAsNumsReplacedInUpdatesToNbr");
7097 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7098 json_object_boolean_true_add(json_addr, "privateAsNumsAllRemovedInUpdatesToNbr");
7099 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS))
7100 json_object_boolean_true_add(json_addr, "privateAsNumsRemovedInUpdatesToNbr");
7101
7102 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7103 json_object_boolean_true_add(json_addr, "addpathTxAllPaths");
7104
7105 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7106 json_object_boolean_true_add(json_addr, "addpathTxBestpathPerAS");
7107
7108 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7109 json_object_string_add(json_addr, "overrideASNsInOutboundUpdates", "ifAspathEqualRemoteAs");
7110
7111 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
7112 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
7113 json_object_boolean_true_add(json_addr, "routerAlwaysNextHop");
7114 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED))
7115 json_object_boolean_true_add(json_addr, "unchangedAsPathPropogatedToNbr");
7116 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
7117 json_object_boolean_true_add(json_addr, "unchangedNextHopPropogatedToNbr");
7118 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7119 json_object_boolean_true_add(json_addr, "unchangedMedPropogatedToNbr");
7120 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7121 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7122 {
7123 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7124 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7125 json_object_string_add(json_addr, "commAttriSentToNbr", "extendedAndStandard");
7126 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7127 json_object_string_add(json_addr, "commAttriSentToNbr", "extended");
7128 else
7129 json_object_string_add(json_addr, "commAttriSentToNbr", "standard");
7130 }
7131 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
7132 {
7133 if (p->default_rmap[afi][safi].name)
7134 json_object_string_add(json_addr, "defaultRouteMap", p->default_rmap[afi][safi].name);
7135
7136 if (paf && PAF_SUBGRP(paf) && CHECK_FLAG(PAF_SUBGRP(paf)->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
7137 json_object_boolean_true_add(json_addr, "defaultSent");
7138 else
7139 json_object_boolean_true_add(json_addr, "defaultNotSent");
7140 }
7141
7142 if (filter->plist[FILTER_IN].name
7143 || filter->dlist[FILTER_IN].name
7144 || filter->aslist[FILTER_IN].name
7145 || filter->map[RMAP_IN].name)
7146 json_object_boolean_true_add(json_addr, "inboundPathPolicyConfig");
7147 if (filter->plist[FILTER_OUT].name
7148 || filter->dlist[FILTER_OUT].name
7149 || filter->aslist[FILTER_OUT].name
7150 || filter->map[RMAP_OUT].name
7151 || filter->usmap.name)
7152 json_object_boolean_true_add(json_addr, "outboundPathPolicyConfig");
7153
7154 /* prefix-list */
7155 if (filter->plist[FILTER_IN].name)
7156 json_object_string_add(json_addr, "incomingUpdatePrefixFilterList", filter->plist[FILTER_IN].name);
7157 if (filter->plist[FILTER_OUT].name)
7158 json_object_string_add(json_addr, "outgoingUpdatePrefixFilterList", filter->plist[FILTER_OUT].name);
7159
7160 /* distribute-list */
7161 if (filter->dlist[FILTER_IN].name)
7162 json_object_string_add(json_addr, "incomingUpdateNetworkFilterList", filter->dlist[FILTER_IN].name);
7163 if (filter->dlist[FILTER_OUT].name)
7164 json_object_string_add(json_addr, "outgoingUpdateNetworkFilterList", filter->dlist[FILTER_OUT].name);
7165
7166 /* filter-list. */
7167 if (filter->aslist[FILTER_IN].name)
7168 json_object_string_add(json_addr, "incomingUpdateAsPathFilterList", filter->aslist[FILTER_IN].name);
7169 if (filter->aslist[FILTER_OUT].name)
7170 json_object_string_add(json_addr, "outgoingUpdateAsPathFilterList", filter->aslist[FILTER_OUT].name);
7171
7172 /* route-map. */
7173 if (filter->map[RMAP_IN].name)
7174 json_object_string_add(json_addr, "routeMapForIncomingAdvertisements", filter->map[RMAP_IN].name);
7175 if (filter->map[RMAP_OUT].name)
7176 json_object_string_add(json_addr, "routeMapForOutgoingAdvertisements", filter->map[RMAP_OUT].name);
7177
7178 /* unsuppress-map */
7179 if (filter->usmap.name)
7180 json_object_string_add(json_addr, "selectiveUnsuppressRouteMap", filter->usmap.name);
7181
7182 /* Receive prefix count */
7183 json_object_int_add(json_addr, "acceptedPrefixCounter", p->pcount[afi][safi]);
7184
7185 /* Maximum prefix */
7186 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
7187 {
7188 json_object_int_add(json_addr, "prefixAllowedMax", p->pmax[afi][safi]);
7189 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
7190 json_object_boolean_true_add(json_addr, "prefixAllowedMaxWarning");
7191 json_object_int_add(json_addr, "prefixAllowedWarningThresh", p->pmax_threshold[afi][safi]);
7192 if (p->pmax_restart[afi][safi])
7193 json_object_int_add(json_addr, "prefixAllowedRestartIntervalMsecs", p->pmax_restart[afi][safi] * 60000);
7194 }
7195 json_object_object_add(json_neigh, afi_safi_print (afi, safi), json_addr);
7196
7197 }
7198 else
7199 {
7200 filter = &p->filter[afi][safi];
7201
7202 vty_out (vty, " For address family: %s%s", afi_safi_print (afi, safi),
7203 VTY_NEWLINE);
7204
7205 if (peer_group_active(p))
7206 vty_out (vty, " %s peer-group member%s", p->group->name, VTY_NEWLINE);
7207
7208 paf = peer_af_find(p, afi, safi);
7209 if (paf && PAF_SUBGRP(paf))
7210 {
7211 vty_out (vty, " Update group %" PRIu64 ", subgroup %" PRIu64 "%s",
7212 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id, VTY_NEWLINE);
7213 vty_out (vty, " Packet Queue length %d%s",
7214 bpacket_queue_virtual_length(paf), VTY_NEWLINE);
7215 }
7216 else
7217 {
7218 vty_out(vty, " Not part of any update group%s", VTY_NEWLINE);
7219 }
7220 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7221 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7222 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7223 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7224 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)
7225 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7226 vty_out (vty, " AF-dependant capabilities:%s", VTY_NEWLINE);
7227
7228 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7229 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7230 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7231 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV))
7232 {
7233 vty_out (vty, " Outbound Route Filter (ORF) type (%d) Prefix-list:%s",
7234 ORF_TYPE_PREFIX, VTY_NEWLINE);
7235 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7236 PEER_CAP_ORF_PREFIX_SM_ADV,
7237 PEER_CAP_ORF_PREFIX_RM_ADV,
7238 PEER_CAP_ORF_PREFIX_SM_RCV,
7239 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7240 }
7241 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7242 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7243 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7244 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7245 {
7246 vty_out (vty, " Outbound Route Filter (ORF) type (%d) Prefix-list:%s",
7247 ORF_TYPE_PREFIX_OLD, VTY_NEWLINE);
7248 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7249 PEER_CAP_ORF_PREFIX_SM_ADV,
7250 PEER_CAP_ORF_PREFIX_RM_ADV,
7251 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7252 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7253 }
7254
7255 sprintf (orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7256 orf_pfx_count = prefix_bgp_show_prefix_list (NULL, afi, orf_pfx_name, use_json);
7257
7258 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND)
7259 || orf_pfx_count)
7260 {
7261 vty_out (vty, " Outbound Route Filter (ORF):");
7262 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND))
7263 vty_out (vty, " sent;");
7264 if (orf_pfx_count)
7265 vty_out (vty, " received (%d entries)", orf_pfx_count);
7266 vty_out (vty, "%s", VTY_NEWLINE);
7267 }
7268 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
7269 vty_out (vty, " First update is deferred until ORF or ROUTE-REFRESH is received%s", VTY_NEWLINE);
7270
7271 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7272 vty_out (vty, " Route-Reflector Client%s", VTY_NEWLINE);
7273 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7274 vty_out (vty, " Route-Server Client%s", VTY_NEWLINE);
7275 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7276 vty_out (vty, " Inbound soft reconfiguration allowed%s", VTY_NEWLINE);
7277
7278 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7279 vty_out (vty, " Private AS numbers (all) replaced in updates to this neighbor%s", VTY_NEWLINE);
7280 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7281 vty_out (vty, " Private AS numbers replaced in updates to this neighbor%s", VTY_NEWLINE);
7282 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7283 vty_out (vty, " Private AS numbers (all) removed in updates to this neighbor%s", VTY_NEWLINE);
7284 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS))
7285 vty_out (vty, " Private AS numbers removed in updates to this neighbor%s", VTY_NEWLINE);
7286
7287 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7288 vty_out (vty, " Advertise all paths via addpath%s", VTY_NEWLINE);
7289
7290 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7291 vty_out (vty, " Advertise bestpath per AS via addpath%s", VTY_NEWLINE);
7292
7293 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7294 vty_out (vty, " Override ASNs in outbound updates if aspath equals remote-as%s", VTY_NEWLINE);
7295
7296 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
7297 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
7298 vty_out (vty, " NEXT_HOP is always this router%s", VTY_NEWLINE);
7299 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED))
7300 vty_out (vty, " AS_PATH is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7301 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
7302 vty_out (vty, " NEXT_HOP is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7303 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7304 vty_out (vty, " MED is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7305 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7306 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)
7307 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
7308 {
7309 vty_out (vty, " Community attribute sent to this neighbor");
7310 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7311 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)
7312 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
7313 vty_out (vty, "(all)%s", VTY_NEWLINE);
7314 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
7315 vty_out (vty, "(large)%s", VTY_NEWLINE);
7316 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7317 vty_out (vty, "(extended)%s", VTY_NEWLINE);
7318 else
7319 vty_out (vty, "(standard)%s", VTY_NEWLINE);
7320 }
7321 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
7322 {
7323 vty_out (vty, " Default information originate,");
7324
7325 if (p->default_rmap[afi][safi].name)
7326 vty_out (vty, " default route-map %s%s,",
7327 p->default_rmap[afi][safi].map ? "*" : "",
7328 p->default_rmap[afi][safi].name);
7329 if (paf && PAF_SUBGRP(paf) && CHECK_FLAG(PAF_SUBGRP(paf)->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
7330 vty_out (vty, " default sent%s", VTY_NEWLINE);
7331 else
7332 vty_out (vty, " default not sent%s", VTY_NEWLINE);
7333 }
7334
7335 if (filter->plist[FILTER_IN].name
7336 || filter->dlist[FILTER_IN].name
7337 || filter->aslist[FILTER_IN].name
7338 || filter->map[RMAP_IN].name)
7339 vty_out (vty, " Inbound path policy configured%s", VTY_NEWLINE);
7340 if (filter->plist[FILTER_OUT].name
7341 || filter->dlist[FILTER_OUT].name
7342 || filter->aslist[FILTER_OUT].name
7343 || filter->map[RMAP_OUT].name
7344 || filter->usmap.name)
7345 vty_out (vty, " Outbound path policy configured%s", VTY_NEWLINE);
7346
7347 /* prefix-list */
7348 if (filter->plist[FILTER_IN].name)
7349 vty_out (vty, " Incoming update prefix filter list is %s%s%s",
7350 filter->plist[FILTER_IN].plist ? "*" : "",
7351 filter->plist[FILTER_IN].name,
7352 VTY_NEWLINE);
7353 if (filter->plist[FILTER_OUT].name)
7354 vty_out (vty, " Outgoing update prefix filter list is %s%s%s",
7355 filter->plist[FILTER_OUT].plist ? "*" : "",
7356 filter->plist[FILTER_OUT].name,
7357 VTY_NEWLINE);
7358
7359 /* distribute-list */
7360 if (filter->dlist[FILTER_IN].name)
7361 vty_out (vty, " Incoming update network filter list is %s%s%s",
7362 filter->dlist[FILTER_IN].alist ? "*" : "",
7363 filter->dlist[FILTER_IN].name,
7364 VTY_NEWLINE);
7365 if (filter->dlist[FILTER_OUT].name)
7366 vty_out (vty, " Outgoing update network filter list is %s%s%s",
7367 filter->dlist[FILTER_OUT].alist ? "*" : "",
7368 filter->dlist[FILTER_OUT].name,
7369 VTY_NEWLINE);
7370
7371 /* filter-list. */
7372 if (filter->aslist[FILTER_IN].name)
7373 vty_out (vty, " Incoming update AS path filter list is %s%s%s",
7374 filter->aslist[FILTER_IN].aslist ? "*" : "",
7375 filter->aslist[FILTER_IN].name,
7376 VTY_NEWLINE);
7377 if (filter->aslist[FILTER_OUT].name)
7378 vty_out (vty, " Outgoing update AS path filter list is %s%s%s",
7379 filter->aslist[FILTER_OUT].aslist ? "*" : "",
7380 filter->aslist[FILTER_OUT].name,
7381 VTY_NEWLINE);
7382
7383 /* route-map. */
7384 if (filter->map[RMAP_IN].name)
7385 vty_out (vty, " Route map for incoming advertisements is %s%s%s",
7386 filter->map[RMAP_IN].map ? "*" : "",
7387 filter->map[RMAP_IN].name,
7388 VTY_NEWLINE);
7389 if (filter->map[RMAP_OUT].name)
7390 vty_out (vty, " Route map for outgoing advertisements is %s%s%s",
7391 filter->map[RMAP_OUT].map ? "*" : "",
7392 filter->map[RMAP_OUT].name,
7393 VTY_NEWLINE);
7394
7395 /* unsuppress-map */
7396 if (filter->usmap.name)
7397 vty_out (vty, " Route map for selective unsuppress is %s%s%s",
7398 filter->usmap.map ? "*" : "",
7399 filter->usmap.name, VTY_NEWLINE);
7400
7401 /* Receive prefix count */
7402 vty_out (vty, " %ld accepted prefixes%s", p->pcount[afi][safi], VTY_NEWLINE);
7403
7404 /* Maximum prefix */
7405 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
7406 {
7407 vty_out (vty, " Maximum prefixes allowed %ld%s%s", p->pmax[afi][safi],
7408 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)
7409 ? " (warning-only)" : "", VTY_NEWLINE);
7410 vty_out (vty, " Threshold for warning message %d%%",
7411 p->pmax_threshold[afi][safi]);
7412 if (p->pmax_restart[afi][safi])
7413 vty_out (vty, ", restart interval %d min", p->pmax_restart[afi][safi]);
7414 vty_out (vty, "%s", VTY_NEWLINE);
7415 }
7416
7417 vty_out (vty, "%s", VTY_NEWLINE);
7418 }
7419 }
7420
7421 static void
7422 bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *json)
7423 {
7424 struct bgp *bgp;
7425 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
7426 char timebuf[BGP_UPTIME_LEN];
7427 char dn_flag[2];
7428 const char *subcode_str;
7429 const char *code_str;
7430 afi_t afi;
7431 safi_t safi;
7432 u_int16_t i;
7433 u_char *msg;
7434 json_object *json_neigh = NULL;
7435
7436 bgp = p->bgp;
7437
7438 if (use_json)
7439 json_neigh = json_object_new_object();
7440
7441 memset (dn_flag, '\0', sizeof (dn_flag));
7442 if (!p->conf_if && peer_dynamic_neighbor (p))
7443 dn_flag[0] = '*';
7444
7445 if (!use_json)
7446 {
7447 if (p->conf_if) /* Configured interface name. */
7448 vty_out (vty, "BGP neighbor on %s: %s, ", p->conf_if,
7449 BGP_PEER_SU_UNSPEC(p) ? "None" :
7450 sockunion2str (&p->su, buf, SU_ADDRSTRLEN));
7451 else /* Configured IP address. */
7452 vty_out (vty, "BGP neighbor is %s%s, ", dn_flag, p->host);
7453 }
7454
7455 if (use_json)
7456 {
7457 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
7458 json_object_string_add(json_neigh, "bgpNeighborAddr", "none");
7459 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
7460 json_object_string_add(json_neigh, "bgpNeighborAddr", sockunion2str (&p->su, buf, SU_ADDRSTRLEN));
7461
7462 json_object_int_add(json_neigh, "remoteAs", p->as);
7463
7464 if (p->change_local_as)
7465 json_object_int_add(json_neigh, "localAs", p->change_local_as);
7466 else
7467 json_object_int_add(json_neigh, "localAs", p->local_as);
7468
7469 if (CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
7470 json_object_boolean_true_add(json_neigh, "localAsNoPrepend");
7471
7472 if (CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
7473 json_object_boolean_true_add(json_neigh, "localAsReplaceAs");
7474 }
7475 else
7476 {
7477 if ((p->as_type == AS_SPECIFIED) ||
7478 (p->as_type == AS_EXTERNAL) ||
7479 (p->as_type == AS_INTERNAL))
7480 vty_out (vty, "remote AS %u, ", p->as);
7481 else
7482 vty_out (vty, "remote AS Unspecified, ");
7483 vty_out (vty, "local AS %u%s%s, ",
7484 p->change_local_as ? p->change_local_as : p->local_as,
7485 CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND) ?
7486 " no-prepend" : "",
7487 CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS) ?
7488 " replace-as" : "");
7489 }
7490 /* peer type internal, external, confed-internal or confed-external */
7491 if (p->as == p->local_as)
7492 {
7493 if (use_json)
7494 {
7495 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7496 json_object_boolean_true_add(json_neigh, "nbrConfedInternalLink");
7497 else
7498 json_object_boolean_true_add(json_neigh, "nbrInternalLink");
7499 }
7500 else
7501 {
7502 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7503 vty_out (vty, "confed-internal link%s", VTY_NEWLINE);
7504 else
7505 vty_out (vty, "internal link%s", VTY_NEWLINE);
7506 }
7507 }
7508 else
7509 {
7510 if (use_json)
7511 {
7512 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7513 json_object_boolean_true_add(json_neigh, "nbrConfedExternalLink");
7514 else
7515 json_object_boolean_true_add(json_neigh, "nbrExternalLink");
7516 }
7517 else
7518 {
7519 if (bgp_confederation_peers_check(bgp, p->as))
7520 vty_out (vty, "confed-external link%s", VTY_NEWLINE);
7521 else
7522 vty_out (vty, "external link%s", VTY_NEWLINE);
7523 }
7524 }
7525
7526 /* Description. */
7527 if (p->desc)
7528 {
7529 if (use_json)
7530 json_object_string_add(json_neigh, "nbrDesc", p->desc);
7531 else
7532 vty_out (vty, " Description: %s%s", p->desc, VTY_NEWLINE);
7533 }
7534
7535 if (p->hostname)
7536 {
7537 if (use_json)
7538 {
7539 if (p->hostname)
7540 json_object_string_add(json_neigh, "hostname", p->hostname);
7541
7542 if (p->domainname)
7543 json_object_string_add(json_neigh, "domainname", p->domainname);
7544 }
7545 else
7546 {
7547 if (p->domainname && (p->domainname[0] != '\0'))
7548 vty_out(vty, "Hostname: %s.%s%s", p->hostname, p->domainname,
7549 VTY_NEWLINE);
7550 else
7551 vty_out(vty, "Hostname: %s%s", p->hostname, VTY_NEWLINE);
7552 }
7553
7554 }
7555
7556 /* Peer-group */
7557 if (p->group)
7558 {
7559 if (use_json)
7560 {
7561 json_object_string_add(json_neigh, "peerGroup", p->group->name);
7562
7563 if (dn_flag[0])
7564 {
7565 struct prefix prefix, *range = NULL;
7566
7567 sockunion2hostprefix(&(p->su), &prefix);
7568 range = peer_group_lookup_dynamic_neighbor_range (p->group, &prefix);
7569
7570 if (range)
7571 {
7572 prefix2str(range, buf1, sizeof(buf1));
7573 json_object_string_add(json_neigh, "peerSubnetRangeGroup", buf1);
7574 }
7575 }
7576 }
7577 else
7578 {
7579 vty_out (vty, " Member of peer-group %s for session parameters%s",
7580 p->group->name, VTY_NEWLINE);
7581
7582 if (dn_flag[0])
7583 {
7584 struct prefix prefix, *range = NULL;
7585
7586 sockunion2hostprefix(&(p->su), &prefix);
7587 range = peer_group_lookup_dynamic_neighbor_range (p->group, &prefix);
7588
7589 if (range)
7590 {
7591 prefix2str(range, buf1, sizeof(buf1));
7592 vty_out (vty, " Belongs to the subnet range group: %s%s", buf1, VTY_NEWLINE);
7593 }
7594 }
7595 }
7596 }
7597
7598 if (use_json)
7599 {
7600 /* Administrative shutdown. */
7601 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
7602 json_object_boolean_true_add(json_neigh, "adminShutDown");
7603
7604 /* BGP Version. */
7605 json_object_int_add(json_neigh, "bgpVersion", 4);
7606 json_object_string_add(json_neigh, "remoteRouterId",
7607 inet_ntop (AF_INET, &p->remote_id, buf1, sizeof(buf1)));
7608
7609 /* Confederation */
7610 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION) && bgp_confederation_peers_check (bgp, p->as))
7611 json_object_boolean_true_add(json_neigh, "nbrCommonAdmin");
7612
7613 /* Status. */
7614 json_object_string_add(json_neigh, "bgpState", LOOKUP (bgp_status_msg, p->status));
7615
7616 if (p->status == Established)
7617 {
7618 time_t uptime;
7619 struct tm *tm;
7620
7621 uptime = bgp_clock();
7622 uptime -= p->uptime;
7623 tm = gmtime(&uptime);
7624
7625 json_object_int_add(json_neigh, "bgpTimerUp", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
7626 }
7627
7628 else if (p->status == Active)
7629 {
7630 if (CHECK_FLAG (p->flags, PEER_FLAG_PASSIVE))
7631 json_object_string_add(json_neigh, "bgpStateIs", "passive");
7632 else if (CHECK_FLAG (p->sflags, PEER_STATUS_NSF_WAIT))
7633 json_object_string_add(json_neigh, "bgpStateIs", "passiveNSF");
7634 }
7635
7636 /* read timer */
7637 time_t uptime;
7638 struct tm *tm;
7639
7640 uptime = bgp_clock();
7641 uptime -= p->readtime;
7642 tm = gmtime(&uptime);
7643 json_object_int_add(json_neigh, "bgpTimerLastRead", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
7644
7645 uptime = bgp_clock();
7646 uptime -= p->last_write;
7647 tm = gmtime(&uptime);
7648 json_object_int_add(json_neigh, "bgpTimerLastWrite", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
7649
7650 uptime = bgp_clock();
7651 uptime -= p->update_time;
7652 tm = gmtime(&uptime);
7653 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
7654 (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
7655
7656 /* Configured timer values. */
7657 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs", p->v_holdtime * 1000);
7658 json_object_int_add(json_neigh, "bgpTimerKeepAliveIntervalMsecs", p->v_keepalive * 1000);
7659
7660 if (CHECK_FLAG (p->config, PEER_CONFIG_TIMER))
7661 {
7662 json_object_int_add(json_neigh, "bgpTimerConfiguredHoldTimeMsecs", p->holdtime * 1000);
7663 json_object_int_add(json_neigh, "bgpTimerConfiguredKeepAliveIntervalMsecs", p->keepalive * 1000);
7664 }
7665 }
7666 else
7667 {
7668 /* Administrative shutdown. */
7669 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
7670 vty_out (vty, " Administratively shut down%s", VTY_NEWLINE);
7671
7672 /* BGP Version. */
7673 vty_out (vty, " BGP version 4");
7674 vty_out (vty, ", remote router ID %s%s",
7675 inet_ntop (AF_INET, &p->remote_id, buf1, sizeof(buf1)),
7676 VTY_NEWLINE);
7677
7678 /* Confederation */
7679 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION)
7680 && bgp_confederation_peers_check (bgp, p->as))
7681 vty_out (vty, " Neighbor under common administration%s", VTY_NEWLINE);
7682
7683 /* Status. */
7684 vty_out (vty, " BGP state = %s", LOOKUP (bgp_status_msg, p->status));
7685
7686 if (p->status == Established)
7687 vty_out (vty, ", up for %8s", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
7688
7689 else if (p->status == Active)
7690 {
7691 if (CHECK_FLAG (p->flags, PEER_FLAG_PASSIVE))
7692 vty_out (vty, " (passive)");
7693 else if (CHECK_FLAG (p->sflags, PEER_STATUS_NSF_WAIT))
7694 vty_out (vty, " (NSF passive)");
7695 }
7696 vty_out (vty, "%s", VTY_NEWLINE);
7697
7698 /* read timer */
7699 vty_out (vty, " Last read %s", peer_uptime (p->readtime, timebuf, BGP_UPTIME_LEN, 0, NULL));
7700 vty_out (vty, ", Last write %s%s",
7701 peer_uptime (p->last_write, timebuf, BGP_UPTIME_LEN, 0, NULL), VTY_NEWLINE);
7702
7703 /* Configured timer values. */
7704 vty_out (vty, " Hold time is %d, keepalive interval is %d seconds%s",
7705 p->v_holdtime, p->v_keepalive, VTY_NEWLINE);
7706 if (CHECK_FLAG (p->config, PEER_CONFIG_TIMER))
7707 {
7708 vty_out (vty, " Configured hold time is %d", p->holdtime);
7709 vty_out (vty, ", keepalive interval is %d seconds%s",
7710 p->keepalive, VTY_NEWLINE);
7711 }
7712 }
7713 /* Capability. */
7714 if (p->status == Established)
7715 {
7716 if (p->cap
7717 || p->afc_adv[AFI_IP][SAFI_UNICAST]
7718 || p->afc_recv[AFI_IP][SAFI_UNICAST]
7719 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
7720 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
7721 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
7722 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
7723 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
7724 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
7725 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
7726 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
7727 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
7728 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
7729 || p->afc_adv[AFI_IP][SAFI_ENCAP]
7730 || p->afc_recv[AFI_IP][SAFI_ENCAP]
7731 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
7732 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN])
7733 {
7734 if (use_json)
7735 {
7736 json_object *json_cap = NULL;
7737
7738 json_cap = json_object_new_object();
7739
7740 /* AS4 */
7741 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV)
7742 || CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
7743 {
7744 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV) && CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
7745 json_object_string_add(json_cap, "4byteAs", "advertisedAndReceived");
7746 else if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
7747 json_object_string_add(json_cap, "4byteAs", "advertised");
7748 else if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
7749 json_object_string_add(json_cap, "4byteAs", "received");
7750 }
7751
7752 /* AddPath */
7753 if (CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_RCV)
7754 || CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_ADV))
7755 {
7756 json_object *json_add = NULL;
7757 const char *print_store;
7758
7759 json_add = json_object_new_object();
7760
7761 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7762 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7763 {
7764 json_object *json_sub = NULL;
7765 json_sub = json_object_new_object();
7766 print_store = afi_safi_print (afi, safi);
7767
7768 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
7769 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
7770 {
7771 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))
7772 json_object_boolean_true_add(json_sub, "txAdvertisedAndReceived");
7773 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV))
7774 json_object_boolean_true_add(json_sub, "txAdvertised");
7775 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
7776 json_object_boolean_true_add(json_sub, "txReceived");
7777 }
7778
7779 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
7780 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7781 {
7782 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))
7783 json_object_boolean_true_add(json_sub, "rxAdvertisedAndReceived");
7784 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV))
7785 json_object_boolean_true_add(json_sub, "rxAdvertised");
7786 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7787 json_object_boolean_true_add(json_sub, "rxReceived");
7788 }
7789
7790 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
7791 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV) ||
7792 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
7793 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7794 json_object_object_add(json_add, print_store, json_sub);
7795 else
7796 json_object_free(json_sub);
7797 }
7798
7799 json_object_object_add(json_cap, "addPath", json_add);
7800 }
7801
7802 /* Dynamic */
7803 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV)
7804 || CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
7805 {
7806 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV) && CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
7807 json_object_string_add(json_cap, "dynamic", "advertisedAndReceived");
7808 else if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
7809 json_object_string_add(json_cap, "dynamic", "advertised");
7810 else if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
7811 json_object_string_add(json_cap, "dynamic", "received");
7812 }
7813
7814 /* Extended nexthop */
7815 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV)
7816 || CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
7817 {
7818 json_object *json_nxt = NULL;
7819 const char *print_store;
7820
7821
7822 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV) && CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
7823 json_object_string_add(json_cap, "extendedNexthop", "advertisedAndReceived");
7824 else if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
7825 json_object_string_add(json_cap, "extendedNexthop", "advertised");
7826 else if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
7827 json_object_string_add(json_cap, "extendedNexthop", "received");
7828
7829 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
7830 {
7831 json_nxt = json_object_new_object();
7832
7833 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7834 {
7835 if (CHECK_FLAG (p->af_cap[AFI_IP][safi], PEER_CAP_ENHE_AF_RCV))
7836 {
7837 print_store = afi_safi_print (AFI_IP, safi);
7838 json_object_string_add(json_nxt, print_store, "recieved");
7839 }
7840 }
7841 json_object_object_add(json_cap, "extendedNexthopFamililesByPeer", json_nxt);
7842 }
7843 }
7844
7845 /* Route Refresh */
7846 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV)
7847 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
7848 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
7849 {
7850 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)))
7851 {
7852 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV) && CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV))
7853 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedOldNew");
7854 else
7855 {
7856 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
7857 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedOld");
7858 else
7859 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedNew");
7860 }
7861 }
7862 else if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV))
7863 json_object_string_add(json_cap, "routeRefresh", "advertised");
7864 else if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV) || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
7865 json_object_string_add(json_cap, "routeRefresh", "received");
7866 }
7867
7868 /* Multiprotocol Extensions */
7869 json_object *json_multi = NULL;
7870 json_multi = json_object_new_object();
7871
7872 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7873 {
7874 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7875 {
7876 if (p->afc_adv[afi][safi] || p->afc_recv[afi][safi])
7877 {
7878 json_object *json_exten = NULL;
7879 json_exten = json_object_new_object();
7880
7881 if (p->afc_adv[afi][safi] && p->afc_recv[afi][safi])
7882 json_object_boolean_true_add(json_exten, "advertisedAndReceived");
7883 else if (p->afc_adv[afi][safi])
7884 json_object_boolean_true_add(json_exten, "advertised");
7885 else if (p->afc_recv[afi][safi])
7886 json_object_boolean_true_add(json_exten, "received");
7887
7888 json_object_object_add(json_multi, afi_safi_print (afi, safi), json_exten);
7889 }
7890 }
7891 }
7892 json_object_object_add(json_cap, "multiprotocolExtensions", json_multi);
7893
7894 /* Gracefull Restart */
7895 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
7896 || CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
7897 {
7898 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV) && CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
7899 json_object_string_add(json_cap, "gracefulRestart", "advertisedAndReceived");
7900 else if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
7901 json_object_string_add(json_cap, "gracefulRestartCapability", "advertised");
7902 else if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
7903 json_object_string_add(json_cap, "gracefulRestartCapability", "received");
7904
7905 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
7906 {
7907 int restart_af_count = 0;
7908 json_object *json_restart = NULL;
7909 json_restart = json_object_new_object();
7910
7911 json_object_int_add(json_cap, "gracefulRestartRemoteTimerMsecs", p->v_gr_restart * 1000);
7912
7913 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7914 {
7915 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7916 {
7917 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV))
7918 {
7919 json_object *json_sub = NULL;
7920 json_sub = json_object_new_object();
7921
7922 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV))
7923 json_object_boolean_true_add(json_sub, "preserved");
7924 restart_af_count++;
7925 json_object_object_add(json_restart, afi_safi_print (afi, safi), json_sub);
7926 }
7927 }
7928 }
7929 if (! restart_af_count)
7930 {
7931 json_object_string_add(json_cap, "addressFamiliesByPeer", "none");
7932 json_object_free(json_restart);
7933 }
7934 else
7935 json_object_object_add(json_cap, "addressFamiliesByPeer", json_restart);
7936 }
7937 }
7938 json_object_object_add(json_neigh, "neighborCapabilities", json_cap);
7939 }
7940 else
7941 {
7942 vty_out (vty, " Neighbor capabilities:%s", VTY_NEWLINE);
7943
7944 /* AS4 */
7945 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV)
7946 || CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
7947 {
7948 vty_out (vty, " 4 Byte AS:");
7949 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
7950 vty_out (vty, " advertised");
7951 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
7952 vty_out (vty, " %sreceived",
7953 CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV) ? "and " : "");
7954 vty_out (vty, "%s", VTY_NEWLINE);
7955 }
7956
7957 /* AddPath */
7958 if (CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_RCV)
7959 || CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_ADV))
7960 {
7961 vty_out (vty, " AddPath:%s", VTY_NEWLINE);
7962
7963 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7964 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7965 {
7966 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
7967 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
7968 {
7969 vty_out (vty, " %s: TX ", afi_safi_print (afi, safi));
7970
7971 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV))
7972 vty_out (vty, "advertised %s", afi_safi_print (afi, safi));
7973
7974 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
7975 vty_out (vty, "%sreceived", CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ? " and " : "" );
7976
7977 vty_out (vty, "%s", VTY_NEWLINE);
7978 }
7979
7980 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
7981 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7982 {
7983 vty_out (vty, " %s: RX ", afi_safi_print (afi, safi));
7984
7985 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV))
7986 vty_out (vty, "advertised %s", afi_safi_print (afi, safi));
7987
7988 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7989 vty_out (vty, "%sreceived", CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ? " and " : "" );
7990
7991 vty_out (vty, "%s", VTY_NEWLINE);
7992 }
7993 }
7994 }
7995
7996 /* Dynamic */
7997 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV)
7998 || CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
7999 {
8000 vty_out (vty, " Dynamic:");
8001 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8002 vty_out (vty, " advertised");
8003 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
8004 vty_out (vty, " %sreceived",
8005 CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV) ? "and " : "");
8006 vty_out (vty, "%s", VTY_NEWLINE);
8007 }
8008
8009 /* Extended nexthop */
8010 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV)
8011 || CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8012 {
8013 vty_out (vty, " Extended nexthop:");
8014 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8015 vty_out (vty, " advertised");
8016 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8017 vty_out (vty, " %sreceived",
8018 CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV) ? "and " : "");
8019 vty_out (vty, "%s", VTY_NEWLINE);
8020
8021 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8022 {
8023 vty_out (vty, " Address families by peer:%s ", VTY_NEWLINE);
8024 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8025 if (CHECK_FLAG (p->af_cap[AFI_IP][safi], PEER_CAP_ENHE_AF_RCV))
8026 vty_out (vty, " %s%s",
8027 afi_safi_print (AFI_IP, safi), VTY_NEWLINE);
8028 }
8029 }
8030
8031 /* Route Refresh */
8032 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV)
8033 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
8034 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8035 {
8036 vty_out (vty, " Route refresh:");
8037 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV))
8038 vty_out (vty, " advertised");
8039 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
8040 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8041 vty_out (vty, " %sreceived(%s)",
8042 CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV) ? "and " : "",
8043 (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV)
8044 && CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)) ?
8045 "old & new" : CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV) ? "old" : "new");
8046
8047 vty_out (vty, "%s", VTY_NEWLINE);
8048 }
8049
8050 /* Multiprotocol Extensions */
8051 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8052 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8053 if (p->afc_adv[afi][safi] || p->afc_recv[afi][safi])
8054 {
8055 vty_out (vty, " Address Family %s:", afi_safi_print (afi, safi));
8056 if (p->afc_adv[afi][safi])
8057 vty_out (vty, " advertised");
8058 if (p->afc_recv[afi][safi])
8059 vty_out (vty, " %sreceived", p->afc_adv[afi][safi] ? "and " : "");
8060 vty_out (vty, "%s", VTY_NEWLINE);
8061 }
8062
8063 /* Hostname capability */
8064 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV) ||
8065 CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV))
8066 {
8067 vty_out (vty, " Hostname Capability:");
8068 if (CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_ADV))
8069 vty_out (vty, " advertised");
8070 if (CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_RCV))
8071 vty_out (vty, " %sreceived",
8072 CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_ADV) ? "and " : "");
8073 vty_out (vty, "%s", VTY_NEWLINE);
8074 }
8075
8076 /* Gracefull Restart */
8077 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8078 || CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8079 {
8080 vty_out (vty, " Graceful Restart Capabilty:");
8081 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8082 vty_out (vty, " advertised");
8083 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8084 vty_out (vty, " %sreceived",
8085 CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV) ? "and " : "");
8086 vty_out (vty, "%s", VTY_NEWLINE);
8087
8088 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8089 {
8090 int restart_af_count = 0;
8091
8092 vty_out (vty, " Remote Restart timer is %d seconds%s",
8093 p->v_gr_restart, VTY_NEWLINE);
8094 vty_out (vty, " Address families by peer:%s ", VTY_NEWLINE);
8095
8096 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8097 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8098 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV))
8099 {
8100 vty_out (vty, "%s%s(%s)", restart_af_count ? ", " : "",
8101 afi_safi_print (afi, safi),
8102 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV) ?
8103 "preserved" : "not preserved");
8104 restart_af_count++;
8105 }
8106 if (! restart_af_count)
8107 vty_out (vty, "none");
8108 vty_out (vty, "%s", VTY_NEWLINE);
8109 }
8110 }
8111 }
8112 }
8113 }
8114
8115 /* graceful restart information */
8116 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8117 || p->t_gr_restart
8118 || p->t_gr_stale)
8119 {
8120 json_object *json_grace = NULL;
8121 json_object *json_grace_send = NULL;
8122 json_object *json_grace_recv = NULL;
8123 int eor_send_af_count = 0;
8124 int eor_receive_af_count = 0;
8125
8126 if (use_json)
8127 {
8128 json_grace = json_object_new_object();
8129 json_grace_send = json_object_new_object();
8130 json_grace_recv = json_object_new_object();
8131
8132 if (p->status == Established)
8133 {
8134 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8135 {
8136 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8137 {
8138 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_SEND))
8139 {
8140 json_object_boolean_true_add(json_grace_send, afi_safi_print (afi, safi));
8141 eor_send_af_count++;
8142 }
8143 }
8144 }
8145 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8146 {
8147 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8148 {
8149 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED))
8150 {
8151 json_object_boolean_true_add(json_grace_recv, afi_safi_print (afi, safi));
8152 eor_receive_af_count++;
8153 }
8154 }
8155 }
8156 }
8157
8158 json_object_object_add(json_grace, "endOfRibSend", json_grace_send);
8159 json_object_object_add(json_grace, "endOfRibRecv", json_grace_recv);
8160
8161 if (p->t_gr_restart)
8162 json_object_int_add(json_grace, "gracefulRestartTimerMsecs", thread_timer_remain_second (p->t_gr_restart) * 1000);
8163
8164 if (p->t_gr_stale)
8165 json_object_int_add(json_grace, "gracefulStalepathTimerMsecs", thread_timer_remain_second (p->t_gr_stale) * 1000);
8166
8167 json_object_object_add(json_neigh, "gracefulRestartInfo", json_grace);
8168 }
8169 else
8170 {
8171 vty_out (vty, " Graceful restart informations:%s", VTY_NEWLINE);
8172 if (p->status == Established)
8173 {
8174 vty_out (vty, " End-of-RIB send: ");
8175 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8176 {
8177 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8178 {
8179 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_SEND))
8180 {
8181 vty_out (vty, "%s%s", eor_send_af_count ? ", " : "",
8182 afi_safi_print (afi, safi));
8183 eor_send_af_count++;
8184 }
8185 }
8186 }
8187 vty_out (vty, "%s", VTY_NEWLINE);
8188 vty_out (vty, " End-of-RIB received: ");
8189 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8190 {
8191 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8192 {
8193 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED))
8194 {
8195 vty_out (vty, "%s%s", eor_receive_af_count ? ", " : "",
8196 afi_safi_print (afi, safi));
8197 eor_receive_af_count++;
8198 }
8199 }
8200 }
8201 vty_out (vty, "%s", VTY_NEWLINE);
8202 }
8203
8204 if (p->t_gr_restart)
8205 vty_out (vty, " The remaining time of restart timer is %ld%s",
8206 thread_timer_remain_second (p->t_gr_restart), VTY_NEWLINE);
8207
8208 if (p->t_gr_stale)
8209 vty_out (vty, " The remaining time of stalepath timer is %ld%s",
8210 thread_timer_remain_second (p->t_gr_stale), VTY_NEWLINE);
8211 }
8212 }
8213 if (use_json)
8214 {
8215 json_object *json_stat = NULL;
8216 json_stat = json_object_new_object();
8217 /* Packet counts. */
8218 json_object_int_add(json_stat, "depthInq", 0);
8219 json_object_int_add(json_stat, "depthOutq", (unsigned long) p->obuf->count);
8220 json_object_int_add(json_stat, "opensSent", p->open_out);
8221 json_object_int_add(json_stat, "opensRecv", p->open_in);
8222 json_object_int_add(json_stat, "notificationsSent", p->notify_out);
8223 json_object_int_add(json_stat, "notificationsRecv", p->notify_in);
8224 json_object_int_add(json_stat, "updatesSent", p->update_out);
8225 json_object_int_add(json_stat, "updatesRecv", p->update_in);
8226 json_object_int_add(json_stat, "keepalivesSent", p->keepalive_out);
8227 json_object_int_add(json_stat, "keepalivesRecv", p->keepalive_in);
8228 json_object_int_add(json_stat, "routeRefreshSent", p->refresh_out);
8229 json_object_int_add(json_stat, "routeRefreshRecv", p->refresh_in);
8230 json_object_int_add(json_stat, "capabilitySent", p->dynamic_cap_out);
8231 json_object_int_add(json_stat, "capabilityRecv", p->dynamic_cap_in);
8232 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);
8233 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);
8234 json_object_object_add(json_neigh, "messageStats", json_stat);
8235 }
8236 else
8237 {
8238 /* Packet counts. */
8239 vty_out (vty, " Message statistics:%s", VTY_NEWLINE);
8240 vty_out (vty, " Inq depth is 0%s", VTY_NEWLINE);
8241 vty_out (vty, " Outq depth is %lu%s", (unsigned long) p->obuf->count, VTY_NEWLINE);
8242 vty_out (vty, " Sent Rcvd%s", VTY_NEWLINE);
8243 vty_out (vty, " Opens: %10d %10d%s", p->open_out, p->open_in, VTY_NEWLINE);
8244 vty_out (vty, " Notifications: %10d %10d%s", p->notify_out, p->notify_in, VTY_NEWLINE);
8245 vty_out (vty, " Updates: %10d %10d%s", p->update_out, p->update_in, VTY_NEWLINE);
8246 vty_out (vty, " Keepalives: %10d %10d%s", p->keepalive_out, p->keepalive_in, VTY_NEWLINE);
8247 vty_out (vty, " Route Refresh: %10d %10d%s", p->refresh_out, p->refresh_in, VTY_NEWLINE);
8248 vty_out (vty, " Capability: %10d %10d%s", p->dynamic_cap_out, p->dynamic_cap_in, VTY_NEWLINE);
8249 vty_out (vty, " Total: %10d %10d%s", p->open_out + p->notify_out +
8250 p->update_out + p->keepalive_out + p->refresh_out + p->dynamic_cap_out,
8251 p->open_in + p->notify_in + p->update_in + p->keepalive_in + p->refresh_in +
8252 p->dynamic_cap_in, VTY_NEWLINE);
8253 }
8254
8255 if (use_json)
8256 {
8257 /* advertisement-interval */
8258 json_object_int_add(json_neigh, "minBtwnAdvertisementRunsTimerMsecs", p->v_routeadv * 1000);
8259
8260 /* Update-source. */
8261 if (p->update_if || p->update_source)
8262 {
8263 if (p->update_if)
8264 json_object_string_add(json_neigh, "updateSource", p->update_if);
8265 else if (p->update_source)
8266 json_object_string_add(json_neigh, "updateSource", sockunion2str (p->update_source, buf1, SU_ADDRSTRLEN));
8267 }
8268 }
8269 else
8270 {
8271 /* advertisement-interval */
8272 vty_out (vty, " Minimum time between advertisement runs is %d seconds%s",
8273 p->v_routeadv, VTY_NEWLINE);
8274
8275 /* Update-source. */
8276 if (p->update_if || p->update_source)
8277 {
8278 vty_out (vty, " Update source is ");
8279 if (p->update_if)
8280 vty_out (vty, "%s", p->update_if);
8281 else if (p->update_source)
8282 vty_out (vty, "%s", sockunion2str (p->update_source, buf1, SU_ADDRSTRLEN));
8283 vty_out (vty, "%s", VTY_NEWLINE);
8284 }
8285
8286 vty_out (vty, "%s", VTY_NEWLINE);
8287 }
8288
8289 /* Address Family Information */
8290 json_object *json_hold = NULL;
8291
8292 if (use_json)
8293 json_hold = json_object_new_object();
8294
8295 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8296 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8297 if (p->afc[afi][safi])
8298 bgp_show_peer_afi (vty, p, afi, safi, use_json, json_hold);
8299
8300 if (use_json)
8301 {
8302 json_object_object_add(json_neigh, "addressFamilyInfo", json_hold);
8303 json_object_int_add(json_neigh, "connectionsEstablished", p->established);
8304 json_object_int_add(json_neigh, "connectionsDropped", p->dropped);
8305 }
8306 else
8307 vty_out (vty, " Connections established %d; dropped %d%s", p->established, p->dropped,
8308 VTY_NEWLINE);
8309
8310 if (! p->last_reset)
8311 {
8312 if (use_json)
8313 json_object_string_add(json_neigh, "lastReset", "never");
8314 else
8315 vty_out (vty, " Last reset never%s", VTY_NEWLINE);
8316 }
8317 else
8318 {
8319 if (use_json)
8320 {
8321 time_t uptime;
8322 struct tm *tm;
8323
8324 uptime = bgp_clock();
8325 uptime -= p->resettime;
8326 tm = gmtime(&uptime);
8327 json_object_int_add(json_neigh, "lastResetTimerMsecs", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8328 json_object_string_add(json_neigh, "lastResetDueTo", peer_down_str[(int) p->last_reset]);
8329 if (p->last_reset == PEER_DOWN_NOTIFY_SEND ||
8330 p->last_reset == PEER_DOWN_NOTIFY_RECEIVED)
8331 {
8332 char errorcodesubcode_hexstr[5];
8333 char errorcodesubcode_str[256];
8334
8335 code_str = bgp_notify_code_str(p->notify.code);
8336 subcode_str = bgp_notify_subcode_str(p->notify.code, p->notify.subcode);
8337
8338 sprintf(errorcodesubcode_hexstr, "%02X%02X", p->notify.code, p->notify.subcode);
8339 json_object_string_add(json_neigh, "lastErrorCodeSubcode", errorcodesubcode_hexstr);
8340 snprintf(errorcodesubcode_str, 255, "%s%s", code_str, subcode_str);
8341 json_object_string_add(json_neigh, "lastNotificationReason", errorcodesubcode_str);
8342 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8343 && p->notify.code == BGP_NOTIFY_CEASE
8344 && (p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8345 || p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_RESET)
8346 && p->notify.length)
8347 {
8348 char msgbuf[1024];
8349 const char *msg_str;
8350
8351 msg_str = bgp_notify_admin_message(msgbuf, sizeof(msgbuf),
8352 (u_char*)p->notify.data, p->notify.length);
8353 if (msg_str)
8354 json_object_string_add(json_neigh, "lastShutdownDescription", msg_str);
8355 }
8356 }
8357 }
8358 else
8359 {
8360 vty_out (vty, " Last reset %s, ",
8361 peer_uptime (p->resettime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8362
8363 if (p->last_reset == PEER_DOWN_NOTIFY_SEND ||
8364 p->last_reset == PEER_DOWN_NOTIFY_RECEIVED)
8365 {
8366 code_str = bgp_notify_code_str(p->notify.code);
8367 subcode_str = bgp_notify_subcode_str(p->notify.code, p->notify.subcode);
8368 vty_out (vty, "due to NOTIFICATION %s (%s%s)%s",
8369 p->last_reset == PEER_DOWN_NOTIFY_SEND ? "sent" : "received",
8370 code_str, subcode_str, VTY_NEWLINE);
8371 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8372 && p->notify.code == BGP_NOTIFY_CEASE
8373 && (p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8374 || p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_RESET)
8375 && p->notify.length)
8376 {
8377 char msgbuf[1024];
8378 const char *msg_str;
8379
8380 msg_str = bgp_notify_admin_message(msgbuf, sizeof(msgbuf),
8381 (u_char*)p->notify.data, p->notify.length);
8382 if (msg_str)
8383 vty_out (vty, " Message: \"%s\"%s", msg_str, VTY_NEWLINE);
8384 }
8385 }
8386 else
8387 {
8388 vty_out (vty, "due to %s%s",
8389 peer_down_str[(int) p->last_reset], VTY_NEWLINE);
8390 }
8391
8392 if (p->last_reset_cause_size)
8393 {
8394 msg = p->last_reset_cause;
8395 vty_out(vty, " Message received that caused BGP to send a NOTIFICATION:%s ", VTY_NEWLINE);
8396 for (i = 1; i <= p->last_reset_cause_size; i++)
8397 {
8398 vty_out(vty, "%02X", *msg++);
8399
8400 if (i != p->last_reset_cause_size)
8401 {
8402 if (i % 16 == 0)
8403 {
8404 vty_out(vty, "%s ", VTY_NEWLINE);
8405 }
8406 else if (i % 4 == 0)
8407 {
8408 vty_out(vty, " ");
8409 }
8410 }
8411 }
8412 vty_out(vty, "%s", VTY_NEWLINE);
8413 }
8414 }
8415 }
8416
8417 if (CHECK_FLAG (p->sflags, PEER_STATUS_PREFIX_OVERFLOW))
8418 {
8419 if (use_json)
8420 json_object_boolean_true_add(json_neigh, "prefixesConfigExceedMax");
8421 else
8422 vty_out (vty, " Peer had exceeded the max. no. of prefixes configured.%s", VTY_NEWLINE);
8423
8424 if (p->t_pmax_restart)
8425 {
8426 if (use_json)
8427 {
8428 json_object_boolean_true_add(json_neigh, "reducePrefixNumFrom");
8429 json_object_int_add(json_neigh, "restartInTimerMsec", thread_timer_remain_second (p->t_pmax_restart) * 1000);
8430 }
8431 else
8432 vty_out (vty, " Reduce the no. of prefix from %s, will restart in %ld seconds%s",
8433 p->host, thread_timer_remain_second (p->t_pmax_restart),
8434 VTY_NEWLINE);
8435 }
8436 else
8437 {
8438 if (use_json)
8439 json_object_boolean_true_add(json_neigh, "reducePrefixNumAndClearIpBgp");
8440 else
8441 vty_out (vty, " Reduce the no. of prefix and clear ip bgp %s to restore peering%s",
8442 p->host, VTY_NEWLINE);
8443 }
8444 }
8445
8446 /* EBGP Multihop and GTSM */
8447 if (p->sort != BGP_PEER_IBGP)
8448 {
8449 if (use_json)
8450 {
8451 if (p->gtsm_hops > 0)
8452 json_object_int_add(json_neigh, "externalBgpNbrMaxHopsAway", p->gtsm_hops);
8453 else if (p->ttl > 1)
8454 json_object_int_add(json_neigh, "externalBgpNbrMaxHopsAway", p->ttl);
8455 }
8456 else
8457 {
8458 if (p->gtsm_hops > 0)
8459 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
8460 p->gtsm_hops, VTY_NEWLINE);
8461 else if (p->ttl > 1)
8462 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
8463 p->ttl, VTY_NEWLINE);
8464 }
8465 }
8466 else
8467 {
8468 if (p->gtsm_hops > 0)
8469 {
8470 if (use_json)
8471 json_object_int_add(json_neigh, "internalBgpNbrMaxHopsAway", p->gtsm_hops);
8472 else
8473 vty_out (vty, " Internal BGP neighbor may be up to %d hops away.%s",
8474 p->gtsm_hops, VTY_NEWLINE);
8475 }
8476 }
8477
8478 /* Local address. */
8479 if (p->su_local)
8480 {
8481 if (use_json)
8482 {
8483 json_object_string_add(json_neigh, "hostLocal", sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN));
8484 json_object_int_add(json_neigh, "portLocal", ntohs (p->su_local->sin.sin_port));
8485 }
8486 else
8487 vty_out (vty, "Local host: %s, Local port: %d%s",
8488 sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN),
8489 ntohs (p->su_local->sin.sin_port),
8490 VTY_NEWLINE);
8491 }
8492
8493 /* Remote address. */
8494 if (p->su_remote)
8495 {
8496 if (use_json)
8497 {
8498 json_object_string_add(json_neigh, "hostForeign", sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN));
8499 json_object_int_add(json_neigh, "portForeign", ntohs (p->su_remote->sin.sin_port));
8500 }
8501 else
8502 vty_out (vty, "Foreign host: %s, Foreign port: %d%s",
8503 sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN),
8504 ntohs (p->su_remote->sin.sin_port),
8505 VTY_NEWLINE);
8506 }
8507
8508 /* Nexthop display. */
8509 if (p->su_local)
8510 {
8511 if (use_json)
8512 {
8513 json_object_string_add(json_neigh, "nexthop",
8514 inet_ntop (AF_INET, &p->nexthop.v4, buf1, sizeof(buf1)));
8515 json_object_string_add(json_neigh, "nexthopGlobal",
8516 inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, sizeof(buf1)));
8517 json_object_string_add(json_neigh, "nexthopLocal",
8518 inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, sizeof(buf1)));
8519 if (p->shared_network)
8520 json_object_string_add(json_neigh, "bgpConnection", "sharedNetwork");
8521 else
8522 json_object_string_add(json_neigh, "bgpConnection", "nonSharedNetwork");
8523 }
8524 else
8525 {
8526 vty_out (vty, "Nexthop: %s%s",
8527 inet_ntop (AF_INET, &p->nexthop.v4, buf1, sizeof(buf1)),
8528 VTY_NEWLINE);
8529 vty_out (vty, "Nexthop global: %s%s",
8530 inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, sizeof(buf1)),
8531 VTY_NEWLINE);
8532 vty_out (vty, "Nexthop local: %s%s",
8533 inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, sizeof(buf1)),
8534 VTY_NEWLINE);
8535 vty_out (vty, "BGP connection: %s%s",
8536 p->shared_network ? "shared network" : "non shared network",
8537 VTY_NEWLINE);
8538 }
8539 }
8540
8541 /* Timer information. */
8542 if (use_json)
8543 {
8544 json_object_int_add(json_neigh, "connectRetryTimer", p->v_connect);
8545 if (p->status == Established && p->rtt)
8546 json_object_int_add(json_neigh, "estimatedRttInMsecs", p->rtt);
8547 if (p->t_start)
8548 json_object_int_add(json_neigh, "nextStartTimerDueInMsecs", thread_timer_remain_second (p->t_start) * 1000);
8549 if (p->t_connect)
8550 json_object_int_add(json_neigh, "nextConnectTimerDueInMsecs", thread_timer_remain_second (p->t_connect) * 1000);
8551 if (p->t_routeadv)
8552 {
8553 json_object_int_add(json_neigh, "mraiInterval", p->v_routeadv);
8554 json_object_int_add(json_neigh, "mraiTimerExpireInMsecs", thread_timer_remain_second (p->t_routeadv) * 1000);
8555 }
8556
8557 if (p->t_read)
8558 json_object_string_add(json_neigh, "readThread", "on");
8559 else
8560 json_object_string_add(json_neigh, "readThread", "off");
8561 if (p->t_write)
8562 json_object_string_add(json_neigh, "writeThread", "on");
8563 else
8564 json_object_string_add(json_neigh, "writeThread", "off");
8565 }
8566 else
8567 {
8568 vty_out (vty, "BGP Connect Retry Timer in Seconds: %d%s",
8569 p->v_connect, VTY_NEWLINE);
8570 if (p->status == Established && p->rtt)
8571 vty_out (vty, "Estimated round trip time: %d ms%s",
8572 p->rtt, VTY_NEWLINE);
8573 if (p->t_start)
8574 vty_out (vty, "Next start timer due in %ld seconds%s",
8575 thread_timer_remain_second (p->t_start), VTY_NEWLINE);
8576 if (p->t_connect)
8577 vty_out (vty, "Next connect timer due in %ld seconds%s",
8578 thread_timer_remain_second (p->t_connect), VTY_NEWLINE);
8579 if (p->t_routeadv)
8580 vty_out (vty, "MRAI (interval %u) timer expires in %ld seconds%s",
8581 p->v_routeadv, thread_timer_remain_second (p->t_routeadv),
8582 VTY_NEWLINE);
8583
8584 vty_out (vty, "Read thread: %s Write thread: %s%s",
8585 p->t_read ? "on" : "off",
8586 p->t_write ? "on" : "off",
8587 VTY_NEWLINE);
8588 }
8589
8590 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
8591 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
8592 bgp_capability_vty_out (vty, p, use_json, json_neigh);
8593
8594 if (!use_json)
8595 vty_out (vty, "%s", VTY_NEWLINE);
8596
8597 /* BFD information. */
8598 bgp_bfd_show_info(vty, p, use_json, json_neigh);
8599
8600 if (use_json)
8601 {
8602 if (p->conf_if) /* Configured interface name. */
8603 json_object_object_add(json, p->conf_if, json_neigh);
8604 else /* Configured IP address. */
8605 json_object_object_add(json, p->host, json_neigh);
8606 }
8607 }
8608
8609 static int
8610 bgp_show_neighbor (struct vty *vty, struct bgp *bgp, enum show_type type,
8611 union sockunion *su, const char *conf_if, u_char use_json, json_object *json)
8612 {
8613 struct listnode *node, *nnode;
8614 struct peer *peer;
8615 int find = 0;
8616
8617 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
8618 {
8619 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8620 continue;
8621
8622 switch (type)
8623 {
8624 case show_all:
8625 bgp_show_peer (vty, peer, use_json, json);
8626 break;
8627 case show_peer:
8628 if (conf_if)
8629 {
8630 if ((peer->conf_if && !strcmp(peer->conf_if, conf_if)) ||
8631 (peer->hostname && !strcmp(peer->hostname, conf_if)))
8632 {
8633 find = 1;
8634 bgp_show_peer (vty, peer, use_json, json);
8635 }
8636 }
8637 else
8638 {
8639 if (sockunion_same (&peer->su, su))
8640 {
8641 find = 1;
8642 bgp_show_peer (vty, peer, use_json, json);
8643 }
8644 }
8645 break;
8646 }
8647 }
8648
8649 if (type == show_peer && ! find)
8650 {
8651 if (use_json)
8652 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
8653 else
8654 vty_out (vty, "%% No such neighbor%s", VTY_NEWLINE);
8655 }
8656
8657 if (use_json)
8658 {
8659 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8660 json_object_free(json);
8661 }
8662 else
8663 {
8664 vty_out (vty, "%s", VTY_NEWLINE);
8665 }
8666
8667 return CMD_SUCCESS;
8668 }
8669
8670 static void
8671 bgp_show_all_instances_neighbors_vty (struct vty *vty, u_char use_json)
8672 {
8673 struct listnode *node, *nnode;
8674 struct bgp *bgp;
8675 json_object *json = NULL;
8676 int is_first = 1;
8677
8678 if (use_json)
8679 vty_out (vty, "{%s", VTY_NEWLINE);
8680
8681 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
8682 {
8683 if (use_json)
8684 {
8685 if (!(json = json_object_new_object()))
8686 {
8687 zlog_err("Unable to allocate memory for JSON object");
8688 vty_out (vty,
8689 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
8690 VTY_NEWLINE);
8691 return;
8692 }
8693
8694 json_object_int_add(json, "vrfId",
8695 (bgp->vrf_id == VRF_UNKNOWN)
8696 ? -1 : bgp->vrf_id);
8697 json_object_string_add(json, "vrfName",
8698 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8699 ? "Default" : bgp->name);
8700
8701 if (! is_first)
8702 vty_out (vty, ",%s", VTY_NEWLINE);
8703 else
8704 is_first = 0;
8705
8706 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8707 ? "Default" : bgp->name);
8708 }
8709 else
8710 {
8711 vty_out (vty, "%sInstance %s:%s",
8712 VTY_NEWLINE,
8713 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8714 ? "Default" : bgp->name,
8715 VTY_NEWLINE);
8716 }
8717 bgp_show_neighbor (vty, bgp, show_all, NULL, NULL, use_json, json);
8718 }
8719
8720 if (use_json)
8721 vty_out (vty, "}%s", VTY_NEWLINE);
8722 }
8723
8724 static int
8725 bgp_show_neighbor_vty (struct vty *vty, const char *name,
8726 enum show_type type, const char *ip_str, u_char use_json)
8727 {
8728 int ret;
8729 struct bgp *bgp;
8730 union sockunion su;
8731 json_object *json = NULL;
8732
8733 if (use_json)
8734 json = json_object_new_object();
8735
8736 if (name)
8737 {
8738 if (strmatch(name, "all"))
8739 {
8740 bgp_show_all_instances_neighbors_vty (vty, use_json);
8741 return CMD_SUCCESS;
8742 }
8743 else
8744 {
8745 bgp = bgp_lookup_by_name (name);
8746 if (! bgp)
8747 {
8748 if (use_json)
8749 {
8750 json_object_boolean_true_add(json, "bgpNoSuchInstance");
8751 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8752 json_object_free(json);
8753 }
8754 else
8755 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
8756
8757 return CMD_WARNING;
8758 }
8759 }
8760 }
8761 else
8762 {
8763 bgp = bgp_get_default ();
8764 }
8765
8766 if (bgp)
8767 {
8768 if (ip_str)
8769 {
8770 ret = str2sockunion (ip_str, &su);
8771 if (ret < 0)
8772 bgp_show_neighbor (vty, bgp, type, NULL, ip_str, use_json, json);
8773 else
8774 bgp_show_neighbor (vty, bgp, type, &su, NULL, use_json, json);
8775 }
8776 else
8777 {
8778 bgp_show_neighbor (vty, bgp, type, NULL, NULL, use_json, json);
8779 }
8780 }
8781
8782 return CMD_SUCCESS;
8783 }
8784
8785 /* "show [ip] bgp neighbors" commands. */
8786 DEFUN (show_ip_bgp_neighbors,
8787 show_ip_bgp_neighbors_cmd,
8788 "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]",
8789 SHOW_STR
8790 IP_STR
8791 BGP_STR
8792 BGP_INSTANCE_HELP_STR
8793 "Address Family\n"
8794 "Address Family\n"
8795 "Address Family\n"
8796 "Display information about all VPNv4 NLRIs\n"
8797 "Display information for a route distinguisher\n"
8798 "VPN Route Distinguisher\n"
8799 "Detailed information on TCP and BGP neighbor connections\n"
8800 "Neighbor to display information about\n"
8801 "Neighbor to display information about\n"
8802 "Neighbor on BGP configured interface\n"
8803 JSON_STR)
8804 {
8805 char *vrf = NULL;
8806 char *sh_arg = NULL;
8807 enum show_type sh_type;
8808
8809 u_char uj = use_json(argc, argv);
8810
8811 int idx = 0;
8812
8813 if (argv_find (argv, argc, "view", &idx) ||
8814 argv_find (argv, argc, "vrf", &idx))
8815 vrf = argv[idx+1]->arg;
8816
8817 idx++;
8818 if (argv_find (argv, argc, "A.B.C.D", &idx) ||
8819 argv_find (argv, argc, "X:X::X:X", &idx) ||
8820 argv_find (argv, argc, "WORD", &idx))
8821 {
8822 sh_type = show_peer;
8823 sh_arg = argv[idx]->arg;
8824 }
8825 else
8826 sh_type = show_all;
8827
8828 return bgp_show_neighbor_vty (vty, vrf, sh_type, sh_arg, uj);
8829 }
8830
8831 /* Show BGP's AS paths internal data. There are both `show [ip] bgp
8832 paths' and `show ip mbgp paths'. Those functions results are the
8833 same.*/
8834 DEFUN (show_ip_bgp_paths,
8835 show_ip_bgp_paths_cmd,
8836 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
8837 SHOW_STR
8838 IP_STR
8839 BGP_STR
8840 BGP_SAFI_HELP_STR
8841 "Path information\n")
8842 {
8843 vty_out (vty, "Address Refcnt Path%s", VTY_NEWLINE);
8844 aspath_print_all_vty (vty);
8845 return CMD_SUCCESS;
8846 }
8847
8848 #include "hash.h"
8849
8850 static void
8851 community_show_all_iterator (struct hash_backet *backet, struct vty *vty)
8852 {
8853 struct community *com;
8854
8855 com = (struct community *) backet->data;
8856 vty_out (vty, "[%p] (%ld) %s%s", (void *)backet, com->refcnt,
8857 community_str (com), VTY_NEWLINE);
8858 }
8859
8860 /* Show BGP's community internal data. */
8861 DEFUN (show_ip_bgp_community_info,
8862 show_ip_bgp_community_info_cmd,
8863 "show [ip] bgp community-info",
8864 SHOW_STR
8865 IP_STR
8866 BGP_STR
8867 "List all bgp community information\n")
8868 {
8869 vty_out (vty, "Address Refcnt Community%s", VTY_NEWLINE);
8870
8871 hash_iterate (community_hash (),
8872 (void (*) (struct hash_backet *, void *))
8873 community_show_all_iterator,
8874 vty);
8875
8876 return CMD_SUCCESS;
8877 }
8878
8879 static void
8880 lcommunity_show_all_iterator (struct hash_backet *backet, struct vty *vty)
8881 {
8882 struct lcommunity *lcom;
8883
8884 lcom = (struct lcommunity *) backet->data;
8885 vty_out (vty, "[%p] (%ld) %s%s", (void *)backet, lcom->refcnt,
8886 lcommunity_str (lcom), VTY_NEWLINE);
8887 }
8888
8889 /* Show BGP's community internal data. */
8890 DEFUN (show_ip_bgp_lcommunity_info,
8891 show_ip_bgp_lcommunity_info_cmd,
8892 "show ip bgp large-community-info",
8893 SHOW_STR
8894 IP_STR
8895 BGP_STR
8896 "List all bgp large-community information\n")
8897 {
8898 vty_out (vty, "Address Refcnt Large-community%s", VTY_NEWLINE);
8899
8900 hash_iterate (lcommunity_hash (),
8901 (void (*) (struct hash_backet *, void *))
8902 lcommunity_show_all_iterator,
8903 vty);
8904
8905 return CMD_SUCCESS;
8906 }
8907
8908
8909 DEFUN (show_ip_bgp_attr_info,
8910 show_ip_bgp_attr_info_cmd,
8911 "show [ip] bgp attribute-info",
8912 SHOW_STR
8913 IP_STR
8914 BGP_STR
8915 "List all bgp attribute information\n")
8916 {
8917 attr_show_all (vty);
8918 return CMD_SUCCESS;
8919 }
8920
8921 static void
8922 bgp_show_all_instances_updgrps_vty (struct vty *vty, afi_t afi, safi_t safi)
8923 {
8924 struct listnode *node, *nnode;
8925 struct bgp *bgp;
8926
8927 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
8928 {
8929 vty_out (vty, "%sInstance %s:%s",
8930 VTY_NEWLINE,
8931 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) ? "Default" : bgp->name,
8932 VTY_NEWLINE);
8933 update_group_show(bgp, afi, safi, vty, 0);
8934 }
8935 }
8936
8937 static int
8938 bgp_show_update_groups(struct vty *vty, const char *name,
8939 int afi, int safi,
8940 uint64_t subgrp_id)
8941 {
8942 struct bgp *bgp;
8943
8944 if (name)
8945 {
8946 if (strmatch (name, "all"))
8947 {
8948 bgp_show_all_instances_updgrps_vty (vty, afi, safi);
8949 return CMD_SUCCESS;
8950 }
8951 else
8952 {
8953 bgp = bgp_lookup_by_name (name);
8954 }
8955 }
8956 else
8957 {
8958 bgp = bgp_get_default ();
8959 }
8960
8961 if (bgp)
8962 update_group_show(bgp, afi, safi, vty, subgrp_id);
8963 return CMD_SUCCESS;
8964 }
8965
8966 DEFUN (show_ip_bgp_updgrps,
8967 show_ip_bgp_updgrps_cmd,
8968 "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] update-groups [SUBGROUP-ID]",
8969 SHOW_STR
8970 IP_STR
8971 BGP_STR
8972 BGP_INSTANCE_HELP_STR
8973 BGP_AFI_HELP_STR
8974 BGP_SAFI_HELP_STR
8975 "Detailed info about dynamic update groups\n"
8976 "Specific subgroup to display detailed info for\n")
8977 {
8978 char *vrf = NULL;
8979 afi_t afi = AFI_IP6;
8980 safi_t safi = SAFI_UNICAST;
8981 uint64_t subgrp_id = 0;
8982
8983 int idx = 0;
8984
8985 /* show [ip] bgp */
8986 if (argv_find (argv, argc, "ip", &idx))
8987 afi = AFI_IP;
8988 /* [<view|vrf> WORD] */
8989 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
8990 vrf = argv[++idx]->arg;
8991 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
8992 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
8993 {
8994 argv_find_and_parse_safi (argv, argc, &idx, &safi);
8995 }
8996
8997 /* get subgroup id, if provided */
8998 idx = argc - 1;
8999 if (argv[idx]->type == VARIABLE_TKN)
9000 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx]->arg);
9001
9002 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
9003 }
9004
9005 DEFUN (show_bgp_instance_all_ipv6_updgrps,
9006 show_bgp_instance_all_ipv6_updgrps_cmd,
9007 "show [ip] bgp <view|vrf> all update-groups",
9008 SHOW_STR
9009 IP_STR
9010 BGP_STR
9011 BGP_INSTANCE_ALL_HELP_STR
9012 "Detailed info about dynamic update groups\n")
9013 {
9014 bgp_show_all_instances_updgrps_vty (vty, AFI_IP6, SAFI_UNICAST);
9015 return CMD_SUCCESS;
9016 }
9017
9018 DEFUN (show_bgp_updgrps_stats,
9019 show_bgp_updgrps_stats_cmd,
9020 "show [ip] bgp update-groups statistics",
9021 SHOW_STR
9022 IP_STR
9023 BGP_STR
9024 "Detailed info about dynamic update groups\n"
9025 "Statistics\n")
9026 {
9027 struct bgp *bgp;
9028
9029 bgp = bgp_get_default();
9030 if (bgp)
9031 update_group_show_stats(bgp, vty);
9032
9033 return CMD_SUCCESS;
9034 }
9035
9036 DEFUN (show_bgp_instance_updgrps_stats,
9037 show_bgp_instance_updgrps_stats_cmd,
9038 "show [ip] bgp <view|vrf> WORD update-groups statistics",
9039 SHOW_STR
9040 IP_STR
9041 BGP_STR
9042 BGP_INSTANCE_HELP_STR
9043 "Detailed info about dynamic update groups\n"
9044 "Statistics\n")
9045 {
9046 int idx_word = 3;
9047 struct bgp *bgp;
9048
9049 bgp = bgp_lookup_by_name (argv[idx_word]->arg);
9050 if (bgp)
9051 update_group_show_stats(bgp, vty);
9052
9053 return CMD_SUCCESS;
9054 }
9055
9056 static void
9057 show_bgp_updgrps_adj_info_aux (struct vty *vty, const char *name,
9058 afi_t afi, safi_t safi,
9059 const char *what, uint64_t subgrp_id)
9060 {
9061 struct bgp *bgp;
9062
9063 if (name)
9064 bgp = bgp_lookup_by_name (name);
9065 else
9066 bgp = bgp_get_default ();
9067
9068 if (bgp)
9069 {
9070 if (!strcmp(what, "advertise-queue"))
9071 update_group_show_adj_queue(bgp, afi, safi, vty, subgrp_id);
9072 else if (!strcmp(what, "advertised-routes"))
9073 update_group_show_advertised(bgp, afi, safi, vty, subgrp_id);
9074 else if (!strcmp(what, "packet-queue"))
9075 update_group_show_packet_queue(bgp, afi, safi, vty, subgrp_id);
9076 }
9077 }
9078
9079 DEFUN (show_ip_bgp_updgrps_adj,
9080 show_ip_bgp_updgrps_adj_cmd,
9081 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
9082 SHOW_STR
9083 IP_STR
9084 BGP_STR
9085 "Detailed info about dynamic update groups\n"
9086 "Advertisement queue\n"
9087 "Announced routes\n"
9088 "Packet queue\n")
9089
9090 {
9091 int idx_type = 4;
9092 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, 0);
9093 return CMD_SUCCESS;
9094 }
9095
9096 DEFUN (show_ip_bgp_instance_updgrps_adj,
9097 show_ip_bgp_instance_updgrps_adj_cmd,
9098 "show [ip] bgp <view|vrf> WORD update-groups <advertise-queue|advertised-routes|packet-queue>",
9099 SHOW_STR
9100 IP_STR
9101 BGP_STR
9102 BGP_INSTANCE_HELP_STR
9103 "Detailed info about dynamic update groups\n"
9104 "Advertisement queue\n"
9105 "Announced routes\n"
9106 "Packet queue\n")
9107
9108 {
9109 int idx_word = 4;
9110 int idx_type = 6;
9111 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, 0);
9112 return CMD_SUCCESS;
9113 }
9114
9115 DEFUN (show_bgp_updgrps_afi_adj,
9116 show_bgp_updgrps_afi_adj_cmd,
9117 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
9118 SHOW_STR
9119 IP_STR
9120 BGP_STR
9121 BGP_AFI_SAFI_HELP_STR
9122 "Detailed info about dynamic update groups\n"
9123 "Advertisement queue\n"
9124 "Announced routes\n"
9125 "Packet queue\n"
9126 "Specific subgroup info wanted for\n")
9127 {
9128 int idx_afi = 2;
9129 int idx_safi = 3;
9130 int idx_type = 5;
9131 show_bgp_updgrps_adj_info_aux(vty, NULL,
9132 bgp_vty_afi_from_arg(argv[idx_afi]->arg),
9133 bgp_vty_safi_from_arg(argv[idx_safi]->arg),
9134 argv[idx_type]->arg, 0);
9135 return CMD_SUCCESS;
9136 }
9137
9138 DEFUN (show_bgp_updgrps_adj,
9139 show_bgp_updgrps_adj_cmd,
9140 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
9141 SHOW_STR
9142 IP_STR
9143 BGP_STR
9144 "Detailed info about dynamic update groups\n"
9145 "Advertisement queue\n"
9146 "Announced routes\n"
9147 "Packet queue\n")
9148 {
9149 int idx_type = 3;
9150 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, 0);
9151 return CMD_SUCCESS;
9152 }
9153
9154 DEFUN (show_bgp_instance_updgrps_adj,
9155 show_bgp_instance_updgrps_adj_cmd,
9156 "show [ip] bgp <view|vrf> WORD update-groups <advertise-queue|advertised-routes|packet-queue>",
9157 SHOW_STR
9158 IP_STR
9159 BGP_STR
9160 BGP_INSTANCE_HELP_STR
9161 "Detailed info about dynamic update groups\n"
9162 "Advertisement queue\n"
9163 "Announced routes\n"
9164 "Packet queue\n")
9165 {
9166 int idx_word = 3;
9167 int idx_type = 5;
9168 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, 0);
9169 return CMD_SUCCESS;
9170 }
9171
9172 DEFUN (show_ip_bgp_updgrps_adj_s,
9173 show_ip_bgp_updgrps_adj_s_cmd,
9174 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9175 SHOW_STR
9176 IP_STR
9177 BGP_STR
9178 "Detailed info about dynamic update groups\n"
9179 "Specific subgroup to display info for\n"
9180 "Advertisement queue\n"
9181 "Announced routes\n"
9182 "Packet queue\n")
9183
9184 {
9185 int idx_subgroup_id = 4;
9186 int idx_type = 5;
9187 uint64_t subgrp_id;
9188
9189 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
9190
9191 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
9192 return CMD_SUCCESS;
9193 }
9194
9195 DEFUN (show_ip_bgp_instance_updgrps_adj_s,
9196 show_ip_bgp_instance_updgrps_adj_s_cmd,
9197 "show [ip] bgp <view|vrf> WORD update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9198 SHOW_STR
9199 IP_STR
9200 BGP_STR
9201 BGP_INSTANCE_HELP_STR
9202 "Detailed info about dynamic update groups\n"
9203 "Specific subgroup to display info for\n"
9204 "Advertisement queue\n"
9205 "Announced routes\n"
9206 "Packet queue\n")
9207
9208 {
9209 int idx_vrf = 4;
9210 int idx_subgroup_id = 6;
9211 int idx_type = 7;
9212 uint64_t subgrp_id;
9213
9214 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
9215
9216 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
9217 return CMD_SUCCESS;
9218 }
9219
9220 DEFUN (show_bgp_updgrps_afi_adj_s,
9221 show_bgp_updgrps_afi_adj_s_cmd,
9222 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9223 SHOW_STR
9224 IP_STR
9225 BGP_STR
9226 BGP_AFI_SAFI_HELP_STR
9227 "Detailed info about dynamic update groups\n"
9228 "Specific subgroup to display info for\n"
9229 "Advertisement queue\n"
9230 "Announced routes\n"
9231 "Packet queue\n"
9232 "Specific subgroup info wanted for\n")
9233 {
9234 int idx_afi = 2;
9235 int idx_safi = 3;
9236 int idx_subgroup_id = 5;
9237 int idx_type = 6;
9238 uint64_t subgrp_id;
9239
9240 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
9241
9242 show_bgp_updgrps_adj_info_aux(vty, NULL,
9243 bgp_vty_afi_from_arg(argv[idx_afi]->arg),
9244 bgp_vty_safi_from_arg(argv[idx_safi]->arg),
9245 argv[idx_type]->arg, subgrp_id);
9246 return CMD_SUCCESS;
9247 }
9248
9249 DEFUN (show_bgp_updgrps_adj_s,
9250 show_bgp_updgrps_adj_s_cmd,
9251 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9252 SHOW_STR
9253 IP_STR
9254 BGP_STR
9255 "Detailed info about dynamic update groups\n"
9256 "Specific subgroup to display info for\n"
9257 "Advertisement queue\n"
9258 "Announced routes\n"
9259 "Packet queue\n")
9260 {
9261 int idx_subgroup_id = 3;
9262 int idx_type = 4;
9263 uint64_t subgrp_id;
9264
9265 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
9266
9267 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
9268 return CMD_SUCCESS;
9269 }
9270
9271 DEFUN (show_bgp_instance_updgrps_adj_s,
9272 show_bgp_instance_updgrps_adj_s_cmd,
9273 "show [ip] bgp <view|vrf> WORD update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
9274 SHOW_STR
9275 IP_STR
9276 BGP_STR
9277 BGP_INSTANCE_HELP_STR
9278 "Detailed info about dynamic update groups\n"
9279 "Specific subgroup to display info for\n"
9280 "Advertisement queue\n"
9281 "Announced routes\n"
9282 "Packet queue\n")
9283 {
9284 int idx_vrf = 3;
9285 int idx_subgroup_id = 5;
9286 int idx_type = 6;
9287 uint64_t subgrp_id;
9288
9289 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
9290
9291 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
9292 return CMD_SUCCESS;
9293 }
9294
9295
9296
9297 static int
9298 bgp_show_one_peer_group (struct vty *vty, struct peer_group *group)
9299 {
9300 struct listnode *node, *nnode;
9301 struct prefix *range;
9302 struct peer *conf;
9303 struct peer *peer;
9304 char buf[PREFIX2STR_BUFFER];
9305 afi_t afi;
9306 safi_t safi;
9307 const char *peer_status;
9308 const char *af_str;
9309 int lr_count;
9310 int dynamic;
9311 int af_cfgd;
9312
9313 conf = group->conf;
9314
9315 if (conf->as_type == AS_SPECIFIED ||
9316 conf->as_type == AS_EXTERNAL) {
9317 vty_out (vty, "%sBGP peer-group %s, remote AS %d%s",
9318 VTY_NEWLINE, group->name, conf->as, VTY_NEWLINE);
9319 } else if (conf->as_type == AS_INTERNAL) {
9320 vty_out (vty, "%sBGP peer-group %s, remote AS %d%s",
9321 VTY_NEWLINE, group->name, group->bgp->as, VTY_NEWLINE);
9322 } else {
9323 vty_out (vty, "%sBGP peer-group %s%s",
9324 VTY_NEWLINE, group->name, VTY_NEWLINE);
9325 }
9326
9327 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
9328 vty_out (vty, " Peer-group type is internal%s", VTY_NEWLINE);
9329 else
9330 vty_out (vty, " Peer-group type is external%s", VTY_NEWLINE);
9331
9332 /* Display AFs configured. */
9333 vty_out (vty, " Configured address-families:");
9334 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9335 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
9336 {
9337 if (conf->afc[afi][safi])
9338 {
9339 af_cfgd = 1;
9340 vty_out (vty, " %s;", afi_safi_print(afi, safi));
9341 }
9342 }
9343 if (!af_cfgd)
9344 vty_out (vty, " none%s", VTY_NEWLINE);
9345 else
9346 vty_out (vty, "%s", VTY_NEWLINE);
9347
9348 /* Display listen ranges (for dynamic neighbors), if any */
9349 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9350 {
9351 if (afi == AFI_IP)
9352 af_str = "IPv4";
9353 else if (afi == AFI_IP6)
9354 af_str = "IPv6";
9355 else
9356 af_str = "???";
9357 lr_count = listcount(group->listen_range[afi]);
9358 if (lr_count)
9359 {
9360 vty_out(vty,
9361 " %d %s listen range(s)%s",
9362 lr_count, af_str, VTY_NEWLINE);
9363
9364
9365 for (ALL_LIST_ELEMENTS (group->listen_range[afi], node,
9366 nnode, range))
9367 {
9368 prefix2str(range, buf, sizeof(buf));
9369 vty_out(vty, " %s%s", buf, VTY_NEWLINE);
9370 }
9371 }
9372 }
9373
9374 /* Display group members and their status */
9375 if (listcount(group->peer))
9376 {
9377 vty_out (vty, " Peer-group members:%s", VTY_NEWLINE);
9378 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
9379 {
9380 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
9381 peer_status = "Idle (Admin)";
9382 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
9383 peer_status = "Idle (PfxCt)";
9384 else
9385 peer_status = LOOKUP(bgp_status_msg, peer->status);
9386
9387 dynamic = peer_dynamic_neighbor(peer);
9388 vty_out (vty, " %s %s %s %s",
9389 peer->host, dynamic ? "(dynamic)" : "",
9390 peer_status, VTY_NEWLINE);
9391 }
9392 }
9393
9394 return CMD_SUCCESS;
9395 }
9396
9397 /* Show BGP peer group's information. */
9398 enum show_group_type
9399 {
9400 show_all_groups,
9401 show_peer_group
9402 };
9403
9404 static int
9405 bgp_show_peer_group (struct vty *vty, struct bgp *bgp,
9406 enum show_group_type type, const char *group_name)
9407 {
9408 struct listnode *node, *nnode;
9409 struct peer_group *group;
9410 int find = 0;
9411
9412 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
9413 {
9414 switch (type)
9415 {
9416 case show_all_groups:
9417 bgp_show_one_peer_group (vty, group);
9418 break;
9419 case show_peer_group:
9420 if (group_name && (strcmp(group->name, group_name) == 0))
9421 {
9422 find = 1;
9423 bgp_show_one_peer_group (vty, group);
9424 }
9425 break;
9426 }
9427 }
9428
9429 if (type == show_peer_group && ! find)
9430 vty_out (vty, "%% No such peer-group%s", VTY_NEWLINE);
9431
9432 return CMD_SUCCESS;
9433 }
9434
9435 static int
9436 bgp_show_peer_group_vty (struct vty *vty, const char *name,
9437 enum show_group_type type, const char *group_name)
9438 {
9439 struct bgp *bgp;
9440 int ret = CMD_SUCCESS;
9441
9442 if (name)
9443 bgp = bgp_lookup_by_name (name);
9444 else
9445 bgp = bgp_get_default ();
9446
9447 if (! bgp)
9448 {
9449 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9450 return CMD_WARNING;
9451 }
9452
9453 ret = bgp_show_peer_group (vty, bgp, type, group_name);
9454
9455 return ret;
9456 }
9457
9458 DEFUN (show_ip_bgp_peer_groups,
9459 show_ip_bgp_peer_groups_cmd,
9460 "show [ip] bgp [<view|vrf> WORD] peer-group [PGNAME]",
9461 SHOW_STR
9462 IP_STR
9463 BGP_STR
9464 BGP_INSTANCE_HELP_STR
9465 "Detailed information on BGP peer groups\n"
9466 "Peer group name\n")
9467 {
9468 char *vrf, *pg;
9469 vrf = pg = NULL;
9470 int idx = 0;
9471
9472 vrf = argv_find (argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
9473 pg = argv_find (argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
9474
9475 return bgp_show_peer_group_vty (vty, vrf, show_all_groups, pg);
9476 }
9477
9478
9479 /* Redistribute VTY commands. */
9480
9481 DEFUN (bgp_redistribute_ipv4,
9482 bgp_redistribute_ipv4_cmd,
9483 "redistribute " FRR_IP_REDIST_STR_BGPD,
9484 "Redistribute information from another routing protocol\n"
9485 FRR_IP_REDIST_HELP_STR_BGPD)
9486 {
9487 VTY_DECLVAR_CONTEXT(bgp, bgp);
9488 int idx_protocol = 1;
9489 int type;
9490
9491 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
9492 if (type < 0)
9493 {
9494 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9495 return CMD_WARNING;
9496 }
9497 bgp_redist_add(bgp, AFI_IP, type, 0);
9498 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
9499 }
9500
9501 DEFUN (bgp_redistribute_ipv4_rmap,
9502 bgp_redistribute_ipv4_rmap_cmd,
9503 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
9504 "Redistribute information from another routing protocol\n"
9505 FRR_IP_REDIST_HELP_STR_BGPD
9506 "Route map reference\n"
9507 "Pointer to route-map entries\n")
9508 {
9509 VTY_DECLVAR_CONTEXT(bgp, bgp);
9510 int idx_protocol = 1;
9511 int idx_word = 3;
9512 int type;
9513 struct bgp_redist *red;
9514
9515 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
9516 if (type < 0)
9517 {
9518 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9519 return CMD_WARNING;
9520 }
9521
9522 red = bgp_redist_add(bgp, AFI_IP, type, 0);
9523 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9524 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
9525 }
9526
9527 DEFUN (bgp_redistribute_ipv4_metric,
9528 bgp_redistribute_ipv4_metric_cmd,
9529 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
9530 "Redistribute information from another routing protocol\n"
9531 FRR_IP_REDIST_HELP_STR_BGPD
9532 "Metric for redistributed routes\n"
9533 "Default metric\n")
9534 {
9535 VTY_DECLVAR_CONTEXT(bgp, bgp);
9536 int idx_protocol = 1;
9537 int idx_number = 3;
9538 int type;
9539 u_int32_t metric;
9540 struct bgp_redist *red;
9541
9542 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
9543 if (type < 0)
9544 {
9545 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9546 return CMD_WARNING;
9547 }
9548 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
9549
9550 red = bgp_redist_add(bgp, AFI_IP, type, 0);
9551 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
9552 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
9553 }
9554
9555 DEFUN (bgp_redistribute_ipv4_rmap_metric,
9556 bgp_redistribute_ipv4_rmap_metric_cmd,
9557 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
9558 "Redistribute information from another routing protocol\n"
9559 FRR_IP_REDIST_HELP_STR_BGPD
9560 "Route map reference\n"
9561 "Pointer to route-map entries\n"
9562 "Metric for redistributed routes\n"
9563 "Default metric\n")
9564 {
9565 VTY_DECLVAR_CONTEXT(bgp, bgp);
9566 int idx_protocol = 1;
9567 int idx_word = 3;
9568 int idx_number = 5;
9569 int type;
9570 u_int32_t metric;
9571 struct bgp_redist *red;
9572
9573 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
9574 if (type < 0)
9575 {
9576 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9577 return CMD_WARNING;
9578 }
9579 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
9580
9581 red = bgp_redist_add(bgp, AFI_IP, type, 0);
9582 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9583 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
9584 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
9585 }
9586
9587 DEFUN (bgp_redistribute_ipv4_metric_rmap,
9588 bgp_redistribute_ipv4_metric_rmap_cmd,
9589 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
9590 "Redistribute information from another routing protocol\n"
9591 FRR_IP_REDIST_HELP_STR_BGPD
9592 "Metric for redistributed routes\n"
9593 "Default metric\n"
9594 "Route map reference\n"
9595 "Pointer to route-map entries\n")
9596 {
9597 VTY_DECLVAR_CONTEXT(bgp, bgp);
9598 int idx_protocol = 1;
9599 int idx_number = 3;
9600 int idx_word = 5;
9601 int type;
9602 u_int32_t metric;
9603 struct bgp_redist *red;
9604
9605 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
9606 if (type < 0)
9607 {
9608 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9609 return CMD_WARNING;
9610 }
9611 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
9612
9613 red = bgp_redist_add(bgp, AFI_IP, type, 0);
9614 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
9615 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9616 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
9617 }
9618
9619 DEFUN (bgp_redistribute_ipv4_ospf,
9620 bgp_redistribute_ipv4_ospf_cmd,
9621 "redistribute <ospf|table> (1-65535)",
9622 "Redistribute information from another routing protocol\n"
9623 "Open Shortest Path First (OSPFv2)\n"
9624 "Non-main Kernel Routing Table\n"
9625 "Instance ID/Table ID\n")
9626 {
9627 VTY_DECLVAR_CONTEXT(bgp, bgp);
9628 int idx_ospf_table = 1;
9629 int idx_number = 2;
9630 u_short instance;
9631 u_short protocol;
9632
9633 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9634
9635 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9636 protocol = ZEBRA_ROUTE_OSPF;
9637 else
9638 protocol = ZEBRA_ROUTE_TABLE;
9639
9640 bgp_redist_add(bgp, AFI_IP, protocol, instance);
9641 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
9642 }
9643
9644 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
9645 bgp_redistribute_ipv4_ospf_rmap_cmd,
9646 "redistribute <ospf|table> (1-65535) route-map WORD",
9647 "Redistribute information from another routing protocol\n"
9648 "Open Shortest Path First (OSPFv2)\n"
9649 "Non-main Kernel Routing Table\n"
9650 "Instance ID/Table ID\n"
9651 "Route map reference\n"
9652 "Pointer to route-map entries\n")
9653 {
9654 VTY_DECLVAR_CONTEXT(bgp, bgp);
9655 int idx_ospf_table = 1;
9656 int idx_number = 2;
9657 int idx_word = 4;
9658 struct bgp_redist *red;
9659 u_short instance;
9660 int protocol;
9661
9662 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9663 protocol = ZEBRA_ROUTE_OSPF;
9664 else
9665 protocol = ZEBRA_ROUTE_TABLE;
9666
9667 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9668 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
9669 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9670 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
9671 }
9672
9673 DEFUN (bgp_redistribute_ipv4_ospf_metric,
9674 bgp_redistribute_ipv4_ospf_metric_cmd,
9675 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
9676 "Redistribute information from another routing protocol\n"
9677 "Open Shortest Path First (OSPFv2)\n"
9678 "Non-main Kernel Routing Table\n"
9679 "Instance ID/Table ID\n"
9680 "Metric for redistributed routes\n"
9681 "Default metric\n")
9682 {
9683 VTY_DECLVAR_CONTEXT(bgp, bgp);
9684 int idx_ospf_table = 1;
9685 int idx_number = 2;
9686 int idx_number_2 = 4;
9687 u_int32_t metric;
9688 struct bgp_redist *red;
9689 u_short instance;
9690 int protocol;
9691
9692 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9693 protocol = ZEBRA_ROUTE_OSPF;
9694 else
9695 protocol = ZEBRA_ROUTE_TABLE;
9696
9697 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9698 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
9699
9700 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
9701 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
9702 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
9703 }
9704
9705 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
9706 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
9707 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
9708 "Redistribute information from another routing protocol\n"
9709 "Open Shortest Path First (OSPFv2)\n"
9710 "Non-main Kernel Routing Table\n"
9711 "Instance ID/Table ID\n"
9712 "Route map reference\n"
9713 "Pointer to route-map entries\n"
9714 "Metric for redistributed routes\n"
9715 "Default metric\n")
9716 {
9717 VTY_DECLVAR_CONTEXT(bgp, bgp);
9718 int idx_ospf_table = 1;
9719 int idx_number = 2;
9720 int idx_word = 4;
9721 int idx_number_2 = 6;
9722 u_int32_t metric;
9723 struct bgp_redist *red;
9724 u_short instance;
9725 int protocol;
9726
9727 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9728 protocol = ZEBRA_ROUTE_OSPF;
9729 else
9730 protocol = ZEBRA_ROUTE_TABLE;
9731
9732 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9733 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
9734
9735 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
9736 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9737 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
9738 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
9739 }
9740
9741 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
9742 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
9743 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
9744 "Redistribute information from another routing protocol\n"
9745 "Open Shortest Path First (OSPFv2)\n"
9746 "Non-main Kernel Routing Table\n"
9747 "Instance ID/Table ID\n"
9748 "Metric for redistributed routes\n"
9749 "Default metric\n"
9750 "Route map reference\n"
9751 "Pointer to route-map entries\n")
9752 {
9753 VTY_DECLVAR_CONTEXT(bgp, bgp);
9754 int idx_ospf_table = 1;
9755 int idx_number = 2;
9756 int idx_number_2 = 4;
9757 int idx_word = 6;
9758 u_int32_t metric;
9759 struct bgp_redist *red;
9760 u_short instance;
9761 int protocol;
9762
9763 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9764 protocol = ZEBRA_ROUTE_OSPF;
9765 else
9766 protocol = ZEBRA_ROUTE_TABLE;
9767
9768 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9769 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
9770
9771 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
9772 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
9773 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9774 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
9775 }
9776
9777 DEFUN (no_bgp_redistribute_ipv4_ospf,
9778 no_bgp_redistribute_ipv4_ospf_cmd,
9779 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
9780 NO_STR
9781 "Redistribute information from another routing protocol\n"
9782 "Open Shortest Path First (OSPFv2)\n"
9783 "Non-main Kernel Routing Table\n"
9784 "Instance ID/Table ID\n"
9785 "Metric for redistributed routes\n"
9786 "Default metric\n"
9787 "Route map reference\n"
9788 "Pointer to route-map entries\n")
9789 {
9790 VTY_DECLVAR_CONTEXT(bgp, bgp);
9791 int idx_ospf_table = 2;
9792 int idx_number = 3;
9793 u_short instance;
9794 int protocol;
9795
9796 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9797 protocol = ZEBRA_ROUTE_OSPF;
9798 else
9799 protocol = ZEBRA_ROUTE_TABLE;
9800
9801 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9802 return bgp_redistribute_unset (bgp, AFI_IP, protocol, instance);
9803 }
9804
9805 DEFUN (no_bgp_redistribute_ipv4,
9806 no_bgp_redistribute_ipv4_cmd,
9807 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
9808 NO_STR
9809 "Redistribute information from another routing protocol\n"
9810 FRR_IP_REDIST_HELP_STR_BGPD
9811 "Metric for redistributed routes\n"
9812 "Default metric\n"
9813 "Route map reference\n"
9814 "Pointer to route-map entries\n")
9815 {
9816 VTY_DECLVAR_CONTEXT(bgp, bgp);
9817 int idx_protocol = 2;
9818 int type;
9819
9820 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
9821 if (type < 0)
9822 {
9823 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9824 return CMD_WARNING;
9825 }
9826 return bgp_redistribute_unset (bgp, AFI_IP, type, 0);
9827 }
9828
9829 DEFUN (bgp_redistribute_ipv6,
9830 bgp_redistribute_ipv6_cmd,
9831 "redistribute " FRR_IP6_REDIST_STR_BGPD,
9832 "Redistribute information from another routing protocol\n"
9833 FRR_IP6_REDIST_HELP_STR_BGPD)
9834 {
9835 VTY_DECLVAR_CONTEXT(bgp, bgp);
9836 int idx_protocol = 1;
9837 int type;
9838
9839 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
9840 if (type < 0)
9841 {
9842 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9843 return CMD_WARNING;
9844 }
9845
9846 bgp_redist_add(bgp, AFI_IP6, type, 0);
9847 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
9848 }
9849
9850 DEFUN (bgp_redistribute_ipv6_rmap,
9851 bgp_redistribute_ipv6_rmap_cmd,
9852 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
9853 "Redistribute information from another routing protocol\n"
9854 FRR_IP6_REDIST_HELP_STR_BGPD
9855 "Route map reference\n"
9856 "Pointer to route-map entries\n")
9857 {
9858 VTY_DECLVAR_CONTEXT(bgp, bgp);
9859 int idx_protocol = 1;
9860 int idx_word = 3;
9861 int type;
9862 struct bgp_redist *red;
9863
9864 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
9865 if (type < 0)
9866 {
9867 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9868 return CMD_WARNING;
9869 }
9870
9871 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
9872 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9873 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
9874 }
9875
9876 DEFUN (bgp_redistribute_ipv6_metric,
9877 bgp_redistribute_ipv6_metric_cmd,
9878 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
9879 "Redistribute information from another routing protocol\n"
9880 FRR_IP6_REDIST_HELP_STR_BGPD
9881 "Metric for redistributed routes\n"
9882 "Default metric\n")
9883 {
9884 VTY_DECLVAR_CONTEXT(bgp, bgp);
9885 int idx_protocol = 1;
9886 int idx_number = 3;
9887 int type;
9888 u_int32_t metric;
9889 struct bgp_redist *red;
9890
9891 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
9892 if (type < 0)
9893 {
9894 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9895 return CMD_WARNING;
9896 }
9897 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
9898
9899 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
9900 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
9901 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
9902 }
9903
9904 DEFUN (bgp_redistribute_ipv6_rmap_metric,
9905 bgp_redistribute_ipv6_rmap_metric_cmd,
9906 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
9907 "Redistribute information from another routing protocol\n"
9908 FRR_IP6_REDIST_HELP_STR_BGPD
9909 "Route map reference\n"
9910 "Pointer to route-map entries\n"
9911 "Metric for redistributed routes\n"
9912 "Default metric\n")
9913 {
9914 VTY_DECLVAR_CONTEXT(bgp, bgp);
9915 int idx_protocol = 1;
9916 int idx_word = 3;
9917 int idx_number = 5;
9918 int type;
9919 u_int32_t metric;
9920 struct bgp_redist *red;
9921
9922 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
9923 if (type < 0)
9924 {
9925 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9926 return CMD_WARNING;
9927 }
9928 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
9929
9930 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
9931 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9932 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
9933 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
9934 }
9935
9936 DEFUN (bgp_redistribute_ipv6_metric_rmap,
9937 bgp_redistribute_ipv6_metric_rmap_cmd,
9938 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
9939 "Redistribute information from another routing protocol\n"
9940 FRR_IP6_REDIST_HELP_STR_BGPD
9941 "Metric for redistributed routes\n"
9942 "Default metric\n"
9943 "Route map reference\n"
9944 "Pointer to route-map entries\n")
9945 {
9946 VTY_DECLVAR_CONTEXT(bgp, bgp);
9947 int idx_protocol = 1;
9948 int idx_number = 3;
9949 int idx_word = 5;
9950 int type;
9951 u_int32_t metric;
9952 struct bgp_redist *red;
9953
9954 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
9955 if (type < 0)
9956 {
9957 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9958 return CMD_WARNING;
9959 }
9960 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
9961
9962 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
9963 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
9964 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
9965 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
9966 }
9967
9968 DEFUN (no_bgp_redistribute_ipv6,
9969 no_bgp_redistribute_ipv6_cmd,
9970 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
9971 NO_STR
9972 "Redistribute information from another routing protocol\n"
9973 FRR_IP6_REDIST_HELP_STR_BGPD
9974 "Metric for redistributed routes\n"
9975 "Default metric\n"
9976 "Route map reference\n"
9977 "Pointer to route-map entries\n")
9978 {
9979 VTY_DECLVAR_CONTEXT(bgp, bgp);
9980 int idx_protocol = 2;
9981 int type;
9982
9983 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
9984 if (type < 0)
9985 {
9986 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9987 return CMD_WARNING;
9988 }
9989
9990 return bgp_redistribute_unset (bgp, AFI_IP6, type, 0);
9991 }
9992
9993 int
9994 bgp_config_write_redistribute (struct vty *vty, struct bgp *bgp, afi_t afi,
9995 safi_t safi, int *write)
9996 {
9997 int i;
9998
9999 /* Unicast redistribution only. */
10000 if (safi != SAFI_UNICAST)
10001 return 0;
10002
10003 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
10004 {
10005 /* Redistribute BGP does not make sense. */
10006 if (i != ZEBRA_ROUTE_BGP)
10007 {
10008 struct list *red_list;
10009 struct listnode *node;
10010 struct bgp_redist *red;
10011
10012 red_list = bgp->redist[afi][i];
10013 if (!red_list)
10014 continue;
10015
10016 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
10017 {
10018 /* Display "address-family" when it is not yet diplayed. */
10019 bgp_config_write_family_header (vty, afi, safi, write);
10020
10021 /* "redistribute" configuration. */
10022 vty_out (vty, " redistribute %s", zebra_route_string(i));
10023 if (red->instance)
10024 vty_out (vty, " %d", red->instance);
10025 if (red->redist_metric_flag)
10026 vty_out (vty, " metric %u", red->redist_metric);
10027 if (red->rmap.name)
10028 vty_out (vty, " route-map %s", red->rmap.name);
10029 vty_out (vty, "%s", VTY_NEWLINE);
10030 }
10031 }
10032 }
10033 return *write;
10034 }
10035
10036 /* BGP node structure. */
10037 static struct cmd_node bgp_node =
10038 {
10039 BGP_NODE,
10040 "%s(config-router)# ",
10041 1,
10042 };
10043
10044 static struct cmd_node bgp_ipv4_unicast_node =
10045 {
10046 BGP_IPV4_NODE,
10047 "%s(config-router-af)# ",
10048 1,
10049 };
10050
10051 static struct cmd_node bgp_ipv4_multicast_node =
10052 {
10053 BGP_IPV4M_NODE,
10054 "%s(config-router-af)# ",
10055 1,
10056 };
10057
10058 static struct cmd_node bgp_ipv6_unicast_node =
10059 {
10060 BGP_IPV6_NODE,
10061 "%s(config-router-af)# ",
10062 1,
10063 };
10064
10065 static struct cmd_node bgp_ipv6_multicast_node =
10066 {
10067 BGP_IPV6M_NODE,
10068 "%s(config-router-af)# ",
10069 1,
10070 };
10071
10072 static struct cmd_node bgp_vpnv4_node =
10073 {
10074 BGP_VPNV4_NODE,
10075 "%s(config-router-af)# ",
10076 1
10077 };
10078
10079 static struct cmd_node bgp_vpnv6_node =
10080 {
10081 BGP_VPNV6_NODE,
10082 "%s(config-router-af-vpnv6)# ",
10083 1
10084 };
10085
10086 static struct cmd_node bgp_encap_node =
10087 {
10088 BGP_ENCAP_NODE,
10089 "%s(config-router-af-encap)# ",
10090 1
10091 };
10092
10093 static struct cmd_node bgp_encapv6_node =
10094 {
10095 BGP_ENCAPV6_NODE,
10096 "%s(config-router-af-encapv6)# ",
10097 1
10098 };
10099
10100 static struct cmd_node bgp_evpn_node =
10101 {
10102 BGP_EVPN_NODE,
10103 "%s(config-router-evpn)# ",
10104 1
10105 };
10106
10107 static void community_list_vty (void);
10108
10109 void
10110 bgp_vty_init (void)
10111 {
10112 /* Install bgp top node. */
10113 install_node (&bgp_node, bgp_config_write);
10114 install_node (&bgp_ipv4_unicast_node, NULL);
10115 install_node (&bgp_ipv4_multicast_node, NULL);
10116 install_node (&bgp_ipv6_unicast_node, NULL);
10117 install_node (&bgp_ipv6_multicast_node, NULL);
10118 install_node (&bgp_vpnv4_node, NULL);
10119 install_node (&bgp_vpnv6_node, NULL);
10120 install_node (&bgp_encap_node, NULL);
10121 install_node (&bgp_encapv6_node, NULL);
10122 install_node (&bgp_evpn_node, NULL);
10123
10124 /* Install default VTY commands to new nodes. */
10125 install_default (BGP_NODE);
10126 install_default (BGP_IPV4_NODE);
10127 install_default (BGP_IPV4M_NODE);
10128 install_default (BGP_IPV6_NODE);
10129 install_default (BGP_IPV6M_NODE);
10130 install_default (BGP_VPNV4_NODE);
10131 install_default (BGP_VPNV6_NODE);
10132 install_default (BGP_ENCAP_NODE);
10133 install_default (BGP_ENCAPV6_NODE);
10134 install_default (BGP_EVPN_NODE);
10135
10136 /* "bgp multiple-instance" commands. */
10137 install_element (CONFIG_NODE, &bgp_multiple_instance_cmd);
10138 install_element (CONFIG_NODE, &no_bgp_multiple_instance_cmd);
10139
10140 /* "bgp config-type" commands. */
10141 install_element (CONFIG_NODE, &bgp_config_type_cmd);
10142 install_element (CONFIG_NODE, &no_bgp_config_type_cmd);
10143
10144 /* bgp route-map delay-timer commands. */
10145 install_element (CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
10146 install_element (CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
10147
10148 /* Dummy commands (Currently not supported) */
10149 install_element (BGP_NODE, &no_synchronization_cmd);
10150 install_element (BGP_NODE, &no_auto_summary_cmd);
10151
10152 /* "router bgp" commands. */
10153 install_element (CONFIG_NODE, &router_bgp_cmd);
10154
10155 /* "no router bgp" commands. */
10156 install_element (CONFIG_NODE, &no_router_bgp_cmd);
10157
10158 /* "bgp router-id" commands. */
10159 install_element (BGP_NODE, &bgp_router_id_cmd);
10160 install_element (BGP_NODE, &no_bgp_router_id_cmd);
10161
10162 /* "bgp cluster-id" commands. */
10163 install_element (BGP_NODE, &bgp_cluster_id_cmd);
10164 install_element (BGP_NODE, &no_bgp_cluster_id_cmd);
10165
10166 /* "bgp confederation" commands. */
10167 install_element (BGP_NODE, &bgp_confederation_identifier_cmd);
10168 install_element (BGP_NODE, &no_bgp_confederation_identifier_cmd);
10169
10170 /* "bgp confederation peers" commands. */
10171 install_element (BGP_NODE, &bgp_confederation_peers_cmd);
10172 install_element (BGP_NODE, &no_bgp_confederation_peers_cmd);
10173
10174 /* bgp max-med command */
10175 install_element (BGP_NODE, &bgp_maxmed_admin_cmd);
10176 install_element (BGP_NODE, &no_bgp_maxmed_admin_cmd);
10177 install_element (BGP_NODE, &bgp_maxmed_admin_medv_cmd);
10178 install_element (BGP_NODE, &bgp_maxmed_onstartup_cmd);
10179 install_element (BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
10180 install_element (BGP_NODE, &bgp_maxmed_onstartup_medv_cmd);
10181
10182 /* bgp disable-ebgp-connected-nh-check */
10183 install_element (BGP_NODE, &bgp_disable_connected_route_check_cmd);
10184 install_element (BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
10185
10186 /* bgp update-delay command */
10187 install_element (BGP_NODE, &bgp_update_delay_cmd);
10188 install_element (BGP_NODE, &no_bgp_update_delay_cmd);
10189 install_element (BGP_NODE, &bgp_update_delay_establish_wait_cmd);
10190
10191 install_element (BGP_NODE, &bgp_wpkt_quanta_cmd);
10192 install_element (BGP_NODE, &no_bgp_wpkt_quanta_cmd);
10193
10194 install_element (BGP_NODE, &bgp_coalesce_time_cmd);
10195 install_element (BGP_NODE, &no_bgp_coalesce_time_cmd);
10196
10197 /* "maximum-paths" commands. */
10198 install_element (BGP_NODE, &bgp_maxpaths_cmd);
10199 install_element (BGP_NODE, &no_bgp_maxpaths_cmd);
10200 install_element (BGP_IPV4_NODE, &bgp_maxpaths_cmd);
10201 install_element (BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
10202 install_element (BGP_IPV6_NODE, &bgp_maxpaths_cmd);
10203 install_element (BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
10204 install_element (BGP_NODE, &bgp_maxpaths_ibgp_cmd);
10205 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
10206 install_element (BGP_NODE, &no_bgp_maxpaths_ibgp_cmd);
10207 install_element (BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
10208 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
10209 install_element (BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
10210 install_element (BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
10211 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
10212 install_element (BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
10213
10214 /* "timers bgp" commands. */
10215 install_element (BGP_NODE, &bgp_timers_cmd);
10216 install_element (BGP_NODE, &no_bgp_timers_cmd);
10217
10218 /* route-map delay-timer commands - per instance for backwards compat. */
10219 install_element (BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
10220 install_element (BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
10221
10222 /* "bgp client-to-client reflection" commands */
10223 install_element (BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
10224 install_element (BGP_NODE, &bgp_client_to_client_reflection_cmd);
10225
10226 /* "bgp always-compare-med" commands */
10227 install_element (BGP_NODE, &bgp_always_compare_med_cmd);
10228 install_element (BGP_NODE, &no_bgp_always_compare_med_cmd);
10229
10230 /* "bgp deterministic-med" commands */
10231 install_element (BGP_NODE, &bgp_deterministic_med_cmd);
10232 install_element (BGP_NODE, &no_bgp_deterministic_med_cmd);
10233
10234 /* "bgp graceful-restart" commands */
10235 install_element (BGP_NODE, &bgp_graceful_restart_cmd);
10236 install_element (BGP_NODE, &no_bgp_graceful_restart_cmd);
10237 install_element (BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
10238 install_element (BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
10239 install_element (BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
10240 install_element (BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
10241
10242 install_element (BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
10243 install_element (BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
10244
10245 /* "bgp fast-external-failover" commands */
10246 install_element (BGP_NODE, &bgp_fast_external_failover_cmd);
10247 install_element (BGP_NODE, &no_bgp_fast_external_failover_cmd);
10248
10249 /* "bgp enforce-first-as" commands */
10250 install_element (BGP_NODE, &bgp_enforce_first_as_cmd);
10251 install_element (BGP_NODE, &no_bgp_enforce_first_as_cmd);
10252
10253 /* "bgp bestpath compare-routerid" commands */
10254 install_element (BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
10255 install_element (BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
10256
10257 /* "bgp bestpath as-path ignore" commands */
10258 install_element (BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
10259 install_element (BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
10260
10261 /* "bgp bestpath as-path confed" commands */
10262 install_element (BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
10263 install_element (BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
10264
10265 /* "bgp bestpath as-path multipath-relax" commands */
10266 install_element (BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
10267 install_element (BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
10268
10269 /* "bgp log-neighbor-changes" commands */
10270 install_element (BGP_NODE, &bgp_log_neighbor_changes_cmd);
10271 install_element (BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
10272
10273 /* "bgp bestpath med" commands */
10274 install_element (BGP_NODE, &bgp_bestpath_med_cmd);
10275 install_element (BGP_NODE, &no_bgp_bestpath_med_cmd);
10276
10277 /* "no bgp default ipv4-unicast" commands. */
10278 install_element (BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
10279 install_element (BGP_NODE, &bgp_default_ipv4_unicast_cmd);
10280
10281 /* "bgp network import-check" commands. */
10282 install_element (BGP_NODE, &bgp_network_import_check_cmd);
10283 install_element (BGP_NODE, &bgp_network_import_check_exact_cmd);
10284 install_element (BGP_NODE, &no_bgp_network_import_check_cmd);
10285
10286 /* "bgp default local-preference" commands. */
10287 install_element (BGP_NODE, &bgp_default_local_preference_cmd);
10288 install_element (BGP_NODE, &no_bgp_default_local_preference_cmd);
10289
10290 /* bgp default show-hostname */
10291 install_element (BGP_NODE, &bgp_default_show_hostname_cmd);
10292 install_element (BGP_NODE, &no_bgp_default_show_hostname_cmd);
10293
10294 /* "bgp default subgroup-pkt-queue-max" commands. */
10295 install_element (BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
10296 install_element (BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
10297
10298 /* bgp ibgp-allow-policy-mods command */
10299 install_element (BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
10300 install_element (BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
10301
10302 /* "bgp listen limit" commands. */
10303 install_element (BGP_NODE, &bgp_listen_limit_cmd);
10304 install_element (BGP_NODE, &no_bgp_listen_limit_cmd);
10305
10306 /* "bgp listen range" commands. */
10307 install_element (BGP_NODE, &bgp_listen_range_cmd);
10308 install_element (BGP_NODE, &no_bgp_listen_range_cmd);
10309
10310 /* "neighbor remote-as" commands. */
10311 install_element (BGP_NODE, &neighbor_remote_as_cmd);
10312 install_element (BGP_NODE, &neighbor_interface_config_cmd);
10313 install_element (BGP_NODE, &neighbor_interface_config_v6only_cmd);
10314 install_element (BGP_NODE, &neighbor_interface_config_remote_as_cmd);
10315 install_element (BGP_NODE, &neighbor_interface_v6only_config_remote_as_cmd);
10316 install_element (BGP_NODE, &no_neighbor_cmd);
10317 install_element (BGP_NODE, &no_neighbor_interface_config_cmd);
10318
10319 /* "neighbor peer-group" commands. */
10320 install_element (BGP_NODE, &neighbor_peer_group_cmd);
10321 install_element (BGP_NODE, &no_neighbor_peer_group_cmd);
10322 install_element (BGP_NODE, &no_neighbor_interface_peer_group_remote_as_cmd);
10323
10324 /* "neighbor local-as" commands. */
10325 install_element (BGP_NODE, &neighbor_local_as_cmd);
10326 install_element (BGP_NODE, &neighbor_local_as_no_prepend_cmd);
10327 install_element (BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
10328 install_element (BGP_NODE, &no_neighbor_local_as_cmd);
10329
10330 /* "neighbor solo" commands. */
10331 install_element (BGP_NODE, &neighbor_solo_cmd);
10332 install_element (BGP_NODE, &no_neighbor_solo_cmd);
10333
10334 /* "neighbor password" commands. */
10335 install_element (BGP_NODE, &neighbor_password_cmd);
10336 install_element (BGP_NODE, &no_neighbor_password_cmd);
10337
10338 /* "neighbor activate" commands. */
10339 install_element (BGP_NODE, &neighbor_activate_cmd);
10340 install_element (BGP_IPV4_NODE, &neighbor_activate_cmd);
10341 install_element (BGP_IPV4M_NODE, &neighbor_activate_cmd);
10342 install_element (BGP_IPV6_NODE, &neighbor_activate_cmd);
10343 install_element (BGP_IPV6M_NODE, &neighbor_activate_cmd);
10344 install_element (BGP_VPNV4_NODE, &neighbor_activate_cmd);
10345 install_element (BGP_VPNV6_NODE, &neighbor_activate_cmd);
10346 install_element (BGP_ENCAP_NODE, &neighbor_activate_cmd);
10347 install_element (BGP_ENCAPV6_NODE, &neighbor_activate_cmd);
10348 install_element (BGP_EVPN_NODE, &neighbor_activate_cmd);
10349
10350 /* "no neighbor activate" commands. */
10351 install_element (BGP_NODE, &no_neighbor_activate_cmd);
10352 install_element (BGP_IPV4_NODE, &no_neighbor_activate_cmd);
10353 install_element (BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
10354 install_element (BGP_IPV6_NODE, &no_neighbor_activate_cmd);
10355 install_element (BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
10356 install_element (BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
10357 install_element (BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
10358 install_element (BGP_ENCAP_NODE, &no_neighbor_activate_cmd);
10359 install_element (BGP_ENCAPV6_NODE, &no_neighbor_activate_cmd);
10360 install_element (BGP_EVPN_NODE, &no_neighbor_activate_cmd);
10361
10362 /* "neighbor peer-group" set commands.
10363 * Long term we should only accept this command under BGP_NODE and not all of
10364 * the afi/safi sub-contexts. For now though we need to accept it for backwards
10365 * compatibility. This changed when we stopped requiring that peers be assigned
10366 * to their peer-group under each address-family sub-context.
10367 */
10368 install_element (BGP_NODE, &neighbor_set_peer_group_cmd);
10369 install_element (BGP_IPV4_NODE, &neighbor_set_peer_group_cmd);
10370 install_element (BGP_IPV4M_NODE, &neighbor_set_peer_group_cmd);
10371 install_element (BGP_IPV6_NODE, &neighbor_set_peer_group_cmd);
10372 install_element (BGP_IPV6M_NODE, &neighbor_set_peer_group_cmd);
10373 install_element (BGP_VPNV4_NODE, &neighbor_set_peer_group_cmd);
10374 install_element (BGP_VPNV6_NODE, &neighbor_set_peer_group_cmd);
10375 install_element (BGP_ENCAP_NODE, &neighbor_set_peer_group_cmd);
10376 install_element (BGP_ENCAPV6_NODE, &neighbor_set_peer_group_cmd);
10377
10378 /* "no neighbor peer-group unset" commands. */
10379 install_element (BGP_NODE, &no_neighbor_set_peer_group_cmd);
10380 install_element (BGP_IPV4_NODE, &no_neighbor_set_peer_group_cmd);
10381 install_element (BGP_IPV4M_NODE, &no_neighbor_set_peer_group_cmd);
10382 install_element (BGP_IPV6_NODE, &no_neighbor_set_peer_group_cmd);
10383 install_element (BGP_IPV6M_NODE, &no_neighbor_set_peer_group_cmd);
10384 install_element (BGP_VPNV4_NODE, &no_neighbor_set_peer_group_cmd);
10385 install_element (BGP_VPNV6_NODE, &no_neighbor_set_peer_group_cmd);
10386 install_element (BGP_ENCAP_NODE, &no_neighbor_set_peer_group_cmd);
10387 install_element (BGP_ENCAPV6_NODE, &no_neighbor_set_peer_group_cmd);
10388
10389 /* "neighbor softreconfiguration inbound" commands.*/
10390 install_element (BGP_NODE, &neighbor_soft_reconfiguration_cmd);
10391 install_element (BGP_NODE, &no_neighbor_soft_reconfiguration_cmd);
10392 install_element (BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
10393 install_element (BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
10394 install_element (BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
10395 install_element (BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
10396 install_element (BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
10397 install_element (BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
10398 install_element (BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
10399 install_element (BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
10400 install_element (BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
10401 install_element (BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
10402 install_element (BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
10403 install_element (BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
10404 install_element (BGP_ENCAP_NODE, &neighbor_soft_reconfiguration_cmd);
10405 install_element (BGP_ENCAP_NODE, &no_neighbor_soft_reconfiguration_cmd);
10406 install_element (BGP_ENCAPV6_NODE, &neighbor_soft_reconfiguration_cmd);
10407 install_element (BGP_ENCAPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
10408
10409 /* "neighbor attribute-unchanged" commands. */
10410 install_element (BGP_NODE, &neighbor_attr_unchanged_cmd);
10411 install_element (BGP_NODE, &no_neighbor_attr_unchanged_cmd);
10412 install_element (BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
10413 install_element (BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
10414 install_element (BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
10415 install_element (BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
10416 install_element (BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
10417 install_element (BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
10418 install_element (BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
10419 install_element (BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
10420 install_element (BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
10421 install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
10422 install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
10423 install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
10424
10425 install_element (BGP_ENCAP_NODE, &neighbor_attr_unchanged_cmd);
10426 install_element (BGP_ENCAP_NODE, &no_neighbor_attr_unchanged_cmd);
10427
10428 install_element (BGP_ENCAPV6_NODE, &neighbor_attr_unchanged_cmd);
10429 install_element (BGP_ENCAPV6_NODE, &no_neighbor_attr_unchanged_cmd);
10430
10431 install_element (BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
10432 install_element (BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
10433
10434 /* "nexthop-local unchanged" commands */
10435 install_element (BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
10436 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_local_unchanged_cmd);
10437
10438 /* "neighbor next-hop-self" commands. */
10439 install_element (BGP_NODE, &neighbor_nexthop_self_cmd);
10440 install_element (BGP_NODE, &no_neighbor_nexthop_self_cmd);
10441 install_element (BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
10442 install_element (BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
10443 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
10444 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
10445 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
10446 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
10447 install_element (BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
10448 install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
10449 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
10450 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
10451 install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
10452 install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
10453 install_element (BGP_ENCAP_NODE, &neighbor_nexthop_self_cmd);
10454 install_element (BGP_ENCAP_NODE, &no_neighbor_nexthop_self_cmd);
10455 install_element (BGP_ENCAPV6_NODE, &neighbor_nexthop_self_cmd);
10456 install_element (BGP_ENCAPV6_NODE, &no_neighbor_nexthop_self_cmd);
10457
10458 /* "neighbor next-hop-self force" commands. */
10459 install_element (BGP_NODE, &neighbor_nexthop_self_force_cmd);
10460 install_element (BGP_NODE, &no_neighbor_nexthop_self_force_cmd);
10461 install_element (BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
10462 install_element (BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
10463 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
10464 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
10465 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
10466 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
10467 install_element (BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
10468 install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
10469 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
10470 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
10471 install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
10472 install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
10473
10474 /* "neighbor as-override" commands. */
10475 install_element (BGP_NODE, &neighbor_as_override_cmd);
10476 install_element (BGP_NODE, &no_neighbor_as_override_cmd);
10477 install_element (BGP_IPV4_NODE, &neighbor_as_override_cmd);
10478 install_element (BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
10479 install_element (BGP_IPV4M_NODE, &neighbor_as_override_cmd);
10480 install_element (BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
10481 install_element (BGP_IPV6_NODE, &neighbor_as_override_cmd);
10482 install_element (BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
10483 install_element (BGP_IPV6M_NODE, &neighbor_as_override_cmd);
10484 install_element (BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
10485 install_element (BGP_VPNV4_NODE, &neighbor_as_override_cmd);
10486 install_element (BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
10487 install_element (BGP_VPNV6_NODE, &neighbor_as_override_cmd);
10488 install_element (BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
10489
10490 /* "neighbor remove-private-AS" commands. */
10491 install_element (BGP_NODE, &neighbor_remove_private_as_cmd);
10492 install_element (BGP_NODE, &no_neighbor_remove_private_as_cmd);
10493 install_element (BGP_NODE, &neighbor_remove_private_as_all_cmd);
10494 install_element (BGP_NODE, &no_neighbor_remove_private_as_all_cmd);
10495 install_element (BGP_NODE, &neighbor_remove_private_as_replace_as_cmd);
10496 install_element (BGP_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10497 install_element (BGP_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10498 install_element (BGP_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
10499 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
10500 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
10501 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
10502 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
10503 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_replace_as_cmd);
10504 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10505 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10506 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
10507 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
10508 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
10509 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
10510 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
10511 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_replace_as_cmd);
10512 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10513 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10514 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
10515 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
10516 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
10517 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
10518 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
10519 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_replace_as_cmd);
10520 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10521 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10522 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
10523 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
10524 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
10525 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
10526 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
10527 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_replace_as_cmd);
10528 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10529 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10530 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
10531 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
10532 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
10533 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
10534 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
10535 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_replace_as_cmd);
10536 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10537 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10538 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
10539 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
10540 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
10541 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
10542 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
10543 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_replace_as_cmd);
10544 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10545 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10546 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
10547 install_element (BGP_ENCAP_NODE, &neighbor_remove_private_as_cmd);
10548 install_element (BGP_ENCAP_NODE, &no_neighbor_remove_private_as_cmd);
10549 install_element (BGP_ENCAPV6_NODE, &neighbor_remove_private_as_cmd);
10550 install_element (BGP_ENCAPV6_NODE, &no_neighbor_remove_private_as_cmd);
10551
10552 /* "neighbor send-community" commands.*/
10553 install_element (BGP_NODE, &neighbor_send_community_cmd);
10554 install_element (BGP_NODE, &neighbor_send_community_type_cmd);
10555 install_element (BGP_NODE, &no_neighbor_send_community_cmd);
10556 install_element (BGP_NODE, &no_neighbor_send_community_type_cmd);
10557 install_element (BGP_IPV4_NODE, &neighbor_send_community_cmd);
10558 install_element (BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
10559 install_element (BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
10560 install_element (BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
10561 install_element (BGP_IPV4M_NODE, &neighbor_send_community_cmd);
10562 install_element (BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
10563 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
10564 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
10565 install_element (BGP_IPV6_NODE, &neighbor_send_community_cmd);
10566 install_element (BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
10567 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
10568 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
10569 install_element (BGP_IPV6M_NODE, &neighbor_send_community_cmd);
10570 install_element (BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
10571 install_element (BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
10572 install_element (BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
10573 install_element (BGP_VPNV4_NODE, &neighbor_send_community_cmd);
10574 install_element (BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
10575 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
10576 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
10577 install_element (BGP_VPNV6_NODE, &neighbor_send_community_cmd);
10578 install_element (BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
10579 install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
10580 install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
10581 install_element (BGP_ENCAP_NODE, &neighbor_send_community_cmd);
10582 install_element (BGP_ENCAP_NODE, &neighbor_send_community_type_cmd);
10583 install_element (BGP_ENCAP_NODE, &no_neighbor_send_community_cmd);
10584 install_element (BGP_ENCAP_NODE, &no_neighbor_send_community_type_cmd);
10585 install_element (BGP_ENCAPV6_NODE, &neighbor_send_community_cmd);
10586 install_element (BGP_ENCAPV6_NODE, &neighbor_send_community_type_cmd);
10587 install_element (BGP_ENCAPV6_NODE, &no_neighbor_send_community_cmd);
10588 install_element (BGP_ENCAPV6_NODE, &no_neighbor_send_community_type_cmd);
10589
10590 /* "neighbor route-reflector" commands.*/
10591 install_element (BGP_NODE, &neighbor_route_reflector_client_cmd);
10592 install_element (BGP_NODE, &no_neighbor_route_reflector_client_cmd);
10593 install_element (BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
10594 install_element (BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
10595 install_element (BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
10596 install_element (BGP_IPV4M_NODE, &no_neighbor_route_reflector_client_cmd);
10597 install_element (BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
10598 install_element (BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
10599 install_element (BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
10600 install_element (BGP_IPV6M_NODE, &no_neighbor_route_reflector_client_cmd);
10601 install_element (BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
10602 install_element (BGP_VPNV4_NODE, &no_neighbor_route_reflector_client_cmd);
10603 install_element (BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
10604 install_element (BGP_VPNV6_NODE, &no_neighbor_route_reflector_client_cmd);
10605 install_element (BGP_ENCAP_NODE, &neighbor_route_reflector_client_cmd);
10606 install_element (BGP_ENCAP_NODE, &no_neighbor_route_reflector_client_cmd);
10607 install_element (BGP_ENCAPV6_NODE, &neighbor_route_reflector_client_cmd);
10608 install_element (BGP_ENCAPV6_NODE, &no_neighbor_route_reflector_client_cmd);
10609
10610 /* "neighbor route-server" commands.*/
10611 install_element (BGP_NODE, &neighbor_route_server_client_cmd);
10612 install_element (BGP_NODE, &no_neighbor_route_server_client_cmd);
10613 install_element (BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
10614 install_element (BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
10615 install_element (BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
10616 install_element (BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
10617 install_element (BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
10618 install_element (BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
10619 install_element (BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
10620 install_element (BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
10621 install_element (BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
10622 install_element (BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
10623 install_element (BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
10624 install_element (BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
10625 install_element (BGP_ENCAP_NODE, &neighbor_route_server_client_cmd);
10626 install_element (BGP_ENCAP_NODE, &no_neighbor_route_server_client_cmd);
10627 install_element (BGP_ENCAPV6_NODE, &neighbor_route_server_client_cmd);
10628 install_element (BGP_ENCAPV6_NODE, &no_neighbor_route_server_client_cmd);
10629
10630 /* "neighbor addpath-tx-all-paths" commands.*/
10631 install_element (BGP_NODE, &neighbor_addpath_tx_all_paths_cmd);
10632 install_element (BGP_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10633 install_element (BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
10634 install_element (BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10635 install_element (BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
10636 install_element (BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10637 install_element (BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
10638 install_element (BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10639 install_element (BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
10640 install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10641 install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
10642 install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10643 install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
10644 install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10645
10646 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
10647 install_element (BGP_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10648 install_element (BGP_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10649 install_element (BGP_IPV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10650 install_element (BGP_IPV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10651 install_element (BGP_IPV4M_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10652 install_element (BGP_IPV4M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10653 install_element (BGP_IPV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10654 install_element (BGP_IPV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10655 install_element (BGP_IPV6M_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10656 install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10657 install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10658 install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10659 install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10660 install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10661
10662 /* "neighbor passive" commands. */
10663 install_element (BGP_NODE, &neighbor_passive_cmd);
10664 install_element (BGP_NODE, &no_neighbor_passive_cmd);
10665
10666
10667 /* "neighbor shutdown" commands. */
10668 install_element (BGP_NODE, &neighbor_shutdown_cmd);
10669 install_element (BGP_NODE, &no_neighbor_shutdown_cmd);
10670 install_element (BGP_NODE, &neighbor_shutdown_msg_cmd);
10671 install_element (BGP_NODE, &no_neighbor_shutdown_msg_cmd);
10672
10673 /* "neighbor capability extended-nexthop" commands.*/
10674 install_element (BGP_NODE, &neighbor_capability_enhe_cmd);
10675 install_element (BGP_NODE, &no_neighbor_capability_enhe_cmd);
10676
10677 /* "neighbor capability orf prefix-list" commands.*/
10678 install_element (BGP_NODE, &neighbor_capability_orf_prefix_cmd);
10679 install_element (BGP_NODE, &no_neighbor_capability_orf_prefix_cmd);
10680 install_element (BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
10681 install_element (BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
10682 install_element (BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
10683 install_element (BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
10684 install_element (BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
10685 install_element (BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
10686 install_element (BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
10687 install_element (BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
10688
10689 /* "neighbor capability dynamic" commands.*/
10690 install_element (BGP_NODE, &neighbor_capability_dynamic_cmd);
10691 install_element (BGP_NODE, &no_neighbor_capability_dynamic_cmd);
10692
10693 /* "neighbor dont-capability-negotiate" commands. */
10694 install_element (BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
10695 install_element (BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
10696
10697 /* "neighbor ebgp-multihop" commands. */
10698 install_element (BGP_NODE, &neighbor_ebgp_multihop_cmd);
10699 install_element (BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
10700 install_element (BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
10701
10702 /* "neighbor disable-connected-check" commands. */
10703 install_element (BGP_NODE, &neighbor_disable_connected_check_cmd);
10704 install_element (BGP_NODE, &no_neighbor_disable_connected_check_cmd);
10705
10706 /* "neighbor description" commands. */
10707 install_element (BGP_NODE, &neighbor_description_cmd);
10708 install_element (BGP_NODE, &no_neighbor_description_cmd);
10709
10710 /* "neighbor update-source" commands. "*/
10711 install_element (BGP_NODE, &neighbor_update_source_cmd);
10712 install_element (BGP_NODE, &no_neighbor_update_source_cmd);
10713
10714 /* "neighbor default-originate" commands. */
10715 install_element (BGP_NODE, &neighbor_default_originate_cmd);
10716 install_element (BGP_NODE, &neighbor_default_originate_rmap_cmd);
10717 install_element (BGP_NODE, &no_neighbor_default_originate_cmd);
10718 install_element (BGP_IPV4_NODE, &neighbor_default_originate_cmd);
10719 install_element (BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
10720 install_element (BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
10721 install_element (BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
10722 install_element (BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
10723 install_element (BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
10724 install_element (BGP_IPV6_NODE, &neighbor_default_originate_cmd);
10725 install_element (BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
10726 install_element (BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
10727 install_element (BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
10728 install_element (BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
10729 install_element (BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
10730
10731 /* "neighbor port" commands. */
10732 install_element (BGP_NODE, &neighbor_port_cmd);
10733 install_element (BGP_NODE, &no_neighbor_port_cmd);
10734
10735 /* "neighbor weight" commands. */
10736 install_element (BGP_NODE, &neighbor_weight_cmd);
10737 install_element (BGP_NODE, &no_neighbor_weight_cmd);
10738
10739 install_element (BGP_IPV4_NODE, &neighbor_weight_cmd);
10740 install_element (BGP_IPV4_NODE, &no_neighbor_weight_cmd);
10741 install_element (BGP_IPV4M_NODE, &neighbor_weight_cmd);
10742 install_element (BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
10743 install_element (BGP_IPV6_NODE, &neighbor_weight_cmd);
10744 install_element (BGP_IPV6_NODE, &no_neighbor_weight_cmd);
10745 install_element (BGP_IPV6M_NODE, &neighbor_weight_cmd);
10746 install_element (BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
10747 install_element (BGP_VPNV4_NODE, &neighbor_weight_cmd);
10748 install_element (BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
10749 install_element (BGP_VPNV6_NODE, &neighbor_weight_cmd);
10750 install_element (BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
10751 install_element (BGP_ENCAP_NODE, &neighbor_weight_cmd);
10752 install_element (BGP_ENCAP_NODE, &no_neighbor_weight_cmd);
10753 install_element (BGP_ENCAPV6_NODE, &neighbor_weight_cmd);
10754 install_element (BGP_ENCAPV6_NODE, &no_neighbor_weight_cmd);
10755
10756 /* "neighbor override-capability" commands. */
10757 install_element (BGP_NODE, &neighbor_override_capability_cmd);
10758 install_element (BGP_NODE, &no_neighbor_override_capability_cmd);
10759
10760 /* "neighbor strict-capability-match" commands. */
10761 install_element (BGP_NODE, &neighbor_strict_capability_cmd);
10762 install_element (BGP_NODE, &no_neighbor_strict_capability_cmd);
10763
10764 /* "neighbor timers" commands. */
10765 install_element (BGP_NODE, &neighbor_timers_cmd);
10766 install_element (BGP_NODE, &no_neighbor_timers_cmd);
10767
10768 /* "neighbor timers connect" commands. */
10769 install_element (BGP_NODE, &neighbor_timers_connect_cmd);
10770 install_element (BGP_NODE, &no_neighbor_timers_connect_cmd);
10771
10772 /* "neighbor advertisement-interval" commands. */
10773 install_element (BGP_NODE, &neighbor_advertise_interval_cmd);
10774 install_element (BGP_NODE, &no_neighbor_advertise_interval_cmd);
10775
10776 /* "neighbor interface" commands. */
10777 install_element (BGP_NODE, &neighbor_interface_cmd);
10778 install_element (BGP_NODE, &no_neighbor_interface_cmd);
10779
10780 /* "neighbor distribute" commands. */
10781 install_element (BGP_NODE, &neighbor_distribute_list_cmd);
10782 install_element (BGP_NODE, &no_neighbor_distribute_list_cmd);
10783 install_element (BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
10784 install_element (BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
10785 install_element (BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
10786 install_element (BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
10787 install_element (BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
10788 install_element (BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
10789 install_element (BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
10790 install_element (BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
10791 install_element (BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
10792 install_element (BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
10793 install_element (BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
10794 install_element (BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
10795 install_element (BGP_ENCAP_NODE, &neighbor_distribute_list_cmd);
10796 install_element (BGP_ENCAP_NODE, &no_neighbor_distribute_list_cmd);
10797 install_element (BGP_ENCAPV6_NODE, &neighbor_distribute_list_cmd);
10798 install_element (BGP_ENCAPV6_NODE, &no_neighbor_distribute_list_cmd);
10799
10800 /* "neighbor prefix-list" commands. */
10801 install_element (BGP_NODE, &neighbor_prefix_list_cmd);
10802 install_element (BGP_NODE, &no_neighbor_prefix_list_cmd);
10803 install_element (BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
10804 install_element (BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
10805 install_element (BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
10806 install_element (BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
10807 install_element (BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
10808 install_element (BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
10809 install_element (BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
10810 install_element (BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
10811 install_element (BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
10812 install_element (BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
10813 install_element (BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
10814 install_element (BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
10815 install_element (BGP_ENCAP_NODE, &neighbor_prefix_list_cmd);
10816 install_element (BGP_ENCAP_NODE, &no_neighbor_prefix_list_cmd);
10817 install_element (BGP_ENCAPV6_NODE, &neighbor_prefix_list_cmd);
10818 install_element (BGP_ENCAPV6_NODE, &no_neighbor_prefix_list_cmd);
10819
10820 /* "neighbor filter-list" commands. */
10821 install_element (BGP_NODE, &neighbor_filter_list_cmd);
10822 install_element (BGP_NODE, &no_neighbor_filter_list_cmd);
10823 install_element (BGP_IPV4_NODE, &neighbor_filter_list_cmd);
10824 install_element (BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
10825 install_element (BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
10826 install_element (BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
10827 install_element (BGP_IPV6_NODE, &neighbor_filter_list_cmd);
10828 install_element (BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
10829 install_element (BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
10830 install_element (BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
10831 install_element (BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
10832 install_element (BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
10833 install_element (BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
10834 install_element (BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
10835 install_element (BGP_ENCAP_NODE, &neighbor_filter_list_cmd);
10836 install_element (BGP_ENCAP_NODE, &no_neighbor_filter_list_cmd);
10837 install_element (BGP_ENCAPV6_NODE, &neighbor_filter_list_cmd);
10838 install_element (BGP_ENCAPV6_NODE, &no_neighbor_filter_list_cmd);
10839
10840 /* "neighbor route-map" commands. */
10841 install_element (BGP_NODE, &neighbor_route_map_cmd);
10842 install_element (BGP_NODE, &no_neighbor_route_map_cmd);
10843 install_element (BGP_IPV4_NODE, &neighbor_route_map_cmd);
10844 install_element (BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
10845 install_element (BGP_IPV4M_NODE, &neighbor_route_map_cmd);
10846 install_element (BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
10847 install_element (BGP_IPV6_NODE, &neighbor_route_map_cmd);
10848 install_element (BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
10849 install_element (BGP_IPV6M_NODE, &neighbor_route_map_cmd);
10850 install_element (BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
10851 install_element (BGP_VPNV4_NODE, &neighbor_route_map_cmd);
10852 install_element (BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
10853 install_element (BGP_VPNV6_NODE, &neighbor_route_map_cmd);
10854 install_element (BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
10855 install_element (BGP_ENCAP_NODE, &neighbor_route_map_cmd);
10856 install_element (BGP_ENCAP_NODE, &no_neighbor_route_map_cmd);
10857 install_element (BGP_ENCAPV6_NODE, &neighbor_route_map_cmd);
10858 install_element (BGP_ENCAPV6_NODE, &no_neighbor_route_map_cmd);
10859
10860 /* "neighbor unsuppress-map" commands. */
10861 install_element (BGP_NODE, &neighbor_unsuppress_map_cmd);
10862 install_element (BGP_NODE, &no_neighbor_unsuppress_map_cmd);
10863 install_element (BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
10864 install_element (BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
10865 install_element (BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
10866 install_element (BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
10867 install_element (BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
10868 install_element (BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
10869 install_element (BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
10870 install_element (BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
10871 install_element (BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
10872 install_element (BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
10873 install_element (BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
10874 install_element (BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
10875 install_element (BGP_ENCAP_NODE, &neighbor_unsuppress_map_cmd);
10876 install_element (BGP_ENCAP_NODE, &no_neighbor_unsuppress_map_cmd);
10877 install_element (BGP_ENCAPV6_NODE, &neighbor_unsuppress_map_cmd);
10878 install_element (BGP_ENCAPV6_NODE, &no_neighbor_unsuppress_map_cmd);
10879
10880 /* "neighbor maximum-prefix" commands. */
10881 install_element (BGP_NODE, &neighbor_maximum_prefix_cmd);
10882 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_cmd);
10883 install_element (BGP_NODE, &neighbor_maximum_prefix_warning_cmd);
10884 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10885 install_element (BGP_NODE, &neighbor_maximum_prefix_restart_cmd);
10886 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10887 install_element (BGP_NODE, &no_neighbor_maximum_prefix_cmd);
10888 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
10889 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
10890 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
10891 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10892 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
10893 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10894 install_element (BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
10895 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
10896 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
10897 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
10898 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10899 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
10900 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10901 install_element (BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
10902 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
10903 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
10904 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
10905 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10906 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
10907 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10908 install_element (BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
10909 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
10910 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
10911 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
10912 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10913 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
10914 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10915 install_element (BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
10916 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
10917 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
10918 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
10919 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10920 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
10921 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10922 install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
10923 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
10924 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
10925 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
10926 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10927 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
10928 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10929 install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
10930
10931 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_cmd);
10932 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_threshold_cmd);
10933 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_warning_cmd);
10934 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10935 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_restart_cmd);
10936 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10937 install_element (BGP_ENCAP_NODE, &no_neighbor_maximum_prefix_cmd);
10938
10939 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_cmd);
10940 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
10941 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
10942 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10943 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
10944 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10945 install_element (BGP_ENCAPV6_NODE, &no_neighbor_maximum_prefix_cmd);
10946
10947 /* "neighbor allowas-in" */
10948 install_element (BGP_NODE, &neighbor_allowas_in_cmd);
10949 install_element (BGP_NODE, &no_neighbor_allowas_in_cmd);
10950 install_element (BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
10951 install_element (BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
10952 install_element (BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
10953 install_element (BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
10954 install_element (BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
10955 install_element (BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
10956 install_element (BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
10957 install_element (BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
10958 install_element (BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
10959 install_element (BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
10960 install_element (BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
10961 install_element (BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
10962 install_element (BGP_ENCAP_NODE, &neighbor_allowas_in_cmd);
10963 install_element (BGP_ENCAP_NODE, &no_neighbor_allowas_in_cmd);
10964 install_element (BGP_ENCAPV6_NODE, &neighbor_allowas_in_cmd);
10965 install_element (BGP_ENCAPV6_NODE, &no_neighbor_allowas_in_cmd);
10966
10967 /* address-family commands. */
10968 install_element (BGP_NODE, &address_family_ipv4_safi_cmd);
10969 install_element (BGP_NODE, &address_family_ipv6_safi_cmd);
10970 #ifdef KEEP_OLD_VPN_COMMANDS
10971 install_element (BGP_NODE, &address_family_vpnv4_cmd);
10972 install_element (BGP_NODE, &address_family_vpnv6_cmd);
10973 #endif /* KEEP_OLD_VPN_COMMANDS */
10974
10975 install_element (BGP_NODE, &address_family_encap_cmd);
10976 install_element (BGP_NODE, &address_family_encapv6_cmd);
10977
10978 install_element (BGP_NODE, &address_family_evpn_cmd);
10979
10980 /* "exit-address-family" command. */
10981 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
10982 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
10983 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
10984 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
10985 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
10986 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
10987 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
10988 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
10989 install_element (BGP_EVPN_NODE, &exit_address_family_cmd);
10990
10991 /* "clear ip bgp commands" */
10992 install_element (ENABLE_NODE, &clear_ip_bgp_all_cmd);
10993
10994 /* clear ip bgp prefix */
10995 install_element (ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
10996 install_element (ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
10997 install_element (ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
10998
10999 /* "show [ip] bgp summary" commands. */
11000 install_element (VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
11001 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
11002 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
11003 install_element (VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
11004 install_element (VIEW_NODE, &show_bgp_updgrps_adj_cmd);
11005 install_element (VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
11006 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
11007 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
11008 install_element (VIEW_NODE, &show_bgp_updgrps_stats_cmd);
11009 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
11010 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
11011 install_element (VIEW_NODE, &show_ip_bgp_summary_cmd);
11012 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
11013 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
11014 install_element (VIEW_NODE, &show_ip_bgp_updgrps_cmd);
11015
11016 /* "show [ip] bgp neighbors" commands. */
11017 install_element (VIEW_NODE, &show_ip_bgp_neighbors_cmd);
11018
11019 /* "show [ip] bgp peer-group" commands. */
11020 install_element (VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
11021
11022 /* "show [ip] bgp paths" commands. */
11023 install_element (VIEW_NODE, &show_ip_bgp_paths_cmd);
11024
11025 /* "show [ip] bgp community" commands. */
11026 install_element (VIEW_NODE, &show_ip_bgp_community_info_cmd);
11027
11028 /* "show ip bgp large-community" commands. */
11029 install_element (VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
11030 /* "show [ip] bgp attribute-info" commands. */
11031 install_element (VIEW_NODE, &show_ip_bgp_attr_info_cmd);
11032
11033 /* "redistribute" commands. */
11034 install_element (BGP_NODE, &bgp_redistribute_ipv4_cmd);
11035 install_element (BGP_NODE, &no_bgp_redistribute_ipv4_cmd);
11036 install_element (BGP_NODE, &bgp_redistribute_ipv4_rmap_cmd);
11037 install_element (BGP_NODE, &bgp_redistribute_ipv4_metric_cmd);
11038 install_element (BGP_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
11039 install_element (BGP_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
11040 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_cmd);
11041 install_element (BGP_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
11042 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
11043 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
11044 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
11045 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
11046 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
11047 install_element (BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
11048 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
11049 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
11050 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
11051 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
11052 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
11053 install_element (BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
11054 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
11055 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
11056 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
11057 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
11058 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
11059 install_element (BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
11060 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
11061 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
11062 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
11063 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
11064
11065 /* ttl_security commands */
11066 install_element (BGP_NODE, &neighbor_ttl_security_cmd);
11067 install_element (BGP_NODE, &no_neighbor_ttl_security_cmd);
11068
11069 /* "show [ip] bgp memory" commands. */
11070 install_element (VIEW_NODE, &show_bgp_memory_cmd);
11071
11072 /* "show [ip] bgp views" commands. */
11073 install_element (VIEW_NODE, &show_bgp_views_cmd);
11074
11075 /* "show [ip] bgp vrfs" commands. */
11076 install_element (VIEW_NODE, &show_bgp_vrfs_cmd);
11077
11078 /* Community-list. */
11079 community_list_vty ();
11080 }
11081
11082 #include "memory.h"
11083 #include "bgp_regex.h"
11084 #include "bgp_clist.h"
11085 #include "bgp_ecommunity.h"
11086
11087 /* VTY functions. */
11088
11089 /* Direction value to string conversion. */
11090 static const char *
11091 community_direct_str (int direct)
11092 {
11093 switch (direct)
11094 {
11095 case COMMUNITY_DENY:
11096 return "deny";
11097 case COMMUNITY_PERMIT:
11098 return "permit";
11099 default:
11100 return "unknown";
11101 }
11102 }
11103
11104 /* Display error string. */
11105 static void
11106 community_list_perror (struct vty *vty, int ret)
11107 {
11108 switch (ret)
11109 {
11110 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
11111 vty_out (vty, "%% Can't find community-list%s", VTY_NEWLINE);
11112 break;
11113 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
11114 vty_out (vty, "%% Malformed community-list value%s", VTY_NEWLINE);
11115 break;
11116 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
11117 vty_out (vty, "%% Community name conflict, previously defined as standard community%s", VTY_NEWLINE);
11118 break;
11119 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
11120 vty_out (vty, "%% Community name conflict, previously defined as expanded community%s", VTY_NEWLINE);
11121 break;
11122 }
11123 }
11124
11125 /* "community-list" keyword help string. */
11126 #define COMMUNITY_LIST_STR "Add a community list entry\n"
11127
11128
11129 /* ip community-list standard */
11130 DEFUN (ip_community_list_standard,
11131 ip_community_list_standard_cmd,
11132 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
11133 IP_STR
11134 COMMUNITY_LIST_STR
11135 "Community list number (standard)\n"
11136 "Add an standard community-list entry\n"
11137 "Community list name\n"
11138 "Specify community to reject\n"
11139 "Specify community to accept\n"
11140 COMMUNITY_VAL_STR)
11141 {
11142 char *cl_name_or_number = NULL;
11143 int direct = 0;
11144 int style = COMMUNITY_LIST_STANDARD;
11145
11146 int idx = 0;
11147 argv_find (argv, argc, "(1-99)", &idx);
11148 argv_find (argv, argc, "WORD", &idx);
11149 cl_name_or_number = argv[idx]->arg;
11150 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11151 argv_find (argv, argc, "AA:NN", &idx);
11152 char *str = argv_concat (argv, argc, idx);
11153
11154 int ret = community_list_set (bgp_clist, cl_name_or_number, str, direct, style);
11155
11156 XFREE (MTYPE_TMP, str);
11157
11158 if (ret < 0)
11159 {
11160 /* Display error string. */
11161 community_list_perror (vty, ret);
11162 return CMD_WARNING;
11163 }
11164
11165 return CMD_SUCCESS;
11166 }
11167
11168 DEFUN (no_ip_community_list_standard_all,
11169 no_ip_community_list_standard_all_cmd,
11170 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
11171 NO_STR
11172 IP_STR
11173 COMMUNITY_LIST_STR
11174 "Community list number (standard)\n"
11175 "Add an standard community-list entry\n"
11176 "Community list name\n"
11177 "Specify community to reject\n"
11178 "Specify community to accept\n"
11179 COMMUNITY_VAL_STR)
11180 {
11181 int delete_all = 0;
11182
11183 char *cl_name_or_number = NULL;
11184 int direct = 0;
11185 int style = COMMUNITY_LIST_STANDARD;
11186
11187 int idx = 0;
11188 argv_find (argv, argc, "(1-99)", &idx);
11189 argv_find (argv, argc, "WORD", &idx);
11190 cl_name_or_number = argv[idx]->arg;
11191 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11192 argv_find (argv, argc, "AA:NN", &idx);
11193 char *str = argv_concat (argv, argc, idx);
11194
11195 int ret = community_list_unset (bgp_clist, cl_name_or_number, str, direct, style, delete_all);
11196
11197 XFREE (MTYPE_TMP, str);
11198
11199 if (ret < 0)
11200 {
11201 community_list_perror (vty, ret);
11202 return CMD_WARNING;
11203 }
11204
11205 return CMD_SUCCESS;
11206 }
11207
11208 /* ip community-list expanded */
11209 DEFUN (ip_community_list_expanded_all,
11210 ip_community_list_expanded_all_cmd,
11211 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
11212 IP_STR
11213 COMMUNITY_LIST_STR
11214 "Community list number (expanded)\n"
11215 "Add an expanded community-list entry\n"
11216 "Community list name\n"
11217 "Specify community to reject\n"
11218 "Specify community to accept\n"
11219 COMMUNITY_VAL_STR)
11220 {
11221 char *cl_name_or_number = NULL;
11222 int direct = 0;
11223 int style = COMMUNITY_LIST_EXPANDED;
11224
11225 int idx = 0;
11226 argv_find (argv, argc, "(100-500)", &idx);
11227 argv_find (argv, argc, "WORD", &idx);
11228 cl_name_or_number = argv[idx]->arg;
11229 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11230 argv_find (argv, argc, "AA:NN", &idx);
11231 char *str = argv_concat (argv, argc, idx);
11232
11233 int ret = community_list_set (bgp_clist, cl_name_or_number, str, direct, style);
11234
11235 XFREE (MTYPE_TMP, str);
11236
11237 if (ret < 0)
11238 {
11239 /* Display error string. */
11240 community_list_perror (vty, ret);
11241 return CMD_WARNING;
11242 }
11243
11244 return CMD_SUCCESS;
11245 }
11246
11247 DEFUN (no_ip_community_list_expanded_all,
11248 no_ip_community_list_expanded_all_cmd,
11249 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
11250 NO_STR
11251 IP_STR
11252 COMMUNITY_LIST_STR
11253 "Community list number (expanded)\n"
11254 "Add an expanded community-list entry\n"
11255 "Community list name\n"
11256 "Specify community to reject\n"
11257 "Specify community to accept\n"
11258 COMMUNITY_VAL_STR)
11259 {
11260 int delete_all = 0;
11261
11262 char *cl_name_or_number = NULL;
11263 int direct = 0;
11264 int style = COMMUNITY_LIST_EXPANDED;
11265
11266 int idx = 0;
11267 argv_find (argv, argc, "(100-500)", &idx);
11268 argv_find (argv, argc, "WORD", &idx);
11269 cl_name_or_number = argv[idx]->arg;
11270 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11271 argv_find (argv, argc, "AA:NN", &idx);
11272 char *str = argv_concat (argv, argc, idx);
11273
11274 int ret = community_list_unset (bgp_clist, cl_name_or_number, str, direct, style, delete_all);
11275
11276 XFREE (MTYPE_TMP, str);
11277
11278 if (ret < 0)
11279 {
11280 community_list_perror (vty, ret);
11281 return CMD_WARNING;
11282 }
11283
11284 return CMD_SUCCESS;
11285 }
11286
11287 static void
11288 community_list_show (struct vty *vty, struct community_list *list)
11289 {
11290 struct community_entry *entry;
11291
11292 for (entry = list->head; entry; entry = entry->next)
11293 {
11294 if (entry == list->head)
11295 {
11296 if (all_digit (list->name))
11297 vty_out (vty, "Community %s list %s%s",
11298 entry->style == COMMUNITY_LIST_STANDARD ?
11299 "standard" : "(expanded) access",
11300 list->name, VTY_NEWLINE);
11301 else
11302 vty_out (vty, "Named Community %s list %s%s",
11303 entry->style == COMMUNITY_LIST_STANDARD ?
11304 "standard" : "expanded",
11305 list->name, VTY_NEWLINE);
11306 }
11307 if (entry->any)
11308 vty_out (vty, " %s%s",
11309 community_direct_str (entry->direct), VTY_NEWLINE);
11310 else
11311 vty_out (vty, " %s %s%s",
11312 community_direct_str (entry->direct),
11313 entry->style == COMMUNITY_LIST_STANDARD
11314 ? community_str (entry->u.com) : entry->config,
11315 VTY_NEWLINE);
11316 }
11317 }
11318
11319 DEFUN (show_ip_community_list,
11320 show_ip_community_list_cmd,
11321 "show ip community-list",
11322 SHOW_STR
11323 IP_STR
11324 "List community-list\n")
11325 {
11326 struct community_list *list;
11327 struct community_list_master *cm;
11328
11329 cm = community_list_master_lookup (bgp_clist, COMMUNITY_LIST_MASTER);
11330 if (! cm)
11331 return CMD_SUCCESS;
11332
11333 for (list = cm->num.head; list; list = list->next)
11334 community_list_show (vty, list);
11335
11336 for (list = cm->str.head; list; list = list->next)
11337 community_list_show (vty, list);
11338
11339 return CMD_SUCCESS;
11340 }
11341
11342 DEFUN (show_ip_community_list_arg,
11343 show_ip_community_list_arg_cmd,
11344 "show ip community-list <(1-500)|WORD>",
11345 SHOW_STR
11346 IP_STR
11347 "List community-list\n"
11348 "Community-list number\n"
11349 "Community-list name\n")
11350 {
11351 int idx_comm_list = 3;
11352 struct community_list *list;
11353
11354 list = community_list_lookup (bgp_clist, argv[idx_comm_list]->arg, COMMUNITY_LIST_MASTER);
11355 if (! list)
11356 {
11357 vty_out (vty, "%% Can't find community-list%s", VTY_NEWLINE);
11358 return CMD_WARNING;
11359 }
11360
11361 community_list_show (vty, list);
11362
11363 return CMD_SUCCESS;
11364 }
11365
11366 /*
11367 * Large Community code.
11368 */
11369 static int
11370 lcommunity_list_set_vty (struct vty *vty, int argc, struct cmd_token **argv,
11371 int style, int reject_all_digit_name)
11372 {
11373 int ret;
11374 int direct;
11375 char *str;
11376 int idx = 0;
11377 char *cl_name;
11378
11379 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11380
11381 /* All digit name check. */
11382 idx = 0;
11383 argv_find (argv, argc, "WORD", &idx);
11384 argv_find (argv, argc, "(1-99)", &idx);
11385 argv_find (argv, argc, "(100-500)", &idx);
11386 cl_name = argv[idx]->arg;
11387 if (reject_all_digit_name && all_digit (cl_name))
11388 {
11389 vty_out (vty, "%% Community name cannot have all digits%s", VTY_NEWLINE);
11390 return CMD_WARNING;
11391 }
11392
11393 argv_find (argv, argc, "AA:BB:CC", &idx);
11394 argv_find (argv, argc, "LINE", &idx);
11395 /* Concat community string argument. */
11396 if (idx)
11397 str = argv_concat (argv, argc, idx);
11398 else
11399 str = NULL;
11400
11401 ret = lcommunity_list_set (bgp_clist, cl_name, str, direct, style);
11402
11403 /* Free temporary community list string allocated by
11404 argv_concat(). */
11405 if (str)
11406 XFREE (MTYPE_TMP, str);
11407
11408 if (ret < 0)
11409 {
11410 community_list_perror (vty, ret);
11411 return CMD_WARNING;
11412 }
11413 return CMD_SUCCESS;
11414 }
11415
11416 static int
11417 lcommunity_list_unset_vty (struct vty *vty, int argc, struct cmd_token **argv,
11418 int style)
11419 {
11420 int ret;
11421 int direct = 0;
11422 char *str = NULL;
11423 int idx = 0;
11424
11425 argv_find (argv, argc, "permit", &idx);
11426 argv_find (argv, argc, "deny", &idx);
11427
11428 if (idx)
11429 {
11430 /* Check the list direct. */
11431 if (strncmp (argv[idx]->arg, "p", 1) == 0)
11432 direct = COMMUNITY_PERMIT;
11433 else
11434 direct = COMMUNITY_DENY;
11435
11436 idx = 0;
11437 argv_find (argv, argc, "LINE", &idx);
11438 argv_find (argv, argc, "AA:AA:NN", &idx);
11439 /* Concat community string argument. */
11440 str = argv_concat (argv, argc, idx);
11441 }
11442
11443 idx = 0;
11444 argv_find (argv, argc, "(1-99)", &idx);
11445 argv_find (argv, argc, "(100-500)", &idx);
11446 argv_find (argv, argc, "WORD", &idx);
11447
11448 /* Unset community list. */
11449 ret = lcommunity_list_unset (bgp_clist, argv[idx]->arg, str, direct, style);
11450
11451 /* Free temporary community list string allocated by
11452 argv_concat(). */
11453 if (str)
11454 XFREE (MTYPE_TMP, str);
11455
11456 if (ret < 0)
11457 {
11458 community_list_perror (vty, ret);
11459 return CMD_WARNING;
11460 }
11461
11462 return CMD_SUCCESS;
11463 }
11464
11465 /* "large-community-list" keyword help string. */
11466 #define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
11467 #define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
11468
11469 DEFUN (ip_lcommunity_list_standard,
11470 ip_lcommunity_list_standard_cmd,
11471 "ip large-community-list (1-99) <deny|permit>",
11472 IP_STR
11473 LCOMMUNITY_LIST_STR
11474 "Large Community list number (standard)\n"
11475 "Specify large community to reject\n"
11476 "Specify large community to accept\n"
11477 LCOMMUNITY_VAL_STR)
11478 {
11479 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 0);
11480 }
11481
11482 DEFUN (ip_lcommunity_list_standard1,
11483 ip_lcommunity_list_standard1_cmd,
11484 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
11485 IP_STR
11486 LCOMMUNITY_LIST_STR
11487 "Large Community list number (standard)\n"
11488 "Specify large community to reject\n"
11489 "Specify large community to accept\n"
11490 LCOMMUNITY_VAL_STR)
11491 {
11492 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 0);
11493 }
11494
11495 DEFUN (ip_lcommunity_list_expanded,
11496 ip_lcommunity_list_expanded_cmd,
11497 "ip large-community-list (100-500) <deny|permit> LINE...",
11498 IP_STR
11499 LCOMMUNITY_LIST_STR
11500 "Large Community list number (expanded)\n"
11501 "Specify large community to reject\n"
11502 "Specify large community to accept\n"
11503 "An ordered list as a regular-expression\n")
11504 {
11505 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED, 0);
11506 }
11507
11508 DEFUN (ip_lcommunity_list_name_standard,
11509 ip_lcommunity_list_name_standard_cmd,
11510 "ip large-community-list standard WORD <deny|permit>",
11511 IP_STR
11512 LCOMMUNITY_LIST_STR
11513 "Specify standard large-community-list\n"
11514 "Large Community list name\n"
11515 "Specify large community to reject\n"
11516 "Specify large community to accept\n")
11517 {
11518 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 1);
11519 }
11520
11521 DEFUN (ip_lcommunity_list_name_standard1,
11522 ip_lcommunity_list_name_standard1_cmd,
11523 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
11524 IP_STR
11525 LCOMMUNITY_LIST_STR
11526 "Specify standard large-community-list\n"
11527 "Large Community list name\n"
11528 "Specify large community to reject\n"
11529 "Specify large community to accept\n"
11530 LCOMMUNITY_VAL_STR)
11531 {
11532 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 1);
11533 }
11534
11535 DEFUN (ip_lcommunity_list_name_expanded,
11536 ip_lcommunity_list_name_expanded_cmd,
11537 "ip large-community-list expanded WORD <deny|permit> LINE...",
11538 IP_STR
11539 LCOMMUNITY_LIST_STR
11540 "Specify expanded large-community-list\n"
11541 "Large Community list name\n"
11542 "Specify large community to reject\n"
11543 "Specify large community to accept\n"
11544 "An ordered list as a regular-expression\n")
11545 {
11546 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED, 1);
11547 }
11548
11549 DEFUN (no_ip_lcommunity_list_standard_all,
11550 no_ip_lcommunity_list_standard_all_cmd,
11551 "no ip large-community-list <(1-99)|(100-500)|WORD>",
11552 NO_STR
11553 IP_STR
11554 LCOMMUNITY_LIST_STR
11555 "Large Community list number (standard)\n"
11556 "Large Community list number (expanded)\n"
11557 "Large Community list name\n")
11558 {
11559 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
11560 }
11561
11562 DEFUN (no_ip_lcommunity_list_name_expanded_all,
11563 no_ip_lcommunity_list_name_expanded_all_cmd,
11564 "no ip large-community-list expanded WORD",
11565 NO_STR
11566 IP_STR
11567 LCOMMUNITY_LIST_STR
11568 "Specify expanded large-community-list\n"
11569 "Large Community list name\n")
11570 {
11571 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
11572 }
11573
11574 DEFUN (no_ip_lcommunity_list_standard,
11575 no_ip_lcommunity_list_standard_cmd,
11576 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
11577 NO_STR
11578 IP_STR
11579 LCOMMUNITY_LIST_STR
11580 "Large Community list number (standard)\n"
11581 "Specify large community to reject\n"
11582 "Specify large community to accept\n"
11583 LCOMMUNITY_VAL_STR)
11584 {
11585 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
11586 }
11587
11588 DEFUN (no_ip_lcommunity_list_expanded,
11589 no_ip_lcommunity_list_expanded_cmd,
11590 "no ip large-community-list (100-500) <deny|permit> LINE...",
11591 NO_STR
11592 IP_STR
11593 LCOMMUNITY_LIST_STR
11594 "Large Community list number (expanded)\n"
11595 "Specify large community to reject\n"
11596 "Specify large community to accept\n"
11597 "An ordered list as a regular-expression\n")
11598 {
11599 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
11600 }
11601
11602 DEFUN (no_ip_lcommunity_list_name_standard,
11603 no_ip_lcommunity_list_name_standard_cmd,
11604 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
11605 NO_STR
11606 IP_STR
11607 LCOMMUNITY_LIST_STR
11608 "Specify standard large-community-list\n"
11609 "Large Community list name\n"
11610 "Specify large community to reject\n"
11611 "Specify large community to accept\n"
11612 LCOMMUNITY_VAL_STR)
11613 {
11614 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
11615 }
11616
11617 DEFUN (no_ip_lcommunity_list_name_expanded,
11618 no_ip_lcommunity_list_name_expanded_cmd,
11619 "no ip large-community-list expanded WORD <deny|permit> LINE...",
11620 NO_STR
11621 IP_STR
11622 LCOMMUNITY_LIST_STR
11623 "Specify expanded large-community-list\n"
11624 "Large community list name\n"
11625 "Specify large community to reject\n"
11626 "Specify large community to accept\n"
11627 "An ordered list as a regular-expression\n")
11628 {
11629 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
11630 }
11631
11632 static void
11633 lcommunity_list_show (struct vty *vty, struct community_list *list)
11634 {
11635 struct community_entry *entry;
11636
11637 for (entry = list->head; entry; entry = entry->next)
11638 {
11639 if (entry == list->head)
11640 {
11641 if (all_digit (list->name))
11642 vty_out (vty, "Large community %s list %s%s",
11643 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11644 "standard" : "(expanded) access",
11645 list->name, VTY_NEWLINE);
11646 else
11647 vty_out (vty, "Named large community %s list %s%s",
11648 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11649 "standard" : "expanded",
11650 list->name, VTY_NEWLINE);
11651 }
11652 if (entry->any)
11653 vty_out (vty, " %s%s",
11654 community_direct_str (entry->direct), VTY_NEWLINE);
11655 else
11656 vty_out (vty, " %s %s%s",
11657 community_direct_str (entry->direct),
11658 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11659 entry->u.ecom->str : entry->config,
11660 VTY_NEWLINE);
11661 }
11662 }
11663
11664 DEFUN (show_ip_lcommunity_list,
11665 show_ip_lcommunity_list_cmd,
11666 "show ip large-community-list",
11667 SHOW_STR
11668 IP_STR
11669 "List large-community list\n")
11670 {
11671 struct community_list *list;
11672 struct community_list_master *cm;
11673
11674 cm = community_list_master_lookup (bgp_clist, LARGE_COMMUNITY_LIST_MASTER);
11675 if (! cm)
11676 return CMD_SUCCESS;
11677
11678 for (list = cm->num.head; list; list = list->next)
11679 lcommunity_list_show (vty, list);
11680
11681 for (list = cm->str.head; list; list = list->next)
11682 lcommunity_list_show (vty, list);
11683
11684 return CMD_SUCCESS;
11685 }
11686
11687 DEFUN (show_ip_lcommunity_list_arg,
11688 show_ip_lcommunity_list_arg_cmd,
11689 "show ip large-community-list <(1-500)|WORD>",
11690 SHOW_STR
11691 IP_STR
11692 "List large-community list\n"
11693 "large-community-list number\n"
11694 "large-community-list name\n")
11695 {
11696 struct community_list *list;
11697
11698 list = community_list_lookup (bgp_clist, argv[3]->arg, LARGE_COMMUNITY_LIST_MASTER);
11699 if (! list)
11700 {
11701 vty_out (vty, "%% Can't find extcommunity-list%s", VTY_NEWLINE);
11702 return CMD_WARNING;
11703 }
11704
11705 lcommunity_list_show (vty, list);
11706
11707 return CMD_SUCCESS;
11708 }
11709
11710 /* "extcommunity-list" keyword help string. */
11711 #define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
11712 #define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
11713
11714 DEFUN (ip_extcommunity_list_standard,
11715 ip_extcommunity_list_standard_cmd,
11716 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
11717 IP_STR
11718 EXTCOMMUNITY_LIST_STR
11719 "Extended Community list number (standard)\n"
11720 "Specify standard extcommunity-list\n"
11721 "Community list name\n"
11722 "Specify community to reject\n"
11723 "Specify community to accept\n"
11724 EXTCOMMUNITY_VAL_STR)
11725 {
11726 int style = EXTCOMMUNITY_LIST_STANDARD;
11727 int direct = 0;
11728 char *cl_number_or_name = NULL;
11729
11730 int idx = 0;
11731 argv_find (argv, argc, "(1-99)", &idx);
11732 argv_find (argv, argc, "WORD", &idx);
11733 cl_number_or_name = argv[idx]->arg;
11734 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11735 argv_find (argv, argc, "AA:NN", &idx);
11736 char *str = argv_concat (argv, argc, idx);
11737
11738 int ret = extcommunity_list_set (bgp_clist, cl_number_or_name, str, direct, style);
11739
11740 XFREE (MTYPE_TMP, str);
11741
11742 if (ret < 0)
11743 {
11744 community_list_perror (vty, ret);
11745 return CMD_WARNING;
11746 }
11747
11748 return CMD_SUCCESS;
11749 }
11750
11751 DEFUN (ip_extcommunity_list_name_expanded,
11752 ip_extcommunity_list_name_expanded_cmd,
11753 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
11754 IP_STR
11755 EXTCOMMUNITY_LIST_STR
11756 "Extended Community list number (expanded)\n"
11757 "Specify expanded extcommunity-list\n"
11758 "Extended Community list name\n"
11759 "Specify community to reject\n"
11760 "Specify community to accept\n"
11761 "An ordered list as a regular-expression\n")
11762 {
11763 int style = EXTCOMMUNITY_LIST_EXPANDED;
11764 int direct = 0;
11765 char *cl_number_or_name = NULL;
11766
11767 int idx = 0;
11768 argv_find (argv, argc, "(100-500)", &idx);
11769 argv_find (argv, argc, "WORD", &idx);
11770 cl_number_or_name = argv[idx]->arg;
11771 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11772 argv_find (argv, argc, "LINE", &idx);
11773 char *str = argv_concat (argv, argc, idx);
11774
11775 int ret = extcommunity_list_set (bgp_clist, cl_number_or_name, str, direct, style);
11776
11777 XFREE (MTYPE_TMP, str);
11778
11779 if (ret < 0)
11780 {
11781 community_list_perror (vty, ret);
11782 return CMD_WARNING;
11783 }
11784
11785 return CMD_SUCCESS;
11786 }
11787
11788 DEFUN (no_ip_extcommunity_list_standard_all,
11789 no_ip_extcommunity_list_standard_all_cmd,
11790 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
11791 NO_STR
11792 IP_STR
11793 EXTCOMMUNITY_LIST_STR
11794 "Extended Community list number (standard)\n"
11795 "Specify standard extcommunity-list\n"
11796 "Community list name\n"
11797 "Specify community to reject\n"
11798 "Specify community to accept\n"
11799 EXTCOMMUNITY_VAL_STR)
11800 {
11801 int deleteall = 0;
11802
11803 int style = EXTCOMMUNITY_LIST_STANDARD;
11804 int direct = 0;
11805 char *cl_number_or_name = NULL;
11806
11807 int idx = 0;
11808 argv_find (argv, argc, "(1-99)", &idx);
11809 argv_find (argv, argc, "WORD", &idx);
11810 cl_number_or_name = argv[idx]->arg;
11811 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11812 argv_find (argv, argc, "AA:NN", &idx);
11813 char *str = argv_concat (argv, argc, idx);
11814
11815 int ret = extcommunity_list_unset (bgp_clist, cl_number_or_name, str, direct, style, deleteall);
11816
11817 XFREE (MTYPE_TMP, str);
11818
11819 if (ret < 0)
11820 {
11821 community_list_perror (vty, ret);
11822 return CMD_WARNING;
11823 }
11824
11825 return CMD_SUCCESS;
11826 }
11827
11828 DEFUN (no_ip_extcommunity_list_expanded_all,
11829 no_ip_extcommunity_list_expanded_all_cmd,
11830 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
11831 NO_STR
11832 IP_STR
11833 EXTCOMMUNITY_LIST_STR
11834 "Extended Community list number (expanded)\n"
11835 "Specify expanded extcommunity-list\n"
11836 "Extended Community list name\n"
11837 "Specify community to reject\n"
11838 "Specify community to accept\n"
11839 "An ordered list as a regular-expression\n")
11840 {
11841 int deleteall = 0;
11842
11843 int style = EXTCOMMUNITY_LIST_EXPANDED;
11844 int direct = 0;
11845 char *cl_number_or_name = NULL;
11846
11847 int idx = 0;
11848 argv_find (argv, argc, "(100-500)", &idx);
11849 argv_find (argv, argc, "WORD", &idx);
11850 cl_number_or_name = argv[idx]->arg;
11851 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
11852 argv_find (argv, argc, "LINE", &idx);
11853 char *str = argv_concat (argv, argc, idx);
11854
11855 int ret = extcommunity_list_unset (bgp_clist, cl_number_or_name, str, direct, style, deleteall);
11856
11857 XFREE (MTYPE_TMP, str);
11858
11859 if (ret < 0)
11860 {
11861 community_list_perror (vty, ret);
11862 return CMD_WARNING;
11863 }
11864
11865 return CMD_SUCCESS;
11866 }
11867
11868 static void
11869 extcommunity_list_show (struct vty *vty, struct community_list *list)
11870 {
11871 struct community_entry *entry;
11872
11873 for (entry = list->head; entry; entry = entry->next)
11874 {
11875 if (entry == list->head)
11876 {
11877 if (all_digit (list->name))
11878 vty_out (vty, "Extended community %s list %s%s",
11879 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11880 "standard" : "(expanded) access",
11881 list->name, VTY_NEWLINE);
11882 else
11883 vty_out (vty, "Named extended community %s list %s%s",
11884 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11885 "standard" : "expanded",
11886 list->name, VTY_NEWLINE);
11887 }
11888 if (entry->any)
11889 vty_out (vty, " %s%s",
11890 community_direct_str (entry->direct), VTY_NEWLINE);
11891 else
11892 vty_out (vty, " %s %s%s",
11893 community_direct_str (entry->direct),
11894 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11895 entry->u.ecom->str : entry->config,
11896 VTY_NEWLINE);
11897 }
11898 }
11899
11900 DEFUN (show_ip_extcommunity_list,
11901 show_ip_extcommunity_list_cmd,
11902 "show ip extcommunity-list",
11903 SHOW_STR
11904 IP_STR
11905 "List extended-community list\n")
11906 {
11907 struct community_list *list;
11908 struct community_list_master *cm;
11909
11910 cm = community_list_master_lookup (bgp_clist, EXTCOMMUNITY_LIST_MASTER);
11911 if (! cm)
11912 return CMD_SUCCESS;
11913
11914 for (list = cm->num.head; list; list = list->next)
11915 extcommunity_list_show (vty, list);
11916
11917 for (list = cm->str.head; list; list = list->next)
11918 extcommunity_list_show (vty, list);
11919
11920 return CMD_SUCCESS;
11921 }
11922
11923 DEFUN (show_ip_extcommunity_list_arg,
11924 show_ip_extcommunity_list_arg_cmd,
11925 "show ip extcommunity-list <(1-500)|WORD>",
11926 SHOW_STR
11927 IP_STR
11928 "List extended-community list\n"
11929 "Extcommunity-list number\n"
11930 "Extcommunity-list name\n")
11931 {
11932 int idx_comm_list = 3;
11933 struct community_list *list;
11934
11935 list = community_list_lookup (bgp_clist, argv[idx_comm_list]->arg, EXTCOMMUNITY_LIST_MASTER);
11936 if (! list)
11937 {
11938 vty_out (vty, "%% Can't find extcommunity-list%s", VTY_NEWLINE);
11939 return CMD_WARNING;
11940 }
11941
11942 extcommunity_list_show (vty, list);
11943
11944 return CMD_SUCCESS;
11945 }
11946
11947 /* Return configuration string of community-list entry. */
11948 static const char *
11949 community_list_config_str (struct community_entry *entry)
11950 {
11951 const char *str;
11952
11953 if (entry->any)
11954 str = "";
11955 else
11956 {
11957 if (entry->style == COMMUNITY_LIST_STANDARD)
11958 str = community_str (entry->u.com);
11959 else
11960 str = entry->config;
11961 }
11962 return str;
11963 }
11964
11965 /* Display community-list and extcommunity-list configuration. */
11966 static int
11967 community_list_config_write (struct vty *vty)
11968 {
11969 struct community_list *list;
11970 struct community_entry *entry;
11971 struct community_list_master *cm;
11972 int write = 0;
11973
11974 /* Community-list. */
11975 cm = community_list_master_lookup (bgp_clist, COMMUNITY_LIST_MASTER);
11976
11977 for (list = cm->num.head; list; list = list->next)
11978 for (entry = list->head; entry; entry = entry->next)
11979 {
11980 vty_out (vty, "ip community-list %s %s %s%s",
11981 list->name, community_direct_str (entry->direct),
11982 community_list_config_str (entry),
11983 VTY_NEWLINE);
11984 write++;
11985 }
11986 for (list = cm->str.head; list; list = list->next)
11987 for (entry = list->head; entry; entry = entry->next)
11988 {
11989 vty_out (vty, "ip community-list %s %s %s %s%s",
11990 entry->style == COMMUNITY_LIST_STANDARD
11991 ? "standard" : "expanded",
11992 list->name, community_direct_str (entry->direct),
11993 community_list_config_str (entry),
11994 VTY_NEWLINE);
11995 write++;
11996 }
11997
11998 /* Extcommunity-list. */
11999 cm = community_list_master_lookup (bgp_clist, EXTCOMMUNITY_LIST_MASTER);
12000
12001 for (list = cm->num.head; list; list = list->next)
12002 for (entry = list->head; entry; entry = entry->next)
12003 {
12004 vty_out (vty, "ip extcommunity-list %s %s %s%s",
12005 list->name, community_direct_str (entry->direct),
12006 community_list_config_str (entry), VTY_NEWLINE);
12007 write++;
12008 }
12009 for (list = cm->str.head; list; list = list->next)
12010 for (entry = list->head; entry; entry = entry->next)
12011 {
12012 vty_out (vty, "ip extcommunity-list %s %s %s %s%s",
12013 entry->style == EXTCOMMUNITY_LIST_STANDARD
12014 ? "standard" : "expanded",
12015 list->name, community_direct_str (entry->direct),
12016 community_list_config_str (entry), VTY_NEWLINE);
12017 write++;
12018 }
12019
12020
12021 /* lcommunity-list. */
12022 cm = community_list_master_lookup (bgp_clist, LARGE_COMMUNITY_LIST_MASTER);
12023
12024 for (list = cm->num.head; list; list = list->next)
12025 for (entry = list->head; entry; entry = entry->next)
12026 {
12027 vty_out (vty, "ip large-community-list %s %s %s%s",
12028 list->name, community_direct_str (entry->direct),
12029 community_list_config_str (entry), VTY_NEWLINE);
12030 write++;
12031 }
12032 for (list = cm->str.head; list; list = list->next)
12033 for (entry = list->head; entry; entry = entry->next)
12034 {
12035 vty_out (vty, "ip large-community-list %s %s %s %s%s",
12036 entry->style == LARGE_COMMUNITY_LIST_STANDARD
12037 ? "standard" : "expanded",
12038 list->name, community_direct_str (entry->direct),
12039 community_list_config_str (entry), VTY_NEWLINE);
12040 write++;
12041 }
12042
12043 return write;
12044 }
12045
12046 static struct cmd_node community_list_node =
12047 {
12048 COMMUNITY_LIST_NODE,
12049 "",
12050 1 /* Export to vtysh. */
12051 };
12052
12053 static void
12054 community_list_vty (void)
12055 {
12056 install_node (&community_list_node, community_list_config_write);
12057
12058 /* Community-list. */
12059 install_element (CONFIG_NODE, &ip_community_list_standard_cmd);
12060 install_element (CONFIG_NODE, &ip_community_list_expanded_all_cmd);
12061 install_element (CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
12062 install_element (CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
12063 install_element (VIEW_NODE, &show_ip_community_list_cmd);
12064 install_element (VIEW_NODE, &show_ip_community_list_arg_cmd);
12065
12066 /* Extcommunity-list. */
12067 install_element (CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
12068 install_element (CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
12069 install_element (CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
12070 install_element (CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
12071 install_element (VIEW_NODE, &show_ip_extcommunity_list_cmd);
12072 install_element (VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
12073
12074 /* Large Community List */
12075 install_element (CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
12076 install_element (CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
12077 install_element (CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
12078 install_element (CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
12079 install_element (CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
12080 install_element (CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
12081 install_element (CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
12082 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_all_cmd);
12083 install_element (CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
12084 install_element (CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
12085 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
12086 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
12087 install_element (VIEW_NODE, &show_ip_lcommunity_list_cmd);
12088 install_element (VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
12089 }