]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: Add view/vrf auto completion to commands
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 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);
20aeb970 63
f51bae9c
DS
64static enum node_type
65bgp_node_type (afi_t afi, safi_t safi)
66{
67 switch (afi)
68 {
69 case AFI_IP:
70 switch (safi)
71 {
72 case SAFI_UNICAST:
73 return BGP_IPV4_NODE;
74 break;
75 case SAFI_MULTICAST:
76 return BGP_IPV4M_NODE;
77 break;
78 case SAFI_LABELED_UNICAST:
79 return BGP_IPV4L_NODE;
80 break;
81 case SAFI_MPLS_VPN:
82 return BGP_VPNV4_NODE;
83 break;
f51bae9c
DS
84 }
85 break;
86 case AFI_IP6:
87 switch (safi)
88 {
89 case SAFI_UNICAST:
90 return BGP_IPV6_NODE;
91 break;
92 case SAFI_MULTICAST:
93 return BGP_IPV6M_NODE;
94 break;
95 case SAFI_LABELED_UNICAST:
96 return BGP_IPV6L_NODE;
97 break;
98 case SAFI_MPLS_VPN:
99 return BGP_VPNV6_NODE;
100 break;
f51bae9c
DS
101 }
102 break;
b3b3879c
DS
103 case AFI_L2VPN:
104 return BGP_EVPN_NODE;
105 break;
106 case AFI_MAX:
107 // We should never be here but to clarify the switch statement..
108 return BGP_IPV4_NODE;
f51bae9c
DS
109 break;
110 }
b3b3879c
DS
111
112 // Impossible to happen
113 return BGP_IPV4_NODE;
f51bae9c 114}
20eb8864 115
718e3744 116/* Utility function to get address family from current node. */
117afi_t
118bgp_node_afi (struct vty *vty)
119{
4e851f1f
LB
120 afi_t afi;
121 switch (vty->node)
122 {
123 case BGP_IPV6_NODE:
124 case BGP_IPV6M_NODE:
f51bae9c 125 case BGP_IPV6L_NODE:
4e851f1f 126 case BGP_VPNV6_NODE:
4e851f1f
LB
127 afi = AFI_IP6;
128 break;
4e0b7b6d
PG
129 case BGP_EVPN_NODE:
130 afi = AFI_L2VPN;
131 break;
4e851f1f
LB
132 default:
133 afi = AFI_IP;
134 break;
135 }
136 return afi;
718e3744 137}
138
139/* Utility function to get subsequent address family from current
140 node. */
141safi_t
142bgp_node_safi (struct vty *vty)
143{
4e851f1f
LB
144 safi_t safi;
145 switch (vty->node)
146 {
4e851f1f
LB
147 case BGP_VPNV4_NODE:
148 case BGP_VPNV6_NODE:
149 safi = SAFI_MPLS_VPN;
150 break;
151 case BGP_IPV4M_NODE:
152 case BGP_IPV6M_NODE:
153 safi = SAFI_MULTICAST;
154 break;
4e0b7b6d
PG
155 case BGP_EVPN_NODE:
156 safi = SAFI_EVPN;
157 break;
f51bae9c
DS
158 case BGP_IPV4L_NODE:
159 case BGP_IPV6L_NODE:
160 safi = SAFI_LABELED_UNICAST;
161 break;
4e851f1f
LB
162 default:
163 safi = SAFI_UNICAST;
164 break;
165 }
166 return safi;
718e3744 167}
168
46f296b4
LB
169/* supports <ipv4|ipv6> */
170afi_t
171bgp_vty_afi_from_arg(const char *afi_str)
8b1fb8be 172{
46f296b4
LB
173 afi_t afi = AFI_MAX; /* unknown */
174 if (!strcmp(afi_str, "ipv4")) {
175 afi = AFI_IP;
8b1fb8be 176 }
46f296b4
LB
177 else if (!strcmp(afi_str, "ipv6")) {
178 afi = AFI_IP6;
179 }
4e0b7b6d
PG
180 else if (!strcmp(afi_str, "l2vpn")) {
181 afi = AFI_L2VPN;
182 }
46f296b4
LB
183 return afi;
184}
185
186int
187bgp_parse_afi(const char *str, afi_t *afi)
188{
189 *afi = bgp_vty_afi_from_arg(str);
190 if (*afi != AFI_MAX)
191 return 0;
192 else
8b1fb8be
LB
193 return -1;
194}
195
46f296b4
LB
196int
197argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index, afi_t *afi)
198{
199 int ret = 0;
200 if (argv_find (argv, argc, "ipv4", index))
201 {
202 ret = 1;
203 if (afi)
204 *afi = AFI_IP;
205 }
206 else if (argv_find (argv, argc, "ipv6", index))
207 {
208 ret = 1;
209 if (afi)
210 *afi = AFI_IP6;
211 }
212 return ret;
213}
214
375a2e67 215/* supports <unicast|multicast|vpn|labeled-unicast> */
ccbb332a 216safi_t
3b14d86e 217bgp_vty_safi_from_arg(const char *safi_str)
ccbb332a
LB
218{
219 safi_t safi = SAFI_MAX; /* unknown */
220 if (strncmp (safi_str, "m", 1) == 0)
221 safi = SAFI_MULTICAST;
222 else if (strncmp (safi_str, "u", 1) == 0)
223 safi = SAFI_UNICAST;
ccbb332a 224 else if (strncmp (safi_str, "v", 1) == 0)
46f296b4 225 safi = SAFI_MPLS_VPN;
f51bae9c
DS
226 else if (strncmp (safi_str, "l", 1) == 0)
227 safi = SAFI_LABELED_UNICAST;
ccbb332a
LB
228 return safi;
229}
230
8b1fb8be 231int
3289141f 232argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t *safi)
46f296b4
LB
233{
234 int ret = 0;
235 if (argv_find (argv, argc, "unicast", index))
236 {
237 ret = 1;
238 if (safi)
239 *safi = SAFI_UNICAST;
240 }
241 else if (argv_find (argv, argc, "multicast", index))
242 {
243 ret = 1;
244 if (safi)
245 *safi = SAFI_MULTICAST;
246 }
b60f5275
DS
247 else if (argv_find (argv, argc, "labeled-unicast", index))
248 {
249 ret = 1;
250 if (safi)
251 *safi = SAFI_LABELED_UNICAST;
252 }
46f296b4
LB
253 else if (argv_find (argv, argc, "vpn", index))
254 {
255 ret = 1;
256 if (safi)
257 *safi = SAFI_MPLS_VPN;
258 }
4e0b7b6d
PG
259 else if (argv_find (argv, argc, "evpn", index))
260 {
261 ret = 1;
262 if (safi)
263 *safi = SAFI_EVPN;
264 }
46f296b4
LB
265 return ret;
266}
267
7eeee51e 268/*
f212a857 269 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 270 *
f212a857
DS
271 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
272 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
273 * to appropriate values for the calling function. This is to allow the
274 * calling function to make decisions appropriate for the show command
275 * that is being parsed.
276 *
277 * The show commands are generally of the form:
18c57037 278 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
279 *
280 * Since we use argv_find if the show command in particular doesn't have:
281 * [ip]
18c57037 282 * [<view|vrf> VIEWVRFNAME]
375a2e67 283 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
284 * The command parsing should still be ok.
285 *
286 * vty -> The vty for the command so we can output some useful data in
287 * the event of a parse error in the vrf.
288 * argv -> The command tokens
289 * argc -> How many command tokens we have
290 * idx -> The current place in the command, generally should be 0 for this function
291 * afi -> The parsed afi if it was included in the show command, returned here
292 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 293 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
294 *
295 * The function returns the correct location in the parse tree for the
296 * last token found.
0e37c258
DS
297 *
298 * Returns 0 for failure to parse correctly, else the idx position of where
299 * it found the last token.
7eeee51e 300 */
af462945 301int
f212a857
DS
302bgp_vty_find_and_parse_afi_safi_bgp (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
303 afi_t *afi, safi_t *safi, struct bgp **bgp)
af462945
DS
304{
305 char *vrf_name = NULL;
306
b4898a38
DS
307 assert (afi);
308 assert (safi);
f212a857 309 assert (bgp);
b4898a38 310
9317e17d 311 if (argv_find (argv, argc, "ip", idx))
af462945
DS
312 *afi = AFI_IP;
313
9317e17d 314 if (argv_find (argv, argc, "view", idx) || argv_find (argv, argc, "vrf", idx))
af462945 315 {
9317e17d 316 vrf_name = argv[*idx + 1]->arg;
af462945 317
f212a857
DS
318 if (strmatch (vrf_name, "all"))
319 *bgp = NULL;
af462945 320 else
f212a857
DS
321 {
322 *bgp = bgp_lookup_by_name (vrf_name);
323 if (!*bgp)
324 {
325 vty_out (vty, "View/Vrf specified is unknown: %s%s", vrf_name, VTY_NEWLINE);
326 *idx = 0;
327 return 0;
328 }
329 }
af462945 330 }
f212a857 331 else
af462945 332 {
f212a857
DS
333 *bgp = bgp_get_default ();
334 if (!*bgp)
335 {
336 vty_out (vty, "Unable to find default BGP instance%s", VTY_NEWLINE);
337 *idx = 0;
338 return 0;
339 }
af462945 340 }
9317e17d 341
f212a857
DS
342 if (argv_find_and_parse_afi (argv, argc, idx, afi))
343 argv_find_and_parse_safi (argv, argc, idx, safi);
344
9317e17d
DS
345 *idx += 1;
346 return *idx;
af462945
DS
347}
348
94f2b392 349static int
6aeb9e78 350peer_address_self_check (struct bgp *bgp, union sockunion *su)
718e3744 351{
352 struct interface *ifp = NULL;
353
354 if (su->sa.sa_family == AF_INET)
6aeb9e78 355 ifp = if_lookup_by_ipv4_exact (&su->sin.sin_addr, bgp->vrf_id);
718e3744 356 else if (su->sa.sa_family == AF_INET6)
f2345335 357 ifp = if_lookup_by_ipv6_exact (&su->sin6.sin6_addr,
6aeb9e78 358 su->sin6.sin6_scope_id, bgp->vrf_id);
718e3744 359
360 if (ifp)
361 return 1;
362
363 return 0;
364}
365
366/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
367/* This is used only for configuration, so disallow if attempted on
368 * a dynamic neighbor.
369 */
94f2b392 370static struct peer *
fd79ac91 371peer_lookup_vty (struct vty *vty, const char *ip_str)
718e3744 372{
cdc2d765 373 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
718e3744 374 int ret;
718e3744 375 union sockunion su;
376 struct peer *peer;
377
cdc2d765
DL
378 if (!bgp) {
379 return NULL;
380 }
718e3744 381
382 ret = str2sockunion (ip_str, &su);
383 if (ret < 0)
384 {
a80beece
DS
385 peer = peer_lookup_by_conf_if (bgp, ip_str);
386 if (!peer)
387 {
04b6bdc0
DW
388 if ((peer = peer_lookup_by_hostname(bgp, ip_str)) == NULL)
389 {
390 vty_out (vty, "%% Malformed address or name: %s%s", ip_str, VTY_NEWLINE);
391 return NULL;
392 }
a80beece 393 }
718e3744 394 }
a80beece 395 else
718e3744 396 {
a80beece
DS
397 peer = peer_lookup (bgp, &su);
398 if (! peer)
399 {
400 vty_out (vty, "%% Specify remote-as or peer-group commands first%s",
401 VTY_NEWLINE);
402 return NULL;
403 }
f14e6fdb
DS
404 if (peer_dynamic_neighbor (peer))
405 {
406 vty_out (vty, "%% Operation not allowed on a dynamic neighbor%s",
407 VTY_NEWLINE);
408 return NULL;
409 }
410
718e3744 411 }
412 return peer;
413}
414
415/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
416/* This is used only for configuration, so disallow if attempted on
417 * a dynamic neighbor.
418 */
c43ed2e4 419struct peer *
fd79ac91 420peer_and_group_lookup_vty (struct vty *vty, const char *peer_str)
718e3744 421{
cdc2d765 422 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
718e3744 423 int ret;
718e3744 424 union sockunion su;
f14e6fdb
DS
425 struct peer *peer = NULL;
426 struct peer_group *group = NULL;
718e3744 427
cdc2d765
DL
428 if (!bgp) {
429 return NULL;
430 }
718e3744 431
432 ret = str2sockunion (peer_str, &su);
433 if (ret == 0)
434 {
f14e6fdb 435 /* IP address, locate peer. */
718e3744 436 peer = peer_lookup (bgp, &su);
718e3744 437 }
438 else
439 {
f14e6fdb 440 /* Not IP, could match either peer configured on interface or a group. */
a80beece 441 peer = peer_lookup_by_conf_if (bgp, peer_str);
f14e6fdb
DS
442 if (!peer)
443 group = peer_group_lookup (bgp, peer_str);
444 }
a80beece 445
f14e6fdb
DS
446 if (peer)
447 {
448 if (peer_dynamic_neighbor (peer))
449 {
450 vty_out (vty, "%% Operation not allowed on a dynamic neighbor%s",
451 VTY_NEWLINE);
452 return NULL;
453 }
454
455 return peer;
718e3744 456 }
457
f14e6fdb
DS
458 if (group)
459 return group->conf;
460
718e3744 461 vty_out (vty, "%% Specify remote-as or peer-group commands first%s",
462 VTY_NEWLINE);
463
464 return NULL;
465}
466
c43ed2e4 467int
718e3744 468bgp_vty_return (struct vty *vty, int ret)
469{
fd79ac91 470 const char *str = NULL;
718e3744 471
472 switch (ret)
473 {
474 case BGP_ERR_INVALID_VALUE:
475 str = "Invalid value";
476 break;
477 case BGP_ERR_INVALID_FLAG:
478 str = "Invalid flag";
479 break;
718e3744 480 case BGP_ERR_PEER_GROUP_SHUTDOWN:
481 str = "Peer-group has been shutdown. Activate the peer-group first";
482 break;
718e3744 483 case BGP_ERR_PEER_FLAG_CONFLICT:
484 str = "Can't set override-capability and strict-capability-match at the same time";
485 break;
718e3744 486 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
487 str = "Specify remote-as or peer-group remote AS first";
488 break;
489 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
490 str = "Cannot change the peer-group. Deconfigure first";
491 break;
492 case BGP_ERR_PEER_GROUP_MISMATCH:
4c48cf63 493 str = "Peer is not a member of this peer-group";
718e3744 494 break;
495 case BGP_ERR_PEER_FILTER_CONFLICT:
496 str = "Prefix/distribute list can not co-exist";
497 break;
498 case BGP_ERR_NOT_INTERNAL_PEER:
499 str = "Invalid command. Not an internal neighbor";
500 break;
501 case BGP_ERR_REMOVE_PRIVATE_AS:
5000f21c 502 str = "remove-private-AS cannot be configured for IBGP peers";
718e3744 503 break;
504 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
505 str = "Local-AS allowed only for EBGP peers";
506 break;
507 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
508 str = "Cannot have local-as same as BGP AS number";
509 break;
0df7c91f
PJ
510 case BGP_ERR_TCPSIG_FAILED:
511 str = "Error while applying TCP-Sig to session(s)";
512 break;
fa411a21
NH
513 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
514 str = "ebgp-multihop and ttl-security cannot be configured together";
515 break;
f5a4827d
SH
516 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
517 str = "ttl-security only allowed for EBGP peers";
518 break;
c7122e14
DS
519 case BGP_ERR_AS_OVERRIDE:
520 str = "as-override cannot be configured for IBGP peers";
521 break;
f14e6fdb
DS
522 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
523 str = "Invalid limit for number of dynamic neighbors";
524 break;
525 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
526 str = "Dynamic neighbor listen range already exists";
527 break;
528 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
529 str = "Operation not allowed on a dynamic neighbor";
530 break;
63fa10b5
QY
531 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
532 str = "Operation not allowed on a directly connected neighbor";
533 break;
718e3744 534 }
535 if (str)
536 {
537 vty_out (vty, "%% %s%s", str, VTY_NEWLINE);
538 return CMD_WARNING;
539 }
540 return CMD_SUCCESS;
541}
542
7aafcaca
DS
543/* BGP clear sort. */
544enum clear_sort
545{
546 clear_all,
547 clear_peer,
548 clear_group,
549 clear_external,
550 clear_as
551};
552
7aafcaca
DS
553static void
554bgp_clear_vty_error (struct vty *vty, struct peer *peer, afi_t afi,
555 safi_t safi, int error)
556{
557 switch (error)
558 {
559 case BGP_ERR_AF_UNCONFIGURED:
560 vty_out (vty,
46f296b4
LB
561 "%%BGP: Enable %s address family for the neighbor %s%s",
562 afi_safi_print(afi, safi), peer->host, VTY_NEWLINE);
7aafcaca
DS
563 break;
564 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
565 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);
566 break;
567 default:
568 break;
569 }
570}
571
572/* `clear ip bgp' functions. */
573static int
574bgp_clear (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
575 enum clear_sort sort,enum bgp_clear_type stype, const char *arg)
576{
577 int ret;
578 struct peer *peer;
579 struct listnode *node, *nnode;
580
581 /* Clear all neighbors. */
582 /*
583 * Pass along pointer to next node to peer_clear() when walking all nodes
584 * on the BGP instance as that may get freed if it is a doppelganger
585 */
586 if (sort == clear_all)
587 {
588 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
589 {
590 if (stype == BGP_CLEAR_SOFT_NONE)
591 ret = peer_clear (peer, &nnode);
592 else if (peer->afc[afi][safi])
593 ret = peer_clear_soft (peer, afi, safi, stype);
594 else
595 ret = 0;
596
597 if (ret < 0)
598 bgp_clear_vty_error (vty, peer, afi, safi, ret);
599 }
600
601 /* This is to apply read-only mode on this clear. */
602 if (stype == BGP_CLEAR_SOFT_NONE)
603 bgp->update_delay_over = 0;
604
605 return CMD_SUCCESS;
606 }
607
608 /* Clear specified neighbors. */
609 if (sort == clear_peer)
610 {
611 union sockunion su;
612 int ret;
613
614 /* Make sockunion for lookup. */
615 ret = str2sockunion (arg, &su);
616 if (ret < 0)
617 {
618 peer = peer_lookup_by_conf_if (bgp, arg);
619 if (!peer)
620 {
04b6bdc0
DW
621 peer = peer_lookup_by_hostname(bgp, arg);
622 if (!peer)
623 {
624 vty_out (vty, "Malformed address or name: %s%s", arg, VTY_NEWLINE);
625 return CMD_WARNING;
626 }
7aafcaca
DS
627 }
628 }
629 else
630 {
631 peer = peer_lookup (bgp, &su);
632 if (! peer)
633 {
634 vty_out (vty, "%%BGP: Unknown neighbor - \"%s\"%s", arg, VTY_NEWLINE);
635 return CMD_WARNING;
636 }
637 }
638
639 if (stype == BGP_CLEAR_SOFT_NONE)
640 ret = peer_clear (peer, NULL);
641 else
642 ret = peer_clear_soft (peer, afi, safi, stype);
643
644 if (ret < 0)
645 bgp_clear_vty_error (vty, peer, afi, safi, ret);
646
647 return CMD_SUCCESS;
648 }
649
650 /* Clear all peer-group members. */
651 if (sort == clear_group)
652 {
653 struct peer_group *group;
654
655 group = peer_group_lookup (bgp, arg);
656 if (! group)
657 {
658 vty_out (vty, "%%BGP: No such peer-group %s%s", arg, VTY_NEWLINE);
659 return CMD_WARNING;
660 }
661
662 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
663 {
664 if (stype == BGP_CLEAR_SOFT_NONE)
665 {
18f1dc06 666 peer_clear (peer, NULL);
7aafcaca
DS
667 continue;
668 }
669
c8560b44 670 if (! peer->afc[afi][safi])
7aafcaca
DS
671 continue;
672
673 ret = peer_clear_soft (peer, afi, safi, stype);
674
675 if (ret < 0)
676 bgp_clear_vty_error (vty, peer, afi, safi, ret);
677 }
678 return CMD_SUCCESS;
679 }
680
681 if (sort == clear_external)
682 {
683 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
684 {
685 if (peer->sort == BGP_PEER_IBGP)
686 continue;
687
688 if (stype == BGP_CLEAR_SOFT_NONE)
689 ret = peer_clear (peer, &nnode);
690 else
691 ret = peer_clear_soft (peer, afi, safi, stype);
692
693 if (ret < 0)
694 bgp_clear_vty_error (vty, peer, afi, safi, ret);
695 }
696 return CMD_SUCCESS;
697 }
698
699 if (sort == clear_as)
700 {
701 as_t as;
702 int find = 0;
703
704 VTY_GET_INTEGER_RANGE ("AS", as, arg, 1, BGP_AS4_MAX);
705
706 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
707 {
708 if (peer->as != as)
709 continue;
710
711 find = 1;
712 if (stype == BGP_CLEAR_SOFT_NONE)
713 ret = peer_clear (peer, &nnode);
714 else
715 ret = peer_clear_soft (peer, afi, safi, stype);
716
717 if (ret < 0)
718 bgp_clear_vty_error (vty, peer, afi, safi, ret);
719 }
720 if (! find)
721 vty_out (vty, "%%BGP: No peer is configured with AS %s%s", arg,
722 VTY_NEWLINE);
723 return CMD_SUCCESS;
724 }
725
726 return CMD_SUCCESS;
727}
728
729static int
730bgp_clear_vty (struct vty *vty, const char *name, afi_t afi, safi_t safi,
731 enum clear_sort sort, enum bgp_clear_type stype,
732 const char *arg)
733{
734 struct bgp *bgp;
735
736 /* BGP structure lookup. */
737 if (name)
738 {
739 bgp = bgp_lookup_by_name (name);
740 if (bgp == NULL)
741 {
6aeb9e78 742 vty_out (vty, "Can't find BGP instance %s%s", name, VTY_NEWLINE);
7aafcaca
DS
743 return CMD_WARNING;
744 }
745 }
746 else
747 {
f31fa004 748 bgp = bgp_get_default ();
7aafcaca
DS
749 if (bgp == NULL)
750 {
751 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
752 return CMD_WARNING;
753 }
754 }
755
756 return bgp_clear (vty, bgp, afi, safi, sort, stype, arg);
757}
758
759/* clear soft inbound */
760static void
f31fa004 761bgp_clear_star_soft_in (struct vty *vty, const char *name)
7aafcaca 762{
b09b5ae0 763 bgp_clear_vty (vty, name, AFI_IP, SAFI_UNICAST, clear_all,
7aafcaca 764 BGP_CLEAR_SOFT_IN, NULL);
f31fa004 765 bgp_clear_vty (vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
7aafcaca 766 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
767}
768
769/* clear soft outbound */
770static void
f31fa004 771bgp_clear_star_soft_out (struct vty *vty, const char *name)
7aafcaca 772{
f31fa004 773 bgp_clear_vty (vty, name, AFI_IP, SAFI_UNICAST, clear_all,
7aafcaca 774 BGP_CLEAR_SOFT_OUT, NULL);
f31fa004 775 bgp_clear_vty (vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
7aafcaca 776 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
777}
778
779
718e3744 780/* BGP global configuration. */
781
782DEFUN (bgp_multiple_instance_func,
783 bgp_multiple_instance_cmd,
784 "bgp multiple-instance",
785 BGP_STR
786 "Enable bgp multiple instance\n")
787{
788 bgp_option_set (BGP_OPT_MULTIPLE_INSTANCE);
789 return CMD_SUCCESS;
790}
791
792DEFUN (no_bgp_multiple_instance,
793 no_bgp_multiple_instance_cmd,
794 "no bgp multiple-instance",
795 NO_STR
796 BGP_STR
797 "BGP multiple instance\n")
798{
799 int ret;
800
801 ret = bgp_option_unset (BGP_OPT_MULTIPLE_INSTANCE);
802 if (ret < 0)
803 {
804 vty_out (vty, "%% There are more than two BGP instances%s", VTY_NEWLINE);
805 return CMD_WARNING;
806 }
807 return CMD_SUCCESS;
808}
809
810DEFUN (bgp_config_type,
811 bgp_config_type_cmd,
6147e2c6 812 "bgp config-type <cisco|zebra>",
718e3744 813 BGP_STR
814 "Configuration type\n"
815 "cisco\n"
816 "zebra\n")
817{
c500ae40
DW
818 int idx_vendor = 2;
819 if (strncmp (argv[idx_vendor]->arg, "c", 1) == 0)
718e3744 820 bgp_option_set (BGP_OPT_CONFIG_CISCO);
821 else
822 bgp_option_unset (BGP_OPT_CONFIG_CISCO);
823
824 return CMD_SUCCESS;
825}
826
827DEFUN (no_bgp_config_type,
828 no_bgp_config_type_cmd,
c7178fe7 829 "no bgp config-type [<cisco|zebra>]",
718e3744 830 NO_STR
831 BGP_STR
838758ac
DW
832 "Display configuration type\n"
833 "cisco\n"
834 "zebra\n")
718e3744 835{
836 bgp_option_unset (BGP_OPT_CONFIG_CISCO);
837 return CMD_SUCCESS;
838}
839
813d4307 840
718e3744 841DEFUN (no_synchronization,
842 no_synchronization_cmd,
843 "no synchronization",
844 NO_STR
845 "Perform IGP synchronization\n")
846{
847 return CMD_SUCCESS;
848}
849
850DEFUN (no_auto_summary,
851 no_auto_summary_cmd,
852 "no auto-summary",
853 NO_STR
854 "Enable automatic network number summarization\n")
855{
856 return CMD_SUCCESS;
857}
3d515fd9 858
718e3744 859/* "router bgp" commands. */
505e5056 860DEFUN_NOSH (router_bgp,
f412b39a 861 router_bgp_cmd,
18c57037 862 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 863 ROUTER_STR
864 BGP_STR
31500417
DW
865 AS_STR
866 BGP_INSTANCE_HELP_STR)
718e3744 867{
31500417
DW
868 int idx_asn = 2;
869 int idx_view_vrf = 3;
870 int idx_vrf = 4;
718e3744 871 int ret;
872 as_t as;
873 struct bgp *bgp;
fd79ac91 874 const char *name = NULL;
ad4cbda1 875 enum bgp_instance_type inst_type;
718e3744 876
2385a876 877 // "router bgp" without an ASN
31500417 878 if (argc == 2)
2385a876 879 {
6aeb9e78 880 //Pending: Make VRF option available for ASN less config
2385a876 881 bgp = bgp_get_default();
718e3744 882
2385a876
DW
883 if (bgp == NULL)
884 {
885 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
886 return CMD_WARNING;
887 }
718e3744 888
2385a876
DW
889 if (listcount(bm->bgp) > 1)
890 {
891 vty_out (vty, "%% Multiple BGP processes are configured%s", VTY_NEWLINE);
892 return CMD_WARNING;
893 }
894 }
895
896 // "router bgp X"
897 else
718e3744 898 {
31500417 899 VTY_GET_INTEGER_RANGE ("AS", as, argv[idx_asn]->arg, 1, BGP_AS4_MAX);
2385a876 900
ad4cbda1 901 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
31500417 902 if (argc > 3)
ad4cbda1 903 {
31500417
DW
904 name = argv[idx_vrf]->arg;
905
e52702f2 906 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
ad4cbda1 907 inst_type = BGP_INSTANCE_TYPE_VRF;
e52702f2 908 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
ad4cbda1 909 inst_type = BGP_INSTANCE_TYPE_VIEW;
910 }
2385a876 911
ad4cbda1 912 ret = bgp_get (&bgp, &as, name, inst_type);
2385a876
DW
913 switch (ret)
914 {
915 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
916 vty_out (vty, "Please specify 'bgp multiple-instance' first%s",
917 VTY_NEWLINE);
918 return CMD_WARNING;
919 case BGP_ERR_AS_MISMATCH:
920 vty_out (vty, "BGP is already running; AS is %u%s", as, VTY_NEWLINE);
921 return CMD_WARNING;
922 case BGP_ERR_INSTANCE_MISMATCH:
6aeb9e78 923 vty_out (vty, "BGP instance name and AS number mismatch%s", VTY_NEWLINE);
2385a876
DW
924 vty_out (vty, "BGP instance is already running; AS is %u%s",
925 as, VTY_NEWLINE);
926 return CMD_WARNING;
927 }
6aeb9e78
DS
928
929 /* Pending: handle when user tries to change a view to vrf n vv. */
718e3744 930 }
931
cdc2d765 932 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
718e3744 933
934 return CMD_SUCCESS;
935}
936
718e3744 937/* "no router bgp" commands. */
938DEFUN (no_router_bgp,
939 no_router_bgp_cmd,
18c57037 940 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 941 NO_STR
942 ROUTER_STR
943 BGP_STR
31500417
DW
944 AS_STR
945 BGP_INSTANCE_HELP_STR)
718e3744 946{
31500417 947 int idx_asn = 3;
31500417 948 int idx_vrf = 5;
718e3744 949 as_t as;
950 struct bgp *bgp;
fd79ac91 951 const char *name = NULL;
718e3744 952
7fb21a9f 953 // "no router bgp" without an ASN
31500417 954 if (argc == 3)
7fb21a9f
QY
955 {
956 //Pending: Make VRF option available for ASN less config
957 bgp = bgp_get_default();
718e3744 958
7fb21a9f
QY
959 if (bgp == NULL)
960 {
961 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
962 return CMD_WARNING;
963 }
964
965 if (listcount(bm->bgp) > 1)
966 {
967 vty_out (vty, "%% Multiple BGP processes are configured%s", VTY_NEWLINE);
968 return CMD_WARNING;
969 }
970 }
971 else
718e3744 972 {
31500417 973 VTY_GET_INTEGER_RANGE ("AS", as, argv[idx_asn]->arg, 1, BGP_AS4_MAX);
7fb21a9f 974
31500417
DW
975 if (argc > 4)
976 name = argv[idx_vrf]->arg;
7fb21a9f
QY
977
978 /* Lookup bgp structure. */
979 bgp = bgp_lookup (as, name);
980 if (! bgp)
981 {
982 vty_out (vty, "%% Can't find BGP instance%s", VTY_NEWLINE);
983 return CMD_WARNING;
984 }
718e3744 985 }
986
987 bgp_delete (bgp);
988
989 return CMD_SUCCESS;
990}
991
6b0655a2 992
7fb21a9f 993
718e3744 994/* BGP router-id. */
995
996DEFUN (bgp_router_id,
997 bgp_router_id_cmd,
998 "bgp router-id A.B.C.D",
999 BGP_STR
1000 "Override configured router identifier\n"
1001 "Manually configured router identifier\n")
1002{
cdc2d765 1003 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 1004 int idx_ipv4 = 2;
718e3744 1005 int ret;
1006 struct in_addr id;
718e3744 1007
c500ae40 1008 ret = inet_aton (argv[idx_ipv4]->arg, &id);
718e3744 1009 if (! ret)
1010 {
1011 vty_out (vty, "%% Malformed bgp router identifier%s", VTY_NEWLINE);
1012 return CMD_WARNING;
1013 }
1014
0e6cb743 1015 bgp_router_id_static_set (bgp, id);
718e3744 1016
1017 return CMD_SUCCESS;
1018}
1019
1020DEFUN (no_bgp_router_id,
1021 no_bgp_router_id_cmd,
31500417 1022 "no bgp router-id [A.B.C.D]",
718e3744 1023 NO_STR
1024 BGP_STR
31500417
DW
1025 "Override configured router identifier\n"
1026 "Manually configured router identifier\n")
718e3744 1027{
cdc2d765 1028 VTY_DECLVAR_CONTEXT(bgp, bgp);
31500417 1029 int idx_router_id = 3;
718e3744 1030 int ret;
1031 struct in_addr id;
718e3744 1032
31500417 1033 if (argc > idx_router_id)
718e3744 1034 {
31500417 1035 ret = inet_aton (argv[idx_router_id]->arg, &id);
718e3744 1036 if (! ret)
e018c7cc
SK
1037 {
1038 vty_out (vty, "%% Malformed BGP router identifier%s", VTY_NEWLINE);
1039 return CMD_WARNING;
1040 }
718e3744 1041
18a6dce6 1042 if (! IPV4_ADDR_SAME (&bgp->router_id_static, &id))
e018c7cc
SK
1043 {
1044 vty_out (vty, "%% BGP router-id doesn't match%s", VTY_NEWLINE);
1045 return CMD_WARNING;
1046 }
718e3744 1047 }
1048
0e6cb743
DL
1049 id.s_addr = 0;
1050 bgp_router_id_static_set (bgp, id);
718e3744 1051
1052 return CMD_SUCCESS;
1053}
1054
6b0655a2 1055
718e3744 1056/* BGP Cluster ID. */
718e3744 1057DEFUN (bgp_cluster_id,
1058 bgp_cluster_id_cmd,
838758ac 1059 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 1060 BGP_STR
1061 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
1062 "Route-Reflector Cluster-id in IP address format\n"
1063 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1064{
cdc2d765 1065 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 1066 int idx_ipv4 = 2;
718e3744 1067 int ret;
718e3744 1068 struct in_addr cluster;
1069
c500ae40 1070 ret = inet_aton (argv[idx_ipv4]->arg, &cluster);
718e3744 1071 if (! ret)
1072 {
1073 vty_out (vty, "%% Malformed bgp cluster identifier%s", VTY_NEWLINE);
1074 return CMD_WARNING;
1075 }
1076
1077 bgp_cluster_id_set (bgp, &cluster);
f31fa004 1078 bgp_clear_star_soft_out (vty, bgp->name);
718e3744 1079
1080 return CMD_SUCCESS;
1081}
1082
718e3744 1083DEFUN (no_bgp_cluster_id,
1084 no_bgp_cluster_id_cmd,
c7178fe7 1085 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1086 NO_STR
1087 BGP_STR
838758ac
DW
1088 "Configure Route-Reflector Cluster-id\n"
1089 "Route-Reflector Cluster-id in IP address format\n"
1090 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1091{
cdc2d765 1092 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1093 bgp_cluster_id_unset (bgp);
f31fa004 1094 bgp_clear_star_soft_out (vty, bgp->name);
718e3744 1095
1096 return CMD_SUCCESS;
1097}
1098
718e3744 1099DEFUN (bgp_confederation_identifier,
1100 bgp_confederation_identifier_cmd,
9ccf14f7 1101 "bgp confederation identifier (1-4294967295)",
718e3744 1102 "BGP specific commands\n"
1103 "AS confederation parameters\n"
1104 "AS number\n"
1105 "Set routing domain confederation AS\n")
1106{
cdc2d765 1107 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 1108 int idx_number = 3;
718e3744 1109 as_t as;
1110
c500ae40 1111 VTY_GET_INTEGER_RANGE ("AS", as, argv[idx_number]->arg, 1, BGP_AS4_MAX);
718e3744 1112
1113 bgp_confederation_id_set (bgp, as);
1114
1115 return CMD_SUCCESS;
1116}
1117
1118DEFUN (no_bgp_confederation_identifier,
1119 no_bgp_confederation_identifier_cmd,
838758ac 1120 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1121 NO_STR
1122 "BGP specific commands\n"
1123 "AS confederation parameters\n"
3a2d747c
QY
1124 "AS number\n"
1125 "Set routing domain confederation AS\n")
718e3744 1126{
cdc2d765 1127 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1128 bgp_confederation_id_unset (bgp);
1129
1130 return CMD_SUCCESS;
1131}
1132
718e3744 1133DEFUN (bgp_confederation_peers,
1134 bgp_confederation_peers_cmd,
12dcf78e 1135 "bgp confederation peers (1-4294967295)...",
718e3744 1136 "BGP specific commands\n"
1137 "AS confederation parameters\n"
1138 "Peer ASs in BGP confederation\n"
1139 AS_STR)
1140{
cdc2d765 1141 VTY_DECLVAR_CONTEXT(bgp, bgp);
58749582 1142 int idx_asn = 3;
718e3744 1143 as_t as;
1144 int i;
1145
58749582 1146 for (i = idx_asn; i < argc; i++)
718e3744 1147 {
afec25d9 1148 VTY_GET_INTEGER_RANGE ("AS", as, argv[i]->arg, 1, BGP_AS4_MAX);
718e3744 1149
1150 if (bgp->as == as)
1151 {
1152 vty_out (vty, "%% Local member-AS not allowed in confed peer list%s",
1153 VTY_NEWLINE);
1154 continue;
1155 }
1156
1157 bgp_confederation_peers_add (bgp, as);
1158 }
1159 return CMD_SUCCESS;
1160}
1161
1162DEFUN (no_bgp_confederation_peers,
1163 no_bgp_confederation_peers_cmd,
e83a9414 1164 "no bgp confederation peers (1-4294967295)...",
718e3744 1165 NO_STR
1166 "BGP specific commands\n"
1167 "AS confederation parameters\n"
1168 "Peer ASs in BGP confederation\n"
1169 AS_STR)
1170{
cdc2d765 1171 VTY_DECLVAR_CONTEXT(bgp, bgp);
58749582 1172 int idx_asn = 4;
718e3744 1173 as_t as;
1174 int i;
1175
58749582 1176 for (i = idx_asn; i < argc; i++)
718e3744 1177 {
afec25d9 1178 VTY_GET_INTEGER_RANGE ("AS", as, argv[i]->arg, 1, BGP_AS4_MAX);
0b2aa3a0 1179
718e3744 1180 bgp_confederation_peers_remove (bgp, as);
1181 }
1182 return CMD_SUCCESS;
1183}
6b0655a2 1184
5e242b0d
DS
1185/**
1186 * Central routine for maximum-paths configuration.
1187 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1188 * @set: 1 for setting values, 0 for removing the max-paths config.
1189 */
ffd0c037
DS
1190static int
1191bgp_maxpaths_config_vty (struct vty *vty, int peer_type, const char *mpaths,
5e242b0d 1192 u_int16_t options, int set)
165b5fff 1193{
cdc2d765 1194 VTY_DECLVAR_CONTEXT(bgp, bgp);
4c9dee98 1195 u_int16_t maxpaths = 0;
165b5fff 1196 int ret;
5e242b0d
DS
1197 afi_t afi;
1198 safi_t safi;
165b5fff 1199
5e242b0d
DS
1200 afi = bgp_node_afi (vty);
1201 safi = bgp_node_safi (vty);
165b5fff 1202
5e242b0d 1203 if (set)
4c9dee98 1204 {
c59f2066 1205 maxpaths = strtol(mpaths, NULL, 10);
37fe7731
DS
1206 if (maxpaths > multipath_num)
1207 {
1208 vty_out (vty,
1209 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1210 maxpaths, multipath_num);
1211 return CMD_WARNING;
1212 }
dff6764a 1213 ret = bgp_maximum_paths_set (bgp, afi, safi, peer_type, maxpaths, options);
4c9dee98 1214 }
5e242b0d
DS
1215 else
1216 ret = bgp_maximum_paths_unset (bgp, afi, safi, peer_type);
165b5fff 1217
165b5fff
JB
1218 if (ret < 0)
1219 {
1220 vty_out (vty,
5e242b0d
DS
1221 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u%s",
1222 (set == 1) ? "" : "un",
1223 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1224 maxpaths, afi, safi, VTY_NEWLINE);
165b5fff
JB
1225 return CMD_WARNING;
1226 }
1227
7aafcaca
DS
1228 bgp_recalculate_all_bestpaths (bgp);
1229
165b5fff
JB
1230 return CMD_SUCCESS;
1231}
1232
abc920f8
DS
1233DEFUN (bgp_maxmed_admin,
1234 bgp_maxmed_admin_cmd,
1235 "bgp max-med administrative ",
1236 BGP_STR
1237 "Advertise routes with max-med\n"
1238 "Administratively applied, for an indefinite period\n")
1239{
cdc2d765 1240 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8
DS
1241
1242 bgp->v_maxmed_admin = 1;
1243 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1244
1245 bgp_maxmed_update(bgp);
1246
1247 return CMD_SUCCESS;
1248}
1249
1250DEFUN (bgp_maxmed_admin_medv,
1251 bgp_maxmed_admin_medv_cmd,
6147e2c6 1252 "bgp max-med administrative (0-4294967294)",
abc920f8
DS
1253 BGP_STR
1254 "Advertise routes with max-med\n"
1255 "Administratively applied, for an indefinite period\n"
1256 "Max MED value to be used\n")
1257{
cdc2d765 1258 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 1259 int idx_number = 3;
abc920f8
DS
1260
1261 bgp->v_maxmed_admin = 1;
c500ae40 1262 VTY_GET_INTEGER ("max-med admin med-value", bgp->maxmed_admin_value, argv[idx_number]->arg);
abc920f8
DS
1263
1264 bgp_maxmed_update(bgp);
1265
1266 return CMD_SUCCESS;
1267}
1268
1269DEFUN (no_bgp_maxmed_admin,
1270 no_bgp_maxmed_admin_cmd,
8334fd5a 1271 "no bgp max-med administrative [(0-4294967294)]",
abc920f8
DS
1272 NO_STR
1273 BGP_STR
1274 "Advertise routes with max-med\n"
838758ac
DW
1275 "Administratively applied, for an indefinite period\n"
1276 "Max MED value to be used\n")
abc920f8 1277{
cdc2d765 1278 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8
DS
1279 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1280 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8
DS
1281 bgp_maxmed_update(bgp);
1282
1283 return CMD_SUCCESS;
1284}
1285
abc920f8
DS
1286DEFUN (bgp_maxmed_onstartup,
1287 bgp_maxmed_onstartup_cmd,
6147e2c6 1288 "bgp max-med on-startup (5-86400)",
abc920f8
DS
1289 BGP_STR
1290 "Advertise routes with max-med\n"
1291 "Effective on a startup\n"
1292 "Time (seconds) period for max-med\n")
1293{
cdc2d765 1294 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 1295 int idx_number = 3;
c500ae40 1296 VTY_GET_INTEGER ("max-med on-startup period", bgp->v_maxmed_onstartup, argv[idx_number]->arg);
abc920f8 1297 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8
DS
1298 bgp_maxmed_update(bgp);
1299
1300 return CMD_SUCCESS;
1301}
1302
1303DEFUN (bgp_maxmed_onstartup_medv,
1304 bgp_maxmed_onstartup_medv_cmd,
6147e2c6 1305 "bgp max-med on-startup (5-86400) (0-4294967294)",
abc920f8
DS
1306 BGP_STR
1307 "Advertise routes with max-med\n"
1308 "Effective on a startup\n"
1309 "Time (seconds) period for max-med\n"
1310 "Max MED value to be used\n")
1311{
cdc2d765 1312 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
1313 int idx_number = 3;
1314 int idx_number_2 = 4;
c500ae40
DW
1315 VTY_GET_INTEGER ("max-med on-startup period", bgp->v_maxmed_onstartup, argv[idx_number]->arg);
1316 VTY_GET_INTEGER ("max-med on-startup med-value", bgp->maxmed_onstartup_value, argv[idx_number_2]->arg);
abc920f8
DS
1317 bgp_maxmed_update(bgp);
1318
1319 return CMD_SUCCESS;
1320}
1321
1322DEFUN (no_bgp_maxmed_onstartup,
1323 no_bgp_maxmed_onstartup_cmd,
8334fd5a 1324 "no bgp max-med on-startup [(5-86400) [(0-4294967294)]]",
abc920f8
DS
1325 NO_STR
1326 BGP_STR
1327 "Advertise routes with max-med\n"
838758ac
DW
1328 "Effective on a startup\n"
1329 "Time (seconds) period for max-med\n"
1330 "Max MED value to be used\n")
abc920f8 1331{
cdc2d765 1332 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8
DS
1333
1334 /* Cancel max-med onstartup if its on */
1335 if (bgp->t_maxmed_onstartup)
1336 {
1337 THREAD_TIMER_OFF (bgp->t_maxmed_onstartup);
1338 bgp->maxmed_onstartup_over = 1;
1339 }
1340
1341 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1342 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
1343
1344 bgp_maxmed_update(bgp);
1345
1346 return CMD_SUCCESS;
1347}
1348
f188f2c4
DS
1349static int
1350bgp_update_delay_config_vty (struct vty *vty, const char *delay,
1351 const char *wait)
1352{
cdc2d765 1353 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4
DS
1354 u_int16_t update_delay;
1355 u_int16_t establish_wait;
1356
f188f2c4
DS
1357 VTY_GET_INTEGER_RANGE ("update-delay", update_delay, delay,
1358 BGP_UPDATE_DELAY_MIN, BGP_UPDATE_DELAY_MAX);
1359
1360 if (!wait) /* update-delay <delay> */
1361 {
1362 bgp->v_update_delay = update_delay;
1363 bgp->v_establish_wait = bgp->v_update_delay;
1364 return CMD_SUCCESS;
1365 }
1366
1367 /* update-delay <delay> <establish-wait> */
1368 establish_wait = atoi (wait);
1369 if (update_delay < establish_wait)
1370 {
1371 vty_out (vty, "%%Failed: update-delay less than the establish-wait!%s",
1372 VTY_NEWLINE);
1373 return CMD_WARNING;
1374 }
1375
1376 bgp->v_update_delay = update_delay;
1377 bgp->v_establish_wait = establish_wait;
1378
1379 return CMD_SUCCESS;
1380}
1381
1382static int
1383bgp_update_delay_deconfig_vty (struct vty *vty)
1384{
cdc2d765 1385 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4
DS
1386
1387 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1388 bgp->v_establish_wait = bgp->v_update_delay;
1389
1390 return CMD_SUCCESS;
1391}
1392
1393int
1394bgp_config_write_update_delay (struct vty *vty, struct bgp *bgp)
1395{
1396 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF)
1397 {
1398 vty_out (vty, " update-delay %d", bgp->v_update_delay);
1399 if (bgp->v_update_delay != bgp->v_establish_wait)
1400 vty_out (vty, " %d", bgp->v_establish_wait);
1401 vty_out (vty, "%s", VTY_NEWLINE);
1402 }
1403
1404 return 0;
1405}
1406
1407
1408/* Update-delay configuration */
1409DEFUN (bgp_update_delay,
1410 bgp_update_delay_cmd,
6147e2c6 1411 "update-delay (0-3600)",
f188f2c4
DS
1412 "Force initial delay for best-path and updates\n"
1413 "Seconds\n")
1414{
c500ae40
DW
1415 int idx_number = 1;
1416 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1417}
1418
1419DEFUN (bgp_update_delay_establish_wait,
1420 bgp_update_delay_establish_wait_cmd,
6147e2c6 1421 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1422 "Force initial delay for best-path and updates\n"
1423 "Seconds\n"
1424 "Wait for peers to be established\n"
1425 "Seconds\n")
1426{
c500ae40
DW
1427 int idx_number = 1;
1428 int idx_number_2 = 2;
1429 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, argv[idx_number_2]->arg);
f188f2c4
DS
1430}
1431
1432/* Update-delay deconfiguration */
1433DEFUN (no_bgp_update_delay,
1434 no_bgp_update_delay_cmd,
838758ac
DW
1435 "no update-delay [(0-3600) [(1-3600)]]",
1436 NO_STR
f188f2c4 1437 "Force initial delay for best-path and updates\n"
838758ac
DW
1438 "Seconds\n"
1439 "Wait for peers to be established\n")
f188f2c4
DS
1440{
1441 return bgp_update_delay_deconfig_vty(vty);
1442}
1443
5e242b0d 1444
ffd0c037
DS
1445static int
1446bgp_wpkt_quanta_config_vty (struct vty *vty, const char *num, char set)
cb1faec9 1447{
cdc2d765 1448 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9
DS
1449
1450 if (set)
1451 VTY_GET_INTEGER_RANGE ("write-quanta", bgp->wpkt_quanta, num,
4543bbb4 1452 1, 10000);
cb1faec9
DS
1453 else
1454 bgp->wpkt_quanta = BGP_WRITE_PACKET_MAX;
1455
1456 return CMD_SUCCESS;
1457}
1458
1459int
1460bgp_config_write_wpkt_quanta (struct vty *vty, struct bgp *bgp)
1461{
1462 if (bgp->wpkt_quanta != BGP_WRITE_PACKET_MAX)
1463 vty_out (vty, " write-quanta %d%s",
1464 bgp->wpkt_quanta, VTY_NEWLINE);
1465
1466 return 0;
1467}
1468
1469
1470/* Update-delay configuration */
1471DEFUN (bgp_wpkt_quanta,
1472 bgp_wpkt_quanta_cmd,
6147e2c6 1473 "write-quanta (1-10000)",
cb1faec9
DS
1474 "How many packets to write to peer socket per run\n"
1475 "Number of packets\n")
1476{
c500ae40
DW
1477 int idx_number = 1;
1478 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1479}
1480
1481/* Update-delay deconfiguration */
1482DEFUN (no_bgp_wpkt_quanta,
1483 no_bgp_wpkt_quanta_cmd,
6147e2c6 1484 "no write-quanta (1-10000)",
d7fa34c1 1485 NO_STR
cb1faec9
DS
1486 "How many packets to write to peer socket per run\n"
1487 "Number of packets\n")
1488{
c500ae40
DW
1489 int idx_number = 2;
1490 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1491}
1492
ffd0c037 1493static int
3f9c7369
DS
1494bgp_coalesce_config_vty (struct vty *vty, const char *num, char set)
1495{
cdc2d765 1496 VTY_DECLVAR_CONTEXT(bgp, bgp);
3f9c7369
DS
1497
1498 if (set)
1499 VTY_GET_INTEGER_RANGE ("coalesce-time", bgp->coalesce_time, num,
1500 0, 4294967295);
1501 else
1502 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1503
1504 return CMD_SUCCESS;
1505}
1506
1507int
1508bgp_config_write_coalesce_time (struct vty *vty, struct bgp *bgp)
1509{
1510 if (bgp->coalesce_time != BGP_DEFAULT_SUBGROUP_COALESCE_TIME)
1511 vty_out (vty, " coalesce-time %d%s",
1512 bgp->coalesce_time, VTY_NEWLINE);
1513
1514 return 0;
1515}
1516
1517
1518DEFUN (bgp_coalesce_time,
1519 bgp_coalesce_time_cmd,
6147e2c6 1520 "coalesce-time (0-4294967295)",
3f9c7369
DS
1521 "Subgroup coalesce timer\n"
1522 "Subgroup coalesce timer value (in ms)\n")
1523{
c500ae40
DW
1524 int idx_number = 1;
1525 return bgp_coalesce_config_vty(vty, argv[idx_number]->arg, 1);
3f9c7369
DS
1526}
1527
1528DEFUN (no_bgp_coalesce_time,
1529 no_bgp_coalesce_time_cmd,
6147e2c6 1530 "no coalesce-time (0-4294967295)",
3a2d747c 1531 NO_STR
3f9c7369
DS
1532 "Subgroup coalesce timer\n"
1533 "Subgroup coalesce timer value (in ms)\n")
1534{
c500ae40
DW
1535 int idx_number = 2;
1536 return bgp_coalesce_config_vty(vty, argv[idx_number]->arg, 0);
3f9c7369
DS
1537}
1538
5e242b0d
DS
1539/* Maximum-paths configuration */
1540DEFUN (bgp_maxpaths,
1541 bgp_maxpaths_cmd,
9ccf14f7 1542 "maximum-paths (1-255)",
5e242b0d
DS
1543 "Forward packets over multiple paths\n"
1544 "Number of paths\n")
1545{
c500ae40
DW
1546 int idx_number = 1;
1547 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1548}
1549
596c17ba
DW
1550ALIAS_HIDDEN (bgp_maxpaths,
1551 bgp_maxpaths_hidden_cmd,
1552 "maximum-paths (1-255)",
1553 "Forward packets over multiple paths\n"
1554 "Number of paths\n")
1555
165b5fff
JB
1556DEFUN (bgp_maxpaths_ibgp,
1557 bgp_maxpaths_ibgp_cmd,
9ccf14f7 1558 "maximum-paths ibgp (1-255)",
165b5fff
JB
1559 "Forward packets over multiple paths\n"
1560 "iBGP-multipath\n"
1561 "Number of paths\n")
1562{
c500ae40
DW
1563 int idx_number = 2;
1564 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, argv[idx_number]->arg, 0, 1);
5e242b0d 1565}
165b5fff 1566
596c17ba
DW
1567ALIAS_HIDDEN (bgp_maxpaths_ibgp,
1568 bgp_maxpaths_ibgp_hidden_cmd,
1569 "maximum-paths ibgp (1-255)",
1570 "Forward packets over multiple paths\n"
1571 "iBGP-multipath\n"
1572 "Number of paths\n")
1573
5e242b0d
DS
1574DEFUN (bgp_maxpaths_ibgp_cluster,
1575 bgp_maxpaths_ibgp_cluster_cmd,
9ccf14f7 1576 "maximum-paths ibgp (1-255) equal-cluster-length",
5e242b0d
DS
1577 "Forward packets over multiple paths\n"
1578 "iBGP-multipath\n"
1579 "Number of paths\n"
1580 "Match the cluster length\n")
1581{
c500ae40
DW
1582 int idx_number = 2;
1583 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, argv[idx_number]->arg,
5e242b0d 1584 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1585}
1586
596c17ba
DW
1587ALIAS_HIDDEN (bgp_maxpaths_ibgp_cluster,
1588 bgp_maxpaths_ibgp_cluster_hidden_cmd,
1589 "maximum-paths ibgp (1-255) equal-cluster-length",
1590 "Forward packets over multiple paths\n"
1591 "iBGP-multipath\n"
1592 "Number of paths\n"
1593 "Match the cluster length\n")
1594
165b5fff
JB
1595DEFUN (no_bgp_maxpaths,
1596 no_bgp_maxpaths_cmd,
9ccf14f7 1597 "no maximum-paths [(1-255)]",
165b5fff
JB
1598 NO_STR
1599 "Forward packets over multiple paths\n"
1600 "Number of paths\n")
1601{
5e242b0d 1602 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1603}
1604
596c17ba
DW
1605ALIAS_HIDDEN (no_bgp_maxpaths,
1606 no_bgp_maxpaths_hidden_cmd,
1607 "no maximum-paths [(1-255)]",
1608 NO_STR
1609 "Forward packets over multiple paths\n"
1610 "Number of paths\n")
1611
165b5fff
JB
1612DEFUN (no_bgp_maxpaths_ibgp,
1613 no_bgp_maxpaths_ibgp_cmd,
9ccf14f7 1614 "no maximum-paths ibgp [(1-255) [equal-cluster-length]]",
165b5fff
JB
1615 NO_STR
1616 "Forward packets over multiple paths\n"
1617 "iBGP-multipath\n"
838758ac
DW
1618 "Number of paths\n"
1619 "Match the cluster length\n")
165b5fff 1620{
5e242b0d 1621 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1622}
1623
596c17ba
DW
1624ALIAS_HIDDEN (no_bgp_maxpaths_ibgp,
1625 no_bgp_maxpaths_ibgp_hidden_cmd,
1626 "no maximum-paths ibgp [(1-255) [equal-cluster-length]]",
1627 NO_STR
1628 "Forward packets over multiple paths\n"
1629 "iBGP-multipath\n"
1630 "Number of paths\n"
1631 "Match the cluster length\n")
1632
165b5fff
JB
1633int
1634bgp_config_write_maxpaths (struct vty *vty, struct bgp *bgp, afi_t afi,
1635 safi_t safi, int *write)
1636{
d5b77cc2 1637 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM)
165b5fff
JB
1638 {
1639 bgp_config_write_family_header (vty, afi, safi, write);
0b960b4d 1640 vty_out (vty, " maximum-paths %d%s",
165b5fff
JB
1641 bgp->maxpaths[afi][safi].maxpaths_ebgp, VTY_NEWLINE);
1642 }
1643
d5b77cc2 1644 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM)
165b5fff
JB
1645 {
1646 bgp_config_write_family_header (vty, afi, safi, write);
0b960b4d 1647 vty_out (vty, " maximum-paths ibgp %d",
5e242b0d
DS
1648 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1649 if (CHECK_FLAG (bgp->maxpaths[afi][safi].ibgp_flags,
1650 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1651 vty_out (vty, " equal-cluster-length");
1652 vty_out (vty, "%s", VTY_NEWLINE);
165b5fff
JB
1653 }
1654
1655 return 0;
1656}
6b0655a2 1657
718e3744 1658/* BGP timers. */
1659
1660DEFUN (bgp_timers,
1661 bgp_timers_cmd,
6147e2c6 1662 "timers bgp (0-65535) (0-65535)",
718e3744 1663 "Adjust routing timers\n"
1664 "BGP timers\n"
1665 "Keepalive interval\n"
1666 "Holdtime\n")
1667{
cdc2d765 1668 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
1669 int idx_number = 2;
1670 int idx_number_2 = 3;
718e3744 1671 unsigned long keepalive = 0;
1672 unsigned long holdtime = 0;
1673
c500ae40
DW
1674 VTY_GET_INTEGER ("keepalive", keepalive, argv[idx_number]->arg);
1675 VTY_GET_INTEGER ("holdtime", holdtime, argv[idx_number_2]->arg);
718e3744 1676
1677 /* Holdtime value check. */
1678 if (holdtime < 3 && holdtime != 0)
1679 {
1680 vty_out (vty, "%% hold time value must be either 0 or greater than 3%s",
1681 VTY_NEWLINE);
1682 return CMD_WARNING;
1683 }
1684
1685 bgp_timers_set (bgp, keepalive, holdtime);
1686
1687 return CMD_SUCCESS;
1688}
1689
1690DEFUN (no_bgp_timers,
1691 no_bgp_timers_cmd,
838758ac 1692 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1693 NO_STR
1694 "Adjust routing timers\n"
838758ac
DW
1695 "BGP timers\n"
1696 "Keepalive interval\n"
1697 "Holdtime\n")
718e3744 1698{
cdc2d765 1699 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1700 bgp_timers_unset (bgp);
1701
1702 return CMD_SUCCESS;
1703}
1704
6b0655a2 1705
718e3744 1706DEFUN (bgp_client_to_client_reflection,
1707 bgp_client_to_client_reflection_cmd,
1708 "bgp client-to-client reflection",
1709 "BGP specific commands\n"
1710 "Configure client to client route reflection\n"
1711 "reflection of routes allowed\n")
1712{
cdc2d765 1713 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1714 bgp_flag_unset (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
f31fa004 1715 bgp_clear_star_soft_out (vty, bgp->name);
7aafcaca 1716
718e3744 1717 return CMD_SUCCESS;
1718}
1719
1720DEFUN (no_bgp_client_to_client_reflection,
1721 no_bgp_client_to_client_reflection_cmd,
1722 "no bgp client-to-client reflection",
1723 NO_STR
1724 "BGP specific commands\n"
1725 "Configure client to client route reflection\n"
1726 "reflection of routes allowed\n")
1727{
cdc2d765 1728 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1729 bgp_flag_set (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
f31fa004 1730 bgp_clear_star_soft_out (vty, bgp->name);
7aafcaca 1731
718e3744 1732 return CMD_SUCCESS;
1733}
1734
1735/* "bgp always-compare-med" configuration. */
1736DEFUN (bgp_always_compare_med,
1737 bgp_always_compare_med_cmd,
1738 "bgp always-compare-med",
1739 "BGP specific commands\n"
1740 "Allow comparing MED from different neighbors\n")
1741{
cdc2d765 1742 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1743 bgp_flag_set (bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
7aafcaca
DS
1744 bgp_recalculate_all_bestpaths (bgp);
1745
718e3744 1746 return CMD_SUCCESS;
1747}
1748
1749DEFUN (no_bgp_always_compare_med,
1750 no_bgp_always_compare_med_cmd,
1751 "no bgp always-compare-med",
1752 NO_STR
1753 "BGP specific commands\n"
1754 "Allow comparing MED from different neighbors\n")
1755{
cdc2d765 1756 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1757 bgp_flag_unset (bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
7aafcaca
DS
1758 bgp_recalculate_all_bestpaths (bgp);
1759
718e3744 1760 return CMD_SUCCESS;
1761}
6b0655a2 1762
718e3744 1763/* "bgp deterministic-med" configuration. */
1764DEFUN (bgp_deterministic_med,
1765 bgp_deterministic_med_cmd,
1766 "bgp deterministic-med",
1767 "BGP specific commands\n"
1768 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1769{
cdc2d765 1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87
DW
1771
1772 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED))
1773 {
1774 bgp_flag_set (bgp, BGP_FLAG_DETERMINISTIC_MED);
1775 bgp_recalculate_all_bestpaths (bgp);
1776 }
7aafcaca 1777
718e3744 1778 return CMD_SUCCESS;
1779}
1780
1781DEFUN (no_bgp_deterministic_med,
1782 no_bgp_deterministic_med_cmd,
1783 "no bgp deterministic-med",
1784 NO_STR
1785 "BGP specific commands\n"
1786 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1787{
cdc2d765 1788 VTY_DECLVAR_CONTEXT(bgp, bgp);
06370dac
DW
1789 int bestpath_per_as_used;
1790 afi_t afi;
1791 safi_t safi;
1792 struct peer *peer;
1793 struct listnode *node, *nnode;
718e3744 1794
1475ac87
DW
1795 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED))
1796 {
06370dac
DW
1797 bestpath_per_as_used = 0;
1798
1799 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1800 {
1801 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1802 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1803 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
1804 {
1805 bestpath_per_as_used = 1;
1806 break;
1807 }
1808
1809 if (bestpath_per_as_used)
1810 break;
1811 }
1812
1813 if (bestpath_per_as_used)
1814 {
1815 vty_out (vty, "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use%s",
1816 VTY_NEWLINE);
1817 return CMD_WARNING;
1818 }
1819 else
1820 {
1821 bgp_flag_unset (bgp, BGP_FLAG_DETERMINISTIC_MED);
1822 bgp_recalculate_all_bestpaths (bgp);
1823 }
1475ac87 1824 }
7aafcaca 1825
718e3744 1826 return CMD_SUCCESS;
1827}
538621f2 1828
1829/* "bgp graceful-restart" configuration. */
1830DEFUN (bgp_graceful_restart,
1831 bgp_graceful_restart_cmd,
1832 "bgp graceful-restart",
1833 "BGP specific commands\n"
1834 "Graceful restart capability parameters\n")
1835{
cdc2d765 1836 VTY_DECLVAR_CONTEXT(bgp, bgp);
538621f2 1837 bgp_flag_set (bgp, BGP_FLAG_GRACEFUL_RESTART);
1838 return CMD_SUCCESS;
1839}
1840
1841DEFUN (no_bgp_graceful_restart,
1842 no_bgp_graceful_restart_cmd,
1843 "no bgp graceful-restart",
1844 NO_STR
1845 "BGP specific commands\n"
1846 "Graceful restart capability parameters\n")
1847{
cdc2d765 1848 VTY_DECLVAR_CONTEXT(bgp, bgp);
538621f2 1849 bgp_flag_unset (bgp, BGP_FLAG_GRACEFUL_RESTART);
1850 return CMD_SUCCESS;
1851}
1852
93406d87 1853DEFUN (bgp_graceful_restart_stalepath_time,
1854 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1855 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1856 "BGP specific commands\n"
1857 "Graceful restart capability parameters\n"
1858 "Set the max time to hold onto restarting peer's stale paths\n"
1859 "Delay value (seconds)\n")
1860{
cdc2d765 1861 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 1862 int idx_number = 3;
93406d87 1863 u_int32_t stalepath;
1864
c500ae40 1865 VTY_GET_INTEGER_RANGE ("stalepath-time", stalepath, argv[idx_number]->arg, 1, 3600);
93406d87 1866 bgp->stalepath_time = stalepath;
1867 return CMD_SUCCESS;
1868}
1869
eb6f1b41
PG
1870DEFUN (bgp_graceful_restart_restart_time,
1871 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1872 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1873 "BGP specific commands\n"
1874 "Graceful restart capability parameters\n"
1875 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1876 "Delay value (seconds)\n")
1877{
cdc2d765 1878 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 1879 int idx_number = 3;
eb6f1b41
PG
1880 u_int32_t restart;
1881
c500ae40 1882 VTY_GET_INTEGER_RANGE ("restart-time", restart, argv[idx_number]->arg, 1, 3600);
eb6f1b41
PG
1883 bgp->restart_time = restart;
1884 return CMD_SUCCESS;
1885}
1886
93406d87 1887DEFUN (no_bgp_graceful_restart_stalepath_time,
1888 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1889 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1890 NO_STR
1891 "BGP specific commands\n"
1892 "Graceful restart capability parameters\n"
838758ac
DW
1893 "Set the max time to hold onto restarting peer's stale paths\n"
1894 "Delay value (seconds)\n")
93406d87 1895{
cdc2d765 1896 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1897
1898 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1899 return CMD_SUCCESS;
1900}
1901
eb6f1b41
PG
1902DEFUN (no_bgp_graceful_restart_restart_time,
1903 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1904 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1905 NO_STR
1906 "BGP specific commands\n"
1907 "Graceful restart capability parameters\n"
838758ac
DW
1908 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1909 "Delay value (seconds)\n")
eb6f1b41 1910{
cdc2d765 1911 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41
PG
1912
1913 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1914 return CMD_SUCCESS;
1915}
1916
43fc21b3
JC
1917DEFUN (bgp_graceful_restart_preserve_fw,
1918 bgp_graceful_restart_preserve_fw_cmd,
1919 "bgp graceful-restart preserve-fw-state",
1920 "BGP specific commands\n"
1921 "Graceful restart capability parameters\n"
1922 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1923{
1924 VTY_DECLVAR_CONTEXT(bgp, bgp);
1925 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1926 return CMD_SUCCESS;
1927}
1928
1929DEFUN (no_bgp_graceful_restart_preserve_fw,
1930 no_bgp_graceful_restart_preserve_fw_cmd,
1931 "no bgp graceful-restart preserve-fw-state",
1932 NO_STR
1933 "BGP specific commands\n"
1934 "Graceful restart capability parameters\n"
1935 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1936{
1937 VTY_DECLVAR_CONTEXT(bgp, bgp);
1938 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1939 return CMD_SUCCESS;
1940}
1941
718e3744 1942/* "bgp fast-external-failover" configuration. */
1943DEFUN (bgp_fast_external_failover,
1944 bgp_fast_external_failover_cmd,
1945 "bgp fast-external-failover",
1946 BGP_STR
1947 "Immediately reset session if a link to a directly connected external peer goes down\n")
1948{
cdc2d765 1949 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1950 bgp_flag_unset (bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1951 return CMD_SUCCESS;
1952}
1953
1954DEFUN (no_bgp_fast_external_failover,
1955 no_bgp_fast_external_failover_cmd,
1956 "no bgp fast-external-failover",
1957 NO_STR
1958 BGP_STR
1959 "Immediately reset session if a link to a directly connected external peer goes down\n")
1960{
cdc2d765 1961 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1962 bgp_flag_set (bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1963 return CMD_SUCCESS;
1964}
6b0655a2 1965
718e3744 1966/* "bgp enforce-first-as" configuration. */
1967DEFUN (bgp_enforce_first_as,
1968 bgp_enforce_first_as_cmd,
1969 "bgp enforce-first-as",
1970 BGP_STR
1971 "Enforce the first AS for EBGP routes\n")
1972{
cdc2d765 1973 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1974 bgp_flag_set (bgp, BGP_FLAG_ENFORCE_FIRST_AS);
f31fa004 1975 bgp_clear_star_soft_in (vty, bgp->name);
7aafcaca 1976
718e3744 1977 return CMD_SUCCESS;
1978}
1979
1980DEFUN (no_bgp_enforce_first_as,
1981 no_bgp_enforce_first_as_cmd,
1982 "no bgp enforce-first-as",
1983 NO_STR
1984 BGP_STR
1985 "Enforce the first AS for EBGP routes\n")
1986{
cdc2d765 1987 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 1988 bgp_flag_unset (bgp, BGP_FLAG_ENFORCE_FIRST_AS);
f31fa004 1989 bgp_clear_star_soft_in (vty, bgp->name);
7aafcaca 1990
718e3744 1991 return CMD_SUCCESS;
1992}
6b0655a2 1993
718e3744 1994/* "bgp bestpath compare-routerid" configuration. */
1995DEFUN (bgp_bestpath_compare_router_id,
1996 bgp_bestpath_compare_router_id_cmd,
1997 "bgp bestpath compare-routerid",
1998 "BGP specific commands\n"
1999 "Change the default bestpath selection\n"
2000 "Compare router-id for identical EBGP paths\n")
2001{
cdc2d765 2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2003 bgp_flag_set (bgp, BGP_FLAG_COMPARE_ROUTER_ID);
7aafcaca
DS
2004 bgp_recalculate_all_bestpaths (bgp);
2005
718e3744 2006 return CMD_SUCCESS;
2007}
2008
2009DEFUN (no_bgp_bestpath_compare_router_id,
2010 no_bgp_bestpath_compare_router_id_cmd,
2011 "no bgp bestpath compare-routerid",
2012 NO_STR
2013 "BGP specific commands\n"
2014 "Change the default bestpath selection\n"
2015 "Compare router-id for identical EBGP paths\n")
2016{
cdc2d765 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2018 bgp_flag_unset (bgp, BGP_FLAG_COMPARE_ROUTER_ID);
7aafcaca
DS
2019 bgp_recalculate_all_bestpaths (bgp);
2020
718e3744 2021 return CMD_SUCCESS;
2022}
6b0655a2 2023
718e3744 2024/* "bgp bestpath as-path ignore" configuration. */
2025DEFUN (bgp_bestpath_aspath_ignore,
2026 bgp_bestpath_aspath_ignore_cmd,
2027 "bgp bestpath as-path ignore",
2028 "BGP specific commands\n"
2029 "Change the default bestpath selection\n"
2030 "AS-path attribute\n"
2031 "Ignore as-path length in selecting a route\n")
2032{
cdc2d765 2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2034 bgp_flag_set (bgp, BGP_FLAG_ASPATH_IGNORE);
7aafcaca
DS
2035 bgp_recalculate_all_bestpaths (bgp);
2036
718e3744 2037 return CMD_SUCCESS;
2038}
2039
2040DEFUN (no_bgp_bestpath_aspath_ignore,
2041 no_bgp_bestpath_aspath_ignore_cmd,
2042 "no bgp bestpath as-path ignore",
2043 NO_STR
2044 "BGP specific commands\n"
2045 "Change the default bestpath selection\n"
2046 "AS-path attribute\n"
2047 "Ignore as-path length in selecting a route\n")
2048{
cdc2d765 2049 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2050 bgp_flag_unset (bgp, BGP_FLAG_ASPATH_IGNORE);
7aafcaca
DS
2051 bgp_recalculate_all_bestpaths (bgp);
2052
718e3744 2053 return CMD_SUCCESS;
2054}
6b0655a2 2055
6811845b 2056/* "bgp bestpath as-path confed" configuration. */
2057DEFUN (bgp_bestpath_aspath_confed,
2058 bgp_bestpath_aspath_confed_cmd,
2059 "bgp bestpath as-path confed",
2060 "BGP specific commands\n"
2061 "Change the default bestpath selection\n"
2062 "AS-path attribute\n"
2063 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2064{
cdc2d765 2065 VTY_DECLVAR_CONTEXT(bgp, bgp);
6811845b 2066 bgp_flag_set (bgp, BGP_FLAG_ASPATH_CONFED);
7aafcaca
DS
2067 bgp_recalculate_all_bestpaths (bgp);
2068
6811845b 2069 return CMD_SUCCESS;
2070}
2071
2072DEFUN (no_bgp_bestpath_aspath_confed,
2073 no_bgp_bestpath_aspath_confed_cmd,
2074 "no bgp bestpath as-path confed",
2075 NO_STR
2076 "BGP specific commands\n"
2077 "Change the default bestpath selection\n"
2078 "AS-path attribute\n"
2079 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2080{
cdc2d765 2081 VTY_DECLVAR_CONTEXT(bgp, bgp);
6811845b 2082 bgp_flag_unset (bgp, BGP_FLAG_ASPATH_CONFED);
7aafcaca
DS
2083 bgp_recalculate_all_bestpaths (bgp);
2084
6811845b 2085 return CMD_SUCCESS;
2086}
6b0655a2 2087
2fdd455c
PM
2088/* "bgp bestpath as-path multipath-relax" configuration. */
2089DEFUN (bgp_bestpath_aspath_multipath_relax,
2090 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2091 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2092 "BGP specific commands\n"
2093 "Change the default bestpath selection\n"
2094 "AS-path attribute\n"
2095 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2096 "Generate an AS_SET\n"
16fc1eec
DS
2097 "Do not generate an AS_SET\n")
2098{
cdc2d765 2099 VTY_DECLVAR_CONTEXT(bgp, bgp);
4c4ff4c1 2100 int idx = 0;
16fc1eec 2101 bgp_flag_set (bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6
DW
2102
2103 /* no-as-set is now the default behavior so we can silently
2104 * ignore it */
4c4ff4c1 2105 if (argv_find (argv, argc, "as-set", &idx))
219178b6
DW
2106 bgp_flag_set (bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2107 else
2108 bgp_flag_unset (bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET) ;
2109
7aafcaca
DS
2110 bgp_recalculate_all_bestpaths (bgp);
2111
16fc1eec
DS
2112 return CMD_SUCCESS;
2113}
2114
219178b6
DW
2115DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2116 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2117 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2118 NO_STR
2119 "BGP specific commands\n"
2120 "Change the default bestpath selection\n"
2121 "AS-path attribute\n"
2122 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2123 "Generate an AS_SET\n"
16fc1eec
DS
2124 "Do not generate an AS_SET\n")
2125{
cdc2d765 2126 VTY_DECLVAR_CONTEXT(bgp, bgp);
16fc1eec 2127 bgp_flag_unset (bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2128 bgp_flag_unset (bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
7aafcaca
DS
2129 bgp_recalculate_all_bestpaths (bgp);
2130
2fdd455c
PM
2131 return CMD_SUCCESS;
2132}
6b0655a2 2133
848973c7 2134/* "bgp log-neighbor-changes" configuration. */
2135DEFUN (bgp_log_neighbor_changes,
2136 bgp_log_neighbor_changes_cmd,
2137 "bgp log-neighbor-changes",
2138 "BGP specific commands\n"
2139 "Log neighbor up/down and reset reason\n")
2140{
cdc2d765 2141 VTY_DECLVAR_CONTEXT(bgp, bgp);
848973c7 2142 bgp_flag_set (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2143 return CMD_SUCCESS;
2144}
2145
2146DEFUN (no_bgp_log_neighbor_changes,
2147 no_bgp_log_neighbor_changes_cmd,
2148 "no bgp log-neighbor-changes",
2149 NO_STR
2150 "BGP specific commands\n"
2151 "Log neighbor up/down and reset reason\n")
2152{
cdc2d765 2153 VTY_DECLVAR_CONTEXT(bgp, bgp);
848973c7 2154 bgp_flag_unset (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2155 return CMD_SUCCESS;
2156}
6b0655a2 2157
718e3744 2158/* "bgp bestpath med" configuration. */
2159DEFUN (bgp_bestpath_med,
2160 bgp_bestpath_med_cmd,
2d8c1a4d 2161 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2162 "BGP specific commands\n"
2163 "Change the default bestpath selection\n"
2164 "MED attribute\n"
2165 "Compare MED among confederation paths\n"
838758ac
DW
2166 "Treat missing MED as the least preferred one\n"
2167 "Treat missing MED as the least preferred one\n"
2168 "Compare MED among confederation paths\n")
718e3744 2169{
cdc2d765 2170 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915
QY
2171
2172 int idx = 0;
2173 if (argv_find (argv, argc, "confed", &idx))
2174 bgp_flag_set (bgp, BGP_FLAG_MED_CONFED);
2175 idx = 0;
2176 if (argv_find (argv, argc, "missing-as-worst", &idx))
2177 bgp_flag_set (bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2178
7aafcaca
DS
2179 bgp_recalculate_all_bestpaths (bgp);
2180
718e3744 2181 return CMD_SUCCESS;
2182}
2183
718e3744 2184DEFUN (no_bgp_bestpath_med,
2185 no_bgp_bestpath_med_cmd,
2d8c1a4d 2186 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2187 NO_STR
2188 "BGP specific commands\n"
2189 "Change the default bestpath selection\n"
2190 "MED attribute\n"
2191 "Compare MED among confederation paths\n"
3a2d747c
QY
2192 "Treat missing MED as the least preferred one\n"
2193 "Treat missing MED as the least preferred one\n"
2194 "Compare MED among confederation paths\n")
718e3744 2195{
cdc2d765 2196 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2197
6cbd1915
QY
2198 int idx = 0;
2199 if (argv_find (argv, argc, "confed", &idx))
718e3744 2200 bgp_flag_unset (bgp, BGP_FLAG_MED_CONFED);
6cbd1915
QY
2201 idx = 0;
2202 if (argv_find (argv, argc, "missing-as-worst", &idx))
718e3744 2203 bgp_flag_unset (bgp, BGP_FLAG_MED_MISSING_AS_WORST);
2204
7aafcaca
DS
2205 bgp_recalculate_all_bestpaths (bgp);
2206
718e3744 2207 return CMD_SUCCESS;
2208}
2209
718e3744 2210/* "no bgp default ipv4-unicast". */
2211DEFUN (no_bgp_default_ipv4_unicast,
2212 no_bgp_default_ipv4_unicast_cmd,
2213 "no bgp default ipv4-unicast",
2214 NO_STR
2215 "BGP specific commands\n"
2216 "Configure BGP defaults\n"
2217 "Activate ipv4-unicast for a peer by default\n")
2218{
cdc2d765 2219 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2220 bgp_flag_set (bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2221 return CMD_SUCCESS;
2222}
2223
2224DEFUN (bgp_default_ipv4_unicast,
2225 bgp_default_ipv4_unicast_cmd,
2226 "bgp default ipv4-unicast",
2227 "BGP specific commands\n"
2228 "Configure BGP defaults\n"
2229 "Activate ipv4-unicast for a peer by default\n")
2230{
cdc2d765 2231 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2232 bgp_flag_unset (bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2233 return CMD_SUCCESS;
2234}
6b0655a2 2235
04b6bdc0
DW
2236/* Display hostname in certain command outputs */
2237DEFUN (bgp_default_show_hostname,
2238 bgp_default_show_hostname_cmd,
2239 "bgp default show-hostname",
2240 "BGP specific commands\n"
2241 "Configure BGP defaults\n"
2242 "Show hostname in certain command ouputs\n")
2243{
cdc2d765 2244 VTY_DECLVAR_CONTEXT(bgp, bgp);
04b6bdc0
DW
2245 bgp_flag_set (bgp, BGP_FLAG_SHOW_HOSTNAME);
2246 return CMD_SUCCESS;
2247}
2248
2249DEFUN (no_bgp_default_show_hostname,
2250 no_bgp_default_show_hostname_cmd,
2251 "no bgp default show-hostname",
2252 NO_STR
2253 "BGP specific commands\n"
2254 "Configure BGP defaults\n"
2255 "Show hostname in certain command ouputs\n")
2256{
cdc2d765 2257 VTY_DECLVAR_CONTEXT(bgp, bgp);
04b6bdc0
DW
2258 bgp_flag_unset (bgp, BGP_FLAG_SHOW_HOSTNAME);
2259 return CMD_SUCCESS;
2260}
2261
8233ef81 2262/* "bgp network import-check" configuration. */
718e3744 2263DEFUN (bgp_network_import_check,
2264 bgp_network_import_check_cmd,
5623e905 2265 "bgp network import-check",
718e3744 2266 "BGP specific commands\n"
2267 "BGP network command\n"
5623e905 2268 "Check BGP network route exists in IGP\n")
718e3744 2269{
cdc2d765 2270 VTY_DECLVAR_CONTEXT(bgp, bgp);
078430f6
DS
2271 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK))
2272 {
2273 bgp_flag_set (bgp, BGP_FLAG_IMPORT_CHECK);
5623e905 2274 bgp_static_redo_import_check(bgp);
078430f6
DS
2275 }
2276
718e3744 2277 return CMD_SUCCESS;
2278}
2279
8233ef81
DW
2280ALIAS_HIDDEN (bgp_network_import_check,
2281 bgp_network_import_check_exact_cmd,
2282 "bgp network import-check exact",
2283 "BGP specific commands\n"
2284 "BGP network command\n"
2285 "Check BGP network route exists in IGP\n"
2286 "Match route precisely\n")
2287
718e3744 2288DEFUN (no_bgp_network_import_check,
2289 no_bgp_network_import_check_cmd,
5623e905 2290 "no bgp network import-check",
718e3744 2291 NO_STR
2292 "BGP specific commands\n"
2293 "BGP network command\n"
2294 "Check BGP network route exists in IGP\n")
2295{
cdc2d765 2296 VTY_DECLVAR_CONTEXT(bgp, bgp);
078430f6
DS
2297 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK))
2298 {
2299 bgp_flag_unset (bgp, BGP_FLAG_IMPORT_CHECK);
078430f6
DS
2300 bgp_static_redo_import_check(bgp);
2301 }
5623e905 2302
718e3744 2303 return CMD_SUCCESS;
2304}
6b0655a2 2305
718e3744 2306DEFUN (bgp_default_local_preference,
2307 bgp_default_local_preference_cmd,
6147e2c6 2308 "bgp default local-preference (0-4294967295)",
718e3744 2309 "BGP specific commands\n"
2310 "Configure BGP defaults\n"
2311 "local preference (higher=more preferred)\n"
2312 "Configure default local preference value\n")
2313{
cdc2d765 2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 2315 int idx_number = 3;
718e3744 2316 u_int32_t local_pref;
2317
c500ae40 2318 VTY_GET_INTEGER ("local preference", local_pref, argv[idx_number]->arg);
718e3744 2319
2320 bgp_default_local_preference_set (bgp, local_pref);
f31fa004 2321 bgp_clear_star_soft_in (vty, bgp->name);
718e3744 2322
2323 return CMD_SUCCESS;
2324}
2325
2326DEFUN (no_bgp_default_local_preference,
2327 no_bgp_default_local_preference_cmd,
838758ac 2328 "no bgp default local-preference [(0-4294967295)]",
718e3744 2329 NO_STR
2330 "BGP specific commands\n"
2331 "Configure BGP defaults\n"
838758ac
DW
2332 "local preference (higher=more preferred)\n"
2333 "Configure default local preference value\n")
718e3744 2334{
cdc2d765 2335 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2336 bgp_default_local_preference_unset (bgp);
f31fa004 2337 bgp_clear_star_soft_in (vty, bgp->name);
7aafcaca 2338
718e3744 2339 return CMD_SUCCESS;
2340}
2341
6b0655a2 2342
3f9c7369
DS
2343DEFUN (bgp_default_subgroup_pkt_queue_max,
2344 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2345 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2346 "BGP specific commands\n"
2347 "Configure BGP defaults\n"
2348 "subgroup-pkt-queue-max\n"
2349 "Configure subgroup packet queue max\n")
8bd9d948 2350{
cdc2d765 2351 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 2352 int idx_number = 3;
3f9c7369 2353 u_int32_t max_size;
8bd9d948 2354
c500ae40 2355 VTY_GET_INTEGER ("subgroup packet queue max", max_size, argv[idx_number]->arg);
3f9c7369
DS
2356
2357 bgp_default_subgroup_pkt_queue_max_set (bgp, max_size);
2358
2359 return CMD_SUCCESS;
2360}
2361
2362DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2363 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2364 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2365 NO_STR
2366 "BGP specific commands\n"
2367 "Configure BGP defaults\n"
838758ac
DW
2368 "subgroup-pkt-queue-max\n"
2369 "Configure subgroup packet queue max\n")
3f9c7369 2370{
cdc2d765 2371 VTY_DECLVAR_CONTEXT(bgp, bgp);
3f9c7369
DS
2372 bgp_default_subgroup_pkt_queue_max_unset (bgp);
2373 return CMD_SUCCESS;
8bd9d948
DS
2374}
2375
813d4307 2376
8bd9d948
DS
2377DEFUN (bgp_rr_allow_outbound_policy,
2378 bgp_rr_allow_outbound_policy_cmd,
2379 "bgp route-reflector allow-outbound-policy",
2380 "BGP specific commands\n"
2381 "Allow modifications made by out route-map\n"
2382 "on ibgp neighbors\n")
2383{
cdc2d765 2384 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948
DS
2385
2386 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
2387 {
2388 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3f9c7369 2389 update_group_announce_rrclients(bgp);
f31fa004 2390 bgp_clear_star_soft_out (vty, bgp->name);
8bd9d948
DS
2391 }
2392
2393 return CMD_SUCCESS;
2394}
2395
2396DEFUN (no_bgp_rr_allow_outbound_policy,
2397 no_bgp_rr_allow_outbound_policy_cmd,
2398 "no bgp route-reflector allow-outbound-policy",
2399 NO_STR
2400 "BGP specific commands\n"
2401 "Allow modifications made by out route-map\n"
2402 "on ibgp neighbors\n")
2403{
cdc2d765 2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948
DS
2405
2406 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
2407 {
2408 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
3f9c7369 2409 update_group_announce_rrclients(bgp);
f31fa004 2410 bgp_clear_star_soft_out (vty, bgp->name);
8bd9d948
DS
2411 }
2412
2413 return CMD_SUCCESS;
2414}
2415
f14e6fdb
DS
2416DEFUN (bgp_listen_limit,
2417 bgp_listen_limit_cmd,
9ccf14f7 2418 "bgp listen limit (1-5000)",
f14e6fdb
DS
2419 "BGP specific commands\n"
2420 "Configure BGP defaults\n"
2421 "maximum number of BGP Dynamic Neighbors that can be created\n"
2422 "Configure Dynamic Neighbors listen limit value\n")
2423{
cdc2d765 2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 2425 int idx_number = 3;
f14e6fdb
DS
2426 int listen_limit;
2427
c500ae40 2428 VTY_GET_INTEGER_RANGE ("listen limit", listen_limit, argv[idx_number]->arg,
f14e6fdb
DS
2429 BGP_DYNAMIC_NEIGHBORS_LIMIT_MIN,
2430 BGP_DYNAMIC_NEIGHBORS_LIMIT_MAX);
2431
2432 bgp_listen_limit_set (bgp, listen_limit);
2433
2434 return CMD_SUCCESS;
2435}
2436
2437DEFUN (no_bgp_listen_limit,
2438 no_bgp_listen_limit_cmd,
838758ac 2439 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2440 "BGP specific commands\n"
2441 "Configure BGP defaults\n"
2442 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2443 "Configure Dynamic Neighbors listen limit value to default\n"
2444 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2445{
cdc2d765 2446 VTY_DECLVAR_CONTEXT(bgp, bgp);
f14e6fdb
DS
2447 bgp_listen_limit_unset (bgp);
2448 return CMD_SUCCESS;
2449}
2450
2451
20eb8864 2452/*
2453 * Check if this listen range is already configured. Check for exact
2454 * match or overlap based on input.
2455 */
2456static struct peer_group *
2457listen_range_exists (struct bgp *bgp, struct prefix *range, int exact)
2458{
2459 struct listnode *node, *nnode;
2460 struct listnode *node1, *nnode1;
2461 struct peer_group *group;
2462 struct prefix *lr;
2463 afi_t afi;
2464 int match;
2465
2466 afi = family2afi(range->family);
2467 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
2468 {
2469 for (ALL_LIST_ELEMENTS (group->listen_range[afi], node1,
2470 nnode1, lr))
2471 {
2472 if (exact)
2473 match = prefix_same (range, lr);
2474 else
2475 match = (prefix_match (range, lr) || prefix_match (lr, range));
2476 if (match)
2477 return group;
2478 }
2479 }
2480
2481 return NULL;
2482}
2483
f14e6fdb
DS
2484DEFUN (bgp_listen_range,
2485 bgp_listen_range_cmd,
9ccf14f7 2486 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2487 "BGP specific commands\n"
d7fa34c1
QY
2488 "Configure BGP dynamic neighbors listen range\n"
2489 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2490 NEIGHBOR_ADDR_STR
2491 "Member of the peer-group\n"
2492 "Peer-group name\n")
f14e6fdb 2493{
cdc2d765 2494 VTY_DECLVAR_CONTEXT(bgp, bgp);
f14e6fdb 2495 struct prefix range;
20eb8864 2496 struct peer_group *group, *existing_group;
f14e6fdb
DS
2497 afi_t afi;
2498 int ret;
d7fa34c1 2499 int idx = 0;
f14e6fdb 2500
d7fa34c1
QY
2501 argv_find (argv, argc, "A.B.C.D/M", &idx);
2502 argv_find (argv, argc, "X:X::X:X/M", &idx);
2503 char *prefix = argv[idx]->arg;
2504 argv_find (argv, argc, "WORD", &idx);
2505 char *peergroup = argv[idx]->arg;
f14e6fdb 2506
f14e6fdb 2507 /* Convert IP prefix string to struct prefix. */
d7fa34c1 2508 ret = str2prefix (prefix, &range);
f14e6fdb
DS
2509 if (! ret)
2510 {
2511 vty_out (vty, "%% Malformed listen range%s", VTY_NEWLINE);
2512 return CMD_WARNING;
2513 }
2514
2515 afi = family2afi(range.family);
2516
f14e6fdb
DS
2517 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&range.u.prefix6))
2518 {
2519 vty_out (vty, "%% Malformed listen range (link-local address)%s",
2520 VTY_NEWLINE);
2521 return CMD_WARNING;
2522 }
f14e6fdb
DS
2523
2524 apply_mask (&range);
2525
20eb8864 2526 /* Check if same listen range is already configured. */
2527 existing_group = listen_range_exists (bgp, &range, 1);
2528 if (existing_group)
2529 {
d7fa34c1 2530 if (strcmp (existing_group->name, peergroup) == 0)
20eb8864 2531 return CMD_SUCCESS;
2532 else
2533 {
2534 vty_out (vty, "%% Same listen range is attached to peer-group %s%s",
2535 existing_group->name, VTY_NEWLINE);
2536 return CMD_WARNING;
2537 }
2538 }
2539
2540 /* Check if an overlapping listen range exists. */
2541 if (listen_range_exists (bgp, &range, 0))
2542 {
2543 vty_out (vty, "%% Listen range overlaps with existing listen range%s",
2544 VTY_NEWLINE);
2545 return CMD_WARNING;
2546 }
f14e6fdb 2547
d7fa34c1 2548 group = peer_group_lookup (bgp, peergroup);
f14e6fdb
DS
2549 if (! group)
2550 {
2551 vty_out (vty, "%% Configure the peer-group first%s", VTY_NEWLINE);
2552 return CMD_WARNING;
2553 }
2554
2555 ret = peer_group_listen_range_add(group, &range);
2556 return bgp_vty_return (vty, ret);
2557}
2558
2559DEFUN (no_bgp_listen_range,
2560 no_bgp_listen_range_cmd,
d7fa34c1
QY
2561 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2562 NO_STR
f14e6fdb 2563 "BGP specific commands\n"
d7fa34c1
QY
2564 "Unconfigure BGP dynamic neighbors listen range\n"
2565 "Unconfigure BGP dynamic neighbors listen range\n"
2566 NEIGHBOR_ADDR_STR
2567 "Member of the peer-group\n"
2568 "Peer-group name\n")
f14e6fdb 2569{
cdc2d765 2570 VTY_DECLVAR_CONTEXT(bgp, bgp);
f14e6fdb
DS
2571 struct prefix range;
2572 struct peer_group *group;
2573 afi_t afi;
2574 int ret;
d7fa34c1
QY
2575 int idx = 0;
2576
2577 argv_find (argv, argc, "A.B.C.D/M", &idx);
2578 argv_find (argv, argc, "X:X::X:X/M", &idx);
2579 char *prefix = argv[idx]->arg;
2580 argv_find (argv, argc, "WORD", &idx);
2581 char *peergroup = argv[idx]->arg;
f14e6fdb 2582
c500ae40 2583 // VTY_GET_IPV4_PREFIX ("listen range", range, argv[idx_ipv4_prefixlen]->arg);
f14e6fdb
DS
2584
2585 /* Convert IP prefix string to struct prefix. */
d7fa34c1 2586 ret = str2prefix (prefix, &range);
f14e6fdb
DS
2587 if (! ret)
2588 {
2589 vty_out (vty, "%% Malformed listen range%s", VTY_NEWLINE);
2590 return CMD_WARNING;
2591 }
2592
2593 afi = family2afi(range.family);
2594
f14e6fdb
DS
2595 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&range.u.prefix6))
2596 {
2597 vty_out (vty, "%% Malformed listen range (link-local address)%s",
2598 VTY_NEWLINE);
2599 return CMD_WARNING;
2600 }
f14e6fdb
DS
2601
2602 apply_mask (&range);
2603
d7fa34c1 2604 group = peer_group_lookup (bgp, peergroup);
f14e6fdb
DS
2605 if (! group)
2606 {
2607 vty_out (vty, "%% Peer-group does not exist%s", VTY_NEWLINE);
2608 return CMD_WARNING;
2609 }
2610
2611 ret = peer_group_listen_range_del(group, &range);
2612 return bgp_vty_return (vty, ret);
2613}
2614
2615int
2616bgp_config_write_listen (struct vty *vty, struct bgp *bgp)
2617{
2618 struct peer_group *group;
2619 struct listnode *node, *nnode, *rnode, *nrnode;
2620 struct prefix *range;
2621 afi_t afi;
4690c7d7 2622 char buf[PREFIX2STR_BUFFER];
f14e6fdb
DS
2623
2624 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2625 vty_out (vty, " bgp listen limit %d%s",
2626 bgp->dynamic_neighbors_limit, VTY_NEWLINE);
2627
2628 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
2629 {
2630 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2631 {
2632 for (ALL_LIST_ELEMENTS (group->listen_range[afi], rnode, nrnode, range))
2633 {
2634 prefix2str(range, buf, sizeof(buf));
2635 vty_out(vty, " bgp listen range %s peer-group %s%s",
2636 buf, group->name, VTY_NEWLINE);
2637 }
2638 }
2639 }
2640
2641 return 0;
2642}
2643
2644
907f92c8
DS
2645DEFUN (bgp_disable_connected_route_check,
2646 bgp_disable_connected_route_check_cmd,
2647 "bgp disable-ebgp-connected-route-check",
2648 "BGP specific commands\n"
2649 "Disable checking if nexthop is connected on ebgp sessions\n")
2650{
cdc2d765 2651 VTY_DECLVAR_CONTEXT(bgp, bgp);
907f92c8 2652 bgp_flag_set (bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
f31fa004 2653 bgp_clear_star_soft_in (vty, bgp->name);
7aafcaca 2654
907f92c8
DS
2655 return CMD_SUCCESS;
2656}
2657
2658DEFUN (no_bgp_disable_connected_route_check,
2659 no_bgp_disable_connected_route_check_cmd,
2660 "no bgp disable-ebgp-connected-route-check",
2661 NO_STR
2662 "BGP specific commands\n"
2663 "Disable checking if nexthop is connected on ebgp sessions\n")
2664{
cdc2d765 2665 VTY_DECLVAR_CONTEXT(bgp, bgp);
907f92c8 2666 bgp_flag_unset (bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
f31fa004 2667 bgp_clear_star_soft_in (vty, bgp->name);
7aafcaca 2668
907f92c8
DS
2669 return CMD_SUCCESS;
2670}
2671
2672
718e3744 2673static int
e52702f2 2674peer_remote_as_vty (struct vty *vty, const char *peer_str,
fd79ac91 2675 const char *as_str, afi_t afi, safi_t safi)
718e3744 2676{
cdc2d765 2677 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 2678 int ret;
718e3744 2679 as_t as;
0299c004 2680 int as_type = AS_SPECIFIED;
718e3744 2681 union sockunion su;
2682
7ae5fc81 2683 if (as_str[0] == 'i')
0299c004
DS
2684 {
2685 as = 0;
2686 as_type = AS_INTERNAL;
2687 }
7ae5fc81 2688 else if (as_str[0] == 'e')
0299c004
DS
2689 {
2690 as = 0;
2691 as_type = AS_EXTERNAL;
2692 }
2693 else
2694 {
2695 /* Get AS number. */
2696 VTY_GET_INTEGER_RANGE ("AS", as, as_str, 1, BGP_AS4_MAX);
2697 }
718e3744 2698
2699 /* If peer is peer group, call proper function. */
2700 ret = str2sockunion (peer_str, &su);
2701 if (ret < 0)
2702 {
a80beece 2703 /* Check for peer by interface */
0299c004 2704 ret = peer_remote_as (bgp, NULL, peer_str, &as, as_type, afi, safi);
718e3744 2705 if (ret < 0)
a80beece 2706 {
0299c004 2707 ret = peer_group_remote_as (bgp, peer_str, &as, as_type);
a80beece
DS
2708 if (ret < 0)
2709 {
2710 vty_out (vty, "%% Create the peer-group or interface first%s",
2711 VTY_NEWLINE);
2712 return CMD_WARNING;
2713 }
2714 return CMD_SUCCESS;
2715 }
718e3744 2716 }
a80beece 2717 else
718e3744 2718 {
6aeb9e78 2719 if (peer_address_self_check (bgp, &su))
a80beece
DS
2720 {
2721 vty_out (vty, "%% Can not configure the local system as neighbor%s",
2722 VTY_NEWLINE);
2723 return CMD_WARNING;
2724 }
0299c004 2725 ret = peer_remote_as (bgp, &su, NULL, &as, as_type, afi, safi);
718e3744 2726 }
2727
718e3744 2728 /* This peer belongs to peer group. */
2729 switch (ret)
2730 {
2731 case BGP_ERR_PEER_GROUP_MEMBER:
aea339f7 2732 vty_out (vty, "%% Peer-group AS %u. Cannot configure remote-as for member%s", as, VTY_NEWLINE);
718e3744 2733 return CMD_WARNING;
718e3744 2734 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
aea339f7 2735 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 2736 return CMD_WARNING;
718e3744 2737 }
2738 return bgp_vty_return (vty, ret);
2739}
2740
2741DEFUN (neighbor_remote_as,
2742 neighbor_remote_as_cmd,
3a2d747c 2743 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2744 NEIGHBOR_STR
2745 NEIGHBOR_ADDR_STR2
2746 "Specify a BGP neighbor\n"
d7fa34c1 2747 AS_STR
3a2d747c
QY
2748 "Internal BGP peer\n"
2749 "External BGP peer\n")
718e3744 2750{
c500ae40
DW
2751 int idx_peer = 1;
2752 int idx_remote_as = 3;
2753 return peer_remote_as_vty (vty, argv[idx_peer]->arg, argv[idx_remote_as]->arg, AFI_IP, SAFI_UNICAST);
718e3744 2754}
6b0655a2 2755
4c48cf63
DW
2756static int
2757peer_conf_interface_get (struct vty *vty, const char *conf_if, afi_t afi,
b3a39dc5
DD
2758 safi_t safi, int v6only, const char *peer_group_name,
2759 const char *as_str)
a80beece 2760{
cdc2d765 2761 VTY_DECLVAR_CONTEXT(bgp, bgp);
b3a39dc5
DD
2762 as_t as = 0;
2763 int as_type = AS_UNSPECIFIED;
a80beece
DS
2764 struct peer *peer;
2765 struct peer_group *group;
4c48cf63
DW
2766 int ret = 0;
2767 union sockunion su;
a80beece 2768
4c48cf63
DW
2769 group = peer_group_lookup (bgp, conf_if);
2770
a80beece
DS
2771 if (group)
2772 {
2773 vty_out (vty, "%% Name conflict with peer-group %s", VTY_NEWLINE);
2774 return CMD_WARNING;
2775 }
2776
b3a39dc5
DD
2777 if (as_str)
2778 {
7ae5fc81 2779 if (as_str[0] == 'i')
b3a39dc5
DD
2780 {
2781 as_type = AS_INTERNAL;
2782 }
7ae5fc81 2783 else if (as_str[0] == 'e')
b3a39dc5
DD
2784 {
2785 as_type = AS_EXTERNAL;
2786 }
2787 else
2788 {
2789 /* Get AS number. */
2790 VTY_GET_INTEGER_RANGE ("AS", as, as_str, 1, BGP_AS4_MAX);
2791 as_type = AS_SPECIFIED;
2792 }
2793 }
2794
4c48cf63 2795 peer = peer_lookup_by_conf_if (bgp, conf_if);
464598de
DW
2796 if (peer)
2797 {
2798 if (as_str)
3bd07551 2799 ret = peer_remote_as (bgp, &su, conf_if, &as, as_type, afi, safi);
464598de
DW
2800 }
2801 else
4c48cf63
DW
2802 {
2803 if (bgp_flag_check (bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2804 && afi == AFI_IP && safi == SAFI_UNICAST)
b3a39dc5
DD
2805 peer = peer_create (NULL, conf_if, bgp, bgp->as, as, as_type, 0, 0,
2806 NULL);
4c48cf63 2807 else
b3a39dc5
DD
2808 peer = peer_create (NULL, conf_if, bgp, bgp->as, as, as_type, afi, safi,
2809 NULL);
4c48cf63 2810
c358f112
DS
2811 if (!peer)
2812 return CMD_WARNING;
2813
2814 if (v6only)
4c48cf63 2815 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
4a04e5f7 2816
2817 /* Request zebra to initiate IPv6 RAs on this interface. We do this
2818 * any unnumbered peer in order to not worry about run-time transitions
2819 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31 address
2820 * gets deleted later etc.)
2821 */
2822 if (peer->ifp)
c358f112 2823 bgp_zebra_initiate_radv (bgp, peer);
4c48cf63 2824 }
464598de
DW
2825
2826 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) ||
2827 (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)))
4c48cf63
DW
2828 {
2829 if (v6only)
2830 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2831 else
2832 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2833
2834 /* v6only flag changed. Reset bgp seesion */
2835 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status))
2836 {
2837 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2838 bgp_notify_send (peer, BGP_NOTIFY_CEASE,
2839 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2840 }
2841 else
2842 bgp_session_reset(peer);
2843 }
2844
c358f112
DS
2845 if (!CHECK_FLAG (peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2846 peer_flag_set (peer, PEER_FLAG_CAPABILITY_ENHE);
a80beece 2847
4c48cf63
DW
2848 if (peer_group_name)
2849 {
2850 group = peer_group_lookup (bgp, peer_group_name);
2851 if (! group)
2852 {
2853 vty_out (vty, "%% Configure the peer-group first%s", VTY_NEWLINE);
2854 return CMD_WARNING;
2855 }
2856
2857 ret = peer_group_bind (bgp, &su, peer, group, &as);
2858 }
2859
2860 return bgp_vty_return (vty, ret);
a80beece
DS
2861}
2862
4c48cf63
DW
2863DEFUN (neighbor_interface_config,
2864 neighbor_interface_config_cmd,
31500417 2865 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2866 NEIGHBOR_STR
2867 "Interface name or neighbor tag\n"
31500417
DW
2868 "Enable BGP on interface\n"
2869 "Member of the peer-group\n"
16cedbb0 2870 "Peer-group name\n")
4c48cf63 2871{
c500ae40 2872 int idx_word = 1;
31500417
DW
2873 int idx_peer_group_word = 4;
2874
2875 if (argc > idx_peer_group_word)
c500ae40 2876 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
31500417 2877 argv[idx_peer_group_word]->arg, NULL);
4c48cf63 2878 else
c500ae40 2879 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
b3a39dc5 2880 NULL, NULL);
4c48cf63
DW
2881}
2882
4c48cf63
DW
2883DEFUN (neighbor_interface_config_v6only,
2884 neighbor_interface_config_v6only_cmd,
31500417 2885 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2886 NEIGHBOR_STR
2887 "Interface name or neighbor tag\n"
2888 "Enable BGP on interface\n"
31500417
DW
2889 "Enable BGP with v6 link-local only\n"
2890 "Member of the peer-group\n"
16cedbb0 2891 "Peer-group name\n")
4c48cf63 2892{
c500ae40 2893 int idx_word = 1;
31500417
DW
2894 int idx_peer_group_word = 5;
2895
2896 if (argc > idx_peer_group_word)
2897 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2898 argv[idx_peer_group_word]->arg, NULL);
2899
c500ae40 2900 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
31500417 2901 NULL, NULL);
4c48cf63
DW
2902}
2903
a80beece 2904
b3a39dc5
DD
2905DEFUN (neighbor_interface_config_remote_as,
2906 neighbor_interface_config_remote_as_cmd,
3a2d747c 2907 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2908 NEIGHBOR_STR
2909 "Interface name or neighbor tag\n"
2910 "Enable BGP on interface\n"
3a2d747c 2911 "Specify a BGP neighbor\n"
d7fa34c1 2912 AS_STR
3a2d747c
QY
2913 "Internal BGP peer\n"
2914 "External BGP peer\n")
b3a39dc5 2915{
c500ae40
DW
2916 int idx_word = 1;
2917 int idx_remote_as = 4;
2918 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2919 NULL, argv[idx_remote_as]->arg);
b3a39dc5
DD
2920}
2921
2922DEFUN (neighbor_interface_v6only_config_remote_as,
2923 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2924 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2925 NEIGHBOR_STR
2926 "Interface name or neighbor tag\n"
3a2d747c 2927 "Enable BGP with v6 link-local only\n"
b3a39dc5 2928 "Enable BGP on interface\n"
3a2d747c 2929 "Specify a BGP neighbor\n"
d7fa34c1 2930 AS_STR
3a2d747c
QY
2931 "Internal BGP peer\n"
2932 "External BGP peer\n")
b3a39dc5 2933{
c500ae40
DW
2934 int idx_word = 1;
2935 int idx_remote_as = 5;
2936 return peer_conf_interface_get (vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2937 NULL, argv[idx_remote_as]->arg);
b3a39dc5
DD
2938}
2939
718e3744 2940DEFUN (neighbor_peer_group,
2941 neighbor_peer_group_cmd,
2942 "neighbor WORD peer-group",
2943 NEIGHBOR_STR
a80beece 2944 "Interface name or neighbor tag\n"
718e3744 2945 "Configure peer-group\n")
2946{
cdc2d765 2947 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 2948 int idx_word = 1;
a80beece 2949 struct peer *peer;
718e3744 2950 struct peer_group *group;
2951
c500ae40 2952 peer = peer_lookup_by_conf_if (bgp, argv[idx_word]->arg);
a80beece
DS
2953 if (peer)
2954 {
2955 vty_out (vty, "%% Name conflict with interface: %s", VTY_NEWLINE);
2956 return CMD_WARNING;
2957 }
718e3744 2958
c500ae40 2959 group = peer_group_get (bgp, argv[idx_word]->arg);
718e3744 2960 if (! group)
2961 return CMD_WARNING;
2962
2963 return CMD_SUCCESS;
2964}
2965
2966DEFUN (no_neighbor,
2967 no_neighbor_cmd,
dab8cd00 2968 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2969 NO_STR
2970 NEIGHBOR_STR
3a2d747c
QY
2971 NEIGHBOR_ADDR_STR2
2972 "Specify a BGP neighbor\n"
2973 AS_STR
2974 "Internal BGP peer\n"
2975 "External BGP peer\n")
718e3744 2976{
cdc2d765 2977 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 2978 int idx_peer = 2;
718e3744 2979 int ret;
2980 union sockunion su;
2981 struct peer_group *group;
2982 struct peer *peer;
1ff9a340 2983 struct peer *other;
718e3744 2984
c500ae40 2985 ret = str2sockunion (argv[idx_peer]->arg, &su);
718e3744 2986 if (ret < 0)
2987 {
a80beece 2988 /* look up for neighbor by interface name config. */
cdc2d765 2989 peer = peer_lookup_by_conf_if (bgp, argv[idx_peer]->arg);
a80beece
DS
2990 if (peer)
2991 {
4a04e5f7 2992 /* Request zebra to terminate IPv6 RAs on this interface. */
2993 if (peer->ifp)
2994 bgp_zebra_terminate_radv (peer->bgp, peer);
a80beece
DS
2995 peer_delete (peer);
2996 return CMD_SUCCESS;
2997 }
2998
cdc2d765 2999 group = peer_group_lookup (bgp, argv[idx_peer]->arg);
718e3744 3000 if (group)
3001 peer_group_delete (group);
3002 else
3003 {
3004 vty_out (vty, "%% Create the peer-group first%s", VTY_NEWLINE);
3005 return CMD_WARNING;
3006 }
3007 }
3008 else
3009 {
cdc2d765 3010 peer = peer_lookup (bgp, &su);
718e3744 3011 if (peer)
1ff9a340 3012 {
f14e6fdb
DS
3013 if (peer_dynamic_neighbor (peer))
3014 {
3015 vty_out (vty, "%% Operation not allowed on a dynamic neighbor%s",
3016 VTY_NEWLINE);
3017 return CMD_WARNING;
3018 }
3019
1ff9a340
DS
3020 other = peer->doppelganger;
3021 peer_delete (peer);
3022 if (other && other->status != Deleted)
3023 peer_delete(other);
3024 }
718e3744 3025 }
3026
3027 return CMD_SUCCESS;
3028}
3029
a80beece
DS
3030DEFUN (no_neighbor_interface_config,
3031 no_neighbor_interface_config_cmd,
31500417 3032 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
3033 NO_STR
3034 NEIGHBOR_STR
3035 "Interface name\n"
31500417
DW
3036 "Configure BGP on interface\n"
3037 "Enable BGP with v6 link-local only\n"
3038 "Member of the peer-group\n"
16cedbb0 3039 "Peer-group name\n"
3a2d747c
QY
3040 "Specify a BGP neighbor\n"
3041 AS_STR
3042 "Internal BGP peer\n"
3043 "External BGP peer\n")
a80beece 3044{
cdc2d765 3045 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 3046 int idx_word = 2;
a80beece
DS
3047 struct peer *peer;
3048
3049 /* look up for neighbor by interface name config. */
cdc2d765 3050 peer = peer_lookup_by_conf_if (bgp, argv[idx_word]->arg);
a80beece
DS
3051 if (peer)
3052 {
4a04e5f7 3053 /* Request zebra to terminate IPv6 RAs on this interface. */
3054 if (peer->ifp)
3055 bgp_zebra_terminate_radv (peer->bgp, peer);
a80beece
DS
3056 peer_delete (peer);
3057 }
3058 else
3059 {
3060 vty_out (vty, "%% Create the bgp interface first%s", VTY_NEWLINE);
3061 return CMD_WARNING;
3062 }
3063 return CMD_SUCCESS;
3064}
3065
718e3744 3066DEFUN (no_neighbor_peer_group,
3067 no_neighbor_peer_group_cmd,
3068 "no neighbor WORD peer-group",
3069 NO_STR
3070 NEIGHBOR_STR
3071 "Neighbor tag\n"
3072 "Configure peer-group\n")
3073{
cdc2d765 3074 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 3075 int idx_word = 2;
718e3744 3076 struct peer_group *group;
3077
cdc2d765 3078 group = peer_group_lookup (bgp, argv[idx_word]->arg);
718e3744 3079 if (group)
3080 peer_group_delete (group);
3081 else
3082 {
3083 vty_out (vty, "%% Create the peer-group first%s", VTY_NEWLINE);
3084 return CMD_WARNING;
3085 }
3086 return CMD_SUCCESS;
3087}
3088
a80beece
DS
3089DEFUN (no_neighbor_interface_peer_group_remote_as,
3090 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3091 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3092 NO_STR
3093 NEIGHBOR_STR
a80beece 3094 "Interface name or neighbor tag\n"
718e3744 3095 "Specify a BGP neighbor\n"
3a2d747c
QY
3096 AS_STR
3097 "Internal BGP peer\n"
3098 "External BGP peer\n")
718e3744 3099{
cdc2d765 3100 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 3101 int idx_word = 2;
718e3744 3102 struct peer_group *group;
a80beece
DS
3103 struct peer *peer;
3104
3105 /* look up for neighbor by interface name config. */
cdc2d765 3106 peer = peer_lookup_by_conf_if (bgp, argv[idx_word]->arg);
a80beece
DS
3107 if (peer)
3108 {
0299c004 3109 peer_as_change (peer, 0, AS_SPECIFIED);
a80beece
DS
3110 return CMD_SUCCESS;
3111 }
718e3744 3112
cdc2d765 3113 group = peer_group_lookup (bgp, argv[idx_word]->arg);
718e3744 3114 if (group)
3115 peer_group_remote_as_delete (group);
3116 else
3117 {
a80beece 3118 vty_out (vty, "%% Create the peer-group or interface first%s", VTY_NEWLINE);
718e3744 3119 return CMD_WARNING;
3120 }
3121 return CMD_SUCCESS;
3122}
6b0655a2 3123
718e3744 3124DEFUN (neighbor_local_as,
3125 neighbor_local_as_cmd,
9ccf14f7 3126 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3127 NEIGHBOR_STR
3128 NEIGHBOR_ADDR_STR2
3129 "Specify a local-as number\n"
3130 "AS number used as local AS\n")
3131{
c500ae40
DW
3132 int idx_peer = 1;
3133 int idx_number = 3;
718e3744 3134 struct peer *peer;
3135 int ret;
e14fda0f 3136 as_t as;
718e3744 3137
c500ae40 3138 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 3139 if (! peer)
3140 return CMD_WARNING;
3141
b6f1faf0 3142 VTY_GET_INTEGER_RANGE ("Local AS", as, argv[idx_number]->arg, 1, BGP_AS4_MAX);
e14fda0f 3143 ret = peer_local_as_set (peer, as, 0, 0);
718e3744 3144 return bgp_vty_return (vty, ret);
3145}
3146
3147DEFUN (neighbor_local_as_no_prepend,
3148 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3149 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3150 NEIGHBOR_STR
3151 NEIGHBOR_ADDR_STR2
3152 "Specify a local-as number\n"
3153 "AS number used as local AS\n"
3154 "Do not prepend local-as to updates from ebgp peers\n")
3155{
c500ae40
DW
3156 int idx_peer = 1;
3157 int idx_number = 3;
718e3744 3158 struct peer *peer;
3159 int ret;
e14fda0f 3160 as_t as;
718e3744 3161
c500ae40 3162 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 3163 if (! peer)
3164 return CMD_WARNING;
3165
b6f1faf0 3166 VTY_GET_INTEGER_RANGE ("Local AS", as, argv[idx_number]->arg, 1, BGP_AS4_MAX);
e14fda0f 3167 ret = peer_local_as_set (peer, as, 1, 0);
718e3744 3168 return bgp_vty_return (vty, ret);
3169}
3170
9d3f9705
AC
3171DEFUN (neighbor_local_as_no_prepend_replace_as,
3172 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3173 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3174 NEIGHBOR_STR
3175 NEIGHBOR_ADDR_STR2
3176 "Specify a local-as number\n"
3177 "AS number used as local AS\n"
3178 "Do not prepend local-as to updates from ebgp peers\n"
3179 "Do not prepend local-as to updates from ibgp peers\n")
3180{
c500ae40
DW
3181 int idx_peer = 1;
3182 int idx_number = 3;
9d3f9705
AC
3183 struct peer *peer;
3184 int ret;
e14fda0f 3185 as_t as;
9d3f9705 3186
c500ae40 3187 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
9d3f9705
AC
3188 if (! peer)
3189 return CMD_WARNING;
3190
b6f1faf0 3191 VTY_GET_INTEGER_RANGE ("Local AS", as, argv[idx_number]->arg, 1, BGP_AS4_MAX);
e14fda0f 3192 ret = peer_local_as_set (peer, as, 1, 1);
9d3f9705
AC
3193 return bgp_vty_return (vty, ret);
3194}
3195
718e3744 3196DEFUN (no_neighbor_local_as,
3197 no_neighbor_local_as_cmd,
a636c635 3198 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3199 NO_STR
3200 NEIGHBOR_STR
3201 NEIGHBOR_ADDR_STR2
a636c635
DW
3202 "Specify a local-as number\n"
3203 "AS number used as local AS\n"
3204 "Do not prepend local-as to updates from ebgp peers\n"
3205 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3206{
c500ae40 3207 int idx_peer = 2;
718e3744 3208 struct peer *peer;
3209 int ret;
3210
c500ae40 3211 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 3212 if (! peer)
3213 return CMD_WARNING;
3214
3215 ret = peer_local_as_unset (peer);
3216 return bgp_vty_return (vty, ret);
3217}
3218
718e3744 3219
9d3f9705 3220
6b0655a2 3221
3f9c7369
DS
3222DEFUN (neighbor_solo,
3223 neighbor_solo_cmd,
9ccf14f7 3224 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3225 NEIGHBOR_STR
3226 NEIGHBOR_ADDR_STR2
3227 "Solo peer - part of its own update group\n")
3228{
c500ae40 3229 int idx_peer = 1;
3f9c7369
DS
3230 struct peer *peer;
3231 int ret;
3232
c500ae40 3233 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3f9c7369
DS
3234 if (! peer)
3235 return CMD_WARNING;
3236
3237 ret = update_group_adjust_soloness(peer, 1);
3238 return bgp_vty_return (vty, ret);
3239}
3240
3241DEFUN (no_neighbor_solo,
3242 no_neighbor_solo_cmd,
9ccf14f7 3243 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3244 NO_STR
3245 NEIGHBOR_STR
3246 NEIGHBOR_ADDR_STR2
3247 "Solo peer - part of its own update group\n")
3248{
c500ae40 3249 int idx_peer = 2;
3f9c7369
DS
3250 struct peer *peer;
3251 int ret;
3252
c500ae40 3253 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
3f9c7369
DS
3254 if (! peer)
3255 return CMD_WARNING;
3256
3257 ret = update_group_adjust_soloness(peer, 0);
3258 return bgp_vty_return (vty, ret);
3259}
3260
0df7c91f
PJ
3261DEFUN (neighbor_password,
3262 neighbor_password_cmd,
9ccf14f7 3263 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3264 NEIGHBOR_STR
3265 NEIGHBOR_ADDR_STR2
3266 "Set a password\n"
3267 "The password\n")
3268{
c500ae40
DW
3269 int idx_peer = 1;
3270 int idx_line = 3;
0df7c91f
PJ
3271 struct peer *peer;
3272 int ret;
3273
c500ae40 3274 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
0df7c91f
PJ
3275 if (! peer)
3276 return CMD_WARNING;
3277
c500ae40 3278 ret = peer_password_set (peer, argv[idx_line]->arg);
0df7c91f
PJ
3279 return bgp_vty_return (vty, ret);
3280}
3281
3282DEFUN (no_neighbor_password,
3283 no_neighbor_password_cmd,
a636c635 3284 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3285 NO_STR
3286 NEIGHBOR_STR
3287 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3288 "Set a password\n"
3289 "The password\n")
0df7c91f 3290{
c500ae40 3291 int idx_peer = 2;
0df7c91f
PJ
3292 struct peer *peer;
3293 int ret;
3294
c500ae40 3295 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
0df7c91f
PJ
3296 if (! peer)
3297 return CMD_WARNING;
3298
3299 ret = peer_password_unset (peer);
3300 return bgp_vty_return (vty, ret);
3301}
6b0655a2 3302
813d4307 3303
718e3744 3304DEFUN (neighbor_activate,
3305 neighbor_activate_cmd,
9ccf14f7 3306 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3307 NEIGHBOR_STR
3308 NEIGHBOR_ADDR_STR2
3309 "Enable the Address Family for this Neighbor\n")
3310{
c500ae40 3311 int idx_peer = 1;
c8560b44 3312 int ret;
718e3744 3313 struct peer *peer;
3314
c500ae40 3315 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 3316 if (! peer)
3317 return CMD_WARNING;
3318
c8560b44 3319 ret = peer_activate (peer, bgp_node_afi (vty), bgp_node_safi (vty));
718e3744 3320
c8560b44
DW
3321 if (ret)
3322 return CMD_WARNING;
718e3744 3323 return CMD_SUCCESS;
3324}
3325
596c17ba
DW
3326ALIAS_HIDDEN (neighbor_activate,
3327 neighbor_activate_hidden_cmd,
3328 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3329 NEIGHBOR_STR
3330 NEIGHBOR_ADDR_STR2
3331 "Enable the Address Family for this Neighbor\n")
3332
718e3744 3333DEFUN (no_neighbor_activate,
3334 no_neighbor_activate_cmd,
9ccf14f7 3335 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3336 NO_STR
3337 NEIGHBOR_STR
3338 NEIGHBOR_ADDR_STR2
3339 "Enable the Address Family for this Neighbor\n")
3340{
c500ae40 3341 int idx_peer = 2;
718e3744 3342 int ret;
3343 struct peer *peer;
3344
3345 /* Lookup peer. */
c500ae40 3346 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 3347 if (! peer)
3348 return CMD_WARNING;
3349
3350 ret = peer_deactivate (peer, bgp_node_afi (vty), bgp_node_safi (vty));
3351
c8560b44
DW
3352 if (ret)
3353 return CMD_WARNING;
3354 return CMD_SUCCESS;
718e3744 3355}
6b0655a2 3356
596c17ba
DW
3357ALIAS_HIDDEN (no_neighbor_activate,
3358 no_neighbor_activate_hidden_cmd,
3359 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3360 NO_STR
3361 NEIGHBOR_STR
3362 NEIGHBOR_ADDR_STR2
3363 "Enable the Address Family for this Neighbor\n")
3364
718e3744 3365DEFUN (neighbor_set_peer_group,
3366 neighbor_set_peer_group_cmd,
9ccf14f7 3367 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3368 NEIGHBOR_STR
a80beece 3369 NEIGHBOR_ADDR_STR2
718e3744 3370 "Member of the peer-group\n"
16cedbb0 3371 "Peer-group name\n")
718e3744 3372{
cdc2d765 3373 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
3374 int idx_peer = 1;
3375 int idx_word = 3;
718e3744 3376 int ret;
3377 as_t as;
3378 union sockunion su;
a80beece 3379 struct peer *peer;
718e3744 3380 struct peer_group *group;
3381
a80beece 3382 peer = NULL;
718e3744 3383
c500ae40 3384 ret = str2sockunion (argv[idx_peer]->arg, &su);
718e3744 3385 if (ret < 0)
3386 {
c500ae40 3387 peer = peer_lookup_by_conf_if (bgp, argv[idx_peer]->arg);
a80beece
DS
3388 if (!peer)
3389 {
c500ae40 3390 vty_out (vty, "%% Malformed address or name: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
a80beece
DS
3391 return CMD_WARNING;
3392 }
3393 }
3394 else
3395 {
6aeb9e78 3396 if (peer_address_self_check (bgp, &su))
a80beece
DS
3397 {
3398 vty_out (vty, "%% Can not configure the local system as neighbor%s",
3399 VTY_NEWLINE);
3400 return CMD_WARNING;
3401 }
f14e6fdb
DS
3402
3403 /* Disallow for dynamic neighbor. */
3404 peer = peer_lookup (bgp, &su);
3405 if (peer && peer_dynamic_neighbor (peer))
3406 {
3407 vty_out (vty, "%% Operation not allowed on a dynamic neighbor%s",
3408 VTY_NEWLINE);
3409 return CMD_WARNING;
3410 }
718e3744 3411 }
3412
c500ae40 3413 group = peer_group_lookup (bgp, argv[idx_word]->arg);
718e3744 3414 if (! group)
3415 {
3416 vty_out (vty, "%% Configure the peer-group first%s", VTY_NEWLINE);
3417 return CMD_WARNING;
3418 }
3419
c8560b44 3420 ret = peer_group_bind (bgp, &su, peer, group, &as);
718e3744 3421
3422 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT)
3423 {
aea339f7 3424 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 3425 return CMD_WARNING;
3426 }
3427
3428 return bgp_vty_return (vty, ret);
3429}
3430
596c17ba
DW
3431ALIAS_HIDDEN (neighbor_set_peer_group,
3432 neighbor_set_peer_group_hidden_cmd,
3433 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3434 NEIGHBOR_STR
3435 NEIGHBOR_ADDR_STR2
3436 "Member of the peer-group\n"
3437 "Peer-group name\n")
3438
718e3744 3439DEFUN (no_neighbor_set_peer_group,
3440 no_neighbor_set_peer_group_cmd,
9ccf14f7 3441 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3442 NO_STR
3443 NEIGHBOR_STR
a80beece 3444 NEIGHBOR_ADDR_STR2
718e3744 3445 "Member of the peer-group\n"
16cedbb0 3446 "Peer-group name\n")
718e3744 3447{
cdc2d765 3448 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
3449 int idx_peer = 2;
3450 int idx_word = 4;
718e3744 3451 int ret;
718e3744 3452 struct peer *peer;
3453 struct peer_group *group;
3454
c500ae40 3455 peer = peer_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 3456 if (! peer)
3457 return CMD_WARNING;
3458
c500ae40 3459 group = peer_group_lookup (bgp, argv[idx_word]->arg);
718e3744 3460 if (! group)
3461 {
3462 vty_out (vty, "%% Configure the peer-group first%s", VTY_NEWLINE);
3463 return CMD_WARNING;
3464 }
3465
c8560b44 3466 ret = peer_group_unbind (bgp, peer, group);
718e3744 3467
3468 return bgp_vty_return (vty, ret);
3469}
6b0655a2 3470
596c17ba
DW
3471ALIAS_HIDDEN (no_neighbor_set_peer_group,
3472 no_neighbor_set_peer_group_hidden_cmd,
3473 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3474 NO_STR
3475 NEIGHBOR_STR
3476 NEIGHBOR_ADDR_STR2
3477 "Member of the peer-group\n"
3478 "Peer-group name\n")
3479
94f2b392 3480static int
e52702f2 3481peer_flag_modify_vty (struct vty *vty, const char *ip_str,
fd79ac91 3482 u_int16_t flag, int set)
718e3744 3483{
3484 int ret;
3485 struct peer *peer;
3486
3487 peer = peer_and_group_lookup_vty (vty, ip_str);
3488 if (! peer)
3489 return CMD_WARNING;
3490
8cdabf90
SK
3491 /*
3492 * If 'neighbor <interface>', then this is for directly connected peers,
3493 * we should not accept disable-connected-check.
3494 */
3495 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3496 vty_out (vty, "%s is directly connected peer, cannot accept disable-"
3497 "connected-check%s", ip_str, VTY_NEWLINE);
3498 return CMD_WARNING;
3499 }
3500
ae9b0e11
DS
3501 if (!set && flag == PEER_FLAG_SHUTDOWN)
3502 peer_tx_shutdown_message_unset (peer);
3503
718e3744 3504 if (set)
3505 ret = peer_flag_set (peer, flag);
3506 else
3507 ret = peer_flag_unset (peer, flag);
3508
3509 return bgp_vty_return (vty, ret);
3510}
3511
94f2b392 3512static int
fd79ac91 3513peer_flag_set_vty (struct vty *vty, const char *ip_str, u_int16_t flag)
718e3744 3514{
3515 return peer_flag_modify_vty (vty, ip_str, flag, 1);
3516}
3517
94f2b392 3518static int
fd79ac91 3519peer_flag_unset_vty (struct vty *vty, const char *ip_str, u_int16_t flag)
718e3744 3520{
3521 return peer_flag_modify_vty (vty, ip_str, flag, 0);
3522}
3523
3524/* neighbor passive. */
3525DEFUN (neighbor_passive,
3526 neighbor_passive_cmd,
9ccf14f7 3527 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3528 NEIGHBOR_STR
3529 NEIGHBOR_ADDR_STR2
3530 "Don't send open messages to this neighbor\n")
3531{
c500ae40
DW
3532 int idx_peer = 1;
3533 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3534}
3535
3536DEFUN (no_neighbor_passive,
3537 no_neighbor_passive_cmd,
9ccf14f7 3538 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3539 NO_STR
3540 NEIGHBOR_STR
3541 NEIGHBOR_ADDR_STR2
3542 "Don't send open messages to this neighbor\n")
3543{
c500ae40
DW
3544 int idx_peer = 2;
3545 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3546}
6b0655a2 3547
718e3744 3548/* neighbor shutdown. */
73d70fa6
DL
3549DEFUN (neighbor_shutdown_msg,
3550 neighbor_shutdown_msg_cmd,
3551 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3552 NEIGHBOR_STR
3553 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3554 "Administratively shut down this neighbor\n"
3555 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3556 "Shutdown message\n")
718e3744 3557{
c500ae40 3558 int idx_peer = 1;
73d70fa6
DL
3559
3560 if (argc >= 5)
3561 {
ae9b0e11 3562 struct peer *peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
73d70fa6
DL
3563 char *message;
3564
ae9b0e11
DS
3565 if (!peer)
3566 return CMD_WARNING;
73d70fa6
DL
3567 message = argv_concat (argv, argc, 4);
3568 peer_tx_shutdown_message_set (peer, message);
3569 XFREE (MTYPE_TMP, message);
3570 }
3571
c500ae40 3572 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3573}
3574
73d70fa6
DL
3575ALIAS (neighbor_shutdown_msg,
3576 neighbor_shutdown_cmd,
3577 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
718e3744 3578 NEIGHBOR_STR
3579 NEIGHBOR_ADDR_STR2
3580 "Administratively shut down this neighbor\n")
73d70fa6
DL
3581
3582DEFUN (no_neighbor_shutdown_msg,
3583 no_neighbor_shutdown_msg_cmd,
3584 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3585 NO_STR
3586 NEIGHBOR_STR
3587 NEIGHBOR_ADDR_STR2
3588 "Administratively shut down this neighbor\n"
3589 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3590 "Shutdown message\n")
718e3744 3591{
c500ae40 3592 int idx_peer = 2;
73d70fa6 3593
c500ae40 3594 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3595}
6b0655a2 3596
73d70fa6
DL
3597ALIAS (no_neighbor_shutdown_msg,
3598 no_neighbor_shutdown_cmd,
3599 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3600 NO_STR
3601 NEIGHBOR_STR
3602 NEIGHBOR_ADDR_STR2
3603 "Administratively shut down this neighbor\n")
3604
718e3744 3605/* neighbor capability dynamic. */
3606DEFUN (neighbor_capability_dynamic,
3607 neighbor_capability_dynamic_cmd,
9ccf14f7 3608 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3609 NEIGHBOR_STR
3610 NEIGHBOR_ADDR_STR2
3611 "Advertise capability to the peer\n"
3612 "Advertise dynamic capability to this neighbor\n")
3613{
c500ae40
DW
3614 int idx_peer = 1;
3615 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3616}
3617
3618DEFUN (no_neighbor_capability_dynamic,
3619 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3620 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3621 NO_STR
3622 NEIGHBOR_STR
3623 NEIGHBOR_ADDR_STR2
3624 "Advertise capability to the peer\n"
3625 "Advertise dynamic capability to this neighbor\n")
3626{
c500ae40
DW
3627 int idx_peer = 2;
3628 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3629}
6b0655a2 3630
718e3744 3631/* neighbor dont-capability-negotiate */
3632DEFUN (neighbor_dont_capability_negotiate,
3633 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3634 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3635 NEIGHBOR_STR
3636 NEIGHBOR_ADDR_STR2
3637 "Do not perform capability negotiation\n")
3638{
c500ae40
DW
3639 int idx_peer = 1;
3640 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DONT_CAPABILITY);
718e3744 3641}
3642
3643DEFUN (no_neighbor_dont_capability_negotiate,
3644 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3645 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3646 NO_STR
3647 NEIGHBOR_STR
3648 NEIGHBOR_ADDR_STR2
3649 "Do not perform capability negotiation\n")
3650{
c500ae40
DW
3651 int idx_peer = 2;
3652 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DONT_CAPABILITY);
718e3744 3653}
6b0655a2 3654
8a92a8a0
DS
3655/* neighbor capability extended next hop encoding */
3656DEFUN (neighbor_capability_enhe,
3657 neighbor_capability_enhe_cmd,
9ccf14f7 3658 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3659 NEIGHBOR_STR
3660 NEIGHBOR_ADDR_STR2
3661 "Advertise capability to the peer\n"
3662 "Advertise extended next-hop capability to the peer\n")
3663{
c500ae40
DW
3664 int idx_peer = 1;
3665 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3666}
3667
3668DEFUN (no_neighbor_capability_enhe,
3669 no_neighbor_capability_enhe_cmd,
9ccf14f7 3670 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3671 NO_STR
3672 NEIGHBOR_STR
3673 NEIGHBOR_ADDR_STR2
3674 "Advertise capability to the peer\n"
3675 "Advertise extended next-hop capability to the peer\n")
3676{
c500ae40
DW
3677 int idx_peer = 2;
3678 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3679}
3680
94f2b392 3681static int
fd79ac91 3682peer_af_flag_modify_vty (struct vty *vty, const char *peer_str, afi_t afi,
fee0f4c6 3683 safi_t safi, u_int32_t flag, int set)
718e3744 3684{
3685 int ret;
3686 struct peer *peer;
3687
3688 peer = peer_and_group_lookup_vty (vty, peer_str);
3689 if (! peer)
3690 return CMD_WARNING;
3691
3692 if (set)
3693 ret = peer_af_flag_set (peer, afi, safi, flag);
3694 else
3695 ret = peer_af_flag_unset (peer, afi, safi, flag);
3696
3697 return bgp_vty_return (vty, ret);
3698}
3699
94f2b392 3700static int
fd79ac91 3701peer_af_flag_set_vty (struct vty *vty, const char *peer_str, afi_t afi,
fee0f4c6 3702 safi_t safi, u_int32_t flag)
718e3744 3703{
3704 return peer_af_flag_modify_vty (vty, peer_str, afi, safi, flag, 1);
3705}
3706
94f2b392 3707static int
fd79ac91 3708peer_af_flag_unset_vty (struct vty *vty, const char *peer_str, afi_t afi,
fee0f4c6 3709 safi_t safi, u_int32_t flag)
718e3744 3710{
3711 return peer_af_flag_modify_vty (vty, peer_str, afi, safi, flag, 0);
3712}
6b0655a2 3713
718e3744 3714/* neighbor capability orf prefix-list. */
3715DEFUN (neighbor_capability_orf_prefix,
3716 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3717 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3718 NEIGHBOR_STR
3719 NEIGHBOR_ADDR_STR2
3720 "Advertise capability to the peer\n"
3721 "Advertise ORF capability to the peer\n"
3722 "Advertise prefixlist ORF capability to this neighbor\n"
3723 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3724 "Capability to RECEIVE the ORF from this neighbor\n"
3725 "Capability to SEND the ORF to this neighbor\n")
3726{
c500ae40
DW
3727 int idx_peer = 1;
3728 int idx_send_recv = 5;
718e3744 3729 u_int16_t flag = 0;
3730
c500ae40 3731 if (strncmp (argv[idx_send_recv]->arg, "s", 1) == 0)
718e3744 3732 flag = PEER_FLAG_ORF_PREFIX_SM;
c500ae40 3733 else if (strncmp (argv[idx_send_recv]->arg, "r", 1) == 0)
718e3744 3734 flag = PEER_FLAG_ORF_PREFIX_RM;
c500ae40 3735 else if (strncmp (argv[idx_send_recv]->arg, "b", 1) == 0)
718e3744 3736 flag = PEER_FLAG_ORF_PREFIX_SM|PEER_FLAG_ORF_PREFIX_RM;
3737 else
3738 return CMD_WARNING;
3739
c500ae40 3740 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 3741 bgp_node_safi (vty), flag);
3742}
3743
596c17ba
DW
3744ALIAS_HIDDEN (neighbor_capability_orf_prefix,
3745 neighbor_capability_orf_prefix_hidden_cmd,
3746 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3747 NEIGHBOR_STR
3748 NEIGHBOR_ADDR_STR2
3749 "Advertise capability to the peer\n"
3750 "Advertise ORF capability to the peer\n"
3751 "Advertise prefixlist ORF capability to this neighbor\n"
3752 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3753 "Capability to RECEIVE the ORF from this neighbor\n"
3754 "Capability to SEND the ORF to this neighbor\n")
3755
718e3744 3756DEFUN (no_neighbor_capability_orf_prefix,
3757 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3758 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3759 NO_STR
3760 NEIGHBOR_STR
3761 NEIGHBOR_ADDR_STR2
3762 "Advertise capability to the peer\n"
3763 "Advertise ORF capability to the peer\n"
3764 "Advertise prefixlist ORF capability to this neighbor\n"
3765 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3766 "Capability to RECEIVE the ORF from this neighbor\n"
3767 "Capability to SEND the ORF to this neighbor\n")
3768{
c500ae40
DW
3769 int idx_peer = 2;
3770 int idx_send_recv = 6;
718e3744 3771 u_int16_t flag = 0;
3772
c500ae40 3773 if (strncmp (argv[idx_send_recv]->arg, "s", 1) == 0)
718e3744 3774 flag = PEER_FLAG_ORF_PREFIX_SM;
c500ae40 3775 else if (strncmp (argv[idx_send_recv]->arg, "r", 1) == 0)
718e3744 3776 flag = PEER_FLAG_ORF_PREFIX_RM;
c500ae40 3777 else if (strncmp (argv[idx_send_recv]->arg, "b", 1) == 0)
718e3744 3778 flag = PEER_FLAG_ORF_PREFIX_SM|PEER_FLAG_ORF_PREFIX_RM;
3779 else
3780 return CMD_WARNING;
3781
c500ae40 3782 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 3783 bgp_node_safi (vty), flag);
3784}
6b0655a2 3785
596c17ba
DW
3786ALIAS_HIDDEN (no_neighbor_capability_orf_prefix,
3787 no_neighbor_capability_orf_prefix_hidden_cmd,
3788 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3789 NO_STR
3790 NEIGHBOR_STR
3791 NEIGHBOR_ADDR_STR2
3792 "Advertise capability to the peer\n"
3793 "Advertise ORF capability to the peer\n"
3794 "Advertise prefixlist ORF capability to this neighbor\n"
3795 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3796 "Capability to RECEIVE the ORF from this neighbor\n"
3797 "Capability to SEND the ORF to this neighbor\n")
3798
718e3744 3799/* neighbor next-hop-self. */
3800DEFUN (neighbor_nexthop_self,
3801 neighbor_nexthop_self_cmd,
9ccf14f7 3802 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3803 NEIGHBOR_STR
3804 NEIGHBOR_ADDR_STR2
a538debe 3805 "Disable the next hop calculation for this neighbor\n")
718e3744 3806{
c500ae40
DW
3807 int idx_peer = 1;
3808 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
a538debe
DS
3809 bgp_node_safi (vty), PEER_FLAG_NEXTHOP_SELF);
3810}
9e7a53c1 3811
596c17ba
DW
3812ALIAS_HIDDEN (neighbor_nexthop_self,
3813 neighbor_nexthop_self_hidden_cmd,
3814 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3815 NEIGHBOR_STR
3816 NEIGHBOR_ADDR_STR2
3817 "Disable the next hop calculation for this neighbor\n")
3818
a538debe
DS
3819/* neighbor next-hop-self. */
3820DEFUN (neighbor_nexthop_self_force,
3821 neighbor_nexthop_self_force_cmd,
9ccf14f7 3822 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3823 NEIGHBOR_STR
3824 NEIGHBOR_ADDR_STR2
3825 "Disable the next hop calculation for this neighbor\n"
3826 "Set the next hop to self for reflected routes\n")
3827{
c500ae40
DW
3828 int idx_peer = 1;
3829 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
a538debe 3830 bgp_node_safi (vty),
88b8ed8d 3831 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3832}
3833
596c17ba
DW
3834ALIAS_HIDDEN (neighbor_nexthop_self_force,
3835 neighbor_nexthop_self_force_hidden_cmd,
3836 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3837 NEIGHBOR_STR
3838 NEIGHBOR_ADDR_STR2
3839 "Disable the next hop calculation for this neighbor\n"
3840 "Set the next hop to self for reflected routes\n")
3841
718e3744 3842DEFUN (no_neighbor_nexthop_self,
3843 no_neighbor_nexthop_self_cmd,
9ccf14f7 3844 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3845 NO_STR
3846 NEIGHBOR_STR
3847 NEIGHBOR_ADDR_STR2
a538debe 3848 "Disable the next hop calculation for this neighbor\n")
718e3744 3849{
c500ae40
DW
3850 int idx_peer = 2;
3851 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
9e7a53c1 3852 bgp_node_safi (vty),
88b8ed8d 3853 PEER_FLAG_NEXTHOP_SELF);
718e3744 3854}
6b0655a2 3855
596c17ba
DW
3856ALIAS_HIDDEN (no_neighbor_nexthop_self,
3857 no_neighbor_nexthop_self_hidden_cmd,
3858 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3859 NO_STR
3860 NEIGHBOR_STR
3861 NEIGHBOR_ADDR_STR2
3862 "Disable the next hop calculation for this neighbor\n")
3863
88b8ed8d 3864DEFUN (no_neighbor_nexthop_self_force,
a538debe 3865 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3866 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3867 NO_STR
3868 NEIGHBOR_STR
3869 NEIGHBOR_ADDR_STR2
3870 "Disable the next hop calculation for this neighbor\n"
3871 "Set the next hop to self for reflected routes\n")
88b8ed8d 3872{
c500ae40
DW
3873 int idx_peer = 2;
3874 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
88b8ed8d
DW
3875 bgp_node_safi (vty),
3876 PEER_FLAG_FORCE_NEXTHOP_SELF);
3877}
a538debe 3878
596c17ba
DW
3879ALIAS_HIDDEN (no_neighbor_nexthop_self_force,
3880 no_neighbor_nexthop_self_force_hidden_cmd,
3881 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3882 NO_STR
3883 NEIGHBOR_STR
3884 NEIGHBOR_ADDR_STR2
3885 "Disable the next hop calculation for this neighbor\n"
3886 "Set the next hop to self for reflected routes\n")
3887
c7122e14
DS
3888/* neighbor as-override */
3889DEFUN (neighbor_as_override,
3890 neighbor_as_override_cmd,
9ccf14f7 3891 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3892 NEIGHBOR_STR
3893 NEIGHBOR_ADDR_STR2
3894 "Override ASNs in outbound updates if aspath equals remote-as\n")
3895{
c500ae40
DW
3896 int idx_peer = 1;
3897 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
c7122e14
DS
3898 bgp_node_safi (vty),
3899 PEER_FLAG_AS_OVERRIDE);
3900}
3901
596c17ba
DW
3902ALIAS_HIDDEN (neighbor_as_override,
3903 neighbor_as_override_hidden_cmd,
3904 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3905 NEIGHBOR_STR
3906 NEIGHBOR_ADDR_STR2
3907 "Override ASNs in outbound updates if aspath equals remote-as\n")
3908
c7122e14
DS
3909DEFUN (no_neighbor_as_override,
3910 no_neighbor_as_override_cmd,
9ccf14f7 3911 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3912 NO_STR
3913 NEIGHBOR_STR
3914 NEIGHBOR_ADDR_STR2
3915 "Override ASNs in outbound updates if aspath equals remote-as\n")
3916{
c500ae40
DW
3917 int idx_peer = 2;
3918 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
c7122e14
DS
3919 bgp_node_safi (vty),
3920 PEER_FLAG_AS_OVERRIDE);
3921}
3922
596c17ba
DW
3923ALIAS_HIDDEN (no_neighbor_as_override,
3924 no_neighbor_as_override_hidden_cmd,
3925 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3926 NO_STR
3927 NEIGHBOR_STR
3928 NEIGHBOR_ADDR_STR2
3929 "Override ASNs in outbound updates if aspath equals remote-as\n")
3930
718e3744 3931/* neighbor remove-private-AS. */
3932DEFUN (neighbor_remove_private_as,
3933 neighbor_remove_private_as_cmd,
9ccf14f7 3934 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3935 NEIGHBOR_STR
3936 NEIGHBOR_ADDR_STR2
5000f21c 3937 "Remove private ASNs in outbound updates\n")
718e3744 3938{
c500ae40
DW
3939 int idx_peer = 1;
3940 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 3941 bgp_node_safi (vty),
3942 PEER_FLAG_REMOVE_PRIVATE_AS);
3943}
3944
596c17ba
DW
3945ALIAS_HIDDEN (neighbor_remove_private_as,
3946 neighbor_remove_private_as_hidden_cmd,
3947 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3948 NEIGHBOR_STR
3949 NEIGHBOR_ADDR_STR2
3950 "Remove private ASNs in outbound updates\n")
3951
5000f21c
DS
3952DEFUN (neighbor_remove_private_as_all,
3953 neighbor_remove_private_as_all_cmd,
9ccf14f7 3954 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3955 NEIGHBOR_STR
3956 NEIGHBOR_ADDR_STR2
3957 "Remove private ASNs in outbound updates\n"
3958 "Apply to all AS numbers")
3959{
c500ae40
DW
3960 int idx_peer = 1;
3961 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5000f21c 3962 bgp_node_safi (vty),
5000f21c
DS
3963 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
3964}
3965
596c17ba
DW
3966ALIAS_HIDDEN (neighbor_remove_private_as_all,
3967 neighbor_remove_private_as_all_hidden_cmd,
3968 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3969 NEIGHBOR_STR
3970 NEIGHBOR_ADDR_STR2
3971 "Remove private ASNs in outbound updates\n"
3972 "Apply to all AS numbers")
3973
5000f21c
DS
3974DEFUN (neighbor_remove_private_as_replace_as,
3975 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3976 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3977 NEIGHBOR_STR
3978 NEIGHBOR_ADDR_STR2
3979 "Remove private ASNs in outbound updates\n"
3980 "Replace private ASNs with our ASN in outbound updates\n")
3981{
c500ae40
DW
3982 int idx_peer = 1;
3983 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5000f21c 3984 bgp_node_safi (vty),
5000f21c
DS
3985 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
3986}
3987
596c17ba
DW
3988ALIAS_HIDDEN (neighbor_remove_private_as_replace_as,
3989 neighbor_remove_private_as_replace_as_hidden_cmd,
3990 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3991 NEIGHBOR_STR
3992 NEIGHBOR_ADDR_STR2
3993 "Remove private ASNs in outbound updates\n"
3994 "Replace private ASNs with our ASN in outbound updates\n")
3995
5000f21c
DS
3996DEFUN (neighbor_remove_private_as_all_replace_as,
3997 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3998 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3999 NEIGHBOR_STR
4000 NEIGHBOR_ADDR_STR2
4001 "Remove private ASNs in outbound updates\n"
16cedbb0 4002 "Apply to all AS numbers\n"
5000f21c
DS
4003 "Replace private ASNs with our ASN in outbound updates\n")
4004{
c500ae40
DW
4005 int idx_peer = 1;
4006 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5000f21c 4007 bgp_node_safi (vty),
88b8ed8d 4008 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
4009}
4010
596c17ba
DW
4011ALIAS_HIDDEN (neighbor_remove_private_as_all_replace_as,
4012 neighbor_remove_private_as_all_replace_as_hidden_cmd,
4013 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4014 NEIGHBOR_STR
4015 NEIGHBOR_ADDR_STR2
4016 "Remove private ASNs in outbound updates\n"
4017 "Apply to all AS numbers\n"
4018 "Replace private ASNs with our ASN in outbound updates\n")
4019
718e3744 4020DEFUN (no_neighbor_remove_private_as,
4021 no_neighbor_remove_private_as_cmd,
9ccf14f7 4022 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 4023 NO_STR
4024 NEIGHBOR_STR
4025 NEIGHBOR_ADDR_STR2
5000f21c 4026 "Remove private ASNs in outbound updates\n")
718e3744 4027{
c500ae40
DW
4028 int idx_peer = 2;
4029 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4030 bgp_node_safi (vty),
88b8ed8d 4031 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 4032}
6b0655a2 4033
596c17ba
DW
4034ALIAS_HIDDEN (no_neighbor_remove_private_as,
4035 no_neighbor_remove_private_as_hidden_cmd,
4036 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
4037 NO_STR
4038 NEIGHBOR_STR
4039 NEIGHBOR_ADDR_STR2
4040 "Remove private ASNs in outbound updates\n")
4041
88b8ed8d 4042DEFUN (no_neighbor_remove_private_as_all,
5000f21c 4043 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 4044 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
4045 NO_STR
4046 NEIGHBOR_STR
4047 NEIGHBOR_ADDR_STR2
4048 "Remove private ASNs in outbound updates\n"
16cedbb0 4049 "Apply to all AS numbers\n")
88b8ed8d 4050{
c500ae40
DW
4051 int idx_peer = 2;
4052 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
88b8ed8d
DW
4053 bgp_node_safi (vty),
4054 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
4055}
5000f21c 4056
596c17ba
DW
4057ALIAS_HIDDEN (no_neighbor_remove_private_as_all,
4058 no_neighbor_remove_private_as_all_hidden_cmd,
4059 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
4060 NO_STR
4061 NEIGHBOR_STR
4062 NEIGHBOR_ADDR_STR2
4063 "Remove private ASNs in outbound updates\n"
4064 "Apply to all AS numbers\n")
4065
88b8ed8d 4066DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 4067 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 4068 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
4069 NO_STR
4070 NEIGHBOR_STR
4071 NEIGHBOR_ADDR_STR2
4072 "Remove private ASNs in outbound updates\n"
4073 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4074{
c500ae40
DW
4075 int idx_peer = 2;
4076 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
88b8ed8d
DW
4077 bgp_node_safi (vty),
4078 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
4079}
5000f21c 4080
596c17ba
DW
4081ALIAS_HIDDEN (no_neighbor_remove_private_as_replace_as,
4082 no_neighbor_remove_private_as_replace_as_hidden_cmd,
4083 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
4084 NO_STR
4085 NEIGHBOR_STR
4086 NEIGHBOR_ADDR_STR2
4087 "Remove private ASNs in outbound updates\n"
4088 "Replace private ASNs with our ASN in outbound updates\n")
4089
88b8ed8d 4090DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4091 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4092 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4093 NO_STR
4094 NEIGHBOR_STR
4095 NEIGHBOR_ADDR_STR2
4096 "Remove private ASNs in outbound updates\n"
16cedbb0 4097 "Apply to all AS numbers\n"
5000f21c 4098 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4099{
c500ae40
DW
4100 int idx_peer = 2;
4101 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
88b8ed8d
DW
4102 bgp_node_safi (vty),
4103 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
4104}
5000f21c 4105
596c17ba
DW
4106ALIAS_HIDDEN (no_neighbor_remove_private_as_all_replace_as,
4107 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4108 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4109 NO_STR
4110 NEIGHBOR_STR
4111 NEIGHBOR_ADDR_STR2
4112 "Remove private ASNs in outbound updates\n"
4113 "Apply to all AS numbers\n"
4114 "Replace private ASNs with our ASN in outbound updates\n")
4115
5000f21c 4116
718e3744 4117/* neighbor send-community. */
4118DEFUN (neighbor_send_community,
4119 neighbor_send_community_cmd,
9ccf14f7 4120 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4121 NEIGHBOR_STR
4122 NEIGHBOR_ADDR_STR2
4123 "Send Community attribute to this neighbor\n")
4124{
c500ae40
DW
4125 int idx_peer = 1;
4126 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4127 bgp_node_safi (vty),
4128 PEER_FLAG_SEND_COMMUNITY);
4129}
4130
596c17ba
DW
4131ALIAS_HIDDEN (neighbor_send_community,
4132 neighbor_send_community_hidden_cmd,
4133 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4134 NEIGHBOR_STR
4135 NEIGHBOR_ADDR_STR2
4136 "Send Community attribute to this neighbor\n")
4137
718e3744 4138DEFUN (no_neighbor_send_community,
4139 no_neighbor_send_community_cmd,
9ccf14f7 4140 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4141 NO_STR
4142 NEIGHBOR_STR
4143 NEIGHBOR_ADDR_STR2
4144 "Send Community attribute to this neighbor\n")
4145{
c500ae40
DW
4146 int idx_peer = 2;
4147 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4148 bgp_node_safi (vty),
4149 PEER_FLAG_SEND_COMMUNITY);
4150}
6b0655a2 4151
596c17ba
DW
4152ALIAS_HIDDEN (no_neighbor_send_community,
4153 no_neighbor_send_community_hidden_cmd,
4154 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4155 NO_STR
4156 NEIGHBOR_STR
4157 NEIGHBOR_ADDR_STR2
4158 "Send Community attribute to this neighbor\n")
4159
718e3744 4160/* neighbor send-community extended. */
4161DEFUN (neighbor_send_community_type,
4162 neighbor_send_community_type_cmd,
57d187bc 4163 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4164 NEIGHBOR_STR
4165 NEIGHBOR_ADDR_STR2
4166 "Send Community attribute to this neighbor\n"
4167 "Send Standard and Extended Community attributes\n"
57d187bc 4168 "Send Standard, Large and Extended Community attributes\n"
718e3744 4169 "Send Extended Community attributes\n"
57d187bc
JS
4170 "Send Standard Community attributes\n"
4171 "Send Large Community attributes\n")
718e3744 4172{
4c4ff4c1
QY
4173 int idx = 0;
4174 u_int32_t flag = 0;
718e3744 4175
4c4ff4c1
QY
4176 char *peer = argv[1]->arg;
4177
4178 if (argv_find (argv, argc, "standard", &idx))
4179 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
4180 else if (argv_find (argv, argc, "extended", &idx))
4181 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
57d187bc
JS
4182 else if (argv_find (argv, argc, "large", &idx))
4183 SET_FLAG (flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4184 else if (argv_find (argv, argc, "both", &idx))
4185 {
4186 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
4187 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4188 }
4c4ff4c1 4189 else
57d187bc
JS
4190 {
4191 SET_FLAG (flag, PEER_FLAG_SEND_COMMUNITY);
4192 SET_FLAG (flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4193 SET_FLAG (flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4194 }
4c4ff4c1
QY
4195
4196 return peer_af_flag_set_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flag);
718e3744 4197}
4198
596c17ba
DW
4199ALIAS_HIDDEN (neighbor_send_community_type,
4200 neighbor_send_community_type_hidden_cmd,
4201 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4202 NEIGHBOR_STR
4203 NEIGHBOR_ADDR_STR2
4204 "Send Community attribute to this neighbor\n"
4205 "Send Standard and Extended Community attributes\n"
4206 "Send Standard, Large and Extended Community attributes\n"
4207 "Send Extended Community attributes\n"
4208 "Send Standard Community attributes\n"
4209 "Send Large Community attributes\n")
4210
718e3744 4211DEFUN (no_neighbor_send_community_type,
4212 no_neighbor_send_community_type_cmd,
57d187bc 4213 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4214 NO_STR
4215 NEIGHBOR_STR
4216 NEIGHBOR_ADDR_STR2
4217 "Send Community attribute to this neighbor\n"
4218 "Send Standard and Extended Community attributes\n"
57d187bc 4219 "Send Standard, Large and Extended Community attributes\n"
718e3744 4220 "Send Extended Community attributes\n"
57d187bc
JS
4221 "Send Standard Community attributes\n"
4222 "Send Large Community attributes\n")
718e3744 4223{
c500ae40
DW
4224 int idx_peer = 2;
4225 int idx_type = 4;
4226 if (strncmp (argv[idx_type]->arg, "s", 1) == 0)
4227 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4228 bgp_node_safi (vty),
4229 PEER_FLAG_SEND_COMMUNITY);
c500ae40
DW
4230 if (strncmp (argv[idx_type]->arg, "e", 1) == 0)
4231 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4232 bgp_node_safi (vty),
4233 PEER_FLAG_SEND_EXT_COMMUNITY);
57d187bc
JS
4234 if (strncmp (argv[idx_type]->arg, "l", 1) == 0)
4235 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4236 bgp_node_safi (vty),
4237 PEER_FLAG_SEND_LARGE_COMMUNITY);
4238 if (strncmp (argv[idx_type]->arg, "b", 1) == 0)
4239 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4240 bgp_node_safi (vty),
4241 PEER_FLAG_SEND_COMMUNITY |
4242 PEER_FLAG_SEND_EXT_COMMUNITY);
718e3744 4243
c500ae40 4244 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4245 bgp_node_safi (vty),
4246 (PEER_FLAG_SEND_COMMUNITY |
57d187bc
JS
4247 PEER_FLAG_SEND_EXT_COMMUNITY|
4248 PEER_FLAG_SEND_LARGE_COMMUNITY));
718e3744 4249}
6b0655a2 4250
596c17ba
DW
4251ALIAS_HIDDEN (no_neighbor_send_community_type,
4252 no_neighbor_send_community_type_hidden_cmd,
4253 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4254 NO_STR
4255 NEIGHBOR_STR
4256 NEIGHBOR_ADDR_STR2
4257 "Send Community attribute to this neighbor\n"
4258 "Send Standard and Extended Community attributes\n"
4259 "Send Standard, Large and Extended Community attributes\n"
4260 "Send Extended Community attributes\n"
4261 "Send Standard Community attributes\n"
4262 "Send Large Community attributes\n")
4263
718e3744 4264/* neighbor soft-reconfig. */
4265DEFUN (neighbor_soft_reconfiguration,
4266 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4267 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4268 NEIGHBOR_STR
4269 NEIGHBOR_ADDR_STR2
4270 "Per neighbor soft reconfiguration\n"
4271 "Allow inbound soft reconfiguration for this neighbor\n")
4272{
c500ae40
DW
4273 int idx_peer = 1;
4274 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg,
718e3744 4275 bgp_node_afi (vty), bgp_node_safi (vty),
4276 PEER_FLAG_SOFT_RECONFIG);
4277}
4278
596c17ba
DW
4279ALIAS_HIDDEN (neighbor_soft_reconfiguration,
4280 neighbor_soft_reconfiguration_hidden_cmd,
4281 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4282 NEIGHBOR_STR
4283 NEIGHBOR_ADDR_STR2
4284 "Per neighbor soft reconfiguration\n"
4285 "Allow inbound soft reconfiguration for this neighbor\n")
4286
718e3744 4287DEFUN (no_neighbor_soft_reconfiguration,
4288 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4289 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4290 NO_STR
4291 NEIGHBOR_STR
4292 NEIGHBOR_ADDR_STR2
4293 "Per neighbor soft reconfiguration\n"
4294 "Allow inbound soft reconfiguration for this neighbor\n")
4295{
c500ae40
DW
4296 int idx_peer = 2;
4297 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg,
718e3744 4298 bgp_node_afi (vty), bgp_node_safi (vty),
4299 PEER_FLAG_SOFT_RECONFIG);
4300}
6b0655a2 4301
596c17ba
DW
4302ALIAS_HIDDEN (no_neighbor_soft_reconfiguration,
4303 no_neighbor_soft_reconfiguration_hidden_cmd,
4304 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4305 NO_STR
4306 NEIGHBOR_STR
4307 NEIGHBOR_ADDR_STR2
4308 "Per neighbor soft reconfiguration\n"
4309 "Allow inbound soft reconfiguration for this neighbor\n")
4310
718e3744 4311DEFUN (neighbor_route_reflector_client,
4312 neighbor_route_reflector_client_cmd,
9ccf14f7 4313 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4314 NEIGHBOR_STR
4315 NEIGHBOR_ADDR_STR2
4316 "Configure a neighbor as Route Reflector client\n")
4317{
c500ae40 4318 int idx_peer = 1;
718e3744 4319 struct peer *peer;
4320
4321
c500ae40 4322 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 4323 if (! peer)
4324 return CMD_WARNING;
4325
c500ae40 4326 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4327 bgp_node_safi (vty),
4328 PEER_FLAG_REFLECTOR_CLIENT);
4329}
4330
596c17ba
DW
4331ALIAS_HIDDEN (neighbor_route_reflector_client,
4332 neighbor_route_reflector_client_hidden_cmd,
4333 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4334 NEIGHBOR_STR
4335 NEIGHBOR_ADDR_STR2
4336 "Configure a neighbor as Route Reflector client\n")
4337
718e3744 4338DEFUN (no_neighbor_route_reflector_client,
4339 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4340 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4341 NO_STR
4342 NEIGHBOR_STR
4343 NEIGHBOR_ADDR_STR2
4344 "Configure a neighbor as Route Reflector client\n")
4345{
c500ae40
DW
4346 int idx_peer = 2;
4347 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4348 bgp_node_safi (vty),
4349 PEER_FLAG_REFLECTOR_CLIENT);
4350}
6b0655a2 4351
596c17ba
DW
4352ALIAS_HIDDEN (no_neighbor_route_reflector_client,
4353 no_neighbor_route_reflector_client_hidden_cmd,
4354 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4355 NO_STR
4356 NEIGHBOR_STR
4357 NEIGHBOR_ADDR_STR2
4358 "Configure a neighbor as Route Reflector client\n")
4359
718e3744 4360/* neighbor route-server-client. */
4361DEFUN (neighbor_route_server_client,
4362 neighbor_route_server_client_cmd,
9ccf14f7 4363 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4364 NEIGHBOR_STR
4365 NEIGHBOR_ADDR_STR2
4366 "Configure a neighbor as Route Server client\n")
4367{
c500ae40 4368 int idx_peer = 1;
2a3d5731
DW
4369 struct peer *peer;
4370
c500ae40 4371 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
2a3d5731
DW
4372 if (! peer)
4373 return CMD_WARNING;
c500ae40 4374 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
2a3d5731
DW
4375 bgp_node_safi (vty),
4376 PEER_FLAG_RSERVER_CLIENT);
718e3744 4377}
4378
596c17ba
DW
4379ALIAS_HIDDEN (neighbor_route_server_client,
4380 neighbor_route_server_client_hidden_cmd,
4381 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4382 NEIGHBOR_STR
4383 NEIGHBOR_ADDR_STR2
4384 "Configure a neighbor as Route Server client\n")
4385
718e3744 4386DEFUN (no_neighbor_route_server_client,
4387 no_neighbor_route_server_client_cmd,
9ccf14f7 4388 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4389 NO_STR
4390 NEIGHBOR_STR
4391 NEIGHBOR_ADDR_STR2
4392 "Configure a neighbor as Route Server client\n")
fee0f4c6 4393{
c500ae40
DW
4394 int idx_peer = 2;
4395 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
2a3d5731
DW
4396 bgp_node_safi (vty),
4397 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4398}
6b0655a2 4399
596c17ba
DW
4400ALIAS_HIDDEN (no_neighbor_route_server_client,
4401 no_neighbor_route_server_client_hidden_cmd,
4402 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4403 NO_STR
4404 NEIGHBOR_STR
4405 NEIGHBOR_ADDR_STR2
4406 "Configure a neighbor as Route Server client\n")
4407
fee0f4c6 4408DEFUN (neighbor_nexthop_local_unchanged,
4409 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4410 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4411 NEIGHBOR_STR
4412 NEIGHBOR_ADDR_STR2
4413 "Configure treatment of outgoing link-local nexthop attribute\n"
4414 "Leave link-local nexthop unchanged for this peer\n")
4415{
c500ae40
DW
4416 int idx_peer = 1;
4417 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
fee0f4c6 4418 bgp_node_safi (vty),
4419 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED );
4420}
6b0655a2 4421
fee0f4c6 4422DEFUN (no_neighbor_nexthop_local_unchanged,
4423 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4424 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4425 NO_STR
4426 NEIGHBOR_STR
4427 NEIGHBOR_ADDR_STR2
4428 "Configure treatment of outgoing link-local-nexthop attribute\n"
4429 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4430{
c500ae40
DW
4431 int idx_peer = 2;
4432 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4433 bgp_node_safi (vty),
fee0f4c6 4434 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED );
718e3744 4435}
6b0655a2 4436
718e3744 4437DEFUN (neighbor_attr_unchanged,
4438 neighbor_attr_unchanged_cmd,
1084263f
QY
4439 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged\
4440 [<\
ddbaf941
QY
4441 as-path [<next-hop [med]|med [next-hop]>]|\
4442 next-hop [<as-path [med]|med [as-path]>]|\
4443 med [<as-path [next-hop]|next-hop [as-path]>]\
1084263f 4444 >]",
718e3744 4445 NEIGHBOR_STR
4446 NEIGHBOR_ADDR_STR2
4447 "BGP attribute is propagated unchanged to this neighbor\n"
4448 "As-path attribute\n"
4449 "Nexthop attribute\n"
40e718b5 4450 "Med attribute\n"
1084263f
QY
4451 "Med attribute\n"
4452 "Nexthop attribute\n"
4453 "Nexthop attribute\n"
4454 "As-path attribute\n"
4455 "Med attribute\n"
40e718b5 4456 "Med attribute\n"
718e3744 4457 "As-path attribute\n"
1084263f
QY
4458 "Med attribute\n"
4459 "As-path attribute\n"
4460 "Nexthop attribute\n"
40e718b5 4461 "Nexthop attribute\n"
1084263f 4462 "As-path attribute\n")
718e3744 4463{
40e718b5
QY
4464 int idx = 0;
4465 char *peer = argv[1]->arg;
4466 u_int16_t flags = 0;
718e3744 4467
40e718b5 4468 if (argv_find (argv, argc, "as-path", &idx))
718e3744 4469 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
40e718b5
QY
4470 idx = 0;
4471 if (argv_find (argv, argc, "next-hop", &idx))
4472 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4473 idx = 0;
4474 if (argv_find (argv, argc, "med", &idx))
718e3744 4475 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4476
40e718b5
QY
4477 if (!flags) // no flags means all of them!
4478 {
718e3744 4479 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
718e3744 4480 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
40e718b5
QY
4481 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4482 }
718e3744 4483
40e718b5 4484 return peer_af_flag_set_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flags);
718e3744 4485}
4486
596c17ba
DW
4487ALIAS_HIDDEN (neighbor_attr_unchanged,
4488 neighbor_attr_unchanged_hidden_cmd,
4489 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged\
4490 [<\
4491 as-path [<next-hop [med]|med [next-hop]>]|\
4492 next-hop [<as-path [med]|med [as-path]>]|\
4493 med [<as-path [next-hop]|next-hop [as-path]>]\
4494 >]",
4495 NEIGHBOR_STR
4496 NEIGHBOR_ADDR_STR2
4497 "BGP attribute is propagated unchanged to this neighbor\n"
4498 "As-path attribute\n"
4499 "Nexthop attribute\n"
4500 "Med attribute\n"
4501 "Med attribute\n"
4502 "Nexthop attribute\n"
4503 "Nexthop attribute\n"
4504 "As-path attribute\n"
4505 "Med attribute\n"
4506 "Med attribute\n"
4507 "As-path attribute\n"
4508 "Med attribute\n"
4509 "As-path attribute\n"
4510 "Nexthop attribute\n"
4511 "Nexthop attribute\n"
4512 "As-path attribute\n")
4513
718e3744 4514DEFUN (no_neighbor_attr_unchanged,
4515 no_neighbor_attr_unchanged_cmd,
1084263f
QY
4516 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged\
4517 [<\
ddbaf941
QY
4518 as-path [<next-hop [med]|med [next-hop]>]|\
4519 next-hop [<as-path [med]|med [as-path]>]|\
4520 med [<as-path [next-hop]|next-hop [as-path]>]\
1084263f 4521 >]",
e52702f2 4522 NO_STR
718e3744 4523 NEIGHBOR_STR
4524 NEIGHBOR_ADDR_STR2
31500417
DW
4525 "BGP attribute is propagated unchanged to this neighbor\n"
4526 "As-path attribute\n"
40e718b5 4527 "Nexthop attribute\n"
31500417 4528 "Med attribute\n"
1084263f
QY
4529 "Med attribute\n"
4530 "Nexthop attribute\n"
4531 "Nexthop attribute\n"
4532 "As-path attribute\n"
4533 "Med attribute\n"
40e718b5 4534 "Med attribute\n"
718e3744 4535 "As-path attribute\n"
1084263f
QY
4536 "Med attribute\n"
4537 "As-path attribute\n"
4538 "Nexthop attribute\n"
718e3744 4539 "Nexthop attribute\n"
1084263f 4540 "As-path attribute\n")
718e3744 4541{
40e718b5
QY
4542 int idx = 0;
4543 char *peer = argv[2]->arg;
4544 u_int16_t flags = 0;
718e3744 4545
40e718b5 4546 if (argv_find (argv, argc, "as-path", &idx))
718e3744 4547 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
40e718b5
QY
4548 idx = 0;
4549 if (argv_find (argv, argc, "next-hop", &idx))
4550 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4551 idx = 0;
4552 if (argv_find (argv, argc, "med", &idx))
718e3744 4553 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4554
40e718b5
QY
4555 if (!flags) // no flags means all of them!
4556 {
718e3744 4557 SET_FLAG (flags, PEER_FLAG_AS_PATH_UNCHANGED);
718e3744 4558 SET_FLAG (flags, PEER_FLAG_NEXTHOP_UNCHANGED);
40e718b5
QY
4559 SET_FLAG (flags, PEER_FLAG_MED_UNCHANGED);
4560 }
718e3744 4561
40e718b5 4562 return peer_af_flag_unset_vty (vty, peer, bgp_node_afi (vty), bgp_node_safi (vty), flags);
718e3744 4563}
4564
596c17ba
DW
4565ALIAS_HIDDEN (no_neighbor_attr_unchanged,
4566 no_neighbor_attr_unchanged_hidden_cmd,
4567 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged\
4568 [<\
4569 as-path [<next-hop [med]|med [next-hop]>]|\
4570 next-hop [<as-path [med]|med [as-path]>]|\
4571 med [<as-path [next-hop]|next-hop [as-path]>]\
4572 >]",
4573 NO_STR
4574 NEIGHBOR_STR
4575 NEIGHBOR_ADDR_STR2
4576 "BGP attribute is propagated unchanged to this neighbor\n"
4577 "As-path attribute\n"
4578 "Nexthop attribute\n"
4579 "Med attribute\n"
4580 "Med attribute\n"
4581 "Nexthop attribute\n"
4582 "Nexthop attribute\n"
4583 "As-path attribute\n"
4584 "Med attribute\n"
4585 "Med attribute\n"
4586 "As-path attribute\n"
4587 "Med attribute\n"
4588 "As-path attribute\n"
4589 "Nexthop attribute\n"
4590 "Nexthop attribute\n"
4591 "As-path attribute\n")
4592
718e3744 4593
718e3744 4594/* EBGP multihop configuration. */
94f2b392 4595static int
e52702f2 4596peer_ebgp_multihop_set_vty (struct vty *vty, const char *ip_str,
fd79ac91 4597 const char *ttl_str)
718e3744 4598{
4599 struct peer *peer;
fd79ac91 4600 unsigned int ttl;
718e3744 4601
4602 peer = peer_and_group_lookup_vty (vty, ip_str);
4603 if (! peer)
4604 return CMD_WARNING;
4605
63fa10b5
QY
4606 if (peer->conf_if)
4607 return bgp_vty_return (vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
4608
718e3744 4609 if (! ttl_str)
9b1be336 4610 ttl = MAXTTL;
718e3744 4611 else
9b1be336 4612 VTY_GET_INTEGER_RANGE ("TTL", ttl, ttl_str, 1, MAXTTL);
718e3744 4613
89b6d1f8 4614 return bgp_vty_return (vty, peer_ebgp_multihop_set (peer, ttl));
718e3744 4615}
4616
94f2b392 4617static int
e52702f2 4618peer_ebgp_multihop_unset_vty (struct vty *vty, const char *ip_str)
718e3744 4619{
4620 struct peer *peer;
4621
4622 peer = peer_and_group_lookup_vty (vty, ip_str);
4623 if (! peer)
4624 return CMD_WARNING;
4625
89b6d1f8 4626 return bgp_vty_return (vty, peer_ebgp_multihop_unset (peer));
718e3744 4627}
4628
4629/* neighbor ebgp-multihop. */
4630DEFUN (neighbor_ebgp_multihop,
4631 neighbor_ebgp_multihop_cmd,
9ccf14f7 4632 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4633 NEIGHBOR_STR
4634 NEIGHBOR_ADDR_STR2
4635 "Allow EBGP neighbors not on directly connected networks\n")
4636{
c500ae40
DW
4637 int idx_peer = 1;
4638 return peer_ebgp_multihop_set_vty (vty, argv[idx_peer]->arg, NULL);
718e3744 4639}
4640
4641DEFUN (neighbor_ebgp_multihop_ttl,
4642 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4643 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4644 NEIGHBOR_STR
4645 NEIGHBOR_ADDR_STR2
4646 "Allow EBGP neighbors not on directly connected networks\n"
4647 "maximum hop count\n")
4648{
c500ae40
DW
4649 int idx_peer = 1;
4650 int idx_number = 3;
4651 return peer_ebgp_multihop_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg);
718e3744 4652}
4653
4654DEFUN (no_neighbor_ebgp_multihop,
4655 no_neighbor_ebgp_multihop_cmd,
a636c635 4656 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4657 NO_STR
4658 NEIGHBOR_STR
4659 NEIGHBOR_ADDR_STR2
a636c635
DW
4660 "Allow EBGP neighbors not on directly connected networks\n"
4661 "maximum hop count\n")
718e3744 4662{
c500ae40
DW
4663 int idx_peer = 2;
4664 return peer_ebgp_multihop_unset_vty (vty, argv[idx_peer]->arg);
718e3744 4665}
4666
6b0655a2 4667
6ffd2079 4668/* disable-connected-check */
4669DEFUN (neighbor_disable_connected_check,
4670 neighbor_disable_connected_check_cmd,
a636c635 4671 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4672 NEIGHBOR_STR
4673 NEIGHBOR_ADDR_STR2
a636c635
DW
4674 "one-hop away EBGP peer using loopback address\n"
4675 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4676{
c500ae40
DW
4677 int idx_peer = 1;
4678 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4679}
4680
4681DEFUN (no_neighbor_disable_connected_check,
4682 no_neighbor_disable_connected_check_cmd,
a636c635 4683 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4684 NO_STR
4685 NEIGHBOR_STR
4686 NEIGHBOR_ADDR_STR2
a636c635
DW
4687 "one-hop away EBGP peer using loopback address\n"
4688 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4689{
c500ae40
DW
4690 int idx_peer = 2;
4691 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4692}
4693
718e3744 4694DEFUN (neighbor_description,
4695 neighbor_description_cmd,
e961923c 4696 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4697 NEIGHBOR_STR
4698 NEIGHBOR_ADDR_STR2
4699 "Neighbor specific description\n"
4700 "Up to 80 characters describing this neighbor\n")
4701{
c500ae40 4702 int idx_peer = 1;
58749582 4703 int idx_line = 3;
718e3744 4704 struct peer *peer;
718e3744 4705 char *str;
718e3744 4706
c500ae40 4707 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 4708 if (! peer)
4709 return CMD_WARNING;
4710
58749582 4711 str = argv_concat(argv, argc, idx_line);
718e3744 4712
4713 peer_description_set (peer, str);
4714
3b8b1855 4715 XFREE (MTYPE_TMP, str);
718e3744 4716
4717 return CMD_SUCCESS;
4718}
4719
4720DEFUN (no_neighbor_description,
4721 no_neighbor_description_cmd,
a636c635 4722 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4723 NO_STR
4724 NEIGHBOR_STR
4725 NEIGHBOR_ADDR_STR2
a636c635
DW
4726 "Neighbor specific description\n"
4727 "Up to 80 characters describing this neighbor\n")
718e3744 4728{
c500ae40 4729 int idx_peer = 2;
718e3744 4730 struct peer *peer;
4731
c500ae40 4732 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 4733 if (! peer)
4734 return CMD_WARNING;
4735
4736 peer_description_unset (peer);
4737
4738 return CMD_SUCCESS;
4739}
4740
6b0655a2 4741
718e3744 4742/* Neighbor update-source. */
94f2b392 4743static int
e52702f2 4744peer_update_source_vty (struct vty *vty, const char *peer_str,
fd79ac91 4745 const char *source_str)
718e3744 4746{
4747 struct peer *peer;
3b69fd51 4748 struct prefix p;
718e3744 4749
4750 peer = peer_and_group_lookup_vty (vty, peer_str);
4751 if (! peer)
4752 return CMD_WARNING;
4753
a80beece
DS
4754 if (peer->conf_if)
4755 return CMD_WARNING;
4756
718e3744 4757 if (source_str)
4758 {
c63b83fe
JBD
4759 union sockunion su;
4760 int ret = str2sockunion (source_str, &su);
4761
4762 if (ret == 0)
4763 peer_update_source_addr_set (peer, &su);
718e3744 4764 else
3b69fd51
DS
4765 {
4766 if (str2prefix (source_str, &p))
4767 {
4768 vty_out (vty, "%% Invalid update-source, remove prefix length %s",
4769 VTY_NEWLINE);
4770 return CMD_WARNING;
4771 }
4772 else
4773 peer_update_source_if_set (peer, source_str);
4774 }
718e3744 4775 }
4776 else
4777 peer_update_source_unset (peer);
4778
4779 return CMD_SUCCESS;
4780}
4781
369688c0
PJ
4782#define BGP_UPDATE_SOURCE_HELP_STR \
4783 "IPv4 address\n" \
9a1a331d
PJ
4784 "IPv6 address\n" \
4785 "Interface name (requires zebra to be running)\n"
369688c0 4786
718e3744 4787DEFUN (neighbor_update_source,
4788 neighbor_update_source_cmd,
9ccf14f7 4789 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4790 NEIGHBOR_STR
4791 NEIGHBOR_ADDR_STR2
4792 "Source of routing updates\n"
369688c0 4793 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4794{
c500ae40
DW
4795 int idx_peer = 1;
4796 int idx_peer_2 = 3;
4797 return peer_update_source_vty (vty, argv[idx_peer]->arg, argv[idx_peer_2]->arg);
718e3744 4798}
4799
4800DEFUN (no_neighbor_update_source,
4801 no_neighbor_update_source_cmd,
c7178fe7 4802 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4803 NO_STR
4804 NEIGHBOR_STR
4805 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4806 "Source of routing updates\n"
4807 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4808{
c500ae40
DW
4809 int idx_peer = 2;
4810 return peer_update_source_vty (vty, argv[idx_peer]->arg, NULL);
718e3744 4811}
6b0655a2 4812
94f2b392 4813static int
e52702f2
QY
4814peer_default_originate_set_vty (struct vty *vty, const char *peer_str,
4815 afi_t afi, safi_t safi,
fd79ac91 4816 const char *rmap, int set)
718e3744 4817{
4818 int ret;
4819 struct peer *peer;
4820
4821 peer = peer_and_group_lookup_vty (vty, peer_str);
4822 if (! peer)
4823 return CMD_WARNING;
4824
4825 if (set)
4826 ret = peer_default_originate_set (peer, afi, safi, rmap);
4827 else
4828 ret = peer_default_originate_unset (peer, afi, safi);
4829
4830 return bgp_vty_return (vty, ret);
4831}
4832
4833/* neighbor default-originate. */
4834DEFUN (neighbor_default_originate,
4835 neighbor_default_originate_cmd,
9ccf14f7 4836 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4837 NEIGHBOR_STR
4838 NEIGHBOR_ADDR_STR2
4839 "Originate default route to this neighbor\n")
4840{
c500ae40
DW
4841 int idx_peer = 1;
4842 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4843 bgp_node_safi (vty), NULL, 1);
4844}
4845
596c17ba
DW
4846ALIAS_HIDDEN (neighbor_default_originate,
4847 neighbor_default_originate_hidden_cmd,
4848 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4849 NEIGHBOR_STR
4850 NEIGHBOR_ADDR_STR2
4851 "Originate default route to this neighbor\n")
4852
718e3744 4853DEFUN (neighbor_default_originate_rmap,
4854 neighbor_default_originate_rmap_cmd,
9ccf14f7 4855 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4856 NEIGHBOR_STR
4857 NEIGHBOR_ADDR_STR2
4858 "Originate default route to this neighbor\n"
4859 "Route-map to specify criteria to originate default\n"
4860 "route-map name\n")
4861{
c500ae40
DW
4862 int idx_peer = 1;
4863 int idx_word = 4;
4864 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
4865 bgp_node_safi (vty), argv[idx_word]->arg, 1);
718e3744 4866}
4867
596c17ba
DW
4868ALIAS_HIDDEN (neighbor_default_originate_rmap,
4869 neighbor_default_originate_rmap_hidden_cmd,
4870 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4871 NEIGHBOR_STR
4872 NEIGHBOR_ADDR_STR2
4873 "Originate default route to this neighbor\n"
4874 "Route-map to specify criteria to originate default\n"
4875 "route-map name\n")
4876
718e3744 4877DEFUN (no_neighbor_default_originate,
4878 no_neighbor_default_originate_cmd,
a636c635 4879 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4880 NO_STR
4881 NEIGHBOR_STR
4882 NEIGHBOR_ADDR_STR2
a636c635
DW
4883 "Originate default route to this neighbor\n"
4884 "Route-map to specify criteria to originate default\n"
4885 "route-map name\n")
718e3744 4886{
c500ae40
DW
4887 int idx_peer = 2;
4888 return peer_default_originate_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 4889 bgp_node_safi (vty), NULL, 0);
4890}
4891
596c17ba
DW
4892ALIAS_HIDDEN (no_neighbor_default_originate,
4893 no_neighbor_default_originate_hidden_cmd,
4894 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4895 NO_STR
4896 NEIGHBOR_STR
4897 NEIGHBOR_ADDR_STR2
4898 "Originate default route to this neighbor\n"
4899 "Route-map to specify criteria to originate default\n"
4900 "route-map name\n")
4901
6b0655a2 4902
718e3744 4903/* Set neighbor's BGP port. */
94f2b392 4904static int
e52702f2 4905peer_port_vty (struct vty *vty, const char *ip_str, int afi,
fd79ac91 4906 const char *port_str)
718e3744 4907{
4908 struct peer *peer;
4909 u_int16_t port;
4910 struct servent *sp;
4911
4912 peer = peer_lookup_vty (vty, ip_str);
4913 if (! peer)
4914 return CMD_WARNING;
4915
4916 if (! port_str)
e52702f2 4917 {
718e3744 4918 sp = getservbyname ("bgp", "tcp");
4919 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs (sp->s_port);
4920 }
4921 else
4922 {
4923 VTY_GET_INTEGER("port", port, port_str);
4924 }
4925
4926 peer_port_set (peer, port);
4927
4928 return CMD_SUCCESS;
4929}
4930
f418446b 4931/* Set specified peer's BGP port. */
718e3744 4932DEFUN (neighbor_port,
4933 neighbor_port_cmd,
9ccf14f7 4934 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4935 NEIGHBOR_STR
4936 NEIGHBOR_ADDR_STR
4937 "Neighbor's BGP port\n"
4938 "TCP port number\n")
4939{
c500ae40
DW
4940 int idx_ip = 1;
4941 int idx_number = 3;
4942 return peer_port_vty (vty, argv[idx_ip]->arg, AFI_IP, argv[idx_number]->arg);
718e3744 4943}
4944
4945DEFUN (no_neighbor_port,
4946 no_neighbor_port_cmd,
9ccf14f7 4947 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4948 NO_STR
4949 NEIGHBOR_STR
4950 NEIGHBOR_ADDR_STR
8334fd5a
DW
4951 "Neighbor's BGP port\n"
4952 "TCP port number\n")
718e3744 4953{
c500ae40
DW
4954 int idx_ip = 2;
4955 return peer_port_vty (vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4956}
4957
6b0655a2 4958
718e3744 4959/* neighbor weight. */
94f2b392 4960static int
e52702f2 4961peer_weight_set_vty (struct vty *vty, const char *ip_str,
d93f7ffc 4962 afi_t afi, safi_t safi,
fd79ac91 4963 const char *weight_str)
718e3744 4964{
1f9a9fff 4965 int ret;
718e3744 4966 struct peer *peer;
4967 unsigned long weight;
4968
4969 peer = peer_and_group_lookup_vty (vty, ip_str);
4970 if (! peer)
4971 return CMD_WARNING;
4972
4973 VTY_GET_INTEGER_RANGE("weight", weight, weight_str, 0, 65535);
4974
d93f7ffc 4975 ret = peer_weight_set (peer, afi, safi, weight);
1f9a9fff 4976 return bgp_vty_return (vty, ret);
718e3744 4977}
4978
94f2b392 4979static int
d93f7ffc
DW
4980peer_weight_unset_vty (struct vty *vty, const char *ip_str,
4981 afi_t afi, safi_t safi)
718e3744 4982{
1f9a9fff 4983 int ret;
718e3744 4984 struct peer *peer;
4985
4986 peer = peer_and_group_lookup_vty (vty, ip_str);
4987 if (! peer)
4988 return CMD_WARNING;
4989
d93f7ffc 4990 ret = peer_weight_unset (peer, afi, safi);
1f9a9fff 4991 return bgp_vty_return (vty, ret);
718e3744 4992}
4993
4994DEFUN (neighbor_weight,
4995 neighbor_weight_cmd,
9ccf14f7 4996 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4997 NEIGHBOR_STR
4998 NEIGHBOR_ADDR_STR2
4999 "Set default weight for routes from this neighbor\n"
5000 "default weight\n")
5001{
c500ae40
DW
5002 int idx_peer = 1;
5003 int idx_number = 3;
e52702f2
QY
5004 return peer_weight_set_vty (vty,
5005 argv[idx_peer]->arg,
5006 bgp_node_afi (vty),
5007 bgp_node_safi (vty),
5008 argv[idx_number]->arg);
718e3744 5009}
5010
596c17ba
DW
5011ALIAS_HIDDEN (neighbor_weight,
5012 neighbor_weight_hidden_cmd,
5013 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
5014 NEIGHBOR_STR
5015 NEIGHBOR_ADDR_STR2
5016 "Set default weight for routes from this neighbor\n"
5017 "default weight\n")
5018
718e3744 5019DEFUN (no_neighbor_weight,
5020 no_neighbor_weight_cmd,
9ccf14f7 5021 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 5022 NO_STR
5023 NEIGHBOR_STR
5024 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5025 "Set default weight for routes from this neighbor\n"
5026 "default weight\n")
718e3744 5027{
c500ae40 5028 int idx_peer = 2;
e52702f2 5029 return peer_weight_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty), bgp_node_safi (vty));
718e3744 5030}
5031
596c17ba
DW
5032ALIAS_HIDDEN (no_neighbor_weight,
5033 no_neighbor_weight_hidden_cmd,
5034 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
5035 NO_STR
5036 NEIGHBOR_STR
5037 NEIGHBOR_ADDR_STR2
5038 "Set default weight for routes from this neighbor\n"
5039 "default weight\n")
5040
6b0655a2 5041
718e3744 5042/* Override capability negotiation. */
5043DEFUN (neighbor_override_capability,
5044 neighbor_override_capability_cmd,
9ccf14f7 5045 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5046 NEIGHBOR_STR
5047 NEIGHBOR_ADDR_STR2
5048 "Override capability negotiation result\n")
5049{
c500ae40
DW
5050 int idx_peer = 1;
5051 return peer_flag_set_vty (vty, argv[idx_peer]->arg, PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5052}
5053
5054DEFUN (no_neighbor_override_capability,
5055 no_neighbor_override_capability_cmd,
9ccf14f7 5056 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 5057 NO_STR
5058 NEIGHBOR_STR
5059 NEIGHBOR_ADDR_STR2
5060 "Override capability negotiation result\n")
5061{
c500ae40
DW
5062 int idx_peer = 2;
5063 return peer_flag_unset_vty (vty, argv[idx_peer]->arg, PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 5064}
6b0655a2 5065
718e3744 5066DEFUN (neighbor_strict_capability,
5067 neighbor_strict_capability_cmd,
9ccf14f7 5068 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 5069 NEIGHBOR_STR
5070 NEIGHBOR_ADDR_STR
5071 "Strict capability negotiation match\n")
5072{
c500ae40
DW
5073 int idx_ip = 1;
5074 return peer_flag_set_vty (vty, argv[idx_ip]->arg, PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5075}
5076
5077DEFUN (no_neighbor_strict_capability,
5078 no_neighbor_strict_capability_cmd,
9ccf14f7 5079 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 5080 NO_STR
5081 NEIGHBOR_STR
5082 NEIGHBOR_ADDR_STR
5083 "Strict capability negotiation match\n")
5084{
c500ae40
DW
5085 int idx_ip = 2;
5086 return peer_flag_unset_vty (vty, argv[idx_ip]->arg, PEER_FLAG_STRICT_CAP_MATCH);
718e3744 5087}
6b0655a2 5088
94f2b392 5089static int
e52702f2 5090peer_timers_set_vty (struct vty *vty, const char *ip_str,
fd79ac91 5091 const char *keep_str, const char *hold_str)
718e3744 5092{
5093 int ret;
5094 struct peer *peer;
5095 u_int32_t keepalive;
5096 u_int32_t holdtime;
5097
5098 peer = peer_and_group_lookup_vty (vty, ip_str);
5099 if (! peer)
5100 return CMD_WARNING;
5101
5102 VTY_GET_INTEGER_RANGE ("Keepalive", keepalive, keep_str, 0, 65535);
5103 VTY_GET_INTEGER_RANGE ("Holdtime", holdtime, hold_str, 0, 65535);
5104
5105 ret = peer_timers_set (peer, keepalive, holdtime);
5106
5107 return bgp_vty_return (vty, ret);
5108}
6b0655a2 5109
94f2b392 5110static int
fd79ac91 5111peer_timers_unset_vty (struct vty *vty, const char *ip_str)
718e3744 5112{
5113 int ret;
5114 struct peer *peer;
5115
0c412461 5116 peer = peer_and_group_lookup_vty (vty, ip_str);
718e3744 5117 if (! peer)
5118 return CMD_WARNING;
5119
5120 ret = peer_timers_unset (peer);
5121
5122 return bgp_vty_return (vty, ret);
5123}
5124
5125DEFUN (neighbor_timers,
5126 neighbor_timers_cmd,
9ccf14f7 5127 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 5128 NEIGHBOR_STR
5129 NEIGHBOR_ADDR_STR2
5130 "BGP per neighbor timers\n"
5131 "Keepalive interval\n"
5132 "Holdtime\n")
5133{
c500ae40
DW
5134 int idx_peer = 1;
5135 int idx_number = 3;
5136 int idx_number_2 = 4;
5137 return peer_timers_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg, argv[idx_number_2]->arg);
718e3744 5138}
5139
5140DEFUN (no_neighbor_timers,
5141 no_neighbor_timers_cmd,
9ccf14f7 5142 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 5143 NO_STR
5144 NEIGHBOR_STR
5145 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5146 "BGP per neighbor timers\n"
5147 "Keepalive interval\n"
5148 "Holdtime\n")
718e3744 5149{
c500ae40
DW
5150 int idx_peer = 2;
5151 return peer_timers_unset_vty (vty, argv[idx_peer]->arg);
718e3744 5152}
6b0655a2 5153
813d4307 5154
94f2b392 5155static int
e52702f2 5156peer_timers_connect_set_vty (struct vty *vty, const char *ip_str,
fd79ac91 5157 const char *time_str)
718e3744 5158{
5159 int ret;
5160 struct peer *peer;
5161 u_int32_t connect;
5162
966f821c 5163 peer = peer_and_group_lookup_vty (vty, ip_str);
718e3744 5164 if (! peer)
5165 return CMD_WARNING;
5166
5167 VTY_GET_INTEGER_RANGE ("Connect time", connect, time_str, 0, 65535);
5168
5169 ret = peer_timers_connect_set (peer, connect);
5170
966f821c 5171 return bgp_vty_return (vty, ret);
718e3744 5172}
5173
94f2b392 5174static int
fd79ac91 5175peer_timers_connect_unset_vty (struct vty *vty, const char *ip_str)
718e3744 5176{
5177 int ret;
5178 struct peer *peer;
5179
5180 peer = peer_and_group_lookup_vty (vty, ip_str);
5181 if (! peer)
5182 return CMD_WARNING;
5183
5184 ret = peer_timers_connect_unset (peer);
5185
966f821c 5186 return bgp_vty_return (vty, ret);
718e3744 5187}
5188
5189DEFUN (neighbor_timers_connect,
5190 neighbor_timers_connect_cmd,
9ccf14f7 5191 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5192 NEIGHBOR_STR
966f821c 5193 NEIGHBOR_ADDR_STR2
718e3744 5194 "BGP per neighbor timers\n"
5195 "BGP connect timer\n"
5196 "Connect timer\n")
5197{
c500ae40
DW
5198 int idx_peer = 1;
5199 int idx_number = 4;
5200 return peer_timers_connect_set_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg);
718e3744 5201}
5202
5203DEFUN (no_neighbor_timers_connect,
5204 no_neighbor_timers_connect_cmd,
9ccf14f7 5205 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5206 NO_STR
5207 NEIGHBOR_STR
966f821c 5208 NEIGHBOR_ADDR_STR2
718e3744 5209 "BGP per neighbor timers\n"
8334fd5a
DW
5210 "BGP connect timer\n"
5211 "Connect timer\n")
718e3744 5212{
c500ae40
DW
5213 int idx_peer = 2;
5214 return peer_timers_connect_unset_vty (vty, argv[idx_peer]->arg);
718e3744 5215}
5216
6b0655a2 5217
94f2b392 5218static int
e52702f2
QY
5219peer_advertise_interval_vty (struct vty *vty, const char *ip_str,
5220 const char *time_str, int set)
718e3744 5221{
5222 int ret;
5223 struct peer *peer;
5224 u_int32_t routeadv = 0;
5225
966f821c 5226 peer = peer_and_group_lookup_vty (vty, ip_str);
718e3744 5227 if (! peer)
5228 return CMD_WARNING;
5229
5230 if (time_str)
5231 VTY_GET_INTEGER_RANGE ("advertise interval", routeadv, time_str, 0, 600);
5232
5233 if (set)
5234 ret = peer_advertise_interval_set (peer, routeadv);
5235 else
5236 ret = peer_advertise_interval_unset (peer);
5237
966f821c 5238 return bgp_vty_return (vty, ret);
718e3744 5239}
5240
5241DEFUN (neighbor_advertise_interval,
5242 neighbor_advertise_interval_cmd,
9ccf14f7 5243 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5244 NEIGHBOR_STR
966f821c 5245 NEIGHBOR_ADDR_STR2
718e3744 5246 "Minimum interval between sending BGP routing updates\n"
5247 "time in seconds\n")
5248{
c500ae40
DW
5249 int idx_peer = 1;
5250 int idx_number = 3;
5251 return peer_advertise_interval_vty (vty, argv[idx_peer]->arg, argv[idx_number]->arg, 1);
718e3744 5252}
5253
5254DEFUN (no_neighbor_advertise_interval,
5255 no_neighbor_advertise_interval_cmd,
9ccf14f7 5256 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5257 NO_STR
5258 NEIGHBOR_STR
966f821c 5259 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5260 "Minimum interval between sending BGP routing updates\n"
5261 "time in seconds\n")
718e3744 5262{
c500ae40
DW
5263 int idx_peer = 2;
5264 return peer_advertise_interval_vty (vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5265}
5266
6b0655a2 5267
518f0eb1
DS
5268/* Time to wait before processing route-map updates */
5269DEFUN (bgp_set_route_map_delay_timer,
5270 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5271 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5272 SET_STR
5273 "BGP route-map delay timer\n"
5274 "Time in secs to wait before processing route-map changes\n"
f414725f 5275 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5276{
c500ae40 5277 int idx_number = 3;
518f0eb1 5278 u_int32_t rmap_delay_timer;
518f0eb1 5279
c500ae40 5280 if (argv[idx_number]->arg)
518f0eb1 5281 {
c500ae40 5282 VTY_GET_INTEGER_RANGE ("delay-timer", rmap_delay_timer, argv[idx_number]->arg, 0, 600);
5fe9f963 5283 bm->rmap_update_timer = rmap_delay_timer;
518f0eb1
DS
5284
5285 /* if the dynamic update handling is being disabled, and a timer is
5286 * running, stop the timer and act as if the timer has already fired.
5287 */
5fe9f963 5288 if (!rmap_delay_timer && bm->t_rmap_update )
518f0eb1 5289 {
5fe9f963 5290 BGP_TIMER_OFF(bm->t_rmap_update);
5291 thread_execute (bm->master, bgp_route_map_update_timer, NULL, 0);
518f0eb1
DS
5292 }
5293 return CMD_SUCCESS;
5294 }
5295 else
ffd0c037 5296 return CMD_WARNING;
518f0eb1
DS
5297}
5298
5299DEFUN (no_bgp_set_route_map_delay_timer,
5300 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5301 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5302 NO_STR
3a2d747c 5303 BGP_STR
518f0eb1 5304 "Default BGP route-map delay timer\n"
8334fd5a
DW
5305 "Reset to default time to wait for processing route-map changes\n"
5306 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5307{
518f0eb1 5308
5fe9f963 5309 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1
DS
5310
5311 return CMD_SUCCESS;
5312}
5313
f414725f 5314
718e3744 5315/* neighbor interface */
94f2b392 5316static int
fd79ac91 5317peer_interface_vty (struct vty *vty, const char *ip_str, const char *str)
718e3744 5318{
718e3744 5319 struct peer *peer;
5320
5321 peer = peer_lookup_vty (vty, ip_str);
a80beece 5322 if (! peer || peer->conf_if)
718e3744 5323 return CMD_WARNING;
5324
5325 if (str)
ffd0c037 5326 peer_interface_set (peer, str);
718e3744 5327 else
ffd0c037 5328 peer_interface_unset (peer);
718e3744 5329
5330 return CMD_SUCCESS;
5331}
5332
5333DEFUN (neighbor_interface,
5334 neighbor_interface_cmd,
9ccf14f7 5335 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5336 NEIGHBOR_STR
5337 NEIGHBOR_ADDR_STR
5338 "Interface\n"
5339 "Interface name\n")
5340{
c500ae40
DW
5341 int idx_ip = 1;
5342 int idx_word = 3;
00d7d2d3 5343 return peer_interface_vty (vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5344}
5345
5346DEFUN (no_neighbor_interface,
5347 no_neighbor_interface_cmd,
9ccf14f7 5348 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5349 NO_STR
5350 NEIGHBOR_STR
16cedbb0 5351 NEIGHBOR_ADDR_STR2
718e3744 5352 "Interface\n"
5353 "Interface name\n")
5354{
c500ae40
DW
5355 int idx_peer = 2;
5356 return peer_interface_vty (vty, argv[idx_peer]->arg, NULL);
718e3744 5357}
6b0655a2 5358
718e3744 5359/* Set distribute list to the peer. */
94f2b392 5360static int
e52702f2 5361peer_distribute_set_vty (struct vty *vty, const char *ip_str,
fd79ac91 5362 afi_t afi, safi_t safi,
5363 const char *name_str, const char *direct_str)
718e3744 5364{
5365 int ret;
5366 struct peer *peer;
5367 int direct = FILTER_IN;
5368
5369 peer = peer_and_group_lookup_vty (vty, ip_str);
5370 if (! peer)
5371 return CMD_WARNING;
5372
5373 /* Check filter direction. */
5374 if (strncmp (direct_str, "i", 1) == 0)
5375 direct = FILTER_IN;
5376 else if (strncmp (direct_str, "o", 1) == 0)
5377 direct = FILTER_OUT;
5378
5379 ret = peer_distribute_set (peer, afi, safi, direct, name_str);
5380
5381 return bgp_vty_return (vty, ret);
5382}
5383
94f2b392 5384static int
fd79ac91 5385peer_distribute_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5386 safi_t safi, const char *direct_str)
718e3744 5387{
5388 int ret;
5389 struct peer *peer;
5390 int direct = FILTER_IN;
5391
5392 peer = peer_and_group_lookup_vty (vty, ip_str);
5393 if (! peer)
5394 return CMD_WARNING;
5395
5396 /* Check filter direction. */
5397 if (strncmp (direct_str, "i", 1) == 0)
5398 direct = FILTER_IN;
5399 else if (strncmp (direct_str, "o", 1) == 0)
5400 direct = FILTER_OUT;
5401
5402 ret = peer_distribute_unset (peer, afi, safi, direct);
5403
5404 return bgp_vty_return (vty, ret);
5405}
5406
5407DEFUN (neighbor_distribute_list,
5408 neighbor_distribute_list_cmd,
9ccf14f7 5409 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5410 NEIGHBOR_STR
5411 NEIGHBOR_ADDR_STR2
5412 "Filter updates to/from this neighbor\n"
5413 "IP access-list number\n"
5414 "IP access-list number (expanded range)\n"
5415 "IP Access-list name\n"
5416 "Filter incoming updates\n"
5417 "Filter outgoing updates\n")
5418{
c500ae40
DW
5419 int idx_peer = 1;
5420 int idx_acl = 3;
5421 int idx_in_out = 4;
5422 return peer_distribute_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5423 bgp_node_safi (vty), argv[idx_acl]->arg, argv[idx_in_out]->arg);
718e3744 5424}
5425
596c17ba
DW
5426ALIAS_HIDDEN (neighbor_distribute_list,
5427 neighbor_distribute_list_hidden_cmd,
5428 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5429 NEIGHBOR_STR
5430 NEIGHBOR_ADDR_STR2
5431 "Filter updates to/from this neighbor\n"
5432 "IP access-list number\n"
5433 "IP access-list number (expanded range)\n"
5434 "IP Access-list name\n"
5435 "Filter incoming updates\n"
5436 "Filter outgoing updates\n")
5437
718e3744 5438DEFUN (no_neighbor_distribute_list,
5439 no_neighbor_distribute_list_cmd,
9ccf14f7 5440 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5441 NO_STR
5442 NEIGHBOR_STR
5443 NEIGHBOR_ADDR_STR2
5444 "Filter updates to/from this neighbor\n"
5445 "IP access-list number\n"
5446 "IP access-list number (expanded range)\n"
5447 "IP Access-list name\n"
5448 "Filter incoming updates\n"
5449 "Filter outgoing updates\n")
5450{
c500ae40
DW
5451 int idx_peer = 2;
5452 int idx_in_out = 5;
5453 return peer_distribute_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5454 bgp_node_safi (vty), argv[idx_in_out]->arg);
718e3744 5455}
6b0655a2 5456
596c17ba
DW
5457ALIAS_HIDDEN (no_neighbor_distribute_list,
5458 no_neighbor_distribute_list_hidden_cmd,
5459 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5460 NO_STR
5461 NEIGHBOR_STR
5462 NEIGHBOR_ADDR_STR2
5463 "Filter updates to/from this neighbor\n"
5464 "IP access-list number\n"
5465 "IP access-list number (expanded range)\n"
5466 "IP Access-list name\n"
5467 "Filter incoming updates\n"
5468 "Filter outgoing updates\n")
5469
718e3744 5470/* Set prefix list to the peer. */
94f2b392 5471static int
fd79ac91 5472peer_prefix_list_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
e52702f2 5473 safi_t safi, const char *name_str,
fd79ac91 5474 const char *direct_str)
718e3744 5475{
5476 int ret;
5477 struct peer *peer;
5478 int direct = FILTER_IN;
5479
5480 peer = peer_and_group_lookup_vty (vty, ip_str);
5481 if (! peer)
5482 return CMD_WARNING;
5483
5484 /* Check filter direction. */
5485 if (strncmp (direct_str, "i", 1) == 0)
5486 direct = FILTER_IN;
5487 else if (strncmp (direct_str, "o", 1) == 0)
5488 direct = FILTER_OUT;
5489
5490 ret = peer_prefix_list_set (peer, afi, safi, direct, name_str);
5491
5492 return bgp_vty_return (vty, ret);
5493}
5494
94f2b392 5495static int
fd79ac91 5496peer_prefix_list_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5497 safi_t safi, const char *direct_str)
718e3744 5498{
5499 int ret;
5500 struct peer *peer;
5501 int direct = FILTER_IN;
5502
5503 peer = peer_and_group_lookup_vty (vty, ip_str);
5504 if (! peer)
5505 return CMD_WARNING;
e52702f2 5506
718e3744 5507 /* Check filter direction. */
5508 if (strncmp (direct_str, "i", 1) == 0)
5509 direct = FILTER_IN;
5510 else if (strncmp (direct_str, "o", 1) == 0)
5511 direct = FILTER_OUT;
5512
5513 ret = peer_prefix_list_unset (peer, afi, safi, direct);
5514
5515 return bgp_vty_return (vty, ret);
5516}
5517
5518DEFUN (neighbor_prefix_list,
5519 neighbor_prefix_list_cmd,
9ccf14f7 5520 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5521 NEIGHBOR_STR
5522 NEIGHBOR_ADDR_STR2
5523 "Filter updates to/from this neighbor\n"
5524 "Name of a prefix list\n"
5525 "Filter incoming updates\n"
5526 "Filter outgoing updates\n")
5527{
c500ae40
DW
5528 int idx_peer = 1;
5529 int idx_word = 3;
5530 int idx_in_out = 4;
5531 return peer_prefix_list_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5532 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5533}
5534
596c17ba
DW
5535ALIAS_HIDDEN (neighbor_prefix_list,
5536 neighbor_prefix_list_hidden_cmd,
5537 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5538 NEIGHBOR_STR
5539 NEIGHBOR_ADDR_STR2
5540 "Filter updates to/from this neighbor\n"
5541 "Name of a prefix list\n"
5542 "Filter incoming updates\n"
5543 "Filter outgoing updates\n")
5544
718e3744 5545DEFUN (no_neighbor_prefix_list,
5546 no_neighbor_prefix_list_cmd,
9ccf14f7 5547 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5548 NO_STR
5549 NEIGHBOR_STR
5550 NEIGHBOR_ADDR_STR2
5551 "Filter updates to/from this neighbor\n"
5552 "Name of a prefix list\n"
5553 "Filter incoming updates\n"
5554 "Filter outgoing updates\n")
5555{
c500ae40
DW
5556 int idx_peer = 2;
5557 int idx_in_out = 5;
5558 return peer_prefix_list_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5559 bgp_node_safi (vty), argv[idx_in_out]->arg);
718e3744 5560}
6b0655a2 5561
596c17ba
DW
5562ALIAS_HIDDEN (no_neighbor_prefix_list,
5563 no_neighbor_prefix_list_hidden_cmd,
5564 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5565 NO_STR
5566 NEIGHBOR_STR
5567 NEIGHBOR_ADDR_STR2
5568 "Filter updates to/from this neighbor\n"
5569 "Name of a prefix list\n"
5570 "Filter incoming updates\n"
5571 "Filter outgoing updates\n")
5572
94f2b392 5573static int
e52702f2 5574peer_aslist_set_vty (struct vty *vty, const char *ip_str,
fd79ac91 5575 afi_t afi, safi_t safi,
5576 const char *name_str, const char *direct_str)
718e3744 5577{
5578 int ret;
5579 struct peer *peer;
5580 int direct = FILTER_IN;
5581
5582 peer = peer_and_group_lookup_vty (vty, ip_str);
5583 if (! peer)
5584 return CMD_WARNING;
5585
5586 /* Check filter direction. */
5587 if (strncmp (direct_str, "i", 1) == 0)
5588 direct = FILTER_IN;
5589 else if (strncmp (direct_str, "o", 1) == 0)
5590 direct = FILTER_OUT;
5591
5592 ret = peer_aslist_set (peer, afi, safi, direct, name_str);
5593
5594 return bgp_vty_return (vty, ret);
5595}
5596
94f2b392 5597static int
e52702f2 5598peer_aslist_unset_vty (struct vty *vty, const char *ip_str,
fd79ac91 5599 afi_t afi, safi_t safi,
5600 const char *direct_str)
718e3744 5601{
5602 int ret;
5603 struct peer *peer;
5604 int direct = FILTER_IN;
5605
5606 peer = peer_and_group_lookup_vty (vty, ip_str);
5607 if (! peer)
5608 return CMD_WARNING;
5609
5610 /* Check filter direction. */
5611 if (strncmp (direct_str, "i", 1) == 0)
5612 direct = FILTER_IN;
5613 else if (strncmp (direct_str, "o", 1) == 0)
5614 direct = FILTER_OUT;
5615
5616 ret = peer_aslist_unset (peer, afi, safi, direct);
5617
5618 return bgp_vty_return (vty, ret);
5619}
5620
5621DEFUN (neighbor_filter_list,
5622 neighbor_filter_list_cmd,
9ccf14f7 5623 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5624 NEIGHBOR_STR
5625 NEIGHBOR_ADDR_STR2
5626 "Establish BGP filters\n"
5627 "AS path access-list name\n"
5628 "Filter incoming routes\n"
5629 "Filter outgoing routes\n")
5630{
c500ae40
DW
5631 int idx_peer = 1;
5632 int idx_word = 3;
5633 int idx_in_out = 4;
5634 return peer_aslist_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5635 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5636}
5637
596c17ba
DW
5638ALIAS_HIDDEN (neighbor_filter_list,
5639 neighbor_filter_list_hidden_cmd,
5640 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5641 NEIGHBOR_STR
5642 NEIGHBOR_ADDR_STR2
5643 "Establish BGP filters\n"
5644 "AS path access-list name\n"
5645 "Filter incoming routes\n"
5646 "Filter outgoing routes\n")
5647
718e3744 5648DEFUN (no_neighbor_filter_list,
5649 no_neighbor_filter_list_cmd,
9ccf14f7 5650 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5651 NO_STR
5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Establish BGP filters\n"
5655 "AS path access-list name\n"
5656 "Filter incoming routes\n"
5657 "Filter outgoing routes\n")
5658{
c500ae40
DW
5659 int idx_peer = 2;
5660 int idx_in_out = 5;
5661 return peer_aslist_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5662 bgp_node_safi (vty), argv[idx_in_out]->arg);
718e3744 5663}
6b0655a2 5664
596c17ba
DW
5665ALIAS_HIDDEN (no_neighbor_filter_list,
5666 no_neighbor_filter_list_hidden_cmd,
5667 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5668 NO_STR
5669 NEIGHBOR_STR
5670 NEIGHBOR_ADDR_STR2
5671 "Establish BGP filters\n"
5672 "AS path access-list name\n"
5673 "Filter incoming routes\n"
5674 "Filter outgoing routes\n")
5675
718e3744 5676/* Set route-map to the peer. */
94f2b392 5677static int
e52702f2 5678peer_route_map_set_vty (struct vty *vty, const char *ip_str,
fd79ac91 5679 afi_t afi, safi_t safi,
5680 const char *name_str, const char *direct_str)
718e3744 5681{
5682 int ret;
5683 struct peer *peer;
fee0f4c6 5684 int direct = RMAP_IN;
718e3744 5685
5686 peer = peer_and_group_lookup_vty (vty, ip_str);
5687 if (! peer)
5688 return CMD_WARNING;
5689
5690 /* Check filter direction. */
fee0f4c6 5691 if (strncmp (direct_str, "in", 2) == 0)
5692 direct = RMAP_IN;
718e3744 5693 else if (strncmp (direct_str, "o", 1) == 0)
fee0f4c6 5694 direct = RMAP_OUT;
718e3744 5695
5696 ret = peer_route_map_set (peer, afi, safi, direct, name_str);
5697
5698 return bgp_vty_return (vty, ret);
5699}
5700
94f2b392 5701static int
fd79ac91 5702peer_route_map_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
5703 safi_t safi, const char *direct_str)
718e3744 5704{
5705 int ret;
5706 struct peer *peer;
fee0f4c6 5707 int direct = RMAP_IN;
718e3744 5708
5709 peer = peer_and_group_lookup_vty (vty, ip_str);
5710 if (! peer)
5711 return CMD_WARNING;
5712
5713 /* Check filter direction. */
fee0f4c6 5714 if (strncmp (direct_str, "in", 2) == 0)
5715 direct = RMAP_IN;
718e3744 5716 else if (strncmp (direct_str, "o", 1) == 0)
fee0f4c6 5717 direct = RMAP_OUT;
718e3744 5718
5719 ret = peer_route_map_unset (peer, afi, safi, direct);
5720
5721 return bgp_vty_return (vty, ret);
5722}
5723
5724DEFUN (neighbor_route_map,
5725 neighbor_route_map_cmd,
9ccf14f7 5726 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5727 NEIGHBOR_STR
5728 NEIGHBOR_ADDR_STR2
5729 "Apply route map to neighbor\n"
5730 "Name of route map\n"
5731 "Apply map to incoming routes\n"
2a3d5731 5732 "Apply map to outbound routes\n")
718e3744 5733{
c500ae40
DW
5734 int idx_peer = 1;
5735 int idx_word = 3;
5736 int idx_in_out = 4;
5737 return peer_route_map_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5738 bgp_node_safi (vty), argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5739}
5740
596c17ba
DW
5741ALIAS_HIDDEN (neighbor_route_map,
5742 neighbor_route_map_hidden_cmd,
5743 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5744 NEIGHBOR_STR
5745 NEIGHBOR_ADDR_STR2
5746 "Apply route map to neighbor\n"
5747 "Name of route map\n"
5748 "Apply map to incoming routes\n"
5749 "Apply map to outbound routes\n")
5750
718e3744 5751DEFUN (no_neighbor_route_map,
5752 no_neighbor_route_map_cmd,
9ccf14f7 5753 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5754 NO_STR
5755 NEIGHBOR_STR
5756 NEIGHBOR_ADDR_STR2
5757 "Apply route map to neighbor\n"
5758 "Name of route map\n"
5759 "Apply map to incoming routes\n"
2a3d5731 5760 "Apply map to outbound routes\n")
718e3744 5761{
c500ae40
DW
5762 int idx_peer = 2;
5763 int idx_in_out = 5;
5764 return peer_route_map_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5765 bgp_node_safi (vty), argv[idx_in_out]->arg);
718e3744 5766}
6b0655a2 5767
596c17ba
DW
5768ALIAS_HIDDEN (no_neighbor_route_map,
5769 no_neighbor_route_map_hidden_cmd,
5770 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5771 NO_STR
5772 NEIGHBOR_STR
5773 NEIGHBOR_ADDR_STR2
5774 "Apply route map to neighbor\n"
5775 "Name of route map\n"
5776 "Apply map to incoming routes\n"
5777 "Apply map to outbound routes\n")
5778
718e3744 5779/* Set unsuppress-map to the peer. */
94f2b392 5780static int
fd79ac91 5781peer_unsuppress_map_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
5782 safi_t safi, const char *name_str)
718e3744 5783{
5784 int ret;
5785 struct peer *peer;
5786
5787 peer = peer_and_group_lookup_vty (vty, ip_str);
5788 if (! peer)
5789 return CMD_WARNING;
5790
5791 ret = peer_unsuppress_map_set (peer, afi, safi, name_str);
5792
5793 return bgp_vty_return (vty, ret);
5794}
5795
5796/* Unset route-map from the peer. */
94f2b392 5797static int
fd79ac91 5798peer_unsuppress_map_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
718e3744 5799 safi_t safi)
5800{
5801 int ret;
5802 struct peer *peer;
5803
5804 peer = peer_and_group_lookup_vty (vty, ip_str);
5805 if (! peer)
5806 return CMD_WARNING;
5807
5808 ret = peer_unsuppress_map_unset (peer, afi, safi);
5809
5810 return bgp_vty_return (vty, ret);
5811}
5812
5813DEFUN (neighbor_unsuppress_map,
5814 neighbor_unsuppress_map_cmd,
9ccf14f7 5815 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
5818 "Route-map to selectively unsuppress suppressed routes\n"
5819 "Name of route map\n")
5820{
c500ae40
DW
5821 int idx_peer = 1;
5822 int idx_word = 3;
5823 return peer_unsuppress_map_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5824 bgp_node_safi (vty), argv[idx_word]->arg);
718e3744 5825}
5826
596c17ba
DW
5827ALIAS_HIDDEN (neighbor_unsuppress_map,
5828 neighbor_unsuppress_map_hidden_cmd,
5829 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5830 NEIGHBOR_STR
5831 NEIGHBOR_ADDR_STR2
5832 "Route-map to selectively unsuppress suppressed routes\n"
5833 "Name of route map\n")
5834
718e3744 5835DEFUN (no_neighbor_unsuppress_map,
5836 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5837 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5838 NO_STR
5839 NEIGHBOR_STR
5840 NEIGHBOR_ADDR_STR2
5841 "Route-map to selectively unsuppress suppressed routes\n"
5842 "Name of route map\n")
5843{
c500ae40
DW
5844 int idx_peer = 2;
5845 return peer_unsuppress_map_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 5846 bgp_node_safi (vty));
5847}
6b0655a2 5848
596c17ba
DW
5849ALIAS_HIDDEN (no_neighbor_unsuppress_map,
5850 no_neighbor_unsuppress_map_hidden_cmd,
5851 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5852 NO_STR
5853 NEIGHBOR_STR
5854 NEIGHBOR_ADDR_STR2
5855 "Route-map to selectively unsuppress suppressed routes\n"
5856 "Name of route map\n")
5857
94f2b392 5858static int
fd79ac91 5859peer_maximum_prefix_set_vty (struct vty *vty, const char *ip_str, afi_t afi,
e52702f2 5860 safi_t safi, const char *num_str,
0a486e5f 5861 const char *threshold_str, int warning,
5862 const char *restart_str)
718e3744 5863{
5864 int ret;
5865 struct peer *peer;
5866 u_int32_t max;
e0701b79 5867 u_char threshold;
0a486e5f 5868 u_int16_t restart;
718e3744 5869
5870 peer = peer_and_group_lookup_vty (vty, ip_str);
5871 if (! peer)
5872 return CMD_WARNING;
5873
e6ec1c36 5874 VTY_GET_INTEGER ("maximum number", max, num_str);
e0701b79 5875 if (threshold_str)
5876 threshold = atoi (threshold_str);
5877 else
5878 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5879
0a486e5f 5880 if (restart_str)
5881 restart = atoi (restart_str);
5882 else
5883 restart = 0;
5884
5885 ret = peer_maximum_prefix_set (peer, afi, safi, max, threshold, warning, restart);
718e3744 5886
5887 return bgp_vty_return (vty, ret);
5888}
5889
94f2b392 5890static int
fd79ac91 5891peer_maximum_prefix_unset_vty (struct vty *vty, const char *ip_str, afi_t afi,
718e3744 5892 safi_t safi)
5893{
5894 int ret;
5895 struct peer *peer;
5896
5897 peer = peer_and_group_lookup_vty (vty, ip_str);
5898 if (! peer)
5899 return CMD_WARNING;
5900
5901 ret = peer_maximum_prefix_unset (peer, afi, safi);
5902
5903 return bgp_vty_return (vty, ret);
5904}
5905
5906/* Maximum number of prefix configuration. prefix count is different
5907 for each peer configuration. So this configuration can be set for
5908 each peer configuration. */
5909DEFUN (neighbor_maximum_prefix,
5910 neighbor_maximum_prefix_cmd,
9ccf14f7 5911 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5912 NEIGHBOR_STR
5913 NEIGHBOR_ADDR_STR2
5914 "Maximum number of prefix accept from this peer\n"
5915 "maximum no. of prefix limit\n")
5916{
c500ae40
DW
5917 int idx_peer = 1;
5918 int idx_number = 3;
5919 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5920 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 0,
0a486e5f 5921 NULL);
718e3744 5922}
5923
596c17ba
DW
5924ALIAS_HIDDEN (neighbor_maximum_prefix,
5925 neighbor_maximum_prefix_hidden_cmd,
5926 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5927 NEIGHBOR_STR
5928 NEIGHBOR_ADDR_STR2
5929 "Maximum number of prefix accept from this peer\n"
5930 "maximum no. of prefix limit\n")
5931
e0701b79 5932DEFUN (neighbor_maximum_prefix_threshold,
5933 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5934 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5935 NEIGHBOR_STR
5936 NEIGHBOR_ADDR_STR2
5937 "Maximum number of prefix accept from this peer\n"
5938 "maximum no. of prefix limit\n"
5939 "Threshold value (%) at which to generate a warning msg\n")
5940{
c500ae40
DW
5941 int idx_peer = 1;
5942 int idx_number = 3;
5943 int idx_number_2 = 4;
5944 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5945 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
0a486e5f 5946 NULL);
5947}
e0701b79 5948
596c17ba
DW
5949ALIAS_HIDDEN (neighbor_maximum_prefix_threshold,
5950 neighbor_maximum_prefix_threshold_hidden_cmd,
5951 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5952 NEIGHBOR_STR
5953 NEIGHBOR_ADDR_STR2
5954 "Maximum number of prefix accept from this peer\n"
5955 "maximum no. of prefix limit\n"
5956 "Threshold value (%) at which to generate a warning msg\n")
5957
718e3744 5958DEFUN (neighbor_maximum_prefix_warning,
5959 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5960 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5961 NEIGHBOR_STR
5962 NEIGHBOR_ADDR_STR2
5963 "Maximum number of prefix accept from this peer\n"
5964 "maximum no. of prefix limit\n"
5965 "Only give warning message when limit is exceeded\n")
5966{
c500ae40
DW
5967 int idx_peer = 1;
5968 int idx_number = 3;
5969 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5970 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 1,
0a486e5f 5971 NULL);
718e3744 5972}
5973
596c17ba
DW
5974ALIAS_HIDDEN (neighbor_maximum_prefix_warning,
5975 neighbor_maximum_prefix_warning_hidden_cmd,
5976 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5977 NEIGHBOR_STR
5978 NEIGHBOR_ADDR_STR2
5979 "Maximum number of prefix accept from this peer\n"
5980 "maximum no. of prefix limit\n"
5981 "Only give warning message when limit is exceeded\n")
5982
e0701b79 5983DEFUN (neighbor_maximum_prefix_threshold_warning,
5984 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5985 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5986 NEIGHBOR_STR
5987 NEIGHBOR_ADDR_STR2
5988 "Maximum number of prefix accept from this peer\n"
5989 "maximum no. of prefix limit\n"
5990 "Threshold value (%) at which to generate a warning msg\n"
5991 "Only give warning message when limit is exceeded\n")
5992{
c500ae40
DW
5993 int idx_peer = 1;
5994 int idx_number = 3;
5995 int idx_number_2 = 4;
5996 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
5997 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5998}
5999
596c17ba
DW
6000ALIAS_HIDDEN (neighbor_maximum_prefix_threshold_warning,
6001 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
6002 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
6003 NEIGHBOR_STR
6004 NEIGHBOR_ADDR_STR2
6005 "Maximum number of prefix accept from this peer\n"
6006 "maximum no. of prefix limit\n"
6007 "Threshold value (%) at which to generate a warning msg\n"
6008 "Only give warning message when limit is exceeded\n")
6009
0a486e5f 6010DEFUN (neighbor_maximum_prefix_restart,
6011 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 6012 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 6013 NEIGHBOR_STR
6014 NEIGHBOR_ADDR_STR2
6015 "Maximum number of prefix accept from this peer\n"
6016 "maximum no. of prefix limit\n"
6017 "Restart bgp connection after limit is exceeded\n"
6018 "Restart interval in minutes")
6019{
c500ae40
DW
6020 int idx_peer = 1;
6021 int idx_number = 3;
6022 int idx_number_2 = 5;
6023 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
6024 bgp_node_safi (vty), argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 6025}
6026
596c17ba
DW
6027ALIAS_HIDDEN (neighbor_maximum_prefix_restart,
6028 neighbor_maximum_prefix_restart_hidden_cmd,
6029 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
6030 NEIGHBOR_STR
6031 NEIGHBOR_ADDR_STR2
6032 "Maximum number of prefix accept from this peer\n"
6033 "maximum no. of prefix limit\n"
6034 "Restart bgp connection after limit is exceeded\n"
6035 "Restart interval in minutes")
6036
0a486e5f 6037DEFUN (neighbor_maximum_prefix_threshold_restart,
6038 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 6039 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 6040 NEIGHBOR_STR
6041 NEIGHBOR_ADDR_STR2
16cedbb0 6042 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 6043 "maximum no. of prefix limit\n"
6044 "Threshold value (%) at which to generate a warning msg\n"
6045 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6046 "Restart interval in minutes\n")
0a486e5f 6047{
c500ae40
DW
6048 int idx_peer = 1;
6049 int idx_number = 3;
6050 int idx_number_2 = 4;
6051 int idx_number_3 = 6;
6052 return peer_maximum_prefix_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
6053 bgp_node_safi (vty), argv[idx_number]->arg, argv[idx_number_2]->arg, 0, argv[idx_number_3]->arg);
0a486e5f 6054}
e0701b79 6055
596c17ba
DW
6056ALIAS_HIDDEN (neighbor_maximum_prefix_threshold_restart,
6057 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
6058 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
6059 NEIGHBOR_STR
6060 NEIGHBOR_ADDR_STR2
6061 "Maximum number of prefixes to accept from this peer\n"
6062 "maximum no. of prefix limit\n"
6063 "Threshold value (%) at which to generate a warning msg\n"
6064 "Restart bgp connection after limit is exceeded\n"
6065 "Restart interval in minutes\n")
6066
718e3744 6067DEFUN (no_neighbor_maximum_prefix,
6068 no_neighbor_maximum_prefix_cmd,
d04c479d 6069 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 6070 NO_STR
6071 NEIGHBOR_STR
6072 NEIGHBOR_ADDR_STR2
16cedbb0 6073 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
6074 "maximum no. of prefix limit\n"
6075 "Threshold value (%) at which to generate a warning msg\n"
6076 "Restart bgp connection after limit is exceeded\n"
16cedbb0 6077 "Restart interval in minutes\n"
31500417 6078 "Only give warning message when limit is exceeded\n")
718e3744 6079{
c500ae40
DW
6080 int idx_peer = 2;
6081 return peer_maximum_prefix_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
718e3744 6082 bgp_node_safi (vty));
6083}
e52702f2 6084
596c17ba
DW
6085ALIAS_HIDDEN (no_neighbor_maximum_prefix,
6086 no_neighbor_maximum_prefix_hidden_cmd,
6087 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
6088 NO_STR
6089 NEIGHBOR_STR
6090 NEIGHBOR_ADDR_STR2
6091 "Maximum number of prefixes to accept from this peer\n"
6092 "maximum no. of prefix limit\n"
6093 "Threshold value (%) at which to generate a warning msg\n"
6094 "Restart bgp connection after limit is exceeded\n"
6095 "Restart interval in minutes\n"
6096 "Only give warning message when limit is exceeded\n")
6097
718e3744 6098
718e3744 6099/* "neighbor allowas-in" */
6100DEFUN (neighbor_allowas_in,
6101 neighbor_allowas_in_cmd,
fd8503f5 6102 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6103 NEIGHBOR_STR
6104 NEIGHBOR_ADDR_STR2
31500417 6105 "Accept as-path with my AS present in it\n"
fd8503f5
QY
6106 "Number of occurances of AS number\n"
6107 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6108{
c500ae40 6109 int idx_peer = 1;
fd8503f5 6110 int idx_number_origin = 3;
718e3744 6111 int ret;
aac9ef6c 6112 int origin = 0;
718e3744 6113 struct peer *peer;
aac9ef6c 6114 int allow_num = 0;
718e3744 6115
c500ae40 6116 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 6117 if (! peer)
6118 return CMD_WARNING;
6119
fd8503f5 6120 if (argc <= idx_number_origin)
718e3744 6121 allow_num = 3;
6122 else
aac9ef6c 6123 {
fd8503f5 6124 if (argv[idx_number_origin]->type == WORD_TKN)
aac9ef6c
DW
6125 origin = 1;
6126 else
fd8503f5 6127 allow_num = atoi (argv[idx_number_origin]->arg);
aac9ef6c 6128 }
718e3744 6129
6130 ret = peer_allowas_in_set (peer, bgp_node_afi (vty), bgp_node_safi (vty),
aac9ef6c 6131 allow_num, origin);
718e3744 6132
6133 return bgp_vty_return (vty, ret);
6134}
6135
596c17ba
DW
6136ALIAS_HIDDEN (neighbor_allowas_in,
6137 neighbor_allowas_in_hidden_cmd,
6138 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6139 NEIGHBOR_STR
6140 NEIGHBOR_ADDR_STR2
6141 "Accept as-path with my AS present in it\n"
6142 "Number of occurances of AS number\n"
6143 "Only accept my AS in the as-path if the route was originated in my AS\n")
6144
718e3744 6145DEFUN (no_neighbor_allowas_in,
6146 no_neighbor_allowas_in_cmd,
fd8503f5 6147 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 6148 NO_STR
6149 NEIGHBOR_STR
6150 NEIGHBOR_ADDR_STR2
8334fd5a 6151 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
6152 "Number of occurances of AS number\n"
6153 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 6154{
c500ae40 6155 int idx_peer = 2;
718e3744 6156 int ret;
6157 struct peer *peer;
6158
c500ae40 6159 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
718e3744 6160 if (! peer)
6161 return CMD_WARNING;
6162
6163 ret = peer_allowas_in_unset (peer, bgp_node_afi (vty), bgp_node_safi (vty));
6164
6165 return bgp_vty_return (vty, ret);
6166}
6b0655a2 6167
596c17ba
DW
6168ALIAS_HIDDEN (no_neighbor_allowas_in,
6169 no_neighbor_allowas_in_hidden_cmd,
6170 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
6171 NO_STR
6172 NEIGHBOR_STR
6173 NEIGHBOR_ADDR_STR2
6174 "allow local ASN appears in aspath attribute\n"
6175 "Number of occurances of AS number\n"
6176 "Only accept my AS in the as-path if the route was originated in my AS\n")
6177
fa411a21
NH
6178DEFUN (neighbor_ttl_security,
6179 neighbor_ttl_security_cmd,
9ccf14f7 6180 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6181 NEIGHBOR_STR
6182 NEIGHBOR_ADDR_STR2
16cedbb0 6183 "BGP ttl-security parameters\n"
d7fa34c1
QY
6184 "Specify the maximum number of hops to the BGP peer\n"
6185 "Number of hops to BGP peer\n")
fa411a21 6186{
c500ae40
DW
6187 int idx_peer = 1;
6188 int idx_number = 4;
fa411a21 6189 struct peer *peer;
89b6d1f8 6190 int gtsm_hops;
fa411a21 6191
c500ae40 6192 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
fa411a21
NH
6193 if (! peer)
6194 return CMD_WARNING;
e52702f2 6195
c500ae40 6196 VTY_GET_INTEGER_RANGE ("", gtsm_hops, argv[idx_number]->arg, 1, 254);
fa411a21 6197
8cdabf90
SK
6198 /*
6199 * If 'neighbor swpX', then this is for directly connected peers,
6200 * we should not accept a ttl-security hops value greater than 1.
6201 */
6202 if (peer->conf_if && (gtsm_hops > 1)) {
6203 vty_out (vty, "%s is directly connected peer, hops cannot exceed 1%s",
c500ae40 6204 argv[idx_peer]->arg, VTY_NEWLINE);
8cdabf90
SK
6205 return CMD_WARNING;
6206 }
6207
89b6d1f8 6208 return bgp_vty_return (vty, peer_ttl_security_hops_set (peer, gtsm_hops));
fa411a21
NH
6209}
6210
6211DEFUN (no_neighbor_ttl_security,
6212 no_neighbor_ttl_security_cmd,
9ccf14f7 6213 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6214 NO_STR
6215 NEIGHBOR_STR
6216 NEIGHBOR_ADDR_STR2
16cedbb0 6217 "BGP ttl-security parameters\n"
3a2d747c
QY
6218 "Specify the maximum number of hops to the BGP peer\n"
6219 "Number of hops to BGP peer\n")
fa411a21 6220{
c500ae40 6221 int idx_peer = 2;
fa411a21 6222 struct peer *peer;
fa411a21 6223
c500ae40 6224 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
fa411a21
NH
6225 if (! peer)
6226 return CMD_WARNING;
6227
89b6d1f8 6228 return bgp_vty_return (vty, peer_ttl_security_hops_unset (peer));
fa411a21 6229}
6b0655a2 6230
adbac85e
DW
6231DEFUN (neighbor_addpath_tx_all_paths,
6232 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6233 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6234 NEIGHBOR_STR
6235 NEIGHBOR_ADDR_STR2
6236 "Use addpath to advertise all paths to a neighbor\n")
6237{
c500ae40 6238 int idx_peer = 1;
adbac85e
DW
6239 struct peer *peer;
6240
c500ae40 6241 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
adbac85e
DW
6242 if (! peer)
6243 return CMD_WARNING;
6244
c500ae40 6245 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
adbac85e
DW
6246 bgp_node_safi (vty),
6247 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6248}
6249
596c17ba
DW
6250ALIAS_HIDDEN (neighbor_addpath_tx_all_paths,
6251 neighbor_addpath_tx_all_paths_hidden_cmd,
6252 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6253 NEIGHBOR_STR
6254 NEIGHBOR_ADDR_STR2
6255 "Use addpath to advertise all paths to a neighbor\n")
6256
adbac85e
DW
6257DEFUN (no_neighbor_addpath_tx_all_paths,
6258 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6259 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6260 NO_STR
6261 NEIGHBOR_STR
6262 NEIGHBOR_ADDR_STR2
6263 "Use addpath to advertise all paths to a neighbor\n")
6264{
c500ae40
DW
6265 int idx_peer = 2;
6266 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
adbac85e
DW
6267 bgp_node_safi (vty),
6268 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
6269}
6270
596c17ba
DW
6271ALIAS_HIDDEN (no_neighbor_addpath_tx_all_paths,
6272 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6273 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6274 NO_STR
6275 NEIGHBOR_STR
6276 NEIGHBOR_ADDR_STR2
6277 "Use addpath to advertise all paths to a neighbor\n")
6278
06370dac
DW
6279DEFUN (neighbor_addpath_tx_bestpath_per_as,
6280 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6281 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6282 NEIGHBOR_STR
6283 NEIGHBOR_ADDR_STR2
6284 "Use addpath to advertise the bestpath per each neighboring AS\n")
6285{
c500ae40 6286 int idx_peer = 1;
06370dac
DW
6287 struct peer *peer;
6288
c500ae40 6289 peer = peer_and_group_lookup_vty (vty, argv[idx_peer]->arg);
06370dac
DW
6290 if (! peer)
6291 return CMD_WARNING;
6292
c500ae40 6293 return peer_af_flag_set_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
06370dac
DW
6294 bgp_node_safi (vty),
6295 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6296}
6297
596c17ba
DW
6298ALIAS_HIDDEN (neighbor_addpath_tx_bestpath_per_as,
6299 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6300 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6301 NEIGHBOR_STR
6302 NEIGHBOR_ADDR_STR2
6303 "Use addpath to advertise the bestpath per each neighboring AS\n")
6304
06370dac
DW
6305DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6306 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6307 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6308 NO_STR
6309 NEIGHBOR_STR
6310 NEIGHBOR_ADDR_STR2
6311 "Use addpath to advertise the bestpath per each neighboring AS\n")
6312{
c500ae40
DW
6313 int idx_peer = 2;
6314 return peer_af_flag_unset_vty (vty, argv[idx_peer]->arg, bgp_node_afi (vty),
06370dac
DW
6315 bgp_node_safi (vty),
6316 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
6317}
6318
596c17ba
DW
6319ALIAS_HIDDEN (no_neighbor_addpath_tx_bestpath_per_as,
6320 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6321 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6322 NO_STR
6323 NEIGHBOR_STR
6324 NEIGHBOR_ADDR_STR2
6325 "Use addpath to advertise the bestpath per each neighboring AS\n")
6326
505e5056 6327DEFUN_NOSH (address_family_ipv4_safi,
718e3744 6328 address_family_ipv4_safi_cmd,
5b1f0f29 6329 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6330 "Enter Address Family command mode\n"
8c3deaae 6331 "Address Family\n"
46f296b4 6332 BGP_SAFI_HELP_STR)
718e3744 6333{
f51bae9c
DS
6334
6335 if (argc == 3)
ccbb332a 6336 {
f51bae9c
DS
6337 safi_t safi = bgp_vty_safi_from_arg(argv[2]->arg);
6338 vty->node = bgp_node_type(AFI_IP, safi);
ccbb332a 6339 }
c7f1274b
DS
6340 else
6341 vty->node = BGP_IPV4_NODE;
718e3744 6342
6343 return CMD_SUCCESS;
6344}
6345
505e5056 6346DEFUN_NOSH (address_family_ipv6_safi,
25ffbdc1 6347 address_family_ipv6_safi_cmd,
5b1f0f29 6348 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6349 "Enter Address Family command mode\n"
8c3deaae 6350 "Address Family\n"
46f296b4 6351 BGP_SAFI_HELP_STR)
25ffbdc1 6352{
f51bae9c 6353 if (argc == 3)
46f296b4 6354 {
f51bae9c
DS
6355 safi_t safi = bgp_vty_safi_from_arg(argv[2]->arg);
6356 vty->node = bgp_node_type(AFI_IP6, safi);
46f296b4 6357 }
c7f1274b
DS
6358 else
6359 vty->node = BGP_IPV6_NODE;
25ffbdc1 6360
6361 return CMD_SUCCESS;
6362}
718e3744 6363
d6902373 6364#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6365DEFUN_NOSH (address_family_vpnv4,
718e3744 6366 address_family_vpnv4_cmd,
8334fd5a 6367 "address-family vpnv4 [unicast]",
718e3744 6368 "Enter Address Family command mode\n"
8c3deaae 6369 "Address Family\n"
3a2d747c 6370 "Address Family modifier\n")
718e3744 6371{
6372 vty->node = BGP_VPNV4_NODE;
6373 return CMD_SUCCESS;
6374}
6375
505e5056 6376DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6377 address_family_vpnv6_cmd,
8334fd5a 6378 "address-family vpnv6 [unicast]",
8ecd3266 6379 "Enter Address Family command mode\n"
8c3deaae 6380 "Address Family\n"
3a2d747c 6381 "Address Family modifier\n")
8ecd3266 6382{
6383 vty->node = BGP_VPNV6_NODE;
6384 return CMD_SUCCESS;
6385}
c016b6c7 6386#endif
d6902373 6387
505e5056 6388DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6389 address_family_evpn_cmd,
b194703e 6390 "address-family <l2vpn evpn>",
4e0b7b6d 6391 "Enter Address Family command mode\n"
61a51962
PG
6392 "EVPN Address family\n"
6393 "Layer2 VPN Address family\n"
6394 "Ethernet Virtual Private Network Subsequent Address Family\n")
4e0b7b6d 6395{
4e0b7b6d 6396 vty->node = BGP_EVPN_NODE;
4e0b7b6d
PG
6397 return CMD_SUCCESS;
6398}
6399
505e5056 6400DEFUN_NOSH (exit_address_family,
718e3744 6401 exit_address_family_cmd,
6402 "exit-address-family",
6403 "Exit from Address Family configuration mode\n")
6404{
a8a80d53 6405 if (vty->node == BGP_IPV4_NODE
6406 || vty->node == BGP_IPV4M_NODE
f51bae9c 6407 || vty->node == BGP_IPV4L_NODE
718e3744 6408 || vty->node == BGP_VPNV4_NODE
25ffbdc1 6409 || vty->node == BGP_IPV6_NODE
8ecd3266 6410 || vty->node == BGP_IPV6M_NODE
f51bae9c 6411 || vty->node == BGP_IPV6L_NODE
8b1fb8be 6412 || vty->node == BGP_VPNV6_NODE
4e0b7b6d 6413 || vty->node == BGP_EVPN_NODE)
718e3744 6414 vty->node = BGP_NODE;
6415 return CMD_SUCCESS;
6416}
6b0655a2 6417
8ad7271d
DS
6418/* Recalculate bestpath and re-advertise a prefix */
6419static int
01080f7c 6420bgp_clear_prefix (struct vty *vty, const char *view_name, const char *ip_str,
8ad7271d
DS
6421 afi_t afi, safi_t safi, struct prefix_rd *prd)
6422{
6423 int ret;
6424 struct prefix match;
6425 struct bgp_node *rn;
6426 struct bgp_node *rm;
8ad7271d
DS
6427 struct bgp *bgp;
6428 struct bgp_table *table;
6429 struct bgp_table *rib;
6430
6431 /* BGP structure lookup. */
6432 if (view_name)
6433 {
6434 bgp = bgp_lookup_by_name (view_name);
6435 if (bgp == NULL)
6436 {
6aeb9e78 6437 vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
8ad7271d
DS
6438 return CMD_WARNING;
6439 }
6440 }
6441 else
6442 {
6443 bgp = bgp_get_default ();
6444 if (bgp == NULL)
6445 {
6446 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
6447 return CMD_WARNING;
6448 }
6449 }
6450
6451 /* Check IP address argument. */
6452 ret = str2prefix (ip_str, &match);
6453 if (! ret)
6454 {
6455 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
6456 return CMD_WARNING;
6457 }
6458
6459 match.family = afi2family (afi);
6460 rib = bgp->rib[afi][safi];
6461
6462 if (safi == SAFI_MPLS_VPN)
6463 {
6464 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
6465 {
6466 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6467 continue;
6468
6469 if ((table = rn->info) != NULL)
6470 {
6471 if ((rm = bgp_node_match (table, &match)) != NULL)
6472 {
6473 if (rm->p.prefixlen == match.prefixlen)
6474 {
6475 SET_FLAG (rn->flags, BGP_NODE_USER_CLEAR);
6476 bgp_process (bgp, rm, afi, safi);
6477 }
6478 bgp_unlock_node (rm);
6479 }
6480 }
6481 }
6482 }
6483 else
6484 {
6485 if ((rn = bgp_node_match (rib, &match)) != NULL)
6486 {
6487 if (rn->p.prefixlen == match.prefixlen)
6488 {
6489 SET_FLAG (rn->flags, BGP_NODE_USER_CLEAR);
6490 bgp_process (bgp, rn, afi, safi);
6491 }
6492 bgp_unlock_node (rn);
6493 }
6494 }
6495
6496 return CMD_SUCCESS;
6497}
6498
b09b5ae0 6499/* one clear bgp command to rule them all */
718e3744 6500DEFUN (clear_ip_bgp_all,
6501 clear_ip_bgp_all_cmd,
18c57037 6502 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["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 6503 CLEAR_STR
6504 IP_STR
6505 BGP_STR
838758ac 6506 BGP_INSTANCE_HELP_STR
b09b5ae0
DW
6507 "Clear all peers\n"
6508 "BGP neighbor address to clear\n"
a80beece 6509 "BGP IPv6 neighbor to clear\n"
838758ac 6510 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
6511 "Clear peers with the AS number\n"
6512 "Clear all external peers\n"
718e3744 6513 "Clear all members of peer-group\n"
b09b5ae0 6514 "BGP peer-group name\n"
46f296b4
LB
6515 BGP_AFI_HELP_STR
6516 BGP_SAFI_HELP_STR
b09b5ae0
DW
6517 BGP_SOFT_STR
6518 BGP_SOFT_IN_STR
b09b5ae0
DW
6519 BGP_SOFT_OUT_STR
6520 BGP_SOFT_IN_STR
6521 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 6522 BGP_SOFT_OUT_STR)
718e3744 6523{
8334fd5a 6524 char *vrf = NULL;
630a298c 6525
ae19d7dd
QY
6526 afi_t afi = AFI_IP6;
6527 safi_t safi = SAFI_UNICAST;
5bf15956 6528 enum clear_sort clr_sort = clear_peer;
b09b5ae0
DW
6529 enum bgp_clear_type clr_type;
6530 char *clr_arg = NULL;
718e3744 6531
ae19d7dd 6532 int idx = 0;
01080f7c 6533
ae19d7dd
QY
6534 /* clear [ip] bgp */
6535 if (argv_find (argv, argc, "ip", &idx))
6536 afi = AFI_IP;
18c57037 6537 /* [<view|vrf> VIEWVRFNAME] */
ae19d7dd 6538 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
838758ac 6539 {
ae19d7dd
QY
6540 vrf = argv[idx + 1]->arg;
6541 idx += 2;
838758ac 6542 }
ae19d7dd
QY
6543 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6544 if (argv_find (argv, argc, "*", &idx))
b09b5ae0 6545 {
ae19d7dd 6546 clr_sort = clear_all;
b09b5ae0 6547 }
ae19d7dd 6548 else if (argv_find (argv, argc, "A.B.C.D", &idx))
b09b5ae0
DW
6549 {
6550 clr_sort = clear_peer;
ae19d7dd 6551 clr_arg = argv[idx]->arg;
b09b5ae0 6552 }
ae19d7dd 6553 else if (argv_find (argv, argc, "X:X::X:X", &idx))
b09b5ae0 6554 {
ae19d7dd
QY
6555 clr_sort = clear_peer;
6556 clr_arg = argv[idx]->arg;
838758ac 6557 }
ae19d7dd 6558 else if (argv_find (argv, argc, "peer-group", &idx))
b09b5ae0
DW
6559 {
6560 clr_sort = clear_group;
ae19d7dd
QY
6561 idx++;
6562 clr_arg = argv[idx]->arg;
b09b5ae0 6563 }
ae19d7dd 6564 else if (argv_find (argv, argc, "WORD", &idx))
b09b5ae0 6565 {
f0dac89f
RW
6566 clr_sort = clear_peer;
6567 clr_arg = argv[idx]->arg;
b09b5ae0 6568 }
ae19d7dd
QY
6569 else if (argv_find (argv, argc, "(1-4294967295)", &idx))
6570 {
6571 clr_sort = clear_as;
6572 clr_arg = argv[idx]->arg;
6573 }
6574 else if (argv_find (argv, argc, "external", &idx))
6575 {
6576 clr_sort = clear_external;
6577 }
46f296b4
LB
6578 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6579 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
ae19d7dd 6580 {
46f296b4 6581 argv_find_and_parse_safi (argv, argc, &idx, &safi);
ae19d7dd
QY
6582 }
6583 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6584 if (argv_find (argv, argc, "soft", &idx))
6585 {
6586 if (argv_find (argv, argc, "in", &idx) || argv_find (argv, argc, "out", &idx))
6587 clr_type = strmatch (argv[idx]->text, "in") ? BGP_CLEAR_SOFT_IN : BGP_CLEAR_SOFT_OUT;
6588 else
6589 clr_type = BGP_CLEAR_SOFT_BOTH;
6590 }
6591 else if (argv_find (argv, argc, "in", &idx))
6592 {
6593 clr_type = argv_find (argv, argc, "prefix-filter", &idx) ? BGP_CLEAR_SOFT_IN_ORF_PREFIX : BGP_CLEAR_SOFT_IN;
6594 }
6595 else if (argv_find (argv, argc, "out", &idx))
6596 {
5daa3e5e 6597 clr_type = BGP_CLEAR_SOFT_OUT;
ae19d7dd
QY
6598 }
6599 else
6600 clr_type = BGP_CLEAR_SOFT_NONE;
718e3744 6601
b09b5ae0 6602 return bgp_clear_vty (vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 6603}
01080f7c 6604
8ad7271d
DS
6605DEFUN (clear_ip_bgp_prefix,
6606 clear_ip_bgp_prefix_cmd,
18c57037 6607 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
6608 CLEAR_STR
6609 IP_STR
6610 BGP_STR
838758ac 6611 BGP_INSTANCE_HELP_STR
8ad7271d 6612 "Clear bestpath and re-advertise\n"
0c7b1b01 6613 "IPv4 prefix\n")
8ad7271d 6614{
8334fd5a 6615 char *vrf = NULL;
630a298c 6616 char *prefix = NULL;
8ad7271d 6617
630a298c 6618 int idx = 0;
01080f7c 6619
18c57037 6620 /* [<view|vrf> VIEWVRFNAME] */
630a298c
QY
6621 if (argv_find (argv, argc, "WORD", &idx))
6622 vrf = argv[idx]->arg;
0c7b1b01 6623
630a298c 6624 prefix = argv[argc-1]->arg;
8ad7271d 6625
630a298c 6626 return bgp_clear_prefix (vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 6627}
8ad7271d 6628
b09b5ae0
DW
6629DEFUN (clear_bgp_ipv6_safi_prefix,
6630 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 6631 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6632 CLEAR_STR
3a2d747c 6633 IP_STR
718e3744 6634 BGP_STR
8c3deaae 6635 "Address Family\n"
46f296b4 6636 BGP_SAFI_HELP_STR
b09b5ae0 6637 "Clear bestpath and re-advertise\n"
0c7b1b01 6638 "IPv6 prefix\n")
718e3744 6639{
b09b5ae0
DW
6640 int idx_safi = 3;
6641 int idx_ipv6_prefixlen = 5;
46f296b4
LB
6642 return bgp_clear_prefix (vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6643 bgp_vty_safi_from_arg(argv[idx_safi]->arg), NULL);
838758ac 6644}
01080f7c 6645
b09b5ae0
DW
6646DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6647 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 6648 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6649 CLEAR_STR
3a2d747c 6650 IP_STR
718e3744 6651 BGP_STR
838758ac 6652 BGP_INSTANCE_HELP_STR
8c3deaae 6653 "Address Family\n"
46f296b4 6654 BGP_SAFI_HELP_STR
b09b5ae0 6655 "Clear bestpath and re-advertise\n"
0c7b1b01 6656 "IPv6 prefix\n")
718e3744 6657{
b09b5ae0 6658 int idx_word = 3;
c500ae40 6659 int idx_safi = 5;
b09b5ae0 6660 int idx_ipv6_prefixlen = 7;
46f296b4
LB
6661 return bgp_clear_prefix (vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6662 bgp_vty_safi_from_arg(argv[idx_safi]->arg), NULL);
718e3744 6663}
6664
b09b5ae0
DW
6665DEFUN (show_bgp_views,
6666 show_bgp_views_cmd,
d6e3c605 6667 "show [ip] bgp views",
b09b5ae0 6668 SHOW_STR
d6e3c605 6669 IP_STR
01080f7c 6670 BGP_STR
b09b5ae0 6671 "Show the defined BGP views\n")
01080f7c 6672{
b09b5ae0
DW
6673 struct list *inst = bm->bgp;
6674 struct listnode *node;
6675 struct bgp *bgp;
01080f7c 6676
b09b5ae0
DW
6677 if (!bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
6678 {
6679 vty_out (vty, "BGP Multiple Instance is not enabled%s", VTY_NEWLINE);
6680 return CMD_WARNING;
6681 }
e52702f2 6682
b09b5ae0
DW
6683 vty_out (vty, "Defined BGP views:%s", VTY_NEWLINE);
6684 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp))
6685 {
6686 /* Skip VRFs. */
6687 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6688 continue;
6689 vty_out (vty, "\t%s (AS%u)%s",
6690 bgp->name ? bgp->name : "(null)",
6691 bgp->as, VTY_NEWLINE);
6692 }
e52702f2 6693
b09b5ae0 6694 return CMD_SUCCESS;
e0081f70
ML
6695}
6696
8386ac43 6697DEFUN (show_bgp_vrfs,
6698 show_bgp_vrfs_cmd,
d6e3c605 6699 "show [ip] bgp vrfs [json]",
8386ac43 6700 SHOW_STR
d6e3c605 6701 IP_STR
8386ac43 6702 BGP_STR
6703 "Show BGP VRFs\n"
9973d184 6704 JSON_STR)
8386ac43 6705{
6706 struct list *inst = bm->bgp;
6707 struct listnode *node;
6708 struct bgp *bgp;
6709 u_char uj = use_json(argc, argv);
6710 json_object *json = NULL;
6711 json_object *json_vrfs = NULL;
6712 int count = 0;
6713 static char header[] = "Type Id RouterId #PeersCfg #PeersEstb Name";
6714
6715 if (!bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
6716 {
6717 vty_out (vty, "BGP Multiple Instance is not enabled%s", VTY_NEWLINE);
6718 return CMD_WARNING;
6719 }
6720
6721 if (uj)
6722 {
6723 json = json_object_new_object();
6724 json_vrfs = json_object_new_object();
6725 }
6726
6727 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp))
6728 {
6729 const char *name, *type;
6730 struct peer *peer;
6731 struct listnode *node, *nnode;
6732 int peers_cfg, peers_estb;
6733 json_object *json_vrf = NULL;
5c81a5f3 6734 int vrf_id_ui;
8386ac43 6735
6736 /* Skip Views. */
6737 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6738 continue;
6739
6740 count++;
6741 if (!uj && count == 1)
6742 vty_out (vty, "%s%s", header, VTY_NEWLINE);
6743
6744 peers_cfg = peers_estb = 0;
6745 if (uj)
6746 json_vrf = json_object_new_object();
6747
6748
6749 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6750 {
6751 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6752 continue;
6753 peers_cfg++;
6754 if (peer->status == Established)
6755 peers_estb++;
6756 }
6757
6758 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
6759 {
6760 name = "Default";
6761 type = "DFLT";
6762 }
6763 else
6764 {
6765 name = bgp->name;
6766 type = "VRF";
6767 }
6768
5c81a5f3 6769 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
8386ac43 6770 if (uj)
6771 {
6772 json_object_string_add(json_vrf, "type", type);
5c81a5f3 6773 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
8386ac43 6774 json_object_string_add(json_vrf, "routerId", inet_ntoa (bgp->router_id));
6775 json_object_int_add(json_vrf, "numConfiguredPeers", peers_cfg);
6776 json_object_int_add(json_vrf, "numEstablishedPeers", peers_estb);
6777
6778 json_object_object_add(json_vrfs, name, json_vrf);
6779 }
6780 else
5c81a5f3 6781 vty_out (vty, "%4s %-5d %-16s %9u %10u %s%s",
6782 type, vrf_id_ui, inet_ntoa (bgp->router_id),
8386ac43 6783 peers_cfg, peers_estb, name,
6784 VTY_NEWLINE);
6785 }
6786
6787 if (uj)
6788 {
6789 json_object_object_add(json, "vrfs", json_vrfs);
6790
6791 json_object_int_add(json, "totalVrfs", count);
6792
2aac5767 6793 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
8386ac43 6794 json_object_free(json);
6795 }
6796 else
6797 {
6798 if (count)
6799 vty_out (vty, "%sTotal number of VRFs (including default): %d%s",
6800 VTY_NEWLINE, count, VTY_NEWLINE);
6801 }
6802
6803 return CMD_SUCCESS;
6804}
6805
f412b39a 6806DEFUN (show_bgp_memory,
4bf6a362 6807 show_bgp_memory_cmd,
7fa12b13 6808 "show [ip] bgp memory",
4bf6a362 6809 SHOW_STR
3a2d747c 6810 IP_STR
4bf6a362
PJ
6811 BGP_STR
6812 "Global BGP memory statistics\n")
6813{
6814 char memstrbuf[MTYPE_MEMSTR_LEN];
6815 unsigned long count;
e52702f2 6816
4bf6a362
PJ
6817 /* RIB related usage stats */
6818 count = mtype_stats_alloc (MTYPE_BGP_NODE);
6819 vty_out (vty, "%ld RIB nodes, using %s of memory%s", count,
6820 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6821 count * sizeof (struct bgp_node)),
6822 VTY_NEWLINE);
e52702f2 6823
4bf6a362
PJ
6824 count = mtype_stats_alloc (MTYPE_BGP_ROUTE);
6825 vty_out (vty, "%ld BGP routes, using %s of memory%s", count,
6826 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6827 count * sizeof (struct bgp_info)),
6828 VTY_NEWLINE);
fb982c25
PJ
6829 if ((count = mtype_stats_alloc (MTYPE_BGP_ROUTE_EXTRA)))
6830 vty_out (vty, "%ld BGP route ancillaries, using %s of memory%s", count,
6831 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6832 count * sizeof (struct bgp_info_extra)),
6833 VTY_NEWLINE);
e52702f2 6834
4bf6a362
PJ
6835 if ((count = mtype_stats_alloc (MTYPE_BGP_STATIC)))
6836 vty_out (vty, "%ld Static routes, using %s of memory%s", count,
6837 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6838 count * sizeof (struct bgp_static)),
6839 VTY_NEWLINE);
3f9c7369
DS
6840
6841 if ((count = mtype_stats_alloc (MTYPE_BGP_PACKET)))
6842 vty_out (vty, "%ld Packets, using %s of memory%s", count,
6843 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6844 count * sizeof (struct bpacket)),
6845 VTY_NEWLINE);
e52702f2 6846
4bf6a362
PJ
6847 /* Adj-In/Out */
6848 if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_IN)))
6849 vty_out (vty, "%ld Adj-In entries, using %s of memory%s", count,
6850 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6851 count * sizeof (struct bgp_adj_in)),
6852 VTY_NEWLINE);
6853 if ((count = mtype_stats_alloc (MTYPE_BGP_ADJ_OUT)))
6854 vty_out (vty, "%ld Adj-Out entries, using %s of memory%s", count,
6855 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6856 count * sizeof (struct bgp_adj_out)),
6857 VTY_NEWLINE);
e52702f2 6858
4bf6a362
PJ
6859 if ((count = mtype_stats_alloc (MTYPE_BGP_NEXTHOP_CACHE)))
6860 vty_out (vty, "%ld Nexthop cache entries, using %s of memory%s", count,
6861 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6862 count * sizeof (struct bgp_nexthop_cache)),
6863 VTY_NEWLINE);
6864
6865 if ((count = mtype_stats_alloc (MTYPE_BGP_DAMP_INFO)))
6866 vty_out (vty, "%ld Dampening entries, using %s of memory%s", count,
6867 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6868 count * sizeof (struct bgp_damp_info)),
6869 VTY_NEWLINE);
6870
6871 /* Attributes */
6872 count = attr_count();
e52702f2
QY
6873 vty_out (vty, "%ld BGP attributes, using %s of memory%s", count,
6874 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6875 count * sizeof(struct attr)),
4bf6a362 6876 VTY_NEWLINE);
fb982c25 6877 if ((count = mtype_stats_alloc (MTYPE_ATTR_EXTRA)))
e52702f2
QY
6878 vty_out (vty, "%ld BGP extra attributes, using %s of memory%s", count,
6879 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6880 count * sizeof(struct attr_extra)),
fb982c25 6881 VTY_NEWLINE);
e52702f2 6882
4bf6a362
PJ
6883 if ((count = attr_unknown_count()))
6884 vty_out (vty, "%ld unknown attributes%s", count, VTY_NEWLINE);
e52702f2 6885
4bf6a362
PJ
6886 /* AS_PATH attributes */
6887 count = aspath_count ();
6888 vty_out (vty, "%ld BGP AS-PATH entries, using %s of memory%s", count,
6889 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6890 count * sizeof (struct aspath)),
6891 VTY_NEWLINE);
e52702f2 6892
4bf6a362
PJ
6893 count = mtype_stats_alloc (MTYPE_AS_SEG);
6894 vty_out (vty, "%ld BGP AS-PATH segments, using %s of memory%s", count,
6895 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6896 count * sizeof (struct assegment)),
6897 VTY_NEWLINE);
e52702f2 6898
4bf6a362
PJ
6899 /* Other attributes */
6900 if ((count = community_count ()))
6901 vty_out (vty, "%ld BGP community entries, using %s of memory%s", count,
6902 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6903 count * sizeof (struct community)),
6904 VTY_NEWLINE);
6905 if ((count = mtype_stats_alloc (MTYPE_ECOMMUNITY)))
6906 vty_out (vty, "%ld BGP community entries, using %s of memory%s", count,
6907 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6908 count * sizeof (struct ecommunity)),
6909 VTY_NEWLINE);
57d187bc
JS
6910 if ((count = mtype_stats_alloc (MTYPE_LCOMMUNITY)))
6911 vty_out (vty, "%ld BGP large-community entries, using %s of memory%s",
2acb4ac2 6912 count,
57d187bc
JS
6913 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6914 count * sizeof (struct lcommunity)),
6915 VTY_NEWLINE);
e52702f2 6916
4bf6a362
PJ
6917 if ((count = mtype_stats_alloc (MTYPE_CLUSTER)))
6918 vty_out (vty, "%ld Cluster lists, using %s of memory%s", count,
6919 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6920 count * sizeof (struct cluster_list)),
6921 VTY_NEWLINE);
e52702f2 6922
4bf6a362
PJ
6923 /* Peer related usage */
6924 count = mtype_stats_alloc (MTYPE_BGP_PEER);
6925 vty_out (vty, "%ld peers, using %s of memory%s", count,
6926 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6927 count * sizeof (struct peer)),
6928 VTY_NEWLINE);
e52702f2 6929
4a1ab8e4 6930 if ((count = mtype_stats_alloc (MTYPE_PEER_GROUP)))
4bf6a362
PJ
6931 vty_out (vty, "%ld peer groups, using %s of memory%s", count,
6932 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6933 count * sizeof (struct peer_group)),
6934 VTY_NEWLINE);
e52702f2 6935
4bf6a362
PJ
6936 /* Other */
6937 if ((count = mtype_stats_alloc (MTYPE_HASH)))
6938 vty_out (vty, "%ld hash tables, using %s of memory%s", count,
6939 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6940 count * sizeof (struct hash)),
6941 VTY_NEWLINE);
6942 if ((count = mtype_stats_alloc (MTYPE_HASH_BACKET)))
6943 vty_out (vty, "%ld hash buckets, using %s of memory%s", count,
6944 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6945 count * sizeof (struct hash_backet)),
6946 VTY_NEWLINE);
6947 if ((count = mtype_stats_alloc (MTYPE_BGP_REGEXP)))
6948 vty_out (vty, "%ld compiled regexes, using %s of memory%s", count,
6949 mtype_memstr (memstrbuf, sizeof (memstrbuf),
6950 count * sizeof (regex_t)),
6951 VTY_NEWLINE);
6952 return CMD_SUCCESS;
6953}
fee0f4c6 6954
718e3744 6955/* Show BGP peer's summary information. */
94f2b392 6956static int
b05a1c8b 6957bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
9f689658 6958 u_char use_json, json_object *json)
718e3744 6959{
6960 struct peer *peer;
1eb8ef25 6961 struct listnode *node, *nnode;
f14e6fdb
DS
6962 unsigned int count = 0, dn_count = 0;
6963 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
f933309e
DW
6964 char neighbor_buf[VTY_BUFSIZ];
6965 int neighbor_col_default_width = 16;
718e3744 6966 int len;
f933309e 6967 int max_neighbor_width = 0;
ffd0c037
DS
6968 json_object *json_peer = NULL;
6969 json_object *json_peers = NULL;
718e3744 6970
b05a1c8b
DS
6971 if (use_json)
6972 {
9f689658
DD
6973 if (json == NULL)
6974 json = json_object_new_object();
6975
f1aa5d8a 6976 json_peers = json_object_new_object();
b05a1c8b 6977 }
f933309e
DW
6978 else
6979 {
6980 /* Loop over all neighbors that will be displayed to determine how many
6981 * characters are needed for the Neighbor column
6982 */
6983 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6984 {
6985 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6986 continue;
6987
6988 if (peer->afc[afi][safi])
6989 {
c9d5bd27
DS
6990 memset(dn_flag, '\0', sizeof(dn_flag));
6991 if (peer_dynamic_neighbor(peer))
6992 dn_flag[0] = '*';
6993
f933309e
DW
6994 if (peer->hostname && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
6995 sprintf(neighbor_buf, "%s%s(%s) ", dn_flag, peer->hostname, peer->host);
6996 else
6997 sprintf(neighbor_buf, "%s%s ", dn_flag, peer->host);
6998
6999 len = strlen(neighbor_buf);
7000
7001 if (len > max_neighbor_width)
7002 max_neighbor_width = len;
7003 }
7004 }
7005
7006 /* Originally we displayed the Neighbor column as 16
7007 * characters wide so make that the default
7008 */
7009 if (max_neighbor_width < neighbor_col_default_width)
7010 max_neighbor_width = neighbor_col_default_width;
7011 }
b05a1c8b 7012
1eb8ef25 7013 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 7014 {
1ff9a340
DS
7015 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7016 continue;
7017
718e3744 7018 if (peer->afc[afi][safi])
7019 {
b05a1c8b 7020 if (!count)
4bf6a362
PJ
7021 {
7022 unsigned long ents;
7023 char memstrbuf[MTYPE_MEMSTR_LEN];
5c81a5f3 7024 int vrf_id_ui;
7025
7026 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
b05a1c8b 7027
4bf6a362 7028 /* Usage summary and header */
b05a1c8b
DS
7029 if (use_json)
7030 {
62d6dca0 7031 json_object_string_add(json, "routerId", inet_ntoa (bgp->router_id));
f1aa5d8a 7032 json_object_int_add(json, "as", bgp->as);
9f689658
DD
7033 json_object_int_add(json, "vrfId", vrf_id_ui);
7034 json_object_string_add(json, "vrfName",
7035 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7036 ? "Default" : bgp->name);
b05a1c8b
DS
7037 }
7038 else
7039 {
7040 vty_out (vty,
5c81a5f3 7041 "BGP router identifier %s, local AS number %u vrf-id %d",
7042 inet_ntoa (bgp->router_id), bgp->as, vrf_id_ui);
6aeb9e78 7043 vty_out (vty, "%s", VTY_NEWLINE);
b05a1c8b
DS
7044 }
7045
f188f2c4
DS
7046 if (bgp_update_delay_configured(bgp))
7047 {
b05a1c8b 7048 if (use_json)
f188f2c4 7049 {
62d6dca0 7050 json_object_int_add(json, "updateDelayLimit", bgp->v_update_delay);
b05a1c8b
DS
7051
7052 if (bgp->v_update_delay != bgp->v_establish_wait)
62d6dca0 7053 json_object_int_add(json, "updateDelayEstablishWait", bgp->v_establish_wait);
b05a1c8b
DS
7054
7055 if (bgp_update_delay_active(bgp))
7056 {
62d6dca0
DS
7057 json_object_string_add(json, "updateDelayFirstNeighbor", bgp->update_delay_begin_time);
7058 json_object_boolean_true_add(json, "updateDelayInProgress");
b05a1c8b
DS
7059 }
7060 else
7061 {
7062 if (bgp->update_delay_over)
7063 {
62d6dca0 7064 json_object_string_add(json, "updateDelayFirstNeighbor",
f1aa5d8a 7065 bgp->update_delay_begin_time);
62d6dca0 7066 json_object_string_add(json, "updateDelayBestpathResumed",
f1aa5d8a 7067 bgp->update_delay_end_time);
62d6dca0 7068 json_object_string_add(json, "updateDelayZebraUpdateResume",
f1aa5d8a 7069 bgp->update_delay_zebra_resume_time);
62d6dca0 7070 json_object_string_add(json, "updateDelayPeerUpdateResume",
f1aa5d8a 7071 bgp->update_delay_peers_resume_time);
b05a1c8b
DS
7072 }
7073 }
f188f2c4
DS
7074 }
7075 else
7076 {
b05a1c8b
DS
7077 vty_out (vty, "Read-only mode update-delay limit: %d seconds%s",
7078 bgp->v_update_delay, VTY_NEWLINE);
7079 if (bgp->v_update_delay != bgp->v_establish_wait)
7080 vty_out (vty, " Establish wait: %d seconds%s",
7081 bgp->v_establish_wait, VTY_NEWLINE);
7082
7083 if (bgp_update_delay_active(bgp))
f188f2c4
DS
7084 {
7085 vty_out (vty, " First neighbor established: %s%s",
7086 bgp->update_delay_begin_time, VTY_NEWLINE);
b05a1c8b
DS
7087 vty_out (vty, " Delay in progress%s", VTY_NEWLINE);
7088 }
7089 else
7090 {
7091 if (bgp->update_delay_over)
7092 {
7093 vty_out (vty, " First neighbor established: %s%s",
7094 bgp->update_delay_begin_time, VTY_NEWLINE);
7095 vty_out (vty, " Best-paths resumed: %s%s",
7096 bgp->update_delay_end_time, VTY_NEWLINE);
7097 vty_out (vty, " zebra update resumed: %s%s",
7098 bgp->update_delay_zebra_resume_time, VTY_NEWLINE);
7099 vty_out (vty, " peers update resumed: %s%s",
7100 bgp->update_delay_peers_resume_time, VTY_NEWLINE);
7101 }
f188f2c4
DS
7102 }
7103 }
7104 }
4bf6a362 7105
b05a1c8b
DS
7106 if (use_json)
7107 {
7108 if (bgp_maxmed_onstartup_configured(bgp) && bgp->maxmed_active)
62d6dca0 7109 json_object_boolean_true_add(json, "maxMedOnStartup");
b05a1c8b 7110 if (bgp->v_maxmed_admin)
62d6dca0 7111 json_object_boolean_true_add(json, "maxMedAdministrative");
b05a1c8b 7112
62d6dca0 7113 json_object_int_add(json, "tableVersion", bgp_table_version(bgp->rib[afi][safi]));
b05a1c8b
DS
7114
7115 ents = bgp_table_count (bgp->rib[afi][safi]);
62d6dca0
DS
7116 json_object_int_add(json, "ribCount", ents);
7117 json_object_int_add(json, "ribMemory", ents * sizeof (struct bgp_node));
b05a1c8b
DS
7118
7119 ents = listcount (bgp->peer);
62d6dca0
DS
7120 json_object_int_add(json, "peerCount", ents);
7121 json_object_int_add(json, "peerMemory", ents * sizeof (struct peer));
b05a1c8b 7122
b05a1c8b
DS
7123 if ((ents = listcount (bgp->group)))
7124 {
62d6dca0
DS
7125 json_object_int_add(json, "peerGroupCount", ents);
7126 json_object_int_add(json, "peerGroupMemory", ents * sizeof (struct peer_group));
b05a1c8b 7127 }
3f9c7369 7128
b05a1c8b 7129 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
62d6dca0 7130 json_object_boolean_true_add(json, "dampeningEnabled");
b05a1c8b
DS
7131 }
7132 else
7133 {
7134 if (bgp_maxmed_onstartup_configured(bgp) && bgp->maxmed_active)
7135 vty_out (vty, "Max-med on-startup active%s", VTY_NEWLINE);
7136 if (bgp->v_maxmed_admin)
7137 vty_out (vty, "Max-med administrative active%s", VTY_NEWLINE);
7138
ffd0c037 7139 vty_out(vty, "BGP table version %" PRIu64 "%s",
b05a1c8b
DS
7140 bgp_table_version(bgp->rib[afi][safi]), VTY_NEWLINE);
7141
7142 ents = bgp_table_count (bgp->rib[afi][safi]);
7143 vty_out (vty, "RIB entries %ld, using %s of memory%s", ents,
7144 mtype_memstr (memstrbuf, sizeof (memstrbuf),
7145 ents * sizeof (struct bgp_node)),
7146 VTY_NEWLINE);
7147
7148 /* Peer related usage */
7149 ents = listcount (bgp->peer);
7150 vty_out (vty, "Peers %ld, using %s of memory%s",
7151 ents,
7152 mtype_memstr (memstrbuf, sizeof (memstrbuf),
7153 ents * sizeof (struct peer)),
7154 VTY_NEWLINE);
7155
b05a1c8b
DS
7156 if ((ents = listcount (bgp->group)))
7157 vty_out (vty, "Peer groups %ld, using %s of memory%s", ents,
7158 mtype_memstr (memstrbuf, sizeof (memstrbuf),
7159 ents * sizeof (struct peer_group)),
7160 VTY_NEWLINE);
7161
7162 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
7163 vty_out (vty, "Dampening enabled.%s", VTY_NEWLINE);
7164 vty_out (vty, "%s", VTY_NEWLINE);
f933309e
DW
7165
7166 /* Subtract 8 here because 'Neighbor' is 8 characters */
7167 vty_out (vty, "Neighbor");
7168 vty_out (vty, "%*s", max_neighbor_width - 8, " ");
7169 vty_out (vty, "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd%s", VTY_NEWLINE);
b05a1c8b 7170 }
4bf6a362 7171 }
e52702f2 7172
b05a1c8b 7173 count++;
718e3744 7174
b05a1c8b
DS
7175 if (use_json)
7176 {
7177 json_peer = json_object_new_object();
f14e6fdb 7178
b05a1c8b 7179 if (peer_dynamic_neighbor(peer))
62d6dca0 7180 json_object_boolean_true_add(json_peer, "dynamicPeer");
b05a1c8b 7181
04b6bdc0
DW
7182 if (peer->hostname)
7183 json_object_string_add(json_peer, "hostname", peer->hostname);
7184
7185 if (peer->domainname)
7186 json_object_string_add(json_peer, "domainname", peer->domainname);
7187
62d6dca0 7188 json_object_int_add(json_peer, "remoteAs", peer->as);
f1aa5d8a 7189 json_object_int_add(json_peer, "version", 4);
62d6dca0 7190 json_object_int_add(json_peer, "msgRcvd",
f1aa5d8a
DS
7191 peer->open_in + peer->update_in + peer->keepalive_in
7192 + peer->notify_in + peer->refresh_in
7193 + peer->dynamic_cap_in);
62d6dca0 7194 json_object_int_add(json_peer, "msgSent",
f1aa5d8a
DS
7195 peer->open_out + peer->update_out + peer->keepalive_out
7196 + peer->notify_out + peer->refresh_out
7197 + peer->dynamic_cap_out);
7198
62d6dca0 7199 json_object_int_add(json_peer, "tableVersion", peer->version[afi][safi]);
f1aa5d8a
DS
7200 json_object_int_add(json_peer, "outq", peer->obuf->count);
7201 json_object_int_add(json_peer, "inq", 0);
856ca177 7202 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN, use_json, json_peer);
62d6dca0 7203 json_object_int_add(json_peer, "prefixReceivedCount", peer->pcount[afi][safi]);
b05a1c8b
DS
7204
7205 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
f1aa5d8a 7206 json_object_string_add(json_peer, "state", "Idle (Admin)");
b05a1c8b 7207 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
f1aa5d8a 7208 json_object_string_add(json_peer, "state", "Idle (PfxCt)");
b05a1c8b 7209 else
f1aa5d8a 7210 json_object_string_add(json_peer, "state", LOOKUP(bgp_status_msg, peer->status));
b05a1c8b 7211
f1aa5d8a 7212 if (peer->conf_if)
62d6dca0 7213 json_object_string_add(json_peer, "idType", "interface");
f1aa5d8a 7214 else if (peer->su.sa.sa_family == AF_INET)
62d6dca0 7215 json_object_string_add(json_peer, "idType", "ipv4");
f1aa5d8a 7216 else if (peer->su.sa.sa_family == AF_INET6)
62d6dca0 7217 json_object_string_add(json_peer, "idType", "ipv6");
b05a1c8b 7218
f1aa5d8a 7219 json_object_object_add(json_peers, peer->host, json_peer);
b05a1c8b
DS
7220 }
7221 else
7222 {
7223 memset(dn_flag, '\0', sizeof(dn_flag));
7224 if (peer_dynamic_neighbor(peer))
7225 {
7226 dn_count++;
7227 dn_flag[0] = '*';
7228 }
7229
04b6bdc0
DW
7230 if (peer->hostname && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
7231 len = vty_out (vty, "%s%s(%s)", dn_flag, peer->hostname,
7232 peer->host);
7233 else
7234 len = vty_out (vty, "%s%s", dn_flag, peer->host);
b05a1c8b 7235
f933309e
DW
7236 /* pad the neighbor column with spaces */
7237 if (len < max_neighbor_width)
7238 vty_out (vty, "%*s", max_neighbor_width - len, " ");
b05a1c8b 7239
f933309e 7240 vty_out (vty, "4 %10u %7d %7d %8" PRIu64 " %4d %4zd %8s",
b05a1c8b
DS
7241 peer->as,
7242 peer->open_in + peer->update_in + peer->keepalive_in
7243 + peer->notify_in + peer->refresh_in
7244 + peer->dynamic_cap_in,
7245 peer->open_out + peer->update_out + peer->keepalive_out
7246 + peer->notify_out + peer->refresh_out
7247 + peer->dynamic_cap_out,
7248 peer->version[afi][safi],
7249 0,
f933309e 7250 peer->obuf->count,
856ca177 7251 peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
b05a1c8b
DS
7252
7253 if (peer->status == Established)
46f8c104 7254 vty_out (vty, " %12ld", peer->pcount[afi][safi]);
b05a1c8b
DS
7255 else
7256 {
7257 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
7258 vty_out (vty, " Idle (Admin)");
7259 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
7260 vty_out (vty, " Idle (PfxCt)");
7261 else
f933309e 7262 vty_out (vty, " %12s", LOOKUP(bgp_status_msg, peer->status));
b05a1c8b
DS
7263 }
7264 vty_out (vty, "%s", VTY_NEWLINE);
7265 }
718e3744 7266 }
7267 }
7268
b05a1c8b
DS
7269 if (use_json)
7270 {
7271 json_object_object_add(json, "peers", json_peers);
14151a32 7272
62d6dca0
DS
7273 json_object_int_add(json, "totalPeers", count);
7274 json_object_int_add(json, "dynamicPeers", dn_count);
14151a32 7275
2aac5767 7276 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
f1aa5d8a 7277 json_object_free(json);
b05a1c8b
DS
7278 }
7279 else
f14e6fdb 7280 {
b05a1c8b
DS
7281 if (count)
7282 vty_out (vty, "%sTotal number of neighbors %d%s", VTY_NEWLINE,
7283 count, VTY_NEWLINE);
7284 else
9f689658
DD
7285 {
7286 if (use_json)
7287 vty_out(vty, "{\"error\": {\"message\": \"No %s neighbor configured\"}}%s",
46f296b4 7288 afi_safi_print(afi, safi), VTY_NEWLINE);
9f689658
DD
7289 else
7290 vty_out (vty, "No %s neighbor is configured%s",
46f296b4 7291 afi_safi_print(afi, safi), VTY_NEWLINE);
9f689658 7292 }
b05a1c8b 7293
9f689658 7294 if (dn_count && ! use_json)
b05a1c8b
DS
7295 {
7296 vty_out(vty, "* - dynamic neighbor%s", VTY_NEWLINE);
7297 vty_out(vty,
7298 "%d dynamic neighbor(s), limit %d%s",
7299 dn_count, bgp->dynamic_neighbors_limit, VTY_NEWLINE);
7300 }
f14e6fdb
DS
7301 }
7302
718e3744 7303 return CMD_SUCCESS;
7304}
7305
798c3572
DS
7306/*
7307 * Return if we have a peer configured to use this afi/safi
7308 */
7309static int
7310bgp_show_summary_afi_safi_peer_exists (struct bgp *bgp, int afi, int safi)
7311{
7312 struct listnode *node;
7313 struct peer *peer;
7314
7315 for (ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer))
7316 {
7317 if (!CHECK_FLAG (peer->flags, PEER_FLAG_CONFIG_NODE))
7318 continue;
7319
7320 if (peer->afc[afi][safi])
7321 return 1;
7322 }
7323
7324 return 0;
7325}
7326
27162734
LB
7327static void
7328bgp_show_summary_afi_safi (struct vty *vty, struct bgp *bgp, int afi, int safi,
7329 u_char use_json, json_object *json)
7330{
7331 int is_first = 1;
7332 int afi_wildcard = (afi == AFI_MAX);
7333 int safi_wildcard = (safi == SAFI_MAX);
7334 int is_wildcard = (afi_wildcard || safi_wildcard);
5ce77b2b 7335 bool json_output = false;
798c3572 7336
27162734
LB
7337 if (use_json && is_wildcard)
7338 vty_out (vty, "{%s", VTY_NEWLINE);
7339 if (afi_wildcard)
7340 afi = 1; /* AFI_IP */
7341 while (afi < AFI_MAX)
7342 {
7343 if (safi_wildcard)
7344 safi = 1; /* SAFI_UNICAST */
7345 while (safi < SAFI_MAX)
7346 {
798c3572 7347 if (bgp_show_summary_afi_safi_peer_exists (bgp, afi, safi))
27162734 7348 {
5ce77b2b 7349 json_output = true;
798c3572 7350 if (is_wildcard)
27162734 7351 {
798c3572
DS
7352 /*
7353 * So limit output to those afi/safi pairs that
7354 * actualy have something interesting in them
7355 */
7356 if (use_json)
7357 {
7358 json = json_object_new_object();
27162734 7359
798c3572
DS
7360 if (! is_first)
7361 vty_out (vty, ",%s", VTY_NEWLINE);
7362 else
7363 is_first = 0;
27162734 7364
798c3572
DS
7365 vty_out(vty, "\"%s\":", afi_safi_json(afi, safi));
7366 }
7367 else
7368 {
7369 vty_out (vty, "%s%s Summary:%s",
7370 VTY_NEWLINE, afi_safi_print(afi, safi), VTY_NEWLINE);
7371 }
27162734 7372 }
798c3572 7373 bgp_show_summary (vty, bgp, afi, safi, use_json, json);
27162734 7374 }
f62a5c33
LB
7375 safi++;
7376 if (safi == SAFI_RESERVED_4 ||
7377 safi == SAFI_RESERVED_5) /* handle special cases to match zebra.h */
7378 safi++;
27162734
LB
7379 if (! safi_wildcard)
7380 safi = SAFI_MAX;
7381 }
7382 afi++;
7383 if (! afi_wildcard ||
5ef6cd69 7384 afi == AFI_L2VPN) /* special case, not handled yet */
27162734
LB
7385 afi = AFI_MAX;
7386 }
7387
7388 if (use_json && is_wildcard)
7389 vty_out (vty, "}%s", VTY_NEWLINE);
5ce77b2b
DS
7390 else if (use_json && !json_output)
7391 vty_out (vty, "{}%s", VTY_NEWLINE);
27162734
LB
7392}
7393
f186de26 7394static void
7395bgp_show_all_instances_summary_vty (struct vty *vty, afi_t afi, safi_t safi,
7396 u_char use_json)
7397{
7398 struct listnode *node, *nnode;
7399 struct bgp *bgp;
9f689658
DD
7400 json_object *json = NULL;
7401 int is_first = 1;
7402
7403 if (use_json)
7404 vty_out (vty, "{%s", VTY_NEWLINE);
f186de26 7405
7406 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
7407 {
9f689658
DD
7408 if (use_json)
7409 {
4fb25c53 7410 json = json_object_new_object();
9f689658
DD
7411
7412 if (! is_first)
7413 vty_out (vty, ",%s", VTY_NEWLINE);
7414 else
7415 is_first = 0;
7416
7417 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7418 ? "Default" : bgp->name);
7419 }
7420 else
7421 {
7422 vty_out (vty, "%sInstance %s:%s",
7423 VTY_NEWLINE,
7424 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7425 ? "Default" : bgp->name, VTY_NEWLINE);
7426 }
27162734 7427 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, json);
f186de26 7428 }
9f689658
DD
7429
7430 if (use_json)
7431 vty_out (vty, "}%s", VTY_NEWLINE);
7432
f186de26 7433}
7434
4fb25c53
DW
7435static int
7436bgp_show_summary_vty (struct vty *vty, const char *name,
7437 afi_t afi, safi_t safi, u_char use_json)
7438{
7439 struct bgp *bgp;
7440
7441 if (name)
7442 {
7443 if (strmatch(name, "all"))
7444 {
7445 bgp_show_all_instances_summary_vty (vty, afi, safi, use_json);
7446 return CMD_SUCCESS;
7447 }
7448 else
7449 {
7450 bgp = bgp_lookup_by_name (name);
7451
7452 if (! bgp)
7453 {
7454 if (use_json)
7455 vty_out (vty, "{}%s", VTY_NEWLINE);
7456 else
7457 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
7458 return CMD_WARNING;
7459 }
7460
27162734 7461 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL);
4fb25c53
DW
7462 return CMD_SUCCESS;
7463 }
7464 }
7465
7466 bgp = bgp_get_default ();
7467
7468 if (bgp)
27162734 7469 bgp_show_summary_afi_safi (vty, bgp, afi, safi, use_json, NULL);
4fb25c53
DW
7470
7471 return CMD_SUCCESS;
7472}
7473
716b2d8a 7474/* `show [ip] bgp summary' commands. */
47fc97cc 7475DEFUN (show_ip_bgp_summary,
718e3744 7476 show_ip_bgp_summary_cmd,
18c57037 7477 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] summary [json]",
718e3744 7478 SHOW_STR
7479 IP_STR
7480 BGP_STR
8386ac43 7481 BGP_INSTANCE_HELP_STR
46f296b4
LB
7482 BGP_AFI_HELP_STR
7483 BGP_SAFI_HELP_STR
b05a1c8b 7484 "Summary of BGP neighbor status\n"
9973d184 7485 JSON_STR)
718e3744 7486{
74ca3d33 7487 char *vrf = NULL;
27162734
LB
7488 afi_t afi = AFI_MAX;
7489 safi_t safi = SAFI_MAX;
ae19d7dd
QY
7490
7491 int idx = 0;
7492
7493 /* show [ip] bgp */
7494 if (argv_find (argv, argc, "ip", &idx))
7495 afi = AFI_IP;
18c57037 7496 /* [<view|vrf> VIEWVRFNAME] */
ae19d7dd
QY
7497 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
7498 vrf = argv[++idx]->arg;
46f296b4
LB
7499 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7500 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
ae19d7dd 7501 {
46f296b4 7502 argv_find_and_parse_safi (argv, argc, &idx, &safi);
91d37724
QY
7503 }
7504
ae19d7dd 7505 int uj = use_json (argc, argv);
74ca3d33
DW
7506
7507 return bgp_show_summary_vty (vty, vrf, afi, safi, uj);
718e3744 7508}
7509
fd79ac91 7510const char *
538621f2 7511afi_safi_print (afi_t afi, safi_t safi)
7512{
7513 if (afi == AFI_IP && safi == SAFI_UNICAST)
7514 return "IPv4 Unicast";
7515 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7516 return "IPv4 Multicast";
b60f5275
DS
7517 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7518 return "IPv4 labeled-unicast";
538621f2 7519 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
46f296b4 7520 return "IPv4 VPN";
8b1fb8be 7521 else if (afi == AFI_IP && safi == SAFI_ENCAP)
46f296b4 7522 return "IPv4 Encap";
538621f2 7523 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7524 return "IPv6 Unicast";
7525 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7526 return "IPv6 Multicast";
b60f5275
DS
7527 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7528 return "IPv6 labeled-unicast";
945c8fe9 7529 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
46f296b4 7530 return "IPv6 VPN";
8b1fb8be 7531 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
46f296b4 7532 return "IPv6 Encap";
3d6c0dfa
PG
7533 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7534 return "L2VPN EVPN";
538621f2 7535 else
7536 return "Unknown";
7537}
7538
b9f77ec8
DS
7539/*
7540 * Please note that we have intentionally camelCased
7541 * the return strings here. So if you want
7542 * to use this function, please ensure you
7543 * are doing this within json output
7544 */
27162734
LB
7545const char *
7546afi_safi_json (afi_t afi, safi_t safi)
7547{
7548 if (afi == AFI_IP && safi == SAFI_UNICAST)
b9f77ec8 7549 return "ipv4Unicast";
27162734 7550 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
b9f77ec8 7551 return "ipv4Multicast";
b60f5275 7552 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
05ba625a 7553 return "ipv4LabeledUnicast";
27162734 7554 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
b9f77ec8 7555 return "ipv4Vpn";
27162734 7556 else if (afi == AFI_IP && safi == SAFI_ENCAP)
b9f77ec8 7557 return "ipv4Encap";
27162734 7558 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
b9f77ec8 7559 return "ipv6Unicast";
27162734 7560 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
b9f77ec8 7561 return "ipv6Multicast";
b60f5275 7562 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
05ba625a 7563 return "ipv6LabeledUnicast";
27162734 7564 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
b9f77ec8 7565 return "ipv6Vpn";
27162734 7566 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
b9f77ec8 7567 return "ipv6Encap";
3d6c0dfa 7568 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
b9f77ec8 7569 return "l2VpnEvpn";
27162734
LB
7570 else
7571 return "Unknown";
7572}
7573
718e3744 7574/* Show BGP peer's information. */
7575enum show_type
7576{
7577 show_all,
7578 show_peer
7579};
7580
94f2b392 7581static void
856ca177
MS
7582bgp_show_peer_afi_orf_cap (struct vty *vty, struct peer *p, afi_t afi, safi_t safi,
7583 u_int16_t adv_smcap, u_int16_t adv_rmcap, u_int16_t rcv_smcap,
7584 u_int16_t rcv_rmcap, u_char use_json, json_object *json_pref)
718e3744 7585{
7586 /* Send-Mode */
7587 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap)
7588 || CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
7589 {
856ca177
MS
7590 if (use_json)
7591 {
7592 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap) && CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
7593 json_object_string_add(json_pref, "sendMode", "advertisedAndReceived");
7594 else if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap))
7595 json_object_string_add(json_pref, "sendMode", "advertised");
7596 else if (CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
7597 json_object_string_add(json_pref, "sendMode", "received");
7598 }
7599 else
7600 {
7601 vty_out (vty, " Send-mode: ");
7602 if (CHECK_FLAG (p->af_cap[afi][safi], adv_smcap))
7603 vty_out (vty, "advertised");
7604 if (CHECK_FLAG (p->af_cap[afi][safi], rcv_smcap))
7605 vty_out (vty, "%sreceived",
7606 CHECK_FLAG (p->af_cap[afi][safi], adv_smcap) ?
7607 ", " : "");
7608 vty_out (vty, "%s", VTY_NEWLINE);
7609 }
718e3744 7610 }
7611
7612 /* Receive-Mode */
7613 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap)
7614 || CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
7615 {
856ca177
MS
7616 if (use_json)
7617 {
7618 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap) && CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
7619 json_object_string_add(json_pref, "recvMode", "advertisedAndReceived");
7620 else if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap))
7621 json_object_string_add(json_pref, "recvMode", "advertised");
7622 else if (CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
7623 json_object_string_add(json_pref, "recvMode", "received");
7624 }
7625 else
7626 {
7627 vty_out (vty, " Receive-mode: ");
7628 if (CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap))
7629 vty_out (vty, "advertised");
7630 if (CHECK_FLAG (p->af_cap[afi][safi], rcv_rmcap))
7631 vty_out (vty, "%sreceived",
7632 CHECK_FLAG (p->af_cap[afi][safi], adv_rmcap) ?
7633 ", " : "");
7634 vty_out (vty, "%s", VTY_NEWLINE);
7635 }
718e3744 7636 }
7637}
7638
94f2b392 7639static void
856ca177
MS
7640bgp_show_peer_afi (struct vty *vty, struct peer *p, afi_t afi, safi_t safi,
7641 u_char use_json, json_object *json_neigh)
718e3744 7642{
7643 struct bgp_filter *filter;
3f9c7369 7644 struct peer_af *paf;
718e3744 7645 char orf_pfx_name[BUFSIZ];
7646 int orf_pfx_count;
856ca177
MS
7647 json_object *json_af = NULL;
7648 json_object *json_prefA = NULL;
7649 json_object *json_prefB = NULL;
7650 json_object *json_addr = NULL;
718e3744 7651
856ca177
MS
7652 if (use_json)
7653 {
7654 json_addr = json_object_new_object();
7655 json_af = json_object_new_object();
856ca177 7656 filter = &p->filter[afi][safi];
718e3744 7657
c8560b44 7658 if (peer_group_active(p))
856ca177 7659 json_object_string_add(json_addr, "peerGroupMember", p->group->name);
538621f2 7660
856ca177
MS
7661 paf = peer_af_find(p, afi, safi);
7662 if (paf && PAF_SUBGRP(paf))
7663 {
7664 json_object_int_add(json_addr, "updateGroupId", PAF_UPDGRP(paf)->id);
7665 json_object_int_add(json_addr, "subGroupId", PAF_SUBGRP(paf)->id);
7666 json_object_int_add(json_addr, "packetQueueLength", bpacket_queue_virtual_length(paf));
7667 }
7668
7669 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7670 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7671 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7672 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV))
7673 {
7674 json_object_int_add(json_af, "orfType", ORF_TYPE_PREFIX);
b6df4090 7675 json_prefA = json_object_new_object();
856ca177
MS
7676 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7677 PEER_CAP_ORF_PREFIX_SM_ADV,
7678 PEER_CAP_ORF_PREFIX_RM_ADV,
7679 PEER_CAP_ORF_PREFIX_SM_RCV,
7680 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, json_prefA);
7681 json_object_object_add(json_af, "orfPrefixList", json_prefA);
7682 }
7683
7684 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7685 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7686 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7687 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7688 {
7689 json_object_int_add(json_af, "orfOldType", ORF_TYPE_PREFIX_OLD);
b6df4090 7690 json_prefB = json_object_new_object();
856ca177
MS
7691 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7692 PEER_CAP_ORF_PREFIX_SM_ADV,
7693 PEER_CAP_ORF_PREFIX_RM_ADV,
7694 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7695 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, json_prefB);
7696 json_object_object_add(json_af, "orfOldPrefixList", json_prefB);
7697 }
7698
7699 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7700 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7701 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7702 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7703 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)
7704 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7705 json_object_object_add(json_addr, "afDependentCap", json_af);
b6df4090
DS
7706 else
7707 json_object_free(json_af);
856ca177
MS
7708
7709 sprintf (orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7710 orf_pfx_count = prefix_bgp_show_prefix_list (NULL, afi, orf_pfx_name, use_json);
7711
7712 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND)
7713 || orf_pfx_count)
7714 {
7715 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND))
7716 json_object_boolean_true_add(json_neigh, "orfSent");
7717 if (orf_pfx_count)
7718 json_object_int_add(json_addr, "orfRecvCounter", orf_pfx_count);
7719 }
7720 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
7721 json_object_string_add(json_addr, "orfFirstUpdate", "deferredUntilORFOrRouteRefreshRecvd");
7722
7723 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7724 json_object_boolean_true_add(json_addr, "routeReflectorClient");
7725 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7726 json_object_boolean_true_add(json_addr, "routeServerClient");
7727 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7728 json_object_boolean_true_add(json_addr, "inboundSoftConfigPermit");
7729
88b8ed8d
DW
7730 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7731 json_object_boolean_true_add(json_addr, "privateAsNumsAllReplacedInUpdatesToNbr");
7732 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
856ca177 7733 json_object_boolean_true_add(json_addr, "privateAsNumsReplacedInUpdatesToNbr");
88b8ed8d
DW
7734 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7735 json_object_boolean_true_add(json_addr, "privateAsNumsAllRemovedInUpdatesToNbr");
856ca177
MS
7736 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS))
7737 json_object_boolean_true_add(json_addr, "privateAsNumsRemovedInUpdatesToNbr");
7738
adbac85e
DW
7739 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7740 json_object_boolean_true_add(json_addr, "addpathTxAllPaths");
7741
06370dac
DW
7742 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7743 json_object_boolean_true_add(json_addr, "addpathTxBestpathPerAS");
7744
856ca177
MS
7745 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7746 json_object_string_add(json_addr, "overrideASNsInOutboundUpdates", "ifAspathEqualRemoteAs");
7747
7748 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
7749 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
7750 json_object_boolean_true_add(json_addr, "routerAlwaysNextHop");
7751 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED))
7752 json_object_boolean_true_add(json_addr, "unchangedAsPathPropogatedToNbr");
7753 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
7754 json_object_boolean_true_add(json_addr, "unchangedNextHopPropogatedToNbr");
7755 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7756 json_object_boolean_true_add(json_addr, "unchangedMedPropogatedToNbr");
718e3744 7757 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
856ca177
MS
7758 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7759 {
7760 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7761 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7762 json_object_string_add(json_addr, "commAttriSentToNbr", "extendedAndStandard");
7763 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7764 json_object_string_add(json_addr, "commAttriSentToNbr", "extended");
7765 else
7766 json_object_string_add(json_addr, "commAttriSentToNbr", "standard");
7767 }
7768 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
7769 {
7770 if (p->default_rmap[afi][safi].name)
7771 json_object_string_add(json_addr, "defaultRouteMap", p->default_rmap[afi][safi].name);
7772
7773 if (paf && PAF_SUBGRP(paf) && CHECK_FLAG(PAF_SUBGRP(paf)->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
7774 json_object_boolean_true_add(json_addr, "defaultSent");
7775 else
7776 json_object_boolean_true_add(json_addr, "defaultNotSent");
7777 }
7778
7779 if (filter->plist[FILTER_IN].name
7780 || filter->dlist[FILTER_IN].name
7781 || filter->aslist[FILTER_IN].name
7782 || filter->map[RMAP_IN].name)
7783 json_object_boolean_true_add(json_addr, "inboundPathPolicyConfig");
7784 if (filter->plist[FILTER_OUT].name
7785 || filter->dlist[FILTER_OUT].name
7786 || filter->aslist[FILTER_OUT].name
7787 || filter->map[RMAP_OUT].name
7788 || filter->usmap.name)
7789 json_object_boolean_true_add(json_addr, "outboundPathPolicyConfig");
856ca177
MS
7790
7791 /* prefix-list */
7792 if (filter->plist[FILTER_IN].name)
7793 json_object_string_add(json_addr, "incomingUpdatePrefixFilterList", filter->plist[FILTER_IN].name);
7794 if (filter->plist[FILTER_OUT].name)
7795 json_object_string_add(json_addr, "outgoingUpdatePrefixFilterList", filter->plist[FILTER_OUT].name);
7796
7797 /* distribute-list */
7798 if (filter->dlist[FILTER_IN].name)
7799 json_object_string_add(json_addr, "incomingUpdateNetworkFilterList", filter->dlist[FILTER_IN].name);
7800 if (filter->dlist[FILTER_OUT].name)
7801 json_object_string_add(json_addr, "outgoingUpdateNetworkFilterList", filter->dlist[FILTER_OUT].name);
7802
7803 /* filter-list. */
7804 if (filter->aslist[FILTER_IN].name)
7805 json_object_string_add(json_addr, "incomingUpdateAsPathFilterList", filter->aslist[FILTER_IN].name);
7806 if (filter->aslist[FILTER_OUT].name)
7807 json_object_string_add(json_addr, "outgoingUpdateAsPathFilterList", filter->aslist[FILTER_OUT].name);
7808
7809 /* route-map. */
7810 if (filter->map[RMAP_IN].name)
7811 json_object_string_add(json_addr, "routeMapForIncomingAdvertisements", filter->map[RMAP_IN].name);
7812 if (filter->map[RMAP_OUT].name)
7813 json_object_string_add(json_addr, "routeMapForOutgoingAdvertisements", filter->map[RMAP_OUT].name);
856ca177
MS
7814
7815 /* unsuppress-map */
7816 if (filter->usmap.name)
7817 json_object_string_add(json_addr, "selectiveUnsuppressRouteMap", filter->usmap.name);
7818
7819 /* Receive prefix count */
7820 json_object_int_add(json_addr, "acceptedPrefixCounter", p->pcount[afi][safi]);
7821
7822 /* Maximum prefix */
7823 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
7824 {
7825 json_object_int_add(json_addr, "prefixAllowedMax", p->pmax[afi][safi]);
7826 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
7827 json_object_boolean_true_add(json_addr, "prefixAllowedMaxWarning");
7828 json_object_int_add(json_addr, "prefixAllowedWarningThresh", p->pmax_threshold[afi][safi]);
7829 if (p->pmax_restart[afi][safi])
7830 json_object_int_add(json_addr, "prefixAllowedRestartIntervalMsecs", p->pmax_restart[afi][safi] * 60000);
7831 }
7832 json_object_object_add(json_neigh, afi_safi_print (afi, safi), json_addr);
7833
7834 }
7835 else
7836 {
7837 filter = &p->filter[afi][safi];
7838
7839 vty_out (vty, " For address family: %s%s", afi_safi_print (afi, safi),
7840 VTY_NEWLINE);
7841
c8560b44 7842 if (peer_group_active(p))
856ca177
MS
7843 vty_out (vty, " %s peer-group member%s", p->group->name, VTY_NEWLINE);
7844
7845 paf = peer_af_find(p, afi, safi);
7846 if (paf && PAF_SUBGRP(paf))
7847 {
7848 vty_out (vty, " Update group %" PRIu64 ", subgroup %" PRIu64 "%s",
7849 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id, VTY_NEWLINE);
7850 vty_out (vty, " Packet Queue length %d%s",
7851 bpacket_queue_virtual_length(paf), VTY_NEWLINE);
7852 }
718e3744 7853 else
856ca177
MS
7854 {
7855 vty_out(vty, " Not part of any update group%s", VTY_NEWLINE);
7856 }
7857 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7858 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7859 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7860 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7861 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)
7862 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7863 vty_out (vty, " AF-dependant capabilities:%s", VTY_NEWLINE);
7864
7865 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7866 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
7867 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7868 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV))
7869 {
7870 vty_out (vty, " Outbound Route Filter (ORF) type (%d) Prefix-list:%s",
7871 ORF_TYPE_PREFIX, VTY_NEWLINE);
7872 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7873 PEER_CAP_ORF_PREFIX_SM_ADV,
7874 PEER_CAP_ORF_PREFIX_RM_ADV,
7875 PEER_CAP_ORF_PREFIX_SM_RCV,
7876 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7877 }
7878 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7879 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7880 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
7881 || CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7882 {
7883 vty_out (vty, " Outbound Route Filter (ORF) type (%d) Prefix-list:%s",
7884 ORF_TYPE_PREFIX_OLD, VTY_NEWLINE);
7885 bgp_show_peer_afi_orf_cap (vty, p, afi, safi,
7886 PEER_CAP_ORF_PREFIX_SM_ADV,
7887 PEER_CAP_ORF_PREFIX_RM_ADV,
7888 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7889 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7890 }
718e3744 7891
856ca177
MS
7892 sprintf (orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7893 orf_pfx_count = prefix_bgp_show_prefix_list (NULL, afi, orf_pfx_name, use_json);
718e3744 7894
856ca177
MS
7895 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND)
7896 || orf_pfx_count)
7897 {
7898 vty_out (vty, " Outbound Route Filter (ORF):");
7899 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_PREFIX_SEND))
7900 vty_out (vty, " sent;");
7901 if (orf_pfx_count)
7902 vty_out (vty, " received (%d entries)", orf_pfx_count);
7903 vty_out (vty, "%s", VTY_NEWLINE);
7904 }
7905 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
7906 vty_out (vty, " First update is deferred until ORF or ROUTE-REFRESH is received%s", VTY_NEWLINE);
7907
7908 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
7909 vty_out (vty, " Route-Reflector Client%s", VTY_NEWLINE);
7910 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
7911 vty_out (vty, " Route-Server Client%s", VTY_NEWLINE);
7912 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7913 vty_out (vty, " Inbound soft reconfiguration allowed%s", VTY_NEWLINE);
7914
88b8ed8d
DW
7915 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7916 vty_out (vty, " Private AS numbers (all) replaced in updates to this neighbor%s", VTY_NEWLINE);
7917 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
856ca177 7918 vty_out (vty, " Private AS numbers replaced in updates to this neighbor%s", VTY_NEWLINE);
88b8ed8d
DW
7919 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7920 vty_out (vty, " Private AS numbers (all) removed in updates to this neighbor%s", VTY_NEWLINE);
856ca177
MS
7921 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS))
7922 vty_out (vty, " Private AS numbers removed in updates to this neighbor%s", VTY_NEWLINE);
7923
adbac85e
DW
7924 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7925 vty_out (vty, " Advertise all paths via addpath%s", VTY_NEWLINE);
7926
06370dac
DW
7927 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7928 vty_out (vty, " Advertise bestpath per AS via addpath%s", VTY_NEWLINE);
7929
856ca177
MS
7930 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7931 vty_out (vty, " Override ASNs in outbound updates if aspath equals remote-as%s", VTY_NEWLINE);
7932
7933 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF) ||
7934 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_FORCE_NEXTHOP_SELF))
7935 vty_out (vty, " NEXT_HOP is always this router%s", VTY_NEWLINE);
7936 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED))
7937 vty_out (vty, " AS_PATH is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7938 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED))
7939 vty_out (vty, " NEXT_HOP is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7940 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7941 vty_out (vty, " MED is propagated unchanged to this neighbor%s", VTY_NEWLINE);
7942 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
57d187bc
JS
7943 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)
7944 || CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
856ca177
MS
7945 {
7946 vty_out (vty, " Community attribute sent to this neighbor");
7947 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
57d187bc
JS
7948 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)
7949 && CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
7950 vty_out (vty, "(all)%s", VTY_NEWLINE);
7951 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY))
7952 vty_out (vty, "(large)%s", VTY_NEWLINE);
856ca177
MS
7953 else if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY))
7954 vty_out (vty, "(extended)%s", VTY_NEWLINE);
7955 else
7956 vty_out (vty, "(standard)%s", VTY_NEWLINE);
7957 }
7958 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
7959 {
7960 vty_out (vty, " Default information originate,");
7961
7962 if (p->default_rmap[afi][safi].name)
7963 vty_out (vty, " default route-map %s%s,",
7964 p->default_rmap[afi][safi].map ? "*" : "",
7965 p->default_rmap[afi][safi].name);
7966 if (paf && PAF_SUBGRP(paf) && CHECK_FLAG(PAF_SUBGRP(paf)->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE))
7967 vty_out (vty, " default sent%s", VTY_NEWLINE);
7968 else
7969 vty_out (vty, " default not sent%s", VTY_NEWLINE);
7970 }
718e3744 7971
856ca177
MS
7972 if (filter->plist[FILTER_IN].name
7973 || filter->dlist[FILTER_IN].name
7974 || filter->aslist[FILTER_IN].name
7975 || filter->map[RMAP_IN].name)
7976 vty_out (vty, " Inbound path policy configured%s", VTY_NEWLINE);
7977 if (filter->plist[FILTER_OUT].name
7978 || filter->dlist[FILTER_OUT].name
7979 || filter->aslist[FILTER_OUT].name
7980 || filter->map[RMAP_OUT].name
7981 || filter->usmap.name)
7982 vty_out (vty, " Outbound path policy configured%s", VTY_NEWLINE);
856ca177
MS
7983
7984 /* prefix-list */
7985 if (filter->plist[FILTER_IN].name)
7986 vty_out (vty, " Incoming update prefix filter list is %s%s%s",
7987 filter->plist[FILTER_IN].plist ? "*" : "",
7988 filter->plist[FILTER_IN].name,
7989 VTY_NEWLINE);
7990 if (filter->plist[FILTER_OUT].name)
7991 vty_out (vty, " Outgoing update prefix filter list is %s%s%s",
7992 filter->plist[FILTER_OUT].plist ? "*" : "",
7993 filter->plist[FILTER_OUT].name,
7994 VTY_NEWLINE);
7995
7996 /* distribute-list */
7997 if (filter->dlist[FILTER_IN].name)
7998 vty_out (vty, " Incoming update network filter list is %s%s%s",
7999 filter->dlist[FILTER_IN].alist ? "*" : "",
8000 filter->dlist[FILTER_IN].name,
8001 VTY_NEWLINE);
8002 if (filter->dlist[FILTER_OUT].name)
8003 vty_out (vty, " Outgoing update network filter list is %s%s%s",
8004 filter->dlist[FILTER_OUT].alist ? "*" : "",
8005 filter->dlist[FILTER_OUT].name,
8006 VTY_NEWLINE);
8007
8008 /* filter-list. */
8009 if (filter->aslist[FILTER_IN].name)
8010 vty_out (vty, " Incoming update AS path filter list is %s%s%s",
8011 filter->aslist[FILTER_IN].aslist ? "*" : "",
8012 filter->aslist[FILTER_IN].name,
8013 VTY_NEWLINE);
8014 if (filter->aslist[FILTER_OUT].name)
8015 vty_out (vty, " Outgoing update AS path filter list is %s%s%s",
8016 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8017 filter->aslist[FILTER_OUT].name,
8018 VTY_NEWLINE);
8019
8020 /* route-map. */
8021 if (filter->map[RMAP_IN].name)
8022 vty_out (vty, " Route map for incoming advertisements is %s%s%s",
8023 filter->map[RMAP_IN].map ? "*" : "",
8024 filter->map[RMAP_IN].name,
8025 VTY_NEWLINE);
8026 if (filter->map[RMAP_OUT].name)
8027 vty_out (vty, " Route map for outgoing advertisements is %s%s%s",
8028 filter->map[RMAP_OUT].map ? "*" : "",
8029 filter->map[RMAP_OUT].name,
8030 VTY_NEWLINE);
856ca177
MS
8031
8032 /* unsuppress-map */
8033 if (filter->usmap.name)
8034 vty_out (vty, " Route map for selective unsuppress is %s%s%s",
8035 filter->usmap.map ? "*" : "",
8036 filter->usmap.name, VTY_NEWLINE);
8037
8038 /* Receive prefix count */
8039 vty_out (vty, " %ld accepted prefixes%s", p->pcount[afi][safi], VTY_NEWLINE);
8040
8041 /* Maximum prefix */
8042 if (CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
8043 {
8044 vty_out (vty, " Maximum prefixes allowed %ld%s%s", p->pmax[afi][safi],
8045 CHECK_FLAG (p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)
8046 ? " (warning-only)" : "", VTY_NEWLINE);
8047 vty_out (vty, " Threshold for warning message %d%%",
8048 p->pmax_threshold[afi][safi]);
8049 if (p->pmax_restart[afi][safi])
8050 vty_out (vty, ", restart interval %d min", p->pmax_restart[afi][safi]);
8051 vty_out (vty, "%s", VTY_NEWLINE);
8052 }
718e3744 8053
0a486e5f 8054 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 8055 }
718e3744 8056}
8057
94f2b392 8058static void
e8f7da3a 8059bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *json)
718e3744 8060{
8061 struct bgp *bgp;
4690c7d7 8062 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
718e3744 8063 char timebuf[BGP_UPTIME_LEN];
f14e6fdb 8064 char dn_flag[2];
3a8c7ba1
DW
8065 const char *subcode_str;
8066 const char *code_str;
538621f2 8067 afi_t afi;
8068 safi_t safi;
d6661008
DS
8069 u_int16_t i;
8070 u_char *msg;
e8f7da3a 8071 json_object *json_neigh = NULL;
46111f2f 8072 time_t epoch_tbuf;
718e3744 8073
8074 bgp = p->bgp;
8075
e8f7da3a
DW
8076 if (use_json)
8077 json_neigh = json_object_new_object();
8078
517cd68a
DS
8079 memset (dn_flag, '\0', sizeof (dn_flag));
8080 if (!p->conf_if && peer_dynamic_neighbor (p))
8081 dn_flag[0] = '*';
8082
856ca177 8083 if (!use_json)
f14e6fdb 8084 {
856ca177
MS
8085 if (p->conf_if) /* Configured interface name. */
8086 vty_out (vty, "BGP neighbor on %s: %s, ", p->conf_if,
8087 BGP_PEER_SU_UNSPEC(p) ? "None" :
8088 sockunion2str (&p->su, buf, SU_ADDRSTRLEN));
8089 else /* Configured IP address. */
74ef1672 8090 vty_out (vty, "BGP neighbor is %s%s, ", dn_flag, p->host);
f14e6fdb
DS
8091 }
8092
856ca177
MS
8093 if (use_json)
8094 {
8095 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8096 json_object_string_add(json_neigh, "bgpNeighborAddr", "none");
8097 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8098 json_object_string_add(json_neigh, "bgpNeighborAddr", sockunion2str (&p->su, buf, SU_ADDRSTRLEN));
8099
8100 json_object_int_add(json_neigh, "remoteAs", p->as);
8101
8102 if (p->change_local_as)
8103 json_object_int_add(json_neigh, "localAs", p->change_local_as);
8104 else
8105 json_object_int_add(json_neigh, "localAs", p->local_as);
8106
8107 if (CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8108 json_object_boolean_true_add(json_neigh, "localAsNoPrepend");
66b199b2 8109
856ca177
MS
8110 if (CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8111 json_object_boolean_true_add(json_neigh, "localAsReplaceAs");
8112 }
8113 else
8114 {
f8cfafda
DS
8115 if ((p->as_type == AS_SPECIFIED) ||
8116 (p->as_type == AS_EXTERNAL) ||
8117 (p->as_type == AS_INTERNAL))
8118 vty_out (vty, "remote AS %u, ", p->as);
8119 else
8120 vty_out (vty, "remote AS Unspecified, ");
856ca177
MS
8121 vty_out (vty, "local AS %u%s%s, ",
8122 p->change_local_as ? p->change_local_as : p->local_as,
8123 CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND) ?
8124 " no-prepend" : "",
8125 CHECK_FLAG (p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS) ?
8126 " replace-as" : "");
8127 }
66b199b2
DS
8128 /* peer type internal, external, confed-internal or confed-external */
8129 if (p->as == p->local_as)
8130 {
856ca177
MS
8131 if (use_json)
8132 {
8133 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8134 json_object_boolean_true_add(json_neigh, "nbrConfedInternalLink");
8135 else
8136 json_object_boolean_true_add(json_neigh, "nbrInternalLink");
8137 }
66b199b2 8138 else
856ca177
MS
8139 {
8140 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8141 vty_out (vty, "confed-internal link%s", VTY_NEWLINE);
8142 else
8143 vty_out (vty, "internal link%s", VTY_NEWLINE);
8144 }
66b199b2
DS
8145 }
8146 else
8147 {
856ca177
MS
8148 if (use_json)
8149 {
8150 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8151 json_object_boolean_true_add(json_neigh, "nbrConfedExternalLink");
8152 else
8153 json_object_boolean_true_add(json_neigh, "nbrExternalLink");
8154 }
66b199b2 8155 else
856ca177
MS
8156 {
8157 if (bgp_confederation_peers_check(bgp, p->as))
8158 vty_out (vty, "confed-external link%s", VTY_NEWLINE);
8159 else
8160 vty_out (vty, "external link%s", VTY_NEWLINE);
8161 }
66b199b2 8162 }
718e3744 8163
8164 /* Description. */
8165 if (p->desc)
856ca177
MS
8166 {
8167 if (use_json)
8168 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8169 else
8170 vty_out (vty, " Description: %s%s", p->desc, VTY_NEWLINE);
8171 }
6410e93a 8172
04b6bdc0
DW
8173 if (p->hostname)
8174 {
d1570739
DW
8175 if (use_json)
8176 {
8177 if (p->hostname)
8178 json_object_string_add(json_neigh, "hostname", p->hostname);
8179
8180 if (p->domainname)
8181 json_object_string_add(json_neigh, "domainname", p->domainname);
8182 }
04b6bdc0 8183 else
d1570739
DW
8184 {
8185 if (p->domainname && (p->domainname[0] != '\0'))
8186 vty_out(vty, "Hostname: %s.%s%s", p->hostname, p->domainname,
8187 VTY_NEWLINE);
8188 else
8189 vty_out(vty, "Hostname: %s%s", p->hostname, VTY_NEWLINE);
8190 }
8191
04b6bdc0
DW
8192 }
8193
c744aa9f 8194 /* Peer-group */
718e3744 8195 if (p->group)
f14e6fdb 8196 {
856ca177
MS
8197 if (use_json)
8198 {
8199 json_object_string_add(json_neigh, "peerGroup", p->group->name);
8200
8201 if (dn_flag[0])
8202 {
40ee54a7 8203 struct prefix prefix, *range = NULL;
f14e6fdb 8204
40ee54a7
TT
8205 sockunion2hostprefix(&(p->su), &prefix);
8206 range = peer_group_lookup_dynamic_neighbor_range (p->group, &prefix);
856ca177
MS
8207
8208 if (range)
8209 {
8210 prefix2str(range, buf1, sizeof(buf1));
8211 json_object_string_add(json_neigh, "peerSubnetRangeGroup", buf1);
8212 }
8213 }
8214 }
8215 else
f14e6fdb 8216 {
856ca177
MS
8217 vty_out (vty, " Member of peer-group %s for session parameters%s",
8218 p->group->name, VTY_NEWLINE);
f14e6fdb 8219
856ca177 8220 if (dn_flag[0])
f14e6fdb 8221 {
40ee54a7 8222 struct prefix prefix, *range = NULL;
856ca177 8223
40ee54a7
TT
8224 sockunion2hostprefix(&(p->su), &prefix);
8225 range = peer_group_lookup_dynamic_neighbor_range (p->group, &prefix);
856ca177
MS
8226
8227 if (range)
8228 {
8229 prefix2str(range, buf1, sizeof(buf1));
8230 vty_out (vty, " Belongs to the subnet range group: %s%s", buf1, VTY_NEWLINE);
8231 }
f14e6fdb
DS
8232 }
8233 }
8234 }
718e3744 8235
856ca177
MS
8236 if (use_json)
8237 {
8238 /* Administrative shutdown. */
8239 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
8240 json_object_boolean_true_add(json_neigh, "adminShutDown");
718e3744 8241
856ca177
MS
8242 /* BGP Version. */
8243 json_object_int_add(json_neigh, "bgpVersion", 4);
389e3fe0 8244 json_object_string_add(json_neigh, "remoteRouterId",
44b8cd53 8245 inet_ntop (AF_INET, &p->remote_id, buf1, sizeof(buf1)));
718e3744 8246
856ca177
MS
8247 /* Confederation */
8248 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION) && bgp_confederation_peers_check (bgp, p->as))
8249 json_object_boolean_true_add(json_neigh, "nbrCommonAdmin");
8250
8251 /* Status. */
8252 json_object_string_add(json_neigh, "bgpState", LOOKUP (bgp_status_msg, p->status));
8253
8254 if (p->status == Established)
8255 {
8256 time_t uptime;
8257 struct tm *tm;
8258
8259 uptime = bgp_clock();
8260 uptime -= p->uptime;
8261 tm = gmtime(&uptime);
46111f2f 8262 epoch_tbuf = time(NULL) - uptime;
856ca177
MS
8263
8264 json_object_int_add(json_neigh, "bgpTimerUp", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
46111f2f
DW
8265 json_object_string_add(json_neigh, "bgpTimerUpString", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8266 json_object_int_add(json_neigh, "bgpTimerUpEstablishedEpoch", epoch_tbuf);
856ca177
MS
8267 }
8268
8269 else if (p->status == Active)
8270 {
8271 if (CHECK_FLAG (p->flags, PEER_FLAG_PASSIVE))
8272 json_object_string_add(json_neigh, "bgpStateIs", "passive");
8273 else if (CHECK_FLAG (p->sflags, PEER_STATUS_NSF_WAIT))
8274 json_object_string_add(json_neigh, "bgpStateIs", "passiveNSF");
8275 }
8276
8277 /* read timer */
8278 time_t uptime;
8279 struct tm *tm;
8280
8281 uptime = bgp_clock();
8282 uptime -= p->readtime;
8283 tm = gmtime(&uptime);
8284 json_object_int_add(json_neigh, "bgpTimerLastRead", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8285
8286 uptime = bgp_clock();
8287 uptime -= p->last_write;
8288 tm = gmtime(&uptime);
39e871e6
ST
8289 json_object_int_add(json_neigh, "bgpTimerLastWrite", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8290
8291 uptime = bgp_clock();
8292 uptime -= p->update_time;
8293 tm = gmtime(&uptime);
8294 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8295 (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
856ca177
MS
8296
8297 /* Configured timer values. */
8298 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs", p->v_holdtime * 1000);
8299 json_object_int_add(json_neigh, "bgpTimerKeepAliveIntervalMsecs", p->v_keepalive * 1000);
8300
8301 if (CHECK_FLAG (p->config, PEER_CONFIG_TIMER))
8302 {
8303 json_object_int_add(json_neigh, "bgpTimerConfiguredHoldTimeMsecs", p->holdtime * 1000);
8304 json_object_int_add(json_neigh, "bgpTimerConfiguredKeepAliveIntervalMsecs", p->keepalive * 1000);
8305 }
93406d87 8306 }
856ca177
MS
8307 else
8308 {
8309 /* Administrative shutdown. */
8310 if (CHECK_FLAG (p->flags, PEER_FLAG_SHUTDOWN))
8311 vty_out (vty, " Administratively shut down%s", VTY_NEWLINE);
8312
8313 /* BGP Version. */
8314 vty_out (vty, " BGP version 4");
389e3fe0 8315 vty_out (vty, ", remote router ID %s%s",
44b8cd53 8316 inet_ntop (AF_INET, &p->remote_id, buf1, sizeof(buf1)),
856ca177
MS
8317 VTY_NEWLINE);
8318
8319 /* Confederation */
8320 if (CHECK_FLAG (bgp->config, BGP_CONFIG_CONFEDERATION)
8321 && bgp_confederation_peers_check (bgp, p->as))
8322 vty_out (vty, " Neighbor under common administration%s", VTY_NEWLINE);
e52702f2 8323
856ca177
MS
8324 /* Status. */
8325 vty_out (vty, " BGP state = %s", LOOKUP (bgp_status_msg, p->status));
718e3744 8326
856ca177
MS
8327 if (p->status == Established)
8328 vty_out (vty, ", up for %8s", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8329
8330 else if (p->status == Active)
8331 {
8332 if (CHECK_FLAG (p->flags, PEER_FLAG_PASSIVE))
8333 vty_out (vty, " (passive)");
8334 else if (CHECK_FLAG (p->sflags, PEER_STATUS_NSF_WAIT))
8335 vty_out (vty, " (NSF passive)");
8336 }
8337 vty_out (vty, "%s", VTY_NEWLINE);
93406d87 8338
856ca177
MS
8339 /* read timer */
8340 vty_out (vty, " Last read %s", peer_uptime (p->readtime, timebuf, BGP_UPTIME_LEN, 0, NULL));
8341 vty_out (vty, ", Last write %s%s",
8342 peer_uptime (p->last_write, timebuf, BGP_UPTIME_LEN, 0, NULL), VTY_NEWLINE);
8343
8344 /* Configured timer values. */
8345 vty_out (vty, " Hold time is %d, keepalive interval is %d seconds%s",
8346 p->v_holdtime, p->v_keepalive, VTY_NEWLINE);
8347 if (CHECK_FLAG (p->config, PEER_CONFIG_TIMER))
8348 {
8349 vty_out (vty, " Configured hold time is %d", p->holdtime);
8350 vty_out (vty, ", keepalive interval is %d seconds%s",
8351 p->keepalive, VTY_NEWLINE);
8352 }
8353 }
718e3744 8354 /* Capability. */
e52702f2 8355 if (p->status == Established)
718e3744 8356 {
538621f2 8357 if (p->cap
718e3744 8358 || p->afc_adv[AFI_IP][SAFI_UNICAST]
8359 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8360 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8361 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
718e3744 8362 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8363 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8364 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8365 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
945c8fe9
LB
8366 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8367 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8b1fb8be
LB
8368 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8369 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8b1fb8be
LB
8370 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8371 || p->afc_recv[AFI_IP][SAFI_ENCAP]
718e3744 8372 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8373 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN])
8374 {
856ca177
MS
8375 if (use_json)
8376 {
8377 json_object *json_cap = NULL;
8378
8379 json_cap = json_object_new_object();
8380
8381 /* AS4 */
8382 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV)
8383 || CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
8384 {
8385 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV) && CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
8386 json_object_string_add(json_cap, "4byteAs", "advertisedAndReceived");
8387 else if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
8388 json_object_string_add(json_cap, "4byteAs", "advertised");
8389 else if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
8390 json_object_string_add(json_cap, "4byteAs", "received");
8391 }
8392
8393 /* AddPath */
8394 if (CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_RCV)
8395 || CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_ADV))
8396 {
8397 json_object *json_add = NULL;
8398 const char *print_store;
718e3744 8399
856ca177 8400 json_add = json_object_new_object();
a82478b9 8401
856ca177
MS
8402 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8403 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8404 {
8405 json_object *json_sub = NULL;
8406 json_sub = json_object_new_object();
8407 print_store = afi_safi_print (afi, safi);
8408
8409 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
8410 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8411 {
8412 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))
8413 json_object_boolean_true_add(json_sub, "txAdvertisedAndReceived");
8414 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV))
8415 json_object_boolean_true_add(json_sub, "txAdvertised");
8416 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8417 json_object_boolean_true_add(json_sub, "txReceived");
8418 }
8419
8420 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
8421 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8422 {
8423 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))
8424 json_object_boolean_true_add(json_sub, "rxAdvertisedAndReceived");
8425 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV))
8426 json_object_boolean_true_add(json_sub, "rxAdvertised");
8427 else if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8428 json_object_boolean_true_add(json_sub, "rxReceived");
8429 }
8430
8431 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
8432 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV) ||
8433 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
8434 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8435 json_object_object_add(json_add, print_store, json_sub);
b6df4090
DS
8436 else
8437 json_object_free(json_sub);
856ca177 8438 }
a82478b9 8439
856ca177
MS
8440 json_object_object_add(json_cap, "addPath", json_add);
8441 }
8442
8443 /* Dynamic */
8444 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV)
8445 || CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8446 {
8447 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV) && CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
8448 json_object_string_add(json_cap, "dynamic", "advertisedAndReceived");
8449 else if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8450 json_object_string_add(json_cap, "dynamic", "advertised");
8451 else if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
8452 json_object_string_add(json_cap, "dynamic", "received");
8453 }
8454
8455 /* Extended nexthop */
8456 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV)
8457 || CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8458 {
8459 json_object *json_nxt = NULL;
8460 const char *print_store;
8461
856ca177
MS
8462
8463 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV) && CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8464 json_object_string_add(json_cap, "extendedNexthop", "advertisedAndReceived");
8465 else if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8466 json_object_string_add(json_cap, "extendedNexthop", "advertised");
8467 else if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8468 json_object_string_add(json_cap, "extendedNexthop", "received");
8469
8470 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8471 {
b6df4090
DS
8472 json_nxt = json_object_new_object();
8473
856ca177
MS
8474 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8475 {
8476 if (CHECK_FLAG (p->af_cap[AFI_IP][safi], PEER_CAP_ENHE_AF_RCV))
8477 {
8478 print_store = afi_safi_print (AFI_IP, safi);
8479 json_object_string_add(json_nxt, print_store, "recieved");
8480 }
8481 }
8482 json_object_object_add(json_cap, "extendedNexthopFamililesByPeer", json_nxt);
8483 }
8484 }
8485
8486 /* Route Refresh */
8487 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV)
8488 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
8489 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8490 {
8491 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)))
8492 {
8493 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV) && CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV))
8494 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedOldNew");
8495 else
8496 {
8497 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8498 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedOld");
8499 else
8500 json_object_string_add(json_cap, "routeRefresh", "advertisedAndReceivedNew");
8501 }
8502 }
8503 else if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV))
8504 json_object_string_add(json_cap, "routeRefresh", "advertised");
8505 else if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV) || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8506 json_object_string_add(json_cap, "routeRefresh", "received");
8507 }
8508
8509 /* Multiprotocol Extensions */
8510 json_object *json_multi = NULL;
8511 json_multi = json_object_new_object();
8512
8513 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8514 {
8515 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8516 {
8517 if (p->afc_adv[afi][safi] || p->afc_recv[afi][safi])
8518 {
8519 json_object *json_exten = NULL;
8520 json_exten = json_object_new_object();
8521
8522 if (p->afc_adv[afi][safi] && p->afc_recv[afi][safi])
8523 json_object_boolean_true_add(json_exten, "advertisedAndReceived");
8524 else if (p->afc_adv[afi][safi])
8525 json_object_boolean_true_add(json_exten, "advertised");
8526 else if (p->afc_recv[afi][safi])
8527 json_object_boolean_true_add(json_exten, "received");
8528
8529 json_object_object_add(json_multi, afi_safi_print (afi, safi), json_exten);
8530 }
8531 }
8532 }
8533 json_object_object_add(json_cap, "multiprotocolExtensions", json_multi);
8534
8535 /* Gracefull Restart */
8536 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8537 || CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8538 {
8539 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV) && CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8540 json_object_string_add(json_cap, "gracefulRestart", "advertisedAndReceived");
8541 else if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8542 json_object_string_add(json_cap, "gracefulRestartCapability", "advertised");
8543 else if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8544 json_object_string_add(json_cap, "gracefulRestartCapability", "received");
8545
8546 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8547 {
8548 int restart_af_count = 0;
8549 json_object *json_restart = NULL;
8550 json_restart = json_object_new_object();
8551
8552 json_object_int_add(json_cap, "gracefulRestartRemoteTimerMsecs", p->v_gr_restart * 1000);
8553
8554 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8555 {
8556 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8557 {
8558 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV))
8559 {
8560 json_object *json_sub = NULL;
8561 json_sub = json_object_new_object();
8562
8563 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV))
8564 json_object_boolean_true_add(json_sub, "preserved");
8565 restart_af_count++;
8566 json_object_object_add(json_restart, afi_safi_print (afi, safi), json_sub);
8567 }
8568 }
8569 }
8570 if (! restart_af_count)
b6df4090 8571 {
856ca177 8572 json_object_string_add(json_cap, "addressFamiliesByPeer", "none");
b6df4090
DS
8573 json_object_free(json_restart);
8574 }
856ca177
MS
8575 else
8576 json_object_object_add(json_cap, "addressFamiliesByPeer", json_restart);
8577 }
8578 }
8579 json_object_object_add(json_neigh, "neighborCapabilities", json_cap);
8580 }
8581 else
8582 {
8583 vty_out (vty, " Neighbor capabilities:%s", VTY_NEWLINE);
8584
8585 /* AS4 */
8586 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV)
8587 || CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
8588 {
8589 vty_out (vty, " 4 Byte AS:");
8590 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV))
8591 vty_out (vty, " advertised");
8592 if (CHECK_FLAG (p->cap, PEER_CAP_AS4_RCV))
8593 vty_out (vty, " %sreceived",
8594 CHECK_FLAG (p->cap, PEER_CAP_AS4_ADV) ? "and " : "");
8595 vty_out (vty, "%s", VTY_NEWLINE);
8596 }
8597
8598 /* AddPath */
8599 if (CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_RCV)
8600 || CHECK_FLAG (p->cap, PEER_CAP_ADDPATH_ADV))
8601 {
8602 vty_out (vty, " AddPath:%s", VTY_NEWLINE);
a82478b9 8603
856ca177
MS
8604 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8605 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
a82478b9 8606 {
856ca177
MS
8607 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ||
8608 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8609 {
8610 vty_out (vty, " %s: TX ", afi_safi_print (afi, safi));
a82478b9 8611
856ca177
MS
8612 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV))
8613 vty_out (vty, "advertised %s", afi_safi_print (afi, safi));
a82478b9 8614
856ca177
MS
8615 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV))
8616 vty_out (vty, "%sreceived", CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_ADV) ? " and " : "" );
a82478b9 8617
856ca177
MS
8618 vty_out (vty, "%s", VTY_NEWLINE);
8619 }
a82478b9 8620
856ca177 8621 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ||
a82478b9 8622 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
856ca177
MS
8623 {
8624 vty_out (vty, " %s: RX ", afi_safi_print (afi, safi));
a82478b9 8625
856ca177
MS
8626 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV))
8627 vty_out (vty, "advertised %s", afi_safi_print (afi, safi));
a82478b9 8628
856ca177
MS
8629 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV))
8630 vty_out (vty, "%sreceived", CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) ? " and " : "" );
a82478b9 8631
856ca177
MS
8632 vty_out (vty, "%s", VTY_NEWLINE);
8633 }
a82478b9 8634 }
856ca177 8635 }
a82478b9 8636
856ca177
MS
8637 /* Dynamic */
8638 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV)
8639 || CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8640 {
8641 vty_out (vty, " Dynamic:");
8642 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV))
8643 vty_out (vty, " advertised");
8644 if (CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_RCV))
8645 vty_out (vty, " %sreceived",
8646 CHECK_FLAG (p->cap, PEER_CAP_DYNAMIC_ADV) ? "and " : "");
8647 vty_out (vty, "%s", VTY_NEWLINE);
8648 }
8649
8650 /* Extended nexthop */
8651 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV)
8652 || CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8653 {
8654 vty_out (vty, " Extended nexthop:");
8655 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV))
8656 vty_out (vty, " advertised");
8657 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8658 vty_out (vty, " %sreceived",
8659 CHECK_FLAG (p->cap, PEER_CAP_ENHE_ADV) ? "and " : "");
8660 vty_out (vty, "%s", VTY_NEWLINE);
718e3744 8661
856ca177
MS
8662 if (CHECK_FLAG (p->cap, PEER_CAP_ENHE_RCV))
8663 {
8664 vty_out (vty, " Address families by peer:%s ", VTY_NEWLINE);
8665 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8666 if (CHECK_FLAG (p->af_cap[AFI_IP][safi], PEER_CAP_ENHE_AF_RCV))
8667 vty_out (vty, " %s%s",
8668 afi_safi_print (AFI_IP, safi), VTY_NEWLINE);
8669 }
8670 }
8a92a8a0 8671
856ca177
MS
8672 /* Route Refresh */
8673 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV)
8674 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
8675 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8676 {
8677 vty_out (vty, " Route refresh:");
8678 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV))
8679 vty_out (vty, " advertised");
8680 if (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)
8681 || CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV))
8682 vty_out (vty, " %sreceived(%s)",
8683 CHECK_FLAG (p->cap, PEER_CAP_REFRESH_ADV) ? "and " : "",
8684 (CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV)
8685 && CHECK_FLAG (p->cap, PEER_CAP_REFRESH_NEW_RCV)) ?
8686 "old & new" : CHECK_FLAG (p->cap, PEER_CAP_REFRESH_OLD_RCV) ? "old" : "new");
8a92a8a0 8687
856ca177
MS
8688 vty_out (vty, "%s", VTY_NEWLINE);
8689 }
718e3744 8690
856ca177
MS
8691 /* Multiprotocol Extensions */
8692 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8693 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8694 if (p->afc_adv[afi][safi] || p->afc_recv[afi][safi])
8695 {
8c3deaae 8696 vty_out (vty, " Address Family %s:", afi_safi_print (afi, safi));
856ca177
MS
8697 if (p->afc_adv[afi][safi])
8698 vty_out (vty, " advertised");
8699 if (p->afc_recv[afi][safi])
8700 vty_out (vty, " %sreceived", p->afc_adv[afi][safi] ? "and " : "");
8701 vty_out (vty, "%s", VTY_NEWLINE);
8702 }
538621f2 8703
04b6bdc0
DW
8704 /* Hostname capability */
8705 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV) ||
8706 CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV))
8707 {
8708 vty_out (vty, " Hostname Capability:");
8709 if (CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_ADV))
8710 vty_out (vty, " advertised");
8711 if (CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_RCV))
8712 vty_out (vty, " %sreceived",
8713 CHECK_FLAG (p->cap, PEER_CAP_HOSTNAME_ADV) ? "and " : "");
8714 vty_out (vty, "%s", VTY_NEWLINE);
8715 }
8716
856ca177
MS
8717 /* Gracefull Restart */
8718 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8719 || CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
8720 {
8721 vty_out (vty, " Graceful Restart Capabilty:");
8722 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV))
538621f2 8723 vty_out (vty, " advertised");
856ca177
MS
8724 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8725 vty_out (vty, " %sreceived",
8726 CHECK_FLAG (p->cap, PEER_CAP_RESTART_ADV) ? "and " : "");
8727 vty_out (vty, "%s", VTY_NEWLINE);
538621f2 8728
856ca177
MS
8729 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV))
8730 {
8731 int restart_af_count = 0;
8732
8733 vty_out (vty, " Remote Restart timer is %d seconds%s",
8734 p->v_gr_restart, VTY_NEWLINE);
8735 vty_out (vty, " Address families by peer:%s ", VTY_NEWLINE);
8736
8737 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8738 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8739 if (CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_RCV))
8740 {
8741 vty_out (vty, "%s%s(%s)", restart_af_count ? ", " : "",
8742 afi_safi_print (afi, safi),
8743 CHECK_FLAG (p->af_cap[afi][safi], PEER_CAP_RESTART_AF_PRESERVE_RCV) ?
8744 "preserved" : "not preserved");
8745 restart_af_count++;
8746 }
8747 if (! restart_af_count)
8748 vty_out (vty, "none");
8749 vty_out (vty, "%s", VTY_NEWLINE);
8750 }
8751 }
8752 }
718e3744 8753 }
8754 }
8755
93406d87 8756 /* graceful restart information */
8757 if (CHECK_FLAG (p->cap, PEER_CAP_RESTART_RCV)
8758 || p->t_gr_restart
8759 || p->t_gr_stale)
8760 {
856ca177
MS
8761 json_object *json_grace = NULL;
8762 json_object *json_grace_send = NULL;
8763 json_object *json_grace_recv = NULL;
93406d87 8764 int eor_send_af_count = 0;
8765 int eor_receive_af_count = 0;
8766
856ca177
MS
8767 if (use_json)
8768 {
8769 json_grace = json_object_new_object();
8770 json_grace_send = json_object_new_object();
8771 json_grace_recv = json_object_new_object();
8772
8773 if (p->status == Established)
8774 {
8775 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8776 {
8777 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8778 {
8779 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_SEND))
8780 {
8781 json_object_boolean_true_add(json_grace_send, afi_safi_print (afi, safi));
8782 eor_send_af_count++;
8783 }
8784 }
8785 }
8786 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8787 {
8788 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8789 {
8790 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED))
8791 {
8792 json_object_boolean_true_add(json_grace_recv, afi_safi_print (afi, safi));
8793 eor_receive_af_count++;
8794 }
8795 }
8796 }
8797 }
8798
8799 json_object_object_add(json_grace, "endOfRibSend", json_grace_send);
8800 json_object_object_add(json_grace, "endOfRibRecv", json_grace_recv);
8801
8802 if (p->t_gr_restart)
8803 json_object_int_add(json_grace, "gracefulRestartTimerMsecs", thread_timer_remain_second (p->t_gr_restart) * 1000);
8804
8805 if (p->t_gr_stale)
8806 json_object_int_add(json_grace, "gracefulStalepathTimerMsecs", thread_timer_remain_second (p->t_gr_stale) * 1000);
8807
8808 json_object_object_add(json_neigh, "gracefulRestartInfo", json_grace);
8809 }
8810 else
8811 {
8812 vty_out (vty, " Graceful restart informations:%s", VTY_NEWLINE);
8813 if (p->status == Established)
8814 {
8815 vty_out (vty, " End-of-RIB send: ");
8816 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8817 {
8818 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8819 {
8820 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_SEND))
8821 {
8822 vty_out (vty, "%s%s", eor_send_af_count ? ", " : "",
8823 afi_safi_print (afi, safi));
8824 eor_send_af_count++;
8825 }
8826 }
8827 }
8828 vty_out (vty, "%s", VTY_NEWLINE);
8829 vty_out (vty, " End-of-RIB received: ");
8830 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8831 {
8832 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8833 {
8834 if (CHECK_FLAG (p->af_sflags[afi][safi], PEER_STATUS_EOR_RECEIVED))
8835 {
8836 vty_out (vty, "%s%s", eor_receive_af_count ? ", " : "",
8837 afi_safi_print (afi, safi));
8838 eor_receive_af_count++;
8839 }
8840 }
8841 }
8842 vty_out (vty, "%s", VTY_NEWLINE);
8843 }
93406d87 8844
856ca177
MS
8845 if (p->t_gr_restart)
8846 vty_out (vty, " The remaining time of restart timer is %ld%s",
8847 thread_timer_remain_second (p->t_gr_restart), VTY_NEWLINE);
e52702f2 8848
856ca177
MS
8849 if (p->t_gr_stale)
8850 vty_out (vty, " The remaining time of stalepath timer is %ld%s",
8851 thread_timer_remain_second (p->t_gr_stale), VTY_NEWLINE);
8852 }
8853 }
8854 if (use_json)
8855 {
8856 json_object *json_stat = NULL;
8857 json_stat = json_object_new_object();
8858 /* Packet counts. */
8859 json_object_int_add(json_stat, "depthInq", 0);
8860 json_object_int_add(json_stat, "depthOutq", (unsigned long) p->obuf->count);
8861 json_object_int_add(json_stat, "opensSent", p->open_out);
8862 json_object_int_add(json_stat, "opensRecv", p->open_in);
8863 json_object_int_add(json_stat, "notificationsSent", p->notify_out);
8864 json_object_int_add(json_stat, "notificationsRecv", p->notify_in);
8865 json_object_int_add(json_stat, "updatesSent", p->update_out);
8866 json_object_int_add(json_stat, "updatesRecv", p->update_in);
8867 json_object_int_add(json_stat, "keepalivesSent", p->keepalive_out);
8868 json_object_int_add(json_stat, "keepalivesRecv", p->keepalive_in);
8869 json_object_int_add(json_stat, "routeRefreshSent", p->refresh_out);
8870 json_object_int_add(json_stat, "routeRefreshRecv", p->refresh_in);
8871 json_object_int_add(json_stat, "capabilitySent", p->dynamic_cap_out);
8872 json_object_int_add(json_stat, "capabilityRecv", p->dynamic_cap_in);
8873 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);
8874 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);
8875 json_object_object_add(json_neigh, "messageStats", json_stat);
8876 }
8877 else
8878 {
8879 /* Packet counts. */
8880 vty_out (vty, " Message statistics:%s", VTY_NEWLINE);
8881 vty_out (vty, " Inq depth is 0%s", VTY_NEWLINE);
8882 vty_out (vty, " Outq depth is %lu%s", (unsigned long) p->obuf->count, VTY_NEWLINE);
8883 vty_out (vty, " Sent Rcvd%s", VTY_NEWLINE);
8884 vty_out (vty, " Opens: %10d %10d%s", p->open_out, p->open_in, VTY_NEWLINE);
8885 vty_out (vty, " Notifications: %10d %10d%s", p->notify_out, p->notify_in, VTY_NEWLINE);
8886 vty_out (vty, " Updates: %10d %10d%s", p->update_out, p->update_in, VTY_NEWLINE);
8887 vty_out (vty, " Keepalives: %10d %10d%s", p->keepalive_out, p->keepalive_in, VTY_NEWLINE);
8888 vty_out (vty, " Route Refresh: %10d %10d%s", p->refresh_out, p->refresh_in, VTY_NEWLINE);
8889 vty_out (vty, " Capability: %10d %10d%s", p->dynamic_cap_out, p->dynamic_cap_in, VTY_NEWLINE);
8890 vty_out (vty, " Total: %10d %10d%s", p->open_out + p->notify_out +
8891 p->update_out + p->keepalive_out + p->refresh_out + p->dynamic_cap_out,
8892 p->open_in + p->notify_in + p->update_in + p->keepalive_in + p->refresh_in +
8893 p->dynamic_cap_in, VTY_NEWLINE);
718e3744 8894 }
8895
856ca177
MS
8896 if (use_json)
8897 {
8898 /* advertisement-interval */
8899 json_object_int_add(json_neigh, "minBtwnAdvertisementRunsTimerMsecs", p->v_routeadv * 1000);
718e3744 8900
856ca177
MS
8901 /* Update-source. */
8902 if (p->update_if || p->update_source)
8903 {
8904 if (p->update_if)
8905 json_object_string_add(json_neigh, "updateSource", p->update_if);
8906 else if (p->update_source)
8907 json_object_string_add(json_neigh, "updateSource", sockunion2str (p->update_source, buf1, SU_ADDRSTRLEN));
8908 }
856ca177
MS
8909 }
8910 else
8911 {
8912 /* advertisement-interval */
8913 vty_out (vty, " Minimum time between advertisement runs is %d seconds%s",
8914 p->v_routeadv, VTY_NEWLINE);
8915
8916 /* Update-source. */
8917 if (p->update_if || p->update_source)
8918 {
8919 vty_out (vty, " Update source is ");
8920 if (p->update_if)
8921 vty_out (vty, "%s", p->update_if);
8922 else if (p->update_source)
8923 vty_out (vty, "%s", sockunion2str (p->update_source, buf1, SU_ADDRSTRLEN));
8924 vty_out (vty, "%s", VTY_NEWLINE);
8925 }
8926
856ca177
MS
8927 vty_out (vty, "%s", VTY_NEWLINE);
8928 }
718e3744 8929
8930 /* Address Family Information */
856ca177
MS
8931 json_object *json_hold = NULL;
8932
8933 if (use_json)
8934 json_hold = json_object_new_object();
8935
538621f2 8936 for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
8937 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
8938 if (p->afc[afi][safi])
856ca177 8939 bgp_show_peer_afi (vty, p, afi, safi, use_json, json_hold);
718e3744 8940
856ca177
MS
8941 if (use_json)
8942 {
58433ae6 8943 json_object_object_add(json_neigh, "addressFamilyInfo", json_hold);
e08ac8b7
DW
8944 json_object_int_add(json_neigh, "connectionsEstablished", p->established);
8945 json_object_int_add(json_neigh, "connectionsDropped", p->dropped);
856ca177
MS
8946 }
8947 else
8948 vty_out (vty, " Connections established %d; dropped %d%s", p->established, p->dropped,
8949 VTY_NEWLINE);
718e3744 8950
d6661008 8951 if (! p->last_reset)
856ca177
MS
8952 {
8953 if (use_json)
e08ac8b7 8954 json_object_string_add(json_neigh, "lastReset", "never");
856ca177
MS
8955 else
8956 vty_out (vty, " Last reset never%s", VTY_NEWLINE);
8957 }
e0701b79 8958 else
d6661008 8959 {
856ca177
MS
8960 if (use_json)
8961 {
8962 time_t uptime;
8963 struct tm *tm;
8964
8965 uptime = bgp_clock();
8966 uptime -= p->resettime;
8967 tm = gmtime(&uptime);
e08ac8b7
DW
8968 json_object_int_add(json_neigh, "lastResetTimerMsecs", (tm->tm_sec * 1000) + (tm->tm_min * 60000) + (tm->tm_hour * 3600000));
8969 json_object_string_add(json_neigh, "lastResetDueTo", peer_down_str[(int) p->last_reset]);
cca1dda8
DD
8970 if (p->last_reset == PEER_DOWN_NOTIFY_SEND ||
8971 p->last_reset == PEER_DOWN_NOTIFY_RECEIVED)
856ca177 8972 {
39e871e6 8973 char errorcodesubcode_hexstr[5];
cca1dda8
DD
8974 char errorcodesubcode_str[256];
8975
8976 code_str = bgp_notify_code_str(p->notify.code);
8977 subcode_str = bgp_notify_subcode_str(p->notify.code, p->notify.subcode);
8978
39e871e6 8979 sprintf(errorcodesubcode_hexstr, "%02X%02X", p->notify.code, p->notify.subcode);
e08ac8b7 8980 json_object_string_add(json_neigh, "lastErrorCodeSubcode", errorcodesubcode_hexstr);
cca1dda8
DD
8981 snprintf(errorcodesubcode_str, 255, "%s%s", code_str, subcode_str);
8982 json_object_string_add(json_neigh, "lastNotificationReason", errorcodesubcode_str);
652b9429
DS
8983 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
8984 && p->notify.code == BGP_NOTIFY_CEASE
8985 && (p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
8986 || p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_RESET)
8987 && p->notify.length)
8988 {
8989 char msgbuf[1024];
8990 const char *msg_str;
8991
8992 msg_str = bgp_notify_admin_message(msgbuf, sizeof(msgbuf),
8993 (u_char*)p->notify.data, p->notify.length);
8994 if (msg_str)
8995 json_object_string_add(json_neigh, "lastShutdownDescription", msg_str);
8996 }
856ca177
MS
8997 }
8998 }
8999 else
d6661008 9000 {
3a8c7ba1
DW
9001 vty_out (vty, " Last reset %s, ",
9002 peer_uptime (p->resettime, timebuf, BGP_UPTIME_LEN, 0, NULL));
9003
9004 if (p->last_reset == PEER_DOWN_NOTIFY_SEND ||
9005 p->last_reset == PEER_DOWN_NOTIFY_RECEIVED)
9006 {
9007 code_str = bgp_notify_code_str(p->notify.code);
9008 subcode_str = bgp_notify_subcode_str(p->notify.code, p->notify.subcode);
9009 vty_out (vty, "due to NOTIFICATION %s (%s%s)%s",
9010 p->last_reset == PEER_DOWN_NOTIFY_SEND ? "sent" : "received",
9011 code_str, subcode_str, VTY_NEWLINE);
38de8d02
DL
9012 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9013 && p->notify.code == BGP_NOTIFY_CEASE
9014 && (p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9015 || p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_RESET)
9016 && p->notify.length)
9017 {
9018 char msgbuf[1024];
9019 const char *msg_str;
9020
9021 msg_str = bgp_notify_admin_message(msgbuf, sizeof(msgbuf),
9022 (u_char*)p->notify.data, p->notify.length);
9023 if (msg_str)
9024 vty_out (vty, " Message: \"%s\"%s", msg_str, VTY_NEWLINE);
9025 }
3a8c7ba1
DW
9026 }
9027 else
9028 {
9029 vty_out (vty, "due to %s%s",
9030 peer_down_str[(int) p->last_reset], VTY_NEWLINE);
9031 }
856ca177
MS
9032
9033 if (p->last_reset_cause_size)
d6661008 9034 {
856ca177
MS
9035 msg = p->last_reset_cause;
9036 vty_out(vty, " Message received that caused BGP to send a NOTIFICATION:%s ", VTY_NEWLINE);
9037 for (i = 1; i <= p->last_reset_cause_size; i++)
9038 {
9039 vty_out(vty, "%02X", *msg++);
d6661008 9040
856ca177
MS
9041 if (i != p->last_reset_cause_size)
9042 {
9043 if (i % 16 == 0)
9044 {
9045 vty_out(vty, "%s ", VTY_NEWLINE);
9046 }
9047 else if (i % 4 == 0)
9048 {
9049 vty_out(vty, " ");
9050 }
9051 }
9052 }
9053 vty_out(vty, "%s", VTY_NEWLINE);
d6661008 9054 }
d6661008
DS
9055 }
9056 }
848973c7 9057
718e3744 9058 if (CHECK_FLAG (p->sflags, PEER_STATUS_PREFIX_OVERFLOW))
9059 {
856ca177 9060 if (use_json)
e08ac8b7 9061 json_object_boolean_true_add(json_neigh, "prefixesConfigExceedMax");
856ca177
MS
9062 else
9063 vty_out (vty, " Peer had exceeded the max. no. of prefixes configured.%s", VTY_NEWLINE);
0a486e5f 9064
9065 if (p->t_pmax_restart)
856ca177
MS
9066 {
9067 if (use_json)
9068 {
e08ac8b7
DW
9069 json_object_boolean_true_add(json_neigh, "reducePrefixNumFrom");
9070 json_object_int_add(json_neigh, "restartInTimerMsec", thread_timer_remain_second (p->t_pmax_restart) * 1000);
856ca177
MS
9071 }
9072 else
9073 vty_out (vty, " Reduce the no. of prefix from %s, will restart in %ld seconds%s",
9074 p->host, thread_timer_remain_second (p->t_pmax_restart),
9075 VTY_NEWLINE);
9076 }
0a486e5f 9077 else
856ca177
MS
9078 {
9079 if (use_json)
e08ac8b7 9080 json_object_boolean_true_add(json_neigh, "reducePrefixNumAndClearIpBgp");
856ca177
MS
9081 else
9082 vty_out (vty, " Reduce the no. of prefix and clear ip bgp %s to restore peering%s",
9083 p->host, VTY_NEWLINE);
9084 }
718e3744 9085 }
9086
f5a4827d 9087 /* EBGP Multihop and GTSM */
6d85b15b 9088 if (p->sort != BGP_PEER_IBGP)
f5a4827d 9089 {
856ca177
MS
9090 if (use_json)
9091 {
9092 if (p->gtsm_hops > 0)
9093 json_object_int_add(json_neigh, "externalBgpNbrMaxHopsAway", p->gtsm_hops);
9094 else if (p->ttl > 1)
9095 json_object_int_add(json_neigh, "externalBgpNbrMaxHopsAway", p->ttl);
9096 }
9097 else
9098 {
9099 if (p->gtsm_hops > 0)
9100 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
9101 p->gtsm_hops, VTY_NEWLINE);
9102 else if (p->ttl > 1)
9103 vty_out (vty, " External BGP neighbor may be up to %d hops away.%s",
9104 p->ttl, VTY_NEWLINE);
9105 }
f5a4827d 9106 }
5d804b43
PM
9107 else
9108 {
9109 if (p->gtsm_hops > 0)
856ca177
MS
9110 {
9111 if (use_json)
9112 json_object_int_add(json_neigh, "internalBgpNbrMaxHopsAway", p->gtsm_hops);
9113 else
9114 vty_out (vty, " Internal BGP neighbor may be up to %d hops away.%s",
9115 p->gtsm_hops, VTY_NEWLINE);
9116 }
5d804b43 9117 }
718e3744 9118
9119 /* Local address. */
9120 if (p->su_local)
9121 {
856ca177
MS
9122 if (use_json)
9123 {
9124 json_object_string_add(json_neigh, "hostLocal", sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN));
9125 json_object_int_add(json_neigh, "portLocal", ntohs (p->su_local->sin.sin_port));
9126 }
9127 else
9128 vty_out (vty, "Local host: %s, Local port: %d%s",
9129 sockunion2str (p->su_local, buf1, SU_ADDRSTRLEN),
9130 ntohs (p->su_local->sin.sin_port),
9131 VTY_NEWLINE);
718e3744 9132 }
e52702f2 9133
718e3744 9134 /* Remote address. */
9135 if (p->su_remote)
9136 {
856ca177
MS
9137 if (use_json)
9138 {
9139 json_object_string_add(json_neigh, "hostForeign", sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN));
9140 json_object_int_add(json_neigh, "portForeign", ntohs (p->su_remote->sin.sin_port));
9141 }
9142 else
9143 vty_out (vty, "Foreign host: %s, Foreign port: %d%s",
718e3744 9144 sockunion2str (p->su_remote, buf1, SU_ADDRSTRLEN),
9145 ntohs (p->su_remote->sin.sin_port),
9146 VTY_NEWLINE);
9147 }
9148
9149 /* Nexthop display. */
9150 if (p->su_local)
9151 {
856ca177
MS
9152 if (use_json)
9153 {
389e3fe0 9154 json_object_string_add(json_neigh, "nexthop",
44b8cd53 9155 inet_ntop (AF_INET, &p->nexthop.v4, buf1, sizeof(buf1)));
389e3fe0 9156 json_object_string_add(json_neigh, "nexthopGlobal",
44b8cd53 9157 inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, sizeof(buf1)));
389e3fe0 9158 json_object_string_add(json_neigh, "nexthopLocal",
44b8cd53 9159 inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, sizeof(buf1)));
856ca177
MS
9160 if (p->shared_network)
9161 json_object_string_add(json_neigh, "bgpConnection", "sharedNetwork");
9162 else
9163 json_object_string_add(json_neigh, "bgpConnection", "nonSharedNetwork");
856ca177
MS
9164 }
9165 else
9166 {
9167 vty_out (vty, "Nexthop: %s%s",
44b8cd53
DL
9168 inet_ntop (AF_INET, &p->nexthop.v4, buf1, sizeof(buf1)),
9169 VTY_NEWLINE);
856ca177 9170 vty_out (vty, "Nexthop global: %s%s",
44b8cd53
DL
9171 inet_ntop (AF_INET6, &p->nexthop.v6_global, buf1, sizeof(buf1)),
9172 VTY_NEWLINE);
856ca177 9173 vty_out (vty, "Nexthop local: %s%s",
44b8cd53
DL
9174 inet_ntop (AF_INET6, &p->nexthop.v6_local, buf1, sizeof(buf1)),
9175 VTY_NEWLINE);
856ca177 9176 vty_out (vty, "BGP connection: %s%s",
44b8cd53
DL
9177 p->shared_network ? "shared network" : "non shared network",
9178 VTY_NEWLINE);
856ca177 9179 }
718e3744 9180 }
9181
9182 /* Timer information. */
856ca177
MS
9183 if (use_json)
9184 {
39e871e6 9185 json_object_int_add(json_neigh, "connectRetryTimer", p->v_connect);
dd9275d6
ST
9186 if (p->status == Established && p->rtt)
9187 json_object_int_add(json_neigh, "estimatedRttInMsecs", p->rtt);
856ca177
MS
9188 if (p->t_start)
9189 json_object_int_add(json_neigh, "nextStartTimerDueInMsecs", thread_timer_remain_second (p->t_start) * 1000);
9190 if (p->t_connect)
9191 json_object_int_add(json_neigh, "nextConnectTimerDueInMsecs", thread_timer_remain_second (p->t_connect) * 1000);
9192 if (p->t_routeadv)
9193 {
9194 json_object_int_add(json_neigh, "mraiInterval", p->v_routeadv);
9195 json_object_int_add(json_neigh, "mraiTimerExpireInMsecs", thread_timer_remain_second (p->t_routeadv) * 1000);
9196 }
047fc950
DS
9197 if (p->password)
9198 json_object_int_add(json_neigh, "authenticationEnabled", 1);
cb1faec9 9199
856ca177
MS
9200 if (p->t_read)
9201 json_object_string_add(json_neigh, "readThread", "on");
9202 else
9203 json_object_string_add(json_neigh, "readThread", "off");
9204 if (p->t_write)
9205 json_object_string_add(json_neigh, "writeThread", "on");
9206 else
9207 json_object_string_add(json_neigh, "writeThread", "off");
9208 }
9209 else
9210 {
39e871e6
ST
9211 vty_out (vty, "BGP Connect Retry Timer in Seconds: %d%s",
9212 p->v_connect, VTY_NEWLINE);
dd9275d6
ST
9213 if (p->status == Established && p->rtt)
9214 vty_out (vty, "Estimated round trip time: %d ms%s",
9215 p->rtt, VTY_NEWLINE);
856ca177
MS
9216 if (p->t_start)
9217 vty_out (vty, "Next start timer due in %ld seconds%s",
9218 thread_timer_remain_second (p->t_start), VTY_NEWLINE);
9219 if (p->t_connect)
9220 vty_out (vty, "Next connect timer due in %ld seconds%s",
9221 thread_timer_remain_second (p->t_connect), VTY_NEWLINE);
9222 if (p->t_routeadv)
9223 vty_out (vty, "MRAI (interval %u) timer expires in %ld seconds%s",
9224 p->v_routeadv, thread_timer_remain_second (p->t_routeadv),
9225 VTY_NEWLINE);
047fc950
DS
9226 if (p->password)
9227 vty_out (vty, "Peer Authentication Enabled%s", VTY_NEWLINE);
856ca177
MS
9228
9229 vty_out (vty, "Read thread: %s Write thread: %s%s",
9230 p->t_read ? "on" : "off",
9231 p->t_write ? "on" : "off",
9232 VTY_NEWLINE);
9233 }
718e3744 9234
9235 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9236 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
856ca177
MS
9237 bgp_capability_vty_out (vty, p, use_json, json_neigh);
9238
9239 if (!use_json)
9240 vty_out (vty, "%s", VTY_NEWLINE);
c43ed2e4
DS
9241
9242 /* BFD information. */
856ca177
MS
9243 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9244
9245 if (use_json)
9246 {
9247 if (p->conf_if) /* Configured interface name. */
9248 json_object_object_add(json, p->conf_if, json_neigh);
9249 else /* Configured IP address. */
9250 json_object_object_add(json, p->host, json_neigh);
9251 }
718e3744 9252}
9253
94f2b392 9254static int
856ca177
MS
9255bgp_show_neighbor (struct vty *vty, struct bgp *bgp, enum show_type type,
9256 union sockunion *su, const char *conf_if, u_char use_json, json_object *json)
718e3744 9257{
1eb8ef25 9258 struct listnode *node, *nnode;
718e3744 9259 struct peer *peer;
9260 int find = 0;
9261
1eb8ef25 9262 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
718e3744 9263 {
1ff9a340
DS
9264 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9265 continue;
9266
718e3744 9267 switch (type)
856ca177
MS
9268 {
9269 case show_all:
e8f7da3a 9270 bgp_show_peer (vty, peer, use_json, json);
856ca177
MS
9271 break;
9272 case show_peer:
9273 if (conf_if)
9274 {
4873b3b9
DW
9275 if ((peer->conf_if && !strcmp(peer->conf_if, conf_if)) ||
9276 (peer->hostname && !strcmp(peer->hostname, conf_if)))
856ca177
MS
9277 {
9278 find = 1;
e8f7da3a 9279 bgp_show_peer (vty, peer, use_json, json);
856ca177
MS
9280 }
9281 }
9282 else
9283 {
9284 if (sockunion_same (&peer->su, su))
9285 {
9286 find = 1;
e8f7da3a 9287 bgp_show_peer (vty, peer, use_json, json);
856ca177
MS
9288 }
9289 }
9290 break;
718e3744 9291 }
9292 }
9293
9294 if (type == show_peer && ! find)
856ca177
MS
9295 {
9296 if (use_json)
9297 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9298 else
9299 vty_out (vty, "%% No such neighbor%s", VTY_NEWLINE);
9300 }
9301
9302 if (use_json)
9303 {
2aac5767 9304 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
856ca177
MS
9305 json_object_free(json);
9306 }
9307 else
9308 {
9309 vty_out (vty, "%s", VTY_NEWLINE);
9310 }
9311
718e3744 9312 return CMD_SUCCESS;
9313}
9314
f186de26 9315static void
9316bgp_show_all_instances_neighbors_vty (struct vty *vty, u_char use_json)
9317{
9318 struct listnode *node, *nnode;
9319 struct bgp *bgp;
9320 json_object *json = NULL;
9f689658
DD
9321 int is_first = 1;
9322
9323 if (use_json)
9324 vty_out (vty, "{%s", VTY_NEWLINE);
f186de26 9325
9326 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
9327 {
f186de26 9328 if (use_json)
9f689658
DD
9329 {
9330 if (!(json = json_object_new_object()))
9331 {
9332 zlog_err("Unable to allocate memory for JSON object");
9333 vty_out (vty,
9334 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}%s",
9335 VTY_NEWLINE);
9336 return;
9337 }
9338
9339 json_object_int_add(json, "vrfId",
9340 (bgp->vrf_id == VRF_UNKNOWN)
9341 ? -1 : bgp->vrf_id);
9342 json_object_string_add(json, "vrfName",
9343 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9344 ? "Default" : bgp->name);
9345
9346 if (! is_first)
9347 vty_out (vty, ",%s", VTY_NEWLINE);
9348 else
9349 is_first = 0;
9350
9351 vty_out(vty, "\"%s\":", (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9352 ? "Default" : bgp->name);
9353 }
9354 else
9355 {
9356 vty_out (vty, "%sInstance %s:%s",
9357 VTY_NEWLINE,
9358 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9359 ? "Default" : bgp->name,
9360 VTY_NEWLINE);
9361 }
f186de26 9362 bgp_show_neighbor (vty, bgp, show_all, NULL, NULL, use_json, json);
9363 }
9f689658
DD
9364
9365 if (use_json)
9366 vty_out (vty, "}%s", VTY_NEWLINE);
f186de26 9367}
9368
4fb25c53
DW
9369static int
9370bgp_show_neighbor_vty (struct vty *vty, const char *name,
9371 enum show_type type, const char *ip_str, u_char use_json)
9372{
9373 int ret;
9374 struct bgp *bgp;
9375 union sockunion su;
9376 json_object *json = NULL;
9377
4fb25c53
DW
9378 if (name)
9379 {
9380 if (strmatch(name, "all"))
9381 {
9382 bgp_show_all_instances_neighbors_vty (vty, use_json);
9383 return CMD_SUCCESS;
9384 }
9385 else
9386 {
9387 bgp = bgp_lookup_by_name (name);
9388 if (! bgp)
9389 {
9390 if (use_json)
9391 {
47332bd0 9392 json = json_object_new_object();
4fb25c53 9393 json_object_boolean_true_add(json, "bgpNoSuchInstance");
e52702f2 9394 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
4fb25c53
DW
9395 json_object_free(json);
9396 }
9397 else
9398 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9399
9400 return CMD_WARNING;
9401 }
9402 }
9403 }
9404 else
9405 {
9406 bgp = bgp_get_default ();
9407 }
9408
9409 if (bgp)
9410 {
47332bd0 9411 json = json_object_new_object();
4fb25c53
DW
9412 if (ip_str)
9413 {
9414 ret = str2sockunion (ip_str, &su);
9415 if (ret < 0)
9416 bgp_show_neighbor (vty, bgp, type, NULL, ip_str, use_json, json);
9417 else
9418 bgp_show_neighbor (vty, bgp, type, &su, NULL, use_json, json);
9419 }
9420 else
9421 {
9422 bgp_show_neighbor (vty, bgp, type, NULL, NULL, use_json, json);
9423 }
47332bd0 9424 json_object_free (json);
4fb25c53
DW
9425 }
9426
9427 return CMD_SUCCESS;
9428}
9429
716b2d8a 9430/* "show [ip] bgp neighbors" commands. */
718e3744 9431DEFUN (show_ip_bgp_neighbors,
9432 show_ip_bgp_neighbors_cmd,
18c57037 9433 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|vpnv4 <all|rd ASN:nn_or_IP-address:nn>>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 9434 SHOW_STR
9435 IP_STR
9436 BGP_STR
f2a8972b 9437 BGP_INSTANCE_HELP_STR
8c3deaae
QY
9438 "Address Family\n"
9439 "Address Family\n"
91d37724
QY
9440 "Address Family\n"
9441 "Display information about all VPNv4 NLRIs\n"
9442 "Display information for a route distinguisher\n"
9443 "VPN Route Distinguisher\n"
718e3744 9444 "Detailed information on TCP and BGP neighbor connections\n"
9445 "Neighbor to display information about\n"
a80beece 9446 "Neighbor to display information about\n"
91d37724 9447 "Neighbor on BGP configured interface\n"
9973d184 9448 JSON_STR)
718e3744 9449{
5bf15956
DW
9450 char *vrf = NULL;
9451 char *sh_arg = NULL;
9452 enum show_type sh_type;
718e3744 9453
5bf15956 9454 u_char uj = use_json(argc, argv);
718e3744 9455
630a298c 9456 int idx = 0;
718e3744 9457
46854ac0
DS
9458 if (argv_find (argv, argc, "view", &idx) ||
9459 argv_find (argv, argc, "vrf", &idx))
9460 vrf = argv[idx+1]->arg;
718e3744 9461
46854ac0 9462 idx++;
91d37724
QY
9463 if (argv_find (argv, argc, "A.B.C.D", &idx) ||
9464 argv_find (argv, argc, "X:X::X:X", &idx) ||
630a298c
QY
9465 argv_find (argv, argc, "WORD", &idx))
9466 {
9467 sh_type = show_peer;
9468 sh_arg = argv[idx]->arg;
9469 }
5bf15956 9470 else
630a298c 9471 sh_type = show_all;
856ca177 9472
5bf15956 9473 return bgp_show_neighbor_vty (vty, vrf, sh_type, sh_arg, uj);
718e3744 9474}
9475
716b2d8a 9476/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 9477 paths' and `show ip mbgp paths'. Those functions results are the
9478 same.*/
f412b39a 9479DEFUN (show_ip_bgp_paths,
718e3744 9480 show_ip_bgp_paths_cmd,
46f296b4 9481 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 9482 SHOW_STR
9483 IP_STR
9484 BGP_STR
46f296b4 9485 BGP_SAFI_HELP_STR
718e3744 9486 "Path information\n")
9487{
9488 vty_out (vty, "Address Refcnt Path%s", VTY_NEWLINE);
9489 aspath_print_all_vty (vty);
9490 return CMD_SUCCESS;
9491}
9492
718e3744 9493#include "hash.h"
9494
94f2b392 9495static void
718e3744 9496community_show_all_iterator (struct hash_backet *backet, struct vty *vty)
9497{
9498 struct community *com;
9499
9500 com = (struct community *) backet->data;
6c4f4e6e 9501 vty_out (vty, "[%p] (%ld) %s%s", (void *)backet, com->refcnt,
718e3744 9502 community_str (com), VTY_NEWLINE);
9503}
9504
9505/* Show BGP's community internal data. */
f412b39a 9506DEFUN (show_ip_bgp_community_info,
718e3744 9507 show_ip_bgp_community_info_cmd,
bec37ba5 9508 "show [ip] bgp community-info",
718e3744 9509 SHOW_STR
9510 IP_STR
9511 BGP_STR
9512 "List all bgp community information\n")
9513{
9514 vty_out (vty, "Address Refcnt Community%s", VTY_NEWLINE);
9515
e52702f2 9516 hash_iterate (community_hash (),
718e3744 9517 (void (*) (struct hash_backet *, void *))
9518 community_show_all_iterator,
9519 vty);
9520
9521 return CMD_SUCCESS;
9522}
9523
57d187bc
JS
9524static void
9525lcommunity_show_all_iterator (struct hash_backet *backet, struct vty *vty)
9526{
9527 struct lcommunity *lcom;
9528
9529 lcom = (struct lcommunity *) backet->data;
9530 vty_out (vty, "[%p] (%ld) %s%s", (void *)backet, lcom->refcnt,
2acb4ac2 9531 lcommunity_str (lcom), VTY_NEWLINE);
57d187bc
JS
9532}
9533
9534/* Show BGP's community internal data. */
9535DEFUN (show_ip_bgp_lcommunity_info,
9536 show_ip_bgp_lcommunity_info_cmd,
9537 "show ip bgp large-community-info",
9538 SHOW_STR
9539 IP_STR
9540 BGP_STR
9541 "List all bgp large-community information\n")
9542{
9543 vty_out (vty, "Address Refcnt Large-community%s", VTY_NEWLINE);
9544
9545 hash_iterate (lcommunity_hash (),
2acb4ac2
DL
9546 (void (*) (struct hash_backet *, void *))
9547 lcommunity_show_all_iterator,
9548 vty);
57d187bc
JS
9549
9550 return CMD_SUCCESS;
9551}
9552
9553
f412b39a 9554DEFUN (show_ip_bgp_attr_info,
718e3744 9555 show_ip_bgp_attr_info_cmd,
bec37ba5 9556 "show [ip] bgp attribute-info",
718e3744 9557 SHOW_STR
9558 IP_STR
9559 BGP_STR
9560 "List all bgp attribute information\n")
9561{
9562 attr_show_all (vty);
9563 return CMD_SUCCESS;
9564}
6b0655a2 9565
f186de26 9566static void
9567bgp_show_all_instances_updgrps_vty (struct vty *vty, afi_t afi, safi_t safi)
9568{
9569 struct listnode *node, *nnode;
9570 struct bgp *bgp;
9571
9572 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
9573 {
9574 vty_out (vty, "%sInstance %s:%s",
9575 VTY_NEWLINE,
9576 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) ? "Default" : bgp->name,
9577 VTY_NEWLINE);
9578 update_group_show(bgp, afi, safi, vty, 0);
9579 }
9580}
9581
4fb25c53
DW
9582static int
9583bgp_show_update_groups(struct vty *vty, const char *name,
9584 int afi, int safi,
9585 uint64_t subgrp_id)
9586{
9587 struct bgp *bgp;
9588
9589 if (name)
9590 {
9591 if (strmatch (name, "all"))
9592 {
9593 bgp_show_all_instances_updgrps_vty (vty, afi, safi);
9594 return CMD_SUCCESS;
9595 }
9596 else
9597 {
9598 bgp = bgp_lookup_by_name (name);
9599 }
9600 }
9601 else
9602 {
9603 bgp = bgp_get_default ();
9604 }
9605
9606 if (bgp)
9607 update_group_show(bgp, afi, safi, vty, subgrp_id);
9608 return CMD_SUCCESS;
9609}
9610
8fe8a7f6
DS
9611DEFUN (show_ip_bgp_updgrps,
9612 show_ip_bgp_updgrps_cmd,
18c57037 9613 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 9614 SHOW_STR
9615 IP_STR
9616 BGP_STR
9617 BGP_INSTANCE_HELP_STR
c9e571b4 9618 BGP_AFI_HELP_STR
46f296b4 9619 BGP_SAFI_HELP_STR
5bf15956
DW
9620 "Detailed info about dynamic update groups\n"
9621 "Specific subgroup to display detailed info for\n")
8386ac43 9622{
5bf15956 9623 char *vrf = NULL;
ae19d7dd
QY
9624 afi_t afi = AFI_IP6;
9625 safi_t safi = SAFI_UNICAST;
5bf15956
DW
9626 uint64_t subgrp_id = 0;
9627
ae19d7dd
QY
9628 int idx = 0;
9629
9630 /* show [ip] bgp */
9631 if (argv_find (argv, argc, "ip", &idx))
9632 afi = AFI_IP;
18c57037 9633 /* [<view|vrf> VIEWVRFNAME] */
ae19d7dd
QY
9634 if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
9635 vrf = argv[++idx]->arg;
c9e571b4
LB
9636 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
9637 if (argv_find_and_parse_afi (argv, argc, &idx, &afi))
9638 {
9639 argv_find_and_parse_safi (argv, argc, &idx, &safi);
9640 }
5bf15956 9641
ae19d7dd
QY
9642 /* get subgroup id, if provided */
9643 idx = argc - 1;
9644 if (argv[idx]->type == VARIABLE_TKN)
9645 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx]->arg);
5bf15956
DW
9646
9647 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
9648}
9649
f186de26 9650DEFUN (show_bgp_instance_all_ipv6_updgrps,
9651 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 9652 "show [ip] bgp <view|vrf> all update-groups",
f186de26 9653 SHOW_STR
716b2d8a 9654 IP_STR
f186de26 9655 BGP_STR
9656 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 9657 "Detailed info about dynamic update groups\n")
f186de26 9658{
9659 bgp_show_all_instances_updgrps_vty (vty, AFI_IP6, SAFI_UNICAST);
9660 return CMD_SUCCESS;
9661}
9662
5bf15956
DW
9663DEFUN (show_bgp_updgrps_stats,
9664 show_bgp_updgrps_stats_cmd,
716b2d8a 9665 "show [ip] bgp update-groups statistics",
3f9c7369 9666 SHOW_STR
716b2d8a 9667 IP_STR
3f9c7369 9668 BGP_STR
0c7b1b01 9669 "Detailed info about dynamic update groups\n"
3f9c7369
DS
9670 "Statistics\n")
9671{
9672 struct bgp *bgp;
9673
9674 bgp = bgp_get_default();
9675 if (bgp)
9676 update_group_show_stats(bgp, vty);
9677
9678 return CMD_SUCCESS;
9679}
9680
8386ac43 9681DEFUN (show_bgp_instance_updgrps_stats,
9682 show_bgp_instance_updgrps_stats_cmd,
18c57037 9683 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 9684 SHOW_STR
716b2d8a 9685 IP_STR
8386ac43 9686 BGP_STR
9687 BGP_INSTANCE_HELP_STR
0c7b1b01 9688 "Detailed info about dynamic update groups\n"
8386ac43 9689 "Statistics\n")
9690{
c500ae40 9691 int idx_word = 3;
8386ac43 9692 struct bgp *bgp;
9693
c500ae40 9694 bgp = bgp_lookup_by_name (argv[idx_word]->arg);
8386ac43 9695 if (bgp)
9696 update_group_show_stats(bgp, vty);
9697
9698 return CMD_SUCCESS;
9699}
9700
3f9c7369 9701static void
8386ac43 9702show_bgp_updgrps_adj_info_aux (struct vty *vty, const char *name,
9703 afi_t afi, safi_t safi,
f43e655e 9704 const char *what, uint64_t subgrp_id)
3f9c7369
DS
9705{
9706 struct bgp *bgp;
8386ac43 9707
9708 if (name)
9709 bgp = bgp_lookup_by_name (name);
9710 else
9711 bgp = bgp_get_default ();
9712
3f9c7369
DS
9713 if (bgp)
9714 {
9715 if (!strcmp(what, "advertise-queue"))
9716 update_group_show_adj_queue(bgp, afi, safi, vty, subgrp_id);
9717 else if (!strcmp(what, "advertised-routes"))
9718 update_group_show_advertised(bgp, afi, safi, vty, subgrp_id);
9719 else if (!strcmp(what, "packet-queue"))
9720 update_group_show_packet_queue(bgp, afi, safi, vty, subgrp_id);
9721 }
9722}
9723
9724DEFUN (show_ip_bgp_updgrps_adj,
9725 show_ip_bgp_updgrps_adj_cmd,
716b2d8a 9726 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
9727 SHOW_STR
9728 IP_STR
9729 BGP_STR
0c7b1b01 9730 "Detailed info about dynamic update groups\n"
3f9c7369
DS
9731 "Advertisement queue\n"
9732 "Announced routes\n"
9733 "Packet queue\n")
8fe8a7f6 9734
3f9c7369 9735{
c500ae40
DW
9736 int idx_type = 4;
9737 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, 0);
8386ac43 9738 return CMD_SUCCESS;
9739}
9740
9741DEFUN (show_ip_bgp_instance_updgrps_adj,
9742 show_ip_bgp_instance_updgrps_adj_cmd,
18c57037 9743 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 9744 SHOW_STR
9745 IP_STR
9746 BGP_STR
9747 BGP_INSTANCE_HELP_STR
0c7b1b01 9748 "Detailed info about dynamic update groups\n"
8386ac43 9749 "Advertisement queue\n"
9750 "Announced routes\n"
9751 "Packet queue\n")
9752
9753{
c500ae40
DW
9754 int idx_word = 4;
9755 int idx_type = 6;
9756 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, 0);
3f9c7369
DS
9757 return CMD_SUCCESS;
9758}
9759
9760DEFUN (show_bgp_updgrps_afi_adj,
9761 show_bgp_updgrps_afi_adj_cmd,
46f296b4 9762 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 9763 SHOW_STR
716b2d8a 9764 IP_STR
3f9c7369 9765 BGP_STR
46f296b4 9766 BGP_AFI_SAFI_HELP_STR
0c7b1b01 9767 "Detailed info about dynamic update groups\n"
3f9c7369
DS
9768 "Advertisement queue\n"
9769 "Announced routes\n"
8fe8a7f6
DS
9770 "Packet queue\n"
9771 "Specific subgroup info wanted for\n")
3f9c7369 9772{
c500ae40
DW
9773 int idx_afi = 2;
9774 int idx_safi = 3;
9775 int idx_type = 5;
46f296b4
LB
9776 show_bgp_updgrps_adj_info_aux(vty, NULL,
9777 bgp_vty_afi_from_arg(argv[idx_afi]->arg),
9778 bgp_vty_safi_from_arg(argv[idx_safi]->arg),
9779 argv[idx_type]->arg, 0);
8fe8a7f6 9780 return CMD_SUCCESS;
3f9c7369
DS
9781}
9782
9783DEFUN (show_bgp_updgrps_adj,
9784 show_bgp_updgrps_adj_cmd,
716b2d8a 9785 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 9786 SHOW_STR
716b2d8a 9787 IP_STR
3f9c7369 9788 BGP_STR
0c7b1b01 9789 "Detailed info about dynamic update groups\n"
3f9c7369
DS
9790 "Advertisement queue\n"
9791 "Announced routes\n"
9792 "Packet queue\n")
9793{
c500ae40
DW
9794 int idx_type = 3;
9795 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, 0);
8386ac43 9796 return CMD_SUCCESS;
9797}
9798
9799DEFUN (show_bgp_instance_updgrps_adj,
9800 show_bgp_instance_updgrps_adj_cmd,
18c57037 9801 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 9802 SHOW_STR
716b2d8a 9803 IP_STR
8386ac43 9804 BGP_STR
9805 BGP_INSTANCE_HELP_STR
0c7b1b01 9806 "Detailed info about dynamic update groups\n"
8386ac43 9807 "Advertisement queue\n"
9808 "Announced routes\n"
9809 "Packet queue\n")
9810{
c500ae40
DW
9811 int idx_word = 3;
9812 int idx_type = 5;
9813 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, 0);
3f9c7369
DS
9814 return CMD_SUCCESS;
9815}
9816
9817DEFUN (show_ip_bgp_updgrps_adj_s,
8fe8a7f6 9818 show_ip_bgp_updgrps_adj_s_cmd,
716b2d8a 9819 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
9820 SHOW_STR
9821 IP_STR
9822 BGP_STR
0c7b1b01 9823 "Detailed info about dynamic update groups\n"
8fe8a7f6 9824 "Specific subgroup to display info for\n"
3f9c7369
DS
9825 "Advertisement queue\n"
9826 "Announced routes\n"
9827 "Packet queue\n")
3f9c7369 9828
3f9c7369 9829{
5bf15956 9830 int idx_subgroup_id = 4;
c500ae40 9831 int idx_type = 5;
f43e655e 9832 uint64_t subgrp_id;
8fe8a7f6 9833
5bf15956 9834 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8fe8a7f6 9835
5bf15956 9836 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
8386ac43 9837 return CMD_SUCCESS;
9838}
9839
9840DEFUN (show_ip_bgp_instance_updgrps_adj_s,
9841 show_ip_bgp_instance_updgrps_adj_s_cmd,
18c57037 9842 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 9843 SHOW_STR
9844 IP_STR
9845 BGP_STR
9846 BGP_INSTANCE_HELP_STR
0c7b1b01 9847 "Detailed info about dynamic update groups\n"
8386ac43 9848 "Specific subgroup to display info for\n"
9849 "Advertisement queue\n"
9850 "Announced routes\n"
9851 "Packet queue\n")
9852
9853{
5bf15956
DW
9854 int idx_vrf = 4;
9855 int idx_subgroup_id = 6;
c500ae40 9856 int idx_type = 7;
f43e655e 9857 uint64_t subgrp_id;
8386ac43 9858
5bf15956 9859 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8386ac43 9860
5bf15956 9861 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
3f9c7369
DS
9862 return CMD_SUCCESS;
9863}
9864
8fe8a7f6
DS
9865DEFUN (show_bgp_updgrps_afi_adj_s,
9866 show_bgp_updgrps_afi_adj_s_cmd,
46f296b4 9867 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 9868 SHOW_STR
716b2d8a 9869 IP_STR
3f9c7369 9870 BGP_STR
46f296b4 9871 BGP_AFI_SAFI_HELP_STR
0c7b1b01 9872 "Detailed info about dynamic update groups\n"
8fe8a7f6 9873 "Specific subgroup to display info for\n"
3f9c7369
DS
9874 "Advertisement queue\n"
9875 "Announced routes\n"
8fe8a7f6
DS
9876 "Packet queue\n"
9877 "Specific subgroup info wanted for\n")
3f9c7369 9878{
c500ae40
DW
9879 int idx_afi = 2;
9880 int idx_safi = 3;
5bf15956 9881 int idx_subgroup_id = 5;
c500ae40 9882 int idx_type = 6;
f43e655e 9883 uint64_t subgrp_id;
3f9c7369 9884
5bf15956 9885 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8fe8a7f6 9886
46f296b4
LB
9887 show_bgp_updgrps_adj_info_aux(vty, NULL,
9888 bgp_vty_afi_from_arg(argv[idx_afi]->arg),
9889 bgp_vty_safi_from_arg(argv[idx_safi]->arg),
9890 argv[idx_type]->arg, subgrp_id);
8fe8a7f6 9891 return CMD_SUCCESS;
3f9c7369
DS
9892}
9893
8fe8a7f6
DS
9894DEFUN (show_bgp_updgrps_adj_s,
9895 show_bgp_updgrps_adj_s_cmd,
716b2d8a 9896 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8fe8a7f6 9897 SHOW_STR
716b2d8a 9898 IP_STR
8fe8a7f6 9899 BGP_STR
0c7b1b01 9900 "Detailed info about dynamic update groups\n"
8fe8a7f6
DS
9901 "Specific subgroup to display info for\n"
9902 "Advertisement queue\n"
9903 "Announced routes\n"
9904 "Packet queue\n")
9905{
5bf15956 9906 int idx_subgroup_id = 3;
c500ae40 9907 int idx_type = 4;
f43e655e 9908 uint64_t subgrp_id;
8fe8a7f6 9909
5bf15956 9910 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8fe8a7f6 9911
5bf15956 9912 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
8fe8a7f6
DS
9913 return CMD_SUCCESS;
9914}
9915
8386ac43 9916DEFUN (show_bgp_instance_updgrps_adj_s,
9917 show_bgp_instance_updgrps_adj_s_cmd,
18c57037 9918 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 9919 SHOW_STR
716b2d8a 9920 IP_STR
8386ac43 9921 BGP_STR
9922 BGP_INSTANCE_HELP_STR
0c7b1b01 9923 "Detailed info about dynamic update groups\n"
8386ac43 9924 "Specific subgroup to display info for\n"
9925 "Advertisement queue\n"
9926 "Announced routes\n"
9927 "Packet queue\n")
9928{
5bf15956
DW
9929 int idx_vrf = 3;
9930 int idx_subgroup_id = 5;
c500ae40 9931 int idx_type = 6;
f43e655e 9932 uint64_t subgrp_id;
8386ac43 9933
5bf15956 9934 VTY_GET_ULL("subgroup-id", subgrp_id, argv[idx_subgroup_id]->arg);
8386ac43 9935
5bf15956 9936 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6, SAFI_UNICAST, argv[idx_type]->arg, subgrp_id);
8386ac43 9937 return CMD_SUCCESS;
9938}
9939
9940
8fe8a7f6 9941
f14e6fdb
DS
9942static int
9943bgp_show_one_peer_group (struct vty *vty, struct peer_group *group)
9944{
9945 struct listnode *node, *nnode;
9946 struct prefix *range;
9947 struct peer *conf;
9948 struct peer *peer;
4690c7d7 9949 char buf[PREFIX2STR_BUFFER];
f14e6fdb
DS
9950 afi_t afi;
9951 safi_t safi;
ffd0c037
DS
9952 const char *peer_status;
9953 const char *af_str;
f14e6fdb
DS
9954 int lr_count;
9955 int dynamic;
9956 int af_cfgd;
9957
9958 conf = group->conf;
9959
0299c004
DS
9960 if (conf->as_type == AS_SPECIFIED ||
9961 conf->as_type == AS_EXTERNAL) {
66b199b2 9962 vty_out (vty, "%sBGP peer-group %s, remote AS %d%s",
f14e6fdb 9963 VTY_NEWLINE, group->name, conf->as, VTY_NEWLINE);
0299c004 9964 } else if (conf->as_type == AS_INTERNAL) {
66b199b2 9965 vty_out (vty, "%sBGP peer-group %s, remote AS %d%s",
0299c004 9966 VTY_NEWLINE, group->name, group->bgp->as, VTY_NEWLINE);
66b199b2
DS
9967 } else {
9968 vty_out (vty, "%sBGP peer-group %s%s",
9969 VTY_NEWLINE, group->name, VTY_NEWLINE);
0299c004 9970 }
f14e6fdb 9971
0299c004 9972 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
f14e6fdb
DS
9973 vty_out (vty, " Peer-group type is internal%s", VTY_NEWLINE);
9974 else
9975 vty_out (vty, " Peer-group type is external%s", VTY_NEWLINE);
9976
9977 /* Display AFs configured. */
9978 vty_out (vty, " Configured address-families:");
9979 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9980 for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++)
9981 {
9982 if (conf->afc[afi][safi])
9983 {
9984 af_cfgd = 1;
9985 vty_out (vty, " %s;", afi_safi_print(afi, safi));
9986 }
9987 }
9988 if (!af_cfgd)
9989 vty_out (vty, " none%s", VTY_NEWLINE);
9990 else
9991 vty_out (vty, "%s", VTY_NEWLINE);
9992
9993 /* Display listen ranges (for dynamic neighbors), if any */
9994 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9995 {
9996 if (afi == AFI_IP)
9997 af_str = "IPv4";
9998 else if (afi == AFI_IP6)
9999 af_str = "IPv6";
45ef4300
DL
10000 else
10001 af_str = "???";
f14e6fdb
DS
10002 lr_count = listcount(group->listen_range[afi]);
10003 if (lr_count)
10004 {
10005 vty_out(vty,
10006 " %d %s listen range(s)%s",
10007 lr_count, af_str, VTY_NEWLINE);
10008
10009
10010 for (ALL_LIST_ELEMENTS (group->listen_range[afi], node,
10011 nnode, range))
10012 {
10013 prefix2str(range, buf, sizeof(buf));
10014 vty_out(vty, " %s%s", buf, VTY_NEWLINE);
10015 }
10016 }
10017 }
10018
10019 /* Display group members and their status */
10020 if (listcount(group->peer))
10021 {
10022 vty_out (vty, " Peer-group members:%s", VTY_NEWLINE);
10023 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
10024 {
10025 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
10026 peer_status = "Idle (Admin)";
10027 else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
10028 peer_status = "Idle (PfxCt)";
10029 else
10030 peer_status = LOOKUP(bgp_status_msg, peer->status);
10031
10032 dynamic = peer_dynamic_neighbor(peer);
10033 vty_out (vty, " %s %s %s %s",
10034 peer->host, dynamic ? "(dynamic)" : "",
10035 peer_status, VTY_NEWLINE);
10036 }
10037 }
10038
10039 return CMD_SUCCESS;
10040}
10041
10042/* Show BGP peer group's information. */
10043enum show_group_type
10044{
10045 show_all_groups,
10046 show_peer_group
10047};
10048
10049static int
10050bgp_show_peer_group (struct vty *vty, struct bgp *bgp,
10051 enum show_group_type type, const char *group_name)
10052{
10053 struct listnode *node, *nnode;
10054 struct peer_group *group;
10055 int find = 0;
10056
10057 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
10058 {
10059 switch (type)
10060 {
10061 case show_all_groups:
10062 bgp_show_one_peer_group (vty, group);
10063 break;
10064 case show_peer_group:
10065 if (group_name && (strcmp(group->name, group_name) == 0))
10066 {
10067 find = 1;
10068 bgp_show_one_peer_group (vty, group);
10069 }
10070 break;
10071 }
10072 }
10073
10074 if (type == show_peer_group && ! find)
6d9e66dc 10075 vty_out (vty, "%% No such peer-group%s", VTY_NEWLINE);
f14e6fdb
DS
10076
10077 return CMD_SUCCESS;
10078}
10079
10080static int
10081bgp_show_peer_group_vty (struct vty *vty, const char *name,
10082 enum show_group_type type, const char *group_name)
10083{
10084 struct bgp *bgp;
10085 int ret = CMD_SUCCESS;
10086
10087 if (name)
8386ac43 10088 bgp = bgp_lookup_by_name (name);
10089 else
10090 bgp = bgp_get_default ();
f14e6fdb 10091
8386ac43 10092 if (! bgp)
10093 {
10094 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
10095 return CMD_WARNING;
f14e6fdb
DS
10096 }
10097
8386ac43 10098 ret = bgp_show_peer_group (vty, bgp, type, group_name);
f14e6fdb
DS
10099
10100 return ret;
10101}
10102
10103DEFUN (show_ip_bgp_peer_groups,
10104 show_ip_bgp_peer_groups_cmd,
18c57037 10105 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10106 SHOW_STR
10107 IP_STR
10108 BGP_STR
8386ac43 10109 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10110 "Detailed information on BGP peer groups\n"
10111 "Peer group name\n")
f14e6fdb 10112{
d6e3c605
QY
10113 char *vrf, *pg;
10114 vrf = pg = NULL;
10115 int idx = 0;
f14e6fdb 10116
f2a8972b 10117 vrf = argv_find (argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
d6e3c605 10118 pg = argv_find (argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10119
d6e3c605 10120 return bgp_show_peer_group_vty (vty, vrf, show_all_groups, pg);
f14e6fdb 10121}
3f9c7369 10122
d6e3c605 10123
718e3744 10124/* Redistribute VTY commands. */
10125
718e3744 10126DEFUN (bgp_redistribute_ipv4,
10127 bgp_redistribute_ipv4_cmd,
40d1cbfb 10128 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 10129 "Redistribute information from another routing protocol\n"
ab0181ee 10130 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 10131{
cdc2d765 10132 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 10133 int idx_protocol = 1;
718e3744 10134 int type;
10135
6d681bd8
QY
10136 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10137 if (type < 0)
718e3744 10138 {
10139 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10140 return CMD_WARNING;
10141 }
cdc2d765
DL
10142 bgp_redist_add(bgp, AFI_IP, type, 0);
10143 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
718e3744 10144}
10145
596c17ba
DW
10146ALIAS_HIDDEN (bgp_redistribute_ipv4,
10147 bgp_redistribute_ipv4_hidden_cmd,
10148 "redistribute " FRR_IP_REDIST_STR_BGPD,
10149 "Redistribute information from another routing protocol\n"
10150 FRR_IP_REDIST_HELP_STR_BGPD)
10151
718e3744 10152DEFUN (bgp_redistribute_ipv4_rmap,
10153 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 10154 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 10155 "Redistribute information from another routing protocol\n"
ab0181ee 10156 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10157 "Route map reference\n"
10158 "Pointer to route-map entries\n")
10159{
cdc2d765 10160 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10161 int idx_protocol = 1;
10162 int idx_word = 3;
718e3744 10163 int type;
7c8ff89e 10164 struct bgp_redist *red;
718e3744 10165
6d681bd8
QY
10166 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10167 if (type < 0)
718e3744 10168 {
10169 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10170 return CMD_WARNING;
10171 }
10172
cdc2d765 10173 red = bgp_redist_add(bgp, AFI_IP, type, 0);
c500ae40 10174 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765 10175 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
718e3744 10176}
10177
596c17ba
DW
10178ALIAS_HIDDEN (bgp_redistribute_ipv4_rmap,
10179 bgp_redistribute_ipv4_rmap_hidden_cmd,
10180 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10181 "Redistribute information from another routing protocol\n"
10182 FRR_IP_REDIST_HELP_STR_BGPD
10183 "Route map reference\n"
10184 "Pointer to route-map entries\n")
10185
718e3744 10186DEFUN (bgp_redistribute_ipv4_metric,
10187 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 10188 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 10189 "Redistribute information from another routing protocol\n"
ab0181ee 10190 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10191 "Metric for redistributed routes\n"
10192 "Default metric\n")
10193{
cdc2d765 10194 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10195 int idx_protocol = 1;
10196 int idx_number = 3;
718e3744 10197 int type;
10198 u_int32_t metric;
7c8ff89e 10199 struct bgp_redist *red;
718e3744 10200
6d681bd8
QY
10201 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10202 if (type < 0)
718e3744 10203 {
10204 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10205 return CMD_WARNING;
10206 }
c500ae40 10207 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 10208
cdc2d765
DL
10209 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10210 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10211 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
718e3744 10212}
10213
596c17ba
DW
10214ALIAS_HIDDEN (bgp_redistribute_ipv4_metric,
10215 bgp_redistribute_ipv4_metric_hidden_cmd,
10216 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10217 "Redistribute information from another routing protocol\n"
10218 FRR_IP_REDIST_HELP_STR_BGPD
10219 "Metric for redistributed routes\n"
10220 "Default metric\n")
10221
718e3744 10222DEFUN (bgp_redistribute_ipv4_rmap_metric,
10223 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 10224 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 10225 "Redistribute information from another routing protocol\n"
ab0181ee 10226 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10227 "Route map reference\n"
10228 "Pointer to route-map entries\n"
10229 "Metric for redistributed routes\n"
10230 "Default metric\n")
10231{
cdc2d765 10232 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10233 int idx_protocol = 1;
10234 int idx_word = 3;
10235 int idx_number = 5;
718e3744 10236 int type;
10237 u_int32_t metric;
7c8ff89e 10238 struct bgp_redist *red;
718e3744 10239
6d681bd8
QY
10240 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10241 if (type < 0)
718e3744 10242 {
10243 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10244 return CMD_WARNING;
10245 }
c500ae40 10246 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 10247
cdc2d765 10248 red = bgp_redist_add(bgp, AFI_IP, type, 0);
c500ae40 10249 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765
DL
10250 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10251 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
718e3744 10252}
10253
596c17ba
DW
10254ALIAS_HIDDEN (bgp_redistribute_ipv4_rmap_metric,
10255 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10256 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
10257 "Redistribute information from another routing protocol\n"
10258 FRR_IP_REDIST_HELP_STR_BGPD
10259 "Route map reference\n"
10260 "Pointer to route-map entries\n"
10261 "Metric for redistributed routes\n"
10262 "Default metric\n")
10263
718e3744 10264DEFUN (bgp_redistribute_ipv4_metric_rmap,
10265 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 10266 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 10267 "Redistribute information from another routing protocol\n"
ab0181ee 10268 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10269 "Metric for redistributed routes\n"
10270 "Default metric\n"
10271 "Route map reference\n"
10272 "Pointer to route-map entries\n")
10273{
cdc2d765 10274 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10275 int idx_protocol = 1;
10276 int idx_number = 3;
10277 int idx_word = 5;
718e3744 10278 int type;
10279 u_int32_t metric;
7c8ff89e 10280 struct bgp_redist *red;
718e3744 10281
6d681bd8
QY
10282 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10283 if (type < 0)
718e3744 10284 {
10285 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10286 return CMD_WARNING;
10287 }
c500ae40 10288 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 10289
cdc2d765
DL
10290 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10291 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
c500ae40 10292 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765 10293 return bgp_redistribute_set (bgp, AFI_IP, type, 0);
718e3744 10294}
10295
596c17ba
DW
10296ALIAS_HIDDEN (bgp_redistribute_ipv4_metric_rmap,
10297 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10298 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
10299 "Redistribute information from another routing protocol\n"
10300 FRR_IP_REDIST_HELP_STR_BGPD
10301 "Metric for redistributed routes\n"
10302 "Default metric\n"
10303 "Route map reference\n"
10304 "Pointer to route-map entries\n")
10305
7c8ff89e
DS
10306DEFUN (bgp_redistribute_ipv4_ospf,
10307 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 10308 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
10309 "Redistribute information from another routing protocol\n"
10310 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10311 "Non-main Kernel Routing Table\n"
10312 "Instance ID/Table ID\n")
7c8ff89e 10313{
cdc2d765 10314 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10315 int idx_ospf_table = 1;
10316 int idx_number = 2;
7c8ff89e 10317 u_short instance;
7a4bb9c5 10318 u_short protocol;
7c8ff89e 10319
c500ae40 10320 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7a4bb9c5 10321
c500ae40 10322 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
10323 protocol = ZEBRA_ROUTE_OSPF;
10324 else
10325 protocol = ZEBRA_ROUTE_TABLE;
10326
cdc2d765
DL
10327 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10328 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10329}
10330
596c17ba
DW
10331ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf,
10332 bgp_redistribute_ipv4_ospf_hidden_cmd,
10333 "redistribute <ospf|table> (1-65535)",
10334 "Redistribute information from another routing protocol\n"
10335 "Open Shortest Path First (OSPFv2)\n"
10336 "Non-main Kernel Routing Table\n"
10337 "Instance ID/Table ID\n")
10338
7c8ff89e
DS
10339DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10340 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 10341 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
10342 "Redistribute information from another routing protocol\n"
10343 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10344 "Non-main Kernel Routing Table\n"
10345 "Instance ID/Table ID\n"
7c8ff89e
DS
10346 "Route map reference\n"
10347 "Pointer to route-map entries\n")
10348{
cdc2d765 10349 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10350 int idx_ospf_table = 1;
10351 int idx_number = 2;
10352 int idx_word = 4;
7c8ff89e
DS
10353 struct bgp_redist *red;
10354 u_short instance;
7a4bb9c5 10355 int protocol;
7c8ff89e 10356
c500ae40 10357 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
10358 protocol = ZEBRA_ROUTE_OSPF;
10359 else
10360 protocol = ZEBRA_ROUTE_TABLE;
10361
c500ae40 10362 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
cdc2d765 10363 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
c500ae40 10364 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765 10365 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10366}
10367
596c17ba
DW
10368ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf_rmap,
10369 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10370 "redistribute <ospf|table> (1-65535) route-map WORD",
10371 "Redistribute information from another routing protocol\n"
10372 "Open Shortest Path First (OSPFv2)\n"
10373 "Non-main Kernel Routing Table\n"
10374 "Instance ID/Table ID\n"
10375 "Route map reference\n"
10376 "Pointer to route-map entries\n")
10377
7c8ff89e
DS
10378DEFUN (bgp_redistribute_ipv4_ospf_metric,
10379 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 10380 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
10381 "Redistribute information from another routing protocol\n"
10382 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10383 "Non-main Kernel Routing Table\n"
10384 "Instance ID/Table ID\n"
7c8ff89e
DS
10385 "Metric for redistributed routes\n"
10386 "Default metric\n")
10387{
cdc2d765 10388 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10389 int idx_ospf_table = 1;
10390 int idx_number = 2;
10391 int idx_number_2 = 4;
7c8ff89e
DS
10392 u_int32_t metric;
10393 struct bgp_redist *red;
10394 u_short instance;
7a4bb9c5 10395 int protocol;
7c8ff89e 10396
c500ae40 10397 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
10398 protocol = ZEBRA_ROUTE_OSPF;
10399 else
10400 protocol = ZEBRA_ROUTE_TABLE;
7c8ff89e 10401
c500ae40
DW
10402 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
10403 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
7a4bb9c5 10404
cdc2d765
DL
10405 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10406 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10407 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10408}
10409
596c17ba
DW
10410ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf_metric,
10411 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10412 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10413 "Redistribute information from another routing protocol\n"
10414 "Open Shortest Path First (OSPFv2)\n"
10415 "Non-main Kernel Routing Table\n"
10416 "Instance ID/Table ID\n"
10417 "Metric for redistributed routes\n"
10418 "Default metric\n")
10419
7c8ff89e
DS
10420DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10421 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 10422 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
10423 "Redistribute information from another routing protocol\n"
10424 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10425 "Non-main Kernel Routing Table\n"
10426 "Instance ID/Table ID\n"
7c8ff89e
DS
10427 "Route map reference\n"
10428 "Pointer to route-map entries\n"
10429 "Metric for redistributed routes\n"
10430 "Default metric\n")
10431{
cdc2d765 10432 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10433 int idx_ospf_table = 1;
10434 int idx_number = 2;
10435 int idx_word = 4;
10436 int idx_number_2 = 6;
7c8ff89e
DS
10437 u_int32_t metric;
10438 struct bgp_redist *red;
10439 u_short instance;
7a4bb9c5 10440 int protocol;
7c8ff89e 10441
c500ae40 10442 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
10443 protocol = ZEBRA_ROUTE_OSPF;
10444 else
10445 protocol = ZEBRA_ROUTE_TABLE;
7c8ff89e 10446
c500ae40
DW
10447 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
10448 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
7a4bb9c5 10449
cdc2d765 10450 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
c500ae40 10451 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765
DL
10452 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10453 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10454}
10455
596c17ba
DW
10456ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf_rmap_metric,
10457 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10458 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10459 "Redistribute information from another routing protocol\n"
10460 "Open Shortest Path First (OSPFv2)\n"
10461 "Non-main Kernel Routing Table\n"
10462 "Instance ID/Table ID\n"
10463 "Route map reference\n"
10464 "Pointer to route-map entries\n"
10465 "Metric for redistributed routes\n"
10466 "Default metric\n")
10467
7c8ff89e
DS
10468DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
10469 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 10470 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
10471 "Redistribute information from another routing protocol\n"
10472 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10473 "Non-main Kernel Routing Table\n"
10474 "Instance ID/Table ID\n"
7c8ff89e
DS
10475 "Metric for redistributed routes\n"
10476 "Default metric\n"
10477 "Route map reference\n"
10478 "Pointer to route-map entries\n")
10479{
cdc2d765 10480 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10481 int idx_ospf_table = 1;
10482 int idx_number = 2;
10483 int idx_number_2 = 4;
10484 int idx_word = 6;
7c8ff89e
DS
10485 u_int32_t metric;
10486 struct bgp_redist *red;
10487 u_short instance;
7a4bb9c5 10488 int protocol;
7c8ff89e 10489
c500ae40 10490 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
10491 protocol = ZEBRA_ROUTE_OSPF;
10492 else
10493 protocol = ZEBRA_ROUTE_TABLE;
7c8ff89e 10494
c500ae40
DW
10495 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
10496 VTY_GET_INTEGER ("metric", metric, argv[idx_number_2]->arg);
7a4bb9c5 10497
cdc2d765
DL
10498 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10499 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
c500ae40 10500 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765 10501 return bgp_redistribute_set (bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10502}
10503
596c17ba
DW
10504ALIAS_HIDDEN (bgp_redistribute_ipv4_ospf_metric_rmap,
10505 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
10506 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10507 "Redistribute information from another routing protocol\n"
10508 "Open Shortest Path First (OSPFv2)\n"
10509 "Non-main Kernel Routing Table\n"
10510 "Instance ID/Table ID\n"
10511 "Metric for redistributed routes\n"
10512 "Default metric\n"
10513 "Route map reference\n"
10514 "Pointer to route-map entries\n")
10515
7c8ff89e
DS
10516DEFUN (no_bgp_redistribute_ipv4_ospf,
10517 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 10518 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
10519 NO_STR
10520 "Redistribute information from another routing protocol\n"
10521 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 10522 "Non-main Kernel Routing Table\n"
31500417
DW
10523 "Instance ID/Table ID\n"
10524 "Metric for redistributed routes\n"
10525 "Default metric\n"
10526 "Route map reference\n"
10527 "Pointer to route-map entries\n")
7c8ff89e 10528{
cdc2d765 10529 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10530 int idx_ospf_table = 2;
10531 int idx_number = 3;
7c8ff89e 10532 u_short instance;
7a4bb9c5
DS
10533 int protocol;
10534
c500ae40 10535 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7a4bb9c5
DS
10536 protocol = ZEBRA_ROUTE_OSPF;
10537 else
10538 protocol = ZEBRA_ROUTE_TABLE;
7c8ff89e 10539
c500ae40 10540 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
cdc2d765 10541 return bgp_redistribute_unset (bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10542}
10543
596c17ba
DW
10544ALIAS_HIDDEN (no_bgp_redistribute_ipv4_ospf,
10545 no_bgp_redistribute_ipv4_ospf_hidden_cmd,
10546 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
10547 NO_STR
10548 "Redistribute information from another routing protocol\n"
10549 "Open Shortest Path First (OSPFv2)\n"
10550 "Non-main Kernel Routing Table\n"
10551 "Instance ID/Table ID\n"
10552 "Metric for redistributed routes\n"
10553 "Default metric\n"
10554 "Route map reference\n"
10555 "Pointer to route-map entries\n")
10556
718e3744 10557DEFUN (no_bgp_redistribute_ipv4,
10558 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 10559 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 10560 NO_STR
10561 "Redistribute information from another routing protocol\n"
3b14d86e 10562 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
10563 "Metric for redistributed routes\n"
10564 "Default metric\n"
10565 "Route map reference\n"
10566 "Pointer to route-map entries\n")
718e3744 10567{
cdc2d765 10568 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 10569 int idx_protocol = 2;
718e3744 10570 int type;
10571
6d681bd8
QY
10572 type = proto_redistnum (AFI_IP, argv[idx_protocol]->text);
10573 if (type < 0)
718e3744 10574 {
10575 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10576 return CMD_WARNING;
10577 }
cdc2d765 10578 return bgp_redistribute_unset (bgp, AFI_IP, type, 0);
718e3744 10579}
10580
596c17ba
DW
10581ALIAS_HIDDEN (no_bgp_redistribute_ipv4,
10582 no_bgp_redistribute_ipv4_hidden_cmd,
10583 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
10584 NO_STR
10585 "Redistribute information from another routing protocol\n"
10586 FRR_IP_REDIST_HELP_STR_BGPD
10587 "Metric for redistributed routes\n"
10588 "Default metric\n"
10589 "Route map reference\n"
10590 "Pointer to route-map entries\n")
10591
718e3744 10592DEFUN (bgp_redistribute_ipv6,
10593 bgp_redistribute_ipv6_cmd,
40d1cbfb 10594 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 10595 "Redistribute information from another routing protocol\n"
ab0181ee 10596 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 10597{
cdc2d765 10598 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 10599 int idx_protocol = 1;
718e3744 10600 int type;
10601
6d681bd8
QY
10602 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10603 if (type < 0)
718e3744 10604 {
10605 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10606 return CMD_WARNING;
10607 }
10608
cdc2d765
DL
10609 bgp_redist_add(bgp, AFI_IP6, type, 0);
10610 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
718e3744 10611}
10612
10613DEFUN (bgp_redistribute_ipv6_rmap,
10614 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 10615 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 10616 "Redistribute information from another routing protocol\n"
ab0181ee 10617 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 10618 "Route map reference\n"
10619 "Pointer to route-map entries\n")
10620{
cdc2d765 10621 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10622 int idx_protocol = 1;
10623 int idx_word = 3;
718e3744 10624 int type;
7c8ff89e 10625 struct bgp_redist *red;
718e3744 10626
6d681bd8
QY
10627 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10628 if (type < 0)
718e3744 10629 {
10630 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10631 return CMD_WARNING;
10632 }
10633
cdc2d765 10634 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
c500ae40 10635 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765 10636 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
718e3744 10637}
10638
10639DEFUN (bgp_redistribute_ipv6_metric,
10640 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 10641 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 10642 "Redistribute information from another routing protocol\n"
ab0181ee 10643 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 10644 "Metric for redistributed routes\n"
10645 "Default metric\n")
10646{
cdc2d765 10647 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10648 int idx_protocol = 1;
10649 int idx_number = 3;
718e3744 10650 int type;
10651 u_int32_t metric;
7c8ff89e 10652 struct bgp_redist *red;
718e3744 10653
6d681bd8
QY
10654 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10655 if (type < 0)
718e3744 10656 {
10657 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10658 return CMD_WARNING;
10659 }
c500ae40 10660 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 10661
cdc2d765
DL
10662 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
10663 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
10664 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
718e3744 10665}
10666
10667DEFUN (bgp_redistribute_ipv6_rmap_metric,
10668 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 10669 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 10670 "Redistribute information from another routing protocol\n"
ab0181ee 10671 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 10672 "Route map reference\n"
10673 "Pointer to route-map entries\n"
10674 "Metric for redistributed routes\n"
10675 "Default metric\n")
10676{
cdc2d765 10677 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10678 int idx_protocol = 1;
10679 int idx_word = 3;
10680 int idx_number = 5;
718e3744 10681 int type;
10682 u_int32_t metric;
7c8ff89e 10683 struct bgp_redist *red;
718e3744 10684
6d681bd8
QY
10685 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10686 if (type < 0)
718e3744 10687 {
10688 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10689 return CMD_WARNING;
10690 }
c500ae40 10691 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 10692
cdc2d765 10693 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
c500ae40 10694 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765
DL
10695 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
10696 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
718e3744 10697}
10698
10699DEFUN (bgp_redistribute_ipv6_metric_rmap,
10700 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 10701 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 10702 "Redistribute information from another routing protocol\n"
ab0181ee 10703 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 10704 "Metric for redistributed routes\n"
10705 "Default metric\n"
10706 "Route map reference\n"
10707 "Pointer to route-map entries\n")
10708{
cdc2d765 10709 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40
DW
10710 int idx_protocol = 1;
10711 int idx_number = 3;
10712 int idx_word = 5;
718e3744 10713 int type;
10714 u_int32_t metric;
7c8ff89e 10715 struct bgp_redist *red;
718e3744 10716
6d681bd8
QY
10717 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10718 if (type < 0)
718e3744 10719 {
10720 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10721 return CMD_WARNING;
10722 }
c500ae40 10723 VTY_GET_INTEGER ("metric", metric, argv[idx_number]->arg);
718e3744 10724
cdc2d765
DL
10725 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
10726 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
c500ae40 10727 bgp_redistribute_rmap_set (red, argv[idx_word]->arg);
cdc2d765 10728 return bgp_redistribute_set (bgp, AFI_IP6, type, 0);
718e3744 10729}
10730
10731DEFUN (no_bgp_redistribute_ipv6,
10732 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 10733 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 10734 NO_STR
10735 "Redistribute information from another routing protocol\n"
3b14d86e 10736 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
10737 "Metric for redistributed routes\n"
10738 "Default metric\n"
10739 "Route map reference\n"
10740 "Pointer to route-map entries\n")
718e3744 10741{
cdc2d765 10742 VTY_DECLVAR_CONTEXT(bgp, bgp);
c500ae40 10743 int idx_protocol = 2;
718e3744 10744 int type;
10745
6d681bd8
QY
10746 type = proto_redistnum (AFI_IP6, argv[idx_protocol]->text);
10747 if (type < 0)
718e3744 10748 {
10749 vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
10750 return CMD_WARNING;
10751 }
10752
cdc2d765 10753 return bgp_redistribute_unset (bgp, AFI_IP6, type, 0);
718e3744 10754}
6b0655a2 10755
718e3744 10756int
10757bgp_config_write_redistribute (struct vty *vty, struct bgp *bgp, afi_t afi,
10758 safi_t safi, int *write)
10759{
10760 int i;
718e3744 10761
10762 /* Unicast redistribution only. */
10763 if (safi != SAFI_UNICAST)
10764 return 0;
10765
10766 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
10767 {
10768 /* Redistribute BGP does not make sense. */
7c8ff89e 10769 if (i != ZEBRA_ROUTE_BGP)
718e3744 10770 {
7c8ff89e
DS
10771 struct list *red_list;
10772 struct listnode *node;
10773 struct bgp_redist *red;
718e3744 10774
7c8ff89e
DS
10775 red_list = bgp->redist[afi][i];
10776 if (!red_list)
10777 continue;
718e3744 10778
7c8ff89e
DS
10779 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
10780 {
10781 /* Display "address-family" when it is not yet diplayed. */
10782 bgp_config_write_family_header (vty, afi, safi, write);
10783
10784 /* "redistribute" configuration. */
0b960b4d 10785 vty_out (vty, " redistribute %s", zebra_route_string(i));
7c8ff89e
DS
10786 if (red->instance)
10787 vty_out (vty, " %d", red->instance);
10788 if (red->redist_metric_flag)
10789 vty_out (vty, " metric %u", red->redist_metric);
10790 if (red->rmap.name)
10791 vty_out (vty, " route-map %s", red->rmap.name);
10792 vty_out (vty, "%s", VTY_NEWLINE);
10793 }
718e3744 10794 }
10795 }
10796 return *write;
10797}
6b0655a2 10798
718e3744 10799/* BGP node structure. */
7fc626de 10800static struct cmd_node bgp_node =
718e3744 10801{
10802 BGP_NODE,
10803 "%s(config-router)# ",
10804 1,
10805};
10806
7fc626de 10807static struct cmd_node bgp_ipv4_unicast_node =
718e3744 10808{
10809 BGP_IPV4_NODE,
10810 "%s(config-router-af)# ",
10811 1,
10812};
10813
7fc626de 10814static struct cmd_node bgp_ipv4_multicast_node =
718e3744 10815{
10816 BGP_IPV4M_NODE,
10817 "%s(config-router-af)# ",
10818 1,
10819};
10820
f51bae9c
DS
10821static struct cmd_node bgp_ipv4_labeled_unicast_node =
10822{
10823 BGP_IPV4L_NODE,
10824 "%s(config-router-af)# ",
10825 1,
10826};
10827
7fc626de 10828static struct cmd_node bgp_ipv6_unicast_node =
718e3744 10829{
10830 BGP_IPV6_NODE,
10831 "%s(config-router-af)# ",
10832 1,
10833};
10834
7fc626de 10835static struct cmd_node bgp_ipv6_multicast_node =
25ffbdc1 10836{
10837 BGP_IPV6M_NODE,
10838 "%s(config-router-af)# ",
10839 1,
10840};
10841
f51bae9c
DS
10842static struct cmd_node bgp_ipv6_labeled_unicast_node =
10843{
10844 BGP_IPV6L_NODE,
10845 "%s(config-router-af)# ",
10846 1,
10847};
10848
7fc626de 10849static struct cmd_node bgp_vpnv4_node =
718e3744 10850{
10851 BGP_VPNV4_NODE,
10852 "%s(config-router-af)# ",
10853 1
10854};
6b0655a2 10855
8ecd3266 10856static struct cmd_node bgp_vpnv6_node =
10857{
10858 BGP_VPNV6_NODE,
10859 "%s(config-router-af-vpnv6)# ",
10860 1
10861};
10862
4e0b7b6d
PG
10863static struct cmd_node bgp_evpn_node =
10864{
10865 BGP_EVPN_NODE,
10866 "%s(config-router-evpn)# ",
10867 1
10868};
10869
1f8ae70b 10870static void community_list_vty (void);
10871
b8a815e5
DL
10872static void
10873bgp_ac_neighbor (vector comps, struct cmd_token *token)
10874{
10875 struct bgp *bgp;
10876 struct peer *peer;
d48ed3e0 10877 struct peer_group *group;
b8a815e5
DL
10878 struct listnode *lnbgp, *lnpeer;
10879
b8a815e5 10880 for (ALL_LIST_ELEMENTS_RO (bm->bgp, lnbgp, bgp))
d48ed3e0
DL
10881 {
10882 for (ALL_LIST_ELEMENTS_RO (bgp->peer, lnpeer, peer))
b8a815e5 10883 {
d48ed3e0
DL
10884 /* only provide suggestions on the appropriate input token type,
10885 * they'll otherwise show up multiple times */
10886 enum cmd_token_type match_type;
10887 char *name = peer->host;
10888
10889 if (peer->conf_if)
10890 {
10891 match_type = VARIABLE_TKN;
10892 name = peer->conf_if;
10893 }
10894 else if (strchr(peer->host, ':'))
10895 match_type = IPV6_TKN;
10896 else
10897 match_type = IPV4_TKN;
10898
10899 if (token->type != match_type)
b8a815e5 10900 continue;
d48ed3e0
DL
10901
10902 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
b8a815e5 10903 }
d48ed3e0
DL
10904
10905 if (token->type == VARIABLE_TKN)
10906 for (ALL_LIST_ELEMENTS_RO (bgp->group, lnpeer, group))
10907 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, group->name));
10908 }
b8a815e5
DL
10909}
10910
10911static const struct cmd_variable_handler bgp_var_neighbor[] = {
10912 {
10913 .varname = "neighbor",
10914 .completions = bgp_ac_neighbor
10915 }, {
10916 .varname = "neighbors",
10917 .completions = bgp_ac_neighbor
10918 }, {
10919 .completions = NULL
10920 }
10921};
10922
718e3744 10923void
94f2b392 10924bgp_vty_init (void)
718e3744 10925{
b8a815e5
DL
10926 cmd_variable_handler_register(bgp_var_neighbor);
10927
718e3744 10928 /* Install bgp top node. */
10929 install_node (&bgp_node, bgp_config_write);
10930 install_node (&bgp_ipv4_unicast_node, NULL);
10931 install_node (&bgp_ipv4_multicast_node, NULL);
f51bae9c 10932 install_node (&bgp_ipv4_labeled_unicast_node, NULL);
718e3744 10933 install_node (&bgp_ipv6_unicast_node, NULL);
25ffbdc1 10934 install_node (&bgp_ipv6_multicast_node, NULL);
f51bae9c 10935 install_node (&bgp_ipv6_labeled_unicast_node, NULL);
718e3744 10936 install_node (&bgp_vpnv4_node, NULL);
8ecd3266 10937 install_node (&bgp_vpnv6_node, NULL);
4e0b7b6d 10938 install_node (&bgp_evpn_node, NULL);
718e3744 10939
10940 /* Install default VTY commands to new nodes. */
10941 install_default (BGP_NODE);
10942 install_default (BGP_IPV4_NODE);
10943 install_default (BGP_IPV4M_NODE);
f51bae9c 10944 install_default (BGP_IPV4L_NODE);
718e3744 10945 install_default (BGP_IPV6_NODE);
25ffbdc1 10946 install_default (BGP_IPV6M_NODE);
f51bae9c 10947 install_default (BGP_IPV6L_NODE);
718e3744 10948 install_default (BGP_VPNV4_NODE);
8ecd3266 10949 install_default (BGP_VPNV6_NODE);
4e0b7b6d 10950 install_default (BGP_EVPN_NODE);
e52702f2 10951
718e3744 10952 /* "bgp multiple-instance" commands. */
10953 install_element (CONFIG_NODE, &bgp_multiple_instance_cmd);
10954 install_element (CONFIG_NODE, &no_bgp_multiple_instance_cmd);
10955
10956 /* "bgp config-type" commands. */
10957 install_element (CONFIG_NODE, &bgp_config_type_cmd);
8c3deaae 10958 install_element (CONFIG_NODE, &no_bgp_config_type_cmd);
718e3744 10959
5fe9f963 10960 /* bgp route-map delay-timer commands. */
10961 install_element (CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
10962 install_element (CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
5fe9f963 10963
718e3744 10964 /* Dummy commands (Currently not supported) */
10965 install_element (BGP_NODE, &no_synchronization_cmd);
10966 install_element (BGP_NODE, &no_auto_summary_cmd);
10967
10968 /* "router bgp" commands. */
10969 install_element (CONFIG_NODE, &router_bgp_cmd);
718e3744 10970
10971 /* "no router bgp" commands. */
10972 install_element (CONFIG_NODE, &no_router_bgp_cmd);
718e3744 10973
10974 /* "bgp router-id" commands. */
10975 install_element (BGP_NODE, &bgp_router_id_cmd);
10976 install_element (BGP_NODE, &no_bgp_router_id_cmd);
718e3744 10977
10978 /* "bgp cluster-id" commands. */
10979 install_element (BGP_NODE, &bgp_cluster_id_cmd);
718e3744 10980 install_element (BGP_NODE, &no_bgp_cluster_id_cmd);
718e3744 10981
10982 /* "bgp confederation" commands. */
10983 install_element (BGP_NODE, &bgp_confederation_identifier_cmd);
10984 install_element (BGP_NODE, &no_bgp_confederation_identifier_cmd);
718e3744 10985
10986 /* "bgp confederation peers" commands. */
10987 install_element (BGP_NODE, &bgp_confederation_peers_cmd);
10988 install_element (BGP_NODE, &no_bgp_confederation_peers_cmd);
10989
abc920f8
DS
10990 /* bgp max-med command */
10991 install_element (BGP_NODE, &bgp_maxmed_admin_cmd);
10992 install_element (BGP_NODE, &no_bgp_maxmed_admin_cmd);
10993 install_element (BGP_NODE, &bgp_maxmed_admin_medv_cmd);
abc920f8
DS
10994 install_element (BGP_NODE, &bgp_maxmed_onstartup_cmd);
10995 install_element (BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
abc920f8 10996 install_element (BGP_NODE, &bgp_maxmed_onstartup_medv_cmd);
abc920f8 10997
907f92c8
DS
10998 /* bgp disable-ebgp-connected-nh-check */
10999 install_element (BGP_NODE, &bgp_disable_connected_route_check_cmd);
11000 install_element (BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11001
f188f2c4
DS
11002 /* bgp update-delay command */
11003 install_element (BGP_NODE, &bgp_update_delay_cmd);
11004 install_element (BGP_NODE, &no_bgp_update_delay_cmd);
11005 install_element (BGP_NODE, &bgp_update_delay_establish_wait_cmd);
f188f2c4 11006
cb1faec9
DS
11007 install_element (BGP_NODE, &bgp_wpkt_quanta_cmd);
11008 install_element (BGP_NODE, &no_bgp_wpkt_quanta_cmd);
11009
3f9c7369
DS
11010 install_element (BGP_NODE, &bgp_coalesce_time_cmd);
11011 install_element (BGP_NODE, &no_bgp_coalesce_time_cmd);
11012
165b5fff 11013 /* "maximum-paths" commands. */
596c17ba
DW
11014 install_element (BGP_NODE, &bgp_maxpaths_hidden_cmd);
11015 install_element (BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
165b5fff
JB
11016 install_element (BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11017 install_element (BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
431aa9f9
DS
11018 install_element (BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11019 install_element (BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
596c17ba
DW
11020 install_element (BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11021 install_element (BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11022 install_element (BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
165b5fff 11023 install_element (BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
f51bae9c 11024 install_element (BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
165b5fff 11025 install_element (BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
431aa9f9 11026 install_element (BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
f51bae9c 11027 install_element (BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
431aa9f9 11028 install_element (BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
165b5fff 11029
f51bae9c
DS
11030 install_element (BGP_IPV4L_NODE, &bgp_maxpaths_cmd);
11031 install_element (BGP_IPV4L_NODE, &no_bgp_maxpaths_cmd);
11032 install_element (BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11033 install_element (BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11034
11035 install_element (BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cmd);
11036 install_element (BGP_IPV4L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11037 install_element (BGP_IPV4L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11038 install_element (BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11039 install_element (BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11040 install_element (BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11041
718e3744 11042 /* "timers bgp" commands. */
11043 install_element (BGP_NODE, &bgp_timers_cmd);
11044 install_element (BGP_NODE, &no_bgp_timers_cmd);
718e3744 11045
5fe9f963 11046 /* route-map delay-timer commands - per instance for backwards compat. */
518f0eb1
DS
11047 install_element (BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11048 install_element (BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11049
718e3744 11050 /* "bgp client-to-client reflection" commands */
11051 install_element (BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11052 install_element (BGP_NODE, &bgp_client_to_client_reflection_cmd);
11053
11054 /* "bgp always-compare-med" commands */
11055 install_element (BGP_NODE, &bgp_always_compare_med_cmd);
11056 install_element (BGP_NODE, &no_bgp_always_compare_med_cmd);
e52702f2 11057
718e3744 11058 /* "bgp deterministic-med" commands */
11059 install_element (BGP_NODE, &bgp_deterministic_med_cmd);
11060 install_element (BGP_NODE, &no_bgp_deterministic_med_cmd);
538621f2 11061
538621f2 11062 /* "bgp graceful-restart" commands */
11063 install_element (BGP_NODE, &bgp_graceful_restart_cmd);
11064 install_element (BGP_NODE, &no_bgp_graceful_restart_cmd);
93406d87 11065 install_element (BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11066 install_element (BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
eb6f1b41
PG
11067 install_element (BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11068 install_element (BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
e52702f2 11069
43fc21b3
JC
11070 install_element (BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11071 install_element (BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11072
718e3744 11073 /* "bgp fast-external-failover" commands */
11074 install_element (BGP_NODE, &bgp_fast_external_failover_cmd);
11075 install_element (BGP_NODE, &no_bgp_fast_external_failover_cmd);
11076
11077 /* "bgp enforce-first-as" commands */
11078 install_element (BGP_NODE, &bgp_enforce_first_as_cmd);
11079 install_element (BGP_NODE, &no_bgp_enforce_first_as_cmd);
11080
11081 /* "bgp bestpath compare-routerid" commands */
11082 install_element (BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11083 install_element (BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11084
11085 /* "bgp bestpath as-path ignore" commands */
11086 install_element (BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11087 install_element (BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11088
6811845b 11089 /* "bgp bestpath as-path confed" commands */
11090 install_element (BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11091 install_element (BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11092
2fdd455c
PM
11093 /* "bgp bestpath as-path multipath-relax" commands */
11094 install_element (BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11095 install_element (BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11096
848973c7 11097 /* "bgp log-neighbor-changes" commands */
11098 install_element (BGP_NODE, &bgp_log_neighbor_changes_cmd);
11099 install_element (BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11100
718e3744 11101 /* "bgp bestpath med" commands */
11102 install_element (BGP_NODE, &bgp_bestpath_med_cmd);
718e3744 11103 install_element (BGP_NODE, &no_bgp_bestpath_med_cmd);
718e3744 11104
11105 /* "no bgp default ipv4-unicast" commands. */
11106 install_element (BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11107 install_element (BGP_NODE, &bgp_default_ipv4_unicast_cmd);
e52702f2 11108
718e3744 11109 /* "bgp network import-check" commands. */
11110 install_element (BGP_NODE, &bgp_network_import_check_cmd);
8233ef81 11111 install_element (BGP_NODE, &bgp_network_import_check_exact_cmd);
718e3744 11112 install_element (BGP_NODE, &no_bgp_network_import_check_cmd);
11113
11114 /* "bgp default local-preference" commands. */
11115 install_element (BGP_NODE, &bgp_default_local_preference_cmd);
11116 install_element (BGP_NODE, &no_bgp_default_local_preference_cmd);
718e3744 11117
04b6bdc0
DW
11118 /* bgp default show-hostname */
11119 install_element (BGP_NODE, &bgp_default_show_hostname_cmd);
11120 install_element (BGP_NODE, &no_bgp_default_show_hostname_cmd);
11121
3f9c7369
DS
11122 /* "bgp default subgroup-pkt-queue-max" commands. */
11123 install_element (BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11124 install_element (BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11125
8bd9d948
DS
11126 /* bgp ibgp-allow-policy-mods command */
11127 install_element (BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11128 install_element (BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11129
f14e6fdb
DS
11130 /* "bgp listen limit" commands. */
11131 install_element (BGP_NODE, &bgp_listen_limit_cmd);
11132 install_element (BGP_NODE, &no_bgp_listen_limit_cmd);
11133
11134 /* "bgp listen range" commands. */
11135 install_element (BGP_NODE, &bgp_listen_range_cmd);
11136 install_element (BGP_NODE, &no_bgp_listen_range_cmd);
11137
718e3744 11138 /* "neighbor remote-as" commands. */
11139 install_element (BGP_NODE, &neighbor_remote_as_cmd);
a80beece 11140 install_element (BGP_NODE, &neighbor_interface_config_cmd);
4c48cf63 11141 install_element (BGP_NODE, &neighbor_interface_config_v6only_cmd);
b3a39dc5
DD
11142 install_element (BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11143 install_element (BGP_NODE, &neighbor_interface_v6only_config_remote_as_cmd);
718e3744 11144 install_element (BGP_NODE, &no_neighbor_cmd);
a80beece 11145 install_element (BGP_NODE, &no_neighbor_interface_config_cmd);
718e3744 11146
11147 /* "neighbor peer-group" commands. */
11148 install_element (BGP_NODE, &neighbor_peer_group_cmd);
11149 install_element (BGP_NODE, &no_neighbor_peer_group_cmd);
a80beece 11150 install_element (BGP_NODE, &no_neighbor_interface_peer_group_remote_as_cmd);
718e3744 11151
11152 /* "neighbor local-as" commands. */
11153 install_element (BGP_NODE, &neighbor_local_as_cmd);
11154 install_element (BGP_NODE, &neighbor_local_as_no_prepend_cmd);
9d3f9705 11155 install_element (BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
718e3744 11156 install_element (BGP_NODE, &no_neighbor_local_as_cmd);
718e3744 11157
3f9c7369
DS
11158 /* "neighbor solo" commands. */
11159 install_element (BGP_NODE, &neighbor_solo_cmd);
11160 install_element (BGP_NODE, &no_neighbor_solo_cmd);
11161
0df7c91f
PJ
11162 /* "neighbor password" commands. */
11163 install_element (BGP_NODE, &neighbor_password_cmd);
11164 install_element (BGP_NODE, &no_neighbor_password_cmd);
11165
718e3744 11166 /* "neighbor activate" commands. */
596c17ba 11167 install_element (BGP_NODE, &neighbor_activate_hidden_cmd);
718e3744 11168 install_element (BGP_IPV4_NODE, &neighbor_activate_cmd);
11169 install_element (BGP_IPV4M_NODE, &neighbor_activate_cmd);
f51bae9c 11170 install_element (BGP_IPV4L_NODE, &neighbor_activate_cmd);
718e3744 11171 install_element (BGP_IPV6_NODE, &neighbor_activate_cmd);
25ffbdc1 11172 install_element (BGP_IPV6M_NODE, &neighbor_activate_cmd);
f51bae9c 11173 install_element (BGP_IPV6L_NODE, &neighbor_activate_cmd);
718e3744 11174 install_element (BGP_VPNV4_NODE, &neighbor_activate_cmd);
8ecd3266 11175 install_element (BGP_VPNV6_NODE, &neighbor_activate_cmd);
4e0b7b6d 11176 install_element (BGP_EVPN_NODE, &neighbor_activate_cmd);
718e3744 11177
11178 /* "no neighbor activate" commands. */
596c17ba 11179 install_element (BGP_NODE, &no_neighbor_activate_hidden_cmd);
718e3744 11180 install_element (BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11181 install_element (BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
f51bae9c 11182 install_element (BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
718e3744 11183 install_element (BGP_IPV6_NODE, &no_neighbor_activate_cmd);
25ffbdc1 11184 install_element (BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
f51bae9c 11185 install_element (BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
718e3744 11186 install_element (BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
8ecd3266 11187 install_element (BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
4e0b7b6d 11188 install_element (BGP_EVPN_NODE, &no_neighbor_activate_cmd);
718e3744 11189
596c17ba 11190 /* "neighbor peer-group" set commands. */
718e3744 11191 install_element (BGP_NODE, &neighbor_set_peer_group_cmd);
596c17ba
DW
11192 install_element (BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11193 install_element (BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11194 install_element (BGP_IPV4L_NODE, &neighbor_set_peer_group_hidden_cmd);
11195 install_element (BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11196 install_element (BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11197 install_element (BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11198 install_element (BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11199 install_element (BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
c8560b44 11200
718e3744 11201 /* "no neighbor peer-group unset" commands. */
11202 install_element (BGP_NODE, &no_neighbor_set_peer_group_cmd);
596c17ba
DW
11203 install_element (BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11204 install_element (BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11205 install_element (BGP_IPV4L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11206 install_element (BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11207 install_element (BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11208 install_element (BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11209 install_element (BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11210 install_element (BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
e52702f2 11211
718e3744 11212 /* "neighbor softreconfiguration inbound" commands.*/
596c17ba
DW
11213 install_element (BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11214 install_element (BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
718e3744 11215 install_element (BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11216 install_element (BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
f51bae9c
DS
11217 install_element (BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11218 install_element (BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
718e3744 11219 install_element (BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11220 install_element (BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11221 install_element (BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11222 install_element (BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
25ffbdc1 11223 install_element (BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11224 install_element (BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
f51bae9c
DS
11225 install_element (BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11226 install_element (BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
a58545bb 11227 install_element (BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11228 install_element (BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
8ecd3266 11229 install_element (BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11230 install_element (BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
718e3744 11231
11232 /* "neighbor attribute-unchanged" commands. */
596c17ba
DW
11233 install_element (BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11234 install_element (BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
718e3744 11235 install_element (BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
718e3744 11236 install_element (BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
718e3744 11237 install_element (BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
718e3744 11238 install_element (BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
f51bae9c
DS
11239 install_element (BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11240 install_element (BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
718e3744 11241 install_element (BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
718e3744 11242 install_element (BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
25ffbdc1 11243 install_element (BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
25ffbdc1 11244 install_element (BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
f51bae9c
DS
11245 install_element (BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11246 install_element (BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
718e3744 11247 install_element (BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
718e3744 11248 install_element (BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
8ecd3266 11249 install_element (BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
8ecd3266 11250 install_element (BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
8ecd3266 11251
4e0b7b6d
PG
11252 install_element (BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11253 install_element (BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11254
fee0f4c6 11255 /* "nexthop-local unchanged" commands */
11256 install_element (BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11257 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_local_unchanged_cmd);
11258
718e3744 11259 /* "neighbor next-hop-self" commands. */
596c17ba
DW
11260 install_element (BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11261 install_element (BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
718e3744 11262 install_element (BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11263 install_element (BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11264 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11265 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
f51bae9c
DS
11266 install_element (BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11267 install_element (BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
718e3744 11268 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11269 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
25ffbdc1 11270 install_element (BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11271 install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
f51bae9c
DS
11272 install_element (BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11273 install_element (BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
718e3744 11274 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11275 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
8ecd3266 11276 install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11277 install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
718e3744 11278
a538debe 11279 /* "neighbor next-hop-self force" commands. */
596c17ba
DW
11280 install_element (BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11281 install_element (BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
a538debe
DS
11282 install_element (BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11283 install_element (BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11284 install_element (BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11285 install_element (BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
f51bae9c
DS
11286 install_element (BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11287 install_element (BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
a538debe
DS
11288 install_element (BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11289 install_element (BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11290 install_element (BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11291 install_element (BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
f51bae9c
DS
11292 install_element (BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11293 install_element (BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
a538debe
DS
11294 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11295 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
8ecd3266 11296 install_element (BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11297 install_element (BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
a538debe 11298
c7122e14 11299 /* "neighbor as-override" commands. */
596c17ba
DW
11300 install_element (BGP_NODE, &neighbor_as_override_hidden_cmd);
11301 install_element (BGP_NODE, &no_neighbor_as_override_hidden_cmd);
c7122e14
DS
11302 install_element (BGP_IPV4_NODE, &neighbor_as_override_cmd);
11303 install_element (BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11304 install_element (BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11305 install_element (BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
f51bae9c
DS
11306 install_element (BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11307 install_element (BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
c7122e14
DS
11308 install_element (BGP_IPV6_NODE, &neighbor_as_override_cmd);
11309 install_element (BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11310 install_element (BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11311 install_element (BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
f51bae9c
DS
11312 install_element (BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11313 install_element (BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
c7122e14
DS
11314 install_element (BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11315 install_element (BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
8ecd3266 11316 install_element (BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11317 install_element (BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
c7122e14 11318
718e3744 11319 /* "neighbor remove-private-AS" commands. */
596c17ba
DW
11320 install_element (BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11321 install_element (BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11322 install_element (BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11323 install_element (BGP_NODE, &no_neighbor_remove_private_as_all_hidden_cmd);
11324 install_element (BGP_NODE, &neighbor_remove_private_as_replace_as_hidden_cmd);
11325 install_element (BGP_NODE, &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11326 install_element (BGP_NODE, &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11327 install_element (BGP_NODE, &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
718e3744 11328 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11329 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
11330 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11331 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11332 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_replace_as_cmd);
11333 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11334 install_element (BGP_IPV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11335 install_element (BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
718e3744 11336 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11337 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
11338 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11339 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11340 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_replace_as_cmd);
11341 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11342 install_element (BGP_IPV4M_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11343 install_element (BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
f51bae9c
DS
11344 install_element (BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11345 install_element (BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11346 install_element (BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11347 install_element (BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11348 install_element (BGP_IPV4L_NODE, &neighbor_remove_private_as_replace_as_cmd);
11349 install_element (BGP_IPV4L_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11350 install_element (BGP_IPV4L_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11351 install_element (BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
718e3744 11352 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11353 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
11354 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11355 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11356 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_replace_as_cmd);
11357 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11358 install_element (BGP_IPV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11359 install_element (BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
25ffbdc1 11360 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11361 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
11362 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11363 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11364 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_replace_as_cmd);
11365 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11366 install_element (BGP_IPV6M_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11367 install_element (BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
f51bae9c
DS
11368 install_element (BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11369 install_element (BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11370 install_element (BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11371 install_element (BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11372 install_element (BGP_IPV6L_NODE, &neighbor_remove_private_as_replace_as_cmd);
11373 install_element (BGP_IPV6L_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11374 install_element (BGP_IPV6L_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11375 install_element (BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
718e3744 11376 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11377 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
5000f21c
DS
11378 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11379 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11380 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_replace_as_cmd);
11381 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11382 install_element (BGP_VPNV4_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11383 install_element (BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
8ecd3266 11384 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11385 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11386 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11387 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11388 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_replace_as_cmd);
11389 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_replace_as_cmd);
11390 install_element (BGP_VPNV6_NODE, &neighbor_remove_private_as_all_replace_as_cmd);
11391 install_element (BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_replace_as_cmd);
718e3744 11392
11393 /* "neighbor send-community" commands.*/
596c17ba
DW
11394 install_element (BGP_NODE, &neighbor_send_community_hidden_cmd);
11395 install_element (BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11396 install_element (BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11397 install_element (BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
718e3744 11398 install_element (BGP_IPV4_NODE, &neighbor_send_community_cmd);
11399 install_element (BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11400 install_element (BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11401 install_element (BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11402 install_element (BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11403 install_element (BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11404 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11405 install_element (BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
f51bae9c
DS
11406 install_element (BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11407 install_element (BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11408 install_element (BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11409 install_element (BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
718e3744 11410 install_element (BGP_IPV6_NODE, &neighbor_send_community_cmd);
11411 install_element (BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11412 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11413 install_element (BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
25ffbdc1 11414 install_element (BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11415 install_element (BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11416 install_element (BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11417 install_element (BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
f51bae9c
DS
11418 install_element (BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11419 install_element (BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11420 install_element (BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11421 install_element (BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
718e3744 11422 install_element (BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11423 install_element (BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11424 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11425 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
8ecd3266 11426 install_element (BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11427 install_element (BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11428 install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11429 install_element (BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
718e3744 11430
11431 /* "neighbor route-reflector" commands.*/
596c17ba
DW
11432 install_element (BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11433 install_element (BGP_NODE, &no_neighbor_route_reflector_client_hidden_cmd);
718e3744 11434 install_element (BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11435 install_element (BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11436 install_element (BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11437 install_element (BGP_IPV4M_NODE, &no_neighbor_route_reflector_client_cmd);
f51bae9c
DS
11438 install_element (BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11439 install_element (BGP_IPV4L_NODE, &no_neighbor_route_reflector_client_cmd);
718e3744 11440 install_element (BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11441 install_element (BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
25ffbdc1 11442 install_element (BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11443 install_element (BGP_IPV6M_NODE, &no_neighbor_route_reflector_client_cmd);
f51bae9c
DS
11444 install_element (BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11445 install_element (BGP_IPV6L_NODE, &no_neighbor_route_reflector_client_cmd);
718e3744 11446 install_element (BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11447 install_element (BGP_VPNV4_NODE, &no_neighbor_route_reflector_client_cmd);
8ecd3266 11448 install_element (BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11449 install_element (BGP_VPNV6_NODE, &no_neighbor_route_reflector_client_cmd);
718e3744 11450
11451 /* "neighbor route-server" commands.*/
596c17ba
DW
11452 install_element (BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11453 install_element (BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
718e3744 11454 install_element (BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11455 install_element (BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11456 install_element (BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11457 install_element (BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
f51bae9c
DS
11458 install_element (BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
11459 install_element (BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
718e3744 11460 install_element (BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
11461 install_element (BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
25ffbdc1 11462 install_element (BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
11463 install_element (BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
f51bae9c
DS
11464 install_element (BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
11465 install_element (BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
718e3744 11466 install_element (BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
11467 install_element (BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
8ecd3266 11468 install_element (BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
11469 install_element (BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
718e3744 11470
adbac85e 11471 /* "neighbor addpath-tx-all-paths" commands.*/
596c17ba
DW
11472 install_element (BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
11473 install_element (BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
adbac85e
DW
11474 install_element (BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11475 install_element (BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11476 install_element (BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11477 install_element (BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
f51bae9c
DS
11478 install_element (BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11479 install_element (BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
adbac85e
DW
11480 install_element (BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11481 install_element (BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11482 install_element (BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11483 install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
f51bae9c
DS
11484 install_element (BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11485 install_element (BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
adbac85e
DW
11486 install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11487 install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
8ecd3266 11488 install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11489 install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
adbac85e 11490
06370dac 11491 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
596c17ba
DW
11492 install_element (BGP_NODE, &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11493 install_element (BGP_NODE, &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
06370dac
DW
11494 install_element (BGP_IPV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11495 install_element (BGP_IPV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11496 install_element (BGP_IPV4M_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11497 install_element (BGP_IPV4M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
f51bae9c
DS
11498 install_element (BGP_IPV4L_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11499 install_element (BGP_IPV4L_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
06370dac
DW
11500 install_element (BGP_IPV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11501 install_element (BGP_IPV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11502 install_element (BGP_IPV6M_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11503 install_element (BGP_IPV6M_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
f51bae9c
DS
11504 install_element (BGP_IPV6L_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11505 install_element (BGP_IPV6L_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
06370dac
DW
11506 install_element (BGP_VPNV4_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11507 install_element (BGP_VPNV4_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
8ecd3266 11508 install_element (BGP_VPNV6_NODE, &neighbor_addpath_tx_bestpath_per_as_cmd);
11509 install_element (BGP_VPNV6_NODE, &no_neighbor_addpath_tx_bestpath_per_as_cmd);
06370dac 11510
718e3744 11511 /* "neighbor passive" commands. */
11512 install_element (BGP_NODE, &neighbor_passive_cmd);
11513 install_element (BGP_NODE, &no_neighbor_passive_cmd);
11514
d5a5c8f0 11515
718e3744 11516 /* "neighbor shutdown" commands. */
11517 install_element (BGP_NODE, &neighbor_shutdown_cmd);
11518 install_element (BGP_NODE, &no_neighbor_shutdown_cmd);
73d70fa6
DL
11519 install_element (BGP_NODE, &neighbor_shutdown_msg_cmd);
11520 install_element (BGP_NODE, &no_neighbor_shutdown_msg_cmd);
718e3744 11521
8a92a8a0
DS
11522 /* "neighbor capability extended-nexthop" commands.*/
11523 install_element (BGP_NODE, &neighbor_capability_enhe_cmd);
11524 install_element (BGP_NODE, &no_neighbor_capability_enhe_cmd);
11525
718e3744 11526 /* "neighbor capability orf prefix-list" commands.*/
596c17ba
DW
11527 install_element (BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
11528 install_element (BGP_NODE, &no_neighbor_capability_orf_prefix_hidden_cmd);
718e3744 11529 install_element (BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
11530 install_element (BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
11531 install_element (BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
11532 install_element (BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
f51bae9c
DS
11533 install_element (BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
11534 install_element (BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
718e3744 11535 install_element (BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
11536 install_element (BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
25ffbdc1 11537 install_element (BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
11538 install_element (BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
f51bae9c
DS
11539 install_element (BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
11540 install_element (BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
718e3744 11541
11542 /* "neighbor capability dynamic" commands.*/
11543 install_element (BGP_NODE, &neighbor_capability_dynamic_cmd);
11544 install_element (BGP_NODE, &no_neighbor_capability_dynamic_cmd);
11545
11546 /* "neighbor dont-capability-negotiate" commands. */
11547 install_element (BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
11548 install_element (BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
11549
11550 /* "neighbor ebgp-multihop" commands. */
11551 install_element (BGP_NODE, &neighbor_ebgp_multihop_cmd);
11552 install_element (BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
11553 install_element (BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
718e3744 11554
6ffd2079 11555 /* "neighbor disable-connected-check" commands. */
11556 install_element (BGP_NODE, &neighbor_disable_connected_check_cmd);
11557 install_element (BGP_NODE, &no_neighbor_disable_connected_check_cmd);
718e3744 11558
11559 /* "neighbor description" commands. */
11560 install_element (BGP_NODE, &neighbor_description_cmd);
11561 install_element (BGP_NODE, &no_neighbor_description_cmd);
718e3744 11562
11563 /* "neighbor update-source" commands. "*/
11564 install_element (BGP_NODE, &neighbor_update_source_cmd);
11565 install_element (BGP_NODE, &no_neighbor_update_source_cmd);
11566
11567 /* "neighbor default-originate" commands. */
596c17ba
DW
11568 install_element (BGP_NODE, &neighbor_default_originate_hidden_cmd);
11569 install_element (BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
11570 install_element (BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
718e3744 11571 install_element (BGP_IPV4_NODE, &neighbor_default_originate_cmd);
11572 install_element (BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
11573 install_element (BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
718e3744 11574 install_element (BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
11575 install_element (BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
11576 install_element (BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
f51bae9c
DS
11577 install_element (BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
11578 install_element (BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
11579 install_element (BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
718e3744 11580 install_element (BGP_IPV6_NODE, &neighbor_default_originate_cmd);
11581 install_element (BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
11582 install_element (BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
25ffbdc1 11583 install_element (BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
11584 install_element (BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
11585 install_element (BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
f51bae9c
DS
11586 install_element (BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
11587 install_element (BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
11588 install_element (BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
718e3744 11589
11590 /* "neighbor port" commands. */
11591 install_element (BGP_NODE, &neighbor_port_cmd);
11592 install_element (BGP_NODE, &no_neighbor_port_cmd);
718e3744 11593
11594 /* "neighbor weight" commands. */
596c17ba
DW
11595 install_element (BGP_NODE, &neighbor_weight_hidden_cmd);
11596 install_element (BGP_NODE, &no_neighbor_weight_hidden_cmd);
718e3744 11597
d93f7ffc
DW
11598 install_element (BGP_IPV4_NODE, &neighbor_weight_cmd);
11599 install_element (BGP_IPV4_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
11600 install_element (BGP_IPV4M_NODE, &neighbor_weight_cmd);
11601 install_element (BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
f51bae9c
DS
11602 install_element (BGP_IPV4L_NODE, &neighbor_weight_cmd);
11603 install_element (BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
11604 install_element (BGP_IPV6_NODE, &neighbor_weight_cmd);
11605 install_element (BGP_IPV6_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
11606 install_element (BGP_IPV6M_NODE, &neighbor_weight_cmd);
11607 install_element (BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
f51bae9c
DS
11608 install_element (BGP_IPV6L_NODE, &neighbor_weight_cmd);
11609 install_element (BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
11610 install_element (BGP_VPNV4_NODE, &neighbor_weight_cmd);
11611 install_element (BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
d93f7ffc
DW
11612 install_element (BGP_VPNV6_NODE, &neighbor_weight_cmd);
11613 install_element (BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
718e3744 11614
11615 /* "neighbor override-capability" commands. */
11616 install_element (BGP_NODE, &neighbor_override_capability_cmd);
11617 install_element (BGP_NODE, &no_neighbor_override_capability_cmd);
11618
11619 /* "neighbor strict-capability-match" commands. */
11620 install_element (BGP_NODE, &neighbor_strict_capability_cmd);
11621 install_element (BGP_NODE, &no_neighbor_strict_capability_cmd);
11622
11623 /* "neighbor timers" commands. */
11624 install_element (BGP_NODE, &neighbor_timers_cmd);
11625 install_element (BGP_NODE, &no_neighbor_timers_cmd);
11626
11627 /* "neighbor timers connect" commands. */
11628 install_element (BGP_NODE, &neighbor_timers_connect_cmd);
11629 install_element (BGP_NODE, &no_neighbor_timers_connect_cmd);
718e3744 11630
11631 /* "neighbor advertisement-interval" commands. */
11632 install_element (BGP_NODE, &neighbor_advertise_interval_cmd);
11633 install_element (BGP_NODE, &no_neighbor_advertise_interval_cmd);
718e3744 11634
718e3744 11635 /* "neighbor interface" commands. */
11636 install_element (BGP_NODE, &neighbor_interface_cmd);
11637 install_element (BGP_NODE, &no_neighbor_interface_cmd);
11638
11639 /* "neighbor distribute" commands. */
596c17ba
DW
11640 install_element (BGP_NODE, &neighbor_distribute_list_hidden_cmd);
11641 install_element (BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
718e3744 11642 install_element (BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
11643 install_element (BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
11644 install_element (BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
11645 install_element (BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
f51bae9c
DS
11646 install_element (BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
11647 install_element (BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
718e3744 11648 install_element (BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
11649 install_element (BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
25ffbdc1 11650 install_element (BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
11651 install_element (BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
f51bae9c
DS
11652 install_element (BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
11653 install_element (BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
718e3744 11654 install_element (BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
11655 install_element (BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
8ecd3266 11656 install_element (BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
11657 install_element (BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
718e3744 11658
11659 /* "neighbor prefix-list" commands. */
596c17ba
DW
11660 install_element (BGP_NODE, &neighbor_prefix_list_hidden_cmd);
11661 install_element (BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
718e3744 11662 install_element (BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
11663 install_element (BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
11664 install_element (BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
11665 install_element (BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
f51bae9c
DS
11666 install_element (BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
11667 install_element (BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
718e3744 11668 install_element (BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
11669 install_element (BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
25ffbdc1 11670 install_element (BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
11671 install_element (BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
f51bae9c
DS
11672 install_element (BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
11673 install_element (BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
718e3744 11674 install_element (BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
11675 install_element (BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
8ecd3266 11676 install_element (BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
11677 install_element (BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
718e3744 11678
11679 /* "neighbor filter-list" commands. */
596c17ba
DW
11680 install_element (BGP_NODE, &neighbor_filter_list_hidden_cmd);
11681 install_element (BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
718e3744 11682 install_element (BGP_IPV4_NODE, &neighbor_filter_list_cmd);
11683 install_element (BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
11684 install_element (BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
11685 install_element (BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
f51bae9c
DS
11686 install_element (BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
11687 install_element (BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
718e3744 11688 install_element (BGP_IPV6_NODE, &neighbor_filter_list_cmd);
11689 install_element (BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
25ffbdc1 11690 install_element (BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
11691 install_element (BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
f51bae9c
DS
11692 install_element (BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
11693 install_element (BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
718e3744 11694 install_element (BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
11695 install_element (BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
8ecd3266 11696 install_element (BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
11697 install_element (BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
718e3744 11698
11699 /* "neighbor route-map" commands. */
596c17ba
DW
11700 install_element (BGP_NODE, &neighbor_route_map_hidden_cmd);
11701 install_element (BGP_NODE, &no_neighbor_route_map_hidden_cmd);
718e3744 11702 install_element (BGP_IPV4_NODE, &neighbor_route_map_cmd);
11703 install_element (BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
11704 install_element (BGP_IPV4M_NODE, &neighbor_route_map_cmd);
11705 install_element (BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
f51bae9c
DS
11706 install_element (BGP_IPV4L_NODE, &neighbor_route_map_cmd);
11707 install_element (BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
718e3744 11708 install_element (BGP_IPV6_NODE, &neighbor_route_map_cmd);
11709 install_element (BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
25ffbdc1 11710 install_element (BGP_IPV6M_NODE, &neighbor_route_map_cmd);
11711 install_element (BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
f51bae9c
DS
11712 install_element (BGP_IPV6L_NODE, &neighbor_route_map_cmd);
11713 install_element (BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
718e3744 11714 install_element (BGP_VPNV4_NODE, &neighbor_route_map_cmd);
11715 install_element (BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
8ecd3266 11716 install_element (BGP_VPNV6_NODE, &neighbor_route_map_cmd);
11717 install_element (BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
718e3744 11718
11719 /* "neighbor unsuppress-map" commands. */
596c17ba
DW
11720 install_element (BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
11721 install_element (BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
718e3744 11722 install_element (BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
11723 install_element (BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
11724 install_element (BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
11725 install_element (BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
f51bae9c
DS
11726 install_element (BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
11727 install_element (BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
718e3744 11728 install_element (BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
11729 install_element (BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
25ffbdc1 11730 install_element (BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
11731 install_element (BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
f51bae9c
DS
11732 install_element (BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
11733 install_element (BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
a58545bb 11734 install_element (BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
bb86c601 11735 install_element (BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
8ecd3266 11736 install_element (BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
bb86c601 11737 install_element (BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
718e3744 11738
11739 /* "neighbor maximum-prefix" commands. */
596c17ba
DW
11740 install_element (BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
11741 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_hidden_cmd);
11742 install_element (BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
11743 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
11744 install_element (BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
11745 install_element (BGP_NODE, &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
11746 install_element (BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
718e3744 11747 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 11748 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 11749 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 11750 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 11751 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
11752 install_element (BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 11753 install_element (BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 11754 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 11755 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 11756 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 11757 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 11758 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
11759 install_element (BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 11760 install_element (BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
f51bae9c
DS
11761 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
11762 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
11763 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
11764 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11765 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
11766 install_element (BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11767 install_element (BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 11768 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 11769 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 11770 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 11771 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 11772 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
11773 install_element (BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 11774 install_element (BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
25ffbdc1 11775 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
11776 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
11777 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
11778 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11779 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
11780 install_element (BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11781 install_element (BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
f51bae9c
DS
11782 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
11783 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
11784 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
11785 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11786 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
11787 install_element (BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11788 install_element (BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 11789 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
e0701b79 11790 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
718e3744 11791 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
e0701b79 11792 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
0a486e5f 11793 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
11794 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
718e3744 11795 install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
8ecd3266 11796 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
11797 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
11798 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
11799 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_warning_cmd);
11800 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
11801 install_element (BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_restart_cmd);
11802 install_element (BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
718e3744 11803
11804 /* "neighbor allowas-in" */
596c17ba
DW
11805 install_element (BGP_NODE, &neighbor_allowas_in_hidden_cmd);
11806 install_element (BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
718e3744 11807 install_element (BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
718e3744 11808 install_element (BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
11809 install_element (BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
718e3744 11810 install_element (BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
f51bae9c
DS
11811 install_element (BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
11812 install_element (BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
718e3744 11813 install_element (BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
718e3744 11814 install_element (BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
25ffbdc1 11815 install_element (BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
25ffbdc1 11816 install_element (BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
f51bae9c
DS
11817 install_element (BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
11818 install_element (BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
718e3744 11819 install_element (BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
718e3744 11820 install_element (BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
8ecd3266 11821 install_element (BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
8ecd3266 11822 install_element (BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
718e3744 11823
11824 /* address-family commands. */
718e3744 11825 install_element (BGP_NODE, &address_family_ipv4_safi_cmd);
25ffbdc1 11826 install_element (BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 11827#ifdef KEEP_OLD_VPN_COMMANDS
718e3744 11828 install_element (BGP_NODE, &address_family_vpnv4_cmd);
8b1fb8be 11829 install_element (BGP_NODE, &address_family_vpnv6_cmd);
d6902373 11830#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 11831
4e0b7b6d
PG
11832 install_element (BGP_NODE, &address_family_evpn_cmd);
11833
718e3744 11834 /* "exit-address-family" command. */
11835 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
11836 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
f51bae9c 11837 install_element (BGP_IPV4L_NODE, &exit_address_family_cmd);
718e3744 11838 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
25ffbdc1 11839 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
f51bae9c 11840 install_element (BGP_IPV6L_NODE, &exit_address_family_cmd);
718e3744 11841 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
8ecd3266 11842 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
4e0b7b6d 11843 install_element (BGP_EVPN_NODE, &exit_address_family_cmd);
718e3744 11844
11845 /* "clear ip bgp commands" */
11846 install_element (ENABLE_NODE, &clear_ip_bgp_all_cmd);
718e3744 11847
8ad7271d
DS
11848 /* clear ip bgp prefix */
11849 install_element (ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
11850 install_element (ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
01080f7c 11851 install_element (ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
8ad7271d 11852
716b2d8a 11853 /* "show [ip] bgp summary" commands. */
f186de26 11854 install_element (VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
8386ac43 11855 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
8386ac43 11856 install_element (VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
271ad8d5 11857 install_element (VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
e52702f2 11858 install_element (VIEW_NODE, &show_bgp_updgrps_adj_cmd);
e52702f2 11859 install_element (VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
271ad8d5 11860 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
e52702f2 11861 install_element (VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
8c3deaae 11862 install_element (VIEW_NODE, &show_bgp_updgrps_stats_cmd);
271ad8d5
QY
11863 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
11864 install_element (VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
11865 install_element (VIEW_NODE, &show_ip_bgp_summary_cmd);
11866 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
11867 install_element (VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
11868 install_element (VIEW_NODE, &show_ip_bgp_updgrps_cmd);
e3e29b32 11869
716b2d8a 11870 /* "show [ip] bgp neighbors" commands. */
718e3744 11871 install_element (VIEW_NODE, &show_ip_bgp_neighbors_cmd);
718e3744 11872
716b2d8a 11873 /* "show [ip] bgp peer-group" commands. */
f14e6fdb 11874 install_element (VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
f14e6fdb 11875
716b2d8a 11876 /* "show [ip] bgp paths" commands. */
718e3744 11877 install_element (VIEW_NODE, &show_ip_bgp_paths_cmd);
718e3744 11878
716b2d8a 11879 /* "show [ip] bgp community" commands. */
718e3744 11880 install_element (VIEW_NODE, &show_ip_bgp_community_info_cmd);
718e3744 11881
57d187bc
JS
11882 /* "show ip bgp large-community" commands. */
11883 install_element (VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
716b2d8a 11884 /* "show [ip] bgp attribute-info" commands. */
718e3744 11885 install_element (VIEW_NODE, &show_ip_bgp_attr_info_cmd);
718e3744 11886
11887 /* "redistribute" commands. */
596c17ba
DW
11888 install_element (BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
11889 install_element (BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
11890 install_element (BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
11891 install_element (BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
11892 install_element (BGP_NODE, &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
11893 install_element (BGP_NODE, &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
11894 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
11895 install_element (BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
11896 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
11897 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
11898 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
11899 install_element (BGP_NODE, &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
919e0666
DW
11900 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
11901 install_element (BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
11902 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
919e0666 11903 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
919e0666
DW
11904 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
11905 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
919e0666
DW
11906 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
11907 install_element (BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
11908 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
919e0666 11909 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
919e0666 11910 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
919e0666 11911 install_element (BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
718e3744 11912 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
11913 install_element (BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
11914 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
718e3744 11915 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
718e3744 11916 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
11917 install_element (BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
718e3744 11918
fa411a21
NH
11919 /* ttl_security commands */
11920 install_element (BGP_NODE, &neighbor_ttl_security_cmd);
11921 install_element (BGP_NODE, &no_neighbor_ttl_security_cmd);
11922
716b2d8a 11923 /* "show [ip] bgp memory" commands. */
4bf6a362 11924 install_element (VIEW_NODE, &show_bgp_memory_cmd);
e52702f2 11925
716b2d8a 11926 /* "show [ip] bgp views" commands. */
e0081f70 11927 install_element (VIEW_NODE, &show_bgp_views_cmd);
e52702f2 11928
716b2d8a 11929 /* "show [ip] bgp vrfs" commands. */
8386ac43 11930 install_element (VIEW_NODE, &show_bgp_vrfs_cmd);
e52702f2 11931
718e3744 11932 /* Community-list. */
11933 community_list_vty ();
11934}
6b0655a2 11935
718e3744 11936#include "memory.h"
11937#include "bgp_regex.h"
11938#include "bgp_clist.h"
11939#include "bgp_ecommunity.h"
11940
11941/* VTY functions. */
11942
11943/* Direction value to string conversion. */
94f2b392 11944static const char *
718e3744 11945community_direct_str (int direct)
11946{
11947 switch (direct)
11948 {
11949 case COMMUNITY_DENY:
11950 return "deny";
718e3744 11951 case COMMUNITY_PERMIT:
11952 return "permit";
718e3744 11953 default:
11954 return "unknown";
718e3744 11955 }
11956}
11957
11958/* Display error string. */
94f2b392 11959static void
718e3744 11960community_list_perror (struct vty *vty, int ret)
11961{
11962 switch (ret)
11963 {
11964 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
b729294c 11965 vty_out (vty, "%% Can't find community-list%s", VTY_NEWLINE);
718e3744 11966 break;
11967 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
11968 vty_out (vty, "%% Malformed community-list value%s", VTY_NEWLINE);
11969 break;
11970 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
11971 vty_out (vty, "%% Community name conflict, previously defined as standard community%s", VTY_NEWLINE);
11972 break;
11973 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
11974 vty_out (vty, "%% Community name conflict, previously defined as expanded community%s", VTY_NEWLINE);
11975 break;
11976 }
11977}
11978
5bf15956
DW
11979/* "community-list" keyword help string. */
11980#define COMMUNITY_LIST_STR "Add a community list entry\n"
11981
718e3744 11982
5bf15956 11983/* ip community-list standard */
718e3744 11984DEFUN (ip_community_list_standard,
11985 ip_community_list_standard_cmd,
e961923c 11986 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 11987 IP_STR
11988 COMMUNITY_LIST_STR
11989 "Community list number (standard)\n"
5bf15956 11990 "Add an standard community-list entry\n"
718e3744 11991 "Community list name\n"
11992 "Specify community to reject\n"
11993 "Specify community to accept\n"
11994 COMMUNITY_VAL_STR)
11995{
42f914d4
QY
11996 char *cl_name_or_number = NULL;
11997 int direct = 0;
11998 int style = COMMUNITY_LIST_STANDARD;
11999
12000 int idx = 0;
12001 argv_find (argv, argc, "(1-99)", &idx);
12002 argv_find (argv, argc, "WORD", &idx);
12003 cl_name_or_number = argv[idx]->arg;
12004 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12005 argv_find (argv, argc, "AA:NN", &idx);
12006 char *str = argv_concat (argv, argc, idx);
12007
12008 int ret = community_list_set (bgp_clist, cl_name_or_number, str, direct, style);
12009
12010 XFREE (MTYPE_TMP, str);
12011
12012 if (ret < 0)
12013 {
12014 /* Display error string. */
12015 community_list_perror (vty, ret);
12016 return CMD_WARNING;
12017 }
12018
12019 return CMD_SUCCESS;
718e3744 12020}
12021
fee6e4e4 12022DEFUN (no_ip_community_list_standard_all,
12023 no_ip_community_list_standard_all_cmd,
e961923c 12024 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12025 NO_STR
12026 IP_STR
12027 COMMUNITY_LIST_STR
12028 "Community list number (standard)\n"
5bf15956
DW
12029 "Add an standard community-list entry\n"
12030 "Community list name\n"
718e3744 12031 "Specify community to reject\n"
12032 "Specify community to accept\n"
12033 COMMUNITY_VAL_STR)
12034{
42f914d4
QY
12035 int delete_all = 0;
12036
12037 char *cl_name_or_number = NULL;
12038 int direct = 0;
12039 int style = COMMUNITY_LIST_STANDARD;
12040
12041 int idx = 0;
12042 argv_find (argv, argc, "(1-99)", &idx);
12043 argv_find (argv, argc, "WORD", &idx);
12044 cl_name_or_number = argv[idx]->arg;
12045 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12046 argv_find (argv, argc, "AA:NN", &idx);
12047 char *str = argv_concat (argv, argc, idx);
12048
12049 int ret = community_list_unset (bgp_clist, cl_name_or_number, str, direct, style, delete_all);
12050
daf9ddbb
DS
12051 XFREE (MTYPE_TMP, str);
12052
42f914d4
QY
12053 if (ret < 0)
12054 {
12055 community_list_perror (vty, ret);
12056 return CMD_WARNING;
12057 }
12058
12059 return CMD_SUCCESS;
718e3744 12060}
12061
5bf15956
DW
12062/* ip community-list expanded */
12063DEFUN (ip_community_list_expanded_all,
12064 ip_community_list_expanded_all_cmd,
42f914d4 12065 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12066 IP_STR
12067 COMMUNITY_LIST_STR
12068 "Community list number (expanded)\n"
5bf15956 12069 "Add an expanded community-list entry\n"
718e3744 12070 "Community list name\n"
12071 "Specify community to reject\n"
12072 "Specify community to accept\n"
12073 COMMUNITY_VAL_STR)
12074{
42f914d4
QY
12075 char *cl_name_or_number = NULL;
12076 int direct = 0;
12077 int style = COMMUNITY_LIST_EXPANDED;
12078
12079 int idx = 0;
12080 argv_find (argv, argc, "(100-500)", &idx);
12081 argv_find (argv, argc, "WORD", &idx);
12082 cl_name_or_number = argv[idx]->arg;
12083 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12084 argv_find (argv, argc, "AA:NN", &idx);
12085 char *str = argv_concat (argv, argc, idx);
12086
12087 int ret = community_list_set (bgp_clist, cl_name_or_number, str, direct, style);
12088
12089 XFREE (MTYPE_TMP, str);
12090
12091 if (ret < 0)
12092 {
12093 /* Display error string. */
12094 community_list_perror (vty, ret);
12095 return CMD_WARNING;
12096 }
12097
12098 return CMD_SUCCESS;
718e3744 12099}
12100
5bf15956
DW
12101DEFUN (no_ip_community_list_expanded_all,
12102 no_ip_community_list_expanded_all_cmd,
42f914d4 12103 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12104 NO_STR
12105 IP_STR
12106 COMMUNITY_LIST_STR
5bf15956
DW
12107 "Community list number (expanded)\n"
12108 "Add an expanded community-list entry\n"
718e3744 12109 "Community list name\n"
12110 "Specify community to reject\n"
12111 "Specify community to accept\n"
5bf15956 12112 COMMUNITY_VAL_STR)
718e3744 12113{
42f914d4
QY
12114 int delete_all = 0;
12115
12116 char *cl_name_or_number = NULL;
12117 int direct = 0;
12118 int style = COMMUNITY_LIST_EXPANDED;
12119
12120 int idx = 0;
12121 argv_find (argv, argc, "(100-500)", &idx);
12122 argv_find (argv, argc, "WORD", &idx);
12123 cl_name_or_number = argv[idx]->arg;
12124 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12125 argv_find (argv, argc, "AA:NN", &idx);
12126 char *str = argv_concat (argv, argc, idx);
12127
12128 int ret = community_list_unset (bgp_clist, cl_name_or_number, str, direct, style, delete_all);
12129
daf9ddbb
DS
12130 XFREE (MTYPE_TMP, str);
12131
42f914d4
QY
12132 if (ret < 0)
12133 {
12134 community_list_perror (vty, ret);
12135 return CMD_WARNING;
12136 }
12137
12138 return CMD_SUCCESS;
718e3744 12139}
12140
94f2b392 12141static void
718e3744 12142community_list_show (struct vty *vty, struct community_list *list)
12143{
12144 struct community_entry *entry;
12145
12146 for (entry = list->head; entry; entry = entry->next)
12147 {
12148 if (entry == list->head)
12149 {
12150 if (all_digit (list->name))
12151 vty_out (vty, "Community %s list %s%s",
12152 entry->style == COMMUNITY_LIST_STANDARD ?
12153 "standard" : "(expanded) access",
12154 list->name, VTY_NEWLINE);
12155 else
12156 vty_out (vty, "Named Community %s list %s%s",
12157 entry->style == COMMUNITY_LIST_STANDARD ?
12158 "standard" : "expanded",
12159 list->name, VTY_NEWLINE);
12160 }
12161 if (entry->any)
12162 vty_out (vty, " %s%s",
12163 community_direct_str (entry->direct), VTY_NEWLINE);
12164 else
12165 vty_out (vty, " %s %s%s",
12166 community_direct_str (entry->direct),
12167 entry->style == COMMUNITY_LIST_STANDARD
12168 ? community_str (entry->u.com) : entry->config,
12169 VTY_NEWLINE);
12170 }
12171}
12172
12173DEFUN (show_ip_community_list,
12174 show_ip_community_list_cmd,
12175 "show ip community-list",
12176 SHOW_STR
12177 IP_STR
12178 "List community-list\n")
12179{
12180 struct community_list *list;
12181 struct community_list_master *cm;
12182
fee6e4e4 12183 cm = community_list_master_lookup (bgp_clist, COMMUNITY_LIST_MASTER);
718e3744 12184 if (! cm)
12185 return CMD_SUCCESS;
12186
12187 for (list = cm->num.head; list; list = list->next)
12188 community_list_show (vty, list);
12189
12190 for (list = cm->str.head; list; list = list->next)
12191 community_list_show (vty, list);
12192
12193 return CMD_SUCCESS;
12194}
12195
12196DEFUN (show_ip_community_list_arg,
12197 show_ip_community_list_arg_cmd,
6147e2c6 12198 "show ip community-list <(1-500)|WORD>",
718e3744 12199 SHOW_STR
12200 IP_STR
12201 "List community-list\n"
12202 "Community-list number\n"
12203 "Community-list name\n")
12204{
c500ae40 12205 int idx_comm_list = 3;
718e3744 12206 struct community_list *list;
12207
c500ae40 12208 list = community_list_lookup (bgp_clist, argv[idx_comm_list]->arg, COMMUNITY_LIST_MASTER);
718e3744 12209 if (! list)
12210 {
b729294c 12211 vty_out (vty, "%% Can't find community-list%s", VTY_NEWLINE);
718e3744 12212 return CMD_WARNING;
12213 }
12214
12215 community_list_show (vty, list);
12216
12217 return CMD_SUCCESS;
12218}
6b0655a2 12219
57d187bc
JS
12220/*
12221 * Large Community code.
12222 */
12223static int
12224lcommunity_list_set_vty (struct vty *vty, int argc, struct cmd_token **argv,
2acb4ac2 12225 int style, int reject_all_digit_name)
57d187bc
JS
12226{
12227 int ret;
12228 int direct;
12229 char *str;
12230 int idx = 0;
12231 char *cl_name;
12232
12233 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12234
12235 /* All digit name check. */
12236 idx = 0;
12237 argv_find (argv, argc, "WORD", &idx);
12238 argv_find (argv, argc, "(1-99)", &idx);
12239 argv_find (argv, argc, "(100-500)", &idx);
12240 cl_name = argv[idx]->arg;
12241 if (reject_all_digit_name && all_digit (cl_name))
12242 {
12243 vty_out (vty, "%% Community name cannot have all digits%s", VTY_NEWLINE);
12244 return CMD_WARNING;
12245 }
12246
ce2570bc 12247 idx = 0;
57d187bc
JS
12248 argv_find (argv, argc, "AA:BB:CC", &idx);
12249 argv_find (argv, argc, "LINE", &idx);
12250 /* Concat community string argument. */
12251 if (idx)
12252 str = argv_concat (argv, argc, idx);
12253 else
12254 str = NULL;
12255
12256 ret = lcommunity_list_set (bgp_clist, cl_name, str, direct, style);
12257
12258 /* Free temporary community list string allocated by
12259 argv_concat(). */
12260 if (str)
12261 XFREE (MTYPE_TMP, str);
12262
12263 if (ret < 0)
12264 {
12265 community_list_perror (vty, ret);
12266 return CMD_WARNING;
12267 }
12268 return CMD_SUCCESS;
12269}
12270
12271static int
12272lcommunity_list_unset_vty (struct vty *vty, int argc, struct cmd_token **argv,
2acb4ac2 12273 int style)
57d187bc
JS
12274{
12275 int ret;
12276 int direct = 0;
12277 char *str = NULL;
12278 int idx = 0;
12279
12280 argv_find (argv, argc, "permit", &idx);
12281 argv_find (argv, argc, "deny", &idx);
12282
12283 if (idx)
12284 {
12285 /* Check the list direct. */
12286 if (strncmp (argv[idx]->arg, "p", 1) == 0)
2acb4ac2 12287 direct = COMMUNITY_PERMIT;
57d187bc 12288 else
2acb4ac2 12289 direct = COMMUNITY_DENY;
57d187bc
JS
12290
12291 idx = 0;
12292 argv_find (argv, argc, "LINE", &idx);
12293 argv_find (argv, argc, "AA:AA:NN", &idx);
12294 /* Concat community string argument. */
12295 str = argv_concat (argv, argc, idx);
12296 }
12297
12298 idx = 0;
12299 argv_find (argv, argc, "(1-99)", &idx);
12300 argv_find (argv, argc, "(100-500)", &idx);
12301 argv_find (argv, argc, "WORD", &idx);
12302
12303 /* Unset community list. */
12304 ret = lcommunity_list_unset (bgp_clist, argv[idx]->arg, str, direct, style);
12305
12306 /* Free temporary community list string allocated by
12307 argv_concat(). */
12308 if (str)
12309 XFREE (MTYPE_TMP, str);
12310
12311 if (ret < 0)
12312 {
12313 community_list_perror (vty, ret);
12314 return CMD_WARNING;
12315 }
12316
12317 return CMD_SUCCESS;
12318}
12319
12320/* "large-community-list" keyword help string. */
12321#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12322#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12323
12324DEFUN (ip_lcommunity_list_standard,
12325 ip_lcommunity_list_standard_cmd,
52951b63
DS
12326 "ip large-community-list (1-99) <deny|permit>",
12327 IP_STR
12328 LCOMMUNITY_LIST_STR
12329 "Large Community list number (standard)\n"
12330 "Specify large community to reject\n"
12331 "Specify large community to accept\n"
12332 LCOMMUNITY_VAL_STR)
12333{
12334 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 0);
12335}
12336
12337DEFUN (ip_lcommunity_list_standard1,
12338 ip_lcommunity_list_standard1_cmd,
12339 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
12340 IP_STR
12341 LCOMMUNITY_LIST_STR
12342 "Large Community list number (standard)\n"
12343 "Specify large community to reject\n"
12344 "Specify large community to accept\n"
12345 LCOMMUNITY_VAL_STR)
12346{
12347 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 0);
12348}
12349
12350DEFUN (ip_lcommunity_list_expanded,
12351 ip_lcommunity_list_expanded_cmd,
12352 "ip large-community-list (100-500) <deny|permit> LINE...",
12353 IP_STR
12354 LCOMMUNITY_LIST_STR
12355 "Large Community list number (expanded)\n"
12356 "Specify large community to reject\n"
12357 "Specify large community to accept\n"
12358 "An ordered list as a regular-expression\n")
12359{
12360 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED, 0);
12361}
12362
12363DEFUN (ip_lcommunity_list_name_standard,
12364 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
12365 "ip large-community-list standard WORD <deny|permit>",
12366 IP_STR
12367 LCOMMUNITY_LIST_STR
12368 "Specify standard large-community-list\n"
12369 "Large Community list name\n"
12370 "Specify large community to reject\n"
12371 "Specify large community to accept\n")
12372{
12373 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 1);
12374}
12375
12376DEFUN (ip_lcommunity_list_name_standard1,
12377 ip_lcommunity_list_name_standard1_cmd,
12378 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
12379 IP_STR
12380 LCOMMUNITY_LIST_STR
12381 "Specify standard large-community-list\n"
12382 "Large Community list name\n"
12383 "Specify large community to reject\n"
12384 "Specify large community to accept\n"
12385 LCOMMUNITY_VAL_STR)
12386{
12387 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD, 1);
12388}
12389
12390DEFUN (ip_lcommunity_list_name_expanded,
12391 ip_lcommunity_list_name_expanded_cmd,
12392 "ip large-community-list expanded WORD <deny|permit> LINE...",
12393 IP_STR
12394 LCOMMUNITY_LIST_STR
12395 "Specify expanded large-community-list\n"
12396 "Large Community list name\n"
12397 "Specify large community to reject\n"
12398 "Specify large community to accept\n"
12399 "An ordered list as a regular-expression\n")
12400{
12401 return lcommunity_list_set_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED, 1);
12402}
12403
12404DEFUN (no_ip_lcommunity_list_standard_all,
12405 no_ip_lcommunity_list_standard_all_cmd,
12406 "no ip large-community-list <(1-99)|(100-500)|WORD>",
12407 NO_STR
12408 IP_STR
12409 LCOMMUNITY_LIST_STR
12410 "Large Community list number (standard)\n"
12411 "Large Community list number (expanded)\n"
12412 "Large Community list name\n")
12413{
12414 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
12415}
12416
12417DEFUN (no_ip_lcommunity_list_name_expanded_all,
12418 no_ip_lcommunity_list_name_expanded_all_cmd,
12419 "no ip large-community-list expanded WORD",
12420 NO_STR
12421 IP_STR
12422 LCOMMUNITY_LIST_STR
12423 "Specify expanded large-community-list\n"
12424 "Large Community list name\n")
12425{
12426 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
12427}
12428
12429DEFUN (no_ip_lcommunity_list_standard,
12430 no_ip_lcommunity_list_standard_cmd,
12431 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
12432 NO_STR
12433 IP_STR
12434 LCOMMUNITY_LIST_STR
12435 "Large Community list number (standard)\n"
12436 "Specify large community to reject\n"
12437 "Specify large community to accept\n"
12438 LCOMMUNITY_VAL_STR)
12439{
12440 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
12441}
12442
12443DEFUN (no_ip_lcommunity_list_expanded,
12444 no_ip_lcommunity_list_expanded_cmd,
12445 "no ip large-community-list (100-500) <deny|permit> LINE...",
12446 NO_STR
12447 IP_STR
12448 LCOMMUNITY_LIST_STR
12449 "Large Community list number (expanded)\n"
12450 "Specify large community to reject\n"
12451 "Specify large community to accept\n"
12452 "An ordered list as a regular-expression\n")
12453{
12454 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
12455}
12456
12457DEFUN (no_ip_lcommunity_list_name_standard,
12458 no_ip_lcommunity_list_name_standard_cmd,
12459 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
12460 NO_STR
12461 IP_STR
12462 LCOMMUNITY_LIST_STR
12463 "Specify standard large-community-list\n"
12464 "Large Community list name\n"
12465 "Specify large community to reject\n"
12466 "Specify large community to accept\n"
12467 LCOMMUNITY_VAL_STR)
12468{
12469 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_STANDARD);
12470}
12471
12472DEFUN (no_ip_lcommunity_list_name_expanded,
12473 no_ip_lcommunity_list_name_expanded_cmd,
12474 "no ip large-community-list expanded WORD <deny|permit> LINE...",
12475 NO_STR
12476 IP_STR
12477 LCOMMUNITY_LIST_STR
12478 "Specify expanded large-community-list\n"
12479 "Large community list name\n"
12480 "Specify large community to reject\n"
12481 "Specify large community to accept\n"
12482 "An ordered list as a regular-expression\n")
12483{
12484 return lcommunity_list_unset_vty (vty, argc, argv, LARGE_COMMUNITY_LIST_EXPANDED);
12485}
12486
12487static void
12488lcommunity_list_show (struct vty *vty, struct community_list *list)
12489{
12490 struct community_entry *entry;
12491
12492 for (entry = list->head; entry; entry = entry->next)
12493 {
12494 if (entry == list->head)
2acb4ac2
DL
12495 {
12496 if (all_digit (list->name))
12497 vty_out (vty, "Large community %s list %s%s",
12498 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12499 "standard" : "(expanded) access",
12500 list->name, VTY_NEWLINE);
12501 else
12502 vty_out (vty, "Named large community %s list %s%s",
12503 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12504 "standard" : "expanded",
12505 list->name, VTY_NEWLINE);
12506 }
57d187bc 12507 if (entry->any)
2acb4ac2
DL
12508 vty_out (vty, " %s%s",
12509 community_direct_str (entry->direct), VTY_NEWLINE);
57d187bc 12510 else
2acb4ac2
DL
12511 vty_out (vty, " %s %s%s",
12512 community_direct_str (entry->direct),
12513 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12514 entry->u.ecom->str : entry->config,
12515 VTY_NEWLINE);
57d187bc
JS
12516 }
12517}
12518
12519DEFUN (show_ip_lcommunity_list,
12520 show_ip_lcommunity_list_cmd,
12521 "show ip large-community-list",
12522 SHOW_STR
12523 IP_STR
12524 "List large-community list\n")
12525{
12526 struct community_list *list;
12527 struct community_list_master *cm;
12528
12529 cm = community_list_master_lookup (bgp_clist, LARGE_COMMUNITY_LIST_MASTER);
12530 if (! cm)
12531 return CMD_SUCCESS;
12532
12533 for (list = cm->num.head; list; list = list->next)
12534 lcommunity_list_show (vty, list);
12535
12536 for (list = cm->str.head; list; list = list->next)
12537 lcommunity_list_show (vty, list);
12538
12539 return CMD_SUCCESS;
12540}
12541
12542DEFUN (show_ip_lcommunity_list_arg,
12543 show_ip_lcommunity_list_arg_cmd,
12544 "show ip large-community-list <(1-500)|WORD>",
12545 SHOW_STR
12546 IP_STR
12547 "List large-community list\n"
12548 "large-community-list number\n"
12549 "large-community-list name\n")
12550{
12551 struct community_list *list;
12552
12553 list = community_list_lookup (bgp_clist, argv[3]->arg, LARGE_COMMUNITY_LIST_MASTER);
12554 if (! list)
12555 {
12556 vty_out (vty, "%% Can't find extcommunity-list%s", VTY_NEWLINE);
12557 return CMD_WARNING;
12558 }
12559
12560 lcommunity_list_show (vty, list);
12561
12562 return CMD_SUCCESS;
12563}
12564
718e3744 12565/* "extcommunity-list" keyword help string. */
12566#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
12567#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
12568
12569DEFUN (ip_extcommunity_list_standard,
12570 ip_extcommunity_list_standard_cmd,
e961923c 12571 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12572 IP_STR
12573 EXTCOMMUNITY_LIST_STR
12574 "Extended Community list number (standard)\n"
718e3744 12575 "Specify standard extcommunity-list\n"
5bf15956 12576 "Community list name\n"
718e3744 12577 "Specify community to reject\n"
12578 "Specify community to accept\n"
12579 EXTCOMMUNITY_VAL_STR)
12580{
42f914d4
QY
12581 int style = EXTCOMMUNITY_LIST_STANDARD;
12582 int direct = 0;
12583 char *cl_number_or_name = NULL;
12584
12585 int idx = 0;
12586 argv_find (argv, argc, "(1-99)", &idx);
12587 argv_find (argv, argc, "WORD", &idx);
12588 cl_number_or_name = argv[idx]->arg;
12589 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12590 argv_find (argv, argc, "AA:NN", &idx);
12591 char *str = argv_concat (argv, argc, idx);
12592
12593 int ret = extcommunity_list_set (bgp_clist, cl_number_or_name, str, direct, style);
12594
12595 XFREE (MTYPE_TMP, str);
12596
12597 if (ret < 0)
12598 {
12599 community_list_perror (vty, ret);
12600 return CMD_WARNING;
12601 }
12602
12603 return CMD_SUCCESS;
718e3744 12604}
12605
718e3744 12606DEFUN (ip_extcommunity_list_name_expanded,
12607 ip_extcommunity_list_name_expanded_cmd,
e961923c 12608 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 12609 IP_STR
12610 EXTCOMMUNITY_LIST_STR
5bf15956 12611 "Extended Community list number (expanded)\n"
718e3744 12612 "Specify expanded extcommunity-list\n"
12613 "Extended Community list name\n"
12614 "Specify community to reject\n"
12615 "Specify community to accept\n"
12616 "An ordered list as a regular-expression\n")
12617{
42f914d4
QY
12618 int style = EXTCOMMUNITY_LIST_EXPANDED;
12619 int direct = 0;
12620 char *cl_number_or_name = NULL;
12621
12622 int idx = 0;
12623 argv_find (argv, argc, "(100-500)", &idx);
12624 argv_find (argv, argc, "WORD", &idx);
12625 cl_number_or_name = argv[idx]->arg;
12626 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12627 argv_find (argv, argc, "LINE", &idx);
12628 char *str = argv_concat (argv, argc, idx);
12629
12630 int ret = extcommunity_list_set (bgp_clist, cl_number_or_name, str, direct, style);
12631
12632 XFREE (MTYPE_TMP, str);
12633
12634 if (ret < 0)
12635 {
12636 community_list_perror (vty, ret);
12637 return CMD_WARNING;
12638 }
12639
12640 return CMD_SUCCESS;
718e3744 12641}
12642
fee6e4e4 12643DEFUN (no_ip_extcommunity_list_standard_all,
12644 no_ip_extcommunity_list_standard_all_cmd,
e961923c 12645 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
12646 NO_STR
12647 IP_STR
12648 EXTCOMMUNITY_LIST_STR
12649 "Extended Community list number (standard)\n"
718e3744 12650 "Specify standard extcommunity-list\n"
5bf15956 12651 "Community list name\n"
718e3744 12652 "Specify community to reject\n"
12653 "Specify community to accept\n"
12654 EXTCOMMUNITY_VAL_STR)
12655{
42f914d4
QY
12656 int deleteall = 0;
12657
12658 int style = EXTCOMMUNITY_LIST_STANDARD;
12659 int direct = 0;
12660 char *cl_number_or_name = NULL;
12661
12662 int idx = 0;
12663 argv_find (argv, argc, "(1-99)", &idx);
12664 argv_find (argv, argc, "WORD", &idx);
12665 cl_number_or_name = argv[idx]->arg;
12666 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12667 argv_find (argv, argc, "AA:NN", &idx);
12668 char *str = argv_concat (argv, argc, idx);
12669
12670 int ret = extcommunity_list_unset (bgp_clist, cl_number_or_name, str, direct, style, deleteall);
12671
12672 XFREE (MTYPE_TMP, str);
12673
12674 if (ret < 0)
12675 {
12676 community_list_perror (vty, ret);
12677 return CMD_WARNING;
12678 }
12679
12680 return CMD_SUCCESS;
718e3744 12681}
12682
5bf15956
DW
12683DEFUN (no_ip_extcommunity_list_expanded_all,
12684 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 12685 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 12686 NO_STR
12687 IP_STR
12688 EXTCOMMUNITY_LIST_STR
12689 "Extended Community list number (expanded)\n"
718e3744 12690 "Specify expanded extcommunity-list\n"
5bf15956 12691 "Extended Community list name\n"
718e3744 12692 "Specify community to reject\n"
12693 "Specify community to accept\n"
12694 "An ordered list as a regular-expression\n")
12695{
42f914d4
QY
12696 int deleteall = 0;
12697
12698 int style = EXTCOMMUNITY_LIST_EXPANDED;
12699 int direct = 0;
12700 char *cl_number_or_name = NULL;
12701
12702 int idx = 0;
12703 argv_find (argv, argc, "(100-500)", &idx);
12704 argv_find (argv, argc, "WORD", &idx);
12705 cl_number_or_name = argv[idx]->arg;
12706 direct = argv_find (argv, argc, "permit", &idx) ? COMMUNITY_PERMIT : COMMUNITY_DENY;
12707 argv_find (argv, argc, "LINE", &idx);
12708 char *str = argv_concat (argv, argc, idx);
12709
12710 int ret = extcommunity_list_unset (bgp_clist, cl_number_or_name, str, direct, style, deleteall);
12711
12712 XFREE (MTYPE_TMP, str);
12713
12714 if (ret < 0)
12715 {
12716 community_list_perror (vty, ret);
12717 return CMD_WARNING;
12718 }
12719
12720 return CMD_SUCCESS;
718e3744 12721}
12722
94f2b392 12723static void
718e3744 12724extcommunity_list_show (struct vty *vty, struct community_list *list)
12725{
12726 struct community_entry *entry;
12727
12728 for (entry = list->head; entry; entry = entry->next)
12729 {
12730 if (entry == list->head)
12731 {
12732 if (all_digit (list->name))
12733 vty_out (vty, "Extended community %s list %s%s",
12734 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12735 "standard" : "(expanded) access",
12736 list->name, VTY_NEWLINE);
12737 else
12738 vty_out (vty, "Named extended community %s list %s%s",
12739 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12740 "standard" : "expanded",
12741 list->name, VTY_NEWLINE);
12742 }
12743 if (entry->any)
12744 vty_out (vty, " %s%s",
12745 community_direct_str (entry->direct), VTY_NEWLINE);
12746 else
12747 vty_out (vty, " %s %s%s",
12748 community_direct_str (entry->direct),
12749 entry->style == EXTCOMMUNITY_LIST_STANDARD ?
12750 entry->u.ecom->str : entry->config,
12751 VTY_NEWLINE);
12752 }
12753}
12754
12755DEFUN (show_ip_extcommunity_list,
12756 show_ip_extcommunity_list_cmd,
12757 "show ip extcommunity-list",
12758 SHOW_STR
12759 IP_STR
12760 "List extended-community list\n")
12761{
12762 struct community_list *list;
12763 struct community_list_master *cm;
12764
fee6e4e4 12765 cm = community_list_master_lookup (bgp_clist, EXTCOMMUNITY_LIST_MASTER);
718e3744 12766 if (! cm)
12767 return CMD_SUCCESS;
12768
12769 for (list = cm->num.head; list; list = list->next)
12770 extcommunity_list_show (vty, list);
12771
12772 for (list = cm->str.head; list; list = list->next)
12773 extcommunity_list_show (vty, list);
12774
12775 return CMD_SUCCESS;
12776}
12777
12778DEFUN (show_ip_extcommunity_list_arg,
12779 show_ip_extcommunity_list_arg_cmd,
6147e2c6 12780 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 12781 SHOW_STR
12782 IP_STR
12783 "List extended-community list\n"
12784 "Extcommunity-list number\n"
12785 "Extcommunity-list name\n")
12786{
c500ae40 12787 int idx_comm_list = 3;
718e3744 12788 struct community_list *list;
12789
c500ae40 12790 list = community_list_lookup (bgp_clist, argv[idx_comm_list]->arg, EXTCOMMUNITY_LIST_MASTER);
718e3744 12791 if (! list)
12792 {
b729294c 12793 vty_out (vty, "%% Can't find extcommunity-list%s", VTY_NEWLINE);
718e3744 12794 return CMD_WARNING;
12795 }
12796
12797 extcommunity_list_show (vty, list);
12798
12799 return CMD_SUCCESS;
12800}
6b0655a2 12801
718e3744 12802/* Return configuration string of community-list entry. */
fd79ac91 12803static const char *
718e3744 12804community_list_config_str (struct community_entry *entry)
12805{
fd79ac91 12806 const char *str;
718e3744 12807
12808 if (entry->any)
12809 str = "";
12810 else
12811 {
12812 if (entry->style == COMMUNITY_LIST_STANDARD)
12813 str = community_str (entry->u.com);
12814 else
12815 str = entry->config;
12816 }
12817 return str;
12818}
12819
12820/* Display community-list and extcommunity-list configuration. */
94f2b392 12821static int
718e3744 12822community_list_config_write (struct vty *vty)
12823{
12824 struct community_list *list;
12825 struct community_entry *entry;
12826 struct community_list_master *cm;
12827 int write = 0;
12828
12829 /* Community-list. */
fee6e4e4 12830 cm = community_list_master_lookup (bgp_clist, COMMUNITY_LIST_MASTER);
718e3744 12831
12832 for (list = cm->num.head; list; list = list->next)
12833 for (entry = list->head; entry; entry = entry->next)
12834 {
fee6e4e4 12835 vty_out (vty, "ip community-list %s %s %s%s",
12836 list->name, community_direct_str (entry->direct),
12837 community_list_config_str (entry),
12838 VTY_NEWLINE);
718e3744 12839 write++;
12840 }
12841 for (list = cm->str.head; list; list = list->next)
12842 for (entry = list->head; entry; entry = entry->next)
12843 {
12844 vty_out (vty, "ip community-list %s %s %s %s%s",
12845 entry->style == COMMUNITY_LIST_STANDARD
12846 ? "standard" : "expanded",
12847 list->name, community_direct_str (entry->direct),
12848 community_list_config_str (entry),
12849 VTY_NEWLINE);
12850 write++;
12851 }
12852
12853 /* Extcommunity-list. */
fee6e4e4 12854 cm = community_list_master_lookup (bgp_clist, EXTCOMMUNITY_LIST_MASTER);
718e3744 12855
12856 for (list = cm->num.head; list; list = list->next)
12857 for (entry = list->head; entry; entry = entry->next)
12858 {
fee6e4e4 12859 vty_out (vty, "ip extcommunity-list %s %s %s%s",
12860 list->name, community_direct_str (entry->direct),
12861 community_list_config_str (entry), VTY_NEWLINE);
718e3744 12862 write++;
12863 }
12864 for (list = cm->str.head; list; list = list->next)
12865 for (entry = list->head; entry; entry = entry->next)
12866 {
12867 vty_out (vty, "ip extcommunity-list %s %s %s %s%s",
12868 entry->style == EXTCOMMUNITY_LIST_STANDARD
12869 ? "standard" : "expanded",
12870 list->name, community_direct_str (entry->direct),
12871 community_list_config_str (entry), VTY_NEWLINE);
12872 write++;
12873 }
57d187bc
JS
12874
12875
12876 /* lcommunity-list. */
12877 cm = community_list_master_lookup (bgp_clist, LARGE_COMMUNITY_LIST_MASTER);
12878
12879 for (list = cm->num.head; list; list = list->next)
12880 for (entry = list->head; entry; entry = entry->next)
12881 {
2acb4ac2
DL
12882 vty_out (vty, "ip large-community-list %s %s %s%s",
12883 list->name, community_direct_str (entry->direct),
12884 community_list_config_str (entry), VTY_NEWLINE);
12885 write++;
57d187bc
JS
12886 }
12887 for (list = cm->str.head; list; list = list->next)
12888 for (entry = list->head; entry; entry = entry->next)
12889 {
2acb4ac2
DL
12890 vty_out (vty, "ip large-community-list %s %s %s %s%s",
12891 entry->style == LARGE_COMMUNITY_LIST_STANDARD
12892 ? "standard" : "expanded",
12893 list->name, community_direct_str (entry->direct),
12894 community_list_config_str (entry), VTY_NEWLINE);
12895 write++;
57d187bc
JS
12896 }
12897
718e3744 12898 return write;
12899}
12900
7fc626de 12901static struct cmd_node community_list_node =
718e3744 12902{
12903 COMMUNITY_LIST_NODE,
12904 "",
12905 1 /* Export to vtysh. */
12906};
12907
94f2b392 12908static void
12909community_list_vty (void)
718e3744 12910{
12911 install_node (&community_list_node, community_list_config_write);
12912
12913 /* Community-list. */
718e3744 12914 install_element (CONFIG_NODE, &ip_community_list_standard_cmd);
d7d73ffc 12915 install_element (CONFIG_NODE, &ip_community_list_expanded_all_cmd);
fee6e4e4 12916 install_element (CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
12917 install_element (CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
718e3744 12918 install_element (VIEW_NODE, &show_ip_community_list_cmd);
12919 install_element (VIEW_NODE, &show_ip_community_list_arg_cmd);
718e3744 12920
12921 /* Extcommunity-list. */
12922 install_element (CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
718e3744 12923 install_element (CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
fee6e4e4 12924 install_element (CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
12925 install_element (CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
718e3744 12926 install_element (VIEW_NODE, &show_ip_extcommunity_list_cmd);
12927 install_element (VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
57d187bc
JS
12928
12929 /* Large Community List */
12930 install_element (CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
52951b63 12931 install_element (CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
57d187bc
JS
12932 install_element (CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
12933 install_element (CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
52951b63 12934 install_element (CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
57d187bc
JS
12935 install_element (CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
12936 install_element (CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
12937 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_all_cmd);
12938 install_element (CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
12939 install_element (CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
12940 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
12941 install_element (CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
12942 install_element (VIEW_NODE, &show_ip_lcommunity_list_cmd);
12943 install_element (VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 12944}