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