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