]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: display hostname capabilities as advertised and received
[mirror_frr.git] / bgpd / bgp_vty.c
CommitLineData
718e3744 1/* BGP VTY interface.
896014f4
DL
2 * Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#include <zebra.h>
22
23#include "command.h"
afec25d9 24#include "lib/json.h"
718e3744 25#include "prefix.h"
26#include "plist.h"
27#include "buffer.h"
28#include "linklist.h"
29#include "stream.h"
30#include "thread.h"
31#include "log.h"
3b8b1855 32#include "memory.h"
fc7948fa 33#include "memory_vty.h"
4bf6a362 34#include "hash.h"
3f9c7369 35#include "queue.h"
039f3a34 36#include "filter.h"
718e3744 37
38#include "bgpd/bgpd.h"
4bf6a362 39#include "bgpd/bgp_advertise.h"
718e3744 40#include "bgpd/bgp_attr.h"
41#include "bgpd/bgp_aspath.h"
42#include "bgpd/bgp_community.h"
4bf6a362 43#include "bgpd/bgp_ecommunity.h"
57d187bc 44#include "bgpd/bgp_lcommunity.h"
4bf6a362 45#include "bgpd/bgp_damp.h"
718e3744 46#include "bgpd/bgp_debug.h"
e0701b79 47#include "bgpd/bgp_fsm.h"
4bf6a362 48#include "bgpd/bgp_nexthop.h"
718e3744 49#include "bgpd/bgp_open.h"
4bf6a362 50#include "bgpd/bgp_regex.h"
718e3744 51#include "bgpd/bgp_route.h"
c016b6c7 52#include "bgpd/bgp_mplsvpn.h"
718e3744 53#include "bgpd/bgp_zebra.h"
fee0f4c6 54#include "bgpd/bgp_table.h"
94f2b392 55#include "bgpd/bgp_vty.h"
165b5fff 56#include "bgpd/bgp_mpath.h"
cb1faec9 57#include "bgpd/bgp_packet.h"
3f9c7369 58#include "bgpd/bgp_updgrp.h"
c43ed2e4 59#include "bgpd/bgp_bfd.h"
718e3744 60
d62a17ae 61static struct peer_group *listen_range_exists(struct bgp *bgp,
62 struct prefix *range, int exact);
63
64static enum node_type bgp_node_type(afi_t afi, safi_t safi)
65{
66 switch (afi) {
67 case AFI_IP:
68 switch (safi) {
69 case SAFI_UNICAST:
70 return BGP_IPV4_NODE;
71 break;
72 case SAFI_MULTICAST:
73 return BGP_IPV4M_NODE;
74 break;
75 case SAFI_LABELED_UNICAST:
76 return BGP_IPV4L_NODE;
77 break;
78 case SAFI_MPLS_VPN:
79 return BGP_VPNV4_NODE;
80 break;
5c525538
RW
81 default:
82 /* not expected */
83 return BGP_IPV4_NODE;
84 break;
d62a17ae 85 }
86 break;
87 case AFI_IP6:
88 switch (safi) {
89 case SAFI_UNICAST:
90 return BGP_IPV6_NODE;
91 break;
92 case SAFI_MULTICAST:
93 return BGP_IPV6M_NODE;
94 break;
95 case SAFI_LABELED_UNICAST:
96 return BGP_IPV6L_NODE;
97 break;
98 case SAFI_MPLS_VPN:
99 return BGP_VPNV6_NODE;
100 break;
5c525538
RW
101 default:
102 /* not expected */
103 return BGP_IPV4_NODE;
104 break;
d62a17ae 105 }
106 break;
107 case AFI_L2VPN:
108 return BGP_EVPN_NODE;
109 break;
110 case AFI_MAX:
111 // We should never be here but to clarify the switch statement..
112 return BGP_IPV4_NODE;
113 break;
114 }
115
116 // Impossible to happen
117 return BGP_IPV4_NODE;
f51bae9c 118}
20eb8864 119
718e3744 120/* Utility function to get address family from current node. */
d62a17ae 121afi_t bgp_node_afi(struct vty *vty)
122{
123 afi_t afi;
124 switch (vty->node) {
125 case BGP_IPV6_NODE:
126 case BGP_IPV6M_NODE:
127 case BGP_IPV6L_NODE:
128 case BGP_VPNV6_NODE:
129 afi = AFI_IP6;
130 break;
131 case BGP_EVPN_NODE:
132 afi = AFI_L2VPN;
133 break;
134 default:
135 afi = AFI_IP;
136 break;
137 }
138 return afi;
718e3744 139}
140
141/* Utility function to get subsequent address family from current
142 node. */
d62a17ae 143safi_t bgp_node_safi(struct vty *vty)
144{
145 safi_t safi;
146 switch (vty->node) {
147 case BGP_VPNV4_NODE:
148 case BGP_VPNV6_NODE:
149 safi = SAFI_MPLS_VPN;
150 break;
151 case BGP_IPV4M_NODE:
152 case BGP_IPV6M_NODE:
153 safi = SAFI_MULTICAST;
154 break;
155 case BGP_EVPN_NODE:
156 safi = SAFI_EVPN;
157 break;
158 case BGP_IPV4L_NODE:
159 case BGP_IPV6L_NODE:
160 safi = SAFI_LABELED_UNICAST;
161 break;
162 default:
163 safi = SAFI_UNICAST;
164 break;
165 }
166 return safi;
718e3744 167}
168
55f91488
QY
169/**
170 * Converts an AFI in string form to afi_t
171 *
172 * @param afi string, one of
173 * - "ipv4"
174 * - "ipv6"
175 * @return the corresponding afi_t
176 */
d62a17ae 177afi_t bgp_vty_afi_from_str(const char *afi_str)
178{
179 afi_t afi = AFI_MAX; /* unknown */
180 if (strmatch(afi_str, "ipv4"))
181 afi = AFI_IP;
182 else if (strmatch(afi_str, "ipv6"))
183 afi = AFI_IP6;
184 return afi;
185}
186
187int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
188 afi_t *afi)
189{
190 int ret = 0;
191 if (argv_find(argv, argc, "ipv4", index)) {
192 ret = 1;
193 if (afi)
194 *afi = AFI_IP;
195 } else if (argv_find(argv, argc, "ipv6", index)) {
196 ret = 1;
197 if (afi)
198 *afi = AFI_IP6;
199 }
200 return ret;
46f296b4
LB
201}
202
375a2e67 203/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 204safi_t bgp_vty_safi_from_str(const char *safi_str)
205{
206 safi_t safi = SAFI_MAX; /* unknown */
207 if (strmatch(safi_str, "multicast"))
208 safi = SAFI_MULTICAST;
209 else if (strmatch(safi_str, "unicast"))
210 safi = SAFI_UNICAST;
211 else if (strmatch(safi_str, "vpn"))
212 safi = SAFI_MPLS_VPN;
213 else if (strmatch(safi_str, "labeled-unicast"))
214 safi = SAFI_LABELED_UNICAST;
215 return safi;
216}
217
218int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
219 safi_t *safi)
220{
221 int ret = 0;
222 if (argv_find(argv, argc, "unicast", index)) {
223 ret = 1;
224 if (safi)
225 *safi = SAFI_UNICAST;
226 } else if (argv_find(argv, argc, "multicast", index)) {
227 ret = 1;
228 if (safi)
229 *safi = SAFI_MULTICAST;
230 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
231 ret = 1;
232 if (safi)
233 *safi = SAFI_LABELED_UNICAST;
234 } else if (argv_find(argv, argc, "vpn", index)) {
235 ret = 1;
236 if (safi)
237 *safi = SAFI_MPLS_VPN;
238 }
239 return ret;
46f296b4
LB
240}
241
7eeee51e 242/*
f212a857 243 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 244 *
f212a857
DS
245 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
246 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
247 * to appropriate values for the calling function. This is to allow the
248 * calling function to make decisions appropriate for the show command
249 * that is being parsed.
250 *
251 * The show commands are generally of the form:
d62a17ae 252 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
253 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
254 *
255 * Since we use argv_find if the show command in particular doesn't have:
256 * [ip]
18c57037 257 * [<view|vrf> VIEWVRFNAME]
375a2e67 258 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
259 * The command parsing should still be ok.
260 *
261 * vty -> The vty for the command so we can output some useful data in
262 * the event of a parse error in the vrf.
263 * argv -> The command tokens
264 * argc -> How many command tokens we have
d62a17ae 265 * idx -> The current place in the command, generally should be 0 for this
266 * function
7eeee51e
DS
267 * afi -> The parsed afi if it was included in the show command, returned here
268 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 269 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
270 *
271 * The function returns the correct location in the parse tree for the
272 * last token found.
0e37c258
DS
273 *
274 * Returns 0 for failure to parse correctly, else the idx position of where
275 * it found the last token.
7eeee51e 276 */
d62a17ae 277int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
278 struct cmd_token **argv, int argc,
279 int *idx, afi_t *afi, safi_t *safi,
280 struct bgp **bgp)
281{
282 char *vrf_name = NULL;
283
284 assert(afi);
285 assert(safi);
286 assert(bgp);
287
288 if (argv_find(argv, argc, "ip", idx))
289 *afi = AFI_IP;
290
291 if (argv_find(argv, argc, "view", idx)
292 || argv_find(argv, argc, "vrf", idx)) {
293 vrf_name = argv[*idx + 1]->arg;
294
295 if (strmatch(vrf_name, "all"))
296 *bgp = NULL;
297 else {
298 *bgp = bgp_lookup_by_name(vrf_name);
299 if (!*bgp) {
300 vty_out(vty,
301 "View/Vrf specified is unknown: %s\n",
302 vrf_name);
303 *idx = 0;
304 return 0;
305 }
306 }
307 } else {
308 *bgp = bgp_get_default();
309 if (!*bgp) {
310 vty_out(vty, "Unable to find default BGP instance\n");
311 *idx = 0;
312 return 0;
313 }
314 }
315
316 if (argv_find_and_parse_afi(argv, argc, idx, afi))
317 argv_find_and_parse_safi(argv, argc, idx, safi);
318
319 *idx += 1;
320 return *idx;
321}
322
323static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
324{
325 struct interface *ifp = NULL;
326
327 if (su->sa.sa_family == AF_INET)
328 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
329 else if (su->sa.sa_family == AF_INET6)
330 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
331 su->sin6.sin6_scope_id,
332 bgp->vrf_id);
333
334 if (ifp)
335 return 1;
336
337 return 0;
718e3744 338}
339
340/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
341/* This is used only for configuration, so disallow if attempted on
342 * a dynamic neighbor.
343 */
d62a17ae 344static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
345{
346 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
347 int ret;
348 union sockunion su;
349 struct peer *peer;
350
351 if (!bgp) {
352 return NULL;
353 }
354
355 ret = str2sockunion(ip_str, &su);
356 if (ret < 0) {
357 peer = peer_lookup_by_conf_if(bgp, ip_str);
358 if (!peer) {
359 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
360 == NULL) {
361 vty_out(vty,
362 "%% Malformed address or name: %s\n",
363 ip_str);
364 return NULL;
365 }
366 }
367 } else {
368 peer = peer_lookup(bgp, &su);
369 if (!peer) {
370 vty_out(vty,
371 "%% Specify remote-as or peer-group commands first\n");
372 return NULL;
373 }
374 if (peer_dynamic_neighbor(peer)) {
375 vty_out(vty,
376 "%% Operation not allowed on a dynamic neighbor\n");
377 return NULL;
378 }
379 }
380 return peer;
718e3744 381}
382
383/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
384/* This is used only for configuration, so disallow if attempted on
385 * a dynamic neighbor.
386 */
d62a17ae 387struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
388{
389 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
390 int ret;
391 union sockunion su;
392 struct peer *peer = NULL;
393 struct peer_group *group = NULL;
394
395 if (!bgp) {
396 return NULL;
397 }
398
399 ret = str2sockunion(peer_str, &su);
400 if (ret == 0) {
401 /* IP address, locate peer. */
402 peer = peer_lookup(bgp, &su);
403 } else {
404 /* Not IP, could match either peer configured on interface or a
405 * group. */
406 peer = peer_lookup_by_conf_if(bgp, peer_str);
407 if (!peer)
408 group = peer_group_lookup(bgp, peer_str);
409 }
410
411 if (peer) {
412 if (peer_dynamic_neighbor(peer)) {
413 vty_out(vty,
414 "%% Operation not allowed on a dynamic neighbor\n");
415 return NULL;
416 }
417
418 return peer;
419 }
420
421 if (group)
422 return group->conf;
423
424 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
425
426 return NULL;
427}
428
429int bgp_vty_return(struct vty *vty, int ret)
430{
431 const char *str = NULL;
432
433 switch (ret) {
434 case BGP_ERR_INVALID_VALUE:
435 str = "Invalid value";
436 break;
437 case BGP_ERR_INVALID_FLAG:
438 str = "Invalid flag";
439 break;
440 case BGP_ERR_PEER_GROUP_SHUTDOWN:
441 str = "Peer-group has been shutdown. Activate the peer-group first";
442 break;
443 case BGP_ERR_PEER_FLAG_CONFLICT:
444 str = "Can't set override-capability and strict-capability-match at the same time";
445 break;
446 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
447 str = "Specify remote-as or peer-group remote AS first";
448 break;
449 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
450 str = "Cannot change the peer-group. Deconfigure first";
451 break;
452 case BGP_ERR_PEER_GROUP_MISMATCH:
453 str = "Peer is not a member of this peer-group";
454 break;
455 case BGP_ERR_PEER_FILTER_CONFLICT:
456 str = "Prefix/distribute list can not co-exist";
457 break;
458 case BGP_ERR_NOT_INTERNAL_PEER:
459 str = "Invalid command. Not an internal neighbor";
460 break;
461 case BGP_ERR_REMOVE_PRIVATE_AS:
462 str = "remove-private-AS cannot be configured for IBGP peers";
463 break;
464 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
465 str = "Local-AS allowed only for EBGP peers";
466 break;
467 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
468 str = "Cannot have local-as same as BGP AS number";
469 break;
470 case BGP_ERR_TCPSIG_FAILED:
471 str = "Error while applying TCP-Sig to session(s)";
472 break;
473 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
474 str = "ebgp-multihop and ttl-security cannot be configured together";
475 break;
476 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
477 str = "ttl-security only allowed for EBGP peers";
478 break;
479 case BGP_ERR_AS_OVERRIDE:
480 str = "as-override cannot be configured for IBGP peers";
481 break;
482 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
483 str = "Invalid limit for number of dynamic neighbors";
484 break;
485 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
486 str = "Dynamic neighbor listen range already exists";
487 break;
488 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
489 str = "Operation not allowed on a dynamic neighbor";
490 break;
491 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
492 str = "Operation not allowed on a directly connected neighbor";
493 break;
494 case BGP_ERR_PEER_SAFI_CONFLICT:
495 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
496 break;
497 }
498 if (str) {
499 vty_out(vty, "%% %s\n", str);
500 return CMD_WARNING_CONFIG_FAILED;
501 }
502 return CMD_SUCCESS;
718e3744 503}
504
7aafcaca 505/* BGP clear sort. */
d62a17ae 506enum clear_sort {
507 clear_all,
508 clear_peer,
509 clear_group,
510 clear_external,
511 clear_as
7aafcaca
DS
512};
513
d62a17ae 514static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
515 safi_t safi, int error)
516{
517 switch (error) {
518 case BGP_ERR_AF_UNCONFIGURED:
519 vty_out(vty,
520 "%%BGP: Enable %s address family for the neighbor %s\n",
521 afi_safi_print(afi, safi), peer->host);
522 break;
523 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
524 vty_out(vty,
525 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
526 peer->host);
527 break;
528 default:
529 break;
530 }
7aafcaca
DS
531}
532
533/* `clear ip bgp' functions. */
d62a17ae 534static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
535 enum clear_sort sort, enum bgp_clear_type stype,
536 const char *arg)
537{
538 int ret;
539 struct peer *peer;
540 struct listnode *node, *nnode;
541
542 /* Clear all neighbors. */
543 /*
544 * Pass along pointer to next node to peer_clear() when walking all
545 * nodes
546 * on the BGP instance as that may get freed if it is a doppelganger
547 */
548 if (sort == clear_all) {
549 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
550 if (stype == BGP_CLEAR_SOFT_NONE)
551 ret = peer_clear(peer, &nnode);
552 else if (peer->afc[afi][safi])
553 ret = peer_clear_soft(peer, afi, safi, stype);
554 else
555 ret = 0;
556
557 if (ret < 0)
558 bgp_clear_vty_error(vty, peer, afi, safi, ret);
04b6bdc0 559 }
d62a17ae 560
561 /* This is to apply read-only mode on this clear. */
562 if (stype == BGP_CLEAR_SOFT_NONE)
563 bgp->update_delay_over = 0;
564
565 return CMD_SUCCESS;
7aafcaca
DS
566 }
567
d62a17ae 568 /* Clear specified neighbors. */
569 if (sort == clear_peer) {
570 union sockunion su;
571 int ret;
572
573 /* Make sockunion for lookup. */
574 ret = str2sockunion(arg, &su);
575 if (ret < 0) {
576 peer = peer_lookup_by_conf_if(bgp, arg);
577 if (!peer) {
578 peer = peer_lookup_by_hostname(bgp, arg);
579 if (!peer) {
580 vty_out(vty,
581 "Malformed address or name: %s\n",
582 arg);
583 return CMD_WARNING;
584 }
585 }
586 } else {
587 peer = peer_lookup(bgp, &su);
588 if (!peer) {
589 vty_out(vty,
590 "%%BGP: Unknown neighbor - \"%s\"\n",
591 arg);
592 return CMD_WARNING;
593 }
594 }
7aafcaca 595
d62a17ae 596 if (stype == BGP_CLEAR_SOFT_NONE)
597 ret = peer_clear(peer, NULL);
598 else
599 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 600
d62a17ae 601 if (ret < 0)
602 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 603
d62a17ae 604 return CMD_SUCCESS;
7aafcaca 605 }
7aafcaca 606
d62a17ae 607 /* Clear all peer-group members. */
608 if (sort == clear_group) {
609 struct peer_group *group;
7aafcaca 610
d62a17ae 611 group = peer_group_lookup(bgp, arg);
612 if (!group) {
613 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
614 return CMD_WARNING;
615 }
616
617 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
618 if (stype == BGP_CLEAR_SOFT_NONE) {
619 peer_clear(peer, NULL);
620 continue;
621 }
622
623 if (!peer->afc[afi][safi])
624 continue;
625
626 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 627
d62a17ae 628 if (ret < 0)
629 bgp_clear_vty_error(vty, peer, afi, safi, ret);
630 }
631 return CMD_SUCCESS;
7aafcaca 632 }
7aafcaca 633
d62a17ae 634 if (sort == clear_external) {
635 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
636 if (peer->sort == BGP_PEER_IBGP)
637 continue;
7aafcaca 638
d62a17ae 639 if (stype == BGP_CLEAR_SOFT_NONE)
640 ret = peer_clear(peer, &nnode);
641 else
642 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 643
d62a17ae 644 if (ret < 0)
645 bgp_clear_vty_error(vty, peer, afi, safi, ret);
646 }
647 return CMD_SUCCESS;
648 }
649
650 if (sort == clear_as) {
651 as_t as;
652 int find = 0;
653
654 as = strtoul(arg, NULL, 10);
655
656 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
657 if (peer->as != as)
658 continue;
659
660 find = 1;
661 if (stype == BGP_CLEAR_SOFT_NONE)
662 ret = peer_clear(peer, &nnode);
663 else
664 ret = peer_clear_soft(peer, afi, safi, stype);
665
666 if (ret < 0)
667 bgp_clear_vty_error(vty, peer, afi, safi, ret);
668 }
669 if (!find)
670 vty_out(vty,
671 "%%BGP: No peer is configured with AS %s\n",
672 arg);
673 return CMD_SUCCESS;
674 }
675
676 return CMD_SUCCESS;
677}
678
679static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
680 safi_t safi, enum clear_sort sort,
681 enum bgp_clear_type stype, const char *arg)
682{
683 struct bgp *bgp;
684
685 /* BGP structure lookup. */
686 if (name) {
687 bgp = bgp_lookup_by_name(name);
688 if (bgp == NULL) {
689 vty_out(vty, "Can't find BGP instance %s\n", name);
690 return CMD_WARNING;
691 }
692 } else {
693 bgp = bgp_get_default();
694 if (bgp == NULL) {
695 vty_out(vty, "No BGP process is configured\n");
696 return CMD_WARNING;
697 }
698 }
699
700 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
701}
702
703/* clear soft inbound */
d62a17ae 704static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 705{
d62a17ae 706 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
707 BGP_CLEAR_SOFT_IN, NULL);
708 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
709 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
710}
711
712/* clear soft outbound */
d62a17ae 713static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 714{
d62a17ae 715 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
716 BGP_CLEAR_SOFT_OUT, NULL);
717 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
718 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
719}
720
721
f787d7a0
DL
722#ifndef VTYSH_EXTRACT_PL
723#include "bgp_vty_clippy.c"
724#endif
725
718e3744 726/* BGP global configuration. */
727
728DEFUN (bgp_multiple_instance_func,
729 bgp_multiple_instance_cmd,
730 "bgp multiple-instance",
731 BGP_STR
732 "Enable bgp multiple instance\n")
733{
d62a17ae 734 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
735 return CMD_SUCCESS;
718e3744 736}
737
738DEFUN (no_bgp_multiple_instance,
739 no_bgp_multiple_instance_cmd,
740 "no bgp multiple-instance",
741 NO_STR
742 BGP_STR
743 "BGP multiple instance\n")
744{
d62a17ae 745 int ret;
718e3744 746
d62a17ae 747 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
748 if (ret < 0) {
749 vty_out(vty, "%% There are more than two BGP instances\n");
750 return CMD_WARNING_CONFIG_FAILED;
751 }
752 return CMD_SUCCESS;
718e3744 753}
754
755DEFUN (bgp_config_type,
756 bgp_config_type_cmd,
6147e2c6 757 "bgp config-type <cisco|zebra>",
718e3744 758 BGP_STR
759 "Configuration type\n"
760 "cisco\n"
761 "zebra\n")
762{
d62a17ae 763 int idx = 0;
764 if (argv_find(argv, argc, "cisco", &idx))
765 bgp_option_set(BGP_OPT_CONFIG_CISCO);
766 else
767 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 768
d62a17ae 769 return CMD_SUCCESS;
718e3744 770}
771
772DEFUN (no_bgp_config_type,
773 no_bgp_config_type_cmd,
c7178fe7 774 "no bgp config-type [<cisco|zebra>]",
718e3744 775 NO_STR
776 BGP_STR
838758ac
DW
777 "Display configuration type\n"
778 "cisco\n"
779 "zebra\n")
718e3744 780{
d62a17ae 781 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
782 return CMD_SUCCESS;
718e3744 783}
784
813d4307 785
718e3744 786DEFUN (no_synchronization,
787 no_synchronization_cmd,
788 "no synchronization",
789 NO_STR
790 "Perform IGP synchronization\n")
791{
d62a17ae 792 return CMD_SUCCESS;
718e3744 793}
794
795DEFUN (no_auto_summary,
796 no_auto_summary_cmd,
797 "no auto-summary",
798 NO_STR
799 "Enable automatic network number summarization\n")
800{
d62a17ae 801 return CMD_SUCCESS;
718e3744 802}
3d515fd9 803
718e3744 804/* "router bgp" commands. */
505e5056 805DEFUN_NOSH (router_bgp,
f412b39a 806 router_bgp_cmd,
18c57037 807 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 808 ROUTER_STR
809 BGP_STR
31500417
DW
810 AS_STR
811 BGP_INSTANCE_HELP_STR)
718e3744 812{
d62a17ae 813 int idx_asn = 2;
814 int idx_view_vrf = 3;
815 int idx_vrf = 4;
816 int ret;
817 as_t as;
818 struct bgp *bgp;
819 const char *name = NULL;
820 enum bgp_instance_type inst_type;
821
822 // "router bgp" without an ASN
823 if (argc == 2) {
824 // Pending: Make VRF option available for ASN less config
825 bgp = bgp_get_default();
826
827 if (bgp == NULL) {
828 vty_out(vty, "%% No BGP process is configured\n");
829 return CMD_WARNING_CONFIG_FAILED;
830 }
831
832 if (listcount(bm->bgp) > 1) {
833 vty_out(vty,
834 "%% Multiple BGP processes are configured\n");
835 return CMD_WARNING_CONFIG_FAILED;
836 }
837 }
838
839 // "router bgp X"
840 else {
841 as = strtoul(argv[idx_asn]->arg, NULL, 10);
842
843 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
844 if (argc > 3) {
845 name = argv[idx_vrf]->arg;
846
847 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
848 inst_type = BGP_INSTANCE_TYPE_VRF;
849 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
850 inst_type = BGP_INSTANCE_TYPE_VIEW;
851 }
852
853 ret = bgp_get(&bgp, &as, name, inst_type);
854 switch (ret) {
855 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
856 vty_out(vty,
857 "Please specify 'bgp multiple-instance' first\n");
858 return CMD_WARNING_CONFIG_FAILED;
859 case BGP_ERR_AS_MISMATCH:
860 vty_out(vty, "BGP is already running; AS is %u\n", as);
861 return CMD_WARNING_CONFIG_FAILED;
862 case BGP_ERR_INSTANCE_MISMATCH:
863 vty_out(vty,
864 "BGP instance name and AS number mismatch\n");
865 vty_out(vty,
866 "BGP instance is already running; AS is %u\n",
867 as);
868 return CMD_WARNING_CONFIG_FAILED;
869 }
870
871 /* Pending: handle when user tries to change a view to vrf n vv.
872 */
873 }
874
875 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
876
877 return CMD_SUCCESS;
718e3744 878}
879
718e3744 880/* "no router bgp" commands. */
881DEFUN (no_router_bgp,
882 no_router_bgp_cmd,
18c57037 883 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 884 NO_STR
885 ROUTER_STR
886 BGP_STR
31500417
DW
887 AS_STR
888 BGP_INSTANCE_HELP_STR)
718e3744 889{
d62a17ae 890 int idx_asn = 3;
891 int idx_vrf = 5;
892 as_t as;
893 struct bgp *bgp;
894 const char *name = NULL;
718e3744 895
d62a17ae 896 // "no router bgp" without an ASN
897 if (argc == 3) {
898 // Pending: Make VRF option available for ASN less config
899 bgp = bgp_get_default();
718e3744 900
d62a17ae 901 if (bgp == NULL) {
902 vty_out(vty, "%% No BGP process is configured\n");
903 return CMD_WARNING_CONFIG_FAILED;
904 }
7fb21a9f 905
d62a17ae 906 if (listcount(bm->bgp) > 1) {
907 vty_out(vty,
908 "%% Multiple BGP processes are configured\n");
909 return CMD_WARNING_CONFIG_FAILED;
910 }
911 } else {
912 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 913
d62a17ae 914 if (argc > 4)
915 name = argv[idx_vrf]->arg;
7fb21a9f 916
d62a17ae 917 /* Lookup bgp structure. */
918 bgp = bgp_lookup(as, name);
919 if (!bgp) {
920 vty_out(vty, "%% Can't find BGP instance\n");
921 return CMD_WARNING_CONFIG_FAILED;
922 }
923 }
718e3744 924
d62a17ae 925 bgp_delete(bgp);
718e3744 926
d62a17ae 927 return CMD_SUCCESS;
718e3744 928}
929
6b0655a2 930
718e3744 931/* BGP router-id. */
932
f787d7a0 933DEFPY (bgp_router_id,
718e3744 934 bgp_router_id_cmd,
935 "bgp router-id A.B.C.D",
936 BGP_STR
937 "Override configured router identifier\n"
938 "Manually configured router identifier\n")
939{
d62a17ae 940 VTY_DECLVAR_CONTEXT(bgp, bgp);
941 bgp_router_id_static_set(bgp, router_id);
942 return CMD_SUCCESS;
718e3744 943}
944
f787d7a0 945DEFPY (no_bgp_router_id,
718e3744 946 no_bgp_router_id_cmd,
31500417 947 "no bgp router-id [A.B.C.D]",
718e3744 948 NO_STR
949 BGP_STR
31500417
DW
950 "Override configured router identifier\n"
951 "Manually configured router identifier\n")
718e3744 952{
d62a17ae 953 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 954
d62a17ae 955 if (router_id_str) {
956 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
957 vty_out(vty, "%% BGP router-id doesn't match\n");
958 return CMD_WARNING_CONFIG_FAILED;
959 }
e018c7cc 960 }
718e3744 961
d62a17ae 962 router_id.s_addr = 0;
963 bgp_router_id_static_set(bgp, router_id);
718e3744 964
d62a17ae 965 return CMD_SUCCESS;
718e3744 966}
967
6b0655a2 968
718e3744 969/* BGP Cluster ID. */
718e3744 970DEFUN (bgp_cluster_id,
971 bgp_cluster_id_cmd,
838758ac 972 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 973 BGP_STR
974 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
975 "Route-Reflector Cluster-id in IP address format\n"
976 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 977{
d62a17ae 978 VTY_DECLVAR_CONTEXT(bgp, bgp);
979 int idx_ipv4 = 2;
980 int ret;
981 struct in_addr cluster;
718e3744 982
d62a17ae 983 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
984 if (!ret) {
985 vty_out(vty, "%% Malformed bgp cluster identifier\n");
986 return CMD_WARNING_CONFIG_FAILED;
987 }
718e3744 988
d62a17ae 989 bgp_cluster_id_set(bgp, &cluster);
990 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 991
d62a17ae 992 return CMD_SUCCESS;
718e3744 993}
994
718e3744 995DEFUN (no_bgp_cluster_id,
996 no_bgp_cluster_id_cmd,
c7178fe7 997 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 998 NO_STR
999 BGP_STR
838758ac
DW
1000 "Configure Route-Reflector Cluster-id\n"
1001 "Route-Reflector Cluster-id in IP address format\n"
1002 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1003{
d62a17ae 1004 VTY_DECLVAR_CONTEXT(bgp, bgp);
1005 bgp_cluster_id_unset(bgp);
1006 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1007
d62a17ae 1008 return CMD_SUCCESS;
718e3744 1009}
1010
718e3744 1011DEFUN (bgp_confederation_identifier,
1012 bgp_confederation_identifier_cmd,
9ccf14f7 1013 "bgp confederation identifier (1-4294967295)",
718e3744 1014 "BGP specific commands\n"
1015 "AS confederation parameters\n"
1016 "AS number\n"
1017 "Set routing domain confederation AS\n")
1018{
d62a17ae 1019 VTY_DECLVAR_CONTEXT(bgp, bgp);
1020 int idx_number = 3;
1021 as_t as;
718e3744 1022
d62a17ae 1023 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1024
d62a17ae 1025 bgp_confederation_id_set(bgp, as);
718e3744 1026
d62a17ae 1027 return CMD_SUCCESS;
718e3744 1028}
1029
1030DEFUN (no_bgp_confederation_identifier,
1031 no_bgp_confederation_identifier_cmd,
838758ac 1032 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1033 NO_STR
1034 "BGP specific commands\n"
1035 "AS confederation parameters\n"
3a2d747c
QY
1036 "AS number\n"
1037 "Set routing domain confederation AS\n")
718e3744 1038{
d62a17ae 1039 VTY_DECLVAR_CONTEXT(bgp, bgp);
1040 bgp_confederation_id_unset(bgp);
718e3744 1041
d62a17ae 1042 return CMD_SUCCESS;
718e3744 1043}
1044
718e3744 1045DEFUN (bgp_confederation_peers,
1046 bgp_confederation_peers_cmd,
12dcf78e 1047 "bgp confederation peers (1-4294967295)...",
718e3744 1048 "BGP specific commands\n"
1049 "AS confederation parameters\n"
1050 "Peer ASs in BGP confederation\n"
1051 AS_STR)
1052{
d62a17ae 1053 VTY_DECLVAR_CONTEXT(bgp, bgp);
1054 int idx_asn = 3;
1055 as_t as;
1056 int i;
718e3744 1057
d62a17ae 1058 for (i = idx_asn; i < argc; i++) {
1059 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1060
d62a17ae 1061 if (bgp->as == as) {
1062 vty_out(vty,
1063 "%% Local member-AS not allowed in confed peer list\n");
1064 continue;
1065 }
718e3744 1066
d62a17ae 1067 bgp_confederation_peers_add(bgp, as);
1068 }
1069 return CMD_SUCCESS;
718e3744 1070}
1071
1072DEFUN (no_bgp_confederation_peers,
1073 no_bgp_confederation_peers_cmd,
e83a9414 1074 "no bgp confederation peers (1-4294967295)...",
718e3744 1075 NO_STR
1076 "BGP specific commands\n"
1077 "AS confederation parameters\n"
1078 "Peer ASs in BGP confederation\n"
1079 AS_STR)
1080{
d62a17ae 1081 VTY_DECLVAR_CONTEXT(bgp, bgp);
1082 int idx_asn = 4;
1083 as_t as;
1084 int i;
718e3744 1085
d62a17ae 1086 for (i = idx_asn; i < argc; i++) {
1087 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1088
d62a17ae 1089 bgp_confederation_peers_remove(bgp, as);
1090 }
1091 return CMD_SUCCESS;
718e3744 1092}
6b0655a2 1093
5e242b0d
DS
1094/**
1095 * Central routine for maximum-paths configuration.
1096 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1097 * @set: 1 for setting values, 0 for removing the max-paths config.
1098 */
d62a17ae 1099static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1100 const char *mpaths, u_int16_t options,
1101 int set)
1102{
1103 VTY_DECLVAR_CONTEXT(bgp, bgp);
1104 u_int16_t maxpaths = 0;
1105 int ret;
1106 afi_t afi;
1107 safi_t safi;
1108
1109 afi = bgp_node_afi(vty);
1110 safi = bgp_node_safi(vty);
1111
1112 if (set) {
1113 maxpaths = strtol(mpaths, NULL, 10);
1114 if (maxpaths > multipath_num) {
1115 vty_out(vty,
1116 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1117 maxpaths, multipath_num);
1118 return CMD_WARNING_CONFIG_FAILED;
1119 }
1120 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1121 options);
1122 } else
1123 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1124
1125 if (ret < 0) {
1126 vty_out(vty,
1127 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1128 (set == 1) ? "" : "un",
1129 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1130 maxpaths, afi, safi);
1131 return CMD_WARNING_CONFIG_FAILED;
1132 }
1133
1134 bgp_recalculate_all_bestpaths(bgp);
1135
1136 return CMD_SUCCESS;
165b5fff
JB
1137}
1138
abc920f8
DS
1139DEFUN (bgp_maxmed_admin,
1140 bgp_maxmed_admin_cmd,
1141 "bgp max-med administrative ",
1142 BGP_STR
1143 "Advertise routes with max-med\n"
1144 "Administratively applied, for an indefinite period\n")
1145{
d62a17ae 1146 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1147
d62a17ae 1148 bgp->v_maxmed_admin = 1;
1149 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1150
d62a17ae 1151 bgp_maxmed_update(bgp);
abc920f8 1152
d62a17ae 1153 return CMD_SUCCESS;
abc920f8
DS
1154}
1155
1156DEFUN (bgp_maxmed_admin_medv,
1157 bgp_maxmed_admin_medv_cmd,
4668a151 1158 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1159 BGP_STR
1160 "Advertise routes with max-med\n"
1161 "Administratively applied, for an indefinite period\n"
1162 "Max MED value to be used\n")
1163{
d62a17ae 1164 VTY_DECLVAR_CONTEXT(bgp, bgp);
1165 int idx_number = 3;
abc920f8 1166
d62a17ae 1167 bgp->v_maxmed_admin = 1;
1168 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1169
d62a17ae 1170 bgp_maxmed_update(bgp);
abc920f8 1171
d62a17ae 1172 return CMD_SUCCESS;
abc920f8
DS
1173}
1174
1175DEFUN (no_bgp_maxmed_admin,
1176 no_bgp_maxmed_admin_cmd,
4668a151 1177 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1178 NO_STR
1179 BGP_STR
1180 "Advertise routes with max-med\n"
838758ac
DW
1181 "Administratively applied, for an indefinite period\n"
1182 "Max MED value to be used\n")
abc920f8 1183{
d62a17ae 1184 VTY_DECLVAR_CONTEXT(bgp, bgp);
1185 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1186 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1187 bgp_maxmed_update(bgp);
abc920f8 1188
d62a17ae 1189 return CMD_SUCCESS;
abc920f8
DS
1190}
1191
abc920f8
DS
1192DEFUN (bgp_maxmed_onstartup,
1193 bgp_maxmed_onstartup_cmd,
4668a151 1194 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1195 BGP_STR
1196 "Advertise routes with max-med\n"
1197 "Effective on a startup\n"
1198 "Time (seconds) period for max-med\n"
1199 "Max MED value to be used\n")
1200{
d62a17ae 1201 VTY_DECLVAR_CONTEXT(bgp, bgp);
1202 int idx = 0;
4668a151 1203
d62a17ae 1204 argv_find(argv, argc, "(5-86400)", &idx);
1205 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1206 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1207 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1208 else
1209 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1210
d62a17ae 1211 bgp_maxmed_update(bgp);
abc920f8 1212
d62a17ae 1213 return CMD_SUCCESS;
abc920f8
DS
1214}
1215
1216DEFUN (no_bgp_maxmed_onstartup,
1217 no_bgp_maxmed_onstartup_cmd,
4668a151 1218 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1219 NO_STR
1220 BGP_STR
1221 "Advertise routes with max-med\n"
838758ac
DW
1222 "Effective on a startup\n"
1223 "Time (seconds) period for max-med\n"
1224 "Max MED value to be used\n")
abc920f8 1225{
d62a17ae 1226 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1227
d62a17ae 1228 /* Cancel max-med onstartup if its on */
1229 if (bgp->t_maxmed_onstartup) {
1230 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1231 bgp->maxmed_onstartup_over = 1;
1232 }
abc920f8 1233
d62a17ae 1234 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1235 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1236
d62a17ae 1237 bgp_maxmed_update(bgp);
abc920f8 1238
d62a17ae 1239 return CMD_SUCCESS;
abc920f8
DS
1240}
1241
d62a17ae 1242static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1243 const char *wait)
f188f2c4 1244{
d62a17ae 1245 VTY_DECLVAR_CONTEXT(bgp, bgp);
1246 u_int16_t update_delay;
1247 u_int16_t establish_wait;
f188f2c4 1248
d62a17ae 1249 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1250
d62a17ae 1251 if (!wait) /* update-delay <delay> */
1252 {
1253 bgp->v_update_delay = update_delay;
1254 bgp->v_establish_wait = bgp->v_update_delay;
1255 return CMD_SUCCESS;
1256 }
f188f2c4 1257
d62a17ae 1258 /* update-delay <delay> <establish-wait> */
1259 establish_wait = atoi(wait);
1260 if (update_delay < establish_wait) {
1261 vty_out(vty,
1262 "%%Failed: update-delay less than the establish-wait!\n");
1263 return CMD_WARNING_CONFIG_FAILED;
1264 }
f188f2c4 1265
d62a17ae 1266 bgp->v_update_delay = update_delay;
1267 bgp->v_establish_wait = establish_wait;
f188f2c4 1268
d62a17ae 1269 return CMD_SUCCESS;
f188f2c4
DS
1270}
1271
d62a17ae 1272static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1273{
d62a17ae 1274 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1275
d62a17ae 1276 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1277 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1278
d62a17ae 1279 return CMD_SUCCESS;
f188f2c4
DS
1280}
1281
d62a17ae 1282int bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1283{
d62a17ae 1284 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1285 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1286 if (bgp->v_update_delay != bgp->v_establish_wait)
1287 vty_out(vty, " %d", bgp->v_establish_wait);
1288 vty_out(vty, "\n");
1289 }
f188f2c4 1290
d62a17ae 1291 return 0;
f188f2c4
DS
1292}
1293
1294
1295/* Update-delay configuration */
1296DEFUN (bgp_update_delay,
1297 bgp_update_delay_cmd,
6147e2c6 1298 "update-delay (0-3600)",
f188f2c4
DS
1299 "Force initial delay for best-path and updates\n"
1300 "Seconds\n")
1301{
d62a17ae 1302 int idx_number = 1;
1303 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1304}
1305
1306DEFUN (bgp_update_delay_establish_wait,
1307 bgp_update_delay_establish_wait_cmd,
6147e2c6 1308 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1309 "Force initial delay for best-path and updates\n"
1310 "Seconds\n"
f188f2c4
DS
1311 "Seconds\n")
1312{
d62a17ae 1313 int idx_number = 1;
1314 int idx_number_2 = 2;
1315 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1316 argv[idx_number_2]->arg);
f188f2c4
DS
1317}
1318
1319/* Update-delay deconfiguration */
1320DEFUN (no_bgp_update_delay,
1321 no_bgp_update_delay_cmd,
838758ac
DW
1322 "no update-delay [(0-3600) [(1-3600)]]",
1323 NO_STR
f188f2c4 1324 "Force initial delay for best-path and updates\n"
838758ac 1325 "Seconds\n"
7111c1a0 1326 "Seconds\n")
f188f2c4 1327{
d62a17ae 1328 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1329}
1330
5e242b0d 1331
d62a17ae 1332static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1333 char set)
cb1faec9 1334{
d62a17ae 1335 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1336
d62a17ae 1337 if (set)
1338 bgp->wpkt_quanta = strtoul(num, NULL, 10);
1339 else
1340 bgp->wpkt_quanta = BGP_WRITE_PACKET_MAX;
cb1faec9 1341
d62a17ae 1342 return CMD_SUCCESS;
cb1faec9
DS
1343}
1344
d62a17ae 1345int bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1346{
d62a17ae 1347 if (bgp->wpkt_quanta != BGP_WRITE_PACKET_MAX)
1348 vty_out(vty, " write-quanta %d\n", bgp->wpkt_quanta);
cb1faec9 1349
d62a17ae 1350 return 0;
cb1faec9
DS
1351}
1352
1353
1354/* Update-delay configuration */
1355DEFUN (bgp_wpkt_quanta,
1356 bgp_wpkt_quanta_cmd,
6147e2c6 1357 "write-quanta (1-10000)",
cb1faec9
DS
1358 "How many packets to write to peer socket per run\n"
1359 "Number of packets\n")
1360{
d62a17ae 1361 int idx_number = 1;
1362 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1363}
1364
1365/* Update-delay deconfiguration */
1366DEFUN (no_bgp_wpkt_quanta,
1367 no_bgp_wpkt_quanta_cmd,
6147e2c6 1368 "no write-quanta (1-10000)",
d7fa34c1 1369 NO_STR
cb1faec9
DS
1370 "How many packets to write to peer socket per run\n"
1371 "Number of packets\n")
1372{
d62a17ae 1373 int idx_number = 2;
1374 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1375}
1376
d62a17ae 1377int bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1378{
d62a17ae 1379 if (bgp->coalesce_time != BGP_DEFAULT_SUBGROUP_COALESCE_TIME)
1380 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369 1381
d62a17ae 1382 return 0;
3f9c7369
DS
1383}
1384
1385
1386DEFUN (bgp_coalesce_time,
1387 bgp_coalesce_time_cmd,
6147e2c6 1388 "coalesce-time (0-4294967295)",
3f9c7369
DS
1389 "Subgroup coalesce timer\n"
1390 "Subgroup coalesce timer value (in ms)\n")
1391{
d62a17ae 1392 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1393
d62a17ae 1394 int idx = 0;
1395 argv_find(argv, argc, "(0-4294967295)", &idx);
1396 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1397 return CMD_SUCCESS;
3f9c7369
DS
1398}
1399
1400DEFUN (no_bgp_coalesce_time,
1401 no_bgp_coalesce_time_cmd,
6147e2c6 1402 "no coalesce-time (0-4294967295)",
3a2d747c 1403 NO_STR
3f9c7369
DS
1404 "Subgroup coalesce timer\n"
1405 "Subgroup coalesce timer value (in ms)\n")
1406{
d62a17ae 1407 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1408
d62a17ae 1409 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1410 return CMD_SUCCESS;
3f9c7369
DS
1411}
1412
5e242b0d
DS
1413/* Maximum-paths configuration */
1414DEFUN (bgp_maxpaths,
1415 bgp_maxpaths_cmd,
6319fd63 1416 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1417 "Forward packets over multiple paths\n"
1418 "Number of paths\n")
1419{
d62a17ae 1420 int idx_number = 1;
1421 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1422 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1423}
1424
d62a17ae 1425ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1426 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1427 "Forward packets over multiple paths\n"
1428 "Number of paths\n")
596c17ba 1429
165b5fff
JB
1430DEFUN (bgp_maxpaths_ibgp,
1431 bgp_maxpaths_ibgp_cmd,
6319fd63 1432 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1433 "Forward packets over multiple paths\n"
1434 "iBGP-multipath\n"
1435 "Number of paths\n")
1436{
d62a17ae 1437 int idx_number = 2;
1438 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1439 argv[idx_number]->arg, 0, 1);
5e242b0d 1440}
165b5fff 1441
d62a17ae 1442ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1443 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1444 "Forward packets over multiple paths\n"
1445 "iBGP-multipath\n"
1446 "Number of paths\n")
596c17ba 1447
5e242b0d
DS
1448DEFUN (bgp_maxpaths_ibgp_cluster,
1449 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1450 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1451 "Forward packets over multiple paths\n"
1452 "iBGP-multipath\n"
1453 "Number of paths\n"
1454 "Match the cluster length\n")
1455{
d62a17ae 1456 int idx_number = 2;
1457 return bgp_maxpaths_config_vty(
1458 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1459 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1460}
1461
d62a17ae 1462ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1463 "maximum-paths ibgp " CMD_RANGE_STR(
1464 1, MULTIPATH_NUM) " equal-cluster-length",
1465 "Forward packets over multiple paths\n"
1466 "iBGP-multipath\n"
1467 "Number of paths\n"
1468 "Match the cluster length\n")
596c17ba 1469
165b5fff
JB
1470DEFUN (no_bgp_maxpaths,
1471 no_bgp_maxpaths_cmd,
6319fd63 1472 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1473 NO_STR
1474 "Forward packets over multiple paths\n"
1475 "Number of paths\n")
1476{
d62a17ae 1477 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1478}
1479
d62a17ae 1480ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
9d303b37 1481 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1482 "Forward packets over multiple paths\n"
1483 "Number of paths\n")
596c17ba 1484
165b5fff
JB
1485DEFUN (no_bgp_maxpaths_ibgp,
1486 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1487 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1488 NO_STR
1489 "Forward packets over multiple paths\n"
1490 "iBGP-multipath\n"
838758ac
DW
1491 "Number of paths\n"
1492 "Match the cluster length\n")
165b5fff 1493{
d62a17ae 1494 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1495}
1496
d62a17ae 1497ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1498 "no maximum-paths ibgp [" CMD_RANGE_STR(
1499 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1500 NO_STR
1501 "Forward packets over multiple paths\n"
1502 "iBGP-multipath\n"
1503 "Number of paths\n"
1504 "Match the cluster length\n")
596c17ba 1505
d62a17ae 1506int bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
1507 safi_t safi, int *write)
165b5fff 1508{
d62a17ae 1509 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
1510 bgp_config_write_family_header(vty, afi, safi, write);
1511 vty_out(vty, " maximum-paths %d\n",
1512 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1513 }
165b5fff 1514
d62a17ae 1515 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
1516 bgp_config_write_family_header(vty, afi, safi, write);
1517 vty_out(vty, " maximum-paths ibgp %d",
1518 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1519 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1520 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1521 vty_out(vty, " equal-cluster-length");
1522 vty_out(vty, "\n");
1523 }
165b5fff 1524
d62a17ae 1525 return 0;
165b5fff 1526}
6b0655a2 1527
718e3744 1528/* BGP timers. */
1529
1530DEFUN (bgp_timers,
1531 bgp_timers_cmd,
6147e2c6 1532 "timers bgp (0-65535) (0-65535)",
718e3744 1533 "Adjust routing timers\n"
1534 "BGP timers\n"
1535 "Keepalive interval\n"
1536 "Holdtime\n")
1537{
d62a17ae 1538 VTY_DECLVAR_CONTEXT(bgp, bgp);
1539 int idx_number = 2;
1540 int idx_number_2 = 3;
1541 unsigned long keepalive = 0;
1542 unsigned long holdtime = 0;
718e3744 1543
d62a17ae 1544 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1545 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1546
d62a17ae 1547 /* Holdtime value check. */
1548 if (holdtime < 3 && holdtime != 0) {
1549 vty_out(vty,
1550 "%% hold time value must be either 0 or greater than 3\n");
1551 return CMD_WARNING_CONFIG_FAILED;
1552 }
718e3744 1553
d62a17ae 1554 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1555
d62a17ae 1556 return CMD_SUCCESS;
718e3744 1557}
1558
1559DEFUN (no_bgp_timers,
1560 no_bgp_timers_cmd,
838758ac 1561 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1562 NO_STR
1563 "Adjust routing timers\n"
838758ac
DW
1564 "BGP timers\n"
1565 "Keepalive interval\n"
1566 "Holdtime\n")
718e3744 1567{
d62a17ae 1568 VTY_DECLVAR_CONTEXT(bgp, bgp);
1569 bgp_timers_unset(bgp);
718e3744 1570
d62a17ae 1571 return CMD_SUCCESS;
718e3744 1572}
1573
6b0655a2 1574
718e3744 1575DEFUN (bgp_client_to_client_reflection,
1576 bgp_client_to_client_reflection_cmd,
1577 "bgp client-to-client reflection",
1578 "BGP specific commands\n"
1579 "Configure client to client route reflection\n"
1580 "reflection of routes allowed\n")
1581{
d62a17ae 1582 VTY_DECLVAR_CONTEXT(bgp, bgp);
1583 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1584 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1585
d62a17ae 1586 return CMD_SUCCESS;
718e3744 1587}
1588
1589DEFUN (no_bgp_client_to_client_reflection,
1590 no_bgp_client_to_client_reflection_cmd,
1591 "no bgp client-to-client reflection",
1592 NO_STR
1593 "BGP specific commands\n"
1594 "Configure client to client route reflection\n"
1595 "reflection of routes allowed\n")
1596{
d62a17ae 1597 VTY_DECLVAR_CONTEXT(bgp, bgp);
1598 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1599 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1600
d62a17ae 1601 return CMD_SUCCESS;
718e3744 1602}
1603
1604/* "bgp always-compare-med" configuration. */
1605DEFUN (bgp_always_compare_med,
1606 bgp_always_compare_med_cmd,
1607 "bgp always-compare-med",
1608 "BGP specific commands\n"
1609 "Allow comparing MED from different neighbors\n")
1610{
d62a17ae 1611 VTY_DECLVAR_CONTEXT(bgp, bgp);
1612 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1613 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1614
d62a17ae 1615 return CMD_SUCCESS;
718e3744 1616}
1617
1618DEFUN (no_bgp_always_compare_med,
1619 no_bgp_always_compare_med_cmd,
1620 "no bgp always-compare-med",
1621 NO_STR
1622 "BGP specific commands\n"
1623 "Allow comparing MED from different neighbors\n")
1624{
d62a17ae 1625 VTY_DECLVAR_CONTEXT(bgp, bgp);
1626 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1627 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1628
d62a17ae 1629 return CMD_SUCCESS;
718e3744 1630}
6b0655a2 1631
718e3744 1632/* "bgp deterministic-med" configuration. */
1633DEFUN (bgp_deterministic_med,
1634 bgp_deterministic_med_cmd,
1635 "bgp deterministic-med",
1636 "BGP specific commands\n"
1637 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1638{
d62a17ae 1639 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1640
d62a17ae 1641 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1642 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1643 bgp_recalculate_all_bestpaths(bgp);
1644 }
7aafcaca 1645
d62a17ae 1646 return CMD_SUCCESS;
718e3744 1647}
1648
1649DEFUN (no_bgp_deterministic_med,
1650 no_bgp_deterministic_med_cmd,
1651 "no bgp deterministic-med",
1652 NO_STR
1653 "BGP specific commands\n"
1654 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1655{
d62a17ae 1656 VTY_DECLVAR_CONTEXT(bgp, bgp);
1657 int bestpath_per_as_used;
1658 afi_t afi;
1659 safi_t safi;
1660 struct peer *peer;
1661 struct listnode *node, *nnode;
1662
1663 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1664 bestpath_per_as_used = 0;
1665
1666 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
1667 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1668 for (safi = SAFI_UNICAST; safi < SAFI_MAX;
1669 safi++)
1670 if (CHECK_FLAG(
1671 peer->af_flags[afi][safi],
1672 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1673 bestpath_per_as_used = 1;
1674 break;
1675 }
1676
1677 if (bestpath_per_as_used)
1678 break;
1679 }
1680
1681 if (bestpath_per_as_used) {
1682 vty_out(vty,
1683 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1684 return CMD_WARNING_CONFIG_FAILED;
1685 } else {
1686 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1687 bgp_recalculate_all_bestpaths(bgp);
1688 }
1689 }
1690
1691 return CMD_SUCCESS;
718e3744 1692}
538621f2 1693
1694/* "bgp graceful-restart" configuration. */
1695DEFUN (bgp_graceful_restart,
1696 bgp_graceful_restart_cmd,
1697 "bgp graceful-restart",
1698 "BGP specific commands\n"
1699 "Graceful restart capability parameters\n")
1700{
d62a17ae 1701 VTY_DECLVAR_CONTEXT(bgp, bgp);
1702 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1703 return CMD_SUCCESS;
538621f2 1704}
1705
1706DEFUN (no_bgp_graceful_restart,
1707 no_bgp_graceful_restart_cmd,
1708 "no bgp graceful-restart",
1709 NO_STR
1710 "BGP specific commands\n"
1711 "Graceful restart capability parameters\n")
1712{
d62a17ae 1713 VTY_DECLVAR_CONTEXT(bgp, bgp);
1714 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1715 return CMD_SUCCESS;
538621f2 1716}
1717
93406d87 1718DEFUN (bgp_graceful_restart_stalepath_time,
1719 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1720 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1721 "BGP specific commands\n"
1722 "Graceful restart capability parameters\n"
1723 "Set the max time to hold onto restarting peer's stale paths\n"
1724 "Delay value (seconds)\n")
1725{
d62a17ae 1726 VTY_DECLVAR_CONTEXT(bgp, bgp);
1727 int idx_number = 3;
1728 u_int32_t stalepath;
93406d87 1729
d62a17ae 1730 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1731 bgp->stalepath_time = stalepath;
1732 return CMD_SUCCESS;
93406d87 1733}
1734
eb6f1b41
PG
1735DEFUN (bgp_graceful_restart_restart_time,
1736 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1737 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1738 "BGP specific commands\n"
1739 "Graceful restart capability parameters\n"
1740 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1741 "Delay value (seconds)\n")
1742{
d62a17ae 1743 VTY_DECLVAR_CONTEXT(bgp, bgp);
1744 int idx_number = 3;
1745 u_int32_t restart;
eb6f1b41 1746
d62a17ae 1747 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1748 bgp->restart_time = restart;
1749 return CMD_SUCCESS;
eb6f1b41
PG
1750}
1751
93406d87 1752DEFUN (no_bgp_graceful_restart_stalepath_time,
1753 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1754 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1755 NO_STR
1756 "BGP specific commands\n"
1757 "Graceful restart capability parameters\n"
838758ac
DW
1758 "Set the max time to hold onto restarting peer's stale paths\n"
1759 "Delay value (seconds)\n")
93406d87 1760{
d62a17ae 1761 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1762
d62a17ae 1763 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1764 return CMD_SUCCESS;
93406d87 1765}
1766
eb6f1b41
PG
1767DEFUN (no_bgp_graceful_restart_restart_time,
1768 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1769 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1770 NO_STR
1771 "BGP specific commands\n"
1772 "Graceful restart capability parameters\n"
838758ac
DW
1773 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1774 "Delay value (seconds)\n")
eb6f1b41 1775{
d62a17ae 1776 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1777
d62a17ae 1778 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1779 return CMD_SUCCESS;
eb6f1b41
PG
1780}
1781
43fc21b3
JC
1782DEFUN (bgp_graceful_restart_preserve_fw,
1783 bgp_graceful_restart_preserve_fw_cmd,
1784 "bgp graceful-restart preserve-fw-state",
1785 "BGP specific commands\n"
1786 "Graceful restart capability parameters\n"
1787 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1788{
d62a17ae 1789 VTY_DECLVAR_CONTEXT(bgp, bgp);
1790 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1791 return CMD_SUCCESS;
43fc21b3
JC
1792}
1793
1794DEFUN (no_bgp_graceful_restart_preserve_fw,
1795 no_bgp_graceful_restart_preserve_fw_cmd,
1796 "no bgp graceful-restart preserve-fw-state",
1797 NO_STR
1798 "BGP specific commands\n"
1799 "Graceful restart capability parameters\n"
1800 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1801{
d62a17ae 1802 VTY_DECLVAR_CONTEXT(bgp, bgp);
1803 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1804 return CMD_SUCCESS;
43fc21b3
JC
1805}
1806
718e3744 1807/* "bgp fast-external-failover" configuration. */
1808DEFUN (bgp_fast_external_failover,
1809 bgp_fast_external_failover_cmd,
1810 "bgp fast-external-failover",
1811 BGP_STR
1812 "Immediately reset session if a link to a directly connected external peer goes down\n")
1813{
d62a17ae 1814 VTY_DECLVAR_CONTEXT(bgp, bgp);
1815 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1816 return CMD_SUCCESS;
718e3744 1817}
1818
1819DEFUN (no_bgp_fast_external_failover,
1820 no_bgp_fast_external_failover_cmd,
1821 "no bgp fast-external-failover",
1822 NO_STR
1823 BGP_STR
1824 "Immediately reset session if a link to a directly connected external peer goes down\n")
1825{
d62a17ae 1826 VTY_DECLVAR_CONTEXT(bgp, bgp);
1827 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1828 return CMD_SUCCESS;
718e3744 1829}
6b0655a2 1830
718e3744 1831/* "bgp enforce-first-as" configuration. */
1832DEFUN (bgp_enforce_first_as,
1833 bgp_enforce_first_as_cmd,
1834 "bgp enforce-first-as",
1835 BGP_STR
1836 "Enforce the first AS for EBGP routes\n")
1837{
d62a17ae 1838 VTY_DECLVAR_CONTEXT(bgp, bgp);
1839 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1840 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1841
d62a17ae 1842 return CMD_SUCCESS;
718e3744 1843}
1844
1845DEFUN (no_bgp_enforce_first_as,
1846 no_bgp_enforce_first_as_cmd,
1847 "no bgp enforce-first-as",
1848 NO_STR
1849 BGP_STR
1850 "Enforce the first AS for EBGP routes\n")
1851{
d62a17ae 1852 VTY_DECLVAR_CONTEXT(bgp, bgp);
1853 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1854 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1855
d62a17ae 1856 return CMD_SUCCESS;
718e3744 1857}
6b0655a2 1858
718e3744 1859/* "bgp bestpath compare-routerid" configuration. */
1860DEFUN (bgp_bestpath_compare_router_id,
1861 bgp_bestpath_compare_router_id_cmd,
1862 "bgp bestpath compare-routerid",
1863 "BGP specific commands\n"
1864 "Change the default bestpath selection\n"
1865 "Compare router-id for identical EBGP paths\n")
1866{
d62a17ae 1867 VTY_DECLVAR_CONTEXT(bgp, bgp);
1868 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1869 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1870
d62a17ae 1871 return CMD_SUCCESS;
718e3744 1872}
1873
1874DEFUN (no_bgp_bestpath_compare_router_id,
1875 no_bgp_bestpath_compare_router_id_cmd,
1876 "no bgp bestpath compare-routerid",
1877 NO_STR
1878 "BGP specific commands\n"
1879 "Change the default bestpath selection\n"
1880 "Compare router-id for identical EBGP paths\n")
1881{
d62a17ae 1882 VTY_DECLVAR_CONTEXT(bgp, bgp);
1883 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1884 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1885
d62a17ae 1886 return CMD_SUCCESS;
718e3744 1887}
6b0655a2 1888
718e3744 1889/* "bgp bestpath as-path ignore" configuration. */
1890DEFUN (bgp_bestpath_aspath_ignore,
1891 bgp_bestpath_aspath_ignore_cmd,
1892 "bgp bestpath as-path ignore",
1893 "BGP specific commands\n"
1894 "Change the default bestpath selection\n"
1895 "AS-path attribute\n"
1896 "Ignore as-path length in selecting a route\n")
1897{
d62a17ae 1898 VTY_DECLVAR_CONTEXT(bgp, bgp);
1899 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
1900 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1901
d62a17ae 1902 return CMD_SUCCESS;
718e3744 1903}
1904
1905DEFUN (no_bgp_bestpath_aspath_ignore,
1906 no_bgp_bestpath_aspath_ignore_cmd,
1907 "no bgp bestpath as-path ignore",
1908 NO_STR
1909 "BGP specific commands\n"
1910 "Change the default bestpath selection\n"
1911 "AS-path attribute\n"
1912 "Ignore as-path length in selecting a route\n")
1913{
d62a17ae 1914 VTY_DECLVAR_CONTEXT(bgp, bgp);
1915 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
1916 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1917
d62a17ae 1918 return CMD_SUCCESS;
718e3744 1919}
6b0655a2 1920
6811845b 1921/* "bgp bestpath as-path confed" configuration. */
1922DEFUN (bgp_bestpath_aspath_confed,
1923 bgp_bestpath_aspath_confed_cmd,
1924 "bgp bestpath as-path confed",
1925 "BGP specific commands\n"
1926 "Change the default bestpath selection\n"
1927 "AS-path attribute\n"
1928 "Compare path lengths including confederation sets & sequences in selecting a route\n")
1929{
d62a17ae 1930 VTY_DECLVAR_CONTEXT(bgp, bgp);
1931 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
1932 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1933
d62a17ae 1934 return CMD_SUCCESS;
6811845b 1935}
1936
1937DEFUN (no_bgp_bestpath_aspath_confed,
1938 no_bgp_bestpath_aspath_confed_cmd,
1939 "no bgp bestpath as-path confed",
1940 NO_STR
1941 "BGP specific commands\n"
1942 "Change the default bestpath selection\n"
1943 "AS-path attribute\n"
1944 "Compare path lengths including confederation sets & sequences in selecting a route\n")
1945{
d62a17ae 1946 VTY_DECLVAR_CONTEXT(bgp, bgp);
1947 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
1948 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1949
d62a17ae 1950 return CMD_SUCCESS;
6811845b 1951}
6b0655a2 1952
2fdd455c
PM
1953/* "bgp bestpath as-path multipath-relax" configuration. */
1954DEFUN (bgp_bestpath_aspath_multipath_relax,
1955 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 1956 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
1957 "BGP specific commands\n"
1958 "Change the default bestpath selection\n"
1959 "AS-path attribute\n"
1960 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 1961 "Generate an AS_SET\n"
16fc1eec
DS
1962 "Do not generate an AS_SET\n")
1963{
d62a17ae 1964 VTY_DECLVAR_CONTEXT(bgp, bgp);
1965 int idx = 0;
1966 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 1967
d62a17ae 1968 /* no-as-set is now the default behavior so we can silently
1969 * ignore it */
1970 if (argv_find(argv, argc, "as-set", &idx))
1971 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
1972 else
1973 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 1974
d62a17ae 1975 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1976
d62a17ae 1977 return CMD_SUCCESS;
16fc1eec
DS
1978}
1979
219178b6
DW
1980DEFUN (no_bgp_bestpath_aspath_multipath_relax,
1981 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 1982 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
1983 NO_STR
1984 "BGP specific commands\n"
1985 "Change the default bestpath selection\n"
1986 "AS-path attribute\n"
1987 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 1988 "Generate an AS_SET\n"
16fc1eec
DS
1989 "Do not generate an AS_SET\n")
1990{
d62a17ae 1991 VTY_DECLVAR_CONTEXT(bgp, bgp);
1992 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
1993 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
1994 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1995
d62a17ae 1996 return CMD_SUCCESS;
2fdd455c 1997}
6b0655a2 1998
848973c7 1999/* "bgp log-neighbor-changes" configuration. */
2000DEFUN (bgp_log_neighbor_changes,
2001 bgp_log_neighbor_changes_cmd,
2002 "bgp log-neighbor-changes",
2003 "BGP specific commands\n"
2004 "Log neighbor up/down and reset reason\n")
2005{
d62a17ae 2006 VTY_DECLVAR_CONTEXT(bgp, bgp);
2007 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2008 return CMD_SUCCESS;
848973c7 2009}
2010
2011DEFUN (no_bgp_log_neighbor_changes,
2012 no_bgp_log_neighbor_changes_cmd,
2013 "no bgp log-neighbor-changes",
2014 NO_STR
2015 "BGP specific commands\n"
2016 "Log neighbor up/down and reset reason\n")
2017{
d62a17ae 2018 VTY_DECLVAR_CONTEXT(bgp, bgp);
2019 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2020 return CMD_SUCCESS;
848973c7 2021}
6b0655a2 2022
718e3744 2023/* "bgp bestpath med" configuration. */
2024DEFUN (bgp_bestpath_med,
2025 bgp_bestpath_med_cmd,
2d8c1a4d 2026 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2027 "BGP specific commands\n"
2028 "Change the default bestpath selection\n"
2029 "MED attribute\n"
2030 "Compare MED among confederation paths\n"
838758ac
DW
2031 "Treat missing MED as the least preferred one\n"
2032 "Treat missing MED as the least preferred one\n"
2033 "Compare MED among confederation paths\n")
718e3744 2034{
d62a17ae 2035 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2036
d62a17ae 2037 int idx = 0;
2038 if (argv_find(argv, argc, "confed", &idx))
2039 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2040 idx = 0;
2041 if (argv_find(argv, argc, "missing-as-worst", &idx))
2042 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2043
d62a17ae 2044 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2045
d62a17ae 2046 return CMD_SUCCESS;
718e3744 2047}
2048
718e3744 2049DEFUN (no_bgp_bestpath_med,
2050 no_bgp_bestpath_med_cmd,
2d8c1a4d 2051 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2052 NO_STR
2053 "BGP specific commands\n"
2054 "Change the default bestpath selection\n"
2055 "MED attribute\n"
2056 "Compare MED among confederation paths\n"
3a2d747c
QY
2057 "Treat missing MED as the least preferred one\n"
2058 "Treat missing MED as the least preferred one\n"
2059 "Compare MED among confederation paths\n")
718e3744 2060{
d62a17ae 2061 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2062
d62a17ae 2063 int idx = 0;
2064 if (argv_find(argv, argc, "confed", &idx))
2065 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2066 idx = 0;
2067 if (argv_find(argv, argc, "missing-as-worst", &idx))
2068 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2069
d62a17ae 2070 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2071
d62a17ae 2072 return CMD_SUCCESS;
718e3744 2073}
2074
718e3744 2075/* "no bgp default ipv4-unicast". */
2076DEFUN (no_bgp_default_ipv4_unicast,
2077 no_bgp_default_ipv4_unicast_cmd,
2078 "no bgp default ipv4-unicast",
2079 NO_STR
2080 "BGP specific commands\n"
2081 "Configure BGP defaults\n"
2082 "Activate ipv4-unicast for a peer by default\n")
2083{
d62a17ae 2084 VTY_DECLVAR_CONTEXT(bgp, bgp);
2085 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2086 return CMD_SUCCESS;
718e3744 2087}
2088
2089DEFUN (bgp_default_ipv4_unicast,
2090 bgp_default_ipv4_unicast_cmd,
2091 "bgp default ipv4-unicast",
2092 "BGP specific commands\n"
2093 "Configure BGP defaults\n"
2094 "Activate ipv4-unicast for a peer by default\n")
2095{
d62a17ae 2096 VTY_DECLVAR_CONTEXT(bgp, bgp);
2097 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2098 return CMD_SUCCESS;
718e3744 2099}
6b0655a2 2100
04b6bdc0
DW
2101/* Display hostname in certain command outputs */
2102DEFUN (bgp_default_show_hostname,
2103 bgp_default_show_hostname_cmd,
2104 "bgp default show-hostname",
2105 "BGP specific commands\n"
2106 "Configure BGP defaults\n"
2107 "Show hostname in certain command ouputs\n")
2108{
d62a17ae 2109 VTY_DECLVAR_CONTEXT(bgp, bgp);
2110 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2111 return CMD_SUCCESS;
04b6bdc0
DW
2112}
2113
2114DEFUN (no_bgp_default_show_hostname,
2115 no_bgp_default_show_hostname_cmd,
2116 "no bgp default show-hostname",
2117 NO_STR
2118 "BGP specific commands\n"
2119 "Configure BGP defaults\n"
2120 "Show hostname in certain command ouputs\n")
2121{
d62a17ae 2122 VTY_DECLVAR_CONTEXT(bgp, bgp);
2123 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2124 return CMD_SUCCESS;
04b6bdc0
DW
2125}
2126
8233ef81 2127/* "bgp network import-check" configuration. */
718e3744 2128DEFUN (bgp_network_import_check,
2129 bgp_network_import_check_cmd,
5623e905 2130 "bgp network import-check",
718e3744 2131 "BGP specific commands\n"
2132 "BGP network command\n"
5623e905 2133 "Check BGP network route exists in IGP\n")
718e3744 2134{
d62a17ae 2135 VTY_DECLVAR_CONTEXT(bgp, bgp);
2136 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2137 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2138 bgp_static_redo_import_check(bgp);
2139 }
078430f6 2140
d62a17ae 2141 return CMD_SUCCESS;
718e3744 2142}
2143
d62a17ae 2144ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2145 "bgp network import-check exact",
2146 "BGP specific commands\n"
2147 "BGP network command\n"
2148 "Check BGP network route exists in IGP\n"
2149 "Match route precisely\n")
8233ef81 2150
718e3744 2151DEFUN (no_bgp_network_import_check,
2152 no_bgp_network_import_check_cmd,
5623e905 2153 "no bgp network import-check",
718e3744 2154 NO_STR
2155 "BGP specific commands\n"
2156 "BGP network command\n"
2157 "Check BGP network route exists in IGP\n")
2158{
d62a17ae 2159 VTY_DECLVAR_CONTEXT(bgp, bgp);
2160 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2161 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2162 bgp_static_redo_import_check(bgp);
2163 }
5623e905 2164
d62a17ae 2165 return CMD_SUCCESS;
718e3744 2166}
6b0655a2 2167
718e3744 2168DEFUN (bgp_default_local_preference,
2169 bgp_default_local_preference_cmd,
6147e2c6 2170 "bgp default local-preference (0-4294967295)",
718e3744 2171 "BGP specific commands\n"
2172 "Configure BGP defaults\n"
2173 "local preference (higher=more preferred)\n"
2174 "Configure default local preference value\n")
2175{
d62a17ae 2176 VTY_DECLVAR_CONTEXT(bgp, bgp);
2177 int idx_number = 3;
2178 u_int32_t local_pref;
718e3744 2179
d62a17ae 2180 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2181
d62a17ae 2182 bgp_default_local_preference_set(bgp, local_pref);
2183 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2184
d62a17ae 2185 return CMD_SUCCESS;
718e3744 2186}
2187
2188DEFUN (no_bgp_default_local_preference,
2189 no_bgp_default_local_preference_cmd,
838758ac 2190 "no bgp default local-preference [(0-4294967295)]",
718e3744 2191 NO_STR
2192 "BGP specific commands\n"
2193 "Configure BGP defaults\n"
838758ac
DW
2194 "local preference (higher=more preferred)\n"
2195 "Configure default local preference value\n")
718e3744 2196{
d62a17ae 2197 VTY_DECLVAR_CONTEXT(bgp, bgp);
2198 bgp_default_local_preference_unset(bgp);
2199 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2200
d62a17ae 2201 return CMD_SUCCESS;
718e3744 2202}
2203
6b0655a2 2204
3f9c7369
DS
2205DEFUN (bgp_default_subgroup_pkt_queue_max,
2206 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2207 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2208 "BGP specific commands\n"
2209 "Configure BGP defaults\n"
2210 "subgroup-pkt-queue-max\n"
2211 "Configure subgroup packet queue max\n")
8bd9d948 2212{
d62a17ae 2213 VTY_DECLVAR_CONTEXT(bgp, bgp);
2214 int idx_number = 3;
2215 u_int32_t max_size;
8bd9d948 2216
d62a17ae 2217 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2218
d62a17ae 2219 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2220
d62a17ae 2221 return CMD_SUCCESS;
3f9c7369
DS
2222}
2223
2224DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2225 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2226 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2227 NO_STR
2228 "BGP specific commands\n"
2229 "Configure BGP defaults\n"
838758ac
DW
2230 "subgroup-pkt-queue-max\n"
2231 "Configure subgroup packet queue max\n")
3f9c7369 2232{
d62a17ae 2233 VTY_DECLVAR_CONTEXT(bgp, bgp);
2234 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2235 return CMD_SUCCESS;
8bd9d948
DS
2236}
2237
813d4307 2238
8bd9d948
DS
2239DEFUN (bgp_rr_allow_outbound_policy,
2240 bgp_rr_allow_outbound_policy_cmd,
2241 "bgp route-reflector allow-outbound-policy",
2242 "BGP specific commands\n"
2243 "Allow modifications made by out route-map\n"
2244 "on ibgp neighbors\n")
2245{
d62a17ae 2246 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2247
d62a17ae 2248 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2249 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2250 update_group_announce_rrclients(bgp);
2251 bgp_clear_star_soft_out(vty, bgp->name);
2252 }
8bd9d948 2253
d62a17ae 2254 return CMD_SUCCESS;
8bd9d948
DS
2255}
2256
2257DEFUN (no_bgp_rr_allow_outbound_policy,
2258 no_bgp_rr_allow_outbound_policy_cmd,
2259 "no bgp route-reflector allow-outbound-policy",
2260 NO_STR
2261 "BGP specific commands\n"
2262 "Allow modifications made by out route-map\n"
2263 "on ibgp neighbors\n")
2264{
d62a17ae 2265 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2266
d62a17ae 2267 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2268 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2269 update_group_announce_rrclients(bgp);
2270 bgp_clear_star_soft_out(vty, bgp->name);
2271 }
8bd9d948 2272
d62a17ae 2273 return CMD_SUCCESS;
8bd9d948
DS
2274}
2275
f14e6fdb
DS
2276DEFUN (bgp_listen_limit,
2277 bgp_listen_limit_cmd,
9ccf14f7 2278 "bgp listen limit (1-5000)",
f14e6fdb
DS
2279 "BGP specific commands\n"
2280 "Configure BGP defaults\n"
2281 "maximum number of BGP Dynamic Neighbors that can be created\n"
2282 "Configure Dynamic Neighbors listen limit value\n")
2283{
d62a17ae 2284 VTY_DECLVAR_CONTEXT(bgp, bgp);
2285 int idx_number = 3;
2286 int listen_limit;
f14e6fdb 2287
d62a17ae 2288 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2289
d62a17ae 2290 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2291
d62a17ae 2292 return CMD_SUCCESS;
f14e6fdb
DS
2293}
2294
2295DEFUN (no_bgp_listen_limit,
2296 no_bgp_listen_limit_cmd,
838758ac 2297 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2298 "BGP specific commands\n"
2299 "Configure BGP defaults\n"
2300 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2301 "Configure Dynamic Neighbors listen limit value to default\n"
2302 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2303{
d62a17ae 2304 VTY_DECLVAR_CONTEXT(bgp, bgp);
2305 bgp_listen_limit_unset(bgp);
2306 return CMD_SUCCESS;
f14e6fdb
DS
2307}
2308
2309
20eb8864 2310/*
2311 * Check if this listen range is already configured. Check for exact
2312 * match or overlap based on input.
2313 */
d62a17ae 2314static struct peer_group *listen_range_exists(struct bgp *bgp,
2315 struct prefix *range, int exact)
2316{
2317 struct listnode *node, *nnode;
2318 struct listnode *node1, *nnode1;
2319 struct peer_group *group;
2320 struct prefix *lr;
2321 afi_t afi;
2322 int match;
2323
2324 afi = family2afi(range->family);
2325 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2326 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2327 lr)) {
2328 if (exact)
2329 match = prefix_same(range, lr);
2330 else
2331 match = (prefix_match(range, lr)
2332 || prefix_match(lr, range));
2333 if (match)
2334 return group;
2335 }
2336 }
2337
2338 return NULL;
20eb8864 2339}
2340
f14e6fdb
DS
2341DEFUN (bgp_listen_range,
2342 bgp_listen_range_cmd,
9ccf14f7 2343 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2344 "BGP specific commands\n"
d7fa34c1
QY
2345 "Configure BGP dynamic neighbors listen range\n"
2346 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2347 NEIGHBOR_ADDR_STR
2348 "Member of the peer-group\n"
2349 "Peer-group name\n")
f14e6fdb 2350{
d62a17ae 2351 VTY_DECLVAR_CONTEXT(bgp, bgp);
2352 struct prefix range;
2353 struct peer_group *group, *existing_group;
2354 afi_t afi;
2355 int ret;
2356 int idx = 0;
2357
2358 argv_find(argv, argc, "A.B.C.D/M", &idx);
2359 argv_find(argv, argc, "X:X::X:X/M", &idx);
2360 char *prefix = argv[idx]->arg;
2361 argv_find(argv, argc, "WORD", &idx);
2362 char *peergroup = argv[idx]->arg;
2363
2364 /* Convert IP prefix string to struct prefix. */
2365 ret = str2prefix(prefix, &range);
2366 if (!ret) {
2367 vty_out(vty, "%% Malformed listen range\n");
2368 return CMD_WARNING_CONFIG_FAILED;
2369 }
2370
2371 afi = family2afi(range.family);
2372
2373 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2374 vty_out(vty,
2375 "%% Malformed listen range (link-local address)\n");
2376 return CMD_WARNING_CONFIG_FAILED;
2377 }
2378
2379 apply_mask(&range);
2380
2381 /* Check if same listen range is already configured. */
2382 existing_group = listen_range_exists(bgp, &range, 1);
2383 if (existing_group) {
2384 if (strcmp(existing_group->name, peergroup) == 0)
2385 return CMD_SUCCESS;
2386 else {
2387 vty_out(vty,
2388 "%% Same listen range is attached to peer-group %s\n",
2389 existing_group->name);
2390 return CMD_WARNING_CONFIG_FAILED;
2391 }
2392 }
2393
2394 /* Check if an overlapping listen range exists. */
2395 if (listen_range_exists(bgp, &range, 0)) {
2396 vty_out(vty,
2397 "%% Listen range overlaps with existing listen range\n");
2398 return CMD_WARNING_CONFIG_FAILED;
2399 }
2400
2401 group = peer_group_lookup(bgp, peergroup);
2402 if (!group) {
2403 vty_out(vty, "%% Configure the peer-group first\n");
2404 return CMD_WARNING_CONFIG_FAILED;
2405 }
2406
2407 ret = peer_group_listen_range_add(group, &range);
2408 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2409}
2410
2411DEFUN (no_bgp_listen_range,
2412 no_bgp_listen_range_cmd,
d7fa34c1
QY
2413 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2414 NO_STR
f14e6fdb 2415 "BGP specific commands\n"
d7fa34c1
QY
2416 "Unconfigure BGP dynamic neighbors listen range\n"
2417 "Unconfigure BGP dynamic neighbors listen range\n"
2418 NEIGHBOR_ADDR_STR
2419 "Member of the peer-group\n"
2420 "Peer-group name\n")
f14e6fdb 2421{
d62a17ae 2422 VTY_DECLVAR_CONTEXT(bgp, bgp);
2423 struct prefix range;
2424 struct peer_group *group;
2425 afi_t afi;
2426 int ret;
2427 int idx = 0;
2428
2429 argv_find(argv, argc, "A.B.C.D/M", &idx);
2430 argv_find(argv, argc, "X:X::X:X/M", &idx);
2431 char *prefix = argv[idx]->arg;
2432 argv_find(argv, argc, "WORD", &idx);
2433 char *peergroup = argv[idx]->arg;
2434
2435 /* Convert IP prefix string to struct prefix. */
2436 ret = str2prefix(prefix, &range);
2437 if (!ret) {
2438 vty_out(vty, "%% Malformed listen range\n");
2439 return CMD_WARNING_CONFIG_FAILED;
2440 }
2441
2442 afi = family2afi(range.family);
2443
2444 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2445 vty_out(vty,
2446 "%% Malformed listen range (link-local address)\n");
2447 return CMD_WARNING_CONFIG_FAILED;
2448 }
2449
2450 apply_mask(&range);
2451
2452 group = peer_group_lookup(bgp, peergroup);
2453 if (!group) {
2454 vty_out(vty, "%% Peer-group does not exist\n");
2455 return CMD_WARNING_CONFIG_FAILED;
2456 }
2457
2458 ret = peer_group_listen_range_del(group, &range);
2459 return bgp_vty_return(vty, ret);
2460}
2461
2462int bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
2463{
2464 struct peer_group *group;
2465 struct listnode *node, *nnode, *rnode, *nrnode;
2466 struct prefix *range;
2467 afi_t afi;
2468 char buf[PREFIX2STR_BUFFER];
2469
2470 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2471 vty_out(vty, " bgp listen limit %d\n",
2472 bgp->dynamic_neighbors_limit);
2473
2474 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2475 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2476 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2477 nrnode, range)) {
2478 prefix2str(range, buf, sizeof(buf));
2479 vty_out(vty,
2480 " bgp listen range %s peer-group %s\n",
2481 buf, group->name);
2482 }
2483 }
2484 }
2485
2486 return 0;
f14e6fdb
DS
2487}
2488
2489
907f92c8
DS
2490DEFUN (bgp_disable_connected_route_check,
2491 bgp_disable_connected_route_check_cmd,
2492 "bgp disable-ebgp-connected-route-check",
2493 "BGP specific commands\n"
2494 "Disable checking if nexthop is connected on ebgp sessions\n")
2495{
d62a17ae 2496 VTY_DECLVAR_CONTEXT(bgp, bgp);
2497 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2498 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2499
d62a17ae 2500 return CMD_SUCCESS;
907f92c8
DS
2501}
2502
2503DEFUN (no_bgp_disable_connected_route_check,
2504 no_bgp_disable_connected_route_check_cmd,
2505 "no bgp disable-ebgp-connected-route-check",
2506 NO_STR
2507 "BGP specific commands\n"
2508 "Disable checking if nexthop is connected on ebgp sessions\n")
2509{
d62a17ae 2510 VTY_DECLVAR_CONTEXT(bgp, bgp);
2511 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2512 bgp_clear_star_soft_in(vty, bgp->name);
2513
2514 return CMD_SUCCESS;
2515}
2516
2517
2518static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2519 const char *as_str, afi_t afi, safi_t safi)
2520{
2521 VTY_DECLVAR_CONTEXT(bgp, bgp);
2522 int ret;
2523 as_t as;
2524 int as_type = AS_SPECIFIED;
2525 union sockunion su;
2526
2527 if (as_str[0] == 'i') {
2528 as = 0;
2529 as_type = AS_INTERNAL;
2530 } else if (as_str[0] == 'e') {
2531 as = 0;
2532 as_type = AS_EXTERNAL;
2533 } else {
2534 /* Get AS number. */
2535 as = strtoul(as_str, NULL, 10);
2536 }
2537
2538 /* If peer is peer group, call proper function. */
2539 ret = str2sockunion(peer_str, &su);
2540 if (ret < 0) {
2541 /* Check for peer by interface */
2542 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2543 safi);
2544 if (ret < 0) {
2545 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2546 if (ret < 0) {
2547 vty_out(vty,
2548 "%% Create the peer-group or interface first\n");
2549 return CMD_WARNING_CONFIG_FAILED;
2550 }
2551 return CMD_SUCCESS;
2552 }
2553 } else {
2554 if (peer_address_self_check(bgp, &su)) {
2555 vty_out(vty,
2556 "%% Can not configure the local system as neighbor\n");
2557 return CMD_WARNING_CONFIG_FAILED;
2558 }
2559 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2560 }
2561
2562 /* This peer belongs to peer group. */
2563 switch (ret) {
2564 case BGP_ERR_PEER_GROUP_MEMBER:
2565 vty_out(vty,
2566 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2567 as);
2568 return CMD_WARNING_CONFIG_FAILED;
2569 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2570 vty_out(vty,
2571 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2572 as, as_str);
2573 return CMD_WARNING_CONFIG_FAILED;
2574 }
2575 return bgp_vty_return(vty, ret);
718e3744 2576}
2577
2578DEFUN (neighbor_remote_as,
2579 neighbor_remote_as_cmd,
3a2d747c 2580 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2581 NEIGHBOR_STR
2582 NEIGHBOR_ADDR_STR2
2583 "Specify a BGP neighbor\n"
d7fa34c1 2584 AS_STR
3a2d747c
QY
2585 "Internal BGP peer\n"
2586 "External BGP peer\n")
718e3744 2587{
d62a17ae 2588 int idx_peer = 1;
2589 int idx_remote_as = 3;
2590 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2591 argv[idx_remote_as]->arg, AFI_IP,
2592 SAFI_UNICAST);
2593}
2594
2595static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2596 afi_t afi, safi_t safi, int v6only,
2597 const char *peer_group_name,
2598 const char *as_str)
2599{
2600 VTY_DECLVAR_CONTEXT(bgp, bgp);
2601 as_t as = 0;
2602 int as_type = AS_UNSPECIFIED;
2603 struct peer *peer;
2604 struct peer_group *group;
2605 int ret = 0;
2606 union sockunion su;
2607
2608 group = peer_group_lookup(bgp, conf_if);
2609
2610 if (group) {
2611 vty_out(vty, "%% Name conflict with peer-group \n");
2612 return CMD_WARNING_CONFIG_FAILED;
2613 }
2614
2615 if (as_str) {
2616 if (as_str[0] == 'i') {
2617 as_type = AS_INTERNAL;
2618 } else if (as_str[0] == 'e') {
2619 as_type = AS_EXTERNAL;
2620 } else {
2621 /* Get AS number. */
2622 as = strtoul(as_str, NULL, 10);
2623 as_type = AS_SPECIFIED;
2624 }
2625 }
2626
2627 peer = peer_lookup_by_conf_if(bgp, conf_if);
2628 if (peer) {
2629 if (as_str)
2630 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2631 afi, safi);
2632 } else {
2633 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2634 && afi == AFI_IP && safi == SAFI_UNICAST)
2635 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2636 as_type, 0, 0, NULL);
2637 else
2638 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2639 as_type, afi, safi, NULL);
2640
2641 if (!peer) {
2642 vty_out(vty, "%% BGP failed to create peer\n");
2643 return CMD_WARNING_CONFIG_FAILED;
2644 }
2645
2646 if (v6only)
2647 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2648
2649 /* Request zebra to initiate IPv6 RAs on this interface. We do
2650 * this
2651 * any unnumbered peer in order to not worry about run-time
2652 * transitions
2653 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2654 * address
2655 * gets deleted later etc.)
2656 */
2657 if (peer->ifp)
2658 bgp_zebra_initiate_radv(bgp, peer);
2659 }
2660
2661 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2662 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2663 if (v6only)
2664 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2665 else
2666 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2667
2668 /* v6only flag changed. Reset bgp seesion */
2669 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2670 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2671 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2672 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2673 } else
2674 bgp_session_reset(peer);
2675 }
2676
2677 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2678 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2679
2680 if (peer_group_name) {
2681 group = peer_group_lookup(bgp, peer_group_name);
2682 if (!group) {
2683 vty_out(vty, "%% Configure the peer-group first\n");
2684 return CMD_WARNING_CONFIG_FAILED;
2685 }
2686
2687 ret = peer_group_bind(bgp, &su, peer, group, &as);
2688 }
2689
2690 return bgp_vty_return(vty, ret);
a80beece
DS
2691}
2692
4c48cf63
DW
2693DEFUN (neighbor_interface_config,
2694 neighbor_interface_config_cmd,
31500417 2695 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2696 NEIGHBOR_STR
2697 "Interface name or neighbor tag\n"
31500417
DW
2698 "Enable BGP on interface\n"
2699 "Member of the peer-group\n"
16cedbb0 2700 "Peer-group name\n")
4c48cf63 2701{
d62a17ae 2702 int idx_word = 1;
2703 int idx_peer_group_word = 4;
31500417 2704
d62a17ae 2705 if (argc > idx_peer_group_word)
2706 return peer_conf_interface_get(
2707 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2708 argv[idx_peer_group_word]->arg, NULL);
2709 else
2710 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2711 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2712}
2713
4c48cf63
DW
2714DEFUN (neighbor_interface_config_v6only,
2715 neighbor_interface_config_v6only_cmd,
31500417 2716 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2717 NEIGHBOR_STR
2718 "Interface name or neighbor tag\n"
2719 "Enable BGP on interface\n"
31500417
DW
2720 "Enable BGP with v6 link-local only\n"
2721 "Member of the peer-group\n"
16cedbb0 2722 "Peer-group name\n")
4c48cf63 2723{
d62a17ae 2724 int idx_word = 1;
2725 int idx_peer_group_word = 5;
31500417 2726
d62a17ae 2727 if (argc > idx_peer_group_word)
2728 return peer_conf_interface_get(
2729 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2730 argv[idx_peer_group_word]->arg, NULL);
31500417 2731
d62a17ae 2732 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2733 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2734}
2735
a80beece 2736
b3a39dc5
DD
2737DEFUN (neighbor_interface_config_remote_as,
2738 neighbor_interface_config_remote_as_cmd,
3a2d747c 2739 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2740 NEIGHBOR_STR
2741 "Interface name or neighbor tag\n"
2742 "Enable BGP on interface\n"
3a2d747c 2743 "Specify a BGP neighbor\n"
d7fa34c1 2744 AS_STR
3a2d747c
QY
2745 "Internal BGP peer\n"
2746 "External BGP peer\n")
b3a39dc5 2747{
d62a17ae 2748 int idx_word = 1;
2749 int idx_remote_as = 4;
2750 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2751 SAFI_UNICAST, 0, NULL,
2752 argv[idx_remote_as]->arg);
b3a39dc5
DD
2753}
2754
2755DEFUN (neighbor_interface_v6only_config_remote_as,
2756 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2757 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2758 NEIGHBOR_STR
2759 "Interface name or neighbor tag\n"
3a2d747c 2760 "Enable BGP with v6 link-local only\n"
b3a39dc5 2761 "Enable BGP on interface\n"
3a2d747c 2762 "Specify a BGP neighbor\n"
d7fa34c1 2763 AS_STR
3a2d747c
QY
2764 "Internal BGP peer\n"
2765 "External BGP peer\n")
b3a39dc5 2766{
d62a17ae 2767 int idx_word = 1;
2768 int idx_remote_as = 5;
2769 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2770 SAFI_UNICAST, 1, NULL,
2771 argv[idx_remote_as]->arg);
b3a39dc5
DD
2772}
2773
718e3744 2774DEFUN (neighbor_peer_group,
2775 neighbor_peer_group_cmd,
2776 "neighbor WORD peer-group",
2777 NEIGHBOR_STR
a80beece 2778 "Interface name or neighbor tag\n"
718e3744 2779 "Configure peer-group\n")
2780{
d62a17ae 2781 VTY_DECLVAR_CONTEXT(bgp, bgp);
2782 int idx_word = 1;
2783 struct peer *peer;
2784 struct peer_group *group;
718e3744 2785
d62a17ae 2786 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2787 if (peer) {
2788 vty_out(vty, "%% Name conflict with interface: \n");
2789 return CMD_WARNING_CONFIG_FAILED;
2790 }
718e3744 2791
d62a17ae 2792 group = peer_group_get(bgp, argv[idx_word]->arg);
2793 if (!group) {
2794 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2795 return CMD_WARNING_CONFIG_FAILED;
2796 }
718e3744 2797
d62a17ae 2798 return CMD_SUCCESS;
718e3744 2799}
2800
2801DEFUN (no_neighbor,
2802 no_neighbor_cmd,
dab8cd00 2803 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2804 NO_STR
2805 NEIGHBOR_STR
3a2d747c
QY
2806 NEIGHBOR_ADDR_STR2
2807 "Specify a BGP neighbor\n"
2808 AS_STR
2809 "Internal BGP peer\n"
2810 "External BGP peer\n")
718e3744 2811{
d62a17ae 2812 VTY_DECLVAR_CONTEXT(bgp, bgp);
2813 int idx_peer = 2;
2814 int ret;
2815 union sockunion su;
2816 struct peer_group *group;
2817 struct peer *peer;
2818 struct peer *other;
2819
2820 ret = str2sockunion(argv[idx_peer]->arg, &su);
2821 if (ret < 0) {
2822 /* look up for neighbor by interface name config. */
2823 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2824 if (peer) {
2825 /* Request zebra to terminate IPv6 RAs on this
2826 * interface. */
2827 if (peer->ifp)
2828 bgp_zebra_terminate_radv(peer->bgp, peer);
2829 peer_delete(peer);
2830 return CMD_SUCCESS;
2831 }
f14e6fdb 2832
d62a17ae 2833 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2834 if (group)
2835 peer_group_delete(group);
2836 else {
2837 vty_out(vty, "%% Create the peer-group first\n");
2838 return CMD_WARNING_CONFIG_FAILED;
2839 }
2840 } else {
2841 peer = peer_lookup(bgp, &su);
2842 if (peer) {
2843 if (peer_dynamic_neighbor(peer)) {
2844 vty_out(vty,
2845 "%% Operation not allowed on a dynamic neighbor\n");
2846 return CMD_WARNING_CONFIG_FAILED;
2847 }
2848
2849 other = peer->doppelganger;
2850 peer_delete(peer);
2851 if (other && other->status != Deleted)
2852 peer_delete(other);
2853 }
1ff9a340 2854 }
718e3744 2855
d62a17ae 2856 return CMD_SUCCESS;
718e3744 2857}
2858
a80beece
DS
2859DEFUN (no_neighbor_interface_config,
2860 no_neighbor_interface_config_cmd,
31500417 2861 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
2862 NO_STR
2863 NEIGHBOR_STR
2864 "Interface name\n"
31500417
DW
2865 "Configure BGP on interface\n"
2866 "Enable BGP with v6 link-local only\n"
2867 "Member of the peer-group\n"
16cedbb0 2868 "Peer-group name\n"
3a2d747c
QY
2869 "Specify a BGP neighbor\n"
2870 AS_STR
2871 "Internal BGP peer\n"
2872 "External BGP peer\n")
a80beece 2873{
d62a17ae 2874 VTY_DECLVAR_CONTEXT(bgp, bgp);
2875 int idx_word = 2;
2876 struct peer *peer;
2877
2878 /* look up for neighbor by interface name config. */
2879 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2880 if (peer) {
2881 /* Request zebra to terminate IPv6 RAs on this interface. */
2882 if (peer->ifp)
2883 bgp_zebra_terminate_radv(peer->bgp, peer);
2884 peer_delete(peer);
2885 } else {
2886 vty_out(vty, "%% Create the bgp interface first\n");
2887 return CMD_WARNING_CONFIG_FAILED;
2888 }
2889 return CMD_SUCCESS;
a80beece
DS
2890}
2891
718e3744 2892DEFUN (no_neighbor_peer_group,
2893 no_neighbor_peer_group_cmd,
2894 "no neighbor WORD peer-group",
2895 NO_STR
2896 NEIGHBOR_STR
2897 "Neighbor tag\n"
2898 "Configure peer-group\n")
2899{
d62a17ae 2900 VTY_DECLVAR_CONTEXT(bgp, bgp);
2901 int idx_word = 2;
2902 struct peer_group *group;
718e3744 2903
d62a17ae 2904 group = peer_group_lookup(bgp, argv[idx_word]->arg);
2905 if (group)
2906 peer_group_delete(group);
2907 else {
2908 vty_out(vty, "%% Create the peer-group first\n");
2909 return CMD_WARNING_CONFIG_FAILED;
2910 }
2911 return CMD_SUCCESS;
718e3744 2912}
2913
a80beece
DS
2914DEFUN (no_neighbor_interface_peer_group_remote_as,
2915 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 2916 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 2917 NO_STR
2918 NEIGHBOR_STR
a80beece 2919 "Interface name or neighbor tag\n"
718e3744 2920 "Specify a BGP neighbor\n"
3a2d747c
QY
2921 AS_STR
2922 "Internal BGP peer\n"
2923 "External BGP peer\n")
718e3744 2924{
d62a17ae 2925 VTY_DECLVAR_CONTEXT(bgp, bgp);
2926 int idx_word = 2;
2927 struct peer_group *group;
2928 struct peer *peer;
2929
2930 /* look up for neighbor by interface name config. */
2931 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2932 if (peer) {
2933 peer_as_change(peer, 0, AS_SPECIFIED);
2934 return CMD_SUCCESS;
2935 }
2936
2937 group = peer_group_lookup(bgp, argv[idx_word]->arg);
2938 if (group)
2939 peer_group_remote_as_delete(group);
2940 else {
2941 vty_out(vty, "%% Create the peer-group or interface first\n");
2942 return CMD_WARNING_CONFIG_FAILED;
2943 }
2944 return CMD_SUCCESS;
718e3744 2945}
6b0655a2 2946
718e3744 2947DEFUN (neighbor_local_as,
2948 neighbor_local_as_cmd,
9ccf14f7 2949 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 2950 NEIGHBOR_STR
2951 NEIGHBOR_ADDR_STR2
2952 "Specify a local-as number\n"
2953 "AS number used as local AS\n")
2954{
d62a17ae 2955 int idx_peer = 1;
2956 int idx_number = 3;
2957 struct peer *peer;
2958 int ret;
2959 as_t as;
718e3744 2960
d62a17ae 2961 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2962 if (!peer)
2963 return CMD_WARNING_CONFIG_FAILED;
718e3744 2964
d62a17ae 2965 as = strtoul(argv[idx_number]->arg, NULL, 10);
2966 ret = peer_local_as_set(peer, as, 0, 0);
2967 return bgp_vty_return(vty, ret);
718e3744 2968}
2969
2970DEFUN (neighbor_local_as_no_prepend,
2971 neighbor_local_as_no_prepend_cmd,
9ccf14f7 2972 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 2973 NEIGHBOR_STR
2974 NEIGHBOR_ADDR_STR2
2975 "Specify a local-as number\n"
2976 "AS number used as local AS\n"
2977 "Do not prepend local-as to updates from ebgp peers\n")
2978{
d62a17ae 2979 int idx_peer = 1;
2980 int idx_number = 3;
2981 struct peer *peer;
2982 int ret;
2983 as_t as;
718e3744 2984
d62a17ae 2985 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
2986 if (!peer)
2987 return CMD_WARNING_CONFIG_FAILED;
718e3744 2988
d62a17ae 2989 as = strtoul(argv[idx_number]->arg, NULL, 10);
2990 ret = peer_local_as_set(peer, as, 1, 0);
2991 return bgp_vty_return(vty, ret);
718e3744 2992}
2993
9d3f9705
AC
2994DEFUN (neighbor_local_as_no_prepend_replace_as,
2995 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 2996 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
2997 NEIGHBOR_STR
2998 NEIGHBOR_ADDR_STR2
2999 "Specify a local-as number\n"
3000 "AS number used as local AS\n"
3001 "Do not prepend local-as to updates from ebgp peers\n"
3002 "Do not prepend local-as to updates from ibgp peers\n")
3003{
d62a17ae 3004 int idx_peer = 1;
3005 int idx_number = 3;
3006 struct peer *peer;
3007 int ret;
3008 as_t as;
9d3f9705 3009
d62a17ae 3010 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3011 if (!peer)
3012 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3013
d62a17ae 3014 as = strtoul(argv[idx_number]->arg, NULL, 10);
3015 ret = peer_local_as_set(peer, as, 1, 1);
3016 return bgp_vty_return(vty, ret);
9d3f9705
AC
3017}
3018
718e3744 3019DEFUN (no_neighbor_local_as,
3020 no_neighbor_local_as_cmd,
a636c635 3021 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3022 NO_STR
3023 NEIGHBOR_STR
3024 NEIGHBOR_ADDR_STR2
a636c635
DW
3025 "Specify a local-as number\n"
3026 "AS number used as local AS\n"
3027 "Do not prepend local-as to updates from ebgp peers\n"
3028 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3029{
d62a17ae 3030 int idx_peer = 2;
3031 struct peer *peer;
3032 int ret;
718e3744 3033
d62a17ae 3034 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3035 if (!peer)
3036 return CMD_WARNING_CONFIG_FAILED;
718e3744 3037
d62a17ae 3038 ret = peer_local_as_unset(peer);
3039 return bgp_vty_return(vty, ret);
718e3744 3040}
3041
718e3744 3042
3f9c7369
DS
3043DEFUN (neighbor_solo,
3044 neighbor_solo_cmd,
9ccf14f7 3045 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3046 NEIGHBOR_STR
3047 NEIGHBOR_ADDR_STR2
3048 "Solo peer - part of its own update group\n")
3049{
d62a17ae 3050 int idx_peer = 1;
3051 struct peer *peer;
3052 int ret;
3f9c7369 3053
d62a17ae 3054 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3055 if (!peer)
3056 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3057
d62a17ae 3058 ret = update_group_adjust_soloness(peer, 1);
3059 return bgp_vty_return(vty, ret);
3f9c7369
DS
3060}
3061
3062DEFUN (no_neighbor_solo,
3063 no_neighbor_solo_cmd,
9ccf14f7 3064 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3065 NO_STR
3066 NEIGHBOR_STR
3067 NEIGHBOR_ADDR_STR2
3068 "Solo peer - part of its own update group\n")
3069{
d62a17ae 3070 int idx_peer = 2;
3071 struct peer *peer;
3072 int ret;
3f9c7369 3073
d62a17ae 3074 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3075 if (!peer)
3076 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3077
d62a17ae 3078 ret = update_group_adjust_soloness(peer, 0);
3079 return bgp_vty_return(vty, ret);
3f9c7369
DS
3080}
3081
0df7c91f
PJ
3082DEFUN (neighbor_password,
3083 neighbor_password_cmd,
9ccf14f7 3084 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3085 NEIGHBOR_STR
3086 NEIGHBOR_ADDR_STR2
3087 "Set a password\n"
3088 "The password\n")
3089{
d62a17ae 3090 int idx_peer = 1;
3091 int idx_line = 3;
3092 struct peer *peer;
3093 int ret;
0df7c91f 3094
d62a17ae 3095 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3096 if (!peer)
3097 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3098
d62a17ae 3099 ret = peer_password_set(peer, argv[idx_line]->arg);
3100 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3101}
3102
3103DEFUN (no_neighbor_password,
3104 no_neighbor_password_cmd,
a636c635 3105 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3106 NO_STR
3107 NEIGHBOR_STR
3108 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3109 "Set a password\n"
3110 "The password\n")
0df7c91f 3111{
d62a17ae 3112 int idx_peer = 2;
3113 struct peer *peer;
3114 int ret;
0df7c91f 3115
d62a17ae 3116 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3117 if (!peer)
3118 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3119
d62a17ae 3120 ret = peer_password_unset(peer);
3121 return bgp_vty_return(vty, ret);
0df7c91f 3122}
6b0655a2 3123
813d4307 3124
718e3744 3125DEFUN (neighbor_activate,
3126 neighbor_activate_cmd,
9ccf14f7 3127 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3128 NEIGHBOR_STR
3129 NEIGHBOR_ADDR_STR2
3130 "Enable the Address Family for this Neighbor\n")
3131{
d62a17ae 3132 int idx_peer = 1;
3133 int ret;
3134 struct peer *peer;
718e3744 3135
d62a17ae 3136 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3137 if (!peer)
3138 return CMD_WARNING_CONFIG_FAILED;
718e3744 3139
d62a17ae 3140 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3141 return bgp_vty_return(vty, ret);
718e3744 3142}
3143
d62a17ae 3144ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3145 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3146 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3147 "Enable the Address Family for this Neighbor\n")
596c17ba 3148
718e3744 3149DEFUN (no_neighbor_activate,
3150 no_neighbor_activate_cmd,
9ccf14f7 3151 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3152 NO_STR
3153 NEIGHBOR_STR
3154 NEIGHBOR_ADDR_STR2
3155 "Enable the Address Family for this Neighbor\n")
3156{
d62a17ae 3157 int idx_peer = 2;
3158 int ret;
3159 struct peer *peer;
718e3744 3160
d62a17ae 3161 /* Lookup peer. */
3162 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3163 if (!peer)
3164 return CMD_WARNING_CONFIG_FAILED;
718e3744 3165
d62a17ae 3166 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3167 return bgp_vty_return(vty, ret);
718e3744 3168}
6b0655a2 3169
d62a17ae 3170ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3171 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3172 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3173 "Enable the Address Family for this Neighbor\n")
596c17ba 3174
718e3744 3175DEFUN (neighbor_set_peer_group,
3176 neighbor_set_peer_group_cmd,
9ccf14f7 3177 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3178 NEIGHBOR_STR
a80beece 3179 NEIGHBOR_ADDR_STR2
718e3744 3180 "Member of the peer-group\n"
16cedbb0 3181 "Peer-group name\n")
718e3744 3182{
d62a17ae 3183 VTY_DECLVAR_CONTEXT(bgp, bgp);
3184 int idx_peer = 1;
3185 int idx_word = 3;
3186 int ret;
3187 as_t as;
3188 union sockunion su;
3189 struct peer *peer;
3190 struct peer_group *group;
3191
3192 peer = NULL;
3193
3194 ret = str2sockunion(argv[idx_peer]->arg, &su);
3195 if (ret < 0) {
3196 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3197 if (!peer) {
3198 vty_out(vty, "%% Malformed address or name: %s\n",
3199 argv[idx_peer]->arg);
3200 return CMD_WARNING_CONFIG_FAILED;
3201 }
3202 } else {
3203 if (peer_address_self_check(bgp, &su)) {
3204 vty_out(vty,
3205 "%% Can not configure the local system as neighbor\n");
3206 return CMD_WARNING_CONFIG_FAILED;
3207 }
3208
3209 /* Disallow for dynamic neighbor. */
3210 peer = peer_lookup(bgp, &su);
3211 if (peer && peer_dynamic_neighbor(peer)) {
3212 vty_out(vty,
3213 "%% Operation not allowed on a dynamic neighbor\n");
3214 return CMD_WARNING_CONFIG_FAILED;
3215 }
3216 }
3217
3218 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3219 if (!group) {
3220 vty_out(vty, "%% Configure the peer-group first\n");
3221 return CMD_WARNING_CONFIG_FAILED;
3222 }
3223
3224 ret = peer_group_bind(bgp, &su, peer, group, &as);
3225
3226 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3227 vty_out(vty,
3228 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3229 as);
3230 return CMD_WARNING_CONFIG_FAILED;
3231 }
3232
3233 return bgp_vty_return(vty, ret);
3234}
3235
3236ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3237 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3238 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3239 "Member of the peer-group\n"
3240 "Peer-group name\n")
596c17ba 3241
718e3744 3242DEFUN (no_neighbor_set_peer_group,
3243 no_neighbor_set_peer_group_cmd,
9ccf14f7 3244 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3245 NO_STR
3246 NEIGHBOR_STR
a80beece 3247 NEIGHBOR_ADDR_STR2
718e3744 3248 "Member of the peer-group\n"
16cedbb0 3249 "Peer-group name\n")
718e3744 3250{
d62a17ae 3251 VTY_DECLVAR_CONTEXT(bgp, bgp);
3252 int idx_peer = 2;
3253 int idx_word = 4;
3254 int ret;
3255 struct peer *peer;
3256 struct peer_group *group;
3257
3258 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3259 if (!peer)
3260 return CMD_WARNING_CONFIG_FAILED;
3261
3262 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3263 if (!group) {
3264 vty_out(vty, "%% Configure the peer-group first\n");
3265 return CMD_WARNING_CONFIG_FAILED;
3266 }
718e3744 3267
d62a17ae 3268 ret = peer_group_unbind(bgp, peer, group);
718e3744 3269
d62a17ae 3270 return bgp_vty_return(vty, ret);
718e3744 3271}
6b0655a2 3272
d62a17ae 3273ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3274 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3275 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3276 "Member of the peer-group\n"
3277 "Peer-group name\n")
596c17ba 3278
d62a17ae 3279static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3280 u_int16_t flag, int set)
718e3744 3281{
d62a17ae 3282 int ret;
3283 struct peer *peer;
718e3744 3284
d62a17ae 3285 peer = peer_and_group_lookup_vty(vty, ip_str);
3286 if (!peer)
3287 return CMD_WARNING_CONFIG_FAILED;
718e3744 3288
d62a17ae 3289 /*
3290 * If 'neighbor <interface>', then this is for directly connected peers,
3291 * we should not accept disable-connected-check.
3292 */
3293 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3294 vty_out(vty,
3295 "%s is directly connected peer, cannot accept disable-"
3296 "connected-check\n",
3297 ip_str);
3298 return CMD_WARNING_CONFIG_FAILED;
3299 }
8cdabf90 3300
d62a17ae 3301 if (!set && flag == PEER_FLAG_SHUTDOWN)
3302 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3303
d62a17ae 3304 if (set)
3305 ret = peer_flag_set(peer, flag);
3306 else
3307 ret = peer_flag_unset(peer, flag);
718e3744 3308
d62a17ae 3309 return bgp_vty_return(vty, ret);
718e3744 3310}
3311
d62a17ae 3312static int peer_flag_set_vty(struct vty *vty, const char *ip_str,
3313 u_int16_t flag)
718e3744 3314{
d62a17ae 3315 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3316}
3317
d62a17ae 3318static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3319 u_int16_t flag)
718e3744 3320{
d62a17ae 3321 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3322}
3323
3324/* neighbor passive. */
3325DEFUN (neighbor_passive,
3326 neighbor_passive_cmd,
9ccf14f7 3327 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3328 NEIGHBOR_STR
3329 NEIGHBOR_ADDR_STR2
3330 "Don't send open messages to this neighbor\n")
3331{
d62a17ae 3332 int idx_peer = 1;
3333 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3334}
3335
3336DEFUN (no_neighbor_passive,
3337 no_neighbor_passive_cmd,
9ccf14f7 3338 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3339 NO_STR
3340 NEIGHBOR_STR
3341 NEIGHBOR_ADDR_STR2
3342 "Don't send open messages to this neighbor\n")
3343{
d62a17ae 3344 int idx_peer = 2;
3345 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3346}
6b0655a2 3347
718e3744 3348/* neighbor shutdown. */
73d70fa6
DL
3349DEFUN (neighbor_shutdown_msg,
3350 neighbor_shutdown_msg_cmd,
3351 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3352 NEIGHBOR_STR
3353 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3354 "Administratively shut down this neighbor\n"
3355 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3356 "Shutdown message\n")
718e3744 3357{
d62a17ae 3358 int idx_peer = 1;
73d70fa6 3359
d62a17ae 3360 if (argc >= 5) {
3361 struct peer *peer =
3362 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3363 char *message;
73d70fa6 3364
d62a17ae 3365 if (!peer)
3366 return CMD_WARNING_CONFIG_FAILED;
3367 message = argv_concat(argv, argc, 4);
3368 peer_tx_shutdown_message_set(peer, message);
3369 XFREE(MTYPE_TMP, message);
3370 }
73d70fa6 3371
d62a17ae 3372 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3373}
3374
d62a17ae 3375ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3376 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3377 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3378 "Administratively shut down this neighbor\n")
73d70fa6
DL
3379
3380DEFUN (no_neighbor_shutdown_msg,
3381 no_neighbor_shutdown_msg_cmd,
3382 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3383 NO_STR
3384 NEIGHBOR_STR
3385 NEIGHBOR_ADDR_STR2
3386 "Administratively shut down this neighbor\n"
3387 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3388 "Shutdown message\n")
718e3744 3389{
d62a17ae 3390 int idx_peer = 2;
73d70fa6 3391
d62a17ae 3392 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3393 PEER_FLAG_SHUTDOWN);
718e3744 3394}
6b0655a2 3395
d62a17ae 3396ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3397 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3398 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3399 "Administratively shut down this neighbor\n")
73d70fa6 3400
718e3744 3401/* neighbor capability dynamic. */
3402DEFUN (neighbor_capability_dynamic,
3403 neighbor_capability_dynamic_cmd,
9ccf14f7 3404 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3405 NEIGHBOR_STR
3406 NEIGHBOR_ADDR_STR2
3407 "Advertise capability to the peer\n"
3408 "Advertise dynamic capability to this neighbor\n")
3409{
d62a17ae 3410 int idx_peer = 1;
3411 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3412 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3413}
3414
3415DEFUN (no_neighbor_capability_dynamic,
3416 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3417 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3418 NO_STR
3419 NEIGHBOR_STR
3420 NEIGHBOR_ADDR_STR2
3421 "Advertise capability to the peer\n"
3422 "Advertise dynamic capability to this neighbor\n")
3423{
d62a17ae 3424 int idx_peer = 2;
3425 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3426 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3427}
6b0655a2 3428
718e3744 3429/* neighbor dont-capability-negotiate */
3430DEFUN (neighbor_dont_capability_negotiate,
3431 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3432 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3433 NEIGHBOR_STR
3434 NEIGHBOR_ADDR_STR2
3435 "Do not perform capability negotiation\n")
3436{
d62a17ae 3437 int idx_peer = 1;
3438 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3439 PEER_FLAG_DONT_CAPABILITY);
718e3744 3440}
3441
3442DEFUN (no_neighbor_dont_capability_negotiate,
3443 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3444 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3445 NO_STR
3446 NEIGHBOR_STR
3447 NEIGHBOR_ADDR_STR2
3448 "Do not perform capability negotiation\n")
3449{
d62a17ae 3450 int idx_peer = 2;
3451 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3452 PEER_FLAG_DONT_CAPABILITY);
718e3744 3453}
6b0655a2 3454
8a92a8a0
DS
3455/* neighbor capability extended next hop encoding */
3456DEFUN (neighbor_capability_enhe,
3457 neighbor_capability_enhe_cmd,
9ccf14f7 3458 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3459 NEIGHBOR_STR
3460 NEIGHBOR_ADDR_STR2
3461 "Advertise capability to the peer\n"
3462 "Advertise extended next-hop capability to the peer\n")
3463{
d62a17ae 3464 int idx_peer = 1;
3465 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3466 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3467}
3468
3469DEFUN (no_neighbor_capability_enhe,
3470 no_neighbor_capability_enhe_cmd,
9ccf14f7 3471 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3472 NO_STR
3473 NEIGHBOR_STR
3474 NEIGHBOR_ADDR_STR2
3475 "Advertise capability to the peer\n"
3476 "Advertise extended next-hop capability to the peer\n")
3477{
d62a17ae 3478 int idx_peer = 2;
3479 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3480 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3481}
3482
d62a17ae 3483static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3484 afi_t afi, safi_t safi, u_int32_t flag,
3485 int set)
718e3744 3486{
d62a17ae 3487 int ret;
3488 struct peer *peer;
718e3744 3489
d62a17ae 3490 peer = peer_and_group_lookup_vty(vty, peer_str);
3491 if (!peer)
3492 return CMD_WARNING_CONFIG_FAILED;
718e3744 3493
d62a17ae 3494 if (set)
3495 ret = peer_af_flag_set(peer, afi, safi, flag);
3496 else
3497 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3498
d62a17ae 3499 return bgp_vty_return(vty, ret);
718e3744 3500}
3501
d62a17ae 3502static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3503 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3504{
d62a17ae 3505 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3506}
3507
d62a17ae 3508static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3509 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3510{
d62a17ae 3511 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3512}
6b0655a2 3513
718e3744 3514/* neighbor capability orf prefix-list. */
3515DEFUN (neighbor_capability_orf_prefix,
3516 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3517 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3518 NEIGHBOR_STR
3519 NEIGHBOR_ADDR_STR2
3520 "Advertise capability to the peer\n"
3521 "Advertise ORF capability to the peer\n"
3522 "Advertise prefixlist ORF capability to this neighbor\n"
3523 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3524 "Capability to RECEIVE the ORF from this neighbor\n"
3525 "Capability to SEND the ORF to this neighbor\n")
3526{
d62a17ae 3527 int idx_peer = 1;
3528 int idx_send_recv = 5;
3529 u_int16_t flag = 0;
3530
3531 if (strmatch(argv[idx_send_recv]->text, "send"))
3532 flag = PEER_FLAG_ORF_PREFIX_SM;
3533 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3534 flag = PEER_FLAG_ORF_PREFIX_RM;
3535 else if (strmatch(argv[idx_send_recv]->text, "both"))
3536 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3537 else {
3538 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3539 return CMD_WARNING_CONFIG_FAILED;
3540 }
3541
3542 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3543 bgp_node_safi(vty), flag);
3544}
3545
3546ALIAS_HIDDEN(
3547 neighbor_capability_orf_prefix,
3548 neighbor_capability_orf_prefix_hidden_cmd,
3549 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3550 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3551 "Advertise capability to the peer\n"
3552 "Advertise ORF capability to the peer\n"
3553 "Advertise prefixlist ORF capability to this neighbor\n"
3554 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3555 "Capability to RECEIVE the ORF from this neighbor\n"
3556 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3557
718e3744 3558DEFUN (no_neighbor_capability_orf_prefix,
3559 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3560 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3561 NO_STR
3562 NEIGHBOR_STR
3563 NEIGHBOR_ADDR_STR2
3564 "Advertise capability to the peer\n"
3565 "Advertise ORF capability to the peer\n"
3566 "Advertise prefixlist ORF capability to this neighbor\n"
3567 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3568 "Capability to RECEIVE the ORF from this neighbor\n"
3569 "Capability to SEND the ORF to this neighbor\n")
3570{
d62a17ae 3571 int idx_peer = 2;
3572 int idx_send_recv = 6;
3573 u_int16_t flag = 0;
3574
3575 if (strmatch(argv[idx_send_recv]->text, "send"))
3576 flag = PEER_FLAG_ORF_PREFIX_SM;
3577 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3578 flag = PEER_FLAG_ORF_PREFIX_RM;
3579 else if (strmatch(argv[idx_send_recv]->text, "both"))
3580 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3581 else {
3582 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3583 return CMD_WARNING_CONFIG_FAILED;
3584 }
3585
3586 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3587 bgp_node_afi(vty), bgp_node_safi(vty),
3588 flag);
3589}
3590
3591ALIAS_HIDDEN(
3592 no_neighbor_capability_orf_prefix,
3593 no_neighbor_capability_orf_prefix_hidden_cmd,
3594 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3595 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3596 "Advertise capability to the peer\n"
3597 "Advertise ORF capability to the peer\n"
3598 "Advertise prefixlist ORF capability to this neighbor\n"
3599 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3600 "Capability to RECEIVE the ORF from this neighbor\n"
3601 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3602
718e3744 3603/* neighbor next-hop-self. */
3604DEFUN (neighbor_nexthop_self,
3605 neighbor_nexthop_self_cmd,
9ccf14f7 3606 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3607 NEIGHBOR_STR
3608 NEIGHBOR_ADDR_STR2
a538debe 3609 "Disable the next hop calculation for this neighbor\n")
718e3744 3610{
d62a17ae 3611 int idx_peer = 1;
3612 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3613 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3614}
9e7a53c1 3615
d62a17ae 3616ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3617 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3618 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3619 "Disable the next hop calculation for this neighbor\n")
596c17ba 3620
a538debe
DS
3621/* neighbor next-hop-self. */
3622DEFUN (neighbor_nexthop_self_force,
3623 neighbor_nexthop_self_force_cmd,
9ccf14f7 3624 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3625 NEIGHBOR_STR
3626 NEIGHBOR_ADDR_STR2
3627 "Disable the next hop calculation for this neighbor\n"
3628 "Set the next hop to self for reflected routes\n")
3629{
d62a17ae 3630 int idx_peer = 1;
3631 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3632 bgp_node_safi(vty),
3633 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3634}
3635
d62a17ae 3636ALIAS_HIDDEN(neighbor_nexthop_self_force,
3637 neighbor_nexthop_self_force_hidden_cmd,
3638 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3639 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3640 "Disable the next hop calculation for this neighbor\n"
3641 "Set the next hop to self for reflected routes\n")
596c17ba 3642
718e3744 3643DEFUN (no_neighbor_nexthop_self,
3644 no_neighbor_nexthop_self_cmd,
9ccf14f7 3645 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3646 NO_STR
3647 NEIGHBOR_STR
3648 NEIGHBOR_ADDR_STR2
a538debe 3649 "Disable the next hop calculation for this neighbor\n")
718e3744 3650{
d62a17ae 3651 int idx_peer = 2;
3652 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3653 bgp_node_afi(vty), bgp_node_safi(vty),
3654 PEER_FLAG_NEXTHOP_SELF);
718e3744 3655}
6b0655a2 3656
d62a17ae 3657ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3658 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3659 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3660 "Disable the next hop calculation for this neighbor\n")
596c17ba 3661
88b8ed8d 3662DEFUN (no_neighbor_nexthop_self_force,
a538debe 3663 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3664 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3665 NO_STR
3666 NEIGHBOR_STR
3667 NEIGHBOR_ADDR_STR2
3668 "Disable the next hop calculation for this neighbor\n"
3669 "Set the next hop to self for reflected routes\n")
88b8ed8d 3670{
d62a17ae 3671 int idx_peer = 2;
3672 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3673 bgp_node_afi(vty), bgp_node_safi(vty),
3674 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3675}
a538debe 3676
d62a17ae 3677ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3678 no_neighbor_nexthop_self_force_hidden_cmd,
3679 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3680 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3681 "Disable the next hop calculation for this neighbor\n"
3682 "Set the next hop to self for reflected routes\n")
596c17ba 3683
c7122e14
DS
3684/* neighbor as-override */
3685DEFUN (neighbor_as_override,
3686 neighbor_as_override_cmd,
9ccf14f7 3687 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3688 NEIGHBOR_STR
3689 NEIGHBOR_ADDR_STR2
3690 "Override ASNs in outbound updates if aspath equals remote-as\n")
3691{
d62a17ae 3692 int idx_peer = 1;
3693 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3694 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3695}
3696
d62a17ae 3697ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3698 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3700 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3701
c7122e14
DS
3702DEFUN (no_neighbor_as_override,
3703 no_neighbor_as_override_cmd,
9ccf14f7 3704 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3705 NO_STR
3706 NEIGHBOR_STR
3707 NEIGHBOR_ADDR_STR2
3708 "Override ASNs in outbound updates if aspath equals remote-as\n")
3709{
d62a17ae 3710 int idx_peer = 2;
3711 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3712 bgp_node_afi(vty), bgp_node_safi(vty),
3713 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3714}
3715
d62a17ae 3716ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3717 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3718 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3719 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3720
718e3744 3721/* neighbor remove-private-AS. */
3722DEFUN (neighbor_remove_private_as,
3723 neighbor_remove_private_as_cmd,
9ccf14f7 3724 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3725 NEIGHBOR_STR
3726 NEIGHBOR_ADDR_STR2
5000f21c 3727 "Remove private ASNs in outbound updates\n")
718e3744 3728{
d62a17ae 3729 int idx_peer = 1;
3730 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3731 bgp_node_safi(vty),
3732 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3733}
3734
d62a17ae 3735ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3736 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3737 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3738 "Remove private ASNs in outbound updates\n")
596c17ba 3739
5000f21c
DS
3740DEFUN (neighbor_remove_private_as_all,
3741 neighbor_remove_private_as_all_cmd,
9ccf14f7 3742 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3743 NEIGHBOR_STR
3744 NEIGHBOR_ADDR_STR2
3745 "Remove private ASNs in outbound updates\n"
3746 "Apply to all AS numbers")
3747{
d62a17ae 3748 int idx_peer = 1;
3749 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3750 bgp_node_safi(vty),
3751 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3752}
3753
d62a17ae 3754ALIAS_HIDDEN(neighbor_remove_private_as_all,
3755 neighbor_remove_private_as_all_hidden_cmd,
3756 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3757 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3758 "Remove private ASNs in outbound updates\n"
3759 "Apply to all AS numbers")
596c17ba 3760
5000f21c
DS
3761DEFUN (neighbor_remove_private_as_replace_as,
3762 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3763 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3764 NEIGHBOR_STR
3765 NEIGHBOR_ADDR_STR2
3766 "Remove private ASNs in outbound updates\n"
3767 "Replace private ASNs with our ASN in outbound updates\n")
3768{
d62a17ae 3769 int idx_peer = 1;
3770 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3771 bgp_node_safi(vty),
3772 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3773}
3774
d62a17ae 3775ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3776 neighbor_remove_private_as_replace_as_hidden_cmd,
3777 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3778 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3779 "Remove private ASNs in outbound updates\n"
3780 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3781
5000f21c
DS
3782DEFUN (neighbor_remove_private_as_all_replace_as,
3783 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3784 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3785 NEIGHBOR_STR
3786 NEIGHBOR_ADDR_STR2
3787 "Remove private ASNs in outbound updates\n"
16cedbb0 3788 "Apply to all AS numbers\n"
5000f21c
DS
3789 "Replace private ASNs with our ASN in outbound updates\n")
3790{
d62a17ae 3791 int idx_peer = 1;
3792 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3793 bgp_node_safi(vty),
3794 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3795}
3796
d62a17ae 3797ALIAS_HIDDEN(
3798 neighbor_remove_private_as_all_replace_as,
3799 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3800 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3801 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3802 "Remove private ASNs in outbound updates\n"
3803 "Apply to all AS numbers\n"
3804 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3805
718e3744 3806DEFUN (no_neighbor_remove_private_as,
3807 no_neighbor_remove_private_as_cmd,
9ccf14f7 3808 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3809 NO_STR
3810 NEIGHBOR_STR
3811 NEIGHBOR_ADDR_STR2
5000f21c 3812 "Remove private ASNs in outbound updates\n")
718e3744 3813{
d62a17ae 3814 int idx_peer = 2;
3815 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3816 bgp_node_afi(vty), bgp_node_safi(vty),
3817 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3818}
6b0655a2 3819
d62a17ae 3820ALIAS_HIDDEN(no_neighbor_remove_private_as,
3821 no_neighbor_remove_private_as_hidden_cmd,
3822 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3823 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3824 "Remove private ASNs in outbound updates\n")
596c17ba 3825
88b8ed8d 3826DEFUN (no_neighbor_remove_private_as_all,
5000f21c 3827 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 3828 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3829 NO_STR
3830 NEIGHBOR_STR
3831 NEIGHBOR_ADDR_STR2
3832 "Remove private ASNs in outbound updates\n"
16cedbb0 3833 "Apply to all AS numbers\n")
88b8ed8d 3834{
d62a17ae 3835 int idx_peer = 2;
3836 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3837 bgp_node_afi(vty), bgp_node_safi(vty),
3838 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 3839}
5000f21c 3840
d62a17ae 3841ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3842 no_neighbor_remove_private_as_all_hidden_cmd,
3843 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3844 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3845 "Remove private ASNs in outbound updates\n"
3846 "Apply to all AS numbers\n")
596c17ba 3847
88b8ed8d 3848DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 3849 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3850 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3851 NO_STR
3852 NEIGHBOR_STR
3853 NEIGHBOR_ADDR_STR2
3854 "Remove private ASNs in outbound updates\n"
3855 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3856{
d62a17ae 3857 int idx_peer = 2;
3858 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3859 bgp_node_afi(vty), bgp_node_safi(vty),
3860 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 3861}
5000f21c 3862
d62a17ae 3863ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
3864 no_neighbor_remove_private_as_replace_as_hidden_cmd,
3865 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3867 "Remove private ASNs in outbound updates\n"
3868 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3869
88b8ed8d 3870DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 3871 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3872 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3873 NO_STR
3874 NEIGHBOR_STR
3875 NEIGHBOR_ADDR_STR2
3876 "Remove private ASNs in outbound updates\n"
16cedbb0 3877 "Apply to all AS numbers\n"
5000f21c 3878 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3879{
d62a17ae 3880 int idx_peer = 2;
3881 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3882 bgp_node_afi(vty), bgp_node_safi(vty),
3883 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 3884}
5000f21c 3885
d62a17ae 3886ALIAS_HIDDEN(
3887 no_neighbor_remove_private_as_all_replace_as,
3888 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
3889 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3890 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3891 "Remove private ASNs in outbound updates\n"
3892 "Apply to all AS numbers\n"
3893 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3894
5000f21c 3895
718e3744 3896/* neighbor send-community. */
3897DEFUN (neighbor_send_community,
3898 neighbor_send_community_cmd,
9ccf14f7 3899 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 3900 NEIGHBOR_STR
3901 NEIGHBOR_ADDR_STR2
3902 "Send Community attribute to this neighbor\n")
3903{
d62a17ae 3904 int idx_peer = 1;
3905 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3906 bgp_node_safi(vty),
3907 PEER_FLAG_SEND_COMMUNITY);
718e3744 3908}
3909
d62a17ae 3910ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
3911 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
3912 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3913 "Send Community attribute to this neighbor\n")
596c17ba 3914
718e3744 3915DEFUN (no_neighbor_send_community,
3916 no_neighbor_send_community_cmd,
9ccf14f7 3917 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 3918 NO_STR
3919 NEIGHBOR_STR
3920 NEIGHBOR_ADDR_STR2
3921 "Send Community attribute to this neighbor\n")
3922{
d62a17ae 3923 int idx_peer = 2;
3924 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3925 bgp_node_afi(vty), bgp_node_safi(vty),
3926 PEER_FLAG_SEND_COMMUNITY);
718e3744 3927}
6b0655a2 3928
d62a17ae 3929ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
3930 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
3931 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3932 "Send Community attribute to this neighbor\n")
596c17ba 3933
718e3744 3934/* neighbor send-community extended. */
3935DEFUN (neighbor_send_community_type,
3936 neighbor_send_community_type_cmd,
57d187bc 3937 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 3938 NEIGHBOR_STR
3939 NEIGHBOR_ADDR_STR2
3940 "Send Community attribute to this neighbor\n"
3941 "Send Standard and Extended Community attributes\n"
57d187bc 3942 "Send Standard, Large and Extended Community attributes\n"
718e3744 3943 "Send Extended Community attributes\n"
57d187bc
JS
3944 "Send Standard Community attributes\n"
3945 "Send Large Community attributes\n")
718e3744 3946{
d62a17ae 3947 int idx = 0;
3948 u_int32_t flag = 0;
3949
3950 char *peer = argv[1]->arg;
3951
3952 if (argv_find(argv, argc, "standard", &idx))
3953 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
3954 else if (argv_find(argv, argc, "extended", &idx))
3955 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
3956 else if (argv_find(argv, argc, "large", &idx))
3957 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
3958 else if (argv_find(argv, argc, "both", &idx)) {
3959 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
3960 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
3961 } else {
3962 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
3963 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
3964 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
3965 }
3966
3967 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
3968 bgp_node_safi(vty), flag);
3969}
3970
3971ALIAS_HIDDEN(
3972 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
3973 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
3974 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3975 "Send Community attribute to this neighbor\n"
3976 "Send Standard and Extended Community attributes\n"
3977 "Send Standard, Large and Extended Community attributes\n"
3978 "Send Extended Community attributes\n"
3979 "Send Standard Community attributes\n"
3980 "Send Large Community attributes\n")
596c17ba 3981
718e3744 3982DEFUN (no_neighbor_send_community_type,
3983 no_neighbor_send_community_type_cmd,
57d187bc 3984 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 3985 NO_STR
3986 NEIGHBOR_STR
3987 NEIGHBOR_ADDR_STR2
3988 "Send Community attribute to this neighbor\n"
3989 "Send Standard and Extended Community attributes\n"
57d187bc 3990 "Send Standard, Large and Extended Community attributes\n"
718e3744 3991 "Send Extended Community attributes\n"
57d187bc
JS
3992 "Send Standard Community attributes\n"
3993 "Send Large Community attributes\n")
718e3744 3994{
d62a17ae 3995 int idx_peer = 2;
3996
3997 const char *type = argv[argc - 1]->text;
3998
3999 if (strmatch(type, "standard"))
4000 return peer_af_flag_unset_vty(
4001 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4002 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4003 if (strmatch(type, "extended"))
4004 return peer_af_flag_unset_vty(
4005 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4006 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4007 if (strmatch(type, "large"))
4008 return peer_af_flag_unset_vty(
4009 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4010 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4011 if (strmatch(type, "both"))
4012 return peer_af_flag_unset_vty(
4013 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4014 bgp_node_safi(vty),
4015 PEER_FLAG_SEND_COMMUNITY
4016 | PEER_FLAG_SEND_EXT_COMMUNITY);
4017
4018 /* if (strmatch (type, "all")) */
4019 return peer_af_flag_unset_vty(
4020 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4021 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4022 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4023}
4024
4025ALIAS_HIDDEN(
4026 no_neighbor_send_community_type,
4027 no_neighbor_send_community_type_hidden_cmd,
4028 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4029 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4030 "Send Community attribute to this neighbor\n"
4031 "Send Standard and Extended Community attributes\n"
4032 "Send Standard, Large and Extended Community attributes\n"
4033 "Send Extended Community attributes\n"
4034 "Send Standard Community attributes\n"
4035 "Send Large Community attributes\n")
596c17ba 4036
718e3744 4037/* neighbor soft-reconfig. */
4038DEFUN (neighbor_soft_reconfiguration,
4039 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4040 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4041 NEIGHBOR_STR
4042 NEIGHBOR_ADDR_STR2
4043 "Per neighbor soft reconfiguration\n"
4044 "Allow inbound soft reconfiguration for this neighbor\n")
4045{
d62a17ae 4046 int idx_peer = 1;
4047 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4048 bgp_node_safi(vty),
4049 PEER_FLAG_SOFT_RECONFIG);
718e3744 4050}
4051
d62a17ae 4052ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4053 neighbor_soft_reconfiguration_hidden_cmd,
4054 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4055 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4056 "Per neighbor soft reconfiguration\n"
4057 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4058
718e3744 4059DEFUN (no_neighbor_soft_reconfiguration,
4060 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4061 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4062 NO_STR
4063 NEIGHBOR_STR
4064 NEIGHBOR_ADDR_STR2
4065 "Per neighbor soft reconfiguration\n"
4066 "Allow inbound soft reconfiguration for this neighbor\n")
4067{
d62a17ae 4068 int idx_peer = 2;
4069 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4070 bgp_node_afi(vty), bgp_node_safi(vty),
4071 PEER_FLAG_SOFT_RECONFIG);
718e3744 4072}
6b0655a2 4073
d62a17ae 4074ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4075 no_neighbor_soft_reconfiguration_hidden_cmd,
4076 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4077 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4078 "Per neighbor soft reconfiguration\n"
4079 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4080
718e3744 4081DEFUN (neighbor_route_reflector_client,
4082 neighbor_route_reflector_client_cmd,
9ccf14f7 4083 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4084 NEIGHBOR_STR
4085 NEIGHBOR_ADDR_STR2
4086 "Configure a neighbor as Route Reflector client\n")
4087{
d62a17ae 4088 int idx_peer = 1;
4089 struct peer *peer;
718e3744 4090
4091
d62a17ae 4092 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4093 if (!peer)
4094 return CMD_WARNING_CONFIG_FAILED;
718e3744 4095
d62a17ae 4096 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4097 bgp_node_safi(vty),
4098 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4099}
4100
d62a17ae 4101ALIAS_HIDDEN(neighbor_route_reflector_client,
4102 neighbor_route_reflector_client_hidden_cmd,
4103 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4104 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4105 "Configure a neighbor as Route Reflector client\n")
596c17ba 4106
718e3744 4107DEFUN (no_neighbor_route_reflector_client,
4108 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4109 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4110 NO_STR
4111 NEIGHBOR_STR
4112 NEIGHBOR_ADDR_STR2
4113 "Configure a neighbor as Route Reflector client\n")
4114{
d62a17ae 4115 int idx_peer = 2;
4116 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4117 bgp_node_afi(vty), bgp_node_safi(vty),
4118 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4119}
6b0655a2 4120
d62a17ae 4121ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4122 no_neighbor_route_reflector_client_hidden_cmd,
4123 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4124 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4125 "Configure a neighbor as Route Reflector client\n")
596c17ba 4126
718e3744 4127/* neighbor route-server-client. */
4128DEFUN (neighbor_route_server_client,
4129 neighbor_route_server_client_cmd,
9ccf14f7 4130 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4131 NEIGHBOR_STR
4132 NEIGHBOR_ADDR_STR2
4133 "Configure a neighbor as Route Server client\n")
4134{
d62a17ae 4135 int idx_peer = 1;
4136 struct peer *peer;
2a3d5731 4137
d62a17ae 4138 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4139 if (!peer)
4140 return CMD_WARNING_CONFIG_FAILED;
4141 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4142 bgp_node_safi(vty),
4143 PEER_FLAG_RSERVER_CLIENT);
718e3744 4144}
4145
d62a17ae 4146ALIAS_HIDDEN(neighbor_route_server_client,
4147 neighbor_route_server_client_hidden_cmd,
4148 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4149 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4150 "Configure a neighbor as Route Server client\n")
596c17ba 4151
718e3744 4152DEFUN (no_neighbor_route_server_client,
4153 no_neighbor_route_server_client_cmd,
9ccf14f7 4154 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4155 NO_STR
4156 NEIGHBOR_STR
4157 NEIGHBOR_ADDR_STR2
4158 "Configure a neighbor as Route Server client\n")
fee0f4c6 4159{
d62a17ae 4160 int idx_peer = 2;
4161 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4162 bgp_node_afi(vty), bgp_node_safi(vty),
4163 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4164}
6b0655a2 4165
d62a17ae 4166ALIAS_HIDDEN(no_neighbor_route_server_client,
4167 no_neighbor_route_server_client_hidden_cmd,
4168 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4169 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4170 "Configure a neighbor as Route Server client\n")
596c17ba 4171
fee0f4c6 4172DEFUN (neighbor_nexthop_local_unchanged,
4173 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4174 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4175 NEIGHBOR_STR
4176 NEIGHBOR_ADDR_STR2
4177 "Configure treatment of outgoing link-local nexthop attribute\n"
4178 "Leave link-local nexthop unchanged for this peer\n")
4179{
d62a17ae 4180 int idx_peer = 1;
4181 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4182 bgp_node_safi(vty),
4183 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4184}
6b0655a2 4185
fee0f4c6 4186DEFUN (no_neighbor_nexthop_local_unchanged,
4187 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4188 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4189 NO_STR
4190 NEIGHBOR_STR
4191 NEIGHBOR_ADDR_STR2
4192 "Configure treatment of outgoing link-local-nexthop attribute\n"
4193 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4194{
d62a17ae 4195 int idx_peer = 2;
4196 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4197 bgp_node_afi(vty), bgp_node_safi(vty),
4198 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4199}
6b0655a2 4200
718e3744 4201DEFUN (neighbor_attr_unchanged,
4202 neighbor_attr_unchanged_cmd,
a8206004 4203 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4204 NEIGHBOR_STR
4205 NEIGHBOR_ADDR_STR2
4206 "BGP attribute is propagated unchanged to this neighbor\n"
4207 "As-path attribute\n"
4208 "Nexthop attribute\n"
a8206004 4209 "Med attribute\n")
718e3744 4210{
d62a17ae 4211 int idx = 0;
8eeb0335
DW
4212 char *peer_str = argv[1]->arg;
4213 struct peer *peer;
d62a17ae 4214 u_int16_t flags = 0;
8eeb0335
DW
4215 afi_t afi = bgp_node_afi(vty);
4216 safi_t safi = bgp_node_safi(vty);
4217
4218 peer = peer_and_group_lookup_vty(vty, peer_str);
4219 if (!peer)
4220 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4221
4222 if (argv_find(argv, argc, "as-path", &idx))
4223 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4224 idx = 0;
4225 if (argv_find(argv, argc, "next-hop", &idx))
4226 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4227 idx = 0;
4228 if (argv_find(argv, argc, "med", &idx))
4229 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4230
8eeb0335
DW
4231 /* no flags means all of them! */
4232 if (!flags) {
d62a17ae 4233 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4234 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4235 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335
DW
4236 } else {
4237 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED) &&
4238 peer_af_flag_check(peer, afi, safi,
4239 PEER_FLAG_AS_PATH_UNCHANGED)) {
4240 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4241 PEER_FLAG_AS_PATH_UNCHANGED);
4242 }
4243
4244 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED) &&
4245 peer_af_flag_check(peer, afi, safi,
4246 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4247 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4248 PEER_FLAG_NEXTHOP_UNCHANGED);
4249 }
4250
4251 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED) &&
4252 peer_af_flag_check(peer, afi, safi,
4253 PEER_FLAG_MED_UNCHANGED)) {
4254 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4255 PEER_FLAG_MED_UNCHANGED);
4256 }
d62a17ae 4257 }
4258
8eeb0335 4259 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4260}
4261
4262ALIAS_HIDDEN(
4263 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4264 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4265 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4266 "BGP attribute is propagated unchanged to this neighbor\n"
4267 "As-path attribute\n"
4268 "Nexthop attribute\n"
4269 "Med attribute\n")
596c17ba 4270
718e3744 4271DEFUN (no_neighbor_attr_unchanged,
4272 no_neighbor_attr_unchanged_cmd,
a8206004 4273 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4274 NO_STR
718e3744 4275 NEIGHBOR_STR
4276 NEIGHBOR_ADDR_STR2
31500417
DW
4277 "BGP attribute is propagated unchanged to this neighbor\n"
4278 "As-path attribute\n"
40e718b5 4279 "Nexthop attribute\n"
a8206004 4280 "Med attribute\n")
718e3744 4281{
d62a17ae 4282 int idx = 0;
4283 char *peer = argv[2]->arg;
4284 u_int16_t flags = 0;
4285
4286 if (argv_find(argv, argc, "as-path", &idx))
4287 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4288 idx = 0;
4289 if (argv_find(argv, argc, "next-hop", &idx))
4290 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4291 idx = 0;
4292 if (argv_find(argv, argc, "med", &idx))
4293 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4294
4295 if (!flags) // no flags means all of them!
4296 {
4297 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4298 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4299 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4300 }
4301
4302 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4303 bgp_node_safi(vty), flags);
4304}
4305
4306ALIAS_HIDDEN(
4307 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4308 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4309 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4310 "BGP attribute is propagated unchanged to this neighbor\n"
4311 "As-path attribute\n"
4312 "Nexthop attribute\n"
4313 "Med attribute\n")
718e3744 4314
718e3744 4315/* EBGP multihop configuration. */
d62a17ae 4316static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4317 const char *ttl_str)
718e3744 4318{
d62a17ae 4319 struct peer *peer;
4320 unsigned int ttl;
718e3744 4321
d62a17ae 4322 peer = peer_and_group_lookup_vty(vty, ip_str);
4323 if (!peer)
4324 return CMD_WARNING_CONFIG_FAILED;
718e3744 4325
d62a17ae 4326 if (peer->conf_if)
4327 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4328
d62a17ae 4329 if (!ttl_str)
4330 ttl = MAXTTL;
4331 else
4332 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4333
d62a17ae 4334 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4335}
4336
d62a17ae 4337static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4338{
d62a17ae 4339 struct peer *peer;
718e3744 4340
d62a17ae 4341 peer = peer_and_group_lookup_vty(vty, ip_str);
4342 if (!peer)
4343 return CMD_WARNING_CONFIG_FAILED;
718e3744 4344
d62a17ae 4345 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4346}
4347
4348/* neighbor ebgp-multihop. */
4349DEFUN (neighbor_ebgp_multihop,
4350 neighbor_ebgp_multihop_cmd,
9ccf14f7 4351 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4352 NEIGHBOR_STR
4353 NEIGHBOR_ADDR_STR2
4354 "Allow EBGP neighbors not on directly connected networks\n")
4355{
d62a17ae 4356 int idx_peer = 1;
4357 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4358}
4359
4360DEFUN (neighbor_ebgp_multihop_ttl,
4361 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4362 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4363 NEIGHBOR_STR
4364 NEIGHBOR_ADDR_STR2
4365 "Allow EBGP neighbors not on directly connected networks\n"
4366 "maximum hop count\n")
4367{
d62a17ae 4368 int idx_peer = 1;
4369 int idx_number = 3;
4370 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4371 argv[idx_number]->arg);
718e3744 4372}
4373
4374DEFUN (no_neighbor_ebgp_multihop,
4375 no_neighbor_ebgp_multihop_cmd,
a636c635 4376 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4377 NO_STR
4378 NEIGHBOR_STR
4379 NEIGHBOR_ADDR_STR2
a636c635
DW
4380 "Allow EBGP neighbors not on directly connected networks\n"
4381 "maximum hop count\n")
718e3744 4382{
d62a17ae 4383 int idx_peer = 2;
4384 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4385}
4386
6b0655a2 4387
6ffd2079 4388/* disable-connected-check */
4389DEFUN (neighbor_disable_connected_check,
4390 neighbor_disable_connected_check_cmd,
a636c635 4391 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4392 NEIGHBOR_STR
4393 NEIGHBOR_ADDR_STR2
a636c635
DW
4394 "one-hop away EBGP peer using loopback address\n"
4395 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4396{
d62a17ae 4397 int idx_peer = 1;
4398 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4399 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4400}
4401
4402DEFUN (no_neighbor_disable_connected_check,
4403 no_neighbor_disable_connected_check_cmd,
a636c635 4404 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4405 NO_STR
4406 NEIGHBOR_STR
4407 NEIGHBOR_ADDR_STR2
a636c635
DW
4408 "one-hop away EBGP peer using loopback address\n"
4409 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4410{
d62a17ae 4411 int idx_peer = 2;
4412 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4413 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4414}
4415
718e3744 4416DEFUN (neighbor_description,
4417 neighbor_description_cmd,
e961923c 4418 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4419 NEIGHBOR_STR
4420 NEIGHBOR_ADDR_STR2
4421 "Neighbor specific description\n"
4422 "Up to 80 characters describing this neighbor\n")
4423{
d62a17ae 4424 int idx_peer = 1;
4425 int idx_line = 3;
4426 struct peer *peer;
4427 char *str;
718e3744 4428
d62a17ae 4429 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4430 if (!peer)
4431 return CMD_WARNING_CONFIG_FAILED;
718e3744 4432
d62a17ae 4433 str = argv_concat(argv, argc, idx_line);
718e3744 4434
d62a17ae 4435 peer_description_set(peer, str);
718e3744 4436
d62a17ae 4437 XFREE(MTYPE_TMP, str);
718e3744 4438
d62a17ae 4439 return CMD_SUCCESS;
718e3744 4440}
4441
4442DEFUN (no_neighbor_description,
4443 no_neighbor_description_cmd,
a636c635 4444 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4445 NO_STR
4446 NEIGHBOR_STR
4447 NEIGHBOR_ADDR_STR2
a636c635
DW
4448 "Neighbor specific description\n"
4449 "Up to 80 characters describing this neighbor\n")
718e3744 4450{
d62a17ae 4451 int idx_peer = 2;
4452 struct peer *peer;
718e3744 4453
d62a17ae 4454 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4455 if (!peer)
4456 return CMD_WARNING_CONFIG_FAILED;
718e3744 4457
d62a17ae 4458 peer_description_unset(peer);
718e3744 4459
d62a17ae 4460 return CMD_SUCCESS;
718e3744 4461}
4462
6b0655a2 4463
718e3744 4464/* Neighbor update-source. */
d62a17ae 4465static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4466 const char *source_str)
4467{
4468 struct peer *peer;
4469 struct prefix p;
4470
4471 peer = peer_and_group_lookup_vty(vty, peer_str);
4472 if (!peer)
4473 return CMD_WARNING_CONFIG_FAILED;
4474
4475 if (peer->conf_if)
4476 return CMD_WARNING;
4477
4478 if (source_str) {
4479 union sockunion su;
4480 int ret = str2sockunion(source_str, &su);
4481
4482 if (ret == 0)
4483 peer_update_source_addr_set(peer, &su);
4484 else {
4485 if (str2prefix(source_str, &p)) {
4486 vty_out(vty,
4487 "%% Invalid update-source, remove prefix length \n");
4488 return CMD_WARNING_CONFIG_FAILED;
4489 } else
4490 peer_update_source_if_set(peer, source_str);
4491 }
4492 } else
4493 peer_update_source_unset(peer);
4494
4495 return CMD_SUCCESS;
4496}
4497
4498#define BGP_UPDATE_SOURCE_HELP_STR \
4499 "IPv4 address\n" \
4500 "IPv6 address\n" \
4501 "Interface name (requires zebra to be running)\n"
369688c0 4502
718e3744 4503DEFUN (neighbor_update_source,
4504 neighbor_update_source_cmd,
9ccf14f7 4505 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4506 NEIGHBOR_STR
4507 NEIGHBOR_ADDR_STR2
4508 "Source of routing updates\n"
369688c0 4509 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4510{
d62a17ae 4511 int idx_peer = 1;
4512 int idx_peer_2 = 3;
4513 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4514 argv[idx_peer_2]->arg);
718e3744 4515}
4516
4517DEFUN (no_neighbor_update_source,
4518 no_neighbor_update_source_cmd,
c7178fe7 4519 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4520 NO_STR
4521 NEIGHBOR_STR
4522 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4523 "Source of routing updates\n"
4524 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4525{
d62a17ae 4526 int idx_peer = 2;
4527 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4528}
6b0655a2 4529
d62a17ae 4530static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4531 afi_t afi, safi_t safi,
4532 const char *rmap, int set)
718e3744 4533{
d62a17ae 4534 int ret;
4535 struct peer *peer;
718e3744 4536
d62a17ae 4537 peer = peer_and_group_lookup_vty(vty, peer_str);
4538 if (!peer)
4539 return CMD_WARNING_CONFIG_FAILED;
718e3744 4540
d62a17ae 4541 if (set)
4542 ret = peer_default_originate_set(peer, afi, safi, rmap);
4543 else
4544 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4545
d62a17ae 4546 return bgp_vty_return(vty, ret);
718e3744 4547}
4548
4549/* neighbor default-originate. */
4550DEFUN (neighbor_default_originate,
4551 neighbor_default_originate_cmd,
9ccf14f7 4552 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4553 NEIGHBOR_STR
4554 NEIGHBOR_ADDR_STR2
4555 "Originate default route to this neighbor\n")
4556{
d62a17ae 4557 int idx_peer = 1;
4558 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4559 bgp_node_afi(vty),
4560 bgp_node_safi(vty), NULL, 1);
718e3744 4561}
4562
d62a17ae 4563ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4564 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4565 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4566 "Originate default route to this neighbor\n")
596c17ba 4567
718e3744 4568DEFUN (neighbor_default_originate_rmap,
4569 neighbor_default_originate_rmap_cmd,
9ccf14f7 4570 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4571 NEIGHBOR_STR
4572 NEIGHBOR_ADDR_STR2
4573 "Originate default route to this neighbor\n"
4574 "Route-map to specify criteria to originate default\n"
4575 "route-map name\n")
4576{
d62a17ae 4577 int idx_peer = 1;
4578 int idx_word = 4;
4579 return peer_default_originate_set_vty(
4580 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4581 argv[idx_word]->arg, 1);
718e3744 4582}
4583
d62a17ae 4584ALIAS_HIDDEN(
4585 neighbor_default_originate_rmap,
4586 neighbor_default_originate_rmap_hidden_cmd,
4587 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4588 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4589 "Originate default route to this neighbor\n"
4590 "Route-map to specify criteria to originate default\n"
4591 "route-map name\n")
596c17ba 4592
718e3744 4593DEFUN (no_neighbor_default_originate,
4594 no_neighbor_default_originate_cmd,
a636c635 4595 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4596 NO_STR
4597 NEIGHBOR_STR
4598 NEIGHBOR_ADDR_STR2
a636c635
DW
4599 "Originate default route to this neighbor\n"
4600 "Route-map to specify criteria to originate default\n"
4601 "route-map name\n")
718e3744 4602{
d62a17ae 4603 int idx_peer = 2;
4604 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4605 bgp_node_afi(vty),
4606 bgp_node_safi(vty), NULL, 0);
718e3744 4607}
4608
d62a17ae 4609ALIAS_HIDDEN(
4610 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4611 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4612 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4613 "Originate default route to this neighbor\n"
4614 "Route-map to specify criteria to originate default\n"
4615 "route-map name\n")
596c17ba 4616
6b0655a2 4617
718e3744 4618/* Set neighbor's BGP port. */
d62a17ae 4619static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4620 const char *port_str)
4621{
4622 struct peer *peer;
4623 u_int16_t port;
4624 struct servent *sp;
4625
4626 peer = peer_lookup_vty(vty, ip_str);
4627 if (!peer)
4628 return CMD_WARNING_CONFIG_FAILED;
4629
4630 if (!port_str) {
4631 sp = getservbyname("bgp", "tcp");
4632 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4633 } else {
4634 port = strtoul(port_str, NULL, 10);
4635 }
718e3744 4636
d62a17ae 4637 peer_port_set(peer, port);
718e3744 4638
d62a17ae 4639 return CMD_SUCCESS;
718e3744 4640}
4641
f418446b 4642/* Set specified peer's BGP port. */
718e3744 4643DEFUN (neighbor_port,
4644 neighbor_port_cmd,
9ccf14f7 4645 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4646 NEIGHBOR_STR
4647 NEIGHBOR_ADDR_STR
4648 "Neighbor's BGP port\n"
4649 "TCP port number\n")
4650{
d62a17ae 4651 int idx_ip = 1;
4652 int idx_number = 3;
4653 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4654 argv[idx_number]->arg);
718e3744 4655}
4656
4657DEFUN (no_neighbor_port,
4658 no_neighbor_port_cmd,
9ccf14f7 4659 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4660 NO_STR
4661 NEIGHBOR_STR
4662 NEIGHBOR_ADDR_STR
8334fd5a
DW
4663 "Neighbor's BGP port\n"
4664 "TCP port number\n")
718e3744 4665{
d62a17ae 4666 int idx_ip = 2;
4667 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4668}
4669
6b0655a2 4670
718e3744 4671/* neighbor weight. */
d62a17ae 4672static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4673 safi_t safi, const char *weight_str)
718e3744 4674{
d62a17ae 4675 int ret;
4676 struct peer *peer;
4677 unsigned long weight;
718e3744 4678
d62a17ae 4679 peer = peer_and_group_lookup_vty(vty, ip_str);
4680 if (!peer)
4681 return CMD_WARNING_CONFIG_FAILED;
718e3744 4682
d62a17ae 4683 weight = strtoul(weight_str, NULL, 10);
718e3744 4684
d62a17ae 4685 ret = peer_weight_set(peer, afi, safi, weight);
4686 return bgp_vty_return(vty, ret);
718e3744 4687}
4688
d62a17ae 4689static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4690 safi_t safi)
718e3744 4691{
d62a17ae 4692 int ret;
4693 struct peer *peer;
718e3744 4694
d62a17ae 4695 peer = peer_and_group_lookup_vty(vty, ip_str);
4696 if (!peer)
4697 return CMD_WARNING_CONFIG_FAILED;
718e3744 4698
d62a17ae 4699 ret = peer_weight_unset(peer, afi, safi);
4700 return bgp_vty_return(vty, ret);
718e3744 4701}
4702
4703DEFUN (neighbor_weight,
4704 neighbor_weight_cmd,
9ccf14f7 4705 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4706 NEIGHBOR_STR
4707 NEIGHBOR_ADDR_STR2
4708 "Set default weight for routes from this neighbor\n"
4709 "default weight\n")
4710{
d62a17ae 4711 int idx_peer = 1;
4712 int idx_number = 3;
4713 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4714 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4715}
4716
d62a17ae 4717ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4718 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4719 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4720 "Set default weight for routes from this neighbor\n"
4721 "default weight\n")
596c17ba 4722
718e3744 4723DEFUN (no_neighbor_weight,
4724 no_neighbor_weight_cmd,
9ccf14f7 4725 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4726 NO_STR
4727 NEIGHBOR_STR
4728 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4729 "Set default weight for routes from this neighbor\n"
4730 "default weight\n")
718e3744 4731{
d62a17ae 4732 int idx_peer = 2;
4733 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4734 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4735}
4736
d62a17ae 4737ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4738 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4739 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4740 "Set default weight for routes from this neighbor\n"
4741 "default weight\n")
596c17ba 4742
6b0655a2 4743
718e3744 4744/* Override capability negotiation. */
4745DEFUN (neighbor_override_capability,
4746 neighbor_override_capability_cmd,
9ccf14f7 4747 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4748 NEIGHBOR_STR
4749 NEIGHBOR_ADDR_STR2
4750 "Override capability negotiation result\n")
4751{
d62a17ae 4752 int idx_peer = 1;
4753 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4754 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4755}
4756
4757DEFUN (no_neighbor_override_capability,
4758 no_neighbor_override_capability_cmd,
9ccf14f7 4759 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4760 NO_STR
4761 NEIGHBOR_STR
4762 NEIGHBOR_ADDR_STR2
4763 "Override capability negotiation result\n")
4764{
d62a17ae 4765 int idx_peer = 2;
4766 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4767 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4768}
6b0655a2 4769
718e3744 4770DEFUN (neighbor_strict_capability,
4771 neighbor_strict_capability_cmd,
9ccf14f7 4772 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4773 NEIGHBOR_STR
4774 NEIGHBOR_ADDR_STR
4775 "Strict capability negotiation match\n")
4776{
d62a17ae 4777 int idx_ip = 1;
4778 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4779 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4780}
4781
4782DEFUN (no_neighbor_strict_capability,
4783 no_neighbor_strict_capability_cmd,
9ccf14f7 4784 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4785 NO_STR
4786 NEIGHBOR_STR
4787 NEIGHBOR_ADDR_STR
4788 "Strict capability negotiation match\n")
4789{
d62a17ae 4790 int idx_ip = 2;
4791 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4792 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4793}
6b0655a2 4794
d62a17ae 4795static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4796 const char *keep_str, const char *hold_str)
718e3744 4797{
d62a17ae 4798 int ret;
4799 struct peer *peer;
4800 u_int32_t keepalive;
4801 u_int32_t holdtime;
718e3744 4802
d62a17ae 4803 peer = peer_and_group_lookup_vty(vty, ip_str);
4804 if (!peer)
4805 return CMD_WARNING_CONFIG_FAILED;
718e3744 4806
d62a17ae 4807 keepalive = strtoul(keep_str, NULL, 10);
4808 holdtime = strtoul(hold_str, NULL, 10);
718e3744 4809
d62a17ae 4810 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 4811
d62a17ae 4812 return bgp_vty_return(vty, ret);
718e3744 4813}
6b0655a2 4814
d62a17ae 4815static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4816{
d62a17ae 4817 int ret;
4818 struct peer *peer;
718e3744 4819
d62a17ae 4820 peer = peer_and_group_lookup_vty(vty, ip_str);
4821 if (!peer)
4822 return CMD_WARNING_CONFIG_FAILED;
718e3744 4823
d62a17ae 4824 ret = peer_timers_unset(peer);
718e3744 4825
d62a17ae 4826 return bgp_vty_return(vty, ret);
718e3744 4827}
4828
4829DEFUN (neighbor_timers,
4830 neighbor_timers_cmd,
9ccf14f7 4831 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 4832 NEIGHBOR_STR
4833 NEIGHBOR_ADDR_STR2
4834 "BGP per neighbor timers\n"
4835 "Keepalive interval\n"
4836 "Holdtime\n")
4837{
d62a17ae 4838 int idx_peer = 1;
4839 int idx_number = 3;
4840 int idx_number_2 = 4;
4841 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4842 argv[idx_number]->arg,
4843 argv[idx_number_2]->arg);
718e3744 4844}
4845
4846DEFUN (no_neighbor_timers,
4847 no_neighbor_timers_cmd,
9ccf14f7 4848 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 4849 NO_STR
4850 NEIGHBOR_STR
4851 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4852 "BGP per neighbor timers\n"
4853 "Keepalive interval\n"
4854 "Holdtime\n")
718e3744 4855{
d62a17ae 4856 int idx_peer = 2;
4857 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4858}
6b0655a2 4859
813d4307 4860
d62a17ae 4861static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
4862 const char *time_str)
718e3744 4863{
d62a17ae 4864 int ret;
4865 struct peer *peer;
4866 u_int32_t connect;
718e3744 4867
d62a17ae 4868 peer = peer_and_group_lookup_vty(vty, ip_str);
4869 if (!peer)
4870 return CMD_WARNING_CONFIG_FAILED;
718e3744 4871
d62a17ae 4872 connect = strtoul(time_str, NULL, 10);
718e3744 4873
d62a17ae 4874 ret = peer_timers_connect_set(peer, connect);
718e3744 4875
d62a17ae 4876 return bgp_vty_return(vty, ret);
718e3744 4877}
4878
d62a17ae 4879static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4880{
d62a17ae 4881 int ret;
4882 struct peer *peer;
718e3744 4883
d62a17ae 4884 peer = peer_and_group_lookup_vty(vty, ip_str);
4885 if (!peer)
4886 return CMD_WARNING_CONFIG_FAILED;
718e3744 4887
d62a17ae 4888 ret = peer_timers_connect_unset(peer);
718e3744 4889
d62a17ae 4890 return bgp_vty_return(vty, ret);
718e3744 4891}
4892
4893DEFUN (neighbor_timers_connect,
4894 neighbor_timers_connect_cmd,
9ccf14f7 4895 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 4896 NEIGHBOR_STR
966f821c 4897 NEIGHBOR_ADDR_STR2
718e3744 4898 "BGP per neighbor timers\n"
4899 "BGP connect timer\n"
4900 "Connect timer\n")
4901{
d62a17ae 4902 int idx_peer = 1;
4903 int idx_number = 4;
4904 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
4905 argv[idx_number]->arg);
718e3744 4906}
4907
4908DEFUN (no_neighbor_timers_connect,
4909 no_neighbor_timers_connect_cmd,
9ccf14f7 4910 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 4911 NO_STR
4912 NEIGHBOR_STR
966f821c 4913 NEIGHBOR_ADDR_STR2
718e3744 4914 "BGP per neighbor timers\n"
8334fd5a
DW
4915 "BGP connect timer\n"
4916 "Connect timer\n")
718e3744 4917{
d62a17ae 4918 int idx_peer = 2;
4919 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4920}
4921
6b0655a2 4922
d62a17ae 4923static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
4924 const char *time_str, int set)
718e3744 4925{
d62a17ae 4926 int ret;
4927 struct peer *peer;
4928 u_int32_t routeadv = 0;
718e3744 4929
d62a17ae 4930 peer = peer_and_group_lookup_vty(vty, ip_str);
4931 if (!peer)
4932 return CMD_WARNING_CONFIG_FAILED;
718e3744 4933
d62a17ae 4934 if (time_str)
4935 routeadv = strtoul(time_str, NULL, 10);
718e3744 4936
d62a17ae 4937 if (set)
4938 ret = peer_advertise_interval_set(peer, routeadv);
4939 else
4940 ret = peer_advertise_interval_unset(peer);
718e3744 4941
d62a17ae 4942 return bgp_vty_return(vty, ret);
718e3744 4943}
4944
4945DEFUN (neighbor_advertise_interval,
4946 neighbor_advertise_interval_cmd,
9ccf14f7 4947 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 4948 NEIGHBOR_STR
966f821c 4949 NEIGHBOR_ADDR_STR2
718e3744 4950 "Minimum interval between sending BGP routing updates\n"
4951 "time in seconds\n")
4952{
d62a17ae 4953 int idx_peer = 1;
4954 int idx_number = 3;
4955 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
4956 argv[idx_number]->arg, 1);
718e3744 4957}
4958
4959DEFUN (no_neighbor_advertise_interval,
4960 no_neighbor_advertise_interval_cmd,
9ccf14f7 4961 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 4962 NO_STR
4963 NEIGHBOR_STR
966f821c 4964 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4965 "Minimum interval between sending BGP routing updates\n"
4966 "time in seconds\n")
718e3744 4967{
d62a17ae 4968 int idx_peer = 2;
4969 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 4970}
4971
6b0655a2 4972
518f0eb1
DS
4973/* Time to wait before processing route-map updates */
4974DEFUN (bgp_set_route_map_delay_timer,
4975 bgp_set_route_map_delay_timer_cmd,
6147e2c6 4976 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
4977 SET_STR
4978 "BGP route-map delay timer\n"
4979 "Time in secs to wait before processing route-map changes\n"
f414725f 4980 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 4981{
d62a17ae 4982 int idx_number = 3;
4983 u_int32_t rmap_delay_timer;
4984
4985 if (argv[idx_number]->arg) {
4986 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
4987 bm->rmap_update_timer = rmap_delay_timer;
4988
4989 /* if the dynamic update handling is being disabled, and a timer
4990 * is
4991 * running, stop the timer and act as if the timer has already
4992 * fired.
4993 */
4994 if (!rmap_delay_timer && bm->t_rmap_update) {
4995 BGP_TIMER_OFF(bm->t_rmap_update);
4996 thread_execute(bm->master, bgp_route_map_update_timer,
4997 NULL, 0);
4998 }
4999 return CMD_SUCCESS;
5000 } else {
5001 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5002 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5003 }
518f0eb1
DS
5004}
5005
5006DEFUN (no_bgp_set_route_map_delay_timer,
5007 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5008 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5009 NO_STR
3a2d747c 5010 BGP_STR
518f0eb1 5011 "Default BGP route-map delay timer\n"
8334fd5a
DW
5012 "Reset to default time to wait for processing route-map changes\n"
5013 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5014{
518f0eb1 5015
d62a17ae 5016 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5017
d62a17ae 5018 return CMD_SUCCESS;
518f0eb1
DS
5019}
5020
f414725f 5021
718e3744 5022/* neighbor interface */
d62a17ae 5023static int peer_interface_vty(struct vty *vty, const char *ip_str,
5024 const char *str)
718e3744 5025{
d62a17ae 5026 struct peer *peer;
718e3744 5027
d62a17ae 5028 peer = peer_lookup_vty(vty, ip_str);
5029 if (!peer || peer->conf_if) {
5030 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5031 return CMD_WARNING_CONFIG_FAILED;
5032 }
718e3744 5033
d62a17ae 5034 if (str)
5035 peer_interface_set(peer, str);
5036 else
5037 peer_interface_unset(peer);
718e3744 5038
d62a17ae 5039 return CMD_SUCCESS;
718e3744 5040}
5041
5042DEFUN (neighbor_interface,
5043 neighbor_interface_cmd,
9ccf14f7 5044 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5045 NEIGHBOR_STR
5046 NEIGHBOR_ADDR_STR
5047 "Interface\n"
5048 "Interface name\n")
5049{
d62a17ae 5050 int idx_ip = 1;
5051 int idx_word = 3;
5052 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5053}
5054
5055DEFUN (no_neighbor_interface,
5056 no_neighbor_interface_cmd,
9ccf14f7 5057 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5058 NO_STR
5059 NEIGHBOR_STR
16cedbb0 5060 NEIGHBOR_ADDR_STR2
718e3744 5061 "Interface\n"
5062 "Interface name\n")
5063{
d62a17ae 5064 int idx_peer = 2;
5065 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5066}
6b0655a2 5067
718e3744 5068DEFUN (neighbor_distribute_list,
5069 neighbor_distribute_list_cmd,
9ccf14f7 5070 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5071 NEIGHBOR_STR
5072 NEIGHBOR_ADDR_STR2
5073 "Filter updates to/from this neighbor\n"
5074 "IP access-list number\n"
5075 "IP access-list number (expanded range)\n"
5076 "IP Access-list name\n"
5077 "Filter incoming updates\n"
5078 "Filter outgoing updates\n")
5079{
d62a17ae 5080 int idx_peer = 1;
5081 int idx_acl = 3;
5082 int direct, ret;
5083 struct peer *peer;
a8206004 5084
d62a17ae 5085 const char *pstr = argv[idx_peer]->arg;
5086 const char *acl = argv[idx_acl]->arg;
5087 const char *inout = argv[argc - 1]->text;
a8206004 5088
d62a17ae 5089 peer = peer_and_group_lookup_vty(vty, pstr);
5090 if (!peer)
5091 return CMD_WARNING_CONFIG_FAILED;
a8206004 5092
d62a17ae 5093 /* Check filter direction. */
5094 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5095 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5096 direct, acl);
a8206004 5097
d62a17ae 5098 return bgp_vty_return(vty, ret);
718e3744 5099}
5100
d62a17ae 5101ALIAS_HIDDEN(
5102 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5103 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5104 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5105 "Filter updates to/from this neighbor\n"
5106 "IP access-list number\n"
5107 "IP access-list number (expanded range)\n"
5108 "IP Access-list name\n"
5109 "Filter incoming updates\n"
5110 "Filter outgoing updates\n")
596c17ba 5111
718e3744 5112DEFUN (no_neighbor_distribute_list,
5113 no_neighbor_distribute_list_cmd,
9ccf14f7 5114 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5115 NO_STR
5116 NEIGHBOR_STR
5117 NEIGHBOR_ADDR_STR2
5118 "Filter updates to/from this neighbor\n"
5119 "IP access-list number\n"
5120 "IP access-list number (expanded range)\n"
5121 "IP Access-list name\n"
5122 "Filter incoming updates\n"
5123 "Filter outgoing updates\n")
5124{
d62a17ae 5125 int idx_peer = 2;
5126 int direct, ret;
5127 struct peer *peer;
a8206004 5128
d62a17ae 5129 const char *pstr = argv[idx_peer]->arg;
5130 const char *inout = argv[argc - 1]->text;
a8206004 5131
d62a17ae 5132 peer = peer_and_group_lookup_vty(vty, pstr);
5133 if (!peer)
5134 return CMD_WARNING_CONFIG_FAILED;
a8206004 5135
d62a17ae 5136 /* Check filter direction. */
5137 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5138 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5139 direct);
a8206004 5140
d62a17ae 5141 return bgp_vty_return(vty, ret);
718e3744 5142}
6b0655a2 5143
d62a17ae 5144ALIAS_HIDDEN(
5145 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5146 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5147 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5148 "Filter updates to/from this neighbor\n"
5149 "IP access-list number\n"
5150 "IP access-list number (expanded range)\n"
5151 "IP Access-list name\n"
5152 "Filter incoming updates\n"
5153 "Filter outgoing updates\n")
596c17ba 5154
718e3744 5155/* Set prefix list to the peer. */
d62a17ae 5156static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5157 afi_t afi, safi_t safi,
5158 const char *name_str,
5159 const char *direct_str)
718e3744 5160{
d62a17ae 5161 int ret;
5162 struct peer *peer;
5163 int direct = FILTER_IN;
718e3744 5164
d62a17ae 5165 peer = peer_and_group_lookup_vty(vty, ip_str);
5166 if (!peer)
5167 return CMD_WARNING_CONFIG_FAILED;
718e3744 5168
d62a17ae 5169 /* Check filter direction. */
5170 if (strncmp(direct_str, "i", 1) == 0)
5171 direct = FILTER_IN;
5172 else if (strncmp(direct_str, "o", 1) == 0)
5173 direct = FILTER_OUT;
718e3744 5174
d62a17ae 5175 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5176
d62a17ae 5177 return bgp_vty_return(vty, ret);
718e3744 5178}
5179
d62a17ae 5180static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5181 afi_t afi, safi_t safi,
5182 const char *direct_str)
718e3744 5183{
d62a17ae 5184 int ret;
5185 struct peer *peer;
5186 int direct = FILTER_IN;
718e3744 5187
d62a17ae 5188 peer = peer_and_group_lookup_vty(vty, ip_str);
5189 if (!peer)
5190 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5191
d62a17ae 5192 /* Check filter direction. */
5193 if (strncmp(direct_str, "i", 1) == 0)
5194 direct = FILTER_IN;
5195 else if (strncmp(direct_str, "o", 1) == 0)
5196 direct = FILTER_OUT;
718e3744 5197
d62a17ae 5198 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5199
d62a17ae 5200 return bgp_vty_return(vty, ret);
718e3744 5201}
5202
5203DEFUN (neighbor_prefix_list,
5204 neighbor_prefix_list_cmd,
9ccf14f7 5205 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5206 NEIGHBOR_STR
5207 NEIGHBOR_ADDR_STR2
5208 "Filter updates to/from this neighbor\n"
5209 "Name of a prefix list\n"
5210 "Filter incoming updates\n"
5211 "Filter outgoing updates\n")
5212{
d62a17ae 5213 int idx_peer = 1;
5214 int idx_word = 3;
5215 int idx_in_out = 4;
5216 return peer_prefix_list_set_vty(
5217 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5218 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5219}
5220
d62a17ae 5221ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5222 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5223 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5224 "Filter updates to/from this neighbor\n"
5225 "Name of a prefix list\n"
5226 "Filter incoming updates\n"
5227 "Filter outgoing updates\n")
596c17ba 5228
718e3744 5229DEFUN (no_neighbor_prefix_list,
5230 no_neighbor_prefix_list_cmd,
9ccf14f7 5231 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5232 NO_STR
5233 NEIGHBOR_STR
5234 NEIGHBOR_ADDR_STR2
5235 "Filter updates to/from this neighbor\n"
5236 "Name of a prefix list\n"
5237 "Filter incoming updates\n"
5238 "Filter outgoing updates\n")
5239{
d62a17ae 5240 int idx_peer = 2;
5241 int idx_in_out = 5;
5242 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5243 bgp_node_afi(vty), bgp_node_safi(vty),
5244 argv[idx_in_out]->arg);
718e3744 5245}
6b0655a2 5246
d62a17ae 5247ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5248 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5249 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5250 "Filter updates to/from this neighbor\n"
5251 "Name of a prefix list\n"
5252 "Filter incoming updates\n"
5253 "Filter outgoing updates\n")
596c17ba 5254
d62a17ae 5255static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5256 safi_t safi, const char *name_str,
5257 const char *direct_str)
718e3744 5258{
d62a17ae 5259 int ret;
5260 struct peer *peer;
5261 int direct = FILTER_IN;
718e3744 5262
d62a17ae 5263 peer = peer_and_group_lookup_vty(vty, ip_str);
5264 if (!peer)
5265 return CMD_WARNING_CONFIG_FAILED;
718e3744 5266
d62a17ae 5267 /* Check filter direction. */
5268 if (strncmp(direct_str, "i", 1) == 0)
5269 direct = FILTER_IN;
5270 else if (strncmp(direct_str, "o", 1) == 0)
5271 direct = FILTER_OUT;
718e3744 5272
d62a17ae 5273 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5274
d62a17ae 5275 return bgp_vty_return(vty, ret);
718e3744 5276}
5277
d62a17ae 5278static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5279 safi_t safi, const char *direct_str)
718e3744 5280{
d62a17ae 5281 int ret;
5282 struct peer *peer;
5283 int direct = FILTER_IN;
718e3744 5284
d62a17ae 5285 peer = peer_and_group_lookup_vty(vty, ip_str);
5286 if (!peer)
5287 return CMD_WARNING_CONFIG_FAILED;
718e3744 5288
d62a17ae 5289 /* Check filter direction. */
5290 if (strncmp(direct_str, "i", 1) == 0)
5291 direct = FILTER_IN;
5292 else if (strncmp(direct_str, "o", 1) == 0)
5293 direct = FILTER_OUT;
718e3744 5294
d62a17ae 5295 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5296
d62a17ae 5297 return bgp_vty_return(vty, ret);
718e3744 5298}
5299
5300DEFUN (neighbor_filter_list,
5301 neighbor_filter_list_cmd,
9ccf14f7 5302 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5303 NEIGHBOR_STR
5304 NEIGHBOR_ADDR_STR2
5305 "Establish BGP filters\n"
5306 "AS path access-list name\n"
5307 "Filter incoming routes\n"
5308 "Filter outgoing routes\n")
5309{
d62a17ae 5310 int idx_peer = 1;
5311 int idx_word = 3;
5312 int idx_in_out = 4;
5313 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5314 bgp_node_safi(vty), argv[idx_word]->arg,
5315 argv[idx_in_out]->arg);
718e3744 5316}
5317
d62a17ae 5318ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5319 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5320 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5321 "Establish BGP filters\n"
5322 "AS path access-list name\n"
5323 "Filter incoming routes\n"
5324 "Filter outgoing routes\n")
596c17ba 5325
718e3744 5326DEFUN (no_neighbor_filter_list,
5327 no_neighbor_filter_list_cmd,
9ccf14f7 5328 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5329 NO_STR
5330 NEIGHBOR_STR
5331 NEIGHBOR_ADDR_STR2
5332 "Establish BGP filters\n"
5333 "AS path access-list name\n"
5334 "Filter incoming routes\n"
5335 "Filter outgoing routes\n")
5336{
d62a17ae 5337 int idx_peer = 2;
5338 int idx_in_out = 5;
5339 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5340 bgp_node_afi(vty), bgp_node_safi(vty),
5341 argv[idx_in_out]->arg);
718e3744 5342}
6b0655a2 5343
d62a17ae 5344ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5345 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5346 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5347 "Establish BGP filters\n"
5348 "AS path access-list name\n"
5349 "Filter incoming routes\n"
5350 "Filter outgoing routes\n")
596c17ba 5351
718e3744 5352/* Set route-map to the peer. */
d62a17ae 5353static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5354 afi_t afi, safi_t safi, const char *name_str,
5355 const char *direct_str)
718e3744 5356{
d62a17ae 5357 int ret;
5358 struct peer *peer;
5359 int direct = RMAP_IN;
718e3744 5360
d62a17ae 5361 peer = peer_and_group_lookup_vty(vty, ip_str);
5362 if (!peer)
5363 return CMD_WARNING_CONFIG_FAILED;
718e3744 5364
d62a17ae 5365 /* Check filter direction. */
5366 if (strncmp(direct_str, "in", 2) == 0)
5367 direct = RMAP_IN;
5368 else if (strncmp(direct_str, "o", 1) == 0)
5369 direct = RMAP_OUT;
718e3744 5370
d62a17ae 5371 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5372
d62a17ae 5373 return bgp_vty_return(vty, ret);
718e3744 5374}
5375
d62a17ae 5376static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5377 afi_t afi, safi_t safi,
5378 const char *direct_str)
718e3744 5379{
d62a17ae 5380 int ret;
5381 struct peer *peer;
5382 int direct = RMAP_IN;
718e3744 5383
d62a17ae 5384 peer = peer_and_group_lookup_vty(vty, ip_str);
5385 if (!peer)
5386 return CMD_WARNING_CONFIG_FAILED;
718e3744 5387
d62a17ae 5388 /* Check filter direction. */
5389 if (strncmp(direct_str, "in", 2) == 0)
5390 direct = RMAP_IN;
5391 else if (strncmp(direct_str, "o", 1) == 0)
5392 direct = RMAP_OUT;
718e3744 5393
d62a17ae 5394 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5395
d62a17ae 5396 return bgp_vty_return(vty, ret);
718e3744 5397}
5398
5399DEFUN (neighbor_route_map,
5400 neighbor_route_map_cmd,
9ccf14f7 5401 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5402 NEIGHBOR_STR
5403 NEIGHBOR_ADDR_STR2
5404 "Apply route map to neighbor\n"
5405 "Name of route map\n"
5406 "Apply map to incoming routes\n"
2a3d5731 5407 "Apply map to outbound routes\n")
718e3744 5408{
d62a17ae 5409 int idx_peer = 1;
5410 int idx_word = 3;
5411 int idx_in_out = 4;
5412 return peer_route_map_set_vty(
5413 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5414 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5415}
5416
d62a17ae 5417ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5418 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5419 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5420 "Apply route map to neighbor\n"
5421 "Name of route map\n"
5422 "Apply map to incoming routes\n"
5423 "Apply map to outbound routes\n")
596c17ba 5424
718e3744 5425DEFUN (no_neighbor_route_map,
5426 no_neighbor_route_map_cmd,
9ccf14f7 5427 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5428 NO_STR
5429 NEIGHBOR_STR
5430 NEIGHBOR_ADDR_STR2
5431 "Apply route map to neighbor\n"
5432 "Name of route map\n"
5433 "Apply map to incoming routes\n"
2a3d5731 5434 "Apply map to outbound routes\n")
718e3744 5435{
d62a17ae 5436 int idx_peer = 2;
5437 int idx_in_out = 5;
5438 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5439 bgp_node_afi(vty), bgp_node_safi(vty),
5440 argv[idx_in_out]->arg);
718e3744 5441}
6b0655a2 5442
d62a17ae 5443ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5444 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5445 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5446 "Apply route map to neighbor\n"
5447 "Name of route map\n"
5448 "Apply map to incoming routes\n"
5449 "Apply map to outbound routes\n")
596c17ba 5450
718e3744 5451/* Set unsuppress-map to the peer. */
d62a17ae 5452static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5453 afi_t afi, safi_t safi,
5454 const char *name_str)
718e3744 5455{
d62a17ae 5456 int ret;
5457 struct peer *peer;
718e3744 5458
d62a17ae 5459 peer = peer_and_group_lookup_vty(vty, ip_str);
5460 if (!peer)
5461 return CMD_WARNING_CONFIG_FAILED;
718e3744 5462
d62a17ae 5463 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5464
d62a17ae 5465 return bgp_vty_return(vty, ret);
718e3744 5466}
5467
5468/* Unset route-map from the peer. */
d62a17ae 5469static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5470 afi_t afi, safi_t safi)
718e3744 5471{
d62a17ae 5472 int ret;
5473 struct peer *peer;
718e3744 5474
d62a17ae 5475 peer = peer_and_group_lookup_vty(vty, ip_str);
5476 if (!peer)
5477 return CMD_WARNING_CONFIG_FAILED;
718e3744 5478
d62a17ae 5479 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5480
d62a17ae 5481 return bgp_vty_return(vty, ret);
718e3744 5482}
5483
5484DEFUN (neighbor_unsuppress_map,
5485 neighbor_unsuppress_map_cmd,
9ccf14f7 5486 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5487 NEIGHBOR_STR
5488 NEIGHBOR_ADDR_STR2
5489 "Route-map to selectively unsuppress suppressed routes\n"
5490 "Name of route map\n")
5491{
d62a17ae 5492 int idx_peer = 1;
5493 int idx_word = 3;
5494 return peer_unsuppress_map_set_vty(
5495 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5496 argv[idx_word]->arg);
718e3744 5497}
5498
d62a17ae 5499ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5500 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5501 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5502 "Route-map to selectively unsuppress suppressed routes\n"
5503 "Name of route map\n")
596c17ba 5504
718e3744 5505DEFUN (no_neighbor_unsuppress_map,
5506 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5507 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5508 NO_STR
5509 NEIGHBOR_STR
5510 NEIGHBOR_ADDR_STR2
5511 "Route-map to selectively unsuppress suppressed routes\n"
5512 "Name of route map\n")
5513{
d62a17ae 5514 int idx_peer = 2;
5515 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5516 bgp_node_afi(vty),
5517 bgp_node_safi(vty));
718e3744 5518}
6b0655a2 5519
d62a17ae 5520ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5521 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5522 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5523 "Route-map to selectively unsuppress suppressed routes\n"
5524 "Name of route map\n")
596c17ba 5525
d62a17ae 5526static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5527 afi_t afi, safi_t safi,
5528 const char *num_str,
5529 const char *threshold_str, int warning,
5530 const char *restart_str)
718e3744 5531{
d62a17ae 5532 int ret;
5533 struct peer *peer;
5534 u_int32_t max;
5535 u_char threshold;
5536 u_int16_t restart;
718e3744 5537
d62a17ae 5538 peer = peer_and_group_lookup_vty(vty, ip_str);
5539 if (!peer)
5540 return CMD_WARNING_CONFIG_FAILED;
718e3744 5541
d62a17ae 5542 max = strtoul(num_str, NULL, 10);
5543 if (threshold_str)
5544 threshold = atoi(threshold_str);
5545 else
5546 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5547
d62a17ae 5548 if (restart_str)
5549 restart = atoi(restart_str);
5550 else
5551 restart = 0;
0a486e5f 5552
d62a17ae 5553 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5554 restart);
718e3744 5555
d62a17ae 5556 return bgp_vty_return(vty, ret);
718e3744 5557}
5558
d62a17ae 5559static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5560 afi_t afi, safi_t safi)
718e3744 5561{
d62a17ae 5562 int ret;
5563 struct peer *peer;
718e3744 5564
d62a17ae 5565 peer = peer_and_group_lookup_vty(vty, ip_str);
5566 if (!peer)
5567 return CMD_WARNING_CONFIG_FAILED;
718e3744 5568
d62a17ae 5569 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5570
d62a17ae 5571 return bgp_vty_return(vty, ret);
718e3744 5572}
5573
5574/* Maximum number of prefix configuration. prefix count is different
5575 for each peer configuration. So this configuration can be set for
5576 each peer configuration. */
5577DEFUN (neighbor_maximum_prefix,
5578 neighbor_maximum_prefix_cmd,
9ccf14f7 5579 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5580 NEIGHBOR_STR
5581 NEIGHBOR_ADDR_STR2
5582 "Maximum number of prefix accept from this peer\n"
5583 "maximum no. of prefix limit\n")
5584{
d62a17ae 5585 int idx_peer = 1;
5586 int idx_number = 3;
5587 return peer_maximum_prefix_set_vty(
5588 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5589 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5590}
5591
d62a17ae 5592ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5593 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5594 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5595 "Maximum number of prefix accept from this peer\n"
5596 "maximum no. of prefix limit\n")
596c17ba 5597
e0701b79 5598DEFUN (neighbor_maximum_prefix_threshold,
5599 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5600 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5601 NEIGHBOR_STR
5602 NEIGHBOR_ADDR_STR2
5603 "Maximum number of prefix accept from this peer\n"
5604 "maximum no. of prefix limit\n"
5605 "Threshold value (%) at which to generate a warning msg\n")
5606{
d62a17ae 5607 int idx_peer = 1;
5608 int idx_number = 3;
5609 int idx_number_2 = 4;
5610 return peer_maximum_prefix_set_vty(
5611 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5612 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5613}
e0701b79 5614
d62a17ae 5615ALIAS_HIDDEN(
5616 neighbor_maximum_prefix_threshold,
5617 neighbor_maximum_prefix_threshold_hidden_cmd,
5618 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5619 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5620 "Maximum number of prefix accept from this peer\n"
5621 "maximum no. of prefix limit\n"
5622 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5623
718e3744 5624DEFUN (neighbor_maximum_prefix_warning,
5625 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5626 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5627 NEIGHBOR_STR
5628 NEIGHBOR_ADDR_STR2
5629 "Maximum number of prefix accept from this peer\n"
5630 "maximum no. of prefix limit\n"
5631 "Only give warning message when limit is exceeded\n")
5632{
d62a17ae 5633 int idx_peer = 1;
5634 int idx_number = 3;
5635 return peer_maximum_prefix_set_vty(
5636 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5637 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5638}
5639
d62a17ae 5640ALIAS_HIDDEN(
5641 neighbor_maximum_prefix_warning,
5642 neighbor_maximum_prefix_warning_hidden_cmd,
5643 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5644 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5645 "Maximum number of prefix accept from this peer\n"
5646 "maximum no. of prefix limit\n"
5647 "Only give warning message when limit is exceeded\n")
596c17ba 5648
e0701b79 5649DEFUN (neighbor_maximum_prefix_threshold_warning,
5650 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5651 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5652 NEIGHBOR_STR
5653 NEIGHBOR_ADDR_STR2
5654 "Maximum number of prefix accept from this peer\n"
5655 "maximum no. of prefix limit\n"
5656 "Threshold value (%) at which to generate a warning msg\n"
5657 "Only give warning message when limit is exceeded\n")
5658{
d62a17ae 5659 int idx_peer = 1;
5660 int idx_number = 3;
5661 int idx_number_2 = 4;
5662 return peer_maximum_prefix_set_vty(
5663 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5664 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5665}
5666
d62a17ae 5667ALIAS_HIDDEN(
5668 neighbor_maximum_prefix_threshold_warning,
5669 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5670 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5671 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5672 "Maximum number of prefix accept from this peer\n"
5673 "maximum no. of prefix limit\n"
5674 "Threshold value (%) at which to generate a warning msg\n"
5675 "Only give warning message when limit is exceeded\n")
596c17ba 5676
0a486e5f 5677DEFUN (neighbor_maximum_prefix_restart,
5678 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5679 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5680 NEIGHBOR_STR
5681 NEIGHBOR_ADDR_STR2
5682 "Maximum number of prefix accept from this peer\n"
5683 "maximum no. of prefix limit\n"
5684 "Restart bgp connection after limit is exceeded\n"
5685 "Restart interval in minutes")
5686{
d62a17ae 5687 int idx_peer = 1;
5688 int idx_number = 3;
5689 int idx_number_2 = 5;
5690 return peer_maximum_prefix_set_vty(
5691 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5692 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5693}
5694
d62a17ae 5695ALIAS_HIDDEN(
5696 neighbor_maximum_prefix_restart,
5697 neighbor_maximum_prefix_restart_hidden_cmd,
5698 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5699 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5700 "Maximum number of prefix accept from this peer\n"
5701 "maximum no. of prefix limit\n"
5702 "Restart bgp connection after limit is exceeded\n"
5703 "Restart interval in minutes")
596c17ba 5704
0a486e5f 5705DEFUN (neighbor_maximum_prefix_threshold_restart,
5706 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5707 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5708 NEIGHBOR_STR
5709 NEIGHBOR_ADDR_STR2
16cedbb0 5710 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5711 "maximum no. of prefix limit\n"
5712 "Threshold value (%) at which to generate a warning msg\n"
5713 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5714 "Restart interval in minutes\n")
0a486e5f 5715{
d62a17ae 5716 int idx_peer = 1;
5717 int idx_number = 3;
5718 int idx_number_2 = 4;
5719 int idx_number_3 = 6;
5720 return peer_maximum_prefix_set_vty(
5721 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5722 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5723 argv[idx_number_3]->arg);
5724}
5725
5726ALIAS_HIDDEN(
5727 neighbor_maximum_prefix_threshold_restart,
5728 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5729 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5730 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5731 "Maximum number of prefixes to accept from this peer\n"
5732 "maximum no. of prefix limit\n"
5733 "Threshold value (%) at which to generate a warning msg\n"
5734 "Restart bgp connection after limit is exceeded\n"
5735 "Restart interval in minutes\n")
596c17ba 5736
718e3744 5737DEFUN (no_neighbor_maximum_prefix,
5738 no_neighbor_maximum_prefix_cmd,
d04c479d 5739 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5740 NO_STR
5741 NEIGHBOR_STR
5742 NEIGHBOR_ADDR_STR2
16cedbb0 5743 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5744 "maximum no. of prefix limit\n"
5745 "Threshold value (%) at which to generate a warning msg\n"
5746 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5747 "Restart interval in minutes\n"
31500417 5748 "Only give warning message when limit is exceeded\n")
718e3744 5749{
d62a17ae 5750 int idx_peer = 2;
5751 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5752 bgp_node_afi(vty),
5753 bgp_node_safi(vty));
718e3744 5754}
e52702f2 5755
d62a17ae 5756ALIAS_HIDDEN(
5757 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5758 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5759 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5760 "Maximum number of prefixes to accept from this peer\n"
5761 "maximum no. of prefix limit\n"
5762 "Threshold value (%) at which to generate a warning msg\n"
5763 "Restart bgp connection after limit is exceeded\n"
5764 "Restart interval in minutes\n"
5765 "Only give warning message when limit is exceeded\n")
596c17ba 5766
718e3744 5767
718e3744 5768/* "neighbor allowas-in" */
5769DEFUN (neighbor_allowas_in,
5770 neighbor_allowas_in_cmd,
fd8503f5 5771 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5772 NEIGHBOR_STR
5773 NEIGHBOR_ADDR_STR2
31500417 5774 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5775 "Number of occurances of AS number\n"
5776 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5777{
d62a17ae 5778 int idx_peer = 1;
5779 int idx_number_origin = 3;
5780 int ret;
5781 int origin = 0;
5782 struct peer *peer;
5783 int allow_num = 0;
5784
5785 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5786 if (!peer)
5787 return CMD_WARNING_CONFIG_FAILED;
5788
5789 if (argc <= idx_number_origin)
5790 allow_num = 3;
5791 else {
5792 if (argv[idx_number_origin]->type == WORD_TKN)
5793 origin = 1;
5794 else
5795 allow_num = atoi(argv[idx_number_origin]->arg);
5796 }
5797
5798 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5799 allow_num, origin);
5800
5801 return bgp_vty_return(vty, ret);
5802}
5803
5804ALIAS_HIDDEN(
5805 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5806 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5807 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5808 "Accept as-path with my AS present in it\n"
5809 "Number of occurances of AS number\n"
5810 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5811
718e3744 5812DEFUN (no_neighbor_allowas_in,
5813 no_neighbor_allowas_in_cmd,
fd8503f5 5814 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5815 NO_STR
5816 NEIGHBOR_STR
5817 NEIGHBOR_ADDR_STR2
8334fd5a 5818 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
5819 "Number of occurances of AS number\n"
5820 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5821{
d62a17ae 5822 int idx_peer = 2;
5823 int ret;
5824 struct peer *peer;
718e3744 5825
d62a17ae 5826 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5827 if (!peer)
5828 return CMD_WARNING_CONFIG_FAILED;
718e3744 5829
d62a17ae 5830 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5831 bgp_node_safi(vty));
718e3744 5832
d62a17ae 5833 return bgp_vty_return(vty, ret);
718e3744 5834}
6b0655a2 5835
d62a17ae 5836ALIAS_HIDDEN(
5837 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5838 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5839 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5840 "allow local ASN appears in aspath attribute\n"
5841 "Number of occurances of AS number\n"
5842 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5843
fa411a21
NH
5844DEFUN (neighbor_ttl_security,
5845 neighbor_ttl_security_cmd,
9ccf14f7 5846 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
5847 NEIGHBOR_STR
5848 NEIGHBOR_ADDR_STR2
16cedbb0 5849 "BGP ttl-security parameters\n"
d7fa34c1
QY
5850 "Specify the maximum number of hops to the BGP peer\n"
5851 "Number of hops to BGP peer\n")
fa411a21 5852{
d62a17ae 5853 int idx_peer = 1;
5854 int idx_number = 4;
5855 struct peer *peer;
5856 int gtsm_hops;
5857
5858 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5859 if (!peer)
5860 return CMD_WARNING_CONFIG_FAILED;
5861
5862 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
5863
5864 /*
5865 * If 'neighbor swpX', then this is for directly connected peers,
5866 * we should not accept a ttl-security hops value greater than 1.
5867 */
5868 if (peer->conf_if && (gtsm_hops > 1)) {
5869 vty_out(vty,
5870 "%s is directly connected peer, hops cannot exceed 1\n",
5871 argv[idx_peer]->arg);
5872 return CMD_WARNING_CONFIG_FAILED;
5873 }
8cdabf90 5874
d62a17ae 5875 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
5876}
5877
5878DEFUN (no_neighbor_ttl_security,
5879 no_neighbor_ttl_security_cmd,
9ccf14f7 5880 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
5881 NO_STR
5882 NEIGHBOR_STR
5883 NEIGHBOR_ADDR_STR2
16cedbb0 5884 "BGP ttl-security parameters\n"
3a2d747c
QY
5885 "Specify the maximum number of hops to the BGP peer\n"
5886 "Number of hops to BGP peer\n")
fa411a21 5887{
d62a17ae 5888 int idx_peer = 2;
5889 struct peer *peer;
fa411a21 5890
d62a17ae 5891 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5892 if (!peer)
5893 return CMD_WARNING_CONFIG_FAILED;
fa411a21 5894
d62a17ae 5895 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 5896}
6b0655a2 5897
adbac85e
DW
5898DEFUN (neighbor_addpath_tx_all_paths,
5899 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 5900 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
5901 NEIGHBOR_STR
5902 NEIGHBOR_ADDR_STR2
5903 "Use addpath to advertise all paths to a neighbor\n")
5904{
d62a17ae 5905 int idx_peer = 1;
5906 struct peer *peer;
adbac85e 5907
d62a17ae 5908 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5909 if (!peer)
5910 return CMD_WARNING_CONFIG_FAILED;
adbac85e 5911
d62a17ae 5912 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5913 bgp_node_safi(vty),
5914 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
5915}
5916
d62a17ae 5917ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
5918 neighbor_addpath_tx_all_paths_hidden_cmd,
5919 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
5920 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5921 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 5922
adbac85e
DW
5923DEFUN (no_neighbor_addpath_tx_all_paths,
5924 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 5925 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
5926 NO_STR
5927 NEIGHBOR_STR
5928 NEIGHBOR_ADDR_STR2
5929 "Use addpath to advertise all paths to a neighbor\n")
5930{
d62a17ae 5931 int idx_peer = 2;
5932 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5933 bgp_node_afi(vty), bgp_node_safi(vty),
5934 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
5935}
5936
d62a17ae 5937ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
5938 no_neighbor_addpath_tx_all_paths_hidden_cmd,
5939 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
5940 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5941 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 5942
06370dac
DW
5943DEFUN (neighbor_addpath_tx_bestpath_per_as,
5944 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 5945 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
5946 NEIGHBOR_STR
5947 NEIGHBOR_ADDR_STR2
5948 "Use addpath to advertise the bestpath per each neighboring AS\n")
5949{
d62a17ae 5950 int idx_peer = 1;
5951 struct peer *peer;
06370dac 5952
d62a17ae 5953 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5954 if (!peer)
5955 return CMD_WARNING_CONFIG_FAILED;
06370dac 5956
d62a17ae 5957 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5958 bgp_node_safi(vty),
5959 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
5960}
5961
d62a17ae 5962ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
5963 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
5964 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
5965 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5966 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 5967
06370dac
DW
5968DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
5969 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 5970 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
5971 NO_STR
5972 NEIGHBOR_STR
5973 NEIGHBOR_ADDR_STR2
5974 "Use addpath to advertise the bestpath per each neighboring AS\n")
5975{
d62a17ae 5976 int idx_peer = 2;
5977 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
5978 bgp_node_afi(vty), bgp_node_safi(vty),
5979 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
5980}
5981
d62a17ae 5982ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
5983 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
5984 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
5985 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5986 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 5987
505e5056 5988DEFUN_NOSH (address_family_ipv4_safi,
718e3744 5989 address_family_ipv4_safi_cmd,
5b1f0f29 5990 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 5991 "Enter Address Family command mode\n"
8c3deaae 5992 "Address Family\n"
b6ab5a3a 5993 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 5994{
f51bae9c 5995
d62a17ae 5996 if (argc == 3) {
5997 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
5998 vty->node = bgp_node_type(AFI_IP, safi);
5999 } else
6000 vty->node = BGP_IPV4_NODE;
718e3744 6001
d62a17ae 6002 return CMD_SUCCESS;
718e3744 6003}
6004
505e5056 6005DEFUN_NOSH (address_family_ipv6_safi,
25ffbdc1 6006 address_family_ipv6_safi_cmd,
5b1f0f29 6007 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6008 "Enter Address Family command mode\n"
8c3deaae 6009 "Address Family\n"
b6ab5a3a 6010 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6011{
d62a17ae 6012 if (argc == 3) {
6013 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
6014 vty->node = bgp_node_type(AFI_IP6, safi);
6015 } else
6016 vty->node = BGP_IPV6_NODE;
25ffbdc1 6017
d62a17ae 6018 return CMD_SUCCESS;
25ffbdc1 6019}
718e3744 6020
d6902373 6021#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6022DEFUN_NOSH (address_family_vpnv4,
718e3744 6023 address_family_vpnv4_cmd,
8334fd5a 6024 "address-family vpnv4 [unicast]",
718e3744 6025 "Enter Address Family command mode\n"
8c3deaae 6026 "Address Family\n"
3a2d747c 6027 "Address Family modifier\n")
718e3744 6028{
d62a17ae 6029 vty->node = BGP_VPNV4_NODE;
6030 return CMD_SUCCESS;
718e3744 6031}
6032
505e5056 6033DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6034 address_family_vpnv6_cmd,
8334fd5a 6035 "address-family vpnv6 [unicast]",
8ecd3266 6036 "Enter Address Family command mode\n"
8c3deaae 6037 "Address Family\n"
3a2d747c 6038 "Address Family modifier\n")
8ecd3266 6039{
d62a17ae 6040 vty->node = BGP_VPNV6_NODE;
6041 return CMD_SUCCESS;
8ecd3266 6042}
c016b6c7 6043#endif
d6902373 6044
505e5056 6045DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6046 address_family_evpn_cmd,
7111c1a0 6047 "address-family l2vpn evpn",
4e0b7b6d 6048 "Enter Address Family command mode\n"
7111c1a0
QY
6049 "Address Family\n"
6050 "Address Family modifier\n")
4e0b7b6d 6051{
d62a17ae 6052 vty->node = BGP_EVPN_NODE;
6053 return CMD_SUCCESS;
4e0b7b6d
PG
6054}
6055
505e5056 6056DEFUN_NOSH (exit_address_family,
718e3744 6057 exit_address_family_cmd,
6058 "exit-address-family",
6059 "Exit from Address Family configuration mode\n")
6060{
d62a17ae 6061 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6062 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6063 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6064 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6065 || vty->node == BGP_EVPN_NODE)
6066 vty->node = BGP_NODE;
6067 return CMD_SUCCESS;
718e3744 6068}
6b0655a2 6069
8ad7271d 6070/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6071static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6072 const char *ip_str, afi_t afi, safi_t safi,
6073 struct prefix_rd *prd)
6074{
6075 int ret;
6076 struct prefix match;
6077 struct bgp_node *rn;
6078 struct bgp_node *rm;
6079 struct bgp *bgp;
6080 struct bgp_table *table;
6081 struct bgp_table *rib;
6082
6083 /* BGP structure lookup. */
6084 if (view_name) {
6085 bgp = bgp_lookup_by_name(view_name);
6086 if (bgp == NULL) {
6087 vty_out(vty, "%% Can't find BGP instance %s\n",
6088 view_name);
6089 return CMD_WARNING;
6090 }
6091 } else {
6092 bgp = bgp_get_default();
6093 if (bgp == NULL) {
6094 vty_out(vty, "%% No BGP process is configured\n");
6095 return CMD_WARNING;
6096 }
6097 }
6098
6099 /* Check IP address argument. */
6100 ret = str2prefix(ip_str, &match);
6101 if (!ret) {
6102 vty_out(vty, "%% address is malformed\n");
6103 return CMD_WARNING;
6104 }
6105
6106 match.family = afi2family(afi);
6107 rib = bgp->rib[afi][safi];
6108
6109 if (safi == SAFI_MPLS_VPN) {
6110 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6111 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6112 continue;
6113
6114 if ((table = rn->info) != NULL) {
6115 if ((rm = bgp_node_match(table, &match))
6116 != NULL) {
6117 if (rm->p.prefixlen
6118 == match.prefixlen) {
6119 SET_FLAG(rn->flags,
6120 BGP_NODE_USER_CLEAR);
6121 bgp_process(bgp, rm, afi, safi);
6122 }
6123 bgp_unlock_node(rm);
6124 }
6125 }
6126 }
6127 } else {
6128 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6129 if (rn->p.prefixlen == match.prefixlen) {
6130 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6131 bgp_process(bgp, rn, afi, safi);
6132 }
6133 bgp_unlock_node(rn);
6134 }
6135 }
6136
6137 return CMD_SUCCESS;
8ad7271d
DS
6138}
6139
b09b5ae0 6140/* one clear bgp command to rule them all */
718e3744 6141DEFUN (clear_ip_bgp_all,
6142 clear_ip_bgp_all_cmd,
c1a44e43 6143 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_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 6144 CLEAR_STR
6145 IP_STR
6146 BGP_STR
838758ac 6147 BGP_INSTANCE_HELP_STR
b09b5ae0
DW
6148 "Clear all peers\n"
6149 "BGP neighbor address to clear\n"
a80beece 6150 "BGP IPv6 neighbor to clear\n"
838758ac 6151 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
6152 "Clear peers with the AS number\n"
6153 "Clear all external peers\n"
718e3744 6154 "Clear all members of peer-group\n"
b09b5ae0 6155 "BGP peer-group name\n"
46f296b4 6156 BGP_AFI_HELP_STR
9bedbb1e 6157 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
6158 BGP_SOFT_STR
6159 BGP_SOFT_IN_STR
b09b5ae0
DW
6160 BGP_SOFT_OUT_STR
6161 BGP_SOFT_IN_STR
6162 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 6163 BGP_SOFT_OUT_STR)
718e3744 6164{
d62a17ae 6165 char *vrf = NULL;
6166
6167 afi_t afi = AFI_IP6;
6168 safi_t safi = SAFI_UNICAST;
6169 enum clear_sort clr_sort = clear_peer;
6170 enum bgp_clear_type clr_type;
6171 char *clr_arg = NULL;
6172
6173 int idx = 0;
6174
6175 /* clear [ip] bgp */
6176 if (argv_find(argv, argc, "ip", &idx))
6177 afi = AFI_IP;
6178
6179 /* [<view|vrf> VIEWVRFNAME] */
6180 if (argv_find(argv, argc, "view", &idx)
6181 || argv_find(argv, argc, "vrf", &idx)) {
6182 vrf = argv[idx + 1]->arg;
6183 idx += 2;
6184 }
6185
6186 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6187 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6188 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6189
6190 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6191 if (argv_find(argv, argc, "*", &idx)) {
6192 clr_sort = clear_all;
6193 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6194 clr_sort = clear_peer;
6195 clr_arg = argv[idx]->arg;
6196 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6197 clr_sort = clear_peer;
6198 clr_arg = argv[idx]->arg;
6199 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6200 clr_sort = clear_group;
6201 idx++;
6202 clr_arg = argv[idx]->arg;
6203 } else if (argv_find(argv, argc, "WORD", &idx)) {
6204 clr_sort = clear_peer;
6205 clr_arg = argv[idx]->arg;
6206 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6207 clr_sort = clear_as;
6208 clr_arg = argv[idx]->arg;
6209 } else if (argv_find(argv, argc, "external", &idx)) {
6210 clr_sort = clear_external;
6211 }
6212
6213 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6214 if (argv_find(argv, argc, "soft", &idx)) {
6215 if (argv_find(argv, argc, "in", &idx)
6216 || argv_find(argv, argc, "out", &idx))
6217 clr_type = strmatch(argv[idx]->text, "in")
6218 ? BGP_CLEAR_SOFT_IN
6219 : BGP_CLEAR_SOFT_OUT;
6220 else
6221 clr_type = BGP_CLEAR_SOFT_BOTH;
6222 } else if (argv_find(argv, argc, "in", &idx)) {
6223 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6224 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6225 : BGP_CLEAR_SOFT_IN;
6226 } else if (argv_find(argv, argc, "out", &idx)) {
6227 clr_type = BGP_CLEAR_SOFT_OUT;
6228 } else
6229 clr_type = BGP_CLEAR_SOFT_NONE;
6230
6231 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 6232}
01080f7c 6233
8ad7271d
DS
6234DEFUN (clear_ip_bgp_prefix,
6235 clear_ip_bgp_prefix_cmd,
18c57037 6236 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
6237 CLEAR_STR
6238 IP_STR
6239 BGP_STR
838758ac 6240 BGP_INSTANCE_HELP_STR
8ad7271d 6241 "Clear bestpath and re-advertise\n"
0c7b1b01 6242 "IPv4 prefix\n")
8ad7271d 6243{
d62a17ae 6244 char *vrf = NULL;
6245 char *prefix = NULL;
8ad7271d 6246
d62a17ae 6247 int idx = 0;
01080f7c 6248
d62a17ae 6249 /* [<view|vrf> VIEWVRFNAME] */
6250 if (argv_find(argv, argc, "WORD", &idx))
6251 vrf = argv[idx]->arg;
0c7b1b01 6252
d62a17ae 6253 prefix = argv[argc - 1]->arg;
8ad7271d 6254
d62a17ae 6255 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 6256}
8ad7271d 6257
b09b5ae0
DW
6258DEFUN (clear_bgp_ipv6_safi_prefix,
6259 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 6260 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6261 CLEAR_STR
3a2d747c 6262 IP_STR
718e3744 6263 BGP_STR
8c3deaae 6264 "Address Family\n"
46f296b4 6265 BGP_SAFI_HELP_STR
b09b5ae0 6266 "Clear bestpath and re-advertise\n"
0c7b1b01 6267 "IPv6 prefix\n")
718e3744 6268{
d62a17ae 6269 int idx_safi = 3;
6270 int idx_ipv6_prefixlen = 5;
6271 return bgp_clear_prefix(
6272 vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6273 bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
838758ac 6274}
01080f7c 6275
b09b5ae0
DW
6276DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6277 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 6278 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6279 CLEAR_STR
3a2d747c 6280 IP_STR
718e3744 6281 BGP_STR
838758ac 6282 BGP_INSTANCE_HELP_STR
8c3deaae 6283 "Address Family\n"
46f296b4 6284 BGP_SAFI_HELP_STR
b09b5ae0 6285 "Clear bestpath and re-advertise\n"
0c7b1b01 6286 "IPv6 prefix\n")
718e3744 6287{
d62a17ae 6288 int idx_word = 3;
6289 int idx_safi = 5;
6290 int idx_ipv6_prefixlen = 7;
6291 return bgp_clear_prefix(
6292 vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg,
6293 AFI_IP6, bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
718e3744 6294}
6295
b09b5ae0
DW
6296DEFUN (show_bgp_views,
6297 show_bgp_views_cmd,
d6e3c605 6298 "show [ip] bgp views",
b09b5ae0 6299 SHOW_STR
d6e3c605 6300 IP_STR
01080f7c 6301 BGP_STR
b09b5ae0 6302 "Show the defined BGP views\n")
01080f7c 6303{
d62a17ae 6304 struct list *inst = bm->bgp;
6305 struct listnode *node;
6306 struct bgp *bgp;
01080f7c 6307
d62a17ae 6308 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6309 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6310 return CMD_WARNING;
6311 }
e52702f2 6312
d62a17ae 6313 vty_out(vty, "Defined BGP views:\n");
6314 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6315 /* Skip VRFs. */
6316 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6317 continue;
6318 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6319 bgp->as);
6320 }
e52702f2 6321
d62a17ae 6322 return CMD_SUCCESS;
e0081f70
ML
6323}
6324
8386ac43 6325DEFUN (show_bgp_vrfs,
6326 show_bgp_vrfs_cmd,
d6e3c605 6327 "show [ip] bgp vrfs [json]",
8386ac43 6328 SHOW_STR
d6e3c605 6329 IP_STR
8386ac43 6330 BGP_STR
6331 "Show BGP VRFs\n"
9973d184 6332 JSON_STR)
8386ac43 6333{
d62a17ae 6334 struct list *inst = bm->bgp;
6335 struct listnode *node;
6336 struct bgp *bgp;
6337 u_char uj = use_json(argc, argv);
6338 json_object *json = NULL;
6339 json_object *json_vrfs = NULL;
6340 int count = 0;
6341 static char header[] =
6342 "Type Id RouterId #PeersCfg #PeersEstb Name";
6343
6344 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6345 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6346 return CMD_WARNING;
6347 }
6348
6349 if (uj) {
6350 json = json_object_new_object();
6351 json_vrfs = json_object_new_object();
6352 }
6353
6354 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6355 const char *name, *type;
6356 struct peer *peer;
6357 struct listnode *node, *nnode;
6358 int peers_cfg, peers_estb;
6359 json_object *json_vrf = NULL;
6360 int vrf_id_ui;
6361
6362 /* Skip Views. */
6363 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6364 continue;
6365
6366 count++;
6367 if (!uj && count == 1)
6368 vty_out(vty, "%s\n", header);
6369
6370 peers_cfg = peers_estb = 0;
6371 if (uj)
6372 json_vrf = json_object_new_object();
6373
6374
6375 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6376 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6377 continue;
6378 peers_cfg++;
6379 if (peer->status == Established)
6380 peers_estb++;
6381 }
6382
6383 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
6384 name = "Default";
6385 type = "DFLT";
6386 } else {
6387 name = bgp->name;
6388 type = "VRF";
6389 }
6390
6391 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 : bgp->vrf_id;
6392 if (uj) {
6393 json_object_string_add(json_vrf, "type", type);
6394 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
6395 json_object_string_add(json_vrf, "routerId",
6396 inet_ntoa(bgp->router_id));
6397 json_object_int_add(json_vrf, "numConfiguredPeers",
6398 peers_cfg);
6399 json_object_int_add(json_vrf, "numEstablishedPeers",
6400 peers_estb);
6401
6402 json_object_object_add(json_vrfs, name, json_vrf);
6403 } else
6404 vty_out(vty, "%4s %-5d %-16s %9u %10u %s\n", type,
6405 vrf_id_ui, inet_ntoa(bgp->router_id), peers_cfg,
6406 peers_estb, name);
6407 }
6408
6409 if (uj) {
6410 json_object_object_add(json, "vrfs", json_vrfs);
6411
6412 json_object_int_add(json, "totalVrfs", count);
6413
9d303b37
DL
6414 vty_out(vty, "%s\n", json_object_to_json_string_ext(
6415 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 6416 json_object_free(json);
6417 } else {
6418 if (count)
6419 vty_out(vty,
6420 "\nTotal number of VRFs (including default): %d\n",
6421 count);
6422 }
6423
6424 return CMD_SUCCESS;
8386ac43 6425}
6426
acf71666
MK
6427static void show_address_entry(struct hash_backet *backet, void *args)
6428{
6429 struct vty *vty = (struct vty *) args;
6430 struct bgp_addr *addr = (struct bgp_addr *) backet->data;
6431
6432 vty_out(vty, "addr: %s, count: %d\n",
6433 inet_ntoa(addr->addr),
6434 addr->refcnt);
6435}
6436
6437static void show_tip_entry(struct hash_backet *backet, void *args)
6438{
6439 struct vty *vty = (struct vty *)args;
6440 struct tip_addr *tip = (struct tip_addr *) backet->data;
6441
6442 vty_out(vty, "addr: %s, count: %d\n",
6443 inet_ntoa(tip->addr),
6444 tip->refcnt);
6445}
6446
6447static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
6448{
6449 vty_out(vty, "self nexthop database:\n");
6450 hash_iterate(bgp->address_hash,
6451 (void (*)(struct hash_backet *, void *))show_address_entry,
6452 vty);
6453
6454 vty_out(vty, "Tunnel-ip database:\n");
6455 hash_iterate(bgp->tip_hash,
6456 (void (*)(struct hash_backet *, void *))show_tip_entry,
6457 vty);
6458}
6459
6460DEFUN (show_bgp_martian_nexthop_db,
6461 show_bgp_martian_nexthop_db_cmd,
6462 "show bgp martian next-hop",
6463 SHOW_STR
6464 BGP_STR
6465 "martian next-hops\n"
6466 "martian next-hop database\n")
6467{
6468 struct bgp *bgp = NULL;
6469
6470 bgp = bgp_get_default();
6471 if (!bgp) {
6472 vty_out(vty, "%% No BGP process is configured\n");
6473 return CMD_WARNING;
6474 }
6475 bgp_show_martian_nexthops(vty, bgp);
6476
6477 return CMD_SUCCESS;
6478}
6479
f412b39a 6480DEFUN (show_bgp_memory,
4bf6a362 6481 show_bgp_memory_cmd,
7fa12b13 6482 "show [ip] bgp memory",
4bf6a362 6483 SHOW_STR
3a2d747c 6484 IP_STR
4bf6a362
PJ
6485 BGP_STR
6486 "Global BGP memory statistics\n")
6487{
d62a17ae 6488 char memstrbuf[MTYPE_MEMSTR_LEN];
6489 unsigned long count;
6490
6491 /* RIB related usage stats */
6492 count = mtype_stats_alloc(MTYPE_BGP_NODE);
6493 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
6494 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6495 count * sizeof(struct bgp_node)));
6496
6497 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
6498 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
6499 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6500 count * sizeof(struct bgp_info)));
6501 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
6502 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
6503 count,
6504 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6505 count * sizeof(struct bgp_info_extra)));
6506
6507 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
6508 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
6509 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6510 count * sizeof(struct bgp_static)));
6511
6512 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
6513 vty_out(vty, "%ld Packets, using %s of memory\n", count,
6514 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6515 count * sizeof(struct bpacket)));
6516
6517 /* Adj-In/Out */
6518 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
6519 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
6520 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6521 count * sizeof(struct bgp_adj_in)));
6522 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
6523 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
6524 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6525 count * sizeof(struct bgp_adj_out)));
6526
6527 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
6528 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
6529 count,
6530 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6531 count * sizeof(struct bgp_nexthop_cache)));
6532
6533 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
6534 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
6535 count,
6536 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6537 count * sizeof(struct bgp_damp_info)));
6538
6539 /* Attributes */
6540 count = attr_count();
6541 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
6542 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6543 count * sizeof(struct attr)));
6544
6545 if ((count = attr_unknown_count()))
6546 vty_out(vty, "%ld unknown attributes\n", count);
6547
6548 /* AS_PATH attributes */
6549 count = aspath_count();
6550 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
6551 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6552 count * sizeof(struct aspath)));
6553
6554 count = mtype_stats_alloc(MTYPE_AS_SEG);
6555 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
6556 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6557 count * sizeof(struct assegment)));
6558
6559 /* Other attributes */
6560 if ((count = community_count()))
6561 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9d303b37
DL
6562 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6563 count * sizeof(struct community)));
d62a17ae 6564 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
6565 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9d303b37
DL
6566 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6567 count * sizeof(struct ecommunity)));
d62a17ae 6568 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
6569 vty_out(vty,
6570 "%ld BGP large-community entries, using %s of memory\n",
9d303b37
DL
6571 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6572 count * sizeof(struct lcommunity)));
d62a17ae 6573
6574 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
6575 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
6576 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6577 count * sizeof(struct cluster_list)));
6578
6579 /* Peer related usage */
6580 count = mtype_stats_alloc(MTYPE_BGP_PEER);
6581 vty_out(vty, "%ld peers, using %s of memory\n", count,
6582 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6583 count * sizeof(struct peer)));
6584
6585 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
6586 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
6587 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6588 count * sizeof(struct peer_group)));
6589
6590 /* Other */
6591 if ((count = mtype_stats_alloc(MTYPE_HASH)))
6592 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
6593 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6594 count * sizeof(struct hash)));
6595 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
6596 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
6597 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6598 count * sizeof(struct hash_backet)));
6599 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
6600 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
9d303b37
DL
6601 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6602 count * sizeof(regex_t)));
d62a17ae 6603 return CMD_SUCCESS;
4bf6a362 6604}
fee0f4c6 6605
718e3744 6606/* Show BGP peer's summary information. */
d62a17ae 6607static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
6608 u_char use_json, json_object *json)
6609{
6610 struct peer *peer;
6611 struct listnode *node, *nnode;
6612 unsigned int count = 0, dn_count = 0;
6613 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
6614 char neighbor_buf[VTY_BUFSIZ];
6615 int neighbor_col_default_width = 16;
6616 int len;
6617 int max_neighbor_width = 0;
6618 int pfx_rcd_safi;
6619 json_object *json_peer = NULL;
6620 json_object *json_peers = NULL;
6621
6622 /* labeled-unicast routes are installed in the unicast table so in order
6623 * to
6624 * display the correct PfxRcd value we must look at SAFI_UNICAST
6625 */
6626 if (safi == SAFI_LABELED_UNICAST)
6627 pfx_rcd_safi = SAFI_UNICAST;
6628 else
6629 pfx_rcd_safi = safi;
6630
6631 if (use_json) {
6632 if (json == NULL)
6633 json = json_object_new_object();
6634
6635 json_peers = json_object_new_object();
6636 } else {
6637 /* Loop over all neighbors that will be displayed to determine
6638 * how many
6639 * characters are needed for the Neighbor column
6640 */
6641 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6642 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6643 continue;
6644
6645 if (peer->afc[afi][safi]) {
6646 memset(dn_flag, '\0', sizeof(dn_flag));
6647 if (peer_dynamic_neighbor(peer))
6648 dn_flag[0] = '*';
6649
6650 if (peer->hostname
6651 && bgp_flag_check(bgp,
6652 BGP_FLAG_SHOW_HOSTNAME))
6653 sprintf(neighbor_buf, "%s%s(%s) ",
6654 dn_flag, peer->hostname,
6655 peer->host);
6656 else
6657 sprintf(neighbor_buf, "%s%s ", dn_flag,
6658 peer->host);
6659
6660 len = strlen(neighbor_buf);
6661
6662 if (len > max_neighbor_width)
6663 max_neighbor_width = len;
6664 }
6665 }
f933309e 6666
d62a17ae 6667 /* Originally we displayed the Neighbor column as 16
6668 * characters wide so make that the default
6669 */
6670 if (max_neighbor_width < neighbor_col_default_width)
6671 max_neighbor_width = neighbor_col_default_width;
6672 }
f933309e 6673
d62a17ae 6674 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6675 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6676 continue;
6677
6678 if (peer->afc[afi][safi]) {
6679 if (!count) {
6680 unsigned long ents;
6681 char memstrbuf[MTYPE_MEMSTR_LEN];
6682 int vrf_id_ui;
6683
6684 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
6685 ? -1
6686 : bgp->vrf_id;
6687
6688 /* Usage summary and header */
6689 if (use_json) {
6690 json_object_string_add(
6691 json, "routerId",
6692 inet_ntoa(bgp->router_id));
6693 json_object_int_add(json, "as",
6694 bgp->as);
6695 json_object_int_add(json, "vrfId",
6696 vrf_id_ui);
6697 json_object_string_add(
6698 json, "vrfName",
6699 (bgp->inst_type
6700 == BGP_INSTANCE_TYPE_DEFAULT)
6701 ? "Default"
6702 : bgp->name);
6703 } else {
6704 vty_out(vty,
6705 "BGP router identifier %s, local AS number %u vrf-id %d",
6706 inet_ntoa(bgp->router_id),
6707 bgp->as, vrf_id_ui);
6708 vty_out(vty, "\n");
6709 }
6710
6711 if (bgp_update_delay_configured(bgp)) {
6712 if (use_json) {
6713 json_object_int_add(
6714 json,
6715 "updateDelayLimit",
6716 bgp->v_update_delay);
6717
6718 if (bgp->v_update_delay
6719 != bgp->v_establish_wait)
6720 json_object_int_add(
6721 json,
6722 "updateDelayEstablishWait",
6723 bgp->v_establish_wait);
6724
6725 if (bgp_update_delay_active(
6726 bgp)) {
6727 json_object_string_add(
6728 json,
6729 "updateDelayFirstNeighbor",
6730 bgp->update_delay_begin_time);
6731 json_object_boolean_true_add(
6732 json,
6733 "updateDelayInProgress");
6734 } else {
6735 if (bgp->update_delay_over) {
6736 json_object_string_add(
6737 json,
6738 "updateDelayFirstNeighbor",
6739 bgp->update_delay_begin_time);
6740 json_object_string_add(
6741 json,
6742 "updateDelayBestpathResumed",
6743 bgp->update_delay_end_time);
6744 json_object_string_add(
6745 json,
6746 "updateDelayZebraUpdateResume",
6747 bgp->update_delay_zebra_resume_time);
6748 json_object_string_add(
6749 json,
6750 "updateDelayPeerUpdateResume",
6751 bgp->update_delay_peers_resume_time);
6752 }
6753 }
6754 } else {
6755 vty_out(vty,
6756 "Read-only mode update-delay limit: %d seconds\n",
6757 bgp->v_update_delay);
6758 if (bgp->v_update_delay
6759 != bgp->v_establish_wait)
6760 vty_out(vty,
6761 " Establish wait: %d seconds\n",
6762 bgp->v_establish_wait);
6763
6764 if (bgp_update_delay_active(
6765 bgp)) {
6766 vty_out(vty,
6767 " First neighbor established: %s\n",
6768 bgp->update_delay_begin_time);
6769 vty_out(vty,
6770 " Delay in progress\n");
6771 } else {
6772 if (bgp->update_delay_over) {
6773 vty_out(vty,
6774 " First neighbor established: %s\n",
6775 bgp->update_delay_begin_time);
6776 vty_out(vty,
6777 " Best-paths resumed: %s\n",
6778 bgp->update_delay_end_time);
6779 vty_out(vty,
6780 " zebra update resumed: %s\n",
6781 bgp->update_delay_zebra_resume_time);
6782 vty_out(vty,
6783 " peers update resumed: %s\n",
6784 bgp->update_delay_peers_resume_time);
6785 }
6786 }
6787 }
6788 }
6789
6790 if (use_json) {
6791 if (bgp_maxmed_onstartup_configured(bgp)
6792 && bgp->maxmed_active)
6793 json_object_boolean_true_add(
6794 json,
6795 "maxMedOnStartup");
6796 if (bgp->v_maxmed_admin)
6797 json_object_boolean_true_add(
6798 json,
6799 "maxMedAdministrative");
6800
6801 json_object_int_add(
6802 json, "tableVersion",
6803 bgp_table_version(
6804 bgp->rib[afi][safi]));
6805
6806 ents = bgp_table_count(
6807 bgp->rib[afi][safi]);
6808 json_object_int_add(json, "ribCount",
6809 ents);
6810 json_object_int_add(
6811 json, "ribMemory",
6812 ents * sizeof(struct bgp_node));
6813
6814 ents = listcount(bgp->peer);
6815 json_object_int_add(json, "peerCount",
6816 ents);
6817 json_object_int_add(
6818 json, "peerMemory",
6819 ents * sizeof(struct peer));
6820
6821 if ((ents = listcount(bgp->group))) {
6822 json_object_int_add(
6823 json, "peerGroupCount",
6824 ents);
6825 json_object_int_add(
6826 json, "peerGroupMemory",
9d303b37
DL
6827 ents * sizeof(struct
6828 peer_group));
d62a17ae 6829 }
6830
6831 if (CHECK_FLAG(bgp->af_flags[afi][safi],
6832 BGP_CONFIG_DAMPENING))
6833 json_object_boolean_true_add(
6834 json,
6835 "dampeningEnabled");
6836 } else {
6837 if (bgp_maxmed_onstartup_configured(bgp)
6838 && bgp->maxmed_active)
6839 vty_out(vty,
6840 "Max-med on-startup active\n");
6841 if (bgp->v_maxmed_admin)
6842 vty_out(vty,
6843 "Max-med administrative active\n");
6844
6845 vty_out(vty,
6846 "BGP table version %" PRIu64
6847 "\n",
6848 bgp_table_version(
6849 bgp->rib[afi][safi]));
6850
6851 ents = bgp_table_count(
6852 bgp->rib[afi][safi]);
6853 vty_out(vty,
6854 "RIB entries %ld, using %s of memory\n",
6855 ents,
6856 mtype_memstr(
6857 memstrbuf,
6858 sizeof(memstrbuf),
9d303b37
DL
6859 ents * sizeof(struct
6860 bgp_node)));
d62a17ae 6861
6862 /* Peer related usage */
6863 ents = listcount(bgp->peer);
6864 vty_out(vty,
6865 "Peers %ld, using %s of memory\n",
6866 ents,
6867 mtype_memstr(
6868 memstrbuf,
6869 sizeof(memstrbuf),
9d303b37
DL
6870 ents * sizeof(struct
6871 peer)));
d62a17ae 6872
6873 if ((ents = listcount(bgp->group)))
6874 vty_out(vty,
6875 "Peer groups %ld, using %s of memory\n",
6876 ents,
6877 mtype_memstr(
6878 memstrbuf,
6879 sizeof(memstrbuf),
9d303b37
DL
6880 ents * sizeof(struct
6881 peer_group)));
d62a17ae 6882
6883 if (CHECK_FLAG(bgp->af_flags[afi][safi],
6884 BGP_CONFIG_DAMPENING))
6885 vty_out(vty,
6886 "Dampening enabled.\n");
6887 vty_out(vty, "\n");
6888
6889 /* Subtract 8 here because 'Neighbor' is
6890 * 8 characters */
6891 vty_out(vty, "Neighbor");
6892 vty_out(vty, "%*s",
6893 max_neighbor_width - 8, " ");
6894 vty_out(vty,
6895 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
6896 }
6897 }
6898
6899 count++;
6900
6901 if (use_json) {
6902 json_peer = json_object_new_object();
6903
6904 if (peer_dynamic_neighbor(peer))
6905 json_object_boolean_true_add(
6906 json_peer, "dynamicPeer");
6907
6908 if (peer->hostname)
6909 json_object_string_add(json_peer,
6910 "hostname",
6911 peer->hostname);
6912
6913 if (peer->domainname)
6914 json_object_string_add(
6915 json_peer, "domainname",
6916 peer->domainname);
6917
6918 json_object_int_add(json_peer, "remoteAs",
6919 peer->as);
6920 json_object_int_add(json_peer, "version", 4);
6921 json_object_int_add(
6922 json_peer, "msgRcvd",
6923 peer->open_in + peer->update_in
6924 + peer->keepalive_in
6925 + peer->notify_in
6926 + peer->refresh_in
6927 + peer->dynamic_cap_in);
6928 json_object_int_add(
6929 json_peer, "msgSent",
6930 peer->open_out + peer->update_out
6931 + peer->keepalive_out
6932 + peer->notify_out
6933 + peer->refresh_out
6934 + peer->dynamic_cap_out);
6935
6936 json_object_int_add(json_peer, "tableVersion",
6937 peer->version[afi][safi]);
6938 json_object_int_add(json_peer, "outq",
6939 peer->obuf->count);
6940 json_object_int_add(json_peer, "inq", 0);
6941 peer_uptime(peer->uptime, timebuf,
6942 BGP_UPTIME_LEN, use_json,
6943 json_peer);
6944 json_object_int_add(
6945 json_peer, "prefixReceivedCount",
6946 peer->pcount[afi][pfx_rcd_safi]);
6947
6948 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
6949 json_object_string_add(json_peer,
6950 "state",
6951 "Idle (Admin)");
6952 else if (CHECK_FLAG(
6953 peer->sflags,
6954 PEER_STATUS_PREFIX_OVERFLOW))
6955 json_object_string_add(json_peer,
6956 "state",
6957 "Idle (PfxCt)");
6958 else
6959 json_object_string_add(
6960 json_peer, "state",
6961 lookup_msg(bgp_status_msg,
6962 peer->status, NULL));
6963
6964 if (peer->conf_if)
6965 json_object_string_add(json_peer,
6966 "idType",
6967 "interface");
6968 else if (peer->su.sa.sa_family == AF_INET)
6969 json_object_string_add(
6970 json_peer, "idType", "ipv4");
6971 else if (peer->su.sa.sa_family == AF_INET6)
6972 json_object_string_add(
6973 json_peer, "idType", "ipv6");
6974
6975 json_object_object_add(json_peers, peer->host,
6976 json_peer);
6977 } else {
6978 memset(dn_flag, '\0', sizeof(dn_flag));
6979 if (peer_dynamic_neighbor(peer)) {
6980 dn_count++;
6981 dn_flag[0] = '*';
6982 }
6983
6984 if (peer->hostname
6985 && bgp_flag_check(bgp,
6986 BGP_FLAG_SHOW_HOSTNAME))
6987 len = vty_out(vty, "%s%s(%s)", dn_flag,
6988 peer->hostname,
6989 peer->host);
6990 else
6991 len = vty_out(vty, "%s%s", dn_flag,
6992 peer->host);
6993
6994 /* pad the neighbor column with spaces */
6995 if (len < max_neighbor_width)
6996 vty_out(vty, "%*s",
6997 max_neighbor_width - len, " ");
6998
9d303b37
DL
6999 vty_out(vty, "4 %10u %7d %7d %8" PRIu64
7000 " %4d %4zd %8s",
d62a17ae 7001 peer->as,
7002 peer->open_in + peer->update_in
7003 + peer->keepalive_in
7004 + peer->notify_in
7005 + peer->refresh_in
7006 + peer->dynamic_cap_in,
7007 peer->open_out + peer->update_out
7008 + peer->keepalive_out
7009 + peer->notify_out
7010 + peer->refresh_out
7011 + peer->dynamic_cap_out,
7012 peer->version[afi][safi], 0,
7013 peer->obuf->count,
7014 peer_uptime(peer->uptime, timebuf,
7015 BGP_UPTIME_LEN, 0, NULL));
7016
7017 if (peer->status == Established)
7018 vty_out(vty, " %12ld",
7019 peer->pcount[afi]
7020 [pfx_rcd_safi]);
7021 else {
7022 if (CHECK_FLAG(peer->flags,
7023 PEER_FLAG_SHUTDOWN))
7024 vty_out(vty, " Idle (Admin)");
7025 else if (
7026 CHECK_FLAG(
7027 peer->sflags,
7028 PEER_STATUS_PREFIX_OVERFLOW))
7029 vty_out(vty, " Idle (PfxCt)");
7030 else
7031 vty_out(vty, " %12s",
7032 lookup_msg(
7033 bgp_status_msg,
7034 peer->status,
7035 NULL));
7036 }
7037 vty_out(vty, "\n");
7038 }
7039 }
7040 }
f933309e 7041
d62a17ae 7042 if (use_json) {
7043 json_object_object_add(json, "peers", json_peers);
7044
7045 json_object_int_add(json, "totalPeers", count);
7046 json_object_int_add(json, "dynamicPeers", dn_count);
7047
9d303b37
DL
7048 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7049 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7050 json_object_free(json);
7051 } else {
7052 if (count)
7053 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7054 else {
7055 if (use_json)
7056 vty_out(vty,
7057 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7058 afi_safi_print(afi, safi));
7059 else
7060 vty_out(vty, "No %s neighbor is configured\n",
7061 afi_safi_print(afi, safi));
7062 }
b05a1c8b 7063
d62a17ae 7064 if (dn_count && !use_json) {
7065 vty_out(vty, "* - dynamic neighbor\n");
7066 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7067 dn_count, bgp->dynamic_neighbors_limit);
7068 }
7069 }
1ff9a340 7070
d62a17ae 7071 return CMD_SUCCESS;
718e3744 7072}
7073
798c3572
DS
7074/*
7075 * Return if we have a peer configured to use this afi/safi
7076 */
d62a17ae 7077static int bgp_show_summary_afi_safi_peer_exists(struct bgp *bgp, int afi,
7078 int safi)
7079{
7080 struct listnode *node;
7081 struct peer *peer;
7082
7083 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
7084 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7085 continue;
7086
7087 if (peer->afc[afi][safi])
7088 return 1;
7089 }
7090
7091 return 0;
7092}
7093
7094static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7095 int safi, u_char use_json,
7096 json_object *json)
7097{
7098 int is_first = 1;
7099 int afi_wildcard = (afi == AFI_MAX);
7100 int safi_wildcard = (safi == SAFI_MAX);
7101 int is_wildcard = (afi_wildcard || safi_wildcard);
7102 bool json_output = false;
7103
7104 if (use_json && is_wildcard)
7105 vty_out(vty, "{\n");
7106 if (afi_wildcard)
7107 afi = 1; /* AFI_IP */
7108 while (afi < AFI_MAX) {
7109 if (safi_wildcard)
7110 safi = 1; /* SAFI_UNICAST */
7111 while (safi < SAFI_MAX) {
7112 if (bgp_show_summary_afi_safi_peer_exists(bgp, afi,
7113 safi)) {
7114 json_output = true;
7115 if (is_wildcard) {
7116 /*
7117 * So limit output to those afi/safi
7118 * pairs that
7119 * actualy have something interesting in
7120 * them
7121 */
7122 if (use_json) {
7123 json = json_object_new_object();
7124
7125 if (!is_first)
7126 vty_out(vty, ",\n");
7127 else
7128 is_first = 0;
7129
7130 vty_out(vty, "\"%s\":",
7131 afi_safi_json(afi,
7132 safi));
7133 } else {
7134 vty_out(vty, "\n%s Summary:\n",
7135 afi_safi_print(afi,
7136 safi));
7137 }
7138 }
7139 bgp_show_summary(vty, bgp, afi, safi, use_json,
7140 json);
7141 }
7142 safi++;
d62a17ae 7143 if (!safi_wildcard)
7144 safi = SAFI_MAX;
7145 }
7146 afi++;
7147 if (!afi_wildcard
7148 || afi == AFI_L2VPN) /* special case, not handled yet */
7149 afi = AFI_MAX;
7150 }
7151
7152 if (use_json && is_wildcard)
7153 vty_out(vty, "}\n");
7154 else if (use_json && !json_output)
7155 vty_out(vty, "{}\n");
7156}
7157
7158static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7159 safi_t safi, u_char use_json)
7160{
7161 struct listnode *node, *nnode;
7162 struct bgp *bgp;
7163 json_object *json = NULL;
7164 int is_first = 1;
7165
7166 if (use_json)
7167 vty_out(vty, "{\n");
7168
7169 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
7170 if (use_json) {
7171 json = json_object_new_object();
7172
7173 if (!is_first)
7174 vty_out(vty, ",\n");
7175 else
7176 is_first = 0;
7177
7178 vty_out(vty, "\"%s\":",
7179 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7180 ? "Default"
7181 : bgp->name);
7182 } else {
7183 vty_out(vty, "\nInstance %s:\n",
7184 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7185 ? "Default"
7186 : bgp->name);
7187 }
7188 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7189 }
7190
7191 if (use_json)
7192 vty_out(vty, "}\n");
7193}
7194
7195int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7196 safi_t safi, u_char use_json)
7197{
7198 struct bgp *bgp;
7199
7200 if (name) {
7201 if (strmatch(name, "all")) {
7202 bgp_show_all_instances_summary_vty(vty, afi, safi,
7203 use_json);
7204 return CMD_SUCCESS;
7205 } else {
7206 bgp = bgp_lookup_by_name(name);
7207
7208 if (!bgp) {
7209 if (use_json)
7210 vty_out(vty, "{}\n");
7211 else
7212 vty_out(vty,
7213 "%% No such BGP instance exist\n");
7214 return CMD_WARNING;
7215 }
7216
7217 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7218 NULL);
7219 return CMD_SUCCESS;
7220 }
7221 }
7222
7223 bgp = bgp_get_default();
7224
7225 if (bgp)
7226 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7227
7228 return CMD_SUCCESS;
4fb25c53
DW
7229}
7230
716b2d8a 7231/* `show [ip] bgp summary' commands. */
47fc97cc 7232DEFUN (show_ip_bgp_summary,
718e3744 7233 show_ip_bgp_summary_cmd,
dd6bd0f1 7234 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 7235 SHOW_STR
7236 IP_STR
7237 BGP_STR
8386ac43 7238 BGP_INSTANCE_HELP_STR
46f296b4 7239 BGP_AFI_HELP_STR
dd6bd0f1 7240 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 7241 "Summary of BGP neighbor status\n"
9973d184 7242 JSON_STR)
718e3744 7243{
d62a17ae 7244 char *vrf = NULL;
7245 afi_t afi = AFI_MAX;
7246 safi_t safi = SAFI_MAX;
7247
7248 int idx = 0;
7249
7250 /* show [ip] bgp */
7251 if (argv_find(argv, argc, "ip", &idx))
7252 afi = AFI_IP;
7253 /* [<view|vrf> VIEWVRFNAME] */
7254 if (argv_find(argv, argc, "view", &idx)
7255 || argv_find(argv, argc, "vrf", &idx))
7256 vrf = argv[++idx]->arg;
7257 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7258 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7259 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7260 }
7261
7262 int uj = use_json(argc, argv);
7263
7264 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7265}
7266
7267const char *afi_safi_print(afi_t afi, safi_t safi)
7268{
7269 if (afi == AFI_IP && safi == SAFI_UNICAST)
7270 return "IPv4 Unicast";
7271 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7272 return "IPv4 Multicast";
7273 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7274 return "IPv4 Labeled Unicast";
7275 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7276 return "IPv4 VPN";
7277 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7278 return "IPv4 Encap";
7279 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7280 return "IPv6 Unicast";
7281 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7282 return "IPv6 Multicast";
7283 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7284 return "IPv6 Labeled Unicast";
7285 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7286 return "IPv6 VPN";
7287 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7288 return "IPv6 Encap";
7289 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7290 return "L2VPN EVPN";
7291 else
7292 return "Unknown";
538621f2 7293}
7294
b9f77ec8
DS
7295/*
7296 * Please note that we have intentionally camelCased
7297 * the return strings here. So if you want
7298 * to use this function, please ensure you
7299 * are doing this within json output
7300 */
d62a17ae 7301const char *afi_safi_json(afi_t afi, safi_t safi)
7302{
7303 if (afi == AFI_IP && safi == SAFI_UNICAST)
7304 return "ipv4Unicast";
7305 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7306 return "ipv4Multicast";
7307 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7308 return "ipv4LabeledUnicast";
7309 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7310 return "ipv4Vpn";
7311 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7312 return "ipv4Encap";
7313 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7314 return "ipv6Unicast";
7315 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7316 return "ipv6Multicast";
7317 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7318 return "ipv6LabeledUnicast";
7319 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7320 return "ipv6Vpn";
7321 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7322 return "ipv6Encap";
7323 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7324 return "l2VpnEvpn";
7325 else
7326 return "Unknown";
27162734
LB
7327}
7328
718e3744 7329/* Show BGP peer's information. */
d62a17ae 7330enum show_type { show_all, show_peer };
7331
7332static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7333 afi_t afi, safi_t safi,
7334 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7335 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7336 u_char use_json, json_object *json_pref)
7337{
7338 /* Send-Mode */
7339 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7340 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7341 if (use_json) {
7342 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7343 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7344 json_object_string_add(json_pref, "sendMode",
7345 "advertisedAndReceived");
7346 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7347 json_object_string_add(json_pref, "sendMode",
7348 "advertised");
7349 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7350 json_object_string_add(json_pref, "sendMode",
7351 "received");
7352 } else {
7353 vty_out(vty, " Send-mode: ");
7354 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7355 vty_out(vty, "advertised");
7356 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7357 vty_out(vty, "%sreceived",
7358 CHECK_FLAG(p->af_cap[afi][safi],
7359 adv_smcap)
7360 ? ", "
7361 : "");
7362 vty_out(vty, "\n");
7363 }
7364 }
7365
7366 /* Receive-Mode */
7367 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7368 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
7369 if (use_json) {
7370 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7371 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7372 json_object_string_add(json_pref, "recvMode",
7373 "advertisedAndReceived");
7374 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7375 json_object_string_add(json_pref, "recvMode",
7376 "advertised");
7377 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7378 json_object_string_add(json_pref, "recvMode",
7379 "received");
7380 } else {
7381 vty_out(vty, " Receive-mode: ");
7382 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7383 vty_out(vty, "advertised");
7384 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7385 vty_out(vty, "%sreceived",
7386 CHECK_FLAG(p->af_cap[afi][safi],
7387 adv_rmcap)
7388 ? ", "
7389 : "");
7390 vty_out(vty, "\n");
7391 }
7392 }
7393}
7394
7395static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
7396 safi_t safi, u_char use_json,
7397 json_object *json_neigh)
7398{
7399 struct bgp_filter *filter;
7400 struct peer_af *paf;
7401 char orf_pfx_name[BUFSIZ];
7402 int orf_pfx_count;
7403 json_object *json_af = NULL;
7404 json_object *json_prefA = NULL;
7405 json_object *json_prefB = NULL;
7406 json_object *json_addr = NULL;
7407
7408 if (use_json) {
7409 json_addr = json_object_new_object();
7410 json_af = json_object_new_object();
7411 filter = &p->filter[afi][safi];
7412
7413 if (peer_group_active(p))
7414 json_object_string_add(json_addr, "peerGroupMember",
7415 p->group->name);
7416
7417 paf = peer_af_find(p, afi, safi);
7418 if (paf && PAF_SUBGRP(paf)) {
7419 json_object_int_add(json_addr, "updateGroupId",
7420 PAF_UPDGRP(paf)->id);
7421 json_object_int_add(json_addr, "subGroupId",
7422 PAF_SUBGRP(paf)->id);
7423 json_object_int_add(json_addr, "packetQueueLength",
7424 bpacket_queue_virtual_length(paf));
7425 }
7426
7427 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7428 || CHECK_FLAG(p->af_cap[afi][safi],
7429 PEER_CAP_ORF_PREFIX_SM_RCV)
7430 || CHECK_FLAG(p->af_cap[afi][safi],
7431 PEER_CAP_ORF_PREFIX_RM_ADV)
7432 || CHECK_FLAG(p->af_cap[afi][safi],
7433 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7434 json_object_int_add(json_af, "orfType",
7435 ORF_TYPE_PREFIX);
7436 json_prefA = json_object_new_object();
7437 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
7438 PEER_CAP_ORF_PREFIX_SM_ADV,
7439 PEER_CAP_ORF_PREFIX_RM_ADV,
7440 PEER_CAP_ORF_PREFIX_SM_RCV,
7441 PEER_CAP_ORF_PREFIX_RM_RCV,
7442 use_json, json_prefA);
7443 json_object_object_add(json_af, "orfPrefixList",
7444 json_prefA);
7445 }
7446
7447 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7448 || CHECK_FLAG(p->af_cap[afi][safi],
7449 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7450 || CHECK_FLAG(p->af_cap[afi][safi],
7451 PEER_CAP_ORF_PREFIX_RM_ADV)
7452 || CHECK_FLAG(p->af_cap[afi][safi],
7453 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7454 json_object_int_add(json_af, "orfOldType",
7455 ORF_TYPE_PREFIX_OLD);
7456 json_prefB = json_object_new_object();
7457 bgp_show_peer_afi_orf_cap(
7458 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7459 PEER_CAP_ORF_PREFIX_RM_ADV,
7460 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7461 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
7462 json_prefB);
7463 json_object_object_add(json_af, "orfOldPrefixList",
7464 json_prefB);
7465 }
7466
7467 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7468 || CHECK_FLAG(p->af_cap[afi][safi],
7469 PEER_CAP_ORF_PREFIX_SM_RCV)
7470 || CHECK_FLAG(p->af_cap[afi][safi],
7471 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7472 || CHECK_FLAG(p->af_cap[afi][safi],
7473 PEER_CAP_ORF_PREFIX_RM_ADV)
7474 || CHECK_FLAG(p->af_cap[afi][safi],
7475 PEER_CAP_ORF_PREFIX_RM_RCV)
7476 || CHECK_FLAG(p->af_cap[afi][safi],
7477 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7478 json_object_object_add(json_addr, "afDependentCap",
7479 json_af);
7480 else
7481 json_object_free(json_af);
7482
7483 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7484 orf_pfx_count = prefix_bgp_show_prefix_list(
7485 NULL, afi, orf_pfx_name, use_json);
7486
7487 if (CHECK_FLAG(p->af_sflags[afi][safi],
7488 PEER_STATUS_ORF_PREFIX_SEND)
7489 || orf_pfx_count) {
7490 if (CHECK_FLAG(p->af_sflags[afi][safi],
7491 PEER_STATUS_ORF_PREFIX_SEND))
7492 json_object_boolean_true_add(json_neigh,
7493 "orfSent");
7494 if (orf_pfx_count)
7495 json_object_int_add(json_addr, "orfRecvCounter",
7496 orf_pfx_count);
7497 }
7498 if (CHECK_FLAG(p->af_sflags[afi][safi],
7499 PEER_STATUS_ORF_WAIT_REFRESH))
7500 json_object_string_add(
7501 json_addr, "orfFirstUpdate",
7502 "deferredUntilORFOrRouteRefreshRecvd");
7503
7504 if (CHECK_FLAG(p->af_flags[afi][safi],
7505 PEER_FLAG_REFLECTOR_CLIENT))
7506 json_object_boolean_true_add(json_addr,
7507 "routeReflectorClient");
7508 if (CHECK_FLAG(p->af_flags[afi][safi],
7509 PEER_FLAG_RSERVER_CLIENT))
7510 json_object_boolean_true_add(json_addr,
7511 "routeServerClient");
7512 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7513 json_object_boolean_true_add(json_addr,
7514 "inboundSoftConfigPermit");
7515
7516 if (CHECK_FLAG(p->af_flags[afi][safi],
7517 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7518 json_object_boolean_true_add(
7519 json_addr,
7520 "privateAsNumsAllReplacedInUpdatesToNbr");
7521 else if (CHECK_FLAG(p->af_flags[afi][safi],
7522 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7523 json_object_boolean_true_add(
7524 json_addr,
7525 "privateAsNumsReplacedInUpdatesToNbr");
7526 else if (CHECK_FLAG(p->af_flags[afi][safi],
7527 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7528 json_object_boolean_true_add(
7529 json_addr,
7530 "privateAsNumsAllRemovedInUpdatesToNbr");
7531 else if (CHECK_FLAG(p->af_flags[afi][safi],
7532 PEER_FLAG_REMOVE_PRIVATE_AS))
7533 json_object_boolean_true_add(
7534 json_addr,
7535 "privateAsNumsRemovedInUpdatesToNbr");
7536
7537 if (CHECK_FLAG(p->af_flags[afi][safi],
7538 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7539 json_object_boolean_true_add(json_addr,
7540 "addpathTxAllPaths");
7541
7542 if (CHECK_FLAG(p->af_flags[afi][safi],
7543 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7544 json_object_boolean_true_add(json_addr,
7545 "addpathTxBestpathPerAS");
7546
7547 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7548 json_object_string_add(json_addr,
7549 "overrideASNsInOutboundUpdates",
7550 "ifAspathEqualRemoteAs");
7551
7552 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7553 || CHECK_FLAG(p->af_flags[afi][safi],
7554 PEER_FLAG_FORCE_NEXTHOP_SELF))
7555 json_object_boolean_true_add(json_addr,
7556 "routerAlwaysNextHop");
7557 if (CHECK_FLAG(p->af_flags[afi][safi],
7558 PEER_FLAG_AS_PATH_UNCHANGED))
7559 json_object_boolean_true_add(
7560 json_addr, "unchangedAsPathPropogatedToNbr");
7561 if (CHECK_FLAG(p->af_flags[afi][safi],
7562 PEER_FLAG_NEXTHOP_UNCHANGED))
7563 json_object_boolean_true_add(
7564 json_addr, "unchangedNextHopPropogatedToNbr");
7565 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7566 json_object_boolean_true_add(
7567 json_addr, "unchangedMedPropogatedToNbr");
7568 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7569 || CHECK_FLAG(p->af_flags[afi][safi],
7570 PEER_FLAG_SEND_EXT_COMMUNITY)) {
7571 if (CHECK_FLAG(p->af_flags[afi][safi],
7572 PEER_FLAG_SEND_COMMUNITY)
7573 && CHECK_FLAG(p->af_flags[afi][safi],
7574 PEER_FLAG_SEND_EXT_COMMUNITY))
7575 json_object_string_add(json_addr,
7576 "commAttriSentToNbr",
7577 "extendedAndStandard");
7578 else if (CHECK_FLAG(p->af_flags[afi][safi],
7579 PEER_FLAG_SEND_EXT_COMMUNITY))
7580 json_object_string_add(json_addr,
7581 "commAttriSentToNbr",
7582 "extended");
7583 else
7584 json_object_string_add(json_addr,
7585 "commAttriSentToNbr",
7586 "standard");
7587 }
7588 if (CHECK_FLAG(p->af_flags[afi][safi],
7589 PEER_FLAG_DEFAULT_ORIGINATE)) {
7590 if (p->default_rmap[afi][safi].name)
7591 json_object_string_add(
7592 json_addr, "defaultRouteMap",
7593 p->default_rmap[afi][safi].name);
7594
7595 if (paf && PAF_SUBGRP(paf)
7596 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7597 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7598 json_object_boolean_true_add(json_addr,
7599 "defaultSent");
7600 else
7601 json_object_boolean_true_add(json_addr,
7602 "defaultNotSent");
7603 }
7604
7605 if (filter->plist[FILTER_IN].name
7606 || filter->dlist[FILTER_IN].name
7607 || filter->aslist[FILTER_IN].name
7608 || filter->map[RMAP_IN].name)
7609 json_object_boolean_true_add(json_addr,
7610 "inboundPathPolicyConfig");
7611 if (filter->plist[FILTER_OUT].name
7612 || filter->dlist[FILTER_OUT].name
7613 || filter->aslist[FILTER_OUT].name
7614 || filter->map[RMAP_OUT].name || filter->usmap.name)
7615 json_object_boolean_true_add(
7616 json_addr, "outboundPathPolicyConfig");
7617
7618 /* prefix-list */
7619 if (filter->plist[FILTER_IN].name)
7620 json_object_string_add(json_addr,
7621 "incomingUpdatePrefixFilterList",
7622 filter->plist[FILTER_IN].name);
7623 if (filter->plist[FILTER_OUT].name)
7624 json_object_string_add(json_addr,
7625 "outgoingUpdatePrefixFilterList",
7626 filter->plist[FILTER_OUT].name);
7627
7628 /* distribute-list */
7629 if (filter->dlist[FILTER_IN].name)
7630 json_object_string_add(
7631 json_addr, "incomingUpdateNetworkFilterList",
7632 filter->dlist[FILTER_IN].name);
7633 if (filter->dlist[FILTER_OUT].name)
7634 json_object_string_add(
7635 json_addr, "outgoingUpdateNetworkFilterList",
7636 filter->dlist[FILTER_OUT].name);
7637
7638 /* filter-list. */
7639 if (filter->aslist[FILTER_IN].name)
7640 json_object_string_add(json_addr,
7641 "incomingUpdateAsPathFilterList",
7642 filter->aslist[FILTER_IN].name);
7643 if (filter->aslist[FILTER_OUT].name)
7644 json_object_string_add(json_addr,
7645 "outgoingUpdateAsPathFilterList",
7646 filter->aslist[FILTER_OUT].name);
7647
7648 /* route-map. */
7649 if (filter->map[RMAP_IN].name)
7650 json_object_string_add(
7651 json_addr, "routeMapForIncomingAdvertisements",
7652 filter->map[RMAP_IN].name);
7653 if (filter->map[RMAP_OUT].name)
7654 json_object_string_add(
7655 json_addr, "routeMapForOutgoingAdvertisements",
7656 filter->map[RMAP_OUT].name);
7657
7658 /* unsuppress-map */
7659 if (filter->usmap.name)
7660 json_object_string_add(json_addr,
7661 "selectiveUnsuppressRouteMap",
7662 filter->usmap.name);
7663
7664 /* Receive prefix count */
7665 json_object_int_add(json_addr, "acceptedPrefixCounter",
7666 p->pcount[afi][safi]);
7667
7668 /* Maximum prefix */
7669 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7670 json_object_int_add(json_addr, "prefixAllowedMax",
7671 p->pmax[afi][safi]);
7672 if (CHECK_FLAG(p->af_flags[afi][safi],
7673 PEER_FLAG_MAX_PREFIX_WARNING))
7674 json_object_boolean_true_add(
7675 json_addr, "prefixAllowedMaxWarning");
7676 json_object_int_add(json_addr,
7677 "prefixAllowedWarningThresh",
7678 p->pmax_threshold[afi][safi]);
7679 if (p->pmax_restart[afi][safi])
7680 json_object_int_add(
7681 json_addr,
7682 "prefixAllowedRestartIntervalMsecs",
7683 p->pmax_restart[afi][safi] * 60000);
7684 }
7685 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
7686 json_addr);
7687
7688 } else {
7689 filter = &p->filter[afi][safi];
7690
7691 vty_out(vty, " For address family: %s\n",
7692 afi_safi_print(afi, safi));
7693
7694 if (peer_group_active(p))
7695 vty_out(vty, " %s peer-group member\n",
7696 p->group->name);
7697
7698 paf = peer_af_find(p, afi, safi);
7699 if (paf && PAF_SUBGRP(paf)) {
9d303b37
DL
7700 vty_out(vty, " Update group %" PRIu64
7701 ", subgroup %" PRIu64 "\n",
d62a17ae 7702 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
7703 vty_out(vty, " Packet Queue length %d\n",
7704 bpacket_queue_virtual_length(paf));
7705 } else {
7706 vty_out(vty, " Not part of any update group\n");
7707 }
7708 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7709 || CHECK_FLAG(p->af_cap[afi][safi],
7710 PEER_CAP_ORF_PREFIX_SM_RCV)
7711 || CHECK_FLAG(p->af_cap[afi][safi],
7712 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7713 || CHECK_FLAG(p->af_cap[afi][safi],
7714 PEER_CAP_ORF_PREFIX_RM_ADV)
7715 || CHECK_FLAG(p->af_cap[afi][safi],
7716 PEER_CAP_ORF_PREFIX_RM_RCV)
7717 || CHECK_FLAG(p->af_cap[afi][safi],
7718 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7719 vty_out(vty, " AF-dependant capabilities:\n");
7720
7721 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7722 || CHECK_FLAG(p->af_cap[afi][safi],
7723 PEER_CAP_ORF_PREFIX_SM_RCV)
7724 || CHECK_FLAG(p->af_cap[afi][safi],
7725 PEER_CAP_ORF_PREFIX_RM_ADV)
7726 || CHECK_FLAG(p->af_cap[afi][safi],
7727 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7728 vty_out(vty,
7729 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7730 ORF_TYPE_PREFIX);
7731 bgp_show_peer_afi_orf_cap(
7732 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7733 PEER_CAP_ORF_PREFIX_RM_ADV,
7734 PEER_CAP_ORF_PREFIX_SM_RCV,
7735 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7736 }
7737 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7738 || CHECK_FLAG(p->af_cap[afi][safi],
7739 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7740 || CHECK_FLAG(p->af_cap[afi][safi],
7741 PEER_CAP_ORF_PREFIX_RM_ADV)
7742 || CHECK_FLAG(p->af_cap[afi][safi],
7743 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7744 vty_out(vty,
7745 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7746 ORF_TYPE_PREFIX_OLD);
7747 bgp_show_peer_afi_orf_cap(
7748 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7749 PEER_CAP_ORF_PREFIX_RM_ADV,
7750 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7751 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7752 }
7753
7754 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7755 orf_pfx_count = prefix_bgp_show_prefix_list(
7756 NULL, afi, orf_pfx_name, use_json);
7757
7758 if (CHECK_FLAG(p->af_sflags[afi][safi],
7759 PEER_STATUS_ORF_PREFIX_SEND)
7760 || orf_pfx_count) {
7761 vty_out(vty, " Outbound Route Filter (ORF):");
7762 if (CHECK_FLAG(p->af_sflags[afi][safi],
7763 PEER_STATUS_ORF_PREFIX_SEND))
7764 vty_out(vty, " sent;");
7765 if (orf_pfx_count)
7766 vty_out(vty, " received (%d entries)",
7767 orf_pfx_count);
7768 vty_out(vty, "\n");
7769 }
7770 if (CHECK_FLAG(p->af_sflags[afi][safi],
7771 PEER_STATUS_ORF_WAIT_REFRESH))
7772 vty_out(vty,
7773 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
7774
7775 if (CHECK_FLAG(p->af_flags[afi][safi],
7776 PEER_FLAG_REFLECTOR_CLIENT))
7777 vty_out(vty, " Route-Reflector Client\n");
7778 if (CHECK_FLAG(p->af_flags[afi][safi],
7779 PEER_FLAG_RSERVER_CLIENT))
7780 vty_out(vty, " Route-Server Client\n");
7781 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7782 vty_out(vty,
7783 " Inbound soft reconfiguration allowed\n");
7784
7785 if (CHECK_FLAG(p->af_flags[afi][safi],
7786 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7787 vty_out(vty,
7788 " Private AS numbers (all) replaced in updates to this neighbor\n");
7789 else if (CHECK_FLAG(p->af_flags[afi][safi],
7790 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7791 vty_out(vty,
7792 " Private AS numbers replaced in updates to this neighbor\n");
7793 else if (CHECK_FLAG(p->af_flags[afi][safi],
7794 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7795 vty_out(vty,
7796 " Private AS numbers (all) removed in updates to this neighbor\n");
7797 else if (CHECK_FLAG(p->af_flags[afi][safi],
7798 PEER_FLAG_REMOVE_PRIVATE_AS))
7799 vty_out(vty,
7800 " Private AS numbers removed in updates to this neighbor\n");
7801
7802 if (CHECK_FLAG(p->af_flags[afi][safi],
7803 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7804 vty_out(vty, " Advertise all paths via addpath\n");
7805
7806 if (CHECK_FLAG(p->af_flags[afi][safi],
7807 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7808 vty_out(vty,
7809 " Advertise bestpath per AS via addpath\n");
7810
7811 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7812 vty_out(vty,
7813 " Override ASNs in outbound updates if aspath equals remote-as\n");
7814
7815 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7816 || CHECK_FLAG(p->af_flags[afi][safi],
7817 PEER_FLAG_FORCE_NEXTHOP_SELF))
7818 vty_out(vty, " NEXT_HOP is always this router\n");
7819 if (CHECK_FLAG(p->af_flags[afi][safi],
7820 PEER_FLAG_AS_PATH_UNCHANGED))
7821 vty_out(vty,
7822 " AS_PATH is propagated unchanged to this neighbor\n");
7823 if (CHECK_FLAG(p->af_flags[afi][safi],
7824 PEER_FLAG_NEXTHOP_UNCHANGED))
7825 vty_out(vty,
7826 " NEXT_HOP is propagated unchanged to this neighbor\n");
7827 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7828 vty_out(vty,
7829 " MED is propagated unchanged to this neighbor\n");
7830 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7831 || CHECK_FLAG(p->af_flags[afi][safi],
7832 PEER_FLAG_SEND_EXT_COMMUNITY)
7833 || CHECK_FLAG(p->af_flags[afi][safi],
7834 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
7835 vty_out(vty,
7836 " Community attribute sent to this neighbor");
7837 if (CHECK_FLAG(p->af_flags[afi][safi],
7838 PEER_FLAG_SEND_COMMUNITY)
7839 && CHECK_FLAG(p->af_flags[afi][safi],
7840 PEER_FLAG_SEND_EXT_COMMUNITY)
7841 && CHECK_FLAG(p->af_flags[afi][safi],
7842 PEER_FLAG_SEND_LARGE_COMMUNITY))
7843 vty_out(vty, "(all)\n");
7844 else if (CHECK_FLAG(p->af_flags[afi][safi],
7845 PEER_FLAG_SEND_LARGE_COMMUNITY))
7846 vty_out(vty, "(large)\n");
7847 else if (CHECK_FLAG(p->af_flags[afi][safi],
7848 PEER_FLAG_SEND_EXT_COMMUNITY))
7849 vty_out(vty, "(extended)\n");
7850 else
7851 vty_out(vty, "(standard)\n");
7852 }
7853 if (CHECK_FLAG(p->af_flags[afi][safi],
7854 PEER_FLAG_DEFAULT_ORIGINATE)) {
7855 vty_out(vty, " Default information originate,");
7856
7857 if (p->default_rmap[afi][safi].name)
7858 vty_out(vty, " default route-map %s%s,",
7859 p->default_rmap[afi][safi].map ? "*"
7860 : "",
7861 p->default_rmap[afi][safi].name);
7862 if (paf && PAF_SUBGRP(paf)
7863 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7864 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7865 vty_out(vty, " default sent\n");
7866 else
7867 vty_out(vty, " default not sent\n");
7868 }
7869
7870 if (filter->plist[FILTER_IN].name
7871 || filter->dlist[FILTER_IN].name
7872 || filter->aslist[FILTER_IN].name
7873 || filter->map[RMAP_IN].name)
7874 vty_out(vty, " Inbound path policy configured\n");
7875 if (filter->plist[FILTER_OUT].name
7876 || filter->dlist[FILTER_OUT].name
7877 || filter->aslist[FILTER_OUT].name
7878 || filter->map[RMAP_OUT].name || filter->usmap.name)
7879 vty_out(vty, " Outbound path policy configured\n");
7880
7881 /* prefix-list */
7882 if (filter->plist[FILTER_IN].name)
7883 vty_out(vty,
7884 " Incoming update prefix filter list is %s%s\n",
7885 filter->plist[FILTER_IN].plist ? "*" : "",
7886 filter->plist[FILTER_IN].name);
7887 if (filter->plist[FILTER_OUT].name)
7888 vty_out(vty,
7889 " Outgoing update prefix filter list is %s%s\n",
7890 filter->plist[FILTER_OUT].plist ? "*" : "",
7891 filter->plist[FILTER_OUT].name);
7892
7893 /* distribute-list */
7894 if (filter->dlist[FILTER_IN].name)
7895 vty_out(vty,
7896 " Incoming update network filter list is %s%s\n",
7897 filter->dlist[FILTER_IN].alist ? "*" : "",
7898 filter->dlist[FILTER_IN].name);
7899 if (filter->dlist[FILTER_OUT].name)
7900 vty_out(vty,
7901 " Outgoing update network filter list is %s%s\n",
7902 filter->dlist[FILTER_OUT].alist ? "*" : "",
7903 filter->dlist[FILTER_OUT].name);
7904
7905 /* filter-list. */
7906 if (filter->aslist[FILTER_IN].name)
7907 vty_out(vty,
7908 " Incoming update AS path filter list is %s%s\n",
7909 filter->aslist[FILTER_IN].aslist ? "*" : "",
7910 filter->aslist[FILTER_IN].name);
7911 if (filter->aslist[FILTER_OUT].name)
7912 vty_out(vty,
7913 " Outgoing update AS path filter list is %s%s\n",
7914 filter->aslist[FILTER_OUT].aslist ? "*" : "",
7915 filter->aslist[FILTER_OUT].name);
7916
7917 /* route-map. */
7918 if (filter->map[RMAP_IN].name)
7919 vty_out(vty,
7920 " Route map for incoming advertisements is %s%s\n",
7921 filter->map[RMAP_IN].map ? "*" : "",
7922 filter->map[RMAP_IN].name);
7923 if (filter->map[RMAP_OUT].name)
7924 vty_out(vty,
7925 " Route map for outgoing advertisements is %s%s\n",
7926 filter->map[RMAP_OUT].map ? "*" : "",
7927 filter->map[RMAP_OUT].name);
7928
7929 /* unsuppress-map */
7930 if (filter->usmap.name)
7931 vty_out(vty,
7932 " Route map for selective unsuppress is %s%s\n",
7933 filter->usmap.map ? "*" : "",
7934 filter->usmap.name);
7935
7936 /* Receive prefix count */
7937 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
7938
7939 /* Maximum prefix */
7940 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7941 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
7942 p->pmax[afi][safi],
7943 CHECK_FLAG(p->af_flags[afi][safi],
7944 PEER_FLAG_MAX_PREFIX_WARNING)
7945 ? " (warning-only)"
7946 : "");
7947 vty_out(vty, " Threshold for warning message %d%%",
7948 p->pmax_threshold[afi][safi]);
7949 if (p->pmax_restart[afi][safi])
7950 vty_out(vty, ", restart interval %d min",
7951 p->pmax_restart[afi][safi]);
7952 vty_out(vty, "\n");
7953 }
7954
7955 vty_out(vty, "\n");
7956 }
7957}
7958
7959static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
7960 json_object *json)
718e3744 7961{
d62a17ae 7962 struct bgp *bgp;
7963 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
7964 char timebuf[BGP_UPTIME_LEN];
7965 char dn_flag[2];
7966 const char *subcode_str;
7967 const char *code_str;
7968 afi_t afi;
7969 safi_t safi;
7970 u_int16_t i;
7971 u_char *msg;
7972 json_object *json_neigh = NULL;
7973 time_t epoch_tbuf;
718e3744 7974
d62a17ae 7975 bgp = p->bgp;
7976
7977 if (use_json)
7978 json_neigh = json_object_new_object();
7979
7980 memset(dn_flag, '\0', sizeof(dn_flag));
7981 if (!p->conf_if && peer_dynamic_neighbor(p))
7982 dn_flag[0] = '*';
7983
7984 if (!use_json) {
7985 if (p->conf_if) /* Configured interface name. */
7986 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
7987 BGP_PEER_SU_UNSPEC(p)
7988 ? "None"
7989 : sockunion2str(&p->su, buf,
7990 SU_ADDRSTRLEN));
7991 else /* Configured IP address. */
7992 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
7993 p->host);
7994 }
7995
7996 if (use_json) {
7997 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
7998 json_object_string_add(json_neigh, "bgpNeighborAddr",
7999 "none");
8000 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8001 json_object_string_add(
8002 json_neigh, "bgpNeighborAddr",
8003 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8004
8005 json_object_int_add(json_neigh, "remoteAs", p->as);
8006
8007 if (p->change_local_as)
8008 json_object_int_add(json_neigh, "localAs",
8009 p->change_local_as);
8010 else
8011 json_object_int_add(json_neigh, "localAs", p->local_as);
8012
8013 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8014 json_object_boolean_true_add(json_neigh,
8015 "localAsNoPrepend");
8016
8017 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8018 json_object_boolean_true_add(json_neigh,
8019 "localAsReplaceAs");
8020 } else {
8021 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8022 || (p->as_type == AS_INTERNAL))
8023 vty_out(vty, "remote AS %u, ", p->as);
8024 else
8025 vty_out(vty, "remote AS Unspecified, ");
8026 vty_out(vty, "local AS %u%s%s, ",
8027 p->change_local_as ? p->change_local_as : p->local_as,
8028 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8029 ? " no-prepend"
8030 : "",
8031 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8032 ? " replace-as"
8033 : "");
8034 }
8035 /* peer type internal, external, confed-internal or confed-external */
8036 if (p->as == p->local_as) {
8037 if (use_json) {
8038 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8039 json_object_boolean_true_add(
8040 json_neigh, "nbrConfedInternalLink");
8041 else
8042 json_object_boolean_true_add(json_neigh,
8043 "nbrInternalLink");
8044 } else {
8045 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8046 vty_out(vty, "confed-internal link\n");
8047 else
8048 vty_out(vty, "internal link\n");
8049 }
8050 } else {
8051 if (use_json) {
8052 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8053 json_object_boolean_true_add(
8054 json_neigh, "nbrConfedExternalLink");
8055 else
8056 json_object_boolean_true_add(json_neigh,
8057 "nbrExternalLink");
8058 } else {
8059 if (bgp_confederation_peers_check(bgp, p->as))
8060 vty_out(vty, "confed-external link\n");
8061 else
8062 vty_out(vty, "external link\n");
8063 }
8064 }
8065
8066 /* Description. */
8067 if (p->desc) {
8068 if (use_json)
8069 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8070 else
8071 vty_out(vty, " Description: %s\n", p->desc);
8072 }
8073
8074 if (p->hostname) {
8075 if (use_json) {
8076 if (p->hostname)
8077 json_object_string_add(json_neigh, "hostname",
8078 p->hostname);
8079
8080 if (p->domainname)
8081 json_object_string_add(json_neigh, "domainname",
8082 p->domainname);
8083 } else {
8084 if (p->domainname && (p->domainname[0] != '\0'))
8085 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8086 p->domainname);
8087 else
8088 vty_out(vty, "Hostname: %s\n", p->hostname);
8089 }
8090 }
8091
8092 /* Peer-group */
8093 if (p->group) {
8094 if (use_json) {
8095 json_object_string_add(json_neigh, "peerGroup",
8096 p->group->name);
8097
8098 if (dn_flag[0]) {
8099 struct prefix prefix, *range = NULL;
8100
8101 sockunion2hostprefix(&(p->su), &prefix);
8102 range = peer_group_lookup_dynamic_neighbor_range(
8103 p->group, &prefix);
8104
8105 if (range) {
8106 prefix2str(range, buf1, sizeof(buf1));
8107 json_object_string_add(
8108 json_neigh,
8109 "peerSubnetRangeGroup", buf1);
8110 }
8111 }
8112 } else {
8113 vty_out(vty,
8114 " Member of peer-group %s for session parameters\n",
8115 p->group->name);
8116
8117 if (dn_flag[0]) {
8118 struct prefix prefix, *range = NULL;
8119
8120 sockunion2hostprefix(&(p->su), &prefix);
8121 range = peer_group_lookup_dynamic_neighbor_range(
8122 p->group, &prefix);
8123
8124 if (range) {
8125 prefix2str(range, buf1, sizeof(buf1));
8126 vty_out(vty,
8127 " Belongs to the subnet range group: %s\n",
8128 buf1);
8129 }
8130 }
8131 }
8132 }
8133
8134 if (use_json) {
8135 /* Administrative shutdown. */
8136 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8137 json_object_boolean_true_add(json_neigh,
8138 "adminShutDown");
8139
8140 /* BGP Version. */
8141 json_object_int_add(json_neigh, "bgpVersion", 4);
8142 json_object_string_add(
8143 json_neigh, "remoteRouterId",
8144 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8145
8146 /* Confederation */
8147 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8148 && bgp_confederation_peers_check(bgp, p->as))
8149 json_object_boolean_true_add(json_neigh,
8150 "nbrCommonAdmin");
8151
8152 /* Status. */
8153 json_object_string_add(
8154 json_neigh, "bgpState",
8155 lookup_msg(bgp_status_msg, p->status, NULL));
8156
8157 if (p->status == Established) {
8158 time_t uptime;
8159 struct tm *tm;
8160
8161 uptime = bgp_clock();
8162 uptime -= p->uptime;
8163 tm = gmtime(&uptime);
8164 epoch_tbuf = time(NULL) - uptime;
8165
8166 json_object_int_add(json_neigh, "bgpTimerUp",
8167 (tm->tm_sec * 1000)
8168 + (tm->tm_min * 60000)
8169 + (tm->tm_hour * 3600000));
8170 json_object_string_add(json_neigh, "bgpTimerUpString",
8171 peer_uptime(p->uptime, timebuf,
8172 BGP_UPTIME_LEN, 0,
8173 NULL));
8174 json_object_int_add(json_neigh,
8175 "bgpTimerUpEstablishedEpoch",
8176 epoch_tbuf);
8177 }
8178
8179 else if (p->status == Active) {
8180 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8181 json_object_string_add(json_neigh, "bgpStateIs",
8182 "passive");
8183 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8184 json_object_string_add(json_neigh, "bgpStateIs",
8185 "passiveNSF");
8186 }
8187
8188 /* read timer */
8189 time_t uptime;
8190 struct tm *tm;
8191
8192 uptime = bgp_clock();
8193 uptime -= p->readtime;
8194 tm = gmtime(&uptime);
8195 json_object_int_add(json_neigh, "bgpTimerLastRead",
8196 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8197 + (tm->tm_hour * 3600000));
8198
8199 uptime = bgp_clock();
8200 uptime -= p->last_write;
8201 tm = gmtime(&uptime);
8202 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8203 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8204 + (tm->tm_hour * 3600000));
8205
8206 uptime = bgp_clock();
8207 uptime -= p->update_time;
8208 tm = gmtime(&uptime);
8209 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8210 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8211 + (tm->tm_hour * 3600000));
8212
8213 /* Configured timer values. */
8214 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8215 p->v_holdtime * 1000);
8216 json_object_int_add(json_neigh,
8217 "bgpTimerKeepAliveIntervalMsecs",
8218 p->v_keepalive * 1000);
8219
8220 if (CHECK_FLAG(p->config, PEER_CONFIG_TIMER)) {
8221 json_object_int_add(json_neigh,
8222 "bgpTimerConfiguredHoldTimeMsecs",
8223 p->holdtime * 1000);
8224 json_object_int_add(
8225 json_neigh,
8226 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8227 p->keepalive * 1000);
8228 }
8229 } else {
8230 /* Administrative shutdown. */
8231 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8232 vty_out(vty, " Administratively shut down\n");
8233
8234 /* BGP Version. */
8235 vty_out(vty, " BGP version 4");
8236 vty_out(vty, ", remote router ID %s\n",
8237 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8238
8239 /* Confederation */
8240 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8241 && bgp_confederation_peers_check(bgp, p->as))
8242 vty_out(vty,
8243 " Neighbor under common administration\n");
8244
8245 /* Status. */
8246 vty_out(vty, " BGP state = %s",
8247 lookup_msg(bgp_status_msg, p->status, NULL));
8248
8249 if (p->status == Established)
8250 vty_out(vty, ", up for %8s",
8251 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8252 0, NULL));
8253
8254 else if (p->status == Active) {
8255 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8256 vty_out(vty, " (passive)");
8257 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8258 vty_out(vty, " (NSF passive)");
8259 }
8260 vty_out(vty, "\n");
8261
8262 /* read timer */
8263 vty_out(vty, " Last read %s",
8264 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8265 NULL));
8266 vty_out(vty, ", Last write %s\n",
8267 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8268 NULL));
8269
8270 /* Configured timer values. */
8271 vty_out(vty,
8272 " Hold time is %d, keepalive interval is %d seconds\n",
8273 p->v_holdtime, p->v_keepalive);
8274 if (CHECK_FLAG(p->config, PEER_CONFIG_TIMER)) {
8275 vty_out(vty, " Configured hold time is %d",
8276 p->holdtime);
8277 vty_out(vty, ", keepalive interval is %d seconds\n",
8278 p->keepalive);
8279 }
8280 }
8281 /* Capability. */
8282 if (p->status == Established) {
8283 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8284 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8285 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8286 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8287 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8288 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8289 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8290 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8291 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8292 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8293 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8294 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8295 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8296 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8297 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8298 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8299 if (use_json) {
8300 json_object *json_cap = NULL;
8301
8302 json_cap = json_object_new_object();
8303
8304 /* AS4 */
8305 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8306 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8307 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8308 && CHECK_FLAG(p->cap,
8309 PEER_CAP_AS4_RCV))
8310 json_object_string_add(
8311 json_cap, "4byteAs",
8312 "advertisedAndReceived");
8313 else if (CHECK_FLAG(p->cap,
8314 PEER_CAP_AS4_ADV))
8315 json_object_string_add(
8316 json_cap, "4byteAs",
8317 "advertised");
8318 else if (CHECK_FLAG(p->cap,
8319 PEER_CAP_AS4_RCV))
8320 json_object_string_add(
8321 json_cap, "4byteAs",
8322 "received");
8323 }
8324
8325 /* AddPath */
8326 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8327 || CHECK_FLAG(p->cap,
8328 PEER_CAP_ADDPATH_ADV)) {
8329 json_object *json_add = NULL;
8330 const char *print_store;
8331
8332 json_add = json_object_new_object();
8333
8334 for (afi = AFI_IP; afi < AFI_MAX; afi++)
8335 for (safi = SAFI_UNICAST;
8336 safi < SAFI_MAX; safi++) {
8337 json_object *json_sub =
8338 NULL;
8339 json_sub =
8340 json_object_new_object();
8341 print_store =
8342 afi_safi_print(
8343 afi,
8344 safi);
8345
8346 if (CHECK_FLAG(
8347 p->af_cap
8348 [afi]
8349 [safi],
8350 PEER_CAP_ADDPATH_AF_TX_ADV)
8351 || CHECK_FLAG(
8352 p->af_cap
8353 [afi]
8354 [safi],
8355 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8356 if (CHECK_FLAG(
8357 p->af_cap
8358 [afi]
8359 [safi],
8360 PEER_CAP_ADDPATH_AF_TX_ADV)
8361 && CHECK_FLAG(
8362 p->af_cap
8363 [afi]
8364 [safi],
8365 PEER_CAP_ADDPATH_AF_TX_RCV))
8366 json_object_boolean_true_add(
8367 json_sub,
8368 "txAdvertisedAndReceived");
8369 else if (
8370 CHECK_FLAG(
8371 p->af_cap
8372 [afi]
8373 [safi],
8374 PEER_CAP_ADDPATH_AF_TX_ADV))
8375 json_object_boolean_true_add(
8376 json_sub,
8377 "txAdvertised");
8378 else if (
8379 CHECK_FLAG(
8380 p->af_cap
8381 [afi]
8382 [safi],
8383 PEER_CAP_ADDPATH_AF_TX_RCV))
8384 json_object_boolean_true_add(
8385 json_sub,
8386 "txReceived");
8387 }
8388
8389 if (CHECK_FLAG(
8390 p->af_cap
8391 [afi]
8392 [safi],
8393 PEER_CAP_ADDPATH_AF_RX_ADV)
8394 || CHECK_FLAG(
8395 p->af_cap
8396 [afi]
8397 [safi],
8398 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8399 if (CHECK_FLAG(
8400 p->af_cap
8401 [afi]
8402 [safi],
8403 PEER_CAP_ADDPATH_AF_RX_ADV)
8404 && CHECK_FLAG(
8405 p->af_cap
8406 [afi]
8407 [safi],
8408 PEER_CAP_ADDPATH_AF_RX_RCV))
8409 json_object_boolean_true_add(
8410 json_sub,
8411 "rxAdvertisedAndReceived");
8412 else if (
8413 CHECK_FLAG(
8414 p->af_cap
8415 [afi]
8416 [safi],
8417 PEER_CAP_ADDPATH_AF_RX_ADV))
8418 json_object_boolean_true_add(
8419 json_sub,
8420 "rxAdvertised");
8421 else if (
8422 CHECK_FLAG(
8423 p->af_cap
8424 [afi]
8425 [safi],
8426 PEER_CAP_ADDPATH_AF_RX_RCV))
8427 json_object_boolean_true_add(
8428 json_sub,
8429 "rxReceived");
8430 }
8431
8432 if (CHECK_FLAG(
8433 p->af_cap
8434 [afi]
8435 [safi],
8436 PEER_CAP_ADDPATH_AF_TX_ADV)
8437 || CHECK_FLAG(
8438 p->af_cap
8439 [afi]
8440 [safi],
8441 PEER_CAP_ADDPATH_AF_TX_RCV)
8442 || CHECK_FLAG(
8443 p->af_cap
8444 [afi]
8445 [safi],
8446 PEER_CAP_ADDPATH_AF_RX_ADV)
8447 || CHECK_FLAG(
8448 p->af_cap
8449 [afi]
8450 [safi],
8451 PEER_CAP_ADDPATH_AF_RX_RCV))
8452 json_object_object_add(
8453 json_add,
8454 print_store,
8455 json_sub);
8456 else
8457 json_object_free(
8458 json_sub);
8459 }
8460
8461 json_object_object_add(
8462 json_cap, "addPath", json_add);
8463 }
8464
8465 /* Dynamic */
8466 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8467 || CHECK_FLAG(p->cap,
8468 PEER_CAP_DYNAMIC_ADV)) {
8469 if (CHECK_FLAG(p->cap,
8470 PEER_CAP_DYNAMIC_ADV)
8471 && CHECK_FLAG(p->cap,
8472 PEER_CAP_DYNAMIC_RCV))
8473 json_object_string_add(
8474 json_cap, "dynamic",
8475 "advertisedAndReceived");
8476 else if (CHECK_FLAG(
8477 p->cap,
8478 PEER_CAP_DYNAMIC_ADV))
8479 json_object_string_add(
8480 json_cap, "dynamic",
8481 "advertised");
8482 else if (CHECK_FLAG(
8483 p->cap,
8484 PEER_CAP_DYNAMIC_RCV))
8485 json_object_string_add(
8486 json_cap, "dynamic",
8487 "received");
8488 }
8489
8490 /* Extended nexthop */
8491 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8492 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8493 json_object *json_nxt = NULL;
8494 const char *print_store;
8495
8496
8497 if (CHECK_FLAG(p->cap,
8498 PEER_CAP_ENHE_ADV)
8499 && CHECK_FLAG(p->cap,
8500 PEER_CAP_ENHE_RCV))
8501 json_object_string_add(
8502 json_cap,
8503 "extendedNexthop",
8504 "advertisedAndReceived");
8505 else if (CHECK_FLAG(p->cap,
8506 PEER_CAP_ENHE_ADV))
8507 json_object_string_add(
8508 json_cap,
8509 "extendedNexthop",
8510 "advertised");
8511 else if (CHECK_FLAG(p->cap,
8512 PEER_CAP_ENHE_RCV))
8513 json_object_string_add(
8514 json_cap,
8515 "extendedNexthop",
8516 "received");
8517
8518 if (CHECK_FLAG(p->cap,
8519 PEER_CAP_ENHE_RCV)) {
8520 json_nxt =
8521 json_object_new_object();
8522
8523 for (safi = SAFI_UNICAST;
8524 safi < SAFI_MAX; safi++) {
8525 if (CHECK_FLAG(
8526 p->af_cap
8527 [AFI_IP]
8528 [safi],
8529 PEER_CAP_ENHE_AF_RCV)) {
8530 print_store = afi_safi_print(
8531 AFI_IP,
8532 safi);
8533 json_object_string_add(
8534 json_nxt,
8535 print_store,
8536 "recieved");
8537 }
8538 }
8539 json_object_object_add(
8540 json_cap,
8541 "extendedNexthopFamililesByPeer",
8542 json_nxt);
8543 }
8544 }
8545
8546 /* Route Refresh */
8547 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8548 || CHECK_FLAG(p->cap,
8549 PEER_CAP_REFRESH_NEW_RCV)
8550 || CHECK_FLAG(p->cap,
8551 PEER_CAP_REFRESH_OLD_RCV)) {
8552 if (CHECK_FLAG(p->cap,
8553 PEER_CAP_REFRESH_ADV)
8554 && (CHECK_FLAG(
8555 p->cap,
8556 PEER_CAP_REFRESH_NEW_RCV)
8557 || CHECK_FLAG(
8558 p->cap,
8559 PEER_CAP_REFRESH_OLD_RCV))) {
8560 if (CHECK_FLAG(
8561 p->cap,
8562 PEER_CAP_REFRESH_OLD_RCV)
8563 && CHECK_FLAG(
8564 p->cap,
8565 PEER_CAP_REFRESH_NEW_RCV))
8566 json_object_string_add(
8567 json_cap,
8568 "routeRefresh",
8569 "advertisedAndReceivedOldNew");
8570 else {
8571 if (CHECK_FLAG(
8572 p->cap,
8573 PEER_CAP_REFRESH_OLD_RCV))
8574 json_object_string_add(
8575 json_cap,
8576 "routeRefresh",
8577 "advertisedAndReceivedOld");
8578 else
8579 json_object_string_add(
8580 json_cap,
8581 "routeRefresh",
8582 "advertisedAndReceivedNew");
8583 }
8584 } else if (
8585 CHECK_FLAG(
8586 p->cap,
8587 PEER_CAP_REFRESH_ADV))
8588 json_object_string_add(
8589 json_cap,
8590 "routeRefresh",
8591 "advertised");
8592 else if (
8593 CHECK_FLAG(
8594 p->cap,
8595 PEER_CAP_REFRESH_NEW_RCV)
8596 || CHECK_FLAG(
8597 p->cap,
8598 PEER_CAP_REFRESH_OLD_RCV))
8599 json_object_string_add(
8600 json_cap,
8601 "routeRefresh",
8602 "received");
8603 }
8604
8605 /* Multiprotocol Extensions */
8606 json_object *json_multi = NULL;
8607 json_multi = json_object_new_object();
8608
8609 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
8610 for (safi = SAFI_UNICAST;
8611 safi < SAFI_MAX; safi++) {
8612 if (p->afc_adv[afi][safi]
8613 || p->afc_recv[afi][safi]) {
8614 json_object
8615 *json_exten =
8616 NULL;
8617 json_exten =
8618 json_object_new_object();
8619
8620 if (p->afc_adv[afi]
8621 [safi]
8622 && p->afc_recv
8623 [afi]
8624 [safi])
8625 json_object_boolean_true_add(
8626 json_exten,
8627 "advertisedAndReceived");
8628 else if (p->afc_adv
8629 [afi]
8630 [safi])
8631 json_object_boolean_true_add(
8632 json_exten,
8633 "advertised");
8634 else if (p->afc_recv
8635 [afi]
8636 [safi])
8637 json_object_boolean_true_add(
8638 json_exten,
8639 "received");
8640
8641 json_object_object_add(
8642 json_multi,
8643 afi_safi_print(
8644 afi,
8645 safi),
8646 json_exten);
8647 }
8648 }
8649 }
8650 json_object_object_add(
8651 json_cap, "multiprotocolExtensions",
8652 json_multi);
8653
d77114b7
MK
8654 /* Hostname capabilities */
8655 json_object *json_hname = NULL;
8656
8657 json_hname = json_object_new_object();
8658
8659 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
8660 json_object_string_add(
8661 json_hname,
8662 "advHostName",
8663 bgp->peer_self->hostname ?
8664 bgp->peer_self->hostname
8665 : "n/a");
8666 json_object_string_add(
8667 json_hname,
8668 "advDomainName",
8669 bgp->peer_self->domainname ?
8670 bgp->peer_self->domainname
8671 : "n/a");
8672 }
8673
8674
8675 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
8676 json_object_string_add(
8677 json_hname,
8678 "rcvHostName",
8679 p->hostname ?
8680 p->hostname :
8681 "n/a");
8682 json_object_string_add(
8683 json_hname,
8684 "rcvDomainName",
8685 p->domainname ?
8686 p->domainname :
8687 "n/a");
8688 }
8689
8690 json_object_object_add(json_cap,
8691 "hostName",
8692 json_hname);
8693
d62a17ae 8694 /* Gracefull Restart */
8695 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
8696 || CHECK_FLAG(p->cap,
8697 PEER_CAP_RESTART_ADV)) {
8698 if (CHECK_FLAG(p->cap,
8699 PEER_CAP_RESTART_ADV)
8700 && CHECK_FLAG(p->cap,
8701 PEER_CAP_RESTART_RCV))
8702 json_object_string_add(
8703 json_cap,
8704 "gracefulRestart",
8705 "advertisedAndReceived");
8706 else if (CHECK_FLAG(
8707 p->cap,
8708 PEER_CAP_RESTART_ADV))
8709 json_object_string_add(
8710 json_cap,
8711 "gracefulRestartCapability",
8712 "advertised");
8713 else if (CHECK_FLAG(
8714 p->cap,
8715 PEER_CAP_RESTART_RCV))
8716 json_object_string_add(
8717 json_cap,
8718 "gracefulRestartCapability",
8719 "received");
8720
8721 if (CHECK_FLAG(p->cap,
8722 PEER_CAP_RESTART_RCV)) {
8723 int restart_af_count = 0;
8724 json_object *json_restart =
8725 NULL;
8726 json_restart =
8727 json_object_new_object();
8728
8729 json_object_int_add(
8730 json_cap,
8731 "gracefulRestartRemoteTimerMsecs",
8732 p->v_gr_restart * 1000);
8733
8734 for (afi = AFI_IP;
8735 afi < AFI_MAX; afi++) {
8736 for (safi = SAFI_UNICAST;
8737 safi < SAFI_MAX;
8738 safi++) {
8739 if (CHECK_FLAG(
8740 p->af_cap
8741 [afi]
8742 [safi],
8743 PEER_CAP_RESTART_AF_RCV)) {
8744 json_object *json_sub =
8745 NULL;
8746 json_sub =
8747 json_object_new_object();
8748
8749 if (CHECK_FLAG(
8750 p->af_cap
8751 [afi]
8752 [safi],
8753 PEER_CAP_RESTART_AF_PRESERVE_RCV))
8754 json_object_boolean_true_add(
8755 json_sub,
8756 "preserved");
8757 restart_af_count++;
8758 json_object_object_add(
8759 json_restart,
8760 afi_safi_print(
8761 afi,
8762 safi),
8763 json_sub);
8764 }
8765 }
8766 }
8767 if (!restart_af_count) {
8768 json_object_string_add(
8769 json_cap,
8770 "addressFamiliesByPeer",
8771 "none");
8772 json_object_free(
8773 json_restart);
8774 } else
8775 json_object_object_add(
8776 json_cap,
8777 "addressFamiliesByPeer",
8778 json_restart);
8779 }
8780 }
8781 json_object_object_add(json_neigh,
8782 "neighborCapabilities",
8783 json_cap);
8784 } else {
8785 vty_out(vty, " Neighbor capabilities:\n");
8786
8787 /* AS4 */
8788 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8789 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8790 vty_out(vty, " 4 Byte AS:");
8791 if (CHECK_FLAG(p->cap,
8792 PEER_CAP_AS4_ADV))
8793 vty_out(vty, " advertised");
8794 if (CHECK_FLAG(p->cap,
8795 PEER_CAP_AS4_RCV))
8796 vty_out(vty, " %sreceived",
8797 CHECK_FLAG(
8798 p->cap,
8799 PEER_CAP_AS4_ADV)
8800 ? "and "
8801 : "");
8802 vty_out(vty, "\n");
8803 }
8804
8805 /* AddPath */
8806 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8807 || CHECK_FLAG(p->cap,
8808 PEER_CAP_ADDPATH_ADV)) {
8809 vty_out(vty, " AddPath:\n");
8810
8811 for (afi = AFI_IP; afi < AFI_MAX; afi++)
8812 for (safi = SAFI_UNICAST;
8813 safi < SAFI_MAX; safi++) {
8814 if (CHECK_FLAG(
8815 p->af_cap
8816 [afi]
8817 [safi],
8818 PEER_CAP_ADDPATH_AF_TX_ADV)
8819 || CHECK_FLAG(
8820 p->af_cap
8821 [afi]
8822 [safi],
8823 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8824 vty_out(vty,
8825 " %s: TX ",
8826 afi_safi_print(
8827 afi,
8828 safi));
8829
8830 if (CHECK_FLAG(
8831 p->af_cap
8832 [afi]
8833 [safi],
8834 PEER_CAP_ADDPATH_AF_TX_ADV))
8835 vty_out(vty,
8836 "advertised %s",
8837 afi_safi_print(
8838 afi,
8839 safi));
8840
8841 if (CHECK_FLAG(
8842 p->af_cap
8843 [afi]
8844 [safi],
8845 PEER_CAP_ADDPATH_AF_TX_RCV))
8846 vty_out(vty,
8847 "%sreceived",
8848 CHECK_FLAG(
8849 p->af_cap
8850 [afi]
8851 [safi],
8852 PEER_CAP_ADDPATH_AF_TX_ADV)
8853 ? " and "
8854 : "");
8855
8856 vty_out(vty,
8857 "\n");
8858 }
8859
8860 if (CHECK_FLAG(
8861 p->af_cap
8862 [afi]
8863 [safi],
8864 PEER_CAP_ADDPATH_AF_RX_ADV)
8865 || CHECK_FLAG(
8866 p->af_cap
8867 [afi]
8868 [safi],
8869 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8870 vty_out(vty,
8871 " %s: RX ",
8872 afi_safi_print(
8873 afi,
8874 safi));
8875
8876 if (CHECK_FLAG(
8877 p->af_cap
8878 [afi]
8879 [safi],
8880 PEER_CAP_ADDPATH_AF_RX_ADV))
8881 vty_out(vty,
8882 "advertised %s",
8883 afi_safi_print(
8884 afi,
8885 safi));
8886
8887 if (CHECK_FLAG(
8888 p->af_cap
8889 [afi]
8890 [safi],
8891 PEER_CAP_ADDPATH_AF_RX_RCV))
8892 vty_out(vty,
8893 "%sreceived",
8894 CHECK_FLAG(
8895 p->af_cap
8896 [afi]
8897 [safi],
8898 PEER_CAP_ADDPATH_AF_RX_ADV)
8899 ? " and "
8900 : "");
8901
8902 vty_out(vty,
8903 "\n");
8904 }
8905 }
8906 }
8907
8908 /* Dynamic */
8909 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8910 || CHECK_FLAG(p->cap,
8911 PEER_CAP_DYNAMIC_ADV)) {
8912 vty_out(vty, " Dynamic:");
8913 if (CHECK_FLAG(p->cap,
8914 PEER_CAP_DYNAMIC_ADV))
8915 vty_out(vty, " advertised");
8916 if (CHECK_FLAG(p->cap,
8917 PEER_CAP_DYNAMIC_RCV))
8918 vty_out(vty, " %sreceived",
8919 CHECK_FLAG(
8920 p->cap,
8921 PEER_CAP_DYNAMIC_ADV)
8922 ? "and "
8923 : "");
8924 vty_out(vty, "\n");
8925 }
8926
8927 /* Extended nexthop */
8928 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8929 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8930 vty_out(vty, " Extended nexthop:");
8931 if (CHECK_FLAG(p->cap,
8932 PEER_CAP_ENHE_ADV))
8933 vty_out(vty, " advertised");
8934 if (CHECK_FLAG(p->cap,
8935 PEER_CAP_ENHE_RCV))
8936 vty_out(vty, " %sreceived",
8937 CHECK_FLAG(
8938 p->cap,
8939 PEER_CAP_ENHE_ADV)
8940 ? "and "
8941 : "");
8942 vty_out(vty, "\n");
8943
8944 if (CHECK_FLAG(p->cap,
8945 PEER_CAP_ENHE_RCV)) {
8946 vty_out(vty,
8947 " Address families by peer:\n ");
8948 for (safi = SAFI_UNICAST;
8949 safi < SAFI_MAX; safi++)
8950 if (CHECK_FLAG(
8951 p->af_cap
8952 [AFI_IP]
8953 [safi],
8954 PEER_CAP_ENHE_AF_RCV))
8955 vty_out(vty,
8956 " %s\n",
8957 afi_safi_print(
8958 AFI_IP,
8959 safi));
8960 }
8961 }
8962
8963 /* Route Refresh */
8964 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8965 || CHECK_FLAG(p->cap,
8966 PEER_CAP_REFRESH_NEW_RCV)
8967 || CHECK_FLAG(p->cap,
8968 PEER_CAP_REFRESH_OLD_RCV)) {
8969 vty_out(vty, " Route refresh:");
8970 if (CHECK_FLAG(p->cap,
8971 PEER_CAP_REFRESH_ADV))
8972 vty_out(vty, " advertised");
8973 if (CHECK_FLAG(p->cap,
8974 PEER_CAP_REFRESH_NEW_RCV)
8975 || CHECK_FLAG(
8976 p->cap,
8977 PEER_CAP_REFRESH_OLD_RCV))
8978 vty_out(vty, " %sreceived(%s)",
8979 CHECK_FLAG(
8980 p->cap,
8981 PEER_CAP_REFRESH_ADV)
8982 ? "and "
8983 : "",
8984 (CHECK_FLAG(
8985 p->cap,
8986 PEER_CAP_REFRESH_OLD_RCV)
8987 && CHECK_FLAG(
8988 p->cap,
8989 PEER_CAP_REFRESH_NEW_RCV))
8990 ? "old & new"
8991 : CHECK_FLAG(
8992 p->cap,
8993 PEER_CAP_REFRESH_OLD_RCV)
8994 ? "old"
8995 : "new");
8996
8997 vty_out(vty, "\n");
8998 }
8999
9000 /* Multiprotocol Extensions */
9001 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9002 for (safi = SAFI_UNICAST;
9003 safi < SAFI_MAX; safi++)
9004 if (p->afc_adv[afi][safi]
9005 || p->afc_recv[afi][safi]) {
9006 vty_out(vty,
9007 " Address Family %s:",
9008 afi_safi_print(
9009 afi,
9010 safi));
9011 if (p->afc_adv[afi]
9012 [safi])
9013 vty_out(vty,
9014 " advertised");
9015 if (p->afc_recv[afi]
9016 [safi])
9017 vty_out(vty,
9018 " %sreceived",
9019 p->afc_adv[afi]
9020 [safi]
9021 ? "and "
9022 : "");
9023 vty_out(vty, "\n");
9024 }
9025
9026 /* Hostname capability */
d77114b7
MK
9027 vty_out(vty,
9028 " Hostname Capability:");
9029
9030 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9031 vty_out(vty, " advertised (name: %s, "
9032 "domain name: %s)",
9033 bgp->peer_self->hostname ?
9034 bgp->peer_self->hostname
9035 : "n/a",
9036 bgp->peer_self->domainname ?
9037 bgp->peer_self->domainname
9038 : "n/a");
9039 } else {
9040 vty_out(vty, " not advertised");
d62a17ae 9041 }
9042
d77114b7
MK
9043 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9044 vty_out(vty, " received (name: %s, "
9045 "domain name: %s)",
9046 p->hostname ?
9047 p->hostname : "n/a",
9048 p->domainname ?
9049 p->domainname : "n/a");
9050 } else {
9051 vty_out(vty, " not received");
9052 }
9053
9054 vty_out(vty, "\n");
9055
d62a17ae 9056 /* Gracefull Restart */
9057 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9058 || CHECK_FLAG(p->cap,
9059 PEER_CAP_RESTART_ADV)) {
9060 vty_out(vty,
9061 " Graceful Restart Capabilty:");
9062 if (CHECK_FLAG(p->cap,
9063 PEER_CAP_RESTART_ADV))
9064 vty_out(vty, " advertised");
9065 if (CHECK_FLAG(p->cap,
9066 PEER_CAP_RESTART_RCV))
9067 vty_out(vty, " %sreceived",
9068 CHECK_FLAG(
9069 p->cap,
9070 PEER_CAP_RESTART_ADV)
9071 ? "and "
9072 : "");
9073 vty_out(vty, "\n");
9074
9075 if (CHECK_FLAG(p->cap,
9076 PEER_CAP_RESTART_RCV)) {
9077 int restart_af_count = 0;
9078
9079 vty_out(vty,
9080 " Remote Restart timer is %d seconds\n",
9081 p->v_gr_restart);
9082 vty_out(vty,
9083 " Address families by peer:\n ");
9084
9085 for (afi = AFI_IP;
9086 afi < AFI_MAX; afi++)
9087 for (safi = SAFI_UNICAST;
9088 safi < SAFI_MAX;
9089 safi++)
9090 if (CHECK_FLAG(
9091 p->af_cap
9092 [afi]
9093 [safi],
9094 PEER_CAP_RESTART_AF_RCV)) {
9095 vty_out(vty,
9096 "%s%s(%s)",
9097 restart_af_count
9098 ? ", "
9099 : "",
9100 afi_safi_print(
9101 afi,
9102 safi),
9103 CHECK_FLAG(
9104 p->af_cap
9105 [afi]
9106 [safi],
9107 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9108 ? "preserved"
9109 : "not preserved");
9110 restart_af_count++;
9111 }
9112 if (!restart_af_count)
9113 vty_out(vty, "none");
9114 vty_out(vty, "\n");
9115 }
9116 }
9117 }
9118 }
9119 }
9120
9121 /* graceful restart information */
9122 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9123 || p->t_gr_stale) {
9124 json_object *json_grace = NULL;
9125 json_object *json_grace_send = NULL;
9126 json_object *json_grace_recv = NULL;
9127 int eor_send_af_count = 0;
9128 int eor_receive_af_count = 0;
9129
9130 if (use_json) {
9131 json_grace = json_object_new_object();
9132 json_grace_send = json_object_new_object();
9133 json_grace_recv = json_object_new_object();
9134
9135 if (p->status == Established) {
9136 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9137 for (safi = SAFI_UNICAST;
9138 safi < SAFI_MAX; safi++) {
9139 if (CHECK_FLAG(
9140 p->af_sflags[afi]
9141 [safi],
9142 PEER_STATUS_EOR_SEND)) {
9143 json_object_boolean_true_add(
9144 json_grace_send,
9145 afi_safi_print(
9146 afi,
9147 safi));
9148 eor_send_af_count++;
9149 }
9150 }
9151 }
9152 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9153 for (safi = SAFI_UNICAST;
9154 safi < SAFI_MAX; safi++) {
9155 if (CHECK_FLAG(
9156 p->af_sflags[afi]
9157 [safi],
9158 PEER_STATUS_EOR_RECEIVED)) {
9159 json_object_boolean_true_add(
9160 json_grace_recv,
9161 afi_safi_print(
9162 afi,
9163 safi));
9164 eor_receive_af_count++;
9165 }
9166 }
9167 }
9168 }
9169
9170 json_object_object_add(json_grace, "endOfRibSend",
9171 json_grace_send);
9172 json_object_object_add(json_grace, "endOfRibRecv",
9173 json_grace_recv);
9174
9175 if (p->t_gr_restart)
9176 json_object_int_add(json_grace,
9177 "gracefulRestartTimerMsecs",
9178 thread_timer_remain_second(
9179 p->t_gr_restart)
9180 * 1000);
9181
9182 if (p->t_gr_stale)
9183 json_object_int_add(
9184 json_grace,
9185 "gracefulStalepathTimerMsecs",
9186 thread_timer_remain_second(
9187 p->t_gr_stale)
9188 * 1000);
9189
9190 json_object_object_add(
9191 json_neigh, "gracefulRestartInfo", json_grace);
9192 } else {
9193 vty_out(vty, " Graceful restart informations:\n");
9194 if (p->status == Established) {
9195 vty_out(vty, " End-of-RIB send: ");
9196 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9197 for (safi = SAFI_UNICAST;
9198 safi < SAFI_MAX; safi++) {
9199 if (CHECK_FLAG(
9200 p->af_sflags[afi]
9201 [safi],
9202 PEER_STATUS_EOR_SEND)) {
9203 vty_out(vty, "%s%s",
9204 eor_send_af_count
9205 ? ", "
9206 : "",
9207 afi_safi_print(
9208 afi,
9209 safi));
9210 eor_send_af_count++;
9211 }
9212 }
9213 }
9214 vty_out(vty, "\n");
9215 vty_out(vty, " End-of-RIB received: ");
9216 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9217 for (safi = SAFI_UNICAST;
9218 safi < SAFI_MAX; safi++) {
9219 if (CHECK_FLAG(
9220 p->af_sflags[afi]
9221 [safi],
9222 PEER_STATUS_EOR_RECEIVED)) {
9223 vty_out(vty, "%s%s",
9224 eor_receive_af_count
9225 ? ", "
9226 : "",
9227 afi_safi_print(
9228 afi,
9229 safi));
9230 eor_receive_af_count++;
9231 }
9232 }
9233 }
9234 vty_out(vty, "\n");
9235 }
9236
9237 if (p->t_gr_restart)
9238 vty_out(vty,
9239 " The remaining time of restart timer is %ld\n",
9240 thread_timer_remain_second(
9241 p->t_gr_restart));
9242
9243 if (p->t_gr_stale)
9244 vty_out(vty,
9245 " The remaining time of stalepath timer is %ld\n",
9246 thread_timer_remain_second(
9247 p->t_gr_stale));
9248 }
9249 }
9250 if (use_json) {
9251 json_object *json_stat = NULL;
9252 json_stat = json_object_new_object();
9253 /* Packet counts. */
9254 json_object_int_add(json_stat, "depthInq", 0);
9255 json_object_int_add(json_stat, "depthOutq",
9256 (unsigned long)p->obuf->count);
9257 json_object_int_add(json_stat, "opensSent", p->open_out);
9258 json_object_int_add(json_stat, "opensRecv", p->open_in);
9259 json_object_int_add(json_stat, "notificationsSent",
9260 p->notify_out);
9261 json_object_int_add(json_stat, "notificationsRecv",
9262 p->notify_in);
9263 json_object_int_add(json_stat, "updatesSent", p->update_out);
9264 json_object_int_add(json_stat, "updatesRecv", p->update_in);
9265 json_object_int_add(json_stat, "keepalivesSent",
9266 p->keepalive_out);
9267 json_object_int_add(json_stat, "keepalivesRecv",
9268 p->keepalive_in);
9269 json_object_int_add(json_stat, "routeRefreshSent",
9270 p->refresh_out);
9271 json_object_int_add(json_stat, "routeRefreshRecv",
9272 p->refresh_in);
9273 json_object_int_add(json_stat, "capabilitySent",
9274 p->dynamic_cap_out);
9275 json_object_int_add(json_stat, "capabilityRecv",
9276 p->dynamic_cap_in);
9277 json_object_int_add(json_stat, "totalSent",
9278 p->open_out + p->notify_out + p->update_out
9279 + p->keepalive_out + p->refresh_out
9280 + p->dynamic_cap_out);
9281 json_object_int_add(json_stat, "totalRecv",
9282 p->open_in + p->notify_in + p->update_in
9283 + p->keepalive_in + p->refresh_in
9284 + p->dynamic_cap_in);
9285 json_object_object_add(json_neigh, "messageStats", json_stat);
9286 } else {
9287 /* Packet counts. */
9288 vty_out(vty, " Message statistics:\n");
9289 vty_out(vty, " Inq depth is 0\n");
9290 vty_out(vty, " Outq depth is %lu\n",
9291 (unsigned long)p->obuf->count);
9292 vty_out(vty, " Sent Rcvd\n");
9293 vty_out(vty, " Opens: %10d %10d\n", p->open_out,
9294 p->open_in);
9295 vty_out(vty, " Notifications: %10d %10d\n", p->notify_out,
9296 p->notify_in);
9297 vty_out(vty, " Updates: %10d %10d\n", p->update_out,
9298 p->update_in);
9299 vty_out(vty, " Keepalives: %10d %10d\n", p->keepalive_out,
9300 p->keepalive_in);
9301 vty_out(vty, " Route Refresh: %10d %10d\n", p->refresh_out,
9302 p->refresh_in);
9303 vty_out(vty, " Capability: %10d %10d\n",
9304 p->dynamic_cap_out, p->dynamic_cap_in);
9305 vty_out(vty, " Total: %10d %10d\n",
9306 p->open_out + p->notify_out + p->update_out
9307 + p->keepalive_out + p->refresh_out
9308 + p->dynamic_cap_out,
9309 p->open_in + p->notify_in + p->update_in
9310 + p->keepalive_in + p->refresh_in
9311 + p->dynamic_cap_in);
9312 }
9313
9314 if (use_json) {
9315 /* advertisement-interval */
9316 json_object_int_add(json_neigh,
9317 "minBtwnAdvertisementRunsTimerMsecs",
9318 p->v_routeadv * 1000);
9319
9320 /* Update-source. */
9321 if (p->update_if || p->update_source) {
9322 if (p->update_if)
9323 json_object_string_add(json_neigh,
9324 "updateSource",
9325 p->update_if);
9326 else if (p->update_source)
9327 json_object_string_add(
9328 json_neigh, "updateSource",
9329 sockunion2str(p->update_source, buf1,
9330 SU_ADDRSTRLEN));
9331 }
9332 } else {
9333 /* advertisement-interval */
9334 vty_out(vty,
9335 " Minimum time between advertisement runs is %d seconds\n",
9336 p->v_routeadv);
9337
9338 /* Update-source. */
9339 if (p->update_if || p->update_source) {
9340 vty_out(vty, " Update source is ");
9341 if (p->update_if)
9342 vty_out(vty, "%s", p->update_if);
9343 else if (p->update_source)
9344 vty_out(vty, "%s",
9345 sockunion2str(p->update_source, buf1,
9346 SU_ADDRSTRLEN));
9347 vty_out(vty, "\n");
9348 }
9349
9350 vty_out(vty, "\n");
9351 }
9352
9353 /* Address Family Information */
9354 json_object *json_hold = NULL;
9355
9356 if (use_json)
9357 json_hold = json_object_new_object();
9358
9359 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9360 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
9361 if (p->afc[afi][safi])
9362 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9363 json_hold);
9364
9365 if (use_json) {
9366 json_object_object_add(json_neigh, "addressFamilyInfo",
9367 json_hold);
9368 json_object_int_add(json_neigh, "connectionsEstablished",
9369 p->established);
9370 json_object_int_add(json_neigh, "connectionsDropped",
9371 p->dropped);
9372 } else
9373 vty_out(vty, " Connections established %d; dropped %d\n",
9374 p->established, p->dropped);
9375
9376 if (!p->last_reset) {
9377 if (use_json)
9378 json_object_string_add(json_neigh, "lastReset",
9379 "never");
9380 else
9381 vty_out(vty, " Last reset never\n");
9382 } else {
9383 if (use_json) {
9384 time_t uptime;
9385 struct tm *tm;
9386
9387 uptime = bgp_clock();
9388 uptime -= p->resettime;
9389 tm = gmtime(&uptime);
9390 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9391 (tm->tm_sec * 1000)
9392 + (tm->tm_min * 60000)
9393 + (tm->tm_hour * 3600000));
9394 json_object_string_add(
9395 json_neigh, "lastResetDueTo",
9396 peer_down_str[(int)p->last_reset]);
9397 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9398 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9399 char errorcodesubcode_hexstr[5];
9400 char errorcodesubcode_str[256];
9401
9402 code_str = bgp_notify_code_str(p->notify.code);
9403 subcode_str = bgp_notify_subcode_str(
9404 p->notify.code, p->notify.subcode);
9405
9406 sprintf(errorcodesubcode_hexstr, "%02X%02X",
9407 p->notify.code, p->notify.subcode);
9408 json_object_string_add(json_neigh,
9409 "lastErrorCodeSubcode",
9410 errorcodesubcode_hexstr);
9411 snprintf(errorcodesubcode_str, 255, "%s%s",
9412 code_str, subcode_str);
9413 json_object_string_add(json_neigh,
9414 "lastNotificationReason",
9415 errorcodesubcode_str);
9416 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9417 && p->notify.code == BGP_NOTIFY_CEASE
9418 && (p->notify.subcode
9419 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9420 || p->notify.subcode
9421 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9422 && p->notify.length) {
9423 char msgbuf[1024];
9424 const char *msg_str;
9425
9426 msg_str = bgp_notify_admin_message(
9427 msgbuf, sizeof(msgbuf),
9428 (u_char *)p->notify.data,
9429 p->notify.length);
9430 if (msg_str)
9431 json_object_string_add(
9432 json_neigh,
9433 "lastShutdownDescription",
9434 msg_str);
9435 }
9436 }
9437 } else {
9438 vty_out(vty, " Last reset %s, ",
9439 peer_uptime(p->resettime, timebuf,
9440 BGP_UPTIME_LEN, 0, NULL));
9441
9442 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9443 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9444 code_str = bgp_notify_code_str(p->notify.code);
9445 subcode_str = bgp_notify_subcode_str(
9446 p->notify.code, p->notify.subcode);
9447 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
9448 p->last_reset == PEER_DOWN_NOTIFY_SEND
9449 ? "sent"
9450 : "received",
9451 code_str, subcode_str);
9452 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9453 && p->notify.code == BGP_NOTIFY_CEASE
9454 && (p->notify.subcode
9455 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9456 || p->notify.subcode
9457 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9458 && p->notify.length) {
9459 char msgbuf[1024];
9460 const char *msg_str;
9461
9462 msg_str = bgp_notify_admin_message(
9463 msgbuf, sizeof(msgbuf),
9464 (u_char *)p->notify.data,
9465 p->notify.length);
9466 if (msg_str)
9467 vty_out(vty,
9468 " Message: \"%s\"\n",
9469 msg_str);
9470 }
9471 } else {
9472 vty_out(vty, "due to %s\n",
9473 peer_down_str[(int)p->last_reset]);
9474 }
9475
9476 if (p->last_reset_cause_size) {
9477 msg = p->last_reset_cause;
9478 vty_out(vty,
9479 " Message received that caused BGP to send a NOTIFICATION:\n ");
9480 for (i = 1; i <= p->last_reset_cause_size;
9481 i++) {
9482 vty_out(vty, "%02X", *msg++);
9483
9484 if (i != p->last_reset_cause_size) {
9485 if (i % 16 == 0) {
9486 vty_out(vty, "\n ");
9487 } else if (i % 4 == 0) {
9488 vty_out(vty, " ");
9489 }
9490 }
9491 }
9492 vty_out(vty, "\n");
9493 }
9494 }
9495 }
9496
9497 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
9498 if (use_json)
9499 json_object_boolean_true_add(json_neigh,
9500 "prefixesConfigExceedMax");
9501 else
9502 vty_out(vty,
9503 " Peer had exceeded the max. no. of prefixes configured.\n");
9504
9505 if (p->t_pmax_restart) {
9506 if (use_json) {
9507 json_object_boolean_true_add(
9508 json_neigh, "reducePrefixNumFrom");
9509 json_object_int_add(json_neigh,
9510 "restartInTimerMsec",
9511 thread_timer_remain_second(
9512 p->t_pmax_restart)
9513 * 1000);
9514 } else
9515 vty_out(vty,
9516 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
9d303b37
DL
9517 p->host, thread_timer_remain_second(
9518 p->t_pmax_restart));
d62a17ae 9519 } else {
9520 if (use_json)
9521 json_object_boolean_true_add(
9522 json_neigh,
9523 "reducePrefixNumAndClearIpBgp");
9524 else
9525 vty_out(vty,
9526 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
9527 p->host);
9528 }
9529 }
9530
9531 /* EBGP Multihop and GTSM */
9532 if (p->sort != BGP_PEER_IBGP) {
9533 if (use_json) {
9534 if (p->gtsm_hops > 0)
9535 json_object_int_add(json_neigh,
9536 "externalBgpNbrMaxHopsAway",
9537 p->gtsm_hops);
9538 else if (p->ttl > 1)
9539 json_object_int_add(json_neigh,
9540 "externalBgpNbrMaxHopsAway",
9541 p->ttl);
9542 } else {
9543 if (p->gtsm_hops > 0)
9544 vty_out(vty,
9545 " External BGP neighbor may be up to %d hops away.\n",
9546 p->gtsm_hops);
9547 else if (p->ttl > 1)
9548 vty_out(vty,
9549 " External BGP neighbor may be up to %d hops away.\n",
9550 p->ttl);
9551 }
9552 } else {
9553 if (p->gtsm_hops > 0) {
9554 if (use_json)
9555 json_object_int_add(json_neigh,
9556 "internalBgpNbrMaxHopsAway",
9557 p->gtsm_hops);
9558 else
9559 vty_out(vty,
9560 " Internal BGP neighbor may be up to %d hops away.\n",
9561 p->gtsm_hops);
9562 }
9563 }
9564
9565 /* Local address. */
9566 if (p->su_local) {
9567 if (use_json) {
9568 json_object_string_add(json_neigh, "hostLocal",
9569 sockunion2str(p->su_local, buf1,
9570 SU_ADDRSTRLEN));
9571 json_object_int_add(json_neigh, "portLocal",
9572 ntohs(p->su_local->sin.sin_port));
9573 } else
9574 vty_out(vty, "Local host: %s, Local port: %d\n",
9575 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
9576 ntohs(p->su_local->sin.sin_port));
9577 }
9578
9579 /* Remote address. */
9580 if (p->su_remote) {
9581 if (use_json) {
9582 json_object_string_add(json_neigh, "hostForeign",
9583 sockunion2str(p->su_remote, buf1,
9584 SU_ADDRSTRLEN));
9585 json_object_int_add(json_neigh, "portForeign",
9586 ntohs(p->su_remote->sin.sin_port));
9587 } else
9588 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
9589 sockunion2str(p->su_remote, buf1,
9590 SU_ADDRSTRLEN),
9591 ntohs(p->su_remote->sin.sin_port));
9592 }
9593
9594 /* Nexthop display. */
9595 if (p->su_local) {
9596 if (use_json) {
9597 json_object_string_add(json_neigh, "nexthop",
9598 inet_ntop(AF_INET,
9599 &p->nexthop.v4, buf1,
9600 sizeof(buf1)));
9601 json_object_string_add(json_neigh, "nexthopGlobal",
9602 inet_ntop(AF_INET6,
9603 &p->nexthop.v6_global,
9604 buf1, sizeof(buf1)));
9605 json_object_string_add(json_neigh, "nexthopLocal",
9606 inet_ntop(AF_INET6,
9607 &p->nexthop.v6_local,
9608 buf1, sizeof(buf1)));
9609 if (p->shared_network)
9610 json_object_string_add(json_neigh,
9611 "bgpConnection",
9612 "sharedNetwork");
9613 else
9614 json_object_string_add(json_neigh,
9615 "bgpConnection",
9616 "nonSharedNetwork");
9617 } else {
9618 vty_out(vty, "Nexthop: %s\n",
9619 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
9620 sizeof(buf1)));
9621 vty_out(vty, "Nexthop global: %s\n",
9622 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
9623 sizeof(buf1)));
9624 vty_out(vty, "Nexthop local: %s\n",
9625 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
9626 sizeof(buf1)));
9627 vty_out(vty, "BGP connection: %s\n",
9628 p->shared_network ? "shared network"
9629 : "non shared network");
9630 }
9631 }
9632
9633 /* Timer information. */
9634 if (use_json) {
9635 json_object_int_add(json_neigh, "connectRetryTimer",
9636 p->v_connect);
9637 if (p->status == Established && p->rtt)
9638 json_object_int_add(json_neigh, "estimatedRttInMsecs",
9639 p->rtt);
9640 if (p->t_start)
9641 json_object_int_add(
9642 json_neigh, "nextStartTimerDueInMsecs",
9643 thread_timer_remain_second(p->t_start) * 1000);
9644 if (p->t_connect)
9645 json_object_int_add(
9646 json_neigh, "nextConnectTimerDueInMsecs",
9647 thread_timer_remain_second(p->t_connect)
9648 * 1000);
9649 if (p->t_routeadv) {
9650 json_object_int_add(json_neigh, "mraiInterval",
9651 p->v_routeadv);
9652 json_object_int_add(
9653 json_neigh, "mraiTimerExpireInMsecs",
9654 thread_timer_remain_second(p->t_routeadv)
9655 * 1000);
9656 }
9657 if (p->password)
9658 json_object_int_add(json_neigh, "authenticationEnabled",
9659 1);
9660
9661 if (p->t_read)
9662 json_object_string_add(json_neigh, "readThread", "on");
9663 else
9664 json_object_string_add(json_neigh, "readThread", "off");
9665 if (p->t_write)
9666 json_object_string_add(json_neigh, "writeThread", "on");
9667 else
9668 json_object_string_add(json_neigh, "writeThread",
9669 "off");
9670 } else {
9671 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
9672 p->v_connect);
9673 if (p->status == Established && p->rtt)
9674 vty_out(vty, "Estimated round trip time: %d ms\n",
9675 p->rtt);
9676 if (p->t_start)
9677 vty_out(vty, "Next start timer due in %ld seconds\n",
9678 thread_timer_remain_second(p->t_start));
9679 if (p->t_connect)
9680 vty_out(vty, "Next connect timer due in %ld seconds\n",
9681 thread_timer_remain_second(p->t_connect));
9682 if (p->t_routeadv)
9683 vty_out(vty,
9684 "MRAI (interval %u) timer expires in %ld seconds\n",
9685 p->v_routeadv,
9686 thread_timer_remain_second(p->t_routeadv));
9687 if (p->password)
9688 vty_out(vty, "Peer Authentication Enabled\n");
9689
9690 vty_out(vty, "Read thread: %s Write thread: %s\n",
9691 p->t_read ? "on" : "off", p->t_write ? "on" : "off");
9692 }
9693
9694 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9695 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
9696 bgp_capability_vty_out(vty, p, use_json, json_neigh);
9697
9698 if (!use_json)
9699 vty_out(vty, "\n");
9700
9701 /* BFD information. */
9702 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9703
9704 if (use_json) {
9705 if (p->conf_if) /* Configured interface name. */
9706 json_object_object_add(json, p->conf_if, json_neigh);
9707 else /* Configured IP address. */
9708 json_object_object_add(json, p->host, json_neigh);
9709 }
9710}
9711
9712static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
9713 enum show_type type, union sockunion *su,
9714 const char *conf_if, u_char use_json,
9715 json_object *json)
9716{
9717 struct listnode *node, *nnode;
9718 struct peer *peer;
9719 int find = 0;
9720
9721 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9722 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9723 continue;
9724
9725 switch (type) {
9726 case show_all:
9727 bgp_show_peer(vty, peer, use_json, json);
9728 break;
9729 case show_peer:
9730 if (conf_if) {
9731 if ((peer->conf_if
9732 && !strcmp(peer->conf_if, conf_if))
9733 || (peer->hostname
9734 && !strcmp(peer->hostname, conf_if))) {
9735 find = 1;
9736 bgp_show_peer(vty, peer, use_json,
9737 json);
9738 }
9739 } else {
9740 if (sockunion_same(&peer->su, su)) {
9741 find = 1;
9742 bgp_show_peer(vty, peer, use_json,
9743 json);
9744 }
9745 }
9746 break;
9747 }
9748 }
9749
9750 if (type == show_peer && !find) {
9751 if (use_json)
9752 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9753 else
9754 vty_out(vty, "%% No such neighbor\n");
9755 }
9756
9757 if (use_json) {
9d303b37
DL
9758 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9759 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9760 json_object_free(json);
9761 } else {
9762 vty_out(vty, "\n");
9763 }
9764
9765 return CMD_SUCCESS;
9766}
9767
9768static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
9769 u_char use_json)
9770{
9771 struct listnode *node, *nnode;
9772 struct bgp *bgp;
9773 json_object *json = NULL;
9774 int is_first = 1;
9775
9776 if (use_json)
9777 vty_out(vty, "{\n");
9778
9779 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9780 if (use_json) {
9781 if (!(json = json_object_new_object())) {
9782 zlog_err(
9783 "Unable to allocate memory for JSON object");
9784 vty_out(vty,
9785 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
9786 return;
9787 }
9788
9789 json_object_int_add(json, "vrfId",
9790 (bgp->vrf_id == VRF_UNKNOWN)
9791 ? -1
9792 : bgp->vrf_id);
9793 json_object_string_add(
9794 json, "vrfName",
9795 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9796 ? "Default"
9797 : bgp->name);
9798
9799 if (!is_first)
9800 vty_out(vty, ",\n");
9801 else
9802 is_first = 0;
9803
9804 vty_out(vty, "\"%s\":",
9805 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9806 ? "Default"
9807 : bgp->name);
9808 } else {
9809 vty_out(vty, "\nInstance %s:\n",
9810 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9811 ? "Default"
9812 : bgp->name);
9813 }
9814 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL, use_json,
9815 json);
9816 }
9817
9818 if (use_json)
9819 vty_out(vty, "}\n");
9820}
9821
9822static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
9823 enum show_type type, const char *ip_str,
9824 u_char use_json)
9825{
9826 int ret;
9827 struct bgp *bgp;
9828 union sockunion su;
9829 json_object *json = NULL;
9830
9831 if (name) {
9832 if (strmatch(name, "all")) {
9833 bgp_show_all_instances_neighbors_vty(vty, use_json);
9834 return CMD_SUCCESS;
9835 } else {
9836 bgp = bgp_lookup_by_name(name);
9837 if (!bgp) {
9838 if (use_json) {
9839 json = json_object_new_object();
9840 json_object_boolean_true_add(
9841 json, "bgpNoSuchInstance");
9842 vty_out(vty, "%s\n",
9843 json_object_to_json_string_ext(
9844 json,
9845 JSON_C_TO_STRING_PRETTY));
9846 json_object_free(json);
9847 } else
9848 vty_out(vty,
9849 "%% No such BGP instance exist\n");
9850
9851 return CMD_WARNING;
9852 }
9853 }
9854 } else {
9855 bgp = bgp_get_default();
9856 }
9857
9858 if (bgp) {
9859 json = json_object_new_object();
9860 if (ip_str) {
9861 ret = str2sockunion(ip_str, &su);
9862 if (ret < 0)
9863 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
9864 use_json, json);
9865 else
9866 bgp_show_neighbor(vty, bgp, type, &su, NULL,
9867 use_json, json);
9868 } else {
9869 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
9870 json);
9871 }
9872 json_object_free(json);
9873 }
9874
9875 return CMD_SUCCESS;
4fb25c53
DW
9876}
9877
716b2d8a 9878/* "show [ip] bgp neighbors" commands. */
718e3744 9879DEFUN (show_ip_bgp_neighbors,
9880 show_ip_bgp_neighbors_cmd,
18c57037 9881 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|vpnv4 <all|rd ASN:nn_or_IP-address:nn>>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 9882 SHOW_STR
9883 IP_STR
9884 BGP_STR
f2a8972b 9885 BGP_INSTANCE_HELP_STR
8c3deaae
QY
9886 "Address Family\n"
9887 "Address Family\n"
91d37724
QY
9888 "Address Family\n"
9889 "Display information about all VPNv4 NLRIs\n"
9890 "Display information for a route distinguisher\n"
9891 "VPN Route Distinguisher\n"
718e3744 9892 "Detailed information on TCP and BGP neighbor connections\n"
9893 "Neighbor to display information about\n"
a80beece 9894 "Neighbor to display information about\n"
91d37724 9895 "Neighbor on BGP configured interface\n"
9973d184 9896 JSON_STR)
718e3744 9897{
d62a17ae 9898 char *vrf = NULL;
9899 char *sh_arg = NULL;
9900 enum show_type sh_type;
718e3744 9901
d62a17ae 9902 u_char uj = use_json(argc, argv);
718e3744 9903
d62a17ae 9904 int idx = 0;
718e3744 9905
d62a17ae 9906 if (argv_find(argv, argc, "view", &idx)
9907 || argv_find(argv, argc, "vrf", &idx))
9908 vrf = argv[idx + 1]->arg;
718e3744 9909
d62a17ae 9910 idx++;
9911 if (argv_find(argv, argc, "A.B.C.D", &idx)
9912 || argv_find(argv, argc, "X:X::X:X", &idx)
9913 || argv_find(argv, argc, "WORD", &idx)) {
9914 sh_type = show_peer;
9915 sh_arg = argv[idx]->arg;
9916 } else
9917 sh_type = show_all;
856ca177 9918
d62a17ae 9919 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 9920}
9921
716b2d8a 9922/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 9923 paths' and `show ip mbgp paths'. Those functions results are the
9924 same.*/
f412b39a 9925DEFUN (show_ip_bgp_paths,
718e3744 9926 show_ip_bgp_paths_cmd,
46f296b4 9927 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 9928 SHOW_STR
9929 IP_STR
9930 BGP_STR
46f296b4 9931 BGP_SAFI_HELP_STR
718e3744 9932 "Path information\n")
9933{
d62a17ae 9934 vty_out(vty, "Address Refcnt Path\n");
9935 aspath_print_all_vty(vty);
9936 return CMD_SUCCESS;
718e3744 9937}
9938
718e3744 9939#include "hash.h"
9940
d62a17ae 9941static void community_show_all_iterator(struct hash_backet *backet,
9942 struct vty *vty)
718e3744 9943{
d62a17ae 9944 struct community *com;
718e3744 9945
d62a17ae 9946 com = (struct community *)backet->data;
9947 vty_out(vty, "[%p] (%ld) %s\n", (void *)backet, com->refcnt,
9948 community_str(com));
718e3744 9949}
9950
9951/* Show BGP's community internal data. */
f412b39a 9952DEFUN (show_ip_bgp_community_info,
718e3744 9953 show_ip_bgp_community_info_cmd,
bec37ba5 9954 "show [ip] bgp community-info",
718e3744 9955 SHOW_STR
9956 IP_STR
9957 BGP_STR
9958 "List all bgp community information\n")
9959{
d62a17ae 9960 vty_out(vty, "Address Refcnt Community\n");
718e3744 9961
d62a17ae 9962 hash_iterate(community_hash(),
9963 (void (*)(struct hash_backet *,
9964 void *))community_show_all_iterator,
9965 vty);
718e3744 9966
d62a17ae 9967 return CMD_SUCCESS;
718e3744 9968}
9969
d62a17ae 9970static void lcommunity_show_all_iterator(struct hash_backet *backet,
9971 struct vty *vty)
57d187bc 9972{
d62a17ae 9973 struct lcommunity *lcom;
57d187bc 9974
d62a17ae 9975 lcom = (struct lcommunity *)backet->data;
9976 vty_out(vty, "[%p] (%ld) %s\n", (void *)backet, lcom->refcnt,
9977 lcommunity_str(lcom));
57d187bc
JS
9978}
9979
9980/* Show BGP's community internal data. */
9981DEFUN (show_ip_bgp_lcommunity_info,
9982 show_ip_bgp_lcommunity_info_cmd,
9983 "show ip bgp large-community-info",
9984 SHOW_STR
9985 IP_STR
9986 BGP_STR
9987 "List all bgp large-community information\n")
9988{
d62a17ae 9989 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 9990
d62a17ae 9991 hash_iterate(lcommunity_hash(),
9992 (void (*)(struct hash_backet *,
9993 void *))lcommunity_show_all_iterator,
9994 vty);
57d187bc 9995
d62a17ae 9996 return CMD_SUCCESS;
57d187bc
JS
9997}
9998
9999
f412b39a 10000DEFUN (show_ip_bgp_attr_info,
718e3744 10001 show_ip_bgp_attr_info_cmd,
bec37ba5 10002 "show [ip] bgp attribute-info",
718e3744 10003 SHOW_STR
10004 IP_STR
10005 BGP_STR
10006 "List all bgp attribute information\n")
10007{
d62a17ae 10008 attr_show_all(vty);
10009 return CMD_SUCCESS;
718e3744 10010}
6b0655a2 10011
d62a17ae 10012static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10013 safi_t safi)
f186de26 10014{
d62a17ae 10015 struct listnode *node, *nnode;
10016 struct bgp *bgp;
f186de26 10017
d62a17ae 10018 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10019 vty_out(vty, "\nInstance %s:\n",
10020 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10021 ? "Default"
10022 : bgp->name);
10023 update_group_show(bgp, afi, safi, vty, 0);
10024 }
f186de26 10025}
10026
d62a17ae 10027static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10028 int safi, uint64_t subgrp_id)
4fb25c53 10029{
d62a17ae 10030 struct bgp *bgp;
4fb25c53 10031
d62a17ae 10032 if (name) {
10033 if (strmatch(name, "all")) {
10034 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10035 return CMD_SUCCESS;
10036 } else {
10037 bgp = bgp_lookup_by_name(name);
10038 }
10039 } else {
10040 bgp = bgp_get_default();
10041 }
4fb25c53 10042
d62a17ae 10043 if (bgp)
10044 update_group_show(bgp, afi, safi, vty, subgrp_id);
10045 return CMD_SUCCESS;
4fb25c53
DW
10046}
10047
8fe8a7f6
DS
10048DEFUN (show_ip_bgp_updgrps,
10049 show_ip_bgp_updgrps_cmd,
c1a44e43 10050 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 10051 SHOW_STR
10052 IP_STR
10053 BGP_STR
10054 BGP_INSTANCE_HELP_STR
c9e571b4 10055 BGP_AFI_HELP_STR
9bedbb1e 10056 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
10057 "Detailed info about dynamic update groups\n"
10058 "Specific subgroup to display detailed info for\n")
8386ac43 10059{
d62a17ae 10060 char *vrf = NULL;
10061 afi_t afi = AFI_IP6;
10062 safi_t safi = SAFI_UNICAST;
10063 uint64_t subgrp_id = 0;
10064
10065 int idx = 0;
10066
10067 /* show [ip] bgp */
10068 if (argv_find(argv, argc, "ip", &idx))
10069 afi = AFI_IP;
10070 /* [<view|vrf> VIEWVRFNAME] */
10071 if (argv_find(argv, argc, "view", &idx)
10072 || argv_find(argv, argc, "vrf", &idx))
10073 vrf = argv[++idx]->arg;
10074 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10075 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10076 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10077 }
5bf15956 10078
d62a17ae 10079 /* get subgroup id, if provided */
10080 idx = argc - 1;
10081 if (argv[idx]->type == VARIABLE_TKN)
10082 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 10083
d62a17ae 10084 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
10085}
10086
f186de26 10087DEFUN (show_bgp_instance_all_ipv6_updgrps,
10088 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 10089 "show [ip] bgp <view|vrf> all update-groups",
f186de26 10090 SHOW_STR
716b2d8a 10091 IP_STR
f186de26 10092 BGP_STR
10093 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 10094 "Detailed info about dynamic update groups\n")
f186de26 10095{
d62a17ae 10096 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10097 return CMD_SUCCESS;
f186de26 10098}
10099
5bf15956
DW
10100DEFUN (show_bgp_updgrps_stats,
10101 show_bgp_updgrps_stats_cmd,
716b2d8a 10102 "show [ip] bgp update-groups statistics",
3f9c7369 10103 SHOW_STR
716b2d8a 10104 IP_STR
3f9c7369 10105 BGP_STR
0c7b1b01 10106 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10107 "Statistics\n")
10108{
d62a17ae 10109 struct bgp *bgp;
3f9c7369 10110
d62a17ae 10111 bgp = bgp_get_default();
10112 if (bgp)
10113 update_group_show_stats(bgp, vty);
3f9c7369 10114
d62a17ae 10115 return CMD_SUCCESS;
3f9c7369
DS
10116}
10117
8386ac43 10118DEFUN (show_bgp_instance_updgrps_stats,
10119 show_bgp_instance_updgrps_stats_cmd,
18c57037 10120 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 10121 SHOW_STR
716b2d8a 10122 IP_STR
8386ac43 10123 BGP_STR
10124 BGP_INSTANCE_HELP_STR
0c7b1b01 10125 "Detailed info about dynamic update groups\n"
8386ac43 10126 "Statistics\n")
10127{
d62a17ae 10128 int idx_word = 3;
10129 struct bgp *bgp;
8386ac43 10130
d62a17ae 10131 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10132 if (bgp)
10133 update_group_show_stats(bgp, vty);
8386ac43 10134
d62a17ae 10135 return CMD_SUCCESS;
8386ac43 10136}
10137
d62a17ae 10138static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10139 afi_t afi, safi_t safi,
10140 const char *what, uint64_t subgrp_id)
3f9c7369 10141{
d62a17ae 10142 struct bgp *bgp;
8386ac43 10143
d62a17ae 10144 if (name)
10145 bgp = bgp_lookup_by_name(name);
10146 else
10147 bgp = bgp_get_default();
8386ac43 10148
d62a17ae 10149 if (bgp) {
10150 if (!strcmp(what, "advertise-queue"))
10151 update_group_show_adj_queue(bgp, afi, safi, vty,
10152 subgrp_id);
10153 else if (!strcmp(what, "advertised-routes"))
10154 update_group_show_advertised(bgp, afi, safi, vty,
10155 subgrp_id);
10156 else if (!strcmp(what, "packet-queue"))
10157 update_group_show_packet_queue(bgp, afi, safi, vty,
10158 subgrp_id);
10159 }
3f9c7369
DS
10160}
10161
10162DEFUN (show_ip_bgp_updgrps_adj,
10163 show_ip_bgp_updgrps_adj_cmd,
716b2d8a 10164 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10165 SHOW_STR
10166 IP_STR
10167 BGP_STR
0c7b1b01 10168 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10169 "Advertisement queue\n"
10170 "Announced routes\n"
10171 "Packet queue\n")
10172{
d62a17ae 10173 int idx_type = 4;
10174 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10175 argv[idx_type]->arg, 0);
10176 return CMD_SUCCESS;
8386ac43 10177}
10178
10179DEFUN (show_ip_bgp_instance_updgrps_adj,
10180 show_ip_bgp_instance_updgrps_adj_cmd,
18c57037 10181 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10182 SHOW_STR
10183 IP_STR
10184 BGP_STR
10185 BGP_INSTANCE_HELP_STR
0c7b1b01 10186 "Detailed info about dynamic update groups\n"
8386ac43 10187 "Advertisement queue\n"
10188 "Announced routes\n"
10189 "Packet queue\n")
8386ac43 10190{
d62a17ae 10191 int idx_word = 4;
10192 int idx_type = 6;
10193 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP,
10194 SAFI_UNICAST, argv[idx_type]->arg, 0);
10195 return CMD_SUCCESS;
3f9c7369
DS
10196}
10197
10198DEFUN (show_bgp_updgrps_afi_adj,
10199 show_bgp_updgrps_afi_adj_cmd,
46f296b4 10200 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10201 SHOW_STR
716b2d8a 10202 IP_STR
3f9c7369 10203 BGP_STR
46f296b4 10204 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10205 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10206 "Advertisement queue\n"
10207 "Announced routes\n"
7111c1a0 10208 "Packet queue\n")
3f9c7369 10209{
d62a17ae 10210 int idx_afi = 2;
10211 int idx_safi = 3;
10212 int idx_type = 5;
10213 show_bgp_updgrps_adj_info_aux(
10214 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10215 bgp_vty_safi_from_str(argv[idx_safi]->text),
10216 argv[idx_type]->arg, 0);
10217 return CMD_SUCCESS;
3f9c7369
DS
10218}
10219
10220DEFUN (show_bgp_updgrps_adj,
10221 show_bgp_updgrps_adj_cmd,
716b2d8a 10222 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10223 SHOW_STR
716b2d8a 10224 IP_STR
3f9c7369 10225 BGP_STR
0c7b1b01 10226 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10227 "Advertisement queue\n"
10228 "Announced routes\n"
10229 "Packet queue\n")
10230{
d62a17ae 10231 int idx_type = 3;
10232 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10233 argv[idx_type]->arg, 0);
10234 return CMD_SUCCESS;
8386ac43 10235}
10236
10237DEFUN (show_bgp_instance_updgrps_adj,
10238 show_bgp_instance_updgrps_adj_cmd,
18c57037 10239 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10240 SHOW_STR
716b2d8a 10241 IP_STR
8386ac43 10242 BGP_STR
10243 BGP_INSTANCE_HELP_STR
0c7b1b01 10244 "Detailed info about dynamic update groups\n"
8386ac43 10245 "Advertisement queue\n"
10246 "Announced routes\n"
10247 "Packet queue\n")
10248{
d62a17ae 10249 int idx_word = 3;
10250 int idx_type = 5;
10251 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6,
10252 SAFI_UNICAST, argv[idx_type]->arg, 0);
10253 return CMD_SUCCESS;
3f9c7369
DS
10254}
10255
10256DEFUN (show_ip_bgp_updgrps_adj_s,
8fe8a7f6 10257 show_ip_bgp_updgrps_adj_s_cmd,
716b2d8a 10258 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10259 SHOW_STR
10260 IP_STR
10261 BGP_STR
0c7b1b01 10262 "Detailed info about dynamic update groups\n"
8fe8a7f6 10263 "Specific subgroup to display info for\n"
3f9c7369
DS
10264 "Advertisement queue\n"
10265 "Announced routes\n"
10266 "Packet queue\n")
3f9c7369 10267{
d62a17ae 10268 int idx_subgroup_id = 4;
10269 int idx_type = 5;
10270 uint64_t subgrp_id;
8fe8a7f6 10271
d62a17ae 10272 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10273
d62a17ae 10274 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10275 argv[idx_type]->arg, subgrp_id);
10276 return CMD_SUCCESS;
8386ac43 10277}
10278
10279DEFUN (show_ip_bgp_instance_updgrps_adj_s,
10280 show_ip_bgp_instance_updgrps_adj_s_cmd,
18c57037 10281 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10282 SHOW_STR
10283 IP_STR
10284 BGP_STR
10285 BGP_INSTANCE_HELP_STR
0c7b1b01 10286 "Detailed info about dynamic update groups\n"
8386ac43 10287 "Specific subgroup to display info for\n"
10288 "Advertisement queue\n"
10289 "Announced routes\n"
10290 "Packet queue\n")
8386ac43 10291{
d62a17ae 10292 int idx_vrf = 4;
10293 int idx_subgroup_id = 6;
10294 int idx_type = 7;
10295 uint64_t subgrp_id;
8386ac43 10296
d62a17ae 10297 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8386ac43 10298
d62a17ae 10299 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP,
10300 SAFI_UNICAST, argv[idx_type]->arg,
10301 subgrp_id);
10302 return CMD_SUCCESS;
3f9c7369
DS
10303}
10304
8fe8a7f6
DS
10305DEFUN (show_bgp_updgrps_afi_adj_s,
10306 show_bgp_updgrps_afi_adj_s_cmd,
46f296b4 10307 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10308 SHOW_STR
716b2d8a 10309 IP_STR
3f9c7369 10310 BGP_STR
46f296b4 10311 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10312 "Detailed info about dynamic update groups\n"
8fe8a7f6 10313 "Specific subgroup to display info for\n"
3f9c7369
DS
10314 "Advertisement queue\n"
10315 "Announced routes\n"
7111c1a0 10316 "Packet queue\n")
3f9c7369 10317{
d62a17ae 10318 int idx_afi = 2;
10319 int idx_safi = 3;
10320 int idx_subgroup_id = 5;
10321 int idx_type = 6;
10322 uint64_t subgrp_id;
3f9c7369 10323
d62a17ae 10324 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10325
d62a17ae 10326 show_bgp_updgrps_adj_info_aux(
10327 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10328 bgp_vty_safi_from_str(argv[idx_safi]->text),
10329 argv[idx_type]->arg, subgrp_id);
10330 return CMD_SUCCESS;
3f9c7369
DS
10331}
10332
8fe8a7f6
DS
10333DEFUN (show_bgp_updgrps_adj_s,
10334 show_bgp_updgrps_adj_s_cmd,
716b2d8a 10335 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8fe8a7f6 10336 SHOW_STR
716b2d8a 10337 IP_STR
8fe8a7f6 10338 BGP_STR
0c7b1b01 10339 "Detailed info about dynamic update groups\n"
8fe8a7f6
DS
10340 "Specific subgroup to display info for\n"
10341 "Advertisement queue\n"
10342 "Announced routes\n"
10343 "Packet queue\n")
10344{
d62a17ae 10345 int idx_subgroup_id = 3;
10346 int idx_type = 4;
10347 uint64_t subgrp_id;
8fe8a7f6 10348
d62a17ae 10349 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10350
d62a17ae 10351 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10352 argv[idx_type]->arg, subgrp_id);
10353 return CMD_SUCCESS;
8fe8a7f6
DS
10354}
10355
8386ac43 10356DEFUN (show_bgp_instance_updgrps_adj_s,
10357 show_bgp_instance_updgrps_adj_s_cmd,
18c57037 10358 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10359 SHOW_STR
716b2d8a 10360 IP_STR
8386ac43 10361 BGP_STR
10362 BGP_INSTANCE_HELP_STR
0c7b1b01 10363 "Detailed info about dynamic update groups\n"
8386ac43 10364 "Specific subgroup to display info for\n"
10365 "Advertisement queue\n"
10366 "Announced routes\n"
10367 "Packet queue\n")
10368{
d62a17ae 10369 int idx_vrf = 3;
10370 int idx_subgroup_id = 5;
10371 int idx_type = 6;
10372 uint64_t subgrp_id;
10373
10374 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10375
10376 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6,
10377 SAFI_UNICAST, argv[idx_type]->arg,
10378 subgrp_id);
10379 return CMD_SUCCESS;
10380}
10381
10382
10383static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10384{
10385 struct listnode *node, *nnode;
10386 struct prefix *range;
10387 struct peer *conf;
10388 struct peer *peer;
10389 char buf[PREFIX2STR_BUFFER];
10390 afi_t afi;
10391 safi_t safi;
10392 const char *peer_status;
10393 const char *af_str;
10394 int lr_count;
10395 int dynamic;
10396 int af_cfgd;
10397
10398 conf = group->conf;
10399
10400 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10401 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10402 conf->as);
10403 } else if (conf->as_type == AS_INTERNAL) {
10404 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10405 group->bgp->as);
10406 } else {
10407 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10408 }
f14e6fdb 10409
d62a17ae 10410 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10411 vty_out(vty, " Peer-group type is internal\n");
10412 else
10413 vty_out(vty, " Peer-group type is external\n");
10414
10415 /* Display AFs configured. */
10416 vty_out(vty, " Configured address-families:");
10417 for (afi = AFI_IP; afi < AFI_MAX; afi++)
10418 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
10419 if (conf->afc[afi][safi]) {
10420 af_cfgd = 1;
10421 vty_out(vty, " %s;", afi_safi_print(afi, safi));
10422 }
10423 }
10424 if (!af_cfgd)
10425 vty_out(vty, " none\n");
10426 else
10427 vty_out(vty, "\n");
10428
10429 /* Display listen ranges (for dynamic neighbors), if any */
10430 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10431 if (afi == AFI_IP)
10432 af_str = "IPv4";
10433 else if (afi == AFI_IP6)
10434 af_str = "IPv6";
10435 else
10436 af_str = "???";
10437 lr_count = listcount(group->listen_range[afi]);
10438 if (lr_count) {
10439 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10440 af_str);
10441
10442
10443 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10444 nnode, range)) {
10445 prefix2str(range, buf, sizeof(buf));
10446 vty_out(vty, " %s\n", buf);
10447 }
10448 }
10449 }
f14e6fdb 10450
d62a17ae 10451 /* Display group members and their status */
10452 if (listcount(group->peer)) {
10453 vty_out(vty, " Peer-group members:\n");
10454 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10455 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10456 peer_status = "Idle (Admin)";
10457 else if (CHECK_FLAG(peer->sflags,
10458 PEER_STATUS_PREFIX_OVERFLOW))
10459 peer_status = "Idle (PfxCt)";
10460 else
10461 peer_status = lookup_msg(bgp_status_msg,
10462 peer->status, NULL);
10463
10464 dynamic = peer_dynamic_neighbor(peer);
10465 vty_out(vty, " %s %s %s \n", peer->host,
10466 dynamic ? "(dynamic)" : "", peer_status);
10467 }
10468 }
f14e6fdb 10469
d62a17ae 10470 return CMD_SUCCESS;
10471}
10472
10473/* Show BGP peer group's information. */
10474enum show_group_type { show_all_groups, show_peer_group };
10475
10476static int bgp_show_peer_group(struct vty *vty, struct bgp *bgp,
10477 enum show_group_type type,
10478 const char *group_name)
10479{
10480 struct listnode *node, *nnode;
10481 struct peer_group *group;
10482 int find = 0;
10483
10484 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
10485 switch (type) {
10486 case show_all_groups:
10487 bgp_show_one_peer_group(vty, group);
10488 break;
10489 case show_peer_group:
10490 if (group_name
10491 && (strcmp(group->name, group_name) == 0)) {
10492 find = 1;
10493 bgp_show_one_peer_group(vty, group);
10494 }
10495 break;
10496 }
f14e6fdb 10497 }
f14e6fdb 10498
d62a17ae 10499 if (type == show_peer_group && !find)
10500 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 10501
d62a17ae 10502 return CMD_SUCCESS;
f14e6fdb
DS
10503}
10504
d62a17ae 10505static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10506 enum show_group_type type,
10507 const char *group_name)
f14e6fdb 10508{
d62a17ae 10509 struct bgp *bgp;
10510 int ret = CMD_SUCCESS;
f14e6fdb 10511
d62a17ae 10512 if (name)
10513 bgp = bgp_lookup_by_name(name);
10514 else
10515 bgp = bgp_get_default();
f14e6fdb 10516
d62a17ae 10517 if (!bgp) {
10518 vty_out(vty, "%% No such BGP instance exist\n");
10519 return CMD_WARNING;
10520 }
f14e6fdb 10521
d62a17ae 10522 ret = bgp_show_peer_group(vty, bgp, type, group_name);
f14e6fdb 10523
d62a17ae 10524 return ret;
f14e6fdb
DS
10525}
10526
10527DEFUN (show_ip_bgp_peer_groups,
10528 show_ip_bgp_peer_groups_cmd,
18c57037 10529 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10530 SHOW_STR
10531 IP_STR
10532 BGP_STR
8386ac43 10533 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10534 "Detailed information on BGP peer groups\n"
10535 "Peer group name\n")
f14e6fdb 10536{
d62a17ae 10537 char *vrf, *pg;
10538 vrf = pg = NULL;
10539 int idx = 0;
f14e6fdb 10540
d62a17ae 10541 vrf = argv_find(argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
10542 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10543
d62a17ae 10544 return bgp_show_peer_group_vty(vty, vrf, show_all_groups, pg);
f14e6fdb 10545}
3f9c7369 10546
d6e3c605 10547
718e3744 10548/* Redistribute VTY commands. */
10549
718e3744 10550DEFUN (bgp_redistribute_ipv4,
10551 bgp_redistribute_ipv4_cmd,
40d1cbfb 10552 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 10553 "Redistribute information from another routing protocol\n"
ab0181ee 10554 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 10555{
d62a17ae 10556 VTY_DECLVAR_CONTEXT(bgp, bgp);
10557 int idx_protocol = 1;
10558 int type;
718e3744 10559
d62a17ae 10560 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10561 if (type < 0) {
10562 vty_out(vty, "%% Invalid route type\n");
10563 return CMD_WARNING_CONFIG_FAILED;
10564 }
10565 bgp_redist_add(bgp, AFI_IP, type, 0);
10566 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10567}
10568
d62a17ae 10569ALIAS_HIDDEN(
10570 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10571 "redistribute " FRR_IP_REDIST_STR_BGPD,
10572 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 10573
718e3744 10574DEFUN (bgp_redistribute_ipv4_rmap,
10575 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 10576 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 10577 "Redistribute information from another routing protocol\n"
ab0181ee 10578 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10579 "Route map reference\n"
10580 "Pointer to route-map entries\n")
10581{
d62a17ae 10582 VTY_DECLVAR_CONTEXT(bgp, bgp);
10583 int idx_protocol = 1;
10584 int idx_word = 3;
10585 int type;
10586 struct bgp_redist *red;
718e3744 10587
d62a17ae 10588 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10589 if (type < 0) {
10590 vty_out(vty, "%% Invalid route type\n");
10591 return CMD_WARNING_CONFIG_FAILED;
10592 }
718e3744 10593
d62a17ae 10594 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10595 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10596 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10597}
10598
d62a17ae 10599ALIAS_HIDDEN(
10600 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
10601 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10602 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10603 "Route map reference\n"
10604 "Pointer to route-map entries\n")
596c17ba 10605
718e3744 10606DEFUN (bgp_redistribute_ipv4_metric,
10607 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 10608 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 10609 "Redistribute information from another routing protocol\n"
ab0181ee 10610 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10611 "Metric for redistributed routes\n"
10612 "Default metric\n")
10613{
d62a17ae 10614 VTY_DECLVAR_CONTEXT(bgp, bgp);
10615 int idx_protocol = 1;
10616 int idx_number = 3;
10617 int type;
10618 u_int32_t metric;
10619 struct bgp_redist *red;
10620
10621 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10622 if (type < 0) {
10623 vty_out(vty, "%% Invalid route type\n");
10624 return CMD_WARNING_CONFIG_FAILED;
10625 }
10626 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10627
10628 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10629 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10630 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10631}
10632
10633ALIAS_HIDDEN(
10634 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
10635 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10636 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10637 "Metric for redistributed routes\n"
10638 "Default metric\n")
596c17ba 10639
718e3744 10640DEFUN (bgp_redistribute_ipv4_rmap_metric,
10641 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 10642 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 10643 "Redistribute information from another routing protocol\n"
ab0181ee 10644 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10645 "Route map reference\n"
10646 "Pointer to route-map entries\n"
10647 "Metric for redistributed routes\n"
10648 "Default metric\n")
10649{
d62a17ae 10650 VTY_DECLVAR_CONTEXT(bgp, bgp);
10651 int idx_protocol = 1;
10652 int idx_word = 3;
10653 int idx_number = 5;
10654 int type;
10655 u_int32_t metric;
10656 struct bgp_redist *red;
10657
10658 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10659 if (type < 0) {
10660 vty_out(vty, "%% Invalid route type\n");
10661 return CMD_WARNING_CONFIG_FAILED;
10662 }
10663 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10664
10665 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10666 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10667 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10668 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10669}
10670
10671ALIAS_HIDDEN(
10672 bgp_redistribute_ipv4_rmap_metric,
10673 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10674 "redistribute " FRR_IP_REDIST_STR_BGPD
10675 " route-map WORD metric (0-4294967295)",
10676 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10677 "Route map reference\n"
10678 "Pointer to route-map entries\n"
10679 "Metric for redistributed routes\n"
10680 "Default metric\n")
596c17ba 10681
718e3744 10682DEFUN (bgp_redistribute_ipv4_metric_rmap,
10683 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 10684 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 10685 "Redistribute information from another routing protocol\n"
ab0181ee 10686 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10687 "Metric for redistributed routes\n"
10688 "Default metric\n"
10689 "Route map reference\n"
10690 "Pointer to route-map entries\n")
10691{
d62a17ae 10692 VTY_DECLVAR_CONTEXT(bgp, bgp);
10693 int idx_protocol = 1;
10694 int idx_number = 3;
10695 int idx_word = 5;
10696 int type;
10697 u_int32_t metric;
10698 struct bgp_redist *red;
10699
10700 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10701 if (type < 0) {
10702 vty_out(vty, "%% Invalid route type\n");
10703 return CMD_WARNING_CONFIG_FAILED;
10704 }
10705 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10706
10707 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10708 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10709 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10710 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10711}
10712
10713ALIAS_HIDDEN(
10714 bgp_redistribute_ipv4_metric_rmap,
10715 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10716 "redistribute " FRR_IP_REDIST_STR_BGPD
10717 " metric (0-4294967295) route-map WORD",
10718 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10719 "Metric for redistributed routes\n"
10720 "Default metric\n"
10721 "Route map reference\n"
10722 "Pointer to route-map entries\n")
596c17ba 10723
7c8ff89e
DS
10724DEFUN (bgp_redistribute_ipv4_ospf,
10725 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 10726 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
10727 "Redistribute information from another routing protocol\n"
10728 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10729 "Non-main Kernel Routing Table\n"
10730 "Instance ID/Table ID\n")
7c8ff89e 10731{
d62a17ae 10732 VTY_DECLVAR_CONTEXT(bgp, bgp);
10733 int idx_ospf_table = 1;
10734 int idx_number = 2;
10735 u_short instance;
10736 u_short protocol;
7c8ff89e 10737
d62a17ae 10738 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 10739
d62a17ae 10740 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10741 protocol = ZEBRA_ROUTE_OSPF;
10742 else
10743 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 10744
d62a17ae 10745 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10746 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10747}
10748
d62a17ae 10749ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
10750 "redistribute <ospf|table> (1-65535)",
10751 "Redistribute information from another routing protocol\n"
10752 "Open Shortest Path First (OSPFv2)\n"
10753 "Non-main Kernel Routing Table\n"
10754 "Instance ID/Table ID\n")
596c17ba 10755
7c8ff89e
DS
10756DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10757 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 10758 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
10759 "Redistribute information from another routing protocol\n"
10760 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10761 "Non-main Kernel Routing Table\n"
10762 "Instance ID/Table ID\n"
7c8ff89e
DS
10763 "Route map reference\n"
10764 "Pointer to route-map entries\n")
10765{
d62a17ae 10766 VTY_DECLVAR_CONTEXT(bgp, bgp);
10767 int idx_ospf_table = 1;
10768 int idx_number = 2;
10769 int idx_word = 4;
10770 struct bgp_redist *red;
10771 u_short instance;
10772 int protocol;
10773
10774 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10775 protocol = ZEBRA_ROUTE_OSPF;
10776 else
10777 protocol = ZEBRA_ROUTE_TABLE;
10778
10779 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10780 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10781 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10782 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10783}
10784
10785ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
10786 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10787 "redistribute <ospf|table> (1-65535) route-map WORD",
10788 "Redistribute information from another routing protocol\n"
10789 "Open Shortest Path First (OSPFv2)\n"
10790 "Non-main Kernel Routing Table\n"
10791 "Instance ID/Table ID\n"
10792 "Route map reference\n"
10793 "Pointer to route-map entries\n")
596c17ba 10794
7c8ff89e
DS
10795DEFUN (bgp_redistribute_ipv4_ospf_metric,
10796 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 10797 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
10798 "Redistribute information from another routing protocol\n"
10799 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10800 "Non-main Kernel Routing Table\n"
10801 "Instance ID/Table ID\n"
7c8ff89e
DS
10802 "Metric for redistributed routes\n"
10803 "Default metric\n")
10804{
d62a17ae 10805 VTY_DECLVAR_CONTEXT(bgp, bgp);
10806 int idx_ospf_table = 1;
10807 int idx_number = 2;
10808 int idx_number_2 = 4;
10809 u_int32_t metric;
10810 struct bgp_redist *red;
10811 u_short instance;
10812 int protocol;
10813
10814 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10815 protocol = ZEBRA_ROUTE_OSPF;
10816 else
10817 protocol = ZEBRA_ROUTE_TABLE;
10818
10819 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10820 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10821
10822 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10823 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10824 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10825}
10826
10827ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
10828 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10829 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10830 "Redistribute information from another routing protocol\n"
10831 "Open Shortest Path First (OSPFv2)\n"
10832 "Non-main Kernel Routing Table\n"
10833 "Instance ID/Table ID\n"
10834 "Metric for redistributed routes\n"
10835 "Default metric\n")
596c17ba 10836
7c8ff89e
DS
10837DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10838 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 10839 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
10840 "Redistribute information from another routing protocol\n"
10841 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10842 "Non-main Kernel Routing Table\n"
10843 "Instance ID/Table ID\n"
7c8ff89e
DS
10844 "Route map reference\n"
10845 "Pointer to route-map entries\n"
10846 "Metric for redistributed routes\n"
10847 "Default metric\n")
10848{
d62a17ae 10849 VTY_DECLVAR_CONTEXT(bgp, bgp);
10850 int idx_ospf_table = 1;
10851 int idx_number = 2;
10852 int idx_word = 4;
10853 int idx_number_2 = 6;
10854 u_int32_t metric;
10855 struct bgp_redist *red;
10856 u_short instance;
10857 int protocol;
10858
10859 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10860 protocol = ZEBRA_ROUTE_OSPF;
10861 else
10862 protocol = ZEBRA_ROUTE_TABLE;
10863
10864 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10865 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10866
10867 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10868 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10869 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10870 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10871}
10872
10873ALIAS_HIDDEN(
10874 bgp_redistribute_ipv4_ospf_rmap_metric,
10875 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10876 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10877 "Redistribute information from another routing protocol\n"
10878 "Open Shortest Path First (OSPFv2)\n"
10879 "Non-main Kernel Routing Table\n"
10880 "Instance ID/Table ID\n"
10881 "Route map reference\n"
10882 "Pointer to route-map entries\n"
10883 "Metric for redistributed routes\n"
10884 "Default metric\n")
596c17ba 10885
7c8ff89e
DS
10886DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
10887 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 10888 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
10889 "Redistribute information from another routing protocol\n"
10890 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10891 "Non-main Kernel Routing Table\n"
10892 "Instance ID/Table ID\n"
7c8ff89e
DS
10893 "Metric for redistributed routes\n"
10894 "Default metric\n"
10895 "Route map reference\n"
10896 "Pointer to route-map entries\n")
10897{
d62a17ae 10898 VTY_DECLVAR_CONTEXT(bgp, bgp);
10899 int idx_ospf_table = 1;
10900 int idx_number = 2;
10901 int idx_number_2 = 4;
10902 int idx_word = 6;
10903 u_int32_t metric;
10904 struct bgp_redist *red;
10905 u_short instance;
10906 int protocol;
10907
10908 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10909 protocol = ZEBRA_ROUTE_OSPF;
10910 else
10911 protocol = ZEBRA_ROUTE_TABLE;
10912
10913 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10914 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10915
10916 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10917 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10918 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10919 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10920}
10921
10922ALIAS_HIDDEN(
10923 bgp_redistribute_ipv4_ospf_metric_rmap,
10924 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
10925 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10926 "Redistribute information from another routing protocol\n"
10927 "Open Shortest Path First (OSPFv2)\n"
10928 "Non-main Kernel Routing Table\n"
10929 "Instance ID/Table ID\n"
10930 "Metric for redistributed routes\n"
10931 "Default metric\n"
10932 "Route map reference\n"
10933 "Pointer to route-map entries\n")
596c17ba 10934
7c8ff89e
DS
10935DEFUN (no_bgp_redistribute_ipv4_ospf,
10936 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 10937 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
10938 NO_STR
10939 "Redistribute information from another routing protocol\n"
10940 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 10941 "Non-main Kernel Routing Table\n"
31500417
DW
10942 "Instance ID/Table ID\n"
10943 "Metric for redistributed routes\n"
10944 "Default metric\n"
10945 "Route map reference\n"
10946 "Pointer to route-map entries\n")
7c8ff89e 10947{
d62a17ae 10948 VTY_DECLVAR_CONTEXT(bgp, bgp);
10949 int idx_ospf_table = 2;
10950 int idx_number = 3;
10951 u_short instance;
10952 int protocol;
10953
10954 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10955 protocol = ZEBRA_ROUTE_OSPF;
10956 else
10957 protocol = ZEBRA_ROUTE_TABLE;
10958
10959 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10960 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
10961}
10962
10963ALIAS_HIDDEN(
10964 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
10965 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
10966 NO_STR
10967 "Redistribute information from another routing protocol\n"
10968 "Open Shortest Path First (OSPFv2)\n"
10969 "Non-main Kernel Routing Table\n"
10970 "Instance ID/Table ID\n"
10971 "Metric for redistributed routes\n"
10972 "Default metric\n"
10973 "Route map reference\n"
10974 "Pointer to route-map entries\n")
596c17ba 10975
718e3744 10976DEFUN (no_bgp_redistribute_ipv4,
10977 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 10978 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 10979 NO_STR
10980 "Redistribute information from another routing protocol\n"
3b14d86e 10981 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
10982 "Metric for redistributed routes\n"
10983 "Default metric\n"
10984 "Route map reference\n"
10985 "Pointer to route-map entries\n")
718e3744 10986{
d62a17ae 10987 VTY_DECLVAR_CONTEXT(bgp, bgp);
10988 int idx_protocol = 2;
10989 int type;
10990
10991 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10992 if (type < 0) {
10993 vty_out(vty, "%% Invalid route type\n");
10994 return CMD_WARNING_CONFIG_FAILED;
10995 }
10996 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
10997}
10998
10999ALIAS_HIDDEN(
11000 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11001 "no redistribute " FRR_IP_REDIST_STR_BGPD
11002 " [metric (0-4294967295)] [route-map WORD]",
11003 NO_STR
11004 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11005 "Metric for redistributed routes\n"
11006 "Default metric\n"
11007 "Route map reference\n"
11008 "Pointer to route-map entries\n")
596c17ba 11009
718e3744 11010DEFUN (bgp_redistribute_ipv6,
11011 bgp_redistribute_ipv6_cmd,
40d1cbfb 11012 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11013 "Redistribute information from another routing protocol\n"
ab0181ee 11014 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11015{
d62a17ae 11016 VTY_DECLVAR_CONTEXT(bgp, bgp);
11017 int idx_protocol = 1;
11018 int type;
718e3744 11019
d62a17ae 11020 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11021 if (type < 0) {
11022 vty_out(vty, "%% Invalid route type\n");
11023 return CMD_WARNING_CONFIG_FAILED;
11024 }
718e3744 11025
d62a17ae 11026 bgp_redist_add(bgp, AFI_IP6, type, 0);
11027 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11028}
11029
11030DEFUN (bgp_redistribute_ipv6_rmap,
11031 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11032 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11033 "Redistribute information from another routing protocol\n"
ab0181ee 11034 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11035 "Route map reference\n"
11036 "Pointer to route-map entries\n")
11037{
d62a17ae 11038 VTY_DECLVAR_CONTEXT(bgp, bgp);
11039 int idx_protocol = 1;
11040 int idx_word = 3;
11041 int type;
11042 struct bgp_redist *red;
718e3744 11043
d62a17ae 11044 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11045 if (type < 0) {
11046 vty_out(vty, "%% Invalid route type\n");
11047 return CMD_WARNING_CONFIG_FAILED;
11048 }
718e3744 11049
d62a17ae 11050 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11051 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11052 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11053}
11054
11055DEFUN (bgp_redistribute_ipv6_metric,
11056 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11057 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11058 "Redistribute information from another routing protocol\n"
ab0181ee 11059 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11060 "Metric for redistributed routes\n"
11061 "Default metric\n")
11062{
d62a17ae 11063 VTY_DECLVAR_CONTEXT(bgp, bgp);
11064 int idx_protocol = 1;
11065 int idx_number = 3;
11066 int type;
11067 u_int32_t metric;
11068 struct bgp_redist *red;
11069
11070 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11071 if (type < 0) {
11072 vty_out(vty, "%% Invalid route type\n");
11073 return CMD_WARNING_CONFIG_FAILED;
11074 }
11075 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11076
d62a17ae 11077 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11078 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11079 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11080}
11081
11082DEFUN (bgp_redistribute_ipv6_rmap_metric,
11083 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11084 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11085 "Redistribute information from another routing protocol\n"
ab0181ee 11086 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11087 "Route map reference\n"
11088 "Pointer to route-map entries\n"
11089 "Metric for redistributed routes\n"
11090 "Default metric\n")
11091{
d62a17ae 11092 VTY_DECLVAR_CONTEXT(bgp, bgp);
11093 int idx_protocol = 1;
11094 int idx_word = 3;
11095 int idx_number = 5;
11096 int type;
11097 u_int32_t metric;
11098 struct bgp_redist *red;
11099
11100 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11101 if (type < 0) {
11102 vty_out(vty, "%% Invalid route type\n");
11103 return CMD_WARNING_CONFIG_FAILED;
11104 }
11105 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11106
d62a17ae 11107 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11108 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11109 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11110 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11111}
11112
11113DEFUN (bgp_redistribute_ipv6_metric_rmap,
11114 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11115 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11116 "Redistribute information from another routing protocol\n"
ab0181ee 11117 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11118 "Metric for redistributed routes\n"
11119 "Default metric\n"
11120 "Route map reference\n"
11121 "Pointer to route-map entries\n")
11122{
d62a17ae 11123 VTY_DECLVAR_CONTEXT(bgp, bgp);
11124 int idx_protocol = 1;
11125 int idx_number = 3;
11126 int idx_word = 5;
11127 int type;
11128 u_int32_t metric;
11129 struct bgp_redist *red;
11130
11131 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11132 if (type < 0) {
11133 vty_out(vty, "%% Invalid route type\n");
11134 return CMD_WARNING_CONFIG_FAILED;
11135 }
11136 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11137
d62a17ae 11138 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11139 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11140 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11141 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11142}
11143
11144DEFUN (no_bgp_redistribute_ipv6,
11145 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11146 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11147 NO_STR
11148 "Redistribute information from another routing protocol\n"
3b14d86e 11149 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11150 "Metric for redistributed routes\n"
11151 "Default metric\n"
11152 "Route map reference\n"
11153 "Pointer to route-map entries\n")
718e3744 11154{
d62a17ae 11155 VTY_DECLVAR_CONTEXT(bgp, bgp);
11156 int idx_protocol = 2;
11157 int type;
718e3744 11158
d62a17ae 11159 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11160 if (type < 0) {
11161 vty_out(vty, "%% Invalid route type\n");
11162 return CMD_WARNING_CONFIG_FAILED;
11163 }
718e3744 11164
d62a17ae 11165 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11166}
11167
11168int bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
11169 safi_t safi, int *write)
11170{
11171 int i;
11172
11173 /* Unicast redistribution only. */
11174 if (safi != SAFI_UNICAST)
11175 return 0;
11176
11177 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11178 /* Redistribute BGP does not make sense. */
11179 if (i != ZEBRA_ROUTE_BGP) {
11180 struct list *red_list;
11181 struct listnode *node;
11182 struct bgp_redist *red;
11183
11184 red_list = bgp->redist[afi][i];
11185 if (!red_list)
11186 continue;
11187
11188 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
11189 /* Display "address-family" when it is not yet
11190 * diplayed. */
11191 bgp_config_write_family_header(vty, afi, safi,
11192 write);
11193
11194 /* "redistribute" configuration. */
11195 vty_out(vty, " redistribute %s",
11196 zebra_route_string(i));
11197 if (red->instance)
11198 vty_out(vty, " %d", red->instance);
11199 if (red->redist_metric_flag)
11200 vty_out(vty, " metric %u",
11201 red->redist_metric);
11202 if (red->rmap.name)
11203 vty_out(vty, " route-map %s",
11204 red->rmap.name);
11205 vty_out(vty, "\n");
11206 }
11207 }
11208 }
11209 return *write;
718e3744 11210}
6b0655a2 11211
718e3744 11212/* BGP node structure. */
d62a17ae 11213static struct cmd_node bgp_node = {
9d303b37 11214 BGP_NODE, "%s(config-router)# ", 1,
718e3744 11215};
11216
d62a17ae 11217static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 11218 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 11219};
11220
d62a17ae 11221static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 11222 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 11223};
11224
d62a17ae 11225static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 11226 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11227};
11228
d62a17ae 11229static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 11230 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 11231};
11232
d62a17ae 11233static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 11234 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 11235};
11236
d62a17ae 11237static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 11238 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11239};
11240
d62a17ae 11241static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11242 "%s(config-router-af)# ", 1};
6b0655a2 11243
d62a17ae 11244static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11245 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 11246
d62a17ae 11247static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11248 "%s(config-router-evpn)# ", 1};
4e0b7b6d 11249
d62a17ae 11250static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11251 "%s(config-router-af-vni)# ", 1};
90e60aa7 11252
d62a17ae 11253static void community_list_vty(void);
1f8ae70b 11254
d62a17ae 11255static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 11256{
d62a17ae 11257 struct bgp *bgp;
11258 struct peer *peer;
11259 struct peer_group *group;
11260 struct listnode *lnbgp, *lnpeer;
b8a815e5 11261
d62a17ae 11262 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11263 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11264 /* only provide suggestions on the appropriate input
11265 * token type,
11266 * they'll otherwise show up multiple times */
11267 enum cmd_token_type match_type;
11268 char *name = peer->host;
d48ed3e0 11269
d62a17ae 11270 if (peer->conf_if) {
11271 match_type = VARIABLE_TKN;
11272 name = peer->conf_if;
11273 } else if (strchr(peer->host, ':'))
11274 match_type = IPV6_TKN;
11275 else
11276 match_type = IPV4_TKN;
d48ed3e0 11277
d62a17ae 11278 if (token->type != match_type)
11279 continue;
d48ed3e0 11280
d62a17ae 11281 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11282 }
d48ed3e0 11283
d62a17ae 11284 if (token->type == VARIABLE_TKN)
11285 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11286 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11287 group->name));
11288 }
b8a815e5
DL
11289}
11290
11291static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 11292 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11293 {.varname = "neighbors", .completions = bgp_ac_neighbor},
11294 {.completions = NULL}};
11295
11296void bgp_vty_init(void)
11297{
11298 cmd_variable_handler_register(bgp_var_neighbor);
11299
11300 /* Install bgp top node. */
11301 install_node(&bgp_node, bgp_config_write);
11302 install_node(&bgp_ipv4_unicast_node, NULL);
11303 install_node(&bgp_ipv4_multicast_node, NULL);
11304 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11305 install_node(&bgp_ipv6_unicast_node, NULL);
11306 install_node(&bgp_ipv6_multicast_node, NULL);
11307 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11308 install_node(&bgp_vpnv4_node, NULL);
11309 install_node(&bgp_vpnv6_node, NULL);
11310 install_node(&bgp_evpn_node, NULL);
11311 install_node(&bgp_evpn_vni_node, NULL);
11312
11313 /* Install default VTY commands to new nodes. */
11314 install_default(BGP_NODE);
11315 install_default(BGP_IPV4_NODE);
11316 install_default(BGP_IPV4M_NODE);
11317 install_default(BGP_IPV4L_NODE);
11318 install_default(BGP_IPV6_NODE);
11319 install_default(BGP_IPV6M_NODE);
11320 install_default(BGP_IPV6L_NODE);
11321 install_default(BGP_VPNV4_NODE);
11322 install_default(BGP_VPNV6_NODE);
11323 install_default(BGP_EVPN_NODE);
11324 install_default(BGP_EVPN_VNI_NODE);
11325
11326 /* "bgp multiple-instance" commands. */
11327 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11328 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11329
11330 /* "bgp config-type" commands. */
11331 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11332 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11333
11334 /* bgp route-map delay-timer commands. */
11335 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11336 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11337
11338 /* Dummy commands (Currently not supported) */
11339 install_element(BGP_NODE, &no_synchronization_cmd);
11340 install_element(BGP_NODE, &no_auto_summary_cmd);
11341
11342 /* "router bgp" commands. */
11343 install_element(CONFIG_NODE, &router_bgp_cmd);
11344
11345 /* "no router bgp" commands. */
11346 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11347
11348 /* "bgp router-id" commands. */
11349 install_element(BGP_NODE, &bgp_router_id_cmd);
11350 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11351
11352 /* "bgp cluster-id" commands. */
11353 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11354 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11355
11356 /* "bgp confederation" commands. */
11357 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11358 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11359
11360 /* "bgp confederation peers" commands. */
11361 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11362 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11363
11364 /* bgp max-med command */
11365 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11366 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11367 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11368 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11369 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11370
11371 /* bgp disable-ebgp-connected-nh-check */
11372 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11373 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11374
11375 /* bgp update-delay command */
11376 install_element(BGP_NODE, &bgp_update_delay_cmd);
11377 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11378 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11379
11380 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11381 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
11382
11383 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11384 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11385
11386 /* "maximum-paths" commands. */
11387 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11388 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11389 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11390 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11391 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11392 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11393 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11394 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11395 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11396 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11397 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11398 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11399 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11400 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11401 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11402
11403 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11404 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11405 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11406 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11407 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11408
11409 /* "timers bgp" commands. */
11410 install_element(BGP_NODE, &bgp_timers_cmd);
11411 install_element(BGP_NODE, &no_bgp_timers_cmd);
11412
11413 /* route-map delay-timer commands - per instance for backwards compat.
11414 */
11415 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11416 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11417
11418 /* "bgp client-to-client reflection" commands */
11419 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11420 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11421
11422 /* "bgp always-compare-med" commands */
11423 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11424 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11425
11426 /* "bgp deterministic-med" commands */
11427 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11428 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11429
11430 /* "bgp graceful-restart" commands */
11431 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11432 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11433 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11434 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11435 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11436 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11437
11438 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11439 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11440
11441 /* "bgp fast-external-failover" commands */
11442 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11443 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11444
11445 /* "bgp enforce-first-as" commands */
11446 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11447 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11448
11449 /* "bgp bestpath compare-routerid" commands */
11450 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11451 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11452
11453 /* "bgp bestpath as-path ignore" commands */
11454 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11455 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11456
11457 /* "bgp bestpath as-path confed" commands */
11458 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11459 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11460
11461 /* "bgp bestpath as-path multipath-relax" commands */
11462 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11463 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11464
11465 /* "bgp log-neighbor-changes" commands */
11466 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11467 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11468
11469 /* "bgp bestpath med" commands */
11470 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11471 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11472
11473 /* "no bgp default ipv4-unicast" commands. */
11474 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11475 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11476
11477 /* "bgp network import-check" commands. */
11478 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11479 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11480 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11481
11482 /* "bgp default local-preference" commands. */
11483 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11484 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11485
11486 /* bgp default show-hostname */
11487 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11488 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11489
11490 /* "bgp default subgroup-pkt-queue-max" commands. */
11491 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11492 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11493
11494 /* bgp ibgp-allow-policy-mods command */
11495 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11496 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11497
11498 /* "bgp listen limit" commands. */
11499 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11500 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11501
11502 /* "bgp listen range" commands. */
11503 install_element(BGP_NODE, &bgp_listen_range_cmd);
11504 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11505
11506 /* "neighbor remote-as" commands. */
11507 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11508 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11509 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11510 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11511 install_element(BGP_NODE,
11512 &neighbor_interface_v6only_config_remote_as_cmd);
11513 install_element(BGP_NODE, &no_neighbor_cmd);
11514 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
11515
11516 /* "neighbor peer-group" commands. */
11517 install_element(BGP_NODE, &neighbor_peer_group_cmd);
11518 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
11519 install_element(BGP_NODE,
11520 &no_neighbor_interface_peer_group_remote_as_cmd);
11521
11522 /* "neighbor local-as" commands. */
11523 install_element(BGP_NODE, &neighbor_local_as_cmd);
11524 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
11525 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
11526 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
11527
11528 /* "neighbor solo" commands. */
11529 install_element(BGP_NODE, &neighbor_solo_cmd);
11530 install_element(BGP_NODE, &no_neighbor_solo_cmd);
11531
11532 /* "neighbor password" commands. */
11533 install_element(BGP_NODE, &neighbor_password_cmd);
11534 install_element(BGP_NODE, &no_neighbor_password_cmd);
11535
11536 /* "neighbor activate" commands. */
11537 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
11538 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
11539 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
11540 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
11541 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
11542 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
11543 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
11544 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
11545 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
11546 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
11547
11548 /* "no neighbor activate" commands. */
11549 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
11550 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11551 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
11552 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
11553 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
11554 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
11555 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
11556 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
11557 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
11558 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
11559
11560 /* "neighbor peer-group" set commands. */
11561 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
11562 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11563 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11564 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11565 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11566 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11567 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11568 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11569
11570 /* "no neighbor peer-group unset" commands. */
11571 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
11572 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11573 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11574 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11575 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11576 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11577 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11578 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11579
11580 /* "neighbor softreconfiguration inbound" commands.*/
11581 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11582 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
11583 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11584 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11585 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11586 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11587 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11588 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11589 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11590 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11591 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11592 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11593 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11594 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11595 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11596 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11597 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11598 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11599
11600 /* "neighbor attribute-unchanged" commands. */
11601 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11602 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
11603 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
11604 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
11605 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
11606 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
11607 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11608 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
11609 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
11610 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
11611 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
11612 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
11613 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11614 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
11615 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
11616 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
11617 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
11618 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
11619
11620 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11621 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11622
11623 /* "nexthop-local unchanged" commands */
11624 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11625 install_element(BGP_IPV6_NODE,
11626 &no_neighbor_nexthop_local_unchanged_cmd);
11627
11628 /* "neighbor next-hop-self" commands. */
11629 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11630 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
11631 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11632 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11633 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11634 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
11635 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11636 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
11637 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11638 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
11639 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11640 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
11641 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11642 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
11643 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11644 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
11645 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11646 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
11647
11648 /* "neighbor next-hop-self force" commands. */
11649 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11650 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
11651 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11652 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11653 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11654 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
11655 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11656 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
11657 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11658 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11659 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11660 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
11661 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11662 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
11663 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11664 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11665 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11666 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11667
11668 /* "neighbor as-override" commands. */
11669 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
11670 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
11671 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
11672 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11673 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11674 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
11675 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11676 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
11677 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
11678 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11679 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11680 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
11681 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11682 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
11683 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11684 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
11685 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11686 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
11687
11688 /* "neighbor remove-private-AS" commands. */
11689 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11690 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11691 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11692 install_element(BGP_NODE,
11693 &no_neighbor_remove_private_as_all_hidden_cmd);
11694 install_element(BGP_NODE,
11695 &neighbor_remove_private_as_replace_as_hidden_cmd);
11696 install_element(BGP_NODE,
11697 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11698 install_element(BGP_NODE,
11699 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11700 install_element(
11701 BGP_NODE,
11702 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
11703 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11704 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
11705 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11706 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11707 install_element(BGP_IPV4_NODE,
11708 &neighbor_remove_private_as_replace_as_cmd);
11709 install_element(BGP_IPV4_NODE,
11710 &no_neighbor_remove_private_as_replace_as_cmd);
11711 install_element(BGP_IPV4_NODE,
11712 &neighbor_remove_private_as_all_replace_as_cmd);
11713 install_element(BGP_IPV4_NODE,
11714 &no_neighbor_remove_private_as_all_replace_as_cmd);
11715 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11716 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
11717 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11718 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11719 install_element(BGP_IPV4M_NODE,
11720 &neighbor_remove_private_as_replace_as_cmd);
11721 install_element(BGP_IPV4M_NODE,
11722 &no_neighbor_remove_private_as_replace_as_cmd);
11723 install_element(BGP_IPV4M_NODE,
11724 &neighbor_remove_private_as_all_replace_as_cmd);
11725 install_element(BGP_IPV4M_NODE,
11726 &no_neighbor_remove_private_as_all_replace_as_cmd);
11727 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11728 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11729 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11730 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11731 install_element(BGP_IPV4L_NODE,
11732 &neighbor_remove_private_as_replace_as_cmd);
11733 install_element(BGP_IPV4L_NODE,
11734 &no_neighbor_remove_private_as_replace_as_cmd);
11735 install_element(BGP_IPV4L_NODE,
11736 &neighbor_remove_private_as_all_replace_as_cmd);
11737 install_element(BGP_IPV4L_NODE,
11738 &no_neighbor_remove_private_as_all_replace_as_cmd);
11739 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11740 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
11741 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11742 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11743 install_element(BGP_IPV6_NODE,
11744 &neighbor_remove_private_as_replace_as_cmd);
11745 install_element(BGP_IPV6_NODE,
11746 &no_neighbor_remove_private_as_replace_as_cmd);
11747 install_element(BGP_IPV6_NODE,
11748 &neighbor_remove_private_as_all_replace_as_cmd);
11749 install_element(BGP_IPV6_NODE,
11750 &no_neighbor_remove_private_as_all_replace_as_cmd);
11751 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11752 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
11753 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11754 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11755 install_element(BGP_IPV6M_NODE,
11756 &neighbor_remove_private_as_replace_as_cmd);
11757 install_element(BGP_IPV6M_NODE,
11758 &no_neighbor_remove_private_as_replace_as_cmd);
11759 install_element(BGP_IPV6M_NODE,
11760 &neighbor_remove_private_as_all_replace_as_cmd);
11761 install_element(BGP_IPV6M_NODE,
11762 &no_neighbor_remove_private_as_all_replace_as_cmd);
11763 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11764 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11765 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11766 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11767 install_element(BGP_IPV6L_NODE,
11768 &neighbor_remove_private_as_replace_as_cmd);
11769 install_element(BGP_IPV6L_NODE,
11770 &no_neighbor_remove_private_as_replace_as_cmd);
11771 install_element(BGP_IPV6L_NODE,
11772 &neighbor_remove_private_as_all_replace_as_cmd);
11773 install_element(BGP_IPV6L_NODE,
11774 &no_neighbor_remove_private_as_all_replace_as_cmd);
11775 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11776 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
11777 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11778 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11779 install_element(BGP_VPNV4_NODE,
11780 &neighbor_remove_private_as_replace_as_cmd);
11781 install_element(BGP_VPNV4_NODE,
11782 &no_neighbor_remove_private_as_replace_as_cmd);
11783 install_element(BGP_VPNV4_NODE,
11784 &neighbor_remove_private_as_all_replace_as_cmd);
11785 install_element(BGP_VPNV4_NODE,
11786 &no_neighbor_remove_private_as_all_replace_as_cmd);
11787 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11788 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11789 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11790 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11791 install_element(BGP_VPNV6_NODE,
11792 &neighbor_remove_private_as_replace_as_cmd);
11793 install_element(BGP_VPNV6_NODE,
11794 &no_neighbor_remove_private_as_replace_as_cmd);
11795 install_element(BGP_VPNV6_NODE,
11796 &neighbor_remove_private_as_all_replace_as_cmd);
11797 install_element(BGP_VPNV6_NODE,
11798 &no_neighbor_remove_private_as_all_replace_as_cmd);
11799
11800 /* "neighbor send-community" commands.*/
11801 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
11802 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11803 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11804 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
11805 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
11806 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11807 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11808 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11809 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11810 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11811 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11812 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
11813 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11814 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11815 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11816 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
11817 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
11818 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11819 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11820 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
11821 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11822 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11823 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11824 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
11825 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11826 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11827 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11828 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
11829 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11830 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11831 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11832 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
11833 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11834 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11835 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11836 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
11837
11838 /* "neighbor route-reflector" commands.*/
11839 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11840 install_element(BGP_NODE,
11841 &no_neighbor_route_reflector_client_hidden_cmd);
11842 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11843 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11844 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11845 install_element(BGP_IPV4M_NODE,
11846 &no_neighbor_route_reflector_client_cmd);
11847 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11848 install_element(BGP_IPV4L_NODE,
11849 &no_neighbor_route_reflector_client_cmd);
11850 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11851 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
11852 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11853 install_element(BGP_IPV6M_NODE,
11854 &no_neighbor_route_reflector_client_cmd);
11855 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11856 install_element(BGP_IPV6L_NODE,
11857 &no_neighbor_route_reflector_client_cmd);
11858 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11859 install_element(BGP_VPNV4_NODE,
11860 &no_neighbor_route_reflector_client_cmd);
11861 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11862 install_element(BGP_VPNV6_NODE,
11863 &no_neighbor_route_reflector_client_cmd);
11864 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
11865 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
11866
11867 /* "neighbor route-server" commands.*/
11868 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11869 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
11870 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11871 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11872 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11873 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
11874 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
11875 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
11876 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
11877 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
11878 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
11879 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
11880 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
11881 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
11882 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
11883 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
11884 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
11885 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
11886
11887 /* "neighbor addpath-tx-all-paths" commands.*/
11888 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
11889 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
11890 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11891 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11892 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11893 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11894 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11895 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11896 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11897 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11898 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11899 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11900 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11901 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11902 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11903 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11904 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11905 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11906
11907 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
11908 install_element(BGP_NODE,
11909 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11910 install_element(BGP_NODE,
11911 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11912 install_element(BGP_IPV4_NODE,
11913 &neighbor_addpath_tx_bestpath_per_as_cmd);
11914 install_element(BGP_IPV4_NODE,
11915 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11916 install_element(BGP_IPV4M_NODE,
11917 &neighbor_addpath_tx_bestpath_per_as_cmd);
11918 install_element(BGP_IPV4M_NODE,
11919 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11920 install_element(BGP_IPV4L_NODE,
11921 &neighbor_addpath_tx_bestpath_per_as_cmd);
11922 install_element(BGP_IPV4L_NODE,
11923 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11924 install_element(BGP_IPV6_NODE,
11925 &neighbor_addpath_tx_bestpath_per_as_cmd);
11926 install_element(BGP_IPV6_NODE,
11927 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11928 install_element(BGP_IPV6M_NODE,
11929 &neighbor_addpath_tx_bestpath_per_as_cmd);
11930 install_element(BGP_IPV6M_NODE,
11931 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11932 install_element(BGP_IPV6L_NODE,
11933 &neighbor_addpath_tx_bestpath_per_as_cmd);
11934 install_element(BGP_IPV6L_NODE,
11935 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11936 install_element(BGP_VPNV4_NODE,
11937 &neighbor_addpath_tx_bestpath_per_as_cmd);
11938 install_element(BGP_VPNV4_NODE,
11939 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11940 install_element(BGP_VPNV6_NODE,
11941 &neighbor_addpath_tx_bestpath_per_as_cmd);
11942 install_element(BGP_VPNV6_NODE,
11943 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11944
11945 /* "neighbor passive" commands. */
11946 install_element(BGP_NODE, &neighbor_passive_cmd);
11947 install_element(BGP_NODE, &no_neighbor_passive_cmd);
11948
11949
11950 /* "neighbor shutdown" commands. */
11951 install_element(BGP_NODE, &neighbor_shutdown_cmd);
11952 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
11953 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
11954 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
11955
11956 /* "neighbor capability extended-nexthop" commands.*/
11957 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
11958 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
11959
11960 /* "neighbor capability orf prefix-list" commands.*/
11961 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
11962 install_element(BGP_NODE,
11963 &no_neighbor_capability_orf_prefix_hidden_cmd);
11964 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
11965 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
11966 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
11967 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
11968 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
11969 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
11970 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
11971 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
11972 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
11973 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
11974 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
11975 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
11976
11977 /* "neighbor capability dynamic" commands.*/
11978 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
11979 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
11980
11981 /* "neighbor dont-capability-negotiate" commands. */
11982 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
11983 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
11984
11985 /* "neighbor ebgp-multihop" commands. */
11986 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
11987 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
11988 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
11989
11990 /* "neighbor disable-connected-check" commands. */
11991 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
11992 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
11993
11994 /* "neighbor description" commands. */
11995 install_element(BGP_NODE, &neighbor_description_cmd);
11996 install_element(BGP_NODE, &no_neighbor_description_cmd);
11997
11998 /* "neighbor update-source" commands. "*/
11999 install_element(BGP_NODE, &neighbor_update_source_cmd);
12000 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12001
12002 /* "neighbor default-originate" commands. */
12003 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12004 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12005 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12006 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12007 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12008 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12009 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12010 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12011 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12012 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12013 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12014 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12015 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12016 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12017 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12018 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12019 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12020 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12021 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12022 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12023 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12024
12025 /* "neighbor port" commands. */
12026 install_element(BGP_NODE, &neighbor_port_cmd);
12027 install_element(BGP_NODE, &no_neighbor_port_cmd);
12028
12029 /* "neighbor weight" commands. */
12030 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12031 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12032
12033 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12034 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12035 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12036 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12037 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12038 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12039 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12040 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12041 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12042 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12043 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12044 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12045 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12046 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12047 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12048 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12049
12050 /* "neighbor override-capability" commands. */
12051 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12052 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12053
12054 /* "neighbor strict-capability-match" commands. */
12055 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12056 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12057
12058 /* "neighbor timers" commands. */
12059 install_element(BGP_NODE, &neighbor_timers_cmd);
12060 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12061
12062 /* "neighbor timers connect" commands. */
12063 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12064 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12065
12066 /* "neighbor advertisement-interval" commands. */
12067 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12068 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12069
12070 /* "neighbor interface" commands. */
12071 install_element(BGP_NODE, &neighbor_interface_cmd);
12072 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12073
12074 /* "neighbor distribute" commands. */
12075 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12076 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12077 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12078 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12079 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12080 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12081 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12082 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12083 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12084 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12085 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12086 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12087 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12088 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12089 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12090 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12091 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12092 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12093
12094 /* "neighbor prefix-list" commands. */
12095 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12096 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12097 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12098 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12099 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12100 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12101 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12102 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12103 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12104 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12105 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12106 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12107 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12108 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12109 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12110 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12111 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12112 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12113
12114 /* "neighbor filter-list" commands. */
12115 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12116 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12117 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12118 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12119 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12120 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12121 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12122 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12123 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12124 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12125 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12126 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12127 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12128 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12129 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12130 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12131 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12132 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12133
12134 /* "neighbor route-map" commands. */
12135 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12136 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12137 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12138 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12139 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12140 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12141 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12142 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12143 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12144 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12145 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12146 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12147 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12148 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12149 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12150 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12151 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12152 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
12153 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12154 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 12155
12156 /* "neighbor unsuppress-map" commands. */
12157 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12158 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12159 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12160 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12161 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12162 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12163 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12164 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12165 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12166 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12167 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12168 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12169 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12170 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12171 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12172 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12173 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12174 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12175
12176 /* "neighbor maximum-prefix" commands. */
12177 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12178 install_element(BGP_NODE,
12179 &neighbor_maximum_prefix_threshold_hidden_cmd);
12180 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12181 install_element(BGP_NODE,
12182 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12183 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12184 install_element(BGP_NODE,
12185 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12186 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12187 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12188 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12189 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12190 install_element(BGP_IPV4_NODE,
12191 &neighbor_maximum_prefix_threshold_warning_cmd);
12192 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12193 install_element(BGP_IPV4_NODE,
12194 &neighbor_maximum_prefix_threshold_restart_cmd);
12195 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12196 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12197 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12198 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12199 install_element(BGP_IPV4M_NODE,
12200 &neighbor_maximum_prefix_threshold_warning_cmd);
12201 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12202 install_element(BGP_IPV4M_NODE,
12203 &neighbor_maximum_prefix_threshold_restart_cmd);
12204 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12205 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12206 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12207 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12208 install_element(BGP_IPV4L_NODE,
12209 &neighbor_maximum_prefix_threshold_warning_cmd);
12210 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12211 install_element(BGP_IPV4L_NODE,
12212 &neighbor_maximum_prefix_threshold_restart_cmd);
12213 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12214 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12215 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12216 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12217 install_element(BGP_IPV6_NODE,
12218 &neighbor_maximum_prefix_threshold_warning_cmd);
12219 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12220 install_element(BGP_IPV6_NODE,
12221 &neighbor_maximum_prefix_threshold_restart_cmd);
12222 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12223 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12224 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12225 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12226 install_element(BGP_IPV6M_NODE,
12227 &neighbor_maximum_prefix_threshold_warning_cmd);
12228 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12229 install_element(BGP_IPV6M_NODE,
12230 &neighbor_maximum_prefix_threshold_restart_cmd);
12231 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12232 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12233 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12234 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12235 install_element(BGP_IPV6L_NODE,
12236 &neighbor_maximum_prefix_threshold_warning_cmd);
12237 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12238 install_element(BGP_IPV6L_NODE,
12239 &neighbor_maximum_prefix_threshold_restart_cmd);
12240 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12241 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12242 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12243 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12244 install_element(BGP_VPNV4_NODE,
12245 &neighbor_maximum_prefix_threshold_warning_cmd);
12246 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12247 install_element(BGP_VPNV4_NODE,
12248 &neighbor_maximum_prefix_threshold_restart_cmd);
12249 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12250 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12251 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12252 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12253 install_element(BGP_VPNV6_NODE,
12254 &neighbor_maximum_prefix_threshold_warning_cmd);
12255 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12256 install_element(BGP_VPNV6_NODE,
12257 &neighbor_maximum_prefix_threshold_restart_cmd);
12258 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12259
12260 /* "neighbor allowas-in" */
12261 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12262 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12263 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12264 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12265 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12266 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12267 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12268 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12269 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12270 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12271 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12272 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12273 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12274 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12275 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12276 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12277 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12278 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12279 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12280 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12281
12282 /* address-family commands. */
12283 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12284 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 12285#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 12286 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12287 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 12288#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 12289
d62a17ae 12290 install_element(BGP_NODE, &address_family_evpn_cmd);
12291
12292 /* "exit-address-family" command. */
12293 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12294 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12295 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12296 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12297 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12298 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12299 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12300 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12301 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12302
12303 /* "clear ip bgp commands" */
12304 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12305
12306 /* clear ip bgp prefix */
12307 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12308 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12309 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12310
12311 /* "show [ip] bgp summary" commands. */
12312 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
12313 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
12314 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
12315 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
12316 install_element(VIEW_NODE, &show_bgp_updgrps_adj_cmd);
12317 install_element(VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
12318 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
12319 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
12320 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
12321 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
12322 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12323 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
12324 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
12325 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
12326 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12327
12328 /* "show [ip] bgp neighbors" commands. */
12329 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12330
12331 /* "show [ip] bgp peer-group" commands. */
12332 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12333
12334 /* "show [ip] bgp paths" commands. */
12335 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12336
12337 /* "show [ip] bgp community" commands. */
12338 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12339
12340 /* "show ip bgp large-community" commands. */
12341 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12342 /* "show [ip] bgp attribute-info" commands. */
12343 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12344
12345 /* "redistribute" commands. */
12346 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12347 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12348 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12349 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12350 install_element(BGP_NODE,
12351 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12352 install_element(BGP_NODE,
12353 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12354 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12355 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12356 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12357 install_element(BGP_NODE,
12358 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12359 install_element(BGP_NODE,
12360 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12361 install_element(BGP_NODE,
12362 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12363 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12364 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12365 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12366 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12367 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12368 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12369 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12370 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12371 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12372 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12373 install_element(BGP_IPV4_NODE,
12374 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12375 install_element(BGP_IPV4_NODE,
12376 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12377 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12378 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12379 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12380 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12381 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12382 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12383
12384 /* ttl_security commands */
12385 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12386 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12387
12388 /* "show [ip] bgp memory" commands. */
12389 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12390
acf71666
MK
12391 /* "show bgp martian next-hop" */
12392 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12393
d62a17ae 12394 /* "show [ip] bgp views" commands. */
12395 install_element(VIEW_NODE, &show_bgp_views_cmd);
12396
12397 /* "show [ip] bgp vrfs" commands. */
12398 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12399
12400 /* Community-list. */
12401 community_list_vty();
718e3744 12402}
6b0655a2 12403
718e3744 12404#include "memory.h"
12405#include "bgp_regex.h"
12406#include "bgp_clist.h"
12407#include "bgp_ecommunity.h"
12408
12409/* VTY functions. */
12410
12411/* Direction value to string conversion. */
d62a17ae 12412static const char *community_direct_str(int direct)
12413{
12414 switch (direct) {
12415 case COMMUNITY_DENY:
12416 return "deny";
12417 case COMMUNITY_PERMIT:
12418 return "permit";
12419 default:
12420 return "unknown";
12421 }
718e3744 12422}
12423
12424/* Display error string. */
d62a17ae 12425static void community_list_perror(struct vty *vty, int ret)
12426{
12427 switch (ret) {
12428 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12429 vty_out(vty, "%% Can't find community-list\n");
12430 break;
12431 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12432 vty_out(vty, "%% Malformed community-list value\n");
12433 break;
12434 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12435 vty_out(vty,
12436 "%% Community name conflict, previously defined as standard community\n");
12437 break;
12438 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12439 vty_out(vty,
12440 "%% Community name conflict, previously defined as expanded community\n");
12441 break;
12442 }
718e3744 12443}
12444
5bf15956
DW
12445/* "community-list" keyword help string. */
12446#define COMMUNITY_LIST_STR "Add a community list entry\n"
12447
5bf15956 12448/* ip community-list standard */
718e3744 12449DEFUN (ip_community_list_standard,
12450 ip_community_list_standard_cmd,
e961923c 12451 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12452 IP_STR
12453 COMMUNITY_LIST_STR
12454 "Community list number (standard)\n"
5bf15956 12455 "Add an standard community-list entry\n"
718e3744 12456 "Community list name\n"
12457 "Specify community to reject\n"
12458 "Specify community to accept\n"
12459 COMMUNITY_VAL_STR)
12460{
d62a17ae 12461 char *cl_name_or_number = NULL;
12462 int direct = 0;
12463 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12464
d62a17ae 12465 int idx = 0;
12466 argv_find(argv, argc, "(1-99)", &idx);
12467 argv_find(argv, argc, "WORD", &idx);
12468 cl_name_or_number = argv[idx]->arg;
12469 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12470 : COMMUNITY_DENY;
12471 argv_find(argv, argc, "AA:NN", &idx);
12472 char *str = argv_concat(argv, argc, idx);
42f914d4 12473
d62a17ae 12474 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12475 style);
42f914d4 12476
d62a17ae 12477 XFREE(MTYPE_TMP, str);
42f914d4 12478
d62a17ae 12479 if (ret < 0) {
12480 /* Display error string. */
12481 community_list_perror(vty, ret);
12482 return CMD_WARNING_CONFIG_FAILED;
12483 }
42f914d4 12484
d62a17ae 12485 return CMD_SUCCESS;
718e3744 12486}
12487
fee6e4e4 12488DEFUN (no_ip_community_list_standard_all,
12489 no_ip_community_list_standard_all_cmd,
e961923c 12490 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12491 NO_STR
12492 IP_STR
12493 COMMUNITY_LIST_STR
12494 "Community list number (standard)\n"
5bf15956
DW
12495 "Add an standard community-list entry\n"
12496 "Community list name\n"
718e3744 12497 "Specify community to reject\n"
12498 "Specify community to accept\n"
12499 COMMUNITY_VAL_STR)
12500{
d62a17ae 12501 int delete_all = 0;
42f914d4 12502
d62a17ae 12503 char *cl_name_or_number = NULL;
12504 int direct = 0;
12505 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12506
d62a17ae 12507 int idx = 0;
12508 argv_find(argv, argc, "(1-99)", &idx);
12509 argv_find(argv, argc, "WORD", &idx);
12510 cl_name_or_number = argv[idx]->arg;
12511 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12512 : COMMUNITY_DENY;
12513 argv_find(argv, argc, "AA:NN", &idx);
12514 char *str = argv_concat(argv, argc, idx);
42f914d4 12515
d62a17ae 12516 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12517 direct, style, delete_all);
42f914d4 12518
d62a17ae 12519 XFREE(MTYPE_TMP, str);
daf9ddbb 12520
d62a17ae 12521 if (ret < 0) {
12522 community_list_perror(vty, ret);
12523 return CMD_WARNING_CONFIG_FAILED;
12524 }
42f914d4 12525
d62a17ae 12526 return CMD_SUCCESS;
718e3744 12527}
12528
5bf15956
DW
12529/* ip community-list expanded */
12530DEFUN (ip_community_list_expanded_all,
12531 ip_community_list_expanded_all_cmd,
42f914d4 12532 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12533 IP_STR
12534 COMMUNITY_LIST_STR
12535 "Community list number (expanded)\n"
5bf15956 12536 "Add an expanded community-list entry\n"
718e3744 12537 "Community list name\n"
12538 "Specify community to reject\n"
12539 "Specify community to accept\n"
12540 COMMUNITY_VAL_STR)
12541{
d62a17ae 12542 char *cl_name_or_number = NULL;
12543 int direct = 0;
12544 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12545
d62a17ae 12546 int idx = 0;
12547 argv_find(argv, argc, "(100-500)", &idx);
12548 argv_find(argv, argc, "WORD", &idx);
12549 cl_name_or_number = argv[idx]->arg;
12550 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12551 : COMMUNITY_DENY;
12552 argv_find(argv, argc, "AA:NN", &idx);
12553 char *str = argv_concat(argv, argc, idx);
42f914d4 12554
d62a17ae 12555 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12556 style);
42f914d4 12557
d62a17ae 12558 XFREE(MTYPE_TMP, str);
42f914d4 12559
d62a17ae 12560 if (ret < 0) {
12561 /* Display error string. */
12562 community_list_perror(vty, ret);
12563 return CMD_WARNING_CONFIG_FAILED;
12564 }
42f914d4 12565
d62a17ae 12566 return CMD_SUCCESS;
718e3744 12567}
12568
5bf15956
DW
12569DEFUN (no_ip_community_list_expanded_all,
12570 no_ip_community_list_expanded_all_cmd,
42f914d4 12571 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12572 NO_STR
12573 IP_STR
12574 COMMUNITY_LIST_STR
5bf15956
DW
12575 "Community list number (expanded)\n"
12576 "Add an expanded community-list entry\n"
718e3744 12577 "Community list name\n"
12578 "Specify community to reject\n"
12579 "Specify community to accept\n"
5bf15956 12580 COMMUNITY_VAL_STR)
718e3744 12581{
d62a17ae 12582 int delete_all = 0;
42f914d4 12583
d62a17ae 12584 char *cl_name_or_number = NULL;
12585 int direct = 0;
12586 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12587
d62a17ae 12588 int idx = 0;
12589 argv_find(argv, argc, "(100-500)", &idx);
12590 argv_find(argv, argc, "WORD", &idx);
12591 cl_name_or_number = argv[idx]->arg;
12592 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12593 : COMMUNITY_DENY;
12594 argv_find(argv, argc, "AA:NN", &idx);
12595 char *str = argv_concat(argv, argc, idx);
42f914d4 12596
d62a17ae 12597 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12598 direct, style, delete_all);
42f914d4 12599
d62a17ae 12600 XFREE(MTYPE_TMP, str);
daf9ddbb 12601
d62a17ae 12602 if (ret < 0) {
12603 community_list_perror(vty, ret);
12604 return CMD_WARNING_CONFIG_FAILED;
12605 }
42f914d4 12606
d62a17ae 12607 return CMD_SUCCESS;
718e3744 12608}
12609
d62a17ae 12610static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 12611{
d62a17ae 12612 struct community_entry *entry;
718e3744 12613
d62a17ae 12614 for (entry = list->head; entry; entry = entry->next) {
12615 if (entry == list->head) {
12616 if (all_digit(list->name))
12617 vty_out(vty, "Community %s list %s\n",
12618 entry->style == COMMUNITY_LIST_STANDARD
12619 ? "standard"
12620 : "(expanded) access",
12621 list->name);
12622 else
12623 vty_out(vty, "Named Community %s list %s\n",
12624 entry->style == COMMUNITY_LIST_STANDARD
12625 ? "standard"
12626 : "expanded",
12627 list->name);
12628 }
12629 if (entry->any)
12630 vty_out(vty, " %s\n",
12631 community_direct_str(entry->direct));
12632 else
12633 vty_out(vty, " %s %s\n",
12634 community_direct_str(entry->direct),
12635 entry->style == COMMUNITY_LIST_STANDARD
12636 ? community_str(entry->u.com)
12637 : entry->config);
12638 }
718e3744 12639}
12640
12641DEFUN (show_ip_community_list,
12642 show_ip_community_list_cmd,
12643 "show ip community-list",
12644 SHOW_STR
12645 IP_STR
12646 "List community-list\n")
12647{
d62a17ae 12648 struct community_list *list;
12649 struct community_list_master *cm;
718e3744 12650
d62a17ae 12651 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
12652 if (!cm)
12653 return CMD_SUCCESS;
718e3744 12654
d62a17ae 12655 for (list = cm->num.head; list; list = list->next)
12656 community_list_show(vty, list);
718e3744 12657
d62a17ae 12658 for (list = cm->str.head; list; list = list->next)
12659 community_list_show(vty, list);
718e3744 12660
d62a17ae 12661 return CMD_SUCCESS;
718e3744 12662}
12663
12664DEFUN (show_ip_community_list_arg,
12665 show_ip_community_list_arg_cmd,
6147e2c6 12666 "show ip community-list <(1-500)|WORD>",
718e3744 12667 SHOW_STR
12668 IP_STR
12669 "List community-list\n"
12670 "Community-list number\n"
12671 "Community-list name\n")
12672{
d62a17ae 12673 int idx_comm_list = 3;
12674 struct community_list *list;
718e3744 12675
d62a17ae 12676 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
12677 COMMUNITY_LIST_MASTER);
12678 if (!list) {
12679 vty_out(vty, "%% Can't find community-list\n");
12680 return CMD_WARNING;
12681 }
718e3744 12682
d62a17ae 12683 community_list_show(vty, list);
718e3744 12684
d62a17ae 12685 return CMD_SUCCESS;
718e3744 12686}
6b0655a2 12687
57d187bc
JS
12688/*
12689 * Large Community code.
12690 */
d62a17ae 12691static int lcommunity_list_set_vty(struct vty *vty, int argc,
12692 struct cmd_token **argv, int style,
12693 int reject_all_digit_name)
12694{
12695 int ret;
12696 int direct;
12697 char *str;
12698 int idx = 0;
12699 char *cl_name;
12700
12701 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12702 : COMMUNITY_DENY;
12703
12704 /* All digit name check. */
12705 idx = 0;
12706 argv_find(argv, argc, "WORD", &idx);
12707 argv_find(argv, argc, "(1-99)", &idx);
12708 argv_find(argv, argc, "(100-500)", &idx);
12709 cl_name = argv[idx]->arg;
12710 if (reject_all_digit_name && all_digit(cl_name)) {
12711 vty_out(vty, "%% Community name cannot have all digits\n");
12712 return CMD_WARNING_CONFIG_FAILED;
12713 }
12714
12715 idx = 0;
12716 argv_find(argv, argc, "AA:BB:CC", &idx);
12717 argv_find(argv, argc, "LINE", &idx);
12718 /* Concat community string argument. */
12719 if (idx)
12720 str = argv_concat(argv, argc, idx);
12721 else
12722 str = NULL;
12723
12724 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
12725
12726 /* Free temporary community list string allocated by
12727 argv_concat(). */
12728 if (str)
12729 XFREE(MTYPE_TMP, str);
12730
12731 if (ret < 0) {
12732 community_list_perror(vty, ret);
12733 return CMD_WARNING_CONFIG_FAILED;
12734 }
12735 return CMD_SUCCESS;
12736}
12737
12738static int lcommunity_list_unset_vty(struct vty *vty, int argc,
12739 struct cmd_token **argv, int style)
12740{
12741 int ret;
12742 int direct = 0;
12743 char *str = NULL;
12744 int idx = 0;
12745
12746 argv_find(argv, argc, "permit", &idx);
12747 argv_find(argv, argc, "deny", &idx);
12748
12749 if (idx) {
12750 /* Check the list direct. */
12751 if (strncmp(argv[idx]->arg, "p", 1) == 0)
12752 direct = COMMUNITY_PERMIT;
12753 else
12754 direct = COMMUNITY_DENY;
12755
12756 idx = 0;
12757 argv_find(argv, argc, "LINE", &idx);
12758 argv_find(argv, argc, "AA:AA:NN", &idx);
12759 /* Concat community string argument. */
12760 str = argv_concat(argv, argc, idx);
12761 }
12762
12763 idx = 0;
12764 argv_find(argv, argc, "(1-99)", &idx);
12765 argv_find(argv, argc, "(100-500)", &idx);
12766 argv_find(argv, argc, "WORD", &idx);
12767
12768 /* Unset community list. */
12769 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
12770 style);
12771
12772 /* Free temporary community list string allocated by
12773 argv_concat(). */
12774 if (str)
12775 XFREE(MTYPE_TMP, str);
12776
12777 if (ret < 0) {
12778 community_list_perror(vty, ret);
12779 return CMD_WARNING_CONFIG_FAILED;
12780 }
12781
12782 return CMD_SUCCESS;
57d187bc
JS
12783}
12784
12785/* "large-community-list" keyword help string. */
12786#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12787#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12788
12789DEFUN (ip_lcommunity_list_standard,
12790 ip_lcommunity_list_standard_cmd,
52951b63
DS
12791 "ip large-community-list (1-99) <deny|permit>",
12792 IP_STR
12793 LCOMMUNITY_LIST_STR
12794 "Large Community list number (standard)\n"
12795 "Specify large community to reject\n"
7111c1a0 12796 "Specify large community to accept\n")
52951b63 12797{
d62a17ae 12798 return lcommunity_list_set_vty(vty, argc, argv,
12799 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
12800}
12801
12802DEFUN (ip_lcommunity_list_standard1,
12803 ip_lcommunity_list_standard1_cmd,
12804 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
12805 IP_STR
12806 LCOMMUNITY_LIST_STR
12807 "Large Community list number (standard)\n"
12808 "Specify large community to reject\n"
12809 "Specify large community to accept\n"
12810 LCOMMUNITY_VAL_STR)
12811{
d62a17ae 12812 return lcommunity_list_set_vty(vty, argc, argv,
12813 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
12814}
12815
12816DEFUN (ip_lcommunity_list_expanded,
12817 ip_lcommunity_list_expanded_cmd,
12818 "ip large-community-list (100-500) <deny|permit> LINE...",
12819 IP_STR
12820 LCOMMUNITY_LIST_STR
12821 "Large Community list number (expanded)\n"
12822 "Specify large community to reject\n"
12823 "Specify large community to accept\n"
12824 "An ordered list as a regular-expression\n")
12825{
d62a17ae 12826 return lcommunity_list_set_vty(vty, argc, argv,
12827 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
12828}
12829
12830DEFUN (ip_lcommunity_list_name_standard,
12831 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
12832 "ip large-community-list standard WORD <deny|permit>",
12833 IP_STR
12834 LCOMMUNITY_LIST_STR
12835 "Specify standard large-community-list\n"
12836 "Large Community list name\n"
12837 "Specify large community to reject\n"
12838 "Specify large community to accept\n")
12839{
d62a17ae 12840 return lcommunity_list_set_vty(vty, argc, argv,
12841 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
12842}
12843
12844DEFUN (ip_lcommunity_list_name_standard1,
12845 ip_lcommunity_list_name_standard1_cmd,
12846 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
12847 IP_STR
12848 LCOMMUNITY_LIST_STR
12849 "Specify standard large-community-list\n"
12850 "Large Community list name\n"
12851 "Specify large community to reject\n"
12852 "Specify large community to accept\n"
12853 LCOMMUNITY_VAL_STR)
12854{
d62a17ae 12855 return lcommunity_list_set_vty(vty, argc, argv,
12856 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
12857}
12858
12859DEFUN (ip_lcommunity_list_name_expanded,
12860 ip_lcommunity_list_name_expanded_cmd,
12861 "ip large-community-list expanded WORD <deny|permit> LINE...",
12862 IP_STR
12863 LCOMMUNITY_LIST_STR
12864 "Specify expanded large-community-list\n"
12865 "Large Community list name\n"
12866 "Specify large community to reject\n"
12867 "Specify large community to accept\n"
12868 "An ordered list as a regular-expression\n")
12869{
d62a17ae 12870 return lcommunity_list_set_vty(vty, argc, argv,
12871 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
12872}
12873
12874DEFUN (no_ip_lcommunity_list_standard_all,
12875 no_ip_lcommunity_list_standard_all_cmd,
12876 "no ip large-community-list <(1-99)|(100-500)|WORD>",
12877 NO_STR
12878 IP_STR
12879 LCOMMUNITY_LIST_STR
12880 "Large Community list number (standard)\n"
12881 "Large Community list number (expanded)\n"
12882 "Large Community list name\n")
12883{
d62a17ae 12884 return lcommunity_list_unset_vty(vty, argc, argv,
12885 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12886}
12887
12888DEFUN (no_ip_lcommunity_list_name_expanded_all,
12889 no_ip_lcommunity_list_name_expanded_all_cmd,
12890 "no ip large-community-list expanded WORD",
12891 NO_STR
12892 IP_STR
12893 LCOMMUNITY_LIST_STR
12894 "Specify expanded large-community-list\n"
12895 "Large Community list name\n")
12896{
d62a17ae 12897 return lcommunity_list_unset_vty(vty, argc, argv,
12898 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12899}
12900
12901DEFUN (no_ip_lcommunity_list_standard,
12902 no_ip_lcommunity_list_standard_cmd,
12903 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
12904 NO_STR
12905 IP_STR
12906 LCOMMUNITY_LIST_STR
12907 "Large Community list number (standard)\n"
12908 "Specify large community to reject\n"
12909 "Specify large community to accept\n"
12910 LCOMMUNITY_VAL_STR)
12911{
d62a17ae 12912 return lcommunity_list_unset_vty(vty, argc, argv,
12913 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12914}
12915
12916DEFUN (no_ip_lcommunity_list_expanded,
12917 no_ip_lcommunity_list_expanded_cmd,
12918 "no ip large-community-list (100-500) <deny|permit> LINE...",
12919 NO_STR
12920 IP_STR
12921 LCOMMUNITY_LIST_STR
12922 "Large Community list number (expanded)\n"
12923 "Specify large community to reject\n"
12924 "Specify large community to accept\n"
12925 "An ordered list as a regular-expression\n")
12926{
d62a17ae 12927 return lcommunity_list_unset_vty(vty, argc, argv,
12928 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12929}
12930
12931DEFUN (no_ip_lcommunity_list_name_standard,
12932 no_ip_lcommunity_list_name_standard_cmd,
12933 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
12934 NO_STR
12935 IP_STR
12936 LCOMMUNITY_LIST_STR
12937 "Specify standard large-community-list\n"
12938 "Large Community list name\n"
12939 "Specify large community to reject\n"
12940 "Specify large community to accept\n"
12941 LCOMMUNITY_VAL_STR)
12942{
d62a17ae 12943 return lcommunity_list_unset_vty(vty, argc, argv,
12944 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12945}
12946
12947DEFUN (no_ip_lcommunity_list_name_expanded,
12948 no_ip_lcommunity_list_name_expanded_cmd,
12949 "no ip large-community-list expanded WORD <deny|permit> LINE...",
12950 NO_STR
12951 IP_STR
12952 LCOMMUNITY_LIST_STR
12953 "Specify expanded large-community-list\n"
12954 "Large community list name\n"
12955 "Specify large community to reject\n"
12956 "Specify large community to accept\n"
12957 "An ordered list as a regular-expression\n")
12958{
d62a17ae 12959 return lcommunity_list_unset_vty(vty, argc, argv,
12960 LARGE_COMMUNITY_LIST_EXPANDED);
12961}
12962
12963static void lcommunity_list_show(struct vty *vty, struct community_list *list)
12964{
12965 struct community_entry *entry;
12966
12967 for (entry = list->head; entry; entry = entry->next) {
12968 if (entry == list->head) {
12969 if (all_digit(list->name))
12970 vty_out(vty, "Large community %s list %s\n",
12971 entry->style == EXTCOMMUNITY_LIST_STANDARD
12972 ? "standard"
12973 : "(expanded) access",
12974 list->name);
12975 else
12976 vty_out(vty,
12977 "Named large community %s list %s\n",
12978 entry->style == EXTCOMMUNITY_LIST_STANDARD
12979 ? "standard"
12980 : "expanded",
12981 list->name);
12982 }
12983 if (entry->any)
12984 vty_out(vty, " %s\n",
12985 community_direct_str(entry->direct));
12986 else
12987 vty_out(vty, " %s %s\n",
12988 community_direct_str(entry->direct),
12989 entry->style == EXTCOMMUNITY_LIST_STANDARD
12990 ? entry->u.ecom->str
12991 : entry->config);
12992 }
57d187bc
JS
12993}
12994
12995DEFUN (show_ip_lcommunity_list,
12996 show_ip_lcommunity_list_cmd,
12997 "show ip large-community-list",
12998 SHOW_STR
12999 IP_STR
13000 "List large-community list\n")
13001{
d62a17ae 13002 struct community_list *list;
13003 struct community_list_master *cm;
57d187bc 13004
d62a17ae 13005 cm = community_list_master_lookup(bgp_clist,
13006 LARGE_COMMUNITY_LIST_MASTER);
13007 if (!cm)
13008 return CMD_SUCCESS;
57d187bc 13009
d62a17ae 13010 for (list = cm->num.head; list; list = list->next)
13011 lcommunity_list_show(vty, list);
57d187bc 13012
d62a17ae 13013 for (list = cm->str.head; list; list = list->next)
13014 lcommunity_list_show(vty, list);
57d187bc 13015
d62a17ae 13016 return CMD_SUCCESS;
57d187bc
JS
13017}
13018
13019DEFUN (show_ip_lcommunity_list_arg,
13020 show_ip_lcommunity_list_arg_cmd,
13021 "show ip large-community-list <(1-500)|WORD>",
13022 SHOW_STR
13023 IP_STR
13024 "List large-community list\n"
13025 "large-community-list number\n"
13026 "large-community-list name\n")
13027{
d62a17ae 13028 struct community_list *list;
57d187bc 13029
d62a17ae 13030 list = community_list_lookup(bgp_clist, argv[3]->arg,
13031 LARGE_COMMUNITY_LIST_MASTER);
13032 if (!list) {
13033 vty_out(vty, "%% Can't find extcommunity-list\n");
13034 return CMD_WARNING;
13035 }
57d187bc 13036
d62a17ae 13037 lcommunity_list_show(vty, list);
57d187bc 13038
d62a17ae 13039 return CMD_SUCCESS;
57d187bc
JS
13040}
13041
718e3744 13042/* "extcommunity-list" keyword help string. */
13043#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13044#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13045
13046DEFUN (ip_extcommunity_list_standard,
13047 ip_extcommunity_list_standard_cmd,
e961923c 13048 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13049 IP_STR
13050 EXTCOMMUNITY_LIST_STR
13051 "Extended Community list number (standard)\n"
718e3744 13052 "Specify standard extcommunity-list\n"
5bf15956 13053 "Community list name\n"
718e3744 13054 "Specify community to reject\n"
13055 "Specify community to accept\n"
13056 EXTCOMMUNITY_VAL_STR)
13057{
d62a17ae 13058 int style = EXTCOMMUNITY_LIST_STANDARD;
13059 int direct = 0;
13060 char *cl_number_or_name = NULL;
42f914d4 13061
d62a17ae 13062 int idx = 0;
13063 argv_find(argv, argc, "(1-99)", &idx);
13064 argv_find(argv, argc, "WORD", &idx);
13065 cl_number_or_name = argv[idx]->arg;
13066 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13067 : COMMUNITY_DENY;
13068 argv_find(argv, argc, "AA:NN", &idx);
13069 char *str = argv_concat(argv, argc, idx);
42f914d4 13070
d62a17ae 13071 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13072 direct, style);
42f914d4 13073
d62a17ae 13074 XFREE(MTYPE_TMP, str);
42f914d4 13075
d62a17ae 13076 if (ret < 0) {
13077 community_list_perror(vty, ret);
13078 return CMD_WARNING_CONFIG_FAILED;
13079 }
42f914d4 13080
d62a17ae 13081 return CMD_SUCCESS;
718e3744 13082}
13083
718e3744 13084DEFUN (ip_extcommunity_list_name_expanded,
13085 ip_extcommunity_list_name_expanded_cmd,
e961923c 13086 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13087 IP_STR
13088 EXTCOMMUNITY_LIST_STR
5bf15956 13089 "Extended Community list number (expanded)\n"
718e3744 13090 "Specify expanded extcommunity-list\n"
13091 "Extended Community list name\n"
13092 "Specify community to reject\n"
13093 "Specify community to accept\n"
13094 "An ordered list as a regular-expression\n")
13095{
d62a17ae 13096 int style = EXTCOMMUNITY_LIST_EXPANDED;
13097 int direct = 0;
13098 char *cl_number_or_name = NULL;
42f914d4 13099
d62a17ae 13100 int idx = 0;
13101 argv_find(argv, argc, "(100-500)", &idx);
13102 argv_find(argv, argc, "WORD", &idx);
13103 cl_number_or_name = argv[idx]->arg;
13104 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13105 : COMMUNITY_DENY;
13106 argv_find(argv, argc, "LINE", &idx);
13107 char *str = argv_concat(argv, argc, idx);
42f914d4 13108
d62a17ae 13109 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13110 direct, style);
42f914d4 13111
d62a17ae 13112 XFREE(MTYPE_TMP, str);
42f914d4 13113
d62a17ae 13114 if (ret < 0) {
13115 community_list_perror(vty, ret);
13116 return CMD_WARNING_CONFIG_FAILED;
13117 }
42f914d4 13118
d62a17ae 13119 return CMD_SUCCESS;
718e3744 13120}
13121
fee6e4e4 13122DEFUN (no_ip_extcommunity_list_standard_all,
13123 no_ip_extcommunity_list_standard_all_cmd,
e961923c 13124 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
13125 NO_STR
13126 IP_STR
13127 EXTCOMMUNITY_LIST_STR
13128 "Extended Community list number (standard)\n"
718e3744 13129 "Specify standard extcommunity-list\n"
5bf15956 13130 "Community list name\n"
718e3744 13131 "Specify community to reject\n"
13132 "Specify community to accept\n"
13133 EXTCOMMUNITY_VAL_STR)
13134{
d62a17ae 13135 int deleteall = 0;
42f914d4 13136
d62a17ae 13137 int style = EXTCOMMUNITY_LIST_STANDARD;
13138 int direct = 0;
13139 char *cl_number_or_name = NULL;
42f914d4 13140
d62a17ae 13141 int idx = 0;
13142 argv_find(argv, argc, "(1-99)", &idx);
13143 argv_find(argv, argc, "WORD", &idx);
13144 cl_number_or_name = argv[idx]->arg;
13145 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13146 : COMMUNITY_DENY;
13147 argv_find(argv, argc, "AA:NN", &idx);
13148 char *str = argv_concat(argv, argc, idx);
42f914d4 13149
d62a17ae 13150 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13151 direct, style, deleteall);
42f914d4 13152
d62a17ae 13153 XFREE(MTYPE_TMP, str);
42f914d4 13154
d62a17ae 13155 if (ret < 0) {
13156 community_list_perror(vty, ret);
13157 return CMD_WARNING_CONFIG_FAILED;
13158 }
42f914d4 13159
d62a17ae 13160 return CMD_SUCCESS;
718e3744 13161}
13162
5bf15956
DW
13163DEFUN (no_ip_extcommunity_list_expanded_all,
13164 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 13165 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13166 NO_STR
13167 IP_STR
13168 EXTCOMMUNITY_LIST_STR
13169 "Extended Community list number (expanded)\n"
718e3744 13170 "Specify expanded extcommunity-list\n"
5bf15956 13171 "Extended Community list name\n"
718e3744 13172 "Specify community to reject\n"
13173 "Specify community to accept\n"
13174 "An ordered list as a regular-expression\n")
13175{
d62a17ae 13176 int deleteall = 0;
42f914d4 13177
d62a17ae 13178 int style = EXTCOMMUNITY_LIST_EXPANDED;
13179 int direct = 0;
13180 char *cl_number_or_name = NULL;
42f914d4 13181
d62a17ae 13182 int idx = 0;
13183 argv_find(argv, argc, "(100-500)", &idx);
13184 argv_find(argv, argc, "WORD", &idx);
13185 cl_number_or_name = argv[idx]->arg;
13186 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13187 : COMMUNITY_DENY;
13188 argv_find(argv, argc, "LINE", &idx);
13189 char *str = argv_concat(argv, argc, idx);
42f914d4 13190
d62a17ae 13191 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13192 direct, style, deleteall);
42f914d4 13193
d62a17ae 13194 XFREE(MTYPE_TMP, str);
42f914d4 13195
d62a17ae 13196 if (ret < 0) {
13197 community_list_perror(vty, ret);
13198 return CMD_WARNING_CONFIG_FAILED;
13199 }
42f914d4 13200
d62a17ae 13201 return CMD_SUCCESS;
718e3744 13202}
13203
d62a17ae 13204static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 13205{
d62a17ae 13206 struct community_entry *entry;
718e3744 13207
d62a17ae 13208 for (entry = list->head; entry; entry = entry->next) {
13209 if (entry == list->head) {
13210 if (all_digit(list->name))
13211 vty_out(vty, "Extended community %s list %s\n",
13212 entry->style == EXTCOMMUNITY_LIST_STANDARD
13213 ? "standard"
13214 : "(expanded) access",
13215 list->name);
13216 else
13217 vty_out(vty,
13218 "Named extended community %s list %s\n",
13219 entry->style == EXTCOMMUNITY_LIST_STANDARD
13220 ? "standard"
13221 : "expanded",
13222 list->name);
13223 }
13224 if (entry->any)
13225 vty_out(vty, " %s\n",
13226 community_direct_str(entry->direct));
13227 else
13228 vty_out(vty, " %s %s\n",
13229 community_direct_str(entry->direct),
13230 entry->style == EXTCOMMUNITY_LIST_STANDARD
13231 ? entry->u.ecom->str
13232 : entry->config);
13233 }
718e3744 13234}
13235
13236DEFUN (show_ip_extcommunity_list,
13237 show_ip_extcommunity_list_cmd,
13238 "show ip extcommunity-list",
13239 SHOW_STR
13240 IP_STR
13241 "List extended-community list\n")
13242{
d62a17ae 13243 struct community_list *list;
13244 struct community_list_master *cm;
718e3744 13245
d62a17ae 13246 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13247 if (!cm)
13248 return CMD_SUCCESS;
718e3744 13249
d62a17ae 13250 for (list = cm->num.head; list; list = list->next)
13251 extcommunity_list_show(vty, list);
718e3744 13252
d62a17ae 13253 for (list = cm->str.head; list; list = list->next)
13254 extcommunity_list_show(vty, list);
718e3744 13255
d62a17ae 13256 return CMD_SUCCESS;
718e3744 13257}
13258
13259DEFUN (show_ip_extcommunity_list_arg,
13260 show_ip_extcommunity_list_arg_cmd,
6147e2c6 13261 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 13262 SHOW_STR
13263 IP_STR
13264 "List extended-community list\n"
13265 "Extcommunity-list number\n"
13266 "Extcommunity-list name\n")
13267{
d62a17ae 13268 int idx_comm_list = 3;
13269 struct community_list *list;
718e3744 13270
d62a17ae 13271 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13272 EXTCOMMUNITY_LIST_MASTER);
13273 if (!list) {
13274 vty_out(vty, "%% Can't find extcommunity-list\n");
13275 return CMD_WARNING;
13276 }
718e3744 13277
d62a17ae 13278 extcommunity_list_show(vty, list);
718e3744 13279
d62a17ae 13280 return CMD_SUCCESS;
718e3744 13281}
6b0655a2 13282
718e3744 13283/* Return configuration string of community-list entry. */
d62a17ae 13284static const char *community_list_config_str(struct community_entry *entry)
718e3744 13285{
d62a17ae 13286 const char *str;
718e3744 13287
d62a17ae 13288 if (entry->any)
13289 str = "";
13290 else {
13291 if (entry->style == COMMUNITY_LIST_STANDARD)
13292 str = community_str(entry->u.com);
13293 else
13294 str = entry->config;
13295 }
13296 return str;
718e3744 13297}
13298
13299/* Display community-list and extcommunity-list configuration. */
d62a17ae 13300static int community_list_config_write(struct vty *vty)
13301{
13302 struct community_list *list;
13303 struct community_entry *entry;
13304 struct community_list_master *cm;
13305 int write = 0;
13306
13307 /* Community-list. */
13308 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13309
13310 for (list = cm->num.head; list; list = list->next)
13311 for (entry = list->head; entry; entry = entry->next) {
13312 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13313 community_direct_str(entry->direct),
13314 community_list_config_str(entry));
13315 write++;
13316 }
13317 for (list = cm->str.head; list; list = list->next)
13318 for (entry = list->head; entry; entry = entry->next) {
13319 vty_out(vty, "ip community-list %s %s %s %s\n",
13320 entry->style == COMMUNITY_LIST_STANDARD
13321 ? "standard"
13322 : "expanded",
13323 list->name, community_direct_str(entry->direct),
13324 community_list_config_str(entry));
13325 write++;
13326 }
13327
13328 /* Extcommunity-list. */
13329 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13330
13331 for (list = cm->num.head; list; list = list->next)
13332 for (entry = list->head; entry; entry = entry->next) {
13333 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13334 list->name, community_direct_str(entry->direct),
13335 community_list_config_str(entry));
13336 write++;
13337 }
13338 for (list = cm->str.head; list; list = list->next)
13339 for (entry = list->head; entry; entry = entry->next) {
13340 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13341 entry->style == EXTCOMMUNITY_LIST_STANDARD
13342 ? "standard"
13343 : "expanded",
13344 list->name, community_direct_str(entry->direct),
13345 community_list_config_str(entry));
13346 write++;
13347 }
13348
13349
13350 /* lcommunity-list. */
13351 cm = community_list_master_lookup(bgp_clist,
13352 LARGE_COMMUNITY_LIST_MASTER);
13353
13354 for (list = cm->num.head; list; list = list->next)
13355 for (entry = list->head; entry; entry = entry->next) {
13356 vty_out(vty, "ip large-community-list %s %s %s\n",
13357 list->name, community_direct_str(entry->direct),
13358 community_list_config_str(entry));
13359 write++;
13360 }
13361 for (list = cm->str.head; list; list = list->next)
13362 for (entry = list->head; entry; entry = entry->next) {
13363 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13364 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13365 ? "standard"
13366 : "expanded",
13367 list->name, community_direct_str(entry->direct),
13368 community_list_config_str(entry));
13369 write++;
13370 }
13371
13372 return write;
13373}
13374
13375static struct cmd_node community_list_node = {
13376 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 13377};
13378
d62a17ae 13379static void community_list_vty(void)
13380{
13381 install_node(&community_list_node, community_list_config_write);
13382
13383 /* Community-list. */
13384 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13385 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13386 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13387 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13388 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13389 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13390
13391 /* Extcommunity-list. */
13392 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13393 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13394 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13395 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13396 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13397 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13398
13399 /* Large Community List */
13400 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13401 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13402 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13403 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13404 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13405 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13406 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13407 install_element(CONFIG_NODE,
13408 &no_ip_lcommunity_list_name_expanded_all_cmd);
13409 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13410 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13411 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13412 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13413 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13414 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 13415}