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