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