]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: use macro HAVE_STRUCT_UTSNAME_DOMAINNAME to avoid compilation failures
[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{
dff8f48d
MK
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;
d62a17ae 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
dff8f48d
MK
7605 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
7606 if (p->bgp->advertise_all_vni)
7607 json_object_boolean_true_add(json_addr,
7608 "advertiseAllVnis");
7609 }
7610
d62a17ae 7611 if (filter->plist[FILTER_IN].name
7612 || filter->dlist[FILTER_IN].name
7613 || filter->aslist[FILTER_IN].name
7614 || filter->map[RMAP_IN].name)
7615 json_object_boolean_true_add(json_addr,
7616 "inboundPathPolicyConfig");
7617 if (filter->plist[FILTER_OUT].name
7618 || filter->dlist[FILTER_OUT].name
7619 || filter->aslist[FILTER_OUT].name
7620 || filter->map[RMAP_OUT].name || filter->usmap.name)
7621 json_object_boolean_true_add(
7622 json_addr, "outboundPathPolicyConfig");
7623
7624 /* prefix-list */
7625 if (filter->plist[FILTER_IN].name)
7626 json_object_string_add(json_addr,
7627 "incomingUpdatePrefixFilterList",
7628 filter->plist[FILTER_IN].name);
7629 if (filter->plist[FILTER_OUT].name)
7630 json_object_string_add(json_addr,
7631 "outgoingUpdatePrefixFilterList",
7632 filter->plist[FILTER_OUT].name);
7633
7634 /* distribute-list */
7635 if (filter->dlist[FILTER_IN].name)
7636 json_object_string_add(
7637 json_addr, "incomingUpdateNetworkFilterList",
7638 filter->dlist[FILTER_IN].name);
7639 if (filter->dlist[FILTER_OUT].name)
7640 json_object_string_add(
7641 json_addr, "outgoingUpdateNetworkFilterList",
7642 filter->dlist[FILTER_OUT].name);
7643
7644 /* filter-list. */
7645 if (filter->aslist[FILTER_IN].name)
7646 json_object_string_add(json_addr,
7647 "incomingUpdateAsPathFilterList",
7648 filter->aslist[FILTER_IN].name);
7649 if (filter->aslist[FILTER_OUT].name)
7650 json_object_string_add(json_addr,
7651 "outgoingUpdateAsPathFilterList",
7652 filter->aslist[FILTER_OUT].name);
7653
7654 /* route-map. */
7655 if (filter->map[RMAP_IN].name)
7656 json_object_string_add(
7657 json_addr, "routeMapForIncomingAdvertisements",
7658 filter->map[RMAP_IN].name);
7659 if (filter->map[RMAP_OUT].name)
7660 json_object_string_add(
7661 json_addr, "routeMapForOutgoingAdvertisements",
7662 filter->map[RMAP_OUT].name);
7663
7664 /* unsuppress-map */
7665 if (filter->usmap.name)
7666 json_object_string_add(json_addr,
7667 "selectiveUnsuppressRouteMap",
7668 filter->usmap.name);
7669
7670 /* Receive prefix count */
7671 json_object_int_add(json_addr, "acceptedPrefixCounter",
7672 p->pcount[afi][safi]);
7673
7674 /* Maximum prefix */
7675 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7676 json_object_int_add(json_addr, "prefixAllowedMax",
7677 p->pmax[afi][safi]);
7678 if (CHECK_FLAG(p->af_flags[afi][safi],
7679 PEER_FLAG_MAX_PREFIX_WARNING))
7680 json_object_boolean_true_add(
7681 json_addr, "prefixAllowedMaxWarning");
7682 json_object_int_add(json_addr,
7683 "prefixAllowedWarningThresh",
7684 p->pmax_threshold[afi][safi]);
7685 if (p->pmax_restart[afi][safi])
7686 json_object_int_add(
7687 json_addr,
7688 "prefixAllowedRestartIntervalMsecs",
7689 p->pmax_restart[afi][safi] * 60000);
7690 }
7691 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
7692 json_addr);
7693
7694 } else {
7695 filter = &p->filter[afi][safi];
7696
7697 vty_out(vty, " For address family: %s\n",
7698 afi_safi_print(afi, safi));
7699
7700 if (peer_group_active(p))
7701 vty_out(vty, " %s peer-group member\n",
7702 p->group->name);
7703
7704 paf = peer_af_find(p, afi, safi);
7705 if (paf && PAF_SUBGRP(paf)) {
9d303b37
DL
7706 vty_out(vty, " Update group %" PRIu64
7707 ", subgroup %" PRIu64 "\n",
d62a17ae 7708 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
7709 vty_out(vty, " Packet Queue length %d\n",
7710 bpacket_queue_virtual_length(paf));
7711 } else {
7712 vty_out(vty, " Not part of any update group\n");
7713 }
7714 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7715 || CHECK_FLAG(p->af_cap[afi][safi],
7716 PEER_CAP_ORF_PREFIX_SM_RCV)
7717 || CHECK_FLAG(p->af_cap[afi][safi],
7718 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7719 || CHECK_FLAG(p->af_cap[afi][safi],
7720 PEER_CAP_ORF_PREFIX_RM_ADV)
7721 || CHECK_FLAG(p->af_cap[afi][safi],
7722 PEER_CAP_ORF_PREFIX_RM_RCV)
7723 || CHECK_FLAG(p->af_cap[afi][safi],
7724 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7725 vty_out(vty, " AF-dependant capabilities:\n");
7726
7727 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7728 || CHECK_FLAG(p->af_cap[afi][safi],
7729 PEER_CAP_ORF_PREFIX_SM_RCV)
7730 || CHECK_FLAG(p->af_cap[afi][safi],
7731 PEER_CAP_ORF_PREFIX_RM_ADV)
7732 || CHECK_FLAG(p->af_cap[afi][safi],
7733 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7734 vty_out(vty,
7735 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7736 ORF_TYPE_PREFIX);
7737 bgp_show_peer_afi_orf_cap(
7738 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7739 PEER_CAP_ORF_PREFIX_RM_ADV,
7740 PEER_CAP_ORF_PREFIX_SM_RCV,
7741 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7742 }
7743 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7744 || CHECK_FLAG(p->af_cap[afi][safi],
7745 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7746 || CHECK_FLAG(p->af_cap[afi][safi],
7747 PEER_CAP_ORF_PREFIX_RM_ADV)
7748 || CHECK_FLAG(p->af_cap[afi][safi],
7749 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7750 vty_out(vty,
7751 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7752 ORF_TYPE_PREFIX_OLD);
7753 bgp_show_peer_afi_orf_cap(
7754 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7755 PEER_CAP_ORF_PREFIX_RM_ADV,
7756 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7757 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7758 }
7759
7760 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7761 orf_pfx_count = prefix_bgp_show_prefix_list(
7762 NULL, afi, orf_pfx_name, use_json);
7763
7764 if (CHECK_FLAG(p->af_sflags[afi][safi],
7765 PEER_STATUS_ORF_PREFIX_SEND)
7766 || orf_pfx_count) {
7767 vty_out(vty, " Outbound Route Filter (ORF):");
7768 if (CHECK_FLAG(p->af_sflags[afi][safi],
7769 PEER_STATUS_ORF_PREFIX_SEND))
7770 vty_out(vty, " sent;");
7771 if (orf_pfx_count)
7772 vty_out(vty, " received (%d entries)",
7773 orf_pfx_count);
7774 vty_out(vty, "\n");
7775 }
7776 if (CHECK_FLAG(p->af_sflags[afi][safi],
7777 PEER_STATUS_ORF_WAIT_REFRESH))
7778 vty_out(vty,
7779 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
7780
7781 if (CHECK_FLAG(p->af_flags[afi][safi],
7782 PEER_FLAG_REFLECTOR_CLIENT))
7783 vty_out(vty, " Route-Reflector Client\n");
7784 if (CHECK_FLAG(p->af_flags[afi][safi],
7785 PEER_FLAG_RSERVER_CLIENT))
7786 vty_out(vty, " Route-Server Client\n");
7787 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7788 vty_out(vty,
7789 " Inbound soft reconfiguration allowed\n");
7790
7791 if (CHECK_FLAG(p->af_flags[afi][safi],
7792 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7793 vty_out(vty,
7794 " Private AS numbers (all) replaced in updates to this neighbor\n");
7795 else if (CHECK_FLAG(p->af_flags[afi][safi],
7796 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7797 vty_out(vty,
7798 " Private AS numbers replaced in updates to this neighbor\n");
7799 else if (CHECK_FLAG(p->af_flags[afi][safi],
7800 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7801 vty_out(vty,
7802 " Private AS numbers (all) removed in updates to this neighbor\n");
7803 else if (CHECK_FLAG(p->af_flags[afi][safi],
7804 PEER_FLAG_REMOVE_PRIVATE_AS))
7805 vty_out(vty,
7806 " Private AS numbers removed in updates to this neighbor\n");
7807
7808 if (CHECK_FLAG(p->af_flags[afi][safi],
7809 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7810 vty_out(vty, " Advertise all paths via addpath\n");
7811
7812 if (CHECK_FLAG(p->af_flags[afi][safi],
7813 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7814 vty_out(vty,
7815 " Advertise bestpath per AS via addpath\n");
7816
7817 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7818 vty_out(vty,
7819 " Override ASNs in outbound updates if aspath equals remote-as\n");
7820
7821 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7822 || CHECK_FLAG(p->af_flags[afi][safi],
7823 PEER_FLAG_FORCE_NEXTHOP_SELF))
7824 vty_out(vty, " NEXT_HOP is always this router\n");
7825 if (CHECK_FLAG(p->af_flags[afi][safi],
7826 PEER_FLAG_AS_PATH_UNCHANGED))
7827 vty_out(vty,
7828 " AS_PATH is propagated unchanged to this neighbor\n");
7829 if (CHECK_FLAG(p->af_flags[afi][safi],
7830 PEER_FLAG_NEXTHOP_UNCHANGED))
7831 vty_out(vty,
7832 " NEXT_HOP is propagated unchanged to this neighbor\n");
7833 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7834 vty_out(vty,
7835 " MED is propagated unchanged to this neighbor\n");
7836 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7837 || CHECK_FLAG(p->af_flags[afi][safi],
7838 PEER_FLAG_SEND_EXT_COMMUNITY)
7839 || CHECK_FLAG(p->af_flags[afi][safi],
7840 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
7841 vty_out(vty,
7842 " Community attribute sent to this neighbor");
7843 if (CHECK_FLAG(p->af_flags[afi][safi],
7844 PEER_FLAG_SEND_COMMUNITY)
7845 && CHECK_FLAG(p->af_flags[afi][safi],
7846 PEER_FLAG_SEND_EXT_COMMUNITY)
7847 && CHECK_FLAG(p->af_flags[afi][safi],
7848 PEER_FLAG_SEND_LARGE_COMMUNITY))
7849 vty_out(vty, "(all)\n");
7850 else if (CHECK_FLAG(p->af_flags[afi][safi],
7851 PEER_FLAG_SEND_LARGE_COMMUNITY))
7852 vty_out(vty, "(large)\n");
7853 else if (CHECK_FLAG(p->af_flags[afi][safi],
7854 PEER_FLAG_SEND_EXT_COMMUNITY))
7855 vty_out(vty, "(extended)\n");
7856 else
7857 vty_out(vty, "(standard)\n");
7858 }
7859 if (CHECK_FLAG(p->af_flags[afi][safi],
7860 PEER_FLAG_DEFAULT_ORIGINATE)) {
7861 vty_out(vty, " Default information originate,");
7862
7863 if (p->default_rmap[afi][safi].name)
7864 vty_out(vty, " default route-map %s%s,",
7865 p->default_rmap[afi][safi].map ? "*"
7866 : "",
7867 p->default_rmap[afi][safi].name);
7868 if (paf && PAF_SUBGRP(paf)
7869 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7870 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7871 vty_out(vty, " default sent\n");
7872 else
7873 vty_out(vty, " default not sent\n");
7874 }
7875
dff8f48d
MK
7876 /* advertise-vni-all */
7877 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
7878 if (p->bgp->advertise_all_vni)
7879 vty_out(vty, " advertise-all-vni\n");
7880 }
7881
d62a17ae 7882 if (filter->plist[FILTER_IN].name
7883 || filter->dlist[FILTER_IN].name
7884 || filter->aslist[FILTER_IN].name
7885 || filter->map[RMAP_IN].name)
7886 vty_out(vty, " Inbound path policy configured\n");
7887 if (filter->plist[FILTER_OUT].name
7888 || filter->dlist[FILTER_OUT].name
7889 || filter->aslist[FILTER_OUT].name
7890 || filter->map[RMAP_OUT].name || filter->usmap.name)
7891 vty_out(vty, " Outbound path policy configured\n");
7892
7893 /* prefix-list */
7894 if (filter->plist[FILTER_IN].name)
7895 vty_out(vty,
7896 " Incoming update prefix filter list is %s%s\n",
7897 filter->plist[FILTER_IN].plist ? "*" : "",
7898 filter->plist[FILTER_IN].name);
7899 if (filter->plist[FILTER_OUT].name)
7900 vty_out(vty,
7901 " Outgoing update prefix filter list is %s%s\n",
7902 filter->plist[FILTER_OUT].plist ? "*" : "",
7903 filter->plist[FILTER_OUT].name);
7904
7905 /* distribute-list */
7906 if (filter->dlist[FILTER_IN].name)
7907 vty_out(vty,
7908 " Incoming update network filter list is %s%s\n",
7909 filter->dlist[FILTER_IN].alist ? "*" : "",
7910 filter->dlist[FILTER_IN].name);
7911 if (filter->dlist[FILTER_OUT].name)
7912 vty_out(vty,
7913 " Outgoing update network filter list is %s%s\n",
7914 filter->dlist[FILTER_OUT].alist ? "*" : "",
7915 filter->dlist[FILTER_OUT].name);
7916
7917 /* filter-list. */
7918 if (filter->aslist[FILTER_IN].name)
7919 vty_out(vty,
7920 " Incoming update AS path filter list is %s%s\n",
7921 filter->aslist[FILTER_IN].aslist ? "*" : "",
7922 filter->aslist[FILTER_IN].name);
7923 if (filter->aslist[FILTER_OUT].name)
7924 vty_out(vty,
7925 " Outgoing update AS path filter list is %s%s\n",
7926 filter->aslist[FILTER_OUT].aslist ? "*" : "",
7927 filter->aslist[FILTER_OUT].name);
7928
7929 /* route-map. */
7930 if (filter->map[RMAP_IN].name)
7931 vty_out(vty,
7932 " Route map for incoming advertisements is %s%s\n",
7933 filter->map[RMAP_IN].map ? "*" : "",
7934 filter->map[RMAP_IN].name);
7935 if (filter->map[RMAP_OUT].name)
7936 vty_out(vty,
7937 " Route map for outgoing advertisements is %s%s\n",
7938 filter->map[RMAP_OUT].map ? "*" : "",
7939 filter->map[RMAP_OUT].name);
7940
7941 /* unsuppress-map */
7942 if (filter->usmap.name)
7943 vty_out(vty,
7944 " Route map for selective unsuppress is %s%s\n",
7945 filter->usmap.map ? "*" : "",
7946 filter->usmap.name);
7947
7948 /* Receive prefix count */
7949 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
7950
7951 /* Maximum prefix */
7952 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7953 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
7954 p->pmax[afi][safi],
7955 CHECK_FLAG(p->af_flags[afi][safi],
7956 PEER_FLAG_MAX_PREFIX_WARNING)
7957 ? " (warning-only)"
7958 : "");
7959 vty_out(vty, " Threshold for warning message %d%%",
7960 p->pmax_threshold[afi][safi]);
7961 if (p->pmax_restart[afi][safi])
7962 vty_out(vty, ", restart interval %d min",
7963 p->pmax_restart[afi][safi]);
7964 vty_out(vty, "\n");
7965 }
7966
7967 vty_out(vty, "\n");
7968 }
7969}
7970
7971static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
7972 json_object *json)
718e3744 7973{
d62a17ae 7974 struct bgp *bgp;
7975 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
7976 char timebuf[BGP_UPTIME_LEN];
7977 char dn_flag[2];
7978 const char *subcode_str;
7979 const char *code_str;
7980 afi_t afi;
7981 safi_t safi;
7982 u_int16_t i;
7983 u_char *msg;
7984 json_object *json_neigh = NULL;
7985 time_t epoch_tbuf;
718e3744 7986
d62a17ae 7987 bgp = p->bgp;
7988
7989 if (use_json)
7990 json_neigh = json_object_new_object();
7991
7992 memset(dn_flag, '\0', sizeof(dn_flag));
7993 if (!p->conf_if && peer_dynamic_neighbor(p))
7994 dn_flag[0] = '*';
7995
7996 if (!use_json) {
7997 if (p->conf_if) /* Configured interface name. */
7998 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
7999 BGP_PEER_SU_UNSPEC(p)
8000 ? "None"
8001 : sockunion2str(&p->su, buf,
8002 SU_ADDRSTRLEN));
8003 else /* Configured IP address. */
8004 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8005 p->host);
8006 }
8007
8008 if (use_json) {
8009 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8010 json_object_string_add(json_neigh, "bgpNeighborAddr",
8011 "none");
8012 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8013 json_object_string_add(
8014 json_neigh, "bgpNeighborAddr",
8015 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8016
8017 json_object_int_add(json_neigh, "remoteAs", p->as);
8018
8019 if (p->change_local_as)
8020 json_object_int_add(json_neigh, "localAs",
8021 p->change_local_as);
8022 else
8023 json_object_int_add(json_neigh, "localAs", p->local_as);
8024
8025 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8026 json_object_boolean_true_add(json_neigh,
8027 "localAsNoPrepend");
8028
8029 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8030 json_object_boolean_true_add(json_neigh,
8031 "localAsReplaceAs");
8032 } else {
8033 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8034 || (p->as_type == AS_INTERNAL))
8035 vty_out(vty, "remote AS %u, ", p->as);
8036 else
8037 vty_out(vty, "remote AS Unspecified, ");
8038 vty_out(vty, "local AS %u%s%s, ",
8039 p->change_local_as ? p->change_local_as : p->local_as,
8040 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8041 ? " no-prepend"
8042 : "",
8043 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8044 ? " replace-as"
8045 : "");
8046 }
8047 /* peer type internal, external, confed-internal or confed-external */
8048 if (p->as == p->local_as) {
8049 if (use_json) {
8050 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8051 json_object_boolean_true_add(
8052 json_neigh, "nbrConfedInternalLink");
8053 else
8054 json_object_boolean_true_add(json_neigh,
8055 "nbrInternalLink");
8056 } else {
8057 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8058 vty_out(vty, "confed-internal link\n");
8059 else
8060 vty_out(vty, "internal link\n");
8061 }
8062 } else {
8063 if (use_json) {
8064 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8065 json_object_boolean_true_add(
8066 json_neigh, "nbrConfedExternalLink");
8067 else
8068 json_object_boolean_true_add(json_neigh,
8069 "nbrExternalLink");
8070 } else {
8071 if (bgp_confederation_peers_check(bgp, p->as))
8072 vty_out(vty, "confed-external link\n");
8073 else
8074 vty_out(vty, "external link\n");
8075 }
8076 }
8077
8078 /* Description. */
8079 if (p->desc) {
8080 if (use_json)
8081 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8082 else
8083 vty_out(vty, " Description: %s\n", p->desc);
8084 }
8085
8086 if (p->hostname) {
8087 if (use_json) {
8088 if (p->hostname)
8089 json_object_string_add(json_neigh, "hostname",
8090 p->hostname);
8091
8092 if (p->domainname)
8093 json_object_string_add(json_neigh, "domainname",
8094 p->domainname);
8095 } else {
8096 if (p->domainname && (p->domainname[0] != '\0'))
8097 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8098 p->domainname);
8099 else
8100 vty_out(vty, "Hostname: %s\n", p->hostname);
8101 }
8102 }
8103
8104 /* Peer-group */
8105 if (p->group) {
8106 if (use_json) {
8107 json_object_string_add(json_neigh, "peerGroup",
8108 p->group->name);
8109
8110 if (dn_flag[0]) {
8111 struct prefix prefix, *range = NULL;
8112
8113 sockunion2hostprefix(&(p->su), &prefix);
8114 range = peer_group_lookup_dynamic_neighbor_range(
8115 p->group, &prefix);
8116
8117 if (range) {
8118 prefix2str(range, buf1, sizeof(buf1));
8119 json_object_string_add(
8120 json_neigh,
8121 "peerSubnetRangeGroup", buf1);
8122 }
8123 }
8124 } else {
8125 vty_out(vty,
8126 " Member of peer-group %s for session parameters\n",
8127 p->group->name);
8128
8129 if (dn_flag[0]) {
8130 struct prefix prefix, *range = NULL;
8131
8132 sockunion2hostprefix(&(p->su), &prefix);
8133 range = peer_group_lookup_dynamic_neighbor_range(
8134 p->group, &prefix);
8135
8136 if (range) {
8137 prefix2str(range, buf1, sizeof(buf1));
8138 vty_out(vty,
8139 " Belongs to the subnet range group: %s\n",
8140 buf1);
8141 }
8142 }
8143 }
8144 }
8145
8146 if (use_json) {
8147 /* Administrative shutdown. */
8148 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8149 json_object_boolean_true_add(json_neigh,
8150 "adminShutDown");
8151
8152 /* BGP Version. */
8153 json_object_int_add(json_neigh, "bgpVersion", 4);
8154 json_object_string_add(
8155 json_neigh, "remoteRouterId",
8156 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8157
8158 /* Confederation */
8159 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8160 && bgp_confederation_peers_check(bgp, p->as))
8161 json_object_boolean_true_add(json_neigh,
8162 "nbrCommonAdmin");
8163
8164 /* Status. */
8165 json_object_string_add(
8166 json_neigh, "bgpState",
8167 lookup_msg(bgp_status_msg, p->status, NULL));
8168
8169 if (p->status == Established) {
8170 time_t uptime;
8171 struct tm *tm;
8172
8173 uptime = bgp_clock();
8174 uptime -= p->uptime;
8175 tm = gmtime(&uptime);
8176 epoch_tbuf = time(NULL) - uptime;
8177
8178 json_object_int_add(json_neigh, "bgpTimerUp",
8179 (tm->tm_sec * 1000)
8180 + (tm->tm_min * 60000)
8181 + (tm->tm_hour * 3600000));
8182 json_object_string_add(json_neigh, "bgpTimerUpString",
8183 peer_uptime(p->uptime, timebuf,
8184 BGP_UPTIME_LEN, 0,
8185 NULL));
8186 json_object_int_add(json_neigh,
8187 "bgpTimerUpEstablishedEpoch",
8188 epoch_tbuf);
8189 }
8190
8191 else if (p->status == Active) {
8192 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8193 json_object_string_add(json_neigh, "bgpStateIs",
8194 "passive");
8195 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8196 json_object_string_add(json_neigh, "bgpStateIs",
8197 "passiveNSF");
8198 }
8199
8200 /* read timer */
8201 time_t uptime;
8202 struct tm *tm;
8203
8204 uptime = bgp_clock();
8205 uptime -= p->readtime;
8206 tm = gmtime(&uptime);
8207 json_object_int_add(json_neigh, "bgpTimerLastRead",
8208 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8209 + (tm->tm_hour * 3600000));
8210
8211 uptime = bgp_clock();
8212 uptime -= p->last_write;
8213 tm = gmtime(&uptime);
8214 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8215 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8216 + (tm->tm_hour * 3600000));
8217
8218 uptime = bgp_clock();
8219 uptime -= p->update_time;
8220 tm = gmtime(&uptime);
8221 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8222 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8223 + (tm->tm_hour * 3600000));
8224
8225 /* Configured timer values. */
8226 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8227 p->v_holdtime * 1000);
8228 json_object_int_add(json_neigh,
8229 "bgpTimerKeepAliveIntervalMsecs",
8230 p->v_keepalive * 1000);
8231
8232 if (CHECK_FLAG(p->config, PEER_CONFIG_TIMER)) {
8233 json_object_int_add(json_neigh,
8234 "bgpTimerConfiguredHoldTimeMsecs",
8235 p->holdtime * 1000);
8236 json_object_int_add(
8237 json_neigh,
8238 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8239 p->keepalive * 1000);
8240 }
8241 } else {
8242 /* Administrative shutdown. */
8243 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8244 vty_out(vty, " Administratively shut down\n");
8245
8246 /* BGP Version. */
8247 vty_out(vty, " BGP version 4");
8248 vty_out(vty, ", remote router ID %s\n",
8249 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8250
8251 /* Confederation */
8252 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8253 && bgp_confederation_peers_check(bgp, p->as))
8254 vty_out(vty,
8255 " Neighbor under common administration\n");
8256
8257 /* Status. */
8258 vty_out(vty, " BGP state = %s",
8259 lookup_msg(bgp_status_msg, p->status, NULL));
8260
8261 if (p->status == Established)
8262 vty_out(vty, ", up for %8s",
8263 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8264 0, NULL));
8265
8266 else if (p->status == Active) {
8267 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8268 vty_out(vty, " (passive)");
8269 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8270 vty_out(vty, " (NSF passive)");
8271 }
8272 vty_out(vty, "\n");
8273
8274 /* read timer */
8275 vty_out(vty, " Last read %s",
8276 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8277 NULL));
8278 vty_out(vty, ", Last write %s\n",
8279 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8280 NULL));
8281
8282 /* Configured timer values. */
8283 vty_out(vty,
8284 " Hold time is %d, keepalive interval is %d seconds\n",
8285 p->v_holdtime, p->v_keepalive);
8286 if (CHECK_FLAG(p->config, PEER_CONFIG_TIMER)) {
8287 vty_out(vty, " Configured hold time is %d",
8288 p->holdtime);
8289 vty_out(vty, ", keepalive interval is %d seconds\n",
8290 p->keepalive);
8291 }
8292 }
8293 /* Capability. */
8294 if (p->status == Established) {
8295 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8296 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8297 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8298 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8299 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8300 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8301 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8302 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8303 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8304 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8305 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8306 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8307 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8308 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8309 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8310 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8311 if (use_json) {
8312 json_object *json_cap = NULL;
8313
8314 json_cap = json_object_new_object();
8315
8316 /* AS4 */
8317 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8318 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8319 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8320 && CHECK_FLAG(p->cap,
8321 PEER_CAP_AS4_RCV))
8322 json_object_string_add(
8323 json_cap, "4byteAs",
8324 "advertisedAndReceived");
8325 else if (CHECK_FLAG(p->cap,
8326 PEER_CAP_AS4_ADV))
8327 json_object_string_add(
8328 json_cap, "4byteAs",
8329 "advertised");
8330 else if (CHECK_FLAG(p->cap,
8331 PEER_CAP_AS4_RCV))
8332 json_object_string_add(
8333 json_cap, "4byteAs",
8334 "received");
8335 }
8336
8337 /* AddPath */
8338 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8339 || CHECK_FLAG(p->cap,
8340 PEER_CAP_ADDPATH_ADV)) {
8341 json_object *json_add = NULL;
8342 const char *print_store;
8343
8344 json_add = json_object_new_object();
8345
8346 for (afi = AFI_IP; afi < AFI_MAX; afi++)
8347 for (safi = SAFI_UNICAST;
8348 safi < SAFI_MAX; safi++) {
8349 json_object *json_sub =
8350 NULL;
8351 json_sub =
8352 json_object_new_object();
8353 print_store =
8354 afi_safi_print(
8355 afi,
8356 safi);
8357
8358 if (CHECK_FLAG(
8359 p->af_cap
8360 [afi]
8361 [safi],
8362 PEER_CAP_ADDPATH_AF_TX_ADV)
8363 || CHECK_FLAG(
8364 p->af_cap
8365 [afi]
8366 [safi],
8367 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8368 if (CHECK_FLAG(
8369 p->af_cap
8370 [afi]
8371 [safi],
8372 PEER_CAP_ADDPATH_AF_TX_ADV)
8373 && CHECK_FLAG(
8374 p->af_cap
8375 [afi]
8376 [safi],
8377 PEER_CAP_ADDPATH_AF_TX_RCV))
8378 json_object_boolean_true_add(
8379 json_sub,
8380 "txAdvertisedAndReceived");
8381 else if (
8382 CHECK_FLAG(
8383 p->af_cap
8384 [afi]
8385 [safi],
8386 PEER_CAP_ADDPATH_AF_TX_ADV))
8387 json_object_boolean_true_add(
8388 json_sub,
8389 "txAdvertised");
8390 else if (
8391 CHECK_FLAG(
8392 p->af_cap
8393 [afi]
8394 [safi],
8395 PEER_CAP_ADDPATH_AF_TX_RCV))
8396 json_object_boolean_true_add(
8397 json_sub,
8398 "txReceived");
8399 }
8400
8401 if (CHECK_FLAG(
8402 p->af_cap
8403 [afi]
8404 [safi],
8405 PEER_CAP_ADDPATH_AF_RX_ADV)
8406 || CHECK_FLAG(
8407 p->af_cap
8408 [afi]
8409 [safi],
8410 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8411 if (CHECK_FLAG(
8412 p->af_cap
8413 [afi]
8414 [safi],
8415 PEER_CAP_ADDPATH_AF_RX_ADV)
8416 && CHECK_FLAG(
8417 p->af_cap
8418 [afi]
8419 [safi],
8420 PEER_CAP_ADDPATH_AF_RX_RCV))
8421 json_object_boolean_true_add(
8422 json_sub,
8423 "rxAdvertisedAndReceived");
8424 else if (
8425 CHECK_FLAG(
8426 p->af_cap
8427 [afi]
8428 [safi],
8429 PEER_CAP_ADDPATH_AF_RX_ADV))
8430 json_object_boolean_true_add(
8431 json_sub,
8432 "rxAdvertised");
8433 else if (
8434 CHECK_FLAG(
8435 p->af_cap
8436 [afi]
8437 [safi],
8438 PEER_CAP_ADDPATH_AF_RX_RCV))
8439 json_object_boolean_true_add(
8440 json_sub,
8441 "rxReceived");
8442 }
8443
8444 if (CHECK_FLAG(
8445 p->af_cap
8446 [afi]
8447 [safi],
8448 PEER_CAP_ADDPATH_AF_TX_ADV)
8449 || CHECK_FLAG(
8450 p->af_cap
8451 [afi]
8452 [safi],
8453 PEER_CAP_ADDPATH_AF_TX_RCV)
8454 || CHECK_FLAG(
8455 p->af_cap
8456 [afi]
8457 [safi],
8458 PEER_CAP_ADDPATH_AF_RX_ADV)
8459 || CHECK_FLAG(
8460 p->af_cap
8461 [afi]
8462 [safi],
8463 PEER_CAP_ADDPATH_AF_RX_RCV))
8464 json_object_object_add(
8465 json_add,
8466 print_store,
8467 json_sub);
8468 else
8469 json_object_free(
8470 json_sub);
8471 }
8472
8473 json_object_object_add(
8474 json_cap, "addPath", json_add);
8475 }
8476
8477 /* Dynamic */
8478 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8479 || CHECK_FLAG(p->cap,
8480 PEER_CAP_DYNAMIC_ADV)) {
8481 if (CHECK_FLAG(p->cap,
8482 PEER_CAP_DYNAMIC_ADV)
8483 && CHECK_FLAG(p->cap,
8484 PEER_CAP_DYNAMIC_RCV))
8485 json_object_string_add(
8486 json_cap, "dynamic",
8487 "advertisedAndReceived");
8488 else if (CHECK_FLAG(
8489 p->cap,
8490 PEER_CAP_DYNAMIC_ADV))
8491 json_object_string_add(
8492 json_cap, "dynamic",
8493 "advertised");
8494 else if (CHECK_FLAG(
8495 p->cap,
8496 PEER_CAP_DYNAMIC_RCV))
8497 json_object_string_add(
8498 json_cap, "dynamic",
8499 "received");
8500 }
8501
8502 /* Extended nexthop */
8503 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8504 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8505 json_object *json_nxt = NULL;
8506 const char *print_store;
8507
8508
8509 if (CHECK_FLAG(p->cap,
8510 PEER_CAP_ENHE_ADV)
8511 && CHECK_FLAG(p->cap,
8512 PEER_CAP_ENHE_RCV))
8513 json_object_string_add(
8514 json_cap,
8515 "extendedNexthop",
8516 "advertisedAndReceived");
8517 else if (CHECK_FLAG(p->cap,
8518 PEER_CAP_ENHE_ADV))
8519 json_object_string_add(
8520 json_cap,
8521 "extendedNexthop",
8522 "advertised");
8523 else if (CHECK_FLAG(p->cap,
8524 PEER_CAP_ENHE_RCV))
8525 json_object_string_add(
8526 json_cap,
8527 "extendedNexthop",
8528 "received");
8529
8530 if (CHECK_FLAG(p->cap,
8531 PEER_CAP_ENHE_RCV)) {
8532 json_nxt =
8533 json_object_new_object();
8534
8535 for (safi = SAFI_UNICAST;
8536 safi < SAFI_MAX; safi++) {
8537 if (CHECK_FLAG(
8538 p->af_cap
8539 [AFI_IP]
8540 [safi],
8541 PEER_CAP_ENHE_AF_RCV)) {
8542 print_store = afi_safi_print(
8543 AFI_IP,
8544 safi);
8545 json_object_string_add(
8546 json_nxt,
8547 print_store,
8548 "recieved");
8549 }
8550 }
8551 json_object_object_add(
8552 json_cap,
8553 "extendedNexthopFamililesByPeer",
8554 json_nxt);
8555 }
8556 }
8557
8558 /* Route Refresh */
8559 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8560 || CHECK_FLAG(p->cap,
8561 PEER_CAP_REFRESH_NEW_RCV)
8562 || CHECK_FLAG(p->cap,
8563 PEER_CAP_REFRESH_OLD_RCV)) {
8564 if (CHECK_FLAG(p->cap,
8565 PEER_CAP_REFRESH_ADV)
8566 && (CHECK_FLAG(
8567 p->cap,
8568 PEER_CAP_REFRESH_NEW_RCV)
8569 || CHECK_FLAG(
8570 p->cap,
8571 PEER_CAP_REFRESH_OLD_RCV))) {
8572 if (CHECK_FLAG(
8573 p->cap,
8574 PEER_CAP_REFRESH_OLD_RCV)
8575 && CHECK_FLAG(
8576 p->cap,
8577 PEER_CAP_REFRESH_NEW_RCV))
8578 json_object_string_add(
8579 json_cap,
8580 "routeRefresh",
8581 "advertisedAndReceivedOldNew");
8582 else {
8583 if (CHECK_FLAG(
8584 p->cap,
8585 PEER_CAP_REFRESH_OLD_RCV))
8586 json_object_string_add(
8587 json_cap,
8588 "routeRefresh",
8589 "advertisedAndReceivedOld");
8590 else
8591 json_object_string_add(
8592 json_cap,
8593 "routeRefresh",
8594 "advertisedAndReceivedNew");
8595 }
8596 } else if (
8597 CHECK_FLAG(
8598 p->cap,
8599 PEER_CAP_REFRESH_ADV))
8600 json_object_string_add(
8601 json_cap,
8602 "routeRefresh",
8603 "advertised");
8604 else if (
8605 CHECK_FLAG(
8606 p->cap,
8607 PEER_CAP_REFRESH_NEW_RCV)
8608 || CHECK_FLAG(
8609 p->cap,
8610 PEER_CAP_REFRESH_OLD_RCV))
8611 json_object_string_add(
8612 json_cap,
8613 "routeRefresh",
8614 "received");
8615 }
8616
8617 /* Multiprotocol Extensions */
8618 json_object *json_multi = NULL;
8619 json_multi = json_object_new_object();
8620
8621 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
8622 for (safi = SAFI_UNICAST;
8623 safi < SAFI_MAX; safi++) {
8624 if (p->afc_adv[afi][safi]
8625 || p->afc_recv[afi][safi]) {
8626 json_object
8627 *json_exten =
8628 NULL;
8629 json_exten =
8630 json_object_new_object();
8631
8632 if (p->afc_adv[afi]
8633 [safi]
8634 && p->afc_recv
8635 [afi]
8636 [safi])
8637 json_object_boolean_true_add(
8638 json_exten,
8639 "advertisedAndReceived");
8640 else if (p->afc_adv
8641 [afi]
8642 [safi])
8643 json_object_boolean_true_add(
8644 json_exten,
8645 "advertised");
8646 else if (p->afc_recv
8647 [afi]
8648 [safi])
8649 json_object_boolean_true_add(
8650 json_exten,
8651 "received");
8652
8653 json_object_object_add(
8654 json_multi,
8655 afi_safi_print(
8656 afi,
8657 safi),
8658 json_exten);
8659 }
8660 }
8661 }
8662 json_object_object_add(
8663 json_cap, "multiprotocolExtensions",
8664 json_multi);
8665
d77114b7
MK
8666 /* Hostname capabilities */
8667 json_object *json_hname = NULL;
8668
8669 json_hname = json_object_new_object();
8670
8671 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
8672 json_object_string_add(
8673 json_hname,
8674 "advHostName",
8675 bgp->peer_self->hostname ?
8676 bgp->peer_self->hostname
8677 : "n/a");
8678 json_object_string_add(
8679 json_hname,
8680 "advDomainName",
8681 bgp->peer_self->domainname ?
8682 bgp->peer_self->domainname
8683 : "n/a");
8684 }
8685
8686
8687 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
8688 json_object_string_add(
8689 json_hname,
8690 "rcvHostName",
8691 p->hostname ?
8692 p->hostname :
8693 "n/a");
8694 json_object_string_add(
8695 json_hname,
8696 "rcvDomainName",
8697 p->domainname ?
8698 p->domainname :
8699 "n/a");
8700 }
8701
8702 json_object_object_add(json_cap,
8703 "hostName",
8704 json_hname);
8705
d62a17ae 8706 /* Gracefull Restart */
8707 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
8708 || CHECK_FLAG(p->cap,
8709 PEER_CAP_RESTART_ADV)) {
8710 if (CHECK_FLAG(p->cap,
8711 PEER_CAP_RESTART_ADV)
8712 && CHECK_FLAG(p->cap,
8713 PEER_CAP_RESTART_RCV))
8714 json_object_string_add(
8715 json_cap,
8716 "gracefulRestart",
8717 "advertisedAndReceived");
8718 else if (CHECK_FLAG(
8719 p->cap,
8720 PEER_CAP_RESTART_ADV))
8721 json_object_string_add(
8722 json_cap,
8723 "gracefulRestartCapability",
8724 "advertised");
8725 else if (CHECK_FLAG(
8726 p->cap,
8727 PEER_CAP_RESTART_RCV))
8728 json_object_string_add(
8729 json_cap,
8730 "gracefulRestartCapability",
8731 "received");
8732
8733 if (CHECK_FLAG(p->cap,
8734 PEER_CAP_RESTART_RCV)) {
8735 int restart_af_count = 0;
8736 json_object *json_restart =
8737 NULL;
8738 json_restart =
8739 json_object_new_object();
8740
8741 json_object_int_add(
8742 json_cap,
8743 "gracefulRestartRemoteTimerMsecs",
8744 p->v_gr_restart * 1000);
8745
8746 for (afi = AFI_IP;
8747 afi < AFI_MAX; afi++) {
8748 for (safi = SAFI_UNICAST;
8749 safi < SAFI_MAX;
8750 safi++) {
8751 if (CHECK_FLAG(
8752 p->af_cap
8753 [afi]
8754 [safi],
8755 PEER_CAP_RESTART_AF_RCV)) {
8756 json_object *json_sub =
8757 NULL;
8758 json_sub =
8759 json_object_new_object();
8760
8761 if (CHECK_FLAG(
8762 p->af_cap
8763 [afi]
8764 [safi],
8765 PEER_CAP_RESTART_AF_PRESERVE_RCV))
8766 json_object_boolean_true_add(
8767 json_sub,
8768 "preserved");
8769 restart_af_count++;
8770 json_object_object_add(
8771 json_restart,
8772 afi_safi_print(
8773 afi,
8774 safi),
8775 json_sub);
8776 }
8777 }
8778 }
8779 if (!restart_af_count) {
8780 json_object_string_add(
8781 json_cap,
8782 "addressFamiliesByPeer",
8783 "none");
8784 json_object_free(
8785 json_restart);
8786 } else
8787 json_object_object_add(
8788 json_cap,
8789 "addressFamiliesByPeer",
8790 json_restart);
8791 }
8792 }
8793 json_object_object_add(json_neigh,
8794 "neighborCapabilities",
8795 json_cap);
8796 } else {
8797 vty_out(vty, " Neighbor capabilities:\n");
8798
8799 /* AS4 */
8800 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8801 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8802 vty_out(vty, " 4 Byte AS:");
8803 if (CHECK_FLAG(p->cap,
8804 PEER_CAP_AS4_ADV))
8805 vty_out(vty, " advertised");
8806 if (CHECK_FLAG(p->cap,
8807 PEER_CAP_AS4_RCV))
8808 vty_out(vty, " %sreceived",
8809 CHECK_FLAG(
8810 p->cap,
8811 PEER_CAP_AS4_ADV)
8812 ? "and "
8813 : "");
8814 vty_out(vty, "\n");
8815 }
8816
8817 /* AddPath */
8818 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8819 || CHECK_FLAG(p->cap,
8820 PEER_CAP_ADDPATH_ADV)) {
8821 vty_out(vty, " AddPath:\n");
8822
8823 for (afi = AFI_IP; afi < AFI_MAX; afi++)
8824 for (safi = SAFI_UNICAST;
8825 safi < SAFI_MAX; safi++) {
8826 if (CHECK_FLAG(
8827 p->af_cap
8828 [afi]
8829 [safi],
8830 PEER_CAP_ADDPATH_AF_TX_ADV)
8831 || CHECK_FLAG(
8832 p->af_cap
8833 [afi]
8834 [safi],
8835 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8836 vty_out(vty,
8837 " %s: TX ",
8838 afi_safi_print(
8839 afi,
8840 safi));
8841
8842 if (CHECK_FLAG(
8843 p->af_cap
8844 [afi]
8845 [safi],
8846 PEER_CAP_ADDPATH_AF_TX_ADV))
8847 vty_out(vty,
8848 "advertised %s",
8849 afi_safi_print(
8850 afi,
8851 safi));
8852
8853 if (CHECK_FLAG(
8854 p->af_cap
8855 [afi]
8856 [safi],
8857 PEER_CAP_ADDPATH_AF_TX_RCV))
8858 vty_out(vty,
8859 "%sreceived",
8860 CHECK_FLAG(
8861 p->af_cap
8862 [afi]
8863 [safi],
8864 PEER_CAP_ADDPATH_AF_TX_ADV)
8865 ? " and "
8866 : "");
8867
8868 vty_out(vty,
8869 "\n");
8870 }
8871
8872 if (CHECK_FLAG(
8873 p->af_cap
8874 [afi]
8875 [safi],
8876 PEER_CAP_ADDPATH_AF_RX_ADV)
8877 || CHECK_FLAG(
8878 p->af_cap
8879 [afi]
8880 [safi],
8881 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8882 vty_out(vty,
8883 " %s: RX ",
8884 afi_safi_print(
8885 afi,
8886 safi));
8887
8888 if (CHECK_FLAG(
8889 p->af_cap
8890 [afi]
8891 [safi],
8892 PEER_CAP_ADDPATH_AF_RX_ADV))
8893 vty_out(vty,
8894 "advertised %s",
8895 afi_safi_print(
8896 afi,
8897 safi));
8898
8899 if (CHECK_FLAG(
8900 p->af_cap
8901 [afi]
8902 [safi],
8903 PEER_CAP_ADDPATH_AF_RX_RCV))
8904 vty_out(vty,
8905 "%sreceived",
8906 CHECK_FLAG(
8907 p->af_cap
8908 [afi]
8909 [safi],
8910 PEER_CAP_ADDPATH_AF_RX_ADV)
8911 ? " and "
8912 : "");
8913
8914 vty_out(vty,
8915 "\n");
8916 }
8917 }
8918 }
8919
8920 /* Dynamic */
8921 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8922 || CHECK_FLAG(p->cap,
8923 PEER_CAP_DYNAMIC_ADV)) {
8924 vty_out(vty, " Dynamic:");
8925 if (CHECK_FLAG(p->cap,
8926 PEER_CAP_DYNAMIC_ADV))
8927 vty_out(vty, " advertised");
8928 if (CHECK_FLAG(p->cap,
8929 PEER_CAP_DYNAMIC_RCV))
8930 vty_out(vty, " %sreceived",
8931 CHECK_FLAG(
8932 p->cap,
8933 PEER_CAP_DYNAMIC_ADV)
8934 ? "and "
8935 : "");
8936 vty_out(vty, "\n");
8937 }
8938
8939 /* Extended nexthop */
8940 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8941 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8942 vty_out(vty, " Extended nexthop:");
8943 if (CHECK_FLAG(p->cap,
8944 PEER_CAP_ENHE_ADV))
8945 vty_out(vty, " advertised");
8946 if (CHECK_FLAG(p->cap,
8947 PEER_CAP_ENHE_RCV))
8948 vty_out(vty, " %sreceived",
8949 CHECK_FLAG(
8950 p->cap,
8951 PEER_CAP_ENHE_ADV)
8952 ? "and "
8953 : "");
8954 vty_out(vty, "\n");
8955
8956 if (CHECK_FLAG(p->cap,
8957 PEER_CAP_ENHE_RCV)) {
8958 vty_out(vty,
8959 " Address families by peer:\n ");
8960 for (safi = SAFI_UNICAST;
8961 safi < SAFI_MAX; safi++)
8962 if (CHECK_FLAG(
8963 p->af_cap
8964 [AFI_IP]
8965 [safi],
8966 PEER_CAP_ENHE_AF_RCV))
8967 vty_out(vty,
8968 " %s\n",
8969 afi_safi_print(
8970 AFI_IP,
8971 safi));
8972 }
8973 }
8974
8975 /* Route Refresh */
8976 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8977 || CHECK_FLAG(p->cap,
8978 PEER_CAP_REFRESH_NEW_RCV)
8979 || CHECK_FLAG(p->cap,
8980 PEER_CAP_REFRESH_OLD_RCV)) {
8981 vty_out(vty, " Route refresh:");
8982 if (CHECK_FLAG(p->cap,
8983 PEER_CAP_REFRESH_ADV))
8984 vty_out(vty, " advertised");
8985 if (CHECK_FLAG(p->cap,
8986 PEER_CAP_REFRESH_NEW_RCV)
8987 || CHECK_FLAG(
8988 p->cap,
8989 PEER_CAP_REFRESH_OLD_RCV))
8990 vty_out(vty, " %sreceived(%s)",
8991 CHECK_FLAG(
8992 p->cap,
8993 PEER_CAP_REFRESH_ADV)
8994 ? "and "
8995 : "",
8996 (CHECK_FLAG(
8997 p->cap,
8998 PEER_CAP_REFRESH_OLD_RCV)
8999 && CHECK_FLAG(
9000 p->cap,
9001 PEER_CAP_REFRESH_NEW_RCV))
9002 ? "old & new"
9003 : CHECK_FLAG(
9004 p->cap,
9005 PEER_CAP_REFRESH_OLD_RCV)
9006 ? "old"
9007 : "new");
9008
9009 vty_out(vty, "\n");
9010 }
9011
9012 /* Multiprotocol Extensions */
9013 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9014 for (safi = SAFI_UNICAST;
9015 safi < SAFI_MAX; safi++)
9016 if (p->afc_adv[afi][safi]
9017 || p->afc_recv[afi][safi]) {
9018 vty_out(vty,
9019 " Address Family %s:",
9020 afi_safi_print(
9021 afi,
9022 safi));
9023 if (p->afc_adv[afi]
9024 [safi])
9025 vty_out(vty,
9026 " advertised");
9027 if (p->afc_recv[afi]
9028 [safi])
9029 vty_out(vty,
9030 " %sreceived",
9031 p->afc_adv[afi]
9032 [safi]
9033 ? "and "
9034 : "");
9035 vty_out(vty, "\n");
9036 }
9037
9038 /* Hostname capability */
d77114b7
MK
9039 vty_out(vty,
9040 " Hostname Capability:");
9041
9042 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
b682f6de 9043 vty_out(vty, " advertised (name: %s,domain name: %s)",
d77114b7
MK
9044 bgp->peer_self->hostname ?
9045 bgp->peer_self->hostname
9046 : "n/a",
9047 bgp->peer_self->domainname ?
9048 bgp->peer_self->domainname
9049 : "n/a");
9050 } else {
9051 vty_out(vty, " not advertised");
d62a17ae 9052 }
9053
d77114b7 9054 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
b682f6de 9055 vty_out(vty, " received (name: %s,domain name: %s)",
d77114b7
MK
9056 p->hostname ?
9057 p->hostname : "n/a",
9058 p->domainname ?
9059 p->domainname : "n/a");
9060 } else {
9061 vty_out(vty, " not received");
9062 }
9063
9064 vty_out(vty, "\n");
9065
d62a17ae 9066 /* Gracefull Restart */
9067 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9068 || CHECK_FLAG(p->cap,
9069 PEER_CAP_RESTART_ADV)) {
9070 vty_out(vty,
9071 " Graceful Restart Capabilty:");
9072 if (CHECK_FLAG(p->cap,
9073 PEER_CAP_RESTART_ADV))
9074 vty_out(vty, " advertised");
9075 if (CHECK_FLAG(p->cap,
9076 PEER_CAP_RESTART_RCV))
9077 vty_out(vty, " %sreceived",
9078 CHECK_FLAG(
9079 p->cap,
9080 PEER_CAP_RESTART_ADV)
9081 ? "and "
9082 : "");
9083 vty_out(vty, "\n");
9084
9085 if (CHECK_FLAG(p->cap,
9086 PEER_CAP_RESTART_RCV)) {
9087 int restart_af_count = 0;
9088
9089 vty_out(vty,
9090 " Remote Restart timer is %d seconds\n",
9091 p->v_gr_restart);
9092 vty_out(vty,
9093 " Address families by peer:\n ");
9094
9095 for (afi = AFI_IP;
9096 afi < AFI_MAX; afi++)
9097 for (safi = SAFI_UNICAST;
9098 safi < SAFI_MAX;
9099 safi++)
9100 if (CHECK_FLAG(
9101 p->af_cap
9102 [afi]
9103 [safi],
9104 PEER_CAP_RESTART_AF_RCV)) {
9105 vty_out(vty,
9106 "%s%s(%s)",
9107 restart_af_count
9108 ? ", "
9109 : "",
9110 afi_safi_print(
9111 afi,
9112 safi),
9113 CHECK_FLAG(
9114 p->af_cap
9115 [afi]
9116 [safi],
9117 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9118 ? "preserved"
9119 : "not preserved");
9120 restart_af_count++;
9121 }
9122 if (!restart_af_count)
9123 vty_out(vty, "none");
9124 vty_out(vty, "\n");
9125 }
9126 }
9127 }
9128 }
9129 }
9130
9131 /* graceful restart information */
9132 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9133 || p->t_gr_stale) {
9134 json_object *json_grace = NULL;
9135 json_object *json_grace_send = NULL;
9136 json_object *json_grace_recv = NULL;
9137 int eor_send_af_count = 0;
9138 int eor_receive_af_count = 0;
9139
9140 if (use_json) {
9141 json_grace = json_object_new_object();
9142 json_grace_send = json_object_new_object();
9143 json_grace_recv = json_object_new_object();
9144
9145 if (p->status == Established) {
9146 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9147 for (safi = SAFI_UNICAST;
9148 safi < SAFI_MAX; safi++) {
9149 if (CHECK_FLAG(
9150 p->af_sflags[afi]
9151 [safi],
9152 PEER_STATUS_EOR_SEND)) {
9153 json_object_boolean_true_add(
9154 json_grace_send,
9155 afi_safi_print(
9156 afi,
9157 safi));
9158 eor_send_af_count++;
9159 }
9160 }
9161 }
9162 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9163 for (safi = SAFI_UNICAST;
9164 safi < SAFI_MAX; safi++) {
9165 if (CHECK_FLAG(
9166 p->af_sflags[afi]
9167 [safi],
9168 PEER_STATUS_EOR_RECEIVED)) {
9169 json_object_boolean_true_add(
9170 json_grace_recv,
9171 afi_safi_print(
9172 afi,
9173 safi));
9174 eor_receive_af_count++;
9175 }
9176 }
9177 }
9178 }
9179
9180 json_object_object_add(json_grace, "endOfRibSend",
9181 json_grace_send);
9182 json_object_object_add(json_grace, "endOfRibRecv",
9183 json_grace_recv);
9184
9185 if (p->t_gr_restart)
9186 json_object_int_add(json_grace,
9187 "gracefulRestartTimerMsecs",
9188 thread_timer_remain_second(
9189 p->t_gr_restart)
9190 * 1000);
9191
9192 if (p->t_gr_stale)
9193 json_object_int_add(
9194 json_grace,
9195 "gracefulStalepathTimerMsecs",
9196 thread_timer_remain_second(
9197 p->t_gr_stale)
9198 * 1000);
9199
9200 json_object_object_add(
9201 json_neigh, "gracefulRestartInfo", json_grace);
9202 } else {
9203 vty_out(vty, " Graceful restart informations:\n");
9204 if (p->status == Established) {
9205 vty_out(vty, " End-of-RIB send: ");
9206 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9207 for (safi = SAFI_UNICAST;
9208 safi < SAFI_MAX; safi++) {
9209 if (CHECK_FLAG(
9210 p->af_sflags[afi]
9211 [safi],
9212 PEER_STATUS_EOR_SEND)) {
9213 vty_out(vty, "%s%s",
9214 eor_send_af_count
9215 ? ", "
9216 : "",
9217 afi_safi_print(
9218 afi,
9219 safi));
9220 eor_send_af_count++;
9221 }
9222 }
9223 }
9224 vty_out(vty, "\n");
9225 vty_out(vty, " End-of-RIB received: ");
9226 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
9227 for (safi = SAFI_UNICAST;
9228 safi < SAFI_MAX; safi++) {
9229 if (CHECK_FLAG(
9230 p->af_sflags[afi]
9231 [safi],
9232 PEER_STATUS_EOR_RECEIVED)) {
9233 vty_out(vty, "%s%s",
9234 eor_receive_af_count
9235 ? ", "
9236 : "",
9237 afi_safi_print(
9238 afi,
9239 safi));
9240 eor_receive_af_count++;
9241 }
9242 }
9243 }
9244 vty_out(vty, "\n");
9245 }
9246
9247 if (p->t_gr_restart)
9248 vty_out(vty,
9249 " The remaining time of restart timer is %ld\n",
9250 thread_timer_remain_second(
9251 p->t_gr_restart));
9252
9253 if (p->t_gr_stale)
9254 vty_out(vty,
9255 " The remaining time of stalepath timer is %ld\n",
9256 thread_timer_remain_second(
9257 p->t_gr_stale));
9258 }
9259 }
9260 if (use_json) {
9261 json_object *json_stat = NULL;
9262 json_stat = json_object_new_object();
9263 /* Packet counts. */
9264 json_object_int_add(json_stat, "depthInq", 0);
9265 json_object_int_add(json_stat, "depthOutq",
9266 (unsigned long)p->obuf->count);
9267 json_object_int_add(json_stat, "opensSent", p->open_out);
9268 json_object_int_add(json_stat, "opensRecv", p->open_in);
9269 json_object_int_add(json_stat, "notificationsSent",
9270 p->notify_out);
9271 json_object_int_add(json_stat, "notificationsRecv",
9272 p->notify_in);
9273 json_object_int_add(json_stat, "updatesSent", p->update_out);
9274 json_object_int_add(json_stat, "updatesRecv", p->update_in);
9275 json_object_int_add(json_stat, "keepalivesSent",
9276 p->keepalive_out);
9277 json_object_int_add(json_stat, "keepalivesRecv",
9278 p->keepalive_in);
9279 json_object_int_add(json_stat, "routeRefreshSent",
9280 p->refresh_out);
9281 json_object_int_add(json_stat, "routeRefreshRecv",
9282 p->refresh_in);
9283 json_object_int_add(json_stat, "capabilitySent",
9284 p->dynamic_cap_out);
9285 json_object_int_add(json_stat, "capabilityRecv",
9286 p->dynamic_cap_in);
9287 json_object_int_add(json_stat, "totalSent",
9288 p->open_out + p->notify_out + p->update_out
9289 + p->keepalive_out + p->refresh_out
9290 + p->dynamic_cap_out);
9291 json_object_int_add(json_stat, "totalRecv",
9292 p->open_in + p->notify_in + p->update_in
9293 + p->keepalive_in + p->refresh_in
9294 + p->dynamic_cap_in);
9295 json_object_object_add(json_neigh, "messageStats", json_stat);
9296 } else {
9297 /* Packet counts. */
9298 vty_out(vty, " Message statistics:\n");
9299 vty_out(vty, " Inq depth is 0\n");
9300 vty_out(vty, " Outq depth is %lu\n",
9301 (unsigned long)p->obuf->count);
9302 vty_out(vty, " Sent Rcvd\n");
9303 vty_out(vty, " Opens: %10d %10d\n", p->open_out,
9304 p->open_in);
9305 vty_out(vty, " Notifications: %10d %10d\n", p->notify_out,
9306 p->notify_in);
9307 vty_out(vty, " Updates: %10d %10d\n", p->update_out,
9308 p->update_in);
9309 vty_out(vty, " Keepalives: %10d %10d\n", p->keepalive_out,
9310 p->keepalive_in);
9311 vty_out(vty, " Route Refresh: %10d %10d\n", p->refresh_out,
9312 p->refresh_in);
9313 vty_out(vty, " Capability: %10d %10d\n",
9314 p->dynamic_cap_out, p->dynamic_cap_in);
9315 vty_out(vty, " Total: %10d %10d\n",
9316 p->open_out + p->notify_out + p->update_out
9317 + p->keepalive_out + p->refresh_out
9318 + p->dynamic_cap_out,
9319 p->open_in + p->notify_in + p->update_in
9320 + p->keepalive_in + p->refresh_in
9321 + p->dynamic_cap_in);
9322 }
9323
9324 if (use_json) {
9325 /* advertisement-interval */
9326 json_object_int_add(json_neigh,
9327 "minBtwnAdvertisementRunsTimerMsecs",
9328 p->v_routeadv * 1000);
9329
9330 /* Update-source. */
9331 if (p->update_if || p->update_source) {
9332 if (p->update_if)
9333 json_object_string_add(json_neigh,
9334 "updateSource",
9335 p->update_if);
9336 else if (p->update_source)
9337 json_object_string_add(
9338 json_neigh, "updateSource",
9339 sockunion2str(p->update_source, buf1,
9340 SU_ADDRSTRLEN));
9341 }
9342 } else {
9343 /* advertisement-interval */
9344 vty_out(vty,
9345 " Minimum time between advertisement runs is %d seconds\n",
9346 p->v_routeadv);
9347
9348 /* Update-source. */
9349 if (p->update_if || p->update_source) {
9350 vty_out(vty, " Update source is ");
9351 if (p->update_if)
9352 vty_out(vty, "%s", p->update_if);
9353 else if (p->update_source)
9354 vty_out(vty, "%s",
9355 sockunion2str(p->update_source, buf1,
9356 SU_ADDRSTRLEN));
9357 vty_out(vty, "\n");
9358 }
9359
9360 vty_out(vty, "\n");
9361 }
9362
9363 /* Address Family Information */
9364 json_object *json_hold = NULL;
9365
9366 if (use_json)
9367 json_hold = json_object_new_object();
9368
9369 for (afi = AFI_IP; afi < AFI_MAX; afi++)
9370 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
9371 if (p->afc[afi][safi])
9372 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9373 json_hold);
9374
9375 if (use_json) {
9376 json_object_object_add(json_neigh, "addressFamilyInfo",
9377 json_hold);
9378 json_object_int_add(json_neigh, "connectionsEstablished",
9379 p->established);
9380 json_object_int_add(json_neigh, "connectionsDropped",
9381 p->dropped);
9382 } else
9383 vty_out(vty, " Connections established %d; dropped %d\n",
9384 p->established, p->dropped);
9385
9386 if (!p->last_reset) {
9387 if (use_json)
9388 json_object_string_add(json_neigh, "lastReset",
9389 "never");
9390 else
9391 vty_out(vty, " Last reset never\n");
9392 } else {
9393 if (use_json) {
9394 time_t uptime;
9395 struct tm *tm;
9396
9397 uptime = bgp_clock();
9398 uptime -= p->resettime;
9399 tm = gmtime(&uptime);
9400 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9401 (tm->tm_sec * 1000)
9402 + (tm->tm_min * 60000)
9403 + (tm->tm_hour * 3600000));
9404 json_object_string_add(
9405 json_neigh, "lastResetDueTo",
9406 peer_down_str[(int)p->last_reset]);
9407 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9408 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9409 char errorcodesubcode_hexstr[5];
9410 char errorcodesubcode_str[256];
9411
9412 code_str = bgp_notify_code_str(p->notify.code);
9413 subcode_str = bgp_notify_subcode_str(
9414 p->notify.code, p->notify.subcode);
9415
9416 sprintf(errorcodesubcode_hexstr, "%02X%02X",
9417 p->notify.code, p->notify.subcode);
9418 json_object_string_add(json_neigh,
9419 "lastErrorCodeSubcode",
9420 errorcodesubcode_hexstr);
9421 snprintf(errorcodesubcode_str, 255, "%s%s",
9422 code_str, subcode_str);
9423 json_object_string_add(json_neigh,
9424 "lastNotificationReason",
9425 errorcodesubcode_str);
9426 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9427 && p->notify.code == BGP_NOTIFY_CEASE
9428 && (p->notify.subcode
9429 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9430 || p->notify.subcode
9431 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9432 && p->notify.length) {
9433 char msgbuf[1024];
9434 const char *msg_str;
9435
9436 msg_str = bgp_notify_admin_message(
9437 msgbuf, sizeof(msgbuf),
9438 (u_char *)p->notify.data,
9439 p->notify.length);
9440 if (msg_str)
9441 json_object_string_add(
9442 json_neigh,
9443 "lastShutdownDescription",
9444 msg_str);
9445 }
9446 }
9447 } else {
9448 vty_out(vty, " Last reset %s, ",
9449 peer_uptime(p->resettime, timebuf,
9450 BGP_UPTIME_LEN, 0, NULL));
9451
9452 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9453 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9454 code_str = bgp_notify_code_str(p->notify.code);
9455 subcode_str = bgp_notify_subcode_str(
9456 p->notify.code, p->notify.subcode);
9457 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
9458 p->last_reset == PEER_DOWN_NOTIFY_SEND
9459 ? "sent"
9460 : "received",
9461 code_str, subcode_str);
9462 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9463 && p->notify.code == BGP_NOTIFY_CEASE
9464 && (p->notify.subcode
9465 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9466 || p->notify.subcode
9467 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9468 && p->notify.length) {
9469 char msgbuf[1024];
9470 const char *msg_str;
9471
9472 msg_str = bgp_notify_admin_message(
9473 msgbuf, sizeof(msgbuf),
9474 (u_char *)p->notify.data,
9475 p->notify.length);
9476 if (msg_str)
9477 vty_out(vty,
9478 " Message: \"%s\"\n",
9479 msg_str);
9480 }
9481 } else {
9482 vty_out(vty, "due to %s\n",
9483 peer_down_str[(int)p->last_reset]);
9484 }
9485
9486 if (p->last_reset_cause_size) {
9487 msg = p->last_reset_cause;
9488 vty_out(vty,
9489 " Message received that caused BGP to send a NOTIFICATION:\n ");
9490 for (i = 1; i <= p->last_reset_cause_size;
9491 i++) {
9492 vty_out(vty, "%02X", *msg++);
9493
9494 if (i != p->last_reset_cause_size) {
9495 if (i % 16 == 0) {
9496 vty_out(vty, "\n ");
9497 } else if (i % 4 == 0) {
9498 vty_out(vty, " ");
9499 }
9500 }
9501 }
9502 vty_out(vty, "\n");
9503 }
9504 }
9505 }
9506
9507 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
9508 if (use_json)
9509 json_object_boolean_true_add(json_neigh,
9510 "prefixesConfigExceedMax");
9511 else
9512 vty_out(vty,
9513 " Peer had exceeded the max. no. of prefixes configured.\n");
9514
9515 if (p->t_pmax_restart) {
9516 if (use_json) {
9517 json_object_boolean_true_add(
9518 json_neigh, "reducePrefixNumFrom");
9519 json_object_int_add(json_neigh,
9520 "restartInTimerMsec",
9521 thread_timer_remain_second(
9522 p->t_pmax_restart)
9523 * 1000);
9524 } else
9525 vty_out(vty,
9526 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
9d303b37
DL
9527 p->host, thread_timer_remain_second(
9528 p->t_pmax_restart));
d62a17ae 9529 } else {
9530 if (use_json)
9531 json_object_boolean_true_add(
9532 json_neigh,
9533 "reducePrefixNumAndClearIpBgp");
9534 else
9535 vty_out(vty,
9536 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
9537 p->host);
9538 }
9539 }
9540
9541 /* EBGP Multihop and GTSM */
9542 if (p->sort != BGP_PEER_IBGP) {
9543 if (use_json) {
9544 if (p->gtsm_hops > 0)
9545 json_object_int_add(json_neigh,
9546 "externalBgpNbrMaxHopsAway",
9547 p->gtsm_hops);
9548 else if (p->ttl > 1)
9549 json_object_int_add(json_neigh,
9550 "externalBgpNbrMaxHopsAway",
9551 p->ttl);
9552 } else {
9553 if (p->gtsm_hops > 0)
9554 vty_out(vty,
9555 " External BGP neighbor may be up to %d hops away.\n",
9556 p->gtsm_hops);
9557 else if (p->ttl > 1)
9558 vty_out(vty,
9559 " External BGP neighbor may be up to %d hops away.\n",
9560 p->ttl);
9561 }
9562 } else {
9563 if (p->gtsm_hops > 0) {
9564 if (use_json)
9565 json_object_int_add(json_neigh,
9566 "internalBgpNbrMaxHopsAway",
9567 p->gtsm_hops);
9568 else
9569 vty_out(vty,
9570 " Internal BGP neighbor may be up to %d hops away.\n",
9571 p->gtsm_hops);
9572 }
9573 }
9574
9575 /* Local address. */
9576 if (p->su_local) {
9577 if (use_json) {
9578 json_object_string_add(json_neigh, "hostLocal",
9579 sockunion2str(p->su_local, buf1,
9580 SU_ADDRSTRLEN));
9581 json_object_int_add(json_neigh, "portLocal",
9582 ntohs(p->su_local->sin.sin_port));
9583 } else
9584 vty_out(vty, "Local host: %s, Local port: %d\n",
9585 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
9586 ntohs(p->su_local->sin.sin_port));
9587 }
9588
9589 /* Remote address. */
9590 if (p->su_remote) {
9591 if (use_json) {
9592 json_object_string_add(json_neigh, "hostForeign",
9593 sockunion2str(p->su_remote, buf1,
9594 SU_ADDRSTRLEN));
9595 json_object_int_add(json_neigh, "portForeign",
9596 ntohs(p->su_remote->sin.sin_port));
9597 } else
9598 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
9599 sockunion2str(p->su_remote, buf1,
9600 SU_ADDRSTRLEN),
9601 ntohs(p->su_remote->sin.sin_port));
9602 }
9603
9604 /* Nexthop display. */
9605 if (p->su_local) {
9606 if (use_json) {
9607 json_object_string_add(json_neigh, "nexthop",
9608 inet_ntop(AF_INET,
9609 &p->nexthop.v4, buf1,
9610 sizeof(buf1)));
9611 json_object_string_add(json_neigh, "nexthopGlobal",
9612 inet_ntop(AF_INET6,
9613 &p->nexthop.v6_global,
9614 buf1, sizeof(buf1)));
9615 json_object_string_add(json_neigh, "nexthopLocal",
9616 inet_ntop(AF_INET6,
9617 &p->nexthop.v6_local,
9618 buf1, sizeof(buf1)));
9619 if (p->shared_network)
9620 json_object_string_add(json_neigh,
9621 "bgpConnection",
9622 "sharedNetwork");
9623 else
9624 json_object_string_add(json_neigh,
9625 "bgpConnection",
9626 "nonSharedNetwork");
9627 } else {
9628 vty_out(vty, "Nexthop: %s\n",
9629 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
9630 sizeof(buf1)));
9631 vty_out(vty, "Nexthop global: %s\n",
9632 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
9633 sizeof(buf1)));
9634 vty_out(vty, "Nexthop local: %s\n",
9635 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
9636 sizeof(buf1)));
9637 vty_out(vty, "BGP connection: %s\n",
9638 p->shared_network ? "shared network"
9639 : "non shared network");
9640 }
9641 }
9642
9643 /* Timer information. */
9644 if (use_json) {
9645 json_object_int_add(json_neigh, "connectRetryTimer",
9646 p->v_connect);
9647 if (p->status == Established && p->rtt)
9648 json_object_int_add(json_neigh, "estimatedRttInMsecs",
9649 p->rtt);
9650 if (p->t_start)
9651 json_object_int_add(
9652 json_neigh, "nextStartTimerDueInMsecs",
9653 thread_timer_remain_second(p->t_start) * 1000);
9654 if (p->t_connect)
9655 json_object_int_add(
9656 json_neigh, "nextConnectTimerDueInMsecs",
9657 thread_timer_remain_second(p->t_connect)
9658 * 1000);
9659 if (p->t_routeadv) {
9660 json_object_int_add(json_neigh, "mraiInterval",
9661 p->v_routeadv);
9662 json_object_int_add(
9663 json_neigh, "mraiTimerExpireInMsecs",
9664 thread_timer_remain_second(p->t_routeadv)
9665 * 1000);
9666 }
9667 if (p->password)
9668 json_object_int_add(json_neigh, "authenticationEnabled",
9669 1);
9670
9671 if (p->t_read)
9672 json_object_string_add(json_neigh, "readThread", "on");
9673 else
9674 json_object_string_add(json_neigh, "readThread", "off");
9675 if (p->t_write)
9676 json_object_string_add(json_neigh, "writeThread", "on");
9677 else
9678 json_object_string_add(json_neigh, "writeThread",
9679 "off");
9680 } else {
9681 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
9682 p->v_connect);
9683 if (p->status == Established && p->rtt)
9684 vty_out(vty, "Estimated round trip time: %d ms\n",
9685 p->rtt);
9686 if (p->t_start)
9687 vty_out(vty, "Next start timer due in %ld seconds\n",
9688 thread_timer_remain_second(p->t_start));
9689 if (p->t_connect)
9690 vty_out(vty, "Next connect timer due in %ld seconds\n",
9691 thread_timer_remain_second(p->t_connect));
9692 if (p->t_routeadv)
9693 vty_out(vty,
9694 "MRAI (interval %u) timer expires in %ld seconds\n",
9695 p->v_routeadv,
9696 thread_timer_remain_second(p->t_routeadv));
9697 if (p->password)
9698 vty_out(vty, "Peer Authentication Enabled\n");
9699
9700 vty_out(vty, "Read thread: %s Write thread: %s\n",
9701 p->t_read ? "on" : "off", p->t_write ? "on" : "off");
9702 }
9703
9704 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9705 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
9706 bgp_capability_vty_out(vty, p, use_json, json_neigh);
9707
9708 if (!use_json)
9709 vty_out(vty, "\n");
9710
9711 /* BFD information. */
9712 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9713
9714 if (use_json) {
9715 if (p->conf_if) /* Configured interface name. */
9716 json_object_object_add(json, p->conf_if, json_neigh);
9717 else /* Configured IP address. */
9718 json_object_object_add(json, p->host, json_neigh);
9719 }
9720}
9721
9722static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
9723 enum show_type type, union sockunion *su,
9724 const char *conf_if, u_char use_json,
9725 json_object *json)
9726{
9727 struct listnode *node, *nnode;
9728 struct peer *peer;
9729 int find = 0;
9730
9731 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9732 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9733 continue;
9734
9735 switch (type) {
9736 case show_all:
9737 bgp_show_peer(vty, peer, use_json, json);
9738 break;
9739 case show_peer:
9740 if (conf_if) {
9741 if ((peer->conf_if
9742 && !strcmp(peer->conf_if, conf_if))
9743 || (peer->hostname
9744 && !strcmp(peer->hostname, conf_if))) {
9745 find = 1;
9746 bgp_show_peer(vty, peer, use_json,
9747 json);
9748 }
9749 } else {
9750 if (sockunion_same(&peer->su, su)) {
9751 find = 1;
9752 bgp_show_peer(vty, peer, use_json,
9753 json);
9754 }
9755 }
9756 break;
9757 }
9758 }
9759
9760 if (type == show_peer && !find) {
9761 if (use_json)
9762 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9763 else
9764 vty_out(vty, "%% No such neighbor\n");
9765 }
9766
9767 if (use_json) {
9d303b37
DL
9768 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9769 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9770 json_object_free(json);
9771 } else {
9772 vty_out(vty, "\n");
9773 }
9774
9775 return CMD_SUCCESS;
9776}
9777
9778static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
9779 u_char use_json)
9780{
dff8f48d
MK
9781 struct listnode *node, *nnode;
9782 struct bgp *bgp;
9783 json_object *json = NULL;
9784 int is_first = 1;
d62a17ae 9785
9786 if (use_json)
9787 vty_out(vty, "{\n");
9788
9789 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9790 if (use_json) {
9791 if (!(json = json_object_new_object())) {
9792 zlog_err(
9793 "Unable to allocate memory for JSON object");
9794 vty_out(vty,
9795 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
9796 return;
9797 }
9798
9799 json_object_int_add(json, "vrfId",
9800 (bgp->vrf_id == VRF_UNKNOWN)
9801 ? -1
9802 : bgp->vrf_id);
9803 json_object_string_add(
9804 json, "vrfName",
9805 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9806 ? "Default"
9807 : bgp->name);
9808
9809 if (!is_first)
9810 vty_out(vty, ",\n");
9811 else
9812 is_first = 0;
9813
9814 vty_out(vty, "\"%s\":",
9815 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9816 ? "Default"
9817 : bgp->name);
9818 } else {
9819 vty_out(vty, "\nInstance %s:\n",
9820 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9821 ? "Default"
9822 : bgp->name);
9823 }
9824 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL, use_json,
9825 json);
9826 }
9827
9828 if (use_json)
9829 vty_out(vty, "}\n");
9830}
9831
9832static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
9833 enum show_type type, const char *ip_str,
9834 u_char use_json)
9835{
9836 int ret;
9837 struct bgp *bgp;
9838 union sockunion su;
9839 json_object *json = NULL;
9840
9841 if (name) {
9842 if (strmatch(name, "all")) {
9843 bgp_show_all_instances_neighbors_vty(vty, use_json);
9844 return CMD_SUCCESS;
9845 } else {
9846 bgp = bgp_lookup_by_name(name);
9847 if (!bgp) {
9848 if (use_json) {
9849 json = json_object_new_object();
9850 json_object_boolean_true_add(
9851 json, "bgpNoSuchInstance");
9852 vty_out(vty, "%s\n",
9853 json_object_to_json_string_ext(
9854 json,
9855 JSON_C_TO_STRING_PRETTY));
9856 json_object_free(json);
9857 } else
9858 vty_out(vty,
9859 "%% No such BGP instance exist\n");
9860
9861 return CMD_WARNING;
9862 }
9863 }
9864 } else {
9865 bgp = bgp_get_default();
9866 }
9867
9868 if (bgp) {
9869 json = json_object_new_object();
9870 if (ip_str) {
9871 ret = str2sockunion(ip_str, &su);
9872 if (ret < 0)
9873 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
9874 use_json, json);
9875 else
9876 bgp_show_neighbor(vty, bgp, type, &su, NULL,
9877 use_json, json);
9878 } else {
9879 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
9880 json);
9881 }
9882 json_object_free(json);
9883 }
9884
9885 return CMD_SUCCESS;
4fb25c53
DW
9886}
9887
716b2d8a 9888/* "show [ip] bgp neighbors" commands. */
718e3744 9889DEFUN (show_ip_bgp_neighbors,
9890 show_ip_bgp_neighbors_cmd,
18c57037 9891 "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 9892 SHOW_STR
9893 IP_STR
9894 BGP_STR
f2a8972b 9895 BGP_INSTANCE_HELP_STR
8c3deaae
QY
9896 "Address Family\n"
9897 "Address Family\n"
91d37724
QY
9898 "Address Family\n"
9899 "Display information about all VPNv4 NLRIs\n"
9900 "Display information for a route distinguisher\n"
9901 "VPN Route Distinguisher\n"
718e3744 9902 "Detailed information on TCP and BGP neighbor connections\n"
9903 "Neighbor to display information about\n"
a80beece 9904 "Neighbor to display information about\n"
91d37724 9905 "Neighbor on BGP configured interface\n"
9973d184 9906 JSON_STR)
718e3744 9907{
d62a17ae 9908 char *vrf = NULL;
9909 char *sh_arg = NULL;
9910 enum show_type sh_type;
718e3744 9911
d62a17ae 9912 u_char uj = use_json(argc, argv);
718e3744 9913
d62a17ae 9914 int idx = 0;
718e3744 9915
d62a17ae 9916 if (argv_find(argv, argc, "view", &idx)
9917 || argv_find(argv, argc, "vrf", &idx))
9918 vrf = argv[idx + 1]->arg;
718e3744 9919
d62a17ae 9920 idx++;
9921 if (argv_find(argv, argc, "A.B.C.D", &idx)
9922 || argv_find(argv, argc, "X:X::X:X", &idx)
9923 || argv_find(argv, argc, "WORD", &idx)) {
9924 sh_type = show_peer;
9925 sh_arg = argv[idx]->arg;
9926 } else
9927 sh_type = show_all;
856ca177 9928
d62a17ae 9929 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 9930}
9931
716b2d8a 9932/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 9933 paths' and `show ip mbgp paths'. Those functions results are the
9934 same.*/
f412b39a 9935DEFUN (show_ip_bgp_paths,
718e3744 9936 show_ip_bgp_paths_cmd,
46f296b4 9937 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 9938 SHOW_STR
9939 IP_STR
9940 BGP_STR
46f296b4 9941 BGP_SAFI_HELP_STR
718e3744 9942 "Path information\n")
9943{
d62a17ae 9944 vty_out(vty, "Address Refcnt Path\n");
9945 aspath_print_all_vty(vty);
9946 return CMD_SUCCESS;
718e3744 9947}
9948
718e3744 9949#include "hash.h"
9950
d62a17ae 9951static void community_show_all_iterator(struct hash_backet *backet,
9952 struct vty *vty)
718e3744 9953{
d62a17ae 9954 struct community *com;
718e3744 9955
d62a17ae 9956 com = (struct community *)backet->data;
9957 vty_out(vty, "[%p] (%ld) %s\n", (void *)backet, com->refcnt,
9958 community_str(com));
718e3744 9959}
9960
9961/* Show BGP's community internal data. */
f412b39a 9962DEFUN (show_ip_bgp_community_info,
718e3744 9963 show_ip_bgp_community_info_cmd,
bec37ba5 9964 "show [ip] bgp community-info",
718e3744 9965 SHOW_STR
9966 IP_STR
9967 BGP_STR
9968 "List all bgp community information\n")
9969{
d62a17ae 9970 vty_out(vty, "Address Refcnt Community\n");
718e3744 9971
d62a17ae 9972 hash_iterate(community_hash(),
9973 (void (*)(struct hash_backet *,
9974 void *))community_show_all_iterator,
9975 vty);
718e3744 9976
d62a17ae 9977 return CMD_SUCCESS;
718e3744 9978}
9979
d62a17ae 9980static void lcommunity_show_all_iterator(struct hash_backet *backet,
9981 struct vty *vty)
57d187bc 9982{
d62a17ae 9983 struct lcommunity *lcom;
57d187bc 9984
d62a17ae 9985 lcom = (struct lcommunity *)backet->data;
9986 vty_out(vty, "[%p] (%ld) %s\n", (void *)backet, lcom->refcnt,
9987 lcommunity_str(lcom));
57d187bc
JS
9988}
9989
9990/* Show BGP's community internal data. */
9991DEFUN (show_ip_bgp_lcommunity_info,
9992 show_ip_bgp_lcommunity_info_cmd,
9993 "show ip bgp large-community-info",
9994 SHOW_STR
9995 IP_STR
9996 BGP_STR
9997 "List all bgp large-community information\n")
9998{
d62a17ae 9999 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10000
d62a17ae 10001 hash_iterate(lcommunity_hash(),
10002 (void (*)(struct hash_backet *,
10003 void *))lcommunity_show_all_iterator,
10004 vty);
57d187bc 10005
d62a17ae 10006 return CMD_SUCCESS;
57d187bc
JS
10007}
10008
10009
f412b39a 10010DEFUN (show_ip_bgp_attr_info,
718e3744 10011 show_ip_bgp_attr_info_cmd,
bec37ba5 10012 "show [ip] bgp attribute-info",
718e3744 10013 SHOW_STR
10014 IP_STR
10015 BGP_STR
10016 "List all bgp attribute information\n")
10017{
d62a17ae 10018 attr_show_all(vty);
10019 return CMD_SUCCESS;
718e3744 10020}
6b0655a2 10021
d62a17ae 10022static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10023 safi_t safi)
f186de26 10024{
d62a17ae 10025 struct listnode *node, *nnode;
10026 struct bgp *bgp;
f186de26 10027
d62a17ae 10028 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10029 vty_out(vty, "\nInstance %s:\n",
10030 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10031 ? "Default"
10032 : bgp->name);
10033 update_group_show(bgp, afi, safi, vty, 0);
10034 }
f186de26 10035}
10036
d62a17ae 10037static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10038 int safi, uint64_t subgrp_id)
4fb25c53 10039{
d62a17ae 10040 struct bgp *bgp;
4fb25c53 10041
d62a17ae 10042 if (name) {
10043 if (strmatch(name, "all")) {
10044 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10045 return CMD_SUCCESS;
10046 } else {
10047 bgp = bgp_lookup_by_name(name);
10048 }
10049 } else {
10050 bgp = bgp_get_default();
10051 }
4fb25c53 10052
d62a17ae 10053 if (bgp)
10054 update_group_show(bgp, afi, safi, vty, subgrp_id);
10055 return CMD_SUCCESS;
4fb25c53
DW
10056}
10057
8fe8a7f6
DS
10058DEFUN (show_ip_bgp_updgrps,
10059 show_ip_bgp_updgrps_cmd,
c1a44e43 10060 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 10061 SHOW_STR
10062 IP_STR
10063 BGP_STR
10064 BGP_INSTANCE_HELP_STR
c9e571b4 10065 BGP_AFI_HELP_STR
9bedbb1e 10066 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
10067 "Detailed info about dynamic update groups\n"
10068 "Specific subgroup to display detailed info for\n")
8386ac43 10069{
d62a17ae 10070 char *vrf = NULL;
10071 afi_t afi = AFI_IP6;
10072 safi_t safi = SAFI_UNICAST;
10073 uint64_t subgrp_id = 0;
10074
10075 int idx = 0;
10076
10077 /* show [ip] bgp */
10078 if (argv_find(argv, argc, "ip", &idx))
10079 afi = AFI_IP;
10080 /* [<view|vrf> VIEWVRFNAME] */
10081 if (argv_find(argv, argc, "view", &idx)
10082 || argv_find(argv, argc, "vrf", &idx))
10083 vrf = argv[++idx]->arg;
10084 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10085 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10086 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10087 }
5bf15956 10088
d62a17ae 10089 /* get subgroup id, if provided */
10090 idx = argc - 1;
10091 if (argv[idx]->type == VARIABLE_TKN)
10092 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 10093
d62a17ae 10094 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
10095}
10096
f186de26 10097DEFUN (show_bgp_instance_all_ipv6_updgrps,
10098 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 10099 "show [ip] bgp <view|vrf> all update-groups",
f186de26 10100 SHOW_STR
716b2d8a 10101 IP_STR
f186de26 10102 BGP_STR
10103 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 10104 "Detailed info about dynamic update groups\n")
f186de26 10105{
d62a17ae 10106 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10107 return CMD_SUCCESS;
f186de26 10108}
10109
5bf15956
DW
10110DEFUN (show_bgp_updgrps_stats,
10111 show_bgp_updgrps_stats_cmd,
716b2d8a 10112 "show [ip] bgp update-groups statistics",
3f9c7369 10113 SHOW_STR
716b2d8a 10114 IP_STR
3f9c7369 10115 BGP_STR
0c7b1b01 10116 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10117 "Statistics\n")
10118{
d62a17ae 10119 struct bgp *bgp;
3f9c7369 10120
d62a17ae 10121 bgp = bgp_get_default();
10122 if (bgp)
10123 update_group_show_stats(bgp, vty);
3f9c7369 10124
d62a17ae 10125 return CMD_SUCCESS;
3f9c7369
DS
10126}
10127
8386ac43 10128DEFUN (show_bgp_instance_updgrps_stats,
10129 show_bgp_instance_updgrps_stats_cmd,
18c57037 10130 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 10131 SHOW_STR
716b2d8a 10132 IP_STR
8386ac43 10133 BGP_STR
10134 BGP_INSTANCE_HELP_STR
0c7b1b01 10135 "Detailed info about dynamic update groups\n"
8386ac43 10136 "Statistics\n")
10137{
d62a17ae 10138 int idx_word = 3;
10139 struct bgp *bgp;
8386ac43 10140
d62a17ae 10141 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10142 if (bgp)
10143 update_group_show_stats(bgp, vty);
8386ac43 10144
d62a17ae 10145 return CMD_SUCCESS;
8386ac43 10146}
10147
d62a17ae 10148static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10149 afi_t afi, safi_t safi,
10150 const char *what, uint64_t subgrp_id)
3f9c7369 10151{
d62a17ae 10152 struct bgp *bgp;
8386ac43 10153
d62a17ae 10154 if (name)
10155 bgp = bgp_lookup_by_name(name);
10156 else
10157 bgp = bgp_get_default();
8386ac43 10158
d62a17ae 10159 if (bgp) {
10160 if (!strcmp(what, "advertise-queue"))
10161 update_group_show_adj_queue(bgp, afi, safi, vty,
10162 subgrp_id);
10163 else if (!strcmp(what, "advertised-routes"))
10164 update_group_show_advertised(bgp, afi, safi, vty,
10165 subgrp_id);
10166 else if (!strcmp(what, "packet-queue"))
10167 update_group_show_packet_queue(bgp, afi, safi, vty,
10168 subgrp_id);
10169 }
3f9c7369
DS
10170}
10171
10172DEFUN (show_ip_bgp_updgrps_adj,
10173 show_ip_bgp_updgrps_adj_cmd,
716b2d8a 10174 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10175 SHOW_STR
10176 IP_STR
10177 BGP_STR
0c7b1b01 10178 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10179 "Advertisement queue\n"
10180 "Announced routes\n"
10181 "Packet queue\n")
10182{
d62a17ae 10183 int idx_type = 4;
10184 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10185 argv[idx_type]->arg, 0);
10186 return CMD_SUCCESS;
8386ac43 10187}
10188
10189DEFUN (show_ip_bgp_instance_updgrps_adj,
10190 show_ip_bgp_instance_updgrps_adj_cmd,
18c57037 10191 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10192 SHOW_STR
10193 IP_STR
10194 BGP_STR
10195 BGP_INSTANCE_HELP_STR
0c7b1b01 10196 "Detailed info about dynamic update groups\n"
8386ac43 10197 "Advertisement queue\n"
10198 "Announced routes\n"
10199 "Packet queue\n")
8386ac43 10200{
d62a17ae 10201 int idx_word = 4;
10202 int idx_type = 6;
10203 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP,
10204 SAFI_UNICAST, argv[idx_type]->arg, 0);
10205 return CMD_SUCCESS;
3f9c7369
DS
10206}
10207
10208DEFUN (show_bgp_updgrps_afi_adj,
10209 show_bgp_updgrps_afi_adj_cmd,
46f296b4 10210 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10211 SHOW_STR
716b2d8a 10212 IP_STR
3f9c7369 10213 BGP_STR
46f296b4 10214 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10215 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10216 "Advertisement queue\n"
10217 "Announced routes\n"
7111c1a0 10218 "Packet queue\n")
3f9c7369 10219{
d62a17ae 10220 int idx_afi = 2;
10221 int idx_safi = 3;
10222 int idx_type = 5;
10223 show_bgp_updgrps_adj_info_aux(
10224 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10225 bgp_vty_safi_from_str(argv[idx_safi]->text),
10226 argv[idx_type]->arg, 0);
10227 return CMD_SUCCESS;
3f9c7369
DS
10228}
10229
10230DEFUN (show_bgp_updgrps_adj,
10231 show_bgp_updgrps_adj_cmd,
716b2d8a 10232 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10233 SHOW_STR
716b2d8a 10234 IP_STR
3f9c7369 10235 BGP_STR
0c7b1b01 10236 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10237 "Advertisement queue\n"
10238 "Announced routes\n"
10239 "Packet queue\n")
10240{
d62a17ae 10241 int idx_type = 3;
10242 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10243 argv[idx_type]->arg, 0);
10244 return CMD_SUCCESS;
8386ac43 10245}
10246
10247DEFUN (show_bgp_instance_updgrps_adj,
10248 show_bgp_instance_updgrps_adj_cmd,
18c57037 10249 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10250 SHOW_STR
716b2d8a 10251 IP_STR
8386ac43 10252 BGP_STR
10253 BGP_INSTANCE_HELP_STR
0c7b1b01 10254 "Detailed info about dynamic update groups\n"
8386ac43 10255 "Advertisement queue\n"
10256 "Announced routes\n"
10257 "Packet queue\n")
10258{
d62a17ae 10259 int idx_word = 3;
10260 int idx_type = 5;
10261 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6,
10262 SAFI_UNICAST, argv[idx_type]->arg, 0);
10263 return CMD_SUCCESS;
3f9c7369
DS
10264}
10265
10266DEFUN (show_ip_bgp_updgrps_adj_s,
8fe8a7f6 10267 show_ip_bgp_updgrps_adj_s_cmd,
716b2d8a 10268 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10269 SHOW_STR
10270 IP_STR
10271 BGP_STR
0c7b1b01 10272 "Detailed info about dynamic update groups\n"
8fe8a7f6 10273 "Specific subgroup to display info for\n"
3f9c7369
DS
10274 "Advertisement queue\n"
10275 "Announced routes\n"
10276 "Packet queue\n")
3f9c7369 10277{
d62a17ae 10278 int idx_subgroup_id = 4;
10279 int idx_type = 5;
10280 uint64_t subgrp_id;
8fe8a7f6 10281
d62a17ae 10282 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10283
d62a17ae 10284 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10285 argv[idx_type]->arg, subgrp_id);
10286 return CMD_SUCCESS;
8386ac43 10287}
10288
10289DEFUN (show_ip_bgp_instance_updgrps_adj_s,
10290 show_ip_bgp_instance_updgrps_adj_s_cmd,
18c57037 10291 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10292 SHOW_STR
10293 IP_STR
10294 BGP_STR
10295 BGP_INSTANCE_HELP_STR
0c7b1b01 10296 "Detailed info about dynamic update groups\n"
8386ac43 10297 "Specific subgroup to display info for\n"
10298 "Advertisement queue\n"
10299 "Announced routes\n"
10300 "Packet queue\n")
8386ac43 10301{
d62a17ae 10302 int idx_vrf = 4;
10303 int idx_subgroup_id = 6;
10304 int idx_type = 7;
10305 uint64_t subgrp_id;
8386ac43 10306
d62a17ae 10307 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8386ac43 10308
d62a17ae 10309 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP,
10310 SAFI_UNICAST, argv[idx_type]->arg,
10311 subgrp_id);
10312 return CMD_SUCCESS;
3f9c7369
DS
10313}
10314
8fe8a7f6
DS
10315DEFUN (show_bgp_updgrps_afi_adj_s,
10316 show_bgp_updgrps_afi_adj_s_cmd,
46f296b4 10317 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10318 SHOW_STR
716b2d8a 10319 IP_STR
3f9c7369 10320 BGP_STR
46f296b4 10321 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10322 "Detailed info about dynamic update groups\n"
8fe8a7f6 10323 "Specific subgroup to display info for\n"
3f9c7369
DS
10324 "Advertisement queue\n"
10325 "Announced routes\n"
7111c1a0 10326 "Packet queue\n")
3f9c7369 10327{
d62a17ae 10328 int idx_afi = 2;
10329 int idx_safi = 3;
10330 int idx_subgroup_id = 5;
10331 int idx_type = 6;
10332 uint64_t subgrp_id;
3f9c7369 10333
d62a17ae 10334 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10335
d62a17ae 10336 show_bgp_updgrps_adj_info_aux(
10337 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10338 bgp_vty_safi_from_str(argv[idx_safi]->text),
10339 argv[idx_type]->arg, subgrp_id);
10340 return CMD_SUCCESS;
3f9c7369
DS
10341}
10342
8fe8a7f6
DS
10343DEFUN (show_bgp_updgrps_adj_s,
10344 show_bgp_updgrps_adj_s_cmd,
716b2d8a 10345 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8fe8a7f6 10346 SHOW_STR
716b2d8a 10347 IP_STR
8fe8a7f6 10348 BGP_STR
0c7b1b01 10349 "Detailed info about dynamic update groups\n"
8fe8a7f6
DS
10350 "Specific subgroup to display info for\n"
10351 "Advertisement queue\n"
10352 "Announced routes\n"
10353 "Packet queue\n")
10354{
d62a17ae 10355 int idx_subgroup_id = 3;
10356 int idx_type = 4;
10357 uint64_t subgrp_id;
8fe8a7f6 10358
d62a17ae 10359 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10360
d62a17ae 10361 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10362 argv[idx_type]->arg, subgrp_id);
10363 return CMD_SUCCESS;
8fe8a7f6
DS
10364}
10365
8386ac43 10366DEFUN (show_bgp_instance_updgrps_adj_s,
10367 show_bgp_instance_updgrps_adj_s_cmd,
18c57037 10368 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10369 SHOW_STR
716b2d8a 10370 IP_STR
8386ac43 10371 BGP_STR
10372 BGP_INSTANCE_HELP_STR
0c7b1b01 10373 "Detailed info about dynamic update groups\n"
8386ac43 10374 "Specific subgroup to display info for\n"
10375 "Advertisement queue\n"
10376 "Announced routes\n"
10377 "Packet queue\n")
10378{
d62a17ae 10379 int idx_vrf = 3;
10380 int idx_subgroup_id = 5;
10381 int idx_type = 6;
10382 uint64_t subgrp_id;
10383
10384 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10385
10386 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6,
10387 SAFI_UNICAST, argv[idx_type]->arg,
10388 subgrp_id);
10389 return CMD_SUCCESS;
10390}
10391
10392
10393static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10394{
10395 struct listnode *node, *nnode;
10396 struct prefix *range;
10397 struct peer *conf;
10398 struct peer *peer;
10399 char buf[PREFIX2STR_BUFFER];
10400 afi_t afi;
10401 safi_t safi;
10402 const char *peer_status;
10403 const char *af_str;
10404 int lr_count;
10405 int dynamic;
10406 int af_cfgd;
10407
10408 conf = group->conf;
10409
10410 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10411 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10412 conf->as);
10413 } else if (conf->as_type == AS_INTERNAL) {
10414 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10415 group->bgp->as);
10416 } else {
10417 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10418 }
f14e6fdb 10419
d62a17ae 10420 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10421 vty_out(vty, " Peer-group type is internal\n");
10422 else
10423 vty_out(vty, " Peer-group type is external\n");
10424
10425 /* Display AFs configured. */
10426 vty_out(vty, " Configured address-families:");
10427 for (afi = AFI_IP; afi < AFI_MAX; afi++)
10428 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
10429 if (conf->afc[afi][safi]) {
10430 af_cfgd = 1;
10431 vty_out(vty, " %s;", afi_safi_print(afi, safi));
10432 }
10433 }
10434 if (!af_cfgd)
10435 vty_out(vty, " none\n");
10436 else
10437 vty_out(vty, "\n");
10438
10439 /* Display listen ranges (for dynamic neighbors), if any */
10440 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10441 if (afi == AFI_IP)
10442 af_str = "IPv4";
10443 else if (afi == AFI_IP6)
10444 af_str = "IPv6";
10445 else
10446 af_str = "???";
10447 lr_count = listcount(group->listen_range[afi]);
10448 if (lr_count) {
10449 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10450 af_str);
10451
10452
10453 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10454 nnode, range)) {
10455 prefix2str(range, buf, sizeof(buf));
10456 vty_out(vty, " %s\n", buf);
10457 }
10458 }
10459 }
f14e6fdb 10460
d62a17ae 10461 /* Display group members and their status */
10462 if (listcount(group->peer)) {
10463 vty_out(vty, " Peer-group members:\n");
10464 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10465 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10466 peer_status = "Idle (Admin)";
10467 else if (CHECK_FLAG(peer->sflags,
10468 PEER_STATUS_PREFIX_OVERFLOW))
10469 peer_status = "Idle (PfxCt)";
10470 else
10471 peer_status = lookup_msg(bgp_status_msg,
10472 peer->status, NULL);
10473
10474 dynamic = peer_dynamic_neighbor(peer);
10475 vty_out(vty, " %s %s %s \n", peer->host,
10476 dynamic ? "(dynamic)" : "", peer_status);
10477 }
10478 }
f14e6fdb 10479
d62a17ae 10480 return CMD_SUCCESS;
10481}
10482
10483/* Show BGP peer group's information. */
10484enum show_group_type { show_all_groups, show_peer_group };
10485
10486static int bgp_show_peer_group(struct vty *vty, struct bgp *bgp,
10487 enum show_group_type type,
10488 const char *group_name)
10489{
10490 struct listnode *node, *nnode;
10491 struct peer_group *group;
10492 int find = 0;
10493
10494 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
10495 switch (type) {
10496 case show_all_groups:
10497 bgp_show_one_peer_group(vty, group);
10498 break;
10499 case show_peer_group:
10500 if (group_name
10501 && (strcmp(group->name, group_name) == 0)) {
10502 find = 1;
10503 bgp_show_one_peer_group(vty, group);
10504 }
10505 break;
10506 }
f14e6fdb 10507 }
f14e6fdb 10508
d62a17ae 10509 if (type == show_peer_group && !find)
10510 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 10511
d62a17ae 10512 return CMD_SUCCESS;
f14e6fdb
DS
10513}
10514
d62a17ae 10515static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10516 enum show_group_type type,
10517 const char *group_name)
f14e6fdb 10518{
d62a17ae 10519 struct bgp *bgp;
10520 int ret = CMD_SUCCESS;
f14e6fdb 10521
d62a17ae 10522 if (name)
10523 bgp = bgp_lookup_by_name(name);
10524 else
10525 bgp = bgp_get_default();
f14e6fdb 10526
d62a17ae 10527 if (!bgp) {
10528 vty_out(vty, "%% No such BGP instance exist\n");
10529 return CMD_WARNING;
10530 }
f14e6fdb 10531
d62a17ae 10532 ret = bgp_show_peer_group(vty, bgp, type, group_name);
f14e6fdb 10533
d62a17ae 10534 return ret;
f14e6fdb
DS
10535}
10536
10537DEFUN (show_ip_bgp_peer_groups,
10538 show_ip_bgp_peer_groups_cmd,
18c57037 10539 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10540 SHOW_STR
10541 IP_STR
10542 BGP_STR
8386ac43 10543 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10544 "Detailed information on BGP peer groups\n"
10545 "Peer group name\n")
f14e6fdb 10546{
d62a17ae 10547 char *vrf, *pg;
10548 vrf = pg = NULL;
10549 int idx = 0;
f14e6fdb 10550
d62a17ae 10551 vrf = argv_find(argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL;
10552 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10553
d62a17ae 10554 return bgp_show_peer_group_vty(vty, vrf, show_all_groups, pg);
f14e6fdb 10555}
3f9c7369 10556
d6e3c605 10557
718e3744 10558/* Redistribute VTY commands. */
10559
718e3744 10560DEFUN (bgp_redistribute_ipv4,
10561 bgp_redistribute_ipv4_cmd,
40d1cbfb 10562 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 10563 "Redistribute information from another routing protocol\n"
ab0181ee 10564 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 10565{
d62a17ae 10566 VTY_DECLVAR_CONTEXT(bgp, bgp);
10567 int idx_protocol = 1;
10568 int type;
718e3744 10569
d62a17ae 10570 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10571 if (type < 0) {
10572 vty_out(vty, "%% Invalid route type\n");
10573 return CMD_WARNING_CONFIG_FAILED;
10574 }
10575 bgp_redist_add(bgp, AFI_IP, type, 0);
10576 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10577}
10578
d62a17ae 10579ALIAS_HIDDEN(
10580 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10581 "redistribute " FRR_IP_REDIST_STR_BGPD,
10582 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 10583
718e3744 10584DEFUN (bgp_redistribute_ipv4_rmap,
10585 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 10586 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 10587 "Redistribute information from another routing protocol\n"
ab0181ee 10588 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10589 "Route map reference\n"
10590 "Pointer to route-map entries\n")
10591{
d62a17ae 10592 VTY_DECLVAR_CONTEXT(bgp, bgp);
10593 int idx_protocol = 1;
10594 int idx_word = 3;
10595 int type;
10596 struct bgp_redist *red;
718e3744 10597
d62a17ae 10598 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10599 if (type < 0) {
10600 vty_out(vty, "%% Invalid route type\n");
10601 return CMD_WARNING_CONFIG_FAILED;
10602 }
718e3744 10603
d62a17ae 10604 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10605 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10606 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10607}
10608
d62a17ae 10609ALIAS_HIDDEN(
10610 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
10611 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10612 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10613 "Route map reference\n"
10614 "Pointer to route-map entries\n")
596c17ba 10615
718e3744 10616DEFUN (bgp_redistribute_ipv4_metric,
10617 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 10618 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 10619 "Redistribute information from another routing protocol\n"
ab0181ee 10620 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10621 "Metric for redistributed routes\n"
10622 "Default metric\n")
10623{
d62a17ae 10624 VTY_DECLVAR_CONTEXT(bgp, bgp);
10625 int idx_protocol = 1;
10626 int idx_number = 3;
10627 int type;
10628 u_int32_t metric;
10629 struct bgp_redist *red;
10630
10631 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10632 if (type < 0) {
10633 vty_out(vty, "%% Invalid route type\n");
10634 return CMD_WARNING_CONFIG_FAILED;
10635 }
10636 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10637
10638 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10639 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10640 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10641}
10642
10643ALIAS_HIDDEN(
10644 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
10645 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10646 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10647 "Metric for redistributed routes\n"
10648 "Default metric\n")
596c17ba 10649
718e3744 10650DEFUN (bgp_redistribute_ipv4_rmap_metric,
10651 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 10652 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 10653 "Redistribute information from another routing protocol\n"
ab0181ee 10654 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10655 "Route map reference\n"
10656 "Pointer to route-map entries\n"
10657 "Metric for redistributed routes\n"
10658 "Default metric\n")
10659{
d62a17ae 10660 VTY_DECLVAR_CONTEXT(bgp, bgp);
10661 int idx_protocol = 1;
10662 int idx_word = 3;
10663 int idx_number = 5;
10664 int type;
10665 u_int32_t metric;
10666 struct bgp_redist *red;
10667
10668 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10669 if (type < 0) {
10670 vty_out(vty, "%% Invalid route type\n");
10671 return CMD_WARNING_CONFIG_FAILED;
10672 }
10673 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10674
10675 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10676 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10677 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10678 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10679}
10680
10681ALIAS_HIDDEN(
10682 bgp_redistribute_ipv4_rmap_metric,
10683 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10684 "redistribute " FRR_IP_REDIST_STR_BGPD
10685 " route-map WORD metric (0-4294967295)",
10686 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10687 "Route map reference\n"
10688 "Pointer to route-map entries\n"
10689 "Metric for redistributed routes\n"
10690 "Default metric\n")
596c17ba 10691
718e3744 10692DEFUN (bgp_redistribute_ipv4_metric_rmap,
10693 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 10694 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 10695 "Redistribute information from another routing protocol\n"
ab0181ee 10696 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10697 "Metric for redistributed routes\n"
10698 "Default metric\n"
10699 "Route map reference\n"
10700 "Pointer to route-map entries\n")
10701{
d62a17ae 10702 VTY_DECLVAR_CONTEXT(bgp, bgp);
10703 int idx_protocol = 1;
10704 int idx_number = 3;
10705 int idx_word = 5;
10706 int type;
10707 u_int32_t metric;
10708 struct bgp_redist *red;
10709
10710 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10711 if (type < 0) {
10712 vty_out(vty, "%% Invalid route type\n");
10713 return CMD_WARNING_CONFIG_FAILED;
10714 }
10715 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10716
10717 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10718 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10719 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10720 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10721}
10722
10723ALIAS_HIDDEN(
10724 bgp_redistribute_ipv4_metric_rmap,
10725 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10726 "redistribute " FRR_IP_REDIST_STR_BGPD
10727 " metric (0-4294967295) route-map WORD",
10728 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10729 "Metric for redistributed routes\n"
10730 "Default metric\n"
10731 "Route map reference\n"
10732 "Pointer to route-map entries\n")
596c17ba 10733
7c8ff89e
DS
10734DEFUN (bgp_redistribute_ipv4_ospf,
10735 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 10736 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
10737 "Redistribute information from another routing protocol\n"
10738 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10739 "Non-main Kernel Routing Table\n"
10740 "Instance ID/Table ID\n")
7c8ff89e 10741{
d62a17ae 10742 VTY_DECLVAR_CONTEXT(bgp, bgp);
10743 int idx_ospf_table = 1;
10744 int idx_number = 2;
10745 u_short instance;
10746 u_short protocol;
7c8ff89e 10747
d62a17ae 10748 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 10749
d62a17ae 10750 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10751 protocol = ZEBRA_ROUTE_OSPF;
10752 else
10753 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 10754
d62a17ae 10755 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10756 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10757}
10758
d62a17ae 10759ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
10760 "redistribute <ospf|table> (1-65535)",
10761 "Redistribute information from another routing protocol\n"
10762 "Open Shortest Path First (OSPFv2)\n"
10763 "Non-main Kernel Routing Table\n"
10764 "Instance ID/Table ID\n")
596c17ba 10765
7c8ff89e
DS
10766DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10767 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 10768 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
10769 "Redistribute information from another routing protocol\n"
10770 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10771 "Non-main Kernel Routing Table\n"
10772 "Instance ID/Table ID\n"
7c8ff89e
DS
10773 "Route map reference\n"
10774 "Pointer to route-map entries\n")
10775{
d62a17ae 10776 VTY_DECLVAR_CONTEXT(bgp, bgp);
10777 int idx_ospf_table = 1;
10778 int idx_number = 2;
10779 int idx_word = 4;
10780 struct bgp_redist *red;
10781 u_short instance;
10782 int protocol;
10783
10784 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10785 protocol = ZEBRA_ROUTE_OSPF;
10786 else
10787 protocol = ZEBRA_ROUTE_TABLE;
10788
10789 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10790 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10791 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10792 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10793}
10794
10795ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
10796 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10797 "redistribute <ospf|table> (1-65535) route-map WORD",
10798 "Redistribute information from another routing protocol\n"
10799 "Open Shortest Path First (OSPFv2)\n"
10800 "Non-main Kernel Routing Table\n"
10801 "Instance ID/Table ID\n"
10802 "Route map reference\n"
10803 "Pointer to route-map entries\n")
596c17ba 10804
7c8ff89e
DS
10805DEFUN (bgp_redistribute_ipv4_ospf_metric,
10806 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 10807 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
10808 "Redistribute information from another routing protocol\n"
10809 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10810 "Non-main Kernel Routing Table\n"
10811 "Instance ID/Table ID\n"
7c8ff89e
DS
10812 "Metric for redistributed routes\n"
10813 "Default metric\n")
10814{
d62a17ae 10815 VTY_DECLVAR_CONTEXT(bgp, bgp);
10816 int idx_ospf_table = 1;
10817 int idx_number = 2;
10818 int idx_number_2 = 4;
10819 u_int32_t metric;
10820 struct bgp_redist *red;
10821 u_short instance;
10822 int protocol;
10823
10824 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10825 protocol = ZEBRA_ROUTE_OSPF;
10826 else
10827 protocol = ZEBRA_ROUTE_TABLE;
10828
10829 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10830 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10831
10832 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10833 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10834 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10835}
10836
10837ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
10838 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10839 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10840 "Redistribute information from another routing protocol\n"
10841 "Open Shortest Path First (OSPFv2)\n"
10842 "Non-main Kernel Routing Table\n"
10843 "Instance ID/Table ID\n"
10844 "Metric for redistributed routes\n"
10845 "Default metric\n")
596c17ba 10846
7c8ff89e
DS
10847DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10848 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 10849 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
10850 "Redistribute information from another routing protocol\n"
10851 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10852 "Non-main Kernel Routing Table\n"
10853 "Instance ID/Table ID\n"
7c8ff89e
DS
10854 "Route map reference\n"
10855 "Pointer to route-map entries\n"
10856 "Metric for redistributed routes\n"
10857 "Default metric\n")
10858{
d62a17ae 10859 VTY_DECLVAR_CONTEXT(bgp, bgp);
10860 int idx_ospf_table = 1;
10861 int idx_number = 2;
10862 int idx_word = 4;
10863 int idx_number_2 = 6;
10864 u_int32_t metric;
10865 struct bgp_redist *red;
10866 u_short instance;
10867 int protocol;
10868
10869 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10870 protocol = ZEBRA_ROUTE_OSPF;
10871 else
10872 protocol = ZEBRA_ROUTE_TABLE;
10873
10874 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10875 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10876
10877 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10878 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10879 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10880 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10881}
10882
10883ALIAS_HIDDEN(
10884 bgp_redistribute_ipv4_ospf_rmap_metric,
10885 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10886 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10887 "Redistribute information from another routing protocol\n"
10888 "Open Shortest Path First (OSPFv2)\n"
10889 "Non-main Kernel Routing Table\n"
10890 "Instance ID/Table ID\n"
10891 "Route map reference\n"
10892 "Pointer to route-map entries\n"
10893 "Metric for redistributed routes\n"
10894 "Default metric\n")
596c17ba 10895
7c8ff89e
DS
10896DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
10897 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 10898 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
10899 "Redistribute information from another routing protocol\n"
10900 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10901 "Non-main Kernel Routing Table\n"
10902 "Instance ID/Table ID\n"
7c8ff89e
DS
10903 "Metric for redistributed routes\n"
10904 "Default metric\n"
10905 "Route map reference\n"
10906 "Pointer to route-map entries\n")
10907{
d62a17ae 10908 VTY_DECLVAR_CONTEXT(bgp, bgp);
10909 int idx_ospf_table = 1;
10910 int idx_number = 2;
10911 int idx_number_2 = 4;
10912 int idx_word = 6;
10913 u_int32_t metric;
10914 struct bgp_redist *red;
10915 u_short instance;
10916 int protocol;
10917
10918 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10919 protocol = ZEBRA_ROUTE_OSPF;
10920 else
10921 protocol = ZEBRA_ROUTE_TABLE;
10922
10923 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10924 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10925
10926 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10927 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10928 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10929 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10930}
10931
10932ALIAS_HIDDEN(
10933 bgp_redistribute_ipv4_ospf_metric_rmap,
10934 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
10935 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10936 "Redistribute information from another routing protocol\n"
10937 "Open Shortest Path First (OSPFv2)\n"
10938 "Non-main Kernel Routing Table\n"
10939 "Instance ID/Table ID\n"
10940 "Metric for redistributed routes\n"
10941 "Default metric\n"
10942 "Route map reference\n"
10943 "Pointer to route-map entries\n")
596c17ba 10944
7c8ff89e
DS
10945DEFUN (no_bgp_redistribute_ipv4_ospf,
10946 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 10947 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
10948 NO_STR
10949 "Redistribute information from another routing protocol\n"
10950 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 10951 "Non-main Kernel Routing Table\n"
31500417
DW
10952 "Instance ID/Table ID\n"
10953 "Metric for redistributed routes\n"
10954 "Default metric\n"
10955 "Route map reference\n"
10956 "Pointer to route-map entries\n")
7c8ff89e 10957{
d62a17ae 10958 VTY_DECLVAR_CONTEXT(bgp, bgp);
10959 int idx_ospf_table = 2;
10960 int idx_number = 3;
10961 u_short instance;
10962 int protocol;
10963
10964 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10965 protocol = ZEBRA_ROUTE_OSPF;
10966 else
10967 protocol = ZEBRA_ROUTE_TABLE;
10968
10969 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10970 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
10971}
10972
10973ALIAS_HIDDEN(
10974 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
10975 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
10976 NO_STR
10977 "Redistribute information from another routing protocol\n"
10978 "Open Shortest Path First (OSPFv2)\n"
10979 "Non-main Kernel Routing Table\n"
10980 "Instance ID/Table ID\n"
10981 "Metric for redistributed routes\n"
10982 "Default metric\n"
10983 "Route map reference\n"
10984 "Pointer to route-map entries\n")
596c17ba 10985
718e3744 10986DEFUN (no_bgp_redistribute_ipv4,
10987 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 10988 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 10989 NO_STR
10990 "Redistribute information from another routing protocol\n"
3b14d86e 10991 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
10992 "Metric for redistributed routes\n"
10993 "Default metric\n"
10994 "Route map reference\n"
10995 "Pointer to route-map entries\n")
718e3744 10996{
d62a17ae 10997 VTY_DECLVAR_CONTEXT(bgp, bgp);
10998 int idx_protocol = 2;
10999 int type;
11000
11001 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11002 if (type < 0) {
11003 vty_out(vty, "%% Invalid route type\n");
11004 return CMD_WARNING_CONFIG_FAILED;
11005 }
11006 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11007}
11008
11009ALIAS_HIDDEN(
11010 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11011 "no redistribute " FRR_IP_REDIST_STR_BGPD
11012 " [metric (0-4294967295)] [route-map WORD]",
11013 NO_STR
11014 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11015 "Metric for redistributed routes\n"
11016 "Default metric\n"
11017 "Route map reference\n"
11018 "Pointer to route-map entries\n")
596c17ba 11019
718e3744 11020DEFUN (bgp_redistribute_ipv6,
11021 bgp_redistribute_ipv6_cmd,
40d1cbfb 11022 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11023 "Redistribute information from another routing protocol\n"
ab0181ee 11024 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11025{
d62a17ae 11026 VTY_DECLVAR_CONTEXT(bgp, bgp);
11027 int idx_protocol = 1;
11028 int type;
718e3744 11029
d62a17ae 11030 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11031 if (type < 0) {
11032 vty_out(vty, "%% Invalid route type\n");
11033 return CMD_WARNING_CONFIG_FAILED;
11034 }
718e3744 11035
d62a17ae 11036 bgp_redist_add(bgp, AFI_IP6, type, 0);
11037 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11038}
11039
11040DEFUN (bgp_redistribute_ipv6_rmap,
11041 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11042 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11043 "Redistribute information from another routing protocol\n"
ab0181ee 11044 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11045 "Route map reference\n"
11046 "Pointer to route-map entries\n")
11047{
d62a17ae 11048 VTY_DECLVAR_CONTEXT(bgp, bgp);
11049 int idx_protocol = 1;
11050 int idx_word = 3;
11051 int type;
11052 struct bgp_redist *red;
718e3744 11053
d62a17ae 11054 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11055 if (type < 0) {
11056 vty_out(vty, "%% Invalid route type\n");
11057 return CMD_WARNING_CONFIG_FAILED;
11058 }
718e3744 11059
d62a17ae 11060 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11061 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11062 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11063}
11064
11065DEFUN (bgp_redistribute_ipv6_metric,
11066 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11067 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11068 "Redistribute information from another routing protocol\n"
ab0181ee 11069 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11070 "Metric for redistributed routes\n"
11071 "Default metric\n")
11072{
d62a17ae 11073 VTY_DECLVAR_CONTEXT(bgp, bgp);
11074 int idx_protocol = 1;
11075 int idx_number = 3;
11076 int type;
11077 u_int32_t metric;
11078 struct bgp_redist *red;
11079
11080 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11081 if (type < 0) {
11082 vty_out(vty, "%% Invalid route type\n");
11083 return CMD_WARNING_CONFIG_FAILED;
11084 }
11085 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11086
d62a17ae 11087 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11088 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11089 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11090}
11091
11092DEFUN (bgp_redistribute_ipv6_rmap_metric,
11093 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11094 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11095 "Redistribute information from another routing protocol\n"
ab0181ee 11096 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11097 "Route map reference\n"
11098 "Pointer to route-map entries\n"
11099 "Metric for redistributed routes\n"
11100 "Default metric\n")
11101{
d62a17ae 11102 VTY_DECLVAR_CONTEXT(bgp, bgp);
11103 int idx_protocol = 1;
11104 int idx_word = 3;
11105 int idx_number = 5;
11106 int type;
11107 u_int32_t metric;
11108 struct bgp_redist *red;
11109
11110 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11111 if (type < 0) {
11112 vty_out(vty, "%% Invalid route type\n");
11113 return CMD_WARNING_CONFIG_FAILED;
11114 }
11115 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11116
d62a17ae 11117 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11118 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11119 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11120 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11121}
11122
11123DEFUN (bgp_redistribute_ipv6_metric_rmap,
11124 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11125 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11126 "Redistribute information from another routing protocol\n"
ab0181ee 11127 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11128 "Metric for redistributed routes\n"
11129 "Default metric\n"
11130 "Route map reference\n"
11131 "Pointer to route-map entries\n")
11132{
d62a17ae 11133 VTY_DECLVAR_CONTEXT(bgp, bgp);
11134 int idx_protocol = 1;
11135 int idx_number = 3;
11136 int idx_word = 5;
11137 int type;
11138 u_int32_t metric;
11139 struct bgp_redist *red;
11140
11141 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11142 if (type < 0) {
11143 vty_out(vty, "%% Invalid route type\n");
11144 return CMD_WARNING_CONFIG_FAILED;
11145 }
11146 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11147
d62a17ae 11148 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11149 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11150 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11151 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11152}
11153
11154DEFUN (no_bgp_redistribute_ipv6,
11155 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11156 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11157 NO_STR
11158 "Redistribute information from another routing protocol\n"
3b14d86e 11159 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11160 "Metric for redistributed routes\n"
11161 "Default metric\n"
11162 "Route map reference\n"
11163 "Pointer to route-map entries\n")
718e3744 11164{
d62a17ae 11165 VTY_DECLVAR_CONTEXT(bgp, bgp);
11166 int idx_protocol = 2;
11167 int type;
718e3744 11168
d62a17ae 11169 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11170 if (type < 0) {
11171 vty_out(vty, "%% Invalid route type\n");
11172 return CMD_WARNING_CONFIG_FAILED;
11173 }
718e3744 11174
d62a17ae 11175 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11176}
11177
11178int bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
11179 safi_t safi, int *write)
11180{
11181 int i;
11182
11183 /* Unicast redistribution only. */
11184 if (safi != SAFI_UNICAST)
11185 return 0;
11186
11187 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11188 /* Redistribute BGP does not make sense. */
11189 if (i != ZEBRA_ROUTE_BGP) {
11190 struct list *red_list;
11191 struct listnode *node;
11192 struct bgp_redist *red;
11193
11194 red_list = bgp->redist[afi][i];
11195 if (!red_list)
11196 continue;
11197
11198 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
11199 /* Display "address-family" when it is not yet
11200 * diplayed. */
11201 bgp_config_write_family_header(vty, afi, safi,
11202 write);
11203
11204 /* "redistribute" configuration. */
11205 vty_out(vty, " redistribute %s",
11206 zebra_route_string(i));
11207 if (red->instance)
11208 vty_out(vty, " %d", red->instance);
11209 if (red->redist_metric_flag)
11210 vty_out(vty, " metric %u",
11211 red->redist_metric);
11212 if (red->rmap.name)
11213 vty_out(vty, " route-map %s",
11214 red->rmap.name);
11215 vty_out(vty, "\n");
11216 }
11217 }
11218 }
11219 return *write;
718e3744 11220}
6b0655a2 11221
718e3744 11222/* BGP node structure. */
d62a17ae 11223static struct cmd_node bgp_node = {
9d303b37 11224 BGP_NODE, "%s(config-router)# ", 1,
718e3744 11225};
11226
d62a17ae 11227static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 11228 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 11229};
11230
d62a17ae 11231static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 11232 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 11233};
11234
d62a17ae 11235static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 11236 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11237};
11238
d62a17ae 11239static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 11240 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 11241};
11242
d62a17ae 11243static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 11244 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 11245};
11246
d62a17ae 11247static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 11248 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11249};
11250
d62a17ae 11251static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11252 "%s(config-router-af)# ", 1};
6b0655a2 11253
d62a17ae 11254static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11255 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 11256
d62a17ae 11257static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11258 "%s(config-router-evpn)# ", 1};
4e0b7b6d 11259
d62a17ae 11260static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11261 "%s(config-router-af-vni)# ", 1};
90e60aa7 11262
d62a17ae 11263static void community_list_vty(void);
1f8ae70b 11264
d62a17ae 11265static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 11266{
d62a17ae 11267 struct bgp *bgp;
11268 struct peer *peer;
11269 struct peer_group *group;
11270 struct listnode *lnbgp, *lnpeer;
b8a815e5 11271
d62a17ae 11272 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11273 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11274 /* only provide suggestions on the appropriate input
11275 * token type,
11276 * they'll otherwise show up multiple times */
11277 enum cmd_token_type match_type;
11278 char *name = peer->host;
d48ed3e0 11279
d62a17ae 11280 if (peer->conf_if) {
11281 match_type = VARIABLE_TKN;
11282 name = peer->conf_if;
11283 } else if (strchr(peer->host, ':'))
11284 match_type = IPV6_TKN;
11285 else
11286 match_type = IPV4_TKN;
d48ed3e0 11287
d62a17ae 11288 if (token->type != match_type)
11289 continue;
d48ed3e0 11290
d62a17ae 11291 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11292 }
d48ed3e0 11293
d62a17ae 11294 if (token->type == VARIABLE_TKN)
11295 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11296 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11297 group->name));
11298 }
b8a815e5
DL
11299}
11300
11301static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 11302 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11303 {.varname = "neighbors", .completions = bgp_ac_neighbor},
11304 {.completions = NULL}};
11305
11306void bgp_vty_init(void)
11307{
11308 cmd_variable_handler_register(bgp_var_neighbor);
11309
11310 /* Install bgp top node. */
11311 install_node(&bgp_node, bgp_config_write);
11312 install_node(&bgp_ipv4_unicast_node, NULL);
11313 install_node(&bgp_ipv4_multicast_node, NULL);
11314 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11315 install_node(&bgp_ipv6_unicast_node, NULL);
11316 install_node(&bgp_ipv6_multicast_node, NULL);
11317 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11318 install_node(&bgp_vpnv4_node, NULL);
11319 install_node(&bgp_vpnv6_node, NULL);
11320 install_node(&bgp_evpn_node, NULL);
11321 install_node(&bgp_evpn_vni_node, NULL);
11322
11323 /* Install default VTY commands to new nodes. */
11324 install_default(BGP_NODE);
11325 install_default(BGP_IPV4_NODE);
11326 install_default(BGP_IPV4M_NODE);
11327 install_default(BGP_IPV4L_NODE);
11328 install_default(BGP_IPV6_NODE);
11329 install_default(BGP_IPV6M_NODE);
11330 install_default(BGP_IPV6L_NODE);
11331 install_default(BGP_VPNV4_NODE);
11332 install_default(BGP_VPNV6_NODE);
11333 install_default(BGP_EVPN_NODE);
11334 install_default(BGP_EVPN_VNI_NODE);
11335
11336 /* "bgp multiple-instance" commands. */
11337 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11338 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11339
11340 /* "bgp config-type" commands. */
11341 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11342 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11343
11344 /* bgp route-map delay-timer commands. */
11345 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11346 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11347
11348 /* Dummy commands (Currently not supported) */
11349 install_element(BGP_NODE, &no_synchronization_cmd);
11350 install_element(BGP_NODE, &no_auto_summary_cmd);
11351
11352 /* "router bgp" commands. */
11353 install_element(CONFIG_NODE, &router_bgp_cmd);
11354
11355 /* "no router bgp" commands. */
11356 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11357
11358 /* "bgp router-id" commands. */
11359 install_element(BGP_NODE, &bgp_router_id_cmd);
11360 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11361
11362 /* "bgp cluster-id" commands. */
11363 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11364 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11365
11366 /* "bgp confederation" commands. */
11367 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11368 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11369
11370 /* "bgp confederation peers" commands. */
11371 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11372 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11373
11374 /* bgp max-med command */
11375 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11376 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11377 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11378 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11379 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11380
11381 /* bgp disable-ebgp-connected-nh-check */
11382 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11383 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11384
11385 /* bgp update-delay command */
11386 install_element(BGP_NODE, &bgp_update_delay_cmd);
11387 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11388 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11389
11390 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11391 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
11392
11393 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11394 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11395
11396 /* "maximum-paths" commands. */
11397 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11398 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11399 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11400 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11401 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11402 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11403 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11404 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11405 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11406 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11407 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11408 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11409 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11410 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11411 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11412
11413 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11414 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11415 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11416 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11417 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11418
11419 /* "timers bgp" commands. */
11420 install_element(BGP_NODE, &bgp_timers_cmd);
11421 install_element(BGP_NODE, &no_bgp_timers_cmd);
11422
11423 /* route-map delay-timer commands - per instance for backwards compat.
11424 */
11425 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11426 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11427
11428 /* "bgp client-to-client reflection" commands */
11429 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11430 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11431
11432 /* "bgp always-compare-med" commands */
11433 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11434 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11435
11436 /* "bgp deterministic-med" commands */
11437 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11438 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11439
11440 /* "bgp graceful-restart" commands */
11441 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11442 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11443 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11444 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11445 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11446 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11447
11448 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11449 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11450
11451 /* "bgp fast-external-failover" commands */
11452 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11453 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11454
11455 /* "bgp enforce-first-as" commands */
11456 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11457 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11458
11459 /* "bgp bestpath compare-routerid" commands */
11460 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11461 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11462
11463 /* "bgp bestpath as-path ignore" commands */
11464 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11465 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11466
11467 /* "bgp bestpath as-path confed" commands */
11468 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11469 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11470
11471 /* "bgp bestpath as-path multipath-relax" commands */
11472 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11473 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11474
11475 /* "bgp log-neighbor-changes" commands */
11476 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11477 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11478
11479 /* "bgp bestpath med" commands */
11480 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11481 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11482
11483 /* "no bgp default ipv4-unicast" commands. */
11484 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11485 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11486
11487 /* "bgp network import-check" commands. */
11488 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11489 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11490 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11491
11492 /* "bgp default local-preference" commands. */
11493 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11494 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11495
11496 /* bgp default show-hostname */
11497 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11498 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11499
11500 /* "bgp default subgroup-pkt-queue-max" commands. */
11501 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11502 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11503
11504 /* bgp ibgp-allow-policy-mods command */
11505 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11506 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11507
11508 /* "bgp listen limit" commands. */
11509 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11510 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11511
11512 /* "bgp listen range" commands. */
11513 install_element(BGP_NODE, &bgp_listen_range_cmd);
11514 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11515
11516 /* "neighbor remote-as" commands. */
11517 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11518 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11519 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11520 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11521 install_element(BGP_NODE,
11522 &neighbor_interface_v6only_config_remote_as_cmd);
11523 install_element(BGP_NODE, &no_neighbor_cmd);
11524 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
11525
11526 /* "neighbor peer-group" commands. */
11527 install_element(BGP_NODE, &neighbor_peer_group_cmd);
11528 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
11529 install_element(BGP_NODE,
11530 &no_neighbor_interface_peer_group_remote_as_cmd);
11531
11532 /* "neighbor local-as" commands. */
11533 install_element(BGP_NODE, &neighbor_local_as_cmd);
11534 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
11535 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
11536 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
11537
11538 /* "neighbor solo" commands. */
11539 install_element(BGP_NODE, &neighbor_solo_cmd);
11540 install_element(BGP_NODE, &no_neighbor_solo_cmd);
11541
11542 /* "neighbor password" commands. */
11543 install_element(BGP_NODE, &neighbor_password_cmd);
11544 install_element(BGP_NODE, &no_neighbor_password_cmd);
11545
11546 /* "neighbor activate" commands. */
11547 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
11548 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
11549 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
11550 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
11551 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
11552 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
11553 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
11554 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
11555 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
11556 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
11557
11558 /* "no neighbor activate" commands. */
11559 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
11560 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11561 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
11562 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
11563 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
11564 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
11565 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
11566 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
11567 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
11568 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
11569
11570 /* "neighbor peer-group" set commands. */
11571 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
11572 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11573 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11574 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11575 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11576 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11577 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11578 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11579
11580 /* "no neighbor peer-group unset" commands. */
11581 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
11582 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11583 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11584 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11585 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11586 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11587 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11588 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11589
11590 /* "neighbor softreconfiguration inbound" commands.*/
11591 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11592 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
11593 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11594 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11595 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11596 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11597 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11598 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11599 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11600 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11601 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11602 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11603 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11604 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11605 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11606 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11607 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11608 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11609
11610 /* "neighbor attribute-unchanged" commands. */
11611 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11612 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
11613 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
11614 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
11615 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
11616 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
11617 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11618 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
11619 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
11620 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
11621 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
11622 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
11623 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11624 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
11625 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
11626 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
11627 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
11628 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
11629
11630 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11631 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11632
11633 /* "nexthop-local unchanged" commands */
11634 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11635 install_element(BGP_IPV6_NODE,
11636 &no_neighbor_nexthop_local_unchanged_cmd);
11637
11638 /* "neighbor next-hop-self" commands. */
11639 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11640 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
11641 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11642 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11643 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11644 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
11645 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11646 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
11647 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11648 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
11649 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11650 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
11651 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11652 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
11653 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11654 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
11655 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11656 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
11657
11658 /* "neighbor next-hop-self force" commands. */
11659 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11660 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
11661 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11662 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11663 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11664 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
11665 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11666 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
11667 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11668 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11669 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11670 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
11671 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11672 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
11673 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11674 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11675 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11676 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11677
11678 /* "neighbor as-override" commands. */
11679 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
11680 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
11681 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
11682 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11683 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11684 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
11685 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11686 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
11687 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
11688 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11689 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11690 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
11691 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11692 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
11693 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11694 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
11695 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11696 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
11697
11698 /* "neighbor remove-private-AS" commands. */
11699 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11700 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11701 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11702 install_element(BGP_NODE,
11703 &no_neighbor_remove_private_as_all_hidden_cmd);
11704 install_element(BGP_NODE,
11705 &neighbor_remove_private_as_replace_as_hidden_cmd);
11706 install_element(BGP_NODE,
11707 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11708 install_element(BGP_NODE,
11709 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11710 install_element(
11711 BGP_NODE,
11712 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
11713 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11714 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
11715 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11716 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11717 install_element(BGP_IPV4_NODE,
11718 &neighbor_remove_private_as_replace_as_cmd);
11719 install_element(BGP_IPV4_NODE,
11720 &no_neighbor_remove_private_as_replace_as_cmd);
11721 install_element(BGP_IPV4_NODE,
11722 &neighbor_remove_private_as_all_replace_as_cmd);
11723 install_element(BGP_IPV4_NODE,
11724 &no_neighbor_remove_private_as_all_replace_as_cmd);
11725 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11726 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
11727 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11728 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11729 install_element(BGP_IPV4M_NODE,
11730 &neighbor_remove_private_as_replace_as_cmd);
11731 install_element(BGP_IPV4M_NODE,
11732 &no_neighbor_remove_private_as_replace_as_cmd);
11733 install_element(BGP_IPV4M_NODE,
11734 &neighbor_remove_private_as_all_replace_as_cmd);
11735 install_element(BGP_IPV4M_NODE,
11736 &no_neighbor_remove_private_as_all_replace_as_cmd);
11737 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11738 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11739 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11740 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11741 install_element(BGP_IPV4L_NODE,
11742 &neighbor_remove_private_as_replace_as_cmd);
11743 install_element(BGP_IPV4L_NODE,
11744 &no_neighbor_remove_private_as_replace_as_cmd);
11745 install_element(BGP_IPV4L_NODE,
11746 &neighbor_remove_private_as_all_replace_as_cmd);
11747 install_element(BGP_IPV4L_NODE,
11748 &no_neighbor_remove_private_as_all_replace_as_cmd);
11749 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11750 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
11751 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11752 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11753 install_element(BGP_IPV6_NODE,
11754 &neighbor_remove_private_as_replace_as_cmd);
11755 install_element(BGP_IPV6_NODE,
11756 &no_neighbor_remove_private_as_replace_as_cmd);
11757 install_element(BGP_IPV6_NODE,
11758 &neighbor_remove_private_as_all_replace_as_cmd);
11759 install_element(BGP_IPV6_NODE,
11760 &no_neighbor_remove_private_as_all_replace_as_cmd);
11761 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11762 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
11763 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11764 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11765 install_element(BGP_IPV6M_NODE,
11766 &neighbor_remove_private_as_replace_as_cmd);
11767 install_element(BGP_IPV6M_NODE,
11768 &no_neighbor_remove_private_as_replace_as_cmd);
11769 install_element(BGP_IPV6M_NODE,
11770 &neighbor_remove_private_as_all_replace_as_cmd);
11771 install_element(BGP_IPV6M_NODE,
11772 &no_neighbor_remove_private_as_all_replace_as_cmd);
11773 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11774 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11775 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11776 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11777 install_element(BGP_IPV6L_NODE,
11778 &neighbor_remove_private_as_replace_as_cmd);
11779 install_element(BGP_IPV6L_NODE,
11780 &no_neighbor_remove_private_as_replace_as_cmd);
11781 install_element(BGP_IPV6L_NODE,
11782 &neighbor_remove_private_as_all_replace_as_cmd);
11783 install_element(BGP_IPV6L_NODE,
11784 &no_neighbor_remove_private_as_all_replace_as_cmd);
11785 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11786 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
11787 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11788 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11789 install_element(BGP_VPNV4_NODE,
11790 &neighbor_remove_private_as_replace_as_cmd);
11791 install_element(BGP_VPNV4_NODE,
11792 &no_neighbor_remove_private_as_replace_as_cmd);
11793 install_element(BGP_VPNV4_NODE,
11794 &neighbor_remove_private_as_all_replace_as_cmd);
11795 install_element(BGP_VPNV4_NODE,
11796 &no_neighbor_remove_private_as_all_replace_as_cmd);
11797 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11798 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11799 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11800 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11801 install_element(BGP_VPNV6_NODE,
11802 &neighbor_remove_private_as_replace_as_cmd);
11803 install_element(BGP_VPNV6_NODE,
11804 &no_neighbor_remove_private_as_replace_as_cmd);
11805 install_element(BGP_VPNV6_NODE,
11806 &neighbor_remove_private_as_all_replace_as_cmd);
11807 install_element(BGP_VPNV6_NODE,
11808 &no_neighbor_remove_private_as_all_replace_as_cmd);
11809
11810 /* "neighbor send-community" commands.*/
11811 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
11812 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11813 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11814 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
11815 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
11816 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11817 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11818 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11819 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11820 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11821 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11822 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
11823 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11824 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11825 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11826 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
11827 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
11828 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11829 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11830 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
11831 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11832 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11833 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11834 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
11835 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11836 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11837 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11838 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
11839 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11840 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11841 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11842 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
11843 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11844 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11845 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11846 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
11847
11848 /* "neighbor route-reflector" commands.*/
11849 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11850 install_element(BGP_NODE,
11851 &no_neighbor_route_reflector_client_hidden_cmd);
11852 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11853 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11854 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11855 install_element(BGP_IPV4M_NODE,
11856 &no_neighbor_route_reflector_client_cmd);
11857 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11858 install_element(BGP_IPV4L_NODE,
11859 &no_neighbor_route_reflector_client_cmd);
11860 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11861 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
11862 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11863 install_element(BGP_IPV6M_NODE,
11864 &no_neighbor_route_reflector_client_cmd);
11865 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11866 install_element(BGP_IPV6L_NODE,
11867 &no_neighbor_route_reflector_client_cmd);
11868 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11869 install_element(BGP_VPNV4_NODE,
11870 &no_neighbor_route_reflector_client_cmd);
11871 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11872 install_element(BGP_VPNV6_NODE,
11873 &no_neighbor_route_reflector_client_cmd);
11874 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
11875 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
11876
11877 /* "neighbor route-server" commands.*/
11878 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11879 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
11880 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11881 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11882 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11883 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
11884 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
11885 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
11886 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
11887 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
11888 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
11889 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
11890 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
11891 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
11892 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
11893 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
11894 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
11895 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
11896
11897 /* "neighbor addpath-tx-all-paths" commands.*/
11898 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
11899 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
11900 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11901 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11902 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11903 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11904 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11905 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11906 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11907 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11908 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11909 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11910 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11911 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11912 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11913 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11914 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11915 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11916
11917 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
11918 install_element(BGP_NODE,
11919 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11920 install_element(BGP_NODE,
11921 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11922 install_element(BGP_IPV4_NODE,
11923 &neighbor_addpath_tx_bestpath_per_as_cmd);
11924 install_element(BGP_IPV4_NODE,
11925 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11926 install_element(BGP_IPV4M_NODE,
11927 &neighbor_addpath_tx_bestpath_per_as_cmd);
11928 install_element(BGP_IPV4M_NODE,
11929 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11930 install_element(BGP_IPV4L_NODE,
11931 &neighbor_addpath_tx_bestpath_per_as_cmd);
11932 install_element(BGP_IPV4L_NODE,
11933 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11934 install_element(BGP_IPV6_NODE,
11935 &neighbor_addpath_tx_bestpath_per_as_cmd);
11936 install_element(BGP_IPV6_NODE,
11937 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11938 install_element(BGP_IPV6M_NODE,
11939 &neighbor_addpath_tx_bestpath_per_as_cmd);
11940 install_element(BGP_IPV6M_NODE,
11941 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11942 install_element(BGP_IPV6L_NODE,
11943 &neighbor_addpath_tx_bestpath_per_as_cmd);
11944 install_element(BGP_IPV6L_NODE,
11945 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11946 install_element(BGP_VPNV4_NODE,
11947 &neighbor_addpath_tx_bestpath_per_as_cmd);
11948 install_element(BGP_VPNV4_NODE,
11949 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11950 install_element(BGP_VPNV6_NODE,
11951 &neighbor_addpath_tx_bestpath_per_as_cmd);
11952 install_element(BGP_VPNV6_NODE,
11953 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11954
11955 /* "neighbor passive" commands. */
11956 install_element(BGP_NODE, &neighbor_passive_cmd);
11957 install_element(BGP_NODE, &no_neighbor_passive_cmd);
11958
11959
11960 /* "neighbor shutdown" commands. */
11961 install_element(BGP_NODE, &neighbor_shutdown_cmd);
11962 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
11963 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
11964 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
11965
11966 /* "neighbor capability extended-nexthop" commands.*/
11967 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
11968 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
11969
11970 /* "neighbor capability orf prefix-list" commands.*/
11971 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
11972 install_element(BGP_NODE,
11973 &no_neighbor_capability_orf_prefix_hidden_cmd);
11974 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
11975 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
11976 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
11977 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
11978 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
11979 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
11980 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
11981 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
11982 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
11983 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
11984 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
11985 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
11986
11987 /* "neighbor capability dynamic" commands.*/
11988 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
11989 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
11990
11991 /* "neighbor dont-capability-negotiate" commands. */
11992 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
11993 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
11994
11995 /* "neighbor ebgp-multihop" commands. */
11996 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
11997 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
11998 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
11999
12000 /* "neighbor disable-connected-check" commands. */
12001 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12002 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12003
12004 /* "neighbor description" commands. */
12005 install_element(BGP_NODE, &neighbor_description_cmd);
12006 install_element(BGP_NODE, &no_neighbor_description_cmd);
12007
12008 /* "neighbor update-source" commands. "*/
12009 install_element(BGP_NODE, &neighbor_update_source_cmd);
12010 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12011
12012 /* "neighbor default-originate" commands. */
12013 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12014 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12015 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12016 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12017 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12018 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12019 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12020 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12021 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12022 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12023 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12024 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12025 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12026 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12027 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12028 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12029 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12030 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12031 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12032 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12033 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12034
12035 /* "neighbor port" commands. */
12036 install_element(BGP_NODE, &neighbor_port_cmd);
12037 install_element(BGP_NODE, &no_neighbor_port_cmd);
12038
12039 /* "neighbor weight" commands. */
12040 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12041 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12042
12043 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12044 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12045 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12046 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12047 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12048 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12049 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12050 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12051 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12052 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12053 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12054 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12055 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12056 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12057 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12058 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12059
12060 /* "neighbor override-capability" commands. */
12061 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12062 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12063
12064 /* "neighbor strict-capability-match" commands. */
12065 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12066 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12067
12068 /* "neighbor timers" commands. */
12069 install_element(BGP_NODE, &neighbor_timers_cmd);
12070 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12071
12072 /* "neighbor timers connect" commands. */
12073 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12074 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12075
12076 /* "neighbor advertisement-interval" commands. */
12077 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12078 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12079
12080 /* "neighbor interface" commands. */
12081 install_element(BGP_NODE, &neighbor_interface_cmd);
12082 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12083
12084 /* "neighbor distribute" commands. */
12085 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12086 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12087 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12088 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12089 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12090 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12091 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12092 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12093 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12094 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12095 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12096 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12097 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12098 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12099 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12100 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12101 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12102 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12103
12104 /* "neighbor prefix-list" commands. */
12105 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12106 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12107 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12108 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12109 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12110 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12111 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12112 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12113 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12114 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12115 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12116 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12117 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12118 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12119 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12120 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12121 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12122 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12123
12124 /* "neighbor filter-list" commands. */
12125 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12126 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12127 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12128 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12129 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12130 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12131 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12132 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12133 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12134 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12135 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12136 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12137 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12138 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12139 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12140 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12141 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12142 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12143
12144 /* "neighbor route-map" commands. */
12145 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12146 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12147 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12148 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12149 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12150 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12151 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12152 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12153 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12154 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12155 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12156 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12157 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12158 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12159 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12160 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12161 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12162 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
12163 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12164 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 12165
12166 /* "neighbor unsuppress-map" commands. */
12167 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12168 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12169 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12170 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12171 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12172 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12173 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12174 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12175 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12176 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12177 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12178 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12179 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12180 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12181 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12182 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12183 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12184 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12185
12186 /* "neighbor maximum-prefix" commands. */
12187 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12188 install_element(BGP_NODE,
12189 &neighbor_maximum_prefix_threshold_hidden_cmd);
12190 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12191 install_element(BGP_NODE,
12192 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12193 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12194 install_element(BGP_NODE,
12195 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12196 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12197 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12198 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12199 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12200 install_element(BGP_IPV4_NODE,
12201 &neighbor_maximum_prefix_threshold_warning_cmd);
12202 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12203 install_element(BGP_IPV4_NODE,
12204 &neighbor_maximum_prefix_threshold_restart_cmd);
12205 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12206 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12207 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12208 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12209 install_element(BGP_IPV4M_NODE,
12210 &neighbor_maximum_prefix_threshold_warning_cmd);
12211 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12212 install_element(BGP_IPV4M_NODE,
12213 &neighbor_maximum_prefix_threshold_restart_cmd);
12214 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12215 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12216 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12217 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12218 install_element(BGP_IPV4L_NODE,
12219 &neighbor_maximum_prefix_threshold_warning_cmd);
12220 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12221 install_element(BGP_IPV4L_NODE,
12222 &neighbor_maximum_prefix_threshold_restart_cmd);
12223 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12224 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12225 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12226 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12227 install_element(BGP_IPV6_NODE,
12228 &neighbor_maximum_prefix_threshold_warning_cmd);
12229 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12230 install_element(BGP_IPV6_NODE,
12231 &neighbor_maximum_prefix_threshold_restart_cmd);
12232 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12233 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12234 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12235 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12236 install_element(BGP_IPV6M_NODE,
12237 &neighbor_maximum_prefix_threshold_warning_cmd);
12238 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12239 install_element(BGP_IPV6M_NODE,
12240 &neighbor_maximum_prefix_threshold_restart_cmd);
12241 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12242 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12243 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12244 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12245 install_element(BGP_IPV6L_NODE,
12246 &neighbor_maximum_prefix_threshold_warning_cmd);
12247 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12248 install_element(BGP_IPV6L_NODE,
12249 &neighbor_maximum_prefix_threshold_restart_cmd);
12250 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12251 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12252 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12253 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12254 install_element(BGP_VPNV4_NODE,
12255 &neighbor_maximum_prefix_threshold_warning_cmd);
12256 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12257 install_element(BGP_VPNV4_NODE,
12258 &neighbor_maximum_prefix_threshold_restart_cmd);
12259 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12260 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12261 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12262 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12263 install_element(BGP_VPNV6_NODE,
12264 &neighbor_maximum_prefix_threshold_warning_cmd);
12265 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12266 install_element(BGP_VPNV6_NODE,
12267 &neighbor_maximum_prefix_threshold_restart_cmd);
12268 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12269
12270 /* "neighbor allowas-in" */
12271 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12272 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12273 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12274 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12275 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12276 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12277 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12278 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12279 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12280 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12281 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12282 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12283 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12284 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12285 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12286 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12287 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12288 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12289 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12290 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12291
12292 /* address-family commands. */
12293 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12294 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 12295#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 12296 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12297 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 12298#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 12299
d62a17ae 12300 install_element(BGP_NODE, &address_family_evpn_cmd);
12301
12302 /* "exit-address-family" command. */
12303 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12304 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12305 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12306 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12307 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12308 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12309 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12310 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12311 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12312
12313 /* "clear ip bgp commands" */
12314 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12315
12316 /* clear ip bgp prefix */
12317 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12318 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12319 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12320
12321 /* "show [ip] bgp summary" commands. */
12322 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
12323 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
12324 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
12325 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
12326 install_element(VIEW_NODE, &show_bgp_updgrps_adj_cmd);
12327 install_element(VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
12328 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
12329 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
12330 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
12331 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
12332 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12333 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
12334 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
12335 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
12336 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12337
12338 /* "show [ip] bgp neighbors" commands. */
12339 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12340
12341 /* "show [ip] bgp peer-group" commands. */
12342 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12343
12344 /* "show [ip] bgp paths" commands. */
12345 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12346
12347 /* "show [ip] bgp community" commands. */
12348 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12349
12350 /* "show ip bgp large-community" commands. */
12351 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12352 /* "show [ip] bgp attribute-info" commands. */
12353 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12354
12355 /* "redistribute" commands. */
12356 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12357 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12358 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12359 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12360 install_element(BGP_NODE,
12361 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12362 install_element(BGP_NODE,
12363 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12364 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12365 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12366 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12367 install_element(BGP_NODE,
12368 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12369 install_element(BGP_NODE,
12370 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12371 install_element(BGP_NODE,
12372 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12373 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12374 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12375 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12376 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12377 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12378 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12379 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12380 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12381 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12382 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12383 install_element(BGP_IPV4_NODE,
12384 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12385 install_element(BGP_IPV4_NODE,
12386 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12387 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12388 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12389 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12390 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12391 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12392 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12393
12394 /* ttl_security commands */
12395 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12396 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12397
12398 /* "show [ip] bgp memory" commands. */
12399 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12400
acf71666
MK
12401 /* "show bgp martian next-hop" */
12402 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12403
d62a17ae 12404 /* "show [ip] bgp views" commands. */
12405 install_element(VIEW_NODE, &show_bgp_views_cmd);
12406
12407 /* "show [ip] bgp vrfs" commands. */
12408 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12409
12410 /* Community-list. */
12411 community_list_vty();
718e3744 12412}
6b0655a2 12413
718e3744 12414#include "memory.h"
12415#include "bgp_regex.h"
12416#include "bgp_clist.h"
12417#include "bgp_ecommunity.h"
12418
12419/* VTY functions. */
12420
12421/* Direction value to string conversion. */
d62a17ae 12422static const char *community_direct_str(int direct)
12423{
12424 switch (direct) {
12425 case COMMUNITY_DENY:
12426 return "deny";
12427 case COMMUNITY_PERMIT:
12428 return "permit";
12429 default:
12430 return "unknown";
12431 }
718e3744 12432}
12433
12434/* Display error string. */
d62a17ae 12435static void community_list_perror(struct vty *vty, int ret)
12436{
12437 switch (ret) {
12438 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12439 vty_out(vty, "%% Can't find community-list\n");
12440 break;
12441 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12442 vty_out(vty, "%% Malformed community-list value\n");
12443 break;
12444 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12445 vty_out(vty,
12446 "%% Community name conflict, previously defined as standard community\n");
12447 break;
12448 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12449 vty_out(vty,
12450 "%% Community name conflict, previously defined as expanded community\n");
12451 break;
12452 }
718e3744 12453}
12454
5bf15956
DW
12455/* "community-list" keyword help string. */
12456#define COMMUNITY_LIST_STR "Add a community list entry\n"
12457
5bf15956 12458/* ip community-list standard */
718e3744 12459DEFUN (ip_community_list_standard,
12460 ip_community_list_standard_cmd,
e961923c 12461 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12462 IP_STR
12463 COMMUNITY_LIST_STR
12464 "Community list number (standard)\n"
5bf15956 12465 "Add an standard community-list entry\n"
718e3744 12466 "Community list name\n"
12467 "Specify community to reject\n"
12468 "Specify community to accept\n"
12469 COMMUNITY_VAL_STR)
12470{
d62a17ae 12471 char *cl_name_or_number = NULL;
12472 int direct = 0;
12473 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12474
d62a17ae 12475 int idx = 0;
12476 argv_find(argv, argc, "(1-99)", &idx);
12477 argv_find(argv, argc, "WORD", &idx);
12478 cl_name_or_number = argv[idx]->arg;
12479 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12480 : COMMUNITY_DENY;
12481 argv_find(argv, argc, "AA:NN", &idx);
12482 char *str = argv_concat(argv, argc, idx);
42f914d4 12483
d62a17ae 12484 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12485 style);
42f914d4 12486
d62a17ae 12487 XFREE(MTYPE_TMP, str);
42f914d4 12488
d62a17ae 12489 if (ret < 0) {
12490 /* Display error string. */
12491 community_list_perror(vty, ret);
12492 return CMD_WARNING_CONFIG_FAILED;
12493 }
42f914d4 12494
d62a17ae 12495 return CMD_SUCCESS;
718e3744 12496}
12497
fee6e4e4 12498DEFUN (no_ip_community_list_standard_all,
12499 no_ip_community_list_standard_all_cmd,
e961923c 12500 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12501 NO_STR
12502 IP_STR
12503 COMMUNITY_LIST_STR
12504 "Community list number (standard)\n"
5bf15956
DW
12505 "Add an standard community-list entry\n"
12506 "Community list name\n"
718e3744 12507 "Specify community to reject\n"
12508 "Specify community to accept\n"
12509 COMMUNITY_VAL_STR)
12510{
d62a17ae 12511 int delete_all = 0;
42f914d4 12512
d62a17ae 12513 char *cl_name_or_number = NULL;
12514 int direct = 0;
12515 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12516
d62a17ae 12517 int idx = 0;
12518 argv_find(argv, argc, "(1-99)", &idx);
12519 argv_find(argv, argc, "WORD", &idx);
12520 cl_name_or_number = argv[idx]->arg;
12521 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12522 : COMMUNITY_DENY;
12523 argv_find(argv, argc, "AA:NN", &idx);
12524 char *str = argv_concat(argv, argc, idx);
42f914d4 12525
d62a17ae 12526 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12527 direct, style, delete_all);
42f914d4 12528
d62a17ae 12529 XFREE(MTYPE_TMP, str);
daf9ddbb 12530
d62a17ae 12531 if (ret < 0) {
12532 community_list_perror(vty, ret);
12533 return CMD_WARNING_CONFIG_FAILED;
12534 }
42f914d4 12535
d62a17ae 12536 return CMD_SUCCESS;
718e3744 12537}
12538
5bf15956
DW
12539/* ip community-list expanded */
12540DEFUN (ip_community_list_expanded_all,
12541 ip_community_list_expanded_all_cmd,
42f914d4 12542 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12543 IP_STR
12544 COMMUNITY_LIST_STR
12545 "Community list number (expanded)\n"
5bf15956 12546 "Add an expanded community-list entry\n"
718e3744 12547 "Community list name\n"
12548 "Specify community to reject\n"
12549 "Specify community to accept\n"
12550 COMMUNITY_VAL_STR)
12551{
d62a17ae 12552 char *cl_name_or_number = NULL;
12553 int direct = 0;
12554 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12555
d62a17ae 12556 int idx = 0;
12557 argv_find(argv, argc, "(100-500)", &idx);
12558 argv_find(argv, argc, "WORD", &idx);
12559 cl_name_or_number = argv[idx]->arg;
12560 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12561 : COMMUNITY_DENY;
12562 argv_find(argv, argc, "AA:NN", &idx);
12563 char *str = argv_concat(argv, argc, idx);
42f914d4 12564
d62a17ae 12565 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12566 style);
42f914d4 12567
d62a17ae 12568 XFREE(MTYPE_TMP, str);
42f914d4 12569
d62a17ae 12570 if (ret < 0) {
12571 /* Display error string. */
12572 community_list_perror(vty, ret);
12573 return CMD_WARNING_CONFIG_FAILED;
12574 }
42f914d4 12575
d62a17ae 12576 return CMD_SUCCESS;
718e3744 12577}
12578
5bf15956
DW
12579DEFUN (no_ip_community_list_expanded_all,
12580 no_ip_community_list_expanded_all_cmd,
42f914d4 12581 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12582 NO_STR
12583 IP_STR
12584 COMMUNITY_LIST_STR
5bf15956
DW
12585 "Community list number (expanded)\n"
12586 "Add an expanded community-list entry\n"
718e3744 12587 "Community list name\n"
12588 "Specify community to reject\n"
12589 "Specify community to accept\n"
5bf15956 12590 COMMUNITY_VAL_STR)
718e3744 12591{
d62a17ae 12592 int delete_all = 0;
42f914d4 12593
d62a17ae 12594 char *cl_name_or_number = NULL;
12595 int direct = 0;
12596 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12597
d62a17ae 12598 int idx = 0;
12599 argv_find(argv, argc, "(100-500)", &idx);
12600 argv_find(argv, argc, "WORD", &idx);
12601 cl_name_or_number = argv[idx]->arg;
12602 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12603 : COMMUNITY_DENY;
12604 argv_find(argv, argc, "AA:NN", &idx);
12605 char *str = argv_concat(argv, argc, idx);
42f914d4 12606
d62a17ae 12607 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12608 direct, style, delete_all);
42f914d4 12609
d62a17ae 12610 XFREE(MTYPE_TMP, str);
daf9ddbb 12611
d62a17ae 12612 if (ret < 0) {
12613 community_list_perror(vty, ret);
12614 return CMD_WARNING_CONFIG_FAILED;
12615 }
42f914d4 12616
d62a17ae 12617 return CMD_SUCCESS;
718e3744 12618}
12619
d62a17ae 12620static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 12621{
d62a17ae 12622 struct community_entry *entry;
718e3744 12623
d62a17ae 12624 for (entry = list->head; entry; entry = entry->next) {
12625 if (entry == list->head) {
12626 if (all_digit(list->name))
12627 vty_out(vty, "Community %s list %s\n",
12628 entry->style == COMMUNITY_LIST_STANDARD
12629 ? "standard"
12630 : "(expanded) access",
12631 list->name);
12632 else
12633 vty_out(vty, "Named Community %s list %s\n",
12634 entry->style == COMMUNITY_LIST_STANDARD
12635 ? "standard"
12636 : "expanded",
12637 list->name);
12638 }
12639 if (entry->any)
12640 vty_out(vty, " %s\n",
12641 community_direct_str(entry->direct));
12642 else
12643 vty_out(vty, " %s %s\n",
12644 community_direct_str(entry->direct),
12645 entry->style == COMMUNITY_LIST_STANDARD
12646 ? community_str(entry->u.com)
12647 : entry->config);
12648 }
718e3744 12649}
12650
12651DEFUN (show_ip_community_list,
12652 show_ip_community_list_cmd,
12653 "show ip community-list",
12654 SHOW_STR
12655 IP_STR
12656 "List community-list\n")
12657{
d62a17ae 12658 struct community_list *list;
12659 struct community_list_master *cm;
718e3744 12660
d62a17ae 12661 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
12662 if (!cm)
12663 return CMD_SUCCESS;
718e3744 12664
d62a17ae 12665 for (list = cm->num.head; list; list = list->next)
12666 community_list_show(vty, list);
718e3744 12667
d62a17ae 12668 for (list = cm->str.head; list; list = list->next)
12669 community_list_show(vty, list);
718e3744 12670
d62a17ae 12671 return CMD_SUCCESS;
718e3744 12672}
12673
12674DEFUN (show_ip_community_list_arg,
12675 show_ip_community_list_arg_cmd,
6147e2c6 12676 "show ip community-list <(1-500)|WORD>",
718e3744 12677 SHOW_STR
12678 IP_STR
12679 "List community-list\n"
12680 "Community-list number\n"
12681 "Community-list name\n")
12682{
d62a17ae 12683 int idx_comm_list = 3;
12684 struct community_list *list;
718e3744 12685
d62a17ae 12686 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
12687 COMMUNITY_LIST_MASTER);
12688 if (!list) {
12689 vty_out(vty, "%% Can't find community-list\n");
12690 return CMD_WARNING;
12691 }
718e3744 12692
d62a17ae 12693 community_list_show(vty, list);
718e3744 12694
d62a17ae 12695 return CMD_SUCCESS;
718e3744 12696}
6b0655a2 12697
57d187bc
JS
12698/*
12699 * Large Community code.
12700 */
d62a17ae 12701static int lcommunity_list_set_vty(struct vty *vty, int argc,
12702 struct cmd_token **argv, int style,
12703 int reject_all_digit_name)
12704{
12705 int ret;
12706 int direct;
12707 char *str;
12708 int idx = 0;
12709 char *cl_name;
12710
12711 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12712 : COMMUNITY_DENY;
12713
12714 /* All digit name check. */
12715 idx = 0;
12716 argv_find(argv, argc, "WORD", &idx);
12717 argv_find(argv, argc, "(1-99)", &idx);
12718 argv_find(argv, argc, "(100-500)", &idx);
12719 cl_name = argv[idx]->arg;
12720 if (reject_all_digit_name && all_digit(cl_name)) {
12721 vty_out(vty, "%% Community name cannot have all digits\n");
12722 return CMD_WARNING_CONFIG_FAILED;
12723 }
12724
12725 idx = 0;
12726 argv_find(argv, argc, "AA:BB:CC", &idx);
12727 argv_find(argv, argc, "LINE", &idx);
12728 /* Concat community string argument. */
12729 if (idx)
12730 str = argv_concat(argv, argc, idx);
12731 else
12732 str = NULL;
12733
12734 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
12735
12736 /* Free temporary community list string allocated by
12737 argv_concat(). */
12738 if (str)
12739 XFREE(MTYPE_TMP, str);
12740
12741 if (ret < 0) {
12742 community_list_perror(vty, ret);
12743 return CMD_WARNING_CONFIG_FAILED;
12744 }
12745 return CMD_SUCCESS;
12746}
12747
12748static int lcommunity_list_unset_vty(struct vty *vty, int argc,
12749 struct cmd_token **argv, int style)
12750{
12751 int ret;
12752 int direct = 0;
12753 char *str = NULL;
12754 int idx = 0;
12755
12756 argv_find(argv, argc, "permit", &idx);
12757 argv_find(argv, argc, "deny", &idx);
12758
12759 if (idx) {
12760 /* Check the list direct. */
12761 if (strncmp(argv[idx]->arg, "p", 1) == 0)
12762 direct = COMMUNITY_PERMIT;
12763 else
12764 direct = COMMUNITY_DENY;
12765
12766 idx = 0;
12767 argv_find(argv, argc, "LINE", &idx);
12768 argv_find(argv, argc, "AA:AA:NN", &idx);
12769 /* Concat community string argument. */
12770 str = argv_concat(argv, argc, idx);
12771 }
12772
12773 idx = 0;
12774 argv_find(argv, argc, "(1-99)", &idx);
12775 argv_find(argv, argc, "(100-500)", &idx);
12776 argv_find(argv, argc, "WORD", &idx);
12777
12778 /* Unset community list. */
12779 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
12780 style);
12781
12782 /* Free temporary community list string allocated by
12783 argv_concat(). */
12784 if (str)
12785 XFREE(MTYPE_TMP, str);
12786
12787 if (ret < 0) {
12788 community_list_perror(vty, ret);
12789 return CMD_WARNING_CONFIG_FAILED;
12790 }
12791
12792 return CMD_SUCCESS;
57d187bc
JS
12793}
12794
12795/* "large-community-list" keyword help string. */
12796#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12797#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12798
12799DEFUN (ip_lcommunity_list_standard,
12800 ip_lcommunity_list_standard_cmd,
52951b63
DS
12801 "ip large-community-list (1-99) <deny|permit>",
12802 IP_STR
12803 LCOMMUNITY_LIST_STR
12804 "Large Community list number (standard)\n"
12805 "Specify large community to reject\n"
7111c1a0 12806 "Specify large community to accept\n")
52951b63 12807{
d62a17ae 12808 return lcommunity_list_set_vty(vty, argc, argv,
12809 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
12810}
12811
12812DEFUN (ip_lcommunity_list_standard1,
12813 ip_lcommunity_list_standard1_cmd,
12814 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
12815 IP_STR
12816 LCOMMUNITY_LIST_STR
12817 "Large Community list number (standard)\n"
12818 "Specify large community to reject\n"
12819 "Specify large community to accept\n"
12820 LCOMMUNITY_VAL_STR)
12821{
d62a17ae 12822 return lcommunity_list_set_vty(vty, argc, argv,
12823 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
12824}
12825
12826DEFUN (ip_lcommunity_list_expanded,
12827 ip_lcommunity_list_expanded_cmd,
12828 "ip large-community-list (100-500) <deny|permit> LINE...",
12829 IP_STR
12830 LCOMMUNITY_LIST_STR
12831 "Large Community list number (expanded)\n"
12832 "Specify large community to reject\n"
12833 "Specify large community to accept\n"
12834 "An ordered list as a regular-expression\n")
12835{
d62a17ae 12836 return lcommunity_list_set_vty(vty, argc, argv,
12837 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
12838}
12839
12840DEFUN (ip_lcommunity_list_name_standard,
12841 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
12842 "ip large-community-list standard WORD <deny|permit>",
12843 IP_STR
12844 LCOMMUNITY_LIST_STR
12845 "Specify standard large-community-list\n"
12846 "Large Community list name\n"
12847 "Specify large community to reject\n"
12848 "Specify large community to accept\n")
12849{
d62a17ae 12850 return lcommunity_list_set_vty(vty, argc, argv,
12851 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
12852}
12853
12854DEFUN (ip_lcommunity_list_name_standard1,
12855 ip_lcommunity_list_name_standard1_cmd,
12856 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
12857 IP_STR
12858 LCOMMUNITY_LIST_STR
12859 "Specify standard large-community-list\n"
12860 "Large Community list name\n"
12861 "Specify large community to reject\n"
12862 "Specify large community to accept\n"
12863 LCOMMUNITY_VAL_STR)
12864{
d62a17ae 12865 return lcommunity_list_set_vty(vty, argc, argv,
12866 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
12867}
12868
12869DEFUN (ip_lcommunity_list_name_expanded,
12870 ip_lcommunity_list_name_expanded_cmd,
12871 "ip large-community-list expanded WORD <deny|permit> LINE...",
12872 IP_STR
12873 LCOMMUNITY_LIST_STR
12874 "Specify expanded large-community-list\n"
12875 "Large Community list name\n"
12876 "Specify large community to reject\n"
12877 "Specify large community to accept\n"
12878 "An ordered list as a regular-expression\n")
12879{
d62a17ae 12880 return lcommunity_list_set_vty(vty, argc, argv,
12881 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
12882}
12883
12884DEFUN (no_ip_lcommunity_list_standard_all,
12885 no_ip_lcommunity_list_standard_all_cmd,
12886 "no ip large-community-list <(1-99)|(100-500)|WORD>",
12887 NO_STR
12888 IP_STR
12889 LCOMMUNITY_LIST_STR
12890 "Large Community list number (standard)\n"
12891 "Large Community list number (expanded)\n"
12892 "Large Community list name\n")
12893{
d62a17ae 12894 return lcommunity_list_unset_vty(vty, argc, argv,
12895 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12896}
12897
12898DEFUN (no_ip_lcommunity_list_name_expanded_all,
12899 no_ip_lcommunity_list_name_expanded_all_cmd,
12900 "no ip large-community-list expanded WORD",
12901 NO_STR
12902 IP_STR
12903 LCOMMUNITY_LIST_STR
12904 "Specify expanded large-community-list\n"
12905 "Large Community list name\n")
12906{
d62a17ae 12907 return lcommunity_list_unset_vty(vty, argc, argv,
12908 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12909}
12910
12911DEFUN (no_ip_lcommunity_list_standard,
12912 no_ip_lcommunity_list_standard_cmd,
12913 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
12914 NO_STR
12915 IP_STR
12916 LCOMMUNITY_LIST_STR
12917 "Large Community list number (standard)\n"
12918 "Specify large community to reject\n"
12919 "Specify large community to accept\n"
12920 LCOMMUNITY_VAL_STR)
12921{
d62a17ae 12922 return lcommunity_list_unset_vty(vty, argc, argv,
12923 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12924}
12925
12926DEFUN (no_ip_lcommunity_list_expanded,
12927 no_ip_lcommunity_list_expanded_cmd,
12928 "no ip large-community-list (100-500) <deny|permit> LINE...",
12929 NO_STR
12930 IP_STR
12931 LCOMMUNITY_LIST_STR
12932 "Large Community list number (expanded)\n"
12933 "Specify large community to reject\n"
12934 "Specify large community to accept\n"
12935 "An ordered list as a regular-expression\n")
12936{
d62a17ae 12937 return lcommunity_list_unset_vty(vty, argc, argv,
12938 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12939}
12940
12941DEFUN (no_ip_lcommunity_list_name_standard,
12942 no_ip_lcommunity_list_name_standard_cmd,
12943 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
12944 NO_STR
12945 IP_STR
12946 LCOMMUNITY_LIST_STR
12947 "Specify standard large-community-list\n"
12948 "Large Community list name\n"
12949 "Specify large community to reject\n"
12950 "Specify large community to accept\n"
12951 LCOMMUNITY_VAL_STR)
12952{
d62a17ae 12953 return lcommunity_list_unset_vty(vty, argc, argv,
12954 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12955}
12956
12957DEFUN (no_ip_lcommunity_list_name_expanded,
12958 no_ip_lcommunity_list_name_expanded_cmd,
12959 "no ip large-community-list expanded WORD <deny|permit> LINE...",
12960 NO_STR
12961 IP_STR
12962 LCOMMUNITY_LIST_STR
12963 "Specify expanded large-community-list\n"
12964 "Large community list name\n"
12965 "Specify large community to reject\n"
12966 "Specify large community to accept\n"
12967 "An ordered list as a regular-expression\n")
12968{
d62a17ae 12969 return lcommunity_list_unset_vty(vty, argc, argv,
12970 LARGE_COMMUNITY_LIST_EXPANDED);
12971}
12972
12973static void lcommunity_list_show(struct vty *vty, struct community_list *list)
12974{
12975 struct community_entry *entry;
12976
12977 for (entry = list->head; entry; entry = entry->next) {
12978 if (entry == list->head) {
12979 if (all_digit(list->name))
12980 vty_out(vty, "Large community %s list %s\n",
12981 entry->style == EXTCOMMUNITY_LIST_STANDARD
12982 ? "standard"
12983 : "(expanded) access",
12984 list->name);
12985 else
12986 vty_out(vty,
12987 "Named large community %s list %s\n",
12988 entry->style == EXTCOMMUNITY_LIST_STANDARD
12989 ? "standard"
12990 : "expanded",
12991 list->name);
12992 }
12993 if (entry->any)
12994 vty_out(vty, " %s\n",
12995 community_direct_str(entry->direct));
12996 else
12997 vty_out(vty, " %s %s\n",
12998 community_direct_str(entry->direct),
12999 entry->style == EXTCOMMUNITY_LIST_STANDARD
13000 ? entry->u.ecom->str
13001 : entry->config);
13002 }
57d187bc
JS
13003}
13004
13005DEFUN (show_ip_lcommunity_list,
13006 show_ip_lcommunity_list_cmd,
13007 "show ip large-community-list",
13008 SHOW_STR
13009 IP_STR
13010 "List large-community list\n")
13011{
d62a17ae 13012 struct community_list *list;
13013 struct community_list_master *cm;
57d187bc 13014
d62a17ae 13015 cm = community_list_master_lookup(bgp_clist,
13016 LARGE_COMMUNITY_LIST_MASTER);
13017 if (!cm)
13018 return CMD_SUCCESS;
57d187bc 13019
d62a17ae 13020 for (list = cm->num.head; list; list = list->next)
13021 lcommunity_list_show(vty, list);
57d187bc 13022
d62a17ae 13023 for (list = cm->str.head; list; list = list->next)
13024 lcommunity_list_show(vty, list);
57d187bc 13025
d62a17ae 13026 return CMD_SUCCESS;
57d187bc
JS
13027}
13028
13029DEFUN (show_ip_lcommunity_list_arg,
13030 show_ip_lcommunity_list_arg_cmd,
13031 "show ip large-community-list <(1-500)|WORD>",
13032 SHOW_STR
13033 IP_STR
13034 "List large-community list\n"
13035 "large-community-list number\n"
13036 "large-community-list name\n")
13037{
d62a17ae 13038 struct community_list *list;
57d187bc 13039
d62a17ae 13040 list = community_list_lookup(bgp_clist, argv[3]->arg,
13041 LARGE_COMMUNITY_LIST_MASTER);
13042 if (!list) {
13043 vty_out(vty, "%% Can't find extcommunity-list\n");
13044 return CMD_WARNING;
13045 }
57d187bc 13046
d62a17ae 13047 lcommunity_list_show(vty, list);
57d187bc 13048
d62a17ae 13049 return CMD_SUCCESS;
57d187bc
JS
13050}
13051
718e3744 13052/* "extcommunity-list" keyword help string. */
13053#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13054#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13055
13056DEFUN (ip_extcommunity_list_standard,
13057 ip_extcommunity_list_standard_cmd,
e961923c 13058 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13059 IP_STR
13060 EXTCOMMUNITY_LIST_STR
13061 "Extended Community list number (standard)\n"
718e3744 13062 "Specify standard extcommunity-list\n"
5bf15956 13063 "Community list name\n"
718e3744 13064 "Specify community to reject\n"
13065 "Specify community to accept\n"
13066 EXTCOMMUNITY_VAL_STR)
13067{
d62a17ae 13068 int style = EXTCOMMUNITY_LIST_STANDARD;
13069 int direct = 0;
13070 char *cl_number_or_name = NULL;
42f914d4 13071
d62a17ae 13072 int idx = 0;
13073 argv_find(argv, argc, "(1-99)", &idx);
13074 argv_find(argv, argc, "WORD", &idx);
13075 cl_number_or_name = argv[idx]->arg;
13076 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13077 : COMMUNITY_DENY;
13078 argv_find(argv, argc, "AA:NN", &idx);
13079 char *str = argv_concat(argv, argc, idx);
42f914d4 13080
d62a17ae 13081 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13082 direct, style);
42f914d4 13083
d62a17ae 13084 XFREE(MTYPE_TMP, str);
42f914d4 13085
d62a17ae 13086 if (ret < 0) {
13087 community_list_perror(vty, ret);
13088 return CMD_WARNING_CONFIG_FAILED;
13089 }
42f914d4 13090
d62a17ae 13091 return CMD_SUCCESS;
718e3744 13092}
13093
718e3744 13094DEFUN (ip_extcommunity_list_name_expanded,
13095 ip_extcommunity_list_name_expanded_cmd,
e961923c 13096 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13097 IP_STR
13098 EXTCOMMUNITY_LIST_STR
5bf15956 13099 "Extended Community list number (expanded)\n"
718e3744 13100 "Specify expanded extcommunity-list\n"
13101 "Extended Community list name\n"
13102 "Specify community to reject\n"
13103 "Specify community to accept\n"
13104 "An ordered list as a regular-expression\n")
13105{
d62a17ae 13106 int style = EXTCOMMUNITY_LIST_EXPANDED;
13107 int direct = 0;
13108 char *cl_number_or_name = NULL;
42f914d4 13109
d62a17ae 13110 int idx = 0;
13111 argv_find(argv, argc, "(100-500)", &idx);
13112 argv_find(argv, argc, "WORD", &idx);
13113 cl_number_or_name = argv[idx]->arg;
13114 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13115 : COMMUNITY_DENY;
13116 argv_find(argv, argc, "LINE", &idx);
13117 char *str = argv_concat(argv, argc, idx);
42f914d4 13118
d62a17ae 13119 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13120 direct, style);
42f914d4 13121
d62a17ae 13122 XFREE(MTYPE_TMP, str);
42f914d4 13123
d62a17ae 13124 if (ret < 0) {
13125 community_list_perror(vty, ret);
13126 return CMD_WARNING_CONFIG_FAILED;
13127 }
42f914d4 13128
d62a17ae 13129 return CMD_SUCCESS;
718e3744 13130}
13131
fee6e4e4 13132DEFUN (no_ip_extcommunity_list_standard_all,
13133 no_ip_extcommunity_list_standard_all_cmd,
e961923c 13134 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
13135 NO_STR
13136 IP_STR
13137 EXTCOMMUNITY_LIST_STR
13138 "Extended Community list number (standard)\n"
718e3744 13139 "Specify standard extcommunity-list\n"
5bf15956 13140 "Community list name\n"
718e3744 13141 "Specify community to reject\n"
13142 "Specify community to accept\n"
13143 EXTCOMMUNITY_VAL_STR)
13144{
d62a17ae 13145 int deleteall = 0;
42f914d4 13146
d62a17ae 13147 int style = EXTCOMMUNITY_LIST_STANDARD;
13148 int direct = 0;
13149 char *cl_number_or_name = NULL;
42f914d4 13150
d62a17ae 13151 int idx = 0;
13152 argv_find(argv, argc, "(1-99)", &idx);
13153 argv_find(argv, argc, "WORD", &idx);
13154 cl_number_or_name = argv[idx]->arg;
13155 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13156 : COMMUNITY_DENY;
13157 argv_find(argv, argc, "AA:NN", &idx);
13158 char *str = argv_concat(argv, argc, idx);
42f914d4 13159
d62a17ae 13160 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13161 direct, style, deleteall);
42f914d4 13162
d62a17ae 13163 XFREE(MTYPE_TMP, str);
42f914d4 13164
d62a17ae 13165 if (ret < 0) {
13166 community_list_perror(vty, ret);
13167 return CMD_WARNING_CONFIG_FAILED;
13168 }
42f914d4 13169
d62a17ae 13170 return CMD_SUCCESS;
718e3744 13171}
13172
5bf15956
DW
13173DEFUN (no_ip_extcommunity_list_expanded_all,
13174 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 13175 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13176 NO_STR
13177 IP_STR
13178 EXTCOMMUNITY_LIST_STR
13179 "Extended Community list number (expanded)\n"
718e3744 13180 "Specify expanded extcommunity-list\n"
5bf15956 13181 "Extended Community list name\n"
718e3744 13182 "Specify community to reject\n"
13183 "Specify community to accept\n"
13184 "An ordered list as a regular-expression\n")
13185{
d62a17ae 13186 int deleteall = 0;
42f914d4 13187
d62a17ae 13188 int style = EXTCOMMUNITY_LIST_EXPANDED;
13189 int direct = 0;
13190 char *cl_number_or_name = NULL;
42f914d4 13191
d62a17ae 13192 int idx = 0;
13193 argv_find(argv, argc, "(100-500)", &idx);
13194 argv_find(argv, argc, "WORD", &idx);
13195 cl_number_or_name = argv[idx]->arg;
13196 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13197 : COMMUNITY_DENY;
13198 argv_find(argv, argc, "LINE", &idx);
13199 char *str = argv_concat(argv, argc, idx);
42f914d4 13200
d62a17ae 13201 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13202 direct, style, deleteall);
42f914d4 13203
d62a17ae 13204 XFREE(MTYPE_TMP, str);
42f914d4 13205
d62a17ae 13206 if (ret < 0) {
13207 community_list_perror(vty, ret);
13208 return CMD_WARNING_CONFIG_FAILED;
13209 }
42f914d4 13210
d62a17ae 13211 return CMD_SUCCESS;
718e3744 13212}
13213
d62a17ae 13214static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 13215{
d62a17ae 13216 struct community_entry *entry;
718e3744 13217
d62a17ae 13218 for (entry = list->head; entry; entry = entry->next) {
13219 if (entry == list->head) {
13220 if (all_digit(list->name))
13221 vty_out(vty, "Extended community %s list %s\n",
13222 entry->style == EXTCOMMUNITY_LIST_STANDARD
13223 ? "standard"
13224 : "(expanded) access",
13225 list->name);
13226 else
13227 vty_out(vty,
13228 "Named extended community %s list %s\n",
13229 entry->style == EXTCOMMUNITY_LIST_STANDARD
13230 ? "standard"
13231 : "expanded",
13232 list->name);
13233 }
13234 if (entry->any)
13235 vty_out(vty, " %s\n",
13236 community_direct_str(entry->direct));
13237 else
13238 vty_out(vty, " %s %s\n",
13239 community_direct_str(entry->direct),
13240 entry->style == EXTCOMMUNITY_LIST_STANDARD
13241 ? entry->u.ecom->str
13242 : entry->config);
13243 }
718e3744 13244}
13245
13246DEFUN (show_ip_extcommunity_list,
13247 show_ip_extcommunity_list_cmd,
13248 "show ip extcommunity-list",
13249 SHOW_STR
13250 IP_STR
13251 "List extended-community list\n")
13252{
d62a17ae 13253 struct community_list *list;
13254 struct community_list_master *cm;
718e3744 13255
d62a17ae 13256 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13257 if (!cm)
13258 return CMD_SUCCESS;
718e3744 13259
d62a17ae 13260 for (list = cm->num.head; list; list = list->next)
13261 extcommunity_list_show(vty, list);
718e3744 13262
d62a17ae 13263 for (list = cm->str.head; list; list = list->next)
13264 extcommunity_list_show(vty, list);
718e3744 13265
d62a17ae 13266 return CMD_SUCCESS;
718e3744 13267}
13268
13269DEFUN (show_ip_extcommunity_list_arg,
13270 show_ip_extcommunity_list_arg_cmd,
6147e2c6 13271 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 13272 SHOW_STR
13273 IP_STR
13274 "List extended-community list\n"
13275 "Extcommunity-list number\n"
13276 "Extcommunity-list name\n")
13277{
d62a17ae 13278 int idx_comm_list = 3;
13279 struct community_list *list;
718e3744 13280
d62a17ae 13281 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13282 EXTCOMMUNITY_LIST_MASTER);
13283 if (!list) {
13284 vty_out(vty, "%% Can't find extcommunity-list\n");
13285 return CMD_WARNING;
13286 }
718e3744 13287
d62a17ae 13288 extcommunity_list_show(vty, list);
718e3744 13289
d62a17ae 13290 return CMD_SUCCESS;
718e3744 13291}
6b0655a2 13292
718e3744 13293/* Return configuration string of community-list entry. */
d62a17ae 13294static const char *community_list_config_str(struct community_entry *entry)
718e3744 13295{
d62a17ae 13296 const char *str;
718e3744 13297
d62a17ae 13298 if (entry->any)
13299 str = "";
13300 else {
13301 if (entry->style == COMMUNITY_LIST_STANDARD)
13302 str = community_str(entry->u.com);
13303 else
13304 str = entry->config;
13305 }
13306 return str;
718e3744 13307}
13308
13309/* Display community-list and extcommunity-list configuration. */
d62a17ae 13310static int community_list_config_write(struct vty *vty)
13311{
13312 struct community_list *list;
13313 struct community_entry *entry;
13314 struct community_list_master *cm;
13315 int write = 0;
13316
13317 /* Community-list. */
13318 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13319
13320 for (list = cm->num.head; list; list = list->next)
13321 for (entry = list->head; entry; entry = entry->next) {
13322 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13323 community_direct_str(entry->direct),
13324 community_list_config_str(entry));
13325 write++;
13326 }
13327 for (list = cm->str.head; list; list = list->next)
13328 for (entry = list->head; entry; entry = entry->next) {
13329 vty_out(vty, "ip community-list %s %s %s %s\n",
13330 entry->style == COMMUNITY_LIST_STANDARD
13331 ? "standard"
13332 : "expanded",
13333 list->name, community_direct_str(entry->direct),
13334 community_list_config_str(entry));
13335 write++;
13336 }
13337
13338 /* Extcommunity-list. */
13339 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13340
13341 for (list = cm->num.head; list; list = list->next)
13342 for (entry = list->head; entry; entry = entry->next) {
13343 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13344 list->name, community_direct_str(entry->direct),
13345 community_list_config_str(entry));
13346 write++;
13347 }
13348 for (list = cm->str.head; list; list = list->next)
13349 for (entry = list->head; entry; entry = entry->next) {
13350 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13351 entry->style == EXTCOMMUNITY_LIST_STANDARD
13352 ? "standard"
13353 : "expanded",
13354 list->name, community_direct_str(entry->direct),
13355 community_list_config_str(entry));
13356 write++;
13357 }
13358
13359
13360 /* lcommunity-list. */
13361 cm = community_list_master_lookup(bgp_clist,
13362 LARGE_COMMUNITY_LIST_MASTER);
13363
13364 for (list = cm->num.head; list; list = list->next)
13365 for (entry = list->head; entry; entry = entry->next) {
13366 vty_out(vty, "ip large-community-list %s %s %s\n",
13367 list->name, community_direct_str(entry->direct),
13368 community_list_config_str(entry));
13369 write++;
13370 }
13371 for (list = cm->str.head; list; list = list->next)
13372 for (entry = list->head; entry; entry = entry->next) {
13373 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13374 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13375 ? "standard"
13376 : "expanded",
13377 list->name, community_direct_str(entry->direct),
13378 community_list_config_str(entry));
13379 write++;
13380 }
13381
13382 return write;
13383}
13384
13385static struct cmd_node community_list_node = {
13386 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 13387};
13388
d62a17ae 13389static void community_list_vty(void)
13390{
13391 install_node(&community_list_node, community_list_config_write);
13392
13393 /* Community-list. */
13394 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13395 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13396 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13397 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13398 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13399 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13400
13401 /* Extcommunity-list. */
13402 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13403 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13404 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13405 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13406 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13407 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13408
13409 /* Large Community List */
13410 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13411 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13412 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13413 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13414 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13415 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13416 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13417 install_element(CONFIG_NODE,
13418 &no_ip_lcommunity_list_name_expanded_all_cmd);
13419 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13420 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13421 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13422 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13423 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13424 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 13425}