]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #1664 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,
9d303b37 1543 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1544 "Forward packets over multiple paths\n"
1545 "Number of paths\n")
596c17ba 1546
165b5fff
JB
1547DEFUN (no_bgp_maxpaths_ibgp,
1548 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1549 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1550 NO_STR
1551 "Forward packets over multiple paths\n"
1552 "iBGP-multipath\n"
838758ac
DW
1553 "Number of paths\n"
1554 "Match the cluster length\n")
165b5fff 1555{
d62a17ae 1556 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1557}
1558
d62a17ae 1559ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1560 "no maximum-paths ibgp [" CMD_RANGE_STR(
1561 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1562 NO_STR
1563 "Forward packets over multiple paths\n"
1564 "iBGP-multipath\n"
1565 "Number of paths\n"
1566 "Match the cluster length\n")
596c17ba 1567
2b791107 1568void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1569 safi_t safi)
165b5fff 1570{
d62a17ae 1571 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1572 vty_out(vty, " maximum-paths %d\n",
1573 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1574 }
165b5fff 1575
d62a17ae 1576 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1577 vty_out(vty, " maximum-paths ibgp %d",
1578 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1579 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1580 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1581 vty_out(vty, " equal-cluster-length");
1582 vty_out(vty, "\n");
1583 }
165b5fff 1584}
6b0655a2 1585
718e3744 1586/* BGP timers. */
1587
1588DEFUN (bgp_timers,
1589 bgp_timers_cmd,
6147e2c6 1590 "timers bgp (0-65535) (0-65535)",
718e3744 1591 "Adjust routing timers\n"
1592 "BGP timers\n"
1593 "Keepalive interval\n"
1594 "Holdtime\n")
1595{
d62a17ae 1596 VTY_DECLVAR_CONTEXT(bgp, bgp);
1597 int idx_number = 2;
1598 int idx_number_2 = 3;
1599 unsigned long keepalive = 0;
1600 unsigned long holdtime = 0;
718e3744 1601
d62a17ae 1602 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1603 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1604
d62a17ae 1605 /* Holdtime value check. */
1606 if (holdtime < 3 && holdtime != 0) {
1607 vty_out(vty,
1608 "%% hold time value must be either 0 or greater than 3\n");
1609 return CMD_WARNING_CONFIG_FAILED;
1610 }
718e3744 1611
d62a17ae 1612 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1613
d62a17ae 1614 return CMD_SUCCESS;
718e3744 1615}
1616
1617DEFUN (no_bgp_timers,
1618 no_bgp_timers_cmd,
838758ac 1619 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1620 NO_STR
1621 "Adjust routing timers\n"
838758ac
DW
1622 "BGP timers\n"
1623 "Keepalive interval\n"
1624 "Holdtime\n")
718e3744 1625{
d62a17ae 1626 VTY_DECLVAR_CONTEXT(bgp, bgp);
1627 bgp_timers_unset(bgp);
718e3744 1628
d62a17ae 1629 return CMD_SUCCESS;
718e3744 1630}
1631
6b0655a2 1632
718e3744 1633DEFUN (bgp_client_to_client_reflection,
1634 bgp_client_to_client_reflection_cmd,
1635 "bgp client-to-client reflection",
1636 "BGP specific commands\n"
1637 "Configure client to client route reflection\n"
1638 "reflection of routes allowed\n")
1639{
d62a17ae 1640 VTY_DECLVAR_CONTEXT(bgp, bgp);
1641 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1642 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1643
d62a17ae 1644 return CMD_SUCCESS;
718e3744 1645}
1646
1647DEFUN (no_bgp_client_to_client_reflection,
1648 no_bgp_client_to_client_reflection_cmd,
1649 "no bgp client-to-client reflection",
1650 NO_STR
1651 "BGP specific commands\n"
1652 "Configure client to client route reflection\n"
1653 "reflection of routes allowed\n")
1654{
d62a17ae 1655 VTY_DECLVAR_CONTEXT(bgp, bgp);
1656 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1657 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1658
d62a17ae 1659 return CMD_SUCCESS;
718e3744 1660}
1661
1662/* "bgp always-compare-med" configuration. */
1663DEFUN (bgp_always_compare_med,
1664 bgp_always_compare_med_cmd,
1665 "bgp always-compare-med",
1666 "BGP specific commands\n"
1667 "Allow comparing MED from different neighbors\n")
1668{
d62a17ae 1669 VTY_DECLVAR_CONTEXT(bgp, bgp);
1670 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1671 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1672
d62a17ae 1673 return CMD_SUCCESS;
718e3744 1674}
1675
1676DEFUN (no_bgp_always_compare_med,
1677 no_bgp_always_compare_med_cmd,
1678 "no bgp always-compare-med",
1679 NO_STR
1680 "BGP specific commands\n"
1681 "Allow comparing MED from different neighbors\n")
1682{
d62a17ae 1683 VTY_DECLVAR_CONTEXT(bgp, bgp);
1684 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1685 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1686
d62a17ae 1687 return CMD_SUCCESS;
718e3744 1688}
6b0655a2 1689
718e3744 1690/* "bgp deterministic-med" configuration. */
1691DEFUN (bgp_deterministic_med,
1692 bgp_deterministic_med_cmd,
1693 "bgp deterministic-med",
1694 "BGP specific commands\n"
1695 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1696{
d62a17ae 1697 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1698
d62a17ae 1699 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1700 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1701 bgp_recalculate_all_bestpaths(bgp);
1702 }
7aafcaca 1703
d62a17ae 1704 return CMD_SUCCESS;
718e3744 1705}
1706
1707DEFUN (no_bgp_deterministic_med,
1708 no_bgp_deterministic_med_cmd,
1709 "no bgp deterministic-med",
1710 NO_STR
1711 "BGP specific commands\n"
1712 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1713{
d62a17ae 1714 VTY_DECLVAR_CONTEXT(bgp, bgp);
1715 int bestpath_per_as_used;
1716 afi_t afi;
1717 safi_t safi;
1718 struct peer *peer;
1719 struct listnode *node, *nnode;
1720
1721 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1722 bestpath_per_as_used = 0;
1723
1724 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1725 FOREACH_AFI_SAFI (afi, safi)
1726 if (CHECK_FLAG(
1727 peer->af_flags[afi][safi],
1728 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1729 bestpath_per_as_used = 1;
1730 break;
1731 }
d62a17ae 1732
1733 if (bestpath_per_as_used)
1734 break;
1735 }
1736
1737 if (bestpath_per_as_used) {
1738 vty_out(vty,
1739 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1740 return CMD_WARNING_CONFIG_FAILED;
1741 } else {
1742 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1743 bgp_recalculate_all_bestpaths(bgp);
1744 }
1745 }
1746
1747 return CMD_SUCCESS;
718e3744 1748}
538621f2 1749
1750/* "bgp graceful-restart" configuration. */
1751DEFUN (bgp_graceful_restart,
1752 bgp_graceful_restart_cmd,
1753 "bgp graceful-restart",
1754 "BGP specific commands\n"
1755 "Graceful restart capability parameters\n")
1756{
d62a17ae 1757 VTY_DECLVAR_CONTEXT(bgp, bgp);
1758 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1759 return CMD_SUCCESS;
538621f2 1760}
1761
1762DEFUN (no_bgp_graceful_restart,
1763 no_bgp_graceful_restart_cmd,
1764 "no bgp graceful-restart",
1765 NO_STR
1766 "BGP specific commands\n"
1767 "Graceful restart capability parameters\n")
1768{
d62a17ae 1769 VTY_DECLVAR_CONTEXT(bgp, bgp);
1770 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1771 return CMD_SUCCESS;
538621f2 1772}
1773
93406d87 1774DEFUN (bgp_graceful_restart_stalepath_time,
1775 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1776 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1777 "BGP specific commands\n"
1778 "Graceful restart capability parameters\n"
1779 "Set the max time to hold onto restarting peer's stale paths\n"
1780 "Delay value (seconds)\n")
1781{
d62a17ae 1782 VTY_DECLVAR_CONTEXT(bgp, bgp);
1783 int idx_number = 3;
1784 u_int32_t stalepath;
93406d87 1785
d62a17ae 1786 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1787 bgp->stalepath_time = stalepath;
1788 return CMD_SUCCESS;
93406d87 1789}
1790
eb6f1b41
PG
1791DEFUN (bgp_graceful_restart_restart_time,
1792 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1793 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1794 "BGP specific commands\n"
1795 "Graceful restart capability parameters\n"
1796 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1797 "Delay value (seconds)\n")
1798{
d62a17ae 1799 VTY_DECLVAR_CONTEXT(bgp, bgp);
1800 int idx_number = 3;
1801 u_int32_t restart;
eb6f1b41 1802
d62a17ae 1803 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1804 bgp->restart_time = restart;
1805 return CMD_SUCCESS;
eb6f1b41
PG
1806}
1807
93406d87 1808DEFUN (no_bgp_graceful_restart_stalepath_time,
1809 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1810 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1811 NO_STR
1812 "BGP specific commands\n"
1813 "Graceful restart capability parameters\n"
838758ac
DW
1814 "Set the max time to hold onto restarting peer's stale paths\n"
1815 "Delay value (seconds)\n")
93406d87 1816{
d62a17ae 1817 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1818
d62a17ae 1819 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1820 return CMD_SUCCESS;
93406d87 1821}
1822
eb6f1b41
PG
1823DEFUN (no_bgp_graceful_restart_restart_time,
1824 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1825 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1826 NO_STR
1827 "BGP specific commands\n"
1828 "Graceful restart capability parameters\n"
838758ac
DW
1829 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1830 "Delay value (seconds)\n")
eb6f1b41 1831{
d62a17ae 1832 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1833
d62a17ae 1834 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1835 return CMD_SUCCESS;
eb6f1b41
PG
1836}
1837
43fc21b3
JC
1838DEFUN (bgp_graceful_restart_preserve_fw,
1839 bgp_graceful_restart_preserve_fw_cmd,
1840 "bgp graceful-restart preserve-fw-state",
1841 "BGP specific commands\n"
1842 "Graceful restart capability parameters\n"
1843 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1844{
d62a17ae 1845 VTY_DECLVAR_CONTEXT(bgp, bgp);
1846 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1847 return CMD_SUCCESS;
43fc21b3
JC
1848}
1849
1850DEFUN (no_bgp_graceful_restart_preserve_fw,
1851 no_bgp_graceful_restart_preserve_fw_cmd,
1852 "no bgp graceful-restart preserve-fw-state",
1853 NO_STR
1854 "BGP specific commands\n"
1855 "Graceful restart capability parameters\n"
1856 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1857{
d62a17ae 1858 VTY_DECLVAR_CONTEXT(bgp, bgp);
1859 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1860 return CMD_SUCCESS;
43fc21b3
JC
1861}
1862
7f323236
DW
1863static void bgp_redistribute_redo(struct bgp *bgp)
1864{
1865 afi_t afi;
1866 int i;
1867 struct list *red_list;
1868 struct listnode *node;
1869 struct bgp_redist *red;
1870
1871 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1872 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1873
1874 red_list = bgp->redist[afi][i];
1875 if (!red_list)
1876 continue;
1877
1878 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
1879 bgp_redistribute_resend(bgp, afi, i,
1880 red->instance);
1881 }
1882 }
1883 }
1884}
1885
1886/* "bgp graceful-shutdown" configuration */
1887DEFUN (bgp_graceful_shutdown,
1888 bgp_graceful_shutdown_cmd,
1889 "bgp graceful-shutdown",
1890 BGP_STR
1891 "Graceful shutdown parameters\n")
1892{
1893 VTY_DECLVAR_CONTEXT(bgp, bgp);
1894
1895 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1896 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1897 bgp_static_redo_import_check(bgp);
1898 bgp_redistribute_redo(bgp);
1899 bgp_clear_star_soft_out(vty, bgp->name);
1900 bgp_clear_star_soft_in(vty, bgp->name);
1901 }
1902
1903 return CMD_SUCCESS;
1904}
1905
1906DEFUN (no_bgp_graceful_shutdown,
1907 no_bgp_graceful_shutdown_cmd,
1908 "no bgp graceful-shutdown",
1909 NO_STR
1910 BGP_STR
1911 "Graceful shutdown parameters\n")
1912{
1913 VTY_DECLVAR_CONTEXT(bgp, bgp);
1914
1915 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1916 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1917 bgp_static_redo_import_check(bgp);
1918 bgp_redistribute_redo(bgp);
1919 bgp_clear_star_soft_out(vty, bgp->name);
1920 bgp_clear_star_soft_in(vty, bgp->name);
1921 }
1922
1923 return CMD_SUCCESS;
1924}
1925
718e3744 1926/* "bgp fast-external-failover" configuration. */
1927DEFUN (bgp_fast_external_failover,
1928 bgp_fast_external_failover_cmd,
1929 "bgp fast-external-failover",
1930 BGP_STR
1931 "Immediately reset session if a link to a directly connected external peer goes down\n")
1932{
d62a17ae 1933 VTY_DECLVAR_CONTEXT(bgp, bgp);
1934 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1935 return CMD_SUCCESS;
718e3744 1936}
1937
1938DEFUN (no_bgp_fast_external_failover,
1939 no_bgp_fast_external_failover_cmd,
1940 "no bgp fast-external-failover",
1941 NO_STR
1942 BGP_STR
1943 "Immediately reset session if a link to a directly connected external peer goes down\n")
1944{
d62a17ae 1945 VTY_DECLVAR_CONTEXT(bgp, bgp);
1946 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1947 return CMD_SUCCESS;
718e3744 1948}
6b0655a2 1949
718e3744 1950/* "bgp enforce-first-as" configuration. */
1951DEFUN (bgp_enforce_first_as,
1952 bgp_enforce_first_as_cmd,
1953 "bgp enforce-first-as",
1954 BGP_STR
1955 "Enforce the first AS for EBGP routes\n")
1956{
d62a17ae 1957 VTY_DECLVAR_CONTEXT(bgp, bgp);
1958 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1959 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1960
d62a17ae 1961 return CMD_SUCCESS;
718e3744 1962}
1963
1964DEFUN (no_bgp_enforce_first_as,
1965 no_bgp_enforce_first_as_cmd,
1966 "no bgp enforce-first-as",
1967 NO_STR
1968 BGP_STR
1969 "Enforce the first AS for EBGP routes\n")
1970{
d62a17ae 1971 VTY_DECLVAR_CONTEXT(bgp, bgp);
1972 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1973 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1974
d62a17ae 1975 return CMD_SUCCESS;
718e3744 1976}
6b0655a2 1977
718e3744 1978/* "bgp bestpath compare-routerid" configuration. */
1979DEFUN (bgp_bestpath_compare_router_id,
1980 bgp_bestpath_compare_router_id_cmd,
1981 "bgp bestpath compare-routerid",
1982 "BGP specific commands\n"
1983 "Change the default bestpath selection\n"
1984 "Compare router-id for identical EBGP paths\n")
1985{
d62a17ae 1986 VTY_DECLVAR_CONTEXT(bgp, bgp);
1987 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1988 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1989
d62a17ae 1990 return CMD_SUCCESS;
718e3744 1991}
1992
1993DEFUN (no_bgp_bestpath_compare_router_id,
1994 no_bgp_bestpath_compare_router_id_cmd,
1995 "no bgp bestpath compare-routerid",
1996 NO_STR
1997 "BGP specific commands\n"
1998 "Change the default bestpath selection\n"
1999 "Compare router-id for identical EBGP paths\n")
2000{
d62a17ae 2001 VTY_DECLVAR_CONTEXT(bgp, bgp);
2002 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2003 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2004
d62a17ae 2005 return CMD_SUCCESS;
718e3744 2006}
6b0655a2 2007
718e3744 2008/* "bgp bestpath as-path ignore" configuration. */
2009DEFUN (bgp_bestpath_aspath_ignore,
2010 bgp_bestpath_aspath_ignore_cmd,
2011 "bgp bestpath as-path ignore",
2012 "BGP specific commands\n"
2013 "Change the default bestpath selection\n"
2014 "AS-path attribute\n"
2015 "Ignore as-path length in selecting a route\n")
2016{
d62a17ae 2017 VTY_DECLVAR_CONTEXT(bgp, bgp);
2018 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2019 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2020
d62a17ae 2021 return CMD_SUCCESS;
718e3744 2022}
2023
2024DEFUN (no_bgp_bestpath_aspath_ignore,
2025 no_bgp_bestpath_aspath_ignore_cmd,
2026 "no bgp bestpath as-path ignore",
2027 NO_STR
2028 "BGP specific commands\n"
2029 "Change the default bestpath selection\n"
2030 "AS-path attribute\n"
2031 "Ignore as-path length in selecting a route\n")
2032{
d62a17ae 2033 VTY_DECLVAR_CONTEXT(bgp, bgp);
2034 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2035 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2036
d62a17ae 2037 return CMD_SUCCESS;
718e3744 2038}
6b0655a2 2039
6811845b 2040/* "bgp bestpath as-path confed" configuration. */
2041DEFUN (bgp_bestpath_aspath_confed,
2042 bgp_bestpath_aspath_confed_cmd,
2043 "bgp bestpath as-path confed",
2044 "BGP specific commands\n"
2045 "Change the default bestpath selection\n"
2046 "AS-path attribute\n"
2047 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2048{
d62a17ae 2049 VTY_DECLVAR_CONTEXT(bgp, bgp);
2050 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2051 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2052
d62a17ae 2053 return CMD_SUCCESS;
6811845b 2054}
2055
2056DEFUN (no_bgp_bestpath_aspath_confed,
2057 no_bgp_bestpath_aspath_confed_cmd,
2058 "no bgp bestpath as-path confed",
2059 NO_STR
2060 "BGP specific commands\n"
2061 "Change the default bestpath selection\n"
2062 "AS-path attribute\n"
2063 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2064{
d62a17ae 2065 VTY_DECLVAR_CONTEXT(bgp, bgp);
2066 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2067 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2068
d62a17ae 2069 return CMD_SUCCESS;
6811845b 2070}
6b0655a2 2071
2fdd455c
PM
2072/* "bgp bestpath as-path multipath-relax" configuration. */
2073DEFUN (bgp_bestpath_aspath_multipath_relax,
2074 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2075 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2076 "BGP specific commands\n"
2077 "Change the default bestpath selection\n"
2078 "AS-path attribute\n"
2079 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2080 "Generate an AS_SET\n"
16fc1eec
DS
2081 "Do not generate an AS_SET\n")
2082{
d62a17ae 2083 VTY_DECLVAR_CONTEXT(bgp, bgp);
2084 int idx = 0;
2085 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2086
d62a17ae 2087 /* no-as-set is now the default behavior so we can silently
2088 * ignore it */
2089 if (argv_find(argv, argc, "as-set", &idx))
2090 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2091 else
2092 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2093
d62a17ae 2094 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2095
d62a17ae 2096 return CMD_SUCCESS;
16fc1eec
DS
2097}
2098
219178b6
DW
2099DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2100 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2101 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2102 NO_STR
2103 "BGP specific commands\n"
2104 "Change the default bestpath selection\n"
2105 "AS-path attribute\n"
2106 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2107 "Generate an AS_SET\n"
16fc1eec
DS
2108 "Do not generate an AS_SET\n")
2109{
d62a17ae 2110 VTY_DECLVAR_CONTEXT(bgp, bgp);
2111 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2112 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2113 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2114
d62a17ae 2115 return CMD_SUCCESS;
2fdd455c 2116}
6b0655a2 2117
848973c7 2118/* "bgp log-neighbor-changes" configuration. */
2119DEFUN (bgp_log_neighbor_changes,
2120 bgp_log_neighbor_changes_cmd,
2121 "bgp log-neighbor-changes",
2122 "BGP specific commands\n"
2123 "Log neighbor up/down and reset reason\n")
2124{
d62a17ae 2125 VTY_DECLVAR_CONTEXT(bgp, bgp);
2126 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2127 return CMD_SUCCESS;
848973c7 2128}
2129
2130DEFUN (no_bgp_log_neighbor_changes,
2131 no_bgp_log_neighbor_changes_cmd,
2132 "no bgp log-neighbor-changes",
2133 NO_STR
2134 "BGP specific commands\n"
2135 "Log neighbor up/down and reset reason\n")
2136{
d62a17ae 2137 VTY_DECLVAR_CONTEXT(bgp, bgp);
2138 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2139 return CMD_SUCCESS;
848973c7 2140}
6b0655a2 2141
718e3744 2142/* "bgp bestpath med" configuration. */
2143DEFUN (bgp_bestpath_med,
2144 bgp_bestpath_med_cmd,
2d8c1a4d 2145 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2146 "BGP specific commands\n"
2147 "Change the default bestpath selection\n"
2148 "MED attribute\n"
2149 "Compare MED among confederation paths\n"
838758ac
DW
2150 "Treat missing MED as the least preferred one\n"
2151 "Treat missing MED as the least preferred one\n"
2152 "Compare MED among confederation paths\n")
718e3744 2153{
d62a17ae 2154 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2155
d62a17ae 2156 int idx = 0;
2157 if (argv_find(argv, argc, "confed", &idx))
2158 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2159 idx = 0;
2160 if (argv_find(argv, argc, "missing-as-worst", &idx))
2161 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2162
d62a17ae 2163 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2164
d62a17ae 2165 return CMD_SUCCESS;
718e3744 2166}
2167
718e3744 2168DEFUN (no_bgp_bestpath_med,
2169 no_bgp_bestpath_med_cmd,
2d8c1a4d 2170 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2171 NO_STR
2172 "BGP specific commands\n"
2173 "Change the default bestpath selection\n"
2174 "MED attribute\n"
2175 "Compare MED among confederation paths\n"
3a2d747c
QY
2176 "Treat missing MED as the least preferred one\n"
2177 "Treat missing MED as the least preferred one\n"
2178 "Compare MED among confederation paths\n")
718e3744 2179{
d62a17ae 2180 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2181
d62a17ae 2182 int idx = 0;
2183 if (argv_find(argv, argc, "confed", &idx))
2184 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2185 idx = 0;
2186 if (argv_find(argv, argc, "missing-as-worst", &idx))
2187 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2188
d62a17ae 2189 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2190
d62a17ae 2191 return CMD_SUCCESS;
718e3744 2192}
2193
718e3744 2194/* "no bgp default ipv4-unicast". */
2195DEFUN (no_bgp_default_ipv4_unicast,
2196 no_bgp_default_ipv4_unicast_cmd,
2197 "no bgp default ipv4-unicast",
2198 NO_STR
2199 "BGP specific commands\n"
2200 "Configure BGP defaults\n"
2201 "Activate ipv4-unicast for a peer by default\n")
2202{
d62a17ae 2203 VTY_DECLVAR_CONTEXT(bgp, bgp);
2204 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2205 return CMD_SUCCESS;
718e3744 2206}
2207
2208DEFUN (bgp_default_ipv4_unicast,
2209 bgp_default_ipv4_unicast_cmd,
2210 "bgp default ipv4-unicast",
2211 "BGP specific commands\n"
2212 "Configure BGP defaults\n"
2213 "Activate ipv4-unicast for a peer by default\n")
2214{
d62a17ae 2215 VTY_DECLVAR_CONTEXT(bgp, bgp);
2216 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2217 return CMD_SUCCESS;
718e3744 2218}
6b0655a2 2219
04b6bdc0
DW
2220/* Display hostname in certain command outputs */
2221DEFUN (bgp_default_show_hostname,
2222 bgp_default_show_hostname_cmd,
2223 "bgp default show-hostname",
2224 "BGP specific commands\n"
2225 "Configure BGP defaults\n"
2226 "Show hostname in certain command ouputs\n")
2227{
d62a17ae 2228 VTY_DECLVAR_CONTEXT(bgp, bgp);
2229 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2230 return CMD_SUCCESS;
04b6bdc0
DW
2231}
2232
2233DEFUN (no_bgp_default_show_hostname,
2234 no_bgp_default_show_hostname_cmd,
2235 "no bgp default show-hostname",
2236 NO_STR
2237 "BGP specific commands\n"
2238 "Configure BGP defaults\n"
2239 "Show hostname in certain command ouputs\n")
2240{
d62a17ae 2241 VTY_DECLVAR_CONTEXT(bgp, bgp);
2242 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2243 return CMD_SUCCESS;
04b6bdc0
DW
2244}
2245
8233ef81 2246/* "bgp network import-check" configuration. */
718e3744 2247DEFUN (bgp_network_import_check,
2248 bgp_network_import_check_cmd,
5623e905 2249 "bgp network import-check",
718e3744 2250 "BGP specific commands\n"
2251 "BGP network command\n"
5623e905 2252 "Check BGP network route exists in IGP\n")
718e3744 2253{
d62a17ae 2254 VTY_DECLVAR_CONTEXT(bgp, bgp);
2255 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2256 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2257 bgp_static_redo_import_check(bgp);
2258 }
078430f6 2259
d62a17ae 2260 return CMD_SUCCESS;
718e3744 2261}
2262
d62a17ae 2263ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2264 "bgp network import-check exact",
2265 "BGP specific commands\n"
2266 "BGP network command\n"
2267 "Check BGP network route exists in IGP\n"
2268 "Match route precisely\n")
8233ef81 2269
718e3744 2270DEFUN (no_bgp_network_import_check,
2271 no_bgp_network_import_check_cmd,
5623e905 2272 "no bgp network import-check",
718e3744 2273 NO_STR
2274 "BGP specific commands\n"
2275 "BGP network command\n"
2276 "Check BGP network route exists in IGP\n")
2277{
d62a17ae 2278 VTY_DECLVAR_CONTEXT(bgp, bgp);
2279 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2280 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2281 bgp_static_redo_import_check(bgp);
2282 }
5623e905 2283
d62a17ae 2284 return CMD_SUCCESS;
718e3744 2285}
6b0655a2 2286
718e3744 2287DEFUN (bgp_default_local_preference,
2288 bgp_default_local_preference_cmd,
6147e2c6 2289 "bgp default local-preference (0-4294967295)",
718e3744 2290 "BGP specific commands\n"
2291 "Configure BGP defaults\n"
2292 "local preference (higher=more preferred)\n"
2293 "Configure default local preference value\n")
2294{
d62a17ae 2295 VTY_DECLVAR_CONTEXT(bgp, bgp);
2296 int idx_number = 3;
2297 u_int32_t local_pref;
718e3744 2298
d62a17ae 2299 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2300
d62a17ae 2301 bgp_default_local_preference_set(bgp, local_pref);
2302 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2303
d62a17ae 2304 return CMD_SUCCESS;
718e3744 2305}
2306
2307DEFUN (no_bgp_default_local_preference,
2308 no_bgp_default_local_preference_cmd,
838758ac 2309 "no bgp default local-preference [(0-4294967295)]",
718e3744 2310 NO_STR
2311 "BGP specific commands\n"
2312 "Configure BGP defaults\n"
838758ac
DW
2313 "local preference (higher=more preferred)\n"
2314 "Configure default local preference value\n")
718e3744 2315{
d62a17ae 2316 VTY_DECLVAR_CONTEXT(bgp, bgp);
2317 bgp_default_local_preference_unset(bgp);
2318 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2319
d62a17ae 2320 return CMD_SUCCESS;
718e3744 2321}
2322
6b0655a2 2323
3f9c7369
DS
2324DEFUN (bgp_default_subgroup_pkt_queue_max,
2325 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2326 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2327 "BGP specific commands\n"
2328 "Configure BGP defaults\n"
2329 "subgroup-pkt-queue-max\n"
2330 "Configure subgroup packet queue max\n")
8bd9d948 2331{
d62a17ae 2332 VTY_DECLVAR_CONTEXT(bgp, bgp);
2333 int idx_number = 3;
2334 u_int32_t max_size;
8bd9d948 2335
d62a17ae 2336 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2337
d62a17ae 2338 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2339
d62a17ae 2340 return CMD_SUCCESS;
3f9c7369
DS
2341}
2342
2343DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2344 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2345 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2346 NO_STR
2347 "BGP specific commands\n"
2348 "Configure BGP defaults\n"
838758ac
DW
2349 "subgroup-pkt-queue-max\n"
2350 "Configure subgroup packet queue max\n")
3f9c7369 2351{
d62a17ae 2352 VTY_DECLVAR_CONTEXT(bgp, bgp);
2353 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2354 return CMD_SUCCESS;
8bd9d948
DS
2355}
2356
813d4307 2357
8bd9d948
DS
2358DEFUN (bgp_rr_allow_outbound_policy,
2359 bgp_rr_allow_outbound_policy_cmd,
2360 "bgp route-reflector allow-outbound-policy",
2361 "BGP specific commands\n"
2362 "Allow modifications made by out route-map\n"
2363 "on ibgp neighbors\n")
2364{
d62a17ae 2365 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2366
d62a17ae 2367 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2368 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2369 update_group_announce_rrclients(bgp);
2370 bgp_clear_star_soft_out(vty, bgp->name);
2371 }
8bd9d948 2372
d62a17ae 2373 return CMD_SUCCESS;
8bd9d948
DS
2374}
2375
2376DEFUN (no_bgp_rr_allow_outbound_policy,
2377 no_bgp_rr_allow_outbound_policy_cmd,
2378 "no bgp route-reflector allow-outbound-policy",
2379 NO_STR
2380 "BGP specific commands\n"
2381 "Allow modifications made by out route-map\n"
2382 "on ibgp neighbors\n")
2383{
d62a17ae 2384 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2385
d62a17ae 2386 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2387 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2388 update_group_announce_rrclients(bgp);
2389 bgp_clear_star_soft_out(vty, bgp->name);
2390 }
8bd9d948 2391
d62a17ae 2392 return CMD_SUCCESS;
8bd9d948
DS
2393}
2394
f14e6fdb
DS
2395DEFUN (bgp_listen_limit,
2396 bgp_listen_limit_cmd,
9ccf14f7 2397 "bgp listen limit (1-5000)",
f14e6fdb
DS
2398 "BGP specific commands\n"
2399 "Configure BGP defaults\n"
2400 "maximum number of BGP Dynamic Neighbors that can be created\n"
2401 "Configure Dynamic Neighbors listen limit value\n")
2402{
d62a17ae 2403 VTY_DECLVAR_CONTEXT(bgp, bgp);
2404 int idx_number = 3;
2405 int listen_limit;
f14e6fdb 2406
d62a17ae 2407 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2408
d62a17ae 2409 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2410
d62a17ae 2411 return CMD_SUCCESS;
f14e6fdb
DS
2412}
2413
2414DEFUN (no_bgp_listen_limit,
2415 no_bgp_listen_limit_cmd,
838758ac 2416 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2417 "BGP specific commands\n"
2418 "Configure BGP defaults\n"
2419 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2420 "Configure Dynamic Neighbors listen limit value to default\n"
2421 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2422{
d62a17ae 2423 VTY_DECLVAR_CONTEXT(bgp, bgp);
2424 bgp_listen_limit_unset(bgp);
2425 return CMD_SUCCESS;
f14e6fdb
DS
2426}
2427
2428
20eb8864 2429/*
2430 * Check if this listen range is already configured. Check for exact
2431 * match or overlap based on input.
2432 */
d62a17ae 2433static struct peer_group *listen_range_exists(struct bgp *bgp,
2434 struct prefix *range, int exact)
2435{
2436 struct listnode *node, *nnode;
2437 struct listnode *node1, *nnode1;
2438 struct peer_group *group;
2439 struct prefix *lr;
2440 afi_t afi;
2441 int match;
2442
2443 afi = family2afi(range->family);
2444 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2445 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2446 lr)) {
2447 if (exact)
2448 match = prefix_same(range, lr);
2449 else
2450 match = (prefix_match(range, lr)
2451 || prefix_match(lr, range));
2452 if (match)
2453 return group;
2454 }
2455 }
2456
2457 return NULL;
20eb8864 2458}
2459
f14e6fdb
DS
2460DEFUN (bgp_listen_range,
2461 bgp_listen_range_cmd,
9ccf14f7 2462 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2463 "BGP specific commands\n"
d7fa34c1
QY
2464 "Configure BGP dynamic neighbors listen range\n"
2465 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2466 NEIGHBOR_ADDR_STR
2467 "Member of the peer-group\n"
2468 "Peer-group name\n")
f14e6fdb 2469{
d62a17ae 2470 VTY_DECLVAR_CONTEXT(bgp, bgp);
2471 struct prefix range;
2472 struct peer_group *group, *existing_group;
2473 afi_t afi;
2474 int ret;
2475 int idx = 0;
2476
2477 argv_find(argv, argc, "A.B.C.D/M", &idx);
2478 argv_find(argv, argc, "X:X::X:X/M", &idx);
2479 char *prefix = argv[idx]->arg;
2480 argv_find(argv, argc, "WORD", &idx);
2481 char *peergroup = argv[idx]->arg;
2482
2483 /* Convert IP prefix string to struct prefix. */
2484 ret = str2prefix(prefix, &range);
2485 if (!ret) {
2486 vty_out(vty, "%% Malformed listen range\n");
2487 return CMD_WARNING_CONFIG_FAILED;
2488 }
2489
2490 afi = family2afi(range.family);
2491
2492 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2493 vty_out(vty,
2494 "%% Malformed listen range (link-local address)\n");
2495 return CMD_WARNING_CONFIG_FAILED;
2496 }
2497
2498 apply_mask(&range);
2499
2500 /* Check if same listen range is already configured. */
2501 existing_group = listen_range_exists(bgp, &range, 1);
2502 if (existing_group) {
2503 if (strcmp(existing_group->name, peergroup) == 0)
2504 return CMD_SUCCESS;
2505 else {
2506 vty_out(vty,
2507 "%% Same listen range is attached to peer-group %s\n",
2508 existing_group->name);
2509 return CMD_WARNING_CONFIG_FAILED;
2510 }
2511 }
2512
2513 /* Check if an overlapping listen range exists. */
2514 if (listen_range_exists(bgp, &range, 0)) {
2515 vty_out(vty,
2516 "%% Listen range overlaps with existing listen range\n");
2517 return CMD_WARNING_CONFIG_FAILED;
2518 }
2519
2520 group = peer_group_lookup(bgp, peergroup);
2521 if (!group) {
2522 vty_out(vty, "%% Configure the peer-group first\n");
2523 return CMD_WARNING_CONFIG_FAILED;
2524 }
2525
2526 ret = peer_group_listen_range_add(group, &range);
2527 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2528}
2529
2530DEFUN (no_bgp_listen_range,
2531 no_bgp_listen_range_cmd,
d7fa34c1
QY
2532 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2533 NO_STR
f14e6fdb 2534 "BGP specific commands\n"
d7fa34c1
QY
2535 "Unconfigure BGP dynamic neighbors listen range\n"
2536 "Unconfigure BGP dynamic neighbors listen range\n"
2537 NEIGHBOR_ADDR_STR
2538 "Member of the peer-group\n"
2539 "Peer-group name\n")
f14e6fdb 2540{
d62a17ae 2541 VTY_DECLVAR_CONTEXT(bgp, bgp);
2542 struct prefix range;
2543 struct peer_group *group;
2544 afi_t afi;
2545 int ret;
2546 int idx = 0;
2547
2548 argv_find(argv, argc, "A.B.C.D/M", &idx);
2549 argv_find(argv, argc, "X:X::X:X/M", &idx);
2550 char *prefix = argv[idx]->arg;
2551 argv_find(argv, argc, "WORD", &idx);
2552 char *peergroup = argv[idx]->arg;
2553
2554 /* Convert IP prefix string to struct prefix. */
2555 ret = str2prefix(prefix, &range);
2556 if (!ret) {
2557 vty_out(vty, "%% Malformed listen range\n");
2558 return CMD_WARNING_CONFIG_FAILED;
2559 }
2560
2561 afi = family2afi(range.family);
2562
2563 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2564 vty_out(vty,
2565 "%% Malformed listen range (link-local address)\n");
2566 return CMD_WARNING_CONFIG_FAILED;
2567 }
2568
2569 apply_mask(&range);
2570
2571 group = peer_group_lookup(bgp, peergroup);
2572 if (!group) {
2573 vty_out(vty, "%% Peer-group does not exist\n");
2574 return CMD_WARNING_CONFIG_FAILED;
2575 }
2576
2577 ret = peer_group_listen_range_del(group, &range);
2578 return bgp_vty_return(vty, ret);
2579}
2580
2b791107 2581void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2582{
2583 struct peer_group *group;
2584 struct listnode *node, *nnode, *rnode, *nrnode;
2585 struct prefix *range;
2586 afi_t afi;
2587 char buf[PREFIX2STR_BUFFER];
2588
2589 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2590 vty_out(vty, " bgp listen limit %d\n",
2591 bgp->dynamic_neighbors_limit);
2592
2593 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2594 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2595 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2596 nrnode, range)) {
2597 prefix2str(range, buf, sizeof(buf));
2598 vty_out(vty,
2599 " bgp listen range %s peer-group %s\n",
2600 buf, group->name);
2601 }
2602 }
2603 }
f14e6fdb
DS
2604}
2605
2606
907f92c8
DS
2607DEFUN (bgp_disable_connected_route_check,
2608 bgp_disable_connected_route_check_cmd,
2609 "bgp disable-ebgp-connected-route-check",
2610 "BGP specific commands\n"
2611 "Disable checking if nexthop is connected on ebgp sessions\n")
2612{
d62a17ae 2613 VTY_DECLVAR_CONTEXT(bgp, bgp);
2614 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2615 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2616
d62a17ae 2617 return CMD_SUCCESS;
907f92c8
DS
2618}
2619
2620DEFUN (no_bgp_disable_connected_route_check,
2621 no_bgp_disable_connected_route_check_cmd,
2622 "no bgp disable-ebgp-connected-route-check",
2623 NO_STR
2624 "BGP specific commands\n"
2625 "Disable checking if nexthop is connected on ebgp sessions\n")
2626{
d62a17ae 2627 VTY_DECLVAR_CONTEXT(bgp, bgp);
2628 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2629 bgp_clear_star_soft_in(vty, bgp->name);
2630
2631 return CMD_SUCCESS;
2632}
2633
2634
2635static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2636 const char *as_str, afi_t afi, safi_t safi)
2637{
2638 VTY_DECLVAR_CONTEXT(bgp, bgp);
2639 int ret;
2640 as_t as;
2641 int as_type = AS_SPECIFIED;
2642 union sockunion su;
2643
2644 if (as_str[0] == 'i') {
2645 as = 0;
2646 as_type = AS_INTERNAL;
2647 } else if (as_str[0] == 'e') {
2648 as = 0;
2649 as_type = AS_EXTERNAL;
2650 } else {
2651 /* Get AS number. */
2652 as = strtoul(as_str, NULL, 10);
2653 }
2654
2655 /* If peer is peer group, call proper function. */
2656 ret = str2sockunion(peer_str, &su);
2657 if (ret < 0) {
2658 /* Check for peer by interface */
2659 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2660 safi);
2661 if (ret < 0) {
2662 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2663 if (ret < 0) {
2664 vty_out(vty,
2665 "%% Create the peer-group or interface first\n");
2666 return CMD_WARNING_CONFIG_FAILED;
2667 }
2668 return CMD_SUCCESS;
2669 }
2670 } else {
2671 if (peer_address_self_check(bgp, &su)) {
2672 vty_out(vty,
2673 "%% Can not configure the local system as neighbor\n");
2674 return CMD_WARNING_CONFIG_FAILED;
2675 }
2676 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2677 }
2678
2679 /* This peer belongs to peer group. */
2680 switch (ret) {
2681 case BGP_ERR_PEER_GROUP_MEMBER:
2682 vty_out(vty,
2683 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2684 as);
2685 return CMD_WARNING_CONFIG_FAILED;
2686 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2687 vty_out(vty,
2688 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2689 as, as_str);
2690 return CMD_WARNING_CONFIG_FAILED;
2691 }
2692 return bgp_vty_return(vty, ret);
718e3744 2693}
2694
f26845f9
QY
2695DEFUN (bgp_default_shutdown,
2696 bgp_default_shutdown_cmd,
2697 "[no] bgp default shutdown",
2698 NO_STR
2699 BGP_STR
2700 "Configure BGP defaults\n"
2701 "Do not automatically activate peers upon configuration\n")
2702{
2703 VTY_DECLVAR_CONTEXT(bgp, bgp);
2704 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2705 return CMD_SUCCESS;
2706}
2707
718e3744 2708DEFUN (neighbor_remote_as,
2709 neighbor_remote_as_cmd,
3a2d747c 2710 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2711 NEIGHBOR_STR
2712 NEIGHBOR_ADDR_STR2
2713 "Specify a BGP neighbor\n"
d7fa34c1 2714 AS_STR
3a2d747c
QY
2715 "Internal BGP peer\n"
2716 "External BGP peer\n")
718e3744 2717{
d62a17ae 2718 int idx_peer = 1;
2719 int idx_remote_as = 3;
2720 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2721 argv[idx_remote_as]->arg, AFI_IP,
2722 SAFI_UNICAST);
2723}
2724
2725static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2726 afi_t afi, safi_t safi, int v6only,
2727 const char *peer_group_name,
2728 const char *as_str)
2729{
2730 VTY_DECLVAR_CONTEXT(bgp, bgp);
2731 as_t as = 0;
2732 int as_type = AS_UNSPECIFIED;
2733 struct peer *peer;
2734 struct peer_group *group;
2735 int ret = 0;
2736 union sockunion su;
2737
2738 group = peer_group_lookup(bgp, conf_if);
2739
2740 if (group) {
2741 vty_out(vty, "%% Name conflict with peer-group \n");
2742 return CMD_WARNING_CONFIG_FAILED;
2743 }
2744
2745 if (as_str) {
2746 if (as_str[0] == 'i') {
2747 as_type = AS_INTERNAL;
2748 } else if (as_str[0] == 'e') {
2749 as_type = AS_EXTERNAL;
2750 } else {
2751 /* Get AS number. */
2752 as = strtoul(as_str, NULL, 10);
2753 as_type = AS_SPECIFIED;
2754 }
2755 }
2756
2757 peer = peer_lookup_by_conf_if(bgp, conf_if);
2758 if (peer) {
2759 if (as_str)
2760 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2761 afi, safi);
2762 } else {
2763 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2764 && afi == AFI_IP && safi == SAFI_UNICAST)
2765 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2766 as_type, 0, 0, NULL);
2767 else
2768 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2769 as_type, afi, safi, NULL);
2770
2771 if (!peer) {
2772 vty_out(vty, "%% BGP failed to create peer\n");
2773 return CMD_WARNING_CONFIG_FAILED;
2774 }
2775
2776 if (v6only)
2777 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2778
2779 /* Request zebra to initiate IPv6 RAs on this interface. We do
2780 * this
2781 * any unnumbered peer in order to not worry about run-time
2782 * transitions
2783 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2784 * address
2785 * gets deleted later etc.)
2786 */
2787 if (peer->ifp)
2788 bgp_zebra_initiate_radv(bgp, peer);
2789 }
2790
2791 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2792 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2793 if (v6only)
2794 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2795 else
2796 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2797
2798 /* v6only flag changed. Reset bgp seesion */
2799 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2800 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2801 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2802 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2803 } else
2804 bgp_session_reset(peer);
2805 }
2806
2807 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2808 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2809
2810 if (peer_group_name) {
2811 group = peer_group_lookup(bgp, peer_group_name);
2812 if (!group) {
2813 vty_out(vty, "%% Configure the peer-group first\n");
2814 return CMD_WARNING_CONFIG_FAILED;
2815 }
2816
2817 ret = peer_group_bind(bgp, &su, peer, group, &as);
2818 }
2819
2820 return bgp_vty_return(vty, ret);
a80beece
DS
2821}
2822
4c48cf63
DW
2823DEFUN (neighbor_interface_config,
2824 neighbor_interface_config_cmd,
31500417 2825 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2826 NEIGHBOR_STR
2827 "Interface name or neighbor tag\n"
31500417
DW
2828 "Enable BGP on interface\n"
2829 "Member of the peer-group\n"
16cedbb0 2830 "Peer-group name\n")
4c48cf63 2831{
d62a17ae 2832 int idx_word = 1;
2833 int idx_peer_group_word = 4;
31500417 2834
d62a17ae 2835 if (argc > idx_peer_group_word)
2836 return peer_conf_interface_get(
2837 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2838 argv[idx_peer_group_word]->arg, NULL);
2839 else
2840 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2841 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2842}
2843
4c48cf63
DW
2844DEFUN (neighbor_interface_config_v6only,
2845 neighbor_interface_config_v6only_cmd,
31500417 2846 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2847 NEIGHBOR_STR
2848 "Interface name or neighbor tag\n"
2849 "Enable BGP on interface\n"
31500417
DW
2850 "Enable BGP with v6 link-local only\n"
2851 "Member of the peer-group\n"
16cedbb0 2852 "Peer-group name\n")
4c48cf63 2853{
d62a17ae 2854 int idx_word = 1;
2855 int idx_peer_group_word = 5;
31500417 2856
d62a17ae 2857 if (argc > idx_peer_group_word)
2858 return peer_conf_interface_get(
2859 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2860 argv[idx_peer_group_word]->arg, NULL);
31500417 2861
d62a17ae 2862 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2863 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2864}
2865
a80beece 2866
b3a39dc5
DD
2867DEFUN (neighbor_interface_config_remote_as,
2868 neighbor_interface_config_remote_as_cmd,
3a2d747c 2869 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2870 NEIGHBOR_STR
2871 "Interface name or neighbor tag\n"
2872 "Enable BGP on interface\n"
3a2d747c 2873 "Specify a BGP neighbor\n"
d7fa34c1 2874 AS_STR
3a2d747c
QY
2875 "Internal BGP peer\n"
2876 "External BGP peer\n")
b3a39dc5 2877{
d62a17ae 2878 int idx_word = 1;
2879 int idx_remote_as = 4;
2880 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2881 SAFI_UNICAST, 0, NULL,
2882 argv[idx_remote_as]->arg);
b3a39dc5
DD
2883}
2884
2885DEFUN (neighbor_interface_v6only_config_remote_as,
2886 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2887 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2888 NEIGHBOR_STR
2889 "Interface name or neighbor tag\n"
3a2d747c 2890 "Enable BGP with v6 link-local only\n"
b3a39dc5 2891 "Enable BGP on interface\n"
3a2d747c 2892 "Specify a BGP neighbor\n"
d7fa34c1 2893 AS_STR
3a2d747c
QY
2894 "Internal BGP peer\n"
2895 "External BGP peer\n")
b3a39dc5 2896{
d62a17ae 2897 int idx_word = 1;
2898 int idx_remote_as = 5;
2899 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2900 SAFI_UNICAST, 1, NULL,
2901 argv[idx_remote_as]->arg);
b3a39dc5
DD
2902}
2903
718e3744 2904DEFUN (neighbor_peer_group,
2905 neighbor_peer_group_cmd,
2906 "neighbor WORD peer-group",
2907 NEIGHBOR_STR
a80beece 2908 "Interface name or neighbor tag\n"
718e3744 2909 "Configure peer-group\n")
2910{
d62a17ae 2911 VTY_DECLVAR_CONTEXT(bgp, bgp);
2912 int idx_word = 1;
2913 struct peer *peer;
2914 struct peer_group *group;
718e3744 2915
d62a17ae 2916 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2917 if (peer) {
2918 vty_out(vty, "%% Name conflict with interface: \n");
2919 return CMD_WARNING_CONFIG_FAILED;
2920 }
718e3744 2921
d62a17ae 2922 group = peer_group_get(bgp, argv[idx_word]->arg);
2923 if (!group) {
2924 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2925 return CMD_WARNING_CONFIG_FAILED;
2926 }
718e3744 2927
d62a17ae 2928 return CMD_SUCCESS;
718e3744 2929}
2930
2931DEFUN (no_neighbor,
2932 no_neighbor_cmd,
dab8cd00 2933 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2934 NO_STR
2935 NEIGHBOR_STR
3a2d747c
QY
2936 NEIGHBOR_ADDR_STR2
2937 "Specify a BGP neighbor\n"
2938 AS_STR
2939 "Internal BGP peer\n"
2940 "External BGP peer\n")
718e3744 2941{
d62a17ae 2942 VTY_DECLVAR_CONTEXT(bgp, bgp);
2943 int idx_peer = 2;
2944 int ret;
2945 union sockunion su;
2946 struct peer_group *group;
2947 struct peer *peer;
2948 struct peer *other;
2949
2950 ret = str2sockunion(argv[idx_peer]->arg, &su);
2951 if (ret < 0) {
2952 /* look up for neighbor by interface name config. */
2953 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2954 if (peer) {
2955 /* Request zebra to terminate IPv6 RAs on this
2956 * interface. */
2957 if (peer->ifp)
2958 bgp_zebra_terminate_radv(peer->bgp, peer);
2959 peer_delete(peer);
2960 return CMD_SUCCESS;
2961 }
f14e6fdb 2962
d62a17ae 2963 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2964 if (group)
2965 peer_group_delete(group);
2966 else {
2967 vty_out(vty, "%% Create the peer-group first\n");
2968 return CMD_WARNING_CONFIG_FAILED;
2969 }
2970 } else {
2971 peer = peer_lookup(bgp, &su);
2972 if (peer) {
2973 if (peer_dynamic_neighbor(peer)) {
2974 vty_out(vty,
2975 "%% Operation not allowed on a dynamic neighbor\n");
2976 return CMD_WARNING_CONFIG_FAILED;
2977 }
2978
2979 other = peer->doppelganger;
2980 peer_delete(peer);
2981 if (other && other->status != Deleted)
2982 peer_delete(other);
2983 }
1ff9a340 2984 }
718e3744 2985
d62a17ae 2986 return CMD_SUCCESS;
718e3744 2987}
2988
a80beece
DS
2989DEFUN (no_neighbor_interface_config,
2990 no_neighbor_interface_config_cmd,
31500417 2991 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
2992 NO_STR
2993 NEIGHBOR_STR
2994 "Interface name\n"
31500417
DW
2995 "Configure BGP on interface\n"
2996 "Enable BGP with v6 link-local only\n"
2997 "Member of the peer-group\n"
16cedbb0 2998 "Peer-group name\n"
3a2d747c
QY
2999 "Specify a BGP neighbor\n"
3000 AS_STR
3001 "Internal BGP peer\n"
3002 "External BGP peer\n")
a80beece 3003{
d62a17ae 3004 VTY_DECLVAR_CONTEXT(bgp, bgp);
3005 int idx_word = 2;
3006 struct peer *peer;
3007
3008 /* look up for neighbor by interface name config. */
3009 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3010 if (peer) {
3011 /* Request zebra to terminate IPv6 RAs on this interface. */
3012 if (peer->ifp)
3013 bgp_zebra_terminate_radv(peer->bgp, peer);
3014 peer_delete(peer);
3015 } else {
3016 vty_out(vty, "%% Create the bgp interface first\n");
3017 return CMD_WARNING_CONFIG_FAILED;
3018 }
3019 return CMD_SUCCESS;
a80beece
DS
3020}
3021
718e3744 3022DEFUN (no_neighbor_peer_group,
3023 no_neighbor_peer_group_cmd,
3024 "no neighbor WORD peer-group",
3025 NO_STR
3026 NEIGHBOR_STR
3027 "Neighbor tag\n"
3028 "Configure peer-group\n")
3029{
d62a17ae 3030 VTY_DECLVAR_CONTEXT(bgp, bgp);
3031 int idx_word = 2;
3032 struct peer_group *group;
718e3744 3033
d62a17ae 3034 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3035 if (group)
3036 peer_group_delete(group);
3037 else {
3038 vty_out(vty, "%% Create the peer-group first\n");
3039 return CMD_WARNING_CONFIG_FAILED;
3040 }
3041 return CMD_SUCCESS;
718e3744 3042}
3043
a80beece
DS
3044DEFUN (no_neighbor_interface_peer_group_remote_as,
3045 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3046 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3047 NO_STR
3048 NEIGHBOR_STR
a80beece 3049 "Interface name or neighbor tag\n"
718e3744 3050 "Specify a BGP neighbor\n"
3a2d747c
QY
3051 AS_STR
3052 "Internal BGP peer\n"
3053 "External BGP peer\n")
718e3744 3054{
d62a17ae 3055 VTY_DECLVAR_CONTEXT(bgp, bgp);
3056 int idx_word = 2;
3057 struct peer_group *group;
3058 struct peer *peer;
3059
3060 /* look up for neighbor by interface name config. */
3061 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3062 if (peer) {
3063 peer_as_change(peer, 0, AS_SPECIFIED);
3064 return CMD_SUCCESS;
3065 }
3066
3067 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3068 if (group)
3069 peer_group_remote_as_delete(group);
3070 else {
3071 vty_out(vty, "%% Create the peer-group or interface first\n");
3072 return CMD_WARNING_CONFIG_FAILED;
3073 }
3074 return CMD_SUCCESS;
718e3744 3075}
6b0655a2 3076
718e3744 3077DEFUN (neighbor_local_as,
3078 neighbor_local_as_cmd,
9ccf14f7 3079 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3080 NEIGHBOR_STR
3081 NEIGHBOR_ADDR_STR2
3082 "Specify a local-as number\n"
3083 "AS number used as local AS\n")
3084{
d62a17ae 3085 int idx_peer = 1;
3086 int idx_number = 3;
3087 struct peer *peer;
3088 int ret;
3089 as_t as;
718e3744 3090
d62a17ae 3091 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3092 if (!peer)
3093 return CMD_WARNING_CONFIG_FAILED;
718e3744 3094
d62a17ae 3095 as = strtoul(argv[idx_number]->arg, NULL, 10);
3096 ret = peer_local_as_set(peer, as, 0, 0);
3097 return bgp_vty_return(vty, ret);
718e3744 3098}
3099
3100DEFUN (neighbor_local_as_no_prepend,
3101 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3102 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3103 NEIGHBOR_STR
3104 NEIGHBOR_ADDR_STR2
3105 "Specify a local-as number\n"
3106 "AS number used as local AS\n"
3107 "Do not prepend local-as to updates from ebgp peers\n")
3108{
d62a17ae 3109 int idx_peer = 1;
3110 int idx_number = 3;
3111 struct peer *peer;
3112 int ret;
3113 as_t as;
718e3744 3114
d62a17ae 3115 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3116 if (!peer)
3117 return CMD_WARNING_CONFIG_FAILED;
718e3744 3118
d62a17ae 3119 as = strtoul(argv[idx_number]->arg, NULL, 10);
3120 ret = peer_local_as_set(peer, as, 1, 0);
3121 return bgp_vty_return(vty, ret);
718e3744 3122}
3123
9d3f9705
AC
3124DEFUN (neighbor_local_as_no_prepend_replace_as,
3125 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3126 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3127 NEIGHBOR_STR
3128 NEIGHBOR_ADDR_STR2
3129 "Specify a local-as number\n"
3130 "AS number used as local AS\n"
3131 "Do not prepend local-as to updates from ebgp peers\n"
3132 "Do not prepend local-as to updates from ibgp peers\n")
3133{
d62a17ae 3134 int idx_peer = 1;
3135 int idx_number = 3;
3136 struct peer *peer;
3137 int ret;
3138 as_t as;
9d3f9705 3139
d62a17ae 3140 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3141 if (!peer)
3142 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3143
d62a17ae 3144 as = strtoul(argv[idx_number]->arg, NULL, 10);
3145 ret = peer_local_as_set(peer, as, 1, 1);
3146 return bgp_vty_return(vty, ret);
9d3f9705
AC
3147}
3148
718e3744 3149DEFUN (no_neighbor_local_as,
3150 no_neighbor_local_as_cmd,
a636c635 3151 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3152 NO_STR
3153 NEIGHBOR_STR
3154 NEIGHBOR_ADDR_STR2
a636c635
DW
3155 "Specify a local-as number\n"
3156 "AS number used as local AS\n"
3157 "Do not prepend local-as to updates from ebgp peers\n"
3158 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3159{
d62a17ae 3160 int idx_peer = 2;
3161 struct peer *peer;
3162 int ret;
718e3744 3163
d62a17ae 3164 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3165 if (!peer)
3166 return CMD_WARNING_CONFIG_FAILED;
718e3744 3167
d62a17ae 3168 ret = peer_local_as_unset(peer);
3169 return bgp_vty_return(vty, ret);
718e3744 3170}
3171
718e3744 3172
3f9c7369
DS
3173DEFUN (neighbor_solo,
3174 neighbor_solo_cmd,
9ccf14f7 3175 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3176 NEIGHBOR_STR
3177 NEIGHBOR_ADDR_STR2
3178 "Solo peer - part of its own update group\n")
3179{
d62a17ae 3180 int idx_peer = 1;
3181 struct peer *peer;
3182 int ret;
3f9c7369 3183
d62a17ae 3184 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3185 if (!peer)
3186 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3187
d62a17ae 3188 ret = update_group_adjust_soloness(peer, 1);
3189 return bgp_vty_return(vty, ret);
3f9c7369
DS
3190}
3191
3192DEFUN (no_neighbor_solo,
3193 no_neighbor_solo_cmd,
9ccf14f7 3194 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3195 NO_STR
3196 NEIGHBOR_STR
3197 NEIGHBOR_ADDR_STR2
3198 "Solo peer - part of its own update group\n")
3199{
d62a17ae 3200 int idx_peer = 2;
3201 struct peer *peer;
3202 int ret;
3f9c7369 3203
d62a17ae 3204 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3205 if (!peer)
3206 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3207
d62a17ae 3208 ret = update_group_adjust_soloness(peer, 0);
3209 return bgp_vty_return(vty, ret);
3f9c7369
DS
3210}
3211
0df7c91f
PJ
3212DEFUN (neighbor_password,
3213 neighbor_password_cmd,
9ccf14f7 3214 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3215 NEIGHBOR_STR
3216 NEIGHBOR_ADDR_STR2
3217 "Set a password\n"
3218 "The password\n")
3219{
d62a17ae 3220 int idx_peer = 1;
3221 int idx_line = 3;
3222 struct peer *peer;
3223 int ret;
0df7c91f 3224
d62a17ae 3225 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3226 if (!peer)
3227 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3228
d62a17ae 3229 ret = peer_password_set(peer, argv[idx_line]->arg);
3230 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3231}
3232
3233DEFUN (no_neighbor_password,
3234 no_neighbor_password_cmd,
a636c635 3235 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3236 NO_STR
3237 NEIGHBOR_STR
3238 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3239 "Set a password\n"
3240 "The password\n")
0df7c91f 3241{
d62a17ae 3242 int idx_peer = 2;
3243 struct peer *peer;
3244 int ret;
0df7c91f 3245
d62a17ae 3246 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3247 if (!peer)
3248 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3249
d62a17ae 3250 ret = peer_password_unset(peer);
3251 return bgp_vty_return(vty, ret);
0df7c91f 3252}
6b0655a2 3253
718e3744 3254DEFUN (neighbor_activate,
3255 neighbor_activate_cmd,
9ccf14f7 3256 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3257 NEIGHBOR_STR
3258 NEIGHBOR_ADDR_STR2
3259 "Enable the Address Family for this Neighbor\n")
3260{
d62a17ae 3261 int idx_peer = 1;
3262 int ret;
3263 struct peer *peer;
718e3744 3264
d62a17ae 3265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3266 if (!peer)
3267 return CMD_WARNING_CONFIG_FAILED;
718e3744 3268
d62a17ae 3269 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3270 return bgp_vty_return(vty, ret);
718e3744 3271}
3272
d62a17ae 3273ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3274 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3275 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3276 "Enable the Address Family for this Neighbor\n")
596c17ba 3277
718e3744 3278DEFUN (no_neighbor_activate,
3279 no_neighbor_activate_cmd,
9ccf14f7 3280 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3281 NO_STR
3282 NEIGHBOR_STR
3283 NEIGHBOR_ADDR_STR2
3284 "Enable the Address Family for this Neighbor\n")
3285{
d62a17ae 3286 int idx_peer = 2;
3287 int ret;
3288 struct peer *peer;
718e3744 3289
d62a17ae 3290 /* Lookup peer. */
3291 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3292 if (!peer)
3293 return CMD_WARNING_CONFIG_FAILED;
718e3744 3294
d62a17ae 3295 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3296 return bgp_vty_return(vty, ret);
718e3744 3297}
6b0655a2 3298
d62a17ae 3299ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3300 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3301 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3302 "Enable the Address Family for this Neighbor\n")
596c17ba 3303
718e3744 3304DEFUN (neighbor_set_peer_group,
3305 neighbor_set_peer_group_cmd,
9ccf14f7 3306 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3307 NEIGHBOR_STR
a80beece 3308 NEIGHBOR_ADDR_STR2
718e3744 3309 "Member of the peer-group\n"
16cedbb0 3310 "Peer-group name\n")
718e3744 3311{
d62a17ae 3312 VTY_DECLVAR_CONTEXT(bgp, bgp);
3313 int idx_peer = 1;
3314 int idx_word = 3;
3315 int ret;
3316 as_t as;
3317 union sockunion su;
3318 struct peer *peer;
3319 struct peer_group *group;
3320
3321 peer = NULL;
3322
3323 ret = str2sockunion(argv[idx_peer]->arg, &su);
3324 if (ret < 0) {
3325 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3326 if (!peer) {
3327 vty_out(vty, "%% Malformed address or name: %s\n",
3328 argv[idx_peer]->arg);
3329 return CMD_WARNING_CONFIG_FAILED;
3330 }
3331 } else {
3332 if (peer_address_self_check(bgp, &su)) {
3333 vty_out(vty,
3334 "%% Can not configure the local system as neighbor\n");
3335 return CMD_WARNING_CONFIG_FAILED;
3336 }
3337
3338 /* Disallow for dynamic neighbor. */
3339 peer = peer_lookup(bgp, &su);
3340 if (peer && peer_dynamic_neighbor(peer)) {
3341 vty_out(vty,
3342 "%% Operation not allowed on a dynamic neighbor\n");
3343 return CMD_WARNING_CONFIG_FAILED;
3344 }
3345 }
3346
3347 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3348 if (!group) {
3349 vty_out(vty, "%% Configure the peer-group first\n");
3350 return CMD_WARNING_CONFIG_FAILED;
3351 }
3352
3353 ret = peer_group_bind(bgp, &su, peer, group, &as);
3354
3355 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3356 vty_out(vty,
3357 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3358 as);
3359 return CMD_WARNING_CONFIG_FAILED;
3360 }
3361
3362 return bgp_vty_return(vty, ret);
3363}
3364
3365ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3366 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3367 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3368 "Member of the peer-group\n"
3369 "Peer-group name\n")
596c17ba 3370
718e3744 3371DEFUN (no_neighbor_set_peer_group,
3372 no_neighbor_set_peer_group_cmd,
9ccf14f7 3373 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3374 NO_STR
3375 NEIGHBOR_STR
a80beece 3376 NEIGHBOR_ADDR_STR2
718e3744 3377 "Member of the peer-group\n"
16cedbb0 3378 "Peer-group name\n")
718e3744 3379{
d62a17ae 3380 VTY_DECLVAR_CONTEXT(bgp, bgp);
3381 int idx_peer = 2;
3382 int idx_word = 4;
3383 int ret;
3384 struct peer *peer;
3385 struct peer_group *group;
3386
3387 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3388 if (!peer)
3389 return CMD_WARNING_CONFIG_FAILED;
3390
3391 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3392 if (!group) {
3393 vty_out(vty, "%% Configure the peer-group first\n");
3394 return CMD_WARNING_CONFIG_FAILED;
3395 }
718e3744 3396
d62a17ae 3397 ret = peer_group_unbind(bgp, peer, group);
718e3744 3398
d62a17ae 3399 return bgp_vty_return(vty, ret);
718e3744 3400}
6b0655a2 3401
d62a17ae 3402ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3403 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3404 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3405 "Member of the peer-group\n"
3406 "Peer-group name\n")
596c17ba 3407
d62a17ae 3408static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3409 u_int16_t flag, int set)
718e3744 3410{
d62a17ae 3411 int ret;
3412 struct peer *peer;
718e3744 3413
d62a17ae 3414 peer = peer_and_group_lookup_vty(vty, ip_str);
3415 if (!peer)
3416 return CMD_WARNING_CONFIG_FAILED;
718e3744 3417
d62a17ae 3418 if (!set && flag == PEER_FLAG_SHUTDOWN)
3419 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3420
d62a17ae 3421 if (set)
3422 ret = peer_flag_set(peer, flag);
3423 else
3424 ret = peer_flag_unset(peer, flag);
718e3744 3425
d62a17ae 3426 return bgp_vty_return(vty, ret);
718e3744 3427}
3428
d62a17ae 3429static int peer_flag_set_vty(struct vty *vty, const char *ip_str,
3430 u_int16_t flag)
718e3744 3431{
d62a17ae 3432 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3433}
3434
d62a17ae 3435static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3436 u_int16_t flag)
718e3744 3437{
d62a17ae 3438 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3439}
3440
3441/* neighbor passive. */
3442DEFUN (neighbor_passive,
3443 neighbor_passive_cmd,
9ccf14f7 3444 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3445 NEIGHBOR_STR
3446 NEIGHBOR_ADDR_STR2
3447 "Don't send open messages to this neighbor\n")
3448{
d62a17ae 3449 int idx_peer = 1;
3450 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3451}
3452
3453DEFUN (no_neighbor_passive,
3454 no_neighbor_passive_cmd,
9ccf14f7 3455 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3456 NO_STR
3457 NEIGHBOR_STR
3458 NEIGHBOR_ADDR_STR2
3459 "Don't send open messages to this neighbor\n")
3460{
d62a17ae 3461 int idx_peer = 2;
3462 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3463}
6b0655a2 3464
718e3744 3465/* neighbor shutdown. */
73d70fa6
DL
3466DEFUN (neighbor_shutdown_msg,
3467 neighbor_shutdown_msg_cmd,
3468 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3469 NEIGHBOR_STR
3470 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3471 "Administratively shut down this neighbor\n"
3472 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3473 "Shutdown message\n")
718e3744 3474{
d62a17ae 3475 int idx_peer = 1;
73d70fa6 3476
d62a17ae 3477 if (argc >= 5) {
3478 struct peer *peer =
3479 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3480 char *message;
73d70fa6 3481
d62a17ae 3482 if (!peer)
3483 return CMD_WARNING_CONFIG_FAILED;
3484 message = argv_concat(argv, argc, 4);
3485 peer_tx_shutdown_message_set(peer, message);
3486 XFREE(MTYPE_TMP, message);
3487 }
73d70fa6 3488
d62a17ae 3489 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3490}
3491
d62a17ae 3492ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3493 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3494 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3495 "Administratively shut down this neighbor\n")
73d70fa6
DL
3496
3497DEFUN (no_neighbor_shutdown_msg,
3498 no_neighbor_shutdown_msg_cmd,
3499 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3500 NO_STR
3501 NEIGHBOR_STR
3502 NEIGHBOR_ADDR_STR2
3503 "Administratively shut down this neighbor\n"
3504 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3505 "Shutdown message\n")
718e3744 3506{
d62a17ae 3507 int idx_peer = 2;
73d70fa6 3508
d62a17ae 3509 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3510 PEER_FLAG_SHUTDOWN);
718e3744 3511}
6b0655a2 3512
d62a17ae 3513ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3514 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3515 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3516 "Administratively shut down this neighbor\n")
73d70fa6 3517
718e3744 3518/* neighbor capability dynamic. */
3519DEFUN (neighbor_capability_dynamic,
3520 neighbor_capability_dynamic_cmd,
9ccf14f7 3521 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3522 NEIGHBOR_STR
3523 NEIGHBOR_ADDR_STR2
3524 "Advertise capability to the peer\n"
3525 "Advertise dynamic capability to this neighbor\n")
3526{
d62a17ae 3527 int idx_peer = 1;
3528 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3529 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3530}
3531
3532DEFUN (no_neighbor_capability_dynamic,
3533 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3534 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3535 NO_STR
3536 NEIGHBOR_STR
3537 NEIGHBOR_ADDR_STR2
3538 "Advertise capability to the peer\n"
3539 "Advertise dynamic capability to this neighbor\n")
3540{
d62a17ae 3541 int idx_peer = 2;
3542 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3543 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3544}
6b0655a2 3545
718e3744 3546/* neighbor dont-capability-negotiate */
3547DEFUN (neighbor_dont_capability_negotiate,
3548 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3549 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3550 NEIGHBOR_STR
3551 NEIGHBOR_ADDR_STR2
3552 "Do not perform capability negotiation\n")
3553{
d62a17ae 3554 int idx_peer = 1;
3555 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3556 PEER_FLAG_DONT_CAPABILITY);
718e3744 3557}
3558
3559DEFUN (no_neighbor_dont_capability_negotiate,
3560 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3561 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3562 NO_STR
3563 NEIGHBOR_STR
3564 NEIGHBOR_ADDR_STR2
3565 "Do not perform capability negotiation\n")
3566{
d62a17ae 3567 int idx_peer = 2;
3568 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3569 PEER_FLAG_DONT_CAPABILITY);
718e3744 3570}
6b0655a2 3571
8a92a8a0
DS
3572/* neighbor capability extended next hop encoding */
3573DEFUN (neighbor_capability_enhe,
3574 neighbor_capability_enhe_cmd,
9ccf14f7 3575 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3576 NEIGHBOR_STR
3577 NEIGHBOR_ADDR_STR2
3578 "Advertise capability to the peer\n"
3579 "Advertise extended next-hop capability to the peer\n")
3580{
d62a17ae 3581 int idx_peer = 1;
3582 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3583 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3584}
3585
3586DEFUN (no_neighbor_capability_enhe,
3587 no_neighbor_capability_enhe_cmd,
9ccf14f7 3588 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3589 NO_STR
3590 NEIGHBOR_STR
3591 NEIGHBOR_ADDR_STR2
3592 "Advertise capability to the peer\n"
3593 "Advertise extended next-hop capability to the peer\n")
3594{
d62a17ae 3595 int idx_peer = 2;
3596 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3597 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3598}
3599
d62a17ae 3600static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3601 afi_t afi, safi_t safi, u_int32_t flag,
3602 int set)
718e3744 3603{
d62a17ae 3604 int ret;
3605 struct peer *peer;
718e3744 3606
d62a17ae 3607 peer = peer_and_group_lookup_vty(vty, peer_str);
3608 if (!peer)
3609 return CMD_WARNING_CONFIG_FAILED;
718e3744 3610
d62a17ae 3611 if (set)
3612 ret = peer_af_flag_set(peer, afi, safi, flag);
3613 else
3614 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3615
d62a17ae 3616 return bgp_vty_return(vty, ret);
718e3744 3617}
3618
d62a17ae 3619static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3620 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3621{
d62a17ae 3622 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3623}
3624
d62a17ae 3625static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3626 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3627{
d62a17ae 3628 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3629}
6b0655a2 3630
718e3744 3631/* neighbor capability orf prefix-list. */
3632DEFUN (neighbor_capability_orf_prefix,
3633 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3634 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3635 NEIGHBOR_STR
3636 NEIGHBOR_ADDR_STR2
3637 "Advertise capability to the peer\n"
3638 "Advertise ORF capability to the peer\n"
3639 "Advertise prefixlist ORF capability to this neighbor\n"
3640 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3641 "Capability to RECEIVE the ORF from this neighbor\n"
3642 "Capability to SEND the ORF to this neighbor\n")
3643{
d62a17ae 3644 int idx_peer = 1;
3645 int idx_send_recv = 5;
3646 u_int16_t flag = 0;
3647
3648 if (strmatch(argv[idx_send_recv]->text, "send"))
3649 flag = PEER_FLAG_ORF_PREFIX_SM;
3650 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3651 flag = PEER_FLAG_ORF_PREFIX_RM;
3652 else if (strmatch(argv[idx_send_recv]->text, "both"))
3653 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3654 else {
3655 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3656 return CMD_WARNING_CONFIG_FAILED;
3657 }
3658
3659 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3660 bgp_node_safi(vty), flag);
3661}
3662
3663ALIAS_HIDDEN(
3664 neighbor_capability_orf_prefix,
3665 neighbor_capability_orf_prefix_hidden_cmd,
3666 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3667 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3668 "Advertise capability to the peer\n"
3669 "Advertise ORF capability to the peer\n"
3670 "Advertise prefixlist ORF capability to this neighbor\n"
3671 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3672 "Capability to RECEIVE the ORF from this neighbor\n"
3673 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3674
718e3744 3675DEFUN (no_neighbor_capability_orf_prefix,
3676 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3677 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3678 NO_STR
3679 NEIGHBOR_STR
3680 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")
3687{
d62a17ae 3688 int idx_peer = 2;
3689 int idx_send_recv = 6;
3690 u_int16_t flag = 0;
3691
3692 if (strmatch(argv[idx_send_recv]->text, "send"))
3693 flag = PEER_FLAG_ORF_PREFIX_SM;
3694 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3695 flag = PEER_FLAG_ORF_PREFIX_RM;
3696 else if (strmatch(argv[idx_send_recv]->text, "both"))
3697 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3698 else {
3699 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3700 return CMD_WARNING_CONFIG_FAILED;
3701 }
3702
3703 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3704 bgp_node_afi(vty), bgp_node_safi(vty),
3705 flag);
3706}
3707
3708ALIAS_HIDDEN(
3709 no_neighbor_capability_orf_prefix,
3710 no_neighbor_capability_orf_prefix_hidden_cmd,
3711 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3712 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3713 "Advertise capability to the peer\n"
3714 "Advertise ORF capability to the peer\n"
3715 "Advertise prefixlist ORF capability to this neighbor\n"
3716 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3717 "Capability to RECEIVE the ORF from this neighbor\n"
3718 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3719
718e3744 3720/* neighbor next-hop-self. */
3721DEFUN (neighbor_nexthop_self,
3722 neighbor_nexthop_self_cmd,
9ccf14f7 3723 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3724 NEIGHBOR_STR
3725 NEIGHBOR_ADDR_STR2
a538debe 3726 "Disable the next hop calculation for this neighbor\n")
718e3744 3727{
d62a17ae 3728 int idx_peer = 1;
3729 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3730 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3731}
9e7a53c1 3732
d62a17ae 3733ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3734 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3735 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3736 "Disable the next hop calculation for this neighbor\n")
596c17ba 3737
a538debe
DS
3738/* neighbor next-hop-self. */
3739DEFUN (neighbor_nexthop_self_force,
3740 neighbor_nexthop_self_force_cmd,
9ccf14f7 3741 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3742 NEIGHBOR_STR
3743 NEIGHBOR_ADDR_STR2
3744 "Disable the next hop calculation for this neighbor\n"
3745 "Set the next hop to self for reflected routes\n")
3746{
d62a17ae 3747 int idx_peer = 1;
3748 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3749 bgp_node_safi(vty),
3750 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3751}
3752
d62a17ae 3753ALIAS_HIDDEN(neighbor_nexthop_self_force,
3754 neighbor_nexthop_self_force_hidden_cmd,
3755 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3756 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3757 "Disable the next hop calculation for this neighbor\n"
3758 "Set the next hop to self for reflected routes\n")
596c17ba 3759
718e3744 3760DEFUN (no_neighbor_nexthop_self,
3761 no_neighbor_nexthop_self_cmd,
9ccf14f7 3762 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3763 NO_STR
3764 NEIGHBOR_STR
3765 NEIGHBOR_ADDR_STR2
a538debe 3766 "Disable the next hop calculation for this neighbor\n")
718e3744 3767{
d62a17ae 3768 int idx_peer = 2;
3769 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3770 bgp_node_afi(vty), bgp_node_safi(vty),
3771 PEER_FLAG_NEXTHOP_SELF);
718e3744 3772}
6b0655a2 3773
d62a17ae 3774ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3775 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3776 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3777 "Disable the next hop calculation for this neighbor\n")
596c17ba 3778
88b8ed8d 3779DEFUN (no_neighbor_nexthop_self_force,
a538debe 3780 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3781 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3782 NO_STR
3783 NEIGHBOR_STR
3784 NEIGHBOR_ADDR_STR2
3785 "Disable the next hop calculation for this neighbor\n"
3786 "Set the next hop to self for reflected routes\n")
88b8ed8d 3787{
d62a17ae 3788 int idx_peer = 2;
3789 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3790 bgp_node_afi(vty), bgp_node_safi(vty),
3791 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3792}
a538debe 3793
d62a17ae 3794ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3795 no_neighbor_nexthop_self_force_hidden_cmd,
3796 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3797 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3798 "Disable the next hop calculation for this neighbor\n"
3799 "Set the next hop to self for reflected routes\n")
596c17ba 3800
c7122e14
DS
3801/* neighbor as-override */
3802DEFUN (neighbor_as_override,
3803 neighbor_as_override_cmd,
9ccf14f7 3804 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3805 NEIGHBOR_STR
3806 NEIGHBOR_ADDR_STR2
3807 "Override ASNs in outbound updates if aspath equals remote-as\n")
3808{
d62a17ae 3809 int idx_peer = 1;
3810 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3811 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3812}
3813
d62a17ae 3814ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3815 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3816 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3817 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3818
c7122e14
DS
3819DEFUN (no_neighbor_as_override,
3820 no_neighbor_as_override_cmd,
9ccf14f7 3821 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3822 NO_STR
3823 NEIGHBOR_STR
3824 NEIGHBOR_ADDR_STR2
3825 "Override ASNs in outbound updates if aspath equals remote-as\n")
3826{
d62a17ae 3827 int idx_peer = 2;
3828 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3829 bgp_node_afi(vty), bgp_node_safi(vty),
3830 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3831}
3832
d62a17ae 3833ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3834 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3835 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3836 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3837
718e3744 3838/* neighbor remove-private-AS. */
3839DEFUN (neighbor_remove_private_as,
3840 neighbor_remove_private_as_cmd,
9ccf14f7 3841 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3842 NEIGHBOR_STR
3843 NEIGHBOR_ADDR_STR2
5000f21c 3844 "Remove private ASNs in outbound updates\n")
718e3744 3845{
d62a17ae 3846 int idx_peer = 1;
3847 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3848 bgp_node_safi(vty),
3849 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3850}
3851
d62a17ae 3852ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3853 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3854 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3855 "Remove private ASNs in outbound updates\n")
596c17ba 3856
5000f21c
DS
3857DEFUN (neighbor_remove_private_as_all,
3858 neighbor_remove_private_as_all_cmd,
9ccf14f7 3859 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3860 NEIGHBOR_STR
3861 NEIGHBOR_ADDR_STR2
3862 "Remove private ASNs in outbound updates\n"
efd7904e 3863 "Apply to all AS numbers\n")
5000f21c 3864{
d62a17ae 3865 int idx_peer = 1;
3866 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3867 bgp_node_safi(vty),
3868 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3869}
3870
d62a17ae 3871ALIAS_HIDDEN(neighbor_remove_private_as_all,
3872 neighbor_remove_private_as_all_hidden_cmd,
3873 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3874 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3875 "Remove private ASNs in outbound updates\n"
3876 "Apply to all AS numbers")
596c17ba 3877
5000f21c
DS
3878DEFUN (neighbor_remove_private_as_replace_as,
3879 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3880 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3881 NEIGHBOR_STR
3882 NEIGHBOR_ADDR_STR2
3883 "Remove private ASNs in outbound updates\n"
3884 "Replace private ASNs with our ASN in outbound updates\n")
3885{
d62a17ae 3886 int idx_peer = 1;
3887 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3888 bgp_node_safi(vty),
3889 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3890}
3891
d62a17ae 3892ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3893 neighbor_remove_private_as_replace_as_hidden_cmd,
3894 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3895 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3896 "Remove private ASNs in outbound updates\n"
3897 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3898
5000f21c
DS
3899DEFUN (neighbor_remove_private_as_all_replace_as,
3900 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3901 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3902 NEIGHBOR_STR
3903 NEIGHBOR_ADDR_STR2
3904 "Remove private ASNs in outbound updates\n"
16cedbb0 3905 "Apply to all AS numbers\n"
5000f21c
DS
3906 "Replace private ASNs with our ASN in outbound updates\n")
3907{
d62a17ae 3908 int idx_peer = 1;
3909 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3910 bgp_node_safi(vty),
3911 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3912}
3913
d62a17ae 3914ALIAS_HIDDEN(
3915 neighbor_remove_private_as_all_replace_as,
3916 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3917 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3918 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3919 "Remove private ASNs in outbound updates\n"
3920 "Apply to all AS numbers\n"
3921 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3922
718e3744 3923DEFUN (no_neighbor_remove_private_as,
3924 no_neighbor_remove_private_as_cmd,
9ccf14f7 3925 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3926 NO_STR
3927 NEIGHBOR_STR
3928 NEIGHBOR_ADDR_STR2
5000f21c 3929 "Remove private ASNs in outbound updates\n")
718e3744 3930{
d62a17ae 3931 int idx_peer = 2;
3932 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3933 bgp_node_afi(vty), bgp_node_safi(vty),
3934 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3935}
6b0655a2 3936
d62a17ae 3937ALIAS_HIDDEN(no_neighbor_remove_private_as,
3938 no_neighbor_remove_private_as_hidden_cmd,
3939 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3940 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3941 "Remove private ASNs in outbound updates\n")
596c17ba 3942
88b8ed8d 3943DEFUN (no_neighbor_remove_private_as_all,
5000f21c 3944 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 3945 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3946 NO_STR
3947 NEIGHBOR_STR
3948 NEIGHBOR_ADDR_STR2
3949 "Remove private ASNs in outbound updates\n"
16cedbb0 3950 "Apply to all AS numbers\n")
88b8ed8d 3951{
d62a17ae 3952 int idx_peer = 2;
3953 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3954 bgp_node_afi(vty), bgp_node_safi(vty),
3955 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 3956}
5000f21c 3957
d62a17ae 3958ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3959 no_neighbor_remove_private_as_all_hidden_cmd,
3960 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3961 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3962 "Remove private ASNs in outbound updates\n"
3963 "Apply to all AS numbers\n")
596c17ba 3964
88b8ed8d 3965DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 3966 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3967 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3968 NO_STR
3969 NEIGHBOR_STR
3970 NEIGHBOR_ADDR_STR2
3971 "Remove private ASNs in outbound updates\n"
3972 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3973{
d62a17ae 3974 int idx_peer = 2;
3975 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3976 bgp_node_afi(vty), bgp_node_safi(vty),
3977 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 3978}
5000f21c 3979
d62a17ae 3980ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
3981 no_neighbor_remove_private_as_replace_as_hidden_cmd,
3982 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3983 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3984 "Remove private ASNs in outbound updates\n"
3985 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3986
88b8ed8d 3987DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 3988 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3989 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3990 NO_STR
3991 NEIGHBOR_STR
3992 NEIGHBOR_ADDR_STR2
3993 "Remove private ASNs in outbound updates\n"
16cedbb0 3994 "Apply to all AS numbers\n"
5000f21c 3995 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3996{
d62a17ae 3997 int idx_peer = 2;
3998 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3999 bgp_node_afi(vty), bgp_node_safi(vty),
4000 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4001}
5000f21c 4002
d62a17ae 4003ALIAS_HIDDEN(
4004 no_neighbor_remove_private_as_all_replace_as,
4005 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4006 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4007 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4008 "Remove private ASNs in outbound updates\n"
4009 "Apply to all AS numbers\n"
4010 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4011
5000f21c 4012
718e3744 4013/* neighbor send-community. */
4014DEFUN (neighbor_send_community,
4015 neighbor_send_community_cmd,
9ccf14f7 4016 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4017 NEIGHBOR_STR
4018 NEIGHBOR_ADDR_STR2
4019 "Send Community attribute to this neighbor\n")
4020{
d62a17ae 4021 int idx_peer = 1;
4022 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4023 bgp_node_safi(vty),
4024 PEER_FLAG_SEND_COMMUNITY);
718e3744 4025}
4026
d62a17ae 4027ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4028 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4029 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4030 "Send Community attribute to this neighbor\n")
596c17ba 4031
718e3744 4032DEFUN (no_neighbor_send_community,
4033 no_neighbor_send_community_cmd,
9ccf14f7 4034 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4035 NO_STR
4036 NEIGHBOR_STR
4037 NEIGHBOR_ADDR_STR2
4038 "Send Community attribute to this neighbor\n")
4039{
d62a17ae 4040 int idx_peer = 2;
4041 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4042 bgp_node_afi(vty), bgp_node_safi(vty),
4043 PEER_FLAG_SEND_COMMUNITY);
718e3744 4044}
6b0655a2 4045
d62a17ae 4046ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4047 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4048 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4049 "Send Community attribute to this neighbor\n")
596c17ba 4050
718e3744 4051/* neighbor send-community extended. */
4052DEFUN (neighbor_send_community_type,
4053 neighbor_send_community_type_cmd,
57d187bc 4054 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4055 NEIGHBOR_STR
4056 NEIGHBOR_ADDR_STR2
4057 "Send Community attribute to this neighbor\n"
4058 "Send Standard and Extended Community attributes\n"
57d187bc 4059 "Send Standard, Large and Extended Community attributes\n"
718e3744 4060 "Send Extended Community attributes\n"
57d187bc
JS
4061 "Send Standard Community attributes\n"
4062 "Send Large Community attributes\n")
718e3744 4063{
d62a17ae 4064 int idx = 0;
4065 u_int32_t flag = 0;
4066
4067 char *peer = argv[1]->arg;
4068
4069 if (argv_find(argv, argc, "standard", &idx))
4070 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4071 else if (argv_find(argv, argc, "extended", &idx))
4072 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4073 else if (argv_find(argv, argc, "large", &idx))
4074 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4075 else if (argv_find(argv, argc, "both", &idx)) {
4076 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4077 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4078 } else {
4079 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4080 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4081 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4082 }
4083
4084 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4085 bgp_node_safi(vty), flag);
4086}
4087
4088ALIAS_HIDDEN(
4089 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4090 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4091 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4092 "Send Community attribute to this neighbor\n"
4093 "Send Standard and Extended Community attributes\n"
4094 "Send Standard, Large and Extended Community attributes\n"
4095 "Send Extended Community attributes\n"
4096 "Send Standard Community attributes\n"
4097 "Send Large Community attributes\n")
596c17ba 4098
718e3744 4099DEFUN (no_neighbor_send_community_type,
4100 no_neighbor_send_community_type_cmd,
57d187bc 4101 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4102 NO_STR
4103 NEIGHBOR_STR
4104 NEIGHBOR_ADDR_STR2
4105 "Send Community attribute to this neighbor\n"
4106 "Send Standard and Extended Community attributes\n"
57d187bc 4107 "Send Standard, Large and Extended Community attributes\n"
718e3744 4108 "Send Extended Community attributes\n"
57d187bc
JS
4109 "Send Standard Community attributes\n"
4110 "Send Large Community attributes\n")
718e3744 4111{
d62a17ae 4112 int idx_peer = 2;
4113
4114 const char *type = argv[argc - 1]->text;
4115
4116 if (strmatch(type, "standard"))
4117 return peer_af_flag_unset_vty(
4118 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4119 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4120 if (strmatch(type, "extended"))
4121 return peer_af_flag_unset_vty(
4122 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4123 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4124 if (strmatch(type, "large"))
4125 return peer_af_flag_unset_vty(
4126 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4127 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4128 if (strmatch(type, "both"))
4129 return peer_af_flag_unset_vty(
4130 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4131 bgp_node_safi(vty),
4132 PEER_FLAG_SEND_COMMUNITY
4133 | PEER_FLAG_SEND_EXT_COMMUNITY);
4134
4135 /* if (strmatch (type, "all")) */
4136 return peer_af_flag_unset_vty(
4137 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4138 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4139 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4140}
4141
4142ALIAS_HIDDEN(
4143 no_neighbor_send_community_type,
4144 no_neighbor_send_community_type_hidden_cmd,
4145 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4146 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4147 "Send Community attribute to this neighbor\n"
4148 "Send Standard and Extended Community attributes\n"
4149 "Send Standard, Large and Extended Community attributes\n"
4150 "Send Extended Community attributes\n"
4151 "Send Standard Community attributes\n"
4152 "Send Large Community attributes\n")
596c17ba 4153
718e3744 4154/* neighbor soft-reconfig. */
4155DEFUN (neighbor_soft_reconfiguration,
4156 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4157 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4158 NEIGHBOR_STR
4159 NEIGHBOR_ADDR_STR2
4160 "Per neighbor soft reconfiguration\n"
4161 "Allow inbound soft reconfiguration for this neighbor\n")
4162{
d62a17ae 4163 int idx_peer = 1;
4164 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4165 bgp_node_safi(vty),
4166 PEER_FLAG_SOFT_RECONFIG);
718e3744 4167}
4168
d62a17ae 4169ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4170 neighbor_soft_reconfiguration_hidden_cmd,
4171 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4172 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4173 "Per neighbor soft reconfiguration\n"
4174 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4175
718e3744 4176DEFUN (no_neighbor_soft_reconfiguration,
4177 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4178 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4179 NO_STR
4180 NEIGHBOR_STR
4181 NEIGHBOR_ADDR_STR2
4182 "Per neighbor soft reconfiguration\n"
4183 "Allow inbound soft reconfiguration for this neighbor\n")
4184{
d62a17ae 4185 int idx_peer = 2;
4186 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4187 bgp_node_afi(vty), bgp_node_safi(vty),
4188 PEER_FLAG_SOFT_RECONFIG);
718e3744 4189}
6b0655a2 4190
d62a17ae 4191ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4192 no_neighbor_soft_reconfiguration_hidden_cmd,
4193 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4194 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4195 "Per neighbor soft reconfiguration\n"
4196 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4197
718e3744 4198DEFUN (neighbor_route_reflector_client,
4199 neighbor_route_reflector_client_cmd,
9ccf14f7 4200 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4201 NEIGHBOR_STR
4202 NEIGHBOR_ADDR_STR2
4203 "Configure a neighbor as Route Reflector client\n")
4204{
d62a17ae 4205 int idx_peer = 1;
4206 struct peer *peer;
718e3744 4207
4208
d62a17ae 4209 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4210 if (!peer)
4211 return CMD_WARNING_CONFIG_FAILED;
718e3744 4212
d62a17ae 4213 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4214 bgp_node_safi(vty),
4215 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4216}
4217
d62a17ae 4218ALIAS_HIDDEN(neighbor_route_reflector_client,
4219 neighbor_route_reflector_client_hidden_cmd,
4220 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4221 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4222 "Configure a neighbor as Route Reflector client\n")
596c17ba 4223
718e3744 4224DEFUN (no_neighbor_route_reflector_client,
4225 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4226 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4227 NO_STR
4228 NEIGHBOR_STR
4229 NEIGHBOR_ADDR_STR2
4230 "Configure a neighbor as Route Reflector client\n")
4231{
d62a17ae 4232 int idx_peer = 2;
4233 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4234 bgp_node_afi(vty), bgp_node_safi(vty),
4235 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4236}
6b0655a2 4237
d62a17ae 4238ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4239 no_neighbor_route_reflector_client_hidden_cmd,
4240 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4241 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4242 "Configure a neighbor as Route Reflector client\n")
596c17ba 4243
718e3744 4244/* neighbor route-server-client. */
4245DEFUN (neighbor_route_server_client,
4246 neighbor_route_server_client_cmd,
9ccf14f7 4247 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4248 NEIGHBOR_STR
4249 NEIGHBOR_ADDR_STR2
4250 "Configure a neighbor as Route Server client\n")
4251{
d62a17ae 4252 int idx_peer = 1;
4253 struct peer *peer;
2a3d5731 4254
d62a17ae 4255 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4256 if (!peer)
4257 return CMD_WARNING_CONFIG_FAILED;
4258 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4259 bgp_node_safi(vty),
4260 PEER_FLAG_RSERVER_CLIENT);
718e3744 4261}
4262
d62a17ae 4263ALIAS_HIDDEN(neighbor_route_server_client,
4264 neighbor_route_server_client_hidden_cmd,
4265 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4266 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4267 "Configure a neighbor as Route Server client\n")
596c17ba 4268
718e3744 4269DEFUN (no_neighbor_route_server_client,
4270 no_neighbor_route_server_client_cmd,
9ccf14f7 4271 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4272 NO_STR
4273 NEIGHBOR_STR
4274 NEIGHBOR_ADDR_STR2
4275 "Configure a neighbor as Route Server client\n")
fee0f4c6 4276{
d62a17ae 4277 int idx_peer = 2;
4278 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4279 bgp_node_afi(vty), bgp_node_safi(vty),
4280 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4281}
6b0655a2 4282
d62a17ae 4283ALIAS_HIDDEN(no_neighbor_route_server_client,
4284 no_neighbor_route_server_client_hidden_cmd,
4285 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4286 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4287 "Configure a neighbor as Route Server client\n")
596c17ba 4288
fee0f4c6 4289DEFUN (neighbor_nexthop_local_unchanged,
4290 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4291 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4292 NEIGHBOR_STR
4293 NEIGHBOR_ADDR_STR2
4294 "Configure treatment of outgoing link-local nexthop attribute\n"
4295 "Leave link-local nexthop unchanged for this peer\n")
4296{
d62a17ae 4297 int idx_peer = 1;
4298 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4299 bgp_node_safi(vty),
4300 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4301}
6b0655a2 4302
fee0f4c6 4303DEFUN (no_neighbor_nexthop_local_unchanged,
4304 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4305 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4306 NO_STR
4307 NEIGHBOR_STR
4308 NEIGHBOR_ADDR_STR2
4309 "Configure treatment of outgoing link-local-nexthop attribute\n"
4310 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4311{
d62a17ae 4312 int idx_peer = 2;
4313 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4314 bgp_node_afi(vty), bgp_node_safi(vty),
4315 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4316}
6b0655a2 4317
718e3744 4318DEFUN (neighbor_attr_unchanged,
4319 neighbor_attr_unchanged_cmd,
a8206004 4320 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4321 NEIGHBOR_STR
4322 NEIGHBOR_ADDR_STR2
4323 "BGP attribute is propagated unchanged to this neighbor\n"
4324 "As-path attribute\n"
4325 "Nexthop attribute\n"
a8206004 4326 "Med attribute\n")
718e3744 4327{
d62a17ae 4328 int idx = 0;
8eeb0335
DW
4329 char *peer_str = argv[1]->arg;
4330 struct peer *peer;
d62a17ae 4331 u_int16_t flags = 0;
8eeb0335
DW
4332 afi_t afi = bgp_node_afi(vty);
4333 safi_t safi = bgp_node_safi(vty);
4334
4335 peer = peer_and_group_lookup_vty(vty, peer_str);
4336 if (!peer)
4337 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4338
4339 if (argv_find(argv, argc, "as-path", &idx))
4340 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4341 idx = 0;
4342 if (argv_find(argv, argc, "next-hop", &idx))
4343 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4344 idx = 0;
4345 if (argv_find(argv, argc, "med", &idx))
4346 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4347
8eeb0335
DW
4348 /* no flags means all of them! */
4349 if (!flags) {
d62a17ae 4350 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4351 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4352 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335
DW
4353 } else {
4354 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED) &&
4355 peer_af_flag_check(peer, afi, safi,
4356 PEER_FLAG_AS_PATH_UNCHANGED)) {
4357 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4358 PEER_FLAG_AS_PATH_UNCHANGED);
4359 }
4360
4361 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED) &&
4362 peer_af_flag_check(peer, afi, safi,
4363 PEER_FLAG_NEXTHOP_UNCHANGED)) {
4364 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4365 PEER_FLAG_NEXTHOP_UNCHANGED);
4366 }
4367
4368 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED) &&
4369 peer_af_flag_check(peer, afi, safi,
4370 PEER_FLAG_MED_UNCHANGED)) {
4371 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4372 PEER_FLAG_MED_UNCHANGED);
4373 }
d62a17ae 4374 }
4375
8eeb0335 4376 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4377}
4378
4379ALIAS_HIDDEN(
4380 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4381 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4382 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4383 "BGP attribute is propagated unchanged to this neighbor\n"
4384 "As-path attribute\n"
4385 "Nexthop attribute\n"
4386 "Med attribute\n")
596c17ba 4387
718e3744 4388DEFUN (no_neighbor_attr_unchanged,
4389 no_neighbor_attr_unchanged_cmd,
a8206004 4390 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4391 NO_STR
718e3744 4392 NEIGHBOR_STR
4393 NEIGHBOR_ADDR_STR2
31500417
DW
4394 "BGP attribute is propagated unchanged to this neighbor\n"
4395 "As-path attribute\n"
40e718b5 4396 "Nexthop attribute\n"
a8206004 4397 "Med attribute\n")
718e3744 4398{
d62a17ae 4399 int idx = 0;
4400 char *peer = argv[2]->arg;
4401 u_int16_t flags = 0;
4402
4403 if (argv_find(argv, argc, "as-path", &idx))
4404 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4405 idx = 0;
4406 if (argv_find(argv, argc, "next-hop", &idx))
4407 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4408 idx = 0;
4409 if (argv_find(argv, argc, "med", &idx))
4410 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4411
4412 if (!flags) // no flags means all of them!
4413 {
4414 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4415 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4416 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4417 }
4418
4419 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4420 bgp_node_safi(vty), flags);
4421}
4422
4423ALIAS_HIDDEN(
4424 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4425 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4426 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4427 "BGP attribute is propagated unchanged to this neighbor\n"
4428 "As-path attribute\n"
4429 "Nexthop attribute\n"
4430 "Med attribute\n")
718e3744 4431
718e3744 4432/* EBGP multihop configuration. */
d62a17ae 4433static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4434 const char *ttl_str)
718e3744 4435{
d62a17ae 4436 struct peer *peer;
4437 unsigned int ttl;
718e3744 4438
d62a17ae 4439 peer = peer_and_group_lookup_vty(vty, ip_str);
4440 if (!peer)
4441 return CMD_WARNING_CONFIG_FAILED;
718e3744 4442
d62a17ae 4443 if (peer->conf_if)
4444 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4445
d62a17ae 4446 if (!ttl_str)
4447 ttl = MAXTTL;
4448 else
4449 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4450
d62a17ae 4451 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4452}
4453
d62a17ae 4454static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4455{
d62a17ae 4456 struct peer *peer;
718e3744 4457
d62a17ae 4458 peer = peer_and_group_lookup_vty(vty, ip_str);
4459 if (!peer)
4460 return CMD_WARNING_CONFIG_FAILED;
718e3744 4461
d62a17ae 4462 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4463}
4464
4465/* neighbor ebgp-multihop. */
4466DEFUN (neighbor_ebgp_multihop,
4467 neighbor_ebgp_multihop_cmd,
9ccf14f7 4468 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4469 NEIGHBOR_STR
4470 NEIGHBOR_ADDR_STR2
4471 "Allow EBGP neighbors not on directly connected networks\n")
4472{
d62a17ae 4473 int idx_peer = 1;
4474 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4475}
4476
4477DEFUN (neighbor_ebgp_multihop_ttl,
4478 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4479 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4480 NEIGHBOR_STR
4481 NEIGHBOR_ADDR_STR2
4482 "Allow EBGP neighbors not on directly connected networks\n"
4483 "maximum hop count\n")
4484{
d62a17ae 4485 int idx_peer = 1;
4486 int idx_number = 3;
4487 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4488 argv[idx_number]->arg);
718e3744 4489}
4490
4491DEFUN (no_neighbor_ebgp_multihop,
4492 no_neighbor_ebgp_multihop_cmd,
a636c635 4493 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4494 NO_STR
4495 NEIGHBOR_STR
4496 NEIGHBOR_ADDR_STR2
a636c635
DW
4497 "Allow EBGP neighbors not on directly connected networks\n"
4498 "maximum hop count\n")
718e3744 4499{
d62a17ae 4500 int idx_peer = 2;
4501 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4502}
4503
6b0655a2 4504
6ffd2079 4505/* disable-connected-check */
4506DEFUN (neighbor_disable_connected_check,
4507 neighbor_disable_connected_check_cmd,
a174be63 4508 "neighbor <A.B.C.D|X:X::X:X> <disable-connected-check|enforce-multihop>",
6ffd2079 4509 NEIGHBOR_STR
a174be63 4510 NEIGHBOR_ADDR_STR
a636c635
DW
4511 "one-hop away EBGP peer using loopback address\n"
4512 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4513{
d62a17ae 4514 int idx_peer = 1;
4515 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4516 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4517}
4518
4519DEFUN (no_neighbor_disable_connected_check,
4520 no_neighbor_disable_connected_check_cmd,
a174be63 4521 "no neighbor <A.B.C.D|X:X::X:X> <disable-connected-check|enforce-multihop>",
6ffd2079 4522 NO_STR
4523 NEIGHBOR_STR
a174be63 4524 NEIGHBOR_ADDR_STR
a636c635
DW
4525 "one-hop away EBGP peer using loopback address\n"
4526 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4527{
d62a17ae 4528 int idx_peer = 2;
4529 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4530 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4531}
4532
718e3744 4533DEFUN (neighbor_description,
4534 neighbor_description_cmd,
e961923c 4535 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4536 NEIGHBOR_STR
4537 NEIGHBOR_ADDR_STR2
4538 "Neighbor specific description\n"
4539 "Up to 80 characters describing this neighbor\n")
4540{
d62a17ae 4541 int idx_peer = 1;
4542 int idx_line = 3;
4543 struct peer *peer;
4544 char *str;
718e3744 4545
d62a17ae 4546 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4547 if (!peer)
4548 return CMD_WARNING_CONFIG_FAILED;
718e3744 4549
d62a17ae 4550 str = argv_concat(argv, argc, idx_line);
718e3744 4551
d62a17ae 4552 peer_description_set(peer, str);
718e3744 4553
d62a17ae 4554 XFREE(MTYPE_TMP, str);
718e3744 4555
d62a17ae 4556 return CMD_SUCCESS;
718e3744 4557}
4558
4559DEFUN (no_neighbor_description,
4560 no_neighbor_description_cmd,
a636c635 4561 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4562 NO_STR
4563 NEIGHBOR_STR
4564 NEIGHBOR_ADDR_STR2
a636c635
DW
4565 "Neighbor specific description\n"
4566 "Up to 80 characters describing this neighbor\n")
718e3744 4567{
d62a17ae 4568 int idx_peer = 2;
4569 struct peer *peer;
718e3744 4570
d62a17ae 4571 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4572 if (!peer)
4573 return CMD_WARNING_CONFIG_FAILED;
718e3744 4574
d62a17ae 4575 peer_description_unset(peer);
718e3744 4576
d62a17ae 4577 return CMD_SUCCESS;
718e3744 4578}
4579
6b0655a2 4580
718e3744 4581/* Neighbor update-source. */
d62a17ae 4582static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4583 const char *source_str)
4584{
4585 struct peer *peer;
4586 struct prefix p;
4587
4588 peer = peer_and_group_lookup_vty(vty, peer_str);
4589 if (!peer)
4590 return CMD_WARNING_CONFIG_FAILED;
4591
4592 if (peer->conf_if)
4593 return CMD_WARNING;
4594
4595 if (source_str) {
4596 union sockunion su;
4597 int ret = str2sockunion(source_str, &su);
4598
4599 if (ret == 0)
4600 peer_update_source_addr_set(peer, &su);
4601 else {
4602 if (str2prefix(source_str, &p)) {
4603 vty_out(vty,
4604 "%% Invalid update-source, remove prefix length \n");
4605 return CMD_WARNING_CONFIG_FAILED;
4606 } else
4607 peer_update_source_if_set(peer, source_str);
4608 }
4609 } else
4610 peer_update_source_unset(peer);
4611
4612 return CMD_SUCCESS;
4613}
4614
4615#define BGP_UPDATE_SOURCE_HELP_STR \
4616 "IPv4 address\n" \
4617 "IPv6 address\n" \
4618 "Interface name (requires zebra to be running)\n"
369688c0 4619
718e3744 4620DEFUN (neighbor_update_source,
4621 neighbor_update_source_cmd,
9ccf14f7 4622 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4623 NEIGHBOR_STR
4624 NEIGHBOR_ADDR_STR2
4625 "Source of routing updates\n"
369688c0 4626 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4627{
d62a17ae 4628 int idx_peer = 1;
4629 int idx_peer_2 = 3;
4630 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4631 argv[idx_peer_2]->arg);
718e3744 4632}
4633
4634DEFUN (no_neighbor_update_source,
4635 no_neighbor_update_source_cmd,
c7178fe7 4636 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4637 NO_STR
4638 NEIGHBOR_STR
4639 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4640 "Source of routing updates\n"
4641 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4642{
d62a17ae 4643 int idx_peer = 2;
4644 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4645}
6b0655a2 4646
d62a17ae 4647static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4648 afi_t afi, safi_t safi,
4649 const char *rmap, int set)
718e3744 4650{
d62a17ae 4651 int ret;
4652 struct peer *peer;
718e3744 4653
d62a17ae 4654 peer = peer_and_group_lookup_vty(vty, peer_str);
4655 if (!peer)
4656 return CMD_WARNING_CONFIG_FAILED;
718e3744 4657
d62a17ae 4658 if (set)
4659 ret = peer_default_originate_set(peer, afi, safi, rmap);
4660 else
4661 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4662
d62a17ae 4663 return bgp_vty_return(vty, ret);
718e3744 4664}
4665
4666/* neighbor default-originate. */
4667DEFUN (neighbor_default_originate,
4668 neighbor_default_originate_cmd,
9ccf14f7 4669 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4670 NEIGHBOR_STR
4671 NEIGHBOR_ADDR_STR2
4672 "Originate default route to this neighbor\n")
4673{
d62a17ae 4674 int idx_peer = 1;
4675 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4676 bgp_node_afi(vty),
4677 bgp_node_safi(vty), NULL, 1);
718e3744 4678}
4679
d62a17ae 4680ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4681 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4682 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4683 "Originate default route to this neighbor\n")
596c17ba 4684
718e3744 4685DEFUN (neighbor_default_originate_rmap,
4686 neighbor_default_originate_rmap_cmd,
9ccf14f7 4687 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4688 NEIGHBOR_STR
4689 NEIGHBOR_ADDR_STR2
4690 "Originate default route to this neighbor\n"
4691 "Route-map to specify criteria to originate default\n"
4692 "route-map name\n")
4693{
d62a17ae 4694 int idx_peer = 1;
4695 int idx_word = 4;
4696 return peer_default_originate_set_vty(
4697 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4698 argv[idx_word]->arg, 1);
718e3744 4699}
4700
d62a17ae 4701ALIAS_HIDDEN(
4702 neighbor_default_originate_rmap,
4703 neighbor_default_originate_rmap_hidden_cmd,
4704 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4705 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4706 "Originate default route to this neighbor\n"
4707 "Route-map to specify criteria to originate default\n"
4708 "route-map name\n")
596c17ba 4709
718e3744 4710DEFUN (no_neighbor_default_originate,
4711 no_neighbor_default_originate_cmd,
a636c635 4712 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4713 NO_STR
4714 NEIGHBOR_STR
4715 NEIGHBOR_ADDR_STR2
a636c635
DW
4716 "Originate default route to this neighbor\n"
4717 "Route-map to specify criteria to originate default\n"
4718 "route-map name\n")
718e3744 4719{
d62a17ae 4720 int idx_peer = 2;
4721 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4722 bgp_node_afi(vty),
4723 bgp_node_safi(vty), NULL, 0);
718e3744 4724}
4725
d62a17ae 4726ALIAS_HIDDEN(
4727 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4728 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4729 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4730 "Originate default route to this neighbor\n"
4731 "Route-map to specify criteria to originate default\n"
4732 "route-map name\n")
596c17ba 4733
6b0655a2 4734
718e3744 4735/* Set neighbor's BGP port. */
d62a17ae 4736static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4737 const char *port_str)
4738{
4739 struct peer *peer;
4740 u_int16_t port;
4741 struct servent *sp;
4742
4743 peer = peer_lookup_vty(vty, ip_str);
4744 if (!peer)
4745 return CMD_WARNING_CONFIG_FAILED;
4746
4747 if (!port_str) {
4748 sp = getservbyname("bgp", "tcp");
4749 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4750 } else {
4751 port = strtoul(port_str, NULL, 10);
4752 }
718e3744 4753
d62a17ae 4754 peer_port_set(peer, port);
718e3744 4755
d62a17ae 4756 return CMD_SUCCESS;
718e3744 4757}
4758
f418446b 4759/* Set specified peer's BGP port. */
718e3744 4760DEFUN (neighbor_port,
4761 neighbor_port_cmd,
9ccf14f7 4762 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4763 NEIGHBOR_STR
4764 NEIGHBOR_ADDR_STR
4765 "Neighbor's BGP port\n"
4766 "TCP port number\n")
4767{
d62a17ae 4768 int idx_ip = 1;
4769 int idx_number = 3;
4770 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4771 argv[idx_number]->arg);
718e3744 4772}
4773
4774DEFUN (no_neighbor_port,
4775 no_neighbor_port_cmd,
9ccf14f7 4776 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4777 NO_STR
4778 NEIGHBOR_STR
4779 NEIGHBOR_ADDR_STR
8334fd5a
DW
4780 "Neighbor's BGP port\n"
4781 "TCP port number\n")
718e3744 4782{
d62a17ae 4783 int idx_ip = 2;
4784 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4785}
4786
6b0655a2 4787
718e3744 4788/* neighbor weight. */
d62a17ae 4789static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4790 safi_t safi, const char *weight_str)
718e3744 4791{
d62a17ae 4792 int ret;
4793 struct peer *peer;
4794 unsigned long weight;
718e3744 4795
d62a17ae 4796 peer = peer_and_group_lookup_vty(vty, ip_str);
4797 if (!peer)
4798 return CMD_WARNING_CONFIG_FAILED;
718e3744 4799
d62a17ae 4800 weight = strtoul(weight_str, NULL, 10);
718e3744 4801
d62a17ae 4802 ret = peer_weight_set(peer, afi, safi, weight);
4803 return bgp_vty_return(vty, ret);
718e3744 4804}
4805
d62a17ae 4806static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4807 safi_t safi)
718e3744 4808{
d62a17ae 4809 int ret;
4810 struct peer *peer;
718e3744 4811
d62a17ae 4812 peer = peer_and_group_lookup_vty(vty, ip_str);
4813 if (!peer)
4814 return CMD_WARNING_CONFIG_FAILED;
718e3744 4815
d62a17ae 4816 ret = peer_weight_unset(peer, afi, safi);
4817 return bgp_vty_return(vty, ret);
718e3744 4818}
4819
4820DEFUN (neighbor_weight,
4821 neighbor_weight_cmd,
9ccf14f7 4822 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4823 NEIGHBOR_STR
4824 NEIGHBOR_ADDR_STR2
4825 "Set default weight for routes from this neighbor\n"
4826 "default weight\n")
4827{
d62a17ae 4828 int idx_peer = 1;
4829 int idx_number = 3;
4830 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4831 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4832}
4833
d62a17ae 4834ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4835 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4836 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4837 "Set default weight for routes from this neighbor\n"
4838 "default weight\n")
596c17ba 4839
718e3744 4840DEFUN (no_neighbor_weight,
4841 no_neighbor_weight_cmd,
9ccf14f7 4842 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4843 NO_STR
4844 NEIGHBOR_STR
4845 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4846 "Set default weight for routes from this neighbor\n"
4847 "default weight\n")
718e3744 4848{
d62a17ae 4849 int idx_peer = 2;
4850 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4851 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4852}
4853
d62a17ae 4854ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4855 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4856 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4857 "Set default weight for routes from this neighbor\n"
4858 "default weight\n")
596c17ba 4859
6b0655a2 4860
718e3744 4861/* Override capability negotiation. */
4862DEFUN (neighbor_override_capability,
4863 neighbor_override_capability_cmd,
9ccf14f7 4864 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4865 NEIGHBOR_STR
4866 NEIGHBOR_ADDR_STR2
4867 "Override capability negotiation result\n")
4868{
d62a17ae 4869 int idx_peer = 1;
4870 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4871 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4872}
4873
4874DEFUN (no_neighbor_override_capability,
4875 no_neighbor_override_capability_cmd,
9ccf14f7 4876 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4877 NO_STR
4878 NEIGHBOR_STR
4879 NEIGHBOR_ADDR_STR2
4880 "Override capability negotiation result\n")
4881{
d62a17ae 4882 int idx_peer = 2;
4883 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4884 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4885}
6b0655a2 4886
718e3744 4887DEFUN (neighbor_strict_capability,
4888 neighbor_strict_capability_cmd,
9ccf14f7 4889 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4890 NEIGHBOR_STR
4891 NEIGHBOR_ADDR_STR
4892 "Strict capability negotiation match\n")
4893{
d62a17ae 4894 int idx_ip = 1;
4895 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4896 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4897}
4898
4899DEFUN (no_neighbor_strict_capability,
4900 no_neighbor_strict_capability_cmd,
9ccf14f7 4901 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4902 NO_STR
4903 NEIGHBOR_STR
4904 NEIGHBOR_ADDR_STR
4905 "Strict capability negotiation match\n")
4906{
d62a17ae 4907 int idx_ip = 2;
4908 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4909 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4910}
6b0655a2 4911
d62a17ae 4912static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4913 const char *keep_str, const char *hold_str)
718e3744 4914{
d62a17ae 4915 int ret;
4916 struct peer *peer;
4917 u_int32_t keepalive;
4918 u_int32_t holdtime;
718e3744 4919
d62a17ae 4920 peer = peer_and_group_lookup_vty(vty, ip_str);
4921 if (!peer)
4922 return CMD_WARNING_CONFIG_FAILED;
718e3744 4923
d62a17ae 4924 keepalive = strtoul(keep_str, NULL, 10);
4925 holdtime = strtoul(hold_str, NULL, 10);
718e3744 4926
d62a17ae 4927 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 4928
d62a17ae 4929 return bgp_vty_return(vty, ret);
718e3744 4930}
6b0655a2 4931
d62a17ae 4932static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4933{
d62a17ae 4934 int ret;
4935 struct peer *peer;
718e3744 4936
d62a17ae 4937 peer = peer_and_group_lookup_vty(vty, ip_str);
4938 if (!peer)
4939 return CMD_WARNING_CONFIG_FAILED;
718e3744 4940
d62a17ae 4941 ret = peer_timers_unset(peer);
718e3744 4942
d62a17ae 4943 return bgp_vty_return(vty, ret);
718e3744 4944}
4945
4946DEFUN (neighbor_timers,
4947 neighbor_timers_cmd,
9ccf14f7 4948 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 4949 NEIGHBOR_STR
4950 NEIGHBOR_ADDR_STR2
4951 "BGP per neighbor timers\n"
4952 "Keepalive interval\n"
4953 "Holdtime\n")
4954{
d62a17ae 4955 int idx_peer = 1;
4956 int idx_number = 3;
4957 int idx_number_2 = 4;
4958 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4959 argv[idx_number]->arg,
4960 argv[idx_number_2]->arg);
718e3744 4961}
4962
4963DEFUN (no_neighbor_timers,
4964 no_neighbor_timers_cmd,
9ccf14f7 4965 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 4966 NO_STR
4967 NEIGHBOR_STR
4968 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4969 "BGP per neighbor timers\n"
4970 "Keepalive interval\n"
4971 "Holdtime\n")
718e3744 4972{
d62a17ae 4973 int idx_peer = 2;
4974 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4975}
6b0655a2 4976
813d4307 4977
d62a17ae 4978static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
4979 const char *time_str)
718e3744 4980{
d62a17ae 4981 int ret;
4982 struct peer *peer;
4983 u_int32_t connect;
718e3744 4984
d62a17ae 4985 peer = peer_and_group_lookup_vty(vty, ip_str);
4986 if (!peer)
4987 return CMD_WARNING_CONFIG_FAILED;
718e3744 4988
d62a17ae 4989 connect = strtoul(time_str, NULL, 10);
718e3744 4990
d62a17ae 4991 ret = peer_timers_connect_set(peer, connect);
718e3744 4992
d62a17ae 4993 return bgp_vty_return(vty, ret);
718e3744 4994}
4995
d62a17ae 4996static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4997{
d62a17ae 4998 int ret;
4999 struct peer *peer;
718e3744 5000
d62a17ae 5001 peer = peer_and_group_lookup_vty(vty, ip_str);
5002 if (!peer)
5003 return CMD_WARNING_CONFIG_FAILED;
718e3744 5004
d62a17ae 5005 ret = peer_timers_connect_unset(peer);
718e3744 5006
d62a17ae 5007 return bgp_vty_return(vty, ret);
718e3744 5008}
5009
5010DEFUN (neighbor_timers_connect,
5011 neighbor_timers_connect_cmd,
9ccf14f7 5012 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5013 NEIGHBOR_STR
966f821c 5014 NEIGHBOR_ADDR_STR2
718e3744 5015 "BGP per neighbor timers\n"
5016 "BGP connect timer\n"
5017 "Connect timer\n")
5018{
d62a17ae 5019 int idx_peer = 1;
5020 int idx_number = 4;
5021 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5022 argv[idx_number]->arg);
718e3744 5023}
5024
5025DEFUN (no_neighbor_timers_connect,
5026 no_neighbor_timers_connect_cmd,
9ccf14f7 5027 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5028 NO_STR
5029 NEIGHBOR_STR
966f821c 5030 NEIGHBOR_ADDR_STR2
718e3744 5031 "BGP per neighbor timers\n"
8334fd5a
DW
5032 "BGP connect timer\n"
5033 "Connect timer\n")
718e3744 5034{
d62a17ae 5035 int idx_peer = 2;
5036 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5037}
5038
6b0655a2 5039
d62a17ae 5040static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5041 const char *time_str, int set)
718e3744 5042{
d62a17ae 5043 int ret;
5044 struct peer *peer;
5045 u_int32_t routeadv = 0;
718e3744 5046
d62a17ae 5047 peer = peer_and_group_lookup_vty(vty, ip_str);
5048 if (!peer)
5049 return CMD_WARNING_CONFIG_FAILED;
718e3744 5050
d62a17ae 5051 if (time_str)
5052 routeadv = strtoul(time_str, NULL, 10);
718e3744 5053
d62a17ae 5054 if (set)
5055 ret = peer_advertise_interval_set(peer, routeadv);
5056 else
5057 ret = peer_advertise_interval_unset(peer);
718e3744 5058
d62a17ae 5059 return bgp_vty_return(vty, ret);
718e3744 5060}
5061
5062DEFUN (neighbor_advertise_interval,
5063 neighbor_advertise_interval_cmd,
9ccf14f7 5064 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5065 NEIGHBOR_STR
966f821c 5066 NEIGHBOR_ADDR_STR2
718e3744 5067 "Minimum interval between sending BGP routing updates\n"
5068 "time in seconds\n")
5069{
d62a17ae 5070 int idx_peer = 1;
5071 int idx_number = 3;
5072 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5073 argv[idx_number]->arg, 1);
718e3744 5074}
5075
5076DEFUN (no_neighbor_advertise_interval,
5077 no_neighbor_advertise_interval_cmd,
9ccf14f7 5078 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5079 NO_STR
5080 NEIGHBOR_STR
966f821c 5081 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5082 "Minimum interval between sending BGP routing updates\n"
5083 "time in seconds\n")
718e3744 5084{
d62a17ae 5085 int idx_peer = 2;
5086 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5087}
5088
6b0655a2 5089
518f0eb1
DS
5090/* Time to wait before processing route-map updates */
5091DEFUN (bgp_set_route_map_delay_timer,
5092 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5093 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5094 SET_STR
5095 "BGP route-map delay timer\n"
5096 "Time in secs to wait before processing route-map changes\n"
f414725f 5097 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5098{
d62a17ae 5099 int idx_number = 3;
5100 u_int32_t rmap_delay_timer;
5101
5102 if (argv[idx_number]->arg) {
5103 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5104 bm->rmap_update_timer = rmap_delay_timer;
5105
5106 /* if the dynamic update handling is being disabled, and a timer
5107 * is
5108 * running, stop the timer and act as if the timer has already
5109 * fired.
5110 */
5111 if (!rmap_delay_timer && bm->t_rmap_update) {
5112 BGP_TIMER_OFF(bm->t_rmap_update);
5113 thread_execute(bm->master, bgp_route_map_update_timer,
5114 NULL, 0);
5115 }
5116 return CMD_SUCCESS;
5117 } else {
5118 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5119 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5120 }
518f0eb1
DS
5121}
5122
5123DEFUN (no_bgp_set_route_map_delay_timer,
5124 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5125 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5126 NO_STR
3a2d747c 5127 BGP_STR
518f0eb1 5128 "Default BGP route-map delay timer\n"
8334fd5a
DW
5129 "Reset to default time to wait for processing route-map changes\n"
5130 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5131{
518f0eb1 5132
d62a17ae 5133 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5134
d62a17ae 5135 return CMD_SUCCESS;
518f0eb1
DS
5136}
5137
f414725f 5138
718e3744 5139/* neighbor interface */
d62a17ae 5140static int peer_interface_vty(struct vty *vty, const char *ip_str,
5141 const char *str)
718e3744 5142{
d62a17ae 5143 struct peer *peer;
718e3744 5144
d62a17ae 5145 peer = peer_lookup_vty(vty, ip_str);
5146 if (!peer || peer->conf_if) {
5147 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5148 return CMD_WARNING_CONFIG_FAILED;
5149 }
718e3744 5150
d62a17ae 5151 if (str)
5152 peer_interface_set(peer, str);
5153 else
5154 peer_interface_unset(peer);
718e3744 5155
d62a17ae 5156 return CMD_SUCCESS;
718e3744 5157}
5158
5159DEFUN (neighbor_interface,
5160 neighbor_interface_cmd,
9ccf14f7 5161 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5162 NEIGHBOR_STR
5163 NEIGHBOR_ADDR_STR
5164 "Interface\n"
5165 "Interface name\n")
5166{
d62a17ae 5167 int idx_ip = 1;
5168 int idx_word = 3;
5169 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5170}
5171
5172DEFUN (no_neighbor_interface,
5173 no_neighbor_interface_cmd,
9ccf14f7 5174 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5175 NO_STR
5176 NEIGHBOR_STR
16cedbb0 5177 NEIGHBOR_ADDR_STR2
718e3744 5178 "Interface\n"
5179 "Interface name\n")
5180{
d62a17ae 5181 int idx_peer = 2;
5182 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5183}
6b0655a2 5184
718e3744 5185DEFUN (neighbor_distribute_list,
5186 neighbor_distribute_list_cmd,
9ccf14f7 5187 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5188 NEIGHBOR_STR
5189 NEIGHBOR_ADDR_STR2
5190 "Filter updates to/from this neighbor\n"
5191 "IP access-list number\n"
5192 "IP access-list number (expanded range)\n"
5193 "IP Access-list name\n"
5194 "Filter incoming updates\n"
5195 "Filter outgoing updates\n")
5196{
d62a17ae 5197 int idx_peer = 1;
5198 int idx_acl = 3;
5199 int direct, ret;
5200 struct peer *peer;
a8206004 5201
d62a17ae 5202 const char *pstr = argv[idx_peer]->arg;
5203 const char *acl = argv[idx_acl]->arg;
5204 const char *inout = argv[argc - 1]->text;
a8206004 5205
d62a17ae 5206 peer = peer_and_group_lookup_vty(vty, pstr);
5207 if (!peer)
5208 return CMD_WARNING_CONFIG_FAILED;
a8206004 5209
d62a17ae 5210 /* Check filter direction. */
5211 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5212 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5213 direct, acl);
a8206004 5214
d62a17ae 5215 return bgp_vty_return(vty, ret);
718e3744 5216}
5217
d62a17ae 5218ALIAS_HIDDEN(
5219 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5220 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5221 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5222 "Filter updates to/from this neighbor\n"
5223 "IP access-list number\n"
5224 "IP access-list number (expanded range)\n"
5225 "IP Access-list name\n"
5226 "Filter incoming updates\n"
5227 "Filter outgoing updates\n")
596c17ba 5228
718e3744 5229DEFUN (no_neighbor_distribute_list,
5230 no_neighbor_distribute_list_cmd,
9ccf14f7 5231 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5232 NO_STR
5233 NEIGHBOR_STR
5234 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")
5241{
d62a17ae 5242 int idx_peer = 2;
5243 int direct, ret;
5244 struct peer *peer;
a8206004 5245
d62a17ae 5246 const char *pstr = argv[idx_peer]->arg;
5247 const char *inout = argv[argc - 1]->text;
a8206004 5248
d62a17ae 5249 peer = peer_and_group_lookup_vty(vty, pstr);
5250 if (!peer)
5251 return CMD_WARNING_CONFIG_FAILED;
a8206004 5252
d62a17ae 5253 /* Check filter direction. */
5254 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5255 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5256 direct);
a8206004 5257
d62a17ae 5258 return bgp_vty_return(vty, ret);
718e3744 5259}
6b0655a2 5260
d62a17ae 5261ALIAS_HIDDEN(
5262 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5263 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5264 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5265 "Filter updates to/from this neighbor\n"
5266 "IP access-list number\n"
5267 "IP access-list number (expanded range)\n"
5268 "IP Access-list name\n"
5269 "Filter incoming updates\n"
5270 "Filter outgoing updates\n")
596c17ba 5271
718e3744 5272/* Set prefix list to the peer. */
d62a17ae 5273static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5274 afi_t afi, safi_t safi,
5275 const char *name_str,
5276 const char *direct_str)
718e3744 5277{
d62a17ae 5278 int ret;
5279 struct peer *peer;
5280 int direct = FILTER_IN;
718e3744 5281
d62a17ae 5282 peer = peer_and_group_lookup_vty(vty, ip_str);
5283 if (!peer)
5284 return CMD_WARNING_CONFIG_FAILED;
718e3744 5285
d62a17ae 5286 /* Check filter direction. */
5287 if (strncmp(direct_str, "i", 1) == 0)
5288 direct = FILTER_IN;
5289 else if (strncmp(direct_str, "o", 1) == 0)
5290 direct = FILTER_OUT;
718e3744 5291
d62a17ae 5292 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5293
d62a17ae 5294 return bgp_vty_return(vty, ret);
718e3744 5295}
5296
d62a17ae 5297static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5298 afi_t afi, safi_t safi,
5299 const char *direct_str)
718e3744 5300{
d62a17ae 5301 int ret;
5302 struct peer *peer;
5303 int direct = FILTER_IN;
718e3744 5304
d62a17ae 5305 peer = peer_and_group_lookup_vty(vty, ip_str);
5306 if (!peer)
5307 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5308
d62a17ae 5309 /* Check filter direction. */
5310 if (strncmp(direct_str, "i", 1) == 0)
5311 direct = FILTER_IN;
5312 else if (strncmp(direct_str, "o", 1) == 0)
5313 direct = FILTER_OUT;
718e3744 5314
d62a17ae 5315 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5316
d62a17ae 5317 return bgp_vty_return(vty, ret);
718e3744 5318}
5319
5320DEFUN (neighbor_prefix_list,
5321 neighbor_prefix_list_cmd,
9ccf14f7 5322 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5323 NEIGHBOR_STR
5324 NEIGHBOR_ADDR_STR2
5325 "Filter updates to/from this neighbor\n"
5326 "Name of a prefix list\n"
5327 "Filter incoming updates\n"
5328 "Filter outgoing updates\n")
5329{
d62a17ae 5330 int idx_peer = 1;
5331 int idx_word = 3;
5332 int idx_in_out = 4;
5333 return peer_prefix_list_set_vty(
5334 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5335 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5336}
5337
d62a17ae 5338ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5339 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5340 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5341 "Filter updates to/from this neighbor\n"
5342 "Name of a prefix list\n"
5343 "Filter incoming updates\n"
5344 "Filter outgoing updates\n")
596c17ba 5345
718e3744 5346DEFUN (no_neighbor_prefix_list,
5347 no_neighbor_prefix_list_cmd,
9ccf14f7 5348 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5349 NO_STR
5350 NEIGHBOR_STR
5351 NEIGHBOR_ADDR_STR2
5352 "Filter updates to/from this neighbor\n"
5353 "Name of a prefix list\n"
5354 "Filter incoming updates\n"
5355 "Filter outgoing updates\n")
5356{
d62a17ae 5357 int idx_peer = 2;
5358 int idx_in_out = 5;
5359 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5360 bgp_node_afi(vty), bgp_node_safi(vty),
5361 argv[idx_in_out]->arg);
718e3744 5362}
6b0655a2 5363
d62a17ae 5364ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5365 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5366 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5367 "Filter updates to/from this neighbor\n"
5368 "Name of a prefix list\n"
5369 "Filter incoming updates\n"
5370 "Filter outgoing updates\n")
596c17ba 5371
d62a17ae 5372static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5373 safi_t safi, const char *name_str,
5374 const char *direct_str)
718e3744 5375{
d62a17ae 5376 int ret;
5377 struct peer *peer;
5378 int direct = FILTER_IN;
718e3744 5379
d62a17ae 5380 peer = peer_and_group_lookup_vty(vty, ip_str);
5381 if (!peer)
5382 return CMD_WARNING_CONFIG_FAILED;
718e3744 5383
d62a17ae 5384 /* Check filter direction. */
5385 if (strncmp(direct_str, "i", 1) == 0)
5386 direct = FILTER_IN;
5387 else if (strncmp(direct_str, "o", 1) == 0)
5388 direct = FILTER_OUT;
718e3744 5389
d62a17ae 5390 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5391
d62a17ae 5392 return bgp_vty_return(vty, ret);
718e3744 5393}
5394
d62a17ae 5395static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5396 safi_t safi, const char *direct_str)
718e3744 5397{
d62a17ae 5398 int ret;
5399 struct peer *peer;
5400 int direct = FILTER_IN;
718e3744 5401
d62a17ae 5402 peer = peer_and_group_lookup_vty(vty, ip_str);
5403 if (!peer)
5404 return CMD_WARNING_CONFIG_FAILED;
718e3744 5405
d62a17ae 5406 /* Check filter direction. */
5407 if (strncmp(direct_str, "i", 1) == 0)
5408 direct = FILTER_IN;
5409 else if (strncmp(direct_str, "o", 1) == 0)
5410 direct = FILTER_OUT;
718e3744 5411
d62a17ae 5412 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5413
d62a17ae 5414 return bgp_vty_return(vty, ret);
718e3744 5415}
5416
5417DEFUN (neighbor_filter_list,
5418 neighbor_filter_list_cmd,
9ccf14f7 5419 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5420 NEIGHBOR_STR
5421 NEIGHBOR_ADDR_STR2
5422 "Establish BGP filters\n"
5423 "AS path access-list name\n"
5424 "Filter incoming routes\n"
5425 "Filter outgoing routes\n")
5426{
d62a17ae 5427 int idx_peer = 1;
5428 int idx_word = 3;
5429 int idx_in_out = 4;
5430 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5431 bgp_node_safi(vty), argv[idx_word]->arg,
5432 argv[idx_in_out]->arg);
718e3744 5433}
5434
d62a17ae 5435ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5436 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5437 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5438 "Establish BGP filters\n"
5439 "AS path access-list name\n"
5440 "Filter incoming routes\n"
5441 "Filter outgoing routes\n")
596c17ba 5442
718e3744 5443DEFUN (no_neighbor_filter_list,
5444 no_neighbor_filter_list_cmd,
9ccf14f7 5445 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5446 NO_STR
5447 NEIGHBOR_STR
5448 NEIGHBOR_ADDR_STR2
5449 "Establish BGP filters\n"
5450 "AS path access-list name\n"
5451 "Filter incoming routes\n"
5452 "Filter outgoing routes\n")
5453{
d62a17ae 5454 int idx_peer = 2;
5455 int idx_in_out = 5;
5456 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5457 bgp_node_afi(vty), bgp_node_safi(vty),
5458 argv[idx_in_out]->arg);
718e3744 5459}
6b0655a2 5460
d62a17ae 5461ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5462 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5463 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5464 "Establish BGP filters\n"
5465 "AS path access-list name\n"
5466 "Filter incoming routes\n"
5467 "Filter outgoing routes\n")
596c17ba 5468
718e3744 5469/* Set route-map to the peer. */
d62a17ae 5470static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5471 afi_t afi, safi_t safi, const char *name_str,
5472 const char *direct_str)
718e3744 5473{
d62a17ae 5474 int ret;
5475 struct peer *peer;
5476 int direct = RMAP_IN;
718e3744 5477
d62a17ae 5478 peer = peer_and_group_lookup_vty(vty, ip_str);
5479 if (!peer)
5480 return CMD_WARNING_CONFIG_FAILED;
718e3744 5481
d62a17ae 5482 /* Check filter direction. */
5483 if (strncmp(direct_str, "in", 2) == 0)
5484 direct = RMAP_IN;
5485 else if (strncmp(direct_str, "o", 1) == 0)
5486 direct = RMAP_OUT;
718e3744 5487
d62a17ae 5488 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5489
d62a17ae 5490 return bgp_vty_return(vty, ret);
718e3744 5491}
5492
d62a17ae 5493static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5494 afi_t afi, safi_t safi,
5495 const char *direct_str)
718e3744 5496{
d62a17ae 5497 int ret;
5498 struct peer *peer;
5499 int direct = RMAP_IN;
718e3744 5500
d62a17ae 5501 peer = peer_and_group_lookup_vty(vty, ip_str);
5502 if (!peer)
5503 return CMD_WARNING_CONFIG_FAILED;
718e3744 5504
d62a17ae 5505 /* Check filter direction. */
5506 if (strncmp(direct_str, "in", 2) == 0)
5507 direct = RMAP_IN;
5508 else if (strncmp(direct_str, "o", 1) == 0)
5509 direct = RMAP_OUT;
718e3744 5510
d62a17ae 5511 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5512
d62a17ae 5513 return bgp_vty_return(vty, ret);
718e3744 5514}
5515
5516DEFUN (neighbor_route_map,
5517 neighbor_route_map_cmd,
9ccf14f7 5518 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5519 NEIGHBOR_STR
5520 NEIGHBOR_ADDR_STR2
5521 "Apply route map to neighbor\n"
5522 "Name of route map\n"
5523 "Apply map to incoming routes\n"
2a3d5731 5524 "Apply map to outbound routes\n")
718e3744 5525{
d62a17ae 5526 int idx_peer = 1;
5527 int idx_word = 3;
5528 int idx_in_out = 4;
5529 return peer_route_map_set_vty(
5530 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5531 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5532}
5533
d62a17ae 5534ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5535 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5536 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5537 "Apply route map to neighbor\n"
5538 "Name of route map\n"
5539 "Apply map to incoming routes\n"
5540 "Apply map to outbound routes\n")
596c17ba 5541
718e3744 5542DEFUN (no_neighbor_route_map,
5543 no_neighbor_route_map_cmd,
9ccf14f7 5544 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5545 NO_STR
5546 NEIGHBOR_STR
5547 NEIGHBOR_ADDR_STR2
5548 "Apply route map to neighbor\n"
5549 "Name of route map\n"
5550 "Apply map to incoming routes\n"
2a3d5731 5551 "Apply map to outbound routes\n")
718e3744 5552{
d62a17ae 5553 int idx_peer = 2;
5554 int idx_in_out = 5;
5555 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5556 bgp_node_afi(vty), bgp_node_safi(vty),
5557 argv[idx_in_out]->arg);
718e3744 5558}
6b0655a2 5559
d62a17ae 5560ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5561 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5562 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5563 "Apply route map to neighbor\n"
5564 "Name of route map\n"
5565 "Apply map to incoming routes\n"
5566 "Apply map to outbound routes\n")
596c17ba 5567
718e3744 5568/* Set unsuppress-map to the peer. */
d62a17ae 5569static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5570 afi_t afi, safi_t safi,
5571 const char *name_str)
718e3744 5572{
d62a17ae 5573 int ret;
5574 struct peer *peer;
718e3744 5575
d62a17ae 5576 peer = peer_and_group_lookup_vty(vty, ip_str);
5577 if (!peer)
5578 return CMD_WARNING_CONFIG_FAILED;
718e3744 5579
d62a17ae 5580 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5581
d62a17ae 5582 return bgp_vty_return(vty, ret);
718e3744 5583}
5584
5585/* Unset route-map from the peer. */
d62a17ae 5586static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5587 afi_t afi, safi_t safi)
718e3744 5588{
d62a17ae 5589 int ret;
5590 struct peer *peer;
718e3744 5591
d62a17ae 5592 peer = peer_and_group_lookup_vty(vty, ip_str);
5593 if (!peer)
5594 return CMD_WARNING_CONFIG_FAILED;
718e3744 5595
d62a17ae 5596 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5597
d62a17ae 5598 return bgp_vty_return(vty, ret);
718e3744 5599}
5600
5601DEFUN (neighbor_unsuppress_map,
5602 neighbor_unsuppress_map_cmd,
9ccf14f7 5603 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5604 NEIGHBOR_STR
5605 NEIGHBOR_ADDR_STR2
5606 "Route-map to selectively unsuppress suppressed routes\n"
5607 "Name of route map\n")
5608{
d62a17ae 5609 int idx_peer = 1;
5610 int idx_word = 3;
5611 return peer_unsuppress_map_set_vty(
5612 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5613 argv[idx_word]->arg);
718e3744 5614}
5615
d62a17ae 5616ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5617 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5618 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5619 "Route-map to selectively unsuppress suppressed routes\n"
5620 "Name of route map\n")
596c17ba 5621
718e3744 5622DEFUN (no_neighbor_unsuppress_map,
5623 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5624 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5625 NO_STR
5626 NEIGHBOR_STR
5627 NEIGHBOR_ADDR_STR2
5628 "Route-map to selectively unsuppress suppressed routes\n"
5629 "Name of route map\n")
5630{
d62a17ae 5631 int idx_peer = 2;
5632 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5633 bgp_node_afi(vty),
5634 bgp_node_safi(vty));
718e3744 5635}
6b0655a2 5636
d62a17ae 5637ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5638 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5639 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5640 "Route-map to selectively unsuppress suppressed routes\n"
5641 "Name of route map\n")
596c17ba 5642
d62a17ae 5643static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5644 afi_t afi, safi_t safi,
5645 const char *num_str,
5646 const char *threshold_str, int warning,
5647 const char *restart_str)
718e3744 5648{
d62a17ae 5649 int ret;
5650 struct peer *peer;
5651 u_int32_t max;
5652 u_char threshold;
5653 u_int16_t restart;
718e3744 5654
d62a17ae 5655 peer = peer_and_group_lookup_vty(vty, ip_str);
5656 if (!peer)
5657 return CMD_WARNING_CONFIG_FAILED;
718e3744 5658
d62a17ae 5659 max = strtoul(num_str, NULL, 10);
5660 if (threshold_str)
5661 threshold = atoi(threshold_str);
5662 else
5663 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5664
d62a17ae 5665 if (restart_str)
5666 restart = atoi(restart_str);
5667 else
5668 restart = 0;
0a486e5f 5669
d62a17ae 5670 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5671 restart);
718e3744 5672
d62a17ae 5673 return bgp_vty_return(vty, ret);
718e3744 5674}
5675
d62a17ae 5676static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5677 afi_t afi, safi_t safi)
718e3744 5678{
d62a17ae 5679 int ret;
5680 struct peer *peer;
718e3744 5681
d62a17ae 5682 peer = peer_and_group_lookup_vty(vty, ip_str);
5683 if (!peer)
5684 return CMD_WARNING_CONFIG_FAILED;
718e3744 5685
d62a17ae 5686 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5687
d62a17ae 5688 return bgp_vty_return(vty, ret);
718e3744 5689}
5690
5691/* Maximum number of prefix configuration. prefix count is different
5692 for each peer configuration. So this configuration can be set for
5693 each peer configuration. */
5694DEFUN (neighbor_maximum_prefix,
5695 neighbor_maximum_prefix_cmd,
9ccf14f7 5696 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5697 NEIGHBOR_STR
5698 NEIGHBOR_ADDR_STR2
5699 "Maximum number of prefix accept from this peer\n"
5700 "maximum no. of prefix limit\n")
5701{
d62a17ae 5702 int idx_peer = 1;
5703 int idx_number = 3;
5704 return peer_maximum_prefix_set_vty(
5705 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5706 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5707}
5708
d62a17ae 5709ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5710 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5711 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5712 "Maximum number of prefix accept from this peer\n"
5713 "maximum no. of prefix limit\n")
596c17ba 5714
e0701b79 5715DEFUN (neighbor_maximum_prefix_threshold,
5716 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5717 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5718 NEIGHBOR_STR
5719 NEIGHBOR_ADDR_STR2
5720 "Maximum number of prefix accept from this peer\n"
5721 "maximum no. of prefix limit\n"
5722 "Threshold value (%) at which to generate a warning msg\n")
5723{
d62a17ae 5724 int idx_peer = 1;
5725 int idx_number = 3;
5726 int idx_number_2 = 4;
5727 return peer_maximum_prefix_set_vty(
5728 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5729 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5730}
e0701b79 5731
d62a17ae 5732ALIAS_HIDDEN(
5733 neighbor_maximum_prefix_threshold,
5734 neighbor_maximum_prefix_threshold_hidden_cmd,
5735 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5736 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5737 "Maximum number of prefix accept from this peer\n"
5738 "maximum no. of prefix limit\n"
5739 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5740
718e3744 5741DEFUN (neighbor_maximum_prefix_warning,
5742 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5743 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5744 NEIGHBOR_STR
5745 NEIGHBOR_ADDR_STR2
5746 "Maximum number of prefix accept from this peer\n"
5747 "maximum no. of prefix limit\n"
5748 "Only give warning message when limit is exceeded\n")
5749{
d62a17ae 5750 int idx_peer = 1;
5751 int idx_number = 3;
5752 return peer_maximum_prefix_set_vty(
5753 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5754 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5755}
5756
d62a17ae 5757ALIAS_HIDDEN(
5758 neighbor_maximum_prefix_warning,
5759 neighbor_maximum_prefix_warning_hidden_cmd,
5760 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5761 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5762 "Maximum number of prefix accept from this peer\n"
5763 "maximum no. of prefix limit\n"
5764 "Only give warning message when limit is exceeded\n")
596c17ba 5765
e0701b79 5766DEFUN (neighbor_maximum_prefix_threshold_warning,
5767 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5768 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5769 NEIGHBOR_STR
5770 NEIGHBOR_ADDR_STR2
5771 "Maximum number of prefix accept from this peer\n"
5772 "maximum no. of prefix limit\n"
5773 "Threshold value (%) at which to generate a warning msg\n"
5774 "Only give warning message when limit is exceeded\n")
5775{
d62a17ae 5776 int idx_peer = 1;
5777 int idx_number = 3;
5778 int idx_number_2 = 4;
5779 return peer_maximum_prefix_set_vty(
5780 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5781 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5782}
5783
d62a17ae 5784ALIAS_HIDDEN(
5785 neighbor_maximum_prefix_threshold_warning,
5786 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5787 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5788 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5789 "Maximum number of prefix accept from this peer\n"
5790 "maximum no. of prefix limit\n"
5791 "Threshold value (%) at which to generate a warning msg\n"
5792 "Only give warning message when limit is exceeded\n")
596c17ba 5793
0a486e5f 5794DEFUN (neighbor_maximum_prefix_restart,
5795 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5796 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5797 NEIGHBOR_STR
5798 NEIGHBOR_ADDR_STR2
5799 "Maximum number of prefix accept from this peer\n"
5800 "maximum no. of prefix limit\n"
5801 "Restart bgp connection after limit is exceeded\n"
efd7904e 5802 "Restart interval in minutes\n")
0a486e5f 5803{
d62a17ae 5804 int idx_peer = 1;
5805 int idx_number = 3;
5806 int idx_number_2 = 5;
5807 return peer_maximum_prefix_set_vty(
5808 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5809 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5810}
5811
d62a17ae 5812ALIAS_HIDDEN(
5813 neighbor_maximum_prefix_restart,
5814 neighbor_maximum_prefix_restart_hidden_cmd,
5815 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5816 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5817 "Maximum number of prefix accept from this peer\n"
5818 "maximum no. of prefix limit\n"
5819 "Restart bgp connection after limit is exceeded\n"
efd7904e 5820 "Restart interval in minutes\n")
596c17ba 5821
0a486e5f 5822DEFUN (neighbor_maximum_prefix_threshold_restart,
5823 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5824 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5825 NEIGHBOR_STR
5826 NEIGHBOR_ADDR_STR2
16cedbb0 5827 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5828 "maximum no. of prefix limit\n"
5829 "Threshold value (%) at which to generate a warning msg\n"
5830 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5831 "Restart interval in minutes\n")
0a486e5f 5832{
d62a17ae 5833 int idx_peer = 1;
5834 int idx_number = 3;
5835 int idx_number_2 = 4;
5836 int idx_number_3 = 6;
5837 return peer_maximum_prefix_set_vty(
5838 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5839 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5840 argv[idx_number_3]->arg);
5841}
5842
5843ALIAS_HIDDEN(
5844 neighbor_maximum_prefix_threshold_restart,
5845 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5846 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5847 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5848 "Maximum number of prefixes to accept from this peer\n"
5849 "maximum no. of prefix limit\n"
5850 "Threshold value (%) at which to generate a warning msg\n"
5851 "Restart bgp connection after limit is exceeded\n"
5852 "Restart interval in minutes\n")
596c17ba 5853
718e3744 5854DEFUN (no_neighbor_maximum_prefix,
5855 no_neighbor_maximum_prefix_cmd,
d04c479d 5856 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5857 NO_STR
5858 NEIGHBOR_STR
5859 NEIGHBOR_ADDR_STR2
16cedbb0 5860 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5861 "maximum no. of prefix limit\n"
5862 "Threshold value (%) at which to generate a warning msg\n"
5863 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5864 "Restart interval in minutes\n"
31500417 5865 "Only give warning message when limit is exceeded\n")
718e3744 5866{
d62a17ae 5867 int idx_peer = 2;
5868 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5869 bgp_node_afi(vty),
5870 bgp_node_safi(vty));
718e3744 5871}
e52702f2 5872
d62a17ae 5873ALIAS_HIDDEN(
5874 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5875 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5876 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5877 "Maximum number of prefixes to accept from this peer\n"
5878 "maximum no. of prefix limit\n"
5879 "Threshold value (%) at which to generate a warning msg\n"
5880 "Restart bgp connection after limit is exceeded\n"
5881 "Restart interval in minutes\n"
5882 "Only give warning message when limit is exceeded\n")
596c17ba 5883
718e3744 5884
718e3744 5885/* "neighbor allowas-in" */
5886DEFUN (neighbor_allowas_in,
5887 neighbor_allowas_in_cmd,
fd8503f5 5888 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5889 NEIGHBOR_STR
5890 NEIGHBOR_ADDR_STR2
31500417 5891 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5892 "Number of occurances of AS number\n"
5893 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5894{
d62a17ae 5895 int idx_peer = 1;
5896 int idx_number_origin = 3;
5897 int ret;
5898 int origin = 0;
5899 struct peer *peer;
5900 int allow_num = 0;
5901
5902 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5903 if (!peer)
5904 return CMD_WARNING_CONFIG_FAILED;
5905
5906 if (argc <= idx_number_origin)
5907 allow_num = 3;
5908 else {
5909 if (argv[idx_number_origin]->type == WORD_TKN)
5910 origin = 1;
5911 else
5912 allow_num = atoi(argv[idx_number_origin]->arg);
5913 }
5914
5915 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5916 allow_num, origin);
5917
5918 return bgp_vty_return(vty, ret);
5919}
5920
5921ALIAS_HIDDEN(
5922 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5923 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5924 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5925 "Accept as-path with my AS present in it\n"
5926 "Number of occurances of AS number\n"
5927 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5928
718e3744 5929DEFUN (no_neighbor_allowas_in,
5930 no_neighbor_allowas_in_cmd,
fd8503f5 5931 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5932 NO_STR
5933 NEIGHBOR_STR
5934 NEIGHBOR_ADDR_STR2
8334fd5a 5935 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
5936 "Number of occurances of AS number\n"
5937 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5938{
d62a17ae 5939 int idx_peer = 2;
5940 int ret;
5941 struct peer *peer;
718e3744 5942
d62a17ae 5943 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5944 if (!peer)
5945 return CMD_WARNING_CONFIG_FAILED;
718e3744 5946
d62a17ae 5947 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5948 bgp_node_safi(vty));
718e3744 5949
d62a17ae 5950 return bgp_vty_return(vty, ret);
718e3744 5951}
6b0655a2 5952
d62a17ae 5953ALIAS_HIDDEN(
5954 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5955 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5956 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5957 "allow local ASN appears in aspath attribute\n"
5958 "Number of occurances of AS number\n"
5959 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5960
fa411a21
NH
5961DEFUN (neighbor_ttl_security,
5962 neighbor_ttl_security_cmd,
a174be63 5963 "neighbor <A.B.C.D|X:X::X:X> ttl-security hops (1-254)",
fa411a21 5964 NEIGHBOR_STR
a174be63 5965 NEIGHBOR_ADDR_STR
16cedbb0 5966 "BGP ttl-security parameters\n"
d7fa34c1
QY
5967 "Specify the maximum number of hops to the BGP peer\n"
5968 "Number of hops to BGP peer\n")
fa411a21 5969{
d62a17ae 5970 int idx_peer = 1;
5971 int idx_number = 4;
5972 struct peer *peer;
5973 int gtsm_hops;
5974
5975 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5976 if (!peer)
5977 return CMD_WARNING_CONFIG_FAILED;
5978
5979 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
5980
d62a17ae 5981 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
5982}
5983
5984DEFUN (no_neighbor_ttl_security,
5985 no_neighbor_ttl_security_cmd,
a174be63 5986 "no neighbor <A.B.C.D|X:X::X:X> ttl-security hops (1-254)",
fa411a21
NH
5987 NO_STR
5988 NEIGHBOR_STR
a174be63 5989 NEIGHBOR_ADDR_STR
16cedbb0 5990 "BGP ttl-security parameters\n"
3a2d747c
QY
5991 "Specify the maximum number of hops to the BGP peer\n"
5992 "Number of hops to BGP peer\n")
fa411a21 5993{
d62a17ae 5994 int idx_peer = 2;
5995 struct peer *peer;
fa411a21 5996
d62a17ae 5997 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5998 if (!peer)
5999 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6000
d62a17ae 6001 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6002}
6b0655a2 6003
adbac85e
DW
6004DEFUN (neighbor_addpath_tx_all_paths,
6005 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6006 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6007 NEIGHBOR_STR
6008 NEIGHBOR_ADDR_STR2
6009 "Use addpath to advertise all paths to a neighbor\n")
6010{
d62a17ae 6011 int idx_peer = 1;
6012 struct peer *peer;
adbac85e 6013
d62a17ae 6014 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6015 if (!peer)
6016 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6017
d62a17ae 6018 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6019 bgp_node_safi(vty),
6020 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6021}
6022
d62a17ae 6023ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6024 neighbor_addpath_tx_all_paths_hidden_cmd,
6025 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6026 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6027 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6028
adbac85e
DW
6029DEFUN (no_neighbor_addpath_tx_all_paths,
6030 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6031 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6032 NO_STR
6033 NEIGHBOR_STR
6034 NEIGHBOR_ADDR_STR2
6035 "Use addpath to advertise all paths to a neighbor\n")
6036{
d62a17ae 6037 int idx_peer = 2;
6038 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6039 bgp_node_afi(vty), bgp_node_safi(vty),
6040 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6041}
6042
d62a17ae 6043ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6044 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6045 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6046 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6047 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6048
06370dac
DW
6049DEFUN (neighbor_addpath_tx_bestpath_per_as,
6050 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6051 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6052 NEIGHBOR_STR
6053 NEIGHBOR_ADDR_STR2
6054 "Use addpath to advertise the bestpath per each neighboring AS\n")
6055{
d62a17ae 6056 int idx_peer = 1;
6057 struct peer *peer;
06370dac 6058
d62a17ae 6059 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6060 if (!peer)
6061 return CMD_WARNING_CONFIG_FAILED;
06370dac 6062
d62a17ae 6063 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6064 bgp_node_safi(vty),
6065 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6066}
6067
d62a17ae 6068ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6069 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6070 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6071 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6072 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6073
06370dac
DW
6074DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6075 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6076 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6077 NO_STR
6078 NEIGHBOR_STR
6079 NEIGHBOR_ADDR_STR2
6080 "Use addpath to advertise the bestpath per each neighboring AS\n")
6081{
d62a17ae 6082 int idx_peer = 2;
6083 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6084 bgp_node_afi(vty), bgp_node_safi(vty),
6085 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6086}
6087
d62a17ae 6088ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6089 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6090 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6091 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6092 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6093
505e5056 6094DEFUN_NOSH (address_family_ipv4_safi,
718e3744 6095 address_family_ipv4_safi_cmd,
5b1f0f29 6096 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6097 "Enter Address Family command mode\n"
8c3deaae 6098 "Address Family\n"
b6ab5a3a 6099 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6100{
f51bae9c 6101
d62a17ae 6102 if (argc == 3) {
2131d5cf 6103 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6104 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
2131d5cf
LB
6105 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT &&
6106 safi != SAFI_UNICAST && safi != SAFI_MULTICAST) {
6107 vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n");
6108 return CMD_WARNING_CONFIG_FAILED;
6109 }
d62a17ae 6110 vty->node = bgp_node_type(AFI_IP, safi);
6111 } else
6112 vty->node = BGP_IPV4_NODE;
718e3744 6113
d62a17ae 6114 return CMD_SUCCESS;
718e3744 6115}
6116
505e5056 6117DEFUN_NOSH (address_family_ipv6_safi,
25ffbdc1 6118 address_family_ipv6_safi_cmd,
5b1f0f29 6119 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6120 "Enter Address Family command mode\n"
8c3deaae 6121 "Address Family\n"
b6ab5a3a 6122 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6123{
d62a17ae 6124 if (argc == 3) {
2131d5cf 6125 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6126 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
2131d5cf
LB
6127 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT &&
6128 safi != SAFI_UNICAST && safi != SAFI_MULTICAST) {
6129 vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n");
6130 return CMD_WARNING_CONFIG_FAILED;
6131 }
d62a17ae 6132 vty->node = bgp_node_type(AFI_IP6, safi);
6133 } else
6134 vty->node = BGP_IPV6_NODE;
25ffbdc1 6135
d62a17ae 6136 return CMD_SUCCESS;
25ffbdc1 6137}
718e3744 6138
d6902373 6139#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6140DEFUN_NOSH (address_family_vpnv4,
718e3744 6141 address_family_vpnv4_cmd,
8334fd5a 6142 "address-family vpnv4 [unicast]",
718e3744 6143 "Enter Address Family command mode\n"
8c3deaae 6144 "Address Family\n"
3a2d747c 6145 "Address Family modifier\n")
718e3744 6146{
d62a17ae 6147 vty->node = BGP_VPNV4_NODE;
6148 return CMD_SUCCESS;
718e3744 6149}
6150
505e5056 6151DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6152 address_family_vpnv6_cmd,
8334fd5a 6153 "address-family vpnv6 [unicast]",
8ecd3266 6154 "Enter Address Family command mode\n"
8c3deaae 6155 "Address Family\n"
3a2d747c 6156 "Address Family modifier\n")
8ecd3266 6157{
d62a17ae 6158 vty->node = BGP_VPNV6_NODE;
6159 return CMD_SUCCESS;
8ecd3266 6160}
c016b6c7 6161#endif
d6902373 6162
505e5056 6163DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6164 address_family_evpn_cmd,
7111c1a0 6165 "address-family l2vpn evpn",
4e0b7b6d 6166 "Enter Address Family command mode\n"
7111c1a0
QY
6167 "Address Family\n"
6168 "Address Family modifier\n")
4e0b7b6d 6169{
2131d5cf
LB
6170 VTY_DECLVAR_CONTEXT(bgp, bgp);
6171 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT) {
6172 vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n");
6173 return CMD_WARNING_CONFIG_FAILED;
6174 }
d62a17ae 6175 vty->node = BGP_EVPN_NODE;
6176 return CMD_SUCCESS;
4e0b7b6d
PG
6177}
6178
505e5056 6179DEFUN_NOSH (exit_address_family,
718e3744 6180 exit_address_family_cmd,
6181 "exit-address-family",
6182 "Exit from Address Family configuration mode\n")
6183{
d62a17ae 6184 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6185 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6186 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6187 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6188 || vty->node == BGP_EVPN_NODE)
6189 vty->node = BGP_NODE;
6190 return CMD_SUCCESS;
718e3744 6191}
6b0655a2 6192
8ad7271d 6193/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6194static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6195 const char *ip_str, afi_t afi, safi_t safi,
6196 struct prefix_rd *prd)
6197{
6198 int ret;
6199 struct prefix match;
6200 struct bgp_node *rn;
6201 struct bgp_node *rm;
6202 struct bgp *bgp;
6203 struct bgp_table *table;
6204 struct bgp_table *rib;
6205
6206 /* BGP structure lookup. */
6207 if (view_name) {
6208 bgp = bgp_lookup_by_name(view_name);
6209 if (bgp == NULL) {
6210 vty_out(vty, "%% Can't find BGP instance %s\n",
6211 view_name);
6212 return CMD_WARNING;
6213 }
6214 } else {
6215 bgp = bgp_get_default();
6216 if (bgp == NULL) {
6217 vty_out(vty, "%% No BGP process is configured\n");
6218 return CMD_WARNING;
6219 }
6220 }
6221
6222 /* Check IP address argument. */
6223 ret = str2prefix(ip_str, &match);
6224 if (!ret) {
6225 vty_out(vty, "%% address is malformed\n");
6226 return CMD_WARNING;
6227 }
6228
6229 match.family = afi2family(afi);
6230 rib = bgp->rib[afi][safi];
6231
6232 if (safi == SAFI_MPLS_VPN) {
6233 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6234 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6235 continue;
6236
6237 if ((table = rn->info) != NULL) {
6238 if ((rm = bgp_node_match(table, &match))
6239 != NULL) {
6240 if (rm->p.prefixlen
6241 == match.prefixlen) {
6242 SET_FLAG(rn->flags,
6243 BGP_NODE_USER_CLEAR);
6244 bgp_process(bgp, rm, afi, safi);
6245 }
6246 bgp_unlock_node(rm);
6247 }
6248 }
6249 }
6250 } else {
6251 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6252 if (rn->p.prefixlen == match.prefixlen) {
6253 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6254 bgp_process(bgp, rn, afi, safi);
6255 }
6256 bgp_unlock_node(rn);
6257 }
6258 }
6259
6260 return CMD_SUCCESS;
8ad7271d
DS
6261}
6262
b09b5ae0 6263/* one clear bgp command to rule them all */
718e3744 6264DEFUN (clear_ip_bgp_all,
6265 clear_ip_bgp_all_cmd,
c1a44e43 6266 "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 6267 CLEAR_STR
6268 IP_STR
6269 BGP_STR
838758ac 6270 BGP_INSTANCE_HELP_STR
510afcd6
DS
6271 BGP_AFI_HELP_STR
6272 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
6273 "Clear all peers\n"
6274 "BGP neighbor address to clear\n"
a80beece 6275 "BGP IPv6 neighbor to clear\n"
838758ac 6276 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
6277 "Clear peers with the AS number\n"
6278 "Clear all external peers\n"
718e3744 6279 "Clear all members of peer-group\n"
b09b5ae0 6280 "BGP peer-group name\n"
b09b5ae0
DW
6281 BGP_SOFT_STR
6282 BGP_SOFT_IN_STR
b09b5ae0
DW
6283 BGP_SOFT_OUT_STR
6284 BGP_SOFT_IN_STR
6285 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 6286 BGP_SOFT_OUT_STR)
718e3744 6287{
d62a17ae 6288 char *vrf = NULL;
6289
6290 afi_t afi = AFI_IP6;
6291 safi_t safi = SAFI_UNICAST;
6292 enum clear_sort clr_sort = clear_peer;
6293 enum bgp_clear_type clr_type;
6294 char *clr_arg = NULL;
6295
6296 int idx = 0;
6297
6298 /* clear [ip] bgp */
6299 if (argv_find(argv, argc, "ip", &idx))
6300 afi = AFI_IP;
6301
6302 /* [<view|vrf> VIEWVRFNAME] */
6303 if (argv_find(argv, argc, "view", &idx)
6304 || argv_find(argv, argc, "vrf", &idx)) {
6305 vrf = argv[idx + 1]->arg;
6306 idx += 2;
6307 }
6308
6309 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6310 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6311 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6312
6313 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6314 if (argv_find(argv, argc, "*", &idx)) {
6315 clr_sort = clear_all;
6316 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6317 clr_sort = clear_peer;
6318 clr_arg = argv[idx]->arg;
6319 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6320 clr_sort = clear_peer;
6321 clr_arg = argv[idx]->arg;
6322 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6323 clr_sort = clear_group;
6324 idx++;
6325 clr_arg = argv[idx]->arg;
6326 } else if (argv_find(argv, argc, "WORD", &idx)) {
6327 clr_sort = clear_peer;
6328 clr_arg = argv[idx]->arg;
6329 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6330 clr_sort = clear_as;
6331 clr_arg = argv[idx]->arg;
6332 } else if (argv_find(argv, argc, "external", &idx)) {
6333 clr_sort = clear_external;
6334 }
6335
6336 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6337 if (argv_find(argv, argc, "soft", &idx)) {
6338 if (argv_find(argv, argc, "in", &idx)
6339 || argv_find(argv, argc, "out", &idx))
6340 clr_type = strmatch(argv[idx]->text, "in")
6341 ? BGP_CLEAR_SOFT_IN
6342 : BGP_CLEAR_SOFT_OUT;
6343 else
6344 clr_type = BGP_CLEAR_SOFT_BOTH;
6345 } else if (argv_find(argv, argc, "in", &idx)) {
6346 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6347 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6348 : BGP_CLEAR_SOFT_IN;
6349 } else if (argv_find(argv, argc, "out", &idx)) {
6350 clr_type = BGP_CLEAR_SOFT_OUT;
6351 } else
6352 clr_type = BGP_CLEAR_SOFT_NONE;
6353
6354 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 6355}
01080f7c 6356
8ad7271d
DS
6357DEFUN (clear_ip_bgp_prefix,
6358 clear_ip_bgp_prefix_cmd,
18c57037 6359 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
6360 CLEAR_STR
6361 IP_STR
6362 BGP_STR
838758ac 6363 BGP_INSTANCE_HELP_STR
8ad7271d 6364 "Clear bestpath and re-advertise\n"
0c7b1b01 6365 "IPv4 prefix\n")
8ad7271d 6366{
d62a17ae 6367 char *vrf = NULL;
6368 char *prefix = NULL;
8ad7271d 6369
d62a17ae 6370 int idx = 0;
01080f7c 6371
d62a17ae 6372 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 6373 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 6374 vrf = argv[idx]->arg;
0c7b1b01 6375
d62a17ae 6376 prefix = argv[argc - 1]->arg;
8ad7271d 6377
d62a17ae 6378 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 6379}
8ad7271d 6380
b09b5ae0
DW
6381DEFUN (clear_bgp_ipv6_safi_prefix,
6382 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 6383 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6384 CLEAR_STR
3a2d747c 6385 IP_STR
718e3744 6386 BGP_STR
8c3deaae 6387 "Address Family\n"
46f296b4 6388 BGP_SAFI_HELP_STR
b09b5ae0 6389 "Clear bestpath and re-advertise\n"
0c7b1b01 6390 "IPv6 prefix\n")
718e3744 6391{
d62a17ae 6392 int idx_safi = 3;
6393 int idx_ipv6_prefixlen = 5;
6394 return bgp_clear_prefix(
6395 vty, NULL, argv[idx_ipv6_prefixlen]->arg, AFI_IP6,
6396 bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
838758ac 6397}
01080f7c 6398
b09b5ae0
DW
6399DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6400 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 6401 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6402 CLEAR_STR
3a2d747c 6403 IP_STR
718e3744 6404 BGP_STR
838758ac 6405 BGP_INSTANCE_HELP_STR
8c3deaae 6406 "Address Family\n"
46f296b4 6407 BGP_SAFI_HELP_STR
b09b5ae0 6408 "Clear bestpath and re-advertise\n"
0c7b1b01 6409 "IPv6 prefix\n")
718e3744 6410{
d62a17ae 6411 int idx_word = 3;
6412 int idx_safi = 5;
6413 int idx_ipv6_prefixlen = 7;
6414 return bgp_clear_prefix(
6415 vty, argv[idx_word]->arg, argv[idx_ipv6_prefixlen]->arg,
6416 AFI_IP6, bgp_vty_safi_from_str(argv[idx_safi]->text), NULL);
718e3744 6417}
6418
b09b5ae0
DW
6419DEFUN (show_bgp_views,
6420 show_bgp_views_cmd,
d6e3c605 6421 "show [ip] bgp views",
b09b5ae0 6422 SHOW_STR
d6e3c605 6423 IP_STR
01080f7c 6424 BGP_STR
b09b5ae0 6425 "Show the defined BGP views\n")
01080f7c 6426{
d62a17ae 6427 struct list *inst = bm->bgp;
6428 struct listnode *node;
6429 struct bgp *bgp;
01080f7c 6430
d62a17ae 6431 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6432 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6433 return CMD_WARNING;
6434 }
e52702f2 6435
d62a17ae 6436 vty_out(vty, "Defined BGP views:\n");
6437 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6438 /* Skip VRFs. */
6439 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6440 continue;
6441 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6442 bgp->as);
6443 }
e52702f2 6444
d62a17ae 6445 return CMD_SUCCESS;
e0081f70
ML
6446}
6447
8386ac43 6448DEFUN (show_bgp_vrfs,
6449 show_bgp_vrfs_cmd,
d6e3c605 6450 "show [ip] bgp vrfs [json]",
8386ac43 6451 SHOW_STR
d6e3c605 6452 IP_STR
8386ac43 6453 BGP_STR
6454 "Show BGP VRFs\n"
9973d184 6455 JSON_STR)
8386ac43 6456{
fe1dc5a3 6457 char buf[ETHER_ADDR_STRLEN];
d62a17ae 6458 struct list *inst = bm->bgp;
6459 struct listnode *node;
6460 struct bgp *bgp;
6461 u_char uj = use_json(argc, argv);
6462 json_object *json = NULL;
6463 json_object *json_vrfs = NULL;
6464 int count = 0;
d62a17ae 6465
6466 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6467 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6468 return CMD_WARNING;
6469 }
6470
6471 if (uj) {
6472 json = json_object_new_object();
6473 json_vrfs = json_object_new_object();
6474 }
6475
6476 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6477 const char *name, *type;
6478 struct peer *peer;
6479 struct listnode *node, *nnode;
6480 int peers_cfg, peers_estb;
6481 json_object *json_vrf = NULL;
d62a17ae 6482
6483 /* Skip Views. */
6484 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6485 continue;
6486
6487 count++;
6488 if (!uj && count == 1)
fe1dc5a3
MK
6489 vty_out(vty,
6490 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
6491 "Type", "Id", "routerId", "#PeersVfg",
6492 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 6493
6494 peers_cfg = peers_estb = 0;
6495 if (uj)
6496 json_vrf = json_object_new_object();
6497
6498
6499 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6500 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6501 continue;
6502 peers_cfg++;
6503 if (peer->status == Established)
6504 peers_estb++;
6505 }
6506
6507 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
6508 name = "Default";
6509 type = "DFLT";
6510 } else {
6511 name = bgp->name;
6512 type = "VRF";
6513 }
6514
a8bf7d9c 6515
d62a17ae 6516 if (uj) {
a8bf7d9c
PG
6517 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN) ? -1 :
6518 (int64_t)bgp->vrf_id;
d62a17ae 6519 json_object_string_add(json_vrf, "type", type);
6520 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
6521 json_object_string_add(json_vrf, "routerId",
6522 inet_ntoa(bgp->router_id));
6523 json_object_int_add(json_vrf, "numConfiguredPeers",
6524 peers_cfg);
6525 json_object_int_add(json_vrf, "numEstablishedPeers",
6526 peers_estb);
6527
fe1dc5a3
MK
6528 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
6529 json_object_string_add(json_vrf, "rmac",
6530 prefix_mac2str(&bgp->rmac, buf,
6531 sizeof(buf)));
d62a17ae 6532 json_object_object_add(json_vrfs, name, json_vrf);
6533 } else
fe1dc5a3
MK
6534 vty_out(vty,
6535 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a8bf7d9c
PG
6536 type, bgp->vrf_id == VRF_UNKNOWN ?
6537 -1 : (int)bgp->vrf_id,
6538 inet_ntoa(bgp->router_id),
fe1dc5a3
MK
6539 peers_cfg, peers_estb, name, bgp->l3vni,
6540 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 6541 }
6542
6543 if (uj) {
6544 json_object_object_add(json, "vrfs", json_vrfs);
6545
6546 json_object_int_add(json, "totalVrfs", count);
6547
9d303b37
DL
6548 vty_out(vty, "%s\n", json_object_to_json_string_ext(
6549 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 6550 json_object_free(json);
6551 } else {
6552 if (count)
6553 vty_out(vty,
6554 "\nTotal number of VRFs (including default): %d\n",
6555 count);
6556 }
6557
6558 return CMD_SUCCESS;
8386ac43 6559}
6560
acf71666
MK
6561static void show_address_entry(struct hash_backet *backet, void *args)
6562{
60466a63
QY
6563 struct vty *vty = (struct vty *)args;
6564 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 6565
60466a63 6566 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
6567 addr->refcnt);
6568}
6569
6570static void show_tip_entry(struct hash_backet *backet, void *args)
6571{
0291c246 6572 struct vty *vty = (struct vty *)args;
60466a63 6573 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 6574
60466a63 6575 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
6576 tip->refcnt);
6577}
6578
6579static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
6580{
6581 vty_out(vty, "self nexthop database:\n");
6582 hash_iterate(bgp->address_hash,
6583 (void (*)(struct hash_backet *, void *))show_address_entry,
6584 vty);
6585
6586 vty_out(vty, "Tunnel-ip database:\n");
6587 hash_iterate(bgp->tip_hash,
6588 (void (*)(struct hash_backet *, void *))show_tip_entry,
6589 vty);
6590}
6591
60466a63
QY
6592DEFUN(show_bgp_martian_nexthop_db,
6593 show_bgp_martian_nexthop_db_cmd,
6594 "show bgp martian next-hop",
6595 SHOW_STR
6596 BGP_STR
6597 "martian next-hops\n"
6598 "martian next-hop database\n")
acf71666 6599{
0291c246 6600 struct bgp *bgp = NULL;
acf71666
MK
6601
6602 bgp = bgp_get_default();
6603 if (!bgp) {
6604 vty_out(vty, "%% No BGP process is configured\n");
6605 return CMD_WARNING;
6606 }
6607 bgp_show_martian_nexthops(vty, bgp);
6608
6609 return CMD_SUCCESS;
6610}
6611
f412b39a 6612DEFUN (show_bgp_memory,
4bf6a362 6613 show_bgp_memory_cmd,
7fa12b13 6614 "show [ip] bgp memory",
4bf6a362 6615 SHOW_STR
3a2d747c 6616 IP_STR
4bf6a362
PJ
6617 BGP_STR
6618 "Global BGP memory statistics\n")
6619{
d62a17ae 6620 char memstrbuf[MTYPE_MEMSTR_LEN];
6621 unsigned long count;
6622
6623 /* RIB related usage stats */
6624 count = mtype_stats_alloc(MTYPE_BGP_NODE);
6625 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
6626 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6627 count * sizeof(struct bgp_node)));
6628
6629 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
6630 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
6631 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6632 count * sizeof(struct bgp_info)));
6633 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
6634 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
6635 count,
6636 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6637 count * sizeof(struct bgp_info_extra)));
6638
6639 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
6640 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
6641 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6642 count * sizeof(struct bgp_static)));
6643
6644 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
6645 vty_out(vty, "%ld Packets, using %s of memory\n", count,
6646 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6647 count * sizeof(struct bpacket)));
6648
6649 /* Adj-In/Out */
6650 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
6651 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
6652 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6653 count * sizeof(struct bgp_adj_in)));
6654 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
6655 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
6656 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6657 count * sizeof(struct bgp_adj_out)));
6658
6659 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
6660 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
6661 count,
6662 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6663 count * sizeof(struct bgp_nexthop_cache)));
6664
6665 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
6666 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
6667 count,
6668 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6669 count * sizeof(struct bgp_damp_info)));
6670
6671 /* Attributes */
6672 count = attr_count();
6673 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
6674 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6675 count * sizeof(struct attr)));
6676
6677 if ((count = attr_unknown_count()))
6678 vty_out(vty, "%ld unknown attributes\n", count);
6679
6680 /* AS_PATH attributes */
6681 count = aspath_count();
6682 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
6683 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6684 count * sizeof(struct aspath)));
6685
6686 count = mtype_stats_alloc(MTYPE_AS_SEG);
6687 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
6688 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6689 count * sizeof(struct assegment)));
6690
6691 /* Other attributes */
6692 if ((count = community_count()))
6693 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9d303b37
DL
6694 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6695 count * sizeof(struct community)));
d62a17ae 6696 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
6697 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
9d303b37
DL
6698 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6699 count * sizeof(struct ecommunity)));
d62a17ae 6700 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
6701 vty_out(vty,
6702 "%ld BGP large-community entries, using %s of memory\n",
9d303b37
DL
6703 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6704 count * sizeof(struct lcommunity)));
d62a17ae 6705
6706 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
6707 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
6708 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6709 count * sizeof(struct cluster_list)));
6710
6711 /* Peer related usage */
6712 count = mtype_stats_alloc(MTYPE_BGP_PEER);
6713 vty_out(vty, "%ld peers, using %s of memory\n", count,
6714 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6715 count * sizeof(struct peer)));
6716
6717 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
6718 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
6719 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6720 count * sizeof(struct peer_group)));
6721
6722 /* Other */
6723 if ((count = mtype_stats_alloc(MTYPE_HASH)))
6724 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
6725 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6726 count * sizeof(struct hash)));
6727 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
6728 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
6729 mtype_memstr(memstrbuf, sizeof(memstrbuf),
6730 count * sizeof(struct hash_backet)));
6731 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
6732 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
9d303b37
DL
6733 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
6734 count * sizeof(regex_t)));
d62a17ae 6735 return CMD_SUCCESS;
4bf6a362 6736}
fee0f4c6 6737
57a9c8a8
DS
6738static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
6739{
6740 json_object *bestpath = json_object_new_object();
6741
6742 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
6743 json_object_string_add(bestpath, "asPath", "ignore");
6744
6745 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
6746 json_object_string_add(bestpath, "asPath", "confed");
6747
6748 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
6749 if (bgp_flag_check(bgp,
6750 BGP_FLAG_MULTIPATH_RELAX_AS_SET))
6751 json_object_string_add(bestpath,
6752 "multiPathRelax",
6753 "as-set");
6754 else
6755 json_object_string_add(bestpath,
6756 "multiPathRelax",
6757 "true");
6758 } else
6759 json_object_string_add(bestpath,
6760 "multiPathRelax",
6761 "false");
6762
6763 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
6764 json_object_string_add(bestpath, "compareRouterId", "true");
6765 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
6766 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
6767 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
6768 json_object_string_add(bestpath, "med",
6769 "confed");
6770 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
6771 json_object_string_add(bestpath, "med",
6772 "missing-as-worst");
6773 else
6774 json_object_string_add(bestpath, "med", "true");
6775 }
6776
6777 json_object_object_add(json, "bestPath", bestpath);
6778}
6779
718e3744 6780/* Show BGP peer's summary information. */
d62a17ae 6781static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
6782 u_char use_json, json_object *json)
6783{
6784 struct peer *peer;
6785 struct listnode *node, *nnode;
6786 unsigned int count = 0, dn_count = 0;
6787 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
6788 char neighbor_buf[VTY_BUFSIZ];
6789 int neighbor_col_default_width = 16;
6790 int len;
6791 int max_neighbor_width = 0;
6792 int pfx_rcd_safi;
6793 json_object *json_peer = NULL;
6794 json_object *json_peers = NULL;
6795
6796 /* labeled-unicast routes are installed in the unicast table so in order
6797 * to
6798 * display the correct PfxRcd value we must look at SAFI_UNICAST
6799 */
6800 if (safi == SAFI_LABELED_UNICAST)
6801 pfx_rcd_safi = SAFI_UNICAST;
6802 else
6803 pfx_rcd_safi = safi;
6804
6805 if (use_json) {
6806 if (json == NULL)
6807 json = json_object_new_object();
6808
6809 json_peers = json_object_new_object();
6810 } else {
6811 /* Loop over all neighbors that will be displayed to determine
6812 * how many
6813 * characters are needed for the Neighbor column
6814 */
6815 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6816 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6817 continue;
6818
6819 if (peer->afc[afi][safi]) {
6820 memset(dn_flag, '\0', sizeof(dn_flag));
6821 if (peer_dynamic_neighbor(peer))
6822 dn_flag[0] = '*';
6823
6824 if (peer->hostname
6825 && bgp_flag_check(bgp,
6826 BGP_FLAG_SHOW_HOSTNAME))
6827 sprintf(neighbor_buf, "%s%s(%s) ",
6828 dn_flag, peer->hostname,
6829 peer->host);
6830 else
6831 sprintf(neighbor_buf, "%s%s ", dn_flag,
6832 peer->host);
6833
6834 len = strlen(neighbor_buf);
6835
6836 if (len > max_neighbor_width)
6837 max_neighbor_width = len;
6838 }
6839 }
f933309e 6840
d62a17ae 6841 /* Originally we displayed the Neighbor column as 16
6842 * characters wide so make that the default
6843 */
6844 if (max_neighbor_width < neighbor_col_default_width)
6845 max_neighbor_width = neighbor_col_default_width;
6846 }
f933309e 6847
d62a17ae 6848 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
6849 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
6850 continue;
6851
ea47320b
DL
6852 if (!peer->afc[afi][safi])
6853 continue;
d62a17ae 6854
ea47320b
DL
6855 if (!count) {
6856 unsigned long ents;
6857 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 6858 int64_t vrf_id_ui;
d62a17ae 6859
60466a63 6860 vrf_id_ui =
a8bf7d9c
PG
6861 (bgp->vrf_id == VRF_UNKNOWN) ? -1 :
6862 (int64_t)bgp->vrf_id;
ea47320b
DL
6863
6864 /* Usage summary and header */
6865 if (use_json) {
6866 json_object_string_add(
6867 json, "routerId",
6868 inet_ntoa(bgp->router_id));
60466a63
QY
6869 json_object_int_add(json, "as", bgp->as);
6870 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
6871 json_object_string_add(
6872 json, "vrfName",
6873 (bgp->inst_type
6874 == BGP_INSTANCE_TYPE_DEFAULT)
6875 ? "Default"
6876 : bgp->name);
6877 } else {
6878 vty_out(vty,
6879 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 6880 inet_ntoa(bgp->router_id), bgp->as,
a8bf7d9c
PG
6881 bgp->vrf_id == VRF_UNKNOWN ? -1 :
6882 (int)bgp->vrf_id);
ea47320b
DL
6883 vty_out(vty, "\n");
6884 }
d62a17ae 6885
ea47320b 6886 if (bgp_update_delay_configured(bgp)) {
d62a17ae 6887 if (use_json) {
ea47320b 6888 json_object_int_add(
60466a63 6889 json, "updateDelayLimit",
ea47320b 6890 bgp->v_update_delay);
d62a17ae 6891
ea47320b
DL
6892 if (bgp->v_update_delay
6893 != bgp->v_establish_wait)
d62a17ae 6894 json_object_int_add(
6895 json,
ea47320b
DL
6896 "updateDelayEstablishWait",
6897 bgp->v_establish_wait);
d62a17ae 6898
60466a63 6899 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
6900 json_object_string_add(
6901 json,
6902 "updateDelayFirstNeighbor",
6903 bgp->update_delay_begin_time);
6904 json_object_boolean_true_add(
6905 json,
6906 "updateDelayInProgress");
6907 } else {
6908 if (bgp->update_delay_over) {
d62a17ae 6909 json_object_string_add(
6910 json,
6911 "updateDelayFirstNeighbor",
6912 bgp->update_delay_begin_time);
ea47320b 6913 json_object_string_add(
d62a17ae 6914 json,
ea47320b
DL
6915 "updateDelayBestpathResumed",
6916 bgp->update_delay_end_time);
6917 json_object_string_add(
d62a17ae 6918 json,
ea47320b
DL
6919 "updateDelayZebraUpdateResume",
6920 bgp->update_delay_zebra_resume_time);
6921 json_object_string_add(
6922 json,
6923 "updateDelayPeerUpdateResume",
6924 bgp->update_delay_peers_resume_time);
d62a17ae 6925 }
ea47320b
DL
6926 }
6927 } else {
6928 vty_out(vty,
6929 "Read-only mode update-delay limit: %d seconds\n",
6930 bgp->v_update_delay);
6931 if (bgp->v_update_delay
6932 != bgp->v_establish_wait)
d62a17ae 6933 vty_out(vty,
ea47320b
DL
6934 " Establish wait: %d seconds\n",
6935 bgp->v_establish_wait);
d62a17ae 6936
60466a63 6937 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
6938 vty_out(vty,
6939 " First neighbor established: %s\n",
6940 bgp->update_delay_begin_time);
6941 vty_out(vty,
6942 " Delay in progress\n");
6943 } else {
6944 if (bgp->update_delay_over) {
d62a17ae 6945 vty_out(vty,
6946 " First neighbor established: %s\n",
6947 bgp->update_delay_begin_time);
6948 vty_out(vty,
ea47320b
DL
6949 " Best-paths resumed: %s\n",
6950 bgp->update_delay_end_time);
6951 vty_out(vty,
6952 " zebra update resumed: %s\n",
6953 bgp->update_delay_zebra_resume_time);
6954 vty_out(vty,
6955 " peers update resumed: %s\n",
6956 bgp->update_delay_peers_resume_time);
d62a17ae 6957 }
6958 }
6959 }
ea47320b 6960 }
d62a17ae 6961
ea47320b
DL
6962 if (use_json) {
6963 if (bgp_maxmed_onstartup_configured(bgp)
6964 && bgp->maxmed_active)
6965 json_object_boolean_true_add(
60466a63 6966 json, "maxMedOnStartup");
ea47320b
DL
6967 if (bgp->v_maxmed_admin)
6968 json_object_boolean_true_add(
60466a63 6969 json, "maxMedAdministrative");
d62a17ae 6970
ea47320b
DL
6971 json_object_int_add(
6972 json, "tableVersion",
60466a63 6973 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 6974
60466a63
QY
6975 ents = bgp_table_count(bgp->rib[afi][safi]);
6976 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
6977 json_object_int_add(
6978 json, "ribMemory",
6979 ents * sizeof(struct bgp_node));
d62a17ae 6980
ea47320b 6981 ents = listcount(bgp->peer);
60466a63
QY
6982 json_object_int_add(json, "peerCount", ents);
6983 json_object_int_add(json, "peerMemory",
6984 ents * sizeof(struct peer));
d62a17ae 6985
ea47320b
DL
6986 if ((ents = listcount(bgp->group))) {
6987 json_object_int_add(
60466a63 6988 json, "peerGroupCount", ents);
ea47320b
DL
6989 json_object_int_add(
6990 json, "peerGroupMemory",
6991 ents * sizeof(struct
6992 peer_group));
6993 }
d62a17ae 6994
ea47320b
DL
6995 if (CHECK_FLAG(bgp->af_flags[afi][safi],
6996 BGP_CONFIG_DAMPENING))
6997 json_object_boolean_true_add(
60466a63 6998 json, "dampeningEnabled");
ea47320b
DL
6999 } else {
7000 if (bgp_maxmed_onstartup_configured(bgp)
7001 && bgp->maxmed_active)
d62a17ae 7002 vty_out(vty,
ea47320b
DL
7003 "Max-med on-startup active\n");
7004 if (bgp->v_maxmed_admin)
d62a17ae 7005 vty_out(vty,
ea47320b 7006 "Max-med administrative active\n");
d62a17ae 7007
60466a63
QY
7008 vty_out(vty, "BGP table version %" PRIu64 "\n",
7009 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7010
60466a63 7011 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7012 vty_out(vty,
7013 "RIB entries %ld, using %s of memory\n",
7014 ents,
60466a63
QY
7015 mtype_memstr(memstrbuf,
7016 sizeof(memstrbuf),
7017 ents * sizeof(struct
7018 bgp_node)));
ea47320b
DL
7019
7020 /* Peer related usage */
7021 ents = listcount(bgp->peer);
60466a63 7022 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7023 ents,
7024 mtype_memstr(
60466a63
QY
7025 memstrbuf, sizeof(memstrbuf),
7026 ents * sizeof(struct peer)));
ea47320b
DL
7027
7028 if ((ents = listcount(bgp->group)))
d62a17ae 7029 vty_out(vty,
ea47320b 7030 "Peer groups %ld, using %s of memory\n",
d62a17ae 7031 ents,
7032 mtype_memstr(
7033 memstrbuf,
7034 sizeof(memstrbuf),
9d303b37 7035 ents * sizeof(struct
ea47320b 7036 peer_group)));
d62a17ae 7037
ea47320b
DL
7038 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7039 BGP_CONFIG_DAMPENING))
60466a63 7040 vty_out(vty, "Dampening enabled.\n");
ea47320b 7041 vty_out(vty, "\n");
d62a17ae 7042
ea47320b
DL
7043 /* Subtract 8 here because 'Neighbor' is
7044 * 8 characters */
7045 vty_out(vty, "Neighbor");
60466a63
QY
7046 vty_out(vty, "%*s", max_neighbor_width - 8,
7047 " ");
ea47320b
DL
7048 vty_out(vty,
7049 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7050 }
ea47320b 7051 }
d62a17ae 7052
ea47320b 7053 count++;
d62a17ae 7054
ea47320b
DL
7055 if (use_json) {
7056 json_peer = json_object_new_object();
d62a17ae 7057
ea47320b 7058 if (peer_dynamic_neighbor(peer))
60466a63
QY
7059 json_object_boolean_true_add(json_peer,
7060 "dynamicPeer");
d62a17ae 7061
ea47320b 7062 if (peer->hostname)
60466a63 7063 json_object_string_add(json_peer, "hostname",
ea47320b 7064 peer->hostname);
d62a17ae 7065
ea47320b 7066 if (peer->domainname)
60466a63
QY
7067 json_object_string_add(json_peer, "domainname",
7068 peer->domainname);
d62a17ae 7069
60466a63 7070 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7071 json_object_int_add(json_peer, "version", 4);
60466a63 7072 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7073 PEER_TOTAL_RX(peer));
60466a63 7074 json_object_int_add(json_peer, "msgSent",
0112e9e0 7075 PEER_TOTAL_TX(peer));
ea47320b
DL
7076
7077 json_object_int_add(json_peer, "tableVersion",
7078 peer->version[afi][safi]);
7079 json_object_int_add(json_peer, "outq",
7080 peer->obuf->count);
7081 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7082 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7083 use_json, json_peer);
7084 json_object_int_add(json_peer, "prefixReceivedCount",
7085 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7086
ea47320b 7087 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7088 json_object_string_add(json_peer, "state",
ea47320b 7089 "Idle (Admin)");
60466a63
QY
7090 else if (CHECK_FLAG(peer->sflags,
7091 PEER_STATUS_PREFIX_OVERFLOW))
7092 json_object_string_add(json_peer, "state",
ea47320b
DL
7093 "Idle (PfxCt)");
7094 else
7095 json_object_string_add(
7096 json_peer, "state",
60466a63
QY
7097 lookup_msg(bgp_status_msg, peer->status,
7098 NULL));
ea47320b
DL
7099
7100 if (peer->conf_if)
60466a63 7101 json_object_string_add(json_peer, "idType",
ea47320b
DL
7102 "interface");
7103 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7104 json_object_string_add(json_peer, "idType",
7105 "ipv4");
ea47320b 7106 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7107 json_object_string_add(json_peer, "idType",
7108 "ipv6");
d62a17ae 7109
ea47320b
DL
7110 json_object_object_add(json_peers, peer->host,
7111 json_peer);
7112 } else {
7113 memset(dn_flag, '\0', sizeof(dn_flag));
7114 if (peer_dynamic_neighbor(peer)) {
7115 dn_count++;
7116 dn_flag[0] = '*';
7117 }
d62a17ae 7118
ea47320b 7119 if (peer->hostname
60466a63 7120 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7121 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7122 peer->hostname, peer->host);
ea47320b 7123 else
60466a63 7124 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7125
7126 /* pad the neighbor column with spaces */
7127 if (len < max_neighbor_width)
60466a63
QY
7128 vty_out(vty, "%*s", max_neighbor_width - len,
7129 " ");
ea47320b 7130
86a55b99 7131 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7132 peer->as, PEER_TOTAL_RX(peer),
7133 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7134 0, peer->obuf->count,
d62a17ae 7135 peer_uptime(peer->uptime, timebuf,
ea47320b 7136 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7137
ea47320b 7138 if (peer->status == Established)
95077abf
DW
7139 if (peer->afc_recv[afi][pfx_rcd_safi])
7140 vty_out(vty, " %12ld",
7141 peer->pcount[afi][pfx_rcd_safi]);
7142 else
7143 vty_out(vty, " NoNeg");
ea47320b 7144 else {
60466a63 7145 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7146 vty_out(vty, " Idle (Admin)");
60466a63
QY
7147 else if (CHECK_FLAG(
7148 peer->sflags,
7149 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7150 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7151 else
ea47320b 7152 vty_out(vty, " %12s",
60466a63
QY
7153 lookup_msg(bgp_status_msg,
7154 peer->status, NULL));
d62a17ae 7155 }
ea47320b 7156 vty_out(vty, "\n");
d62a17ae 7157 }
7158 }
f933309e 7159
d62a17ae 7160 if (use_json) {
7161 json_object_object_add(json, "peers", json_peers);
7162
7163 json_object_int_add(json, "totalPeers", count);
7164 json_object_int_add(json, "dynamicPeers", dn_count);
7165
57a9c8a8
DS
7166 bgp_show_bestpath_json(bgp, json);
7167
9d303b37
DL
7168 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7169 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7170 json_object_free(json);
7171 } else {
7172 if (count)
7173 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7174 else {
7175 if (use_json)
7176 vty_out(vty,
7177 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7178 afi_safi_print(afi, safi));
7179 else
7180 vty_out(vty, "No %s neighbor is configured\n",
7181 afi_safi_print(afi, safi));
7182 }
b05a1c8b 7183
d62a17ae 7184 if (dn_count && !use_json) {
7185 vty_out(vty, "* - dynamic neighbor\n");
7186 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7187 dn_count, bgp->dynamic_neighbors_limit);
7188 }
7189 }
1ff9a340 7190
d62a17ae 7191 return CMD_SUCCESS;
718e3744 7192}
7193
d62a17ae 7194static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7195 int safi, u_char use_json,
7196 json_object *json)
7197{
7198 int is_first = 1;
7199 int afi_wildcard = (afi == AFI_MAX);
7200 int safi_wildcard = (safi == SAFI_MAX);
7201 int is_wildcard = (afi_wildcard || safi_wildcard);
7202 bool json_output = false;
7203
7204 if (use_json && is_wildcard)
7205 vty_out(vty, "{\n");
7206 if (afi_wildcard)
7207 afi = 1; /* AFI_IP */
7208 while (afi < AFI_MAX) {
7209 if (safi_wildcard)
7210 safi = 1; /* SAFI_UNICAST */
7211 while (safi < SAFI_MAX) {
318cac96 7212 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 7213 json_output = true;
7214 if (is_wildcard) {
7215 /*
7216 * So limit output to those afi/safi
7217 * pairs that
7218 * actualy have something interesting in
7219 * them
7220 */
7221 if (use_json) {
7222 json = json_object_new_object();
7223
7224 if (!is_first)
7225 vty_out(vty, ",\n");
7226 else
7227 is_first = 0;
7228
7229 vty_out(vty, "\"%s\":",
7230 afi_safi_json(afi,
7231 safi));
7232 } else {
7233 vty_out(vty, "\n%s Summary:\n",
7234 afi_safi_print(afi,
7235 safi));
7236 }
7237 }
7238 bgp_show_summary(vty, bgp, afi, safi, use_json,
7239 json);
7240 }
7241 safi++;
d62a17ae 7242 if (!safi_wildcard)
7243 safi = SAFI_MAX;
7244 }
7245 afi++;
7246 if (!afi_wildcard
7247 || afi == AFI_L2VPN) /* special case, not handled yet */
7248 afi = AFI_MAX;
7249 }
7250
7251 if (use_json && is_wildcard)
7252 vty_out(vty, "}\n");
7253 else if (use_json && !json_output)
7254 vty_out(vty, "{}\n");
7255}
7256
7257static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7258 safi_t safi, u_char use_json)
7259{
7260 struct listnode *node, *nnode;
7261 struct bgp *bgp;
7262 json_object *json = NULL;
7263 int is_first = 1;
7264
7265 if (use_json)
7266 vty_out(vty, "{\n");
7267
7268 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
7269 if (use_json) {
7270 json = json_object_new_object();
7271
7272 if (!is_first)
7273 vty_out(vty, ",\n");
7274 else
7275 is_first = 0;
7276
7277 vty_out(vty, "\"%s\":",
7278 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7279 ? "Default"
7280 : bgp->name);
7281 } else {
7282 vty_out(vty, "\nInstance %s:\n",
7283 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7284 ? "Default"
7285 : bgp->name);
7286 }
7287 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7288 }
7289
7290 if (use_json)
7291 vty_out(vty, "}\n");
7292}
7293
7294int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7295 safi_t safi, u_char use_json)
7296{
7297 struct bgp *bgp;
7298
7299 if (name) {
7300 if (strmatch(name, "all")) {
7301 bgp_show_all_instances_summary_vty(vty, afi, safi,
7302 use_json);
7303 return CMD_SUCCESS;
7304 } else {
7305 bgp = bgp_lookup_by_name(name);
7306
7307 if (!bgp) {
7308 if (use_json)
7309 vty_out(vty, "{}\n");
7310 else
7311 vty_out(vty,
7312 "%% No such BGP instance exist\n");
7313 return CMD_WARNING;
7314 }
7315
7316 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7317 NULL);
7318 return CMD_SUCCESS;
7319 }
7320 }
7321
7322 bgp = bgp_get_default();
7323
7324 if (bgp)
7325 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7326
7327 return CMD_SUCCESS;
4fb25c53
DW
7328}
7329
716b2d8a 7330/* `show [ip] bgp summary' commands. */
47fc97cc 7331DEFUN (show_ip_bgp_summary,
718e3744 7332 show_ip_bgp_summary_cmd,
dd6bd0f1 7333 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 7334 SHOW_STR
7335 IP_STR
7336 BGP_STR
8386ac43 7337 BGP_INSTANCE_HELP_STR
46f296b4 7338 BGP_AFI_HELP_STR
dd6bd0f1 7339 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 7340 "Summary of BGP neighbor status\n"
9973d184 7341 JSON_STR)
718e3744 7342{
d62a17ae 7343 char *vrf = NULL;
7344 afi_t afi = AFI_MAX;
7345 safi_t safi = SAFI_MAX;
7346
7347 int idx = 0;
7348
7349 /* show [ip] bgp */
7350 if (argv_find(argv, argc, "ip", &idx))
7351 afi = AFI_IP;
7352 /* [<view|vrf> VIEWVRFNAME] */
7353 if (argv_find(argv, argc, "view", &idx)
7354 || argv_find(argv, argc, "vrf", &idx))
7355 vrf = argv[++idx]->arg;
7356 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7357 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7358 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7359 }
7360
7361 int uj = use_json(argc, argv);
7362
7363 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7364}
7365
7366const char *afi_safi_print(afi_t afi, safi_t safi)
7367{
7368 if (afi == AFI_IP && safi == SAFI_UNICAST)
7369 return "IPv4 Unicast";
7370 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7371 return "IPv4 Multicast";
7372 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7373 return "IPv4 Labeled Unicast";
7374 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7375 return "IPv4 VPN";
7376 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7377 return "IPv4 Encap";
7378 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7379 return "IPv6 Unicast";
7380 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7381 return "IPv6 Multicast";
7382 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7383 return "IPv6 Labeled Unicast";
7384 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7385 return "IPv6 VPN";
7386 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7387 return "IPv6 Encap";
7388 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7389 return "L2VPN EVPN";
7390 else
7391 return "Unknown";
538621f2 7392}
7393
b9f77ec8
DS
7394/*
7395 * Please note that we have intentionally camelCased
7396 * the return strings here. So if you want
7397 * to use this function, please ensure you
7398 * are doing this within json output
7399 */
d62a17ae 7400const char *afi_safi_json(afi_t afi, safi_t safi)
7401{
7402 if (afi == AFI_IP && safi == SAFI_UNICAST)
7403 return "ipv4Unicast";
7404 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7405 return "ipv4Multicast";
7406 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7407 return "ipv4LabeledUnicast";
7408 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7409 return "ipv4Vpn";
7410 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7411 return "ipv4Encap";
7412 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7413 return "ipv6Unicast";
7414 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7415 return "ipv6Multicast";
7416 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7417 return "ipv6LabeledUnicast";
7418 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7419 return "ipv6Vpn";
7420 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7421 return "ipv6Encap";
7422 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7423 return "l2VpnEvpn";
7424 else
7425 return "Unknown";
27162734
LB
7426}
7427
718e3744 7428/* Show BGP peer's information. */
d62a17ae 7429enum show_type { show_all, show_peer };
7430
7431static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7432 afi_t afi, safi_t safi,
7433 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7434 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7435 u_char use_json, json_object *json_pref)
7436{
7437 /* Send-Mode */
7438 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7439 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7440 if (use_json) {
7441 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7442 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7443 json_object_string_add(json_pref, "sendMode",
7444 "advertisedAndReceived");
7445 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7446 json_object_string_add(json_pref, "sendMode",
7447 "advertised");
7448 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7449 json_object_string_add(json_pref, "sendMode",
7450 "received");
7451 } else {
7452 vty_out(vty, " Send-mode: ");
7453 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7454 vty_out(vty, "advertised");
7455 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7456 vty_out(vty, "%sreceived",
7457 CHECK_FLAG(p->af_cap[afi][safi],
7458 adv_smcap)
7459 ? ", "
7460 : "");
7461 vty_out(vty, "\n");
7462 }
7463 }
7464
7465 /* Receive-Mode */
7466 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7467 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
7468 if (use_json) {
7469 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7470 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7471 json_object_string_add(json_pref, "recvMode",
7472 "advertisedAndReceived");
7473 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7474 json_object_string_add(json_pref, "recvMode",
7475 "advertised");
7476 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7477 json_object_string_add(json_pref, "recvMode",
7478 "received");
7479 } else {
7480 vty_out(vty, " Receive-mode: ");
7481 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7482 vty_out(vty, "advertised");
7483 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7484 vty_out(vty, "%sreceived",
7485 CHECK_FLAG(p->af_cap[afi][safi],
7486 adv_rmcap)
7487 ? ", "
7488 : "");
7489 vty_out(vty, "\n");
7490 }
7491 }
7492}
7493
7494static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
7495 safi_t safi, u_char use_json,
7496 json_object *json_neigh)
7497{
0291c246
MK
7498 struct bgp_filter *filter;
7499 struct peer_af *paf;
7500 char orf_pfx_name[BUFSIZ];
7501 int orf_pfx_count;
7502 json_object *json_af = NULL;
7503 json_object *json_prefA = NULL;
7504 json_object *json_prefB = NULL;
7505 json_object *json_addr = NULL;
d62a17ae 7506
7507 if (use_json) {
7508 json_addr = json_object_new_object();
7509 json_af = json_object_new_object();
7510 filter = &p->filter[afi][safi];
7511
7512 if (peer_group_active(p))
7513 json_object_string_add(json_addr, "peerGroupMember",
7514 p->group->name);
7515
7516 paf = peer_af_find(p, afi, safi);
7517 if (paf && PAF_SUBGRP(paf)) {
7518 json_object_int_add(json_addr, "updateGroupId",
7519 PAF_UPDGRP(paf)->id);
7520 json_object_int_add(json_addr, "subGroupId",
7521 PAF_SUBGRP(paf)->id);
7522 json_object_int_add(json_addr, "packetQueueLength",
7523 bpacket_queue_virtual_length(paf));
7524 }
7525
7526 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7527 || CHECK_FLAG(p->af_cap[afi][safi],
7528 PEER_CAP_ORF_PREFIX_SM_RCV)
7529 || CHECK_FLAG(p->af_cap[afi][safi],
7530 PEER_CAP_ORF_PREFIX_RM_ADV)
7531 || CHECK_FLAG(p->af_cap[afi][safi],
7532 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7533 json_object_int_add(json_af, "orfType",
7534 ORF_TYPE_PREFIX);
7535 json_prefA = json_object_new_object();
7536 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
7537 PEER_CAP_ORF_PREFIX_SM_ADV,
7538 PEER_CAP_ORF_PREFIX_RM_ADV,
7539 PEER_CAP_ORF_PREFIX_SM_RCV,
7540 PEER_CAP_ORF_PREFIX_RM_RCV,
7541 use_json, json_prefA);
7542 json_object_object_add(json_af, "orfPrefixList",
7543 json_prefA);
7544 }
7545
7546 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7547 || CHECK_FLAG(p->af_cap[afi][safi],
7548 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7549 || CHECK_FLAG(p->af_cap[afi][safi],
7550 PEER_CAP_ORF_PREFIX_RM_ADV)
7551 || CHECK_FLAG(p->af_cap[afi][safi],
7552 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7553 json_object_int_add(json_af, "orfOldType",
7554 ORF_TYPE_PREFIX_OLD);
7555 json_prefB = json_object_new_object();
7556 bgp_show_peer_afi_orf_cap(
7557 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7558 PEER_CAP_ORF_PREFIX_RM_ADV,
7559 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7560 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
7561 json_prefB);
7562 json_object_object_add(json_af, "orfOldPrefixList",
7563 json_prefB);
7564 }
7565
7566 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7567 || CHECK_FLAG(p->af_cap[afi][safi],
7568 PEER_CAP_ORF_PREFIX_SM_RCV)
7569 || CHECK_FLAG(p->af_cap[afi][safi],
7570 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7571 || CHECK_FLAG(p->af_cap[afi][safi],
7572 PEER_CAP_ORF_PREFIX_RM_ADV)
7573 || CHECK_FLAG(p->af_cap[afi][safi],
7574 PEER_CAP_ORF_PREFIX_RM_RCV)
7575 || CHECK_FLAG(p->af_cap[afi][safi],
7576 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7577 json_object_object_add(json_addr, "afDependentCap",
7578 json_af);
7579 else
7580 json_object_free(json_af);
7581
7582 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7583 orf_pfx_count = prefix_bgp_show_prefix_list(
7584 NULL, afi, orf_pfx_name, use_json);
7585
7586 if (CHECK_FLAG(p->af_sflags[afi][safi],
7587 PEER_STATUS_ORF_PREFIX_SEND)
7588 || orf_pfx_count) {
7589 if (CHECK_FLAG(p->af_sflags[afi][safi],
7590 PEER_STATUS_ORF_PREFIX_SEND))
7591 json_object_boolean_true_add(json_neigh,
7592 "orfSent");
7593 if (orf_pfx_count)
7594 json_object_int_add(json_addr, "orfRecvCounter",
7595 orf_pfx_count);
7596 }
7597 if (CHECK_FLAG(p->af_sflags[afi][safi],
7598 PEER_STATUS_ORF_WAIT_REFRESH))
7599 json_object_string_add(
7600 json_addr, "orfFirstUpdate",
7601 "deferredUntilORFOrRouteRefreshRecvd");
7602
7603 if (CHECK_FLAG(p->af_flags[afi][safi],
7604 PEER_FLAG_REFLECTOR_CLIENT))
7605 json_object_boolean_true_add(json_addr,
7606 "routeReflectorClient");
7607 if (CHECK_FLAG(p->af_flags[afi][safi],
7608 PEER_FLAG_RSERVER_CLIENT))
7609 json_object_boolean_true_add(json_addr,
7610 "routeServerClient");
7611 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7612 json_object_boolean_true_add(json_addr,
7613 "inboundSoftConfigPermit");
7614
7615 if (CHECK_FLAG(p->af_flags[afi][safi],
7616 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7617 json_object_boolean_true_add(
7618 json_addr,
7619 "privateAsNumsAllReplacedInUpdatesToNbr");
7620 else if (CHECK_FLAG(p->af_flags[afi][safi],
7621 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7622 json_object_boolean_true_add(
7623 json_addr,
7624 "privateAsNumsReplacedInUpdatesToNbr");
7625 else if (CHECK_FLAG(p->af_flags[afi][safi],
7626 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7627 json_object_boolean_true_add(
7628 json_addr,
7629 "privateAsNumsAllRemovedInUpdatesToNbr");
7630 else if (CHECK_FLAG(p->af_flags[afi][safi],
7631 PEER_FLAG_REMOVE_PRIVATE_AS))
7632 json_object_boolean_true_add(
7633 json_addr,
7634 "privateAsNumsRemovedInUpdatesToNbr");
7635
7636 if (CHECK_FLAG(p->af_flags[afi][safi],
7637 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7638 json_object_boolean_true_add(json_addr,
7639 "addpathTxAllPaths");
7640
7641 if (CHECK_FLAG(p->af_flags[afi][safi],
7642 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7643 json_object_boolean_true_add(json_addr,
7644 "addpathTxBestpathPerAS");
7645
7646 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7647 json_object_string_add(json_addr,
7648 "overrideASNsInOutboundUpdates",
7649 "ifAspathEqualRemoteAs");
7650
7651 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7652 || CHECK_FLAG(p->af_flags[afi][safi],
7653 PEER_FLAG_FORCE_NEXTHOP_SELF))
7654 json_object_boolean_true_add(json_addr,
7655 "routerAlwaysNextHop");
7656 if (CHECK_FLAG(p->af_flags[afi][safi],
7657 PEER_FLAG_AS_PATH_UNCHANGED))
7658 json_object_boolean_true_add(
7659 json_addr, "unchangedAsPathPropogatedToNbr");
7660 if (CHECK_FLAG(p->af_flags[afi][safi],
7661 PEER_FLAG_NEXTHOP_UNCHANGED))
7662 json_object_boolean_true_add(
7663 json_addr, "unchangedNextHopPropogatedToNbr");
7664 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7665 json_object_boolean_true_add(
7666 json_addr, "unchangedMedPropogatedToNbr");
7667 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7668 || CHECK_FLAG(p->af_flags[afi][safi],
7669 PEER_FLAG_SEND_EXT_COMMUNITY)) {
7670 if (CHECK_FLAG(p->af_flags[afi][safi],
7671 PEER_FLAG_SEND_COMMUNITY)
7672 && CHECK_FLAG(p->af_flags[afi][safi],
7673 PEER_FLAG_SEND_EXT_COMMUNITY))
7674 json_object_string_add(json_addr,
7675 "commAttriSentToNbr",
7676 "extendedAndStandard");
7677 else if (CHECK_FLAG(p->af_flags[afi][safi],
7678 PEER_FLAG_SEND_EXT_COMMUNITY))
7679 json_object_string_add(json_addr,
7680 "commAttriSentToNbr",
7681 "extended");
7682 else
7683 json_object_string_add(json_addr,
7684 "commAttriSentToNbr",
7685 "standard");
7686 }
7687 if (CHECK_FLAG(p->af_flags[afi][safi],
7688 PEER_FLAG_DEFAULT_ORIGINATE)) {
7689 if (p->default_rmap[afi][safi].name)
7690 json_object_string_add(
7691 json_addr, "defaultRouteMap",
7692 p->default_rmap[afi][safi].name);
7693
7694 if (paf && PAF_SUBGRP(paf)
7695 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7696 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7697 json_object_boolean_true_add(json_addr,
7698 "defaultSent");
7699 else
7700 json_object_boolean_true_add(json_addr,
7701 "defaultNotSent");
7702 }
7703
dff8f48d 7704 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 7705 if (is_evpn_enabled())
60466a63
QY
7706 json_object_boolean_true_add(
7707 json_addr, "advertiseAllVnis");
dff8f48d
MK
7708 }
7709
d62a17ae 7710 if (filter->plist[FILTER_IN].name
7711 || filter->dlist[FILTER_IN].name
7712 || filter->aslist[FILTER_IN].name
7713 || filter->map[RMAP_IN].name)
7714 json_object_boolean_true_add(json_addr,
7715 "inboundPathPolicyConfig");
7716 if (filter->plist[FILTER_OUT].name
7717 || filter->dlist[FILTER_OUT].name
7718 || filter->aslist[FILTER_OUT].name
7719 || filter->map[RMAP_OUT].name || filter->usmap.name)
7720 json_object_boolean_true_add(
7721 json_addr, "outboundPathPolicyConfig");
7722
7723 /* prefix-list */
7724 if (filter->plist[FILTER_IN].name)
7725 json_object_string_add(json_addr,
7726 "incomingUpdatePrefixFilterList",
7727 filter->plist[FILTER_IN].name);
7728 if (filter->plist[FILTER_OUT].name)
7729 json_object_string_add(json_addr,
7730 "outgoingUpdatePrefixFilterList",
7731 filter->plist[FILTER_OUT].name);
7732
7733 /* distribute-list */
7734 if (filter->dlist[FILTER_IN].name)
7735 json_object_string_add(
7736 json_addr, "incomingUpdateNetworkFilterList",
7737 filter->dlist[FILTER_IN].name);
7738 if (filter->dlist[FILTER_OUT].name)
7739 json_object_string_add(
7740 json_addr, "outgoingUpdateNetworkFilterList",
7741 filter->dlist[FILTER_OUT].name);
7742
7743 /* filter-list. */
7744 if (filter->aslist[FILTER_IN].name)
7745 json_object_string_add(json_addr,
7746 "incomingUpdateAsPathFilterList",
7747 filter->aslist[FILTER_IN].name);
7748 if (filter->aslist[FILTER_OUT].name)
7749 json_object_string_add(json_addr,
7750 "outgoingUpdateAsPathFilterList",
7751 filter->aslist[FILTER_OUT].name);
7752
7753 /* route-map. */
7754 if (filter->map[RMAP_IN].name)
7755 json_object_string_add(
7756 json_addr, "routeMapForIncomingAdvertisements",
7757 filter->map[RMAP_IN].name);
7758 if (filter->map[RMAP_OUT].name)
7759 json_object_string_add(
7760 json_addr, "routeMapForOutgoingAdvertisements",
7761 filter->map[RMAP_OUT].name);
7762
7763 /* unsuppress-map */
7764 if (filter->usmap.name)
7765 json_object_string_add(json_addr,
7766 "selectiveUnsuppressRouteMap",
7767 filter->usmap.name);
7768
7769 /* Receive prefix count */
7770 json_object_int_add(json_addr, "acceptedPrefixCounter",
7771 p->pcount[afi][safi]);
7772
7773 /* Maximum prefix */
7774 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
7775 json_object_int_add(json_addr, "prefixAllowedMax",
7776 p->pmax[afi][safi]);
7777 if (CHECK_FLAG(p->af_flags[afi][safi],
7778 PEER_FLAG_MAX_PREFIX_WARNING))
7779 json_object_boolean_true_add(
7780 json_addr, "prefixAllowedMaxWarning");
7781 json_object_int_add(json_addr,
7782 "prefixAllowedWarningThresh",
7783 p->pmax_threshold[afi][safi]);
7784 if (p->pmax_restart[afi][safi])
7785 json_object_int_add(
7786 json_addr,
7787 "prefixAllowedRestartIntervalMsecs",
7788 p->pmax_restart[afi][safi] * 60000);
7789 }
7790 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
7791 json_addr);
7792
7793 } else {
7794 filter = &p->filter[afi][safi];
7795
7796 vty_out(vty, " For address family: %s\n",
7797 afi_safi_print(afi, safi));
7798
7799 if (peer_group_active(p))
7800 vty_out(vty, " %s peer-group member\n",
7801 p->group->name);
7802
7803 paf = peer_af_find(p, afi, safi);
7804 if (paf && PAF_SUBGRP(paf)) {
9d303b37
DL
7805 vty_out(vty, " Update group %" PRIu64
7806 ", subgroup %" PRIu64 "\n",
d62a17ae 7807 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
7808 vty_out(vty, " Packet Queue length %d\n",
7809 bpacket_queue_virtual_length(paf));
7810 } else {
7811 vty_out(vty, " Not part of any update group\n");
7812 }
7813 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7814 || CHECK_FLAG(p->af_cap[afi][safi],
7815 PEER_CAP_ORF_PREFIX_SM_RCV)
7816 || CHECK_FLAG(p->af_cap[afi][safi],
7817 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7818 || CHECK_FLAG(p->af_cap[afi][safi],
7819 PEER_CAP_ORF_PREFIX_RM_ADV)
7820 || CHECK_FLAG(p->af_cap[afi][safi],
7821 PEER_CAP_ORF_PREFIX_RM_RCV)
7822 || CHECK_FLAG(p->af_cap[afi][safi],
7823 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
7824 vty_out(vty, " AF-dependant capabilities:\n");
7825
7826 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7827 || CHECK_FLAG(p->af_cap[afi][safi],
7828 PEER_CAP_ORF_PREFIX_SM_RCV)
7829 || CHECK_FLAG(p->af_cap[afi][safi],
7830 PEER_CAP_ORF_PREFIX_RM_ADV)
7831 || CHECK_FLAG(p->af_cap[afi][safi],
7832 PEER_CAP_ORF_PREFIX_RM_RCV)) {
7833 vty_out(vty,
7834 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7835 ORF_TYPE_PREFIX);
7836 bgp_show_peer_afi_orf_cap(
7837 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7838 PEER_CAP_ORF_PREFIX_RM_ADV,
7839 PEER_CAP_ORF_PREFIX_SM_RCV,
7840 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
7841 }
7842 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
7843 || CHECK_FLAG(p->af_cap[afi][safi],
7844 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
7845 || CHECK_FLAG(p->af_cap[afi][safi],
7846 PEER_CAP_ORF_PREFIX_RM_ADV)
7847 || CHECK_FLAG(p->af_cap[afi][safi],
7848 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
7849 vty_out(vty,
7850 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
7851 ORF_TYPE_PREFIX_OLD);
7852 bgp_show_peer_afi_orf_cap(
7853 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
7854 PEER_CAP_ORF_PREFIX_RM_ADV,
7855 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
7856 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
7857 }
7858
7859 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
7860 orf_pfx_count = prefix_bgp_show_prefix_list(
7861 NULL, afi, orf_pfx_name, use_json);
7862
7863 if (CHECK_FLAG(p->af_sflags[afi][safi],
7864 PEER_STATUS_ORF_PREFIX_SEND)
7865 || orf_pfx_count) {
7866 vty_out(vty, " Outbound Route Filter (ORF):");
7867 if (CHECK_FLAG(p->af_sflags[afi][safi],
7868 PEER_STATUS_ORF_PREFIX_SEND))
7869 vty_out(vty, " sent;");
7870 if (orf_pfx_count)
7871 vty_out(vty, " received (%d entries)",
7872 orf_pfx_count);
7873 vty_out(vty, "\n");
7874 }
7875 if (CHECK_FLAG(p->af_sflags[afi][safi],
7876 PEER_STATUS_ORF_WAIT_REFRESH))
7877 vty_out(vty,
7878 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
7879
7880 if (CHECK_FLAG(p->af_flags[afi][safi],
7881 PEER_FLAG_REFLECTOR_CLIENT))
7882 vty_out(vty, " Route-Reflector Client\n");
7883 if (CHECK_FLAG(p->af_flags[afi][safi],
7884 PEER_FLAG_RSERVER_CLIENT))
7885 vty_out(vty, " Route-Server Client\n");
7886 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7887 vty_out(vty,
7888 " Inbound soft reconfiguration allowed\n");
7889
7890 if (CHECK_FLAG(p->af_flags[afi][safi],
7891 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
7892 vty_out(vty,
7893 " Private AS numbers (all) replaced in updates to this neighbor\n");
7894 else if (CHECK_FLAG(p->af_flags[afi][safi],
7895 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
7896 vty_out(vty,
7897 " Private AS numbers replaced in updates to this neighbor\n");
7898 else if (CHECK_FLAG(p->af_flags[afi][safi],
7899 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
7900 vty_out(vty,
7901 " Private AS numbers (all) removed in updates to this neighbor\n");
7902 else if (CHECK_FLAG(p->af_flags[afi][safi],
7903 PEER_FLAG_REMOVE_PRIVATE_AS))
7904 vty_out(vty,
7905 " Private AS numbers removed in updates to this neighbor\n");
7906
7907 if (CHECK_FLAG(p->af_flags[afi][safi],
7908 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
7909 vty_out(vty, " Advertise all paths via addpath\n");
7910
7911 if (CHECK_FLAG(p->af_flags[afi][safi],
7912 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
7913 vty_out(vty,
7914 " Advertise bestpath per AS via addpath\n");
7915
7916 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
7917 vty_out(vty,
7918 " Override ASNs in outbound updates if aspath equals remote-as\n");
7919
7920 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
7921 || CHECK_FLAG(p->af_flags[afi][safi],
7922 PEER_FLAG_FORCE_NEXTHOP_SELF))
7923 vty_out(vty, " NEXT_HOP is always this router\n");
7924 if (CHECK_FLAG(p->af_flags[afi][safi],
7925 PEER_FLAG_AS_PATH_UNCHANGED))
7926 vty_out(vty,
7927 " AS_PATH is propagated unchanged to this neighbor\n");
7928 if (CHECK_FLAG(p->af_flags[afi][safi],
7929 PEER_FLAG_NEXTHOP_UNCHANGED))
7930 vty_out(vty,
7931 " NEXT_HOP is propagated unchanged to this neighbor\n");
7932 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
7933 vty_out(vty,
7934 " MED is propagated unchanged to this neighbor\n");
7935 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
7936 || CHECK_FLAG(p->af_flags[afi][safi],
7937 PEER_FLAG_SEND_EXT_COMMUNITY)
7938 || CHECK_FLAG(p->af_flags[afi][safi],
7939 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
7940 vty_out(vty,
7941 " Community attribute sent to this neighbor");
7942 if (CHECK_FLAG(p->af_flags[afi][safi],
7943 PEER_FLAG_SEND_COMMUNITY)
7944 && CHECK_FLAG(p->af_flags[afi][safi],
7945 PEER_FLAG_SEND_EXT_COMMUNITY)
7946 && CHECK_FLAG(p->af_flags[afi][safi],
7947 PEER_FLAG_SEND_LARGE_COMMUNITY))
7948 vty_out(vty, "(all)\n");
7949 else if (CHECK_FLAG(p->af_flags[afi][safi],
7950 PEER_FLAG_SEND_LARGE_COMMUNITY))
7951 vty_out(vty, "(large)\n");
7952 else if (CHECK_FLAG(p->af_flags[afi][safi],
7953 PEER_FLAG_SEND_EXT_COMMUNITY))
7954 vty_out(vty, "(extended)\n");
7955 else
7956 vty_out(vty, "(standard)\n");
7957 }
7958 if (CHECK_FLAG(p->af_flags[afi][safi],
7959 PEER_FLAG_DEFAULT_ORIGINATE)) {
7960 vty_out(vty, " Default information originate,");
7961
7962 if (p->default_rmap[afi][safi].name)
7963 vty_out(vty, " default route-map %s%s,",
7964 p->default_rmap[afi][safi].map ? "*"
7965 : "",
7966 p->default_rmap[afi][safi].name);
7967 if (paf && PAF_SUBGRP(paf)
7968 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
7969 SUBGRP_STATUS_DEFAULT_ORIGINATE))
7970 vty_out(vty, " default sent\n");
7971 else
7972 vty_out(vty, " default not sent\n");
7973 }
7974
dff8f48d
MK
7975 /* advertise-vni-all */
7976 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 7977 if (is_evpn_enabled())
dff8f48d
MK
7978 vty_out(vty, " advertise-all-vni\n");
7979 }
7980
d62a17ae 7981 if (filter->plist[FILTER_IN].name
7982 || filter->dlist[FILTER_IN].name
7983 || filter->aslist[FILTER_IN].name
7984 || filter->map[RMAP_IN].name)
7985 vty_out(vty, " Inbound path policy configured\n");
7986 if (filter->plist[FILTER_OUT].name
7987 || filter->dlist[FILTER_OUT].name
7988 || filter->aslist[FILTER_OUT].name
7989 || filter->map[RMAP_OUT].name || filter->usmap.name)
7990 vty_out(vty, " Outbound path policy configured\n");
7991
7992 /* prefix-list */
7993 if (filter->plist[FILTER_IN].name)
7994 vty_out(vty,
7995 " Incoming update prefix filter list is %s%s\n",
7996 filter->plist[FILTER_IN].plist ? "*" : "",
7997 filter->plist[FILTER_IN].name);
7998 if (filter->plist[FILTER_OUT].name)
7999 vty_out(vty,
8000 " Outgoing update prefix filter list is %s%s\n",
8001 filter->plist[FILTER_OUT].plist ? "*" : "",
8002 filter->plist[FILTER_OUT].name);
8003
8004 /* distribute-list */
8005 if (filter->dlist[FILTER_IN].name)
8006 vty_out(vty,
8007 " Incoming update network filter list is %s%s\n",
8008 filter->dlist[FILTER_IN].alist ? "*" : "",
8009 filter->dlist[FILTER_IN].name);
8010 if (filter->dlist[FILTER_OUT].name)
8011 vty_out(vty,
8012 " Outgoing update network filter list is %s%s\n",
8013 filter->dlist[FILTER_OUT].alist ? "*" : "",
8014 filter->dlist[FILTER_OUT].name);
8015
8016 /* filter-list. */
8017 if (filter->aslist[FILTER_IN].name)
8018 vty_out(vty,
8019 " Incoming update AS path filter list is %s%s\n",
8020 filter->aslist[FILTER_IN].aslist ? "*" : "",
8021 filter->aslist[FILTER_IN].name);
8022 if (filter->aslist[FILTER_OUT].name)
8023 vty_out(vty,
8024 " Outgoing update AS path filter list is %s%s\n",
8025 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8026 filter->aslist[FILTER_OUT].name);
8027
8028 /* route-map. */
8029 if (filter->map[RMAP_IN].name)
8030 vty_out(vty,
8031 " Route map for incoming advertisements is %s%s\n",
8032 filter->map[RMAP_IN].map ? "*" : "",
8033 filter->map[RMAP_IN].name);
8034 if (filter->map[RMAP_OUT].name)
8035 vty_out(vty,
8036 " Route map for outgoing advertisements is %s%s\n",
8037 filter->map[RMAP_OUT].map ? "*" : "",
8038 filter->map[RMAP_OUT].name);
8039
8040 /* unsuppress-map */
8041 if (filter->usmap.name)
8042 vty_out(vty,
8043 " Route map for selective unsuppress is %s%s\n",
8044 filter->usmap.map ? "*" : "",
8045 filter->usmap.name);
8046
8047 /* Receive prefix count */
8048 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8049
8050 /* Maximum prefix */
8051 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8052 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8053 p->pmax[afi][safi],
8054 CHECK_FLAG(p->af_flags[afi][safi],
8055 PEER_FLAG_MAX_PREFIX_WARNING)
8056 ? " (warning-only)"
8057 : "");
8058 vty_out(vty, " Threshold for warning message %d%%",
8059 p->pmax_threshold[afi][safi]);
8060 if (p->pmax_restart[afi][safi])
8061 vty_out(vty, ", restart interval %d min",
8062 p->pmax_restart[afi][safi]);
8063 vty_out(vty, "\n");
8064 }
8065
8066 vty_out(vty, "\n");
8067 }
8068}
8069
8070static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
8071 json_object *json)
718e3744 8072{
d62a17ae 8073 struct bgp *bgp;
8074 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8075 char timebuf[BGP_UPTIME_LEN];
8076 char dn_flag[2];
8077 const char *subcode_str;
8078 const char *code_str;
8079 afi_t afi;
8080 safi_t safi;
8081 u_int16_t i;
8082 u_char *msg;
8083 json_object *json_neigh = NULL;
8084 time_t epoch_tbuf;
718e3744 8085
d62a17ae 8086 bgp = p->bgp;
8087
8088 if (use_json)
8089 json_neigh = json_object_new_object();
8090
8091 memset(dn_flag, '\0', sizeof(dn_flag));
8092 if (!p->conf_if && peer_dynamic_neighbor(p))
8093 dn_flag[0] = '*';
8094
8095 if (!use_json) {
8096 if (p->conf_if) /* Configured interface name. */
8097 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8098 BGP_PEER_SU_UNSPEC(p)
8099 ? "None"
8100 : sockunion2str(&p->su, buf,
8101 SU_ADDRSTRLEN));
8102 else /* Configured IP address. */
8103 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8104 p->host);
8105 }
8106
8107 if (use_json) {
8108 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8109 json_object_string_add(json_neigh, "bgpNeighborAddr",
8110 "none");
8111 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8112 json_object_string_add(
8113 json_neigh, "bgpNeighborAddr",
8114 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8115
8116 json_object_int_add(json_neigh, "remoteAs", p->as);
8117
8118 if (p->change_local_as)
8119 json_object_int_add(json_neigh, "localAs",
8120 p->change_local_as);
8121 else
8122 json_object_int_add(json_neigh, "localAs", p->local_as);
8123
8124 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8125 json_object_boolean_true_add(json_neigh,
8126 "localAsNoPrepend");
8127
8128 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8129 json_object_boolean_true_add(json_neigh,
8130 "localAsReplaceAs");
8131 } else {
8132 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8133 || (p->as_type == AS_INTERNAL))
8134 vty_out(vty, "remote AS %u, ", p->as);
8135 else
8136 vty_out(vty, "remote AS Unspecified, ");
8137 vty_out(vty, "local AS %u%s%s, ",
8138 p->change_local_as ? p->change_local_as : p->local_as,
8139 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8140 ? " no-prepend"
8141 : "",
8142 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8143 ? " replace-as"
8144 : "");
8145 }
8146 /* peer type internal, external, confed-internal or confed-external */
8147 if (p->as == p->local_as) {
8148 if (use_json) {
8149 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8150 json_object_boolean_true_add(
8151 json_neigh, "nbrConfedInternalLink");
8152 else
8153 json_object_boolean_true_add(json_neigh,
8154 "nbrInternalLink");
8155 } else {
8156 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8157 vty_out(vty, "confed-internal link\n");
8158 else
8159 vty_out(vty, "internal link\n");
8160 }
8161 } else {
8162 if (use_json) {
8163 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8164 json_object_boolean_true_add(
8165 json_neigh, "nbrConfedExternalLink");
8166 else
8167 json_object_boolean_true_add(json_neigh,
8168 "nbrExternalLink");
8169 } else {
8170 if (bgp_confederation_peers_check(bgp, p->as))
8171 vty_out(vty, "confed-external link\n");
8172 else
8173 vty_out(vty, "external link\n");
8174 }
8175 }
8176
8177 /* Description. */
8178 if (p->desc) {
8179 if (use_json)
8180 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8181 else
8182 vty_out(vty, " Description: %s\n", p->desc);
8183 }
8184
8185 if (p->hostname) {
8186 if (use_json) {
8187 if (p->hostname)
8188 json_object_string_add(json_neigh, "hostname",
8189 p->hostname);
8190
8191 if (p->domainname)
8192 json_object_string_add(json_neigh, "domainname",
8193 p->domainname);
8194 } else {
8195 if (p->domainname && (p->domainname[0] != '\0'))
8196 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8197 p->domainname);
8198 else
8199 vty_out(vty, "Hostname: %s\n", p->hostname);
8200 }
8201 }
8202
8203 /* Peer-group */
8204 if (p->group) {
8205 if (use_json) {
8206 json_object_string_add(json_neigh, "peerGroup",
8207 p->group->name);
8208
8209 if (dn_flag[0]) {
8210 struct prefix prefix, *range = NULL;
8211
8212 sockunion2hostprefix(&(p->su), &prefix);
8213 range = peer_group_lookup_dynamic_neighbor_range(
8214 p->group, &prefix);
8215
8216 if (range) {
8217 prefix2str(range, buf1, sizeof(buf1));
8218 json_object_string_add(
8219 json_neigh,
8220 "peerSubnetRangeGroup", buf1);
8221 }
8222 }
8223 } else {
8224 vty_out(vty,
8225 " Member of peer-group %s for session parameters\n",
8226 p->group->name);
8227
8228 if (dn_flag[0]) {
8229 struct prefix prefix, *range = NULL;
8230
8231 sockunion2hostprefix(&(p->su), &prefix);
8232 range = peer_group_lookup_dynamic_neighbor_range(
8233 p->group, &prefix);
8234
8235 if (range) {
8236 prefix2str(range, buf1, sizeof(buf1));
8237 vty_out(vty,
8238 " Belongs to the subnet range group: %s\n",
8239 buf1);
8240 }
8241 }
8242 }
8243 }
8244
8245 if (use_json) {
8246 /* Administrative shutdown. */
8247 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8248 json_object_boolean_true_add(json_neigh,
8249 "adminShutDown");
8250
8251 /* BGP Version. */
8252 json_object_int_add(json_neigh, "bgpVersion", 4);
8253 json_object_string_add(
8254 json_neigh, "remoteRouterId",
8255 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8256
8257 /* Confederation */
8258 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8259 && bgp_confederation_peers_check(bgp, p->as))
8260 json_object_boolean_true_add(json_neigh,
8261 "nbrCommonAdmin");
8262
8263 /* Status. */
8264 json_object_string_add(
8265 json_neigh, "bgpState",
8266 lookup_msg(bgp_status_msg, p->status, NULL));
8267
8268 if (p->status == Established) {
8269 time_t uptime;
d62a17ae 8270
8271 uptime = bgp_clock();
8272 uptime -= p->uptime;
d62a17ae 8273 epoch_tbuf = time(NULL) - uptime;
8274
d3c7efed
DS
8275#if CONFDATE > 20200101
8276 CPP_NOTICE("bgpTimerUp should be deprecated and can be removed now");
8277#endif
8278 /*
8279 * bgpTimerUp was miliseconds that was accurate
8280 * up to 1 day, then the value returned
8281 * became garbage. So in order to provide
8282 * some level of backwards compatability,
8283 * we still provde the data, but now
8284 * we are returning the correct value
8285 * and also adding a new bgpTimerUpMsec
8286 * which will allow us to deprecate
8287 * this eventually
8288 */
d62a17ae 8289 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 8290 uptime * 1000);
d3c7efed
DS
8291 json_object_int_add(json_neigh, "bgpTimerUpMsec",
8292 uptime * 1000);
d62a17ae 8293 json_object_string_add(json_neigh, "bgpTimerUpString",
8294 peer_uptime(p->uptime, timebuf,
8295 BGP_UPTIME_LEN, 0,
8296 NULL));
8297 json_object_int_add(json_neigh,
8298 "bgpTimerUpEstablishedEpoch",
8299 epoch_tbuf);
8300 }
8301
8302 else if (p->status == Active) {
8303 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8304 json_object_string_add(json_neigh, "bgpStateIs",
8305 "passive");
8306 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8307 json_object_string_add(json_neigh, "bgpStateIs",
8308 "passiveNSF");
8309 }
8310
8311 /* read timer */
8312 time_t uptime;
8313 struct tm *tm;
8314
8315 uptime = bgp_clock();
8316 uptime -= p->readtime;
8317 tm = gmtime(&uptime);
8318 json_object_int_add(json_neigh, "bgpTimerLastRead",
8319 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8320 + (tm->tm_hour * 3600000));
8321
8322 uptime = bgp_clock();
8323 uptime -= p->last_write;
8324 tm = gmtime(&uptime);
8325 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8326 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8327 + (tm->tm_hour * 3600000));
8328
8329 uptime = bgp_clock();
8330 uptime -= p->update_time;
8331 tm = gmtime(&uptime);
8332 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8333 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8334 + (tm->tm_hour * 3600000));
8335
8336 /* Configured timer values. */
8337 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8338 p->v_holdtime * 1000);
8339 json_object_int_add(json_neigh,
8340 "bgpTimerKeepAliveIntervalMsecs",
8341 p->v_keepalive * 1000);
8342
d25e4efc 8343 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8344 json_object_int_add(json_neigh,
8345 "bgpTimerConfiguredHoldTimeMsecs",
8346 p->holdtime * 1000);
8347 json_object_int_add(
8348 json_neigh,
8349 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8350 p->keepalive * 1000);
d25e4efc
DS
8351 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8352 || (bgp->default_keepalive !=
8353 BGP_DEFAULT_KEEPALIVE)) {
8354 json_object_int_add(json_neigh,
8355 "bgpTimerConfiguredHoldTimeMsecs",
8356 bgp->default_holdtime);
8357 json_object_int_add(
8358 json_neigh,
8359 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8360 bgp->default_keepalive);
d62a17ae 8361 }
8362 } else {
8363 /* Administrative shutdown. */
8364 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8365 vty_out(vty, " Administratively shut down\n");
8366
8367 /* BGP Version. */
8368 vty_out(vty, " BGP version 4");
8369 vty_out(vty, ", remote router ID %s\n",
8370 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8371
8372 /* Confederation */
8373 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8374 && bgp_confederation_peers_check(bgp, p->as))
8375 vty_out(vty,
8376 " Neighbor under common administration\n");
8377
8378 /* Status. */
8379 vty_out(vty, " BGP state = %s",
8380 lookup_msg(bgp_status_msg, p->status, NULL));
8381
8382 if (p->status == Established)
8383 vty_out(vty, ", up for %8s",
8384 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8385 0, NULL));
8386
8387 else if (p->status == Active) {
8388 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8389 vty_out(vty, " (passive)");
8390 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8391 vty_out(vty, " (NSF passive)");
8392 }
8393 vty_out(vty, "\n");
8394
8395 /* read timer */
8396 vty_out(vty, " Last read %s",
8397 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8398 NULL));
8399 vty_out(vty, ", Last write %s\n",
8400 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8401 NULL));
8402
8403 /* Configured timer values. */
8404 vty_out(vty,
8405 " Hold time is %d, keepalive interval is %d seconds\n",
8406 p->v_holdtime, p->v_keepalive);
d25e4efc 8407 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8408 vty_out(vty, " Configured hold time is %d",
8409 p->holdtime);
8410 vty_out(vty, ", keepalive interval is %d seconds\n",
8411 p->keepalive);
d25e4efc
DS
8412 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
8413 || (bgp->default_keepalive !=
8414 BGP_DEFAULT_KEEPALIVE)) {
8415 vty_out(vty, " Configured hold time is %d",
8416 bgp->default_holdtime);
8417 vty_out(vty, ", keepalive interval is %d seconds\n",
8418 bgp->default_keepalive);
d62a17ae 8419 }
8420 }
8421 /* Capability. */
8422 if (p->status == Established) {
8423 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8424 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8425 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8426 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8427 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8428 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8429 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8430 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8431 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8432 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8433 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8434 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8435 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8436 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8437 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8438 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8439 if (use_json) {
8440 json_object *json_cap = NULL;
8441
8442 json_cap = json_object_new_object();
8443
8444 /* AS4 */
8445 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8446 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8447 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8448 && CHECK_FLAG(p->cap,
8449 PEER_CAP_AS4_RCV))
8450 json_object_string_add(
8451 json_cap, "4byteAs",
8452 "advertisedAndReceived");
8453 else if (CHECK_FLAG(p->cap,
8454 PEER_CAP_AS4_ADV))
8455 json_object_string_add(
8456 json_cap, "4byteAs",
8457 "advertised");
8458 else if (CHECK_FLAG(p->cap,
8459 PEER_CAP_AS4_RCV))
8460 json_object_string_add(
8461 json_cap, "4byteAs",
8462 "received");
8463 }
8464
8465 /* AddPath */
8466 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8467 || CHECK_FLAG(p->cap,
8468 PEER_CAP_ADDPATH_ADV)) {
8469 json_object *json_add = NULL;
8470 const char *print_store;
8471
8472 json_add = json_object_new_object();
8473
05c7a1cc
QY
8474 FOREACH_AFI_SAFI (afi, safi) {
8475 json_object *json_sub = NULL;
8476 json_sub =
8477 json_object_new_object();
8478 print_store = afi_safi_print(
8479 afi, safi);
d62a17ae 8480
05c7a1cc
QY
8481 if (CHECK_FLAG(
8482 p->af_cap[afi]
8483 [safi],
8484 PEER_CAP_ADDPATH_AF_TX_ADV)
8485 || CHECK_FLAG(
8486 p->af_cap[afi]
8487 [safi],
8488 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 8489 if (CHECK_FLAG(
8490 p->af_cap
8491 [afi]
8492 [safi],
8493 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 8494 && CHECK_FLAG(
d62a17ae 8495 p->af_cap
8496 [afi]
8497 [safi],
05c7a1cc
QY
8498 PEER_CAP_ADDPATH_AF_TX_RCV))
8499 json_object_boolean_true_add(
8500 json_sub,
8501 "txAdvertisedAndReceived");
8502 else if (
8503 CHECK_FLAG(
8504 p->af_cap
8505 [afi]
8506 [safi],
8507 PEER_CAP_ADDPATH_AF_TX_ADV))
8508 json_object_boolean_true_add(
8509 json_sub,
8510 "txAdvertised");
8511 else if (
8512 CHECK_FLAG(
8513 p->af_cap
8514 [afi]
8515 [safi],
8516 PEER_CAP_ADDPATH_AF_TX_RCV))
8517 json_object_boolean_true_add(
8518 json_sub,
8519 "txReceived");
8520 }
d62a17ae 8521
05c7a1cc
QY
8522 if (CHECK_FLAG(
8523 p->af_cap[afi]
8524 [safi],
8525 PEER_CAP_ADDPATH_AF_RX_ADV)
8526 || CHECK_FLAG(
8527 p->af_cap[afi]
8528 [safi],
8529 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 8530 if (CHECK_FLAG(
8531 p->af_cap
8532 [afi]
8533 [safi],
8534 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 8535 && CHECK_FLAG(
d62a17ae 8536 p->af_cap
8537 [afi]
8538 [safi],
8539 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
8540 json_object_boolean_true_add(
8541 json_sub,
8542 "rxAdvertisedAndReceived");
8543 else if (
8544 CHECK_FLAG(
8545 p->af_cap
8546 [afi]
8547 [safi],
8548 PEER_CAP_ADDPATH_AF_RX_ADV))
8549 json_object_boolean_true_add(
8550 json_sub,
8551 "rxAdvertised");
8552 else if (
8553 CHECK_FLAG(
8554 p->af_cap
8555 [afi]
8556 [safi],
8557 PEER_CAP_ADDPATH_AF_RX_RCV))
8558 json_object_boolean_true_add(
8559 json_sub,
8560 "rxReceived");
d62a17ae 8561 }
8562
05c7a1cc
QY
8563 if (CHECK_FLAG(
8564 p->af_cap[afi]
8565 [safi],
8566 PEER_CAP_ADDPATH_AF_TX_ADV)
8567 || CHECK_FLAG(
8568 p->af_cap[afi]
8569 [safi],
8570 PEER_CAP_ADDPATH_AF_TX_RCV)
8571 || CHECK_FLAG(
8572 p->af_cap[afi]
8573 [safi],
8574 PEER_CAP_ADDPATH_AF_RX_ADV)
8575 || CHECK_FLAG(
8576 p->af_cap[afi]
8577 [safi],
8578 PEER_CAP_ADDPATH_AF_RX_RCV))
8579 json_object_object_add(
8580 json_add,
8581 print_store,
8582 json_sub);
8583 else
8584 json_object_free(
8585 json_sub);
8586 }
8587
d62a17ae 8588 json_object_object_add(
8589 json_cap, "addPath", json_add);
8590 }
8591
8592 /* Dynamic */
8593 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
8594 || CHECK_FLAG(p->cap,
8595 PEER_CAP_DYNAMIC_ADV)) {
8596 if (CHECK_FLAG(p->cap,
8597 PEER_CAP_DYNAMIC_ADV)
8598 && CHECK_FLAG(p->cap,
8599 PEER_CAP_DYNAMIC_RCV))
8600 json_object_string_add(
8601 json_cap, "dynamic",
8602 "advertisedAndReceived");
8603 else if (CHECK_FLAG(
8604 p->cap,
8605 PEER_CAP_DYNAMIC_ADV))
8606 json_object_string_add(
8607 json_cap, "dynamic",
8608 "advertised");
8609 else if (CHECK_FLAG(
8610 p->cap,
8611 PEER_CAP_DYNAMIC_RCV))
8612 json_object_string_add(
8613 json_cap, "dynamic",
8614 "received");
8615 }
8616
8617 /* Extended nexthop */
8618 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
8619 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
8620 json_object *json_nxt = NULL;
8621 const char *print_store;
8622
8623
8624 if (CHECK_FLAG(p->cap,
8625 PEER_CAP_ENHE_ADV)
8626 && CHECK_FLAG(p->cap,
8627 PEER_CAP_ENHE_RCV))
8628 json_object_string_add(
8629 json_cap,
8630 "extendedNexthop",
8631 "advertisedAndReceived");
8632 else if (CHECK_FLAG(p->cap,
8633 PEER_CAP_ENHE_ADV))
8634 json_object_string_add(
8635 json_cap,
8636 "extendedNexthop",
8637 "advertised");
8638 else if (CHECK_FLAG(p->cap,
8639 PEER_CAP_ENHE_RCV))
8640 json_object_string_add(
8641 json_cap,
8642 "extendedNexthop",
8643 "received");
8644
8645 if (CHECK_FLAG(p->cap,
8646 PEER_CAP_ENHE_RCV)) {
8647 json_nxt =
8648 json_object_new_object();
8649
8650 for (safi = SAFI_UNICAST;
8651 safi < SAFI_MAX; safi++) {
8652 if (CHECK_FLAG(
8653 p->af_cap
8654 [AFI_IP]
8655 [safi],
8656 PEER_CAP_ENHE_AF_RCV)) {
8657 print_store = afi_safi_print(
8658 AFI_IP,
8659 safi);
8660 json_object_string_add(
8661 json_nxt,
8662 print_store,
8663 "recieved");
8664 }
8665 }
8666 json_object_object_add(
8667 json_cap,
8668 "extendedNexthopFamililesByPeer",
8669 json_nxt);
8670 }
8671 }
8672
8673 /* Route Refresh */
8674 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
8675 || CHECK_FLAG(p->cap,
8676 PEER_CAP_REFRESH_NEW_RCV)
8677 || CHECK_FLAG(p->cap,
8678 PEER_CAP_REFRESH_OLD_RCV)) {
8679 if (CHECK_FLAG(p->cap,
8680 PEER_CAP_REFRESH_ADV)
8681 && (CHECK_FLAG(
8682 p->cap,
8683 PEER_CAP_REFRESH_NEW_RCV)
8684 || CHECK_FLAG(
8685 p->cap,
8686 PEER_CAP_REFRESH_OLD_RCV))) {
8687 if (CHECK_FLAG(
8688 p->cap,
8689 PEER_CAP_REFRESH_OLD_RCV)
8690 && CHECK_FLAG(
8691 p->cap,
8692 PEER_CAP_REFRESH_NEW_RCV))
8693 json_object_string_add(
8694 json_cap,
8695 "routeRefresh",
8696 "advertisedAndReceivedOldNew");
8697 else {
8698 if (CHECK_FLAG(
8699 p->cap,
8700 PEER_CAP_REFRESH_OLD_RCV))
8701 json_object_string_add(
8702 json_cap,
8703 "routeRefresh",
8704 "advertisedAndReceivedOld");
8705 else
8706 json_object_string_add(
8707 json_cap,
8708 "routeRefresh",
8709 "advertisedAndReceivedNew");
8710 }
8711 } else if (
8712 CHECK_FLAG(
8713 p->cap,
8714 PEER_CAP_REFRESH_ADV))
8715 json_object_string_add(
8716 json_cap,
8717 "routeRefresh",
8718 "advertised");
8719 else if (
8720 CHECK_FLAG(
8721 p->cap,
8722 PEER_CAP_REFRESH_NEW_RCV)
8723 || CHECK_FLAG(
8724 p->cap,
8725 PEER_CAP_REFRESH_OLD_RCV))
8726 json_object_string_add(
8727 json_cap,
8728 "routeRefresh",
8729 "received");
8730 }
8731
8732 /* Multiprotocol Extensions */
8733 json_object *json_multi = NULL;
8734 json_multi = json_object_new_object();
8735
05c7a1cc
QY
8736 FOREACH_AFI_SAFI (afi, safi) {
8737 if (p->afc_adv[afi][safi]
8738 || p->afc_recv[afi][safi]) {
8739 json_object *json_exten = NULL;
8740 json_exten =
8741 json_object_new_object();
8742
d62a17ae 8743 if (p->afc_adv[afi][safi]
05c7a1cc
QY
8744 && p->afc_recv[afi][safi])
8745 json_object_boolean_true_add(
8746 json_exten,
8747 "advertisedAndReceived");
8748 else if (p->afc_adv[afi][safi])
8749 json_object_boolean_true_add(
8750 json_exten,
8751 "advertised");
8752 else if (p->afc_recv[afi][safi])
8753 json_object_boolean_true_add(
8754 json_exten,
8755 "received");
d62a17ae 8756
05c7a1cc
QY
8757 json_object_object_add(
8758 json_multi,
8759 afi_safi_print(afi,
8760 safi),
8761 json_exten);
d62a17ae 8762 }
8763 }
8764 json_object_object_add(
8765 json_cap, "multiprotocolExtensions",
8766 json_multi);
8767
d77114b7 8768 /* Hostname capabilities */
60466a63 8769 json_object *json_hname = NULL;
d77114b7
MK
8770
8771 json_hname = json_object_new_object();
8772
8773 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
8774 json_object_string_add(
60466a63
QY
8775 json_hname, "advHostName",
8776 bgp->peer_self->hostname
8777 ? bgp->peer_self
8778 ->hostname
d77114b7
MK
8779 : "n/a");
8780 json_object_string_add(
60466a63
QY
8781 json_hname, "advDomainName",
8782 bgp->peer_self->domainname
8783 ? bgp->peer_self
8784 ->domainname
d77114b7
MK
8785 : "n/a");
8786 }
8787
8788
8789 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
8790 json_object_string_add(
60466a63
QY
8791 json_hname, "rcvHostName",
8792 p->hostname ? p->hostname
8793 : "n/a");
d77114b7 8794 json_object_string_add(
60466a63
QY
8795 json_hname, "rcvDomainName",
8796 p->domainname ? p->domainname
8797 : "n/a");
d77114b7
MK
8798 }
8799
60466a63 8800 json_object_object_add(json_cap, "hostName",
d77114b7
MK
8801 json_hname);
8802
d62a17ae 8803 /* Gracefull Restart */
8804 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
8805 || CHECK_FLAG(p->cap,
8806 PEER_CAP_RESTART_ADV)) {
8807 if (CHECK_FLAG(p->cap,
8808 PEER_CAP_RESTART_ADV)
8809 && CHECK_FLAG(p->cap,
8810 PEER_CAP_RESTART_RCV))
8811 json_object_string_add(
8812 json_cap,
8813 "gracefulRestart",
8814 "advertisedAndReceived");
8815 else if (CHECK_FLAG(
8816 p->cap,
8817 PEER_CAP_RESTART_ADV))
8818 json_object_string_add(
8819 json_cap,
8820 "gracefulRestartCapability",
8821 "advertised");
8822 else if (CHECK_FLAG(
8823 p->cap,
8824 PEER_CAP_RESTART_RCV))
8825 json_object_string_add(
8826 json_cap,
8827 "gracefulRestartCapability",
8828 "received");
8829
8830 if (CHECK_FLAG(p->cap,
8831 PEER_CAP_RESTART_RCV)) {
8832 int restart_af_count = 0;
8833 json_object *json_restart =
8834 NULL;
8835 json_restart =
8836 json_object_new_object();
8837
8838 json_object_int_add(
8839 json_cap,
8840 "gracefulRestartRemoteTimerMsecs",
8841 p->v_gr_restart * 1000);
8842
05c7a1cc
QY
8843 FOREACH_AFI_SAFI (afi, safi) {
8844 if (CHECK_FLAG(
8845 p->af_cap
8846 [afi]
8847 [safi],
8848 PEER_CAP_RESTART_AF_RCV)) {
8849 json_object *
8850 json_sub =
8851 NULL;
8852 json_sub =
8853 json_object_new_object();
8854
d62a17ae 8855 if (CHECK_FLAG(
8856 p->af_cap
8857 [afi]
8858 [safi],
05c7a1cc
QY
8859 PEER_CAP_RESTART_AF_PRESERVE_RCV))
8860 json_object_boolean_true_add(
8861 json_sub,
8862 "preserved");
8863 restart_af_count++;
8864 json_object_object_add(
8865 json_restart,
8866 afi_safi_print(
8867 afi,
8868 safi),
8869 json_sub);
d62a17ae 8870 }
8871 }
8872 if (!restart_af_count) {
8873 json_object_string_add(
8874 json_cap,
8875 "addressFamiliesByPeer",
8876 "none");
8877 json_object_free(
8878 json_restart);
8879 } else
8880 json_object_object_add(
8881 json_cap,
8882 "addressFamiliesByPeer",
8883 json_restart);
8884 }
8885 }
8886 json_object_object_add(json_neigh,
8887 "neighborCapabilities",
8888 json_cap);
8889 } else {
8890 vty_out(vty, " Neighbor capabilities:\n");
8891
8892 /* AS4 */
8893 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8894 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8895 vty_out(vty, " 4 Byte AS:");
8896 if (CHECK_FLAG(p->cap,
8897 PEER_CAP_AS4_ADV))
8898 vty_out(vty, " advertised");
8899 if (CHECK_FLAG(p->cap,
8900 PEER_CAP_AS4_RCV))
8901 vty_out(vty, " %sreceived",
8902 CHECK_FLAG(
8903 p->cap,
8904 PEER_CAP_AS4_ADV)
8905 ? "and "
8906 : "");
8907 vty_out(vty, "\n");
8908 }
8909
8910 /* AddPath */
8911 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8912 || CHECK_FLAG(p->cap,
8913 PEER_CAP_ADDPATH_ADV)) {
8914 vty_out(vty, " AddPath:\n");
8915
05c7a1cc
QY
8916 FOREACH_AFI_SAFI (afi, safi) {
8917 if (CHECK_FLAG(
8918 p->af_cap[afi]
8919 [safi],
8920 PEER_CAP_ADDPATH_AF_TX_ADV)
8921 || CHECK_FLAG(
8922 p->af_cap[afi]
8923 [safi],
8924 PEER_CAP_ADDPATH_AF_TX_RCV)) {
8925 vty_out(vty,
8926 " %s: TX ",
8927 afi_safi_print(
8928 afi,
8929 safi));
8930
d62a17ae 8931 if (CHECK_FLAG(
8932 p->af_cap
8933 [afi]
8934 [safi],
05c7a1cc 8935 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 8936 vty_out(vty,
05c7a1cc 8937 "advertised %s",
d62a17ae 8938 afi_safi_print(
8939 afi,
8940 safi));
8941
05c7a1cc
QY
8942 if (CHECK_FLAG(
8943 p->af_cap
8944 [afi]
8945 [safi],
8946 PEER_CAP_ADDPATH_AF_TX_RCV))
8947 vty_out(vty,
8948 "%sreceived",
8949 CHECK_FLAG(
8950 p->af_cap
8951 [afi]
8952 [safi],
8953 PEER_CAP_ADDPATH_AF_TX_ADV)
8954 ? " and "
8955 : "");
d62a17ae 8956
05c7a1cc
QY
8957 vty_out(vty, "\n");
8958 }
d62a17ae 8959
05c7a1cc
QY
8960 if (CHECK_FLAG(
8961 p->af_cap[afi]
8962 [safi],
8963 PEER_CAP_ADDPATH_AF_RX_ADV)
8964 || CHECK_FLAG(
8965 p->af_cap[afi]
8966 [safi],
8967 PEER_CAP_ADDPATH_AF_RX_RCV)) {
8968 vty_out(vty,
8969 " %s: RX ",
8970 afi_safi_print(
8971 afi,
8972 safi));
d62a17ae 8973
8974 if (CHECK_FLAG(
8975 p->af_cap
8976 [afi]
8977 [safi],
05c7a1cc 8978 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 8979 vty_out(vty,
05c7a1cc 8980 "advertised %s",
d62a17ae 8981 afi_safi_print(
8982 afi,
8983 safi));
8984
05c7a1cc
QY
8985 if (CHECK_FLAG(
8986 p->af_cap
8987 [afi]
8988 [safi],
8989 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 8990 vty_out(vty,
05c7a1cc
QY
8991 "%sreceived",
8992 CHECK_FLAG(
8993 p->af_cap
8994 [afi]
8995 [safi],
8996 PEER_CAP_ADDPATH_AF_RX_ADV)
8997 ? " and "
8998 : "");
8999
9000 vty_out(vty, "\n");
d62a17ae 9001 }
05c7a1cc 9002 }
d62a17ae 9003 }
9004
9005 /* Dynamic */
9006 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9007 || CHECK_FLAG(p->cap,
9008 PEER_CAP_DYNAMIC_ADV)) {
9009 vty_out(vty, " Dynamic:");
9010 if (CHECK_FLAG(p->cap,
9011 PEER_CAP_DYNAMIC_ADV))
9012 vty_out(vty, " advertised");
9013 if (CHECK_FLAG(p->cap,
9014 PEER_CAP_DYNAMIC_RCV))
9015 vty_out(vty, " %sreceived",
9016 CHECK_FLAG(
9017 p->cap,
9018 PEER_CAP_DYNAMIC_ADV)
9019 ? "and "
9020 : "");
9021 vty_out(vty, "\n");
9022 }
9023
9024 /* Extended nexthop */
9025 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9026 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9027 vty_out(vty, " Extended nexthop:");
9028 if (CHECK_FLAG(p->cap,
9029 PEER_CAP_ENHE_ADV))
9030 vty_out(vty, " advertised");
9031 if (CHECK_FLAG(p->cap,
9032 PEER_CAP_ENHE_RCV))
9033 vty_out(vty, " %sreceived",
9034 CHECK_FLAG(
9035 p->cap,
9036 PEER_CAP_ENHE_ADV)
9037 ? "and "
9038 : "");
9039 vty_out(vty, "\n");
9040
9041 if (CHECK_FLAG(p->cap,
9042 PEER_CAP_ENHE_RCV)) {
9043 vty_out(vty,
9044 " Address families by peer:\n ");
9045 for (safi = SAFI_UNICAST;
9046 safi < SAFI_MAX; safi++)
9047 if (CHECK_FLAG(
9048 p->af_cap
9049 [AFI_IP]
9050 [safi],
9051 PEER_CAP_ENHE_AF_RCV))
9052 vty_out(vty,
9053 " %s\n",
9054 afi_safi_print(
9055 AFI_IP,
9056 safi));
9057 }
9058 }
9059
9060 /* Route Refresh */
9061 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9062 || CHECK_FLAG(p->cap,
9063 PEER_CAP_REFRESH_NEW_RCV)
9064 || CHECK_FLAG(p->cap,
9065 PEER_CAP_REFRESH_OLD_RCV)) {
9066 vty_out(vty, " Route refresh:");
9067 if (CHECK_FLAG(p->cap,
9068 PEER_CAP_REFRESH_ADV))
9069 vty_out(vty, " advertised");
9070 if (CHECK_FLAG(p->cap,
9071 PEER_CAP_REFRESH_NEW_RCV)
9072 || CHECK_FLAG(
9073 p->cap,
9074 PEER_CAP_REFRESH_OLD_RCV))
9075 vty_out(vty, " %sreceived(%s)",
9076 CHECK_FLAG(
9077 p->cap,
9078 PEER_CAP_REFRESH_ADV)
9079 ? "and "
9080 : "",
9081 (CHECK_FLAG(
9082 p->cap,
9083 PEER_CAP_REFRESH_OLD_RCV)
9084 && CHECK_FLAG(
9085 p->cap,
9086 PEER_CAP_REFRESH_NEW_RCV))
9087 ? "old & new"
9088 : CHECK_FLAG(
9089 p->cap,
9090 PEER_CAP_REFRESH_OLD_RCV)
9091 ? "old"
9092 : "new");
9093
9094 vty_out(vty, "\n");
9095 }
9096
9097 /* Multiprotocol Extensions */
05c7a1cc
QY
9098 FOREACH_AFI_SAFI (afi, safi)
9099 if (p->afc_adv[afi][safi]
9100 || p->afc_recv[afi][safi]) {
9101 vty_out(vty,
9102 " Address Family %s:",
9103 afi_safi_print(afi,
9104 safi));
9105 if (p->afc_adv[afi][safi])
d62a17ae 9106 vty_out(vty,
05c7a1cc
QY
9107 " advertised");
9108 if (p->afc_recv[afi][safi])
9109 vty_out(vty,
9110 " %sreceived",
9111 p->afc_adv[afi]
9112 [safi]
9113 ? "and "
9114 : "");
9115 vty_out(vty, "\n");
9116 }
d62a17ae 9117
9118 /* Hostname capability */
60466a63 9119 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9120
9121 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9122 vty_out(vty,
9123 " advertised (name: %s,domain name: %s)",
60466a63
QY
9124 bgp->peer_self->hostname
9125 ? bgp->peer_self
9126 ->hostname
d77114b7 9127 : "n/a",
60466a63
QY
9128 bgp->peer_self->domainname
9129 ? bgp->peer_self
9130 ->domainname
d77114b7
MK
9131 : "n/a");
9132 } else {
9133 vty_out(vty, " not advertised");
d62a17ae 9134 }
9135
d77114b7 9136 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9137 vty_out(vty,
9138 " received (name: %s,domain name: %s)",
60466a63
QY
9139 p->hostname ? p->hostname
9140 : "n/a",
9141 p->domainname ? p->domainname
9142 : "n/a");
d77114b7
MK
9143 } else {
9144 vty_out(vty, " not received");
9145 }
9146
9147 vty_out(vty, "\n");
9148
d62a17ae 9149 /* Gracefull Restart */
9150 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9151 || CHECK_FLAG(p->cap,
9152 PEER_CAP_RESTART_ADV)) {
9153 vty_out(vty,
9154 " Graceful Restart Capabilty:");
9155 if (CHECK_FLAG(p->cap,
9156 PEER_CAP_RESTART_ADV))
9157 vty_out(vty, " advertised");
9158 if (CHECK_FLAG(p->cap,
9159 PEER_CAP_RESTART_RCV))
9160 vty_out(vty, " %sreceived",
9161 CHECK_FLAG(
9162 p->cap,
9163 PEER_CAP_RESTART_ADV)
9164 ? "and "
9165 : "");
9166 vty_out(vty, "\n");
9167
9168 if (CHECK_FLAG(p->cap,
9169 PEER_CAP_RESTART_RCV)) {
9170 int restart_af_count = 0;
9171
9172 vty_out(vty,
9173 " Remote Restart timer is %d seconds\n",
9174 p->v_gr_restart);
9175 vty_out(vty,
9176 " Address families by peer:\n ");
9177
05c7a1cc
QY
9178 FOREACH_AFI_SAFI (afi, safi)
9179 if (CHECK_FLAG(
9180 p->af_cap
9181 [afi]
9182 [safi],
9183 PEER_CAP_RESTART_AF_RCV)) {
9184 vty_out(vty,
9185 "%s%s(%s)",
9186 restart_af_count
9187 ? ", "
9188 : "",
9189 afi_safi_print(
9190 afi,
9191 safi),
9192 CHECK_FLAG(
9193 p->af_cap
9194 [afi]
9195 [safi],
9196 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9197 ? "preserved"
9198 : "not preserved");
9199 restart_af_count++;
9200 }
d62a17ae 9201 if (!restart_af_count)
9202 vty_out(vty, "none");
9203 vty_out(vty, "\n");
9204 }
9205 }
9206 }
9207 }
9208 }
9209
9210 /* graceful restart information */
9211 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9212 || p->t_gr_stale) {
9213 json_object *json_grace = NULL;
9214 json_object *json_grace_send = NULL;
9215 json_object *json_grace_recv = NULL;
9216 int eor_send_af_count = 0;
9217 int eor_receive_af_count = 0;
9218
9219 if (use_json) {
9220 json_grace = json_object_new_object();
9221 json_grace_send = json_object_new_object();
9222 json_grace_recv = json_object_new_object();
9223
9224 if (p->status == Established) {
05c7a1cc
QY
9225 FOREACH_AFI_SAFI (afi, safi) {
9226 if (CHECK_FLAG(p->af_sflags[afi][safi],
9227 PEER_STATUS_EOR_SEND)) {
9228 json_object_boolean_true_add(
9229 json_grace_send,
9230 afi_safi_print(afi,
9231 safi));
9232 eor_send_af_count++;
d62a17ae 9233 }
9234 }
05c7a1cc
QY
9235 FOREACH_AFI_SAFI (afi, safi) {
9236 if (CHECK_FLAG(
9237 p->af_sflags[afi][safi],
9238 PEER_STATUS_EOR_RECEIVED)) {
9239 json_object_boolean_true_add(
9240 json_grace_recv,
9241 afi_safi_print(afi,
9242 safi));
9243 eor_receive_af_count++;
d62a17ae 9244 }
9245 }
9246 }
9247
9248 json_object_object_add(json_grace, "endOfRibSend",
9249 json_grace_send);
9250 json_object_object_add(json_grace, "endOfRibRecv",
9251 json_grace_recv);
9252
9253 if (p->t_gr_restart)
9254 json_object_int_add(json_grace,
9255 "gracefulRestartTimerMsecs",
9256 thread_timer_remain_second(
9257 p->t_gr_restart)
9258 * 1000);
9259
9260 if (p->t_gr_stale)
9261 json_object_int_add(
9262 json_grace,
9263 "gracefulStalepathTimerMsecs",
9264 thread_timer_remain_second(
9265 p->t_gr_stale)
9266 * 1000);
9267
9268 json_object_object_add(
9269 json_neigh, "gracefulRestartInfo", json_grace);
9270 } else {
9271 vty_out(vty, " Graceful restart informations:\n");
9272 if (p->status == Established) {
9273 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
9274 FOREACH_AFI_SAFI (afi, safi) {
9275 if (CHECK_FLAG(p->af_sflags[afi][safi],
9276 PEER_STATUS_EOR_SEND)) {
9277 vty_out(vty, "%s%s",
9278 eor_send_af_count ? ", "
9279 : "",
9280 afi_safi_print(afi,
9281 safi));
9282 eor_send_af_count++;
d62a17ae 9283 }
9284 }
9285 vty_out(vty, "\n");
9286 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
9287 FOREACH_AFI_SAFI (afi, safi) {
9288 if (CHECK_FLAG(
9289 p->af_sflags[afi][safi],
9290 PEER_STATUS_EOR_RECEIVED)) {
9291 vty_out(vty, "%s%s",
9292 eor_receive_af_count
9293 ? ", "
9294 : "",
9295 afi_safi_print(afi,
9296 safi));
9297 eor_receive_af_count++;
d62a17ae 9298 }
9299 }
9300 vty_out(vty, "\n");
9301 }
9302
9303 if (p->t_gr_restart)
9304 vty_out(vty,
9305 " The remaining time of restart timer is %ld\n",
9306 thread_timer_remain_second(
9307 p->t_gr_restart));
9308
9309 if (p->t_gr_stale)
9310 vty_out(vty,
9311 " The remaining time of stalepath timer is %ld\n",
9312 thread_timer_remain_second(
9313 p->t_gr_stale));
9314 }
9315 }
9316 if (use_json) {
9317 json_object *json_stat = NULL;
9318 json_stat = json_object_new_object();
9319 /* Packet counts. */
9320 json_object_int_add(json_stat, "depthInq", 0);
9321 json_object_int_add(json_stat, "depthOutq",
9322 (unsigned long)p->obuf->count);
0112e9e0
QY
9323 json_object_int_add(json_stat, "opensSent",
9324 atomic_load_explicit(&p->open_out,
9325 memory_order_relaxed));
9326 json_object_int_add(json_stat, "opensRecv",
9327 atomic_load_explicit(&p->open_in,
9328 memory_order_relaxed));
d62a17ae 9329 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
9330 atomic_load_explicit(&p->notify_out,
9331 memory_order_relaxed));
d62a17ae 9332 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
9333 atomic_load_explicit(&p->notify_in,
9334 memory_order_relaxed));
9335 json_object_int_add(json_stat, "updatesSent",
9336 atomic_load_explicit(&p->update_out,
9337 memory_order_relaxed));
9338 json_object_int_add(json_stat, "updatesRecv",
9339 atomic_load_explicit(&p->update_in,
9340 memory_order_relaxed));
d62a17ae 9341 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
9342 atomic_load_explicit(&p->keepalive_out,
9343 memory_order_relaxed));
d62a17ae 9344 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
9345 atomic_load_explicit(&p->keepalive_in,
9346 memory_order_relaxed));
d62a17ae 9347 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
9348 atomic_load_explicit(&p->refresh_out,
9349 memory_order_relaxed));
d62a17ae 9350 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
9351 atomic_load_explicit(&p->refresh_in,
9352 memory_order_relaxed));
d62a17ae 9353 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
9354 atomic_load_explicit(&p->dynamic_cap_out,
9355 memory_order_relaxed));
d62a17ae 9356 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
9357 atomic_load_explicit(&p->dynamic_cap_in,
9358 memory_order_relaxed));
9359 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
9360 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 9361 json_object_object_add(json_neigh, "messageStats", json_stat);
9362 } else {
9363 /* Packet counts. */
9364 vty_out(vty, " Message statistics:\n");
9365 vty_out(vty, " Inq depth is 0\n");
9366 vty_out(vty, " Outq depth is %lu\n",
9367 (unsigned long)p->obuf->count);
9368 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
9369 vty_out(vty, " Opens: %10d %10d\n",
9370 atomic_load_explicit(&p->open_out,
9371 memory_order_relaxed),
9372 atomic_load_explicit(&p->open_in,
9373 memory_order_relaxed));
9374 vty_out(vty, " Notifications: %10d %10d\n",
9375 atomic_load_explicit(&p->notify_out,
9376 memory_order_relaxed),
9377 atomic_load_explicit(&p->notify_in,
9378 memory_order_relaxed));
9379 vty_out(vty, " Updates: %10d %10d\n",
9380 atomic_load_explicit(&p->update_out,
9381 memory_order_relaxed),
9382 atomic_load_explicit(&p->update_in,
9383 memory_order_relaxed));
9384 vty_out(vty, " Keepalives: %10d %10d\n",
9385 atomic_load_explicit(&p->keepalive_out,
9386 memory_order_relaxed),
9387 atomic_load_explicit(&p->keepalive_in,
9388 memory_order_relaxed));
9389 vty_out(vty, " Route Refresh: %10d %10d\n",
9390 atomic_load_explicit(&p->refresh_out,
9391 memory_order_relaxed),
9392 atomic_load_explicit(&p->refresh_in,
9393 memory_order_relaxed));
d62a17ae 9394 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
9395 atomic_load_explicit(&p->dynamic_cap_out,
9396 memory_order_relaxed),
9397 atomic_load_explicit(&p->dynamic_cap_in,
9398 memory_order_relaxed));
9399 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
9400 PEER_TOTAL_RX(p));
d62a17ae 9401 }
9402
9403 if (use_json) {
9404 /* advertisement-interval */
9405 json_object_int_add(json_neigh,
9406 "minBtwnAdvertisementRunsTimerMsecs",
9407 p->v_routeadv * 1000);
9408
9409 /* Update-source. */
9410 if (p->update_if || p->update_source) {
9411 if (p->update_if)
9412 json_object_string_add(json_neigh,
9413 "updateSource",
9414 p->update_if);
9415 else if (p->update_source)
9416 json_object_string_add(
9417 json_neigh, "updateSource",
9418 sockunion2str(p->update_source, buf1,
9419 SU_ADDRSTRLEN));
9420 }
9421 } else {
9422 /* advertisement-interval */
9423 vty_out(vty,
9424 " Minimum time between advertisement runs is %d seconds\n",
9425 p->v_routeadv);
9426
9427 /* Update-source. */
9428 if (p->update_if || p->update_source) {
9429 vty_out(vty, " Update source is ");
9430 if (p->update_if)
9431 vty_out(vty, "%s", p->update_if);
9432 else if (p->update_source)
9433 vty_out(vty, "%s",
9434 sockunion2str(p->update_source, buf1,
9435 SU_ADDRSTRLEN));
9436 vty_out(vty, "\n");
9437 }
9438
9439 vty_out(vty, "\n");
9440 }
9441
9442 /* Address Family Information */
9443 json_object *json_hold = NULL;
9444
9445 if (use_json)
9446 json_hold = json_object_new_object();
9447
05c7a1cc
QY
9448 FOREACH_AFI_SAFI (afi, safi)
9449 if (p->afc[afi][safi])
9450 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9451 json_hold);
d62a17ae 9452
9453 if (use_json) {
9454 json_object_object_add(json_neigh, "addressFamilyInfo",
9455 json_hold);
9456 json_object_int_add(json_neigh, "connectionsEstablished",
9457 p->established);
9458 json_object_int_add(json_neigh, "connectionsDropped",
9459 p->dropped);
9460 } else
9461 vty_out(vty, " Connections established %d; dropped %d\n",
9462 p->established, p->dropped);
9463
9464 if (!p->last_reset) {
9465 if (use_json)
9466 json_object_string_add(json_neigh, "lastReset",
9467 "never");
9468 else
9469 vty_out(vty, " Last reset never\n");
9470 } else {
9471 if (use_json) {
9472 time_t uptime;
9473 struct tm *tm;
9474
9475 uptime = bgp_clock();
9476 uptime -= p->resettime;
9477 tm = gmtime(&uptime);
9478 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9479 (tm->tm_sec * 1000)
9480 + (tm->tm_min * 60000)
9481 + (tm->tm_hour * 3600000));
9482 json_object_string_add(
9483 json_neigh, "lastResetDueTo",
9484 peer_down_str[(int)p->last_reset]);
9485 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9486 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9487 char errorcodesubcode_hexstr[5];
9488 char errorcodesubcode_str[256];
9489
9490 code_str = bgp_notify_code_str(p->notify.code);
9491 subcode_str = bgp_notify_subcode_str(
9492 p->notify.code, p->notify.subcode);
9493
9494 sprintf(errorcodesubcode_hexstr, "%02X%02X",
9495 p->notify.code, p->notify.subcode);
9496 json_object_string_add(json_neigh,
9497 "lastErrorCodeSubcode",
9498 errorcodesubcode_hexstr);
9499 snprintf(errorcodesubcode_str, 255, "%s%s",
9500 code_str, subcode_str);
9501 json_object_string_add(json_neigh,
9502 "lastNotificationReason",
9503 errorcodesubcode_str);
9504 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9505 && p->notify.code == BGP_NOTIFY_CEASE
9506 && (p->notify.subcode
9507 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9508 || p->notify.subcode
9509 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9510 && p->notify.length) {
9511 char msgbuf[1024];
9512 const char *msg_str;
9513
9514 msg_str = bgp_notify_admin_message(
9515 msgbuf, sizeof(msgbuf),
9516 (u_char *)p->notify.data,
9517 p->notify.length);
9518 if (msg_str)
9519 json_object_string_add(
9520 json_neigh,
9521 "lastShutdownDescription",
9522 msg_str);
9523 }
9524 }
9525 } else {
9526 vty_out(vty, " Last reset %s, ",
9527 peer_uptime(p->resettime, timebuf,
9528 BGP_UPTIME_LEN, 0, NULL));
9529
9530 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9531 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9532 code_str = bgp_notify_code_str(p->notify.code);
9533 subcode_str = bgp_notify_subcode_str(
9534 p->notify.code, p->notify.subcode);
9535 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
9536 p->last_reset == PEER_DOWN_NOTIFY_SEND
9537 ? "sent"
9538 : "received",
9539 code_str, subcode_str);
9540 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
9541 && p->notify.code == BGP_NOTIFY_CEASE
9542 && (p->notify.subcode
9543 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
9544 || p->notify.subcode
9545 == BGP_NOTIFY_CEASE_ADMIN_RESET)
9546 && p->notify.length) {
9547 char msgbuf[1024];
9548 const char *msg_str;
9549
9550 msg_str = bgp_notify_admin_message(
9551 msgbuf, sizeof(msgbuf),
9552 (u_char *)p->notify.data,
9553 p->notify.length);
9554 if (msg_str)
9555 vty_out(vty,
9556 " Message: \"%s\"\n",
9557 msg_str);
9558 }
9559 } else {
9560 vty_out(vty, "due to %s\n",
9561 peer_down_str[(int)p->last_reset]);
9562 }
9563
9564 if (p->last_reset_cause_size) {
9565 msg = p->last_reset_cause;
9566 vty_out(vty,
9567 " Message received that caused BGP to send a NOTIFICATION:\n ");
9568 for (i = 1; i <= p->last_reset_cause_size;
9569 i++) {
9570 vty_out(vty, "%02X", *msg++);
9571
9572 if (i != p->last_reset_cause_size) {
9573 if (i % 16 == 0) {
9574 vty_out(vty, "\n ");
9575 } else if (i % 4 == 0) {
9576 vty_out(vty, " ");
9577 }
9578 }
9579 }
9580 vty_out(vty, "\n");
9581 }
9582 }
9583 }
9584
9585 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
9586 if (use_json)
9587 json_object_boolean_true_add(json_neigh,
9588 "prefixesConfigExceedMax");
9589 else
9590 vty_out(vty,
9591 " Peer had exceeded the max. no. of prefixes configured.\n");
9592
9593 if (p->t_pmax_restart) {
9594 if (use_json) {
9595 json_object_boolean_true_add(
9596 json_neigh, "reducePrefixNumFrom");
9597 json_object_int_add(json_neigh,
9598 "restartInTimerMsec",
9599 thread_timer_remain_second(
9600 p->t_pmax_restart)
9601 * 1000);
9602 } else
9603 vty_out(vty,
9604 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
9d303b37
DL
9605 p->host, thread_timer_remain_second(
9606 p->t_pmax_restart));
d62a17ae 9607 } else {
9608 if (use_json)
9609 json_object_boolean_true_add(
9610 json_neigh,
9611 "reducePrefixNumAndClearIpBgp");
9612 else
9613 vty_out(vty,
9614 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
9615 p->host);
9616 }
9617 }
9618
9619 /* EBGP Multihop and GTSM */
9620 if (p->sort != BGP_PEER_IBGP) {
9621 if (use_json) {
9622 if (p->gtsm_hops > 0)
9623 json_object_int_add(json_neigh,
9624 "externalBgpNbrMaxHopsAway",
9625 p->gtsm_hops);
9626 else if (p->ttl > 1)
9627 json_object_int_add(json_neigh,
9628 "externalBgpNbrMaxHopsAway",
9629 p->ttl);
9630 } else {
9631 if (p->gtsm_hops > 0)
9632 vty_out(vty,
9633 " External BGP neighbor may be up to %d hops away.\n",
9634 p->gtsm_hops);
9635 else if (p->ttl > 1)
9636 vty_out(vty,
9637 " External BGP neighbor may be up to %d hops away.\n",
9638 p->ttl);
9639 }
9640 } else {
9641 if (p->gtsm_hops > 0) {
9642 if (use_json)
9643 json_object_int_add(json_neigh,
9644 "internalBgpNbrMaxHopsAway",
9645 p->gtsm_hops);
9646 else
9647 vty_out(vty,
9648 " Internal BGP neighbor may be up to %d hops away.\n",
9649 p->gtsm_hops);
9650 }
9651 }
9652
9653 /* Local address. */
9654 if (p->su_local) {
9655 if (use_json) {
9656 json_object_string_add(json_neigh, "hostLocal",
9657 sockunion2str(p->su_local, buf1,
9658 SU_ADDRSTRLEN));
9659 json_object_int_add(json_neigh, "portLocal",
9660 ntohs(p->su_local->sin.sin_port));
9661 } else
9662 vty_out(vty, "Local host: %s, Local port: %d\n",
9663 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
9664 ntohs(p->su_local->sin.sin_port));
9665 }
9666
9667 /* Remote address. */
9668 if (p->su_remote) {
9669 if (use_json) {
9670 json_object_string_add(json_neigh, "hostForeign",
9671 sockunion2str(p->su_remote, buf1,
9672 SU_ADDRSTRLEN));
9673 json_object_int_add(json_neigh, "portForeign",
9674 ntohs(p->su_remote->sin.sin_port));
9675 } else
9676 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
9677 sockunion2str(p->su_remote, buf1,
9678 SU_ADDRSTRLEN),
9679 ntohs(p->su_remote->sin.sin_port));
9680 }
9681
9682 /* Nexthop display. */
9683 if (p->su_local) {
9684 if (use_json) {
9685 json_object_string_add(json_neigh, "nexthop",
9686 inet_ntop(AF_INET,
9687 &p->nexthop.v4, buf1,
9688 sizeof(buf1)));
9689 json_object_string_add(json_neigh, "nexthopGlobal",
9690 inet_ntop(AF_INET6,
9691 &p->nexthop.v6_global,
9692 buf1, sizeof(buf1)));
9693 json_object_string_add(json_neigh, "nexthopLocal",
9694 inet_ntop(AF_INET6,
9695 &p->nexthop.v6_local,
9696 buf1, sizeof(buf1)));
9697 if (p->shared_network)
9698 json_object_string_add(json_neigh,
9699 "bgpConnection",
9700 "sharedNetwork");
9701 else
9702 json_object_string_add(json_neigh,
9703 "bgpConnection",
9704 "nonSharedNetwork");
9705 } else {
9706 vty_out(vty, "Nexthop: %s\n",
9707 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
9708 sizeof(buf1)));
9709 vty_out(vty, "Nexthop global: %s\n",
9710 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
9711 sizeof(buf1)));
9712 vty_out(vty, "Nexthop local: %s\n",
9713 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
9714 sizeof(buf1)));
9715 vty_out(vty, "BGP connection: %s\n",
9716 p->shared_network ? "shared network"
9717 : "non shared network");
9718 }
9719 }
9720
9721 /* Timer information. */
9722 if (use_json) {
9723 json_object_int_add(json_neigh, "connectRetryTimer",
9724 p->v_connect);
9725 if (p->status == Established && p->rtt)
9726 json_object_int_add(json_neigh, "estimatedRttInMsecs",
9727 p->rtt);
9728 if (p->t_start)
9729 json_object_int_add(
9730 json_neigh, "nextStartTimerDueInMsecs",
9731 thread_timer_remain_second(p->t_start) * 1000);
9732 if (p->t_connect)
9733 json_object_int_add(
9734 json_neigh, "nextConnectTimerDueInMsecs",
9735 thread_timer_remain_second(p->t_connect)
9736 * 1000);
9737 if (p->t_routeadv) {
9738 json_object_int_add(json_neigh, "mraiInterval",
9739 p->v_routeadv);
9740 json_object_int_add(
9741 json_neigh, "mraiTimerExpireInMsecs",
9742 thread_timer_remain_second(p->t_routeadv)
9743 * 1000);
9744 }
9745 if (p->password)
9746 json_object_int_add(json_neigh, "authenticationEnabled",
9747 1);
9748
9749 if (p->t_read)
9750 json_object_string_add(json_neigh, "readThread", "on");
9751 else
9752 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
9753
9754 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 9755 json_object_string_add(json_neigh, "writeThread", "on");
9756 else
9757 json_object_string_add(json_neigh, "writeThread",
9758 "off");
9759 } else {
9760 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
9761 p->v_connect);
9762 if (p->status == Established && p->rtt)
9763 vty_out(vty, "Estimated round trip time: %d ms\n",
9764 p->rtt);
9765 if (p->t_start)
9766 vty_out(vty, "Next start timer due in %ld seconds\n",
9767 thread_timer_remain_second(p->t_start));
9768 if (p->t_connect)
9769 vty_out(vty, "Next connect timer due in %ld seconds\n",
9770 thread_timer_remain_second(p->t_connect));
9771 if (p->t_routeadv)
9772 vty_out(vty,
9773 "MRAI (interval %u) timer expires in %ld seconds\n",
9774 p->v_routeadv,
9775 thread_timer_remain_second(p->t_routeadv));
9776 if (p->password)
9777 vty_out(vty, "Peer Authentication Enabled\n");
9778
9779 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
9780 p->t_read ? "on" : "off",
9781 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
9782 ? "on"
9783 : "off");
d62a17ae 9784 }
9785
9786 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
9787 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
9788 bgp_capability_vty_out(vty, p, use_json, json_neigh);
9789
9790 if (!use_json)
9791 vty_out(vty, "\n");
9792
9793 /* BFD information. */
9794 bgp_bfd_show_info(vty, p, use_json, json_neigh);
9795
9796 if (use_json) {
9797 if (p->conf_if) /* Configured interface name. */
9798 json_object_object_add(json, p->conf_if, json_neigh);
9799 else /* Configured IP address. */
9800 json_object_object_add(json, p->host, json_neigh);
9801 }
9802}
9803
9804static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
9805 enum show_type type, union sockunion *su,
9806 const char *conf_if, u_char use_json,
9807 json_object *json)
9808{
9809 struct listnode *node, *nnode;
9810 struct peer *peer;
9811 int find = 0;
9812
9813 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
9814 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
9815 continue;
9816
9817 switch (type) {
9818 case show_all:
9819 bgp_show_peer(vty, peer, use_json, json);
9820 break;
9821 case show_peer:
9822 if (conf_if) {
9823 if ((peer->conf_if
9824 && !strcmp(peer->conf_if, conf_if))
9825 || (peer->hostname
9826 && !strcmp(peer->hostname, conf_if))) {
9827 find = 1;
9828 bgp_show_peer(vty, peer, use_json,
9829 json);
9830 }
9831 } else {
9832 if (sockunion_same(&peer->su, su)) {
9833 find = 1;
9834 bgp_show_peer(vty, peer, use_json,
9835 json);
9836 }
9837 }
9838 break;
9839 }
9840 }
9841
9842 if (type == show_peer && !find) {
9843 if (use_json)
9844 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
9845 else
9846 vty_out(vty, "%% No such neighbor\n");
9847 }
9848
9849 if (use_json) {
57a9c8a8 9850 bgp_show_bestpath_json(bgp, json);
9d303b37
DL
9851 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9852 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 9853 json_object_free(json);
9854 } else {
9855 vty_out(vty, "\n");
9856 }
9857
9858 return CMD_SUCCESS;
9859}
9860
9861static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
9862 u_char use_json)
9863{
0291c246
MK
9864 struct listnode *node, *nnode;
9865 struct bgp *bgp;
9866 json_object *json = NULL;
9867 int is_first = 1;
d62a17ae 9868
9869 if (use_json)
9870 vty_out(vty, "{\n");
9871
9872 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
9873 if (use_json) {
9874 if (!(json = json_object_new_object())) {
9875 zlog_err(
9876 "Unable to allocate memory for JSON object");
9877 vty_out(vty,
9878 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
9879 return;
9880 }
9881
9882 json_object_int_add(json, "vrfId",
9883 (bgp->vrf_id == VRF_UNKNOWN)
a8bf7d9c 9884 ? -1 : (int64_t) bgp->vrf_id);
d62a17ae 9885 json_object_string_add(
9886 json, "vrfName",
9887 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9888 ? "Default"
9889 : bgp->name);
9890
9891 if (!is_first)
9892 vty_out(vty, ",\n");
9893 else
9894 is_first = 0;
9895
9896 vty_out(vty, "\"%s\":",
9897 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9898 ? "Default"
9899 : bgp->name);
9900 } else {
9901 vty_out(vty, "\nInstance %s:\n",
9902 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
9903 ? "Default"
9904 : bgp->name);
9905 }
9906 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL, use_json,
9907 json);
9908 }
9909
9910 if (use_json)
9911 vty_out(vty, "}\n");
9912}
9913
9914static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
9915 enum show_type type, const char *ip_str,
9916 u_char use_json)
9917{
9918 int ret;
9919 struct bgp *bgp;
9920 union sockunion su;
9921 json_object *json = NULL;
9922
9923 if (name) {
9924 if (strmatch(name, "all")) {
9925 bgp_show_all_instances_neighbors_vty(vty, use_json);
9926 return CMD_SUCCESS;
9927 } else {
9928 bgp = bgp_lookup_by_name(name);
9929 if (!bgp) {
9930 if (use_json) {
9931 json = json_object_new_object();
9932 json_object_boolean_true_add(
9933 json, "bgpNoSuchInstance");
9934 vty_out(vty, "%s\n",
9935 json_object_to_json_string_ext(
9936 json,
9937 JSON_C_TO_STRING_PRETTY));
9938 json_object_free(json);
9939 } else
9940 vty_out(vty,
9941 "%% No such BGP instance exist\n");
9942
9943 return CMD_WARNING;
9944 }
9945 }
9946 } else {
9947 bgp = bgp_get_default();
9948 }
9949
9950 if (bgp) {
9951 json = json_object_new_object();
9952 if (ip_str) {
9953 ret = str2sockunion(ip_str, &su);
9954 if (ret < 0)
9955 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
9956 use_json, json);
9957 else
9958 bgp_show_neighbor(vty, bgp, type, &su, NULL,
9959 use_json, json);
9960 } else {
9961 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
9962 json);
9963 }
9964 json_object_free(json);
9965 }
9966
9967 return CMD_SUCCESS;
4fb25c53
DW
9968}
9969
716b2d8a 9970/* "show [ip] bgp neighbors" commands. */
718e3744 9971DEFUN (show_ip_bgp_neighbors,
9972 show_ip_bgp_neighbors_cmd,
24345e82 9973 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 9974 SHOW_STR
9975 IP_STR
9976 BGP_STR
f2a8972b 9977 BGP_INSTANCE_HELP_STR
8c3deaae
QY
9978 "Address Family\n"
9979 "Address Family\n"
718e3744 9980 "Detailed information on TCP and BGP neighbor connections\n"
9981 "Neighbor to display information about\n"
a80beece 9982 "Neighbor to display information about\n"
91d37724 9983 "Neighbor on BGP configured interface\n"
9973d184 9984 JSON_STR)
718e3744 9985{
d62a17ae 9986 char *vrf = NULL;
9987 char *sh_arg = NULL;
9988 enum show_type sh_type;
718e3744 9989
d62a17ae 9990 u_char uj = use_json(argc, argv);
718e3744 9991
d62a17ae 9992 int idx = 0;
718e3744 9993
d62a17ae 9994 if (argv_find(argv, argc, "view", &idx)
9995 || argv_find(argv, argc, "vrf", &idx))
9996 vrf = argv[idx + 1]->arg;
718e3744 9997
d62a17ae 9998 idx++;
9999 if (argv_find(argv, argc, "A.B.C.D", &idx)
10000 || argv_find(argv, argc, "X:X::X:X", &idx)
10001 || argv_find(argv, argc, "WORD", &idx)) {
10002 sh_type = show_peer;
10003 sh_arg = argv[idx]->arg;
10004 } else
10005 sh_type = show_all;
856ca177 10006
d62a17ae 10007 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10008}
10009
716b2d8a 10010/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10011 paths' and `show ip mbgp paths'. Those functions results are the
10012 same.*/
f412b39a 10013DEFUN (show_ip_bgp_paths,
718e3744 10014 show_ip_bgp_paths_cmd,
46f296b4 10015 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10016 SHOW_STR
10017 IP_STR
10018 BGP_STR
46f296b4 10019 BGP_SAFI_HELP_STR
718e3744 10020 "Path information\n")
10021{
d62a17ae 10022 vty_out(vty, "Address Refcnt Path\n");
10023 aspath_print_all_vty(vty);
10024 return CMD_SUCCESS;
718e3744 10025}
10026
718e3744 10027#include "hash.h"
10028
d62a17ae 10029static void community_show_all_iterator(struct hash_backet *backet,
10030 struct vty *vty)
718e3744 10031{
d62a17ae 10032 struct community *com;
718e3744 10033
d62a17ae 10034 com = (struct community *)backet->data;
3f65c5b1 10035 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10036 community_str(com, false));
718e3744 10037}
10038
10039/* Show BGP's community internal data. */
f412b39a 10040DEFUN (show_ip_bgp_community_info,
718e3744 10041 show_ip_bgp_community_info_cmd,
bec37ba5 10042 "show [ip] bgp community-info",
718e3744 10043 SHOW_STR
10044 IP_STR
10045 BGP_STR
10046 "List all bgp community information\n")
10047{
d62a17ae 10048 vty_out(vty, "Address Refcnt Community\n");
718e3744 10049
d62a17ae 10050 hash_iterate(community_hash(),
10051 (void (*)(struct hash_backet *,
10052 void *))community_show_all_iterator,
10053 vty);
718e3744 10054
d62a17ae 10055 return CMD_SUCCESS;
718e3744 10056}
10057
d62a17ae 10058static void lcommunity_show_all_iterator(struct hash_backet *backet,
10059 struct vty *vty)
57d187bc 10060{
d62a17ae 10061 struct lcommunity *lcom;
57d187bc 10062
d62a17ae 10063 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10064 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
d62a17ae 10065 lcommunity_str(lcom));
57d187bc
JS
10066}
10067
10068/* Show BGP's community internal data. */
10069DEFUN (show_ip_bgp_lcommunity_info,
10070 show_ip_bgp_lcommunity_info_cmd,
10071 "show ip bgp large-community-info",
10072 SHOW_STR
10073 IP_STR
10074 BGP_STR
10075 "List all bgp large-community information\n")
10076{
d62a17ae 10077 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10078
d62a17ae 10079 hash_iterate(lcommunity_hash(),
10080 (void (*)(struct hash_backet *,
10081 void *))lcommunity_show_all_iterator,
10082 vty);
57d187bc 10083
d62a17ae 10084 return CMD_SUCCESS;
57d187bc
JS
10085}
10086
10087
f412b39a 10088DEFUN (show_ip_bgp_attr_info,
718e3744 10089 show_ip_bgp_attr_info_cmd,
bec37ba5 10090 "show [ip] bgp attribute-info",
718e3744 10091 SHOW_STR
10092 IP_STR
10093 BGP_STR
10094 "List all bgp attribute information\n")
10095{
d62a17ae 10096 attr_show_all(vty);
10097 return CMD_SUCCESS;
718e3744 10098}
6b0655a2 10099
d62a17ae 10100static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10101 safi_t safi)
f186de26 10102{
d62a17ae 10103 struct listnode *node, *nnode;
10104 struct bgp *bgp;
f186de26 10105
d62a17ae 10106 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10107 vty_out(vty, "\nInstance %s:\n",
10108 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10109 ? "Default"
10110 : bgp->name);
10111 update_group_show(bgp, afi, safi, vty, 0);
10112 }
f186de26 10113}
10114
d62a17ae 10115static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10116 int safi, uint64_t subgrp_id)
4fb25c53 10117{
d62a17ae 10118 struct bgp *bgp;
4fb25c53 10119
d62a17ae 10120 if (name) {
10121 if (strmatch(name, "all")) {
10122 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10123 return CMD_SUCCESS;
10124 } else {
10125 bgp = bgp_lookup_by_name(name);
10126 }
10127 } else {
10128 bgp = bgp_get_default();
10129 }
4fb25c53 10130
d62a17ae 10131 if (bgp)
10132 update_group_show(bgp, afi, safi, vty, subgrp_id);
10133 return CMD_SUCCESS;
4fb25c53
DW
10134}
10135
8fe8a7f6
DS
10136DEFUN (show_ip_bgp_updgrps,
10137 show_ip_bgp_updgrps_cmd,
c1a44e43 10138 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 10139 SHOW_STR
10140 IP_STR
10141 BGP_STR
10142 BGP_INSTANCE_HELP_STR
c9e571b4 10143 BGP_AFI_HELP_STR
9bedbb1e 10144 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
10145 "Detailed info about dynamic update groups\n"
10146 "Specific subgroup to display detailed info for\n")
8386ac43 10147{
d62a17ae 10148 char *vrf = NULL;
10149 afi_t afi = AFI_IP6;
10150 safi_t safi = SAFI_UNICAST;
10151 uint64_t subgrp_id = 0;
10152
10153 int idx = 0;
10154
10155 /* show [ip] bgp */
10156 if (argv_find(argv, argc, "ip", &idx))
10157 afi = AFI_IP;
10158 /* [<view|vrf> VIEWVRFNAME] */
10159 if (argv_find(argv, argc, "view", &idx)
10160 || argv_find(argv, argc, "vrf", &idx))
10161 vrf = argv[++idx]->arg;
10162 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10163 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10164 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10165 }
5bf15956 10166
d62a17ae 10167 /* get subgroup id, if provided */
10168 idx = argc - 1;
10169 if (argv[idx]->type == VARIABLE_TKN)
10170 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 10171
d62a17ae 10172 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
10173}
10174
f186de26 10175DEFUN (show_bgp_instance_all_ipv6_updgrps,
10176 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 10177 "show [ip] bgp <view|vrf> all update-groups",
f186de26 10178 SHOW_STR
716b2d8a 10179 IP_STR
f186de26 10180 BGP_STR
10181 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 10182 "Detailed info about dynamic update groups\n")
f186de26 10183{
d62a17ae 10184 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10185 return CMD_SUCCESS;
f186de26 10186}
10187
5bf15956
DW
10188DEFUN (show_bgp_updgrps_stats,
10189 show_bgp_updgrps_stats_cmd,
716b2d8a 10190 "show [ip] bgp update-groups statistics",
3f9c7369 10191 SHOW_STR
716b2d8a 10192 IP_STR
3f9c7369 10193 BGP_STR
0c7b1b01 10194 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10195 "Statistics\n")
10196{
d62a17ae 10197 struct bgp *bgp;
3f9c7369 10198
d62a17ae 10199 bgp = bgp_get_default();
10200 if (bgp)
10201 update_group_show_stats(bgp, vty);
3f9c7369 10202
d62a17ae 10203 return CMD_SUCCESS;
3f9c7369
DS
10204}
10205
8386ac43 10206DEFUN (show_bgp_instance_updgrps_stats,
10207 show_bgp_instance_updgrps_stats_cmd,
18c57037 10208 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 10209 SHOW_STR
716b2d8a 10210 IP_STR
8386ac43 10211 BGP_STR
10212 BGP_INSTANCE_HELP_STR
0c7b1b01 10213 "Detailed info about dynamic update groups\n"
8386ac43 10214 "Statistics\n")
10215{
d62a17ae 10216 int idx_word = 3;
10217 struct bgp *bgp;
8386ac43 10218
d62a17ae 10219 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10220 if (bgp)
10221 update_group_show_stats(bgp, vty);
8386ac43 10222
d62a17ae 10223 return CMD_SUCCESS;
8386ac43 10224}
10225
d62a17ae 10226static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10227 afi_t afi, safi_t safi,
10228 const char *what, uint64_t subgrp_id)
3f9c7369 10229{
d62a17ae 10230 struct bgp *bgp;
8386ac43 10231
d62a17ae 10232 if (name)
10233 bgp = bgp_lookup_by_name(name);
10234 else
10235 bgp = bgp_get_default();
8386ac43 10236
d62a17ae 10237 if (bgp) {
10238 if (!strcmp(what, "advertise-queue"))
10239 update_group_show_adj_queue(bgp, afi, safi, vty,
10240 subgrp_id);
10241 else if (!strcmp(what, "advertised-routes"))
10242 update_group_show_advertised(bgp, afi, safi, vty,
10243 subgrp_id);
10244 else if (!strcmp(what, "packet-queue"))
10245 update_group_show_packet_queue(bgp, afi, safi, vty,
10246 subgrp_id);
10247 }
3f9c7369
DS
10248}
10249
10250DEFUN (show_ip_bgp_updgrps_adj,
10251 show_ip_bgp_updgrps_adj_cmd,
716b2d8a 10252 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10253 SHOW_STR
10254 IP_STR
10255 BGP_STR
0c7b1b01 10256 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10257 "Advertisement queue\n"
10258 "Announced routes\n"
10259 "Packet queue\n")
10260{
d62a17ae 10261 int idx_type = 4;
10262 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10263 argv[idx_type]->arg, 0);
10264 return CMD_SUCCESS;
8386ac43 10265}
10266
10267DEFUN (show_ip_bgp_instance_updgrps_adj,
10268 show_ip_bgp_instance_updgrps_adj_cmd,
18c57037 10269 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10270 SHOW_STR
10271 IP_STR
10272 BGP_STR
10273 BGP_INSTANCE_HELP_STR
0c7b1b01 10274 "Detailed info about dynamic update groups\n"
8386ac43 10275 "Advertisement queue\n"
10276 "Announced routes\n"
10277 "Packet queue\n")
8386ac43 10278{
d62a17ae 10279 int idx_word = 4;
10280 int idx_type = 6;
10281 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP,
10282 SAFI_UNICAST, argv[idx_type]->arg, 0);
10283 return CMD_SUCCESS;
3f9c7369
DS
10284}
10285
10286DEFUN (show_bgp_updgrps_afi_adj,
10287 show_bgp_updgrps_afi_adj_cmd,
46f296b4 10288 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10289 SHOW_STR
716b2d8a 10290 IP_STR
3f9c7369 10291 BGP_STR
46f296b4 10292 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10293 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10294 "Advertisement queue\n"
10295 "Announced routes\n"
7111c1a0 10296 "Packet queue\n")
3f9c7369 10297{
d62a17ae 10298 int idx_afi = 2;
10299 int idx_safi = 3;
10300 int idx_type = 5;
10301 show_bgp_updgrps_adj_info_aux(
10302 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10303 bgp_vty_safi_from_str(argv[idx_safi]->text),
10304 argv[idx_type]->arg, 0);
10305 return CMD_SUCCESS;
3f9c7369
DS
10306}
10307
10308DEFUN (show_bgp_updgrps_adj,
10309 show_bgp_updgrps_adj_cmd,
716b2d8a 10310 "show [ip] bgp update-groups <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10311 SHOW_STR
716b2d8a 10312 IP_STR
3f9c7369 10313 BGP_STR
0c7b1b01 10314 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10315 "Advertisement queue\n"
10316 "Announced routes\n"
10317 "Packet queue\n")
10318{
d62a17ae 10319 int idx_type = 3;
10320 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10321 argv[idx_type]->arg, 0);
10322 return CMD_SUCCESS;
8386ac43 10323}
10324
10325DEFUN (show_bgp_instance_updgrps_adj,
10326 show_bgp_instance_updgrps_adj_cmd,
18c57037 10327 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10328 SHOW_STR
716b2d8a 10329 IP_STR
8386ac43 10330 BGP_STR
10331 BGP_INSTANCE_HELP_STR
0c7b1b01 10332 "Detailed info about dynamic update groups\n"
8386ac43 10333 "Advertisement queue\n"
10334 "Announced routes\n"
10335 "Packet queue\n")
10336{
d62a17ae 10337 int idx_word = 3;
10338 int idx_type = 5;
10339 show_bgp_updgrps_adj_info_aux(vty, argv[idx_word]->arg, AFI_IP6,
10340 SAFI_UNICAST, argv[idx_type]->arg, 0);
10341 return CMD_SUCCESS;
3f9c7369
DS
10342}
10343
10344DEFUN (show_ip_bgp_updgrps_adj_s,
8fe8a7f6 10345 show_ip_bgp_updgrps_adj_s_cmd,
716b2d8a 10346 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369
DS
10347 SHOW_STR
10348 IP_STR
10349 BGP_STR
0c7b1b01 10350 "Detailed info about dynamic update groups\n"
8fe8a7f6 10351 "Specific subgroup to display info for\n"
3f9c7369
DS
10352 "Advertisement queue\n"
10353 "Announced routes\n"
10354 "Packet queue\n")
3f9c7369 10355{
d62a17ae 10356 int idx_subgroup_id = 4;
10357 int idx_type = 5;
10358 uint64_t subgrp_id;
8fe8a7f6 10359
d62a17ae 10360 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10361
d62a17ae 10362 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP, SAFI_UNICAST,
10363 argv[idx_type]->arg, subgrp_id);
10364 return CMD_SUCCESS;
8386ac43 10365}
10366
10367DEFUN (show_ip_bgp_instance_updgrps_adj_s,
10368 show_ip_bgp_instance_updgrps_adj_s_cmd,
18c57037 10369 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10370 SHOW_STR
10371 IP_STR
10372 BGP_STR
10373 BGP_INSTANCE_HELP_STR
0c7b1b01 10374 "Detailed info about dynamic update groups\n"
8386ac43 10375 "Specific subgroup to display info for\n"
10376 "Advertisement queue\n"
10377 "Announced routes\n"
10378 "Packet queue\n")
8386ac43 10379{
d62a17ae 10380 int idx_vrf = 4;
10381 int idx_subgroup_id = 6;
10382 int idx_type = 7;
10383 uint64_t subgrp_id;
8386ac43 10384
d62a17ae 10385 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8386ac43 10386
d62a17ae 10387 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP,
10388 SAFI_UNICAST, argv[idx_type]->arg,
10389 subgrp_id);
10390 return CMD_SUCCESS;
3f9c7369
DS
10391}
10392
8fe8a7f6
DS
10393DEFUN (show_bgp_updgrps_afi_adj_s,
10394 show_bgp_updgrps_afi_adj_s_cmd,
46f296b4 10395 "show [ip] bgp "BGP_AFI_SAFI_CMD_STR" update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
3f9c7369 10396 SHOW_STR
716b2d8a 10397 IP_STR
3f9c7369 10398 BGP_STR
46f296b4 10399 BGP_AFI_SAFI_HELP_STR
0c7b1b01 10400 "Detailed info about dynamic update groups\n"
8fe8a7f6 10401 "Specific subgroup to display info for\n"
3f9c7369
DS
10402 "Advertisement queue\n"
10403 "Announced routes\n"
7111c1a0 10404 "Packet queue\n")
3f9c7369 10405{
d62a17ae 10406 int idx_afi = 2;
10407 int idx_safi = 3;
10408 int idx_subgroup_id = 5;
10409 int idx_type = 6;
10410 uint64_t subgrp_id;
3f9c7369 10411
d62a17ae 10412 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10413
d62a17ae 10414 show_bgp_updgrps_adj_info_aux(
10415 vty, NULL, bgp_vty_afi_from_str(argv[idx_afi]->text),
10416 bgp_vty_safi_from_str(argv[idx_safi]->text),
10417 argv[idx_type]->arg, subgrp_id);
10418 return CMD_SUCCESS;
3f9c7369
DS
10419}
10420
8fe8a7f6
DS
10421DEFUN (show_bgp_updgrps_adj_s,
10422 show_bgp_updgrps_adj_s_cmd,
716b2d8a 10423 "show [ip] bgp update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8fe8a7f6 10424 SHOW_STR
716b2d8a 10425 IP_STR
8fe8a7f6 10426 BGP_STR
0c7b1b01 10427 "Detailed info about dynamic update groups\n"
8fe8a7f6
DS
10428 "Specific subgroup to display info for\n"
10429 "Advertisement queue\n"
10430 "Announced routes\n"
10431 "Packet queue\n")
10432{
d62a17ae 10433 int idx_subgroup_id = 3;
10434 int idx_type = 4;
10435 uint64_t subgrp_id;
8fe8a7f6 10436
d62a17ae 10437 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
8fe8a7f6 10438
d62a17ae 10439 show_bgp_updgrps_adj_info_aux(vty, NULL, AFI_IP6, SAFI_UNICAST,
10440 argv[idx_type]->arg, subgrp_id);
10441 return CMD_SUCCESS;
8fe8a7f6
DS
10442}
10443
8386ac43 10444DEFUN (show_bgp_instance_updgrps_adj_s,
10445 show_bgp_instance_updgrps_adj_s_cmd,
18c57037 10446 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
8386ac43 10447 SHOW_STR
716b2d8a 10448 IP_STR
8386ac43 10449 BGP_STR
10450 BGP_INSTANCE_HELP_STR
0c7b1b01 10451 "Detailed info about dynamic update groups\n"
8386ac43 10452 "Specific subgroup to display info for\n"
10453 "Advertisement queue\n"
10454 "Announced routes\n"
10455 "Packet queue\n")
10456{
d62a17ae 10457 int idx_vrf = 3;
10458 int idx_subgroup_id = 5;
10459 int idx_type = 6;
10460 uint64_t subgrp_id;
10461
10462 subgrp_id = strtoull(argv[idx_subgroup_id]->arg, NULL, 10);
10463
10464 show_bgp_updgrps_adj_info_aux(vty, argv[idx_vrf]->arg, AFI_IP6,
10465 SAFI_UNICAST, argv[idx_type]->arg,
10466 subgrp_id);
10467 return CMD_SUCCESS;
10468}
10469
10470
10471static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10472{
10473 struct listnode *node, *nnode;
10474 struct prefix *range;
10475 struct peer *conf;
10476 struct peer *peer;
10477 char buf[PREFIX2STR_BUFFER];
10478 afi_t afi;
10479 safi_t safi;
10480 const char *peer_status;
10481 const char *af_str;
10482 int lr_count;
10483 int dynamic;
10484 int af_cfgd;
10485
10486 conf = group->conf;
10487
10488 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10489 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10490 conf->as);
10491 } else if (conf->as_type == AS_INTERNAL) {
10492 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10493 group->bgp->as);
10494 } else {
10495 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10496 }
f14e6fdb 10497
d62a17ae 10498 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10499 vty_out(vty, " Peer-group type is internal\n");
10500 else
10501 vty_out(vty, " Peer-group type is external\n");
10502
10503 /* Display AFs configured. */
10504 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
10505 FOREACH_AFI_SAFI (afi, safi) {
10506 if (conf->afc[afi][safi]) {
10507 af_cfgd = 1;
10508 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 10509 }
05c7a1cc 10510 }
d62a17ae 10511 if (!af_cfgd)
10512 vty_out(vty, " none\n");
10513 else
10514 vty_out(vty, "\n");
10515
10516 /* Display listen ranges (for dynamic neighbors), if any */
10517 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10518 if (afi == AFI_IP)
10519 af_str = "IPv4";
10520 else if (afi == AFI_IP6)
10521 af_str = "IPv6";
10522 else
10523 af_str = "???";
10524 lr_count = listcount(group->listen_range[afi]);
10525 if (lr_count) {
10526 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10527 af_str);
10528
10529
10530 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10531 nnode, range)) {
10532 prefix2str(range, buf, sizeof(buf));
10533 vty_out(vty, " %s\n", buf);
10534 }
10535 }
10536 }
f14e6fdb 10537
d62a17ae 10538 /* Display group members and their status */
10539 if (listcount(group->peer)) {
10540 vty_out(vty, " Peer-group members:\n");
10541 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10542 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10543 peer_status = "Idle (Admin)";
10544 else if (CHECK_FLAG(peer->sflags,
10545 PEER_STATUS_PREFIX_OVERFLOW))
10546 peer_status = "Idle (PfxCt)";
10547 else
10548 peer_status = lookup_msg(bgp_status_msg,
10549 peer->status, NULL);
10550
10551 dynamic = peer_dynamic_neighbor(peer);
10552 vty_out(vty, " %s %s %s \n", peer->host,
10553 dynamic ? "(dynamic)" : "", peer_status);
10554 }
10555 }
f14e6fdb 10556
d62a17ae 10557 return CMD_SUCCESS;
10558}
10559
ff9959b0
QY
10560static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10561 const char *group_name)
d62a17ae 10562{
ff9959b0 10563 struct bgp *bgp;
d62a17ae 10564 struct listnode *node, *nnode;
10565 struct peer_group *group;
ff9959b0
QY
10566 bool found = false;
10567
10568 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
10569
10570 if (!bgp) {
10571 vty_out(vty, "%% No such BGP instance exists\n");
10572 return CMD_WARNING;
10573 }
d62a17ae 10574
10575 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
10576 if (group_name) {
10577 if (strmatch(group->name, group_name)) {
d62a17ae 10578 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
10579 found = true;
10580 break;
d62a17ae 10581 }
ff9959b0
QY
10582 } else {
10583 bgp_show_one_peer_group(vty, group);
d62a17ae 10584 }
f14e6fdb 10585 }
f14e6fdb 10586
ff9959b0 10587 if (group_name && !found)
d62a17ae 10588 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 10589
d62a17ae 10590 return CMD_SUCCESS;
f14e6fdb
DS
10591}
10592
f14e6fdb
DS
10593DEFUN (show_ip_bgp_peer_groups,
10594 show_ip_bgp_peer_groups_cmd,
18c57037 10595 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10596 SHOW_STR
10597 IP_STR
10598 BGP_STR
8386ac43 10599 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10600 "Detailed information on BGP peer groups\n"
10601 "Peer group name\n")
f14e6fdb 10602{
d62a17ae 10603 char *vrf, *pg;
10604 vrf = pg = NULL;
10605 int idx = 0;
f14e6fdb 10606
1d35f218 10607 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg : NULL;
d62a17ae 10608 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10609
ff9959b0 10610 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 10611}
3f9c7369 10612
d6e3c605 10613
718e3744 10614/* Redistribute VTY commands. */
10615
718e3744 10616DEFUN (bgp_redistribute_ipv4,
10617 bgp_redistribute_ipv4_cmd,
40d1cbfb 10618 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 10619 "Redistribute information from another routing protocol\n"
ab0181ee 10620 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 10621{
d62a17ae 10622 VTY_DECLVAR_CONTEXT(bgp, bgp);
10623 int idx_protocol = 1;
10624 int type;
718e3744 10625
d62a17ae 10626 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10627 if (type < 0) {
10628 vty_out(vty, "%% Invalid route type\n");
10629 return CMD_WARNING_CONFIG_FAILED;
10630 }
7f323236 10631
d62a17ae 10632 bgp_redist_add(bgp, AFI_IP, type, 0);
10633 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10634}
10635
d62a17ae 10636ALIAS_HIDDEN(
10637 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10638 "redistribute " FRR_IP_REDIST_STR_BGPD,
10639 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 10640
718e3744 10641DEFUN (bgp_redistribute_ipv4_rmap,
10642 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 10643 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 10644 "Redistribute information from another routing protocol\n"
ab0181ee 10645 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10646 "Route map reference\n"
10647 "Pointer to route-map entries\n")
10648{
d62a17ae 10649 VTY_DECLVAR_CONTEXT(bgp, bgp);
10650 int idx_protocol = 1;
10651 int idx_word = 3;
10652 int type;
10653 struct bgp_redist *red;
718e3744 10654
d62a17ae 10655 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10656 if (type < 0) {
10657 vty_out(vty, "%% Invalid route type\n");
10658 return CMD_WARNING_CONFIG_FAILED;
10659 }
718e3744 10660
d62a17ae 10661 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10662 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10663 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10664}
10665
d62a17ae 10666ALIAS_HIDDEN(
10667 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
10668 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
10669 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10670 "Route map reference\n"
10671 "Pointer to route-map entries\n")
596c17ba 10672
718e3744 10673DEFUN (bgp_redistribute_ipv4_metric,
10674 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 10675 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 10676 "Redistribute information from another routing protocol\n"
ab0181ee 10677 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10678 "Metric for redistributed routes\n"
10679 "Default metric\n")
10680{
d62a17ae 10681 VTY_DECLVAR_CONTEXT(bgp, bgp);
10682 int idx_protocol = 1;
10683 int idx_number = 3;
10684 int type;
10685 u_int32_t metric;
10686 struct bgp_redist *red;
10687
10688 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10689 if (type < 0) {
10690 vty_out(vty, "%% Invalid route type\n");
10691 return CMD_WARNING_CONFIG_FAILED;
10692 }
10693 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10694
10695 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10696 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10697 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10698}
10699
10700ALIAS_HIDDEN(
10701 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
10702 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
10703 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10704 "Metric for redistributed routes\n"
10705 "Default metric\n")
596c17ba 10706
718e3744 10707DEFUN (bgp_redistribute_ipv4_rmap_metric,
10708 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 10709 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 10710 "Redistribute information from another routing protocol\n"
ab0181ee 10711 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10712 "Route map reference\n"
10713 "Pointer to route-map entries\n"
10714 "Metric for redistributed routes\n"
10715 "Default metric\n")
10716{
d62a17ae 10717 VTY_DECLVAR_CONTEXT(bgp, bgp);
10718 int idx_protocol = 1;
10719 int idx_word = 3;
10720 int idx_number = 5;
10721 int type;
10722 u_int32_t metric;
10723 struct bgp_redist *red;
10724
10725 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10726 if (type < 0) {
10727 vty_out(vty, "%% Invalid route type\n");
10728 return CMD_WARNING_CONFIG_FAILED;
10729 }
10730 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10731
10732 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10733 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10734 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10735 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10736}
10737
10738ALIAS_HIDDEN(
10739 bgp_redistribute_ipv4_rmap_metric,
10740 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
10741 "redistribute " FRR_IP_REDIST_STR_BGPD
10742 " route-map WORD metric (0-4294967295)",
10743 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10744 "Route map reference\n"
10745 "Pointer to route-map entries\n"
10746 "Metric for redistributed routes\n"
10747 "Default metric\n")
596c17ba 10748
718e3744 10749DEFUN (bgp_redistribute_ipv4_metric_rmap,
10750 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 10751 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 10752 "Redistribute information from another routing protocol\n"
ab0181ee 10753 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10754 "Metric for redistributed routes\n"
10755 "Default metric\n"
10756 "Route map reference\n"
10757 "Pointer to route-map entries\n")
10758{
d62a17ae 10759 VTY_DECLVAR_CONTEXT(bgp, bgp);
10760 int idx_protocol = 1;
10761 int idx_number = 3;
10762 int idx_word = 5;
10763 int type;
10764 u_int32_t metric;
10765 struct bgp_redist *red;
10766
10767 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10768 if (type < 0) {
10769 vty_out(vty, "%% Invalid route type\n");
10770 return CMD_WARNING_CONFIG_FAILED;
10771 }
10772 metric = strtoul(argv[idx_number]->arg, NULL, 10);
10773
10774 red = bgp_redist_add(bgp, AFI_IP, type, 0);
10775 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
10776 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10777 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
10778}
10779
10780ALIAS_HIDDEN(
10781 bgp_redistribute_ipv4_metric_rmap,
10782 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
10783 "redistribute " FRR_IP_REDIST_STR_BGPD
10784 " metric (0-4294967295) route-map WORD",
10785 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
10786 "Metric for redistributed routes\n"
10787 "Default metric\n"
10788 "Route map reference\n"
10789 "Pointer to route-map entries\n")
596c17ba 10790
7c8ff89e
DS
10791DEFUN (bgp_redistribute_ipv4_ospf,
10792 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 10793 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
10794 "Redistribute information from another routing protocol\n"
10795 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10796 "Non-main Kernel Routing Table\n"
10797 "Instance ID/Table ID\n")
7c8ff89e 10798{
d62a17ae 10799 VTY_DECLVAR_CONTEXT(bgp, bgp);
10800 int idx_ospf_table = 1;
10801 int idx_number = 2;
10802 u_short instance;
10803 u_short protocol;
7c8ff89e 10804
d62a17ae 10805 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 10806
d62a17ae 10807 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10808 protocol = ZEBRA_ROUTE_OSPF;
10809 else
10810 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 10811
d62a17ae 10812 bgp_redist_add(bgp, AFI_IP, protocol, instance);
10813 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
10814}
10815
d62a17ae 10816ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
10817 "redistribute <ospf|table> (1-65535)",
10818 "Redistribute information from another routing protocol\n"
10819 "Open Shortest Path First (OSPFv2)\n"
10820 "Non-main Kernel Routing Table\n"
10821 "Instance ID/Table ID\n")
596c17ba 10822
7c8ff89e
DS
10823DEFUN (bgp_redistribute_ipv4_ospf_rmap,
10824 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 10825 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
10826 "Redistribute information from another routing protocol\n"
10827 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10828 "Non-main Kernel Routing Table\n"
10829 "Instance ID/Table ID\n"
7c8ff89e
DS
10830 "Route map reference\n"
10831 "Pointer to route-map entries\n")
10832{
d62a17ae 10833 VTY_DECLVAR_CONTEXT(bgp, bgp);
10834 int idx_ospf_table = 1;
10835 int idx_number = 2;
10836 int idx_word = 4;
10837 struct bgp_redist *red;
10838 u_short instance;
10839 int protocol;
10840
10841 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10842 protocol = ZEBRA_ROUTE_OSPF;
10843 else
10844 protocol = ZEBRA_ROUTE_TABLE;
10845
10846 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10847 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10848 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10849 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10850}
10851
10852ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
10853 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
10854 "redistribute <ospf|table> (1-65535) route-map WORD",
10855 "Redistribute information from another routing protocol\n"
10856 "Open Shortest Path First (OSPFv2)\n"
10857 "Non-main Kernel Routing Table\n"
10858 "Instance ID/Table ID\n"
10859 "Route map reference\n"
10860 "Pointer to route-map entries\n")
596c17ba 10861
7c8ff89e
DS
10862DEFUN (bgp_redistribute_ipv4_ospf_metric,
10863 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 10864 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
10865 "Redistribute information from another routing protocol\n"
10866 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10867 "Non-main Kernel Routing Table\n"
10868 "Instance ID/Table ID\n"
7c8ff89e
DS
10869 "Metric for redistributed routes\n"
10870 "Default metric\n")
10871{
d62a17ae 10872 VTY_DECLVAR_CONTEXT(bgp, bgp);
10873 int idx_ospf_table = 1;
10874 int idx_number = 2;
10875 int idx_number_2 = 4;
10876 u_int32_t metric;
10877 struct bgp_redist *red;
10878 u_short instance;
10879 int protocol;
10880
10881 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10882 protocol = ZEBRA_ROUTE_OSPF;
10883 else
10884 protocol = ZEBRA_ROUTE_TABLE;
10885
10886 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10887 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10888
10889 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10890 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10891 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10892}
10893
10894ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
10895 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
10896 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
10897 "Redistribute information from another routing protocol\n"
10898 "Open Shortest Path First (OSPFv2)\n"
10899 "Non-main Kernel Routing Table\n"
10900 "Instance ID/Table ID\n"
10901 "Metric for redistributed routes\n"
10902 "Default metric\n")
596c17ba 10903
7c8ff89e
DS
10904DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
10905 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 10906 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
10907 "Redistribute information from another routing protocol\n"
10908 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10909 "Non-main Kernel Routing Table\n"
10910 "Instance ID/Table ID\n"
7c8ff89e
DS
10911 "Route map reference\n"
10912 "Pointer to route-map entries\n"
10913 "Metric for redistributed routes\n"
10914 "Default metric\n")
10915{
d62a17ae 10916 VTY_DECLVAR_CONTEXT(bgp, bgp);
10917 int idx_ospf_table = 1;
10918 int idx_number = 2;
10919 int idx_word = 4;
10920 int idx_number_2 = 6;
10921 u_int32_t metric;
10922 struct bgp_redist *red;
10923 u_short instance;
10924 int protocol;
10925
10926 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10927 protocol = ZEBRA_ROUTE_OSPF;
10928 else
10929 protocol = ZEBRA_ROUTE_TABLE;
10930
10931 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10932 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10933
10934 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10935 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10936 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10937 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10938}
10939
10940ALIAS_HIDDEN(
10941 bgp_redistribute_ipv4_ospf_rmap_metric,
10942 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
10943 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
10944 "Redistribute information from another routing protocol\n"
10945 "Open Shortest Path First (OSPFv2)\n"
10946 "Non-main Kernel Routing Table\n"
10947 "Instance ID/Table ID\n"
10948 "Route map reference\n"
10949 "Pointer to route-map entries\n"
10950 "Metric for redistributed routes\n"
10951 "Default metric\n")
596c17ba 10952
7c8ff89e
DS
10953DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
10954 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 10955 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
10956 "Redistribute information from another routing protocol\n"
10957 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
10958 "Non-main Kernel Routing Table\n"
10959 "Instance ID/Table ID\n"
7c8ff89e
DS
10960 "Metric for redistributed routes\n"
10961 "Default metric\n"
10962 "Route map reference\n"
10963 "Pointer to route-map entries\n")
10964{
d62a17ae 10965 VTY_DECLVAR_CONTEXT(bgp, bgp);
10966 int idx_ospf_table = 1;
10967 int idx_number = 2;
10968 int idx_number_2 = 4;
10969 int idx_word = 6;
10970 u_int32_t metric;
10971 struct bgp_redist *red;
10972 u_short instance;
10973 int protocol;
10974
10975 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
10976 protocol = ZEBRA_ROUTE_OSPF;
10977 else
10978 protocol = ZEBRA_ROUTE_TABLE;
10979
10980 instance = strtoul(argv[idx_number]->arg, NULL, 10);
10981 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
10982
10983 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
10984 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
10985 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
10986 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
10987}
10988
10989ALIAS_HIDDEN(
10990 bgp_redistribute_ipv4_ospf_metric_rmap,
10991 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
10992 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
10993 "Redistribute information from another routing protocol\n"
10994 "Open Shortest Path First (OSPFv2)\n"
10995 "Non-main Kernel Routing Table\n"
10996 "Instance ID/Table ID\n"
10997 "Metric for redistributed routes\n"
10998 "Default metric\n"
10999 "Route map reference\n"
11000 "Pointer to route-map entries\n")
596c17ba 11001
7c8ff89e
DS
11002DEFUN (no_bgp_redistribute_ipv4_ospf,
11003 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11004 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11005 NO_STR
11006 "Redistribute information from another routing protocol\n"
11007 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11008 "Non-main Kernel Routing Table\n"
31500417
DW
11009 "Instance ID/Table ID\n"
11010 "Metric for redistributed routes\n"
11011 "Default metric\n"
11012 "Route map reference\n"
11013 "Pointer to route-map entries\n")
7c8ff89e 11014{
d62a17ae 11015 VTY_DECLVAR_CONTEXT(bgp, bgp);
11016 int idx_ospf_table = 2;
11017 int idx_number = 3;
11018 u_short instance;
11019 int protocol;
11020
11021 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11022 protocol = ZEBRA_ROUTE_OSPF;
11023 else
11024 protocol = ZEBRA_ROUTE_TABLE;
11025
11026 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11027 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11028}
11029
11030ALIAS_HIDDEN(
11031 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11032 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11033 NO_STR
11034 "Redistribute information from another routing protocol\n"
11035 "Open Shortest Path First (OSPFv2)\n"
11036 "Non-main Kernel Routing Table\n"
11037 "Instance ID/Table ID\n"
11038 "Metric for redistributed routes\n"
11039 "Default metric\n"
11040 "Route map reference\n"
11041 "Pointer to route-map entries\n")
596c17ba 11042
718e3744 11043DEFUN (no_bgp_redistribute_ipv4,
11044 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11045 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11046 NO_STR
11047 "Redistribute information from another routing protocol\n"
3b14d86e 11048 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11049 "Metric for redistributed routes\n"
11050 "Default metric\n"
11051 "Route map reference\n"
11052 "Pointer to route-map entries\n")
718e3744 11053{
d62a17ae 11054 VTY_DECLVAR_CONTEXT(bgp, bgp);
11055 int idx_protocol = 2;
11056 int type;
11057
11058 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11059 if (type < 0) {
11060 vty_out(vty, "%% Invalid route type\n");
11061 return CMD_WARNING_CONFIG_FAILED;
11062 }
11063 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11064}
11065
11066ALIAS_HIDDEN(
11067 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11068 "no redistribute " FRR_IP_REDIST_STR_BGPD
11069 " [metric (0-4294967295)] [route-map WORD]",
11070 NO_STR
11071 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11072 "Metric for redistributed routes\n"
11073 "Default metric\n"
11074 "Route map reference\n"
11075 "Pointer to route-map entries\n")
596c17ba 11076
718e3744 11077DEFUN (bgp_redistribute_ipv6,
11078 bgp_redistribute_ipv6_cmd,
40d1cbfb 11079 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11080 "Redistribute information from another routing protocol\n"
ab0181ee 11081 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11082{
d62a17ae 11083 VTY_DECLVAR_CONTEXT(bgp, bgp);
11084 int idx_protocol = 1;
11085 int type;
718e3744 11086
d62a17ae 11087 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11088 if (type < 0) {
11089 vty_out(vty, "%% Invalid route type\n");
11090 return CMD_WARNING_CONFIG_FAILED;
11091 }
718e3744 11092
d62a17ae 11093 bgp_redist_add(bgp, AFI_IP6, type, 0);
11094 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11095}
11096
11097DEFUN (bgp_redistribute_ipv6_rmap,
11098 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11099 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11100 "Redistribute information from another routing protocol\n"
ab0181ee 11101 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11102 "Route map reference\n"
11103 "Pointer to route-map entries\n")
11104{
d62a17ae 11105 VTY_DECLVAR_CONTEXT(bgp, bgp);
11106 int idx_protocol = 1;
11107 int idx_word = 3;
11108 int type;
11109 struct bgp_redist *red;
718e3744 11110
d62a17ae 11111 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11112 if (type < 0) {
11113 vty_out(vty, "%% Invalid route type\n");
11114 return CMD_WARNING_CONFIG_FAILED;
11115 }
718e3744 11116
d62a17ae 11117 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11118 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11119 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11120}
11121
11122DEFUN (bgp_redistribute_ipv6_metric,
11123 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11124 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11125 "Redistribute information from another routing protocol\n"
ab0181ee 11126 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11127 "Metric for redistributed routes\n"
11128 "Default metric\n")
11129{
d62a17ae 11130 VTY_DECLVAR_CONTEXT(bgp, bgp);
11131 int idx_protocol = 1;
11132 int idx_number = 3;
11133 int type;
11134 u_int32_t metric;
11135 struct bgp_redist *red;
11136
11137 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11138 if (type < 0) {
11139 vty_out(vty, "%% Invalid route type\n");
11140 return CMD_WARNING_CONFIG_FAILED;
11141 }
11142 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11143
d62a17ae 11144 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11145 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11146 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11147}
11148
11149DEFUN (bgp_redistribute_ipv6_rmap_metric,
11150 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11151 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11152 "Redistribute information from another routing protocol\n"
ab0181ee 11153 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11154 "Route map reference\n"
11155 "Pointer to route-map entries\n"
11156 "Metric for redistributed routes\n"
11157 "Default metric\n")
11158{
d62a17ae 11159 VTY_DECLVAR_CONTEXT(bgp, bgp);
11160 int idx_protocol = 1;
11161 int idx_word = 3;
11162 int idx_number = 5;
11163 int type;
11164 u_int32_t metric;
11165 struct bgp_redist *red;
11166
11167 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11168 if (type < 0) {
11169 vty_out(vty, "%% Invalid route type\n");
11170 return CMD_WARNING_CONFIG_FAILED;
11171 }
11172 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11173
d62a17ae 11174 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11175 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11176 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11177 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11178}
11179
11180DEFUN (bgp_redistribute_ipv6_metric_rmap,
11181 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11182 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11183 "Redistribute information from another routing protocol\n"
ab0181ee 11184 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11185 "Metric for redistributed routes\n"
11186 "Default metric\n"
11187 "Route map reference\n"
11188 "Pointer to route-map entries\n")
11189{
d62a17ae 11190 VTY_DECLVAR_CONTEXT(bgp, bgp);
11191 int idx_protocol = 1;
11192 int idx_number = 3;
11193 int idx_word = 5;
11194 int type;
11195 u_int32_t metric;
11196 struct bgp_redist *red;
11197
11198 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11199 if (type < 0) {
11200 vty_out(vty, "%% Invalid route type\n");
11201 return CMD_WARNING_CONFIG_FAILED;
11202 }
11203 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11204
d62a17ae 11205 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11206 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11207 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11208 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11209}
11210
11211DEFUN (no_bgp_redistribute_ipv6,
11212 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11213 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11214 NO_STR
11215 "Redistribute information from another routing protocol\n"
3b14d86e 11216 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11217 "Metric for redistributed routes\n"
11218 "Default metric\n"
11219 "Route map reference\n"
11220 "Pointer to route-map entries\n")
718e3744 11221{
d62a17ae 11222 VTY_DECLVAR_CONTEXT(bgp, bgp);
11223 int idx_protocol = 2;
11224 int type;
718e3744 11225
d62a17ae 11226 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11227 if (type < 0) {
11228 vty_out(vty, "%% Invalid route type\n");
11229 return CMD_WARNING_CONFIG_FAILED;
11230 }
718e3744 11231
d62a17ae 11232 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11233}
11234
2b791107 11235void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 11236 safi_t safi)
d62a17ae 11237{
11238 int i;
11239
11240 /* Unicast redistribution only. */
11241 if (safi != SAFI_UNICAST)
2b791107 11242 return;
d62a17ae 11243
11244 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11245 /* Redistribute BGP does not make sense. */
11246 if (i != ZEBRA_ROUTE_BGP) {
11247 struct list *red_list;
11248 struct listnode *node;
11249 struct bgp_redist *red;
11250
11251 red_list = bgp->redist[afi][i];
11252 if (!red_list)
11253 continue;
11254
11255 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 11256 /* "redistribute" configuration. */
11257 vty_out(vty, " redistribute %s",
11258 zebra_route_string(i));
11259 if (red->instance)
11260 vty_out(vty, " %d", red->instance);
11261 if (red->redist_metric_flag)
11262 vty_out(vty, " metric %u",
11263 red->redist_metric);
11264 if (red->rmap.name)
11265 vty_out(vty, " route-map %s",
11266 red->rmap.name);
11267 vty_out(vty, "\n");
11268 }
11269 }
11270 }
718e3744 11271}
6b0655a2 11272
718e3744 11273/* BGP node structure. */
d62a17ae 11274static struct cmd_node bgp_node = {
9d303b37 11275 BGP_NODE, "%s(config-router)# ", 1,
718e3744 11276};
11277
d62a17ae 11278static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 11279 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 11280};
11281
d62a17ae 11282static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 11283 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 11284};
11285
d62a17ae 11286static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 11287 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11288};
11289
d62a17ae 11290static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 11291 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 11292};
11293
d62a17ae 11294static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 11295 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 11296};
11297
d62a17ae 11298static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 11299 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11300};
11301
d62a17ae 11302static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11303 "%s(config-router-af)# ", 1};
6b0655a2 11304
d62a17ae 11305static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11306 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 11307
d62a17ae 11308static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11309 "%s(config-router-evpn)# ", 1};
4e0b7b6d 11310
d62a17ae 11311static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11312 "%s(config-router-af-vni)# ", 1};
90e60aa7 11313
d62a17ae 11314static void community_list_vty(void);
1f8ae70b 11315
d62a17ae 11316static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 11317{
d62a17ae 11318 struct bgp *bgp;
11319 struct peer *peer;
11320 struct peer_group *group;
11321 struct listnode *lnbgp, *lnpeer;
b8a815e5 11322
d62a17ae 11323 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11324 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11325 /* only provide suggestions on the appropriate input
11326 * token type,
11327 * they'll otherwise show up multiple times */
11328 enum cmd_token_type match_type;
11329 char *name = peer->host;
d48ed3e0 11330
d62a17ae 11331 if (peer->conf_if) {
11332 match_type = VARIABLE_TKN;
11333 name = peer->conf_if;
11334 } else if (strchr(peer->host, ':'))
11335 match_type = IPV6_TKN;
11336 else
11337 match_type = IPV4_TKN;
d48ed3e0 11338
d62a17ae 11339 if (token->type != match_type)
11340 continue;
d48ed3e0 11341
d62a17ae 11342 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11343 }
d48ed3e0 11344
d62a17ae 11345 if (token->type == VARIABLE_TKN)
11346 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11347 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11348 group->name));
11349 }
b8a815e5
DL
11350}
11351
11352static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 11353 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11354 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 11355 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 11356 {.completions = NULL}};
11357
11358void bgp_vty_init(void)
11359{
11360 cmd_variable_handler_register(bgp_var_neighbor);
11361
11362 /* Install bgp top node. */
11363 install_node(&bgp_node, bgp_config_write);
11364 install_node(&bgp_ipv4_unicast_node, NULL);
11365 install_node(&bgp_ipv4_multicast_node, NULL);
11366 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11367 install_node(&bgp_ipv6_unicast_node, NULL);
11368 install_node(&bgp_ipv6_multicast_node, NULL);
11369 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11370 install_node(&bgp_vpnv4_node, NULL);
11371 install_node(&bgp_vpnv6_node, NULL);
11372 install_node(&bgp_evpn_node, NULL);
11373 install_node(&bgp_evpn_vni_node, NULL);
11374
11375 /* Install default VTY commands to new nodes. */
11376 install_default(BGP_NODE);
11377 install_default(BGP_IPV4_NODE);
11378 install_default(BGP_IPV4M_NODE);
11379 install_default(BGP_IPV4L_NODE);
11380 install_default(BGP_IPV6_NODE);
11381 install_default(BGP_IPV6M_NODE);
11382 install_default(BGP_IPV6L_NODE);
11383 install_default(BGP_VPNV4_NODE);
11384 install_default(BGP_VPNV6_NODE);
11385 install_default(BGP_EVPN_NODE);
11386 install_default(BGP_EVPN_VNI_NODE);
11387
11388 /* "bgp multiple-instance" commands. */
11389 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11390 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11391
11392 /* "bgp config-type" commands. */
11393 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11394 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11395
11396 /* bgp route-map delay-timer commands. */
11397 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11398 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11399
11400 /* Dummy commands (Currently not supported) */
11401 install_element(BGP_NODE, &no_synchronization_cmd);
11402 install_element(BGP_NODE, &no_auto_summary_cmd);
11403
11404 /* "router bgp" commands. */
11405 install_element(CONFIG_NODE, &router_bgp_cmd);
11406
11407 /* "no router bgp" commands. */
11408 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11409
11410 /* "bgp router-id" commands. */
11411 install_element(BGP_NODE, &bgp_router_id_cmd);
11412 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11413
11414 /* "bgp cluster-id" commands. */
11415 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11416 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11417
11418 /* "bgp confederation" commands. */
11419 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11420 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11421
11422 /* "bgp confederation peers" commands. */
11423 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11424 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11425
11426 /* bgp max-med command */
11427 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11428 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11429 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11430 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11431 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11432
11433 /* bgp disable-ebgp-connected-nh-check */
11434 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11435 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11436
11437 /* bgp update-delay command */
11438 install_element(BGP_NODE, &bgp_update_delay_cmd);
11439 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11440 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11441
11442 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11443 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
11444 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
11445 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 11446
11447 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11448 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11449
11450 /* "maximum-paths" commands. */
11451 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11452 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11453 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11454 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11455 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11456 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11457 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11458 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11459 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11460 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11461 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11462 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11463 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11464 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11465 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11466
11467 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11468 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11469 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11470 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11471 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11472
11473 /* "timers bgp" commands. */
11474 install_element(BGP_NODE, &bgp_timers_cmd);
11475 install_element(BGP_NODE, &no_bgp_timers_cmd);
11476
11477 /* route-map delay-timer commands - per instance for backwards compat.
11478 */
11479 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11480 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11481
11482 /* "bgp client-to-client reflection" commands */
11483 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11484 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11485
11486 /* "bgp always-compare-med" commands */
11487 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11488 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11489
11490 /* "bgp deterministic-med" commands */
11491 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11492 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11493
11494 /* "bgp graceful-restart" commands */
11495 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11496 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11497 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11498 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11499 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11500 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11501
11502 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11503 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11504
7f323236
DW
11505 /* "bgp graceful-shutdown" commands */
11506 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
11507 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
11508
d62a17ae 11509 /* "bgp fast-external-failover" commands */
11510 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11511 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11512
11513 /* "bgp enforce-first-as" commands */
11514 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11515 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11516
11517 /* "bgp bestpath compare-routerid" commands */
11518 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11519 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11520
11521 /* "bgp bestpath as-path ignore" commands */
11522 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11523 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11524
11525 /* "bgp bestpath as-path confed" commands */
11526 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11527 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11528
11529 /* "bgp bestpath as-path multipath-relax" commands */
11530 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11531 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11532
11533 /* "bgp log-neighbor-changes" commands */
11534 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11535 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11536
11537 /* "bgp bestpath med" commands */
11538 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11539 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11540
11541 /* "no bgp default ipv4-unicast" commands. */
11542 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11543 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11544
11545 /* "bgp network import-check" commands. */
11546 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11547 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11548 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11549
11550 /* "bgp default local-preference" commands. */
11551 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11552 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11553
11554 /* bgp default show-hostname */
11555 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11556 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11557
11558 /* "bgp default subgroup-pkt-queue-max" commands. */
11559 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11560 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11561
11562 /* bgp ibgp-allow-policy-mods command */
11563 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11564 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11565
11566 /* "bgp listen limit" commands. */
11567 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11568 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11569
11570 /* "bgp listen range" commands. */
11571 install_element(BGP_NODE, &bgp_listen_range_cmd);
11572 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11573
f26845f9
QY
11574 /* "neighbors auto-shutdown" command */
11575 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
11576
d62a17ae 11577 /* "neighbor remote-as" commands. */
11578 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11579 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11580 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11581 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11582 install_element(BGP_NODE,
11583 &neighbor_interface_v6only_config_remote_as_cmd);
11584 install_element(BGP_NODE, &no_neighbor_cmd);
11585 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
11586
11587 /* "neighbor peer-group" commands. */
11588 install_element(BGP_NODE, &neighbor_peer_group_cmd);
11589 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
11590 install_element(BGP_NODE,
11591 &no_neighbor_interface_peer_group_remote_as_cmd);
11592
11593 /* "neighbor local-as" commands. */
11594 install_element(BGP_NODE, &neighbor_local_as_cmd);
11595 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
11596 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
11597 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
11598
11599 /* "neighbor solo" commands. */
11600 install_element(BGP_NODE, &neighbor_solo_cmd);
11601 install_element(BGP_NODE, &no_neighbor_solo_cmd);
11602
11603 /* "neighbor password" commands. */
11604 install_element(BGP_NODE, &neighbor_password_cmd);
11605 install_element(BGP_NODE, &no_neighbor_password_cmd);
11606
11607 /* "neighbor activate" commands. */
11608 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
11609 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
11610 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
11611 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
11612 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
11613 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
11614 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
11615 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
11616 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
11617 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
11618
11619 /* "no neighbor activate" commands. */
11620 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
11621 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
11622 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
11623 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
11624 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
11625 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
11626 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
11627 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
11628 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
11629 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
11630
11631 /* "neighbor peer-group" set commands. */
11632 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
11633 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11634 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
11635 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11636 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
11637 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
11638 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
11639 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
11640
11641 /* "no neighbor peer-group unset" commands. */
11642 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
11643 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11644 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11645 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11646 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11647 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11648 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11649 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
11650
11651 /* "neighbor softreconfiguration inbound" commands.*/
11652 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
11653 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
11654 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
11655 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11656 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
11657 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11658 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
11659 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11660 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
11661 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11662 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
11663 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
11664 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
11665 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
11666 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
11667 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
11668 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
11669 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
11670
11671 /* "neighbor attribute-unchanged" commands. */
11672 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
11673 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
11674 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
11675 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
11676 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
11677 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
11678 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
11679 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
11680 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
11681 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
11682 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
11683 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
11684 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
11685 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
11686 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
11687 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
11688 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
11689 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
11690
11691 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
11692 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
11693
11694 /* "nexthop-local unchanged" commands */
11695 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
11696 install_element(BGP_IPV6_NODE,
11697 &no_neighbor_nexthop_local_unchanged_cmd);
11698
11699 /* "neighbor next-hop-self" commands. */
11700 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
11701 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
11702 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
11703 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
11704 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
11705 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
11706 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
11707 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
11708 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
11709 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
11710 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
11711 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
11712 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
11713 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
11714 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
11715 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
11716 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
11717 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
11718
11719 /* "neighbor next-hop-self force" commands. */
11720 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
11721 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
11722 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
11723 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11724 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
11725 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
11726 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
11727 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
11728 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
11729 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11730 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
11731 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
11732 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
11733 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
11734 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
11735 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
11736 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
11737 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
11738
11739 /* "neighbor as-override" commands. */
11740 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
11741 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
11742 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
11743 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
11744 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
11745 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
11746 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
11747 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
11748 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
11749 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
11750 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
11751 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
11752 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
11753 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
11754 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
11755 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
11756 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
11757 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
11758
11759 /* "neighbor remove-private-AS" commands. */
11760 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
11761 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
11762 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
11763 install_element(BGP_NODE,
11764 &no_neighbor_remove_private_as_all_hidden_cmd);
11765 install_element(BGP_NODE,
11766 &neighbor_remove_private_as_replace_as_hidden_cmd);
11767 install_element(BGP_NODE,
11768 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
11769 install_element(BGP_NODE,
11770 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
11771 install_element(
11772 BGP_NODE,
11773 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
11774 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
11775 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
11776 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
11777 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11778 install_element(BGP_IPV4_NODE,
11779 &neighbor_remove_private_as_replace_as_cmd);
11780 install_element(BGP_IPV4_NODE,
11781 &no_neighbor_remove_private_as_replace_as_cmd);
11782 install_element(BGP_IPV4_NODE,
11783 &neighbor_remove_private_as_all_replace_as_cmd);
11784 install_element(BGP_IPV4_NODE,
11785 &no_neighbor_remove_private_as_all_replace_as_cmd);
11786 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
11787 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
11788 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
11789 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
11790 install_element(BGP_IPV4M_NODE,
11791 &neighbor_remove_private_as_replace_as_cmd);
11792 install_element(BGP_IPV4M_NODE,
11793 &no_neighbor_remove_private_as_replace_as_cmd);
11794 install_element(BGP_IPV4M_NODE,
11795 &neighbor_remove_private_as_all_replace_as_cmd);
11796 install_element(BGP_IPV4M_NODE,
11797 &no_neighbor_remove_private_as_all_replace_as_cmd);
11798 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
11799 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
11800 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
11801 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
11802 install_element(BGP_IPV4L_NODE,
11803 &neighbor_remove_private_as_replace_as_cmd);
11804 install_element(BGP_IPV4L_NODE,
11805 &no_neighbor_remove_private_as_replace_as_cmd);
11806 install_element(BGP_IPV4L_NODE,
11807 &neighbor_remove_private_as_all_replace_as_cmd);
11808 install_element(BGP_IPV4L_NODE,
11809 &no_neighbor_remove_private_as_all_replace_as_cmd);
11810 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
11811 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
11812 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
11813 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11814 install_element(BGP_IPV6_NODE,
11815 &neighbor_remove_private_as_replace_as_cmd);
11816 install_element(BGP_IPV6_NODE,
11817 &no_neighbor_remove_private_as_replace_as_cmd);
11818 install_element(BGP_IPV6_NODE,
11819 &neighbor_remove_private_as_all_replace_as_cmd);
11820 install_element(BGP_IPV6_NODE,
11821 &no_neighbor_remove_private_as_all_replace_as_cmd);
11822 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
11823 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
11824 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
11825 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
11826 install_element(BGP_IPV6M_NODE,
11827 &neighbor_remove_private_as_replace_as_cmd);
11828 install_element(BGP_IPV6M_NODE,
11829 &no_neighbor_remove_private_as_replace_as_cmd);
11830 install_element(BGP_IPV6M_NODE,
11831 &neighbor_remove_private_as_all_replace_as_cmd);
11832 install_element(BGP_IPV6M_NODE,
11833 &no_neighbor_remove_private_as_all_replace_as_cmd);
11834 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
11835 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
11836 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
11837 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
11838 install_element(BGP_IPV6L_NODE,
11839 &neighbor_remove_private_as_replace_as_cmd);
11840 install_element(BGP_IPV6L_NODE,
11841 &no_neighbor_remove_private_as_replace_as_cmd);
11842 install_element(BGP_IPV6L_NODE,
11843 &neighbor_remove_private_as_all_replace_as_cmd);
11844 install_element(BGP_IPV6L_NODE,
11845 &no_neighbor_remove_private_as_all_replace_as_cmd);
11846 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
11847 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
11848 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
11849 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
11850 install_element(BGP_VPNV4_NODE,
11851 &neighbor_remove_private_as_replace_as_cmd);
11852 install_element(BGP_VPNV4_NODE,
11853 &no_neighbor_remove_private_as_replace_as_cmd);
11854 install_element(BGP_VPNV4_NODE,
11855 &neighbor_remove_private_as_all_replace_as_cmd);
11856 install_element(BGP_VPNV4_NODE,
11857 &no_neighbor_remove_private_as_all_replace_as_cmd);
11858 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
11859 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
11860 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
11861 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
11862 install_element(BGP_VPNV6_NODE,
11863 &neighbor_remove_private_as_replace_as_cmd);
11864 install_element(BGP_VPNV6_NODE,
11865 &no_neighbor_remove_private_as_replace_as_cmd);
11866 install_element(BGP_VPNV6_NODE,
11867 &neighbor_remove_private_as_all_replace_as_cmd);
11868 install_element(BGP_VPNV6_NODE,
11869 &no_neighbor_remove_private_as_all_replace_as_cmd);
11870
11871 /* "neighbor send-community" commands.*/
11872 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
11873 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
11874 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
11875 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
11876 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
11877 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
11878 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
11879 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
11880 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
11881 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
11882 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
11883 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
11884 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
11885 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
11886 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
11887 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
11888 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
11889 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
11890 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
11891 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
11892 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
11893 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
11894 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
11895 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
11896 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
11897 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
11898 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
11899 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
11900 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
11901 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
11902 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
11903 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
11904 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
11905 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
11906 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
11907 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
11908
11909 /* "neighbor route-reflector" commands.*/
11910 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
11911 install_element(BGP_NODE,
11912 &no_neighbor_route_reflector_client_hidden_cmd);
11913 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
11914 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
11915 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
11916 install_element(BGP_IPV4M_NODE,
11917 &no_neighbor_route_reflector_client_cmd);
11918 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
11919 install_element(BGP_IPV4L_NODE,
11920 &no_neighbor_route_reflector_client_cmd);
11921 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
11922 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
11923 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
11924 install_element(BGP_IPV6M_NODE,
11925 &no_neighbor_route_reflector_client_cmd);
11926 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
11927 install_element(BGP_IPV6L_NODE,
11928 &no_neighbor_route_reflector_client_cmd);
11929 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
11930 install_element(BGP_VPNV4_NODE,
11931 &no_neighbor_route_reflector_client_cmd);
11932 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
11933 install_element(BGP_VPNV6_NODE,
11934 &no_neighbor_route_reflector_client_cmd);
11935 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
11936 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
11937
11938 /* "neighbor route-server" commands.*/
11939 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
11940 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
11941 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
11942 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
11943 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
11944 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
11945 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
11946 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
11947 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
11948 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
11949 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
11950 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
11951 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
11952 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
11953 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
11954 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
11955 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
11956 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
11957
11958 /* "neighbor addpath-tx-all-paths" commands.*/
11959 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
11960 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
11961 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11962 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11963 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11964 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11965 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11966 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11967 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11968 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11969 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
11970 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11971 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
11972 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11973 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
11974 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11975 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
11976 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
11977
11978 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
11979 install_element(BGP_NODE,
11980 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11981 install_element(BGP_NODE,
11982 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
11983 install_element(BGP_IPV4_NODE,
11984 &neighbor_addpath_tx_bestpath_per_as_cmd);
11985 install_element(BGP_IPV4_NODE,
11986 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11987 install_element(BGP_IPV4M_NODE,
11988 &neighbor_addpath_tx_bestpath_per_as_cmd);
11989 install_element(BGP_IPV4M_NODE,
11990 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11991 install_element(BGP_IPV4L_NODE,
11992 &neighbor_addpath_tx_bestpath_per_as_cmd);
11993 install_element(BGP_IPV4L_NODE,
11994 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11995 install_element(BGP_IPV6_NODE,
11996 &neighbor_addpath_tx_bestpath_per_as_cmd);
11997 install_element(BGP_IPV6_NODE,
11998 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
11999 install_element(BGP_IPV6M_NODE,
12000 &neighbor_addpath_tx_bestpath_per_as_cmd);
12001 install_element(BGP_IPV6M_NODE,
12002 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12003 install_element(BGP_IPV6L_NODE,
12004 &neighbor_addpath_tx_bestpath_per_as_cmd);
12005 install_element(BGP_IPV6L_NODE,
12006 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12007 install_element(BGP_VPNV4_NODE,
12008 &neighbor_addpath_tx_bestpath_per_as_cmd);
12009 install_element(BGP_VPNV4_NODE,
12010 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12011 install_element(BGP_VPNV6_NODE,
12012 &neighbor_addpath_tx_bestpath_per_as_cmd);
12013 install_element(BGP_VPNV6_NODE,
12014 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12015
12016 /* "neighbor passive" commands. */
12017 install_element(BGP_NODE, &neighbor_passive_cmd);
12018 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12019
12020
12021 /* "neighbor shutdown" commands. */
12022 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12023 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12024 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12025 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12026
12027 /* "neighbor capability extended-nexthop" commands.*/
12028 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12029 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12030
12031 /* "neighbor capability orf prefix-list" commands.*/
12032 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12033 install_element(BGP_NODE,
12034 &no_neighbor_capability_orf_prefix_hidden_cmd);
12035 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12036 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12037 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12038 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12039 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12040 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12041 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12042 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12043 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12044 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12045 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12046 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12047
12048 /* "neighbor capability dynamic" commands.*/
12049 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12050 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12051
12052 /* "neighbor dont-capability-negotiate" commands. */
12053 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12054 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12055
12056 /* "neighbor ebgp-multihop" commands. */
12057 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12058 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12059 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12060
12061 /* "neighbor disable-connected-check" commands. */
12062 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12063 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12064
12065 /* "neighbor description" commands. */
12066 install_element(BGP_NODE, &neighbor_description_cmd);
12067 install_element(BGP_NODE, &no_neighbor_description_cmd);
12068
12069 /* "neighbor update-source" commands. "*/
12070 install_element(BGP_NODE, &neighbor_update_source_cmd);
12071 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12072
12073 /* "neighbor default-originate" commands. */
12074 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12075 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12076 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12077 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12078 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12079 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12080 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12081 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12082 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12083 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12084 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12085 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12086 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12087 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12088 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12089 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12090 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12091 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12092 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12093 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12094 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12095
12096 /* "neighbor port" commands. */
12097 install_element(BGP_NODE, &neighbor_port_cmd);
12098 install_element(BGP_NODE, &no_neighbor_port_cmd);
12099
12100 /* "neighbor weight" commands. */
12101 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12102 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12103
12104 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12105 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12106 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12107 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12108 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12109 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12110 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12111 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12112 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12113 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12114 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12115 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12116 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12117 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12118 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12119 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12120
12121 /* "neighbor override-capability" commands. */
12122 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12123 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12124
12125 /* "neighbor strict-capability-match" commands. */
12126 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12127 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12128
12129 /* "neighbor timers" commands. */
12130 install_element(BGP_NODE, &neighbor_timers_cmd);
12131 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12132
12133 /* "neighbor timers connect" commands. */
12134 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12135 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12136
12137 /* "neighbor advertisement-interval" commands. */
12138 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12139 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12140
12141 /* "neighbor interface" commands. */
12142 install_element(BGP_NODE, &neighbor_interface_cmd);
12143 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12144
12145 /* "neighbor distribute" commands. */
12146 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12147 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12148 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12149 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12150 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12151 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12152 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12153 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12154 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12155 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12156 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12157 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12158 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12159 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12160 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12161 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12162 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12163 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12164
12165 /* "neighbor prefix-list" commands. */
12166 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12167 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12168 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12169 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12170 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12171 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12172 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12173 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12174 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12175 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12176 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12177 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12178 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12179 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12180 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12181 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12182 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12183 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12184
12185 /* "neighbor filter-list" commands. */
12186 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12187 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12188 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12189 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12190 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12191 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12192 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12193 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12194 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12195 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12196 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12197 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12198 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12199 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12200 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12201 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12202 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12203 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12204
12205 /* "neighbor route-map" commands. */
12206 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12207 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12208 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12209 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12210 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12211 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12212 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12213 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12214 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12215 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12216 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12217 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12218 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12219 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12220 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12221 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12222 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12223 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
12224 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12225 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 12226
12227 /* "neighbor unsuppress-map" commands. */
12228 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12229 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12230 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12231 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12232 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12233 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12234 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12235 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12236 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12237 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12238 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12239 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12240 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12241 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12242 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12243 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12244 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12245 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12246
12247 /* "neighbor maximum-prefix" commands. */
12248 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12249 install_element(BGP_NODE,
12250 &neighbor_maximum_prefix_threshold_hidden_cmd);
12251 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12252 install_element(BGP_NODE,
12253 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12254 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12255 install_element(BGP_NODE,
12256 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12257 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12258 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12259 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12260 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12261 install_element(BGP_IPV4_NODE,
12262 &neighbor_maximum_prefix_threshold_warning_cmd);
12263 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12264 install_element(BGP_IPV4_NODE,
12265 &neighbor_maximum_prefix_threshold_restart_cmd);
12266 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12267 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12268 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12269 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12270 install_element(BGP_IPV4M_NODE,
12271 &neighbor_maximum_prefix_threshold_warning_cmd);
12272 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12273 install_element(BGP_IPV4M_NODE,
12274 &neighbor_maximum_prefix_threshold_restart_cmd);
12275 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12276 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12277 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12278 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12279 install_element(BGP_IPV4L_NODE,
12280 &neighbor_maximum_prefix_threshold_warning_cmd);
12281 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12282 install_element(BGP_IPV4L_NODE,
12283 &neighbor_maximum_prefix_threshold_restart_cmd);
12284 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12285 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12286 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12287 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12288 install_element(BGP_IPV6_NODE,
12289 &neighbor_maximum_prefix_threshold_warning_cmd);
12290 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12291 install_element(BGP_IPV6_NODE,
12292 &neighbor_maximum_prefix_threshold_restart_cmd);
12293 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12294 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12295 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12296 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12297 install_element(BGP_IPV6M_NODE,
12298 &neighbor_maximum_prefix_threshold_warning_cmd);
12299 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12300 install_element(BGP_IPV6M_NODE,
12301 &neighbor_maximum_prefix_threshold_restart_cmd);
12302 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12303 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12304 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12305 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12306 install_element(BGP_IPV6L_NODE,
12307 &neighbor_maximum_prefix_threshold_warning_cmd);
12308 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12309 install_element(BGP_IPV6L_NODE,
12310 &neighbor_maximum_prefix_threshold_restart_cmd);
12311 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12312 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12313 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12314 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12315 install_element(BGP_VPNV4_NODE,
12316 &neighbor_maximum_prefix_threshold_warning_cmd);
12317 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12318 install_element(BGP_VPNV4_NODE,
12319 &neighbor_maximum_prefix_threshold_restart_cmd);
12320 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12321 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12322 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12323 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12324 install_element(BGP_VPNV6_NODE,
12325 &neighbor_maximum_prefix_threshold_warning_cmd);
12326 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12327 install_element(BGP_VPNV6_NODE,
12328 &neighbor_maximum_prefix_threshold_restart_cmd);
12329 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12330
12331 /* "neighbor allowas-in" */
12332 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12333 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12334 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12335 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12336 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12337 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12338 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12339 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12340 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12341 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12342 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12343 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12344 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12345 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12346 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12347 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12348 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12349 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12350 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12351 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12352
12353 /* address-family commands. */
12354 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12355 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 12356#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 12357 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12358 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 12359#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 12360
d62a17ae 12361 install_element(BGP_NODE, &address_family_evpn_cmd);
12362
12363 /* "exit-address-family" command. */
12364 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12365 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12366 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12367 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12368 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12369 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12370 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12371 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12372 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12373
12374 /* "clear ip bgp commands" */
12375 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12376
12377 /* clear ip bgp prefix */
12378 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12379 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12380 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12381
12382 /* "show [ip] bgp summary" commands. */
12383 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
12384 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_cmd);
12385 install_element(VIEW_NODE, &show_bgp_instance_updgrps_adj_s_cmd);
12386 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
12387 install_element(VIEW_NODE, &show_bgp_updgrps_adj_cmd);
12388 install_element(VIEW_NODE, &show_bgp_updgrps_adj_s_cmd);
12389 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_cmd);
12390 install_element(VIEW_NODE, &show_bgp_updgrps_afi_adj_s_cmd);
12391 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
12392 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_cmd);
12393 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12394 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
12395 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_cmd);
12396 install_element(VIEW_NODE, &show_ip_bgp_updgrps_adj_s_cmd);
12397 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12398
12399 /* "show [ip] bgp neighbors" commands. */
12400 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12401
12402 /* "show [ip] bgp peer-group" commands. */
12403 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12404
12405 /* "show [ip] bgp paths" commands. */
12406 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12407
12408 /* "show [ip] bgp community" commands. */
12409 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12410
12411 /* "show ip bgp large-community" commands. */
12412 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12413 /* "show [ip] bgp attribute-info" commands. */
12414 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12415
12416 /* "redistribute" commands. */
12417 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12418 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12419 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12420 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12421 install_element(BGP_NODE,
12422 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12423 install_element(BGP_NODE,
12424 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12425 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12426 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12427 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12428 install_element(BGP_NODE,
12429 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12430 install_element(BGP_NODE,
12431 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12432 install_element(BGP_NODE,
12433 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12434 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12435 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12436 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12437 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12438 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12439 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12440 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12441 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12442 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12443 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12444 install_element(BGP_IPV4_NODE,
12445 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12446 install_element(BGP_IPV4_NODE,
12447 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12448 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12449 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12450 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12451 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12452 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12453 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12454
12455 /* ttl_security commands */
12456 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12457 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12458
12459 /* "show [ip] bgp memory" commands. */
12460 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12461
acf71666
MK
12462 /* "show bgp martian next-hop" */
12463 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12464
d62a17ae 12465 /* "show [ip] bgp views" commands. */
12466 install_element(VIEW_NODE, &show_bgp_views_cmd);
12467
12468 /* "show [ip] bgp vrfs" commands. */
12469 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12470
12471 /* Community-list. */
12472 community_list_vty();
718e3744 12473}
6b0655a2 12474
718e3744 12475#include "memory.h"
12476#include "bgp_regex.h"
12477#include "bgp_clist.h"
12478#include "bgp_ecommunity.h"
12479
12480/* VTY functions. */
12481
12482/* Direction value to string conversion. */
d62a17ae 12483static const char *community_direct_str(int direct)
12484{
12485 switch (direct) {
12486 case COMMUNITY_DENY:
12487 return "deny";
12488 case COMMUNITY_PERMIT:
12489 return "permit";
12490 default:
12491 return "unknown";
12492 }
718e3744 12493}
12494
12495/* Display error string. */
d62a17ae 12496static void community_list_perror(struct vty *vty, int ret)
12497{
12498 switch (ret) {
12499 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12500 vty_out(vty, "%% Can't find community-list\n");
12501 break;
12502 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12503 vty_out(vty, "%% Malformed community-list value\n");
12504 break;
12505 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12506 vty_out(vty,
12507 "%% Community name conflict, previously defined as standard community\n");
12508 break;
12509 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12510 vty_out(vty,
12511 "%% Community name conflict, previously defined as expanded community\n");
12512 break;
12513 }
718e3744 12514}
12515
5bf15956
DW
12516/* "community-list" keyword help string. */
12517#define COMMUNITY_LIST_STR "Add a community list entry\n"
12518
5bf15956 12519/* ip community-list standard */
718e3744 12520DEFUN (ip_community_list_standard,
12521 ip_community_list_standard_cmd,
e961923c 12522 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12523 IP_STR
12524 COMMUNITY_LIST_STR
12525 "Community list number (standard)\n"
5bf15956 12526 "Add an standard community-list entry\n"
718e3744 12527 "Community list name\n"
12528 "Specify community to reject\n"
12529 "Specify community to accept\n"
12530 COMMUNITY_VAL_STR)
12531{
d62a17ae 12532 char *cl_name_or_number = NULL;
12533 int direct = 0;
12534 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12535
d62a17ae 12536 int idx = 0;
12537 argv_find(argv, argc, "(1-99)", &idx);
12538 argv_find(argv, argc, "WORD", &idx);
12539 cl_name_or_number = argv[idx]->arg;
12540 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12541 : COMMUNITY_DENY;
12542 argv_find(argv, argc, "AA:NN", &idx);
12543 char *str = argv_concat(argv, argc, idx);
42f914d4 12544
d62a17ae 12545 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12546 style);
42f914d4 12547
d62a17ae 12548 XFREE(MTYPE_TMP, str);
42f914d4 12549
d62a17ae 12550 if (ret < 0) {
12551 /* Display error string. */
12552 community_list_perror(vty, ret);
12553 return CMD_WARNING_CONFIG_FAILED;
12554 }
42f914d4 12555
d62a17ae 12556 return CMD_SUCCESS;
718e3744 12557}
12558
fee6e4e4 12559DEFUN (no_ip_community_list_standard_all,
12560 no_ip_community_list_standard_all_cmd,
e961923c 12561 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12562 NO_STR
12563 IP_STR
12564 COMMUNITY_LIST_STR
12565 "Community list number (standard)\n"
5bf15956
DW
12566 "Add an standard community-list entry\n"
12567 "Community list name\n"
718e3744 12568 "Specify community to reject\n"
12569 "Specify community to accept\n"
12570 COMMUNITY_VAL_STR)
12571{
d62a17ae 12572 int delete_all = 0;
42f914d4 12573
d62a17ae 12574 char *cl_name_or_number = NULL;
12575 int direct = 0;
12576 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12577
d62a17ae 12578 int idx = 0;
12579 argv_find(argv, argc, "(1-99)", &idx);
12580 argv_find(argv, argc, "WORD", &idx);
12581 cl_name_or_number = argv[idx]->arg;
12582 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12583 : COMMUNITY_DENY;
12584 argv_find(argv, argc, "AA:NN", &idx);
12585 char *str = argv_concat(argv, argc, idx);
42f914d4 12586
d62a17ae 12587 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12588 direct, style, delete_all);
42f914d4 12589
d62a17ae 12590 XFREE(MTYPE_TMP, str);
daf9ddbb 12591
d62a17ae 12592 if (ret < 0) {
12593 community_list_perror(vty, ret);
12594 return CMD_WARNING_CONFIG_FAILED;
12595 }
42f914d4 12596
d62a17ae 12597 return CMD_SUCCESS;
718e3744 12598}
12599
5bf15956
DW
12600/* ip community-list expanded */
12601DEFUN (ip_community_list_expanded_all,
12602 ip_community_list_expanded_all_cmd,
42f914d4 12603 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12604 IP_STR
12605 COMMUNITY_LIST_STR
12606 "Community list number (expanded)\n"
5bf15956 12607 "Add an expanded community-list entry\n"
718e3744 12608 "Community list name\n"
12609 "Specify community to reject\n"
12610 "Specify community to accept\n"
12611 COMMUNITY_VAL_STR)
12612{
d62a17ae 12613 char *cl_name_or_number = NULL;
12614 int direct = 0;
12615 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12616
d62a17ae 12617 int idx = 0;
12618 argv_find(argv, argc, "(100-500)", &idx);
12619 argv_find(argv, argc, "WORD", &idx);
12620 cl_name_or_number = argv[idx]->arg;
12621 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12622 : COMMUNITY_DENY;
12623 argv_find(argv, argc, "AA:NN", &idx);
12624 char *str = argv_concat(argv, argc, idx);
42f914d4 12625
d62a17ae 12626 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12627 style);
42f914d4 12628
d62a17ae 12629 XFREE(MTYPE_TMP, str);
42f914d4 12630
d62a17ae 12631 if (ret < 0) {
12632 /* Display error string. */
12633 community_list_perror(vty, ret);
12634 return CMD_WARNING_CONFIG_FAILED;
12635 }
42f914d4 12636
d62a17ae 12637 return CMD_SUCCESS;
718e3744 12638}
12639
5bf15956
DW
12640DEFUN (no_ip_community_list_expanded_all,
12641 no_ip_community_list_expanded_all_cmd,
42f914d4 12642 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 12643 NO_STR
12644 IP_STR
12645 COMMUNITY_LIST_STR
5bf15956
DW
12646 "Community list number (expanded)\n"
12647 "Add an expanded community-list entry\n"
718e3744 12648 "Community list name\n"
12649 "Specify community to reject\n"
12650 "Specify community to accept\n"
5bf15956 12651 COMMUNITY_VAL_STR)
718e3744 12652{
d62a17ae 12653 int delete_all = 0;
42f914d4 12654
d62a17ae 12655 char *cl_name_or_number = NULL;
12656 int direct = 0;
12657 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 12658
d62a17ae 12659 int idx = 0;
12660 argv_find(argv, argc, "(100-500)", &idx);
12661 argv_find(argv, argc, "WORD", &idx);
12662 cl_name_or_number = argv[idx]->arg;
12663 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12664 : COMMUNITY_DENY;
12665 argv_find(argv, argc, "AA:NN", &idx);
12666 char *str = argv_concat(argv, argc, idx);
42f914d4 12667
d62a17ae 12668 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
12669 direct, style, delete_all);
42f914d4 12670
d62a17ae 12671 XFREE(MTYPE_TMP, str);
daf9ddbb 12672
d62a17ae 12673 if (ret < 0) {
12674 community_list_perror(vty, ret);
12675 return CMD_WARNING_CONFIG_FAILED;
12676 }
42f914d4 12677
d62a17ae 12678 return CMD_SUCCESS;
718e3744 12679}
12680
d62a17ae 12681static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 12682{
d62a17ae 12683 struct community_entry *entry;
718e3744 12684
d62a17ae 12685 for (entry = list->head; entry; entry = entry->next) {
12686 if (entry == list->head) {
12687 if (all_digit(list->name))
12688 vty_out(vty, "Community %s list %s\n",
12689 entry->style == COMMUNITY_LIST_STANDARD
12690 ? "standard"
12691 : "(expanded) access",
12692 list->name);
12693 else
12694 vty_out(vty, "Named Community %s list %s\n",
12695 entry->style == COMMUNITY_LIST_STANDARD
12696 ? "standard"
12697 : "expanded",
12698 list->name);
12699 }
12700 if (entry->any)
12701 vty_out(vty, " %s\n",
12702 community_direct_str(entry->direct));
12703 else
12704 vty_out(vty, " %s %s\n",
12705 community_direct_str(entry->direct),
12706 entry->style == COMMUNITY_LIST_STANDARD
a69ea8ae 12707 ? community_str(entry->u.com, false)
d62a17ae 12708 : entry->config);
12709 }
718e3744 12710}
12711
12712DEFUN (show_ip_community_list,
12713 show_ip_community_list_cmd,
12714 "show ip community-list",
12715 SHOW_STR
12716 IP_STR
12717 "List community-list\n")
12718{
d62a17ae 12719 struct community_list *list;
12720 struct community_list_master *cm;
718e3744 12721
d62a17ae 12722 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
12723 if (!cm)
12724 return CMD_SUCCESS;
718e3744 12725
d62a17ae 12726 for (list = cm->num.head; list; list = list->next)
12727 community_list_show(vty, list);
718e3744 12728
d62a17ae 12729 for (list = cm->str.head; list; list = list->next)
12730 community_list_show(vty, list);
718e3744 12731
d62a17ae 12732 return CMD_SUCCESS;
718e3744 12733}
12734
12735DEFUN (show_ip_community_list_arg,
12736 show_ip_community_list_arg_cmd,
6147e2c6 12737 "show ip community-list <(1-500)|WORD>",
718e3744 12738 SHOW_STR
12739 IP_STR
12740 "List community-list\n"
12741 "Community-list number\n"
12742 "Community-list name\n")
12743{
d62a17ae 12744 int idx_comm_list = 3;
12745 struct community_list *list;
718e3744 12746
d62a17ae 12747 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
12748 COMMUNITY_LIST_MASTER);
12749 if (!list) {
12750 vty_out(vty, "%% Can't find community-list\n");
12751 return CMD_WARNING;
12752 }
718e3744 12753
d62a17ae 12754 community_list_show(vty, list);
718e3744 12755
d62a17ae 12756 return CMD_SUCCESS;
718e3744 12757}
6b0655a2 12758
57d187bc
JS
12759/*
12760 * Large Community code.
12761 */
d62a17ae 12762static int lcommunity_list_set_vty(struct vty *vty, int argc,
12763 struct cmd_token **argv, int style,
12764 int reject_all_digit_name)
12765{
12766 int ret;
12767 int direct;
12768 char *str;
12769 int idx = 0;
12770 char *cl_name;
12771
12772 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12773 : COMMUNITY_DENY;
12774
12775 /* All digit name check. */
12776 idx = 0;
12777 argv_find(argv, argc, "WORD", &idx);
12778 argv_find(argv, argc, "(1-99)", &idx);
12779 argv_find(argv, argc, "(100-500)", &idx);
12780 cl_name = argv[idx]->arg;
12781 if (reject_all_digit_name && all_digit(cl_name)) {
12782 vty_out(vty, "%% Community name cannot have all digits\n");
12783 return CMD_WARNING_CONFIG_FAILED;
12784 }
12785
12786 idx = 0;
12787 argv_find(argv, argc, "AA:BB:CC", &idx);
12788 argv_find(argv, argc, "LINE", &idx);
12789 /* Concat community string argument. */
12790 if (idx)
12791 str = argv_concat(argv, argc, idx);
12792 else
12793 str = NULL;
12794
12795 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
12796
12797 /* Free temporary community list string allocated by
12798 argv_concat(). */
12799 if (str)
12800 XFREE(MTYPE_TMP, str);
12801
12802 if (ret < 0) {
12803 community_list_perror(vty, ret);
12804 return CMD_WARNING_CONFIG_FAILED;
12805 }
12806 return CMD_SUCCESS;
12807}
12808
12809static int lcommunity_list_unset_vty(struct vty *vty, int argc,
12810 struct cmd_token **argv, int style)
12811{
12812 int ret;
12813 int direct = 0;
12814 char *str = NULL;
12815 int idx = 0;
12816
12817 argv_find(argv, argc, "permit", &idx);
12818 argv_find(argv, argc, "deny", &idx);
12819
12820 if (idx) {
12821 /* Check the list direct. */
12822 if (strncmp(argv[idx]->arg, "p", 1) == 0)
12823 direct = COMMUNITY_PERMIT;
12824 else
12825 direct = COMMUNITY_DENY;
12826
12827 idx = 0;
12828 argv_find(argv, argc, "LINE", &idx);
12829 argv_find(argv, argc, "AA:AA:NN", &idx);
12830 /* Concat community string argument. */
12831 str = argv_concat(argv, argc, idx);
12832 }
12833
12834 idx = 0;
12835 argv_find(argv, argc, "(1-99)", &idx);
12836 argv_find(argv, argc, "(100-500)", &idx);
12837 argv_find(argv, argc, "WORD", &idx);
12838
12839 /* Unset community list. */
12840 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
12841 style);
12842
12843 /* Free temporary community list string allocated by
12844 argv_concat(). */
12845 if (str)
12846 XFREE(MTYPE_TMP, str);
12847
12848 if (ret < 0) {
12849 community_list_perror(vty, ret);
12850 return CMD_WARNING_CONFIG_FAILED;
12851 }
12852
12853 return CMD_SUCCESS;
57d187bc
JS
12854}
12855
12856/* "large-community-list" keyword help string. */
12857#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
12858#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
12859
12860DEFUN (ip_lcommunity_list_standard,
12861 ip_lcommunity_list_standard_cmd,
52951b63
DS
12862 "ip large-community-list (1-99) <deny|permit>",
12863 IP_STR
12864 LCOMMUNITY_LIST_STR
12865 "Large Community list number (standard)\n"
12866 "Specify large community to reject\n"
7111c1a0 12867 "Specify large community to accept\n")
52951b63 12868{
d62a17ae 12869 return lcommunity_list_set_vty(vty, argc, argv,
12870 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
12871}
12872
12873DEFUN (ip_lcommunity_list_standard1,
12874 ip_lcommunity_list_standard1_cmd,
12875 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
12876 IP_STR
12877 LCOMMUNITY_LIST_STR
12878 "Large Community list number (standard)\n"
12879 "Specify large community to reject\n"
12880 "Specify large community to accept\n"
12881 LCOMMUNITY_VAL_STR)
12882{
d62a17ae 12883 return lcommunity_list_set_vty(vty, argc, argv,
12884 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
12885}
12886
12887DEFUN (ip_lcommunity_list_expanded,
12888 ip_lcommunity_list_expanded_cmd,
12889 "ip large-community-list (100-500) <deny|permit> LINE...",
12890 IP_STR
12891 LCOMMUNITY_LIST_STR
12892 "Large Community list number (expanded)\n"
12893 "Specify large community to reject\n"
12894 "Specify large community to accept\n"
12895 "An ordered list as a regular-expression\n")
12896{
d62a17ae 12897 return lcommunity_list_set_vty(vty, argc, argv,
12898 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
12899}
12900
12901DEFUN (ip_lcommunity_list_name_standard,
12902 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
12903 "ip large-community-list standard WORD <deny|permit>",
12904 IP_STR
12905 LCOMMUNITY_LIST_STR
12906 "Specify standard large-community-list\n"
12907 "Large Community list name\n"
12908 "Specify large community to reject\n"
12909 "Specify large community to accept\n")
12910{
d62a17ae 12911 return lcommunity_list_set_vty(vty, argc, argv,
12912 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
12913}
12914
12915DEFUN (ip_lcommunity_list_name_standard1,
12916 ip_lcommunity_list_name_standard1_cmd,
12917 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
12918 IP_STR
12919 LCOMMUNITY_LIST_STR
12920 "Specify standard large-community-list\n"
12921 "Large Community list name\n"
12922 "Specify large community to reject\n"
12923 "Specify large community to accept\n"
12924 LCOMMUNITY_VAL_STR)
12925{
d62a17ae 12926 return lcommunity_list_set_vty(vty, argc, argv,
12927 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
12928}
12929
12930DEFUN (ip_lcommunity_list_name_expanded,
12931 ip_lcommunity_list_name_expanded_cmd,
12932 "ip large-community-list expanded WORD <deny|permit> LINE...",
12933 IP_STR
12934 LCOMMUNITY_LIST_STR
12935 "Specify expanded large-community-list\n"
12936 "Large Community list name\n"
12937 "Specify large community to reject\n"
12938 "Specify large community to accept\n"
12939 "An ordered list as a regular-expression\n")
12940{
d62a17ae 12941 return lcommunity_list_set_vty(vty, argc, argv,
12942 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
12943}
12944
12945DEFUN (no_ip_lcommunity_list_standard_all,
12946 no_ip_lcommunity_list_standard_all_cmd,
12947 "no ip large-community-list <(1-99)|(100-500)|WORD>",
12948 NO_STR
12949 IP_STR
12950 LCOMMUNITY_LIST_STR
12951 "Large Community list number (standard)\n"
12952 "Large Community list number (expanded)\n"
12953 "Large Community list name\n")
12954{
d62a17ae 12955 return lcommunity_list_unset_vty(vty, argc, argv,
12956 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12957}
12958
12959DEFUN (no_ip_lcommunity_list_name_expanded_all,
12960 no_ip_lcommunity_list_name_expanded_all_cmd,
12961 "no ip large-community-list expanded WORD",
12962 NO_STR
12963 IP_STR
12964 LCOMMUNITY_LIST_STR
12965 "Specify expanded large-community-list\n"
12966 "Large Community list name\n")
12967{
d62a17ae 12968 return lcommunity_list_unset_vty(vty, argc, argv,
12969 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
12970}
12971
12972DEFUN (no_ip_lcommunity_list_standard,
12973 no_ip_lcommunity_list_standard_cmd,
12974 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
12975 NO_STR
12976 IP_STR
12977 LCOMMUNITY_LIST_STR
12978 "Large Community list number (standard)\n"
12979 "Specify large community to reject\n"
12980 "Specify large community to accept\n"
12981 LCOMMUNITY_VAL_STR)
12982{
d62a17ae 12983 return lcommunity_list_unset_vty(vty, argc, argv,
12984 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
12985}
12986
12987DEFUN (no_ip_lcommunity_list_expanded,
12988 no_ip_lcommunity_list_expanded_cmd,
12989 "no ip large-community-list (100-500) <deny|permit> LINE...",
12990 NO_STR
12991 IP_STR
12992 LCOMMUNITY_LIST_STR
12993 "Large Community list number (expanded)\n"
12994 "Specify large community to reject\n"
12995 "Specify large community to accept\n"
12996 "An ordered list as a regular-expression\n")
12997{
d62a17ae 12998 return lcommunity_list_unset_vty(vty, argc, argv,
12999 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13000}
13001
13002DEFUN (no_ip_lcommunity_list_name_standard,
13003 no_ip_lcommunity_list_name_standard_cmd,
13004 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13005 NO_STR
13006 IP_STR
13007 LCOMMUNITY_LIST_STR
13008 "Specify standard large-community-list\n"
13009 "Large Community list name\n"
13010 "Specify large community to reject\n"
13011 "Specify large community to accept\n"
13012 LCOMMUNITY_VAL_STR)
13013{
d62a17ae 13014 return lcommunity_list_unset_vty(vty, argc, argv,
13015 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13016}
13017
13018DEFUN (no_ip_lcommunity_list_name_expanded,
13019 no_ip_lcommunity_list_name_expanded_cmd,
13020 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13021 NO_STR
13022 IP_STR
13023 LCOMMUNITY_LIST_STR
13024 "Specify expanded large-community-list\n"
13025 "Large community list name\n"
13026 "Specify large community to reject\n"
13027 "Specify large community to accept\n"
13028 "An ordered list as a regular-expression\n")
13029{
d62a17ae 13030 return lcommunity_list_unset_vty(vty, argc, argv,
13031 LARGE_COMMUNITY_LIST_EXPANDED);
13032}
13033
13034static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13035{
13036 struct community_entry *entry;
13037
13038 for (entry = list->head; entry; entry = entry->next) {
13039 if (entry == list->head) {
13040 if (all_digit(list->name))
13041 vty_out(vty, "Large community %s list %s\n",
13042 entry->style == EXTCOMMUNITY_LIST_STANDARD
13043 ? "standard"
13044 : "(expanded) access",
13045 list->name);
13046 else
13047 vty_out(vty,
13048 "Named large community %s list %s\n",
13049 entry->style == EXTCOMMUNITY_LIST_STANDARD
13050 ? "standard"
13051 : "expanded",
13052 list->name);
13053 }
13054 if (entry->any)
13055 vty_out(vty, " %s\n",
13056 community_direct_str(entry->direct));
13057 else
13058 vty_out(vty, " %s %s\n",
13059 community_direct_str(entry->direct),
13060 entry->style == EXTCOMMUNITY_LIST_STANDARD
13061 ? entry->u.ecom->str
13062 : entry->config);
13063 }
57d187bc
JS
13064}
13065
13066DEFUN (show_ip_lcommunity_list,
13067 show_ip_lcommunity_list_cmd,
13068 "show ip large-community-list",
13069 SHOW_STR
13070 IP_STR
13071 "List large-community list\n")
13072{
d62a17ae 13073 struct community_list *list;
13074 struct community_list_master *cm;
57d187bc 13075
d62a17ae 13076 cm = community_list_master_lookup(bgp_clist,
13077 LARGE_COMMUNITY_LIST_MASTER);
13078 if (!cm)
13079 return CMD_SUCCESS;
57d187bc 13080
d62a17ae 13081 for (list = cm->num.head; list; list = list->next)
13082 lcommunity_list_show(vty, list);
57d187bc 13083
d62a17ae 13084 for (list = cm->str.head; list; list = list->next)
13085 lcommunity_list_show(vty, list);
57d187bc 13086
d62a17ae 13087 return CMD_SUCCESS;
57d187bc
JS
13088}
13089
13090DEFUN (show_ip_lcommunity_list_arg,
13091 show_ip_lcommunity_list_arg_cmd,
13092 "show ip large-community-list <(1-500)|WORD>",
13093 SHOW_STR
13094 IP_STR
13095 "List large-community list\n"
13096 "large-community-list number\n"
13097 "large-community-list name\n")
13098{
d62a17ae 13099 struct community_list *list;
57d187bc 13100
d62a17ae 13101 list = community_list_lookup(bgp_clist, argv[3]->arg,
13102 LARGE_COMMUNITY_LIST_MASTER);
13103 if (!list) {
13104 vty_out(vty, "%% Can't find extcommunity-list\n");
13105 return CMD_WARNING;
13106 }
57d187bc 13107
d62a17ae 13108 lcommunity_list_show(vty, list);
57d187bc 13109
d62a17ae 13110 return CMD_SUCCESS;
57d187bc
JS
13111}
13112
718e3744 13113/* "extcommunity-list" keyword help string. */
13114#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13115#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13116
13117DEFUN (ip_extcommunity_list_standard,
13118 ip_extcommunity_list_standard_cmd,
e961923c 13119 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13120 IP_STR
13121 EXTCOMMUNITY_LIST_STR
13122 "Extended Community list number (standard)\n"
718e3744 13123 "Specify standard extcommunity-list\n"
5bf15956 13124 "Community list name\n"
718e3744 13125 "Specify community to reject\n"
13126 "Specify community to accept\n"
13127 EXTCOMMUNITY_VAL_STR)
13128{
d62a17ae 13129 int style = EXTCOMMUNITY_LIST_STANDARD;
13130 int direct = 0;
13131 char *cl_number_or_name = NULL;
42f914d4 13132
d62a17ae 13133 int idx = 0;
13134 argv_find(argv, argc, "(1-99)", &idx);
13135 argv_find(argv, argc, "WORD", &idx);
13136 cl_number_or_name = argv[idx]->arg;
13137 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13138 : COMMUNITY_DENY;
13139 argv_find(argv, argc, "AA:NN", &idx);
13140 char *str = argv_concat(argv, argc, idx);
42f914d4 13141
d62a17ae 13142 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13143 direct, style);
42f914d4 13144
d62a17ae 13145 XFREE(MTYPE_TMP, str);
42f914d4 13146
d62a17ae 13147 if (ret < 0) {
13148 community_list_perror(vty, ret);
13149 return CMD_WARNING_CONFIG_FAILED;
13150 }
42f914d4 13151
d62a17ae 13152 return CMD_SUCCESS;
718e3744 13153}
13154
718e3744 13155DEFUN (ip_extcommunity_list_name_expanded,
13156 ip_extcommunity_list_name_expanded_cmd,
e961923c 13157 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13158 IP_STR
13159 EXTCOMMUNITY_LIST_STR
5bf15956 13160 "Extended Community list number (expanded)\n"
718e3744 13161 "Specify expanded extcommunity-list\n"
13162 "Extended Community list name\n"
13163 "Specify community to reject\n"
13164 "Specify community to accept\n"
13165 "An ordered list as a regular-expression\n")
13166{
d62a17ae 13167 int style = EXTCOMMUNITY_LIST_EXPANDED;
13168 int direct = 0;
13169 char *cl_number_or_name = NULL;
42f914d4 13170
d62a17ae 13171 int idx = 0;
13172 argv_find(argv, argc, "(100-500)", &idx);
13173 argv_find(argv, argc, "WORD", &idx);
13174 cl_number_or_name = argv[idx]->arg;
13175 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13176 : COMMUNITY_DENY;
13177 argv_find(argv, argc, "LINE", &idx);
13178 char *str = argv_concat(argv, argc, idx);
42f914d4 13179
d62a17ae 13180 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13181 direct, style);
42f914d4 13182
d62a17ae 13183 XFREE(MTYPE_TMP, str);
42f914d4 13184
d62a17ae 13185 if (ret < 0) {
13186 community_list_perror(vty, ret);
13187 return CMD_WARNING_CONFIG_FAILED;
13188 }
42f914d4 13189
d62a17ae 13190 return CMD_SUCCESS;
718e3744 13191}
13192
fee6e4e4 13193DEFUN (no_ip_extcommunity_list_standard_all,
13194 no_ip_extcommunity_list_standard_all_cmd,
e961923c 13195 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
13196 NO_STR
13197 IP_STR
13198 EXTCOMMUNITY_LIST_STR
13199 "Extended Community list number (standard)\n"
718e3744 13200 "Specify standard extcommunity-list\n"
5bf15956 13201 "Community list name\n"
718e3744 13202 "Specify community to reject\n"
13203 "Specify community to accept\n"
13204 EXTCOMMUNITY_VAL_STR)
13205{
d62a17ae 13206 int deleteall = 0;
42f914d4 13207
d62a17ae 13208 int style = EXTCOMMUNITY_LIST_STANDARD;
13209 int direct = 0;
13210 char *cl_number_or_name = NULL;
42f914d4 13211
d62a17ae 13212 int idx = 0;
13213 argv_find(argv, argc, "(1-99)", &idx);
13214 argv_find(argv, argc, "WORD", &idx);
13215 cl_number_or_name = argv[idx]->arg;
13216 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13217 : COMMUNITY_DENY;
13218 argv_find(argv, argc, "AA:NN", &idx);
13219 char *str = argv_concat(argv, argc, idx);
42f914d4 13220
d62a17ae 13221 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13222 direct, style, deleteall);
42f914d4 13223
d62a17ae 13224 XFREE(MTYPE_TMP, str);
42f914d4 13225
d62a17ae 13226 if (ret < 0) {
13227 community_list_perror(vty, ret);
13228 return CMD_WARNING_CONFIG_FAILED;
13229 }
42f914d4 13230
d62a17ae 13231 return CMD_SUCCESS;
718e3744 13232}
13233
5bf15956
DW
13234DEFUN (no_ip_extcommunity_list_expanded_all,
13235 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 13236 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13237 NO_STR
13238 IP_STR
13239 EXTCOMMUNITY_LIST_STR
13240 "Extended Community list number (expanded)\n"
718e3744 13241 "Specify expanded extcommunity-list\n"
5bf15956 13242 "Extended Community list name\n"
718e3744 13243 "Specify community to reject\n"
13244 "Specify community to accept\n"
13245 "An ordered list as a regular-expression\n")
13246{
d62a17ae 13247 int deleteall = 0;
42f914d4 13248
d62a17ae 13249 int style = EXTCOMMUNITY_LIST_EXPANDED;
13250 int direct = 0;
13251 char *cl_number_or_name = NULL;
42f914d4 13252
d62a17ae 13253 int idx = 0;
13254 argv_find(argv, argc, "(100-500)", &idx);
13255 argv_find(argv, argc, "WORD", &idx);
13256 cl_number_or_name = argv[idx]->arg;
13257 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13258 : COMMUNITY_DENY;
13259 argv_find(argv, argc, "LINE", &idx);
13260 char *str = argv_concat(argv, argc, idx);
42f914d4 13261
d62a17ae 13262 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13263 direct, style, deleteall);
42f914d4 13264
d62a17ae 13265 XFREE(MTYPE_TMP, str);
42f914d4 13266
d62a17ae 13267 if (ret < 0) {
13268 community_list_perror(vty, ret);
13269 return CMD_WARNING_CONFIG_FAILED;
13270 }
42f914d4 13271
d62a17ae 13272 return CMD_SUCCESS;
718e3744 13273}
13274
d62a17ae 13275static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 13276{
d62a17ae 13277 struct community_entry *entry;
718e3744 13278
d62a17ae 13279 for (entry = list->head; entry; entry = entry->next) {
13280 if (entry == list->head) {
13281 if (all_digit(list->name))
13282 vty_out(vty, "Extended community %s list %s\n",
13283 entry->style == EXTCOMMUNITY_LIST_STANDARD
13284 ? "standard"
13285 : "(expanded) access",
13286 list->name);
13287 else
13288 vty_out(vty,
13289 "Named extended community %s list %s\n",
13290 entry->style == EXTCOMMUNITY_LIST_STANDARD
13291 ? "standard"
13292 : "expanded",
13293 list->name);
13294 }
13295 if (entry->any)
13296 vty_out(vty, " %s\n",
13297 community_direct_str(entry->direct));
13298 else
13299 vty_out(vty, " %s %s\n",
13300 community_direct_str(entry->direct),
13301 entry->style == EXTCOMMUNITY_LIST_STANDARD
13302 ? entry->u.ecom->str
13303 : entry->config);
13304 }
718e3744 13305}
13306
13307DEFUN (show_ip_extcommunity_list,
13308 show_ip_extcommunity_list_cmd,
13309 "show ip extcommunity-list",
13310 SHOW_STR
13311 IP_STR
13312 "List extended-community list\n")
13313{
d62a17ae 13314 struct community_list *list;
13315 struct community_list_master *cm;
718e3744 13316
d62a17ae 13317 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13318 if (!cm)
13319 return CMD_SUCCESS;
718e3744 13320
d62a17ae 13321 for (list = cm->num.head; list; list = list->next)
13322 extcommunity_list_show(vty, list);
718e3744 13323
d62a17ae 13324 for (list = cm->str.head; list; list = list->next)
13325 extcommunity_list_show(vty, list);
718e3744 13326
d62a17ae 13327 return CMD_SUCCESS;
718e3744 13328}
13329
13330DEFUN (show_ip_extcommunity_list_arg,
13331 show_ip_extcommunity_list_arg_cmd,
6147e2c6 13332 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 13333 SHOW_STR
13334 IP_STR
13335 "List extended-community list\n"
13336 "Extcommunity-list number\n"
13337 "Extcommunity-list name\n")
13338{
d62a17ae 13339 int idx_comm_list = 3;
13340 struct community_list *list;
718e3744 13341
d62a17ae 13342 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13343 EXTCOMMUNITY_LIST_MASTER);
13344 if (!list) {
13345 vty_out(vty, "%% Can't find extcommunity-list\n");
13346 return CMD_WARNING;
13347 }
718e3744 13348
d62a17ae 13349 extcommunity_list_show(vty, list);
718e3744 13350
d62a17ae 13351 return CMD_SUCCESS;
718e3744 13352}
6b0655a2 13353
718e3744 13354/* Return configuration string of community-list entry. */
d62a17ae 13355static const char *community_list_config_str(struct community_entry *entry)
718e3744 13356{
d62a17ae 13357 const char *str;
718e3744 13358
d62a17ae 13359 if (entry->any)
13360 str = "";
13361 else {
13362 if (entry->style == COMMUNITY_LIST_STANDARD)
a69ea8ae 13363 str = community_str(entry->u.com, false);
d62a17ae 13364 else
13365 str = entry->config;
13366 }
13367 return str;
718e3744 13368}
13369
13370/* Display community-list and extcommunity-list configuration. */
d62a17ae 13371static int community_list_config_write(struct vty *vty)
13372{
13373 struct community_list *list;
13374 struct community_entry *entry;
13375 struct community_list_master *cm;
13376 int write = 0;
13377
13378 /* Community-list. */
13379 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13380
13381 for (list = cm->num.head; list; list = list->next)
13382 for (entry = list->head; entry; entry = entry->next) {
13383 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13384 community_direct_str(entry->direct),
13385 community_list_config_str(entry));
13386 write++;
13387 }
13388 for (list = cm->str.head; list; list = list->next)
13389 for (entry = list->head; entry; entry = entry->next) {
13390 vty_out(vty, "ip community-list %s %s %s %s\n",
13391 entry->style == COMMUNITY_LIST_STANDARD
13392 ? "standard"
13393 : "expanded",
13394 list->name, community_direct_str(entry->direct),
13395 community_list_config_str(entry));
13396 write++;
13397 }
13398
13399 /* Extcommunity-list. */
13400 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13401
13402 for (list = cm->num.head; list; list = list->next)
13403 for (entry = list->head; entry; entry = entry->next) {
13404 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13405 list->name, community_direct_str(entry->direct),
13406 community_list_config_str(entry));
13407 write++;
13408 }
13409 for (list = cm->str.head; list; list = list->next)
13410 for (entry = list->head; entry; entry = entry->next) {
13411 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13412 entry->style == EXTCOMMUNITY_LIST_STANDARD
13413 ? "standard"
13414 : "expanded",
13415 list->name, community_direct_str(entry->direct),
13416 community_list_config_str(entry));
13417 write++;
13418 }
13419
13420
13421 /* lcommunity-list. */
13422 cm = community_list_master_lookup(bgp_clist,
13423 LARGE_COMMUNITY_LIST_MASTER);
13424
13425 for (list = cm->num.head; list; list = list->next)
13426 for (entry = list->head; entry; entry = entry->next) {
13427 vty_out(vty, "ip large-community-list %s %s %s\n",
13428 list->name, community_direct_str(entry->direct),
13429 community_list_config_str(entry));
13430 write++;
13431 }
13432 for (list = cm->str.head; list; list = list->next)
13433 for (entry = list->head; entry; entry = entry->next) {
13434 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13435 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13436 ? "standard"
13437 : "expanded",
13438 list->name, community_direct_str(entry->direct),
13439 community_list_config_str(entry));
13440 write++;
13441 }
13442
13443 return write;
13444}
13445
13446static struct cmd_node community_list_node = {
13447 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 13448};
13449
d62a17ae 13450static void community_list_vty(void)
13451{
13452 install_node(&community_list_node, community_list_config_write);
13453
13454 /* Community-list. */
13455 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13456 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13457 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13458 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13459 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13460 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13461
13462 /* Extcommunity-list. */
13463 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13464 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13465 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13466 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13467 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13468 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13469
13470 /* Large Community List */
13471 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13472 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13473 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13474 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13475 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13476 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13477 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13478 install_element(CONFIG_NODE,
13479 &no_ip_lcommunity_list_name_expanded_all_cmd);
13480 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13481 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13482 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13483 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13484 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13485 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 13486}