]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #1738 from chiragshah6/ospfv3_dev
[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"
555e09d4 60#include "bgpd/bgp_io.h"
94c2f693 61#include "bgpd/bgp_evpn.h"
718e3744 62
d62a17ae 63static struct peer_group *listen_range_exists(struct bgp *bgp,
64 struct prefix *range, int exact);
65
66static enum node_type bgp_node_type(afi_t afi, safi_t safi)
67{
68 switch (afi) {
69 case AFI_IP:
70 switch (safi) {
71 case SAFI_UNICAST:
72 return BGP_IPV4_NODE;
73 break;
74 case SAFI_MULTICAST:
75 return BGP_IPV4M_NODE;
76 break;
77 case SAFI_LABELED_UNICAST:
78 return BGP_IPV4L_NODE;
79 break;
80 case SAFI_MPLS_VPN:
81 return BGP_VPNV4_NODE;
82 break;
5c525538
RW
83 default:
84 /* not expected */
85 return BGP_IPV4_NODE;
86 break;
d62a17ae 87 }
88 break;
89 case AFI_IP6:
90 switch (safi) {
91 case SAFI_UNICAST:
92 return BGP_IPV6_NODE;
93 break;
94 case SAFI_MULTICAST:
95 return BGP_IPV6M_NODE;
96 break;
97 case SAFI_LABELED_UNICAST:
98 return BGP_IPV6L_NODE;
99 break;
100 case SAFI_MPLS_VPN:
101 return BGP_VPNV6_NODE;
102 break;
5c525538
RW
103 default:
104 /* not expected */
105 return BGP_IPV4_NODE;
106 break;
d62a17ae 107 }
108 break;
109 case AFI_L2VPN:
110 return BGP_EVPN_NODE;
111 break;
112 case AFI_MAX:
113 // We should never be here but to clarify the switch statement..
114 return BGP_IPV4_NODE;
115 break;
116 }
117
118 // Impossible to happen
119 return BGP_IPV4_NODE;
f51bae9c 120}
20eb8864 121
718e3744 122/* Utility function to get address family from current node. */
d62a17ae 123afi_t bgp_node_afi(struct vty *vty)
124{
125 afi_t afi;
126 switch (vty->node) {
127 case BGP_IPV6_NODE:
128 case BGP_IPV6M_NODE:
129 case BGP_IPV6L_NODE:
130 case BGP_VPNV6_NODE:
131 afi = AFI_IP6;
132 break;
133 case BGP_EVPN_NODE:
134 afi = AFI_L2VPN;
135 break;
136 default:
137 afi = AFI_IP;
138 break;
139 }
140 return afi;
718e3744 141}
142
143/* Utility function to get subsequent address family from current
144 node. */
d62a17ae 145safi_t bgp_node_safi(struct vty *vty)
146{
147 safi_t safi;
148 switch (vty->node) {
149 case BGP_VPNV4_NODE:
150 case BGP_VPNV6_NODE:
151 safi = SAFI_MPLS_VPN;
152 break;
153 case BGP_IPV4M_NODE:
154 case BGP_IPV6M_NODE:
155 safi = SAFI_MULTICAST;
156 break;
157 case BGP_EVPN_NODE:
158 safi = SAFI_EVPN;
159 break;
160 case BGP_IPV4L_NODE:
161 case BGP_IPV6L_NODE:
162 safi = SAFI_LABELED_UNICAST;
163 break;
164 default:
165 safi = SAFI_UNICAST;
166 break;
167 }
168 return safi;
718e3744 169}
170
55f91488
QY
171/**
172 * Converts an AFI in string form to afi_t
173 *
174 * @param afi string, one of
175 * - "ipv4"
176 * - "ipv6"
177 * @return the corresponding afi_t
178 */
d62a17ae 179afi_t bgp_vty_afi_from_str(const char *afi_str)
180{
181 afi_t afi = AFI_MAX; /* unknown */
182 if (strmatch(afi_str, "ipv4"))
183 afi = AFI_IP;
184 else if (strmatch(afi_str, "ipv6"))
185 afi = AFI_IP6;
186 return afi;
187}
188
189int argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index,
190 afi_t *afi)
191{
192 int ret = 0;
193 if (argv_find(argv, argc, "ipv4", index)) {
194 ret = 1;
195 if (afi)
196 *afi = AFI_IP;
197 } else if (argv_find(argv, argc, "ipv6", index)) {
198 ret = 1;
199 if (afi)
200 *afi = AFI_IP6;
201 }
202 return ret;
46f296b4
LB
203}
204
375a2e67 205/* supports <unicast|multicast|vpn|labeled-unicast> */
d62a17ae 206safi_t bgp_vty_safi_from_str(const char *safi_str)
207{
208 safi_t safi = SAFI_MAX; /* unknown */
209 if (strmatch(safi_str, "multicast"))
210 safi = SAFI_MULTICAST;
211 else if (strmatch(safi_str, "unicast"))
212 safi = SAFI_UNICAST;
213 else if (strmatch(safi_str, "vpn"))
214 safi = SAFI_MPLS_VPN;
215 else if (strmatch(safi_str, "labeled-unicast"))
216 safi = SAFI_LABELED_UNICAST;
217 return safi;
218}
219
220int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index,
221 safi_t *safi)
222{
223 int ret = 0;
224 if (argv_find(argv, argc, "unicast", index)) {
225 ret = 1;
226 if (safi)
227 *safi = SAFI_UNICAST;
228 } else if (argv_find(argv, argc, "multicast", index)) {
229 ret = 1;
230 if (safi)
231 *safi = SAFI_MULTICAST;
232 } else if (argv_find(argv, argc, "labeled-unicast", index)) {
233 ret = 1;
234 if (safi)
235 *safi = SAFI_LABELED_UNICAST;
236 } else if (argv_find(argv, argc, "vpn", index)) {
237 ret = 1;
238 if (safi)
239 *safi = SAFI_MPLS_VPN;
240 }
241 return ret;
46f296b4
LB
242}
243
7eeee51e 244/*
f212a857 245 * bgp_vty_find_and_parse_afi_safi_bgp
7eeee51e 246 *
f212a857
DS
247 * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
248 * This function *assumes* that the calling function pre-sets the afi/safi/bgp
7eeee51e
DS
249 * to appropriate values for the calling function. This is to allow the
250 * calling function to make decisions appropriate for the show command
251 * that is being parsed.
252 *
253 * The show commands are generally of the form:
d62a17ae 254 * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>
255 * [<unicast|multicast|vpn|labeled-unicast>]] ..."
7eeee51e
DS
256 *
257 * Since we use argv_find if the show command in particular doesn't have:
258 * [ip]
18c57037 259 * [<view|vrf> VIEWVRFNAME]
375a2e67 260 * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
7eeee51e
DS
261 * The command parsing should still be ok.
262 *
263 * vty -> The vty for the command so we can output some useful data in
264 * the event of a parse error in the vrf.
265 * argv -> The command tokens
266 * argc -> How many command tokens we have
d62a17ae 267 * idx -> The current place in the command, generally should be 0 for this
268 * function
7eeee51e
DS
269 * afi -> The parsed afi if it was included in the show command, returned here
270 * safi -> The parsed safi if it was included in the show command, returned here
f212a857 271 * bgp -> Pointer to the bgp data structure we need to fill in.
7eeee51e
DS
272 *
273 * The function returns the correct location in the parse tree for the
274 * last token found.
0e37c258
DS
275 *
276 * Returns 0 for failure to parse correctly, else the idx position of where
277 * it found the last token.
7eeee51e 278 */
d62a17ae 279int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,
280 struct cmd_token **argv, int argc,
281 int *idx, afi_t *afi, safi_t *safi,
282 struct bgp **bgp)
283{
284 char *vrf_name = NULL;
285
286 assert(afi);
287 assert(safi);
288 assert(bgp);
289
290 if (argv_find(argv, argc, "ip", idx))
291 *afi = AFI_IP;
292
293 if (argv_find(argv, argc, "view", idx)
294 || argv_find(argv, argc, "vrf", idx)) {
295 vrf_name = argv[*idx + 1]->arg;
296
297 if (strmatch(vrf_name, "all"))
298 *bgp = NULL;
299 else {
300 *bgp = bgp_lookup_by_name(vrf_name);
301 if (!*bgp) {
302 vty_out(vty,
303 "View/Vrf specified is unknown: %s\n",
304 vrf_name);
305 *idx = 0;
306 return 0;
307 }
308 }
309 } else {
310 *bgp = bgp_get_default();
311 if (!*bgp) {
312 vty_out(vty, "Unable to find default BGP instance\n");
313 *idx = 0;
314 return 0;
315 }
316 }
317
318 if (argv_find_and_parse_afi(argv, argc, idx, afi))
319 argv_find_and_parse_safi(argv, argc, idx, safi);
320
321 *idx += 1;
322 return *idx;
323}
324
325static int peer_address_self_check(struct bgp *bgp, union sockunion *su)
326{
327 struct interface *ifp = NULL;
328
329 if (su->sa.sa_family == AF_INET)
330 ifp = if_lookup_by_ipv4_exact(&su->sin.sin_addr, bgp->vrf_id);
331 else if (su->sa.sa_family == AF_INET6)
332 ifp = if_lookup_by_ipv6_exact(&su->sin6.sin6_addr,
333 su->sin6.sin6_scope_id,
334 bgp->vrf_id);
335
336 if (ifp)
337 return 1;
338
339 return 0;
718e3744 340}
341
342/* Utility function for looking up peer from VTY. */
f14e6fdb
DS
343/* This is used only for configuration, so disallow if attempted on
344 * a dynamic neighbor.
345 */
d62a17ae 346static struct peer *peer_lookup_vty(struct vty *vty, const char *ip_str)
347{
348 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
349 int ret;
350 union sockunion su;
351 struct peer *peer;
352
353 if (!bgp) {
354 return NULL;
355 }
356
357 ret = str2sockunion(ip_str, &su);
358 if (ret < 0) {
359 peer = peer_lookup_by_conf_if(bgp, ip_str);
360 if (!peer) {
361 if ((peer = peer_lookup_by_hostname(bgp, ip_str))
362 == NULL) {
363 vty_out(vty,
364 "%% Malformed address or name: %s\n",
365 ip_str);
366 return NULL;
367 }
368 }
369 } else {
370 peer = peer_lookup(bgp, &su);
371 if (!peer) {
372 vty_out(vty,
373 "%% Specify remote-as or peer-group commands first\n");
374 return NULL;
375 }
376 if (peer_dynamic_neighbor(peer)) {
377 vty_out(vty,
378 "%% Operation not allowed on a dynamic neighbor\n");
379 return NULL;
380 }
381 }
382 return peer;
718e3744 383}
384
385/* Utility function for looking up peer or peer group. */
f14e6fdb
DS
386/* This is used only for configuration, so disallow if attempted on
387 * a dynamic neighbor.
388 */
d62a17ae 389struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str)
390{
391 struct bgp *bgp = VTY_GET_CONTEXT(bgp);
392 int ret;
393 union sockunion su;
394 struct peer *peer = NULL;
395 struct peer_group *group = NULL;
396
397 if (!bgp) {
398 return NULL;
399 }
400
401 ret = str2sockunion(peer_str, &su);
402 if (ret == 0) {
403 /* IP address, locate peer. */
404 peer = peer_lookup(bgp, &su);
405 } else {
406 /* Not IP, could match either peer configured on interface or a
407 * group. */
408 peer = peer_lookup_by_conf_if(bgp, peer_str);
409 if (!peer)
410 group = peer_group_lookup(bgp, peer_str);
411 }
412
413 if (peer) {
414 if (peer_dynamic_neighbor(peer)) {
415 vty_out(vty,
416 "%% Operation not allowed on a dynamic neighbor\n");
417 return NULL;
418 }
419
420 return peer;
421 }
422
423 if (group)
424 return group->conf;
425
426 vty_out(vty, "%% Specify remote-as or peer-group commands first\n");
427
428 return NULL;
429}
430
431int bgp_vty_return(struct vty *vty, int ret)
432{
433 const char *str = NULL;
434
435 switch (ret) {
436 case BGP_ERR_INVALID_VALUE:
437 str = "Invalid value";
438 break;
439 case BGP_ERR_INVALID_FLAG:
440 str = "Invalid flag";
441 break;
442 case BGP_ERR_PEER_GROUP_SHUTDOWN:
443 str = "Peer-group has been shutdown. Activate the peer-group first";
444 break;
445 case BGP_ERR_PEER_FLAG_CONFLICT:
446 str = "Can't set override-capability and strict-capability-match at the same time";
447 break;
448 case BGP_ERR_PEER_GROUP_NO_REMOTE_AS:
449 str = "Specify remote-as or peer-group remote AS first";
450 break;
451 case BGP_ERR_PEER_GROUP_CANT_CHANGE:
452 str = "Cannot change the peer-group. Deconfigure first";
453 break;
454 case BGP_ERR_PEER_GROUP_MISMATCH:
455 str = "Peer is not a member of this peer-group";
456 break;
457 case BGP_ERR_PEER_FILTER_CONFLICT:
458 str = "Prefix/distribute list can not co-exist";
459 break;
460 case BGP_ERR_NOT_INTERNAL_PEER:
461 str = "Invalid command. Not an internal neighbor";
462 break;
463 case BGP_ERR_REMOVE_PRIVATE_AS:
464 str = "remove-private-AS cannot be configured for IBGP peers";
465 break;
466 case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
467 str = "Local-AS allowed only for EBGP peers";
468 break;
469 case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
470 str = "Cannot have local-as same as BGP AS number";
471 break;
472 case BGP_ERR_TCPSIG_FAILED:
473 str = "Error while applying TCP-Sig to session(s)";
474 break;
475 case BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK:
476 str = "ebgp-multihop and ttl-security cannot be configured together";
477 break;
478 case BGP_ERR_NO_IBGP_WITH_TTLHACK:
479 str = "ttl-security only allowed for EBGP peers";
480 break;
481 case BGP_ERR_AS_OVERRIDE:
482 str = "as-override cannot be configured for IBGP peers";
483 break;
484 case BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT:
485 str = "Invalid limit for number of dynamic neighbors";
486 break;
487 case BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS:
488 str = "Dynamic neighbor listen range already exists";
489 break;
490 case BGP_ERR_INVALID_FOR_DYNAMIC_PEER:
491 str = "Operation not allowed on a dynamic neighbor";
492 break;
493 case BGP_ERR_INVALID_FOR_DIRECT_PEER:
494 str = "Operation not allowed on a directly connected neighbor";
495 break;
496 case BGP_ERR_PEER_SAFI_CONFLICT:
497 str = "Cannot activate peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast'";
498 break;
499 }
500 if (str) {
501 vty_out(vty, "%% %s\n", str);
502 return CMD_WARNING_CONFIG_FAILED;
503 }
504 return CMD_SUCCESS;
718e3744 505}
506
7aafcaca 507/* BGP clear sort. */
d62a17ae 508enum clear_sort {
509 clear_all,
510 clear_peer,
511 clear_group,
512 clear_external,
513 clear_as
7aafcaca
DS
514};
515
d62a17ae 516static void bgp_clear_vty_error(struct vty *vty, struct peer *peer, afi_t afi,
517 safi_t safi, int error)
518{
519 switch (error) {
520 case BGP_ERR_AF_UNCONFIGURED:
521 vty_out(vty,
522 "%%BGP: Enable %s address family for the neighbor %s\n",
523 afi_safi_print(afi, safi), peer->host);
524 break;
525 case BGP_ERR_SOFT_RECONFIG_UNCONFIGURED:
526 vty_out(vty,
527 "%%BGP: Inbound soft reconfig for %s not possible as it\n has neither refresh capability, nor inbound soft reconfig\n",
528 peer->host);
529 break;
530 default:
531 break;
532 }
7aafcaca
DS
533}
534
535/* `clear ip bgp' functions. */
d62a17ae 536static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
537 enum clear_sort sort, enum bgp_clear_type stype,
538 const char *arg)
539{
540 int ret;
541 struct peer *peer;
542 struct listnode *node, *nnode;
543
544 /* Clear all neighbors. */
545 /*
546 * Pass along pointer to next node to peer_clear() when walking all
547 * nodes
548 * on the BGP instance as that may get freed if it is a doppelganger
549 */
550 if (sort == clear_all) {
551 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
552 if (stype == BGP_CLEAR_SOFT_NONE)
553 ret = peer_clear(peer, &nnode);
554 else if (peer->afc[afi][safi])
555 ret = peer_clear_soft(peer, afi, safi, stype);
556 else
557 ret = 0;
558
559 if (ret < 0)
560 bgp_clear_vty_error(vty, peer, afi, safi, ret);
04b6bdc0 561 }
d62a17ae 562
563 /* This is to apply read-only mode on this clear. */
564 if (stype == BGP_CLEAR_SOFT_NONE)
565 bgp->update_delay_over = 0;
566
567 return CMD_SUCCESS;
7aafcaca
DS
568 }
569
d62a17ae 570 /* Clear specified neighbors. */
571 if (sort == clear_peer) {
572 union sockunion su;
573 int ret;
574
575 /* Make sockunion for lookup. */
576 ret = str2sockunion(arg, &su);
577 if (ret < 0) {
578 peer = peer_lookup_by_conf_if(bgp, arg);
579 if (!peer) {
580 peer = peer_lookup_by_hostname(bgp, arg);
581 if (!peer) {
582 vty_out(vty,
583 "Malformed address or name: %s\n",
584 arg);
585 return CMD_WARNING;
586 }
587 }
588 } else {
589 peer = peer_lookup(bgp, &su);
590 if (!peer) {
591 vty_out(vty,
592 "%%BGP: Unknown neighbor - \"%s\"\n",
593 arg);
594 return CMD_WARNING;
595 }
596 }
7aafcaca 597
d62a17ae 598 if (stype == BGP_CLEAR_SOFT_NONE)
599 ret = peer_clear(peer, NULL);
600 else
601 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 602
d62a17ae 603 if (ret < 0)
604 bgp_clear_vty_error(vty, peer, afi, safi, ret);
7aafcaca 605
d62a17ae 606 return CMD_SUCCESS;
7aafcaca 607 }
7aafcaca 608
d62a17ae 609 /* Clear all peer-group members. */
610 if (sort == clear_group) {
611 struct peer_group *group;
7aafcaca 612
d62a17ae 613 group = peer_group_lookup(bgp, arg);
614 if (!group) {
615 vty_out(vty, "%%BGP: No such peer-group %s\n", arg);
616 return CMD_WARNING;
617 }
618
619 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
620 if (stype == BGP_CLEAR_SOFT_NONE) {
621 peer_clear(peer, NULL);
622 continue;
623 }
624
625 if (!peer->afc[afi][safi])
626 continue;
627
628 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 629
d62a17ae 630 if (ret < 0)
631 bgp_clear_vty_error(vty, peer, afi, safi, ret);
632 }
633 return CMD_SUCCESS;
7aafcaca 634 }
7aafcaca 635
d62a17ae 636 if (sort == clear_external) {
637 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
638 if (peer->sort == BGP_PEER_IBGP)
639 continue;
7aafcaca 640
d62a17ae 641 if (stype == BGP_CLEAR_SOFT_NONE)
642 ret = peer_clear(peer, &nnode);
643 else
644 ret = peer_clear_soft(peer, afi, safi, stype);
7aafcaca 645
d62a17ae 646 if (ret < 0)
647 bgp_clear_vty_error(vty, peer, afi, safi, ret);
648 }
649 return CMD_SUCCESS;
650 }
651
652 if (sort == clear_as) {
653 as_t as;
654 int find = 0;
655
656 as = strtoul(arg, NULL, 10);
657
658 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
659 if (peer->as != as)
660 continue;
661
662 find = 1;
663 if (stype == BGP_CLEAR_SOFT_NONE)
664 ret = peer_clear(peer, &nnode);
665 else
666 ret = peer_clear_soft(peer, afi, safi, stype);
667
668 if (ret < 0)
669 bgp_clear_vty_error(vty, peer, afi, safi, ret);
670 }
671 if (!find)
672 vty_out(vty,
673 "%%BGP: No peer is configured with AS %s\n",
674 arg);
675 return CMD_SUCCESS;
676 }
677
678 return CMD_SUCCESS;
679}
680
681static int bgp_clear_vty(struct vty *vty, const char *name, afi_t afi,
682 safi_t safi, enum clear_sort sort,
683 enum bgp_clear_type stype, const char *arg)
684{
685 struct bgp *bgp;
686
687 /* BGP structure lookup. */
688 if (name) {
689 bgp = bgp_lookup_by_name(name);
690 if (bgp == NULL) {
691 vty_out(vty, "Can't find BGP instance %s\n", name);
692 return CMD_WARNING;
693 }
694 } else {
695 bgp = bgp_get_default();
696 if (bgp == NULL) {
697 vty_out(vty, "No BGP process is configured\n");
698 return CMD_WARNING;
699 }
700 }
701
702 return bgp_clear(vty, bgp, afi, safi, sort, stype, arg);
7aafcaca
DS
703}
704
705/* clear soft inbound */
d62a17ae 706static void bgp_clear_star_soft_in(struct vty *vty, const char *name)
7aafcaca 707{
d62a17ae 708 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
709 BGP_CLEAR_SOFT_IN, NULL);
710 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
711 BGP_CLEAR_SOFT_IN, NULL);
7aafcaca
DS
712}
713
714/* clear soft outbound */
d62a17ae 715static void bgp_clear_star_soft_out(struct vty *vty, const char *name)
7aafcaca 716{
d62a17ae 717 bgp_clear_vty(vty, name, AFI_IP, SAFI_UNICAST, clear_all,
718 BGP_CLEAR_SOFT_OUT, NULL);
719 bgp_clear_vty(vty, name, AFI_IP6, SAFI_UNICAST, clear_all,
720 BGP_CLEAR_SOFT_OUT, NULL);
7aafcaca
DS
721}
722
723
f787d7a0 724#ifndef VTYSH_EXTRACT_PL
2e4c2296 725#include "bgpd/bgp_vty_clippy.c"
f787d7a0
DL
726#endif
727
718e3744 728/* BGP global configuration. */
729
730DEFUN (bgp_multiple_instance_func,
731 bgp_multiple_instance_cmd,
732 "bgp multiple-instance",
733 BGP_STR
734 "Enable bgp multiple instance\n")
735{
d62a17ae 736 bgp_option_set(BGP_OPT_MULTIPLE_INSTANCE);
737 return CMD_SUCCESS;
718e3744 738}
739
740DEFUN (no_bgp_multiple_instance,
741 no_bgp_multiple_instance_cmd,
742 "no bgp multiple-instance",
743 NO_STR
744 BGP_STR
745 "BGP multiple instance\n")
746{
d62a17ae 747 int ret;
718e3744 748
d62a17ae 749 ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
750 if (ret < 0) {
751 vty_out(vty, "%% There are more than two BGP instances\n");
752 return CMD_WARNING_CONFIG_FAILED;
753 }
754 return CMD_SUCCESS;
718e3744 755}
756
757DEFUN (bgp_config_type,
758 bgp_config_type_cmd,
6147e2c6 759 "bgp config-type <cisco|zebra>",
718e3744 760 BGP_STR
761 "Configuration type\n"
762 "cisco\n"
763 "zebra\n")
764{
d62a17ae 765 int idx = 0;
766 if (argv_find(argv, argc, "cisco", &idx))
767 bgp_option_set(BGP_OPT_CONFIG_CISCO);
768 else
769 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
718e3744 770
d62a17ae 771 return CMD_SUCCESS;
718e3744 772}
773
774DEFUN (no_bgp_config_type,
775 no_bgp_config_type_cmd,
c7178fe7 776 "no bgp config-type [<cisco|zebra>]",
718e3744 777 NO_STR
778 BGP_STR
838758ac
DW
779 "Display configuration type\n"
780 "cisco\n"
781 "zebra\n")
718e3744 782{
d62a17ae 783 bgp_option_unset(BGP_OPT_CONFIG_CISCO);
784 return CMD_SUCCESS;
718e3744 785}
786
813d4307 787
718e3744 788DEFUN (no_synchronization,
789 no_synchronization_cmd,
790 "no synchronization",
791 NO_STR
792 "Perform IGP synchronization\n")
793{
d62a17ae 794 return CMD_SUCCESS;
718e3744 795}
796
797DEFUN (no_auto_summary,
798 no_auto_summary_cmd,
799 "no auto-summary",
800 NO_STR
801 "Enable automatic network number summarization\n")
802{
d62a17ae 803 return CMD_SUCCESS;
718e3744 804}
3d515fd9 805
718e3744 806/* "router bgp" commands. */
505e5056 807DEFUN_NOSH (router_bgp,
f412b39a 808 router_bgp_cmd,
18c57037 809 "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 810 ROUTER_STR
811 BGP_STR
31500417
DW
812 AS_STR
813 BGP_INSTANCE_HELP_STR)
718e3744 814{
d62a17ae 815 int idx_asn = 2;
816 int idx_view_vrf = 3;
817 int idx_vrf = 4;
818 int ret;
819 as_t as;
820 struct bgp *bgp;
821 const char *name = NULL;
822 enum bgp_instance_type inst_type;
823
824 // "router bgp" without an ASN
825 if (argc == 2) {
826 // Pending: Make VRF option available for ASN less config
827 bgp = bgp_get_default();
828
829 if (bgp == NULL) {
830 vty_out(vty, "%% No BGP process is configured\n");
831 return CMD_WARNING_CONFIG_FAILED;
832 }
833
834 if (listcount(bm->bgp) > 1) {
835 vty_out(vty,
836 "%% Multiple BGP processes are configured\n");
837 return CMD_WARNING_CONFIG_FAILED;
838 }
839 }
840
841 // "router bgp X"
842 else {
843 as = strtoul(argv[idx_asn]->arg, NULL, 10);
844
845 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
846 if (argc > 3) {
847 name = argv[idx_vrf]->arg;
848
849 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
850 inst_type = BGP_INSTANCE_TYPE_VRF;
851 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
852 inst_type = BGP_INSTANCE_TYPE_VIEW;
853 }
854
855 ret = bgp_get(&bgp, &as, name, inst_type);
856 switch (ret) {
857 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
858 vty_out(vty,
859 "Please specify 'bgp multiple-instance' first\n");
860 return CMD_WARNING_CONFIG_FAILED;
861 case BGP_ERR_AS_MISMATCH:
862 vty_out(vty, "BGP is already running; AS is %u\n", as);
863 return CMD_WARNING_CONFIG_FAILED;
864 case BGP_ERR_INSTANCE_MISMATCH:
865 vty_out(vty,
866 "BGP instance name and AS number mismatch\n");
867 vty_out(vty,
868 "BGP instance is already running; AS is %u\n",
869 as);
870 return CMD_WARNING_CONFIG_FAILED;
871 }
872
873 /* Pending: handle when user tries to change a view to vrf n vv.
874 */
875 }
876
0b5131c9
MK
877 /* unset the auto created flag as the user config is now present */
878 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 879 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
880
881 return CMD_SUCCESS;
718e3744 882}
883
718e3744 884/* "no router bgp" commands. */
885DEFUN (no_router_bgp,
886 no_router_bgp_cmd,
18c57037 887 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 888 NO_STR
889 ROUTER_STR
890 BGP_STR
31500417
DW
891 AS_STR
892 BGP_INSTANCE_HELP_STR)
718e3744 893{
d62a17ae 894 int idx_asn = 3;
895 int idx_vrf = 5;
896 as_t as;
897 struct bgp *bgp;
898 const char *name = NULL;
718e3744 899
d62a17ae 900 // "no router bgp" without an ASN
901 if (argc == 3) {
902 // Pending: Make VRF option available for ASN less config
903 bgp = bgp_get_default();
718e3744 904
d62a17ae 905 if (bgp == NULL) {
906 vty_out(vty, "%% No BGP process is configured\n");
907 return CMD_WARNING_CONFIG_FAILED;
908 }
7fb21a9f 909
d62a17ae 910 if (listcount(bm->bgp) > 1) {
911 vty_out(vty,
912 "%% Multiple BGP processes are configured\n");
913 return CMD_WARNING_CONFIG_FAILED;
914 }
0b5131c9
MK
915
916 if (bgp->l3vni) {
917 vty_out(vty, "%% Please unconfigure l3vni %u",
918 bgp->l3vni);
919 return CMD_WARNING_CONFIG_FAILED;
920 }
d62a17ae 921 } else {
922 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 923
d62a17ae 924 if (argc > 4)
925 name = argv[idx_vrf]->arg;
7fb21a9f 926
d62a17ae 927 /* Lookup bgp structure. */
928 bgp = bgp_lookup(as, name);
929 if (!bgp) {
930 vty_out(vty, "%% Can't find BGP instance\n");
931 return CMD_WARNING_CONFIG_FAILED;
932 }
0b5131c9
MK
933
934 if (bgp->l3vni) {
935 vty_out(vty, "%% Please unconfigure l3vni %u",
936 bgp->l3vni);
937 return CMD_WARNING_CONFIG_FAILED;
938 }
d62a17ae 939 }
718e3744 940
d62a17ae 941 bgp_delete(bgp);
718e3744 942
d62a17ae 943 return CMD_SUCCESS;
718e3744 944}
945
6b0655a2 946
718e3744 947/* BGP router-id. */
948
f787d7a0 949DEFPY (bgp_router_id,
718e3744 950 bgp_router_id_cmd,
951 "bgp router-id A.B.C.D",
952 BGP_STR
953 "Override configured router identifier\n"
954 "Manually configured router identifier\n")
955{
d62a17ae 956 VTY_DECLVAR_CONTEXT(bgp, bgp);
957 bgp_router_id_static_set(bgp, router_id);
958 return CMD_SUCCESS;
718e3744 959}
960
f787d7a0 961DEFPY (no_bgp_router_id,
718e3744 962 no_bgp_router_id_cmd,
31500417 963 "no bgp router-id [A.B.C.D]",
718e3744 964 NO_STR
965 BGP_STR
31500417
DW
966 "Override configured router identifier\n"
967 "Manually configured router identifier\n")
718e3744 968{
d62a17ae 969 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 970
d62a17ae 971 if (router_id_str) {
972 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
973 vty_out(vty, "%% BGP router-id doesn't match\n");
974 return CMD_WARNING_CONFIG_FAILED;
975 }
e018c7cc 976 }
718e3744 977
d62a17ae 978 router_id.s_addr = 0;
979 bgp_router_id_static_set(bgp, router_id);
718e3744 980
d62a17ae 981 return CMD_SUCCESS;
718e3744 982}
983
6b0655a2 984
718e3744 985/* BGP Cluster ID. */
718e3744 986DEFUN (bgp_cluster_id,
987 bgp_cluster_id_cmd,
838758ac 988 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 989 BGP_STR
990 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
991 "Route-Reflector Cluster-id in IP address format\n"
992 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 993{
d62a17ae 994 VTY_DECLVAR_CONTEXT(bgp, bgp);
995 int idx_ipv4 = 2;
996 int ret;
997 struct in_addr cluster;
718e3744 998
d62a17ae 999 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
1000 if (!ret) {
1001 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1002 return CMD_WARNING_CONFIG_FAILED;
1003 }
718e3744 1004
d62a17ae 1005 bgp_cluster_id_set(bgp, &cluster);
1006 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1007
d62a17ae 1008 return CMD_SUCCESS;
718e3744 1009}
1010
718e3744 1011DEFUN (no_bgp_cluster_id,
1012 no_bgp_cluster_id_cmd,
c7178fe7 1013 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1014 NO_STR
1015 BGP_STR
838758ac
DW
1016 "Configure Route-Reflector Cluster-id\n"
1017 "Route-Reflector Cluster-id in IP address format\n"
1018 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1019{
d62a17ae 1020 VTY_DECLVAR_CONTEXT(bgp, bgp);
1021 bgp_cluster_id_unset(bgp);
1022 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1023
d62a17ae 1024 return CMD_SUCCESS;
718e3744 1025}
1026
718e3744 1027DEFUN (bgp_confederation_identifier,
1028 bgp_confederation_identifier_cmd,
9ccf14f7 1029 "bgp confederation identifier (1-4294967295)",
718e3744 1030 "BGP specific commands\n"
1031 "AS confederation parameters\n"
1032 "AS number\n"
1033 "Set routing domain confederation AS\n")
1034{
d62a17ae 1035 VTY_DECLVAR_CONTEXT(bgp, bgp);
1036 int idx_number = 3;
1037 as_t as;
718e3744 1038
d62a17ae 1039 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1040
d62a17ae 1041 bgp_confederation_id_set(bgp, as);
718e3744 1042
d62a17ae 1043 return CMD_SUCCESS;
718e3744 1044}
1045
1046DEFUN (no_bgp_confederation_identifier,
1047 no_bgp_confederation_identifier_cmd,
838758ac 1048 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1049 NO_STR
1050 "BGP specific commands\n"
1051 "AS confederation parameters\n"
3a2d747c
QY
1052 "AS number\n"
1053 "Set routing domain confederation AS\n")
718e3744 1054{
d62a17ae 1055 VTY_DECLVAR_CONTEXT(bgp, bgp);
1056 bgp_confederation_id_unset(bgp);
718e3744 1057
d62a17ae 1058 return CMD_SUCCESS;
718e3744 1059}
1060
718e3744 1061DEFUN (bgp_confederation_peers,
1062 bgp_confederation_peers_cmd,
12dcf78e 1063 "bgp confederation peers (1-4294967295)...",
718e3744 1064 "BGP specific commands\n"
1065 "AS confederation parameters\n"
1066 "Peer ASs in BGP confederation\n"
1067 AS_STR)
1068{
d62a17ae 1069 VTY_DECLVAR_CONTEXT(bgp, bgp);
1070 int idx_asn = 3;
1071 as_t as;
1072 int i;
718e3744 1073
d62a17ae 1074 for (i = idx_asn; i < argc; i++) {
1075 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1076
d62a17ae 1077 if (bgp->as == as) {
1078 vty_out(vty,
1079 "%% Local member-AS not allowed in confed peer list\n");
1080 continue;
1081 }
718e3744 1082
d62a17ae 1083 bgp_confederation_peers_add(bgp, as);
1084 }
1085 return CMD_SUCCESS;
718e3744 1086}
1087
1088DEFUN (no_bgp_confederation_peers,
1089 no_bgp_confederation_peers_cmd,
e83a9414 1090 "no bgp confederation peers (1-4294967295)...",
718e3744 1091 NO_STR
1092 "BGP specific commands\n"
1093 "AS confederation parameters\n"
1094 "Peer ASs in BGP confederation\n"
1095 AS_STR)
1096{
d62a17ae 1097 VTY_DECLVAR_CONTEXT(bgp, bgp);
1098 int idx_asn = 4;
1099 as_t as;
1100 int i;
718e3744 1101
d62a17ae 1102 for (i = idx_asn; i < argc; i++) {
1103 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1104
d62a17ae 1105 bgp_confederation_peers_remove(bgp, as);
1106 }
1107 return CMD_SUCCESS;
718e3744 1108}
6b0655a2 1109
5e242b0d
DS
1110/**
1111 * Central routine for maximum-paths configuration.
1112 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1113 * @set: 1 for setting values, 0 for removing the max-paths config.
1114 */
d62a17ae 1115static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1116 const char *mpaths, u_int16_t options,
1117 int set)
1118{
1119 VTY_DECLVAR_CONTEXT(bgp, bgp);
1120 u_int16_t maxpaths = 0;
1121 int ret;
1122 afi_t afi;
1123 safi_t safi;
1124
1125 afi = bgp_node_afi(vty);
1126 safi = bgp_node_safi(vty);
1127
1128 if (set) {
1129 maxpaths = strtol(mpaths, NULL, 10);
1130 if (maxpaths > multipath_num) {
1131 vty_out(vty,
1132 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1133 maxpaths, multipath_num);
1134 return CMD_WARNING_CONFIG_FAILED;
1135 }
1136 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1137 options);
1138 } else
1139 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1140
1141 if (ret < 0) {
1142 vty_out(vty,
1143 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1144 (set == 1) ? "" : "un",
1145 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1146 maxpaths, afi, safi);
1147 return CMD_WARNING_CONFIG_FAILED;
1148 }
1149
1150 bgp_recalculate_all_bestpaths(bgp);
1151
1152 return CMD_SUCCESS;
165b5fff
JB
1153}
1154
abc920f8
DS
1155DEFUN (bgp_maxmed_admin,
1156 bgp_maxmed_admin_cmd,
1157 "bgp max-med administrative ",
1158 BGP_STR
1159 "Advertise routes with max-med\n"
1160 "Administratively applied, for an indefinite period\n")
1161{
d62a17ae 1162 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1163
d62a17ae 1164 bgp->v_maxmed_admin = 1;
1165 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1166
d62a17ae 1167 bgp_maxmed_update(bgp);
abc920f8 1168
d62a17ae 1169 return CMD_SUCCESS;
abc920f8
DS
1170}
1171
1172DEFUN (bgp_maxmed_admin_medv,
1173 bgp_maxmed_admin_medv_cmd,
4668a151 1174 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1175 BGP_STR
1176 "Advertise routes with max-med\n"
1177 "Administratively applied, for an indefinite period\n"
1178 "Max MED value to be used\n")
1179{
d62a17ae 1180 VTY_DECLVAR_CONTEXT(bgp, bgp);
1181 int idx_number = 3;
abc920f8 1182
d62a17ae 1183 bgp->v_maxmed_admin = 1;
1184 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1185
d62a17ae 1186 bgp_maxmed_update(bgp);
abc920f8 1187
d62a17ae 1188 return CMD_SUCCESS;
abc920f8
DS
1189}
1190
1191DEFUN (no_bgp_maxmed_admin,
1192 no_bgp_maxmed_admin_cmd,
4668a151 1193 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1194 NO_STR
1195 BGP_STR
1196 "Advertise routes with max-med\n"
838758ac
DW
1197 "Administratively applied, for an indefinite period\n"
1198 "Max MED value to be used\n")
abc920f8 1199{
d62a17ae 1200 VTY_DECLVAR_CONTEXT(bgp, bgp);
1201 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1202 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1203 bgp_maxmed_update(bgp);
abc920f8 1204
d62a17ae 1205 return CMD_SUCCESS;
abc920f8
DS
1206}
1207
abc920f8
DS
1208DEFUN (bgp_maxmed_onstartup,
1209 bgp_maxmed_onstartup_cmd,
4668a151 1210 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1211 BGP_STR
1212 "Advertise routes with max-med\n"
1213 "Effective on a startup\n"
1214 "Time (seconds) period for max-med\n"
1215 "Max MED value to be used\n")
1216{
d62a17ae 1217 VTY_DECLVAR_CONTEXT(bgp, bgp);
1218 int idx = 0;
4668a151 1219
d62a17ae 1220 argv_find(argv, argc, "(5-86400)", &idx);
1221 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1222 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1223 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1224 else
1225 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1226
d62a17ae 1227 bgp_maxmed_update(bgp);
abc920f8 1228
d62a17ae 1229 return CMD_SUCCESS;
abc920f8
DS
1230}
1231
1232DEFUN (no_bgp_maxmed_onstartup,
1233 no_bgp_maxmed_onstartup_cmd,
4668a151 1234 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1235 NO_STR
1236 BGP_STR
1237 "Advertise routes with max-med\n"
838758ac
DW
1238 "Effective on a startup\n"
1239 "Time (seconds) period for max-med\n"
1240 "Max MED value to be used\n")
abc920f8 1241{
d62a17ae 1242 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1243
d62a17ae 1244 /* Cancel max-med onstartup if its on */
1245 if (bgp->t_maxmed_onstartup) {
1246 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1247 bgp->maxmed_onstartup_over = 1;
1248 }
abc920f8 1249
d62a17ae 1250 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1251 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1252
d62a17ae 1253 bgp_maxmed_update(bgp);
abc920f8 1254
d62a17ae 1255 return CMD_SUCCESS;
abc920f8
DS
1256}
1257
d62a17ae 1258static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1259 const char *wait)
f188f2c4 1260{
d62a17ae 1261 VTY_DECLVAR_CONTEXT(bgp, bgp);
1262 u_int16_t update_delay;
1263 u_int16_t establish_wait;
f188f2c4 1264
d62a17ae 1265 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1266
d62a17ae 1267 if (!wait) /* update-delay <delay> */
1268 {
1269 bgp->v_update_delay = update_delay;
1270 bgp->v_establish_wait = bgp->v_update_delay;
1271 return CMD_SUCCESS;
1272 }
f188f2c4 1273
d62a17ae 1274 /* update-delay <delay> <establish-wait> */
1275 establish_wait = atoi(wait);
1276 if (update_delay < establish_wait) {
1277 vty_out(vty,
1278 "%%Failed: update-delay less than the establish-wait!\n");
1279 return CMD_WARNING_CONFIG_FAILED;
1280 }
f188f2c4 1281
d62a17ae 1282 bgp->v_update_delay = update_delay;
1283 bgp->v_establish_wait = establish_wait;
f188f2c4 1284
d62a17ae 1285 return CMD_SUCCESS;
f188f2c4
DS
1286}
1287
d62a17ae 1288static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1289{
d62a17ae 1290 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1291
d62a17ae 1292 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1293 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1294
d62a17ae 1295 return CMD_SUCCESS;
f188f2c4
DS
1296}
1297
2b791107 1298void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1299{
d62a17ae 1300 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1301 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1302 if (bgp->v_update_delay != bgp->v_establish_wait)
1303 vty_out(vty, " %d", bgp->v_establish_wait);
1304 vty_out(vty, "\n");
1305 }
f188f2c4
DS
1306}
1307
1308
1309/* Update-delay configuration */
1310DEFUN (bgp_update_delay,
1311 bgp_update_delay_cmd,
6147e2c6 1312 "update-delay (0-3600)",
f188f2c4
DS
1313 "Force initial delay for best-path and updates\n"
1314 "Seconds\n")
1315{
d62a17ae 1316 int idx_number = 1;
1317 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1318}
1319
1320DEFUN (bgp_update_delay_establish_wait,
1321 bgp_update_delay_establish_wait_cmd,
6147e2c6 1322 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1323 "Force initial delay for best-path and updates\n"
1324 "Seconds\n"
f188f2c4
DS
1325 "Seconds\n")
1326{
d62a17ae 1327 int idx_number = 1;
1328 int idx_number_2 = 2;
1329 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1330 argv[idx_number_2]->arg);
f188f2c4
DS
1331}
1332
1333/* Update-delay deconfiguration */
1334DEFUN (no_bgp_update_delay,
1335 no_bgp_update_delay_cmd,
838758ac
DW
1336 "no update-delay [(0-3600) [(1-3600)]]",
1337 NO_STR
f188f2c4 1338 "Force initial delay for best-path and updates\n"
838758ac 1339 "Seconds\n"
7111c1a0 1340 "Seconds\n")
f188f2c4 1341{
d62a17ae 1342 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1343}
1344
5e242b0d 1345
d62a17ae 1346static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1347 char set)
cb1faec9 1348{
d62a17ae 1349 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1350
555e09d4
QY
1351 if (set) {
1352 uint32_t quanta = strtoul(num, NULL, 10);
1353 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1354 memory_order_relaxed);
1355 } else {
1356 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1357 memory_order_relaxed);
1358 }
1359
1360 return CMD_SUCCESS;
1361}
1362
1363static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1364 char set)
1365{
1366 VTY_DECLVAR_CONTEXT(bgp, bgp);
1367
1368 if (set) {
1369 uint32_t quanta = strtoul(num, NULL, 10);
1370 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1371 memory_order_relaxed);
1372 } else {
1373 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1374 memory_order_relaxed);
1375 }
cb1faec9 1376
d62a17ae 1377 return CMD_SUCCESS;
cb1faec9
DS
1378}
1379
2b791107 1380void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1381{
555e09d4
QY
1382 uint32_t quanta =
1383 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1384 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1385 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1386}
1387
555e09d4
QY
1388void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1389{
1390 uint32_t quanta =
1391 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1392 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1393 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1394}
cb1faec9 1395
555e09d4 1396/* Packet quanta configuration */
cb1faec9
DS
1397DEFUN (bgp_wpkt_quanta,
1398 bgp_wpkt_quanta_cmd,
555e09d4 1399 "write-quanta (1-10)",
cb1faec9
DS
1400 "How many packets to write to peer socket per run\n"
1401 "Number of packets\n")
1402{
d62a17ae 1403 int idx_number = 1;
1404 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1405}
1406
cb1faec9
DS
1407DEFUN (no_bgp_wpkt_quanta,
1408 no_bgp_wpkt_quanta_cmd,
555e09d4 1409 "no write-quanta (1-10)",
d7fa34c1 1410 NO_STR
555e09d4 1411 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1412 "Number of packets\n")
1413{
d62a17ae 1414 int idx_number = 2;
1415 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1416}
1417
555e09d4
QY
1418DEFUN (bgp_rpkt_quanta,
1419 bgp_rpkt_quanta_cmd,
1420 "read-quanta (1-10)",
1421 "How many packets to read from peer socket per I/O cycle\n"
1422 "Number of packets\n")
1423{
1424 int idx_number = 1;
1425 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1426}
1427
1428DEFUN (no_bgp_rpkt_quanta,
1429 no_bgp_rpkt_quanta_cmd,
1430 "no read-quanta (1-10)",
1431 NO_STR
1432 "How many packets to read from peer socket per I/O cycle\n"
1433 "Number of packets\n")
1434{
1435 int idx_number = 2;
1436 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1437}
1438
2b791107 1439void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1440{
37a333fe 1441 if (!bgp->heuristic_coalesce)
d62a17ae 1442 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1443}
1444
1445
1446DEFUN (bgp_coalesce_time,
1447 bgp_coalesce_time_cmd,
6147e2c6 1448 "coalesce-time (0-4294967295)",
3f9c7369
DS
1449 "Subgroup coalesce timer\n"
1450 "Subgroup coalesce timer value (in ms)\n")
1451{
d62a17ae 1452 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1453
d62a17ae 1454 int idx = 0;
1455 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1456 bgp->heuristic_coalesce = false;
d62a17ae 1457 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1458 return CMD_SUCCESS;
3f9c7369
DS
1459}
1460
1461DEFUN (no_bgp_coalesce_time,
1462 no_bgp_coalesce_time_cmd,
6147e2c6 1463 "no coalesce-time (0-4294967295)",
3a2d747c 1464 NO_STR
3f9c7369
DS
1465 "Subgroup coalesce timer\n"
1466 "Subgroup coalesce timer value (in ms)\n")
1467{
d62a17ae 1468 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1469
37a333fe 1470 bgp->heuristic_coalesce = true;
d62a17ae 1471 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1472 return CMD_SUCCESS;
3f9c7369
DS
1473}
1474
5e242b0d
DS
1475/* Maximum-paths configuration */
1476DEFUN (bgp_maxpaths,
1477 bgp_maxpaths_cmd,
6319fd63 1478 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1479 "Forward packets over multiple paths\n"
1480 "Number of paths\n")
1481{
d62a17ae 1482 int idx_number = 1;
1483 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1484 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1485}
1486
d62a17ae 1487ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1488 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1489 "Forward packets over multiple paths\n"
1490 "Number of paths\n")
596c17ba 1491
165b5fff
JB
1492DEFUN (bgp_maxpaths_ibgp,
1493 bgp_maxpaths_ibgp_cmd,
6319fd63 1494 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1495 "Forward packets over multiple paths\n"
1496 "iBGP-multipath\n"
1497 "Number of paths\n")
1498{
d62a17ae 1499 int idx_number = 2;
1500 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1501 argv[idx_number]->arg, 0, 1);
5e242b0d 1502}
165b5fff 1503
d62a17ae 1504ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1505 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1506 "Forward packets over multiple paths\n"
1507 "iBGP-multipath\n"
1508 "Number of paths\n")
596c17ba 1509
5e242b0d
DS
1510DEFUN (bgp_maxpaths_ibgp_cluster,
1511 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1512 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1513 "Forward packets over multiple paths\n"
1514 "iBGP-multipath\n"
1515 "Number of paths\n"
1516 "Match the cluster length\n")
1517{
d62a17ae 1518 int idx_number = 2;
1519 return bgp_maxpaths_config_vty(
1520 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1521 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1522}
1523
d62a17ae 1524ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1525 "maximum-paths ibgp " CMD_RANGE_STR(
1526 1, MULTIPATH_NUM) " equal-cluster-length",
1527 "Forward packets over multiple paths\n"
1528 "iBGP-multipath\n"
1529 "Number of paths\n"
1530 "Match the cluster length\n")
596c17ba 1531
165b5fff
JB
1532DEFUN (no_bgp_maxpaths,
1533 no_bgp_maxpaths_cmd,
6319fd63 1534 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1535 NO_STR
1536 "Forward packets over multiple paths\n"
1537 "Number of paths\n")
1538{
d62a17ae 1539 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1540}
1541
d62a17ae 1542ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
a4d82a8a
PZ
1543 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
1544 NO_STR
d62a17ae 1545 "Forward packets over multiple paths\n"
1546 "Number of paths\n")
596c17ba 1547
165b5fff
JB
1548DEFUN (no_bgp_maxpaths_ibgp,
1549 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1550 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1551 NO_STR
1552 "Forward packets over multiple paths\n"
1553 "iBGP-multipath\n"
838758ac
DW
1554 "Number of paths\n"
1555 "Match the cluster length\n")
165b5fff 1556{
d62a17ae 1557 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1558}
1559
d62a17ae 1560ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1561 "no maximum-paths ibgp [" CMD_RANGE_STR(
1562 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1563 NO_STR
1564 "Forward packets over multiple paths\n"
1565 "iBGP-multipath\n"
1566 "Number of paths\n"
1567 "Match the cluster length\n")
596c17ba 1568
2b791107 1569void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1570 safi_t safi)
165b5fff 1571{
d62a17ae 1572 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1573 vty_out(vty, " maximum-paths %d\n",
1574 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1575 }
165b5fff 1576
d62a17ae 1577 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1578 vty_out(vty, " maximum-paths ibgp %d",
1579 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1580 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1581 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1582 vty_out(vty, " equal-cluster-length");
1583 vty_out(vty, "\n");
1584 }
165b5fff 1585}
6b0655a2 1586
718e3744 1587/* BGP timers. */
1588
1589DEFUN (bgp_timers,
1590 bgp_timers_cmd,
6147e2c6 1591 "timers bgp (0-65535) (0-65535)",
718e3744 1592 "Adjust routing timers\n"
1593 "BGP timers\n"
1594 "Keepalive interval\n"
1595 "Holdtime\n")
1596{
d62a17ae 1597 VTY_DECLVAR_CONTEXT(bgp, bgp);
1598 int idx_number = 2;
1599 int idx_number_2 = 3;
1600 unsigned long keepalive = 0;
1601 unsigned long holdtime = 0;
718e3744 1602
d62a17ae 1603 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1604 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1605
d62a17ae 1606 /* Holdtime value check. */
1607 if (holdtime < 3 && holdtime != 0) {
1608 vty_out(vty,
1609 "%% hold time value must be either 0 or greater than 3\n");
1610 return CMD_WARNING_CONFIG_FAILED;
1611 }
718e3744 1612
d62a17ae 1613 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1614
d62a17ae 1615 return CMD_SUCCESS;
718e3744 1616}
1617
1618DEFUN (no_bgp_timers,
1619 no_bgp_timers_cmd,
838758ac 1620 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1621 NO_STR
1622 "Adjust routing timers\n"
838758ac
DW
1623 "BGP timers\n"
1624 "Keepalive interval\n"
1625 "Holdtime\n")
718e3744 1626{
d62a17ae 1627 VTY_DECLVAR_CONTEXT(bgp, bgp);
1628 bgp_timers_unset(bgp);
718e3744 1629
d62a17ae 1630 return CMD_SUCCESS;
718e3744 1631}
1632
6b0655a2 1633
718e3744 1634DEFUN (bgp_client_to_client_reflection,
1635 bgp_client_to_client_reflection_cmd,
1636 "bgp client-to-client reflection",
1637 "BGP specific commands\n"
1638 "Configure client to client route reflection\n"
1639 "reflection of routes allowed\n")
1640{
d62a17ae 1641 VTY_DECLVAR_CONTEXT(bgp, bgp);
1642 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1643 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1644
d62a17ae 1645 return CMD_SUCCESS;
718e3744 1646}
1647
1648DEFUN (no_bgp_client_to_client_reflection,
1649 no_bgp_client_to_client_reflection_cmd,
1650 "no bgp client-to-client reflection",
1651 NO_STR
1652 "BGP specific commands\n"
1653 "Configure client to client route reflection\n"
1654 "reflection of routes allowed\n")
1655{
d62a17ae 1656 VTY_DECLVAR_CONTEXT(bgp, bgp);
1657 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1658 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1659
d62a17ae 1660 return CMD_SUCCESS;
718e3744 1661}
1662
1663/* "bgp always-compare-med" configuration. */
1664DEFUN (bgp_always_compare_med,
1665 bgp_always_compare_med_cmd,
1666 "bgp always-compare-med",
1667 "BGP specific commands\n"
1668 "Allow comparing MED from different neighbors\n")
1669{
d62a17ae 1670 VTY_DECLVAR_CONTEXT(bgp, bgp);
1671 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1672 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1673
d62a17ae 1674 return CMD_SUCCESS;
718e3744 1675}
1676
1677DEFUN (no_bgp_always_compare_med,
1678 no_bgp_always_compare_med_cmd,
1679 "no bgp always-compare-med",
1680 NO_STR
1681 "BGP specific commands\n"
1682 "Allow comparing MED from different neighbors\n")
1683{
d62a17ae 1684 VTY_DECLVAR_CONTEXT(bgp, bgp);
1685 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1686 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1687
d62a17ae 1688 return CMD_SUCCESS;
718e3744 1689}
6b0655a2 1690
718e3744 1691/* "bgp deterministic-med" configuration. */
1692DEFUN (bgp_deterministic_med,
1693 bgp_deterministic_med_cmd,
1694 "bgp deterministic-med",
1695 "BGP specific commands\n"
1696 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1697{
d62a17ae 1698 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1699
d62a17ae 1700 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1701 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1702 bgp_recalculate_all_bestpaths(bgp);
1703 }
7aafcaca 1704
d62a17ae 1705 return CMD_SUCCESS;
718e3744 1706}
1707
1708DEFUN (no_bgp_deterministic_med,
1709 no_bgp_deterministic_med_cmd,
1710 "no bgp deterministic-med",
1711 NO_STR
1712 "BGP specific commands\n"
1713 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1714{
d62a17ae 1715 VTY_DECLVAR_CONTEXT(bgp, bgp);
1716 int bestpath_per_as_used;
1717 afi_t afi;
1718 safi_t safi;
1719 struct peer *peer;
1720 struct listnode *node, *nnode;
1721
1722 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1723 bestpath_per_as_used = 0;
1724
1725 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1726 FOREACH_AFI_SAFI (afi, safi)
1727 if (CHECK_FLAG(
1728 peer->af_flags[afi][safi],
1729 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1730 bestpath_per_as_used = 1;
1731 break;
1732 }
d62a17ae 1733
1734 if (bestpath_per_as_used)
1735 break;
1736 }
1737
1738 if (bestpath_per_as_used) {
1739 vty_out(vty,
1740 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1741 return CMD_WARNING_CONFIG_FAILED;
1742 } else {
1743 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1744 bgp_recalculate_all_bestpaths(bgp);
1745 }
1746 }
1747
1748 return CMD_SUCCESS;
718e3744 1749}
538621f2 1750
1751/* "bgp graceful-restart" configuration. */
1752DEFUN (bgp_graceful_restart,
1753 bgp_graceful_restart_cmd,
1754 "bgp graceful-restart",
1755 "BGP specific commands\n"
1756 "Graceful restart capability parameters\n")
1757{
d62a17ae 1758 VTY_DECLVAR_CONTEXT(bgp, bgp);
1759 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1760 return CMD_SUCCESS;
538621f2 1761}
1762
1763DEFUN (no_bgp_graceful_restart,
1764 no_bgp_graceful_restart_cmd,
1765 "no bgp graceful-restart",
1766 NO_STR
1767 "BGP specific commands\n"
1768 "Graceful restart capability parameters\n")
1769{
d62a17ae 1770 VTY_DECLVAR_CONTEXT(bgp, bgp);
1771 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1772 return CMD_SUCCESS;
538621f2 1773}
1774
93406d87 1775DEFUN (bgp_graceful_restart_stalepath_time,
1776 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1777 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1778 "BGP specific commands\n"
1779 "Graceful restart capability parameters\n"
1780 "Set the max time to hold onto restarting peer's stale paths\n"
1781 "Delay value (seconds)\n")
1782{
d62a17ae 1783 VTY_DECLVAR_CONTEXT(bgp, bgp);
1784 int idx_number = 3;
1785 u_int32_t stalepath;
93406d87 1786
d62a17ae 1787 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1788 bgp->stalepath_time = stalepath;
1789 return CMD_SUCCESS;
93406d87 1790}
1791
eb6f1b41
PG
1792DEFUN (bgp_graceful_restart_restart_time,
1793 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1794 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1795 "BGP specific commands\n"
1796 "Graceful restart capability parameters\n"
1797 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1798 "Delay value (seconds)\n")
1799{
d62a17ae 1800 VTY_DECLVAR_CONTEXT(bgp, bgp);
1801 int idx_number = 3;
1802 u_int32_t restart;
eb6f1b41 1803
d62a17ae 1804 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1805 bgp->restart_time = restart;
1806 return CMD_SUCCESS;
eb6f1b41
PG
1807}
1808
93406d87 1809DEFUN (no_bgp_graceful_restart_stalepath_time,
1810 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1811 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1812 NO_STR
1813 "BGP specific commands\n"
1814 "Graceful restart capability parameters\n"
838758ac
DW
1815 "Set the max time to hold onto restarting peer's stale paths\n"
1816 "Delay value (seconds)\n")
93406d87 1817{
d62a17ae 1818 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1819
d62a17ae 1820 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1821 return CMD_SUCCESS;
93406d87 1822}
1823
eb6f1b41
PG
1824DEFUN (no_bgp_graceful_restart_restart_time,
1825 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1826 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1827 NO_STR
1828 "BGP specific commands\n"
1829 "Graceful restart capability parameters\n"
838758ac
DW
1830 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1831 "Delay value (seconds)\n")
eb6f1b41 1832{
d62a17ae 1833 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1834
d62a17ae 1835 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1836 return CMD_SUCCESS;
eb6f1b41
PG
1837}
1838
43fc21b3
JC
1839DEFUN (bgp_graceful_restart_preserve_fw,
1840 bgp_graceful_restart_preserve_fw_cmd,
1841 "bgp graceful-restart preserve-fw-state",
1842 "BGP specific commands\n"
1843 "Graceful restart capability parameters\n"
1844 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1845{
d62a17ae 1846 VTY_DECLVAR_CONTEXT(bgp, bgp);
1847 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1848 return CMD_SUCCESS;
43fc21b3
JC
1849}
1850
1851DEFUN (no_bgp_graceful_restart_preserve_fw,
1852 no_bgp_graceful_restart_preserve_fw_cmd,
1853 "no bgp graceful-restart preserve-fw-state",
1854 NO_STR
1855 "BGP specific commands\n"
1856 "Graceful restart capability parameters\n"
1857 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1858{
d62a17ae 1859 VTY_DECLVAR_CONTEXT(bgp, bgp);
1860 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1861 return CMD_SUCCESS;
43fc21b3
JC
1862}
1863
7f323236
DW
1864static void bgp_redistribute_redo(struct bgp *bgp)
1865{
1866 afi_t afi;
1867 int i;
1868 struct list *red_list;
1869 struct listnode *node;
1870 struct bgp_redist *red;
1871
a4d82a8a
PZ
1872 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1873 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1874
a4d82a8a
PZ
1875 red_list = bgp->redist[afi][i];
1876 if (!red_list)
1877 continue;
7f323236 1878
a4d82a8a 1879 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1880 bgp_redistribute_resend(bgp, afi, i,
1881 red->instance);
1882 }
1883 }
1884 }
1885}
1886
1887/* "bgp graceful-shutdown" configuration */
1888DEFUN (bgp_graceful_shutdown,
1889 bgp_graceful_shutdown_cmd,
1890 "bgp graceful-shutdown",
1891 BGP_STR
1892 "Graceful shutdown parameters\n")
1893{
1894 VTY_DECLVAR_CONTEXT(bgp, bgp);
1895
1896 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1897 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1898 bgp_static_redo_import_check(bgp);
1899 bgp_redistribute_redo(bgp);
1900 bgp_clear_star_soft_out(vty, bgp->name);
1901 bgp_clear_star_soft_in(vty, bgp->name);
1902 }
1903
1904 return CMD_SUCCESS;
1905}
1906
1907DEFUN (no_bgp_graceful_shutdown,
1908 no_bgp_graceful_shutdown_cmd,
1909 "no bgp graceful-shutdown",
1910 NO_STR
1911 BGP_STR
1912 "Graceful shutdown parameters\n")
1913{
1914 VTY_DECLVAR_CONTEXT(bgp, bgp);
1915
1916 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1917 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1918 bgp_static_redo_import_check(bgp);
1919 bgp_redistribute_redo(bgp);
1920 bgp_clear_star_soft_out(vty, bgp->name);
1921 bgp_clear_star_soft_in(vty, bgp->name);
1922 }
1923
1924 return CMD_SUCCESS;
1925}
1926
718e3744 1927/* "bgp fast-external-failover" configuration. */
1928DEFUN (bgp_fast_external_failover,
1929 bgp_fast_external_failover_cmd,
1930 "bgp fast-external-failover",
1931 BGP_STR
1932 "Immediately reset session if a link to a directly connected external peer goes down\n")
1933{
d62a17ae 1934 VTY_DECLVAR_CONTEXT(bgp, bgp);
1935 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1936 return CMD_SUCCESS;
718e3744 1937}
1938
1939DEFUN (no_bgp_fast_external_failover,
1940 no_bgp_fast_external_failover_cmd,
1941 "no bgp fast-external-failover",
1942 NO_STR
1943 BGP_STR
1944 "Immediately reset session if a link to a directly connected external peer goes down\n")
1945{
d62a17ae 1946 VTY_DECLVAR_CONTEXT(bgp, bgp);
1947 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1948 return CMD_SUCCESS;
718e3744 1949}
6b0655a2 1950
718e3744 1951/* "bgp enforce-first-as" configuration. */
1952DEFUN (bgp_enforce_first_as,
1953 bgp_enforce_first_as_cmd,
1954 "bgp enforce-first-as",
1955 BGP_STR
1956 "Enforce the first AS for EBGP routes\n")
1957{
d62a17ae 1958 VTY_DECLVAR_CONTEXT(bgp, bgp);
1959 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1960 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1961
d62a17ae 1962 return CMD_SUCCESS;
718e3744 1963}
1964
1965DEFUN (no_bgp_enforce_first_as,
1966 no_bgp_enforce_first_as_cmd,
1967 "no bgp enforce-first-as",
1968 NO_STR
1969 BGP_STR
1970 "Enforce the first AS for EBGP routes\n")
1971{
d62a17ae 1972 VTY_DECLVAR_CONTEXT(bgp, bgp);
1973 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1974 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1975
d62a17ae 1976 return CMD_SUCCESS;
718e3744 1977}
6b0655a2 1978
718e3744 1979/* "bgp bestpath compare-routerid" configuration. */
1980DEFUN (bgp_bestpath_compare_router_id,
1981 bgp_bestpath_compare_router_id_cmd,
1982 "bgp bestpath compare-routerid",
1983 "BGP specific commands\n"
1984 "Change the default bestpath selection\n"
1985 "Compare router-id for identical EBGP paths\n")
1986{
d62a17ae 1987 VTY_DECLVAR_CONTEXT(bgp, bgp);
1988 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1989 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1990
d62a17ae 1991 return CMD_SUCCESS;
718e3744 1992}
1993
1994DEFUN (no_bgp_bestpath_compare_router_id,
1995 no_bgp_bestpath_compare_router_id_cmd,
1996 "no bgp bestpath compare-routerid",
1997 NO_STR
1998 "BGP specific commands\n"
1999 "Change the default bestpath selection\n"
2000 "Compare router-id for identical EBGP paths\n")
2001{
d62a17ae 2002 VTY_DECLVAR_CONTEXT(bgp, bgp);
2003 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2004 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2005
d62a17ae 2006 return CMD_SUCCESS;
718e3744 2007}
6b0655a2 2008
718e3744 2009/* "bgp bestpath as-path ignore" configuration. */
2010DEFUN (bgp_bestpath_aspath_ignore,
2011 bgp_bestpath_aspath_ignore_cmd,
2012 "bgp bestpath as-path ignore",
2013 "BGP specific commands\n"
2014 "Change the default bestpath selection\n"
2015 "AS-path attribute\n"
2016 "Ignore as-path length in selecting a route\n")
2017{
d62a17ae 2018 VTY_DECLVAR_CONTEXT(bgp, bgp);
2019 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2020 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2021
d62a17ae 2022 return CMD_SUCCESS;
718e3744 2023}
2024
2025DEFUN (no_bgp_bestpath_aspath_ignore,
2026 no_bgp_bestpath_aspath_ignore_cmd,
2027 "no bgp bestpath as-path ignore",
2028 NO_STR
2029 "BGP specific commands\n"
2030 "Change the default bestpath selection\n"
2031 "AS-path attribute\n"
2032 "Ignore as-path length in selecting a route\n")
2033{
d62a17ae 2034 VTY_DECLVAR_CONTEXT(bgp, bgp);
2035 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2036 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2037
d62a17ae 2038 return CMD_SUCCESS;
718e3744 2039}
6b0655a2 2040
6811845b 2041/* "bgp bestpath as-path confed" configuration. */
2042DEFUN (bgp_bestpath_aspath_confed,
2043 bgp_bestpath_aspath_confed_cmd,
2044 "bgp bestpath as-path confed",
2045 "BGP specific commands\n"
2046 "Change the default bestpath selection\n"
2047 "AS-path attribute\n"
2048 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2049{
d62a17ae 2050 VTY_DECLVAR_CONTEXT(bgp, bgp);
2051 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2052 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2053
d62a17ae 2054 return CMD_SUCCESS;
6811845b 2055}
2056
2057DEFUN (no_bgp_bestpath_aspath_confed,
2058 no_bgp_bestpath_aspath_confed_cmd,
2059 "no bgp bestpath as-path confed",
2060 NO_STR
2061 "BGP specific commands\n"
2062 "Change the default bestpath selection\n"
2063 "AS-path attribute\n"
2064 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2065{
d62a17ae 2066 VTY_DECLVAR_CONTEXT(bgp, bgp);
2067 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2068 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2069
d62a17ae 2070 return CMD_SUCCESS;
6811845b 2071}
6b0655a2 2072
2fdd455c
PM
2073/* "bgp bestpath as-path multipath-relax" configuration. */
2074DEFUN (bgp_bestpath_aspath_multipath_relax,
2075 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2076 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2077 "BGP specific commands\n"
2078 "Change the default bestpath selection\n"
2079 "AS-path attribute\n"
2080 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2081 "Generate an AS_SET\n"
16fc1eec
DS
2082 "Do not generate an AS_SET\n")
2083{
d62a17ae 2084 VTY_DECLVAR_CONTEXT(bgp, bgp);
2085 int idx = 0;
2086 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2087
d62a17ae 2088 /* no-as-set is now the default behavior so we can silently
2089 * ignore it */
2090 if (argv_find(argv, argc, "as-set", &idx))
2091 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2092 else
2093 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2094
d62a17ae 2095 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2096
d62a17ae 2097 return CMD_SUCCESS;
16fc1eec
DS
2098}
2099
219178b6
DW
2100DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2101 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2102 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2103 NO_STR
2104 "BGP specific commands\n"
2105 "Change the default bestpath selection\n"
2106 "AS-path attribute\n"
2107 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2108 "Generate an AS_SET\n"
16fc1eec
DS
2109 "Do not generate an AS_SET\n")
2110{
d62a17ae 2111 VTY_DECLVAR_CONTEXT(bgp, bgp);
2112 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2113 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2114 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2115
d62a17ae 2116 return CMD_SUCCESS;
2fdd455c 2117}
6b0655a2 2118
848973c7 2119/* "bgp log-neighbor-changes" configuration. */
2120DEFUN (bgp_log_neighbor_changes,
2121 bgp_log_neighbor_changes_cmd,
2122 "bgp log-neighbor-changes",
2123 "BGP specific commands\n"
2124 "Log neighbor up/down and reset reason\n")
2125{
d62a17ae 2126 VTY_DECLVAR_CONTEXT(bgp, bgp);
2127 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2128 return CMD_SUCCESS;
848973c7 2129}
2130
2131DEFUN (no_bgp_log_neighbor_changes,
2132 no_bgp_log_neighbor_changes_cmd,
2133 "no bgp log-neighbor-changes",
2134 NO_STR
2135 "BGP specific commands\n"
2136 "Log neighbor up/down and reset reason\n")
2137{
d62a17ae 2138 VTY_DECLVAR_CONTEXT(bgp, bgp);
2139 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2140 return CMD_SUCCESS;
848973c7 2141}
6b0655a2 2142
718e3744 2143/* "bgp bestpath med" configuration. */
2144DEFUN (bgp_bestpath_med,
2145 bgp_bestpath_med_cmd,
2d8c1a4d 2146 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2147 "BGP specific commands\n"
2148 "Change the default bestpath selection\n"
2149 "MED attribute\n"
2150 "Compare MED among confederation paths\n"
838758ac
DW
2151 "Treat missing MED as the least preferred one\n"
2152 "Treat missing MED as the least preferred one\n"
2153 "Compare MED among confederation paths\n")
718e3744 2154{
d62a17ae 2155 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2156
d62a17ae 2157 int idx = 0;
2158 if (argv_find(argv, argc, "confed", &idx))
2159 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2160 idx = 0;
2161 if (argv_find(argv, argc, "missing-as-worst", &idx))
2162 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2163
d62a17ae 2164 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2165
d62a17ae 2166 return CMD_SUCCESS;
718e3744 2167}
2168
718e3744 2169DEFUN (no_bgp_bestpath_med,
2170 no_bgp_bestpath_med_cmd,
2d8c1a4d 2171 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2172 NO_STR
2173 "BGP specific commands\n"
2174 "Change the default bestpath selection\n"
2175 "MED attribute\n"
2176 "Compare MED among confederation paths\n"
3a2d747c
QY
2177 "Treat missing MED as the least preferred one\n"
2178 "Treat missing MED as the least preferred one\n"
2179 "Compare MED among confederation paths\n")
718e3744 2180{
d62a17ae 2181 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2182
d62a17ae 2183 int idx = 0;
2184 if (argv_find(argv, argc, "confed", &idx))
2185 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2186 idx = 0;
2187 if (argv_find(argv, argc, "missing-as-worst", &idx))
2188 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2189
d62a17ae 2190 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2191
d62a17ae 2192 return CMD_SUCCESS;
718e3744 2193}
2194
718e3744 2195/* "no bgp default ipv4-unicast". */
2196DEFUN (no_bgp_default_ipv4_unicast,
2197 no_bgp_default_ipv4_unicast_cmd,
2198 "no bgp default ipv4-unicast",
2199 NO_STR
2200 "BGP specific commands\n"
2201 "Configure BGP defaults\n"
2202 "Activate ipv4-unicast for a peer by default\n")
2203{
d62a17ae 2204 VTY_DECLVAR_CONTEXT(bgp, bgp);
2205 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2206 return CMD_SUCCESS;
718e3744 2207}
2208
2209DEFUN (bgp_default_ipv4_unicast,
2210 bgp_default_ipv4_unicast_cmd,
2211 "bgp default ipv4-unicast",
2212 "BGP specific commands\n"
2213 "Configure BGP defaults\n"
2214 "Activate ipv4-unicast for a peer by default\n")
2215{
d62a17ae 2216 VTY_DECLVAR_CONTEXT(bgp, bgp);
2217 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2218 return CMD_SUCCESS;
718e3744 2219}
6b0655a2 2220
04b6bdc0
DW
2221/* Display hostname in certain command outputs */
2222DEFUN (bgp_default_show_hostname,
2223 bgp_default_show_hostname_cmd,
2224 "bgp default show-hostname",
2225 "BGP specific commands\n"
2226 "Configure BGP defaults\n"
2227 "Show hostname in certain command ouputs\n")
2228{
d62a17ae 2229 VTY_DECLVAR_CONTEXT(bgp, bgp);
2230 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2231 return CMD_SUCCESS;
04b6bdc0
DW
2232}
2233
2234DEFUN (no_bgp_default_show_hostname,
2235 no_bgp_default_show_hostname_cmd,
2236 "no bgp default show-hostname",
2237 NO_STR
2238 "BGP specific commands\n"
2239 "Configure BGP defaults\n"
2240 "Show hostname in certain command ouputs\n")
2241{
d62a17ae 2242 VTY_DECLVAR_CONTEXT(bgp, bgp);
2243 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2244 return CMD_SUCCESS;
04b6bdc0
DW
2245}
2246
8233ef81 2247/* "bgp network import-check" configuration. */
718e3744 2248DEFUN (bgp_network_import_check,
2249 bgp_network_import_check_cmd,
5623e905 2250 "bgp network import-check",
718e3744 2251 "BGP specific commands\n"
2252 "BGP network command\n"
5623e905 2253 "Check BGP network route exists in IGP\n")
718e3744 2254{
d62a17ae 2255 VTY_DECLVAR_CONTEXT(bgp, bgp);
2256 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2257 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2258 bgp_static_redo_import_check(bgp);
2259 }
078430f6 2260
d62a17ae 2261 return CMD_SUCCESS;
718e3744 2262}
2263
d62a17ae 2264ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2265 "bgp network import-check exact",
2266 "BGP specific commands\n"
2267 "BGP network command\n"
2268 "Check BGP network route exists in IGP\n"
2269 "Match route precisely\n")
8233ef81 2270
718e3744 2271DEFUN (no_bgp_network_import_check,
2272 no_bgp_network_import_check_cmd,
5623e905 2273 "no bgp network import-check",
718e3744 2274 NO_STR
2275 "BGP specific commands\n"
2276 "BGP network command\n"
2277 "Check BGP network route exists in IGP\n")
2278{
d62a17ae 2279 VTY_DECLVAR_CONTEXT(bgp, bgp);
2280 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2281 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2282 bgp_static_redo_import_check(bgp);
2283 }
5623e905 2284
d62a17ae 2285 return CMD_SUCCESS;
718e3744 2286}
6b0655a2 2287
718e3744 2288DEFUN (bgp_default_local_preference,
2289 bgp_default_local_preference_cmd,
6147e2c6 2290 "bgp default local-preference (0-4294967295)",
718e3744 2291 "BGP specific commands\n"
2292 "Configure BGP defaults\n"
2293 "local preference (higher=more preferred)\n"
2294 "Configure default local preference value\n")
2295{
d62a17ae 2296 VTY_DECLVAR_CONTEXT(bgp, bgp);
2297 int idx_number = 3;
2298 u_int32_t local_pref;
718e3744 2299
d62a17ae 2300 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2301
d62a17ae 2302 bgp_default_local_preference_set(bgp, local_pref);
2303 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2304
d62a17ae 2305 return CMD_SUCCESS;
718e3744 2306}
2307
2308DEFUN (no_bgp_default_local_preference,
2309 no_bgp_default_local_preference_cmd,
838758ac 2310 "no bgp default local-preference [(0-4294967295)]",
718e3744 2311 NO_STR
2312 "BGP specific commands\n"
2313 "Configure BGP defaults\n"
838758ac
DW
2314 "local preference (higher=more preferred)\n"
2315 "Configure default local preference value\n")
718e3744 2316{
d62a17ae 2317 VTY_DECLVAR_CONTEXT(bgp, bgp);
2318 bgp_default_local_preference_unset(bgp);
2319 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2320
d62a17ae 2321 return CMD_SUCCESS;
718e3744 2322}
2323
6b0655a2 2324
3f9c7369
DS
2325DEFUN (bgp_default_subgroup_pkt_queue_max,
2326 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2327 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2328 "BGP specific commands\n"
2329 "Configure BGP defaults\n"
2330 "subgroup-pkt-queue-max\n"
2331 "Configure subgroup packet queue max\n")
8bd9d948 2332{
d62a17ae 2333 VTY_DECLVAR_CONTEXT(bgp, bgp);
2334 int idx_number = 3;
2335 u_int32_t max_size;
8bd9d948 2336
d62a17ae 2337 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2338
d62a17ae 2339 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2340
d62a17ae 2341 return CMD_SUCCESS;
3f9c7369
DS
2342}
2343
2344DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2345 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2346 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2347 NO_STR
2348 "BGP specific commands\n"
2349 "Configure BGP defaults\n"
838758ac
DW
2350 "subgroup-pkt-queue-max\n"
2351 "Configure subgroup packet queue max\n")
3f9c7369 2352{
d62a17ae 2353 VTY_DECLVAR_CONTEXT(bgp, bgp);
2354 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2355 return CMD_SUCCESS;
8bd9d948
DS
2356}
2357
813d4307 2358
8bd9d948
DS
2359DEFUN (bgp_rr_allow_outbound_policy,
2360 bgp_rr_allow_outbound_policy_cmd,
2361 "bgp route-reflector allow-outbound-policy",
2362 "BGP specific commands\n"
2363 "Allow modifications made by out route-map\n"
2364 "on ibgp neighbors\n")
2365{
d62a17ae 2366 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2367
d62a17ae 2368 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2369 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2370 update_group_announce_rrclients(bgp);
2371 bgp_clear_star_soft_out(vty, bgp->name);
2372 }
8bd9d948 2373
d62a17ae 2374 return CMD_SUCCESS;
8bd9d948
DS
2375}
2376
2377DEFUN (no_bgp_rr_allow_outbound_policy,
2378 no_bgp_rr_allow_outbound_policy_cmd,
2379 "no bgp route-reflector allow-outbound-policy",
2380 NO_STR
2381 "BGP specific commands\n"
2382 "Allow modifications made by out route-map\n"
2383 "on ibgp neighbors\n")
2384{
d62a17ae 2385 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2386
d62a17ae 2387 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2388 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2389 update_group_announce_rrclients(bgp);
2390 bgp_clear_star_soft_out(vty, bgp->name);
2391 }
8bd9d948 2392
d62a17ae 2393 return CMD_SUCCESS;
8bd9d948
DS
2394}
2395
f14e6fdb
DS
2396DEFUN (bgp_listen_limit,
2397 bgp_listen_limit_cmd,
9ccf14f7 2398 "bgp listen limit (1-5000)",
f14e6fdb
DS
2399 "BGP specific commands\n"
2400 "Configure BGP defaults\n"
2401 "maximum number of BGP Dynamic Neighbors that can be created\n"
2402 "Configure Dynamic Neighbors listen limit value\n")
2403{
d62a17ae 2404 VTY_DECLVAR_CONTEXT(bgp, bgp);
2405 int idx_number = 3;
2406 int listen_limit;
f14e6fdb 2407
d62a17ae 2408 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2409
d62a17ae 2410 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2411
d62a17ae 2412 return CMD_SUCCESS;
f14e6fdb
DS
2413}
2414
2415DEFUN (no_bgp_listen_limit,
2416 no_bgp_listen_limit_cmd,
838758ac 2417 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2418 "BGP specific commands\n"
2419 "Configure BGP defaults\n"
2420 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2421 "Configure Dynamic Neighbors listen limit value to default\n"
2422 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2423{
d62a17ae 2424 VTY_DECLVAR_CONTEXT(bgp, bgp);
2425 bgp_listen_limit_unset(bgp);
2426 return CMD_SUCCESS;
f14e6fdb
DS
2427}
2428
2429
20eb8864 2430/*
2431 * Check if this listen range is already configured. Check for exact
2432 * match or overlap based on input.
2433 */
d62a17ae 2434static struct peer_group *listen_range_exists(struct bgp *bgp,
2435 struct prefix *range, int exact)
2436{
2437 struct listnode *node, *nnode;
2438 struct listnode *node1, *nnode1;
2439 struct peer_group *group;
2440 struct prefix *lr;
2441 afi_t afi;
2442 int match;
2443
2444 afi = family2afi(range->family);
2445 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2446 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2447 lr)) {
2448 if (exact)
2449 match = prefix_same(range, lr);
2450 else
2451 match = (prefix_match(range, lr)
2452 || prefix_match(lr, range));
2453 if (match)
2454 return group;
2455 }
2456 }
2457
2458 return NULL;
20eb8864 2459}
2460
f14e6fdb
DS
2461DEFUN (bgp_listen_range,
2462 bgp_listen_range_cmd,
9ccf14f7 2463 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2464 "BGP specific commands\n"
d7fa34c1
QY
2465 "Configure BGP dynamic neighbors listen range\n"
2466 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2467 NEIGHBOR_ADDR_STR
2468 "Member of the peer-group\n"
2469 "Peer-group name\n")
f14e6fdb 2470{
d62a17ae 2471 VTY_DECLVAR_CONTEXT(bgp, bgp);
2472 struct prefix range;
2473 struct peer_group *group, *existing_group;
2474 afi_t afi;
2475 int ret;
2476 int idx = 0;
2477
2478 argv_find(argv, argc, "A.B.C.D/M", &idx);
2479 argv_find(argv, argc, "X:X::X:X/M", &idx);
2480 char *prefix = argv[idx]->arg;
2481 argv_find(argv, argc, "WORD", &idx);
2482 char *peergroup = argv[idx]->arg;
2483
2484 /* Convert IP prefix string to struct prefix. */
2485 ret = str2prefix(prefix, &range);
2486 if (!ret) {
2487 vty_out(vty, "%% Malformed listen range\n");
2488 return CMD_WARNING_CONFIG_FAILED;
2489 }
2490
2491 afi = family2afi(range.family);
2492
2493 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2494 vty_out(vty,
2495 "%% Malformed listen range (link-local address)\n");
2496 return CMD_WARNING_CONFIG_FAILED;
2497 }
2498
2499 apply_mask(&range);
2500
2501 /* Check if same listen range is already configured. */
2502 existing_group = listen_range_exists(bgp, &range, 1);
2503 if (existing_group) {
2504 if (strcmp(existing_group->name, peergroup) == 0)
2505 return CMD_SUCCESS;
2506 else {
2507 vty_out(vty,
2508 "%% Same listen range is attached to peer-group %s\n",
2509 existing_group->name);
2510 return CMD_WARNING_CONFIG_FAILED;
2511 }
2512 }
2513
2514 /* Check if an overlapping listen range exists. */
2515 if (listen_range_exists(bgp, &range, 0)) {
2516 vty_out(vty,
2517 "%% Listen range overlaps with existing listen range\n");
2518 return CMD_WARNING_CONFIG_FAILED;
2519 }
2520
2521 group = peer_group_lookup(bgp, peergroup);
2522 if (!group) {
2523 vty_out(vty, "%% Configure the peer-group first\n");
2524 return CMD_WARNING_CONFIG_FAILED;
2525 }
2526
2527 ret = peer_group_listen_range_add(group, &range);
2528 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2529}
2530
2531DEFUN (no_bgp_listen_range,
2532 no_bgp_listen_range_cmd,
d7fa34c1
QY
2533 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2534 NO_STR
f14e6fdb 2535 "BGP specific commands\n"
d7fa34c1
QY
2536 "Unconfigure BGP dynamic neighbors listen range\n"
2537 "Unconfigure BGP dynamic neighbors listen range\n"
2538 NEIGHBOR_ADDR_STR
2539 "Member of the peer-group\n"
2540 "Peer-group name\n")
f14e6fdb 2541{
d62a17ae 2542 VTY_DECLVAR_CONTEXT(bgp, bgp);
2543 struct prefix range;
2544 struct peer_group *group;
2545 afi_t afi;
2546 int ret;
2547 int idx = 0;
2548
2549 argv_find(argv, argc, "A.B.C.D/M", &idx);
2550 argv_find(argv, argc, "X:X::X:X/M", &idx);
2551 char *prefix = argv[idx]->arg;
2552 argv_find(argv, argc, "WORD", &idx);
2553 char *peergroup = argv[idx]->arg;
2554
2555 /* Convert IP prefix string to struct prefix. */
2556 ret = str2prefix(prefix, &range);
2557 if (!ret) {
2558 vty_out(vty, "%% Malformed listen range\n");
2559 return CMD_WARNING_CONFIG_FAILED;
2560 }
2561
2562 afi = family2afi(range.family);
2563
2564 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2565 vty_out(vty,
2566 "%% Malformed listen range (link-local address)\n");
2567 return CMD_WARNING_CONFIG_FAILED;
2568 }
2569
2570 apply_mask(&range);
2571
2572 group = peer_group_lookup(bgp, peergroup);
2573 if (!group) {
2574 vty_out(vty, "%% Peer-group does not exist\n");
2575 return CMD_WARNING_CONFIG_FAILED;
2576 }
2577
2578 ret = peer_group_listen_range_del(group, &range);
2579 return bgp_vty_return(vty, ret);
2580}
2581
2b791107 2582void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2583{
2584 struct peer_group *group;
2585 struct listnode *node, *nnode, *rnode, *nrnode;
2586 struct prefix *range;
2587 afi_t afi;
2588 char buf[PREFIX2STR_BUFFER];
2589
2590 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2591 vty_out(vty, " bgp listen limit %d\n",
2592 bgp->dynamic_neighbors_limit);
2593
2594 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2595 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2596 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2597 nrnode, range)) {
2598 prefix2str(range, buf, sizeof(buf));
2599 vty_out(vty,
2600 " bgp listen range %s peer-group %s\n",
2601 buf, group->name);
2602 }
2603 }
2604 }
f14e6fdb
DS
2605}
2606
2607
907f92c8
DS
2608DEFUN (bgp_disable_connected_route_check,
2609 bgp_disable_connected_route_check_cmd,
2610 "bgp disable-ebgp-connected-route-check",
2611 "BGP specific commands\n"
2612 "Disable checking if nexthop is connected on ebgp sessions\n")
2613{
d62a17ae 2614 VTY_DECLVAR_CONTEXT(bgp, bgp);
2615 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2616 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2617
d62a17ae 2618 return CMD_SUCCESS;
907f92c8
DS
2619}
2620
2621DEFUN (no_bgp_disable_connected_route_check,
2622 no_bgp_disable_connected_route_check_cmd,
2623 "no bgp disable-ebgp-connected-route-check",
2624 NO_STR
2625 "BGP specific commands\n"
2626 "Disable checking if nexthop is connected on ebgp sessions\n")
2627{
d62a17ae 2628 VTY_DECLVAR_CONTEXT(bgp, bgp);
2629 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2630 bgp_clear_star_soft_in(vty, bgp->name);
2631
2632 return CMD_SUCCESS;
2633}
2634
2635
2636static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2637 const char *as_str, afi_t afi, safi_t safi)
2638{
2639 VTY_DECLVAR_CONTEXT(bgp, bgp);
2640 int ret;
2641 as_t as;
2642 int as_type = AS_SPECIFIED;
2643 union sockunion su;
2644
2645 if (as_str[0] == 'i') {
2646 as = 0;
2647 as_type = AS_INTERNAL;
2648 } else if (as_str[0] == 'e') {
2649 as = 0;
2650 as_type = AS_EXTERNAL;
2651 } else {
2652 /* Get AS number. */
2653 as = strtoul(as_str, NULL, 10);
2654 }
2655
2656 /* If peer is peer group, call proper function. */
2657 ret = str2sockunion(peer_str, &su);
2658 if (ret < 0) {
2659 /* Check for peer by interface */
2660 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2661 safi);
2662 if (ret < 0) {
2663 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2664 if (ret < 0) {
2665 vty_out(vty,
2666 "%% Create the peer-group or interface first\n");
2667 return CMD_WARNING_CONFIG_FAILED;
2668 }
2669 return CMD_SUCCESS;
2670 }
2671 } else {
2672 if (peer_address_self_check(bgp, &su)) {
2673 vty_out(vty,
2674 "%% Can not configure the local system as neighbor\n");
2675 return CMD_WARNING_CONFIG_FAILED;
2676 }
2677 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2678 }
2679
2680 /* This peer belongs to peer group. */
2681 switch (ret) {
2682 case BGP_ERR_PEER_GROUP_MEMBER:
2683 vty_out(vty,
2684 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2685 as);
2686 return CMD_WARNING_CONFIG_FAILED;
2687 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2688 vty_out(vty,
2689 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2690 as, as_str);
2691 return CMD_WARNING_CONFIG_FAILED;
2692 }
2693 return bgp_vty_return(vty, ret);
718e3744 2694}
2695
f26845f9
QY
2696DEFUN (bgp_default_shutdown,
2697 bgp_default_shutdown_cmd,
2698 "[no] bgp default shutdown",
2699 NO_STR
2700 BGP_STR
2701 "Configure BGP defaults\n"
b012cbe2 2702 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2703{
2704 VTY_DECLVAR_CONTEXT(bgp, bgp);
2705 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2706 return CMD_SUCCESS;
2707}
2708
718e3744 2709DEFUN (neighbor_remote_as,
2710 neighbor_remote_as_cmd,
3a2d747c 2711 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2712 NEIGHBOR_STR
2713 NEIGHBOR_ADDR_STR2
2714 "Specify a BGP neighbor\n"
d7fa34c1 2715 AS_STR
3a2d747c
QY
2716 "Internal BGP peer\n"
2717 "External BGP peer\n")
718e3744 2718{
d62a17ae 2719 int idx_peer = 1;
2720 int idx_remote_as = 3;
2721 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2722 argv[idx_remote_as]->arg, AFI_IP,
2723 SAFI_UNICAST);
2724}
2725
2726static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2727 afi_t afi, safi_t safi, int v6only,
2728 const char *peer_group_name,
2729 const char *as_str)
2730{
2731 VTY_DECLVAR_CONTEXT(bgp, bgp);
2732 as_t as = 0;
2733 int as_type = AS_UNSPECIFIED;
2734 struct peer *peer;
2735 struct peer_group *group;
2736 int ret = 0;
2737 union sockunion su;
2738
2739 group = peer_group_lookup(bgp, conf_if);
2740
2741 if (group) {
2742 vty_out(vty, "%% Name conflict with peer-group \n");
2743 return CMD_WARNING_CONFIG_FAILED;
2744 }
2745
2746 if (as_str) {
2747 if (as_str[0] == 'i') {
2748 as_type = AS_INTERNAL;
2749 } else if (as_str[0] == 'e') {
2750 as_type = AS_EXTERNAL;
2751 } else {
2752 /* Get AS number. */
2753 as = strtoul(as_str, NULL, 10);
2754 as_type = AS_SPECIFIED;
2755 }
2756 }
2757
2758 peer = peer_lookup_by_conf_if(bgp, conf_if);
2759 if (peer) {
2760 if (as_str)
2761 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2762 afi, safi);
2763 } else {
2764 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2765 && afi == AFI_IP && safi == SAFI_UNICAST)
2766 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2767 as_type, 0, 0, NULL);
2768 else
2769 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2770 as_type, afi, safi, NULL);
2771
2772 if (!peer) {
2773 vty_out(vty, "%% BGP failed to create peer\n");
2774 return CMD_WARNING_CONFIG_FAILED;
2775 }
2776
2777 if (v6only)
2778 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2779
2780 /* Request zebra to initiate IPv6 RAs on this interface. We do
2781 * this
2782 * any unnumbered peer in order to not worry about run-time
2783 * transitions
2784 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2785 * address
2786 * gets deleted later etc.)
2787 */
2788 if (peer->ifp)
2789 bgp_zebra_initiate_radv(bgp, peer);
2790 }
2791
2792 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2793 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2794 if (v6only)
2795 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2796 else
2797 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2798
2799 /* v6only flag changed. Reset bgp seesion */
2800 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2801 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2802 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2803 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2804 } else
2805 bgp_session_reset(peer);
2806 }
2807
2808 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2809 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2810
2811 if (peer_group_name) {
2812 group = peer_group_lookup(bgp, peer_group_name);
2813 if (!group) {
2814 vty_out(vty, "%% Configure the peer-group first\n");
2815 return CMD_WARNING_CONFIG_FAILED;
2816 }
2817
2818 ret = peer_group_bind(bgp, &su, peer, group, &as);
2819 }
2820
2821 return bgp_vty_return(vty, ret);
a80beece
DS
2822}
2823
4c48cf63
DW
2824DEFUN (neighbor_interface_config,
2825 neighbor_interface_config_cmd,
31500417 2826 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2827 NEIGHBOR_STR
2828 "Interface name or neighbor tag\n"
31500417
DW
2829 "Enable BGP on interface\n"
2830 "Member of the peer-group\n"
16cedbb0 2831 "Peer-group name\n")
4c48cf63 2832{
d62a17ae 2833 int idx_word = 1;
2834 int idx_peer_group_word = 4;
31500417 2835
d62a17ae 2836 if (argc > idx_peer_group_word)
2837 return peer_conf_interface_get(
2838 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2839 argv[idx_peer_group_word]->arg, NULL);
2840 else
2841 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2842 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2843}
2844
4c48cf63
DW
2845DEFUN (neighbor_interface_config_v6only,
2846 neighbor_interface_config_v6only_cmd,
31500417 2847 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2848 NEIGHBOR_STR
2849 "Interface name or neighbor tag\n"
2850 "Enable BGP on interface\n"
31500417
DW
2851 "Enable BGP with v6 link-local only\n"
2852 "Member of the peer-group\n"
16cedbb0 2853 "Peer-group name\n")
4c48cf63 2854{
d62a17ae 2855 int idx_word = 1;
2856 int idx_peer_group_word = 5;
31500417 2857
d62a17ae 2858 if (argc > idx_peer_group_word)
2859 return peer_conf_interface_get(
2860 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2861 argv[idx_peer_group_word]->arg, NULL);
31500417 2862
d62a17ae 2863 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2864 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2865}
2866
a80beece 2867
b3a39dc5
DD
2868DEFUN (neighbor_interface_config_remote_as,
2869 neighbor_interface_config_remote_as_cmd,
3a2d747c 2870 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2871 NEIGHBOR_STR
2872 "Interface name or neighbor tag\n"
2873 "Enable BGP on interface\n"
3a2d747c 2874 "Specify a BGP neighbor\n"
d7fa34c1 2875 AS_STR
3a2d747c
QY
2876 "Internal BGP peer\n"
2877 "External BGP peer\n")
b3a39dc5 2878{
d62a17ae 2879 int idx_word = 1;
2880 int idx_remote_as = 4;
2881 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2882 SAFI_UNICAST, 0, NULL,
2883 argv[idx_remote_as]->arg);
b3a39dc5
DD
2884}
2885
2886DEFUN (neighbor_interface_v6only_config_remote_as,
2887 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2888 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2889 NEIGHBOR_STR
2890 "Interface name or neighbor tag\n"
3a2d747c 2891 "Enable BGP with v6 link-local only\n"
b3a39dc5 2892 "Enable BGP on interface\n"
3a2d747c 2893 "Specify a BGP neighbor\n"
d7fa34c1 2894 AS_STR
3a2d747c
QY
2895 "Internal BGP peer\n"
2896 "External BGP peer\n")
b3a39dc5 2897{
d62a17ae 2898 int idx_word = 1;
2899 int idx_remote_as = 5;
2900 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2901 SAFI_UNICAST, 1, NULL,
2902 argv[idx_remote_as]->arg);
b3a39dc5
DD
2903}
2904
718e3744 2905DEFUN (neighbor_peer_group,
2906 neighbor_peer_group_cmd,
2907 "neighbor WORD peer-group",
2908 NEIGHBOR_STR
a80beece 2909 "Interface name or neighbor tag\n"
718e3744 2910 "Configure peer-group\n")
2911{
d62a17ae 2912 VTY_DECLVAR_CONTEXT(bgp, bgp);
2913 int idx_word = 1;
2914 struct peer *peer;
2915 struct peer_group *group;
718e3744 2916
d62a17ae 2917 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2918 if (peer) {
2919 vty_out(vty, "%% Name conflict with interface: \n");
2920 return CMD_WARNING_CONFIG_FAILED;
2921 }
718e3744 2922
d62a17ae 2923 group = peer_group_get(bgp, argv[idx_word]->arg);
2924 if (!group) {
2925 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2926 return CMD_WARNING_CONFIG_FAILED;
2927 }
718e3744 2928
d62a17ae 2929 return CMD_SUCCESS;
718e3744 2930}
2931
2932DEFUN (no_neighbor,
2933 no_neighbor_cmd,
dab8cd00 2934 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2935 NO_STR
2936 NEIGHBOR_STR
3a2d747c
QY
2937 NEIGHBOR_ADDR_STR2
2938 "Specify a BGP neighbor\n"
2939 AS_STR
2940 "Internal BGP peer\n"
2941 "External BGP peer\n")
718e3744 2942{
d62a17ae 2943 VTY_DECLVAR_CONTEXT(bgp, bgp);
2944 int idx_peer = 2;
2945 int ret;
2946 union sockunion su;
2947 struct peer_group *group;
2948 struct peer *peer;
2949 struct peer *other;
2950
2951 ret = str2sockunion(argv[idx_peer]->arg, &su);
2952 if (ret < 0) {
2953 /* look up for neighbor by interface name config. */
2954 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2955 if (peer) {
2956 /* Request zebra to terminate IPv6 RAs on this
2957 * interface. */
2958 if (peer->ifp)
2959 bgp_zebra_terminate_radv(peer->bgp, peer);
2960 peer_delete(peer);
2961 return CMD_SUCCESS;
2962 }
f14e6fdb 2963
d62a17ae 2964 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2965 if (group)
2966 peer_group_delete(group);
2967 else {
2968 vty_out(vty, "%% Create the peer-group first\n");
2969 return CMD_WARNING_CONFIG_FAILED;
2970 }
2971 } else {
2972 peer = peer_lookup(bgp, &su);
2973 if (peer) {
2974 if (peer_dynamic_neighbor(peer)) {
2975 vty_out(vty,
2976 "%% Operation not allowed on a dynamic neighbor\n");
2977 return CMD_WARNING_CONFIG_FAILED;
2978 }
2979
2980 other = peer->doppelganger;
2981 peer_delete(peer);
2982 if (other && other->status != Deleted)
2983 peer_delete(other);
2984 }
1ff9a340 2985 }
718e3744 2986
d62a17ae 2987 return CMD_SUCCESS;
718e3744 2988}
2989
a80beece
DS
2990DEFUN (no_neighbor_interface_config,
2991 no_neighbor_interface_config_cmd,
31500417 2992 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
2993 NO_STR
2994 NEIGHBOR_STR
2995 "Interface name\n"
31500417
DW
2996 "Configure BGP on interface\n"
2997 "Enable BGP with v6 link-local only\n"
2998 "Member of the peer-group\n"
16cedbb0 2999 "Peer-group name\n"
3a2d747c
QY
3000 "Specify a BGP neighbor\n"
3001 AS_STR
3002 "Internal BGP peer\n"
3003 "External BGP peer\n")
a80beece 3004{
d62a17ae 3005 VTY_DECLVAR_CONTEXT(bgp, bgp);
3006 int idx_word = 2;
3007 struct peer *peer;
3008
3009 /* look up for neighbor by interface name config. */
3010 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3011 if (peer) {
3012 /* Request zebra to terminate IPv6 RAs on this interface. */
3013 if (peer->ifp)
3014 bgp_zebra_terminate_radv(peer->bgp, peer);
3015 peer_delete(peer);
3016 } else {
3017 vty_out(vty, "%% Create the bgp interface first\n");
3018 return CMD_WARNING_CONFIG_FAILED;
3019 }
3020 return CMD_SUCCESS;
a80beece
DS
3021}
3022
718e3744 3023DEFUN (no_neighbor_peer_group,
3024 no_neighbor_peer_group_cmd,
3025 "no neighbor WORD peer-group",
3026 NO_STR
3027 NEIGHBOR_STR
3028 "Neighbor tag\n"
3029 "Configure peer-group\n")
3030{
d62a17ae 3031 VTY_DECLVAR_CONTEXT(bgp, bgp);
3032 int idx_word = 2;
3033 struct peer_group *group;
718e3744 3034
d62a17ae 3035 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3036 if (group)
3037 peer_group_delete(group);
3038 else {
3039 vty_out(vty, "%% Create the peer-group first\n");
3040 return CMD_WARNING_CONFIG_FAILED;
3041 }
3042 return CMD_SUCCESS;
718e3744 3043}
3044
a80beece
DS
3045DEFUN (no_neighbor_interface_peer_group_remote_as,
3046 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3047 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3048 NO_STR
3049 NEIGHBOR_STR
a80beece 3050 "Interface name or neighbor tag\n"
718e3744 3051 "Specify a BGP neighbor\n"
3a2d747c
QY
3052 AS_STR
3053 "Internal BGP peer\n"
3054 "External BGP peer\n")
718e3744 3055{
d62a17ae 3056 VTY_DECLVAR_CONTEXT(bgp, bgp);
3057 int idx_word = 2;
3058 struct peer_group *group;
3059 struct peer *peer;
3060
3061 /* look up for neighbor by interface name config. */
3062 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3063 if (peer) {
3064 peer_as_change(peer, 0, AS_SPECIFIED);
3065 return CMD_SUCCESS;
3066 }
3067
3068 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3069 if (group)
3070 peer_group_remote_as_delete(group);
3071 else {
3072 vty_out(vty, "%% Create the peer-group or interface first\n");
3073 return CMD_WARNING_CONFIG_FAILED;
3074 }
3075 return CMD_SUCCESS;
718e3744 3076}
6b0655a2 3077
718e3744 3078DEFUN (neighbor_local_as,
3079 neighbor_local_as_cmd,
9ccf14f7 3080 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3081 NEIGHBOR_STR
3082 NEIGHBOR_ADDR_STR2
3083 "Specify a local-as number\n"
3084 "AS number used as local AS\n")
3085{
d62a17ae 3086 int idx_peer = 1;
3087 int idx_number = 3;
3088 struct peer *peer;
3089 int ret;
3090 as_t as;
718e3744 3091
d62a17ae 3092 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3093 if (!peer)
3094 return CMD_WARNING_CONFIG_FAILED;
718e3744 3095
d62a17ae 3096 as = strtoul(argv[idx_number]->arg, NULL, 10);
3097 ret = peer_local_as_set(peer, as, 0, 0);
3098 return bgp_vty_return(vty, ret);
718e3744 3099}
3100
3101DEFUN (neighbor_local_as_no_prepend,
3102 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3103 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3104 NEIGHBOR_STR
3105 NEIGHBOR_ADDR_STR2
3106 "Specify a local-as number\n"
3107 "AS number used as local AS\n"
3108 "Do not prepend local-as to updates from ebgp peers\n")
3109{
d62a17ae 3110 int idx_peer = 1;
3111 int idx_number = 3;
3112 struct peer *peer;
3113 int ret;
3114 as_t as;
718e3744 3115
d62a17ae 3116 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3117 if (!peer)
3118 return CMD_WARNING_CONFIG_FAILED;
718e3744 3119
d62a17ae 3120 as = strtoul(argv[idx_number]->arg, NULL, 10);
3121 ret = peer_local_as_set(peer, as, 1, 0);
3122 return bgp_vty_return(vty, ret);
718e3744 3123}
3124
9d3f9705
AC
3125DEFUN (neighbor_local_as_no_prepend_replace_as,
3126 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3127 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3128 NEIGHBOR_STR
3129 NEIGHBOR_ADDR_STR2
3130 "Specify a local-as number\n"
3131 "AS number used as local AS\n"
3132 "Do not prepend local-as to updates from ebgp peers\n"
3133 "Do not prepend local-as to updates from ibgp peers\n")
3134{
d62a17ae 3135 int idx_peer = 1;
3136 int idx_number = 3;
3137 struct peer *peer;
3138 int ret;
3139 as_t as;
9d3f9705 3140
d62a17ae 3141 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3142 if (!peer)
3143 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3144
d62a17ae 3145 as = strtoul(argv[idx_number]->arg, NULL, 10);
3146 ret = peer_local_as_set(peer, as, 1, 1);
3147 return bgp_vty_return(vty, ret);
9d3f9705
AC
3148}
3149
718e3744 3150DEFUN (no_neighbor_local_as,
3151 no_neighbor_local_as_cmd,
a636c635 3152 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3153 NO_STR
3154 NEIGHBOR_STR
3155 NEIGHBOR_ADDR_STR2
a636c635
DW
3156 "Specify a local-as number\n"
3157 "AS number used as local AS\n"
3158 "Do not prepend local-as to updates from ebgp peers\n"
3159 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3160{
d62a17ae 3161 int idx_peer = 2;
3162 struct peer *peer;
3163 int ret;
718e3744 3164
d62a17ae 3165 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3166 if (!peer)
3167 return CMD_WARNING_CONFIG_FAILED;
718e3744 3168
d62a17ae 3169 ret = peer_local_as_unset(peer);
3170 return bgp_vty_return(vty, ret);
718e3744 3171}
3172
718e3744 3173
3f9c7369
DS
3174DEFUN (neighbor_solo,
3175 neighbor_solo_cmd,
9ccf14f7 3176 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3177 NEIGHBOR_STR
3178 NEIGHBOR_ADDR_STR2
3179 "Solo peer - part of its own update group\n")
3180{
d62a17ae 3181 int idx_peer = 1;
3182 struct peer *peer;
3183 int ret;
3f9c7369 3184
d62a17ae 3185 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3186 if (!peer)
3187 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3188
d62a17ae 3189 ret = update_group_adjust_soloness(peer, 1);
3190 return bgp_vty_return(vty, ret);
3f9c7369
DS
3191}
3192
3193DEFUN (no_neighbor_solo,
3194 no_neighbor_solo_cmd,
9ccf14f7 3195 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3196 NO_STR
3197 NEIGHBOR_STR
3198 NEIGHBOR_ADDR_STR2
3199 "Solo peer - part of its own update group\n")
3200{
d62a17ae 3201 int idx_peer = 2;
3202 struct peer *peer;
3203 int ret;
3f9c7369 3204
d62a17ae 3205 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3206 if (!peer)
3207 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3208
d62a17ae 3209 ret = update_group_adjust_soloness(peer, 0);
3210 return bgp_vty_return(vty, ret);
3f9c7369
DS
3211}
3212
0df7c91f
PJ
3213DEFUN (neighbor_password,
3214 neighbor_password_cmd,
9ccf14f7 3215 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3216 NEIGHBOR_STR
3217 NEIGHBOR_ADDR_STR2
3218 "Set a password\n"
3219 "The password\n")
3220{
d62a17ae 3221 int idx_peer = 1;
3222 int idx_line = 3;
3223 struct peer *peer;
3224 int ret;
0df7c91f 3225
d62a17ae 3226 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3227 if (!peer)
3228 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3229
d62a17ae 3230 ret = peer_password_set(peer, argv[idx_line]->arg);
3231 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3232}
3233
3234DEFUN (no_neighbor_password,
3235 no_neighbor_password_cmd,
a636c635 3236 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3237 NO_STR
3238 NEIGHBOR_STR
3239 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3240 "Set a password\n"
3241 "The password\n")
0df7c91f 3242{
d62a17ae 3243 int idx_peer = 2;
3244 struct peer *peer;
3245 int ret;
0df7c91f 3246
d62a17ae 3247 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3248 if (!peer)
3249 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3250
d62a17ae 3251 ret = peer_password_unset(peer);
3252 return bgp_vty_return(vty, ret);
0df7c91f 3253}
6b0655a2 3254
718e3744 3255DEFUN (neighbor_activate,
3256 neighbor_activate_cmd,
9ccf14f7 3257 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3258 NEIGHBOR_STR
3259 NEIGHBOR_ADDR_STR2
3260 "Enable the Address Family for this Neighbor\n")
3261{
d62a17ae 3262 int idx_peer = 1;
3263 int ret;
3264 struct peer *peer;
718e3744 3265
d62a17ae 3266 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3267 if (!peer)
3268 return CMD_WARNING_CONFIG_FAILED;
718e3744 3269
d62a17ae 3270 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3271 return bgp_vty_return(vty, ret);
718e3744 3272}
3273
d62a17ae 3274ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3275 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3276 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3277 "Enable the Address Family for this Neighbor\n")
596c17ba 3278
718e3744 3279DEFUN (no_neighbor_activate,
3280 no_neighbor_activate_cmd,
9ccf14f7 3281 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3282 NO_STR
3283 NEIGHBOR_STR
3284 NEIGHBOR_ADDR_STR2
3285 "Enable the Address Family for this Neighbor\n")
3286{
d62a17ae 3287 int idx_peer = 2;
3288 int ret;
3289 struct peer *peer;
718e3744 3290
d62a17ae 3291 /* Lookup peer. */
3292 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3293 if (!peer)
3294 return CMD_WARNING_CONFIG_FAILED;
718e3744 3295
d62a17ae 3296 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3297 return bgp_vty_return(vty, ret);
718e3744 3298}
6b0655a2 3299
d62a17ae 3300ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3301 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3302 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3303 "Enable the Address Family for this Neighbor\n")
596c17ba 3304
718e3744 3305DEFUN (neighbor_set_peer_group,
3306 neighbor_set_peer_group_cmd,
9ccf14f7 3307 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3308 NEIGHBOR_STR
a80beece 3309 NEIGHBOR_ADDR_STR2
718e3744 3310 "Member of the peer-group\n"
16cedbb0 3311 "Peer-group name\n")
718e3744 3312{
d62a17ae 3313 VTY_DECLVAR_CONTEXT(bgp, bgp);
3314 int idx_peer = 1;
3315 int idx_word = 3;
3316 int ret;
3317 as_t as;
3318 union sockunion su;
3319 struct peer *peer;
3320 struct peer_group *group;
3321
3322 peer = NULL;
3323
3324 ret = str2sockunion(argv[idx_peer]->arg, &su);
3325 if (ret < 0) {
3326 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3327 if (!peer) {
3328 vty_out(vty, "%% Malformed address or name: %s\n",
3329 argv[idx_peer]->arg);
3330 return CMD_WARNING_CONFIG_FAILED;
3331 }
3332 } else {
3333 if (peer_address_self_check(bgp, &su)) {
3334 vty_out(vty,
3335 "%% Can not configure the local system as neighbor\n");
3336 return CMD_WARNING_CONFIG_FAILED;
3337 }
3338
3339 /* Disallow for dynamic neighbor. */
3340 peer = peer_lookup(bgp, &su);
3341 if (peer && peer_dynamic_neighbor(peer)) {
3342 vty_out(vty,
3343 "%% Operation not allowed on a dynamic neighbor\n");
3344 return CMD_WARNING_CONFIG_FAILED;
3345 }
3346 }
3347
3348 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3349 if (!group) {
3350 vty_out(vty, "%% Configure the peer-group first\n");
3351 return CMD_WARNING_CONFIG_FAILED;
3352 }
3353
3354 ret = peer_group_bind(bgp, &su, peer, group, &as);
3355
3356 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3357 vty_out(vty,
3358 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3359 as);
3360 return CMD_WARNING_CONFIG_FAILED;
3361 }
3362
3363 return bgp_vty_return(vty, ret);
3364}
3365
3366ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3367 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3368 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3369 "Member of the peer-group\n"
3370 "Peer-group name\n")
596c17ba 3371
718e3744 3372DEFUN (no_neighbor_set_peer_group,
3373 no_neighbor_set_peer_group_cmd,
9ccf14f7 3374 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3375 NO_STR
3376 NEIGHBOR_STR
a80beece 3377 NEIGHBOR_ADDR_STR2
718e3744 3378 "Member of the peer-group\n"
16cedbb0 3379 "Peer-group name\n")
718e3744 3380{
d62a17ae 3381 VTY_DECLVAR_CONTEXT(bgp, bgp);
3382 int idx_peer = 2;
3383 int idx_word = 4;
3384 int ret;
3385 struct peer *peer;
3386 struct peer_group *group;
3387
3388 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3389 if (!peer)
3390 return CMD_WARNING_CONFIG_FAILED;
3391
3392 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3393 if (!group) {
3394 vty_out(vty, "%% Configure the peer-group first\n");
3395 return CMD_WARNING_CONFIG_FAILED;
3396 }
718e3744 3397
d62a17ae 3398 ret = peer_group_unbind(bgp, peer, group);
718e3744 3399
d62a17ae 3400 return bgp_vty_return(vty, ret);
718e3744 3401}
6b0655a2 3402
d62a17ae 3403ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3404 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3405 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3406 "Member of the peer-group\n"
3407 "Peer-group name\n")
596c17ba 3408
d62a17ae 3409static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3410 u_int16_t flag, int set)
718e3744 3411{
d62a17ae 3412 int ret;
3413 struct peer *peer;
718e3744 3414
d62a17ae 3415 peer = peer_and_group_lookup_vty(vty, ip_str);
3416 if (!peer)
3417 return CMD_WARNING_CONFIG_FAILED;
718e3744 3418
7ebe625c
QY
3419 /*
3420 * If 'neighbor <interface>', then this is for directly connected peers,
3421 * we should not accept disable-connected-check.
3422 */
3423 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3424 vty_out(vty,
3425 "%s is directly connected peer, cannot accept disable-"
3426 "connected-check\n",
3427 ip_str);
3428 return CMD_WARNING_CONFIG_FAILED;
3429 }
3430
d62a17ae 3431 if (!set && flag == PEER_FLAG_SHUTDOWN)
3432 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3433
d62a17ae 3434 if (set)
3435 ret = peer_flag_set(peer, flag);
3436 else
3437 ret = peer_flag_unset(peer, flag);
718e3744 3438
d62a17ae 3439 return bgp_vty_return(vty, ret);
718e3744 3440}
3441
d62a17ae 3442static int peer_flag_set_vty(struct vty *vty, const char *ip_str,
3443 u_int16_t flag)
718e3744 3444{
d62a17ae 3445 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3446}
3447
d62a17ae 3448static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3449 u_int16_t flag)
718e3744 3450{
d62a17ae 3451 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3452}
3453
3454/* neighbor passive. */
3455DEFUN (neighbor_passive,
3456 neighbor_passive_cmd,
9ccf14f7 3457 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3458 NEIGHBOR_STR
3459 NEIGHBOR_ADDR_STR2
3460 "Don't send open messages to this neighbor\n")
3461{
d62a17ae 3462 int idx_peer = 1;
3463 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3464}
3465
3466DEFUN (no_neighbor_passive,
3467 no_neighbor_passive_cmd,
9ccf14f7 3468 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3469 NO_STR
3470 NEIGHBOR_STR
3471 NEIGHBOR_ADDR_STR2
3472 "Don't send open messages to this neighbor\n")
3473{
d62a17ae 3474 int idx_peer = 2;
3475 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3476}
6b0655a2 3477
718e3744 3478/* neighbor shutdown. */
73d70fa6
DL
3479DEFUN (neighbor_shutdown_msg,
3480 neighbor_shutdown_msg_cmd,
3481 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3482 NEIGHBOR_STR
3483 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3484 "Administratively shut down this neighbor\n"
3485 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3486 "Shutdown message\n")
718e3744 3487{
d62a17ae 3488 int idx_peer = 1;
73d70fa6 3489
d62a17ae 3490 if (argc >= 5) {
3491 struct peer *peer =
3492 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3493 char *message;
73d70fa6 3494
d62a17ae 3495 if (!peer)
3496 return CMD_WARNING_CONFIG_FAILED;
3497 message = argv_concat(argv, argc, 4);
3498 peer_tx_shutdown_message_set(peer, message);
3499 XFREE(MTYPE_TMP, message);
3500 }
73d70fa6 3501
d62a17ae 3502 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3503}
3504
d62a17ae 3505ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3506 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3507 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3508 "Administratively shut down this neighbor\n")
73d70fa6
DL
3509
3510DEFUN (no_neighbor_shutdown_msg,
3511 no_neighbor_shutdown_msg_cmd,
3512 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3513 NO_STR
3514 NEIGHBOR_STR
3515 NEIGHBOR_ADDR_STR2
3516 "Administratively shut down this neighbor\n"
3517 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3518 "Shutdown message\n")
718e3744 3519{
d62a17ae 3520 int idx_peer = 2;
73d70fa6 3521
d62a17ae 3522 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3523 PEER_FLAG_SHUTDOWN);
718e3744 3524}
6b0655a2 3525
d62a17ae 3526ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3527 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3528 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3529 "Administratively shut down this neighbor\n")
73d70fa6 3530
718e3744 3531/* neighbor capability dynamic. */
3532DEFUN (neighbor_capability_dynamic,
3533 neighbor_capability_dynamic_cmd,
9ccf14f7 3534 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3535 NEIGHBOR_STR
3536 NEIGHBOR_ADDR_STR2
3537 "Advertise capability to the peer\n"
3538 "Advertise dynamic capability to this neighbor\n")
3539{
d62a17ae 3540 int idx_peer = 1;
3541 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3542 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3543}
3544
3545DEFUN (no_neighbor_capability_dynamic,
3546 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3547 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3548 NO_STR
3549 NEIGHBOR_STR
3550 NEIGHBOR_ADDR_STR2
3551 "Advertise capability to the peer\n"
3552 "Advertise dynamic capability to this neighbor\n")
3553{
d62a17ae 3554 int idx_peer = 2;
3555 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3556 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3557}
6b0655a2 3558
718e3744 3559/* neighbor dont-capability-negotiate */
3560DEFUN (neighbor_dont_capability_negotiate,
3561 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3562 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3563 NEIGHBOR_STR
3564 NEIGHBOR_ADDR_STR2
3565 "Do not perform capability negotiation\n")
3566{
d62a17ae 3567 int idx_peer = 1;
3568 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3569 PEER_FLAG_DONT_CAPABILITY);
718e3744 3570}
3571
3572DEFUN (no_neighbor_dont_capability_negotiate,
3573 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3574 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3575 NO_STR
3576 NEIGHBOR_STR
3577 NEIGHBOR_ADDR_STR2
3578 "Do not perform capability negotiation\n")
3579{
d62a17ae 3580 int idx_peer = 2;
3581 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3582 PEER_FLAG_DONT_CAPABILITY);
718e3744 3583}
6b0655a2 3584
8a92a8a0
DS
3585/* neighbor capability extended next hop encoding */
3586DEFUN (neighbor_capability_enhe,
3587 neighbor_capability_enhe_cmd,
9ccf14f7 3588 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3589 NEIGHBOR_STR
3590 NEIGHBOR_ADDR_STR2
3591 "Advertise capability to the peer\n"
3592 "Advertise extended next-hop capability to the peer\n")
3593{
d62a17ae 3594 int idx_peer = 1;
3595 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3596 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3597}
3598
3599DEFUN (no_neighbor_capability_enhe,
3600 no_neighbor_capability_enhe_cmd,
9ccf14f7 3601 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3602 NO_STR
3603 NEIGHBOR_STR
3604 NEIGHBOR_ADDR_STR2
3605 "Advertise capability to the peer\n"
3606 "Advertise extended next-hop capability to the peer\n")
3607{
d62a17ae 3608 int idx_peer = 2;
3609 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3610 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3611}
3612
d62a17ae 3613static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3614 afi_t afi, safi_t safi, u_int32_t flag,
3615 int set)
718e3744 3616{
d62a17ae 3617 int ret;
3618 struct peer *peer;
718e3744 3619
d62a17ae 3620 peer = peer_and_group_lookup_vty(vty, peer_str);
3621 if (!peer)
3622 return CMD_WARNING_CONFIG_FAILED;
718e3744 3623
d62a17ae 3624 if (set)
3625 ret = peer_af_flag_set(peer, afi, safi, flag);
3626 else
3627 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3628
d62a17ae 3629 return bgp_vty_return(vty, ret);
718e3744 3630}
3631
d62a17ae 3632static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3633 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3634{
d62a17ae 3635 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3636}
3637
d62a17ae 3638static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3639 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3640{
d62a17ae 3641 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3642}
6b0655a2 3643
718e3744 3644/* neighbor capability orf prefix-list. */
3645DEFUN (neighbor_capability_orf_prefix,
3646 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3647 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3648 NEIGHBOR_STR
3649 NEIGHBOR_ADDR_STR2
3650 "Advertise capability to the peer\n"
3651 "Advertise ORF capability to the peer\n"
3652 "Advertise prefixlist ORF capability to this neighbor\n"
3653 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3654 "Capability to RECEIVE the ORF from this neighbor\n"
3655 "Capability to SEND the ORF to this neighbor\n")
3656{
d62a17ae 3657 int idx_peer = 1;
3658 int idx_send_recv = 5;
3659 u_int16_t flag = 0;
3660
3661 if (strmatch(argv[idx_send_recv]->text, "send"))
3662 flag = PEER_FLAG_ORF_PREFIX_SM;
3663 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3664 flag = PEER_FLAG_ORF_PREFIX_RM;
3665 else if (strmatch(argv[idx_send_recv]->text, "both"))
3666 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3667 else {
3668 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3669 return CMD_WARNING_CONFIG_FAILED;
3670 }
3671
3672 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3673 bgp_node_safi(vty), flag);
3674}
3675
3676ALIAS_HIDDEN(
3677 neighbor_capability_orf_prefix,
3678 neighbor_capability_orf_prefix_hidden_cmd,
3679 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3680 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3681 "Advertise capability to the peer\n"
3682 "Advertise ORF capability to the peer\n"
3683 "Advertise prefixlist ORF capability to this neighbor\n"
3684 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3685 "Capability to RECEIVE the ORF from this neighbor\n"
3686 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3687
718e3744 3688DEFUN (no_neighbor_capability_orf_prefix,
3689 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3690 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3691 NO_STR
3692 NEIGHBOR_STR
3693 NEIGHBOR_ADDR_STR2
3694 "Advertise capability to the peer\n"
3695 "Advertise ORF capability to the peer\n"
3696 "Advertise prefixlist ORF capability to this neighbor\n"
3697 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3698 "Capability to RECEIVE the ORF from this neighbor\n"
3699 "Capability to SEND the ORF to this neighbor\n")
3700{
d62a17ae 3701 int idx_peer = 2;
3702 int idx_send_recv = 6;
3703 u_int16_t flag = 0;
3704
3705 if (strmatch(argv[idx_send_recv]->text, "send"))
3706 flag = PEER_FLAG_ORF_PREFIX_SM;
3707 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3708 flag = PEER_FLAG_ORF_PREFIX_RM;
3709 else if (strmatch(argv[idx_send_recv]->text, "both"))
3710 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3711 else {
3712 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3713 return CMD_WARNING_CONFIG_FAILED;
3714 }
3715
3716 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3717 bgp_node_afi(vty), bgp_node_safi(vty),
3718 flag);
3719}
3720
3721ALIAS_HIDDEN(
3722 no_neighbor_capability_orf_prefix,
3723 no_neighbor_capability_orf_prefix_hidden_cmd,
3724 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3725 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3726 "Advertise capability to the peer\n"
3727 "Advertise ORF capability to the peer\n"
3728 "Advertise prefixlist ORF capability to this neighbor\n"
3729 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3730 "Capability to RECEIVE the ORF from this neighbor\n"
3731 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3732
718e3744 3733/* neighbor next-hop-self. */
3734DEFUN (neighbor_nexthop_self,
3735 neighbor_nexthop_self_cmd,
9ccf14f7 3736 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3737 NEIGHBOR_STR
3738 NEIGHBOR_ADDR_STR2
a538debe 3739 "Disable the next hop calculation for this neighbor\n")
718e3744 3740{
d62a17ae 3741 int idx_peer = 1;
3742 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3743 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3744}
9e7a53c1 3745
d62a17ae 3746ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3747 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3748 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3749 "Disable the next hop calculation for this neighbor\n")
596c17ba 3750
a538debe
DS
3751/* neighbor next-hop-self. */
3752DEFUN (neighbor_nexthop_self_force,
3753 neighbor_nexthop_self_force_cmd,
9ccf14f7 3754 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3755 NEIGHBOR_STR
3756 NEIGHBOR_ADDR_STR2
3757 "Disable the next hop calculation for this neighbor\n"
3758 "Set the next hop to self for reflected routes\n")
3759{
d62a17ae 3760 int idx_peer = 1;
3761 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3762 bgp_node_safi(vty),
3763 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3764}
3765
d62a17ae 3766ALIAS_HIDDEN(neighbor_nexthop_self_force,
3767 neighbor_nexthop_self_force_hidden_cmd,
3768 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3769 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3770 "Disable the next hop calculation for this neighbor\n"
3771 "Set the next hop to self for reflected routes\n")
596c17ba 3772
718e3744 3773DEFUN (no_neighbor_nexthop_self,
3774 no_neighbor_nexthop_self_cmd,
9ccf14f7 3775 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3776 NO_STR
3777 NEIGHBOR_STR
3778 NEIGHBOR_ADDR_STR2
a538debe 3779 "Disable the next hop calculation for this neighbor\n")
718e3744 3780{
d62a17ae 3781 int idx_peer = 2;
3782 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3783 bgp_node_afi(vty), bgp_node_safi(vty),
3784 PEER_FLAG_NEXTHOP_SELF);
718e3744 3785}
6b0655a2 3786
d62a17ae 3787ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3788 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3789 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3790 "Disable the next hop calculation for this neighbor\n")
596c17ba 3791
88b8ed8d 3792DEFUN (no_neighbor_nexthop_self_force,
a538debe 3793 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3794 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3795 NO_STR
3796 NEIGHBOR_STR
3797 NEIGHBOR_ADDR_STR2
3798 "Disable the next hop calculation for this neighbor\n"
3799 "Set the next hop to self for reflected routes\n")
88b8ed8d 3800{
d62a17ae 3801 int idx_peer = 2;
3802 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3803 bgp_node_afi(vty), bgp_node_safi(vty),
3804 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3805}
a538debe 3806
d62a17ae 3807ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3808 no_neighbor_nexthop_self_force_hidden_cmd,
3809 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3810 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3811 "Disable the next hop calculation for this neighbor\n"
3812 "Set the next hop to self for reflected routes\n")
596c17ba 3813
c7122e14
DS
3814/* neighbor as-override */
3815DEFUN (neighbor_as_override,
3816 neighbor_as_override_cmd,
9ccf14f7 3817 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3818 NEIGHBOR_STR
3819 NEIGHBOR_ADDR_STR2
3820 "Override ASNs in outbound updates if aspath equals remote-as\n")
3821{
d62a17ae 3822 int idx_peer = 1;
3823 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3824 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3825}
3826
d62a17ae 3827ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3828 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3829 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3830 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3831
c7122e14
DS
3832DEFUN (no_neighbor_as_override,
3833 no_neighbor_as_override_cmd,
9ccf14f7 3834 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3835 NO_STR
3836 NEIGHBOR_STR
3837 NEIGHBOR_ADDR_STR2
3838 "Override ASNs in outbound updates if aspath equals remote-as\n")
3839{
d62a17ae 3840 int idx_peer = 2;
3841 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3842 bgp_node_afi(vty), bgp_node_safi(vty),
3843 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3844}
3845
d62a17ae 3846ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3847 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3848 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3849 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3850
718e3744 3851/* neighbor remove-private-AS. */
3852DEFUN (neighbor_remove_private_as,
3853 neighbor_remove_private_as_cmd,
9ccf14f7 3854 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3855 NEIGHBOR_STR
3856 NEIGHBOR_ADDR_STR2
5000f21c 3857 "Remove private ASNs in outbound updates\n")
718e3744 3858{
d62a17ae 3859 int idx_peer = 1;
3860 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3861 bgp_node_safi(vty),
3862 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3863}
3864
d62a17ae 3865ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3866 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3867 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3868 "Remove private ASNs in outbound updates\n")
596c17ba 3869
5000f21c
DS
3870DEFUN (neighbor_remove_private_as_all,
3871 neighbor_remove_private_as_all_cmd,
9ccf14f7 3872 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3873 NEIGHBOR_STR
3874 NEIGHBOR_ADDR_STR2
3875 "Remove private ASNs in outbound updates\n"
efd7904e 3876 "Apply to all AS numbers\n")
5000f21c 3877{
d62a17ae 3878 int idx_peer = 1;
3879 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3880 bgp_node_safi(vty),
3881 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3882}
3883
d62a17ae 3884ALIAS_HIDDEN(neighbor_remove_private_as_all,
3885 neighbor_remove_private_as_all_hidden_cmd,
3886 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3887 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3888 "Remove private ASNs in outbound updates\n"
3889 "Apply to all AS numbers")
596c17ba 3890
5000f21c
DS
3891DEFUN (neighbor_remove_private_as_replace_as,
3892 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3893 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3894 NEIGHBOR_STR
3895 NEIGHBOR_ADDR_STR2
3896 "Remove private ASNs in outbound updates\n"
3897 "Replace private ASNs with our ASN in outbound updates\n")
3898{
d62a17ae 3899 int idx_peer = 1;
3900 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3901 bgp_node_safi(vty),
3902 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3903}
3904
d62a17ae 3905ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3906 neighbor_remove_private_as_replace_as_hidden_cmd,
3907 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3908 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3909 "Remove private ASNs in outbound updates\n"
3910 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3911
5000f21c
DS
3912DEFUN (neighbor_remove_private_as_all_replace_as,
3913 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3914 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3915 NEIGHBOR_STR
3916 NEIGHBOR_ADDR_STR2
3917 "Remove private ASNs in outbound updates\n"
16cedbb0 3918 "Apply to all AS numbers\n"
5000f21c
DS
3919 "Replace private ASNs with our ASN in outbound updates\n")
3920{
d62a17ae 3921 int idx_peer = 1;
3922 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3923 bgp_node_safi(vty),
3924 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3925}
3926
d62a17ae 3927ALIAS_HIDDEN(
3928 neighbor_remove_private_as_all_replace_as,
3929 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3930 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3931 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3932 "Remove private ASNs in outbound updates\n"
3933 "Apply to all AS numbers\n"
3934 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3935
718e3744 3936DEFUN (no_neighbor_remove_private_as,
3937 no_neighbor_remove_private_as_cmd,
9ccf14f7 3938 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3939 NO_STR
3940 NEIGHBOR_STR
3941 NEIGHBOR_ADDR_STR2
5000f21c 3942 "Remove private ASNs in outbound updates\n")
718e3744 3943{
d62a17ae 3944 int idx_peer = 2;
3945 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3946 bgp_node_afi(vty), bgp_node_safi(vty),
3947 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3948}
6b0655a2 3949
d62a17ae 3950ALIAS_HIDDEN(no_neighbor_remove_private_as,
3951 no_neighbor_remove_private_as_hidden_cmd,
3952 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3953 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3954 "Remove private ASNs in outbound updates\n")
596c17ba 3955
88b8ed8d 3956DEFUN (no_neighbor_remove_private_as_all,
5000f21c 3957 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 3958 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3959 NO_STR
3960 NEIGHBOR_STR
3961 NEIGHBOR_ADDR_STR2
3962 "Remove private ASNs in outbound updates\n"
16cedbb0 3963 "Apply to all AS numbers\n")
88b8ed8d 3964{
d62a17ae 3965 int idx_peer = 2;
3966 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3967 bgp_node_afi(vty), bgp_node_safi(vty),
3968 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 3969}
5000f21c 3970
d62a17ae 3971ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3972 no_neighbor_remove_private_as_all_hidden_cmd,
3973 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3974 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3975 "Remove private ASNs in outbound updates\n"
3976 "Apply to all AS numbers\n")
596c17ba 3977
88b8ed8d 3978DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 3979 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3980 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3981 NO_STR
3982 NEIGHBOR_STR
3983 NEIGHBOR_ADDR_STR2
3984 "Remove private ASNs in outbound updates\n"
3985 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3986{
d62a17ae 3987 int idx_peer = 2;
3988 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3989 bgp_node_afi(vty), bgp_node_safi(vty),
3990 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 3991}
5000f21c 3992
d62a17ae 3993ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
3994 no_neighbor_remove_private_as_replace_as_hidden_cmd,
3995 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3996 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3997 "Remove private ASNs in outbound updates\n"
3998 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3999
88b8ed8d 4000DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 4001 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 4002 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4003 NO_STR
4004 NEIGHBOR_STR
4005 NEIGHBOR_ADDR_STR2
4006 "Remove private ASNs in outbound updates\n"
16cedbb0 4007 "Apply to all AS numbers\n"
5000f21c 4008 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4009{
d62a17ae 4010 int idx_peer = 2;
4011 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4012 bgp_node_afi(vty), bgp_node_safi(vty),
4013 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4014}
5000f21c 4015
d62a17ae 4016ALIAS_HIDDEN(
4017 no_neighbor_remove_private_as_all_replace_as,
4018 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4019 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4020 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4021 "Remove private ASNs in outbound updates\n"
4022 "Apply to all AS numbers\n"
4023 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4024
5000f21c 4025
718e3744 4026/* neighbor send-community. */
4027DEFUN (neighbor_send_community,
4028 neighbor_send_community_cmd,
9ccf14f7 4029 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4030 NEIGHBOR_STR
4031 NEIGHBOR_ADDR_STR2
4032 "Send Community attribute to this neighbor\n")
4033{
d62a17ae 4034 int idx_peer = 1;
4035 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4036 bgp_node_safi(vty),
4037 PEER_FLAG_SEND_COMMUNITY);
718e3744 4038}
4039
d62a17ae 4040ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4041 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4042 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4043 "Send Community attribute to this neighbor\n")
596c17ba 4044
718e3744 4045DEFUN (no_neighbor_send_community,
4046 no_neighbor_send_community_cmd,
9ccf14f7 4047 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4048 NO_STR
4049 NEIGHBOR_STR
4050 NEIGHBOR_ADDR_STR2
4051 "Send Community attribute to this neighbor\n")
4052{
d62a17ae 4053 int idx_peer = 2;
4054 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4055 bgp_node_afi(vty), bgp_node_safi(vty),
4056 PEER_FLAG_SEND_COMMUNITY);
718e3744 4057}
6b0655a2 4058
d62a17ae 4059ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4060 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4061 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4062 "Send Community attribute to this neighbor\n")
596c17ba 4063
718e3744 4064/* neighbor send-community extended. */
4065DEFUN (neighbor_send_community_type,
4066 neighbor_send_community_type_cmd,
57d187bc 4067 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4068 NEIGHBOR_STR
4069 NEIGHBOR_ADDR_STR2
4070 "Send Community attribute to this neighbor\n"
4071 "Send Standard and Extended Community attributes\n"
57d187bc 4072 "Send Standard, Large and Extended Community attributes\n"
718e3744 4073 "Send Extended Community attributes\n"
57d187bc
JS
4074 "Send Standard Community attributes\n"
4075 "Send Large Community attributes\n")
718e3744 4076{
d62a17ae 4077 int idx = 0;
4078 u_int32_t flag = 0;
4079
4080 char *peer = argv[1]->arg;
4081
4082 if (argv_find(argv, argc, "standard", &idx))
4083 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4084 else if (argv_find(argv, argc, "extended", &idx))
4085 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4086 else if (argv_find(argv, argc, "large", &idx))
4087 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4088 else if (argv_find(argv, argc, "both", &idx)) {
4089 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4090 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4091 } else {
4092 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4093 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4094 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4095 }
4096
4097 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4098 bgp_node_safi(vty), flag);
4099}
4100
4101ALIAS_HIDDEN(
4102 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4103 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4104 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4105 "Send Community attribute to this neighbor\n"
4106 "Send Standard and Extended Community attributes\n"
4107 "Send Standard, Large and Extended Community attributes\n"
4108 "Send Extended Community attributes\n"
4109 "Send Standard Community attributes\n"
4110 "Send Large Community attributes\n")
596c17ba 4111
718e3744 4112DEFUN (no_neighbor_send_community_type,
4113 no_neighbor_send_community_type_cmd,
57d187bc 4114 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4115 NO_STR
4116 NEIGHBOR_STR
4117 NEIGHBOR_ADDR_STR2
4118 "Send Community attribute to this neighbor\n"
4119 "Send Standard and Extended Community attributes\n"
57d187bc 4120 "Send Standard, Large and Extended Community attributes\n"
718e3744 4121 "Send Extended Community attributes\n"
57d187bc
JS
4122 "Send Standard Community attributes\n"
4123 "Send Large Community attributes\n")
718e3744 4124{
d62a17ae 4125 int idx_peer = 2;
4126
4127 const char *type = argv[argc - 1]->text;
4128
4129 if (strmatch(type, "standard"))
4130 return peer_af_flag_unset_vty(
4131 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4132 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4133 if (strmatch(type, "extended"))
4134 return peer_af_flag_unset_vty(
4135 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4136 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4137 if (strmatch(type, "large"))
4138 return peer_af_flag_unset_vty(
4139 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4140 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4141 if (strmatch(type, "both"))
4142 return peer_af_flag_unset_vty(
4143 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4144 bgp_node_safi(vty),
4145 PEER_FLAG_SEND_COMMUNITY
4146 | PEER_FLAG_SEND_EXT_COMMUNITY);
4147
4148 /* if (strmatch (type, "all")) */
4149 return peer_af_flag_unset_vty(
4150 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4151 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4152 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4153}
4154
4155ALIAS_HIDDEN(
4156 no_neighbor_send_community_type,
4157 no_neighbor_send_community_type_hidden_cmd,
4158 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4159 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4160 "Send Community attribute to this neighbor\n"
4161 "Send Standard and Extended Community attributes\n"
4162 "Send Standard, Large and Extended Community attributes\n"
4163 "Send Extended Community attributes\n"
4164 "Send Standard Community attributes\n"
4165 "Send Large Community attributes\n")
596c17ba 4166
718e3744 4167/* neighbor soft-reconfig. */
4168DEFUN (neighbor_soft_reconfiguration,
4169 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4170 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4171 NEIGHBOR_STR
4172 NEIGHBOR_ADDR_STR2
4173 "Per neighbor soft reconfiguration\n"
4174 "Allow inbound soft reconfiguration for this neighbor\n")
4175{
d62a17ae 4176 int idx_peer = 1;
4177 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4178 bgp_node_safi(vty),
4179 PEER_FLAG_SOFT_RECONFIG);
718e3744 4180}
4181
d62a17ae 4182ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4183 neighbor_soft_reconfiguration_hidden_cmd,
4184 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4185 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4186 "Per neighbor soft reconfiguration\n"
4187 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4188
718e3744 4189DEFUN (no_neighbor_soft_reconfiguration,
4190 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4191 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4192 NO_STR
4193 NEIGHBOR_STR
4194 NEIGHBOR_ADDR_STR2
4195 "Per neighbor soft reconfiguration\n"
4196 "Allow inbound soft reconfiguration for this neighbor\n")
4197{
d62a17ae 4198 int idx_peer = 2;
4199 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4200 bgp_node_afi(vty), bgp_node_safi(vty),
4201 PEER_FLAG_SOFT_RECONFIG);
718e3744 4202}
6b0655a2 4203
d62a17ae 4204ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4205 no_neighbor_soft_reconfiguration_hidden_cmd,
4206 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4207 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4208 "Per neighbor soft reconfiguration\n"
4209 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4210
718e3744 4211DEFUN (neighbor_route_reflector_client,
4212 neighbor_route_reflector_client_cmd,
9ccf14f7 4213 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4214 NEIGHBOR_STR
4215 NEIGHBOR_ADDR_STR2
4216 "Configure a neighbor as Route Reflector client\n")
4217{
d62a17ae 4218 int idx_peer = 1;
4219 struct peer *peer;
718e3744 4220
4221
d62a17ae 4222 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4223 if (!peer)
4224 return CMD_WARNING_CONFIG_FAILED;
718e3744 4225
d62a17ae 4226 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4227 bgp_node_safi(vty),
4228 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4229}
4230
d62a17ae 4231ALIAS_HIDDEN(neighbor_route_reflector_client,
4232 neighbor_route_reflector_client_hidden_cmd,
4233 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4234 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4235 "Configure a neighbor as Route Reflector client\n")
596c17ba 4236
718e3744 4237DEFUN (no_neighbor_route_reflector_client,
4238 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4239 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4240 NO_STR
4241 NEIGHBOR_STR
4242 NEIGHBOR_ADDR_STR2
4243 "Configure a neighbor as Route Reflector client\n")
4244{
d62a17ae 4245 int idx_peer = 2;
4246 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4247 bgp_node_afi(vty), bgp_node_safi(vty),
4248 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4249}
6b0655a2 4250
d62a17ae 4251ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4252 no_neighbor_route_reflector_client_hidden_cmd,
4253 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4254 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4255 "Configure a neighbor as Route Reflector client\n")
596c17ba 4256
718e3744 4257/* neighbor route-server-client. */
4258DEFUN (neighbor_route_server_client,
4259 neighbor_route_server_client_cmd,
9ccf14f7 4260 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4261 NEIGHBOR_STR
4262 NEIGHBOR_ADDR_STR2
4263 "Configure a neighbor as Route Server client\n")
4264{
d62a17ae 4265 int idx_peer = 1;
4266 struct peer *peer;
2a3d5731 4267
d62a17ae 4268 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4269 if (!peer)
4270 return CMD_WARNING_CONFIG_FAILED;
4271 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4272 bgp_node_safi(vty),
4273 PEER_FLAG_RSERVER_CLIENT);
718e3744 4274}
4275
d62a17ae 4276ALIAS_HIDDEN(neighbor_route_server_client,
4277 neighbor_route_server_client_hidden_cmd,
4278 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4279 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4280 "Configure a neighbor as Route Server client\n")
596c17ba 4281
718e3744 4282DEFUN (no_neighbor_route_server_client,
4283 no_neighbor_route_server_client_cmd,
9ccf14f7 4284 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4285 NO_STR
4286 NEIGHBOR_STR
4287 NEIGHBOR_ADDR_STR2
4288 "Configure a neighbor as Route Server client\n")
fee0f4c6 4289{
d62a17ae 4290 int idx_peer = 2;
4291 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4292 bgp_node_afi(vty), bgp_node_safi(vty),
4293 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4294}
6b0655a2 4295
d62a17ae 4296ALIAS_HIDDEN(no_neighbor_route_server_client,
4297 no_neighbor_route_server_client_hidden_cmd,
4298 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4299 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4300 "Configure a neighbor as Route Server client\n")
596c17ba 4301
fee0f4c6 4302DEFUN (neighbor_nexthop_local_unchanged,
4303 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4304 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4305 NEIGHBOR_STR
4306 NEIGHBOR_ADDR_STR2
4307 "Configure treatment of outgoing link-local nexthop attribute\n"
4308 "Leave link-local nexthop unchanged for this peer\n")
4309{
d62a17ae 4310 int idx_peer = 1;
4311 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4312 bgp_node_safi(vty),
4313 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4314}
6b0655a2 4315
fee0f4c6 4316DEFUN (no_neighbor_nexthop_local_unchanged,
4317 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4318 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4319 NO_STR
4320 NEIGHBOR_STR
4321 NEIGHBOR_ADDR_STR2
4322 "Configure treatment of outgoing link-local-nexthop attribute\n"
4323 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4324{
d62a17ae 4325 int idx_peer = 2;
4326 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4327 bgp_node_afi(vty), bgp_node_safi(vty),
4328 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4329}
6b0655a2 4330
718e3744 4331DEFUN (neighbor_attr_unchanged,
4332 neighbor_attr_unchanged_cmd,
a8206004 4333 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4334 NEIGHBOR_STR
4335 NEIGHBOR_ADDR_STR2
4336 "BGP attribute is propagated unchanged to this neighbor\n"
4337 "As-path attribute\n"
4338 "Nexthop attribute\n"
a8206004 4339 "Med attribute\n")
718e3744 4340{
d62a17ae 4341 int idx = 0;
8eeb0335
DW
4342 char *peer_str = argv[1]->arg;
4343 struct peer *peer;
d62a17ae 4344 u_int16_t flags = 0;
8eeb0335
DW
4345 afi_t afi = bgp_node_afi(vty);
4346 safi_t safi = bgp_node_safi(vty);
4347
4348 peer = peer_and_group_lookup_vty(vty, peer_str);
4349 if (!peer)
4350 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4351
4352 if (argv_find(argv, argc, "as-path", &idx))
4353 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4354 idx = 0;
4355 if (argv_find(argv, argc, "next-hop", &idx))
4356 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4357 idx = 0;
4358 if (argv_find(argv, argc, "med", &idx))
4359 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4360
8eeb0335
DW
4361 /* no flags means all of them! */
4362 if (!flags) {
d62a17ae 4363 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4364 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4365 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4366 } else {
a4d82a8a
PZ
4367 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4368 && peer_af_flag_check(peer, afi, safi,
4369 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4370 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4371 PEER_FLAG_AS_PATH_UNCHANGED);
4372 }
4373
a4d82a8a
PZ
4374 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4375 && peer_af_flag_check(peer, afi, safi,
4376 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4377 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4378 PEER_FLAG_NEXTHOP_UNCHANGED);
4379 }
4380
a4d82a8a
PZ
4381 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4382 && peer_af_flag_check(peer, afi, safi,
4383 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4384 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4385 PEER_FLAG_MED_UNCHANGED);
4386 }
d62a17ae 4387 }
4388
8eeb0335 4389 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4390}
4391
4392ALIAS_HIDDEN(
4393 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4394 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4395 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4396 "BGP attribute is propagated unchanged to this neighbor\n"
4397 "As-path attribute\n"
4398 "Nexthop attribute\n"
4399 "Med attribute\n")
596c17ba 4400
718e3744 4401DEFUN (no_neighbor_attr_unchanged,
4402 no_neighbor_attr_unchanged_cmd,
a8206004 4403 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4404 NO_STR
718e3744 4405 NEIGHBOR_STR
4406 NEIGHBOR_ADDR_STR2
31500417
DW
4407 "BGP attribute is propagated unchanged to this neighbor\n"
4408 "As-path attribute\n"
40e718b5 4409 "Nexthop attribute\n"
a8206004 4410 "Med attribute\n")
718e3744 4411{
d62a17ae 4412 int idx = 0;
4413 char *peer = argv[2]->arg;
4414 u_int16_t flags = 0;
4415
4416 if (argv_find(argv, argc, "as-path", &idx))
4417 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4418 idx = 0;
4419 if (argv_find(argv, argc, "next-hop", &idx))
4420 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4421 idx = 0;
4422 if (argv_find(argv, argc, "med", &idx))
4423 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4424
4425 if (!flags) // no flags means all of them!
4426 {
4427 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4428 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4429 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4430 }
4431
4432 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4433 bgp_node_safi(vty), flags);
4434}
4435
4436ALIAS_HIDDEN(
4437 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4438 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4439 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4440 "BGP attribute is propagated unchanged to this neighbor\n"
4441 "As-path attribute\n"
4442 "Nexthop attribute\n"
4443 "Med attribute\n")
718e3744 4444
718e3744 4445/* EBGP multihop configuration. */
d62a17ae 4446static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4447 const char *ttl_str)
718e3744 4448{
d62a17ae 4449 struct peer *peer;
4450 unsigned int ttl;
718e3744 4451
d62a17ae 4452 peer = peer_and_group_lookup_vty(vty, ip_str);
4453 if (!peer)
4454 return CMD_WARNING_CONFIG_FAILED;
718e3744 4455
d62a17ae 4456 if (peer->conf_if)
4457 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4458
d62a17ae 4459 if (!ttl_str)
4460 ttl = MAXTTL;
4461 else
4462 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4463
d62a17ae 4464 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4465}
4466
d62a17ae 4467static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4468{
d62a17ae 4469 struct peer *peer;
718e3744 4470
d62a17ae 4471 peer = peer_and_group_lookup_vty(vty, ip_str);
4472 if (!peer)
4473 return CMD_WARNING_CONFIG_FAILED;
718e3744 4474
d62a17ae 4475 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4476}
4477
4478/* neighbor ebgp-multihop. */
4479DEFUN (neighbor_ebgp_multihop,
4480 neighbor_ebgp_multihop_cmd,
9ccf14f7 4481 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4482 NEIGHBOR_STR
4483 NEIGHBOR_ADDR_STR2
4484 "Allow EBGP neighbors not on directly connected networks\n")
4485{
d62a17ae 4486 int idx_peer = 1;
4487 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4488}
4489
4490DEFUN (neighbor_ebgp_multihop_ttl,
4491 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4492 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4493 NEIGHBOR_STR
4494 NEIGHBOR_ADDR_STR2
4495 "Allow EBGP neighbors not on directly connected networks\n"
4496 "maximum hop count\n")
4497{
d62a17ae 4498 int idx_peer = 1;
4499 int idx_number = 3;
4500 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4501 argv[idx_number]->arg);
718e3744 4502}
4503
4504DEFUN (no_neighbor_ebgp_multihop,
4505 no_neighbor_ebgp_multihop_cmd,
a636c635 4506 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4507 NO_STR
4508 NEIGHBOR_STR
4509 NEIGHBOR_ADDR_STR2
a636c635
DW
4510 "Allow EBGP neighbors not on directly connected networks\n"
4511 "maximum hop count\n")
718e3744 4512{
d62a17ae 4513 int idx_peer = 2;
4514 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4515}
4516
6b0655a2 4517
6ffd2079 4518/* disable-connected-check */
4519DEFUN (neighbor_disable_connected_check,
4520 neighbor_disable_connected_check_cmd,
7ebe625c 4521 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4522 NEIGHBOR_STR
7ebe625c 4523 NEIGHBOR_ADDR_STR2
a636c635
DW
4524 "one-hop away EBGP peer using loopback address\n"
4525 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4526{
d62a17ae 4527 int idx_peer = 1;
4528 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4529 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4530}
4531
4532DEFUN (no_neighbor_disable_connected_check,
4533 no_neighbor_disable_connected_check_cmd,
7ebe625c 4534 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4535 NO_STR
4536 NEIGHBOR_STR
7ebe625c 4537 NEIGHBOR_ADDR_STR2
a636c635
DW
4538 "one-hop away EBGP peer using loopback address\n"
4539 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4540{
d62a17ae 4541 int idx_peer = 2;
4542 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4543 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4544}
4545
718e3744 4546DEFUN (neighbor_description,
4547 neighbor_description_cmd,
e961923c 4548 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4549 NEIGHBOR_STR
4550 NEIGHBOR_ADDR_STR2
4551 "Neighbor specific description\n"
4552 "Up to 80 characters describing this neighbor\n")
4553{
d62a17ae 4554 int idx_peer = 1;
4555 int idx_line = 3;
4556 struct peer *peer;
4557 char *str;
718e3744 4558
d62a17ae 4559 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4560 if (!peer)
4561 return CMD_WARNING_CONFIG_FAILED;
718e3744 4562
d62a17ae 4563 str = argv_concat(argv, argc, idx_line);
718e3744 4564
d62a17ae 4565 peer_description_set(peer, str);
718e3744 4566
d62a17ae 4567 XFREE(MTYPE_TMP, str);
718e3744 4568
d62a17ae 4569 return CMD_SUCCESS;
718e3744 4570}
4571
4572DEFUN (no_neighbor_description,
4573 no_neighbor_description_cmd,
a636c635 4574 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4575 NO_STR
4576 NEIGHBOR_STR
4577 NEIGHBOR_ADDR_STR2
a636c635
DW
4578 "Neighbor specific description\n"
4579 "Up to 80 characters describing this neighbor\n")
718e3744 4580{
d62a17ae 4581 int idx_peer = 2;
4582 struct peer *peer;
718e3744 4583
d62a17ae 4584 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4585 if (!peer)
4586 return CMD_WARNING_CONFIG_FAILED;
718e3744 4587
d62a17ae 4588 peer_description_unset(peer);
718e3744 4589
d62a17ae 4590 return CMD_SUCCESS;
718e3744 4591}
4592
6b0655a2 4593
718e3744 4594/* Neighbor update-source. */
d62a17ae 4595static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4596 const char *source_str)
4597{
4598 struct peer *peer;
4599 struct prefix p;
4600
4601 peer = peer_and_group_lookup_vty(vty, peer_str);
4602 if (!peer)
4603 return CMD_WARNING_CONFIG_FAILED;
4604
4605 if (peer->conf_if)
4606 return CMD_WARNING;
4607
4608 if (source_str) {
4609 union sockunion su;
4610 int ret = str2sockunion(source_str, &su);
4611
4612 if (ret == 0)
4613 peer_update_source_addr_set(peer, &su);
4614 else {
4615 if (str2prefix(source_str, &p)) {
4616 vty_out(vty,
4617 "%% Invalid update-source, remove prefix length \n");
4618 return CMD_WARNING_CONFIG_FAILED;
4619 } else
4620 peer_update_source_if_set(peer, source_str);
4621 }
4622 } else
4623 peer_update_source_unset(peer);
4624
4625 return CMD_SUCCESS;
4626}
4627
4628#define BGP_UPDATE_SOURCE_HELP_STR \
4629 "IPv4 address\n" \
4630 "IPv6 address\n" \
4631 "Interface name (requires zebra to be running)\n"
369688c0 4632
718e3744 4633DEFUN (neighbor_update_source,
4634 neighbor_update_source_cmd,
9ccf14f7 4635 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4636 NEIGHBOR_STR
4637 NEIGHBOR_ADDR_STR2
4638 "Source of routing updates\n"
369688c0 4639 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4640{
d62a17ae 4641 int idx_peer = 1;
4642 int idx_peer_2 = 3;
4643 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4644 argv[idx_peer_2]->arg);
718e3744 4645}
4646
4647DEFUN (no_neighbor_update_source,
4648 no_neighbor_update_source_cmd,
c7178fe7 4649 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4650 NO_STR
4651 NEIGHBOR_STR
4652 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4653 "Source of routing updates\n"
4654 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4655{
d62a17ae 4656 int idx_peer = 2;
4657 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4658}
6b0655a2 4659
d62a17ae 4660static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4661 afi_t afi, safi_t safi,
4662 const char *rmap, int set)
718e3744 4663{
d62a17ae 4664 int ret;
4665 struct peer *peer;
718e3744 4666
d62a17ae 4667 peer = peer_and_group_lookup_vty(vty, peer_str);
4668 if (!peer)
4669 return CMD_WARNING_CONFIG_FAILED;
718e3744 4670
d62a17ae 4671 if (set)
4672 ret = peer_default_originate_set(peer, afi, safi, rmap);
4673 else
4674 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4675
d62a17ae 4676 return bgp_vty_return(vty, ret);
718e3744 4677}
4678
4679/* neighbor default-originate. */
4680DEFUN (neighbor_default_originate,
4681 neighbor_default_originate_cmd,
9ccf14f7 4682 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4683 NEIGHBOR_STR
4684 NEIGHBOR_ADDR_STR2
4685 "Originate default route to this neighbor\n")
4686{
d62a17ae 4687 int idx_peer = 1;
4688 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4689 bgp_node_afi(vty),
4690 bgp_node_safi(vty), NULL, 1);
718e3744 4691}
4692
d62a17ae 4693ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4694 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4695 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4696 "Originate default route to this neighbor\n")
596c17ba 4697
718e3744 4698DEFUN (neighbor_default_originate_rmap,
4699 neighbor_default_originate_rmap_cmd,
9ccf14f7 4700 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4701 NEIGHBOR_STR
4702 NEIGHBOR_ADDR_STR2
4703 "Originate default route to this neighbor\n"
4704 "Route-map to specify criteria to originate default\n"
4705 "route-map name\n")
4706{
d62a17ae 4707 int idx_peer = 1;
4708 int idx_word = 4;
4709 return peer_default_originate_set_vty(
4710 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4711 argv[idx_word]->arg, 1);
718e3744 4712}
4713
d62a17ae 4714ALIAS_HIDDEN(
4715 neighbor_default_originate_rmap,
4716 neighbor_default_originate_rmap_hidden_cmd,
4717 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4718 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4719 "Originate default route to this neighbor\n"
4720 "Route-map to specify criteria to originate default\n"
4721 "route-map name\n")
596c17ba 4722
718e3744 4723DEFUN (no_neighbor_default_originate,
4724 no_neighbor_default_originate_cmd,
a636c635 4725 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4726 NO_STR
4727 NEIGHBOR_STR
4728 NEIGHBOR_ADDR_STR2
a636c635
DW
4729 "Originate default route to this neighbor\n"
4730 "Route-map to specify criteria to originate default\n"
4731 "route-map name\n")
718e3744 4732{
d62a17ae 4733 int idx_peer = 2;
4734 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4735 bgp_node_afi(vty),
4736 bgp_node_safi(vty), NULL, 0);
718e3744 4737}
4738
d62a17ae 4739ALIAS_HIDDEN(
4740 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4741 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4742 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4743 "Originate default route to this neighbor\n"
4744 "Route-map to specify criteria to originate default\n"
4745 "route-map name\n")
596c17ba 4746
6b0655a2 4747
718e3744 4748/* Set neighbor's BGP port. */
d62a17ae 4749static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4750 const char *port_str)
4751{
4752 struct peer *peer;
4753 u_int16_t port;
4754 struct servent *sp;
4755
4756 peer = peer_lookup_vty(vty, ip_str);
4757 if (!peer)
4758 return CMD_WARNING_CONFIG_FAILED;
4759
4760 if (!port_str) {
4761 sp = getservbyname("bgp", "tcp");
4762 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4763 } else {
4764 port = strtoul(port_str, NULL, 10);
4765 }
718e3744 4766
d62a17ae 4767 peer_port_set(peer, port);
718e3744 4768
d62a17ae 4769 return CMD_SUCCESS;
718e3744 4770}
4771
f418446b 4772/* Set specified peer's BGP port. */
718e3744 4773DEFUN (neighbor_port,
4774 neighbor_port_cmd,
9ccf14f7 4775 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4776 NEIGHBOR_STR
4777 NEIGHBOR_ADDR_STR
4778 "Neighbor's BGP port\n"
4779 "TCP port number\n")
4780{
d62a17ae 4781 int idx_ip = 1;
4782 int idx_number = 3;
4783 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4784 argv[idx_number]->arg);
718e3744 4785}
4786
4787DEFUN (no_neighbor_port,
4788 no_neighbor_port_cmd,
9ccf14f7 4789 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4790 NO_STR
4791 NEIGHBOR_STR
4792 NEIGHBOR_ADDR_STR
8334fd5a
DW
4793 "Neighbor's BGP port\n"
4794 "TCP port number\n")
718e3744 4795{
d62a17ae 4796 int idx_ip = 2;
4797 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4798}
4799
6b0655a2 4800
718e3744 4801/* neighbor weight. */
d62a17ae 4802static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4803 safi_t safi, const char *weight_str)
718e3744 4804{
d62a17ae 4805 int ret;
4806 struct peer *peer;
4807 unsigned long weight;
718e3744 4808
d62a17ae 4809 peer = peer_and_group_lookup_vty(vty, ip_str);
4810 if (!peer)
4811 return CMD_WARNING_CONFIG_FAILED;
718e3744 4812
d62a17ae 4813 weight = strtoul(weight_str, NULL, 10);
718e3744 4814
d62a17ae 4815 ret = peer_weight_set(peer, afi, safi, weight);
4816 return bgp_vty_return(vty, ret);
718e3744 4817}
4818
d62a17ae 4819static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4820 safi_t safi)
718e3744 4821{
d62a17ae 4822 int ret;
4823 struct peer *peer;
718e3744 4824
d62a17ae 4825 peer = peer_and_group_lookup_vty(vty, ip_str);
4826 if (!peer)
4827 return CMD_WARNING_CONFIG_FAILED;
718e3744 4828
d62a17ae 4829 ret = peer_weight_unset(peer, afi, safi);
4830 return bgp_vty_return(vty, ret);
718e3744 4831}
4832
4833DEFUN (neighbor_weight,
4834 neighbor_weight_cmd,
9ccf14f7 4835 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4836 NEIGHBOR_STR
4837 NEIGHBOR_ADDR_STR2
4838 "Set default weight for routes from this neighbor\n"
4839 "default weight\n")
4840{
d62a17ae 4841 int idx_peer = 1;
4842 int idx_number = 3;
4843 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4844 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4845}
4846
d62a17ae 4847ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4848 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4849 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4850 "Set default weight for routes from this neighbor\n"
4851 "default weight\n")
596c17ba 4852
718e3744 4853DEFUN (no_neighbor_weight,
4854 no_neighbor_weight_cmd,
9ccf14f7 4855 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4856 NO_STR
4857 NEIGHBOR_STR
4858 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4859 "Set default weight for routes from this neighbor\n"
4860 "default weight\n")
718e3744 4861{
d62a17ae 4862 int idx_peer = 2;
4863 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4864 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4865}
4866
d62a17ae 4867ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4868 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4869 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4870 "Set default weight for routes from this neighbor\n"
4871 "default weight\n")
596c17ba 4872
6b0655a2 4873
718e3744 4874/* Override capability negotiation. */
4875DEFUN (neighbor_override_capability,
4876 neighbor_override_capability_cmd,
9ccf14f7 4877 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4878 NEIGHBOR_STR
4879 NEIGHBOR_ADDR_STR2
4880 "Override capability negotiation result\n")
4881{
d62a17ae 4882 int idx_peer = 1;
4883 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4884 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4885}
4886
4887DEFUN (no_neighbor_override_capability,
4888 no_neighbor_override_capability_cmd,
9ccf14f7 4889 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4890 NO_STR
4891 NEIGHBOR_STR
4892 NEIGHBOR_ADDR_STR2
4893 "Override capability negotiation result\n")
4894{
d62a17ae 4895 int idx_peer = 2;
4896 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4897 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4898}
6b0655a2 4899
718e3744 4900DEFUN (neighbor_strict_capability,
4901 neighbor_strict_capability_cmd,
9ccf14f7 4902 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4903 NEIGHBOR_STR
4904 NEIGHBOR_ADDR_STR
4905 "Strict capability negotiation match\n")
4906{
d62a17ae 4907 int idx_ip = 1;
4908 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4909 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4910}
4911
4912DEFUN (no_neighbor_strict_capability,
4913 no_neighbor_strict_capability_cmd,
9ccf14f7 4914 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4915 NO_STR
4916 NEIGHBOR_STR
4917 NEIGHBOR_ADDR_STR
4918 "Strict capability negotiation match\n")
4919{
d62a17ae 4920 int idx_ip = 2;
4921 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4922 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4923}
6b0655a2 4924
d62a17ae 4925static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4926 const char *keep_str, const char *hold_str)
718e3744 4927{
d62a17ae 4928 int ret;
4929 struct peer *peer;
4930 u_int32_t keepalive;
4931 u_int32_t holdtime;
718e3744 4932
d62a17ae 4933 peer = peer_and_group_lookup_vty(vty, ip_str);
4934 if (!peer)
4935 return CMD_WARNING_CONFIG_FAILED;
718e3744 4936
d62a17ae 4937 keepalive = strtoul(keep_str, NULL, 10);
4938 holdtime = strtoul(hold_str, NULL, 10);
718e3744 4939
d62a17ae 4940 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 4941
d62a17ae 4942 return bgp_vty_return(vty, ret);
718e3744 4943}
6b0655a2 4944
d62a17ae 4945static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4946{
d62a17ae 4947 int ret;
4948 struct peer *peer;
718e3744 4949
d62a17ae 4950 peer = peer_and_group_lookup_vty(vty, ip_str);
4951 if (!peer)
4952 return CMD_WARNING_CONFIG_FAILED;
718e3744 4953
d62a17ae 4954 ret = peer_timers_unset(peer);
718e3744 4955
d62a17ae 4956 return bgp_vty_return(vty, ret);
718e3744 4957}
4958
4959DEFUN (neighbor_timers,
4960 neighbor_timers_cmd,
9ccf14f7 4961 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 4962 NEIGHBOR_STR
4963 NEIGHBOR_ADDR_STR2
4964 "BGP per neighbor timers\n"
4965 "Keepalive interval\n"
4966 "Holdtime\n")
4967{
d62a17ae 4968 int idx_peer = 1;
4969 int idx_number = 3;
4970 int idx_number_2 = 4;
4971 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4972 argv[idx_number]->arg,
4973 argv[idx_number_2]->arg);
718e3744 4974}
4975
4976DEFUN (no_neighbor_timers,
4977 no_neighbor_timers_cmd,
9ccf14f7 4978 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 4979 NO_STR
4980 NEIGHBOR_STR
4981 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4982 "BGP per neighbor timers\n"
4983 "Keepalive interval\n"
4984 "Holdtime\n")
718e3744 4985{
d62a17ae 4986 int idx_peer = 2;
4987 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4988}
6b0655a2 4989
813d4307 4990
d62a17ae 4991static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
4992 const char *time_str)
718e3744 4993{
d62a17ae 4994 int ret;
4995 struct peer *peer;
4996 u_int32_t connect;
718e3744 4997
d62a17ae 4998 peer = peer_and_group_lookup_vty(vty, ip_str);
4999 if (!peer)
5000 return CMD_WARNING_CONFIG_FAILED;
718e3744 5001
d62a17ae 5002 connect = strtoul(time_str, NULL, 10);
718e3744 5003
d62a17ae 5004 ret = peer_timers_connect_set(peer, connect);
718e3744 5005
d62a17ae 5006 return bgp_vty_return(vty, ret);
718e3744 5007}
5008
d62a17ae 5009static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5010{
d62a17ae 5011 int ret;
5012 struct peer *peer;
718e3744 5013
d62a17ae 5014 peer = peer_and_group_lookup_vty(vty, ip_str);
5015 if (!peer)
5016 return CMD_WARNING_CONFIG_FAILED;
718e3744 5017
d62a17ae 5018 ret = peer_timers_connect_unset(peer);
718e3744 5019
d62a17ae 5020 return bgp_vty_return(vty, ret);
718e3744 5021}
5022
5023DEFUN (neighbor_timers_connect,
5024 neighbor_timers_connect_cmd,
9ccf14f7 5025 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5026 NEIGHBOR_STR
966f821c 5027 NEIGHBOR_ADDR_STR2
718e3744 5028 "BGP per neighbor timers\n"
5029 "BGP connect timer\n"
5030 "Connect timer\n")
5031{
d62a17ae 5032 int idx_peer = 1;
5033 int idx_number = 4;
5034 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5035 argv[idx_number]->arg);
718e3744 5036}
5037
5038DEFUN (no_neighbor_timers_connect,
5039 no_neighbor_timers_connect_cmd,
9ccf14f7 5040 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5041 NO_STR
5042 NEIGHBOR_STR
966f821c 5043 NEIGHBOR_ADDR_STR2
718e3744 5044 "BGP per neighbor timers\n"
8334fd5a
DW
5045 "BGP connect timer\n"
5046 "Connect timer\n")
718e3744 5047{
d62a17ae 5048 int idx_peer = 2;
5049 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5050}
5051
6b0655a2 5052
d62a17ae 5053static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5054 const char *time_str, int set)
718e3744 5055{
d62a17ae 5056 int ret;
5057 struct peer *peer;
5058 u_int32_t routeadv = 0;
718e3744 5059
d62a17ae 5060 peer = peer_and_group_lookup_vty(vty, ip_str);
5061 if (!peer)
5062 return CMD_WARNING_CONFIG_FAILED;
718e3744 5063
d62a17ae 5064 if (time_str)
5065 routeadv = strtoul(time_str, NULL, 10);
718e3744 5066
d62a17ae 5067 if (set)
5068 ret = peer_advertise_interval_set(peer, routeadv);
5069 else
5070 ret = peer_advertise_interval_unset(peer);
718e3744 5071
d62a17ae 5072 return bgp_vty_return(vty, ret);
718e3744 5073}
5074
5075DEFUN (neighbor_advertise_interval,
5076 neighbor_advertise_interval_cmd,
9ccf14f7 5077 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5078 NEIGHBOR_STR
966f821c 5079 NEIGHBOR_ADDR_STR2
718e3744 5080 "Minimum interval between sending BGP routing updates\n"
5081 "time in seconds\n")
5082{
d62a17ae 5083 int idx_peer = 1;
5084 int idx_number = 3;
5085 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5086 argv[idx_number]->arg, 1);
718e3744 5087}
5088
5089DEFUN (no_neighbor_advertise_interval,
5090 no_neighbor_advertise_interval_cmd,
9ccf14f7 5091 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5092 NO_STR
5093 NEIGHBOR_STR
966f821c 5094 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5095 "Minimum interval between sending BGP routing updates\n"
5096 "time in seconds\n")
718e3744 5097{
d62a17ae 5098 int idx_peer = 2;
5099 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5100}
5101
6b0655a2 5102
518f0eb1
DS
5103/* Time to wait before processing route-map updates */
5104DEFUN (bgp_set_route_map_delay_timer,
5105 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5106 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5107 SET_STR
5108 "BGP route-map delay timer\n"
5109 "Time in secs to wait before processing route-map changes\n"
f414725f 5110 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5111{
d62a17ae 5112 int idx_number = 3;
5113 u_int32_t rmap_delay_timer;
5114
5115 if (argv[idx_number]->arg) {
5116 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5117 bm->rmap_update_timer = rmap_delay_timer;
5118
5119 /* if the dynamic update handling is being disabled, and a timer
5120 * is
5121 * running, stop the timer and act as if the timer has already
5122 * fired.
5123 */
5124 if (!rmap_delay_timer && bm->t_rmap_update) {
5125 BGP_TIMER_OFF(bm->t_rmap_update);
5126 thread_execute(bm->master, bgp_route_map_update_timer,
5127 NULL, 0);
5128 }
5129 return CMD_SUCCESS;
5130 } else {
5131 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5132 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5133 }
518f0eb1
DS
5134}
5135
5136DEFUN (no_bgp_set_route_map_delay_timer,
5137 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5138 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5139 NO_STR
3a2d747c 5140 BGP_STR
518f0eb1 5141 "Default BGP route-map delay timer\n"
8334fd5a
DW
5142 "Reset to default time to wait for processing route-map changes\n"
5143 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5144{
518f0eb1 5145
d62a17ae 5146 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5147
d62a17ae 5148 return CMD_SUCCESS;
518f0eb1
DS
5149}
5150
f414725f 5151
718e3744 5152/* neighbor interface */
d62a17ae 5153static int peer_interface_vty(struct vty *vty, const char *ip_str,
5154 const char *str)
718e3744 5155{
d62a17ae 5156 struct peer *peer;
718e3744 5157
d62a17ae 5158 peer = peer_lookup_vty(vty, ip_str);
5159 if (!peer || peer->conf_if) {
5160 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5161 return CMD_WARNING_CONFIG_FAILED;
5162 }
718e3744 5163
d62a17ae 5164 if (str)
5165 peer_interface_set(peer, str);
5166 else
5167 peer_interface_unset(peer);
718e3744 5168
d62a17ae 5169 return CMD_SUCCESS;
718e3744 5170}
5171
5172DEFUN (neighbor_interface,
5173 neighbor_interface_cmd,
9ccf14f7 5174 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5175 NEIGHBOR_STR
5176 NEIGHBOR_ADDR_STR
5177 "Interface\n"
5178 "Interface name\n")
5179{
d62a17ae 5180 int idx_ip = 1;
5181 int idx_word = 3;
5182 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5183}
5184
5185DEFUN (no_neighbor_interface,
5186 no_neighbor_interface_cmd,
9ccf14f7 5187 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5188 NO_STR
5189 NEIGHBOR_STR
16cedbb0 5190 NEIGHBOR_ADDR_STR2
718e3744 5191 "Interface\n"
5192 "Interface name\n")
5193{
d62a17ae 5194 int idx_peer = 2;
5195 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5196}
6b0655a2 5197
718e3744 5198DEFUN (neighbor_distribute_list,
5199 neighbor_distribute_list_cmd,
9ccf14f7 5200 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5201 NEIGHBOR_STR
5202 NEIGHBOR_ADDR_STR2
5203 "Filter updates to/from this neighbor\n"
5204 "IP access-list number\n"
5205 "IP access-list number (expanded range)\n"
5206 "IP Access-list name\n"
5207 "Filter incoming updates\n"
5208 "Filter outgoing updates\n")
5209{
d62a17ae 5210 int idx_peer = 1;
5211 int idx_acl = 3;
5212 int direct, ret;
5213 struct peer *peer;
a8206004 5214
d62a17ae 5215 const char *pstr = argv[idx_peer]->arg;
5216 const char *acl = argv[idx_acl]->arg;
5217 const char *inout = argv[argc - 1]->text;
a8206004 5218
d62a17ae 5219 peer = peer_and_group_lookup_vty(vty, pstr);
5220 if (!peer)
5221 return CMD_WARNING_CONFIG_FAILED;
a8206004 5222
d62a17ae 5223 /* Check filter direction. */
5224 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5225 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5226 direct, acl);
a8206004 5227
d62a17ae 5228 return bgp_vty_return(vty, ret);
718e3744 5229}
5230
d62a17ae 5231ALIAS_HIDDEN(
5232 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5233 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5234 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5235 "Filter updates to/from this neighbor\n"
5236 "IP access-list number\n"
5237 "IP access-list number (expanded range)\n"
5238 "IP Access-list name\n"
5239 "Filter incoming updates\n"
5240 "Filter outgoing updates\n")
596c17ba 5241
718e3744 5242DEFUN (no_neighbor_distribute_list,
5243 no_neighbor_distribute_list_cmd,
9ccf14f7 5244 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5245 NO_STR
5246 NEIGHBOR_STR
5247 NEIGHBOR_ADDR_STR2
5248 "Filter updates to/from this neighbor\n"
5249 "IP access-list number\n"
5250 "IP access-list number (expanded range)\n"
5251 "IP Access-list name\n"
5252 "Filter incoming updates\n"
5253 "Filter outgoing updates\n")
5254{
d62a17ae 5255 int idx_peer = 2;
5256 int direct, ret;
5257 struct peer *peer;
a8206004 5258
d62a17ae 5259 const char *pstr = argv[idx_peer]->arg;
5260 const char *inout = argv[argc - 1]->text;
a8206004 5261
d62a17ae 5262 peer = peer_and_group_lookup_vty(vty, pstr);
5263 if (!peer)
5264 return CMD_WARNING_CONFIG_FAILED;
a8206004 5265
d62a17ae 5266 /* Check filter direction. */
5267 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5268 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5269 direct);
a8206004 5270
d62a17ae 5271 return bgp_vty_return(vty, ret);
718e3744 5272}
6b0655a2 5273
d62a17ae 5274ALIAS_HIDDEN(
5275 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5276 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5277 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5278 "Filter updates to/from this neighbor\n"
5279 "IP access-list number\n"
5280 "IP access-list number (expanded range)\n"
5281 "IP Access-list name\n"
5282 "Filter incoming updates\n"
5283 "Filter outgoing updates\n")
596c17ba 5284
718e3744 5285/* Set prefix list to the peer. */
d62a17ae 5286static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5287 afi_t afi, safi_t safi,
5288 const char *name_str,
5289 const char *direct_str)
718e3744 5290{
d62a17ae 5291 int ret;
5292 struct peer *peer;
5293 int direct = FILTER_IN;
718e3744 5294
d62a17ae 5295 peer = peer_and_group_lookup_vty(vty, ip_str);
5296 if (!peer)
5297 return CMD_WARNING_CONFIG_FAILED;
718e3744 5298
d62a17ae 5299 /* Check filter direction. */
5300 if (strncmp(direct_str, "i", 1) == 0)
5301 direct = FILTER_IN;
5302 else if (strncmp(direct_str, "o", 1) == 0)
5303 direct = FILTER_OUT;
718e3744 5304
d62a17ae 5305 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5306
d62a17ae 5307 return bgp_vty_return(vty, ret);
718e3744 5308}
5309
d62a17ae 5310static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5311 afi_t afi, safi_t safi,
5312 const char *direct_str)
718e3744 5313{
d62a17ae 5314 int ret;
5315 struct peer *peer;
5316 int direct = FILTER_IN;
718e3744 5317
d62a17ae 5318 peer = peer_and_group_lookup_vty(vty, ip_str);
5319 if (!peer)
5320 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5321
d62a17ae 5322 /* Check filter direction. */
5323 if (strncmp(direct_str, "i", 1) == 0)
5324 direct = FILTER_IN;
5325 else if (strncmp(direct_str, "o", 1) == 0)
5326 direct = FILTER_OUT;
718e3744 5327
d62a17ae 5328 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5329
d62a17ae 5330 return bgp_vty_return(vty, ret);
718e3744 5331}
5332
5333DEFUN (neighbor_prefix_list,
5334 neighbor_prefix_list_cmd,
9ccf14f7 5335 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5336 NEIGHBOR_STR
5337 NEIGHBOR_ADDR_STR2
5338 "Filter updates to/from this neighbor\n"
5339 "Name of a prefix list\n"
5340 "Filter incoming updates\n"
5341 "Filter outgoing updates\n")
5342{
d62a17ae 5343 int idx_peer = 1;
5344 int idx_word = 3;
5345 int idx_in_out = 4;
5346 return peer_prefix_list_set_vty(
5347 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5348 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5349}
5350
d62a17ae 5351ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5352 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5353 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5354 "Filter updates to/from this neighbor\n"
5355 "Name of a prefix list\n"
5356 "Filter incoming updates\n"
5357 "Filter outgoing updates\n")
596c17ba 5358
718e3744 5359DEFUN (no_neighbor_prefix_list,
5360 no_neighbor_prefix_list_cmd,
9ccf14f7 5361 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5362 NO_STR
5363 NEIGHBOR_STR
5364 NEIGHBOR_ADDR_STR2
5365 "Filter updates to/from this neighbor\n"
5366 "Name of a prefix list\n"
5367 "Filter incoming updates\n"
5368 "Filter outgoing updates\n")
5369{
d62a17ae 5370 int idx_peer = 2;
5371 int idx_in_out = 5;
5372 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5373 bgp_node_afi(vty), bgp_node_safi(vty),
5374 argv[idx_in_out]->arg);
718e3744 5375}
6b0655a2 5376
d62a17ae 5377ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5378 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5379 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5380 "Filter updates to/from this neighbor\n"
5381 "Name of a prefix list\n"
5382 "Filter incoming updates\n"
5383 "Filter outgoing updates\n")
596c17ba 5384
d62a17ae 5385static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5386 safi_t safi, const char *name_str,
5387 const char *direct_str)
718e3744 5388{
d62a17ae 5389 int ret;
5390 struct peer *peer;
5391 int direct = FILTER_IN;
718e3744 5392
d62a17ae 5393 peer = peer_and_group_lookup_vty(vty, ip_str);
5394 if (!peer)
5395 return CMD_WARNING_CONFIG_FAILED;
718e3744 5396
d62a17ae 5397 /* Check filter direction. */
5398 if (strncmp(direct_str, "i", 1) == 0)
5399 direct = FILTER_IN;
5400 else if (strncmp(direct_str, "o", 1) == 0)
5401 direct = FILTER_OUT;
718e3744 5402
d62a17ae 5403 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5404
d62a17ae 5405 return bgp_vty_return(vty, ret);
718e3744 5406}
5407
d62a17ae 5408static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5409 safi_t safi, const char *direct_str)
718e3744 5410{
d62a17ae 5411 int ret;
5412 struct peer *peer;
5413 int direct = FILTER_IN;
718e3744 5414
d62a17ae 5415 peer = peer_and_group_lookup_vty(vty, ip_str);
5416 if (!peer)
5417 return CMD_WARNING_CONFIG_FAILED;
718e3744 5418
d62a17ae 5419 /* Check filter direction. */
5420 if (strncmp(direct_str, "i", 1) == 0)
5421 direct = FILTER_IN;
5422 else if (strncmp(direct_str, "o", 1) == 0)
5423 direct = FILTER_OUT;
718e3744 5424
d62a17ae 5425 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5426
d62a17ae 5427 return bgp_vty_return(vty, ret);
718e3744 5428}
5429
5430DEFUN (neighbor_filter_list,
5431 neighbor_filter_list_cmd,
9ccf14f7 5432 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5433 NEIGHBOR_STR
5434 NEIGHBOR_ADDR_STR2
5435 "Establish BGP filters\n"
5436 "AS path access-list name\n"
5437 "Filter incoming routes\n"
5438 "Filter outgoing routes\n")
5439{
d62a17ae 5440 int idx_peer = 1;
5441 int idx_word = 3;
5442 int idx_in_out = 4;
5443 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5444 bgp_node_safi(vty), argv[idx_word]->arg,
5445 argv[idx_in_out]->arg);
718e3744 5446}
5447
d62a17ae 5448ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5449 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5450 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5451 "Establish BGP filters\n"
5452 "AS path access-list name\n"
5453 "Filter incoming routes\n"
5454 "Filter outgoing routes\n")
596c17ba 5455
718e3744 5456DEFUN (no_neighbor_filter_list,
5457 no_neighbor_filter_list_cmd,
9ccf14f7 5458 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5459 NO_STR
5460 NEIGHBOR_STR
5461 NEIGHBOR_ADDR_STR2
5462 "Establish BGP filters\n"
5463 "AS path access-list name\n"
5464 "Filter incoming routes\n"
5465 "Filter outgoing routes\n")
5466{
d62a17ae 5467 int idx_peer = 2;
5468 int idx_in_out = 5;
5469 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5470 bgp_node_afi(vty), bgp_node_safi(vty),
5471 argv[idx_in_out]->arg);
718e3744 5472}
6b0655a2 5473
d62a17ae 5474ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5475 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5476 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5477 "Establish BGP filters\n"
5478 "AS path access-list name\n"
5479 "Filter incoming routes\n"
5480 "Filter outgoing routes\n")
596c17ba 5481
718e3744 5482/* Set route-map to the peer. */
d62a17ae 5483static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5484 afi_t afi, safi_t safi, const char *name_str,
5485 const char *direct_str)
718e3744 5486{
d62a17ae 5487 int ret;
5488 struct peer *peer;
5489 int direct = RMAP_IN;
718e3744 5490
d62a17ae 5491 peer = peer_and_group_lookup_vty(vty, ip_str);
5492 if (!peer)
5493 return CMD_WARNING_CONFIG_FAILED;
718e3744 5494
d62a17ae 5495 /* Check filter direction. */
5496 if (strncmp(direct_str, "in", 2) == 0)
5497 direct = RMAP_IN;
5498 else if (strncmp(direct_str, "o", 1) == 0)
5499 direct = RMAP_OUT;
718e3744 5500
d62a17ae 5501 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5502
d62a17ae 5503 return bgp_vty_return(vty, ret);
718e3744 5504}
5505
d62a17ae 5506static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5507 afi_t afi, safi_t safi,
5508 const char *direct_str)
718e3744 5509{
d62a17ae 5510 int ret;
5511 struct peer *peer;
5512 int direct = RMAP_IN;
718e3744 5513
d62a17ae 5514 peer = peer_and_group_lookup_vty(vty, ip_str);
5515 if (!peer)
5516 return CMD_WARNING_CONFIG_FAILED;
718e3744 5517
d62a17ae 5518 /* Check filter direction. */
5519 if (strncmp(direct_str, "in", 2) == 0)
5520 direct = RMAP_IN;
5521 else if (strncmp(direct_str, "o", 1) == 0)
5522 direct = RMAP_OUT;
718e3744 5523
d62a17ae 5524 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5525
d62a17ae 5526 return bgp_vty_return(vty, ret);
718e3744 5527}
5528
5529DEFUN (neighbor_route_map,
5530 neighbor_route_map_cmd,
9ccf14f7 5531 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5532 NEIGHBOR_STR
5533 NEIGHBOR_ADDR_STR2
5534 "Apply route map to neighbor\n"
5535 "Name of route map\n"
5536 "Apply map to incoming routes\n"
2a3d5731 5537 "Apply map to outbound routes\n")
718e3744 5538{
d62a17ae 5539 int idx_peer = 1;
5540 int idx_word = 3;
5541 int idx_in_out = 4;
5542 return peer_route_map_set_vty(
5543 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5544 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5545}
5546
d62a17ae 5547ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5548 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5549 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5550 "Apply route map to neighbor\n"
5551 "Name of route map\n"
5552 "Apply map to incoming routes\n"
5553 "Apply map to outbound routes\n")
596c17ba 5554
718e3744 5555DEFUN (no_neighbor_route_map,
5556 no_neighbor_route_map_cmd,
9ccf14f7 5557 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5558 NO_STR
5559 NEIGHBOR_STR
5560 NEIGHBOR_ADDR_STR2
5561 "Apply route map to neighbor\n"
5562 "Name of route map\n"
5563 "Apply map to incoming routes\n"
2a3d5731 5564 "Apply map to outbound routes\n")
718e3744 5565{
d62a17ae 5566 int idx_peer = 2;
5567 int idx_in_out = 5;
5568 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5569 bgp_node_afi(vty), bgp_node_safi(vty),
5570 argv[idx_in_out]->arg);
718e3744 5571}
6b0655a2 5572
d62a17ae 5573ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5574 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5575 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5576 "Apply route map to neighbor\n"
5577 "Name of route map\n"
5578 "Apply map to incoming routes\n"
5579 "Apply map to outbound routes\n")
596c17ba 5580
718e3744 5581/* Set unsuppress-map to the peer. */
d62a17ae 5582static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5583 afi_t afi, safi_t safi,
5584 const char *name_str)
718e3744 5585{
d62a17ae 5586 int ret;
5587 struct peer *peer;
718e3744 5588
d62a17ae 5589 peer = peer_and_group_lookup_vty(vty, ip_str);
5590 if (!peer)
5591 return CMD_WARNING_CONFIG_FAILED;
718e3744 5592
d62a17ae 5593 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5594
d62a17ae 5595 return bgp_vty_return(vty, ret);
718e3744 5596}
5597
5598/* Unset route-map from the peer. */
d62a17ae 5599static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5600 afi_t afi, safi_t safi)
718e3744 5601{
d62a17ae 5602 int ret;
5603 struct peer *peer;
718e3744 5604
d62a17ae 5605 peer = peer_and_group_lookup_vty(vty, ip_str);
5606 if (!peer)
5607 return CMD_WARNING_CONFIG_FAILED;
718e3744 5608
d62a17ae 5609 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5610
d62a17ae 5611 return bgp_vty_return(vty, ret);
718e3744 5612}
5613
5614DEFUN (neighbor_unsuppress_map,
5615 neighbor_unsuppress_map_cmd,
9ccf14f7 5616 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5617 NEIGHBOR_STR
5618 NEIGHBOR_ADDR_STR2
5619 "Route-map to selectively unsuppress suppressed routes\n"
5620 "Name of route map\n")
5621{
d62a17ae 5622 int idx_peer = 1;
5623 int idx_word = 3;
5624 return peer_unsuppress_map_set_vty(
5625 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5626 argv[idx_word]->arg);
718e3744 5627}
5628
d62a17ae 5629ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5630 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5631 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5632 "Route-map to selectively unsuppress suppressed routes\n"
5633 "Name of route map\n")
596c17ba 5634
718e3744 5635DEFUN (no_neighbor_unsuppress_map,
5636 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5637 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5638 NO_STR
5639 NEIGHBOR_STR
5640 NEIGHBOR_ADDR_STR2
5641 "Route-map to selectively unsuppress suppressed routes\n"
5642 "Name of route map\n")
5643{
d62a17ae 5644 int idx_peer = 2;
5645 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5646 bgp_node_afi(vty),
5647 bgp_node_safi(vty));
718e3744 5648}
6b0655a2 5649
d62a17ae 5650ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5651 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5652 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5653 "Route-map to selectively unsuppress suppressed routes\n"
5654 "Name of route map\n")
596c17ba 5655
d62a17ae 5656static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5657 afi_t afi, safi_t safi,
5658 const char *num_str,
5659 const char *threshold_str, int warning,
5660 const char *restart_str)
718e3744 5661{
d62a17ae 5662 int ret;
5663 struct peer *peer;
5664 u_int32_t max;
5665 u_char threshold;
5666 u_int16_t restart;
718e3744 5667
d62a17ae 5668 peer = peer_and_group_lookup_vty(vty, ip_str);
5669 if (!peer)
5670 return CMD_WARNING_CONFIG_FAILED;
718e3744 5671
d62a17ae 5672 max = strtoul(num_str, NULL, 10);
5673 if (threshold_str)
5674 threshold = atoi(threshold_str);
5675 else
5676 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5677
d62a17ae 5678 if (restart_str)
5679 restart = atoi(restart_str);
5680 else
5681 restart = 0;
0a486e5f 5682
d62a17ae 5683 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5684 restart);
718e3744 5685
d62a17ae 5686 return bgp_vty_return(vty, ret);
718e3744 5687}
5688
d62a17ae 5689static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5690 afi_t afi, safi_t safi)
718e3744 5691{
d62a17ae 5692 int ret;
5693 struct peer *peer;
718e3744 5694
d62a17ae 5695 peer = peer_and_group_lookup_vty(vty, ip_str);
5696 if (!peer)
5697 return CMD_WARNING_CONFIG_FAILED;
718e3744 5698
d62a17ae 5699 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5700
d62a17ae 5701 return bgp_vty_return(vty, ret);
718e3744 5702}
5703
5704/* Maximum number of prefix configuration. prefix count is different
5705 for each peer configuration. So this configuration can be set for
5706 each peer configuration. */
5707DEFUN (neighbor_maximum_prefix,
5708 neighbor_maximum_prefix_cmd,
9ccf14f7 5709 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5710 NEIGHBOR_STR
5711 NEIGHBOR_ADDR_STR2
5712 "Maximum number of prefix accept from this peer\n"
5713 "maximum no. of prefix limit\n")
5714{
d62a17ae 5715 int idx_peer = 1;
5716 int idx_number = 3;
5717 return peer_maximum_prefix_set_vty(
5718 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5719 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5720}
5721
d62a17ae 5722ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5723 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5724 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5725 "Maximum number of prefix accept from this peer\n"
5726 "maximum no. of prefix limit\n")
596c17ba 5727
e0701b79 5728DEFUN (neighbor_maximum_prefix_threshold,
5729 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5730 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5731 NEIGHBOR_STR
5732 NEIGHBOR_ADDR_STR2
5733 "Maximum number of prefix accept from this peer\n"
5734 "maximum no. of prefix limit\n"
5735 "Threshold value (%) at which to generate a warning msg\n")
5736{
d62a17ae 5737 int idx_peer = 1;
5738 int idx_number = 3;
5739 int idx_number_2 = 4;
5740 return peer_maximum_prefix_set_vty(
5741 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5742 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5743}
e0701b79 5744
d62a17ae 5745ALIAS_HIDDEN(
5746 neighbor_maximum_prefix_threshold,
5747 neighbor_maximum_prefix_threshold_hidden_cmd,
5748 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5749 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5750 "Maximum number of prefix accept from this peer\n"
5751 "maximum no. of prefix limit\n"
5752 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5753
718e3744 5754DEFUN (neighbor_maximum_prefix_warning,
5755 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5756 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5757 NEIGHBOR_STR
5758 NEIGHBOR_ADDR_STR2
5759 "Maximum number of prefix accept from this peer\n"
5760 "maximum no. of prefix limit\n"
5761 "Only give warning message when limit is exceeded\n")
5762{
d62a17ae 5763 int idx_peer = 1;
5764 int idx_number = 3;
5765 return peer_maximum_prefix_set_vty(
5766 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5767 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5768}
5769
d62a17ae 5770ALIAS_HIDDEN(
5771 neighbor_maximum_prefix_warning,
5772 neighbor_maximum_prefix_warning_hidden_cmd,
5773 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5774 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5775 "Maximum number of prefix accept from this peer\n"
5776 "maximum no. of prefix limit\n"
5777 "Only give warning message when limit is exceeded\n")
596c17ba 5778
e0701b79 5779DEFUN (neighbor_maximum_prefix_threshold_warning,
5780 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5781 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5782 NEIGHBOR_STR
5783 NEIGHBOR_ADDR_STR2
5784 "Maximum number of prefix accept from this peer\n"
5785 "maximum no. of prefix limit\n"
5786 "Threshold value (%) at which to generate a warning msg\n"
5787 "Only give warning message when limit is exceeded\n")
5788{
d62a17ae 5789 int idx_peer = 1;
5790 int idx_number = 3;
5791 int idx_number_2 = 4;
5792 return peer_maximum_prefix_set_vty(
5793 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5794 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5795}
5796
d62a17ae 5797ALIAS_HIDDEN(
5798 neighbor_maximum_prefix_threshold_warning,
5799 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5800 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5801 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5802 "Maximum number of prefix accept from this peer\n"
5803 "maximum no. of prefix limit\n"
5804 "Threshold value (%) at which to generate a warning msg\n"
5805 "Only give warning message when limit is exceeded\n")
596c17ba 5806
0a486e5f 5807DEFUN (neighbor_maximum_prefix_restart,
5808 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5809 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5810 NEIGHBOR_STR
5811 NEIGHBOR_ADDR_STR2
5812 "Maximum number of prefix accept from this peer\n"
5813 "maximum no. of prefix limit\n"
5814 "Restart bgp connection after limit is exceeded\n"
efd7904e 5815 "Restart interval in minutes\n")
0a486e5f 5816{
d62a17ae 5817 int idx_peer = 1;
5818 int idx_number = 3;
5819 int idx_number_2 = 5;
5820 return peer_maximum_prefix_set_vty(
5821 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5822 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5823}
5824
d62a17ae 5825ALIAS_HIDDEN(
5826 neighbor_maximum_prefix_restart,
5827 neighbor_maximum_prefix_restart_hidden_cmd,
5828 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5829 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5830 "Maximum number of prefix accept from this peer\n"
5831 "maximum no. of prefix limit\n"
5832 "Restart bgp connection after limit is exceeded\n"
efd7904e 5833 "Restart interval in minutes\n")
596c17ba 5834
0a486e5f 5835DEFUN (neighbor_maximum_prefix_threshold_restart,
5836 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5837 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5838 NEIGHBOR_STR
5839 NEIGHBOR_ADDR_STR2
16cedbb0 5840 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5841 "maximum no. of prefix limit\n"
5842 "Threshold value (%) at which to generate a warning msg\n"
5843 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5844 "Restart interval in minutes\n")
0a486e5f 5845{
d62a17ae 5846 int idx_peer = 1;
5847 int idx_number = 3;
5848 int idx_number_2 = 4;
5849 int idx_number_3 = 6;
5850 return peer_maximum_prefix_set_vty(
5851 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5852 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5853 argv[idx_number_3]->arg);
5854}
5855
5856ALIAS_HIDDEN(
5857 neighbor_maximum_prefix_threshold_restart,
5858 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5859 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5860 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5861 "Maximum number of prefixes to accept from this peer\n"
5862 "maximum no. of prefix limit\n"
5863 "Threshold value (%) at which to generate a warning msg\n"
5864 "Restart bgp connection after limit is exceeded\n"
5865 "Restart interval in minutes\n")
596c17ba 5866
718e3744 5867DEFUN (no_neighbor_maximum_prefix,
5868 no_neighbor_maximum_prefix_cmd,
d04c479d 5869 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5870 NO_STR
5871 NEIGHBOR_STR
5872 NEIGHBOR_ADDR_STR2
16cedbb0 5873 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5874 "maximum no. of prefix limit\n"
5875 "Threshold value (%) at which to generate a warning msg\n"
5876 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5877 "Restart interval in minutes\n"
31500417 5878 "Only give warning message when limit is exceeded\n")
718e3744 5879{
d62a17ae 5880 int idx_peer = 2;
5881 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5882 bgp_node_afi(vty),
5883 bgp_node_safi(vty));
718e3744 5884}
e52702f2 5885
d62a17ae 5886ALIAS_HIDDEN(
5887 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5888 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5889 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5890 "Maximum number of prefixes to accept from this peer\n"
5891 "maximum no. of prefix limit\n"
5892 "Threshold value (%) at which to generate a warning msg\n"
5893 "Restart bgp connection after limit is exceeded\n"
5894 "Restart interval in minutes\n"
5895 "Only give warning message when limit is exceeded\n")
596c17ba 5896
718e3744 5897
718e3744 5898/* "neighbor allowas-in" */
5899DEFUN (neighbor_allowas_in,
5900 neighbor_allowas_in_cmd,
fd8503f5 5901 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5902 NEIGHBOR_STR
5903 NEIGHBOR_ADDR_STR2
31500417 5904 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5905 "Number of occurances of AS number\n"
5906 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5907{
d62a17ae 5908 int idx_peer = 1;
5909 int idx_number_origin = 3;
5910 int ret;
5911 int origin = 0;
5912 struct peer *peer;
5913 int allow_num = 0;
5914
5915 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5916 if (!peer)
5917 return CMD_WARNING_CONFIG_FAILED;
5918
5919 if (argc <= idx_number_origin)
5920 allow_num = 3;
5921 else {
5922 if (argv[idx_number_origin]->type == WORD_TKN)
5923 origin = 1;
5924 else
5925 allow_num = atoi(argv[idx_number_origin]->arg);
5926 }
5927
5928 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5929 allow_num, origin);
5930
5931 return bgp_vty_return(vty, ret);
5932}
5933
5934ALIAS_HIDDEN(
5935 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5936 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5937 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5938 "Accept as-path with my AS present in it\n"
5939 "Number of occurances of AS number\n"
5940 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5941
718e3744 5942DEFUN (no_neighbor_allowas_in,
5943 no_neighbor_allowas_in_cmd,
fd8503f5 5944 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5945 NO_STR
5946 NEIGHBOR_STR
5947 NEIGHBOR_ADDR_STR2
8334fd5a 5948 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
5949 "Number of occurances of AS number\n"
5950 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5951{
d62a17ae 5952 int idx_peer = 2;
5953 int ret;
5954 struct peer *peer;
718e3744 5955
d62a17ae 5956 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5957 if (!peer)
5958 return CMD_WARNING_CONFIG_FAILED;
718e3744 5959
d62a17ae 5960 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5961 bgp_node_safi(vty));
718e3744 5962
d62a17ae 5963 return bgp_vty_return(vty, ret);
718e3744 5964}
6b0655a2 5965
d62a17ae 5966ALIAS_HIDDEN(
5967 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5968 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5969 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5970 "allow local ASN appears in aspath attribute\n"
5971 "Number of occurances of AS number\n"
5972 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5973
fa411a21
NH
5974DEFUN (neighbor_ttl_security,
5975 neighbor_ttl_security_cmd,
7ebe625c 5976 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 5977 NEIGHBOR_STR
7ebe625c 5978 NEIGHBOR_ADDR_STR2
16cedbb0 5979 "BGP ttl-security parameters\n"
d7fa34c1
QY
5980 "Specify the maximum number of hops to the BGP peer\n"
5981 "Number of hops to BGP peer\n")
fa411a21 5982{
d62a17ae 5983 int idx_peer = 1;
5984 int idx_number = 4;
5985 struct peer *peer;
5986 int gtsm_hops;
5987
5988 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5989 if (!peer)
5990 return CMD_WARNING_CONFIG_FAILED;
5991
5992 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
5993
7ebe625c
QY
5994 /*
5995 * If 'neighbor swpX', then this is for directly connected peers,
5996 * we should not accept a ttl-security hops value greater than 1.
5997 */
5998 if (peer->conf_if && (gtsm_hops > 1)) {
5999 vty_out(vty,
6000 "%s is directly connected peer, hops cannot exceed 1\n",
6001 argv[idx_peer]->arg);
6002 return CMD_WARNING_CONFIG_FAILED;
6003 }
6004
d62a17ae 6005 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6006}
6007
6008DEFUN (no_neighbor_ttl_security,
6009 no_neighbor_ttl_security_cmd,
7ebe625c 6010 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6011 NO_STR
6012 NEIGHBOR_STR
7ebe625c 6013 NEIGHBOR_ADDR_STR2
16cedbb0 6014 "BGP ttl-security parameters\n"
3a2d747c
QY
6015 "Specify the maximum number of hops to the BGP peer\n"
6016 "Number of hops to BGP peer\n")
fa411a21 6017{
d62a17ae 6018 int idx_peer = 2;
6019 struct peer *peer;
fa411a21 6020
d62a17ae 6021 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6022 if (!peer)
6023 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6024
d62a17ae 6025 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6026}
6b0655a2 6027
adbac85e
DW
6028DEFUN (neighbor_addpath_tx_all_paths,
6029 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6030 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6031 NEIGHBOR_STR
6032 NEIGHBOR_ADDR_STR2
6033 "Use addpath to advertise all paths to a neighbor\n")
6034{
d62a17ae 6035 int idx_peer = 1;
6036 struct peer *peer;
adbac85e 6037
d62a17ae 6038 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6039 if (!peer)
6040 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6041
d62a17ae 6042 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6043 bgp_node_safi(vty),
6044 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6045}
6046
d62a17ae 6047ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6048 neighbor_addpath_tx_all_paths_hidden_cmd,
6049 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6050 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6051 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6052
adbac85e
DW
6053DEFUN (no_neighbor_addpath_tx_all_paths,
6054 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6055 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6056 NO_STR
6057 NEIGHBOR_STR
6058 NEIGHBOR_ADDR_STR2
6059 "Use addpath to advertise all paths to a neighbor\n")
6060{
d62a17ae 6061 int idx_peer = 2;
6062 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6063 bgp_node_afi(vty), bgp_node_safi(vty),
6064 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6065}
6066
d62a17ae 6067ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6068 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6069 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6070 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6071 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6072
06370dac
DW
6073DEFUN (neighbor_addpath_tx_bestpath_per_as,
6074 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6075 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6076 NEIGHBOR_STR
6077 NEIGHBOR_ADDR_STR2
6078 "Use addpath to advertise the bestpath per each neighboring AS\n")
6079{
d62a17ae 6080 int idx_peer = 1;
6081 struct peer *peer;
06370dac 6082
d62a17ae 6083 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6084 if (!peer)
6085 return CMD_WARNING_CONFIG_FAILED;
06370dac 6086
d62a17ae 6087 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6088 bgp_node_safi(vty),
6089 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6090}
6091
d62a17ae 6092ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6093 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6094 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6095 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6096 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6097
06370dac
DW
6098DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6099 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6100 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6101 NO_STR
6102 NEIGHBOR_STR
6103 NEIGHBOR_ADDR_STR2
6104 "Use addpath to advertise the bestpath per each neighboring AS\n")
6105{
d62a17ae 6106 int idx_peer = 2;
6107 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6108 bgp_node_afi(vty), bgp_node_safi(vty),
6109 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6110}
6111
d62a17ae 6112ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6113 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6114 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6115 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6116 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6117
505e5056 6118DEFUN_NOSH (address_family_ipv4_safi,
718e3744 6119 address_family_ipv4_safi_cmd,
5b1f0f29 6120 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6121 "Enter Address Family command mode\n"
8c3deaae 6122 "Address Family\n"
b6ab5a3a 6123 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6124{
f51bae9c 6125
d62a17ae 6126 if (argc == 3) {
2131d5cf 6127 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6128 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6129 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6130 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6131 && safi != SAFI_EVPN) {
31947174
MK
6132 vty_out(vty,
6133 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6134 return CMD_WARNING_CONFIG_FAILED;
6135 }
d62a17ae 6136 vty->node = bgp_node_type(AFI_IP, safi);
6137 } else
6138 vty->node = BGP_IPV4_NODE;
718e3744 6139
d62a17ae 6140 return CMD_SUCCESS;
718e3744 6141}
6142
505e5056 6143DEFUN_NOSH (address_family_ipv6_safi,
25ffbdc1 6144 address_family_ipv6_safi_cmd,
5b1f0f29 6145 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6146 "Enter Address Family command mode\n"
8c3deaae 6147 "Address Family\n"
b6ab5a3a 6148 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6149{
d62a17ae 6150 if (argc == 3) {
2131d5cf 6151 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6152 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6153 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6154 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6155 && safi != SAFI_EVPN) {
31947174
MK
6156 vty_out(vty,
6157 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6158 return CMD_WARNING_CONFIG_FAILED;
6159 }
d62a17ae 6160 vty->node = bgp_node_type(AFI_IP6, safi);
6161 } else
6162 vty->node = BGP_IPV6_NODE;
25ffbdc1 6163
d62a17ae 6164 return CMD_SUCCESS;
25ffbdc1 6165}
718e3744 6166
d6902373 6167#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6168DEFUN_NOSH (address_family_vpnv4,
718e3744 6169 address_family_vpnv4_cmd,
8334fd5a 6170 "address-family vpnv4 [unicast]",
718e3744 6171 "Enter Address Family command mode\n"
8c3deaae 6172 "Address Family\n"
3a2d747c 6173 "Address Family modifier\n")
718e3744 6174{
d62a17ae 6175 vty->node = BGP_VPNV4_NODE;
6176 return CMD_SUCCESS;
718e3744 6177}
6178
505e5056 6179DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6180 address_family_vpnv6_cmd,
8334fd5a 6181 "address-family vpnv6 [unicast]",
8ecd3266 6182 "Enter Address Family command mode\n"
8c3deaae 6183 "Address Family\n"
3a2d747c 6184 "Address Family modifier\n")
8ecd3266 6185{
d62a17ae 6186 vty->node = BGP_VPNV6_NODE;
6187 return CMD_SUCCESS;
8ecd3266 6188}
c016b6c7 6189#endif
d6902373 6190
505e5056 6191DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6192 address_family_evpn_cmd,
7111c1a0 6193 "address-family l2vpn evpn",
4e0b7b6d 6194 "Enter Address Family command mode\n"
7111c1a0
QY
6195 "Address Family\n"
6196 "Address Family modifier\n")
4e0b7b6d 6197{
2131d5cf 6198 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6199 vty->node = BGP_EVPN_NODE;
6200 return CMD_SUCCESS;
4e0b7b6d
PG
6201}
6202
505e5056 6203DEFUN_NOSH (exit_address_family,
718e3744 6204 exit_address_family_cmd,
6205 "exit-address-family",
6206 "Exit from Address Family configuration mode\n")
6207{
d62a17ae 6208 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6209 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6210 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6211 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6212 || vty->node == BGP_EVPN_NODE)
6213 vty->node = BGP_NODE;
6214 return CMD_SUCCESS;
718e3744 6215}
6b0655a2 6216
8ad7271d 6217/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6218static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6219 const char *ip_str, afi_t afi, safi_t safi,
6220 struct prefix_rd *prd)
6221{
6222 int ret;
6223 struct prefix match;
6224 struct bgp_node *rn;
6225 struct bgp_node *rm;
6226 struct bgp *bgp;
6227 struct bgp_table *table;
6228 struct bgp_table *rib;
6229
6230 /* BGP structure lookup. */
6231 if (view_name) {
6232 bgp = bgp_lookup_by_name(view_name);
6233 if (bgp == NULL) {
6234 vty_out(vty, "%% Can't find BGP instance %s\n",
6235 view_name);
6236 return CMD_WARNING;
6237 }
6238 } else {
6239 bgp = bgp_get_default();
6240 if (bgp == NULL) {
6241 vty_out(vty, "%% No BGP process is configured\n");
6242 return CMD_WARNING;
6243 }
6244 }
6245
6246 /* Check IP address argument. */
6247 ret = str2prefix(ip_str, &match);
6248 if (!ret) {
6249 vty_out(vty, "%% address is malformed\n");
6250 return CMD_WARNING;
6251 }
6252
6253 match.family = afi2family(afi);
6254 rib = bgp->rib[afi][safi];
6255
6256 if (safi == SAFI_MPLS_VPN) {
6257 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6258 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6259 continue;
6260
6261 if ((table = rn->info) != NULL) {
6262 if ((rm = bgp_node_match(table, &match))
6263 != NULL) {
6264 if (rm->p.prefixlen
6265 == match.prefixlen) {
6266 SET_FLAG(rn->flags,
6267 BGP_NODE_USER_CLEAR);
6268 bgp_process(bgp, rm, afi, safi);
6269 }
6270 bgp_unlock_node(rm);
6271 }
6272 }
6273 }
6274 } else {
6275 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6276 if (rn->p.prefixlen == match.prefixlen) {
6277 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6278 bgp_process(bgp, rn, afi, safi);
6279 }
6280 bgp_unlock_node(rn);
6281 }
6282 }
6283
6284 return CMD_SUCCESS;
8ad7271d
DS
6285}
6286
b09b5ae0 6287/* one clear bgp command to rule them all */
718e3744 6288DEFUN (clear_ip_bgp_all,
6289 clear_ip_bgp_all_cmd,
c1a44e43 6290 "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 6291 CLEAR_STR
6292 IP_STR
6293 BGP_STR
838758ac 6294 BGP_INSTANCE_HELP_STR
510afcd6
DS
6295 BGP_AFI_HELP_STR
6296 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
6297 "Clear all peers\n"
6298 "BGP neighbor address to clear\n"
a80beece 6299 "BGP IPv6 neighbor to clear\n"
838758ac 6300 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
6301 "Clear peers with the AS number\n"
6302 "Clear all external peers\n"
718e3744 6303 "Clear all members of peer-group\n"
b09b5ae0 6304 "BGP peer-group name\n"
b09b5ae0
DW
6305 BGP_SOFT_STR
6306 BGP_SOFT_IN_STR
b09b5ae0
DW
6307 BGP_SOFT_OUT_STR
6308 BGP_SOFT_IN_STR
6309 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 6310 BGP_SOFT_OUT_STR)
718e3744 6311{
d62a17ae 6312 char *vrf = NULL;
6313
6314 afi_t afi = AFI_IP6;
6315 safi_t safi = SAFI_UNICAST;
6316 enum clear_sort clr_sort = clear_peer;
6317 enum bgp_clear_type clr_type;
6318 char *clr_arg = NULL;
6319
6320 int idx = 0;
6321
6322 /* clear [ip] bgp */
6323 if (argv_find(argv, argc, "ip", &idx))
6324 afi = AFI_IP;
6325
6326 /* [<view|vrf> VIEWVRFNAME] */
6327 if (argv_find(argv, argc, "view", &idx)
6328 || argv_find(argv, argc, "vrf", &idx)) {
6329 vrf = argv[idx + 1]->arg;
6330 idx += 2;
6331 }
6332
6333 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6334 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6335 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6336
6337 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6338 if (argv_find(argv, argc, "*", &idx)) {
6339 clr_sort = clear_all;
6340 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6341 clr_sort = clear_peer;
6342 clr_arg = argv[idx]->arg;
6343 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6344 clr_sort = clear_peer;
6345 clr_arg = argv[idx]->arg;
6346 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6347 clr_sort = clear_group;
6348 idx++;
6349 clr_arg = argv[idx]->arg;
6350 } else if (argv_find(argv, argc, "WORD", &idx)) {
6351 clr_sort = clear_peer;
6352 clr_arg = argv[idx]->arg;
6353 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6354 clr_sort = clear_as;
6355 clr_arg = argv[idx]->arg;
6356 } else if (argv_find(argv, argc, "external", &idx)) {
6357 clr_sort = clear_external;
6358 }
6359
6360 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6361 if (argv_find(argv, argc, "soft", &idx)) {
6362 if (argv_find(argv, argc, "in", &idx)
6363 || argv_find(argv, argc, "out", &idx))
6364 clr_type = strmatch(argv[idx]->text, "in")
6365 ? BGP_CLEAR_SOFT_IN
6366 : BGP_CLEAR_SOFT_OUT;
6367 else
6368 clr_type = BGP_CLEAR_SOFT_BOTH;
6369 } else if (argv_find(argv, argc, "in", &idx)) {
6370 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6371 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6372 : BGP_CLEAR_SOFT_IN;
6373 } else if (argv_find(argv, argc, "out", &idx)) {
6374 clr_type = BGP_CLEAR_SOFT_OUT;
6375 } else
6376 clr_type = BGP_CLEAR_SOFT_NONE;
6377
6378 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 6379}
01080f7c 6380
8ad7271d
DS
6381DEFUN (clear_ip_bgp_prefix,
6382 clear_ip_bgp_prefix_cmd,
18c57037 6383 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
6384 CLEAR_STR
6385 IP_STR
6386 BGP_STR
838758ac 6387 BGP_INSTANCE_HELP_STR
8ad7271d 6388 "Clear bestpath and re-advertise\n"
0c7b1b01 6389 "IPv4 prefix\n")
8ad7271d 6390{
d62a17ae 6391 char *vrf = NULL;
6392 char *prefix = NULL;
8ad7271d 6393
d62a17ae 6394 int idx = 0;
01080f7c 6395
d62a17ae 6396 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 6397 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 6398 vrf = argv[idx]->arg;
0c7b1b01 6399
d62a17ae 6400 prefix = argv[argc - 1]->arg;
8ad7271d 6401
d62a17ae 6402 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 6403}
8ad7271d 6404
b09b5ae0
DW
6405DEFUN (clear_bgp_ipv6_safi_prefix,
6406 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 6407 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6408 CLEAR_STR
3a2d747c 6409 IP_STR
718e3744 6410 BGP_STR
8c3deaae 6411 "Address Family\n"
46f296b4 6412 BGP_SAFI_HELP_STR
b09b5ae0 6413 "Clear bestpath and re-advertise\n"
0c7b1b01 6414 "IPv6 prefix\n")
718e3744 6415{
d62a17ae 6416 int idx_safi = 3;
6417 int idx_ipv6_prefixlen = 5;
6418 return bgp_clear_prefix(
6419 vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6420 bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
838758ac 6421}
01080f7c 6422
b09b5ae0
DW
6423DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6424 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 6425 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6426 CLEAR_STR
3a2d747c 6427 IP_STR
718e3744 6428 BGP_STR
838758ac 6429 BGP_INSTANCE_HELP_STR
8c3deaae 6430 "Address Family\n"
46f296b4 6431 BGP_SAFI_HELP_STR
b09b5ae0 6432 "Clear bestpath and re-advertise\n"
0c7b1b01 6433 "IPv6 prefix\n")
718e3744 6434{
d62a17ae 6435 int idx_word = 3;
6436 int idx_safi = 5;
6437 int idx_ipv6_prefixlen = 7;
6438 return bgp_clear_prefix(
6439 vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg,
6440 AFI_IP6, bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
718e3744 6441}
6442
b09b5ae0
DW
6443DEFUN (show_bgp_views,
6444 show_bgp_views_cmd,
d6e3c605 6445 "show [ip] bgp views",
b09b5ae0 6446 SHOW_STR
d6e3c605 6447 IP_STR
01080f7c 6448 BGP_STR
b09b5ae0 6449 "Show the defined BGP views\n")
01080f7c 6450{
d62a17ae 6451 struct list *inst = bm->bgp;
6452 struct listnode *node;
6453 struct bgp *bgp;
01080f7c 6454
d62a17ae 6455 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6456 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6457 return CMD_WARNING;
6458 }
e52702f2 6459
d62a17ae 6460 vty_out(vty, "Defined BGP views:\n");
6461 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6462 /* Skip VRFs. */
6463 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6464 continue;
6465 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6466 bgp->as);
6467 }
e52702f2 6468
d62a17ae 6469 return CMD_SUCCESS;
e0081f70
ML
6470}
6471
8386ac43 6472DEFUN (show_bgp_vrfs,
6473 show_bgp_vrfs_cmd,
d6e3c605 6474 "show [ip] bgp vrfs [json]",
8386ac43 6475 SHOW_STR
d6e3c605 6476 IP_STR
8386ac43 6477 BGP_STR
6478 "Show BGP VRFs\n"
9973d184 6479 JSON_STR)
8386ac43 6480{
fe1dc5a3 6481 char buf[ETHER_ADDR_STRLEN];
d62a17ae 6482 struct list *inst = bm->bgp;
6483 struct listnode *node;
6484 struct bgp *bgp;
6485 u_char uj = use_json(argc, argv);
6486 json_object *json = NULL;
6487 json_object *json_vrfs = NULL;
6488 int count = 0;
d62a17ae 6489
6490 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6491 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6492 return CMD_WARNING;
6493 }
6494
6495 if (uj) {
6496 json = json_object_new_object();
6497 json_vrfs = json_object_new_object();
6498 }
6499
6500 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6501 const char *name, *type;
6502 struct peer *peer;
6503 struct listnode *node, *nnode;
6504 int peers_cfg, peers_estb;
6505 json_object *json_vrf = NULL;
d62a17ae 6506
6507 /* Skip Views. */
6508 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6509 continue;
6510
6511 count++;
6512 if (!uj && count == 1)
fe1dc5a3
MK
6513 vty_out(vty,
6514 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
6515 "Type", "Id", "routerId", "#PeersVfg",
6516 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 6517
6518 peers_cfg = peers_estb = 0;
6519 if (uj)
6520 json_vrf = json_object_new_object();
6521
6522
6523 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6524 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6525 continue;
6526 peers_cfg++;
6527 if (peer->status == Established)
6528 peers_estb++;
6529 }
6530
6531 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
6532 name = "Default";
6533 type = "DFLT";
6534 } else {
6535 name = bgp->name;
6536 type = "VRF";
6537 }
6538
a8bf7d9c 6539
d62a17ae 6540 if (uj) {
a4d82a8a
PZ
6541 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
6542 ? -1
6543 : (int64_t)bgp->vrf_id;
d62a17ae 6544 json_object_string_add(json_vrf, "type", type);
6545 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
6546 json_object_string_add(json_vrf, "routerId",
6547 inet_ntoa(bgp->router_id));
6548 json_object_int_add(json_vrf, "numConfiguredPeers",
6549 peers_cfg);
6550 json_object_int_add(json_vrf, "numEstablishedPeers",
6551 peers_estb);
6552
fe1dc5a3 6553 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
6554 json_object_string_add(
6555 json_vrf, "rmac",
6556 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 6557 json_object_object_add(json_vrfs, name, json_vrf);
6558 } else
fe1dc5a3
MK
6559 vty_out(vty,
6560 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
6561 type,
6562 bgp->vrf_id == VRF_UNKNOWN ? -1
6563 : (int)bgp->vrf_id,
6564 inet_ntoa(bgp->router_id), peers_cfg,
6565 peers_estb, name, bgp->l3vni,
fe1dc5a3 6566 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 6567 }
6568
6569 if (uj) {
6570 json_object_object_add(json, "vrfs", json_vrfs);
6571
6572 json_object_int_add(json, "totalVrfs", count);
6573
a4d82a8a
PZ
6574 vty_out(vty, "%s\n",
6575 json_object_to_json_string_ext(
6576 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 6577 json_object_free(json);
6578 } else {
6579 if (count)
6580 vty_out(vty,
6581 "\nTotal number of VRFs (including default): %d\n",
6582 count);
6583 }
6584
6585 return CMD_SUCCESS;
8386ac43 6586}
6587
acf71666
MK
6588static void show_address_entry(struct hash_backet *backet, void *args)
6589{
60466a63
QY
6590 struct vty *vty = (struct vty *)args;
6591 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 6592
60466a63 6593 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
6594 addr->refcnt);
6595}
6596
6597static void show_tip_entry(struct hash_backet *backet, void *args)
6598{
0291c246 6599 struct vty *vty = (struct vty *)args;
60466a63 6600 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 6601
60466a63 6602 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
6603 tip->refcnt);
6604}
6605
6606static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
6607{
6608 vty_out(vty, "self nexthop database:\n");
6609 hash_iterate(bgp->address_hash,
6610 (void (*)(struct hash_backet *, void *))show_address_entry,
6611 vty);
6612
6613 vty_out(vty, "Tunnel-ip database:\n");
6614 hash_iterate(bgp->tip_hash,
6615 (void (*)(struct hash_backet *, void *))show_tip_entry,
6616 vty);
6617}
6618
15c81ca4
DS
6619DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
6620 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
6621 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
6622 "martian next-hops\n"
6623 "martian next-hop database\n")
acf71666 6624{
0291c246 6625 struct bgp *bgp = NULL;
15c81ca4
DS
6626 int idx = 0;
6627
6628 if (argv_find(argv, argc, "view", &idx)
6629 || argv_find(argv, argc, "vrf", &idx))
6630 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
6631 else
6632 bgp = bgp_get_default();
acf71666 6633
acf71666
MK
6634 if (!bgp) {
6635 vty_out(vty, "%% No BGP process is configured\n");
6636 return CMD_WARNING;
6637 }
6638 bgp_show_martian_nexthops(vty, bgp);
6639
6640 return CMD_SUCCESS;
6641}
6642
f412b39a 6643DEFUN (show_bgp_memory,
4bf6a362 6644 show_bgp_memory_cmd,
7fa12b13 6645 "show [ip] bgp memory",
4bf6a362 6646 SHOW_STR
3a2d747c 6647 IP_STR
4bf6a362
PJ
6648 BGP_STR
6649 "Global BGP memory statistics\n")
6650{
d62a17ae 6651 char memstrbuf[MTYPE_MEMSTR_LEN];
6652 unsigned long count;
6653
6654 /* RIB related usage stats */
6655 count = mtype_stats_alloc(MTYPE_BGP_NODE);
6656 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
6657 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6658 count * sizeof(struct bgp_node)));
6659
6660 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
6661 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
6662 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6663 count * sizeof(struct bgp_info)));
6664 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
6665 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
6666 count,
6667 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6668 count * sizeof(struct bgp_info_extra)));
6669
6670 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
6671 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
6672 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6673 count * sizeof(struct bgp_static)));
6674
6675 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
6676 vty_out(vty, "%ld Packets, using %s of memory\n", count,
6677 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6678 count * sizeof(struct bpacket)));
6679
6680 /* Adj-In/Out */
6681 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
6682 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
6683 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6684 count * sizeof(struct bgp_adj_in)));
6685 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
6686 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
6687 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6688 count * sizeof(struct bgp_adj_out)));
6689
6690 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
6691 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
6692 count,
6693 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6694 count * sizeof(struct bgp_nexthop_cache)));
6695
6696 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
6697 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
6698 count,
6699 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6700 count * sizeof(struct bgp_damp_info)));
6701
6702 /* Attributes */
6703 count = attr_count();
6704 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
6705 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6706 count * sizeof(struct attr)));
6707
6708 if ((count = attr_unknown_count()))
6709 vty_out(vty, "%ld unknown attributes\n", count);
6710
6711 /* AS_PATH attributes */
6712 count = aspath_count();
6713 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
6714 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6715 count * sizeof(struct aspath)));
6716
6717 count = mtype_stats_alloc(MTYPE_AS_SEG);
6718 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
6719 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6720 count * sizeof(struct assegment)));
6721
6722 /* Other attributes */
6723 if ((count = community_count()))
6724 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
a4d82a8a
PZ
6725 count,
6726 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6727 count * sizeof(struct community)));
d62a17ae 6728 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
6729 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
a4d82a8a
PZ
6730 count,
6731 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6732 count * sizeof(struct ecommunity)));
d62a17ae 6733 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
6734 vty_out(vty,
6735 "%ld BGP large-community entries, using %s of memory\n",
a4d82a8a
PZ
6736 count,
6737 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6738 count * sizeof(struct lcommunity)));
d62a17ae 6739
6740 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
6741 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
6742 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6743 count * sizeof(struct cluster_list)));
6744
6745 /* Peer related usage */
6746 count = mtype_stats_alloc(MTYPE_BGP_PEER);
6747 vty_out(vty, "%ld peers, using %s of memory\n", count,
6748 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6749 count * sizeof(struct peer)));
6750
6751 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
6752 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
6753 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6754 count * sizeof(struct peer_group)));
6755
6756 /* Other */
6757 if ((count = mtype_stats_alloc(MTYPE_HASH)))
6758 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
6759 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6760 count * sizeof(struct hash)));
6761 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
6762 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
6763 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6764 count * sizeof(struct hash_backet)));
6765 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
6766 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
a4d82a8a
PZ
6767 count,
6768 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6769 count * sizeof(regex_t)));
d62a17ae 6770 return CMD_SUCCESS;
4bf6a362 6771}
fee0f4c6 6772
57a9c8a8
DS
6773static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
6774{
6775 json_object *bestpath = json_object_new_object();
6776
6777 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
6778 json_object_string_add(bestpath, "asPath", "ignore");
6779
6780 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
6781 json_object_string_add(bestpath, "asPath", "confed");
6782
6783 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
6784 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
6785 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
6786 "as-set");
6787 else
a4d82a8a 6788 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
6789 "true");
6790 } else
a4d82a8a 6791 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
6792
6793 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
6794 json_object_string_add(bestpath, "compareRouterId", "true");
6795 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
6796 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
6797 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 6798 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
6799 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
6800 json_object_string_add(bestpath, "med",
6801 "missing-as-worst");
6802 else
6803 json_object_string_add(bestpath, "med", "true");
6804 }
6805
6806 json_object_object_add(json, "bestPath", bestpath);
6807}
6808
718e3744 6809/* Show BGP peer's summary information. */
d62a17ae 6810static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
6811 u_char use_json, json_object *json)
6812{
6813 struct peer *peer;
6814 struct listnode *node, *nnode;
6815 unsigned int count = 0, dn_count = 0;
6816 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
6817 char neighbor_buf[VTY_BUFSIZ];
6818 int neighbor_col_default_width = 16;
6819 int len;
6820 int max_neighbor_width = 0;
6821 int pfx_rcd_safi;
6822 json_object *json_peer = NULL;
6823 json_object *json_peers = NULL;
6824
6825 /* labeled-unicast routes are installed in the unicast table so in order
6826 * to
6827 * display the correct PfxRcd value we must look at SAFI_UNICAST
6828 */
6829 if (safi == SAFI_LABELED_UNICAST)
6830 pfx_rcd_safi = SAFI_UNICAST;
6831 else
6832 pfx_rcd_safi = safi;
6833
6834 if (use_json) {
6835 if (json == NULL)
6836 json = json_object_new_object();
6837
6838 json_peers = json_object_new_object();
6839 } else {
6840 /* Loop over all neighbors that will be displayed to determine
6841 * how many
6842 * characters are needed for the Neighbor column
6843 */
6844 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6845 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6846 continue;
6847
6848 if (peer->afc[afi][safi]) {
6849 memset(dn_flag, '\0', sizeof(dn_flag));
6850 if (peer_dynamic_neighbor(peer))
6851 dn_flag[0] = '*';
6852
6853 if (peer->hostname
6854 && bgp_flag_check(bgp,
6855 BGP_FLAG_SHOW_HOSTNAME))
6856 sprintf(neighbor_buf, "%s%s(%s) ",
6857 dn_flag, peer->hostname,
6858 peer->host);
6859 else
6860 sprintf(neighbor_buf, "%s%s ", dn_flag,
6861 peer->host);
6862
6863 len = strlen(neighbor_buf);
6864
6865 if (len > max_neighbor_width)
6866 max_neighbor_width = len;
6867 }
6868 }
f933309e 6869
d62a17ae 6870 /* Originally we displayed the Neighbor column as 16
6871 * characters wide so make that the default
6872 */
6873 if (max_neighbor_width < neighbor_col_default_width)
6874 max_neighbor_width = neighbor_col_default_width;
6875 }
f933309e 6876
d62a17ae 6877 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6878 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6879 continue;
6880
ea47320b
DL
6881 if (!peer->afc[afi][safi])
6882 continue;
d62a17ae 6883
ea47320b
DL
6884 if (!count) {
6885 unsigned long ents;
6886 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 6887 int64_t vrf_id_ui;
d62a17ae 6888
a4d82a8a
PZ
6889 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
6890 ? -1
6891 : (int64_t)bgp->vrf_id;
ea47320b
DL
6892
6893 /* Usage summary and header */
6894 if (use_json) {
6895 json_object_string_add(
6896 json, "routerId",
6897 inet_ntoa(bgp->router_id));
60466a63
QY
6898 json_object_int_add(json, "as", bgp->as);
6899 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
6900 json_object_string_add(
6901 json, "vrfName",
6902 (bgp->inst_type
6903 == BGP_INSTANCE_TYPE_DEFAULT)
6904 ? "Default"
6905 : bgp->name);
6906 } else {
6907 vty_out(vty,
6908 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 6909 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
6910 bgp->vrf_id == VRF_UNKNOWN
6911 ? -1
6912 : (int)bgp->vrf_id);
ea47320b
DL
6913 vty_out(vty, "\n");
6914 }
d62a17ae 6915
ea47320b 6916 if (bgp_update_delay_configured(bgp)) {
d62a17ae 6917 if (use_json) {
ea47320b 6918 json_object_int_add(
60466a63 6919 json, "updateDelayLimit",
ea47320b 6920 bgp->v_update_delay);
d62a17ae 6921
ea47320b
DL
6922 if (bgp->v_update_delay
6923 != bgp->v_establish_wait)
d62a17ae 6924 json_object_int_add(
6925 json,
ea47320b
DL
6926 "updateDelayEstablishWait",
6927 bgp->v_establish_wait);
d62a17ae 6928
60466a63 6929 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
6930 json_object_string_add(
6931 json,
6932 "updateDelayFirstNeighbor",
6933 bgp->update_delay_begin_time);
6934 json_object_boolean_true_add(
6935 json,
6936 "updateDelayInProgress");
6937 } else {
6938 if (bgp->update_delay_over) {
d62a17ae 6939 json_object_string_add(
6940 json,
6941 "updateDelayFirstNeighbor",
6942 bgp->update_delay_begin_time);
ea47320b 6943 json_object_string_add(
d62a17ae 6944 json,
ea47320b
DL
6945 "updateDelayBestpathResumed",
6946 bgp->update_delay_end_time);
6947 json_object_string_add(
d62a17ae 6948 json,
ea47320b
DL
6949 "updateDelayZebraUpdateResume",
6950 bgp->update_delay_zebra_resume_time);
6951 json_object_string_add(
6952 json,
6953 "updateDelayPeerUpdateResume",
6954 bgp->update_delay_peers_resume_time);
d62a17ae 6955 }
ea47320b
DL
6956 }
6957 } else {
6958 vty_out(vty,
6959 "Read-only mode update-delay limit: %d seconds\n",
6960 bgp->v_update_delay);
6961 if (bgp->v_update_delay
6962 != bgp->v_establish_wait)
d62a17ae 6963 vty_out(vty,
ea47320b
DL
6964 " Establish wait: %d seconds\n",
6965 bgp->v_establish_wait);
d62a17ae 6966
60466a63 6967 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
6968 vty_out(vty,
6969 " First neighbor established: %s\n",
6970 bgp->update_delay_begin_time);
6971 vty_out(vty,
6972 " Delay in progress\n");
6973 } else {
6974 if (bgp->update_delay_over) {
d62a17ae 6975 vty_out(vty,
6976 " First neighbor established: %s\n",
6977 bgp->update_delay_begin_time);
6978 vty_out(vty,
ea47320b
DL
6979 " Best-paths resumed: %s\n",
6980 bgp->update_delay_end_time);
6981 vty_out(vty,
6982 " zebra update resumed: %s\n",
6983 bgp->update_delay_zebra_resume_time);
6984 vty_out(vty,
6985 " peers update resumed: %s\n",
6986 bgp->update_delay_peers_resume_time);
d62a17ae 6987 }
6988 }
6989 }
ea47320b 6990 }
d62a17ae 6991
ea47320b
DL
6992 if (use_json) {
6993 if (bgp_maxmed_onstartup_configured(bgp)
6994 && bgp->maxmed_active)
6995 json_object_boolean_true_add(
60466a63 6996 json, "maxMedOnStartup");
ea47320b
DL
6997 if (bgp->v_maxmed_admin)
6998 json_object_boolean_true_add(
60466a63 6999 json, "maxMedAdministrative");
d62a17ae 7000
ea47320b
DL
7001 json_object_int_add(
7002 json, "tableVersion",
60466a63 7003 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7004
60466a63
QY
7005 ents = bgp_table_count(bgp->rib[afi][safi]);
7006 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7007 json_object_int_add(
7008 json, "ribMemory",
7009 ents * sizeof(struct bgp_node));
d62a17ae 7010
ea47320b 7011 ents = listcount(bgp->peer);
60466a63
QY
7012 json_object_int_add(json, "peerCount", ents);
7013 json_object_int_add(json, "peerMemory",
7014 ents * sizeof(struct peer));
d62a17ae 7015
ea47320b
DL
7016 if ((ents = listcount(bgp->group))) {
7017 json_object_int_add(
60466a63 7018 json, "peerGroupCount", ents);
ea47320b
DL
7019 json_object_int_add(
7020 json, "peerGroupMemory",
a4d82a8a
PZ
7021 ents
7022 * sizeof(struct
7023 peer_group));
ea47320b 7024 }
d62a17ae 7025
ea47320b
DL
7026 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7027 BGP_CONFIG_DAMPENING))
7028 json_object_boolean_true_add(
60466a63 7029 json, "dampeningEnabled");
ea47320b
DL
7030 } else {
7031 if (bgp_maxmed_onstartup_configured(bgp)
7032 && bgp->maxmed_active)
d62a17ae 7033 vty_out(vty,
ea47320b
DL
7034 "Max-med on-startup active\n");
7035 if (bgp->v_maxmed_admin)
d62a17ae 7036 vty_out(vty,
ea47320b 7037 "Max-med administrative active\n");
d62a17ae 7038
60466a63
QY
7039 vty_out(vty, "BGP table version %" PRIu64 "\n",
7040 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7041
60466a63 7042 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7043 vty_out(vty,
7044 "RIB entries %ld, using %s of memory\n",
7045 ents,
a4d82a8a
PZ
7046 mtype_memstr(
7047 memstrbuf, sizeof(memstrbuf),
7048 ents
7049 * sizeof(struct
7050 bgp_node)));
ea47320b
DL
7051
7052 /* Peer related usage */
7053 ents = listcount(bgp->peer);
60466a63 7054 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7055 ents,
7056 mtype_memstr(
60466a63
QY
7057 memstrbuf, sizeof(memstrbuf),
7058 ents * sizeof(struct peer)));
ea47320b
DL
7059
7060 if ((ents = listcount(bgp->group)))
d62a17ae 7061 vty_out(vty,
ea47320b 7062 "Peer groups %ld, using %s of memory\n",
d62a17ae 7063 ents,
7064 mtype_memstr(
7065 memstrbuf,
7066 sizeof(memstrbuf),
a4d82a8a
PZ
7067 ents
7068 * sizeof(struct
7069 peer_group)));
d62a17ae 7070
ea47320b
DL
7071 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7072 BGP_CONFIG_DAMPENING))
60466a63 7073 vty_out(vty, "Dampening enabled.\n");
ea47320b 7074 vty_out(vty, "\n");
d62a17ae 7075
ea47320b
DL
7076 /* Subtract 8 here because 'Neighbor' is
7077 * 8 characters */
7078 vty_out(vty, "Neighbor");
60466a63
QY
7079 vty_out(vty, "%*s", max_neighbor_width - 8,
7080 " ");
ea47320b
DL
7081 vty_out(vty,
7082 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7083 }
ea47320b 7084 }
d62a17ae 7085
ea47320b 7086 count++;
d62a17ae 7087
ea47320b
DL
7088 if (use_json) {
7089 json_peer = json_object_new_object();
d62a17ae 7090
ea47320b 7091 if (peer_dynamic_neighbor(peer))
60466a63
QY
7092 json_object_boolean_true_add(json_peer,
7093 "dynamicPeer");
d62a17ae 7094
ea47320b 7095 if (peer->hostname)
60466a63 7096 json_object_string_add(json_peer, "hostname",
ea47320b 7097 peer->hostname);
d62a17ae 7098
ea47320b 7099 if (peer->domainname)
60466a63
QY
7100 json_object_string_add(json_peer, "domainname",
7101 peer->domainname);
d62a17ae 7102
60466a63 7103 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7104 json_object_int_add(json_peer, "version", 4);
60466a63 7105 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7106 PEER_TOTAL_RX(peer));
60466a63 7107 json_object_int_add(json_peer, "msgSent",
0112e9e0 7108 PEER_TOTAL_TX(peer));
ea47320b
DL
7109
7110 json_object_int_add(json_peer, "tableVersion",
7111 peer->version[afi][safi]);
7112 json_object_int_add(json_peer, "outq",
7113 peer->obuf->count);
7114 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7115 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7116 use_json, json_peer);
7117 json_object_int_add(json_peer, "prefixReceivedCount",
7118 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7119
ea47320b 7120 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7121 json_object_string_add(json_peer, "state",
ea47320b 7122 "Idle (Admin)");
60466a63
QY
7123 else if (CHECK_FLAG(peer->sflags,
7124 PEER_STATUS_PREFIX_OVERFLOW))
7125 json_object_string_add(json_peer, "state",
ea47320b
DL
7126 "Idle (PfxCt)");
7127 else
7128 json_object_string_add(
7129 json_peer, "state",
60466a63
QY
7130 lookup_msg(bgp_status_msg, peer->status,
7131 NULL));
ea47320b
DL
7132
7133 if (peer->conf_if)
60466a63 7134 json_object_string_add(json_peer, "idType",
ea47320b
DL
7135 "interface");
7136 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7137 json_object_string_add(json_peer, "idType",
7138 "ipv4");
ea47320b 7139 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7140 json_object_string_add(json_peer, "idType",
7141 "ipv6");
d62a17ae 7142
ea47320b
DL
7143 json_object_object_add(json_peers, peer->host,
7144 json_peer);
7145 } else {
7146 memset(dn_flag, '\0', sizeof(dn_flag));
7147 if (peer_dynamic_neighbor(peer)) {
7148 dn_count++;
7149 dn_flag[0] = '*';
7150 }
d62a17ae 7151
ea47320b 7152 if (peer->hostname
60466a63 7153 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7154 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7155 peer->hostname, peer->host);
ea47320b 7156 else
60466a63 7157 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7158
7159 /* pad the neighbor column with spaces */
7160 if (len < max_neighbor_width)
60466a63
QY
7161 vty_out(vty, "%*s", max_neighbor_width - len,
7162 " ");
ea47320b 7163
86a55b99 7164 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7165 peer->as, PEER_TOTAL_RX(peer),
7166 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7167 0, peer->obuf->count,
d62a17ae 7168 peer_uptime(peer->uptime, timebuf,
ea47320b 7169 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7170
ea47320b 7171 if (peer->status == Established)
95077abf
DW
7172 if (peer->afc_recv[afi][pfx_rcd_safi])
7173 vty_out(vty, " %12ld",
a4d82a8a
PZ
7174 peer->pcount[afi]
7175 [pfx_rcd_safi]);
95077abf
DW
7176 else
7177 vty_out(vty, " NoNeg");
ea47320b 7178 else {
60466a63 7179 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7180 vty_out(vty, " Idle (Admin)");
60466a63
QY
7181 else if (CHECK_FLAG(
7182 peer->sflags,
7183 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7184 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7185 else
ea47320b 7186 vty_out(vty, " %12s",
60466a63
QY
7187 lookup_msg(bgp_status_msg,
7188 peer->status, NULL));
d62a17ae 7189 }
ea47320b 7190 vty_out(vty, "\n");
d62a17ae 7191 }
7192 }
f933309e 7193
d62a17ae 7194 if (use_json) {
7195 json_object_object_add(json, "peers", json_peers);
7196
7197 json_object_int_add(json, "totalPeers", count);
7198 json_object_int_add(json, "dynamicPeers", dn_count);
7199
57a9c8a8
DS
7200 bgp_show_bestpath_json(bgp, json);
7201
a4d82a8a
PZ
7202 vty_out(vty, "%s\n",
7203 json_object_to_json_string_ext(
7204 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7205 json_object_free(json);
7206 } else {
7207 if (count)
7208 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7209 else {
7210 if (use_json)
7211 vty_out(vty,
7212 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7213 afi_safi_print(afi, safi));
7214 else
7215 vty_out(vty, "No %s neighbor is configured\n",
7216 afi_safi_print(afi, safi));
7217 }
b05a1c8b 7218
d62a17ae 7219 if (dn_count && !use_json) {
7220 vty_out(vty, "* - dynamic neighbor\n");
7221 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7222 dn_count, bgp->dynamic_neighbors_limit);
7223 }
7224 }
1ff9a340 7225
d62a17ae 7226 return CMD_SUCCESS;
718e3744 7227}
7228
d62a17ae 7229static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7230 int safi, u_char use_json,
7231 json_object *json)
7232{
7233 int is_first = 1;
7234 int afi_wildcard = (afi == AFI_MAX);
7235 int safi_wildcard = (safi == SAFI_MAX);
7236 int is_wildcard = (afi_wildcard || safi_wildcard);
7237 bool json_output = false;
7238
7239 if (use_json && is_wildcard)
7240 vty_out(vty, "{\n");
7241 if (afi_wildcard)
7242 afi = 1; /* AFI_IP */
7243 while (afi < AFI_MAX) {
7244 if (safi_wildcard)
7245 safi = 1; /* SAFI_UNICAST */
7246 while (safi < SAFI_MAX) {
318cac96 7247 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 7248 json_output = true;
7249 if (is_wildcard) {
7250 /*
7251 * So limit output to those afi/safi
7252 * pairs that
7253 * actualy have something interesting in
7254 * them
7255 */
7256 if (use_json) {
7257 json = json_object_new_object();
7258
7259 if (!is_first)
7260 vty_out(vty, ",\n");
7261 else
7262 is_first = 0;
7263
7264 vty_out(vty, "\"%s\":",
7265 afi_safi_json(afi,
7266 safi));
7267 } else {
7268 vty_out(vty, "\n%s Summary:\n",
7269 afi_safi_print(afi,
7270 safi));
7271 }
7272 }
7273 bgp_show_summary(vty, bgp, afi, safi, use_json,
7274 json);
7275 }
7276 safi++;
d62a17ae 7277 if (!safi_wildcard)
7278 safi = SAFI_MAX;
7279 }
7280 afi++;
7281 if (!afi_wildcard
7282 || afi == AFI_L2VPN) /* special case, not handled yet */
7283 afi = AFI_MAX;
7284 }
7285
7286 if (use_json && is_wildcard)
7287 vty_out(vty, "}\n");
7288 else if (use_json && !json_output)
7289 vty_out(vty, "{}\n");
7290}
7291
7292static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7293 safi_t safi, u_char use_json)
7294{
7295 struct listnode *node, *nnode;
7296 struct bgp *bgp;
7297 json_object *json = NULL;
7298 int is_first = 1;
7299
7300 if (use_json)
7301 vty_out(vty, "{\n");
7302
7303 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
7304 if (use_json) {
7305 json = json_object_new_object();
7306
7307 if (!is_first)
7308 vty_out(vty, ",\n");
7309 else
7310 is_first = 0;
7311
7312 vty_out(vty, "\"%s\":",
7313 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7314 ? "Default"
7315 : bgp->name);
7316 } else {
7317 vty_out(vty, "\nInstance %s:\n",
7318 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7319 ? "Default"
7320 : bgp->name);
7321 }
7322 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7323 }
7324
7325 if (use_json)
7326 vty_out(vty, "}\n");
7327}
7328
7329int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7330 safi_t safi, u_char use_json)
7331{
7332 struct bgp *bgp;
7333
7334 if (name) {
7335 if (strmatch(name, "all")) {
7336 bgp_show_all_instances_summary_vty(vty, afi, safi,
7337 use_json);
7338 return CMD_SUCCESS;
7339 } else {
7340 bgp = bgp_lookup_by_name(name);
7341
7342 if (!bgp) {
7343 if (use_json)
7344 vty_out(vty, "{}\n");
7345 else
7346 vty_out(vty,
7347 "%% No such BGP instance exist\n");
7348 return CMD_WARNING;
7349 }
7350
7351 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7352 NULL);
7353 return CMD_SUCCESS;
7354 }
7355 }
7356
7357 bgp = bgp_get_default();
7358
7359 if (bgp)
7360 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7361
7362 return CMD_SUCCESS;
4fb25c53
DW
7363}
7364
716b2d8a 7365/* `show [ip] bgp summary' commands. */
47fc97cc 7366DEFUN (show_ip_bgp_summary,
718e3744 7367 show_ip_bgp_summary_cmd,
dd6bd0f1 7368 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 7369 SHOW_STR
7370 IP_STR
7371 BGP_STR
8386ac43 7372 BGP_INSTANCE_HELP_STR
46f296b4 7373 BGP_AFI_HELP_STR
dd6bd0f1 7374 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 7375 "Summary of BGP neighbor status\n"
9973d184 7376 JSON_STR)
718e3744 7377{
d62a17ae 7378 char *vrf = NULL;
7379 afi_t afi = AFI_MAX;
7380 safi_t safi = SAFI_MAX;
7381
7382 int idx = 0;
7383
7384 /* show [ip] bgp */
7385 if (argv_find(argv, argc, "ip", &idx))
7386 afi = AFI_IP;
7387 /* [<view|vrf> VIEWVRFNAME] */
7388 if (argv_find(argv, argc, "view", &idx)
7389 || argv_find(argv, argc, "vrf", &idx))
7390 vrf = argv[++idx]->arg;
7391 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7392 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7393 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7394 }
7395
7396 int uj = use_json(argc, argv);
7397
7398 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7399}
7400
7401const char *afi_safi_print(afi_t afi, safi_t safi)
7402{
7403 if (afi == AFI_IP && safi == SAFI_UNICAST)
7404 return "IPv4 Unicast";
7405 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7406 return "IPv4 Multicast";
7407 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7408 return "IPv4 Labeled Unicast";
7409 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7410 return "IPv4 VPN";
7411 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7412 return "IPv4 Encap";
7413 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7414 return "IPv6 Unicast";
7415 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7416 return "IPv6 Multicast";
7417 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7418 return "IPv6 Labeled Unicast";
7419 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7420 return "IPv6 VPN";
7421 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7422 return "IPv6 Encap";
7423 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7424 return "L2VPN EVPN";
7425 else
7426 return "Unknown";
538621f2 7427}
7428
b9f77ec8
DS
7429/*
7430 * Please note that we have intentionally camelCased
7431 * the return strings here. So if you want
7432 * to use this function, please ensure you
7433 * are doing this within json output
7434 */
d62a17ae 7435const char *afi_safi_json(afi_t afi, safi_t safi)
7436{
7437 if (afi == AFI_IP && safi == SAFI_UNICAST)
7438 return "ipv4Unicast";
7439 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7440 return "ipv4Multicast";
7441 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7442 return "ipv4LabeledUnicast";
7443 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7444 return "ipv4Vpn";
7445 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7446 return "ipv4Encap";
7447 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7448 return "ipv6Unicast";
7449 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7450 return "ipv6Multicast";
7451 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7452 return "ipv6LabeledUnicast";
7453 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7454 return "ipv6Vpn";
7455 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7456 return "ipv6Encap";
7457 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7458 return "l2VpnEvpn";
7459 else
7460 return "Unknown";
27162734
LB
7461}
7462
718e3744 7463/* Show BGP peer's information. */
d62a17ae 7464enum show_type { show_all, show_peer };
7465
7466static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7467 afi_t afi, safi_t safi,
7468 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7469 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7470 u_char use_json, json_object *json_pref)
7471{
7472 /* Send-Mode */
7473 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7474 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7475 if (use_json) {
7476 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7477 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7478 json_object_string_add(json_pref, "sendMode",
7479 "advertisedAndReceived");
7480 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7481 json_object_string_add(json_pref, "sendMode",
7482 "advertised");
7483 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7484 json_object_string_add(json_pref, "sendMode",
7485 "received");
7486 } else {
7487 vty_out(vty, " Send-mode: ");
7488 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7489 vty_out(vty, "advertised");
7490 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7491 vty_out(vty, "%sreceived",
7492 CHECK_FLAG(p->af_cap[afi][safi],
7493 adv_smcap)
7494 ? ", "
7495 : "");
7496 vty_out(vty, "\n");
7497 }
7498 }
7499
7500 /* Receive-Mode */
7501 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7502 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
7503 if (use_json) {
7504 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7505 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7506 json_object_string_add(json_pref, "recvMode",
7507 "advertisedAndReceived");
7508 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7509 json_object_string_add(json_pref, "recvMode",
7510 "advertised");
7511 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7512 json_object_string_add(json_pref, "recvMode",
7513 "received");
7514 } else {
7515 vty_out(vty, " Receive-mode: ");
7516 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7517 vty_out(vty, "advertised");
7518 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7519 vty_out(vty, "%sreceived",
7520 CHECK_FLAG(p->af_cap[afi][safi],
7521 adv_rmcap)
7522 ? ", "
7523 : "");
7524 vty_out(vty, "\n");
7525 }
7526 }
7527}
7528
7529static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
7530 safi_t safi, u_char use_json,
7531 json_object *json_neigh)
7532{
0291c246
MK
7533 struct bgp_filter *filter;
7534 struct peer_af *paf;
7535 char orf_pfx_name[BUFSIZ];
7536 int orf_pfx_count;
7537 json_object *json_af = NULL;
7538 json_object *json_prefA = NULL;
7539 json_object *json_prefB = NULL;
7540 json_object *json_addr = NULL;
d62a17ae 7541
7542 if (use_json) {
7543 json_addr = json_object_new_object();
7544 json_af = json_object_new_object();
7545 filter = &p->filter[afi][safi];
7546
7547 if (peer_group_active(p))
7548 json_object_string_add(json_addr, "peerGroupMember",
7549 p->group->name);
7550
7551 paf = peer_af_find(p, afi, safi);
7552 if (paf && PAF_SUBGRP(paf)) {
7553 json_object_int_add(json_addr, "updateGroupId",
7554 PAF_UPDGRP(paf)->id);
7555 json_object_int_add(json_addr, "subGroupId",
7556 PAF_SUBGRP(paf)->id);
7557 json_object_int_add(json_addr, "packetQueueLength",
7558 bpacket_queue_virtual_length(paf));
7559 }
7560
7561 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7562 || CHECK_FLAG(p->af_cap[afi][safi],
7563 PEER_CAP_ORF_PREFIX_SM_RCV)
7564 || CHECK_FLAG(p->af_cap[afi][safi],
7565 PEER_CAP_ORF_PREFIX_RM_ADV)
7566 || CHECK_FLAG(p->af_cap[afi][safi],
7567 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7568 json_object_int_add(json_af, "orfType",
7569 ORF_TYPE_PREFIX);
7570 json_prefA = json_object_new_object();
7571 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
7572 PEER_CAP_ORF_PREFIX_SM_ADV,
7573 PEER_CAP_ORF_PREFIX_RM_ADV,
7574 PEER_CAP_ORF_PREFIX_SM_RCV,
7575 PEER_CAP_ORF_PREFIX_RM_RCV,
7576 use_json, json_prefA);
7577 json_object_object_add(json_af, "orfPrefixList",
7578 json_prefA);
7579 }
7580
7581 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7582 || CHECK_FLAG(p->af_cap[afi][safi],
7583 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7584 || CHECK_FLAG(p->af_cap[afi][safi],
7585 PEER_CAP_ORF_PREFIX_RM_ADV)
7586 || CHECK_FLAG(p->af_cap[afi][safi],
7587 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7588 json_object_int_add(json_af, "orfOldType",
7589 ORF_TYPE_PREFIX_OLD);
7590 json_prefB = json_object_new_object();
7591 bgp_show_peer_afi_orf_cap(
7592 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7593 PEER_CAP_ORF_PREFIX_RM_ADV,
7594 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7595 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
7596 json_prefB);
7597 json_object_object_add(json_af, "orfOldPrefixList",
7598 json_prefB);
7599 }
7600
7601 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7602 || CHECK_FLAG(p->af_cap[afi][safi],
7603 PEER_CAP_ORF_PREFIX_SM_RCV)
7604 || CHECK_FLAG(p->af_cap[afi][safi],
7605 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7606 || CHECK_FLAG(p->af_cap[afi][safi],
7607 PEER_CAP_ORF_PREFIX_RM_ADV)
7608 || CHECK_FLAG(p->af_cap[afi][safi],
7609 PEER_CAP_ORF_PREFIX_RM_RCV)
7610 || CHECK_FLAG(p->af_cap[afi][safi],
7611 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7612 json_object_object_add(json_addr, "afDependentCap",
7613 json_af);
7614 else
7615 json_object_free(json_af);
7616
7617 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7618 orf_pfx_count = prefix_bgp_show_prefix_list(
7619 NULL, afi, orf_pfx_name, use_json);
7620
7621 if (CHECK_FLAG(p->af_sflags[afi][safi],
7622 PEER_STATUS_ORF_PREFIX_SEND)
7623 || orf_pfx_count) {
7624 if (CHECK_FLAG(p->af_sflags[afi][safi],
7625 PEER_STATUS_ORF_PREFIX_SEND))
7626 json_object_boolean_true_add(json_neigh,
7627 "orfSent");
7628 if (orf_pfx_count)
7629 json_object_int_add(json_addr, "orfRecvCounter",
7630 orf_pfx_count);
7631 }
7632 if (CHECK_FLAG(p->af_sflags[afi][safi],
7633 PEER_STATUS_ORF_WAIT_REFRESH))
7634 json_object_string_add(
7635 json_addr, "orfFirstUpdate",
7636 "deferredUntilORFOrRouteRefreshRecvd");
7637
7638 if (CHECK_FLAG(p->af_flags[afi][safi],
7639 PEER_FLAG_REFLECTOR_CLIENT))
7640 json_object_boolean_true_add(json_addr,
7641 "routeReflectorClient");
7642 if (CHECK_FLAG(p->af_flags[afi][safi],
7643 PEER_FLAG_RSERVER_CLIENT))
7644 json_object_boolean_true_add(json_addr,
7645 "routeServerClient");
7646 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7647 json_object_boolean_true_add(json_addr,
7648 "inboundSoftConfigPermit");
7649
7650 if (CHECK_FLAG(p->af_flags[afi][safi],
7651 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7652 json_object_boolean_true_add(
7653 json_addr,
7654 "privateAsNumsAllReplacedInUpdatesToNbr");
7655 else if (CHECK_FLAG(p->af_flags[afi][safi],
7656 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7657 json_object_boolean_true_add(
7658 json_addr,
7659 "privateAsNumsReplacedInUpdatesToNbr");
7660 else if (CHECK_FLAG(p->af_flags[afi][safi],
7661 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7662 json_object_boolean_true_add(
7663 json_addr,
7664 "privateAsNumsAllRemovedInUpdatesToNbr");
7665 else if (CHECK_FLAG(p->af_flags[afi][safi],
7666 PEER_FLAG_REMOVE_PRIVATE_AS))
7667 json_object_boolean_true_add(
7668 json_addr,
7669 "privateAsNumsRemovedInUpdatesToNbr");
7670
7671 if (CHECK_FLAG(p->af_flags[afi][safi],
7672 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7673 json_object_boolean_true_add(json_addr,
7674 "addpathTxAllPaths");
7675
7676 if (CHECK_FLAG(p->af_flags[afi][safi],
7677 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7678 json_object_boolean_true_add(json_addr,
7679 "addpathTxBestpathPerAS");
7680
7681 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7682 json_object_string_add(json_addr,
7683 "overrideASNsInOutboundUpdates",
7684 "ifAspathEqualRemoteAs");
7685
7686 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7687 || CHECK_FLAG(p->af_flags[afi][safi],
7688 PEER_FLAG_FORCE_NEXTHOP_SELF))
7689 json_object_boolean_true_add(json_addr,
7690 "routerAlwaysNextHop");
7691 if (CHECK_FLAG(p->af_flags[afi][safi],
7692 PEER_FLAG_AS_PATH_UNCHANGED))
7693 json_object_boolean_true_add(
7694 json_addr, "unchangedAsPathPropogatedToNbr");
7695 if (CHECK_FLAG(p->af_flags[afi][safi],
7696 PEER_FLAG_NEXTHOP_UNCHANGED))
7697 json_object_boolean_true_add(
7698 json_addr, "unchangedNextHopPropogatedToNbr");
7699 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7700 json_object_boolean_true_add(
7701 json_addr, "unchangedMedPropogatedToNbr");
7702 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7703 || CHECK_FLAG(p->af_flags[afi][safi],
7704 PEER_FLAG_SEND_EXT_COMMUNITY)) {
7705 if (CHECK_FLAG(p->af_flags[afi][safi],
7706 PEER_FLAG_SEND_COMMUNITY)
7707 && CHECK_FLAG(p->af_flags[afi][safi],
7708 PEER_FLAG_SEND_EXT_COMMUNITY))
7709 json_object_string_add(json_addr,
7710 "commAttriSentToNbr",
7711 "extendedAndStandard");
7712 else if (CHECK_FLAG(p->af_flags[afi][safi],
7713 PEER_FLAG_SEND_EXT_COMMUNITY))
7714 json_object_string_add(json_addr,
7715 "commAttriSentToNbr",
7716 "extended");
7717 else
7718 json_object_string_add(json_addr,
7719 "commAttriSentToNbr",
7720 "standard");
7721 }
7722 if (CHECK_FLAG(p->af_flags[afi][safi],
7723 PEER_FLAG_DEFAULT_ORIGINATE)) {
7724 if (p->default_rmap[afi][safi].name)
7725 json_object_string_add(
7726 json_addr, "defaultRouteMap",
7727 p->default_rmap[afi][safi].name);
7728
7729 if (paf && PAF_SUBGRP(paf)
7730 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7731 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7732 json_object_boolean_true_add(json_addr,
7733 "defaultSent");
7734 else
7735 json_object_boolean_true_add(json_addr,
7736 "defaultNotSent");
7737 }
7738
dff8f48d 7739 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 7740 if (is_evpn_enabled())
60466a63
QY
7741 json_object_boolean_true_add(
7742 json_addr, "advertiseAllVnis");
dff8f48d
MK
7743 }
7744
d62a17ae 7745 if (filter->plist[FILTER_IN].name
7746 || filter->dlist[FILTER_IN].name
7747 || filter->aslist[FILTER_IN].name
7748 || filter->map[RMAP_IN].name)
7749 json_object_boolean_true_add(json_addr,
7750 "inboundPathPolicyConfig");
7751 if (filter->plist[FILTER_OUT].name
7752 || filter->dlist[FILTER_OUT].name
7753 || filter->aslist[FILTER_OUT].name
7754 || filter->map[RMAP_OUT].name || filter->usmap.name)
7755 json_object_boolean_true_add(
7756 json_addr, "outboundPathPolicyConfig");
7757
7758 /* prefix-list */
7759 if (filter->plist[FILTER_IN].name)
7760 json_object_string_add(json_addr,
7761 "incomingUpdatePrefixFilterList",
7762 filter->plist[FILTER_IN].name);
7763 if (filter->plist[FILTER_OUT].name)
7764 json_object_string_add(json_addr,
7765 "outgoingUpdatePrefixFilterList",
7766 filter->plist[FILTER_OUT].name);
7767
7768 /* distribute-list */
7769 if (filter->dlist[FILTER_IN].name)
7770 json_object_string_add(
7771 json_addr, "incomingUpdateNetworkFilterList",
7772 filter->dlist[FILTER_IN].name);
7773 if (filter->dlist[FILTER_OUT].name)
7774 json_object_string_add(
7775 json_addr, "outgoingUpdateNetworkFilterList",
7776 filter->dlist[FILTER_OUT].name);
7777
7778 /* filter-list. */
7779 if (filter->aslist[FILTER_IN].name)
7780 json_object_string_add(json_addr,
7781 "incomingUpdateAsPathFilterList",
7782 filter->aslist[FILTER_IN].name);
7783 if (filter->aslist[FILTER_OUT].name)
7784 json_object_string_add(json_addr,
7785 "outgoingUpdateAsPathFilterList",
7786 filter->aslist[FILTER_OUT].name);
7787
7788 /* route-map. */
7789 if (filter->map[RMAP_IN].name)
7790 json_object_string_add(
7791 json_addr, "routeMapForIncomingAdvertisements",
7792 filter->map[RMAP_IN].name);
7793 if (filter->map[RMAP_OUT].name)
7794 json_object_string_add(
7795 json_addr, "routeMapForOutgoingAdvertisements",
7796 filter->map[RMAP_OUT].name);
7797
7798 /* unsuppress-map */
7799 if (filter->usmap.name)
7800 json_object_string_add(json_addr,
7801 "selectiveUnsuppressRouteMap",
7802 filter->usmap.name);
7803
7804 /* Receive prefix count */
7805 json_object_int_add(json_addr, "acceptedPrefixCounter",
7806 p->pcount[afi][safi]);
7807
7808 /* Maximum prefix */
7809 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7810 json_object_int_add(json_addr, "prefixAllowedMax",
7811 p->pmax[afi][safi]);
7812 if (CHECK_FLAG(p->af_flags[afi][safi],
7813 PEER_FLAG_MAX_PREFIX_WARNING))
7814 json_object_boolean_true_add(
7815 json_addr, "prefixAllowedMaxWarning");
7816 json_object_int_add(json_addr,
7817 "prefixAllowedWarningThresh",
7818 p->pmax_threshold[afi][safi]);
7819 if (p->pmax_restart[afi][safi])
7820 json_object_int_add(
7821 json_addr,
7822 "prefixAllowedRestartIntervalMsecs",
7823 p->pmax_restart[afi][safi] * 60000);
7824 }
7825 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
7826 json_addr);
7827
7828 } else {
7829 filter = &p->filter[afi][safi];
7830
7831 vty_out(vty, " For address family: %s\n",
7832 afi_safi_print(afi, safi));
7833
7834 if (peer_group_active(p))
7835 vty_out(vty, " %s peer-group member\n",
7836 p->group->name);
7837
7838 paf = peer_af_find(p, afi, safi);
7839 if (paf && PAF_SUBGRP(paf)) {
a4d82a8a
PZ
7840 vty_out(vty,
7841 " Update group %" PRIu64 ", subgroup %" PRIu64
7842 "\n",
d62a17ae 7843 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
7844 vty_out(vty, " Packet Queue length %d\n",
7845 bpacket_queue_virtual_length(paf));
7846 } else {
7847 vty_out(vty, " Not part of any update group\n");
7848 }
7849 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7850 || CHECK_FLAG(p->af_cap[afi][safi],
7851 PEER_CAP_ORF_PREFIX_SM_RCV)
7852 || CHECK_FLAG(p->af_cap[afi][safi],
7853 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7854 || CHECK_FLAG(p->af_cap[afi][safi],
7855 PEER_CAP_ORF_PREFIX_RM_ADV)
7856 || CHECK_FLAG(p->af_cap[afi][safi],
7857 PEER_CAP_ORF_PREFIX_RM_RCV)
7858 || CHECK_FLAG(p->af_cap[afi][safi],
7859 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7860 vty_out(vty, " AF-dependant capabilities:\n");
7861
7862 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7863 || CHECK_FLAG(p->af_cap[afi][safi],
7864 PEER_CAP_ORF_PREFIX_SM_RCV)
7865 || CHECK_FLAG(p->af_cap[afi][safi],
7866 PEER_CAP_ORF_PREFIX_RM_ADV)
7867 || CHECK_FLAG(p->af_cap[afi][safi],
7868 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7869 vty_out(vty,
7870 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7871 ORF_TYPE_PREFIX);
7872 bgp_show_peer_afi_orf_cap(
7873 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7874 PEER_CAP_ORF_PREFIX_RM_ADV,
7875 PEER_CAP_ORF_PREFIX_SM_RCV,
7876 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7877 }
7878 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7879 || CHECK_FLAG(p->af_cap[afi][safi],
7880 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7881 || CHECK_FLAG(p->af_cap[afi][safi],
7882 PEER_CAP_ORF_PREFIX_RM_ADV)
7883 || CHECK_FLAG(p->af_cap[afi][safi],
7884 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7885 vty_out(vty,
7886 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7887 ORF_TYPE_PREFIX_OLD);
7888 bgp_show_peer_afi_orf_cap(
7889 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7890 PEER_CAP_ORF_PREFIX_RM_ADV,
7891 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7892 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7893 }
7894
7895 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7896 orf_pfx_count = prefix_bgp_show_prefix_list(
7897 NULL, afi, orf_pfx_name, use_json);
7898
7899 if (CHECK_FLAG(p->af_sflags[afi][safi],
7900 PEER_STATUS_ORF_PREFIX_SEND)
7901 || orf_pfx_count) {
7902 vty_out(vty, " Outbound Route Filter (ORF):");
7903 if (CHECK_FLAG(p->af_sflags[afi][safi],
7904 PEER_STATUS_ORF_PREFIX_SEND))
7905 vty_out(vty, " sent;");
7906 if (orf_pfx_count)
7907 vty_out(vty, " received (%d entries)",
7908 orf_pfx_count);
7909 vty_out(vty, "\n");
7910 }
7911 if (CHECK_FLAG(p->af_sflags[afi][safi],
7912 PEER_STATUS_ORF_WAIT_REFRESH))
7913 vty_out(vty,
7914 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
7915
7916 if (CHECK_FLAG(p->af_flags[afi][safi],
7917 PEER_FLAG_REFLECTOR_CLIENT))
7918 vty_out(vty, " Route-Reflector Client\n");
7919 if (CHECK_FLAG(p->af_flags[afi][safi],
7920 PEER_FLAG_RSERVER_CLIENT))
7921 vty_out(vty, " Route-Server Client\n");
7922 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7923 vty_out(vty,
7924 " Inbound soft reconfiguration allowed\n");
7925
7926 if (CHECK_FLAG(p->af_flags[afi][safi],
7927 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7928 vty_out(vty,
7929 " Private AS numbers (all) replaced in updates to this neighbor\n");
7930 else if (CHECK_FLAG(p->af_flags[afi][safi],
7931 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7932 vty_out(vty,
7933 " Private AS numbers replaced in updates to this neighbor\n");
7934 else if (CHECK_FLAG(p->af_flags[afi][safi],
7935 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7936 vty_out(vty,
7937 " Private AS numbers (all) removed in updates to this neighbor\n");
7938 else if (CHECK_FLAG(p->af_flags[afi][safi],
7939 PEER_FLAG_REMOVE_PRIVATE_AS))
7940 vty_out(vty,
7941 " Private AS numbers removed in updates to this neighbor\n");
7942
7943 if (CHECK_FLAG(p->af_flags[afi][safi],
7944 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7945 vty_out(vty, " Advertise all paths via addpath\n");
7946
7947 if (CHECK_FLAG(p->af_flags[afi][safi],
7948 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7949 vty_out(vty,
7950 " Advertise bestpath per AS via addpath\n");
7951
7952 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7953 vty_out(vty,
7954 " Override ASNs in outbound updates if aspath equals remote-as\n");
7955
7956 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7957 || CHECK_FLAG(p->af_flags[afi][safi],
7958 PEER_FLAG_FORCE_NEXTHOP_SELF))
7959 vty_out(vty, " NEXT_HOP is always this router\n");
7960 if (CHECK_FLAG(p->af_flags[afi][safi],
7961 PEER_FLAG_AS_PATH_UNCHANGED))
7962 vty_out(vty,
7963 " AS_PATH is propagated unchanged to this neighbor\n");
7964 if (CHECK_FLAG(p->af_flags[afi][safi],
7965 PEER_FLAG_NEXTHOP_UNCHANGED))
7966 vty_out(vty,
7967 " NEXT_HOP is propagated unchanged to this neighbor\n");
7968 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7969 vty_out(vty,
7970 " MED is propagated unchanged to this neighbor\n");
7971 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7972 || CHECK_FLAG(p->af_flags[afi][safi],
7973 PEER_FLAG_SEND_EXT_COMMUNITY)
7974 || CHECK_FLAG(p->af_flags[afi][safi],
7975 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
7976 vty_out(vty,
7977 " Community attribute sent to this neighbor");
7978 if (CHECK_FLAG(p->af_flags[afi][safi],
7979 PEER_FLAG_SEND_COMMUNITY)
7980 && CHECK_FLAG(p->af_flags[afi][safi],
7981 PEER_FLAG_SEND_EXT_COMMUNITY)
7982 && CHECK_FLAG(p->af_flags[afi][safi],
7983 PEER_FLAG_SEND_LARGE_COMMUNITY))
7984 vty_out(vty, "(all)\n");
7985 else if (CHECK_FLAG(p->af_flags[afi][safi],
7986 PEER_FLAG_SEND_LARGE_COMMUNITY))
7987 vty_out(vty, "(large)\n");
7988 else if (CHECK_FLAG(p->af_flags[afi][safi],
7989 PEER_FLAG_SEND_EXT_COMMUNITY))
7990 vty_out(vty, "(extended)\n");
7991 else
7992 vty_out(vty, "(standard)\n");
7993 }
7994 if (CHECK_FLAG(p->af_flags[afi][safi],
7995 PEER_FLAG_DEFAULT_ORIGINATE)) {
7996 vty_out(vty, " Default information originate,");
7997
7998 if (p->default_rmap[afi][safi].name)
7999 vty_out(vty, " default route-map %s%s,",
8000 p->default_rmap[afi][safi].map ? "*"
8001 : "",
8002 p->default_rmap[afi][safi].name);
8003 if (paf && PAF_SUBGRP(paf)
8004 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8005 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8006 vty_out(vty, " default sent\n");
8007 else
8008 vty_out(vty, " default not sent\n");
8009 }
8010
dff8f48d
MK
8011 /* advertise-vni-all */
8012 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8013 if (is_evpn_enabled())
dff8f48d
MK
8014 vty_out(vty, " advertise-all-vni\n");
8015 }
8016
d62a17ae 8017 if (filter->plist[FILTER_IN].name
8018 || filter->dlist[FILTER_IN].name
8019 || filter->aslist[FILTER_IN].name
8020 || filter->map[RMAP_IN].name)
8021 vty_out(vty, " Inbound path policy configured\n");
8022 if (filter->plist[FILTER_OUT].name
8023 || filter->dlist[FILTER_OUT].name
8024 || filter->aslist[FILTER_OUT].name
8025 || filter->map[RMAP_OUT].name || filter->usmap.name)
8026 vty_out(vty, " Outbound path policy configured\n");
8027
8028 /* prefix-list */
8029 if (filter->plist[FILTER_IN].name)
8030 vty_out(vty,
8031 " Incoming update prefix filter list is %s%s\n",
8032 filter->plist[FILTER_IN].plist ? "*" : "",
8033 filter->plist[FILTER_IN].name);
8034 if (filter->plist[FILTER_OUT].name)
8035 vty_out(vty,
8036 " Outgoing update prefix filter list is %s%s\n",
8037 filter->plist[FILTER_OUT].plist ? "*" : "",
8038 filter->plist[FILTER_OUT].name);
8039
8040 /* distribute-list */
8041 if (filter->dlist[FILTER_IN].name)
8042 vty_out(vty,
8043 " Incoming update network filter list is %s%s\n",
8044 filter->dlist[FILTER_IN].alist ? "*" : "",
8045 filter->dlist[FILTER_IN].name);
8046 if (filter->dlist[FILTER_OUT].name)
8047 vty_out(vty,
8048 " Outgoing update network filter list is %s%s\n",
8049 filter->dlist[FILTER_OUT].alist ? "*" : "",
8050 filter->dlist[FILTER_OUT].name);
8051
8052 /* filter-list. */
8053 if (filter->aslist[FILTER_IN].name)
8054 vty_out(vty,
8055 " Incoming update AS path filter list is %s%s\n",
8056 filter->aslist[FILTER_IN].aslist ? "*" : "",
8057 filter->aslist[FILTER_IN].name);
8058 if (filter->aslist[FILTER_OUT].name)
8059 vty_out(vty,
8060 " Outgoing update AS path filter list is %s%s\n",
8061 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8062 filter->aslist[FILTER_OUT].name);
8063
8064 /* route-map. */
8065 if (filter->map[RMAP_IN].name)
8066 vty_out(vty,
8067 " Route map for incoming advertisements is %s%s\n",
8068 filter->map[RMAP_IN].map ? "*" : "",
8069 filter->map[RMAP_IN].name);
8070 if (filter->map[RMAP_OUT].name)
8071 vty_out(vty,
8072 " Route map for outgoing advertisements is %s%s\n",
8073 filter->map[RMAP_OUT].map ? "*" : "",
8074 filter->map[RMAP_OUT].name);
8075
8076 /* unsuppress-map */
8077 if (filter->usmap.name)
8078 vty_out(vty,
8079 " Route map for selective unsuppress is %s%s\n",
8080 filter->usmap.map ? "*" : "",
8081 filter->usmap.name);
8082
8083 /* Receive prefix count */
8084 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8085
8086 /* Maximum prefix */
8087 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8088 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8089 p->pmax[afi][safi],
8090 CHECK_FLAG(p->af_flags[afi][safi],
8091 PEER_FLAG_MAX_PREFIX_WARNING)
8092 ? " (warning-only)"
8093 : "");
8094 vty_out(vty, " Threshold for warning message %d%%",
8095 p->pmax_threshold[afi][safi]);
8096 if (p->pmax_restart[afi][safi])
8097 vty_out(vty, ", restart interval %d min",
8098 p->pmax_restart[afi][safi]);
8099 vty_out(vty, "\n");
8100 }
8101
8102 vty_out(vty, "\n");
8103 }
8104}
8105
8106static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
8107 json_object *json)
718e3744 8108{
d62a17ae 8109 struct bgp *bgp;
8110 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8111 char timebuf[BGP_UPTIME_LEN];
8112 char dn_flag[2];
8113 const char *subcode_str;
8114 const char *code_str;
8115 afi_t afi;
8116 safi_t safi;
8117 u_int16_t i;
8118 u_char *msg;
8119 json_object *json_neigh = NULL;
8120 time_t epoch_tbuf;
718e3744 8121
d62a17ae 8122 bgp = p->bgp;
8123
8124 if (use_json)
8125 json_neigh = json_object_new_object();
8126
8127 memset(dn_flag, '\0', sizeof(dn_flag));
8128 if (!p->conf_if && peer_dynamic_neighbor(p))
8129 dn_flag[0] = '*';
8130
8131 if (!use_json) {
8132 if (p->conf_if) /* Configured interface name. */
8133 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8134 BGP_PEER_SU_UNSPEC(p)
8135 ? "None"
8136 : sockunion2str(&p->su, buf,
8137 SU_ADDRSTRLEN));
8138 else /* Configured IP address. */
8139 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8140 p->host);
8141 }
8142
8143 if (use_json) {
8144 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8145 json_object_string_add(json_neigh, "bgpNeighborAddr",
8146 "none");
8147 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8148 json_object_string_add(
8149 json_neigh, "bgpNeighborAddr",
8150 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8151
8152 json_object_int_add(json_neigh, "remoteAs", p->as);
8153
8154 if (p->change_local_as)
8155 json_object_int_add(json_neigh, "localAs",
8156 p->change_local_as);
8157 else
8158 json_object_int_add(json_neigh, "localAs", p->local_as);
8159
8160 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8161 json_object_boolean_true_add(json_neigh,
8162 "localAsNoPrepend");
8163
8164 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8165 json_object_boolean_true_add(json_neigh,
8166 "localAsReplaceAs");
8167 } else {
8168 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8169 || (p->as_type == AS_INTERNAL))
8170 vty_out(vty, "remote AS %u, ", p->as);
8171 else
8172 vty_out(vty, "remote AS Unspecified, ");
8173 vty_out(vty, "local AS %u%s%s, ",
8174 p->change_local_as ? p->change_local_as : p->local_as,
8175 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8176 ? " no-prepend"
8177 : "",
8178 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8179 ? " replace-as"
8180 : "");
8181 }
8182 /* peer type internal, external, confed-internal or confed-external */
8183 if (p->as == p->local_as) {
8184 if (use_json) {
8185 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8186 json_object_boolean_true_add(
8187 json_neigh, "nbrConfedInternalLink");
8188 else
8189 json_object_boolean_true_add(json_neigh,
8190 "nbrInternalLink");
8191 } else {
8192 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8193 vty_out(vty, "confed-internal link\n");
8194 else
8195 vty_out(vty, "internal link\n");
8196 }
8197 } else {
8198 if (use_json) {
8199 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8200 json_object_boolean_true_add(
8201 json_neigh, "nbrConfedExternalLink");
8202 else
8203 json_object_boolean_true_add(json_neigh,
8204 "nbrExternalLink");
8205 } else {
8206 if (bgp_confederation_peers_check(bgp, p->as))
8207 vty_out(vty, "confed-external link\n");
8208 else
8209 vty_out(vty, "external link\n");
8210 }
8211 }
8212
8213 /* Description. */
8214 if (p->desc) {
8215 if (use_json)
8216 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8217 else
8218 vty_out(vty, " Description: %s\n", p->desc);
8219 }
8220
8221 if (p->hostname) {
8222 if (use_json) {
8223 if (p->hostname)
8224 json_object_string_add(json_neigh, "hostname",
8225 p->hostname);
8226
8227 if (p->domainname)
8228 json_object_string_add(json_neigh, "domainname",
8229 p->domainname);
8230 } else {
8231 if (p->domainname && (p->domainname[0] != '\0'))
8232 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8233 p->domainname);
8234 else
8235 vty_out(vty, "Hostname: %s\n", p->hostname);
8236 }
8237 }
8238
8239 /* Peer-group */
8240 if (p->group) {
8241 if (use_json) {
8242 json_object_string_add(json_neigh, "peerGroup",
8243 p->group->name);
8244
8245 if (dn_flag[0]) {
8246 struct prefix prefix, *range = NULL;
8247
8248 sockunion2hostprefix(&(p->su), &prefix);
8249 range = peer_group_lookup_dynamic_neighbor_range(
8250 p->group, &prefix);
8251
8252 if (range) {
8253 prefix2str(range, buf1, sizeof(buf1));
8254 json_object_string_add(
8255 json_neigh,
8256 "peerSubnetRangeGroup", buf1);
8257 }
8258 }
8259 } else {
8260 vty_out(vty,
8261 " Member of peer-group %s for session parameters\n",
8262 p->group->name);
8263
8264 if (dn_flag[0]) {
8265 struct prefix prefix, *range = NULL;
8266
8267 sockunion2hostprefix(&(p->su), &prefix);
8268 range = peer_group_lookup_dynamic_neighbor_range(
8269 p->group, &prefix);
8270
8271 if (range) {
8272 prefix2str(range, buf1, sizeof(buf1));
8273 vty_out(vty,
8274 " Belongs to the subnet range group: %s\n",
8275 buf1);
8276 }
8277 }
8278 }
8279 }
8280
8281 if (use_json) {
8282 /* Administrative shutdown. */
8283 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8284 json_object_boolean_true_add(json_neigh,
8285 "adminShutDown");
8286
8287 /* BGP Version. */
8288 json_object_int_add(json_neigh, "bgpVersion", 4);
8289 json_object_string_add(
8290 json_neigh, "remoteRouterId",
8291 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8292
8293 /* Confederation */
8294 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8295 && bgp_confederation_peers_check(bgp, p->as))
8296 json_object_boolean_true_add(json_neigh,
8297 "nbrCommonAdmin");
8298
8299 /* Status. */
8300 json_object_string_add(
8301 json_neigh, "bgpState",
8302 lookup_msg(bgp_status_msg, p->status, NULL));
8303
8304 if (p->status == Established) {
8305 time_t uptime;
d62a17ae 8306
8307 uptime = bgp_clock();
8308 uptime -= p->uptime;
d62a17ae 8309 epoch_tbuf = time(NULL) - uptime;
8310
d3c7efed 8311#if CONFDATE > 20200101
a4d82a8a
PZ
8312 CPP_NOTICE(
8313 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
8314#endif
8315 /*
8316 * bgpTimerUp was miliseconds that was accurate
8317 * up to 1 day, then the value returned
8318 * became garbage. So in order to provide
8319 * some level of backwards compatability,
8320 * we still provde the data, but now
8321 * we are returning the correct value
8322 * and also adding a new bgpTimerUpMsec
8323 * which will allow us to deprecate
8324 * this eventually
8325 */
d62a17ae 8326 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 8327 uptime * 1000);
d3c7efed
DS
8328 json_object_int_add(json_neigh, "bgpTimerUpMsec",
8329 uptime * 1000);
d62a17ae 8330 json_object_string_add(json_neigh, "bgpTimerUpString",
8331 peer_uptime(p->uptime, timebuf,
8332 BGP_UPTIME_LEN, 0,
8333 NULL));
8334 json_object_int_add(json_neigh,
8335 "bgpTimerUpEstablishedEpoch",
8336 epoch_tbuf);
8337 }
8338
8339 else if (p->status == Active) {
8340 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8341 json_object_string_add(json_neigh, "bgpStateIs",
8342 "passive");
8343 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8344 json_object_string_add(json_neigh, "bgpStateIs",
8345 "passiveNSF");
8346 }
8347
8348 /* read timer */
8349 time_t uptime;
8350 struct tm *tm;
8351
8352 uptime = bgp_clock();
8353 uptime -= p->readtime;
8354 tm = gmtime(&uptime);
8355 json_object_int_add(json_neigh, "bgpTimerLastRead",
8356 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8357 + (tm->tm_hour * 3600000));
8358
8359 uptime = bgp_clock();
8360 uptime -= p->last_write;
8361 tm = gmtime(&uptime);
8362 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8363 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8364 + (tm->tm_hour * 3600000));
8365
8366 uptime = bgp_clock();
8367 uptime -= p->update_time;
8368 tm = gmtime(&uptime);
8369 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8370 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8371 + (tm->tm_hour * 3600000));
8372
8373 /* Configured timer values. */
8374 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8375 p->v_holdtime * 1000);
8376 json_object_int_add(json_neigh,
8377 "bgpTimerKeepAliveIntervalMsecs",
8378 p->v_keepalive * 1000);
8379
d25e4efc 8380 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8381 json_object_int_add(json_neigh,
8382 "bgpTimerConfiguredHoldTimeMsecs",
8383 p->holdtime * 1000);
8384 json_object_int_add(
8385 json_neigh,
8386 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8387 p->keepalive * 1000);
d25e4efc 8388 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
8389 || (bgp->default_keepalive
8390 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
8391 json_object_int_add(json_neigh,
8392 "bgpTimerConfiguredHoldTimeMsecs",
8393 bgp->default_holdtime);
8394 json_object_int_add(
8395 json_neigh,
8396 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8397 bgp->default_keepalive);
d62a17ae 8398 }
8399 } else {
8400 /* Administrative shutdown. */
8401 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8402 vty_out(vty, " Administratively shut down\n");
8403
8404 /* BGP Version. */
8405 vty_out(vty, " BGP version 4");
8406 vty_out(vty, ", remote router ID %s\n",
8407 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8408
8409 /* Confederation */
8410 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8411 && bgp_confederation_peers_check(bgp, p->as))
8412 vty_out(vty,
8413 " Neighbor under common administration\n");
8414
8415 /* Status. */
8416 vty_out(vty, " BGP state = %s",
8417 lookup_msg(bgp_status_msg, p->status, NULL));
8418
8419 if (p->status == Established)
8420 vty_out(vty, ", up for %8s",
8421 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8422 0, NULL));
8423
8424 else if (p->status == Active) {
8425 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8426 vty_out(vty, " (passive)");
8427 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8428 vty_out(vty, " (NSF passive)");
8429 }
8430 vty_out(vty, "\n");
8431
8432 /* read timer */
8433 vty_out(vty, " Last read %s",
8434 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8435 NULL));
8436 vty_out(vty, ", Last write %s\n",
8437 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8438 NULL));
8439
8440 /* Configured timer values. */
8441 vty_out(vty,
8442 " Hold time is %d, keepalive interval is %d seconds\n",
8443 p->v_holdtime, p->v_keepalive);
d25e4efc 8444 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8445 vty_out(vty, " Configured hold time is %d",
8446 p->holdtime);
8447 vty_out(vty, ", keepalive interval is %d seconds\n",
8448 p->keepalive);
d25e4efc 8449 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
8450 || (bgp->default_keepalive
8451 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
8452 vty_out(vty, " Configured hold time is %d",
8453 bgp->default_holdtime);
8454 vty_out(vty, ", keepalive interval is %d seconds\n",
8455 bgp->default_keepalive);
d62a17ae 8456 }
8457 }
8458 /* Capability. */
8459 if (p->status == Established) {
8460 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8461 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8462 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8463 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8464 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8465 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8466 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8467 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8468 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8469 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8470 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8471 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8472 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8473 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8474 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8475 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8476 if (use_json) {
8477 json_object *json_cap = NULL;
8478
8479 json_cap = json_object_new_object();
8480
8481 /* AS4 */
8482 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8483 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8484 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8485 && CHECK_FLAG(p->cap,
8486 PEER_CAP_AS4_RCV))
8487 json_object_string_add(
8488 json_cap, "4byteAs",
8489 "advertisedAndReceived");
8490 else if (CHECK_FLAG(p->cap,
8491 PEER_CAP_AS4_ADV))
8492 json_object_string_add(
8493 json_cap, "4byteAs",
8494 "advertised");
8495 else if (CHECK_FLAG(p->cap,
8496 PEER_CAP_AS4_RCV))
8497 json_object_string_add(
8498 json_cap, "4byteAs",
8499 "received");
8500 }
8501
8502 /* AddPath */
8503 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8504 || CHECK_FLAG(p->cap,
8505 PEER_CAP_ADDPATH_ADV)) {
8506 json_object *json_add = NULL;
8507 const char *print_store;
8508
8509 json_add = json_object_new_object();
8510
05c7a1cc
QY
8511 FOREACH_AFI_SAFI (afi, safi) {
8512 json_object *json_sub = NULL;
8513 json_sub =
8514 json_object_new_object();
8515 print_store = afi_safi_print(
8516 afi, safi);
d62a17ae 8517
05c7a1cc
QY
8518 if (CHECK_FLAG(
8519 p->af_cap[afi]
8520 [safi],
8521 PEER_CAP_ADDPATH_AF_TX_ADV)
8522 || CHECK_FLAG(
8523 p->af_cap[afi]
8524 [safi],
8525 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 8526 if (CHECK_FLAG(
8527 p->af_cap
8528 [afi]
8529 [safi],
8530 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 8531 && CHECK_FLAG(
d62a17ae 8532 p->af_cap
8533 [afi]
8534 [safi],
05c7a1cc
QY
8535 PEER_CAP_ADDPATH_AF_TX_RCV))
8536 json_object_boolean_true_add(
8537 json_sub,
8538 "txAdvertisedAndReceived");
8539 else if (
8540 CHECK_FLAG(
8541 p->af_cap
8542 [afi]
8543 [safi],
8544 PEER_CAP_ADDPATH_AF_TX_ADV))
8545 json_object_boolean_true_add(
8546 json_sub,
8547 "txAdvertised");
8548 else if (
8549 CHECK_FLAG(
8550 p->af_cap
8551 [afi]
8552 [safi],
8553 PEER_CAP_ADDPATH_AF_TX_RCV))
8554 json_object_boolean_true_add(
8555 json_sub,
8556 "txReceived");
8557 }
d62a17ae 8558
05c7a1cc
QY
8559 if (CHECK_FLAG(
8560 p->af_cap[afi]
8561 [safi],
8562 PEER_CAP_ADDPATH_AF_RX_ADV)
8563 || CHECK_FLAG(
8564 p->af_cap[afi]
8565 [safi],
8566 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 8567 if (CHECK_FLAG(
8568 p->af_cap
8569 [afi]
8570 [safi],
8571 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 8572 && CHECK_FLAG(
d62a17ae 8573 p->af_cap
8574 [afi]
8575 [safi],
8576 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
8577 json_object_boolean_true_add(
8578 json_sub,
8579 "rxAdvertisedAndReceived");
8580 else if (
8581 CHECK_FLAG(
8582 p->af_cap
8583 [afi]
8584 [safi],
8585 PEER_CAP_ADDPATH_AF_RX_ADV))
8586 json_object_boolean_true_add(
8587 json_sub,
8588 "rxAdvertised");
8589 else if (
8590 CHECK_FLAG(
8591 p->af_cap
8592 [afi]
8593 [safi],
8594 PEER_CAP_ADDPATH_AF_RX_RCV))
8595 json_object_boolean_true_add(
8596 json_sub,
8597 "rxReceived");
d62a17ae 8598 }
8599
05c7a1cc
QY
8600 if (CHECK_FLAG(
8601 p->af_cap[afi]
8602 [safi],
8603 PEER_CAP_ADDPATH_AF_TX_ADV)
8604 || CHECK_FLAG(
8605 p->af_cap[afi]
8606 [safi],
8607 PEER_CAP_ADDPATH_AF_TX_RCV)
8608 || CHECK_FLAG(
8609 p->af_cap[afi]
8610 [safi],
8611 PEER_CAP_ADDPATH_AF_RX_ADV)
8612 || CHECK_FLAG(
8613 p->af_cap[afi]
8614 [safi],
8615 PEER_CAP_ADDPATH_AF_RX_RCV))
8616 json_object_object_add(
8617 json_add,
8618 print_store,
8619 json_sub);
8620 else
8621 json_object_free(
8622 json_sub);
8623 }
8624
d62a17ae 8625 json_object_object_add(
8626 json_cap, "addPath", json_add);
8627 }
8628
8629 /* Dynamic */
8630 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8631 || CHECK_FLAG(p->cap,
8632 PEER_CAP_DYNAMIC_ADV)) {
8633 if (CHECK_FLAG(p->cap,
8634 PEER_CAP_DYNAMIC_ADV)
8635 && CHECK_FLAG(p->cap,
8636 PEER_CAP_DYNAMIC_RCV))
8637 json_object_string_add(
8638 json_cap, "dynamic",
8639 "advertisedAndReceived");
8640 else if (CHECK_FLAG(
8641 p->cap,
8642 PEER_CAP_DYNAMIC_ADV))
8643 json_object_string_add(
8644 json_cap, "dynamic",
8645 "advertised");
8646 else if (CHECK_FLAG(
8647 p->cap,
8648 PEER_CAP_DYNAMIC_RCV))
8649 json_object_string_add(
8650 json_cap, "dynamic",
8651 "received");
8652 }
8653
8654 /* Extended nexthop */
8655 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8656 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8657 json_object *json_nxt = NULL;
8658 const char *print_store;
8659
8660
8661 if (CHECK_FLAG(p->cap,
8662 PEER_CAP_ENHE_ADV)
8663 && CHECK_FLAG(p->cap,
8664 PEER_CAP_ENHE_RCV))
8665 json_object_string_add(
8666 json_cap,
8667 "extendedNexthop",
8668 "advertisedAndReceived");
8669 else if (CHECK_FLAG(p->cap,
8670 PEER_CAP_ENHE_ADV))
8671 json_object_string_add(
8672 json_cap,
8673 "extendedNexthop",
8674 "advertised");
8675 else if (CHECK_FLAG(p->cap,
8676 PEER_CAP_ENHE_RCV))
8677 json_object_string_add(
8678 json_cap,
8679 "extendedNexthop",
8680 "received");
8681
8682 if (CHECK_FLAG(p->cap,
8683 PEER_CAP_ENHE_RCV)) {
8684 json_nxt =
8685 json_object_new_object();
8686
8687 for (safi = SAFI_UNICAST;
8688 safi < SAFI_MAX; safi++) {
8689 if (CHECK_FLAG(
8690 p->af_cap
8691 [AFI_IP]
8692 [safi],
8693 PEER_CAP_ENHE_AF_RCV)) {
8694 print_store = afi_safi_print(
8695 AFI_IP,
8696 safi);
8697 json_object_string_add(
8698 json_nxt,
8699 print_store,
8700 "recieved");
8701 }
8702 }
8703 json_object_object_add(
8704 json_cap,
8705 "extendedNexthopFamililesByPeer",
8706 json_nxt);
8707 }
8708 }
8709
8710 /* Route Refresh */
8711 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8712 || CHECK_FLAG(p->cap,
8713 PEER_CAP_REFRESH_NEW_RCV)
8714 || CHECK_FLAG(p->cap,
8715 PEER_CAP_REFRESH_OLD_RCV)) {
8716 if (CHECK_FLAG(p->cap,
8717 PEER_CAP_REFRESH_ADV)
8718 && (CHECK_FLAG(
8719 p->cap,
8720 PEER_CAP_REFRESH_NEW_RCV)
8721 || CHECK_FLAG(
8722 p->cap,
8723 PEER_CAP_REFRESH_OLD_RCV))) {
8724 if (CHECK_FLAG(
8725 p->cap,
8726 PEER_CAP_REFRESH_OLD_RCV)
8727 && CHECK_FLAG(
8728 p->cap,
8729 PEER_CAP_REFRESH_NEW_RCV))
8730 json_object_string_add(
8731 json_cap,
8732 "routeRefresh",
8733 "advertisedAndReceivedOldNew");
8734 else {
8735 if (CHECK_FLAG(
8736 p->cap,
8737 PEER_CAP_REFRESH_OLD_RCV))
8738 json_object_string_add(
8739 json_cap,
8740 "routeRefresh",
8741 "advertisedAndReceivedOld");
8742 else
8743 json_object_string_add(
8744 json_cap,
8745 "routeRefresh",
8746 "advertisedAndReceivedNew");
8747 }
8748 } else if (
8749 CHECK_FLAG(
8750 p->cap,
8751 PEER_CAP_REFRESH_ADV))
8752 json_object_string_add(
8753 json_cap,
8754 "routeRefresh",
8755 "advertised");
8756 else if (
8757 CHECK_FLAG(
8758 p->cap,
8759 PEER_CAP_REFRESH_NEW_RCV)
8760 || CHECK_FLAG(
8761 p->cap,
8762 PEER_CAP_REFRESH_OLD_RCV))
8763 json_object_string_add(
8764 json_cap,
8765 "routeRefresh",
8766 "received");
8767 }
8768
8769 /* Multiprotocol Extensions */
8770 json_object *json_multi = NULL;
8771 json_multi = json_object_new_object();
8772
05c7a1cc
QY
8773 FOREACH_AFI_SAFI (afi, safi) {
8774 if (p->afc_adv[afi][safi]
8775 || p->afc_recv[afi][safi]) {
8776 json_object *json_exten = NULL;
8777 json_exten =
8778 json_object_new_object();
8779
d62a17ae 8780 if (p->afc_adv[afi][safi]
05c7a1cc
QY
8781 && p->afc_recv[afi][safi])
8782 json_object_boolean_true_add(
8783 json_exten,
8784 "advertisedAndReceived");
8785 else if (p->afc_adv[afi][safi])
8786 json_object_boolean_true_add(
8787 json_exten,
8788 "advertised");
8789 else if (p->afc_recv[afi][safi])
8790 json_object_boolean_true_add(
8791 json_exten,
8792 "received");
d62a17ae 8793
05c7a1cc
QY
8794 json_object_object_add(
8795 json_multi,
8796 afi_safi_print(afi,
8797 safi),
8798 json_exten);
d62a17ae 8799 }
8800 }
8801 json_object_object_add(
8802 json_cap, "multiprotocolExtensions",
8803 json_multi);
8804
d77114b7 8805 /* Hostname capabilities */
60466a63 8806 json_object *json_hname = NULL;
d77114b7
MK
8807
8808 json_hname = json_object_new_object();
8809
8810 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
8811 json_object_string_add(
60466a63
QY
8812 json_hname, "advHostName",
8813 bgp->peer_self->hostname
8814 ? bgp->peer_self
8815 ->hostname
d77114b7
MK
8816 : "n/a");
8817 json_object_string_add(
60466a63
QY
8818 json_hname, "advDomainName",
8819 bgp->peer_self->domainname
8820 ? bgp->peer_self
8821 ->domainname
d77114b7
MK
8822 : "n/a");
8823 }
8824
8825
8826 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
8827 json_object_string_add(
60466a63
QY
8828 json_hname, "rcvHostName",
8829 p->hostname ? p->hostname
8830 : "n/a");
d77114b7 8831 json_object_string_add(
60466a63
QY
8832 json_hname, "rcvDomainName",
8833 p->domainname ? p->domainname
8834 : "n/a");
d77114b7
MK
8835 }
8836
60466a63 8837 json_object_object_add(json_cap, "hostName",
d77114b7
MK
8838 json_hname);
8839
d62a17ae 8840 /* Gracefull Restart */
8841 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
8842 || CHECK_FLAG(p->cap,
8843 PEER_CAP_RESTART_ADV)) {
8844 if (CHECK_FLAG(p->cap,
8845 PEER_CAP_RESTART_ADV)
8846 && CHECK_FLAG(p->cap,
8847 PEER_CAP_RESTART_RCV))
8848 json_object_string_add(
8849 json_cap,
8850 "gracefulRestart",
8851 "advertisedAndReceived");
8852 else if (CHECK_FLAG(
8853 p->cap,
8854 PEER_CAP_RESTART_ADV))
8855 json_object_string_add(
8856 json_cap,
8857 "gracefulRestartCapability",
8858 "advertised");
8859 else if (CHECK_FLAG(
8860 p->cap,
8861 PEER_CAP_RESTART_RCV))
8862 json_object_string_add(
8863 json_cap,
8864 "gracefulRestartCapability",
8865 "received");
8866
8867 if (CHECK_FLAG(p->cap,
8868 PEER_CAP_RESTART_RCV)) {
8869 int restart_af_count = 0;
8870 json_object *json_restart =
8871 NULL;
8872 json_restart =
8873 json_object_new_object();
8874
8875 json_object_int_add(
8876 json_cap,
8877 "gracefulRestartRemoteTimerMsecs",
8878 p->v_gr_restart * 1000);
8879
05c7a1cc
QY
8880 FOREACH_AFI_SAFI (afi, safi) {
8881 if (CHECK_FLAG(
8882 p->af_cap
8883 [afi]
8884 [safi],
8885 PEER_CAP_RESTART_AF_RCV)) {
8886 json_object *
8887 json_sub =
8888 NULL;
8889 json_sub =
8890 json_object_new_object();
8891
d62a17ae 8892 if (CHECK_FLAG(
8893 p->af_cap
8894 [afi]
8895 [safi],
05c7a1cc
QY
8896 PEER_CAP_RESTART_AF_PRESERVE_RCV))
8897 json_object_boolean_true_add(
8898 json_sub,
8899 "preserved");
8900 restart_af_count++;
8901 json_object_object_add(
8902 json_restart,
8903 afi_safi_print(
8904 afi,
8905 safi),
8906 json_sub);
d62a17ae 8907 }
8908 }
8909 if (!restart_af_count) {
8910 json_object_string_add(
8911 json_cap,
8912 "addressFamiliesByPeer",
8913 "none");
8914 json_object_free(
8915 json_restart);
8916 } else
8917 json_object_object_add(
8918 json_cap,
8919 "addressFamiliesByPeer",
8920 json_restart);
8921 }
8922 }
8923 json_object_object_add(json_neigh,
8924 "neighborCapabilities",
8925 json_cap);
8926 } else {
8927 vty_out(vty, " Neighbor capabilities:\n");
8928
8929 /* AS4 */
8930 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8931 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8932 vty_out(vty, " 4 Byte AS:");
8933 if (CHECK_FLAG(p->cap,
8934 PEER_CAP_AS4_ADV))
8935 vty_out(vty, " advertised");
8936 if (CHECK_FLAG(p->cap,
8937 PEER_CAP_AS4_RCV))
8938 vty_out(vty, " %sreceived",
8939 CHECK_FLAG(
8940 p->cap,
8941 PEER_CAP_AS4_ADV)
8942 ? "and "
8943 : "");
8944 vty_out(vty, "\n");
8945 }
8946
8947 /* AddPath */
8948 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8949 || CHECK_FLAG(p->cap,
8950 PEER_CAP_ADDPATH_ADV)) {
8951 vty_out(vty, " AddPath:\n");
8952
05c7a1cc
QY
8953 FOREACH_AFI_SAFI (afi, safi) {
8954 if (CHECK_FLAG(
8955 p->af_cap[afi]
8956 [safi],
8957 PEER_CAP_ADDPATH_AF_TX_ADV)
8958 || CHECK_FLAG(
8959 p->af_cap[afi]
8960 [safi],
8961 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8962 vty_out(vty,
8963 " %s: TX ",
8964 afi_safi_print(
8965 afi,
8966 safi));
8967
d62a17ae 8968 if (CHECK_FLAG(
8969 p->af_cap
8970 [afi]
8971 [safi],
05c7a1cc 8972 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 8973 vty_out(vty,
05c7a1cc 8974 "advertised %s",
d62a17ae 8975 afi_safi_print(
8976 afi,
8977 safi));
8978
05c7a1cc
QY
8979 if (CHECK_FLAG(
8980 p->af_cap
8981 [afi]
8982 [safi],
8983 PEER_CAP_ADDPATH_AF_TX_RCV))
8984 vty_out(vty,
8985 "%sreceived",
8986 CHECK_FLAG(
8987 p->af_cap
8988 [afi]
8989 [safi],
8990 PEER_CAP_ADDPATH_AF_TX_ADV)
8991 ? " and "
8992 : "");
d62a17ae 8993
05c7a1cc
QY
8994 vty_out(vty, "\n");
8995 }
d62a17ae 8996
05c7a1cc
QY
8997 if (CHECK_FLAG(
8998 p->af_cap[afi]
8999 [safi],
9000 PEER_CAP_ADDPATH_AF_RX_ADV)
9001 || CHECK_FLAG(
9002 p->af_cap[afi]
9003 [safi],
9004 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9005 vty_out(vty,
9006 " %s: RX ",
9007 afi_safi_print(
9008 afi,
9009 safi));
d62a17ae 9010
9011 if (CHECK_FLAG(
9012 p->af_cap
9013 [afi]
9014 [safi],
05c7a1cc 9015 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9016 vty_out(vty,
05c7a1cc 9017 "advertised %s",
d62a17ae 9018 afi_safi_print(
9019 afi,
9020 safi));
9021
05c7a1cc
QY
9022 if (CHECK_FLAG(
9023 p->af_cap
9024 [afi]
9025 [safi],
9026 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9027 vty_out(vty,
05c7a1cc
QY
9028 "%sreceived",
9029 CHECK_FLAG(
9030 p->af_cap
9031 [afi]
9032 [safi],
9033 PEER_CAP_ADDPATH_AF_RX_ADV)
9034 ? " and "
9035 : "");
9036
9037 vty_out(vty, "\n");
d62a17ae 9038 }
05c7a1cc 9039 }
d62a17ae 9040 }
9041
9042 /* Dynamic */
9043 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9044 || CHECK_FLAG(p->cap,
9045 PEER_CAP_DYNAMIC_ADV)) {
9046 vty_out(vty, " Dynamic:");
9047 if (CHECK_FLAG(p->cap,
9048 PEER_CAP_DYNAMIC_ADV))
9049 vty_out(vty, " advertised");
9050 if (CHECK_FLAG(p->cap,
9051 PEER_CAP_DYNAMIC_RCV))
9052 vty_out(vty, " %sreceived",
9053 CHECK_FLAG(
9054 p->cap,
9055 PEER_CAP_DYNAMIC_ADV)
9056 ? "and "
9057 : "");
9058 vty_out(vty, "\n");
9059 }
9060
9061 /* Extended nexthop */
9062 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9063 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9064 vty_out(vty, " Extended nexthop:");
9065 if (CHECK_FLAG(p->cap,
9066 PEER_CAP_ENHE_ADV))
9067 vty_out(vty, " advertised");
9068 if (CHECK_FLAG(p->cap,
9069 PEER_CAP_ENHE_RCV))
9070 vty_out(vty, " %sreceived",
9071 CHECK_FLAG(
9072 p->cap,
9073 PEER_CAP_ENHE_ADV)
9074 ? "and "
9075 : "");
9076 vty_out(vty, "\n");
9077
9078 if (CHECK_FLAG(p->cap,
9079 PEER_CAP_ENHE_RCV)) {
9080 vty_out(vty,
9081 " Address families by peer:\n ");
9082 for (safi = SAFI_UNICAST;
9083 safi < SAFI_MAX; safi++)
9084 if (CHECK_FLAG(
9085 p->af_cap
9086 [AFI_IP]
9087 [safi],
9088 PEER_CAP_ENHE_AF_RCV))
9089 vty_out(vty,
9090 " %s\n",
9091 afi_safi_print(
9092 AFI_IP,
9093 safi));
9094 }
9095 }
9096
9097 /* Route Refresh */
9098 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9099 || CHECK_FLAG(p->cap,
9100 PEER_CAP_REFRESH_NEW_RCV)
9101 || CHECK_FLAG(p->cap,
9102 PEER_CAP_REFRESH_OLD_RCV)) {
9103 vty_out(vty, " Route refresh:");
9104 if (CHECK_FLAG(p->cap,
9105 PEER_CAP_REFRESH_ADV))
9106 vty_out(vty, " advertised");
9107 if (CHECK_FLAG(p->cap,
9108 PEER_CAP_REFRESH_NEW_RCV)
9109 || CHECK_FLAG(
9110 p->cap,
9111 PEER_CAP_REFRESH_OLD_RCV))
9112 vty_out(vty, " %sreceived(%s)",
9113 CHECK_FLAG(
9114 p->cap,
9115 PEER_CAP_REFRESH_ADV)
9116 ? "and "
9117 : "",
9118 (CHECK_FLAG(
9119 p->cap,
9120 PEER_CAP_REFRESH_OLD_RCV)
9121 && CHECK_FLAG(
9122 p->cap,
9123 PEER_CAP_REFRESH_NEW_RCV))
9124 ? "old & new"
9125 : CHECK_FLAG(
9126 p->cap,
9127 PEER_CAP_REFRESH_OLD_RCV)
9128 ? "old"
9129 : "new");
9130
9131 vty_out(vty, "\n");
9132 }
9133
9134 /* Multiprotocol Extensions */
05c7a1cc
QY
9135 FOREACH_AFI_SAFI (afi, safi)
9136 if (p->afc_adv[afi][safi]
9137 || p->afc_recv[afi][safi]) {
9138 vty_out(vty,
9139 " Address Family %s:",
9140 afi_safi_print(afi,
9141 safi));
9142 if (p->afc_adv[afi][safi])
d62a17ae 9143 vty_out(vty,
05c7a1cc
QY
9144 " advertised");
9145 if (p->afc_recv[afi][safi])
9146 vty_out(vty,
9147 " %sreceived",
9148 p->afc_adv[afi]
9149 [safi]
9150 ? "and "
9151 : "");
9152 vty_out(vty, "\n");
9153 }
d62a17ae 9154
9155 /* Hostname capability */
60466a63 9156 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9157
9158 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9159 vty_out(vty,
9160 " advertised (name: %s,domain name: %s)",
60466a63
QY
9161 bgp->peer_self->hostname
9162 ? bgp->peer_self
9163 ->hostname
d77114b7 9164 : "n/a",
60466a63
QY
9165 bgp->peer_self->domainname
9166 ? bgp->peer_self
9167 ->domainname
d77114b7
MK
9168 : "n/a");
9169 } else {
9170 vty_out(vty, " not advertised");
d62a17ae 9171 }
9172
d77114b7 9173 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9174 vty_out(vty,
9175 " received (name: %s,domain name: %s)",
60466a63
QY
9176 p->hostname ? p->hostname
9177 : "n/a",
9178 p->domainname ? p->domainname
9179 : "n/a");
d77114b7
MK
9180 } else {
9181 vty_out(vty, " not received");
9182 }
9183
9184 vty_out(vty, "\n");
9185
d62a17ae 9186 /* Gracefull Restart */
9187 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9188 || CHECK_FLAG(p->cap,
9189 PEER_CAP_RESTART_ADV)) {
9190 vty_out(vty,
9191 " Graceful Restart Capabilty:");
9192 if (CHECK_FLAG(p->cap,
9193 PEER_CAP_RESTART_ADV))
9194 vty_out(vty, " advertised");
9195 if (CHECK_FLAG(p->cap,
9196 PEER_CAP_RESTART_RCV))
9197 vty_out(vty, " %sreceived",
9198 CHECK_FLAG(
9199 p->cap,
9200 PEER_CAP_RESTART_ADV)
9201 ? "and "
9202 : "");
9203 vty_out(vty, "\n");
9204
9205 if (CHECK_FLAG(p->cap,
9206 PEER_CAP_RESTART_RCV)) {
9207 int restart_af_count = 0;
9208
9209 vty_out(vty,
9210 " Remote Restart timer is %d seconds\n",
9211 p->v_gr_restart);
9212 vty_out(vty,
9213 " Address families by peer:\n ");
9214
05c7a1cc
QY
9215 FOREACH_AFI_SAFI (afi, safi)
9216 if (CHECK_FLAG(
9217 p->af_cap
9218 [afi]
9219 [safi],
9220 PEER_CAP_RESTART_AF_RCV)) {
9221 vty_out(vty,
9222 "%s%s(%s)",
9223 restart_af_count
9224 ? ", "
9225 : "",
9226 afi_safi_print(
9227 afi,
9228 safi),
9229 CHECK_FLAG(
9230 p->af_cap
9231 [afi]
9232 [safi],
9233 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9234 ? "preserved"
9235 : "not preserved");
9236 restart_af_count++;
9237 }
d62a17ae 9238 if (!restart_af_count)
9239 vty_out(vty, "none");
9240 vty_out(vty, "\n");
9241 }
9242 }
9243 }
9244 }
9245 }
9246
9247 /* graceful restart information */
9248 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9249 || p->t_gr_stale) {
9250 json_object *json_grace = NULL;
9251 json_object *json_grace_send = NULL;
9252 json_object *json_grace_recv = NULL;
9253 int eor_send_af_count = 0;
9254 int eor_receive_af_count = 0;
9255
9256 if (use_json) {
9257 json_grace = json_object_new_object();
9258 json_grace_send = json_object_new_object();
9259 json_grace_recv = json_object_new_object();
9260
9261 if (p->status == Established) {
05c7a1cc
QY
9262 FOREACH_AFI_SAFI (afi, safi) {
9263 if (CHECK_FLAG(p->af_sflags[afi][safi],
9264 PEER_STATUS_EOR_SEND)) {
9265 json_object_boolean_true_add(
9266 json_grace_send,
9267 afi_safi_print(afi,
9268 safi));
9269 eor_send_af_count++;
d62a17ae 9270 }
9271 }
05c7a1cc
QY
9272 FOREACH_AFI_SAFI (afi, safi) {
9273 if (CHECK_FLAG(
9274 p->af_sflags[afi][safi],
9275 PEER_STATUS_EOR_RECEIVED)) {
9276 json_object_boolean_true_add(
9277 json_grace_recv,
9278 afi_safi_print(afi,
9279 safi));
9280 eor_receive_af_count++;
d62a17ae 9281 }
9282 }
9283 }
9284
9285 json_object_object_add(json_grace, "endOfRibSend",
9286 json_grace_send);
9287 json_object_object_add(json_grace, "endOfRibRecv",
9288 json_grace_recv);
9289
9290 if (p->t_gr_restart)
9291 json_object_int_add(json_grace,
9292 "gracefulRestartTimerMsecs",
9293 thread_timer_remain_second(
9294 p->t_gr_restart)
9295 * 1000);
9296
9297 if (p->t_gr_stale)
9298 json_object_int_add(
9299 json_grace,
9300 "gracefulStalepathTimerMsecs",
9301 thread_timer_remain_second(
9302 p->t_gr_stale)
9303 * 1000);
9304
9305 json_object_object_add(
9306 json_neigh, "gracefulRestartInfo", json_grace);
9307 } else {
9308 vty_out(vty, " Graceful restart informations:\n");
9309 if (p->status == Established) {
9310 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
9311 FOREACH_AFI_SAFI (afi, safi) {
9312 if (CHECK_FLAG(p->af_sflags[afi][safi],
9313 PEER_STATUS_EOR_SEND)) {
9314 vty_out(vty, "%s%s",
9315 eor_send_af_count ? ", "
9316 : "",
9317 afi_safi_print(afi,
9318 safi));
9319 eor_send_af_count++;
d62a17ae 9320 }
9321 }
9322 vty_out(vty, "\n");
9323 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
9324 FOREACH_AFI_SAFI (afi, safi) {
9325 if (CHECK_FLAG(
9326 p->af_sflags[afi][safi],
9327 PEER_STATUS_EOR_RECEIVED)) {
9328 vty_out(vty, "%s%s",
9329 eor_receive_af_count
9330 ? ", "
9331 : "",
9332 afi_safi_print(afi,
9333 safi));
9334 eor_receive_af_count++;
d62a17ae 9335 }
9336 }
9337 vty_out(vty, "\n");
9338 }
9339
9340 if (p->t_gr_restart)
9341 vty_out(vty,
9342 " The remaining time of restart timer is %ld\n",
9343 thread_timer_remain_second(
9344 p->t_gr_restart));
9345
9346 if (p->t_gr_stale)
9347 vty_out(vty,
9348 " The remaining time of stalepath timer is %ld\n",
9349 thread_timer_remain_second(
9350 p->t_gr_stale));
9351 }
9352 }
9353 if (use_json) {
9354 json_object *json_stat = NULL;
9355 json_stat = json_object_new_object();
9356 /* Packet counts. */
9357 json_object_int_add(json_stat, "depthInq", 0);
9358 json_object_int_add(json_stat, "depthOutq",
9359 (unsigned long)p->obuf->count);
0112e9e0
QY
9360 json_object_int_add(json_stat, "opensSent",
9361 atomic_load_explicit(&p->open_out,
9362 memory_order_relaxed));
9363 json_object_int_add(json_stat, "opensRecv",
9364 atomic_load_explicit(&p->open_in,
9365 memory_order_relaxed));
d62a17ae 9366 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
9367 atomic_load_explicit(&p->notify_out,
9368 memory_order_relaxed));
d62a17ae 9369 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
9370 atomic_load_explicit(&p->notify_in,
9371 memory_order_relaxed));
9372 json_object_int_add(json_stat, "updatesSent",
9373 atomic_load_explicit(&p->update_out,
9374 memory_order_relaxed));
9375 json_object_int_add(json_stat, "updatesRecv",
9376 atomic_load_explicit(&p->update_in,
9377 memory_order_relaxed));
d62a17ae 9378 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
9379 atomic_load_explicit(&p->keepalive_out,
9380 memory_order_relaxed));
d62a17ae 9381 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
9382 atomic_load_explicit(&p->keepalive_in,
9383 memory_order_relaxed));
d62a17ae 9384 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
9385 atomic_load_explicit(&p->refresh_out,
9386 memory_order_relaxed));
d62a17ae 9387 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
9388 atomic_load_explicit(&p->refresh_in,
9389 memory_order_relaxed));
d62a17ae 9390 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
9391 atomic_load_explicit(&p->dynamic_cap_out,
9392 memory_order_relaxed));
d62a17ae 9393 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
9394 atomic_load_explicit(&p->dynamic_cap_in,
9395 memory_order_relaxed));
9396 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
9397 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 9398 json_object_object_add(json_neigh, "messageStats", json_stat);
9399 } else {
9400 /* Packet counts. */
9401 vty_out(vty, " Message statistics:\n");
9402 vty_out(vty, " Inq depth is 0\n");
9403 vty_out(vty, " Outq depth is %lu\n",
9404 (unsigned long)p->obuf->count);
9405 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
9406 vty_out(vty, " Opens: %10d %10d\n",
9407 atomic_load_explicit(&p->open_out,
9408 memory_order_relaxed),
9409 atomic_load_explicit(&p->open_in,
9410 memory_order_relaxed));
9411 vty_out(vty, " Notifications: %10d %10d\n",
9412 atomic_load_explicit(&p->notify_out,
9413 memory_order_relaxed),
9414 atomic_load_explicit(&p->notify_in,
9415 memory_order_relaxed));
9416 vty_out(vty, " Updates: %10d %10d\n",
9417 atomic_load_explicit(&p->update_out,
9418 memory_order_relaxed),
9419 atomic_load_explicit(&p->update_in,
9420 memory_order_relaxed));
9421 vty_out(vty, " Keepalives: %10d %10d\n",
9422 atomic_load_explicit(&p->keepalive_out,
9423 memory_order_relaxed),
9424 atomic_load_explicit(&p->keepalive_in,
9425 memory_order_relaxed));
9426 vty_out(vty, " Route Refresh: %10d %10d\n",
9427 atomic_load_explicit(&p->refresh_out,
9428 memory_order_relaxed),
9429 atomic_load_explicit(&p->refresh_in,
9430 memory_order_relaxed));
d62a17ae 9431 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
9432 atomic_load_explicit(&p->dynamic_cap_out,
9433 memory_order_relaxed),
9434 atomic_load_explicit(&p->dynamic_cap_in,
9435 memory_order_relaxed));
9436 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
9437 PEER_TOTAL_RX(p));
d62a17ae 9438 }
9439
9440 if (use_json) {
9441 /* advertisement-interval */
9442 json_object_int_add(json_neigh,
9443 "minBtwnAdvertisementRunsTimerMsecs",
9444 p->v_routeadv * 1000);
9445
9446 /* Update-source. */
9447 if (p->update_if || p->update_source) {
9448 if (p->update_if)
9449 json_object_string_add(json_neigh,
9450 "updateSource",
9451 p->update_if);
9452 else if (p->update_source)
9453 json_object_string_add(
9454 json_neigh, "updateSource",
9455 sockunion2str(p->update_source, buf1,
9456 SU_ADDRSTRLEN));
9457 }
9458 } else {
9459 /* advertisement-interval */
9460 vty_out(vty,
9461 " Minimum time between advertisement runs is %d seconds\n",
9462 p->v_routeadv);
9463
9464 /* Update-source. */
9465 if (p->update_if || p->update_source) {
9466 vty_out(vty, " Update source is ");
9467 if (p->update_if)
9468 vty_out(vty, "%s", p->update_if);
9469 else if (p->update_source)
9470 vty_out(vty, "%s",
9471 sockunion2str(p->update_source, buf1,
9472 SU_ADDRSTRLEN));
9473 vty_out(vty, "\n");
9474 }
9475
9476 vty_out(vty, "\n");
9477 }
9478
9479 /* Address Family Information */
9480 json_object *json_hold = NULL;
9481
9482 if (use_json)
9483 json_hold = json_object_new_object();
9484
05c7a1cc
QY
9485 FOREACH_AFI_SAFI (afi, safi)
9486 if (p->afc[afi][safi])
9487 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9488 json_hold);
d62a17ae 9489
9490 if (use_json) {
9491 json_object_object_add(json_neigh, "addressFamilyInfo",
9492 json_hold);
9493 json_object_int_add(json_neigh, "connectionsEstablished",
9494 p->established);
9495 json_object_int_add(json_neigh, "connectionsDropped",
9496 p->dropped);
9497 } else
9498 vty_out(vty, " Connections established %d; dropped %d\n",
9499 p->established, p->dropped);
9500
9501 if (!p->last_reset) {
9502 if (use_json)
9503 json_object_string_add(json_neigh, "lastReset",
9504 "never");
9505 else
9506 vty_out(vty, " Last reset never\n");
9507 } else {
9508 if (use_json) {
9509 time_t uptime;
9510 struct tm *tm;
9511
9512 uptime = bgp_clock();
9513 uptime -= p->resettime;
9514 tm = gmtime(&uptime);
9515 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9516 (tm->tm_sec * 1000)
9517 + (tm->tm_min * 60000)
9518 + (tm->tm_hour * 3600000));
9519 json_object_string_add(
9520 json_neigh, "lastResetDueTo",
9521 peer_down_str[(int)p->last_reset]);
9522 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9523 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9524 char errorcodesubcode_hexstr[5];
9525 char errorcodesubcode_str[256];
9526
9527 code_str = bgp_notify_code_str(p->notify.code);
9528 subcode_str = bgp_notify_subcode_str(
9529 p->notify.code, p->notify.subcode);
9530
9531 sprintf(errorcodesubcode_hexstr, "%02X%02X",
9532 p->notify.code, p->notify.subcode);
9533 json_object_string_add(json_neigh,
9534 "lastErrorCodeSubcode",
9535 errorcodesubcode_hexstr);
9536 snprintf(errorcodesubcode_str, 255, "%s%s",
9537 code_str, subcode_str);
9538 json_object_string_add(json_neigh,
9539 "lastNotificationReason",
9540 errorcodesubcode_str);
9541 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9542 && p->notify.code == BGP_NOTIFY_CEASE
9543 && (p->notify.subcode
9544 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9545 || p->notify.subcode
9546 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9547 && p->notify.length) {
9548 char msgbuf[1024];
9549 const char *msg_str;
9550
9551 msg_str = bgp_notify_admin_message(
9552 msgbuf, sizeof(msgbuf),
9553 (u_char *)p->notify.data,
9554 p->notify.length);
9555 if (msg_str)
9556 json_object_string_add(
9557 json_neigh,
9558 "lastShutdownDescription",
9559 msg_str);
9560 }
9561 }
9562 } else {
9563 vty_out(vty, " Last reset %s, ",
9564 peer_uptime(p->resettime, timebuf,
9565 BGP_UPTIME_LEN, 0, NULL));
9566
9567 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9568 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9569 code_str = bgp_notify_code_str(p->notify.code);
9570 subcode_str = bgp_notify_subcode_str(
9571 p->notify.code, p->notify.subcode);
9572 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
9573 p->last_reset == PEER_DOWN_NOTIFY_SEND
9574 ? "sent"
9575 : "received",
9576 code_str, subcode_str);
9577 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9578 && p->notify.code == BGP_NOTIFY_CEASE
9579 && (p->notify.subcode
9580 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9581 || p->notify.subcode
9582 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9583 && p->notify.length) {
9584 char msgbuf[1024];
9585 const char *msg_str;
9586
9587 msg_str = bgp_notify_admin_message(
9588 msgbuf, sizeof(msgbuf),
9589 (u_char *)p->notify.data,
9590 p->notify.length);
9591 if (msg_str)
9592 vty_out(vty,
9593 " Message: \"%s\"\n",
9594 msg_str);
9595 }
9596 } else {
9597 vty_out(vty, "due to %s\n",
9598 peer_down_str[(int)p->last_reset]);
9599 }
9600
9601 if (p->last_reset_cause_size) {
9602 msg = p->last_reset_cause;
9603 vty_out(vty,
9604 " Message received that caused BGP to send a NOTIFICATION:\n ");
9605 for (i = 1; i <= p->last_reset_cause_size;
9606 i++) {
9607 vty_out(vty, "%02X", *msg++);
9608
9609 if (i != p->last_reset_cause_size) {
9610 if (i % 16 == 0) {
9611 vty_out(vty, "\n ");
9612 } else if (i % 4 == 0) {
9613 vty_out(vty, " ");
9614 }
9615 }
9616 }
9617 vty_out(vty, "\n");
9618 }
9619 }
9620 }
9621
9622 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
9623 if (use_json)
9624 json_object_boolean_true_add(json_neigh,
9625 "prefixesConfigExceedMax");
9626 else
9627 vty_out(vty,
9628 " Peer had exceeded the max. no. of prefixes configured.\n");
9629
9630 if (p->t_pmax_restart) {
9631 if (use_json) {
9632 json_object_boolean_true_add(
9633 json_neigh, "reducePrefixNumFrom");
9634 json_object_int_add(json_neigh,
9635 "restartInTimerMsec",
9636 thread_timer_remain_second(
9637 p->t_pmax_restart)
9638 * 1000);
9639 } else
9640 vty_out(vty,
9641 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
a4d82a8a
PZ
9642 p->host,
9643 thread_timer_remain_second(
9644 p->t_pmax_restart));
d62a17ae 9645 } else {
9646 if (use_json)
9647 json_object_boolean_true_add(
9648 json_neigh,
9649 "reducePrefixNumAndClearIpBgp");
9650 else
9651 vty_out(vty,
9652 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
9653 p->host);
9654 }
9655 }
9656
9657 /* EBGP Multihop and GTSM */
9658 if (p->sort != BGP_PEER_IBGP) {
9659 if (use_json) {
9660 if (p->gtsm_hops > 0)
9661 json_object_int_add(json_neigh,
9662 "externalBgpNbrMaxHopsAway",
9663 p->gtsm_hops);
9664 else if (p->ttl > 1)
9665 json_object_int_add(json_neigh,
9666 "externalBgpNbrMaxHopsAway",
9667 p->ttl);
9668 } else {
9669 if (p->gtsm_hops > 0)
9670 vty_out(vty,
9671 " External BGP neighbor may be up to %d hops away.\n",
9672 p->gtsm_hops);
9673 else if (p->ttl > 1)
9674 vty_out(vty,
9675 " External BGP neighbor may be up to %d hops away.\n",
9676 p->ttl);
9677 }
9678 } else {
9679 if (p->gtsm_hops > 0) {
9680 if (use_json)
9681 json_object_int_add(json_neigh,
9682 "internalBgpNbrMaxHopsAway",
9683 p->gtsm_hops);
9684 else
9685 vty_out(vty,
9686 " Internal BGP neighbor may be up to %d hops away.\n",
9687 p->gtsm_hops);
9688 }
9689 }
9690
9691 /* Local address. */
9692 if (p->su_local) {
9693 if (use_json) {
9694 json_object_string_add(json_neigh, "hostLocal",
9695 sockunion2str(p->su_local, buf1,
9696 SU_ADDRSTRLEN));
9697 json_object_int_add(json_neigh, "portLocal",
9698 ntohs(p->su_local->sin.sin_port));
9699 } else
9700 vty_out(vty, "Local host: %s, Local port: %d\n",
9701 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
9702 ntohs(p->su_local->sin.sin_port));
9703 }
9704
9705 /* Remote address. */
9706 if (p->su_remote) {
9707 if (use_json) {
9708 json_object_string_add(json_neigh, "hostForeign",
9709 sockunion2str(p->su_remote, buf1,
9710 SU_ADDRSTRLEN));
9711 json_object_int_add(json_neigh, "portForeign",
9712 ntohs(p->su_remote->sin.sin_port));
9713 } else
9714 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
9715 sockunion2str(p->su_remote, buf1,
9716 SU_ADDRSTRLEN),
9717 ntohs(p->su_remote->sin.sin_port));
9718 }
9719
9720 /* Nexthop display. */
9721 if (p->su_local) {
9722 if (use_json) {
9723 json_object_string_add(json_neigh, "nexthop",
9724 inet_ntop(AF_INET,
9725 &p->nexthop.v4, buf1,
9726 sizeof(buf1)));
9727 json_object_string_add(json_neigh, "nexthopGlobal",
9728 inet_ntop(AF_INET6,
9729 &p->nexthop.v6_global,
9730 buf1, sizeof(buf1)));
9731 json_object_string_add(json_neigh, "nexthopLocal",
9732 inet_ntop(AF_INET6,
9733 &p->nexthop.v6_local,
9734 buf1, sizeof(buf1)));
9735 if (p->shared_network)
9736 json_object_string_add(json_neigh,
9737 "bgpConnection",
9738 "sharedNetwork");
9739 else
9740 json_object_string_add(json_neigh,
9741 "bgpConnection",
9742 "nonSharedNetwork");
9743 } else {
9744 vty_out(vty, "Nexthop: %s\n",
9745 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
9746 sizeof(buf1)));
9747 vty_out(vty, "Nexthop global: %s\n",
9748 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
9749 sizeof(buf1)));
9750 vty_out(vty, "Nexthop local: %s\n",
9751 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
9752 sizeof(buf1)));
9753 vty_out(vty, "BGP connection: %s\n",
9754 p->shared_network ? "shared network"
9755 : "non shared network");
9756 }
9757 }
9758
9759 /* Timer information. */
9760 if (use_json) {
9761 json_object_int_add(json_neigh, "connectRetryTimer",
9762 p->v_connect);
9763 if (p->status == Established && p->rtt)
9764 json_object_int_add(json_neigh, "estimatedRttInMsecs",
9765 p->rtt);
9766 if (p->t_start)
9767 json_object_int_add(
9768 json_neigh, "nextStartTimerDueInMsecs",
9769 thread_timer_remain_second(p->t_start) * 1000);
9770 if (p->t_connect)
9771 json_object_int_add(
9772 json_neigh, "nextConnectTimerDueInMsecs",
9773 thread_timer_remain_second(p->t_connect)
9774 * 1000);
9775 if (p->t_routeadv) {
9776 json_object_int_add(json_neigh, "mraiInterval",
9777 p->v_routeadv);
9778 json_object_int_add(
9779 json_neigh, "mraiTimerExpireInMsecs",
9780 thread_timer_remain_second(p->t_routeadv)
9781 * 1000);
9782 }
9783 if (p->password)
9784 json_object_int_add(json_neigh, "authenticationEnabled",
9785 1);
9786
9787 if (p->t_read)
9788 json_object_string_add(json_neigh, "readThread", "on");
9789 else
9790 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
9791
9792 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 9793 json_object_string_add(json_neigh, "writeThread", "on");
9794 else
9795 json_object_string_add(json_neigh, "writeThread",
9796 "off");
9797 } else {
9798 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
9799 p->v_connect);
9800 if (p->status == Established && p->rtt)
9801 vty_out(vty, "Estimated round trip time: %d ms\n",
9802 p->rtt);
9803 if (p->t_start)
9804 vty_out(vty, "Next start timer due in %ld seconds\n",
9805 thread_timer_remain_second(p->t_start));
9806 if (p->t_connect)
9807 vty_out(vty, "Next connect timer due in %ld seconds\n",
9808 thread_timer_remain_second(p->t_connect));
9809 if (p->t_routeadv)
9810 vty_out(vty,
9811 "MRAI (interval %u) timer expires in %ld seconds\n",
9812 p->v_routeadv,
9813 thread_timer_remain_second(p->t_routeadv));
9814 if (p->password)
9815 vty_out(vty, "Peer Authentication Enabled\n");
9816
9817 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
9818 p->t_read ? "on" : "off",
9819 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
9820 ? "on"
9821 : "off");
d62a17ae 9822 }
9823
9824 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9825 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
9826 bgp_capability_vty_out(vty, p, use_json, json_neigh);
9827
9828 if (!use_json)
9829 vty_out(vty, "\n");
9830
9831 /* BFD information. */
9832 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9833
9834 if (use_json) {
9835 if (p->conf_if) /* Configured interface name. */
9836 json_object_object_add(json, p->conf_if, json_neigh);
9837 else /* Configured IP address. */
9838 json_object_object_add(json, p->host, json_neigh);
9839 }
9840}
9841
9842static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
9843 enum show_type type, union sockunion *su,
9844 const char *conf_if, u_char use_json,
9845 json_object *json)
9846{
9847 struct listnode *node, *nnode;
9848 struct peer *peer;
9849 int find = 0;
9850
9851 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9852 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9853 continue;
9854
9855 switch (type) {
9856 case show_all:
9857 bgp_show_peer(vty, peer, use_json, json);
9858 break;
9859 case show_peer:
9860 if (conf_if) {
9861 if ((peer->conf_if
9862 && !strcmp(peer->conf_if, conf_if))
9863 || (peer->hostname
9864 && !strcmp(peer->hostname, conf_if))) {
9865 find = 1;
9866 bgp_show_peer(vty, peer, use_json,
9867 json);
9868 }
9869 } else {
9870 if (sockunion_same(&peer->su, su)) {
9871 find = 1;
9872 bgp_show_peer(vty, peer, use_json,
9873 json);
9874 }
9875 }
9876 break;
9877 }
9878 }
9879
9880 if (type == show_peer && !find) {
9881 if (use_json)
9882 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9883 else
9884 vty_out(vty, "%% No such neighbor\n");
9885 }
9886
9887 if (use_json) {
a4d82a8a
PZ
9888 vty_out(vty, "%s\n",
9889 json_object_to_json_string_ext(
9890 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9891 json_object_free(json);
9892 } else {
9893 vty_out(vty, "\n");
9894 }
9895
9896 return CMD_SUCCESS;
9897}
9898
9899static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
9900 enum show_type type,
9901 const char *ip_str,
d62a17ae 9902 u_char use_json)
9903{
0291c246
MK
9904 struct listnode *node, *nnode;
9905 struct bgp *bgp;
71aedaa3 9906 union sockunion su;
0291c246 9907 json_object *json = NULL;
71aedaa3 9908 int ret, is_first = 1;
d62a17ae 9909
9910 if (use_json)
9911 vty_out(vty, "{\n");
9912
9913 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9914 if (use_json) {
9915 if (!(json = json_object_new_object())) {
9916 zlog_err(
9917 "Unable to allocate memory for JSON object");
9918 vty_out(vty,
9919 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
9920 return;
9921 }
9922
9923 json_object_int_add(json, "vrfId",
9924 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
9925 ? -1
9926 : (int64_t)bgp->vrf_id);
d62a17ae 9927 json_object_string_add(
9928 json, "vrfName",
9929 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9930 ? "Default"
9931 : bgp->name);
9932
9933 if (!is_first)
9934 vty_out(vty, ",\n");
9935 else
9936 is_first = 0;
9937
9938 vty_out(vty, "\"%s\":",
9939 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9940 ? "Default"
9941 : bgp->name);
9942 } else {
9943 vty_out(vty, "\nInstance %s:\n",
9944 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9945 ? "Default"
9946 : bgp->name);
9947 }
71aedaa3
DS
9948
9949 if (type == show_peer) {
9950 ret = str2sockunion(ip_str, &su);
9951 if (ret < 0)
9952 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
9953 use_json, json);
9954 else
9955 bgp_show_neighbor(vty, bgp, type, &su, NULL,
9956 use_json, json);
9957 } else {
9958 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
9959 use_json, json);
9960 }
d62a17ae 9961 }
9962
9963 if (use_json)
9964 vty_out(vty, "}\n");
9965}
9966
9967static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
9968 enum show_type type, const char *ip_str,
9969 u_char use_json)
9970{
9971 int ret;
9972 struct bgp *bgp;
9973 union sockunion su;
9974 json_object *json = NULL;
9975
9976 if (name) {
9977 if (strmatch(name, "all")) {
71aedaa3
DS
9978 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
9979 use_json);
d62a17ae 9980 return CMD_SUCCESS;
9981 } else {
9982 bgp = bgp_lookup_by_name(name);
9983 if (!bgp) {
9984 if (use_json) {
9985 json = json_object_new_object();
9986 json_object_boolean_true_add(
9987 json, "bgpNoSuchInstance");
9988 vty_out(vty, "%s\n",
9989 json_object_to_json_string_ext(
9990 json,
9991 JSON_C_TO_STRING_PRETTY));
9992 json_object_free(json);
9993 } else
9994 vty_out(vty,
9995 "%% No such BGP instance exist\n");
9996
9997 return CMD_WARNING;
9998 }
9999 }
10000 } else {
10001 bgp = bgp_get_default();
10002 }
10003
10004 if (bgp) {
10005 json = json_object_new_object();
10006 if (ip_str) {
10007 ret = str2sockunion(ip_str, &su);
10008 if (ret < 0)
10009 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10010 use_json, json);
10011 else
10012 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10013 use_json, json);
10014 } else {
10015 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10016 json);
10017 }
10018 json_object_free(json);
10019 }
10020
10021 return CMD_SUCCESS;
4fb25c53
DW
10022}
10023
716b2d8a 10024/* "show [ip] bgp neighbors" commands. */
718e3744 10025DEFUN (show_ip_bgp_neighbors,
10026 show_ip_bgp_neighbors_cmd,
24345e82 10027 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10028 SHOW_STR
10029 IP_STR
10030 BGP_STR
f2a8972b 10031 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10032 "Address Family\n"
10033 "Address Family\n"
718e3744 10034 "Detailed information on TCP and BGP neighbor connections\n"
10035 "Neighbor to display information about\n"
a80beece 10036 "Neighbor to display information about\n"
91d37724 10037 "Neighbor on BGP configured interface\n"
9973d184 10038 JSON_STR)
718e3744 10039{
d62a17ae 10040 char *vrf = NULL;
10041 char *sh_arg = NULL;
10042 enum show_type sh_type;
718e3744 10043
d62a17ae 10044 u_char uj = use_json(argc, argv);
718e3744 10045
d62a17ae 10046 int idx = 0;
718e3744 10047
d62a17ae 10048 if (argv_find(argv, argc, "view", &idx)
10049 || argv_find(argv, argc, "vrf", &idx))
10050 vrf = argv[idx + 1]->arg;
718e3744 10051
d62a17ae 10052 idx++;
10053 if (argv_find(argv, argc, "A.B.C.D", &idx)
10054 || argv_find(argv, argc, "X:X::X:X", &idx)
10055 || argv_find(argv, argc, "WORD", &idx)) {
10056 sh_type = show_peer;
10057 sh_arg = argv[idx]->arg;
10058 } else
10059 sh_type = show_all;
856ca177 10060
d62a17ae 10061 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10062}
10063
716b2d8a 10064/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10065 paths' and `show ip mbgp paths'. Those functions results are the
10066 same.*/
f412b39a 10067DEFUN (show_ip_bgp_paths,
718e3744 10068 show_ip_bgp_paths_cmd,
46f296b4 10069 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10070 SHOW_STR
10071 IP_STR
10072 BGP_STR
46f296b4 10073 BGP_SAFI_HELP_STR
718e3744 10074 "Path information\n")
10075{
d62a17ae 10076 vty_out(vty, "Address Refcnt Path\n");
10077 aspath_print_all_vty(vty);
10078 return CMD_SUCCESS;
718e3744 10079}
10080
718e3744 10081#include "hash.h"
10082
d62a17ae 10083static void community_show_all_iterator(struct hash_backet *backet,
10084 struct vty *vty)
718e3744 10085{
d62a17ae 10086 struct community *com;
718e3744 10087
d62a17ae 10088 com = (struct community *)backet->data;
3f65c5b1 10089 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10090 community_str(com, false));
718e3744 10091}
10092
10093/* Show BGP's community internal data. */
f412b39a 10094DEFUN (show_ip_bgp_community_info,
718e3744 10095 show_ip_bgp_community_info_cmd,
bec37ba5 10096 "show [ip] bgp community-info",
718e3744 10097 SHOW_STR
10098 IP_STR
10099 BGP_STR
10100 "List all bgp community information\n")
10101{
d62a17ae 10102 vty_out(vty, "Address Refcnt Community\n");
718e3744 10103
d62a17ae 10104 hash_iterate(community_hash(),
10105 (void (*)(struct hash_backet *,
10106 void *))community_show_all_iterator,
10107 vty);
718e3744 10108
d62a17ae 10109 return CMD_SUCCESS;
718e3744 10110}
10111
d62a17ae 10112static void lcommunity_show_all_iterator(struct hash_backet *backet,
10113 struct vty *vty)
57d187bc 10114{
d62a17ae 10115 struct lcommunity *lcom;
57d187bc 10116
d62a17ae 10117 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10118 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
d62a17ae 10119 lcommunity_str(lcom));
57d187bc
JS
10120}
10121
10122/* Show BGP's community internal data. */
10123DEFUN (show_ip_bgp_lcommunity_info,
10124 show_ip_bgp_lcommunity_info_cmd,
10125 "show ip bgp large-community-info",
10126 SHOW_STR
10127 IP_STR
10128 BGP_STR
10129 "List all bgp large-community information\n")
10130{
d62a17ae 10131 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10132
d62a17ae 10133 hash_iterate(lcommunity_hash(),
10134 (void (*)(struct hash_backet *,
10135 void *))lcommunity_show_all_iterator,
10136 vty);
57d187bc 10137
d62a17ae 10138 return CMD_SUCCESS;
57d187bc
JS
10139}
10140
10141
f412b39a 10142DEFUN (show_ip_bgp_attr_info,
718e3744 10143 show_ip_bgp_attr_info_cmd,
bec37ba5 10144 "show [ip] bgp attribute-info",
718e3744 10145 SHOW_STR
10146 IP_STR
10147 BGP_STR
10148 "List all bgp attribute information\n")
10149{
d62a17ae 10150 attr_show_all(vty);
10151 return CMD_SUCCESS;
718e3744 10152}
6b0655a2 10153
d62a17ae 10154static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10155 safi_t safi)
f186de26 10156{
d62a17ae 10157 struct listnode *node, *nnode;
10158 struct bgp *bgp;
f186de26 10159
d62a17ae 10160 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10161 vty_out(vty, "\nInstance %s:\n",
10162 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10163 ? "Default"
10164 : bgp->name);
10165 update_group_show(bgp, afi, safi, vty, 0);
10166 }
f186de26 10167}
10168
d62a17ae 10169static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10170 int safi, uint64_t subgrp_id)
4fb25c53 10171{
d62a17ae 10172 struct bgp *bgp;
4fb25c53 10173
d62a17ae 10174 if (name) {
10175 if (strmatch(name, "all")) {
10176 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10177 return CMD_SUCCESS;
10178 } else {
10179 bgp = bgp_lookup_by_name(name);
10180 }
10181 } else {
10182 bgp = bgp_get_default();
10183 }
4fb25c53 10184
d62a17ae 10185 if (bgp)
10186 update_group_show(bgp, afi, safi, vty, subgrp_id);
10187 return CMD_SUCCESS;
4fb25c53
DW
10188}
10189
8fe8a7f6
DS
10190DEFUN (show_ip_bgp_updgrps,
10191 show_ip_bgp_updgrps_cmd,
c1a44e43 10192 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 10193 SHOW_STR
10194 IP_STR
10195 BGP_STR
10196 BGP_INSTANCE_HELP_STR
c9e571b4 10197 BGP_AFI_HELP_STR
9bedbb1e 10198 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
10199 "Detailed info about dynamic update groups\n"
10200 "Specific subgroup to display detailed info for\n")
8386ac43 10201{
d62a17ae 10202 char *vrf = NULL;
10203 afi_t afi = AFI_IP6;
10204 safi_t safi = SAFI_UNICAST;
10205 uint64_t subgrp_id = 0;
10206
10207 int idx = 0;
10208
10209 /* show [ip] bgp */
10210 if (argv_find(argv, argc, "ip", &idx))
10211 afi = AFI_IP;
10212 /* [<view|vrf> VIEWVRFNAME] */
10213 if (argv_find(argv, argc, "view", &idx)
10214 || argv_find(argv, argc, "vrf", &idx))
10215 vrf = argv[++idx]->arg;
10216 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10217 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10218 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10219 }
5bf15956 10220
d62a17ae 10221 /* get subgroup id, if provided */
10222 idx = argc - 1;
10223 if (argv[idx]->type == VARIABLE_TKN)
10224 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 10225
d62a17ae 10226 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
10227}
10228
f186de26 10229DEFUN (show_bgp_instance_all_ipv6_updgrps,
10230 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 10231 "show [ip] bgp <view|vrf> all update-groups",
f186de26 10232 SHOW_STR
716b2d8a 10233 IP_STR
f186de26 10234 BGP_STR
10235 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 10236 "Detailed info about dynamic update groups\n")
f186de26 10237{
d62a17ae 10238 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10239 return CMD_SUCCESS;
f186de26 10240}
10241
5bf15956
DW
10242DEFUN (show_bgp_updgrps_stats,
10243 show_bgp_updgrps_stats_cmd,
716b2d8a 10244 "show [ip] bgp update-groups statistics",
3f9c7369 10245 SHOW_STR
716b2d8a 10246 IP_STR
3f9c7369 10247 BGP_STR
0c7b1b01 10248 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10249 "Statistics\n")
10250{
d62a17ae 10251 struct bgp *bgp;
3f9c7369 10252
d62a17ae 10253 bgp = bgp_get_default();
10254 if (bgp)
10255 update_group_show_stats(bgp, vty);
3f9c7369 10256
d62a17ae 10257 return CMD_SUCCESS;
3f9c7369
DS
10258}
10259
8386ac43 10260DEFUN (show_bgp_instance_updgrps_stats,
10261 show_bgp_instance_updgrps_stats_cmd,
18c57037 10262 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 10263 SHOW_STR
716b2d8a 10264 IP_STR
8386ac43 10265 BGP_STR
10266 BGP_INSTANCE_HELP_STR
0c7b1b01 10267 "Detailed info about dynamic update groups\n"
8386ac43 10268 "Statistics\n")
10269{
d62a17ae 10270 int idx_word = 3;
10271 struct bgp *bgp;
8386ac43 10272
d62a17ae 10273 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10274 if (bgp)
10275 update_group_show_stats(bgp, vty);
8386ac43 10276
d62a17ae 10277 return CMD_SUCCESS;
8386ac43 10278}
10279
d62a17ae 10280static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10281 afi_t afi, safi_t safi,
10282 const char *what, uint64_t subgrp_id)
3f9c7369 10283{
d62a17ae 10284 struct bgp *bgp;
8386ac43 10285
d62a17ae 10286 if (name)
10287 bgp = bgp_lookup_by_name(name);
10288 else
10289 bgp = bgp_get_default();
8386ac43 10290
d62a17ae 10291 if (bgp) {
10292 if (!strcmp(what, "advertise-queue"))
10293 update_group_show_adj_queue(bgp, afi, safi, vty,
10294 subgrp_id);
10295 else if (!strcmp(what, "advertised-routes"))
10296 update_group_show_advertised(bgp, afi, safi, vty,
10297 subgrp_id);
10298 else if (!strcmp(what, "packet-queue"))
10299 update_group_show_packet_queue(bgp, afi, safi, vty,
10300 subgrp_id);
10301 }
3f9c7369
DS
10302}
10303
10304DEFUN (show_ip_bgp_updgrps_adj,
10305 show_ip_bgp_updgrps_adj_cmd,
716b2d8a 10306 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10307 SHOW_STR
10308 IP_STR
10309 BGP_STR
0c7b1b01 10310 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10311 "Advertisement queue\n"
10312 "Announced routes\n"
10313 "Packet queue\n")
10314{
d62a17ae 10315 int idx_type = 4;
10316 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10317 argv[idx_type]->arg, 0);
10318 return CMD_SUCCESS;
8386ac43 10319}
10320
10321DEFUN (show_ip_bgp_instance_updgrps_adj,
10322 show_ip_bgp_instance_updgrps_adj_cmd,
18c57037 10323 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10324 SHOW_STR
10325 IP_STR
10326 BGP_STR
10327 BGP_INSTANCE_HELP_STR
0c7b1b01 10328 "Detailed info about dynamic update groups\n"
8386ac43 10329 "Advertisement queue\n"
10330 "Announced routes\n"
10331 "Packet queue\n")
8386ac43 10332{
d62a17ae 10333 int idx_word = 4;
10334 int idx_type = 6;
10335 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP,
10336 SAFI_UNICAST, argv[idx_type]->arg, 0);
10337 return CMD_SUCCESS;
3f9c7369
DS
10338}
10339
10340DEFUN (show_bgp_updgrps_afi_adj,
10341 show_bgp_updgrps_afi_adj_cmd,
46f296b4 10342 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10343 SHOW_STR
716b2d8a 10344 IP_STR
3f9c7369 10345 BGP_STR
46f296b4 10346 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10347 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10348 "Advertisement queue\n"
10349 "Announced routes\n"
7111c1a0 10350 "Packet queue\n")
3f9c7369 10351{
d62a17ae 10352 int idx_afi = 2;
10353 int idx_safi = 3;
10354 int idx_type = 5;
10355 show_bgp_updgrps_adj_info_aux(
10356 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10357 bgp_vty_safi_from_str(argv[idx_safi]->text),
10358 argv[idx_type]->arg, 0);
10359 return CMD_SUCCESS;
3f9c7369
DS
10360}
10361
10362DEFUN (show_bgp_updgrps_adj,
10363 show_bgp_updgrps_adj_cmd,
716b2d8a 10364 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10365 SHOW_STR
716b2d8a 10366 IP_STR
3f9c7369 10367 BGP_STR
0c7b1b01 10368 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10369 "Advertisement queue\n"
10370 "Announced routes\n"
10371 "Packet queue\n")
10372{
d62a17ae 10373 int idx_type = 3;
10374 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10375 argv[idx_type]->arg, 0);
10376 return CMD_SUCCESS;
8386ac43 10377}
10378
10379DEFUN (show_bgp_instance_updgrps_adj,
10380 show_bgp_instance_updgrps_adj_cmd,
18c57037 10381 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10382 SHOW_STR
716b2d8a 10383 IP_STR
8386ac43 10384 BGP_STR
10385 BGP_INSTANCE_HELP_STR
0c7b1b01 10386 "Detailed info about dynamic update groups\n"
8386ac43 10387 "Advertisement queue\n"
10388 "Announced routes\n"
10389 "Packet queue\n")
10390{
d62a17ae 10391 int idx_word = 3;
10392 int idx_type = 5;
10393 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6,
10394 SAFI_UNICAST, argv[idx_type]->arg, 0);
10395 return CMD_SUCCESS;
3f9c7369
DS
10396}
10397
10398DEFUN (show_ip_bgp_updgrps_adj_s,
8fe8a7f6 10399 show_ip_bgp_updgrps_adj_s_cmd,
716b2d8a 10400 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10401 SHOW_STR
10402 IP_STR
10403 BGP_STR
0c7b1b01 10404 "Detailed info about dynamic update groups\n"
8fe8a7f6 10405 "Specific subgroup to display info for\n"
3f9c7369
DS
10406 "Advertisement queue\n"
10407 "Announced routes\n"
10408 "Packet queue\n")
3f9c7369 10409{
d62a17ae 10410 int idx_subgroup_id = 4;
10411 int idx_type = 5;
10412 uint64_t subgrp_id;
8fe8a7f6 10413
d62a17ae 10414 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10415
d62a17ae 10416 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10417 argv[idx_type]->arg, subgrp_id);
10418 return CMD_SUCCESS;
8386ac43 10419}
10420
10421DEFUN (show_ip_bgp_instance_updgrps_adj_s,
10422 show_ip_bgp_instance_updgrps_adj_s_cmd,
18c57037 10423 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10424 SHOW_STR
10425 IP_STR
10426 BGP_STR
10427 BGP_INSTANCE_HELP_STR
0c7b1b01 10428 "Detailed info about dynamic update groups\n"
8386ac43 10429 "Specific subgroup to display info for\n"
10430 "Advertisement queue\n"
10431 "Announced routes\n"
10432 "Packet queue\n")
8386ac43 10433{
d62a17ae 10434 int idx_vrf = 4;
10435 int idx_subgroup_id = 6;
10436 int idx_type = 7;
10437 uint64_t subgrp_id;
8386ac43 10438
d62a17ae 10439 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8386ac43 10440
d62a17ae 10441 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP,
10442 SAFI_UNICAST, argv[idx_type]->arg,
10443 subgrp_id);
10444 return CMD_SUCCESS;
3f9c7369
DS
10445}
10446
8fe8a7f6
DS
10447DEFUN (show_bgp_updgrps_afi_adj_s,
10448 show_bgp_updgrps_afi_adj_s_cmd,
46f296b4 10449 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10450 SHOW_STR
716b2d8a 10451 IP_STR
3f9c7369 10452 BGP_STR
46f296b4 10453 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10454 "Detailed info about dynamic update groups\n"
8fe8a7f6 10455 "Specific subgroup to display info for\n"
3f9c7369
DS
10456 "Advertisement queue\n"
10457 "Announced routes\n"
7111c1a0 10458 "Packet queue\n")
3f9c7369 10459{
d62a17ae 10460 int idx_afi = 2;
10461 int idx_safi = 3;
10462 int idx_subgroup_id = 5;
10463 int idx_type = 6;
10464 uint64_t subgrp_id;
3f9c7369 10465
d62a17ae 10466 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10467
d62a17ae 10468 show_bgp_updgrps_adj_info_aux(
10469 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10470 bgp_vty_safi_from_str(argv[idx_safi]->text),
10471 argv[idx_type]->arg, subgrp_id);
10472 return CMD_SUCCESS;
3f9c7369
DS
10473}
10474
8fe8a7f6
DS
10475DEFUN (show_bgp_updgrps_adj_s,
10476 show_bgp_updgrps_adj_s_cmd,
716b2d8a 10477 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8fe8a7f6 10478 SHOW_STR
716b2d8a 10479 IP_STR
8fe8a7f6 10480 BGP_STR
0c7b1b01 10481 "Detailed info about dynamic update groups\n"
8fe8a7f6
DS
10482 "Specific subgroup to display info for\n"
10483 "Advertisement queue\n"
10484 "Announced routes\n"
10485 "Packet queue\n")
10486{
d62a17ae 10487 int idx_subgroup_id = 3;
10488 int idx_type = 4;
10489 uint64_t subgrp_id;
8fe8a7f6 10490
d62a17ae 10491 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10492
d62a17ae 10493 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10494 argv[idx_type]->arg, subgrp_id);
10495 return CMD_SUCCESS;
8fe8a7f6
DS
10496}
10497
8386ac43 10498DEFUN (show_bgp_instance_updgrps_adj_s,
10499 show_bgp_instance_updgrps_adj_s_cmd,
18c57037 10500 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10501 SHOW_STR
716b2d8a 10502 IP_STR
8386ac43 10503 BGP_STR
10504 BGP_INSTANCE_HELP_STR
0c7b1b01 10505 "Detailed info about dynamic update groups\n"
8386ac43 10506 "Specific subgroup to display info for\n"
10507 "Advertisement queue\n"
10508 "Announced routes\n"
10509 "Packet queue\n")
10510{
d62a17ae 10511 int idx_vrf = 3;
10512 int idx_subgroup_id = 5;
10513 int idx_type = 6;
10514 uint64_t subgrp_id;
10515
10516 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10517
10518 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6,
10519 SAFI_UNICAST, argv[idx_type]->arg,
10520 subgrp_id);
10521 return CMD_SUCCESS;
10522}
10523
10524
10525static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10526{
10527 struct listnode *node, *nnode;
10528 struct prefix *range;
10529 struct peer *conf;
10530 struct peer *peer;
10531 char buf[PREFIX2STR_BUFFER];
10532 afi_t afi;
10533 safi_t safi;
10534 const char *peer_status;
10535 const char *af_str;
10536 int lr_count;
10537 int dynamic;
10538 int af_cfgd;
10539
10540 conf = group->conf;
10541
10542 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10543 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10544 conf->as);
10545 } else if (conf->as_type == AS_INTERNAL) {
10546 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10547 group->bgp->as);
10548 } else {
10549 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10550 }
f14e6fdb 10551
d62a17ae 10552 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10553 vty_out(vty, " Peer-group type is internal\n");
10554 else
10555 vty_out(vty, " Peer-group type is external\n");
10556
10557 /* Display AFs configured. */
10558 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
10559 FOREACH_AFI_SAFI (afi, safi) {
10560 if (conf->afc[afi][safi]) {
10561 af_cfgd = 1;
10562 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 10563 }
05c7a1cc 10564 }
d62a17ae 10565 if (!af_cfgd)
10566 vty_out(vty, " none\n");
10567 else
10568 vty_out(vty, "\n");
10569
10570 /* Display listen ranges (for dynamic neighbors), if any */
10571 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10572 if (afi == AFI_IP)
10573 af_str = "IPv4";
10574 else if (afi == AFI_IP6)
10575 af_str = "IPv6";
10576 else
10577 af_str = "???";
10578 lr_count = listcount(group->listen_range[afi]);
10579 if (lr_count) {
10580 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10581 af_str);
10582
10583
10584 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10585 nnode, range)) {
10586 prefix2str(range, buf, sizeof(buf));
10587 vty_out(vty, " %s\n", buf);
10588 }
10589 }
10590 }
f14e6fdb 10591
d62a17ae 10592 /* Display group members and their status */
10593 if (listcount(group->peer)) {
10594 vty_out(vty, " Peer-group members:\n");
10595 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10596 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10597 peer_status = "Idle (Admin)";
10598 else if (CHECK_FLAG(peer->sflags,
10599 PEER_STATUS_PREFIX_OVERFLOW))
10600 peer_status = "Idle (PfxCt)";
10601 else
10602 peer_status = lookup_msg(bgp_status_msg,
10603 peer->status, NULL);
10604
10605 dynamic = peer_dynamic_neighbor(peer);
10606 vty_out(vty, " %s %s %s \n", peer->host,
10607 dynamic ? "(dynamic)" : "", peer_status);
10608 }
10609 }
f14e6fdb 10610
d62a17ae 10611 return CMD_SUCCESS;
10612}
10613
ff9959b0
QY
10614static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10615 const char *group_name)
d62a17ae 10616{
ff9959b0 10617 struct bgp *bgp;
d62a17ae 10618 struct listnode *node, *nnode;
10619 struct peer_group *group;
ff9959b0
QY
10620 bool found = false;
10621
10622 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
10623
10624 if (!bgp) {
10625 vty_out(vty, "%% No such BGP instance exists\n");
10626 return CMD_WARNING;
10627 }
d62a17ae 10628
10629 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
10630 if (group_name) {
10631 if (strmatch(group->name, group_name)) {
d62a17ae 10632 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
10633 found = true;
10634 break;
d62a17ae 10635 }
ff9959b0
QY
10636 } else {
10637 bgp_show_one_peer_group(vty, group);
d62a17ae 10638 }
f14e6fdb 10639 }
f14e6fdb 10640
ff9959b0 10641 if (group_name && !found)
d62a17ae 10642 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 10643
d62a17ae 10644 return CMD_SUCCESS;
f14e6fdb
DS
10645}
10646
f14e6fdb
DS
10647DEFUN (show_ip_bgp_peer_groups,
10648 show_ip_bgp_peer_groups_cmd,
18c57037 10649 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10650 SHOW_STR
10651 IP_STR
10652 BGP_STR
8386ac43 10653 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10654 "Detailed information on BGP peer groups\n"
10655 "Peer group name\n")
f14e6fdb 10656{
d62a17ae 10657 char *vrf, *pg;
10658 vrf = pg = NULL;
10659 int idx = 0;
f14e6fdb 10660
a4d82a8a
PZ
10661 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
10662 : NULL;
d62a17ae 10663 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10664
ff9959b0 10665 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 10666}
3f9c7369 10667
d6e3c605 10668
718e3744 10669/* Redistribute VTY commands. */
10670
718e3744 10671DEFUN (bgp_redistribute_ipv4,
10672 bgp_redistribute_ipv4_cmd,
40d1cbfb 10673 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 10674 "Redistribute information from another routing protocol\n"
ab0181ee 10675 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 10676{
d62a17ae 10677 VTY_DECLVAR_CONTEXT(bgp, bgp);
10678 int idx_protocol = 1;
10679 int type;
718e3744 10680
d62a17ae 10681 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10682 if (type < 0) {
10683 vty_out(vty, "%% Invalid route type\n");
10684 return CMD_WARNING_CONFIG_FAILED;
10685 }
7f323236 10686
d62a17ae 10687 bgp_redist_add(bgp, AFI_IP, type, 0);
10688 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10689}
10690
d62a17ae 10691ALIAS_HIDDEN(
10692 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10693 "redistribute " FRR_IP_REDIST_STR_BGPD,
10694 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 10695
718e3744 10696DEFUN (bgp_redistribute_ipv4_rmap,
10697 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 10698 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 10699 "Redistribute information from another routing protocol\n"
ab0181ee 10700 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10701 "Route map reference\n"
10702 "Pointer to route-map entries\n")
10703{
d62a17ae 10704 VTY_DECLVAR_CONTEXT(bgp, bgp);
10705 int idx_protocol = 1;
10706 int idx_word = 3;
10707 int type;
10708 struct bgp_redist *red;
718e3744 10709
d62a17ae 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 }
718e3744 10715
d62a17ae 10716 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10717 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10718 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10719}
10720
d62a17ae 10721ALIAS_HIDDEN(
10722 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
10723 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10724 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10725 "Route map reference\n"
10726 "Pointer to route-map entries\n")
596c17ba 10727
718e3744 10728DEFUN (bgp_redistribute_ipv4_metric,
10729 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 10730 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 10731 "Redistribute information from another routing protocol\n"
ab0181ee 10732 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10733 "Metric for redistributed routes\n"
10734 "Default metric\n")
10735{
d62a17ae 10736 VTY_DECLVAR_CONTEXT(bgp, bgp);
10737 int idx_protocol = 1;
10738 int idx_number = 3;
10739 int type;
10740 u_int32_t metric;
10741 struct bgp_redist *red;
10742
10743 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10744 if (type < 0) {
10745 vty_out(vty, "%% Invalid route type\n");
10746 return CMD_WARNING_CONFIG_FAILED;
10747 }
10748 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10749
10750 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10751 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10752 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10753}
10754
10755ALIAS_HIDDEN(
10756 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
10757 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10758 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10759 "Metric for redistributed routes\n"
10760 "Default metric\n")
596c17ba 10761
718e3744 10762DEFUN (bgp_redistribute_ipv4_rmap_metric,
10763 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 10764 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 10765 "Redistribute information from another routing protocol\n"
ab0181ee 10766 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10767 "Route map reference\n"
10768 "Pointer to route-map entries\n"
10769 "Metric for redistributed routes\n"
10770 "Default metric\n")
10771{
d62a17ae 10772 VTY_DECLVAR_CONTEXT(bgp, bgp);
10773 int idx_protocol = 1;
10774 int idx_word = 3;
10775 int idx_number = 5;
10776 int type;
10777 u_int32_t metric;
10778 struct bgp_redist *red;
10779
10780 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10781 if (type < 0) {
10782 vty_out(vty, "%% Invalid route type\n");
10783 return CMD_WARNING_CONFIG_FAILED;
10784 }
10785 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10786
10787 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10788 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10789 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10790 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10791}
10792
10793ALIAS_HIDDEN(
10794 bgp_redistribute_ipv4_rmap_metric,
10795 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10796 "redistribute " FRR_IP_REDIST_STR_BGPD
10797 " route-map WORD metric (0-4294967295)",
10798 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10799 "Route map reference\n"
10800 "Pointer to route-map entries\n"
10801 "Metric for redistributed routes\n"
10802 "Default metric\n")
596c17ba 10803
718e3744 10804DEFUN (bgp_redistribute_ipv4_metric_rmap,
10805 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 10806 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 10807 "Redistribute information from another routing protocol\n"
ab0181ee 10808 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10809 "Metric for redistributed routes\n"
10810 "Default metric\n"
10811 "Route map reference\n"
10812 "Pointer to route-map entries\n")
10813{
d62a17ae 10814 VTY_DECLVAR_CONTEXT(bgp, bgp);
10815 int idx_protocol = 1;
10816 int idx_number = 3;
10817 int idx_word = 5;
10818 int type;
10819 u_int32_t metric;
10820 struct bgp_redist *red;
10821
10822 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10823 if (type < 0) {
10824 vty_out(vty, "%% Invalid route type\n");
10825 return CMD_WARNING_CONFIG_FAILED;
10826 }
10827 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10828
10829 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10830 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10831 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10832 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10833}
10834
10835ALIAS_HIDDEN(
10836 bgp_redistribute_ipv4_metric_rmap,
10837 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10838 "redistribute " FRR_IP_REDIST_STR_BGPD
10839 " metric (0-4294967295) route-map WORD",
10840 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10841 "Metric for redistributed routes\n"
10842 "Default metric\n"
10843 "Route map reference\n"
10844 "Pointer to route-map entries\n")
596c17ba 10845
7c8ff89e
DS
10846DEFUN (bgp_redistribute_ipv4_ospf,
10847 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 10848 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
10849 "Redistribute information from another routing protocol\n"
10850 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10851 "Non-main Kernel Routing Table\n"
10852 "Instance ID/Table ID\n")
7c8ff89e 10853{
d62a17ae 10854 VTY_DECLVAR_CONTEXT(bgp, bgp);
10855 int idx_ospf_table = 1;
10856 int idx_number = 2;
10857 u_short instance;
10858 u_short protocol;
7c8ff89e 10859
d62a17ae 10860 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 10861
d62a17ae 10862 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10863 protocol = ZEBRA_ROUTE_OSPF;
10864 else
10865 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 10866
d62a17ae 10867 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10868 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10869}
10870
d62a17ae 10871ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
10872 "redistribute <ospf|table> (1-65535)",
10873 "Redistribute information from another routing protocol\n"
10874 "Open Shortest Path First (OSPFv2)\n"
10875 "Non-main Kernel Routing Table\n"
10876 "Instance ID/Table ID\n")
596c17ba 10877
7c8ff89e
DS
10878DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10879 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 10880 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
10881 "Redistribute information from another routing protocol\n"
10882 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10883 "Non-main Kernel Routing Table\n"
10884 "Instance ID/Table ID\n"
7c8ff89e
DS
10885 "Route map reference\n"
10886 "Pointer to route-map entries\n")
10887{
d62a17ae 10888 VTY_DECLVAR_CONTEXT(bgp, bgp);
10889 int idx_ospf_table = 1;
10890 int idx_number = 2;
10891 int idx_word = 4;
10892 struct bgp_redist *red;
10893 u_short instance;
10894 int protocol;
10895
10896 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10897 protocol = ZEBRA_ROUTE_OSPF;
10898 else
10899 protocol = ZEBRA_ROUTE_TABLE;
10900
10901 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10902 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10903 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10904 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10905}
10906
10907ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
10908 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10909 "redistribute <ospf|table> (1-65535) route-map WORD",
10910 "Redistribute information from another routing protocol\n"
10911 "Open Shortest Path First (OSPFv2)\n"
10912 "Non-main Kernel Routing Table\n"
10913 "Instance ID/Table ID\n"
10914 "Route map reference\n"
10915 "Pointer to route-map entries\n")
596c17ba 10916
7c8ff89e
DS
10917DEFUN (bgp_redistribute_ipv4_ospf_metric,
10918 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 10919 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
10920 "Redistribute information from another routing protocol\n"
10921 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10922 "Non-main Kernel Routing Table\n"
10923 "Instance ID/Table ID\n"
7c8ff89e
DS
10924 "Metric for redistributed routes\n"
10925 "Default metric\n")
10926{
d62a17ae 10927 VTY_DECLVAR_CONTEXT(bgp, bgp);
10928 int idx_ospf_table = 1;
10929 int idx_number = 2;
10930 int idx_number_2 = 4;
10931 u_int32_t metric;
10932 struct bgp_redist *red;
10933 u_short instance;
10934 int protocol;
10935
10936 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10937 protocol = ZEBRA_ROUTE_OSPF;
10938 else
10939 protocol = ZEBRA_ROUTE_TABLE;
10940
10941 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10942 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10943
10944 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10945 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10946 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10947}
10948
10949ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
10950 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10951 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10952 "Redistribute information from another routing protocol\n"
10953 "Open Shortest Path First (OSPFv2)\n"
10954 "Non-main Kernel Routing Table\n"
10955 "Instance ID/Table ID\n"
10956 "Metric for redistributed routes\n"
10957 "Default metric\n")
596c17ba 10958
7c8ff89e
DS
10959DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10960 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 10961 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
10962 "Redistribute information from another routing protocol\n"
10963 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10964 "Non-main Kernel Routing Table\n"
10965 "Instance ID/Table ID\n"
7c8ff89e
DS
10966 "Route map reference\n"
10967 "Pointer to route-map entries\n"
10968 "Metric for redistributed routes\n"
10969 "Default metric\n")
10970{
d62a17ae 10971 VTY_DECLVAR_CONTEXT(bgp, bgp);
10972 int idx_ospf_table = 1;
10973 int idx_number = 2;
10974 int idx_word = 4;
10975 int idx_number_2 = 6;
10976 u_int32_t metric;
10977 struct bgp_redist *red;
10978 u_short instance;
10979 int protocol;
10980
10981 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10982 protocol = ZEBRA_ROUTE_OSPF;
10983 else
10984 protocol = ZEBRA_ROUTE_TABLE;
10985
10986 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10987 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10988
10989 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10990 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10991 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10992 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10993}
10994
10995ALIAS_HIDDEN(
10996 bgp_redistribute_ipv4_ospf_rmap_metric,
10997 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10998 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10999 "Redistribute information from another routing protocol\n"
11000 "Open Shortest Path First (OSPFv2)\n"
11001 "Non-main Kernel Routing Table\n"
11002 "Instance ID/Table ID\n"
11003 "Route map reference\n"
11004 "Pointer to route-map entries\n"
11005 "Metric for redistributed routes\n"
11006 "Default metric\n")
596c17ba 11007
7c8ff89e
DS
11008DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11009 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11010 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11011 "Redistribute information from another routing protocol\n"
11012 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11013 "Non-main Kernel Routing Table\n"
11014 "Instance ID/Table ID\n"
7c8ff89e
DS
11015 "Metric for redistributed routes\n"
11016 "Default metric\n"
11017 "Route map reference\n"
11018 "Pointer to route-map entries\n")
11019{
d62a17ae 11020 VTY_DECLVAR_CONTEXT(bgp, bgp);
11021 int idx_ospf_table = 1;
11022 int idx_number = 2;
11023 int idx_number_2 = 4;
11024 int idx_word = 6;
11025 u_int32_t metric;
11026 struct bgp_redist *red;
11027 u_short instance;
11028 int protocol;
11029
11030 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11031 protocol = ZEBRA_ROUTE_OSPF;
11032 else
11033 protocol = ZEBRA_ROUTE_TABLE;
11034
11035 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11036 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11037
11038 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11039 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11040 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11041 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11042}
11043
11044ALIAS_HIDDEN(
11045 bgp_redistribute_ipv4_ospf_metric_rmap,
11046 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11047 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11048 "Redistribute information from another routing protocol\n"
11049 "Open Shortest Path First (OSPFv2)\n"
11050 "Non-main Kernel Routing Table\n"
11051 "Instance ID/Table ID\n"
11052 "Metric for redistributed routes\n"
11053 "Default metric\n"
11054 "Route map reference\n"
11055 "Pointer to route-map entries\n")
596c17ba 11056
7c8ff89e
DS
11057DEFUN (no_bgp_redistribute_ipv4_ospf,
11058 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11059 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11060 NO_STR
11061 "Redistribute information from another routing protocol\n"
11062 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11063 "Non-main Kernel Routing Table\n"
31500417
DW
11064 "Instance ID/Table ID\n"
11065 "Metric for redistributed routes\n"
11066 "Default metric\n"
11067 "Route map reference\n"
11068 "Pointer to route-map entries\n")
7c8ff89e 11069{
d62a17ae 11070 VTY_DECLVAR_CONTEXT(bgp, bgp);
11071 int idx_ospf_table = 2;
11072 int idx_number = 3;
11073 u_short instance;
11074 int protocol;
11075
11076 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11077 protocol = ZEBRA_ROUTE_OSPF;
11078 else
11079 protocol = ZEBRA_ROUTE_TABLE;
11080
11081 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11082 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11083}
11084
11085ALIAS_HIDDEN(
11086 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11087 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11088 NO_STR
11089 "Redistribute information from another routing protocol\n"
11090 "Open Shortest Path First (OSPFv2)\n"
11091 "Non-main Kernel Routing Table\n"
11092 "Instance ID/Table ID\n"
11093 "Metric for redistributed routes\n"
11094 "Default metric\n"
11095 "Route map reference\n"
11096 "Pointer to route-map entries\n")
596c17ba 11097
718e3744 11098DEFUN (no_bgp_redistribute_ipv4,
11099 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11100 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11101 NO_STR
11102 "Redistribute information from another routing protocol\n"
3b14d86e 11103 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11104 "Metric for redistributed routes\n"
11105 "Default metric\n"
11106 "Route map reference\n"
11107 "Pointer to route-map entries\n")
718e3744 11108{
d62a17ae 11109 VTY_DECLVAR_CONTEXT(bgp, bgp);
11110 int idx_protocol = 2;
11111 int type;
11112
11113 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11114 if (type < 0) {
11115 vty_out(vty, "%% Invalid route type\n");
11116 return CMD_WARNING_CONFIG_FAILED;
11117 }
11118 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11119}
11120
11121ALIAS_HIDDEN(
11122 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11123 "no redistribute " FRR_IP_REDIST_STR_BGPD
11124 " [metric (0-4294967295)] [route-map WORD]",
11125 NO_STR
11126 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11127 "Metric for redistributed routes\n"
11128 "Default metric\n"
11129 "Route map reference\n"
11130 "Pointer to route-map entries\n")
596c17ba 11131
718e3744 11132DEFUN (bgp_redistribute_ipv6,
11133 bgp_redistribute_ipv6_cmd,
40d1cbfb 11134 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11135 "Redistribute information from another routing protocol\n"
ab0181ee 11136 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11137{
d62a17ae 11138 VTY_DECLVAR_CONTEXT(bgp, bgp);
11139 int idx_protocol = 1;
11140 int type;
718e3744 11141
d62a17ae 11142 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11143 if (type < 0) {
11144 vty_out(vty, "%% Invalid route type\n");
11145 return CMD_WARNING_CONFIG_FAILED;
11146 }
718e3744 11147
d62a17ae 11148 bgp_redist_add(bgp, AFI_IP6, type, 0);
11149 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11150}
11151
11152DEFUN (bgp_redistribute_ipv6_rmap,
11153 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11154 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11155 "Redistribute information from another routing protocol\n"
ab0181ee 11156 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11157 "Route map reference\n"
11158 "Pointer to route-map entries\n")
11159{
d62a17ae 11160 VTY_DECLVAR_CONTEXT(bgp, bgp);
11161 int idx_protocol = 1;
11162 int idx_word = 3;
11163 int type;
11164 struct bgp_redist *red;
718e3744 11165
d62a17ae 11166 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11167 if (type < 0) {
11168 vty_out(vty, "%% Invalid route type\n");
11169 return CMD_WARNING_CONFIG_FAILED;
11170 }
718e3744 11171
d62a17ae 11172 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11173 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11174 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11175}
11176
11177DEFUN (bgp_redistribute_ipv6_metric,
11178 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11179 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11180 "Redistribute information from another routing protocol\n"
ab0181ee 11181 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11182 "Metric for redistributed routes\n"
11183 "Default metric\n")
11184{
d62a17ae 11185 VTY_DECLVAR_CONTEXT(bgp, bgp);
11186 int idx_protocol = 1;
11187 int idx_number = 3;
11188 int type;
11189 u_int32_t metric;
11190 struct bgp_redist *red;
11191
11192 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11193 if (type < 0) {
11194 vty_out(vty, "%% Invalid route type\n");
11195 return CMD_WARNING_CONFIG_FAILED;
11196 }
11197 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11198
d62a17ae 11199 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11200 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11201 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11202}
11203
11204DEFUN (bgp_redistribute_ipv6_rmap_metric,
11205 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11206 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11207 "Redistribute information from another routing protocol\n"
ab0181ee 11208 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11209 "Route map reference\n"
11210 "Pointer to route-map entries\n"
11211 "Metric for redistributed routes\n"
11212 "Default metric\n")
11213{
d62a17ae 11214 VTY_DECLVAR_CONTEXT(bgp, bgp);
11215 int idx_protocol = 1;
11216 int idx_word = 3;
11217 int idx_number = 5;
11218 int type;
11219 u_int32_t metric;
11220 struct bgp_redist *red;
11221
11222 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11223 if (type < 0) {
11224 vty_out(vty, "%% Invalid route type\n");
11225 return CMD_WARNING_CONFIG_FAILED;
11226 }
11227 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11228
d62a17ae 11229 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11230 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11231 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11232 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11233}
11234
11235DEFUN (bgp_redistribute_ipv6_metric_rmap,
11236 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11237 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11238 "Redistribute information from another routing protocol\n"
ab0181ee 11239 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11240 "Metric for redistributed routes\n"
11241 "Default metric\n"
11242 "Route map reference\n"
11243 "Pointer to route-map entries\n")
11244{
d62a17ae 11245 VTY_DECLVAR_CONTEXT(bgp, bgp);
11246 int idx_protocol = 1;
11247 int idx_number = 3;
11248 int idx_word = 5;
11249 int type;
11250 u_int32_t metric;
11251 struct bgp_redist *red;
11252
11253 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11254 if (type < 0) {
11255 vty_out(vty, "%% Invalid route type\n");
11256 return CMD_WARNING_CONFIG_FAILED;
11257 }
11258 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11259
d62a17ae 11260 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11261 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11262 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11263 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11264}
11265
11266DEFUN (no_bgp_redistribute_ipv6,
11267 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11268 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11269 NO_STR
11270 "Redistribute information from another routing protocol\n"
3b14d86e 11271 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11272 "Metric for redistributed routes\n"
11273 "Default metric\n"
11274 "Route map reference\n"
11275 "Pointer to route-map entries\n")
718e3744 11276{
d62a17ae 11277 VTY_DECLVAR_CONTEXT(bgp, bgp);
11278 int idx_protocol = 2;
11279 int type;
718e3744 11280
d62a17ae 11281 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11282 if (type < 0) {
11283 vty_out(vty, "%% Invalid route type\n");
11284 return CMD_WARNING_CONFIG_FAILED;
11285 }
718e3744 11286
d62a17ae 11287 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11288}
11289
2b791107 11290void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 11291 safi_t safi)
d62a17ae 11292{
11293 int i;
11294
11295 /* Unicast redistribution only. */
11296 if (safi != SAFI_UNICAST)
2b791107 11297 return;
d62a17ae 11298
11299 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11300 /* Redistribute BGP does not make sense. */
11301 if (i != ZEBRA_ROUTE_BGP) {
11302 struct list *red_list;
11303 struct listnode *node;
11304 struct bgp_redist *red;
11305
11306 red_list = bgp->redist[afi][i];
11307 if (!red_list)
11308 continue;
11309
11310 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 11311 /* "redistribute" configuration. */
11312 vty_out(vty, " redistribute %s",
11313 zebra_route_string(i));
11314 if (red->instance)
11315 vty_out(vty, " %d", red->instance);
11316 if (red->redist_metric_flag)
11317 vty_out(vty, " metric %u",
11318 red->redist_metric);
11319 if (red->rmap.name)
11320 vty_out(vty, " route-map %s",
11321 red->rmap.name);
11322 vty_out(vty, "\n");
11323 }
11324 }
11325 }
718e3744 11326}
6b0655a2 11327
718e3744 11328/* BGP node structure. */
d62a17ae 11329static struct cmd_node bgp_node = {
9d303b37 11330 BGP_NODE, "%s(config-router)# ", 1,
718e3744 11331};
11332
d62a17ae 11333static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 11334 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 11335};
11336
d62a17ae 11337static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 11338 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 11339};
11340
d62a17ae 11341static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 11342 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11343};
11344
d62a17ae 11345static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 11346 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 11347};
11348
d62a17ae 11349static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 11350 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 11351};
11352
d62a17ae 11353static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 11354 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11355};
11356
d62a17ae 11357static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11358 "%s(config-router-af)# ", 1};
6b0655a2 11359
d62a17ae 11360static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11361 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 11362
d62a17ae 11363static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11364 "%s(config-router-evpn)# ", 1};
4e0b7b6d 11365
d62a17ae 11366static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11367 "%s(config-router-af-vni)# ", 1};
90e60aa7 11368
d62a17ae 11369static void community_list_vty(void);
1f8ae70b 11370
d62a17ae 11371static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 11372{
d62a17ae 11373 struct bgp *bgp;
11374 struct peer *peer;
11375 struct peer_group *group;
11376 struct listnode *lnbgp, *lnpeer;
b8a815e5 11377
d62a17ae 11378 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11379 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11380 /* only provide suggestions on the appropriate input
11381 * token type,
11382 * they'll otherwise show up multiple times */
11383 enum cmd_token_type match_type;
11384 char *name = peer->host;
d48ed3e0 11385
d62a17ae 11386 if (peer->conf_if) {
11387 match_type = VARIABLE_TKN;
11388 name = peer->conf_if;
11389 } else if (strchr(peer->host, ':'))
11390 match_type = IPV6_TKN;
11391 else
11392 match_type = IPV4_TKN;
d48ed3e0 11393
d62a17ae 11394 if (token->type != match_type)
11395 continue;
d48ed3e0 11396
d62a17ae 11397 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11398 }
d48ed3e0 11399
d62a17ae 11400 if (token->type == VARIABLE_TKN)
11401 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11402 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11403 group->name));
11404 }
b8a815e5
DL
11405}
11406
11407static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 11408 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11409 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 11410 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 11411 {.completions = NULL}};
11412
11413void bgp_vty_init(void)
11414{
11415 cmd_variable_handler_register(bgp_var_neighbor);
11416
11417 /* Install bgp top node. */
11418 install_node(&bgp_node, bgp_config_write);
11419 install_node(&bgp_ipv4_unicast_node, NULL);
11420 install_node(&bgp_ipv4_multicast_node, NULL);
11421 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11422 install_node(&bgp_ipv6_unicast_node, NULL);
11423 install_node(&bgp_ipv6_multicast_node, NULL);
11424 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11425 install_node(&bgp_vpnv4_node, NULL);
11426 install_node(&bgp_vpnv6_node, NULL);
11427 install_node(&bgp_evpn_node, NULL);
11428 install_node(&bgp_evpn_vni_node, NULL);
11429
11430 /* Install default VTY commands to new nodes. */
11431 install_default(BGP_NODE);
11432 install_default(BGP_IPV4_NODE);
11433 install_default(BGP_IPV4M_NODE);
11434 install_default(BGP_IPV4L_NODE);
11435 install_default(BGP_IPV6_NODE);
11436 install_default(BGP_IPV6M_NODE);
11437 install_default(BGP_IPV6L_NODE);
11438 install_default(BGP_VPNV4_NODE);
11439 install_default(BGP_VPNV6_NODE);
11440 install_default(BGP_EVPN_NODE);
11441 install_default(BGP_EVPN_VNI_NODE);
11442
11443 /* "bgp multiple-instance" commands. */
11444 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11445 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11446
11447 /* "bgp config-type" commands. */
11448 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11449 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11450
11451 /* bgp route-map delay-timer commands. */
11452 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11453 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11454
11455 /* Dummy commands (Currently not supported) */
11456 install_element(BGP_NODE, &no_synchronization_cmd);
11457 install_element(BGP_NODE, &no_auto_summary_cmd);
11458
11459 /* "router bgp" commands. */
11460 install_element(CONFIG_NODE, &router_bgp_cmd);
11461
11462 /* "no router bgp" commands. */
11463 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11464
11465 /* "bgp router-id" commands. */
11466 install_element(BGP_NODE, &bgp_router_id_cmd);
11467 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11468
11469 /* "bgp cluster-id" commands. */
11470 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11471 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11472
11473 /* "bgp confederation" commands. */
11474 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11475 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11476
11477 /* "bgp confederation peers" commands. */
11478 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11479 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11480
11481 /* bgp max-med command */
11482 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11483 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11484 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11485 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11486 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11487
11488 /* bgp disable-ebgp-connected-nh-check */
11489 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11490 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11491
11492 /* bgp update-delay command */
11493 install_element(BGP_NODE, &bgp_update_delay_cmd);
11494 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11495 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11496
11497 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11498 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
11499 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
11500 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 11501
11502 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11503 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11504
11505 /* "maximum-paths" commands. */
11506 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11507 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11508 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11509 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11510 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11511 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11512 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11513 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11514 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11515 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11516 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11517 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11518 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11519 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11520 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11521
11522 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11523 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11524 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11525 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11526 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11527
11528 /* "timers bgp" commands. */
11529 install_element(BGP_NODE, &bgp_timers_cmd);
11530 install_element(BGP_NODE, &no_bgp_timers_cmd);
11531
11532 /* route-map delay-timer commands - per instance for backwards compat.
11533 */
11534 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11535 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11536
11537 /* "bgp client-to-client reflection" commands */
11538 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11539 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11540
11541 /* "bgp always-compare-med" commands */
11542 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11543 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11544
11545 /* "bgp deterministic-med" commands */
11546 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11547 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11548
11549 /* "bgp graceful-restart" commands */
11550 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11551 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11552 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11553 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11554 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11555 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11556
11557 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11558 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11559
7f323236
DW
11560 /* "bgp graceful-shutdown" commands */
11561 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
11562 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
11563
d62a17ae 11564 /* "bgp fast-external-failover" commands */
11565 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11566 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11567
11568 /* "bgp enforce-first-as" commands */
11569 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11570 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11571
11572 /* "bgp bestpath compare-routerid" commands */
11573 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11574 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11575
11576 /* "bgp bestpath as-path ignore" commands */
11577 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11578 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11579
11580 /* "bgp bestpath as-path confed" commands */
11581 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11582 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11583
11584 /* "bgp bestpath as-path multipath-relax" commands */
11585 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11586 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11587
11588 /* "bgp log-neighbor-changes" commands */
11589 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11590 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11591
11592 /* "bgp bestpath med" commands */
11593 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11594 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11595
11596 /* "no bgp default ipv4-unicast" commands. */
11597 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11598 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11599
11600 /* "bgp network import-check" commands. */
11601 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11602 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11603 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11604
11605 /* "bgp default local-preference" commands. */
11606 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11607 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11608
11609 /* bgp default show-hostname */
11610 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11611 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11612
11613 /* "bgp default subgroup-pkt-queue-max" commands. */
11614 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11615 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11616
11617 /* bgp ibgp-allow-policy-mods command */
11618 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11619 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11620
11621 /* "bgp listen limit" commands. */
11622 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11623 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11624
11625 /* "bgp listen range" commands. */
11626 install_element(BGP_NODE, &bgp_listen_range_cmd);
11627 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11628
8175f54a 11629 /* "bgp default shutdown" command */
f26845f9
QY
11630 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
11631
d62a17ae 11632 /* "neighbor remote-as" commands. */
11633 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11634 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11635 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11636 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11637 install_element(BGP_NODE,
11638 &neighbor_interface_v6only_config_remote_as_cmd);
11639 install_element(BGP_NODE, &no_neighbor_cmd);
11640 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
11641
11642 /* "neighbor peer-group" commands. */
11643 install_element(BGP_NODE, &neighbor_peer_group_cmd);
11644 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
11645 install_element(BGP_NODE,
11646 &no_neighbor_interface_peer_group_remote_as_cmd);
11647
11648 /* "neighbor local-as" commands. */
11649 install_element(BGP_NODE, &neighbor_local_as_cmd);
11650 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
11651 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
11652 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
11653
11654 /* "neighbor solo" commands. */
11655 install_element(BGP_NODE, &neighbor_solo_cmd);
11656 install_element(BGP_NODE, &no_neighbor_solo_cmd);
11657
11658 /* "neighbor password" commands. */
11659 install_element(BGP_NODE, &neighbor_password_cmd);
11660 install_element(BGP_NODE, &no_neighbor_password_cmd);
11661
11662 /* "neighbor activate" commands. */
11663 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
11664 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
11665 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
11666 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
11667 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
11668 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
11669 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
11670 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
11671 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
11672 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
11673
11674 /* "no neighbor activate" commands. */
11675 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
11676 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11677 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
11678 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
11679 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
11680 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
11681 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
11682 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
11683 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
11684 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
11685
11686 /* "neighbor peer-group" set commands. */
11687 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
11688 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11689 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11690 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11691 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11692 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11693 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11694 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11695
11696 /* "no neighbor peer-group unset" commands. */
11697 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
11698 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11699 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11700 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11701 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11702 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11703 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11704 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11705
11706 /* "neighbor softreconfiguration inbound" commands.*/
11707 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11708 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
11709 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11710 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11711 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11712 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11713 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11714 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11715 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11716 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11717 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11718 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11719 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11720 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11721 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11722 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11723 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11724 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11725
11726 /* "neighbor attribute-unchanged" commands. */
11727 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11728 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
11729 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
11730 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
11731 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
11732 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
11733 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11734 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
11735 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
11736 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
11737 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
11738 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
11739 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11740 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
11741 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
11742 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
11743 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
11744 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
11745
11746 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11747 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11748
11749 /* "nexthop-local unchanged" commands */
11750 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11751 install_element(BGP_IPV6_NODE,
11752 &no_neighbor_nexthop_local_unchanged_cmd);
11753
11754 /* "neighbor next-hop-self" commands. */
11755 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11756 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
11757 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11758 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11759 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11760 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
11761 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11762 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
11763 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11764 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
11765 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11766 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
11767 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11768 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
11769 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11770 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
11771 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11772 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
11773
11774 /* "neighbor next-hop-self force" commands. */
11775 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11776 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
11777 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11778 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11779 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11780 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
11781 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11782 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
11783 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11784 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11785 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11786 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
11787 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11788 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
11789 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11790 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11791 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11792 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11793
11794 /* "neighbor as-override" commands. */
11795 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
11796 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
11797 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
11798 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11799 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11800 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
11801 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11802 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
11803 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
11804 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11805 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11806 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
11807 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11808 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
11809 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11810 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
11811 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11812 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
11813
11814 /* "neighbor remove-private-AS" commands. */
11815 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11816 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11817 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11818 install_element(BGP_NODE,
11819 &no_neighbor_remove_private_as_all_hidden_cmd);
11820 install_element(BGP_NODE,
11821 &neighbor_remove_private_as_replace_as_hidden_cmd);
11822 install_element(BGP_NODE,
11823 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11824 install_element(BGP_NODE,
11825 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11826 install_element(
11827 BGP_NODE,
11828 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
11829 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11830 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
11831 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11832 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11833 install_element(BGP_IPV4_NODE,
11834 &neighbor_remove_private_as_replace_as_cmd);
11835 install_element(BGP_IPV4_NODE,
11836 &no_neighbor_remove_private_as_replace_as_cmd);
11837 install_element(BGP_IPV4_NODE,
11838 &neighbor_remove_private_as_all_replace_as_cmd);
11839 install_element(BGP_IPV4_NODE,
11840 &no_neighbor_remove_private_as_all_replace_as_cmd);
11841 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11842 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
11843 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11844 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11845 install_element(BGP_IPV4M_NODE,
11846 &neighbor_remove_private_as_replace_as_cmd);
11847 install_element(BGP_IPV4M_NODE,
11848 &no_neighbor_remove_private_as_replace_as_cmd);
11849 install_element(BGP_IPV4M_NODE,
11850 &neighbor_remove_private_as_all_replace_as_cmd);
11851 install_element(BGP_IPV4M_NODE,
11852 &no_neighbor_remove_private_as_all_replace_as_cmd);
11853 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11854 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11855 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11856 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11857 install_element(BGP_IPV4L_NODE,
11858 &neighbor_remove_private_as_replace_as_cmd);
11859 install_element(BGP_IPV4L_NODE,
11860 &no_neighbor_remove_private_as_replace_as_cmd);
11861 install_element(BGP_IPV4L_NODE,
11862 &neighbor_remove_private_as_all_replace_as_cmd);
11863 install_element(BGP_IPV4L_NODE,
11864 &no_neighbor_remove_private_as_all_replace_as_cmd);
11865 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11866 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
11867 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11868 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11869 install_element(BGP_IPV6_NODE,
11870 &neighbor_remove_private_as_replace_as_cmd);
11871 install_element(BGP_IPV6_NODE,
11872 &no_neighbor_remove_private_as_replace_as_cmd);
11873 install_element(BGP_IPV6_NODE,
11874 &neighbor_remove_private_as_all_replace_as_cmd);
11875 install_element(BGP_IPV6_NODE,
11876 &no_neighbor_remove_private_as_all_replace_as_cmd);
11877 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11878 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
11879 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11880 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11881 install_element(BGP_IPV6M_NODE,
11882 &neighbor_remove_private_as_replace_as_cmd);
11883 install_element(BGP_IPV6M_NODE,
11884 &no_neighbor_remove_private_as_replace_as_cmd);
11885 install_element(BGP_IPV6M_NODE,
11886 &neighbor_remove_private_as_all_replace_as_cmd);
11887 install_element(BGP_IPV6M_NODE,
11888 &no_neighbor_remove_private_as_all_replace_as_cmd);
11889 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11890 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11891 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11892 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11893 install_element(BGP_IPV6L_NODE,
11894 &neighbor_remove_private_as_replace_as_cmd);
11895 install_element(BGP_IPV6L_NODE,
11896 &no_neighbor_remove_private_as_replace_as_cmd);
11897 install_element(BGP_IPV6L_NODE,
11898 &neighbor_remove_private_as_all_replace_as_cmd);
11899 install_element(BGP_IPV6L_NODE,
11900 &no_neighbor_remove_private_as_all_replace_as_cmd);
11901 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11902 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
11903 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11904 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11905 install_element(BGP_VPNV4_NODE,
11906 &neighbor_remove_private_as_replace_as_cmd);
11907 install_element(BGP_VPNV4_NODE,
11908 &no_neighbor_remove_private_as_replace_as_cmd);
11909 install_element(BGP_VPNV4_NODE,
11910 &neighbor_remove_private_as_all_replace_as_cmd);
11911 install_element(BGP_VPNV4_NODE,
11912 &no_neighbor_remove_private_as_all_replace_as_cmd);
11913 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11914 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11915 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11916 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11917 install_element(BGP_VPNV6_NODE,
11918 &neighbor_remove_private_as_replace_as_cmd);
11919 install_element(BGP_VPNV6_NODE,
11920 &no_neighbor_remove_private_as_replace_as_cmd);
11921 install_element(BGP_VPNV6_NODE,
11922 &neighbor_remove_private_as_all_replace_as_cmd);
11923 install_element(BGP_VPNV6_NODE,
11924 &no_neighbor_remove_private_as_all_replace_as_cmd);
11925
11926 /* "neighbor send-community" commands.*/
11927 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
11928 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11929 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11930 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
11931 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
11932 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11933 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11934 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11935 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11936 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11937 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11938 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
11939 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11940 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11941 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11942 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
11943 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
11944 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11945 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11946 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
11947 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11948 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11949 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11950 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
11951 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11952 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11953 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11954 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
11955 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11956 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11957 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11958 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
11959 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11960 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11961 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11962 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
11963
11964 /* "neighbor route-reflector" commands.*/
11965 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11966 install_element(BGP_NODE,
11967 &no_neighbor_route_reflector_client_hidden_cmd);
11968 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11969 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11970 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11971 install_element(BGP_IPV4M_NODE,
11972 &no_neighbor_route_reflector_client_cmd);
11973 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11974 install_element(BGP_IPV4L_NODE,
11975 &no_neighbor_route_reflector_client_cmd);
11976 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11977 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
11978 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11979 install_element(BGP_IPV6M_NODE,
11980 &no_neighbor_route_reflector_client_cmd);
11981 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11982 install_element(BGP_IPV6L_NODE,
11983 &no_neighbor_route_reflector_client_cmd);
11984 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11985 install_element(BGP_VPNV4_NODE,
11986 &no_neighbor_route_reflector_client_cmd);
11987 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11988 install_element(BGP_VPNV6_NODE,
11989 &no_neighbor_route_reflector_client_cmd);
11990 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
11991 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
11992
11993 /* "neighbor route-server" commands.*/
11994 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11995 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
11996 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11997 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11998 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11999 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12000 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12001 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12002 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12003 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12004 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12005 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12006 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12007 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12008 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12009 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12010 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12011 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12012
12013 /* "neighbor addpath-tx-all-paths" commands.*/
12014 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12015 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12016 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12017 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12018 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12019 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12020 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12021 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12022 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12023 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12024 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12025 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12026 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12027 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12028 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12029 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12030 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12031 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12032
12033 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12034 install_element(BGP_NODE,
12035 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12036 install_element(BGP_NODE,
12037 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12038 install_element(BGP_IPV4_NODE,
12039 &neighbor_addpath_tx_bestpath_per_as_cmd);
12040 install_element(BGP_IPV4_NODE,
12041 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12042 install_element(BGP_IPV4M_NODE,
12043 &neighbor_addpath_tx_bestpath_per_as_cmd);
12044 install_element(BGP_IPV4M_NODE,
12045 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12046 install_element(BGP_IPV4L_NODE,
12047 &neighbor_addpath_tx_bestpath_per_as_cmd);
12048 install_element(BGP_IPV4L_NODE,
12049 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12050 install_element(BGP_IPV6_NODE,
12051 &neighbor_addpath_tx_bestpath_per_as_cmd);
12052 install_element(BGP_IPV6_NODE,
12053 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12054 install_element(BGP_IPV6M_NODE,
12055 &neighbor_addpath_tx_bestpath_per_as_cmd);
12056 install_element(BGP_IPV6M_NODE,
12057 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12058 install_element(BGP_IPV6L_NODE,
12059 &neighbor_addpath_tx_bestpath_per_as_cmd);
12060 install_element(BGP_IPV6L_NODE,
12061 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12062 install_element(BGP_VPNV4_NODE,
12063 &neighbor_addpath_tx_bestpath_per_as_cmd);
12064 install_element(BGP_VPNV4_NODE,
12065 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12066 install_element(BGP_VPNV6_NODE,
12067 &neighbor_addpath_tx_bestpath_per_as_cmd);
12068 install_element(BGP_VPNV6_NODE,
12069 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12070
12071 /* "neighbor passive" commands. */
12072 install_element(BGP_NODE, &neighbor_passive_cmd);
12073 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12074
12075
12076 /* "neighbor shutdown" commands. */
12077 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12078 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12079 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12080 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12081
12082 /* "neighbor capability extended-nexthop" commands.*/
12083 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12084 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12085
12086 /* "neighbor capability orf prefix-list" commands.*/
12087 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12088 install_element(BGP_NODE,
12089 &no_neighbor_capability_orf_prefix_hidden_cmd);
12090 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12091 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12092 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12093 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12094 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12095 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12096 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12097 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12098 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12099 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12100 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12101 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12102
12103 /* "neighbor capability dynamic" commands.*/
12104 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12105 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12106
12107 /* "neighbor dont-capability-negotiate" commands. */
12108 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12109 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12110
12111 /* "neighbor ebgp-multihop" commands. */
12112 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12113 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12114 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12115
12116 /* "neighbor disable-connected-check" commands. */
12117 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12118 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12119
12120 /* "neighbor description" commands. */
12121 install_element(BGP_NODE, &neighbor_description_cmd);
12122 install_element(BGP_NODE, &no_neighbor_description_cmd);
12123
12124 /* "neighbor update-source" commands. "*/
12125 install_element(BGP_NODE, &neighbor_update_source_cmd);
12126 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12127
12128 /* "neighbor default-originate" commands. */
12129 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12130 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12131 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12132 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12133 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12134 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12135 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12136 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12137 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12138 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12139 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12140 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12141 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12142 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12143 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12144 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12145 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12146 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12147 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12148 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12149 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12150
12151 /* "neighbor port" commands. */
12152 install_element(BGP_NODE, &neighbor_port_cmd);
12153 install_element(BGP_NODE, &no_neighbor_port_cmd);
12154
12155 /* "neighbor weight" commands. */
12156 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12157 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12158
12159 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12160 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12161 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12162 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12163 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12164 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12165 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12166 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12167 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12168 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12169 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12170 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12171 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12172 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12173 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12174 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12175
12176 /* "neighbor override-capability" commands. */
12177 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12178 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12179
12180 /* "neighbor strict-capability-match" commands. */
12181 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12182 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12183
12184 /* "neighbor timers" commands. */
12185 install_element(BGP_NODE, &neighbor_timers_cmd);
12186 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12187
12188 /* "neighbor timers connect" commands. */
12189 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12190 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12191
12192 /* "neighbor advertisement-interval" commands. */
12193 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12194 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12195
12196 /* "neighbor interface" commands. */
12197 install_element(BGP_NODE, &neighbor_interface_cmd);
12198 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12199
12200 /* "neighbor distribute" commands. */
12201 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12202 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12203 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12204 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12205 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12206 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12207 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12208 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12209 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12210 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12211 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12212 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12213 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12214 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12215 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12216 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12217 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12218 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12219
12220 /* "neighbor prefix-list" commands. */
12221 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12222 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12223 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12224 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12225 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12226 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12227 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12228 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12229 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12230 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12231 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12232 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12233 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12234 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12235 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12236 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12237 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12238 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12239
12240 /* "neighbor filter-list" commands. */
12241 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12242 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12243 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12244 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12245 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12246 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12247 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12248 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12249 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12250 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12251 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12252 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12253 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12254 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12255 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12256 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12257 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12258 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12259
12260 /* "neighbor route-map" commands. */
12261 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12262 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12263 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12264 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12265 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12266 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12267 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12268 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12269 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12270 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12271 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12272 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12273 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12274 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12275 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12276 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12277 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12278 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
12279 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12280 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 12281
12282 /* "neighbor unsuppress-map" commands. */
12283 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12284 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12285 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12286 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12287 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12288 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12289 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12290 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12291 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12292 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12293 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12294 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12295 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12296 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12297 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12298 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12299 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12300 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12301
12302 /* "neighbor maximum-prefix" commands. */
12303 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12304 install_element(BGP_NODE,
12305 &neighbor_maximum_prefix_threshold_hidden_cmd);
12306 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12307 install_element(BGP_NODE,
12308 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12309 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12310 install_element(BGP_NODE,
12311 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12312 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12313 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12314 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12315 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12316 install_element(BGP_IPV4_NODE,
12317 &neighbor_maximum_prefix_threshold_warning_cmd);
12318 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12319 install_element(BGP_IPV4_NODE,
12320 &neighbor_maximum_prefix_threshold_restart_cmd);
12321 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12322 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12323 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12324 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12325 install_element(BGP_IPV4M_NODE,
12326 &neighbor_maximum_prefix_threshold_warning_cmd);
12327 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12328 install_element(BGP_IPV4M_NODE,
12329 &neighbor_maximum_prefix_threshold_restart_cmd);
12330 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12331 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12332 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12333 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12334 install_element(BGP_IPV4L_NODE,
12335 &neighbor_maximum_prefix_threshold_warning_cmd);
12336 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12337 install_element(BGP_IPV4L_NODE,
12338 &neighbor_maximum_prefix_threshold_restart_cmd);
12339 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12340 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12341 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12342 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12343 install_element(BGP_IPV6_NODE,
12344 &neighbor_maximum_prefix_threshold_warning_cmd);
12345 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12346 install_element(BGP_IPV6_NODE,
12347 &neighbor_maximum_prefix_threshold_restart_cmd);
12348 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12349 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12350 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12351 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12352 install_element(BGP_IPV6M_NODE,
12353 &neighbor_maximum_prefix_threshold_warning_cmd);
12354 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12355 install_element(BGP_IPV6M_NODE,
12356 &neighbor_maximum_prefix_threshold_restart_cmd);
12357 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12358 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12359 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12360 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12361 install_element(BGP_IPV6L_NODE,
12362 &neighbor_maximum_prefix_threshold_warning_cmd);
12363 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12364 install_element(BGP_IPV6L_NODE,
12365 &neighbor_maximum_prefix_threshold_restart_cmd);
12366 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12367 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12368 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12369 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12370 install_element(BGP_VPNV4_NODE,
12371 &neighbor_maximum_prefix_threshold_warning_cmd);
12372 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12373 install_element(BGP_VPNV4_NODE,
12374 &neighbor_maximum_prefix_threshold_restart_cmd);
12375 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12376 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12377 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12378 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12379 install_element(BGP_VPNV6_NODE,
12380 &neighbor_maximum_prefix_threshold_warning_cmd);
12381 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12382 install_element(BGP_VPNV6_NODE,
12383 &neighbor_maximum_prefix_threshold_restart_cmd);
12384 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12385
12386 /* "neighbor allowas-in" */
12387 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12388 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12389 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12390 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12391 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12392 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12393 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12394 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12395 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12396 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12397 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12398 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12399 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12400 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12401 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12402 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12403 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12404 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12405 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12406 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12407
12408 /* address-family commands. */
12409 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12410 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 12411#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 12412 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12413 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 12414#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 12415
d62a17ae 12416 install_element(BGP_NODE, &address_family_evpn_cmd);
12417
12418 /* "exit-address-family" command. */
12419 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12420 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12421 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12422 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12423 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12424 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12425 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12426 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12427 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12428
12429 /* "clear ip bgp commands" */
12430 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12431
12432 /* clear ip bgp prefix */
12433 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12434 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12435 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12436
12437 /* "show [ip] bgp summary" commands. */
12438 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
12439 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
12440 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
12441 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
12442 install_element(VIEW_NODE, &show_bgp_updgrps_adj_cmd);
12443 install_element(VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
12444 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
12445 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
12446 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
12447 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
12448 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12449 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
12450 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
12451 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
12452 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12453
12454 /* "show [ip] bgp neighbors" commands. */
12455 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12456
12457 /* "show [ip] bgp peer-group" commands. */
12458 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12459
12460 /* "show [ip] bgp paths" commands. */
12461 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12462
12463 /* "show [ip] bgp community" commands. */
12464 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12465
12466 /* "show ip bgp large-community" commands. */
12467 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12468 /* "show [ip] bgp attribute-info" commands. */
12469 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12470
12471 /* "redistribute" commands. */
12472 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12473 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12474 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12475 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12476 install_element(BGP_NODE,
12477 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12478 install_element(BGP_NODE,
12479 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12480 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12481 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12482 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12483 install_element(BGP_NODE,
12484 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12485 install_element(BGP_NODE,
12486 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12487 install_element(BGP_NODE,
12488 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12489 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12490 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12491 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12492 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12493 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12494 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12495 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12496 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12497 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12498 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12499 install_element(BGP_IPV4_NODE,
12500 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12501 install_element(BGP_IPV4_NODE,
12502 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12503 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12504 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12505 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12506 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12507 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12508 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12509
12510 /* ttl_security commands */
12511 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12512 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12513
12514 /* "show [ip] bgp memory" commands. */
12515 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12516
acf71666
MK
12517 /* "show bgp martian next-hop" */
12518 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12519
d62a17ae 12520 /* "show [ip] bgp views" commands. */
12521 install_element(VIEW_NODE, &show_bgp_views_cmd);
12522
12523 /* "show [ip] bgp vrfs" commands. */
12524 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12525
12526 /* Community-list. */
12527 community_list_vty();
718e3744 12528}
6b0655a2 12529
718e3744 12530#include "memory.h"
12531#include "bgp_regex.h"
12532#include "bgp_clist.h"
12533#include "bgp_ecommunity.h"
12534
12535/* VTY functions. */
12536
12537/* Direction value to string conversion. */
d62a17ae 12538static const char *community_direct_str(int direct)
12539{
12540 switch (direct) {
12541 case COMMUNITY_DENY:
12542 return "deny";
12543 case COMMUNITY_PERMIT:
12544 return "permit";
12545 default:
12546 return "unknown";
12547 }
718e3744 12548}
12549
12550/* Display error string. */
d62a17ae 12551static void community_list_perror(struct vty *vty, int ret)
12552{
12553 switch (ret) {
12554 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12555 vty_out(vty, "%% Can't find community-list\n");
12556 break;
12557 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12558 vty_out(vty, "%% Malformed community-list value\n");
12559 break;
12560 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12561 vty_out(vty,
12562 "%% Community name conflict, previously defined as standard community\n");
12563 break;
12564 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12565 vty_out(vty,
12566 "%% Community name conflict, previously defined as expanded community\n");
12567 break;
12568 }
718e3744 12569}
12570
5bf15956
DW
12571/* "community-list" keyword help string. */
12572#define COMMUNITY_LIST_STR "Add a community list entry\n"
12573
5bf15956 12574/* ip community-list standard */
718e3744 12575DEFUN (ip_community_list_standard,
12576 ip_community_list_standard_cmd,
e961923c 12577 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12578 IP_STR
12579 COMMUNITY_LIST_STR
12580 "Community list number (standard)\n"
5bf15956 12581 "Add an standard community-list entry\n"
718e3744 12582 "Community list name\n"
12583 "Specify community to reject\n"
12584 "Specify community to accept\n"
12585 COMMUNITY_VAL_STR)
12586{
d62a17ae 12587 char *cl_name_or_number = NULL;
12588 int direct = 0;
12589 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12590
d62a17ae 12591 int idx = 0;
12592 argv_find(argv, argc, "(1-99)", &idx);
12593 argv_find(argv, argc, "WORD", &idx);
12594 cl_name_or_number = argv[idx]->arg;
12595 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12596 : COMMUNITY_DENY;
12597 argv_find(argv, argc, "AA:NN", &idx);
12598 char *str = argv_concat(argv, argc, idx);
42f914d4 12599
d62a17ae 12600 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12601 style);
42f914d4 12602
d62a17ae 12603 XFREE(MTYPE_TMP, str);
42f914d4 12604
d62a17ae 12605 if (ret < 0) {
12606 /* Display error string. */
12607 community_list_perror(vty, ret);
12608 return CMD_WARNING_CONFIG_FAILED;
12609 }
42f914d4 12610
d62a17ae 12611 return CMD_SUCCESS;
718e3744 12612}
12613
fee6e4e4 12614DEFUN (no_ip_community_list_standard_all,
12615 no_ip_community_list_standard_all_cmd,
e961923c 12616 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12617 NO_STR
12618 IP_STR
12619 COMMUNITY_LIST_STR
12620 "Community list number (standard)\n"
5bf15956
DW
12621 "Add an standard community-list entry\n"
12622 "Community list name\n"
718e3744 12623 "Specify community to reject\n"
12624 "Specify community to accept\n"
12625 COMMUNITY_VAL_STR)
12626{
d62a17ae 12627 int delete_all = 0;
42f914d4 12628
d62a17ae 12629 char *cl_name_or_number = NULL;
12630 int direct = 0;
12631 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12632
d62a17ae 12633 int idx = 0;
12634 argv_find(argv, argc, "(1-99)", &idx);
12635 argv_find(argv, argc, "WORD", &idx);
12636 cl_name_or_number = argv[idx]->arg;
12637 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12638 : COMMUNITY_DENY;
12639 argv_find(argv, argc, "AA:NN", &idx);
12640 char *str = argv_concat(argv, argc, idx);
42f914d4 12641
d62a17ae 12642 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12643 direct, style, delete_all);
42f914d4 12644
d62a17ae 12645 XFREE(MTYPE_TMP, str);
daf9ddbb 12646
d62a17ae 12647 if (ret < 0) {
12648 community_list_perror(vty, ret);
12649 return CMD_WARNING_CONFIG_FAILED;
12650 }
42f914d4 12651
d62a17ae 12652 return CMD_SUCCESS;
718e3744 12653}
12654
5bf15956
DW
12655/* ip community-list expanded */
12656DEFUN (ip_community_list_expanded_all,
12657 ip_community_list_expanded_all_cmd,
42f914d4 12658 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12659 IP_STR
12660 COMMUNITY_LIST_STR
12661 "Community list number (expanded)\n"
5bf15956 12662 "Add an expanded community-list entry\n"
718e3744 12663 "Community list name\n"
12664 "Specify community to reject\n"
12665 "Specify community to accept\n"
12666 COMMUNITY_VAL_STR)
12667{
d62a17ae 12668 char *cl_name_or_number = NULL;
12669 int direct = 0;
12670 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12671
d62a17ae 12672 int idx = 0;
12673 argv_find(argv, argc, "(100-500)", &idx);
12674 argv_find(argv, argc, "WORD", &idx);
12675 cl_name_or_number = argv[idx]->arg;
12676 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12677 : COMMUNITY_DENY;
12678 argv_find(argv, argc, "AA:NN", &idx);
12679 char *str = argv_concat(argv, argc, idx);
42f914d4 12680
d62a17ae 12681 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12682 style);
42f914d4 12683
d62a17ae 12684 XFREE(MTYPE_TMP, str);
42f914d4 12685
d62a17ae 12686 if (ret < 0) {
12687 /* Display error string. */
12688 community_list_perror(vty, ret);
12689 return CMD_WARNING_CONFIG_FAILED;
12690 }
42f914d4 12691
d62a17ae 12692 return CMD_SUCCESS;
718e3744 12693}
12694
5bf15956
DW
12695DEFUN (no_ip_community_list_expanded_all,
12696 no_ip_community_list_expanded_all_cmd,
42f914d4 12697 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12698 NO_STR
12699 IP_STR
12700 COMMUNITY_LIST_STR
5bf15956
DW
12701 "Community list number (expanded)\n"
12702 "Add an expanded community-list entry\n"
718e3744 12703 "Community list name\n"
12704 "Specify community to reject\n"
12705 "Specify community to accept\n"
5bf15956 12706 COMMUNITY_VAL_STR)
718e3744 12707{
d62a17ae 12708 int delete_all = 0;
42f914d4 12709
d62a17ae 12710 char *cl_name_or_number = NULL;
12711 int direct = 0;
12712 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12713
d62a17ae 12714 int idx = 0;
12715 argv_find(argv, argc, "(100-500)", &idx);
12716 argv_find(argv, argc, "WORD", &idx);
12717 cl_name_or_number = argv[idx]->arg;
12718 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12719 : COMMUNITY_DENY;
12720 argv_find(argv, argc, "AA:NN", &idx);
12721 char *str = argv_concat(argv, argc, idx);
42f914d4 12722
d62a17ae 12723 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12724 direct, style, delete_all);
42f914d4 12725
d62a17ae 12726 XFREE(MTYPE_TMP, str);
daf9ddbb 12727
d62a17ae 12728 if (ret < 0) {
12729 community_list_perror(vty, ret);
12730 return CMD_WARNING_CONFIG_FAILED;
12731 }
42f914d4 12732
d62a17ae 12733 return CMD_SUCCESS;
718e3744 12734}
12735
d62a17ae 12736static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 12737{
d62a17ae 12738 struct community_entry *entry;
718e3744 12739
d62a17ae 12740 for (entry = list->head; entry; entry = entry->next) {
12741 if (entry == list->head) {
12742 if (all_digit(list->name))
12743 vty_out(vty, "Community %s list %s\n",
12744 entry->style == COMMUNITY_LIST_STANDARD
12745 ? "standard"
12746 : "(expanded) access",
12747 list->name);
12748 else
12749 vty_out(vty, "Named Community %s list %s\n",
12750 entry->style == COMMUNITY_LIST_STANDARD
12751 ? "standard"
12752 : "expanded",
12753 list->name);
12754 }
12755 if (entry->any)
12756 vty_out(vty, " %s\n",
12757 community_direct_str(entry->direct));
12758 else
12759 vty_out(vty, " %s %s\n",
12760 community_direct_str(entry->direct),
12761 entry->style == COMMUNITY_LIST_STANDARD
a69ea8ae 12762 ? community_str(entry->u.com, false)
d62a17ae 12763 : entry->config);
12764 }
718e3744 12765}
12766
12767DEFUN (show_ip_community_list,
12768 show_ip_community_list_cmd,
12769 "show ip community-list",
12770 SHOW_STR
12771 IP_STR
12772 "List community-list\n")
12773{
d62a17ae 12774 struct community_list *list;
12775 struct community_list_master *cm;
718e3744 12776
d62a17ae 12777 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
12778 if (!cm)
12779 return CMD_SUCCESS;
718e3744 12780
d62a17ae 12781 for (list = cm->num.head; list; list = list->next)
12782 community_list_show(vty, list);
718e3744 12783
d62a17ae 12784 for (list = cm->str.head; list; list = list->next)
12785 community_list_show(vty, list);
718e3744 12786
d62a17ae 12787 return CMD_SUCCESS;
718e3744 12788}
12789
12790DEFUN (show_ip_community_list_arg,
12791 show_ip_community_list_arg_cmd,
6147e2c6 12792 "show ip community-list <(1-500)|WORD>",
718e3744 12793 SHOW_STR
12794 IP_STR
12795 "List community-list\n"
12796 "Community-list number\n"
12797 "Community-list name\n")
12798{
d62a17ae 12799 int idx_comm_list = 3;
12800 struct community_list *list;
718e3744 12801
d62a17ae 12802 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
12803 COMMUNITY_LIST_MASTER);
12804 if (!list) {
12805 vty_out(vty, "%% Can't find community-list\n");
12806 return CMD_WARNING;
12807 }
718e3744 12808
d62a17ae 12809 community_list_show(vty, list);
718e3744 12810
d62a17ae 12811 return CMD_SUCCESS;
718e3744 12812}
6b0655a2 12813
57d187bc
JS
12814/*
12815 * Large Community code.
12816 */
d62a17ae 12817static int lcommunity_list_set_vty(struct vty *vty, int argc,
12818 struct cmd_token **argv, int style,
12819 int reject_all_digit_name)
12820{
12821 int ret;
12822 int direct;
12823 char *str;
12824 int idx = 0;
12825 char *cl_name;
12826
12827 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12828 : COMMUNITY_DENY;
12829
12830 /* All digit name check. */
12831 idx = 0;
12832 argv_find(argv, argc, "WORD", &idx);
12833 argv_find(argv, argc, "(1-99)", &idx);
12834 argv_find(argv, argc, "(100-500)", &idx);
12835 cl_name = argv[idx]->arg;
12836 if (reject_all_digit_name && all_digit(cl_name)) {
12837 vty_out(vty, "%% Community name cannot have all digits\n");
12838 return CMD_WARNING_CONFIG_FAILED;
12839 }
12840
12841 idx = 0;
12842 argv_find(argv, argc, "AA:BB:CC", &idx);
12843 argv_find(argv, argc, "LINE", &idx);
12844 /* Concat community string argument. */
12845 if (idx)
12846 str = argv_concat(argv, argc, idx);
12847 else
12848 str = NULL;
12849
12850 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
12851
12852 /* Free temporary community list string allocated by
12853 argv_concat(). */
12854 if (str)
12855 XFREE(MTYPE_TMP, str);
12856
12857 if (ret < 0) {
12858 community_list_perror(vty, ret);
12859 return CMD_WARNING_CONFIG_FAILED;
12860 }
12861 return CMD_SUCCESS;
12862}
12863
12864static int lcommunity_list_unset_vty(struct vty *vty, int argc,
12865 struct cmd_token **argv, int style)
12866{
12867 int ret;
12868 int direct = 0;
12869 char *str = NULL;
12870 int idx = 0;
12871
12872 argv_find(argv, argc, "permit", &idx);
12873 argv_find(argv, argc, "deny", &idx);
12874
12875 if (idx) {
12876 /* Check the list direct. */
12877 if (strncmp(argv[idx]->arg, "p", 1) == 0)
12878 direct = COMMUNITY_PERMIT;
12879 else
12880 direct = COMMUNITY_DENY;
12881
12882 idx = 0;
12883 argv_find(argv, argc, "LINE", &idx);
12884 argv_find(argv, argc, "AA:AA:NN", &idx);
12885 /* Concat community string argument. */
12886 str = argv_concat(argv, argc, idx);
12887 }
12888
12889 idx = 0;
12890 argv_find(argv, argc, "(1-99)", &idx);
12891 argv_find(argv, argc, "(100-500)", &idx);
12892 argv_find(argv, argc, "WORD", &idx);
12893
12894 /* Unset community list. */
12895 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
12896 style);
12897
12898 /* Free temporary community list string allocated by
12899 argv_concat(). */
12900 if (str)
12901 XFREE(MTYPE_TMP, str);
12902
12903 if (ret < 0) {
12904 community_list_perror(vty, ret);
12905 return CMD_WARNING_CONFIG_FAILED;
12906 }
12907
12908 return CMD_SUCCESS;
57d187bc
JS
12909}
12910
12911/* "large-community-list" keyword help string. */
12912#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12913#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12914
12915DEFUN (ip_lcommunity_list_standard,
12916 ip_lcommunity_list_standard_cmd,
52951b63
DS
12917 "ip large-community-list (1-99) <deny|permit>",
12918 IP_STR
12919 LCOMMUNITY_LIST_STR
12920 "Large Community list number (standard)\n"
12921 "Specify large community to reject\n"
7111c1a0 12922 "Specify large community to accept\n")
52951b63 12923{
d62a17ae 12924 return lcommunity_list_set_vty(vty, argc, argv,
12925 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
12926}
12927
12928DEFUN (ip_lcommunity_list_standard1,
12929 ip_lcommunity_list_standard1_cmd,
12930 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
12931 IP_STR
12932 LCOMMUNITY_LIST_STR
12933 "Large Community list number (standard)\n"
12934 "Specify large community to reject\n"
12935 "Specify large community to accept\n"
12936 LCOMMUNITY_VAL_STR)
12937{
d62a17ae 12938 return lcommunity_list_set_vty(vty, argc, argv,
12939 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
12940}
12941
12942DEFUN (ip_lcommunity_list_expanded,
12943 ip_lcommunity_list_expanded_cmd,
12944 "ip large-community-list (100-500) <deny|permit> LINE...",
12945 IP_STR
12946 LCOMMUNITY_LIST_STR
12947 "Large Community list number (expanded)\n"
12948 "Specify large community to reject\n"
12949 "Specify large community to accept\n"
12950 "An ordered list as a regular-expression\n")
12951{
d62a17ae 12952 return lcommunity_list_set_vty(vty, argc, argv,
12953 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
12954}
12955
12956DEFUN (ip_lcommunity_list_name_standard,
12957 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
12958 "ip large-community-list standard WORD <deny|permit>",
12959 IP_STR
12960 LCOMMUNITY_LIST_STR
12961 "Specify standard large-community-list\n"
12962 "Large Community list name\n"
12963 "Specify large community to reject\n"
12964 "Specify large community to accept\n")
12965{
d62a17ae 12966 return lcommunity_list_set_vty(vty, argc, argv,
12967 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
12968}
12969
12970DEFUN (ip_lcommunity_list_name_standard1,
12971 ip_lcommunity_list_name_standard1_cmd,
12972 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
12973 IP_STR
12974 LCOMMUNITY_LIST_STR
12975 "Specify standard large-community-list\n"
12976 "Large Community list name\n"
12977 "Specify large community to reject\n"
12978 "Specify large community to accept\n"
12979 LCOMMUNITY_VAL_STR)
12980{
d62a17ae 12981 return lcommunity_list_set_vty(vty, argc, argv,
12982 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
12983}
12984
12985DEFUN (ip_lcommunity_list_name_expanded,
12986 ip_lcommunity_list_name_expanded_cmd,
12987 "ip large-community-list expanded WORD <deny|permit> LINE...",
12988 IP_STR
12989 LCOMMUNITY_LIST_STR
12990 "Specify expanded large-community-list\n"
12991 "Large Community list name\n"
12992 "Specify large community to reject\n"
12993 "Specify large community to accept\n"
12994 "An ordered list as a regular-expression\n")
12995{
d62a17ae 12996 return lcommunity_list_set_vty(vty, argc, argv,
12997 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
12998}
12999
13000DEFUN (no_ip_lcommunity_list_standard_all,
13001 no_ip_lcommunity_list_standard_all_cmd,
13002 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13003 NO_STR
13004 IP_STR
13005 LCOMMUNITY_LIST_STR
13006 "Large Community list number (standard)\n"
13007 "Large Community list number (expanded)\n"
13008 "Large Community list name\n")
13009{
d62a17ae 13010 return lcommunity_list_unset_vty(vty, argc, argv,
13011 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13012}
13013
13014DEFUN (no_ip_lcommunity_list_name_expanded_all,
13015 no_ip_lcommunity_list_name_expanded_all_cmd,
13016 "no ip large-community-list expanded WORD",
13017 NO_STR
13018 IP_STR
13019 LCOMMUNITY_LIST_STR
13020 "Specify expanded large-community-list\n"
13021 "Large Community list name\n")
13022{
d62a17ae 13023 return lcommunity_list_unset_vty(vty, argc, argv,
13024 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13025}
13026
13027DEFUN (no_ip_lcommunity_list_standard,
13028 no_ip_lcommunity_list_standard_cmd,
13029 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13030 NO_STR
13031 IP_STR
13032 LCOMMUNITY_LIST_STR
13033 "Large Community list number (standard)\n"
13034 "Specify large community to reject\n"
13035 "Specify large community to accept\n"
13036 LCOMMUNITY_VAL_STR)
13037{
d62a17ae 13038 return lcommunity_list_unset_vty(vty, argc, argv,
13039 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13040}
13041
13042DEFUN (no_ip_lcommunity_list_expanded,
13043 no_ip_lcommunity_list_expanded_cmd,
13044 "no ip large-community-list (100-500) <deny|permit> LINE...",
13045 NO_STR
13046 IP_STR
13047 LCOMMUNITY_LIST_STR
13048 "Large Community list number (expanded)\n"
13049 "Specify large community to reject\n"
13050 "Specify large community to accept\n"
13051 "An ordered list as a regular-expression\n")
13052{
d62a17ae 13053 return lcommunity_list_unset_vty(vty, argc, argv,
13054 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13055}
13056
13057DEFUN (no_ip_lcommunity_list_name_standard,
13058 no_ip_lcommunity_list_name_standard_cmd,
13059 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13060 NO_STR
13061 IP_STR
13062 LCOMMUNITY_LIST_STR
13063 "Specify standard large-community-list\n"
13064 "Large Community list name\n"
13065 "Specify large community to reject\n"
13066 "Specify large community to accept\n"
13067 LCOMMUNITY_VAL_STR)
13068{
d62a17ae 13069 return lcommunity_list_unset_vty(vty, argc, argv,
13070 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13071}
13072
13073DEFUN (no_ip_lcommunity_list_name_expanded,
13074 no_ip_lcommunity_list_name_expanded_cmd,
13075 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13076 NO_STR
13077 IP_STR
13078 LCOMMUNITY_LIST_STR
13079 "Specify expanded large-community-list\n"
13080 "Large community list name\n"
13081 "Specify large community to reject\n"
13082 "Specify large community to accept\n"
13083 "An ordered list as a regular-expression\n")
13084{
d62a17ae 13085 return lcommunity_list_unset_vty(vty, argc, argv,
13086 LARGE_COMMUNITY_LIST_EXPANDED);
13087}
13088
13089static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13090{
13091 struct community_entry *entry;
13092
13093 for (entry = list->head; entry; entry = entry->next) {
13094 if (entry == list->head) {
13095 if (all_digit(list->name))
13096 vty_out(vty, "Large community %s list %s\n",
13097 entry->style == EXTCOMMUNITY_LIST_STANDARD
13098 ? "standard"
13099 : "(expanded) access",
13100 list->name);
13101 else
13102 vty_out(vty,
13103 "Named large community %s list %s\n",
13104 entry->style == EXTCOMMUNITY_LIST_STANDARD
13105 ? "standard"
13106 : "expanded",
13107 list->name);
13108 }
13109 if (entry->any)
13110 vty_out(vty, " %s\n",
13111 community_direct_str(entry->direct));
13112 else
13113 vty_out(vty, " %s %s\n",
13114 community_direct_str(entry->direct),
13115 entry->style == EXTCOMMUNITY_LIST_STANDARD
13116 ? entry->u.ecom->str
13117 : entry->config);
13118 }
57d187bc
JS
13119}
13120
13121DEFUN (show_ip_lcommunity_list,
13122 show_ip_lcommunity_list_cmd,
13123 "show ip large-community-list",
13124 SHOW_STR
13125 IP_STR
13126 "List large-community list\n")
13127{
d62a17ae 13128 struct community_list *list;
13129 struct community_list_master *cm;
57d187bc 13130
d62a17ae 13131 cm = community_list_master_lookup(bgp_clist,
13132 LARGE_COMMUNITY_LIST_MASTER);
13133 if (!cm)
13134 return CMD_SUCCESS;
57d187bc 13135
d62a17ae 13136 for (list = cm->num.head; list; list = list->next)
13137 lcommunity_list_show(vty, list);
57d187bc 13138
d62a17ae 13139 for (list = cm->str.head; list; list = list->next)
13140 lcommunity_list_show(vty, list);
57d187bc 13141
d62a17ae 13142 return CMD_SUCCESS;
57d187bc
JS
13143}
13144
13145DEFUN (show_ip_lcommunity_list_arg,
13146 show_ip_lcommunity_list_arg_cmd,
13147 "show ip large-community-list <(1-500)|WORD>",
13148 SHOW_STR
13149 IP_STR
13150 "List large-community list\n"
13151 "large-community-list number\n"
13152 "large-community-list name\n")
13153{
d62a17ae 13154 struct community_list *list;
57d187bc 13155
d62a17ae 13156 list = community_list_lookup(bgp_clist, argv[3]->arg,
13157 LARGE_COMMUNITY_LIST_MASTER);
13158 if (!list) {
13159 vty_out(vty, "%% Can't find extcommunity-list\n");
13160 return CMD_WARNING;
13161 }
57d187bc 13162
d62a17ae 13163 lcommunity_list_show(vty, list);
57d187bc 13164
d62a17ae 13165 return CMD_SUCCESS;
57d187bc
JS
13166}
13167
718e3744 13168/* "extcommunity-list" keyword help string. */
13169#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13170#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13171
13172DEFUN (ip_extcommunity_list_standard,
13173 ip_extcommunity_list_standard_cmd,
e961923c 13174 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13175 IP_STR
13176 EXTCOMMUNITY_LIST_STR
13177 "Extended Community list number (standard)\n"
718e3744 13178 "Specify standard extcommunity-list\n"
5bf15956 13179 "Community list name\n"
718e3744 13180 "Specify community to reject\n"
13181 "Specify community to accept\n"
13182 EXTCOMMUNITY_VAL_STR)
13183{
d62a17ae 13184 int style = EXTCOMMUNITY_LIST_STANDARD;
13185 int direct = 0;
13186 char *cl_number_or_name = NULL;
42f914d4 13187
d62a17ae 13188 int idx = 0;
13189 argv_find(argv, argc, "(1-99)", &idx);
13190 argv_find(argv, argc, "WORD", &idx);
13191 cl_number_or_name = argv[idx]->arg;
13192 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13193 : COMMUNITY_DENY;
13194 argv_find(argv, argc, "AA:NN", &idx);
13195 char *str = argv_concat(argv, argc, idx);
42f914d4 13196
d62a17ae 13197 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13198 direct, style);
42f914d4 13199
d62a17ae 13200 XFREE(MTYPE_TMP, str);
42f914d4 13201
d62a17ae 13202 if (ret < 0) {
13203 community_list_perror(vty, ret);
13204 return CMD_WARNING_CONFIG_FAILED;
13205 }
42f914d4 13206
d62a17ae 13207 return CMD_SUCCESS;
718e3744 13208}
13209
718e3744 13210DEFUN (ip_extcommunity_list_name_expanded,
13211 ip_extcommunity_list_name_expanded_cmd,
e961923c 13212 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13213 IP_STR
13214 EXTCOMMUNITY_LIST_STR
5bf15956 13215 "Extended Community list number (expanded)\n"
718e3744 13216 "Specify expanded extcommunity-list\n"
13217 "Extended Community list name\n"
13218 "Specify community to reject\n"
13219 "Specify community to accept\n"
13220 "An ordered list as a regular-expression\n")
13221{
d62a17ae 13222 int style = EXTCOMMUNITY_LIST_EXPANDED;
13223 int direct = 0;
13224 char *cl_number_or_name = NULL;
42f914d4 13225
d62a17ae 13226 int idx = 0;
13227 argv_find(argv, argc, "(100-500)", &idx);
13228 argv_find(argv, argc, "WORD", &idx);
13229 cl_number_or_name = argv[idx]->arg;
13230 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13231 : COMMUNITY_DENY;
13232 argv_find(argv, argc, "LINE", &idx);
13233 char *str = argv_concat(argv, argc, idx);
42f914d4 13234
d62a17ae 13235 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13236 direct, style);
42f914d4 13237
d62a17ae 13238 XFREE(MTYPE_TMP, str);
42f914d4 13239
d62a17ae 13240 if (ret < 0) {
13241 community_list_perror(vty, ret);
13242 return CMD_WARNING_CONFIG_FAILED;
13243 }
42f914d4 13244
d62a17ae 13245 return CMD_SUCCESS;
718e3744 13246}
13247
fee6e4e4 13248DEFUN (no_ip_extcommunity_list_standard_all,
13249 no_ip_extcommunity_list_standard_all_cmd,
e961923c 13250 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
13251 NO_STR
13252 IP_STR
13253 EXTCOMMUNITY_LIST_STR
13254 "Extended Community list number (standard)\n"
718e3744 13255 "Specify standard extcommunity-list\n"
5bf15956 13256 "Community list name\n"
718e3744 13257 "Specify community to reject\n"
13258 "Specify community to accept\n"
13259 EXTCOMMUNITY_VAL_STR)
13260{
d62a17ae 13261 int deleteall = 0;
42f914d4 13262
d62a17ae 13263 int style = EXTCOMMUNITY_LIST_STANDARD;
13264 int direct = 0;
13265 char *cl_number_or_name = NULL;
42f914d4 13266
d62a17ae 13267 int idx = 0;
13268 argv_find(argv, argc, "(1-99)", &idx);
13269 argv_find(argv, argc, "WORD", &idx);
13270 cl_number_or_name = argv[idx]->arg;
13271 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13272 : COMMUNITY_DENY;
13273 argv_find(argv, argc, "AA:NN", &idx);
13274 char *str = argv_concat(argv, argc, idx);
42f914d4 13275
d62a17ae 13276 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13277 direct, style, deleteall);
42f914d4 13278
d62a17ae 13279 XFREE(MTYPE_TMP, str);
42f914d4 13280
d62a17ae 13281 if (ret < 0) {
13282 community_list_perror(vty, ret);
13283 return CMD_WARNING_CONFIG_FAILED;
13284 }
42f914d4 13285
d62a17ae 13286 return CMD_SUCCESS;
718e3744 13287}
13288
5bf15956
DW
13289DEFUN (no_ip_extcommunity_list_expanded_all,
13290 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 13291 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13292 NO_STR
13293 IP_STR
13294 EXTCOMMUNITY_LIST_STR
13295 "Extended Community list number (expanded)\n"
718e3744 13296 "Specify expanded extcommunity-list\n"
5bf15956 13297 "Extended Community list name\n"
718e3744 13298 "Specify community to reject\n"
13299 "Specify community to accept\n"
13300 "An ordered list as a regular-expression\n")
13301{
d62a17ae 13302 int deleteall = 0;
42f914d4 13303
d62a17ae 13304 int style = EXTCOMMUNITY_LIST_EXPANDED;
13305 int direct = 0;
13306 char *cl_number_or_name = NULL;
42f914d4 13307
d62a17ae 13308 int idx = 0;
13309 argv_find(argv, argc, "(100-500)", &idx);
13310 argv_find(argv, argc, "WORD", &idx);
13311 cl_number_or_name = argv[idx]->arg;
13312 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13313 : COMMUNITY_DENY;
13314 argv_find(argv, argc, "LINE", &idx);
13315 char *str = argv_concat(argv, argc, idx);
42f914d4 13316
d62a17ae 13317 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13318 direct, style, deleteall);
42f914d4 13319
d62a17ae 13320 XFREE(MTYPE_TMP, str);
42f914d4 13321
d62a17ae 13322 if (ret < 0) {
13323 community_list_perror(vty, ret);
13324 return CMD_WARNING_CONFIG_FAILED;
13325 }
42f914d4 13326
d62a17ae 13327 return CMD_SUCCESS;
718e3744 13328}
13329
d62a17ae 13330static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 13331{
d62a17ae 13332 struct community_entry *entry;
718e3744 13333
d62a17ae 13334 for (entry = list->head; entry; entry = entry->next) {
13335 if (entry == list->head) {
13336 if (all_digit(list->name))
13337 vty_out(vty, "Extended community %s list %s\n",
13338 entry->style == EXTCOMMUNITY_LIST_STANDARD
13339 ? "standard"
13340 : "(expanded) access",
13341 list->name);
13342 else
13343 vty_out(vty,
13344 "Named extended community %s list %s\n",
13345 entry->style == EXTCOMMUNITY_LIST_STANDARD
13346 ? "standard"
13347 : "expanded",
13348 list->name);
13349 }
13350 if (entry->any)
13351 vty_out(vty, " %s\n",
13352 community_direct_str(entry->direct));
13353 else
13354 vty_out(vty, " %s %s\n",
13355 community_direct_str(entry->direct),
13356 entry->style == EXTCOMMUNITY_LIST_STANDARD
13357 ? entry->u.ecom->str
13358 : entry->config);
13359 }
718e3744 13360}
13361
13362DEFUN (show_ip_extcommunity_list,
13363 show_ip_extcommunity_list_cmd,
13364 "show ip extcommunity-list",
13365 SHOW_STR
13366 IP_STR
13367 "List extended-community list\n")
13368{
d62a17ae 13369 struct community_list *list;
13370 struct community_list_master *cm;
718e3744 13371
d62a17ae 13372 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13373 if (!cm)
13374 return CMD_SUCCESS;
718e3744 13375
d62a17ae 13376 for (list = cm->num.head; list; list = list->next)
13377 extcommunity_list_show(vty, list);
718e3744 13378
d62a17ae 13379 for (list = cm->str.head; list; list = list->next)
13380 extcommunity_list_show(vty, list);
718e3744 13381
d62a17ae 13382 return CMD_SUCCESS;
718e3744 13383}
13384
13385DEFUN (show_ip_extcommunity_list_arg,
13386 show_ip_extcommunity_list_arg_cmd,
6147e2c6 13387 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 13388 SHOW_STR
13389 IP_STR
13390 "List extended-community list\n"
13391 "Extcommunity-list number\n"
13392 "Extcommunity-list name\n")
13393{
d62a17ae 13394 int idx_comm_list = 3;
13395 struct community_list *list;
718e3744 13396
d62a17ae 13397 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13398 EXTCOMMUNITY_LIST_MASTER);
13399 if (!list) {
13400 vty_out(vty, "%% Can't find extcommunity-list\n");
13401 return CMD_WARNING;
13402 }
718e3744 13403
d62a17ae 13404 extcommunity_list_show(vty, list);
718e3744 13405
d62a17ae 13406 return CMD_SUCCESS;
718e3744 13407}
6b0655a2 13408
718e3744 13409/* Return configuration string of community-list entry. */
d62a17ae 13410static const char *community_list_config_str(struct community_entry *entry)
718e3744 13411{
d62a17ae 13412 const char *str;
718e3744 13413
d62a17ae 13414 if (entry->any)
13415 str = "";
13416 else {
13417 if (entry->style == COMMUNITY_LIST_STANDARD)
a69ea8ae 13418 str = community_str(entry->u.com, false);
d62a17ae 13419 else
13420 str = entry->config;
13421 }
13422 return str;
718e3744 13423}
13424
13425/* Display community-list and extcommunity-list configuration. */
d62a17ae 13426static int community_list_config_write(struct vty *vty)
13427{
13428 struct community_list *list;
13429 struct community_entry *entry;
13430 struct community_list_master *cm;
13431 int write = 0;
13432
13433 /* Community-list. */
13434 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13435
13436 for (list = cm->num.head; list; list = list->next)
13437 for (entry = list->head; entry; entry = entry->next) {
13438 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13439 community_direct_str(entry->direct),
13440 community_list_config_str(entry));
13441 write++;
13442 }
13443 for (list = cm->str.head; list; list = list->next)
13444 for (entry = list->head; entry; entry = entry->next) {
13445 vty_out(vty, "ip community-list %s %s %s %s\n",
13446 entry->style == COMMUNITY_LIST_STANDARD
13447 ? "standard"
13448 : "expanded",
13449 list->name, community_direct_str(entry->direct),
13450 community_list_config_str(entry));
13451 write++;
13452 }
13453
13454 /* Extcommunity-list. */
13455 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13456
13457 for (list = cm->num.head; list; list = list->next)
13458 for (entry = list->head; entry; entry = entry->next) {
13459 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13460 list->name, community_direct_str(entry->direct),
13461 community_list_config_str(entry));
13462 write++;
13463 }
13464 for (list = cm->str.head; list; list = list->next)
13465 for (entry = list->head; entry; entry = entry->next) {
13466 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13467 entry->style == EXTCOMMUNITY_LIST_STANDARD
13468 ? "standard"
13469 : "expanded",
13470 list->name, community_direct_str(entry->direct),
13471 community_list_config_str(entry));
13472 write++;
13473 }
13474
13475
13476 /* lcommunity-list. */
13477 cm = community_list_master_lookup(bgp_clist,
13478 LARGE_COMMUNITY_LIST_MASTER);
13479
13480 for (list = cm->num.head; list; list = list->next)
13481 for (entry = list->head; entry; entry = entry->next) {
13482 vty_out(vty, "ip large-community-list %s %s %s\n",
13483 list->name, community_direct_str(entry->direct),
13484 community_list_config_str(entry));
13485 write++;
13486 }
13487 for (list = cm->str.head; list; list = list->next)
13488 for (entry = list->head; entry; entry = entry->next) {
13489 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13490 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13491 ? "standard"
13492 : "expanded",
13493 list->name, community_direct_str(entry->direct),
13494 community_list_config_str(entry));
13495 write++;
13496 }
13497
13498 return write;
13499}
13500
13501static struct cmd_node community_list_node = {
13502 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 13503};
13504
d62a17ae 13505static void community_list_vty(void)
13506{
13507 install_node(&community_list_node, community_list_config_write);
13508
13509 /* Community-list. */
13510 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13511 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13512 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13513 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13514 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13515 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13516
13517 /* Extcommunity-list. */
13518 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13519 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13520 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13521 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13522 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13523 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13524
13525 /* Large Community List */
13526 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13527 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13528 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13529 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13530 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13531 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13532 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13533 install_element(CONFIG_NODE,
13534 &no_ip_lcommunity_list_name_expanded_all_cmd);
13535 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13536 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13537 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13538 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13539 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13540 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 13541}