]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: Unify `show bgp` and `show ip bgp` trees
[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 6017 "Clear bestpath and re-advertise\n"
0c7b1b01 6018 "IPv4 prefix\n")
8ad7271d 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;
0c7b1b01 6028
630a298c 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"
0c7b1b01 6042 "IPv6 prefix\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"
0c7b1b01 6061 "IPv6 prefix\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,
d6e3c605 6074 "show [ip] bgp views",
b09b5ae0 6075 SHOW_STR
d6e3c605 6076 IP_STR
01080f7c 6077 BGP_STR
b09b5ae0 6078 "Show the defined BGP views\n")
01080f7c 6079{
b09b5ae0
DW
6080 struct list *inst = bm->bgp;
6081 struct listnode *node;
6082 struct bgp *bgp;
01080f7c 6083
b09b5ae0
DW
6084 if (!bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
6085 {
6086 vty_out (vty, "BGP Multiple Instance is not enabled%s", VTY_NEWLINE);
6087 return CMD_WARNING;
6088 }
e52702f2 6089
b09b5ae0
DW
6090 vty_out (vty, "Defined BGP views:%s", VTY_NEWLINE);
6091 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp))
6092 {
6093 /* Skip VRFs. */
6094 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6095 continue;
6096 vty_out (vty, "\t%s (AS%u)%s",
6097 bgp->name ? bgp->name : "(null)",
6098 bgp->as, VTY_NEWLINE);
6099 }
e52702f2 6100
b09b5ae0 6101 return CMD_SUCCESS;
e0081f70
ML
6102}
6103
8386ac43 6104DEFUN (show_bgp_vrfs,
6105 show_bgp_vrfs_cmd,
d6e3c605 6106 "show [ip] bgp vrfs [json]",
8386ac43 6107 SHOW_STR
d6e3c605 6108 IP_STR
8386ac43 6109 BGP_STR
6110 "Show BGP VRFs\n"
6111 "JavaScript Object Notation\n")
6112{
6113 struct list *inst = bm->bgp;
6114 struct listnode *node;
6115 struct bgp *bgp;
6116 u_char uj = use_json(argc, argv);
6117 json_object *json = NULL;
6118 json_object *json_vrfs = NULL;
6119 int count = 0;
6120 static char header[] = "Type Id RouterId #PeersCfg #PeersEstb Name";
6121
6122 if (!bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
6123 {
6124 vty_out (vty, "BGP Multiple Instance is not enabled%s", VTY_NEWLINE);
6125 return CMD_WARNING;
6126 }
6127
6128 if (uj)
6129 {
6130 json = json_object_new_object();
6131 json_vrfs = json_object_new_object();
6132 }
6133
6134 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp))
6135 {
6136 const char *name, *type;
6137 struct peer *peer;
6138 struct listnode *node, *nnode;
6139 int peers_cfg, peers_estb;
6140 json_object *json_vrf = NULL;
5c81a5f3 6141 int vrf_id_ui;
8386ac43 6142
6143 /* Skip Views. */
6144 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6145 continue;
6146
6147 count++;
6148 if (!uj && count == 1)
6149 vty_out (vty, "%s%s", header, VTY_NEWLINE);
6150
6151 peers_cfg = peers_estb = 0;
6152 if (uj)
6153 json_vrf = json_object_new_object();
6154
6155
6156 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6157 {
6158 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6159 continue;
6160 peers_cfg++;
6161 if (peer->status == Established)
6162 peers_estb++;
6163 }
6164
6165 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6166 {
6167 name = "Default";
6168 type = "DFLT";
6169 }
6170 else
6171 {
6172 name = bgp->name;
6173 type = "VRF";
6174 }
6175
5c81a5f3 6176 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
8386ac43 6177 if (uj)
6178 {
6179 json_object_string_add(json_vrf, "type", type);
5c81a5f3 6180 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8386ac43 6181 json_object_string_add(json_vrf, "routerId", inet_ntoa (bgp->router_id));
6182 json_object_int_add(json_vrf, "numConfiguredPeers", peers_cfg);
6183 json_object_int_add(json_vrf, "numEstablishedPeers", peers_estb);
6184
6185 json_object_object_add(json_vrfs, name, json_vrf);
6186 }
6187 else
5c81a5f3 6188 vty_out (vty, "%4s %-5d %-16s %9u %10u %s%s",
6189 type, vrf_id_ui, inet_ntoa (bgp->router_id),
8386ac43 6190 peers_cfg, peers_estb, name,
6191 VTY_NEWLINE);
6192 }
6193
6194 if (uj)
6195 {
6196 json_object_object_add(json, "vrfs", json_vrfs);
6197
6198 json_object_int_add(json, "totalVrfs", count);
6199
2aac5767 6200 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8386ac43 6201 json_object_free(json);
6202 }
6203 else
6204 {
6205 if (count)
6206 vty_out (vty, "%sTotal number of VRFs (including default): %d%s",
6207 VTY_NEWLINE, count, VTY_NEWLINE);
6208 }
6209
6210 return CMD_SUCCESS;
6211}
6212
f412b39a 6213DEFUN (show_bgp_memory,
4bf6a362
PJ
6214 show_bgp_memory_cmd,
6215 "show bgp memory",
6216 SHOW_STR
6217 BGP_STR
6218 "Global BGP memory statistics\n")
6219{
6220 char memstrbuf[MTYPE_MEMSTR_LEN];
6221 unsigned long count;
e52702f2 6222
4bf6a362
PJ
6223 /* RIB related usage stats */
6224 count = mtype_stats_alloc (MTYPE_BGP_NODE);
6225 vty_out (vty, "%ld RIB nodes, using %s of memory%s", count,
6226 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6227 count * sizeof (struct bgp_node)),
6228 VTY_NEWLINE);
e52702f2 6229
4bf6a362
PJ
6230 count = mtype_stats_alloc (MTYPE_BGP_ROUTE);
6231 vty_out (vty, "%ld BGP routes, using %s of memory%s", count,
6232 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6233 count * sizeof (struct bgp_info)),
6234 VTY_NEWLINE);
fb982c25
PJ
6235 if ((count = mtype_stats_alloc (MTYPE_BGP_ROUTE_EXTRA)))
6236 vty_out (vty, "%ld BGP route ancillaries, using %s of memory%s", count,
6237 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6238 count * sizeof (struct bgp_info_extra)),
6239 VTY_NEWLINE);
e52702f2 6240
4bf6a362
PJ
6241 if ((count = mtype_stats_alloc (MTYPE_BGP_STATIC)))
6242 vty_out (vty, "%ld Static routes, using %s of memory%s", count,
6243 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6244 count * sizeof (struct bgp_static)),
6245 VTY_NEWLINE);
3f9c7369
DS
6246
6247 if ((count = mtype_stats_alloc (MTYPE_BGP_PACKET)))
6248 vty_out (vty, "%ld Packets, using %s of memory%s", count,
6249 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6250 count * sizeof (struct bpacket)),
6251 VTY_NEWLINE);
e52702f2 6252
4bf6a362
PJ
6253 /* Adj-In/Out */
6254 if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_IN)))
6255 vty_out (vty, "%ld Adj-In entries, using %s of memory%s", count,
6256 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6257 count * sizeof (struct bgp_adj_in)),
6258 VTY_NEWLINE);
6259 if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_OUT)))
6260 vty_out (vty, "%ld Adj-Out entries, using %s of memory%s", count,
6261 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6262 count * sizeof (struct bgp_adj_out)),
6263 VTY_NEWLINE);
e52702f2 6264
4bf6a362
PJ
6265 if ((count = mtype_stats_alloc (MTYPE_BGP_NEXTHOP_CACHE)))
6266 vty_out (vty, "%ld Nexthop cache entries, using %s of memory%s", count,
6267 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6268 count * sizeof (struct bgp_nexthop_cache)),
6269 VTY_NEWLINE);
6270
6271 if ((count = mtype_stats_alloc (MTYPE_BGP_DAMP_INFO)))
6272 vty_out (vty, "%ld Dampening entries, using %s of memory%s", count,
6273 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6274 count * sizeof (struct bgp_damp_info)),
6275 VTY_NEWLINE);
6276
6277 /* Attributes */
6278 count = attr_count();
e52702f2
QY
6279 vty_out (vty, "%ld BGP attributes, using %s of memory%s", count,
6280 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6281 count * sizeof(struct attr)),
4bf6a362 6282 VTY_NEWLINE);
fb982c25 6283 if ((count = mtype_stats_alloc (MTYPE_ATTR_EXTRA)))
e52702f2
QY
6284 vty_out (vty, "%ld BGP extra attributes, using %s of memory%s", count,
6285 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6286 count * sizeof(struct attr_extra)),
fb982c25 6287 VTY_NEWLINE);
e52702f2 6288
4bf6a362
PJ
6289 if ((count = attr_unknown_count()))
6290 vty_out (vty, "%ld unknown attributes%s", count, VTY_NEWLINE);
e52702f2 6291
4bf6a362
PJ
6292 /* AS_PATH attributes */
6293 count = aspath_count ();
6294 vty_out (vty, "%ld BGP AS-PATH entries, using %s of memory%s", count,
6295 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6296 count * sizeof (struct aspath)),
6297 VTY_NEWLINE);
e52702f2 6298
4bf6a362
PJ
6299 count = mtype_stats_alloc (MTYPE_AS_SEG);
6300 vty_out (vty, "%ld BGP AS-PATH segments, using %s of memory%s", count,
6301 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6302 count * sizeof (struct assegment)),
6303 VTY_NEWLINE);
e52702f2 6304
4bf6a362
PJ
6305 /* Other attributes */
6306 if ((count = community_count ()))
6307 vty_out (vty, "%ld BGP community entries, using %s of memory%s", count,
6308 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6309 count * sizeof (struct community)),
6310 VTY_NEWLINE);
6311 if ((count = mtype_stats_alloc (MTYPE_ECOMMUNITY)))
6312 vty_out (vty, "%ld BGP community entries, using %s of memory%s", count,
6313 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6314 count * sizeof (struct ecommunity)),
6315 VTY_NEWLINE);
e52702f2 6316
4bf6a362
PJ
6317 if ((count = mtype_stats_alloc (MTYPE_CLUSTER)))
6318 vty_out (vty, "%ld Cluster lists, using %s of memory%s", count,
6319 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6320 count * sizeof (struct cluster_list)),
6321 VTY_NEWLINE);
e52702f2 6322
4bf6a362
PJ
6323 /* Peer related usage */
6324 count = mtype_stats_alloc (MTYPE_BGP_PEER);
6325 vty_out (vty, "%ld peers, using %s of memory%s", count,
6326 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6327 count * sizeof (struct peer)),
6328 VTY_NEWLINE);
e52702f2 6329
4a1ab8e4 6330 if ((count = mtype_stats_alloc (MTYPE_PEER_GROUP)))
4bf6a362
PJ
6331 vty_out (vty, "%ld peer groups, using %s of memory%s", count,
6332 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6333 count * sizeof (struct peer_group)),
6334 VTY_NEWLINE);
e52702f2 6335
4bf6a362
PJ
6336 /* Other */
6337 if ((count = mtype_stats_alloc (MTYPE_HASH)))
6338 vty_out (vty, "%ld hash tables, using %s of memory%s", count,
6339 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6340 count * sizeof (struct hash)),
6341 VTY_NEWLINE);
6342 if ((count = mtype_stats_alloc (MTYPE_HASH_BACKET)))
6343 vty_out (vty, "%ld hash buckets, using %s of memory%s", count,
6344 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6345 count * sizeof (struct hash_backet)),
6346 VTY_NEWLINE);
6347 if ((count = mtype_stats_alloc (MTYPE_BGP_REGEXP)))
6348 vty_out (vty, "%ld compiled regexes, using %s of memory%s", count,
6349 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6350 count * sizeof (regex_t)),
6351 VTY_NEWLINE);
6352 return CMD_SUCCESS;
6353}
fee0f4c6 6354
718e3744 6355/* Show BGP peer's summary information. */
94f2b392 6356static int
b05a1c8b 6357bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
9f689658 6358 u_char use_json, json_object *json)
718e3744 6359{
6360 struct peer *peer;
1eb8ef25 6361 struct listnode *node, *nnode;
f14e6fdb
DS
6362 unsigned int count = 0, dn_count = 0;
6363 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
f933309e
DW
6364 char neighbor_buf[VTY_BUFSIZ];
6365 int neighbor_col_default_width = 16;
718e3744 6366 int len;
f933309e 6367 int max_neighbor_width = 0;
ffd0c037
DS
6368 json_object *json_peer = NULL;
6369 json_object *json_peers = NULL;
718e3744 6370
b05a1c8b
DS
6371 if (use_json)
6372 {
9f689658
DD
6373 if (json == NULL)
6374 json = json_object_new_object();
6375
f1aa5d8a 6376 json_peers = json_object_new_object();
b05a1c8b 6377 }
f933309e
DW
6378 else
6379 {
6380 /* Loop over all neighbors that will be displayed to determine how many
6381 * characters are needed for the Neighbor column
6382 */
6383 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6384 {
6385 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6386 continue;
6387
6388 if (peer->afc[afi][safi])
6389 {
6390 if (peer->hostname && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
6391 sprintf(neighbor_buf, "%s%s(%s) ", dn_flag, peer->hostname, peer->host);
6392 else
6393 sprintf(neighbor_buf, "%s%s ", dn_flag, peer->host);
6394
6395 len = strlen(neighbor_buf);
6396
6397 if (len > max_neighbor_width)
6398 max_neighbor_width = len;
6399 }
6400 }
6401
6402 /* Originally we displayed the Neighbor column as 16
6403 * characters wide so make that the default
6404 */
6405 if (max_neighbor_width < neighbor_col_default_width)
6406 max_neighbor_width = neighbor_col_default_width;
6407 }
b05a1c8b 6408
1eb8ef25 6409 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 6410 {
1ff9a340
DS
6411 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6412 continue;
6413
718e3744 6414 if (peer->afc[afi][safi])
6415 {
b05a1c8b 6416 if (!count)
4bf6a362
PJ
6417 {
6418 unsigned long ents;
6419 char memstrbuf[MTYPE_MEMSTR_LEN];
5c81a5f3 6420 int vrf_id_ui;
6421
6422 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
b05a1c8b 6423
4bf6a362 6424 /* Usage summary and header */
b05a1c8b
DS
6425 if (use_json)
6426 {
62d6dca0 6427 json_object_string_add(json, "routerId", inet_ntoa (bgp->router_id));
f1aa5d8a 6428 json_object_int_add(json, "as", bgp->as);
9f689658
DD
6429 json_object_int_add(json, "vrfId", vrf_id_ui);
6430 json_object_string_add(json, "vrfName",
6431 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6432 ? "Default" : bgp->name);
b05a1c8b
DS
6433 }
6434 else
6435 {
6436 vty_out (vty,
5c81a5f3 6437 "BGP router identifier %s, local AS number %u vrf-id %d",
6438 inet_ntoa (bgp->router_id), bgp->as, vrf_id_ui);
6aeb9e78 6439 vty_out (vty, "%s", VTY_NEWLINE);
b05a1c8b
DS
6440 }
6441
f188f2c4
DS
6442 if (bgp_update_delay_configured(bgp))
6443 {
b05a1c8b 6444 if (use_json)
f188f2c4 6445 {
62d6dca0 6446 json_object_int_add(json, "updateDelayLimit", bgp->v_update_delay);
b05a1c8b
DS
6447
6448 if (bgp->v_update_delay != bgp->v_establish_wait)
62d6dca0 6449 json_object_int_add(json, "updateDelayEstablishWait", bgp->v_establish_wait);
b05a1c8b
DS
6450
6451 if (bgp_update_delay_active(bgp))
6452 {
62d6dca0
DS
6453 json_object_string_add(json, "updateDelayFirstNeighbor", bgp->update_delay_begin_time);
6454 json_object_boolean_true_add(json, "updateDelayInProgress");
b05a1c8b
DS
6455 }
6456 else
6457 {
6458 if (bgp->update_delay_over)
6459 {
62d6dca0 6460 json_object_string_add(json, "updateDelayFirstNeighbor",
f1aa5d8a 6461 bgp->update_delay_begin_time);
62d6dca0 6462 json_object_string_add(json, "updateDelayBestpathResumed",
f1aa5d8a 6463 bgp->update_delay_end_time);
62d6dca0 6464 json_object_string_add(json, "updateDelayZebraUpdateResume",
f1aa5d8a 6465 bgp->update_delay_zebra_resume_time);
62d6dca0 6466 json_object_string_add(json, "updateDelayPeerUpdateResume",
f1aa5d8a 6467 bgp->update_delay_peers_resume_time);
b05a1c8b
DS
6468 }
6469 }
f188f2c4
DS
6470 }
6471 else
6472 {
b05a1c8b
DS
6473 vty_out (vty, "Read-only mode update-delay limit: %d seconds%s",
6474 bgp->v_update_delay, VTY_NEWLINE);
6475 if (bgp->v_update_delay != bgp->v_establish_wait)
6476 vty_out (vty, " Establish wait: %d seconds%s",
6477 bgp->v_establish_wait, VTY_NEWLINE);
6478
6479 if (bgp_update_delay_active(bgp))
f188f2c4
DS
6480 {
6481 vty_out (vty, " First neighbor established: %s%s",
6482 bgp->update_delay_begin_time, VTY_NEWLINE);
b05a1c8b
DS
6483 vty_out (vty, " Delay in progress%s", VTY_NEWLINE);
6484 }
6485 else
6486 {
6487 if (bgp->update_delay_over)
6488 {
6489 vty_out (vty, " First neighbor established: %s%s",
6490 bgp->update_delay_begin_time, VTY_NEWLINE);
6491 vty_out (vty, " Best-paths resumed: %s%s",
6492 bgp->update_delay_end_time, VTY_NEWLINE);
6493 vty_out (vty, " zebra update resumed: %s%s",
6494 bgp->update_delay_zebra_resume_time, VTY_NEWLINE);
6495 vty_out (vty, " peers update resumed: %s%s",
6496 bgp->update_delay_peers_resume_time, VTY_NEWLINE);
6497 }
f188f2c4
DS
6498 }
6499 }
6500 }
4bf6a362 6501
b05a1c8b
DS
6502 if (use_json)
6503 {
6504 if (bgp_maxmed_onstartup_configured(bgp) && bgp->maxmed_active)
62d6dca0 6505 json_object_boolean_true_add(json, "maxMedOnStartup");
b05a1c8b 6506 if (bgp->v_maxmed_admin)
62d6dca0 6507 json_object_boolean_true_add(json, "maxMedAdministrative");
b05a1c8b 6508
62d6dca0 6509 json_object_int_add(json, "tableVersion", bgp_table_version(bgp->rib[afi][safi]));
b05a1c8b
DS
6510
6511 ents = bgp_table_count (bgp->rib[afi][safi]);
62d6dca0
DS
6512 json_object_int_add(json, "ribCount", ents);
6513 json_object_int_add(json, "ribMemory", ents * sizeof (struct bgp_node));
b05a1c8b
DS
6514
6515 ents = listcount (bgp->peer);
62d6dca0
DS
6516 json_object_int_add(json, "peerCount", ents);
6517 json_object_int_add(json, "peerMemory", ents * sizeof (struct peer));
b05a1c8b 6518
b05a1c8b
DS
6519 if ((ents = listcount (bgp->group)))
6520 {
62d6dca0
DS
6521 json_object_int_add(json, "peerGroupCount", ents);
6522 json_object_int_add(json, "peerGroupMemory", ents * sizeof (struct peer_group));
b05a1c8b 6523 }
3f9c7369 6524
b05a1c8b 6525 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
62d6dca0 6526 json_object_boolean_true_add(json, "dampeningEnabled");
b05a1c8b
DS
6527 }
6528 else
6529 {
6530 if (bgp_maxmed_onstartup_configured(bgp) && bgp->maxmed_active)
6531 vty_out (vty, "Max-med on-startup active%s", VTY_NEWLINE);
6532 if (bgp->v_maxmed_admin)
6533 vty_out (vty, "Max-med administrative active%s", VTY_NEWLINE);
6534
ffd0c037 6535 vty_out(vty, "BGP table version %" PRIu64 "%s",
b05a1c8b
DS
6536 bgp_table_version(bgp->rib[afi][safi]), VTY_NEWLINE);
6537
6538 ents = bgp_table_count (bgp->rib[afi][safi]);
6539 vty_out (vty, "RIB entries %ld, using %s of memory%s", ents,
6540 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6541 ents * sizeof (struct bgp_node)),
6542 VTY_NEWLINE);
6543
6544 /* Peer related usage */
6545 ents = listcount (bgp->peer);
6546 vty_out (vty, "Peers %ld, using %s of memory%s",
6547 ents,
6548 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6549 ents * sizeof (struct peer)),
6550 VTY_NEWLINE);
6551
b05a1c8b
DS
6552 if ((ents = listcount (bgp->group)))
6553 vty_out (vty, "Peer groups %ld, using %s of memory%s", ents,
6554 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6555 ents * sizeof (struct peer_group)),
6556 VTY_NEWLINE);
6557
6558 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
6559 vty_out (vty, "Dampening enabled.%s", VTY_NEWLINE);
6560 vty_out (vty, "%s", VTY_NEWLINE);
f933309e
DW
6561
6562 /* Subtract 8 here because 'Neighbor' is 8 characters */
6563 vty_out (vty, "Neighbor");
6564 vty_out (vty, "%*s", max_neighbor_width - 8, " ");
6565 vty_out (vty, "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd%s", VTY_NEWLINE);
b05a1c8b 6566 }
4bf6a362 6567 }
e52702f2 6568
b05a1c8b 6569 count++;
718e3744 6570
b05a1c8b
DS
6571 if (use_json)
6572 {
6573 json_peer = json_object_new_object();
f14e6fdb 6574
b05a1c8b 6575 if (peer_dynamic_neighbor(peer))
62d6dca0 6576 json_object_boolean_true_add(json_peer, "dynamicPeer");
b05a1c8b 6577
04b6bdc0
DW
6578 if (peer->hostname)
6579 json_object_string_add(json_peer, "hostname", peer->hostname);
6580
6581 if (peer->domainname)
6582 json_object_string_add(json_peer, "domainname", peer->domainname);
6583
62d6dca0 6584 json_object_int_add(json_peer, "remoteAs", peer->as);
f1aa5d8a 6585 json_object_int_add(json_peer, "version", 4);
62d6dca0 6586 json_object_int_add(json_peer, "msgRcvd",
f1aa5d8a
DS
6587 peer->open_in + peer->update_in + peer->keepalive_in
6588 + peer->notify_in + peer->refresh_in
6589 + peer->dynamic_cap_in);
62d6dca0 6590 json_object_int_add(json_peer, "msgSent",
f1aa5d8a
DS
6591 peer->open_out + peer->update_out + peer->keepalive_out
6592 + peer->notify_out + peer->refresh_out
6593 + peer->dynamic_cap_out);
6594
62d6dca0 6595 json_object_int_add(json_peer, "tableVersion", peer->version[afi][safi]);
f1aa5d8a
DS
6596 json_object_int_add(json_peer, "outq", peer->obuf->count);
6597 json_object_int_add(json_peer, "inq", 0);
856ca177 6598 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN, use_json, json_peer);
62d6dca0 6599 json_object_int_add(json_peer, "prefixReceivedCount", peer->pcount[afi][safi]);
b05a1c8b
DS
6600
6601 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
f1aa5d8a 6602 json_object_string_add(json_peer, "state", "Idle (Admin)");
b05a1c8b 6603 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
f1aa5d8a 6604 json_object_string_add(json_peer, "state", "Idle (PfxCt)");
b05a1c8b 6605 else
f1aa5d8a 6606 json_object_string_add(json_peer, "state", LOOKUP(bgp_status_msg, peer->status));
b05a1c8b 6607
f1aa5d8a 6608 if (peer->conf_if)
62d6dca0 6609 json_object_string_add(json_peer, "idType", "interface");
f1aa5d8a 6610 else if (peer->su.sa.sa_family == AF_INET)
62d6dca0 6611 json_object_string_add(json_peer, "idType", "ipv4");
f1aa5d8a 6612 else if (peer->su.sa.sa_family == AF_INET6)
62d6dca0 6613 json_object_string_add(json_peer, "idType", "ipv6");
b05a1c8b 6614
f1aa5d8a 6615 json_object_object_add(json_peers, peer->host, json_peer);
b05a1c8b
DS
6616 }
6617 else
6618 {
6619 memset(dn_flag, '\0', sizeof(dn_flag));
6620 if (peer_dynamic_neighbor(peer))
6621 {
6622 dn_count++;
6623 dn_flag[0] = '*';
6624 }
6625
04b6bdc0
DW
6626 if (peer->hostname && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
6627 len = vty_out (vty, "%s%s(%s)", dn_flag, peer->hostname,
6628 peer->host);
6629 else
6630 len = vty_out (vty, "%s%s", dn_flag, peer->host);
b05a1c8b 6631
f933309e
DW
6632 /* pad the neighbor column with spaces */
6633 if (len < max_neighbor_width)
6634 vty_out (vty, "%*s", max_neighbor_width - len, " ");
b05a1c8b 6635
f933309e 6636 vty_out (vty, "4 %10u %7d %7d %8" PRIu64 " %4d %4zd %8s",
b05a1c8b
DS
6637 peer->as,
6638 peer->open_in + peer->update_in + peer->keepalive_in
6639 + peer->notify_in + peer->refresh_in
6640 + peer->dynamic_cap_in,
6641 peer->open_out + peer->update_out + peer->keepalive_out
6642 + peer->notify_out + peer->refresh_out
6643 + peer->dynamic_cap_out,
6644 peer->version[afi][safi],
6645 0,
f933309e 6646 peer->obuf->count,
856ca177 6647 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
b05a1c8b
DS
6648
6649 if (peer->status == Established)
46f8c104 6650 vty_out (vty, " %12ld", peer->pcount[afi][safi]);
b05a1c8b
DS
6651 else
6652 {
6653 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
6654 vty_out (vty, " Idle (Admin)");
6655 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
6656 vty_out (vty, " Idle (PfxCt)");
6657 else
f933309e 6658 vty_out (vty, " %12s", LOOKUP(bgp_status_msg, peer->status));
b05a1c8b
DS
6659 }
6660 vty_out (vty, "%s", VTY_NEWLINE);
6661 }
718e3744 6662 }
6663 }
6664
b05a1c8b
DS
6665 if (use_json)
6666 {
6667 json_object_object_add(json, "peers", json_peers);
14151a32 6668
62d6dca0
DS
6669 json_object_int_add(json, "totalPeers", count);
6670 json_object_int_add(json, "dynamicPeers", dn_count);
14151a32 6671
2aac5767 6672 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
f1aa5d8a 6673 json_object_free(json);
b05a1c8b
DS
6674 }
6675 else
f14e6fdb 6676 {
b05a1c8b
DS
6677 if (count)
6678 vty_out (vty, "%sTotal number of neighbors %d%s", VTY_NEWLINE,
6679 count, VTY_NEWLINE);
6680 else
9f689658
DD
6681 {
6682 if (use_json)
6683 vty_out(vty, "{\"error\": {\"message\": \"No %s neighbor configured\"}}%s",
6684 afi == AFI_IP ? "IPv4" : "IPv6", VTY_NEWLINE);
6685 else
6686 vty_out (vty, "No %s neighbor is configured%s",
6687 afi == AFI_IP ? "IPv4" : "IPv6", VTY_NEWLINE);
6688 }
b05a1c8b 6689
9f689658 6690 if (dn_count && ! use_json)
b05a1c8b
DS
6691 {
6692 vty_out(vty, "* - dynamic neighbor%s", VTY_NEWLINE);
6693 vty_out(vty,
6694 "%d dynamic neighbor(s), limit %d%s",
6695 dn_count, bgp->dynamic_neighbors_limit, VTY_NEWLINE);
6696 }
f14e6fdb
DS
6697 }
6698
718e3744 6699 return CMD_SUCCESS;
6700}
6701
f186de26 6702static void
6703bgp_show_all_instances_summary_vty (struct vty *vty, afi_t afi, safi_t safi,
6704 u_char use_json)
6705{
6706 struct listnode *node, *nnode;
6707 struct bgp *bgp;
9f689658
DD
6708 json_object *json = NULL;
6709 int is_first = 1;
6710
6711 if (use_json)
6712 vty_out (vty, "{%s", VTY_NEWLINE);
f186de26 6713
6714 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
6715 {
9f689658
DD
6716 if (use_json)
6717 {
4fb25c53 6718 json = json_object_new_object();
9f689658
DD
6719
6720 if (! is_first)
6721 vty_out (vty, ",%s", VTY_NEWLINE);
6722 else
6723 is_first = 0;
6724
6725 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6726 ? "Default" : bgp->name);
6727 }
6728 else
6729 {
6730 vty_out (vty, "%sInstance %s:%s",
6731 VTY_NEWLINE,
6732 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6733 ? "Default" : bgp->name, VTY_NEWLINE);
6734 }
6735 bgp_show_summary (vty, bgp, afi, safi, use_json, json);
f186de26 6736 }
9f689658
DD
6737
6738 if (use_json)
6739 vty_out (vty, "}%s", VTY_NEWLINE);
6740
f186de26 6741}
6742
4fb25c53
DW
6743static int
6744bgp_show_summary_vty (struct vty *vty, const char *name,
6745 afi_t afi, safi_t safi, u_char use_json)
6746{
6747 struct bgp *bgp;
6748
6749 if (name)
6750 {
6751 if (strmatch(name, "all"))
6752 {
6753 bgp_show_all_instances_summary_vty (vty, afi, safi, use_json);
6754 return CMD_SUCCESS;
6755 }
6756 else
6757 {
6758 bgp = bgp_lookup_by_name (name);
6759
6760 if (! bgp)
6761 {
6762 if (use_json)
6763 vty_out (vty, "{}%s", VTY_NEWLINE);
6764 else
6765 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
6766 return CMD_WARNING;
6767 }
6768
6769 bgp_show_summary (vty, bgp, afi, safi, use_json, NULL);
6770 return CMD_SUCCESS;
6771 }
6772 }
6773
6774 bgp = bgp_get_default ();
6775
6776 if (bgp)
6777 bgp_show_summary (vty, bgp, afi, safi, use_json, NULL);
6778
6779 return CMD_SUCCESS;
6780}
6781
718e3744 6782/* `show ip bgp summary' commands. */
47fc97cc 6783DEFUN (show_ip_bgp_summary,
718e3744 6784 show_ip_bgp_summary_cmd,
ae19d7dd 6785 "show [ip] bgp [<view|vrf> WORD] [<ipv4 [<unicast|multicast>]|ipv6 [<unicast|multicast>]|encap [unicast]|vpnv4 [unicast]>] summary [json]",
718e3744 6786 SHOW_STR
6787 IP_STR
6788 BGP_STR
8386ac43 6789 BGP_INSTANCE_HELP_STR
8c3deaae 6790 "Address Family\n"
8de197ce 6791 "Address Family modifier\n"
8de197ce 6792 "Address Family modifier\n"
8c3deaae 6793 "Address Family\n"
8de197ce 6794 "Address Family modifier\n"
0c7b1b01 6795 "Address Family modifier\n"
8c3deaae 6796 "Address Family\n"
718e3744 6797 "Address Family modifier\n"
8c3deaae 6798 "Address Family\n"
718e3744 6799 "Address Family modifier\n"
b05a1c8b
DS
6800 "Summary of BGP neighbor status\n"
6801 "JavaScript Object Notation\n")
718e3744 6802{
74ca3d33 6803 char *vrf = NULL;
ae19d7dd
QY
6804 afi_t afi = AFI_IP6;
6805 safi_t safi = SAFI_UNICAST;
6806
6807 int idx = 0;
6808
6809 /* show [ip] bgp */
6810 if (argv_find (argv, argc, "ip", &idx))
6811 afi = AFI_IP;
6812 /* [<view|vrf> WORD] */
6813 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
6814 vrf = argv[++idx]->arg;
6815 /* [<ipv4 [<unicast|multicast>]|ipv6 [<unicast|multicast>]|encap [unicast]|vpnv4 [unicast]>] */
6816 if (argv_find (argv, argc, "ipv4", &idx) || argv_find (argv, argc, "ipv6", &idx))
6817 {
6818 afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP;
6819 if (argv_find (argv, argc, "unicast", &idx) || argv_find (argv, argc, "multicast", &idx))
6820 safi = strmatch (argv[idx]->text, "unicast") ? SAFI_UNICAST : SAFI_MULTICAST;
6821 }
6822 else if (argv_find (argv, argc, "encap", &idx) || argv_find (argv, argc, "vpnv4", &idx))
6823 {
6824 afi = AFI_IP;
6825 safi = strmatch (argv[idx]->text, "encap") ? SAFI_ENCAP : SAFI_MPLS_VPN;
6826 // advance idx if necessary
6827 argv_find (argv, argc, "unicast", &idx);
6828 }
6829 int uj = use_json (argc, argv);
74ca3d33
DW
6830
6831 return bgp_show_summary_vty (vty, vrf, afi, safi, uj);
718e3744 6832}
6833
fd79ac91 6834const char *
538621f2 6835afi_safi_print (afi_t afi, safi_t safi)
6836{
6837 if (afi == AFI_IP && safi == SAFI_UNICAST)
6838 return "IPv4 Unicast";
6839 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
6840 return "IPv4 Multicast";
6841 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
945c8fe9 6842 return "VPN-IPv4 Unicast";
8b1fb8be
LB
6843 else if (afi == AFI_IP && safi == SAFI_ENCAP)
6844 return "ENCAP-IPv4 Unicast";
538621f2 6845 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
6846 return "IPv6 Unicast";
6847 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
6848 return "IPv6 Multicast";
945c8fe9
LB
6849 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
6850 return "VPN-IPv6 Unicast";
8b1fb8be
LB
6851 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
6852 return "ENCAP-IPv6 Unicast";
538621f2 6853 else
6854 return "Unknown";
6855}
6856
718e3744 6857/* Show BGP peer's information. */
6858enum show_type
6859{
6860 show_all,
6861 show_peer
6862};
6863
94f2b392 6864static void
856ca177
MS
6865bgp_show_peer_afi_orf_cap (struct vty *vty, struct peer *p, afi_t afi, safi_t safi,
6866 u_int16_t adv_smcap, u_int16_t adv_rmcap, u_int16_t rcv_smcap,
6867 u_int16_t rcv_rmcap, u_char use_json, json_object *json_pref)
718e3744 6868{
6869 /* Send-Mode */
6870 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap)
6871 || CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
6872 {
856ca177
MS
6873 if (use_json)
6874 {
6875 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap) && CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
6876 json_object_string_add(json_pref, "sendMode", "advertisedAndReceived");
6877 else if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap))
6878 json_object_string_add(json_pref, "sendMode", "advertised");
6879 else if (CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
6880 json_object_string_add(json_pref, "sendMode", "received");
6881 }
6882 else
6883 {
6884 vty_out (vty, " Send-mode: ");
6885 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap))
6886 vty_out (vty, "advertised");
6887 if (CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
6888 vty_out (vty, "%sreceived",
6889 CHECK_FLAG (p->af_cap[afi][safi], adv_smcap) ?
6890 ", " : "");
6891 vty_out (vty, "%s", VTY_NEWLINE);
6892 }
718e3744 6893 }
6894
6895 /* Receive-Mode */
6896 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap)
6897 || CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
6898 {
856ca177
MS
6899 if (use_json)
6900 {
6901 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap) && CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
6902 json_object_string_add(json_pref, "recvMode", "advertisedAndReceived");
6903 else if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap))
6904 json_object_string_add(json_pref, "recvMode", "advertised");
6905 else if (CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
6906 json_object_string_add(json_pref, "recvMode", "received");
6907 }
6908 else
6909 {
6910 vty_out (vty, " Receive-mode: ");
6911 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap))
6912 vty_out (vty, "advertised");
6913 if (CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
6914 vty_out (vty, "%sreceived",
6915 CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap) ?
6916 ", " : "");
6917 vty_out (vty, "%s", VTY_NEWLINE);
6918 }
718e3744 6919 }
6920}
6921
94f2b392 6922static void
856ca177
MS
6923bgp_show_peer_afi (struct vty *vty, struct peer *p, afi_t afi, safi_t safi,
6924 u_char use_json, json_object *json_neigh)
718e3744 6925{
6926 struct bgp_filter *filter;
3f9c7369 6927 struct peer_af *paf;
718e3744 6928 char orf_pfx_name[BUFSIZ];
6929 int orf_pfx_count;
856ca177
MS
6930 json_object *json_af = NULL;
6931 json_object *json_prefA = NULL;
6932 json_object *json_prefB = NULL;
6933 json_object *json_addr = NULL;
718e3744 6934
856ca177
MS
6935 if (use_json)
6936 {
6937 json_addr = json_object_new_object();
6938 json_af = json_object_new_object();
856ca177 6939 filter = &p->filter[afi][safi];
718e3744 6940
c8560b44 6941 if (peer_group_active(p))
856ca177 6942 json_object_string_add(json_addr, "peerGroupMember", p->group->name);
538621f2 6943
856ca177
MS
6944 paf = peer_af_find(p, afi, safi);
6945 if (paf && PAF_SUBGRP(paf))
6946 {
6947 json_object_int_add(json_addr, "updateGroupId", PAF_UPDGRP(paf)->id);
6948 json_object_int_add(json_addr, "subGroupId", PAF_SUBGRP(paf)->id);
6949 json_object_int_add(json_addr, "packetQueueLength", bpacket_queue_virtual_length(paf));
6950 }
6951
6952 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
6953 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
6954 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
6955 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV))
6956 {
6957 json_object_int_add(json_af, "orfType", ORF_TYPE_PREFIX);
b6df4090 6958 json_prefA = json_object_new_object();
856ca177
MS
6959 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
6960 PEER_CAP_ORF_PREFIX_SM_ADV,
6961 PEER_CAP_ORF_PREFIX_RM_ADV,
6962 PEER_CAP_ORF_PREFIX_SM_RCV,
6963 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, json_prefA);
6964 json_object_object_add(json_af, "orfPrefixList", json_prefA);
6965 }
6966
6967 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
6968 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
6969 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
6970 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
6971 {
6972 json_object_int_add(json_af, "orfOldType", ORF_TYPE_PREFIX_OLD);
b6df4090 6973 json_prefB = json_object_new_object();
856ca177
MS
6974 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
6975 PEER_CAP_ORF_PREFIX_SM_ADV,
6976 PEER_CAP_ORF_PREFIX_RM_ADV,
6977 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
6978 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, json_prefB);
6979 json_object_object_add(json_af, "orfOldPrefixList", json_prefB);
6980 }
6981
6982 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
6983 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
6984 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
6985 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
6986 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)
6987 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
6988 json_object_object_add(json_addr, "afDependentCap", json_af);
b6df4090
DS
6989 else
6990 json_object_free(json_af);
856ca177
MS
6991
6992 sprintf (orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
6993 orf_pfx_count = prefix_bgp_show_prefix_list (NULL, afi, orf_pfx_name, use_json);
6994
6995 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND)
6996 || orf_pfx_count)
6997 {
6998 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND))
6999 json_object_boolean_true_add(json_neigh, "orfSent");
7000 if (orf_pfx_count)
7001 json_object_int_add(json_addr, "orfRecvCounter", orf_pfx_count);
7002 }
7003 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
7004 json_object_string_add(json_addr, "orfFirstUpdate", "deferredUntilORFOrRouteRefreshRecvd");
7005
7006 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7007 json_object_boolean_true_add(json_addr, "routeReflectorClient");
7008 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7009 json_object_boolean_true_add(json_addr, "routeServerClient");
7010 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7011 json_object_boolean_true_add(json_addr, "inboundSoftConfigPermit");
7012
88b8ed8d
DW
7013 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7014 json_object_boolean_true_add(json_addr, "privateAsNumsAllReplacedInUpdatesToNbr");
7015 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
856ca177 7016 json_object_boolean_true_add(json_addr, "privateAsNumsReplacedInUpdatesToNbr");
88b8ed8d
DW
7017 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7018 json_object_boolean_true_add(json_addr, "privateAsNumsAllRemovedInUpdatesToNbr");
856ca177
MS
7019 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS))
7020 json_object_boolean_true_add(json_addr, "privateAsNumsRemovedInUpdatesToNbr");
7021
adbac85e
DW
7022 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7023 json_object_boolean_true_add(json_addr, "addpathTxAllPaths");
7024
06370dac
DW
7025 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7026 json_object_boolean_true_add(json_addr, "addpathTxBestpathPerAS");
7027
856ca177
MS
7028 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7029 json_object_string_add(json_addr, "overrideASNsInOutboundUpdates", "ifAspathEqualRemoteAs");
7030
7031 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
7032 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
7033 json_object_boolean_true_add(json_addr, "routerAlwaysNextHop");
7034 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED))
7035 json_object_boolean_true_add(json_addr, "unchangedAsPathPropogatedToNbr");
7036 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
7037 json_object_boolean_true_add(json_addr, "unchangedNextHopPropogatedToNbr");
7038 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7039 json_object_boolean_true_add(json_addr, "unchangedMedPropogatedToNbr");
718e3744 7040 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
856ca177
MS
7041 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7042 {
7043 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7044 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7045 json_object_string_add(json_addr, "commAttriSentToNbr", "extendedAndStandard");
7046 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7047 json_object_string_add(json_addr, "commAttriSentToNbr", "extended");
7048 else
7049 json_object_string_add(json_addr, "commAttriSentToNbr", "standard");
7050 }
7051 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
7052 {
7053 if (p->default_rmap[afi][safi].name)
7054 json_object_string_add(json_addr, "defaultRouteMap", p->default_rmap[afi][safi].name);
7055
7056 if (paf && PAF_SUBGRP(paf) && CHECK_FLAG(PAF_SUBGRP(paf)->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
7057 json_object_boolean_true_add(json_addr, "defaultSent");
7058 else
7059 json_object_boolean_true_add(json_addr, "defaultNotSent");
7060 }
7061
7062 if (filter->plist[FILTER_IN].name
7063 || filter->dlist[FILTER_IN].name
7064 || filter->aslist[FILTER_IN].name
7065 || filter->map[RMAP_IN].name)
7066 json_object_boolean_true_add(json_addr, "inboundPathPolicyConfig");
7067 if (filter->plist[FILTER_OUT].name
7068 || filter->dlist[FILTER_OUT].name
7069 || filter->aslist[FILTER_OUT].name
7070 || filter->map[RMAP_OUT].name
7071 || filter->usmap.name)
7072 json_object_boolean_true_add(json_addr, "outboundPathPolicyConfig");
856ca177
MS
7073
7074 /* prefix-list */
7075 if (filter->plist[FILTER_IN].name)
7076 json_object_string_add(json_addr, "incomingUpdatePrefixFilterList", filter->plist[FILTER_IN].name);
7077 if (filter->plist[FILTER_OUT].name)
7078 json_object_string_add(json_addr, "outgoingUpdatePrefixFilterList", filter->plist[FILTER_OUT].name);
7079
7080 /* distribute-list */
7081 if (filter->dlist[FILTER_IN].name)
7082 json_object_string_add(json_addr, "incomingUpdateNetworkFilterList", filter->dlist[FILTER_IN].name);
7083 if (filter->dlist[FILTER_OUT].name)
7084 json_object_string_add(json_addr, "outgoingUpdateNetworkFilterList", filter->dlist[FILTER_OUT].name);
7085
7086 /* filter-list. */
7087 if (filter->aslist[FILTER_IN].name)
7088 json_object_string_add(json_addr, "incomingUpdateAsPathFilterList", filter->aslist[FILTER_IN].name);
7089 if (filter->aslist[FILTER_OUT].name)
7090 json_object_string_add(json_addr, "outgoingUpdateAsPathFilterList", filter->aslist[FILTER_OUT].name);
7091
7092 /* route-map. */
7093 if (filter->map[RMAP_IN].name)
7094 json_object_string_add(json_addr, "routeMapForIncomingAdvertisements", filter->map[RMAP_IN].name);
7095 if (filter->map[RMAP_OUT].name)
7096 json_object_string_add(json_addr, "routeMapForOutgoingAdvertisements", filter->map[RMAP_OUT].name);
856ca177
MS
7097
7098 /* unsuppress-map */
7099 if (filter->usmap.name)
7100 json_object_string_add(json_addr, "selectiveUnsuppressRouteMap", filter->usmap.name);
7101
7102 /* Receive prefix count */
7103 json_object_int_add(json_addr, "acceptedPrefixCounter", p->pcount[afi][safi]);
7104
7105 /* Maximum prefix */
7106 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
7107 {
7108 json_object_int_add(json_addr, "prefixAllowedMax", p->pmax[afi][safi]);
7109 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
7110 json_object_boolean_true_add(json_addr, "prefixAllowedMaxWarning");
7111 json_object_int_add(json_addr, "prefixAllowedWarningThresh", p->pmax_threshold[afi][safi]);
7112 if (p->pmax_restart[afi][safi])
7113 json_object_int_add(json_addr, "prefixAllowedRestartIntervalMsecs", p->pmax_restart[afi][safi] * 60000);
7114 }
7115 json_object_object_add(json_neigh, afi_safi_print (afi, safi), json_addr);
7116
7117 }
7118 else
7119 {
7120 filter = &p->filter[afi][safi];
7121
7122 vty_out (vty, " For address family: %s%s", afi_safi_print (afi, safi),
7123 VTY_NEWLINE);
7124
c8560b44 7125 if (peer_group_active(p))
856ca177
MS
7126 vty_out (vty, " %s peer-group member%s", p->group->name, VTY_NEWLINE);
7127
7128 paf = peer_af_find(p, afi, safi);
7129 if (paf && PAF_SUBGRP(paf))
7130 {
7131 vty_out (vty, " Update group %" PRIu64 ", subgroup %" PRIu64 "%s",
7132 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id, VTY_NEWLINE);
7133 vty_out (vty, " Packet Queue length %d%s",
7134 bpacket_queue_virtual_length(paf), VTY_NEWLINE);
7135 }
718e3744 7136 else
856ca177
MS
7137 {
7138 vty_out(vty, " Not part of any update group%s", VTY_NEWLINE);
7139 }
7140 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7141 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7142 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7143 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7144 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)
7145 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7146 vty_out (vty, " AF-dependant capabilities:%s", VTY_NEWLINE);
7147
7148 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7149 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7150 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7151 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV))
7152 {
7153 vty_out (vty, " Outbound Route Filter (ORF) type (%d) Prefix-list:%s",
7154 ORF_TYPE_PREFIX, VTY_NEWLINE);
7155 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7156 PEER_CAP_ORF_PREFIX_SM_ADV,
7157 PEER_CAP_ORF_PREFIX_RM_ADV,
7158 PEER_CAP_ORF_PREFIX_SM_RCV,
7159 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7160 }
7161 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7162 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7163 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7164 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7165 {
7166 vty_out (vty, " Outbound Route Filter (ORF) type (%d) Prefix-list:%s",
7167 ORF_TYPE_PREFIX_OLD, VTY_NEWLINE);
7168 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7169 PEER_CAP_ORF_PREFIX_SM_ADV,
7170 PEER_CAP_ORF_PREFIX_RM_ADV,
7171 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7172 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7173 }
718e3744 7174
856ca177
MS
7175 sprintf (orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7176 orf_pfx_count = prefix_bgp_show_prefix_list (NULL, afi, orf_pfx_name, use_json);
718e3744 7177
856ca177
MS
7178 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND)
7179 || orf_pfx_count)
7180 {
7181 vty_out (vty, " Outbound Route Filter (ORF):");
7182 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND))
7183 vty_out (vty, " sent;");
7184 if (orf_pfx_count)
7185 vty_out (vty, " received (%d entries)", orf_pfx_count);
7186 vty_out (vty, "%s", VTY_NEWLINE);
7187 }
7188 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
7189 vty_out (vty, " First update is deferred until ORF or ROUTE-REFRESH is received%s", VTY_NEWLINE);
7190
7191 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7192 vty_out (vty, " Route-Reflector Client%s", VTY_NEWLINE);
7193 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7194 vty_out (vty, " Route-Server Client%s", VTY_NEWLINE);
7195 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7196 vty_out (vty, " Inbound soft reconfiguration allowed%s", VTY_NEWLINE);
7197
88b8ed8d
DW
7198 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7199 vty_out (vty, " Private AS numbers (all) replaced in updates to this neighbor%s", VTY_NEWLINE);
7200 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
856ca177 7201 vty_out (vty, " Private AS numbers replaced in updates to this neighbor%s", VTY_NEWLINE);
88b8ed8d
DW
7202 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7203 vty_out (vty, " Private AS numbers (all) removed in updates to this neighbor%s", VTY_NEWLINE);
856ca177
MS
7204 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS))
7205 vty_out (vty, " Private AS numbers removed in updates to this neighbor%s", VTY_NEWLINE);
7206
adbac85e
DW
7207 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7208 vty_out (vty, " Advertise all paths via addpath%s", VTY_NEWLINE);
7209
06370dac
DW
7210 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7211 vty_out (vty, " Advertise bestpath per AS via addpath%s", VTY_NEWLINE);
7212
856ca177
MS
7213 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7214 vty_out (vty, " Override ASNs in outbound updates if aspath equals remote-as%s", VTY_NEWLINE);
7215
7216 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
7217 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
7218 vty_out (vty, " NEXT_HOP is always this router%s", VTY_NEWLINE);
7219 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED))
7220 vty_out (vty, " AS_PATH is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7221 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
7222 vty_out (vty, " NEXT_HOP is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7223 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7224 vty_out (vty, " MED is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7225 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7226 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7227 {
7228 vty_out (vty, " Community attribute sent to this neighbor");
7229 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7230 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7231 vty_out (vty, "(both)%s", VTY_NEWLINE);
7232 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7233 vty_out (vty, "(extended)%s", VTY_NEWLINE);
7234 else
7235 vty_out (vty, "(standard)%s", VTY_NEWLINE);
7236 }
7237 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
7238 {
7239 vty_out (vty, " Default information originate,");
7240
7241 if (p->default_rmap[afi][safi].name)
7242 vty_out (vty, " default route-map %s%s,",
7243 p->default_rmap[afi][safi].map ? "*" : "",
7244 p->default_rmap[afi][safi].name);
7245 if (paf && PAF_SUBGRP(paf) && CHECK_FLAG(PAF_SUBGRP(paf)->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
7246 vty_out (vty, " default sent%s", VTY_NEWLINE);
7247 else
7248 vty_out (vty, " default not sent%s", VTY_NEWLINE);
7249 }
718e3744 7250
856ca177
MS
7251 if (filter->plist[FILTER_IN].name
7252 || filter->dlist[FILTER_IN].name
7253 || filter->aslist[FILTER_IN].name
7254 || filter->map[RMAP_IN].name)
7255 vty_out (vty, " Inbound path policy configured%s", VTY_NEWLINE);
7256 if (filter->plist[FILTER_OUT].name
7257 || filter->dlist[FILTER_OUT].name
7258 || filter->aslist[FILTER_OUT].name
7259 || filter->map[RMAP_OUT].name
7260 || filter->usmap.name)
7261 vty_out (vty, " Outbound path policy configured%s", VTY_NEWLINE);
856ca177
MS
7262
7263 /* prefix-list */
7264 if (filter->plist[FILTER_IN].name)
7265 vty_out (vty, " Incoming update prefix filter list is %s%s%s",
7266 filter->plist[FILTER_IN].plist ? "*" : "",
7267 filter->plist[FILTER_IN].name,
7268 VTY_NEWLINE);
7269 if (filter->plist[FILTER_OUT].name)
7270 vty_out (vty, " Outgoing update prefix filter list is %s%s%s",
7271 filter->plist[FILTER_OUT].plist ? "*" : "",
7272 filter->plist[FILTER_OUT].name,
7273 VTY_NEWLINE);
7274
7275 /* distribute-list */
7276 if (filter->dlist[FILTER_IN].name)
7277 vty_out (vty, " Incoming update network filter list is %s%s%s",
7278 filter->dlist[FILTER_IN].alist ? "*" : "",
7279 filter->dlist[FILTER_IN].name,
7280 VTY_NEWLINE);
7281 if (filter->dlist[FILTER_OUT].name)
7282 vty_out (vty, " Outgoing update network filter list is %s%s%s",
7283 filter->dlist[FILTER_OUT].alist ? "*" : "",
7284 filter->dlist[FILTER_OUT].name,
7285 VTY_NEWLINE);
7286
7287 /* filter-list. */
7288 if (filter->aslist[FILTER_IN].name)
7289 vty_out (vty, " Incoming update AS path filter list is %s%s%s",
7290 filter->aslist[FILTER_IN].aslist ? "*" : "",
7291 filter->aslist[FILTER_IN].name,
7292 VTY_NEWLINE);
7293 if (filter->aslist[FILTER_OUT].name)
7294 vty_out (vty, " Outgoing update AS path filter list is %s%s%s",
7295 filter->aslist[FILTER_OUT].aslist ? "*" : "",
7296 filter->aslist[FILTER_OUT].name,
7297 VTY_NEWLINE);
7298
7299 /* route-map. */
7300 if (filter->map[RMAP_IN].name)
7301 vty_out (vty, " Route map for incoming advertisements is %s%s%s",
7302 filter->map[RMAP_IN].map ? "*" : "",
7303 filter->map[RMAP_IN].name,
7304 VTY_NEWLINE);
7305 if (filter->map[RMAP_OUT].name)
7306 vty_out (vty, " Route map for outgoing advertisements is %s%s%s",
7307 filter->map[RMAP_OUT].map ? "*" : "",
7308 filter->map[RMAP_OUT].name,
7309 VTY_NEWLINE);
856ca177
MS
7310
7311 /* unsuppress-map */
7312 if (filter->usmap.name)
7313 vty_out (vty, " Route map for selective unsuppress is %s%s%s",
7314 filter->usmap.map ? "*" : "",
7315 filter->usmap.name, VTY_NEWLINE);
7316
7317 /* Receive prefix count */
7318 vty_out (vty, " %ld accepted prefixes%s", p->pcount[afi][safi], VTY_NEWLINE);
7319
7320 /* Maximum prefix */
7321 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
7322 {
7323 vty_out (vty, " Maximum prefixes allowed %ld%s%s", p->pmax[afi][safi],
7324 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)
7325 ? " (warning-only)" : "", VTY_NEWLINE);
7326 vty_out (vty, " Threshold for warning message %d%%",
7327 p->pmax_threshold[afi][safi]);
7328 if (p->pmax_restart[afi][safi])
7329 vty_out (vty, ", restart interval %d min", p->pmax_restart[afi][safi]);
7330 vty_out (vty, "%s", VTY_NEWLINE);
7331 }
718e3744 7332
0a486e5f 7333 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7334 }
718e3744 7335}
7336
94f2b392 7337static void
e8f7da3a 7338bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *json)
718e3744 7339{
7340 struct bgp *bgp;
4690c7d7 7341 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
718e3744 7342 char timebuf[BGP_UPTIME_LEN];
f14e6fdb 7343 char dn_flag[2];
3a8c7ba1
DW
7344 const char *subcode_str;
7345 const char *code_str;
538621f2 7346 afi_t afi;
7347 safi_t safi;
d6661008
DS
7348 u_int16_t i;
7349 u_char *msg;
e8f7da3a 7350 json_object *json_neigh = NULL;
718e3744 7351
7352 bgp = p->bgp;
7353
e8f7da3a
DW
7354 if (use_json)
7355 json_neigh = json_object_new_object();
7356
856ca177 7357 if (!use_json)
f14e6fdb 7358 {
856ca177
MS
7359 if (p->conf_if) /* Configured interface name. */
7360 vty_out (vty, "BGP neighbor on %s: %s, ", p->conf_if,
7361 BGP_PEER_SU_UNSPEC(p) ? "None" :
7362 sockunion2str (&p->su, buf, SU_ADDRSTRLEN));
7363 else /* Configured IP address. */
7364 {
7365 memset(dn_flag, '\0', sizeof(dn_flag));
7366 if (peer_dynamic_neighbor(p))
7367 dn_flag[0] = '*';
f14e6fdb 7368
856ca177
MS
7369 vty_out (vty, "BGP neighbor is %s%s, ", dn_flag, p->host);
7370 }
f14e6fdb
DS
7371 }
7372
856ca177
MS
7373 if (use_json)
7374 {
7375 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
7376 json_object_string_add(json_neigh, "bgpNeighborAddr", "none");
7377 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
7378 json_object_string_add(json_neigh, "bgpNeighborAddr", sockunion2str (&p->su, buf, SU_ADDRSTRLEN));
7379
7380 json_object_int_add(json_neigh, "remoteAs", p->as);
7381
7382 if (p->change_local_as)
7383 json_object_int_add(json_neigh, "localAs", p->change_local_as);
7384 else
7385 json_object_int_add(json_neigh, "localAs", p->local_as);
7386
7387 if (CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
7388 json_object_boolean_true_add(json_neigh, "localAsNoPrepend");
66b199b2 7389
856ca177
MS
7390 if (CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
7391 json_object_boolean_true_add(json_neigh, "localAsReplaceAs");
7392 }
7393 else
7394 {
f8cfafda
DS
7395 if ((p->as_type == AS_SPECIFIED) ||
7396 (p->as_type == AS_EXTERNAL) ||
7397 (p->as_type == AS_INTERNAL))
7398 vty_out (vty, "remote AS %u, ", p->as);
7399 else
7400 vty_out (vty, "remote AS Unspecified, ");
856ca177
MS
7401 vty_out (vty, "local AS %u%s%s, ",
7402 p->change_local_as ? p->change_local_as : p->local_as,
7403 CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND) ?
7404 " no-prepend" : "",
7405 CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS) ?
7406 " replace-as" : "");
7407 }
66b199b2
DS
7408 /* peer type internal, external, confed-internal or confed-external */
7409 if (p->as == p->local_as)
7410 {
856ca177
MS
7411 if (use_json)
7412 {
7413 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7414 json_object_boolean_true_add(json_neigh, "nbrConfedInternalLink");
7415 else
7416 json_object_boolean_true_add(json_neigh, "nbrInternalLink");
7417 }
66b199b2 7418 else
856ca177
MS
7419 {
7420 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7421 vty_out (vty, "confed-internal link%s", VTY_NEWLINE);
7422 else
7423 vty_out (vty, "internal link%s", VTY_NEWLINE);
7424 }
66b199b2
DS
7425 }
7426 else
7427 {
856ca177
MS
7428 if (use_json)
7429 {
7430 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
7431 json_object_boolean_true_add(json_neigh, "nbrConfedExternalLink");
7432 else
7433 json_object_boolean_true_add(json_neigh, "nbrExternalLink");
7434 }
66b199b2 7435 else
856ca177
MS
7436 {
7437 if (bgp_confederation_peers_check(bgp, p->as))
7438 vty_out (vty, "confed-external link%s", VTY_NEWLINE);
7439 else
7440 vty_out (vty, "external link%s", VTY_NEWLINE);
7441 }
66b199b2 7442 }
718e3744 7443
7444 /* Description. */
7445 if (p->desc)
856ca177
MS
7446 {
7447 if (use_json)
7448 json_object_string_add(json_neigh, "nbrDesc", p->desc);
7449 else
7450 vty_out (vty, " Description: %s%s", p->desc, VTY_NEWLINE);
7451 }
6410e93a 7452
04b6bdc0
DW
7453 if (p->hostname)
7454 {
d1570739
DW
7455 if (use_json)
7456 {
7457 if (p->hostname)
7458 json_object_string_add(json_neigh, "hostname", p->hostname);
7459
7460 if (p->domainname)
7461 json_object_string_add(json_neigh, "domainname", p->domainname);
7462 }
04b6bdc0 7463 else
d1570739
DW
7464 {
7465 if (p->domainname && (p->domainname[0] != '\0'))
7466 vty_out(vty, "Hostname: %s.%s%s", p->hostname, p->domainname,
7467 VTY_NEWLINE);
7468 else
7469 vty_out(vty, "Hostname: %s%s", p->hostname, VTY_NEWLINE);
7470 }
7471
04b6bdc0
DW
7472 }
7473
c744aa9f 7474 /* Peer-group */
718e3744 7475 if (p->group)
f14e6fdb 7476 {
856ca177
MS
7477 if (use_json)
7478 {
7479 json_object_string_add(json_neigh, "peerGroup", p->group->name);
7480
7481 if (dn_flag[0])
7482 {
40ee54a7 7483 struct prefix prefix, *range = NULL;
f14e6fdb 7484
40ee54a7
TT
7485 sockunion2hostprefix(&(p->su), &prefix);
7486 range = peer_group_lookup_dynamic_neighbor_range (p->group, &prefix);
856ca177
MS
7487
7488 if (range)
7489 {
7490 prefix2str(range, buf1, sizeof(buf1));
7491 json_object_string_add(json_neigh, "peerSubnetRangeGroup", buf1);
7492 }
7493 }
7494 }
7495 else
f14e6fdb 7496 {
856ca177
MS
7497 vty_out (vty, " Member of peer-group %s for session parameters%s",
7498 p->group->name, VTY_NEWLINE);
f14e6fdb 7499
856ca177 7500 if (dn_flag[0])
f14e6fdb 7501 {
40ee54a7 7502 struct prefix prefix, *range = NULL;
856ca177 7503
40ee54a7
TT
7504 sockunion2hostprefix(&(p->su), &prefix);
7505 range = peer_group_lookup_dynamic_neighbor_range (p->group, &prefix);
856ca177
MS
7506
7507 if (range)
7508 {
7509 prefix2str(range, buf1, sizeof(buf1));
7510 vty_out (vty, " Belongs to the subnet range group: %s%s", buf1, VTY_NEWLINE);
7511 }
f14e6fdb
DS
7512 }
7513 }
7514 }
718e3744 7515
856ca177
MS
7516 if (use_json)
7517 {
7518 /* Administrative shutdown. */
7519 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
7520 json_object_boolean_true_add(json_neigh, "adminShutDown");
718e3744 7521
856ca177
MS
7522 /* BGP Version. */
7523 json_object_int_add(json_neigh, "bgpVersion", 4);
7524 json_object_string_add(json_neigh, "remoteRouterId", inet_ntop (AF_INET, &p->remote_id, buf1, BUFSIZ));
718e3744 7525
856ca177
MS
7526 /* Confederation */
7527 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION) && bgp_confederation_peers_check (bgp, p->as))
7528 json_object_boolean_true_add(json_neigh, "nbrCommonAdmin");
7529
7530 /* Status. */
7531 json_object_string_add(json_neigh, "bgpState", LOOKUP (bgp_status_msg, p->status));
7532
7533 if (p->status == Established)
7534 {
7535 time_t uptime;
7536 struct tm *tm;
7537
7538 uptime = bgp_clock();
7539 uptime -= p->uptime;
7540 tm = gmtime(&uptime);
7541
7542 json_object_int_add(json_neigh, "bgpTimerUp", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
7543 }
7544
7545 else if (p->status == Active)
7546 {
7547 if (CHECK_FLAG (p->flags, PEER_FLAG_PASSIVE))
7548 json_object_string_add(json_neigh, "bgpStateIs", "passive");
7549 else if (CHECK_FLAG (p->sflags, PEER_STATUS_NSF_WAIT))
7550 json_object_string_add(json_neigh, "bgpStateIs", "passiveNSF");
7551 }
7552
7553 /* read timer */
7554 time_t uptime;
7555 struct tm *tm;
7556
7557 uptime = bgp_clock();
7558 uptime -= p->readtime;
7559 tm = gmtime(&uptime);
7560 json_object_int_add(json_neigh, "bgpTimerLastRead", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
7561
7562 uptime = bgp_clock();
7563 uptime -= p->last_write;
7564 tm = gmtime(&uptime);
39e871e6
ST
7565 json_object_int_add(json_neigh, "bgpTimerLastWrite", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
7566
7567 uptime = bgp_clock();
7568 uptime -= p->update_time;
7569 tm = gmtime(&uptime);
7570 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
7571 (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
856ca177
MS
7572
7573 /* Configured timer values. */
7574 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs", p->v_holdtime * 1000);
7575 json_object_int_add(json_neigh, "bgpTimerKeepAliveIntervalMsecs", p->v_keepalive * 1000);
7576
7577 if (CHECK_FLAG (p->config, PEER_CONFIG_TIMER))
7578 {
7579 json_object_int_add(json_neigh, "bgpTimerConfiguredHoldTimeMsecs", p->holdtime * 1000);
7580 json_object_int_add(json_neigh, "bgpTimerConfiguredKeepAliveIntervalMsecs", p->keepalive * 1000);
7581 }
93406d87 7582 }
856ca177
MS
7583 else
7584 {
7585 /* Administrative shutdown. */
7586 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
7587 vty_out (vty, " Administratively shut down%s", VTY_NEWLINE);
7588
7589 /* BGP Version. */
7590 vty_out (vty, " BGP version 4");
7591 vty_out (vty, ", remote router ID %s%s", inet_ntop (AF_INET, &p->remote_id, buf1, BUFSIZ),
7592 VTY_NEWLINE);
7593
7594 /* Confederation */
7595 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION)
7596 && bgp_confederation_peers_check (bgp, p->as))
7597 vty_out (vty, " Neighbor under common administration%s", VTY_NEWLINE);
e52702f2 7598
856ca177
MS
7599 /* Status. */
7600 vty_out (vty, " BGP state = %s", LOOKUP (bgp_status_msg, p->status));
718e3744 7601
856ca177
MS
7602 if (p->status == Established)
7603 vty_out (vty, ", up for %8s", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
7604
7605 else if (p->status == Active)
7606 {
7607 if (CHECK_FLAG (p->flags, PEER_FLAG_PASSIVE))
7608 vty_out (vty, " (passive)");
7609 else if (CHECK_FLAG (p->sflags, PEER_STATUS_NSF_WAIT))
7610 vty_out (vty, " (NSF passive)");
7611 }
7612 vty_out (vty, "%s", VTY_NEWLINE);
93406d87 7613
856ca177
MS
7614 /* read timer */
7615 vty_out (vty, " Last read %s", peer_uptime (p->readtime, timebuf, BGP_UPTIME_LEN, 0, NULL));
7616 vty_out (vty, ", Last write %s%s",
7617 peer_uptime (p->last_write, timebuf, BGP_UPTIME_LEN, 0, NULL), VTY_NEWLINE);
7618
7619 /* Configured timer values. */
7620 vty_out (vty, " Hold time is %d, keepalive interval is %d seconds%s",
7621 p->v_holdtime, p->v_keepalive, VTY_NEWLINE);
7622 if (CHECK_FLAG (p->config, PEER_CONFIG_TIMER))
7623 {
7624 vty_out (vty, " Configured hold time is %d", p->holdtime);
7625 vty_out (vty, ", keepalive interval is %d seconds%s",
7626 p->keepalive, VTY_NEWLINE);
7627 }
7628 }
718e3744 7629 /* Capability. */
e52702f2 7630 if (p->status == Established)
718e3744 7631 {
538621f2 7632 if (p->cap
718e3744 7633 || p->afc_adv[AFI_IP][SAFI_UNICAST]
7634 || p->afc_recv[AFI_IP][SAFI_UNICAST]
7635 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
7636 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
7637#ifdef HAVE_IPV6
7638 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
7639 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
7640 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
7641 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
945c8fe9
LB
7642 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
7643 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8b1fb8be
LB
7644 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
7645 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
718e3744 7646#endif /* HAVE_IPV6 */
8b1fb8be
LB
7647 || p->afc_adv[AFI_IP][SAFI_ENCAP]
7648 || p->afc_recv[AFI_IP][SAFI_ENCAP]
718e3744 7649 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
7650 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN])
7651 {
856ca177
MS
7652 if (use_json)
7653 {
7654 json_object *json_cap = NULL;
7655
7656 json_cap = json_object_new_object();
7657
7658 /* AS4 */
7659 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV)
7660 || CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
7661 {
7662 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV) && CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
7663 json_object_string_add(json_cap, "4byteAs", "advertisedAndReceived");
7664 else if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
7665 json_object_string_add(json_cap, "4byteAs", "advertised");
7666 else if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
7667 json_object_string_add(json_cap, "4byteAs", "received");
7668 }
7669
7670 /* AddPath */
7671 if (CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_RCV)
7672 || CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_ADV))
7673 {
7674 json_object *json_add = NULL;
7675 const char *print_store;
718e3744 7676
856ca177 7677 json_add = json_object_new_object();
a82478b9 7678
856ca177
MS
7679 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7680 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7681 {
7682 json_object *json_sub = NULL;
7683 json_sub = json_object_new_object();
7684 print_store = afi_safi_print (afi, safi);
7685
7686 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
7687 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
7688 {
7689 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))
7690 json_object_boolean_true_add(json_sub, "txAdvertisedAndReceived");
7691 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV))
7692 json_object_boolean_true_add(json_sub, "txAdvertised");
7693 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
7694 json_object_boolean_true_add(json_sub, "txReceived");
7695 }
7696
7697 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
7698 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7699 {
7700 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))
7701 json_object_boolean_true_add(json_sub, "rxAdvertisedAndReceived");
7702 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV))
7703 json_object_boolean_true_add(json_sub, "rxAdvertised");
7704 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7705 json_object_boolean_true_add(json_sub, "rxReceived");
7706 }
7707
7708 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
7709 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV) ||
7710 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
7711 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7712 json_object_object_add(json_add, print_store, json_sub);
b6df4090
DS
7713 else
7714 json_object_free(json_sub);
856ca177 7715 }
a82478b9 7716
856ca177
MS
7717 json_object_object_add(json_cap, "addPath", json_add);
7718 }
7719
7720 /* Dynamic */
7721 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV)
7722 || CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
7723 {
7724 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV) && CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
7725 json_object_string_add(json_cap, "dynamic", "advertisedAndReceived");
7726 else if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
7727 json_object_string_add(json_cap, "dynamic", "advertised");
7728 else if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
7729 json_object_string_add(json_cap, "dynamic", "received");
7730 }
7731
7732 /* Extended nexthop */
7733 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV)
7734 || CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
7735 {
7736 json_object *json_nxt = NULL;
7737 const char *print_store;
7738
856ca177
MS
7739
7740 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV) && CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
7741 json_object_string_add(json_cap, "extendedNexthop", "advertisedAndReceived");
7742 else if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
7743 json_object_string_add(json_cap, "extendedNexthop", "advertised");
7744 else if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
7745 json_object_string_add(json_cap, "extendedNexthop", "received");
7746
7747 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
7748 {
b6df4090
DS
7749 json_nxt = json_object_new_object();
7750
856ca177
MS
7751 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7752 {
7753 if (CHECK_FLAG (p->af_cap[AFI_IP][safi], PEER_CAP_ENHE_AF_RCV))
7754 {
7755 print_store = afi_safi_print (AFI_IP, safi);
7756 json_object_string_add(json_nxt, print_store, "recieved");
7757 }
7758 }
7759 json_object_object_add(json_cap, "extendedNexthopFamililesByPeer", json_nxt);
7760 }
7761 }
7762
7763 /* Route Refresh */
7764 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV)
7765 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
7766 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
7767 {
7768 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)))
7769 {
7770 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV) && CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV))
7771 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedOldNew");
7772 else
7773 {
7774 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
7775 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedOld");
7776 else
7777 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedNew");
7778 }
7779 }
7780 else if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV))
7781 json_object_string_add(json_cap, "routeRefresh", "advertised");
7782 else if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV) || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
7783 json_object_string_add(json_cap, "routeRefresh", "received");
7784 }
7785
7786 /* Multiprotocol Extensions */
7787 json_object *json_multi = NULL;
7788 json_multi = json_object_new_object();
7789
7790 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7791 {
7792 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7793 {
7794 if (p->afc_adv[afi][safi] || p->afc_recv[afi][safi])
7795 {
7796 json_object *json_exten = NULL;
7797 json_exten = json_object_new_object();
7798
7799 if (p->afc_adv[afi][safi] && p->afc_recv[afi][safi])
7800 json_object_boolean_true_add(json_exten, "advertisedAndReceived");
7801 else if (p->afc_adv[afi][safi])
7802 json_object_boolean_true_add(json_exten, "advertised");
7803 else if (p->afc_recv[afi][safi])
7804 json_object_boolean_true_add(json_exten, "received");
7805
7806 json_object_object_add(json_multi, afi_safi_print (afi, safi), json_exten);
7807 }
7808 }
7809 }
7810 json_object_object_add(json_cap, "multiprotocolExtensions", json_multi);
7811
7812 /* Gracefull Restart */
7813 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
7814 || CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
7815 {
7816 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV) && CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
7817 json_object_string_add(json_cap, "gracefulRestart", "advertisedAndReceived");
7818 else if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
7819 json_object_string_add(json_cap, "gracefulRestartCapability", "advertised");
7820 else if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
7821 json_object_string_add(json_cap, "gracefulRestartCapability", "received");
7822
7823 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
7824 {
7825 int restart_af_count = 0;
7826 json_object *json_restart = NULL;
7827 json_restart = json_object_new_object();
7828
7829 json_object_int_add(json_cap, "gracefulRestartRemoteTimerMsecs", p->v_gr_restart * 1000);
7830
7831 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7832 {
7833 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7834 {
7835 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV))
7836 {
7837 json_object *json_sub = NULL;
7838 json_sub = json_object_new_object();
7839
7840 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV))
7841 json_object_boolean_true_add(json_sub, "preserved");
7842 restart_af_count++;
7843 json_object_object_add(json_restart, afi_safi_print (afi, safi), json_sub);
7844 }
7845 }
7846 }
7847 if (! restart_af_count)
b6df4090 7848 {
856ca177 7849 json_object_string_add(json_cap, "addressFamiliesByPeer", "none");
b6df4090
DS
7850 json_object_free(json_restart);
7851 }
856ca177
MS
7852 else
7853 json_object_object_add(json_cap, "addressFamiliesByPeer", json_restart);
7854 }
7855 }
7856 json_object_object_add(json_neigh, "neighborCapabilities", json_cap);
7857 }
7858 else
7859 {
7860 vty_out (vty, " Neighbor capabilities:%s", VTY_NEWLINE);
7861
7862 /* AS4 */
7863 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV)
7864 || CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
7865 {
7866 vty_out (vty, " 4 Byte AS:");
7867 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
7868 vty_out (vty, " advertised");
7869 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
7870 vty_out (vty, " %sreceived",
7871 CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV) ? "and " : "");
7872 vty_out (vty, "%s", VTY_NEWLINE);
7873 }
7874
7875 /* AddPath */
7876 if (CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_RCV)
7877 || CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_ADV))
7878 {
7879 vty_out (vty, " AddPath:%s", VTY_NEWLINE);
a82478b9 7880
856ca177
MS
7881 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7882 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
a82478b9 7883 {
856ca177
MS
7884 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
7885 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
7886 {
7887 vty_out (vty, " %s: TX ", afi_safi_print (afi, safi));
a82478b9 7888
856ca177
MS
7889 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV))
7890 vty_out (vty, "advertised %s", afi_safi_print (afi, safi));
a82478b9 7891
856ca177
MS
7892 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
7893 vty_out (vty, "%sreceived", CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ? " and " : "" );
a82478b9 7894
856ca177
MS
7895 vty_out (vty, "%s", VTY_NEWLINE);
7896 }
a82478b9 7897
856ca177 7898 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
a82478b9 7899 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
856ca177
MS
7900 {
7901 vty_out (vty, " %s: RX ", afi_safi_print (afi, safi));
a82478b9 7902
856ca177
MS
7903 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV))
7904 vty_out (vty, "advertised %s", afi_safi_print (afi, safi));
a82478b9 7905
856ca177
MS
7906 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
7907 vty_out (vty, "%sreceived", CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ? " and " : "" );
a82478b9 7908
856ca177
MS
7909 vty_out (vty, "%s", VTY_NEWLINE);
7910 }
a82478b9 7911 }
856ca177 7912 }
a82478b9 7913
856ca177
MS
7914 /* Dynamic */
7915 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV)
7916 || CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
7917 {
7918 vty_out (vty, " Dynamic:");
7919 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
7920 vty_out (vty, " advertised");
7921 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
7922 vty_out (vty, " %sreceived",
7923 CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV) ? "and " : "");
7924 vty_out (vty, "%s", VTY_NEWLINE);
7925 }
7926
7927 /* Extended nexthop */
7928 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV)
7929 || CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
7930 {
7931 vty_out (vty, " Extended nexthop:");
7932 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
7933 vty_out (vty, " advertised");
7934 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
7935 vty_out (vty, " %sreceived",
7936 CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV) ? "and " : "");
7937 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 7938
856ca177
MS
7939 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
7940 {
7941 vty_out (vty, " Address families by peer:%s ", VTY_NEWLINE);
7942 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7943 if (CHECK_FLAG (p->af_cap[AFI_IP][safi], PEER_CAP_ENHE_AF_RCV))
7944 vty_out (vty, " %s%s",
7945 afi_safi_print (AFI_IP, safi), VTY_NEWLINE);
7946 }
7947 }
8a92a8a0 7948
856ca177
MS
7949 /* Route Refresh */
7950 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV)
7951 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
7952 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
7953 {
7954 vty_out (vty, " Route refresh:");
7955 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV))
7956 vty_out (vty, " advertised");
7957 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
7958 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
7959 vty_out (vty, " %sreceived(%s)",
7960 CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV) ? "and " : "",
7961 (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV)
7962 && CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)) ?
7963 "old & new" : CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV) ? "old" : "new");
8a92a8a0 7964
856ca177
MS
7965 vty_out (vty, "%s", VTY_NEWLINE);
7966 }
718e3744 7967
856ca177
MS
7968 /* Multiprotocol Extensions */
7969 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
7970 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
7971 if (p->afc_adv[afi][safi] || p->afc_recv[afi][safi])
7972 {
8c3deaae 7973 vty_out (vty, " Address Family %s:", afi_safi_print (afi, safi));
856ca177
MS
7974 if (p->afc_adv[afi][safi])
7975 vty_out (vty, " advertised");
7976 if (p->afc_recv[afi][safi])
7977 vty_out (vty, " %sreceived", p->afc_adv[afi][safi] ? "and " : "");
7978 vty_out (vty, "%s", VTY_NEWLINE);
7979 }
538621f2 7980
04b6bdc0
DW
7981 /* Hostname capability */
7982 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV) ||
7983 CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV))
7984 {
7985 vty_out (vty, " Hostname Capability:");
7986 if (CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_ADV))
7987 vty_out (vty, " advertised");
7988 if (CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_RCV))
7989 vty_out (vty, " %sreceived",
7990 CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_ADV) ? "and " : "");
7991 vty_out (vty, "%s", VTY_NEWLINE);
7992 }
7993
856ca177
MS
7994 /* Gracefull Restart */
7995 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
7996 || CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
7997 {
7998 vty_out (vty, " Graceful Restart Capabilty:");
7999 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
538621f2 8000 vty_out (vty, " advertised");
856ca177
MS
8001 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8002 vty_out (vty, " %sreceived",
8003 CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV) ? "and " : "");
8004 vty_out (vty, "%s", VTY_NEWLINE);
538621f2 8005
856ca177
MS
8006 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8007 {
8008 int restart_af_count = 0;
8009
8010 vty_out (vty, " Remote Restart timer is %d seconds%s",
8011 p->v_gr_restart, VTY_NEWLINE);
8012 vty_out (vty, " Address families by peer:%s ", VTY_NEWLINE);
8013
8014 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8015 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8016 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV))
8017 {
8018 vty_out (vty, "%s%s(%s)", restart_af_count ? ", " : "",
8019 afi_safi_print (afi, safi),
8020 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV) ?
8021 "preserved" : "not preserved");
8022 restart_af_count++;
8023 }
8024 if (! restart_af_count)
8025 vty_out (vty, "none");
8026 vty_out (vty, "%s", VTY_NEWLINE);
8027 }
8028 }
8029 }
718e3744 8030 }
8031 }
8032
93406d87 8033 /* graceful restart information */
8034 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8035 || p->t_gr_restart
8036 || p->t_gr_stale)
8037 {
856ca177
MS
8038 json_object *json_grace = NULL;
8039 json_object *json_grace_send = NULL;
8040 json_object *json_grace_recv = NULL;
93406d87 8041 int eor_send_af_count = 0;
8042 int eor_receive_af_count = 0;
8043
856ca177
MS
8044 if (use_json)
8045 {
8046 json_grace = json_object_new_object();
8047 json_grace_send = json_object_new_object();
8048 json_grace_recv = json_object_new_object();
8049
8050 if (p->status == Established)
8051 {
8052 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8053 {
8054 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8055 {
8056 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_SEND))
8057 {
8058 json_object_boolean_true_add(json_grace_send, afi_safi_print (afi, safi));
8059 eor_send_af_count++;
8060 }
8061 }
8062 }
8063 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8064 {
8065 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8066 {
8067 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED))
8068 {
8069 json_object_boolean_true_add(json_grace_recv, afi_safi_print (afi, safi));
8070 eor_receive_af_count++;
8071 }
8072 }
8073 }
8074 }
8075
8076 json_object_object_add(json_grace, "endOfRibSend", json_grace_send);
8077 json_object_object_add(json_grace, "endOfRibRecv", json_grace_recv);
8078
8079 if (p->t_gr_restart)
8080 json_object_int_add(json_grace, "gracefulRestartTimerMsecs", thread_timer_remain_second (p->t_gr_restart) * 1000);
8081
8082 if (p->t_gr_stale)
8083 json_object_int_add(json_grace, "gracefulStalepathTimerMsecs", thread_timer_remain_second (p->t_gr_stale) * 1000);
8084
8085 json_object_object_add(json_neigh, "gracefulRestartInfo", json_grace);
8086 }
8087 else
8088 {
8089 vty_out (vty, " Graceful restart informations:%s", VTY_NEWLINE);
8090 if (p->status == Established)
8091 {
8092 vty_out (vty, " End-of-RIB send: ");
8093 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8094 {
8095 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8096 {
8097 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_SEND))
8098 {
8099 vty_out (vty, "%s%s", eor_send_af_count ? ", " : "",
8100 afi_safi_print (afi, safi));
8101 eor_send_af_count++;
8102 }
8103 }
8104 }
8105 vty_out (vty, "%s", VTY_NEWLINE);
8106 vty_out (vty, " End-of-RIB received: ");
8107 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8108 {
8109 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8110 {
8111 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED))
8112 {
8113 vty_out (vty, "%s%s", eor_receive_af_count ? ", " : "",
8114 afi_safi_print (afi, safi));
8115 eor_receive_af_count++;
8116 }
8117 }
8118 }
8119 vty_out (vty, "%s", VTY_NEWLINE);
8120 }
93406d87 8121
856ca177
MS
8122 if (p->t_gr_restart)
8123 vty_out (vty, " The remaining time of restart timer is %ld%s",
8124 thread_timer_remain_second (p->t_gr_restart), VTY_NEWLINE);
e52702f2 8125
856ca177
MS
8126 if (p->t_gr_stale)
8127 vty_out (vty, " The remaining time of stalepath timer is %ld%s",
8128 thread_timer_remain_second (p->t_gr_stale), VTY_NEWLINE);
8129 }
8130 }
8131 if (use_json)
8132 {
8133 json_object *json_stat = NULL;
8134 json_stat = json_object_new_object();
8135 /* Packet counts. */
8136 json_object_int_add(json_stat, "depthInq", 0);
8137 json_object_int_add(json_stat, "depthOutq", (unsigned long) p->obuf->count);
8138 json_object_int_add(json_stat, "opensSent", p->open_out);
8139 json_object_int_add(json_stat, "opensRecv", p->open_in);
8140 json_object_int_add(json_stat, "notificationsSent", p->notify_out);
8141 json_object_int_add(json_stat, "notificationsRecv", p->notify_in);
8142 json_object_int_add(json_stat, "updatesSent", p->update_out);
8143 json_object_int_add(json_stat, "updatesRecv", p->update_in);
8144 json_object_int_add(json_stat, "keepalivesSent", p->keepalive_out);
8145 json_object_int_add(json_stat, "keepalivesRecv", p->keepalive_in);
8146 json_object_int_add(json_stat, "routeRefreshSent", p->refresh_out);
8147 json_object_int_add(json_stat, "routeRefreshRecv", p->refresh_in);
8148 json_object_int_add(json_stat, "capabilitySent", p->dynamic_cap_out);
8149 json_object_int_add(json_stat, "capabilityRecv", p->dynamic_cap_in);
8150 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);
8151 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);
8152 json_object_object_add(json_neigh, "messageStats", json_stat);
8153 }
8154 else
8155 {
8156 /* Packet counts. */
8157 vty_out (vty, " Message statistics:%s", VTY_NEWLINE);
8158 vty_out (vty, " Inq depth is 0%s", VTY_NEWLINE);
8159 vty_out (vty, " Outq depth is %lu%s", (unsigned long) p->obuf->count, VTY_NEWLINE);
8160 vty_out (vty, " Sent Rcvd%s", VTY_NEWLINE);
8161 vty_out (vty, " Opens: %10d %10d%s", p->open_out, p->open_in, VTY_NEWLINE);
8162 vty_out (vty, " Notifications: %10d %10d%s", p->notify_out, p->notify_in, VTY_NEWLINE);
8163 vty_out (vty, " Updates: %10d %10d%s", p->update_out, p->update_in, VTY_NEWLINE);
8164 vty_out (vty, " Keepalives: %10d %10d%s", p->keepalive_out, p->keepalive_in, VTY_NEWLINE);
8165 vty_out (vty, " Route Refresh: %10d %10d%s", p->refresh_out, p->refresh_in, VTY_NEWLINE);
8166 vty_out (vty, " Capability: %10d %10d%s", p->dynamic_cap_out, p->dynamic_cap_in, VTY_NEWLINE);
8167 vty_out (vty, " Total: %10d %10d%s", p->open_out + p->notify_out +
8168 p->update_out + p->keepalive_out + p->refresh_out + p->dynamic_cap_out,
8169 p->open_in + p->notify_in + p->update_in + p->keepalive_in + p->refresh_in +
8170 p->dynamic_cap_in, VTY_NEWLINE);
718e3744 8171 }
8172
856ca177
MS
8173 if (use_json)
8174 {
8175 /* advertisement-interval */
8176 json_object_int_add(json_neigh, "minBtwnAdvertisementRunsTimerMsecs", p->v_routeadv * 1000);
718e3744 8177
856ca177
MS
8178 /* Update-source. */
8179 if (p->update_if || p->update_source)
8180 {
8181 if (p->update_if)
8182 json_object_string_add(json_neigh, "updateSource", p->update_if);
8183 else if (p->update_source)
8184 json_object_string_add(json_neigh, "updateSource", sockunion2str (p->update_source, buf1, SU_ADDRSTRLEN));
8185 }
856ca177
MS
8186 }
8187 else
8188 {
8189 /* advertisement-interval */
8190 vty_out (vty, " Minimum time between advertisement runs is %d seconds%s",
8191 p->v_routeadv, VTY_NEWLINE);
8192
8193 /* Update-source. */
8194 if (p->update_if || p->update_source)
8195 {
8196 vty_out (vty, " Update source is ");
8197 if (p->update_if)
8198 vty_out (vty, "%s", p->update_if);
8199 else if (p->update_source)
8200 vty_out (vty, "%s", sockunion2str (p->update_source, buf1, SU_ADDRSTRLEN));
8201 vty_out (vty, "%s", VTY_NEWLINE);
8202 }
8203
856ca177
MS
8204 vty_out (vty, "%s", VTY_NEWLINE);
8205 }
718e3744 8206
8207 /* Address Family Information */
856ca177
MS
8208 json_object *json_hold = NULL;
8209
8210 if (use_json)
8211 json_hold = json_object_new_object();
8212
538621f2 8213 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8214 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8215 if (p->afc[afi][safi])
856ca177 8216 bgp_show_peer_afi (vty, p, afi, safi, use_json, json_hold);
718e3744 8217
856ca177
MS
8218 if (use_json)
8219 {
8220 json_object_int_add(json_hold, "connectionsEstablished", p->established);
8221 json_object_int_add(json_hold, "connectionsDropped", p->dropped);
8222 }
8223 else
8224 vty_out (vty, " Connections established %d; dropped %d%s", p->established, p->dropped,
8225 VTY_NEWLINE);
718e3744 8226
d6661008 8227 if (! p->last_reset)
856ca177
MS
8228 {
8229 if (use_json)
8230 json_object_string_add(json_hold, "lastReset", "never");
8231 else
8232 vty_out (vty, " Last reset never%s", VTY_NEWLINE);
8233 }
e0701b79 8234 else
d6661008 8235 {
856ca177
MS
8236 if (use_json)
8237 {
8238 time_t uptime;
8239 struct tm *tm;
8240
8241 uptime = bgp_clock();
8242 uptime -= p->resettime;
8243 tm = gmtime(&uptime);
8244 json_object_int_add(json_hold, "lastResetTimerMsecs", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8245 json_object_string_add(json_hold, "lastResetDueTo", peer_down_str[(int) p->last_reset]);
8246 if (p->last_reset_cause_size)
8247 {
39e871e6
ST
8248 char errorcodesubcode_hexstr[5];
8249 sprintf(errorcodesubcode_hexstr, "%02X%02X", p->notify.code, p->notify.subcode);
8250 json_object_string_add(json_hold, "lastErrorCodeSubcode", errorcodesubcode_hexstr);
856ca177
MS
8251 }
8252 }
8253 else
d6661008 8254 {
3a8c7ba1
DW
8255 vty_out (vty, " Last reset %s, ",
8256 peer_uptime (p->resettime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8257
8258 if (p->last_reset == PEER_DOWN_NOTIFY_SEND ||
8259 p->last_reset == PEER_DOWN_NOTIFY_RECEIVED)
8260 {
8261 code_str = bgp_notify_code_str(p->notify.code);
8262 subcode_str = bgp_notify_subcode_str(p->notify.code, p->notify.subcode);
8263 vty_out (vty, "due to NOTIFICATION %s (%s%s)%s",
8264 p->last_reset == PEER_DOWN_NOTIFY_SEND ? "sent" : "received",
8265 code_str, subcode_str, VTY_NEWLINE);
8266 }
8267 else
8268 {
8269 vty_out (vty, "due to %s%s",
8270 peer_down_str[(int) p->last_reset], VTY_NEWLINE);
8271 }
856ca177
MS
8272
8273 if (p->last_reset_cause_size)
d6661008 8274 {
856ca177
MS
8275 msg = p->last_reset_cause;
8276 vty_out(vty, " Message received that caused BGP to send a NOTIFICATION:%s ", VTY_NEWLINE);
8277 for (i = 1; i <= p->last_reset_cause_size; i++)
8278 {
8279 vty_out(vty, "%02X", *msg++);
d6661008 8280
856ca177
MS
8281 if (i != p->last_reset_cause_size)
8282 {
8283 if (i % 16 == 0)
8284 {
8285 vty_out(vty, "%s ", VTY_NEWLINE);
8286 }
8287 else if (i % 4 == 0)
8288 {
8289 vty_out(vty, " ");
8290 }
8291 }
8292 }
8293 vty_out(vty, "%s", VTY_NEWLINE);
d6661008 8294 }
d6661008
DS
8295 }
8296 }
848973c7 8297
718e3744 8298 if (CHECK_FLAG (p->sflags, PEER_STATUS_PREFIX_OVERFLOW))
8299 {
856ca177
MS
8300 if (use_json)
8301 json_object_boolean_true_add(json_hold, "prefixesConfigExceedMax");
8302 else
8303 vty_out (vty, " Peer had exceeded the max. no. of prefixes configured.%s", VTY_NEWLINE);
0a486e5f 8304
8305 if (p->t_pmax_restart)
856ca177
MS
8306 {
8307 if (use_json)
8308 {
e8f7da3a 8309 json_object_boolean_true_add(json_hold, "reducePrefixNumFrom");
856ca177
MS
8310 json_object_int_add(json_hold, "restartInTimerMsec", thread_timer_remain_second (p->t_pmax_restart) * 1000);
8311 }
8312 else
8313 vty_out (vty, " Reduce the no. of prefix from %s, will restart in %ld seconds%s",
8314 p->host, thread_timer_remain_second (p->t_pmax_restart),
8315 VTY_NEWLINE);
8316 }
0a486e5f 8317 else
856ca177
MS
8318 {
8319 if (use_json)
e8f7da3a 8320 json_object_boolean_true_add(json_hold, "reducePrefixNumAndClearIpBgp");
856ca177
MS
8321 else
8322 vty_out (vty, " Reduce the no. of prefix and clear ip bgp %s to restore peering%s",
8323 p->host, VTY_NEWLINE);
8324 }
718e3744 8325 }
8326
856ca177
MS
8327 if (use_json)
8328 json_object_object_add(json_neigh, "addressFamilyInfo", json_hold);
8329
f5a4827d 8330 /* EBGP Multihop and GTSM */
6d85b15b 8331 if (p->sort != BGP_PEER_IBGP)
f5a4827d 8332 {
856ca177
MS
8333 if (use_json)
8334 {
8335 if (p->gtsm_hops > 0)
8336 json_object_int_add(json_neigh, "externalBgpNbrMaxHopsAway", p->gtsm_hops);
8337 else if (p->ttl > 1)
8338 json_object_int_add(json_neigh, "externalBgpNbrMaxHopsAway", p->ttl);
8339 }
8340 else
8341 {
8342 if (p->gtsm_hops > 0)
8343 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
8344 p->gtsm_hops, VTY_NEWLINE);
8345 else if (p->ttl > 1)
8346 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
8347 p->ttl, VTY_NEWLINE);
8348 }
f5a4827d 8349 }
5d804b43
PM
8350 else
8351 {
8352 if (p->gtsm_hops > 0)
856ca177
MS
8353 {
8354 if (use_json)
8355 json_object_int_add(json_neigh, "internalBgpNbrMaxHopsAway", p->gtsm_hops);
8356 else
8357 vty_out (vty, " Internal BGP neighbor may be up to %d hops away.%s",
8358 p->gtsm_hops, VTY_NEWLINE);
8359 }
5d804b43 8360 }
718e3744 8361
8362 /* Local address. */
8363 if (p->su_local)
8364 {
856ca177
MS
8365 if (use_json)
8366 {
8367 json_object_string_add(json_neigh, "hostLocal", sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN));
8368 json_object_int_add(json_neigh, "portLocal", ntohs (p->su_local->sin.sin_port));
8369 }
8370 else
8371 vty_out (vty, "Local host: %s, Local port: %d%s",
8372 sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN),
8373 ntohs (p->su_local->sin.sin_port),
8374 VTY_NEWLINE);
718e3744 8375 }
e52702f2 8376
718e3744 8377 /* Remote address. */
8378 if (p->su_remote)
8379 {
856ca177
MS
8380 if (use_json)
8381 {
8382 json_object_string_add(json_neigh, "hostForeign", sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN));
8383 json_object_int_add(json_neigh, "portForeign", ntohs (p->su_remote->sin.sin_port));
8384 }
8385 else
8386 vty_out (vty, "Foreign host: %s, Foreign port: %d%s",
718e3744 8387 sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN),
8388 ntohs (p->su_remote->sin.sin_port),
8389 VTY_NEWLINE);
8390 }
8391
8392 /* Nexthop display. */
8393 if (p->su_local)
8394 {
856ca177
MS
8395 if (use_json)
8396 {
8397 json_object_string_add(json_neigh, "nexthop", inet_ntop (AF_INET, &p->nexthop.v4, buf1, BUFSIZ));
718e3744 8398#ifdef HAVE_IPV6
856ca177
MS
8399 json_object_string_add(json_neigh, "nexthopGlobal", inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, BUFSIZ));
8400 json_object_string_add(json_neigh, "nexthopLocal", inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, BUFSIZ));
8401 if (p->shared_network)
8402 json_object_string_add(json_neigh, "bgpConnection", "sharedNetwork");
8403 else
8404 json_object_string_add(json_neigh, "bgpConnection", "nonSharedNetwork");
8405#endif /* HAVE_IPV6 */
8406 }
8407 else
8408 {
8409 vty_out (vty, "Nexthop: %s%s",
8410 inet_ntop (AF_INET, &p->nexthop.v4, buf1, BUFSIZ),
8411 VTY_NEWLINE);
8412#ifdef HAVE_IPV6
8413 vty_out (vty, "Nexthop global: %s%s",
8414 inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, BUFSIZ),
8415 VTY_NEWLINE);
8416 vty_out (vty, "Nexthop local: %s%s",
8417 inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, BUFSIZ),
8418 VTY_NEWLINE);
8419 vty_out (vty, "BGP connection: %s%s",
8420 p->shared_network ? "shared network" : "non shared network",
8421 VTY_NEWLINE);
718e3744 8422#endif /* HAVE_IPV6 */
856ca177 8423 }
718e3744 8424 }
8425
8426 /* Timer information. */
856ca177
MS
8427 if (use_json)
8428 {
39e871e6 8429 json_object_int_add(json_neigh, "connectRetryTimer", p->v_connect);
dd9275d6
ST
8430 if (p->status == Established && p->rtt)
8431 json_object_int_add(json_neigh, "estimatedRttInMsecs", p->rtt);
856ca177
MS
8432 if (p->t_start)
8433 json_object_int_add(json_neigh, "nextStartTimerDueInMsecs", thread_timer_remain_second (p->t_start) * 1000);
8434 if (p->t_connect)
8435 json_object_int_add(json_neigh, "nextConnectTimerDueInMsecs", thread_timer_remain_second (p->t_connect) * 1000);
8436 if (p->t_routeadv)
8437 {
8438 json_object_int_add(json_neigh, "mraiInterval", p->v_routeadv);
8439 json_object_int_add(json_neigh, "mraiTimerExpireInMsecs", thread_timer_remain_second (p->t_routeadv) * 1000);
8440 }
cb1faec9 8441
856ca177
MS
8442 if (p->t_read)
8443 json_object_string_add(json_neigh, "readThread", "on");
8444 else
8445 json_object_string_add(json_neigh, "readThread", "off");
8446 if (p->t_write)
8447 json_object_string_add(json_neigh, "writeThread", "on");
8448 else
8449 json_object_string_add(json_neigh, "writeThread", "off");
8450 }
8451 else
8452 {
39e871e6
ST
8453 vty_out (vty, "BGP Connect Retry Timer in Seconds: %d%s",
8454 p->v_connect, VTY_NEWLINE);
dd9275d6
ST
8455 if (p->status == Established && p->rtt)
8456 vty_out (vty, "Estimated round trip time: %d ms%s",
8457 p->rtt, VTY_NEWLINE);
856ca177
MS
8458 if (p->t_start)
8459 vty_out (vty, "Next start timer due in %ld seconds%s",
8460 thread_timer_remain_second (p->t_start), VTY_NEWLINE);
8461 if (p->t_connect)
8462 vty_out (vty, "Next connect timer due in %ld seconds%s",
8463 thread_timer_remain_second (p->t_connect), VTY_NEWLINE);
8464 if (p->t_routeadv)
8465 vty_out (vty, "MRAI (interval %u) timer expires in %ld seconds%s",
8466 p->v_routeadv, thread_timer_remain_second (p->t_routeadv),
8467 VTY_NEWLINE);
8468
8469 vty_out (vty, "Read thread: %s Write thread: %s%s",
8470 p->t_read ? "on" : "off",
8471 p->t_write ? "on" : "off",
8472 VTY_NEWLINE);
8473 }
718e3744 8474
8475 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
8476 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
856ca177
MS
8477 bgp_capability_vty_out (vty, p, use_json, json_neigh);
8478
8479 if (!use_json)
8480 vty_out (vty, "%s", VTY_NEWLINE);
c43ed2e4
DS
8481
8482 /* BFD information. */
856ca177
MS
8483 bgp_bfd_show_info(vty, p, use_json, json_neigh);
8484
8485 if (use_json)
8486 {
8487 if (p->conf_if) /* Configured interface name. */
8488 json_object_object_add(json, p->conf_if, json_neigh);
8489 else /* Configured IP address. */
8490 json_object_object_add(json, p->host, json_neigh);
8491 }
718e3744 8492}
8493
94f2b392 8494static int
856ca177
MS
8495bgp_show_neighbor (struct vty *vty, struct bgp *bgp, enum show_type type,
8496 union sockunion *su, const char *conf_if, u_char use_json, json_object *json)
718e3744 8497{
1eb8ef25 8498 struct listnode *node, *nnode;
718e3744 8499 struct peer *peer;
8500 int find = 0;
8501
1eb8ef25 8502 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 8503 {
1ff9a340
DS
8504 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
8505 continue;
8506
718e3744 8507 switch (type)
856ca177
MS
8508 {
8509 case show_all:
e8f7da3a 8510 bgp_show_peer (vty, peer, use_json, json);
856ca177
MS
8511 break;
8512 case show_peer:
8513 if (conf_if)
8514 {
4873b3b9
DW
8515 if ((peer->conf_if && !strcmp(peer->conf_if, conf_if)) ||
8516 (peer->hostname && !strcmp(peer->hostname, conf_if)))
856ca177
MS
8517 {
8518 find = 1;
e8f7da3a 8519 bgp_show_peer (vty, peer, use_json, json);
856ca177
MS
8520 }
8521 }
8522 else
8523 {
8524 if (sockunion_same (&peer->su, su))
8525 {
8526 find = 1;
e8f7da3a 8527 bgp_show_peer (vty, peer, use_json, json);
856ca177
MS
8528 }
8529 }
8530 break;
718e3744 8531 }
8532 }
8533
8534 if (type == show_peer && ! find)
856ca177
MS
8535 {
8536 if (use_json)
8537 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
8538 else
8539 vty_out (vty, "%% No such neighbor%s", VTY_NEWLINE);
8540 }
8541
8542 if (use_json)
8543 {
2aac5767 8544 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
856ca177
MS
8545 json_object_free(json);
8546 }
8547 else
8548 {
8549 vty_out (vty, "%s", VTY_NEWLINE);
8550 }
8551
718e3744 8552 return CMD_SUCCESS;
8553}
8554
f186de26 8555static void
8556bgp_show_all_instances_neighbors_vty (struct vty *vty, u_char use_json)
8557{
8558 struct listnode *node, *nnode;
8559 struct bgp *bgp;
8560 json_object *json = NULL;
9f689658
DD
8561 int is_first = 1;
8562
8563 if (use_json)
8564 vty_out (vty, "{%s", VTY_NEWLINE);
f186de26 8565
8566 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
8567 {
f186de26 8568 if (use_json)
9f689658
DD
8569 {
8570 if (!(json = json_object_new_object()))
8571 {
8572 zlog_err("Unable to allocate memory for JSON object");
8573 vty_out (vty,
8574 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
8575 VTY_NEWLINE);
8576 return;
8577 }
8578
8579 json_object_int_add(json, "vrfId",
8580 (bgp->vrf_id == VRF_UNKNOWN)
8581 ? -1 : bgp->vrf_id);
8582 json_object_string_add(json, "vrfName",
8583 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8584 ? "Default" : bgp->name);
8585
8586 if (! is_first)
8587 vty_out (vty, ",%s", VTY_NEWLINE);
8588 else
8589 is_first = 0;
8590
8591 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8592 ? "Default" : bgp->name);
8593 }
8594 else
8595 {
8596 vty_out (vty, "%sInstance %s:%s",
8597 VTY_NEWLINE,
8598 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
8599 ? "Default" : bgp->name,
8600 VTY_NEWLINE);
8601 }
f186de26 8602 bgp_show_neighbor (vty, bgp, show_all, NULL, NULL, use_json, json);
8603 }
9f689658
DD
8604
8605 if (use_json)
8606 vty_out (vty, "}%s", VTY_NEWLINE);
f186de26 8607}
8608
4fb25c53
DW
8609static int
8610bgp_show_neighbor_vty (struct vty *vty, const char *name,
8611 enum show_type type, const char *ip_str, u_char use_json)
8612{
8613 int ret;
8614 struct bgp *bgp;
8615 union sockunion su;
8616 json_object *json = NULL;
8617
8618 if (use_json)
8619 json = json_object_new_object();
8620
8621 if (name)
8622 {
8623 if (strmatch(name, "all"))
8624 {
8625 bgp_show_all_instances_neighbors_vty (vty, use_json);
8626 return CMD_SUCCESS;
8627 }
8628 else
8629 {
8630 bgp = bgp_lookup_by_name (name);
8631 if (! bgp)
8632 {
8633 if (use_json)
8634 {
8635 json_object_boolean_true_add(json, "bgpNoSuchInstance");
e52702f2 8636 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
4fb25c53
DW
8637 json_object_free(json);
8638 }
8639 else
8640 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
8641
8642 return CMD_WARNING;
8643 }
8644 }
8645 }
8646 else
8647 {
8648 bgp = bgp_get_default ();
8649 }
8650
8651 if (bgp)
8652 {
8653 if (ip_str)
8654 {
8655 ret = str2sockunion (ip_str, &su);
8656 if (ret < 0)
8657 bgp_show_neighbor (vty, bgp, type, NULL, ip_str, use_json, json);
8658 else
8659 bgp_show_neighbor (vty, bgp, type, &su, NULL, use_json, json);
8660 }
8661 else
8662 {
8663 bgp_show_neighbor (vty, bgp, type, NULL, NULL, use_json, json);
8664 }
8665 }
8666
8667 return CMD_SUCCESS;
8668}
8669
718e3744 8670/* "show ip bgp neighbors" commands. */
8671DEFUN (show_ip_bgp_neighbors,
8672 show_ip_bgp_neighbors_cmd,
5bf15956 8673 "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 8674 SHOW_STR
8675 IP_STR
8676 BGP_STR
5bf15956 8677 BGP_INSTANCE_ALL_HELP_STR
8c3deaae
QY
8678 "Address Family\n"
8679 "Address Family\n"
718e3744 8680 "Detailed information on TCP and BGP neighbor connections\n"
8681 "Neighbor to display information about\n"
a80beece 8682 "Neighbor to display information about\n"
856ca177
MS
8683 "Neighbor on bgp configured interface\n"
8684 "JavaScript Object Notation\n")
718e3744 8685{
5bf15956
DW
8686 char *vrf = NULL;
8687 char *sh_arg = NULL;
8688 enum show_type sh_type;
718e3744 8689
5bf15956 8690 u_char uj = use_json(argc, argv);
718e3744 8691
630a298c 8692 int idx = 0;
718e3744 8693
630a298c
QY
8694 if (argv_find (argv, argc, "WORD", &idx))
8695 vrf = argv[idx]->arg;
718e3744 8696
630a298c
QY
8697 if (argv_find (argv, argc, "A.B.C.D", &idx) || argv_find (argv, argc, "X:X::X:X", &idx) ||
8698 argv_find (argv, argc, "WORD", &idx))
8699 {
8700 sh_type = show_peer;
8701 sh_arg = argv[idx]->arg;
8702 }
5bf15956 8703 else
630a298c 8704 sh_type = show_all;
856ca177 8705
5bf15956 8706 return bgp_show_neighbor_vty (vty, vrf, sh_type, sh_arg, uj);
718e3744 8707}
8708
718e3744 8709/* Show BGP's AS paths internal data. There are both `show ip bgp
8710 paths' and `show ip mbgp paths'. Those functions results are the
8711 same.*/
f412b39a 8712DEFUN (show_ip_bgp_paths,
718e3744 8713 show_ip_bgp_paths_cmd,
8714 "show ip bgp paths",
8715 SHOW_STR
8716 IP_STR
8717 BGP_STR
8718 "Path information\n")
8719{
8720 vty_out (vty, "Address Refcnt Path%s", VTY_NEWLINE);
8721 aspath_print_all_vty (vty);
8722 return CMD_SUCCESS;
8723}
8724
f412b39a 8725DEFUN (show_ip_bgp_ipv4_paths,
718e3744 8726 show_ip_bgp_ipv4_paths_cmd,
6147e2c6 8727 "show ip bgp ipv4 <unicast|multicast> paths",
718e3744 8728 SHOW_STR
8729 IP_STR
8730 BGP_STR
8c3deaae 8731 "Address Family\n"
718e3744 8732 "Address Family modifier\n"
8733 "Address Family modifier\n"
8734 "Path information\n")
8735{
8736 vty_out (vty, "Address Refcnt Path\r\n");
8737 aspath_print_all_vty (vty);
8738
8739 return CMD_SUCCESS;
8740}
6b0655a2 8741
718e3744 8742#include "hash.h"
8743
94f2b392 8744static void
718e3744 8745community_show_all_iterator (struct hash_backet *backet, struct vty *vty)
8746{
8747 struct community *com;
8748
8749 com = (struct community *) backet->data;
6c4f4e6e 8750 vty_out (vty, "[%p] (%ld) %s%s", (void *)backet, com->refcnt,
718e3744 8751 community_str (com), VTY_NEWLINE);
8752}
8753
8754/* Show BGP's community internal data. */
f412b39a 8755DEFUN (show_ip_bgp_community_info,
718e3744 8756 show_ip_bgp_community_info_cmd,
8757 "show ip bgp community-info",
8758 SHOW_STR
8759 IP_STR
8760 BGP_STR
8761 "List all bgp community information\n")
8762{
8763 vty_out (vty, "Address Refcnt Community%s", VTY_NEWLINE);
8764
e52702f2 8765 hash_iterate (community_hash (),
718e3744 8766 (void (*) (struct hash_backet *, void *))
8767 community_show_all_iterator,
8768 vty);
8769
8770 return CMD_SUCCESS;
8771}
8772
f412b39a 8773DEFUN (show_ip_bgp_attr_info,
718e3744 8774 show_ip_bgp_attr_info_cmd,
8775 "show ip bgp attribute-info",
8776 SHOW_STR
8777 IP_STR
8778 BGP_STR
8779 "List all bgp attribute information\n")
8780{
8781 attr_show_all (vty);
8782 return CMD_SUCCESS;
8783}
6b0655a2 8784
f186de26 8785static void
8786bgp_show_all_instances_updgrps_vty (struct vty *vty, afi_t afi, safi_t safi)
8787{
8788 struct listnode *node, *nnode;
8789 struct bgp *bgp;
8790
8791 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
8792 {
8793 vty_out (vty, "%sInstance %s:%s",
8794 VTY_NEWLINE,
8795 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) ? "Default" : bgp->name,
8796 VTY_NEWLINE);
8797 update_group_show(bgp, afi, safi, vty, 0);
8798 }
8799}
8800
4fb25c53
DW
8801static int
8802bgp_show_update_groups(struct vty *vty, const char *name,
8803 int afi, int safi,
8804 uint64_t subgrp_id)
8805{
8806 struct bgp *bgp;
8807
8808 if (name)
8809 {
8810 if (strmatch (name, "all"))
8811 {
8812 bgp_show_all_instances_updgrps_vty (vty, afi, safi);
8813 return CMD_SUCCESS;
8814 }
8815 else
8816 {
8817 bgp = bgp_lookup_by_name (name);
8818 }
8819 }
8820 else
8821 {
8822 bgp = bgp_get_default ();
8823 }
8824
8825 if (bgp)
8826 update_group_show(bgp, afi, safi, vty, subgrp_id);
8827 return CMD_SUCCESS;
8828}
8829
8fe8a7f6
DS
8830DEFUN (show_ip_bgp_updgrps,
8831 show_ip_bgp_updgrps_cmd,
ae19d7dd 8832 "show [ip] bgp [<view|vrf> WORD] [<ipv4 [<unicast|multicast>]|ipv6 [<unicast|multicast>]|encap [unicast]|vpnv4 [unicast]>] update-groups [SUBGROUP-ID]",
8386ac43 8833 SHOW_STR
8834 IP_STR
8835 BGP_STR
8836 BGP_INSTANCE_HELP_STR
8c3deaae 8837 "Address Family\n"
5bf15956 8838 "Address Family modifier\n"
5bf15956 8839 "Address Family modifier\n"
8c3deaae 8840 "Address Family\n"
5bf15956 8841 "Address Family modifier\n"
0c7b1b01 8842 "Address Family modifier\n"
8c3deaae 8843 "Address Family\n"
5bf15956 8844 "Address Family modifier\n"
8c3deaae 8845 "Address Family\n"
5bf15956
DW
8846 "Address Family modifier\n"
8847 "Detailed info about dynamic update groups\n"
8848 "Specific subgroup to display detailed info for\n")
8386ac43 8849{
5bf15956 8850 char *vrf = NULL;
ae19d7dd
QY
8851 afi_t afi = AFI_IP6;
8852 safi_t safi = SAFI_UNICAST;
5bf15956
DW
8853 uint64_t subgrp_id = 0;
8854
ae19d7dd
QY
8855 int idx = 0;
8856
8857 /* show [ip] bgp */
8858 if (argv_find (argv, argc, "ip", &idx))
8859 afi = AFI_IP;
8860 /* [<view|vrf> WORD] */
8861 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
8862 vrf = argv[++idx]->arg;
8863 /* [<ipv4 [<unicast|multicast>]|ipv6 [<unicast|multicast>]|encap [unicast]|vpnv4 [unicast]>] */
8864 if (argv_find (argv, argc, "ipv4", &idx) || argv_find (argv, argc, "ipv6", &idx))
8865 {
8866 afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP;
8867 if (argv_find (argv, argc, "unicast", &idx) || argv_find (argv, argc, "multicast", &idx))
8868 safi = strmatch (argv[idx]->text, "unicast") ? SAFI_UNICAST : SAFI_MULTICAST;
8869 }
8870 else if (argv_find (argv, argc, "encap", &idx) || argv_find (argv, argc, "vpnv4", &idx))
8871 {
8872 afi = AFI_IP;
8873 safi = strmatch (argv[idx]->text, "encap") ? SAFI_ENCAP : SAFI_MPLS_VPN;
8874 // advance idx if necessary
8875 argv_find (argv, argc, "unicast", &idx);
8876 }
5bf15956 8877
ae19d7dd
QY
8878 /* get subgroup id, if provided */
8879 idx = argc - 1;
8880 if (argv[idx]->type == VARIABLE_TKN)
8881 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx]->arg);
5bf15956
DW
8882
8883 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
8884}
8885
f186de26 8886DEFUN (show_bgp_instance_all_ipv6_updgrps,
8887 show_bgp_instance_all_ipv6_updgrps_cmd,
9ccf14f7 8888 "show bgp <view|vrf> all update-groups",
f186de26 8889 SHOW_STR
8890 BGP_STR
8891 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 8892 "Detailed info about dynamic update groups\n")
f186de26 8893{
8894 bgp_show_all_instances_updgrps_vty (vty, AFI_IP6, SAFI_UNICAST);
8895 return CMD_SUCCESS;
8896}
8897
5bf15956
DW
8898DEFUN (show_bgp_updgrps_stats,
8899 show_bgp_updgrps_stats_cmd,
8900 "show bgp update-groups statistics",
3f9c7369
DS
8901 SHOW_STR
8902 BGP_STR
0c7b1b01 8903 "Detailed info about dynamic update groups\n"
3f9c7369
DS
8904 "Statistics\n")
8905{
8906 struct bgp *bgp;
8907
8908 bgp = bgp_get_default();
8909 if (bgp)
8910 update_group_show_stats(bgp, vty);
8911
8912 return CMD_SUCCESS;
8913}
8914
8386ac43 8915DEFUN (show_bgp_instance_updgrps_stats,
8916 show_bgp_instance_updgrps_stats_cmd,
9ccf14f7 8917 "show bgp <view|vrf> WORD update-groups statistics",
8386ac43 8918 SHOW_STR
8919 BGP_STR
8920 BGP_INSTANCE_HELP_STR
0c7b1b01 8921 "Detailed info about dynamic update groups\n"
8386ac43 8922 "Statistics\n")
8923{
c500ae40 8924 int idx_word = 3;
8386ac43 8925 struct bgp *bgp;
8926
c500ae40 8927 bgp = bgp_lookup_by_name (argv[idx_word]->arg);
8386ac43 8928 if (bgp)
8929 update_group_show_stats(bgp, vty);
8930
8931 return CMD_SUCCESS;
8932}
8933
3f9c7369 8934static void
8386ac43 8935show_bgp_updgrps_adj_info_aux (struct vty *vty, const char *name,
8936 afi_t afi, safi_t safi,
f43e655e 8937 const char *what, uint64_t subgrp_id)
3f9c7369
DS
8938{
8939 struct bgp *bgp;
8386ac43 8940
8941 if (name)
8942 bgp = bgp_lookup_by_name (name);
8943 else
8944 bgp = bgp_get_default ();
8945
3f9c7369
DS
8946 if (bgp)
8947 {
8948 if (!strcmp(what, "advertise-queue"))
8949 update_group_show_adj_queue(bgp, afi, safi, vty, subgrp_id);
8950 else if (!strcmp(what, "advertised-routes"))
8951 update_group_show_advertised(bgp, afi, safi, vty, subgrp_id);
8952 else if (!strcmp(what, "packet-queue"))
8953 update_group_show_packet_queue(bgp, afi, safi, vty, subgrp_id);
8954 }
8955}
8956
8957DEFUN (show_ip_bgp_updgrps_adj,
8958 show_ip_bgp_updgrps_adj_cmd,
6147e2c6 8959 "show ip bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
8960 SHOW_STR
8961 IP_STR
8962 BGP_STR
0c7b1b01 8963 "Detailed info about dynamic update groups\n"
3f9c7369
DS
8964 "Advertisement queue\n"
8965 "Announced routes\n"
8966 "Packet queue\n")
8fe8a7f6 8967
3f9c7369 8968{
c500ae40
DW
8969 int idx_type = 4;
8970 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, 0);
8386ac43 8971 return CMD_SUCCESS;
8972}
8973
8974DEFUN (show_ip_bgp_instance_updgrps_adj,
8975 show_ip_bgp_instance_updgrps_adj_cmd,
9ccf14f7 8976 "show ip bgp <view|vrf> WORD update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 8977 SHOW_STR
8978 IP_STR
8979 BGP_STR
8980 BGP_INSTANCE_HELP_STR
0c7b1b01 8981 "Detailed info about dynamic update groups\n"
8386ac43 8982 "Advertisement queue\n"
8983 "Announced routes\n"
8984 "Packet queue\n")
8985
8986{
c500ae40
DW
8987 int idx_word = 4;
8988 int idx_type = 6;
8989 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, 0);
3f9c7369
DS
8990 return CMD_SUCCESS;
8991}
8992
8993DEFUN (show_bgp_updgrps_afi_adj,
8994 show_bgp_updgrps_afi_adj_cmd,
6147e2c6 8995 "show bgp <ipv4|ipv6> <unicast|multicast> update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
8996 SHOW_STR
8997 BGP_STR
8c3deaae
QY
8998 "Address Family\n"
8999 "Address Family\n"
3f9c7369
DS
9000 "Address Family modifier\n"
9001 "Address Family modifier\n"
0c7b1b01 9002 "Detailed info about dynamic update groups\n"
3f9c7369
DS
9003 "Advertisement queue\n"
9004 "Announced routes\n"
8fe8a7f6
DS
9005 "Packet queue\n"
9006 "Specific subgroup info wanted for\n")
3f9c7369 9007{
c500ae40
DW
9008 int idx_afi = 2;
9009 int idx_safi = 3;
9010 int idx_type = 5;
3f9c7369
DS
9011 afi_t afi;
9012 safi_t safi;
9013
c500ae40
DW
9014 afi = (strcmp(argv[idx_afi]->arg, "ipv4") == 0) ? AFI_IP : AFI_IP6;
9015 safi = (strncmp (argv[idx_safi]->arg, "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
9016 show_bgp_updgrps_adj_info_aux(vty, NULL, afi, safi, argv[idx_type]->arg, 0);
8fe8a7f6 9017 return CMD_SUCCESS;
3f9c7369
DS
9018}
9019
9020DEFUN (show_bgp_updgrps_adj,
9021 show_bgp_updgrps_adj_cmd,
6147e2c6 9022 "show bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
9023 SHOW_STR
9024 BGP_STR
0c7b1b01 9025 "Detailed info about dynamic update groups\n"
3f9c7369
DS
9026 "Advertisement queue\n"
9027 "Announced routes\n"
9028 "Packet queue\n")
9029{
c500ae40
DW
9030 int idx_type = 3;
9031 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, 0);
8386ac43 9032 return CMD_SUCCESS;
9033}
9034
9035DEFUN (show_bgp_instance_updgrps_adj,
9036 show_bgp_instance_updgrps_adj_cmd,
9ccf14f7 9037 "show bgp <view|vrf> WORD update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 9038 SHOW_STR
9039 BGP_STR
9040 BGP_INSTANCE_HELP_STR
0c7b1b01 9041 "Detailed info about dynamic update groups\n"
8386ac43 9042 "Advertisement queue\n"
9043 "Announced routes\n"
9044 "Packet queue\n")
9045{
c500ae40
DW
9046 int idx_word = 3;
9047 int idx_type = 5;
9048 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, 0);
3f9c7369
DS
9049 return CMD_SUCCESS;
9050}
9051
9052DEFUN (show_ip_bgp_updgrps_adj_s,
8fe8a7f6 9053 show_ip_bgp_updgrps_adj_s_cmd,
6147e2c6 9054 "show ip bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
9055 SHOW_STR
9056 IP_STR
9057 BGP_STR
0c7b1b01 9058 "Detailed info about dynamic update groups\n"
8fe8a7f6 9059 "Specific subgroup to display info for\n"
3f9c7369
DS
9060 "Advertisement queue\n"
9061 "Announced routes\n"
9062 "Packet queue\n")
3f9c7369 9063
3f9c7369 9064{
5bf15956 9065 int idx_subgroup_id = 4;
c500ae40 9066 int idx_type = 5;
f43e655e 9067 uint64_t subgrp_id;
8fe8a7f6 9068
5bf15956 9069 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8fe8a7f6 9070
5bf15956 9071 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
8386ac43 9072 return CMD_SUCCESS;
9073}
9074
9075DEFUN (show_ip_bgp_instance_updgrps_adj_s,
9076 show_ip_bgp_instance_updgrps_adj_s_cmd,
9ccf14f7 9077 "show ip bgp <view|vrf> WORD update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 9078 SHOW_STR
9079 IP_STR
9080 BGP_STR
9081 BGP_INSTANCE_HELP_STR
0c7b1b01 9082 "Detailed info about dynamic update groups\n"
8386ac43 9083 "Specific subgroup to display info for\n"
9084 "Advertisement queue\n"
9085 "Announced routes\n"
9086 "Packet queue\n")
9087
9088{
5bf15956
DW
9089 int idx_vrf = 4;
9090 int idx_subgroup_id = 6;
c500ae40 9091 int idx_type = 7;
f43e655e 9092 uint64_t subgrp_id;
8386ac43 9093
5bf15956 9094 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8386ac43 9095
5bf15956 9096 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
3f9c7369
DS
9097 return CMD_SUCCESS;
9098}
9099
8fe8a7f6
DS
9100DEFUN (show_bgp_updgrps_afi_adj_s,
9101 show_bgp_updgrps_afi_adj_s_cmd,
6147e2c6 9102 "show bgp <ipv4|ipv6> <unicast|multicast> update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
9103 SHOW_STR
9104 BGP_STR
8c3deaae
QY
9105 "Address Family\n"
9106 "Address Family\n"
3f9c7369
DS
9107 "Address Family modifier\n"
9108 "Address Family modifier\n"
0c7b1b01 9109 "Detailed info about dynamic update groups\n"
8fe8a7f6 9110 "Specific subgroup to display info for\n"
3f9c7369
DS
9111 "Advertisement queue\n"
9112 "Announced routes\n"
8fe8a7f6
DS
9113 "Packet queue\n"
9114 "Specific subgroup info wanted for\n")
3f9c7369 9115{
c500ae40
DW
9116 int idx_afi = 2;
9117 int idx_safi = 3;
5bf15956 9118 int idx_subgroup_id = 5;
c500ae40 9119 int idx_type = 6;
3f9c7369
DS
9120 afi_t afi;
9121 safi_t safi;
f43e655e 9122 uint64_t subgrp_id;
3f9c7369 9123
5bf15956
DW
9124 afi = (strmatch(argv[idx_afi]->text, "ipv4")) ? AFI_IP : AFI_IP6;
9125 safi = (strmatch(argv[idx_safi]->text, "unicast")) ? SAFI_UNICAST : SAFI_MULTICAST;
9126 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8fe8a7f6 9127
5bf15956 9128 show_bgp_updgrps_adj_info_aux(vty, NULL, afi, safi, argv[idx_type]->arg, subgrp_id);
8fe8a7f6 9129 return CMD_SUCCESS;
3f9c7369
DS
9130}
9131
8fe8a7f6
DS
9132DEFUN (show_bgp_updgrps_adj_s,
9133 show_bgp_updgrps_adj_s_cmd,
6147e2c6 9134 "show bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8fe8a7f6
DS
9135 SHOW_STR
9136 BGP_STR
0c7b1b01 9137 "Detailed info about dynamic update groups\n"
8fe8a7f6
DS
9138 "Specific subgroup to display info for\n"
9139 "Advertisement queue\n"
9140 "Announced routes\n"
9141 "Packet queue\n")
9142{
5bf15956 9143 int idx_subgroup_id = 3;
c500ae40 9144 int idx_type = 4;
f43e655e 9145 uint64_t subgrp_id;
8fe8a7f6 9146
5bf15956 9147 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8fe8a7f6 9148
5bf15956 9149 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
8fe8a7f6
DS
9150 return CMD_SUCCESS;
9151}
9152
8386ac43 9153DEFUN (show_bgp_instance_updgrps_adj_s,
9154 show_bgp_instance_updgrps_adj_s_cmd,
9ccf14f7 9155 "show bgp <view|vrf> WORD update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 9156 SHOW_STR
9157 BGP_STR
9158 BGP_INSTANCE_HELP_STR
0c7b1b01 9159 "Detailed info about dynamic update groups\n"
8386ac43 9160 "Specific subgroup to display info for\n"
9161 "Advertisement queue\n"
9162 "Announced routes\n"
9163 "Packet queue\n")
9164{
5bf15956
DW
9165 int idx_vrf = 3;
9166 int idx_subgroup_id = 5;
c500ae40 9167 int idx_type = 6;
f43e655e 9168 uint64_t subgrp_id;
8386ac43 9169
5bf15956 9170 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8386ac43 9171
5bf15956 9172 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
8386ac43 9173 return CMD_SUCCESS;
9174}
9175
9176
8fe8a7f6 9177
f14e6fdb
DS
9178static int
9179bgp_show_one_peer_group (struct vty *vty, struct peer_group *group)
9180{
9181 struct listnode *node, *nnode;
9182 struct prefix *range;
9183 struct peer *conf;
9184 struct peer *peer;
4690c7d7 9185 char buf[PREFIX2STR_BUFFER];
f14e6fdb
DS
9186 afi_t afi;
9187 safi_t safi;
ffd0c037
DS
9188 const char *peer_status;
9189 const char *af_str;
f14e6fdb
DS
9190 int lr_count;
9191 int dynamic;
9192 int af_cfgd;
9193
9194 conf = group->conf;
9195
0299c004
DS
9196 if (conf->as_type == AS_SPECIFIED ||
9197 conf->as_type == AS_EXTERNAL) {
66b199b2 9198 vty_out (vty, "%sBGP peer-group %s, remote AS %d%s",
f14e6fdb 9199 VTY_NEWLINE, group->name, conf->as, VTY_NEWLINE);
0299c004 9200 } else if (conf->as_type == AS_INTERNAL) {
66b199b2 9201 vty_out (vty, "%sBGP peer-group %s, remote AS %d%s",
0299c004 9202 VTY_NEWLINE, group->name, group->bgp->as, VTY_NEWLINE);
66b199b2
DS
9203 } else {
9204 vty_out (vty, "%sBGP peer-group %s%s",
9205 VTY_NEWLINE, group->name, VTY_NEWLINE);
0299c004 9206 }
f14e6fdb 9207
0299c004 9208 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
f14e6fdb
DS
9209 vty_out (vty, " Peer-group type is internal%s", VTY_NEWLINE);
9210 else
9211 vty_out (vty, " Peer-group type is external%s", VTY_NEWLINE);
9212
9213 /* Display AFs configured. */
9214 vty_out (vty, " Configured address-families:");
9215 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9216 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
9217 {
9218 if (conf->afc[afi][safi])
9219 {
9220 af_cfgd = 1;
9221 vty_out (vty, " %s;", afi_safi_print(afi, safi));
9222 }
9223 }
9224 if (!af_cfgd)
9225 vty_out (vty, " none%s", VTY_NEWLINE);
9226 else
9227 vty_out (vty, "%s", VTY_NEWLINE);
9228
9229 /* Display listen ranges (for dynamic neighbors), if any */
9230 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9231 {
9232 if (afi == AFI_IP)
9233 af_str = "IPv4";
9234 else if (afi == AFI_IP6)
9235 af_str = "IPv6";
9236 lr_count = listcount(group->listen_range[afi]);
9237 if (lr_count)
9238 {
9239 vty_out(vty,
9240 " %d %s listen range(s)%s",
9241 lr_count, af_str, VTY_NEWLINE);
9242
9243
9244 for (ALL_LIST_ELEMENTS (group->listen_range[afi], node,
9245 nnode, range))
9246 {
9247 prefix2str(range, buf, sizeof(buf));
9248 vty_out(vty, " %s%s", buf, VTY_NEWLINE);
9249 }
9250 }
9251 }
9252
9253 /* Display group members and their status */
9254 if (listcount(group->peer))
9255 {
9256 vty_out (vty, " Peer-group members:%s", VTY_NEWLINE);
9257 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
9258 {
9259 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
9260 peer_status = "Idle (Admin)";
9261 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
9262 peer_status = "Idle (PfxCt)";
9263 else
9264 peer_status = LOOKUP(bgp_status_msg, peer->status);
9265
9266 dynamic = peer_dynamic_neighbor(peer);
9267 vty_out (vty, " %s %s %s %s",
9268 peer->host, dynamic ? "(dynamic)" : "",
9269 peer_status, VTY_NEWLINE);
9270 }
9271 }
9272
9273 return CMD_SUCCESS;
9274}
9275
9276/* Show BGP peer group's information. */
9277enum show_group_type
9278{
9279 show_all_groups,
9280 show_peer_group
9281};
9282
9283static int
9284bgp_show_peer_group (struct vty *vty, struct bgp *bgp,
9285 enum show_group_type type, const char *group_name)
9286{
9287 struct listnode *node, *nnode;
9288 struct peer_group *group;
9289 int find = 0;
9290
9291 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
9292 {
9293 switch (type)
9294 {
9295 case show_all_groups:
9296 bgp_show_one_peer_group (vty, group);
9297 break;
9298 case show_peer_group:
9299 if (group_name && (strcmp(group->name, group_name) == 0))
9300 {
9301 find = 1;
9302 bgp_show_one_peer_group (vty, group);
9303 }
9304 break;
9305 }
9306 }
9307
9308 if (type == show_peer_group && ! find)
6d9e66dc 9309 vty_out (vty, "%% No such peer-group%s", VTY_NEWLINE);
f14e6fdb
DS
9310
9311 return CMD_SUCCESS;
9312}
9313
9314static int
9315bgp_show_peer_group_vty (struct vty *vty, const char *name,
9316 enum show_group_type type, const char *group_name)
9317{
9318 struct bgp *bgp;
9319 int ret = CMD_SUCCESS;
9320
9321 if (name)
8386ac43 9322 bgp = bgp_lookup_by_name (name);
9323 else
9324 bgp = bgp_get_default ();
f14e6fdb 9325
8386ac43 9326 if (! bgp)
9327 {
9328 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9329 return CMD_WARNING;
f14e6fdb
DS
9330 }
9331
8386ac43 9332 ret = bgp_show_peer_group (vty, bgp, type, group_name);
f14e6fdb
DS
9333
9334 return ret;
9335}
9336
9337DEFUN (show_ip_bgp_peer_groups,
9338 show_ip_bgp_peer_groups_cmd,
d6e3c605 9339 "show [ip] bgp [<view|vrf> VRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
9340 SHOW_STR
9341 IP_STR
9342 BGP_STR
8386ac43 9343 BGP_INSTANCE_HELP_STR
d6e3c605
QY
9344 "Detailed information on BGP peer groups\n"
9345 "Peer group name\n")
f14e6fdb 9346{
d6e3c605
QY
9347 char *vrf, *pg;
9348 vrf = pg = NULL;
9349 int idx = 0;
f14e6fdb 9350
d6e3c605
QY
9351 vrf = argv_find (argv, argc, "VRFNAME", &idx) ? argv[idx]->arg : NULL;
9352 pg = argv_find (argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 9353
d6e3c605 9354 return bgp_show_peer_group_vty (vty, vrf, show_all_groups, pg);
f14e6fdb 9355}
3f9c7369 9356
d6e3c605 9357
718e3744 9358/* Redistribute VTY commands. */
9359
718e3744 9360DEFUN (bgp_redistribute_ipv4,
9361 bgp_redistribute_ipv4_cmd,
9ccf14f7 9362 "redistribute <kernel|connected|static|rip|ospf|isis|pim|table>",
718e3744 9363 "Redistribute information from another routing protocol\n"
e0ca5fde 9364 QUAGGA_IP_REDIST_HELP_STR_BGPD)
718e3744 9365{
c500ae40 9366 int idx_protocol = 1;
718e3744 9367 int type;
9368
c500ae40 9369 type = proto_redistnum (AFI_IP, argv[idx_protocol]->arg);
e0ca5fde 9370 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9371 {
9372 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9373 return CMD_WARNING;
9374 }
7c8ff89e 9375 bgp_redist_add(vty->index, AFI_IP, type, 0);
6aeb9e78 9376 return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
718e3744 9377}
9378
9379DEFUN (bgp_redistribute_ipv4_rmap,
9380 bgp_redistribute_ipv4_rmap_cmd,
9ccf14f7 9381 "redistribute <kernel|connected|static|rip|ospf|isis|pim|table> route-map WORD",
718e3744 9382 "Redistribute information from another routing protocol\n"
e0ca5fde 9383 QUAGGA_IP_REDIST_HELP_STR_BGPD
718e3744 9384 "Route map reference\n"
9385 "Pointer to route-map entries\n")
9386{
c500ae40
DW
9387 int idx_protocol = 1;
9388 int idx_word = 3;
718e3744 9389 int type;
7c8ff89e 9390 struct bgp_redist *red;
718e3744 9391
c500ae40 9392 type = proto_redistnum (AFI_IP, argv[idx_protocol]->arg);
e0ca5fde 9393 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9394 {
9395 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9396 return CMD_WARNING;
9397 }
9398
7c8ff89e 9399 red = bgp_redist_add(vty->index, AFI_IP, type, 0);
c500ae40 9400 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
6aeb9e78 9401 return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
718e3744 9402}
9403
9404DEFUN (bgp_redistribute_ipv4_metric,
9405 bgp_redistribute_ipv4_metric_cmd,
9ccf14f7 9406 "redistribute <kernel|connected|static|rip|ospf|isis|pim|table> metric (0-4294967295)",
718e3744 9407 "Redistribute information from another routing protocol\n"
e0ca5fde 9408 QUAGGA_IP_REDIST_HELP_STR_BGPD
718e3744 9409 "Metric for redistributed routes\n"
9410 "Default metric\n")
9411{
c500ae40
DW
9412 int idx_protocol = 1;
9413 int idx_number = 3;
718e3744 9414 int type;
9415 u_int32_t metric;
7c8ff89e 9416 struct bgp_redist *red;
718e3744 9417
c500ae40 9418 type = proto_redistnum (AFI_IP, argv[idx_protocol]->arg);
e0ca5fde 9419 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9420 {
9421 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9422 return CMD_WARNING;
9423 }
c500ae40 9424 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 9425
7c8ff89e 9426 red = bgp_redist_add(vty->index, AFI_IP, type, 0);
caf958b4 9427 bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric);
6aeb9e78 9428 return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
718e3744 9429}
9430
9431DEFUN (bgp_redistribute_ipv4_rmap_metric,
9432 bgp_redistribute_ipv4_rmap_metric_cmd,
9ccf14f7 9433 "redistribute <kernel|connected|static|rip|ospf|isis|pim|table> route-map WORD metric (0-4294967295)",
718e3744 9434 "Redistribute information from another routing protocol\n"
e0ca5fde 9435 QUAGGA_IP_REDIST_HELP_STR_BGPD
718e3744 9436 "Route map reference\n"
9437 "Pointer to route-map entries\n"
9438 "Metric for redistributed routes\n"
9439 "Default metric\n")
9440{
c500ae40
DW
9441 int idx_protocol = 1;
9442 int idx_word = 3;
9443 int idx_number = 5;
718e3744 9444 int type;
9445 u_int32_t metric;
7c8ff89e 9446 struct bgp_redist *red;
718e3744 9447
c500ae40 9448 type = proto_redistnum (AFI_IP, argv[idx_protocol]->arg);
e0ca5fde 9449 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9450 {
9451 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9452 return CMD_WARNING;
9453 }
c500ae40 9454 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 9455
7c8ff89e 9456 red = bgp_redist_add(vty->index, AFI_IP, type, 0);
c500ae40 9457 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
caf958b4 9458 bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric);
6aeb9e78 9459 return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
718e3744 9460}
9461
9462DEFUN (bgp_redistribute_ipv4_metric_rmap,
9463 bgp_redistribute_ipv4_metric_rmap_cmd,
9ccf14f7 9464 "redistribute <kernel|connected|static|rip|ospf|isis|pim|table> metric (0-4294967295) route-map WORD",
718e3744 9465 "Redistribute information from another routing protocol\n"
e0ca5fde 9466 QUAGGA_IP_REDIST_HELP_STR_BGPD
718e3744 9467 "Metric for redistributed routes\n"
9468 "Default metric\n"
9469 "Route map reference\n"
9470 "Pointer to route-map entries\n")
9471{
c500ae40
DW
9472 int idx_protocol = 1;
9473 int idx_number = 3;
9474 int idx_word = 5;
718e3744 9475 int type;
9476 u_int32_t metric;
7c8ff89e 9477 struct bgp_redist *red;
718e3744 9478
c500ae40 9479 type = proto_redistnum (AFI_IP, argv[idx_protocol]->arg);
e0ca5fde 9480 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9481 {
9482 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9483 return CMD_WARNING;
9484 }
c500ae40 9485 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 9486
7c8ff89e 9487 red = bgp_redist_add(vty->index, AFI_IP, type, 0);
caf958b4 9488 bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric);
c500ae40 9489 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
6aeb9e78 9490 return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
718e3744 9491}
9492
7c8ff89e
DS
9493DEFUN (bgp_redistribute_ipv4_ospf,
9494 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 9495 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
9496 "Redistribute information from another routing protocol\n"
9497 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
9498 "Non-main Kernel Routing Table\n"
9499 "Instance ID/Table ID\n")
7c8ff89e 9500{
c500ae40
DW
9501 int idx_ospf_table = 1;
9502 int idx_number = 2;
7c8ff89e 9503 u_short instance;
7a4bb9c5 9504 u_short protocol;
7c8ff89e 9505
c500ae40 9506 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7a4bb9c5 9507
c500ae40 9508 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
9509 protocol = ZEBRA_ROUTE_OSPF;
9510 else
9511 protocol = ZEBRA_ROUTE_TABLE;
9512
9513 bgp_redist_add(vty->index, AFI_IP, protocol, instance);
6aeb9e78 9514 return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
7c8ff89e
DS
9515}
9516
9517DEFUN (bgp_redistribute_ipv4_ospf_rmap,
9518 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 9519 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
9520 "Redistribute information from another routing protocol\n"
9521 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
9522 "Non-main Kernel Routing Table\n"
9523 "Instance ID/Table ID\n"
7c8ff89e
DS
9524 "Route map reference\n"
9525 "Pointer to route-map entries\n")
9526{
c500ae40
DW
9527 int idx_ospf_table = 1;
9528 int idx_number = 2;
9529 int idx_word = 4;
7c8ff89e
DS
9530 struct bgp_redist *red;
9531 u_short instance;
7a4bb9c5 9532 int protocol;
7c8ff89e 9533
c500ae40 9534 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
9535 protocol = ZEBRA_ROUTE_OSPF;
9536 else
9537 protocol = ZEBRA_ROUTE_TABLE;
9538
c500ae40 9539 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7a4bb9c5 9540 red = bgp_redist_add(vty->index, AFI_IP, protocol, instance);
c500ae40 9541 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
6aeb9e78 9542 return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
7c8ff89e
DS
9543}
9544
9545DEFUN (bgp_redistribute_ipv4_ospf_metric,
9546 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 9547 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
9548 "Redistribute information from another routing protocol\n"
9549 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
9550 "Non-main Kernel Routing Table\n"
9551 "Instance ID/Table ID\n"
7c8ff89e
DS
9552 "Metric for redistributed routes\n"
9553 "Default metric\n")
9554{
c500ae40
DW
9555 int idx_ospf_table = 1;
9556 int idx_number = 2;
9557 int idx_number_2 = 4;
7c8ff89e
DS
9558 u_int32_t metric;
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;
7c8ff89e 9567
c500ae40
DW
9568 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9569 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
7a4bb9c5
DS
9570
9571 red = bgp_redist_add(vty->index, AFI_IP, protocol, instance);
caf958b4 9572 bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric);
6aeb9e78 9573 return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
7c8ff89e
DS
9574}
9575
9576DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
9577 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 9578 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
9579 "Redistribute information from another routing protocol\n"
9580 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
9581 "Non-main Kernel Routing Table\n"
9582 "Instance ID/Table ID\n"
7c8ff89e
DS
9583 "Route map reference\n"
9584 "Pointer to route-map entries\n"
9585 "Metric for redistributed routes\n"
9586 "Default metric\n")
9587{
c500ae40
DW
9588 int idx_ospf_table = 1;
9589 int idx_number = 2;
9590 int idx_word = 4;
9591 int idx_number_2 = 6;
7c8ff89e
DS
9592 u_int32_t metric;
9593 struct bgp_redist *red;
9594 u_short instance;
7a4bb9c5 9595 int protocol;
7c8ff89e 9596
c500ae40 9597 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
9598 protocol = ZEBRA_ROUTE_OSPF;
9599 else
9600 protocol = ZEBRA_ROUTE_TABLE;
7c8ff89e 9601
c500ae40
DW
9602 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9603 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
7a4bb9c5
DS
9604
9605 red = bgp_redist_add(vty->index, AFI_IP, protocol, instance);
c500ae40 9606 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
caf958b4 9607 bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric);
6aeb9e78 9608 return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
7c8ff89e
DS
9609}
9610
9611DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
9612 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 9613 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
9614 "Redistribute information from another routing protocol\n"
9615 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
9616 "Non-main Kernel Routing Table\n"
9617 "Instance ID/Table ID\n"
7c8ff89e
DS
9618 "Metric for redistributed routes\n"
9619 "Default metric\n"
9620 "Route map reference\n"
9621 "Pointer to route-map entries\n")
9622{
c500ae40
DW
9623 int idx_ospf_table = 1;
9624 int idx_number = 2;
9625 int idx_number_2 = 4;
9626 int idx_word = 6;
7c8ff89e
DS
9627 u_int32_t metric;
9628 struct bgp_redist *red;
9629 u_short instance;
7a4bb9c5 9630 int protocol;
7c8ff89e 9631
c500ae40 9632 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
9633 protocol = ZEBRA_ROUTE_OSPF;
9634 else
9635 protocol = ZEBRA_ROUTE_TABLE;
7c8ff89e 9636
c500ae40
DW
9637 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
9638 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
7a4bb9c5
DS
9639
9640 red = bgp_redist_add(vty->index, AFI_IP, protocol, instance);
caf958b4 9641 bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric);
c500ae40 9642 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
6aeb9e78 9643 return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
7c8ff89e
DS
9644}
9645
9646DEFUN (no_bgp_redistribute_ipv4_ospf,
9647 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 9648 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
9649 NO_STR
9650 "Redistribute information from another routing protocol\n"
9651 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 9652 "Non-main Kernel Routing Table\n"
31500417
DW
9653 "Instance ID/Table ID\n"
9654 "Metric for redistributed routes\n"
9655 "Default metric\n"
9656 "Route map reference\n"
9657 "Pointer to route-map entries\n")
7c8ff89e 9658{
c500ae40
DW
9659 int idx_ospf_table = 2;
9660 int idx_number = 3;
7c8ff89e 9661 u_short instance;
7a4bb9c5
DS
9662 int protocol;
9663
c500ae40 9664 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
9665 protocol = ZEBRA_ROUTE_OSPF;
9666 else
9667 protocol = ZEBRA_ROUTE_TABLE;
7c8ff89e 9668
c500ae40 9669 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7a4bb9c5 9670 return bgp_redistribute_unset (vty->index, AFI_IP, protocol, instance);
7c8ff89e
DS
9671}
9672
718e3744 9673DEFUN (no_bgp_redistribute_ipv4,
9674 no_bgp_redistribute_ipv4_cmd,
d04c479d 9675 "no redistribute <kernel|connected|static|rip|ospf|isis|pim|table> [metric (0-4294967295)] [route-map WORD]",
718e3744 9676 NO_STR
9677 "Redistribute information from another routing protocol\n"
31500417
DW
9678 QUAGGA_IP_REDIST_HELP_STR_BGPD
9679 "Metric for redistributed routes\n"
9680 "Default metric\n"
9681 "Route map reference\n"
9682 "Pointer to route-map entries\n")
718e3744 9683{
c500ae40 9684 int idx_protocol = 2;
718e3744 9685 int type;
9686
c500ae40 9687 type = proto_redistnum (AFI_IP, argv[idx_protocol]->arg);
e0ca5fde 9688 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9689 {
9690 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9691 return CMD_WARNING;
9692 }
7c8ff89e 9693 return bgp_redistribute_unset (vty->index, AFI_IP, type, 0);
718e3744 9694}
9695
718e3744 9696#ifdef HAVE_IPV6
9697DEFUN (bgp_redistribute_ipv6,
9698 bgp_redistribute_ipv6_cmd,
9ccf14f7 9699 "redistribute <kernel|connected|static|ripng|ospf6|isis|table>",
718e3744 9700 "Redistribute information from another routing protocol\n"
e0ca5fde 9701 QUAGGA_IP6_REDIST_HELP_STR_BGPD)
718e3744 9702{
c500ae40 9703 int idx_protocol = 1;
718e3744 9704 int type;
9705
c500ae40 9706 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->arg);
e0ca5fde 9707 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9708 {
9709 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9710 return CMD_WARNING;
9711 }
9712
7c8ff89e 9713 bgp_redist_add(vty->index, AFI_IP6, type, 0);
6aeb9e78 9714 return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
718e3744 9715}
9716
9717DEFUN (bgp_redistribute_ipv6_rmap,
9718 bgp_redistribute_ipv6_rmap_cmd,
9ccf14f7 9719 "redistribute <kernel|connected|static|ripng|ospf6|isis|table> route-map WORD",
718e3744 9720 "Redistribute information from another routing protocol\n"
e0ca5fde 9721 QUAGGA_IP6_REDIST_HELP_STR_BGPD
718e3744 9722 "Route map reference\n"
9723 "Pointer to route-map entries\n")
9724{
c500ae40
DW
9725 int idx_protocol = 1;
9726 int idx_word = 3;
718e3744 9727 int type;
7c8ff89e 9728 struct bgp_redist *red;
718e3744 9729
c500ae40 9730 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->arg);
e0ca5fde 9731 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9732 {
9733 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9734 return CMD_WARNING;
9735 }
9736
7c8ff89e 9737 red = bgp_redist_add(vty->index, AFI_IP6, type, 0);
c500ae40 9738 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
6aeb9e78 9739 return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
718e3744 9740}
9741
9742DEFUN (bgp_redistribute_ipv6_metric,
9743 bgp_redistribute_ipv6_metric_cmd,
9ccf14f7 9744 "redistribute <kernel|connected|static|ripng|ospf6|isis|table> metric (0-4294967295)",
718e3744 9745 "Redistribute information from another routing protocol\n"
e0ca5fde 9746 QUAGGA_IP6_REDIST_HELP_STR_BGPD
718e3744 9747 "Metric for redistributed routes\n"
9748 "Default metric\n")
9749{
c500ae40
DW
9750 int idx_protocol = 1;
9751 int idx_number = 3;
718e3744 9752 int type;
9753 u_int32_t metric;
7c8ff89e 9754 struct bgp_redist *red;
718e3744 9755
c500ae40 9756 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->arg);
e0ca5fde 9757 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9758 {
9759 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9760 return CMD_WARNING;
9761 }
c500ae40 9762 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 9763
7c8ff89e 9764 red = bgp_redist_add(vty->index, AFI_IP6, type, 0);
caf958b4 9765 bgp_redistribute_metric_set(vty->index, red, AFI_IP6, type, metric);
6aeb9e78 9766 return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
718e3744 9767}
9768
9769DEFUN (bgp_redistribute_ipv6_rmap_metric,
9770 bgp_redistribute_ipv6_rmap_metric_cmd,
9ccf14f7 9771 "redistribute <kernel|connected|static|ripng|ospf6|isis|table> route-map WORD metric (0-4294967295)",
718e3744 9772 "Redistribute information from another routing protocol\n"
e0ca5fde 9773 QUAGGA_IP6_REDIST_HELP_STR_BGPD
718e3744 9774 "Route map reference\n"
9775 "Pointer to route-map entries\n"
9776 "Metric for redistributed routes\n"
9777 "Default metric\n")
9778{
c500ae40
DW
9779 int idx_protocol = 1;
9780 int idx_word = 3;
9781 int idx_number = 5;
718e3744 9782 int type;
9783 u_int32_t metric;
7c8ff89e 9784 struct bgp_redist *red;
718e3744 9785
c500ae40 9786 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->arg);
e0ca5fde 9787 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9788 {
9789 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9790 return CMD_WARNING;
9791 }
c500ae40 9792 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 9793
7c8ff89e 9794 red = bgp_redist_add(vty->index, AFI_IP6, type, 0);
c500ae40 9795 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
caf958b4 9796 bgp_redistribute_metric_set(vty->index, red, AFI_IP6, type, metric);
6aeb9e78 9797 return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
718e3744 9798}
9799
9800DEFUN (bgp_redistribute_ipv6_metric_rmap,
9801 bgp_redistribute_ipv6_metric_rmap_cmd,
9ccf14f7 9802 "redistribute <kernel|connected|static|ripng|ospf6|isis|table> metric (0-4294967295) route-map WORD",
718e3744 9803 "Redistribute information from another routing protocol\n"
e0ca5fde 9804 QUAGGA_IP6_REDIST_HELP_STR_BGPD
718e3744 9805 "Metric for redistributed routes\n"
9806 "Default metric\n"
9807 "Route map reference\n"
9808 "Pointer to route-map entries\n")
9809{
c500ae40
DW
9810 int idx_protocol = 1;
9811 int idx_number = 3;
9812 int idx_word = 5;
718e3744 9813 int type;
9814 u_int32_t metric;
7c8ff89e 9815 struct bgp_redist *red;
718e3744 9816
c500ae40 9817 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->arg);
e0ca5fde 9818 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9819 {
9820 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9821 return CMD_WARNING;
9822 }
c500ae40 9823 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 9824
7c8ff89e 9825 red = bgp_redist_add(vty->index, AFI_IP6, type, 0);
caf958b4 9826 bgp_redistribute_metric_set(vty->index, red, AFI_IP6, SAFI_UNICAST, metric);
c500ae40 9827 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
6aeb9e78 9828 return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
718e3744 9829}
9830
9831DEFUN (no_bgp_redistribute_ipv6,
9832 no_bgp_redistribute_ipv6_cmd,
d04c479d 9833 "no redistribute <kernel|connected|static|ripng|ospf6|isis|table> [metric (0-4294967295)] [route-map WORD]",
718e3744 9834 NO_STR
9835 "Redistribute information from another routing protocol\n"
31500417
DW
9836 QUAGGA_IP6_REDIST_HELP_STR_BGPD
9837 "Metric for redistributed routes\n"
9838 "Default metric\n"
9839 "Route map reference\n"
9840 "Pointer to route-map entries\n")
718e3744 9841{
c500ae40 9842 int idx_protocol = 2;
718e3744 9843 int type;
9844
c500ae40 9845 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->arg);
e0ca5fde 9846 if (type < 0 || type == ZEBRA_ROUTE_BGP)
718e3744 9847 {
9848 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
9849 return CMD_WARNING;
9850 }
9851
7c8ff89e 9852 return bgp_redistribute_unset (vty->index, AFI_IP6, type, 0);
718e3744 9853}
9854
718e3744 9855
718e3744 9856
718e3744 9857
718e3744 9858#endif /* HAVE_IPV6 */
6b0655a2 9859
718e3744 9860int
9861bgp_config_write_redistribute (struct vty *vty, struct bgp *bgp, afi_t afi,
9862 safi_t safi, int *write)
9863{
9864 int i;
718e3744 9865
9866 /* Unicast redistribution only. */
9867 if (safi != SAFI_UNICAST)
9868 return 0;
9869
9870 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
9871 {
9872 /* Redistribute BGP does not make sense. */
7c8ff89e 9873 if (i != ZEBRA_ROUTE_BGP)
718e3744 9874 {
7c8ff89e
DS
9875 struct list *red_list;
9876 struct listnode *node;
9877 struct bgp_redist *red;
718e3744 9878
7c8ff89e
DS
9879 red_list = bgp->redist[afi][i];
9880 if (!red_list)
9881 continue;
718e3744 9882
7c8ff89e
DS
9883 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
9884 {
9885 /* Display "address-family" when it is not yet diplayed. */
9886 bgp_config_write_family_header (vty, afi, safi, write);
9887
9888 /* "redistribute" configuration. */
0b960b4d 9889 vty_out (vty, " redistribute %s", zebra_route_string(i));
7c8ff89e
DS
9890 if (red->instance)
9891 vty_out (vty, " %d", red->instance);
9892 if (red->redist_metric_flag)
9893 vty_out (vty, " metric %u", red->redist_metric);
9894 if (red->rmap.name)
9895 vty_out (vty, " route-map %s", red->rmap.name);
9896 vty_out (vty, "%s", VTY_NEWLINE);
9897 }
718e3744 9898 }
9899 }
9900 return *write;
9901}
6b0655a2 9902
718e3744 9903/* BGP node structure. */
7fc626de 9904static struct cmd_node bgp_node =
718e3744 9905{
9906 BGP_NODE,
9907 "%s(config-router)# ",
9908 1,
9909};
9910
7fc626de 9911static struct cmd_node bgp_ipv4_unicast_node =
718e3744 9912{
9913 BGP_IPV4_NODE,
9914 "%s(config-router-af)# ",
9915 1,
9916};
9917
7fc626de 9918static struct cmd_node bgp_ipv4_multicast_node =
718e3744 9919{
9920 BGP_IPV4M_NODE,
9921 "%s(config-router-af)# ",
9922 1,
9923};
9924
7fc626de 9925static struct cmd_node bgp_ipv6_unicast_node =
718e3744 9926{
9927 BGP_IPV6_NODE,
9928 "%s(config-router-af)# ",
9929 1,
9930};
9931
7fc626de 9932static struct cmd_node bgp_ipv6_multicast_node =
25ffbdc1 9933{
9934 BGP_IPV6M_NODE,
9935 "%s(config-router-af)# ",
9936 1,
9937};
9938
7fc626de 9939static struct cmd_node bgp_vpnv4_node =
718e3744 9940{
9941 BGP_VPNV4_NODE,
9942 "%s(config-router-af)# ",
9943 1
9944};
6b0655a2 9945
8ecd3266 9946static struct cmd_node bgp_vpnv6_node =
9947{
9948 BGP_VPNV6_NODE,
9949 "%s(config-router-af-vpnv6)# ",
9950 1
9951};
9952
8b1fb8be
LB
9953static struct cmd_node bgp_encap_node =
9954{
9955 BGP_ENCAP_NODE,
9956 "%s(config-router-af-encap)# ",
9957 1
9958};
9959
9960static struct cmd_node bgp_encapv6_node =
9961{
9962 BGP_ENCAPV6_NODE,
9963 "%s(config-router-af-encapv6)# ",
9964 1
9965};
9966
1f8ae70b 9967static void community_list_vty (void);
9968
718e3744 9969void
94f2b392 9970bgp_vty_init (void)
718e3744 9971{
718e3744 9972 /* Install bgp top node. */
9973 install_node (&bgp_node, bgp_config_write);
9974 install_node (&bgp_ipv4_unicast_node, NULL);
9975 install_node (&bgp_ipv4_multicast_node, NULL);
9976 install_node (&bgp_ipv6_unicast_node, NULL);
25ffbdc1 9977 install_node (&bgp_ipv6_multicast_node, NULL);
718e3744 9978 install_node (&bgp_vpnv4_node, NULL);
8ecd3266 9979 install_node (&bgp_vpnv6_node, NULL);
8b1fb8be
LB
9980 install_node (&bgp_encap_node, NULL);
9981 install_node (&bgp_encapv6_node, NULL);
718e3744 9982
9983 /* Install default VTY commands to new nodes. */
9984 install_default (BGP_NODE);
9985 install_default (BGP_IPV4_NODE);
9986 install_default (BGP_IPV4M_NODE);
9987 install_default (BGP_IPV6_NODE);
25ffbdc1 9988 install_default (BGP_IPV6M_NODE);
718e3744 9989 install_default (BGP_VPNV4_NODE);
8ecd3266 9990 install_default (BGP_VPNV6_NODE);
8b1fb8be
LB
9991 install_default (BGP_ENCAP_NODE);
9992 install_default (BGP_ENCAPV6_NODE);
e52702f2 9993
718e3744 9994 /* "bgp multiple-instance" commands. */
9995 install_element (CONFIG_NODE, &bgp_multiple_instance_cmd);
9996 install_element (CONFIG_NODE, &no_bgp_multiple_instance_cmd);
9997
9998 /* "bgp config-type" commands. */
9999 install_element (CONFIG_NODE, &bgp_config_type_cmd);
8c3deaae 10000 install_element (CONFIG_NODE, &no_bgp_config_type_cmd);
718e3744 10001
5fe9f963 10002 /* bgp route-map delay-timer commands. */
10003 install_element (CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
10004 install_element (CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
5fe9f963 10005
718e3744 10006 /* Dummy commands (Currently not supported) */
10007 install_element (BGP_NODE, &no_synchronization_cmd);
10008 install_element (BGP_NODE, &no_auto_summary_cmd);
10009
10010 /* "router bgp" commands. */
10011 install_element (CONFIG_NODE, &router_bgp_cmd);
718e3744 10012
10013 /* "no router bgp" commands. */
10014 install_element (CONFIG_NODE, &no_router_bgp_cmd);
718e3744 10015
10016 /* "bgp router-id" commands. */
10017 install_element (BGP_NODE, &bgp_router_id_cmd);
10018 install_element (BGP_NODE, &no_bgp_router_id_cmd);
718e3744 10019
10020 /* "bgp cluster-id" commands. */
10021 install_element (BGP_NODE, &bgp_cluster_id_cmd);
718e3744 10022 install_element (BGP_NODE, &no_bgp_cluster_id_cmd);
718e3744 10023
10024 /* "bgp confederation" commands. */
10025 install_element (BGP_NODE, &bgp_confederation_identifier_cmd);
10026 install_element (BGP_NODE, &no_bgp_confederation_identifier_cmd);
718e3744 10027
10028 /* "bgp confederation peers" commands. */
10029 install_element (BGP_NODE, &bgp_confederation_peers_cmd);
10030 install_element (BGP_NODE, &no_bgp_confederation_peers_cmd);
10031
abc920f8
DS
10032 /* bgp max-med command */
10033 install_element (BGP_NODE, &bgp_maxmed_admin_cmd);
10034 install_element (BGP_NODE, &no_bgp_maxmed_admin_cmd);
10035 install_element (BGP_NODE, &bgp_maxmed_admin_medv_cmd);
abc920f8
DS
10036 install_element (BGP_NODE, &bgp_maxmed_onstartup_cmd);
10037 install_element (BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
abc920f8 10038 install_element (BGP_NODE, &bgp_maxmed_onstartup_medv_cmd);
abc920f8 10039
907f92c8
DS
10040 /* bgp disable-ebgp-connected-nh-check */
10041 install_element (BGP_NODE, &bgp_disable_connected_route_check_cmd);
10042 install_element (BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
10043
f188f2c4
DS
10044 /* bgp update-delay command */
10045 install_element (BGP_NODE, &bgp_update_delay_cmd);
10046 install_element (BGP_NODE, &no_bgp_update_delay_cmd);
10047 install_element (BGP_NODE, &bgp_update_delay_establish_wait_cmd);
f188f2c4 10048
cb1faec9
DS
10049 install_element (BGP_NODE, &bgp_wpkt_quanta_cmd);
10050 install_element (BGP_NODE, &no_bgp_wpkt_quanta_cmd);
10051
3f9c7369
DS
10052 install_element (BGP_NODE, &bgp_coalesce_time_cmd);
10053 install_element (BGP_NODE, &no_bgp_coalesce_time_cmd);
10054
165b5fff
JB
10055 /* "maximum-paths" commands. */
10056 install_element (BGP_NODE, &bgp_maxpaths_cmd);
10057 install_element (BGP_NODE, &no_bgp_maxpaths_cmd);
165b5fff
JB
10058 install_element (BGP_IPV4_NODE, &bgp_maxpaths_cmd);
10059 install_element (BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
431aa9f9
DS
10060 install_element (BGP_IPV6_NODE, &bgp_maxpaths_cmd);
10061 install_element (BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
165b5fff 10062 install_element (BGP_NODE, &bgp_maxpaths_ibgp_cmd);
5e242b0d 10063 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
165b5fff 10064 install_element (BGP_NODE, &no_bgp_maxpaths_ibgp_cmd);
165b5fff 10065 install_element (BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
5e242b0d 10066 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
165b5fff 10067 install_element (BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
431aa9f9 10068 install_element (BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
5e242b0d 10069 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
431aa9f9 10070 install_element (BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
165b5fff 10071
718e3744 10072 /* "timers bgp" commands. */
10073 install_element (BGP_NODE, &bgp_timers_cmd);
10074 install_element (BGP_NODE, &no_bgp_timers_cmd);
718e3744 10075
5fe9f963 10076 /* route-map delay-timer commands - per instance for backwards compat. */
518f0eb1
DS
10077 install_element (BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
10078 install_element (BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
10079
718e3744 10080 /* "bgp client-to-client reflection" commands */
10081 install_element (BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
10082 install_element (BGP_NODE, &bgp_client_to_client_reflection_cmd);
10083
10084 /* "bgp always-compare-med" commands */
10085 install_element (BGP_NODE, &bgp_always_compare_med_cmd);
10086 install_element (BGP_NODE, &no_bgp_always_compare_med_cmd);
e52702f2 10087
718e3744 10088 /* "bgp deterministic-med" commands */
10089 install_element (BGP_NODE, &bgp_deterministic_med_cmd);
10090 install_element (BGP_NODE, &no_bgp_deterministic_med_cmd);
538621f2 10091
538621f2 10092 /* "bgp graceful-restart" commands */
10093 install_element (BGP_NODE, &bgp_graceful_restart_cmd);
10094 install_element (BGP_NODE, &no_bgp_graceful_restart_cmd);
93406d87 10095 install_element (BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
10096 install_element (BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
eb6f1b41
PG
10097 install_element (BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
10098 install_element (BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
e52702f2 10099
718e3744 10100 /* "bgp fast-external-failover" commands */
10101 install_element (BGP_NODE, &bgp_fast_external_failover_cmd);
10102 install_element (BGP_NODE, &no_bgp_fast_external_failover_cmd);
10103
10104 /* "bgp enforce-first-as" commands */
10105 install_element (BGP_NODE, &bgp_enforce_first_as_cmd);
10106 install_element (BGP_NODE, &no_bgp_enforce_first_as_cmd);
10107
10108 /* "bgp bestpath compare-routerid" commands */
10109 install_element (BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
10110 install_element (BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
10111
10112 /* "bgp bestpath as-path ignore" commands */
10113 install_element (BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
10114 install_element (BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
10115
6811845b 10116 /* "bgp bestpath as-path confed" commands */
10117 install_element (BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
10118 install_element (BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
10119
2fdd455c
PM
10120 /* "bgp bestpath as-path multipath-relax" commands */
10121 install_element (BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
10122 install_element (BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
10123
848973c7 10124 /* "bgp log-neighbor-changes" commands */
10125 install_element (BGP_NODE, &bgp_log_neighbor_changes_cmd);
10126 install_element (BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
10127
718e3744 10128 /* "bgp bestpath med" commands */
10129 install_element (BGP_NODE, &bgp_bestpath_med_cmd);
10130 install_element (BGP_NODE, &bgp_bestpath_med2_cmd);
718e3744 10131 install_element (BGP_NODE, &no_bgp_bestpath_med_cmd);
10132 install_element (BGP_NODE, &no_bgp_bestpath_med2_cmd);
718e3744 10133
10134 /* "no bgp default ipv4-unicast" commands. */
10135 install_element (BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
10136 install_element (BGP_NODE, &bgp_default_ipv4_unicast_cmd);
e52702f2 10137
718e3744 10138 /* "bgp network import-check" commands. */
10139 install_element (BGP_NODE, &bgp_network_import_check_cmd);
8233ef81 10140 install_element (BGP_NODE, &bgp_network_import_check_exact_cmd);
718e3744 10141 install_element (BGP_NODE, &no_bgp_network_import_check_cmd);
10142
10143 /* "bgp default local-preference" commands. */
10144 install_element (BGP_NODE, &bgp_default_local_preference_cmd);
10145 install_element (BGP_NODE, &no_bgp_default_local_preference_cmd);
718e3744 10146
04b6bdc0
DW
10147 /* bgp default show-hostname */
10148 install_element (BGP_NODE, &bgp_default_show_hostname_cmd);
10149 install_element (BGP_NODE, &no_bgp_default_show_hostname_cmd);
10150
3f9c7369
DS
10151 /* "bgp default subgroup-pkt-queue-max" commands. */
10152 install_element (BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
10153 install_element (BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
10154
8bd9d948
DS
10155 /* bgp ibgp-allow-policy-mods command */
10156 install_element (BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
10157 install_element (BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
10158
f14e6fdb
DS
10159 /* "bgp listen limit" commands. */
10160 install_element (BGP_NODE, &bgp_listen_limit_cmd);
10161 install_element (BGP_NODE, &no_bgp_listen_limit_cmd);
10162
10163 /* "bgp listen range" commands. */
10164 install_element (BGP_NODE, &bgp_listen_range_cmd);
10165 install_element (BGP_NODE, &no_bgp_listen_range_cmd);
10166
718e3744 10167 /* "neighbor remote-as" commands. */
10168 install_element (BGP_NODE, &neighbor_remote_as_cmd);
a80beece 10169 install_element (BGP_NODE, &neighbor_interface_config_cmd);
4c48cf63 10170 install_element (BGP_NODE, &neighbor_interface_config_v6only_cmd);
b3a39dc5
DD
10171 install_element (BGP_NODE, &neighbor_interface_config_remote_as_cmd);
10172 install_element (BGP_NODE, &neighbor_interface_v6only_config_remote_as_cmd);
718e3744 10173 install_element (BGP_NODE, &no_neighbor_cmd);
a80beece 10174 install_element (BGP_NODE, &no_neighbor_interface_config_cmd);
718e3744 10175
10176 /* "neighbor peer-group" commands. */
10177 install_element (BGP_NODE, &neighbor_peer_group_cmd);
10178 install_element (BGP_NODE, &no_neighbor_peer_group_cmd);
a80beece 10179 install_element (BGP_NODE, &no_neighbor_interface_peer_group_remote_as_cmd);
718e3744 10180
10181 /* "neighbor local-as" commands. */
10182 install_element (BGP_NODE, &neighbor_local_as_cmd);
10183 install_element (BGP_NODE, &neighbor_local_as_no_prepend_cmd);
9d3f9705 10184 install_element (BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
718e3744 10185 install_element (BGP_NODE, &no_neighbor_local_as_cmd);
718e3744 10186
3f9c7369
DS
10187 /* "neighbor solo" commands. */
10188 install_element (BGP_NODE, &neighbor_solo_cmd);
10189 install_element (BGP_NODE, &no_neighbor_solo_cmd);
10190
0df7c91f
PJ
10191 /* "neighbor password" commands. */
10192 install_element (BGP_NODE, &neighbor_password_cmd);
10193 install_element (BGP_NODE, &no_neighbor_password_cmd);
10194
718e3744 10195 /* "neighbor activate" commands. */
10196 install_element (BGP_NODE, &neighbor_activate_cmd);
10197 install_element (BGP_IPV4_NODE, &neighbor_activate_cmd);
10198 install_element (BGP_IPV4M_NODE, &neighbor_activate_cmd);
10199 install_element (BGP_IPV6_NODE, &neighbor_activate_cmd);
25ffbdc1 10200 install_element (BGP_IPV6M_NODE, &neighbor_activate_cmd);
718e3744 10201 install_element (BGP_VPNV4_NODE, &neighbor_activate_cmd);
8ecd3266 10202 install_element (BGP_VPNV6_NODE, &neighbor_activate_cmd);
8b1fb8be
LB
10203 install_element (BGP_ENCAP_NODE, &neighbor_activate_cmd);
10204 install_element (BGP_ENCAPV6_NODE, &neighbor_activate_cmd);
718e3744 10205
10206 /* "no neighbor activate" commands. */
10207 install_element (BGP_NODE, &no_neighbor_activate_cmd);
10208 install_element (BGP_IPV4_NODE, &no_neighbor_activate_cmd);
10209 install_element (BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
10210 install_element (BGP_IPV6_NODE, &no_neighbor_activate_cmd);
25ffbdc1 10211 install_element (BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
718e3744 10212 install_element (BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
8ecd3266 10213 install_element (BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
8b1fb8be
LB
10214 install_element (BGP_ENCAP_NODE, &no_neighbor_activate_cmd);
10215 install_element (BGP_ENCAPV6_NODE, &no_neighbor_activate_cmd);
718e3744 10216
c8560b44
DW
10217 /* "neighbor peer-group" set commands.
10218 * Long term we should only accept this command under BGP_NODE and not all of
10219 * the afi/safi sub-contexts. For now though we need to accept it for backwards
10220 * compatibility. This changed when we stopped requiring that peers be assigned
10221 * to their peer-group under each address-family sub-context.
10222 */
718e3744 10223 install_element (BGP_NODE, &neighbor_set_peer_group_cmd);
10224 install_element (BGP_IPV4_NODE, &neighbor_set_peer_group_cmd);
10225 install_element (BGP_IPV4M_NODE, &neighbor_set_peer_group_cmd);
10226 install_element (BGP_IPV6_NODE, &neighbor_set_peer_group_cmd);
25ffbdc1 10227 install_element (BGP_IPV6M_NODE, &neighbor_set_peer_group_cmd);
a58545bb 10228 install_element (BGP_VPNV4_NODE, &neighbor_set_peer_group_cmd);
8ecd3266 10229 install_element (BGP_VPNV6_NODE, &neighbor_set_peer_group_cmd);
8b1fb8be
LB
10230 install_element (BGP_ENCAP_NODE, &neighbor_set_peer_group_cmd);
10231 install_element (BGP_ENCAPV6_NODE, &neighbor_set_peer_group_cmd);
c8560b44 10232
718e3744 10233 /* "no neighbor peer-group unset" commands. */
10234 install_element (BGP_NODE, &no_neighbor_set_peer_group_cmd);
10235 install_element (BGP_IPV4_NODE, &no_neighbor_set_peer_group_cmd);
10236 install_element (BGP_IPV4M_NODE, &no_neighbor_set_peer_group_cmd);
10237 install_element (BGP_IPV6_NODE, &no_neighbor_set_peer_group_cmd);
25ffbdc1 10238 install_element (BGP_IPV6M_NODE, &no_neighbor_set_peer_group_cmd);
a58545bb 10239 install_element (BGP_VPNV4_NODE, &no_neighbor_set_peer_group_cmd);
8ecd3266 10240 install_element (BGP_VPNV6_NODE, &no_neighbor_set_peer_group_cmd);
8b1fb8be
LB
10241 install_element (BGP_ENCAP_NODE, &no_neighbor_set_peer_group_cmd);
10242 install_element (BGP_ENCAPV6_NODE, &no_neighbor_set_peer_group_cmd);
e52702f2 10243
718e3744 10244 /* "neighbor softreconfiguration inbound" commands.*/
10245 install_element (BGP_NODE, &neighbor_soft_reconfiguration_cmd);
10246 install_element (BGP_NODE, &no_neighbor_soft_reconfiguration_cmd);
10247 install_element (BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
10248 install_element (BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
10249 install_element (BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
10250 install_element (BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
10251 install_element (BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
10252 install_element (BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
25ffbdc1 10253 install_element (BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
10254 install_element (BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
a58545bb 10255 install_element (BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
10256 install_element (BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
8ecd3266 10257 install_element (BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
10258 install_element (BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
8b1fb8be
LB
10259 install_element (BGP_ENCAP_NODE, &neighbor_soft_reconfiguration_cmd);
10260 install_element (BGP_ENCAP_NODE, &no_neighbor_soft_reconfiguration_cmd);
10261 install_element (BGP_ENCAPV6_NODE, &neighbor_soft_reconfiguration_cmd);
10262 install_element (BGP_ENCAPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
718e3744 10263
10264 /* "neighbor attribute-unchanged" commands. */
10265 install_element (BGP_NODE, &neighbor_attr_unchanged_cmd);
10266 install_element (BGP_NODE, &neighbor_attr_unchanged1_cmd);
10267 install_element (BGP_NODE, &neighbor_attr_unchanged2_cmd);
10268 install_element (BGP_NODE, &neighbor_attr_unchanged3_cmd);
10269 install_element (BGP_NODE, &neighbor_attr_unchanged4_cmd);
718e3744 10270 install_element (BGP_NODE, &no_neighbor_attr_unchanged_cmd);
10271 install_element (BGP_NODE, &no_neighbor_attr_unchanged1_cmd);
10272 install_element (BGP_NODE, &no_neighbor_attr_unchanged2_cmd);
10273 install_element (BGP_NODE, &no_neighbor_attr_unchanged3_cmd);
10274 install_element (BGP_NODE, &no_neighbor_attr_unchanged4_cmd);
718e3744 10275 install_element (BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
10276 install_element (BGP_IPV4_NODE, &neighbor_attr_unchanged1_cmd);
10277 install_element (BGP_IPV4_NODE, &neighbor_attr_unchanged2_cmd);
10278 install_element (BGP_IPV4_NODE, &neighbor_attr_unchanged3_cmd);
10279 install_element (BGP_IPV4_NODE, &neighbor_attr_unchanged4_cmd);
718e3744 10280 install_element (BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
10281 install_element (BGP_IPV4_NODE, &no_neighbor_attr_unchanged1_cmd);
10282 install_element (BGP_IPV4_NODE, &no_neighbor_attr_unchanged2_cmd);
10283 install_element (BGP_IPV4_NODE, &no_neighbor_attr_unchanged3_cmd);
10284 install_element (BGP_IPV4_NODE, &no_neighbor_attr_unchanged4_cmd);
718e3744 10285 install_element (BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
10286 install_element (BGP_IPV4M_NODE, &neighbor_attr_unchanged1_cmd);
10287 install_element (BGP_IPV4M_NODE, &neighbor_attr_unchanged2_cmd);
10288 install_element (BGP_IPV4M_NODE, &neighbor_attr_unchanged3_cmd);
10289 install_element (BGP_IPV4M_NODE, &neighbor_attr_unchanged4_cmd);
718e3744 10290 install_element (BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
10291 install_element (BGP_IPV4M_NODE, &no_neighbor_attr_unchanged1_cmd);
10292 install_element (BGP_IPV4M_NODE, &no_neighbor_attr_unchanged2_cmd);
10293 install_element (BGP_IPV4M_NODE, &no_neighbor_attr_unchanged3_cmd);
10294 install_element (BGP_IPV4M_NODE, &no_neighbor_attr_unchanged4_cmd);
718e3744 10295 install_element (BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
10296 install_element (BGP_IPV6_NODE, &neighbor_attr_unchanged1_cmd);
10297 install_element (BGP_IPV6_NODE, &neighbor_attr_unchanged2_cmd);
10298 install_element (BGP_IPV6_NODE, &neighbor_attr_unchanged3_cmd);
10299 install_element (BGP_IPV6_NODE, &neighbor_attr_unchanged4_cmd);
718e3744 10300 install_element (BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
10301 install_element (BGP_IPV6_NODE, &no_neighbor_attr_unchanged1_cmd);
10302 install_element (BGP_IPV6_NODE, &no_neighbor_attr_unchanged2_cmd);
10303 install_element (BGP_IPV6_NODE, &no_neighbor_attr_unchanged3_cmd);
10304 install_element (BGP_IPV6_NODE, &no_neighbor_attr_unchanged4_cmd);
25ffbdc1 10305 install_element (BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
10306 install_element (BGP_IPV6M_NODE, &neighbor_attr_unchanged1_cmd);
10307 install_element (BGP_IPV6M_NODE, &neighbor_attr_unchanged2_cmd);
10308 install_element (BGP_IPV6M_NODE, &neighbor_attr_unchanged3_cmd);
10309 install_element (BGP_IPV6M_NODE, &neighbor_attr_unchanged4_cmd);
25ffbdc1 10310 install_element (BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
10311 install_element (BGP_IPV6M_NODE, &no_neighbor_attr_unchanged1_cmd);
10312 install_element (BGP_IPV6M_NODE, &no_neighbor_attr_unchanged2_cmd);
10313 install_element (BGP_IPV6M_NODE, &no_neighbor_attr_unchanged3_cmd);
10314 install_element (BGP_IPV6M_NODE, &no_neighbor_attr_unchanged4_cmd);
718e3744 10315 install_element (BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
10316 install_element (BGP_VPNV4_NODE, &neighbor_attr_unchanged1_cmd);
10317 install_element (BGP_VPNV4_NODE, &neighbor_attr_unchanged2_cmd);
10318 install_element (BGP_VPNV4_NODE, &neighbor_attr_unchanged3_cmd);
10319 install_element (BGP_VPNV4_NODE, &neighbor_attr_unchanged4_cmd);
718e3744 10320 install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
10321 install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged1_cmd);
10322 install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged2_cmd);
10323 install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged3_cmd);
10324 install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged4_cmd);
8ecd3266 10325 install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
10326 install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged1_cmd);
10327 install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged2_cmd);
10328 install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged3_cmd);
10329 install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged4_cmd);
8ecd3266 10330 install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
10331 install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged1_cmd);
10332 install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged2_cmd);
10333 install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged3_cmd);
10334 install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged4_cmd);
8ecd3266 10335
8b1fb8be
LB
10336 install_element (BGP_ENCAP_NODE, &neighbor_attr_unchanged_cmd);
10337 install_element (BGP_ENCAP_NODE, &neighbor_attr_unchanged1_cmd);
10338 install_element (BGP_ENCAP_NODE, &neighbor_attr_unchanged2_cmd);
10339 install_element (BGP_ENCAP_NODE, &neighbor_attr_unchanged3_cmd);
10340 install_element (BGP_ENCAP_NODE, &neighbor_attr_unchanged4_cmd);
8b1fb8be
LB
10341 install_element (BGP_ENCAP_NODE, &no_neighbor_attr_unchanged_cmd);
10342 install_element (BGP_ENCAP_NODE, &no_neighbor_attr_unchanged1_cmd);
10343 install_element (BGP_ENCAP_NODE, &no_neighbor_attr_unchanged2_cmd);
10344 install_element (BGP_ENCAP_NODE, &no_neighbor_attr_unchanged3_cmd);
10345 install_element (BGP_ENCAP_NODE, &no_neighbor_attr_unchanged4_cmd);
8b1fb8be
LB
10346
10347 install_element (BGP_ENCAPV6_NODE, &neighbor_attr_unchanged_cmd);
10348 install_element (BGP_ENCAPV6_NODE, &neighbor_attr_unchanged1_cmd);
10349 install_element (BGP_ENCAPV6_NODE, &neighbor_attr_unchanged2_cmd);
10350 install_element (BGP_ENCAPV6_NODE, &neighbor_attr_unchanged3_cmd);
10351 install_element (BGP_ENCAPV6_NODE, &neighbor_attr_unchanged4_cmd);
8b1fb8be
LB
10352 install_element (BGP_ENCAPV6_NODE, &no_neighbor_attr_unchanged_cmd);
10353 install_element (BGP_ENCAPV6_NODE, &no_neighbor_attr_unchanged1_cmd);
10354 install_element (BGP_ENCAPV6_NODE, &no_neighbor_attr_unchanged2_cmd);
10355 install_element (BGP_ENCAPV6_NODE, &no_neighbor_attr_unchanged3_cmd);
10356 install_element (BGP_ENCAPV6_NODE, &no_neighbor_attr_unchanged4_cmd);
718e3744 10357
fee0f4c6 10358 /* "nexthop-local unchanged" commands */
10359 install_element (BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
10360 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_local_unchanged_cmd);
10361
718e3744 10362 /* "neighbor next-hop-self" commands. */
10363 install_element (BGP_NODE, &neighbor_nexthop_self_cmd);
10364 install_element (BGP_NODE, &no_neighbor_nexthop_self_cmd);
10365 install_element (BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
10366 install_element (BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
10367 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
10368 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
10369 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
10370 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
25ffbdc1 10371 install_element (BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
10372 install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
718e3744 10373 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
10374 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
8ecd3266 10375 install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
10376 install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
8b1fb8be
LB
10377 install_element (BGP_ENCAP_NODE, &neighbor_nexthop_self_cmd);
10378 install_element (BGP_ENCAP_NODE, &no_neighbor_nexthop_self_cmd);
10379 install_element (BGP_ENCAPV6_NODE, &neighbor_nexthop_self_cmd);
10380 install_element (BGP_ENCAPV6_NODE, &no_neighbor_nexthop_self_cmd);
718e3744 10381
a538debe
DS
10382 /* "neighbor next-hop-self force" commands. */
10383 install_element (BGP_NODE, &neighbor_nexthop_self_force_cmd);
10384 install_element (BGP_NODE, &no_neighbor_nexthop_self_force_cmd);
10385 install_element (BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
10386 install_element (BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
10387 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
10388 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
10389 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
10390 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
10391 install_element (BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
10392 install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
10393 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
10394 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
8ecd3266 10395 install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
10396 install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
a538debe 10397
c7122e14
DS
10398 /* "neighbor as-override" commands. */
10399 install_element (BGP_NODE, &neighbor_as_override_cmd);
10400 install_element (BGP_NODE, &no_neighbor_as_override_cmd);
10401 install_element (BGP_IPV4_NODE, &neighbor_as_override_cmd);
10402 install_element (BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
10403 install_element (BGP_IPV4M_NODE, &neighbor_as_override_cmd);
10404 install_element (BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
10405 install_element (BGP_IPV6_NODE, &neighbor_as_override_cmd);
10406 install_element (BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
10407 install_element (BGP_IPV6M_NODE, &neighbor_as_override_cmd);
10408 install_element (BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
10409 install_element (BGP_VPNV4_NODE, &neighbor_as_override_cmd);
10410 install_element (BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
8ecd3266 10411 install_element (BGP_VPNV6_NODE, &neighbor_as_override_cmd);
10412 install_element (BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
c7122e14 10413
718e3744 10414 /* "neighbor remove-private-AS" commands. */
10415 install_element (BGP_NODE, &neighbor_remove_private_as_cmd);
10416 install_element (BGP_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
10417 install_element (BGP_NODE, &neighbor_remove_private_as_all_cmd);
10418 install_element (BGP_NODE, &no_neighbor_remove_private_as_all_cmd);
10419 install_element (BGP_NODE, &neighbor_remove_private_as_replace_as_cmd);
10420 install_element (BGP_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10421 install_element (BGP_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10422 install_element (BGP_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
718e3744 10423 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
10424 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
10425 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
10426 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
10427 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_replace_as_cmd);
10428 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10429 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10430 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
718e3744 10431 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
10432 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
10433 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
10434 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
10435 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_replace_as_cmd);
10436 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10437 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10438 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
718e3744 10439 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
10440 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
10441 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
10442 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
10443 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_replace_as_cmd);
10444 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10445 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10446 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
25ffbdc1 10447 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
10448 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
10449 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
10450 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
10451 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_replace_as_cmd);
10452 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10453 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10454 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
718e3744 10455 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
10456 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
10457 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
10458 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
10459 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_replace_as_cmd);
10460 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10461 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10462 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
8ecd3266 10463 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
10464 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
10465 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
10466 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
10467 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_replace_as_cmd);
10468 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
10469 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
10470 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
8b1fb8be
LB
10471 install_element (BGP_ENCAP_NODE, &neighbor_remove_private_as_cmd);
10472 install_element (BGP_ENCAP_NODE, &no_neighbor_remove_private_as_cmd);
10473 install_element (BGP_ENCAPV6_NODE, &neighbor_remove_private_as_cmd);
10474 install_element (BGP_ENCAPV6_NODE, &no_neighbor_remove_private_as_cmd);
718e3744 10475
10476 /* "neighbor send-community" commands.*/
10477 install_element (BGP_NODE, &neighbor_send_community_cmd);
10478 install_element (BGP_NODE, &neighbor_send_community_type_cmd);
10479 install_element (BGP_NODE, &no_neighbor_send_community_cmd);
10480 install_element (BGP_NODE, &no_neighbor_send_community_type_cmd);
10481 install_element (BGP_IPV4_NODE, &neighbor_send_community_cmd);
10482 install_element (BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
10483 install_element (BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
10484 install_element (BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
10485 install_element (BGP_IPV4M_NODE, &neighbor_send_community_cmd);
10486 install_element (BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
10487 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
10488 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
10489 install_element (BGP_IPV6_NODE, &neighbor_send_community_cmd);
10490 install_element (BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
10491 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
10492 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
25ffbdc1 10493 install_element (BGP_IPV6M_NODE, &neighbor_send_community_cmd);
10494 install_element (BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
10495 install_element (BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
10496 install_element (BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
718e3744 10497 install_element (BGP_VPNV4_NODE, &neighbor_send_community_cmd);
10498 install_element (BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
10499 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
10500 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
8ecd3266 10501 install_element (BGP_VPNV6_NODE, &neighbor_send_community_cmd);
10502 install_element (BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
10503 install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
10504 install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
8b1fb8be
LB
10505 install_element (BGP_ENCAP_NODE, &neighbor_send_community_cmd);
10506 install_element (BGP_ENCAP_NODE, &neighbor_send_community_type_cmd);
10507 install_element (BGP_ENCAP_NODE, &no_neighbor_send_community_cmd);
10508 install_element (BGP_ENCAP_NODE, &no_neighbor_send_community_type_cmd);
10509 install_element (BGP_ENCAPV6_NODE, &neighbor_send_community_cmd);
10510 install_element (BGP_ENCAPV6_NODE, &neighbor_send_community_type_cmd);
10511 install_element (BGP_ENCAPV6_NODE, &no_neighbor_send_community_cmd);
10512 install_element (BGP_ENCAPV6_NODE, &no_neighbor_send_community_type_cmd);
718e3744 10513
10514 /* "neighbor route-reflector" commands.*/
10515 install_element (BGP_NODE, &neighbor_route_reflector_client_cmd);
10516 install_element (BGP_NODE, &no_neighbor_route_reflector_client_cmd);
10517 install_element (BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
10518 install_element (BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
10519 install_element (BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
10520 install_element (BGP_IPV4M_NODE, &no_neighbor_route_reflector_client_cmd);
10521 install_element (BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
10522 install_element (BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
25ffbdc1 10523 install_element (BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
10524 install_element (BGP_IPV6M_NODE, &no_neighbor_route_reflector_client_cmd);
718e3744 10525 install_element (BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
10526 install_element (BGP_VPNV4_NODE, &no_neighbor_route_reflector_client_cmd);
8ecd3266 10527 install_element (BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
10528 install_element (BGP_VPNV6_NODE, &no_neighbor_route_reflector_client_cmd);
8b1fb8be
LB
10529 install_element (BGP_ENCAP_NODE, &neighbor_route_reflector_client_cmd);
10530 install_element (BGP_ENCAP_NODE, &no_neighbor_route_reflector_client_cmd);
10531 install_element (BGP_ENCAPV6_NODE, &neighbor_route_reflector_client_cmd);
10532 install_element (BGP_ENCAPV6_NODE, &no_neighbor_route_reflector_client_cmd);
718e3744 10533
10534 /* "neighbor route-server" commands.*/
10535 install_element (BGP_NODE, &neighbor_route_server_client_cmd);
10536 install_element (BGP_NODE, &no_neighbor_route_server_client_cmd);
10537 install_element (BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
10538 install_element (BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
10539 install_element (BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
10540 install_element (BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
10541 install_element (BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
10542 install_element (BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
25ffbdc1 10543 install_element (BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
10544 install_element (BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
718e3744 10545 install_element (BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
10546 install_element (BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
8ecd3266 10547 install_element (BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
10548 install_element (BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
8b1fb8be
LB
10549 install_element (BGP_ENCAP_NODE, &neighbor_route_server_client_cmd);
10550 install_element (BGP_ENCAP_NODE, &no_neighbor_route_server_client_cmd);
10551 install_element (BGP_ENCAPV6_NODE, &neighbor_route_server_client_cmd);
10552 install_element (BGP_ENCAPV6_NODE, &no_neighbor_route_server_client_cmd);
718e3744 10553
adbac85e
DW
10554 /* "neighbor addpath-tx-all-paths" commands.*/
10555 install_element (BGP_NODE, &neighbor_addpath_tx_all_paths_cmd);
10556 install_element (BGP_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10557 install_element (BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
10558 install_element (BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10559 install_element (BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
10560 install_element (BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10561 install_element (BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
10562 install_element (BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10563 install_element (BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
10564 install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
10565 install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
10566 install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
8ecd3266 10567 install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
10568 install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
adbac85e 10569
06370dac
DW
10570 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
10571 install_element (BGP_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10572 install_element (BGP_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10573 install_element (BGP_IPV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10574 install_element (BGP_IPV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10575 install_element (BGP_IPV4M_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10576 install_element (BGP_IPV4M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10577 install_element (BGP_IPV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10578 install_element (BGP_IPV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10579 install_element (BGP_IPV6M_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10580 install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
10581 install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10582 install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
8ecd3266 10583 install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
10584 install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
06370dac 10585
718e3744 10586 /* "neighbor passive" commands. */
10587 install_element (BGP_NODE, &neighbor_passive_cmd);
10588 install_element (BGP_NODE, &no_neighbor_passive_cmd);
10589
d5a5c8f0 10590
718e3744 10591 /* "neighbor shutdown" commands. */
10592 install_element (BGP_NODE, &neighbor_shutdown_cmd);
10593 install_element (BGP_NODE, &no_neighbor_shutdown_cmd);
10594
8a92a8a0
DS
10595 /* "neighbor capability extended-nexthop" commands.*/
10596 install_element (BGP_NODE, &neighbor_capability_enhe_cmd);
10597 install_element (BGP_NODE, &no_neighbor_capability_enhe_cmd);
10598
718e3744 10599 /* "neighbor capability orf prefix-list" commands.*/
10600 install_element (BGP_NODE, &neighbor_capability_orf_prefix_cmd);
10601 install_element (BGP_NODE, &no_neighbor_capability_orf_prefix_cmd);
10602 install_element (BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
10603 install_element (BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
10604 install_element (BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
10605 install_element (BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
10606 install_element (BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
10607 install_element (BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
25ffbdc1 10608 install_element (BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
10609 install_element (BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
718e3744 10610
10611 /* "neighbor capability dynamic" commands.*/
10612 install_element (BGP_NODE, &neighbor_capability_dynamic_cmd);
10613 install_element (BGP_NODE, &no_neighbor_capability_dynamic_cmd);
10614
10615 /* "neighbor dont-capability-negotiate" commands. */
10616 install_element (BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
10617 install_element (BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
10618
10619 /* "neighbor ebgp-multihop" commands. */
10620 install_element (BGP_NODE, &neighbor_ebgp_multihop_cmd);
10621 install_element (BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
10622 install_element (BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
718e3744 10623
6ffd2079 10624 /* "neighbor disable-connected-check" commands. */
10625 install_element (BGP_NODE, &neighbor_disable_connected_check_cmd);
10626 install_element (BGP_NODE, &no_neighbor_disable_connected_check_cmd);
718e3744 10627
10628 /* "neighbor description" commands. */
10629 install_element (BGP_NODE, &neighbor_description_cmd);
10630 install_element (BGP_NODE, &no_neighbor_description_cmd);
718e3744 10631
10632 /* "neighbor update-source" commands. "*/
10633 install_element (BGP_NODE, &neighbor_update_source_cmd);
10634 install_element (BGP_NODE, &no_neighbor_update_source_cmd);
10635
10636 /* "neighbor default-originate" commands. */
10637 install_element (BGP_NODE, &neighbor_default_originate_cmd);
10638 install_element (BGP_NODE, &neighbor_default_originate_rmap_cmd);
10639 install_element (BGP_NODE, &no_neighbor_default_originate_cmd);
718e3744 10640 install_element (BGP_IPV4_NODE, &neighbor_default_originate_cmd);
10641 install_element (BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
10642 install_element (BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
718e3744 10643 install_element (BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
10644 install_element (BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
10645 install_element (BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
718e3744 10646 install_element (BGP_IPV6_NODE, &neighbor_default_originate_cmd);
10647 install_element (BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
10648 install_element (BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
25ffbdc1 10649 install_element (BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
10650 install_element (BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
10651 install_element (BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
718e3744 10652
10653 /* "neighbor port" commands. */
10654 install_element (BGP_NODE, &neighbor_port_cmd);
10655 install_element (BGP_NODE, &no_neighbor_port_cmd);
718e3744 10656
10657 /* "neighbor weight" commands. */
10658 install_element (BGP_NODE, &neighbor_weight_cmd);
10659 install_element (BGP_NODE, &no_neighbor_weight_cmd);
718e3744 10660
d93f7ffc
DW
10661 install_element (BGP_IPV4_NODE, &neighbor_weight_cmd);
10662 install_element (BGP_IPV4_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
10663 install_element (BGP_IPV4M_NODE, &neighbor_weight_cmd);
10664 install_element (BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
10665 install_element (BGP_IPV6_NODE, &neighbor_weight_cmd);
10666 install_element (BGP_IPV6_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
10667 install_element (BGP_IPV6M_NODE, &neighbor_weight_cmd);
10668 install_element (BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
10669 install_element (BGP_VPNV4_NODE, &neighbor_weight_cmd);
10670 install_element (BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
10671 install_element (BGP_VPNV6_NODE, &neighbor_weight_cmd);
10672 install_element (BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
10673 install_element (BGP_ENCAP_NODE, &neighbor_weight_cmd);
10674 install_element (BGP_ENCAP_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
10675 install_element (BGP_ENCAPV6_NODE, &neighbor_weight_cmd);
10676 install_element (BGP_ENCAPV6_NODE, &no_neighbor_weight_cmd);
718e3744 10677
10678 /* "neighbor override-capability" commands. */
10679 install_element (BGP_NODE, &neighbor_override_capability_cmd);
10680 install_element (BGP_NODE, &no_neighbor_override_capability_cmd);
10681
10682 /* "neighbor strict-capability-match" commands. */
10683 install_element (BGP_NODE, &neighbor_strict_capability_cmd);
10684 install_element (BGP_NODE, &no_neighbor_strict_capability_cmd);
10685
10686 /* "neighbor timers" commands. */
10687 install_element (BGP_NODE, &neighbor_timers_cmd);
10688 install_element (BGP_NODE, &no_neighbor_timers_cmd);
10689
10690 /* "neighbor timers connect" commands. */
10691 install_element (BGP_NODE, &neighbor_timers_connect_cmd);
10692 install_element (BGP_NODE, &no_neighbor_timers_connect_cmd);
718e3744 10693
10694 /* "neighbor advertisement-interval" commands. */
10695 install_element (BGP_NODE, &neighbor_advertise_interval_cmd);
10696 install_element (BGP_NODE, &no_neighbor_advertise_interval_cmd);
718e3744 10697
718e3744 10698 /* "neighbor interface" commands. */
10699 install_element (BGP_NODE, &neighbor_interface_cmd);
10700 install_element (BGP_NODE, &no_neighbor_interface_cmd);
10701
10702 /* "neighbor distribute" commands. */
10703 install_element (BGP_NODE, &neighbor_distribute_list_cmd);
10704 install_element (BGP_NODE, &no_neighbor_distribute_list_cmd);
10705 install_element (BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
10706 install_element (BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
10707 install_element (BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
10708 install_element (BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
10709 install_element (BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
10710 install_element (BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
25ffbdc1 10711 install_element (BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
10712 install_element (BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
718e3744 10713 install_element (BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
10714 install_element (BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
8ecd3266 10715 install_element (BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
10716 install_element (BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
8b1fb8be
LB
10717 install_element (BGP_ENCAP_NODE, &neighbor_distribute_list_cmd);
10718 install_element (BGP_ENCAP_NODE, &no_neighbor_distribute_list_cmd);
10719 install_element (BGP_ENCAPV6_NODE, &neighbor_distribute_list_cmd);
10720 install_element (BGP_ENCAPV6_NODE, &no_neighbor_distribute_list_cmd);
718e3744 10721
10722 /* "neighbor prefix-list" commands. */
10723 install_element (BGP_NODE, &neighbor_prefix_list_cmd);
10724 install_element (BGP_NODE, &no_neighbor_prefix_list_cmd);
10725 install_element (BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
10726 install_element (BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
10727 install_element (BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
10728 install_element (BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
10729 install_element (BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
10730 install_element (BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
25ffbdc1 10731 install_element (BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
10732 install_element (BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
718e3744 10733 install_element (BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
10734 install_element (BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
8ecd3266 10735 install_element (BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
10736 install_element (BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
8b1fb8be
LB
10737 install_element (BGP_ENCAP_NODE, &neighbor_prefix_list_cmd);
10738 install_element (BGP_ENCAP_NODE, &no_neighbor_prefix_list_cmd);
10739 install_element (BGP_ENCAPV6_NODE, &neighbor_prefix_list_cmd);
10740 install_element (BGP_ENCAPV6_NODE, &no_neighbor_prefix_list_cmd);
718e3744 10741
10742 /* "neighbor filter-list" commands. */
10743 install_element (BGP_NODE, &neighbor_filter_list_cmd);
10744 install_element (BGP_NODE, &no_neighbor_filter_list_cmd);
10745 install_element (BGP_IPV4_NODE, &neighbor_filter_list_cmd);
10746 install_element (BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
10747 install_element (BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
10748 install_element (BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
10749 install_element (BGP_IPV6_NODE, &neighbor_filter_list_cmd);
10750 install_element (BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
25ffbdc1 10751 install_element (BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
10752 install_element (BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
718e3744 10753 install_element (BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
10754 install_element (BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
8ecd3266 10755 install_element (BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
10756 install_element (BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
8b1fb8be
LB
10757 install_element (BGP_ENCAP_NODE, &neighbor_filter_list_cmd);
10758 install_element (BGP_ENCAP_NODE, &no_neighbor_filter_list_cmd);
10759 install_element (BGP_ENCAPV6_NODE, &neighbor_filter_list_cmd);
10760 install_element (BGP_ENCAPV6_NODE, &no_neighbor_filter_list_cmd);
718e3744 10761
10762 /* "neighbor route-map" commands. */
10763 install_element (BGP_NODE, &neighbor_route_map_cmd);
10764 install_element (BGP_NODE, &no_neighbor_route_map_cmd);
10765 install_element (BGP_IPV4_NODE, &neighbor_route_map_cmd);
10766 install_element (BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
10767 install_element (BGP_IPV4M_NODE, &neighbor_route_map_cmd);
10768 install_element (BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
10769 install_element (BGP_IPV6_NODE, &neighbor_route_map_cmd);
10770 install_element (BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
25ffbdc1 10771 install_element (BGP_IPV6M_NODE, &neighbor_route_map_cmd);
10772 install_element (BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
718e3744 10773 install_element (BGP_VPNV4_NODE, &neighbor_route_map_cmd);
10774 install_element (BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
8ecd3266 10775 install_element (BGP_VPNV6_NODE, &neighbor_route_map_cmd);
10776 install_element (BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
8b1fb8be
LB
10777 install_element (BGP_ENCAP_NODE, &neighbor_route_map_cmd);
10778 install_element (BGP_ENCAP_NODE, &no_neighbor_route_map_cmd);
10779 install_element (BGP_ENCAPV6_NODE, &neighbor_route_map_cmd);
10780 install_element (BGP_ENCAPV6_NODE, &no_neighbor_route_map_cmd);
718e3744 10781
10782 /* "neighbor unsuppress-map" commands. */
10783 install_element (BGP_NODE, &neighbor_unsuppress_map_cmd);
10784 install_element (BGP_NODE, &no_neighbor_unsuppress_map_cmd);
10785 install_element (BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
10786 install_element (BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
10787 install_element (BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
10788 install_element (BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
10789 install_element (BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
10790 install_element (BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
25ffbdc1 10791 install_element (BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
10792 install_element (BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
a58545bb 10793 install_element (BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
bb86c601 10794 install_element (BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
8ecd3266 10795 install_element (BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
bb86c601 10796 install_element (BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
8b1fb8be
LB
10797 install_element (BGP_ENCAP_NODE, &neighbor_unsuppress_map_cmd);
10798 install_element (BGP_ENCAP_NODE, &no_neighbor_unsuppress_map_cmd);
10799 install_element (BGP_ENCAPV6_NODE, &neighbor_unsuppress_map_cmd);
10800 install_element (BGP_ENCAPV6_NODE, &no_neighbor_unsuppress_map_cmd);
718e3744 10801
10802 /* "neighbor maximum-prefix" commands. */
10803 install_element (BGP_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 10804 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 10805 install_element (BGP_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 10806 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 10807 install_element (BGP_NODE, &neighbor_maximum_prefix_restart_cmd);
10808 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 10809 install_element (BGP_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 10810 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 10811 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 10812 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 10813 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 10814 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
10815 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 10816 install_element (BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 10817 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 10818 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 10819 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 10820 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 10821 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
10822 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 10823 install_element (BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 10824 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 10825 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 10826 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 10827 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 10828 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
10829 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 10830 install_element (BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
25ffbdc1 10831 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
10832 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
10833 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
10834 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10835 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
10836 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10837 install_element (BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 10838 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 10839 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 10840 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 10841 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 10842 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
10843 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 10844 install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
8ecd3266 10845 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
10846 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
10847 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
10848 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10849 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
10850 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10851 install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 10852
8b1fb8be
LB
10853 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_cmd);
10854 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_threshold_cmd);
10855 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_warning_cmd);
10856 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10857 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_restart_cmd);
10858 install_element (BGP_ENCAP_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10859 install_element (BGP_ENCAP_NODE, &no_neighbor_maximum_prefix_cmd);
8b1fb8be
LB
10860
10861 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_cmd);
10862 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
10863 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
10864 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
10865 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
10866 install_element (BGP_ENCAPV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
10867 install_element (BGP_ENCAPV6_NODE, &no_neighbor_maximum_prefix_cmd);
8b1fb8be 10868
718e3744 10869 /* "neighbor allowas-in" */
10870 install_element (BGP_NODE, &neighbor_allowas_in_cmd);
718e3744 10871 install_element (BGP_NODE, &no_neighbor_allowas_in_cmd);
10872 install_element (BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
718e3744 10873 install_element (BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
10874 install_element (BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
718e3744 10875 install_element (BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
10876 install_element (BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
718e3744 10877 install_element (BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
25ffbdc1 10878 install_element (BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
25ffbdc1 10879 install_element (BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
718e3744 10880 install_element (BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
718e3744 10881 install_element (BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
8ecd3266 10882 install_element (BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
8ecd3266 10883 install_element (BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
8b1fb8be 10884 install_element (BGP_ENCAP_NODE, &neighbor_allowas_in_cmd);
8b1fb8be
LB
10885 install_element (BGP_ENCAP_NODE, &no_neighbor_allowas_in_cmd);
10886 install_element (BGP_ENCAPV6_NODE, &neighbor_allowas_in_cmd);
8b1fb8be 10887 install_element (BGP_ENCAPV6_NODE, &no_neighbor_allowas_in_cmd);
718e3744 10888
10889 /* address-family commands. */
10890 install_element (BGP_NODE, &address_family_ipv4_cmd);
10891 install_element (BGP_NODE, &address_family_ipv4_safi_cmd);
10892#ifdef HAVE_IPV6
10893 install_element (BGP_NODE, &address_family_ipv6_cmd);
25ffbdc1 10894 install_element (BGP_NODE, &address_family_ipv6_safi_cmd);
718e3744 10895#endif /* HAVE_IPV6 */
10896 install_element (BGP_NODE, &address_family_vpnv4_cmd);
718e3744 10897
8b1fb8be 10898 install_element (BGP_NODE, &address_family_vpnv6_cmd);
8b1fb8be
LB
10899
10900 install_element (BGP_NODE, &address_family_encap_cmd);
8b1fb8be
LB
10901#ifdef HAVE_IPV6
10902 install_element (BGP_NODE, &address_family_encapv6_cmd);
10903#endif
10904
718e3744 10905 /* "exit-address-family" command. */
10906 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
10907 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
10908 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
25ffbdc1 10909 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
718e3744 10910 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
8ecd3266 10911 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
8b1fb8be
LB
10912 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
10913 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
718e3744 10914
10915 /* "clear ip bgp commands" */
10916 install_element (ENABLE_NODE, &clear_ip_bgp_all_cmd);
718e3744 10917
8ad7271d
DS
10918 /* clear ip bgp prefix */
10919 install_element (ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
10920 install_element (ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
01080f7c 10921 install_element (ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
8ad7271d 10922
718e3744 10923 /* "show ip bgp summary" commands. */
10924 install_element (VIEW_NODE, &show_ip_bgp_summary_cmd);
3f9c7369 10925 install_element (VIEW_NODE, &show_ip_bgp_updgrps_cmd);
f186de26 10926 install_element (VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
3f9c7369 10927 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
8386ac43 10928 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
3f9c7369 10929 install_element (VIEW_NODE, &show_bgp_updgrps_adj_cmd);
8386ac43 10930 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
3f9c7369 10931 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
8fe8a7f6 10932 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
8386ac43 10933 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
8fe8a7f6 10934 install_element (VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
8386ac43 10935 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
8fe8a7f6 10936 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
e52702f2
QY
10937 install_element (VIEW_NODE, &show_ip_bgp_summary_cmd);
10938 install_element (VIEW_NODE, &show_ip_bgp_updgrps_cmd);
10939 install_element (VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
10940 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
10941 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
10942 install_element (VIEW_NODE, &show_bgp_updgrps_adj_cmd);
10943 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
10944 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
10945 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
10946 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
10947 install_element (VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
10948 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
10949 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
8c3deaae
QY
10950 install_element (VIEW_NODE, &show_bgp_updgrps_stats_cmd);
10951 install_element (VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
e3e29b32 10952
718e3744 10953 /* "show ip bgp neighbors" commands. */
10954 install_element (VIEW_NODE, &show_ip_bgp_neighbors_cmd);
718e3744 10955
f14e6fdb
DS
10956 /* "show ip bgp peer-group" commands. */
10957 install_element (VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
f14e6fdb 10958
718e3744 10959 /* "show ip bgp paths" commands. */
10960 install_element (VIEW_NODE, &show_ip_bgp_paths_cmd);
10961 install_element (VIEW_NODE, &show_ip_bgp_ipv4_paths_cmd);
718e3744 10962
10963 /* "show ip bgp community" commands. */
10964 install_element (VIEW_NODE, &show_ip_bgp_community_info_cmd);
718e3744 10965
10966 /* "show ip bgp attribute-info" commands. */
10967 install_element (VIEW_NODE, &show_ip_bgp_attr_info_cmd);
718e3744 10968
10969 /* "redistribute" commands. */
10970 install_element (BGP_NODE, &bgp_redistribute_ipv4_cmd);
10971 install_element (BGP_NODE, &no_bgp_redistribute_ipv4_cmd);
10972 install_element (BGP_NODE, &bgp_redistribute_ipv4_rmap_cmd);
718e3744 10973 install_element (BGP_NODE, &bgp_redistribute_ipv4_metric_cmd);
718e3744 10974 install_element (BGP_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
10975 install_element (BGP_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
7c8ff89e
DS
10976 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_cmd);
10977 install_element (BGP_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
10978 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
7c8ff89e 10979 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
7c8ff89e 10980 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
7c8ff89e 10981 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
919e0666
DW
10982 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
10983 install_element (BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
10984 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
919e0666 10985 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
919e0666
DW
10986 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
10987 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
919e0666
DW
10988 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
10989 install_element (BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
10990 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
919e0666 10991 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
919e0666 10992 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
919e0666 10993 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
718e3744 10994#ifdef HAVE_IPV6
10995 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
10996 install_element (BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
10997 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
718e3744 10998 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
718e3744 10999 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
11000 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
718e3744 11001#endif /* HAVE_IPV6 */
11002
fa411a21
NH
11003 /* ttl_security commands */
11004 install_element (BGP_NODE, &neighbor_ttl_security_cmd);
11005 install_element (BGP_NODE, &no_neighbor_ttl_security_cmd);
11006
4bf6a362
PJ
11007 /* "show bgp memory" commands. */
11008 install_element (VIEW_NODE, &show_bgp_memory_cmd);
e52702f2 11009
e0081f70
ML
11010 /* "show bgp views" commands. */
11011 install_element (VIEW_NODE, &show_bgp_views_cmd);
e52702f2 11012
8386ac43 11013 /* "show bgp vrfs" commands. */
11014 install_element (VIEW_NODE, &show_bgp_vrfs_cmd);
e52702f2 11015
718e3744 11016 /* Community-list. */
11017 community_list_vty ();
11018}
6b0655a2 11019
718e3744 11020#include "memory.h"
11021#include "bgp_regex.h"
11022#include "bgp_clist.h"
11023#include "bgp_ecommunity.h"
11024
11025/* VTY functions. */
11026
11027/* Direction value to string conversion. */
94f2b392 11028static const char *
718e3744 11029community_direct_str (int direct)
11030{
11031 switch (direct)
11032 {
11033 case COMMUNITY_DENY:
11034 return "deny";
718e3744 11035 case COMMUNITY_PERMIT:
11036 return "permit";
718e3744 11037 default:
11038 return "unknown";
718e3744 11039 }
11040}
11041
11042/* Display error string. */
94f2b392 11043static void
718e3744 11044community_list_perror (struct vty *vty, int ret)
11045{
11046 switch (ret)
11047 {
11048 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
b729294c 11049 vty_out (vty, "%% Can't find community-list%s", VTY_NEWLINE);
718e3744 11050 break;
11051 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
11052 vty_out (vty, "%% Malformed community-list value%s", VTY_NEWLINE);
11053 break;
11054 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
11055 vty_out (vty, "%% Community name conflict, previously defined as standard community%s", VTY_NEWLINE);
11056 break;
11057 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
11058 vty_out (vty, "%% Community name conflict, previously defined as expanded community%s", VTY_NEWLINE);
11059 break;
11060 }
11061}
11062
5bf15956
DW
11063/* "community-list" keyword help string. */
11064#define COMMUNITY_LIST_STR "Add a community list entry\n"
11065
94f2b392 11066static int
5bf15956
DW
11067community_list_set_vty (struct vty *vty, int argc, struct cmd_token **argv,
11068 int style)
718e3744 11069{
5bf15956
DW
11070 int idx_number = 2;
11071 int idx_name = 3;
11072 int idx_permit_deny = 4;
11073 int idx_aa_nn = 5;
718e3744 11074 int direct;
5bf15956 11075 int ret;
718e3744 11076 char *str;
5bf15956 11077 char *name;
718e3744 11078
11079 /* Check the list type. */
5bf15956 11080 if (strmatch(argv[idx_permit_deny]->text, "permit"))
718e3744 11081 direct = COMMUNITY_PERMIT;
718e3744 11082 else
5bf15956
DW
11083 direct = COMMUNITY_DENY;
11084
11085 if (argv[idx_number]->type == RANGE_TKN)
718e3744 11086 {
5bf15956
DW
11087 name = argv[idx_number]->arg;
11088 idx_permit_deny--;
11089 idx_aa_nn--;
718e3744 11090 }
5bf15956 11091 else
718e3744 11092 {
5bf15956
DW
11093 name = argv[idx_name]->arg;
11094
11095 /* All digit name check. */
11096 if (all_digit (name))
11097 {
11098 vty_out (vty, "%% Community name cannot have all digits%s", VTY_NEWLINE);
11099 return CMD_WARNING;
11100 }
718e3744 11101 }
11102
11103 /* Concat community string argument. */
5bf15956
DW
11104 if (argc > idx_aa_nn)
11105 str = argv_concat (argv, argc, idx_aa_nn);
718e3744 11106 else
11107 str = NULL;
11108
11109 /* When community_list_set() return nevetive value, it means
11110 malformed community string. */
5bf15956 11111 ret = community_list_set (bgp_clist, name, str, direct, style);
718e3744 11112
11113 /* Free temporary community list string allocated by
11114 argv_concat(). */
11115 if (str)
11116 XFREE (MTYPE_TMP, str);
11117
11118 if (ret < 0)
11119 {
11120 /* Display error string. */
11121 community_list_perror (vty, ret);
11122 return CMD_WARNING;
11123 }
11124
11125 return CMD_SUCCESS;
11126}
11127
94f2b392 11128static int
5bf15956
DW
11129community_list_unset_vty (struct vty *vty, int argc, struct cmd_token **argv,
11130 int style)
718e3744 11131{
5bf15956 11132 /* CHECK ME dwalton finish this
718e3744 11133 int ret;
fee6e4e4 11134 int direct = 0;
11135 char *str = NULL;
718e3744 11136
fee6e4e4 11137 if (argc > 1)
718e3744 11138 {
e52702f2 11139 // Check the list direct.
fee6e4e4 11140 if (strncmp (argv[1], "p", 1) == 0)
11141 direct = COMMUNITY_PERMIT;
11142 else if (strncmp (argv[1], "d", 1) == 0)
11143 direct = COMMUNITY_DENY;
11144 else
11145 {
11146 vty_out (vty, "%% Matching condition must be permit or deny%s",
11147 VTY_NEWLINE);
11148 return CMD_WARNING;
11149 }
718e3744 11150
5bf15956 11151 // Concat community string argument.
fee6e4e4 11152 str = argv_concat (argv, argc, 2);
11153 }
718e3744 11154
5bf15956 11155 // Unset community list
813d4307 11156 ret = community_list_unset (bgp_clist, argv[0], str, direct, style, delete_all);
718e3744 11157
5bf15956 11158 // Free temporary community list string allocated by argv_concat().
fee6e4e4 11159 if (str)
11160 XFREE (MTYPE_TMP, str);
718e3744 11161
11162 if (ret < 0)
11163 {
11164 community_list_perror (vty, ret);
11165 return CMD_WARNING;
11166 }
5bf15956 11167 * */
718e3744 11168
11169 return CMD_SUCCESS;
11170}
11171
5bf15956 11172/* ip community-list standard */
718e3744 11173DEFUN (ip_community_list_standard,
11174 ip_community_list_standard_cmd,
e961923c 11175 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 11176 IP_STR
11177 COMMUNITY_LIST_STR
11178 "Community list number (standard)\n"
5bf15956 11179 "Add an standard community-list entry\n"
718e3744 11180 "Community list name\n"
11181 "Specify community to reject\n"
11182 "Specify community to accept\n"
11183 COMMUNITY_VAL_STR)
11184{
5bf15956 11185 return community_list_set_vty (vty, argc, argv, COMMUNITY_LIST_STANDARD);
718e3744 11186}
11187
fee6e4e4 11188DEFUN (no_ip_community_list_standard_all,
11189 no_ip_community_list_standard_all_cmd,
e961923c 11190 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 11191 NO_STR
11192 IP_STR
11193 COMMUNITY_LIST_STR
11194 "Community list number (standard)\n"
5bf15956
DW
11195 "Add an standard community-list entry\n"
11196 "Community list name\n"
718e3744 11197 "Specify community to reject\n"
11198 "Specify community to accept\n"
11199 COMMUNITY_VAL_STR)
11200{
5bf15956 11201 return community_list_unset_vty (vty, argc, argv, COMMUNITY_LIST_STANDARD);
718e3744 11202}
11203
5bf15956
DW
11204/* ip community-list expanded */
11205DEFUN (ip_community_list_expanded_all,
11206 ip_community_list_expanded_all_cmd,
e961923c 11207 "ip community-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 11208 IP_STR
11209 COMMUNITY_LIST_STR
11210 "Community list number (expanded)\n"
5bf15956 11211 "Add an expanded 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_EXPANDED);
718e3744 11218}
11219
5bf15956
DW
11220DEFUN (no_ip_community_list_expanded_all,
11221 no_ip_community_list_expanded_all_cmd,
e961923c 11222 "no ip community-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 11223 NO_STR
11224 IP_STR
11225 COMMUNITY_LIST_STR
5bf15956
DW
11226 "Community list number (expanded)\n"
11227 "Add an expanded community-list entry\n"
718e3744 11228 "Community list name\n"
11229 "Specify community to reject\n"
11230 "Specify community to accept\n"
5bf15956 11231 COMMUNITY_VAL_STR)
718e3744 11232{
5bf15956 11233 return community_list_unset_vty (vty, argc, argv, COMMUNITY_LIST_EXPANDED);
718e3744 11234}
11235
94f2b392 11236static void
718e3744 11237community_list_show (struct vty *vty, struct community_list *list)
11238{
11239 struct community_entry *entry;
11240
11241 for (entry = list->head; entry; entry = entry->next)
11242 {
11243 if (entry == list->head)
11244 {
11245 if (all_digit (list->name))
11246 vty_out (vty, "Community %s list %s%s",
11247 entry->style == COMMUNITY_LIST_STANDARD ?
11248 "standard" : "(expanded) access",
11249 list->name, VTY_NEWLINE);
11250 else
11251 vty_out (vty, "Named Community %s list %s%s",
11252 entry->style == COMMUNITY_LIST_STANDARD ?
11253 "standard" : "expanded",
11254 list->name, VTY_NEWLINE);
11255 }
11256 if (entry->any)
11257 vty_out (vty, " %s%s",
11258 community_direct_str (entry->direct), VTY_NEWLINE);
11259 else
11260 vty_out (vty, " %s %s%s",
11261 community_direct_str (entry->direct),
11262 entry->style == COMMUNITY_LIST_STANDARD
11263 ? community_str (entry->u.com) : entry->config,
11264 VTY_NEWLINE);
11265 }
11266}
11267
11268DEFUN (show_ip_community_list,
11269 show_ip_community_list_cmd,
11270 "show ip community-list",
11271 SHOW_STR
11272 IP_STR
11273 "List community-list\n")
11274{
11275 struct community_list *list;
11276 struct community_list_master *cm;
11277
fee6e4e4 11278 cm = community_list_master_lookup (bgp_clist, COMMUNITY_LIST_MASTER);
718e3744 11279 if (! cm)
11280 return CMD_SUCCESS;
11281
11282 for (list = cm->num.head; list; list = list->next)
11283 community_list_show (vty, list);
11284
11285 for (list = cm->str.head; list; list = list->next)
11286 community_list_show (vty, list);
11287
11288 return CMD_SUCCESS;
11289}
11290
11291DEFUN (show_ip_community_list_arg,
11292 show_ip_community_list_arg_cmd,
6147e2c6 11293 "show ip community-list <(1-500)|WORD>",
718e3744 11294 SHOW_STR
11295 IP_STR
11296 "List community-list\n"
11297 "Community-list number\n"
11298 "Community-list name\n")
11299{
c500ae40 11300 int idx_comm_list = 3;
718e3744 11301 struct community_list *list;
11302
c500ae40 11303 list = community_list_lookup (bgp_clist, argv[idx_comm_list]->arg, COMMUNITY_LIST_MASTER);
718e3744 11304 if (! list)
11305 {
b729294c 11306 vty_out (vty, "%% Can't find community-list%s", VTY_NEWLINE);
718e3744 11307 return CMD_WARNING;
11308 }
11309
11310 community_list_show (vty, list);
11311
11312 return CMD_SUCCESS;
11313}
6b0655a2 11314
94f2b392 11315static int
e52702f2 11316extcommunity_list_set_vty (struct vty *vty, int argc, struct cmd_token **argv,
5bf15956 11317 int style)
718e3744 11318{
5bf15956 11319 /* CHECK ME dwalton finish this
718e3744 11320 int ret;
11321 int direct;
11322 char *str;
11323
5bf15956 11324 // Check the list type.
718e3744 11325 if (strncmp (argv[1], "p", 1) == 0)
11326 direct = COMMUNITY_PERMIT;
11327 else if (strncmp (argv[1], "d", 1) == 0)
11328 direct = COMMUNITY_DENY;
11329 else
11330 {
11331 vty_out (vty, "%% Matching condition must be permit or deny%s",
11332 VTY_NEWLINE);
11333 return CMD_WARNING;
11334 }
11335
e52702f2 11336 // All digit name check.
718e3744 11337 if (reject_all_digit_name && all_digit (argv[0]))
11338 {
11339 vty_out (vty, "%% Community name cannot have all digits%s", VTY_NEWLINE);
11340 return CMD_WARNING;
11341 }
11342
5bf15956 11343 // Concat community string argument.
718e3744 11344 if (argc > 1)
11345 str = argv_concat (argv, argc, 2);
11346 else
11347 str = NULL;
11348
11349 ret = extcommunity_list_set (bgp_clist, argv[0], str, direct, style);
11350
e52702f2 11351 // Free temporary community list string allocated by argv_concat().
718e3744 11352 if (str)
11353 XFREE (MTYPE_TMP, str);
11354
11355 if (ret < 0)
11356 {
11357 community_list_perror (vty, ret);
11358 return CMD_WARNING;
11359 }
5bf15956 11360 */
718e3744 11361 return CMD_SUCCESS;
11362}
11363
94f2b392 11364static int
afec25d9 11365extcommunity_list_unset_vty (struct vty *vty, int argc, struct cmd_token **argv,
5bf15956 11366 int style)
718e3744 11367{
5bf15956 11368 /* CHECK ME dwalton finish this
718e3744 11369 int ret;
fee6e4e4 11370 int direct = 0;
11371 char *str = NULL;
718e3744 11372
fee6e4e4 11373 if (argc > 1)
718e3744 11374 {
5bf15956 11375 // Check the list direct
fee6e4e4 11376 if (strncmp (argv[1], "p", 1) == 0)
11377 direct = COMMUNITY_PERMIT;
11378 else if (strncmp (argv[1], "d", 1) == 0)
11379 direct = COMMUNITY_DENY;
11380 else
11381 {
11382 vty_out (vty, "%% Matching condition must be permit or deny%s",
11383 VTY_NEWLINE);
11384 return CMD_WARNING;
11385 }
718e3744 11386
5bf15956 11387 // Concat community string argument.
fee6e4e4 11388 str = argv_concat (argv, argc, 2);
718e3744 11389 }
11390
5bf15956
DW
11391 // Unset community list.
11392 ret = extcommunity_list_unset (bgp_clist, argv[0], str, direct, EXTCOMMUNITY_LIST_STANDARD, delete_all);
718e3744 11393
5bf15956 11394 // Free temporary community list string allocated by argv_concat().
fee6e4e4 11395 if (str)
11396 XFREE (MTYPE_TMP, str);
718e3744 11397
11398 if (ret < 0)
11399 {
11400 community_list_perror (vty, ret);
11401 return CMD_WARNING;
11402 }
11403
5bf15956 11404 */
718e3744 11405 return CMD_SUCCESS;
11406}
11407
11408/* "extcommunity-list" keyword help string. */
11409#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
11410#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
11411
11412DEFUN (ip_extcommunity_list_standard,
11413 ip_extcommunity_list_standard_cmd,
e961923c 11414 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 11415 IP_STR
11416 EXTCOMMUNITY_LIST_STR
11417 "Extended Community list number (standard)\n"
718e3744 11418 "Specify standard extcommunity-list\n"
5bf15956 11419 "Community list name\n"
718e3744 11420 "Specify community to reject\n"
11421 "Specify community to accept\n"
11422 EXTCOMMUNITY_VAL_STR)
11423{
5bf15956 11424 return extcommunity_list_set_vty (vty, argc, argv, EXTCOMMUNITY_LIST_STANDARD);
718e3744 11425}
11426
718e3744 11427DEFUN (ip_extcommunity_list_name_expanded,
11428 ip_extcommunity_list_name_expanded_cmd,
e961923c 11429 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 11430 IP_STR
11431 EXTCOMMUNITY_LIST_STR
5bf15956 11432 "Extended Community list number (expanded)\n"
718e3744 11433 "Specify expanded extcommunity-list\n"
11434 "Extended Community list name\n"
11435 "Specify community to reject\n"
11436 "Specify community to accept\n"
11437 "An ordered list as a regular-expression\n")
11438{
5bf15956 11439 return extcommunity_list_set_vty (vty, argc, argv, EXTCOMMUNITY_LIST_EXPANDED);
718e3744 11440}
11441
fee6e4e4 11442DEFUN (no_ip_extcommunity_list_standard_all,
11443 no_ip_extcommunity_list_standard_all_cmd,
e961923c 11444 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
11445 NO_STR
11446 IP_STR
11447 EXTCOMMUNITY_LIST_STR
11448 "Extended Community list number (standard)\n"
718e3744 11449 "Specify standard extcommunity-list\n"
5bf15956 11450 "Community list name\n"
718e3744 11451 "Specify community to reject\n"
11452 "Specify community to accept\n"
11453 EXTCOMMUNITY_VAL_STR)
11454{
5bf15956 11455 return extcommunity_list_unset_vty (vty, argc, argv, EXTCOMMUNITY_LIST_EXPANDED);
718e3744 11456}
11457
5bf15956
DW
11458DEFUN (no_ip_extcommunity_list_expanded_all,
11459 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 11460 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 11461 NO_STR
11462 IP_STR
11463 EXTCOMMUNITY_LIST_STR
11464 "Extended Community list number (expanded)\n"
718e3744 11465 "Specify expanded extcommunity-list\n"
5bf15956 11466 "Extended Community list name\n"
718e3744 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_unset_vty (vty, argc, argv, EXTCOMMUNITY_LIST_EXPANDED);
718e3744 11472}
11473
94f2b392 11474static void
718e3744 11475extcommunity_list_show (struct vty *vty, struct community_list *list)
11476{
11477 struct community_entry *entry;
11478
11479 for (entry = list->head; entry; entry = entry->next)
11480 {
11481 if (entry == list->head)
11482 {
11483 if (all_digit (list->name))
11484 vty_out (vty, "Extended community %s list %s%s",
11485 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11486 "standard" : "(expanded) access",
11487 list->name, VTY_NEWLINE);
11488 else
11489 vty_out (vty, "Named extended community %s list %s%s",
11490 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11491 "standard" : "expanded",
11492 list->name, VTY_NEWLINE);
11493 }
11494 if (entry->any)
11495 vty_out (vty, " %s%s",
11496 community_direct_str (entry->direct), VTY_NEWLINE);
11497 else
11498 vty_out (vty, " %s %s%s",
11499 community_direct_str (entry->direct),
11500 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
11501 entry->u.ecom->str : entry->config,
11502 VTY_NEWLINE);
11503 }
11504}
11505
11506DEFUN (show_ip_extcommunity_list,
11507 show_ip_extcommunity_list_cmd,
11508 "show ip extcommunity-list",
11509 SHOW_STR
11510 IP_STR
11511 "List extended-community list\n")
11512{
11513 struct community_list *list;
11514 struct community_list_master *cm;
11515
fee6e4e4 11516 cm = community_list_master_lookup (bgp_clist, EXTCOMMUNITY_LIST_MASTER);
718e3744 11517 if (! cm)
11518 return CMD_SUCCESS;
11519
11520 for (list = cm->num.head; list; list = list->next)
11521 extcommunity_list_show (vty, list);
11522
11523 for (list = cm->str.head; list; list = list->next)
11524 extcommunity_list_show (vty, list);
11525
11526 return CMD_SUCCESS;
11527}
11528
11529DEFUN (show_ip_extcommunity_list_arg,
11530 show_ip_extcommunity_list_arg_cmd,
6147e2c6 11531 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 11532 SHOW_STR
11533 IP_STR
11534 "List extended-community list\n"
11535 "Extcommunity-list number\n"
11536 "Extcommunity-list name\n")
11537{
c500ae40 11538 int idx_comm_list = 3;
718e3744 11539 struct community_list *list;
11540
c500ae40 11541 list = community_list_lookup (bgp_clist, argv[idx_comm_list]->arg, EXTCOMMUNITY_LIST_MASTER);
718e3744 11542 if (! list)
11543 {
b729294c 11544 vty_out (vty, "%% Can't find extcommunity-list%s", VTY_NEWLINE);
718e3744 11545 return CMD_WARNING;
11546 }
11547
11548 extcommunity_list_show (vty, list);
11549
11550 return CMD_SUCCESS;
11551}
6b0655a2 11552
718e3744 11553/* Return configuration string of community-list entry. */
fd79ac91 11554static const char *
718e3744 11555community_list_config_str (struct community_entry *entry)
11556{
fd79ac91 11557 const char *str;
718e3744 11558
11559 if (entry->any)
11560 str = "";
11561 else
11562 {
11563 if (entry->style == COMMUNITY_LIST_STANDARD)
11564 str = community_str (entry->u.com);
11565 else
11566 str = entry->config;
11567 }
11568 return str;
11569}
11570
11571/* Display community-list and extcommunity-list configuration. */
94f2b392 11572static int
718e3744 11573community_list_config_write (struct vty *vty)
11574{
11575 struct community_list *list;
11576 struct community_entry *entry;
11577 struct community_list_master *cm;
11578 int write = 0;
11579
11580 /* Community-list. */
fee6e4e4 11581 cm = community_list_master_lookup (bgp_clist, COMMUNITY_LIST_MASTER);
718e3744 11582
11583 for (list = cm->num.head; list; list = list->next)
11584 for (entry = list->head; entry; entry = entry->next)
11585 {
fee6e4e4 11586 vty_out (vty, "ip community-list %s %s %s%s",
11587 list->name, community_direct_str (entry->direct),
11588 community_list_config_str (entry),
11589 VTY_NEWLINE);
718e3744 11590 write++;
11591 }
11592 for (list = cm->str.head; list; list = list->next)
11593 for (entry = list->head; entry; entry = entry->next)
11594 {
11595 vty_out (vty, "ip community-list %s %s %s %s%s",
11596 entry->style == COMMUNITY_LIST_STANDARD
11597 ? "standard" : "expanded",
11598 list->name, community_direct_str (entry->direct),
11599 community_list_config_str (entry),
11600 VTY_NEWLINE);
11601 write++;
11602 }
11603
11604 /* Extcommunity-list. */
fee6e4e4 11605 cm = community_list_master_lookup (bgp_clist, EXTCOMMUNITY_LIST_MASTER);
718e3744 11606
11607 for (list = cm->num.head; list; list = list->next)
11608 for (entry = list->head; entry; entry = entry->next)
11609 {
fee6e4e4 11610 vty_out (vty, "ip extcommunity-list %s %s %s%s",
11611 list->name, community_direct_str (entry->direct),
11612 community_list_config_str (entry), VTY_NEWLINE);
718e3744 11613 write++;
11614 }
11615 for (list = cm->str.head; list; list = list->next)
11616 for (entry = list->head; entry; entry = entry->next)
11617 {
11618 vty_out (vty, "ip extcommunity-list %s %s %s %s%s",
11619 entry->style == EXTCOMMUNITY_LIST_STANDARD
11620 ? "standard" : "expanded",
11621 list->name, community_direct_str (entry->direct),
11622 community_list_config_str (entry), VTY_NEWLINE);
11623 write++;
11624 }
11625 return write;
11626}
11627
7fc626de 11628static struct cmd_node community_list_node =
718e3744 11629{
11630 COMMUNITY_LIST_NODE,
11631 "",
11632 1 /* Export to vtysh. */
11633};
11634
94f2b392 11635static void
11636community_list_vty (void)
718e3744 11637{
11638 install_node (&community_list_node, community_list_config_write);
11639
11640 /* Community-list. */
718e3744 11641 install_element (CONFIG_NODE, &ip_community_list_standard_cmd);
fee6e4e4 11642 install_element (CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
11643 install_element (CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
718e3744 11644 install_element (VIEW_NODE, &show_ip_community_list_cmd);
11645 install_element (VIEW_NODE, &show_ip_community_list_arg_cmd);
718e3744 11646
11647 /* Extcommunity-list. */
11648 install_element (CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
718e3744 11649 install_element (CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
fee6e4e4 11650 install_element (CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
11651 install_element (CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
718e3744 11652 install_element (VIEW_NODE, &show_ip_extcommunity_list_cmd);
11653 install_element (VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
5bf15956 11654}