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