]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
Merge pull request #1885 from msablic/pim_mtrace_client
[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) {
996c9314 835 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 836 return CMD_WARNING_CONFIG_FAILED;
837 }
838 }
839
840 // "router bgp X"
841 else {
842 as = strtoul(argv[idx_asn]->arg, NULL, 10);
843
844 inst_type = BGP_INSTANCE_TYPE_DEFAULT;
845 if (argc > 3) {
846 name = argv[idx_vrf]->arg;
847
848 if (!strcmp(argv[idx_view_vrf]->text, "vrf"))
849 inst_type = BGP_INSTANCE_TYPE_VRF;
850 else if (!strcmp(argv[idx_view_vrf]->text, "view"))
851 inst_type = BGP_INSTANCE_TYPE_VIEW;
852 }
853
854 ret = bgp_get(&bgp, &as, name, inst_type);
855 switch (ret) {
856 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
857 vty_out(vty,
858 "Please specify 'bgp multiple-instance' first\n");
859 return CMD_WARNING_CONFIG_FAILED;
860 case BGP_ERR_AS_MISMATCH:
861 vty_out(vty, "BGP is already running; AS is %u\n", as);
862 return CMD_WARNING_CONFIG_FAILED;
863 case BGP_ERR_INSTANCE_MISMATCH:
864 vty_out(vty,
865 "BGP instance name and AS number mismatch\n");
866 vty_out(vty,
867 "BGP instance is already running; AS is %u\n",
868 as);
869 return CMD_WARNING_CONFIG_FAILED;
870 }
871
872 /* Pending: handle when user tries to change a view to vrf n vv.
873 */
874 }
875
0b5131c9
MK
876 /* unset the auto created flag as the user config is now present */
877 UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO);
d62a17ae 878 VTY_PUSH_CONTEXT(BGP_NODE, bgp);
879
880 return CMD_SUCCESS;
718e3744 881}
882
718e3744 883/* "no router bgp" commands. */
884DEFUN (no_router_bgp,
885 no_router_bgp_cmd,
18c57037 886 "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
718e3744 887 NO_STR
888 ROUTER_STR
889 BGP_STR
31500417
DW
890 AS_STR
891 BGP_INSTANCE_HELP_STR)
718e3744 892{
d62a17ae 893 int idx_asn = 3;
894 int idx_vrf = 5;
895 as_t as;
896 struct bgp *bgp;
897 const char *name = NULL;
718e3744 898
d62a17ae 899 // "no router bgp" without an ASN
900 if (argc == 3) {
901 // Pending: Make VRF option available for ASN less config
902 bgp = bgp_get_default();
718e3744 903
d62a17ae 904 if (bgp == NULL) {
905 vty_out(vty, "%% No BGP process is configured\n");
906 return CMD_WARNING_CONFIG_FAILED;
907 }
7fb21a9f 908
d62a17ae 909 if (listcount(bm->bgp) > 1) {
996c9314 910 vty_out(vty, "%% Please specify ASN and VRF\n");
d62a17ae 911 return CMD_WARNING_CONFIG_FAILED;
912 }
0b5131c9
MK
913
914 if (bgp->l3vni) {
915 vty_out(vty, "%% Please unconfigure l3vni %u",
916 bgp->l3vni);
917 return CMD_WARNING_CONFIG_FAILED;
918 }
d62a17ae 919 } else {
920 as = strtoul(argv[idx_asn]->arg, NULL, 10);
7fb21a9f 921
d62a17ae 922 if (argc > 4)
923 name = argv[idx_vrf]->arg;
7fb21a9f 924
d62a17ae 925 /* Lookup bgp structure. */
926 bgp = bgp_lookup(as, name);
927 if (!bgp) {
928 vty_out(vty, "%% Can't find BGP instance\n");
929 return CMD_WARNING_CONFIG_FAILED;
930 }
0b5131c9
MK
931
932 if (bgp->l3vni) {
933 vty_out(vty, "%% Please unconfigure l3vni %u",
934 bgp->l3vni);
935 return CMD_WARNING_CONFIG_FAILED;
936 }
d62a17ae 937 }
718e3744 938
d62a17ae 939 bgp_delete(bgp);
718e3744 940
d62a17ae 941 return CMD_SUCCESS;
718e3744 942}
943
6b0655a2 944
718e3744 945/* BGP router-id. */
946
f787d7a0 947DEFPY (bgp_router_id,
718e3744 948 bgp_router_id_cmd,
949 "bgp router-id A.B.C.D",
950 BGP_STR
951 "Override configured router identifier\n"
952 "Manually configured router identifier\n")
953{
d62a17ae 954 VTY_DECLVAR_CONTEXT(bgp, bgp);
955 bgp_router_id_static_set(bgp, router_id);
956 return CMD_SUCCESS;
718e3744 957}
958
f787d7a0 959DEFPY (no_bgp_router_id,
718e3744 960 no_bgp_router_id_cmd,
31500417 961 "no bgp router-id [A.B.C.D]",
718e3744 962 NO_STR
963 BGP_STR
31500417
DW
964 "Override configured router identifier\n"
965 "Manually configured router identifier\n")
718e3744 966{
d62a17ae 967 VTY_DECLVAR_CONTEXT(bgp, bgp);
718e3744 968
d62a17ae 969 if (router_id_str) {
970 if (!IPV4_ADDR_SAME(&bgp->router_id_static, &router_id)) {
971 vty_out(vty, "%% BGP router-id doesn't match\n");
972 return CMD_WARNING_CONFIG_FAILED;
973 }
e018c7cc 974 }
718e3744 975
d62a17ae 976 router_id.s_addr = 0;
977 bgp_router_id_static_set(bgp, router_id);
718e3744 978
d62a17ae 979 return CMD_SUCCESS;
718e3744 980}
981
6b0655a2 982
718e3744 983/* BGP Cluster ID. */
718e3744 984DEFUN (bgp_cluster_id,
985 bgp_cluster_id_cmd,
838758ac 986 "bgp cluster-id <A.B.C.D|(1-4294967295)>",
718e3744 987 BGP_STR
988 "Configure Route-Reflector Cluster-id\n"
838758ac
DW
989 "Route-Reflector Cluster-id in IP address format\n"
990 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 991{
d62a17ae 992 VTY_DECLVAR_CONTEXT(bgp, bgp);
993 int idx_ipv4 = 2;
994 int ret;
995 struct in_addr cluster;
718e3744 996
d62a17ae 997 ret = inet_aton(argv[idx_ipv4]->arg, &cluster);
998 if (!ret) {
999 vty_out(vty, "%% Malformed bgp cluster identifier\n");
1000 return CMD_WARNING_CONFIG_FAILED;
1001 }
718e3744 1002
d62a17ae 1003 bgp_cluster_id_set(bgp, &cluster);
1004 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1005
d62a17ae 1006 return CMD_SUCCESS;
718e3744 1007}
1008
718e3744 1009DEFUN (no_bgp_cluster_id,
1010 no_bgp_cluster_id_cmd,
c7178fe7 1011 "no bgp cluster-id [<A.B.C.D|(1-4294967295)>]",
718e3744 1012 NO_STR
1013 BGP_STR
838758ac
DW
1014 "Configure Route-Reflector Cluster-id\n"
1015 "Route-Reflector Cluster-id in IP address format\n"
1016 "Route-Reflector Cluster-id as 32 bit quantity\n")
718e3744 1017{
d62a17ae 1018 VTY_DECLVAR_CONTEXT(bgp, bgp);
1019 bgp_cluster_id_unset(bgp);
1020 bgp_clear_star_soft_out(vty, bgp->name);
718e3744 1021
d62a17ae 1022 return CMD_SUCCESS;
718e3744 1023}
1024
718e3744 1025DEFUN (bgp_confederation_identifier,
1026 bgp_confederation_identifier_cmd,
9ccf14f7 1027 "bgp confederation identifier (1-4294967295)",
718e3744 1028 "BGP specific commands\n"
1029 "AS confederation parameters\n"
1030 "AS number\n"
1031 "Set routing domain confederation AS\n")
1032{
d62a17ae 1033 VTY_DECLVAR_CONTEXT(bgp, bgp);
1034 int idx_number = 3;
1035 as_t as;
718e3744 1036
d62a17ae 1037 as = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 1038
d62a17ae 1039 bgp_confederation_id_set(bgp, as);
718e3744 1040
d62a17ae 1041 return CMD_SUCCESS;
718e3744 1042}
1043
1044DEFUN (no_bgp_confederation_identifier,
1045 no_bgp_confederation_identifier_cmd,
838758ac 1046 "no bgp confederation identifier [(1-4294967295)]",
718e3744 1047 NO_STR
1048 "BGP specific commands\n"
1049 "AS confederation parameters\n"
3a2d747c
QY
1050 "AS number\n"
1051 "Set routing domain confederation AS\n")
718e3744 1052{
d62a17ae 1053 VTY_DECLVAR_CONTEXT(bgp, bgp);
1054 bgp_confederation_id_unset(bgp);
718e3744 1055
d62a17ae 1056 return CMD_SUCCESS;
718e3744 1057}
1058
718e3744 1059DEFUN (bgp_confederation_peers,
1060 bgp_confederation_peers_cmd,
12dcf78e 1061 "bgp confederation peers (1-4294967295)...",
718e3744 1062 "BGP specific commands\n"
1063 "AS confederation parameters\n"
1064 "Peer ASs in BGP confederation\n"
1065 AS_STR)
1066{
d62a17ae 1067 VTY_DECLVAR_CONTEXT(bgp, bgp);
1068 int idx_asn = 3;
1069 as_t as;
1070 int i;
718e3744 1071
d62a17ae 1072 for (i = idx_asn; i < argc; i++) {
1073 as = strtoul(argv[i]->arg, NULL, 10);
718e3744 1074
d62a17ae 1075 if (bgp->as == as) {
1076 vty_out(vty,
1077 "%% Local member-AS not allowed in confed peer list\n");
1078 continue;
1079 }
718e3744 1080
d62a17ae 1081 bgp_confederation_peers_add(bgp, as);
1082 }
1083 return CMD_SUCCESS;
718e3744 1084}
1085
1086DEFUN (no_bgp_confederation_peers,
1087 no_bgp_confederation_peers_cmd,
e83a9414 1088 "no bgp confederation peers (1-4294967295)...",
718e3744 1089 NO_STR
1090 "BGP specific commands\n"
1091 "AS confederation parameters\n"
1092 "Peer ASs in BGP confederation\n"
1093 AS_STR)
1094{
d62a17ae 1095 VTY_DECLVAR_CONTEXT(bgp, bgp);
1096 int idx_asn = 4;
1097 as_t as;
1098 int i;
718e3744 1099
d62a17ae 1100 for (i = idx_asn; i < argc; i++) {
1101 as = strtoul(argv[i]->arg, NULL, 10);
0b2aa3a0 1102
d62a17ae 1103 bgp_confederation_peers_remove(bgp, as);
1104 }
1105 return CMD_SUCCESS;
718e3744 1106}
6b0655a2 1107
5e242b0d
DS
1108/**
1109 * Central routine for maximum-paths configuration.
1110 * @peer_type: BGP_PEER_EBGP or BGP_PEER_IBGP
1111 * @set: 1 for setting values, 0 for removing the max-paths config.
1112 */
d62a17ae 1113static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type,
1114 const char *mpaths, u_int16_t options,
1115 int set)
1116{
1117 VTY_DECLVAR_CONTEXT(bgp, bgp);
1118 u_int16_t maxpaths = 0;
1119 int ret;
1120 afi_t afi;
1121 safi_t safi;
1122
1123 afi = bgp_node_afi(vty);
1124 safi = bgp_node_safi(vty);
1125
1126 if (set) {
1127 maxpaths = strtol(mpaths, NULL, 10);
1128 if (maxpaths > multipath_num) {
1129 vty_out(vty,
1130 "%% Maxpaths Specified: %d is > than multipath num specified on bgp command line %d",
1131 maxpaths, multipath_num);
1132 return CMD_WARNING_CONFIG_FAILED;
1133 }
1134 ret = bgp_maximum_paths_set(bgp, afi, safi, peer_type, maxpaths,
1135 options);
1136 } else
1137 ret = bgp_maximum_paths_unset(bgp, afi, safi, peer_type);
1138
1139 if (ret < 0) {
1140 vty_out(vty,
1141 "%% Failed to %sset maximum-paths %s %u for afi %u, safi %u\n",
1142 (set == 1) ? "" : "un",
1143 (peer_type == BGP_PEER_EBGP) ? "ebgp" : "ibgp",
1144 maxpaths, afi, safi);
1145 return CMD_WARNING_CONFIG_FAILED;
1146 }
1147
1148 bgp_recalculate_all_bestpaths(bgp);
1149
1150 return CMD_SUCCESS;
165b5fff
JB
1151}
1152
abc920f8
DS
1153DEFUN (bgp_maxmed_admin,
1154 bgp_maxmed_admin_cmd,
1155 "bgp max-med administrative ",
1156 BGP_STR
1157 "Advertise routes with max-med\n"
1158 "Administratively applied, for an indefinite period\n")
1159{
d62a17ae 1160 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1161
d62a17ae 1162 bgp->v_maxmed_admin = 1;
1163 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1164
d62a17ae 1165 bgp_maxmed_update(bgp);
abc920f8 1166
d62a17ae 1167 return CMD_SUCCESS;
abc920f8
DS
1168}
1169
1170DEFUN (bgp_maxmed_admin_medv,
1171 bgp_maxmed_admin_medv_cmd,
4668a151 1172 "bgp max-med administrative (0-4294967295)",
abc920f8
DS
1173 BGP_STR
1174 "Advertise routes with max-med\n"
1175 "Administratively applied, for an indefinite period\n"
1176 "Max MED value to be used\n")
1177{
d62a17ae 1178 VTY_DECLVAR_CONTEXT(bgp, bgp);
1179 int idx_number = 3;
abc920f8 1180
d62a17ae 1181 bgp->v_maxmed_admin = 1;
1182 bgp->maxmed_admin_value = strtoul(argv[idx_number]->arg, NULL, 10);
abc920f8 1183
d62a17ae 1184 bgp_maxmed_update(bgp);
abc920f8 1185
d62a17ae 1186 return CMD_SUCCESS;
abc920f8
DS
1187}
1188
1189DEFUN (no_bgp_maxmed_admin,
1190 no_bgp_maxmed_admin_cmd,
4668a151 1191 "no bgp max-med administrative [(0-4294967295)]",
abc920f8
DS
1192 NO_STR
1193 BGP_STR
1194 "Advertise routes with max-med\n"
838758ac
DW
1195 "Administratively applied, for an indefinite period\n"
1196 "Max MED value to be used\n")
abc920f8 1197{
d62a17ae 1198 VTY_DECLVAR_CONTEXT(bgp, bgp);
1199 bgp->v_maxmed_admin = BGP_MAXMED_ADMIN_UNCONFIGURED;
1200 bgp->maxmed_admin_value = BGP_MAXMED_VALUE_DEFAULT;
1201 bgp_maxmed_update(bgp);
abc920f8 1202
d62a17ae 1203 return CMD_SUCCESS;
abc920f8
DS
1204}
1205
abc920f8
DS
1206DEFUN (bgp_maxmed_onstartup,
1207 bgp_maxmed_onstartup_cmd,
4668a151 1208 "bgp max-med on-startup (5-86400) [(0-4294967295)]",
abc920f8
DS
1209 BGP_STR
1210 "Advertise routes with max-med\n"
1211 "Effective on a startup\n"
1212 "Time (seconds) period for max-med\n"
1213 "Max MED value to be used\n")
1214{
d62a17ae 1215 VTY_DECLVAR_CONTEXT(bgp, bgp);
1216 int idx = 0;
4668a151 1217
d62a17ae 1218 argv_find(argv, argc, "(5-86400)", &idx);
1219 bgp->v_maxmed_onstartup = strtoul(argv[idx]->arg, NULL, 10);
1220 if (argv_find(argv, argc, "(0-4294967295)", &idx))
1221 bgp->maxmed_onstartup_value = strtoul(argv[idx]->arg, NULL, 10);
1222 else
1223 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
4668a151 1224
d62a17ae 1225 bgp_maxmed_update(bgp);
abc920f8 1226
d62a17ae 1227 return CMD_SUCCESS;
abc920f8
DS
1228}
1229
1230DEFUN (no_bgp_maxmed_onstartup,
1231 no_bgp_maxmed_onstartup_cmd,
4668a151 1232 "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
abc920f8
DS
1233 NO_STR
1234 BGP_STR
1235 "Advertise routes with max-med\n"
838758ac
DW
1236 "Effective on a startup\n"
1237 "Time (seconds) period for max-med\n"
1238 "Max MED value to be used\n")
abc920f8 1239{
d62a17ae 1240 VTY_DECLVAR_CONTEXT(bgp, bgp);
abc920f8 1241
d62a17ae 1242 /* Cancel max-med onstartup if its on */
1243 if (bgp->t_maxmed_onstartup) {
1244 THREAD_TIMER_OFF(bgp->t_maxmed_onstartup);
1245 bgp->maxmed_onstartup_over = 1;
1246 }
abc920f8 1247
d62a17ae 1248 bgp->v_maxmed_onstartup = BGP_MAXMED_ONSTARTUP_UNCONFIGURED;
1249 bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
abc920f8 1250
d62a17ae 1251 bgp_maxmed_update(bgp);
abc920f8 1252
d62a17ae 1253 return CMD_SUCCESS;
abc920f8
DS
1254}
1255
d62a17ae 1256static int bgp_update_delay_config_vty(struct vty *vty, const char *delay,
1257 const char *wait)
f188f2c4 1258{
d62a17ae 1259 VTY_DECLVAR_CONTEXT(bgp, bgp);
1260 u_int16_t update_delay;
1261 u_int16_t establish_wait;
f188f2c4 1262
d62a17ae 1263 update_delay = strtoul(delay, NULL, 10);
f188f2c4 1264
d62a17ae 1265 if (!wait) /* update-delay <delay> */
1266 {
1267 bgp->v_update_delay = update_delay;
1268 bgp->v_establish_wait = bgp->v_update_delay;
1269 return CMD_SUCCESS;
1270 }
f188f2c4 1271
d62a17ae 1272 /* update-delay <delay> <establish-wait> */
1273 establish_wait = atoi(wait);
1274 if (update_delay < establish_wait) {
1275 vty_out(vty,
1276 "%%Failed: update-delay less than the establish-wait!\n");
1277 return CMD_WARNING_CONFIG_FAILED;
1278 }
f188f2c4 1279
d62a17ae 1280 bgp->v_update_delay = update_delay;
1281 bgp->v_establish_wait = establish_wait;
f188f2c4 1282
d62a17ae 1283 return CMD_SUCCESS;
f188f2c4
DS
1284}
1285
d62a17ae 1286static int bgp_update_delay_deconfig_vty(struct vty *vty)
f188f2c4 1287{
d62a17ae 1288 VTY_DECLVAR_CONTEXT(bgp, bgp);
f188f2c4 1289
d62a17ae 1290 bgp->v_update_delay = BGP_UPDATE_DELAY_DEF;
1291 bgp->v_establish_wait = bgp->v_update_delay;
f188f2c4 1292
d62a17ae 1293 return CMD_SUCCESS;
f188f2c4
DS
1294}
1295
2b791107 1296void bgp_config_write_update_delay(struct vty *vty, struct bgp *bgp)
f188f2c4 1297{
d62a17ae 1298 if (bgp->v_update_delay != BGP_UPDATE_DELAY_DEF) {
1299 vty_out(vty, " update-delay %d", bgp->v_update_delay);
1300 if (bgp->v_update_delay != bgp->v_establish_wait)
1301 vty_out(vty, " %d", bgp->v_establish_wait);
1302 vty_out(vty, "\n");
1303 }
f188f2c4
DS
1304}
1305
1306
1307/* Update-delay configuration */
1308DEFUN (bgp_update_delay,
1309 bgp_update_delay_cmd,
6147e2c6 1310 "update-delay (0-3600)",
f188f2c4
DS
1311 "Force initial delay for best-path and updates\n"
1312 "Seconds\n")
1313{
d62a17ae 1314 int idx_number = 1;
1315 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg, NULL);
f188f2c4
DS
1316}
1317
1318DEFUN (bgp_update_delay_establish_wait,
1319 bgp_update_delay_establish_wait_cmd,
6147e2c6 1320 "update-delay (0-3600) (1-3600)",
f188f2c4
DS
1321 "Force initial delay for best-path and updates\n"
1322 "Seconds\n"
f188f2c4
DS
1323 "Seconds\n")
1324{
d62a17ae 1325 int idx_number = 1;
1326 int idx_number_2 = 2;
1327 return bgp_update_delay_config_vty(vty, argv[idx_number]->arg,
1328 argv[idx_number_2]->arg);
f188f2c4
DS
1329}
1330
1331/* Update-delay deconfiguration */
1332DEFUN (no_bgp_update_delay,
1333 no_bgp_update_delay_cmd,
838758ac
DW
1334 "no update-delay [(0-3600) [(1-3600)]]",
1335 NO_STR
f188f2c4 1336 "Force initial delay for best-path and updates\n"
838758ac 1337 "Seconds\n"
7111c1a0 1338 "Seconds\n")
f188f2c4 1339{
d62a17ae 1340 return bgp_update_delay_deconfig_vty(vty);
f188f2c4
DS
1341}
1342
5e242b0d 1343
d62a17ae 1344static int bgp_wpkt_quanta_config_vty(struct vty *vty, const char *num,
1345 char set)
cb1faec9 1346{
d62a17ae 1347 VTY_DECLVAR_CONTEXT(bgp, bgp);
cb1faec9 1348
555e09d4
QY
1349 if (set) {
1350 uint32_t quanta = strtoul(num, NULL, 10);
1351 atomic_store_explicit(&bgp->wpkt_quanta, quanta,
1352 memory_order_relaxed);
1353 } else {
1354 atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX,
1355 memory_order_relaxed);
1356 }
1357
1358 return CMD_SUCCESS;
1359}
1360
1361static int bgp_rpkt_quanta_config_vty(struct vty *vty, const char *num,
1362 char set)
1363{
1364 VTY_DECLVAR_CONTEXT(bgp, bgp);
1365
1366 if (set) {
1367 uint32_t quanta = strtoul(num, NULL, 10);
1368 atomic_store_explicit(&bgp->rpkt_quanta, quanta,
1369 memory_order_relaxed);
1370 } else {
1371 atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX,
1372 memory_order_relaxed);
1373 }
cb1faec9 1374
d62a17ae 1375 return CMD_SUCCESS;
cb1faec9
DS
1376}
1377
2b791107 1378void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp)
cb1faec9 1379{
555e09d4
QY
1380 uint32_t quanta =
1381 atomic_load_explicit(&bgp->wpkt_quanta, memory_order_relaxed);
1382 if (quanta != BGP_WRITE_PACKET_MAX)
152456fe 1383 vty_out(vty, " write-quanta %d\n", quanta);
cb1faec9
DS
1384}
1385
555e09d4
QY
1386void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp)
1387{
1388 uint32_t quanta =
1389 atomic_load_explicit(&bgp->rpkt_quanta, memory_order_relaxed);
1390 if (quanta != BGP_READ_PACKET_MAX)
152456fe 1391 vty_out(vty, " read-quanta %d\n", quanta);
555e09d4 1392}
cb1faec9 1393
555e09d4 1394/* Packet quanta configuration */
cb1faec9
DS
1395DEFUN (bgp_wpkt_quanta,
1396 bgp_wpkt_quanta_cmd,
555e09d4 1397 "write-quanta (1-10)",
cb1faec9
DS
1398 "How many packets to write to peer socket per run\n"
1399 "Number of packets\n")
1400{
d62a17ae 1401 int idx_number = 1;
1402 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
cb1faec9
DS
1403}
1404
cb1faec9
DS
1405DEFUN (no_bgp_wpkt_quanta,
1406 no_bgp_wpkt_quanta_cmd,
555e09d4 1407 "no write-quanta (1-10)",
d7fa34c1 1408 NO_STR
555e09d4 1409 "How many packets to write to peer socket per I/O cycle\n"
cb1faec9
DS
1410 "Number of packets\n")
1411{
d62a17ae 1412 int idx_number = 2;
1413 return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
cb1faec9
DS
1414}
1415
555e09d4
QY
1416DEFUN (bgp_rpkt_quanta,
1417 bgp_rpkt_quanta_cmd,
1418 "read-quanta (1-10)",
1419 "How many packets to read from peer socket per I/O cycle\n"
1420 "Number of packets\n")
1421{
1422 int idx_number = 1;
1423 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 1);
1424}
1425
1426DEFUN (no_bgp_rpkt_quanta,
1427 no_bgp_rpkt_quanta_cmd,
1428 "no read-quanta (1-10)",
1429 NO_STR
1430 "How many packets to read from peer socket per I/O cycle\n"
1431 "Number of packets\n")
1432{
1433 int idx_number = 2;
1434 return bgp_rpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
1435}
1436
2b791107 1437void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp)
3f9c7369 1438{
37a333fe 1439 if (!bgp->heuristic_coalesce)
d62a17ae 1440 vty_out(vty, " coalesce-time %u\n", bgp->coalesce_time);
3f9c7369
DS
1441}
1442
1443
1444DEFUN (bgp_coalesce_time,
1445 bgp_coalesce_time_cmd,
6147e2c6 1446 "coalesce-time (0-4294967295)",
3f9c7369
DS
1447 "Subgroup coalesce timer\n"
1448 "Subgroup coalesce timer value (in ms)\n")
1449{
d62a17ae 1450 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1451
d62a17ae 1452 int idx = 0;
1453 argv_find(argv, argc, "(0-4294967295)", &idx);
37a333fe 1454 bgp->heuristic_coalesce = false;
d62a17ae 1455 bgp->coalesce_time = strtoul(argv[idx]->arg, NULL, 10);
1456 return CMD_SUCCESS;
3f9c7369
DS
1457}
1458
1459DEFUN (no_bgp_coalesce_time,
1460 no_bgp_coalesce_time_cmd,
6147e2c6 1461 "no coalesce-time (0-4294967295)",
3a2d747c 1462 NO_STR
3f9c7369
DS
1463 "Subgroup coalesce timer\n"
1464 "Subgroup coalesce timer value (in ms)\n")
1465{
d62a17ae 1466 VTY_DECLVAR_CONTEXT(bgp, bgp);
4668a151 1467
37a333fe 1468 bgp->heuristic_coalesce = true;
d62a17ae 1469 bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
1470 return CMD_SUCCESS;
3f9c7369
DS
1471}
1472
5e242b0d
DS
1473/* Maximum-paths configuration */
1474DEFUN (bgp_maxpaths,
1475 bgp_maxpaths_cmd,
6319fd63 1476 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
5e242b0d
DS
1477 "Forward packets over multiple paths\n"
1478 "Number of paths\n")
1479{
d62a17ae 1480 int idx_number = 1;
1481 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP,
1482 argv[idx_number]->arg, 0, 1);
5e242b0d
DS
1483}
1484
d62a17ae 1485ALIAS_HIDDEN(bgp_maxpaths, bgp_maxpaths_hidden_cmd,
1486 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
1487 "Forward packets over multiple paths\n"
1488 "Number of paths\n")
596c17ba 1489
165b5fff
JB
1490DEFUN (bgp_maxpaths_ibgp,
1491 bgp_maxpaths_ibgp_cmd,
6319fd63 1492 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
165b5fff
JB
1493 "Forward packets over multiple paths\n"
1494 "iBGP-multipath\n"
1495 "Number of paths\n")
1496{
d62a17ae 1497 int idx_number = 2;
1498 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP,
1499 argv[idx_number]->arg, 0, 1);
5e242b0d 1500}
165b5fff 1501
d62a17ae 1502ALIAS_HIDDEN(bgp_maxpaths_ibgp, bgp_maxpaths_ibgp_hidden_cmd,
1503 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM),
1504 "Forward packets over multiple paths\n"
1505 "iBGP-multipath\n"
1506 "Number of paths\n")
596c17ba 1507
5e242b0d
DS
1508DEFUN (bgp_maxpaths_ibgp_cluster,
1509 bgp_maxpaths_ibgp_cluster_cmd,
6319fd63 1510 "maximum-paths ibgp " CMD_RANGE_STR(1, MULTIPATH_NUM) " equal-cluster-length",
5e242b0d
DS
1511 "Forward packets over multiple paths\n"
1512 "iBGP-multipath\n"
1513 "Number of paths\n"
1514 "Match the cluster length\n")
1515{
d62a17ae 1516 int idx_number = 2;
1517 return bgp_maxpaths_config_vty(
1518 vty, BGP_PEER_IBGP, argv[idx_number]->arg,
1519 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN, 1);
165b5fff
JB
1520}
1521
d62a17ae 1522ALIAS_HIDDEN(bgp_maxpaths_ibgp_cluster, bgp_maxpaths_ibgp_cluster_hidden_cmd,
1523 "maximum-paths ibgp " CMD_RANGE_STR(
1524 1, MULTIPATH_NUM) " equal-cluster-length",
1525 "Forward packets over multiple paths\n"
1526 "iBGP-multipath\n"
1527 "Number of paths\n"
1528 "Match the cluster length\n")
596c17ba 1529
165b5fff
JB
1530DEFUN (no_bgp_maxpaths,
1531 no_bgp_maxpaths_cmd,
6319fd63 1532 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]",
165b5fff
JB
1533 NO_STR
1534 "Forward packets over multiple paths\n"
1535 "Number of paths\n")
1536{
d62a17ae 1537 return bgp_maxpaths_config_vty(vty, BGP_PEER_EBGP, NULL, 0, 0);
165b5fff
JB
1538}
1539
d62a17ae 1540ALIAS_HIDDEN(no_bgp_maxpaths, no_bgp_maxpaths_hidden_cmd,
996c9314 1541 "no maximum-paths [" CMD_RANGE_STR(1, MULTIPATH_NUM) "]", NO_STR
d62a17ae 1542 "Forward packets over multiple paths\n"
1543 "Number of paths\n")
596c17ba 1544
165b5fff
JB
1545DEFUN (no_bgp_maxpaths_ibgp,
1546 no_bgp_maxpaths_ibgp_cmd,
6319fd63 1547 "no maximum-paths ibgp [" CMD_RANGE_STR(1, MULTIPATH_NUM) " [equal-cluster-length]]",
165b5fff
JB
1548 NO_STR
1549 "Forward packets over multiple paths\n"
1550 "iBGP-multipath\n"
838758ac
DW
1551 "Number of paths\n"
1552 "Match the cluster length\n")
165b5fff 1553{
d62a17ae 1554 return bgp_maxpaths_config_vty(vty, BGP_PEER_IBGP, NULL, 0, 0);
165b5fff
JB
1555}
1556
d62a17ae 1557ALIAS_HIDDEN(no_bgp_maxpaths_ibgp, no_bgp_maxpaths_ibgp_hidden_cmd,
1558 "no maximum-paths ibgp [" CMD_RANGE_STR(
1559 1, MULTIPATH_NUM) " [equal-cluster-length]]",
1560 NO_STR
1561 "Forward packets over multiple paths\n"
1562 "iBGP-multipath\n"
1563 "Number of paths\n"
1564 "Match the cluster length\n")
596c17ba 1565
2b791107 1566void bgp_config_write_maxpaths(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 1567 safi_t safi)
165b5fff 1568{
d62a17ae 1569 if (bgp->maxpaths[afi][safi].maxpaths_ebgp != MULTIPATH_NUM) {
d62a17ae 1570 vty_out(vty, " maximum-paths %d\n",
1571 bgp->maxpaths[afi][safi].maxpaths_ebgp);
1572 }
165b5fff 1573
d62a17ae 1574 if (bgp->maxpaths[afi][safi].maxpaths_ibgp != MULTIPATH_NUM) {
d62a17ae 1575 vty_out(vty, " maximum-paths ibgp %d",
1576 bgp->maxpaths[afi][safi].maxpaths_ibgp);
1577 if (CHECK_FLAG(bgp->maxpaths[afi][safi].ibgp_flags,
1578 BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))
1579 vty_out(vty, " equal-cluster-length");
1580 vty_out(vty, "\n");
1581 }
165b5fff 1582}
6b0655a2 1583
718e3744 1584/* BGP timers. */
1585
1586DEFUN (bgp_timers,
1587 bgp_timers_cmd,
6147e2c6 1588 "timers bgp (0-65535) (0-65535)",
718e3744 1589 "Adjust routing timers\n"
1590 "BGP timers\n"
1591 "Keepalive interval\n"
1592 "Holdtime\n")
1593{
d62a17ae 1594 VTY_DECLVAR_CONTEXT(bgp, bgp);
1595 int idx_number = 2;
1596 int idx_number_2 = 3;
1597 unsigned long keepalive = 0;
1598 unsigned long holdtime = 0;
718e3744 1599
d62a17ae 1600 keepalive = strtoul(argv[idx_number]->arg, NULL, 10);
1601 holdtime = strtoul(argv[idx_number_2]->arg, NULL, 10);
718e3744 1602
d62a17ae 1603 /* Holdtime value check. */
1604 if (holdtime < 3 && holdtime != 0) {
1605 vty_out(vty,
1606 "%% hold time value must be either 0 or greater than 3\n");
1607 return CMD_WARNING_CONFIG_FAILED;
1608 }
718e3744 1609
d62a17ae 1610 bgp_timers_set(bgp, keepalive, holdtime);
718e3744 1611
d62a17ae 1612 return CMD_SUCCESS;
718e3744 1613}
1614
1615DEFUN (no_bgp_timers,
1616 no_bgp_timers_cmd,
838758ac 1617 "no timers bgp [(0-65535) (0-65535)]",
718e3744 1618 NO_STR
1619 "Adjust routing timers\n"
838758ac
DW
1620 "BGP timers\n"
1621 "Keepalive interval\n"
1622 "Holdtime\n")
718e3744 1623{
d62a17ae 1624 VTY_DECLVAR_CONTEXT(bgp, bgp);
1625 bgp_timers_unset(bgp);
718e3744 1626
d62a17ae 1627 return CMD_SUCCESS;
718e3744 1628}
1629
6b0655a2 1630
718e3744 1631DEFUN (bgp_client_to_client_reflection,
1632 bgp_client_to_client_reflection_cmd,
1633 "bgp client-to-client reflection",
1634 "BGP specific commands\n"
1635 "Configure client to client route reflection\n"
1636 "reflection of routes allowed\n")
1637{
d62a17ae 1638 VTY_DECLVAR_CONTEXT(bgp, bgp);
1639 bgp_flag_unset(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1640 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1641
d62a17ae 1642 return CMD_SUCCESS;
718e3744 1643}
1644
1645DEFUN (no_bgp_client_to_client_reflection,
1646 no_bgp_client_to_client_reflection_cmd,
1647 "no bgp client-to-client reflection",
1648 NO_STR
1649 "BGP specific commands\n"
1650 "Configure client to client route reflection\n"
1651 "reflection of routes allowed\n")
1652{
d62a17ae 1653 VTY_DECLVAR_CONTEXT(bgp, bgp);
1654 bgp_flag_set(bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT);
1655 bgp_clear_star_soft_out(vty, bgp->name);
7aafcaca 1656
d62a17ae 1657 return CMD_SUCCESS;
718e3744 1658}
1659
1660/* "bgp always-compare-med" configuration. */
1661DEFUN (bgp_always_compare_med,
1662 bgp_always_compare_med_cmd,
1663 "bgp always-compare-med",
1664 "BGP specific commands\n"
1665 "Allow comparing MED from different neighbors\n")
1666{
d62a17ae 1667 VTY_DECLVAR_CONTEXT(bgp, bgp);
1668 bgp_flag_set(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1669 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1670
d62a17ae 1671 return CMD_SUCCESS;
718e3744 1672}
1673
1674DEFUN (no_bgp_always_compare_med,
1675 no_bgp_always_compare_med_cmd,
1676 "no bgp always-compare-med",
1677 NO_STR
1678 "BGP specific commands\n"
1679 "Allow comparing MED from different neighbors\n")
1680{
d62a17ae 1681 VTY_DECLVAR_CONTEXT(bgp, bgp);
1682 bgp_flag_unset(bgp, BGP_FLAG_ALWAYS_COMPARE_MED);
1683 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1684
d62a17ae 1685 return CMD_SUCCESS;
718e3744 1686}
6b0655a2 1687
718e3744 1688/* "bgp deterministic-med" configuration. */
1689DEFUN (bgp_deterministic_med,
1690 bgp_deterministic_med_cmd,
1691 "bgp deterministic-med",
1692 "BGP specific commands\n"
1693 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1694{
d62a17ae 1695 VTY_DECLVAR_CONTEXT(bgp, bgp);
1475ac87 1696
d62a17ae 1697 if (!bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1698 bgp_flag_set(bgp, BGP_FLAG_DETERMINISTIC_MED);
1699 bgp_recalculate_all_bestpaths(bgp);
1700 }
7aafcaca 1701
d62a17ae 1702 return CMD_SUCCESS;
718e3744 1703}
1704
1705DEFUN (no_bgp_deterministic_med,
1706 no_bgp_deterministic_med_cmd,
1707 "no bgp deterministic-med",
1708 NO_STR
1709 "BGP specific commands\n"
1710 "Pick the best-MED path among paths advertised from the neighboring AS\n")
1711{
d62a17ae 1712 VTY_DECLVAR_CONTEXT(bgp, bgp);
1713 int bestpath_per_as_used;
1714 afi_t afi;
1715 safi_t safi;
1716 struct peer *peer;
1717 struct listnode *node, *nnode;
1718
1719 if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) {
1720 bestpath_per_as_used = 0;
1721
1722 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
05c7a1cc
QY
1723 FOREACH_AFI_SAFI (afi, safi)
1724 if (CHECK_FLAG(
1725 peer->af_flags[afi][safi],
1726 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS)) {
1727 bestpath_per_as_used = 1;
1728 break;
1729 }
d62a17ae 1730
1731 if (bestpath_per_as_used)
1732 break;
1733 }
1734
1735 if (bestpath_per_as_used) {
1736 vty_out(vty,
1737 "bgp deterministic-med cannot be disabled while addpath-tx-bestpath-per-AS is in use\n");
1738 return CMD_WARNING_CONFIG_FAILED;
1739 } else {
1740 bgp_flag_unset(bgp, BGP_FLAG_DETERMINISTIC_MED);
1741 bgp_recalculate_all_bestpaths(bgp);
1742 }
1743 }
1744
1745 return CMD_SUCCESS;
718e3744 1746}
538621f2 1747
1748/* "bgp graceful-restart" configuration. */
1749DEFUN (bgp_graceful_restart,
1750 bgp_graceful_restart_cmd,
1751 "bgp graceful-restart",
1752 "BGP specific commands\n"
1753 "Graceful restart capability parameters\n")
1754{
d62a17ae 1755 VTY_DECLVAR_CONTEXT(bgp, bgp);
1756 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_RESTART);
1757 return CMD_SUCCESS;
538621f2 1758}
1759
1760DEFUN (no_bgp_graceful_restart,
1761 no_bgp_graceful_restart_cmd,
1762 "no bgp graceful-restart",
1763 NO_STR
1764 "BGP specific commands\n"
1765 "Graceful restart capability parameters\n")
1766{
d62a17ae 1767 VTY_DECLVAR_CONTEXT(bgp, bgp);
1768 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_RESTART);
1769 return CMD_SUCCESS;
538621f2 1770}
1771
93406d87 1772DEFUN (bgp_graceful_restart_stalepath_time,
1773 bgp_graceful_restart_stalepath_time_cmd,
6147e2c6 1774 "bgp graceful-restart stalepath-time (1-3600)",
93406d87 1775 "BGP specific commands\n"
1776 "Graceful restart capability parameters\n"
1777 "Set the max time to hold onto restarting peer's stale paths\n"
1778 "Delay value (seconds)\n")
1779{
d62a17ae 1780 VTY_DECLVAR_CONTEXT(bgp, bgp);
1781 int idx_number = 3;
1782 u_int32_t stalepath;
93406d87 1783
d62a17ae 1784 stalepath = strtoul(argv[idx_number]->arg, NULL, 10);
1785 bgp->stalepath_time = stalepath;
1786 return CMD_SUCCESS;
93406d87 1787}
1788
eb6f1b41
PG
1789DEFUN (bgp_graceful_restart_restart_time,
1790 bgp_graceful_restart_restart_time_cmd,
6147e2c6 1791 "bgp graceful-restart restart-time (1-3600)",
eb6f1b41
PG
1792 "BGP specific commands\n"
1793 "Graceful restart capability parameters\n"
1794 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1795 "Delay value (seconds)\n")
1796{
d62a17ae 1797 VTY_DECLVAR_CONTEXT(bgp, bgp);
1798 int idx_number = 3;
1799 u_int32_t restart;
eb6f1b41 1800
d62a17ae 1801 restart = strtoul(argv[idx_number]->arg, NULL, 10);
1802 bgp->restart_time = restart;
1803 return CMD_SUCCESS;
eb6f1b41
PG
1804}
1805
93406d87 1806DEFUN (no_bgp_graceful_restart_stalepath_time,
1807 no_bgp_graceful_restart_stalepath_time_cmd,
838758ac 1808 "no bgp graceful-restart stalepath-time [(1-3600)]",
93406d87 1809 NO_STR
1810 "BGP specific commands\n"
1811 "Graceful restart capability parameters\n"
838758ac
DW
1812 "Set the max time to hold onto restarting peer's stale paths\n"
1813 "Delay value (seconds)\n")
93406d87 1814{
d62a17ae 1815 VTY_DECLVAR_CONTEXT(bgp, bgp);
93406d87 1816
d62a17ae 1817 bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
1818 return CMD_SUCCESS;
93406d87 1819}
1820
eb6f1b41
PG
1821DEFUN (no_bgp_graceful_restart_restart_time,
1822 no_bgp_graceful_restart_restart_time_cmd,
838758ac 1823 "no bgp graceful-restart restart-time [(1-3600)]",
eb6f1b41
PG
1824 NO_STR
1825 "BGP specific commands\n"
1826 "Graceful restart capability parameters\n"
838758ac
DW
1827 "Set the time to wait to delete stale routes before a BGP open message is received\n"
1828 "Delay value (seconds)\n")
eb6f1b41 1829{
d62a17ae 1830 VTY_DECLVAR_CONTEXT(bgp, bgp);
eb6f1b41 1831
d62a17ae 1832 bgp->restart_time = BGP_DEFAULT_RESTART_TIME;
1833 return CMD_SUCCESS;
eb6f1b41
PG
1834}
1835
43fc21b3
JC
1836DEFUN (bgp_graceful_restart_preserve_fw,
1837 bgp_graceful_restart_preserve_fw_cmd,
1838 "bgp graceful-restart preserve-fw-state",
1839 "BGP specific commands\n"
1840 "Graceful restart capability parameters\n"
1841 "Sets F-bit indication that fib is preserved while doing Graceful Restart\n")
1842{
d62a17ae 1843 VTY_DECLVAR_CONTEXT(bgp, bgp);
1844 bgp_flag_set(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1845 return CMD_SUCCESS;
43fc21b3
JC
1846}
1847
1848DEFUN (no_bgp_graceful_restart_preserve_fw,
1849 no_bgp_graceful_restart_preserve_fw_cmd,
1850 "no bgp graceful-restart preserve-fw-state",
1851 NO_STR
1852 "BGP specific commands\n"
1853 "Graceful restart capability parameters\n"
1854 "Unsets F-bit indication that fib is preserved while doing Graceful Restart\n")
1855{
d62a17ae 1856 VTY_DECLVAR_CONTEXT(bgp, bgp);
1857 bgp_flag_unset(bgp, BGP_FLAG_GR_PRESERVE_FWD);
1858 return CMD_SUCCESS;
43fc21b3
JC
1859}
1860
7f323236
DW
1861static void bgp_redistribute_redo(struct bgp *bgp)
1862{
1863 afi_t afi;
1864 int i;
1865 struct list *red_list;
1866 struct listnode *node;
1867 struct bgp_redist *red;
1868
a4d82a8a
PZ
1869 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
1870 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
7f323236 1871
a4d82a8a
PZ
1872 red_list = bgp->redist[afi][i];
1873 if (!red_list)
1874 continue;
7f323236 1875
a4d82a8a 1876 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
7f323236
DW
1877 bgp_redistribute_resend(bgp, afi, i,
1878 red->instance);
1879 }
1880 }
1881 }
1882}
1883
1884/* "bgp graceful-shutdown" configuration */
1885DEFUN (bgp_graceful_shutdown,
1886 bgp_graceful_shutdown_cmd,
1887 "bgp graceful-shutdown",
1888 BGP_STR
1889 "Graceful shutdown parameters\n")
1890{
1891 VTY_DECLVAR_CONTEXT(bgp, bgp);
1892
1893 if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1894 bgp_flag_set(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1895 bgp_static_redo_import_check(bgp);
1896 bgp_redistribute_redo(bgp);
1897 bgp_clear_star_soft_out(vty, bgp->name);
1898 bgp_clear_star_soft_in(vty, bgp->name);
1899 }
1900
1901 return CMD_SUCCESS;
1902}
1903
1904DEFUN (no_bgp_graceful_shutdown,
1905 no_bgp_graceful_shutdown_cmd,
1906 "no bgp graceful-shutdown",
1907 NO_STR
1908 BGP_STR
1909 "Graceful shutdown parameters\n")
1910{
1911 VTY_DECLVAR_CONTEXT(bgp, bgp);
1912
1913 if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
1914 bgp_flag_unset(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN);
1915 bgp_static_redo_import_check(bgp);
1916 bgp_redistribute_redo(bgp);
1917 bgp_clear_star_soft_out(vty, bgp->name);
1918 bgp_clear_star_soft_in(vty, bgp->name);
1919 }
1920
1921 return CMD_SUCCESS;
1922}
1923
718e3744 1924/* "bgp fast-external-failover" configuration. */
1925DEFUN (bgp_fast_external_failover,
1926 bgp_fast_external_failover_cmd,
1927 "bgp fast-external-failover",
1928 BGP_STR
1929 "Immediately reset session if a link to a directly connected external peer goes down\n")
1930{
d62a17ae 1931 VTY_DECLVAR_CONTEXT(bgp, bgp);
1932 bgp_flag_unset(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1933 return CMD_SUCCESS;
718e3744 1934}
1935
1936DEFUN (no_bgp_fast_external_failover,
1937 no_bgp_fast_external_failover_cmd,
1938 "no bgp fast-external-failover",
1939 NO_STR
1940 BGP_STR
1941 "Immediately reset session if a link to a directly connected external peer goes down\n")
1942{
d62a17ae 1943 VTY_DECLVAR_CONTEXT(bgp, bgp);
1944 bgp_flag_set(bgp, BGP_FLAG_NO_FAST_EXT_FAILOVER);
1945 return CMD_SUCCESS;
718e3744 1946}
6b0655a2 1947
718e3744 1948/* "bgp enforce-first-as" configuration. */
1949DEFUN (bgp_enforce_first_as,
1950 bgp_enforce_first_as_cmd,
1951 "bgp enforce-first-as",
1952 BGP_STR
1953 "Enforce the first AS for EBGP routes\n")
1954{
d62a17ae 1955 VTY_DECLVAR_CONTEXT(bgp, bgp);
1956 bgp_flag_set(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1957 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1958
d62a17ae 1959 return CMD_SUCCESS;
718e3744 1960}
1961
1962DEFUN (no_bgp_enforce_first_as,
1963 no_bgp_enforce_first_as_cmd,
1964 "no bgp enforce-first-as",
1965 NO_STR
1966 BGP_STR
1967 "Enforce the first AS for EBGP routes\n")
1968{
d62a17ae 1969 VTY_DECLVAR_CONTEXT(bgp, bgp);
1970 bgp_flag_unset(bgp, BGP_FLAG_ENFORCE_FIRST_AS);
1971 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 1972
d62a17ae 1973 return CMD_SUCCESS;
718e3744 1974}
6b0655a2 1975
718e3744 1976/* "bgp bestpath compare-routerid" configuration. */
1977DEFUN (bgp_bestpath_compare_router_id,
1978 bgp_bestpath_compare_router_id_cmd,
1979 "bgp bestpath compare-routerid",
1980 "BGP specific commands\n"
1981 "Change the default bestpath selection\n"
1982 "Compare router-id for identical EBGP paths\n")
1983{
d62a17ae 1984 VTY_DECLVAR_CONTEXT(bgp, bgp);
1985 bgp_flag_set(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
1986 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 1987
d62a17ae 1988 return CMD_SUCCESS;
718e3744 1989}
1990
1991DEFUN (no_bgp_bestpath_compare_router_id,
1992 no_bgp_bestpath_compare_router_id_cmd,
1993 "no bgp bestpath compare-routerid",
1994 NO_STR
1995 "BGP specific commands\n"
1996 "Change the default bestpath selection\n"
1997 "Compare router-id for identical EBGP paths\n")
1998{
d62a17ae 1999 VTY_DECLVAR_CONTEXT(bgp, bgp);
2000 bgp_flag_unset(bgp, BGP_FLAG_COMPARE_ROUTER_ID);
2001 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2002
d62a17ae 2003 return CMD_SUCCESS;
718e3744 2004}
6b0655a2 2005
718e3744 2006/* "bgp bestpath as-path ignore" configuration. */
2007DEFUN (bgp_bestpath_aspath_ignore,
2008 bgp_bestpath_aspath_ignore_cmd,
2009 "bgp bestpath as-path ignore",
2010 "BGP specific commands\n"
2011 "Change the default bestpath selection\n"
2012 "AS-path attribute\n"
2013 "Ignore as-path length in selecting a route\n")
2014{
d62a17ae 2015 VTY_DECLVAR_CONTEXT(bgp, bgp);
2016 bgp_flag_set(bgp, BGP_FLAG_ASPATH_IGNORE);
2017 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2018
d62a17ae 2019 return CMD_SUCCESS;
718e3744 2020}
2021
2022DEFUN (no_bgp_bestpath_aspath_ignore,
2023 no_bgp_bestpath_aspath_ignore_cmd,
2024 "no bgp bestpath as-path ignore",
2025 NO_STR
2026 "BGP specific commands\n"
2027 "Change the default bestpath selection\n"
2028 "AS-path attribute\n"
2029 "Ignore as-path length in selecting a route\n")
2030{
d62a17ae 2031 VTY_DECLVAR_CONTEXT(bgp, bgp);
2032 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_IGNORE);
2033 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2034
d62a17ae 2035 return CMD_SUCCESS;
718e3744 2036}
6b0655a2 2037
6811845b 2038/* "bgp bestpath as-path confed" configuration. */
2039DEFUN (bgp_bestpath_aspath_confed,
2040 bgp_bestpath_aspath_confed_cmd,
2041 "bgp bestpath as-path confed",
2042 "BGP specific commands\n"
2043 "Change the default bestpath selection\n"
2044 "AS-path attribute\n"
2045 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2046{
d62a17ae 2047 VTY_DECLVAR_CONTEXT(bgp, bgp);
2048 bgp_flag_set(bgp, BGP_FLAG_ASPATH_CONFED);
2049 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2050
d62a17ae 2051 return CMD_SUCCESS;
6811845b 2052}
2053
2054DEFUN (no_bgp_bestpath_aspath_confed,
2055 no_bgp_bestpath_aspath_confed_cmd,
2056 "no bgp bestpath as-path confed",
2057 NO_STR
2058 "BGP specific commands\n"
2059 "Change the default bestpath selection\n"
2060 "AS-path attribute\n"
2061 "Compare path lengths including confederation sets & sequences in selecting a route\n")
2062{
d62a17ae 2063 VTY_DECLVAR_CONTEXT(bgp, bgp);
2064 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_CONFED);
2065 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2066
d62a17ae 2067 return CMD_SUCCESS;
6811845b 2068}
6b0655a2 2069
2fdd455c
PM
2070/* "bgp bestpath as-path multipath-relax" configuration. */
2071DEFUN (bgp_bestpath_aspath_multipath_relax,
2072 bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2073 "bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2074 "BGP specific commands\n"
2075 "Change the default bestpath selection\n"
2076 "AS-path attribute\n"
2077 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2078 "Generate an AS_SET\n"
16fc1eec
DS
2079 "Do not generate an AS_SET\n")
2080{
d62a17ae 2081 VTY_DECLVAR_CONTEXT(bgp, bgp);
2082 int idx = 0;
2083 bgp_flag_set(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
219178b6 2084
d62a17ae 2085 /* no-as-set is now the default behavior so we can silently
2086 * ignore it */
2087 if (argv_find(argv, argc, "as-set", &idx))
2088 bgp_flag_set(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2089 else
2090 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
219178b6 2091
d62a17ae 2092 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2093
d62a17ae 2094 return CMD_SUCCESS;
16fc1eec
DS
2095}
2096
219178b6
DW
2097DEFUN (no_bgp_bestpath_aspath_multipath_relax,
2098 no_bgp_bestpath_aspath_multipath_relax_cmd,
c7178fe7 2099 "no bgp bestpath as-path multipath-relax [<as-set|no-as-set>]",
16fc1eec
DS
2100 NO_STR
2101 "BGP specific commands\n"
2102 "Change the default bestpath selection\n"
2103 "AS-path attribute\n"
2104 "Allow load sharing across routes that have different AS paths (but same length)\n"
219178b6 2105 "Generate an AS_SET\n"
16fc1eec
DS
2106 "Do not generate an AS_SET\n")
2107{
d62a17ae 2108 VTY_DECLVAR_CONTEXT(bgp, bgp);
2109 bgp_flag_unset(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX);
2110 bgp_flag_unset(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET);
2111 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2112
d62a17ae 2113 return CMD_SUCCESS;
2fdd455c 2114}
6b0655a2 2115
848973c7 2116/* "bgp log-neighbor-changes" configuration. */
2117DEFUN (bgp_log_neighbor_changes,
2118 bgp_log_neighbor_changes_cmd,
2119 "bgp log-neighbor-changes",
2120 "BGP specific commands\n"
2121 "Log neighbor up/down and reset reason\n")
2122{
d62a17ae 2123 VTY_DECLVAR_CONTEXT(bgp, bgp);
2124 bgp_flag_set(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2125 return CMD_SUCCESS;
848973c7 2126}
2127
2128DEFUN (no_bgp_log_neighbor_changes,
2129 no_bgp_log_neighbor_changes_cmd,
2130 "no bgp log-neighbor-changes",
2131 NO_STR
2132 "BGP specific commands\n"
2133 "Log neighbor up/down and reset reason\n")
2134{
d62a17ae 2135 VTY_DECLVAR_CONTEXT(bgp, bgp);
2136 bgp_flag_unset(bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
2137 return CMD_SUCCESS;
848973c7 2138}
6b0655a2 2139
718e3744 2140/* "bgp bestpath med" configuration. */
2141DEFUN (bgp_bestpath_med,
2142 bgp_bestpath_med_cmd,
2d8c1a4d 2143 "bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2144 "BGP specific commands\n"
2145 "Change the default bestpath selection\n"
2146 "MED attribute\n"
2147 "Compare MED among confederation paths\n"
838758ac
DW
2148 "Treat missing MED as the least preferred one\n"
2149 "Treat missing MED as the least preferred one\n"
2150 "Compare MED among confederation paths\n")
718e3744 2151{
d62a17ae 2152 VTY_DECLVAR_CONTEXT(bgp, bgp);
6cbd1915 2153
d62a17ae 2154 int idx = 0;
2155 if (argv_find(argv, argc, "confed", &idx))
2156 bgp_flag_set(bgp, BGP_FLAG_MED_CONFED);
2157 idx = 0;
2158 if (argv_find(argv, argc, "missing-as-worst", &idx))
2159 bgp_flag_set(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
e52702f2 2160
d62a17ae 2161 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2162
d62a17ae 2163 return CMD_SUCCESS;
718e3744 2164}
2165
718e3744 2166DEFUN (no_bgp_bestpath_med,
2167 no_bgp_bestpath_med_cmd,
2d8c1a4d 2168 "no bgp bestpath med <confed [missing-as-worst]|missing-as-worst [confed]>",
718e3744 2169 NO_STR
2170 "BGP specific commands\n"
2171 "Change the default bestpath selection\n"
2172 "MED attribute\n"
2173 "Compare MED among confederation paths\n"
3a2d747c
QY
2174 "Treat missing MED as the least preferred one\n"
2175 "Treat missing MED as the least preferred one\n"
2176 "Compare MED among confederation paths\n")
718e3744 2177{
d62a17ae 2178 VTY_DECLVAR_CONTEXT(bgp, bgp);
e52702f2 2179
d62a17ae 2180 int idx = 0;
2181 if (argv_find(argv, argc, "confed", &idx))
2182 bgp_flag_unset(bgp, BGP_FLAG_MED_CONFED);
2183 idx = 0;
2184 if (argv_find(argv, argc, "missing-as-worst", &idx))
2185 bgp_flag_unset(bgp, BGP_FLAG_MED_MISSING_AS_WORST);
718e3744 2186
d62a17ae 2187 bgp_recalculate_all_bestpaths(bgp);
7aafcaca 2188
d62a17ae 2189 return CMD_SUCCESS;
718e3744 2190}
2191
718e3744 2192/* "no bgp default ipv4-unicast". */
2193DEFUN (no_bgp_default_ipv4_unicast,
2194 no_bgp_default_ipv4_unicast_cmd,
2195 "no bgp default ipv4-unicast",
2196 NO_STR
2197 "BGP specific commands\n"
2198 "Configure BGP defaults\n"
2199 "Activate ipv4-unicast for a peer by default\n")
2200{
d62a17ae 2201 VTY_DECLVAR_CONTEXT(bgp, bgp);
2202 bgp_flag_set(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2203 return CMD_SUCCESS;
718e3744 2204}
2205
2206DEFUN (bgp_default_ipv4_unicast,
2207 bgp_default_ipv4_unicast_cmd,
2208 "bgp default ipv4-unicast",
2209 "BGP specific commands\n"
2210 "Configure BGP defaults\n"
2211 "Activate ipv4-unicast for a peer by default\n")
2212{
d62a17ae 2213 VTY_DECLVAR_CONTEXT(bgp, bgp);
2214 bgp_flag_unset(bgp, BGP_FLAG_NO_DEFAULT_IPV4);
2215 return CMD_SUCCESS;
718e3744 2216}
6b0655a2 2217
04b6bdc0
DW
2218/* Display hostname in certain command outputs */
2219DEFUN (bgp_default_show_hostname,
2220 bgp_default_show_hostname_cmd,
2221 "bgp default show-hostname",
2222 "BGP specific commands\n"
2223 "Configure BGP defaults\n"
2224 "Show hostname in certain command ouputs\n")
2225{
d62a17ae 2226 VTY_DECLVAR_CONTEXT(bgp, bgp);
2227 bgp_flag_set(bgp, BGP_FLAG_SHOW_HOSTNAME);
2228 return CMD_SUCCESS;
04b6bdc0
DW
2229}
2230
2231DEFUN (no_bgp_default_show_hostname,
2232 no_bgp_default_show_hostname_cmd,
2233 "no bgp default show-hostname",
2234 NO_STR
2235 "BGP specific commands\n"
2236 "Configure BGP defaults\n"
2237 "Show hostname in certain command ouputs\n")
2238{
d62a17ae 2239 VTY_DECLVAR_CONTEXT(bgp, bgp);
2240 bgp_flag_unset(bgp, BGP_FLAG_SHOW_HOSTNAME);
2241 return CMD_SUCCESS;
04b6bdc0
DW
2242}
2243
8233ef81 2244/* "bgp network import-check" configuration. */
718e3744 2245DEFUN (bgp_network_import_check,
2246 bgp_network_import_check_cmd,
5623e905 2247 "bgp network import-check",
718e3744 2248 "BGP specific commands\n"
2249 "BGP network command\n"
5623e905 2250 "Check BGP network route exists in IGP\n")
718e3744 2251{
d62a17ae 2252 VTY_DECLVAR_CONTEXT(bgp, bgp);
2253 if (!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2254 bgp_flag_set(bgp, BGP_FLAG_IMPORT_CHECK);
2255 bgp_static_redo_import_check(bgp);
2256 }
078430f6 2257
d62a17ae 2258 return CMD_SUCCESS;
718e3744 2259}
2260
d62a17ae 2261ALIAS_HIDDEN(bgp_network_import_check, bgp_network_import_check_exact_cmd,
2262 "bgp network import-check exact",
2263 "BGP specific commands\n"
2264 "BGP network command\n"
2265 "Check BGP network route exists in IGP\n"
2266 "Match route precisely\n")
8233ef81 2267
718e3744 2268DEFUN (no_bgp_network_import_check,
2269 no_bgp_network_import_check_cmd,
5623e905 2270 "no bgp network import-check",
718e3744 2271 NO_STR
2272 "BGP specific commands\n"
2273 "BGP network command\n"
2274 "Check BGP network route exists in IGP\n")
2275{
d62a17ae 2276 VTY_DECLVAR_CONTEXT(bgp, bgp);
2277 if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) {
2278 bgp_flag_unset(bgp, BGP_FLAG_IMPORT_CHECK);
2279 bgp_static_redo_import_check(bgp);
2280 }
5623e905 2281
d62a17ae 2282 return CMD_SUCCESS;
718e3744 2283}
6b0655a2 2284
718e3744 2285DEFUN (bgp_default_local_preference,
2286 bgp_default_local_preference_cmd,
6147e2c6 2287 "bgp default local-preference (0-4294967295)",
718e3744 2288 "BGP specific commands\n"
2289 "Configure BGP defaults\n"
2290 "local preference (higher=more preferred)\n"
2291 "Configure default local preference value\n")
2292{
d62a17ae 2293 VTY_DECLVAR_CONTEXT(bgp, bgp);
2294 int idx_number = 3;
2295 u_int32_t local_pref;
718e3744 2296
d62a17ae 2297 local_pref = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2298
d62a17ae 2299 bgp_default_local_preference_set(bgp, local_pref);
2300 bgp_clear_star_soft_in(vty, bgp->name);
718e3744 2301
d62a17ae 2302 return CMD_SUCCESS;
718e3744 2303}
2304
2305DEFUN (no_bgp_default_local_preference,
2306 no_bgp_default_local_preference_cmd,
838758ac 2307 "no bgp default local-preference [(0-4294967295)]",
718e3744 2308 NO_STR
2309 "BGP specific commands\n"
2310 "Configure BGP defaults\n"
838758ac
DW
2311 "local preference (higher=more preferred)\n"
2312 "Configure default local preference value\n")
718e3744 2313{
d62a17ae 2314 VTY_DECLVAR_CONTEXT(bgp, bgp);
2315 bgp_default_local_preference_unset(bgp);
2316 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2317
d62a17ae 2318 return CMD_SUCCESS;
718e3744 2319}
2320
6b0655a2 2321
3f9c7369
DS
2322DEFUN (bgp_default_subgroup_pkt_queue_max,
2323 bgp_default_subgroup_pkt_queue_max_cmd,
6147e2c6 2324 "bgp default subgroup-pkt-queue-max (20-100)",
3f9c7369
DS
2325 "BGP specific commands\n"
2326 "Configure BGP defaults\n"
2327 "subgroup-pkt-queue-max\n"
2328 "Configure subgroup packet queue max\n")
8bd9d948 2329{
d62a17ae 2330 VTY_DECLVAR_CONTEXT(bgp, bgp);
2331 int idx_number = 3;
2332 u_int32_t max_size;
8bd9d948 2333
d62a17ae 2334 max_size = strtoul(argv[idx_number]->arg, NULL, 10);
3f9c7369 2335
d62a17ae 2336 bgp_default_subgroup_pkt_queue_max_set(bgp, max_size);
3f9c7369 2337
d62a17ae 2338 return CMD_SUCCESS;
3f9c7369
DS
2339}
2340
2341DEFUN (no_bgp_default_subgroup_pkt_queue_max,
2342 no_bgp_default_subgroup_pkt_queue_max_cmd,
838758ac 2343 "no bgp default subgroup-pkt-queue-max [(20-100)]",
3f9c7369
DS
2344 NO_STR
2345 "BGP specific commands\n"
2346 "Configure BGP defaults\n"
838758ac
DW
2347 "subgroup-pkt-queue-max\n"
2348 "Configure subgroup packet queue max\n")
3f9c7369 2349{
d62a17ae 2350 VTY_DECLVAR_CONTEXT(bgp, bgp);
2351 bgp_default_subgroup_pkt_queue_max_unset(bgp);
2352 return CMD_SUCCESS;
8bd9d948
DS
2353}
2354
813d4307 2355
8bd9d948
DS
2356DEFUN (bgp_rr_allow_outbound_policy,
2357 bgp_rr_allow_outbound_policy_cmd,
2358 "bgp route-reflector allow-outbound-policy",
2359 "BGP specific commands\n"
2360 "Allow modifications made by out route-map\n"
2361 "on ibgp neighbors\n")
2362{
d62a17ae 2363 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2364
d62a17ae 2365 if (!bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2366 bgp_flag_set(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2367 update_group_announce_rrclients(bgp);
2368 bgp_clear_star_soft_out(vty, bgp->name);
2369 }
8bd9d948 2370
d62a17ae 2371 return CMD_SUCCESS;
8bd9d948
DS
2372}
2373
2374DEFUN (no_bgp_rr_allow_outbound_policy,
2375 no_bgp_rr_allow_outbound_policy_cmd,
2376 "no bgp route-reflector allow-outbound-policy",
2377 NO_STR
2378 "BGP specific commands\n"
2379 "Allow modifications made by out route-map\n"
2380 "on ibgp neighbors\n")
2381{
d62a17ae 2382 VTY_DECLVAR_CONTEXT(bgp, bgp);
8bd9d948 2383
d62a17ae 2384 if (bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
2385 bgp_flag_unset(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY);
2386 update_group_announce_rrclients(bgp);
2387 bgp_clear_star_soft_out(vty, bgp->name);
2388 }
8bd9d948 2389
d62a17ae 2390 return CMD_SUCCESS;
8bd9d948
DS
2391}
2392
f14e6fdb
DS
2393DEFUN (bgp_listen_limit,
2394 bgp_listen_limit_cmd,
9ccf14f7 2395 "bgp listen limit (1-5000)",
f14e6fdb
DS
2396 "BGP specific commands\n"
2397 "Configure BGP defaults\n"
2398 "maximum number of BGP Dynamic Neighbors that can be created\n"
2399 "Configure Dynamic Neighbors listen limit value\n")
2400{
d62a17ae 2401 VTY_DECLVAR_CONTEXT(bgp, bgp);
2402 int idx_number = 3;
2403 int listen_limit;
f14e6fdb 2404
d62a17ae 2405 listen_limit = strtoul(argv[idx_number]->arg, NULL, 10);
f14e6fdb 2406
d62a17ae 2407 bgp_listen_limit_set(bgp, listen_limit);
f14e6fdb 2408
d62a17ae 2409 return CMD_SUCCESS;
f14e6fdb
DS
2410}
2411
2412DEFUN (no_bgp_listen_limit,
2413 no_bgp_listen_limit_cmd,
838758ac 2414 "no bgp listen limit [(1-5000)]",
f14e6fdb
DS
2415 "BGP specific commands\n"
2416 "Configure BGP defaults\n"
2417 "unset maximum number of BGP Dynamic Neighbors that can be created\n"
838758ac
DW
2418 "Configure Dynamic Neighbors listen limit value to default\n"
2419 "Configure Dynamic Neighbors listen limit value\n")
f14e6fdb 2420{
d62a17ae 2421 VTY_DECLVAR_CONTEXT(bgp, bgp);
2422 bgp_listen_limit_unset(bgp);
2423 return CMD_SUCCESS;
f14e6fdb
DS
2424}
2425
2426
20eb8864 2427/*
2428 * Check if this listen range is already configured. Check for exact
2429 * match or overlap based on input.
2430 */
d62a17ae 2431static struct peer_group *listen_range_exists(struct bgp *bgp,
2432 struct prefix *range, int exact)
2433{
2434 struct listnode *node, *nnode;
2435 struct listnode *node1, *nnode1;
2436 struct peer_group *group;
2437 struct prefix *lr;
2438 afi_t afi;
2439 int match;
2440
2441 afi = family2afi(range->family);
2442 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2443 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node1, nnode1,
2444 lr)) {
2445 if (exact)
2446 match = prefix_same(range, lr);
2447 else
2448 match = (prefix_match(range, lr)
2449 || prefix_match(lr, range));
2450 if (match)
2451 return group;
2452 }
2453 }
2454
2455 return NULL;
20eb8864 2456}
2457
f14e6fdb
DS
2458DEFUN (bgp_listen_range,
2459 bgp_listen_range_cmd,
9ccf14f7 2460 "bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
f14e6fdb 2461 "BGP specific commands\n"
d7fa34c1
QY
2462 "Configure BGP dynamic neighbors listen range\n"
2463 "Configure BGP dynamic neighbors listen range\n"
16cedbb0
QY
2464 NEIGHBOR_ADDR_STR
2465 "Member of the peer-group\n"
2466 "Peer-group name\n")
f14e6fdb 2467{
d62a17ae 2468 VTY_DECLVAR_CONTEXT(bgp, bgp);
2469 struct prefix range;
2470 struct peer_group *group, *existing_group;
2471 afi_t afi;
2472 int ret;
2473 int idx = 0;
2474
2475 argv_find(argv, argc, "A.B.C.D/M", &idx);
2476 argv_find(argv, argc, "X:X::X:X/M", &idx);
2477 char *prefix = argv[idx]->arg;
2478 argv_find(argv, argc, "WORD", &idx);
2479 char *peergroup = argv[idx]->arg;
2480
2481 /* Convert IP prefix string to struct prefix. */
2482 ret = str2prefix(prefix, &range);
2483 if (!ret) {
2484 vty_out(vty, "%% Malformed listen range\n");
2485 return CMD_WARNING_CONFIG_FAILED;
2486 }
2487
2488 afi = family2afi(range.family);
2489
2490 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2491 vty_out(vty,
2492 "%% Malformed listen range (link-local address)\n");
2493 return CMD_WARNING_CONFIG_FAILED;
2494 }
2495
2496 apply_mask(&range);
2497
2498 /* Check if same listen range is already configured. */
2499 existing_group = listen_range_exists(bgp, &range, 1);
2500 if (existing_group) {
2501 if (strcmp(existing_group->name, peergroup) == 0)
2502 return CMD_SUCCESS;
2503 else {
2504 vty_out(vty,
2505 "%% Same listen range is attached to peer-group %s\n",
2506 existing_group->name);
2507 return CMD_WARNING_CONFIG_FAILED;
2508 }
2509 }
2510
2511 /* Check if an overlapping listen range exists. */
2512 if (listen_range_exists(bgp, &range, 0)) {
2513 vty_out(vty,
2514 "%% Listen range overlaps with existing listen range\n");
2515 return CMD_WARNING_CONFIG_FAILED;
2516 }
2517
2518 group = peer_group_lookup(bgp, peergroup);
2519 if (!group) {
2520 vty_out(vty, "%% Configure the peer-group first\n");
2521 return CMD_WARNING_CONFIG_FAILED;
2522 }
2523
2524 ret = peer_group_listen_range_add(group, &range);
2525 return bgp_vty_return(vty, ret);
f14e6fdb
DS
2526}
2527
2528DEFUN (no_bgp_listen_range,
2529 no_bgp_listen_range_cmd,
d7fa34c1
QY
2530 "no bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group WORD",
2531 NO_STR
f14e6fdb 2532 "BGP specific commands\n"
d7fa34c1
QY
2533 "Unconfigure BGP dynamic neighbors listen range\n"
2534 "Unconfigure BGP dynamic neighbors listen range\n"
2535 NEIGHBOR_ADDR_STR
2536 "Member of the peer-group\n"
2537 "Peer-group name\n")
f14e6fdb 2538{
d62a17ae 2539 VTY_DECLVAR_CONTEXT(bgp, bgp);
2540 struct prefix range;
2541 struct peer_group *group;
2542 afi_t afi;
2543 int ret;
2544 int idx = 0;
2545
2546 argv_find(argv, argc, "A.B.C.D/M", &idx);
2547 argv_find(argv, argc, "X:X::X:X/M", &idx);
2548 char *prefix = argv[idx]->arg;
2549 argv_find(argv, argc, "WORD", &idx);
2550 char *peergroup = argv[idx]->arg;
2551
2552 /* Convert IP prefix string to struct prefix. */
2553 ret = str2prefix(prefix, &range);
2554 if (!ret) {
2555 vty_out(vty, "%% Malformed listen range\n");
2556 return CMD_WARNING_CONFIG_FAILED;
2557 }
2558
2559 afi = family2afi(range.family);
2560
2561 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&range.u.prefix6)) {
2562 vty_out(vty,
2563 "%% Malformed listen range (link-local address)\n");
2564 return CMD_WARNING_CONFIG_FAILED;
2565 }
2566
2567 apply_mask(&range);
2568
2569 group = peer_group_lookup(bgp, peergroup);
2570 if (!group) {
2571 vty_out(vty, "%% Peer-group does not exist\n");
2572 return CMD_WARNING_CONFIG_FAILED;
2573 }
2574
2575 ret = peer_group_listen_range_del(group, &range);
2576 return bgp_vty_return(vty, ret);
2577}
2578
2b791107 2579void bgp_config_write_listen(struct vty *vty, struct bgp *bgp)
d62a17ae 2580{
2581 struct peer_group *group;
2582 struct listnode *node, *nnode, *rnode, *nrnode;
2583 struct prefix *range;
2584 afi_t afi;
2585 char buf[PREFIX2STR_BUFFER];
2586
2587 if (bgp->dynamic_neighbors_limit != BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT)
2588 vty_out(vty, " bgp listen limit %d\n",
2589 bgp->dynamic_neighbors_limit);
2590
2591 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
2592 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
2593 for (ALL_LIST_ELEMENTS(group->listen_range[afi], rnode,
2594 nrnode, range)) {
2595 prefix2str(range, buf, sizeof(buf));
2596 vty_out(vty,
2597 " bgp listen range %s peer-group %s\n",
2598 buf, group->name);
2599 }
2600 }
2601 }
f14e6fdb
DS
2602}
2603
2604
907f92c8
DS
2605DEFUN (bgp_disable_connected_route_check,
2606 bgp_disable_connected_route_check_cmd,
2607 "bgp disable-ebgp-connected-route-check",
2608 "BGP specific commands\n"
2609 "Disable checking if nexthop is connected on ebgp sessions\n")
2610{
d62a17ae 2611 VTY_DECLVAR_CONTEXT(bgp, bgp);
2612 bgp_flag_set(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2613 bgp_clear_star_soft_in(vty, bgp->name);
7aafcaca 2614
d62a17ae 2615 return CMD_SUCCESS;
907f92c8
DS
2616}
2617
2618DEFUN (no_bgp_disable_connected_route_check,
2619 no_bgp_disable_connected_route_check_cmd,
2620 "no bgp disable-ebgp-connected-route-check",
2621 NO_STR
2622 "BGP specific commands\n"
2623 "Disable checking if nexthop is connected on ebgp sessions\n")
2624{
d62a17ae 2625 VTY_DECLVAR_CONTEXT(bgp, bgp);
2626 bgp_flag_unset(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK);
2627 bgp_clear_star_soft_in(vty, bgp->name);
2628
2629 return CMD_SUCCESS;
2630}
2631
2632
2633static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
2634 const char *as_str, afi_t afi, safi_t safi)
2635{
2636 VTY_DECLVAR_CONTEXT(bgp, bgp);
2637 int ret;
2638 as_t as;
2639 int as_type = AS_SPECIFIED;
2640 union sockunion su;
2641
2642 if (as_str[0] == 'i') {
2643 as = 0;
2644 as_type = AS_INTERNAL;
2645 } else if (as_str[0] == 'e') {
2646 as = 0;
2647 as_type = AS_EXTERNAL;
2648 } else {
2649 /* Get AS number. */
2650 as = strtoul(as_str, NULL, 10);
2651 }
2652
2653 /* If peer is peer group, call proper function. */
2654 ret = str2sockunion(peer_str, &su);
2655 if (ret < 0) {
2656 /* Check for peer by interface */
2657 ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, afi,
2658 safi);
2659 if (ret < 0) {
2660 ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
2661 if (ret < 0) {
2662 vty_out(vty,
2663 "%% Create the peer-group or interface first\n");
2664 return CMD_WARNING_CONFIG_FAILED;
2665 }
2666 return CMD_SUCCESS;
2667 }
2668 } else {
2669 if (peer_address_self_check(bgp, &su)) {
2670 vty_out(vty,
2671 "%% Can not configure the local system as neighbor\n");
2672 return CMD_WARNING_CONFIG_FAILED;
2673 }
2674 ret = peer_remote_as(bgp, &su, NULL, &as, as_type, afi, safi);
2675 }
2676
2677 /* This peer belongs to peer group. */
2678 switch (ret) {
2679 case BGP_ERR_PEER_GROUP_MEMBER:
2680 vty_out(vty,
2681 "%% Peer-group AS %u. Cannot configure remote-as for member\n",
2682 as);
2683 return CMD_WARNING_CONFIG_FAILED;
2684 case BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT:
2685 vty_out(vty,
2686 "%% The AS# can not be changed from %u to %s, peer-group members must be all internal or all external\n",
2687 as, as_str);
2688 return CMD_WARNING_CONFIG_FAILED;
2689 }
2690 return bgp_vty_return(vty, ret);
718e3744 2691}
2692
f26845f9
QY
2693DEFUN (bgp_default_shutdown,
2694 bgp_default_shutdown_cmd,
2695 "[no] bgp default shutdown",
2696 NO_STR
2697 BGP_STR
2698 "Configure BGP defaults\n"
b012cbe2 2699 "Apply administrative shutdown to newly configured peers\n")
f26845f9
QY
2700{
2701 VTY_DECLVAR_CONTEXT(bgp, bgp);
2702 bgp->autoshutdown = !strmatch(argv[0]->text, "no");
2703 return CMD_SUCCESS;
2704}
2705
718e3744 2706DEFUN (neighbor_remote_as,
2707 neighbor_remote_as_cmd,
3a2d747c 2708 "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
718e3744 2709 NEIGHBOR_STR
2710 NEIGHBOR_ADDR_STR2
2711 "Specify a BGP neighbor\n"
d7fa34c1 2712 AS_STR
3a2d747c
QY
2713 "Internal BGP peer\n"
2714 "External BGP peer\n")
718e3744 2715{
d62a17ae 2716 int idx_peer = 1;
2717 int idx_remote_as = 3;
2718 return peer_remote_as_vty(vty, argv[idx_peer]->arg,
2719 argv[idx_remote_as]->arg, AFI_IP,
2720 SAFI_UNICAST);
2721}
2722
2723static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
2724 afi_t afi, safi_t safi, int v6only,
2725 const char *peer_group_name,
2726 const char *as_str)
2727{
2728 VTY_DECLVAR_CONTEXT(bgp, bgp);
2729 as_t as = 0;
2730 int as_type = AS_UNSPECIFIED;
2731 struct peer *peer;
2732 struct peer_group *group;
2733 int ret = 0;
2734 union sockunion su;
2735
2736 group = peer_group_lookup(bgp, conf_if);
2737
2738 if (group) {
2739 vty_out(vty, "%% Name conflict with peer-group \n");
2740 return CMD_WARNING_CONFIG_FAILED;
2741 }
2742
2743 if (as_str) {
2744 if (as_str[0] == 'i') {
2745 as_type = AS_INTERNAL;
2746 } else if (as_str[0] == 'e') {
2747 as_type = AS_EXTERNAL;
2748 } else {
2749 /* Get AS number. */
2750 as = strtoul(as_str, NULL, 10);
2751 as_type = AS_SPECIFIED;
2752 }
2753 }
2754
2755 peer = peer_lookup_by_conf_if(bgp, conf_if);
2756 if (peer) {
2757 if (as_str)
2758 ret = peer_remote_as(bgp, &su, conf_if, &as, as_type,
2759 afi, safi);
2760 } else {
2761 if (bgp_flag_check(bgp, BGP_FLAG_NO_DEFAULT_IPV4)
2762 && afi == AFI_IP && safi == SAFI_UNICAST)
2763 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2764 as_type, 0, 0, NULL);
2765 else
2766 peer = peer_create(NULL, conf_if, bgp, bgp->as, as,
2767 as_type, afi, safi, NULL);
2768
2769 if (!peer) {
2770 vty_out(vty, "%% BGP failed to create peer\n");
2771 return CMD_WARNING_CONFIG_FAILED;
2772 }
2773
2774 if (v6only)
2775 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2776
2777 /* Request zebra to initiate IPv6 RAs on this interface. We do
2778 * this
2779 * any unnumbered peer in order to not worry about run-time
2780 * transitions
2781 * (e.g., peering is initially IPv4, but the IPv4 /30 or /31
2782 * address
2783 * gets deleted later etc.)
2784 */
2785 if (peer->ifp)
2786 bgp_zebra_initiate_radv(bgp, peer);
2787 }
2788
2789 if ((v6only && !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
2790 || (!v6only && CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))) {
2791 if (v6only)
2792 SET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2793 else
2794 UNSET_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY);
2795
2796 /* v6only flag changed. Reset bgp seesion */
2797 if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
2798 peer->last_reset = PEER_DOWN_V6ONLY_CHANGE;
2799 bgp_notify_send(peer, BGP_NOTIFY_CEASE,
2800 BGP_NOTIFY_CEASE_CONFIG_CHANGE);
2801 } else
2802 bgp_session_reset(peer);
2803 }
2804
2805 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE))
2806 peer_flag_set(peer, PEER_FLAG_CAPABILITY_ENHE);
2807
2808 if (peer_group_name) {
2809 group = peer_group_lookup(bgp, peer_group_name);
2810 if (!group) {
2811 vty_out(vty, "%% Configure the peer-group first\n");
2812 return CMD_WARNING_CONFIG_FAILED;
2813 }
2814
2815 ret = peer_group_bind(bgp, &su, peer, group, &as);
2816 }
2817
2818 return bgp_vty_return(vty, ret);
a80beece
DS
2819}
2820
4c48cf63
DW
2821DEFUN (neighbor_interface_config,
2822 neighbor_interface_config_cmd,
31500417 2823 "neighbor WORD interface [peer-group WORD]",
4c48cf63
DW
2824 NEIGHBOR_STR
2825 "Interface name or neighbor tag\n"
31500417
DW
2826 "Enable BGP on interface\n"
2827 "Member of the peer-group\n"
16cedbb0 2828 "Peer-group name\n")
4c48cf63 2829{
d62a17ae 2830 int idx_word = 1;
2831 int idx_peer_group_word = 4;
31500417 2832
d62a17ae 2833 if (argc > idx_peer_group_word)
2834 return peer_conf_interface_get(
2835 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 0,
2836 argv[idx_peer_group_word]->arg, NULL);
2837 else
2838 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2839 SAFI_UNICAST, 0, NULL, NULL);
4c48cf63
DW
2840}
2841
4c48cf63
DW
2842DEFUN (neighbor_interface_config_v6only,
2843 neighbor_interface_config_v6only_cmd,
31500417 2844 "neighbor WORD interface v6only [peer-group WORD]",
4c48cf63
DW
2845 NEIGHBOR_STR
2846 "Interface name or neighbor tag\n"
2847 "Enable BGP on interface\n"
31500417
DW
2848 "Enable BGP with v6 link-local only\n"
2849 "Member of the peer-group\n"
16cedbb0 2850 "Peer-group name\n")
4c48cf63 2851{
d62a17ae 2852 int idx_word = 1;
2853 int idx_peer_group_word = 5;
31500417 2854
d62a17ae 2855 if (argc > idx_peer_group_word)
2856 return peer_conf_interface_get(
2857 vty, argv[idx_word]->arg, AFI_IP, SAFI_UNICAST, 1,
2858 argv[idx_peer_group_word]->arg, NULL);
31500417 2859
d62a17ae 2860 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2861 SAFI_UNICAST, 1, NULL, NULL);
4c48cf63
DW
2862}
2863
a80beece 2864
b3a39dc5
DD
2865DEFUN (neighbor_interface_config_remote_as,
2866 neighbor_interface_config_remote_as_cmd,
3a2d747c 2867 "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2868 NEIGHBOR_STR
2869 "Interface name or neighbor tag\n"
2870 "Enable BGP on interface\n"
3a2d747c 2871 "Specify a BGP neighbor\n"
d7fa34c1 2872 AS_STR
3a2d747c
QY
2873 "Internal BGP peer\n"
2874 "External BGP peer\n")
b3a39dc5 2875{
d62a17ae 2876 int idx_word = 1;
2877 int idx_remote_as = 4;
2878 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2879 SAFI_UNICAST, 0, NULL,
2880 argv[idx_remote_as]->arg);
b3a39dc5
DD
2881}
2882
2883DEFUN (neighbor_interface_v6only_config_remote_as,
2884 neighbor_interface_v6only_config_remote_as_cmd,
3a2d747c 2885 "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
b3a39dc5
DD
2886 NEIGHBOR_STR
2887 "Interface name or neighbor tag\n"
3a2d747c 2888 "Enable BGP with v6 link-local only\n"
b3a39dc5 2889 "Enable BGP on interface\n"
3a2d747c 2890 "Specify a BGP neighbor\n"
d7fa34c1 2891 AS_STR
3a2d747c
QY
2892 "Internal BGP peer\n"
2893 "External BGP peer\n")
b3a39dc5 2894{
d62a17ae 2895 int idx_word = 1;
2896 int idx_remote_as = 5;
2897 return peer_conf_interface_get(vty, argv[idx_word]->arg, AFI_IP,
2898 SAFI_UNICAST, 1, NULL,
2899 argv[idx_remote_as]->arg);
b3a39dc5
DD
2900}
2901
718e3744 2902DEFUN (neighbor_peer_group,
2903 neighbor_peer_group_cmd,
2904 "neighbor WORD peer-group",
2905 NEIGHBOR_STR
a80beece 2906 "Interface name or neighbor tag\n"
718e3744 2907 "Configure peer-group\n")
2908{
d62a17ae 2909 VTY_DECLVAR_CONTEXT(bgp, bgp);
2910 int idx_word = 1;
2911 struct peer *peer;
2912 struct peer_group *group;
718e3744 2913
d62a17ae 2914 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
2915 if (peer) {
2916 vty_out(vty, "%% Name conflict with interface: \n");
2917 return CMD_WARNING_CONFIG_FAILED;
2918 }
718e3744 2919
d62a17ae 2920 group = peer_group_get(bgp, argv[idx_word]->arg);
2921 if (!group) {
2922 vty_out(vty, "%% BGP failed to find or create peer-group\n");
2923 return CMD_WARNING_CONFIG_FAILED;
2924 }
718e3744 2925
d62a17ae 2926 return CMD_SUCCESS;
718e3744 2927}
2928
2929DEFUN (no_neighbor,
2930 no_neighbor_cmd,
dab8cd00 2931 "no neighbor <WORD|<A.B.C.D|X:X::X:X> [remote-as <(1-4294967295)|internal|external>]>",
718e3744 2932 NO_STR
2933 NEIGHBOR_STR
3a2d747c
QY
2934 NEIGHBOR_ADDR_STR2
2935 "Specify a BGP neighbor\n"
2936 AS_STR
2937 "Internal BGP peer\n"
2938 "External BGP peer\n")
718e3744 2939{
d62a17ae 2940 VTY_DECLVAR_CONTEXT(bgp, bgp);
2941 int idx_peer = 2;
2942 int ret;
2943 union sockunion su;
2944 struct peer_group *group;
2945 struct peer *peer;
2946 struct peer *other;
2947
2948 ret = str2sockunion(argv[idx_peer]->arg, &su);
2949 if (ret < 0) {
2950 /* look up for neighbor by interface name config. */
2951 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
2952 if (peer) {
2953 /* Request zebra to terminate IPv6 RAs on this
2954 * interface. */
2955 if (peer->ifp)
2956 bgp_zebra_terminate_radv(peer->bgp, peer);
2957 peer_delete(peer);
2958 return CMD_SUCCESS;
2959 }
f14e6fdb 2960
d62a17ae 2961 group = peer_group_lookup(bgp, argv[idx_peer]->arg);
2962 if (group)
2963 peer_group_delete(group);
2964 else {
2965 vty_out(vty, "%% Create the peer-group first\n");
2966 return CMD_WARNING_CONFIG_FAILED;
2967 }
2968 } else {
2969 peer = peer_lookup(bgp, &su);
2970 if (peer) {
2971 if (peer_dynamic_neighbor(peer)) {
2972 vty_out(vty,
2973 "%% Operation not allowed on a dynamic neighbor\n");
2974 return CMD_WARNING_CONFIG_FAILED;
2975 }
2976
2977 other = peer->doppelganger;
2978 peer_delete(peer);
2979 if (other && other->status != Deleted)
2980 peer_delete(other);
2981 }
1ff9a340 2982 }
718e3744 2983
d62a17ae 2984 return CMD_SUCCESS;
718e3744 2985}
2986
a80beece
DS
2987DEFUN (no_neighbor_interface_config,
2988 no_neighbor_interface_config_cmd,
31500417 2989 "no neighbor WORD interface [v6only] [peer-group WORD] [remote-as <(1-4294967295)|internal|external>]",
a80beece
DS
2990 NO_STR
2991 NEIGHBOR_STR
2992 "Interface name\n"
31500417
DW
2993 "Configure BGP on interface\n"
2994 "Enable BGP with v6 link-local only\n"
2995 "Member of the peer-group\n"
16cedbb0 2996 "Peer-group name\n"
3a2d747c
QY
2997 "Specify a BGP neighbor\n"
2998 AS_STR
2999 "Internal BGP peer\n"
3000 "External BGP peer\n")
a80beece 3001{
d62a17ae 3002 VTY_DECLVAR_CONTEXT(bgp, bgp);
3003 int idx_word = 2;
3004 struct peer *peer;
3005
3006 /* look up for neighbor by interface name config. */
3007 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3008 if (peer) {
3009 /* Request zebra to terminate IPv6 RAs on this interface. */
3010 if (peer->ifp)
3011 bgp_zebra_terminate_radv(peer->bgp, peer);
3012 peer_delete(peer);
3013 } else {
3014 vty_out(vty, "%% Create the bgp interface first\n");
3015 return CMD_WARNING_CONFIG_FAILED;
3016 }
3017 return CMD_SUCCESS;
a80beece
DS
3018}
3019
718e3744 3020DEFUN (no_neighbor_peer_group,
3021 no_neighbor_peer_group_cmd,
3022 "no neighbor WORD peer-group",
3023 NO_STR
3024 NEIGHBOR_STR
3025 "Neighbor tag\n"
3026 "Configure peer-group\n")
3027{
d62a17ae 3028 VTY_DECLVAR_CONTEXT(bgp, bgp);
3029 int idx_word = 2;
3030 struct peer_group *group;
718e3744 3031
d62a17ae 3032 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3033 if (group)
3034 peer_group_delete(group);
3035 else {
3036 vty_out(vty, "%% Create the peer-group first\n");
3037 return CMD_WARNING_CONFIG_FAILED;
3038 }
3039 return CMD_SUCCESS;
718e3744 3040}
3041
a80beece
DS
3042DEFUN (no_neighbor_interface_peer_group_remote_as,
3043 no_neighbor_interface_peer_group_remote_as_cmd,
9ccf14f7 3044 "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
718e3744 3045 NO_STR
3046 NEIGHBOR_STR
a80beece 3047 "Interface name or neighbor tag\n"
718e3744 3048 "Specify a BGP neighbor\n"
3a2d747c
QY
3049 AS_STR
3050 "Internal BGP peer\n"
3051 "External BGP peer\n")
718e3744 3052{
d62a17ae 3053 VTY_DECLVAR_CONTEXT(bgp, bgp);
3054 int idx_word = 2;
3055 struct peer_group *group;
3056 struct peer *peer;
3057
3058 /* look up for neighbor by interface name config. */
3059 peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
3060 if (peer) {
3061 peer_as_change(peer, 0, AS_SPECIFIED);
3062 return CMD_SUCCESS;
3063 }
3064
3065 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3066 if (group)
3067 peer_group_remote_as_delete(group);
3068 else {
3069 vty_out(vty, "%% Create the peer-group or interface first\n");
3070 return CMD_WARNING_CONFIG_FAILED;
3071 }
3072 return CMD_SUCCESS;
718e3744 3073}
6b0655a2 3074
718e3744 3075DEFUN (neighbor_local_as,
3076 neighbor_local_as_cmd,
9ccf14f7 3077 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
718e3744 3078 NEIGHBOR_STR
3079 NEIGHBOR_ADDR_STR2
3080 "Specify a local-as number\n"
3081 "AS number used as local AS\n")
3082{
d62a17ae 3083 int idx_peer = 1;
3084 int idx_number = 3;
3085 struct peer *peer;
3086 int ret;
3087 as_t as;
718e3744 3088
d62a17ae 3089 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3090 if (!peer)
3091 return CMD_WARNING_CONFIG_FAILED;
718e3744 3092
d62a17ae 3093 as = strtoul(argv[idx_number]->arg, NULL, 10);
3094 ret = peer_local_as_set(peer, as, 0, 0);
3095 return bgp_vty_return(vty, ret);
718e3744 3096}
3097
3098DEFUN (neighbor_local_as_no_prepend,
3099 neighbor_local_as_no_prepend_cmd,
9ccf14f7 3100 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
718e3744 3101 NEIGHBOR_STR
3102 NEIGHBOR_ADDR_STR2
3103 "Specify a local-as number\n"
3104 "AS number used as local AS\n"
3105 "Do not prepend local-as to updates from ebgp peers\n")
3106{
d62a17ae 3107 int idx_peer = 1;
3108 int idx_number = 3;
3109 struct peer *peer;
3110 int ret;
3111 as_t as;
718e3744 3112
d62a17ae 3113 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3114 if (!peer)
3115 return CMD_WARNING_CONFIG_FAILED;
718e3744 3116
d62a17ae 3117 as = strtoul(argv[idx_number]->arg, NULL, 10);
3118 ret = peer_local_as_set(peer, as, 1, 0);
3119 return bgp_vty_return(vty, ret);
718e3744 3120}
3121
9d3f9705
AC
3122DEFUN (neighbor_local_as_no_prepend_replace_as,
3123 neighbor_local_as_no_prepend_replace_as_cmd,
9ccf14f7 3124 "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
9d3f9705
AC
3125 NEIGHBOR_STR
3126 NEIGHBOR_ADDR_STR2
3127 "Specify a local-as number\n"
3128 "AS number used as local AS\n"
3129 "Do not prepend local-as to updates from ebgp peers\n"
3130 "Do not prepend local-as to updates from ibgp peers\n")
3131{
d62a17ae 3132 int idx_peer = 1;
3133 int idx_number = 3;
3134 struct peer *peer;
3135 int ret;
3136 as_t as;
9d3f9705 3137
d62a17ae 3138 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3139 if (!peer)
3140 return CMD_WARNING_CONFIG_FAILED;
9d3f9705 3141
d62a17ae 3142 as = strtoul(argv[idx_number]->arg, NULL, 10);
3143 ret = peer_local_as_set(peer, as, 1, 1);
3144 return bgp_vty_return(vty, ret);
9d3f9705
AC
3145}
3146
718e3744 3147DEFUN (no_neighbor_local_as,
3148 no_neighbor_local_as_cmd,
a636c635 3149 "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
718e3744 3150 NO_STR
3151 NEIGHBOR_STR
3152 NEIGHBOR_ADDR_STR2
a636c635
DW
3153 "Specify a local-as number\n"
3154 "AS number used as local AS\n"
3155 "Do not prepend local-as to updates from ebgp peers\n"
3156 "Do not prepend local-as to updates from ibgp peers\n")
718e3744 3157{
d62a17ae 3158 int idx_peer = 2;
3159 struct peer *peer;
3160 int ret;
718e3744 3161
d62a17ae 3162 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3163 if (!peer)
3164 return CMD_WARNING_CONFIG_FAILED;
718e3744 3165
d62a17ae 3166 ret = peer_local_as_unset(peer);
3167 return bgp_vty_return(vty, ret);
718e3744 3168}
3169
718e3744 3170
3f9c7369
DS
3171DEFUN (neighbor_solo,
3172 neighbor_solo_cmd,
9ccf14f7 3173 "neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3174 NEIGHBOR_STR
3175 NEIGHBOR_ADDR_STR2
3176 "Solo peer - part of its own update group\n")
3177{
d62a17ae 3178 int idx_peer = 1;
3179 struct peer *peer;
3180 int ret;
3f9c7369 3181
d62a17ae 3182 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3183 if (!peer)
3184 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3185
d62a17ae 3186 ret = update_group_adjust_soloness(peer, 1);
3187 return bgp_vty_return(vty, ret);
3f9c7369
DS
3188}
3189
3190DEFUN (no_neighbor_solo,
3191 no_neighbor_solo_cmd,
9ccf14f7 3192 "no neighbor <A.B.C.D|X:X::X:X|WORD> solo",
3f9c7369
DS
3193 NO_STR
3194 NEIGHBOR_STR
3195 NEIGHBOR_ADDR_STR2
3196 "Solo peer - part of its own update group\n")
3197{
d62a17ae 3198 int idx_peer = 2;
3199 struct peer *peer;
3200 int ret;
3f9c7369 3201
d62a17ae 3202 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3203 if (!peer)
3204 return CMD_WARNING_CONFIG_FAILED;
3f9c7369 3205
d62a17ae 3206 ret = update_group_adjust_soloness(peer, 0);
3207 return bgp_vty_return(vty, ret);
3f9c7369
DS
3208}
3209
0df7c91f
PJ
3210DEFUN (neighbor_password,
3211 neighbor_password_cmd,
9ccf14f7 3212 "neighbor <A.B.C.D|X:X::X:X|WORD> password LINE",
0df7c91f
PJ
3213 NEIGHBOR_STR
3214 NEIGHBOR_ADDR_STR2
3215 "Set a password\n"
3216 "The password\n")
3217{
d62a17ae 3218 int idx_peer = 1;
3219 int idx_line = 3;
3220 struct peer *peer;
3221 int ret;
0df7c91f 3222
d62a17ae 3223 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3224 if (!peer)
3225 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3226
d62a17ae 3227 ret = peer_password_set(peer, argv[idx_line]->arg);
3228 return bgp_vty_return(vty, ret);
0df7c91f
PJ
3229}
3230
3231DEFUN (no_neighbor_password,
3232 no_neighbor_password_cmd,
a636c635 3233 "no neighbor <A.B.C.D|X:X::X:X|WORD> password [LINE]",
0df7c91f
PJ
3234 NO_STR
3235 NEIGHBOR_STR
3236 NEIGHBOR_ADDR_STR2
16cedbb0
QY
3237 "Set a password\n"
3238 "The password\n")
0df7c91f 3239{
d62a17ae 3240 int idx_peer = 2;
3241 struct peer *peer;
3242 int ret;
0df7c91f 3243
d62a17ae 3244 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3245 if (!peer)
3246 return CMD_WARNING_CONFIG_FAILED;
0df7c91f 3247
d62a17ae 3248 ret = peer_password_unset(peer);
3249 return bgp_vty_return(vty, ret);
0df7c91f 3250}
6b0655a2 3251
718e3744 3252DEFUN (neighbor_activate,
3253 neighbor_activate_cmd,
9ccf14f7 3254 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3255 NEIGHBOR_STR
3256 NEIGHBOR_ADDR_STR2
3257 "Enable the Address Family for this Neighbor\n")
3258{
d62a17ae 3259 int idx_peer = 1;
3260 int ret;
3261 struct peer *peer;
718e3744 3262
d62a17ae 3263 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3264 if (!peer)
3265 return CMD_WARNING_CONFIG_FAILED;
718e3744 3266
d62a17ae 3267 ret = peer_activate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3268 return bgp_vty_return(vty, ret);
718e3744 3269}
3270
d62a17ae 3271ALIAS_HIDDEN(neighbor_activate, neighbor_activate_hidden_cmd,
3272 "neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3273 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3274 "Enable the Address Family for this Neighbor\n")
596c17ba 3275
718e3744 3276DEFUN (no_neighbor_activate,
3277 no_neighbor_activate_cmd,
9ccf14f7 3278 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
718e3744 3279 NO_STR
3280 NEIGHBOR_STR
3281 NEIGHBOR_ADDR_STR2
3282 "Enable the Address Family for this Neighbor\n")
3283{
d62a17ae 3284 int idx_peer = 2;
3285 int ret;
3286 struct peer *peer;
718e3744 3287
d62a17ae 3288 /* Lookup peer. */
3289 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3290 if (!peer)
3291 return CMD_WARNING_CONFIG_FAILED;
718e3744 3292
d62a17ae 3293 ret = peer_deactivate(peer, bgp_node_afi(vty), bgp_node_safi(vty));
3294 return bgp_vty_return(vty, ret);
718e3744 3295}
6b0655a2 3296
d62a17ae 3297ALIAS_HIDDEN(no_neighbor_activate, no_neighbor_activate_hidden_cmd,
3298 "no neighbor <A.B.C.D|X:X::X:X|WORD> activate",
3299 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3300 "Enable the Address Family for this Neighbor\n")
596c17ba 3301
718e3744 3302DEFUN (neighbor_set_peer_group,
3303 neighbor_set_peer_group_cmd,
9ccf14f7 3304 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3305 NEIGHBOR_STR
a80beece 3306 NEIGHBOR_ADDR_STR2
718e3744 3307 "Member of the peer-group\n"
16cedbb0 3308 "Peer-group name\n")
718e3744 3309{
d62a17ae 3310 VTY_DECLVAR_CONTEXT(bgp, bgp);
3311 int idx_peer = 1;
3312 int idx_word = 3;
3313 int ret;
3314 as_t as;
3315 union sockunion su;
3316 struct peer *peer;
3317 struct peer_group *group;
3318
3319 peer = NULL;
3320
3321 ret = str2sockunion(argv[idx_peer]->arg, &su);
3322 if (ret < 0) {
3323 peer = peer_lookup_by_conf_if(bgp, argv[idx_peer]->arg);
3324 if (!peer) {
3325 vty_out(vty, "%% Malformed address or name: %s\n",
3326 argv[idx_peer]->arg);
3327 return CMD_WARNING_CONFIG_FAILED;
3328 }
3329 } else {
3330 if (peer_address_self_check(bgp, &su)) {
3331 vty_out(vty,
3332 "%% Can not configure the local system as neighbor\n");
3333 return CMD_WARNING_CONFIG_FAILED;
3334 }
3335
3336 /* Disallow for dynamic neighbor. */
3337 peer = peer_lookup(bgp, &su);
3338 if (peer && peer_dynamic_neighbor(peer)) {
3339 vty_out(vty,
3340 "%% Operation not allowed on a dynamic neighbor\n");
3341 return CMD_WARNING_CONFIG_FAILED;
3342 }
3343 }
3344
3345 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3346 if (!group) {
3347 vty_out(vty, "%% Configure the peer-group first\n");
3348 return CMD_WARNING_CONFIG_FAILED;
3349 }
3350
3351 ret = peer_group_bind(bgp, &su, peer, group, &as);
3352
3353 if (ret == BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT) {
3354 vty_out(vty,
3355 "%% Peer with AS %u cannot be in this peer-group, members must be all internal or all external\n",
3356 as);
3357 return CMD_WARNING_CONFIG_FAILED;
3358 }
3359
3360 return bgp_vty_return(vty, ret);
3361}
3362
3363ALIAS_HIDDEN(neighbor_set_peer_group, neighbor_set_peer_group_hidden_cmd,
3364 "neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3365 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3366 "Member of the peer-group\n"
3367 "Peer-group name\n")
596c17ba 3368
718e3744 3369DEFUN (no_neighbor_set_peer_group,
3370 no_neighbor_set_peer_group_cmd,
9ccf14f7 3371 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
718e3744 3372 NO_STR
3373 NEIGHBOR_STR
a80beece 3374 NEIGHBOR_ADDR_STR2
718e3744 3375 "Member of the peer-group\n"
16cedbb0 3376 "Peer-group name\n")
718e3744 3377{
d62a17ae 3378 VTY_DECLVAR_CONTEXT(bgp, bgp);
3379 int idx_peer = 2;
3380 int idx_word = 4;
3381 int ret;
3382 struct peer *peer;
3383 struct peer_group *group;
3384
3385 peer = peer_lookup_vty(vty, argv[idx_peer]->arg);
3386 if (!peer)
3387 return CMD_WARNING_CONFIG_FAILED;
3388
3389 group = peer_group_lookup(bgp, argv[idx_word]->arg);
3390 if (!group) {
3391 vty_out(vty, "%% Configure the peer-group first\n");
3392 return CMD_WARNING_CONFIG_FAILED;
3393 }
718e3744 3394
827ed707 3395 ret = peer_delete(peer);
718e3744 3396
d62a17ae 3397 return bgp_vty_return(vty, ret);
718e3744 3398}
6b0655a2 3399
d62a17ae 3400ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd,
3401 "no neighbor <A.B.C.D|X:X::X:X|WORD> peer-group WORD",
3402 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3403 "Member of the peer-group\n"
3404 "Peer-group name\n")
596c17ba 3405
d62a17ae 3406static int peer_flag_modify_vty(struct vty *vty, const char *ip_str,
3407 u_int16_t flag, int set)
718e3744 3408{
d62a17ae 3409 int ret;
3410 struct peer *peer;
718e3744 3411
d62a17ae 3412 peer = peer_and_group_lookup_vty(vty, ip_str);
3413 if (!peer)
3414 return CMD_WARNING_CONFIG_FAILED;
718e3744 3415
7ebe625c
QY
3416 /*
3417 * If 'neighbor <interface>', then this is for directly connected peers,
3418 * we should not accept disable-connected-check.
3419 */
3420 if (peer->conf_if && (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK)) {
3421 vty_out(vty,
3422 "%s is directly connected peer, cannot accept disable-"
3423 "connected-check\n",
3424 ip_str);
3425 return CMD_WARNING_CONFIG_FAILED;
3426 }
3427
d62a17ae 3428 if (!set && flag == PEER_FLAG_SHUTDOWN)
3429 peer_tx_shutdown_message_unset(peer);
ae9b0e11 3430
d62a17ae 3431 if (set)
3432 ret = peer_flag_set(peer, flag);
3433 else
3434 ret = peer_flag_unset(peer, flag);
718e3744 3435
d62a17ae 3436 return bgp_vty_return(vty, ret);
718e3744 3437}
3438
d62a17ae 3439static int peer_flag_set_vty(struct vty *vty, const char *ip_str,
3440 u_int16_t flag)
718e3744 3441{
d62a17ae 3442 return peer_flag_modify_vty(vty, ip_str, flag, 1);
718e3744 3443}
3444
d62a17ae 3445static int peer_flag_unset_vty(struct vty *vty, const char *ip_str,
3446 u_int16_t flag)
718e3744 3447{
d62a17ae 3448 return peer_flag_modify_vty(vty, ip_str, flag, 0);
718e3744 3449}
3450
3451/* neighbor passive. */
3452DEFUN (neighbor_passive,
3453 neighbor_passive_cmd,
9ccf14f7 3454 "neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3455 NEIGHBOR_STR
3456 NEIGHBOR_ADDR_STR2
3457 "Don't send open messages to this neighbor\n")
3458{
d62a17ae 3459 int idx_peer = 1;
3460 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3461}
3462
3463DEFUN (no_neighbor_passive,
3464 no_neighbor_passive_cmd,
9ccf14f7 3465 "no neighbor <A.B.C.D|X:X::X:X|WORD> passive",
718e3744 3466 NO_STR
3467 NEIGHBOR_STR
3468 NEIGHBOR_ADDR_STR2
3469 "Don't send open messages to this neighbor\n")
3470{
d62a17ae 3471 int idx_peer = 2;
3472 return peer_flag_unset_vty(vty, argv[idx_peer]->arg, PEER_FLAG_PASSIVE);
718e3744 3473}
6b0655a2 3474
718e3744 3475/* neighbor shutdown. */
73d70fa6
DL
3476DEFUN (neighbor_shutdown_msg,
3477 neighbor_shutdown_msg_cmd,
3478 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
718e3744 3479 NEIGHBOR_STR
3480 NEIGHBOR_ADDR_STR2
73d70fa6
DL
3481 "Administratively shut down this neighbor\n"
3482 "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
3483 "Shutdown message\n")
718e3744 3484{
d62a17ae 3485 int idx_peer = 1;
73d70fa6 3486
d62a17ae 3487 if (argc >= 5) {
3488 struct peer *peer =
3489 peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
3490 char *message;
73d70fa6 3491
d62a17ae 3492 if (!peer)
3493 return CMD_WARNING_CONFIG_FAILED;
3494 message = argv_concat(argv, argc, 4);
3495 peer_tx_shutdown_message_set(peer, message);
3496 XFREE(MTYPE_TMP, message);
3497 }
73d70fa6 3498
d62a17ae 3499 return peer_flag_set_vty(vty, argv[idx_peer]->arg, PEER_FLAG_SHUTDOWN);
718e3744 3500}
3501
d62a17ae 3502ALIAS(neighbor_shutdown_msg, neighbor_shutdown_cmd,
3503 "neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3504 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3505 "Administratively shut down this neighbor\n")
73d70fa6
DL
3506
3507DEFUN (no_neighbor_shutdown_msg,
3508 no_neighbor_shutdown_msg_cmd,
3509 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown message MSG...",
3510 NO_STR
3511 NEIGHBOR_STR
3512 NEIGHBOR_ADDR_STR2
3513 "Administratively shut down this neighbor\n"
3514 "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
3515 "Shutdown message\n")
718e3744 3516{
d62a17ae 3517 int idx_peer = 2;
73d70fa6 3518
d62a17ae 3519 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3520 PEER_FLAG_SHUTDOWN);
718e3744 3521}
6b0655a2 3522
d62a17ae 3523ALIAS(no_neighbor_shutdown_msg, no_neighbor_shutdown_cmd,
3524 "no neighbor <A.B.C.D|X:X::X:X|WORD> shutdown",
3525 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3526 "Administratively shut down this neighbor\n")
73d70fa6 3527
718e3744 3528/* neighbor capability dynamic. */
3529DEFUN (neighbor_capability_dynamic,
3530 neighbor_capability_dynamic_cmd,
9ccf14f7 3531 "neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3532 NEIGHBOR_STR
3533 NEIGHBOR_ADDR_STR2
3534 "Advertise capability to the peer\n"
3535 "Advertise dynamic capability to this neighbor\n")
3536{
d62a17ae 3537 int idx_peer = 1;
3538 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3539 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3540}
3541
3542DEFUN (no_neighbor_capability_dynamic,
3543 no_neighbor_capability_dynamic_cmd,
9ccf14f7 3544 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability dynamic",
718e3744 3545 NO_STR
3546 NEIGHBOR_STR
3547 NEIGHBOR_ADDR_STR2
3548 "Advertise capability to the peer\n"
3549 "Advertise dynamic capability to this neighbor\n")
3550{
d62a17ae 3551 int idx_peer = 2;
3552 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3553 PEER_FLAG_DYNAMIC_CAPABILITY);
718e3744 3554}
6b0655a2 3555
718e3744 3556/* neighbor dont-capability-negotiate */
3557DEFUN (neighbor_dont_capability_negotiate,
3558 neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3559 "neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3560 NEIGHBOR_STR
3561 NEIGHBOR_ADDR_STR2
3562 "Do not perform capability negotiation\n")
3563{
d62a17ae 3564 int idx_peer = 1;
3565 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3566 PEER_FLAG_DONT_CAPABILITY);
718e3744 3567}
3568
3569DEFUN (no_neighbor_dont_capability_negotiate,
3570 no_neighbor_dont_capability_negotiate_cmd,
9ccf14f7 3571 "no neighbor <A.B.C.D|X:X::X:X|WORD> dont-capability-negotiate",
718e3744 3572 NO_STR
3573 NEIGHBOR_STR
3574 NEIGHBOR_ADDR_STR2
3575 "Do not perform capability negotiation\n")
3576{
d62a17ae 3577 int idx_peer = 2;
3578 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3579 PEER_FLAG_DONT_CAPABILITY);
718e3744 3580}
6b0655a2 3581
8a92a8a0
DS
3582/* neighbor capability extended next hop encoding */
3583DEFUN (neighbor_capability_enhe,
3584 neighbor_capability_enhe_cmd,
9ccf14f7 3585 "neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3586 NEIGHBOR_STR
3587 NEIGHBOR_ADDR_STR2
3588 "Advertise capability to the peer\n"
3589 "Advertise extended next-hop capability to the peer\n")
3590{
d62a17ae 3591 int idx_peer = 1;
3592 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
3593 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3594}
3595
3596DEFUN (no_neighbor_capability_enhe,
3597 no_neighbor_capability_enhe_cmd,
9ccf14f7 3598 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability extended-nexthop",
8a92a8a0
DS
3599 NO_STR
3600 NEIGHBOR_STR
3601 NEIGHBOR_ADDR_STR2
3602 "Advertise capability to the peer\n"
3603 "Advertise extended next-hop capability to the peer\n")
3604{
d62a17ae 3605 int idx_peer = 2;
3606 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
3607 PEER_FLAG_CAPABILITY_ENHE);
8a92a8a0
DS
3608}
3609
d62a17ae 3610static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str,
3611 afi_t afi, safi_t safi, u_int32_t flag,
3612 int set)
718e3744 3613{
d62a17ae 3614 int ret;
3615 struct peer *peer;
718e3744 3616
d62a17ae 3617 peer = peer_and_group_lookup_vty(vty, peer_str);
3618 if (!peer)
3619 return CMD_WARNING_CONFIG_FAILED;
718e3744 3620
d62a17ae 3621 if (set)
3622 ret = peer_af_flag_set(peer, afi, safi, flag);
3623 else
3624 ret = peer_af_flag_unset(peer, afi, safi, flag);
718e3744 3625
d62a17ae 3626 return bgp_vty_return(vty, ret);
718e3744 3627}
3628
d62a17ae 3629static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str,
3630 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3631{
d62a17ae 3632 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1);
718e3744 3633}
3634
d62a17ae 3635static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str,
3636 afi_t afi, safi_t safi, u_int32_t flag)
718e3744 3637{
d62a17ae 3638 return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0);
718e3744 3639}
6b0655a2 3640
718e3744 3641/* neighbor capability orf prefix-list. */
3642DEFUN (neighbor_capability_orf_prefix,
3643 neighbor_capability_orf_prefix_cmd,
9ccf14f7 3644 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3645 NEIGHBOR_STR
3646 NEIGHBOR_ADDR_STR2
3647 "Advertise capability to the peer\n"
3648 "Advertise ORF capability to the peer\n"
3649 "Advertise prefixlist ORF capability to this neighbor\n"
3650 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3651 "Capability to RECEIVE the ORF from this neighbor\n"
3652 "Capability to SEND the ORF to this neighbor\n")
3653{
d62a17ae 3654 int idx_peer = 1;
3655 int idx_send_recv = 5;
3656 u_int16_t flag = 0;
3657
3658 if (strmatch(argv[idx_send_recv]->text, "send"))
3659 flag = PEER_FLAG_ORF_PREFIX_SM;
3660 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3661 flag = PEER_FLAG_ORF_PREFIX_RM;
3662 else if (strmatch(argv[idx_send_recv]->text, "both"))
3663 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3664 else {
3665 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3666 return CMD_WARNING_CONFIG_FAILED;
3667 }
3668
3669 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3670 bgp_node_safi(vty), flag);
3671}
3672
3673ALIAS_HIDDEN(
3674 neighbor_capability_orf_prefix,
3675 neighbor_capability_orf_prefix_hidden_cmd,
3676 "neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3677 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3678 "Advertise capability to the peer\n"
3679 "Advertise ORF capability to the peer\n"
3680 "Advertise prefixlist ORF capability to this neighbor\n"
3681 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3682 "Capability to RECEIVE the ORF from this neighbor\n"
3683 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3684
718e3744 3685DEFUN (no_neighbor_capability_orf_prefix,
3686 no_neighbor_capability_orf_prefix_cmd,
9ccf14f7 3687 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
718e3744 3688 NO_STR
3689 NEIGHBOR_STR
3690 NEIGHBOR_ADDR_STR2
3691 "Advertise capability to the peer\n"
3692 "Advertise ORF capability to the peer\n"
3693 "Advertise prefixlist ORF capability to this neighbor\n"
3694 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3695 "Capability to RECEIVE the ORF from this neighbor\n"
3696 "Capability to SEND the ORF to this neighbor\n")
3697{
d62a17ae 3698 int idx_peer = 2;
3699 int idx_send_recv = 6;
3700 u_int16_t flag = 0;
3701
3702 if (strmatch(argv[idx_send_recv]->text, "send"))
3703 flag = PEER_FLAG_ORF_PREFIX_SM;
3704 else if (strmatch(argv[idx_send_recv]->text, "receive"))
3705 flag = PEER_FLAG_ORF_PREFIX_RM;
3706 else if (strmatch(argv[idx_send_recv]->text, "both"))
3707 flag = PEER_FLAG_ORF_PREFIX_SM | PEER_FLAG_ORF_PREFIX_RM;
3708 else {
3709 vty_out(vty, "%% BGP invalid orf prefix-list option\n");
3710 return CMD_WARNING_CONFIG_FAILED;
3711 }
3712
3713 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3714 bgp_node_afi(vty), bgp_node_safi(vty),
3715 flag);
3716}
3717
3718ALIAS_HIDDEN(
3719 no_neighbor_capability_orf_prefix,
3720 no_neighbor_capability_orf_prefix_hidden_cmd,
3721 "no neighbor <A.B.C.D|X:X::X:X|WORD> capability orf prefix-list <both|send|receive>",
3722 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3723 "Advertise capability to the peer\n"
3724 "Advertise ORF capability to the peer\n"
3725 "Advertise prefixlist ORF capability to this neighbor\n"
3726 "Capability to SEND and RECEIVE the ORF to/from this neighbor\n"
3727 "Capability to RECEIVE the ORF from this neighbor\n"
3728 "Capability to SEND the ORF to this neighbor\n")
596c17ba 3729
718e3744 3730/* neighbor next-hop-self. */
3731DEFUN (neighbor_nexthop_self,
3732 neighbor_nexthop_self_cmd,
9ccf14f7 3733 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3734 NEIGHBOR_STR
3735 NEIGHBOR_ADDR_STR2
a538debe 3736 "Disable the next hop calculation for this neighbor\n")
718e3744 3737{
d62a17ae 3738 int idx_peer = 1;
3739 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3740 bgp_node_safi(vty), PEER_FLAG_NEXTHOP_SELF);
a538debe 3741}
9e7a53c1 3742
d62a17ae 3743ALIAS_HIDDEN(neighbor_nexthop_self, neighbor_nexthop_self_hidden_cmd,
3744 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3745 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3746 "Disable the next hop calculation for this neighbor\n")
596c17ba 3747
a538debe
DS
3748/* neighbor next-hop-self. */
3749DEFUN (neighbor_nexthop_self_force,
3750 neighbor_nexthop_self_force_cmd,
9ccf14f7 3751 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3752 NEIGHBOR_STR
3753 NEIGHBOR_ADDR_STR2
3754 "Disable the next hop calculation for this neighbor\n"
3755 "Set the next hop to self for reflected routes\n")
3756{
d62a17ae 3757 int idx_peer = 1;
3758 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3759 bgp_node_safi(vty),
3760 PEER_FLAG_FORCE_NEXTHOP_SELF);
718e3744 3761}
3762
d62a17ae 3763ALIAS_HIDDEN(neighbor_nexthop_self_force,
3764 neighbor_nexthop_self_force_hidden_cmd,
3765 "neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3766 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3767 "Disable the next hop calculation for this neighbor\n"
3768 "Set the next hop to self for reflected routes\n")
596c17ba 3769
718e3744 3770DEFUN (no_neighbor_nexthop_self,
3771 no_neighbor_nexthop_self_cmd,
9ccf14f7 3772 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
718e3744 3773 NO_STR
3774 NEIGHBOR_STR
3775 NEIGHBOR_ADDR_STR2
a538debe 3776 "Disable the next hop calculation for this neighbor\n")
718e3744 3777{
d62a17ae 3778 int idx_peer = 2;
3779 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3780 bgp_node_afi(vty), bgp_node_safi(vty),
3781 PEER_FLAG_NEXTHOP_SELF);
718e3744 3782}
6b0655a2 3783
d62a17ae 3784ALIAS_HIDDEN(no_neighbor_nexthop_self, no_neighbor_nexthop_self_hidden_cmd,
3785 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self",
3786 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3787 "Disable the next hop calculation for this neighbor\n")
596c17ba 3788
88b8ed8d 3789DEFUN (no_neighbor_nexthop_self_force,
a538debe 3790 no_neighbor_nexthop_self_force_cmd,
9ccf14f7 3791 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
a538debe
DS
3792 NO_STR
3793 NEIGHBOR_STR
3794 NEIGHBOR_ADDR_STR2
3795 "Disable the next hop calculation for this neighbor\n"
3796 "Set the next hop to self for reflected routes\n")
88b8ed8d 3797{
d62a17ae 3798 int idx_peer = 2;
3799 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3800 bgp_node_afi(vty), bgp_node_safi(vty),
3801 PEER_FLAG_FORCE_NEXTHOP_SELF);
88b8ed8d 3802}
a538debe 3803
d62a17ae 3804ALIAS_HIDDEN(no_neighbor_nexthop_self_force,
3805 no_neighbor_nexthop_self_force_hidden_cmd,
3806 "no neighbor <A.B.C.D|X:X::X:X|WORD> next-hop-self force",
3807 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3808 "Disable the next hop calculation for this neighbor\n"
3809 "Set the next hop to self for reflected routes\n")
596c17ba 3810
c7122e14
DS
3811/* neighbor as-override */
3812DEFUN (neighbor_as_override,
3813 neighbor_as_override_cmd,
9ccf14f7 3814 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3815 NEIGHBOR_STR
3816 NEIGHBOR_ADDR_STR2
3817 "Override ASNs in outbound updates if aspath equals remote-as\n")
3818{
d62a17ae 3819 int idx_peer = 1;
3820 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3821 bgp_node_safi(vty), PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3822}
3823
d62a17ae 3824ALIAS_HIDDEN(neighbor_as_override, neighbor_as_override_hidden_cmd,
3825 "neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3827 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3828
c7122e14
DS
3829DEFUN (no_neighbor_as_override,
3830 no_neighbor_as_override_cmd,
9ccf14f7 3831 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
c7122e14
DS
3832 NO_STR
3833 NEIGHBOR_STR
3834 NEIGHBOR_ADDR_STR2
3835 "Override ASNs in outbound updates if aspath equals remote-as\n")
3836{
d62a17ae 3837 int idx_peer = 2;
3838 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3839 bgp_node_afi(vty), bgp_node_safi(vty),
3840 PEER_FLAG_AS_OVERRIDE);
c7122e14
DS
3841}
3842
d62a17ae 3843ALIAS_HIDDEN(no_neighbor_as_override, no_neighbor_as_override_hidden_cmd,
3844 "no neighbor <A.B.C.D|X:X::X:X|WORD> as-override",
3845 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3846 "Override ASNs in outbound updates if aspath equals remote-as\n")
596c17ba 3847
718e3744 3848/* neighbor remove-private-AS. */
3849DEFUN (neighbor_remove_private_as,
3850 neighbor_remove_private_as_cmd,
9ccf14f7 3851 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3852 NEIGHBOR_STR
3853 NEIGHBOR_ADDR_STR2
5000f21c 3854 "Remove private ASNs in outbound updates\n")
718e3744 3855{
d62a17ae 3856 int idx_peer = 1;
3857 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3858 bgp_node_safi(vty),
3859 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3860}
3861
d62a17ae 3862ALIAS_HIDDEN(neighbor_remove_private_as, neighbor_remove_private_as_hidden_cmd,
3863 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3864 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3865 "Remove private ASNs in outbound updates\n")
596c17ba 3866
5000f21c
DS
3867DEFUN (neighbor_remove_private_as_all,
3868 neighbor_remove_private_as_all_cmd,
9ccf14f7 3869 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3870 NEIGHBOR_STR
3871 NEIGHBOR_ADDR_STR2
3872 "Remove private ASNs in outbound updates\n"
efd7904e 3873 "Apply to all AS numbers\n")
5000f21c 3874{
d62a17ae 3875 int idx_peer = 1;
3876 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3877 bgp_node_safi(vty),
3878 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
5000f21c
DS
3879}
3880
d62a17ae 3881ALIAS_HIDDEN(neighbor_remove_private_as_all,
3882 neighbor_remove_private_as_all_hidden_cmd,
3883 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3884 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3885 "Remove private ASNs in outbound updates\n"
3886 "Apply to all AS numbers")
596c17ba 3887
5000f21c
DS
3888DEFUN (neighbor_remove_private_as_replace_as,
3889 neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3890 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3891 NEIGHBOR_STR
3892 NEIGHBOR_ADDR_STR2
3893 "Remove private ASNs in outbound updates\n"
3894 "Replace private ASNs with our ASN in outbound updates\n")
3895{
d62a17ae 3896 int idx_peer = 1;
3897 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3898 bgp_node_safi(vty),
3899 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
5000f21c
DS
3900}
3901
d62a17ae 3902ALIAS_HIDDEN(neighbor_remove_private_as_replace_as,
3903 neighbor_remove_private_as_replace_as_hidden_cmd,
3904 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3905 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3906 "Remove private ASNs in outbound updates\n"
3907 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3908
5000f21c
DS
3909DEFUN (neighbor_remove_private_as_all_replace_as,
3910 neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3911 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
3912 NEIGHBOR_STR
3913 NEIGHBOR_ADDR_STR2
3914 "Remove private ASNs in outbound updates\n"
16cedbb0 3915 "Apply to all AS numbers\n"
5000f21c
DS
3916 "Replace private ASNs with our ASN in outbound updates\n")
3917{
d62a17ae 3918 int idx_peer = 1;
3919 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
3920 bgp_node_safi(vty),
3921 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
5000f21c
DS
3922}
3923
d62a17ae 3924ALIAS_HIDDEN(
3925 neighbor_remove_private_as_all_replace_as,
3926 neighbor_remove_private_as_all_replace_as_hidden_cmd,
3927 "neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
3928 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3929 "Remove private ASNs in outbound updates\n"
3930 "Apply to all AS numbers\n"
3931 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3932
718e3744 3933DEFUN (no_neighbor_remove_private_as,
3934 no_neighbor_remove_private_as_cmd,
9ccf14f7 3935 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
718e3744 3936 NO_STR
3937 NEIGHBOR_STR
3938 NEIGHBOR_ADDR_STR2
5000f21c 3939 "Remove private ASNs in outbound updates\n")
718e3744 3940{
d62a17ae 3941 int idx_peer = 2;
3942 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3943 bgp_node_afi(vty), bgp_node_safi(vty),
3944 PEER_FLAG_REMOVE_PRIVATE_AS);
718e3744 3945}
6b0655a2 3946
d62a17ae 3947ALIAS_HIDDEN(no_neighbor_remove_private_as,
3948 no_neighbor_remove_private_as_hidden_cmd,
3949 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS",
3950 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3951 "Remove private ASNs in outbound updates\n")
596c17ba 3952
88b8ed8d 3953DEFUN (no_neighbor_remove_private_as_all,
5000f21c 3954 no_neighbor_remove_private_as_all_cmd,
9ccf14f7 3955 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
5000f21c
DS
3956 NO_STR
3957 NEIGHBOR_STR
3958 NEIGHBOR_ADDR_STR2
3959 "Remove private ASNs in outbound updates\n"
16cedbb0 3960 "Apply to all AS numbers\n")
88b8ed8d 3961{
d62a17ae 3962 int idx_peer = 2;
3963 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3964 bgp_node_afi(vty), bgp_node_safi(vty),
3965 PEER_FLAG_REMOVE_PRIVATE_AS_ALL);
88b8ed8d 3966}
5000f21c 3967
d62a17ae 3968ALIAS_HIDDEN(no_neighbor_remove_private_as_all,
3969 no_neighbor_remove_private_as_all_hidden_cmd,
3970 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all",
3971 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3972 "Remove private ASNs in outbound updates\n"
3973 "Apply to all AS numbers\n")
596c17ba 3974
88b8ed8d 3975DEFUN (no_neighbor_remove_private_as_replace_as,
5000f21c 3976 no_neighbor_remove_private_as_replace_as_cmd,
9ccf14f7 3977 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
5000f21c
DS
3978 NO_STR
3979 NEIGHBOR_STR
3980 NEIGHBOR_ADDR_STR2
3981 "Remove private ASNs in outbound updates\n"
3982 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 3983{
d62a17ae 3984 int idx_peer = 2;
3985 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
3986 bgp_node_afi(vty), bgp_node_safi(vty),
3987 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE);
88b8ed8d 3988}
5000f21c 3989
d62a17ae 3990ALIAS_HIDDEN(no_neighbor_remove_private_as_replace_as,
3991 no_neighbor_remove_private_as_replace_as_hidden_cmd,
3992 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS replace-AS",
3993 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
3994 "Remove private ASNs in outbound updates\n"
3995 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 3996
88b8ed8d 3997DEFUN (no_neighbor_remove_private_as_all_replace_as,
5000f21c 3998 no_neighbor_remove_private_as_all_replace_as_cmd,
9ccf14f7 3999 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
5000f21c
DS
4000 NO_STR
4001 NEIGHBOR_STR
4002 NEIGHBOR_ADDR_STR2
4003 "Remove private ASNs in outbound updates\n"
16cedbb0 4004 "Apply to all AS numbers\n"
5000f21c 4005 "Replace private ASNs with our ASN in outbound updates\n")
88b8ed8d 4006{
d62a17ae 4007 int idx_peer = 2;
4008 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4009 bgp_node_afi(vty), bgp_node_safi(vty),
4010 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE);
88b8ed8d 4011}
5000f21c 4012
d62a17ae 4013ALIAS_HIDDEN(
4014 no_neighbor_remove_private_as_all_replace_as,
4015 no_neighbor_remove_private_as_all_replace_as_hidden_cmd,
4016 "no neighbor <A.B.C.D|X:X::X:X|WORD> remove-private-AS all replace-AS",
4017 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4018 "Remove private ASNs in outbound updates\n"
4019 "Apply to all AS numbers\n"
4020 "Replace private ASNs with our ASN in outbound updates\n")
596c17ba 4021
5000f21c 4022
718e3744 4023/* neighbor send-community. */
4024DEFUN (neighbor_send_community,
4025 neighbor_send_community_cmd,
9ccf14f7 4026 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4027 NEIGHBOR_STR
4028 NEIGHBOR_ADDR_STR2
4029 "Send Community attribute to this neighbor\n")
4030{
d62a17ae 4031 int idx_peer = 1;
4032 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4033 bgp_node_safi(vty),
4034 PEER_FLAG_SEND_COMMUNITY);
718e3744 4035}
4036
d62a17ae 4037ALIAS_HIDDEN(neighbor_send_community, neighbor_send_community_hidden_cmd,
4038 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4039 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4040 "Send Community attribute to this neighbor\n")
596c17ba 4041
718e3744 4042DEFUN (no_neighbor_send_community,
4043 no_neighbor_send_community_cmd,
9ccf14f7 4044 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
718e3744 4045 NO_STR
4046 NEIGHBOR_STR
4047 NEIGHBOR_ADDR_STR2
4048 "Send Community attribute to this neighbor\n")
4049{
d62a17ae 4050 int idx_peer = 2;
4051 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4052 bgp_node_afi(vty), bgp_node_safi(vty),
4053 PEER_FLAG_SEND_COMMUNITY);
718e3744 4054}
6b0655a2 4055
d62a17ae 4056ALIAS_HIDDEN(no_neighbor_send_community, no_neighbor_send_community_hidden_cmd,
4057 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community",
4058 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4059 "Send Community attribute to this neighbor\n")
596c17ba 4060
718e3744 4061/* neighbor send-community extended. */
4062DEFUN (neighbor_send_community_type,
4063 neighbor_send_community_type_cmd,
57d187bc 4064 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4065 NEIGHBOR_STR
4066 NEIGHBOR_ADDR_STR2
4067 "Send Community attribute to this neighbor\n"
4068 "Send Standard and Extended Community attributes\n"
57d187bc 4069 "Send Standard, Large and Extended Community attributes\n"
718e3744 4070 "Send Extended Community attributes\n"
57d187bc
JS
4071 "Send Standard Community attributes\n"
4072 "Send Large Community attributes\n")
718e3744 4073{
d62a17ae 4074 int idx = 0;
4075 u_int32_t flag = 0;
4076
4077 char *peer = argv[1]->arg;
4078
4079 if (argv_find(argv, argc, "standard", &idx))
4080 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4081 else if (argv_find(argv, argc, "extended", &idx))
4082 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4083 else if (argv_find(argv, argc, "large", &idx))
4084 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4085 else if (argv_find(argv, argc, "both", &idx)) {
4086 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4087 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4088 } else {
4089 SET_FLAG(flag, PEER_FLAG_SEND_COMMUNITY);
4090 SET_FLAG(flag, PEER_FLAG_SEND_EXT_COMMUNITY);
4091 SET_FLAG(flag, PEER_FLAG_SEND_LARGE_COMMUNITY);
4092 }
4093
4094 return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty),
4095 bgp_node_safi(vty), flag);
4096}
4097
4098ALIAS_HIDDEN(
4099 neighbor_send_community_type, neighbor_send_community_type_hidden_cmd,
4100 "neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4101 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4102 "Send Community attribute to this neighbor\n"
4103 "Send Standard and Extended Community attributes\n"
4104 "Send Standard, Large and Extended Community attributes\n"
4105 "Send Extended Community attributes\n"
4106 "Send Standard Community attributes\n"
4107 "Send Large Community attributes\n")
596c17ba 4108
718e3744 4109DEFUN (no_neighbor_send_community_type,
4110 no_neighbor_send_community_type_cmd,
57d187bc 4111 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
718e3744 4112 NO_STR
4113 NEIGHBOR_STR
4114 NEIGHBOR_ADDR_STR2
4115 "Send Community attribute to this neighbor\n"
4116 "Send Standard and Extended Community attributes\n"
57d187bc 4117 "Send Standard, Large and Extended Community attributes\n"
718e3744 4118 "Send Extended Community attributes\n"
57d187bc
JS
4119 "Send Standard Community attributes\n"
4120 "Send Large Community attributes\n")
718e3744 4121{
d62a17ae 4122 int idx_peer = 2;
4123
4124 const char *type = argv[argc - 1]->text;
4125
4126 if (strmatch(type, "standard"))
4127 return peer_af_flag_unset_vty(
4128 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4129 bgp_node_safi(vty), PEER_FLAG_SEND_COMMUNITY);
4130 if (strmatch(type, "extended"))
4131 return peer_af_flag_unset_vty(
4132 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4133 bgp_node_safi(vty), PEER_FLAG_SEND_EXT_COMMUNITY);
4134 if (strmatch(type, "large"))
4135 return peer_af_flag_unset_vty(
4136 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4137 bgp_node_safi(vty), PEER_FLAG_SEND_LARGE_COMMUNITY);
4138 if (strmatch(type, "both"))
4139 return peer_af_flag_unset_vty(
4140 vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4141 bgp_node_safi(vty),
4142 PEER_FLAG_SEND_COMMUNITY
4143 | PEER_FLAG_SEND_EXT_COMMUNITY);
4144
4145 /* if (strmatch (type, "all")) */
4146 return peer_af_flag_unset_vty(
4147 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4148 (PEER_FLAG_SEND_COMMUNITY | PEER_FLAG_SEND_EXT_COMMUNITY
4149 | PEER_FLAG_SEND_LARGE_COMMUNITY));
4150}
4151
4152ALIAS_HIDDEN(
4153 no_neighbor_send_community_type,
4154 no_neighbor_send_community_type_hidden_cmd,
4155 "no neighbor <A.B.C.D|X:X::X:X|WORD> send-community <both|all|extended|standard|large>",
4156 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4157 "Send Community attribute to this neighbor\n"
4158 "Send Standard and Extended Community attributes\n"
4159 "Send Standard, Large and Extended Community attributes\n"
4160 "Send Extended Community attributes\n"
4161 "Send Standard Community attributes\n"
4162 "Send Large Community attributes\n")
596c17ba 4163
718e3744 4164/* neighbor soft-reconfig. */
4165DEFUN (neighbor_soft_reconfiguration,
4166 neighbor_soft_reconfiguration_cmd,
9ccf14f7 4167 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4168 NEIGHBOR_STR
4169 NEIGHBOR_ADDR_STR2
4170 "Per neighbor soft reconfiguration\n"
4171 "Allow inbound soft reconfiguration for this neighbor\n")
4172{
d62a17ae 4173 int idx_peer = 1;
4174 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4175 bgp_node_safi(vty),
4176 PEER_FLAG_SOFT_RECONFIG);
718e3744 4177}
4178
d62a17ae 4179ALIAS_HIDDEN(neighbor_soft_reconfiguration,
4180 neighbor_soft_reconfiguration_hidden_cmd,
4181 "neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4182 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4183 "Per neighbor soft reconfiguration\n"
4184 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4185
718e3744 4186DEFUN (no_neighbor_soft_reconfiguration,
4187 no_neighbor_soft_reconfiguration_cmd,
9ccf14f7 4188 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
718e3744 4189 NO_STR
4190 NEIGHBOR_STR
4191 NEIGHBOR_ADDR_STR2
4192 "Per neighbor soft reconfiguration\n"
4193 "Allow inbound soft reconfiguration for this neighbor\n")
4194{
d62a17ae 4195 int idx_peer = 2;
4196 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4197 bgp_node_afi(vty), bgp_node_safi(vty),
4198 PEER_FLAG_SOFT_RECONFIG);
718e3744 4199}
6b0655a2 4200
d62a17ae 4201ALIAS_HIDDEN(no_neighbor_soft_reconfiguration,
4202 no_neighbor_soft_reconfiguration_hidden_cmd,
4203 "no neighbor <A.B.C.D|X:X::X:X|WORD> soft-reconfiguration inbound",
4204 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4205 "Per neighbor soft reconfiguration\n"
4206 "Allow inbound soft reconfiguration for this neighbor\n")
596c17ba 4207
718e3744 4208DEFUN (neighbor_route_reflector_client,
4209 neighbor_route_reflector_client_cmd,
9ccf14f7 4210 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4211 NEIGHBOR_STR
4212 NEIGHBOR_ADDR_STR2
4213 "Configure a neighbor as Route Reflector client\n")
4214{
d62a17ae 4215 int idx_peer = 1;
4216 struct peer *peer;
718e3744 4217
4218
d62a17ae 4219 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4220 if (!peer)
4221 return CMD_WARNING_CONFIG_FAILED;
718e3744 4222
d62a17ae 4223 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4224 bgp_node_safi(vty),
4225 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4226}
4227
d62a17ae 4228ALIAS_HIDDEN(neighbor_route_reflector_client,
4229 neighbor_route_reflector_client_hidden_cmd,
4230 "neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4231 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4232 "Configure a neighbor as Route Reflector client\n")
596c17ba 4233
718e3744 4234DEFUN (no_neighbor_route_reflector_client,
4235 no_neighbor_route_reflector_client_cmd,
9ccf14f7 4236 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
718e3744 4237 NO_STR
4238 NEIGHBOR_STR
4239 NEIGHBOR_ADDR_STR2
4240 "Configure a neighbor as Route Reflector client\n")
4241{
d62a17ae 4242 int idx_peer = 2;
4243 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4244 bgp_node_afi(vty), bgp_node_safi(vty),
4245 PEER_FLAG_REFLECTOR_CLIENT);
718e3744 4246}
6b0655a2 4247
d62a17ae 4248ALIAS_HIDDEN(no_neighbor_route_reflector_client,
4249 no_neighbor_route_reflector_client_hidden_cmd,
4250 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-reflector-client",
4251 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4252 "Configure a neighbor as Route Reflector client\n")
596c17ba 4253
718e3744 4254/* neighbor route-server-client. */
4255DEFUN (neighbor_route_server_client,
4256 neighbor_route_server_client_cmd,
9ccf14f7 4257 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4258 NEIGHBOR_STR
4259 NEIGHBOR_ADDR_STR2
4260 "Configure a neighbor as Route Server client\n")
4261{
d62a17ae 4262 int idx_peer = 1;
4263 struct peer *peer;
2a3d5731 4264
d62a17ae 4265 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4266 if (!peer)
4267 return CMD_WARNING_CONFIG_FAILED;
4268 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4269 bgp_node_safi(vty),
4270 PEER_FLAG_RSERVER_CLIENT);
718e3744 4271}
4272
d62a17ae 4273ALIAS_HIDDEN(neighbor_route_server_client,
4274 neighbor_route_server_client_hidden_cmd,
4275 "neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4276 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4277 "Configure a neighbor as Route Server client\n")
596c17ba 4278
718e3744 4279DEFUN (no_neighbor_route_server_client,
4280 no_neighbor_route_server_client_cmd,
9ccf14f7 4281 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
718e3744 4282 NO_STR
4283 NEIGHBOR_STR
4284 NEIGHBOR_ADDR_STR2
4285 "Configure a neighbor as Route Server client\n")
fee0f4c6 4286{
d62a17ae 4287 int idx_peer = 2;
4288 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4289 bgp_node_afi(vty), bgp_node_safi(vty),
4290 PEER_FLAG_RSERVER_CLIENT);
fee0f4c6 4291}
6b0655a2 4292
d62a17ae 4293ALIAS_HIDDEN(no_neighbor_route_server_client,
4294 no_neighbor_route_server_client_hidden_cmd,
4295 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-server-client",
4296 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4297 "Configure a neighbor as Route Server client\n")
596c17ba 4298
fee0f4c6 4299DEFUN (neighbor_nexthop_local_unchanged,
4300 neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4301 "neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4302 NEIGHBOR_STR
4303 NEIGHBOR_ADDR_STR2
4304 "Configure treatment of outgoing link-local nexthop attribute\n"
4305 "Leave link-local nexthop unchanged for this peer\n")
4306{
d62a17ae 4307 int idx_peer = 1;
4308 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4309 bgp_node_safi(vty),
4310 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
fee0f4c6 4311}
6b0655a2 4312
fee0f4c6 4313DEFUN (no_neighbor_nexthop_local_unchanged,
4314 no_neighbor_nexthop_local_unchanged_cmd,
9ccf14f7 4315 "no neighbor <A.B.C.D|X:X::X:X|WORD> nexthop-local unchanged",
fee0f4c6 4316 NO_STR
4317 NEIGHBOR_STR
4318 NEIGHBOR_ADDR_STR2
4319 "Configure treatment of outgoing link-local-nexthop attribute\n"
4320 "Leave link-local nexthop unchanged for this peer\n")
718e3744 4321{
d62a17ae 4322 int idx_peer = 2;
4323 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
4324 bgp_node_afi(vty), bgp_node_safi(vty),
4325 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED);
718e3744 4326}
6b0655a2 4327
718e3744 4328DEFUN (neighbor_attr_unchanged,
4329 neighbor_attr_unchanged_cmd,
a8206004 4330 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
718e3744 4331 NEIGHBOR_STR
4332 NEIGHBOR_ADDR_STR2
4333 "BGP attribute is propagated unchanged to this neighbor\n"
4334 "As-path attribute\n"
4335 "Nexthop attribute\n"
a8206004 4336 "Med attribute\n")
718e3744 4337{
d62a17ae 4338 int idx = 0;
8eeb0335
DW
4339 char *peer_str = argv[1]->arg;
4340 struct peer *peer;
d62a17ae 4341 u_int16_t flags = 0;
8eeb0335
DW
4342 afi_t afi = bgp_node_afi(vty);
4343 safi_t safi = bgp_node_safi(vty);
4344
4345 peer = peer_and_group_lookup_vty(vty, peer_str);
4346 if (!peer)
4347 return CMD_WARNING_CONFIG_FAILED;
d62a17ae 4348
4349 if (argv_find(argv, argc, "as-path", &idx))
4350 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4351 idx = 0;
4352 if (argv_find(argv, argc, "next-hop", &idx))
4353 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4354 idx = 0;
4355 if (argv_find(argv, argc, "med", &idx))
4356 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4357
8eeb0335
DW
4358 /* no flags means all of them! */
4359 if (!flags) {
d62a17ae 4360 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4361 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4362 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
8eeb0335 4363 } else {
a4d82a8a
PZ
4364 if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED)
4365 && peer_af_flag_check(peer, afi, safi,
4366 PEER_FLAG_AS_PATH_UNCHANGED)) {
8eeb0335
DW
4367 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4368 PEER_FLAG_AS_PATH_UNCHANGED);
4369 }
4370
a4d82a8a
PZ
4371 if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED)
4372 && peer_af_flag_check(peer, afi, safi,
4373 PEER_FLAG_NEXTHOP_UNCHANGED)) {
8eeb0335
DW
4374 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4375 PEER_FLAG_NEXTHOP_UNCHANGED);
4376 }
4377
a4d82a8a
PZ
4378 if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED)
4379 && peer_af_flag_check(peer, afi, safi,
4380 PEER_FLAG_MED_UNCHANGED)) {
8eeb0335
DW
4381 peer_af_flag_unset_vty(vty, peer_str, afi, safi,
4382 PEER_FLAG_MED_UNCHANGED);
4383 }
d62a17ae 4384 }
4385
8eeb0335 4386 return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags);
d62a17ae 4387}
4388
4389ALIAS_HIDDEN(
4390 neighbor_attr_unchanged, neighbor_attr_unchanged_hidden_cmd,
4391 "neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4392 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4393 "BGP attribute is propagated unchanged to this neighbor\n"
4394 "As-path attribute\n"
4395 "Nexthop attribute\n"
4396 "Med attribute\n")
596c17ba 4397
718e3744 4398DEFUN (no_neighbor_attr_unchanged,
4399 no_neighbor_attr_unchanged_cmd,
a8206004 4400 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
e52702f2 4401 NO_STR
718e3744 4402 NEIGHBOR_STR
4403 NEIGHBOR_ADDR_STR2
31500417
DW
4404 "BGP attribute is propagated unchanged to this neighbor\n"
4405 "As-path attribute\n"
40e718b5 4406 "Nexthop attribute\n"
a8206004 4407 "Med attribute\n")
718e3744 4408{
d62a17ae 4409 int idx = 0;
4410 char *peer = argv[2]->arg;
4411 u_int16_t flags = 0;
4412
4413 if (argv_find(argv, argc, "as-path", &idx))
4414 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4415 idx = 0;
4416 if (argv_find(argv, argc, "next-hop", &idx))
4417 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4418 idx = 0;
4419 if (argv_find(argv, argc, "med", &idx))
4420 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4421
4422 if (!flags) // no flags means all of them!
4423 {
4424 SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED);
4425 SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED);
4426 SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED);
4427 }
4428
4429 return peer_af_flag_unset_vty(vty, peer, bgp_node_afi(vty),
4430 bgp_node_safi(vty), flags);
4431}
4432
4433ALIAS_HIDDEN(
4434 no_neighbor_attr_unchanged, no_neighbor_attr_unchanged_hidden_cmd,
4435 "no neighbor <A.B.C.D|X:X::X:X|WORD> attribute-unchanged [{as-path|next-hop|med}]",
4436 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4437 "BGP attribute is propagated unchanged to this neighbor\n"
4438 "As-path attribute\n"
4439 "Nexthop attribute\n"
4440 "Med attribute\n")
718e3744 4441
718e3744 4442/* EBGP multihop configuration. */
d62a17ae 4443static int peer_ebgp_multihop_set_vty(struct vty *vty, const char *ip_str,
4444 const char *ttl_str)
718e3744 4445{
d62a17ae 4446 struct peer *peer;
4447 unsigned int ttl;
718e3744 4448
d62a17ae 4449 peer = peer_and_group_lookup_vty(vty, ip_str);
4450 if (!peer)
4451 return CMD_WARNING_CONFIG_FAILED;
718e3744 4452
d62a17ae 4453 if (peer->conf_if)
4454 return bgp_vty_return(vty, BGP_ERR_INVALID_FOR_DIRECT_PEER);
63fa10b5 4455
d62a17ae 4456 if (!ttl_str)
4457 ttl = MAXTTL;
4458 else
4459 ttl = strtoul(ttl_str, NULL, 10);
718e3744 4460
d62a17ae 4461 return bgp_vty_return(vty, peer_ebgp_multihop_set(peer, ttl));
718e3744 4462}
4463
d62a17ae 4464static int peer_ebgp_multihop_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4465{
d62a17ae 4466 struct peer *peer;
718e3744 4467
d62a17ae 4468 peer = peer_and_group_lookup_vty(vty, ip_str);
4469 if (!peer)
4470 return CMD_WARNING_CONFIG_FAILED;
718e3744 4471
d62a17ae 4472 return bgp_vty_return(vty, peer_ebgp_multihop_unset(peer));
718e3744 4473}
4474
4475/* neighbor ebgp-multihop. */
4476DEFUN (neighbor_ebgp_multihop,
4477 neighbor_ebgp_multihop_cmd,
9ccf14f7 4478 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop",
718e3744 4479 NEIGHBOR_STR
4480 NEIGHBOR_ADDR_STR2
4481 "Allow EBGP neighbors not on directly connected networks\n")
4482{
d62a17ae 4483 int idx_peer = 1;
4484 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4485}
4486
4487DEFUN (neighbor_ebgp_multihop_ttl,
4488 neighbor_ebgp_multihop_ttl_cmd,
9ccf14f7 4489 "neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop (1-255)",
718e3744 4490 NEIGHBOR_STR
4491 NEIGHBOR_ADDR_STR2
4492 "Allow EBGP neighbors not on directly connected networks\n"
4493 "maximum hop count\n")
4494{
d62a17ae 4495 int idx_peer = 1;
4496 int idx_number = 3;
4497 return peer_ebgp_multihop_set_vty(vty, argv[idx_peer]->arg,
4498 argv[idx_number]->arg);
718e3744 4499}
4500
4501DEFUN (no_neighbor_ebgp_multihop,
4502 no_neighbor_ebgp_multihop_cmd,
a636c635 4503 "no neighbor <A.B.C.D|X:X::X:X|WORD> ebgp-multihop [(1-255)]",
718e3744 4504 NO_STR
4505 NEIGHBOR_STR
4506 NEIGHBOR_ADDR_STR2
a636c635
DW
4507 "Allow EBGP neighbors not on directly connected networks\n"
4508 "maximum hop count\n")
718e3744 4509{
d62a17ae 4510 int idx_peer = 2;
4511 return peer_ebgp_multihop_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4512}
4513
6b0655a2 4514
6ffd2079 4515/* disable-connected-check */
4516DEFUN (neighbor_disable_connected_check,
4517 neighbor_disable_connected_check_cmd,
7ebe625c 4518 "neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4519 NEIGHBOR_STR
7ebe625c 4520 NEIGHBOR_ADDR_STR2
a636c635
DW
4521 "one-hop away EBGP peer using loopback address\n"
4522 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4523{
d62a17ae 4524 int idx_peer = 1;
4525 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4526 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4527}
4528
4529DEFUN (no_neighbor_disable_connected_check,
4530 no_neighbor_disable_connected_check_cmd,
7ebe625c 4531 "no neighbor <A.B.C.D|X:X::X:X|WORD> <disable-connected-check|enforce-multihop>",
6ffd2079 4532 NO_STR
4533 NEIGHBOR_STR
7ebe625c 4534 NEIGHBOR_ADDR_STR2
a636c635
DW
4535 "one-hop away EBGP peer using loopback address\n"
4536 "Enforce EBGP neighbors perform multihop\n")
6ffd2079 4537{
d62a17ae 4538 int idx_peer = 2;
4539 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4540 PEER_FLAG_DISABLE_CONNECTED_CHECK);
6ffd2079 4541}
4542
718e3744 4543DEFUN (neighbor_description,
4544 neighbor_description_cmd,
e961923c 4545 "neighbor <A.B.C.D|X:X::X:X|WORD> description LINE...",
718e3744 4546 NEIGHBOR_STR
4547 NEIGHBOR_ADDR_STR2
4548 "Neighbor specific description\n"
4549 "Up to 80 characters describing this neighbor\n")
4550{
d62a17ae 4551 int idx_peer = 1;
4552 int idx_line = 3;
4553 struct peer *peer;
4554 char *str;
718e3744 4555
d62a17ae 4556 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4557 if (!peer)
4558 return CMD_WARNING_CONFIG_FAILED;
718e3744 4559
d62a17ae 4560 str = argv_concat(argv, argc, idx_line);
718e3744 4561
d62a17ae 4562 peer_description_set(peer, str);
718e3744 4563
d62a17ae 4564 XFREE(MTYPE_TMP, str);
718e3744 4565
d62a17ae 4566 return CMD_SUCCESS;
718e3744 4567}
4568
4569DEFUN (no_neighbor_description,
4570 no_neighbor_description_cmd,
a636c635 4571 "no neighbor <A.B.C.D|X:X::X:X|WORD> description [LINE]",
718e3744 4572 NO_STR
4573 NEIGHBOR_STR
4574 NEIGHBOR_ADDR_STR2
a636c635
DW
4575 "Neighbor specific description\n"
4576 "Up to 80 characters describing this neighbor\n")
718e3744 4577{
d62a17ae 4578 int idx_peer = 2;
4579 struct peer *peer;
718e3744 4580
d62a17ae 4581 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
4582 if (!peer)
4583 return CMD_WARNING_CONFIG_FAILED;
718e3744 4584
d62a17ae 4585 peer_description_unset(peer);
718e3744 4586
d62a17ae 4587 return CMD_SUCCESS;
718e3744 4588}
4589
6b0655a2 4590
718e3744 4591/* Neighbor update-source. */
d62a17ae 4592static int peer_update_source_vty(struct vty *vty, const char *peer_str,
4593 const char *source_str)
4594{
4595 struct peer *peer;
4596 struct prefix p;
4597
4598 peer = peer_and_group_lookup_vty(vty, peer_str);
4599 if (!peer)
4600 return CMD_WARNING_CONFIG_FAILED;
4601
4602 if (peer->conf_if)
4603 return CMD_WARNING;
4604
4605 if (source_str) {
4606 union sockunion su;
4607 int ret = str2sockunion(source_str, &su);
4608
4609 if (ret == 0)
4610 peer_update_source_addr_set(peer, &su);
4611 else {
4612 if (str2prefix(source_str, &p)) {
4613 vty_out(vty,
4614 "%% Invalid update-source, remove prefix length \n");
4615 return CMD_WARNING_CONFIG_FAILED;
4616 } else
4617 peer_update_source_if_set(peer, source_str);
4618 }
4619 } else
4620 peer_update_source_unset(peer);
4621
4622 return CMD_SUCCESS;
4623}
4624
4625#define BGP_UPDATE_SOURCE_HELP_STR \
4626 "IPv4 address\n" \
4627 "IPv6 address\n" \
4628 "Interface name (requires zebra to be running)\n"
369688c0 4629
718e3744 4630DEFUN (neighbor_update_source,
4631 neighbor_update_source_cmd,
9ccf14f7 4632 "neighbor <A.B.C.D|X:X::X:X|WORD> update-source <A.B.C.D|X:X::X:X|WORD>",
718e3744 4633 NEIGHBOR_STR
4634 NEIGHBOR_ADDR_STR2
4635 "Source of routing updates\n"
369688c0 4636 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4637{
d62a17ae 4638 int idx_peer = 1;
4639 int idx_peer_2 = 3;
4640 return peer_update_source_vty(vty, argv[idx_peer]->arg,
4641 argv[idx_peer_2]->arg);
718e3744 4642}
4643
4644DEFUN (no_neighbor_update_source,
4645 no_neighbor_update_source_cmd,
c7178fe7 4646 "no neighbor <A.B.C.D|X:X::X:X|WORD> update-source [<A.B.C.D|X:X::X:X|WORD>]",
718e3744 4647 NO_STR
4648 NEIGHBOR_STR
4649 NEIGHBOR_ADDR_STR2
dcb52bd5
DS
4650 "Source of routing updates\n"
4651 BGP_UPDATE_SOURCE_HELP_STR)
718e3744 4652{
d62a17ae 4653 int idx_peer = 2;
4654 return peer_update_source_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 4655}
6b0655a2 4656
d62a17ae 4657static int peer_default_originate_set_vty(struct vty *vty, const char *peer_str,
4658 afi_t afi, safi_t safi,
4659 const char *rmap, int set)
718e3744 4660{
d62a17ae 4661 int ret;
4662 struct peer *peer;
718e3744 4663
d62a17ae 4664 peer = peer_and_group_lookup_vty(vty, peer_str);
4665 if (!peer)
4666 return CMD_WARNING_CONFIG_FAILED;
718e3744 4667
d62a17ae 4668 if (set)
4669 ret = peer_default_originate_set(peer, afi, safi, rmap);
4670 else
4671 ret = peer_default_originate_unset(peer, afi, safi);
718e3744 4672
d62a17ae 4673 return bgp_vty_return(vty, ret);
718e3744 4674}
4675
4676/* neighbor default-originate. */
4677DEFUN (neighbor_default_originate,
4678 neighbor_default_originate_cmd,
9ccf14f7 4679 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
718e3744 4680 NEIGHBOR_STR
4681 NEIGHBOR_ADDR_STR2
4682 "Originate default route to this neighbor\n")
4683{
d62a17ae 4684 int idx_peer = 1;
4685 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4686 bgp_node_afi(vty),
4687 bgp_node_safi(vty), NULL, 1);
718e3744 4688}
4689
d62a17ae 4690ALIAS_HIDDEN(neighbor_default_originate, neighbor_default_originate_hidden_cmd,
4691 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate",
4692 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4693 "Originate default route to this neighbor\n")
596c17ba 4694
718e3744 4695DEFUN (neighbor_default_originate_rmap,
4696 neighbor_default_originate_rmap_cmd,
9ccf14f7 4697 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
718e3744 4698 NEIGHBOR_STR
4699 NEIGHBOR_ADDR_STR2
4700 "Originate default route to this neighbor\n"
4701 "Route-map to specify criteria to originate default\n"
4702 "route-map name\n")
4703{
d62a17ae 4704 int idx_peer = 1;
4705 int idx_word = 4;
4706 return peer_default_originate_set_vty(
4707 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
4708 argv[idx_word]->arg, 1);
718e3744 4709}
4710
d62a17ae 4711ALIAS_HIDDEN(
4712 neighbor_default_originate_rmap,
4713 neighbor_default_originate_rmap_hidden_cmd,
4714 "neighbor <A.B.C.D|X:X::X:X|WORD> default-originate route-map WORD",
4715 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4716 "Originate default route to this neighbor\n"
4717 "Route-map to specify criteria to originate default\n"
4718 "route-map name\n")
596c17ba 4719
718e3744 4720DEFUN (no_neighbor_default_originate,
4721 no_neighbor_default_originate_cmd,
a636c635 4722 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
718e3744 4723 NO_STR
4724 NEIGHBOR_STR
4725 NEIGHBOR_ADDR_STR2
a636c635
DW
4726 "Originate default route to this neighbor\n"
4727 "Route-map to specify criteria to originate default\n"
4728 "route-map name\n")
718e3744 4729{
d62a17ae 4730 int idx_peer = 2;
4731 return peer_default_originate_set_vty(vty, argv[idx_peer]->arg,
4732 bgp_node_afi(vty),
4733 bgp_node_safi(vty), NULL, 0);
718e3744 4734}
4735
d62a17ae 4736ALIAS_HIDDEN(
4737 no_neighbor_default_originate, no_neighbor_default_originate_hidden_cmd,
4738 "no neighbor <A.B.C.D|X:X::X:X|WORD> default-originate [route-map WORD]",
4739 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4740 "Originate default route to this neighbor\n"
4741 "Route-map to specify criteria to originate default\n"
4742 "route-map name\n")
596c17ba 4743
6b0655a2 4744
718e3744 4745/* Set neighbor's BGP port. */
d62a17ae 4746static int peer_port_vty(struct vty *vty, const char *ip_str, int afi,
4747 const char *port_str)
4748{
4749 struct peer *peer;
4750 u_int16_t port;
4751 struct servent *sp;
4752
4753 peer = peer_lookup_vty(vty, ip_str);
4754 if (!peer)
4755 return CMD_WARNING_CONFIG_FAILED;
4756
4757 if (!port_str) {
4758 sp = getservbyname("bgp", "tcp");
4759 port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port);
4760 } else {
4761 port = strtoul(port_str, NULL, 10);
4762 }
718e3744 4763
d62a17ae 4764 peer_port_set(peer, port);
718e3744 4765
d62a17ae 4766 return CMD_SUCCESS;
718e3744 4767}
4768
f418446b 4769/* Set specified peer's BGP port. */
718e3744 4770DEFUN (neighbor_port,
4771 neighbor_port_cmd,
9ccf14f7 4772 "neighbor <A.B.C.D|X:X::X:X> port (0-65535)",
718e3744 4773 NEIGHBOR_STR
4774 NEIGHBOR_ADDR_STR
4775 "Neighbor's BGP port\n"
4776 "TCP port number\n")
4777{
d62a17ae 4778 int idx_ip = 1;
4779 int idx_number = 3;
4780 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP,
4781 argv[idx_number]->arg);
718e3744 4782}
4783
4784DEFUN (no_neighbor_port,
4785 no_neighbor_port_cmd,
9ccf14f7 4786 "no neighbor <A.B.C.D|X:X::X:X> port [(0-65535)]",
718e3744 4787 NO_STR
4788 NEIGHBOR_STR
4789 NEIGHBOR_ADDR_STR
8334fd5a
DW
4790 "Neighbor's BGP port\n"
4791 "TCP port number\n")
718e3744 4792{
d62a17ae 4793 int idx_ip = 2;
4794 return peer_port_vty(vty, argv[idx_ip]->arg, AFI_IP, NULL);
718e3744 4795}
4796
6b0655a2 4797
718e3744 4798/* neighbor weight. */
d62a17ae 4799static int peer_weight_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
4800 safi_t safi, const char *weight_str)
718e3744 4801{
d62a17ae 4802 int ret;
4803 struct peer *peer;
4804 unsigned long weight;
718e3744 4805
d62a17ae 4806 peer = peer_and_group_lookup_vty(vty, ip_str);
4807 if (!peer)
4808 return CMD_WARNING_CONFIG_FAILED;
718e3744 4809
d62a17ae 4810 weight = strtoul(weight_str, NULL, 10);
718e3744 4811
d62a17ae 4812 ret = peer_weight_set(peer, afi, safi, weight);
4813 return bgp_vty_return(vty, ret);
718e3744 4814}
4815
d62a17ae 4816static int peer_weight_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
4817 safi_t safi)
718e3744 4818{
d62a17ae 4819 int ret;
4820 struct peer *peer;
718e3744 4821
d62a17ae 4822 peer = peer_and_group_lookup_vty(vty, ip_str);
4823 if (!peer)
4824 return CMD_WARNING_CONFIG_FAILED;
718e3744 4825
d62a17ae 4826 ret = peer_weight_unset(peer, afi, safi);
4827 return bgp_vty_return(vty, ret);
718e3744 4828}
4829
4830DEFUN (neighbor_weight,
4831 neighbor_weight_cmd,
9ccf14f7 4832 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
718e3744 4833 NEIGHBOR_STR
4834 NEIGHBOR_ADDR_STR2
4835 "Set default weight for routes from this neighbor\n"
4836 "default weight\n")
4837{
d62a17ae 4838 int idx_peer = 1;
4839 int idx_number = 3;
4840 return peer_weight_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
4841 bgp_node_safi(vty), argv[idx_number]->arg);
718e3744 4842}
4843
d62a17ae 4844ALIAS_HIDDEN(neighbor_weight, neighbor_weight_hidden_cmd,
4845 "neighbor <A.B.C.D|X:X::X:X|WORD> weight (0-65535)",
4846 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4847 "Set default weight for routes from this neighbor\n"
4848 "default weight\n")
596c17ba 4849
718e3744 4850DEFUN (no_neighbor_weight,
4851 no_neighbor_weight_cmd,
9ccf14f7 4852 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
718e3744 4853 NO_STR
4854 NEIGHBOR_STR
4855 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4856 "Set default weight for routes from this neighbor\n"
4857 "default weight\n")
718e3744 4858{
d62a17ae 4859 int idx_peer = 2;
4860 return peer_weight_unset_vty(vty, argv[idx_peer]->arg,
4861 bgp_node_afi(vty), bgp_node_safi(vty));
718e3744 4862}
4863
d62a17ae 4864ALIAS_HIDDEN(no_neighbor_weight, no_neighbor_weight_hidden_cmd,
4865 "no neighbor <A.B.C.D|X:X::X:X|WORD> weight [(0-65535)]",
4866 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
4867 "Set default weight for routes from this neighbor\n"
4868 "default weight\n")
596c17ba 4869
6b0655a2 4870
718e3744 4871/* Override capability negotiation. */
4872DEFUN (neighbor_override_capability,
4873 neighbor_override_capability_cmd,
9ccf14f7 4874 "neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4875 NEIGHBOR_STR
4876 NEIGHBOR_ADDR_STR2
4877 "Override capability negotiation result\n")
4878{
d62a17ae 4879 int idx_peer = 1;
4880 return peer_flag_set_vty(vty, argv[idx_peer]->arg,
4881 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4882}
4883
4884DEFUN (no_neighbor_override_capability,
4885 no_neighbor_override_capability_cmd,
9ccf14f7 4886 "no neighbor <A.B.C.D|X:X::X:X|WORD> override-capability",
718e3744 4887 NO_STR
4888 NEIGHBOR_STR
4889 NEIGHBOR_ADDR_STR2
4890 "Override capability negotiation result\n")
4891{
d62a17ae 4892 int idx_peer = 2;
4893 return peer_flag_unset_vty(vty, argv[idx_peer]->arg,
4894 PEER_FLAG_OVERRIDE_CAPABILITY);
718e3744 4895}
6b0655a2 4896
718e3744 4897DEFUN (neighbor_strict_capability,
4898 neighbor_strict_capability_cmd,
9ccf14f7 4899 "neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4900 NEIGHBOR_STR
4901 NEIGHBOR_ADDR_STR
4902 "Strict capability negotiation match\n")
4903{
d62a17ae 4904 int idx_ip = 1;
4905 return peer_flag_set_vty(vty, argv[idx_ip]->arg,
4906 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4907}
4908
4909DEFUN (no_neighbor_strict_capability,
4910 no_neighbor_strict_capability_cmd,
9ccf14f7 4911 "no neighbor <A.B.C.D|X:X::X:X> strict-capability-match",
718e3744 4912 NO_STR
4913 NEIGHBOR_STR
4914 NEIGHBOR_ADDR_STR
4915 "Strict capability negotiation match\n")
4916{
d62a17ae 4917 int idx_ip = 2;
4918 return peer_flag_unset_vty(vty, argv[idx_ip]->arg,
4919 PEER_FLAG_STRICT_CAP_MATCH);
718e3744 4920}
6b0655a2 4921
d62a17ae 4922static int peer_timers_set_vty(struct vty *vty, const char *ip_str,
4923 const char *keep_str, const char *hold_str)
718e3744 4924{
d62a17ae 4925 int ret;
4926 struct peer *peer;
4927 u_int32_t keepalive;
4928 u_int32_t holdtime;
718e3744 4929
d62a17ae 4930 peer = peer_and_group_lookup_vty(vty, ip_str);
4931 if (!peer)
4932 return CMD_WARNING_CONFIG_FAILED;
718e3744 4933
d62a17ae 4934 keepalive = strtoul(keep_str, NULL, 10);
4935 holdtime = strtoul(hold_str, NULL, 10);
718e3744 4936
d62a17ae 4937 ret = peer_timers_set(peer, keepalive, holdtime);
718e3744 4938
d62a17ae 4939 return bgp_vty_return(vty, ret);
718e3744 4940}
6b0655a2 4941
d62a17ae 4942static int peer_timers_unset_vty(struct vty *vty, const char *ip_str)
718e3744 4943{
d62a17ae 4944 int ret;
4945 struct peer *peer;
718e3744 4946
d62a17ae 4947 peer = peer_and_group_lookup_vty(vty, ip_str);
4948 if (!peer)
4949 return CMD_WARNING_CONFIG_FAILED;
718e3744 4950
d62a17ae 4951 ret = peer_timers_unset(peer);
718e3744 4952
d62a17ae 4953 return bgp_vty_return(vty, ret);
718e3744 4954}
4955
4956DEFUN (neighbor_timers,
4957 neighbor_timers_cmd,
9ccf14f7 4958 "neighbor <A.B.C.D|X:X::X:X|WORD> timers (0-65535) (0-65535)",
718e3744 4959 NEIGHBOR_STR
4960 NEIGHBOR_ADDR_STR2
4961 "BGP per neighbor timers\n"
4962 "Keepalive interval\n"
4963 "Holdtime\n")
4964{
d62a17ae 4965 int idx_peer = 1;
4966 int idx_number = 3;
4967 int idx_number_2 = 4;
4968 return peer_timers_set_vty(vty, argv[idx_peer]->arg,
4969 argv[idx_number]->arg,
4970 argv[idx_number_2]->arg);
718e3744 4971}
4972
4973DEFUN (no_neighbor_timers,
4974 no_neighbor_timers_cmd,
9ccf14f7 4975 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers [(0-65535) (0-65535)]",
718e3744 4976 NO_STR
4977 NEIGHBOR_STR
4978 NEIGHBOR_ADDR_STR2
8334fd5a
DW
4979 "BGP per neighbor timers\n"
4980 "Keepalive interval\n"
4981 "Holdtime\n")
718e3744 4982{
d62a17ae 4983 int idx_peer = 2;
4984 return peer_timers_unset_vty(vty, argv[idx_peer]->arg);
718e3744 4985}
6b0655a2 4986
813d4307 4987
d62a17ae 4988static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str,
4989 const char *time_str)
718e3744 4990{
d62a17ae 4991 int ret;
4992 struct peer *peer;
4993 u_int32_t connect;
718e3744 4994
d62a17ae 4995 peer = peer_and_group_lookup_vty(vty, ip_str);
4996 if (!peer)
4997 return CMD_WARNING_CONFIG_FAILED;
718e3744 4998
d62a17ae 4999 connect = strtoul(time_str, NULL, 10);
718e3744 5000
d62a17ae 5001 ret = peer_timers_connect_set(peer, connect);
718e3744 5002
d62a17ae 5003 return bgp_vty_return(vty, ret);
718e3744 5004}
5005
d62a17ae 5006static int peer_timers_connect_unset_vty(struct vty *vty, const char *ip_str)
718e3744 5007{
d62a17ae 5008 int ret;
5009 struct peer *peer;
718e3744 5010
d62a17ae 5011 peer = peer_and_group_lookup_vty(vty, ip_str);
5012 if (!peer)
5013 return CMD_WARNING_CONFIG_FAILED;
718e3744 5014
d62a17ae 5015 ret = peer_timers_connect_unset(peer);
718e3744 5016
d62a17ae 5017 return bgp_vty_return(vty, ret);
718e3744 5018}
5019
5020DEFUN (neighbor_timers_connect,
5021 neighbor_timers_connect_cmd,
9ccf14f7 5022 "neighbor <A.B.C.D|X:X::X:X|WORD> timers connect (1-65535)",
718e3744 5023 NEIGHBOR_STR
966f821c 5024 NEIGHBOR_ADDR_STR2
718e3744 5025 "BGP per neighbor timers\n"
5026 "BGP connect timer\n"
5027 "Connect timer\n")
5028{
d62a17ae 5029 int idx_peer = 1;
5030 int idx_number = 4;
5031 return peer_timers_connect_set_vty(vty, argv[idx_peer]->arg,
5032 argv[idx_number]->arg);
718e3744 5033}
5034
5035DEFUN (no_neighbor_timers_connect,
5036 no_neighbor_timers_connect_cmd,
9ccf14f7 5037 "no neighbor <A.B.C.D|X:X::X:X|WORD> timers connect [(1-65535)]",
718e3744 5038 NO_STR
5039 NEIGHBOR_STR
966f821c 5040 NEIGHBOR_ADDR_STR2
718e3744 5041 "BGP per neighbor timers\n"
8334fd5a
DW
5042 "BGP connect timer\n"
5043 "Connect timer\n")
718e3744 5044{
d62a17ae 5045 int idx_peer = 2;
5046 return peer_timers_connect_unset_vty(vty, argv[idx_peer]->arg);
718e3744 5047}
5048
6b0655a2 5049
d62a17ae 5050static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str,
5051 const char *time_str, int set)
718e3744 5052{
d62a17ae 5053 int ret;
5054 struct peer *peer;
5055 u_int32_t routeadv = 0;
718e3744 5056
d62a17ae 5057 peer = peer_and_group_lookup_vty(vty, ip_str);
5058 if (!peer)
5059 return CMD_WARNING_CONFIG_FAILED;
718e3744 5060
d62a17ae 5061 if (time_str)
5062 routeadv = strtoul(time_str, NULL, 10);
718e3744 5063
d62a17ae 5064 if (set)
5065 ret = peer_advertise_interval_set(peer, routeadv);
5066 else
5067 ret = peer_advertise_interval_unset(peer);
718e3744 5068
d62a17ae 5069 return bgp_vty_return(vty, ret);
718e3744 5070}
5071
5072DEFUN (neighbor_advertise_interval,
5073 neighbor_advertise_interval_cmd,
9ccf14f7 5074 "neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval (0-600)",
718e3744 5075 NEIGHBOR_STR
966f821c 5076 NEIGHBOR_ADDR_STR2
718e3744 5077 "Minimum interval between sending BGP routing updates\n"
5078 "time in seconds\n")
5079{
d62a17ae 5080 int idx_peer = 1;
5081 int idx_number = 3;
5082 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg,
5083 argv[idx_number]->arg, 1);
718e3744 5084}
5085
5086DEFUN (no_neighbor_advertise_interval,
5087 no_neighbor_advertise_interval_cmd,
9ccf14f7 5088 "no neighbor <A.B.C.D|X:X::X:X|WORD> advertisement-interval [(0-600)]",
718e3744 5089 NO_STR
5090 NEIGHBOR_STR
966f821c 5091 NEIGHBOR_ADDR_STR2
8334fd5a
DW
5092 "Minimum interval between sending BGP routing updates\n"
5093 "time in seconds\n")
718e3744 5094{
d62a17ae 5095 int idx_peer = 2;
5096 return peer_advertise_interval_vty(vty, argv[idx_peer]->arg, NULL, 0);
718e3744 5097}
5098
6b0655a2 5099
518f0eb1
DS
5100/* Time to wait before processing route-map updates */
5101DEFUN (bgp_set_route_map_delay_timer,
5102 bgp_set_route_map_delay_timer_cmd,
6147e2c6 5103 "bgp route-map delay-timer (0-600)",
518f0eb1
DS
5104 SET_STR
5105 "BGP route-map delay timer\n"
5106 "Time in secs to wait before processing route-map changes\n"
f414725f 5107 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5108{
d62a17ae 5109 int idx_number = 3;
5110 u_int32_t rmap_delay_timer;
5111
5112 if (argv[idx_number]->arg) {
5113 rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10);
5114 bm->rmap_update_timer = rmap_delay_timer;
5115
5116 /* if the dynamic update handling is being disabled, and a timer
5117 * is
5118 * running, stop the timer and act as if the timer has already
5119 * fired.
5120 */
5121 if (!rmap_delay_timer && bm->t_rmap_update) {
5122 BGP_TIMER_OFF(bm->t_rmap_update);
5123 thread_execute(bm->master, bgp_route_map_update_timer,
5124 NULL, 0);
5125 }
5126 return CMD_SUCCESS;
5127 } else {
5128 vty_out(vty, "%% BGP invalid route-map delay-timer\n");
5129 return CMD_WARNING_CONFIG_FAILED;
518f0eb1 5130 }
518f0eb1
DS
5131}
5132
5133DEFUN (no_bgp_set_route_map_delay_timer,
5134 no_bgp_set_route_map_delay_timer_cmd,
8334fd5a 5135 "no bgp route-map delay-timer [(0-600)]",
518f0eb1 5136 NO_STR
3a2d747c 5137 BGP_STR
518f0eb1 5138 "Default BGP route-map delay timer\n"
8334fd5a
DW
5139 "Reset to default time to wait for processing route-map changes\n"
5140 "0 disables the timer, no route updates happen when route-maps change\n")
518f0eb1 5141{
518f0eb1 5142
d62a17ae 5143 bm->rmap_update_timer = RMAP_DEFAULT_UPDATE_TIMER;
518f0eb1 5144
d62a17ae 5145 return CMD_SUCCESS;
518f0eb1
DS
5146}
5147
f414725f 5148
718e3744 5149/* neighbor interface */
d62a17ae 5150static int peer_interface_vty(struct vty *vty, const char *ip_str,
5151 const char *str)
718e3744 5152{
d62a17ae 5153 struct peer *peer;
718e3744 5154
d62a17ae 5155 peer = peer_lookup_vty(vty, ip_str);
5156 if (!peer || peer->conf_if) {
5157 vty_out(vty, "%% BGP invalid peer %s\n", ip_str);
5158 return CMD_WARNING_CONFIG_FAILED;
5159 }
718e3744 5160
d62a17ae 5161 if (str)
5162 peer_interface_set(peer, str);
5163 else
5164 peer_interface_unset(peer);
718e3744 5165
d62a17ae 5166 return CMD_SUCCESS;
718e3744 5167}
5168
5169DEFUN (neighbor_interface,
5170 neighbor_interface_cmd,
9ccf14f7 5171 "neighbor <A.B.C.D|X:X::X:X> interface WORD",
718e3744 5172 NEIGHBOR_STR
5173 NEIGHBOR_ADDR_STR
5174 "Interface\n"
5175 "Interface name\n")
5176{
d62a17ae 5177 int idx_ip = 1;
5178 int idx_word = 3;
5179 return peer_interface_vty(vty, argv[idx_ip]->arg, argv[idx_word]->arg);
718e3744 5180}
5181
5182DEFUN (no_neighbor_interface,
5183 no_neighbor_interface_cmd,
9ccf14f7 5184 "no neighbor <A.B.C.D|X:X::X:X|WORD> interface WORD",
718e3744 5185 NO_STR
5186 NEIGHBOR_STR
16cedbb0 5187 NEIGHBOR_ADDR_STR2
718e3744 5188 "Interface\n"
5189 "Interface name\n")
5190{
d62a17ae 5191 int idx_peer = 2;
5192 return peer_interface_vty(vty, argv[idx_peer]->arg, NULL);
718e3744 5193}
6b0655a2 5194
718e3744 5195DEFUN (neighbor_distribute_list,
5196 neighbor_distribute_list_cmd,
9ccf14f7 5197 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5198 NEIGHBOR_STR
5199 NEIGHBOR_ADDR_STR2
5200 "Filter updates to/from this neighbor\n"
5201 "IP access-list number\n"
5202 "IP access-list number (expanded range)\n"
5203 "IP Access-list name\n"
5204 "Filter incoming updates\n"
5205 "Filter outgoing updates\n")
5206{
d62a17ae 5207 int idx_peer = 1;
5208 int idx_acl = 3;
5209 int direct, ret;
5210 struct peer *peer;
a8206004 5211
d62a17ae 5212 const char *pstr = argv[idx_peer]->arg;
5213 const char *acl = argv[idx_acl]->arg;
5214 const char *inout = argv[argc - 1]->text;
a8206004 5215
d62a17ae 5216 peer = peer_and_group_lookup_vty(vty, pstr);
5217 if (!peer)
5218 return CMD_WARNING_CONFIG_FAILED;
a8206004 5219
d62a17ae 5220 /* Check filter direction. */
5221 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5222 ret = peer_distribute_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5223 direct, acl);
a8206004 5224
d62a17ae 5225 return bgp_vty_return(vty, ret);
718e3744 5226}
5227
d62a17ae 5228ALIAS_HIDDEN(
5229 neighbor_distribute_list, neighbor_distribute_list_hidden_cmd,
5230 "neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5231 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5232 "Filter updates to/from this neighbor\n"
5233 "IP access-list number\n"
5234 "IP access-list number (expanded range)\n"
5235 "IP Access-list name\n"
5236 "Filter incoming updates\n"
5237 "Filter outgoing updates\n")
596c17ba 5238
718e3744 5239DEFUN (no_neighbor_distribute_list,
5240 no_neighbor_distribute_list_cmd,
9ccf14f7 5241 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
718e3744 5242 NO_STR
5243 NEIGHBOR_STR
5244 NEIGHBOR_ADDR_STR2
5245 "Filter updates to/from this neighbor\n"
5246 "IP access-list number\n"
5247 "IP access-list number (expanded range)\n"
5248 "IP Access-list name\n"
5249 "Filter incoming updates\n"
5250 "Filter outgoing updates\n")
5251{
d62a17ae 5252 int idx_peer = 2;
5253 int direct, ret;
5254 struct peer *peer;
a8206004 5255
d62a17ae 5256 const char *pstr = argv[idx_peer]->arg;
5257 const char *inout = argv[argc - 1]->text;
a8206004 5258
d62a17ae 5259 peer = peer_and_group_lookup_vty(vty, pstr);
5260 if (!peer)
5261 return CMD_WARNING_CONFIG_FAILED;
a8206004 5262
d62a17ae 5263 /* Check filter direction. */
5264 direct = strmatch(inout, "in") ? FILTER_IN : FILTER_OUT;
5265 ret = peer_distribute_unset(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5266 direct);
a8206004 5267
d62a17ae 5268 return bgp_vty_return(vty, ret);
718e3744 5269}
6b0655a2 5270
d62a17ae 5271ALIAS_HIDDEN(
5272 no_neighbor_distribute_list, no_neighbor_distribute_list_hidden_cmd,
5273 "no neighbor <A.B.C.D|X:X::X:X|WORD> distribute-list <(1-199)|(1300-2699)|WORD> <in|out>",
5274 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5275 "Filter updates to/from this neighbor\n"
5276 "IP access-list number\n"
5277 "IP access-list number (expanded range)\n"
5278 "IP Access-list name\n"
5279 "Filter incoming updates\n"
5280 "Filter outgoing updates\n")
596c17ba 5281
718e3744 5282/* Set prefix list to the peer. */
d62a17ae 5283static int peer_prefix_list_set_vty(struct vty *vty, const char *ip_str,
5284 afi_t afi, safi_t safi,
5285 const char *name_str,
5286 const char *direct_str)
718e3744 5287{
d62a17ae 5288 int ret;
5289 struct peer *peer;
5290 int direct = FILTER_IN;
718e3744 5291
d62a17ae 5292 peer = peer_and_group_lookup_vty(vty, ip_str);
5293 if (!peer)
5294 return CMD_WARNING_CONFIG_FAILED;
718e3744 5295
d62a17ae 5296 /* Check filter direction. */
5297 if (strncmp(direct_str, "i", 1) == 0)
5298 direct = FILTER_IN;
5299 else if (strncmp(direct_str, "o", 1) == 0)
5300 direct = FILTER_OUT;
718e3744 5301
d62a17ae 5302 ret = peer_prefix_list_set(peer, afi, safi, direct, name_str);
718e3744 5303
d62a17ae 5304 return bgp_vty_return(vty, ret);
718e3744 5305}
5306
d62a17ae 5307static int peer_prefix_list_unset_vty(struct vty *vty, const char *ip_str,
5308 afi_t afi, safi_t safi,
5309 const char *direct_str)
718e3744 5310{
d62a17ae 5311 int ret;
5312 struct peer *peer;
5313 int direct = FILTER_IN;
718e3744 5314
d62a17ae 5315 peer = peer_and_group_lookup_vty(vty, ip_str);
5316 if (!peer)
5317 return CMD_WARNING_CONFIG_FAILED;
e52702f2 5318
d62a17ae 5319 /* Check filter direction. */
5320 if (strncmp(direct_str, "i", 1) == 0)
5321 direct = FILTER_IN;
5322 else if (strncmp(direct_str, "o", 1) == 0)
5323 direct = FILTER_OUT;
718e3744 5324
d62a17ae 5325 ret = peer_prefix_list_unset(peer, afi, safi, direct);
718e3744 5326
d62a17ae 5327 return bgp_vty_return(vty, ret);
718e3744 5328}
5329
5330DEFUN (neighbor_prefix_list,
5331 neighbor_prefix_list_cmd,
9ccf14f7 5332 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5333 NEIGHBOR_STR
5334 NEIGHBOR_ADDR_STR2
5335 "Filter updates to/from this neighbor\n"
5336 "Name of a prefix list\n"
5337 "Filter incoming updates\n"
5338 "Filter outgoing updates\n")
5339{
d62a17ae 5340 int idx_peer = 1;
5341 int idx_word = 3;
5342 int idx_in_out = 4;
5343 return peer_prefix_list_set_vty(
5344 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5345 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5346}
5347
d62a17ae 5348ALIAS_HIDDEN(neighbor_prefix_list, neighbor_prefix_list_hidden_cmd,
5349 "neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5350 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5351 "Filter updates to/from this neighbor\n"
5352 "Name of a prefix list\n"
5353 "Filter incoming updates\n"
5354 "Filter outgoing updates\n")
596c17ba 5355
718e3744 5356DEFUN (no_neighbor_prefix_list,
5357 no_neighbor_prefix_list_cmd,
9ccf14f7 5358 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
718e3744 5359 NO_STR
5360 NEIGHBOR_STR
5361 NEIGHBOR_ADDR_STR2
5362 "Filter updates to/from this neighbor\n"
5363 "Name of a prefix list\n"
5364 "Filter incoming updates\n"
5365 "Filter outgoing updates\n")
5366{
d62a17ae 5367 int idx_peer = 2;
5368 int idx_in_out = 5;
5369 return peer_prefix_list_unset_vty(vty, argv[idx_peer]->arg,
5370 bgp_node_afi(vty), bgp_node_safi(vty),
5371 argv[idx_in_out]->arg);
718e3744 5372}
6b0655a2 5373
d62a17ae 5374ALIAS_HIDDEN(no_neighbor_prefix_list, no_neighbor_prefix_list_hidden_cmd,
5375 "no neighbor <A.B.C.D|X:X::X:X|WORD> prefix-list WORD <in|out>",
5376 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5377 "Filter updates to/from this neighbor\n"
5378 "Name of a prefix list\n"
5379 "Filter incoming updates\n"
5380 "Filter outgoing updates\n")
596c17ba 5381
d62a17ae 5382static int peer_aslist_set_vty(struct vty *vty, const char *ip_str, afi_t afi,
5383 safi_t safi, const char *name_str,
5384 const char *direct_str)
718e3744 5385{
d62a17ae 5386 int ret;
5387 struct peer *peer;
5388 int direct = FILTER_IN;
718e3744 5389
d62a17ae 5390 peer = peer_and_group_lookup_vty(vty, ip_str);
5391 if (!peer)
5392 return CMD_WARNING_CONFIG_FAILED;
718e3744 5393
d62a17ae 5394 /* Check filter direction. */
5395 if (strncmp(direct_str, "i", 1) == 0)
5396 direct = FILTER_IN;
5397 else if (strncmp(direct_str, "o", 1) == 0)
5398 direct = FILTER_OUT;
718e3744 5399
d62a17ae 5400 ret = peer_aslist_set(peer, afi, safi, direct, name_str);
718e3744 5401
d62a17ae 5402 return bgp_vty_return(vty, ret);
718e3744 5403}
5404
d62a17ae 5405static int peer_aslist_unset_vty(struct vty *vty, const char *ip_str, afi_t afi,
5406 safi_t safi, const char *direct_str)
718e3744 5407{
d62a17ae 5408 int ret;
5409 struct peer *peer;
5410 int direct = FILTER_IN;
718e3744 5411
d62a17ae 5412 peer = peer_and_group_lookup_vty(vty, ip_str);
5413 if (!peer)
5414 return CMD_WARNING_CONFIG_FAILED;
718e3744 5415
d62a17ae 5416 /* Check filter direction. */
5417 if (strncmp(direct_str, "i", 1) == 0)
5418 direct = FILTER_IN;
5419 else if (strncmp(direct_str, "o", 1) == 0)
5420 direct = FILTER_OUT;
718e3744 5421
d62a17ae 5422 ret = peer_aslist_unset(peer, afi, safi, direct);
718e3744 5423
d62a17ae 5424 return bgp_vty_return(vty, ret);
718e3744 5425}
5426
5427DEFUN (neighbor_filter_list,
5428 neighbor_filter_list_cmd,
9ccf14f7 5429 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5430 NEIGHBOR_STR
5431 NEIGHBOR_ADDR_STR2
5432 "Establish BGP filters\n"
5433 "AS path access-list name\n"
5434 "Filter incoming routes\n"
5435 "Filter outgoing routes\n")
5436{
d62a17ae 5437 int idx_peer = 1;
5438 int idx_word = 3;
5439 int idx_in_out = 4;
5440 return peer_aslist_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
5441 bgp_node_safi(vty), argv[idx_word]->arg,
5442 argv[idx_in_out]->arg);
718e3744 5443}
5444
d62a17ae 5445ALIAS_HIDDEN(neighbor_filter_list, neighbor_filter_list_hidden_cmd,
5446 "neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5447 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5448 "Establish BGP filters\n"
5449 "AS path access-list name\n"
5450 "Filter incoming routes\n"
5451 "Filter outgoing routes\n")
596c17ba 5452
718e3744 5453DEFUN (no_neighbor_filter_list,
5454 no_neighbor_filter_list_cmd,
9ccf14f7 5455 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
718e3744 5456 NO_STR
5457 NEIGHBOR_STR
5458 NEIGHBOR_ADDR_STR2
5459 "Establish BGP filters\n"
5460 "AS path access-list name\n"
5461 "Filter incoming routes\n"
5462 "Filter outgoing routes\n")
5463{
d62a17ae 5464 int idx_peer = 2;
5465 int idx_in_out = 5;
5466 return peer_aslist_unset_vty(vty, argv[idx_peer]->arg,
5467 bgp_node_afi(vty), bgp_node_safi(vty),
5468 argv[idx_in_out]->arg);
718e3744 5469}
6b0655a2 5470
d62a17ae 5471ALIAS_HIDDEN(no_neighbor_filter_list, no_neighbor_filter_list_hidden_cmd,
5472 "no neighbor <A.B.C.D|X:X::X:X|WORD> filter-list WORD <in|out>",
5473 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5474 "Establish BGP filters\n"
5475 "AS path access-list name\n"
5476 "Filter incoming routes\n"
5477 "Filter outgoing routes\n")
596c17ba 5478
718e3744 5479/* Set route-map to the peer. */
d62a17ae 5480static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
5481 afi_t afi, safi_t safi, const char *name_str,
5482 const char *direct_str)
718e3744 5483{
d62a17ae 5484 int ret;
5485 struct peer *peer;
5486 int direct = RMAP_IN;
718e3744 5487
d62a17ae 5488 peer = peer_and_group_lookup_vty(vty, ip_str);
5489 if (!peer)
5490 return CMD_WARNING_CONFIG_FAILED;
718e3744 5491
d62a17ae 5492 /* Check filter direction. */
5493 if (strncmp(direct_str, "in", 2) == 0)
5494 direct = RMAP_IN;
5495 else if (strncmp(direct_str, "o", 1) == 0)
5496 direct = RMAP_OUT;
718e3744 5497
d62a17ae 5498 ret = peer_route_map_set(peer, afi, safi, direct, name_str);
718e3744 5499
d62a17ae 5500 return bgp_vty_return(vty, ret);
718e3744 5501}
5502
d62a17ae 5503static int peer_route_map_unset_vty(struct vty *vty, const char *ip_str,
5504 afi_t afi, safi_t safi,
5505 const char *direct_str)
718e3744 5506{
d62a17ae 5507 int ret;
5508 struct peer *peer;
5509 int direct = RMAP_IN;
718e3744 5510
d62a17ae 5511 peer = peer_and_group_lookup_vty(vty, ip_str);
5512 if (!peer)
5513 return CMD_WARNING_CONFIG_FAILED;
718e3744 5514
d62a17ae 5515 /* Check filter direction. */
5516 if (strncmp(direct_str, "in", 2) == 0)
5517 direct = RMAP_IN;
5518 else if (strncmp(direct_str, "o", 1) == 0)
5519 direct = RMAP_OUT;
718e3744 5520
d62a17ae 5521 ret = peer_route_map_unset(peer, afi, safi, direct);
718e3744 5522
d62a17ae 5523 return bgp_vty_return(vty, ret);
718e3744 5524}
5525
5526DEFUN (neighbor_route_map,
5527 neighbor_route_map_cmd,
9ccf14f7 5528 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5529 NEIGHBOR_STR
5530 NEIGHBOR_ADDR_STR2
5531 "Apply route map to neighbor\n"
5532 "Name of route map\n"
5533 "Apply map to incoming routes\n"
2a3d5731 5534 "Apply map to outbound routes\n")
718e3744 5535{
d62a17ae 5536 int idx_peer = 1;
5537 int idx_word = 3;
5538 int idx_in_out = 4;
5539 return peer_route_map_set_vty(
5540 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5541 argv[idx_word]->arg, argv[idx_in_out]->arg);
718e3744 5542}
5543
d62a17ae 5544ALIAS_HIDDEN(neighbor_route_map, neighbor_route_map_hidden_cmd,
5545 "neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5546 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5547 "Apply route map to neighbor\n"
5548 "Name of route map\n"
5549 "Apply map to incoming routes\n"
5550 "Apply map to outbound routes\n")
596c17ba 5551
718e3744 5552DEFUN (no_neighbor_route_map,
5553 no_neighbor_route_map_cmd,
9ccf14f7 5554 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
718e3744 5555 NO_STR
5556 NEIGHBOR_STR
5557 NEIGHBOR_ADDR_STR2
5558 "Apply route map to neighbor\n"
5559 "Name of route map\n"
5560 "Apply map to incoming routes\n"
2a3d5731 5561 "Apply map to outbound routes\n")
718e3744 5562{
d62a17ae 5563 int idx_peer = 2;
5564 int idx_in_out = 5;
5565 return peer_route_map_unset_vty(vty, argv[idx_peer]->arg,
5566 bgp_node_afi(vty), bgp_node_safi(vty),
5567 argv[idx_in_out]->arg);
718e3744 5568}
6b0655a2 5569
d62a17ae 5570ALIAS_HIDDEN(no_neighbor_route_map, no_neighbor_route_map_hidden_cmd,
5571 "no neighbor <A.B.C.D|X:X::X:X|WORD> route-map WORD <in|out>",
5572 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5573 "Apply route map to neighbor\n"
5574 "Name of route map\n"
5575 "Apply map to incoming routes\n"
5576 "Apply map to outbound routes\n")
596c17ba 5577
718e3744 5578/* Set unsuppress-map to the peer. */
d62a17ae 5579static int peer_unsuppress_map_set_vty(struct vty *vty, const char *ip_str,
5580 afi_t afi, safi_t safi,
5581 const char *name_str)
718e3744 5582{
d62a17ae 5583 int ret;
5584 struct peer *peer;
718e3744 5585
d62a17ae 5586 peer = peer_and_group_lookup_vty(vty, ip_str);
5587 if (!peer)
5588 return CMD_WARNING_CONFIG_FAILED;
718e3744 5589
d62a17ae 5590 ret = peer_unsuppress_map_set(peer, afi, safi, name_str);
718e3744 5591
d62a17ae 5592 return bgp_vty_return(vty, ret);
718e3744 5593}
5594
5595/* Unset route-map from the peer. */
d62a17ae 5596static int peer_unsuppress_map_unset_vty(struct vty *vty, const char *ip_str,
5597 afi_t afi, safi_t safi)
718e3744 5598{
d62a17ae 5599 int ret;
5600 struct peer *peer;
718e3744 5601
d62a17ae 5602 peer = peer_and_group_lookup_vty(vty, ip_str);
5603 if (!peer)
5604 return CMD_WARNING_CONFIG_FAILED;
718e3744 5605
d62a17ae 5606 ret = peer_unsuppress_map_unset(peer, afi, safi);
718e3744 5607
d62a17ae 5608 return bgp_vty_return(vty, ret);
718e3744 5609}
5610
5611DEFUN (neighbor_unsuppress_map,
5612 neighbor_unsuppress_map_cmd,
9ccf14f7 5613 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5614 NEIGHBOR_STR
5615 NEIGHBOR_ADDR_STR2
5616 "Route-map to selectively unsuppress suppressed routes\n"
5617 "Name of route map\n")
5618{
d62a17ae 5619 int idx_peer = 1;
5620 int idx_word = 3;
5621 return peer_unsuppress_map_set_vty(
5622 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5623 argv[idx_word]->arg);
718e3744 5624}
5625
d62a17ae 5626ALIAS_HIDDEN(neighbor_unsuppress_map, neighbor_unsuppress_map_hidden_cmd,
5627 "neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5628 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5629 "Route-map to selectively unsuppress suppressed routes\n"
5630 "Name of route map\n")
596c17ba 5631
718e3744 5632DEFUN (no_neighbor_unsuppress_map,
5633 no_neighbor_unsuppress_map_cmd,
9ccf14f7 5634 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
718e3744 5635 NO_STR
5636 NEIGHBOR_STR
5637 NEIGHBOR_ADDR_STR2
5638 "Route-map to selectively unsuppress suppressed routes\n"
5639 "Name of route map\n")
5640{
d62a17ae 5641 int idx_peer = 2;
5642 return peer_unsuppress_map_unset_vty(vty, argv[idx_peer]->arg,
5643 bgp_node_afi(vty),
5644 bgp_node_safi(vty));
718e3744 5645}
6b0655a2 5646
d62a17ae 5647ALIAS_HIDDEN(no_neighbor_unsuppress_map, no_neighbor_unsuppress_map_hidden_cmd,
5648 "no neighbor <A.B.C.D|X:X::X:X|WORD> unsuppress-map WORD",
5649 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5650 "Route-map to selectively unsuppress suppressed routes\n"
5651 "Name of route map\n")
596c17ba 5652
d62a17ae 5653static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str,
5654 afi_t afi, safi_t safi,
5655 const char *num_str,
5656 const char *threshold_str, int warning,
5657 const char *restart_str)
718e3744 5658{
d62a17ae 5659 int ret;
5660 struct peer *peer;
5661 u_int32_t max;
5662 u_char threshold;
5663 u_int16_t restart;
718e3744 5664
d62a17ae 5665 peer = peer_and_group_lookup_vty(vty, ip_str);
5666 if (!peer)
5667 return CMD_WARNING_CONFIG_FAILED;
718e3744 5668
d62a17ae 5669 max = strtoul(num_str, NULL, 10);
5670 if (threshold_str)
5671 threshold = atoi(threshold_str);
5672 else
5673 threshold = MAXIMUM_PREFIX_THRESHOLD_DEFAULT;
718e3744 5674
d62a17ae 5675 if (restart_str)
5676 restart = atoi(restart_str);
5677 else
5678 restart = 0;
0a486e5f 5679
d62a17ae 5680 ret = peer_maximum_prefix_set(peer, afi, safi, max, threshold, warning,
5681 restart);
718e3744 5682
d62a17ae 5683 return bgp_vty_return(vty, ret);
718e3744 5684}
5685
d62a17ae 5686static int peer_maximum_prefix_unset_vty(struct vty *vty, const char *ip_str,
5687 afi_t afi, safi_t safi)
718e3744 5688{
d62a17ae 5689 int ret;
5690 struct peer *peer;
718e3744 5691
d62a17ae 5692 peer = peer_and_group_lookup_vty(vty, ip_str);
5693 if (!peer)
5694 return CMD_WARNING_CONFIG_FAILED;
718e3744 5695
d62a17ae 5696 ret = peer_maximum_prefix_unset(peer, afi, safi);
718e3744 5697
d62a17ae 5698 return bgp_vty_return(vty, ret);
718e3744 5699}
5700
5701/* Maximum number of prefix configuration. prefix count is different
5702 for each peer configuration. So this configuration can be set for
5703 each peer configuration. */
5704DEFUN (neighbor_maximum_prefix,
5705 neighbor_maximum_prefix_cmd,
9ccf14f7 5706 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
718e3744 5707 NEIGHBOR_STR
5708 NEIGHBOR_ADDR_STR2
5709 "Maximum number of prefix accept from this peer\n"
5710 "maximum no. of prefix limit\n")
5711{
d62a17ae 5712 int idx_peer = 1;
5713 int idx_number = 3;
5714 return peer_maximum_prefix_set_vty(
5715 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5716 argv[idx_number]->arg, NULL, 0, NULL);
718e3744 5717}
5718
d62a17ae 5719ALIAS_HIDDEN(neighbor_maximum_prefix, neighbor_maximum_prefix_hidden_cmd,
5720 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295)",
5721 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5722 "Maximum number of prefix accept from this peer\n"
5723 "maximum no. of prefix limit\n")
596c17ba 5724
e0701b79 5725DEFUN (neighbor_maximum_prefix_threshold,
5726 neighbor_maximum_prefix_threshold_cmd,
9ccf14f7 5727 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
e0701b79 5728 NEIGHBOR_STR
5729 NEIGHBOR_ADDR_STR2
5730 "Maximum number of prefix accept from this peer\n"
5731 "maximum no. of prefix limit\n"
5732 "Threshold value (%) at which to generate a warning msg\n")
5733{
d62a17ae 5734 int idx_peer = 1;
5735 int idx_number = 3;
5736 int idx_number_2 = 4;
5737 return peer_maximum_prefix_set_vty(
5738 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5739 argv[idx_number]->arg, argv[idx_number_2]->arg, 0, NULL);
0a486e5f 5740}
e0701b79 5741
d62a17ae 5742ALIAS_HIDDEN(
5743 neighbor_maximum_prefix_threshold,
5744 neighbor_maximum_prefix_threshold_hidden_cmd,
5745 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100)",
5746 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5747 "Maximum number of prefix accept from this peer\n"
5748 "maximum no. of prefix limit\n"
5749 "Threshold value (%) at which to generate a warning msg\n")
596c17ba 5750
718e3744 5751DEFUN (neighbor_maximum_prefix_warning,
5752 neighbor_maximum_prefix_warning_cmd,
9ccf14f7 5753 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
718e3744 5754 NEIGHBOR_STR
5755 NEIGHBOR_ADDR_STR2
5756 "Maximum number of prefix accept from this peer\n"
5757 "maximum no. of prefix limit\n"
5758 "Only give warning message when limit is exceeded\n")
5759{
d62a17ae 5760 int idx_peer = 1;
5761 int idx_number = 3;
5762 return peer_maximum_prefix_set_vty(
5763 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5764 argv[idx_number]->arg, NULL, 1, NULL);
718e3744 5765}
5766
d62a17ae 5767ALIAS_HIDDEN(
5768 neighbor_maximum_prefix_warning,
5769 neighbor_maximum_prefix_warning_hidden_cmd,
5770 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) warning-only",
5771 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5772 "Maximum number of prefix accept from this peer\n"
5773 "maximum no. of prefix limit\n"
5774 "Only give warning message when limit is exceeded\n")
596c17ba 5775
e0701b79 5776DEFUN (neighbor_maximum_prefix_threshold_warning,
5777 neighbor_maximum_prefix_threshold_warning_cmd,
9ccf14f7 5778 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
e0701b79 5779 NEIGHBOR_STR
5780 NEIGHBOR_ADDR_STR2
5781 "Maximum number of prefix accept from this peer\n"
5782 "maximum no. of prefix limit\n"
5783 "Threshold value (%) at which to generate a warning msg\n"
5784 "Only give warning message when limit is exceeded\n")
5785{
d62a17ae 5786 int idx_peer = 1;
5787 int idx_number = 3;
5788 int idx_number_2 = 4;
5789 return peer_maximum_prefix_set_vty(
5790 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5791 argv[idx_number]->arg, argv[idx_number_2]->arg, 1, NULL);
0a486e5f 5792}
5793
d62a17ae 5794ALIAS_HIDDEN(
5795 neighbor_maximum_prefix_threshold_warning,
5796 neighbor_maximum_prefix_threshold_warning_hidden_cmd,
5797 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) warning-only",
5798 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5799 "Maximum number of prefix accept from this peer\n"
5800 "maximum no. of prefix limit\n"
5801 "Threshold value (%) at which to generate a warning msg\n"
5802 "Only give warning message when limit is exceeded\n")
596c17ba 5803
0a486e5f 5804DEFUN (neighbor_maximum_prefix_restart,
5805 neighbor_maximum_prefix_restart_cmd,
9ccf14f7 5806 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
0a486e5f 5807 NEIGHBOR_STR
5808 NEIGHBOR_ADDR_STR2
5809 "Maximum number of prefix accept from this peer\n"
5810 "maximum no. of prefix limit\n"
5811 "Restart bgp connection after limit is exceeded\n"
efd7904e 5812 "Restart interval in minutes\n")
0a486e5f 5813{
d62a17ae 5814 int idx_peer = 1;
5815 int idx_number = 3;
5816 int idx_number_2 = 5;
5817 return peer_maximum_prefix_set_vty(
5818 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5819 argv[idx_number]->arg, NULL, 0, argv[idx_number_2]->arg);
0a486e5f 5820}
5821
d62a17ae 5822ALIAS_HIDDEN(
5823 neighbor_maximum_prefix_restart,
5824 neighbor_maximum_prefix_restart_hidden_cmd,
5825 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) restart (1-65535)",
5826 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5827 "Maximum number of prefix accept from this peer\n"
5828 "maximum no. of prefix limit\n"
5829 "Restart bgp connection after limit is exceeded\n"
efd7904e 5830 "Restart interval in minutes\n")
596c17ba 5831
0a486e5f 5832DEFUN (neighbor_maximum_prefix_threshold_restart,
5833 neighbor_maximum_prefix_threshold_restart_cmd,
9ccf14f7 5834 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
0a486e5f 5835 NEIGHBOR_STR
5836 NEIGHBOR_ADDR_STR2
16cedbb0 5837 "Maximum number of prefixes to accept from this peer\n"
0a486e5f 5838 "maximum no. of prefix limit\n"
5839 "Threshold value (%) at which to generate a warning msg\n"
5840 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5841 "Restart interval in minutes\n")
0a486e5f 5842{
d62a17ae 5843 int idx_peer = 1;
5844 int idx_number = 3;
5845 int idx_number_2 = 4;
5846 int idx_number_3 = 6;
5847 return peer_maximum_prefix_set_vty(
5848 vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
5849 argv[idx_number]->arg, argv[idx_number_2]->arg, 0,
5850 argv[idx_number_3]->arg);
5851}
5852
5853ALIAS_HIDDEN(
5854 neighbor_maximum_prefix_threshold_restart,
5855 neighbor_maximum_prefix_threshold_restart_hidden_cmd,
5856 "neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix (1-4294967295) (1-100) restart (1-65535)",
5857 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5858 "Maximum number of prefixes to accept from this peer\n"
5859 "maximum no. of prefix limit\n"
5860 "Threshold value (%) at which to generate a warning msg\n"
5861 "Restart bgp connection after limit is exceeded\n"
5862 "Restart interval in minutes\n")
596c17ba 5863
718e3744 5864DEFUN (no_neighbor_maximum_prefix,
5865 no_neighbor_maximum_prefix_cmd,
d04c479d 5866 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
718e3744 5867 NO_STR
5868 NEIGHBOR_STR
5869 NEIGHBOR_ADDR_STR2
16cedbb0 5870 "Maximum number of prefixes to accept from this peer\n"
31500417
DW
5871 "maximum no. of prefix limit\n"
5872 "Threshold value (%) at which to generate a warning msg\n"
5873 "Restart bgp connection after limit is exceeded\n"
16cedbb0 5874 "Restart interval in minutes\n"
31500417 5875 "Only give warning message when limit is exceeded\n")
718e3744 5876{
d62a17ae 5877 int idx_peer = 2;
5878 return peer_maximum_prefix_unset_vty(vty, argv[idx_peer]->arg,
5879 bgp_node_afi(vty),
5880 bgp_node_safi(vty));
718e3744 5881}
e52702f2 5882
d62a17ae 5883ALIAS_HIDDEN(
5884 no_neighbor_maximum_prefix, no_neighbor_maximum_prefix_hidden_cmd,
5885 "no neighbor <A.B.C.D|X:X::X:X|WORD> maximum-prefix [(1-4294967295) [(1-100)] [restart (1-65535)] [warning-only]]",
5886 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5887 "Maximum number of prefixes to accept from this peer\n"
5888 "maximum no. of prefix limit\n"
5889 "Threshold value (%) at which to generate a warning msg\n"
5890 "Restart bgp connection after limit is exceeded\n"
5891 "Restart interval in minutes\n"
5892 "Only give warning message when limit is exceeded\n")
596c17ba 5893
718e3744 5894
718e3744 5895/* "neighbor allowas-in" */
5896DEFUN (neighbor_allowas_in,
5897 neighbor_allowas_in_cmd,
fd8503f5 5898 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5899 NEIGHBOR_STR
5900 NEIGHBOR_ADDR_STR2
31500417 5901 "Accept as-path with my AS present in it\n"
fd8503f5
QY
5902 "Number of occurances of AS number\n"
5903 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5904{
d62a17ae 5905 int idx_peer = 1;
5906 int idx_number_origin = 3;
5907 int ret;
5908 int origin = 0;
5909 struct peer *peer;
5910 int allow_num = 0;
5911
5912 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5913 if (!peer)
5914 return CMD_WARNING_CONFIG_FAILED;
5915
5916 if (argc <= idx_number_origin)
5917 allow_num = 3;
5918 else {
5919 if (argv[idx_number_origin]->type == WORD_TKN)
5920 origin = 1;
5921 else
5922 allow_num = atoi(argv[idx_number_origin]->arg);
5923 }
5924
5925 ret = peer_allowas_in_set(peer, bgp_node_afi(vty), bgp_node_safi(vty),
5926 allow_num, origin);
5927
5928 return bgp_vty_return(vty, ret);
5929}
5930
5931ALIAS_HIDDEN(
5932 neighbor_allowas_in, neighbor_allowas_in_hidden_cmd,
5933 "neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5934 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5935 "Accept as-path with my AS present in it\n"
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")
596c17ba 5938
718e3744 5939DEFUN (no_neighbor_allowas_in,
5940 no_neighbor_allowas_in_cmd,
fd8503f5 5941 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
718e3744 5942 NO_STR
5943 NEIGHBOR_STR
5944 NEIGHBOR_ADDR_STR2
8334fd5a 5945 "allow local ASN appears in aspath attribute\n"
fd8503f5
QY
5946 "Number of occurances of AS number\n"
5947 "Only accept my AS in the as-path if the route was originated in my AS\n")
718e3744 5948{
d62a17ae 5949 int idx_peer = 2;
5950 int ret;
5951 struct peer *peer;
718e3744 5952
d62a17ae 5953 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5954 if (!peer)
5955 return CMD_WARNING_CONFIG_FAILED;
718e3744 5956
d62a17ae 5957 ret = peer_allowas_in_unset(peer, bgp_node_afi(vty),
5958 bgp_node_safi(vty));
718e3744 5959
d62a17ae 5960 return bgp_vty_return(vty, ret);
718e3744 5961}
6b0655a2 5962
d62a17ae 5963ALIAS_HIDDEN(
5964 no_neighbor_allowas_in, no_neighbor_allowas_in_hidden_cmd,
5965 "no neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]",
5966 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
5967 "allow local ASN appears in aspath attribute\n"
5968 "Number of occurances of AS number\n"
5969 "Only accept my AS in the as-path if the route was originated in my AS\n")
596c17ba 5970
fa411a21
NH
5971DEFUN (neighbor_ttl_security,
5972 neighbor_ttl_security_cmd,
7ebe625c 5973 "neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21 5974 NEIGHBOR_STR
7ebe625c 5975 NEIGHBOR_ADDR_STR2
16cedbb0 5976 "BGP ttl-security parameters\n"
d7fa34c1
QY
5977 "Specify the maximum number of hops to the BGP peer\n"
5978 "Number of hops to BGP peer\n")
fa411a21 5979{
d62a17ae 5980 int idx_peer = 1;
5981 int idx_number = 4;
5982 struct peer *peer;
5983 int gtsm_hops;
5984
5985 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
5986 if (!peer)
5987 return CMD_WARNING_CONFIG_FAILED;
5988
5989 gtsm_hops = strtoul(argv[idx_number]->arg, NULL, 10);
5990
7ebe625c
QY
5991 /*
5992 * If 'neighbor swpX', then this is for directly connected peers,
5993 * we should not accept a ttl-security hops value greater than 1.
5994 */
5995 if (peer->conf_if && (gtsm_hops > 1)) {
5996 vty_out(vty,
5997 "%s is directly connected peer, hops cannot exceed 1\n",
5998 argv[idx_peer]->arg);
5999 return CMD_WARNING_CONFIG_FAILED;
6000 }
6001
d62a17ae 6002 return bgp_vty_return(vty, peer_ttl_security_hops_set(peer, gtsm_hops));
fa411a21
NH
6003}
6004
6005DEFUN (no_neighbor_ttl_security,
6006 no_neighbor_ttl_security_cmd,
7ebe625c 6007 "no neighbor <A.B.C.D|X:X::X:X|WORD> ttl-security hops (1-254)",
fa411a21
NH
6008 NO_STR
6009 NEIGHBOR_STR
7ebe625c 6010 NEIGHBOR_ADDR_STR2
16cedbb0 6011 "BGP ttl-security parameters\n"
3a2d747c
QY
6012 "Specify the maximum number of hops to the BGP peer\n"
6013 "Number of hops to BGP peer\n")
fa411a21 6014{
d62a17ae 6015 int idx_peer = 2;
6016 struct peer *peer;
fa411a21 6017
d62a17ae 6018 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6019 if (!peer)
6020 return CMD_WARNING_CONFIG_FAILED;
fa411a21 6021
d62a17ae 6022 return bgp_vty_return(vty, peer_ttl_security_hops_unset(peer));
fa411a21 6023}
6b0655a2 6024
adbac85e
DW
6025DEFUN (neighbor_addpath_tx_all_paths,
6026 neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6027 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6028 NEIGHBOR_STR
6029 NEIGHBOR_ADDR_STR2
6030 "Use addpath to advertise all paths to a neighbor\n")
6031{
d62a17ae 6032 int idx_peer = 1;
6033 struct peer *peer;
adbac85e 6034
d62a17ae 6035 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6036 if (!peer)
6037 return CMD_WARNING_CONFIG_FAILED;
adbac85e 6038
d62a17ae 6039 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6040 bgp_node_safi(vty),
6041 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6042}
6043
d62a17ae 6044ALIAS_HIDDEN(neighbor_addpath_tx_all_paths,
6045 neighbor_addpath_tx_all_paths_hidden_cmd,
6046 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6047 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6048 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6049
adbac85e
DW
6050DEFUN (no_neighbor_addpath_tx_all_paths,
6051 no_neighbor_addpath_tx_all_paths_cmd,
9ccf14f7 6052 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
adbac85e
DW
6053 NO_STR
6054 NEIGHBOR_STR
6055 NEIGHBOR_ADDR_STR2
6056 "Use addpath to advertise all paths to a neighbor\n")
6057{
d62a17ae 6058 int idx_peer = 2;
6059 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6060 bgp_node_afi(vty), bgp_node_safi(vty),
6061 PEER_FLAG_ADDPATH_TX_ALL_PATHS);
adbac85e
DW
6062}
6063
d62a17ae 6064ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths,
6065 no_neighbor_addpath_tx_all_paths_hidden_cmd,
6066 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths",
6067 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6068 "Use addpath to advertise all paths to a neighbor\n")
596c17ba 6069
06370dac
DW
6070DEFUN (neighbor_addpath_tx_bestpath_per_as,
6071 neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6072 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6073 NEIGHBOR_STR
6074 NEIGHBOR_ADDR_STR2
6075 "Use addpath to advertise the bestpath per each neighboring AS\n")
6076{
d62a17ae 6077 int idx_peer = 1;
6078 struct peer *peer;
06370dac 6079
d62a17ae 6080 peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg);
6081 if (!peer)
6082 return CMD_WARNING_CONFIG_FAILED;
06370dac 6083
d62a17ae 6084 return peer_af_flag_set_vty(vty, argv[idx_peer]->arg, bgp_node_afi(vty),
6085 bgp_node_safi(vty),
6086 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6087}
6088
d62a17ae 6089ALIAS_HIDDEN(neighbor_addpath_tx_bestpath_per_as,
6090 neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6091 "neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6092 NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6093 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6094
06370dac
DW
6095DEFUN (no_neighbor_addpath_tx_bestpath_per_as,
6096 no_neighbor_addpath_tx_bestpath_per_as_cmd,
9ccf14f7 6097 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
06370dac
DW
6098 NO_STR
6099 NEIGHBOR_STR
6100 NEIGHBOR_ADDR_STR2
6101 "Use addpath to advertise the bestpath per each neighboring AS\n")
6102{
d62a17ae 6103 int idx_peer = 2;
6104 return peer_af_flag_unset_vty(vty, argv[idx_peer]->arg,
6105 bgp_node_afi(vty), bgp_node_safi(vty),
6106 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS);
06370dac
DW
6107}
6108
d62a17ae 6109ALIAS_HIDDEN(no_neighbor_addpath_tx_bestpath_per_as,
6110 no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd,
6111 "no neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS",
6112 NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
6113 "Use addpath to advertise the bestpath per each neighboring AS\n")
596c17ba 6114
ddb5b488
PZ
6115
6116DEFUN_NOSH (vpn_policy_afi,
6117 vpn_policy_afi_cmd,
6118 "vpn-policy <ipv4|ipv6>",
6119 "Enter vpn-policy command mode\n"
6120 BGP_AFI_HELP_STR)
6121{
6122 VTY_DECLVAR_CONTEXT(bgp, bgp);
6123 if (bgp->inst_type != BGP_INSTANCE_TYPE_VRF
6124 && bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT) {
6125
6126 vty_out(vty,
6127 "vpn-policy supported only in core or vrf instances.\n");
6128 return CMD_WARNING_CONFIG_FAILED;
6129 }
6130
6131 afi_t afi;
6132 int idx = 0;
6133
6134 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
6135 if (afi == AFI_IP)
6136 vty->node = BGP_VPNPOLICY_IPV4_NODE;
6137 else
6138 vty->node = BGP_VPNPOLICY_IPV6_NODE;
6139 return CMD_SUCCESS;
6140 }
6141 return CMD_WARNING_CONFIG_FAILED;
6142}
6143
6144static int vpn_policy_afis(struct vty *vty, int *doafi)
6145{
6146 switch (vty->node) {
6147 case BGP_VPNPOLICY_IPV4_NODE:
6148 doafi[AFI_IP] = 1;
6149 break;
6150 case BGP_VPNPOLICY_IPV6_NODE:
6151 doafi[AFI_IP6] = 1;
6152 break;
6153 default:
6154 vty_out(vty,
6155 "%% context error: valid only in vpn-policy block\n");
6156 return CMD_WARNING_CONFIG_FAILED;
6157 }
6158 return CMD_SUCCESS;
6159}
6160
6161static int argv_find_and_parse_vpn_policy_dirs(struct vty *vty,
6162 struct cmd_token **argv,
6163 int argc, int *idx, int *dodir)
6164{
6165 if (argv_find(argv, argc, "fromvpn", idx)) {
6166 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6167 } else if (argv_find(argv, argc, "tovpn", idx)) {
6168 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6169 } else if (argv_find(argv, argc, "both", idx)) {
6170 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6171 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6172 } else {
6173 vty_out(vty, "%% direction parse error\n");
6174 return CMD_WARNING_CONFIG_FAILED;
6175 }
6176 return CMD_SUCCESS;
6177}
6178
6179DEFUN (vpn_policy_rd,
6180 vpn_policy_rd_cmd,
6181 "rd ASN:NN_OR_IP-ADDRESS:NN",
6182 "Specify route distinguisher\n"
6183 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6184{
6185 VTY_DECLVAR_CONTEXT(bgp, bgp);
6186 struct prefix_rd prd;
6187 int ret;
6188 int doafi[AFI_MAX] = {0};
6189 afi_t afi;
6190
6191 ret = str2prefix_rd(argv[1]->arg, &prd);
6192 if (!ret) {
6193 vty_out(vty, "%% Malformed rd\n");
6194 return CMD_WARNING_CONFIG_FAILED;
6195 }
6196
6197 ret = vpn_policy_afis(vty, doafi);
6198 if (ret != CMD_SUCCESS)
6199 return ret;
6200
6201
6202 for (afi = 0; afi < AFI_MAX; ++afi) {
6203 if (!doafi[afi])
6204 continue;
6205
6206 /* pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6207 */
6208 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6209 bgp_get_default(), bgp);
6210
6211 bgp->vpn_policy[afi].tovpn_rd = prd;
6212 SET_FLAG(bgp->vpn_policy[afi].flags,
6213 BGP_VPN_POLICY_TOVPN_RD_SET);
6214
6215 /* post-change: re-export vpn routes */
6216 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6217 bgp_get_default(), bgp);
6218 }
6219
6220 return CMD_SUCCESS;
6221}
6222
6223DEFUN (vpn_policy_no_rd,
6224 vpn_policy_no_rd_cmd,
6225 "no rd",
6226 NO_STR
6227 "Specify route distinguisher\n")
6228{
6229 VTY_DECLVAR_CONTEXT(bgp, bgp);
6230 int ret;
6231 int doafi[AFI_MAX] = {0};
6232 afi_t afi;
6233
6234 ret = vpn_policy_afis(vty, doafi);
6235 if (ret != CMD_SUCCESS)
6236 return ret;
6237
6238
6239 for (afi = 0; afi < AFI_MAX; ++afi) {
6240 if (!doafi[afi])
6241 continue;
6242
6243 /* pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6244 */
6245 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6246 bgp_get_default(), bgp);
6247
6248 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6249 BGP_VPN_POLICY_TOVPN_RD_SET);
6250
6251 /* post-change: re-export vpn routes */
6252 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6253 bgp_get_default(), bgp);
6254 }
6255
6256 return CMD_SUCCESS;
6257}
6258
6259DEFUN (vpn_policy_label,
6260 vpn_policy_label_cmd,
6261 "label (0-1048575)",
6262 "label value for VRF\n"
6263 "Label Value <0-1048575>\n")
6264{
6265 VTY_DECLVAR_CONTEXT(bgp, bgp);
6266 mpls_label_t label;
6267 int doafi[AFI_MAX] = {0};
6268 afi_t afi;
6269 int ret;
6270
6271 label = strtoul(argv[1]->arg, NULL, 10);
6272
6273 ret = vpn_policy_afis(vty, doafi);
6274 if (ret != CMD_SUCCESS)
6275 return ret;
6276
6277 for (afi = 0; afi < AFI_MAX; ++afi) {
6278 if (!doafi[afi])
6279 continue;
6280
6281 /* pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6282 */
6283 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6284 bgp_get_default(), bgp);
6285
6286 bgp->vpn_policy[afi].tovpn_label = label;
6287
6288 /* post-change: re-export vpn routes */
6289 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6290 bgp_get_default(), bgp);
6291 }
6292
6293 return CMD_SUCCESS;
6294}
6295
6296DEFUN (vpn_policy_no_label,
6297 vpn_policy_no_label_cmd,
6298 "no label",
6299 "Negate a command or set its defaults\n"
6300 "label value for VRF\n")
6301{
6302 VTY_DECLVAR_CONTEXT(bgp, bgp);
6303 int doafi[AFI_MAX] = {0};
6304 afi_t afi;
6305 int ret;
6306
6307 ret = vpn_policy_afis(vty, doafi);
6308 if (ret != CMD_SUCCESS)
6309 return ret;
6310
6311 for (afi = 0; afi < AFI_MAX; ++afi) {
6312 if (!doafi[afi])
6313 continue;
6314
6315 /* pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6316 */
6317 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6318 bgp_get_default(), bgp);
6319
6320 bgp->vpn_policy[afi].tovpn_label = MPLS_LABEL_NONE;
6321
6322 /* post-change: re-export vpn routes */
6323 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6324 bgp_get_default(), bgp);
6325 }
6326
6327 return CMD_SUCCESS;
6328}
6329
6330DEFPY (vpn_policy_nexthop,
6331 vpn_policy_nexthop_cmd,
6332 "nexthop <A.B.C.D|X:X::X:X>$nexthop",
6333 "Specify next hop to use for VRF advertised prefixes\n"
6334 "IPv4 prefix\n"
6335 "IPv6 prefix\n")
6336{
6337 VTY_DECLVAR_CONTEXT(bgp, bgp);
6338 int doafi[AFI_MAX] = {0};
6339 afi_t afi;
6340 int ret;
6341 struct prefix p;
6342
6343 if (!sockunion2hostprefix(nexthop, &p))
6344 return CMD_WARNING_CONFIG_FAILED;
6345
6346 ret = vpn_policy_afis(vty, doafi);
6347 if (ret != CMD_SUCCESS)
6348 return ret;
6349
6350 for (afi = 0; afi < AFI_MAX; ++afi) {
6351 if (!doafi[afi])
6352 continue;
6353
6354 /*
6355 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6356 */
6357 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6358 bgp_get_default(), bgp);
6359
6360 bgp->vpn_policy[afi].tovpn_nexthop = p;
6361 SET_FLAG(bgp->vpn_policy[afi].flags,
6362 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6363
6364 /* post-change: re-export vpn routes */
6365 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6366 bgp_get_default(), bgp);
6367 }
6368
6369 return CMD_SUCCESS;
6370}
6371
6372DEFUN (vpn_policy_no_nexthop,
6373 vpn_policy_no_nexthop_cmd,
6374 "no nexthop",
6375 NO_STR
6376 "Specify next hop to use for VRF advertised prefixes\n")
6377{
6378 VTY_DECLVAR_CONTEXT(bgp, bgp);
6379 int doafi[AFI_MAX] = {0};
6380 afi_t afi;
6381 int ret;
6382
6383 ret = vpn_policy_afis(vty, doafi);
6384 if (ret != CMD_SUCCESS)
6385 return ret;
6386
6387 for (afi = 0; afi < AFI_MAX; ++afi) {
6388 if (!doafi[afi])
6389 continue;
6390
6391 /* pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6392 */
6393 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6394 bgp_get_default(), bgp);
6395
6396 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6397 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6398
6399 /* post-change: re-export vpn routes */
6400 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6401 bgp_get_default(), bgp);
6402 }
6403
6404 return CMD_SUCCESS;
6405}
6406
6407static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6408 struct ecommunity **list)
6409{
6410 struct ecommunity *ecom = NULL;
6411 struct ecommunity *ecomadd;
6412
6413 for (; argc; --argc, ++argv) {
6414
6415 ecomadd = ecommunity_str2com(argv[0]->arg,
6416 ECOMMUNITY_ROUTE_TARGET, 0);
6417 if (!ecomadd) {
6418 vty_out(vty, "Malformed community-list value\n");
6419 if (ecom)
6420 ecommunity_free(&ecom);
6421 return CMD_WARNING_CONFIG_FAILED;
6422 }
6423
6424 if (ecom) {
6425 ecommunity_merge(ecom, ecomadd);
6426 ecommunity_free(&ecomadd);
6427 } else {
6428 ecom = ecomadd;
6429 }
6430 }
6431
6432 if (*list) {
6433 ecommunity_free(&*list);
6434 }
6435 *list = ecom;
6436
6437 return CMD_SUCCESS;
6438}
6439
6440DEFUN (vpn_policy_rt,
6441 vpn_policy_rt_cmd,
6442 "rt <fromvpn|tovpn|both> RTLIST...",
6443 "Specify route target list\n"
6444 "fromvpn: match any\n"
6445 "tovpn: set\n"
6446 "both fromvpn: match any and tovpn: set\n"
6447 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6448{
6449 VTY_DECLVAR_CONTEXT(bgp, bgp);
6450 int ret;
6451 struct ecommunity *ecom = NULL;
6452 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6453 int doafi[AFI_MAX] = {0};
6454 vpn_policy_direction_t dir;
6455 afi_t afi;
6456 int idx = 0;
6457
6458 ret = vpn_policy_afis(vty, doafi);
6459 if (ret != CMD_SUCCESS)
6460 return ret;
6461
6462 ret = argv_find_and_parse_vpn_policy_dirs(vty, argv, argc, &idx, dodir);
6463 if (ret != CMD_SUCCESS)
6464 return ret;
6465
6466 ret = set_ecom_list(vty, argc - 2, argv + 2, &ecom);
6467 if (ret != CMD_SUCCESS) {
6468 return ret;
6469 }
6470
6471 for (afi = 0; afi < AFI_MAX; ++afi) {
6472 if (!doafi[afi])
6473 continue;
6474 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6475 if (!dodir[dir])
6476 continue;
6477
6478 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6479
6480 if (bgp->vpn_policy[afi].rtlist[dir])
6481 ecommunity_free(
6482 &bgp->vpn_policy[afi].rtlist[dir]);
6483 bgp->vpn_policy[afi].rtlist[dir] = ecommunity_dup(ecom);
6484
6485 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6486 }
6487 }
6488 ecommunity_free(&ecom);
6489
6490 return CMD_SUCCESS;
6491}
6492
6493DEFUN (vpn_policy_no_rt,
6494 vpn_policy_no_rt_cmd,
6495 "no rt <fromvpn|tovpn|both>",
6496 NO_STR
6497 "Specify route target list\n"
6498 "fromvpn: match any\n"
6499 "tovpn: set\n"
6500 "both fromvpn: match any and tovpn: set\n")
6501{
6502 VTY_DECLVAR_CONTEXT(bgp, bgp);
6503 int ret;
6504 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6505 int doafi[AFI_MAX] = {0};
6506 vpn_policy_direction_t dir;
6507 afi_t afi;
6508 int idx = 0;
6509
6510 ret = vpn_policy_afis(vty, doafi);
6511 if (ret != CMD_SUCCESS)
6512 return ret;
6513
6514 ret = argv_find_and_parse_vpn_policy_dirs(vty, argv, argc, &idx, dodir);
6515 if (ret != CMD_SUCCESS)
6516 return ret;
6517
6518 for (afi = 0; afi < AFI_MAX; ++afi) {
6519 if (!doafi[afi])
6520 continue;
6521 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6522 if (!dodir[dir])
6523 continue;
6524
6525 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6526
6527 if (bgp->vpn_policy[afi].rtlist[dir])
6528 ecommunity_free(
6529 &bgp->vpn_policy[afi].rtlist[dir]);
6530 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6531
6532 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6533 }
6534 }
6535
6536 return CMD_SUCCESS;
6537}
6538
6539DEFUN (vpn_policy_route_map,
6540 vpn_policy_route_map_cmd,
6541 "route-map <fromvpn|tovpn> WORD",
6542 "Specify route map\n"
6543 "fromvpn: core vpn -> this vrf\n"
6544 "tovpn: this vrf -> core vpn\n"
6545 "name of route-map\n")
6546{
6547 VTY_DECLVAR_CONTEXT(bgp, bgp);
6548 int ret;
6549 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6550 int doafi[AFI_MAX] = {0};
6551 vpn_policy_direction_t dir;
6552 afi_t afi;
6553 int map_name_arg = 2;
6554 int idx = 0;
6555
6556 ret = vpn_policy_afis(vty, doafi);
6557 if (ret != CMD_SUCCESS)
6558 return ret;
6559
6560 ret = argv_find_and_parse_vpn_policy_dirs(vty, argv, argc, &idx, dodir);
6561 if (ret != CMD_SUCCESS)
6562 return ret;
6563
6564 for (afi = 0; afi < AFI_MAX; ++afi) {
6565 if (!doafi[afi])
6566 continue;
6567 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6568 if (!dodir[dir])
6569 continue;
6570
6571 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6572
6573 if (bgp->vpn_policy[afi].rmap_name[dir])
6574 XFREE(MTYPE_ROUTE_MAP_NAME,
6575 bgp->vpn_policy[afi].rmap_name[dir]);
6576 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6577 MTYPE_ROUTE_MAP_NAME, argv[map_name_arg]->arg);
6578 bgp->vpn_policy[afi].rmap[dir] =
6579 route_map_lookup_by_name(
6580 argv[map_name_arg]->arg);
6581
6582 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6583 }
6584 }
6585
6586 return CMD_SUCCESS;
6587}
6588
6589DEFUN (vpn_policy_no_route_map,
6590 vpn_policy_no_route_map_cmd,
6591 "no route-map <fromvpn|tovpn>",
6592 NO_STR
6593 "Specify route map\n"
6594 "fromvpn: core vpn -> this vrf\n"
6595 "tovpn: this vrf -> core vpn\n")
6596{
6597 VTY_DECLVAR_CONTEXT(bgp, bgp);
6598 int ret;
6599 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6600 int doafi[AFI_MAX] = {0};
6601 vpn_policy_direction_t dir;
6602 afi_t afi;
6603 int idx = 0;
6604
6605 ret = vpn_policy_afis(vty, doafi);
6606 if (ret != CMD_SUCCESS)
6607 return ret;
6608
6609 ret = argv_find_and_parse_vpn_policy_dirs(vty, argv, argc, &idx, dodir);
6610 if (ret != CMD_SUCCESS)
6611 return ret;
6612
6613 for (afi = 0; afi < AFI_MAX; ++afi) {
6614 if (!doafi[afi])
6615 continue;
6616 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6617 if (!dodir[dir])
6618 continue;
6619
6620 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6621
6622 if (bgp->vpn_policy[afi].rmap_name[dir])
6623 XFREE(MTYPE_ROUTE_MAP_NAME,
6624 bgp->vpn_policy[afi].rmap_name[dir]);
6625 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6626 bgp->vpn_policy[afi].rmap[dir] = NULL;
6627
6628 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6629 }
6630 }
6631
6632 return CMD_SUCCESS;
6633}
6634
505e5056 6635DEFUN_NOSH (address_family_ipv4_safi,
718e3744 6636 address_family_ipv4_safi_cmd,
5b1f0f29 6637 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6638 "Enter Address Family command mode\n"
8c3deaae 6639 "Address Family\n"
b6ab5a3a 6640 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6641{
f51bae9c 6642
d62a17ae 6643 if (argc == 3) {
2131d5cf 6644 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6645 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6646 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6647 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6648 && safi != SAFI_EVPN) {
31947174
MK
6649 vty_out(vty,
6650 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6651 return CMD_WARNING_CONFIG_FAILED;
6652 }
d62a17ae 6653 vty->node = bgp_node_type(AFI_IP, safi);
6654 } else
6655 vty->node = BGP_IPV4_NODE;
718e3744 6656
d62a17ae 6657 return CMD_SUCCESS;
718e3744 6658}
6659
505e5056 6660DEFUN_NOSH (address_family_ipv6_safi,
25ffbdc1 6661 address_family_ipv6_safi_cmd,
5b1f0f29 6662 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6663 "Enter Address Family command mode\n"
8c3deaae 6664 "Address Family\n"
b6ab5a3a 6665 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6666{
d62a17ae 6667 if (argc == 3) {
2131d5cf 6668 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6669 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6670 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6671 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6672 && safi != SAFI_EVPN) {
31947174
MK
6673 vty_out(vty,
6674 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6675 return CMD_WARNING_CONFIG_FAILED;
6676 }
d62a17ae 6677 vty->node = bgp_node_type(AFI_IP6, safi);
6678 } else
6679 vty->node = BGP_IPV6_NODE;
25ffbdc1 6680
d62a17ae 6681 return CMD_SUCCESS;
25ffbdc1 6682}
718e3744 6683
d6902373 6684#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6685DEFUN_NOSH (address_family_vpnv4,
718e3744 6686 address_family_vpnv4_cmd,
8334fd5a 6687 "address-family vpnv4 [unicast]",
718e3744 6688 "Enter Address Family command mode\n"
8c3deaae 6689 "Address Family\n"
3a2d747c 6690 "Address Family modifier\n")
718e3744 6691{
d62a17ae 6692 vty->node = BGP_VPNV4_NODE;
6693 return CMD_SUCCESS;
718e3744 6694}
6695
505e5056 6696DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6697 address_family_vpnv6_cmd,
8334fd5a 6698 "address-family vpnv6 [unicast]",
8ecd3266 6699 "Enter Address Family command mode\n"
8c3deaae 6700 "Address Family\n"
3a2d747c 6701 "Address Family modifier\n")
8ecd3266 6702{
d62a17ae 6703 vty->node = BGP_VPNV6_NODE;
6704 return CMD_SUCCESS;
8ecd3266 6705}
c016b6c7 6706#endif
d6902373 6707
505e5056 6708DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6709 address_family_evpn_cmd,
7111c1a0 6710 "address-family l2vpn evpn",
4e0b7b6d 6711 "Enter Address Family command mode\n"
7111c1a0
QY
6712 "Address Family\n"
6713 "Address Family modifier\n")
4e0b7b6d 6714{
2131d5cf 6715 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6716 vty->node = BGP_EVPN_NODE;
6717 return CMD_SUCCESS;
4e0b7b6d
PG
6718}
6719
505e5056 6720DEFUN_NOSH (exit_address_family,
718e3744 6721 exit_address_family_cmd,
6722 "exit-address-family",
6723 "Exit from Address Family configuration mode\n")
6724{
d62a17ae 6725 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6726 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6727 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6728 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6729 || vty->node == BGP_EVPN_NODE)
6730 vty->node = BGP_NODE;
6731 return CMD_SUCCESS;
718e3744 6732}
6b0655a2 6733
8ad7271d 6734/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6735static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6736 const char *ip_str, afi_t afi, safi_t safi,
6737 struct prefix_rd *prd)
6738{
6739 int ret;
6740 struct prefix match;
6741 struct bgp_node *rn;
6742 struct bgp_node *rm;
6743 struct bgp *bgp;
6744 struct bgp_table *table;
6745 struct bgp_table *rib;
6746
6747 /* BGP structure lookup. */
6748 if (view_name) {
6749 bgp = bgp_lookup_by_name(view_name);
6750 if (bgp == NULL) {
6751 vty_out(vty, "%% Can't find BGP instance %s\n",
6752 view_name);
6753 return CMD_WARNING;
6754 }
6755 } else {
6756 bgp = bgp_get_default();
6757 if (bgp == NULL) {
6758 vty_out(vty, "%% No BGP process is configured\n");
6759 return CMD_WARNING;
6760 }
6761 }
6762
6763 /* Check IP address argument. */
6764 ret = str2prefix(ip_str, &match);
6765 if (!ret) {
6766 vty_out(vty, "%% address is malformed\n");
6767 return CMD_WARNING;
6768 }
6769
6770 match.family = afi2family(afi);
6771 rib = bgp->rib[afi][safi];
6772
6773 if (safi == SAFI_MPLS_VPN) {
6774 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6775 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6776 continue;
6777
6778 if ((table = rn->info) != NULL) {
6779 if ((rm = bgp_node_match(table, &match))
6780 != NULL) {
6781 if (rm->p.prefixlen
6782 == match.prefixlen) {
6783 SET_FLAG(rn->flags,
6784 BGP_NODE_USER_CLEAR);
6785 bgp_process(bgp, rm, afi, safi);
6786 }
6787 bgp_unlock_node(rm);
6788 }
6789 }
6790 }
6791 } else {
6792 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6793 if (rn->p.prefixlen == match.prefixlen) {
6794 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6795 bgp_process(bgp, rn, afi, safi);
6796 }
6797 bgp_unlock_node(rn);
6798 }
6799 }
6800
6801 return CMD_SUCCESS;
8ad7271d
DS
6802}
6803
b09b5ae0 6804/* one clear bgp command to rule them all */
718e3744 6805DEFUN (clear_ip_bgp_all,
6806 clear_ip_bgp_all_cmd,
c1a44e43 6807 "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 6808 CLEAR_STR
6809 IP_STR
6810 BGP_STR
838758ac 6811 BGP_INSTANCE_HELP_STR
510afcd6
DS
6812 BGP_AFI_HELP_STR
6813 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
6814 "Clear all peers\n"
6815 "BGP neighbor address to clear\n"
a80beece 6816 "BGP IPv6 neighbor to clear\n"
838758ac 6817 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
6818 "Clear peers with the AS number\n"
6819 "Clear all external peers\n"
718e3744 6820 "Clear all members of peer-group\n"
b09b5ae0 6821 "BGP peer-group name\n"
b09b5ae0
DW
6822 BGP_SOFT_STR
6823 BGP_SOFT_IN_STR
b09b5ae0
DW
6824 BGP_SOFT_OUT_STR
6825 BGP_SOFT_IN_STR
6826 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 6827 BGP_SOFT_OUT_STR)
718e3744 6828{
d62a17ae 6829 char *vrf = NULL;
6830
6831 afi_t afi = AFI_IP6;
6832 safi_t safi = SAFI_UNICAST;
6833 enum clear_sort clr_sort = clear_peer;
6834 enum bgp_clear_type clr_type;
6835 char *clr_arg = NULL;
6836
6837 int idx = 0;
6838
6839 /* clear [ip] bgp */
6840 if (argv_find(argv, argc, "ip", &idx))
6841 afi = AFI_IP;
6842
6843 /* [<view|vrf> VIEWVRFNAME] */
6844 if (argv_find(argv, argc, "view", &idx)
6845 || argv_find(argv, argc, "vrf", &idx)) {
6846 vrf = argv[idx + 1]->arg;
6847 idx += 2;
6848 }
6849
6850 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6851 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6852 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6853
6854 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6855 if (argv_find(argv, argc, "*", &idx)) {
6856 clr_sort = clear_all;
6857 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6858 clr_sort = clear_peer;
6859 clr_arg = argv[idx]->arg;
6860 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6861 clr_sort = clear_peer;
6862 clr_arg = argv[idx]->arg;
6863 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6864 clr_sort = clear_group;
6865 idx++;
6866 clr_arg = argv[idx]->arg;
6867 } else if (argv_find(argv, argc, "WORD", &idx)) {
6868 clr_sort = clear_peer;
6869 clr_arg = argv[idx]->arg;
6870 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6871 clr_sort = clear_as;
6872 clr_arg = argv[idx]->arg;
6873 } else if (argv_find(argv, argc, "external", &idx)) {
6874 clr_sort = clear_external;
6875 }
6876
6877 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6878 if (argv_find(argv, argc, "soft", &idx)) {
6879 if (argv_find(argv, argc, "in", &idx)
6880 || argv_find(argv, argc, "out", &idx))
6881 clr_type = strmatch(argv[idx]->text, "in")
6882 ? BGP_CLEAR_SOFT_IN
6883 : BGP_CLEAR_SOFT_OUT;
6884 else
6885 clr_type = BGP_CLEAR_SOFT_BOTH;
6886 } else if (argv_find(argv, argc, "in", &idx)) {
6887 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6888 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6889 : BGP_CLEAR_SOFT_IN;
6890 } else if (argv_find(argv, argc, "out", &idx)) {
6891 clr_type = BGP_CLEAR_SOFT_OUT;
6892 } else
6893 clr_type = BGP_CLEAR_SOFT_NONE;
6894
6895 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 6896}
01080f7c 6897
8ad7271d
DS
6898DEFUN (clear_ip_bgp_prefix,
6899 clear_ip_bgp_prefix_cmd,
18c57037 6900 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
6901 CLEAR_STR
6902 IP_STR
6903 BGP_STR
838758ac 6904 BGP_INSTANCE_HELP_STR
8ad7271d 6905 "Clear bestpath and re-advertise\n"
0c7b1b01 6906 "IPv4 prefix\n")
8ad7271d 6907{
d62a17ae 6908 char *vrf = NULL;
6909 char *prefix = NULL;
8ad7271d 6910
d62a17ae 6911 int idx = 0;
01080f7c 6912
d62a17ae 6913 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 6914 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 6915 vrf = argv[idx]->arg;
0c7b1b01 6916
d62a17ae 6917 prefix = argv[argc - 1]->arg;
8ad7271d 6918
d62a17ae 6919 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 6920}
8ad7271d 6921
b09b5ae0
DW
6922DEFUN (clear_bgp_ipv6_safi_prefix,
6923 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 6924 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6925 CLEAR_STR
3a2d747c 6926 IP_STR
718e3744 6927 BGP_STR
8c3deaae 6928 "Address Family\n"
46f296b4 6929 BGP_SAFI_HELP_STR
b09b5ae0 6930 "Clear bestpath and re-advertise\n"
0c7b1b01 6931 "IPv6 prefix\n")
718e3744 6932{
9b475e76
PG
6933 int idx_safi = 0;
6934 int idx_ipv6_prefix = 0;
6935 safi_t safi = SAFI_UNICAST;
6936 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
6937 argv[idx_ipv6_prefix]->arg : NULL;
6938
6939 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 6940 return bgp_clear_prefix(
9b475e76
PG
6941 vty, NULL, prefix, AFI_IP6,
6942 safi, NULL);
838758ac 6943}
01080f7c 6944
b09b5ae0
DW
6945DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6946 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 6947 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6948 CLEAR_STR
3a2d747c 6949 IP_STR
718e3744 6950 BGP_STR
838758ac 6951 BGP_INSTANCE_HELP_STR
8c3deaae 6952 "Address Family\n"
46f296b4 6953 BGP_SAFI_HELP_STR
b09b5ae0 6954 "Clear bestpath and re-advertise\n"
0c7b1b01 6955 "IPv6 prefix\n")
718e3744 6956{
d62a17ae 6957 int idx_word = 3;
9b475e76
PG
6958 int idx_safi = 0;
6959 int idx_ipv6_prefix = 0;
6960 safi_t safi = SAFI_UNICAST;
6961 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
6962 argv[idx_ipv6_prefix]->arg : NULL;
6963 /* [<view|vrf> VIEWVRFNAME] */
6964 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
6965 argv[idx_word]->arg : NULL;
6966
6967 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
6968
d62a17ae 6969 return bgp_clear_prefix(
9b475e76
PG
6970 vty, vrfview, prefix,
6971 AFI_IP6, safi, NULL);
718e3744 6972}
6973
b09b5ae0
DW
6974DEFUN (show_bgp_views,
6975 show_bgp_views_cmd,
d6e3c605 6976 "show [ip] bgp views",
b09b5ae0 6977 SHOW_STR
d6e3c605 6978 IP_STR
01080f7c 6979 BGP_STR
b09b5ae0 6980 "Show the defined BGP views\n")
01080f7c 6981{
d62a17ae 6982 struct list *inst = bm->bgp;
6983 struct listnode *node;
6984 struct bgp *bgp;
01080f7c 6985
d62a17ae 6986 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6987 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6988 return CMD_WARNING;
6989 }
e52702f2 6990
d62a17ae 6991 vty_out(vty, "Defined BGP views:\n");
6992 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6993 /* Skip VRFs. */
6994 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6995 continue;
6996 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6997 bgp->as);
6998 }
e52702f2 6999
d62a17ae 7000 return CMD_SUCCESS;
e0081f70
ML
7001}
7002
8386ac43 7003DEFUN (show_bgp_vrfs,
7004 show_bgp_vrfs_cmd,
d6e3c605 7005 "show [ip] bgp vrfs [json]",
8386ac43 7006 SHOW_STR
d6e3c605 7007 IP_STR
8386ac43 7008 BGP_STR
7009 "Show BGP VRFs\n"
9973d184 7010 JSON_STR)
8386ac43 7011{
fe1dc5a3 7012 char buf[ETHER_ADDR_STRLEN];
d62a17ae 7013 struct list *inst = bm->bgp;
7014 struct listnode *node;
7015 struct bgp *bgp;
7016 u_char uj = use_json(argc, argv);
7017 json_object *json = NULL;
7018 json_object *json_vrfs = NULL;
7019 int count = 0;
d62a17ae 7020
7021 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
7022 vty_out(vty, "BGP Multiple Instance is not enabled\n");
7023 return CMD_WARNING;
7024 }
7025
7026 if (uj) {
7027 json = json_object_new_object();
7028 json_vrfs = json_object_new_object();
7029 }
7030
7031 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
7032 const char *name, *type;
7033 struct peer *peer;
7034 struct listnode *node, *nnode;
7035 int peers_cfg, peers_estb;
7036 json_object *json_vrf = NULL;
d62a17ae 7037
7038 /* Skip Views. */
7039 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
7040 continue;
7041
7042 count++;
7043 if (!uj && count == 1)
fe1dc5a3
MK
7044 vty_out(vty,
7045 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
7046 "Type", "Id", "routerId", "#PeersVfg",
7047 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7048
7049 peers_cfg = peers_estb = 0;
7050 if (uj)
7051 json_vrf = json_object_new_object();
7052
7053
7054 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7055 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7056 continue;
7057 peers_cfg++;
7058 if (peer->status == Established)
7059 peers_estb++;
7060 }
7061
7062 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7063 name = "Default";
7064 type = "DFLT";
7065 } else {
7066 name = bgp->name;
7067 type = "VRF";
7068 }
7069
a8bf7d9c 7070
d62a17ae 7071 if (uj) {
a4d82a8a
PZ
7072 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7073 ? -1
7074 : (int64_t)bgp->vrf_id;
d62a17ae 7075 json_object_string_add(json_vrf, "type", type);
7076 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7077 json_object_string_add(json_vrf, "routerId",
7078 inet_ntoa(bgp->router_id));
7079 json_object_int_add(json_vrf, "numConfiguredPeers",
7080 peers_cfg);
7081 json_object_int_add(json_vrf, "numEstablishedPeers",
7082 peers_estb);
7083
fe1dc5a3 7084 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7085 json_object_string_add(
7086 json_vrf, "rmac",
7087 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7088 json_object_object_add(json_vrfs, name, json_vrf);
7089 } else
fe1dc5a3
MK
7090 vty_out(vty,
7091 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7092 type,
7093 bgp->vrf_id == VRF_UNKNOWN ? -1
7094 : (int)bgp->vrf_id,
7095 inet_ntoa(bgp->router_id), peers_cfg,
7096 peers_estb, name, bgp->l3vni,
fe1dc5a3 7097 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7098 }
7099
7100 if (uj) {
7101 json_object_object_add(json, "vrfs", json_vrfs);
7102
7103 json_object_int_add(json, "totalVrfs", count);
7104
996c9314
LB
7105 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7106 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7107 json_object_free(json);
7108 } else {
7109 if (count)
7110 vty_out(vty,
7111 "\nTotal number of VRFs (including default): %d\n",
7112 count);
7113 }
7114
7115 return CMD_SUCCESS;
8386ac43 7116}
7117
acf71666
MK
7118static void show_address_entry(struct hash_backet *backet, void *args)
7119{
60466a63
QY
7120 struct vty *vty = (struct vty *)args;
7121 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7122
60466a63 7123 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7124 addr->refcnt);
7125}
7126
7127static void show_tip_entry(struct hash_backet *backet, void *args)
7128{
0291c246 7129 struct vty *vty = (struct vty *)args;
60466a63 7130 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7131
60466a63 7132 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7133 tip->refcnt);
7134}
7135
7136static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7137{
7138 vty_out(vty, "self nexthop database:\n");
7139 hash_iterate(bgp->address_hash,
7140 (void (*)(struct hash_backet *, void *))show_address_entry,
7141 vty);
7142
7143 vty_out(vty, "Tunnel-ip database:\n");
7144 hash_iterate(bgp->tip_hash,
7145 (void (*)(struct hash_backet *, void *))show_tip_entry,
7146 vty);
7147}
7148
15c81ca4
DS
7149DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7150 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7151 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7152 "martian next-hops\n"
7153 "martian next-hop database\n")
acf71666 7154{
0291c246 7155 struct bgp *bgp = NULL;
15c81ca4
DS
7156 int idx = 0;
7157
7158 if (argv_find(argv, argc, "view", &idx)
7159 || argv_find(argv, argc, "vrf", &idx))
7160 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7161 else
7162 bgp = bgp_get_default();
acf71666 7163
acf71666
MK
7164 if (!bgp) {
7165 vty_out(vty, "%% No BGP process is configured\n");
7166 return CMD_WARNING;
7167 }
7168 bgp_show_martian_nexthops(vty, bgp);
7169
7170 return CMD_SUCCESS;
7171}
7172
f412b39a 7173DEFUN (show_bgp_memory,
4bf6a362 7174 show_bgp_memory_cmd,
7fa12b13 7175 "show [ip] bgp memory",
4bf6a362 7176 SHOW_STR
3a2d747c 7177 IP_STR
4bf6a362
PJ
7178 BGP_STR
7179 "Global BGP memory statistics\n")
7180{
d62a17ae 7181 char memstrbuf[MTYPE_MEMSTR_LEN];
7182 unsigned long count;
7183
7184 /* RIB related usage stats */
7185 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7186 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7187 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7188 count * sizeof(struct bgp_node)));
7189
7190 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7191 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7192 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7193 count * sizeof(struct bgp_info)));
7194 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7195 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7196 count,
7197 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7198 count * sizeof(struct bgp_info_extra)));
7199
7200 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7201 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7202 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7203 count * sizeof(struct bgp_static)));
7204
7205 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7206 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7207 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7208 count * sizeof(struct bpacket)));
7209
7210 /* Adj-In/Out */
7211 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7212 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7213 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7214 count * sizeof(struct bgp_adj_in)));
7215 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7216 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7217 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7218 count * sizeof(struct bgp_adj_out)));
7219
7220 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7221 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7222 count,
7223 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7224 count * sizeof(struct bgp_nexthop_cache)));
7225
7226 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7227 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7228 count,
7229 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7230 count * sizeof(struct bgp_damp_info)));
7231
7232 /* Attributes */
7233 count = attr_count();
7234 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7235 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7236 count * sizeof(struct attr)));
7237
7238 if ((count = attr_unknown_count()))
7239 vty_out(vty, "%ld unknown attributes\n", count);
7240
7241 /* AS_PATH attributes */
7242 count = aspath_count();
7243 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7244 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7245 count * sizeof(struct aspath)));
7246
7247 count = mtype_stats_alloc(MTYPE_AS_SEG);
7248 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7249 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7250 count * sizeof(struct assegment)));
7251
7252 /* Other attributes */
7253 if ((count = community_count()))
7254 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7255 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7256 count * sizeof(struct community)));
d62a17ae 7257 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7258 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7259 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7260 count * sizeof(struct ecommunity)));
d62a17ae 7261 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7262 vty_out(vty,
7263 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7264 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7265 count * sizeof(struct lcommunity)));
d62a17ae 7266
7267 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7268 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7269 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7270 count * sizeof(struct cluster_list)));
7271
7272 /* Peer related usage */
7273 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7274 vty_out(vty, "%ld peers, using %s of memory\n", count,
7275 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7276 count * sizeof(struct peer)));
7277
7278 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7279 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7280 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7281 count * sizeof(struct peer_group)));
7282
7283 /* Other */
7284 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7285 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7286 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7287 count * sizeof(struct hash)));
7288 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7289 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7290 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7291 count * sizeof(struct hash_backet)));
7292 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7293 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7294 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7295 count * sizeof(regex_t)));
d62a17ae 7296 return CMD_SUCCESS;
4bf6a362 7297}
fee0f4c6 7298
57a9c8a8
DS
7299static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7300{
7301 json_object *bestpath = json_object_new_object();
7302
7303 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7304 json_object_string_add(bestpath, "asPath", "ignore");
7305
7306 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7307 json_object_string_add(bestpath, "asPath", "confed");
7308
7309 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7310 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7311 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7312 "as-set");
7313 else
a4d82a8a 7314 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7315 "true");
7316 } else
a4d82a8a 7317 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7318
7319 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7320 json_object_string_add(bestpath, "compareRouterId", "true");
7321 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7322 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7323 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7324 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7325 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7326 json_object_string_add(bestpath, "med",
7327 "missing-as-worst");
7328 else
7329 json_object_string_add(bestpath, "med", "true");
7330 }
7331
7332 json_object_object_add(json, "bestPath", bestpath);
7333}
7334
718e3744 7335/* Show BGP peer's summary information. */
d62a17ae 7336static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7337 u_char use_json, json_object *json)
7338{
7339 struct peer *peer;
7340 struct listnode *node, *nnode;
7341 unsigned int count = 0, dn_count = 0;
7342 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7343 char neighbor_buf[VTY_BUFSIZ];
7344 int neighbor_col_default_width = 16;
7345 int len;
7346 int max_neighbor_width = 0;
7347 int pfx_rcd_safi;
7348 json_object *json_peer = NULL;
7349 json_object *json_peers = NULL;
7350
7351 /* labeled-unicast routes are installed in the unicast table so in order
7352 * to
7353 * display the correct PfxRcd value we must look at SAFI_UNICAST
7354 */
7355 if (safi == SAFI_LABELED_UNICAST)
7356 pfx_rcd_safi = SAFI_UNICAST;
7357 else
7358 pfx_rcd_safi = safi;
7359
7360 if (use_json) {
7361 if (json == NULL)
7362 json = json_object_new_object();
7363
7364 json_peers = json_object_new_object();
7365 } else {
7366 /* Loop over all neighbors that will be displayed to determine
7367 * how many
7368 * characters are needed for the Neighbor column
7369 */
7370 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7371 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7372 continue;
7373
7374 if (peer->afc[afi][safi]) {
7375 memset(dn_flag, '\0', sizeof(dn_flag));
7376 if (peer_dynamic_neighbor(peer))
7377 dn_flag[0] = '*';
7378
7379 if (peer->hostname
7380 && bgp_flag_check(bgp,
7381 BGP_FLAG_SHOW_HOSTNAME))
7382 sprintf(neighbor_buf, "%s%s(%s) ",
7383 dn_flag, peer->hostname,
7384 peer->host);
7385 else
7386 sprintf(neighbor_buf, "%s%s ", dn_flag,
7387 peer->host);
7388
7389 len = strlen(neighbor_buf);
7390
7391 if (len > max_neighbor_width)
7392 max_neighbor_width = len;
7393 }
7394 }
f933309e 7395
d62a17ae 7396 /* Originally we displayed the Neighbor column as 16
7397 * characters wide so make that the default
7398 */
7399 if (max_neighbor_width < neighbor_col_default_width)
7400 max_neighbor_width = neighbor_col_default_width;
7401 }
f933309e 7402
d62a17ae 7403 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7404 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7405 continue;
7406
ea47320b
DL
7407 if (!peer->afc[afi][safi])
7408 continue;
d62a17ae 7409
ea47320b
DL
7410 if (!count) {
7411 unsigned long ents;
7412 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7413 int64_t vrf_id_ui;
d62a17ae 7414
a4d82a8a
PZ
7415 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7416 ? -1
7417 : (int64_t)bgp->vrf_id;
ea47320b
DL
7418
7419 /* Usage summary and header */
7420 if (use_json) {
7421 json_object_string_add(
7422 json, "routerId",
7423 inet_ntoa(bgp->router_id));
60466a63
QY
7424 json_object_int_add(json, "as", bgp->as);
7425 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7426 json_object_string_add(
7427 json, "vrfName",
7428 (bgp->inst_type
7429 == BGP_INSTANCE_TYPE_DEFAULT)
7430 ? "Default"
7431 : bgp->name);
7432 } else {
7433 vty_out(vty,
7434 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7435 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7436 bgp->vrf_id == VRF_UNKNOWN
7437 ? -1
7438 : (int)bgp->vrf_id);
ea47320b
DL
7439 vty_out(vty, "\n");
7440 }
d62a17ae 7441
ea47320b 7442 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7443 if (use_json) {
ea47320b 7444 json_object_int_add(
60466a63 7445 json, "updateDelayLimit",
ea47320b 7446 bgp->v_update_delay);
d62a17ae 7447
ea47320b
DL
7448 if (bgp->v_update_delay
7449 != bgp->v_establish_wait)
d62a17ae 7450 json_object_int_add(
7451 json,
ea47320b
DL
7452 "updateDelayEstablishWait",
7453 bgp->v_establish_wait);
d62a17ae 7454
60466a63 7455 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7456 json_object_string_add(
7457 json,
7458 "updateDelayFirstNeighbor",
7459 bgp->update_delay_begin_time);
7460 json_object_boolean_true_add(
7461 json,
7462 "updateDelayInProgress");
7463 } else {
7464 if (bgp->update_delay_over) {
d62a17ae 7465 json_object_string_add(
7466 json,
7467 "updateDelayFirstNeighbor",
7468 bgp->update_delay_begin_time);
ea47320b 7469 json_object_string_add(
d62a17ae 7470 json,
ea47320b
DL
7471 "updateDelayBestpathResumed",
7472 bgp->update_delay_end_time);
7473 json_object_string_add(
d62a17ae 7474 json,
ea47320b
DL
7475 "updateDelayZebraUpdateResume",
7476 bgp->update_delay_zebra_resume_time);
7477 json_object_string_add(
7478 json,
7479 "updateDelayPeerUpdateResume",
7480 bgp->update_delay_peers_resume_time);
d62a17ae 7481 }
ea47320b
DL
7482 }
7483 } else {
7484 vty_out(vty,
7485 "Read-only mode update-delay limit: %d seconds\n",
7486 bgp->v_update_delay);
7487 if (bgp->v_update_delay
7488 != bgp->v_establish_wait)
d62a17ae 7489 vty_out(vty,
ea47320b
DL
7490 " Establish wait: %d seconds\n",
7491 bgp->v_establish_wait);
d62a17ae 7492
60466a63 7493 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7494 vty_out(vty,
7495 " First neighbor established: %s\n",
7496 bgp->update_delay_begin_time);
7497 vty_out(vty,
7498 " Delay in progress\n");
7499 } else {
7500 if (bgp->update_delay_over) {
d62a17ae 7501 vty_out(vty,
7502 " First neighbor established: %s\n",
7503 bgp->update_delay_begin_time);
7504 vty_out(vty,
ea47320b
DL
7505 " Best-paths resumed: %s\n",
7506 bgp->update_delay_end_time);
7507 vty_out(vty,
7508 " zebra update resumed: %s\n",
7509 bgp->update_delay_zebra_resume_time);
7510 vty_out(vty,
7511 " peers update resumed: %s\n",
7512 bgp->update_delay_peers_resume_time);
d62a17ae 7513 }
7514 }
7515 }
ea47320b 7516 }
d62a17ae 7517
ea47320b
DL
7518 if (use_json) {
7519 if (bgp_maxmed_onstartup_configured(bgp)
7520 && bgp->maxmed_active)
7521 json_object_boolean_true_add(
60466a63 7522 json, "maxMedOnStartup");
ea47320b
DL
7523 if (bgp->v_maxmed_admin)
7524 json_object_boolean_true_add(
60466a63 7525 json, "maxMedAdministrative");
d62a17ae 7526
ea47320b
DL
7527 json_object_int_add(
7528 json, "tableVersion",
60466a63 7529 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7530
60466a63
QY
7531 ents = bgp_table_count(bgp->rib[afi][safi]);
7532 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7533 json_object_int_add(
7534 json, "ribMemory",
7535 ents * sizeof(struct bgp_node));
d62a17ae 7536
ea47320b 7537 ents = listcount(bgp->peer);
60466a63
QY
7538 json_object_int_add(json, "peerCount", ents);
7539 json_object_int_add(json, "peerMemory",
7540 ents * sizeof(struct peer));
d62a17ae 7541
ea47320b
DL
7542 if ((ents = listcount(bgp->group))) {
7543 json_object_int_add(
60466a63 7544 json, "peerGroupCount", ents);
ea47320b
DL
7545 json_object_int_add(
7546 json, "peerGroupMemory",
996c9314
LB
7547 ents * sizeof(struct
7548 peer_group));
ea47320b 7549 }
d62a17ae 7550
ea47320b
DL
7551 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7552 BGP_CONFIG_DAMPENING))
7553 json_object_boolean_true_add(
60466a63 7554 json, "dampeningEnabled");
ea47320b
DL
7555 } else {
7556 if (bgp_maxmed_onstartup_configured(bgp)
7557 && bgp->maxmed_active)
d62a17ae 7558 vty_out(vty,
ea47320b
DL
7559 "Max-med on-startup active\n");
7560 if (bgp->v_maxmed_admin)
d62a17ae 7561 vty_out(vty,
ea47320b 7562 "Max-med administrative active\n");
d62a17ae 7563
60466a63
QY
7564 vty_out(vty, "BGP table version %" PRIu64 "\n",
7565 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7566
60466a63 7567 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7568 vty_out(vty,
7569 "RIB entries %ld, using %s of memory\n",
7570 ents,
996c9314
LB
7571 mtype_memstr(memstrbuf,
7572 sizeof(memstrbuf),
7573 ents * sizeof(struct
7574 bgp_node)));
ea47320b
DL
7575
7576 /* Peer related usage */
7577 ents = listcount(bgp->peer);
60466a63 7578 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7579 ents,
7580 mtype_memstr(
60466a63
QY
7581 memstrbuf, sizeof(memstrbuf),
7582 ents * sizeof(struct peer)));
ea47320b
DL
7583
7584 if ((ents = listcount(bgp->group)))
d62a17ae 7585 vty_out(vty,
ea47320b 7586 "Peer groups %ld, using %s of memory\n",
d62a17ae 7587 ents,
7588 mtype_memstr(
7589 memstrbuf,
7590 sizeof(memstrbuf),
996c9314
LB
7591 ents * sizeof(struct
7592 peer_group)));
d62a17ae 7593
ea47320b
DL
7594 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7595 BGP_CONFIG_DAMPENING))
60466a63 7596 vty_out(vty, "Dampening enabled.\n");
ea47320b 7597 vty_out(vty, "\n");
d62a17ae 7598
ea47320b
DL
7599 /* Subtract 8 here because 'Neighbor' is
7600 * 8 characters */
7601 vty_out(vty, "Neighbor");
60466a63
QY
7602 vty_out(vty, "%*s", max_neighbor_width - 8,
7603 " ");
ea47320b
DL
7604 vty_out(vty,
7605 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7606 }
ea47320b 7607 }
d62a17ae 7608
ea47320b 7609 count++;
d62a17ae 7610
ea47320b
DL
7611 if (use_json) {
7612 json_peer = json_object_new_object();
d62a17ae 7613
ea47320b 7614 if (peer_dynamic_neighbor(peer))
60466a63
QY
7615 json_object_boolean_true_add(json_peer,
7616 "dynamicPeer");
d62a17ae 7617
ea47320b 7618 if (peer->hostname)
60466a63 7619 json_object_string_add(json_peer, "hostname",
ea47320b 7620 peer->hostname);
d62a17ae 7621
ea47320b 7622 if (peer->domainname)
60466a63
QY
7623 json_object_string_add(json_peer, "domainname",
7624 peer->domainname);
d62a17ae 7625
60466a63 7626 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7627 json_object_int_add(json_peer, "version", 4);
60466a63 7628 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7629 PEER_TOTAL_RX(peer));
60466a63 7630 json_object_int_add(json_peer, "msgSent",
0112e9e0 7631 PEER_TOTAL_TX(peer));
ea47320b
DL
7632
7633 json_object_int_add(json_peer, "tableVersion",
7634 peer->version[afi][safi]);
7635 json_object_int_add(json_peer, "outq",
7636 peer->obuf->count);
7637 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7638 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7639 use_json, json_peer);
7640 json_object_int_add(json_peer, "prefixReceivedCount",
7641 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7642
ea47320b 7643 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7644 json_object_string_add(json_peer, "state",
ea47320b 7645 "Idle (Admin)");
60466a63
QY
7646 else if (CHECK_FLAG(peer->sflags,
7647 PEER_STATUS_PREFIX_OVERFLOW))
7648 json_object_string_add(json_peer, "state",
ea47320b
DL
7649 "Idle (PfxCt)");
7650 else
7651 json_object_string_add(
7652 json_peer, "state",
60466a63
QY
7653 lookup_msg(bgp_status_msg, peer->status,
7654 NULL));
ea47320b
DL
7655
7656 if (peer->conf_if)
60466a63 7657 json_object_string_add(json_peer, "idType",
ea47320b
DL
7658 "interface");
7659 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7660 json_object_string_add(json_peer, "idType",
7661 "ipv4");
ea47320b 7662 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7663 json_object_string_add(json_peer, "idType",
7664 "ipv6");
d62a17ae 7665
ea47320b
DL
7666 json_object_object_add(json_peers, peer->host,
7667 json_peer);
7668 } else {
7669 memset(dn_flag, '\0', sizeof(dn_flag));
7670 if (peer_dynamic_neighbor(peer)) {
7671 dn_count++;
7672 dn_flag[0] = '*';
7673 }
d62a17ae 7674
ea47320b 7675 if (peer->hostname
60466a63 7676 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7677 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7678 peer->hostname, peer->host);
ea47320b 7679 else
60466a63 7680 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7681
7682 /* pad the neighbor column with spaces */
7683 if (len < max_neighbor_width)
60466a63
QY
7684 vty_out(vty, "%*s", max_neighbor_width - len,
7685 " ");
ea47320b 7686
86a55b99 7687 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7688 peer->as, PEER_TOTAL_RX(peer),
7689 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7690 0, peer->obuf->count,
d62a17ae 7691 peer_uptime(peer->uptime, timebuf,
ea47320b 7692 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7693
ea47320b 7694 if (peer->status == Established)
95077abf
DW
7695 if (peer->afc_recv[afi][pfx_rcd_safi])
7696 vty_out(vty, " %12ld",
a4d82a8a
PZ
7697 peer->pcount[afi]
7698 [pfx_rcd_safi]);
95077abf
DW
7699 else
7700 vty_out(vty, " NoNeg");
ea47320b 7701 else {
60466a63 7702 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7703 vty_out(vty, " Idle (Admin)");
60466a63
QY
7704 else if (CHECK_FLAG(
7705 peer->sflags,
7706 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7707 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7708 else
ea47320b 7709 vty_out(vty, " %12s",
60466a63
QY
7710 lookup_msg(bgp_status_msg,
7711 peer->status, NULL));
d62a17ae 7712 }
ea47320b 7713 vty_out(vty, "\n");
d62a17ae 7714 }
7715 }
f933309e 7716
d62a17ae 7717 if (use_json) {
7718 json_object_object_add(json, "peers", json_peers);
7719
7720 json_object_int_add(json, "totalPeers", count);
7721 json_object_int_add(json, "dynamicPeers", dn_count);
7722
57a9c8a8
DS
7723 bgp_show_bestpath_json(bgp, json);
7724
996c9314
LB
7725 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7726 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7727 json_object_free(json);
7728 } else {
7729 if (count)
7730 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7731 else {
7732 if (use_json)
7733 vty_out(vty,
7734 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7735 afi_safi_print(afi, safi));
7736 else
7737 vty_out(vty, "No %s neighbor is configured\n",
7738 afi_safi_print(afi, safi));
7739 }
b05a1c8b 7740
d62a17ae 7741 if (dn_count && !use_json) {
7742 vty_out(vty, "* - dynamic neighbor\n");
7743 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7744 dn_count, bgp->dynamic_neighbors_limit);
7745 }
7746 }
1ff9a340 7747
d62a17ae 7748 return CMD_SUCCESS;
718e3744 7749}
7750
d62a17ae 7751static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7752 int safi, u_char use_json,
7753 json_object *json)
7754{
7755 int is_first = 1;
7756 int afi_wildcard = (afi == AFI_MAX);
7757 int safi_wildcard = (safi == SAFI_MAX);
7758 int is_wildcard = (afi_wildcard || safi_wildcard);
7759 bool json_output = false;
7760
7761 if (use_json && is_wildcard)
7762 vty_out(vty, "{\n");
7763 if (afi_wildcard)
7764 afi = 1; /* AFI_IP */
7765 while (afi < AFI_MAX) {
7766 if (safi_wildcard)
7767 safi = 1; /* SAFI_UNICAST */
7768 while (safi < SAFI_MAX) {
318cac96 7769 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 7770 json_output = true;
7771 if (is_wildcard) {
7772 /*
7773 * So limit output to those afi/safi
7774 * pairs that
7775 * actualy have something interesting in
7776 * them
7777 */
7778 if (use_json) {
7779 json = json_object_new_object();
7780
7781 if (!is_first)
7782 vty_out(vty, ",\n");
7783 else
7784 is_first = 0;
7785
7786 vty_out(vty, "\"%s\":",
7787 afi_safi_json(afi,
7788 safi));
7789 } else {
7790 vty_out(vty, "\n%s Summary:\n",
7791 afi_safi_print(afi,
7792 safi));
7793 }
7794 }
7795 bgp_show_summary(vty, bgp, afi, safi, use_json,
7796 json);
7797 }
7798 safi++;
d62a17ae 7799 if (!safi_wildcard)
7800 safi = SAFI_MAX;
7801 }
7802 afi++;
ee851c8c 7803 if (!afi_wildcard)
d62a17ae 7804 afi = AFI_MAX;
7805 }
7806
7807 if (use_json && is_wildcard)
7808 vty_out(vty, "}\n");
7809 else if (use_json && !json_output)
7810 vty_out(vty, "{}\n");
7811}
7812
7813static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7814 safi_t safi, u_char use_json)
7815{
7816 struct listnode *node, *nnode;
7817 struct bgp *bgp;
7818 json_object *json = NULL;
7819 int is_first = 1;
7820
7821 if (use_json)
7822 vty_out(vty, "{\n");
7823
7824 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
7825 if (use_json) {
7826 json = json_object_new_object();
7827
7828 if (!is_first)
7829 vty_out(vty, ",\n");
7830 else
7831 is_first = 0;
7832
7833 vty_out(vty, "\"%s\":",
7834 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7835 ? "Default"
7836 : bgp->name);
7837 } else {
7838 vty_out(vty, "\nInstance %s:\n",
7839 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7840 ? "Default"
7841 : bgp->name);
7842 }
7843 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7844 }
7845
7846 if (use_json)
7847 vty_out(vty, "}\n");
7848}
7849
7850int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7851 safi_t safi, u_char use_json)
7852{
7853 struct bgp *bgp;
7854
7855 if (name) {
7856 if (strmatch(name, "all")) {
7857 bgp_show_all_instances_summary_vty(vty, afi, safi,
7858 use_json);
7859 return CMD_SUCCESS;
7860 } else {
7861 bgp = bgp_lookup_by_name(name);
7862
7863 if (!bgp) {
7864 if (use_json)
7865 vty_out(vty, "{}\n");
7866 else
7867 vty_out(vty,
7868 "%% No such BGP instance exist\n");
7869 return CMD_WARNING;
7870 }
7871
7872 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7873 NULL);
7874 return CMD_SUCCESS;
7875 }
7876 }
7877
7878 bgp = bgp_get_default();
7879
7880 if (bgp)
7881 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7882
7883 return CMD_SUCCESS;
4fb25c53
DW
7884}
7885
716b2d8a 7886/* `show [ip] bgp summary' commands. */
47fc97cc 7887DEFUN (show_ip_bgp_summary,
718e3744 7888 show_ip_bgp_summary_cmd,
dd6bd0f1 7889 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 7890 SHOW_STR
7891 IP_STR
7892 BGP_STR
8386ac43 7893 BGP_INSTANCE_HELP_STR
46f296b4 7894 BGP_AFI_HELP_STR
dd6bd0f1 7895 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 7896 "Summary of BGP neighbor status\n"
9973d184 7897 JSON_STR)
718e3744 7898{
d62a17ae 7899 char *vrf = NULL;
7900 afi_t afi = AFI_MAX;
7901 safi_t safi = SAFI_MAX;
7902
7903 int idx = 0;
7904
7905 /* show [ip] bgp */
7906 if (argv_find(argv, argc, "ip", &idx))
7907 afi = AFI_IP;
7908 /* [<view|vrf> VIEWVRFNAME] */
7909 if (argv_find(argv, argc, "view", &idx)
7910 || argv_find(argv, argc, "vrf", &idx))
7911 vrf = argv[++idx]->arg;
7912 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7913 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7914 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7915 }
7916
7917 int uj = use_json(argc, argv);
7918
7919 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7920}
7921
7922const char *afi_safi_print(afi_t afi, safi_t safi)
7923{
7924 if (afi == AFI_IP && safi == SAFI_UNICAST)
7925 return "IPv4 Unicast";
7926 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7927 return "IPv4 Multicast";
7928 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7929 return "IPv4 Labeled Unicast";
7930 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7931 return "IPv4 VPN";
7932 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7933 return "IPv4 Encap";
7934 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7935 return "IPv6 Unicast";
7936 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7937 return "IPv6 Multicast";
7938 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7939 return "IPv6 Labeled Unicast";
7940 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7941 return "IPv6 VPN";
7942 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7943 return "IPv6 Encap";
7944 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7945 return "L2VPN EVPN";
7946 else
7947 return "Unknown";
538621f2 7948}
7949
b9f77ec8
DS
7950/*
7951 * Please note that we have intentionally camelCased
7952 * the return strings here. So if you want
7953 * to use this function, please ensure you
7954 * are doing this within json output
7955 */
d62a17ae 7956const char *afi_safi_json(afi_t afi, safi_t safi)
7957{
7958 if (afi == AFI_IP && safi == SAFI_UNICAST)
7959 return "ipv4Unicast";
7960 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7961 return "ipv4Multicast";
7962 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7963 return "ipv4LabeledUnicast";
7964 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7965 return "ipv4Vpn";
7966 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7967 return "ipv4Encap";
7968 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7969 return "ipv6Unicast";
7970 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7971 return "ipv6Multicast";
7972 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7973 return "ipv6LabeledUnicast";
7974 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7975 return "ipv6Vpn";
7976 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7977 return "ipv6Encap";
7978 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7979 return "l2VpnEvpn";
7980 else
7981 return "Unknown";
27162734
LB
7982}
7983
718e3744 7984/* Show BGP peer's information. */
d62a17ae 7985enum show_type { show_all, show_peer };
7986
7987static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7988 afi_t afi, safi_t safi,
7989 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7990 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7991 u_char use_json, json_object *json_pref)
7992{
7993 /* Send-Mode */
7994 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7995 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7996 if (use_json) {
7997 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7998 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7999 json_object_string_add(json_pref, "sendMode",
8000 "advertisedAndReceived");
8001 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8002 json_object_string_add(json_pref, "sendMode",
8003 "advertised");
8004 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8005 json_object_string_add(json_pref, "sendMode",
8006 "received");
8007 } else {
8008 vty_out(vty, " Send-mode: ");
8009 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
8010 vty_out(vty, "advertised");
8011 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
8012 vty_out(vty, "%sreceived",
8013 CHECK_FLAG(p->af_cap[afi][safi],
8014 adv_smcap)
8015 ? ", "
8016 : "");
8017 vty_out(vty, "\n");
8018 }
8019 }
8020
8021 /* Receive-Mode */
8022 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8023 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
8024 if (use_json) {
8025 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
8026 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8027 json_object_string_add(json_pref, "recvMode",
8028 "advertisedAndReceived");
8029 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8030 json_object_string_add(json_pref, "recvMode",
8031 "advertised");
8032 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8033 json_object_string_add(json_pref, "recvMode",
8034 "received");
8035 } else {
8036 vty_out(vty, " Receive-mode: ");
8037 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
8038 vty_out(vty, "advertised");
8039 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
8040 vty_out(vty, "%sreceived",
8041 CHECK_FLAG(p->af_cap[afi][safi],
8042 adv_rmcap)
8043 ? ", "
8044 : "");
8045 vty_out(vty, "\n");
8046 }
8047 }
8048}
8049
8050static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8051 safi_t safi, u_char use_json,
8052 json_object *json_neigh)
8053{
0291c246
MK
8054 struct bgp_filter *filter;
8055 struct peer_af *paf;
8056 char orf_pfx_name[BUFSIZ];
8057 int orf_pfx_count;
8058 json_object *json_af = NULL;
8059 json_object *json_prefA = NULL;
8060 json_object *json_prefB = NULL;
8061 json_object *json_addr = NULL;
d62a17ae 8062
8063 if (use_json) {
8064 json_addr = json_object_new_object();
8065 json_af = json_object_new_object();
8066 filter = &p->filter[afi][safi];
8067
8068 if (peer_group_active(p))
8069 json_object_string_add(json_addr, "peerGroupMember",
8070 p->group->name);
8071
8072 paf = peer_af_find(p, afi, safi);
8073 if (paf && PAF_SUBGRP(paf)) {
8074 json_object_int_add(json_addr, "updateGroupId",
8075 PAF_UPDGRP(paf)->id);
8076 json_object_int_add(json_addr, "subGroupId",
8077 PAF_SUBGRP(paf)->id);
8078 json_object_int_add(json_addr, "packetQueueLength",
8079 bpacket_queue_virtual_length(paf));
8080 }
8081
8082 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8083 || CHECK_FLAG(p->af_cap[afi][safi],
8084 PEER_CAP_ORF_PREFIX_SM_RCV)
8085 || CHECK_FLAG(p->af_cap[afi][safi],
8086 PEER_CAP_ORF_PREFIX_RM_ADV)
8087 || CHECK_FLAG(p->af_cap[afi][safi],
8088 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8089 json_object_int_add(json_af, "orfType",
8090 ORF_TYPE_PREFIX);
8091 json_prefA = json_object_new_object();
8092 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8093 PEER_CAP_ORF_PREFIX_SM_ADV,
8094 PEER_CAP_ORF_PREFIX_RM_ADV,
8095 PEER_CAP_ORF_PREFIX_SM_RCV,
8096 PEER_CAP_ORF_PREFIX_RM_RCV,
8097 use_json, json_prefA);
8098 json_object_object_add(json_af, "orfPrefixList",
8099 json_prefA);
8100 }
8101
8102 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8103 || CHECK_FLAG(p->af_cap[afi][safi],
8104 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8105 || CHECK_FLAG(p->af_cap[afi][safi],
8106 PEER_CAP_ORF_PREFIX_RM_ADV)
8107 || CHECK_FLAG(p->af_cap[afi][safi],
8108 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8109 json_object_int_add(json_af, "orfOldType",
8110 ORF_TYPE_PREFIX_OLD);
8111 json_prefB = json_object_new_object();
8112 bgp_show_peer_afi_orf_cap(
8113 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8114 PEER_CAP_ORF_PREFIX_RM_ADV,
8115 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8116 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8117 json_prefB);
8118 json_object_object_add(json_af, "orfOldPrefixList",
8119 json_prefB);
8120 }
8121
8122 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8123 || CHECK_FLAG(p->af_cap[afi][safi],
8124 PEER_CAP_ORF_PREFIX_SM_RCV)
8125 || CHECK_FLAG(p->af_cap[afi][safi],
8126 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8127 || CHECK_FLAG(p->af_cap[afi][safi],
8128 PEER_CAP_ORF_PREFIX_RM_ADV)
8129 || CHECK_FLAG(p->af_cap[afi][safi],
8130 PEER_CAP_ORF_PREFIX_RM_RCV)
8131 || CHECK_FLAG(p->af_cap[afi][safi],
8132 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8133 json_object_object_add(json_addr, "afDependentCap",
8134 json_af);
8135 else
8136 json_object_free(json_af);
8137
8138 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8139 orf_pfx_count = prefix_bgp_show_prefix_list(
8140 NULL, afi, orf_pfx_name, use_json);
8141
8142 if (CHECK_FLAG(p->af_sflags[afi][safi],
8143 PEER_STATUS_ORF_PREFIX_SEND)
8144 || orf_pfx_count) {
8145 if (CHECK_FLAG(p->af_sflags[afi][safi],
8146 PEER_STATUS_ORF_PREFIX_SEND))
8147 json_object_boolean_true_add(json_neigh,
8148 "orfSent");
8149 if (orf_pfx_count)
8150 json_object_int_add(json_addr, "orfRecvCounter",
8151 orf_pfx_count);
8152 }
8153 if (CHECK_FLAG(p->af_sflags[afi][safi],
8154 PEER_STATUS_ORF_WAIT_REFRESH))
8155 json_object_string_add(
8156 json_addr, "orfFirstUpdate",
8157 "deferredUntilORFOrRouteRefreshRecvd");
8158
8159 if (CHECK_FLAG(p->af_flags[afi][safi],
8160 PEER_FLAG_REFLECTOR_CLIENT))
8161 json_object_boolean_true_add(json_addr,
8162 "routeReflectorClient");
8163 if (CHECK_FLAG(p->af_flags[afi][safi],
8164 PEER_FLAG_RSERVER_CLIENT))
8165 json_object_boolean_true_add(json_addr,
8166 "routeServerClient");
8167 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8168 json_object_boolean_true_add(json_addr,
8169 "inboundSoftConfigPermit");
8170
8171 if (CHECK_FLAG(p->af_flags[afi][safi],
8172 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8173 json_object_boolean_true_add(
8174 json_addr,
8175 "privateAsNumsAllReplacedInUpdatesToNbr");
8176 else if (CHECK_FLAG(p->af_flags[afi][safi],
8177 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8178 json_object_boolean_true_add(
8179 json_addr,
8180 "privateAsNumsReplacedInUpdatesToNbr");
8181 else if (CHECK_FLAG(p->af_flags[afi][safi],
8182 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8183 json_object_boolean_true_add(
8184 json_addr,
8185 "privateAsNumsAllRemovedInUpdatesToNbr");
8186 else if (CHECK_FLAG(p->af_flags[afi][safi],
8187 PEER_FLAG_REMOVE_PRIVATE_AS))
8188 json_object_boolean_true_add(
8189 json_addr,
8190 "privateAsNumsRemovedInUpdatesToNbr");
8191
8192 if (CHECK_FLAG(p->af_flags[afi][safi],
8193 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8194 json_object_boolean_true_add(json_addr,
8195 "addpathTxAllPaths");
8196
8197 if (CHECK_FLAG(p->af_flags[afi][safi],
8198 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8199 json_object_boolean_true_add(json_addr,
8200 "addpathTxBestpathPerAS");
8201
8202 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8203 json_object_string_add(json_addr,
8204 "overrideASNsInOutboundUpdates",
8205 "ifAspathEqualRemoteAs");
8206
8207 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8208 || CHECK_FLAG(p->af_flags[afi][safi],
8209 PEER_FLAG_FORCE_NEXTHOP_SELF))
8210 json_object_boolean_true_add(json_addr,
8211 "routerAlwaysNextHop");
8212 if (CHECK_FLAG(p->af_flags[afi][safi],
8213 PEER_FLAG_AS_PATH_UNCHANGED))
8214 json_object_boolean_true_add(
8215 json_addr, "unchangedAsPathPropogatedToNbr");
8216 if (CHECK_FLAG(p->af_flags[afi][safi],
8217 PEER_FLAG_NEXTHOP_UNCHANGED))
8218 json_object_boolean_true_add(
8219 json_addr, "unchangedNextHopPropogatedToNbr");
8220 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8221 json_object_boolean_true_add(
8222 json_addr, "unchangedMedPropogatedToNbr");
8223 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8224 || CHECK_FLAG(p->af_flags[afi][safi],
8225 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8226 if (CHECK_FLAG(p->af_flags[afi][safi],
8227 PEER_FLAG_SEND_COMMUNITY)
8228 && CHECK_FLAG(p->af_flags[afi][safi],
8229 PEER_FLAG_SEND_EXT_COMMUNITY))
8230 json_object_string_add(json_addr,
8231 "commAttriSentToNbr",
8232 "extendedAndStandard");
8233 else if (CHECK_FLAG(p->af_flags[afi][safi],
8234 PEER_FLAG_SEND_EXT_COMMUNITY))
8235 json_object_string_add(json_addr,
8236 "commAttriSentToNbr",
8237 "extended");
8238 else
8239 json_object_string_add(json_addr,
8240 "commAttriSentToNbr",
8241 "standard");
8242 }
8243 if (CHECK_FLAG(p->af_flags[afi][safi],
8244 PEER_FLAG_DEFAULT_ORIGINATE)) {
8245 if (p->default_rmap[afi][safi].name)
8246 json_object_string_add(
8247 json_addr, "defaultRouteMap",
8248 p->default_rmap[afi][safi].name);
8249
8250 if (paf && PAF_SUBGRP(paf)
8251 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8252 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8253 json_object_boolean_true_add(json_addr,
8254 "defaultSent");
8255 else
8256 json_object_boolean_true_add(json_addr,
8257 "defaultNotSent");
8258 }
8259
dff8f48d 8260 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8261 if (is_evpn_enabled())
60466a63
QY
8262 json_object_boolean_true_add(
8263 json_addr, "advertiseAllVnis");
dff8f48d
MK
8264 }
8265
d62a17ae 8266 if (filter->plist[FILTER_IN].name
8267 || filter->dlist[FILTER_IN].name
8268 || filter->aslist[FILTER_IN].name
8269 || filter->map[RMAP_IN].name)
8270 json_object_boolean_true_add(json_addr,
8271 "inboundPathPolicyConfig");
8272 if (filter->plist[FILTER_OUT].name
8273 || filter->dlist[FILTER_OUT].name
8274 || filter->aslist[FILTER_OUT].name
8275 || filter->map[RMAP_OUT].name || filter->usmap.name)
8276 json_object_boolean_true_add(
8277 json_addr, "outboundPathPolicyConfig");
8278
8279 /* prefix-list */
8280 if (filter->plist[FILTER_IN].name)
8281 json_object_string_add(json_addr,
8282 "incomingUpdatePrefixFilterList",
8283 filter->plist[FILTER_IN].name);
8284 if (filter->plist[FILTER_OUT].name)
8285 json_object_string_add(json_addr,
8286 "outgoingUpdatePrefixFilterList",
8287 filter->plist[FILTER_OUT].name);
8288
8289 /* distribute-list */
8290 if (filter->dlist[FILTER_IN].name)
8291 json_object_string_add(
8292 json_addr, "incomingUpdateNetworkFilterList",
8293 filter->dlist[FILTER_IN].name);
8294 if (filter->dlist[FILTER_OUT].name)
8295 json_object_string_add(
8296 json_addr, "outgoingUpdateNetworkFilterList",
8297 filter->dlist[FILTER_OUT].name);
8298
8299 /* filter-list. */
8300 if (filter->aslist[FILTER_IN].name)
8301 json_object_string_add(json_addr,
8302 "incomingUpdateAsPathFilterList",
8303 filter->aslist[FILTER_IN].name);
8304 if (filter->aslist[FILTER_OUT].name)
8305 json_object_string_add(json_addr,
8306 "outgoingUpdateAsPathFilterList",
8307 filter->aslist[FILTER_OUT].name);
8308
8309 /* route-map. */
8310 if (filter->map[RMAP_IN].name)
8311 json_object_string_add(
8312 json_addr, "routeMapForIncomingAdvertisements",
8313 filter->map[RMAP_IN].name);
8314 if (filter->map[RMAP_OUT].name)
8315 json_object_string_add(
8316 json_addr, "routeMapForOutgoingAdvertisements",
8317 filter->map[RMAP_OUT].name);
8318
8319 /* unsuppress-map */
8320 if (filter->usmap.name)
8321 json_object_string_add(json_addr,
8322 "selectiveUnsuppressRouteMap",
8323 filter->usmap.name);
8324
8325 /* Receive prefix count */
8326 json_object_int_add(json_addr, "acceptedPrefixCounter",
8327 p->pcount[afi][safi]);
8328
8329 /* Maximum prefix */
8330 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8331 json_object_int_add(json_addr, "prefixAllowedMax",
8332 p->pmax[afi][safi]);
8333 if (CHECK_FLAG(p->af_flags[afi][safi],
8334 PEER_FLAG_MAX_PREFIX_WARNING))
8335 json_object_boolean_true_add(
8336 json_addr, "prefixAllowedMaxWarning");
8337 json_object_int_add(json_addr,
8338 "prefixAllowedWarningThresh",
8339 p->pmax_threshold[afi][safi]);
8340 if (p->pmax_restart[afi][safi])
8341 json_object_int_add(
8342 json_addr,
8343 "prefixAllowedRestartIntervalMsecs",
8344 p->pmax_restart[afi][safi] * 60000);
8345 }
8346 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8347 json_addr);
8348
8349 } else {
8350 filter = &p->filter[afi][safi];
8351
8352 vty_out(vty, " For address family: %s\n",
8353 afi_safi_print(afi, safi));
8354
8355 if (peer_group_active(p))
8356 vty_out(vty, " %s peer-group member\n",
8357 p->group->name);
8358
8359 paf = peer_af_find(p, afi, safi);
8360 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8361 vty_out(vty, " Update group %" PRIu64
8362 ", subgroup %" PRIu64 "\n",
d62a17ae 8363 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8364 vty_out(vty, " Packet Queue length %d\n",
8365 bpacket_queue_virtual_length(paf));
8366 } else {
8367 vty_out(vty, " Not part of any update group\n");
8368 }
8369 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8370 || CHECK_FLAG(p->af_cap[afi][safi],
8371 PEER_CAP_ORF_PREFIX_SM_RCV)
8372 || CHECK_FLAG(p->af_cap[afi][safi],
8373 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8374 || CHECK_FLAG(p->af_cap[afi][safi],
8375 PEER_CAP_ORF_PREFIX_RM_ADV)
8376 || CHECK_FLAG(p->af_cap[afi][safi],
8377 PEER_CAP_ORF_PREFIX_RM_RCV)
8378 || CHECK_FLAG(p->af_cap[afi][safi],
8379 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8380 vty_out(vty, " AF-dependant capabilities:\n");
8381
8382 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8383 || CHECK_FLAG(p->af_cap[afi][safi],
8384 PEER_CAP_ORF_PREFIX_SM_RCV)
8385 || CHECK_FLAG(p->af_cap[afi][safi],
8386 PEER_CAP_ORF_PREFIX_RM_ADV)
8387 || CHECK_FLAG(p->af_cap[afi][safi],
8388 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8389 vty_out(vty,
8390 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8391 ORF_TYPE_PREFIX);
8392 bgp_show_peer_afi_orf_cap(
8393 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8394 PEER_CAP_ORF_PREFIX_RM_ADV,
8395 PEER_CAP_ORF_PREFIX_SM_RCV,
8396 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8397 }
8398 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8399 || CHECK_FLAG(p->af_cap[afi][safi],
8400 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8401 || CHECK_FLAG(p->af_cap[afi][safi],
8402 PEER_CAP_ORF_PREFIX_RM_ADV)
8403 || CHECK_FLAG(p->af_cap[afi][safi],
8404 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8405 vty_out(vty,
8406 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8407 ORF_TYPE_PREFIX_OLD);
8408 bgp_show_peer_afi_orf_cap(
8409 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8410 PEER_CAP_ORF_PREFIX_RM_ADV,
8411 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8412 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8413 }
8414
8415 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8416 orf_pfx_count = prefix_bgp_show_prefix_list(
8417 NULL, afi, orf_pfx_name, use_json);
8418
8419 if (CHECK_FLAG(p->af_sflags[afi][safi],
8420 PEER_STATUS_ORF_PREFIX_SEND)
8421 || orf_pfx_count) {
8422 vty_out(vty, " Outbound Route Filter (ORF):");
8423 if (CHECK_FLAG(p->af_sflags[afi][safi],
8424 PEER_STATUS_ORF_PREFIX_SEND))
8425 vty_out(vty, " sent;");
8426 if (orf_pfx_count)
8427 vty_out(vty, " received (%d entries)",
8428 orf_pfx_count);
8429 vty_out(vty, "\n");
8430 }
8431 if (CHECK_FLAG(p->af_sflags[afi][safi],
8432 PEER_STATUS_ORF_WAIT_REFRESH))
8433 vty_out(vty,
8434 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8435
8436 if (CHECK_FLAG(p->af_flags[afi][safi],
8437 PEER_FLAG_REFLECTOR_CLIENT))
8438 vty_out(vty, " Route-Reflector Client\n");
8439 if (CHECK_FLAG(p->af_flags[afi][safi],
8440 PEER_FLAG_RSERVER_CLIENT))
8441 vty_out(vty, " Route-Server Client\n");
8442 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8443 vty_out(vty,
8444 " Inbound soft reconfiguration allowed\n");
8445
8446 if (CHECK_FLAG(p->af_flags[afi][safi],
8447 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8448 vty_out(vty,
8449 " Private AS numbers (all) replaced in updates to this neighbor\n");
8450 else if (CHECK_FLAG(p->af_flags[afi][safi],
8451 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8452 vty_out(vty,
8453 " Private AS numbers replaced in updates to this neighbor\n");
8454 else if (CHECK_FLAG(p->af_flags[afi][safi],
8455 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8456 vty_out(vty,
8457 " Private AS numbers (all) removed in updates to this neighbor\n");
8458 else if (CHECK_FLAG(p->af_flags[afi][safi],
8459 PEER_FLAG_REMOVE_PRIVATE_AS))
8460 vty_out(vty,
8461 " Private AS numbers removed in updates to this neighbor\n");
8462
8463 if (CHECK_FLAG(p->af_flags[afi][safi],
8464 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8465 vty_out(vty, " Advertise all paths via addpath\n");
8466
8467 if (CHECK_FLAG(p->af_flags[afi][safi],
8468 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8469 vty_out(vty,
8470 " Advertise bestpath per AS via addpath\n");
8471
8472 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8473 vty_out(vty,
8474 " Override ASNs in outbound updates if aspath equals remote-as\n");
8475
8476 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8477 || CHECK_FLAG(p->af_flags[afi][safi],
8478 PEER_FLAG_FORCE_NEXTHOP_SELF))
8479 vty_out(vty, " NEXT_HOP is always this router\n");
8480 if (CHECK_FLAG(p->af_flags[afi][safi],
8481 PEER_FLAG_AS_PATH_UNCHANGED))
8482 vty_out(vty,
8483 " AS_PATH is propagated unchanged to this neighbor\n");
8484 if (CHECK_FLAG(p->af_flags[afi][safi],
8485 PEER_FLAG_NEXTHOP_UNCHANGED))
8486 vty_out(vty,
8487 " NEXT_HOP is propagated unchanged to this neighbor\n");
8488 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8489 vty_out(vty,
8490 " MED is propagated unchanged to this neighbor\n");
8491 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8492 || CHECK_FLAG(p->af_flags[afi][safi],
8493 PEER_FLAG_SEND_EXT_COMMUNITY)
8494 || CHECK_FLAG(p->af_flags[afi][safi],
8495 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8496 vty_out(vty,
8497 " Community attribute sent to this neighbor");
8498 if (CHECK_FLAG(p->af_flags[afi][safi],
8499 PEER_FLAG_SEND_COMMUNITY)
8500 && CHECK_FLAG(p->af_flags[afi][safi],
8501 PEER_FLAG_SEND_EXT_COMMUNITY)
8502 && CHECK_FLAG(p->af_flags[afi][safi],
8503 PEER_FLAG_SEND_LARGE_COMMUNITY))
8504 vty_out(vty, "(all)\n");
8505 else if (CHECK_FLAG(p->af_flags[afi][safi],
8506 PEER_FLAG_SEND_LARGE_COMMUNITY))
8507 vty_out(vty, "(large)\n");
8508 else if (CHECK_FLAG(p->af_flags[afi][safi],
8509 PEER_FLAG_SEND_EXT_COMMUNITY))
8510 vty_out(vty, "(extended)\n");
8511 else
8512 vty_out(vty, "(standard)\n");
8513 }
8514 if (CHECK_FLAG(p->af_flags[afi][safi],
8515 PEER_FLAG_DEFAULT_ORIGINATE)) {
8516 vty_out(vty, " Default information originate,");
8517
8518 if (p->default_rmap[afi][safi].name)
8519 vty_out(vty, " default route-map %s%s,",
8520 p->default_rmap[afi][safi].map ? "*"
8521 : "",
8522 p->default_rmap[afi][safi].name);
8523 if (paf && PAF_SUBGRP(paf)
8524 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8525 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8526 vty_out(vty, " default sent\n");
8527 else
8528 vty_out(vty, " default not sent\n");
8529 }
8530
dff8f48d
MK
8531 /* advertise-vni-all */
8532 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8533 if (is_evpn_enabled())
dff8f48d
MK
8534 vty_out(vty, " advertise-all-vni\n");
8535 }
8536
d62a17ae 8537 if (filter->plist[FILTER_IN].name
8538 || filter->dlist[FILTER_IN].name
8539 || filter->aslist[FILTER_IN].name
8540 || filter->map[RMAP_IN].name)
8541 vty_out(vty, " Inbound path policy configured\n");
8542 if (filter->plist[FILTER_OUT].name
8543 || filter->dlist[FILTER_OUT].name
8544 || filter->aslist[FILTER_OUT].name
8545 || filter->map[RMAP_OUT].name || filter->usmap.name)
8546 vty_out(vty, " Outbound path policy configured\n");
8547
8548 /* prefix-list */
8549 if (filter->plist[FILTER_IN].name)
8550 vty_out(vty,
8551 " Incoming update prefix filter list is %s%s\n",
8552 filter->plist[FILTER_IN].plist ? "*" : "",
8553 filter->plist[FILTER_IN].name);
8554 if (filter->plist[FILTER_OUT].name)
8555 vty_out(vty,
8556 " Outgoing update prefix filter list is %s%s\n",
8557 filter->plist[FILTER_OUT].plist ? "*" : "",
8558 filter->plist[FILTER_OUT].name);
8559
8560 /* distribute-list */
8561 if (filter->dlist[FILTER_IN].name)
8562 vty_out(vty,
8563 " Incoming update network filter list is %s%s\n",
8564 filter->dlist[FILTER_IN].alist ? "*" : "",
8565 filter->dlist[FILTER_IN].name);
8566 if (filter->dlist[FILTER_OUT].name)
8567 vty_out(vty,
8568 " Outgoing update network filter list is %s%s\n",
8569 filter->dlist[FILTER_OUT].alist ? "*" : "",
8570 filter->dlist[FILTER_OUT].name);
8571
8572 /* filter-list. */
8573 if (filter->aslist[FILTER_IN].name)
8574 vty_out(vty,
8575 " Incoming update AS path filter list is %s%s\n",
8576 filter->aslist[FILTER_IN].aslist ? "*" : "",
8577 filter->aslist[FILTER_IN].name);
8578 if (filter->aslist[FILTER_OUT].name)
8579 vty_out(vty,
8580 " Outgoing update AS path filter list is %s%s\n",
8581 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8582 filter->aslist[FILTER_OUT].name);
8583
8584 /* route-map. */
8585 if (filter->map[RMAP_IN].name)
8586 vty_out(vty,
8587 " Route map for incoming advertisements is %s%s\n",
8588 filter->map[RMAP_IN].map ? "*" : "",
8589 filter->map[RMAP_IN].name);
8590 if (filter->map[RMAP_OUT].name)
8591 vty_out(vty,
8592 " Route map for outgoing advertisements is %s%s\n",
8593 filter->map[RMAP_OUT].map ? "*" : "",
8594 filter->map[RMAP_OUT].name);
8595
8596 /* unsuppress-map */
8597 if (filter->usmap.name)
8598 vty_out(vty,
8599 " Route map for selective unsuppress is %s%s\n",
8600 filter->usmap.map ? "*" : "",
8601 filter->usmap.name);
8602
8603 /* Receive prefix count */
8604 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8605
8606 /* Maximum prefix */
8607 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8608 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8609 p->pmax[afi][safi],
8610 CHECK_FLAG(p->af_flags[afi][safi],
8611 PEER_FLAG_MAX_PREFIX_WARNING)
8612 ? " (warning-only)"
8613 : "");
8614 vty_out(vty, " Threshold for warning message %d%%",
8615 p->pmax_threshold[afi][safi]);
8616 if (p->pmax_restart[afi][safi])
8617 vty_out(vty, ", restart interval %d min",
8618 p->pmax_restart[afi][safi]);
8619 vty_out(vty, "\n");
8620 }
8621
8622 vty_out(vty, "\n");
8623 }
8624}
8625
8626static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
8627 json_object *json)
718e3744 8628{
d62a17ae 8629 struct bgp *bgp;
8630 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8631 char timebuf[BGP_UPTIME_LEN];
8632 char dn_flag[2];
8633 const char *subcode_str;
8634 const char *code_str;
8635 afi_t afi;
8636 safi_t safi;
8637 u_int16_t i;
8638 u_char *msg;
8639 json_object *json_neigh = NULL;
8640 time_t epoch_tbuf;
718e3744 8641
d62a17ae 8642 bgp = p->bgp;
8643
8644 if (use_json)
8645 json_neigh = json_object_new_object();
8646
8647 memset(dn_flag, '\0', sizeof(dn_flag));
8648 if (!p->conf_if && peer_dynamic_neighbor(p))
8649 dn_flag[0] = '*';
8650
8651 if (!use_json) {
8652 if (p->conf_if) /* Configured interface name. */
8653 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8654 BGP_PEER_SU_UNSPEC(p)
8655 ? "None"
8656 : sockunion2str(&p->su, buf,
8657 SU_ADDRSTRLEN));
8658 else /* Configured IP address. */
8659 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8660 p->host);
8661 }
8662
8663 if (use_json) {
8664 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8665 json_object_string_add(json_neigh, "bgpNeighborAddr",
8666 "none");
8667 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8668 json_object_string_add(
8669 json_neigh, "bgpNeighborAddr",
8670 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8671
8672 json_object_int_add(json_neigh, "remoteAs", p->as);
8673
8674 if (p->change_local_as)
8675 json_object_int_add(json_neigh, "localAs",
8676 p->change_local_as);
8677 else
8678 json_object_int_add(json_neigh, "localAs", p->local_as);
8679
8680 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8681 json_object_boolean_true_add(json_neigh,
8682 "localAsNoPrepend");
8683
8684 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8685 json_object_boolean_true_add(json_neigh,
8686 "localAsReplaceAs");
8687 } else {
8688 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8689 || (p->as_type == AS_INTERNAL))
8690 vty_out(vty, "remote AS %u, ", p->as);
8691 else
8692 vty_out(vty, "remote AS Unspecified, ");
8693 vty_out(vty, "local AS %u%s%s, ",
8694 p->change_local_as ? p->change_local_as : p->local_as,
8695 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8696 ? " no-prepend"
8697 : "",
8698 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8699 ? " replace-as"
8700 : "");
8701 }
8702 /* peer type internal, external, confed-internal or confed-external */
8703 if (p->as == p->local_as) {
8704 if (use_json) {
8705 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8706 json_object_boolean_true_add(
8707 json_neigh, "nbrConfedInternalLink");
8708 else
8709 json_object_boolean_true_add(json_neigh,
8710 "nbrInternalLink");
8711 } else {
8712 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8713 vty_out(vty, "confed-internal link\n");
8714 else
8715 vty_out(vty, "internal link\n");
8716 }
8717 } else {
8718 if (use_json) {
8719 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8720 json_object_boolean_true_add(
8721 json_neigh, "nbrConfedExternalLink");
8722 else
8723 json_object_boolean_true_add(json_neigh,
8724 "nbrExternalLink");
8725 } else {
8726 if (bgp_confederation_peers_check(bgp, p->as))
8727 vty_out(vty, "confed-external link\n");
8728 else
8729 vty_out(vty, "external link\n");
8730 }
8731 }
8732
8733 /* Description. */
8734 if (p->desc) {
8735 if (use_json)
8736 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8737 else
8738 vty_out(vty, " Description: %s\n", p->desc);
8739 }
8740
8741 if (p->hostname) {
8742 if (use_json) {
8743 if (p->hostname)
8744 json_object_string_add(json_neigh, "hostname",
8745 p->hostname);
8746
8747 if (p->domainname)
8748 json_object_string_add(json_neigh, "domainname",
8749 p->domainname);
8750 } else {
8751 if (p->domainname && (p->domainname[0] != '\0'))
8752 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8753 p->domainname);
8754 else
8755 vty_out(vty, "Hostname: %s\n", p->hostname);
8756 }
8757 }
8758
8759 /* Peer-group */
8760 if (p->group) {
8761 if (use_json) {
8762 json_object_string_add(json_neigh, "peerGroup",
8763 p->group->name);
8764
8765 if (dn_flag[0]) {
8766 struct prefix prefix, *range = NULL;
8767
8768 sockunion2hostprefix(&(p->su), &prefix);
8769 range = peer_group_lookup_dynamic_neighbor_range(
8770 p->group, &prefix);
8771
8772 if (range) {
8773 prefix2str(range, buf1, sizeof(buf1));
8774 json_object_string_add(
8775 json_neigh,
8776 "peerSubnetRangeGroup", buf1);
8777 }
8778 }
8779 } else {
8780 vty_out(vty,
8781 " Member of peer-group %s for session parameters\n",
8782 p->group->name);
8783
8784 if (dn_flag[0]) {
8785 struct prefix prefix, *range = NULL;
8786
8787 sockunion2hostprefix(&(p->su), &prefix);
8788 range = peer_group_lookup_dynamic_neighbor_range(
8789 p->group, &prefix);
8790
8791 if (range) {
8792 prefix2str(range, buf1, sizeof(buf1));
8793 vty_out(vty,
8794 " Belongs to the subnet range group: %s\n",
8795 buf1);
8796 }
8797 }
8798 }
8799 }
8800
8801 if (use_json) {
8802 /* Administrative shutdown. */
8803 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8804 json_object_boolean_true_add(json_neigh,
8805 "adminShutDown");
8806
8807 /* BGP Version. */
8808 json_object_int_add(json_neigh, "bgpVersion", 4);
8809 json_object_string_add(
8810 json_neigh, "remoteRouterId",
8811 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8812
8813 /* Confederation */
8814 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8815 && bgp_confederation_peers_check(bgp, p->as))
8816 json_object_boolean_true_add(json_neigh,
8817 "nbrCommonAdmin");
8818
8819 /* Status. */
8820 json_object_string_add(
8821 json_neigh, "bgpState",
8822 lookup_msg(bgp_status_msg, p->status, NULL));
8823
8824 if (p->status == Established) {
8825 time_t uptime;
d62a17ae 8826
8827 uptime = bgp_clock();
8828 uptime -= p->uptime;
d62a17ae 8829 epoch_tbuf = time(NULL) - uptime;
8830
d3c7efed 8831#if CONFDATE > 20200101
a4d82a8a
PZ
8832 CPP_NOTICE(
8833 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
8834#endif
8835 /*
8836 * bgpTimerUp was miliseconds that was accurate
8837 * up to 1 day, then the value returned
8838 * became garbage. So in order to provide
8839 * some level of backwards compatability,
8840 * we still provde the data, but now
8841 * we are returning the correct value
8842 * and also adding a new bgpTimerUpMsec
8843 * which will allow us to deprecate
8844 * this eventually
8845 */
d62a17ae 8846 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 8847 uptime * 1000);
d3c7efed
DS
8848 json_object_int_add(json_neigh, "bgpTimerUpMsec",
8849 uptime * 1000);
d62a17ae 8850 json_object_string_add(json_neigh, "bgpTimerUpString",
8851 peer_uptime(p->uptime, timebuf,
8852 BGP_UPTIME_LEN, 0,
8853 NULL));
8854 json_object_int_add(json_neigh,
8855 "bgpTimerUpEstablishedEpoch",
8856 epoch_tbuf);
8857 }
8858
8859 else if (p->status == Active) {
8860 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8861 json_object_string_add(json_neigh, "bgpStateIs",
8862 "passive");
8863 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8864 json_object_string_add(json_neigh, "bgpStateIs",
8865 "passiveNSF");
8866 }
8867
8868 /* read timer */
8869 time_t uptime;
8870 struct tm *tm;
8871
8872 uptime = bgp_clock();
8873 uptime -= p->readtime;
8874 tm = gmtime(&uptime);
8875 json_object_int_add(json_neigh, "bgpTimerLastRead",
8876 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8877 + (tm->tm_hour * 3600000));
8878
8879 uptime = bgp_clock();
8880 uptime -= p->last_write;
8881 tm = gmtime(&uptime);
8882 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8883 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8884 + (tm->tm_hour * 3600000));
8885
8886 uptime = bgp_clock();
8887 uptime -= p->update_time;
8888 tm = gmtime(&uptime);
8889 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8890 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8891 + (tm->tm_hour * 3600000));
8892
8893 /* Configured timer values. */
8894 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8895 p->v_holdtime * 1000);
8896 json_object_int_add(json_neigh,
8897 "bgpTimerKeepAliveIntervalMsecs",
8898 p->v_keepalive * 1000);
8899
d25e4efc 8900 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8901 json_object_int_add(json_neigh,
8902 "bgpTimerConfiguredHoldTimeMsecs",
8903 p->holdtime * 1000);
8904 json_object_int_add(
8905 json_neigh,
8906 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8907 p->keepalive * 1000);
d25e4efc 8908 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
8909 || (bgp->default_keepalive
8910 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
8911 json_object_int_add(json_neigh,
8912 "bgpTimerConfiguredHoldTimeMsecs",
8913 bgp->default_holdtime);
8914 json_object_int_add(
8915 json_neigh,
8916 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8917 bgp->default_keepalive);
d62a17ae 8918 }
8919 } else {
8920 /* Administrative shutdown. */
8921 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8922 vty_out(vty, " Administratively shut down\n");
8923
8924 /* BGP Version. */
8925 vty_out(vty, " BGP version 4");
8926 vty_out(vty, ", remote router ID %s\n",
8927 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8928
8929 /* Confederation */
8930 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8931 && bgp_confederation_peers_check(bgp, p->as))
8932 vty_out(vty,
8933 " Neighbor under common administration\n");
8934
8935 /* Status. */
8936 vty_out(vty, " BGP state = %s",
8937 lookup_msg(bgp_status_msg, p->status, NULL));
8938
8939 if (p->status == Established)
8940 vty_out(vty, ", up for %8s",
8941 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8942 0, NULL));
8943
8944 else if (p->status == Active) {
8945 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8946 vty_out(vty, " (passive)");
8947 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8948 vty_out(vty, " (NSF passive)");
8949 }
8950 vty_out(vty, "\n");
8951
8952 /* read timer */
8953 vty_out(vty, " Last read %s",
8954 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8955 NULL));
8956 vty_out(vty, ", Last write %s\n",
8957 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8958 NULL));
8959
8960 /* Configured timer values. */
8961 vty_out(vty,
8962 " Hold time is %d, keepalive interval is %d seconds\n",
8963 p->v_holdtime, p->v_keepalive);
d25e4efc 8964 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8965 vty_out(vty, " Configured hold time is %d",
8966 p->holdtime);
8967 vty_out(vty, ", keepalive interval is %d seconds\n",
8968 p->keepalive);
d25e4efc 8969 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
8970 || (bgp->default_keepalive
8971 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
8972 vty_out(vty, " Configured hold time is %d",
8973 bgp->default_holdtime);
8974 vty_out(vty, ", keepalive interval is %d seconds\n",
8975 bgp->default_keepalive);
d62a17ae 8976 }
8977 }
8978 /* Capability. */
8979 if (p->status == Established) {
8980 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8981 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8982 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8983 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8984 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8985 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8986 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8987 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8988 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8989 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8990 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8991 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8992 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8993 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8994 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8995 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8996 if (use_json) {
8997 json_object *json_cap = NULL;
8998
8999 json_cap = json_object_new_object();
9000
9001 /* AS4 */
9002 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9003 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9004 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
9005 && CHECK_FLAG(p->cap,
9006 PEER_CAP_AS4_RCV))
9007 json_object_string_add(
9008 json_cap, "4byteAs",
9009 "advertisedAndReceived");
9010 else if (CHECK_FLAG(p->cap,
9011 PEER_CAP_AS4_ADV))
9012 json_object_string_add(
9013 json_cap, "4byteAs",
9014 "advertised");
9015 else if (CHECK_FLAG(p->cap,
9016 PEER_CAP_AS4_RCV))
9017 json_object_string_add(
9018 json_cap, "4byteAs",
9019 "received");
9020 }
9021
9022 /* AddPath */
9023 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9024 || CHECK_FLAG(p->cap,
9025 PEER_CAP_ADDPATH_ADV)) {
9026 json_object *json_add = NULL;
9027 const char *print_store;
9028
9029 json_add = json_object_new_object();
9030
05c7a1cc
QY
9031 FOREACH_AFI_SAFI (afi, safi) {
9032 json_object *json_sub = NULL;
9033 json_sub =
9034 json_object_new_object();
9035 print_store = afi_safi_print(
9036 afi, safi);
d62a17ae 9037
05c7a1cc
QY
9038 if (CHECK_FLAG(
9039 p->af_cap[afi]
9040 [safi],
9041 PEER_CAP_ADDPATH_AF_TX_ADV)
9042 || CHECK_FLAG(
9043 p->af_cap[afi]
9044 [safi],
9045 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 9046 if (CHECK_FLAG(
9047 p->af_cap
9048 [afi]
9049 [safi],
9050 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9051 && CHECK_FLAG(
d62a17ae 9052 p->af_cap
9053 [afi]
9054 [safi],
05c7a1cc
QY
9055 PEER_CAP_ADDPATH_AF_TX_RCV))
9056 json_object_boolean_true_add(
9057 json_sub,
9058 "txAdvertisedAndReceived");
9059 else if (
9060 CHECK_FLAG(
9061 p->af_cap
9062 [afi]
9063 [safi],
9064 PEER_CAP_ADDPATH_AF_TX_ADV))
9065 json_object_boolean_true_add(
9066 json_sub,
9067 "txAdvertised");
9068 else if (
9069 CHECK_FLAG(
9070 p->af_cap
9071 [afi]
9072 [safi],
9073 PEER_CAP_ADDPATH_AF_TX_RCV))
9074 json_object_boolean_true_add(
9075 json_sub,
9076 "txReceived");
9077 }
d62a17ae 9078
05c7a1cc
QY
9079 if (CHECK_FLAG(
9080 p->af_cap[afi]
9081 [safi],
9082 PEER_CAP_ADDPATH_AF_RX_ADV)
9083 || CHECK_FLAG(
9084 p->af_cap[afi]
9085 [safi],
9086 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9087 if (CHECK_FLAG(
9088 p->af_cap
9089 [afi]
9090 [safi],
9091 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9092 && CHECK_FLAG(
d62a17ae 9093 p->af_cap
9094 [afi]
9095 [safi],
9096 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9097 json_object_boolean_true_add(
9098 json_sub,
9099 "rxAdvertisedAndReceived");
9100 else if (
9101 CHECK_FLAG(
9102 p->af_cap
9103 [afi]
9104 [safi],
9105 PEER_CAP_ADDPATH_AF_RX_ADV))
9106 json_object_boolean_true_add(
9107 json_sub,
9108 "rxAdvertised");
9109 else if (
9110 CHECK_FLAG(
9111 p->af_cap
9112 [afi]
9113 [safi],
9114 PEER_CAP_ADDPATH_AF_RX_RCV))
9115 json_object_boolean_true_add(
9116 json_sub,
9117 "rxReceived");
d62a17ae 9118 }
9119
05c7a1cc
QY
9120 if (CHECK_FLAG(
9121 p->af_cap[afi]
9122 [safi],
9123 PEER_CAP_ADDPATH_AF_TX_ADV)
9124 || CHECK_FLAG(
9125 p->af_cap[afi]
9126 [safi],
9127 PEER_CAP_ADDPATH_AF_TX_RCV)
9128 || CHECK_FLAG(
9129 p->af_cap[afi]
9130 [safi],
9131 PEER_CAP_ADDPATH_AF_RX_ADV)
9132 || CHECK_FLAG(
9133 p->af_cap[afi]
9134 [safi],
9135 PEER_CAP_ADDPATH_AF_RX_RCV))
9136 json_object_object_add(
9137 json_add,
9138 print_store,
9139 json_sub);
9140 else
9141 json_object_free(
9142 json_sub);
9143 }
9144
d62a17ae 9145 json_object_object_add(
9146 json_cap, "addPath", json_add);
9147 }
9148
9149 /* Dynamic */
9150 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9151 || CHECK_FLAG(p->cap,
9152 PEER_CAP_DYNAMIC_ADV)) {
9153 if (CHECK_FLAG(p->cap,
9154 PEER_CAP_DYNAMIC_ADV)
9155 && CHECK_FLAG(p->cap,
9156 PEER_CAP_DYNAMIC_RCV))
9157 json_object_string_add(
9158 json_cap, "dynamic",
9159 "advertisedAndReceived");
9160 else if (CHECK_FLAG(
9161 p->cap,
9162 PEER_CAP_DYNAMIC_ADV))
9163 json_object_string_add(
9164 json_cap, "dynamic",
9165 "advertised");
9166 else if (CHECK_FLAG(
9167 p->cap,
9168 PEER_CAP_DYNAMIC_RCV))
9169 json_object_string_add(
9170 json_cap, "dynamic",
9171 "received");
9172 }
9173
9174 /* Extended nexthop */
9175 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9176 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9177 json_object *json_nxt = NULL;
9178 const char *print_store;
9179
9180
9181 if (CHECK_FLAG(p->cap,
9182 PEER_CAP_ENHE_ADV)
9183 && CHECK_FLAG(p->cap,
9184 PEER_CAP_ENHE_RCV))
9185 json_object_string_add(
9186 json_cap,
9187 "extendedNexthop",
9188 "advertisedAndReceived");
9189 else if (CHECK_FLAG(p->cap,
9190 PEER_CAP_ENHE_ADV))
9191 json_object_string_add(
9192 json_cap,
9193 "extendedNexthop",
9194 "advertised");
9195 else if (CHECK_FLAG(p->cap,
9196 PEER_CAP_ENHE_RCV))
9197 json_object_string_add(
9198 json_cap,
9199 "extendedNexthop",
9200 "received");
9201
9202 if (CHECK_FLAG(p->cap,
9203 PEER_CAP_ENHE_RCV)) {
9204 json_nxt =
9205 json_object_new_object();
9206
9207 for (safi = SAFI_UNICAST;
9208 safi < SAFI_MAX; safi++) {
9209 if (CHECK_FLAG(
9210 p->af_cap
9211 [AFI_IP]
9212 [safi],
9213 PEER_CAP_ENHE_AF_RCV)) {
9214 print_store = afi_safi_print(
9215 AFI_IP,
9216 safi);
9217 json_object_string_add(
9218 json_nxt,
9219 print_store,
9220 "recieved");
9221 }
9222 }
9223 json_object_object_add(
9224 json_cap,
9225 "extendedNexthopFamililesByPeer",
9226 json_nxt);
9227 }
9228 }
9229
9230 /* Route Refresh */
9231 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9232 || CHECK_FLAG(p->cap,
9233 PEER_CAP_REFRESH_NEW_RCV)
9234 || CHECK_FLAG(p->cap,
9235 PEER_CAP_REFRESH_OLD_RCV)) {
9236 if (CHECK_FLAG(p->cap,
9237 PEER_CAP_REFRESH_ADV)
9238 && (CHECK_FLAG(
9239 p->cap,
9240 PEER_CAP_REFRESH_NEW_RCV)
9241 || CHECK_FLAG(
9242 p->cap,
9243 PEER_CAP_REFRESH_OLD_RCV))) {
9244 if (CHECK_FLAG(
9245 p->cap,
9246 PEER_CAP_REFRESH_OLD_RCV)
9247 && CHECK_FLAG(
9248 p->cap,
9249 PEER_CAP_REFRESH_NEW_RCV))
9250 json_object_string_add(
9251 json_cap,
9252 "routeRefresh",
9253 "advertisedAndReceivedOldNew");
9254 else {
9255 if (CHECK_FLAG(
9256 p->cap,
9257 PEER_CAP_REFRESH_OLD_RCV))
9258 json_object_string_add(
9259 json_cap,
9260 "routeRefresh",
9261 "advertisedAndReceivedOld");
9262 else
9263 json_object_string_add(
9264 json_cap,
9265 "routeRefresh",
9266 "advertisedAndReceivedNew");
9267 }
9268 } else if (
9269 CHECK_FLAG(
9270 p->cap,
9271 PEER_CAP_REFRESH_ADV))
9272 json_object_string_add(
9273 json_cap,
9274 "routeRefresh",
9275 "advertised");
9276 else if (
9277 CHECK_FLAG(
9278 p->cap,
9279 PEER_CAP_REFRESH_NEW_RCV)
9280 || CHECK_FLAG(
9281 p->cap,
9282 PEER_CAP_REFRESH_OLD_RCV))
9283 json_object_string_add(
9284 json_cap,
9285 "routeRefresh",
9286 "received");
9287 }
9288
9289 /* Multiprotocol Extensions */
9290 json_object *json_multi = NULL;
9291 json_multi = json_object_new_object();
9292
05c7a1cc
QY
9293 FOREACH_AFI_SAFI (afi, safi) {
9294 if (p->afc_adv[afi][safi]
9295 || p->afc_recv[afi][safi]) {
9296 json_object *json_exten = NULL;
9297 json_exten =
9298 json_object_new_object();
9299
d62a17ae 9300 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9301 && p->afc_recv[afi][safi])
9302 json_object_boolean_true_add(
9303 json_exten,
9304 "advertisedAndReceived");
9305 else if (p->afc_adv[afi][safi])
9306 json_object_boolean_true_add(
9307 json_exten,
9308 "advertised");
9309 else if (p->afc_recv[afi][safi])
9310 json_object_boolean_true_add(
9311 json_exten,
9312 "received");
d62a17ae 9313
05c7a1cc
QY
9314 json_object_object_add(
9315 json_multi,
9316 afi_safi_print(afi,
9317 safi),
9318 json_exten);
d62a17ae 9319 }
9320 }
9321 json_object_object_add(
9322 json_cap, "multiprotocolExtensions",
9323 json_multi);
9324
d77114b7 9325 /* Hostname capabilities */
60466a63 9326 json_object *json_hname = NULL;
d77114b7
MK
9327
9328 json_hname = json_object_new_object();
9329
9330 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9331 json_object_string_add(
60466a63
QY
9332 json_hname, "advHostName",
9333 bgp->peer_self->hostname
9334 ? bgp->peer_self
9335 ->hostname
d77114b7
MK
9336 : "n/a");
9337 json_object_string_add(
60466a63
QY
9338 json_hname, "advDomainName",
9339 bgp->peer_self->domainname
9340 ? bgp->peer_self
9341 ->domainname
d77114b7
MK
9342 : "n/a");
9343 }
9344
9345
9346 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9347 json_object_string_add(
60466a63
QY
9348 json_hname, "rcvHostName",
9349 p->hostname ? p->hostname
9350 : "n/a");
d77114b7 9351 json_object_string_add(
60466a63
QY
9352 json_hname, "rcvDomainName",
9353 p->domainname ? p->domainname
9354 : "n/a");
d77114b7
MK
9355 }
9356
60466a63 9357 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9358 json_hname);
9359
d62a17ae 9360 /* Gracefull Restart */
9361 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9362 || CHECK_FLAG(p->cap,
9363 PEER_CAP_RESTART_ADV)) {
9364 if (CHECK_FLAG(p->cap,
9365 PEER_CAP_RESTART_ADV)
9366 && CHECK_FLAG(p->cap,
9367 PEER_CAP_RESTART_RCV))
9368 json_object_string_add(
9369 json_cap,
9370 "gracefulRestart",
9371 "advertisedAndReceived");
9372 else if (CHECK_FLAG(
9373 p->cap,
9374 PEER_CAP_RESTART_ADV))
9375 json_object_string_add(
9376 json_cap,
9377 "gracefulRestartCapability",
9378 "advertised");
9379 else if (CHECK_FLAG(
9380 p->cap,
9381 PEER_CAP_RESTART_RCV))
9382 json_object_string_add(
9383 json_cap,
9384 "gracefulRestartCapability",
9385 "received");
9386
9387 if (CHECK_FLAG(p->cap,
9388 PEER_CAP_RESTART_RCV)) {
9389 int restart_af_count = 0;
9390 json_object *json_restart =
9391 NULL;
9392 json_restart =
9393 json_object_new_object();
9394
9395 json_object_int_add(
9396 json_cap,
9397 "gracefulRestartRemoteTimerMsecs",
9398 p->v_gr_restart * 1000);
9399
05c7a1cc
QY
9400 FOREACH_AFI_SAFI (afi, safi) {
9401 if (CHECK_FLAG(
9402 p->af_cap
9403 [afi]
9404 [safi],
9405 PEER_CAP_RESTART_AF_RCV)) {
9406 json_object *
9407 json_sub =
9408 NULL;
9409 json_sub =
9410 json_object_new_object();
9411
d62a17ae 9412 if (CHECK_FLAG(
9413 p->af_cap
9414 [afi]
9415 [safi],
05c7a1cc
QY
9416 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9417 json_object_boolean_true_add(
9418 json_sub,
9419 "preserved");
9420 restart_af_count++;
9421 json_object_object_add(
9422 json_restart,
9423 afi_safi_print(
9424 afi,
9425 safi),
9426 json_sub);
d62a17ae 9427 }
9428 }
9429 if (!restart_af_count) {
9430 json_object_string_add(
9431 json_cap,
9432 "addressFamiliesByPeer",
9433 "none");
9434 json_object_free(
9435 json_restart);
9436 } else
9437 json_object_object_add(
9438 json_cap,
9439 "addressFamiliesByPeer",
9440 json_restart);
9441 }
9442 }
9443 json_object_object_add(json_neigh,
9444 "neighborCapabilities",
9445 json_cap);
9446 } else {
9447 vty_out(vty, " Neighbor capabilities:\n");
9448
9449 /* AS4 */
9450 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9451 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9452 vty_out(vty, " 4 Byte AS:");
9453 if (CHECK_FLAG(p->cap,
9454 PEER_CAP_AS4_ADV))
9455 vty_out(vty, " advertised");
9456 if (CHECK_FLAG(p->cap,
9457 PEER_CAP_AS4_RCV))
9458 vty_out(vty, " %sreceived",
9459 CHECK_FLAG(
9460 p->cap,
9461 PEER_CAP_AS4_ADV)
9462 ? "and "
9463 : "");
9464 vty_out(vty, "\n");
9465 }
9466
9467 /* AddPath */
9468 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9469 || CHECK_FLAG(p->cap,
9470 PEER_CAP_ADDPATH_ADV)) {
9471 vty_out(vty, " AddPath:\n");
9472
05c7a1cc
QY
9473 FOREACH_AFI_SAFI (afi, safi) {
9474 if (CHECK_FLAG(
9475 p->af_cap[afi]
9476 [safi],
9477 PEER_CAP_ADDPATH_AF_TX_ADV)
9478 || CHECK_FLAG(
9479 p->af_cap[afi]
9480 [safi],
9481 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9482 vty_out(vty,
9483 " %s: TX ",
9484 afi_safi_print(
9485 afi,
9486 safi));
9487
d62a17ae 9488 if (CHECK_FLAG(
9489 p->af_cap
9490 [afi]
9491 [safi],
05c7a1cc 9492 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9493 vty_out(vty,
05c7a1cc 9494 "advertised %s",
d62a17ae 9495 afi_safi_print(
9496 afi,
9497 safi));
9498
05c7a1cc
QY
9499 if (CHECK_FLAG(
9500 p->af_cap
9501 [afi]
9502 [safi],
9503 PEER_CAP_ADDPATH_AF_TX_RCV))
9504 vty_out(vty,
9505 "%sreceived",
9506 CHECK_FLAG(
9507 p->af_cap
9508 [afi]
9509 [safi],
9510 PEER_CAP_ADDPATH_AF_TX_ADV)
9511 ? " and "
9512 : "");
d62a17ae 9513
05c7a1cc
QY
9514 vty_out(vty, "\n");
9515 }
d62a17ae 9516
05c7a1cc
QY
9517 if (CHECK_FLAG(
9518 p->af_cap[afi]
9519 [safi],
9520 PEER_CAP_ADDPATH_AF_RX_ADV)
9521 || CHECK_FLAG(
9522 p->af_cap[afi]
9523 [safi],
9524 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9525 vty_out(vty,
9526 " %s: RX ",
9527 afi_safi_print(
9528 afi,
9529 safi));
d62a17ae 9530
9531 if (CHECK_FLAG(
9532 p->af_cap
9533 [afi]
9534 [safi],
05c7a1cc 9535 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9536 vty_out(vty,
05c7a1cc 9537 "advertised %s",
d62a17ae 9538 afi_safi_print(
9539 afi,
9540 safi));
9541
05c7a1cc
QY
9542 if (CHECK_FLAG(
9543 p->af_cap
9544 [afi]
9545 [safi],
9546 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9547 vty_out(vty,
05c7a1cc
QY
9548 "%sreceived",
9549 CHECK_FLAG(
9550 p->af_cap
9551 [afi]
9552 [safi],
9553 PEER_CAP_ADDPATH_AF_RX_ADV)
9554 ? " and "
9555 : "");
9556
9557 vty_out(vty, "\n");
d62a17ae 9558 }
05c7a1cc 9559 }
d62a17ae 9560 }
9561
9562 /* Dynamic */
9563 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9564 || CHECK_FLAG(p->cap,
9565 PEER_CAP_DYNAMIC_ADV)) {
9566 vty_out(vty, " Dynamic:");
9567 if (CHECK_FLAG(p->cap,
9568 PEER_CAP_DYNAMIC_ADV))
9569 vty_out(vty, " advertised");
9570 if (CHECK_FLAG(p->cap,
9571 PEER_CAP_DYNAMIC_RCV))
9572 vty_out(vty, " %sreceived",
9573 CHECK_FLAG(
9574 p->cap,
9575 PEER_CAP_DYNAMIC_ADV)
9576 ? "and "
9577 : "");
9578 vty_out(vty, "\n");
9579 }
9580
9581 /* Extended nexthop */
9582 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9583 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9584 vty_out(vty, " Extended nexthop:");
9585 if (CHECK_FLAG(p->cap,
9586 PEER_CAP_ENHE_ADV))
9587 vty_out(vty, " advertised");
9588 if (CHECK_FLAG(p->cap,
9589 PEER_CAP_ENHE_RCV))
9590 vty_out(vty, " %sreceived",
9591 CHECK_FLAG(
9592 p->cap,
9593 PEER_CAP_ENHE_ADV)
9594 ? "and "
9595 : "");
9596 vty_out(vty, "\n");
9597
9598 if (CHECK_FLAG(p->cap,
9599 PEER_CAP_ENHE_RCV)) {
9600 vty_out(vty,
9601 " Address families by peer:\n ");
9602 for (safi = SAFI_UNICAST;
9603 safi < SAFI_MAX; safi++)
9604 if (CHECK_FLAG(
9605 p->af_cap
9606 [AFI_IP]
9607 [safi],
9608 PEER_CAP_ENHE_AF_RCV))
9609 vty_out(vty,
9610 " %s\n",
9611 afi_safi_print(
9612 AFI_IP,
9613 safi));
9614 }
9615 }
9616
9617 /* Route Refresh */
9618 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9619 || CHECK_FLAG(p->cap,
9620 PEER_CAP_REFRESH_NEW_RCV)
9621 || CHECK_FLAG(p->cap,
9622 PEER_CAP_REFRESH_OLD_RCV)) {
9623 vty_out(vty, " Route refresh:");
9624 if (CHECK_FLAG(p->cap,
9625 PEER_CAP_REFRESH_ADV))
9626 vty_out(vty, " advertised");
9627 if (CHECK_FLAG(p->cap,
9628 PEER_CAP_REFRESH_NEW_RCV)
9629 || CHECK_FLAG(
9630 p->cap,
9631 PEER_CAP_REFRESH_OLD_RCV))
9632 vty_out(vty, " %sreceived(%s)",
9633 CHECK_FLAG(
9634 p->cap,
9635 PEER_CAP_REFRESH_ADV)
9636 ? "and "
9637 : "",
9638 (CHECK_FLAG(
9639 p->cap,
9640 PEER_CAP_REFRESH_OLD_RCV)
9641 && CHECK_FLAG(
9642 p->cap,
9643 PEER_CAP_REFRESH_NEW_RCV))
9644 ? "old & new"
9645 : CHECK_FLAG(
9646 p->cap,
9647 PEER_CAP_REFRESH_OLD_RCV)
9648 ? "old"
9649 : "new");
9650
9651 vty_out(vty, "\n");
9652 }
9653
9654 /* Multiprotocol Extensions */
05c7a1cc
QY
9655 FOREACH_AFI_SAFI (afi, safi)
9656 if (p->afc_adv[afi][safi]
9657 || p->afc_recv[afi][safi]) {
9658 vty_out(vty,
9659 " Address Family %s:",
9660 afi_safi_print(afi,
9661 safi));
9662 if (p->afc_adv[afi][safi])
d62a17ae 9663 vty_out(vty,
05c7a1cc
QY
9664 " advertised");
9665 if (p->afc_recv[afi][safi])
9666 vty_out(vty,
9667 " %sreceived",
9668 p->afc_adv[afi]
9669 [safi]
9670 ? "and "
9671 : "");
9672 vty_out(vty, "\n");
9673 }
d62a17ae 9674
9675 /* Hostname capability */
60466a63 9676 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9677
9678 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9679 vty_out(vty,
9680 " advertised (name: %s,domain name: %s)",
60466a63
QY
9681 bgp->peer_self->hostname
9682 ? bgp->peer_self
9683 ->hostname
d77114b7 9684 : "n/a",
60466a63
QY
9685 bgp->peer_self->domainname
9686 ? bgp->peer_self
9687 ->domainname
d77114b7
MK
9688 : "n/a");
9689 } else {
9690 vty_out(vty, " not advertised");
d62a17ae 9691 }
9692
d77114b7 9693 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9694 vty_out(vty,
9695 " received (name: %s,domain name: %s)",
60466a63
QY
9696 p->hostname ? p->hostname
9697 : "n/a",
9698 p->domainname ? p->domainname
9699 : "n/a");
d77114b7
MK
9700 } else {
9701 vty_out(vty, " not received");
9702 }
9703
9704 vty_out(vty, "\n");
9705
d62a17ae 9706 /* Gracefull Restart */
9707 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9708 || CHECK_FLAG(p->cap,
9709 PEER_CAP_RESTART_ADV)) {
9710 vty_out(vty,
9711 " Graceful Restart Capabilty:");
9712 if (CHECK_FLAG(p->cap,
9713 PEER_CAP_RESTART_ADV))
9714 vty_out(vty, " advertised");
9715 if (CHECK_FLAG(p->cap,
9716 PEER_CAP_RESTART_RCV))
9717 vty_out(vty, " %sreceived",
9718 CHECK_FLAG(
9719 p->cap,
9720 PEER_CAP_RESTART_ADV)
9721 ? "and "
9722 : "");
9723 vty_out(vty, "\n");
9724
9725 if (CHECK_FLAG(p->cap,
9726 PEER_CAP_RESTART_RCV)) {
9727 int restart_af_count = 0;
9728
9729 vty_out(vty,
9730 " Remote Restart timer is %d seconds\n",
9731 p->v_gr_restart);
9732 vty_out(vty,
9733 " Address families by peer:\n ");
9734
05c7a1cc
QY
9735 FOREACH_AFI_SAFI (afi, safi)
9736 if (CHECK_FLAG(
9737 p->af_cap
9738 [afi]
9739 [safi],
9740 PEER_CAP_RESTART_AF_RCV)) {
9741 vty_out(vty,
9742 "%s%s(%s)",
9743 restart_af_count
9744 ? ", "
9745 : "",
9746 afi_safi_print(
9747 afi,
9748 safi),
9749 CHECK_FLAG(
9750 p->af_cap
9751 [afi]
9752 [safi],
9753 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9754 ? "preserved"
9755 : "not preserved");
9756 restart_af_count++;
9757 }
d62a17ae 9758 if (!restart_af_count)
9759 vty_out(vty, "none");
9760 vty_out(vty, "\n");
9761 }
9762 }
9763 }
9764 }
9765 }
9766
9767 /* graceful restart information */
9768 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9769 || p->t_gr_stale) {
9770 json_object *json_grace = NULL;
9771 json_object *json_grace_send = NULL;
9772 json_object *json_grace_recv = NULL;
9773 int eor_send_af_count = 0;
9774 int eor_receive_af_count = 0;
9775
9776 if (use_json) {
9777 json_grace = json_object_new_object();
9778 json_grace_send = json_object_new_object();
9779 json_grace_recv = json_object_new_object();
9780
9781 if (p->status == Established) {
05c7a1cc
QY
9782 FOREACH_AFI_SAFI (afi, safi) {
9783 if (CHECK_FLAG(p->af_sflags[afi][safi],
9784 PEER_STATUS_EOR_SEND)) {
9785 json_object_boolean_true_add(
9786 json_grace_send,
9787 afi_safi_print(afi,
9788 safi));
9789 eor_send_af_count++;
d62a17ae 9790 }
9791 }
05c7a1cc
QY
9792 FOREACH_AFI_SAFI (afi, safi) {
9793 if (CHECK_FLAG(
9794 p->af_sflags[afi][safi],
9795 PEER_STATUS_EOR_RECEIVED)) {
9796 json_object_boolean_true_add(
9797 json_grace_recv,
9798 afi_safi_print(afi,
9799 safi));
9800 eor_receive_af_count++;
d62a17ae 9801 }
9802 }
9803 }
9804
9805 json_object_object_add(json_grace, "endOfRibSend",
9806 json_grace_send);
9807 json_object_object_add(json_grace, "endOfRibRecv",
9808 json_grace_recv);
9809
9810 if (p->t_gr_restart)
9811 json_object_int_add(json_grace,
9812 "gracefulRestartTimerMsecs",
9813 thread_timer_remain_second(
9814 p->t_gr_restart)
9815 * 1000);
9816
9817 if (p->t_gr_stale)
9818 json_object_int_add(
9819 json_grace,
9820 "gracefulStalepathTimerMsecs",
9821 thread_timer_remain_second(
9822 p->t_gr_stale)
9823 * 1000);
9824
9825 json_object_object_add(
9826 json_neigh, "gracefulRestartInfo", json_grace);
9827 } else {
9828 vty_out(vty, " Graceful restart informations:\n");
9829 if (p->status == Established) {
9830 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
9831 FOREACH_AFI_SAFI (afi, safi) {
9832 if (CHECK_FLAG(p->af_sflags[afi][safi],
9833 PEER_STATUS_EOR_SEND)) {
9834 vty_out(vty, "%s%s",
9835 eor_send_af_count ? ", "
9836 : "",
9837 afi_safi_print(afi,
9838 safi));
9839 eor_send_af_count++;
d62a17ae 9840 }
9841 }
9842 vty_out(vty, "\n");
9843 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
9844 FOREACH_AFI_SAFI (afi, safi) {
9845 if (CHECK_FLAG(
9846 p->af_sflags[afi][safi],
9847 PEER_STATUS_EOR_RECEIVED)) {
9848 vty_out(vty, "%s%s",
9849 eor_receive_af_count
9850 ? ", "
9851 : "",
9852 afi_safi_print(afi,
9853 safi));
9854 eor_receive_af_count++;
d62a17ae 9855 }
9856 }
9857 vty_out(vty, "\n");
9858 }
9859
9860 if (p->t_gr_restart)
9861 vty_out(vty,
9862 " The remaining time of restart timer is %ld\n",
9863 thread_timer_remain_second(
9864 p->t_gr_restart));
9865
9866 if (p->t_gr_stale)
9867 vty_out(vty,
9868 " The remaining time of stalepath timer is %ld\n",
9869 thread_timer_remain_second(
9870 p->t_gr_stale));
9871 }
9872 }
9873 if (use_json) {
9874 json_object *json_stat = NULL;
9875 json_stat = json_object_new_object();
9876 /* Packet counts. */
9877 json_object_int_add(json_stat, "depthInq", 0);
9878 json_object_int_add(json_stat, "depthOutq",
9879 (unsigned long)p->obuf->count);
0112e9e0
QY
9880 json_object_int_add(json_stat, "opensSent",
9881 atomic_load_explicit(&p->open_out,
9882 memory_order_relaxed));
9883 json_object_int_add(json_stat, "opensRecv",
9884 atomic_load_explicit(&p->open_in,
9885 memory_order_relaxed));
d62a17ae 9886 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
9887 atomic_load_explicit(&p->notify_out,
9888 memory_order_relaxed));
d62a17ae 9889 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
9890 atomic_load_explicit(&p->notify_in,
9891 memory_order_relaxed));
9892 json_object_int_add(json_stat, "updatesSent",
9893 atomic_load_explicit(&p->update_out,
9894 memory_order_relaxed));
9895 json_object_int_add(json_stat, "updatesRecv",
9896 atomic_load_explicit(&p->update_in,
9897 memory_order_relaxed));
d62a17ae 9898 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
9899 atomic_load_explicit(&p->keepalive_out,
9900 memory_order_relaxed));
d62a17ae 9901 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
9902 atomic_load_explicit(&p->keepalive_in,
9903 memory_order_relaxed));
d62a17ae 9904 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
9905 atomic_load_explicit(&p->refresh_out,
9906 memory_order_relaxed));
d62a17ae 9907 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
9908 atomic_load_explicit(&p->refresh_in,
9909 memory_order_relaxed));
d62a17ae 9910 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
9911 atomic_load_explicit(&p->dynamic_cap_out,
9912 memory_order_relaxed));
d62a17ae 9913 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
9914 atomic_load_explicit(&p->dynamic_cap_in,
9915 memory_order_relaxed));
9916 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
9917 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 9918 json_object_object_add(json_neigh, "messageStats", json_stat);
9919 } else {
9920 /* Packet counts. */
9921 vty_out(vty, " Message statistics:\n");
9922 vty_out(vty, " Inq depth is 0\n");
9923 vty_out(vty, " Outq depth is %lu\n",
9924 (unsigned long)p->obuf->count);
9925 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
9926 vty_out(vty, " Opens: %10d %10d\n",
9927 atomic_load_explicit(&p->open_out,
9928 memory_order_relaxed),
9929 atomic_load_explicit(&p->open_in,
9930 memory_order_relaxed));
9931 vty_out(vty, " Notifications: %10d %10d\n",
9932 atomic_load_explicit(&p->notify_out,
9933 memory_order_relaxed),
9934 atomic_load_explicit(&p->notify_in,
9935 memory_order_relaxed));
9936 vty_out(vty, " Updates: %10d %10d\n",
9937 atomic_load_explicit(&p->update_out,
9938 memory_order_relaxed),
9939 atomic_load_explicit(&p->update_in,
9940 memory_order_relaxed));
9941 vty_out(vty, " Keepalives: %10d %10d\n",
9942 atomic_load_explicit(&p->keepalive_out,
9943 memory_order_relaxed),
9944 atomic_load_explicit(&p->keepalive_in,
9945 memory_order_relaxed));
9946 vty_out(vty, " Route Refresh: %10d %10d\n",
9947 atomic_load_explicit(&p->refresh_out,
9948 memory_order_relaxed),
9949 atomic_load_explicit(&p->refresh_in,
9950 memory_order_relaxed));
d62a17ae 9951 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
9952 atomic_load_explicit(&p->dynamic_cap_out,
9953 memory_order_relaxed),
9954 atomic_load_explicit(&p->dynamic_cap_in,
9955 memory_order_relaxed));
9956 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
9957 PEER_TOTAL_RX(p));
d62a17ae 9958 }
9959
9960 if (use_json) {
9961 /* advertisement-interval */
9962 json_object_int_add(json_neigh,
9963 "minBtwnAdvertisementRunsTimerMsecs",
9964 p->v_routeadv * 1000);
9965
9966 /* Update-source. */
9967 if (p->update_if || p->update_source) {
9968 if (p->update_if)
9969 json_object_string_add(json_neigh,
9970 "updateSource",
9971 p->update_if);
9972 else if (p->update_source)
9973 json_object_string_add(
9974 json_neigh, "updateSource",
9975 sockunion2str(p->update_source, buf1,
9976 SU_ADDRSTRLEN));
9977 }
9978 } else {
9979 /* advertisement-interval */
9980 vty_out(vty,
9981 " Minimum time between advertisement runs is %d seconds\n",
9982 p->v_routeadv);
9983
9984 /* Update-source. */
9985 if (p->update_if || p->update_source) {
9986 vty_out(vty, " Update source is ");
9987 if (p->update_if)
9988 vty_out(vty, "%s", p->update_if);
9989 else if (p->update_source)
9990 vty_out(vty, "%s",
9991 sockunion2str(p->update_source, buf1,
9992 SU_ADDRSTRLEN));
9993 vty_out(vty, "\n");
9994 }
9995
9996 vty_out(vty, "\n");
9997 }
9998
9999 /* Address Family Information */
10000 json_object *json_hold = NULL;
10001
10002 if (use_json)
10003 json_hold = json_object_new_object();
10004
05c7a1cc
QY
10005 FOREACH_AFI_SAFI (afi, safi)
10006 if (p->afc[afi][safi])
10007 bgp_show_peer_afi(vty, p, afi, safi, use_json,
10008 json_hold);
d62a17ae 10009
10010 if (use_json) {
10011 json_object_object_add(json_neigh, "addressFamilyInfo",
10012 json_hold);
10013 json_object_int_add(json_neigh, "connectionsEstablished",
10014 p->established);
10015 json_object_int_add(json_neigh, "connectionsDropped",
10016 p->dropped);
10017 } else
10018 vty_out(vty, " Connections established %d; dropped %d\n",
10019 p->established, p->dropped);
10020
10021 if (!p->last_reset) {
10022 if (use_json)
10023 json_object_string_add(json_neigh, "lastReset",
10024 "never");
10025 else
10026 vty_out(vty, " Last reset never\n");
10027 } else {
10028 if (use_json) {
10029 time_t uptime;
10030 struct tm *tm;
10031
10032 uptime = bgp_clock();
10033 uptime -= p->resettime;
10034 tm = gmtime(&uptime);
10035 json_object_int_add(json_neigh, "lastResetTimerMsecs",
10036 (tm->tm_sec * 1000)
10037 + (tm->tm_min * 60000)
10038 + (tm->tm_hour * 3600000));
10039 json_object_string_add(
10040 json_neigh, "lastResetDueTo",
10041 peer_down_str[(int)p->last_reset]);
10042 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10043 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10044 char errorcodesubcode_hexstr[5];
10045 char errorcodesubcode_str[256];
10046
10047 code_str = bgp_notify_code_str(p->notify.code);
10048 subcode_str = bgp_notify_subcode_str(
10049 p->notify.code, p->notify.subcode);
10050
10051 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10052 p->notify.code, p->notify.subcode);
10053 json_object_string_add(json_neigh,
10054 "lastErrorCodeSubcode",
10055 errorcodesubcode_hexstr);
10056 snprintf(errorcodesubcode_str, 255, "%s%s",
10057 code_str, subcode_str);
10058 json_object_string_add(json_neigh,
10059 "lastNotificationReason",
10060 errorcodesubcode_str);
10061 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10062 && p->notify.code == BGP_NOTIFY_CEASE
10063 && (p->notify.subcode
10064 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10065 || p->notify.subcode
10066 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10067 && p->notify.length) {
10068 char msgbuf[1024];
10069 const char *msg_str;
10070
10071 msg_str = bgp_notify_admin_message(
10072 msgbuf, sizeof(msgbuf),
10073 (u_char *)p->notify.data,
10074 p->notify.length);
10075 if (msg_str)
10076 json_object_string_add(
10077 json_neigh,
10078 "lastShutdownDescription",
10079 msg_str);
10080 }
10081 }
10082 } else {
10083 vty_out(vty, " Last reset %s, ",
10084 peer_uptime(p->resettime, timebuf,
10085 BGP_UPTIME_LEN, 0, NULL));
10086
10087 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10088 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10089 code_str = bgp_notify_code_str(p->notify.code);
10090 subcode_str = bgp_notify_subcode_str(
10091 p->notify.code, p->notify.subcode);
10092 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10093 p->last_reset == PEER_DOWN_NOTIFY_SEND
10094 ? "sent"
10095 : "received",
10096 code_str, subcode_str);
10097 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10098 && p->notify.code == BGP_NOTIFY_CEASE
10099 && (p->notify.subcode
10100 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10101 || p->notify.subcode
10102 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10103 && p->notify.length) {
10104 char msgbuf[1024];
10105 const char *msg_str;
10106
10107 msg_str = bgp_notify_admin_message(
10108 msgbuf, sizeof(msgbuf),
10109 (u_char *)p->notify.data,
10110 p->notify.length);
10111 if (msg_str)
10112 vty_out(vty,
10113 " Message: \"%s\"\n",
10114 msg_str);
10115 }
10116 } else {
10117 vty_out(vty, "due to %s\n",
10118 peer_down_str[(int)p->last_reset]);
10119 }
10120
10121 if (p->last_reset_cause_size) {
10122 msg = p->last_reset_cause;
10123 vty_out(vty,
10124 " Message received that caused BGP to send a NOTIFICATION:\n ");
10125 for (i = 1; i <= p->last_reset_cause_size;
10126 i++) {
10127 vty_out(vty, "%02X", *msg++);
10128
10129 if (i != p->last_reset_cause_size) {
10130 if (i % 16 == 0) {
10131 vty_out(vty, "\n ");
10132 } else if (i % 4 == 0) {
10133 vty_out(vty, " ");
10134 }
10135 }
10136 }
10137 vty_out(vty, "\n");
10138 }
10139 }
10140 }
10141
10142 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10143 if (use_json)
10144 json_object_boolean_true_add(json_neigh,
10145 "prefixesConfigExceedMax");
10146 else
10147 vty_out(vty,
10148 " Peer had exceeded the max. no. of prefixes configured.\n");
10149
10150 if (p->t_pmax_restart) {
10151 if (use_json) {
10152 json_object_boolean_true_add(
10153 json_neigh, "reducePrefixNumFrom");
10154 json_object_int_add(json_neigh,
10155 "restartInTimerMsec",
10156 thread_timer_remain_second(
10157 p->t_pmax_restart)
10158 * 1000);
10159 } else
10160 vty_out(vty,
10161 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10162 p->host, thread_timer_remain_second(
10163 p->t_pmax_restart));
d62a17ae 10164 } else {
10165 if (use_json)
10166 json_object_boolean_true_add(
10167 json_neigh,
10168 "reducePrefixNumAndClearIpBgp");
10169 else
10170 vty_out(vty,
10171 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10172 p->host);
10173 }
10174 }
10175
10176 /* EBGP Multihop and GTSM */
10177 if (p->sort != BGP_PEER_IBGP) {
10178 if (use_json) {
10179 if (p->gtsm_hops > 0)
10180 json_object_int_add(json_neigh,
10181 "externalBgpNbrMaxHopsAway",
10182 p->gtsm_hops);
10183 else if (p->ttl > 1)
10184 json_object_int_add(json_neigh,
10185 "externalBgpNbrMaxHopsAway",
10186 p->ttl);
10187 } else {
10188 if (p->gtsm_hops > 0)
10189 vty_out(vty,
10190 " External BGP neighbor may be up to %d hops away.\n",
10191 p->gtsm_hops);
10192 else if (p->ttl > 1)
10193 vty_out(vty,
10194 " External BGP neighbor may be up to %d hops away.\n",
10195 p->ttl);
10196 }
10197 } else {
10198 if (p->gtsm_hops > 0) {
10199 if (use_json)
10200 json_object_int_add(json_neigh,
10201 "internalBgpNbrMaxHopsAway",
10202 p->gtsm_hops);
10203 else
10204 vty_out(vty,
10205 " Internal BGP neighbor may be up to %d hops away.\n",
10206 p->gtsm_hops);
10207 }
10208 }
10209
10210 /* Local address. */
10211 if (p->su_local) {
10212 if (use_json) {
10213 json_object_string_add(json_neigh, "hostLocal",
10214 sockunion2str(p->su_local, buf1,
10215 SU_ADDRSTRLEN));
10216 json_object_int_add(json_neigh, "portLocal",
10217 ntohs(p->su_local->sin.sin_port));
10218 } else
10219 vty_out(vty, "Local host: %s, Local port: %d\n",
10220 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10221 ntohs(p->su_local->sin.sin_port));
10222 }
10223
10224 /* Remote address. */
10225 if (p->su_remote) {
10226 if (use_json) {
10227 json_object_string_add(json_neigh, "hostForeign",
10228 sockunion2str(p->su_remote, buf1,
10229 SU_ADDRSTRLEN));
10230 json_object_int_add(json_neigh, "portForeign",
10231 ntohs(p->su_remote->sin.sin_port));
10232 } else
10233 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10234 sockunion2str(p->su_remote, buf1,
10235 SU_ADDRSTRLEN),
10236 ntohs(p->su_remote->sin.sin_port));
10237 }
10238
10239 /* Nexthop display. */
10240 if (p->su_local) {
10241 if (use_json) {
10242 json_object_string_add(json_neigh, "nexthop",
10243 inet_ntop(AF_INET,
10244 &p->nexthop.v4, buf1,
10245 sizeof(buf1)));
10246 json_object_string_add(json_neigh, "nexthopGlobal",
10247 inet_ntop(AF_INET6,
10248 &p->nexthop.v6_global,
10249 buf1, sizeof(buf1)));
10250 json_object_string_add(json_neigh, "nexthopLocal",
10251 inet_ntop(AF_INET6,
10252 &p->nexthop.v6_local,
10253 buf1, sizeof(buf1)));
10254 if (p->shared_network)
10255 json_object_string_add(json_neigh,
10256 "bgpConnection",
10257 "sharedNetwork");
10258 else
10259 json_object_string_add(json_neigh,
10260 "bgpConnection",
10261 "nonSharedNetwork");
10262 } else {
10263 vty_out(vty, "Nexthop: %s\n",
10264 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10265 sizeof(buf1)));
10266 vty_out(vty, "Nexthop global: %s\n",
10267 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10268 sizeof(buf1)));
10269 vty_out(vty, "Nexthop local: %s\n",
10270 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10271 sizeof(buf1)));
10272 vty_out(vty, "BGP connection: %s\n",
10273 p->shared_network ? "shared network"
10274 : "non shared network");
10275 }
10276 }
10277
10278 /* Timer information. */
10279 if (use_json) {
10280 json_object_int_add(json_neigh, "connectRetryTimer",
10281 p->v_connect);
10282 if (p->status == Established && p->rtt)
10283 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10284 p->rtt);
10285 if (p->t_start)
10286 json_object_int_add(
10287 json_neigh, "nextStartTimerDueInMsecs",
10288 thread_timer_remain_second(p->t_start) * 1000);
10289 if (p->t_connect)
10290 json_object_int_add(
10291 json_neigh, "nextConnectTimerDueInMsecs",
10292 thread_timer_remain_second(p->t_connect)
10293 * 1000);
10294 if (p->t_routeadv) {
10295 json_object_int_add(json_neigh, "mraiInterval",
10296 p->v_routeadv);
10297 json_object_int_add(
10298 json_neigh, "mraiTimerExpireInMsecs",
10299 thread_timer_remain_second(p->t_routeadv)
10300 * 1000);
10301 }
10302 if (p->password)
10303 json_object_int_add(json_neigh, "authenticationEnabled",
10304 1);
10305
10306 if (p->t_read)
10307 json_object_string_add(json_neigh, "readThread", "on");
10308 else
10309 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10310
10311 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10312 json_object_string_add(json_neigh, "writeThread", "on");
10313 else
10314 json_object_string_add(json_neigh, "writeThread",
10315 "off");
10316 } else {
10317 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10318 p->v_connect);
10319 if (p->status == Established && p->rtt)
10320 vty_out(vty, "Estimated round trip time: %d ms\n",
10321 p->rtt);
10322 if (p->t_start)
10323 vty_out(vty, "Next start timer due in %ld seconds\n",
10324 thread_timer_remain_second(p->t_start));
10325 if (p->t_connect)
10326 vty_out(vty, "Next connect timer due in %ld seconds\n",
10327 thread_timer_remain_second(p->t_connect));
10328 if (p->t_routeadv)
10329 vty_out(vty,
10330 "MRAI (interval %u) timer expires in %ld seconds\n",
10331 p->v_routeadv,
10332 thread_timer_remain_second(p->t_routeadv));
10333 if (p->password)
10334 vty_out(vty, "Peer Authentication Enabled\n");
10335
10336 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10337 p->t_read ? "on" : "off",
10338 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10339 ? "on"
10340 : "off");
d62a17ae 10341 }
10342
10343 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10344 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10345 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10346
10347 if (!use_json)
10348 vty_out(vty, "\n");
10349
10350 /* BFD information. */
10351 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10352
10353 if (use_json) {
10354 if (p->conf_if) /* Configured interface name. */
10355 json_object_object_add(json, p->conf_if, json_neigh);
10356 else /* Configured IP address. */
10357 json_object_object_add(json, p->host, json_neigh);
10358 }
10359}
10360
10361static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10362 enum show_type type, union sockunion *su,
10363 const char *conf_if, u_char use_json,
10364 json_object *json)
10365{
10366 struct listnode *node, *nnode;
10367 struct peer *peer;
10368 int find = 0;
10369
10370 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10371 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10372 continue;
10373
10374 switch (type) {
10375 case show_all:
10376 bgp_show_peer(vty, peer, use_json, json);
10377 break;
10378 case show_peer:
10379 if (conf_if) {
10380 if ((peer->conf_if
10381 && !strcmp(peer->conf_if, conf_if))
10382 || (peer->hostname
10383 && !strcmp(peer->hostname, conf_if))) {
10384 find = 1;
10385 bgp_show_peer(vty, peer, use_json,
10386 json);
10387 }
10388 } else {
10389 if (sockunion_same(&peer->su, su)) {
10390 find = 1;
10391 bgp_show_peer(vty, peer, use_json,
10392 json);
10393 }
10394 }
10395 break;
10396 }
10397 }
10398
10399 if (type == show_peer && !find) {
10400 if (use_json)
10401 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10402 else
10403 vty_out(vty, "%% No such neighbor\n");
10404 }
10405
10406 if (use_json) {
996c9314
LB
10407 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10408 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10409 json_object_free(json);
10410 } else {
10411 vty_out(vty, "\n");
10412 }
10413
10414 return CMD_SUCCESS;
10415}
10416
10417static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10418 enum show_type type,
10419 const char *ip_str,
d62a17ae 10420 u_char use_json)
10421{
0291c246
MK
10422 struct listnode *node, *nnode;
10423 struct bgp *bgp;
71aedaa3 10424 union sockunion su;
0291c246 10425 json_object *json = NULL;
71aedaa3 10426 int ret, is_first = 1;
d62a17ae 10427
10428 if (use_json)
10429 vty_out(vty, "{\n");
10430
10431 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10432 if (use_json) {
10433 if (!(json = json_object_new_object())) {
10434 zlog_err(
10435 "Unable to allocate memory for JSON object");
10436 vty_out(vty,
10437 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10438 return;
10439 }
10440
10441 json_object_int_add(json, "vrfId",
10442 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10443 ? -1
10444 : (int64_t)bgp->vrf_id);
d62a17ae 10445 json_object_string_add(
10446 json, "vrfName",
10447 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10448 ? "Default"
10449 : bgp->name);
10450
10451 if (!is_first)
10452 vty_out(vty, ",\n");
10453 else
10454 is_first = 0;
10455
10456 vty_out(vty, "\"%s\":",
10457 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10458 ? "Default"
10459 : bgp->name);
10460 } else {
10461 vty_out(vty, "\nInstance %s:\n",
10462 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10463 ? "Default"
10464 : bgp->name);
10465 }
71aedaa3
DS
10466
10467 if (type == show_peer) {
10468 ret = str2sockunion(ip_str, &su);
10469 if (ret < 0)
10470 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10471 use_json, json);
10472 else
10473 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10474 use_json, json);
10475 } else {
10476 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10477 use_json, json);
10478 }
d62a17ae 10479 }
10480
10481 if (use_json)
10482 vty_out(vty, "}\n");
10483}
10484
10485static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10486 enum show_type type, const char *ip_str,
10487 u_char use_json)
10488{
10489 int ret;
10490 struct bgp *bgp;
10491 union sockunion su;
10492 json_object *json = NULL;
10493
10494 if (name) {
10495 if (strmatch(name, "all")) {
71aedaa3
DS
10496 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10497 use_json);
d62a17ae 10498 return CMD_SUCCESS;
10499 } else {
10500 bgp = bgp_lookup_by_name(name);
10501 if (!bgp) {
10502 if (use_json) {
10503 json = json_object_new_object();
10504 json_object_boolean_true_add(
10505 json, "bgpNoSuchInstance");
10506 vty_out(vty, "%s\n",
10507 json_object_to_json_string_ext(
10508 json,
10509 JSON_C_TO_STRING_PRETTY));
10510 json_object_free(json);
10511 } else
10512 vty_out(vty,
10513 "%% No such BGP instance exist\n");
10514
10515 return CMD_WARNING;
10516 }
10517 }
10518 } else {
10519 bgp = bgp_get_default();
10520 }
10521
10522 if (bgp) {
10523 json = json_object_new_object();
10524 if (ip_str) {
10525 ret = str2sockunion(ip_str, &su);
10526 if (ret < 0)
10527 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10528 use_json, json);
10529 else
10530 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10531 use_json, json);
10532 } else {
10533 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10534 json);
10535 }
10536 json_object_free(json);
10537 }
10538
10539 return CMD_SUCCESS;
4fb25c53
DW
10540}
10541
716b2d8a 10542/* "show [ip] bgp neighbors" commands. */
718e3744 10543DEFUN (show_ip_bgp_neighbors,
10544 show_ip_bgp_neighbors_cmd,
24345e82 10545 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10546 SHOW_STR
10547 IP_STR
10548 BGP_STR
f2a8972b 10549 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10550 "Address Family\n"
10551 "Address Family\n"
718e3744 10552 "Detailed information on TCP and BGP neighbor connections\n"
10553 "Neighbor to display information about\n"
a80beece 10554 "Neighbor to display information about\n"
91d37724 10555 "Neighbor on BGP configured interface\n"
9973d184 10556 JSON_STR)
718e3744 10557{
d62a17ae 10558 char *vrf = NULL;
10559 char *sh_arg = NULL;
10560 enum show_type sh_type;
718e3744 10561
d62a17ae 10562 u_char uj = use_json(argc, argv);
718e3744 10563
d62a17ae 10564 int idx = 0;
718e3744 10565
d62a17ae 10566 if (argv_find(argv, argc, "view", &idx)
10567 || argv_find(argv, argc, "vrf", &idx))
10568 vrf = argv[idx + 1]->arg;
718e3744 10569
d62a17ae 10570 idx++;
10571 if (argv_find(argv, argc, "A.B.C.D", &idx)
10572 || argv_find(argv, argc, "X:X::X:X", &idx)
10573 || argv_find(argv, argc, "WORD", &idx)) {
10574 sh_type = show_peer;
10575 sh_arg = argv[idx]->arg;
10576 } else
10577 sh_type = show_all;
856ca177 10578
d62a17ae 10579 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10580}
10581
716b2d8a 10582/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10583 paths' and `show ip mbgp paths'. Those functions results are the
10584 same.*/
f412b39a 10585DEFUN (show_ip_bgp_paths,
718e3744 10586 show_ip_bgp_paths_cmd,
46f296b4 10587 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10588 SHOW_STR
10589 IP_STR
10590 BGP_STR
46f296b4 10591 BGP_SAFI_HELP_STR
718e3744 10592 "Path information\n")
10593{
d62a17ae 10594 vty_out(vty, "Address Refcnt Path\n");
10595 aspath_print_all_vty(vty);
10596 return CMD_SUCCESS;
718e3744 10597}
10598
718e3744 10599#include "hash.h"
10600
d62a17ae 10601static void community_show_all_iterator(struct hash_backet *backet,
10602 struct vty *vty)
718e3744 10603{
d62a17ae 10604 struct community *com;
718e3744 10605
d62a17ae 10606 com = (struct community *)backet->data;
3f65c5b1 10607 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10608 community_str(com, false));
718e3744 10609}
10610
10611/* Show BGP's community internal data. */
f412b39a 10612DEFUN (show_ip_bgp_community_info,
718e3744 10613 show_ip_bgp_community_info_cmd,
bec37ba5 10614 "show [ip] bgp community-info",
718e3744 10615 SHOW_STR
10616 IP_STR
10617 BGP_STR
10618 "List all bgp community information\n")
10619{
d62a17ae 10620 vty_out(vty, "Address Refcnt Community\n");
718e3744 10621
d62a17ae 10622 hash_iterate(community_hash(),
10623 (void (*)(struct hash_backet *,
10624 void *))community_show_all_iterator,
10625 vty);
718e3744 10626
d62a17ae 10627 return CMD_SUCCESS;
718e3744 10628}
10629
d62a17ae 10630static void lcommunity_show_all_iterator(struct hash_backet *backet,
10631 struct vty *vty)
57d187bc 10632{
d62a17ae 10633 struct lcommunity *lcom;
57d187bc 10634
d62a17ae 10635 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10636 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
d62a17ae 10637 lcommunity_str(lcom));
57d187bc
JS
10638}
10639
10640/* Show BGP's community internal data. */
10641DEFUN (show_ip_bgp_lcommunity_info,
10642 show_ip_bgp_lcommunity_info_cmd,
10643 "show ip bgp large-community-info",
10644 SHOW_STR
10645 IP_STR
10646 BGP_STR
10647 "List all bgp large-community information\n")
10648{
d62a17ae 10649 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10650
d62a17ae 10651 hash_iterate(lcommunity_hash(),
10652 (void (*)(struct hash_backet *,
10653 void *))lcommunity_show_all_iterator,
10654 vty);
57d187bc 10655
d62a17ae 10656 return CMD_SUCCESS;
57d187bc
JS
10657}
10658
10659
f412b39a 10660DEFUN (show_ip_bgp_attr_info,
718e3744 10661 show_ip_bgp_attr_info_cmd,
bec37ba5 10662 "show [ip] bgp attribute-info",
718e3744 10663 SHOW_STR
10664 IP_STR
10665 BGP_STR
10666 "List all bgp attribute information\n")
10667{
d62a17ae 10668 attr_show_all(vty);
10669 return CMD_SUCCESS;
718e3744 10670}
6b0655a2 10671
d62a17ae 10672static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10673 safi_t safi)
f186de26 10674{
d62a17ae 10675 struct listnode *node, *nnode;
10676 struct bgp *bgp;
f186de26 10677
d62a17ae 10678 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10679 vty_out(vty, "\nInstance %s:\n",
10680 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10681 ? "Default"
10682 : bgp->name);
10683 update_group_show(bgp, afi, safi, vty, 0);
10684 }
f186de26 10685}
10686
d62a17ae 10687static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10688 int safi, uint64_t subgrp_id)
4fb25c53 10689{
d62a17ae 10690 struct bgp *bgp;
4fb25c53 10691
d62a17ae 10692 if (name) {
10693 if (strmatch(name, "all")) {
10694 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10695 return CMD_SUCCESS;
10696 } else {
10697 bgp = bgp_lookup_by_name(name);
10698 }
10699 } else {
10700 bgp = bgp_get_default();
10701 }
4fb25c53 10702
d62a17ae 10703 if (bgp)
10704 update_group_show(bgp, afi, safi, vty, subgrp_id);
10705 return CMD_SUCCESS;
4fb25c53
DW
10706}
10707
8fe8a7f6
DS
10708DEFUN (show_ip_bgp_updgrps,
10709 show_ip_bgp_updgrps_cmd,
c1a44e43 10710 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 10711 SHOW_STR
10712 IP_STR
10713 BGP_STR
10714 BGP_INSTANCE_HELP_STR
c9e571b4 10715 BGP_AFI_HELP_STR
9bedbb1e 10716 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
10717 "Detailed info about dynamic update groups\n"
10718 "Specific subgroup to display detailed info for\n")
8386ac43 10719{
d62a17ae 10720 char *vrf = NULL;
10721 afi_t afi = AFI_IP6;
10722 safi_t safi = SAFI_UNICAST;
10723 uint64_t subgrp_id = 0;
10724
10725 int idx = 0;
10726
10727 /* show [ip] bgp */
10728 if (argv_find(argv, argc, "ip", &idx))
10729 afi = AFI_IP;
10730 /* [<view|vrf> VIEWVRFNAME] */
10731 if (argv_find(argv, argc, "view", &idx)
10732 || argv_find(argv, argc, "vrf", &idx))
10733 vrf = argv[++idx]->arg;
10734 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10735 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10736 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10737 }
5bf15956 10738
d62a17ae 10739 /* get subgroup id, if provided */
10740 idx = argc - 1;
10741 if (argv[idx]->type == VARIABLE_TKN)
10742 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 10743
d62a17ae 10744 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
10745}
10746
f186de26 10747DEFUN (show_bgp_instance_all_ipv6_updgrps,
10748 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 10749 "show [ip] bgp <view|vrf> all update-groups",
f186de26 10750 SHOW_STR
716b2d8a 10751 IP_STR
f186de26 10752 BGP_STR
10753 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 10754 "Detailed info about dynamic update groups\n")
f186de26 10755{
d62a17ae 10756 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10757 return CMD_SUCCESS;
f186de26 10758}
10759
5bf15956
DW
10760DEFUN (show_bgp_updgrps_stats,
10761 show_bgp_updgrps_stats_cmd,
716b2d8a 10762 "show [ip] bgp update-groups statistics",
3f9c7369 10763 SHOW_STR
716b2d8a 10764 IP_STR
3f9c7369 10765 BGP_STR
0c7b1b01 10766 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10767 "Statistics\n")
10768{
d62a17ae 10769 struct bgp *bgp;
3f9c7369 10770
d62a17ae 10771 bgp = bgp_get_default();
10772 if (bgp)
10773 update_group_show_stats(bgp, vty);
3f9c7369 10774
d62a17ae 10775 return CMD_SUCCESS;
3f9c7369
DS
10776}
10777
8386ac43 10778DEFUN (show_bgp_instance_updgrps_stats,
10779 show_bgp_instance_updgrps_stats_cmd,
18c57037 10780 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 10781 SHOW_STR
716b2d8a 10782 IP_STR
8386ac43 10783 BGP_STR
10784 BGP_INSTANCE_HELP_STR
0c7b1b01 10785 "Detailed info about dynamic update groups\n"
8386ac43 10786 "Statistics\n")
10787{
d62a17ae 10788 int idx_word = 3;
10789 struct bgp *bgp;
8386ac43 10790
d62a17ae 10791 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10792 if (bgp)
10793 update_group_show_stats(bgp, vty);
8386ac43 10794
d62a17ae 10795 return CMD_SUCCESS;
8386ac43 10796}
10797
d62a17ae 10798static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10799 afi_t afi, safi_t safi,
10800 const char *what, uint64_t subgrp_id)
3f9c7369 10801{
d62a17ae 10802 struct bgp *bgp;
8386ac43 10803
d62a17ae 10804 if (name)
10805 bgp = bgp_lookup_by_name(name);
10806 else
10807 bgp = bgp_get_default();
8386ac43 10808
d62a17ae 10809 if (bgp) {
10810 if (!strcmp(what, "advertise-queue"))
10811 update_group_show_adj_queue(bgp, afi, safi, vty,
10812 subgrp_id);
10813 else if (!strcmp(what, "advertised-routes"))
10814 update_group_show_advertised(bgp, afi, safi, vty,
10815 subgrp_id);
10816 else if (!strcmp(what, "packet-queue"))
10817 update_group_show_packet_queue(bgp, afi, safi, vty,
10818 subgrp_id);
10819 }
3f9c7369
DS
10820}
10821
dc64bdec
QY
10822DEFPY(show_ip_bgp_instance_updgrps_adj_s,
10823 show_ip_bgp_instance_updgrps_adj_s_cmd,
10824 "show [ip]$ip bgp [<view|vrf> VIEWVRFNAME$vrf] [<ipv4|ipv6>$afi <unicast|multicast|vpn>$safi] update-groups [SUBGROUP-ID]$sgid <advertise-queue|advertised-routes|packet-queue>$rtq",
10825 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
10826 BGP_SAFI_HELP_STR
10827 "Detailed info about dynamic update groups\n"
10828 "Specific subgroup to display info for\n"
10829 "Advertisement queue\n"
10830 "Announced routes\n"
10831 "Packet queue\n")
3f9c7369 10832{
dc64bdec
QY
10833 uint64_t subgrp_id = 0;
10834 afi_t afiz;
10835 safi_t safiz;
10836 if (sgid)
10837 subgrp_id = strtoull(sgid, NULL, 10);
10838
10839 if (!ip && !afi)
10840 afiz = AFI_IP6;
10841 if (!ip && afi)
10842 afiz = bgp_vty_afi_from_str(afi);
10843 if (ip && !afi)
10844 afiz = AFI_IP;
10845 if (ip && afi) {
10846 afiz = bgp_vty_afi_from_str(afi);
10847 if (afiz != AFI_IP)
10848 vty_out(vty,
10849 "%% Cannot specify both 'ip' and 'ipv6'\n");
10850 return CMD_WARNING;
10851 }
d62a17ae 10852
dc64bdec 10853 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 10854
dc64bdec 10855 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 10856 return CMD_SUCCESS;
10857}
10858
d62a17ae 10859static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10860{
10861 struct listnode *node, *nnode;
10862 struct prefix *range;
10863 struct peer *conf;
10864 struct peer *peer;
10865 char buf[PREFIX2STR_BUFFER];
10866 afi_t afi;
10867 safi_t safi;
10868 const char *peer_status;
10869 const char *af_str;
10870 int lr_count;
10871 int dynamic;
10872 int af_cfgd;
10873
10874 conf = group->conf;
10875
10876 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10877 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10878 conf->as);
10879 } else if (conf->as_type == AS_INTERNAL) {
10880 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10881 group->bgp->as);
10882 } else {
10883 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10884 }
f14e6fdb 10885
d62a17ae 10886 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10887 vty_out(vty, " Peer-group type is internal\n");
10888 else
10889 vty_out(vty, " Peer-group type is external\n");
10890
10891 /* Display AFs configured. */
10892 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
10893 FOREACH_AFI_SAFI (afi, safi) {
10894 if (conf->afc[afi][safi]) {
10895 af_cfgd = 1;
10896 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 10897 }
05c7a1cc 10898 }
d62a17ae 10899 if (!af_cfgd)
10900 vty_out(vty, " none\n");
10901 else
10902 vty_out(vty, "\n");
10903
10904 /* Display listen ranges (for dynamic neighbors), if any */
10905 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10906 if (afi == AFI_IP)
10907 af_str = "IPv4";
10908 else if (afi == AFI_IP6)
10909 af_str = "IPv6";
10910 else
10911 af_str = "???";
10912 lr_count = listcount(group->listen_range[afi]);
10913 if (lr_count) {
10914 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10915 af_str);
10916
10917
10918 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10919 nnode, range)) {
10920 prefix2str(range, buf, sizeof(buf));
10921 vty_out(vty, " %s\n", buf);
10922 }
10923 }
10924 }
f14e6fdb 10925
d62a17ae 10926 /* Display group members and their status */
10927 if (listcount(group->peer)) {
10928 vty_out(vty, " Peer-group members:\n");
10929 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10930 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10931 peer_status = "Idle (Admin)";
10932 else if (CHECK_FLAG(peer->sflags,
10933 PEER_STATUS_PREFIX_OVERFLOW))
10934 peer_status = "Idle (PfxCt)";
10935 else
10936 peer_status = lookup_msg(bgp_status_msg,
10937 peer->status, NULL);
10938
10939 dynamic = peer_dynamic_neighbor(peer);
10940 vty_out(vty, " %s %s %s \n", peer->host,
10941 dynamic ? "(dynamic)" : "", peer_status);
10942 }
10943 }
f14e6fdb 10944
d62a17ae 10945 return CMD_SUCCESS;
10946}
10947
ff9959b0
QY
10948static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10949 const char *group_name)
d62a17ae 10950{
ff9959b0 10951 struct bgp *bgp;
d62a17ae 10952 struct listnode *node, *nnode;
10953 struct peer_group *group;
ff9959b0
QY
10954 bool found = false;
10955
10956 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
10957
10958 if (!bgp) {
10959 vty_out(vty, "%% No such BGP instance exists\n");
10960 return CMD_WARNING;
10961 }
d62a17ae 10962
10963 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
10964 if (group_name) {
10965 if (strmatch(group->name, group_name)) {
d62a17ae 10966 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
10967 found = true;
10968 break;
d62a17ae 10969 }
ff9959b0
QY
10970 } else {
10971 bgp_show_one_peer_group(vty, group);
d62a17ae 10972 }
f14e6fdb 10973 }
f14e6fdb 10974
ff9959b0 10975 if (group_name && !found)
d62a17ae 10976 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 10977
d62a17ae 10978 return CMD_SUCCESS;
f14e6fdb
DS
10979}
10980
f14e6fdb
DS
10981DEFUN (show_ip_bgp_peer_groups,
10982 show_ip_bgp_peer_groups_cmd,
18c57037 10983 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10984 SHOW_STR
10985 IP_STR
10986 BGP_STR
8386ac43 10987 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10988 "Detailed information on BGP peer groups\n"
10989 "Peer group name\n")
f14e6fdb 10990{
d62a17ae 10991 char *vrf, *pg;
10992 vrf = pg = NULL;
10993 int idx = 0;
f14e6fdb 10994
a4d82a8a
PZ
10995 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
10996 : NULL;
d62a17ae 10997 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10998
ff9959b0 10999 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 11000}
3f9c7369 11001
d6e3c605 11002
718e3744 11003/* Redistribute VTY commands. */
11004
718e3744 11005DEFUN (bgp_redistribute_ipv4,
11006 bgp_redistribute_ipv4_cmd,
40d1cbfb 11007 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 11008 "Redistribute information from another routing protocol\n"
ab0181ee 11009 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 11010{
d62a17ae 11011 VTY_DECLVAR_CONTEXT(bgp, bgp);
11012 int idx_protocol = 1;
11013 int type;
718e3744 11014
d62a17ae 11015 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11016 if (type < 0) {
11017 vty_out(vty, "%% Invalid route type\n");
11018 return CMD_WARNING_CONFIG_FAILED;
11019 }
7f323236 11020
d62a17ae 11021 bgp_redist_add(bgp, AFI_IP, type, 0);
11022 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11023}
11024
d62a17ae 11025ALIAS_HIDDEN(
11026 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
11027 "redistribute " FRR_IP_REDIST_STR_BGPD,
11028 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 11029
718e3744 11030DEFUN (bgp_redistribute_ipv4_rmap,
11031 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 11032 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 11033 "Redistribute information from another routing protocol\n"
ab0181ee 11034 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11035 "Route map reference\n"
11036 "Pointer to route-map entries\n")
11037{
d62a17ae 11038 VTY_DECLVAR_CONTEXT(bgp, bgp);
11039 int idx_protocol = 1;
11040 int idx_word = 3;
11041 int type;
11042 struct bgp_redist *red;
718e3744 11043
d62a17ae 11044 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11045 if (type < 0) {
11046 vty_out(vty, "%% Invalid route type\n");
11047 return CMD_WARNING_CONFIG_FAILED;
11048 }
718e3744 11049
d62a17ae 11050 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11051 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11052 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11053}
11054
d62a17ae 11055ALIAS_HIDDEN(
11056 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11057 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11058 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11059 "Route map reference\n"
11060 "Pointer to route-map entries\n")
596c17ba 11061
718e3744 11062DEFUN (bgp_redistribute_ipv4_metric,
11063 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11064 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11065 "Redistribute information from another routing protocol\n"
ab0181ee 11066 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11067 "Metric for redistributed routes\n"
11068 "Default metric\n")
11069{
d62a17ae 11070 VTY_DECLVAR_CONTEXT(bgp, bgp);
11071 int idx_protocol = 1;
11072 int idx_number = 3;
11073 int type;
11074 u_int32_t metric;
11075 struct bgp_redist *red;
11076
11077 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11078 if (type < 0) {
11079 vty_out(vty, "%% Invalid route type\n");
11080 return CMD_WARNING_CONFIG_FAILED;
11081 }
11082 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11083
11084 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11085 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11086 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11087}
11088
11089ALIAS_HIDDEN(
11090 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11091 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11092 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11093 "Metric for redistributed routes\n"
11094 "Default metric\n")
596c17ba 11095
718e3744 11096DEFUN (bgp_redistribute_ipv4_rmap_metric,
11097 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11098 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11099 "Redistribute information from another routing protocol\n"
ab0181ee 11100 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11101 "Route map reference\n"
11102 "Pointer to route-map entries\n"
11103 "Metric for redistributed routes\n"
11104 "Default metric\n")
11105{
d62a17ae 11106 VTY_DECLVAR_CONTEXT(bgp, bgp);
11107 int idx_protocol = 1;
11108 int idx_word = 3;
11109 int idx_number = 5;
11110 int type;
11111 u_int32_t metric;
11112 struct bgp_redist *red;
11113
11114 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11115 if (type < 0) {
11116 vty_out(vty, "%% Invalid route type\n");
11117 return CMD_WARNING_CONFIG_FAILED;
11118 }
11119 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11120
11121 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11122 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11123 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11124 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11125}
11126
11127ALIAS_HIDDEN(
11128 bgp_redistribute_ipv4_rmap_metric,
11129 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11130 "redistribute " FRR_IP_REDIST_STR_BGPD
11131 " route-map WORD metric (0-4294967295)",
11132 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11133 "Route map reference\n"
11134 "Pointer to route-map entries\n"
11135 "Metric for redistributed routes\n"
11136 "Default metric\n")
596c17ba 11137
718e3744 11138DEFUN (bgp_redistribute_ipv4_metric_rmap,
11139 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11140 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11141 "Redistribute information from another routing protocol\n"
ab0181ee 11142 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11143 "Metric for redistributed routes\n"
11144 "Default metric\n"
11145 "Route map reference\n"
11146 "Pointer to route-map entries\n")
11147{
d62a17ae 11148 VTY_DECLVAR_CONTEXT(bgp, bgp);
11149 int idx_protocol = 1;
11150 int idx_number = 3;
11151 int idx_word = 5;
11152 int type;
11153 u_int32_t metric;
11154 struct bgp_redist *red;
11155
11156 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11157 if (type < 0) {
11158 vty_out(vty, "%% Invalid route type\n");
11159 return CMD_WARNING_CONFIG_FAILED;
11160 }
11161 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11162
11163 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11164 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11165 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11166 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11167}
11168
11169ALIAS_HIDDEN(
11170 bgp_redistribute_ipv4_metric_rmap,
11171 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11172 "redistribute " FRR_IP_REDIST_STR_BGPD
11173 " metric (0-4294967295) route-map WORD",
11174 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11175 "Metric for redistributed routes\n"
11176 "Default metric\n"
11177 "Route map reference\n"
11178 "Pointer to route-map entries\n")
596c17ba 11179
7c8ff89e
DS
11180DEFUN (bgp_redistribute_ipv4_ospf,
11181 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11182 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11183 "Redistribute information from another routing protocol\n"
11184 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11185 "Non-main Kernel Routing Table\n"
11186 "Instance ID/Table ID\n")
7c8ff89e 11187{
d62a17ae 11188 VTY_DECLVAR_CONTEXT(bgp, bgp);
11189 int idx_ospf_table = 1;
11190 int idx_number = 2;
11191 u_short instance;
11192 u_short protocol;
7c8ff89e 11193
d62a17ae 11194 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11195
d62a17ae 11196 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11197 protocol = ZEBRA_ROUTE_OSPF;
11198 else
11199 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11200
d62a17ae 11201 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11202 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
11203}
11204
d62a17ae 11205ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11206 "redistribute <ospf|table> (1-65535)",
11207 "Redistribute information from another routing protocol\n"
11208 "Open Shortest Path First (OSPFv2)\n"
11209 "Non-main Kernel Routing Table\n"
11210 "Instance ID/Table ID\n")
596c17ba 11211
7c8ff89e
DS
11212DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11213 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11214 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11215 "Redistribute information from another routing protocol\n"
11216 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11217 "Non-main Kernel Routing Table\n"
11218 "Instance ID/Table ID\n"
7c8ff89e
DS
11219 "Route map reference\n"
11220 "Pointer to route-map entries\n")
11221{
d62a17ae 11222 VTY_DECLVAR_CONTEXT(bgp, bgp);
11223 int idx_ospf_table = 1;
11224 int idx_number = 2;
11225 int idx_word = 4;
11226 struct bgp_redist *red;
11227 u_short instance;
11228 int protocol;
11229
11230 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11231 protocol = ZEBRA_ROUTE_OSPF;
11232 else
11233 protocol = ZEBRA_ROUTE_TABLE;
11234
11235 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11236 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11237 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11238 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11239}
11240
11241ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11242 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11243 "redistribute <ospf|table> (1-65535) route-map WORD",
11244 "Redistribute information from another routing protocol\n"
11245 "Open Shortest Path First (OSPFv2)\n"
11246 "Non-main Kernel Routing Table\n"
11247 "Instance ID/Table ID\n"
11248 "Route map reference\n"
11249 "Pointer to route-map entries\n")
596c17ba 11250
7c8ff89e
DS
11251DEFUN (bgp_redistribute_ipv4_ospf_metric,
11252 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11253 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11254 "Redistribute information from another routing protocol\n"
11255 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11256 "Non-main Kernel Routing Table\n"
11257 "Instance ID/Table ID\n"
7c8ff89e
DS
11258 "Metric for redistributed routes\n"
11259 "Default metric\n")
11260{
d62a17ae 11261 VTY_DECLVAR_CONTEXT(bgp, bgp);
11262 int idx_ospf_table = 1;
11263 int idx_number = 2;
11264 int idx_number_2 = 4;
11265 u_int32_t metric;
11266 struct bgp_redist *red;
11267 u_short instance;
11268 int protocol;
11269
11270 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11271 protocol = ZEBRA_ROUTE_OSPF;
11272 else
11273 protocol = ZEBRA_ROUTE_TABLE;
11274
11275 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11276 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11277
11278 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11279 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11280 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11281}
11282
11283ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11284 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11285 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11286 "Redistribute information from another routing protocol\n"
11287 "Open Shortest Path First (OSPFv2)\n"
11288 "Non-main Kernel Routing Table\n"
11289 "Instance ID/Table ID\n"
11290 "Metric for redistributed routes\n"
11291 "Default metric\n")
596c17ba 11292
7c8ff89e
DS
11293DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11294 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11295 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11296 "Redistribute information from another routing protocol\n"
11297 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11298 "Non-main Kernel Routing Table\n"
11299 "Instance ID/Table ID\n"
7c8ff89e
DS
11300 "Route map reference\n"
11301 "Pointer to route-map entries\n"
11302 "Metric for redistributed routes\n"
11303 "Default metric\n")
11304{
d62a17ae 11305 VTY_DECLVAR_CONTEXT(bgp, bgp);
11306 int idx_ospf_table = 1;
11307 int idx_number = 2;
11308 int idx_word = 4;
11309 int idx_number_2 = 6;
11310 u_int32_t metric;
11311 struct bgp_redist *red;
11312 u_short instance;
11313 int protocol;
11314
11315 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11316 protocol = ZEBRA_ROUTE_OSPF;
11317 else
11318 protocol = ZEBRA_ROUTE_TABLE;
11319
11320 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11321 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11322
11323 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11324 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11325 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11326 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11327}
11328
11329ALIAS_HIDDEN(
11330 bgp_redistribute_ipv4_ospf_rmap_metric,
11331 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11332 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
11333 "Redistribute information from another routing protocol\n"
11334 "Open Shortest Path First (OSPFv2)\n"
11335 "Non-main Kernel Routing Table\n"
11336 "Instance ID/Table ID\n"
11337 "Route map reference\n"
11338 "Pointer to route-map entries\n"
11339 "Metric for redistributed routes\n"
11340 "Default metric\n")
596c17ba 11341
7c8ff89e
DS
11342DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11343 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11344 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11345 "Redistribute information from another routing protocol\n"
11346 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11347 "Non-main Kernel Routing Table\n"
11348 "Instance ID/Table ID\n"
7c8ff89e
DS
11349 "Metric for redistributed routes\n"
11350 "Default metric\n"
11351 "Route map reference\n"
11352 "Pointer to route-map entries\n")
11353{
d62a17ae 11354 VTY_DECLVAR_CONTEXT(bgp, bgp);
11355 int idx_ospf_table = 1;
11356 int idx_number = 2;
11357 int idx_number_2 = 4;
11358 int idx_word = 6;
11359 u_int32_t metric;
11360 struct bgp_redist *red;
11361 u_short instance;
11362 int protocol;
11363
11364 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11365 protocol = ZEBRA_ROUTE_OSPF;
11366 else
11367 protocol = ZEBRA_ROUTE_TABLE;
11368
11369 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11370 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11371
11372 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11373 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11374 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11375 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11376}
11377
11378ALIAS_HIDDEN(
11379 bgp_redistribute_ipv4_ospf_metric_rmap,
11380 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11381 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11382 "Redistribute information from another routing protocol\n"
11383 "Open Shortest Path First (OSPFv2)\n"
11384 "Non-main Kernel Routing Table\n"
11385 "Instance ID/Table ID\n"
11386 "Metric for redistributed routes\n"
11387 "Default metric\n"
11388 "Route map reference\n"
11389 "Pointer to route-map entries\n")
596c17ba 11390
7c8ff89e
DS
11391DEFUN (no_bgp_redistribute_ipv4_ospf,
11392 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11393 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11394 NO_STR
11395 "Redistribute information from another routing protocol\n"
11396 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11397 "Non-main Kernel Routing Table\n"
31500417
DW
11398 "Instance ID/Table ID\n"
11399 "Metric for redistributed routes\n"
11400 "Default metric\n"
11401 "Route map reference\n"
11402 "Pointer to route-map entries\n")
7c8ff89e 11403{
d62a17ae 11404 VTY_DECLVAR_CONTEXT(bgp, bgp);
11405 int idx_ospf_table = 2;
11406 int idx_number = 3;
11407 u_short instance;
11408 int protocol;
11409
11410 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11411 protocol = ZEBRA_ROUTE_OSPF;
11412 else
11413 protocol = ZEBRA_ROUTE_TABLE;
11414
11415 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11416 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11417}
11418
11419ALIAS_HIDDEN(
11420 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11421 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11422 NO_STR
11423 "Redistribute information from another routing protocol\n"
11424 "Open Shortest Path First (OSPFv2)\n"
11425 "Non-main Kernel Routing Table\n"
11426 "Instance ID/Table ID\n"
11427 "Metric for redistributed routes\n"
11428 "Default metric\n"
11429 "Route map reference\n"
11430 "Pointer to route-map entries\n")
596c17ba 11431
718e3744 11432DEFUN (no_bgp_redistribute_ipv4,
11433 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11434 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11435 NO_STR
11436 "Redistribute information from another routing protocol\n"
3b14d86e 11437 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11438 "Metric for redistributed routes\n"
11439 "Default metric\n"
11440 "Route map reference\n"
11441 "Pointer to route-map entries\n")
718e3744 11442{
d62a17ae 11443 VTY_DECLVAR_CONTEXT(bgp, bgp);
11444 int idx_protocol = 2;
11445 int type;
11446
11447 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11448 if (type < 0) {
11449 vty_out(vty, "%% Invalid route type\n");
11450 return CMD_WARNING_CONFIG_FAILED;
11451 }
11452 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11453}
11454
11455ALIAS_HIDDEN(
11456 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11457 "no redistribute " FRR_IP_REDIST_STR_BGPD
11458 " [metric (0-4294967295)] [route-map WORD]",
11459 NO_STR
11460 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11461 "Metric for redistributed routes\n"
11462 "Default metric\n"
11463 "Route map reference\n"
11464 "Pointer to route-map entries\n")
596c17ba 11465
718e3744 11466DEFUN (bgp_redistribute_ipv6,
11467 bgp_redistribute_ipv6_cmd,
40d1cbfb 11468 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11469 "Redistribute information from another routing protocol\n"
ab0181ee 11470 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11471{
d62a17ae 11472 VTY_DECLVAR_CONTEXT(bgp, bgp);
11473 int idx_protocol = 1;
11474 int type;
718e3744 11475
d62a17ae 11476 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11477 if (type < 0) {
11478 vty_out(vty, "%% Invalid route type\n");
11479 return CMD_WARNING_CONFIG_FAILED;
11480 }
718e3744 11481
d62a17ae 11482 bgp_redist_add(bgp, AFI_IP6, type, 0);
11483 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11484}
11485
11486DEFUN (bgp_redistribute_ipv6_rmap,
11487 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11488 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11489 "Redistribute information from another routing protocol\n"
ab0181ee 11490 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11491 "Route map reference\n"
11492 "Pointer to route-map entries\n")
11493{
d62a17ae 11494 VTY_DECLVAR_CONTEXT(bgp, bgp);
11495 int idx_protocol = 1;
11496 int idx_word = 3;
11497 int type;
11498 struct bgp_redist *red;
718e3744 11499
d62a17ae 11500 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11501 if (type < 0) {
11502 vty_out(vty, "%% Invalid route type\n");
11503 return CMD_WARNING_CONFIG_FAILED;
11504 }
718e3744 11505
d62a17ae 11506 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11507 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11508 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11509}
11510
11511DEFUN (bgp_redistribute_ipv6_metric,
11512 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11513 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11514 "Redistribute information from another routing protocol\n"
ab0181ee 11515 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11516 "Metric for redistributed routes\n"
11517 "Default metric\n")
11518{
d62a17ae 11519 VTY_DECLVAR_CONTEXT(bgp, bgp);
11520 int idx_protocol = 1;
11521 int idx_number = 3;
11522 int type;
11523 u_int32_t metric;
11524 struct bgp_redist *red;
11525
11526 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11527 if (type < 0) {
11528 vty_out(vty, "%% Invalid route type\n");
11529 return CMD_WARNING_CONFIG_FAILED;
11530 }
11531 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11532
d62a17ae 11533 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11534 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11535 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11536}
11537
11538DEFUN (bgp_redistribute_ipv6_rmap_metric,
11539 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11540 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11541 "Redistribute information from another routing protocol\n"
ab0181ee 11542 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11543 "Route map reference\n"
11544 "Pointer to route-map entries\n"
11545 "Metric for redistributed routes\n"
11546 "Default metric\n")
11547{
d62a17ae 11548 VTY_DECLVAR_CONTEXT(bgp, bgp);
11549 int idx_protocol = 1;
11550 int idx_word = 3;
11551 int idx_number = 5;
11552 int type;
11553 u_int32_t metric;
11554 struct bgp_redist *red;
11555
11556 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11557 if (type < 0) {
11558 vty_out(vty, "%% Invalid route type\n");
11559 return CMD_WARNING_CONFIG_FAILED;
11560 }
11561 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11562
d62a17ae 11563 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11564 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11565 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11566 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11567}
11568
11569DEFUN (bgp_redistribute_ipv6_metric_rmap,
11570 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11571 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11572 "Redistribute information from another routing protocol\n"
ab0181ee 11573 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11574 "Metric for redistributed routes\n"
11575 "Default metric\n"
11576 "Route map reference\n"
11577 "Pointer to route-map entries\n")
11578{
d62a17ae 11579 VTY_DECLVAR_CONTEXT(bgp, bgp);
11580 int idx_protocol = 1;
11581 int idx_number = 3;
11582 int idx_word = 5;
11583 int type;
11584 u_int32_t metric;
11585 struct bgp_redist *red;
11586
11587 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11588 if (type < 0) {
11589 vty_out(vty, "%% Invalid route type\n");
11590 return CMD_WARNING_CONFIG_FAILED;
11591 }
11592 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11593
d62a17ae 11594 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11595 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11596 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11597 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11598}
11599
11600DEFUN (no_bgp_redistribute_ipv6,
11601 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11602 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11603 NO_STR
11604 "Redistribute information from another routing protocol\n"
3b14d86e 11605 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11606 "Metric for redistributed routes\n"
11607 "Default metric\n"
11608 "Route map reference\n"
11609 "Pointer to route-map entries\n")
718e3744 11610{
d62a17ae 11611 VTY_DECLVAR_CONTEXT(bgp, bgp);
11612 int idx_protocol = 2;
11613 int type;
718e3744 11614
d62a17ae 11615 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11616 if (type < 0) {
11617 vty_out(vty, "%% Invalid route type\n");
11618 return CMD_WARNING_CONFIG_FAILED;
11619 }
718e3744 11620
d62a17ae 11621 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11622}
11623
2b791107 11624void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 11625 safi_t safi)
d62a17ae 11626{
11627 int i;
11628
11629 /* Unicast redistribution only. */
11630 if (safi != SAFI_UNICAST)
2b791107 11631 return;
d62a17ae 11632
11633 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11634 /* Redistribute BGP does not make sense. */
11635 if (i != ZEBRA_ROUTE_BGP) {
11636 struct list *red_list;
11637 struct listnode *node;
11638 struct bgp_redist *red;
11639
11640 red_list = bgp->redist[afi][i];
11641 if (!red_list)
11642 continue;
11643
11644 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 11645 /* "redistribute" configuration. */
11646 vty_out(vty, " redistribute %s",
11647 zebra_route_string(i));
11648 if (red->instance)
11649 vty_out(vty, " %d", red->instance);
11650 if (red->redist_metric_flag)
11651 vty_out(vty, " metric %u",
11652 red->redist_metric);
11653 if (red->rmap.name)
11654 vty_out(vty, " route-map %s",
11655 red->rmap.name);
11656 vty_out(vty, "\n");
11657 }
11658 }
11659 }
718e3744 11660}
6b0655a2 11661
ddb5b488
PZ
11662/* This command is valid only in a bgp vrf instance or the default instance */
11663DEFUN (bgp_export_vpn,
11664 bgp_export_vpn_cmd,
11665 "export vpn",
11666 "Export routes to another routing protocol\n"
11667 "to VPN RIB per vpn-policy")
11668{
11669 VTY_DECLVAR_CONTEXT(bgp, bgp);
11670 int was_off = 0;
11671 afi_t afi;
11672 safi_t safi;
11673
11674 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type
11675 && BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
11676 vty_out(vty,
11677 "%% export vpn valid only for bgp vrf or default instance\n");
11678 return CMD_WARNING_CONFIG_FAILED;
11679 }
11680 afi = bgp_node_afi(vty);
11681 safi = bgp_node_safi(vty);
11682 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
11683 vty_out(vty,
11684 "%% export vpn valid only for unicast ipv4|ipv6\n");
11685 return CMD_WARNING_CONFIG_FAILED;
11686 }
11687
11688 if (!CHECK_FLAG(bgp->af_flags[afi][safi],
11689 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
11690 was_off = 1;
11691 }
11692 SET_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT);
11693 if (was_off) {
11694 /* trigger export current vrf */
11695 zlog_debug("%s: calling postchange", __func__);
11696 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
11697 bgp_get_default(), bgp);
11698 }
11699 return CMD_SUCCESS;
11700}
11701
11702DEFUN (bgp_no_export_vpn,
11703 bgp_no_export_vpn_cmd,
11704 "no export vpn",
11705 NO_STR
11706 "Export routes to another routing protocol\n"
11707 "to VPN RIB per vpn-policy")
11708{
11709 VTY_DECLVAR_CONTEXT(bgp, bgp);
11710 int was_on = 0;
11711 afi_t afi;
11712 safi_t safi;
11713
11714 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type
11715 && BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
11716 vty_out(vty,
11717 "%% export vpn valid only for bgp vrf or default instance\n");
11718 return CMD_WARNING_CONFIG_FAILED;
11719 }
11720 afi = bgp_node_afi(vty);
11721 safi = bgp_node_safi(vty);
11722 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
11723 vty_out(vty,
11724 "%% export vpn valid only for unicast ipv4|ipv6\n");
11725 return CMD_WARNING_CONFIG_FAILED;
11726 }
11727
11728 if (CHECK_FLAG(bgp->af_flags[afi][safi],
11729 BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT)) {
11730 was_on = 1;
11731 }
11732 if (was_on) {
11733 /* trigger un-export current vrf */
11734 zlog_debug("%s: calling postchange", __func__);
11735 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
11736 bgp_get_default(), bgp);
11737 }
11738 UNSET_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT);
11739 return CMD_SUCCESS;
11740}
11741
11742static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
11743 afi_t afi)
11744{
11745 vty_frame(vty, " vpn-policy ipv%d\n", ((afi == AFI_IP) ? 4 : 6));
11746
11747 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
11748 vty_out(vty, " label %u\n",
11749 bgp->vpn_policy[afi].tovpn_label);
11750 }
11751 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
11752 BGP_VPN_POLICY_TOVPN_RD_SET)) {
11753 char buf[RD_ADDRSTRLEN];
11754 vty_out(vty, " rd %s\n",
11755 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
11756 sizeof(buf)));
11757 }
11758 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
11759 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
11760
11761 char buf[PREFIX_STRLEN];
11762 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
11763 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
11764 sizeof(buf))) {
11765
11766 vty_out(vty, " nexthop %s\n", buf);
11767 }
11768 }
11769 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
11770 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
11771 && ecommunity_cmp(
11772 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
11773 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
11774
11775 char *b = ecommunity_ecom2str(
11776 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
11777 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
11778 vty_out(vty, " rt both %s\n", b);
11779 XFREE(MTYPE_ECOMMUNITY_STR, b);
11780 } else {
11781 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
11782 char *b = ecommunity_ecom2str(
11783 bgp->vpn_policy[afi]
11784 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
11785 ECOMMUNITY_FORMAT_ROUTE_MAP,
11786 ECOMMUNITY_ROUTE_TARGET);
11787 vty_out(vty, " rt fromvpn %s\n", b);
11788 XFREE(MTYPE_ECOMMUNITY_STR, b);
11789 }
11790 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
11791 char *b = ecommunity_ecom2str(
11792 bgp->vpn_policy[afi]
11793 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
11794 ECOMMUNITY_FORMAT_ROUTE_MAP,
11795 ECOMMUNITY_ROUTE_TARGET);
11796 vty_out(vty, " rt tovpn %s\n", b);
11797 XFREE(MTYPE_ECOMMUNITY_STR, b);
11798 }
11799 }
11800 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
11801 vty_out(vty, " route-map fromvpn %s\n",
11802 bgp->vpn_policy[afi]
11803 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
11804 }
11805 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN]) {
11806 vty_out(vty, " route-map tovpn %s\n",
11807 bgp->vpn_policy[afi]
11808 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
11809 }
11810
11811 vty_endframe(vty, " exit\n");
11812}
11813
11814void bgp_vpn_policy_config_write(struct vty *vty, struct bgp *bgp)
11815{
11816 bgp_vpn_policy_config_write_afi(vty, bgp, AFI_IP);
11817 bgp_vpn_policy_config_write_afi(vty, bgp, AFI_IP6);
11818}
11819
11820
718e3744 11821/* BGP node structure. */
d62a17ae 11822static struct cmd_node bgp_node = {
9d303b37 11823 BGP_NODE, "%s(config-router)# ", 1,
718e3744 11824};
11825
d62a17ae 11826static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 11827 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 11828};
11829
d62a17ae 11830static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 11831 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 11832};
11833
d62a17ae 11834static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 11835 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11836};
11837
d62a17ae 11838static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 11839 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 11840};
11841
d62a17ae 11842static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 11843 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 11844};
11845
d62a17ae 11846static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 11847 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11848};
11849
d62a17ae 11850static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11851 "%s(config-router-af)# ", 1};
6b0655a2 11852
d62a17ae 11853static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11854 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 11855
d62a17ae 11856static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11857 "%s(config-router-evpn)# ", 1};
4e0b7b6d 11858
d62a17ae 11859static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11860 "%s(config-router-af-vni)# ", 1};
90e60aa7 11861
ddb5b488
PZ
11862static struct cmd_node bgp_vpn_policy_ipv4_node = {
11863 BGP_VPNPOLICY_IPV4_NODE, "%s(config-router-vpn-policy-ipv4)# ", 1};
11864
11865static struct cmd_node bgp_vpn_policy_ipv6_node = {
11866 BGP_VPNPOLICY_IPV6_NODE, "%s(config-router-vpn-policy-ipv6)# ", 1};
11867
d62a17ae 11868static void community_list_vty(void);
1f8ae70b 11869
d62a17ae 11870static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 11871{
d62a17ae 11872 struct bgp *bgp;
11873 struct peer *peer;
11874 struct peer_group *group;
11875 struct listnode *lnbgp, *lnpeer;
b8a815e5 11876
d62a17ae 11877 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11878 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11879 /* only provide suggestions on the appropriate input
11880 * token type,
11881 * they'll otherwise show up multiple times */
11882 enum cmd_token_type match_type;
11883 char *name = peer->host;
d48ed3e0 11884
d62a17ae 11885 if (peer->conf_if) {
11886 match_type = VARIABLE_TKN;
11887 name = peer->conf_if;
11888 } else if (strchr(peer->host, ':'))
11889 match_type = IPV6_TKN;
11890 else
11891 match_type = IPV4_TKN;
d48ed3e0 11892
d62a17ae 11893 if (token->type != match_type)
11894 continue;
d48ed3e0 11895
d62a17ae 11896 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11897 }
d48ed3e0 11898
d62a17ae 11899 if (token->type == VARIABLE_TKN)
11900 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11901 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11902 group->name));
11903 }
b8a815e5
DL
11904}
11905
11906static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 11907 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11908 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 11909 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 11910 {.completions = NULL}};
11911
11912void bgp_vty_init(void)
11913{
11914 cmd_variable_handler_register(bgp_var_neighbor);
11915
11916 /* Install bgp top node. */
11917 install_node(&bgp_node, bgp_config_write);
11918 install_node(&bgp_ipv4_unicast_node, NULL);
11919 install_node(&bgp_ipv4_multicast_node, NULL);
11920 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11921 install_node(&bgp_ipv6_unicast_node, NULL);
11922 install_node(&bgp_ipv6_multicast_node, NULL);
11923 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11924 install_node(&bgp_vpnv4_node, NULL);
11925 install_node(&bgp_vpnv6_node, NULL);
11926 install_node(&bgp_evpn_node, NULL);
11927 install_node(&bgp_evpn_vni_node, NULL);
ddb5b488
PZ
11928 install_node(&bgp_vpn_policy_ipv4_node, NULL);
11929 install_node(&bgp_vpn_policy_ipv6_node, NULL);
d62a17ae 11930
11931 /* Install default VTY commands to new nodes. */
11932 install_default(BGP_NODE);
11933 install_default(BGP_IPV4_NODE);
11934 install_default(BGP_IPV4M_NODE);
11935 install_default(BGP_IPV4L_NODE);
11936 install_default(BGP_IPV6_NODE);
11937 install_default(BGP_IPV6M_NODE);
11938 install_default(BGP_IPV6L_NODE);
11939 install_default(BGP_VPNV4_NODE);
11940 install_default(BGP_VPNV6_NODE);
11941 install_default(BGP_EVPN_NODE);
11942 install_default(BGP_EVPN_VNI_NODE);
ddb5b488
PZ
11943 install_default(BGP_VPNPOLICY_IPV4_NODE);
11944 install_default(BGP_VPNPOLICY_IPV6_NODE);
d62a17ae 11945
11946 /* "bgp multiple-instance" commands. */
11947 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11948 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11949
11950 /* "bgp config-type" commands. */
11951 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11952 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11953
11954 /* bgp route-map delay-timer commands. */
11955 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11956 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11957
11958 /* Dummy commands (Currently not supported) */
11959 install_element(BGP_NODE, &no_synchronization_cmd);
11960 install_element(BGP_NODE, &no_auto_summary_cmd);
11961
11962 /* "router bgp" commands. */
11963 install_element(CONFIG_NODE, &router_bgp_cmd);
11964
11965 /* "no router bgp" commands. */
11966 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11967
11968 /* "bgp router-id" commands. */
11969 install_element(BGP_NODE, &bgp_router_id_cmd);
11970 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11971
11972 /* "bgp cluster-id" commands. */
11973 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11974 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11975
11976 /* "bgp confederation" commands. */
11977 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11978 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11979
11980 /* "bgp confederation peers" commands. */
11981 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11982 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11983
11984 /* bgp max-med command */
11985 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11986 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11987 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11988 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11989 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11990
11991 /* bgp disable-ebgp-connected-nh-check */
11992 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11993 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11994
11995 /* bgp update-delay command */
11996 install_element(BGP_NODE, &bgp_update_delay_cmd);
11997 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11998 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11999
12000 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
12001 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
12002 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
12003 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 12004
12005 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
12006 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
12007
12008 /* "maximum-paths" commands. */
12009 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
12010 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
12011 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
12012 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
12013 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
12014 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
12015 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
12016 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
12017 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
12018 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
12019 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12020 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
12021 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
12022 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12023 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
12024
12025 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
12026 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
12027 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
12028 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
12029 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
12030
12031 /* "timers bgp" commands. */
12032 install_element(BGP_NODE, &bgp_timers_cmd);
12033 install_element(BGP_NODE, &no_bgp_timers_cmd);
12034
12035 /* route-map delay-timer commands - per instance for backwards compat.
12036 */
12037 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
12038 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
12039
12040 /* "bgp client-to-client reflection" commands */
12041 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
12042 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
12043
12044 /* "bgp always-compare-med" commands */
12045 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
12046 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
12047
12048 /* "bgp deterministic-med" commands */
12049 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
12050 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
12051
12052 /* "bgp graceful-restart" commands */
12053 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
12054 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
12055 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
12056 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
12057 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
12058 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
12059
12060 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
12061 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
12062
7f323236
DW
12063 /* "bgp graceful-shutdown" commands */
12064 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
12065 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
12066
d62a17ae 12067 /* "bgp fast-external-failover" commands */
12068 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
12069 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
12070
12071 /* "bgp enforce-first-as" commands */
12072 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
12073 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
12074
12075 /* "bgp bestpath compare-routerid" commands */
12076 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
12077 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
12078
12079 /* "bgp bestpath as-path ignore" commands */
12080 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
12081 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
12082
12083 /* "bgp bestpath as-path confed" commands */
12084 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
12085 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
12086
12087 /* "bgp bestpath as-path multipath-relax" commands */
12088 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
12089 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
12090
12091 /* "bgp log-neighbor-changes" commands */
12092 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
12093 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
12094
12095 /* "bgp bestpath med" commands */
12096 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
12097 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
12098
12099 /* "no bgp default ipv4-unicast" commands. */
12100 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
12101 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
12102
12103 /* "bgp network import-check" commands. */
12104 install_element(BGP_NODE, &bgp_network_import_check_cmd);
12105 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
12106 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
12107
12108 /* "bgp default local-preference" commands. */
12109 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
12110 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
12111
12112 /* bgp default show-hostname */
12113 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
12114 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
12115
12116 /* "bgp default subgroup-pkt-queue-max" commands. */
12117 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
12118 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
12119
12120 /* bgp ibgp-allow-policy-mods command */
12121 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
12122 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
12123
12124 /* "bgp listen limit" commands. */
12125 install_element(BGP_NODE, &bgp_listen_limit_cmd);
12126 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
12127
12128 /* "bgp listen range" commands. */
12129 install_element(BGP_NODE, &bgp_listen_range_cmd);
12130 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
12131
8175f54a 12132 /* "bgp default shutdown" command */
f26845f9
QY
12133 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
12134
d62a17ae 12135 /* "neighbor remote-as" commands. */
12136 install_element(BGP_NODE, &neighbor_remote_as_cmd);
12137 install_element(BGP_NODE, &neighbor_interface_config_cmd);
12138 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
12139 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
12140 install_element(BGP_NODE,
12141 &neighbor_interface_v6only_config_remote_as_cmd);
12142 install_element(BGP_NODE, &no_neighbor_cmd);
12143 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12144
12145 /* "neighbor peer-group" commands. */
12146 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12147 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12148 install_element(BGP_NODE,
12149 &no_neighbor_interface_peer_group_remote_as_cmd);
12150
12151 /* "neighbor local-as" commands. */
12152 install_element(BGP_NODE, &neighbor_local_as_cmd);
12153 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12154 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12155 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12156
12157 /* "neighbor solo" commands. */
12158 install_element(BGP_NODE, &neighbor_solo_cmd);
12159 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12160
12161 /* "neighbor password" commands. */
12162 install_element(BGP_NODE, &neighbor_password_cmd);
12163 install_element(BGP_NODE, &no_neighbor_password_cmd);
12164
12165 /* "neighbor activate" commands. */
12166 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12167 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12168 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12169 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12170 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12171 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12172 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12173 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12174 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12175 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12176
12177 /* "no neighbor activate" commands. */
12178 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12179 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12180 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12181 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12182 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12183 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12184 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12185 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12186 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12187 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12188
12189 /* "neighbor peer-group" set commands. */
12190 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12191 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12192 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12193 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12194 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12195 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12196 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12197 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12198
12199 /* "no neighbor peer-group unset" commands. */
12200 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12201 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12202 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12203 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12204 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12205 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12206 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12207 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12208
12209 /* "neighbor softreconfiguration inbound" commands.*/
12210 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12211 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12212 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12213 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12214 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12215 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12216 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12217 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12218 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12219 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12220 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12221 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12222 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12223 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12224 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12225 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12226 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12227 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12228
12229 /* "neighbor attribute-unchanged" commands. */
12230 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12231 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12232 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12233 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12234 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12235 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12236 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12237 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12238 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12239 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12240 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12241 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12242 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12243 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12244 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12245 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12246 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12247 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12248
12249 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12250 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12251
12252 /* "nexthop-local unchanged" commands */
12253 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12254 install_element(BGP_IPV6_NODE,
12255 &no_neighbor_nexthop_local_unchanged_cmd);
12256
12257 /* "neighbor next-hop-self" commands. */
12258 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12259 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12260 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12261 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12262 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12263 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12264 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12265 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12266 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12267 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12268 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12269 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12270 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12271 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12272 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12273 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12274 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12275 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12276
12277 /* "neighbor next-hop-self force" commands. */
12278 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12279 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12280 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12281 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12282 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12283 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12284 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12285 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12286 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12287 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12288 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12289 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12290 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12291 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12292 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12293 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12294 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12295 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12296
12297 /* "neighbor as-override" commands. */
12298 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12299 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12300 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12301 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12302 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12303 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12304 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12305 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12306 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12307 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12308 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12309 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12310 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12311 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12312 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12313 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12314 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12315 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12316
12317 /* "neighbor remove-private-AS" commands. */
12318 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12319 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12320 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12321 install_element(BGP_NODE,
12322 &no_neighbor_remove_private_as_all_hidden_cmd);
12323 install_element(BGP_NODE,
12324 &neighbor_remove_private_as_replace_as_hidden_cmd);
12325 install_element(BGP_NODE,
12326 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12327 install_element(BGP_NODE,
12328 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12329 install_element(
12330 BGP_NODE,
12331 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12332 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12333 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12334 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12335 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12336 install_element(BGP_IPV4_NODE,
12337 &neighbor_remove_private_as_replace_as_cmd);
12338 install_element(BGP_IPV4_NODE,
12339 &no_neighbor_remove_private_as_replace_as_cmd);
12340 install_element(BGP_IPV4_NODE,
12341 &neighbor_remove_private_as_all_replace_as_cmd);
12342 install_element(BGP_IPV4_NODE,
12343 &no_neighbor_remove_private_as_all_replace_as_cmd);
12344 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12345 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12346 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12347 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12348 install_element(BGP_IPV4M_NODE,
12349 &neighbor_remove_private_as_replace_as_cmd);
12350 install_element(BGP_IPV4M_NODE,
12351 &no_neighbor_remove_private_as_replace_as_cmd);
12352 install_element(BGP_IPV4M_NODE,
12353 &neighbor_remove_private_as_all_replace_as_cmd);
12354 install_element(BGP_IPV4M_NODE,
12355 &no_neighbor_remove_private_as_all_replace_as_cmd);
12356 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12357 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12358 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12359 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12360 install_element(BGP_IPV4L_NODE,
12361 &neighbor_remove_private_as_replace_as_cmd);
12362 install_element(BGP_IPV4L_NODE,
12363 &no_neighbor_remove_private_as_replace_as_cmd);
12364 install_element(BGP_IPV4L_NODE,
12365 &neighbor_remove_private_as_all_replace_as_cmd);
12366 install_element(BGP_IPV4L_NODE,
12367 &no_neighbor_remove_private_as_all_replace_as_cmd);
12368 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12369 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12370 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12371 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12372 install_element(BGP_IPV6_NODE,
12373 &neighbor_remove_private_as_replace_as_cmd);
12374 install_element(BGP_IPV6_NODE,
12375 &no_neighbor_remove_private_as_replace_as_cmd);
12376 install_element(BGP_IPV6_NODE,
12377 &neighbor_remove_private_as_all_replace_as_cmd);
12378 install_element(BGP_IPV6_NODE,
12379 &no_neighbor_remove_private_as_all_replace_as_cmd);
12380 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12381 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12382 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12383 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12384 install_element(BGP_IPV6M_NODE,
12385 &neighbor_remove_private_as_replace_as_cmd);
12386 install_element(BGP_IPV6M_NODE,
12387 &no_neighbor_remove_private_as_replace_as_cmd);
12388 install_element(BGP_IPV6M_NODE,
12389 &neighbor_remove_private_as_all_replace_as_cmd);
12390 install_element(BGP_IPV6M_NODE,
12391 &no_neighbor_remove_private_as_all_replace_as_cmd);
12392 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12393 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12394 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12395 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12396 install_element(BGP_IPV6L_NODE,
12397 &neighbor_remove_private_as_replace_as_cmd);
12398 install_element(BGP_IPV6L_NODE,
12399 &no_neighbor_remove_private_as_replace_as_cmd);
12400 install_element(BGP_IPV6L_NODE,
12401 &neighbor_remove_private_as_all_replace_as_cmd);
12402 install_element(BGP_IPV6L_NODE,
12403 &no_neighbor_remove_private_as_all_replace_as_cmd);
12404 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12405 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12406 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12407 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12408 install_element(BGP_VPNV4_NODE,
12409 &neighbor_remove_private_as_replace_as_cmd);
12410 install_element(BGP_VPNV4_NODE,
12411 &no_neighbor_remove_private_as_replace_as_cmd);
12412 install_element(BGP_VPNV4_NODE,
12413 &neighbor_remove_private_as_all_replace_as_cmd);
12414 install_element(BGP_VPNV4_NODE,
12415 &no_neighbor_remove_private_as_all_replace_as_cmd);
12416 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12417 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12418 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12419 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12420 install_element(BGP_VPNV6_NODE,
12421 &neighbor_remove_private_as_replace_as_cmd);
12422 install_element(BGP_VPNV6_NODE,
12423 &no_neighbor_remove_private_as_replace_as_cmd);
12424 install_element(BGP_VPNV6_NODE,
12425 &neighbor_remove_private_as_all_replace_as_cmd);
12426 install_element(BGP_VPNV6_NODE,
12427 &no_neighbor_remove_private_as_all_replace_as_cmd);
12428
12429 /* "neighbor send-community" commands.*/
12430 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12431 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12432 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12433 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12434 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12435 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12436 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12437 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12438 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12439 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12440 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12441 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12442 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12443 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12444 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12445 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12446 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12447 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12448 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12449 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12450 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12451 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12452 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12453 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12454 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12455 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12456 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12457 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12458 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12459 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12460 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12461 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12462 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12463 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12464 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12465 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12466
12467 /* "neighbor route-reflector" commands.*/
12468 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12469 install_element(BGP_NODE,
12470 &no_neighbor_route_reflector_client_hidden_cmd);
12471 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12472 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12473 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12474 install_element(BGP_IPV4M_NODE,
12475 &no_neighbor_route_reflector_client_cmd);
12476 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12477 install_element(BGP_IPV4L_NODE,
12478 &no_neighbor_route_reflector_client_cmd);
12479 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12480 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12481 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12482 install_element(BGP_IPV6M_NODE,
12483 &no_neighbor_route_reflector_client_cmd);
12484 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12485 install_element(BGP_IPV6L_NODE,
12486 &no_neighbor_route_reflector_client_cmd);
12487 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12488 install_element(BGP_VPNV4_NODE,
12489 &no_neighbor_route_reflector_client_cmd);
12490 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12491 install_element(BGP_VPNV6_NODE,
12492 &no_neighbor_route_reflector_client_cmd);
12493 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12494 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12495
12496 /* "neighbor route-server" commands.*/
12497 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12498 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12499 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12500 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12501 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12502 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12503 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12504 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12505 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12506 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12507 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12508 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12509 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12510 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12511 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12512 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12513 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12514 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12515
12516 /* "neighbor addpath-tx-all-paths" commands.*/
12517 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12518 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12519 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12520 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12521 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12522 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12523 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12524 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12525 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12526 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12527 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12528 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12529 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12530 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12531 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12532 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12533 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12534 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12535
12536 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12537 install_element(BGP_NODE,
12538 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12539 install_element(BGP_NODE,
12540 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12541 install_element(BGP_IPV4_NODE,
12542 &neighbor_addpath_tx_bestpath_per_as_cmd);
12543 install_element(BGP_IPV4_NODE,
12544 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12545 install_element(BGP_IPV4M_NODE,
12546 &neighbor_addpath_tx_bestpath_per_as_cmd);
12547 install_element(BGP_IPV4M_NODE,
12548 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12549 install_element(BGP_IPV4L_NODE,
12550 &neighbor_addpath_tx_bestpath_per_as_cmd);
12551 install_element(BGP_IPV4L_NODE,
12552 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12553 install_element(BGP_IPV6_NODE,
12554 &neighbor_addpath_tx_bestpath_per_as_cmd);
12555 install_element(BGP_IPV6_NODE,
12556 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12557 install_element(BGP_IPV6M_NODE,
12558 &neighbor_addpath_tx_bestpath_per_as_cmd);
12559 install_element(BGP_IPV6M_NODE,
12560 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12561 install_element(BGP_IPV6L_NODE,
12562 &neighbor_addpath_tx_bestpath_per_as_cmd);
12563 install_element(BGP_IPV6L_NODE,
12564 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12565 install_element(BGP_VPNV4_NODE,
12566 &neighbor_addpath_tx_bestpath_per_as_cmd);
12567 install_element(BGP_VPNV4_NODE,
12568 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12569 install_element(BGP_VPNV6_NODE,
12570 &neighbor_addpath_tx_bestpath_per_as_cmd);
12571 install_element(BGP_VPNV6_NODE,
12572 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12573
12574 /* "neighbor passive" commands. */
12575 install_element(BGP_NODE, &neighbor_passive_cmd);
12576 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12577
12578
12579 /* "neighbor shutdown" commands. */
12580 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12581 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12582 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12583 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12584
12585 /* "neighbor capability extended-nexthop" commands.*/
12586 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12587 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12588
12589 /* "neighbor capability orf prefix-list" commands.*/
12590 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12591 install_element(BGP_NODE,
12592 &no_neighbor_capability_orf_prefix_hidden_cmd);
12593 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12594 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12595 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12596 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12597 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12598 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12599 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12600 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12601 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12602 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12603 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12604 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12605
12606 /* "neighbor capability dynamic" commands.*/
12607 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12608 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12609
12610 /* "neighbor dont-capability-negotiate" commands. */
12611 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12612 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12613
12614 /* "neighbor ebgp-multihop" commands. */
12615 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12616 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12617 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12618
12619 /* "neighbor disable-connected-check" commands. */
12620 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12621 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12622
12623 /* "neighbor description" commands. */
12624 install_element(BGP_NODE, &neighbor_description_cmd);
12625 install_element(BGP_NODE, &no_neighbor_description_cmd);
12626
12627 /* "neighbor update-source" commands. "*/
12628 install_element(BGP_NODE, &neighbor_update_source_cmd);
12629 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12630
12631 /* "neighbor default-originate" commands. */
12632 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12633 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12634 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12635 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12636 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12637 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12638 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12639 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12640 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12641 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12642 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12643 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12644 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12645 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12646 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12647 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12648 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12649 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12650 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12651 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12652 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12653
12654 /* "neighbor port" commands. */
12655 install_element(BGP_NODE, &neighbor_port_cmd);
12656 install_element(BGP_NODE, &no_neighbor_port_cmd);
12657
12658 /* "neighbor weight" commands. */
12659 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12660 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12661
12662 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12663 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12664 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12665 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12666 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12667 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12668 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12669 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12670 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12671 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12672 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12673 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12674 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12675 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12676 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12677 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12678
12679 /* "neighbor override-capability" commands. */
12680 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12681 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12682
12683 /* "neighbor strict-capability-match" commands. */
12684 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12685 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12686
12687 /* "neighbor timers" commands. */
12688 install_element(BGP_NODE, &neighbor_timers_cmd);
12689 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12690
12691 /* "neighbor timers connect" commands. */
12692 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12693 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12694
12695 /* "neighbor advertisement-interval" commands. */
12696 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12697 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12698
12699 /* "neighbor interface" commands. */
12700 install_element(BGP_NODE, &neighbor_interface_cmd);
12701 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12702
12703 /* "neighbor distribute" commands. */
12704 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12705 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12706 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12707 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12708 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12709 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12710 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12711 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12712 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12713 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12714 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12715 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12716 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12717 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12718 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12719 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12720 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12721 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12722
12723 /* "neighbor prefix-list" commands. */
12724 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12725 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12726 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12727 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12728 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12729 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12730 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12731 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12732 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12733 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12734 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12735 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12736 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12737 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12738 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12739 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12740 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12741 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12742
12743 /* "neighbor filter-list" commands. */
12744 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12745 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12746 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12747 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12748 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12749 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12750 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12751 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12752 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12753 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12754 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12755 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12756 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12757 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12758 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12759 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12760 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12761 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12762
12763 /* "neighbor route-map" commands. */
12764 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12765 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12766 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12767 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12768 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12769 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12770 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12771 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12772 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12773 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12774 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12775 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12776 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12777 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12778 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12779 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12780 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12781 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
12782 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12783 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 12784
12785 /* "neighbor unsuppress-map" commands. */
12786 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12787 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12788 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12789 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12790 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12791 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12792 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12793 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12794 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12795 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12796 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12797 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12798 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12799 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12800 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12801 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12802 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12803 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12804
12805 /* "neighbor maximum-prefix" commands. */
12806 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12807 install_element(BGP_NODE,
12808 &neighbor_maximum_prefix_threshold_hidden_cmd);
12809 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12810 install_element(BGP_NODE,
12811 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12812 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12813 install_element(BGP_NODE,
12814 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12815 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12816 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12817 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12818 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12819 install_element(BGP_IPV4_NODE,
12820 &neighbor_maximum_prefix_threshold_warning_cmd);
12821 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12822 install_element(BGP_IPV4_NODE,
12823 &neighbor_maximum_prefix_threshold_restart_cmd);
12824 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12825 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12826 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12827 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12828 install_element(BGP_IPV4M_NODE,
12829 &neighbor_maximum_prefix_threshold_warning_cmd);
12830 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12831 install_element(BGP_IPV4M_NODE,
12832 &neighbor_maximum_prefix_threshold_restart_cmd);
12833 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12834 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12835 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12836 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12837 install_element(BGP_IPV4L_NODE,
12838 &neighbor_maximum_prefix_threshold_warning_cmd);
12839 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12840 install_element(BGP_IPV4L_NODE,
12841 &neighbor_maximum_prefix_threshold_restart_cmd);
12842 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12843 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12844 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12845 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12846 install_element(BGP_IPV6_NODE,
12847 &neighbor_maximum_prefix_threshold_warning_cmd);
12848 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12849 install_element(BGP_IPV6_NODE,
12850 &neighbor_maximum_prefix_threshold_restart_cmd);
12851 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12852 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12853 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12854 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12855 install_element(BGP_IPV6M_NODE,
12856 &neighbor_maximum_prefix_threshold_warning_cmd);
12857 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12858 install_element(BGP_IPV6M_NODE,
12859 &neighbor_maximum_prefix_threshold_restart_cmd);
12860 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12861 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12862 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12863 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12864 install_element(BGP_IPV6L_NODE,
12865 &neighbor_maximum_prefix_threshold_warning_cmd);
12866 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12867 install_element(BGP_IPV6L_NODE,
12868 &neighbor_maximum_prefix_threshold_restart_cmd);
12869 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12870 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12871 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12872 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12873 install_element(BGP_VPNV4_NODE,
12874 &neighbor_maximum_prefix_threshold_warning_cmd);
12875 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12876 install_element(BGP_VPNV4_NODE,
12877 &neighbor_maximum_prefix_threshold_restart_cmd);
12878 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12879 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12880 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12881 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12882 install_element(BGP_VPNV6_NODE,
12883 &neighbor_maximum_prefix_threshold_warning_cmd);
12884 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12885 install_element(BGP_VPNV6_NODE,
12886 &neighbor_maximum_prefix_threshold_restart_cmd);
12887 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12888
12889 /* "neighbor allowas-in" */
12890 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12891 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12892 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12893 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12894 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12895 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12896 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12897 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12898 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12899 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12900 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12901 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12902 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12903 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12904 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12905 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12906 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12907 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12908 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12909 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12910
12911 /* address-family commands. */
12912 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12913 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 12914#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 12915 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12916 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 12917#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 12918
d62a17ae 12919 install_element(BGP_NODE, &address_family_evpn_cmd);
12920
12921 /* "exit-address-family" command. */
12922 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12923 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12924 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12925 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12926 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12927 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12928 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12929 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12930 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12931
12932 /* "clear ip bgp commands" */
12933 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12934
12935 /* clear ip bgp prefix */
12936 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12937 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12938 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12939
12940 /* "show [ip] bgp summary" commands. */
12941 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 12942 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 12943 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 12944 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12945 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 12946 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12947
12948 /* "show [ip] bgp neighbors" commands. */
12949 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12950
12951 /* "show [ip] bgp peer-group" commands. */
12952 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12953
12954 /* "show [ip] bgp paths" commands. */
12955 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12956
12957 /* "show [ip] bgp community" commands. */
12958 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12959
12960 /* "show ip bgp large-community" commands. */
12961 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12962 /* "show [ip] bgp attribute-info" commands. */
12963 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12964
12965 /* "redistribute" commands. */
12966 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12967 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12968 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12969 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12970 install_element(BGP_NODE,
12971 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12972 install_element(BGP_NODE,
12973 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12974 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12975 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12976 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12977 install_element(BGP_NODE,
12978 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12979 install_element(BGP_NODE,
12980 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12981 install_element(BGP_NODE,
12982 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12983 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12984 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12985 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12986 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12987 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12988 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12989 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12990 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12991 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12992 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12993 install_element(BGP_IPV4_NODE,
12994 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12995 install_element(BGP_IPV4_NODE,
12996 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12997 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12998 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12999 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
13000 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
13001 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
13002 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
13003
ddb5b488
PZ
13004 /* export vpn [route-map WORD] */
13005 install_element(BGP_IPV4_NODE, &bgp_export_vpn_cmd);
13006 install_element(BGP_IPV6_NODE, &bgp_export_vpn_cmd);
13007 install_element(BGP_IPV4_NODE, &bgp_no_export_vpn_cmd);
13008 install_element(BGP_IPV6_NODE, &bgp_no_export_vpn_cmd);
13009
d62a17ae 13010 /* ttl_security commands */
13011 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
13012 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
13013
13014 /* "show [ip] bgp memory" commands. */
13015 install_element(VIEW_NODE, &show_bgp_memory_cmd);
13016
acf71666
MK
13017 /* "show bgp martian next-hop" */
13018 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
13019
d62a17ae 13020 /* "show [ip] bgp views" commands. */
13021 install_element(VIEW_NODE, &show_bgp_views_cmd);
13022
13023 /* "show [ip] bgp vrfs" commands. */
13024 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
13025
13026 /* Community-list. */
13027 community_list_vty();
ddb5b488
PZ
13028
13029 /* vpn-policy commands */
13030 install_element(BGP_NODE, &vpn_policy_afi_cmd);
13031 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_rd_cmd);
13032 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_rd_cmd);
13033 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_label_cmd);
13034 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_label_cmd);
13035 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_nexthop_cmd);
13036 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_nexthop_cmd);
13037 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_rt_cmd);
13038 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_rt_cmd);
13039 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_route_map_cmd);
13040 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_route_map_cmd);
13041
13042 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_no_rd_cmd);
13043 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_no_rd_cmd);
13044 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_no_label_cmd);
13045 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_no_label_cmd);
13046 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_no_nexthop_cmd);
13047 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_no_nexthop_cmd);
13048 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_no_rt_cmd);
13049 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_no_rt_cmd);
13050 install_element(BGP_VPNPOLICY_IPV4_NODE, &vpn_policy_no_route_map_cmd);
13051 install_element(BGP_VPNPOLICY_IPV6_NODE, &vpn_policy_no_route_map_cmd);
718e3744 13052}
6b0655a2 13053
718e3744 13054#include "memory.h"
13055#include "bgp_regex.h"
13056#include "bgp_clist.h"
13057#include "bgp_ecommunity.h"
13058
13059/* VTY functions. */
13060
13061/* Direction value to string conversion. */
d62a17ae 13062static const char *community_direct_str(int direct)
13063{
13064 switch (direct) {
13065 case COMMUNITY_DENY:
13066 return "deny";
13067 case COMMUNITY_PERMIT:
13068 return "permit";
13069 default:
13070 return "unknown";
13071 }
718e3744 13072}
13073
13074/* Display error string. */
d62a17ae 13075static void community_list_perror(struct vty *vty, int ret)
13076{
13077 switch (ret) {
13078 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
13079 vty_out(vty, "%% Can't find community-list\n");
13080 break;
13081 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
13082 vty_out(vty, "%% Malformed community-list value\n");
13083 break;
13084 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
13085 vty_out(vty,
13086 "%% Community name conflict, previously defined as standard community\n");
13087 break;
13088 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
13089 vty_out(vty,
13090 "%% Community name conflict, previously defined as expanded community\n");
13091 break;
13092 }
718e3744 13093}
13094
5bf15956
DW
13095/* "community-list" keyword help string. */
13096#define COMMUNITY_LIST_STR "Add a community list entry\n"
13097
5bf15956 13098/* ip community-list standard */
718e3744 13099DEFUN (ip_community_list_standard,
13100 ip_community_list_standard_cmd,
e961923c 13101 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13102 IP_STR
13103 COMMUNITY_LIST_STR
13104 "Community list number (standard)\n"
5bf15956 13105 "Add an standard community-list entry\n"
718e3744 13106 "Community list name\n"
13107 "Specify community to reject\n"
13108 "Specify community to accept\n"
13109 COMMUNITY_VAL_STR)
13110{
d62a17ae 13111 char *cl_name_or_number = NULL;
13112 int direct = 0;
13113 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13114
d62a17ae 13115 int idx = 0;
13116 argv_find(argv, argc, "(1-99)", &idx);
13117 argv_find(argv, argc, "WORD", &idx);
13118 cl_name_or_number = argv[idx]->arg;
13119 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13120 : COMMUNITY_DENY;
13121 argv_find(argv, argc, "AA:NN", &idx);
13122 char *str = argv_concat(argv, argc, idx);
42f914d4 13123
d62a17ae 13124 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13125 style);
42f914d4 13126
d62a17ae 13127 XFREE(MTYPE_TMP, str);
42f914d4 13128
d62a17ae 13129 if (ret < 0) {
13130 /* Display error string. */
13131 community_list_perror(vty, ret);
13132 return CMD_WARNING_CONFIG_FAILED;
13133 }
42f914d4 13134
d62a17ae 13135 return CMD_SUCCESS;
718e3744 13136}
13137
fee6e4e4 13138DEFUN (no_ip_community_list_standard_all,
13139 no_ip_community_list_standard_all_cmd,
e961923c 13140 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13141 NO_STR
13142 IP_STR
13143 COMMUNITY_LIST_STR
13144 "Community list number (standard)\n"
5bf15956
DW
13145 "Add an standard community-list entry\n"
13146 "Community list name\n"
718e3744 13147 "Specify community to reject\n"
13148 "Specify community to accept\n"
13149 COMMUNITY_VAL_STR)
13150{
d62a17ae 13151 int delete_all = 0;
42f914d4 13152
d62a17ae 13153 char *cl_name_or_number = NULL;
13154 int direct = 0;
13155 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13156
d62a17ae 13157 int idx = 0;
13158 argv_find(argv, argc, "(1-99)", &idx);
13159 argv_find(argv, argc, "WORD", &idx);
13160 cl_name_or_number = argv[idx]->arg;
13161 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13162 : COMMUNITY_DENY;
13163 argv_find(argv, argc, "AA:NN", &idx);
13164 char *str = argv_concat(argv, argc, idx);
42f914d4 13165
d62a17ae 13166 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13167 direct, style, delete_all);
42f914d4 13168
d62a17ae 13169 XFREE(MTYPE_TMP, str);
daf9ddbb 13170
d62a17ae 13171 if (ret < 0) {
13172 community_list_perror(vty, ret);
13173 return CMD_WARNING_CONFIG_FAILED;
13174 }
42f914d4 13175
d62a17ae 13176 return CMD_SUCCESS;
718e3744 13177}
13178
5bf15956
DW
13179/* ip community-list expanded */
13180DEFUN (ip_community_list_expanded_all,
13181 ip_community_list_expanded_all_cmd,
42f914d4 13182 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13183 IP_STR
13184 COMMUNITY_LIST_STR
13185 "Community list number (expanded)\n"
5bf15956 13186 "Add an expanded community-list entry\n"
718e3744 13187 "Community list name\n"
13188 "Specify community to reject\n"
13189 "Specify community to accept\n"
13190 COMMUNITY_VAL_STR)
13191{
d62a17ae 13192 char *cl_name_or_number = NULL;
13193 int direct = 0;
13194 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13195
d62a17ae 13196 int idx = 0;
13197 argv_find(argv, argc, "(100-500)", &idx);
13198 argv_find(argv, argc, "WORD", &idx);
13199 cl_name_or_number = argv[idx]->arg;
13200 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13201 : COMMUNITY_DENY;
13202 argv_find(argv, argc, "AA:NN", &idx);
13203 char *str = argv_concat(argv, argc, idx);
42f914d4 13204
d62a17ae 13205 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13206 style);
42f914d4 13207
d62a17ae 13208 XFREE(MTYPE_TMP, str);
42f914d4 13209
d62a17ae 13210 if (ret < 0) {
13211 /* Display error string. */
13212 community_list_perror(vty, ret);
13213 return CMD_WARNING_CONFIG_FAILED;
13214 }
42f914d4 13215
d62a17ae 13216 return CMD_SUCCESS;
718e3744 13217}
13218
5bf15956
DW
13219DEFUN (no_ip_community_list_expanded_all,
13220 no_ip_community_list_expanded_all_cmd,
42f914d4 13221 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13222 NO_STR
13223 IP_STR
13224 COMMUNITY_LIST_STR
5bf15956
DW
13225 "Community list number (expanded)\n"
13226 "Add an expanded community-list entry\n"
718e3744 13227 "Community list name\n"
13228 "Specify community to reject\n"
13229 "Specify community to accept\n"
5bf15956 13230 COMMUNITY_VAL_STR)
718e3744 13231{
d62a17ae 13232 int delete_all = 0;
42f914d4 13233
d62a17ae 13234 char *cl_name_or_number = NULL;
13235 int direct = 0;
13236 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13237
d62a17ae 13238 int idx = 0;
13239 argv_find(argv, argc, "(100-500)", &idx);
13240 argv_find(argv, argc, "WORD", &idx);
13241 cl_name_or_number = argv[idx]->arg;
13242 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13243 : COMMUNITY_DENY;
13244 argv_find(argv, argc, "AA:NN", &idx);
13245 char *str = argv_concat(argv, argc, idx);
42f914d4 13246
d62a17ae 13247 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13248 direct, style, delete_all);
42f914d4 13249
d62a17ae 13250 XFREE(MTYPE_TMP, str);
daf9ddbb 13251
d62a17ae 13252 if (ret < 0) {
13253 community_list_perror(vty, ret);
13254 return CMD_WARNING_CONFIG_FAILED;
13255 }
42f914d4 13256
d62a17ae 13257 return CMD_SUCCESS;
718e3744 13258}
13259
d62a17ae 13260static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13261{
d62a17ae 13262 struct community_entry *entry;
718e3744 13263
d62a17ae 13264 for (entry = list->head; entry; entry = entry->next) {
13265 if (entry == list->head) {
13266 if (all_digit(list->name))
13267 vty_out(vty, "Community %s list %s\n",
13268 entry->style == COMMUNITY_LIST_STANDARD
13269 ? "standard"
13270 : "(expanded) access",
13271 list->name);
13272 else
13273 vty_out(vty, "Named Community %s list %s\n",
13274 entry->style == COMMUNITY_LIST_STANDARD
13275 ? "standard"
13276 : "expanded",
13277 list->name);
13278 }
13279 if (entry->any)
13280 vty_out(vty, " %s\n",
13281 community_direct_str(entry->direct));
13282 else
13283 vty_out(vty, " %s %s\n",
13284 community_direct_str(entry->direct),
13285 entry->style == COMMUNITY_LIST_STANDARD
a69ea8ae 13286 ? community_str(entry->u.com, false)
d62a17ae 13287 : entry->config);
13288 }
718e3744 13289}
13290
13291DEFUN (show_ip_community_list,
13292 show_ip_community_list_cmd,
13293 "show ip community-list",
13294 SHOW_STR
13295 IP_STR
13296 "List community-list\n")
13297{
d62a17ae 13298 struct community_list *list;
13299 struct community_list_master *cm;
718e3744 13300
d62a17ae 13301 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13302 if (!cm)
13303 return CMD_SUCCESS;
718e3744 13304
d62a17ae 13305 for (list = cm->num.head; list; list = list->next)
13306 community_list_show(vty, list);
718e3744 13307
d62a17ae 13308 for (list = cm->str.head; list; list = list->next)
13309 community_list_show(vty, list);
718e3744 13310
d62a17ae 13311 return CMD_SUCCESS;
718e3744 13312}
13313
13314DEFUN (show_ip_community_list_arg,
13315 show_ip_community_list_arg_cmd,
6147e2c6 13316 "show ip community-list <(1-500)|WORD>",
718e3744 13317 SHOW_STR
13318 IP_STR
13319 "List community-list\n"
13320 "Community-list number\n"
13321 "Community-list name\n")
13322{
d62a17ae 13323 int idx_comm_list = 3;
13324 struct community_list *list;
718e3744 13325
d62a17ae 13326 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13327 COMMUNITY_LIST_MASTER);
13328 if (!list) {
13329 vty_out(vty, "%% Can't find community-list\n");
13330 return CMD_WARNING;
13331 }
718e3744 13332
d62a17ae 13333 community_list_show(vty, list);
718e3744 13334
d62a17ae 13335 return CMD_SUCCESS;
718e3744 13336}
6b0655a2 13337
57d187bc
JS
13338/*
13339 * Large Community code.
13340 */
d62a17ae 13341static int lcommunity_list_set_vty(struct vty *vty, int argc,
13342 struct cmd_token **argv, int style,
13343 int reject_all_digit_name)
13344{
13345 int ret;
13346 int direct;
13347 char *str;
13348 int idx = 0;
13349 char *cl_name;
13350
13351 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13352 : COMMUNITY_DENY;
13353
13354 /* All digit name check. */
13355 idx = 0;
13356 argv_find(argv, argc, "WORD", &idx);
13357 argv_find(argv, argc, "(1-99)", &idx);
13358 argv_find(argv, argc, "(100-500)", &idx);
13359 cl_name = argv[idx]->arg;
13360 if (reject_all_digit_name && all_digit(cl_name)) {
13361 vty_out(vty, "%% Community name cannot have all digits\n");
13362 return CMD_WARNING_CONFIG_FAILED;
13363 }
13364
13365 idx = 0;
13366 argv_find(argv, argc, "AA:BB:CC", &idx);
13367 argv_find(argv, argc, "LINE", &idx);
13368 /* Concat community string argument. */
13369 if (idx)
13370 str = argv_concat(argv, argc, idx);
13371 else
13372 str = NULL;
13373
13374 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13375
13376 /* Free temporary community list string allocated by
13377 argv_concat(). */
13378 if (str)
13379 XFREE(MTYPE_TMP, str);
13380
13381 if (ret < 0) {
13382 community_list_perror(vty, ret);
13383 return CMD_WARNING_CONFIG_FAILED;
13384 }
13385 return CMD_SUCCESS;
13386}
13387
13388static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13389 struct cmd_token **argv, int style)
13390{
13391 int ret;
13392 int direct = 0;
13393 char *str = NULL;
13394 int idx = 0;
13395
13396 argv_find(argv, argc, "permit", &idx);
13397 argv_find(argv, argc, "deny", &idx);
13398
13399 if (idx) {
13400 /* Check the list direct. */
13401 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13402 direct = COMMUNITY_PERMIT;
13403 else
13404 direct = COMMUNITY_DENY;
13405
13406 idx = 0;
13407 argv_find(argv, argc, "LINE", &idx);
13408 argv_find(argv, argc, "AA:AA:NN", &idx);
13409 /* Concat community string argument. */
13410 str = argv_concat(argv, argc, idx);
13411 }
13412
13413 idx = 0;
13414 argv_find(argv, argc, "(1-99)", &idx);
13415 argv_find(argv, argc, "(100-500)", &idx);
13416 argv_find(argv, argc, "WORD", &idx);
13417
13418 /* Unset community list. */
13419 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13420 style);
13421
13422 /* Free temporary community list string allocated by
13423 argv_concat(). */
13424 if (str)
13425 XFREE(MTYPE_TMP, str);
13426
13427 if (ret < 0) {
13428 community_list_perror(vty, ret);
13429 return CMD_WARNING_CONFIG_FAILED;
13430 }
13431
13432 return CMD_SUCCESS;
57d187bc
JS
13433}
13434
13435/* "large-community-list" keyword help string. */
13436#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13437#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13438
13439DEFUN (ip_lcommunity_list_standard,
13440 ip_lcommunity_list_standard_cmd,
52951b63
DS
13441 "ip large-community-list (1-99) <deny|permit>",
13442 IP_STR
13443 LCOMMUNITY_LIST_STR
13444 "Large Community list number (standard)\n"
13445 "Specify large community to reject\n"
7111c1a0 13446 "Specify large community to accept\n")
52951b63 13447{
d62a17ae 13448 return lcommunity_list_set_vty(vty, argc, argv,
13449 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
13450}
13451
13452DEFUN (ip_lcommunity_list_standard1,
13453 ip_lcommunity_list_standard1_cmd,
13454 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
13455 IP_STR
13456 LCOMMUNITY_LIST_STR
13457 "Large Community list number (standard)\n"
13458 "Specify large community to reject\n"
13459 "Specify large community to accept\n"
13460 LCOMMUNITY_VAL_STR)
13461{
d62a17ae 13462 return lcommunity_list_set_vty(vty, argc, argv,
13463 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
13464}
13465
13466DEFUN (ip_lcommunity_list_expanded,
13467 ip_lcommunity_list_expanded_cmd,
13468 "ip large-community-list (100-500) <deny|permit> LINE...",
13469 IP_STR
13470 LCOMMUNITY_LIST_STR
13471 "Large Community list number (expanded)\n"
13472 "Specify large community to reject\n"
13473 "Specify large community to accept\n"
13474 "An ordered list as a regular-expression\n")
13475{
d62a17ae 13476 return lcommunity_list_set_vty(vty, argc, argv,
13477 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
13478}
13479
13480DEFUN (ip_lcommunity_list_name_standard,
13481 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
13482 "ip large-community-list standard WORD <deny|permit>",
13483 IP_STR
13484 LCOMMUNITY_LIST_STR
13485 "Specify standard large-community-list\n"
13486 "Large Community list name\n"
13487 "Specify large community to reject\n"
13488 "Specify large community to accept\n")
13489{
d62a17ae 13490 return lcommunity_list_set_vty(vty, argc, argv,
13491 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
13492}
13493
13494DEFUN (ip_lcommunity_list_name_standard1,
13495 ip_lcommunity_list_name_standard1_cmd,
13496 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
13497 IP_STR
13498 LCOMMUNITY_LIST_STR
13499 "Specify standard large-community-list\n"
13500 "Large Community list name\n"
13501 "Specify large community to reject\n"
13502 "Specify large community to accept\n"
13503 LCOMMUNITY_VAL_STR)
13504{
d62a17ae 13505 return lcommunity_list_set_vty(vty, argc, argv,
13506 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
13507}
13508
13509DEFUN (ip_lcommunity_list_name_expanded,
13510 ip_lcommunity_list_name_expanded_cmd,
13511 "ip large-community-list expanded WORD <deny|permit> LINE...",
13512 IP_STR
13513 LCOMMUNITY_LIST_STR
13514 "Specify expanded large-community-list\n"
13515 "Large Community list name\n"
13516 "Specify large community to reject\n"
13517 "Specify large community to accept\n"
13518 "An ordered list as a regular-expression\n")
13519{
d62a17ae 13520 return lcommunity_list_set_vty(vty, argc, argv,
13521 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
13522}
13523
13524DEFUN (no_ip_lcommunity_list_standard_all,
13525 no_ip_lcommunity_list_standard_all_cmd,
13526 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13527 NO_STR
13528 IP_STR
13529 LCOMMUNITY_LIST_STR
13530 "Large Community list number (standard)\n"
13531 "Large Community list number (expanded)\n"
13532 "Large Community list name\n")
13533{
d62a17ae 13534 return lcommunity_list_unset_vty(vty, argc, argv,
13535 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13536}
13537
13538DEFUN (no_ip_lcommunity_list_name_expanded_all,
13539 no_ip_lcommunity_list_name_expanded_all_cmd,
13540 "no ip large-community-list expanded WORD",
13541 NO_STR
13542 IP_STR
13543 LCOMMUNITY_LIST_STR
13544 "Specify expanded large-community-list\n"
13545 "Large Community list name\n")
13546{
d62a17ae 13547 return lcommunity_list_unset_vty(vty, argc, argv,
13548 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13549}
13550
13551DEFUN (no_ip_lcommunity_list_standard,
13552 no_ip_lcommunity_list_standard_cmd,
13553 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13554 NO_STR
13555 IP_STR
13556 LCOMMUNITY_LIST_STR
13557 "Large Community list number (standard)\n"
13558 "Specify large community to reject\n"
13559 "Specify large community to accept\n"
13560 LCOMMUNITY_VAL_STR)
13561{
d62a17ae 13562 return lcommunity_list_unset_vty(vty, argc, argv,
13563 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13564}
13565
13566DEFUN (no_ip_lcommunity_list_expanded,
13567 no_ip_lcommunity_list_expanded_cmd,
13568 "no ip large-community-list (100-500) <deny|permit> LINE...",
13569 NO_STR
13570 IP_STR
13571 LCOMMUNITY_LIST_STR
13572 "Large Community list number (expanded)\n"
13573 "Specify large community to reject\n"
13574 "Specify large community to accept\n"
13575 "An ordered list as a regular-expression\n")
13576{
d62a17ae 13577 return lcommunity_list_unset_vty(vty, argc, argv,
13578 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13579}
13580
13581DEFUN (no_ip_lcommunity_list_name_standard,
13582 no_ip_lcommunity_list_name_standard_cmd,
13583 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13584 NO_STR
13585 IP_STR
13586 LCOMMUNITY_LIST_STR
13587 "Specify standard large-community-list\n"
13588 "Large Community list name\n"
13589 "Specify large community to reject\n"
13590 "Specify large community to accept\n"
13591 LCOMMUNITY_VAL_STR)
13592{
d62a17ae 13593 return lcommunity_list_unset_vty(vty, argc, argv,
13594 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13595}
13596
13597DEFUN (no_ip_lcommunity_list_name_expanded,
13598 no_ip_lcommunity_list_name_expanded_cmd,
13599 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13600 NO_STR
13601 IP_STR
13602 LCOMMUNITY_LIST_STR
13603 "Specify expanded large-community-list\n"
13604 "Large community list name\n"
13605 "Specify large community to reject\n"
13606 "Specify large community to accept\n"
13607 "An ordered list as a regular-expression\n")
13608{
d62a17ae 13609 return lcommunity_list_unset_vty(vty, argc, argv,
13610 LARGE_COMMUNITY_LIST_EXPANDED);
13611}
13612
13613static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13614{
13615 struct community_entry *entry;
13616
13617 for (entry = list->head; entry; entry = entry->next) {
13618 if (entry == list->head) {
13619 if (all_digit(list->name))
13620 vty_out(vty, "Large community %s list %s\n",
13621 entry->style == EXTCOMMUNITY_LIST_STANDARD
13622 ? "standard"
13623 : "(expanded) access",
13624 list->name);
13625 else
13626 vty_out(vty,
13627 "Named large community %s list %s\n",
13628 entry->style == EXTCOMMUNITY_LIST_STANDARD
13629 ? "standard"
13630 : "expanded",
13631 list->name);
13632 }
13633 if (entry->any)
13634 vty_out(vty, " %s\n",
13635 community_direct_str(entry->direct));
13636 else
13637 vty_out(vty, " %s %s\n",
13638 community_direct_str(entry->direct),
13639 entry->style == EXTCOMMUNITY_LIST_STANDARD
13640 ? entry->u.ecom->str
13641 : entry->config);
13642 }
57d187bc
JS
13643}
13644
13645DEFUN (show_ip_lcommunity_list,
13646 show_ip_lcommunity_list_cmd,
13647 "show ip large-community-list",
13648 SHOW_STR
13649 IP_STR
13650 "List large-community list\n")
13651{
d62a17ae 13652 struct community_list *list;
13653 struct community_list_master *cm;
57d187bc 13654
d62a17ae 13655 cm = community_list_master_lookup(bgp_clist,
13656 LARGE_COMMUNITY_LIST_MASTER);
13657 if (!cm)
13658 return CMD_SUCCESS;
57d187bc 13659
d62a17ae 13660 for (list = cm->num.head; list; list = list->next)
13661 lcommunity_list_show(vty, list);
57d187bc 13662
d62a17ae 13663 for (list = cm->str.head; list; list = list->next)
13664 lcommunity_list_show(vty, list);
57d187bc 13665
d62a17ae 13666 return CMD_SUCCESS;
57d187bc
JS
13667}
13668
13669DEFUN (show_ip_lcommunity_list_arg,
13670 show_ip_lcommunity_list_arg_cmd,
13671 "show ip large-community-list <(1-500)|WORD>",
13672 SHOW_STR
13673 IP_STR
13674 "List large-community list\n"
13675 "large-community-list number\n"
13676 "large-community-list name\n")
13677{
d62a17ae 13678 struct community_list *list;
57d187bc 13679
d62a17ae 13680 list = community_list_lookup(bgp_clist, argv[3]->arg,
13681 LARGE_COMMUNITY_LIST_MASTER);
13682 if (!list) {
13683 vty_out(vty, "%% Can't find extcommunity-list\n");
13684 return CMD_WARNING;
13685 }
57d187bc 13686
d62a17ae 13687 lcommunity_list_show(vty, list);
57d187bc 13688
d62a17ae 13689 return CMD_SUCCESS;
57d187bc
JS
13690}
13691
718e3744 13692/* "extcommunity-list" keyword help string. */
13693#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13694#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13695
13696DEFUN (ip_extcommunity_list_standard,
13697 ip_extcommunity_list_standard_cmd,
e961923c 13698 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13699 IP_STR
13700 EXTCOMMUNITY_LIST_STR
13701 "Extended Community list number (standard)\n"
718e3744 13702 "Specify standard extcommunity-list\n"
5bf15956 13703 "Community list name\n"
718e3744 13704 "Specify community to reject\n"
13705 "Specify community to accept\n"
13706 EXTCOMMUNITY_VAL_STR)
13707{
d62a17ae 13708 int style = EXTCOMMUNITY_LIST_STANDARD;
13709 int direct = 0;
13710 char *cl_number_or_name = NULL;
42f914d4 13711
d62a17ae 13712 int idx = 0;
13713 argv_find(argv, argc, "(1-99)", &idx);
13714 argv_find(argv, argc, "WORD", &idx);
13715 cl_number_or_name = argv[idx]->arg;
13716 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13717 : COMMUNITY_DENY;
13718 argv_find(argv, argc, "AA:NN", &idx);
13719 char *str = argv_concat(argv, argc, idx);
42f914d4 13720
d62a17ae 13721 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13722 direct, style);
42f914d4 13723
d62a17ae 13724 XFREE(MTYPE_TMP, str);
42f914d4 13725
d62a17ae 13726 if (ret < 0) {
13727 community_list_perror(vty, ret);
13728 return CMD_WARNING_CONFIG_FAILED;
13729 }
42f914d4 13730
d62a17ae 13731 return CMD_SUCCESS;
718e3744 13732}
13733
718e3744 13734DEFUN (ip_extcommunity_list_name_expanded,
13735 ip_extcommunity_list_name_expanded_cmd,
e961923c 13736 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13737 IP_STR
13738 EXTCOMMUNITY_LIST_STR
5bf15956 13739 "Extended Community list number (expanded)\n"
718e3744 13740 "Specify expanded extcommunity-list\n"
13741 "Extended Community list name\n"
13742 "Specify community to reject\n"
13743 "Specify community to accept\n"
13744 "An ordered list as a regular-expression\n")
13745{
d62a17ae 13746 int style = EXTCOMMUNITY_LIST_EXPANDED;
13747 int direct = 0;
13748 char *cl_number_or_name = NULL;
42f914d4 13749
d62a17ae 13750 int idx = 0;
13751 argv_find(argv, argc, "(100-500)", &idx);
13752 argv_find(argv, argc, "WORD", &idx);
13753 cl_number_or_name = argv[idx]->arg;
13754 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13755 : COMMUNITY_DENY;
13756 argv_find(argv, argc, "LINE", &idx);
13757 char *str = argv_concat(argv, argc, idx);
42f914d4 13758
d62a17ae 13759 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13760 direct, style);
42f914d4 13761
d62a17ae 13762 XFREE(MTYPE_TMP, str);
42f914d4 13763
d62a17ae 13764 if (ret < 0) {
13765 community_list_perror(vty, ret);
13766 return CMD_WARNING_CONFIG_FAILED;
13767 }
42f914d4 13768
d62a17ae 13769 return CMD_SUCCESS;
718e3744 13770}
13771
fee6e4e4 13772DEFUN (no_ip_extcommunity_list_standard_all,
13773 no_ip_extcommunity_list_standard_all_cmd,
e961923c 13774 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
13775 NO_STR
13776 IP_STR
13777 EXTCOMMUNITY_LIST_STR
13778 "Extended Community list number (standard)\n"
718e3744 13779 "Specify standard extcommunity-list\n"
5bf15956 13780 "Community list name\n"
718e3744 13781 "Specify community to reject\n"
13782 "Specify community to accept\n"
13783 EXTCOMMUNITY_VAL_STR)
13784{
d62a17ae 13785 int deleteall = 0;
42f914d4 13786
d62a17ae 13787 int style = EXTCOMMUNITY_LIST_STANDARD;
13788 int direct = 0;
13789 char *cl_number_or_name = NULL;
42f914d4 13790
d62a17ae 13791 int idx = 0;
13792 argv_find(argv, argc, "(1-99)", &idx);
13793 argv_find(argv, argc, "WORD", &idx);
13794 cl_number_or_name = argv[idx]->arg;
13795 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13796 : COMMUNITY_DENY;
13797 argv_find(argv, argc, "AA:NN", &idx);
13798 char *str = argv_concat(argv, argc, idx);
42f914d4 13799
d62a17ae 13800 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13801 direct, style, deleteall);
42f914d4 13802
d62a17ae 13803 XFREE(MTYPE_TMP, str);
42f914d4 13804
d62a17ae 13805 if (ret < 0) {
13806 community_list_perror(vty, ret);
13807 return CMD_WARNING_CONFIG_FAILED;
13808 }
42f914d4 13809
d62a17ae 13810 return CMD_SUCCESS;
718e3744 13811}
13812
5bf15956
DW
13813DEFUN (no_ip_extcommunity_list_expanded_all,
13814 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 13815 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13816 NO_STR
13817 IP_STR
13818 EXTCOMMUNITY_LIST_STR
13819 "Extended Community list number (expanded)\n"
718e3744 13820 "Specify expanded extcommunity-list\n"
5bf15956 13821 "Extended Community list name\n"
718e3744 13822 "Specify community to reject\n"
13823 "Specify community to accept\n"
13824 "An ordered list as a regular-expression\n")
13825{
d62a17ae 13826 int deleteall = 0;
42f914d4 13827
d62a17ae 13828 int style = EXTCOMMUNITY_LIST_EXPANDED;
13829 int direct = 0;
13830 char *cl_number_or_name = NULL;
42f914d4 13831
d62a17ae 13832 int idx = 0;
13833 argv_find(argv, argc, "(100-500)", &idx);
13834 argv_find(argv, argc, "WORD", &idx);
13835 cl_number_or_name = argv[idx]->arg;
13836 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13837 : COMMUNITY_DENY;
13838 argv_find(argv, argc, "LINE", &idx);
13839 char *str = argv_concat(argv, argc, idx);
42f914d4 13840
d62a17ae 13841 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13842 direct, style, deleteall);
42f914d4 13843
d62a17ae 13844 XFREE(MTYPE_TMP, str);
42f914d4 13845
d62a17ae 13846 if (ret < 0) {
13847 community_list_perror(vty, ret);
13848 return CMD_WARNING_CONFIG_FAILED;
13849 }
42f914d4 13850
d62a17ae 13851 return CMD_SUCCESS;
718e3744 13852}
13853
d62a17ae 13854static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 13855{
d62a17ae 13856 struct community_entry *entry;
718e3744 13857
d62a17ae 13858 for (entry = list->head; entry; entry = entry->next) {
13859 if (entry == list->head) {
13860 if (all_digit(list->name))
13861 vty_out(vty, "Extended community %s list %s\n",
13862 entry->style == EXTCOMMUNITY_LIST_STANDARD
13863 ? "standard"
13864 : "(expanded) access",
13865 list->name);
13866 else
13867 vty_out(vty,
13868 "Named extended community %s list %s\n",
13869 entry->style == EXTCOMMUNITY_LIST_STANDARD
13870 ? "standard"
13871 : "expanded",
13872 list->name);
13873 }
13874 if (entry->any)
13875 vty_out(vty, " %s\n",
13876 community_direct_str(entry->direct));
13877 else
13878 vty_out(vty, " %s %s\n",
13879 community_direct_str(entry->direct),
13880 entry->style == EXTCOMMUNITY_LIST_STANDARD
13881 ? entry->u.ecom->str
13882 : entry->config);
13883 }
718e3744 13884}
13885
13886DEFUN (show_ip_extcommunity_list,
13887 show_ip_extcommunity_list_cmd,
13888 "show ip extcommunity-list",
13889 SHOW_STR
13890 IP_STR
13891 "List extended-community list\n")
13892{
d62a17ae 13893 struct community_list *list;
13894 struct community_list_master *cm;
718e3744 13895
d62a17ae 13896 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13897 if (!cm)
13898 return CMD_SUCCESS;
718e3744 13899
d62a17ae 13900 for (list = cm->num.head; list; list = list->next)
13901 extcommunity_list_show(vty, list);
718e3744 13902
d62a17ae 13903 for (list = cm->str.head; list; list = list->next)
13904 extcommunity_list_show(vty, list);
718e3744 13905
d62a17ae 13906 return CMD_SUCCESS;
718e3744 13907}
13908
13909DEFUN (show_ip_extcommunity_list_arg,
13910 show_ip_extcommunity_list_arg_cmd,
6147e2c6 13911 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 13912 SHOW_STR
13913 IP_STR
13914 "List extended-community list\n"
13915 "Extcommunity-list number\n"
13916 "Extcommunity-list name\n")
13917{
d62a17ae 13918 int idx_comm_list = 3;
13919 struct community_list *list;
718e3744 13920
d62a17ae 13921 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13922 EXTCOMMUNITY_LIST_MASTER);
13923 if (!list) {
13924 vty_out(vty, "%% Can't find extcommunity-list\n");
13925 return CMD_WARNING;
13926 }
718e3744 13927
d62a17ae 13928 extcommunity_list_show(vty, list);
718e3744 13929
d62a17ae 13930 return CMD_SUCCESS;
718e3744 13931}
6b0655a2 13932
718e3744 13933/* Return configuration string of community-list entry. */
d62a17ae 13934static const char *community_list_config_str(struct community_entry *entry)
718e3744 13935{
d62a17ae 13936 const char *str;
718e3744 13937
d62a17ae 13938 if (entry->any)
13939 str = "";
13940 else {
13941 if (entry->style == COMMUNITY_LIST_STANDARD)
a69ea8ae 13942 str = community_str(entry->u.com, false);
d62a17ae 13943 else
13944 str = entry->config;
13945 }
13946 return str;
718e3744 13947}
13948
13949/* Display community-list and extcommunity-list configuration. */
d62a17ae 13950static int community_list_config_write(struct vty *vty)
13951{
13952 struct community_list *list;
13953 struct community_entry *entry;
13954 struct community_list_master *cm;
13955 int write = 0;
13956
13957 /* Community-list. */
13958 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13959
13960 for (list = cm->num.head; list; list = list->next)
13961 for (entry = list->head; entry; entry = entry->next) {
13962 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13963 community_direct_str(entry->direct),
13964 community_list_config_str(entry));
13965 write++;
13966 }
13967 for (list = cm->str.head; list; list = list->next)
13968 for (entry = list->head; entry; entry = entry->next) {
13969 vty_out(vty, "ip community-list %s %s %s %s\n",
13970 entry->style == COMMUNITY_LIST_STANDARD
13971 ? "standard"
13972 : "expanded",
13973 list->name, community_direct_str(entry->direct),
13974 community_list_config_str(entry));
13975 write++;
13976 }
13977
13978 /* Extcommunity-list. */
13979 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13980
13981 for (list = cm->num.head; list; list = list->next)
13982 for (entry = list->head; entry; entry = entry->next) {
13983 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13984 list->name, community_direct_str(entry->direct),
13985 community_list_config_str(entry));
13986 write++;
13987 }
13988 for (list = cm->str.head; list; list = list->next)
13989 for (entry = list->head; entry; entry = entry->next) {
13990 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13991 entry->style == EXTCOMMUNITY_LIST_STANDARD
13992 ? "standard"
13993 : "expanded",
13994 list->name, community_direct_str(entry->direct),
13995 community_list_config_str(entry));
13996 write++;
13997 }
13998
13999
14000 /* lcommunity-list. */
14001 cm = community_list_master_lookup(bgp_clist,
14002 LARGE_COMMUNITY_LIST_MASTER);
14003
14004 for (list = cm->num.head; list; list = list->next)
14005 for (entry = list->head; entry; entry = entry->next) {
14006 vty_out(vty, "ip large-community-list %s %s %s\n",
14007 list->name, community_direct_str(entry->direct),
14008 community_list_config_str(entry));
14009 write++;
14010 }
14011 for (list = cm->str.head; list; list = list->next)
14012 for (entry = list->head; entry; entry = entry->next) {
14013 vty_out(vty, "ip large-community-list %s %s %s %s\n",
14014 entry->style == LARGE_COMMUNITY_LIST_STANDARD
14015 ? "standard"
14016 : "expanded",
14017 list->name, community_direct_str(entry->direct),
14018 community_list_config_str(entry));
14019 write++;
14020 }
14021
14022 return write;
14023}
14024
14025static struct cmd_node community_list_node = {
14026 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 14027};
14028
d62a17ae 14029static void community_list_vty(void)
14030{
14031 install_node(&community_list_node, community_list_config_write);
14032
14033 /* Community-list. */
14034 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
14035 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
14036 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
14037 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
14038 install_element(VIEW_NODE, &show_ip_community_list_cmd);
14039 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
14040
14041 /* Extcommunity-list. */
14042 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
14043 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
14044 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
14045 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
14046 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
14047 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
14048
14049 /* Large Community List */
14050 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
14051 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
14052 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
14053 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
14054 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
14055 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
14056 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
14057 install_element(CONFIG_NODE,
14058 &no_ip_lcommunity_list_name_expanded_all_cmd);
14059 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
14060 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
14061 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
14062 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
14063 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
14064 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 14065}