]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_vty.c
bgpd: new vpn-policy CLI
[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
b9c7bc5a
PZ
6115static int set_ecom_list(struct vty *vty, int argc, struct cmd_token **argv,
6116 struct ecommunity **list)
ddb5b488 6117{
b9c7bc5a
PZ
6118 struct ecommunity *ecom = NULL;
6119 struct ecommunity *ecomadd;
ddb5b488 6120
b9c7bc5a 6121 for (; argc; --argc, ++argv) {
ddb5b488 6122
b9c7bc5a
PZ
6123 ecomadd = ecommunity_str2com(argv[0]->arg,
6124 ECOMMUNITY_ROUTE_TARGET, 0);
6125 if (!ecomadd) {
6126 vty_out(vty, "Malformed community-list value\n");
6127 if (ecom)
6128 ecommunity_free(&ecom);
6129 return CMD_WARNING_CONFIG_FAILED;
6130 }
ddb5b488 6131
b9c7bc5a
PZ
6132 if (ecom) {
6133 ecommunity_merge(ecom, ecomadd);
6134 ecommunity_free(&ecomadd);
6135 } else {
6136 ecom = ecomadd;
6137 }
6138 }
6139
6140 if (*list) {
6141 ecommunity_free(&*list);
ddb5b488 6142 }
b9c7bc5a
PZ
6143 *list = ecom;
6144
6145 return CMD_SUCCESS;
ddb5b488
PZ
6146}
6147
b9c7bc5a 6148static int vpn_policy_getafi(struct vty *vty, int *doafi)
ddb5b488
PZ
6149{
6150 switch (vty->node) {
b9c7bc5a 6151 case BGP_IPV4_NODE:
ddb5b488
PZ
6152 doafi[AFI_IP] = 1;
6153 break;
b9c7bc5a 6154 case BGP_IPV6_NODE:
ddb5b488
PZ
6155 doafi[AFI_IP6] = 1;
6156 break;
6157 default:
6158 vty_out(vty,
b9c7bc5a 6159 "%% context error: valid only in address-family <ipv4|ipv6> unicast block\n");
ddb5b488
PZ
6160 return CMD_WARNING_CONFIG_FAILED;
6161 }
6162 return CMD_SUCCESS;
6163}
6164
b9c7bc5a
PZ
6165DEFPY (af_rd_vpn_export,
6166 af_rd_vpn_export_cmd,
6167 "[no] rd vpn export ASN:NN_OR_IP-ADDRESS:NN$rd_str",
6168 NO_STR
ddb5b488 6169 "Specify route distinguisher\n"
b9c7bc5a
PZ
6170 "Between current address-family and vpn\n"
6171 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6172 "Route Distinguisher (<as-number>:<number> | <ip-address>:<number>)\n")
6173{
6174 VTY_DECLVAR_CONTEXT(bgp, bgp);
6175 struct prefix_rd prd;
6176 int ret;
6177 int doafi[AFI_MAX] = {0};
6178 afi_t afi;
b9c7bc5a
PZ
6179 int idx = 0;
6180 int yes = 1;
ddb5b488 6181
b9c7bc5a
PZ
6182 if (argv_find(argv, argc, "no", &idx))
6183 yes = 0;
6184
6185 if (yes) {
6186 ret = str2prefix_rd(rd_str, &prd);
6187 if (!ret) {
6188 vty_out(vty, "%% Malformed rd\n");
6189 return CMD_WARNING_CONFIG_FAILED;
6190 }
ddb5b488
PZ
6191 }
6192
b9c7bc5a 6193 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6194 if (ret != CMD_SUCCESS)
6195 return ret;
6196
6197
6198 for (afi = 0; afi < AFI_MAX; ++afi) {
6199 if (!doafi[afi])
6200 continue;
6201
6202 /* pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6203 */
6204 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6205 bgp_get_default(), bgp);
6206
b9c7bc5a
PZ
6207 if (yes) {
6208 bgp->vpn_policy[afi].tovpn_rd = prd;
6209 SET_FLAG(bgp->vpn_policy[afi].flags,
6210 BGP_VPN_POLICY_TOVPN_RD_SET);
6211 } else {
6212 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6213 BGP_VPN_POLICY_TOVPN_RD_SET);
6214 }
ddb5b488
PZ
6215
6216 /* post-change: re-export vpn routes */
6217 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6218 bgp_get_default(), bgp);
6219 }
6220
6221 return CMD_SUCCESS;
6222}
6223
b9c7bc5a
PZ
6224ALIAS (af_rd_vpn_export,
6225 af_no_rd_vpn_export_cmd,
6226 "no rd vpn export",
ddb5b488 6227 NO_STR
b9c7bc5a
PZ
6228 "Specify route distinguisher\n"
6229 "Between current address-family and vpn\n"
6230 "For routes leaked from current address-family to vpn\n")
ddb5b488 6231
b9c7bc5a
PZ
6232DEFPY (af_label_vpn_export,
6233 af_label_vpn_export_cmd,
6234 "[no] label vpn export (0-1048575)$label_val",
6235 NO_STR
ddb5b488 6236 "label value for VRF\n"
b9c7bc5a
PZ
6237 "Between current address-family and vpn\n"
6238 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6239 "Label Value <0-1048575>\n")
6240{
6241 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6242 mpls_label_t label = MPLS_LABEL_NONE;
ddb5b488
PZ
6243 int doafi[AFI_MAX] = {0};
6244 afi_t afi;
6245 int ret;
b9c7bc5a
PZ
6246 int idx = 0;
6247 int yes = 1;
6248
6249 if (argv_find(argv, argc, "no", &idx))
6250 yes = 0;
ddb5b488 6251
b9c7bc5a
PZ
6252 if (yes)
6253 label = label_val; /* rely on parser to force unsigned */
ddb5b488 6254
b9c7bc5a 6255 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6256 if (ret != CMD_SUCCESS)
6257 return ret;
6258
6259 for (afi = 0; afi < AFI_MAX; ++afi) {
6260 if (!doafi[afi])
6261 continue;
6262
b9c7bc5a
PZ
6263 /*
6264 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
ddb5b488
PZ
6265 */
6266 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6267 bgp_get_default(), bgp);
6268
6269 bgp->vpn_policy[afi].tovpn_label = label;
6270
6271 /* post-change: re-export vpn routes */
6272 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6273 bgp_get_default(), bgp);
6274 }
6275
6276 return CMD_SUCCESS;
6277}
6278
b9c7bc5a
PZ
6279ALIAS (af_label_vpn_export,
6280 af_no_label_vpn_export_cmd,
6281 "no label vpn export",
6282 NO_STR
6283 "label value for VRF\n"
6284 "Between current address-family and vpn\n"
6285 "For routes leaked from current address-family to vpn\n")
ddb5b488 6286
b9c7bc5a
PZ
6287DEFPY (af_nexthop_vpn_export,
6288 af_nexthop_vpn_export_cmd,
6289 "[no] nexthop vpn export <A.B.C.D|X:X::X:X>$nexthop_str",
6290 NO_STR
ddb5b488 6291 "Specify next hop to use for VRF advertised prefixes\n"
b9c7bc5a
PZ
6292 "Between current address-family and vpn\n"
6293 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6294 "IPv4 prefix\n"
6295 "IPv6 prefix\n")
6296{
6297 VTY_DECLVAR_CONTEXT(bgp, bgp);
6298 int doafi[AFI_MAX] = {0};
6299 afi_t afi;
6300 int ret;
6301 struct prefix p;
b9c7bc5a
PZ
6302 int idx = 0;
6303 int yes = 1;
ddb5b488 6304
b9c7bc5a
PZ
6305 if (argv_find(argv, argc, "no", &idx))
6306 yes = 0;
6307
6308 if (yes) {
6309 if (!sockunion2hostprefix(nexthop_str, &p))
6310 return CMD_WARNING_CONFIG_FAILED;
6311 }
ddb5b488 6312
b9c7bc5a 6313 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6314 if (ret != CMD_SUCCESS)
6315 return ret;
6316
6317 for (afi = 0; afi < AFI_MAX; ++afi) {
6318 if (!doafi[afi])
6319 continue;
6320
6321 /*
6322 * pre-change: un-export vpn routes (vpn->vrf routes unaffected)
6323 */
6324 vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6325 bgp_get_default(), bgp);
6326
b9c7bc5a
PZ
6327 if (yes) {
6328 bgp->vpn_policy[afi].tovpn_nexthop = p;
6329 SET_FLAG(bgp->vpn_policy[afi].flags,
6330 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6331 } else {
6332 UNSET_FLAG(bgp->vpn_policy[afi].flags,
6333 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET);
6334 }
ddb5b488
PZ
6335
6336 /* post-change: re-export vpn routes */
6337 vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,
6338 bgp_get_default(), bgp);
6339 }
6340
6341 return CMD_SUCCESS;
6342}
6343
b9c7bc5a
PZ
6344ALIAS (af_nexthop_vpn_export,
6345 af_no_nexthop_vpn_export_cmd,
6346 "no nexthop vpn export",
ddb5b488 6347 NO_STR
b9c7bc5a
PZ
6348 "Specify next hop to use for VRF advertised prefixes\n"
6349 "Between current address-family and vpn\n"
6350 "For routes leaked from current address-family to vpn\n")
ddb5b488 6351
b9c7bc5a 6352static int vpn_policy_getdirs(struct vty *vty, const char *dstr, int *dodir)
ddb5b488 6353{
b9c7bc5a
PZ
6354 if (!strcmp(dstr, "import")) {
6355 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6356 } else if (!strcmp(dstr, "export")) {
6357 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6358 } else if (!strcmp(dstr, "both")) {
6359 dodir[BGP_VPN_POLICY_DIR_FROMVPN] = 1;
6360 dodir[BGP_VPN_POLICY_DIR_TOVPN] = 1;
6361 } else {
6362 vty_out(vty, "%% direction parse error\n");
6363 return CMD_WARNING_CONFIG_FAILED;
ddb5b488 6364 }
ddb5b488
PZ
6365 return CMD_SUCCESS;
6366}
6367
b9c7bc5a
PZ
6368DEFPY (af_rt_vpn_imexport,
6369 af_rt_vpn_imexport_cmd,
6370 "[no] <rt|route-target> vpn <import|export|both>$direction_str RTLIST...",
6371 NO_STR
6372 "Specify route target list\n"
ddb5b488 6373 "Specify route target list\n"
b9c7bc5a
PZ
6374 "Between current address-family and vpn\n"
6375 "For routes leaked from vpn to current address-family: match any\n"
6376 "For routes leaked from current address-family to vpn: set\n"
6377 "both import: match any and export: set\n"
ddb5b488
PZ
6378 "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
6379{
6380 VTY_DECLVAR_CONTEXT(bgp, bgp);
6381 int ret;
6382 struct ecommunity *ecom = NULL;
6383 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6384 int doafi[AFI_MAX] = {0};
6385 vpn_policy_direction_t dir;
6386 afi_t afi;
6387 int idx = 0;
b9c7bc5a 6388 int yes = 1;
ddb5b488 6389
b9c7bc5a
PZ
6390 if (argv_find(argv, argc, "no", &idx))
6391 yes = 0;
6392
6393 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6394 if (ret != CMD_SUCCESS)
6395 return ret;
6396
b9c7bc5a 6397 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6398 if (ret != CMD_SUCCESS)
6399 return ret;
6400
b9c7bc5a
PZ
6401 if (yes) {
6402 if (!argv_find(argv, argc, "RTLIST", &idx)) {
6403 vty_out(vty, "%% Missing RTLIST\n");
6404 return CMD_WARNING_CONFIG_FAILED;
6405 }
6406 ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom);
6407 if (ret != CMD_SUCCESS) {
6408 return ret;
6409 }
ddb5b488
PZ
6410 }
6411
6412 for (afi = 0; afi < AFI_MAX; ++afi) {
6413 if (!doafi[afi])
6414 continue;
6415 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6416 if (!dodir[dir])
6417 continue;
6418
6419 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6420
b9c7bc5a
PZ
6421 if (yes) {
6422 if (bgp->vpn_policy[afi].rtlist[dir])
6423 ecommunity_free(
6424 &bgp->vpn_policy[afi].rtlist[dir]);
6425 bgp->vpn_policy[afi].rtlist[dir] =
6426 ecommunity_dup(ecom);
6427 } else {
6428 if (bgp->vpn_policy[afi].rtlist[dir])
6429 ecommunity_free(
6430 &bgp->vpn_policy[afi].rtlist[dir]);
6431 bgp->vpn_policy[afi].rtlist[dir] = NULL;
6432 }
ddb5b488
PZ
6433
6434 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6435 }
6436 }
6437 ecommunity_free(&ecom);
6438
6439 return CMD_SUCCESS;
6440}
6441
b9c7bc5a
PZ
6442ALIAS (af_rt_vpn_imexport,
6443 af_no_rt_vpn_imexport_cmd,
6444 "no <rt|route-target> vpn <import|export|both>$direction_str",
ddb5b488
PZ
6445 NO_STR
6446 "Specify route target list\n"
b9c7bc5a
PZ
6447 "Specify route target list\n"
6448 "Between current address-family and vpn\n"
6449 "For routes leaked from vpn to current address-family\n"
6450 "For routes leaked from current address-family to vpn\n"
6451 "both import and export\n")
6452
6453DEFPY (af_route_map_vpn_imexport,
6454 af_route_map_vpn_imexport_cmd,
6455/* future: "route-map <vpn|evpn|vrf NAME> <import|export> RMAP" */
6456 "[no] route-map vpn <import|export>$direction_str RMAP$rmap_str",
6457 NO_STR
ddb5b488 6458 "Specify route map\n"
b9c7bc5a
PZ
6459 "Between current address-family and vpn\n"
6460 "For routes leaked from vpn to current address-family\n"
6461 "For routes leaked from current address-family to vpn\n"
ddb5b488
PZ
6462 "name of route-map\n")
6463{
6464 VTY_DECLVAR_CONTEXT(bgp, bgp);
6465 int ret;
6466 int dodir[BGP_VPN_POLICY_DIR_MAX] = {0};
6467 int doafi[AFI_MAX] = {0};
6468 vpn_policy_direction_t dir;
6469 afi_t afi;
ddb5b488 6470 int idx = 0;
b9c7bc5a 6471 int yes = 1;
ddb5b488 6472
b9c7bc5a
PZ
6473 if (argv_find(argv, argc, "no", &idx))
6474 yes = 0;
6475
6476 ret = vpn_policy_getafi(vty, doafi);
ddb5b488
PZ
6477 if (ret != CMD_SUCCESS)
6478 return ret;
6479
b9c7bc5a 6480 ret = vpn_policy_getdirs(vty, direction_str, dodir);
ddb5b488
PZ
6481 if (ret != CMD_SUCCESS)
6482 return ret;
6483
6484 for (afi = 0; afi < AFI_MAX; ++afi) {
6485 if (!doafi[afi])
6486 continue;
6487 for (dir = 0; dir < BGP_VPN_POLICY_DIR_MAX; ++dir) {
6488 if (!dodir[dir])
6489 continue;
6490
6491 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6492
b9c7bc5a
PZ
6493 if (yes) {
6494 if (bgp->vpn_policy[afi].rmap_name[dir])
6495 XFREE(MTYPE_ROUTE_MAP_NAME,
6496 bgp->vpn_policy[afi].rmap_name[dir]);
6497 bgp->vpn_policy[afi].rmap_name[dir] = XSTRDUP(
6498 MTYPE_ROUTE_MAP_NAME, rmap_str);
6499 bgp->vpn_policy[afi].rmap[dir] =
6500 route_map_lookup_by_name(rmap_str);
6501 } else {
6502 if (bgp->vpn_policy[afi].rmap_name[dir])
6503 XFREE(MTYPE_ROUTE_MAP_NAME,
6504 bgp->vpn_policy[afi].rmap_name[dir]);
6505 bgp->vpn_policy[afi].rmap_name[dir] = NULL;
6506 bgp->vpn_policy[afi].rmap[dir] = NULL;
6507 }
ddb5b488
PZ
6508
6509 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6510 }
6511 }
6512
6513 return CMD_SUCCESS;
6514}
6515
b9c7bc5a
PZ
6516ALIAS (af_route_map_vpn_imexport,
6517 af_no_route_map_vpn_imexport_cmd,
6518 "no route-map vpn <import|export>$direction_str",
ddb5b488
PZ
6519 NO_STR
6520 "Specify route map\n"
b9c7bc5a
PZ
6521 "Between current address-family and vpn\n"
6522 "For routes leaked from vpn to current address-family\n"
6523 "For routes leaked from current address-family to vpn\n")
6524
6525/* This command is valid only in a bgp vrf instance or the default instance */
6526DEFPY (bgp_imexport_vpn,
6527 bgp_imexport_vpn_cmd,
6528 "[no] <import|export>$direction_str vpn",
6529 "Export routes to another routing protocol\n"
6530 "to VPN RIB per vpn-policy")
ddb5b488
PZ
6531{
6532 VTY_DECLVAR_CONTEXT(bgp, bgp);
b9c7bc5a 6533 int previous_state;
ddb5b488 6534 afi_t afi;
b9c7bc5a 6535 safi_t safi;
ddb5b488 6536 int idx = 0;
b9c7bc5a
PZ
6537 int yes = 1;
6538 int flag;
6539 vpn_policy_direction_t dir;
ddb5b488 6540
b9c7bc5a
PZ
6541 if (argv_find(argv, argc, "no", &idx))
6542 yes = 0;
ddb5b488 6543
b9c7bc5a
PZ
6544 if (BGP_INSTANCE_TYPE_VRF != bgp->inst_type &&
6545 BGP_INSTANCE_TYPE_DEFAULT != bgp->inst_type) {
ddb5b488 6546
b9c7bc5a
PZ
6547 vty_out(vty, "%% import|export vpn valid only for bgp vrf or default instance\n");
6548 return CMD_WARNING_CONFIG_FAILED;
6549 }
ddb5b488 6550
b9c7bc5a
PZ
6551 afi = bgp_node_afi(vty);
6552 safi = bgp_node_safi(vty);
6553 if ((SAFI_UNICAST != safi) || ((AFI_IP != afi) && (AFI_IP6 != afi))) {
6554 vty_out(vty, "%% import|export vpn valid only for unicast ipv4|ipv6\n");
6555 return CMD_WARNING_CONFIG_FAILED;
6556 }
ddb5b488 6557
b9c7bc5a
PZ
6558 if (!strcmp(direction_str, "import")) {
6559 flag = BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT;
6560 dir = BGP_VPN_POLICY_DIR_FROMVPN;
6561 } else if (!strcmp(direction_str, "export")) {
6562 flag = BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT;
6563 dir = BGP_VPN_POLICY_DIR_TOVPN;
6564 } else {
6565 vty_out(vty, "%% unknown direction %s\n", direction_str);
6566 return CMD_WARNING_CONFIG_FAILED;
6567 }
6568
6569 previous_state = CHECK_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488 6570
b9c7bc5a
PZ
6571 if (yes) {
6572 SET_FLAG(bgp->af_flags[afi][safi], flag);
6573 if (!previous_state) {
6574 /* trigger export current vrf */
ddb5b488
PZ
6575 vpn_leak_postchange(dir, afi, bgp_get_default(), bgp);
6576 }
b9c7bc5a
PZ
6577 } else {
6578 if (previous_state) {
6579 /* trigger un-export current vrf */
6580 vpn_leak_prechange(dir, afi, bgp_get_default(), bgp);
6581 }
6582 UNSET_FLAG(bgp->af_flags[afi][safi], flag);
ddb5b488
PZ
6583 }
6584
6585 return CMD_SUCCESS;
6586}
6587
505e5056 6588DEFUN_NOSH (address_family_ipv4_safi,
718e3744 6589 address_family_ipv4_safi_cmd,
5b1f0f29 6590 "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6591 "Enter Address Family command mode\n"
8c3deaae 6592 "Address Family\n"
b6ab5a3a 6593 BGP_SAFI_WITH_LABEL_HELP_STR)
718e3744 6594{
f51bae9c 6595
d62a17ae 6596 if (argc == 3) {
2131d5cf 6597 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6598 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6599 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6600 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6601 && safi != SAFI_EVPN) {
31947174
MK
6602 vty_out(vty,
6603 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6604 return CMD_WARNING_CONFIG_FAILED;
6605 }
d62a17ae 6606 vty->node = bgp_node_type(AFI_IP, safi);
6607 } else
6608 vty->node = BGP_IPV4_NODE;
718e3744 6609
d62a17ae 6610 return CMD_SUCCESS;
718e3744 6611}
6612
505e5056 6613DEFUN_NOSH (address_family_ipv6_safi,
25ffbdc1 6614 address_family_ipv6_safi_cmd,
5b1f0f29 6615 "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]",
718e3744 6616 "Enter Address Family command mode\n"
8c3deaae 6617 "Address Family\n"
b6ab5a3a 6618 BGP_SAFI_WITH_LABEL_HELP_STR)
25ffbdc1 6619{
d62a17ae 6620 if (argc == 3) {
2131d5cf 6621 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6622 safi_t safi = bgp_vty_safi_from_str(argv[2]->text);
a4d82a8a
PZ
6623 if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT
6624 && safi != SAFI_UNICAST && safi != SAFI_MULTICAST
9d00a487 6625 && safi != SAFI_EVPN) {
31947174
MK
6626 vty_out(vty,
6627 "Only Unicast/Multicast/EVPN SAFIs supported in non-core instances.\n");
2131d5cf
LB
6628 return CMD_WARNING_CONFIG_FAILED;
6629 }
d62a17ae 6630 vty->node = bgp_node_type(AFI_IP6, safi);
6631 } else
6632 vty->node = BGP_IPV6_NODE;
25ffbdc1 6633
d62a17ae 6634 return CMD_SUCCESS;
25ffbdc1 6635}
718e3744 6636
d6902373 6637#ifdef KEEP_OLD_VPN_COMMANDS
505e5056 6638DEFUN_NOSH (address_family_vpnv4,
718e3744 6639 address_family_vpnv4_cmd,
8334fd5a 6640 "address-family vpnv4 [unicast]",
718e3744 6641 "Enter Address Family command mode\n"
8c3deaae 6642 "Address Family\n"
3a2d747c 6643 "Address Family modifier\n")
718e3744 6644{
d62a17ae 6645 vty->node = BGP_VPNV4_NODE;
6646 return CMD_SUCCESS;
718e3744 6647}
6648
505e5056 6649DEFUN_NOSH (address_family_vpnv6,
8ecd3266 6650 address_family_vpnv6_cmd,
8334fd5a 6651 "address-family vpnv6 [unicast]",
8ecd3266 6652 "Enter Address Family command mode\n"
8c3deaae 6653 "Address Family\n"
3a2d747c 6654 "Address Family modifier\n")
8ecd3266 6655{
d62a17ae 6656 vty->node = BGP_VPNV6_NODE;
6657 return CMD_SUCCESS;
8ecd3266 6658}
c016b6c7 6659#endif
d6902373 6660
505e5056 6661DEFUN_NOSH (address_family_evpn,
4e0b7b6d 6662 address_family_evpn_cmd,
7111c1a0 6663 "address-family l2vpn evpn",
4e0b7b6d 6664 "Enter Address Family command mode\n"
7111c1a0
QY
6665 "Address Family\n"
6666 "Address Family modifier\n")
4e0b7b6d 6667{
2131d5cf 6668 VTY_DECLVAR_CONTEXT(bgp, bgp);
d62a17ae 6669 vty->node = BGP_EVPN_NODE;
6670 return CMD_SUCCESS;
4e0b7b6d
PG
6671}
6672
505e5056 6673DEFUN_NOSH (exit_address_family,
718e3744 6674 exit_address_family_cmd,
6675 "exit-address-family",
6676 "Exit from Address Family configuration mode\n")
6677{
d62a17ae 6678 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
6679 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
6680 || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE
6681 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE
6682 || vty->node == BGP_EVPN_NODE)
6683 vty->node = BGP_NODE;
6684 return CMD_SUCCESS;
718e3744 6685}
6b0655a2 6686
8ad7271d 6687/* Recalculate bestpath and re-advertise a prefix */
d62a17ae 6688static int bgp_clear_prefix(struct vty *vty, const char *view_name,
6689 const char *ip_str, afi_t afi, safi_t safi,
6690 struct prefix_rd *prd)
6691{
6692 int ret;
6693 struct prefix match;
6694 struct bgp_node *rn;
6695 struct bgp_node *rm;
6696 struct bgp *bgp;
6697 struct bgp_table *table;
6698 struct bgp_table *rib;
6699
6700 /* BGP structure lookup. */
6701 if (view_name) {
6702 bgp = bgp_lookup_by_name(view_name);
6703 if (bgp == NULL) {
6704 vty_out(vty, "%% Can't find BGP instance %s\n",
6705 view_name);
6706 return CMD_WARNING;
6707 }
6708 } else {
6709 bgp = bgp_get_default();
6710 if (bgp == NULL) {
6711 vty_out(vty, "%% No BGP process is configured\n");
6712 return CMD_WARNING;
6713 }
6714 }
6715
6716 /* Check IP address argument. */
6717 ret = str2prefix(ip_str, &match);
6718 if (!ret) {
6719 vty_out(vty, "%% address is malformed\n");
6720 return CMD_WARNING;
6721 }
6722
6723 match.family = afi2family(afi);
6724 rib = bgp->rib[afi][safi];
6725
6726 if (safi == SAFI_MPLS_VPN) {
6727 for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) {
6728 if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0)
6729 continue;
6730
6731 if ((table = rn->info) != NULL) {
6732 if ((rm = bgp_node_match(table, &match))
6733 != NULL) {
6734 if (rm->p.prefixlen
6735 == match.prefixlen) {
6736 SET_FLAG(rn->flags,
6737 BGP_NODE_USER_CLEAR);
6738 bgp_process(bgp, rm, afi, safi);
6739 }
6740 bgp_unlock_node(rm);
6741 }
6742 }
6743 }
6744 } else {
6745 if ((rn = bgp_node_match(rib, &match)) != NULL) {
6746 if (rn->p.prefixlen == match.prefixlen) {
6747 SET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
6748 bgp_process(bgp, rn, afi, safi);
6749 }
6750 bgp_unlock_node(rn);
6751 }
6752 }
6753
6754 return CMD_SUCCESS;
8ad7271d
DS
6755}
6756
b09b5ae0 6757/* one clear bgp command to rule them all */
718e3744 6758DEFUN (clear_ip_bgp_all,
6759 clear_ip_bgp_all_cmd,
c1a44e43 6760 "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 6761 CLEAR_STR
6762 IP_STR
6763 BGP_STR
838758ac 6764 BGP_INSTANCE_HELP_STR
510afcd6
DS
6765 BGP_AFI_HELP_STR
6766 BGP_SAFI_WITH_LABEL_HELP_STR
b09b5ae0
DW
6767 "Clear all peers\n"
6768 "BGP neighbor address to clear\n"
a80beece 6769 "BGP IPv6 neighbor to clear\n"
838758ac 6770 "BGP neighbor on interface to clear\n"
b09b5ae0
DW
6771 "Clear peers with the AS number\n"
6772 "Clear all external peers\n"
718e3744 6773 "Clear all members of peer-group\n"
b09b5ae0 6774 "BGP peer-group name\n"
b09b5ae0
DW
6775 BGP_SOFT_STR
6776 BGP_SOFT_IN_STR
b09b5ae0
DW
6777 BGP_SOFT_OUT_STR
6778 BGP_SOFT_IN_STR
6779 "Push out prefix-list ORF and do inbound soft reconfig\n"
b09b5ae0 6780 BGP_SOFT_OUT_STR)
718e3744 6781{
d62a17ae 6782 char *vrf = NULL;
6783
6784 afi_t afi = AFI_IP6;
6785 safi_t safi = SAFI_UNICAST;
6786 enum clear_sort clr_sort = clear_peer;
6787 enum bgp_clear_type clr_type;
6788 char *clr_arg = NULL;
6789
6790 int idx = 0;
6791
6792 /* clear [ip] bgp */
6793 if (argv_find(argv, argc, "ip", &idx))
6794 afi = AFI_IP;
6795
6796 /* [<view|vrf> VIEWVRFNAME] */
6797 if (argv_find(argv, argc, "view", &idx)
6798 || argv_find(argv, argc, "vrf", &idx)) {
6799 vrf = argv[idx + 1]->arg;
6800 idx += 2;
6801 }
6802
6803 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
6804 if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
6805 argv_find_and_parse_safi(argv, argc, &idx, &safi);
6806
6807 /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> */
6808 if (argv_find(argv, argc, "*", &idx)) {
6809 clr_sort = clear_all;
6810 } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6811 clr_sort = clear_peer;
6812 clr_arg = argv[idx]->arg;
6813 } else if (argv_find(argv, argc, "X:X::X:X", &idx)) {
6814 clr_sort = clear_peer;
6815 clr_arg = argv[idx]->arg;
6816 } else if (argv_find(argv, argc, "peer-group", &idx)) {
6817 clr_sort = clear_group;
6818 idx++;
6819 clr_arg = argv[idx]->arg;
6820 } else if (argv_find(argv, argc, "WORD", &idx)) {
6821 clr_sort = clear_peer;
6822 clr_arg = argv[idx]->arg;
6823 } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
6824 clr_sort = clear_as;
6825 clr_arg = argv[idx]->arg;
6826 } else if (argv_find(argv, argc, "external", &idx)) {
6827 clr_sort = clear_external;
6828 }
6829
6830 /* [<soft [<in|out>]|in [prefix-filter]|out>] */
6831 if (argv_find(argv, argc, "soft", &idx)) {
6832 if (argv_find(argv, argc, "in", &idx)
6833 || argv_find(argv, argc, "out", &idx))
6834 clr_type = strmatch(argv[idx]->text, "in")
6835 ? BGP_CLEAR_SOFT_IN
6836 : BGP_CLEAR_SOFT_OUT;
6837 else
6838 clr_type = BGP_CLEAR_SOFT_BOTH;
6839 } else if (argv_find(argv, argc, "in", &idx)) {
6840 clr_type = argv_find(argv, argc, "prefix-filter", &idx)
6841 ? BGP_CLEAR_SOFT_IN_ORF_PREFIX
6842 : BGP_CLEAR_SOFT_IN;
6843 } else if (argv_find(argv, argc, "out", &idx)) {
6844 clr_type = BGP_CLEAR_SOFT_OUT;
6845 } else
6846 clr_type = BGP_CLEAR_SOFT_NONE;
6847
6848 return bgp_clear_vty(vty, vrf, afi, safi, clr_sort, clr_type, clr_arg);
838758ac 6849}
01080f7c 6850
8ad7271d
DS
6851DEFUN (clear_ip_bgp_prefix,
6852 clear_ip_bgp_prefix_cmd,
18c57037 6853 "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
8ad7271d
DS
6854 CLEAR_STR
6855 IP_STR
6856 BGP_STR
838758ac 6857 BGP_INSTANCE_HELP_STR
8ad7271d 6858 "Clear bestpath and re-advertise\n"
0c7b1b01 6859 "IPv4 prefix\n")
8ad7271d 6860{
d62a17ae 6861 char *vrf = NULL;
6862 char *prefix = NULL;
8ad7271d 6863
d62a17ae 6864 int idx = 0;
01080f7c 6865
d62a17ae 6866 /* [<view|vrf> VIEWVRFNAME] */
1d35f218 6867 if (argv_find(argv, argc, "VIEWVRFNAME", &idx))
d62a17ae 6868 vrf = argv[idx]->arg;
0c7b1b01 6869
d62a17ae 6870 prefix = argv[argc - 1]->arg;
8ad7271d 6871
d62a17ae 6872 return bgp_clear_prefix(vty, vrf, prefix, AFI_IP, SAFI_UNICAST, NULL);
838758ac 6873}
8ad7271d 6874
b09b5ae0
DW
6875DEFUN (clear_bgp_ipv6_safi_prefix,
6876 clear_bgp_ipv6_safi_prefix_cmd,
46f296b4 6877 "clear [ip] bgp ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6878 CLEAR_STR
3a2d747c 6879 IP_STR
718e3744 6880 BGP_STR
8c3deaae 6881 "Address Family\n"
46f296b4 6882 BGP_SAFI_HELP_STR
b09b5ae0 6883 "Clear bestpath and re-advertise\n"
0c7b1b01 6884 "IPv6 prefix\n")
718e3744 6885{
9b475e76
PG
6886 int idx_safi = 0;
6887 int idx_ipv6_prefix = 0;
6888 safi_t safi = SAFI_UNICAST;
6889 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
6890 argv[idx_ipv6_prefix]->arg : NULL;
6891
6892 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
d62a17ae 6893 return bgp_clear_prefix(
9b475e76
PG
6894 vty, NULL, prefix, AFI_IP6,
6895 safi, NULL);
838758ac 6896}
01080f7c 6897
b09b5ae0
DW
6898DEFUN (clear_bgp_instance_ipv6_safi_prefix,
6899 clear_bgp_instance_ipv6_safi_prefix_cmd,
18c57037 6900 "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
718e3744 6901 CLEAR_STR
3a2d747c 6902 IP_STR
718e3744 6903 BGP_STR
838758ac 6904 BGP_INSTANCE_HELP_STR
8c3deaae 6905 "Address Family\n"
46f296b4 6906 BGP_SAFI_HELP_STR
b09b5ae0 6907 "Clear bestpath and re-advertise\n"
0c7b1b01 6908 "IPv6 prefix\n")
718e3744 6909{
d62a17ae 6910 int idx_word = 3;
9b475e76
PG
6911 int idx_safi = 0;
6912 int idx_ipv6_prefix = 0;
6913 safi_t safi = SAFI_UNICAST;
6914 char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ?
6915 argv[idx_ipv6_prefix]->arg : NULL;
6916 /* [<view|vrf> VIEWVRFNAME] */
6917 char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ?
6918 argv[idx_word]->arg : NULL;
6919
6920 argv_find_and_parse_safi(argv, argc, &idx_safi, &safi);
6921
d62a17ae 6922 return bgp_clear_prefix(
9b475e76
PG
6923 vty, vrfview, prefix,
6924 AFI_IP6, safi, NULL);
718e3744 6925}
6926
b09b5ae0
DW
6927DEFUN (show_bgp_views,
6928 show_bgp_views_cmd,
d6e3c605 6929 "show [ip] bgp views",
b09b5ae0 6930 SHOW_STR
d6e3c605 6931 IP_STR
01080f7c 6932 BGP_STR
b09b5ae0 6933 "Show the defined BGP views\n")
01080f7c 6934{
d62a17ae 6935 struct list *inst = bm->bgp;
6936 struct listnode *node;
6937 struct bgp *bgp;
01080f7c 6938
d62a17ae 6939 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6940 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6941 return CMD_WARNING;
6942 }
e52702f2 6943
d62a17ae 6944 vty_out(vty, "Defined BGP views:\n");
6945 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6946 /* Skip VRFs. */
6947 if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
6948 continue;
6949 vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
6950 bgp->as);
6951 }
e52702f2 6952
d62a17ae 6953 return CMD_SUCCESS;
e0081f70
ML
6954}
6955
8386ac43 6956DEFUN (show_bgp_vrfs,
6957 show_bgp_vrfs_cmd,
d6e3c605 6958 "show [ip] bgp vrfs [json]",
8386ac43 6959 SHOW_STR
d6e3c605 6960 IP_STR
8386ac43 6961 BGP_STR
6962 "Show BGP VRFs\n"
9973d184 6963 JSON_STR)
8386ac43 6964{
fe1dc5a3 6965 char buf[ETHER_ADDR_STRLEN];
d62a17ae 6966 struct list *inst = bm->bgp;
6967 struct listnode *node;
6968 struct bgp *bgp;
6969 u_char uj = use_json(argc, argv);
6970 json_object *json = NULL;
6971 json_object *json_vrfs = NULL;
6972 int count = 0;
d62a17ae 6973
6974 if (!bgp_option_check(BGP_OPT_MULTIPLE_INSTANCE)) {
6975 vty_out(vty, "BGP Multiple Instance is not enabled\n");
6976 return CMD_WARNING;
6977 }
6978
6979 if (uj) {
6980 json = json_object_new_object();
6981 json_vrfs = json_object_new_object();
6982 }
6983
6984 for (ALL_LIST_ELEMENTS_RO(inst, node, bgp)) {
6985 const char *name, *type;
6986 struct peer *peer;
6987 struct listnode *node, *nnode;
6988 int peers_cfg, peers_estb;
6989 json_object *json_vrf = NULL;
d62a17ae 6990
6991 /* Skip Views. */
6992 if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
6993 continue;
6994
6995 count++;
6996 if (!uj && count == 1)
fe1dc5a3
MK
6997 vty_out(vty,
6998 "%4s %-5s %-16s %9s %10s %-37s %-10s %-15s\n",
a4d82a8a
PZ
6999 "Type", "Id", "routerId", "#PeersVfg",
7000 "#PeersEstb", "Name", "L3-VNI", "Rmac");
d62a17ae 7001
7002 peers_cfg = peers_estb = 0;
7003 if (uj)
7004 json_vrf = json_object_new_object();
7005
7006
7007 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7008 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7009 continue;
7010 peers_cfg++;
7011 if (peer->status == Established)
7012 peers_estb++;
7013 }
7014
7015 if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
7016 name = "Default";
7017 type = "DFLT";
7018 } else {
7019 name = bgp->name;
7020 type = "VRF";
7021 }
7022
a8bf7d9c 7023
d62a17ae 7024 if (uj) {
a4d82a8a
PZ
7025 int64_t vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7026 ? -1
7027 : (int64_t)bgp->vrf_id;
d62a17ae 7028 json_object_string_add(json_vrf, "type", type);
7029 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
7030 json_object_string_add(json_vrf, "routerId",
7031 inet_ntoa(bgp->router_id));
7032 json_object_int_add(json_vrf, "numConfiguredPeers",
7033 peers_cfg);
7034 json_object_int_add(json_vrf, "numEstablishedPeers",
7035 peers_estb);
7036
fe1dc5a3 7037 json_object_int_add(json_vrf, "l3vni", bgp->l3vni);
a4d82a8a
PZ
7038 json_object_string_add(
7039 json_vrf, "rmac",
7040 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7041 json_object_object_add(json_vrfs, name, json_vrf);
7042 } else
fe1dc5a3
MK
7043 vty_out(vty,
7044 "%4s %-5d %-16s %9u %10u %-37s %-10u %-15s\n",
a4d82a8a
PZ
7045 type,
7046 bgp->vrf_id == VRF_UNKNOWN ? -1
7047 : (int)bgp->vrf_id,
7048 inet_ntoa(bgp->router_id), peers_cfg,
7049 peers_estb, name, bgp->l3vni,
fe1dc5a3 7050 prefix_mac2str(&bgp->rmac, buf, sizeof(buf)));
d62a17ae 7051 }
7052
7053 if (uj) {
7054 json_object_object_add(json, "vrfs", json_vrfs);
7055
7056 json_object_int_add(json, "totalVrfs", count);
7057
996c9314
LB
7058 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7059 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7060 json_object_free(json);
7061 } else {
7062 if (count)
7063 vty_out(vty,
7064 "\nTotal number of VRFs (including default): %d\n",
7065 count);
7066 }
7067
7068 return CMD_SUCCESS;
8386ac43 7069}
7070
acf71666
MK
7071static void show_address_entry(struct hash_backet *backet, void *args)
7072{
60466a63
QY
7073 struct vty *vty = (struct vty *)args;
7074 struct bgp_addr *addr = (struct bgp_addr *)backet->data;
acf71666 7075
60466a63 7076 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(addr->addr),
acf71666
MK
7077 addr->refcnt);
7078}
7079
7080static void show_tip_entry(struct hash_backet *backet, void *args)
7081{
0291c246 7082 struct vty *vty = (struct vty *)args;
60466a63 7083 struct tip_addr *tip = (struct tip_addr *)backet->data;
acf71666 7084
60466a63 7085 vty_out(vty, "addr: %s, count: %d\n", inet_ntoa(tip->addr),
acf71666
MK
7086 tip->refcnt);
7087}
7088
7089static void bgp_show_martian_nexthops(struct vty *vty, struct bgp *bgp)
7090{
7091 vty_out(vty, "self nexthop database:\n");
7092 hash_iterate(bgp->address_hash,
7093 (void (*)(struct hash_backet *, void *))show_address_entry,
7094 vty);
7095
7096 vty_out(vty, "Tunnel-ip database:\n");
7097 hash_iterate(bgp->tip_hash,
7098 (void (*)(struct hash_backet *, void *))show_tip_entry,
7099 vty);
7100}
7101
15c81ca4
DS
7102DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd,
7103 "show bgp [<view|vrf> VIEWVRFNAME] martian next-hop",
7104 SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR
60466a63
QY
7105 "martian next-hops\n"
7106 "martian next-hop database\n")
acf71666 7107{
0291c246 7108 struct bgp *bgp = NULL;
15c81ca4
DS
7109 int idx = 0;
7110
7111 if (argv_find(argv, argc, "view", &idx)
7112 || argv_find(argv, argc, "vrf", &idx))
7113 bgp = bgp_lookup_by_name(argv[idx + 1]->arg);
7114 else
7115 bgp = bgp_get_default();
acf71666 7116
acf71666
MK
7117 if (!bgp) {
7118 vty_out(vty, "%% No BGP process is configured\n");
7119 return CMD_WARNING;
7120 }
7121 bgp_show_martian_nexthops(vty, bgp);
7122
7123 return CMD_SUCCESS;
7124}
7125
f412b39a 7126DEFUN (show_bgp_memory,
4bf6a362 7127 show_bgp_memory_cmd,
7fa12b13 7128 "show [ip] bgp memory",
4bf6a362 7129 SHOW_STR
3a2d747c 7130 IP_STR
4bf6a362
PJ
7131 BGP_STR
7132 "Global BGP memory statistics\n")
7133{
d62a17ae 7134 char memstrbuf[MTYPE_MEMSTR_LEN];
7135 unsigned long count;
7136
7137 /* RIB related usage stats */
7138 count = mtype_stats_alloc(MTYPE_BGP_NODE);
7139 vty_out(vty, "%ld RIB nodes, using %s of memory\n", count,
7140 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7141 count * sizeof(struct bgp_node)));
7142
7143 count = mtype_stats_alloc(MTYPE_BGP_ROUTE);
7144 vty_out(vty, "%ld BGP routes, using %s of memory\n", count,
7145 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7146 count * sizeof(struct bgp_info)));
7147 if ((count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA)))
7148 vty_out(vty, "%ld BGP route ancillaries, using %s of memory\n",
7149 count,
7150 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7151 count * sizeof(struct bgp_info_extra)));
7152
7153 if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC)))
7154 vty_out(vty, "%ld Static routes, using %s of memory\n", count,
7155 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7156 count * sizeof(struct bgp_static)));
7157
7158 if ((count = mtype_stats_alloc(MTYPE_BGP_PACKET)))
7159 vty_out(vty, "%ld Packets, using %s of memory\n", count,
7160 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7161 count * sizeof(struct bpacket)));
7162
7163 /* Adj-In/Out */
7164 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_IN)))
7165 vty_out(vty, "%ld Adj-In entries, using %s of memory\n", count,
7166 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7167 count * sizeof(struct bgp_adj_in)));
7168 if ((count = mtype_stats_alloc(MTYPE_BGP_ADJ_OUT)))
7169 vty_out(vty, "%ld Adj-Out entries, using %s of memory\n", count,
7170 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7171 count * sizeof(struct bgp_adj_out)));
7172
7173 if ((count = mtype_stats_alloc(MTYPE_BGP_NEXTHOP_CACHE)))
7174 vty_out(vty, "%ld Nexthop cache entries, using %s of memory\n",
7175 count,
7176 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7177 count * sizeof(struct bgp_nexthop_cache)));
7178
7179 if ((count = mtype_stats_alloc(MTYPE_BGP_DAMP_INFO)))
7180 vty_out(vty, "%ld Dampening entries, using %s of memory\n",
7181 count,
7182 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7183 count * sizeof(struct bgp_damp_info)));
7184
7185 /* Attributes */
7186 count = attr_count();
7187 vty_out(vty, "%ld BGP attributes, using %s of memory\n", count,
7188 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7189 count * sizeof(struct attr)));
7190
7191 if ((count = attr_unknown_count()))
7192 vty_out(vty, "%ld unknown attributes\n", count);
7193
7194 /* AS_PATH attributes */
7195 count = aspath_count();
7196 vty_out(vty, "%ld BGP AS-PATH entries, using %s of memory\n", count,
7197 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7198 count * sizeof(struct aspath)));
7199
7200 count = mtype_stats_alloc(MTYPE_AS_SEG);
7201 vty_out(vty, "%ld BGP AS-PATH segments, using %s of memory\n", count,
7202 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7203 count * sizeof(struct assegment)));
7204
7205 /* Other attributes */
7206 if ((count = community_count()))
7207 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7208 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7209 count * sizeof(struct community)));
d62a17ae 7210 if ((count = mtype_stats_alloc(MTYPE_ECOMMUNITY)))
7211 vty_out(vty, "%ld BGP community entries, using %s of memory\n",
996c9314
LB
7212 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7213 count * sizeof(struct ecommunity)));
d62a17ae 7214 if ((count = mtype_stats_alloc(MTYPE_LCOMMUNITY)))
7215 vty_out(vty,
7216 "%ld BGP large-community entries, using %s of memory\n",
996c9314
LB
7217 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7218 count * sizeof(struct lcommunity)));
d62a17ae 7219
7220 if ((count = mtype_stats_alloc(MTYPE_CLUSTER)))
7221 vty_out(vty, "%ld Cluster lists, using %s of memory\n", count,
7222 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7223 count * sizeof(struct cluster_list)));
7224
7225 /* Peer related usage */
7226 count = mtype_stats_alloc(MTYPE_BGP_PEER);
7227 vty_out(vty, "%ld peers, using %s of memory\n", count,
7228 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7229 count * sizeof(struct peer)));
7230
7231 if ((count = mtype_stats_alloc(MTYPE_PEER_GROUP)))
7232 vty_out(vty, "%ld peer groups, using %s of memory\n", count,
7233 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7234 count * sizeof(struct peer_group)));
7235
7236 /* Other */
7237 if ((count = mtype_stats_alloc(MTYPE_HASH)))
7238 vty_out(vty, "%ld hash tables, using %s of memory\n", count,
7239 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7240 count * sizeof(struct hash)));
7241 if ((count = mtype_stats_alloc(MTYPE_HASH_BACKET)))
7242 vty_out(vty, "%ld hash buckets, using %s of memory\n", count,
7243 mtype_memstr(memstrbuf, sizeof(memstrbuf),
7244 count * sizeof(struct hash_backet)));
7245 if ((count = mtype_stats_alloc(MTYPE_BGP_REGEXP)))
7246 vty_out(vty, "%ld compiled regexes, using %s of memory\n",
996c9314
LB
7247 count, mtype_memstr(memstrbuf, sizeof(memstrbuf),
7248 count * sizeof(regex_t)));
d62a17ae 7249 return CMD_SUCCESS;
4bf6a362 7250}
fee0f4c6 7251
57a9c8a8
DS
7252static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json)
7253{
7254 json_object *bestpath = json_object_new_object();
7255
7256 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE))
7257 json_object_string_add(bestpath, "asPath", "ignore");
7258
7259 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED))
7260 json_object_string_add(bestpath, "asPath", "confed");
7261
7262 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
a4d82a8a
PZ
7263 if (bgp_flag_check(bgp, BGP_FLAG_MULTIPATH_RELAX_AS_SET))
7264 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7265 "as-set");
7266 else
a4d82a8a 7267 json_object_string_add(bestpath, "multiPathRelax",
57a9c8a8
DS
7268 "true");
7269 } else
a4d82a8a 7270 json_object_string_add(bestpath, "multiPathRelax", "false");
57a9c8a8
DS
7271
7272 if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID))
7273 json_object_string_add(bestpath, "compareRouterId", "true");
7274 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)
7275 || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) {
7276 if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED))
a4d82a8a 7277 json_object_string_add(bestpath, "med", "confed");
57a9c8a8
DS
7278 if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST))
7279 json_object_string_add(bestpath, "med",
7280 "missing-as-worst");
7281 else
7282 json_object_string_add(bestpath, "med", "true");
7283 }
7284
7285 json_object_object_add(json, "bestPath", bestpath);
7286}
7287
718e3744 7288/* Show BGP peer's summary information. */
d62a17ae 7289static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
7290 u_char use_json, json_object *json)
7291{
7292 struct peer *peer;
7293 struct listnode *node, *nnode;
7294 unsigned int count = 0, dn_count = 0;
7295 char timebuf[BGP_UPTIME_LEN], dn_flag[2];
7296 char neighbor_buf[VTY_BUFSIZ];
7297 int neighbor_col_default_width = 16;
7298 int len;
7299 int max_neighbor_width = 0;
7300 int pfx_rcd_safi;
7301 json_object *json_peer = NULL;
7302 json_object *json_peers = NULL;
7303
7304 /* labeled-unicast routes are installed in the unicast table so in order
7305 * to
7306 * display the correct PfxRcd value we must look at SAFI_UNICAST
7307 */
7308 if (safi == SAFI_LABELED_UNICAST)
7309 pfx_rcd_safi = SAFI_UNICAST;
7310 else
7311 pfx_rcd_safi = safi;
7312
7313 if (use_json) {
7314 if (json == NULL)
7315 json = json_object_new_object();
7316
7317 json_peers = json_object_new_object();
7318 } else {
7319 /* Loop over all neighbors that will be displayed to determine
7320 * how many
7321 * characters are needed for the Neighbor column
7322 */
7323 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7324 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7325 continue;
7326
7327 if (peer->afc[afi][safi]) {
7328 memset(dn_flag, '\0', sizeof(dn_flag));
7329 if (peer_dynamic_neighbor(peer))
7330 dn_flag[0] = '*';
7331
7332 if (peer->hostname
7333 && bgp_flag_check(bgp,
7334 BGP_FLAG_SHOW_HOSTNAME))
7335 sprintf(neighbor_buf, "%s%s(%s) ",
7336 dn_flag, peer->hostname,
7337 peer->host);
7338 else
7339 sprintf(neighbor_buf, "%s%s ", dn_flag,
7340 peer->host);
7341
7342 len = strlen(neighbor_buf);
7343
7344 if (len > max_neighbor_width)
7345 max_neighbor_width = len;
7346 }
7347 }
f933309e 7348
d62a17ae 7349 /* Originally we displayed the Neighbor column as 16
7350 * characters wide so make that the default
7351 */
7352 if (max_neighbor_width < neighbor_col_default_width)
7353 max_neighbor_width = neighbor_col_default_width;
7354 }
f933309e 7355
d62a17ae 7356 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
7357 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
7358 continue;
7359
ea47320b
DL
7360 if (!peer->afc[afi][safi])
7361 continue;
d62a17ae 7362
ea47320b
DL
7363 if (!count) {
7364 unsigned long ents;
7365 char memstrbuf[MTYPE_MEMSTR_LEN];
a8bf7d9c 7366 int64_t vrf_id_ui;
d62a17ae 7367
a4d82a8a
PZ
7368 vrf_id_ui = (bgp->vrf_id == VRF_UNKNOWN)
7369 ? -1
7370 : (int64_t)bgp->vrf_id;
ea47320b
DL
7371
7372 /* Usage summary and header */
7373 if (use_json) {
7374 json_object_string_add(
7375 json, "routerId",
7376 inet_ntoa(bgp->router_id));
60466a63
QY
7377 json_object_int_add(json, "as", bgp->as);
7378 json_object_int_add(json, "vrfId", vrf_id_ui);
ea47320b
DL
7379 json_object_string_add(
7380 json, "vrfName",
7381 (bgp->inst_type
7382 == BGP_INSTANCE_TYPE_DEFAULT)
7383 ? "Default"
7384 : bgp->name);
7385 } else {
7386 vty_out(vty,
7387 "BGP router identifier %s, local AS number %u vrf-id %d",
60466a63 7388 inet_ntoa(bgp->router_id), bgp->as,
a4d82a8a
PZ
7389 bgp->vrf_id == VRF_UNKNOWN
7390 ? -1
7391 : (int)bgp->vrf_id);
ea47320b
DL
7392 vty_out(vty, "\n");
7393 }
d62a17ae 7394
ea47320b 7395 if (bgp_update_delay_configured(bgp)) {
d62a17ae 7396 if (use_json) {
ea47320b 7397 json_object_int_add(
60466a63 7398 json, "updateDelayLimit",
ea47320b 7399 bgp->v_update_delay);
d62a17ae 7400
ea47320b
DL
7401 if (bgp->v_update_delay
7402 != bgp->v_establish_wait)
d62a17ae 7403 json_object_int_add(
7404 json,
ea47320b
DL
7405 "updateDelayEstablishWait",
7406 bgp->v_establish_wait);
d62a17ae 7407
60466a63 7408 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7409 json_object_string_add(
7410 json,
7411 "updateDelayFirstNeighbor",
7412 bgp->update_delay_begin_time);
7413 json_object_boolean_true_add(
7414 json,
7415 "updateDelayInProgress");
7416 } else {
7417 if (bgp->update_delay_over) {
d62a17ae 7418 json_object_string_add(
7419 json,
7420 "updateDelayFirstNeighbor",
7421 bgp->update_delay_begin_time);
ea47320b 7422 json_object_string_add(
d62a17ae 7423 json,
ea47320b
DL
7424 "updateDelayBestpathResumed",
7425 bgp->update_delay_end_time);
7426 json_object_string_add(
d62a17ae 7427 json,
ea47320b
DL
7428 "updateDelayZebraUpdateResume",
7429 bgp->update_delay_zebra_resume_time);
7430 json_object_string_add(
7431 json,
7432 "updateDelayPeerUpdateResume",
7433 bgp->update_delay_peers_resume_time);
d62a17ae 7434 }
ea47320b
DL
7435 }
7436 } else {
7437 vty_out(vty,
7438 "Read-only mode update-delay limit: %d seconds\n",
7439 bgp->v_update_delay);
7440 if (bgp->v_update_delay
7441 != bgp->v_establish_wait)
d62a17ae 7442 vty_out(vty,
ea47320b
DL
7443 " Establish wait: %d seconds\n",
7444 bgp->v_establish_wait);
d62a17ae 7445
60466a63 7446 if (bgp_update_delay_active(bgp)) {
ea47320b
DL
7447 vty_out(vty,
7448 " First neighbor established: %s\n",
7449 bgp->update_delay_begin_time);
7450 vty_out(vty,
7451 " Delay in progress\n");
7452 } else {
7453 if (bgp->update_delay_over) {
d62a17ae 7454 vty_out(vty,
7455 " First neighbor established: %s\n",
7456 bgp->update_delay_begin_time);
7457 vty_out(vty,
ea47320b
DL
7458 " Best-paths resumed: %s\n",
7459 bgp->update_delay_end_time);
7460 vty_out(vty,
7461 " zebra update resumed: %s\n",
7462 bgp->update_delay_zebra_resume_time);
7463 vty_out(vty,
7464 " peers update resumed: %s\n",
7465 bgp->update_delay_peers_resume_time);
d62a17ae 7466 }
7467 }
7468 }
ea47320b 7469 }
d62a17ae 7470
ea47320b
DL
7471 if (use_json) {
7472 if (bgp_maxmed_onstartup_configured(bgp)
7473 && bgp->maxmed_active)
7474 json_object_boolean_true_add(
60466a63 7475 json, "maxMedOnStartup");
ea47320b
DL
7476 if (bgp->v_maxmed_admin)
7477 json_object_boolean_true_add(
60466a63 7478 json, "maxMedAdministrative");
d62a17ae 7479
ea47320b
DL
7480 json_object_int_add(
7481 json, "tableVersion",
60466a63 7482 bgp_table_version(bgp->rib[afi][safi]));
ea47320b 7483
60466a63
QY
7484 ents = bgp_table_count(bgp->rib[afi][safi]);
7485 json_object_int_add(json, "ribCount", ents);
ea47320b
DL
7486 json_object_int_add(
7487 json, "ribMemory",
7488 ents * sizeof(struct bgp_node));
d62a17ae 7489
ea47320b 7490 ents = listcount(bgp->peer);
60466a63
QY
7491 json_object_int_add(json, "peerCount", ents);
7492 json_object_int_add(json, "peerMemory",
7493 ents * sizeof(struct peer));
d62a17ae 7494
ea47320b
DL
7495 if ((ents = listcount(bgp->group))) {
7496 json_object_int_add(
60466a63 7497 json, "peerGroupCount", ents);
ea47320b
DL
7498 json_object_int_add(
7499 json, "peerGroupMemory",
996c9314
LB
7500 ents * sizeof(struct
7501 peer_group));
ea47320b 7502 }
d62a17ae 7503
ea47320b
DL
7504 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7505 BGP_CONFIG_DAMPENING))
7506 json_object_boolean_true_add(
60466a63 7507 json, "dampeningEnabled");
ea47320b
DL
7508 } else {
7509 if (bgp_maxmed_onstartup_configured(bgp)
7510 && bgp->maxmed_active)
d62a17ae 7511 vty_out(vty,
ea47320b
DL
7512 "Max-med on-startup active\n");
7513 if (bgp->v_maxmed_admin)
d62a17ae 7514 vty_out(vty,
ea47320b 7515 "Max-med administrative active\n");
d62a17ae 7516
60466a63
QY
7517 vty_out(vty, "BGP table version %" PRIu64 "\n",
7518 bgp_table_version(bgp->rib[afi][safi]));
d62a17ae 7519
60466a63 7520 ents = bgp_table_count(bgp->rib[afi][safi]);
ea47320b
DL
7521 vty_out(vty,
7522 "RIB entries %ld, using %s of memory\n",
7523 ents,
996c9314
LB
7524 mtype_memstr(memstrbuf,
7525 sizeof(memstrbuf),
7526 ents * sizeof(struct
7527 bgp_node)));
ea47320b
DL
7528
7529 /* Peer related usage */
7530 ents = listcount(bgp->peer);
60466a63 7531 vty_out(vty, "Peers %ld, using %s of memory\n",
ea47320b
DL
7532 ents,
7533 mtype_memstr(
60466a63
QY
7534 memstrbuf, sizeof(memstrbuf),
7535 ents * sizeof(struct peer)));
ea47320b
DL
7536
7537 if ((ents = listcount(bgp->group)))
d62a17ae 7538 vty_out(vty,
ea47320b 7539 "Peer groups %ld, using %s of memory\n",
d62a17ae 7540 ents,
7541 mtype_memstr(
7542 memstrbuf,
7543 sizeof(memstrbuf),
996c9314
LB
7544 ents * sizeof(struct
7545 peer_group)));
d62a17ae 7546
ea47320b
DL
7547 if (CHECK_FLAG(bgp->af_flags[afi][safi],
7548 BGP_CONFIG_DAMPENING))
60466a63 7549 vty_out(vty, "Dampening enabled.\n");
ea47320b 7550 vty_out(vty, "\n");
d62a17ae 7551
ea47320b
DL
7552 /* Subtract 8 here because 'Neighbor' is
7553 * 8 characters */
7554 vty_out(vty, "Neighbor");
60466a63
QY
7555 vty_out(vty, "%*s", max_neighbor_width - 8,
7556 " ");
ea47320b
DL
7557 vty_out(vty,
7558 "V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n");
d62a17ae 7559 }
ea47320b 7560 }
d62a17ae 7561
ea47320b 7562 count++;
d62a17ae 7563
ea47320b
DL
7564 if (use_json) {
7565 json_peer = json_object_new_object();
d62a17ae 7566
ea47320b 7567 if (peer_dynamic_neighbor(peer))
60466a63
QY
7568 json_object_boolean_true_add(json_peer,
7569 "dynamicPeer");
d62a17ae 7570
ea47320b 7571 if (peer->hostname)
60466a63 7572 json_object_string_add(json_peer, "hostname",
ea47320b 7573 peer->hostname);
d62a17ae 7574
ea47320b 7575 if (peer->domainname)
60466a63
QY
7576 json_object_string_add(json_peer, "domainname",
7577 peer->domainname);
d62a17ae 7578
60466a63 7579 json_object_int_add(json_peer, "remoteAs", peer->as);
ea47320b 7580 json_object_int_add(json_peer, "version", 4);
60466a63 7581 json_object_int_add(json_peer, "msgRcvd",
0112e9e0 7582 PEER_TOTAL_RX(peer));
60466a63 7583 json_object_int_add(json_peer, "msgSent",
0112e9e0 7584 PEER_TOTAL_TX(peer));
ea47320b
DL
7585
7586 json_object_int_add(json_peer, "tableVersion",
7587 peer->version[afi][safi]);
7588 json_object_int_add(json_peer, "outq",
7589 peer->obuf->count);
7590 json_object_int_add(json_peer, "inq", 0);
60466a63
QY
7591 peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN,
7592 use_json, json_peer);
7593 json_object_int_add(json_peer, "prefixReceivedCount",
7594 peer->pcount[afi][pfx_rcd_safi]);
d62a17ae 7595
ea47320b 7596 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
60466a63 7597 json_object_string_add(json_peer, "state",
ea47320b 7598 "Idle (Admin)");
60466a63
QY
7599 else if (CHECK_FLAG(peer->sflags,
7600 PEER_STATUS_PREFIX_OVERFLOW))
7601 json_object_string_add(json_peer, "state",
ea47320b
DL
7602 "Idle (PfxCt)");
7603 else
7604 json_object_string_add(
7605 json_peer, "state",
60466a63
QY
7606 lookup_msg(bgp_status_msg, peer->status,
7607 NULL));
ea47320b
DL
7608
7609 if (peer->conf_if)
60466a63 7610 json_object_string_add(json_peer, "idType",
ea47320b
DL
7611 "interface");
7612 else if (peer->su.sa.sa_family == AF_INET)
60466a63
QY
7613 json_object_string_add(json_peer, "idType",
7614 "ipv4");
ea47320b 7615 else if (peer->su.sa.sa_family == AF_INET6)
60466a63
QY
7616 json_object_string_add(json_peer, "idType",
7617 "ipv6");
d62a17ae 7618
ea47320b
DL
7619 json_object_object_add(json_peers, peer->host,
7620 json_peer);
7621 } else {
7622 memset(dn_flag, '\0', sizeof(dn_flag));
7623 if (peer_dynamic_neighbor(peer)) {
7624 dn_count++;
7625 dn_flag[0] = '*';
7626 }
d62a17ae 7627
ea47320b 7628 if (peer->hostname
60466a63 7629 && bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
ea47320b 7630 len = vty_out(vty, "%s%s(%s)", dn_flag,
60466a63 7631 peer->hostname, peer->host);
ea47320b 7632 else
60466a63 7633 len = vty_out(vty, "%s%s", dn_flag, peer->host);
ea47320b
DL
7634
7635 /* pad the neighbor column with spaces */
7636 if (len < max_neighbor_width)
60466a63
QY
7637 vty_out(vty, "%*s", max_neighbor_width - len,
7638 " ");
ea47320b 7639
86a55b99 7640 vty_out(vty, "4 %10u %7u %7u %8" PRIu64 " %4d %4zd %8s",
0112e9e0
QY
7641 peer->as, PEER_TOTAL_RX(peer),
7642 PEER_TOTAL_TX(peer), peer->version[afi][safi],
7643 0, peer->obuf->count,
d62a17ae 7644 peer_uptime(peer->uptime, timebuf,
ea47320b 7645 BGP_UPTIME_LEN, 0, NULL));
d62a17ae 7646
ea47320b 7647 if (peer->status == Established)
95077abf
DW
7648 if (peer->afc_recv[afi][pfx_rcd_safi])
7649 vty_out(vty, " %12ld",
a4d82a8a
PZ
7650 peer->pcount[afi]
7651 [pfx_rcd_safi]);
95077abf
DW
7652 else
7653 vty_out(vty, " NoNeg");
ea47320b 7654 else {
60466a63 7655 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
ea47320b 7656 vty_out(vty, " Idle (Admin)");
60466a63
QY
7657 else if (CHECK_FLAG(
7658 peer->sflags,
7659 PEER_STATUS_PREFIX_OVERFLOW))
ea47320b 7660 vty_out(vty, " Idle (PfxCt)");
d62a17ae 7661 else
ea47320b 7662 vty_out(vty, " %12s",
60466a63
QY
7663 lookup_msg(bgp_status_msg,
7664 peer->status, NULL));
d62a17ae 7665 }
ea47320b 7666 vty_out(vty, "\n");
d62a17ae 7667 }
7668 }
f933309e 7669
d62a17ae 7670 if (use_json) {
7671 json_object_object_add(json, "peers", json_peers);
7672
7673 json_object_int_add(json, "totalPeers", count);
7674 json_object_int_add(json, "dynamicPeers", dn_count);
7675
57a9c8a8
DS
7676 bgp_show_bestpath_json(bgp, json);
7677
996c9314
LB
7678 vty_out(vty, "%s\n", json_object_to_json_string_ext(
7679 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 7680 json_object_free(json);
7681 } else {
7682 if (count)
7683 vty_out(vty, "\nTotal number of neighbors %d\n", count);
7684 else {
7685 if (use_json)
7686 vty_out(vty,
7687 "{\"error\": {\"message\": \"No %s neighbor configured\"}}\n",
7688 afi_safi_print(afi, safi));
7689 else
7690 vty_out(vty, "No %s neighbor is configured\n",
7691 afi_safi_print(afi, safi));
7692 }
b05a1c8b 7693
d62a17ae 7694 if (dn_count && !use_json) {
7695 vty_out(vty, "* - dynamic neighbor\n");
7696 vty_out(vty, "%d dynamic neighbor(s), limit %d\n",
7697 dn_count, bgp->dynamic_neighbors_limit);
7698 }
7699 }
1ff9a340 7700
d62a17ae 7701 return CMD_SUCCESS;
718e3744 7702}
7703
d62a17ae 7704static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
7705 int safi, u_char use_json,
7706 json_object *json)
7707{
7708 int is_first = 1;
7709 int afi_wildcard = (afi == AFI_MAX);
7710 int safi_wildcard = (safi == SAFI_MAX);
7711 int is_wildcard = (afi_wildcard || safi_wildcard);
7712 bool json_output = false;
7713
7714 if (use_json && is_wildcard)
7715 vty_out(vty, "{\n");
7716 if (afi_wildcard)
7717 afi = 1; /* AFI_IP */
7718 while (afi < AFI_MAX) {
7719 if (safi_wildcard)
7720 safi = 1; /* SAFI_UNICAST */
7721 while (safi < SAFI_MAX) {
318cac96 7722 if (bgp_afi_safi_peer_exists(bgp, afi, safi)) {
d62a17ae 7723 json_output = true;
7724 if (is_wildcard) {
7725 /*
7726 * So limit output to those afi/safi
7727 * pairs that
7728 * actualy have something interesting in
7729 * them
7730 */
7731 if (use_json) {
7732 json = json_object_new_object();
7733
7734 if (!is_first)
7735 vty_out(vty, ",\n");
7736 else
7737 is_first = 0;
7738
7739 vty_out(vty, "\"%s\":",
7740 afi_safi_json(afi,
7741 safi));
7742 } else {
7743 vty_out(vty, "\n%s Summary:\n",
7744 afi_safi_print(afi,
7745 safi));
7746 }
7747 }
7748 bgp_show_summary(vty, bgp, afi, safi, use_json,
7749 json);
7750 }
7751 safi++;
d62a17ae 7752 if (!safi_wildcard)
7753 safi = SAFI_MAX;
7754 }
7755 afi++;
ee851c8c 7756 if (!afi_wildcard)
d62a17ae 7757 afi = AFI_MAX;
7758 }
7759
7760 if (use_json && is_wildcard)
7761 vty_out(vty, "}\n");
7762 else if (use_json && !json_output)
7763 vty_out(vty, "{}\n");
7764}
7765
7766static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi,
7767 safi_t safi, u_char use_json)
7768{
7769 struct listnode *node, *nnode;
7770 struct bgp *bgp;
7771 json_object *json = NULL;
7772 int is_first = 1;
7773
7774 if (use_json)
7775 vty_out(vty, "{\n");
7776
7777 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
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 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7788 ? "Default"
7789 : bgp->name);
7790 } else {
7791 vty_out(vty, "\nInstance %s:\n",
7792 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
7793 ? "Default"
7794 : bgp->name);
7795 }
7796 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, json);
7797 }
7798
7799 if (use_json)
7800 vty_out(vty, "}\n");
7801}
7802
7803int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
7804 safi_t safi, u_char use_json)
7805{
7806 struct bgp *bgp;
7807
7808 if (name) {
7809 if (strmatch(name, "all")) {
7810 bgp_show_all_instances_summary_vty(vty, afi, safi,
7811 use_json);
7812 return CMD_SUCCESS;
7813 } else {
7814 bgp = bgp_lookup_by_name(name);
7815
7816 if (!bgp) {
7817 if (use_json)
7818 vty_out(vty, "{}\n");
7819 else
7820 vty_out(vty,
7821 "%% No such BGP instance exist\n");
7822 return CMD_WARNING;
7823 }
7824
7825 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json,
7826 NULL);
7827 return CMD_SUCCESS;
7828 }
7829 }
7830
7831 bgp = bgp_get_default();
7832
7833 if (bgp)
7834 bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL);
7835
7836 return CMD_SUCCESS;
4fb25c53
DW
7837}
7838
716b2d8a 7839/* `show [ip] bgp summary' commands. */
47fc97cc 7840DEFUN (show_ip_bgp_summary,
718e3744 7841 show_ip_bgp_summary_cmd,
dd6bd0f1 7842 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] summary [json]",
718e3744 7843 SHOW_STR
7844 IP_STR
7845 BGP_STR
8386ac43 7846 BGP_INSTANCE_HELP_STR
46f296b4 7847 BGP_AFI_HELP_STR
dd6bd0f1 7848 BGP_SAFI_WITH_LABEL_HELP_STR
b05a1c8b 7849 "Summary of BGP neighbor status\n"
9973d184 7850 JSON_STR)
718e3744 7851{
d62a17ae 7852 char *vrf = NULL;
7853 afi_t afi = AFI_MAX;
7854 safi_t safi = SAFI_MAX;
7855
7856 int idx = 0;
7857
7858 /* show [ip] bgp */
7859 if (argv_find(argv, argc, "ip", &idx))
7860 afi = AFI_IP;
7861 /* [<view|vrf> VIEWVRFNAME] */
7862 if (argv_find(argv, argc, "view", &idx)
7863 || argv_find(argv, argc, "vrf", &idx))
7864 vrf = argv[++idx]->arg;
7865 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
7866 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
7867 argv_find_and_parse_safi(argv, argc, &idx, &safi);
7868 }
7869
7870 int uj = use_json(argc, argv);
7871
7872 return bgp_show_summary_vty(vty, vrf, afi, safi, uj);
7873}
7874
7875const char *afi_safi_print(afi_t afi, safi_t safi)
7876{
7877 if (afi == AFI_IP && safi == SAFI_UNICAST)
7878 return "IPv4 Unicast";
7879 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7880 return "IPv4 Multicast";
7881 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7882 return "IPv4 Labeled Unicast";
7883 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7884 return "IPv4 VPN";
7885 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7886 return "IPv4 Encap";
7887 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7888 return "IPv6 Unicast";
7889 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7890 return "IPv6 Multicast";
7891 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7892 return "IPv6 Labeled Unicast";
7893 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7894 return "IPv6 VPN";
7895 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7896 return "IPv6 Encap";
7897 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7898 return "L2VPN EVPN";
7899 else
7900 return "Unknown";
538621f2 7901}
7902
b9f77ec8
DS
7903/*
7904 * Please note that we have intentionally camelCased
7905 * the return strings here. So if you want
7906 * to use this function, please ensure you
7907 * are doing this within json output
7908 */
d62a17ae 7909const char *afi_safi_json(afi_t afi, safi_t safi)
7910{
7911 if (afi == AFI_IP && safi == SAFI_UNICAST)
7912 return "ipv4Unicast";
7913 else if (afi == AFI_IP && safi == SAFI_MULTICAST)
7914 return "ipv4Multicast";
7915 else if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
7916 return "ipv4LabeledUnicast";
7917 else if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
7918 return "ipv4Vpn";
7919 else if (afi == AFI_IP && safi == SAFI_ENCAP)
7920 return "ipv4Encap";
7921 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
7922 return "ipv6Unicast";
7923 else if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
7924 return "ipv6Multicast";
7925 else if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
7926 return "ipv6LabeledUnicast";
7927 else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
7928 return "ipv6Vpn";
7929 else if (afi == AFI_IP6 && safi == SAFI_ENCAP)
7930 return "ipv6Encap";
7931 else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
7932 return "l2VpnEvpn";
7933 else
7934 return "Unknown";
27162734
LB
7935}
7936
718e3744 7937/* Show BGP peer's information. */
d62a17ae 7938enum show_type { show_all, show_peer };
7939
7940static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
7941 afi_t afi, safi_t safi,
7942 u_int16_t adv_smcap, u_int16_t adv_rmcap,
7943 u_int16_t rcv_smcap, u_int16_t rcv_rmcap,
7944 u_char use_json, json_object *json_pref)
7945{
7946 /* Send-Mode */
7947 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7948 || CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap)) {
7949 if (use_json) {
7950 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap)
7951 && CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7952 json_object_string_add(json_pref, "sendMode",
7953 "advertisedAndReceived");
7954 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7955 json_object_string_add(json_pref, "sendMode",
7956 "advertised");
7957 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7958 json_object_string_add(json_pref, "sendMode",
7959 "received");
7960 } else {
7961 vty_out(vty, " Send-mode: ");
7962 if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap))
7963 vty_out(vty, "advertised");
7964 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_smcap))
7965 vty_out(vty, "%sreceived",
7966 CHECK_FLAG(p->af_cap[afi][safi],
7967 adv_smcap)
7968 ? ", "
7969 : "");
7970 vty_out(vty, "\n");
7971 }
7972 }
7973
7974 /* Receive-Mode */
7975 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7976 || CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap)) {
7977 if (use_json) {
7978 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap)
7979 && CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7980 json_object_string_add(json_pref, "recvMode",
7981 "advertisedAndReceived");
7982 else if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7983 json_object_string_add(json_pref, "recvMode",
7984 "advertised");
7985 else if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7986 json_object_string_add(json_pref, "recvMode",
7987 "received");
7988 } else {
7989 vty_out(vty, " Receive-mode: ");
7990 if (CHECK_FLAG(p->af_cap[afi][safi], adv_rmcap))
7991 vty_out(vty, "advertised");
7992 if (CHECK_FLAG(p->af_cap[afi][safi], rcv_rmcap))
7993 vty_out(vty, "%sreceived",
7994 CHECK_FLAG(p->af_cap[afi][safi],
7995 adv_rmcap)
7996 ? ", "
7997 : "");
7998 vty_out(vty, "\n");
7999 }
8000 }
8001}
8002
8003static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
8004 safi_t safi, u_char use_json,
8005 json_object *json_neigh)
8006{
0291c246
MK
8007 struct bgp_filter *filter;
8008 struct peer_af *paf;
8009 char orf_pfx_name[BUFSIZ];
8010 int orf_pfx_count;
8011 json_object *json_af = NULL;
8012 json_object *json_prefA = NULL;
8013 json_object *json_prefB = NULL;
8014 json_object *json_addr = NULL;
d62a17ae 8015
8016 if (use_json) {
8017 json_addr = json_object_new_object();
8018 json_af = json_object_new_object();
8019 filter = &p->filter[afi][safi];
8020
8021 if (peer_group_active(p))
8022 json_object_string_add(json_addr, "peerGroupMember",
8023 p->group->name);
8024
8025 paf = peer_af_find(p, afi, safi);
8026 if (paf && PAF_SUBGRP(paf)) {
8027 json_object_int_add(json_addr, "updateGroupId",
8028 PAF_UPDGRP(paf)->id);
8029 json_object_int_add(json_addr, "subGroupId",
8030 PAF_SUBGRP(paf)->id);
8031 json_object_int_add(json_addr, "packetQueueLength",
8032 bpacket_queue_virtual_length(paf));
8033 }
8034
8035 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8036 || CHECK_FLAG(p->af_cap[afi][safi],
8037 PEER_CAP_ORF_PREFIX_SM_RCV)
8038 || CHECK_FLAG(p->af_cap[afi][safi],
8039 PEER_CAP_ORF_PREFIX_RM_ADV)
8040 || CHECK_FLAG(p->af_cap[afi][safi],
8041 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8042 json_object_int_add(json_af, "orfType",
8043 ORF_TYPE_PREFIX);
8044 json_prefA = json_object_new_object();
8045 bgp_show_peer_afi_orf_cap(vty, p, afi, safi,
8046 PEER_CAP_ORF_PREFIX_SM_ADV,
8047 PEER_CAP_ORF_PREFIX_RM_ADV,
8048 PEER_CAP_ORF_PREFIX_SM_RCV,
8049 PEER_CAP_ORF_PREFIX_RM_RCV,
8050 use_json, json_prefA);
8051 json_object_object_add(json_af, "orfPrefixList",
8052 json_prefA);
8053 }
8054
8055 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8056 || CHECK_FLAG(p->af_cap[afi][safi],
8057 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8058 || CHECK_FLAG(p->af_cap[afi][safi],
8059 PEER_CAP_ORF_PREFIX_RM_ADV)
8060 || CHECK_FLAG(p->af_cap[afi][safi],
8061 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8062 json_object_int_add(json_af, "orfOldType",
8063 ORF_TYPE_PREFIX_OLD);
8064 json_prefB = json_object_new_object();
8065 bgp_show_peer_afi_orf_cap(
8066 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8067 PEER_CAP_ORF_PREFIX_RM_ADV,
8068 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8069 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json,
8070 json_prefB);
8071 json_object_object_add(json_af, "orfOldPrefixList",
8072 json_prefB);
8073 }
8074
8075 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8076 || CHECK_FLAG(p->af_cap[afi][safi],
8077 PEER_CAP_ORF_PREFIX_SM_RCV)
8078 || CHECK_FLAG(p->af_cap[afi][safi],
8079 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8080 || CHECK_FLAG(p->af_cap[afi][safi],
8081 PEER_CAP_ORF_PREFIX_RM_ADV)
8082 || CHECK_FLAG(p->af_cap[afi][safi],
8083 PEER_CAP_ORF_PREFIX_RM_RCV)
8084 || CHECK_FLAG(p->af_cap[afi][safi],
8085 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8086 json_object_object_add(json_addr, "afDependentCap",
8087 json_af);
8088 else
8089 json_object_free(json_af);
8090
8091 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8092 orf_pfx_count = prefix_bgp_show_prefix_list(
8093 NULL, afi, orf_pfx_name, use_json);
8094
8095 if (CHECK_FLAG(p->af_sflags[afi][safi],
8096 PEER_STATUS_ORF_PREFIX_SEND)
8097 || orf_pfx_count) {
8098 if (CHECK_FLAG(p->af_sflags[afi][safi],
8099 PEER_STATUS_ORF_PREFIX_SEND))
8100 json_object_boolean_true_add(json_neigh,
8101 "orfSent");
8102 if (orf_pfx_count)
8103 json_object_int_add(json_addr, "orfRecvCounter",
8104 orf_pfx_count);
8105 }
8106 if (CHECK_FLAG(p->af_sflags[afi][safi],
8107 PEER_STATUS_ORF_WAIT_REFRESH))
8108 json_object_string_add(
8109 json_addr, "orfFirstUpdate",
8110 "deferredUntilORFOrRouteRefreshRecvd");
8111
8112 if (CHECK_FLAG(p->af_flags[afi][safi],
8113 PEER_FLAG_REFLECTOR_CLIENT))
8114 json_object_boolean_true_add(json_addr,
8115 "routeReflectorClient");
8116 if (CHECK_FLAG(p->af_flags[afi][safi],
8117 PEER_FLAG_RSERVER_CLIENT))
8118 json_object_boolean_true_add(json_addr,
8119 "routeServerClient");
8120 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8121 json_object_boolean_true_add(json_addr,
8122 "inboundSoftConfigPermit");
8123
8124 if (CHECK_FLAG(p->af_flags[afi][safi],
8125 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8126 json_object_boolean_true_add(
8127 json_addr,
8128 "privateAsNumsAllReplacedInUpdatesToNbr");
8129 else if (CHECK_FLAG(p->af_flags[afi][safi],
8130 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8131 json_object_boolean_true_add(
8132 json_addr,
8133 "privateAsNumsReplacedInUpdatesToNbr");
8134 else if (CHECK_FLAG(p->af_flags[afi][safi],
8135 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8136 json_object_boolean_true_add(
8137 json_addr,
8138 "privateAsNumsAllRemovedInUpdatesToNbr");
8139 else if (CHECK_FLAG(p->af_flags[afi][safi],
8140 PEER_FLAG_REMOVE_PRIVATE_AS))
8141 json_object_boolean_true_add(
8142 json_addr,
8143 "privateAsNumsRemovedInUpdatesToNbr");
8144
8145 if (CHECK_FLAG(p->af_flags[afi][safi],
8146 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8147 json_object_boolean_true_add(json_addr,
8148 "addpathTxAllPaths");
8149
8150 if (CHECK_FLAG(p->af_flags[afi][safi],
8151 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8152 json_object_boolean_true_add(json_addr,
8153 "addpathTxBestpathPerAS");
8154
8155 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8156 json_object_string_add(json_addr,
8157 "overrideASNsInOutboundUpdates",
8158 "ifAspathEqualRemoteAs");
8159
8160 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8161 || CHECK_FLAG(p->af_flags[afi][safi],
8162 PEER_FLAG_FORCE_NEXTHOP_SELF))
8163 json_object_boolean_true_add(json_addr,
8164 "routerAlwaysNextHop");
8165 if (CHECK_FLAG(p->af_flags[afi][safi],
8166 PEER_FLAG_AS_PATH_UNCHANGED))
8167 json_object_boolean_true_add(
8168 json_addr, "unchangedAsPathPropogatedToNbr");
8169 if (CHECK_FLAG(p->af_flags[afi][safi],
8170 PEER_FLAG_NEXTHOP_UNCHANGED))
8171 json_object_boolean_true_add(
8172 json_addr, "unchangedNextHopPropogatedToNbr");
8173 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8174 json_object_boolean_true_add(
8175 json_addr, "unchangedMedPropogatedToNbr");
8176 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8177 || CHECK_FLAG(p->af_flags[afi][safi],
8178 PEER_FLAG_SEND_EXT_COMMUNITY)) {
8179 if (CHECK_FLAG(p->af_flags[afi][safi],
8180 PEER_FLAG_SEND_COMMUNITY)
8181 && CHECK_FLAG(p->af_flags[afi][safi],
8182 PEER_FLAG_SEND_EXT_COMMUNITY))
8183 json_object_string_add(json_addr,
8184 "commAttriSentToNbr",
8185 "extendedAndStandard");
8186 else if (CHECK_FLAG(p->af_flags[afi][safi],
8187 PEER_FLAG_SEND_EXT_COMMUNITY))
8188 json_object_string_add(json_addr,
8189 "commAttriSentToNbr",
8190 "extended");
8191 else
8192 json_object_string_add(json_addr,
8193 "commAttriSentToNbr",
8194 "standard");
8195 }
8196 if (CHECK_FLAG(p->af_flags[afi][safi],
8197 PEER_FLAG_DEFAULT_ORIGINATE)) {
8198 if (p->default_rmap[afi][safi].name)
8199 json_object_string_add(
8200 json_addr, "defaultRouteMap",
8201 p->default_rmap[afi][safi].name);
8202
8203 if (paf && PAF_SUBGRP(paf)
8204 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8205 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8206 json_object_boolean_true_add(json_addr,
8207 "defaultSent");
8208 else
8209 json_object_boolean_true_add(json_addr,
8210 "defaultNotSent");
8211 }
8212
dff8f48d 8213 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8214 if (is_evpn_enabled())
60466a63
QY
8215 json_object_boolean_true_add(
8216 json_addr, "advertiseAllVnis");
dff8f48d
MK
8217 }
8218
d62a17ae 8219 if (filter->plist[FILTER_IN].name
8220 || filter->dlist[FILTER_IN].name
8221 || filter->aslist[FILTER_IN].name
8222 || filter->map[RMAP_IN].name)
8223 json_object_boolean_true_add(json_addr,
8224 "inboundPathPolicyConfig");
8225 if (filter->plist[FILTER_OUT].name
8226 || filter->dlist[FILTER_OUT].name
8227 || filter->aslist[FILTER_OUT].name
8228 || filter->map[RMAP_OUT].name || filter->usmap.name)
8229 json_object_boolean_true_add(
8230 json_addr, "outboundPathPolicyConfig");
8231
8232 /* prefix-list */
8233 if (filter->plist[FILTER_IN].name)
8234 json_object_string_add(json_addr,
8235 "incomingUpdatePrefixFilterList",
8236 filter->plist[FILTER_IN].name);
8237 if (filter->plist[FILTER_OUT].name)
8238 json_object_string_add(json_addr,
8239 "outgoingUpdatePrefixFilterList",
8240 filter->plist[FILTER_OUT].name);
8241
8242 /* distribute-list */
8243 if (filter->dlist[FILTER_IN].name)
8244 json_object_string_add(
8245 json_addr, "incomingUpdateNetworkFilterList",
8246 filter->dlist[FILTER_IN].name);
8247 if (filter->dlist[FILTER_OUT].name)
8248 json_object_string_add(
8249 json_addr, "outgoingUpdateNetworkFilterList",
8250 filter->dlist[FILTER_OUT].name);
8251
8252 /* filter-list. */
8253 if (filter->aslist[FILTER_IN].name)
8254 json_object_string_add(json_addr,
8255 "incomingUpdateAsPathFilterList",
8256 filter->aslist[FILTER_IN].name);
8257 if (filter->aslist[FILTER_OUT].name)
8258 json_object_string_add(json_addr,
8259 "outgoingUpdateAsPathFilterList",
8260 filter->aslist[FILTER_OUT].name);
8261
8262 /* route-map. */
8263 if (filter->map[RMAP_IN].name)
8264 json_object_string_add(
8265 json_addr, "routeMapForIncomingAdvertisements",
8266 filter->map[RMAP_IN].name);
8267 if (filter->map[RMAP_OUT].name)
8268 json_object_string_add(
8269 json_addr, "routeMapForOutgoingAdvertisements",
8270 filter->map[RMAP_OUT].name);
8271
8272 /* unsuppress-map */
8273 if (filter->usmap.name)
8274 json_object_string_add(json_addr,
8275 "selectiveUnsuppressRouteMap",
8276 filter->usmap.name);
8277
8278 /* Receive prefix count */
8279 json_object_int_add(json_addr, "acceptedPrefixCounter",
8280 p->pcount[afi][safi]);
8281
8282 /* Maximum prefix */
8283 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8284 json_object_int_add(json_addr, "prefixAllowedMax",
8285 p->pmax[afi][safi]);
8286 if (CHECK_FLAG(p->af_flags[afi][safi],
8287 PEER_FLAG_MAX_PREFIX_WARNING))
8288 json_object_boolean_true_add(
8289 json_addr, "prefixAllowedMaxWarning");
8290 json_object_int_add(json_addr,
8291 "prefixAllowedWarningThresh",
8292 p->pmax_threshold[afi][safi]);
8293 if (p->pmax_restart[afi][safi])
8294 json_object_int_add(
8295 json_addr,
8296 "prefixAllowedRestartIntervalMsecs",
8297 p->pmax_restart[afi][safi] * 60000);
8298 }
8299 json_object_object_add(json_neigh, afi_safi_print(afi, safi),
8300 json_addr);
8301
8302 } else {
8303 filter = &p->filter[afi][safi];
8304
8305 vty_out(vty, " For address family: %s\n",
8306 afi_safi_print(afi, safi));
8307
8308 if (peer_group_active(p))
8309 vty_out(vty, " %s peer-group member\n",
8310 p->group->name);
8311
8312 paf = peer_af_find(p, afi, safi);
8313 if (paf && PAF_SUBGRP(paf)) {
996c9314
LB
8314 vty_out(vty, " Update group %" PRIu64
8315 ", subgroup %" PRIu64 "\n",
d62a17ae 8316 PAF_UPDGRP(paf)->id, PAF_SUBGRP(paf)->id);
8317 vty_out(vty, " Packet Queue length %d\n",
8318 bpacket_queue_virtual_length(paf));
8319 } else {
8320 vty_out(vty, " Not part of any update group\n");
8321 }
8322 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8323 || CHECK_FLAG(p->af_cap[afi][safi],
8324 PEER_CAP_ORF_PREFIX_SM_RCV)
8325 || CHECK_FLAG(p->af_cap[afi][safi],
8326 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8327 || CHECK_FLAG(p->af_cap[afi][safi],
8328 PEER_CAP_ORF_PREFIX_RM_ADV)
8329 || CHECK_FLAG(p->af_cap[afi][safi],
8330 PEER_CAP_ORF_PREFIX_RM_RCV)
8331 || CHECK_FLAG(p->af_cap[afi][safi],
8332 PEER_CAP_ORF_PREFIX_RM_OLD_RCV))
8333 vty_out(vty, " AF-dependant capabilities:\n");
8334
8335 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8336 || CHECK_FLAG(p->af_cap[afi][safi],
8337 PEER_CAP_ORF_PREFIX_SM_RCV)
8338 || CHECK_FLAG(p->af_cap[afi][safi],
8339 PEER_CAP_ORF_PREFIX_RM_ADV)
8340 || CHECK_FLAG(p->af_cap[afi][safi],
8341 PEER_CAP_ORF_PREFIX_RM_RCV)) {
8342 vty_out(vty,
8343 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8344 ORF_TYPE_PREFIX);
8345 bgp_show_peer_afi_orf_cap(
8346 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8347 PEER_CAP_ORF_PREFIX_RM_ADV,
8348 PEER_CAP_ORF_PREFIX_SM_RCV,
8349 PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL);
8350 }
8351 if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV)
8352 || CHECK_FLAG(p->af_cap[afi][safi],
8353 PEER_CAP_ORF_PREFIX_SM_OLD_RCV)
8354 || CHECK_FLAG(p->af_cap[afi][safi],
8355 PEER_CAP_ORF_PREFIX_RM_ADV)
8356 || CHECK_FLAG(p->af_cap[afi][safi],
8357 PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) {
8358 vty_out(vty,
8359 " Outbound Route Filter (ORF) type (%d) Prefix-list:\n",
8360 ORF_TYPE_PREFIX_OLD);
8361 bgp_show_peer_afi_orf_cap(
8362 vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV,
8363 PEER_CAP_ORF_PREFIX_RM_ADV,
8364 PEER_CAP_ORF_PREFIX_SM_OLD_RCV,
8365 PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL);
8366 }
8367
8368 sprintf(orf_pfx_name, "%s.%d.%d", p->host, afi, safi);
8369 orf_pfx_count = prefix_bgp_show_prefix_list(
8370 NULL, afi, orf_pfx_name, use_json);
8371
8372 if (CHECK_FLAG(p->af_sflags[afi][safi],
8373 PEER_STATUS_ORF_PREFIX_SEND)
8374 || orf_pfx_count) {
8375 vty_out(vty, " Outbound Route Filter (ORF):");
8376 if (CHECK_FLAG(p->af_sflags[afi][safi],
8377 PEER_STATUS_ORF_PREFIX_SEND))
8378 vty_out(vty, " sent;");
8379 if (orf_pfx_count)
8380 vty_out(vty, " received (%d entries)",
8381 orf_pfx_count);
8382 vty_out(vty, "\n");
8383 }
8384 if (CHECK_FLAG(p->af_sflags[afi][safi],
8385 PEER_STATUS_ORF_WAIT_REFRESH))
8386 vty_out(vty,
8387 " First update is deferred until ORF or ROUTE-REFRESH is received\n");
8388
8389 if (CHECK_FLAG(p->af_flags[afi][safi],
8390 PEER_FLAG_REFLECTOR_CLIENT))
8391 vty_out(vty, " Route-Reflector Client\n");
8392 if (CHECK_FLAG(p->af_flags[afi][safi],
8393 PEER_FLAG_RSERVER_CLIENT))
8394 vty_out(vty, " Route-Server Client\n");
8395 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8396 vty_out(vty,
8397 " Inbound soft reconfiguration allowed\n");
8398
8399 if (CHECK_FLAG(p->af_flags[afi][safi],
8400 PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
8401 vty_out(vty,
8402 " Private AS numbers (all) replaced in updates to this neighbor\n");
8403 else if (CHECK_FLAG(p->af_flags[afi][safi],
8404 PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
8405 vty_out(vty,
8406 " Private AS numbers replaced in updates to this neighbor\n");
8407 else if (CHECK_FLAG(p->af_flags[afi][safi],
8408 PEER_FLAG_REMOVE_PRIVATE_AS_ALL))
8409 vty_out(vty,
8410 " Private AS numbers (all) removed in updates to this neighbor\n");
8411 else if (CHECK_FLAG(p->af_flags[afi][safi],
8412 PEER_FLAG_REMOVE_PRIVATE_AS))
8413 vty_out(vty,
8414 " Private AS numbers removed in updates to this neighbor\n");
8415
8416 if (CHECK_FLAG(p->af_flags[afi][safi],
8417 PEER_FLAG_ADDPATH_TX_ALL_PATHS))
8418 vty_out(vty, " Advertise all paths via addpath\n");
8419
8420 if (CHECK_FLAG(p->af_flags[afi][safi],
8421 PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
8422 vty_out(vty,
8423 " Advertise bestpath per AS via addpath\n");
8424
8425 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_AS_OVERRIDE))
8426 vty_out(vty,
8427 " Override ASNs in outbound updates if aspath equals remote-as\n");
8428
8429 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
8430 || CHECK_FLAG(p->af_flags[afi][safi],
8431 PEER_FLAG_FORCE_NEXTHOP_SELF))
8432 vty_out(vty, " NEXT_HOP is always this router\n");
8433 if (CHECK_FLAG(p->af_flags[afi][safi],
8434 PEER_FLAG_AS_PATH_UNCHANGED))
8435 vty_out(vty,
8436 " AS_PATH is propagated unchanged to this neighbor\n");
8437 if (CHECK_FLAG(p->af_flags[afi][safi],
8438 PEER_FLAG_NEXTHOP_UNCHANGED))
8439 vty_out(vty,
8440 " NEXT_HOP is propagated unchanged to this neighbor\n");
8441 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
8442 vty_out(vty,
8443 " MED is propagated unchanged to this neighbor\n");
8444 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
8445 || CHECK_FLAG(p->af_flags[afi][safi],
8446 PEER_FLAG_SEND_EXT_COMMUNITY)
8447 || CHECK_FLAG(p->af_flags[afi][safi],
8448 PEER_FLAG_SEND_LARGE_COMMUNITY)) {
8449 vty_out(vty,
8450 " Community attribute sent to this neighbor");
8451 if (CHECK_FLAG(p->af_flags[afi][safi],
8452 PEER_FLAG_SEND_COMMUNITY)
8453 && CHECK_FLAG(p->af_flags[afi][safi],
8454 PEER_FLAG_SEND_EXT_COMMUNITY)
8455 && CHECK_FLAG(p->af_flags[afi][safi],
8456 PEER_FLAG_SEND_LARGE_COMMUNITY))
8457 vty_out(vty, "(all)\n");
8458 else if (CHECK_FLAG(p->af_flags[afi][safi],
8459 PEER_FLAG_SEND_LARGE_COMMUNITY))
8460 vty_out(vty, "(large)\n");
8461 else if (CHECK_FLAG(p->af_flags[afi][safi],
8462 PEER_FLAG_SEND_EXT_COMMUNITY))
8463 vty_out(vty, "(extended)\n");
8464 else
8465 vty_out(vty, "(standard)\n");
8466 }
8467 if (CHECK_FLAG(p->af_flags[afi][safi],
8468 PEER_FLAG_DEFAULT_ORIGINATE)) {
8469 vty_out(vty, " Default information originate,");
8470
8471 if (p->default_rmap[afi][safi].name)
8472 vty_out(vty, " default route-map %s%s,",
8473 p->default_rmap[afi][safi].map ? "*"
8474 : "",
8475 p->default_rmap[afi][safi].name);
8476 if (paf && PAF_SUBGRP(paf)
8477 && CHECK_FLAG(PAF_SUBGRP(paf)->sflags,
8478 SUBGRP_STATUS_DEFAULT_ORIGINATE))
8479 vty_out(vty, " default sent\n");
8480 else
8481 vty_out(vty, " default not sent\n");
8482 }
8483
dff8f48d
MK
8484 /* advertise-vni-all */
8485 if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
94c2f693 8486 if (is_evpn_enabled())
dff8f48d
MK
8487 vty_out(vty, " advertise-all-vni\n");
8488 }
8489
d62a17ae 8490 if (filter->plist[FILTER_IN].name
8491 || filter->dlist[FILTER_IN].name
8492 || filter->aslist[FILTER_IN].name
8493 || filter->map[RMAP_IN].name)
8494 vty_out(vty, " Inbound path policy configured\n");
8495 if (filter->plist[FILTER_OUT].name
8496 || filter->dlist[FILTER_OUT].name
8497 || filter->aslist[FILTER_OUT].name
8498 || filter->map[RMAP_OUT].name || filter->usmap.name)
8499 vty_out(vty, " Outbound path policy configured\n");
8500
8501 /* prefix-list */
8502 if (filter->plist[FILTER_IN].name)
8503 vty_out(vty,
8504 " Incoming update prefix filter list is %s%s\n",
8505 filter->plist[FILTER_IN].plist ? "*" : "",
8506 filter->plist[FILTER_IN].name);
8507 if (filter->plist[FILTER_OUT].name)
8508 vty_out(vty,
8509 " Outgoing update prefix filter list is %s%s\n",
8510 filter->plist[FILTER_OUT].plist ? "*" : "",
8511 filter->plist[FILTER_OUT].name);
8512
8513 /* distribute-list */
8514 if (filter->dlist[FILTER_IN].name)
8515 vty_out(vty,
8516 " Incoming update network filter list is %s%s\n",
8517 filter->dlist[FILTER_IN].alist ? "*" : "",
8518 filter->dlist[FILTER_IN].name);
8519 if (filter->dlist[FILTER_OUT].name)
8520 vty_out(vty,
8521 " Outgoing update network filter list is %s%s\n",
8522 filter->dlist[FILTER_OUT].alist ? "*" : "",
8523 filter->dlist[FILTER_OUT].name);
8524
8525 /* filter-list. */
8526 if (filter->aslist[FILTER_IN].name)
8527 vty_out(vty,
8528 " Incoming update AS path filter list is %s%s\n",
8529 filter->aslist[FILTER_IN].aslist ? "*" : "",
8530 filter->aslist[FILTER_IN].name);
8531 if (filter->aslist[FILTER_OUT].name)
8532 vty_out(vty,
8533 " Outgoing update AS path filter list is %s%s\n",
8534 filter->aslist[FILTER_OUT].aslist ? "*" : "",
8535 filter->aslist[FILTER_OUT].name);
8536
8537 /* route-map. */
8538 if (filter->map[RMAP_IN].name)
8539 vty_out(vty,
8540 " Route map for incoming advertisements is %s%s\n",
8541 filter->map[RMAP_IN].map ? "*" : "",
8542 filter->map[RMAP_IN].name);
8543 if (filter->map[RMAP_OUT].name)
8544 vty_out(vty,
8545 " Route map for outgoing advertisements is %s%s\n",
8546 filter->map[RMAP_OUT].map ? "*" : "",
8547 filter->map[RMAP_OUT].name);
8548
8549 /* unsuppress-map */
8550 if (filter->usmap.name)
8551 vty_out(vty,
8552 " Route map for selective unsuppress is %s%s\n",
8553 filter->usmap.map ? "*" : "",
8554 filter->usmap.name);
8555
8556 /* Receive prefix count */
8557 vty_out(vty, " %ld accepted prefixes\n", p->pcount[afi][safi]);
8558
8559 /* Maximum prefix */
8560 if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {
8561 vty_out(vty, " Maximum prefixes allowed %ld%s\n",
8562 p->pmax[afi][safi],
8563 CHECK_FLAG(p->af_flags[afi][safi],
8564 PEER_FLAG_MAX_PREFIX_WARNING)
8565 ? " (warning-only)"
8566 : "");
8567 vty_out(vty, " Threshold for warning message %d%%",
8568 p->pmax_threshold[afi][safi]);
8569 if (p->pmax_restart[afi][safi])
8570 vty_out(vty, ", restart interval %d min",
8571 p->pmax_restart[afi][safi]);
8572 vty_out(vty, "\n");
8573 }
8574
8575 vty_out(vty, "\n");
8576 }
8577}
8578
8579static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
8580 json_object *json)
718e3744 8581{
d62a17ae 8582 struct bgp *bgp;
8583 char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
8584 char timebuf[BGP_UPTIME_LEN];
8585 char dn_flag[2];
8586 const char *subcode_str;
8587 const char *code_str;
8588 afi_t afi;
8589 safi_t safi;
8590 u_int16_t i;
8591 u_char *msg;
8592 json_object *json_neigh = NULL;
8593 time_t epoch_tbuf;
718e3744 8594
d62a17ae 8595 bgp = p->bgp;
8596
8597 if (use_json)
8598 json_neigh = json_object_new_object();
8599
8600 memset(dn_flag, '\0', sizeof(dn_flag));
8601 if (!p->conf_if && peer_dynamic_neighbor(p))
8602 dn_flag[0] = '*';
8603
8604 if (!use_json) {
8605 if (p->conf_if) /* Configured interface name. */
8606 vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
8607 BGP_PEER_SU_UNSPEC(p)
8608 ? "None"
8609 : sockunion2str(&p->su, buf,
8610 SU_ADDRSTRLEN));
8611 else /* Configured IP address. */
8612 vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
8613 p->host);
8614 }
8615
8616 if (use_json) {
8617 if (p->conf_if && BGP_PEER_SU_UNSPEC(p))
8618 json_object_string_add(json_neigh, "bgpNeighborAddr",
8619 "none");
8620 else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
8621 json_object_string_add(
8622 json_neigh, "bgpNeighborAddr",
8623 sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
8624
8625 json_object_int_add(json_neigh, "remoteAs", p->as);
8626
8627 if (p->change_local_as)
8628 json_object_int_add(json_neigh, "localAs",
8629 p->change_local_as);
8630 else
8631 json_object_int_add(json_neigh, "localAs", p->local_as);
8632
8633 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
8634 json_object_boolean_true_add(json_neigh,
8635 "localAsNoPrepend");
8636
8637 if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS))
8638 json_object_boolean_true_add(json_neigh,
8639 "localAsReplaceAs");
8640 } else {
8641 if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
8642 || (p->as_type == AS_INTERNAL))
8643 vty_out(vty, "remote AS %u, ", p->as);
8644 else
8645 vty_out(vty, "remote AS Unspecified, ");
8646 vty_out(vty, "local AS %u%s%s, ",
8647 p->change_local_as ? p->change_local_as : p->local_as,
8648 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
8649 ? " no-prepend"
8650 : "",
8651 CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS)
8652 ? " replace-as"
8653 : "");
8654 }
8655 /* peer type internal, external, confed-internal or confed-external */
8656 if (p->as == p->local_as) {
8657 if (use_json) {
8658 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8659 json_object_boolean_true_add(
8660 json_neigh, "nbrConfedInternalLink");
8661 else
8662 json_object_boolean_true_add(json_neigh,
8663 "nbrInternalLink");
8664 } else {
8665 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8666 vty_out(vty, "confed-internal link\n");
8667 else
8668 vty_out(vty, "internal link\n");
8669 }
8670 } else {
8671 if (use_json) {
8672 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
8673 json_object_boolean_true_add(
8674 json_neigh, "nbrConfedExternalLink");
8675 else
8676 json_object_boolean_true_add(json_neigh,
8677 "nbrExternalLink");
8678 } else {
8679 if (bgp_confederation_peers_check(bgp, p->as))
8680 vty_out(vty, "confed-external link\n");
8681 else
8682 vty_out(vty, "external link\n");
8683 }
8684 }
8685
8686 /* Description. */
8687 if (p->desc) {
8688 if (use_json)
8689 json_object_string_add(json_neigh, "nbrDesc", p->desc);
8690 else
8691 vty_out(vty, " Description: %s\n", p->desc);
8692 }
8693
8694 if (p->hostname) {
8695 if (use_json) {
8696 if (p->hostname)
8697 json_object_string_add(json_neigh, "hostname",
8698 p->hostname);
8699
8700 if (p->domainname)
8701 json_object_string_add(json_neigh, "domainname",
8702 p->domainname);
8703 } else {
8704 if (p->domainname && (p->domainname[0] != '\0'))
8705 vty_out(vty, "Hostname: %s.%s\n", p->hostname,
8706 p->domainname);
8707 else
8708 vty_out(vty, "Hostname: %s\n", p->hostname);
8709 }
8710 }
8711
8712 /* Peer-group */
8713 if (p->group) {
8714 if (use_json) {
8715 json_object_string_add(json_neigh, "peerGroup",
8716 p->group->name);
8717
8718 if (dn_flag[0]) {
8719 struct prefix prefix, *range = NULL;
8720
8721 sockunion2hostprefix(&(p->su), &prefix);
8722 range = peer_group_lookup_dynamic_neighbor_range(
8723 p->group, &prefix);
8724
8725 if (range) {
8726 prefix2str(range, buf1, sizeof(buf1));
8727 json_object_string_add(
8728 json_neigh,
8729 "peerSubnetRangeGroup", buf1);
8730 }
8731 }
8732 } else {
8733 vty_out(vty,
8734 " Member of peer-group %s for session parameters\n",
8735 p->group->name);
8736
8737 if (dn_flag[0]) {
8738 struct prefix prefix, *range = NULL;
8739
8740 sockunion2hostprefix(&(p->su), &prefix);
8741 range = peer_group_lookup_dynamic_neighbor_range(
8742 p->group, &prefix);
8743
8744 if (range) {
8745 prefix2str(range, buf1, sizeof(buf1));
8746 vty_out(vty,
8747 " Belongs to the subnet range group: %s\n",
8748 buf1);
8749 }
8750 }
8751 }
8752 }
8753
8754 if (use_json) {
8755 /* Administrative shutdown. */
8756 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8757 json_object_boolean_true_add(json_neigh,
8758 "adminShutDown");
8759
8760 /* BGP Version. */
8761 json_object_int_add(json_neigh, "bgpVersion", 4);
8762 json_object_string_add(
8763 json_neigh, "remoteRouterId",
8764 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8765
8766 /* Confederation */
8767 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8768 && bgp_confederation_peers_check(bgp, p->as))
8769 json_object_boolean_true_add(json_neigh,
8770 "nbrCommonAdmin");
8771
8772 /* Status. */
8773 json_object_string_add(
8774 json_neigh, "bgpState",
8775 lookup_msg(bgp_status_msg, p->status, NULL));
8776
8777 if (p->status == Established) {
8778 time_t uptime;
d62a17ae 8779
8780 uptime = bgp_clock();
8781 uptime -= p->uptime;
d62a17ae 8782 epoch_tbuf = time(NULL) - uptime;
8783
d3c7efed 8784#if CONFDATE > 20200101
a4d82a8a
PZ
8785 CPP_NOTICE(
8786 "bgpTimerUp should be deprecated and can be removed now");
d3c7efed
DS
8787#endif
8788 /*
8789 * bgpTimerUp was miliseconds that was accurate
8790 * up to 1 day, then the value returned
8791 * became garbage. So in order to provide
8792 * some level of backwards compatability,
8793 * we still provde the data, but now
8794 * we are returning the correct value
8795 * and also adding a new bgpTimerUpMsec
8796 * which will allow us to deprecate
8797 * this eventually
8798 */
d62a17ae 8799 json_object_int_add(json_neigh, "bgpTimerUp",
e0330274 8800 uptime * 1000);
d3c7efed
DS
8801 json_object_int_add(json_neigh, "bgpTimerUpMsec",
8802 uptime * 1000);
d62a17ae 8803 json_object_string_add(json_neigh, "bgpTimerUpString",
8804 peer_uptime(p->uptime, timebuf,
8805 BGP_UPTIME_LEN, 0,
8806 NULL));
8807 json_object_int_add(json_neigh,
8808 "bgpTimerUpEstablishedEpoch",
8809 epoch_tbuf);
8810 }
8811
8812 else if (p->status == Active) {
8813 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8814 json_object_string_add(json_neigh, "bgpStateIs",
8815 "passive");
8816 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8817 json_object_string_add(json_neigh, "bgpStateIs",
8818 "passiveNSF");
8819 }
8820
8821 /* read timer */
8822 time_t uptime;
8823 struct tm *tm;
8824
8825 uptime = bgp_clock();
8826 uptime -= p->readtime;
8827 tm = gmtime(&uptime);
8828 json_object_int_add(json_neigh, "bgpTimerLastRead",
8829 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8830 + (tm->tm_hour * 3600000));
8831
8832 uptime = bgp_clock();
8833 uptime -= p->last_write;
8834 tm = gmtime(&uptime);
8835 json_object_int_add(json_neigh, "bgpTimerLastWrite",
8836 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8837 + (tm->tm_hour * 3600000));
8838
8839 uptime = bgp_clock();
8840 uptime -= p->update_time;
8841 tm = gmtime(&uptime);
8842 json_object_int_add(json_neigh, "bgpInUpdateElapsedTimeMsecs",
8843 (tm->tm_sec * 1000) + (tm->tm_min * 60000)
8844 + (tm->tm_hour * 3600000));
8845
8846 /* Configured timer values. */
8847 json_object_int_add(json_neigh, "bgpTimerHoldTimeMsecs",
8848 p->v_holdtime * 1000);
8849 json_object_int_add(json_neigh,
8850 "bgpTimerKeepAliveIntervalMsecs",
8851 p->v_keepalive * 1000);
8852
d25e4efc 8853 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8854 json_object_int_add(json_neigh,
8855 "bgpTimerConfiguredHoldTimeMsecs",
8856 p->holdtime * 1000);
8857 json_object_int_add(
8858 json_neigh,
8859 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8860 p->keepalive * 1000);
d25e4efc 8861 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
8862 || (bgp->default_keepalive
8863 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
8864 json_object_int_add(json_neigh,
8865 "bgpTimerConfiguredHoldTimeMsecs",
8866 bgp->default_holdtime);
8867 json_object_int_add(
8868 json_neigh,
8869 "bgpTimerConfiguredKeepAliveIntervalMsecs",
8870 bgp->default_keepalive);
d62a17ae 8871 }
8872 } else {
8873 /* Administrative shutdown. */
8874 if (CHECK_FLAG(p->flags, PEER_FLAG_SHUTDOWN))
8875 vty_out(vty, " Administratively shut down\n");
8876
8877 /* BGP Version. */
8878 vty_out(vty, " BGP version 4");
8879 vty_out(vty, ", remote router ID %s\n",
8880 inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
8881
8882 /* Confederation */
8883 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
8884 && bgp_confederation_peers_check(bgp, p->as))
8885 vty_out(vty,
8886 " Neighbor under common administration\n");
8887
8888 /* Status. */
8889 vty_out(vty, " BGP state = %s",
8890 lookup_msg(bgp_status_msg, p->status, NULL));
8891
8892 if (p->status == Established)
8893 vty_out(vty, ", up for %8s",
8894 peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN,
8895 0, NULL));
8896
8897 else if (p->status == Active) {
8898 if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE))
8899 vty_out(vty, " (passive)");
8900 else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT))
8901 vty_out(vty, " (NSF passive)");
8902 }
8903 vty_out(vty, "\n");
8904
8905 /* read timer */
8906 vty_out(vty, " Last read %s",
8907 peer_uptime(p->readtime, timebuf, BGP_UPTIME_LEN, 0,
8908 NULL));
8909 vty_out(vty, ", Last write %s\n",
8910 peer_uptime(p->last_write, timebuf, BGP_UPTIME_LEN, 0,
8911 NULL));
8912
8913 /* Configured timer values. */
8914 vty_out(vty,
8915 " Hold time is %d, keepalive interval is %d seconds\n",
8916 p->v_holdtime, p->v_keepalive);
d25e4efc 8917 if (PEER_OR_GROUP_TIMER_SET(p)) {
d62a17ae 8918 vty_out(vty, " Configured hold time is %d",
8919 p->holdtime);
8920 vty_out(vty, ", keepalive interval is %d seconds\n",
8921 p->keepalive);
d25e4efc 8922 } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
a4d82a8a
PZ
8923 || (bgp->default_keepalive
8924 != BGP_DEFAULT_KEEPALIVE)) {
d25e4efc
DS
8925 vty_out(vty, " Configured hold time is %d",
8926 bgp->default_holdtime);
8927 vty_out(vty, ", keepalive interval is %d seconds\n",
8928 bgp->default_keepalive);
d62a17ae 8929 }
8930 }
8931 /* Capability. */
8932 if (p->status == Established) {
8933 if (p->cap || p->afc_adv[AFI_IP][SAFI_UNICAST]
8934 || p->afc_recv[AFI_IP][SAFI_UNICAST]
8935 || p->afc_adv[AFI_IP][SAFI_MULTICAST]
8936 || p->afc_recv[AFI_IP][SAFI_MULTICAST]
8937 || p->afc_adv[AFI_IP6][SAFI_UNICAST]
8938 || p->afc_recv[AFI_IP6][SAFI_UNICAST]
8939 || p->afc_adv[AFI_IP6][SAFI_MULTICAST]
8940 || p->afc_recv[AFI_IP6][SAFI_MULTICAST]
8941 || p->afc_adv[AFI_IP6][SAFI_MPLS_VPN]
8942 || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN]
8943 || p->afc_adv[AFI_IP6][SAFI_ENCAP]
8944 || p->afc_recv[AFI_IP6][SAFI_ENCAP]
8945 || p->afc_adv[AFI_IP][SAFI_ENCAP]
8946 || p->afc_recv[AFI_IP][SAFI_ENCAP]
8947 || p->afc_adv[AFI_IP][SAFI_MPLS_VPN]
8948 || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) {
8949 if (use_json) {
8950 json_object *json_cap = NULL;
8951
8952 json_cap = json_object_new_object();
8953
8954 /* AS4 */
8955 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
8956 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
8957 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)
8958 && CHECK_FLAG(p->cap,
8959 PEER_CAP_AS4_RCV))
8960 json_object_string_add(
8961 json_cap, "4byteAs",
8962 "advertisedAndReceived");
8963 else if (CHECK_FLAG(p->cap,
8964 PEER_CAP_AS4_ADV))
8965 json_object_string_add(
8966 json_cap, "4byteAs",
8967 "advertised");
8968 else if (CHECK_FLAG(p->cap,
8969 PEER_CAP_AS4_RCV))
8970 json_object_string_add(
8971 json_cap, "4byteAs",
8972 "received");
8973 }
8974
8975 /* AddPath */
8976 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
8977 || CHECK_FLAG(p->cap,
8978 PEER_CAP_ADDPATH_ADV)) {
8979 json_object *json_add = NULL;
8980 const char *print_store;
8981
8982 json_add = json_object_new_object();
8983
05c7a1cc
QY
8984 FOREACH_AFI_SAFI (afi, safi) {
8985 json_object *json_sub = NULL;
8986 json_sub =
8987 json_object_new_object();
8988 print_store = afi_safi_print(
8989 afi, safi);
d62a17ae 8990
05c7a1cc
QY
8991 if (CHECK_FLAG(
8992 p->af_cap[afi]
8993 [safi],
8994 PEER_CAP_ADDPATH_AF_TX_ADV)
8995 || CHECK_FLAG(
8996 p->af_cap[afi]
8997 [safi],
8998 PEER_CAP_ADDPATH_AF_TX_RCV)) {
d62a17ae 8999 if (CHECK_FLAG(
9000 p->af_cap
9001 [afi]
9002 [safi],
9003 PEER_CAP_ADDPATH_AF_TX_ADV)
05c7a1cc 9004 && CHECK_FLAG(
d62a17ae 9005 p->af_cap
9006 [afi]
9007 [safi],
05c7a1cc
QY
9008 PEER_CAP_ADDPATH_AF_TX_RCV))
9009 json_object_boolean_true_add(
9010 json_sub,
9011 "txAdvertisedAndReceived");
9012 else if (
9013 CHECK_FLAG(
9014 p->af_cap
9015 [afi]
9016 [safi],
9017 PEER_CAP_ADDPATH_AF_TX_ADV))
9018 json_object_boolean_true_add(
9019 json_sub,
9020 "txAdvertised");
9021 else if (
9022 CHECK_FLAG(
9023 p->af_cap
9024 [afi]
9025 [safi],
9026 PEER_CAP_ADDPATH_AF_TX_RCV))
9027 json_object_boolean_true_add(
9028 json_sub,
9029 "txReceived");
9030 }
d62a17ae 9031
05c7a1cc
QY
9032 if (CHECK_FLAG(
9033 p->af_cap[afi]
9034 [safi],
9035 PEER_CAP_ADDPATH_AF_RX_ADV)
9036 || CHECK_FLAG(
9037 p->af_cap[afi]
9038 [safi],
9039 PEER_CAP_ADDPATH_AF_RX_RCV)) {
d62a17ae 9040 if (CHECK_FLAG(
9041 p->af_cap
9042 [afi]
9043 [safi],
9044 PEER_CAP_ADDPATH_AF_RX_ADV)
05c7a1cc 9045 && CHECK_FLAG(
d62a17ae 9046 p->af_cap
9047 [afi]
9048 [safi],
9049 PEER_CAP_ADDPATH_AF_RX_RCV))
05c7a1cc
QY
9050 json_object_boolean_true_add(
9051 json_sub,
9052 "rxAdvertisedAndReceived");
9053 else if (
9054 CHECK_FLAG(
9055 p->af_cap
9056 [afi]
9057 [safi],
9058 PEER_CAP_ADDPATH_AF_RX_ADV))
9059 json_object_boolean_true_add(
9060 json_sub,
9061 "rxAdvertised");
9062 else if (
9063 CHECK_FLAG(
9064 p->af_cap
9065 [afi]
9066 [safi],
9067 PEER_CAP_ADDPATH_AF_RX_RCV))
9068 json_object_boolean_true_add(
9069 json_sub,
9070 "rxReceived");
d62a17ae 9071 }
9072
05c7a1cc
QY
9073 if (CHECK_FLAG(
9074 p->af_cap[afi]
9075 [safi],
9076 PEER_CAP_ADDPATH_AF_TX_ADV)
9077 || CHECK_FLAG(
9078 p->af_cap[afi]
9079 [safi],
9080 PEER_CAP_ADDPATH_AF_TX_RCV)
9081 || CHECK_FLAG(
9082 p->af_cap[afi]
9083 [safi],
9084 PEER_CAP_ADDPATH_AF_RX_ADV)
9085 || CHECK_FLAG(
9086 p->af_cap[afi]
9087 [safi],
9088 PEER_CAP_ADDPATH_AF_RX_RCV))
9089 json_object_object_add(
9090 json_add,
9091 print_store,
9092 json_sub);
9093 else
9094 json_object_free(
9095 json_sub);
9096 }
9097
d62a17ae 9098 json_object_object_add(
9099 json_cap, "addPath", json_add);
9100 }
9101
9102 /* Dynamic */
9103 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9104 || CHECK_FLAG(p->cap,
9105 PEER_CAP_DYNAMIC_ADV)) {
9106 if (CHECK_FLAG(p->cap,
9107 PEER_CAP_DYNAMIC_ADV)
9108 && CHECK_FLAG(p->cap,
9109 PEER_CAP_DYNAMIC_RCV))
9110 json_object_string_add(
9111 json_cap, "dynamic",
9112 "advertisedAndReceived");
9113 else if (CHECK_FLAG(
9114 p->cap,
9115 PEER_CAP_DYNAMIC_ADV))
9116 json_object_string_add(
9117 json_cap, "dynamic",
9118 "advertised");
9119 else if (CHECK_FLAG(
9120 p->cap,
9121 PEER_CAP_DYNAMIC_RCV))
9122 json_object_string_add(
9123 json_cap, "dynamic",
9124 "received");
9125 }
9126
9127 /* Extended nexthop */
9128 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9129 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9130 json_object *json_nxt = NULL;
9131 const char *print_store;
9132
9133
9134 if (CHECK_FLAG(p->cap,
9135 PEER_CAP_ENHE_ADV)
9136 && CHECK_FLAG(p->cap,
9137 PEER_CAP_ENHE_RCV))
9138 json_object_string_add(
9139 json_cap,
9140 "extendedNexthop",
9141 "advertisedAndReceived");
9142 else if (CHECK_FLAG(p->cap,
9143 PEER_CAP_ENHE_ADV))
9144 json_object_string_add(
9145 json_cap,
9146 "extendedNexthop",
9147 "advertised");
9148 else if (CHECK_FLAG(p->cap,
9149 PEER_CAP_ENHE_RCV))
9150 json_object_string_add(
9151 json_cap,
9152 "extendedNexthop",
9153 "received");
9154
9155 if (CHECK_FLAG(p->cap,
9156 PEER_CAP_ENHE_RCV)) {
9157 json_nxt =
9158 json_object_new_object();
9159
9160 for (safi = SAFI_UNICAST;
9161 safi < SAFI_MAX; safi++) {
9162 if (CHECK_FLAG(
9163 p->af_cap
9164 [AFI_IP]
9165 [safi],
9166 PEER_CAP_ENHE_AF_RCV)) {
9167 print_store = afi_safi_print(
9168 AFI_IP,
9169 safi);
9170 json_object_string_add(
9171 json_nxt,
9172 print_store,
9173 "recieved");
9174 }
9175 }
9176 json_object_object_add(
9177 json_cap,
9178 "extendedNexthopFamililesByPeer",
9179 json_nxt);
9180 }
9181 }
9182
9183 /* Route Refresh */
9184 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9185 || CHECK_FLAG(p->cap,
9186 PEER_CAP_REFRESH_NEW_RCV)
9187 || CHECK_FLAG(p->cap,
9188 PEER_CAP_REFRESH_OLD_RCV)) {
9189 if (CHECK_FLAG(p->cap,
9190 PEER_CAP_REFRESH_ADV)
9191 && (CHECK_FLAG(
9192 p->cap,
9193 PEER_CAP_REFRESH_NEW_RCV)
9194 || CHECK_FLAG(
9195 p->cap,
9196 PEER_CAP_REFRESH_OLD_RCV))) {
9197 if (CHECK_FLAG(
9198 p->cap,
9199 PEER_CAP_REFRESH_OLD_RCV)
9200 && CHECK_FLAG(
9201 p->cap,
9202 PEER_CAP_REFRESH_NEW_RCV))
9203 json_object_string_add(
9204 json_cap,
9205 "routeRefresh",
9206 "advertisedAndReceivedOldNew");
9207 else {
9208 if (CHECK_FLAG(
9209 p->cap,
9210 PEER_CAP_REFRESH_OLD_RCV))
9211 json_object_string_add(
9212 json_cap,
9213 "routeRefresh",
9214 "advertisedAndReceivedOld");
9215 else
9216 json_object_string_add(
9217 json_cap,
9218 "routeRefresh",
9219 "advertisedAndReceivedNew");
9220 }
9221 } else if (
9222 CHECK_FLAG(
9223 p->cap,
9224 PEER_CAP_REFRESH_ADV))
9225 json_object_string_add(
9226 json_cap,
9227 "routeRefresh",
9228 "advertised");
9229 else if (
9230 CHECK_FLAG(
9231 p->cap,
9232 PEER_CAP_REFRESH_NEW_RCV)
9233 || CHECK_FLAG(
9234 p->cap,
9235 PEER_CAP_REFRESH_OLD_RCV))
9236 json_object_string_add(
9237 json_cap,
9238 "routeRefresh",
9239 "received");
9240 }
9241
9242 /* Multiprotocol Extensions */
9243 json_object *json_multi = NULL;
9244 json_multi = json_object_new_object();
9245
05c7a1cc
QY
9246 FOREACH_AFI_SAFI (afi, safi) {
9247 if (p->afc_adv[afi][safi]
9248 || p->afc_recv[afi][safi]) {
9249 json_object *json_exten = NULL;
9250 json_exten =
9251 json_object_new_object();
9252
d62a17ae 9253 if (p->afc_adv[afi][safi]
05c7a1cc
QY
9254 && p->afc_recv[afi][safi])
9255 json_object_boolean_true_add(
9256 json_exten,
9257 "advertisedAndReceived");
9258 else if (p->afc_adv[afi][safi])
9259 json_object_boolean_true_add(
9260 json_exten,
9261 "advertised");
9262 else if (p->afc_recv[afi][safi])
9263 json_object_boolean_true_add(
9264 json_exten,
9265 "received");
d62a17ae 9266
05c7a1cc
QY
9267 json_object_object_add(
9268 json_multi,
9269 afi_safi_print(afi,
9270 safi),
9271 json_exten);
d62a17ae 9272 }
9273 }
9274 json_object_object_add(
9275 json_cap, "multiprotocolExtensions",
9276 json_multi);
9277
d77114b7 9278 /* Hostname capabilities */
60466a63 9279 json_object *json_hname = NULL;
d77114b7
MK
9280
9281 json_hname = json_object_new_object();
9282
9283 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
9284 json_object_string_add(
60466a63
QY
9285 json_hname, "advHostName",
9286 bgp->peer_self->hostname
9287 ? bgp->peer_self
9288 ->hostname
d77114b7
MK
9289 : "n/a");
9290 json_object_string_add(
60466a63
QY
9291 json_hname, "advDomainName",
9292 bgp->peer_self->domainname
9293 ? bgp->peer_self
9294 ->domainname
d77114b7
MK
9295 : "n/a");
9296 }
9297
9298
9299 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
9300 json_object_string_add(
60466a63
QY
9301 json_hname, "rcvHostName",
9302 p->hostname ? p->hostname
9303 : "n/a");
d77114b7 9304 json_object_string_add(
60466a63
QY
9305 json_hname, "rcvDomainName",
9306 p->domainname ? p->domainname
9307 : "n/a");
d77114b7
MK
9308 }
9309
60466a63 9310 json_object_object_add(json_cap, "hostName",
d77114b7
MK
9311 json_hname);
9312
d62a17ae 9313 /* Gracefull Restart */
9314 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9315 || CHECK_FLAG(p->cap,
9316 PEER_CAP_RESTART_ADV)) {
9317 if (CHECK_FLAG(p->cap,
9318 PEER_CAP_RESTART_ADV)
9319 && CHECK_FLAG(p->cap,
9320 PEER_CAP_RESTART_RCV))
9321 json_object_string_add(
9322 json_cap,
9323 "gracefulRestart",
9324 "advertisedAndReceived");
9325 else if (CHECK_FLAG(
9326 p->cap,
9327 PEER_CAP_RESTART_ADV))
9328 json_object_string_add(
9329 json_cap,
9330 "gracefulRestartCapability",
9331 "advertised");
9332 else if (CHECK_FLAG(
9333 p->cap,
9334 PEER_CAP_RESTART_RCV))
9335 json_object_string_add(
9336 json_cap,
9337 "gracefulRestartCapability",
9338 "received");
9339
9340 if (CHECK_FLAG(p->cap,
9341 PEER_CAP_RESTART_RCV)) {
9342 int restart_af_count = 0;
9343 json_object *json_restart =
9344 NULL;
9345 json_restart =
9346 json_object_new_object();
9347
9348 json_object_int_add(
9349 json_cap,
9350 "gracefulRestartRemoteTimerMsecs",
9351 p->v_gr_restart * 1000);
9352
05c7a1cc
QY
9353 FOREACH_AFI_SAFI (afi, safi) {
9354 if (CHECK_FLAG(
9355 p->af_cap
9356 [afi]
9357 [safi],
9358 PEER_CAP_RESTART_AF_RCV)) {
9359 json_object *
9360 json_sub =
9361 NULL;
9362 json_sub =
9363 json_object_new_object();
9364
d62a17ae 9365 if (CHECK_FLAG(
9366 p->af_cap
9367 [afi]
9368 [safi],
05c7a1cc
QY
9369 PEER_CAP_RESTART_AF_PRESERVE_RCV))
9370 json_object_boolean_true_add(
9371 json_sub,
9372 "preserved");
9373 restart_af_count++;
9374 json_object_object_add(
9375 json_restart,
9376 afi_safi_print(
9377 afi,
9378 safi),
9379 json_sub);
d62a17ae 9380 }
9381 }
9382 if (!restart_af_count) {
9383 json_object_string_add(
9384 json_cap,
9385 "addressFamiliesByPeer",
9386 "none");
9387 json_object_free(
9388 json_restart);
9389 } else
9390 json_object_object_add(
9391 json_cap,
9392 "addressFamiliesByPeer",
9393 json_restart);
9394 }
9395 }
9396 json_object_object_add(json_neigh,
9397 "neighborCapabilities",
9398 json_cap);
9399 } else {
9400 vty_out(vty, " Neighbor capabilities:\n");
9401
9402 /* AS4 */
9403 if (CHECK_FLAG(p->cap, PEER_CAP_AS4_RCV)
9404 || CHECK_FLAG(p->cap, PEER_CAP_AS4_ADV)) {
9405 vty_out(vty, " 4 Byte AS:");
9406 if (CHECK_FLAG(p->cap,
9407 PEER_CAP_AS4_ADV))
9408 vty_out(vty, " advertised");
9409 if (CHECK_FLAG(p->cap,
9410 PEER_CAP_AS4_RCV))
9411 vty_out(vty, " %sreceived",
9412 CHECK_FLAG(
9413 p->cap,
9414 PEER_CAP_AS4_ADV)
9415 ? "and "
9416 : "");
9417 vty_out(vty, "\n");
9418 }
9419
9420 /* AddPath */
9421 if (CHECK_FLAG(p->cap, PEER_CAP_ADDPATH_RCV)
9422 || CHECK_FLAG(p->cap,
9423 PEER_CAP_ADDPATH_ADV)) {
9424 vty_out(vty, " AddPath:\n");
9425
05c7a1cc
QY
9426 FOREACH_AFI_SAFI (afi, safi) {
9427 if (CHECK_FLAG(
9428 p->af_cap[afi]
9429 [safi],
9430 PEER_CAP_ADDPATH_AF_TX_ADV)
9431 || CHECK_FLAG(
9432 p->af_cap[afi]
9433 [safi],
9434 PEER_CAP_ADDPATH_AF_TX_RCV)) {
9435 vty_out(vty,
9436 " %s: TX ",
9437 afi_safi_print(
9438 afi,
9439 safi));
9440
d62a17ae 9441 if (CHECK_FLAG(
9442 p->af_cap
9443 [afi]
9444 [safi],
05c7a1cc 9445 PEER_CAP_ADDPATH_AF_TX_ADV))
d62a17ae 9446 vty_out(vty,
05c7a1cc 9447 "advertised %s",
d62a17ae 9448 afi_safi_print(
9449 afi,
9450 safi));
9451
05c7a1cc
QY
9452 if (CHECK_FLAG(
9453 p->af_cap
9454 [afi]
9455 [safi],
9456 PEER_CAP_ADDPATH_AF_TX_RCV))
9457 vty_out(vty,
9458 "%sreceived",
9459 CHECK_FLAG(
9460 p->af_cap
9461 [afi]
9462 [safi],
9463 PEER_CAP_ADDPATH_AF_TX_ADV)
9464 ? " and "
9465 : "");
d62a17ae 9466
05c7a1cc
QY
9467 vty_out(vty, "\n");
9468 }
d62a17ae 9469
05c7a1cc
QY
9470 if (CHECK_FLAG(
9471 p->af_cap[afi]
9472 [safi],
9473 PEER_CAP_ADDPATH_AF_RX_ADV)
9474 || CHECK_FLAG(
9475 p->af_cap[afi]
9476 [safi],
9477 PEER_CAP_ADDPATH_AF_RX_RCV)) {
9478 vty_out(vty,
9479 " %s: RX ",
9480 afi_safi_print(
9481 afi,
9482 safi));
d62a17ae 9483
9484 if (CHECK_FLAG(
9485 p->af_cap
9486 [afi]
9487 [safi],
05c7a1cc 9488 PEER_CAP_ADDPATH_AF_RX_ADV))
d62a17ae 9489 vty_out(vty,
05c7a1cc 9490 "advertised %s",
d62a17ae 9491 afi_safi_print(
9492 afi,
9493 safi));
9494
05c7a1cc
QY
9495 if (CHECK_FLAG(
9496 p->af_cap
9497 [afi]
9498 [safi],
9499 PEER_CAP_ADDPATH_AF_RX_RCV))
d62a17ae 9500 vty_out(vty,
05c7a1cc
QY
9501 "%sreceived",
9502 CHECK_FLAG(
9503 p->af_cap
9504 [afi]
9505 [safi],
9506 PEER_CAP_ADDPATH_AF_RX_ADV)
9507 ? " and "
9508 : "");
9509
9510 vty_out(vty, "\n");
d62a17ae 9511 }
05c7a1cc 9512 }
d62a17ae 9513 }
9514
9515 /* Dynamic */
9516 if (CHECK_FLAG(p->cap, PEER_CAP_DYNAMIC_RCV)
9517 || CHECK_FLAG(p->cap,
9518 PEER_CAP_DYNAMIC_ADV)) {
9519 vty_out(vty, " Dynamic:");
9520 if (CHECK_FLAG(p->cap,
9521 PEER_CAP_DYNAMIC_ADV))
9522 vty_out(vty, " advertised");
9523 if (CHECK_FLAG(p->cap,
9524 PEER_CAP_DYNAMIC_RCV))
9525 vty_out(vty, " %sreceived",
9526 CHECK_FLAG(
9527 p->cap,
9528 PEER_CAP_DYNAMIC_ADV)
9529 ? "and "
9530 : "");
9531 vty_out(vty, "\n");
9532 }
9533
9534 /* Extended nexthop */
9535 if (CHECK_FLAG(p->cap, PEER_CAP_ENHE_RCV)
9536 || CHECK_FLAG(p->cap, PEER_CAP_ENHE_ADV)) {
9537 vty_out(vty, " Extended nexthop:");
9538 if (CHECK_FLAG(p->cap,
9539 PEER_CAP_ENHE_ADV))
9540 vty_out(vty, " advertised");
9541 if (CHECK_FLAG(p->cap,
9542 PEER_CAP_ENHE_RCV))
9543 vty_out(vty, " %sreceived",
9544 CHECK_FLAG(
9545 p->cap,
9546 PEER_CAP_ENHE_ADV)
9547 ? "and "
9548 : "");
9549 vty_out(vty, "\n");
9550
9551 if (CHECK_FLAG(p->cap,
9552 PEER_CAP_ENHE_RCV)) {
9553 vty_out(vty,
9554 " Address families by peer:\n ");
9555 for (safi = SAFI_UNICAST;
9556 safi < SAFI_MAX; safi++)
9557 if (CHECK_FLAG(
9558 p->af_cap
9559 [AFI_IP]
9560 [safi],
9561 PEER_CAP_ENHE_AF_RCV))
9562 vty_out(vty,
9563 " %s\n",
9564 afi_safi_print(
9565 AFI_IP,
9566 safi));
9567 }
9568 }
9569
9570 /* Route Refresh */
9571 if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)
9572 || CHECK_FLAG(p->cap,
9573 PEER_CAP_REFRESH_NEW_RCV)
9574 || CHECK_FLAG(p->cap,
9575 PEER_CAP_REFRESH_OLD_RCV)) {
9576 vty_out(vty, " Route refresh:");
9577 if (CHECK_FLAG(p->cap,
9578 PEER_CAP_REFRESH_ADV))
9579 vty_out(vty, " advertised");
9580 if (CHECK_FLAG(p->cap,
9581 PEER_CAP_REFRESH_NEW_RCV)
9582 || CHECK_FLAG(
9583 p->cap,
9584 PEER_CAP_REFRESH_OLD_RCV))
9585 vty_out(vty, " %sreceived(%s)",
9586 CHECK_FLAG(
9587 p->cap,
9588 PEER_CAP_REFRESH_ADV)
9589 ? "and "
9590 : "",
9591 (CHECK_FLAG(
9592 p->cap,
9593 PEER_CAP_REFRESH_OLD_RCV)
9594 && CHECK_FLAG(
9595 p->cap,
9596 PEER_CAP_REFRESH_NEW_RCV))
9597 ? "old & new"
9598 : CHECK_FLAG(
9599 p->cap,
9600 PEER_CAP_REFRESH_OLD_RCV)
9601 ? "old"
9602 : "new");
9603
9604 vty_out(vty, "\n");
9605 }
9606
9607 /* Multiprotocol Extensions */
05c7a1cc
QY
9608 FOREACH_AFI_SAFI (afi, safi)
9609 if (p->afc_adv[afi][safi]
9610 || p->afc_recv[afi][safi]) {
9611 vty_out(vty,
9612 " Address Family %s:",
9613 afi_safi_print(afi,
9614 safi));
9615 if (p->afc_adv[afi][safi])
d62a17ae 9616 vty_out(vty,
05c7a1cc
QY
9617 " advertised");
9618 if (p->afc_recv[afi][safi])
9619 vty_out(vty,
9620 " %sreceived",
9621 p->afc_adv[afi]
9622 [safi]
9623 ? "and "
9624 : "");
9625 vty_out(vty, "\n");
9626 }
d62a17ae 9627
9628 /* Hostname capability */
60466a63 9629 vty_out(vty, " Hostname Capability:");
d77114b7
MK
9630
9631 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_ADV)) {
57f7feb6
MK
9632 vty_out(vty,
9633 " advertised (name: %s,domain name: %s)",
60466a63
QY
9634 bgp->peer_self->hostname
9635 ? bgp->peer_self
9636 ->hostname
d77114b7 9637 : "n/a",
60466a63
QY
9638 bgp->peer_self->domainname
9639 ? bgp->peer_self
9640 ->domainname
d77114b7
MK
9641 : "n/a");
9642 } else {
9643 vty_out(vty, " not advertised");
d62a17ae 9644 }
9645
d77114b7 9646 if (CHECK_FLAG(p->cap, PEER_CAP_HOSTNAME_RCV)) {
57f7feb6
MK
9647 vty_out(vty,
9648 " received (name: %s,domain name: %s)",
60466a63
QY
9649 p->hostname ? p->hostname
9650 : "n/a",
9651 p->domainname ? p->domainname
9652 : "n/a");
d77114b7
MK
9653 } else {
9654 vty_out(vty, " not received");
9655 }
9656
9657 vty_out(vty, "\n");
9658
d62a17ae 9659 /* Gracefull Restart */
9660 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)
9661 || CHECK_FLAG(p->cap,
9662 PEER_CAP_RESTART_ADV)) {
9663 vty_out(vty,
9664 " Graceful Restart Capabilty:");
9665 if (CHECK_FLAG(p->cap,
9666 PEER_CAP_RESTART_ADV))
9667 vty_out(vty, " advertised");
9668 if (CHECK_FLAG(p->cap,
9669 PEER_CAP_RESTART_RCV))
9670 vty_out(vty, " %sreceived",
9671 CHECK_FLAG(
9672 p->cap,
9673 PEER_CAP_RESTART_ADV)
9674 ? "and "
9675 : "");
9676 vty_out(vty, "\n");
9677
9678 if (CHECK_FLAG(p->cap,
9679 PEER_CAP_RESTART_RCV)) {
9680 int restart_af_count = 0;
9681
9682 vty_out(vty,
9683 " Remote Restart timer is %d seconds\n",
9684 p->v_gr_restart);
9685 vty_out(vty,
9686 " Address families by peer:\n ");
9687
05c7a1cc
QY
9688 FOREACH_AFI_SAFI (afi, safi)
9689 if (CHECK_FLAG(
9690 p->af_cap
9691 [afi]
9692 [safi],
9693 PEER_CAP_RESTART_AF_RCV)) {
9694 vty_out(vty,
9695 "%s%s(%s)",
9696 restart_af_count
9697 ? ", "
9698 : "",
9699 afi_safi_print(
9700 afi,
9701 safi),
9702 CHECK_FLAG(
9703 p->af_cap
9704 [afi]
9705 [safi],
9706 PEER_CAP_RESTART_AF_PRESERVE_RCV)
9707 ? "preserved"
9708 : "not preserved");
9709 restart_af_count++;
9710 }
d62a17ae 9711 if (!restart_af_count)
9712 vty_out(vty, "none");
9713 vty_out(vty, "\n");
9714 }
9715 }
9716 }
9717 }
9718 }
9719
9720 /* graceful restart information */
9721 if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV) || p->t_gr_restart
9722 || p->t_gr_stale) {
9723 json_object *json_grace = NULL;
9724 json_object *json_grace_send = NULL;
9725 json_object *json_grace_recv = NULL;
9726 int eor_send_af_count = 0;
9727 int eor_receive_af_count = 0;
9728
9729 if (use_json) {
9730 json_grace = json_object_new_object();
9731 json_grace_send = json_object_new_object();
9732 json_grace_recv = json_object_new_object();
9733
9734 if (p->status == Established) {
05c7a1cc
QY
9735 FOREACH_AFI_SAFI (afi, safi) {
9736 if (CHECK_FLAG(p->af_sflags[afi][safi],
9737 PEER_STATUS_EOR_SEND)) {
9738 json_object_boolean_true_add(
9739 json_grace_send,
9740 afi_safi_print(afi,
9741 safi));
9742 eor_send_af_count++;
d62a17ae 9743 }
9744 }
05c7a1cc
QY
9745 FOREACH_AFI_SAFI (afi, safi) {
9746 if (CHECK_FLAG(
9747 p->af_sflags[afi][safi],
9748 PEER_STATUS_EOR_RECEIVED)) {
9749 json_object_boolean_true_add(
9750 json_grace_recv,
9751 afi_safi_print(afi,
9752 safi));
9753 eor_receive_af_count++;
d62a17ae 9754 }
9755 }
9756 }
9757
9758 json_object_object_add(json_grace, "endOfRibSend",
9759 json_grace_send);
9760 json_object_object_add(json_grace, "endOfRibRecv",
9761 json_grace_recv);
9762
9763 if (p->t_gr_restart)
9764 json_object_int_add(json_grace,
9765 "gracefulRestartTimerMsecs",
9766 thread_timer_remain_second(
9767 p->t_gr_restart)
9768 * 1000);
9769
9770 if (p->t_gr_stale)
9771 json_object_int_add(
9772 json_grace,
9773 "gracefulStalepathTimerMsecs",
9774 thread_timer_remain_second(
9775 p->t_gr_stale)
9776 * 1000);
9777
9778 json_object_object_add(
9779 json_neigh, "gracefulRestartInfo", json_grace);
9780 } else {
9781 vty_out(vty, " Graceful restart informations:\n");
9782 if (p->status == Established) {
9783 vty_out(vty, " End-of-RIB send: ");
05c7a1cc
QY
9784 FOREACH_AFI_SAFI (afi, safi) {
9785 if (CHECK_FLAG(p->af_sflags[afi][safi],
9786 PEER_STATUS_EOR_SEND)) {
9787 vty_out(vty, "%s%s",
9788 eor_send_af_count ? ", "
9789 : "",
9790 afi_safi_print(afi,
9791 safi));
9792 eor_send_af_count++;
d62a17ae 9793 }
9794 }
9795 vty_out(vty, "\n");
9796 vty_out(vty, " End-of-RIB received: ");
05c7a1cc
QY
9797 FOREACH_AFI_SAFI (afi, safi) {
9798 if (CHECK_FLAG(
9799 p->af_sflags[afi][safi],
9800 PEER_STATUS_EOR_RECEIVED)) {
9801 vty_out(vty, "%s%s",
9802 eor_receive_af_count
9803 ? ", "
9804 : "",
9805 afi_safi_print(afi,
9806 safi));
9807 eor_receive_af_count++;
d62a17ae 9808 }
9809 }
9810 vty_out(vty, "\n");
9811 }
9812
9813 if (p->t_gr_restart)
9814 vty_out(vty,
9815 " The remaining time of restart timer is %ld\n",
9816 thread_timer_remain_second(
9817 p->t_gr_restart));
9818
9819 if (p->t_gr_stale)
9820 vty_out(vty,
9821 " The remaining time of stalepath timer is %ld\n",
9822 thread_timer_remain_second(
9823 p->t_gr_stale));
9824 }
9825 }
9826 if (use_json) {
9827 json_object *json_stat = NULL;
9828 json_stat = json_object_new_object();
9829 /* Packet counts. */
9830 json_object_int_add(json_stat, "depthInq", 0);
9831 json_object_int_add(json_stat, "depthOutq",
9832 (unsigned long)p->obuf->count);
0112e9e0
QY
9833 json_object_int_add(json_stat, "opensSent",
9834 atomic_load_explicit(&p->open_out,
9835 memory_order_relaxed));
9836 json_object_int_add(json_stat, "opensRecv",
9837 atomic_load_explicit(&p->open_in,
9838 memory_order_relaxed));
d62a17ae 9839 json_object_int_add(json_stat, "notificationsSent",
0112e9e0
QY
9840 atomic_load_explicit(&p->notify_out,
9841 memory_order_relaxed));
d62a17ae 9842 json_object_int_add(json_stat, "notificationsRecv",
0112e9e0
QY
9843 atomic_load_explicit(&p->notify_in,
9844 memory_order_relaxed));
9845 json_object_int_add(json_stat, "updatesSent",
9846 atomic_load_explicit(&p->update_out,
9847 memory_order_relaxed));
9848 json_object_int_add(json_stat, "updatesRecv",
9849 atomic_load_explicit(&p->update_in,
9850 memory_order_relaxed));
d62a17ae 9851 json_object_int_add(json_stat, "keepalivesSent",
0112e9e0
QY
9852 atomic_load_explicit(&p->keepalive_out,
9853 memory_order_relaxed));
d62a17ae 9854 json_object_int_add(json_stat, "keepalivesRecv",
0112e9e0
QY
9855 atomic_load_explicit(&p->keepalive_in,
9856 memory_order_relaxed));
d62a17ae 9857 json_object_int_add(json_stat, "routeRefreshSent",
0112e9e0
QY
9858 atomic_load_explicit(&p->refresh_out,
9859 memory_order_relaxed));
d62a17ae 9860 json_object_int_add(json_stat, "routeRefreshRecv",
0112e9e0
QY
9861 atomic_load_explicit(&p->refresh_in,
9862 memory_order_relaxed));
d62a17ae 9863 json_object_int_add(json_stat, "capabilitySent",
0112e9e0
QY
9864 atomic_load_explicit(&p->dynamic_cap_out,
9865 memory_order_relaxed));
d62a17ae 9866 json_object_int_add(json_stat, "capabilityRecv",
0112e9e0
QY
9867 atomic_load_explicit(&p->dynamic_cap_in,
9868 memory_order_relaxed));
9869 json_object_int_add(json_stat, "totalSent", PEER_TOTAL_TX(p));
9870 json_object_int_add(json_stat, "totalRecv", PEER_TOTAL_RX(p));
d62a17ae 9871 json_object_object_add(json_neigh, "messageStats", json_stat);
9872 } else {
9873 /* Packet counts. */
9874 vty_out(vty, " Message statistics:\n");
9875 vty_out(vty, " Inq depth is 0\n");
9876 vty_out(vty, " Outq depth is %lu\n",
9877 (unsigned long)p->obuf->count);
9878 vty_out(vty, " Sent Rcvd\n");
0112e9e0
QY
9879 vty_out(vty, " Opens: %10d %10d\n",
9880 atomic_load_explicit(&p->open_out,
9881 memory_order_relaxed),
9882 atomic_load_explicit(&p->open_in,
9883 memory_order_relaxed));
9884 vty_out(vty, " Notifications: %10d %10d\n",
9885 atomic_load_explicit(&p->notify_out,
9886 memory_order_relaxed),
9887 atomic_load_explicit(&p->notify_in,
9888 memory_order_relaxed));
9889 vty_out(vty, " Updates: %10d %10d\n",
9890 atomic_load_explicit(&p->update_out,
9891 memory_order_relaxed),
9892 atomic_load_explicit(&p->update_in,
9893 memory_order_relaxed));
9894 vty_out(vty, " Keepalives: %10d %10d\n",
9895 atomic_load_explicit(&p->keepalive_out,
9896 memory_order_relaxed),
9897 atomic_load_explicit(&p->keepalive_in,
9898 memory_order_relaxed));
9899 vty_out(vty, " Route Refresh: %10d %10d\n",
9900 atomic_load_explicit(&p->refresh_out,
9901 memory_order_relaxed),
9902 atomic_load_explicit(&p->refresh_in,
9903 memory_order_relaxed));
d62a17ae 9904 vty_out(vty, " Capability: %10d %10d\n",
0112e9e0
QY
9905 atomic_load_explicit(&p->dynamic_cap_out,
9906 memory_order_relaxed),
9907 atomic_load_explicit(&p->dynamic_cap_in,
9908 memory_order_relaxed));
9909 vty_out(vty, " Total: %10d %10d\n", PEER_TOTAL_TX(p),
9910 PEER_TOTAL_RX(p));
d62a17ae 9911 }
9912
9913 if (use_json) {
9914 /* advertisement-interval */
9915 json_object_int_add(json_neigh,
9916 "minBtwnAdvertisementRunsTimerMsecs",
9917 p->v_routeadv * 1000);
9918
9919 /* Update-source. */
9920 if (p->update_if || p->update_source) {
9921 if (p->update_if)
9922 json_object_string_add(json_neigh,
9923 "updateSource",
9924 p->update_if);
9925 else if (p->update_source)
9926 json_object_string_add(
9927 json_neigh, "updateSource",
9928 sockunion2str(p->update_source, buf1,
9929 SU_ADDRSTRLEN));
9930 }
9931 } else {
9932 /* advertisement-interval */
9933 vty_out(vty,
9934 " Minimum time between advertisement runs is %d seconds\n",
9935 p->v_routeadv);
9936
9937 /* Update-source. */
9938 if (p->update_if || p->update_source) {
9939 vty_out(vty, " Update source is ");
9940 if (p->update_if)
9941 vty_out(vty, "%s", p->update_if);
9942 else if (p->update_source)
9943 vty_out(vty, "%s",
9944 sockunion2str(p->update_source, buf1,
9945 SU_ADDRSTRLEN));
9946 vty_out(vty, "\n");
9947 }
9948
9949 vty_out(vty, "\n");
9950 }
9951
9952 /* Address Family Information */
9953 json_object *json_hold = NULL;
9954
9955 if (use_json)
9956 json_hold = json_object_new_object();
9957
05c7a1cc
QY
9958 FOREACH_AFI_SAFI (afi, safi)
9959 if (p->afc[afi][safi])
9960 bgp_show_peer_afi(vty, p, afi, safi, use_json,
9961 json_hold);
d62a17ae 9962
9963 if (use_json) {
9964 json_object_object_add(json_neigh, "addressFamilyInfo",
9965 json_hold);
9966 json_object_int_add(json_neigh, "connectionsEstablished",
9967 p->established);
9968 json_object_int_add(json_neigh, "connectionsDropped",
9969 p->dropped);
9970 } else
9971 vty_out(vty, " Connections established %d; dropped %d\n",
9972 p->established, p->dropped);
9973
9974 if (!p->last_reset) {
9975 if (use_json)
9976 json_object_string_add(json_neigh, "lastReset",
9977 "never");
9978 else
9979 vty_out(vty, " Last reset never\n");
9980 } else {
9981 if (use_json) {
9982 time_t uptime;
9983 struct tm *tm;
9984
9985 uptime = bgp_clock();
9986 uptime -= p->resettime;
9987 tm = gmtime(&uptime);
9988 json_object_int_add(json_neigh, "lastResetTimerMsecs",
9989 (tm->tm_sec * 1000)
9990 + (tm->tm_min * 60000)
9991 + (tm->tm_hour * 3600000));
9992 json_object_string_add(
9993 json_neigh, "lastResetDueTo",
9994 peer_down_str[(int)p->last_reset]);
9995 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
9996 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
9997 char errorcodesubcode_hexstr[5];
9998 char errorcodesubcode_str[256];
9999
10000 code_str = bgp_notify_code_str(p->notify.code);
10001 subcode_str = bgp_notify_subcode_str(
10002 p->notify.code, p->notify.subcode);
10003
10004 sprintf(errorcodesubcode_hexstr, "%02X%02X",
10005 p->notify.code, p->notify.subcode);
10006 json_object_string_add(json_neigh,
10007 "lastErrorCodeSubcode",
10008 errorcodesubcode_hexstr);
10009 snprintf(errorcodesubcode_str, 255, "%s%s",
10010 code_str, subcode_str);
10011 json_object_string_add(json_neigh,
10012 "lastNotificationReason",
10013 errorcodesubcode_str);
10014 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10015 && p->notify.code == BGP_NOTIFY_CEASE
10016 && (p->notify.subcode
10017 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10018 || p->notify.subcode
10019 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10020 && p->notify.length) {
10021 char msgbuf[1024];
10022 const char *msg_str;
10023
10024 msg_str = bgp_notify_admin_message(
10025 msgbuf, sizeof(msgbuf),
10026 (u_char *)p->notify.data,
10027 p->notify.length);
10028 if (msg_str)
10029 json_object_string_add(
10030 json_neigh,
10031 "lastShutdownDescription",
10032 msg_str);
10033 }
10034 }
10035 } else {
10036 vty_out(vty, " Last reset %s, ",
10037 peer_uptime(p->resettime, timebuf,
10038 BGP_UPTIME_LEN, 0, NULL));
10039
10040 if (p->last_reset == PEER_DOWN_NOTIFY_SEND
10041 || p->last_reset == PEER_DOWN_NOTIFY_RECEIVED) {
10042 code_str = bgp_notify_code_str(p->notify.code);
10043 subcode_str = bgp_notify_subcode_str(
10044 p->notify.code, p->notify.subcode);
10045 vty_out(vty, "due to NOTIFICATION %s (%s%s)\n",
10046 p->last_reset == PEER_DOWN_NOTIFY_SEND
10047 ? "sent"
10048 : "received",
10049 code_str, subcode_str);
10050 if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
10051 && p->notify.code == BGP_NOTIFY_CEASE
10052 && (p->notify.subcode
10053 == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
10054 || p->notify.subcode
10055 == BGP_NOTIFY_CEASE_ADMIN_RESET)
10056 && p->notify.length) {
10057 char msgbuf[1024];
10058 const char *msg_str;
10059
10060 msg_str = bgp_notify_admin_message(
10061 msgbuf, sizeof(msgbuf),
10062 (u_char *)p->notify.data,
10063 p->notify.length);
10064 if (msg_str)
10065 vty_out(vty,
10066 " Message: \"%s\"\n",
10067 msg_str);
10068 }
10069 } else {
10070 vty_out(vty, "due to %s\n",
10071 peer_down_str[(int)p->last_reset]);
10072 }
10073
10074 if (p->last_reset_cause_size) {
10075 msg = p->last_reset_cause;
10076 vty_out(vty,
10077 " Message received that caused BGP to send a NOTIFICATION:\n ");
10078 for (i = 1; i <= p->last_reset_cause_size;
10079 i++) {
10080 vty_out(vty, "%02X", *msg++);
10081
10082 if (i != p->last_reset_cause_size) {
10083 if (i % 16 == 0) {
10084 vty_out(vty, "\n ");
10085 } else if (i % 4 == 0) {
10086 vty_out(vty, " ");
10087 }
10088 }
10089 }
10090 vty_out(vty, "\n");
10091 }
10092 }
10093 }
10094
10095 if (CHECK_FLAG(p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) {
10096 if (use_json)
10097 json_object_boolean_true_add(json_neigh,
10098 "prefixesConfigExceedMax");
10099 else
10100 vty_out(vty,
10101 " Peer had exceeded the max. no. of prefixes configured.\n");
10102
10103 if (p->t_pmax_restart) {
10104 if (use_json) {
10105 json_object_boolean_true_add(
10106 json_neigh, "reducePrefixNumFrom");
10107 json_object_int_add(json_neigh,
10108 "restartInTimerMsec",
10109 thread_timer_remain_second(
10110 p->t_pmax_restart)
10111 * 1000);
10112 } else
10113 vty_out(vty,
10114 " Reduce the no. of prefix from %s, will restart in %ld seconds\n",
996c9314
LB
10115 p->host, thread_timer_remain_second(
10116 p->t_pmax_restart));
d62a17ae 10117 } else {
10118 if (use_json)
10119 json_object_boolean_true_add(
10120 json_neigh,
10121 "reducePrefixNumAndClearIpBgp");
10122 else
10123 vty_out(vty,
10124 " Reduce the no. of prefix and clear ip bgp %s to restore peering\n",
10125 p->host);
10126 }
10127 }
10128
10129 /* EBGP Multihop and GTSM */
10130 if (p->sort != BGP_PEER_IBGP) {
10131 if (use_json) {
10132 if (p->gtsm_hops > 0)
10133 json_object_int_add(json_neigh,
10134 "externalBgpNbrMaxHopsAway",
10135 p->gtsm_hops);
10136 else if (p->ttl > 1)
10137 json_object_int_add(json_neigh,
10138 "externalBgpNbrMaxHopsAway",
10139 p->ttl);
10140 } else {
10141 if (p->gtsm_hops > 0)
10142 vty_out(vty,
10143 " External BGP neighbor may be up to %d hops away.\n",
10144 p->gtsm_hops);
10145 else if (p->ttl > 1)
10146 vty_out(vty,
10147 " External BGP neighbor may be up to %d hops away.\n",
10148 p->ttl);
10149 }
10150 } else {
10151 if (p->gtsm_hops > 0) {
10152 if (use_json)
10153 json_object_int_add(json_neigh,
10154 "internalBgpNbrMaxHopsAway",
10155 p->gtsm_hops);
10156 else
10157 vty_out(vty,
10158 " Internal BGP neighbor may be up to %d hops away.\n",
10159 p->gtsm_hops);
10160 }
10161 }
10162
10163 /* Local address. */
10164 if (p->su_local) {
10165 if (use_json) {
10166 json_object_string_add(json_neigh, "hostLocal",
10167 sockunion2str(p->su_local, buf1,
10168 SU_ADDRSTRLEN));
10169 json_object_int_add(json_neigh, "portLocal",
10170 ntohs(p->su_local->sin.sin_port));
10171 } else
10172 vty_out(vty, "Local host: %s, Local port: %d\n",
10173 sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
10174 ntohs(p->su_local->sin.sin_port));
10175 }
10176
10177 /* Remote address. */
10178 if (p->su_remote) {
10179 if (use_json) {
10180 json_object_string_add(json_neigh, "hostForeign",
10181 sockunion2str(p->su_remote, buf1,
10182 SU_ADDRSTRLEN));
10183 json_object_int_add(json_neigh, "portForeign",
10184 ntohs(p->su_remote->sin.sin_port));
10185 } else
10186 vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
10187 sockunion2str(p->su_remote, buf1,
10188 SU_ADDRSTRLEN),
10189 ntohs(p->su_remote->sin.sin_port));
10190 }
10191
10192 /* Nexthop display. */
10193 if (p->su_local) {
10194 if (use_json) {
10195 json_object_string_add(json_neigh, "nexthop",
10196 inet_ntop(AF_INET,
10197 &p->nexthop.v4, buf1,
10198 sizeof(buf1)));
10199 json_object_string_add(json_neigh, "nexthopGlobal",
10200 inet_ntop(AF_INET6,
10201 &p->nexthop.v6_global,
10202 buf1, sizeof(buf1)));
10203 json_object_string_add(json_neigh, "nexthopLocal",
10204 inet_ntop(AF_INET6,
10205 &p->nexthop.v6_local,
10206 buf1, sizeof(buf1)));
10207 if (p->shared_network)
10208 json_object_string_add(json_neigh,
10209 "bgpConnection",
10210 "sharedNetwork");
10211 else
10212 json_object_string_add(json_neigh,
10213 "bgpConnection",
10214 "nonSharedNetwork");
10215 } else {
10216 vty_out(vty, "Nexthop: %s\n",
10217 inet_ntop(AF_INET, &p->nexthop.v4, buf1,
10218 sizeof(buf1)));
10219 vty_out(vty, "Nexthop global: %s\n",
10220 inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
10221 sizeof(buf1)));
10222 vty_out(vty, "Nexthop local: %s\n",
10223 inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
10224 sizeof(buf1)));
10225 vty_out(vty, "BGP connection: %s\n",
10226 p->shared_network ? "shared network"
10227 : "non shared network");
10228 }
10229 }
10230
10231 /* Timer information. */
10232 if (use_json) {
10233 json_object_int_add(json_neigh, "connectRetryTimer",
10234 p->v_connect);
10235 if (p->status == Established && p->rtt)
10236 json_object_int_add(json_neigh, "estimatedRttInMsecs",
10237 p->rtt);
10238 if (p->t_start)
10239 json_object_int_add(
10240 json_neigh, "nextStartTimerDueInMsecs",
10241 thread_timer_remain_second(p->t_start) * 1000);
10242 if (p->t_connect)
10243 json_object_int_add(
10244 json_neigh, "nextConnectTimerDueInMsecs",
10245 thread_timer_remain_second(p->t_connect)
10246 * 1000);
10247 if (p->t_routeadv) {
10248 json_object_int_add(json_neigh, "mraiInterval",
10249 p->v_routeadv);
10250 json_object_int_add(
10251 json_neigh, "mraiTimerExpireInMsecs",
10252 thread_timer_remain_second(p->t_routeadv)
10253 * 1000);
10254 }
10255 if (p->password)
10256 json_object_int_add(json_neigh, "authenticationEnabled",
10257 1);
10258
10259 if (p->t_read)
10260 json_object_string_add(json_neigh, "readThread", "on");
10261 else
10262 json_object_string_add(json_neigh, "readThread", "off");
49507a6f
QY
10263
10264 if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON))
d62a17ae 10265 json_object_string_add(json_neigh, "writeThread", "on");
10266 else
10267 json_object_string_add(json_neigh, "writeThread",
10268 "off");
10269 } else {
10270 vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n",
10271 p->v_connect);
10272 if (p->status == Established && p->rtt)
10273 vty_out(vty, "Estimated round trip time: %d ms\n",
10274 p->rtt);
10275 if (p->t_start)
10276 vty_out(vty, "Next start timer due in %ld seconds\n",
10277 thread_timer_remain_second(p->t_start));
10278 if (p->t_connect)
10279 vty_out(vty, "Next connect timer due in %ld seconds\n",
10280 thread_timer_remain_second(p->t_connect));
10281 if (p->t_routeadv)
10282 vty_out(vty,
10283 "MRAI (interval %u) timer expires in %ld seconds\n",
10284 p->v_routeadv,
10285 thread_timer_remain_second(p->t_routeadv));
10286 if (p->password)
10287 vty_out(vty, "Peer Authentication Enabled\n");
10288
10289 vty_out(vty, "Read thread: %s Write thread: %s\n",
49507a6f
QY
10290 p->t_read ? "on" : "off",
10291 CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)
10292 ? "on"
10293 : "off");
d62a17ae 10294 }
10295
10296 if (p->notify.code == BGP_NOTIFY_OPEN_ERR
10297 && p->notify.subcode == BGP_NOTIFY_OPEN_UNSUP_CAPBL)
10298 bgp_capability_vty_out(vty, p, use_json, json_neigh);
10299
10300 if (!use_json)
10301 vty_out(vty, "\n");
10302
10303 /* BFD information. */
10304 bgp_bfd_show_info(vty, p, use_json, json_neigh);
10305
10306 if (use_json) {
10307 if (p->conf_if) /* Configured interface name. */
10308 json_object_object_add(json, p->conf_if, json_neigh);
10309 else /* Configured IP address. */
10310 json_object_object_add(json, p->host, json_neigh);
10311 }
10312}
10313
10314static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
10315 enum show_type type, union sockunion *su,
10316 const char *conf_if, u_char use_json,
10317 json_object *json)
10318{
10319 struct listnode *node, *nnode;
10320 struct peer *peer;
10321 int find = 0;
10322
10323 for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
10324 if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
10325 continue;
10326
10327 switch (type) {
10328 case show_all:
10329 bgp_show_peer(vty, peer, use_json, json);
10330 break;
10331 case show_peer:
10332 if (conf_if) {
10333 if ((peer->conf_if
10334 && !strcmp(peer->conf_if, conf_if))
10335 || (peer->hostname
10336 && !strcmp(peer->hostname, conf_if))) {
10337 find = 1;
10338 bgp_show_peer(vty, peer, use_json,
10339 json);
10340 }
10341 } else {
10342 if (sockunion_same(&peer->su, su)) {
10343 find = 1;
10344 bgp_show_peer(vty, peer, use_json,
10345 json);
10346 }
10347 }
10348 break;
10349 }
10350 }
10351
10352 if (type == show_peer && !find) {
10353 if (use_json)
10354 json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
10355 else
10356 vty_out(vty, "%% No such neighbor\n");
10357 }
10358
10359 if (use_json) {
996c9314
LB
10360 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10361 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 10362 json_object_free(json);
10363 } else {
10364 vty_out(vty, "\n");
10365 }
10366
10367 return CMD_SUCCESS;
10368}
10369
10370static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
71aedaa3
DS
10371 enum show_type type,
10372 const char *ip_str,
d62a17ae 10373 u_char use_json)
10374{
0291c246
MK
10375 struct listnode *node, *nnode;
10376 struct bgp *bgp;
71aedaa3 10377 union sockunion su;
0291c246 10378 json_object *json = NULL;
71aedaa3 10379 int ret, is_first = 1;
d62a17ae 10380
10381 if (use_json)
10382 vty_out(vty, "{\n");
10383
10384 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10385 if (use_json) {
10386 if (!(json = json_object_new_object())) {
10387 zlog_err(
10388 "Unable to allocate memory for JSON object");
10389 vty_out(vty,
10390 "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
10391 return;
10392 }
10393
10394 json_object_int_add(json, "vrfId",
10395 (bgp->vrf_id == VRF_UNKNOWN)
a4d82a8a
PZ
10396 ? -1
10397 : (int64_t)bgp->vrf_id);
d62a17ae 10398 json_object_string_add(
10399 json, "vrfName",
10400 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10401 ? "Default"
10402 : bgp->name);
10403
10404 if (!is_first)
10405 vty_out(vty, ",\n");
10406 else
10407 is_first = 0;
10408
10409 vty_out(vty, "\"%s\":",
10410 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10411 ? "Default"
10412 : bgp->name);
10413 } else {
10414 vty_out(vty, "\nInstance %s:\n",
10415 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10416 ? "Default"
10417 : bgp->name);
10418 }
71aedaa3
DS
10419
10420 if (type == show_peer) {
10421 ret = str2sockunion(ip_str, &su);
10422 if (ret < 0)
10423 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10424 use_json, json);
10425 else
10426 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10427 use_json, json);
10428 } else {
10429 bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
10430 use_json, json);
10431 }
d62a17ae 10432 }
10433
10434 if (use_json)
10435 vty_out(vty, "}\n");
10436}
10437
10438static int bgp_show_neighbor_vty(struct vty *vty, const char *name,
10439 enum show_type type, const char *ip_str,
10440 u_char use_json)
10441{
10442 int ret;
10443 struct bgp *bgp;
10444 union sockunion su;
10445 json_object *json = NULL;
10446
10447 if (name) {
10448 if (strmatch(name, "all")) {
71aedaa3
DS
10449 bgp_show_all_instances_neighbors_vty(vty, type, ip_str,
10450 use_json);
d62a17ae 10451 return CMD_SUCCESS;
10452 } else {
10453 bgp = bgp_lookup_by_name(name);
10454 if (!bgp) {
10455 if (use_json) {
10456 json = json_object_new_object();
10457 json_object_boolean_true_add(
10458 json, "bgpNoSuchInstance");
10459 vty_out(vty, "%s\n",
10460 json_object_to_json_string_ext(
10461 json,
10462 JSON_C_TO_STRING_PRETTY));
10463 json_object_free(json);
10464 } else
10465 vty_out(vty,
10466 "%% No such BGP instance exist\n");
10467
10468 return CMD_WARNING;
10469 }
10470 }
10471 } else {
10472 bgp = bgp_get_default();
10473 }
10474
10475 if (bgp) {
10476 json = json_object_new_object();
10477 if (ip_str) {
10478 ret = str2sockunion(ip_str, &su);
10479 if (ret < 0)
10480 bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
10481 use_json, json);
10482 else
10483 bgp_show_neighbor(vty, bgp, type, &su, NULL,
10484 use_json, json);
10485 } else {
10486 bgp_show_neighbor(vty, bgp, type, NULL, NULL, use_json,
10487 json);
10488 }
10489 json_object_free(json);
10490 }
10491
10492 return CMD_SUCCESS;
4fb25c53
DW
10493}
10494
716b2d8a 10495/* "show [ip] bgp neighbors" commands. */
718e3744 10496DEFUN (show_ip_bgp_neighbors,
10497 show_ip_bgp_neighbors_cmd,
24345e82 10498 "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
718e3744 10499 SHOW_STR
10500 IP_STR
10501 BGP_STR
f2a8972b 10502 BGP_INSTANCE_HELP_STR
8c3deaae
QY
10503 "Address Family\n"
10504 "Address Family\n"
718e3744 10505 "Detailed information on TCP and BGP neighbor connections\n"
10506 "Neighbor to display information about\n"
a80beece 10507 "Neighbor to display information about\n"
91d37724 10508 "Neighbor on BGP configured interface\n"
9973d184 10509 JSON_STR)
718e3744 10510{
d62a17ae 10511 char *vrf = NULL;
10512 char *sh_arg = NULL;
10513 enum show_type sh_type;
718e3744 10514
d62a17ae 10515 u_char uj = use_json(argc, argv);
718e3744 10516
d62a17ae 10517 int idx = 0;
718e3744 10518
d62a17ae 10519 if (argv_find(argv, argc, "view", &idx)
10520 || argv_find(argv, argc, "vrf", &idx))
10521 vrf = argv[idx + 1]->arg;
718e3744 10522
d62a17ae 10523 idx++;
10524 if (argv_find(argv, argc, "A.B.C.D", &idx)
10525 || argv_find(argv, argc, "X:X::X:X", &idx)
10526 || argv_find(argv, argc, "WORD", &idx)) {
10527 sh_type = show_peer;
10528 sh_arg = argv[idx]->arg;
10529 } else
10530 sh_type = show_all;
856ca177 10531
d62a17ae 10532 return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
718e3744 10533}
10534
716b2d8a 10535/* Show BGP's AS paths internal data. There are both `show [ip] bgp
718e3744 10536 paths' and `show ip mbgp paths'. Those functions results are the
10537 same.*/
f412b39a 10538DEFUN (show_ip_bgp_paths,
718e3744 10539 show_ip_bgp_paths_cmd,
46f296b4 10540 "show [ip] bgp ["BGP_SAFI_CMD_STR"] paths",
718e3744 10541 SHOW_STR
10542 IP_STR
10543 BGP_STR
46f296b4 10544 BGP_SAFI_HELP_STR
718e3744 10545 "Path information\n")
10546{
d62a17ae 10547 vty_out(vty, "Address Refcnt Path\n");
10548 aspath_print_all_vty(vty);
10549 return CMD_SUCCESS;
718e3744 10550}
10551
718e3744 10552#include "hash.h"
10553
d62a17ae 10554static void community_show_all_iterator(struct hash_backet *backet,
10555 struct vty *vty)
718e3744 10556{
d62a17ae 10557 struct community *com;
718e3744 10558
d62a17ae 10559 com = (struct community *)backet->data;
3f65c5b1 10560 vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
a69ea8ae 10561 community_str(com, false));
718e3744 10562}
10563
10564/* Show BGP's community internal data. */
f412b39a 10565DEFUN (show_ip_bgp_community_info,
718e3744 10566 show_ip_bgp_community_info_cmd,
bec37ba5 10567 "show [ip] bgp community-info",
718e3744 10568 SHOW_STR
10569 IP_STR
10570 BGP_STR
10571 "List all bgp community information\n")
10572{
d62a17ae 10573 vty_out(vty, "Address Refcnt Community\n");
718e3744 10574
d62a17ae 10575 hash_iterate(community_hash(),
10576 (void (*)(struct hash_backet *,
10577 void *))community_show_all_iterator,
10578 vty);
718e3744 10579
d62a17ae 10580 return CMD_SUCCESS;
718e3744 10581}
10582
d62a17ae 10583static void lcommunity_show_all_iterator(struct hash_backet *backet,
10584 struct vty *vty)
57d187bc 10585{
d62a17ae 10586 struct lcommunity *lcom;
57d187bc 10587
d62a17ae 10588 lcom = (struct lcommunity *)backet->data;
3f65c5b1 10589 vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
d62a17ae 10590 lcommunity_str(lcom));
57d187bc
JS
10591}
10592
10593/* Show BGP's community internal data. */
10594DEFUN (show_ip_bgp_lcommunity_info,
10595 show_ip_bgp_lcommunity_info_cmd,
10596 "show ip bgp large-community-info",
10597 SHOW_STR
10598 IP_STR
10599 BGP_STR
10600 "List all bgp large-community information\n")
10601{
d62a17ae 10602 vty_out(vty, "Address Refcnt Large-community\n");
57d187bc 10603
d62a17ae 10604 hash_iterate(lcommunity_hash(),
10605 (void (*)(struct hash_backet *,
10606 void *))lcommunity_show_all_iterator,
10607 vty);
57d187bc 10608
d62a17ae 10609 return CMD_SUCCESS;
57d187bc
JS
10610}
10611
10612
f412b39a 10613DEFUN (show_ip_bgp_attr_info,
718e3744 10614 show_ip_bgp_attr_info_cmd,
bec37ba5 10615 "show [ip] bgp attribute-info",
718e3744 10616 SHOW_STR
10617 IP_STR
10618 BGP_STR
10619 "List all bgp attribute information\n")
10620{
d62a17ae 10621 attr_show_all(vty);
10622 return CMD_SUCCESS;
718e3744 10623}
6b0655a2 10624
d62a17ae 10625static void bgp_show_all_instances_updgrps_vty(struct vty *vty, afi_t afi,
10626 safi_t safi)
f186de26 10627{
d62a17ae 10628 struct listnode *node, *nnode;
10629 struct bgp *bgp;
f186de26 10630
d62a17ae 10631 for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
10632 vty_out(vty, "\nInstance %s:\n",
10633 (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
10634 ? "Default"
10635 : bgp->name);
10636 update_group_show(bgp, afi, safi, vty, 0);
10637 }
f186de26 10638}
10639
d62a17ae 10640static int bgp_show_update_groups(struct vty *vty, const char *name, int afi,
10641 int safi, uint64_t subgrp_id)
4fb25c53 10642{
d62a17ae 10643 struct bgp *bgp;
4fb25c53 10644
d62a17ae 10645 if (name) {
10646 if (strmatch(name, "all")) {
10647 bgp_show_all_instances_updgrps_vty(vty, afi, safi);
10648 return CMD_SUCCESS;
10649 } else {
10650 bgp = bgp_lookup_by_name(name);
10651 }
10652 } else {
10653 bgp = bgp_get_default();
10654 }
4fb25c53 10655
d62a17ae 10656 if (bgp)
10657 update_group_show(bgp, afi, safi, vty, subgrp_id);
10658 return CMD_SUCCESS;
4fb25c53
DW
10659}
10660
8fe8a7f6
DS
10661DEFUN (show_ip_bgp_updgrps,
10662 show_ip_bgp_updgrps_cmd,
c1a44e43 10663 "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] update-groups [SUBGROUP-ID]",
8386ac43 10664 SHOW_STR
10665 IP_STR
10666 BGP_STR
10667 BGP_INSTANCE_HELP_STR
c9e571b4 10668 BGP_AFI_HELP_STR
9bedbb1e 10669 BGP_SAFI_WITH_LABEL_HELP_STR
5bf15956
DW
10670 "Detailed info about dynamic update groups\n"
10671 "Specific subgroup to display detailed info for\n")
8386ac43 10672{
d62a17ae 10673 char *vrf = NULL;
10674 afi_t afi = AFI_IP6;
10675 safi_t safi = SAFI_UNICAST;
10676 uint64_t subgrp_id = 0;
10677
10678 int idx = 0;
10679
10680 /* show [ip] bgp */
10681 if (argv_find(argv, argc, "ip", &idx))
10682 afi = AFI_IP;
10683 /* [<view|vrf> VIEWVRFNAME] */
10684 if (argv_find(argv, argc, "view", &idx)
10685 || argv_find(argv, argc, "vrf", &idx))
10686 vrf = argv[++idx]->arg;
10687 /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
10688 if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
10689 argv_find_and_parse_safi(argv, argc, &idx, &safi);
10690 }
5bf15956 10691
d62a17ae 10692 /* get subgroup id, if provided */
10693 idx = argc - 1;
10694 if (argv[idx]->type == VARIABLE_TKN)
10695 subgrp_id = strtoull(argv[idx]->arg, NULL, 10);
5bf15956 10696
d62a17ae 10697 return (bgp_show_update_groups(vty, vrf, afi, safi, subgrp_id));
8fe8a7f6
DS
10698}
10699
f186de26 10700DEFUN (show_bgp_instance_all_ipv6_updgrps,
10701 show_bgp_instance_all_ipv6_updgrps_cmd,
716b2d8a 10702 "show [ip] bgp <view|vrf> all update-groups",
f186de26 10703 SHOW_STR
716b2d8a 10704 IP_STR
f186de26 10705 BGP_STR
10706 BGP_INSTANCE_ALL_HELP_STR
0c7b1b01 10707 "Detailed info about dynamic update groups\n")
f186de26 10708{
d62a17ae 10709 bgp_show_all_instances_updgrps_vty(vty, AFI_IP6, SAFI_UNICAST);
10710 return CMD_SUCCESS;
f186de26 10711}
10712
5bf15956
DW
10713DEFUN (show_bgp_updgrps_stats,
10714 show_bgp_updgrps_stats_cmd,
716b2d8a 10715 "show [ip] bgp update-groups statistics",
3f9c7369 10716 SHOW_STR
716b2d8a 10717 IP_STR
3f9c7369 10718 BGP_STR
0c7b1b01 10719 "Detailed info about dynamic update groups\n"
3f9c7369
DS
10720 "Statistics\n")
10721{
d62a17ae 10722 struct bgp *bgp;
3f9c7369 10723
d62a17ae 10724 bgp = bgp_get_default();
10725 if (bgp)
10726 update_group_show_stats(bgp, vty);
3f9c7369 10727
d62a17ae 10728 return CMD_SUCCESS;
3f9c7369
DS
10729}
10730
8386ac43 10731DEFUN (show_bgp_instance_updgrps_stats,
10732 show_bgp_instance_updgrps_stats_cmd,
18c57037 10733 "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
8386ac43 10734 SHOW_STR
716b2d8a 10735 IP_STR
8386ac43 10736 BGP_STR
10737 BGP_INSTANCE_HELP_STR
0c7b1b01 10738 "Detailed info about dynamic update groups\n"
8386ac43 10739 "Statistics\n")
10740{
d62a17ae 10741 int idx_word = 3;
10742 struct bgp *bgp;
8386ac43 10743
d62a17ae 10744 bgp = bgp_lookup_by_name(argv[idx_word]->arg);
10745 if (bgp)
10746 update_group_show_stats(bgp, vty);
8386ac43 10747
d62a17ae 10748 return CMD_SUCCESS;
8386ac43 10749}
10750
d62a17ae 10751static void show_bgp_updgrps_adj_info_aux(struct vty *vty, const char *name,
10752 afi_t afi, safi_t safi,
10753 const char *what, uint64_t subgrp_id)
3f9c7369 10754{
d62a17ae 10755 struct bgp *bgp;
8386ac43 10756
d62a17ae 10757 if (name)
10758 bgp = bgp_lookup_by_name(name);
10759 else
10760 bgp = bgp_get_default();
8386ac43 10761
d62a17ae 10762 if (bgp) {
10763 if (!strcmp(what, "advertise-queue"))
10764 update_group_show_adj_queue(bgp, afi, safi, vty,
10765 subgrp_id);
10766 else if (!strcmp(what, "advertised-routes"))
10767 update_group_show_advertised(bgp, afi, safi, vty,
10768 subgrp_id);
10769 else if (!strcmp(what, "packet-queue"))
10770 update_group_show_packet_queue(bgp, afi, safi, vty,
10771 subgrp_id);
10772 }
3f9c7369
DS
10773}
10774
dc64bdec
QY
10775DEFPY(show_ip_bgp_instance_updgrps_adj_s,
10776 show_ip_bgp_instance_updgrps_adj_s_cmd,
10777 "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",
10778 SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
10779 BGP_SAFI_HELP_STR
10780 "Detailed info about dynamic update groups\n"
10781 "Specific subgroup to display info for\n"
10782 "Advertisement queue\n"
10783 "Announced routes\n"
10784 "Packet queue\n")
3f9c7369 10785{
dc64bdec
QY
10786 uint64_t subgrp_id = 0;
10787 afi_t afiz;
10788 safi_t safiz;
10789 if (sgid)
10790 subgrp_id = strtoull(sgid, NULL, 10);
10791
10792 if (!ip && !afi)
10793 afiz = AFI_IP6;
10794 if (!ip && afi)
10795 afiz = bgp_vty_afi_from_str(afi);
10796 if (ip && !afi)
10797 afiz = AFI_IP;
10798 if (ip && afi) {
10799 afiz = bgp_vty_afi_from_str(afi);
10800 if (afiz != AFI_IP)
10801 vty_out(vty,
10802 "%% Cannot specify both 'ip' and 'ipv6'\n");
10803 return CMD_WARNING;
10804 }
d62a17ae 10805
dc64bdec 10806 safiz = safi ? bgp_vty_safi_from_str(safi) : SAFI_UNICAST;
d62a17ae 10807
dc64bdec 10808 show_bgp_updgrps_adj_info_aux(vty, vrf, afiz, safiz, rtq, subgrp_id);
d62a17ae 10809 return CMD_SUCCESS;
10810}
10811
d62a17ae 10812static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group)
10813{
10814 struct listnode *node, *nnode;
10815 struct prefix *range;
10816 struct peer *conf;
10817 struct peer *peer;
10818 char buf[PREFIX2STR_BUFFER];
10819 afi_t afi;
10820 safi_t safi;
10821 const char *peer_status;
10822 const char *af_str;
10823 int lr_count;
10824 int dynamic;
10825 int af_cfgd;
10826
10827 conf = group->conf;
10828
10829 if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
10830 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10831 conf->as);
10832 } else if (conf->as_type == AS_INTERNAL) {
10833 vty_out(vty, "\nBGP peer-group %s, remote AS %d\n", group->name,
10834 group->bgp->as);
10835 } else {
10836 vty_out(vty, "\nBGP peer-group %s\n", group->name);
10837 }
f14e6fdb 10838
d62a17ae 10839 if ((group->bgp->as == conf->as) || (conf->as_type == AS_INTERNAL))
10840 vty_out(vty, " Peer-group type is internal\n");
10841 else
10842 vty_out(vty, " Peer-group type is external\n");
10843
10844 /* Display AFs configured. */
10845 vty_out(vty, " Configured address-families:");
05c7a1cc
QY
10846 FOREACH_AFI_SAFI (afi, safi) {
10847 if (conf->afc[afi][safi]) {
10848 af_cfgd = 1;
10849 vty_out(vty, " %s;", afi_safi_print(afi, safi));
d62a17ae 10850 }
05c7a1cc 10851 }
d62a17ae 10852 if (!af_cfgd)
10853 vty_out(vty, " none\n");
10854 else
10855 vty_out(vty, "\n");
10856
10857 /* Display listen ranges (for dynamic neighbors), if any */
10858 for (afi = AFI_IP; afi < AFI_MAX; afi++) {
10859 if (afi == AFI_IP)
10860 af_str = "IPv4";
10861 else if (afi == AFI_IP6)
10862 af_str = "IPv6";
10863 else
10864 af_str = "???";
10865 lr_count = listcount(group->listen_range[afi]);
10866 if (lr_count) {
10867 vty_out(vty, " %d %s listen range(s)\n", lr_count,
10868 af_str);
10869
10870
10871 for (ALL_LIST_ELEMENTS(group->listen_range[afi], node,
10872 nnode, range)) {
10873 prefix2str(range, buf, sizeof(buf));
10874 vty_out(vty, " %s\n", buf);
10875 }
10876 }
10877 }
f14e6fdb 10878
d62a17ae 10879 /* Display group members and their status */
10880 if (listcount(group->peer)) {
10881 vty_out(vty, " Peer-group members:\n");
10882 for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
10883 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
10884 peer_status = "Idle (Admin)";
10885 else if (CHECK_FLAG(peer->sflags,
10886 PEER_STATUS_PREFIX_OVERFLOW))
10887 peer_status = "Idle (PfxCt)";
10888 else
10889 peer_status = lookup_msg(bgp_status_msg,
10890 peer->status, NULL);
10891
10892 dynamic = peer_dynamic_neighbor(peer);
10893 vty_out(vty, " %s %s %s \n", peer->host,
10894 dynamic ? "(dynamic)" : "", peer_status);
10895 }
10896 }
f14e6fdb 10897
d62a17ae 10898 return CMD_SUCCESS;
10899}
10900
ff9959b0
QY
10901static int bgp_show_peer_group_vty(struct vty *vty, const char *name,
10902 const char *group_name)
d62a17ae 10903{
ff9959b0 10904 struct bgp *bgp;
d62a17ae 10905 struct listnode *node, *nnode;
10906 struct peer_group *group;
ff9959b0
QY
10907 bool found = false;
10908
10909 bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();
10910
10911 if (!bgp) {
10912 vty_out(vty, "%% No such BGP instance exists\n");
10913 return CMD_WARNING;
10914 }
d62a17ae 10915
10916 for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
ff9959b0
QY
10917 if (group_name) {
10918 if (strmatch(group->name, group_name)) {
d62a17ae 10919 bgp_show_one_peer_group(vty, group);
ff9959b0
QY
10920 found = true;
10921 break;
d62a17ae 10922 }
ff9959b0
QY
10923 } else {
10924 bgp_show_one_peer_group(vty, group);
d62a17ae 10925 }
f14e6fdb 10926 }
f14e6fdb 10927
ff9959b0 10928 if (group_name && !found)
d62a17ae 10929 vty_out(vty, "%% No such peer-group\n");
f14e6fdb 10930
d62a17ae 10931 return CMD_SUCCESS;
f14e6fdb
DS
10932}
10933
f14e6fdb
DS
10934DEFUN (show_ip_bgp_peer_groups,
10935 show_ip_bgp_peer_groups_cmd,
18c57037 10936 "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
f14e6fdb
DS
10937 SHOW_STR
10938 IP_STR
10939 BGP_STR
8386ac43 10940 BGP_INSTANCE_HELP_STR
d6e3c605
QY
10941 "Detailed information on BGP peer groups\n"
10942 "Peer group name\n")
f14e6fdb 10943{
d62a17ae 10944 char *vrf, *pg;
10945 vrf = pg = NULL;
10946 int idx = 0;
f14e6fdb 10947
a4d82a8a
PZ
10948 vrf = argv_find(argv, argc, "VIEWVRFNAME", &idx) ? argv[idx]->arg
10949 : NULL;
d62a17ae 10950 pg = argv_find(argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL;
f14e6fdb 10951
ff9959b0 10952 return bgp_show_peer_group_vty(vty, vrf, pg);
f14e6fdb 10953}
3f9c7369 10954
d6e3c605 10955
718e3744 10956/* Redistribute VTY commands. */
10957
718e3744 10958DEFUN (bgp_redistribute_ipv4,
10959 bgp_redistribute_ipv4_cmd,
40d1cbfb 10960 "redistribute " FRR_IP_REDIST_STR_BGPD,
718e3744 10961 "Redistribute information from another routing protocol\n"
ab0181ee 10962 FRR_IP_REDIST_HELP_STR_BGPD)
718e3744 10963{
d62a17ae 10964 VTY_DECLVAR_CONTEXT(bgp, bgp);
10965 int idx_protocol = 1;
10966 int type;
718e3744 10967
d62a17ae 10968 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10969 if (type < 0) {
10970 vty_out(vty, "%% Invalid route type\n");
10971 return CMD_WARNING_CONFIG_FAILED;
10972 }
7f323236 10973
d62a17ae 10974 bgp_redist_add(bgp, AFI_IP, type, 0);
10975 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 10976}
10977
d62a17ae 10978ALIAS_HIDDEN(
10979 bgp_redistribute_ipv4, bgp_redistribute_ipv4_hidden_cmd,
10980 "redistribute " FRR_IP_REDIST_STR_BGPD,
10981 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD)
596c17ba 10982
718e3744 10983DEFUN (bgp_redistribute_ipv4_rmap,
10984 bgp_redistribute_ipv4_rmap_cmd,
40d1cbfb 10985 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
718e3744 10986 "Redistribute information from another routing protocol\n"
ab0181ee 10987 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 10988 "Route map reference\n"
10989 "Pointer to route-map entries\n")
10990{
d62a17ae 10991 VTY_DECLVAR_CONTEXT(bgp, bgp);
10992 int idx_protocol = 1;
10993 int idx_word = 3;
10994 int type;
10995 struct bgp_redist *red;
718e3744 10996
d62a17ae 10997 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
10998 if (type < 0) {
10999 vty_out(vty, "%% Invalid route type\n");
11000 return CMD_WARNING_CONFIG_FAILED;
11001 }
718e3744 11002
d62a17ae 11003 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11004 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11005 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
718e3744 11006}
11007
d62a17ae 11008ALIAS_HIDDEN(
11009 bgp_redistribute_ipv4_rmap, bgp_redistribute_ipv4_rmap_hidden_cmd,
11010 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD",
11011 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11012 "Route map reference\n"
11013 "Pointer to route-map entries\n")
596c17ba 11014
718e3744 11015DEFUN (bgp_redistribute_ipv4_metric,
11016 bgp_redistribute_ipv4_metric_cmd,
40d1cbfb 11017 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11018 "Redistribute information from another routing protocol\n"
ab0181ee 11019 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11020 "Metric for redistributed routes\n"
11021 "Default metric\n")
11022{
d62a17ae 11023 VTY_DECLVAR_CONTEXT(bgp, bgp);
11024 int idx_protocol = 1;
11025 int idx_number = 3;
11026 int type;
11027 u_int32_t metric;
11028 struct bgp_redist *red;
11029
11030 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11031 if (type < 0) {
11032 vty_out(vty, "%% Invalid route type\n");
11033 return CMD_WARNING_CONFIG_FAILED;
11034 }
11035 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11036
11037 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11038 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11039 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11040}
11041
11042ALIAS_HIDDEN(
11043 bgp_redistribute_ipv4_metric, bgp_redistribute_ipv4_metric_hidden_cmd,
11044 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295)",
11045 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11046 "Metric for redistributed routes\n"
11047 "Default metric\n")
596c17ba 11048
718e3744 11049DEFUN (bgp_redistribute_ipv4_rmap_metric,
11050 bgp_redistribute_ipv4_rmap_metric_cmd,
40d1cbfb 11051 "redistribute " FRR_IP_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11052 "Redistribute information from another routing protocol\n"
ab0181ee 11053 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11054 "Route map reference\n"
11055 "Pointer to route-map entries\n"
11056 "Metric for redistributed routes\n"
11057 "Default metric\n")
11058{
d62a17ae 11059 VTY_DECLVAR_CONTEXT(bgp, bgp);
11060 int idx_protocol = 1;
11061 int idx_word = 3;
11062 int idx_number = 5;
11063 int type;
11064 u_int32_t metric;
11065 struct bgp_redist *red;
11066
11067 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11068 if (type < 0) {
11069 vty_out(vty, "%% Invalid route type\n");
11070 return CMD_WARNING_CONFIG_FAILED;
11071 }
11072 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11073
11074 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11075 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11076 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11077 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11078}
11079
11080ALIAS_HIDDEN(
11081 bgp_redistribute_ipv4_rmap_metric,
11082 bgp_redistribute_ipv4_rmap_metric_hidden_cmd,
11083 "redistribute " FRR_IP_REDIST_STR_BGPD
11084 " route-map WORD metric (0-4294967295)",
11085 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11086 "Route map reference\n"
11087 "Pointer to route-map entries\n"
11088 "Metric for redistributed routes\n"
11089 "Default metric\n")
596c17ba 11090
718e3744 11091DEFUN (bgp_redistribute_ipv4_metric_rmap,
11092 bgp_redistribute_ipv4_metric_rmap_cmd,
40d1cbfb 11093 "redistribute " FRR_IP_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11094 "Redistribute information from another routing protocol\n"
ab0181ee 11095 FRR_IP_REDIST_HELP_STR_BGPD
718e3744 11096 "Metric for redistributed routes\n"
11097 "Default metric\n"
11098 "Route map reference\n"
11099 "Pointer to route-map entries\n")
11100{
d62a17ae 11101 VTY_DECLVAR_CONTEXT(bgp, bgp);
11102 int idx_protocol = 1;
11103 int idx_number = 3;
11104 int idx_word = 5;
11105 int type;
11106 u_int32_t metric;
11107 struct bgp_redist *red;
11108
11109 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11110 if (type < 0) {
11111 vty_out(vty, "%% Invalid route type\n");
11112 return CMD_WARNING_CONFIG_FAILED;
11113 }
11114 metric = strtoul(argv[idx_number]->arg, NULL, 10);
11115
11116 red = bgp_redist_add(bgp, AFI_IP, type, 0);
11117 bgp_redistribute_metric_set(bgp, red, AFI_IP, type, metric);
11118 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11119 return bgp_redistribute_set(bgp, AFI_IP, type, 0);
11120}
11121
11122ALIAS_HIDDEN(
11123 bgp_redistribute_ipv4_metric_rmap,
11124 bgp_redistribute_ipv4_metric_rmap_hidden_cmd,
11125 "redistribute " FRR_IP_REDIST_STR_BGPD
11126 " metric (0-4294967295) route-map WORD",
11127 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11128 "Metric for redistributed routes\n"
11129 "Default metric\n"
11130 "Route map reference\n"
11131 "Pointer to route-map entries\n")
596c17ba 11132
7c8ff89e
DS
11133DEFUN (bgp_redistribute_ipv4_ospf,
11134 bgp_redistribute_ipv4_ospf_cmd,
6147e2c6 11135 "redistribute <ospf|table> (1-65535)",
7c8ff89e
DS
11136 "Redistribute information from another routing protocol\n"
11137 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11138 "Non-main Kernel Routing Table\n"
11139 "Instance ID/Table ID\n")
7c8ff89e 11140{
d62a17ae 11141 VTY_DECLVAR_CONTEXT(bgp, bgp);
11142 int idx_ospf_table = 1;
11143 int idx_number = 2;
11144 u_short instance;
11145 u_short protocol;
7c8ff89e 11146
d62a17ae 11147 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7a4bb9c5 11148
d62a17ae 11149 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11150 protocol = ZEBRA_ROUTE_OSPF;
11151 else
11152 protocol = ZEBRA_ROUTE_TABLE;
7a4bb9c5 11153
d62a17ae 11154 bgp_redist_add(bgp, AFI_IP, protocol, instance);
11155 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
7c8ff89e
DS
11156}
11157
d62a17ae 11158ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
11159 "redistribute <ospf|table> (1-65535)",
11160 "Redistribute information from another routing protocol\n"
11161 "Open Shortest Path First (OSPFv2)\n"
11162 "Non-main Kernel Routing Table\n"
11163 "Instance ID/Table ID\n")
596c17ba 11164
7c8ff89e
DS
11165DEFUN (bgp_redistribute_ipv4_ospf_rmap,
11166 bgp_redistribute_ipv4_ospf_rmap_cmd,
6147e2c6 11167 "redistribute <ospf|table> (1-65535) route-map WORD",
7c8ff89e
DS
11168 "Redistribute information from another routing protocol\n"
11169 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11170 "Non-main Kernel Routing Table\n"
11171 "Instance ID/Table ID\n"
7c8ff89e
DS
11172 "Route map reference\n"
11173 "Pointer to route-map entries\n")
11174{
d62a17ae 11175 VTY_DECLVAR_CONTEXT(bgp, bgp);
11176 int idx_ospf_table = 1;
11177 int idx_number = 2;
11178 int idx_word = 4;
11179 struct bgp_redist *red;
11180 u_short instance;
11181 int protocol;
11182
11183 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11184 protocol = ZEBRA_ROUTE_OSPF;
11185 else
11186 protocol = ZEBRA_ROUTE_TABLE;
11187
11188 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11189 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11190 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11191 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11192}
11193
11194ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
11195 bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
11196 "redistribute <ospf|table> (1-65535) route-map WORD",
11197 "Redistribute information from another routing protocol\n"
11198 "Open Shortest Path First (OSPFv2)\n"
11199 "Non-main Kernel Routing Table\n"
11200 "Instance ID/Table ID\n"
11201 "Route map reference\n"
11202 "Pointer to route-map entries\n")
596c17ba 11203
7c8ff89e
DS
11204DEFUN (bgp_redistribute_ipv4_ospf_metric,
11205 bgp_redistribute_ipv4_ospf_metric_cmd,
6147e2c6 11206 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
7c8ff89e
DS
11207 "Redistribute information from another routing protocol\n"
11208 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11209 "Non-main Kernel Routing Table\n"
11210 "Instance ID/Table ID\n"
7c8ff89e
DS
11211 "Metric for redistributed routes\n"
11212 "Default metric\n")
11213{
d62a17ae 11214 VTY_DECLVAR_CONTEXT(bgp, bgp);
11215 int idx_ospf_table = 1;
11216 int idx_number = 2;
11217 int idx_number_2 = 4;
11218 u_int32_t metric;
11219 struct bgp_redist *red;
11220 u_short instance;
11221 int protocol;
11222
11223 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11224 protocol = ZEBRA_ROUTE_OSPF;
11225 else
11226 protocol = ZEBRA_ROUTE_TABLE;
11227
11228 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11229 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11230
11231 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11232 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11233 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11234}
11235
11236ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
11237 bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
11238 "redistribute <ospf|table> (1-65535) metric (0-4294967295)",
11239 "Redistribute information from another routing protocol\n"
11240 "Open Shortest Path First (OSPFv2)\n"
11241 "Non-main Kernel Routing Table\n"
11242 "Instance ID/Table ID\n"
11243 "Metric for redistributed routes\n"
11244 "Default metric\n")
596c17ba 11245
7c8ff89e
DS
11246DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
11247 bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
6147e2c6 11248 "redistribute <ospf|table> (1-65535) route-map WORD metric (0-4294967295)",
7c8ff89e
DS
11249 "Redistribute information from another routing protocol\n"
11250 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11251 "Non-main Kernel Routing Table\n"
11252 "Instance ID/Table ID\n"
7c8ff89e
DS
11253 "Route map reference\n"
11254 "Pointer to route-map entries\n"
11255 "Metric for redistributed routes\n"
11256 "Default metric\n")
11257{
d62a17ae 11258 VTY_DECLVAR_CONTEXT(bgp, bgp);
11259 int idx_ospf_table = 1;
11260 int idx_number = 2;
11261 int idx_word = 4;
11262 int idx_number_2 = 6;
11263 u_int32_t metric;
11264 struct bgp_redist *red;
11265 u_short instance;
11266 int protocol;
11267
11268 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11269 protocol = ZEBRA_ROUTE_OSPF;
11270 else
11271 protocol = ZEBRA_ROUTE_TABLE;
11272
11273 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11274 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11275
11276 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11277 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11278 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11279 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11280}
11281
11282ALIAS_HIDDEN(
11283 bgp_redistribute_ipv4_ospf_rmap_metric,
11284 bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
11285 "redistribute <ospf|table> (1-65535) route-map WORD 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 "Route map reference\n"
11291 "Pointer to route-map entries\n"
11292 "Metric for redistributed routes\n"
11293 "Default metric\n")
596c17ba 11294
7c8ff89e
DS
11295DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
11296 bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
6147e2c6 11297 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
7c8ff89e
DS
11298 "Redistribute information from another routing protocol\n"
11299 "Open Shortest Path First (OSPFv2)\n"
2d627ff5
DS
11300 "Non-main Kernel Routing Table\n"
11301 "Instance ID/Table ID\n"
7c8ff89e
DS
11302 "Metric for redistributed routes\n"
11303 "Default metric\n"
11304 "Route map reference\n"
11305 "Pointer to route-map entries\n")
11306{
d62a17ae 11307 VTY_DECLVAR_CONTEXT(bgp, bgp);
11308 int idx_ospf_table = 1;
11309 int idx_number = 2;
11310 int idx_number_2 = 4;
11311 int idx_word = 6;
11312 u_int32_t metric;
11313 struct bgp_redist *red;
11314 u_short instance;
11315 int protocol;
11316
11317 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11318 protocol = ZEBRA_ROUTE_OSPF;
11319 else
11320 protocol = ZEBRA_ROUTE_TABLE;
11321
11322 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11323 metric = strtoul(argv[idx_number_2]->arg, NULL, 10);
11324
11325 red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
11326 bgp_redistribute_metric_set(bgp, red, AFI_IP, protocol, metric);
11327 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11328 return bgp_redistribute_set(bgp, AFI_IP, protocol, instance);
11329}
11330
11331ALIAS_HIDDEN(
11332 bgp_redistribute_ipv4_ospf_metric_rmap,
11333 bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
11334 "redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map WORD",
11335 "Redistribute information from another routing protocol\n"
11336 "Open Shortest Path First (OSPFv2)\n"
11337 "Non-main Kernel Routing Table\n"
11338 "Instance ID/Table ID\n"
11339 "Metric for redistributed routes\n"
11340 "Default metric\n"
11341 "Route map reference\n"
11342 "Pointer to route-map entries\n")
596c17ba 11343
7c8ff89e
DS
11344DEFUN (no_bgp_redistribute_ipv4_ospf,
11345 no_bgp_redistribute_ipv4_ospf_cmd,
d04c479d 11346 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
7c8ff89e
DS
11347 NO_STR
11348 "Redistribute information from another routing protocol\n"
11349 "Open Shortest Path First (OSPFv2)\n"
2d627ff5 11350 "Non-main Kernel Routing Table\n"
31500417
DW
11351 "Instance ID/Table ID\n"
11352 "Metric for redistributed routes\n"
11353 "Default metric\n"
11354 "Route map reference\n"
11355 "Pointer to route-map entries\n")
7c8ff89e 11356{
d62a17ae 11357 VTY_DECLVAR_CONTEXT(bgp, bgp);
11358 int idx_ospf_table = 2;
11359 int idx_number = 3;
11360 u_short instance;
11361 int protocol;
11362
11363 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
11364 protocol = ZEBRA_ROUTE_OSPF;
11365 else
11366 protocol = ZEBRA_ROUTE_TABLE;
11367
11368 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11369 return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
11370}
11371
11372ALIAS_HIDDEN(
11373 no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
11374 "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
11375 NO_STR
11376 "Redistribute information from another routing protocol\n"
11377 "Open Shortest Path First (OSPFv2)\n"
11378 "Non-main Kernel Routing Table\n"
11379 "Instance ID/Table ID\n"
11380 "Metric for redistributed routes\n"
11381 "Default metric\n"
11382 "Route map reference\n"
11383 "Pointer to route-map entries\n")
596c17ba 11384
718e3744 11385DEFUN (no_bgp_redistribute_ipv4,
11386 no_bgp_redistribute_ipv4_cmd,
40d1cbfb 11387 "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11388 NO_STR
11389 "Redistribute information from another routing protocol\n"
3b14d86e 11390 FRR_IP_REDIST_HELP_STR_BGPD
31500417
DW
11391 "Metric for redistributed routes\n"
11392 "Default metric\n"
11393 "Route map reference\n"
11394 "Pointer to route-map entries\n")
718e3744 11395{
d62a17ae 11396 VTY_DECLVAR_CONTEXT(bgp, bgp);
11397 int idx_protocol = 2;
11398 int type;
11399
11400 type = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
11401 if (type < 0) {
11402 vty_out(vty, "%% Invalid route type\n");
11403 return CMD_WARNING_CONFIG_FAILED;
11404 }
11405 return bgp_redistribute_unset(bgp, AFI_IP, type, 0);
11406}
11407
11408ALIAS_HIDDEN(
11409 no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
11410 "no redistribute " FRR_IP_REDIST_STR_BGPD
11411 " [metric (0-4294967295)] [route-map WORD]",
11412 NO_STR
11413 "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
11414 "Metric for redistributed routes\n"
11415 "Default metric\n"
11416 "Route map reference\n"
11417 "Pointer to route-map entries\n")
596c17ba 11418
718e3744 11419DEFUN (bgp_redistribute_ipv6,
11420 bgp_redistribute_ipv6_cmd,
40d1cbfb 11421 "redistribute " FRR_IP6_REDIST_STR_BGPD,
718e3744 11422 "Redistribute information from another routing protocol\n"
ab0181ee 11423 FRR_IP6_REDIST_HELP_STR_BGPD)
718e3744 11424{
d62a17ae 11425 VTY_DECLVAR_CONTEXT(bgp, bgp);
11426 int idx_protocol = 1;
11427 int type;
718e3744 11428
d62a17ae 11429 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11430 if (type < 0) {
11431 vty_out(vty, "%% Invalid route type\n");
11432 return CMD_WARNING_CONFIG_FAILED;
11433 }
718e3744 11434
d62a17ae 11435 bgp_redist_add(bgp, AFI_IP6, type, 0);
11436 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11437}
11438
11439DEFUN (bgp_redistribute_ipv6_rmap,
11440 bgp_redistribute_ipv6_rmap_cmd,
40d1cbfb 11441 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD",
718e3744 11442 "Redistribute information from another routing protocol\n"
ab0181ee 11443 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11444 "Route map reference\n"
11445 "Pointer to route-map entries\n")
11446{
d62a17ae 11447 VTY_DECLVAR_CONTEXT(bgp, bgp);
11448 int idx_protocol = 1;
11449 int idx_word = 3;
11450 int type;
11451 struct bgp_redist *red;
718e3744 11452
d62a17ae 11453 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11454 if (type < 0) {
11455 vty_out(vty, "%% Invalid route type\n");
11456 return CMD_WARNING_CONFIG_FAILED;
11457 }
718e3744 11458
d62a17ae 11459 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11460 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11461 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11462}
11463
11464DEFUN (bgp_redistribute_ipv6_metric,
11465 bgp_redistribute_ipv6_metric_cmd,
40d1cbfb 11466 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295)",
718e3744 11467 "Redistribute information from another routing protocol\n"
ab0181ee 11468 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11469 "Metric for redistributed routes\n"
11470 "Default metric\n")
11471{
d62a17ae 11472 VTY_DECLVAR_CONTEXT(bgp, bgp);
11473 int idx_protocol = 1;
11474 int idx_number = 3;
11475 int type;
11476 u_int32_t metric;
11477 struct bgp_redist *red;
11478
11479 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11480 if (type < 0) {
11481 vty_out(vty, "%% Invalid route type\n");
11482 return CMD_WARNING_CONFIG_FAILED;
11483 }
11484 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11485
d62a17ae 11486 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11487 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11488 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11489}
11490
11491DEFUN (bgp_redistribute_ipv6_rmap_metric,
11492 bgp_redistribute_ipv6_rmap_metric_cmd,
40d1cbfb 11493 "redistribute " FRR_IP6_REDIST_STR_BGPD " route-map WORD metric (0-4294967295)",
718e3744 11494 "Redistribute information from another routing protocol\n"
ab0181ee 11495 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11496 "Route map reference\n"
11497 "Pointer to route-map entries\n"
11498 "Metric for redistributed routes\n"
11499 "Default metric\n")
11500{
d62a17ae 11501 VTY_DECLVAR_CONTEXT(bgp, bgp);
11502 int idx_protocol = 1;
11503 int idx_word = 3;
11504 int idx_number = 5;
11505 int type;
11506 u_int32_t metric;
11507 struct bgp_redist *red;
11508
11509 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11510 if (type < 0) {
11511 vty_out(vty, "%% Invalid route type\n");
11512 return CMD_WARNING_CONFIG_FAILED;
11513 }
11514 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11515
d62a17ae 11516 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11517 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11518 bgp_redistribute_metric_set(bgp, red, AFI_IP6, type, metric);
11519 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11520}
11521
11522DEFUN (bgp_redistribute_ipv6_metric_rmap,
11523 bgp_redistribute_ipv6_metric_rmap_cmd,
40d1cbfb 11524 "redistribute " FRR_IP6_REDIST_STR_BGPD " metric (0-4294967295) route-map WORD",
718e3744 11525 "Redistribute information from another routing protocol\n"
ab0181ee 11526 FRR_IP6_REDIST_HELP_STR_BGPD
718e3744 11527 "Metric for redistributed routes\n"
11528 "Default metric\n"
11529 "Route map reference\n"
11530 "Pointer to route-map entries\n")
11531{
d62a17ae 11532 VTY_DECLVAR_CONTEXT(bgp, bgp);
11533 int idx_protocol = 1;
11534 int idx_number = 3;
11535 int idx_word = 5;
11536 int type;
11537 u_int32_t metric;
11538 struct bgp_redist *red;
11539
11540 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11541 if (type < 0) {
11542 vty_out(vty, "%% Invalid route type\n");
11543 return CMD_WARNING_CONFIG_FAILED;
11544 }
11545 metric = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 11546
d62a17ae 11547 red = bgp_redist_add(bgp, AFI_IP6, type, 0);
11548 bgp_redistribute_metric_set(bgp, red, AFI_IP6, SAFI_UNICAST, metric);
11549 bgp_redistribute_rmap_set(red, argv[idx_word]->arg);
11550 return bgp_redistribute_set(bgp, AFI_IP6, type, 0);
718e3744 11551}
11552
11553DEFUN (no_bgp_redistribute_ipv6,
11554 no_bgp_redistribute_ipv6_cmd,
40d1cbfb 11555 "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
718e3744 11556 NO_STR
11557 "Redistribute information from another routing protocol\n"
3b14d86e 11558 FRR_IP6_REDIST_HELP_STR_BGPD
31500417
DW
11559 "Metric for redistributed routes\n"
11560 "Default metric\n"
11561 "Route map reference\n"
11562 "Pointer to route-map entries\n")
718e3744 11563{
d62a17ae 11564 VTY_DECLVAR_CONTEXT(bgp, bgp);
11565 int idx_protocol = 2;
11566 int type;
718e3744 11567
d62a17ae 11568 type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text);
11569 if (type < 0) {
11570 vty_out(vty, "%% Invalid route type\n");
11571 return CMD_WARNING_CONFIG_FAILED;
11572 }
718e3744 11573
d62a17ae 11574 return bgp_redistribute_unset(bgp, AFI_IP6, type, 0);
11575}
11576
2b791107 11577void bgp_config_write_redistribute(struct vty *vty, struct bgp *bgp, afi_t afi,
60466a63 11578 safi_t safi)
d62a17ae 11579{
11580 int i;
11581
11582 /* Unicast redistribution only. */
11583 if (safi != SAFI_UNICAST)
2b791107 11584 return;
d62a17ae 11585
11586 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
11587 /* Redistribute BGP does not make sense. */
11588 if (i != ZEBRA_ROUTE_BGP) {
11589 struct list *red_list;
11590 struct listnode *node;
11591 struct bgp_redist *red;
11592
11593 red_list = bgp->redist[afi][i];
11594 if (!red_list)
11595 continue;
11596
11597 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
d62a17ae 11598 /* "redistribute" configuration. */
11599 vty_out(vty, " redistribute %s",
11600 zebra_route_string(i));
11601 if (red->instance)
11602 vty_out(vty, " %d", red->instance);
11603 if (red->redist_metric_flag)
11604 vty_out(vty, " metric %u",
11605 red->redist_metric);
11606 if (red->rmap.name)
11607 vty_out(vty, " route-map %s",
11608 red->rmap.name);
11609 vty_out(vty, "\n");
11610 }
11611 }
11612 }
718e3744 11613}
6b0655a2 11614
b9c7bc5a
PZ
11615/* This is part of the address-family block (unicast only) */
11616void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
ddb5b488
PZ
11617 afi_t afi)
11618{
b9c7bc5a 11619 int indent = 2;
ddb5b488
PZ
11620
11621 if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) {
b9c7bc5a 11622 vty_out(vty, "%*slabel vpn export %u\n", indent, "",
ddb5b488
PZ
11623 bgp->vpn_policy[afi].tovpn_label);
11624 }
11625 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
11626 BGP_VPN_POLICY_TOVPN_RD_SET)) {
11627 char buf[RD_ADDRSTRLEN];
b9c7bc5a 11628 vty_out(vty, "%*srd vpn export %s\n", indent, "",
ddb5b488
PZ
11629 prefix_rd2str(&bgp->vpn_policy[afi].tovpn_rd, buf,
11630 sizeof(buf)));
11631 }
11632 if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
11633 BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
11634
11635 char buf[PREFIX_STRLEN];
11636 if (inet_ntop(bgp->vpn_policy[afi].tovpn_nexthop.family,
11637 &bgp->vpn_policy[afi].tovpn_nexthop.u.prefix, buf,
11638 sizeof(buf))) {
11639
b9c7bc5a
PZ
11640 vty_out(vty, "%*snexthop vpn export %s\n",
11641 indent, "", buf);
ddb5b488
PZ
11642 }
11643 }
11644 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]
11645 && bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]
11646 && ecommunity_cmp(
11647 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
11648 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN])) {
11649
11650 char *b = ecommunity_ecom2str(
11651 bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN],
11652 ECOMMUNITY_FORMAT_ROUTE_MAP, ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 11653 vty_out(vty, "%*srt vpn both %s\n", indent, "", b);
ddb5b488
PZ
11654 XFREE(MTYPE_ECOMMUNITY_STR, b);
11655 } else {
11656 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN]) {
11657 char *b = ecommunity_ecom2str(
11658 bgp->vpn_policy[afi]
11659 .rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
11660 ECOMMUNITY_FORMAT_ROUTE_MAP,
11661 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 11662 vty_out(vty, "%*srt vpn import %s\n", indent, "", b);
ddb5b488
PZ
11663 XFREE(MTYPE_ECOMMUNITY_STR, b);
11664 }
11665 if (bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) {
11666 char *b = ecommunity_ecom2str(
11667 bgp->vpn_policy[afi]
11668 .rtlist[BGP_VPN_POLICY_DIR_TOVPN],
11669 ECOMMUNITY_FORMAT_ROUTE_MAP,
11670 ECOMMUNITY_ROUTE_TARGET);
b9c7bc5a 11671 vty_out(vty, "%*srt vpn export %s\n", indent, "", b);
ddb5b488
PZ
11672 XFREE(MTYPE_ECOMMUNITY_STR, b);
11673 }
11674 }
11675 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]) {
b9c7bc5a 11676 vty_out(vty, "%*sroute-map vpn import %s\n", indent, "",
ddb5b488
PZ
11677 bgp->vpn_policy[afi]
11678 .rmap_name[BGP_VPN_POLICY_DIR_FROMVPN]);
11679 }
11680 if (bgp->vpn_policy[afi].rmap_name[BGP_VPN_POLICY_DIR_TOVPN]) {
b9c7bc5a 11681 vty_out(vty, "%*sroute-map vpn export %s\n", indent, "",
ddb5b488
PZ
11682 bgp->vpn_policy[afi]
11683 .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]);
11684 }
11685
ddb5b488
PZ
11686}
11687
11688
718e3744 11689/* BGP node structure. */
d62a17ae 11690static struct cmd_node bgp_node = {
9d303b37 11691 BGP_NODE, "%s(config-router)# ", 1,
718e3744 11692};
11693
d62a17ae 11694static struct cmd_node bgp_ipv4_unicast_node = {
9d303b37 11695 BGP_IPV4_NODE, "%s(config-router-af)# ", 1,
718e3744 11696};
11697
d62a17ae 11698static struct cmd_node bgp_ipv4_multicast_node = {
9d303b37 11699 BGP_IPV4M_NODE, "%s(config-router-af)# ", 1,
718e3744 11700};
11701
d62a17ae 11702static struct cmd_node bgp_ipv4_labeled_unicast_node = {
9d303b37 11703 BGP_IPV4L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11704};
11705
d62a17ae 11706static struct cmd_node bgp_ipv6_unicast_node = {
9d303b37 11707 BGP_IPV6_NODE, "%s(config-router-af)# ", 1,
718e3744 11708};
11709
d62a17ae 11710static struct cmd_node bgp_ipv6_multicast_node = {
9d303b37 11711 BGP_IPV6M_NODE, "%s(config-router-af)# ", 1,
25ffbdc1 11712};
11713
d62a17ae 11714static struct cmd_node bgp_ipv6_labeled_unicast_node = {
9d303b37 11715 BGP_IPV6L_NODE, "%s(config-router-af)# ", 1,
f51bae9c
DS
11716};
11717
d62a17ae 11718static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
11719 "%s(config-router-af)# ", 1};
6b0655a2 11720
d62a17ae 11721static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE,
11722 "%s(config-router-af-vpnv6)# ", 1};
8ecd3266 11723
d62a17ae 11724static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE,
11725 "%s(config-router-evpn)# ", 1};
4e0b7b6d 11726
d62a17ae 11727static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE,
11728 "%s(config-router-af-vni)# ", 1};
90e60aa7 11729
d62a17ae 11730static void community_list_vty(void);
1f8ae70b 11731
d62a17ae 11732static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
b8a815e5 11733{
d62a17ae 11734 struct bgp *bgp;
11735 struct peer *peer;
11736 struct peer_group *group;
11737 struct listnode *lnbgp, *lnpeer;
b8a815e5 11738
d62a17ae 11739 for (ALL_LIST_ELEMENTS_RO(bm->bgp, lnbgp, bgp)) {
11740 for (ALL_LIST_ELEMENTS_RO(bgp->peer, lnpeer, peer)) {
11741 /* only provide suggestions on the appropriate input
11742 * token type,
11743 * they'll otherwise show up multiple times */
11744 enum cmd_token_type match_type;
11745 char *name = peer->host;
d48ed3e0 11746
d62a17ae 11747 if (peer->conf_if) {
11748 match_type = VARIABLE_TKN;
11749 name = peer->conf_if;
11750 } else if (strchr(peer->host, ':'))
11751 match_type = IPV6_TKN;
11752 else
11753 match_type = IPV4_TKN;
d48ed3e0 11754
d62a17ae 11755 if (token->type != match_type)
11756 continue;
d48ed3e0 11757
d62a17ae 11758 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name));
11759 }
d48ed3e0 11760
d62a17ae 11761 if (token->type == VARIABLE_TKN)
11762 for (ALL_LIST_ELEMENTS_RO(bgp->group, lnpeer, group))
11763 vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
11764 group->name));
11765 }
b8a815e5
DL
11766}
11767
11768static const struct cmd_variable_handler bgp_var_neighbor[] = {
d62a17ae 11769 {.varname = "neighbor", .completions = bgp_ac_neighbor},
11770 {.varname = "neighbors", .completions = bgp_ac_neighbor},
7d4aea30 11771 {.varname = "peer", .completions = bgp_ac_neighbor},
d62a17ae 11772 {.completions = NULL}};
11773
11774void bgp_vty_init(void)
11775{
11776 cmd_variable_handler_register(bgp_var_neighbor);
11777
11778 /* Install bgp top node. */
11779 install_node(&bgp_node, bgp_config_write);
11780 install_node(&bgp_ipv4_unicast_node, NULL);
11781 install_node(&bgp_ipv4_multicast_node, NULL);
11782 install_node(&bgp_ipv4_labeled_unicast_node, NULL);
11783 install_node(&bgp_ipv6_unicast_node, NULL);
11784 install_node(&bgp_ipv6_multicast_node, NULL);
11785 install_node(&bgp_ipv6_labeled_unicast_node, NULL);
11786 install_node(&bgp_vpnv4_node, NULL);
11787 install_node(&bgp_vpnv6_node, NULL);
11788 install_node(&bgp_evpn_node, NULL);
11789 install_node(&bgp_evpn_vni_node, NULL);
11790
11791 /* Install default VTY commands to new nodes. */
11792 install_default(BGP_NODE);
11793 install_default(BGP_IPV4_NODE);
11794 install_default(BGP_IPV4M_NODE);
11795 install_default(BGP_IPV4L_NODE);
11796 install_default(BGP_IPV6_NODE);
11797 install_default(BGP_IPV6M_NODE);
11798 install_default(BGP_IPV6L_NODE);
11799 install_default(BGP_VPNV4_NODE);
11800 install_default(BGP_VPNV6_NODE);
11801 install_default(BGP_EVPN_NODE);
11802 install_default(BGP_EVPN_VNI_NODE);
11803
11804 /* "bgp multiple-instance" commands. */
11805 install_element(CONFIG_NODE, &bgp_multiple_instance_cmd);
11806 install_element(CONFIG_NODE, &no_bgp_multiple_instance_cmd);
11807
11808 /* "bgp config-type" commands. */
11809 install_element(CONFIG_NODE, &bgp_config_type_cmd);
11810 install_element(CONFIG_NODE, &no_bgp_config_type_cmd);
11811
11812 /* bgp route-map delay-timer commands. */
11813 install_element(CONFIG_NODE, &bgp_set_route_map_delay_timer_cmd);
11814 install_element(CONFIG_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11815
11816 /* Dummy commands (Currently not supported) */
11817 install_element(BGP_NODE, &no_synchronization_cmd);
11818 install_element(BGP_NODE, &no_auto_summary_cmd);
11819
11820 /* "router bgp" commands. */
11821 install_element(CONFIG_NODE, &router_bgp_cmd);
11822
11823 /* "no router bgp" commands. */
11824 install_element(CONFIG_NODE, &no_router_bgp_cmd);
11825
11826 /* "bgp router-id" commands. */
11827 install_element(BGP_NODE, &bgp_router_id_cmd);
11828 install_element(BGP_NODE, &no_bgp_router_id_cmd);
11829
11830 /* "bgp cluster-id" commands. */
11831 install_element(BGP_NODE, &bgp_cluster_id_cmd);
11832 install_element(BGP_NODE, &no_bgp_cluster_id_cmd);
11833
11834 /* "bgp confederation" commands. */
11835 install_element(BGP_NODE, &bgp_confederation_identifier_cmd);
11836 install_element(BGP_NODE, &no_bgp_confederation_identifier_cmd);
11837
11838 /* "bgp confederation peers" commands. */
11839 install_element(BGP_NODE, &bgp_confederation_peers_cmd);
11840 install_element(BGP_NODE, &no_bgp_confederation_peers_cmd);
11841
11842 /* bgp max-med command */
11843 install_element(BGP_NODE, &bgp_maxmed_admin_cmd);
11844 install_element(BGP_NODE, &no_bgp_maxmed_admin_cmd);
11845 install_element(BGP_NODE, &bgp_maxmed_admin_medv_cmd);
11846 install_element(BGP_NODE, &bgp_maxmed_onstartup_cmd);
11847 install_element(BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
11848
11849 /* bgp disable-ebgp-connected-nh-check */
11850 install_element(BGP_NODE, &bgp_disable_connected_route_check_cmd);
11851 install_element(BGP_NODE, &no_bgp_disable_connected_route_check_cmd);
11852
11853 /* bgp update-delay command */
11854 install_element(BGP_NODE, &bgp_update_delay_cmd);
11855 install_element(BGP_NODE, &no_bgp_update_delay_cmd);
11856 install_element(BGP_NODE, &bgp_update_delay_establish_wait_cmd);
11857
11858 install_element(BGP_NODE, &bgp_wpkt_quanta_cmd);
11859 install_element(BGP_NODE, &no_bgp_wpkt_quanta_cmd);
555e09d4
QY
11860 install_element(BGP_NODE, &bgp_rpkt_quanta_cmd);
11861 install_element(BGP_NODE, &no_bgp_rpkt_quanta_cmd);
d62a17ae 11862
11863 install_element(BGP_NODE, &bgp_coalesce_time_cmd);
11864 install_element(BGP_NODE, &no_bgp_coalesce_time_cmd);
11865
11866 /* "maximum-paths" commands. */
11867 install_element(BGP_NODE, &bgp_maxpaths_hidden_cmd);
11868 install_element(BGP_NODE, &no_bgp_maxpaths_hidden_cmd);
11869 install_element(BGP_IPV4_NODE, &bgp_maxpaths_cmd);
11870 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_cmd);
11871 install_element(BGP_IPV6_NODE, &bgp_maxpaths_cmd);
11872 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_cmd);
11873 install_element(BGP_NODE, &bgp_maxpaths_ibgp_hidden_cmd);
11874 install_element(BGP_NODE, &bgp_maxpaths_ibgp_cluster_hidden_cmd);
11875 install_element(BGP_NODE, &no_bgp_maxpaths_ibgp_hidden_cmd);
11876 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cmd);
11877 install_element(BGP_IPV4_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11878 install_element(BGP_IPV4_NODE, &no_bgp_maxpaths_ibgp_cmd);
11879 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cmd);
11880 install_element(BGP_IPV6_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11881 install_element(BGP_IPV6_NODE, &no_bgp_maxpaths_ibgp_cmd);
11882
11883 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_cmd);
11884 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_cmd);
11885 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cmd);
11886 install_element(BGP_IPV6L_NODE, &bgp_maxpaths_ibgp_cluster_cmd);
11887 install_element(BGP_IPV6L_NODE, &no_bgp_maxpaths_ibgp_cmd);
11888
11889 /* "timers bgp" commands. */
11890 install_element(BGP_NODE, &bgp_timers_cmd);
11891 install_element(BGP_NODE, &no_bgp_timers_cmd);
11892
11893 /* route-map delay-timer commands - per instance for backwards compat.
11894 */
11895 install_element(BGP_NODE, &bgp_set_route_map_delay_timer_cmd);
11896 install_element(BGP_NODE, &no_bgp_set_route_map_delay_timer_cmd);
11897
11898 /* "bgp client-to-client reflection" commands */
11899 install_element(BGP_NODE, &no_bgp_client_to_client_reflection_cmd);
11900 install_element(BGP_NODE, &bgp_client_to_client_reflection_cmd);
11901
11902 /* "bgp always-compare-med" commands */
11903 install_element(BGP_NODE, &bgp_always_compare_med_cmd);
11904 install_element(BGP_NODE, &no_bgp_always_compare_med_cmd);
11905
11906 /* "bgp deterministic-med" commands */
11907 install_element(BGP_NODE, &bgp_deterministic_med_cmd);
11908 install_element(BGP_NODE, &no_bgp_deterministic_med_cmd);
11909
11910 /* "bgp graceful-restart" commands */
11911 install_element(BGP_NODE, &bgp_graceful_restart_cmd);
11912 install_element(BGP_NODE, &no_bgp_graceful_restart_cmd);
11913 install_element(BGP_NODE, &bgp_graceful_restart_stalepath_time_cmd);
11914 install_element(BGP_NODE, &no_bgp_graceful_restart_stalepath_time_cmd);
11915 install_element(BGP_NODE, &bgp_graceful_restart_restart_time_cmd);
11916 install_element(BGP_NODE, &no_bgp_graceful_restart_restart_time_cmd);
11917
11918 install_element(BGP_NODE, &bgp_graceful_restart_preserve_fw_cmd);
11919 install_element(BGP_NODE, &no_bgp_graceful_restart_preserve_fw_cmd);
11920
7f323236
DW
11921 /* "bgp graceful-shutdown" commands */
11922 install_element(BGP_NODE, &bgp_graceful_shutdown_cmd);
11923 install_element(BGP_NODE, &no_bgp_graceful_shutdown_cmd);
11924
d62a17ae 11925 /* "bgp fast-external-failover" commands */
11926 install_element(BGP_NODE, &bgp_fast_external_failover_cmd);
11927 install_element(BGP_NODE, &no_bgp_fast_external_failover_cmd);
11928
11929 /* "bgp enforce-first-as" commands */
11930 install_element(BGP_NODE, &bgp_enforce_first_as_cmd);
11931 install_element(BGP_NODE, &no_bgp_enforce_first_as_cmd);
11932
11933 /* "bgp bestpath compare-routerid" commands */
11934 install_element(BGP_NODE, &bgp_bestpath_compare_router_id_cmd);
11935 install_element(BGP_NODE, &no_bgp_bestpath_compare_router_id_cmd);
11936
11937 /* "bgp bestpath as-path ignore" commands */
11938 install_element(BGP_NODE, &bgp_bestpath_aspath_ignore_cmd);
11939 install_element(BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd);
11940
11941 /* "bgp bestpath as-path confed" commands */
11942 install_element(BGP_NODE, &bgp_bestpath_aspath_confed_cmd);
11943 install_element(BGP_NODE, &no_bgp_bestpath_aspath_confed_cmd);
11944
11945 /* "bgp bestpath as-path multipath-relax" commands */
11946 install_element(BGP_NODE, &bgp_bestpath_aspath_multipath_relax_cmd);
11947 install_element(BGP_NODE, &no_bgp_bestpath_aspath_multipath_relax_cmd);
11948
11949 /* "bgp log-neighbor-changes" commands */
11950 install_element(BGP_NODE, &bgp_log_neighbor_changes_cmd);
11951 install_element(BGP_NODE, &no_bgp_log_neighbor_changes_cmd);
11952
11953 /* "bgp bestpath med" commands */
11954 install_element(BGP_NODE, &bgp_bestpath_med_cmd);
11955 install_element(BGP_NODE, &no_bgp_bestpath_med_cmd);
11956
11957 /* "no bgp default ipv4-unicast" commands. */
11958 install_element(BGP_NODE, &no_bgp_default_ipv4_unicast_cmd);
11959 install_element(BGP_NODE, &bgp_default_ipv4_unicast_cmd);
11960
11961 /* "bgp network import-check" commands. */
11962 install_element(BGP_NODE, &bgp_network_import_check_cmd);
11963 install_element(BGP_NODE, &bgp_network_import_check_exact_cmd);
11964 install_element(BGP_NODE, &no_bgp_network_import_check_cmd);
11965
11966 /* "bgp default local-preference" commands. */
11967 install_element(BGP_NODE, &bgp_default_local_preference_cmd);
11968 install_element(BGP_NODE, &no_bgp_default_local_preference_cmd);
11969
11970 /* bgp default show-hostname */
11971 install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
11972 install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
11973
11974 /* "bgp default subgroup-pkt-queue-max" commands. */
11975 install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
11976 install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
11977
11978 /* bgp ibgp-allow-policy-mods command */
11979 install_element(BGP_NODE, &bgp_rr_allow_outbound_policy_cmd);
11980 install_element(BGP_NODE, &no_bgp_rr_allow_outbound_policy_cmd);
11981
11982 /* "bgp listen limit" commands. */
11983 install_element(BGP_NODE, &bgp_listen_limit_cmd);
11984 install_element(BGP_NODE, &no_bgp_listen_limit_cmd);
11985
11986 /* "bgp listen range" commands. */
11987 install_element(BGP_NODE, &bgp_listen_range_cmd);
11988 install_element(BGP_NODE, &no_bgp_listen_range_cmd);
11989
8175f54a 11990 /* "bgp default shutdown" command */
f26845f9
QY
11991 install_element(BGP_NODE, &bgp_default_shutdown_cmd);
11992
d62a17ae 11993 /* "neighbor remote-as" commands. */
11994 install_element(BGP_NODE, &neighbor_remote_as_cmd);
11995 install_element(BGP_NODE, &neighbor_interface_config_cmd);
11996 install_element(BGP_NODE, &neighbor_interface_config_v6only_cmd);
11997 install_element(BGP_NODE, &neighbor_interface_config_remote_as_cmd);
11998 install_element(BGP_NODE,
11999 &neighbor_interface_v6only_config_remote_as_cmd);
12000 install_element(BGP_NODE, &no_neighbor_cmd);
12001 install_element(BGP_NODE, &no_neighbor_interface_config_cmd);
12002
12003 /* "neighbor peer-group" commands. */
12004 install_element(BGP_NODE, &neighbor_peer_group_cmd);
12005 install_element(BGP_NODE, &no_neighbor_peer_group_cmd);
12006 install_element(BGP_NODE,
12007 &no_neighbor_interface_peer_group_remote_as_cmd);
12008
12009 /* "neighbor local-as" commands. */
12010 install_element(BGP_NODE, &neighbor_local_as_cmd);
12011 install_element(BGP_NODE, &neighbor_local_as_no_prepend_cmd);
12012 install_element(BGP_NODE, &neighbor_local_as_no_prepend_replace_as_cmd);
12013 install_element(BGP_NODE, &no_neighbor_local_as_cmd);
12014
12015 /* "neighbor solo" commands. */
12016 install_element(BGP_NODE, &neighbor_solo_cmd);
12017 install_element(BGP_NODE, &no_neighbor_solo_cmd);
12018
12019 /* "neighbor password" commands. */
12020 install_element(BGP_NODE, &neighbor_password_cmd);
12021 install_element(BGP_NODE, &no_neighbor_password_cmd);
12022
12023 /* "neighbor activate" commands. */
12024 install_element(BGP_NODE, &neighbor_activate_hidden_cmd);
12025 install_element(BGP_IPV4_NODE, &neighbor_activate_cmd);
12026 install_element(BGP_IPV4M_NODE, &neighbor_activate_cmd);
12027 install_element(BGP_IPV4L_NODE, &neighbor_activate_cmd);
12028 install_element(BGP_IPV6_NODE, &neighbor_activate_cmd);
12029 install_element(BGP_IPV6M_NODE, &neighbor_activate_cmd);
12030 install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd);
12031 install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd);
12032 install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd);
12033 install_element(BGP_EVPN_NODE, &neighbor_activate_cmd);
12034
12035 /* "no neighbor activate" commands. */
12036 install_element(BGP_NODE, &no_neighbor_activate_hidden_cmd);
12037 install_element(BGP_IPV4_NODE, &no_neighbor_activate_cmd);
12038 install_element(BGP_IPV4M_NODE, &no_neighbor_activate_cmd);
12039 install_element(BGP_IPV4L_NODE, &no_neighbor_activate_cmd);
12040 install_element(BGP_IPV6_NODE, &no_neighbor_activate_cmd);
12041 install_element(BGP_IPV6M_NODE, &no_neighbor_activate_cmd);
12042 install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd);
12043 install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd);
12044 install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd);
12045 install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd);
12046
12047 /* "neighbor peer-group" set commands. */
12048 install_element(BGP_NODE, &neighbor_set_peer_group_cmd);
12049 install_element(BGP_IPV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12050 install_element(BGP_IPV4M_NODE, &neighbor_set_peer_group_hidden_cmd);
12051 install_element(BGP_IPV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12052 install_element(BGP_IPV6M_NODE, &neighbor_set_peer_group_hidden_cmd);
12053 install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd);
12054 install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd);
12055 install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd);
12056
12057 /* "no neighbor peer-group unset" commands. */
12058 install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd);
12059 install_element(BGP_IPV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12060 install_element(BGP_IPV4M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12061 install_element(BGP_IPV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12062 install_element(BGP_IPV6M_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12063 install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12064 install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12065 install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd);
12066
12067 /* "neighbor softreconfiguration inbound" commands.*/
12068 install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd);
12069 install_element(BGP_NODE, &no_neighbor_soft_reconfiguration_hidden_cmd);
12070 install_element(BGP_IPV4_NODE, &neighbor_soft_reconfiguration_cmd);
12071 install_element(BGP_IPV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12072 install_element(BGP_IPV4L_NODE, &neighbor_soft_reconfiguration_cmd);
12073 install_element(BGP_IPV4L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12074 install_element(BGP_IPV4M_NODE, &neighbor_soft_reconfiguration_cmd);
12075 install_element(BGP_IPV4M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12076 install_element(BGP_IPV6_NODE, &neighbor_soft_reconfiguration_cmd);
12077 install_element(BGP_IPV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12078 install_element(BGP_IPV6M_NODE, &neighbor_soft_reconfiguration_cmd);
12079 install_element(BGP_IPV6M_NODE, &no_neighbor_soft_reconfiguration_cmd);
12080 install_element(BGP_IPV6L_NODE, &neighbor_soft_reconfiguration_cmd);
12081 install_element(BGP_IPV6L_NODE, &no_neighbor_soft_reconfiguration_cmd);
12082 install_element(BGP_VPNV4_NODE, &neighbor_soft_reconfiguration_cmd);
12083 install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd);
12084 install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd);
12085 install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd);
12086
12087 /* "neighbor attribute-unchanged" commands. */
12088 install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd);
12089 install_element(BGP_NODE, &no_neighbor_attr_unchanged_hidden_cmd);
12090 install_element(BGP_IPV4_NODE, &neighbor_attr_unchanged_cmd);
12091 install_element(BGP_IPV4_NODE, &no_neighbor_attr_unchanged_cmd);
12092 install_element(BGP_IPV4M_NODE, &neighbor_attr_unchanged_cmd);
12093 install_element(BGP_IPV4M_NODE, &no_neighbor_attr_unchanged_cmd);
12094 install_element(BGP_IPV4L_NODE, &neighbor_attr_unchanged_cmd);
12095 install_element(BGP_IPV4L_NODE, &no_neighbor_attr_unchanged_cmd);
12096 install_element(BGP_IPV6_NODE, &neighbor_attr_unchanged_cmd);
12097 install_element(BGP_IPV6_NODE, &no_neighbor_attr_unchanged_cmd);
12098 install_element(BGP_IPV6M_NODE, &neighbor_attr_unchanged_cmd);
12099 install_element(BGP_IPV6M_NODE, &no_neighbor_attr_unchanged_cmd);
12100 install_element(BGP_IPV6L_NODE, &neighbor_attr_unchanged_cmd);
12101 install_element(BGP_IPV6L_NODE, &no_neighbor_attr_unchanged_cmd);
12102 install_element(BGP_VPNV4_NODE, &neighbor_attr_unchanged_cmd);
12103 install_element(BGP_VPNV4_NODE, &no_neighbor_attr_unchanged_cmd);
12104 install_element(BGP_VPNV6_NODE, &neighbor_attr_unchanged_cmd);
12105 install_element(BGP_VPNV6_NODE, &no_neighbor_attr_unchanged_cmd);
12106
12107 install_element(BGP_EVPN_NODE, &neighbor_attr_unchanged_cmd);
12108 install_element(BGP_EVPN_NODE, &no_neighbor_attr_unchanged_cmd);
12109
12110 /* "nexthop-local unchanged" commands */
12111 install_element(BGP_IPV6_NODE, &neighbor_nexthop_local_unchanged_cmd);
12112 install_element(BGP_IPV6_NODE,
12113 &no_neighbor_nexthop_local_unchanged_cmd);
12114
12115 /* "neighbor next-hop-self" commands. */
12116 install_element(BGP_NODE, &neighbor_nexthop_self_hidden_cmd);
12117 install_element(BGP_NODE, &no_neighbor_nexthop_self_hidden_cmd);
12118 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_cmd);
12119 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_cmd);
12120 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_cmd);
12121 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_cmd);
12122 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_cmd);
12123 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_cmd);
12124 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_cmd);
12125 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_cmd);
12126 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_cmd);
12127 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_cmd);
12128 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_cmd);
12129 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_cmd);
12130 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
12131 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
12132 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_cmd);
12133 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_cmd);
12134
12135 /* "neighbor next-hop-self force" commands. */
12136 install_element(BGP_NODE, &neighbor_nexthop_self_force_hidden_cmd);
12137 install_element(BGP_NODE, &no_neighbor_nexthop_self_force_hidden_cmd);
12138 install_element(BGP_IPV4_NODE, &neighbor_nexthop_self_force_cmd);
12139 install_element(BGP_IPV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12140 install_element(BGP_IPV4M_NODE, &neighbor_nexthop_self_force_cmd);
12141 install_element(BGP_IPV4M_NODE, &no_neighbor_nexthop_self_force_cmd);
12142 install_element(BGP_IPV4L_NODE, &neighbor_nexthop_self_force_cmd);
12143 install_element(BGP_IPV4L_NODE, &no_neighbor_nexthop_self_force_cmd);
12144 install_element(BGP_IPV6_NODE, &neighbor_nexthop_self_force_cmd);
12145 install_element(BGP_IPV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12146 install_element(BGP_IPV6M_NODE, &neighbor_nexthop_self_force_cmd);
12147 install_element(BGP_IPV6M_NODE, &no_neighbor_nexthop_self_force_cmd);
12148 install_element(BGP_IPV6L_NODE, &neighbor_nexthop_self_force_cmd);
12149 install_element(BGP_IPV6L_NODE, &no_neighbor_nexthop_self_force_cmd);
12150 install_element(BGP_VPNV4_NODE, &neighbor_nexthop_self_force_cmd);
12151 install_element(BGP_VPNV4_NODE, &no_neighbor_nexthop_self_force_cmd);
12152 install_element(BGP_VPNV6_NODE, &neighbor_nexthop_self_force_cmd);
12153 install_element(BGP_VPNV6_NODE, &no_neighbor_nexthop_self_force_cmd);
12154
12155 /* "neighbor as-override" commands. */
12156 install_element(BGP_NODE, &neighbor_as_override_hidden_cmd);
12157 install_element(BGP_NODE, &no_neighbor_as_override_hidden_cmd);
12158 install_element(BGP_IPV4_NODE, &neighbor_as_override_cmd);
12159 install_element(BGP_IPV4_NODE, &no_neighbor_as_override_cmd);
12160 install_element(BGP_IPV4M_NODE, &neighbor_as_override_cmd);
12161 install_element(BGP_IPV4M_NODE, &no_neighbor_as_override_cmd);
12162 install_element(BGP_IPV4L_NODE, &neighbor_as_override_cmd);
12163 install_element(BGP_IPV4L_NODE, &no_neighbor_as_override_cmd);
12164 install_element(BGP_IPV6_NODE, &neighbor_as_override_cmd);
12165 install_element(BGP_IPV6_NODE, &no_neighbor_as_override_cmd);
12166 install_element(BGP_IPV6M_NODE, &neighbor_as_override_cmd);
12167 install_element(BGP_IPV6M_NODE, &no_neighbor_as_override_cmd);
12168 install_element(BGP_IPV6L_NODE, &neighbor_as_override_cmd);
12169 install_element(BGP_IPV6L_NODE, &no_neighbor_as_override_cmd);
12170 install_element(BGP_VPNV4_NODE, &neighbor_as_override_cmd);
12171 install_element(BGP_VPNV4_NODE, &no_neighbor_as_override_cmd);
12172 install_element(BGP_VPNV6_NODE, &neighbor_as_override_cmd);
12173 install_element(BGP_VPNV6_NODE, &no_neighbor_as_override_cmd);
12174
12175 /* "neighbor remove-private-AS" commands. */
12176 install_element(BGP_NODE, &neighbor_remove_private_as_hidden_cmd);
12177 install_element(BGP_NODE, &no_neighbor_remove_private_as_hidden_cmd);
12178 install_element(BGP_NODE, &neighbor_remove_private_as_all_hidden_cmd);
12179 install_element(BGP_NODE,
12180 &no_neighbor_remove_private_as_all_hidden_cmd);
12181 install_element(BGP_NODE,
12182 &neighbor_remove_private_as_replace_as_hidden_cmd);
12183 install_element(BGP_NODE,
12184 &no_neighbor_remove_private_as_replace_as_hidden_cmd);
12185 install_element(BGP_NODE,
12186 &neighbor_remove_private_as_all_replace_as_hidden_cmd);
12187 install_element(
12188 BGP_NODE,
12189 &no_neighbor_remove_private_as_all_replace_as_hidden_cmd);
12190 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_cmd);
12191 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_cmd);
12192 install_element(BGP_IPV4_NODE, &neighbor_remove_private_as_all_cmd);
12193 install_element(BGP_IPV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12194 install_element(BGP_IPV4_NODE,
12195 &neighbor_remove_private_as_replace_as_cmd);
12196 install_element(BGP_IPV4_NODE,
12197 &no_neighbor_remove_private_as_replace_as_cmd);
12198 install_element(BGP_IPV4_NODE,
12199 &neighbor_remove_private_as_all_replace_as_cmd);
12200 install_element(BGP_IPV4_NODE,
12201 &no_neighbor_remove_private_as_all_replace_as_cmd);
12202 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_cmd);
12203 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_cmd);
12204 install_element(BGP_IPV4M_NODE, &neighbor_remove_private_as_all_cmd);
12205 install_element(BGP_IPV4M_NODE, &no_neighbor_remove_private_as_all_cmd);
12206 install_element(BGP_IPV4M_NODE,
12207 &neighbor_remove_private_as_replace_as_cmd);
12208 install_element(BGP_IPV4M_NODE,
12209 &no_neighbor_remove_private_as_replace_as_cmd);
12210 install_element(BGP_IPV4M_NODE,
12211 &neighbor_remove_private_as_all_replace_as_cmd);
12212 install_element(BGP_IPV4M_NODE,
12213 &no_neighbor_remove_private_as_all_replace_as_cmd);
12214 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_cmd);
12215 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_cmd);
12216 install_element(BGP_IPV4L_NODE, &neighbor_remove_private_as_all_cmd);
12217 install_element(BGP_IPV4L_NODE, &no_neighbor_remove_private_as_all_cmd);
12218 install_element(BGP_IPV4L_NODE,
12219 &neighbor_remove_private_as_replace_as_cmd);
12220 install_element(BGP_IPV4L_NODE,
12221 &no_neighbor_remove_private_as_replace_as_cmd);
12222 install_element(BGP_IPV4L_NODE,
12223 &neighbor_remove_private_as_all_replace_as_cmd);
12224 install_element(BGP_IPV4L_NODE,
12225 &no_neighbor_remove_private_as_all_replace_as_cmd);
12226 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_cmd);
12227 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_cmd);
12228 install_element(BGP_IPV6_NODE, &neighbor_remove_private_as_all_cmd);
12229 install_element(BGP_IPV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12230 install_element(BGP_IPV6_NODE,
12231 &neighbor_remove_private_as_replace_as_cmd);
12232 install_element(BGP_IPV6_NODE,
12233 &no_neighbor_remove_private_as_replace_as_cmd);
12234 install_element(BGP_IPV6_NODE,
12235 &neighbor_remove_private_as_all_replace_as_cmd);
12236 install_element(BGP_IPV6_NODE,
12237 &no_neighbor_remove_private_as_all_replace_as_cmd);
12238 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_cmd);
12239 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_cmd);
12240 install_element(BGP_IPV6M_NODE, &neighbor_remove_private_as_all_cmd);
12241 install_element(BGP_IPV6M_NODE, &no_neighbor_remove_private_as_all_cmd);
12242 install_element(BGP_IPV6M_NODE,
12243 &neighbor_remove_private_as_replace_as_cmd);
12244 install_element(BGP_IPV6M_NODE,
12245 &no_neighbor_remove_private_as_replace_as_cmd);
12246 install_element(BGP_IPV6M_NODE,
12247 &neighbor_remove_private_as_all_replace_as_cmd);
12248 install_element(BGP_IPV6M_NODE,
12249 &no_neighbor_remove_private_as_all_replace_as_cmd);
12250 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_cmd);
12251 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_cmd);
12252 install_element(BGP_IPV6L_NODE, &neighbor_remove_private_as_all_cmd);
12253 install_element(BGP_IPV6L_NODE, &no_neighbor_remove_private_as_all_cmd);
12254 install_element(BGP_IPV6L_NODE,
12255 &neighbor_remove_private_as_replace_as_cmd);
12256 install_element(BGP_IPV6L_NODE,
12257 &no_neighbor_remove_private_as_replace_as_cmd);
12258 install_element(BGP_IPV6L_NODE,
12259 &neighbor_remove_private_as_all_replace_as_cmd);
12260 install_element(BGP_IPV6L_NODE,
12261 &no_neighbor_remove_private_as_all_replace_as_cmd);
12262 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_cmd);
12263 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_cmd);
12264 install_element(BGP_VPNV4_NODE, &neighbor_remove_private_as_all_cmd);
12265 install_element(BGP_VPNV4_NODE, &no_neighbor_remove_private_as_all_cmd);
12266 install_element(BGP_VPNV4_NODE,
12267 &neighbor_remove_private_as_replace_as_cmd);
12268 install_element(BGP_VPNV4_NODE,
12269 &no_neighbor_remove_private_as_replace_as_cmd);
12270 install_element(BGP_VPNV4_NODE,
12271 &neighbor_remove_private_as_all_replace_as_cmd);
12272 install_element(BGP_VPNV4_NODE,
12273 &no_neighbor_remove_private_as_all_replace_as_cmd);
12274 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_cmd);
12275 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_cmd);
12276 install_element(BGP_VPNV6_NODE, &neighbor_remove_private_as_all_cmd);
12277 install_element(BGP_VPNV6_NODE, &no_neighbor_remove_private_as_all_cmd);
12278 install_element(BGP_VPNV6_NODE,
12279 &neighbor_remove_private_as_replace_as_cmd);
12280 install_element(BGP_VPNV6_NODE,
12281 &no_neighbor_remove_private_as_replace_as_cmd);
12282 install_element(BGP_VPNV6_NODE,
12283 &neighbor_remove_private_as_all_replace_as_cmd);
12284 install_element(BGP_VPNV6_NODE,
12285 &no_neighbor_remove_private_as_all_replace_as_cmd);
12286
12287 /* "neighbor send-community" commands.*/
12288 install_element(BGP_NODE, &neighbor_send_community_hidden_cmd);
12289 install_element(BGP_NODE, &neighbor_send_community_type_hidden_cmd);
12290 install_element(BGP_NODE, &no_neighbor_send_community_hidden_cmd);
12291 install_element(BGP_NODE, &no_neighbor_send_community_type_hidden_cmd);
12292 install_element(BGP_IPV4_NODE, &neighbor_send_community_cmd);
12293 install_element(BGP_IPV4_NODE, &neighbor_send_community_type_cmd);
12294 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_cmd);
12295 install_element(BGP_IPV4_NODE, &no_neighbor_send_community_type_cmd);
12296 install_element(BGP_IPV4M_NODE, &neighbor_send_community_cmd);
12297 install_element(BGP_IPV4M_NODE, &neighbor_send_community_type_cmd);
12298 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_cmd);
12299 install_element(BGP_IPV4M_NODE, &no_neighbor_send_community_type_cmd);
12300 install_element(BGP_IPV4L_NODE, &neighbor_send_community_cmd);
12301 install_element(BGP_IPV4L_NODE, &neighbor_send_community_type_cmd);
12302 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_cmd);
12303 install_element(BGP_IPV4L_NODE, &no_neighbor_send_community_type_cmd);
12304 install_element(BGP_IPV6_NODE, &neighbor_send_community_cmd);
12305 install_element(BGP_IPV6_NODE, &neighbor_send_community_type_cmd);
12306 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_cmd);
12307 install_element(BGP_IPV6_NODE, &no_neighbor_send_community_type_cmd);
12308 install_element(BGP_IPV6M_NODE, &neighbor_send_community_cmd);
12309 install_element(BGP_IPV6M_NODE, &neighbor_send_community_type_cmd);
12310 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_cmd);
12311 install_element(BGP_IPV6M_NODE, &no_neighbor_send_community_type_cmd);
12312 install_element(BGP_IPV6L_NODE, &neighbor_send_community_cmd);
12313 install_element(BGP_IPV6L_NODE, &neighbor_send_community_type_cmd);
12314 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_cmd);
12315 install_element(BGP_IPV6L_NODE, &no_neighbor_send_community_type_cmd);
12316 install_element(BGP_VPNV4_NODE, &neighbor_send_community_cmd);
12317 install_element(BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
12318 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
12319 install_element(BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
12320 install_element(BGP_VPNV6_NODE, &neighbor_send_community_cmd);
12321 install_element(BGP_VPNV6_NODE, &neighbor_send_community_type_cmd);
12322 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_cmd);
12323 install_element(BGP_VPNV6_NODE, &no_neighbor_send_community_type_cmd);
12324
12325 /* "neighbor route-reflector" commands.*/
12326 install_element(BGP_NODE, &neighbor_route_reflector_client_hidden_cmd);
12327 install_element(BGP_NODE,
12328 &no_neighbor_route_reflector_client_hidden_cmd);
12329 install_element(BGP_IPV4_NODE, &neighbor_route_reflector_client_cmd);
12330 install_element(BGP_IPV4_NODE, &no_neighbor_route_reflector_client_cmd);
12331 install_element(BGP_IPV4M_NODE, &neighbor_route_reflector_client_cmd);
12332 install_element(BGP_IPV4M_NODE,
12333 &no_neighbor_route_reflector_client_cmd);
12334 install_element(BGP_IPV4L_NODE, &neighbor_route_reflector_client_cmd);
12335 install_element(BGP_IPV4L_NODE,
12336 &no_neighbor_route_reflector_client_cmd);
12337 install_element(BGP_IPV6_NODE, &neighbor_route_reflector_client_cmd);
12338 install_element(BGP_IPV6_NODE, &no_neighbor_route_reflector_client_cmd);
12339 install_element(BGP_IPV6M_NODE, &neighbor_route_reflector_client_cmd);
12340 install_element(BGP_IPV6M_NODE,
12341 &no_neighbor_route_reflector_client_cmd);
12342 install_element(BGP_IPV6L_NODE, &neighbor_route_reflector_client_cmd);
12343 install_element(BGP_IPV6L_NODE,
12344 &no_neighbor_route_reflector_client_cmd);
12345 install_element(BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
12346 install_element(BGP_VPNV4_NODE,
12347 &no_neighbor_route_reflector_client_cmd);
12348 install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd);
12349 install_element(BGP_VPNV6_NODE,
12350 &no_neighbor_route_reflector_client_cmd);
12351 install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd);
12352 install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd);
12353
12354 /* "neighbor route-server" commands.*/
12355 install_element(BGP_NODE, &neighbor_route_server_client_hidden_cmd);
12356 install_element(BGP_NODE, &no_neighbor_route_server_client_hidden_cmd);
12357 install_element(BGP_IPV4_NODE, &neighbor_route_server_client_cmd);
12358 install_element(BGP_IPV4_NODE, &no_neighbor_route_server_client_cmd);
12359 install_element(BGP_IPV4M_NODE, &neighbor_route_server_client_cmd);
12360 install_element(BGP_IPV4M_NODE, &no_neighbor_route_server_client_cmd);
12361 install_element(BGP_IPV4L_NODE, &neighbor_route_server_client_cmd);
12362 install_element(BGP_IPV4L_NODE, &no_neighbor_route_server_client_cmd);
12363 install_element(BGP_IPV6_NODE, &neighbor_route_server_client_cmd);
12364 install_element(BGP_IPV6_NODE, &no_neighbor_route_server_client_cmd);
12365 install_element(BGP_IPV6M_NODE, &neighbor_route_server_client_cmd);
12366 install_element(BGP_IPV6M_NODE, &no_neighbor_route_server_client_cmd);
12367 install_element(BGP_IPV6L_NODE, &neighbor_route_server_client_cmd);
12368 install_element(BGP_IPV6L_NODE, &no_neighbor_route_server_client_cmd);
12369 install_element(BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
12370 install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
12371 install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd);
12372 install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd);
12373
12374 /* "neighbor addpath-tx-all-paths" commands.*/
12375 install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd);
12376 install_element(BGP_NODE, &no_neighbor_addpath_tx_all_paths_hidden_cmd);
12377 install_element(BGP_IPV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12378 install_element(BGP_IPV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12379 install_element(BGP_IPV4M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12380 install_element(BGP_IPV4M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12381 install_element(BGP_IPV4L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12382 install_element(BGP_IPV4L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12383 install_element(BGP_IPV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12384 install_element(BGP_IPV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12385 install_element(BGP_IPV6M_NODE, &neighbor_addpath_tx_all_paths_cmd);
12386 install_element(BGP_IPV6M_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12387 install_element(BGP_IPV6L_NODE, &neighbor_addpath_tx_all_paths_cmd);
12388 install_element(BGP_IPV6L_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12389 install_element(BGP_VPNV4_NODE, &neighbor_addpath_tx_all_paths_cmd);
12390 install_element(BGP_VPNV4_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12391 install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd);
12392 install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd);
12393
12394 /* "neighbor addpath-tx-bestpath-per-AS" commands.*/
12395 install_element(BGP_NODE,
12396 &neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12397 install_element(BGP_NODE,
12398 &no_neighbor_addpath_tx_bestpath_per_as_hidden_cmd);
12399 install_element(BGP_IPV4_NODE,
12400 &neighbor_addpath_tx_bestpath_per_as_cmd);
12401 install_element(BGP_IPV4_NODE,
12402 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12403 install_element(BGP_IPV4M_NODE,
12404 &neighbor_addpath_tx_bestpath_per_as_cmd);
12405 install_element(BGP_IPV4M_NODE,
12406 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12407 install_element(BGP_IPV4L_NODE,
12408 &neighbor_addpath_tx_bestpath_per_as_cmd);
12409 install_element(BGP_IPV4L_NODE,
12410 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12411 install_element(BGP_IPV6_NODE,
12412 &neighbor_addpath_tx_bestpath_per_as_cmd);
12413 install_element(BGP_IPV6_NODE,
12414 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12415 install_element(BGP_IPV6M_NODE,
12416 &neighbor_addpath_tx_bestpath_per_as_cmd);
12417 install_element(BGP_IPV6M_NODE,
12418 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12419 install_element(BGP_IPV6L_NODE,
12420 &neighbor_addpath_tx_bestpath_per_as_cmd);
12421 install_element(BGP_IPV6L_NODE,
12422 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12423 install_element(BGP_VPNV4_NODE,
12424 &neighbor_addpath_tx_bestpath_per_as_cmd);
12425 install_element(BGP_VPNV4_NODE,
12426 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12427 install_element(BGP_VPNV6_NODE,
12428 &neighbor_addpath_tx_bestpath_per_as_cmd);
12429 install_element(BGP_VPNV6_NODE,
12430 &no_neighbor_addpath_tx_bestpath_per_as_cmd);
12431
12432 /* "neighbor passive" commands. */
12433 install_element(BGP_NODE, &neighbor_passive_cmd);
12434 install_element(BGP_NODE, &no_neighbor_passive_cmd);
12435
12436
12437 /* "neighbor shutdown" commands. */
12438 install_element(BGP_NODE, &neighbor_shutdown_cmd);
12439 install_element(BGP_NODE, &no_neighbor_shutdown_cmd);
12440 install_element(BGP_NODE, &neighbor_shutdown_msg_cmd);
12441 install_element(BGP_NODE, &no_neighbor_shutdown_msg_cmd);
12442
12443 /* "neighbor capability extended-nexthop" commands.*/
12444 install_element(BGP_NODE, &neighbor_capability_enhe_cmd);
12445 install_element(BGP_NODE, &no_neighbor_capability_enhe_cmd);
12446
12447 /* "neighbor capability orf prefix-list" commands.*/
12448 install_element(BGP_NODE, &neighbor_capability_orf_prefix_hidden_cmd);
12449 install_element(BGP_NODE,
12450 &no_neighbor_capability_orf_prefix_hidden_cmd);
12451 install_element(BGP_IPV4_NODE, &neighbor_capability_orf_prefix_cmd);
12452 install_element(BGP_IPV4_NODE, &no_neighbor_capability_orf_prefix_cmd);
12453 install_element(BGP_IPV4M_NODE, &neighbor_capability_orf_prefix_cmd);
12454 install_element(BGP_IPV4M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12455 install_element(BGP_IPV4L_NODE, &neighbor_capability_orf_prefix_cmd);
12456 install_element(BGP_IPV4L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12457 install_element(BGP_IPV6_NODE, &neighbor_capability_orf_prefix_cmd);
12458 install_element(BGP_IPV6_NODE, &no_neighbor_capability_orf_prefix_cmd);
12459 install_element(BGP_IPV6M_NODE, &neighbor_capability_orf_prefix_cmd);
12460 install_element(BGP_IPV6M_NODE, &no_neighbor_capability_orf_prefix_cmd);
12461 install_element(BGP_IPV6L_NODE, &neighbor_capability_orf_prefix_cmd);
12462 install_element(BGP_IPV6L_NODE, &no_neighbor_capability_orf_prefix_cmd);
12463
12464 /* "neighbor capability dynamic" commands.*/
12465 install_element(BGP_NODE, &neighbor_capability_dynamic_cmd);
12466 install_element(BGP_NODE, &no_neighbor_capability_dynamic_cmd);
12467
12468 /* "neighbor dont-capability-negotiate" commands. */
12469 install_element(BGP_NODE, &neighbor_dont_capability_negotiate_cmd);
12470 install_element(BGP_NODE, &no_neighbor_dont_capability_negotiate_cmd);
12471
12472 /* "neighbor ebgp-multihop" commands. */
12473 install_element(BGP_NODE, &neighbor_ebgp_multihop_cmd);
12474 install_element(BGP_NODE, &neighbor_ebgp_multihop_ttl_cmd);
12475 install_element(BGP_NODE, &no_neighbor_ebgp_multihop_cmd);
12476
12477 /* "neighbor disable-connected-check" commands. */
12478 install_element(BGP_NODE, &neighbor_disable_connected_check_cmd);
12479 install_element(BGP_NODE, &no_neighbor_disable_connected_check_cmd);
12480
12481 /* "neighbor description" commands. */
12482 install_element(BGP_NODE, &neighbor_description_cmd);
12483 install_element(BGP_NODE, &no_neighbor_description_cmd);
12484
12485 /* "neighbor update-source" commands. "*/
12486 install_element(BGP_NODE, &neighbor_update_source_cmd);
12487 install_element(BGP_NODE, &no_neighbor_update_source_cmd);
12488
12489 /* "neighbor default-originate" commands. */
12490 install_element(BGP_NODE, &neighbor_default_originate_hidden_cmd);
12491 install_element(BGP_NODE, &neighbor_default_originate_rmap_hidden_cmd);
12492 install_element(BGP_NODE, &no_neighbor_default_originate_hidden_cmd);
12493 install_element(BGP_IPV4_NODE, &neighbor_default_originate_cmd);
12494 install_element(BGP_IPV4_NODE, &neighbor_default_originate_rmap_cmd);
12495 install_element(BGP_IPV4_NODE, &no_neighbor_default_originate_cmd);
12496 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_cmd);
12497 install_element(BGP_IPV4M_NODE, &neighbor_default_originate_rmap_cmd);
12498 install_element(BGP_IPV4M_NODE, &no_neighbor_default_originate_cmd);
12499 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_cmd);
12500 install_element(BGP_IPV4L_NODE, &neighbor_default_originate_rmap_cmd);
12501 install_element(BGP_IPV4L_NODE, &no_neighbor_default_originate_cmd);
12502 install_element(BGP_IPV6_NODE, &neighbor_default_originate_cmd);
12503 install_element(BGP_IPV6_NODE, &neighbor_default_originate_rmap_cmd);
12504 install_element(BGP_IPV6_NODE, &no_neighbor_default_originate_cmd);
12505 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_cmd);
12506 install_element(BGP_IPV6M_NODE, &neighbor_default_originate_rmap_cmd);
12507 install_element(BGP_IPV6M_NODE, &no_neighbor_default_originate_cmd);
12508 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_cmd);
12509 install_element(BGP_IPV6L_NODE, &neighbor_default_originate_rmap_cmd);
12510 install_element(BGP_IPV6L_NODE, &no_neighbor_default_originate_cmd);
12511
12512 /* "neighbor port" commands. */
12513 install_element(BGP_NODE, &neighbor_port_cmd);
12514 install_element(BGP_NODE, &no_neighbor_port_cmd);
12515
12516 /* "neighbor weight" commands. */
12517 install_element(BGP_NODE, &neighbor_weight_hidden_cmd);
12518 install_element(BGP_NODE, &no_neighbor_weight_hidden_cmd);
12519
12520 install_element(BGP_IPV4_NODE, &neighbor_weight_cmd);
12521 install_element(BGP_IPV4_NODE, &no_neighbor_weight_cmd);
12522 install_element(BGP_IPV4M_NODE, &neighbor_weight_cmd);
12523 install_element(BGP_IPV4M_NODE, &no_neighbor_weight_cmd);
12524 install_element(BGP_IPV4L_NODE, &neighbor_weight_cmd);
12525 install_element(BGP_IPV4L_NODE, &no_neighbor_weight_cmd);
12526 install_element(BGP_IPV6_NODE, &neighbor_weight_cmd);
12527 install_element(BGP_IPV6_NODE, &no_neighbor_weight_cmd);
12528 install_element(BGP_IPV6M_NODE, &neighbor_weight_cmd);
12529 install_element(BGP_IPV6M_NODE, &no_neighbor_weight_cmd);
12530 install_element(BGP_IPV6L_NODE, &neighbor_weight_cmd);
12531 install_element(BGP_IPV6L_NODE, &no_neighbor_weight_cmd);
12532 install_element(BGP_VPNV4_NODE, &neighbor_weight_cmd);
12533 install_element(BGP_VPNV4_NODE, &no_neighbor_weight_cmd);
12534 install_element(BGP_VPNV6_NODE, &neighbor_weight_cmd);
12535 install_element(BGP_VPNV6_NODE, &no_neighbor_weight_cmd);
12536
12537 /* "neighbor override-capability" commands. */
12538 install_element(BGP_NODE, &neighbor_override_capability_cmd);
12539 install_element(BGP_NODE, &no_neighbor_override_capability_cmd);
12540
12541 /* "neighbor strict-capability-match" commands. */
12542 install_element(BGP_NODE, &neighbor_strict_capability_cmd);
12543 install_element(BGP_NODE, &no_neighbor_strict_capability_cmd);
12544
12545 /* "neighbor timers" commands. */
12546 install_element(BGP_NODE, &neighbor_timers_cmd);
12547 install_element(BGP_NODE, &no_neighbor_timers_cmd);
12548
12549 /* "neighbor timers connect" commands. */
12550 install_element(BGP_NODE, &neighbor_timers_connect_cmd);
12551 install_element(BGP_NODE, &no_neighbor_timers_connect_cmd);
12552
12553 /* "neighbor advertisement-interval" commands. */
12554 install_element(BGP_NODE, &neighbor_advertise_interval_cmd);
12555 install_element(BGP_NODE, &no_neighbor_advertise_interval_cmd);
12556
12557 /* "neighbor interface" commands. */
12558 install_element(BGP_NODE, &neighbor_interface_cmd);
12559 install_element(BGP_NODE, &no_neighbor_interface_cmd);
12560
12561 /* "neighbor distribute" commands. */
12562 install_element(BGP_NODE, &neighbor_distribute_list_hidden_cmd);
12563 install_element(BGP_NODE, &no_neighbor_distribute_list_hidden_cmd);
12564 install_element(BGP_IPV4_NODE, &neighbor_distribute_list_cmd);
12565 install_element(BGP_IPV4_NODE, &no_neighbor_distribute_list_cmd);
12566 install_element(BGP_IPV4M_NODE, &neighbor_distribute_list_cmd);
12567 install_element(BGP_IPV4M_NODE, &no_neighbor_distribute_list_cmd);
12568 install_element(BGP_IPV4L_NODE, &neighbor_distribute_list_cmd);
12569 install_element(BGP_IPV4L_NODE, &no_neighbor_distribute_list_cmd);
12570 install_element(BGP_IPV6_NODE, &neighbor_distribute_list_cmd);
12571 install_element(BGP_IPV6_NODE, &no_neighbor_distribute_list_cmd);
12572 install_element(BGP_IPV6M_NODE, &neighbor_distribute_list_cmd);
12573 install_element(BGP_IPV6M_NODE, &no_neighbor_distribute_list_cmd);
12574 install_element(BGP_IPV6L_NODE, &neighbor_distribute_list_cmd);
12575 install_element(BGP_IPV6L_NODE, &no_neighbor_distribute_list_cmd);
12576 install_element(BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
12577 install_element(BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
12578 install_element(BGP_VPNV6_NODE, &neighbor_distribute_list_cmd);
12579 install_element(BGP_VPNV6_NODE, &no_neighbor_distribute_list_cmd);
12580
12581 /* "neighbor prefix-list" commands. */
12582 install_element(BGP_NODE, &neighbor_prefix_list_hidden_cmd);
12583 install_element(BGP_NODE, &no_neighbor_prefix_list_hidden_cmd);
12584 install_element(BGP_IPV4_NODE, &neighbor_prefix_list_cmd);
12585 install_element(BGP_IPV4_NODE, &no_neighbor_prefix_list_cmd);
12586 install_element(BGP_IPV4M_NODE, &neighbor_prefix_list_cmd);
12587 install_element(BGP_IPV4M_NODE, &no_neighbor_prefix_list_cmd);
12588 install_element(BGP_IPV4L_NODE, &neighbor_prefix_list_cmd);
12589 install_element(BGP_IPV4L_NODE, &no_neighbor_prefix_list_cmd);
12590 install_element(BGP_IPV6_NODE, &neighbor_prefix_list_cmd);
12591 install_element(BGP_IPV6_NODE, &no_neighbor_prefix_list_cmd);
12592 install_element(BGP_IPV6M_NODE, &neighbor_prefix_list_cmd);
12593 install_element(BGP_IPV6M_NODE, &no_neighbor_prefix_list_cmd);
12594 install_element(BGP_IPV6L_NODE, &neighbor_prefix_list_cmd);
12595 install_element(BGP_IPV6L_NODE, &no_neighbor_prefix_list_cmd);
12596 install_element(BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
12597 install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
12598 install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd);
12599 install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd);
12600
12601 /* "neighbor filter-list" commands. */
12602 install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd);
12603 install_element(BGP_NODE, &no_neighbor_filter_list_hidden_cmd);
12604 install_element(BGP_IPV4_NODE, &neighbor_filter_list_cmd);
12605 install_element(BGP_IPV4_NODE, &no_neighbor_filter_list_cmd);
12606 install_element(BGP_IPV4M_NODE, &neighbor_filter_list_cmd);
12607 install_element(BGP_IPV4M_NODE, &no_neighbor_filter_list_cmd);
12608 install_element(BGP_IPV4L_NODE, &neighbor_filter_list_cmd);
12609 install_element(BGP_IPV4L_NODE, &no_neighbor_filter_list_cmd);
12610 install_element(BGP_IPV6_NODE, &neighbor_filter_list_cmd);
12611 install_element(BGP_IPV6_NODE, &no_neighbor_filter_list_cmd);
12612 install_element(BGP_IPV6M_NODE, &neighbor_filter_list_cmd);
12613 install_element(BGP_IPV6M_NODE, &no_neighbor_filter_list_cmd);
12614 install_element(BGP_IPV6L_NODE, &neighbor_filter_list_cmd);
12615 install_element(BGP_IPV6L_NODE, &no_neighbor_filter_list_cmd);
12616 install_element(BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
12617 install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
12618 install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd);
12619 install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd);
12620
12621 /* "neighbor route-map" commands. */
12622 install_element(BGP_NODE, &neighbor_route_map_hidden_cmd);
12623 install_element(BGP_NODE, &no_neighbor_route_map_hidden_cmd);
12624 install_element(BGP_IPV4_NODE, &neighbor_route_map_cmd);
12625 install_element(BGP_IPV4_NODE, &no_neighbor_route_map_cmd);
12626 install_element(BGP_IPV4M_NODE, &neighbor_route_map_cmd);
12627 install_element(BGP_IPV4M_NODE, &no_neighbor_route_map_cmd);
12628 install_element(BGP_IPV4L_NODE, &neighbor_route_map_cmd);
12629 install_element(BGP_IPV4L_NODE, &no_neighbor_route_map_cmd);
12630 install_element(BGP_IPV6_NODE, &neighbor_route_map_cmd);
12631 install_element(BGP_IPV6_NODE, &no_neighbor_route_map_cmd);
12632 install_element(BGP_IPV6M_NODE, &neighbor_route_map_cmd);
12633 install_element(BGP_IPV6M_NODE, &no_neighbor_route_map_cmd);
12634 install_element(BGP_IPV6L_NODE, &neighbor_route_map_cmd);
12635 install_element(BGP_IPV6L_NODE, &no_neighbor_route_map_cmd);
12636 install_element(BGP_VPNV4_NODE, &neighbor_route_map_cmd);
12637 install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
12638 install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd);
12639 install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd);
d37ba549
MK
12640 install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd);
12641 install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd);
d62a17ae 12642
12643 /* "neighbor unsuppress-map" commands. */
12644 install_element(BGP_NODE, &neighbor_unsuppress_map_hidden_cmd);
12645 install_element(BGP_NODE, &no_neighbor_unsuppress_map_hidden_cmd);
12646 install_element(BGP_IPV4_NODE, &neighbor_unsuppress_map_cmd);
12647 install_element(BGP_IPV4_NODE, &no_neighbor_unsuppress_map_cmd);
12648 install_element(BGP_IPV4M_NODE, &neighbor_unsuppress_map_cmd);
12649 install_element(BGP_IPV4M_NODE, &no_neighbor_unsuppress_map_cmd);
12650 install_element(BGP_IPV4L_NODE, &neighbor_unsuppress_map_cmd);
12651 install_element(BGP_IPV4L_NODE, &no_neighbor_unsuppress_map_cmd);
12652 install_element(BGP_IPV6_NODE, &neighbor_unsuppress_map_cmd);
12653 install_element(BGP_IPV6_NODE, &no_neighbor_unsuppress_map_cmd);
12654 install_element(BGP_IPV6M_NODE, &neighbor_unsuppress_map_cmd);
12655 install_element(BGP_IPV6M_NODE, &no_neighbor_unsuppress_map_cmd);
12656 install_element(BGP_IPV6L_NODE, &neighbor_unsuppress_map_cmd);
12657 install_element(BGP_IPV6L_NODE, &no_neighbor_unsuppress_map_cmd);
12658 install_element(BGP_VPNV4_NODE, &neighbor_unsuppress_map_cmd);
12659 install_element(BGP_VPNV4_NODE, &no_neighbor_unsuppress_map_cmd);
12660 install_element(BGP_VPNV6_NODE, &neighbor_unsuppress_map_cmd);
12661 install_element(BGP_VPNV6_NODE, &no_neighbor_unsuppress_map_cmd);
12662
12663 /* "neighbor maximum-prefix" commands. */
12664 install_element(BGP_NODE, &neighbor_maximum_prefix_hidden_cmd);
12665 install_element(BGP_NODE,
12666 &neighbor_maximum_prefix_threshold_hidden_cmd);
12667 install_element(BGP_NODE, &neighbor_maximum_prefix_warning_hidden_cmd);
12668 install_element(BGP_NODE,
12669 &neighbor_maximum_prefix_threshold_warning_hidden_cmd);
12670 install_element(BGP_NODE, &neighbor_maximum_prefix_restart_hidden_cmd);
12671 install_element(BGP_NODE,
12672 &neighbor_maximum_prefix_threshold_restart_hidden_cmd);
12673 install_element(BGP_NODE, &no_neighbor_maximum_prefix_hidden_cmd);
12674 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_cmd);
12675 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12676 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12677 install_element(BGP_IPV4_NODE,
12678 &neighbor_maximum_prefix_threshold_warning_cmd);
12679 install_element(BGP_IPV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12680 install_element(BGP_IPV4_NODE,
12681 &neighbor_maximum_prefix_threshold_restart_cmd);
12682 install_element(BGP_IPV4_NODE, &no_neighbor_maximum_prefix_cmd);
12683 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_cmd);
12684 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12685 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_warning_cmd);
12686 install_element(BGP_IPV4M_NODE,
12687 &neighbor_maximum_prefix_threshold_warning_cmd);
12688 install_element(BGP_IPV4M_NODE, &neighbor_maximum_prefix_restart_cmd);
12689 install_element(BGP_IPV4M_NODE,
12690 &neighbor_maximum_prefix_threshold_restart_cmd);
12691 install_element(BGP_IPV4M_NODE, &no_neighbor_maximum_prefix_cmd);
12692 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_cmd);
12693 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12694 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_warning_cmd);
12695 install_element(BGP_IPV4L_NODE,
12696 &neighbor_maximum_prefix_threshold_warning_cmd);
12697 install_element(BGP_IPV4L_NODE, &neighbor_maximum_prefix_restart_cmd);
12698 install_element(BGP_IPV4L_NODE,
12699 &neighbor_maximum_prefix_threshold_restart_cmd);
12700 install_element(BGP_IPV4L_NODE, &no_neighbor_maximum_prefix_cmd);
12701 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_cmd);
12702 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12703 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12704 install_element(BGP_IPV6_NODE,
12705 &neighbor_maximum_prefix_threshold_warning_cmd);
12706 install_element(BGP_IPV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12707 install_element(BGP_IPV6_NODE,
12708 &neighbor_maximum_prefix_threshold_restart_cmd);
12709 install_element(BGP_IPV6_NODE, &no_neighbor_maximum_prefix_cmd);
12710 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_cmd);
12711 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_threshold_cmd);
12712 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_warning_cmd);
12713 install_element(BGP_IPV6M_NODE,
12714 &neighbor_maximum_prefix_threshold_warning_cmd);
12715 install_element(BGP_IPV6M_NODE, &neighbor_maximum_prefix_restart_cmd);
12716 install_element(BGP_IPV6M_NODE,
12717 &neighbor_maximum_prefix_threshold_restart_cmd);
12718 install_element(BGP_IPV6M_NODE, &no_neighbor_maximum_prefix_cmd);
12719 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_cmd);
12720 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_threshold_cmd);
12721 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_warning_cmd);
12722 install_element(BGP_IPV6L_NODE,
12723 &neighbor_maximum_prefix_threshold_warning_cmd);
12724 install_element(BGP_IPV6L_NODE, &neighbor_maximum_prefix_restart_cmd);
12725 install_element(BGP_IPV6L_NODE,
12726 &neighbor_maximum_prefix_threshold_restart_cmd);
12727 install_element(BGP_IPV6L_NODE, &no_neighbor_maximum_prefix_cmd);
12728 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
12729 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_threshold_cmd);
12730 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
12731 install_element(BGP_VPNV4_NODE,
12732 &neighbor_maximum_prefix_threshold_warning_cmd);
12733 install_element(BGP_VPNV4_NODE, &neighbor_maximum_prefix_restart_cmd);
12734 install_element(BGP_VPNV4_NODE,
12735 &neighbor_maximum_prefix_threshold_restart_cmd);
12736 install_element(BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
12737 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_cmd);
12738 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_threshold_cmd);
12739 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_warning_cmd);
12740 install_element(BGP_VPNV6_NODE,
12741 &neighbor_maximum_prefix_threshold_warning_cmd);
12742 install_element(BGP_VPNV6_NODE, &neighbor_maximum_prefix_restart_cmd);
12743 install_element(BGP_VPNV6_NODE,
12744 &neighbor_maximum_prefix_threshold_restart_cmd);
12745 install_element(BGP_VPNV6_NODE, &no_neighbor_maximum_prefix_cmd);
12746
12747 /* "neighbor allowas-in" */
12748 install_element(BGP_NODE, &neighbor_allowas_in_hidden_cmd);
12749 install_element(BGP_NODE, &no_neighbor_allowas_in_hidden_cmd);
12750 install_element(BGP_IPV4_NODE, &neighbor_allowas_in_cmd);
12751 install_element(BGP_IPV4_NODE, &no_neighbor_allowas_in_cmd);
12752 install_element(BGP_IPV4M_NODE, &neighbor_allowas_in_cmd);
12753 install_element(BGP_IPV4M_NODE, &no_neighbor_allowas_in_cmd);
12754 install_element(BGP_IPV4L_NODE, &neighbor_allowas_in_cmd);
12755 install_element(BGP_IPV4L_NODE, &no_neighbor_allowas_in_cmd);
12756 install_element(BGP_IPV6_NODE, &neighbor_allowas_in_cmd);
12757 install_element(BGP_IPV6_NODE, &no_neighbor_allowas_in_cmd);
12758 install_element(BGP_IPV6M_NODE, &neighbor_allowas_in_cmd);
12759 install_element(BGP_IPV6M_NODE, &no_neighbor_allowas_in_cmd);
12760 install_element(BGP_IPV6L_NODE, &neighbor_allowas_in_cmd);
12761 install_element(BGP_IPV6L_NODE, &no_neighbor_allowas_in_cmd);
12762 install_element(BGP_VPNV4_NODE, &neighbor_allowas_in_cmd);
12763 install_element(BGP_VPNV4_NODE, &no_neighbor_allowas_in_cmd);
12764 install_element(BGP_VPNV6_NODE, &neighbor_allowas_in_cmd);
12765 install_element(BGP_VPNV6_NODE, &no_neighbor_allowas_in_cmd);
12766 install_element(BGP_EVPN_NODE, &neighbor_allowas_in_cmd);
12767 install_element(BGP_EVPN_NODE, &no_neighbor_allowas_in_cmd);
12768
12769 /* address-family commands. */
12770 install_element(BGP_NODE, &address_family_ipv4_safi_cmd);
12771 install_element(BGP_NODE, &address_family_ipv6_safi_cmd);
d6902373 12772#ifdef KEEP_OLD_VPN_COMMANDS
d62a17ae 12773 install_element(BGP_NODE, &address_family_vpnv4_cmd);
12774 install_element(BGP_NODE, &address_family_vpnv6_cmd);
d6902373 12775#endif /* KEEP_OLD_VPN_COMMANDS */
8b1fb8be 12776
d62a17ae 12777 install_element(BGP_NODE, &address_family_evpn_cmd);
12778
12779 /* "exit-address-family" command. */
12780 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
12781 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
12782 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
12783 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
12784 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
12785 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
12786 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
12787 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
12788 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
12789
12790 /* "clear ip bgp commands" */
12791 install_element(ENABLE_NODE, &clear_ip_bgp_all_cmd);
12792
12793 /* clear ip bgp prefix */
12794 install_element(ENABLE_NODE, &clear_ip_bgp_prefix_cmd);
12795 install_element(ENABLE_NODE, &clear_bgp_ipv6_safi_prefix_cmd);
12796 install_element(ENABLE_NODE, &clear_bgp_instance_ipv6_safi_prefix_cmd);
12797
12798 /* "show [ip] bgp summary" commands. */
12799 install_element(VIEW_NODE, &show_bgp_instance_all_ipv6_updgrps_cmd);
d62a17ae 12800 install_element(VIEW_NODE, &show_bgp_instance_updgrps_stats_cmd);
d62a17ae 12801 install_element(VIEW_NODE, &show_bgp_updgrps_stats_cmd);
d62a17ae 12802 install_element(VIEW_NODE, &show_ip_bgp_instance_updgrps_adj_s_cmd);
12803 install_element(VIEW_NODE, &show_ip_bgp_summary_cmd);
d62a17ae 12804 install_element(VIEW_NODE, &show_ip_bgp_updgrps_cmd);
12805
12806 /* "show [ip] bgp neighbors" commands. */
12807 install_element(VIEW_NODE, &show_ip_bgp_neighbors_cmd);
12808
12809 /* "show [ip] bgp peer-group" commands. */
12810 install_element(VIEW_NODE, &show_ip_bgp_peer_groups_cmd);
12811
12812 /* "show [ip] bgp paths" commands. */
12813 install_element(VIEW_NODE, &show_ip_bgp_paths_cmd);
12814
12815 /* "show [ip] bgp community" commands. */
12816 install_element(VIEW_NODE, &show_ip_bgp_community_info_cmd);
12817
12818 /* "show ip bgp large-community" commands. */
12819 install_element(VIEW_NODE, &show_ip_bgp_lcommunity_info_cmd);
12820 /* "show [ip] bgp attribute-info" commands. */
12821 install_element(VIEW_NODE, &show_ip_bgp_attr_info_cmd);
12822
12823 /* "redistribute" commands. */
12824 install_element(BGP_NODE, &bgp_redistribute_ipv4_hidden_cmd);
12825 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_hidden_cmd);
12826 install_element(BGP_NODE, &bgp_redistribute_ipv4_rmap_hidden_cmd);
12827 install_element(BGP_NODE, &bgp_redistribute_ipv4_metric_hidden_cmd);
12828 install_element(BGP_NODE,
12829 &bgp_redistribute_ipv4_rmap_metric_hidden_cmd);
12830 install_element(BGP_NODE,
12831 &bgp_redistribute_ipv4_metric_rmap_hidden_cmd);
12832 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_hidden_cmd);
12833 install_element(BGP_NODE, &no_bgp_redistribute_ipv4_ospf_hidden_cmd);
12834 install_element(BGP_NODE, &bgp_redistribute_ipv4_ospf_rmap_hidden_cmd);
12835 install_element(BGP_NODE,
12836 &bgp_redistribute_ipv4_ospf_metric_hidden_cmd);
12837 install_element(BGP_NODE,
12838 &bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd);
12839 install_element(BGP_NODE,
12840 &bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd);
12841 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_cmd);
12842 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_cmd);
12843 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_cmd);
12844 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_cmd);
12845 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_rmap_metric_cmd);
12846 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_metric_rmap_cmd);
12847 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_cmd);
12848 install_element(BGP_IPV4_NODE, &no_bgp_redistribute_ipv4_ospf_cmd);
12849 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_rmap_cmd);
12850 install_element(BGP_IPV4_NODE, &bgp_redistribute_ipv4_ospf_metric_cmd);
12851 install_element(BGP_IPV4_NODE,
12852 &bgp_redistribute_ipv4_ospf_rmap_metric_cmd);
12853 install_element(BGP_IPV4_NODE,
12854 &bgp_redistribute_ipv4_ospf_metric_rmap_cmd);
12855 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_cmd);
12856 install_element(BGP_IPV6_NODE, &no_bgp_redistribute_ipv6_cmd);
12857 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_cmd);
12858 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_cmd);
12859 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_rmap_metric_cmd);
12860 install_element(BGP_IPV6_NODE, &bgp_redistribute_ipv6_metric_rmap_cmd);
12861
b9c7bc5a
PZ
12862 /* import|export vpn [route-map WORD] */
12863 install_element(BGP_IPV4_NODE, &bgp_imexport_vpn_cmd);
12864 install_element(BGP_IPV6_NODE, &bgp_imexport_vpn_cmd);
ddb5b488 12865
d62a17ae 12866 /* ttl_security commands */
12867 install_element(BGP_NODE, &neighbor_ttl_security_cmd);
12868 install_element(BGP_NODE, &no_neighbor_ttl_security_cmd);
12869
12870 /* "show [ip] bgp memory" commands. */
12871 install_element(VIEW_NODE, &show_bgp_memory_cmd);
12872
acf71666
MK
12873 /* "show bgp martian next-hop" */
12874 install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
12875
d62a17ae 12876 /* "show [ip] bgp views" commands. */
12877 install_element(VIEW_NODE, &show_bgp_views_cmd);
12878
12879 /* "show [ip] bgp vrfs" commands. */
12880 install_element(VIEW_NODE, &show_bgp_vrfs_cmd);
12881
12882 /* Community-list. */
12883 community_list_vty();
ddb5b488
PZ
12884
12885 /* vpn-policy commands */
b9c7bc5a
PZ
12886 install_element(BGP_IPV4_NODE, &af_rd_vpn_export_cmd);
12887 install_element(BGP_IPV6_NODE, &af_rd_vpn_export_cmd);
12888 install_element(BGP_IPV4_NODE, &af_label_vpn_export_cmd);
12889 install_element(BGP_IPV6_NODE, &af_label_vpn_export_cmd);
12890 install_element(BGP_IPV4_NODE, &af_nexthop_vpn_export_cmd);
12891 install_element(BGP_IPV6_NODE, &af_nexthop_vpn_export_cmd);
12892 install_element(BGP_IPV4_NODE, &af_rt_vpn_imexport_cmd);
12893 install_element(BGP_IPV6_NODE, &af_rt_vpn_imexport_cmd);
12894 install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd);
12895 install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd);
12896
12897 install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd);
12898 install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd);
12899 install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd);
12900 install_element(BGP_IPV6_NODE, &af_no_label_vpn_export_cmd);
12901 install_element(BGP_IPV4_NODE, &af_no_nexthop_vpn_export_cmd);
12902 install_element(BGP_IPV6_NODE, &af_no_nexthop_vpn_export_cmd);
12903 install_element(BGP_IPV4_NODE, &af_no_rt_vpn_imexport_cmd);
12904 install_element(BGP_IPV6_NODE, &af_no_rt_vpn_imexport_cmd);
12905 install_element(BGP_IPV4_NODE, &af_no_route_map_vpn_imexport_cmd);
12906 install_element(BGP_IPV6_NODE, &af_no_route_map_vpn_imexport_cmd);
718e3744 12907}
6b0655a2 12908
718e3744 12909#include "memory.h"
12910#include "bgp_regex.h"
12911#include "bgp_clist.h"
12912#include "bgp_ecommunity.h"
12913
12914/* VTY functions. */
12915
12916/* Direction value to string conversion. */
d62a17ae 12917static const char *community_direct_str(int direct)
12918{
12919 switch (direct) {
12920 case COMMUNITY_DENY:
12921 return "deny";
12922 case COMMUNITY_PERMIT:
12923 return "permit";
12924 default:
12925 return "unknown";
12926 }
718e3744 12927}
12928
12929/* Display error string. */
d62a17ae 12930static void community_list_perror(struct vty *vty, int ret)
12931{
12932 switch (ret) {
12933 case COMMUNITY_LIST_ERR_CANT_FIND_LIST:
12934 vty_out(vty, "%% Can't find community-list\n");
12935 break;
12936 case COMMUNITY_LIST_ERR_MALFORMED_VAL:
12937 vty_out(vty, "%% Malformed community-list value\n");
12938 break;
12939 case COMMUNITY_LIST_ERR_STANDARD_CONFLICT:
12940 vty_out(vty,
12941 "%% Community name conflict, previously defined as standard community\n");
12942 break;
12943 case COMMUNITY_LIST_ERR_EXPANDED_CONFLICT:
12944 vty_out(vty,
12945 "%% Community name conflict, previously defined as expanded community\n");
12946 break;
12947 }
718e3744 12948}
12949
5bf15956
DW
12950/* "community-list" keyword help string. */
12951#define COMMUNITY_LIST_STR "Add a community list entry\n"
12952
5bf15956 12953/* ip community-list standard */
718e3744 12954DEFUN (ip_community_list_standard,
12955 ip_community_list_standard_cmd,
e961923c 12956 "ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12957 IP_STR
12958 COMMUNITY_LIST_STR
12959 "Community list number (standard)\n"
5bf15956 12960 "Add an standard community-list entry\n"
718e3744 12961 "Community list name\n"
12962 "Specify community to reject\n"
12963 "Specify community to accept\n"
12964 COMMUNITY_VAL_STR)
12965{
d62a17ae 12966 char *cl_name_or_number = NULL;
12967 int direct = 0;
12968 int style = COMMUNITY_LIST_STANDARD;
42f914d4 12969
d62a17ae 12970 int idx = 0;
12971 argv_find(argv, argc, "(1-99)", &idx);
12972 argv_find(argv, argc, "WORD", &idx);
12973 cl_name_or_number = argv[idx]->arg;
12974 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
12975 : COMMUNITY_DENY;
12976 argv_find(argv, argc, "AA:NN", &idx);
12977 char *str = argv_concat(argv, argc, idx);
42f914d4 12978
d62a17ae 12979 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
12980 style);
42f914d4 12981
d62a17ae 12982 XFREE(MTYPE_TMP, str);
42f914d4 12983
d62a17ae 12984 if (ret < 0) {
12985 /* Display error string. */
12986 community_list_perror(vty, ret);
12987 return CMD_WARNING_CONFIG_FAILED;
12988 }
42f914d4 12989
d62a17ae 12990 return CMD_SUCCESS;
718e3744 12991}
12992
fee6e4e4 12993DEFUN (no_ip_community_list_standard_all,
12994 no_ip_community_list_standard_all_cmd,
e961923c 12995 "no ip community-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 12996 NO_STR
12997 IP_STR
12998 COMMUNITY_LIST_STR
12999 "Community list number (standard)\n"
5bf15956
DW
13000 "Add an standard community-list entry\n"
13001 "Community list name\n"
718e3744 13002 "Specify community to reject\n"
13003 "Specify community to accept\n"
13004 COMMUNITY_VAL_STR)
13005{
d62a17ae 13006 int delete_all = 0;
42f914d4 13007
d62a17ae 13008 char *cl_name_or_number = NULL;
13009 int direct = 0;
13010 int style = COMMUNITY_LIST_STANDARD;
42f914d4 13011
d62a17ae 13012 int idx = 0;
13013 argv_find(argv, argc, "(1-99)", &idx);
13014 argv_find(argv, argc, "WORD", &idx);
13015 cl_name_or_number = argv[idx]->arg;
13016 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13017 : COMMUNITY_DENY;
13018 argv_find(argv, argc, "AA:NN", &idx);
13019 char *str = argv_concat(argv, argc, idx);
42f914d4 13020
d62a17ae 13021 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13022 direct, style, delete_all);
42f914d4 13023
d62a17ae 13024 XFREE(MTYPE_TMP, str);
daf9ddbb 13025
d62a17ae 13026 if (ret < 0) {
13027 community_list_perror(vty, ret);
13028 return CMD_WARNING_CONFIG_FAILED;
13029 }
42f914d4 13030
d62a17ae 13031 return CMD_SUCCESS;
718e3744 13032}
13033
5bf15956
DW
13034/* ip community-list expanded */
13035DEFUN (ip_community_list_expanded_all,
13036 ip_community_list_expanded_all_cmd,
42f914d4 13037 "ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13038 IP_STR
13039 COMMUNITY_LIST_STR
13040 "Community list number (expanded)\n"
5bf15956 13041 "Add an expanded community-list entry\n"
718e3744 13042 "Community list name\n"
13043 "Specify community to reject\n"
13044 "Specify community to accept\n"
13045 COMMUNITY_VAL_STR)
13046{
d62a17ae 13047 char *cl_name_or_number = NULL;
13048 int direct = 0;
13049 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13050
d62a17ae 13051 int idx = 0;
13052 argv_find(argv, argc, "(100-500)", &idx);
13053 argv_find(argv, argc, "WORD", &idx);
13054 cl_name_or_number = argv[idx]->arg;
13055 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13056 : COMMUNITY_DENY;
13057 argv_find(argv, argc, "AA:NN", &idx);
13058 char *str = argv_concat(argv, argc, idx);
42f914d4 13059
d62a17ae 13060 int ret = community_list_set(bgp_clist, cl_name_or_number, str, direct,
13061 style);
42f914d4 13062
d62a17ae 13063 XFREE(MTYPE_TMP, str);
42f914d4 13064
d62a17ae 13065 if (ret < 0) {
13066 /* Display error string. */
13067 community_list_perror(vty, ret);
13068 return CMD_WARNING_CONFIG_FAILED;
13069 }
42f914d4 13070
d62a17ae 13071 return CMD_SUCCESS;
718e3744 13072}
13073
5bf15956
DW
13074DEFUN (no_ip_community_list_expanded_all,
13075 no_ip_community_list_expanded_all_cmd,
42f914d4 13076 "no ip community-list <(100-500)|expanded WORD> <deny|permit> AA:NN...",
718e3744 13077 NO_STR
13078 IP_STR
13079 COMMUNITY_LIST_STR
5bf15956
DW
13080 "Community list number (expanded)\n"
13081 "Add an expanded community-list entry\n"
718e3744 13082 "Community list name\n"
13083 "Specify community to reject\n"
13084 "Specify community to accept\n"
5bf15956 13085 COMMUNITY_VAL_STR)
718e3744 13086{
d62a17ae 13087 int delete_all = 0;
42f914d4 13088
d62a17ae 13089 char *cl_name_or_number = NULL;
13090 int direct = 0;
13091 int style = COMMUNITY_LIST_EXPANDED;
42f914d4 13092
d62a17ae 13093 int idx = 0;
13094 argv_find(argv, argc, "(100-500)", &idx);
13095 argv_find(argv, argc, "WORD", &idx);
13096 cl_name_or_number = argv[idx]->arg;
13097 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13098 : COMMUNITY_DENY;
13099 argv_find(argv, argc, "AA:NN", &idx);
13100 char *str = argv_concat(argv, argc, idx);
42f914d4 13101
d62a17ae 13102 int ret = community_list_unset(bgp_clist, cl_name_or_number, str,
13103 direct, style, delete_all);
42f914d4 13104
d62a17ae 13105 XFREE(MTYPE_TMP, str);
daf9ddbb 13106
d62a17ae 13107 if (ret < 0) {
13108 community_list_perror(vty, ret);
13109 return CMD_WARNING_CONFIG_FAILED;
13110 }
42f914d4 13111
d62a17ae 13112 return CMD_SUCCESS;
718e3744 13113}
13114
d62a17ae 13115static void community_list_show(struct vty *vty, struct community_list *list)
718e3744 13116{
d62a17ae 13117 struct community_entry *entry;
718e3744 13118
d62a17ae 13119 for (entry = list->head; entry; entry = entry->next) {
13120 if (entry == list->head) {
13121 if (all_digit(list->name))
13122 vty_out(vty, "Community %s list %s\n",
13123 entry->style == COMMUNITY_LIST_STANDARD
13124 ? "standard"
13125 : "(expanded) access",
13126 list->name);
13127 else
13128 vty_out(vty, "Named Community %s list %s\n",
13129 entry->style == COMMUNITY_LIST_STANDARD
13130 ? "standard"
13131 : "expanded",
13132 list->name);
13133 }
13134 if (entry->any)
13135 vty_out(vty, " %s\n",
13136 community_direct_str(entry->direct));
13137 else
13138 vty_out(vty, " %s %s\n",
13139 community_direct_str(entry->direct),
13140 entry->style == COMMUNITY_LIST_STANDARD
a69ea8ae 13141 ? community_str(entry->u.com, false)
d62a17ae 13142 : entry->config);
13143 }
718e3744 13144}
13145
13146DEFUN (show_ip_community_list,
13147 show_ip_community_list_cmd,
13148 "show ip community-list",
13149 SHOW_STR
13150 IP_STR
13151 "List community-list\n")
13152{
d62a17ae 13153 struct community_list *list;
13154 struct community_list_master *cm;
718e3744 13155
d62a17ae 13156 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13157 if (!cm)
13158 return CMD_SUCCESS;
718e3744 13159
d62a17ae 13160 for (list = cm->num.head; list; list = list->next)
13161 community_list_show(vty, list);
718e3744 13162
d62a17ae 13163 for (list = cm->str.head; list; list = list->next)
13164 community_list_show(vty, list);
718e3744 13165
d62a17ae 13166 return CMD_SUCCESS;
718e3744 13167}
13168
13169DEFUN (show_ip_community_list_arg,
13170 show_ip_community_list_arg_cmd,
6147e2c6 13171 "show ip community-list <(1-500)|WORD>",
718e3744 13172 SHOW_STR
13173 IP_STR
13174 "List community-list\n"
13175 "Community-list number\n"
13176 "Community-list name\n")
13177{
d62a17ae 13178 int idx_comm_list = 3;
13179 struct community_list *list;
718e3744 13180
d62a17ae 13181 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13182 COMMUNITY_LIST_MASTER);
13183 if (!list) {
13184 vty_out(vty, "%% Can't find community-list\n");
13185 return CMD_WARNING;
13186 }
718e3744 13187
d62a17ae 13188 community_list_show(vty, list);
718e3744 13189
d62a17ae 13190 return CMD_SUCCESS;
718e3744 13191}
6b0655a2 13192
57d187bc
JS
13193/*
13194 * Large Community code.
13195 */
d62a17ae 13196static int lcommunity_list_set_vty(struct vty *vty, int argc,
13197 struct cmd_token **argv, int style,
13198 int reject_all_digit_name)
13199{
13200 int ret;
13201 int direct;
13202 char *str;
13203 int idx = 0;
13204 char *cl_name;
13205
13206 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13207 : COMMUNITY_DENY;
13208
13209 /* All digit name check. */
13210 idx = 0;
13211 argv_find(argv, argc, "WORD", &idx);
13212 argv_find(argv, argc, "(1-99)", &idx);
13213 argv_find(argv, argc, "(100-500)", &idx);
13214 cl_name = argv[idx]->arg;
13215 if (reject_all_digit_name && all_digit(cl_name)) {
13216 vty_out(vty, "%% Community name cannot have all digits\n");
13217 return CMD_WARNING_CONFIG_FAILED;
13218 }
13219
13220 idx = 0;
13221 argv_find(argv, argc, "AA:BB:CC", &idx);
13222 argv_find(argv, argc, "LINE", &idx);
13223 /* Concat community string argument. */
13224 if (idx)
13225 str = argv_concat(argv, argc, idx);
13226 else
13227 str = NULL;
13228
13229 ret = lcommunity_list_set(bgp_clist, cl_name, str, direct, style);
13230
13231 /* Free temporary community list string allocated by
13232 argv_concat(). */
13233 if (str)
13234 XFREE(MTYPE_TMP, str);
13235
13236 if (ret < 0) {
13237 community_list_perror(vty, ret);
13238 return CMD_WARNING_CONFIG_FAILED;
13239 }
13240 return CMD_SUCCESS;
13241}
13242
13243static int lcommunity_list_unset_vty(struct vty *vty, int argc,
13244 struct cmd_token **argv, int style)
13245{
13246 int ret;
13247 int direct = 0;
13248 char *str = NULL;
13249 int idx = 0;
13250
13251 argv_find(argv, argc, "permit", &idx);
13252 argv_find(argv, argc, "deny", &idx);
13253
13254 if (idx) {
13255 /* Check the list direct. */
13256 if (strncmp(argv[idx]->arg, "p", 1) == 0)
13257 direct = COMMUNITY_PERMIT;
13258 else
13259 direct = COMMUNITY_DENY;
13260
13261 idx = 0;
13262 argv_find(argv, argc, "LINE", &idx);
13263 argv_find(argv, argc, "AA:AA:NN", &idx);
13264 /* Concat community string argument. */
13265 str = argv_concat(argv, argc, idx);
13266 }
13267
13268 idx = 0;
13269 argv_find(argv, argc, "(1-99)", &idx);
13270 argv_find(argv, argc, "(100-500)", &idx);
13271 argv_find(argv, argc, "WORD", &idx);
13272
13273 /* Unset community list. */
13274 ret = lcommunity_list_unset(bgp_clist, argv[idx]->arg, str, direct,
13275 style);
13276
13277 /* Free temporary community list string allocated by
13278 argv_concat(). */
13279 if (str)
13280 XFREE(MTYPE_TMP, str);
13281
13282 if (ret < 0) {
13283 community_list_perror(vty, ret);
13284 return CMD_WARNING_CONFIG_FAILED;
13285 }
13286
13287 return CMD_SUCCESS;
57d187bc
JS
13288}
13289
13290/* "large-community-list" keyword help string. */
13291#define LCOMMUNITY_LIST_STR "Add a large community list entry\n"
13292#define LCOMMUNITY_VAL_STR "large community in 'aa:bb:cc' format\n"
13293
13294DEFUN (ip_lcommunity_list_standard,
13295 ip_lcommunity_list_standard_cmd,
52951b63
DS
13296 "ip large-community-list (1-99) <deny|permit>",
13297 IP_STR
13298 LCOMMUNITY_LIST_STR
13299 "Large Community list number (standard)\n"
13300 "Specify large community to reject\n"
7111c1a0 13301 "Specify large community to accept\n")
52951b63 13302{
d62a17ae 13303 return lcommunity_list_set_vty(vty, argc, argv,
13304 LARGE_COMMUNITY_LIST_STANDARD, 0);
52951b63
DS
13305}
13306
13307DEFUN (ip_lcommunity_list_standard1,
13308 ip_lcommunity_list_standard1_cmd,
13309 "ip large-community-list (1-99) <deny|permit> AA:BB:CC...",
57d187bc
JS
13310 IP_STR
13311 LCOMMUNITY_LIST_STR
13312 "Large Community list number (standard)\n"
13313 "Specify large community to reject\n"
13314 "Specify large community to accept\n"
13315 LCOMMUNITY_VAL_STR)
13316{
d62a17ae 13317 return lcommunity_list_set_vty(vty, argc, argv,
13318 LARGE_COMMUNITY_LIST_STANDARD, 0);
57d187bc
JS
13319}
13320
13321DEFUN (ip_lcommunity_list_expanded,
13322 ip_lcommunity_list_expanded_cmd,
13323 "ip large-community-list (100-500) <deny|permit> LINE...",
13324 IP_STR
13325 LCOMMUNITY_LIST_STR
13326 "Large Community list number (expanded)\n"
13327 "Specify large community to reject\n"
13328 "Specify large community to accept\n"
13329 "An ordered list as a regular-expression\n")
13330{
d62a17ae 13331 return lcommunity_list_set_vty(vty, argc, argv,
13332 LARGE_COMMUNITY_LIST_EXPANDED, 0);
57d187bc
JS
13333}
13334
13335DEFUN (ip_lcommunity_list_name_standard,
13336 ip_lcommunity_list_name_standard_cmd,
52951b63
DS
13337 "ip large-community-list standard WORD <deny|permit>",
13338 IP_STR
13339 LCOMMUNITY_LIST_STR
13340 "Specify standard large-community-list\n"
13341 "Large Community list name\n"
13342 "Specify large community to reject\n"
13343 "Specify large community to accept\n")
13344{
d62a17ae 13345 return lcommunity_list_set_vty(vty, argc, argv,
13346 LARGE_COMMUNITY_LIST_STANDARD, 1);
52951b63
DS
13347}
13348
13349DEFUN (ip_lcommunity_list_name_standard1,
13350 ip_lcommunity_list_name_standard1_cmd,
13351 "ip large-community-list standard WORD <deny|permit> AA:BB:CC...",
57d187bc
JS
13352 IP_STR
13353 LCOMMUNITY_LIST_STR
13354 "Specify standard large-community-list\n"
13355 "Large Community list name\n"
13356 "Specify large community to reject\n"
13357 "Specify large community to accept\n"
13358 LCOMMUNITY_VAL_STR)
13359{
d62a17ae 13360 return lcommunity_list_set_vty(vty, argc, argv,
13361 LARGE_COMMUNITY_LIST_STANDARD, 1);
57d187bc
JS
13362}
13363
13364DEFUN (ip_lcommunity_list_name_expanded,
13365 ip_lcommunity_list_name_expanded_cmd,
13366 "ip large-community-list expanded WORD <deny|permit> LINE...",
13367 IP_STR
13368 LCOMMUNITY_LIST_STR
13369 "Specify expanded large-community-list\n"
13370 "Large Community list name\n"
13371 "Specify large community to reject\n"
13372 "Specify large community to accept\n"
13373 "An ordered list as a regular-expression\n")
13374{
d62a17ae 13375 return lcommunity_list_set_vty(vty, argc, argv,
13376 LARGE_COMMUNITY_LIST_EXPANDED, 1);
57d187bc
JS
13377}
13378
13379DEFUN (no_ip_lcommunity_list_standard_all,
13380 no_ip_lcommunity_list_standard_all_cmd,
13381 "no ip large-community-list <(1-99)|(100-500)|WORD>",
13382 NO_STR
13383 IP_STR
13384 LCOMMUNITY_LIST_STR
13385 "Large Community list number (standard)\n"
13386 "Large Community list number (expanded)\n"
13387 "Large Community list name\n")
13388{
d62a17ae 13389 return lcommunity_list_unset_vty(vty, argc, argv,
13390 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13391}
13392
13393DEFUN (no_ip_lcommunity_list_name_expanded_all,
13394 no_ip_lcommunity_list_name_expanded_all_cmd,
13395 "no ip large-community-list expanded WORD",
13396 NO_STR
13397 IP_STR
13398 LCOMMUNITY_LIST_STR
13399 "Specify expanded large-community-list\n"
13400 "Large Community list name\n")
13401{
d62a17ae 13402 return lcommunity_list_unset_vty(vty, argc, argv,
13403 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13404}
13405
13406DEFUN (no_ip_lcommunity_list_standard,
13407 no_ip_lcommunity_list_standard_cmd,
13408 "no ip large-community-list (1-99) <deny|permit> AA:AA:NN...",
13409 NO_STR
13410 IP_STR
13411 LCOMMUNITY_LIST_STR
13412 "Large Community list number (standard)\n"
13413 "Specify large community to reject\n"
13414 "Specify large community to accept\n"
13415 LCOMMUNITY_VAL_STR)
13416{
d62a17ae 13417 return lcommunity_list_unset_vty(vty, argc, argv,
13418 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13419}
13420
13421DEFUN (no_ip_lcommunity_list_expanded,
13422 no_ip_lcommunity_list_expanded_cmd,
13423 "no ip large-community-list (100-500) <deny|permit> LINE...",
13424 NO_STR
13425 IP_STR
13426 LCOMMUNITY_LIST_STR
13427 "Large Community list number (expanded)\n"
13428 "Specify large community to reject\n"
13429 "Specify large community to accept\n"
13430 "An ordered list as a regular-expression\n")
13431{
d62a17ae 13432 return lcommunity_list_unset_vty(vty, argc, argv,
13433 LARGE_COMMUNITY_LIST_EXPANDED);
57d187bc
JS
13434}
13435
13436DEFUN (no_ip_lcommunity_list_name_standard,
13437 no_ip_lcommunity_list_name_standard_cmd,
13438 "no ip large-community-list standard WORD <deny|permit> AA:AA:NN...",
13439 NO_STR
13440 IP_STR
13441 LCOMMUNITY_LIST_STR
13442 "Specify standard large-community-list\n"
13443 "Large Community list name\n"
13444 "Specify large community to reject\n"
13445 "Specify large community to accept\n"
13446 LCOMMUNITY_VAL_STR)
13447{
d62a17ae 13448 return lcommunity_list_unset_vty(vty, argc, argv,
13449 LARGE_COMMUNITY_LIST_STANDARD);
57d187bc
JS
13450}
13451
13452DEFUN (no_ip_lcommunity_list_name_expanded,
13453 no_ip_lcommunity_list_name_expanded_cmd,
13454 "no ip large-community-list expanded WORD <deny|permit> LINE...",
13455 NO_STR
13456 IP_STR
13457 LCOMMUNITY_LIST_STR
13458 "Specify expanded large-community-list\n"
13459 "Large community list name\n"
13460 "Specify large community to reject\n"
13461 "Specify large community to accept\n"
13462 "An ordered list as a regular-expression\n")
13463{
d62a17ae 13464 return lcommunity_list_unset_vty(vty, argc, argv,
13465 LARGE_COMMUNITY_LIST_EXPANDED);
13466}
13467
13468static void lcommunity_list_show(struct vty *vty, struct community_list *list)
13469{
13470 struct community_entry *entry;
13471
13472 for (entry = list->head; entry; entry = entry->next) {
13473 if (entry == list->head) {
13474 if (all_digit(list->name))
13475 vty_out(vty, "Large community %s list %s\n",
13476 entry->style == EXTCOMMUNITY_LIST_STANDARD
13477 ? "standard"
13478 : "(expanded) access",
13479 list->name);
13480 else
13481 vty_out(vty,
13482 "Named large community %s list %s\n",
13483 entry->style == EXTCOMMUNITY_LIST_STANDARD
13484 ? "standard"
13485 : "expanded",
13486 list->name);
13487 }
13488 if (entry->any)
13489 vty_out(vty, " %s\n",
13490 community_direct_str(entry->direct));
13491 else
13492 vty_out(vty, " %s %s\n",
13493 community_direct_str(entry->direct),
13494 entry->style == EXTCOMMUNITY_LIST_STANDARD
13495 ? entry->u.ecom->str
13496 : entry->config);
13497 }
57d187bc
JS
13498}
13499
13500DEFUN (show_ip_lcommunity_list,
13501 show_ip_lcommunity_list_cmd,
13502 "show ip large-community-list",
13503 SHOW_STR
13504 IP_STR
13505 "List large-community list\n")
13506{
d62a17ae 13507 struct community_list *list;
13508 struct community_list_master *cm;
57d187bc 13509
d62a17ae 13510 cm = community_list_master_lookup(bgp_clist,
13511 LARGE_COMMUNITY_LIST_MASTER);
13512 if (!cm)
13513 return CMD_SUCCESS;
57d187bc 13514
d62a17ae 13515 for (list = cm->num.head; list; list = list->next)
13516 lcommunity_list_show(vty, list);
57d187bc 13517
d62a17ae 13518 for (list = cm->str.head; list; list = list->next)
13519 lcommunity_list_show(vty, list);
57d187bc 13520
d62a17ae 13521 return CMD_SUCCESS;
57d187bc
JS
13522}
13523
13524DEFUN (show_ip_lcommunity_list_arg,
13525 show_ip_lcommunity_list_arg_cmd,
13526 "show ip large-community-list <(1-500)|WORD>",
13527 SHOW_STR
13528 IP_STR
13529 "List large-community list\n"
13530 "large-community-list number\n"
13531 "large-community-list name\n")
13532{
d62a17ae 13533 struct community_list *list;
57d187bc 13534
d62a17ae 13535 list = community_list_lookup(bgp_clist, argv[3]->arg,
13536 LARGE_COMMUNITY_LIST_MASTER);
13537 if (!list) {
13538 vty_out(vty, "%% Can't find extcommunity-list\n");
13539 return CMD_WARNING;
13540 }
57d187bc 13541
d62a17ae 13542 lcommunity_list_show(vty, list);
57d187bc 13543
d62a17ae 13544 return CMD_SUCCESS;
57d187bc
JS
13545}
13546
718e3744 13547/* "extcommunity-list" keyword help string. */
13548#define EXTCOMMUNITY_LIST_STR "Add a extended community list entry\n"
13549#define EXTCOMMUNITY_VAL_STR "Extended community attribute in 'rt aa:nn_or_IPaddr:nn' OR 'soo aa:nn_or_IPaddr:nn' format\n"
13550
13551DEFUN (ip_extcommunity_list_standard,
13552 ip_extcommunity_list_standard_cmd,
e961923c 13553 "ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
718e3744 13554 IP_STR
13555 EXTCOMMUNITY_LIST_STR
13556 "Extended Community list number (standard)\n"
718e3744 13557 "Specify standard extcommunity-list\n"
5bf15956 13558 "Community list name\n"
718e3744 13559 "Specify community to reject\n"
13560 "Specify community to accept\n"
13561 EXTCOMMUNITY_VAL_STR)
13562{
d62a17ae 13563 int style = EXTCOMMUNITY_LIST_STANDARD;
13564 int direct = 0;
13565 char *cl_number_or_name = NULL;
42f914d4 13566
d62a17ae 13567 int idx = 0;
13568 argv_find(argv, argc, "(1-99)", &idx);
13569 argv_find(argv, argc, "WORD", &idx);
13570 cl_number_or_name = argv[idx]->arg;
13571 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13572 : COMMUNITY_DENY;
13573 argv_find(argv, argc, "AA:NN", &idx);
13574 char *str = argv_concat(argv, argc, idx);
42f914d4 13575
d62a17ae 13576 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13577 direct, style);
42f914d4 13578
d62a17ae 13579 XFREE(MTYPE_TMP, str);
42f914d4 13580
d62a17ae 13581 if (ret < 0) {
13582 community_list_perror(vty, ret);
13583 return CMD_WARNING_CONFIG_FAILED;
13584 }
42f914d4 13585
d62a17ae 13586 return CMD_SUCCESS;
718e3744 13587}
13588
718e3744 13589DEFUN (ip_extcommunity_list_name_expanded,
13590 ip_extcommunity_list_name_expanded_cmd,
e961923c 13591 "ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13592 IP_STR
13593 EXTCOMMUNITY_LIST_STR
5bf15956 13594 "Extended Community list number (expanded)\n"
718e3744 13595 "Specify expanded extcommunity-list\n"
13596 "Extended Community list name\n"
13597 "Specify community to reject\n"
13598 "Specify community to accept\n"
13599 "An ordered list as a regular-expression\n")
13600{
d62a17ae 13601 int style = EXTCOMMUNITY_LIST_EXPANDED;
13602 int direct = 0;
13603 char *cl_number_or_name = NULL;
42f914d4 13604
d62a17ae 13605 int idx = 0;
13606 argv_find(argv, argc, "(100-500)", &idx);
13607 argv_find(argv, argc, "WORD", &idx);
13608 cl_number_or_name = argv[idx]->arg;
13609 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13610 : COMMUNITY_DENY;
13611 argv_find(argv, argc, "LINE", &idx);
13612 char *str = argv_concat(argv, argc, idx);
42f914d4 13613
d62a17ae 13614 int ret = extcommunity_list_set(bgp_clist, cl_number_or_name, str,
13615 direct, style);
42f914d4 13616
d62a17ae 13617 XFREE(MTYPE_TMP, str);
42f914d4 13618
d62a17ae 13619 if (ret < 0) {
13620 community_list_perror(vty, ret);
13621 return CMD_WARNING_CONFIG_FAILED;
13622 }
42f914d4 13623
d62a17ae 13624 return CMD_SUCCESS;
718e3744 13625}
13626
fee6e4e4 13627DEFUN (no_ip_extcommunity_list_standard_all,
13628 no_ip_extcommunity_list_standard_all_cmd,
e961923c 13629 "no ip extcommunity-list <(1-99)|standard WORD> <deny|permit> AA:NN...",
813d4307
DW
13630 NO_STR
13631 IP_STR
13632 EXTCOMMUNITY_LIST_STR
13633 "Extended Community list number (standard)\n"
718e3744 13634 "Specify standard extcommunity-list\n"
5bf15956 13635 "Community list name\n"
718e3744 13636 "Specify community to reject\n"
13637 "Specify community to accept\n"
13638 EXTCOMMUNITY_VAL_STR)
13639{
d62a17ae 13640 int deleteall = 0;
42f914d4 13641
d62a17ae 13642 int style = EXTCOMMUNITY_LIST_STANDARD;
13643 int direct = 0;
13644 char *cl_number_or_name = NULL;
42f914d4 13645
d62a17ae 13646 int idx = 0;
13647 argv_find(argv, argc, "(1-99)", &idx);
13648 argv_find(argv, argc, "WORD", &idx);
13649 cl_number_or_name = argv[idx]->arg;
13650 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13651 : COMMUNITY_DENY;
13652 argv_find(argv, argc, "AA:NN", &idx);
13653 char *str = argv_concat(argv, argc, idx);
42f914d4 13654
d62a17ae 13655 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13656 direct, style, deleteall);
42f914d4 13657
d62a17ae 13658 XFREE(MTYPE_TMP, str);
42f914d4 13659
d62a17ae 13660 if (ret < 0) {
13661 community_list_perror(vty, ret);
13662 return CMD_WARNING_CONFIG_FAILED;
13663 }
42f914d4 13664
d62a17ae 13665 return CMD_SUCCESS;
718e3744 13666}
13667
5bf15956
DW
13668DEFUN (no_ip_extcommunity_list_expanded_all,
13669 no_ip_extcommunity_list_expanded_all_cmd,
e961923c 13670 "no ip extcommunity-list <(100-500)|expanded WORD> <deny|permit> LINE...",
718e3744 13671 NO_STR
13672 IP_STR
13673 EXTCOMMUNITY_LIST_STR
13674 "Extended Community list number (expanded)\n"
718e3744 13675 "Specify expanded extcommunity-list\n"
5bf15956 13676 "Extended Community list name\n"
718e3744 13677 "Specify community to reject\n"
13678 "Specify community to accept\n"
13679 "An ordered list as a regular-expression\n")
13680{
d62a17ae 13681 int deleteall = 0;
42f914d4 13682
d62a17ae 13683 int style = EXTCOMMUNITY_LIST_EXPANDED;
13684 int direct = 0;
13685 char *cl_number_or_name = NULL;
42f914d4 13686
d62a17ae 13687 int idx = 0;
13688 argv_find(argv, argc, "(100-500)", &idx);
13689 argv_find(argv, argc, "WORD", &idx);
13690 cl_number_or_name = argv[idx]->arg;
13691 direct = argv_find(argv, argc, "permit", &idx) ? COMMUNITY_PERMIT
13692 : COMMUNITY_DENY;
13693 argv_find(argv, argc, "LINE", &idx);
13694 char *str = argv_concat(argv, argc, idx);
42f914d4 13695
d62a17ae 13696 int ret = extcommunity_list_unset(bgp_clist, cl_number_or_name, str,
13697 direct, style, deleteall);
42f914d4 13698
d62a17ae 13699 XFREE(MTYPE_TMP, str);
42f914d4 13700
d62a17ae 13701 if (ret < 0) {
13702 community_list_perror(vty, ret);
13703 return CMD_WARNING_CONFIG_FAILED;
13704 }
42f914d4 13705
d62a17ae 13706 return CMD_SUCCESS;
718e3744 13707}
13708
d62a17ae 13709static void extcommunity_list_show(struct vty *vty, struct community_list *list)
718e3744 13710{
d62a17ae 13711 struct community_entry *entry;
718e3744 13712
d62a17ae 13713 for (entry = list->head; entry; entry = entry->next) {
13714 if (entry == list->head) {
13715 if (all_digit(list->name))
13716 vty_out(vty, "Extended community %s list %s\n",
13717 entry->style == EXTCOMMUNITY_LIST_STANDARD
13718 ? "standard"
13719 : "(expanded) access",
13720 list->name);
13721 else
13722 vty_out(vty,
13723 "Named extended community %s list %s\n",
13724 entry->style == EXTCOMMUNITY_LIST_STANDARD
13725 ? "standard"
13726 : "expanded",
13727 list->name);
13728 }
13729 if (entry->any)
13730 vty_out(vty, " %s\n",
13731 community_direct_str(entry->direct));
13732 else
13733 vty_out(vty, " %s %s\n",
13734 community_direct_str(entry->direct),
13735 entry->style == EXTCOMMUNITY_LIST_STANDARD
13736 ? entry->u.ecom->str
13737 : entry->config);
13738 }
718e3744 13739}
13740
13741DEFUN (show_ip_extcommunity_list,
13742 show_ip_extcommunity_list_cmd,
13743 "show ip extcommunity-list",
13744 SHOW_STR
13745 IP_STR
13746 "List extended-community list\n")
13747{
d62a17ae 13748 struct community_list *list;
13749 struct community_list_master *cm;
718e3744 13750
d62a17ae 13751 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13752 if (!cm)
13753 return CMD_SUCCESS;
718e3744 13754
d62a17ae 13755 for (list = cm->num.head; list; list = list->next)
13756 extcommunity_list_show(vty, list);
718e3744 13757
d62a17ae 13758 for (list = cm->str.head; list; list = list->next)
13759 extcommunity_list_show(vty, list);
718e3744 13760
d62a17ae 13761 return CMD_SUCCESS;
718e3744 13762}
13763
13764DEFUN (show_ip_extcommunity_list_arg,
13765 show_ip_extcommunity_list_arg_cmd,
6147e2c6 13766 "show ip extcommunity-list <(1-500)|WORD>",
718e3744 13767 SHOW_STR
13768 IP_STR
13769 "List extended-community list\n"
13770 "Extcommunity-list number\n"
13771 "Extcommunity-list name\n")
13772{
d62a17ae 13773 int idx_comm_list = 3;
13774 struct community_list *list;
718e3744 13775
d62a17ae 13776 list = community_list_lookup(bgp_clist, argv[idx_comm_list]->arg,
13777 EXTCOMMUNITY_LIST_MASTER);
13778 if (!list) {
13779 vty_out(vty, "%% Can't find extcommunity-list\n");
13780 return CMD_WARNING;
13781 }
718e3744 13782
d62a17ae 13783 extcommunity_list_show(vty, list);
718e3744 13784
d62a17ae 13785 return CMD_SUCCESS;
718e3744 13786}
6b0655a2 13787
718e3744 13788/* Return configuration string of community-list entry. */
d62a17ae 13789static const char *community_list_config_str(struct community_entry *entry)
718e3744 13790{
d62a17ae 13791 const char *str;
718e3744 13792
d62a17ae 13793 if (entry->any)
13794 str = "";
13795 else {
13796 if (entry->style == COMMUNITY_LIST_STANDARD)
a69ea8ae 13797 str = community_str(entry->u.com, false);
d62a17ae 13798 else
13799 str = entry->config;
13800 }
13801 return str;
718e3744 13802}
13803
13804/* Display community-list and extcommunity-list configuration. */
d62a17ae 13805static int community_list_config_write(struct vty *vty)
13806{
13807 struct community_list *list;
13808 struct community_entry *entry;
13809 struct community_list_master *cm;
13810 int write = 0;
13811
13812 /* Community-list. */
13813 cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER);
13814
13815 for (list = cm->num.head; list; list = list->next)
13816 for (entry = list->head; entry; entry = entry->next) {
13817 vty_out(vty, "ip community-list %s %s %s\n", list->name,
13818 community_direct_str(entry->direct),
13819 community_list_config_str(entry));
13820 write++;
13821 }
13822 for (list = cm->str.head; list; list = list->next)
13823 for (entry = list->head; entry; entry = entry->next) {
13824 vty_out(vty, "ip community-list %s %s %s %s\n",
13825 entry->style == COMMUNITY_LIST_STANDARD
13826 ? "standard"
13827 : "expanded",
13828 list->name, community_direct_str(entry->direct),
13829 community_list_config_str(entry));
13830 write++;
13831 }
13832
13833 /* Extcommunity-list. */
13834 cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER);
13835
13836 for (list = cm->num.head; list; list = list->next)
13837 for (entry = list->head; entry; entry = entry->next) {
13838 vty_out(vty, "ip extcommunity-list %s %s %s\n",
13839 list->name, community_direct_str(entry->direct),
13840 community_list_config_str(entry));
13841 write++;
13842 }
13843 for (list = cm->str.head; list; list = list->next)
13844 for (entry = list->head; entry; entry = entry->next) {
13845 vty_out(vty, "ip extcommunity-list %s %s %s %s\n",
13846 entry->style == EXTCOMMUNITY_LIST_STANDARD
13847 ? "standard"
13848 : "expanded",
13849 list->name, community_direct_str(entry->direct),
13850 community_list_config_str(entry));
13851 write++;
13852 }
13853
13854
13855 /* lcommunity-list. */
13856 cm = community_list_master_lookup(bgp_clist,
13857 LARGE_COMMUNITY_LIST_MASTER);
13858
13859 for (list = cm->num.head; list; list = list->next)
13860 for (entry = list->head; entry; entry = entry->next) {
13861 vty_out(vty, "ip large-community-list %s %s %s\n",
13862 list->name, community_direct_str(entry->direct),
13863 community_list_config_str(entry));
13864 write++;
13865 }
13866 for (list = cm->str.head; list; list = list->next)
13867 for (entry = list->head; entry; entry = entry->next) {
13868 vty_out(vty, "ip large-community-list %s %s %s %s\n",
13869 entry->style == LARGE_COMMUNITY_LIST_STANDARD
13870 ? "standard"
13871 : "expanded",
13872 list->name, community_direct_str(entry->direct),
13873 community_list_config_str(entry));
13874 write++;
13875 }
13876
13877 return write;
13878}
13879
13880static struct cmd_node community_list_node = {
13881 COMMUNITY_LIST_NODE, "", 1 /* Export to vtysh. */
718e3744 13882};
13883
d62a17ae 13884static void community_list_vty(void)
13885{
13886 install_node(&community_list_node, community_list_config_write);
13887
13888 /* Community-list. */
13889 install_element(CONFIG_NODE, &ip_community_list_standard_cmd);
13890 install_element(CONFIG_NODE, &ip_community_list_expanded_all_cmd);
13891 install_element(CONFIG_NODE, &no_ip_community_list_standard_all_cmd);
13892 install_element(CONFIG_NODE, &no_ip_community_list_expanded_all_cmd);
13893 install_element(VIEW_NODE, &show_ip_community_list_cmd);
13894 install_element(VIEW_NODE, &show_ip_community_list_arg_cmd);
13895
13896 /* Extcommunity-list. */
13897 install_element(CONFIG_NODE, &ip_extcommunity_list_standard_cmd);
13898 install_element(CONFIG_NODE, &ip_extcommunity_list_name_expanded_cmd);
13899 install_element(CONFIG_NODE, &no_ip_extcommunity_list_standard_all_cmd);
13900 install_element(CONFIG_NODE, &no_ip_extcommunity_list_expanded_all_cmd);
13901 install_element(VIEW_NODE, &show_ip_extcommunity_list_cmd);
13902 install_element(VIEW_NODE, &show_ip_extcommunity_list_arg_cmd);
13903
13904 /* Large Community List */
13905 install_element(CONFIG_NODE, &ip_lcommunity_list_standard_cmd);
13906 install_element(CONFIG_NODE, &ip_lcommunity_list_standard1_cmd);
13907 install_element(CONFIG_NODE, &ip_lcommunity_list_expanded_cmd);
13908 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard_cmd);
13909 install_element(CONFIG_NODE, &ip_lcommunity_list_name_standard1_cmd);
13910 install_element(CONFIG_NODE, &ip_lcommunity_list_name_expanded_cmd);
13911 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_all_cmd);
13912 install_element(CONFIG_NODE,
13913 &no_ip_lcommunity_list_name_expanded_all_cmd);
13914 install_element(CONFIG_NODE, &no_ip_lcommunity_list_standard_cmd);
13915 install_element(CONFIG_NODE, &no_ip_lcommunity_list_expanded_cmd);
13916 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_standard_cmd);
13917 install_element(CONFIG_NODE, &no_ip_lcommunity_list_name_expanded_cmd);
13918 install_element(VIEW_NODE, &show_ip_lcommunity_list_cmd);
13919 install_element(VIEW_NODE, &show_ip_lcommunity_list_arg_cmd);
5bf15956 13920}